Skip to content

Commit

Permalink
fixup! 6566565 Test Scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaden Peterson committed Aug 28, 2024
1 parent adc0b5b commit 8ea3a21
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 7 deletions.
20 changes: 17 additions & 3 deletions tests/zinc/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
load("@rules_scala_annex//rules:scala.bzl", "scala_binary")
load("@rules_scala_annex//rules:scala.bzl", "scala_library")

scala_binary(
name = "error_reporting",
scala_library(
name = "error_reporting_2_13",
srcs = ["ErrorReporting.scala"],
scala = "//scala:2_13",
tags = ["manual"],
)

scala_library(
name = "error_reporting_bootstrap_3",
srcs = ["ErrorReporting.scala"],
scala = "//scala:bootstrap_3",
tags = ["manual"],
)

scala_library(
name = "error_reporting_zinc_3",
srcs = ["ErrorReporting.scala"],
scala = "//scala:zinc_3",
tags = ["manual"],
)
67 changes: 63 additions & 4 deletions tests/zinc/test
Original file line number Diff line number Diff line change
@@ -1,5 +1,64 @@
#!/bin/bash -e
. "$(dirname "$0")"/../common.sh
#!/usr/bin/env python

(! bazel build :error_reporting) 2>&1 |
grep -Fq 'def main(arguments: Array[String]): Unit = printZooAnimals(Seq("kangaroos", "giraffes"))'
"""
This test is written in Python because Bash makes it unnecessarily difficult to check that the output of a command
includes a multiline string.
"""

import os
import subprocess

os.chdir(os.path.dirname(os.path.realpath(__file__)))

def output_from_failed_build(target: str) -> str:
result = subprocess.run(["bazel", "build", target], stderr=subprocess.PIPE, text=True)

assert result.returncode != 0

return result.stderr

def string_must_contain(string: str, expected_substring: str):
if expected_substring not in string:
print(f'Expected """{string}""" to contain """{expected_substring}"""')

assert False

string_must_contain(
output_from_failed_build(":error_reporting_2_13"),
"""\
[\x1b[31mError\x1b[0m] zinc/ErrorReporting.scala:4:65: type mismatch;
[\x1b[31mError\x1b[0m] found : Seq[String]
[\x1b[31mError\x1b[0m] required: List[String]
[\x1b[31mError\x1b[0m] def main(arguments: Array[String]): Unit = printZooAnimals(Seq("kangaroos", "giraffes"))
[\x1b[31mError\x1b[0m] ^
one error found
"""
)

string_must_contain(
output_from_failed_build(":error_reporting_bootstrap_3"),
"""\
\x1b[31m\x1b[31m-- [E007] Type Mismatch Error: zinc/ErrorReporting.scala:4:64 ------------------\x1b[0m\x1b[0m
\x1b[31m4 |\x1b[0m \x1b[33mdef\x1b[0m \x1b[36mmain\x1b[0m(\x1b[36marguments\x1b[0m: \x1b[35mArray\x1b[0m[\x1b[35mString\x1b[0m]): \x1b[35mUnit\x1b[0m = printZooAnimals(Seq(\x1b[31m"kangaroos"\x1b[0m, \x1b[31m"giraffes"\x1b[0m))
\x1b[31m\x1b[31m |\x1b[0m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\x1b[0m
\x1b[31m |\x1b[0m Found: \x1b[1m\x1b[31mSeq\x1b[0m[String]
\x1b[31m |\x1b[0m Required: \x1b[1m\x1b[32mList\x1b[0m[String]
\x1b[31m |\x1b[0m
\x1b[31m |\x1b[0m longer explanation available when compiling with `-explain`
1 error found
"""
)

string_must_contain(
output_from_failed_build(":error_reporting_zinc_3"),
"""\
\x1b[31m\x1b[31m-- [E007] Type Mismatch Error: zinc/ErrorReporting.scala:4:64 \x1b[0m\x1b[0m
\x1b[31m4 |\x1b[0m \x1b[33mdef\x1b[0m \x1b[36mmain\x1b[0m(\x1b[36marguments\x1b[0m: \x1b[35mArray\x1b[0m[\x1b[35mString\x1b[0m]): \x1b[35mUnit\x1b[0m = printZooAnimals(Seq(\x1b[31m"kangaroos"\x1b[0m, \x1b[31m"giraffes"\x1b[0m))
\x1b[31m\x1b[31m |\x1b[0m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\x1b[0m
\x1b[31m |\x1b[0m Found: \x1b[1m\x1b[31mSeq\x1b[0m[String]
\x1b[31m |\x1b[0m Required: \x1b[1m\x1b[32mList\x1b[0m[String]
\x1b[31m |\x1b[0m
\x1b[31m |\x1b[0m longer explanation available when compiling with `-explain`
one error found
"""
)

0 comments on commit 8ea3a21

Please sign in to comment.