@@ -71,50 +71,47 @@ abstract class CompilerTest {
7171 def compileLine (cmdLine : String )(implicit defaultOptions : List [String ]): Unit = {
7272 if (generatePartestFiles)
7373 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 )
7575 }
7676
7777 /** Compiles the given code file.
7878 *
7979 * @param prefix the parent directory (including separator at the end)
8080 * @param fileName the filename, by default without extension
8181 * @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.
8482 * @param extension the file extension, .scala by default
8583 * @param defaultOptions more arguments to the compiler
8684 */
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 )
8986 (implicit defaultOptions : List [String ]): Unit = {
9087 val filePath = s " $prefix$fileName$extension"
91- val expErrors = expectedErrors(filePath, negTest )
88+ val expErrors = expectedErrors(filePath)
9289 if (! generatePartestFiles || ! partestableFile(prefix, fileName, extension, args ++ defaultOptions)) {
9390 if (runTest)
9491 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)
9693 } else {
97- val kind = testKind(prefix, negTest, runTest)
94+ val kind = testKind(prefix, runTest)
9895 log(s " generating partest files for test file: $prefix$fileName$extension of kind $kind" )
9996
10097 val sourceFile = new JFile (prefix + fileName + extension)
10198 if (sourceFile.exists) {
10299 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
104101 computeDestAndCopyFiles(sourceFile, firstDest, kind, args ++ defaultOptions, xerrors.toString)
105102 } else {
106103 throw new java.io.FileNotFoundException (s " Unable to locate test file $prefix$fileName" )
107104 }
108105 }
109106 }
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 )
113110 }
114111
115112 /** Compiles the code files in the given directory together. If args starts
116113 * 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 )
118115 (implicit defaultOptions : List [String ]): Unit = {
119116 val computeFilePathsAndExpErrors = { () =>
120117 val dir = Directory (prefix + dirName)
@@ -123,25 +120,25 @@ abstract class CompilerTest {
123120 case _ => (dir.files, args)
124121 }
125122 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)
127124 (filePaths, normArgs, expErrors)
128125 }
129126 if (! generatePartestFiles || ! partestableDir(prefix, dirName, args ++ defaultOptions)) {
130127 if (runTest)
131128 log(s " WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$dirName" )
132129 val (filePaths, normArgs, expErrors) = computeFilePathsAndExpErrors()
133- compileArgs(filePaths ++ normArgs, expErrors, negTest )
130+ compileArgs(filePaths ++ normArgs, expErrors)
134131 } else {
135132 val (sourceDir, flags, deep) = args match {
136133 case " -deep" :: args1 => (flattenDir(prefix, dirName), args1 ++ defaultOptions, " deep" )
137134 case _ => (new JFile (prefix + dirName), args ++ defaultOptions, " shallow" )
138135 }
139- val kind = testKind(prefix, negTest, runTest)
136+ val kind = testKind(prefix, runTest)
140137 log(s " generating partest files for test directory ( $deep): $prefix$dirName of kind $kind" )
141138
142139 if (sourceDir.exists) {
143140 val firstDest = Directory (DPConfig .testRoot + JFile .separator + kind + JFile .separator + dirName)
144- val xerrors = if (negTest ) {
141+ val xerrors = if (isNegTest(prefix) ) {
145142 val (_, _, expErrors) = computeFilePathsAndExpErrors()
146143 expErrors.map(_.totalErrors).sum
147144 } else 0
@@ -153,71 +150,67 @@ abstract class CompilerTest {
153150 }
154151 }
155152 }
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 )
157154 (implicit defaultOptions : List [String ]): Unit =
158- compileDir(prefix, dirName, args, negTest, true )
155+ compileDir(prefix, dirName, args, true )
159156
160157 /** Compiles each source in the directory path separately by calling
161158 * compileFile resp. compileDir. */
162159 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 = {
164161 val dir = Directory (path)
165162 val fileNames = dir.files.toArray.map(_.jfile.getName).filter(name => (name endsWith " .scala" ) || (name endsWith " .java" ))
166163 for (name <- fileNames) {
167164 if (verbose) log(s " testing $path$name" )
168- compileFile(path, name, args, negTest, " " , runTest)
165+ compileFile(path, name, args, " " , runTest)
169166 }
170167 if (compileSubDirs)
171168 for (subdir <- dir.dirs) {
172169 if (verbose) log(s " testing $subdir" )
173- compileDir(path, subdir.jfile.getName, args, negTest, runTest)
170+ compileDir(path, subdir.jfile.getName, args, runTest)
174171 }
175172 }
176173 def runFiles (path : String , args : List [String ] = Nil , verbose : Boolean = true )
177174 (implicit defaultOptions : List [String ]): Unit =
178175 compileFiles(path, args, verbose, true )
179176
180177 /** 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 )
182179 (implicit defaultOptions : List [String ]): Unit = {
183180 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)
186183 } else {
187184 val destDir = Directory (DPConfig .testRoot + JFile .separator + testName)
188185 files.foreach({ file =>
189186 val jfile = new JFile (file)
190187 recCopyFiles(jfile, destDir / jfile.getName)
191188 })
192- compileDir(DPConfig .testRoot + JFile .separator, testName, args, negTest )
189+ compileDir(DPConfig .testRoot + JFile .separator, testName, args)
193190 destDir.deleteRecursively
194191 }
195192 }
196193
197194 // ========== HELPERS =============
198195
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))
204199
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 )
206201
207- private def compileArgs (args : Array [String ], expectedErrorsPerFile : List [ErrorsInFile ], negTest : Boolean )
202+ private def compileArgs (args : Array [String ], expectedErrorsPerFile : List [ErrorsInFile ])
208203 (implicit defaultOptions : List [String ]): Unit = {
209204 val allArgs = args ++ defaultOptions
210205 val processor = if (allArgs.exists(_.startsWith(" #" ))) Bench else Main
211206 val reporter = processor.process(allArgs)
212207
213208 val nerrors = reporter.errorCount
214209 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)
221214 // NEG TEST
222215 if (xerrors > 0 ) {
223216 val errorLines = reporter.allErrors.map(_.pos)
@@ -344,9 +337,9 @@ abstract class CompilerTest {
344337 private val extensionsToCopy = scala.collection.immutable.HashSet (" scala" , " java" )
345338
346339 /** 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 ) = {
348341 if (runTest) " run"
349- else if (negTest ) " neg"
342+ else if (isNegTest(prefixDir) ) " neg"
350343 else if (prefixDir.endsWith(" run" + JFile .separator)) {
351344 log(" WARNING: test is being run as pos test despite being in a run directory. " +
352345 " Use runFile/runDir instead of compileFile/compileDir to do a run test" )
0 commit comments