@@ -31,92 +31,64 @@ trait LegacyScalaRunnerTestDefinitions { _: DefaultTests =>
31
31
}
32
32
33
33
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" )
49
35
}
50
36
51
37
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" )
67
39
}
68
40
69
41
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)
83
46
.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
+ }
88
50
}
89
51
}
90
52
91
53
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)
97
57
.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) ))
99
59
}
100
60
}
101
61
102
62
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 = {
103
86
val msg = " Hello world"
104
87
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))
120
89
}
121
90
}
91
+
92
+ private def deprecatedOptionWarning (optionName : String ) =
93
+ s " Deprecated option ' $optionName' is ignored "
122
94
}
0 commit comments