e2e tests: make them run on Windows (#121)

This commit is contained in:
László Csomor 2019-03-19 13:37:33 +01:00 committed by GitHub
parent 2d1669ed88
commit b2dc5c0e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 31 deletions

View File

@ -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

View File

@ -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",
],

View File

@ -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"
}

View File

@ -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"
}