diff options
author | László Csomor <laszlocsomor@users.noreply.github.com> | 2019-03-19 13:37:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-19 13:37:33 +0100 |
commit | b2dc5c0e63efdcfaddc0b4a4ecd8b0f8bea07978 (patch) | |
tree | ac19b75b95228064d0d4b830f04898b29d978f74 /tests | |
parent | 2d1669ed882652e5fc695bb99c77442a9273ff56 (diff) | |
download | bazel-skylib-b2dc5c0e63efdcfaddc0b4a4ecd8b0f8bea07978.tar.gz |
e2e tests: make them run on Windows (#121)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/BUILD | 6 | ||||
-rwxr-xr-x | tests/analysis_test_test.sh | 37 | ||||
-rwxr-xr-x | tests/unittest_test.sh | 40 |
3 files changed, 58 insertions, 25 deletions
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 <<EOF workspace(name = 'bazel_skylib') EOF - touch rules/BUILD + mkdir -p rules cat > rules/BUILD <<EOF exports_files(["*.bzl"]) EOF + ln -sf "$(rlocation bazel_skylib/rules/analysis_test.bzl)" rules/analysis_test.bzl + mkdir -p fakerules - touch fakerules/rules.bzl cat > fakerules/rules.bzl <<EOF load("//rules:analysis_test.bzl", "analysis_test") @@ -76,7 +80,6 @@ fake_depending_rule = rule( ) EOF - touch fakerules/BUILD cat > fakerules/BUILD <<EOF exports_files(["*.bzl"]) EOF @@ -118,27 +121,31 @@ analysis_test( EOF } -function tear_down() { - rm -rf testdir - rm -rf fakerules -} - function test_target_succeeds() { - bazel test //testdir:target_succeeds >"$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 <<EOF workspace(name = 'bazel_skylib') @@ -55,15 +58,24 @@ load("//lib:unittest.bzl", "register_unittest_toolchains") register_unittest_toolchains() EOF + mkdir -p tests touch tests/BUILD cat > tests/BUILD <<EOF exports_files(["*.bzl"]) EOF + ln -sf "$(rlocation bazel_skylib/tests/unittest_tests.bzl)" tests/unittest_tests.bzl + mkdir -p lib touch lib/BUILD cat > lib/BUILD <<EOF exports_files(["*.bzl"]) EOF + ln -sf "$(rlocation bazel_skylib/lib/dicts.bzl)" lib/dicts.bzl + ln -sf "$(rlocation bazel_skylib/lib/new_sets.bzl)" lib/new_sets.bzl + ln -sf "$(rlocation bazel_skylib/lib/old_sets.bzl)" lib/old_sets.bzl + ln -sf "$(rlocation bazel_skylib/lib/sets.bzl)" lib/sets.bzl + ln -sf "$(rlocation bazel_skylib/lib/types.bzl)" lib/types.bzl + ln -sf "$(rlocation bazel_skylib/lib/unittest.bzl)" lib/unittest.bzl mkdir -p testdir cat > testdir/BUILD <<EOF @@ -85,28 +97,36 @@ fail_unexpected_passing_fake_rule( name = "fail_unexpected_passing_fake_target", tags = ["manual"]) EOF -} -function tear_down() { - rm -rf testdir + mkdir -p toolchains/unittest + ln -sf "$(rlocation bazel_skylib/toolchains/unittest/BUILD)" toolchains/unittest/BUILD } function test_basic_passing_test() { - bazel test //testdir:basic_passing_test >"$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" } |