<commit_before>package dotty
package tools
package dotc

import org.junit.{ Test, BeforeClass, AfterClass }
import org.junit.Assert._
import org.junit.Assume._
import org.junit.experimental.categories.Category

import java.nio.file._
import java.util.stream.{ Stream => JStream }
import scala.collection.JavaConverters._
import scala.util.matching.Regex
import scala.concurrent.duration._
import vulpix._
import dotty.tools.io.JFile


class CompilationTests extends ParallelTesting {
  import ParallelTesting._
  import TestConfiguration._
  import CompilationTests._

  // Test suite configuration --------------------------------------------------

  def maxDuration = 30.seconds
  def numberOfSlaves = 5
  def safeMode = Properties.testsSafeMode
  def isInteractive = SummaryReport.isInteractive
  def testFilter = Properties.testsFilter

  // Positive tests ------------------------------------------------------------

  // @Test  // enable to test compileStdLib separately with detailed stats
  def compileStdLibOnly: Unit = {
    implicit val testGroup: TestGroup = TestGroup("compileStdLibOnly")
    compileList("compileStdLib", StdLibSources.whitelisted, scala2Mode.and("-migration", "-Yno-inline", "-Ydetailed-stats"))
  }.checkCompile()

  @Test def compilePos: Unit = {
    implicit val testGroup: TestGroup = TestGroup("compilePos")
    compileList("compileStdLib", StdLibSources.whitelisted, scala2Mode.and("-migration", "-Yno-inline")) +
    compileDir("../compiler/src/dotty/tools/dotc/ast", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/config", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/core", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/transform", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/parsing", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/printing", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/reporting", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/typer", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/util", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/io", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/core", TestFlags(classPath, noCheckOptions)) +
    compileFile("../tests/pos/nullarify.scala", defaultOptions.and("-Ycheck:nullarify")) +
    compileFile("../tests/pos-scala2/rewrites.scala", scala2Mode.and("-rewrite")).copyToTarget() +
    compileFile("../tests/pos-special/utf8encoded.scala", explicitUTF8) +
    compileFile("../tests/pos-special/utf16encoded.scala", explicitUTF16) +
    compileFile("../tests/pos-special/i3323.scala", defaultOptions.and("-Xfatal-warnings")) +
    compileFile("../tests/pos-special/i3323b.scala", defaultOptions.and("-Xfatal-warnings")) +
    compileFile("../tests/pos-special/i3589-b.scala", defaultOptions.and("-Xfatal-warnings")) +
    compileList(
      "compileMixed",
      List(
        "../tests/pos/B.scala",
        "../scala2-library/src/library/scala/collection/immutable/Seq.scala",
        "../scala2-library/src/library/scala/collection/parallel/ParSeq.scala",
        "../scala2-library/src/library/scala/package.scala",
        "../scala2-library/src/library/scala/collection/GenSeqLike.scala",
        "../scala2-library/src/library/scala/collection/SeqLike.scala",
        "../scala2-library/src/library/scala/collection/generic/GenSeqFactory.scala"
      ),
      scala2Mode
    ) +
    compileFilesInDir("../tests/pos-special/spec-t5545", defaultOptions) +
    compileFilesInDir("../tests/pos-special/strawman-collections", defaultOptions) +
    compileFile("../scala2-library/src/library/scala/collection/immutable/IndexedSeq.scala", defaultOptions) +
    compileFile("../scala2-library/src/library/scala/collection/parallel/mutable/ParSetLike.scala", defaultOptions) +
    compileList(
      "parSetSubset",
      List(
       "../scala2-library/src/library/scala/collection/parallel/mutable/ParSetLike.scala",
       "../scala2-library/src/library/scala/collection/parallel/mutable/ParSet.scala",
       "../scala2-library/src/library/scala/collection/mutable/SetLike.scala"
      ),
      scala2Mode
    ) +
    // FIXME: This fails with .times(2), see #2799
    compileList(
      "testPredefDeprecatedNonCyclic",
      List(
        "../scala2-library/src/library/scala/io/Position.scala",
        "../scala2-library/src/library/scala/Predef.scala",
        "../scala2-library/src/library/scala/deprecated.scala"
      ),
      scala2Mode
    ) +
    compileFilesInDir("../tests/new", defaultOptions) +
    compileFilesInDir("../tests/pos-scala2", scala2Mode) +
    compileFilesInDir("../tests/pos", defaultOptions) +
    compileFilesInDir("../tests/pos-no-optimise", defaultOptions) +
    compileFilesInDir("../tests/pos-deep-subtype", allowDeepSubtypes) +
    compileDir("../tests/pos/i1137-1", defaultOptions and "-Yemit-tasty") +
    compileFile(
      // succeeds despite -Xfatal-warnings because of -nowarn
      "../tests/neg-custom-args/xfatalWarnings.scala",
      defaultOptions.and("-nowarn", "-Xfatal-warnings")
    )
  }.checkCompile()

