Skip to content

Commit

Permalink
refactor CompilerMatcher.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Oct 5, 2023
1 parent 506c9af commit 722882a
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 252 deletions.
31 changes: 31 additions & 0 deletions integration/src/test/scala-2.13+/CompilerMatcherBase.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2010 e.e d3si9n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import scala.tools.nsc.interpreter.IMain
import scala.tools.nsc.GenericRunnerSettings
import scala.tools.nsc.interpreter.shell.ReplReporterImpl

trait CompilerMatcherBase {
protected final def imain(s: GenericRunnerSettings): IMainWithLastReq =
new IMain(s, new ReplReporterImpl(s)) with IMainWithLastReq {
override def lastReq = prevRequestList.last
}
}
237 changes: 0 additions & 237 deletions integration/src/test/scala-2.13-/CompilerMatcher.scala

This file was deleted.

30 changes: 30 additions & 0 deletions integration/src/test/scala-2.13-/CompilerMatcherBase.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2010 e.e d3si9n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import scala.tools.nsc.interpreter.IMain
import scala.tools.nsc.GenericRunnerSettings

trait CompilerMatcherBase {
protected final def imain(s: GenericRunnerSettings): IMainWithLastReq =
new IMain(s) with IMainWithLastReq {
override def lastReq = prevRequestList.last
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,14 @@
* THE SOFTWARE.
*/

import scala.language.reflectiveCalls
import org.specs2.matcher._
import java.io.{File}
import scala.tools.nsc.{Settings, GenericRunnerSettings}
import scala.tools.nsc.GenericRunnerSettings
import scala.reflect.internal.util.{SourceFile, BatchSourceFile}
import scala.tools.nsc.io.{PlainFile}
import scala.tools.nsc.reporters.{ConsoleReporter}

class Holder {
var value: Any = _
override def toString: String = value match {
case s: String => s
case ref: AnyRef => ref.toString
case _ => super.toString
}
}

trait CompilerMatcher {
trait CompilerMatcher extends CompilerMatcherBase {
private lazy val bootPathList = List(jarPathOfClass("scala.tools.nsc.Main"),
jarPathOfClass("scala.Option"),
jarPathOfClass("scala.xml.Elem"),
Expand Down Expand Up @@ -93,9 +83,7 @@ trait CompilerMatcher {
sys.error("At least one line of code is required.")
val s = settings(outdir, classpath, usecurrentcp, unchecked,
deprecation, feature, fatalWarnings, lint)
val main = new IMain(s, new scala.tools.nsc.interpreter.shell.ReplReporterImpl(s)) {
def lastReq = prevRequestList.last
}
val main = imain(s)
if (!main.compileSources(files.map(toSourceFile(_)): _*)) {
sys.error(s"""Error compiling: ${ files.mkString(",") }""")
}
Expand Down
30 changes: 30 additions & 0 deletions integration/src/test/scala/Holder.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2010 e.e d3si9n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

class Holder {
var value: Any = _
override def toString: String = value match {
case s: String => s
case ref: AnyRef => ref.toString
case _ => super.toString
}
}
26 changes: 26 additions & 0 deletions integration/src/test/scala/IMainWIthLastReq.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2010 e.e d3si9n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import scala.tools.nsc.interpreter.IMain

trait IMainWithLastReq extends IMain {
def lastReq: Request
}

0 comments on commit 722882a

Please sign in to comment.