Skip to content

Commit ce2c8a8

Browse files
committed
Add ConfigurationWriterTest
1 parent 0032aa0 commit ce2c8a8

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package proguard
2+
3+
import io.kotest.core.spec.style.FreeSpec
4+
import io.kotest.matchers.shouldBe
5+
import io.kotest.matchers.string.shouldContain
6+
import java.io.PrintWriter
7+
import java.io.StringWriter
8+
9+
/**
10+
* Test printing of the configuration (-printconfiguration option).
11+
*/
12+
class ConfigurationWriterTest : FreeSpec({
13+
fun printConfiguration(rules: String): String {
14+
val out = StringWriter()
15+
val configuration = Configuration()
16+
17+
ConfigurationParser(rules, "", null, System.getProperties()).use {
18+
it.parse(configuration)
19+
}
20+
21+
ConfigurationWriter(PrintWriter(out)).use {
22+
it.write(configuration)
23+
}
24+
25+
return out.toString().trim()
26+
}
27+
28+
"Hash character handling tests" - {
29+
"Comments should not be quoted" {
30+
printConfiguration("# comment\n-keep class **") shouldBe "# comment\n-keep class **"
31+
}
32+
33+
"Hash characters in comments should not be quoted" {
34+
printConfiguration("# #comment\n-keep class **") shouldBe "# #comment\n-keep class **"
35+
}
36+
}
37+
38+
"Given a -dontnote rule specifying a class name" - {
39+
val rules = "-dontnote com.example.MyClass"
40+
41+
"When the rule is parsed and printed out again" - {
42+
val out = printConfiguration(rules)
43+
44+
"Then the printed rule should be the same as the given rule" {
45+
out shouldBe rules
46+
}
47+
}
48+
}
49+
50+
"Given a -dontnote rule specifying a class name with wildcards" - {
51+
val rules = "-dontnote com.example.**"
52+
53+
"When the rule is parsed and printed out again" - {
54+
val out = printConfiguration(rules)
55+
56+
"Then the printed rule should be the same as the given rule" {
57+
out shouldBe rules
58+
}
59+
}
60+
}
61+
62+
"Given a -addconfigurationdebugging rule" - {
63+
val rules = "-addconfigurationdebugging"
64+
65+
"When the rules are parsed and printed out again" - {
66+
val out = printConfiguration(rules)
67+
68+
"Then the rules should be present in the output" {
69+
out shouldContain rules
70+
}
71+
}
72+
}
73+
74+
"Given an -optimizeaggressively rule" - {
75+
val rules = "-optimizeaggressively"
76+
77+
"When the rule is parsed and printed out again" - {
78+
val out = printConfiguration(rules)
79+
80+
"Then the rule should be present in the output" {
81+
out shouldBe rules
82+
}
83+
}
84+
}
85+
})

0 commit comments

Comments
 (0)