  @Test def posTwice: Unit = {
    implicit val testGroup: TestGroup = TestGroup("posTwice")
    compileFile("../tests/pos/Labels.scala", defaultOptions) +
    compileFilesInDir("../tests/pos-java-interop", defaultOptions) +
    compileFilesInDir("../tests/pos-java-interop-separate", defaultOptions) +
    compileFile("../tests/pos/t2168.scala", defaultOptions) +
    compileFile("../tests/pos/erasure.scala", defaultOptions) +
    compileFile("../tests/pos/Coder.scala", defaultOptions) +
    compileFile("../tests/pos/blockescapes.scala", defaultOptions) +
    compileFile("../tests/pos/collections.scala", defaultOptions) +
    compileFile("../tests/pos/functions1.scala", defaultOptions) +
    compileFile("../tests/pos/implicits1.scala", defaultOptions) +
    compileFile("../tests/pos/inferred.scala", defaultOptions) +
    compileFile("../tests/pos/Patterns.scala", defaultOptions) +
    compileFile("../tests/pos/selftypes.scala", defaultOptions) +
    compileFile("../tests/pos/varargs.scala", defaultOptions) +
    compileFile("../tests/pos/vararg-pattern.scala", defaultOptions) +
    compileFile("../tests/pos/opassign.scala", defaultOptions) +
    compileFile("../tests/pos/typedapply.scala", defaultOptions) +
    compileFile("../tests/pos/nameddefaults.scala", defaultOptions) +
    compileFile("../tests/pos/desugar.scala", defaultOptions) +
    compileFile("../tests/pos/sigs.scala", defaultOptions) +
    compileFile("../tests/pos/typers.scala", defaultOptions) +
    compileDir("../tests/pos/typedIdents", defaultOptions) +
    compileFile("../tests/pos/assignments.scala", defaultOptions) +
    compileFile("../tests/pos/packageobject.scala", defaultOptions) +
    compileFile("../tests/pos/overloaded.scala", defaultOptions) +
    compileFile("../tests/pos/overrides.scala", defaultOptions) +
    compileDir("../tests/pos/java-override", defaultOptions) +
    compileFile("../tests/pos/templateParents.scala", defaultOptions) +
    compileFile("../tests/pos/overloadedAccess.scala", defaultOptions) +
    compileFile("../tests/pos/approximateUnion.scala", defaultOptions) +
    compileFilesInDir("../tests/pos/tailcall", defaultOptions) +
    compileShallowFilesInDir("../tests/pos/pos_valueclasses", defaultOptions) +
    compileFile("../tests/pos/subtyping.scala", defaultOptions) +
    compileFile("../tests/pos/i0239.scala", defaultOptions) +
    compileFile("../tests/pos/anonClassSubtyping.scala", defaultOptions) +
    compileFile("../tests/pos/extmethods.scala", defaultOptions) +
    compileFile("../tests/pos/companions.scala", defaultOptions) +
    compileList(
      "testNonCyclic",
      List(
        "../compiler/src/dotty/tools/dotc/CompilationUnit.scala",
        "../compiler/src/dotty/tools/dotc/core/Types.scala",
        "../compiler/src/dotty/tools/dotc/ast/Trees.scala"
      ),
      defaultOptions.and("-Xprompt")
    ) +
    compileList(
      "testIssue34",
      List(
        "../compiler/src/dotty/tools/dotc/config/Properties.scala",
        "../compiler/src/dotty/tools/dotc/config/PathResolver.scala"
      ),
      defaultOptions.and("-Xprompt")
    )
  }.times(2).checkCompile()

  // Negative tests ------------------------------------------------------------

