~sircmpwn/ctools

ref: 0e9f63c42367ef836a3dbe9369cb987558b0d9e3 ctools/test/cmp -rwxr-xr-x 1015 bytes
0e9f63c4 — Christopher Vittal Add dirname 1 year, 7 months ago
                                                                                
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
#!/bin/sh
. "$HARNESS" cmp

should_handle_samefile() (
	[ "$(cmp "$HARNESS" "$HARNESS")" = "" ]
)

should_handle_stdin() (
	[ "$(cmp "$HARNESS" <"$HARNESS")" = "" ]
)

should_handle_difference() (
	[ "$(echo test | cmp "$HARNESS" - || true)" \
		= "$HARNESS - differ: char 1, line 1" ]
)

should_handle_mutex() (
	! cmp -ls "$HARNESS" /dev/null >/dev/null 2>&1
)

should_handle_lflag() (
	[ "$(echo test | cmp -l "$HARNESS" - || true)" \
		= "1 163 164" ]
)

should_handle_sflag() (
	[ "$(echo test | cmp -s "$HARNESS" -)" = "" ]
)

should_handle_exitcode() (
	set +e
	trap 'set -e' EXIT
	cmp "$HARNESS" /dev/null >/dev/null 2>&1
	if ! [ $? -eq 1 ]
	then
		return 1
	fi
	cmp /dev/does/not/exist /dev/null >/dev/null 2>&1
	if ! [ $? -gt 1 ]
	then
		return 1
	fi
)

should_handle_ddash cmp "$HARNESS" "$HARNESS"

runtests \
	should_handle_ddash \
	should_handle_samefile \
	should_handle_difference \
	should_handle_stdin \
	should_handle_mutex \
	should_handle_lflag \
	should_handle_sflag \
	should_handle_exitcode