From b2dc5c0e63efdcfaddc0b4a4ecd8b0f8bea07978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Csomor?= Date: Tue, 19 Mar 2019 13:37:33 +0100 Subject: [PATCH] e2e tests: make them run on Windows (#121) --- .bazelci/presubmit.yml | 14 +++++++------ tests/BUILD | 6 ++++++ tests/analysis_test_test.sh | 37 ++++++++++++++++++++-------------- tests/unittest_test.sh | 40 +++++++++++++++++++++++++++---------- 4 files changed, 66 insertions(+), 31 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 4087c44..26153af 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -50,9 +50,10 @@ tasks: test_targets: - "--" - "//..." - # Shell tests don't run on windows. - - "-//tests:analysis_test_e2e_test" - - "-//tests:unittest_e2e_test" + test_flags: + # TODO(laszlocsomor): remove "--test_env=LOCALAPPDATA" after + # https://github.com/bazelbuild/bazel/issues/7761 is fixed + - "--test_env=LOCALAPPDATA" ubuntu1804_last_green: name: "Last Green Bazel" @@ -104,8 +105,9 @@ tasks: test_targets: - "--" - "//..." - # Shell tests don't run on windows. - - "-//tests:analysis_test_e2e_test" - - "-//tests:unittest_e2e_test" + test_flags: + # TODO(laszlocsomor): remove "--test_env=LOCALAPPDATA" after + # https://github.com/bazelbuild/bazel/issues/7761 is fixed + - "--test_env=LOCALAPPDATA" buildifier: latest diff --git a/tests/BUILD b/tests/BUILD index 13b496d..25ce454 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -62,6 +62,12 @@ sh_test( data = [ ":unittest.bash", ":unittest_tests_bzl", + "//lib:dicts.bzl", + "//lib:new_sets.bzl", + "//lib:old_sets.bzl", + "//lib:sets.bzl", + "//lib:types.bzl", + "//lib:unittest.bzl", "//toolchains/unittest:test_deps", "@bazel_tools//tools/bash/runfiles", ], diff --git a/tests/analysis_test_test.sh b/tests/analysis_test_test.sh index 0c03074..476fd41 100755 --- a/tests/analysis_test_test.sh +++ b/tests/analysis_test_test.sh @@ -44,19 +44,23 @@ fi source "$(rlocation bazel_skylib/tests/unittest.bash)" \ || { echo "Could not source bazel_skylib/tests/unittest.bash" >&2; exit 1; } -function set_up() { - touch WORKSPACE +function create_pkg() { + local -r pkg="$1" + mkdir -p "$pkg" + cd "$pkg" + cat > WORKSPACE < rules/BUILD < fakerules/rules.bzl < fakerules/BUILD <"$TEST_log" 2>&1 || fail "Expected test to pass" + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:target_succeeds >"$TEST_log" 2>&1 || fail "Expected test to pass" expect_log "PASSED" } function test_direct_target_fails() { - ! bazel test //testdir:direct_target_fails --test_output=all --verbose_failures \ - >"$TEST_log" 2>&1 || fail "Expected test to fail" + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:direct_target_fails --test_output=all --verbose_failures \ + >"$TEST_log" 2>&1 && fail "Expected test to fail" || true expect_log "This rule should never work" } function test_transitive_target_fails() { - ! bazel test //testdir:transitive_target_fails --test_output=all --verbose_failures \ - >"$TEST_log" 2>&1 || fail "Expected test to fail" + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:transitive_target_fails --test_output=all --verbose_failures \ + >"$TEST_log" 2>&1 && fail "Expected test to fail" || true expect_log "This rule should never work" } diff --git a/tests/unittest_test.sh b/tests/unittest_test.sh index e5403d4..e4c8008 100755 --- a/tests/unittest_test.sh +++ b/tests/unittest_test.sh @@ -45,8 +45,11 @@ fi source "$(rlocation bazel_skylib/tests/unittest.bash)" \ || { echo "Could not source bazel_skylib/tests/unittest.bash" >&2; exit 1; } -function set_up() { - touch WORKSPACE +function create_pkg() { + local -r pkg="$1" + mkdir -p "$pkg" + cd "$pkg" + cat > WORKSPACE < tests/BUILD < lib/BUILD < testdir/BUILD <"$TEST_log" 2>&1 || fail "Expected test to pass" + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:basic_passing_test >"$TEST_log" 2>&1 || fail "Expected test to pass" expect_log "PASSED" } function test_basic_failing_test() { - ! bazel test //testdir:basic_failing_test --test_output=all --verbose_failures \ - >"$TEST_log" 2>&1 || fail "Expected test to fail" + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:basic_failing_test --test_output=all --verbose_failures \ + >"$TEST_log" 2>&1 && fail "Expected test to fail" || true expect_log "In test _basic_failing_test from //tests:unittest_tests.bzl: Expected \"1\", but got \"2\"" } function test_fail_unexpected_passing_test() { - ! bazel test //testdir:fail_unexpected_passing_test --test_output=all --verbose_failures \ - >"$TEST_log" 2>&1 || fail "Expected test to fail" + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:fail_unexpected_passing_test --test_output=all --verbose_failures \ + >"$TEST_log" 2>&1 && fail "Expected test to fail" || true expect_log "Expected failure of target_under_test, but found success" }