Skip to content

Commit

Permalink
NIT Refactor integration tests
Browse files Browse the repository at this point in the history
  - add missing type annotations
  - update to newer syntax
  - fix formatting
  - other misc fixes
  • Loading branch information
Gedochao committed Aug 2, 2022
1 parent b6c0149 commit cc725b2
Show file tree
Hide file tree
Showing 30 changed files with 84 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect
import os.proc

import scala.cli.integration.util.BloopUtil

class BloopTests extends ScalaCliSuite {

def runScalaCli(args: String*) = os.proc(TestUtil.cli, args)
def runScalaCli(args: String*): proc = os.proc(TestUtil.cli, args)

private lazy val bloopDaemonDir =
BloopUtil.bloopDaemonDir(runScalaCli("directories").call().out.text())

val dummyInputs = TestInputs(
val dummyInputs: TestInputs = TestInputs(
os.rel / "Test.scala" ->
"""//> using scala "2.13"
|object Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.eed3si9n.expecty.Expecty.expect

class CleanTests extends ScalaCliSuite {

override def group = ScalaCliSuite.TestGroup.First
override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First

test("simple") {
val inputs = TestInputs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import scala.cli.integration.util.BloopUtil
abstract class CompileTestDefinitions(val scalaVersionOpt: Option[String])
extends ScalaCliSuite with TestScalaVersionArgs {

protected lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions

private lazy val bloopDaemonDir = BloopUtil.bloopDaemonDir {
os.proc(TestUtil.cli, "directories").call().out.text()
}

val simpleInputs = TestInputs(
val simpleInputs: TestInputs = TestInputs(
os.rel / "MyTests.test.scala" ->
"""//> using lib "com.lihaoyi::utest::0.7.10"
|import utest._
Expand All @@ -32,7 +32,7 @@ abstract class CompileTestDefinitions(val scalaVersionOpt: Option[String])
|""".stripMargin
)

val mainAndTestInputs = TestInputs(
val mainAndTestInputs: TestInputs = TestInputs(
os.rel / "Main.scala" ->
"""//> using lib "com.lihaoyi::utest:0.7.10"
|
Expand Down Expand Up @@ -201,25 +201,25 @@ abstract class CompileTestDefinitions(val scalaVersionOpt: Option[String])

val jvmT = new munit.Tag("jvm-resolution")

val scalaJvm8Project =
val scalaJvm8Project: TestInputs =
TestInputs(os.rel / "Main.scala" -> s"object Main{java.util.Optional.of(1).isPresent}")
val scalaJvm11Project =
val scalaJvm11Project: TestInputs =
TestInputs(os.rel / "Main.scala" -> s"object Main{java.util.Optional.of(1).isEmpty}")
val javaJvm8Project =
val javaJvm8Project: TestInputs =
TestInputs(os.rel / "Main.java" -> """|public class Main{
| public static void main(String[] args) {
| java.util.Optional.of(1).isPresent();
| }
|}""".stripMargin)

val javaJvm11Project =
val javaJvm11Project: TestInputs =
TestInputs(os.rel / "Main.java" -> """|public class Main{
| public static void main(String[] args) {
| java.util.Optional.of(1).isEmpty();
| }
|}""".stripMargin)

val inputs = Map(
val inputs: Map[(String, Int), TestInputs] = Map(
("scala", 8) -> scalaJvm8Project,
("scala", 11) -> scalaJvm11Project,
("java", 8) -> javaJvm8Project,
Expand Down Expand Up @@ -264,7 +264,7 @@ abstract class CompileTestDefinitions(val scalaVersionOpt: Option[String])
targetJvm: String,
shouldSucceed: Boolean,
inputs: TestInputs
) =
): Unit =
inputs.fromRoot { root =>
val bloop = BloopUtil.bloop(Constants.bloopVersion, bloopDaemonDir, jvm = Some(bloopJvm))
bloop(Seq("exit")).call(
Expand Down Expand Up @@ -296,7 +296,7 @@ abstract class CompileTestDefinitions(val scalaVersionOpt: Option[String])
stderr = os.Pipe
)
val stderr = res.err.text()
expect(s"\\[.*warn.*\\].*Conflicting options.*".r.findFirstMatchIn(stderr).isDefined)
expect(s"\\[.*warn.*].*Conflicting options.*".r.findFirstMatchIn(stderr).isDefined)

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class CompileTests212 extends CompileTestDefinitions(
) {
// format: on

val pluginInputs = TestInputs(
val pluginInputs: TestInputs = TestInputs(
os.rel / "Plugin.scala" ->
// Copied from (https://github.com/typelevel/kind-projector/blob/00bf25cef1b7d01d61a3555cccb6cf38fe30e117/src/test/scala/polylambda.scala)
"""object Plugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.eed3si9n.expecty.Expecty.expect

class ConfigTests extends ScalaCliSuite {

override def group = ScalaCliSuite.TestGroup.First
override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First

test("simple") {
val homeDir = os.rel / "home"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.eed3si9n.expecty.Expecty.expect

class DefaultFileTests extends ScalaCliSuite {

override def group = ScalaCliSuite.TestGroup.First
override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First

test("Print .gitignore") {
val res = os.proc(TestUtil.cli, "default-file", ".gitignore")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.eed3si9n.expecty.Expecty.expect
abstract class DocTestDefinitions(val scalaVersionOpt: Option[String])
extends ScalaCliSuite with TestScalaVersionArgs {

protected lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions

test("generate static scala doc") {
val dest = os.rel / "doc-static"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scala.util.Properties
abstract class ExportMillTestDefinitions(val scalaVersionOpt: Option[String])
extends ScalaCliSuite with TestScalaVersionArgs {

protected lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions

protected def runExportTests: Boolean =
Properties.isLinux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scala.util.Properties
abstract class ExportSbtTestDefinitions(val scalaVersionOpt: Option[String])
extends ScalaCliSuite with TestScalaVersionArgs {

protected lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions

protected def runExportTests: Boolean =
Properties.isLinux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.eed3si9n.expecty.Expecty.expect

class FmtTests extends ScalaCliSuite {

override def group = ScalaCliSuite.TestGroup.First
override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First

val confFileName = ".scalafmt.conf"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect
import com.github.plokhotnyuk.jsoniter_scala.core._
import com.github.plokhotnyuk.jsoniter_scala.core.*
import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker
import coursier.cache.ArchiveCache
import coursier.util.Artifact
Expand All @@ -15,7 +15,7 @@ import scala.util.Properties

class GitHubTests extends ScalaCliSuite {

override def group = ScalaCliSuite.TestGroup.First
override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First

def createSecretTest(): Unit = {
GitHubTests.initSodium()
Expand Down Expand Up @@ -85,7 +85,7 @@ object GitHubTests {
private def libsodiumVersion = Constants.libsodiumVersion

// Warning: somehow also in settings.sc in the build, and in FetchExternalBinary
lazy val condaPlatform = {
lazy val condaPlatform: String = {
val mambaOs =
if (Properties.isWin) "win"
else if (Properties.isMac) "osx"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import coursier.cache.shaded.dirs.ProjectDirectories
import scala.util.Properties

class InstallAndUninstallCompletionsTests extends ScalaCliSuite {
val zshRcFile = ".zshrc"
val bashRcFile = ".bashrc"
val rcContent = s"""
|dummy line
|dummy line""".stripMargin
val testInputs = TestInputs(
val zshRcFile: String = ".zshrc"
val bashRcFile: String = ".bashrc"
val rcContent: String = s"""
|dummy line
|dummy line""".stripMargin
val testInputs: TestInputs = TestInputs(
os.rel / zshRcFile -> rcContent,
os.rel / bashRcFile -> rcContent
)
Expand Down Expand Up @@ -42,7 +42,7 @@ class InstallAndUninstallCompletionsTests extends ScalaCliSuite {
runInstallAndUninstallCompletions()
}

lazy val bashRcScript = {
lazy val bashRcScript: String = {
val progName = "scala-cli"
val ifs = "\\n"
val script =
Expand All @@ -56,7 +56,7 @@ class InstallAndUninstallCompletionsTests extends ScalaCliSuite {
addTags(script)
}

lazy val zshRcScript = {
lazy val zshRcScript: String = {
val projDirs = ProjectDirectories.from(null, null, "ScalaCli")
val dir = os.Path(projDirs.dataLocalDir, TestUtil.pwd) / "completions" / "zsh"
val script = Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import scala.util.Properties

class InstallHomeTests extends ScalaCliSuite {

override def group = ScalaCliSuite.TestGroup.First
override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First

val firstVersion = "0.0.1"
val secondVersion = "0.0.2"
val dummyScalaCliFirstName = "DummyScalaCli-1.scala"
val dummyScalaCliSecondName = "DummyScalaCli-2.scala"
val dummyScalaCliBinName = "scala-cli-dummy-test"
val testInputs = TestInputs(
val testInputs: TestInputs = TestInputs(
os.rel / dummyScalaCliFirstName ->
s"""
|object DummyScalaCli extends App {
Expand Down Expand Up @@ -117,7 +117,7 @@ class InstallHomeTests extends ScalaCliSuite {
).out.text().trim
expect(v1Downgrade == firstVersion)

uninstallScalaCli(root, binDirPath, true, true)
uninstallScalaCli(root, binDirPath, force = true, skipCache = true)
expect(!os.exists(binDirPath))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.nio.charset.Charset

class JmhTests extends ScalaCliSuite {

override def group = ScalaCliSuite.TestGroup.First
override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First

test("simple") {
val inputs = TestInputs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.eed3si9n.expecty.Expecty.expect

class MetaCheck extends ScalaCliSuite {

override def group = ScalaCliSuite.TestGroup.First
override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First

/*
* We don't run tests with --scala 3.… any more, and only rely on those
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import scala.util.Properties

class NativePackagerTests extends ScalaCliSuite {

override def group = ScalaCliSuite.TestGroup.First
override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First

val helloWorldFileName = "HelloWorldScalaCli.scala"
val message = "Hello, world!"
val licencePath = "DummyLICENSE"
val testInputs = TestInputs(
val testInputs: TestInputs = TestInputs(
os.rel / helloWorldFileName ->
s"""
|object HelloWorld {
Expand Down Expand Up @@ -344,7 +344,7 @@ class NativePackagerTests extends ScalaCliSuite {
finally os.proc("docker", "rmi", "-f", expectedImage).call(cwd = os.root)
}

def hasDocker =
def hasDocker: Boolean =
Properties.isLinux ||
// no docker command or no Linux from it on Github actions macOS / Windows runners
((Properties.isMac || Properties.isWin) && !TestUtil.isCI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import com.eed3si9n.expecty.Expecty.expect
import java.io.{File, InputStream}
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.util.Arrays
import java.util
import java.util.regex.Pattern
import java.util.zip.ZipFile

import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*
import scala.util.{Properties, Using}

abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String])
Expand All @@ -18,11 +18,11 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String])
private lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions

def maybeUseBash(cmd: os.Shellable*)(cwd: os.Path = null): os.CommandResult = {
val res = os.proc(cmd: _*).call(cwd = cwd, check = false)
val res = os.proc(cmd*).call(cwd = cwd, check = false)
if (Properties.isLinux && res.exitCode == 127)
// /bin/sh seems to have issues with '%' signs in PATH, that coursier can leave
// in the JVM path entry (https://unix.stackexchange.com/questions/126955/percent-in-path-environment-variable)
os.proc(("/bin/bash": os.Shellable) +: cmd: _*).call(cwd = cwd)
os.proc((("/bin/bash": os.Shellable) +: cmd)*).call(cwd = cwd)
else {
expect(res.exitCode == 0)
res
Expand Down Expand Up @@ -465,7 +465,7 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String])

val preambleStart = "#".getBytes(StandardCharsets.UTF_8)
val contentStart = os.read.bytes(launcher).take(preambleStart.length)
expect(!Arrays.equals(contentStart, preambleStart))
expect(!util.Arrays.equals(contentStart, preambleStart))

val output = os.proc("java", "-cp", launcher, "hello.Hello")
.call(cwd = root).out.text().trim
Expand Down Expand Up @@ -575,9 +575,7 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String])
if (actualScalaVersion.startsWith("2.")) actualScalaVersion
else {
val scalaLibJarName = scalaLibCp.split(File.pathSeparator)
.map(_.split(Pattern.quote(File.separator)).last)
.filter(_.startsWith("scala-library-"))
.headOption
.map(_.split(Pattern.quote(File.separator)).last).find(_.startsWith("scala-library-"))
.getOrElse {
sys.error(s"scala-library not found in provided class path $scalaLibCp")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect
import os.RelPath

import java.nio.file.Paths
import java.util.zip.ZipFile

import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*

abstract class PublishTestDefinitions(val scalaVersionOpt: Option[String])
extends ScalaCliSuite with TestScalaVersionArgs {

protected def extraOptions = scalaVersionArgs ++ TestUtil.extraOptions
protected def extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions

private object TestCase {
val testInputs = TestInputs(
val testInputs: TestInputs = TestInputs(
os.rel / "project" / "foo" / "Hello.scala" ->
"""//> using publish.organization "org.virtuslab.scalacli.test"
|//> using publish.name "simple"
Expand All @@ -37,10 +38,10 @@ abstract class PublishTestDefinitions(val scalaVersionOpt: Option[String])
|}
|""".stripMargin
)
val scalaSuffix =
val scalaSuffix: String =
if (actualScalaVersion.startsWith("3.")) "_3"
else "_" + actualScalaVersion.split('.').take(2).mkString(".")
val expectedArtifactsDir =
val expectedArtifactsDir: RelPath =
os.rel / "org" / "virtuslab" / "scalacli" / "test" / s"simple$scalaSuffix" / "0.2.0-SNAPSHOT"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class ReplTestDefinitions(val scalaVersionOpt: Option[String])

private lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions

protected def versionNumberString = actualScalaVersion
protected def versionNumberString: String = actualScalaVersion

test("default dry run") {
TestInputs.empty.fromRoot { root =>
Expand Down
Loading

0 comments on commit cc725b2

Please sign in to comment.