Skip to content

Commit

Permalink
integration tests passing locally
Browse files Browse the repository at this point in the history
  • Loading branch information
jmelahman authored and filmil committed Nov 24, 2021
1 parent e7dd11e commit 1b29f02
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions integration/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test --test_output=errors
42 changes: 42 additions & 0 deletions integration/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
load("@bazel_bats//:rules.bzl", "bats_test")

sh_binary(
name = "exit_with_input_bin",
srcs = ["exit_with_input"],
)

bats_test(
name = "exit_with_input_test",
srcs = ["exit_with_input.bats"],
deps = [
":exit_with_input_bin",
],
)

sh_library(
name = "helper",
srcs = ["helper.bash"],
)

bats_test(
name = "expected_failure",
srcs = ["expected_failure.bats"],
tags = ["manual"],
)

sh_test(
name = "expected_failure_test",
srcs = ["run_expected_failures.sh"],
data = [":expected_failure"],
)

bats_test(
name = "hello_world_load_test",
srcs = ["hello_world_load.bats"],
deps = [":helper"],
)

bats_test(
name = "hello_world_data_test",
srcs = ["hello_world_data.bats"],
data = ["testdata/golden_4.txt"],
)

bats_test(
name = "hello_world_test",
srcs = ["hello_world.bats"],
Expand Down
4 changes: 2 additions & 2 deletions integration/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

BAZEL_BATS_VERSION = "0.29.1"

HEAD = "75dea0bc4d15d48a4238ad2143e998509c0cb3e4"
HEAD = "9ea10a4638ca49e26e779d01efafbf3a25ee5215"

http_archive(
name = "bazel_bats",
sha256 = "e57d61da26bbb5428e8162da4fa2432d85abc2530b6211dd2d096d75be18d9fb",
sha256 = "7633d79b3dfa52a3b822129c44b5ed83ab3b6dbb520056b7a3d0366177673d1d",
# TODO: Tag and release HEAD.
# strip_prefix = "bazel-bats-%s" % BAZEL_BATS_VERSION,
strip_prefix = "bazel-bats-%s" % HEAD,
Expand Down
2 changes: 2 additions & 0 deletions integration/exit_with_input
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
exit $1
13 changes: 13 additions & 0 deletions integration/exit_with_input.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bats

PATH_TO_EXIT_WITH_INPUT="exit_with_input"

@test "can run executable" {
run "${PATH_TO_EXIT_WITH_INPUT}" 1
[ $status -eq 1 ]
}

@test "can run executable with different return code" {
run "${PATH_TO_EXIT_WITH_INPUT}" 2
[ $status -eq 2 ]
}
5 changes: 5 additions & 0 deletions integration/expected_failure.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bats

@test "addition using bc" {
[ 1 -eq 2 ]
}
7 changes: 7 additions & 0 deletions integration/hello_world_data.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bats

@test "can read from data" {
run echo 4
[ $status -eq 0 ]
[ "$output" == "$(< 'testdata/golden_4.txt')" ]
}
9 changes: 9 additions & 0 deletions integration/hello_world_load.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bats

load "helper"

@test "can run function from loaded library" {
run echo4
[ $status -eq 0 ]
[ "$output" == "4" ]
}
5 changes: 5 additions & 0 deletions integration/helper.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

function echo4() {
echo "4"
}
3 changes: 3 additions & 0 deletions integration/run_expected_failures.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
tests/expected_failure
[ $? != 0 ]
1 change: 1 addition & 0 deletions integration/testdata/golden_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4

0 comments on commit 1b29f02

Please sign in to comment.