Skip to content

Commit 64efc73

Browse files
committed
move assert() to separate files
1 parent 5499bfb commit 64efc73

File tree

5 files changed

+38
-30
lines changed

5 files changed

+38
-30
lines changed

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ dependencies:
55

66
test:
77
post:
8-
- bats *.bats
8+
- bats . lib

lib/assert.bash

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
set -o errexit
3+
4+
source lib/batslib.bash
5+
6+
assert() {
7+
[[ $1 = that ]] && shift
8+
9+
case $@ in
10+
*' = '*) assert_equal $1 "${*:3}" ;;
11+
'output contains '*) assert_output -p "${*:3}" ;;
12+
'output does not contain '*) refute_output -p "${*:5}" ;;
13+
*) fail invalid assertion: $@
14+
esac
15+
}

lib/assert.bats

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bats
2+
3+
load assert
4+
5+
@test 'assert asserts equality' {
6+
assert that 1 = 1
7+
}
8+
@test ' asserts output content' {
9+
run echo abc
10+
assert that output contains b
11+
}
12+
@test ' refutes output content' {
13+
run echo abc
14+
assert that output does not contain d
15+
}

unit-test.bats

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
#!/usr/bin/env bats
22

3-
source lib/batslib.bash
4-
5-
assert() {
6-
[[ $1 = that ]] && shift
7-
8-
case $@ in
9-
*' = '*) assert_equal $1 "${*:3}" ;;
10-
'output contains '*) assert_output -p "${*:3}" ;;
11-
'output does not contain '*) refute_output -p "${*:5}" ;;
12-
*) fail invalid assertion: $@
13-
esac
14-
}
15-
16-
@test 'assert asserts equality' {
17-
assert that 1 = 1
18-
}
19-
@test ' asserts output content' {
20-
run echo abc
21-
assert that output contains b
22-
}
23-
@test ' refutes output content' {
24-
run echo abc
25-
assert that output does not contain d
26-
}
27-
3+
source lib/assert.bash
284
source deploy.sh --source-only
295

306
repo=https://secret@github.com/user/repo.git

watch

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
# uses entr to watch for changes: http://entrproject.org
44

5-
# re-run any individual .bats file when it changes. -p to postpone the first execution, since the 2nd entr command below will run all the .bats files.
6-
ls *.bats | entr -p bats /_ &
5+
# re-run any individual .bats file when it changes. -p to postpone the first execution, since the commands below will run all the .bats files.
6+
shopt -s globstar
7+
ls **/*.bats | entr -p bats /_ &
78

8-
# re-run all tests when the script under test changes.
9-
echo deploy.sh | entr bats .
9+
# re-run relevant tests when a source file changes.
10+
echo deploy.sh | entr bats . &
11+
ls lib/*.bash | entr bats lib

0 commit comments

Comments
 (0)