Skip to content

Instantly share code, notes, and snippets.

@ob
Created August 21, 2018 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ob/22436553b03d608c82e54c01afb4caee to your computer and use it in GitHub Desktop.
Save ob/22436553b03d608c82e54c01afb4caee to your computer and use it in GitHub Desktop.
Bazel test cases
TEST_TMPDIR=`pwd`/cc
mkdir -p $TEST_TMPDIR
PATH=/Users/obonilla/o/bazel/bazel-bin/src:$PATH
set -ex
DFLG=""
test x"$DEBUG" = x || DFLG='--host_jvm_args="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005'
which bazel
function test_cc_library_include_prefix_external_repository() {
r="$TEST_TMPDIR/r"
mkdir -p "$TEST_TMPDIR/r/foo/v1"
touch "$TEST_TMPDIR/r/WORKSPACE"
echo "#define FOO 42" > "$TEST_TMPDIR/r/foo/v1/foo.h"
cat > "$TEST_TMPDIR/r/foo/BUILD" <<EOF
cc_library(
name = "foo",
hdrs = ["v1/foo.h"],
include_prefix = "foolib",
strip_include_prefix = "v1",
visibility = ["//visibility:public"],
)
EOF
cat > WORKSPACE <<EOF
local_repository(
name = "foo",
path = "$TEST_TMPDIR/r",
)
EOF
cat > BUILD <<EOF
cc_library(
name = "ok",
srcs = ["ok.cc"],
deps = ["@foo//foo"],
)
cc_library(
name = "bad",
srcs = ["bad.cc"],
deps = ["@foo//foo"],
)
EOF
cat > ok.cc <<EOF
#include <stdio.h>
#include "foolib/foo.h"
int main() {
printf("FOO is %d\n", FOO);
}
EOF
cat > bad.cc <<EOF
#include <stdio.h>
#include "foo/v1/foo.h"
int main() {
printf("FOO is %d\n", FOO);
}
EOF
# bazel build --sandbox_debug --verbose_failures -s :bad && fail "Should not have found include at repository-relative path"
bazel clean
bazel $DFLG build --sandbox_debug --verbose_failures -s :ok || fail "Should have found include at synthetic path"
}
test_cc_library_include_prefix_external_repository
TEST_TMPDIR=`pwd`/objc
mkdir -p $TEST_TMPDIR
PATH=/Users/obonilla/o/bazel/bazel-bin/src:$PATH
DFLG=""
test x$DEBUG = x || DFLG='--host_jvm_args="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"'
set -ex
which bazel
function test_objc_library_include_prefix_external_repository() {
r="$TEST_TMPDIR/r"
mkdir -p "$TEST_TMPDIR/r/foo/v1"
touch "$TEST_TMPDIR/r/WORKSPACE"
echo "#define FOO 42" > "$TEST_TMPDIR/r/foo/v1/foo.h"
cat > "$TEST_TMPDIR/r/foo/BUILD" <<EOF
objc_library(
name = "foo",
hdrs = ["v1/foo.h"],
include_prefix = "foolib",
strip_include_prefix = "v1",
visibility = ["//visibility:public"],
)
EOF
cat > WORKSPACE <<EOF
local_repository(
name = "foo",
path = "$TEST_TMPDIR/r",
)
EOF
cat > BUILD <<EOF
objc_library(
name = "ok",
srcs = ["ok.m"],
deps = ["@foo//foo"],
)
objc_library(
name = "bad",
srcs = ["bad.m"],
deps = ["@foo//foo"],
)
EOF
cat > ok.m <<EOF
#include <stdio.h>
#include "foolib/foo.h"
int main() {
printf("FOO is %d\n", FOO);
}
EOF
cat > bad.m <<EOF
#include <stdio.h>
#include "foo/v1/foo.h"
int main() {
printf("FOO is %d\n", FOO);
}
EOF
# bazel build --sandbox_debug --verbose_failures -s :bad && fail "Should not have found include at repository-relative path"
bazel clean
bazel $DFLG build --sandbox_debug --verbose_failures -s :ok || fail "Should have found include at synthetic path"
# bazel build --sandbox_debug --verbose_failures -s :ok || fail "Should have found include at synthetic path"
}
test_objc_library_include_prefix_external_repository
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment