-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.bats
68 lines (55 loc) · 1.34 KB
/
test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bats
# Local directory relative to PWD
export JRNL_DIR=./.tmp
# Don't open interactively—touching is fine
export EDITOR=touch
# Stub out to use local `jrnl`
jrnl() {
./jrnl "${@}"
}
setup() {
mkdir -p "${JRNL_DIR}"
}
teardown() {
rm -rf "${JRNL_DIR}"
}
@test "jrnl --help prints usage & exits cleanly" {
run jrnl --help
[[ "${lines[0]}" == "Usage:" ]]
[[ "${status}" == 0 ]]
}
@test "jrnl creates \$JRNL_DIR if not exist" {
rm -rf "${JRNL_DIR}"
[[ ! -d "${JRNL_DIR}" ]]
run jrnl --help
[[ -d "${JRNL_DIR}" ]]
[[ "${status}" == 0 ]]
}
@test "jrnl no args makes an entry from today" {
today="$(date +%Y/%m/%d)"
run jrnl
[[ -f "${JRNL_DIR}/${today}.txt" ]]
[[ "${status}" == 0 ]]
}
@test "jrnl --list with single entry works" {
today="$(date +%Y/%m/%d)"
run jrnl
[[ -f "${JRNL_DIR}/${today}.txt" ]]
[[ "${status}" == 0 ]]
run jrnl --list
[[ "${output}" == "${today}" ]]
[[ "${status}" == 0 ]]
}
@test "jrnl w/ args is added to entry" {
# Skipping this for now since $lines doesn't capture blank lines
# https://github.com/bats-core/bats-core/issues/224
skip
today="$(date +%Y/%m/%d)"
content="some content"
run jrnl "$content"
[[ -f "${JRNL_DIR}/${today}.txt" ]]
[[ "${status}" == 0 ]]
run cat "${JRNL_DIR}/${today}.txt"
[[ "${lines[2]}" == "${content}" ]]
[[ "${status}" == 0 ]]
}