  @Test def compileNeg: Unit = {
    implicit val testGroup: TestGroup = TestGroup("compileNeg")
    compileFilesInDir("../tests/neg", defaultOptions) +
    compileFilesInDir("../tests/neg-tailcall", defaultOptions) +
    compileFilesInDir("../tests/neg-no-optimise", defaultOptions) +
    compileFile("../tests/neg-custom-args/i3246.scala", scala2Mode) +
    compileFile("../tests/neg-custom-args/typers.scala", allowDoubleBindings) +
    compileFile("../tests/neg-custom-args/overrideClass.scala", scala2Mode) +
    compileFile("../tests/neg-custom-args/autoTuplingTest.scala", defaultOptions.and("-language:noAutoTupling")) +
    compileFile("../tests/neg-custom-args/i1050.scala", defaultOptions.and("-strict")) +
    compileFile("../tests/neg-custom-args/i1240.scala", allowDoubleBindings) +
    compileFile("../tests/neg-custom-args/i2002.scala", allowDoubleBindings) +
    compileFile("../tests/neg-custom-args/nopredef.scala", defaultOptions.and("-Yno-predef")) +
    compileFile("../tests/neg-custom-args/noimports.scala", defaultOptions.and("-Yno-imports")) +
    compileFile("../tests/neg-custom-args/noimports2.scala", defaultOptions.and("-Yno-imports")) +
    compileFile("../tests/neg-custom-args/overloadsOnAbstractTypes.scala", allowDoubleBindings) +
    compileFile("../tests/neg-custom-args/xfatalWarnings.scala", defaultOptions.and("-Xfatal-warnings")) +
    compileFile("../tests/neg-custom-args/pureStatement.scala", defaultOptions.and("-Xfatal-warnings")) +
    compileFile("../tests/neg-custom-args/i3589-a.scala", defaultOptions.and("-Xfatal-warnings")) +<commit_msg>Add switch warning test<commit_after>package dotty
package tools
package dotc

import org.junit.{ Test, BeforeClass, AfterClass }
import org.junit.Assert._
import org.junit.Assume._
import org.junit.experimental.categories.Category

import java.nio.file._
import java.util.stream.{ Stream => JStream }
import scala.collection.JavaConverters._
import scala.util.matching.Regex
import scala.concurrent.duration._
import vulpix._
import dotty.tools.io.JFile


class CompilationTests extends ParallelTesting {
  import ParallelTesting._
  import TestConfiguration._
  import CompilationTests._

  // Test suite configuration --------------------------------------------------

  def maxDuration = 30.seconds
  def numberOfSlaves = 5
  def safeMode = Properties.testsSafeMode
  def isInteractive = SummaryReport.isInteractive
  def testFilter = Properties.testsFilter

  // Positive tests ------------------------------------------------------------

  // @Test  // enable to test compileStdLib separately with detailed stats
  def compileStdLibOnly: Unit = {
    implicit val testGroup: TestGroup = TestGroup("compileStdLibOnly")
    compileList("compileStdLib", StdLibSources.whitelisted, scala2Mode.and("-migration", "-Yno-inline", "-Ydetailed-stats"))
  }.checkCompile()

  @Test def compilePos: Unit = {
    implicit val testGroup: TestGroup = TestGroup("compilePos")
    compileList("compileStdLib", StdLibSources.whitelisted, scala2Mode.and("-migration", "-Yno-inline")) +
    compileDir("../compiler/src/dotty/tools/dotc/ast", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/config", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/core", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/transform", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/parsing", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/printing", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/reporting", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/typer", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/util", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/io", defaultOptions) +
    compileDir("../compiler/src/dotty/tools/dotc/core", TestFlags(classPath, noCheckOptions)) +
    compileFile("../tests/pos/nullarify.scala", defaultOptions.and("-Ycheck:nullarify")) +
    compileFile("../tests/pos-scala2/rewrites.scala", scala2Mode.and("-rewrite")).copyToTarget() +
    compileFile("../tests/pos-special/utf8encoded.scala", explicitUTF8) +
    compileFile("../tests/pos-special/utf16encoded.scala", explicitUTF16) +
    compileFile("../tests/pos-special/i3323.scala", defaultOptions.and("-Xfatal-warnings")) +
    compileFile("../tests/pos-special/i3323b.scala", defaultOptions.and("-Xfatal-warnings")) +
    compileFile("../tests/pos-special/i3589-b.scala", defaultOptions.and("-Xfatal-warnings")) +
    compileList(
      "compileMixed",
      List(
        "../tests/pos/B.scala",
        "../scala2-library/src/library/scala/collection/immutable/Seq.scala",
        "../scala2-library/src/library/scala/collection/parallel/ParSeq.scala",
        "../scala2-library/src/library/scala/package.scala",
        "../scala2-library/src/library/scala/collection/GenSeqLike.scala",
        "../scala2-library/src/library/scala/collection/SeqLike.scala",
        "../scala2-library/src/library/scala/collection/generic/GenSeqFactory.scala"
      ),
      scala2Mode
    ) +
    compileFilesInDir("../tests/pos-special/spec-t5545", defaultOptions) +
    compileFilesInDir("../tests/pos-special/strawman-collections", defaultOptions) +
    compileFile("../scala2-library/src/library/scala/collection/immutable/IndexedSeq.scala", defaultOptions) +
    compileFile("../scala2-library/src/library/scala/collection/parallel/mutable/ParSetLike.scala", defaultOptions) +
    compileList(
      "parSetSubset",
      List(
       "../scala2-library/src/library/scala/collection/parallel/mutable/ParSetLike.scala",
       "../scala2-library/src/library/scala/collection/parallel/mutable/ParSet.scala",
       "../scala2-library/src/library/scala/collection/mutable/SetLike.scala"
      ),
      scala2Mode
    ) +
    // FIXME: This fails with .times(2), see #2799
    compileList(
      "testPredefDeprecatedNonCyclic",
      List(
        "../scala2-library/src/library/scala/io/Position.scala",
        "../scala2-library/src/library/scala/Predef.scala",
        "../scala2-library/src/library/scala/deprecated.scala"
      ),
      scala2Mode
    ) +
    compileFilesInDir("../tests/new", defaultOptions) +
    compileFilesInDir("../tests/pos-scala2", scala2Mode) +
    compileFilesInDir("../tests/pos", defaultOptions) +
    compileFilesInDir("../tests/pos-no-optimise", defaultOptions) +
    compileFilesInDir("../tests/pos-deep-subtype", allowDeepSubtypes) +
    compileDir("../tests/pos/i1137-1", defaultOptions and "-Yemit-tasty") +
    compileFile(
      // succeeds despite -Xfatal-warnings because of -nowarn
      "../tests/neg-custom-args/xfatalWarnings.scala",
      defaultOptions.and("-nowarn", "-Xfatal-warnings")
    )
  }.checkCompile()

  @Test def posTwice: Unit = {
    implicit val testGroup: TestGroup = TestGroup("posTwice")
    compileFile("../tests/pos/Labels.scala", defaultOptions) +
    compileFilesInDir("../tests/pos-java-interop", defaultOptions) +
    compileFilesInDir("../tests/pos-java-interop-separate", defaultOptions) +
    compileFile("../tests/pos/t2168.scala", defaultOptions) +
    compileFile("../tests/pos/erasure.scala", defaultOptions) +
    compileFile("../tests/pos/Coder.scala", defaultOptions) +
    compileFile("../tests/pos/blockescapes.scala", defaultOptions) +
    compileFile("../tests/pos/collections.scala", defaultOptions) +
    compileFile("../tests/pos/functions1.scala", defaultOptions) +
    compileFile("../tests/pos/implicits1.scala", defaultOptions) +
    compileFile("../tests/pos/inferred.scala", defaultOptions) +
    compileFile("../tests/pos/Patterns.scala", defaultOptions) +
    compileFile("../tests/pos/selftypes.scala", defaultOptions) +
    compileFile("../tests/pos/varargs.scala", defaultOptions) +
    compileFile("../tests/pos/vararg-pattern.scala", defaultOptions) +
    compileFile("../tests/pos/opassign.scala", defaultOptions) +
    compileFile("../tests/pos/typedapply.scala", defaultOptions) +
    compileFile("../tests/pos/nameddefaults.scala", defaultOptions) +
    compileFile("../tests/pos/desugar.scala", defaultOptions) +
    compileFile("../tests/pos/sigs.scala", defaultOptions) +
    compileFile("../tests/pos/typers.scala", defaultOptions) +
    compileDir("../tests/pos/typedIdents", defaultOptions) +
    compileFile("../tests/pos/assignments.scala", defaultOptions) +
    compileFile("../tests/pos/packageobject.scala", defaultOptions) +
    compileFile("../tests/pos/overloaded.scala", defaultOptions) +
    compileFile("../tests/pos/overrides.scala", defaultOptions) +
    compileDir("../tests/pos/java-override", defaultOptions) +
    compileFile("../tests/pos/templateParents.scala", defaultOptions) +
    compileFile("../tests/pos/overloadedAccess.scala", defaultOptions) +
    compileFile("../tests/pos/approximateUnion.scala", defaultOptions) +
    compileFilesInDir("../tests/pos/tailcall", defaultOptions) +
    compileShallowFilesInDir("../tests/pos/pos_valueclasses", defaultOptions) +
    compileFile("../tests/pos/subtyping.scala", defaultOptions) +
    compileFile("../tests/pos/i0239.scala", defaultOptions) +
    compileFile("../tests/pos/anonClassSubtyping.scala", defaultOptions) +
    compileFile("../tests/pos/extmethods.scala", defaultOptions) +
    compileFile("../tests/pos/companions.scala", defaultOptions) +
    compileList(
      "testNonCyclic",
      List(
        "../compiler/src/dotty/tools/dotc/CompilationUnit.scala",
        "../compiler/src/dotty/tools/dotc/core/Types.scala",
        "../compiler/src/dotty/tools/dotc/ast/Trees.scala"
      ),
      defaultOptions.and("-Xprompt")
    ) +
    compileList(
      "testIssue34",
      List(
        "../compiler/src/dotty/tools/dotc/config/Properties.scala",
        "../compiler/src/dotty/tools/dotc/config/PathResolver.scala"
      ),
      defaultOptions.and("-Xprompt")
    )
  }.times(2).checkCompile()

  // Negative tests ------------------------------------------------------------

  @Test def compileNeg: Unit = {
    implicit val testGroup: TestGroup = TestGroup("compileNeg")
    compileFilesInDir("../tests/neg", defaultOptions) +
    compileFilesInDir("../tests/neg-tailcall", defaultOptions) +
    compileFilesInDir("../tests/neg-no-optimise", defaultOptions) +
    compileFile("../tests/neg-custom-args/i3246.scala", scala2Mode) +
    compileFile("../tests/neg-custom-args/typers.scala", allowDoubleBindings) +
    compileFile("../tests/neg-custom-args/overrideClass.scala", scala2Mode) +
    compileFile("../tests/neg-custom-args/autoTuplingTest.scala", defaultOptions.and("-language:noAutoTupling")) +
    compileFile("../tests/neg-custom-args/i1050.scala", defaultOptions.and("-strict")) +
    compileFile("../tests/neg-custom-args/i1240.scala", allowDoubleBindings) +
    compileFile("../tests/neg-custom-args/i2002.scala", allowDoubleBindings) +
    compileFile("../tests/neg-custom-args/nopredef.scala", defaultOptions.and("-Yno-predef")) +
    compileFile("../tests/neg-custom-args/noimports.scala", defaultOptions.and("-Yno-imports")) +
    compileFile("../tests/neg-custom-args/noimports2.scala", defaultOptions.and("-Yno-imports")) +
    compileFile("../tests/neg-custom-args/overloadsOnAbstractTypes.scala", allowDoubleBindings) +
    compileFile("../tests/neg-custom-args/xfatalWarnings.scala", defaultOptions.and("-Xfatal-warnings")) +
    compileFile("../tests/neg-custom-args/i3561.scala", defaultOptions.and("-Xfatal-warnings")) +
    compileFile("../tests/neg-custom-args/pureStatement.scala", defaultOptions.and("-Xfatal-warnings")) +
    compileFile("../tests/neg-custom-args/i3589-a.scala", defaultOptions.and("-Xfatal-warnings")) +
{'fraction_non_alphanumeric': 0.1802551579786704, 'fraction_numerical': 0.00956842420013954, 'mean_word_length': 3.4692650334075723, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '672171', 'n_tokens_mistral': 6354, 'n_tokens_neox': 6092, 'n_words': 691}