@@ -61,14 +61,13 @@ abstract class CompilerTest extends DottyTest {
61
61
new JFile (" ." + JFile .separator + " tests" + JFile .separator + " locks" + JFile .separator + s " partest- $pid.lock " ).exists
62
62
}
63
63
64
- // Delete generated files from previous run
65
- if (generatePartestFiles)
66
- CompilerTest .init
64
+ // Delete generated files from previous run and create new log
65
+ val logFile = if (! generatePartestFiles) None else Some (CompilerTest .init)
67
66
68
67
/** Always run with JUnit. */
69
68
def compileLine (cmdLine : String , xerrors : Int = 0 )(implicit defaultOptions : List [String ]): Unit = {
70
69
if (generatePartestFiles)
71
- NestUI .echoWarning (" WARNING: compileLine will always run with JUnit, no partest files generated." )
70
+ log (" WARNING: compileLine will always run with JUnit, no partest files generated." )
72
71
compileArgs(cmdLine.split(" \n " ), xerrors)
73
72
}
74
73
@@ -87,11 +86,11 @@ abstract class CompilerTest extends DottyTest {
87
86
(implicit defaultOptions : List [String ]): Unit = {
88
87
if (! generatePartestFiles || ! partestableFile(prefix, fileName, extension, args ++ defaultOptions, xerrors)) {
89
88
if (runTest)
90
- NestUI .echoWarning (s " WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$fileName$extension" )
89
+ log (s " WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$fileName$extension" )
91
90
compileArgs((s " $prefix$fileName$extension" :: args).toArray, xerrors)
92
91
} else {
93
92
val kind = testKind(prefix, xerrors, runTest)
94
- println (s " generating partest files for test file: $prefix$fileName$extension of kind $kind" )
93
+ log (s " generating partest files for test file: $prefix$fileName$extension of kind $kind" )
95
94
96
95
val sourceFile = new JFile (prefix + fileName + extension)
97
96
if (sourceFile.exists) {
@@ -102,8 +101,7 @@ abstract class CompilerTest extends DottyTest {
102
101
}
103
102
}
104
103
}
105
-
106
- def runFile (prefix : String , fileName : String , args : List [String ] = Nil , xerrors : Int = 0 ,
104
+ def runFile (prefix : String , fileName : String , args : List [String ] = Nil , xerrors : Int = 0 ,
107
105
extension : String = " .scala" )(implicit defaultOptions : List [String ]): Unit =
108
106
compileFile(prefix, fileName, args, xerrors, extension, true )
109
107
@@ -113,7 +111,7 @@ abstract class CompilerTest extends DottyTest {
113
111
(implicit defaultOptions : List [String ]): Unit = {
114
112
if (! generatePartestFiles || ! partestableDir(prefix, dirName, args ++ defaultOptions, xerrors)) {
115
113
if (runTest)
116
- NestUI .echoWarning (s " WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$dirName" )
114
+ log (s " WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$dirName" )
117
115
val dir = Directory (prefix + dirName)
118
116
val (files, normArgs) = args match {
119
117
case " -deep" :: args1 => (dir.deepFiles, args1)
@@ -127,21 +125,18 @@ abstract class CompilerTest extends DottyTest {
127
125
case _ => (new JFile (prefix + dirName), args ++ defaultOptions, " shallow" )
128
126
}
129
127
val kind = testKind(prefix, xerrors, runTest)
130
- println (s " generating partest files for test directory ( $deep): $prefix$dirName of kind $kind" )
128
+ log (s " generating partest files for test directory ( $deep): $prefix$dirName of kind $kind" )
131
129
132
130
if (sourceDir.exists) {
133
131
val firstDest = Directory (DPConfig .testRoot + JFile .separator + kind + JFile .separator + dirName)
134
132
computeDestAndCopyFiles(sourceDir, firstDest, kind, flags, xerrors.toString)
135
- if (deep == " deep" ) {
136
- sourceDir.listFiles.foreach(_.delete)
137
- sourceDir.delete
138
- }
133
+ if (deep == " deep" )
134
+ deleteDir(sourceDir)
139
135
} else {
140
136
throw new java.io.FileNotFoundException (s " Unable to locate test dir $prefix$dirName" )
141
137
}
142
138
}
143
139
}
144
-
145
140
def runDir (prefix : String , dirName : String , args : List [String ] = Nil , xerrors : Int = 0 )
146
141
(implicit defaultOptions : List [String ]): Unit =
147
142
compileDir(prefix, dirName, args, xerrors, true )
@@ -153,11 +148,11 @@ abstract class CompilerTest extends DottyTest {
153
148
val dir = Directory (path)
154
149
val fileNames = dir.files.toArray.map(_.jfile.getName).filter(name => (name endsWith " .scala" ) || (name endsWith " .java" ))
155
150
for (name <- fileNames) {
156
- if (verbose) println (s " testing $path$name" )
151
+ if (verbose) log (s " testing $path$name" )
157
152
compileFile(path, name, args, 0 , " " , runTest)
158
153
}
159
154
for (subdir <- dir.dirs) {
160
- if (verbose) println (s " testing $subdir" )
155
+ if (verbose) log (s " testing $subdir" )
161
156
compileDir(path, subdir.jfile.getName, args, 0 , runTest)
162
157
}
163
158
}
@@ -177,6 +172,7 @@ abstract class CompilerTest extends DottyTest {
177
172
recCopyFiles(jfile, destDir / jfile.getName)
178
173
})
179
174
compileDir(DPConfig .testRoot + JFile .separator, testName, args, xerrors)
175
+ deleteDir(destDir.jfile)
180
176
}
181
177
}
182
178
@@ -197,7 +193,7 @@ abstract class CompilerTest extends DottyTest {
197
193
if (runTest) " run"
198
194
else if (xerrors > 0 ) " neg"
199
195
else if (prefixDir.endsWith(" run" + JFile .separator)) {
200
- NestUI .echoWarning (" WARNING: test is being run as pos test despite being in a run directory. " +
196
+ log (" WARNING: test is being run as pos test despite being in a run directory. " +
201
197
" Use runFile/runDir instead of compileFile/compileDir to do a run test" )
202
198
" pos"
203
199
} else " pos"
@@ -246,7 +242,7 @@ abstract class CompilerTest extends DottyTest {
246
242
if (kind == " run" )
247
243
FileManager .copyFile(check.jfile, dest.changeExtension(" check" ).jfile)
248
244
else
249
- NestUI .echoWarning (s " WARNING: ignoring $check for test kind $kind" )
245
+ log (s " WARNING: ignoring $check for test kind $kind" )
250
246
})
251
247
252
248
}
@@ -259,7 +255,7 @@ abstract class CompilerTest extends DottyTest {
259
255
dest.parent.jfile.mkdirs
260
256
FileManager .copyFile(sourceFile.jfile, dest.jfile)
261
257
} else {
262
- NestUI .echoWarning (s " WARNING: ignoring $sf" )
258
+ log (s " WARNING: ignoring $sf" )
263
259
}
264
260
}, { sdir =>
265
261
dest.jfile.mkdirs
@@ -330,14 +326,28 @@ abstract class CompilerTest extends DottyTest {
330
326
destDir.jfile
331
327
}
332
328
329
+ /** Recursively deletes directories (and files). */
330
+ private def deleteDir (dir : JFile ): Unit = {
331
+ val children = dir.listFiles
332
+ if (children != null )
333
+ children.foreach(deleteDir(_))
334
+ dir.delete
335
+ }
336
+
337
+ /** Write either to console (JUnit) or log file (partest). */
338
+ private def log (msg : String ) = logFile.map(_.appendAll(msg + " \n " )).getOrElse(println(msg))
333
339
}
334
340
335
341
object CompilerTest extends App {
336
342
337
- /** Delete generated partest sources from a previous run. */
338
- lazy val init = {
343
+ /** Deletes generated partest sources from a previous run, recreates
344
+ * directory and returns the freshly created log file. */
345
+ lazy val init : SFile = {
339
346
scala.reflect.io.Directory (DPConfig .testRoot).deleteRecursively
340
- new java.io.File (DPConfig .testRoot).mkdirs
347
+ new JFile (DPConfig .testRoot).mkdirs
348
+ val log = (Path (DPConfig .testRoot) / Path (" gen.log" )).createFile(true )
349
+ println(s " CompilerTest is generating tests for partest, log: $log" )
350
+ log
341
351
}
342
352
343
353
// val dotcDir = "/Users/odersky/workspace/dotty/src/dotty/"
0 commit comments