From 3b694115de3071e0c57371d209cbf124532a0f85 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Mon, 14 Nov 2011 20:25:01 +0000 Subject: [PATCH] Use simple test (without expect) for usage checking. --- .../04_expiry_no_options/data/usage.out | 8 +++++++ tests/expiry/04_expiry_no_options/expiry.exp | 18 --------------- tests/expiry/04_expiry_no_options/expiry.test | 19 +++++++++++++++- .../10_expiry_bad_option/data/usage.out | 9 ++++++++ tests/expiry/10_expiry_bad_option/expiry.exp | 18 --------------- tests/expiry/10_expiry_bad_option/expiry.test | 22 ++++++++++++++++--- 6 files changed, 54 insertions(+), 40 deletions(-) create mode 100644 tests/expiry/04_expiry_no_options/data/usage.out delete mode 100755 tests/expiry/04_expiry_no_options/expiry.exp create mode 100644 tests/expiry/10_expiry_bad_option/data/usage.out delete mode 100755 tests/expiry/10_expiry_bad_option/expiry.exp diff --git a/tests/expiry/04_expiry_no_options/data/usage.out b/tests/expiry/04_expiry_no_options/data/usage.out new file mode 100644 index 00000000..ab67c87b --- /dev/null +++ b/tests/expiry/04_expiry_no_options/data/usage.out @@ -0,0 +1,8 @@ +Usage: expiry [options] + +Options: + -c, --check check the user's password expiration + -f, --force force password change if the user's password + is expired + -h, --help display this help message and exit + diff --git a/tests/expiry/04_expiry_no_options/expiry.exp b/tests/expiry/04_expiry_no_options/expiry.exp deleted file mode 100755 index 19ddb477..00000000 --- a/tests/expiry/04_expiry_no_options/expiry.exp +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/expect - -set timeout 2 -expect_after default {puts "\nFAIL"; exit 1} - -spawn /bin/sh -send "if \[ \$(id -u) -eq 0 \]; then PS1='# '; else PS1='$ '; fi\r" -expect "# " - -send "expiry\r" -expect "Usage: expiry {-f|-c}" -expect "# " -send "echo \$?\r" -expect "10" -expect "# " -send "exit\r" -puts "OK\n" -exit 0 diff --git a/tests/expiry/04_expiry_no_options/expiry.test b/tests/expiry/04_expiry_no_options/expiry.test index d8c9c0da..02c6cbb0 100755 --- a/tests/expiry/04_expiry_no_options/expiry.test +++ b/tests/expiry/04_expiry_no_options/expiry.test @@ -16,7 +16,24 @@ trap 'log_status "$0" "FAILURE"; restore_config' 0 change_config -./expiry.exp +echo -n "Call expiry without any option (expiry)..." +expiry 2>tmp/usage.out && exit 1 || { + status=$? +} +echo "OK" + +echo -n "Check returned status ($status)..." +test "$status" = "2" +echo "OK" + +echo "expiry reported:" +echo "=======================================================================" +cat tmp/usage.out +echo "=======================================================================" +echo -n "Check the usage message..." +diff -au data/usage.out tmp/usage.out +echo "usage message OK." +rm -f tmp/usage.out echo -n "Check the passwd file..." ../../common/compare_file.pl config/etc/passwd /etc/passwd diff --git a/tests/expiry/10_expiry_bad_option/data/usage.out b/tests/expiry/10_expiry_bad_option/data/usage.out new file mode 100644 index 00000000..c2d97166 --- /dev/null +++ b/tests/expiry/10_expiry_bad_option/data/usage.out @@ -0,0 +1,9 @@ +expiry: invalid option -- 'Z' +Usage: expiry [options] + +Options: + -c, --check check the user's password expiration + -f, --force force password change if the user's password + is expired + -h, --help display this help message and exit + diff --git a/tests/expiry/10_expiry_bad_option/expiry.exp b/tests/expiry/10_expiry_bad_option/expiry.exp deleted file mode 100755 index 0a42cc2e..00000000 --- a/tests/expiry/10_expiry_bad_option/expiry.exp +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/expect - -set timeout 2 -expect_after default {puts "\nFAIL"; exit 1} - -spawn /bin/sh -send "if \[ \$(id -u) -eq 0 \]; then PS1='# '; else PS1='$ '; fi\r" -expect "# " - -send "expiry -Z\r" -expect "Usage: expiry {-f|-c}" -expect "# " -send "echo \$?\r" -expect "10" -expect "# " -send "exit\r" -puts "OK\n" -exit 0 diff --git a/tests/expiry/10_expiry_bad_option/expiry.test b/tests/expiry/10_expiry_bad_option/expiry.test index d8c9c0da..bcbbb608 100755 --- a/tests/expiry/10_expiry_bad_option/expiry.test +++ b/tests/expiry/10_expiry_bad_option/expiry.test @@ -6,8 +6,7 @@ cd $(dirname $0) . ../../common/config.sh . ../../common/log.sh - -log_start "$0" "expiry provides an Usage message if no options are given" +log_start "$0" "expiry provides an Usage message if an invalid option is given" save_config @@ -16,7 +15,24 @@ trap 'log_status "$0" "FAILURE"; restore_config' 0 change_config -./expiry.exp +echo -n "Call expiry with an invalid option (expiry -Z)..." +expiry -Z 2>tmp/usage.out && exit 1 || { + status=$? +} +echo "OK" + +echo -n "Check returned status ($status)..." +test "$status" = "2" +echo "OK" + +echo "expiry reported:" +echo "=======================================================================" +cat tmp/usage.out +echo "=======================================================================" +echo -n "Check the usage message..." +diff -au data/usage.out tmp/usage.out +echo "usage message OK." +rm -f tmp/usage.out echo -n "Check the passwd file..." ../../common/compare_file.pl config/etc/passwd /etc/passwd