Skip to content

Commit 01de592

Browse files
committed
NIT Refactor legacy scala runner backwards compat tests
1 parent 0a1ae85 commit 01de592

File tree

1 file changed

+40
-68
lines changed

1 file changed

+40
-68
lines changed

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

Lines changed: 40 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -31,92 +31,64 @@ trait LegacyScalaRunnerTestDefinitions { _: DefaultTests =>
3131
}
3232

3333
test("ensure -save/--save works with the default command") {
34-
val msg = "Hello world"
35-
TestInputs(os.rel / "s.sc" -> s"""println("$msg")""").fromRoot { root =>
36-
val legacySaveOption = "-save"
37-
val res1 =
38-
os.proc(TestUtil.cli, ".", legacySaveOption, TestUtil.extraOptions)
39-
.call(cwd = root, stderr = os.Pipe)
40-
expect(res1.out.trim() == msg)
41-
expect(res1.err.trim().contains(s"Deprecated option '$legacySaveOption' is ignored"))
42-
val doubleDashSaveOption = "--save"
43-
val res2 =
44-
os.proc(TestUtil.cli, ".", doubleDashSaveOption, TestUtil.extraOptions)
45-
.call(cwd = root, stderr = os.Pipe)
46-
expect(res2.out.trim() == msg)
47-
expect(res2.err.trim().contains(s"Deprecated option '$doubleDashSaveOption' is ignored"))
48-
}
34+
simpleLegacyOptionBackwardsCompatTest("-save", "--save")
4935
}
5036

5137
test("ensure -nosave/--nosave works with the default command") {
52-
val msg = "Hello world"
53-
TestInputs(os.rel / "s.sc" -> s"""println("$msg")""").fromRoot { root =>
54-
val legacyNoSaveOption = "-nosave"
55-
val res1 =
56-
os.proc(TestUtil.cli, ".", legacyNoSaveOption, TestUtil.extraOptions)
57-
.call(cwd = root, stderr = os.Pipe)
58-
expect(res1.out.trim() == msg)
59-
expect(res1.err.trim().contains(s"Deprecated option '$legacyNoSaveOption' is ignored"))
60-
val doubleDashNoSaveOption = "--nosave"
61-
val res2 =
62-
os.proc(TestUtil.cli, ".", doubleDashNoSaveOption, TestUtil.extraOptions)
63-
.call(cwd = root, stderr = os.Pipe)
64-
expect(res2.out.trim() == msg)
65-
expect(res2.err.trim().contains(s"Deprecated option '$doubleDashNoSaveOption' is ignored"))
66-
}
38+
simpleLegacyOptionBackwardsCompatTest("-nosave", "--nosave")
6739
}
6840

