@@ -334,12 +334,12 @@ class SourcesTests extends TestUtil.ScalaCliBuildSuite {
334334 }
335335 }
336336
337- /** Asserts that the only Java source produced by `testInputs` is routed to the test scope and
338- * appears at `expectedPath `.
337+ /** Asserts that the only Java source produced by `testInputs` is routed to the test scope and is
338+ * reachable on disk at `expectedOnDiskPath `.
339339 */
340340 private def expectJavaFileRoutedToTestScope (
341341 testInputs : TestInputs ,
342- expectedPath : os.RelPath
342+ expectedOnDiskPath : os.RelPath
343343 ): Unit =
344344 testInputs.withInputs { (root, inputs) =>
345345 val (crossSources, _) =
@@ -367,36 +367,68 @@ class SourcesTests extends TestUtil.ScalaCliBuildSuite {
367367 ).orThrow
368368
369369 expect(mainSources.paths.isEmpty)
370- expect(testSources.paths.map(_._2) == Seq (expectedPath))
370+ expect(mainSources.inMemory.isEmpty)
371+ val onDiskPaths = testSources.paths.map(_._2)
372+ val inMemoryOriginalPaths =
373+ testSources.inMemory.flatMap(_.originalPath.toOption.map(_._1: os.SubPath ))
374+ expect((onDiskPaths ++ inMemoryOriginalPaths.map(os.rel / _)) == Seq (expectedOnDiskPath))
371375 }
372376
373- private val javaTestSourceContent : String =
374- """ public class Something {
375- | public int a = 1;
376- |}
377- |""" .stripMargin
377+ private val javaTestPublicClassName : String = " Something"
378+ private val javaTestSourceContent : String =
379+ s """ public class $javaTestPublicClassName {
380+ | public int a = 1;
381+ |}
382+ | """ .stripMargin
378383
379384 test(" a .test.java file should be routed to the test scope" ) {
380- val expectedPath = os.rel / " Something.test.java"
381- val testInputs = TestInputs (expectedPath -> javaTestSourceContent)
382- expectJavaFileRoutedToTestScope(testInputs, expectedPath)
385+ val onDiskPath = os.rel / s " $javaTestPublicClassName.test.java "
386+ val testInputs = TestInputs (onDiskPath -> javaTestSourceContent)
387+ expectJavaFileRoutedToTestScope(testInputs, onDiskPath)
388+ }
389+
390+ test(" a .test.java file's generated path strips the .test infix for javac" ) {
391+ val onDiskPath = os.rel / s " $javaTestPublicClassName.test.java "
392+ TestInputs (onDiskPath -> javaTestSourceContent).withInputs { (root, inputs) =>
393+ val (crossSources, _) =
394+ CrossSources .forInputs(
395+ inputs,
396+ preprocessors,
397+ TestLogger (),
398+ SuppressWarningOptions ()
399+ ).orThrow
400+
401+ val scopedSources = crossSources.scopedSources(BuildOptions ()).orThrow
402+ val testSources =
403+ scopedSources.sources(
404+ Scope .Test ,
405+ crossSources.sharedOptions(BuildOptions ()),
406+ root,
407+ TestLogger ()
408+ ).orThrow
409+
410+ val expectedGeneratedRelPath = os.rel / s " $javaTestPublicClassName.java "
411+ expect(testSources.paths.isEmpty)
412+ expect(testSources.inMemory.length == 1 )
413+ expect(testSources.inMemory.head.generatedRelPath == expectedGeneratedRelPath)
414+ }
383415 }
384416
385417 test(" a .java file under a test/ directory should be routed to the test scope" ) {
386- val expectedPath = os.rel / " test" / " Something .java"
387- val testInputs = TestInputs (Seq (expectedPath -> javaTestSourceContent), Seq (" ." ))
388- expectJavaFileRoutedToTestScope(testInputs, expectedPath )
418+ val onDiskPath = os.rel / " test" / s " $javaTestPublicClassName .java "
419+ val testInputs = TestInputs (Seq (onDiskPath -> javaTestSourceContent), Seq (" ." ))
420+ expectJavaFileRoutedToTestScope(testInputs, onDiskPath )
389421 }
390422
391423 test(" a .java file with //> using target.scope test should be routed to the test scope" ) {
392- val expectedPath = os.rel / " Something .java"
393- val testInputs = TestInputs (
394- expectedPath ->
424+ val onDiskPath = os.rel / s " $javaTestPublicClassName .java "
425+ val testInputs = TestInputs (
426+ onDiskPath ->
395427 s """ //> using target.scope test
396428 |
397429 | $javaTestSourceContent""" .stripMargin
398430 )
399- expectJavaFileRoutedToTestScope(testInputs, expectedPath )
431+ expectJavaFileRoutedToTestScope(testInputs, onDiskPath )
400432 }
401433
402434 test(" should skip SheBang in .sc and .scala" ) {
0 commit comments