Skip to content

Commit a0d3dd7

Browse files
authored
Merge pull request #3390 from tgodzik/previous-compilation
tests: Add tests for issue with rereporting errors
2 parents e8573ee + bd9fe44 commit a0d3dd7

File tree

3 files changed

+101
-10
lines changed

3 files changed

+101
-10
lines changed

modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,4 +737,88 @@ abstract class CompileTestDefinitions
737737
os.proc(TestUtil.cli, "compile", extraOptions, ".").call(cwd = root)
738738
}
739739
}
740+
741+
test("no previous compilation error should be printed") {
742+
val filename = "Main.scala"
743+
val inputs = TestInputs(
744+
os.rel / filename ->
745+
"""|object Main extends App {
746+
| val msg: String = "1"
747+
|}
748+
|""".stripMargin
749+
)
750+
inputs.fromRoot { root =>
751+
val result = os.proc(TestUtil.cli, "compile", ".", extraOptions).call(
752+
cwd = root,
753+
check = false,
754+
mergeErrIntoOut = true
755+
)
756+
757+
assertEquals(
758+
TestUtil.fullStableOutput(result),
759+
s"""|Compiling project (Scala $actualScalaVersion, JVM (${Constants
760+
.defaultGraalVMJavaVersion}))
761+
|Compiled project (Scala $actualScalaVersion, JVM (${Constants
762+
.defaultGraalVMJavaVersion}))""".stripMargin
763+
)
764+
765+
os.write.over(
766+
root / filename,
767+
"""|object Main extends App {
768+
| val msg: String = 1
769+
|}
770+
|""".stripMargin
771+
)
772+
773+
val result2 = os.proc(TestUtil.cli, "compile", ".", extraOptions).call(
774+
cwd = root,
775+
check = false,
776+
mergeErrIntoOut = true
777+
)
778+
779+
val expectedError = if (actualScalaVersion.startsWith("2"))
780+
"""|[error] type mismatch;
781+
|[error] found : Int(1)
782+
|[error] required: String""".stripMargin
783+
else
784+
"""|[error] Found: (1 : Int)
785+
|[error] Required: String""".stripMargin
786+
787+
assertEquals(
788+
TestUtil.fullStableOutput(result2).trim,
789+
s"""|Compiling project (Scala $actualScalaVersion, JVM (${Constants
790+
.defaultGraalVMJavaVersion}))
791+
|[error] .${File.separatorChar}Main.scala:2:23
792+
|$expectedError
793+
|[error] val msg: String = 1
794+
|[error] ^
795+
|Error compiling project (Scala $actualScalaVersion, JVM (${Constants
796+
.defaultGraalVMJavaVersion}))
797+
|Compilation failed""".stripMargin
798+
)
799+
800+
os.write.over(
801+
root / filename,
802+
"""|object Main extends App {
803+
| val msg: String = "1"
804+
|}
805+
|""".stripMargin
806+
)
807+
808+
val result3 = os.proc(TestUtil.cli, "compile", ".", extraOptions).call(
809+
cwd = root,
810+
check = false,
811+
mergeErrIntoOut = true
812+
)
813+
814+
assertEquals(
815+
TestUtil.fullStableOutput(result3),
816+
s"""|Compiling project (Scala $actualScalaVersion, JVM (${Constants
817+
.defaultGraalVMJavaVersion}))
818+
|Compiled project (Scala $actualScalaVersion, JVM (${Constants
819+
.defaultGraalVMJavaVersion}))""".stripMargin
820+
)
821+
822+
}
823+
}
740824
}

modules/integration/src/test/scala/scala/cli/integration/CompileTests213.scala

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ class CompileTests213 extends CompileTestDefinitions with Test213 {
4747
val result = os.proc(TestUtil.cli, "test", ".").call(
4848
cwd = root,
4949
check = false,
50-
// stdout = ProcessOutput.Readlines{ str => stringBuffer.append(str)},
5150
mergeErrIntoOut = true
5251
)
5352
val separator = if (Properties.isWin) "\\" else "/"
5453

5554
val expectedOutput =
56-
s"""|Compiling project (Scala ${Constants.scala213}, JVM (17))
57-
|Compiled project (Scala ${Constants.scala213}, JVM (17))
58-
|Compiling project (test, Scala ${Constants.scala213}, JVM (17))
55+
s"""|Compiling project (Scala ${Constants.scala213}, JVM (${Constants
56+
.defaultGraalVMJavaVersion}))
57+
|Compiled project (Scala ${Constants.scala213}, JVM (${Constants
58+
.defaultGraalVMJavaVersion}))
59+
|Compiling project (test, Scala ${Constants.scala213}, JVM (${Constants
60+
.defaultGraalVMJavaVersion}))
5961
|[info] .${separator}Test.test.scala:6:5
6062
|[info] scala.Predef.ArrowAssoc[Int](1).->[String]("test")
6163
|[info] scala.Predef.ArrowAssoc[Int](1).->[String]("test")
@@ -69,16 +71,13 @@ class CompileTests213 extends CompileTestDefinitions with Test213 {
6971
|[error] example error message
7072
|[error] Scala2Example.macroMethod(1 -> "test")
7173
|[error] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
72-
|Error compiling project (test, Scala ${Constants.scala213}, JVM (17))
74+
|Error compiling project (test, Scala ${Constants.scala213}, JVM (${Constants
75+
.defaultGraalVMJavaVersion}))
7376
|Compilation failed
7477
|""".stripMargin
7578

7679
assertNoDiff(
77-
result.toString.trim().linesIterator.filterNot { str =>
78-
// these lines are not stable and can easily change
79-
val shouldNotContain = Set("Starting compilation server", "hint", "Download", "Result of")
80-
shouldNotContain.exists(str.contains)
81-
}.mkString("\n"),
80+
TestUtil.fullStableOutput(result),
8281
expectedOutput
8382
)
8483
}

modules/integration/src/test/scala/scala/cli/integration/TestUtil.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ object TestUtil {
114114

115115
def removeAnsiColors(str: String) = str.replaceAll("\\e\\[[0-9]+m", "")
116116

117+
def fullStableOutput(result: os.CommandResult) =
118+
removeAnsiColors(result.toString).trim().linesIterator.filterNot { str =>
119+
// these lines are not stable and can easily change
120+
val shouldNotContain =
121+
Set("Starting compilation server", "hint", "Download", "Result of", "Checking", "Checked")
122+
shouldNotContain.exists(str.contains)
123+
}.mkString(System.lineSeparator())
124+
117125
def retry[T](
118126
maxAttempts: Int = 3,
119127
waitDuration: FiniteDuration = 5.seconds

0 commit comments

Comments
 (0)