6941
test("ensure -howtorun/--how-to-run works with the default command") {
70-
val msg = "Hello world"
71-
TestInputs(os.rel / "s.sc" -> s"""println("$msg")""").fromRoot { root =>
72-
Seq("object", "script", "jar", "repl", "guess", "invalid").foreach { htrValue =>
73-
val legacyHtrOption = "-howtorun"
74-
val res1 =
75-
os.proc(TestUtil.cli, ".", legacyHtrOption, htrValue, TestUtil.extraOptions)
76-
.call(cwd = root, stderr = os.Pipe)
77-
expect(res1.out.trim() == msg)
78-
expect(res1.err.trim().contains(s"Deprecated option '$legacyHtrOption' is ignored"))
79-
expect(res1.err.trim().contains(htrValue))
80-
val doubleDashHtrOption = "--how-to-run"
81-
val res2 =
82-
os.proc(TestUtil.cli, ".", doubleDashHtrOption, htrValue, TestUtil.extraOptions)
42+
legacyOptionBackwardsCompatTest("-howtorun", "--how-to-run") {
43+
(legacyHtrOption, root) =>
44+
Seq("object", "script", "jar", "repl", "guess", "invalid").foreach { htrValue =>
45+
val res = os.proc(TestUtil.cli, legacyHtrOption, htrValue, "s.sc", TestUtil.extraOptions)
8346
.call(cwd = root, stderr = os.Pipe)
84-
expect(res2.out.trim() == msg)
85-
expect(res2.err.trim().contains(s"Deprecated option '$doubleDashHtrOption' is ignored"))
86-
expect(res2.err.trim().contains(htrValue))
87-
}
47+
expect(res.err.trim().contains(deprecatedOptionWarning(legacyHtrOption)))
48+
expect(res.err.trim().contains(htrValue))
49+
}
8850
}
8951
}
9052

9153
test("ensure -I works with the default command") {
92-
val msg = "Hello world"
93-
TestInputs(os.rel / "s.sc" -> s"""println("$msg")""").fromRoot { root =>
94-
val legacyIOption = "-I"
95-
val res =
96-
os.proc(TestUtil.cli, legacyIOption, "s.sc", "--repl-dry-run", TestUtil.extraOptions)
54+
legacyOptionBackwardsCompatTest("-I") {
55+
(legacyOption, root) =>
56+
val res = os.proc(TestUtil.cli, legacyOption, "--repl-dry-run", TestUtil.extraOptions)
9757
.call(cwd = root, stderr = os.Pipe)
98-
expect(res.err.trim().contains(s"Deprecated option '$legacyIOption' is ignored"))
58+
expect(res.err.trim().contains(deprecatedOptionWarning(legacyOption)))
9959
}
10060
}
10161

10262
test("ensure -nc/-nocompdaemon/--no-compilation-daemon works with the default command") {
63+
simpleLegacyOptionBackwardsCompatTest("-nc", "-nocompdaemon", "--no-compilation-daemon")
64+
}
65+
66+
private def simpleLegacyOptionBackwardsCompatTest(optionAliases: String*): Unit =
67+
abstractLegacyOptionBackwardsCompatTest(optionAliases) {
68+
(legacyOption, expectedMsg, root) =>
69+
val res = os.proc(TestUtil.cli, legacyOption, "s.sc", TestUtil.extraOptions)
70+
.call(cwd = root, stderr = os.Pipe)
71+
expect(res.out.trim() == expectedMsg)
72+
expect(res.err.trim().contains(deprecatedOptionWarning(legacyOption)))
73+
}
74+
75+
private def legacyOptionBackwardsCompatTest(optionAliases: String*)(f: (String, os.Path) => Unit)
76+
: Unit =
77+
abstractLegacyOptionBackwardsCompatTest(optionAliases) { (legacyOption, _, root) =>
78+
f(legacyOption, root)
79+
}
80+
81+
private def abstractLegacyOptionBackwardsCompatTest(optionAliases: Seq[String])(f: (
82+
String,
83+
String,
84+
os.Path
85+
) => Unit): Unit = {
10386
val msg = "Hello world"
10487
TestInputs(os.rel / "s.sc" -> s"""println("$msg")""").fromRoot { root =>
105-
val legacyOption = "-nc"
106-
val res =
107-
os.proc(TestUtil.cli, legacyOption, "s.sc", TestUtil.extraOptions)
108-
.call(cwd = root, stderr = os.Pipe)
109-
expect(res.err.trim().contains(s"Deprecated option '$legacyOption' is ignored"))
110-
val legacyOption2 = "-nocompdaemon"
111-
val res2 =
112-
os.proc(TestUtil.cli, legacyOption2, "s.sc", TestUtil.extraOptions)
113-
.call(cwd = root, stderr = os.Pipe)
114-
expect(res2.err.trim().contains(s"Deprecated option '$legacyOption2' is ignored"))
115-
val legacyOption3 = "--no-compilation-daemon"
116-
val res3 =
117-
os.proc(TestUtil.cli, legacyOption3, "s.sc", TestUtil.extraOptions)
118-
.call(cwd = root, stderr = os.Pipe)
119-
expect(res3.err.trim().contains(s"Deprecated option '$legacyOption3' is ignored"))
88+
optionAliases.foreach(f(_, msg, root))
12089
}
12190
}
91+
92+
private def deprecatedOptionWarning(optionName: String) =
93+
s"Deprecated option '$optionName' is ignored"
12294
}

0 commit comments

Comments
 (0)