1+ #! /usr/bin/env bash
2+
3+ source assert.sh
4+ source assert-extras.sh
5+
6+ assert " echo foo" " foo"
7+ assert_raises " true" 0
8+ assert_raises " exit 127" 127
9+
10+ assert_end sanity
11+
12+ # ##
13+ # ## assert_success tests
14+ # ##
15+
16+ # Tests expecting success
17+ assert_success " true"
18+ assert_success " echo foo"
19+
20+ # Tests expecting failure
21+ assert_raises ' assert_success "false"' 1
22+ assert_raises ' assert_success "exit 1"' 1
23+
24+ assert_end assert_success
25+
26+ # ##
27+ # ## assert_failure tests
28+ # ##
29+
30+ # Tests expecting success
31+ assert_failure " false"
32+ assert_failure " exit 1"
33+ assert_failure " exit -1"
34+ assert_failure " exit 42"
35+ assert_failure " exit -42"
36+
37+ # Tests expecting failure
38+ assert_raises ' assert_failure "true"' 1
39+ assert_raises ' assert_failure "echo foo"' 1
40+
41+ assert_end assert_failure
42+
43+ # ##
44+ # ## assert_contains tests
45+ # ##
46+
47+ # Tests expecting success
48+ assert_contains " echo foo" " foo"
49+ assert_contains " echo foobar" " foo"
50+ assert_contains " echo foo bar" " foo"
51+ assert_contains " echo foo bar" " bar"
52+ assert_contains " echo foo bar" " foo bar"
53+
54+ # Tests expecting failure
55+ assert_failure ' assert_contains "echo foo" "foot"'
56+ assert_failure ' assert_contains "echo foo" "f.."'
57+
58+ # Multi-word argument tests
59+ assert_contains " echo foo bar" " foo bar"
60+ assert_failure ' assert_contains "echo foo; echo bar" "foo bar"'
61+
62+ # Multi-argument tests
63+ assert_contains " echo foo bar baz" " foo" " baz"
64+ assert_failure ' assert_contains "echo foo bar baz" "bar" "foo baz"'
65+
66+ assert_end assert_contains
67+
68+ # ##
69+ # ## assert_matches tests
70+ # ##
71+
72+ # Tests expecting success
73+ assert_matches " echo foo" " f.."
74+ assert_matches " echo foobar" " f."
75+ assert_matches " echo foo bar" " ^foo bar$"
76+ assert_matches " echo foo bar" " [az ]+"
77+
78+ # Tests expecting failure
79+ assert_failure ' assert_matches "echo foot" "foo$"'
80+
81+ # Multi-word argument tests
82+ assert_matches " echo foo bar" " foo .*"
83+ assert_failure ' assert_matches "echo foo; echo bar" "foo .*"'
84+
85+ # Multi-argument tests
86+ assert_matches " echo foo bar baz" " ^f.." " baz$"
87+ assert_failure ' assert_matches "echo foo bar baz" "bar" "foo baz"'
88+
89+ assert_end assert_matches
90+
91+ # ##
92+ # ## assert_startswith tests
93+ # ##
94+
95+ # Tests expecting success
96+ assert_startswith " echo foo" " f"
97+ assert_startswith " echo foo" " foo"
98+ assert_startswith " echo foo; echo bar" " foo"
99+
100+ # Tests expecting failure
101+ assert_failure ' assert_startswith "echo foo" "oo"'
102+ assert_failure ' assert_startswith "echo foo; echo bar" "foo bar"'
103+ assert_failure ' assert_startswith "echo foo" "."'
104+
105+ assert_end assert_startswith
106+
107+ # ##
108+ # ## assert_endswith tests
109+ # ##
110+
111+ # Tests expecting success
112+ assert_endswith " echo foo" " oo"
113+ assert_endswith " echo foo" " foo"
114+ assert_endswith " echo foo; echo bar" " bar"
115+
116+ # Tests expecting failure
117+ assert_failure ' assert_endswith "echo foo" "f"'
118+ assert_failure ' assert_endswith "echo foo; echo bar" "foo bar"'
119+ assert_failure ' assert_endswith "echo foo" "."'
120+
121+ assert_end assert_endswith
0 commit comments