Skip to content

Commit b5cee36

Browse files
committed
Add a simple test for running built-in fix rules alongside scalafix ones
1 parent 8662521 commit b5cee36

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

modules/integration/src/test/scala/scala/cli/integration/FixTestDefinitions.scala

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,53 @@ abstract class FixTestDefinitions
1818
s"--enable-scalafix=${enableScalafix.toString}",
1919
s"--enable-built-in-rules=${enableBuiltIn.toString}"
2020
)
21+
22+
test("built-in + scalafix rules") {
23+
val mainFileName = "Main.scala"
24+
val unusedValName = "unused"
25+
val directive1 = "//> using dep \"com.lihaoyi::os-lib:0.11.3\""
26+
val directive2 = "//> using dep \"com.lihaoyi::pprint:0.9.0\""
27+
val mergedDirective1And2 =
28+
"using dependency \"com.lihaoyi::os-lib:0.11.3\" \"com.lihaoyi::pprint:0.9.0\""
29+
val directive3 =
30+
if (actualScalaVersion.startsWith("2")) "//> using options \"-Xlint:unused\""
31+
else "//> using options \"-Wunused:all\""
32+
TestInputs(
33+
os.rel / "Foo.scala" ->
34+
s"""$directive1
35+
|object Foo {
36+
| def hello: String = "hello"
37+
|}
38+
|""".stripMargin,
39+
os.rel / "Bar.scala" ->
40+
s"""$directive2
41+
|object Bar {
42+
| def world: String = "world"
43+
|}
44+
|""".stripMargin,
45+
os.rel / mainFileName ->
46+
s"""$directive3
47+
|object Main {
48+
| def main(args: Array[String]): Unit = {
49+
| val unused = "unused"
50+
| pprint.pprintln(Foo.hello + Bar.world)
51+
| pprint.pprintln(os.pwd)
52+
| }
53+
|}
54+
|""".stripMargin,
55+
os.rel / scalafixConfFileName ->
56+
"""rules = [
57+
| RemoveUnused
58+
|]
59+
|""".stripMargin
60+
).fromRoot { root =>
61+
os.proc(TestUtil.cli, "fix", ".", extraOptions, "--power").call(cwd = root)
62+
val projectFileContents = os.read(root / projectFileName)
63+
expect(projectFileContents.contains(mergedDirective1And2))
64+
expect(projectFileContents.contains(directive3))
65+
val mainFileContents = os.read(root / mainFileName)
66+
expect(!mainFileContents.contains(unusedValName))
67+
os.proc(TestUtil.cli, "compile", ".", extraOptions).call(cwd = root)
68+
}
69+
}
2170
}

0 commit comments

Comments
 (0)