Skip to content

Commit

Permalink
Make tests more portable
Browse files Browse the repository at this point in the history
By replacing uses of /bin/bash by /bin/sh, a tool which is more
reliably at this location. Then, enable most of the bazel tests
for FreeBSD as well.

Change-Id: Ic56a1705858f1ed67d1e96e2937e9389dd1d0e36
PiperOrigin-RevId: 164241635
  • Loading branch information
aehlig authored and dslomov committed Aug 4, 2017
1 parent 0286694 commit 49463f6
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 64 deletions.
3 changes: 2 additions & 1 deletion scripts/ci/bazel-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"{} +"
],
"tests": [
"//src/test/shell/integration/..."
"//src/test/shell/integration/...",
"let bazel=\"//src/test/shell/bazel/...\" in $bazel - filter(\"all_tests\", $bazel) - filter(\"jdk\", $bazel) - filter(\"maven\", $bazel) - filter(\"android\", $bazel) - filter(\"java\", $bazel) - filter(\"workspace\", $bazel) - filter(\"external\", $bazel) - filter(\"example\", $bazel) - filter(\"skylark_repository\", $bazel) - filter(\"repository_cache\", $bazel)"
],
"targets": []
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/bazel_localtest_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function test_run_local() {
# In standalone mode,
# we have access to /var which is not mounted in sandboxed mode
cat <<EOF > dir/test_local.sh
#!/bin/bash
#!/bin/sh
test -e "$(pwd)/emptyfile" && exit 0 || true
echo "no $(pwd)/emptyfile in standalone mode"
exit 1
Expand Down
4 changes: 2 additions & 2 deletions src/test/shell/bazel/bazel_repository_cache_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ filegroup(
EOF
what_does_the_fox_say="Fraka-kaka-kaka-kaka-kow"
cat > fox/male <<EOF
#!/bin/bash
#!/bin/sh
echo $what_does_the_fox_say
EOF
chmod +x fox/male
Expand Down Expand Up @@ -180,7 +180,7 @@ sh_binary(
EOF

cat > zoo/female.sh <<EOF
#!/bin/bash
#!/bin/sh
../endangered/fox/male
EOF
chmod +x zoo/female.sh
Expand Down
4 changes: 2 additions & 2 deletions src/test/shell/bazel/bazel_rules_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function test_extra_action() {
# action file. This file is a proto, but I don't want to bother implementing
# a program that parses the proto here.
cat > mypkg/echoer.sh <<EOF
#!/bin/bash
#!/bin/sh
if [[ ! -e \$0.runfiles/__main__/mypkg/runfile ]]; then
echo "Runfile not found" >&2
exit 1
Expand Down Expand Up @@ -275,7 +275,7 @@ sh_binary(
EOF

cat > package/in.sh << EOF
#!/bin/bash
#!/bin/sh
echo "Hi"
EOF
chmod +x package/in.sh
Expand Down
12 changes: 6 additions & 6 deletions src/test/shell/bazel/bazel_test_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function set_up_jobcount() {
mkdir -p dir

cat <<EOF > dir/test.sh
#!/bin/bash
#!/bin/sh
# hard link
z=\$(mktemp -u ${tmp}/tmp.XXXXXXXX)
ln ${tmp}/counter \${z}
Expand All @@ -41,7 +41,7 @@ sleep 1
nlink=\$(ls -l ${tmp}/counter | awk '{print \$2}')
# 4 links = 3 jobs + ${tmp}/counter
if [[ "\$nlink" -gt 4 ]] ; then
if [ "\$nlink" -gt 4 ] ; then
echo found "\$nlink" hard links to file, want 4 max.
exit 1
fi
Expand Down Expand Up @@ -84,7 +84,7 @@ function test_3_local_jobs() {
function DISABLED_test_tmpdir() {
mkdir -p foo
cat > foo/bar_test.sh <<'EOF'
#!/bin/bash
#!/bin/sh
echo TEST_TMPDIR=$TEST_TMPDIR
EOF
chmod +x foo/bar_test.sh
Expand Down Expand Up @@ -123,7 +123,7 @@ workspace(name = "bar")
EOF
mkdir -p foo
cat > foo/testenv.sh <<'EOF'
#!/bin/bash
#!/bin/sh
echo "pwd: $PWD"
echo "src: $TEST_SRCDIR"
echo "ws: $TEST_WORKSPACE"
Expand Down Expand Up @@ -254,8 +254,8 @@ function test_runs_per_test_detects_flakes() {
# This file holds the number of the next run
echo 1 > "${COUNTER_DIR}/$i"
cat <<EOF > test$i.sh
#!/bin/bash
i=\$(< "${COUNTER_DIR}/$i")
#!/bin/sh
i=\$(cat "${COUNTER_DIR}/$i")
# increment the hidden state
echo \$((i + 1)) > "${COUNTER_DIR}/$i"
Expand Down
54 changes: 27 additions & 27 deletions src/test/shell/bazel/external_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ filegroup(
EOF
what_does_the_fox_say="Fraka-kaka-kaka-kaka-kow"
cat > fox/male <<EOF
#!/bin/bash
#!/bin/sh
echo $what_does_the_fox_say
EOF
chmod +x fox/male
Expand All @@ -125,7 +125,7 @@ EOF
cat > WORKSPACE <<EOF
http_archive(
name = 'endangered',
url = 'http://localhost:$nc_port/$repo2_name',
url = 'http://127.0.0.1:$nc_port/$repo2_name',
sha256 = '$sha256'
)
EOF
Expand All @@ -139,7 +139,7 @@ sh_binary(
EOF

cat > zoo/female.sh <<EOF
#!/bin/bash
#!/bin/sh
../endangered/fox/male
EOF
chmod +x zoo/female.sh
Expand Down Expand Up @@ -183,7 +183,7 @@ function test_http_archive_zip() {
cat > WORKSPACE <<EOF
http_archive(
name = 'endangered',
url = 'http://localhost:$nc_port/bleh',
url = 'http://127.0.0.1:$nc_port/bleh',
sha256 = '$sha256',
type = 'zip',
)
Expand Down Expand Up @@ -219,7 +219,7 @@ sh_binary(
EOF

cat > zoo/female.sh <<EOF
#!/bin/bash
#!/bin/sh
cat fox/male
EOF
chmod +x zoo/female.sh
Expand All @@ -244,7 +244,7 @@ function test_http_archive_mismatched_sha256() {
cat > WORKSPACE <<EOF
http_archive(
name = 'endangered',
url = 'http://localhost:$nc_port/repo.zip',
url = 'http://127.0.0.1:$nc_port/repo.zip',
sha256 = '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9826',
)
EOF
Expand All @@ -258,7 +258,7 @@ sh_binary(
EOF

cat > zoo/female.sh <<EOF
#!/bin/bash
#!/bin/sh
cat fox/male
EOF
chmod +x zoo/female.sh
Expand Down Expand Up @@ -318,7 +318,7 @@ function test_jar_download() {
serve_jar

cat > WORKSPACE <<EOF
http_jar(name = 'endangered', url = 'http://localhost:$nc_port/lib.jar')
http_jar(name = 'endangered', url = 'http://127.0.0.1:$nc_port/lib.jar')
EOF

mkdir -p zoo
Expand Down Expand Up @@ -350,7 +350,7 @@ function test_http_to_https_redirect() {
http_response=$TEST_TMPDIR/http_response
cat > $http_response <<EOF
HTTP/1.0 301 Moved Permantently
Location: https://localhost:123456789/bad-port-shouldnt-work
Location: https://127.0.0.1:123456789/bad-port-shouldnt-work
EOF
nc_port=$(pick_random_unused_tcp_port) || exit 1
nc_l $nc_port < $http_response &
Expand All @@ -360,7 +360,7 @@ EOF
cat > WORKSPACE <<EOF
http_file(
name = 'toto',
url = 'http://localhost:$nc_port/toto',
url = 'http://127.0.0.1:$nc_port/toto',
sha256 = '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9826'
)
EOF
Expand All @@ -378,7 +378,7 @@ function test_http_404() {
cat > WORKSPACE <<EOF
http_file(
name = 'toto',
url = 'http://localhost:$nc_port/toto',
url = 'http://127.0.0.1:$nc_port/toto',
sha256 = '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9826'
)
EOF
Expand All @@ -391,15 +391,15 @@ EOF
function test_http_download() {
local test_file=$TEST_TMPDIR/toto
cat > $test_file <<EOF
#!/bin/bash
#!/bin/sh
echo "Tra-la!"
EOF
local sha256=$(sha256sum $test_file | cut -f 1 -d ' ')
serve_file $test_file
cd ${WORKSPACE_DIR}

cat > WORKSPACE <<EOF
http_file(name = 'toto', url = 'http://localhost:$nc_port/toto',
http_file(name = 'toto', url = 'http://127.0.0.1:$nc_port/toto',
sha256 = '$sha256', executable = True)
EOF

Expand All @@ -413,7 +413,7 @@ sh_binary(
EOF

cat > test/test.sh <<EOF
#!/bin/bash
#!/bin/sh
echo "symlink:"
ls -l ../toto/file
echo "dest:"
Expand All @@ -434,10 +434,10 @@ function test_http_redirect() {
local sha256=$(sha256sum $test_file | cut -f 1 -d ' ')
serve_file $test_file
cd ${WORKSPACE_DIR}
serve_redirect "http://localhost:$nc_port/toto"
serve_redirect "http://127.0.0.1:$nc_port/toto"

cat > WORKSPACE <<EOF
http_file(name = 'toto', url = 'http://localhost:$redirect_port/toto',
http_file(name = 'toto', url = 'http://127.0.0.1:$redirect_port/toto',
sha256 = '$sha256')
EOF

Expand All @@ -451,7 +451,7 @@ sh_binary(
EOF

cat > test/test.sh <<EOF
#!/bin/bash
#!/bin/sh
cat ../toto/file/toto
EOF

Expand All @@ -471,7 +471,7 @@ function test_empty_file() {
cat > WORKSPACE <<EOF
new_http_archive(
name = "x",
url = "http://localhost:$nc_port/x.tar.gz",
url = "http://127.0.0.1:$nc_port/x.tar.gz",
sha256 = "$sha256",
build_file = "x.BUILD",
)
Expand Down Expand Up @@ -569,7 +569,7 @@ EOF
cat > WORKSPACE <<EOF
new_http_archive(
name = 'endangered',
url = 'http://localhost:$nc_port/repo.zip',
url = 'http://127.0.0.1:$nc_port/repo.zip',
sha256 = '$sha256',
${build_file_attr},
${workspace_file_attr}
Expand All @@ -586,7 +586,7 @@ sh_binary(
EOF

cat > zoo/female.sh <<EOF
#!/bin/bash
#!/bin/sh
cat ../endangered/fox/male
EOF
chmod +x zoo/female.sh
Expand All @@ -604,7 +604,7 @@ function test_fetch() {
maven_jar(
name = 'endangered',
artifact = "com.example.carnivore:carnivore:1.23",
repository = 'http://localhost:$nc_port/',
repository = 'http://127.0.0.1:$nc_port/',
sha1 = '$sha1',
)
bind(name = 'mongoose', actual = '@endangered//jar')
Expand Down Expand Up @@ -642,7 +642,7 @@ function test_prefix_stripping_tar_gz() {
cat > WORKSPACE <<EOF
new_http_archive(
name = "x",
url = "http://localhost:$nc_port/x.tar.gz",
url = "http://127.0.0.1:$nc_port/x.tar.gz",
sha256 = "$sha256",
strip_prefix = "x/y/z",
build_file = "x.BUILD",
Expand Down Expand Up @@ -671,7 +671,7 @@ function test_prefix_stripping_zip() {
cat > WORKSPACE <<EOF
new_http_archive(
name = "x",
url = "http://localhost:$nc_port/x.zip",
url = "http://127.0.0.1:$nc_port/x.zip",
sha256 = "$sha256",
strip_prefix = "x/y/z",
build_file = "x.BUILD",
Expand Down Expand Up @@ -709,7 +709,7 @@ EOF
cat > WORKSPACE <<EOF
http_archive(
name = "x",
url = "http://localhost:$nc_port/x.zip",
url = "http://127.0.0.1:$nc_port/x.zip",
sha256 = "$sha256",
strip_prefix = "x/y/z",
)
Expand All @@ -728,7 +728,7 @@ function test_moving_build_file() {
cat > WORKSPACE <<EOF
new_http_archive(
name = "x",
url = "http://localhost:$nc_port/x.tar.gz",
url = "http://127.0.0.1:$nc_port/x.tar.gz",
sha256 = "$sha256",
build_file = "x.BUILD",
)
Expand Down Expand Up @@ -764,7 +764,7 @@ function test_changing_build_file() {
cat > WORKSPACE <<EOF
new_http_archive(
name = "x",
url = "http://localhost:$nc_port/x.tar.gz",
url = "http://127.0.0.1:$nc_port/x.tar.gz",
sha256 = "$sha256",
build_file = "x.BUILD",
)
Expand Down Expand Up @@ -834,7 +834,7 @@ EOF
cat > remote_ws <<EOF
http_archive(
name = "repo",
url = "http://localhost:$fileserver_port/repo.zip",
url = "http://127.0.0.1:$fileserver_port/repo.zip",
)
EOF
external_dir=$(bazel info output_base)/external
Expand Down
8 changes: 4 additions & 4 deletions src/test/shell/bazel/git_repository_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ sh_binary(
EOF

cat > planets/planet_info.sh <<EOF
#!/bin/bash
#!/bin/sh
cat ../pluto/info
EOF
chmod +x planets/planet_info.sh
Expand Down Expand Up @@ -171,7 +171,7 @@ sh_binary(
EOF

cat > planets/planet_info.sh <<EOF
#!/bin/bash
#!/bin/sh
cat ../pluto/info
EOF
chmod +x planets/planet_info.sh
Expand Down Expand Up @@ -246,7 +246,7 @@ sh_binary(
EOF

cat > planets/planet_info.sh <<EOF
#!/bin/bash
#!/bin/sh
cat ../outer_planets/neptune/info
cat ../outer_planets/pluto/info
EOF
Expand Down Expand Up @@ -351,7 +351,7 @@ function setup_error_test() {
cd $WORKSPACE_DIR
mkdir -p planets
cat > planets/planet_info.sh <<EOF
#!/bin/bash
#!/bin/sh
cat external/pluto/info
EOF

Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/local_repository_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ sh_binary(
EOF

cat > zoo/dumper.sh <<EOF
#!/bin/bash
#!/bin/sh
cat ../pandas/red/baby-panda
cat red/day-keeper
EOF
Expand Down
Loading

0 comments on commit 49463f6

Please sign in to comment.