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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#!/usr/bin/env bash
include './tests/unit/utils.sh'
function oneTimeSetUp()
{
# specifies where to source the lib
KW_LIB_DIR="$PWD/src"
# this test file can be empty, as we're only testing the created varname
test_files=(
"$SHUNIT_TMPDIR/.hidden spaced-dashed include.sh"
"$SHUNIT_TMPDIR/include_hash"
)
touch "${test_files[@]}"
# the next files will be checked for name collisions
printf "%s\n" "function test1(){ printf '%s\n' 'output of test1';}" > "\
$SHUNIT_TMPDIR/include_test_similar_path.sh"
mkdir "$SHUNIT_TMPDIR/include_test"
printf "%s\n" "function test2(){ printf '%s\n' 'output of test2';}" > "\
$SHUNIT_TMPDIR/include_test/similar_path.sh"
}
function oneTimeTearDown()
{
rm -rf "$SHUNIT_TMPDIR"
mkdir -p "$SHUNIT_TMPDIR"
}
function test_include()
{
local fullpath
local output
local relpath
relpath='./src/lib/kwio.sh'
include "$relpath"
fullpath="$(realpath "$relpath")"
output="${KW_INCLUDED_PATHS["$fullpath"]}"
assertEquals "($LINENO)" 1 "$output"
}
function test_include_twice()
{
include ./src/lib/kwlib.sh
include ./src/lib/kwlib.sh
assertEquals "($LINENO)" 0 "$?"
}
function test_include_wrong_path()
{
output=$(include ./src/batata.sh)
assertEquals "($LINENO)" 2 "$?"
}
function test_include_unusual_path()
{
include "$SHUNIT_TMPDIR/.hidden spaced-dashed include.sh"
assertEquals "($LINENO)" 0 "$?"
}
function test_include_similar_paths()
{
local test1_output
local test2_output
local test1_expected
local test2_expected
include "$SHUNIT_TMPDIR/include_test_similar_path.sh"
include "$SHUNIT_TMPDIR/include_test/similar_path.sh"
test1_output=$(test1)
test2_output=$(test2)
test1_expected='output of test1'
test2_expected='output of test2'
assertEquals "($LINENO)" "$test1_expected" "$test1_output"
assertEquals "($LINENO)" "$test2_expected" "$test2_output"
}
invoke_shunit
|