Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reporter tests #1176

Merged
merged 3 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions test/shell/test_diagnostics_reporter.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Diagnostics Reporters Tests. Diagnostics definition based off the definition provided by the LSP

# shellcheck source=./test_runner.sh
dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
. "${dir}"/test_runner.sh
. "${dir}"/test_helper.sh
runner=$(get_test_runner "${1:-local}")

test_diagnostics_reporter() {
bazel build --build_event_publish_all_actions -k --extra_toolchains="//test_expect_failure/diagnostics_reporter:diagnostics_reporter_toolchain" //test_expect_failure/diagnostics_reporter:all || true
diagnostics_output="$(bazel info execution_root)/bazel-out/darwin-fastbuild/bin/test_expect_failure/diagnostics_reporter"
diagnostics_output="$(bazel info bazel-bin)/test_expect_failure/diagnostics_reporter"
bazel run //test/diagnostics_reporter:diagnostics_reporter_test "$diagnostics_output"
}

Expand Down
2 changes: 1 addition & 1 deletion test_rules_scala.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $runner bazel test //test/... --extra_toolchains="//test_expect_failure/plus_one
. "${test_dir}"/test_build_event_protocol.sh
. "${test_dir}"/test_compilation.sh
. "${test_dir}"/test_deps.sh
# . "${test_dir}"/test_diagnostics_reporter.sh TODO: Uncomment after changes to bazel are merged
. "${test_dir}"/test_diagnostics_reporter.sh
. "${test_dir}"/test_javac_jvm_flags.sh
. "${test_dir}"/test_custom_reporter_class.sh
. "${test_dir}"/test_junit.sh
Expand Down
48 changes: 43 additions & 5 deletions test_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,69 @@ SCALA_VERSION_DEFAULT=$scala_2_11_version
SCALA_VERSION_SHAS_DEFAULT=$scala_2_11_shas
TWITTER_SCROOGE_ARTIFACTS='twitter_scrooge_artifacts={}'

diagnostics_reporter_toolchain="//:diagnostics_reporter_toolchain"
no_diagnostics_reporter_toolchain="//:no_diagnostics_reporter_toolchain"

SCALA_TOOLCHAIN_DEFAULT="@io_bazel_rules_scala//testing:testing_toolchain"

compilation_should_fail() {
# runs the tests locally
set +e
TEST_ARG=$@
DUMMY=$(bazel $TEST_ARG)
RESPONSE_CODE=$?
if [ $RESPONSE_CODE -eq 0 ]; then
echo -e "${RED} \"bazel $TEST_ARG\" should have failed but passed. $NC"
return -1
else
return 0
fi
}

run_in_test_repo() {
local SCALA_VERSION=${SCALA_VERSION:-$SCALA_VERSION_DEFAULT}
local SCALA_TOOLCHAIN=${SCALA_TOOLCHAIN:-$SCALA_TOOLCHAIN_DEFAULT}

local test_command=$1
local test_dir_prefix=$2
local test_target=$3

cd "${dir}"/test_version

local timestamp=$(date +%s)

NEW_TEST_DIR="test_${test_dir_prefix}_${timestamp}"

cp -r version_specific_tests_dir/ $NEW_TEST_DIR
cp -r $test_target $NEW_TEST_DIR

sed \
-e "s/\${scala_version}/$SCALA_VERSION/" \
-e "s%\${twitter_scrooge_artifacts}%$TWITTER_SCROOGE_ARTIFACTS%" \
-e "s%\${testing_toolchain}%$SCALA_TOOLCHAIN%" \
WORKSPACE.template >> $NEW_TEST_DIR/WORKSPACE

cd $NEW_TEST_DIR

bazel ${test_command}
${test_command}
RESPONSE_CODE=$?

cd ..
rm -rf $NEW_TEST_DIR

exit $RESPONSE_CODE
}

test_scala_version() {
local SCALA_VERSION="$1"

run_in_test_repo "test //..." "scala_version"
run_in_test_repo "bazel test //..." "scala_version" "version_specific_tests_dir/"
}

test_reporter() {
local SCALA_VERSION="$1"
local SCALA_TOOLCHAIN="$2"

run_in_test_repo "compilation_should_fail build //..." "reporter" "test_reporter/"
}

test_twitter_scrooge_versions() {
Expand Down Expand Up @@ -103,7 +132,7 @@ test_twitter_scrooge_versions() {
echo "Unknown Twitter Scrooge version given $version_under_test"
fi

run_in_test_repo "test //twitter_scrooge/... --test_arg=${version_under_test}" "scrooge_version"
run_in_test_repo "bazel test //twitter_scrooge/... --test_arg=${version_under_test}" "scrooge_version" "version_specific_tests_dir/"
}

if ! bazel_loc="$(type -p 'bazel')" || [[ -z "$bazel_loc" ]]; then
Expand All @@ -123,3 +152,12 @@ TEST_TIMEOUT=15 $runner test_scala_version "${scala_2_13_version}"

TEST_TIMEOUT=15 $runner test_twitter_scrooge_versions "18.6.0"
TEST_TIMEOUT=15 $runner test_twitter_scrooge_versions "20.9.0"

TEST_TIMEOUT=15 $runner test_reporter "${scala_2_11_version}" "${no_diagnostics_reporter_toolchain}"
TEST_TIMEOUT=15 $runner test_reporter "${scala_2_12_version}" "${no_diagnostics_reporter_toolchain}"
TEST_TIMEOUT=15 $runner test_reporter "${scala_2_13_version}" "${no_diagnostics_reporter_toolchain}"

#TODO: Uncomment this out after diagnostics reporter properly reports errors for scala 2.11
#TEST_TIMEOUT=15 $runner test_reporter "${scala_2_11_version}" "${diagnostics_reporter_toolchain}"
TEST_TIMEOUT=15 $runner test_reporter "${scala_2_12_version}" "${diagnostics_reporter_toolchain}"
TESTs_TIMEOUT=15 $runner test_reporter "${scala_2_13_version}" "${diagnostics_reporter_toolchain}"
2 changes: 1 addition & 1 deletion test_version/WORKSPACE.template
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ load("@io_bazel_rules_scala//specs2:specs2_junit.bzl", "specs2_junit_repositorie

specs2_junit_repositories()

register_toolchains("@io_bazel_rules_scala//testing:testing_toolchain")
register_toolchains("${testing_toolchain}")

load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_unused_deps_toolchains")

Expand Down
33 changes: 33 additions & 0 deletions test_version/test_reporter/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("@io_bazel_rules_scala//scala:scala_toolchain.bzl", "scala_toolchain")
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library")

scala_toolchain(
name = "diagnostics_reporter_toolchain_impl",
enable_diagnostics_report = True,
visibility = ["//visibility:public"],
)

toolchain(
name = "diagnostics_reporter_toolchain",
toolchain = "diagnostics_reporter_toolchain_impl",
toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type",
visibility = ["//visibility:public"],
)

scala_toolchain(
name = "no_diagnostics_reporter_toolchain_impl",
visibility = ["//visibility:public"],
)

toolchain(
name = "no_diagnostics_reporter_toolchain",
toolchain = "no_diagnostics_reporter_toolchain_impl",
toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type",
visibility = ["//visibility:public"],
)

scala_library(
name = "error_file",
srcs = ["ErrorFile.scala"],
visibility = ["//visibility:public"],
)
7 changes: 7 additions & 0 deletions test_version/test_reporter/ErrorFile.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object ErrorFile {
val value = "someVal"

def main(args: Array[String]): Unit = {
println(value
}
}