summaryrefslogtreecommitdiff
path: root/test/cases/lib-messages.bats
blob: c992a33934c83493647a19df0797605d03c3ef94 (plain)
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
load ../lib/common

@test "libremessages can be included twice" (
	. libremessages
	. libremessages
)

@test "libremessages can be included with set euE" (
	set -euE
	. libremessages
)

@test "libremessages works with no color and set euE" {
	(
		unset TERM
		set -euE
		. libremessages
		msg Foo
	) >$tmpdir/stdout 2>$tmpdir/stderr

	empty $tmpdir/stdout
	not empty $tmpdir/stderr
}

@test "libremessages can be called without including" {
	libremessages msg Foo >$tmpdir/stdout 2>$tmpdir/stderr

	empty $tmpdir/stdout
	not empty $tmpdir/stderr
}

@test "libremessages fails with msg and no args" {
	libremessages msg || status=$?
	[[ $status != 0 ]]
}

@test "libremessages allows subheadings to flag" {
	# Note that old versions of `flag` panicked if given an odd
	# number of headings, so give an odd number here.
	libremessages flag \
		      -a adesc \
		      -b bdesc \
		      Head1: \
		      -c cdesc > $tmpdir/out
	cat > $tmpdir/exp <<-eot
		  -a            adesc
		  -b            bdesc
		 Head1:
		  -c            cdesc
		eot
	diff -u $tmpdir/exp $tmpdir/out
}

@test "libremessages is quiet on stdout on errs" {
	LC_ALL=C bash -euE -c '. libremessages; setup_traps; false' >"$tmpdir/stdout" 2>"$tmpdir/stderr" || status=$?

	[[ $status != 0 ]]
	empty "$tmpdir/stdout"
	grep '==> ERROR:' "$tmpdir/stderr"
}