@@ -31,10 +31,10 @@ class BashScriptsTests:
31
31
lazy val testScriptArgs = Seq (
32
32
" a" , " b" , " c" , " -repl" , " -run" , " -script" , " -debug"
33
33
)
34
- lazy val (bashExe,bashPath) =
34
+ lazy val (bashExe, bashPath) =
35
35
val bexe = getBashPath
36
36
val bpath = Paths .get(bexe)
37
- printf(" bashExe: [%s]\n " , bexe)
37
+ // printf("bashExe: [%s]\n", bexe)
38
38
(bexe, bpath)
39
39
40
40
val showArgsScript = testFiles.find(_.getName == " showArgs.sc" ).get.absPath
@@ -44,7 +44,7 @@ class BashScriptsTests:
44
44
45
45
/* verify `dist/bin/scalac` */
46
46
@ Test def verifyScalacArgs =
47
- printf(" scalacPath[%s]\n " ,scalacPath)
47
+ printf(" scalacPath[%s]\n " , scalacPath)
48
48
val commandline = (Seq (scalacPath, " -script" , showArgsScript) ++ testScriptArgs).mkString(" " )
49
49
if bashPath.toFile.exists then
50
50
var cmd = Array (bashExe, " -c" , commandline)
@@ -69,7 +69,7 @@ class BashScriptsTests:
69
69
} yield line
70
70
var fail = false
71
71
printf(" \n " )
72
- var mismatches = List .empty[(String ,String )]
72
+ var mismatches = List .empty[(String , String )]
73
73
for (line, expect) <- output zip expectedOutput do
74
74
printf(" expected: %-17s\n actual : %s\n " , expect, line)
75
75
if line != expect then
@@ -85,12 +85,14 @@ class BashScriptsTests:
85
85
val scriptFile = testFiles.find(_.getName == " scriptPath.sc" ).get
86
86
val expected = s " / ${scriptFile.getName}"
87
87
printf(" ===> verify valid system property script.path is reported by script [%s]\n " , scriptFile.getName)
88
- var cmd = Array (bashExe, " -c" , scriptFile.absPath)
89
- val output = Process (cmd).lazyLines_!
90
- output.foreach { printf(" [%s]\n " ,_) }
91
- val valid = output.exists { _.endsWith(expected) }
92
- if valid then printf(" # valid script.path reported by [%s]\n " ,scriptFile.getName)
93
- assert(valid, s " script ${scriptFile.absPath} did not report valid script.path value " )
88
+ val (exitCode, stdout, stderr) = bashCommand(scriptFile.absPath)
89
+ if exitCode == 0 && ! stderr.exists(_.contains(" Permission denied" )) then
90
+ // var cmd = Array(bashExe, "-c", scriptFile.absPath)
91
+ // val stdout = Process(cmd).lazyLines_!
92
+ stdout.foreach { printf(" ######### [%s]\n " , _) }
93
+ val valid = stdout.exists { _.endsWith(expected) }
94
+ if valid then printf(" # valid script.path reported by [%s]\n " , scriptFile.getName)
95
+ assert(valid, s " script ${scriptFile.absPath} did not report valid script.path value " )
94
96
95
97
/*
96
98
* verify SCALA_OPTS can specify an @argsfile when launching a scala script in `dist/bin/scala`.
@@ -99,23 +101,27 @@ class BashScriptsTests:
99
101
val scriptFile = testFiles.find(_.getName == " classpathReport.sc" ).get
100
102
printf(" ===> verify valid system property script.path is reported by script [%s]\n " , scriptFile.getName)
101
103
val argsfile = createArgsFile() // avoid problems caused by drive letter
102
- val envPairs = List ((" SCALA_OPTS" ,s " @ $argsfile" ))
103
- var cmd = Array (bashExe, " -c" , scriptFile.absPath)
104
- val output : Seq [String ] = Process (cmd,cwd,envPairs:_* ).lazyLines_!.toList
105
- val expected = s " ${cwd.toString}"
106
- val List (line1 : String , line2 : String ) = output.take(2 )
107
- val valid = line2.dropWhile( _ != ' ' ).trim.startsWith(expected)
108
- if valid then printf(s " \n ===> success: classpath begins with %s, as reported by [%s] \n " ,cwd, scriptFile.getName)
109
- assert(valid, s " script ${scriptFile.absPath} did not report valid java.class.path first entry " )
104
+ val envPairs = List ((" SCALA_OPTS" , s " @ $argsfile" ))
105
+ val (exitCode, stdout, stderr) = bashCommand(scriptFile.absPath, envPairs:_* )
106
+ if exitCode != 0 || stderr.exists(_.contains(" Permission denied" )) then
107
+ stderr.foreach { System .err.printf(" stderr [%s]\n " , _) }
108
+ printf(" unable to execute script, return value is %d\n " , exitCode)
109
+ else
110
+ // val stdout: Seq[String] = Process(cmd, cwd, envPairs:_*).lazyLines_!.toList
111
+ val expected = s " ${cwd.toString}"
112
+ val List (line1 : String , line2 : String ) = stdout.take(2 )
113
+ val valid = line2.dropWhile( _ != ' ' ).trim.startsWith(expected)
114
+ if valid then printf(s " \n ===> success: classpath begins with %s, as reported by [%s] \n " , cwd, scriptFile.getName)
115
+ assert(valid, s " script ${scriptFile.absPath} did not report valid java.class.path first entry " )
110
116
111
117
lazy val cwd = Paths .get(dotty.tools.dotc.config.Properties .userDir).toFile
112
118
113
119
def createArgsFile (): String =
114
120
val utfCharset = java.nio.charset.StandardCharsets .UTF_8 .name
115
121
val text = s " -classpath ${cwd.absPath}"
116
- val path = Files .createTempFile(" scriptingTest" ," .args" )
122
+ val path = Files .createTempFile(" scriptingTest" , " .args" )
117
123
Files .write(path, text.getBytes(utfCharset))
118
- path.toFile.getAbsolutePath.replace('\\ ' ,'/' )
124
+ path.toFile.getAbsolutePath.replace('\\ ' , '/' )
119
125
120
126
extension (str : String ) def dropExtension : String =
121
127
str.reverse.dropWhile(_ != '.' ).drop(1 ).reverse
@@ -127,14 +133,26 @@ class BashScriptsTests:
127
133
128
134
def getBashPath : String =
129
135
var whichBash = " "
130
- printf(" osname[%s]\n " , osname)
136
+ // printf("osname[%s]\n", osname)
131
137
if osname.startsWith(" windows" ) then
132
138
whichBash = which(" bash.exe" )
133
139
else
134
140
whichBash = which(" bash" )
135
141
136
142
whichBash
137
143
144
+ def bashCommand (cmdstr : String , envPairs : (String , String )* ): (Int , Seq [String ], Seq [String ]) = {
145
+ import scala .sys .process ._
146
+ val cmd = Seq (bashExe, " -c" , cmdstr)
147
+ val proc = Process (cmd, None , envPairs * )
148
+ var (stdout, stderr) = (List .empty[String ], List .empty[String ])
149
+ val exitVal = proc ! ProcessLogger (
150
+ (out : String ) => stdout ::= out,
151
+ (err : String ) => stderr ::= err
152
+ )
153
+ (exitVal, stdout.reverse, stderr.reverse)
154
+ }
155
+
138
156
def execCmd (command : String , options : String * ): Seq [String ] =
139
157
val cmd = (command :: options.toList).toSeq
140
158
for {
0 commit comments