test_common_utils.sh 2.42 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Test common_utils

[ "$(abspath foo)" == "$PWD/foo" ] || ingest "abspath foo"
[ "$(abspath foo/bar)" == "$PWD/foo/bar" ] || ingest "abspath foo/bar"
[ "$(abspath /foo)" == "/foo" ] || ingest "abspath /foo"
[ "$(relpath $PWD/foo)" == "foo" ] || ingest "relpath foo"
[ "$(relpath foo/bar foo)" == "bar" ] || ingest "relpath foo/bar"
[ "$(realpath /foo)" == "/foo" ] || ingest "realpath /foo"

[ "$(lex_ver 2)" == "002000000" ] || ingest "lex_ver 2"
[ "$(lex_ver 2.1)" == "002001000" ] || ingest "lex_ver 2.1"
[ "$(lex_ver 2.1.4)" == "002001004" ] || ingest "lex_ver 2.1.4"
[ "$(lex_ver 2.1.4rc1)" == "002001004" ] || ingest "lex_ver 2.1.4"

15
16
17
18
19
20
21
22
23
24
[ "$(unlex_ver 002000000)" == "2.0.0" ] || ingest "unlex_ver 002000000"
[ "$(unlex_ver 003002012)" == "3.2.12" ] || ingest "unlex_ver 003002012"
# Not octal
[ "$(unlex_ver 003044099)" == "3.44.99" ] || ingest "unlex_ver 003044099"
[ "$(unlex_ver 003543012)" == "3.543.12" ] || ingest "unlex_ver 003543012"
[ "$(unlex_ver 003543012abc)" == "3.543.12" ] || ingest "unlex_ver 003543012abc"

[ "$(strip_ver_suffix 3.4.0rc1)" == "3.4.0" ] || ingest "unlex_ver strip suff 1"
[ "$(strip_ver_suffix 3.24.12a4)" == "3.24.12" ] || ingest "unlex_ver strip suff 2"

25
26
27
28
29
30
31
32
33
34
35
[ "$(is_function abspath)" == "true" ] || ingest "is_function abspath"
[ "$(is_function foo)" == "" ] || ingest "is_function foo"
bar=baz
[ "$(is_function bar)" == "" ] || ingest "is_function bar"

rm_mkdir tmp_dir
[ -d tmp_dir ] || ingest "tmp_dir does not exist"
touch tmp_dir/afile
rm_mkdir tmp_dir
[ -e tmp_dir/afile ] && ingest "tmp_dir/afile should have been deleted"
rmdir tmp_dir
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
61
62
63
# Test suppress command
function bad_cmd {
    echo bad
    return 1
}

function bad_mid_cmd {
    echo ok for now
    false
    echo should be bad now
    return 0
}

function good_cmd {
    echo good
    return 0
}

# Check state of set -e, disable if set
# https://stackoverflow.com/questions/14564746/in-bash-how-to-get-the-current-status-of-set-x?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
using_e=${-//[^e]/}
set +e
[ "$(suppress bad_cmd)" == "$(printf "Running bad_cmd\nbad")" ] || ingest "suppress bad_cmd"
[ "$(suppress good_cmd)" == "Running good_cmd" ] || ingest "suppress good_cmd"
[ "$(suppress bad_mid_cmd)" == "Running bad_mid_cmd" ] || ingest "suppress bad_mid_cmd"
if [ -n "$using_e" ]; then set -e; fi

64
65
# On Linux docker containers in travis, can only be x86_64 or i686
[ "$(get_platform)" == x86_64 ] || [ "$(get_platform)" == i686 ] || exit 1