From 447256c89148e07dfddcfc065bd5f0946b0ae9aa Mon Sep 17 00:00:00 2001
From: VladimirNik <vladimir.nikolaev9@gmail.com>
Date: Mon, 22 Feb 2016 14:50:35 +0100
Subject: [PATCH 1/3] Neg tests: remove xerror parameter from tests (compute
 based on // error)

---
 test/dotc/tests.scala                         |  93 +++------------
 test/test/CompilerTest.scala                  | 109 +++++++++++-------
 tests/neg/Main.scala                          |   4 +-
 .../neg/{ => compExceptions}/structural.scala |   0
 tests/neg/{ => customArgs}/i1050.scala        |   0
 .../neg/{ => customArgs}/overrideClass.scala  |   0
 tests/neg/{ => customArgs}/typers.scala       |   0
 tests/neg/i827.scala                          |   4 +-
 tests/neg/implicitDefs.scala                  |   6 +-
 tests/neg/t1292.scala                         |   4 +-
 tests/neg/t7278.scala                         |   6 +-
 tests/{neg => pos}/patternUnsoundness.scala   |   0
 tests/{neg => pos}/t1164.scala                |   0
 13 files changed, 93 insertions(+), 133 deletions(-)
 rename tests/neg/{ => compExceptions}/structural.scala (100%)
 rename tests/neg/{ => customArgs}/i1050.scala (100%)
 rename tests/neg/{ => customArgs}/overrideClass.scala (100%)
 rename tests/neg/{ => customArgs}/typers.scala (100%)
 rename tests/{neg => pos}/patternUnsoundness.scala (100%)
 rename tests/{neg => pos}/t1164.scala (100%)

diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala
index 0bb27ab1457d..7cc6bafbd3f7 100644
--- a/test/dotc/tests.scala
+++ b/test/dotc/tests.scala
@@ -108,87 +108,22 @@ class tests extends CompilerTest {
 
   @Test def new_all = compileFiles(newDir, twice)
 
-  @Test def neg_abstractOverride() = compileFile(negDir, "abstract-override", xerrors = 2)
-  @Test def neg_blockescapes() = compileFile(negDir, "blockescapesNeg", xerrors = 1)
-  @Test def neg_bounds() = compileFile(negDir, "bounds", xerrors = 2)
-  @Test def neg_functionArity() = compileFile(negDir, "function-arity", xerrors = 7)
-  @Test def neg_typedapply() = compileFile(negDir, "typedapply", xerrors = 3)
-  @Test def neg_typedIdents() = compileDir(negDir, "typedIdents", xerrors = 2)
-  @Test def neg_assignments() = compileFile(negDir, "assignments", xerrors = 3)
-  @Test def neg_typers() = compileFile(negDir, "typers", xerrors = 14)(allowDoubleBindings)
-  @Test def neg_privates() = compileFile(negDir, "privates", xerrors = 2)
-  @Test def neg_rootImports = compileFile(negDir, "rootImplicits", xerrors = 2)
-  @Test def neg_templateParents() = compileFile(negDir, "templateParents", xerrors = 3)
-  @Test def neg_autoTupling = compileFile(posDir, "autoTuplingTest", args = "-language:noAutoTupling" :: Nil, xerrors = 3)
-  @Test def neg_autoTupling2 = compileFile(negDir, "autoTuplingTest", xerrors = 3)
-  @Test def neg_companions = compileFile(negDir, "companions", xerrors = 1)
-  @Test def namedParams = compileFile(negDir, "named-params", xerrors = 14)
-  @Test def neg_over = compileFile(negDir, "over", xerrors = 3)
-  @Test def neg_overrides = compileFile(negDir, "overrides", xerrors = 14)
-  @Test def neg_overrideClass = compileFile(negDir, "overrideClass", List("-language:Scala2"), xerrors = 1)
-  @Test def neg_i39 = compileFile(negDir, "i39", xerrors = 2)
-  @Test def neg_i50_volatile = compileFile(negDir, "i50-volatile", xerrors = 3)
-  @Test def neg_zoo = compileFile(negDir, "zoo", xerrors = 12)
+  @Test def neg_all = compileFiles(negDir, verbose = true, negTest = true, compileSubDirs = false)
+  @Test def neg_typedIdents() = compileDir(negDir, "typedIdents", negTest = true)
+
+  val negCustomArgs = negDir + "customArgs/"
+  @Test def neg_typers() = compileFile(negCustomArgs, "typers", negTest = true)(allowDoubleBindings)
+  @Test def neg_overrideClass = compileFile(negCustomArgs, "overrideClass", List("-language:Scala2"), negTest = true)
+  @Test def neg_autoTupling = compileFile(posDir, "autoTuplingTest", args = "-language:noAutoTupling" :: Nil, negTest = true)
+  @Test def neg_i1050 = compileFile(negCustomArgs, "i1050", List("-strict"), negTest = true)
 
   val negTailcallDir = negDir + "tailcall/"
-  @Test def neg_tailcall_t1672b = compileFile(negTailcallDir, "t1672b", xerrors = 5)
-  @Test def neg_tailcall_t3275 = compileFile(negTailcallDir, "t3275", xerrors = 1)
-  @Test def neg_tailcall_t6574 = compileFile(negTailcallDir, "t6574", xerrors = 2)
-  @Test def neg_tailcall = compileFile(negTailcallDir, "tailrec", xerrors = 7)
-  @Test def neg_tailcall2 = compileFile(negTailcallDir, "tailrec-2", xerrors = 2)
-  @Test def neg_tailcall3 = compileFile(negTailcallDir, "tailrec-3", xerrors = 2)
-
-  @Test def neg_t1843_variances = compileFile(negDir, "t1843-variances", xerrors = 1)
-  @Test def neg_t2660_ambi = compileFile(negDir, "t2660", xerrors = 2)
-  @Test def neg_t2994 = compileFile(negDir, "t2994", xerrors = 2)
-  @Test def neg_subtyping = compileFile(negDir, "subtyping", xerrors = 5)
-  @Test def neg_variances = compileFile(negDir, "variances", xerrors = 2)
-  @Test def neg_variancesConstr = compileFile(negDir, "variances-constr", xerrors = 2)
-  @Test def neg_i871_missingReturnType = compileFile(negDir, "i871", xerrors = 2)
-  @Test def neg_badAuxConstr = compileFile(negDir, "badAuxConstr", xerrors = 2)
-  @Test def neg_typetest = compileFile(negDir, "typetest", xerrors = 1)
-  @Test def neg_t1569_failedAvoid = compileFile(negDir, "t1569-failedAvoid", xerrors = 1)
-  @Test def neg_clashes = compileFile(negDir, "clashes", xerrors = 2)
-  @Test def neg_cycles = compileFile(negDir, "cycles", xerrors = 7)
-  @Test def neg_boundspropagation = compileFile(negDir, "boundspropagation", xerrors = 5)
-  @Test def neg_refinedSubtyping = compileFile(negDir, "refinedSubtyping", xerrors = 2)
-  @Test def neg_hklower = compileFile(negDir, "hklower", xerrors = 4)
-  @Test def neg_Iter2 = compileFile(negDir, "Iter2", xerrors = 2)
-  @Test def neg_i0091_infpaths = compileFile(negDir, "i0091-infpaths", xerrors = 3)
-  @Test def neg_i0248_inherit_refined = compileFile(negDir, "i0248-inherit-refined", xerrors = 4)
-  @Test def neg_i0281 = compileFile(negDir, "i0281-null-primitive-conforms", xerrors = 3)
-  @Test def neg_i324 = compileFile(negDir, "i324", xerrors = 2)
-  @Test def neg_i583 = compileFile(negDir, "i0583-skolemize", xerrors = 2)
-  @Test def neg_i941 = compileFile(negDir, "i941", xerrors = 3)
-  @Test def neg_finalSealed = compileFile(negDir, "final-sealed", xerrors = 2)
-  @Test def neg_i645 = compileFile(negDir, "amp", xerrors = 4)
-  @Test def neg_i705 = compileFile(negDir, "i705-inner-value-class", xerrors = 7)
-  @Test def neg_i803 = compileFile(negDir, "i803", xerrors = 2)
-  @Test def neg_i866 = compileFile(negDir, "i866", xerrors = 2)
-  @Test def neg_i974 = compileFile(negDir, "i974", xerrors = 2)
-  @Test def neg_i997 = compileFile(negDir, "i997", xerrors = 15)
-  @Test def neg_i997a = compileFile(negDir, "i997a", xerrors = 2)
-  @Test def neg_i1050 = compileFile(negDir, "i1050", List("-strict"), xerrors = 11)
-  @Test def neg_i1050a = compileFile(negDir, "i1050a", xerrors = 2)
-  @Test def neg_i1050c = compileFile(negDir, "i1050c", xerrors = 8)
-  @Test def neg_moduleSubtyping = compileFile(negDir, "moduleSubtyping", xerrors = 4)
-  @Test def neg_escapingRefs = compileFile(negDir, "escapingRefs", xerrors = 2)
-  @Test def neg_instantiateAbstract = compileFile(negDir, "instantiateAbstract", xerrors = 8)
-  @Test def neg_partialApplications = compileFile(negDir, "partialApplications", xerrors = 3)
-  @Test def neg_selfInheritance = compileFile(negDir, "selfInheritance", xerrors = 6)
-  @Test def neg_selfreq = compileFile(negDir, "selfreq", xerrors = 2)
-  @Test def neg_singletons = compileFile(negDir, "singletons", xerrors = 8)
-  @Test def neg_ski = compileFile(negDir, "ski", xerrors = 12)
-  @Test def neg_traitParamsTyper = compileFile(negDir, "traitParamsTyper", xerrors = 5)
-  @Test def neg_traitParamsMixin = compileFile(negDir, "traitParamsMixin", xerrors = 2)
-  @Test def neg_firstError = compileFile(negDir, "firstError", xerrors = 3)
-  @Test def neg_implicitLowerBound = compileFile(negDir, "implicit-lower-bound", xerrors = 1)
-  @Test def neg_validate = compileFile(negDir, "validate", xerrors = 18)
-  @Test def neg_validateParsing = compileFile(negDir, "validate-parsing", xerrors = 7)
-  @Test def neg_validateRefchecks = compileFile(negDir, "validate-refchecks", xerrors = 2)
-  @Test def neg_skolemize = compileFile(negDir, "skolemize", xerrors = 2)
-  @Test def neg_nested_bounds = compileFile(negDir, "nested_bounds", xerrors = 1)
-  @Test def neg_valueClasses = compileFile(negDir, "valueClasses", xerrors = 2)
+  @Test def neg_tailcall_t1672b = compileFile(negTailcallDir, "t1672b", negTest = true)
+  @Test def neg_tailcall_t3275 = compileFile(negTailcallDir, "t3275", negTest = true)
+  @Test def neg_tailcall_t6574 = compileFile(negTailcallDir, "t6574", negTest = true)
+  @Test def neg_tailcall = compileFile(negTailcallDir, "tailrec", negTest = true)
+  @Test def neg_tailcall2 = compileFile(negTailcallDir, "tailrec-2", negTest = true)
+  @Test def neg_tailcall3 = compileFile(negTailcallDir, "tailrec-3", negTest = true)
 
   @Test def run_all = runFiles(runDir)
 
diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala
index b8cd88f2d88c..367c36d59c32 100644
--- a/test/test/CompilerTest.scala
+++ b/test/test/CompilerTest.scala
@@ -43,9 +43,9 @@ abstract class CompilerTest {
   val defaultOutputDir: String
 
   /** Override to filter out tests that should not be run by partest. */
-  def partestableFile(prefix: String, fileName: String, extension: String, args: List[String], xerrors: Int) = true
-  def partestableDir(prefix: String, dirName: String, args: List[String], xerrors: Int) = true
-  def partestableList(testName: String, files: List[String], args: List[String], xerrors: Int) = true
+  def partestableFile(prefix: String, fileName: String, extension: String, args: List[String]) = true
+  def partestableDir(prefix: String, dirName: String, args: List[String]) = true
+  def partestableList(testName: String, files: List[String], args: List[String]) = true
 
   val generatePartestFiles = {
     /* Because we fork in test, the JVM in which this JUnit test runs has a
@@ -68,10 +68,10 @@ abstract class CompilerTest {
   val logFile = if (!generatePartestFiles) None else Some(CompilerTest.init)
 
   /** Always run with JUnit. */
-  def compileLine(cmdLine: String, xerrors: Int = 0)(implicit defaultOptions: List[String]): Unit = {
+  def compileLine(cmdLine: String)(implicit defaultOptions: List[String]): Unit = {
     if (generatePartestFiles)
       log("WARNING: compileLine will always run with JUnit, no partest files generated.")
-    compileArgs(cmdLine.split("\n"), xerrors)
+    compileArgs(cmdLine.split("\n"), Nil, negTest = false)
   }
 
   /** Compiles the given code file.
@@ -79,59 +79,72 @@ abstract class CompilerTest {
     * @param prefix    the parent directory (including separator at the end)
     * @param fileName  the filename, by default without extension
     * @param args      arguments to the compiler
-    * @param xerrors   if > 0, this test is a neg test with the expected number
+    * @param negTest   if negTest is true, this test is a neg test with the expected number
     *                  of compiler errors. Otherwise, this is a pos test.
     * @param extension the file extension, .scala by default
     * @param defaultOptions more arguments to the compiler
     */
-  def compileFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0,
+  def compileFile(prefix: String, fileName: String, args: List[String] = Nil, negTest: Boolean = false,
       extension: String = ".scala", runTest: Boolean = false)
       (implicit defaultOptions: List[String]): Unit = {
-    if (!generatePartestFiles || !partestableFile(prefix, fileName, extension, args ++ defaultOptions, xerrors)) {
+    val filePath = s"$prefix$fileName$extension"
+    val expErrors = expectedErrors(filePath, negTest)
+    if (!generatePartestFiles || !partestableFile(prefix, fileName, extension, args ++ defaultOptions)) {
       if (runTest)
         log(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$fileName$extension")
-      compileArgs((s"$prefix$fileName$extension" :: args).toArray, xerrors)
+      compileArgs((s"$filePath" :: args).toArray, expErrors, negTest)
     } else {
-      val kind = testKind(prefix, xerrors, runTest)
+      val kind = testKind(prefix, negTest, runTest)
       log(s"generating partest files for test file: $prefix$fileName$extension of kind $kind")
 
       val sourceFile = new JFile(prefix + fileName + extension)
       if (sourceFile.exists) {
         val firstDest = SFile(DPConfig.testRoot + JFile.separator + kind + JFile.separator + fileName + extension)
+        val xerrors = if (negTest) expErrors.map(_.totalErrors).sum else 0
         computeDestAndCopyFiles(sourceFile, firstDest, kind, args ++ defaultOptions, xerrors.toString)
       } else {
         throw new java.io.FileNotFoundException(s"Unable to locate test file $prefix$fileName")
       }
     }
   }
-  def runFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0,
-      extension: String = ".scala")(implicit defaultOptions: List[String]): Unit =
-    compileFile(prefix, fileName, args, xerrors, extension, true)
+  def runFile(prefix: String, fileName: String, args: List[String] = Nil, negTest: Boolean = false,
+      extension: String = ".scala")(implicit defaultOptions: List[String]): Unit = {
+    compileFile(prefix, fileName, args, negTest, extension, true)
+  }
 
   /** Compiles the code files in the given directory together. If args starts
     * with "-deep", all files in subdirectories (and so on) are included. */
-  def compileDir(prefix: String, dirName: String, args: List[String] = Nil, xerrors: Int = 0, runTest: Boolean = false)
+  def compileDir(prefix: String, dirName: String, args: List[String] = Nil, negTest: Boolean = false, runTest: Boolean = false)
       (implicit defaultOptions: List[String]): Unit = {
-    if (!generatePartestFiles || !partestableDir(prefix, dirName, args ++ defaultOptions, xerrors)) {
-      if (runTest)
-        log(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$dirName")
+    val computeFilePathsAndExpErrors = { () =>
       val dir = Directory(prefix + dirName)
       val (files, normArgs) = args match {
         case "-deep" :: args1 => (dir.deepFiles, args1)
         case _ => (dir.files, args)
       }
-      val fileNames = files.toArray.map(_.toString).filter(name => (name endsWith ".scala") || (name endsWith ".java"))
-      compileArgs(fileNames ++ normArgs, xerrors)
+      val filePaths = files.toArray.map(_.toString).filter(name => (name endsWith ".scala") || (name endsWith ".java"))
+      val expErrors = expectedErrors(filePaths.toList, negTest)
+      (filePaths, normArgs, expErrors)
+    }
+    if (!generatePartestFiles || !partestableDir(prefix, dirName, args ++ defaultOptions)) {
+      if (runTest)
+        log(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$dirName")
+      val (filePaths, normArgs, expErrors) = computeFilePathsAndExpErrors()
+      compileArgs(filePaths ++ normArgs, expErrors, negTest)
     } else {
       val (sourceDir, flags, deep) = args match {
         case "-deep" :: args1 => (flattenDir(prefix, dirName), args1 ++ defaultOptions, "deep")
         case _ => (new JFile(prefix + dirName), args ++ defaultOptions, "shallow")
       }
-      val kind = testKind(prefix, xerrors, runTest)
+      val kind = testKind(prefix, negTest, runTest)
       log(s"generating partest files for test directory ($deep): $prefix$dirName of kind $kind")
 
       if (sourceDir.exists) {
         val firstDest = Directory(DPConfig.testRoot + JFile.separator + kind + JFile.separator + dirName)
+        val xerrors = if (negTest) {
+          val (_, _, expErrors) = computeFilePathsAndExpErrors()
+          expErrors.map(_.totalErrors).sum
+        } else 0
         computeDestAndCopyFiles(sourceDir, firstDest, kind, flags, xerrors.toString)
         if (deep == "deep")
           Directory(sourceDir).deleteRecursively
@@ -140,54 +153,69 @@ abstract class CompilerTest {
       }
     }
   }
-  def runDir(prefix: String, dirName: String, args: List[String] = Nil, xerrors: Int = 0)
+  def runDir(prefix: String, dirName: String, args: List[String] = Nil, negTest: Boolean = false)
       (implicit defaultOptions: List[String]): Unit =
-    compileDir(prefix, dirName, args, xerrors, true)
+    compileDir(prefix, dirName, args, negTest, true)
 
   /** Compiles each source in the directory path separately by calling
     * compileFile resp. compileDir. */
-  def compileFiles(path: String, args: List[String] = Nil, verbose: Boolean = true, runTest: Boolean = false)
-      (implicit defaultOptions: List[String]): Unit = {
+  def compileFiles(path: String, args: List[String] = Nil, verbose: Boolean = true, runTest: Boolean = false,
+                   negTest: Boolean = false, compileSubDirs: Boolean = true)(implicit defaultOptions: List[String]): Unit = {
     val dir = Directory(path)
     val fileNames = dir.files.toArray.map(_.jfile.getName).filter(name => (name endsWith ".scala") || (name endsWith ".java"))
     for (name <- fileNames) {
       if (verbose) log(s"testing $path$name")
-      compileFile(path, name, args, 0, "", runTest)
-    }
-    for (subdir <- dir.dirs) {
-      if (verbose) log(s"testing $subdir")
-      compileDir(path, subdir.jfile.getName, args, 0, runTest)
+      compileFile(path, name, args, negTest, "", runTest)
     }
+    if (compileSubDirs)
+      for (subdir <- dir.dirs) {
+        if (verbose) log(s"testing $subdir")
+        compileDir(path, subdir.jfile.getName, args, negTest, runTest)
+      }
   }
   def runFiles(path: String, args: List[String] = Nil, verbose: Boolean = true)
       (implicit defaultOptions: List[String]): Unit =
     compileFiles(path, args, verbose, true)
 
   /** Compiles the given list of code files. */
-  def compileList(testName: String, files: List[String], args: List[String] = Nil, xerrors: Int = 0)
+  def compileList(testName: String, files: List[String], args: List[String] = Nil, negTest: Boolean = false)
       (implicit defaultOptions: List[String]): Unit = {
-    if (!generatePartestFiles || !partestableList(testName, files, args ++ defaultOptions, xerrors)) {
-      compileArgs((files ++ args).toArray, xerrors)
+    if (!generatePartestFiles || !partestableList(testName, files, args ++ defaultOptions)) {
+      val expErrors = expectedErrors(files, negTest)
+      compileArgs((files ++ args).toArray, expErrors, negTest)
     } else {
       val destDir = Directory(DPConfig.testRoot + JFile.separator + testName)
       files.foreach({ file =>
         val jfile = new JFile(file)
         recCopyFiles(jfile, destDir / jfile.getName)
       })
-      compileDir(DPConfig.testRoot + JFile.separator, testName, args, xerrors)
+      compileDir(DPConfig.testRoot + JFile.separator, testName, args, negTest)
       destDir.deleteRecursively
     }
   }
 
   // ========== HELPERS =============
 
-  private def compileArgs(args: Array[String], xerrors: Int = 0)
+  private def expectedErrors(filePaths: List[String], negTest: Boolean): List[ErrorsInFile] = {
+    if (negTest) {
+      filePaths.map(getErrors(_))
+    } else Nil
+  }
+
+  private def expectedErrors(filePath: String, negTest: Boolean): List[ErrorsInFile] = expectedErrors(List(filePath), negTest)
+
+  private def compileArgs(args: Array[String], expectedErrorsPerFile: List[ErrorsInFile], negTest: Boolean)
       (implicit defaultOptions: List[String]): Unit = {
     val allArgs = args ++ defaultOptions
     val processor = if (allArgs.exists(_.startsWith("#"))) Bench else Main
     val reporter = processor.process(allArgs)
 
     val nerrors = reporter.errorCount
+    val xerrors = (expectedErrorsPerFile map {_.totalErrors}).sum
+    if (negTest)
+      assert((negTest && xerrors > 0), s"No errors found in neg test")
+    else
+      assert((!negTest && xerrors == 0), s"There shouldn't be expected errors in non-neg test")
     assert(nerrors == xerrors, s"Wrong # of errors. Expected: $xerrors, found: $nerrors")
 
     // NEG TEST
@@ -196,11 +224,6 @@ abstract class CompilerTest {
       // reporter didn't record as many errors as its errorCount says
       assert(errorLines.length == nerrors, s"Not enough errors recorded.")
 
-      val allFiles = (allArgs filter {
-          arg => !arg.startsWith("-") && (arg.endsWith(".scala") || arg.endsWith(".java"))
-      }).toList
-      val expectedErrorsPerFile = allFiles.map(getErrors(_))
-
       // Some compiler errors have an associated source position. Each error
       // needs to correspond to a "// error" marker on that line in the source
       // file and vice versa.
@@ -233,7 +256,9 @@ abstract class CompilerTest {
   /** Captures the number of nopos-errors in the given file and the number of
     * errors with a position, represented as a tuple of source line and number
     * of errors on that line. */
-  case class ErrorsInFile(fileName: String, noposErrorNr: Int, posErrorLinesToNr: List[(Int, Int)])
+  case class ErrorsInFile(fileName: String, noposErrorNr: Int, posErrorLinesToNr: List[(Int, Int)]) {
+    def totalErrors = noposErrorNr + posErrorLinesToNr.map(_._2).sum
+  }
 
   /** Extracts the errors expected for the given neg test file. */
   def getErrors(fileName: String): ErrorsInFile = {
@@ -319,9 +344,9 @@ abstract class CompilerTest {
   private val extensionsToCopy = scala.collection.immutable.HashSet("scala", "java")
 
   /** Determines what kind of test to run. */
-  private def testKind(prefixDir: String, xerrors: Int, runTest: Boolean) = {
+  private def testKind(prefixDir: String, negTest: Boolean, runTest: Boolean) = {
     if (runTest) "run"
-    else if (xerrors > 0) "neg"
+    else if (negTest) "neg"
     else if (prefixDir.endsWith("run" + JFile.separator)) {
       log("WARNING: test is being run as pos test despite being in a run directory. " +
         "Use runFile/runDir instead of compileFile/compileDir to do a run test")
diff --git a/tests/neg/Main.scala b/tests/neg/Main.scala
index 2cc7ad50ef2f..24a94d654b58 100644
--- a/tests/neg/Main.scala
+++ b/tests/neg/Main.scala
@@ -17,7 +17,7 @@ object Main extends Driver {
   override def newCompiler(): Compiler = new Compiler
 
   override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Unit = {
-    if (new config.Settings.Setting.SettingDecorator(ctx.base.settings.resident).value) resident(compiler)
-    else super.doCompile(compiler,123)
+    if (new config.Settings.Setting.SettingDecorator(ctx.base.settings.resident).value) resident(compiler) // error
+    else super.doCompile(compiler,123) // error: type mismatch
   }
 }
diff --git a/tests/neg/structural.scala b/tests/neg/compExceptions/structural.scala
similarity index 100%
rename from tests/neg/structural.scala
rename to tests/neg/compExceptions/structural.scala
diff --git a/tests/neg/i1050.scala b/tests/neg/customArgs/i1050.scala
similarity index 100%
rename from tests/neg/i1050.scala
rename to tests/neg/customArgs/i1050.scala
diff --git a/tests/neg/overrideClass.scala b/tests/neg/customArgs/overrideClass.scala
similarity index 100%
rename from tests/neg/overrideClass.scala
rename to tests/neg/customArgs/overrideClass.scala
diff --git a/tests/neg/typers.scala b/tests/neg/customArgs/typers.scala
similarity index 100%
rename from tests/neg/typers.scala
rename to tests/neg/customArgs/typers.scala
diff --git a/tests/neg/i827.scala b/tests/neg/i827.scala
index cc795b590b30..182ffe0b1783 100644
--- a/tests/neg/i827.scala
+++ b/tests/neg/i827.scala
@@ -1,7 +1,7 @@
 trait A { trait Inner }
 trait B { self: A =>
-  trait Inner extends self.Inner
+  trait Inner extends self.Inner // error: cannot merge trait Inner in trait A with trait Inner in trait B as members of type (A & B)(B.this)
 }
 
 
-class C extends C
+class C extends C // error: cyclic inheritance: class C extends itself
diff --git a/tests/neg/implicitDefs.scala b/tests/neg/implicitDefs.scala
index 28ac32656bc7..1489344c862c 100644
--- a/tests/neg/implicitDefs.scala
+++ b/tests/neg/implicitDefs.scala
@@ -5,7 +5,7 @@ import Predef.{any2stringadd => _, StringAdd => _, _}
 
 object implicitDefs {
 
-  implicit val x = 2
-  implicit def y(x: Int) = 3
-  implicit def z(a: x.type): String = ""
+  implicit val x = 2 // error: type of implicit definition needs to be given explicitly
+  implicit def y(x: Int) = 3 // error: result type of implicit definition needs to be given explicitly
+  implicit def z(a: x.type): String = "" // error: implicit conversion may not have a parameter of singleton type
 }
diff --git a/tests/neg/t1292.scala b/tests/neg/t1292.scala
index 69e680320909..de74dc159eaf 100644
--- a/tests/neg/t1292.scala
+++ b/tests/neg/t1292.scala
@@ -1,5 +1,5 @@
 trait Foo[T <: Foo[T, Enum], Enum <: Enumeration] {
-  type StV = Enum#Value
+  type StV = Enum#Value // error: Enum is not a legal path
   type Meta = MegaFoo[T, Enum]
 
   type Slog <: Enumeration
@@ -9,7 +9,7 @@ trait Foo[T <: Foo[T, Enum], Enum <: Enumeration] {
 
 trait MegaFoo[T <: Foo[T, Enum], Enum <: Enumeration] extends Foo[T, Enum] {
   def doSomething(what: T, misc: StV, dog: Meta#Event) = None
-    // error: Meta is not a valid prefix for '#'.
+    // old-error: Meta is not a valid prefix for '#'.
     // The error is correct. Meta is not stable, and it has an abstract type member Slog
   abstract class Event
   object Event
diff --git a/tests/neg/t7278.scala b/tests/neg/t7278.scala
index 9a8292409ee1..7aafbb76fe1e 100644
--- a/tests/neg/t7278.scala
+++ b/tests/neg/t7278.scala
@@ -8,13 +8,13 @@ object Test {
   // should not compile (?)
   // martin says "I'd argue about that"
   // martin retracts his statement: this should not compile
-  type EE[+X <: EC] = X#E
-  type EE2[+X <: EC] = X#E // repeat to get error count to 2
+  type EE[+X <: EC] = X#E // error: X is not a legal path;
+  type EE2[+X <: EC] = X#E // error: X is not a legal path; repeat to get error count to 2
 
   def fail1(): Unit = {
     val b = new B
     var x1: EE[A] = null
-    var x2: EE[B] = new b.E // error: found: B#E, required: A#E
+    var x2: EE[B] = new b.E // old-error: found: B#E, required: A#E
 //    x1 = x2  // gives a prior type error: B#E, required: A#E, masked to get at the real thing.
   }
 
diff --git a/tests/neg/patternUnsoundness.scala b/tests/pos/patternUnsoundness.scala
similarity index 100%
rename from tests/neg/patternUnsoundness.scala
rename to tests/pos/patternUnsoundness.scala
diff --git a/tests/neg/t1164.scala b/tests/pos/t1164.scala
similarity index 100%
rename from tests/neg/t1164.scala
rename to tests/pos/t1164.scala

From 92b6677f3f79bddeaf38c634ba94197e9e805274 Mon Sep 17 00:00:00 2001
From: VladimirNik <vladimir.nikolaev9@gmail.com>
Date: Tue, 23 Feb 2016 19:24:02 +0100
Subject: [PATCH 2/3] Neg tests: remove negTest flag; neg tests are binded to
 neg directory

---
 test/dotc/tests.scala                      | 24 +++----
 test/test/CompilerTest.scala               | 75 ++++++++++------------
 tests/neg/customArgs/autoTuplingTest.scala |  9 +++
 tests/pos/autoTuplingTest.scala            |  4 +-
 4 files changed, 57 insertions(+), 55 deletions(-)
 create mode 100644 tests/neg/customArgs/autoTuplingTest.scala

diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala
index 7cc6bafbd3f7..2d4ed289c9c6 100644
--- a/test/dotc/tests.scala
+++ b/test/dotc/tests.scala
@@ -108,22 +108,22 @@ class tests extends CompilerTest {
 
   @Test def new_all = compileFiles(newDir, twice)
 
-  @Test def neg_all = compileFiles(negDir, verbose = true, negTest = true, compileSubDirs = false)
-  @Test def neg_typedIdents() = compileDir(negDir, "typedIdents", negTest = true)
+  @Test def neg_all = compileFiles(negDir, verbose = true, compileSubDirs = false)
+  @Test def neg_typedIdents() = compileDir(negDir, "typedIdents")
 
   val negCustomArgs = negDir + "customArgs/"
-  @Test def neg_typers() = compileFile(negCustomArgs, "typers", negTest = true)(allowDoubleBindings)
-  @Test def neg_overrideClass = compileFile(negCustomArgs, "overrideClass", List("-language:Scala2"), negTest = true)
-  @Test def neg_autoTupling = compileFile(posDir, "autoTuplingTest", args = "-language:noAutoTupling" :: Nil, negTest = true)
-  @Test def neg_i1050 = compileFile(negCustomArgs, "i1050", List("-strict"), negTest = true)
+  @Test def neg_typers() = compileFile(negCustomArgs, "typers")(allowDoubleBindings)
+  @Test def neg_overrideClass = compileFile(negCustomArgs, "overrideClass", List("-language:Scala2"))
+  @Test def neg_autoTupling = compileFile(negCustomArgs, "autoTuplingTest", args = "-language:noAutoTupling" :: Nil)
+  @Test def neg_i1050 = compileFile(negCustomArgs, "i1050", List("-strict"))
 
   val negTailcallDir = negDir + "tailcall/"
-  @Test def neg_tailcall_t1672b = compileFile(negTailcallDir, "t1672b", negTest = true)
-  @Test def neg_tailcall_t3275 = compileFile(negTailcallDir, "t3275", negTest = true)
-  @Test def neg_tailcall_t6574 = compileFile(negTailcallDir, "t6574", negTest = true)
-  @Test def neg_tailcall = compileFile(negTailcallDir, "tailrec", negTest = true)
-  @Test def neg_tailcall2 = compileFile(negTailcallDir, "tailrec-2", negTest = true)
-  @Test def neg_tailcall3 = compileFile(negTailcallDir, "tailrec-3", negTest = true)
+  @Test def neg_tailcall_t1672b = compileFile(negTailcallDir, "t1672b")
+  @Test def neg_tailcall_t3275 = compileFile(negTailcallDir, "t3275")
+  @Test def neg_tailcall_t6574 = compileFile(negTailcallDir, "t6574")
+  @Test def neg_tailcall = compileFile(negTailcallDir, "tailrec")
+  @Test def neg_tailcall2 = compileFile(negTailcallDir, "tailrec-2")
+  @Test def neg_tailcall3 = compileFile(negTailcallDir, "tailrec-3")
 
   @Test def run_all = runFiles(runDir)
 
diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala
index 367c36d59c32..de81792e0000 100644
--- a/test/test/CompilerTest.scala
+++ b/test/test/CompilerTest.scala
@@ -71,7 +71,7 @@ abstract class CompilerTest {
   def compileLine(cmdLine: String)(implicit defaultOptions: List[String]): Unit = {
     if (generatePartestFiles)
       log("WARNING: compileLine will always run with JUnit, no partest files generated.")
-    compileArgs(cmdLine.split("\n"), Nil, negTest = false)
+    compileArgs(cmdLine.split("\n"), Nil)
   }
 
   /** Compiles the given code file.
@@ -79,42 +79,39 @@ abstract class CompilerTest {
     * @param prefix    the parent directory (including separator at the end)
     * @param fileName  the filename, by default without extension
     * @param args      arguments to the compiler
-    * @param negTest   if negTest is true, this test is a neg test with the expected number
-    *                  of compiler errors. Otherwise, this is a pos test.
     * @param extension the file extension, .scala by default
     * @param defaultOptions more arguments to the compiler
     */
-  def compileFile(prefix: String, fileName: String, args: List[String] = Nil, negTest: Boolean = false,
-      extension: String = ".scala", runTest: Boolean = false)
+  def compileFile(prefix: String, fileName: String, args: List[String] = Nil, extension: String = ".scala", runTest: Boolean = false)
       (implicit defaultOptions: List[String]): Unit = {
     val filePath = s"$prefix$fileName$extension"
-    val expErrors = expectedErrors(filePath, negTest)
+    val expErrors = expectedErrors(filePath)
     if (!generatePartestFiles || !partestableFile(prefix, fileName, extension, args ++ defaultOptions)) {
       if (runTest)
         log(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$fileName$extension")
-      compileArgs((s"$filePath" :: args).toArray, expErrors, negTest)
+      compileArgs((s"$filePath" :: args).toArray, expErrors)
     } else {
-      val kind = testKind(prefix, negTest, runTest)
+      val kind = testKind(prefix, runTest)
       log(s"generating partest files for test file: $prefix$fileName$extension of kind $kind")
 
       val sourceFile = new JFile(prefix + fileName + extension)
       if (sourceFile.exists) {
         val firstDest = SFile(DPConfig.testRoot + JFile.separator + kind + JFile.separator + fileName + extension)
-        val xerrors = if (negTest) expErrors.map(_.totalErrors).sum else 0
+        val xerrors = expErrors.map(_.totalErrors).sum
         computeDestAndCopyFiles(sourceFile, firstDest, kind, args ++ defaultOptions, xerrors.toString)
       } else {
         throw new java.io.FileNotFoundException(s"Unable to locate test file $prefix$fileName")
       }
     }
   }
-  def runFile(prefix: String, fileName: String, args: List[String] = Nil, negTest: Boolean = false,
-      extension: String = ".scala")(implicit defaultOptions: List[String]): Unit = {
-    compileFile(prefix, fileName, args, negTest, extension, true)
+  def runFile(prefix: String, fileName: String, args: List[String] = Nil, extension: String = ".scala")
+       (implicit defaultOptions: List[String]): Unit = {
+    compileFile(prefix, fileName, args, extension, true)
   }
 
   /** Compiles the code files in the given directory together. If args starts
     * with "-deep", all files in subdirectories (and so on) are included. */
-  def compileDir(prefix: String, dirName: String, args: List[String] = Nil, negTest: Boolean = false, runTest: Boolean = false)
+  def compileDir(prefix: String, dirName: String, args: List[String] = Nil, runTest: Boolean = false)
       (implicit defaultOptions: List[String]): Unit = {
     val computeFilePathsAndExpErrors = { () =>
       val dir = Directory(prefix + dirName)
@@ -123,25 +120,25 @@ abstract class CompilerTest {
         case _ => (dir.files, args)
       }
       val filePaths = files.toArray.map(_.toString).filter(name => (name endsWith ".scala") || (name endsWith ".java"))
-      val expErrors = expectedErrors(filePaths.toList, negTest)
+      val expErrors = expectedErrors(filePaths.toList)
       (filePaths, normArgs, expErrors)
     }
     if (!generatePartestFiles || !partestableDir(prefix, dirName, args ++ defaultOptions)) {
       if (runTest)
         log(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$dirName")
       val (filePaths, normArgs, expErrors) = computeFilePathsAndExpErrors()
-      compileArgs(filePaths ++ normArgs, expErrors, negTest)
+      compileArgs(filePaths ++ normArgs, expErrors)
     } else {
       val (sourceDir, flags, deep) = args match {
         case "-deep" :: args1 => (flattenDir(prefix, dirName), args1 ++ defaultOptions, "deep")
         case _ => (new JFile(prefix + dirName), args ++ defaultOptions, "shallow")
       }
-      val kind = testKind(prefix, negTest, runTest)
+      val kind = testKind(prefix, runTest)
       log(s"generating partest files for test directory ($deep): $prefix$dirName of kind $kind")
 
       if (sourceDir.exists) {
         val firstDest = Directory(DPConfig.testRoot + JFile.separator + kind + JFile.separator + dirName)
-        val xerrors = if (negTest) {
+        val xerrors = if (isNegTest(prefix)) {
           val (_, _, expErrors) = computeFilePathsAndExpErrors()
           expErrors.map(_.totalErrors).sum
         } else 0
@@ -153,24 +150,24 @@ abstract class CompilerTest {
       }
     }
   }
-  def runDir(prefix: String, dirName: String, args: List[String] = Nil, negTest: Boolean = false)
+  def runDir(prefix: String, dirName: String, args: List[String] = Nil)
       (implicit defaultOptions: List[String]): Unit =
-    compileDir(prefix, dirName, args, negTest, true)
+    compileDir(prefix, dirName, args, true)
 
   /** Compiles each source in the directory path separately by calling
     * compileFile resp. compileDir. */
   def compileFiles(path: String, args: List[String] = Nil, verbose: Boolean = true, runTest: Boolean = false,
-                   negTest: Boolean = false, compileSubDirs: Boolean = true)(implicit defaultOptions: List[String]): Unit = {
+                   compileSubDirs: Boolean = true)(implicit defaultOptions: List[String]): Unit = {
     val dir = Directory(path)
     val fileNames = dir.files.toArray.map(_.jfile.getName).filter(name => (name endsWith ".scala") || (name endsWith ".java"))
     for (name <- fileNames) {
       if (verbose) log(s"testing $path$name")
-      compileFile(path, name, args, negTest, "", runTest)
+      compileFile(path, name, args, "", runTest)
     }
     if (compileSubDirs)
       for (subdir <- dir.dirs) {
         if (verbose) log(s"testing $subdir")
-        compileDir(path, subdir.jfile.getName, args, negTest, runTest)
+        compileDir(path, subdir.jfile.getName, args, runTest)
       }
   }
   def runFiles(path: String, args: List[String] = Nil, verbose: Boolean = true)
@@ -178,33 +175,31 @@ abstract class CompilerTest {
     compileFiles(path, args, verbose, true)
 
   /** Compiles the given list of code files. */
-  def compileList(testName: String, files: List[String], args: List[String] = Nil, negTest: Boolean = false)
+  def compileList(testName: String, files: List[String], args: List[String] = Nil)
       (implicit defaultOptions: List[String]): Unit = {
     if (!generatePartestFiles || !partestableList(testName, files, args ++ defaultOptions)) {
-      val expErrors = expectedErrors(files, negTest)
-      compileArgs((files ++ args).toArray, expErrors, negTest)
+      val expErrors = expectedErrors(files)
+      compileArgs((files ++ args).toArray, expErrors)
     } else {
       val destDir = Directory(DPConfig.testRoot + JFile.separator + testName)
       files.foreach({ file =>
         val jfile = new JFile(file)
         recCopyFiles(jfile, destDir / jfile.getName)
       })
-      compileDir(DPConfig.testRoot + JFile.separator, testName, args, negTest)
+      compileDir(DPConfig.testRoot + JFile.separator, testName, args)
       destDir.deleteRecursively
     }
   }
 
   // ========== HELPERS =============
 
-  private def expectedErrors(filePaths: List[String], negTest: Boolean): List[ErrorsInFile] = {
-    if (negTest) {
-      filePaths.map(getErrors(_))
-    } else Nil
-  }
+  private def expectedErrors(filePaths: List[String]): List[ErrorsInFile] = if (filePaths.exists(isNegTest(_))) filePaths.map(getErrors(_)) else Nil
+
+  private def expectedErrors(filePath: String): List[ErrorsInFile] = expectedErrors(List(filePath))
 
-  private def expectedErrors(filePath: String, negTest: Boolean): List[ErrorsInFile] = expectedErrors(List(filePath), negTest)
+  private def isNegTest(testPath: String) = testPath.contains(JFile.separator + "neg" + JFile.separator)
 
-  private def compileArgs(args: Array[String], expectedErrorsPerFile: List[ErrorsInFile], negTest: Boolean)
+  private def compileArgs(args: Array[String], expectedErrorsPerFile: List[ErrorsInFile])
       (implicit defaultOptions: List[String]): Unit = {
     val allArgs = args ++ defaultOptions
     val processor = if (allArgs.exists(_.startsWith("#"))) Bench else Main
@@ -212,12 +207,10 @@ abstract class CompilerTest {
 
     val nerrors = reporter.errorCount
     val xerrors = (expectedErrorsPerFile map {_.totalErrors}).sum
-    if (negTest)
-      assert((negTest && xerrors > 0), s"No errors found in neg test")
-    else
-      assert((!negTest && xerrors == 0), s"There shouldn't be expected errors in non-neg test")
-    assert(nerrors == xerrors, s"Wrong # of errors. Expected: $xerrors, found: $nerrors")
-
+    assert(nerrors == xerrors,
+      s"""Wrong # of errors. Expected: $xerrors, found: $nerrors
+         |Files with expected errors: ${expectedErrorsPerFile.collect{ case er if er.totalErrors > 0 => er.fileName} }
+       """.stripMargin)
     // NEG TEST
     if (xerrors > 0) {
       val errorLines = reporter.allErrors.map(_.pos)
@@ -344,9 +337,9 @@ abstract class CompilerTest {
   private val extensionsToCopy = scala.collection.immutable.HashSet("scala", "java")
 
   /** Determines what kind of test to run. */
-  private def testKind(prefixDir: String, negTest: Boolean, runTest: Boolean) = {
+  private def testKind(prefixDir: String, runTest: Boolean) = {
     if (runTest) "run"
-    else if (negTest) "neg"
+    else if (isNegTest(prefixDir)) "neg"
     else if (prefixDir.endsWith("run" + JFile.separator)) {
       log("WARNING: test is being run as pos test despite being in a run directory. " +
         "Use runFile/runDir instead of compileFile/compileDir to do a run test")
diff --git a/tests/neg/customArgs/autoTuplingTest.scala b/tests/neg/customArgs/autoTuplingTest.scala
new file mode 100644
index 000000000000..7321a83827bb
--- /dev/null
+++ b/tests/neg/customArgs/autoTuplingTest.scala
@@ -0,0 +1,9 @@
+object autoTupling {
+
+  val x = Some(1, 2)                                  // error when running with -language:noAutoTupling
+
+  x match {
+    case Some(a, b) => a + b                          // error // error when running with -language:noAutoTupling
+    case None =>
+  }
+}
diff --git a/tests/pos/autoTuplingTest.scala b/tests/pos/autoTuplingTest.scala
index 7321a83827bb..523411a1a410 100644
--- a/tests/pos/autoTuplingTest.scala
+++ b/tests/pos/autoTuplingTest.scala
@@ -1,9 +1,9 @@
 object autoTupling {
 
-  val x = Some(1, 2)                                  // error when running with -language:noAutoTupling
+  val x = Some(1, 2)
 
   x match {
-    case Some(a, b) => a + b                          // error // error when running with -language:noAutoTupling
+    case Some(a, b) => a + b
     case None =>
   }
 }

From 2b8cd5a594c76fa4500f9c50b2bcd9e5c0c3ceae Mon Sep 17 00:00:00 2001
From: VladimirNik <vladimir.nikolaev9@gmail.com>
Date: Thu, 3 Mar 2016 15:50:30 +0100
Subject: [PATCH 3/3] Neg tests: change val computeFilePathsAndExpErrors to def

---
 test/test/CompilerTest.scala | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala
index de81792e0000..678ef74b15a5 100644
--- a/test/test/CompilerTest.scala
+++ b/test/test/CompilerTest.scala
@@ -113,7 +113,7 @@ abstract class CompilerTest {
     * with "-deep", all files in subdirectories (and so on) are included. */
   def compileDir(prefix: String, dirName: String, args: List[String] = Nil, runTest: Boolean = false)
       (implicit defaultOptions: List[String]): Unit = {
-    val computeFilePathsAndExpErrors = { () =>
+    def computeFilePathsAndExpErrors = {
       val dir = Directory(prefix + dirName)
       val (files, normArgs) = args match {
         case "-deep" :: args1 => (dir.deepFiles, args1)
@@ -126,7 +126,7 @@ abstract class CompilerTest {
     if (!generatePartestFiles || !partestableDir(prefix, dirName, args ++ defaultOptions)) {
       if (runTest)
         log(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$dirName")
-      val (filePaths, normArgs, expErrors) = computeFilePathsAndExpErrors()
+      val (filePaths, normArgs, expErrors) = computeFilePathsAndExpErrors
       compileArgs(filePaths ++ normArgs, expErrors)
     } else {
       val (sourceDir, flags, deep) = args match {
@@ -139,7 +139,7 @@ abstract class CompilerTest {
       if (sourceDir.exists) {
         val firstDest = Directory(DPConfig.testRoot + JFile.separator + kind + JFile.separator + dirName)
         val xerrors = if (isNegTest(prefix)) {
-          val (_, _, expErrors) = computeFilePathsAndExpErrors()
+          val (_, _, expErrors) = computeFilePathsAndExpErrors
           expErrors.map(_.totalErrors).sum
         } else 0
         computeDestAndCopyFiles(sourceDir, firstDest, kind, flags, xerrors.toString)