Skip to content

Commit 700af6e

Browse files
committed
test: load imports/setup in setup/setup_file bat callbacks
1 parent 02c8c00 commit 700af6e

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

test/bugs.bats

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
#!/usr/bin/env bats
22

3-
load 'test_helper/bats-support/load'
4-
load 'test_helper/bats-assert/load'
5-
load 'test_helper/util'
3+
# Used by both `setup_file` and `setup`, which are special bats callbacks.
4+
__load_imports__() {
5+
load 'test_helper/bats-support/load'
6+
load 'test_helper/bats-assert/load'
7+
load 'test_helper/util'
8+
}
9+
10+
setup_file() {
11+
__load_imports__
12+
}
13+
14+
setup() {
15+
__load_imports__
16+
}
617

718
# https://github.com/paulirish/dotfiles/commit/6743b907ff586c28cd36e08d1e1c634e2968893e#commitcomment-13459061
819
@test "All removed lines are present in diff" {

test/diff-so-fancy.bats

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
#!/usr/bin/env bats
22

3-
load 'test_helper/bats-support/load'
4-
load 'test_helper/bats-assert/load'
5-
load 'test_helper/util'
3+
# Helper invoked by `setup_file` and `setup`, which are special bats callbacks.
4+
__load_imports__() {
5+
load 'test_helper/bats-support/load'
6+
load 'test_helper/bats-assert/load'
7+
load 'test_helper/util'
8+
}
9+
10+
setup_file() {
11+
__load_imports__
12+
}
613

7-
set_env
14+
setup() {
15+
__load_imports__
816

9-
# bats fails to handle our multiline result, so we save to $output ourselves
10-
output=$( load_fixture "ls-function" | $diff_so_fancy )
17+
set_env
18+
19+
# bats fails to handle our multiline result, so we save to $output ourselves
20+
output=$( load_fixture "ls-function" | $diff_so_fancy )
21+
}
1122

1223
@test "diff-so-fancy runs and exits without error" {
1324
load_fixture "ls-function" | $diff_so_fancy

0 commit comments

Comments
 (0)