|
1 | | -#! /bin/sh |
| 1 | +#! /usr/bin/env bash |
2 | 2 |
|
3 | 3 | # ----------------------------------------------- |
4 | 4 | # ---- Source third-party libraries ----------- |
5 | 5 | # ----------------------------------------------- |
6 | 6 |
|
7 | 7 | # shellcheck source=/dev/null |
8 | | -. dev-container-features-test-lib |
| 8 | +source dev-container-features-test-lib |
9 | 9 |
|
10 | 10 | # shellcheck disable=SC2034 |
11 | | -readonly DATA_BASE_DIR='/opt/devcontainer/features/ghcr_io/georglauterbach' |
| 11 | +readonly DATA_BASE_DIR='/usr/local/share/dev_containers/features/ghcr_io/georglauterbach' |
12 | 12 |
|
13 | 13 | # ----------------------------------------------- |
14 | 14 | # ---- Assertions ----------------------------- |
15 | 15 | # ----------------------------------------------- |
16 | 16 |
|
17 | | -__expect_failure() { |
18 | | - sh -c "${*}" && return 1 |
| 17 | +function __expect_failure() { |
| 18 | + bash -c "${*}" && return 1 |
19 | 19 | return 0 |
20 | 20 | } |
21 | 21 |
|
22 | | -assert_failure() { |
23 | | - __TEST_NAME="${1:?Name of the test required}" |
| 22 | +function assert_failure() { |
| 23 | + local TEST_NAME="${1:?Name of the test required}" |
24 | 24 | shift 1 |
25 | 25 |
|
26 | | - check "expect::failure|${__TEST_NAME}" __expect_failure "${@}" |
| 26 | + check "expect::failure|${TEST_NAME}" __expect_failure "${@}" |
27 | 27 | } |
28 | 28 |
|
29 | | -assert_success() { |
30 | | - __TEST_NAME="${1:?Name of the test required}" |
| 29 | +function assert_success() { |
| 30 | + local TEST_NAME="${1:?Name of the test required}" |
31 | 31 | shift 1 |
32 | 32 |
|
33 | | - check "expect::success|${__TEST_NAME}" sh -c "${*}" |
| 33 | + check "expect::success|${TEST_NAME}" bash -c "${*}" |
34 | 34 | } |
35 | 35 |
|
36 | 36 | # ----------------------------------------------- |
37 | 37 | # ---- Helper --------------------------------- |
38 | 38 | # ----------------------------------------------- |
39 | 39 |
|
40 | | -command_exists() { |
| 40 | +function command_exists() { |
41 | 41 | assert_success "command::${1}" command -v "${1}" |
42 | 42 | } |
43 | 43 |
|
44 | | -command_exists_not() { |
| 44 | +function command_exists_not() { |
45 | 45 | assert_failure "command::${1}" command -v "${1}" |
46 | 46 | } |
47 | 47 |
|
48 | | -dir_exists() { |
49 | | - assert_success "directory::${1}" "[ -d \"${1}\" ]" |
| 48 | +function dir_exists() { |
| 49 | + assert_success "directory::${1}" "[[ -d ${1} ]]" |
50 | 50 | } |
51 | 51 |
|
52 | | -dir_exists_not() { |
53 | | - assert_failure "directory::${1}" "[ -d \"${1}\" ]" |
| 52 | +function dir_exists_not() { |
| 53 | + assert_failure "directory::${1}" "[[ -d ${1} ]]" |
54 | 54 | } |
55 | 55 |
|
56 | | -file_exists() { |
57 | | - assert_success "file::${1}" "[ -f \"${1}\" ]" |
| 56 | +function file_exists() { |
| 57 | + assert_success "file::${1}" "[[ -f ${1} ]]" |
58 | 58 | } |
59 | 59 |
|
60 | | -file_exists_not() { |
61 | | - assert_failure "file::${1}" "[ -f \"${1}\" ]" |
| 60 | +function file_exists_not() { |
| 61 | + assert_failure "file::${1}" "[[ -f ${1} ]]" |
62 | 62 | } |
63 | 63 |
|
64 | | -env_is_set_with_value() { |
65 | | - assert_success "env::set::${1}" "[ -v \"${1}\" ]" |
66 | | - assert_success "env::set::${1}" "[ \"${1}\" = \"${2}\" ]" |
| 64 | +function env_is_set_with_value() { |
| 65 | + assert_success "env::set::${1}" "[[ -v ${1} ]]" |
| 66 | + assert_success "env::set::${1}" "[[ ${1} == ${2} ]]" |
67 | 67 | } |
0 commit comments