Skip to content

Commit

Permalink
Move reporter tests to test_version package
Browse files Browse the repository at this point in the history
  • Loading branch information
SocksDevil committed Jan 12, 2021
1 parent f801762 commit 526dd37
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 50 deletions.
44 changes: 0 additions & 44 deletions test_reporter/WORKSPACE.template

This file was deleted.

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
File renamed without changes.
File renamed without changes.

0 comments on commit 526dd37

Please sign in to comment.