From a5b9f77e2a1e7b7dc1f7b6cb0cf195b77c41c5cf Mon Sep 17 00:00:00 2001 From: Alice Kaerast Date: Nov 12 2012 12:56:19 +0000 Subject: add initial tests for coreutils --- diff --git a/tests/p_coreutils/0-install_coreutils.sh b/tests/p_coreutils/0-install_coreutils.sh new file mode 100755 index 0000000..283b022 --- /dev/null +++ b/tests/p_coreutils/0-install_coreutils.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 - installing coreutils" +t_InstallPackage coreutils diff --git a/tests/p_coreutils/arch.sh b/tests/p_coreutils/arch.sh new file mode 100755 index 0000000..5850ef8 --- /dev/null +++ b/tests/p_coreutils/arch.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 Check arch agrees with current running kernel" +uname -a | grep -q `arch` +t_CheckExitStatus $? diff --git a/tests/p_coreutils/basename.sh b/tests/p_coreutils/basename.sh new file mode 100755 index 0000000..ef817d3 --- /dev/null +++ b/tests/p_coreutils/basename.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 testing basename" + +basename $0 | grep -q basename.sh || exit 1 +basename /etc/hosts | grep -q hosts +t_CheckExitStatus $? + diff --git a/tests/p_coreutils/cat.sh b/tests/p_coreutils/cat.sh new file mode 100755 index 0000000..6c33c66 --- /dev/null +++ b/tests/p_coreutils/cat.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 test cat command" + +cat > /var/tmp/cat-test < /var/tmp/cat-test2 && grep -q "file 2" /var/tmp/cat-test2 +t_CheckExitStatus $? + +rm /var/tmp/cat-test diff --git a/tests/p_coreutils/cut.sh b/tests/p_coreutils/cut.sh new file mode 100755 index 0000000..d7d775c --- /dev/null +++ b/tests/p_coreutils/cut.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 test cut" + +test `echo "1 2 3" | cut -f2 -d" "` -eq 2 +t_CheckExitStatus $? diff --git a/tests/p_coreutils/false.sh b/tests/p_coreutils/false.sh new file mode 100755 index 0000000..9442951 --- /dev/null +++ b/tests/p_coreutils/false.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 test false command" +false +test $? -eq 1 +t_CheckExitStatus $? diff --git a/tests/p_coreutils/head.sh b/tests/p_coreutils/head.sh new file mode 100755 index 0000000..85a1b25 --- /dev/null +++ b/tests/p_coreutils/head.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 test head command" + +cat << EOF > /var/tmp/head-test +1 +2 +3 +4 +5 +EOF + +head -n1 /var/tmp/head-test | grep -q 1 +t_CheckExitStatus $? + +# Cleanup +rm /var/tmp/head-test diff --git a/tests/p_coreutils/pathchk.sh b/tests/p_coreutils/pathchk.sh new file mode 100755 index 0000000..fbc243f --- /dev/null +++ b/tests/p_coreutils/pathchk.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Author: Alice Kaerast +t_Log "$0 testing pathchk gives good results" +pathchk -p "<>" 2> /dev/null +test $? -eq 1 && pathchk /var/tmp/1234567890123456789012345123456789012345678901234512345678901234567890123451234567890123456789012345123456789012345678901234512345678901234567890123451234567890123456789012345123456789012345678901234512345678901234567890123451234567890123456789012345123456 2> /dev/null +test $? -eq 1 && pathchk /var/tmp +t_CheckExitStatus $? diff --git a/tests/p_coreutils/readlink.sh b/tests/p_coreutils/readlink.sh new file mode 100755 index 0000000..d60e9af --- /dev/null +++ b/tests/p_coreutils/readlink.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 checking readlink prints target of a symlink" + +ln -s /var/tmp/foo /var/tmp/readlink-test +readlink /var/tmp/readlink-test | grep -q "/var/tmp/foo" +t_CheckExitStatus $? +rm /var/tmp/readlink-test diff --git a/tests/p_coreutils/sleeptimeout.sh b/tests/p_coreutils/sleeptimeout.sh new file mode 100755 index 0000000..b63688a --- /dev/null +++ b/tests/p_coreutils/sleeptimeout.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# Author Alice Kaerast + +t_Log "$0 checking timeout and sleep" + +timeout 1 sleep 2 +test $? -eq 124 && timeout 2 sleep 1 +t_CheckExitStatus $? diff --git a/tests/p_coreutils/tail.sh b/tests/p_coreutils/tail.sh new file mode 100755 index 0000000..b724b83 --- /dev/null +++ b/tests/p_coreutils/tail.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 test tail command" + +cat << EOF > /var/tmp/tail-test +1 +2 +3 +4 +5 +EOF + +tail -n1 /var/tmp/tail-test | grep -q 5 +t_CheckExitStatus $? + +# Cleanup +rm /var/tmp/tail-test diff --git a/tests/p_coreutils/test_hashsums.sh b/tests/p_coreutils/test_hashsums.sh new file mode 100755 index 0000000..c2a9ad7 --- /dev/null +++ b/tests/p_coreutils/test_hashsums.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 test various hash sum tools" +echo "abcdefghijklmnopqrstuvwxyz1234567890" > /var/tmp/test-hashsums +/usr/bin/sha1sum /var/tmp/test-hashsums | grep -q f2cc9f1b642d1962f244ba7b0ab206649d5f153c +/usr/bin/sha224sum /var/tmp/test-hashsums | grep -q 00f95b5eb233164f4690f1963447fd42d2055ff6e660ee9b9a1943f4 +/usr/bin/sha256sum /var/tmp/test-hashsums | grep -q e125e4eabe1eaac7988796098acb9e1eb8e81628ebf9937a4ec502411e461107 +/usr/bin/sha384sum /var/tmp/test-hashsums | grep -q 8bfefc0ba5512fc53c55a99f2e5d686e3c63c33fb4553edb1ea8844543492d6db5845470e5d6366a09596fd5cbeffce9 +/usr/bin/sha512sum /var/tmp/test-hashsums | grep -q 7ff71e3ce6dcabd62738506f37cba533fb42393981cb526c423ea24528a72d6561bc120eefbb679d831f49abc75de9c35829ea4ec2ea59f74903d15107f90b50 +/usr/bin/md5sum /var/tmp/test-hashsums | grep -q 6c6506b6cb9e6d9a85ec9f8621d85864 +t_CheckExitStatus $? + +# Cleanup +rm /var/tmp/test-hashsums diff --git a/tests/p_coreutils/touch.sh b/tests/p_coreutils/touch.sh new file mode 100755 index 0000000..0e32b60 --- /dev/null +++ b/tests/p_coreutils/touch.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 testing touch and ls" + +# Create two files +touch -t 198307081200 /var/tmp/touch-test-1 +touch -t 198707071200 /var/tmp/touch-test-2 + +# ls -lt should show oldest file last +ls -lt /var/tmp/touch-test-? | tail -n 1 | grep -q "touch-test-1" + +t_CheckExitStatus $? + +# Cleanup +rm /var/tmp/touch-test-? diff --git a/tests/p_coreutils/true.sh b/tests/p_coreutils/true.sh new file mode 100755 index 0000000..d9d79a5 --- /dev/null +++ b/tests/p_coreutils/true.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 test true command" +true +t_CheckExitStatus $? diff --git a/tests/p_coreutils/uniq.sh b/tests/p_coreutils/uniq.sh new file mode 100755 index 0000000..7fafb00 --- /dev/null +++ b/tests/p_coreutils/uniq.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 test uniq command" + +cat << EOF > /var/tmp/uniq-test +1 +2 +2 +3 +3 +4 +5 +EOF + +uniq -d /var/tmp/uniq-test | wc -l | grep -q 2 && uniq -u /var/tmp/uniq-test | wc -l | grep -q 3 +t_CheckExitStatus $? diff --git a/tests/p_coreutils/wc.sh b/tests/p_coreutils/wc.sh new file mode 100755 index 0000000..82b0055 --- /dev/null +++ b/tests/p_coreutils/wc.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 - test wc output" + +cat << EOF > /var/tmp/wc-test +1 2 +3 4 +5 6 +EOF + +# file should have 3 lines, 12 bytes, 12 characters, max line length of 3, and 6 words +wc -l /var/tmp/wc-test | grep -q 3 && wc -c /var/tmp/wc-test | grep -q 12 && wc -m /var/tmp/wc-test | grep -q 12 && wc -L /var/tmp/wc-test | grep -q 3 && wc -w /var/tmp/wc-test | grep -q 6 + +t_CheckExitStatus $? + +# Cleanup +rm /var/tmp/wc-test diff --git a/tests/p_coreutils/yes.sh b/tests/p_coreutils/yes.sh new file mode 100755 index 0000000..2bc68c7 --- /dev/null +++ b/tests/p_coreutils/yes.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Author: Alice Kaerast + +t_Log "$0 - Test yes command" + +# Create test files +touch /var/tmp/test-yes-123 +touch /var/tmp/test-yes-456 + +# -i makes rm ask for confirmation with 'y' so pipe yes to it +yes | rm -i /var/tmp/test-yes-* || exit 1 + +#Set deleted to 1, until we've succesfully tested that the files have gone +deleted=1 +#Test that the files don't exist then set deleted=0 +test -f /var/tmp/test-yes-123 || test -f /var/tmp/test-yes-456 || deleted=0 +t_CheckExitStatus $deleted