-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutilities.bats
51 lines (43 loc) · 1.34 KB
/
utilities.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bats
# shellcheck shell=bash
set -o pipefail
# Tests for the jb-echo jb-cat and jb-stream utilities.
setup() {
cd "${BATS_TEST_DIRNAME:?}"
}
function mktemp_bats() {
mktemp "${BATS_RUN_TMPDIR:?}/json.bats.XXX" "$@"
}
@test "jb-echo" {
run jb-echo
[[ $status == 0 && $output == '[]' ]]
run jb-echo "Hello World"
[[ $status == 0 && $output == '["Hello World"]' ]]
run jb-echo foo bar baz
[[ $status == 0 && $output == '["foo","bar","baz"]' ]]
}
@test "jb-cat" {
run sh -c 'printf "" | jb-cat'
[[ $status == 0 && $output == '""' ]]
run sh -c 'printf "\n" | jb-cat'
[[ $status == 0 && $output == '"\n"' ]]
run sh -c 'printf "foo\nbar\n" | jb-cat'
[[ $status == 0 && $output == '"foo\nbar\n"' ]]
dir=$(mktemp_bats -d)
printf "foo\nbar\n" > "${dir:?}/a"
printf "baz\nboz\n" > "${dir:?}/b"
run jb-cat "${dir:?}/a"
[[ $status == 0 && $output == '"foo\nbar\n"' ]]
run jb-cat "${dir:?}/a" "${dir:?}/b"
[[ $status == 0 && $output == '"foo\nbar\nbaz\nboz\n"' ]]
}
@test "jb-stream" {
run sh -c 'printf "" | jb-stream'
[[ $status == 0 && $output == '' ]]
run sh -c 'printf "\n" | jb-stream'
[[ $status == 0 && $output == '""' ]]
run sh -c 'printf "foo\n" | jb-stream'
[[ $status == 0 && $output == $'"foo"' ]]
run sh -c 'printf "foo\nbar\n" | jb-stream'
[[ $status == 0 && $output == $'"foo"\n"bar"' ]]
}