@@ -270,37 +270,75 @@ trait RunScriptTestDefinitions { this: RunTestDefinitions =>
270270 }
271271 }
272272
273- test(" warn when script name shadows a dependency top-level package" ) {
273+ test(" hint when script name shadows a dependency top-level package and import fails " ) {
274274 val inputs = TestInputs (
275275 os.rel / " os.sc" ->
276276 s """ //> using dep com.lihaoyi::os-lib:0.11.8
277- |println("hi")
277+ |import os.Path
278+ |println(Path("/tmp"))
278279 | """ .stripMargin
279280 )
280281 inputs.fromRoot { root =>
281282 val res = os.proc(TestUtil .cli, extraOptions, " os.sc" )
282283 .call(cwd = root, check = false , mergeErrIntoOut = true )
283284 val output = res.out.trim()
284- expect(output.contains(" shadows the 'os' package" ))
285- expect(res.exitCode == 0 )
285+ expect(res.exitCode != 0 )
286+ expect(output.contains(" shadows the 'os' package from dependencies:" ))
287+ expect(output.contains(" os-lib" ))
288+ expect(output.contains(" is likely the cause of compilation errors mentioning 'os'" ))
286289 }
287290 }
288291
289- test(" warn with multiple JARs when script name shadows a shared package root" ) {
292+ test(" hint with multiple JARs when script name shadows a shared package root" ) {
290293 val inputs = TestInputs (
291294 os.rel / " cats.sc" ->
292295 s """ //> using dep org.typelevel::cats-core:2.12.0
293- |println("hi")
296+ |import cats.Show
297+ |println(Show[Int])
294298 | """ .stripMargin
295299 )
296300 inputs.fromRoot { root =>
297301 val res = os.proc(TestUtil .cli, extraOptions, " cats.sc" )
298302 .call(cwd = root, check = false , mergeErrIntoOut = true )
299303 val output = res.out.trim()
304+ expect(res.exitCode != 0 )
300305 expect(output.contains(" shadows the 'cats' package from dependencies:" ))
301306 expect(output.contains(" cats-core" ))
302307 expect(output.contains(" cats-kernel" ))
303- expect(res.exitCode == 0 )
308+ }
309+ }
310+
311+ test(" hint when script name clashes with a sibling .scala file" ) {
312+ val inputs = TestInputs (
313+ os.rel / " foo.sc" ->
314+ """ println("hi")""" ,
315+ os.rel / " foo.scala" ->
316+ """ object foo { def hello = "world" }"""
317+ )
318+ inputs.fromRoot { root =>
319+ val res = os.proc(TestUtil .cli, extraOptions, " foo.sc" , " foo.scala" )
320+ .call(cwd = root, check = false , mergeErrIntoOut = true )
321+ val output = res.out.trim()
322+ expect(res.exitCode != 0 )
323+ expect(output.contains(" foo.sc" ))
324+ expect(output.contains(" local source 'foo.scala'" ) || output.contains(" local sources:" ))
325+ }
326+ }
327+
328+ test(" do not hint when compile fails for an unrelated reason" ) {
329+ val inputs = TestInputs (
330+ os.rel / " safe.sc" ->
331+ s """ //> using dep com.lihaoyi::os-lib:0.11.8
332+ |val x: Int = "not an int"
333+ | """ .stripMargin
334+ )
335+ inputs.fromRoot { root =>
336+ val res = os.proc(TestUtil .cli, extraOptions, " safe.sc" )
337+ .call(cwd = root, check = false , mergeErrIntoOut = true )
338+ val output = res.out.trim()
339+ expect(res.exitCode != 0 )
340+ expect(! output.contains(" shadows" ))
341+ expect(! output.contains(" is likely the cause" ))
304342 }
305343 }
306344
@@ -315,7 +353,8 @@ trait RunScriptTestDefinitions { this: RunTestDefinitions =>
315353 val res = os.proc(TestUtil .cli, extraOptions, " safe.sc" )
316354 .call(cwd = root, check = false , mergeErrIntoOut = true )
317355 val output = res.out.trim()
318- expect(! output.contains(" shadows the 'os' package" ))
356+ expect(! output.contains(" shadows" ))
357+ expect(! output.contains(" is likely the cause" ))
319358 expect(res.exitCode == 0 )
320359 }
321360 }
0 commit comments