summaryrefslogtreecommitdiff
path: root/tests/cli-opts.sh
blob: 39f01f411a849285b013cd569ccde50cefb81178 (plain) (blame)
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
#!/bin/sh
set -eu

. tests/lib.sh


test_generates_uuid_with_0_args() {
	testing 'generates UUID with 0 arguments'

	N="$LINENO"
	OUT="$(mkstemp)"
	ERR="$(mkstemp)"
	trap 'rm -f "$OUT" "$ERR"' EXIT
	STATUS=0
	./uuid.bin 1>"$OUT" 2>"$ERR" || STATUS=$?
	assert_status 0
	assert_empty_stderr
	rm "$OUT" "$ERR"

	test_ok
}

test_checks_string_with_1_arg() {
	testing 'checks string with 1 arg'

	N="$LINENO"
	OUT="$(mkstemp)"
	ERR="$(mkstemp)"
	trap 'rm -f "$OUT" "$ERR"' EXIT
	STATUS=0
	./uuid.bin 'cac94e13-41fa-40c4-bd46-5b7b3b46c09e' 1>"$OUT" 2>"$ERR" || STATUS=$?
	assert_status 0
	assert_empty_stdout
	assert_empty_stderr
	rm "$OUT" "$ERR"

	N="$LINENO"
	OUT="$(mkstemp)"
	ERR="$(mkstemp)"
	trap 'rm -f "$OUT" "$ERR"' EXIT
	STATUS=0
	./uuid.bin 'bad-uuid-string' 1>"$OUT" 2>"$ERR" || STATUS=$?
	assert_status 3
	assert_empty_stdout
	assert_stderr "uuid: str isn't of the correct length"
	rm "$OUT" "$ERR"

	test_ok
}



test_generates_uuid_with_0_args
test_checks_string_with_1_arg