diff options
Diffstat (limited to 'src/tests/check_all_args.in')
-rwxr-xr-x | src/tests/check_all_args.in | 438 |
1 files changed, 292 insertions, 146 deletions
diff --git a/src/tests/check_all_args.in b/src/tests/check_all_args.in index 75584bc..3a2f121 100755 --- a/src/tests/check_all_args.in +++ b/src/tests/check_all_args.in @@ -8,6 +8,7 @@ script_name=${0##*/} # Use full path to build binary procenv="@builddir@/procenv" man_path="@man_path@" +driver="@procenv_platform@" template="/tmp/${script_name}.XXXXXXXXXX" @@ -93,7 +94,11 @@ _run_command() debug "Running: '$cmdline'" + # interestingly, all environment except OpenBSD allow the code below + # to run even if cmdline fail.s + set +e { eval "$cmdline"; ret=$?; } || : + set -e if [ "$expected_outcome" = success ] then @@ -157,8 +162,135 @@ run_tests() procenv_version=$($procenv --version|grep "version: [0-9]"|awk '{print $2}') [ -n "$procenv_version" ] || die "failed to query procenv version" + # list of all output sections seen when running with an individual + # argument. + arg_sections=$(mktemp "$template") + #--------------------------------------------------------------------- - msg "Running tests for language '$LANG'" + msg "Running procenv version $procenv_version tests for language '$LANG'" + + arg="--help" + msg "Ensure '$arg' works" + + stdout=$(mktemp "$template") + stderr=$(mktemp "$template") + cmd="$procenv $arg 1>\"$stdout\" 2>\"$stderr\"" + run_command "$cmd" "$stdout" "$stderr" + + [ -s "$stdout" ] || die "Expected stdout output in file $stdout" + [ -s "$stderr" ] && die "Unexpected stderr output in file $stdout" + + rm -f "$stdout" "$stderr" + + #--------------------------------------------------------------------- + # XXX: note that we run with each argument in turn *BEFORE* + # running with no arguments to avoid the situation where a + # particular type of outputcauses procenv to hang/spin but it's + # unclear which argument that output relates to if procenv is + # run without args. + + msg "Ensure all documented options produce output" + + procenv_options=$(get_procenv_options) + echo "$procenv_options" | while read arg + do + stdout=$(mktemp "$template") + stderr=$(mktemp "$template") + + # No format option + cmd="$procenv $arg 1>\"$stdout\" 2>\"$stderr\"" + msg "Running '$cmd'" + run_command "$cmd" "$stdout" "$stderr" + + [ -z "$stdout" ] && die "No stdout output running '$cmd'" + [ -s "$stderr" ] && die "Unexpected stderr output running '$cmd' ($stderr)" + + # Establish the name of the section + section=$(head -1 "$stdout"|grep "^[^ ].*:$" || :) + [ -z "$section" ] && die "No section title found running '$cmd'" + + # record the section we've seen + echo "$section" >> "$arg_sections" + + rm -f "$stdout" "$stderr" + + # Text format + cmd="$procenv --format=text $arg 1>\"$stdout\" 2>\"$stderr\"" + msg "Running '$cmd'" + run_command "$cmd" "$stdout" "$stderr" + + [ -z "$stdout" ] && die "No stdout output running '$cmd'" + [ -s "$stderr" ] && die "Unexpected stderr output running '$cmd' ($stderr)" + + if [ "$section" = "capabilities:" ] + then + tmp=$(grep 'CAP_LAST_CAP+1' "$stdout"|cut -d: -f2|tr -d ' ' || :) + # take care to only perform this test on + # platforms the _have_ capabilities :) + if [ -n "$tmp" ] + then + last=$(expr "$tmp" - 1) + + [ -n "$last" ] || die "unable to establish last capability" + { grep -q "number: $last" "$stdout"; ret=$?; } || : + if [ $ret -ne 0 ] + then + warn "" + warn "" + warn "Found extra capability procenv is not aware of (number $last)" + warn "" + warn "Note that this warning will appear if procenv is built on a" + warn "system which is running a newer kernel than the" + warn "development environment assumes (for example if built in a" + warn "chroot for a back-level release of ubuntu)" + warn "" + warn "Please check for a newer version of procenv, " + warn "build on a newer system, or raise a bug at:" + warn "" + warn " @package_url@" + warn "" + warn "" + fi + fi + fi + + rm -f "$stdout" "$stderr" + + # JSON format + if [ "$json_tests" -eq 1 ] + then + cmd="$procenv --format=json $arg 1>\"$stdout\" 2>\"$stderr\"" + msg "Running '$cmd'" + run_command "$cmd" "$stdout" "$stderr" + + [ -z "$stdout" ] && die "No stdout output running '$cmd'" + [ -s "$stderr" ] && die "Unexpected stderr output running '$cmd' ($stderr)" + + run_command "$json_checker < \"$stdout\" >/dev/null" "" "" + + rm -f "$stdout" "$stderr" + fi + + # XML format + if [ "$xml_tests" -eq 1 ] + then + cmd="$procenv --format=xml $arg" + if [ "$section" = "environment:" -a "$control_chars_in_env" -eq 1 ] + then + warn "Skipping '$cmd' as control characters found in environment" + else + msg "Running '$cmd'" + cmd="$cmd 1>\"$stdout\" 2>\"$stderr\"" + run_command "$cmd" "$stdout" "$stderr" + [ -z "$stdout" ] && die "No stdout output running '$cmd'" + [ -s "$stderr" ] && die "Unexpected stderr output running '$cmd' ($stderr)" + [ -z "$($xml_checker "$stdout")" ] || die "XML output not well-formed" + fi + + rm -f "$stdout" "$stderr" + fi + done + #--------------------------------------------------------------------- msg "Ensure $procenv runs with no errors" @@ -167,7 +299,9 @@ run_tests() $procenv 1>"$stdout" 2>"$stderr" rm -f "$stdout" "$stderr" - # Save all sections that are displayed by default for later checks + # Save all section names to compare to the total set of section + # names generated by running procenv once for each output + # argument. sections=$($procenv|grep "^[a-z0-9][a-z0-9 ]*:$") msg "Ensuring output is sorted by section" @@ -175,11 +309,18 @@ run_tests() main_sections=$(mktemp "$template") sorted_sections=$(mktemp "$template") unique_sections=$(mktemp "$template") + unique_arg_sections=$(mktemp "$template") + + echo "$sections"|grep -q ^meta: || die "no meta section in main sections" + grep -q ^meta: "$arg_sections" || die "no meta section in arg sections" # ignore meta which always comes first - echo "$sections"|grep -v meta: > "$main_sections" - echo "$sections"|grep -v meta:|sort > "$sorted_sections" - echo "$sections"|grep -v meta:|sort -u > "$unique_sections" + echo "$sections" |grep -v meta: > "$main_sections" + echo "$sections" |grep -v meta:|sort > "$sorted_sections" + echo "$sections" |grep -v meta:|sort -u > "$unique_sections" + + cat "$arg_sections"|egrep -v "^(meta|version|pathconf):"|\ + sort -u > "$unique_arg_sections" diff=$(diff "$main_sections" "$sorted_sections" || :) [ -n "$diff" ] && die "sections are not sorted - diff: $diff" @@ -187,14 +328,30 @@ run_tests() diff=$(diff "$sorted_sections" "$unique_sections" || :) [ -n "$diff" ] && die "sections are not unique - diff: $diff" - rm -f "$main_sections" "$sorted_sections" "$unique_sections" + # Note that we don't compare the sorted and unique arg_sections + # since there are 2 ways to produce the same section output + # (short and long option). + + diff=$(diff "$unique_sections" "$unique_arg_sections" || :) + [ -n "$diff" ] && die "default output sections do not match arg-collected sections - diff: $diff" + + rm -f "$main_sections" \ + "$sorted_sections" \ + "$unique_sections" \ + "$arg_sections" \ + "$unique_arg_sections" - remaining_file=$(mktemp "$template") - echo "$sections" > "$remaining_file" + # pathconf cannot be handled like other sections since it is + # indented under the mount output, so just check we can find + # some evidence of it being displayed. + # + # Don't do this for the unknown driver since that doesn't produce + # mount output. - # pathconf cannot be handled below as it is indented under the mount - # output, so just check we can find some evidence of it being displayed. - $procenv|egrep -q "\<pathconf\>:" || die "Failed to find pathconf" + if [ "$driver" != "unknown" ] + then + $procenv|egrep -q "\<pathconf\>:" || die "Failed to find pathconf" + fi #--------------------------------------------------------------------- msg "Ensure --file=<file> works" @@ -213,6 +370,62 @@ run_tests() rm -f "$stdout" "$stderr" #--------------------------------------------------------------------- + msg "Ensure running multiple '--file=<file> --version' works" + + out=$(mktemp "$template") + stdout=$(mktemp "$template") + stderr=$(mktemp "$template") + cmd="$procenv --file=\"$out\" --version 1>\"$stdout\" 2>\"$stderr\"" + + # run twice - we expect the output file to be overwritten + for expected in 1 1 + do + run_command "$cmd" "$stdout" "$stderr" + [ -s "$stdout" ] && die "Unexpected stdout output: $stdout" + [ -s "$stderr" ] && die "Unexpected stderr output: $stderr" + [ -s "$out" ] || die "Expected output in file $out" + + count=$(grep -c ^version: "$out") + [ "$count" -eq "$expected" ] || die "expected $expected match in file $out - got $count" + done + + rm "$out" + rm -f "$stdout" "$stderr" + + #--------------------------------------------------------------------- + msg "Ensure '--file-append --file=<file> --version' works" + + out=$(mktemp "$template") + stdout=$(mktemp "$template") + stderr=$(mktemp "$template") + for options in "--file=\"$out\" --file-append" "--file-append --file=\"$out\"" + do + cmd="$procenv $options --version 1>\"$stdout\" 2>\"$stderr\"" + + run_command "$cmd" "$stdout" "$stderr" + [ -s "$stdout" ] && die "Unexpected stdout output: $stdout" + [ -s "$stderr" ] && die "Unexpected stderr output: $stderr" + [ -s "$out" ] || die "Expected output in file $out" + + expected=1 + count=$(grep -c ^version: "$out") + [ "$count" -eq "$expected" ] || die "expected $expected match in file $out - got $count" + + run_command "$cmd" "$stdout" "$stderr" + [ -s "$stdout" ] && die "Unexpected stdout output: $stdout" + [ -s "$stderr" ] && die "Unexpected stderr output: $stderr" + [ -s "$out" ] || die "Expected output in file $out" + + # the output file should be appended + expected=$((expected+1)) + count=$(grep -c ^version: "$out") + [ "$count" -eq "$expected" ] || die "expected $expected match in file $out - got $count" + + rm "$out" + rm -f "$stdout" "$stderr" + done + + #--------------------------------------------------------------------- msg "Ensure --output=stdout works" stdout=$(mktemp "$template") @@ -242,7 +455,7 @@ run_tests() rm -f "$stdout" "$stderr" #--------------------------------------------------------------------- - msg "Ensure --exec works" + msg "Ensure --exec works (with no previous arguments)" str="hello world" out=$(mktemp "$template") @@ -263,7 +476,29 @@ run_tests() rm -f "$stdout" "$stderr" "$out" #--------------------------------------------------------------------- - msg "Ensure --exec can exec $procenv" + msg "Ensure '--version --exec' works" + + str="hello world" + out=$(mktemp "$template") + stdout=$(mktemp "$template") + stderr=$(mktemp "$template") + cmd="$procenv --output=file --file=\"$out\" --version \ + --exec echo \"$str\" 1>\"$stdout\" 2>\"$stderr\"" + run_command "$cmd" "$stdout" "$stderr" + + [ -s "$out" ] || die "Expected $procenv output in file $out" + grep -q ^version: "$out" || die "Expected $procenv --version output in file $out" + [ -s "$stderr" ] && die "Unexpected stderr output in file $stderr" + [ -s "$stdout" ] || die "Expected stdout output in file $stdout" + result=$(cat "$stdout") + + [ "$result" != "$str" ] && die \ + "Expected file $stdout to contain '$str', found '$result'" + + rm -f "$stdout" "$stderr" "$out" + + #--------------------------------------------------------------------- + msg "Ensure '--exec' can exec $procenv" out=$(mktemp "$template") out2=$(mktemp "$template") @@ -283,6 +518,38 @@ run_tests() rm -f "$stdout" "$stderr" "$out" "$out2" #--------------------------------------------------------------------- + msg "Ensure 'PROCENV_EXEC' and 'PROCENV_FILE' variables work" + + out=$(mktemp "$template") + stdout=$(mktemp "$template") + stderr=$(mktemp "$template") + + test_script=$(mktemp "$template") + test_log=$(mktemp "$template") + expected="foo" + cat <<EOT > "$test_script" + #!/bin/sh + + echo "$expected" > "$test_log" +EOT + chmod +x "$test_script" + + (PROCENV_FILE="$out" PROCENV_EXEC="$test_script" \ + "$procenv" 1>"$stdout" 2>"$stderr") + + [ -s "$out" ] || die "Expected $procenv output in file $out" + [ -s "$test_log" ] || die "Expected output in test log file $test_log" + output=$(cat "$test_log") + + [ "$output" = "$expected" ] || \ + die "incorect output from script (expected '$expected', got '$output')" + + [ -s "$stdout" ] && die "Unexpected stdout output in file $stdout" + [ -s "$stderr" ] && die "Unexpected stderr output in file $stderr" + + rm -f "$out" "$stdout" "$stderr" "$test_script" "$test_log" + + #--------------------------------------------------------------------- arg='--format=text' msg "Ensure '$arg' works" @@ -464,122 +731,6 @@ run_tests() rm -f "$stdout" "$stderr" fi - #--------------------------------------------------------------------- - msg "Ensure all documented options produce output" - procenv_options=$(get_procenv_options) - echo "$procenv_options" | while read arg - do - stdout=$(mktemp "$template") - stderr=$(mktemp "$template") - - # No format option - cmd="$procenv $arg 1>\"$stdout\" 2>\"$stderr\"" - msg "Running '$cmd'" - run_command "$cmd" "$stdout" "$stderr" - - [ -z "$stdout" ] && die "No stdout output running '$cmd'" - [ -s "$stderr" ] && die "Unexpected stderr output running '$cmd' ($stderr)" - - # Establish the name of the section - section=$(head -1 "$stdout"|grep "^[^ ].*:$" || :) - [ -z "$section" ] && die "No section title found running '$cmd'" - - if [ "$section" != "version:" ] - then - # XXX: pathconf has already been handled above. - if [ "$section" != "pathconf:" ] - then - # Check that that same section appears in the - # default output. If not, we forgot to update - # dump(). - echo "$sections"|grep -q "^${section}$" || \ - die "Failed to find section '$section' in default $procenv output" - fi - fi - - # Remove this section as it's now been handled - remaining=$(cat "$remaining_file"|grep -v "^${section}$" || :) - echo "$remaining"> "$remaining_file" - - rm -f "$stdout" "$stderr" - - # Text format - cmd="$procenv --format=text $arg 1>\"$stdout\" 2>\"$stderr\"" - msg "Running '$cmd'" - run_command "$cmd" "$stdout" "$stderr" - - [ -z "$stdout" ] && die "No stdout output running '$cmd'" - [ -s "$stderr" ] && die "Unexpected stderr output running '$cmd' ($stderr)" - - if [ "$section" = "capabilities:" ] - then - tmp=$(grep 'CAP_LAST_CAP+1' "$stdout"|cut -d: -f2|tr -d ' ' || :) - # take care to only perform this test on - # platforms the _have_ capabilities :) - if [ -n "$tmp" ] - then - last=$(expr "$tmp" - 1) - - [ -n "$last" ] || die "unable to establish last capability" - { grep -q "number: $last" "$stdout"; ret=$?; } || : - if [ $ret -ne 0 ] - then - warn "" - warn "" - warn "Found extra capability procenv is not aware of (number $last)" - warn "" - warn "Note that this warning will appear if procenv is built on a" - warn "system which is running a newer kernel than the" - warn "development environment assumes (for example if built in a" - warn "chroot for a back-level release of ubuntu)" - warn "" - warn "Please check for a newer version of procenv, " - warn "build on a newer system, or raise a bug at:" - warn "" - warn " @package_url@" - warn "" - warn "" - fi - fi - fi - - rm -f "$stdout" "$stderr" - - # JSON format - if [ "$json_tests" -eq 1 ] - then - cmd="$procenv --format=json $arg 1>\"$stdout\" 2>\"$stderr\"" - msg "Running '$cmd'" - run_command "$cmd" "$stdout" "$stderr" - - [ -z "$stdout" ] && die "No stdout output running '$cmd'" - [ -s "$stderr" ] && die "Unexpected stderr output running '$cmd' ($stderr)" - - run_command "$json_checker < \"$stdout\" >/dev/null" "" "" - - rm -f "$stdout" "$stderr" - fi - - # XML format - if [ "$xml_tests" -eq 1 ] - then - cmd="$procenv --format=xml $arg" - if [ "$section" = "environment:" -a "$control_chars_in_env" -eq 1 ] - then - warn "Skipping '$cmd' as control characters found in environment" - else - msg "Running '$cmd'" - cmd="$cmd 1>\"$stdout\" 2>\"$stderr\"" - run_command "$cmd" "$stdout" "$stderr" - [ -z "$stdout" ] && die "No stdout output running '$cmd'" - [ -s "$stderr" ] && die "Unexpected stderr output running '$cmd' ($stderr)" - [ -z "$($xml_checker "$stdout")" ] || die "XML output not well-formed" - fi - - rm -f "$stdout" "$stderr" - fi - done - for arg in $non_display_options do # XXX: specifying a non-display option _after_ @@ -601,17 +752,6 @@ run_tests() rm -f "$stdout" "$stderr" done - # If there are any remaining sections that were produced by default - # output but which have not been handed by command-line options, we - # forgot to update usage(). - msg "Checking for missing arguments" - remaining=$(cat "$remaining_file") - - [ -n "$remaining" ] && \ - die "No command-line option found for the following section(s): '$remaining'" - - rm -f "$remaining_file" - msg "Ensure an empty environment is tolerated" if command -v env >/dev/null 2>&1 then @@ -641,13 +781,19 @@ run_final_tests() } #--------------------------------------------------------------------- +# main +#--------------------------------------------------------------------- -# allow this useful function to be called independent of the tests. -case "$1" in - options) - get_procenv_options - exit 0 -esac +while getopts "o" opt +do + case "$opt" in + o) + # allow this useful function to be called independent of the tests. + get_procenv_options + exit 0 + ;; + esac +done init |