Skip to content

Commit f695e29

Browse files
committed
build: improve bats tests
Signed-off-by: Josef Andersson <josef.andersson@digg.se>
1 parent 9496b96 commit f695e29

15 files changed

+121
-65
lines changed

tests/check-tools.bats

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ bats_require_minimum_version 1.13.0
99
load "${BATS_TEST_DIRNAME}/libs/bats-support/load.bash"
1010
load "${BATS_TEST_DIRNAME}/libs/bats-assert/load.bash"
1111
load "${BATS_TEST_DIRNAME}/libs/bats-file/load.bash"
12+
load "${BATS_TEST_DIRNAME}/test_helper.bash"
1213

1314
setup() {
14-
export SCRIPT_DIR="${BATS_TEST_DIRNAME}/../scripts"
15+
export DEVTOOLS_ROOT="${BATS_TEST_DIRNAME}/.."
16+
export SCRIPT_DIR="${DEVTOOLS_ROOT}/scripts"
1517
}
1618

1719
@test "check-tools.sh checks for specified tools" {

tests/linters-actions.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ load "${BATS_TEST_DIRNAME}/libs/bats-support/load.bash"
1010
load "${BATS_TEST_DIRNAME}/libs/bats-assert/load.bash"
1111
load "${BATS_TEST_DIRNAME}/libs/bats-file/load.bash"
1212
load "${BATS_TEST_DIRNAME}/libs/bats-mock/stub.bash"
13+
load "${BATS_TEST_DIRNAME}/test_helper.bash"
1314

1415
setup() {
15-
TEST_DIR="$(temp_make)"
16-
export TEST_DIR
17-
export LINTERS_DIR="${BATS_TEST_DIRNAME}/../linters"
16+
common_setup
17+
export LINTERS_DIR="${DEVTOOLS_ROOT}/linters"
1818
cd "$TEST_DIR"
1919
}
2020

2121
teardown() {
2222
unstub actionlint 2>/dev/null || true
23-
temp_del "$TEST_DIR"
23+
common_teardown
2424
}
2525

2626
@test "github-actions.sh runs actionlint when workflows exist" {

tests/linters-commits.bats

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ load "${BATS_TEST_DIRNAME}/libs/bats-mock/stub.bash"
1313
load "${BATS_TEST_DIRNAME}/test_helper.bash"
1414

1515
setup() {
16-
TEST_DIR="$(temp_make)"
17-
export TEST_DIR
18-
export LINTERS_DIR="${BATS_TEST_DIRNAME}/../linters"
16+
common_setup
17+
export LINTERS_DIR="${DEVTOOLS_ROOT}/linters"
1918
cd "$TEST_DIR"
20-
git init -q
19+
init_git_repo
2120
}
2221

2322
teardown() {
2423
unstub conform 2>/dev/null || true
25-
safe_temp_del "$TEST_DIR"
24+
common_teardown
2625
}
2726

2827
@test "commits.sh skips on default branch" {

tests/linters-java.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ load "${BATS_TEST_DIRNAME}/libs/bats-support/load.bash"
1010
load "${BATS_TEST_DIRNAME}/libs/bats-assert/load.bash"
1111
load "${BATS_TEST_DIRNAME}/libs/bats-file/load.bash"
1212
load "${BATS_TEST_DIRNAME}/libs/bats-mock/stub.bash"
13+
load "${BATS_TEST_DIRNAME}/test_helper.bash"
1314

1415
setup() {
15-
TEST_DIR="$(temp_make)"
16-
export TEST_DIR
17-
export JAVA_LINTERS="${BATS_TEST_DIRNAME}/../linters/java"
16+
common_setup
17+
export JAVA_LINTERS="${DEVTOOLS_ROOT}/linters/java"
1818
cd "$TEST_DIR"
1919
}
2020

2121
teardown() {
2222
unstub mvn 2>/dev/null || true
23-
temp_del "$TEST_DIR"
23+
common_teardown
2424
}
2525

2626
@test "lint.sh skips when no pom.xml present" {

tests/linters-license.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ load "${BATS_TEST_DIRNAME}/libs/bats-support/load.bash"
1010
load "${BATS_TEST_DIRNAME}/libs/bats-assert/load.bash"
1111
load "${BATS_TEST_DIRNAME}/libs/bats-file/load.bash"
1212
load "${BATS_TEST_DIRNAME}/libs/bats-mock/stub.bash"
13+
load "${BATS_TEST_DIRNAME}/test_helper.bash"
1314

1415
setup() {
15-
TEST_DIR="$(temp_make)"
16-
export TEST_DIR
17-
export LINTERS_DIR="${BATS_TEST_DIRNAME}/../linters"
16+
common_setup
17+
export LINTERS_DIR="${DEVTOOLS_ROOT}/linters"
1818
cd "$TEST_DIR"
1919
}
2020

2121
teardown() {
2222
unstub reuse 2>/dev/null || true
23-
temp_del "$TEST_DIR"
23+
common_teardown
2424
}
2525

2626
@test "license.sh runs reuse lint" {

tests/linters-markdown.bats

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,23 @@ load "${BATS_TEST_DIRNAME}/libs/bats-support/load.bash"
1010
load "${BATS_TEST_DIRNAME}/libs/bats-assert/load.bash"
1111
load "${BATS_TEST_DIRNAME}/libs/bats-file/load.bash"
1212
load "${BATS_TEST_DIRNAME}/libs/bats-mock/stub.bash"
13+
load "${BATS_TEST_DIRNAME}/test_helper.bash"
1314

1415
setup() {
15-
TEST_DIR="$(temp_make)"
16-
export TEST_DIR
17-
export LINTERS_DIR="${BATS_TEST_DIRNAME}/../linters"
16+
common_setup
17+
export LINTERS_DIR="${DEVTOOLS_ROOT}/linters"
1818
cd "$TEST_DIR"
1919
}
2020

2121
teardown() {
22-
unstub rumdl 2>/dev/null || true
23-
temp_del "$TEST_DIR"
22+
common_teardown
2423
}
2524

2625
@test "markdown.sh check runs rumdl" {
2726
cat > test.md << 'EOF'
2827
# Test
2928
EOF
30-
stub rumdl "check . --disable MD013 : true"
29+
stub_repeated rumdl "true"
3130

3231
run --separate-stderr "$LINTERS_DIR/markdown.sh" check
3332

@@ -40,7 +39,7 @@ EOF
4039
cat > test.md << 'EOF'
4140
# Test
4241
EOF
43-
stub rumdl "check --fix . --disable MD013 : true"
42+
stub_repeated rumdl "true"
4443

4544
run --separate-stderr "$LINTERS_DIR/markdown.sh" fix
4645

tests/linters-node.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ load "${BATS_TEST_DIRNAME}/libs/bats-support/load.bash"
1010
load "${BATS_TEST_DIRNAME}/libs/bats-assert/load.bash"
1111
load "${BATS_TEST_DIRNAME}/libs/bats-file/load.bash"
1212
load "${BATS_TEST_DIRNAME}/libs/bats-mock/stub.bash"
13+
load "${BATS_TEST_DIRNAME}/test_helper.bash"
1314

1415
setup() {
15-
TEST_DIR="$(temp_make)"
16-
export TEST_DIR
17-
export NODE_LINTERS="${BATS_TEST_DIRNAME}/../linters/node"
16+
common_setup
17+
export NODE_LINTERS="${DEVTOOLS_ROOT}/linters/node"
1818
cd "$TEST_DIR"
1919
}
2020

2121
teardown() {
2222
unstub npx 2>/dev/null || true
23-
temp_del "$TEST_DIR"
23+
common_teardown
2424
}
2525

2626
@test "eslint.sh skips when no package.json present" {

tests/linters-secrets.bats

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ load "${BATS_TEST_DIRNAME}/libs/bats-mock/stub.bash"
1313
load "${BATS_TEST_DIRNAME}/test_helper.bash"
1414

1515
setup() {
16-
TEST_DIR="$(temp_make)"
17-
export TEST_DIR
18-
export LINTERS_DIR="${BATS_TEST_DIRNAME}/../linters"
16+
common_setup
17+
export LINTERS_DIR="${DEVTOOLS_ROOT}/linters"
1918
cd "$TEST_DIR"
20-
git init -q
19+
init_git_repo
2120
}
2221

2322
teardown() {
2423
unstub gitleaks 2>/dev/null || true
25-
safe_temp_del "$TEST_DIR"
24+
common_teardown
2625
}
2726

2827
@test "secrets.sh runs gitleaks" {

tests/linters-shell-fmt.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ load "${BATS_TEST_DIRNAME}/libs/bats-support/load.bash"
1010
load "${BATS_TEST_DIRNAME}/libs/bats-assert/load.bash"
1111
load "${BATS_TEST_DIRNAME}/libs/bats-file/load.bash"
1212
load "${BATS_TEST_DIRNAME}/libs/bats-mock/stub.bash"
13+
load "${BATS_TEST_DIRNAME}/test_helper.bash"
1314

1415
setup() {
15-
TEST_DIR="$(temp_make)"
16-
export TEST_DIR
17-
export LINTERS_DIR="${BATS_TEST_DIRNAME}/../linters"
16+
common_setup
17+
export LINTERS_DIR="${DEVTOOLS_ROOT}/linters"
1818
cd "$TEST_DIR"
1919
}
2020

2121
teardown() {
2222
unstub shfmt 2>/dev/null || true
23-
temp_del "$TEST_DIR"
23+
common_teardown
2424
}
2525

2626
@test "shell-fmt.sh check runs shfmt" {

tests/linters-shell.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ load "${BATS_TEST_DIRNAME}/libs/bats-support/load.bash"
1010
load "${BATS_TEST_DIRNAME}/libs/bats-assert/load.bash"
1111
load "${BATS_TEST_DIRNAME}/libs/bats-file/load.bash"
1212
load "${BATS_TEST_DIRNAME}/libs/bats-mock/stub.bash"
13+
load "${BATS_TEST_DIRNAME}/test_helper.bash"
1314

1415
setup() {
15-
TEST_DIR="$(temp_make)"
16-
export TEST_DIR
17-
export LINTERS_DIR="${BATS_TEST_DIRNAME}/../linters"
16+
common_setup
17+
export LINTERS_DIR="${DEVTOOLS_ROOT}/linters"
1818
cd "$TEST_DIR"
1919
}
2020

2121
teardown() {
2222
unstub shellcheck 2>/dev/null || true
23-
temp_del "$TEST_DIR"
23+
common_teardown
2424
}
2525

2626
@test "shell.sh runs shellcheck on shell files" {

0 commit comments

Comments
 (0)