Skip to content

Commit 839f825

Browse files
bishaboshahamzaremmal
authored andcommitted
adjust test sources to be clear which are meant to be self-executing
1 parent e541f42 commit 839f825

22 files changed

+50
-55
lines changed

compiler/test-resources/scripting/argfileClasspath.sc

-9
This file was deleted.

compiler/test-resources/scripting/classpathReport.sc renamed to compiler/test-resources/scripting/classpathReport_scalacli.sc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bin/scala
2-
2+
// This file is a Scala CLI script.
33
import java.nio.file.Paths
44

55
// def main(args: Array[String]): Unit = // MIGRATION: Scala CLI expects `*.sc` files to be straight-line code

compiler/test-resources/scripting/cpArgumentsFile.txt

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
2+
13
def main(args: Array[String]): Unit =
24
println("Hello " + util.Properties.propOrNull("key"))

compiler/test-resources/scripting/envtestNu.sc

-2
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is a Scala CLI script.
2+
3+
println("Hello " + util.Properties.propOrNull("key"))

compiler/test-resources/scripting/hashBang.sc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env scala
1+
#!/usr/bin/env fake-program-to-test-hashbang-removal
22
# comment
33
STUFF=nada
44
!#

compiler/test-resources/scripting/hashBang.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/usr/bin/env scala
1+
#!/usr/bin/env fake-program-to-test-hashbang-removal
22
# comment
33
STUFF=nada
44
!#
5-
5+
// everything above this point should be ignored by the compiler
66
def main(args: Array[String]): Unit =
77
System.err.printf("mainClassFromStack: %s\n",mainFromStack)
88
assert(mainFromStack.contains("hashBang"),s"fromStack[$mainFromStack]")

compiler/test-resources/scripting/scriptName.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env scala
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
22

