File: test_hello_timed

package info (click to toggle)
bash-unit 2.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 1,304 kB
  • sloc: sh: 1,134; makefile: 10
file content (34 lines) | stat: -rw-r--r-- 932 bytes parent folder | download
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
# In this example, we want to test a script which depends on
# the external world (here, the current time). To do so,
# we decide to adapt the script by extracting the time
# querying in a dedicated function named current_hour.
# That way, we can fake the current hour in the test.
# Unfortunately, we also need to adapt the script under
# test so that, when the current_time function is already
# defined, the script does not override this definition.
# Otherwise, the fake created in the test would never be
# used.
# See ../hello_timed


test_can_say_good_morning() {
  it_is_o_clock 10
  assert_equals "Good morning World!" "$(../hello_timed)"
}

test_can_say_good_evening() {
  it_is_o_clock 18
  assert_equals "Good evening World!" "$(../hello_timed)"
}

test_can_say_hello() {
  it_is_o_clock 12
  assert_equals "Hello World!" "$(../hello_timed)"
}

it_is_o_clock() {
  local hour="$1"
  fake current_hour << EOF
$hour
EOF
}