From 6b772f881dd8bb1a2a40181e6c76187c9c847c30 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 9 Jul 2017 18:15:49 -0400 Subject: test: librexgettext: Add tests --- test/librexgettext-test.sh | 58 ++++++++++++++++++++++ test/librexgettext.d/.gitignore | 1 + test/librexgettext.d/combine.pot | 15 ++++++ test/librexgettext.d/combine1.sh | 5 ++ test/librexgettext.d/combine2.sh | 5 ++ .../it_fails_on_missing_final_flag_description.sh | 4 ++ .../it_fails_on_subshell_flag_descriptions.sh | 7 +++ .../it_handles_librefetch_flags.pot | 40 +++++++++++++++ .../librexgettext.d/it_handles_librefetch_flags.sh | 15 ++++++ .../it_handles_multiple_skipped_flags.pot | 58 ++++++++++++++++++++++ .../it_handles_multiple_skipped_flags.sh | 17 +++++++ test/librexgettext.d/it_handles_zero_flags.pot | 0 test/librexgettext.d/it_handles_zero_flags.sh | 4 ++ 13 files changed, 229 insertions(+) create mode 100644 test/librexgettext-test.sh create mode 100644 test/librexgettext.d/.gitignore create mode 100644 test/librexgettext.d/combine.pot create mode 100644 test/librexgettext.d/combine1.sh create mode 100644 test/librexgettext.d/combine2.sh create mode 100644 test/librexgettext.d/it_fails_on_missing_final_flag_description.sh create mode 100644 test/librexgettext.d/it_fails_on_subshell_flag_descriptions.sh create mode 100644 test/librexgettext.d/it_handles_librefetch_flags.pot create mode 100644 test/librexgettext.d/it_handles_librefetch_flags.sh create mode 100644 test/librexgettext.d/it_handles_multiple_skipped_flags.pot create mode 100644 test/librexgettext.d/it_handles_multiple_skipped_flags.sh create mode 100644 test/librexgettext.d/it_handles_zero_flags.pot create mode 100644 test/librexgettext.d/it_handles_zero_flags.sh diff --git a/test/librexgettext-test.sh b/test/librexgettext-test.sh new file mode 100644 index 0000000..f9a0031 --- /dev/null +++ b/test/librexgettext-test.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env roundup + +describe librexgettext +. ./test-common.sh + +it_displays_help() { + LC_ALL=C librexgettext -h >$tmpdir/stdout 2>$tmpdir/stderr + + [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]] + empty $tmpdir/stderr +} + +it_fails_with_0_args() { + librexgettext >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + empty $tmpdir/stdout + not empty $tmpdir/stderr +} + +passcase() { + librexgettext librexgettext.d/$roundup_test_name.sh > $tmpdir/actual.pot 2>$tmpdir/stderr + empty $tmpdir/stderr + diff -u librexgettext.d/$roundup_test_name.pot $tmpdir/actual.pot +} + +it_handles_multiple_skipped_flags() { passcase; } +it_handles_zero_flags() { passcase; } +it_handles_librefetch_flags() { passcase; } + +it_fails_on_missing_final_flag_description() { + librexgettext librexgettext.d/$roundup_test_name.sh > /dev/null 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ "$(sed 1q $tmpdir/stderr)" = "librexgettext.d/$roundup_test_name.sh:4:"* ]] +} + + +it_fails_on_subshell_flag_descriptions() { + librexgettext librexgettext.d/$roundup_test_name.sh > /dev/null 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + [[ "$(sed 1q $tmpdir/stderr)" = "librexgettext.d/$roundup_test_name.sh:4-6:"* ]] +} + +it_doesnt_keep_failing() { + librexgettext some_file_that_doesnt_exist >$tmpdir/stdout 2>$tmpdir/stderr || stat=$? + + [[ $stat != 0 ]] + empty $tmpdir/stdout + [[ "$(wc -l <$tmpdir/stderr)" == 1 ]] +} + +it_handles_multiple_files() { + librexgettext librexgettext.d/combine1.sh librexgettext.d/combine2.sh > $tmpdir/actual.pot 2>$tmpdir/stderr + empty $tmpdir/stderr + diff -u librexgettext.d/combine.pot $tmpdir/actual.pot +} diff --git a/test/librexgettext.d/.gitignore b/test/librexgettext.d/.gitignore new file mode 100644 index 0000000..f0febc8 --- /dev/null +++ b/test/librexgettext.d/.gitignore @@ -0,0 +1 @@ +!/*.pot diff --git a/test/librexgettext.d/combine.pot b/test/librexgettext.d/combine.pot new file mode 100644 index 0000000..80d066f --- /dev/null +++ b/test/librexgettext.d/combine.pot @@ -0,0 +1,15 @@ +#: librexgettext.d/combine1.sh:4 +msgid "Flag a" +msgstr "" + +#: librexgettext.d/combine1.sh:5 +msgid "Flag b" +msgstr "" + +#: librexgettext.d/combine2.sh:4 +msgid "Flag 1" +msgstr "" + +#: librexgettext.d/combine2.sh:5 +msgid "Flag 2" +msgstr "" diff --git a/test/librexgettext.d/combine1.sh b/test/librexgettext.d/combine1.sh new file mode 100644 index 0000000..9946076 --- /dev/null +++ b/test/librexgettext.d/combine1.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +. libremessages + +flag -a 'Flag a' \ + -b 'Flag b' diff --git a/test/librexgettext.d/combine2.sh b/test/librexgettext.d/combine2.sh new file mode 100644 index 0000000..441e87a --- /dev/null +++ b/test/librexgettext.d/combine2.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +. libremessages + +flag -1 'Flag 1' \ + -2 'Flag 2' diff --git a/test/librexgettext.d/it_fails_on_missing_final_flag_description.sh b/test/librexgettext.d/it_fails_on_missing_final_flag_description.sh new file mode 100644 index 0000000..1c9fc23 --- /dev/null +++ b/test/librexgettext.d/it_fails_on_missing_final_flag_description.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +. libremessages + +flag -a diff --git a/test/librexgettext.d/it_fails_on_subshell_flag_descriptions.sh b/test/librexgettext.d/it_fails_on_subshell_flag_descriptions.sh new file mode 100644 index 0000000..f6be764 --- /dev/null +++ b/test/librexgettext.d/it_fails_on_subshell_flag_descriptions.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +. libremessages + +flag '-a' \ + "$(echo foo)" \ + '-h' \ + help diff --git a/test/librexgettext.d/it_handles_librefetch_flags.pot b/test/librexgettext.d/it_handles_librefetch_flags.pot new file mode 100644 index 0000000..0d76a49 --- /dev/null +++ b/test/librexgettext.d/it_handles_librefetch_flags.pot @@ -0,0 +1,40 @@ +#: librexgettext.d/it_handles_librefetch_flags.sh:4 +msgid "Settings:" +msgstr "" + +#: librexgettext.d/it_handles_librefetch_flags.sh:5 +msgid "Force create mode (don't download)" +msgstr "" + +#: librexgettext.d/it_handles_librefetch_flags.sh:6 +msgid "Force download mode (don't create)" +msgstr "" + +#: librexgettext.d/it_handles_librefetch_flags.sh:7 +msgid "FILE" +msgstr "" + +#: librexgettext.d/it_handles_librefetch_flags.sh:7 +msgid "Use an alternate build script (instead of 'PKGBUILD'). If an " + "SRCBUILD exists in the same directory, it is used instead" +msgstr "" + +#: librexgettext.d/it_handles_librefetch_flags.sh:10 +msgid "Alternate modes:" +msgstr "" + +#: librexgettext.d/it_handles_librefetch_flags.sh:11 +msgid "Generate integrity checks for source files" +msgstr "" + +#: librexgettext.d/it_handles_librefetch_flags.sh:12 +msgid "Print the effective build script (SRCBUILD)" +msgstr "" + +#: librexgettext.d/it_handles_librefetch_flags.sh:13 +msgid "Generate and print the location of the effective makepkg script" +msgstr "" + +#: librexgettext.d/it_handles_librefetch_flags.sh:15 +msgid "Show this message" +msgstr "" diff --git a/test/librexgettext.d/it_handles_librefetch_flags.sh b/test/librexgettext.d/it_handles_librefetch_flags.sh new file mode 100644 index 0000000..579ca96 --- /dev/null +++ b/test/librexgettext.d/it_handles_librefetch_flags.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +. libremessages + +flag 'Settings:' \ + "-C" "Force create mode (don't download)" \ + "-D" "Force download mode (don't create)" \ + "-p <$(_ FILE)>" "Use an alternate build script (instead of + 'PKGBUILD'). If an SRCBUILD exists in the same + directory, it is used instead" \ + 'Alternate modes:' \ + "-g, --geninteg" "Generate integrity checks for source files" \ + "-S, --srcbuild" "Print the effective build script (SRCBUILD)" \ + "-M, --makepkg" "Generate and print the location of the + effective makepkg script" \ + "-h, --help" "Show this message" diff --git a/test/librexgettext.d/it_handles_multiple_skipped_flags.pot b/test/librexgettext.d/it_handles_multiple_skipped_flags.pot new file mode 100644 index 0000000..cae2a17 --- /dev/null +++ b/test/librexgettext.d/it_handles_multiple_skipped_flags.pot @@ -0,0 +1,58 @@ +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:4 +msgid "Flag 1" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:4 +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:6 +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:7 +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:8 +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:9 +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:10 +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:11 +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:13 +msgid "OPTARG" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:5 +msgid "Flag 2" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:6 +msgid "Flag 3" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:7 +msgid "Flag 4" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:8 +msgid "Flag 5" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:9 +msgid "Flag 6" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:10 +msgid "Flag 7" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:11 +msgid "Flag 8" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:13 +msgid "FLAG 1" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:14 +msgid "FLAG 2" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:16 +msgid "FLAG A" +msgstr "" + +#: librexgettext.d/it_handles_multiple_skipped_flags.sh:17 +msgid "FLAG B" +msgstr "" diff --git a/test/librexgettext.d/it_handles_multiple_skipped_flags.sh b/test/librexgettext.d/it_handles_multiple_skipped_flags.sh new file mode 100644 index 0000000..3b4dcee --- /dev/null +++ b/test/librexgettext.d/it_handles_multiple_skipped_flags.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +. libremessages + +flag "-a $(_ OPTARG)" 'Flag 1' \ + '-b' 'Flag 2' \ + "-c $(_ OPTARG)" 'Flag 3' \ + "-d $(_ OPTARG)" 'Flag 4' \ + "-e $(_ OPTARG)" 'Flag 5' \ + "-f $(_ OPTARG)" 'Flag 6' \ + "-g $(_ OPTARG)" 'Flag 7' \ + "-h $(_ OPTARG)" 'Flag 8' + +flag "-A $(_ OPTARG)" 'FLAG 1' \ + '-B' 'FLAG 2' + +flag '-1' 'FLAG A' \ + '-2' 'FLAG B' diff --git a/test/librexgettext.d/it_handles_zero_flags.pot b/test/librexgettext.d/it_handles_zero_flags.pot new file mode 100644 index 0000000..e69de29 diff --git a/test/librexgettext.d/it_handles_zero_flags.sh b/test/librexgettext.d/it_handles_zero_flags.sh new file mode 100644 index 0000000..2b6369c --- /dev/null +++ b/test/librexgettext.d/it_handles_zero_flags.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +. libremessages + +flag -- cgit v1.2.2