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

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 @@
     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 @@
     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 @@
     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 @@
 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 @@
 )
 EOF
 
-  touch fakerules/BUILD
   cat > fakerules/BUILD <<EOF
 exports_files(["*.bzl"])
 EOF
@@ -118,27 +121,31 @@
 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 @@
 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 @@
 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 @@
     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"
 }