-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
58 lines (44 loc) · 1.17 KB
/
test.sh
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
#!/bin/sh
#!/bin/bash
typeset -i tests=0
function describe {
let tests+=1
description="$1"
}
function assert {
if [[ "$1" == "$2" ]]; then
printf "\033[32m.\033[0m"
else
printf "\033[31m\nFAIL: $description\033[0m: '$1' != '$2'\n"
exit 1
fi
}
describe "Help"
./binary --help > /dev/null 2>&1
assert $? 0
describe "Help: short flag"
./binary -h > /dev/null 2>&1
assert $? 0
describe "Version"
./binary --version > /dev/null 2>&1
assert $? 0
describe "Version: short flag"
./binary -v > /dev/null 2>&1
assert $? 0
describe "Execute: one argument"
./binary foo > /dev/null 2>&1
assert $? 1
describe "Execute: more than two arguments"
./binary foo bar baz > /dev/null 2>&1
assert $? 1
describe "Execute: should work"
assert `./binary "--to-binary" "7"` 111
assert `./binary "--to-binary" "19"` 10011
assert `./binary "--to-binary" "3"` 11
assert `./binary "--to-decimal" "111"` 7
assert `./binary "--to-decimal" "10011"` 19
assert `./binary "--to-decimal" "11"` 3
assert `./binary "-is" "111"` binary
assert `./binary "-is" "7777777"` non-binary
printf "\033[32m\n(✓) Passed $tests assertions without errors\033[0m\n"
exit 0