From ac183a3cc3df2fb5640496a2d3a54ae0db16a5c6 Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Thu, 26 Sep 2024 12:08:03 +0200 Subject: [PATCH] Extract integration tests tied to Ammonite REPL to a separate trait --- .../ReplAmmoniteTestDefinitions.scala | 236 ++++++++++++++++++ ...ReplAmmoniteTests3StableDefinitions.scala} | 54 +++- .../cli/integration/ReplTestDefinitions.scala | 190 +------------- .../scala/cli/integration/ReplTests212.scala | 2 +- .../scala/cli/integration/ReplTests213.scala | 46 +--- .../scala/cli/integration/ReplTests3Lts.scala | 5 +- .../cli/integration/ReplTestsDefault.scala | 57 +---- 7 files changed, 301 insertions(+), 289 deletions(-) create mode 100644 modules/integration/src/test/scala/scala/cli/integration/ReplAmmoniteTestDefinitions.scala rename modules/integration/src/test/scala/scala/cli/integration/{ReplTests3StableDefinitions.scala => ReplAmmoniteTests3StableDefinitions.scala} (52%) diff --git a/modules/integration/src/test/scala/scala/cli/integration/ReplAmmoniteTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/ReplAmmoniteTestDefinitions.scala new file mode 100644 index 0000000000..6bea1dfbcf --- /dev/null +++ b/modules/integration/src/test/scala/scala/cli/integration/ReplAmmoniteTestDefinitions.scala @@ -0,0 +1,236 @@ +package scala.cli.integration + +import com.eed3si9n.expecty.Expecty.expect + +import scala.cli.integration.TestUtil.removeAnsiColors +import scala.util.Properties + +trait ReplAmmoniteTestDefinitions { _: ReplTestDefinitions => + protected val retrieveScalaVersionCode: String = if (actualScalaVersion.startsWith("2.")) + "scala.util.Properties.versionNumberString" + else "dotty.tools.dotc.config.Properties.simpleVersionString" + + def expectedScalaVersionForAmmonite: String = + actualScalaVersion match { + case s + if s.startsWith("2.12") && + Constants.maxAmmoniteScala212Version.coursierVersion < s.coursierVersion => + Constants.maxAmmoniteScala212Version + case s + if s.startsWith("2.13") && + Constants.maxAmmoniteScala213Version.coursierVersion < s.coursierVersion => + Constants.maxAmmoniteScala213Version + case s + if s.startsWith("3") && + Constants.maxAmmoniteScala3Version.coursierVersion < s.coursierVersion => + Constants.maxAmmoniteScala3Version + case s => s + } + + def actualMaxAmmoniteScalaVersion: String = + if (actualScalaVersion.startsWith("3")) Constants.maxAmmoniteScala3Version + else if (actualScalaVersion.startsWith("2.13")) Constants.maxAmmoniteScala213Version + else Constants.maxAmmoniteScala212Version + + def ammoniteExtraOptions: Seq[String] = + Seq("--scala", actualMaxAmmoniteScalaVersion) ++ TestUtil.extraOptions + + def ammoniteTest(useMaxAmmoniteScalaVersion: Boolean): Unit = { + TestInputs.empty.fromRoot { root => + val testExtraOptions = if (useMaxAmmoniteScalaVersion) ammoniteExtraOptions else extraOptions + val ammArgs = Seq( + "-c", + s"""println("Hello" + " from Scala " + $retrieveScalaVersionCode)""" + ) + .map { + if (Properties.isWin) + a => if (a.contains(" ")) "\"" + a.replace("\"", "\\\"") + "\"" else a + else + identity + } + .flatMap(arg => Seq("--ammonite-arg", arg)) + val res = + os.proc(TestUtil.cli, "--power", "repl", testExtraOptions, "--ammonite", ammArgs) + .call(cwd = root, stderr = os.Pipe) + val output = res.out.trim() + val expectedSv = + if (useMaxAmmoniteScalaVersion) actualMaxAmmoniteScalaVersion + else expectedScalaVersionForAmmonite + expect(output == s"Hello from Scala $expectedSv") + if (useMaxAmmoniteScalaVersion) { + // the maximum Scala version supported by ammonite is being used, so we shouldn't downgrade + val errOutput = res.err.trim() + expect(!errOutput.contains("not yet supported with this version of Ammonite")) + } + } + } + + def ammoniteTestScope(useMaxAmmoniteScalaVersion: Boolean): Unit = { + val message = "something something ammonite" + TestInputs( + os.rel / "example" / "TestScopeExample.test.scala" -> + s"""package example + | + |object TestScopeExample { + | def message: String = "$message" + |} + |""".stripMargin + ).fromRoot { root => + val testExtraOptions = if (useMaxAmmoniteScalaVersion) ammoniteExtraOptions else extraOptions + val ammArgs = Seq("-c", "println(example.TestScopeExample.message)") + .map { + if (Properties.isWin) + a => if (a.contains(" ")) "\"" + a.replace("\"", "\\\"") + "\"" else a + else + identity + } + .flatMap(arg => Seq("--ammonite-arg", arg)) + val res = + os.proc( + TestUtil.cli, + "--power", + "repl", + ".", + testExtraOptions, + "--test", + "--ammonite", + ammArgs + ) + .call(cwd = root, stderr = os.Pipe) + val output = res.out.trim() + expect(output == message) + if (useMaxAmmoniteScalaVersion) { + // the maximum Scala version supported by ammonite is being used, so we shouldn't downgrade + val errOutput = res.err.trim() + expect(!errOutput.contains("not yet supported with this version of Ammonite")) + } + } + } + + def ammoniteScalapyTest(useMaxAmmoniteScalaVersion: Boolean): Unit = { + val testExtraOptions = if (useMaxAmmoniteScalaVersion) ammoniteExtraOptions else extraOptions + val inputs = TestInputs( + os.rel / "foo" / "something.py" -> + """messageStart = 'Hello from' + |messageEnd = 'ScalaPy' + |""".stripMargin + ) + inputs.fromRoot { root => + val ammArgs = Seq( + "-c", + s"""println("Hello" + " from Scala " + $retrieveScalaVersionCode) + |val sth = py.module("foo.something") + |py.Dynamic.global.applyDynamicNamed("print")("" -> sth.messageStart, "" -> sth.messageEnd, "flush" -> py.Any.from(true)) + |""".stripMargin + ) + .map { + if (Properties.isWin) + a => if (a.contains(" ")) "\"" + a.replace("\"", "\\\"") + "\"" else a + else + identity + } + .flatMap(arg => Seq("--ammonite-arg", arg)) + + val errorRes = os.proc( + TestUtil.cli, + "--power", + "repl", + testExtraOptions, + "--ammonite", + "--python", + ammArgs + ).call( + cwd = root, + env = Map("PYTHONSAFEPATH" -> "foo"), + mergeErrIntoOut = true, + check = false + ) + expect(errorRes.exitCode != 0) + val errorOutput = errorRes.out.text() + expect(errorOutput.contains("No module named 'foo'")) + + val res = os.proc( + TestUtil.cli, + "--power", + "repl", + testExtraOptions, + "--ammonite", + "--python", + ammArgs + ).call(cwd = root, stderr = os.Pipe) + val expectedSv = + if (useMaxAmmoniteScalaVersion) actualMaxAmmoniteScalaVersion + else expectedScalaVersionForAmmonite + val lines = res.out.trim().linesIterator.toVector + expect(lines == Seq(s"Hello from Scala $expectedSv", "Hello from ScalaPy")) + if (useMaxAmmoniteScalaVersion) + // the maximum Scala version supported by ammonite is being used, so we shouldn't downgrade + expect(!res.err.trim().contains("not yet supported with this version of Ammonite")) + } + } + + def ammoniteMaxVersionString: String = + if (actualScalaVersion == actualMaxAmmoniteScalaVersion) "" + else s" with Scala $actualMaxAmmoniteScalaVersion (the latest supported version)" + + test(s"ammonite$ammoniteMaxVersionString") { + ammoniteTest(useMaxAmmoniteScalaVersion = true) + } + + test(s"ammonite scalapy$ammoniteMaxVersionString") { + ammoniteScalapyTest(useMaxAmmoniteScalaVersion = true) + } + + test("ammonite with test scope sources") { + ammoniteTestScope(useMaxAmmoniteScalaVersion = true) + } + + test("default ammonite version in help") { + TestInputs.empty.fromRoot { root => + val res = os.proc(TestUtil.cli, "--power", "repl", extraOptions, "--help").call(cwd = root) + val lines = removeAnsiColors(res.out.trim()).linesIterator.toVector + val ammVersionHelp = lines.find(_.contains("--ammonite-ver")).getOrElse("") + expect(ammVersionHelp.contains(s"(${Constants.ammoniteVersion} by default)")) + } + } + + def ammoniteWithExtraJarTest(): Unit = { + TestInputs.empty.fromRoot { root => + val ammArgs = Seq( + "-c", + """import shapeless._; println("Here's an HList: " + (2 :: true :: "a" :: HNil))""" + ) + .map { + if (Properties.isWin) + a => if (a.contains(" ")) "\"" + a.replace("\"", "\\\"") + "\"" else a + else + identity + } + .flatMap(arg => Seq("--ammonite-arg", arg)) + val shapelessJar = + os.proc(TestUtil.cs, "fetch", "--intransitive", "com.chuusai:shapeless_2.13:2.3.7") + .call() + .out + .text() + .trim + val cmd = Seq[os.Shellable]( + TestUtil.cli, + "--power", + "repl", + ammoniteExtraOptions, + "--jar", + shapelessJar, + "--ammonite", + ammArgs + ) + val res = os.proc(cmd).call(cwd = root) + val output = res.out.trim() + expect(output == "Here's an HList: 2 :: true :: a :: HNil") + } + } + + if (actualScalaVersion.startsWith("2.13")) + test(s"ammonite with extra JAR$ammoniteMaxVersionString") { + ammoniteWithExtraJarTest() + } +} diff --git a/modules/integration/src/test/scala/scala/cli/integration/ReplTests3StableDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/ReplAmmoniteTests3StableDefinitions.scala similarity index 52% rename from modules/integration/src/test/scala/scala/cli/integration/ReplTests3StableDefinitions.scala rename to modules/integration/src/test/scala/scala/cli/integration/ReplAmmoniteTests3StableDefinitions.scala index 5282286092..46af915f46 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/ReplTests3StableDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/ReplAmmoniteTests3StableDefinitions.scala @@ -4,7 +4,8 @@ import com.eed3si9n.expecty.Expecty.expect import scala.util.Properties -trait ReplTests3StableDefinitions { _: ReplTestDefinitions => +trait ReplAmmoniteTests3StableDefinitions { + _: ReplTestDefinitions with ReplAmmoniteTestDefinitions => if (!actualScalaVersion.equals(actualMaxAmmoniteScalaVersion)) { lazy val defaultScalaVersionString = s" with Scala $actualScalaVersion (the default version, may downgrade)" @@ -47,4 +48,55 @@ trait ReplTests3StableDefinitions { _: ReplTestDefinitions => expect(res.out.trim().nonEmpty) } } + + test("as jar") { + val inputs = TestInputs( + os.rel / "CheckCp.scala" -> + """//> using lib "com.lihaoyi::os-lib:0.9.1" + |package checkcp + |object CheckCp { + | def hasDir: Boolean = + | sys.props("java.class.path") + | .split(java.io.File.pathSeparator) + | .toVector + | .map(os.Path(_, os.pwd)) + | .exists(os.isDir(_)) + |} + |""".stripMargin + ) + + inputs.fromRoot { root => + val ammArgs = Seq( + "-c", + """println("hasDir=" + checkcp.CheckCp.hasDir)""" + ) + .map { + if (Properties.isWin) + a => if (a.contains(" ")) "\"" + a.replace("\"", "\\\"") + "\"" else a + else + identity + } + .flatMap(arg => Seq("--ammonite-arg", arg)) + + val output = + os.proc(TestUtil.cli, "--power", "repl", ".", TestUtil.extraOptions, "--ammonite", ammArgs) + .call(cwd = root) + .out.trim() + expect(output == "hasDir=true") + + val asJarOutput = os.proc( + TestUtil.cli, + "--power", + "repl", + ".", + TestUtil.extraOptions, + "--ammonite", + ammArgs, + "--as-jar" + ) + .call(cwd = root) + .out.trim() + expect(asJarOutput == "hasDir=false") + } + } } diff --git a/modules/integration/src/test/scala/scala/cli/integration/ReplTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/ReplTestDefinitions.scala index 3c0e2c97dd..d7a1caac1e 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/ReplTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/ReplTestDefinitions.scala @@ -3,33 +3,11 @@ package scala.cli.integration import com.eed3si9n.expecty.Expecty.expect import scala.cli.integration.TestUtil.removeAnsiColors -import scala.util.Properties abstract class ReplTestDefinitions extends ScalaCliSuite with TestScalaVersionArgs { _: TestScalaVersion => protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions - private val retrieveScalaVersionCode = if (actualScalaVersion.startsWith("2.")) - "scala.util.Properties.versionNumberString" - else "dotty.tools.dotc.config.Properties.simpleVersionString" - - def expectedScalaVersionForAmmonite: String = - actualScalaVersion match { - case s - if s.startsWith("2.12") && - Constants.maxAmmoniteScala212Version.coursierVersion < s.coursierVersion => - Constants.maxAmmoniteScala212Version - case s - if s.startsWith("2.13") && - Constants.maxAmmoniteScala213Version.coursierVersion < s.coursierVersion => - Constants.maxAmmoniteScala213Version - case s - if s.startsWith("3") && - Constants.maxAmmoniteScala3Version.coursierVersion < s.coursierVersion => - Constants.maxAmmoniteScala3Version - case s => s - } - test("dry run (default)") { TestInputs.empty.fromRoot { root => os.proc(TestUtil.cli, "repl", extraOptions, "--repl-dry-run").call(cwd = root) @@ -67,174 +45,12 @@ abstract class ReplTestDefinitions extends ScalaCliSuite with TestScalaVersionAr } } - def actualMaxAmmoniteScalaVersion: String = - if (actualScalaVersion.startsWith("3")) Constants.maxAmmoniteScala3Version - else if (actualScalaVersion.startsWith("2.13")) Constants.maxAmmoniteScala213Version - else Constants.maxAmmoniteScala212Version - - def ammoniteExtraOptions: Seq[String] = - Seq("--scala", actualMaxAmmoniteScalaVersion) ++ TestUtil.extraOptions - - def ammoniteTest(useMaxAmmoniteScalaVersion: Boolean): Unit = { + test("default scala version in help") { TestInputs.empty.fromRoot { root => - val testExtraOptions = if (useMaxAmmoniteScalaVersion) ammoniteExtraOptions else extraOptions - val ammArgs = Seq( - "-c", - s"""println("Hello" + " from Scala " + $retrieveScalaVersionCode)""" - ) - .map { - if (Properties.isWin) - a => if (a.contains(" ")) "\"" + a.replace("\"", "\\\"") + "\"" else a - else - identity - } - .flatMap(arg => Seq("--ammonite-arg", arg)) - val res = - os.proc(TestUtil.cli, "--power", "repl", testExtraOptions, "--ammonite", ammArgs) - .call(cwd = root, stderr = os.Pipe) - val output = res.out.trim() - val expectedSv = - if (useMaxAmmoniteScalaVersion) actualMaxAmmoniteScalaVersion - else expectedScalaVersionForAmmonite - expect(output == s"Hello from Scala $expectedSv") - if (useMaxAmmoniteScalaVersion) { - // the maximum Scala version supported by ammonite is being used, so we shouldn't downgrade - val errOutput = res.err.trim() - expect(!errOutput.contains("not yet supported with this version of Ammonite")) - } - } - } - - def ammoniteTestScope(useMaxAmmoniteScalaVersion: Boolean): Unit = { - val message = "something something ammonite" - TestInputs( - os.rel / "example" / "TestScopeExample.test.scala" -> - s"""package example - | - |object TestScopeExample { - | def message: String = "$message" - |} - |""".stripMargin - ).fromRoot { root => - val testExtraOptions = if (useMaxAmmoniteScalaVersion) ammoniteExtraOptions else extraOptions - val ammArgs = Seq("-c", "println(example.TestScopeExample.message)") - .map { - if (Properties.isWin) - a => if (a.contains(" ")) "\"" + a.replace("\"", "\\\"") + "\"" else a - else - identity - } - .flatMap(arg => Seq("--ammonite-arg", arg)) - val res = - os.proc( - TestUtil.cli, - "--power", - "repl", - ".", - testExtraOptions, - "--test", - "--ammonite", - ammArgs - ) - .call(cwd = root, stderr = os.Pipe) - val output = res.out.trim() - expect(output == message) - if (useMaxAmmoniteScalaVersion) { - // the maximum Scala version supported by ammonite is being used, so we shouldn't downgrade - val errOutput = res.err.trim() - expect(!errOutput.contains("not yet supported with this version of Ammonite")) - } - } - } - - def ammoniteScalapyTest(useMaxAmmoniteScalaVersion: Boolean): Unit = { - val testExtraOptions = if (useMaxAmmoniteScalaVersion) ammoniteExtraOptions else extraOptions - val inputs = TestInputs( - os.rel / "foo" / "something.py" -> - """messageStart = 'Hello from' - |messageEnd = 'ScalaPy' - |""".stripMargin - ) - inputs.fromRoot { root => - val ammArgs = Seq( - "-c", - s"""println("Hello" + " from Scala " + $retrieveScalaVersionCode) - |val sth = py.module("foo.something") - |py.Dynamic.global.applyDynamicNamed("print")("" -> sth.messageStart, "" -> sth.messageEnd, "flush" -> py.Any.from(true)) - |""".stripMargin - ) - .map { - if (Properties.isWin) - a => if (a.contains(" ")) "\"" + a.replace("\"", "\\\"") + "\"" else a - else - identity - } - .flatMap(arg => Seq("--ammonite-arg", arg)) - - val errorRes = os.proc( - TestUtil.cli, - "--power", - "repl", - testExtraOptions, - "--ammonite", - "--python", - ammArgs - ).call( - cwd = root, - env = Map("PYTHONSAFEPATH" -> "foo"), - mergeErrIntoOut = true, - check = false - ) - expect(errorRes.exitCode != 0) - val errorOutput = errorRes.out.text() - expect(errorOutput.contains("No module named 'foo'")) - - val res = os.proc( - TestUtil.cli, - "--power", - "repl", - testExtraOptions, - "--ammonite", - "--python", - ammArgs - ).call(cwd = root, stderr = os.Pipe) - val expectedSv = - if (useMaxAmmoniteScalaVersion) actualMaxAmmoniteScalaVersion - else expectedScalaVersionForAmmonite - val lines = res.out.trim().linesIterator.toVector - expect(lines == Seq(s"Hello from Scala $expectedSv", "Hello from ScalaPy")) - if (useMaxAmmoniteScalaVersion) - // the maximum Scala version supported by ammonite is being used, so we shouldn't downgrade - expect(!res.err.trim().contains("not yet supported with this version of Ammonite")) - } - } - - def ammoniteMaxVersionString: String = - if (actualScalaVersion == actualMaxAmmoniteScalaVersion) "" - else s" with Scala $actualMaxAmmoniteScalaVersion (the latest supported version)" - - test(s"ammonite$ammoniteMaxVersionString") { - ammoniteTest(useMaxAmmoniteScalaVersion = true) - } - - test(s"ammonite scalapy$ammoniteMaxVersionString") { - ammoniteScalapyTest(useMaxAmmoniteScalaVersion = true) - } - - test("ammonite with test scope sources") { - ammoniteTestScope(useMaxAmmoniteScalaVersion = true) - } - - test("default values in help") { - TestInputs.empty.fromRoot { root => - val res = os.proc(TestUtil.cli, "--power", "repl", extraOptions, "--help").call(cwd = root) - val lines = removeAnsiColors(res.out.trim()).linesIterator.toVector - + val res = os.proc(TestUtil.cli, "repl", extraOptions, "--help").call(cwd = root) + val lines = removeAnsiColors(res.out.trim()).linesIterator.toVector val scalaVersionHelp = lines.find(_.contains("--scala-version")).getOrElse("") - val ammVersionHelp = lines.find(_.contains("--ammonite-ver")).getOrElse("") - expect(scalaVersionHelp.contains(s"(${Constants.defaultScala} by default)")) - expect(ammVersionHelp.contains(s"(${Constants.ammoniteVersion} by default)")) } } } diff --git a/modules/integration/src/test/scala/scala/cli/integration/ReplTests212.scala b/modules/integration/src/test/scala/scala/cli/integration/ReplTests212.scala index ed5bd0f9ab..a13b0d9a90 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/ReplTests212.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/ReplTests212.scala @@ -1,3 +1,3 @@ package scala.cli.integration -class ReplTests212 extends ReplTestDefinitions with Test212 +class ReplTests212 extends ReplTestDefinitions with ReplAmmoniteTestDefinitions with Test212 diff --git a/modules/integration/src/test/scala/scala/cli/integration/ReplTests213.scala b/modules/integration/src/test/scala/scala/cli/integration/ReplTests213.scala index 5b5048477c..d43d7b9c30 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/ReplTests213.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/ReplTests213.scala @@ -1,10 +1,6 @@ package scala.cli.integration -import com.eed3si9n.expecty.Expecty.expect - -import scala.util.Properties - -class ReplTests213 extends ReplTestDefinitions with Test213 { +class ReplTests213 extends ReplTestDefinitions with ReplAmmoniteTestDefinitions with Test213 { test("repl custom repositories work".flaky) { TestInputs.empty.fromRoot { root => os.proc( @@ -18,44 +14,4 @@ class ReplTests213 extends ReplTestDefinitions with Test213 { ).call(cwd = root) } } - - def ammoniteWithExtraJarTest(): Unit = { - TestInputs.empty.fromRoot { root => - val ammArgs = Seq( - "-c", - """import shapeless._; println("Here's an HList: " + (2 :: true :: "a" :: HNil))""" - ) - .map { - if (Properties.isWin) - a => if (a.contains(" ")) "\"" + a.replace("\"", "\\\"") + "\"" else a - else - identity - } - .flatMap(arg => Seq("--ammonite-arg", arg)) - val shapelessJar = - os.proc(TestUtil.cs, "fetch", "--intransitive", "com.chuusai:shapeless_2.13:2.3.7") - .call() - .out - .text() - .trim - val cmd = Seq[os.Shellable]( - TestUtil.cli, - "--power", - "repl", - ammoniteExtraOptions, - "--jar", - shapelessJar, - "--ammonite", - ammArgs - ) - val res = os.proc(cmd).call(cwd = root) - val output = res.out.trim() - expect(output == "Here's an HList: 2 :: true :: a :: HNil") - } - } - - test(s"ammonite with extra JAR$ammoniteMaxVersionString") { - ammoniteWithExtraJarTest() - } - } diff --git a/modules/integration/src/test/scala/scala/cli/integration/ReplTests3Lts.scala b/modules/integration/src/test/scala/scala/cli/integration/ReplTests3Lts.scala index 0f43da7ae6..bec611690f 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/ReplTests3Lts.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/ReplTests3Lts.scala @@ -1,3 +1,6 @@ package scala.cli.integration -class ReplTests3Lts extends ReplTestDefinitions with ReplTests3StableDefinitions with Test3Lts +class ReplTests3Lts extends ReplTestDefinitions + with ReplAmmoniteTestDefinitions + with ReplAmmoniteTests3StableDefinitions + with Test3Lts diff --git a/modules/integration/src/test/scala/scala/cli/integration/ReplTestsDefault.scala b/modules/integration/src/test/scala/scala/cli/integration/ReplTestsDefault.scala index 5d9e9e48d8..950e904ea7 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/ReplTestsDefault.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/ReplTestsDefault.scala @@ -4,61 +4,10 @@ import com.eed3si9n.expecty.Expecty.expect import java.io.File -import scala.util.Properties - -class ReplTestsDefault extends ReplTestDefinitions with ReplTests3StableDefinitions +class ReplTestsDefault extends ReplTestDefinitions + with ReplAmmoniteTestDefinitions + with ReplAmmoniteTests3StableDefinitions with TestDefault { - test("as jar") { - val inputs = TestInputs( - os.rel / "CheckCp.scala" -> - """//> using lib "com.lihaoyi::os-lib:0.9.1" - |package checkcp - |object CheckCp { - | def hasDir: Boolean = - | sys.props("java.class.path") - | .split(java.io.File.pathSeparator) - | .toVector - | .map(os.Path(_, os.pwd)) - | .exists(os.isDir(_)) - |} - |""".stripMargin - ) - - inputs.fromRoot { root => - val ammArgs = Seq( - "-c", - """println("hasDir=" + checkcp.CheckCp.hasDir)""" - ) - .map { - if (Properties.isWin) - a => if (a.contains(" ")) "\"" + a.replace("\"", "\\\"") + "\"" else a - else - identity - } - .flatMap(arg => Seq("--ammonite-arg", arg)) - - val output = - os.proc(TestUtil.cli, "--power", "repl", ".", TestUtil.extraOptions, "--ammonite", ammArgs) - .call(cwd = root) - .out.trim() - expect(output == "hasDir=true") - - val asJarOutput = os.proc( - TestUtil.cli, - "--power", - "repl", - ".", - TestUtil.extraOptions, - "--ammonite", - ammArgs, - "--as-jar" - ) - .call(cwd = root) - .out.trim() - expect(asJarOutput == "hasDir=false") - } - } - if (TestUtil.isNativeCli) test("not download java 17 when run repl without sources") { TestInputs.empty.fromRoot { root =>