From 191517b8c68f28a61fa745159b3108e3a2983bf4 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Mon, 27 May 2013 05:05:38 -0400 Subject: Start testing oh-installfiles. --- diff --git a/tests/oh-installfiles.sh b/tests/oh-installfiles.sh new file mode 100644 index 0000000..c701392 --- /dev/null +++ b/tests/oh-installfiles.sh @@ -0,0 +1,150 @@ +#!/bin/sh + +main() +{ + run_test dir + run_test dir_slash + run_test pattern_and_links +} + +t_dir() +{ + mkdir foo.pkg + cat >foo.pkg/files <<-EOF + /usr/bin + EOF + mkdir -p tmp/dest/usr/bin + cd tmp + >dest/usr/bin/foo + OPK_PACKAGES='foo' ../../src/oh-installfiles + assert test_non_dir_nodes dest + assert test_nodes foo.data / /usr/ /usr/bin/ /usr/bin/foo + cd .. + rm -Rf foo.pkg tmp +} + +t_dir_slash() +{ + mkdir foo.pkg + cat >foo.pkg/files <<-EOF + /usr/bin/ + EOF + mkdir -p tmp/dest/usr/bin + cd tmp + >dest/usr/bin/foo + OPK_PACKAGES='foo' ../../src/oh-installfiles + assert test_non_dir_nodes dest + assert test_nodes foo.data / /usr/ /usr/bin/ /usr/bin/foo + cd .. + rm -Rf foo.pkg tmp +} + +t_pattern_and_links() +{ + mkdir libfoo.1.pkg libfoo-dev.pkg + cat >libfoo.1.pkg/files <<-EOF + /usr/lib/*/libfoo.so.* + EOF + cat >libfoo-dev.pkg/files <<-EOF + /usr/lib/*/libfoo.so + EOF + mkdir -p tmp/dest/usr/lib/arch + cd tmp + >dest/usr/lib/arch/libfoo.so.1.0.0 + ln -sf libfoo.so.1.0.0 dest/usr/lib/arch/libfoo.so.1 + ln -sf libfoo.so.1 dest/usr/lib/arch/libfoo.so + OPK_PACKAGES='foo libfoo.1 libfoo-dev' ../../src/oh-installfiles + assert test_non_dir_nodes dest + assert test_nodes libfoo.1.data / /usr/ /usr/lib/ /usr/lib/arch/ \ + /usr/lib/arch/libfoo.so.1.0.0 /usr/lib/arch/libfoo.so.1@ + assert test_nodes libfoo-dev.data / /usr/ /usr/lib/ /usr/lib/arch/ \ + /usr/lib/arch/libfoo.so@ + cd .. + rm -Rf foo.pkg libfoo.1.pkg libfoo-dev.pkg tmp +} + +t_foo() +{ + mkdir foo.pkg libfoo.1.pkg libfoo-dev.pkg + cat >foo.pkg/files <<-EOF + /usr/bin + EOF + cat >libfoo.1.pkg/files <<-EOF + /usr/lib/*/libfoo.so.* + EOF + cat >libfoo-dev.pkg/files <<-EOF + /usr/lib/*/libfoo.so + /usr/include/ + EOF + mkdir -p tmp/dest/usr/bin tmp/dest/usr/lib/arch tmp/dest/usr/include + cd tmp + >dest/usr/bin/foo + >dest/usr/lib/arch/libfoo.so.1.0.0 + ln -sf libfoo.so.1.0.0 dest/usr/lib/arch/libfoo.so.1 + ln -sf libfoo.so.1 dest/usr/lib/arch/libfoo.so + >dest/usr/include/foo.h + OPK_PACKAGES='foo libfoo.1 libfoo-dev' ../../src/oh-installfiles + assert [ -f foo.data/usr/bin/foo ] + assert [ -f libfoo.1.data/usr/lib/arch/libfoo.so.1.0.0 ] + assert [ -L libfoo.1.data/usr/lib/arch/libfoo.so.1 ] + assert [ -L libfoo-dev.data/usr/lib/arch/libfoo.so ] + assert [ -f libfoo-dev.data/usr/include/foo.h ] + cd .. + rm -Rf foo.pkg libfoo.1.pkg libfoo-dev.pkg tmp +} + +run_test() +{ + fail='false' + "t_${1}" >out 2>&1 + if "${fail}"; then + printf 'FAIL: %s\n' "${1}" + cat out | sed 's/^/ /' + else + printf 'PASS: %s\n' "${1}" + fi + rm out +} + +assert() +{ + if ! out=$(eval 2>&1 "${@}"); then + printf 'Assertion failed: %s\n' "${*}" + printf '%s\n' "${out}" | sed 's/^/ /' + fail='true' + fi +} + +test_nodes() +{ + dir="${1}" + shift 1 + if [ ${#} -gt 0 ]; then + printf "${dir}%s\n" "${@}" | sort >expected + else + >expected + fi + find "${dir}" -exec ls -dF '{}' ';' | sort >actual + diff -u expected actual + ret=${?} + rm -f expected actual + return ${ret} +} + +test_non_dir_nodes() +{ + dir="${1}" + shift 1 + if [ ${#} -gt 0 ]; then + printf "${dir}%s\n" "${@}" | sort >expected + else + >expected + fi + find "${dir}" ! -type d | sort >actual + diff -u expected actual + ret=${?} + rm -f expected actual + return ${ret} +} + +main "${@}" -- cgit v0.9.1