@@ -71,50 +71,47 @@ abstract class CompilerTest {
71
71
def compileLine (cmdLine : String )(implicit defaultOptions : List [String ]): Unit = {
72
72
if (generatePartestFiles)
73
73
log(" WARNING: compileLine will always run with JUnit, no partest files generated." )
74
- compileArgs(cmdLine.split(" \n " ), Nil , negTest = false )
74
+ compileArgs(cmdLine.split(" \n " ), Nil )
75
75
}
76
76
77
77
/** Compiles the given code file.
78
78
*
79
79
* @param prefix the parent directory (including separator at the end)
80
80
* @param fileName the filename, by default without extension
81
81
* @param args arguments to the compiler
82
- * @param negTest if negTest is true, this test is a neg test with the expected number
83
- * of compiler errors. Otherwise, this is a pos test.
84
82
* @param extension the file extension, .scala by default
85
83
* @param defaultOptions more arguments to the compiler
86
84
*/
87
- def compileFile (prefix : String , fileName : String , args : List [String ] = Nil , negTest : Boolean = false ,
88
- extension : String = " .scala" , runTest : Boolean = false )
85
+ def compileFile (prefix : String , fileName : String , args : List [String ] = Nil , extension : String = " .scala" , runTest : Boolean = false )
89
86
(implicit defaultOptions : List [String ]): Unit = {
90
87
val filePath = s " $prefix$fileName$extension"
91
- val expErrors = expectedErrors(filePath, negTest )
88
+ val expErrors = expectedErrors(filePath)
92
89
if (! generatePartestFiles || ! partestableFile(prefix, fileName, extension, args ++ defaultOptions)) {
93
90
if (runTest)
94
91
log(s " WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$fileName$extension" )
95
- compileArgs((s " $filePath" :: args).toArray, expErrors, negTest )
92
+ compileArgs((s " $filePath" :: args).toArray, expErrors)
96
93
} else {
97
- val kind = testKind(prefix, negTest, runTest)
94
+ val kind = testKind(prefix, runTest)
98
95
log(s " generating partest files for test file: $prefix$fileName$extension of kind $kind" )
99
96
100
97
val sourceFile = new JFile (prefix + fileName + extension)
101
98
if (sourceFile.exists) {
102
99
val firstDest = SFile (DPConfig .testRoot + JFile .separator + kind + JFile .separator + fileName + extension)
103
- val xerrors = if (negTest) expErrors.map(_.totalErrors).sum else 0
100
+ val xerrors = expErrors.map(_.totalErrors).sum
104
101
computeDestAndCopyFiles(sourceFile, firstDest, kind, args ++ defaultOptions, xerrors.toString)
105
102
} else {
106
103
throw new java.io.FileNotFoundException (s " Unable to locate test file $prefix$fileName" )
107
104
}
108
105
}
109
106
}
110
- def runFile (prefix : String , fileName : String , args : List [String ] = Nil , negTest : Boolean = false ,
111
- extension : String = " .scala " ) (implicit defaultOptions : List [String ]): Unit = {
112
- compileFile(prefix, fileName, args, negTest, extension, true )
107
+ def runFile (prefix : String , fileName : String , args : List [String ] = Nil , extension : String = " .scala " )
108
+ (implicit defaultOptions : List [String ]): Unit = {
109
+ compileFile(prefix, fileName, args, extension, true )
113
110
}
114
111
115
112
/** Compiles the code files in the given directory together. If args starts
116
113
* with "-deep", all files in subdirectories (and so on) are included. */
117
- def compileDir (prefix : String , dirName : String , args : List [String ] = Nil , negTest : Boolean = false , runTest : Boolean = false )
114
+ def compileDir (prefix : String , dirName : String , args : List [String ] = Nil , runTest : Boolean = false )
118
115
(implicit defaultOptions : List [String ]): Unit = {
119
116
val computeFilePathsAndExpErrors = { () =>
120
117
val dir = Directory (prefix + dirName)
@@ -123,25 +120,25 @@ abstract class CompilerTest {
123
120
case _ => (dir.files, args)
124
121
}
125
122
val filePaths = files.toArray.map(_.toString).filter(name => (name endsWith " .scala" ) || (name endsWith " .java" ))
126
- val expErrors = expectedErrors(filePaths.toList, negTest )
123
+ val expErrors = expectedErrors(filePaths.toList)
127
124
(filePaths, normArgs, expErrors)
128
125
}
129
126
if (! generatePartestFiles || ! partestableDir(prefix, dirName, args ++ defaultOptions)) {
130
127
if (runTest)
131
128
log(s " WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$dirName" )
132
129
val (filePaths, normArgs, expErrors) = computeFilePathsAndExpErrors()
133
- compileArgs(filePaths ++ normArgs, expErrors, negTest )
130
+ compileArgs(filePaths ++ normArgs, expErrors)
134
131
} else {
135
132
val (sourceDir, flags, deep) = args match {
136
133
case " -deep" :: args1 => (flattenDir(prefix, dirName), args1 ++ defaultOptions, " deep" )
137
134
case _ => (new JFile (prefix + dirName), args ++ defaultOptions, " shallow" )
138
135
}
139
- val kind = testKind(prefix, negTest, runTest)
136
+ val kind = testKind(prefix, runTest)
140
137
log(s " generating partest files for test directory ( $deep): $prefix$dirName of kind $kind" )
141
138
142
139
if (sourceDir.exists) {
143
140
val firstDest = Directory (DPConfig .testRoot + JFile .separator + kind + JFile .separator + dirName)
144
- val xerrors = if (negTest ) {
141
+ val xerrors = if (isNegTest(prefix) ) {
145
142
val (_, _, expErrors) = computeFilePathsAndExpErrors()
146
143
expErrors.map(_.totalErrors).sum
147
144
} else 0
@@ -153,71 +150,67 @@ abstract class CompilerTest {
153
150
}
154
151
}
155
152
}
156
- def runDir (prefix : String , dirName : String , args : List [String ] = Nil , negTest : Boolean = false )
153
+ def runDir (prefix : String , dirName : String , args : List [String ] = Nil )
157
154
(implicit defaultOptions : List [String ]): Unit =
158
- compileDir(prefix, dirName, args, negTest, true )
155
+ compileDir(prefix, dirName, args, true )
159
156
160
157
/** Compiles each source in the directory path separately by calling
161
158
* compileFile resp. compileDir. */
162
159
def compileFiles (path : String , args : List [String ] = Nil , verbose : Boolean = true , runTest : Boolean = false ,
163
- negTest : Boolean = false , compileSubDirs : Boolean = true )(implicit defaultOptions : List [String ]): Unit = {
160
+ compileSubDirs : Boolean = true )(implicit defaultOptions : List [String ]): Unit = {
164
161
val dir = Directory (path)
165
162
val fileNames = dir.files.toArray.map(_.jfile.getName).filter(name => (name endsWith " .scala" ) || (name endsWith " .java" ))
166
163
for (name <- fileNames) {
167
164
if (verbose) log(s " testing $path$name" )
168
- compileFile(path, name, args, negTest, " " , runTest)
165
+ compileFile(path, name, args, " " , runTest)
169
166
}
170
167
if (compileSubDirs)
171
168
for (subdir <- dir.dirs) {
172
169
if (verbose) log(s " testing $subdir" )
173
- compileDir(path, subdir.jfile.getName, args, negTest, runTest)
170
+ compileDir(path, subdir.jfile.getName, args, runTest)
174
171
}
175
172
}
176
173
def runFiles (path : String , args : List [String ] = Nil , verbose : Boolean = true )
177
174
(implicit defaultOptions : List [String ]): Unit =
178
175
compileFiles(path, args, verbose, true )
179
176
180
177
/** Compiles the given list of code files. */
181
- def compileList (testName : String , files : List [String ], args : List [String ] = Nil , negTest : Boolean = false )
178
+ def compileList (testName : String , files : List [String ], args : List [String ] = Nil )
182
179
(implicit defaultOptions : List [String ]): Unit = {
183
180
if (! generatePartestFiles || ! partestableList(testName, files, args ++ defaultOptions)) {
184
- val expErrors = expectedErrors(files, negTest )
185
- compileArgs((files ++ args).toArray, expErrors, negTest )
181
+ val expErrors = expectedErrors(files)
182
+ compileArgs((files ++ args).toArray, expErrors)
186
183
} else {
187
184
val destDir = Directory (DPConfig .testRoot + JFile .separator + testName)
188
185
files.foreach({ file =>
189
186
val jfile = new JFile (file)
190
187
recCopyFiles(jfile, destDir / jfile.getName)
191
188
})
192
- compileDir(DPConfig .testRoot + JFile .separator, testName, args, negTest )
189
+ compileDir(DPConfig .testRoot + JFile .separator, testName, args)
193
190
destDir.deleteRecursively
194
191
}
195
192
}
196
193
197
194
// ========== HELPERS =============
198
195
199
- private def expectedErrors (filePaths : List [String ], negTest : Boolean ): List [ErrorsInFile ] = {
200
- if (negTest) {
201
- filePaths.map(getErrors(_))
202
- } else Nil
203
- }
196
+ private def expectedErrors (filePaths : List [String ]): List [ErrorsInFile ] = if (filePaths.exists(isNegTest(_))) filePaths.map(getErrors(_)) else Nil
197
+
198
+ private def expectedErrors (filePath : String ): List [ErrorsInFile ] = expectedErrors(List (filePath))
204
199
205
- private def expectedErrors ( filePath : String , negTest : Boolean ) : List [ ErrorsInFile ] = expectedErrors( List (filePath), negTest )
200
+ private def isNegTest ( testPath : String ) = testPath.contains( JFile .separator + " neg " + JFile .separator )
206
201
207
- private def compileArgs (args : Array [String ], expectedErrorsPerFile : List [ErrorsInFile ], negTest : Boolean )
202
+ private def compileArgs (args : Array [String ], expectedErrorsPerFile : List [ErrorsInFile ])
208
203
(implicit defaultOptions : List [String ]): Unit = {
209
204
val allArgs = args ++ defaultOptions
210
205
val processor = if (allArgs.exists(_.startsWith(" #" ))) Bench else Main
211
206
val reporter = processor.process(allArgs)
212
207
213
208
val nerrors = reporter.errorCount
214
209
val xerrors = (expectedErrorsPerFile map {_.totalErrors}).sum
215
- if (negTest)
216
- assert((negTest && xerrors > 0 ), s " No errors found in neg test " )
217
- else
218
- assert((! negTest && xerrors == 0 ), s " There shouldn't be expected errors in non-neg test " )
219
- assert(nerrors == xerrors, s " Wrong # of errors. Expected: $xerrors, found: $nerrors" )
220
-
210
+ assert(nerrors == xerrors,
211
+ s """ Wrong # of errors. Expected: $xerrors, found: $nerrors
212
+ |Files with expected errors: ${expectedErrorsPerFile.collect{ case er if er.totalErrors > 0 => er.fileName} }
213
+ """ .stripMargin)
221
214
// NEG TEST
222
215
if (xerrors > 0 ) {
223
216
val errorLines = reporter.allErrors.map(_.pos)
@@ -344,9 +337,9 @@ abstract class CompilerTest {
344
337
private val extensionsToCopy = scala.collection.immutable.HashSet (" scala" , " java" )
345
338
346
339
/** Determines what kind of test to run. */
347
- private def testKind (prefixDir : String , negTest : Boolean , runTest : Boolean ) = {
340
+ private def testKind (prefixDir : String , runTest : Boolean ) = {
348
341
if (runTest) " run"
349
- else if (negTest ) " neg"
342
+ else if (isNegTest(prefixDir) ) " neg"
350
343
else if (prefixDir.endsWith(" run" + JFile .separator)) {
351
344
log(" WARNING: test is being run as pos test despite being in a run directory. " +
352
345
" Use runFile/runDir instead of compileFile/compileDir to do a run test" )
0 commit comments