33
def main(args: Array[String]): Unit =
44
val name = Option(sys.props("script.name")) match {

compiler/test-resources/scripting/scriptPath.sc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!dist/target/pack/bin/scala
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
22

33
def main(args: Array[String]): Unit =
44
args.zipWithIndex.foreach { case (arg,i) => printf("arg %d: [%s]\n",i,arg) }

compiler/test-resources/scripting/scriptPathNu.sc renamed to compiler/test-resources/scripting/scriptPath_scalacli.sc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
args.zipWithIndex.foreach { case (arg,i) => printf("arg %d: [%s]\n",i,arg) }
66

7-
if !scriptPath.endsWith("scriptPathNu.sc") then
7+
if !scriptPath.endsWith("scriptPath_scalacli.sc") then
88
printf( s"incorrect script.path defined as [$scriptPath]")
99
else
1010
printf("scriptPath: %s\n", scriptPath) // report the value

compiler/test-resources/scripting/showArgs.sc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bin/scala
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
22

33
// precise output format expected by BashScriptsTests.scala
44
def main(args: Array[String]): Unit =
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bin/scala
22

3+
// This file is a Scala CLI script.
4+
35
// precise output format expected by BashScriptsTests.scala
4-
// MIGRATION: Scala CLI expects `*.sc` files to be straight-line code
56
for (a,i) <- args.zipWithIndex do
67
printf(s"arg %2d:[%s]\n",i,a)

compiler/test-resources/scripting/sqlDateError.sc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bin/scala
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
22

33
def main(args: Array[String]): Unit = {
44
println(new java.sql.Date(100L))

compiler/test-resources/scripting/sqlDateErrorNu.sc

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bin/scala
2+
3+
// This file is a Scala CLI script.
4+
5+
println(new java.sql.Date(100L))
6+
System.err.println("SCALA_OPTS="+Option(System.getenv("SCALA_OPTS")).getOrElse(""))

compiler/test-resources/scripting/touchFile.sc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env scala
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
22

33
import java.io.File
44

compiler/test-resources/scripting/unglobClasspath.sc

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This file is a Scala CLI script.
2+
3+
import dotty.tools.tasty.TastyFormat
4+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
// not visible on default classpath, "compiler/test/dotty/tools/scripting/ClasspathTests.scala"
6+
// adds it to classpath via a compiler argument `-classpath 'org/scala-lang/tasty-core_3/$VERSION/*'`
7+
8+
val cp = sys.props("java.class.path")
9+
printf("unglobbed classpath: %s\n", cp)

compiler/test/dotty/tools/scripting/BashScriptsTests.scala

+7-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ object BashScriptsTests:
5050
val testScriptArgs = Seq(
5151
"a", "b", "c", "-repl", "-run", "-script", "-debug"
5252
)
53-
val Seq(showArgsScript, showArgsScalaCli) = Seq("showArgs.sc", "showArgsNu.sc").map { name =>
53+
val Seq(showArgsScript, showArgsScalaCli) = Seq("showArgs.sc", "showArgs_scalacli.sc").map { name =>
5454
testFiles.find(_.getName == name).get.absPath
5555
}
5656

@@ -66,7 +66,7 @@ object BashScriptsTests:
6666
}
6767
file
6868

69-
val Seq(envtestNuSc, envtestScala) = Seq("envtestNu.sc", "envtest.scala").map { testFile(_) }
69+
val Seq(envtestNuSc, envtestScala) = Seq("envtest_scalacli.sc", "envtest.scala").map { testFile(_) }
7070

7171
// create command line with given options, execute specified script, return stdout
7272
def callScript(tag: String, script: String, keyPre: String): String =
@@ -173,13 +173,13 @@ class BashScriptsTests:
173173
assert(stdout == expectedOutput)
174174

175175
/*
176-
* verify that scriptPathNu.sc sees a valid script.path property,
177-
* and that it's value is the path to "scriptPathNu.sc".
176+
* verify that scriptPath_scalacli.sc sees a valid script.path property,
177+
* and that it's value is the path to "scriptPath_scalacli.sc".
178178
*/
179179
@Category(Array(classOf[BootstrappedOnlyTests]))
180180
@Test def verifyScriptPathProperty =
181181
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
182-
val scriptFile = testFiles.find(_.getName == "scriptPathNu.sc").get
182+
val scriptFile = testFiles.find(_.getName == "scriptPath_scalacli.sc").get
183183
val expected = s"${scriptFile.getName}"
184184
printf("===> verify valid system property script.path is reported by script [%s]\n", scriptFile.getName)
185185
printf("calling scriptFile: %s\n", scriptFile)
@@ -196,7 +196,7 @@ class BashScriptsTests:
196196
*/
197197
@Test def verifyScalaOpts =
198198
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
199-
val scriptFile = testFiles.find(_.getName == "classpathReport.sc").get
199+
val scriptFile = testFiles.find(_.getName == "classpathReport_scalacli.sc").get
200200
printf("===> verify SCALA_OPTS='@argsfile' is properly handled by `dist/bin/scala`\n")
201201
val envPairs = List(("SCALA_OPTS", s"@$argsfile"))
202202
val (validTest, exitCode, stdout, stderr) = bashCommand(scriptFile.absPath, envPairs)
@@ -219,7 +219,7 @@ class BashScriptsTests:
219219
*/
220220
@Test def sqlDateTest =
221221
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
222-
val scriptBase = "sqlDateErrorNu"
222+
val scriptBase = "sqlDateError_scalacli"
223223
val scriptFile = testFiles.find(_.getName == s"$scriptBase.sc").get
224224
val testJar = testFile(s"$scriptBase.jar") // jar should not be created when scriptFile runs
225225
val tj = Paths.get(testJar).toFile

compiler/test/dotty/tools/scripting/ClasspathTests.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ClasspathTests:
2424
@Ignore
2525
@Test def hashbangClasspathVerifyTest = {
2626
// only interested in classpath test scripts
27-
val testScriptName = "classpathReport.sc"
27+
val testScriptName = "classpathReport_scalacli.sc"
2828
val testScript = scripts("/scripting").find { _.getName.matches(testScriptName) } match
2929
case None => sys.error(s"test script not found: ${testScriptName}")
3030
case Some(file) => file
@@ -39,7 +39,7 @@ class ClasspathTests:
3939

4040
cmd.foreach { printf("[%s]\n", _) }
4141

42-
// classpathReport.sc is expected to produce two lines:
42+
// classpathReport_scalacli.sc is expected to produce two lines:
4343
// cwd: <current-working-directory-seen-by-the-script>
4444
// classpath: <classpath-seen-by-the-script>
4545

@@ -51,7 +51,7 @@ class ClasspathTests:
5151
// convert scriptCp to a list of files
5252
val hashbangJars: List[File] = scriptCp.split(psep).map { _.toFile }.toList
5353
val hashbangClasspathJars = hashbangJars.map { _.name }.sorted.distinct // get jar basenames, remove duplicates
54-
val packlibDir: String = ??? /* ??? was s"$scriptCwd/$packLibDir" */ // classpathReport.sc specifies a wildcard classpath in this directory
54+
val packlibDir: String = ??? /* ??? was s"$scriptCwd/$packLibDir" */ // classpathReport_scalacli.sc specifies a wildcard classpath in this directory
5555
val packlibJars: List[File] = listJars(packlibDir) // classpath entries expected to have been reported by the script
5656

5757
printf("%d jar files in dist/target/pack/lib\n", packlibJars.size)
@@ -78,7 +78,7 @@ class ClasspathTests:
7878
* verify classpath is unglobbed by MainGenericRunner.
7979
*/
8080
@Test def unglobClasspathVerifyTest = {
81-
val testScriptName = "unglobClasspath.sc"
81+
val testScriptName = "unglobClasspath_scalacli.sc"
8282
val testScript = scripts("/scripting").find { _.name.matches(testScriptName) } match
8383
case None => sys.error(s"test script not found: ${testScriptName}")
8484
case Some(file) => file

compiler/test/dotty/tools/scripting/ScriptingTests.scala

+7-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ import org.junit.Assume.assumeFalse
1717
/** Runs all tests contained in `compiler/test-resources/scripting/` */
1818
class ScriptingTests:
1919
// classpath tests managed by scripting.ClasspathTests.scala
20-
def testFiles = scripts("/scripting").filter { ! _.getName.toLowerCase.contains("classpath") }
20+
def testFiles = scripts("/scripting").filter { sc =>
21+
val name = sc.getName.toLowerCase
22+
!name.contains("classpath")
23+
&& !name.contains("_scalacli")
24+
}
2125

2226
/*
2327
* Call .scala scripts without -save option, verify no jar created
@@ -47,10 +51,7 @@ class ScriptingTests:
4751
*/
4852
@Test def scriptingMainTests =
4953
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
50-
for
51-
(scriptFile, scriptArgs) <- scalaFilesWithArgs(".sc")
52-
if !scriptFile.getName().endsWith("Nu.sc")
53-
do
54+
for (scriptFile, scriptArgs) <- scalaFilesWithArgs(".sc") do
5455
showScriptUnderTest(scriptFile)
5556
val unexpectedJar = script2jar(scriptFile)
5657
unexpectedJar.delete
@@ -69,10 +70,7 @@ class ScriptingTests:
6970
*/
7071
@Test def scriptingJarTest =
7172
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
72-
for
73-
(scriptFile, scriptArgs) <- scalaFilesWithArgs(".sc")
74-
if !scriptFile.getName().endsWith("Nu.sc")
75-
do
73+
for (scriptFile, scriptArgs) <- scalaFilesWithArgs(".sc") do
7674
showScriptUnderTest(scriptFile)
7775
val expectedJar = script2jar(scriptFile)
7876
expectedJar.delete

0 commit comments

Comments
 (0)