@@ -19,31 +19,63 @@ trait RunWithWatchTestDefinitions { _: RunTestDefinitions =>
1919 }
2020 }
2121
22- if (! Properties .isMac || ! TestUtil .isCI)
23- // TODO make this pass reliably on Mac CI
24- test(" simple --watch .scala source" ) {
25- val expectedMessage1 = " Hello"
26- val inputPath = os.rel / " smth.scala"
27- TestInputs (inputPath -> s """ object Smth extends App { println(" $expectedMessage1") } """ )
28- .fromRoot { root =>
22+ // TODO make this pass reliably on Mac CI
23+ if (! Properties .isMac || ! TestUtil .isCI) {
24+ val expectedMessage1 = " Hello"
25+ val expectedMessage2 = " World"
26+ for {
27+ (inputPath, inputs, codeToWriteOver) <-
28+ Seq (
29+ {
30+ val inputPath = os.rel / " raw.scala"
31+ def code (message : String ) = s """ object Smth extends App { println(" $message") } """
32+ (
33+ inputPath,
34+ TestInputs (inputPath -> code(expectedMessage1)),
35+ code(expectedMessage2)
36+ )
37+ }, {
38+ val inputPath = os.rel / " script.sc"
39+ def code (message : String ) = s """ println(" $message") """
40+ (
41+ inputPath,
42+ TestInputs (inputPath -> code(expectedMessage1)),
43+ code(expectedMessage2)
44+ )
45+ }, {
46+ val inputPath = os.rel / " markdown.md"
47+ def code (message : String ) =
48+ s """ # Some random docs with a Scala snippet
49+ |```scala
50+ |println(" $message")
51+ |```
52+ |The snippet prints the message, of course.
53+ | """ .stripMargin
54+ (
55+ inputPath,
56+ TestInputs (inputPath -> code(expectedMessage1)),
57+ code(expectedMessage2)
58+ )
59+ }
60+ )
61+ }
62+ test(s " simple --watch ${inputPath.last}" ) {
63+ inputs.fromRoot { root =>
2964 TestUtil .withProcessWatching(
30- proc = os.proc(TestUtil .cli, " run" , " . " , " --watch" , extraOptions)
65+ proc = os.proc(TestUtil .cli, " run" , inputPath.toString() , " --watch" , extraOptions)
3166 .spawn(cwd = root, stderr = os.Pipe ),
3267 timeout = 120 .seconds
3368 ) { (proc, timeout, ec) =>
3469 val output1 = TestUtil .readLine(proc.stdout, ec, timeout)
3570 expect(output1 == expectedMessage1)
36- val expectedMessage2 = " World"
3771 proc.printStderrUntilRerun(timeout)(ec)
38- os.write.over(
39- root / inputPath,
40- s """ object Smth extends App { println(" $expectedMessage2") } """
41- )
72+ os.write.over(root / inputPath, codeToWriteOver)
4273 val output2 = TestUtil .readLine(proc.stdout, ec, timeout)
4374 expect(output2 == expectedMessage2)
4475 }
4576 }
46- }
77+ }
78+ }
4779
4880 test(" watch with interactive, with multiple main classes" ) {
4981 val fileName = " watch.scala"
@@ -232,4 +264,36 @@ trait RunWithWatchTestDefinitions { _: RunTestDefinitions =>
232264 }
233265 }
234266 }
267+
268+ // TODO make this pass reliably on Mac CI
269+ if (! Properties .isMac || ! TestUtil .isCI)
270+ test(" --watch .scala source with changing directives" ) {
271+ val inputPath = os.rel / " smth.scala"
272+
273+ def code (includeDirective : Boolean ) = {
274+ val directive = if (includeDirective) " //> using toolkit default" else " "
275+ s """ $directive
276+ |object Smth extends App { println(os.pwd) }
277+ | """ .stripMargin
278+ }
279+
280+ TestInputs (inputPath -> code(includeDirective = true )).fromRoot { root =>
281+ TestUtil .withProcessWatching(
282+ os.proc(TestUtil .cli, " run" , " ." , " --watch" , extraOptions)
283+ .spawn(cwd = root, stderr = os.Pipe )
284+ ) { (proc, timeout, ec) =>
285+ val output1 = TestUtil .readLine(proc.stdout, ec, timeout)
286+ expect(output1 == root.toString)
287+ proc.printStderrUntilRerun(timeout)(ec)
288+ os.write.over(root / inputPath, code(includeDirective = false ))
289+ TestUtil .readLine(proc.stderr, ec, timeout)
290+ val output2 = TestUtil .readLine(proc.stderr, ec, timeout)
291+ expect(output2.toLowerCase.contains(" error" ))
292+ proc.printStderrUntilRerun(timeout)(ec)
293+ os.write.over(root / inputPath, code(includeDirective = true ))
294+ val output3 = TestUtil .readLine(proc.stdout, ec, timeout)
295+ expect(output3 == root.toString)
296+ }
297+ }
298+ }
235299}
0 commit comments