@@ -6,7 +6,7 @@ class DefaultTests extends ScalaCliSuite {
6
6
test(" running scala-cli with no args should default to repl" ) {
7
7
TestInputs .empty.fromRoot { root =>
8
8
val res = os.proc(TestUtil .cli, " --repl-dry-run" ).call(cwd = root, mergeErrIntoOut = true )
9
- expect(res.out.trim() == " Dry run, not running REPL. " )
9
+ expect(res.out.trim() == replDryRunOutput )
10
10
}
11
11
}
12
12
test(" running scala-cli with no args should not accept run-only options" ) {
@@ -94,11 +94,66 @@ class DefaultTests extends ScalaCliSuite {
94
94
}
95
95
}
96
96
97
+ test(" default to the run sub-command if -classpath and --main-class are passed" ) {
98
+ val expectedOutput = " Hello"
99
+ val mainClassName = " Main"
100
+ TestInputs (
101
+ os.rel / s " $mainClassName.scala " -> s """ object $mainClassName extends App { println(" $expectedOutput") } """
102
+ ).fromRoot { (root : os.Path ) =>
103
+ val compilationOutputDir = os.rel / " compilationOutput"
104
+ // first, precompile to an explicitly specified output directory with -d
105
+ os.proc(
106
+ TestUtil .cli,
107
+ " ." ,
108
+ " -d" ,
109
+ compilationOutputDir
110
+ ).call(cwd = root)
111
+
112
+ // next, run while relying on the pre-compiled class instead of passing inputs
113
+ val runRes = os.proc(
114
+ TestUtil .cli,
115
+ " --main-class" ,
116
+ mainClassName,
117
+ " -classpath" ,
118
+ (os.rel / compilationOutputDir).toString
119
+ ).call(cwd = root)
120
+ expect(runRes.out.trim == expectedOutput)
121
+ }
122
+ }
123
+
124
+ test(" default to the repl sub-command if -classpath is passed, but --main-class isn't" ) {
125
+ val expectedOutput = " Hello"
126
+ val mainClassName = " Main"
127
+ TestInputs (
128
+ os.rel / s " $mainClassName.scala " -> s """ object $mainClassName extends App { println(" $expectedOutput") } """
129
+ ).fromRoot { (root : os.Path ) =>
130
+ val compilationOutputDir = os.rel / " compilationOutput"
131
+ // first, precompile to an explicitly specified output directory with -d
132
+ os.proc(
133
+ TestUtil .cli,
134
+ " ." ,
135
+ " -d" ,
136
+ compilationOutputDir
137
+ ).call(cwd = root)
138
+
139
+ // next, run the repl while relying on the pre-compiled classes
140
+ val runRes = os.proc(
141
+ TestUtil .cli,
142
+ " --repl-dry-run" ,
143
+ " -classpath" ,
144
+ (os.rel / compilationOutputDir).toString
145
+ ).call(cwd = root, mergeErrIntoOut = true )
146
+ expect(runRes.out.trim == replDryRunOutput)
147
+ }
148
+ }
149
+
97
150
private def unrecognizedArgMessage (argName : String ) =
98
151
s """
99
152
|Unrecognized argument: $argName
100
153
|
101
154
|To list all available options, run
102
155
| ${Console .BOLD }${TestUtil .detectCliPath} --help ${Console .RESET }
103
156
| """ .stripMargin.trim
157
+
158
+ private lazy val replDryRunOutput = " Dry run, not running REPL."
104
159
}
0 commit comments