Skip to content

Commit c6cc0a3

Browse files
bishaboshaKordyjan
authored andcommitted
fix bash script tests
[Cherry-picked fbe8323]
1 parent 4682b52 commit c6cc0a3

15 files changed

+108
-38
lines changed

bin/scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."
44

5-
"$ROOT/bin/common" "$ROOT/dist/target/pack/bin/scala" "$@"
5+
"$ROOT/bin/common" "$ROOT/dist/target/pack/bin/scala" "$@" "--offline" "--server=false"

compiler/test-resources/scripting/classpathReport.sc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!bin/scala -classpath 'dist/target/pack/lib/*'
1+
#!/usr/bin/env bin/scala
22

33
import java.nio.file.Paths
44

5-
def main(args: Array[String]): Unit =
5+
// def main(args: Array[String]): Unit = // MIGRATION: Scala CLI expects `*.sc` files to be straight-line code
66
val cwd = Paths.get(".").toAbsolutePath.normalize.toString.norm
77
printf("cwd: %s\n", cwd)
88
printf("classpath: %s\n", sys.props("java.class.path").norm)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// MIGRATION: Scala CLI expects `*.sc` files to be straight-line code
2+
println("Hello " + util.Properties.propOrNull("key"))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bin/scala
2+
3+
// THIS FILE IS RAN WITH SCALA CLI, which wraps scripts exposing scriptPath and args variables
4+
5+
args.zipWithIndex.foreach { case (arg,i) => printf("arg %d: [%s]\n",i,arg) }
6+
7+
if !scriptPath.endsWith("scriptPathNu.sc") then
8+
printf( s"incorrect script.path defined as [$scriptPath]")
9+
else
10+
printf("scriptPath: %s\n", scriptPath) // report the value
11+
12+
extension(s: String)
13+
def norm: String = s.replace('\\', '/')

compiler/test-resources/scripting/showArgs.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env scala
1+
#!/usr/bin/env bin/scala
22

33
// precise output format expected by BashScriptsTests.scala
44
def main(args: Array[String]): Unit =
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bin/scala
2+
3+
// precise output format expected by BashScriptsTests.scala
4+
// MIGRATION: Scala CLI expects `*.sc` files to be straight-line code
5+
for (a,i) <- args.zipWithIndex do
6+
printf(s"arg %2d:[%s]\n",i,a)

compiler/test-resources/scripting/sqlDateError.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!bin/scala
1+
#!/usr/bin/env bin/scala
22

33
def main(args: Array[String]): Unit = {
44
println(new java.sql.Date(100L))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bin/scala
2+
3+
// def main(args: Array[String]): Unit = { MIGRATION: Scala CLI expects `*.sc` files to be straight-line code
4+
println(new java.sql.Date(100L))
5+
System.err.println("SCALA_OPTS="+Option(System.getenv("SCALA_OPTS")).getOrElse(""))
6+
// }
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#!bin/scala -classpath 'dist/target/pack/lib/*'
1+
// won't compile unless classpath is set correctly
2+
import dotty.tools.tasty.TastyFormat
23

3-
// won't compile unless the hashbang line sets classpath
4-
import org.jline.terminal.Terminal
5-
6-
def main(args: Array[String]) =
4+
// def main(args: Array[String]) = // MIGRATION: Scala CLI expects `*.sc` files to be straight-line code
75
val cp = sys.props("java.class.path")
86
printf("unglobbed classpath: %s\n", cp)

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BashExitCodeTests:
2929
}, expectedExitCode, exitCode)
3030

3131
// Helpers for running scala, scalac, and scalac without the the output directory ("raw")
32-
def scala(args: String*) = verifyExit(scalaPath, args*)
32+
def scala(args: String*) = verifyExit(scalaPath, ("--offline" +: "--server=false" +: args)*)
3333
def scalacRaw(args: String*) = verifyExit(scalacPath, args*)
3434
def scalac(args: String*) = scalacRaw(("-d" +: tmpDir +: args)*)
3535

@@ -38,12 +38,16 @@ class BashExitCodeTests:
3838
Files.write(Files.createTempFile(tmpDir.toPath, getClass.getSimpleName, suffix), body.getBytes(UTF_8)).absPath
3939

4040
@Test def neg = scalac(f("@main def Test = prin"))(1)
41-
@Test def run = scalac(f("@main def Test = ???"))(0) & scala("-classpath", tmpDir, "Test")(1)
42-
@Test def pos = scalac(f("@main def Test = ()"))(0) & scala("-classpath", tmpDir, "Test")(0)
41+
@Test def run = scalac(f("@main def Test = ???"))(0) & scala("-classpath", tmpDir, "-M", "Test")(1)
42+
@Test def pos = scalac(f("@main def Test = ()"))(0) & scala("-classpath", tmpDir, "-M", "Test")(0)
4343

44-
@Test def runNeg = scala(f("@main def Test = prin", ".sc"))(1)
45-
@Test def runRun = scala(f("@main def Test = ???", ".sc"))(1)
46-
@Test def runPos = scala(f("@main def Test = ()", ".sc"))(0)
44+
@Test def runNeg_script = scala(f("prin", ".sc"))(1)
45+
@Test def runRun_script = scala(f("???", ".sc"))(1)
46+
@Test def runPos_script = scala(f("()", ".sc"))(0)
47+
48+
@Test def runNeg = scala(f("@main def Test = prin", ".scala"))(1)
49+
@Test def runRun = scala(f("@main def Test = ???", ".scala"))(1)
50+
@Test def runPos = scala(f("@main def Test = ()", ".scala"))(0)
4751

4852
@Test def scNeg = scalac("-script", f("@main def Test = prin", ".sc"))(1)
4953
@Test def scRun = scalac("-script", f("@main def Test = ???", ".sc"))(1)

0 commit comments

Comments
 (0)