Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor CompilerMatcher.scala #618

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}