diff options
-rw-r--r-- | tests/README | 33 | ||||
-rw-r--r-- | tests/include/testassertions.sh | 13 | ||||
-rw-r--r-- | tests/include/testcontrol.sh | 5 | ||||
-rwxr-xr-x | tests/testrun | 7 | ||||
-rw-r--r-- | tests/xdg-mime/data/testmime.xml | 7 | ||||
-rw-r--r-- | tests/xdg-mime/data/textplain.expected | 1 | ||||
-rw-r--r-- | tests/xdg-mime/data/textxdgpattern.expected | 1 | ||||
-rwxr-xr-x | tests/xdg-mime/t.double_mime_install | 46 | ||||
-rwxr-xr-x | tests/xdg-mime/t.notexist_mime_uninstall | 42 | ||||
-rwxr-xr-x | tests/xdg-mime/t.query_text_plain | 33 | ||||
-rwxr-xr-x | tests/xdg-mime/t.system_as_nonroot | 48 | ||||
-rwxr-xr-x | tests/xdg-mime/t.system_mime_install | 48 | ||||
-rwxr-xr-x | tests/xdg-mime/t.system_mime_uninstall | 46 | ||||
-rwxr-xr-x | tests/xdg-mime/t.user_mime_install | 28 | ||||
-rwxr-xr-x | tests/xdg-mime/t.user_mime_uninstall | 44 |
15 files changed, 376 insertions, 26 deletions
diff --git a/tests/README b/tests/README index e0b674f..e8d859b 100644 --- a/tests/README +++ b/tests/README @@ -4,25 +4,36 @@ Created 6/27/2006 by Tom Whipple <tom.whipple@intel.com> RUNNING XDG-UTILS TESTS ----------------------- -To run a test suite, assuming your current directory is the same as this README, ensure you have defined TEST_CODE_DIR. +At a minimum, you must have your current directory be the same as the directory containing this README. Then, simply execute + +$ ./testrun +WARNING: guessed TEST_CODE_DIR to be /home/tw/portland/xdg-utils/tests +TEST_LIST: generic_bogus_arg-1-1 ... generic_version-1-50 +... +FAIL: test_user_mime_install +NORESULT: test_system_mime_install +44 of 50 tests passed. +See xdg-test.log for details. +NOT OK! + +FAIL indicates (not suprisingly) a test failure. +NORESULT indicates that the test prerequisites failed for some reason. -$ export TEST_CODE_DIR=<parent to portland checkout>/portland/xdg-utils/tests +NOTE: The test runner makes guesses about appropriate values of TEST_CODE_DIR and PATH. These values can be overriden explicitly. -Then, run the test runner with the suite(s) as an argument. Or, use no args to run all the tests. +To run tests individually, or as smaller groups do something like $ ./testrun xdg-mime -NORESULT: xdg-mime/t.user_mime_install -2 of 3 tests passed. -See xdg-test.log for details. -In this example we see that the user_mime_install had an error, so run it separately: +OR + +$ ./testrun xdg-mime/t.user_mime_install + +OR (if you have defined TEST_CODE_DIR and PATH correctly) $ xdg-mime/t.user_mime_install -[Tue Jun 27 14:53:23 PDT 2006] xdg-mime/t.user_mime_install: user mime install: NORESULT -<...> -Initilization failed! -In this case, a test depencency failed, so NORESULT is given instead of FAIL. + DIRECTORY STRUCTURE ------------------- diff --git a/tests/include/testassertions.sh b/tests/include/testassertions.sh index cc5df2f..63c663c 100644 --- a/tests/include/testassertions.sh +++ b/tests/include/testassertions.sh @@ -17,9 +17,9 @@ assert_exit() # execute command (saving output) and check exit code EXPECT=0; fi if [ "$EXPECT" = N -a "$CODE" -eq 0 ]; then - test_fail "Command ($1) gave exit code $CODE, expected nonzero" - elif [ "$EXPECT" -ne "$CODE" ]; then - test_fail "Command ($1) gave exit code $CODE, expected $EXPECT" + test_fail "Command ($*) gave exit code $CODE, expected nonzero" + elif [ "$EXPECT" != N ] && [ "$EXPECT" -ne "$CODE" ]; then + test_fail "Command ($*) gave exit code $CODE, expected $EXPECT" fi } @@ -119,6 +119,13 @@ assert_stdout() # check that stderr matches expected error ;; *) expfile="$1" + + if [ ! -e "$expfile" ] ; then + test_status NORESULT "Could not find file '$expfile' to look up expected pattern!" + return + fi + #expline="$*" + #expfile="out.stdout" OK=Y exec 4<&0 0< "$expfile" 3< out.stdout while read expline diff --git a/tests/include/testcontrol.sh b/tests/include/testcontrol.sh index 48933b1..5814c87 100644 --- a/tests/include/testcontrol.sh +++ b/tests/include/testcontrol.sh @@ -65,7 +65,8 @@ declare -i J=1 while [ "$J" -le "$LENGTH" ] ; do declare -i I=1 ## Begin test function string - str="t$IC_NUM() {" # it is only safe to use $IC_NUM since run_test is used later in this function. + #str="t$IC_NUM() {" # it is only safe to use $IC_NUM since run_test is used later in this function. + str="$FUNC-$J-$IC_NUM() {" # it is only safe to use $IC_NUM since run_test is used later in this function. while [ "$I" -le "$VARS" ] ; do ## Assign each value to appropriate variable eval "var=\$v$I" @@ -82,7 +83,7 @@ while [ "$J" -le "$LENGTH" ] ; do }" #echo "$str" eval "$str" - run_test "t$IC_NUM" + run_test "$FUNC-$J-$IC_NUM" J=$(($J+1)) done diff --git a/tests/testrun b/tests/testrun index 2007f3f..7f92a0e 100755 --- a/tests/testrun +++ b/tests/testrun @@ -10,8 +10,11 @@ ## dir1/sub/path/t.bar: UNTESTED: some other reason if [ -z "$TEST_CODE_DIR" ] ; then - echo "TEST_CODE_DIR must be defined!!" - exit 1 + export TEST_CODE_DIR=`pwd` + echo "WARNING: guessed TEST_CODE_DIR to be $TEST_CODE_DIR" +fi +if [ -d "$TEST_CODE_DIR/../scripts" ] ; then + export PATH="$PATH:$TEST_CODE_DIR/../scripts" fi if [ $# -eq 0 ] ; then diff --git a/tests/xdg-mime/data/testmime.xml b/tests/xdg-mime/data/testmime.xml new file mode 100644 index 0000000..938770b --- /dev/null +++ b/tests/xdg-mime/data/testmime.xml @@ -0,0 +1,7 @@ +<?xml version="1.0"?> + <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> + <mime-type type="text/x-xdg-testpattern"> + <comment>xdg-utils install mime test</comment> + <glob pattern="*.xdgtest"/> + </mime-type> + </mime-info> diff --git a/tests/xdg-mime/data/textplain.expected b/tests/xdg-mime/data/textplain.expected new file mode 100644 index 0000000..e70108f --- /dev/null +++ b/tests/xdg-mime/data/textplain.expected @@ -0,0 +1 @@ +text/plain diff --git a/tests/xdg-mime/data/textxdgpattern.expected b/tests/xdg-mime/data/textxdgpattern.expected new file mode 100644 index 0000000..fc53e80 --- /dev/null +++ b/tests/xdg-mime/data/textxdgpattern.expected @@ -0,0 +1 @@ +text/x-xdg-testpattern diff --git a/tests/xdg-mime/t.double_mime_install b/tests/xdg-mime/t.double_mime_install new file mode 100755 index 0000000..99fab72 --- /dev/null +++ b/tests/xdg-mime/t.double_mime_install @@ -0,0 +1,46 @@ +#!/bin/bash + +## Include utility functions. +. "$TEST_CODE_DIR/include/testassertions.sh" +. "$TEST_CODE_DIR/include/testdep.sh" +. "$TEST_CODE_DIR/include/testcontrol.sh" + +## Test function +test_double_mime_install() { +INPUT_FILE="$TEST_CODE_DIR/xdg-mime/data/testmime.xml" +# TODO: should follow the filename tests. +QUERY_FILE="testfile.xdgtest" + +## Begin the test. +test_start "$FUNCNAME: verify installing an existing mime type is OK" + +# Dependencies section +test_init + +set_no_display +assert_file $INPUT_FILE +echo "Some text." > $QUERY_FILE +assert_file "$QUERY_FILE" + +# Verify the test type is not installed already. +assert_exit 0 xdg-mime install --user "$INPUT_FILE" +assert_exit 0 "xdg-mime query filetype $QUERY_FILE" +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textxdgpattern.expected" + +# Test steps section +test_procedure + +assert_exit 0 xdg-mime install --user "$INPUT_FILE" +assert_nostdout +assert_nostderr + +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textxdgpattern.expected" +assert_nostderr + +# TODO: this is a cleanup step +assert_exit 0 xdg-mime uninstall --user "$INPUT_FILE" + +test_result +} +run_test test_double_mime_install diff --git a/tests/xdg-mime/t.notexist_mime_uninstall b/tests/xdg-mime/t.notexist_mime_uninstall new file mode 100755 index 0000000..344dba4 --- /dev/null +++ b/tests/xdg-mime/t.notexist_mime_uninstall @@ -0,0 +1,42 @@ +#!/bin/bash + +## Include utility functions. +. "$TEST_CODE_DIR/include/testassertions.sh" +. "$TEST_CODE_DIR/include/testdep.sh" +. "$TEST_CODE_DIR/include/testcontrol.sh" + +## Test function +test_notexist_mime_uninstall() { +INPUT_FILE="$TEST_CODE_DIR/xdg-mime/data/testmime.xml" +# TODO: should follow the filename tests. +QUERY_FILE="testfile.xdgtest" + +## Begin the test. +test_start "$FUNCNAME: uninstall mime type that is not present" + +# Dependencies section +test_init + +set_no_display +assert_file $INPUT_FILE +echo "Some text." > $QUERY_FILE +assert_file "$QUERY_FILE" + +# Install & verify mime type is installed +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textplain.expected" + +# Test steps section +test_procedure + +assert_exit 0 xdg-mime uninstall --user "$INPUT_FILE" +assert_nostdout +assert_nostderr + +## Verify uninstall +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textplain.expected" + +test_result +} +run_test test_notexist_mime_uninstall diff --git a/tests/xdg-mime/t.query_text_plain b/tests/xdg-mime/t.query_text_plain new file mode 100755 index 0000000..0d599da --- /dev/null +++ b/tests/xdg-mime/t.query_text_plain @@ -0,0 +1,33 @@ +#!/bin/bash + +. "$TEST_CODE_DIR/include/testassertions.sh" +. "$TEST_CODE_DIR/include/testdep.sh" +. "$TEST_CODE_DIR/include/testcontrol.sh" + +test_query_text_plain() { +# TODO: expand to cover file weirdness. +INPUT_FILE='testfile.txt' + +test_start "$FUNCNAME: verify a query against $INPUT_FILE returns 'text/plain'" +test_purpose "Verify that the basic query (text/plain) is working." + +## Check dependencies +test_init + +set_no_display + +echo 'This is some text.' > $INPUT_FILE +assert_file "$INPUT_FILE" + +## Main test +test_procedure + +assert_exit 0 xdg-mime query filetype "$INPUT_FILE" +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textplain.expected" +assert_nostderr + + +test_result +} + +run_test test_query_text_plain diff --git a/tests/xdg-mime/t.system_as_nonroot b/tests/xdg-mime/t.system_as_nonroot new file mode 100755 index 0000000..861e34d --- /dev/null +++ b/tests/xdg-mime/t.system_as_nonroot @@ -0,0 +1,48 @@ +#!/bin/bash + +## Include utility functions. +. "$TEST_CODE_DIR/include/testassertions.sh" +. "$TEST_CODE_DIR/include/testdep.sh" +. "$TEST_CODE_DIR/include/testcontrol.sh" + +## Test function +test_system_as_nonroot() { +INPUT_FILE="$TEST_CODE_DIR/xdg-mime/data/testmime.xml" +# TODO: should follow the filename tests. +QUERY_FILE="testfile.xdgtest" + +## Begin the test. +test_start "$FUNCNAME: verify error for --system when run as a normal user" + +# Dependencies section +test_init + +assert_exit 0 test `whoami` != root + +set_no_display +assert_file $INPUT_FILE +echo "Some text." > $QUERY_FILE +assert_file "$QUERY_FILE" + +# Verify the test type is not installed already. +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textplain.expected" + +# Test steps section +test_procedure + +assert_exit 3 xdg-mime install --system "$INPUT_FILE" +assert_nostdout +assert_stderr + +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textplain.expected" +assert_nostderr + +assert_exit 3 xdg-mime uninstall --system "$INPUT_FILE" +assert_nostdout +assert_stderr + +test_result +} +run_test test_system_as_nonroot diff --git a/tests/xdg-mime/t.system_mime_install b/tests/xdg-mime/t.system_mime_install new file mode 100755 index 0000000..025b7bd --- /dev/null +++ b/tests/xdg-mime/t.system_mime_install @@ -0,0 +1,48 @@ +#!/bin/bash + +## Include utility functions. +. "$TEST_CODE_DIR/include/testassertions.sh" +. "$TEST_CODE_DIR/include/testdep.sh" +. "$TEST_CODE_DIR/include/testcontrol.sh" + +## Test function +test_system_mime_install() { +INPUT_FILE="$TEST_CODE_DIR/xdg-mime/data/testmime.xml" +# TODO: should follow the filename tests. +QUERY_FILE="testfile.xdgtest" + +## Begin the test. +test_start "$FUNCNAME: install system mime type" +test_purpose "Verify that new mime types get installed into the system space correctly" + +# Dependencies section +test_init + +assert_exit 0 test `whoami` = root + +set_no_display +assert_file $INPUT_FILE +echo "Some text." > $QUERY_FILE +assert_file "$QUERY_FILE" + +# Verify the test type is not installed already. +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textplain.expected" + +# Test steps section +test_procedure + +assert_exit 0 xdg-mime install --system "$INPUT_FILE" +assert_nostdout +assert_nostderr + +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textxdgpattern.expected" +assert_nostderr + +# TODO: this is a cleanup step +assert_exit 0 xdg-mime uninstall --system "$INPUT_FILE" + +test_result +} +run_test test_system_mime_install diff --git a/tests/xdg-mime/t.system_mime_uninstall b/tests/xdg-mime/t.system_mime_uninstall new file mode 100755 index 0000000..80d478b --- /dev/null +++ b/tests/xdg-mime/t.system_mime_uninstall @@ -0,0 +1,46 @@ +#!/bin/bash + +## Include utility functions. +. "$TEST_CODE_DIR/include/testassertions.sh" +. "$TEST_CODE_DIR/include/testdep.sh" +. "$TEST_CODE_DIR/include/testcontrol.sh" + +## Test function +test_system_mime_uninstall() { +INPUT_FILE="$TEST_CODE_DIR/xdg-mime/data/testmime.xml" +# TODO: should follow the filename tests. +QUERY_FILE="testfile.xdgtest" + +## Begin the test. +test_start "$FUNCNAME: uninstall system mime type" +test_purpose "Verify that new mime types get removed from the system space correctly" + +# Dependencies section +test_init + +assert_exit 0 test `whoami` = root + +set_no_display +assert_file $INPUT_FILE +echo "Some text." > $QUERY_FILE +assert_file "$QUERY_FILE" + +# Install & verify mime type is installed +assert_exit 0 xdg-mime install --system "$INPUT_FILE" +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textxdgpattern.expected" + +# Test steps section +test_procedure + +assert_exit 0 xdg-mime uninstall --system "$INPUT_FILE" +assert_nostdout +assert_nostderr + +## Verify uninstall +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textplain.expected" + +test_result +} +run_test test_system_mime_uninstall diff --git a/tests/xdg-mime/t.user_mime_install b/tests/xdg-mime/t.user_mime_install index def80d8..719e8bd 100755 --- a/tests/xdg-mime/t.user_mime_install +++ b/tests/xdg-mime/t.user_mime_install @@ -7,7 +7,9 @@ ## Test function test_user_mime_install() { -INPUT_FILE="$TEST_CODE_DIR/xdg-mime/user-mime-install.xml" +INPUT_FILE="$TEST_CODE_DIR/xdg-mime/data/testmime.xml" +# TODO: should follow the filename tests. +QUERY_FILE="testfile.xdgtest" ## Begin the test. test_start "$FUNCNAME: install user mime type" @@ -17,18 +19,28 @@ test_purpose "Verify that new mime types get installed into the user space corre test_init set_no_display +assert_file $INPUT_FILE +echo "Some text." > $QUERY_FILE +assert_file "$QUERY_FILE" -test_infoline "TODO: $INPUT_FILE has not been created yet." - -#assert_file $INPUT_FILE +# Verify the test type is not installed already. +assert_exit 0 "xdg-mime query filetype $QUERY_FILE" +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textplain.expected" # Test steps section test_procedure -#assert_exit 0 xdg-mime install --user "$INPUT_FILE" -#assert_nostdout -#assert_nostderr +assert_exit 0 xdg-mime install --user "$INPUT_FILE" +assert_nostdout +assert_nostderr + +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textxdgpattern.expected" +assert_nostderr + +# TODO: this is a cleanup step +assert_exit 0 xdg-mime uninstall --user "$INPUT_FILE" -test_result PASS +test_result } run_test test_user_mime_install diff --git a/tests/xdg-mime/t.user_mime_uninstall b/tests/xdg-mime/t.user_mime_uninstall new file mode 100755 index 0000000..a65e2e3 --- /dev/null +++ b/tests/xdg-mime/t.user_mime_uninstall @@ -0,0 +1,44 @@ +#!/bin/bash + +## Include utility functions. +. "$TEST_CODE_DIR/include/testassertions.sh" +. "$TEST_CODE_DIR/include/testdep.sh" +. "$TEST_CODE_DIR/include/testcontrol.sh" + +## Test function +test_user_mime_uninstall() { +INPUT_FILE="$TEST_CODE_DIR/xdg-mime/data/testmime.xml" +# TODO: should follow the filename tests. +QUERY_FILE="testfile.xdgtest" + +## Begin the test. +test_start "$FUNCNAME: uninstall user mime type" +test_purpose "Verify that mime types get removed from the user space correctly." + +# Dependencies section +test_init + +set_no_display +assert_file $INPUT_FILE +echo "Some text." > $QUERY_FILE +assert_file "$QUERY_FILE" + +# Install & verify mime type is installed +assert_exit 0 xdg-mime install --user "$INPUT_FILE" +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textxdgpattern.expected" + +# Test steps section +test_procedure + +assert_exit 0 xdg-mime uninstall --user "$INPUT_FILE" +assert_nostdout +assert_nostderr + +## Verify uninstall +assert_exit 0 xdg-mime query filetype $QUERY_FILE +assert_stdout "$TEST_CODE_DIR/xdg-mime/data/textplain.expected" + +test_result +} +run_test test_user_mime_uninstall |