Skip to content

Commit d7e7583

Browse files
committed
tests: Add tests for issue with rereporting errors
Fixes #2226
1 parent 55ccea7 commit d7e7583

File tree

3 files changed

+94
-10
lines changed

3 files changed

+94
-10
lines changed

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,4 +737,81 @@ 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", ".").call(
752+
cwd = root,
753+
check = false,
754+
mergeErrIntoOut = true
755+
)
756+
757+
assertEquals(
758+
TestUtil.fullStableOutput(result),
759+
s"""|Compiling project (Scala ${Constants.scala3Next}, JVM (${Constants
760+
.defaultGraalVMJavaVersion}))
761+
|Compiled project (Scala ${Constants.scala3Next}, 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", ".").call(
774+
cwd = root,
775+
check = false,
776+
mergeErrIntoOut = true
777+
)
778+
779+
assertEquals(
780+
TestUtil.fullStableOutput(result2),
781+
s"""|Compiling project (Scala ${Constants.scala3Next}, JVM (${Constants
782+
.defaultGraalVMJavaVersion}))
783+
|[error] ./Main.scala:2:23
784+
|[error] Found: (1 : Int)
785+
|[error] Required: String
786+
|[error] val msg: String = 1
787+
|[error] ^
788+
|Error compiling project (Scala ${Constants.scala3Next}, JVM (${Constants
789+
.defaultGraalVMJavaVersion}))
790+
|Compilation failed""".stripMargin
791+
)
792+
793+
os.write.over(
794+
root / filename,
795+
"""|object Main extends App {
796+
| val msg: String = "1"
797+
|}
798+
|""".stripMargin
799+
)
800+
801+
val result3 = os.proc(TestUtil.cli, "compile", ".").call(
802+
cwd = root,
803+
check = false,
804+
mergeErrIntoOut = true
805+
)
806+
807+
assertEquals(
808+
TestUtil.fullStableOutput(result3),
809+
s"""|Compiling project (Scala ${Constants.scala3Next}, JVM (${Constants
810+
.defaultGraalVMJavaVersion}))
811+
|Compiled project (Scala ${Constants.scala3Next}, JVM (${Constants
812+
.defaultGraalVMJavaVersion}))""".stripMargin
813+
)
814+
815+
}
816+
}
740817
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package scala.cli.integration
22

33
import scala.util.Properties
4+
import scala.cli.integration.Constants.defaultGraalVMJavaVersion
45

56
class CompileTests213 extends CompileTestDefinitions with Test213 {
67

@@ -47,15 +48,17 @@ class CompileTests213 extends CompileTestDefinitions with Test213 {
4748
val result = os.proc(TestUtil.cli, "test", ".").call(
4849
cwd = root,
4950
check = false,
50-
// stdout = ProcessOutput.Readlines{ str => stringBuffer.append(str)},
5151
mergeErrIntoOut = true
5252
)
5353
val separator = if (Properties.isWin) "\\" else "/"
5454

5555
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))
56+
s"""|Compiling project (Scala ${Constants.scala213}, JVM (${Constants
57+
.defaultGraalVMJavaVersion}))
58+
|Compiled project (Scala ${Constants.scala213}, JVM (${Constants
59+
.defaultGraalVMJavaVersion}))
60+
|Compiling project (test, Scala ${Constants.scala213}, JVM (${Constants
61+
.defaultGraalVMJavaVersion}))
5962
|[info] .${separator}Test.test.scala:6:5
6063
|[info] scala.Predef.ArrowAssoc[Int](1).->[String]("test")
6164
|[info] scala.Predef.ArrowAssoc[Int](1).->[String]("test")
@@ -69,16 +72,13 @@ class CompileTests213 extends CompileTestDefinitions with Test213 {
6972
|[error] example error message
7073
|[error] Scala2Example.macroMethod(1 -> "test")
7174
|[error] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
72-
|Error compiling project (test, Scala ${Constants.scala213}, JVM (17))
75+
|Error compiling project (test, Scala ${Constants.scala213}, JVM (${Constants
76+
.defaultGraalVMJavaVersion}))
7377
|Compilation failed
7478
|""".stripMargin
7579

7680
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"),
81+
TestUtil.fullStableOutput(result),
8282
expectedOutput
8383
)
8484
}

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

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

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

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

0 commit comments

Comments
 (0)