| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| scriptversion=2011-12-27.17; |
| |
| |
| |
| set -u |
| |
| me=tap-driver.sh |
| |
| fatal () |
| { |
| echo "$me: fatal: $*" >&2 |
| exit 1 |
| } |
| |
| usage_error () |
| { |
| echo "$me: $*" >&2 |
| print_usage >&2 |
| exit 2 |
| } |
| |
| print_usage () |
| { |
| cat <<END |
| Usage: |
| tap-driver.sh --test-name=NAME --log-file=PATH --trs-file=PATH |
| [--expect-failure={yes|no}] [--color-tests={yes|no}] |
| [--enable-hard-errors={yes|no}] [--ignore-exit] |
| [--diagnostic-string=STRING] [--merge|--no-merge] |
| [--comments|--no-comments] [--] TEST-COMMAND |
| The \`--test-name', \`--log-file' and \`--trs-file' options are mandatory. |
| END |
| } |
| |
| |
| |
| test_name= |
| log_file= |
| trs_file= |
| expect_failure=0 |
| color_tests=0 |
| merge=0 |
| ignore_exit=0 |
| comments=0 |
| diag_string=' |
| while test $ |
| case $1 in |
| --help) print_usage; exit $?;; |
| --version) echo "$me $scriptversion"; exit $?;; |
| --test-name) test_name=$2; shift;; |
| --log-file) log_file=$2; shift;; |
| --trs-file) trs_file=$2; shift;; |
| --color-tests) color_tests=$2; shift;; |
| --expect-failure) expect_failure=$2; shift;; |
| --enable-hard-errors) shift;; |
| --merge) merge=1;; |
| --no-merge) merge=0;; |
| --ignore-exit) ignore_exit=1;; |
| --comments) comments=1;; |
| --no-comments) comments=0;; |
| --diagnostic-string) diag_string=$2; shift;; |
| --) shift; break;; |
| -*) usage_error "invalid option: '$1'";; |
| esac |
| shift |
| done |
| |
| test $ |
| |
| case $expect_failure in |
| yes) expect_failure=1;; |
| *) expect_failure=0;; |
| esac |
| |
| if test $color_tests = yes; then |
| init_colors=' |
| color_map["red"]="[0;31m" |
| color_map["grn"]="[0;32m" |
| color_map["lgn"]="[1;32m" |
| color_map["blu"]="[1;34m" |
| color_map["mgn"]="[0;35m" |
| color_map["std"]="[m" |
| color_for_result["ERROR"] = "mgn" |
| color_for_result["PASS"] = "grn" |
| color_for_result["XPASS"] = "red" |
| color_for_result["FAIL"] = "red" |
| color_for_result["XFAIL"] = "lgn" |
| color_for_result["SKIP"] = "blu"' |
| else |
| init_colors='' |
| fi |
| |
| |
| |
| |
| :;{ |
| ( |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| trap : 1 3 2 13 15 |
| if test $merge -gt 0; then |
| exec 2>&1 |
| else |
| exec 2>&3 |
| fi |
| "$@" |
| echo $? |
| ) | LC_ALL=C ${AM_TAP_AWK-awk} \ |
| -v me="$me" \ |
| -v test_script_name="$test_name" \ |
| -v log_file="$log_file" \ |
| -v trs_file="$trs_file" \ |
| -v expect_failure="$expect_failure" \ |
| -v merge="$merge" \ |
| -v ignore_exit="$ignore_exit" \ |
| -v comments="$comments" \ |
| -v diag_string="$diag_string" \ |
| ' |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function fatal(msg) |
| { |
| print me ": " msg | "cat >&2" |
| exit 1 |
| } |
| |
| function abort(where) |
| { |
| fatal("internal error " where) |
| } |
| |
| |
| function yn(bool) |
| { |
| return bool ? "yes" : "no"; |
| } |
| |
| function add_test_result(result) |
| { |
| if (!test_results_index) |
| test_results_index = 0 |
| test_results_list[test_results_index] = result |
| test_results_index += 1 |
| test_results_seen[result] = 1; |
| } |
| |
| |
| function must_recheck() |
| { |
| for (k in test_results_seen) |
| if (k != "XFAIL" && k != "PASS" && k != "SKIP") |
| return 1 |
| return 0 |
| } |
| |
| |
| |
| function copy_in_global_log() |
| { |
| for (k in test_results_seen) |
| if (k != "PASS") |
| return 1 |
| return 0 |
| } |
| |
| |
| function get_global_test_result() |
| { |
| if ("ERROR" in test_results_seen) |
| return "ERROR" |
| if ("FAIL" in test_results_seen || "XPASS" in test_results_seen) |
| return "FAIL" |
| all_skipped = 1 |
| for (k in test_results_seen) |
| if (k != "SKIP") |
| all_skipped = 0 |
| if (all_skipped) |
| return "SKIP" |
| return "PASS"; |
| } |
| |
| function stringify_result_obj(result_obj) |
| { |
| if (result_obj["is_unplanned"] || result_obj["number"] != testno) |
| return "ERROR" |
| |
| if (plan_seen == LATE_PLAN) |
| return "ERROR" |
| |
| if (result_obj["directive"] == "TODO") |
| return result_obj["is_ok"] ? "XPASS" : "XFAIL" |
| |
| if (result_obj["directive"] == "SKIP") |
| return result_obj["is_ok"] ? "SKIP" : COOKED_FAIL; |
| |
| if (length(result_obj["directive"])) |
| abort("in function stringify_result_obj()") |
| |
| return result_obj["is_ok"] ? COOKED_PASS : COOKED_FAIL |
| } |
| |
| function decorate_result(result) |
| { |
| color_name = color_for_result[result] |
| if (color_name) |
| return color_map[color_name] "" result "" color_map["std"] |
| |
| |
| return result |
| } |
| |
| function report(result, details) |
| { |
| if (result ~ /^(X?(PASS|FAIL)|SKIP|ERROR)/) |
| { |
| msg = ": " test_script_name |
| add_test_result(result) |
| } |
| else if (result == "#") |
| { |
| msg = " " test_script_name ":" |
| } |
| else |
| { |
| abort("in function report()") |
| } |
| if (length(details)) |
| msg = msg " " details |
| |
| print decorate_result(result) msg |
| |
| |
| print result msg | "cat >&3"; |
| } |
| |
| function testsuite_error(error_message) |
| { |
| report("ERROR", "- " error_message) |
| } |
| |
| function handle_tap_result() |
| { |
| details = result_obj["number"]; |
| if (length(result_obj["description"])) |
| details = details " " result_obj["description"] |
| |
| if (plan_seen == LATE_PLAN) |
| { |
| details = details " # AFTER LATE PLAN"; |
| } |
| else if (result_obj["is_unplanned"]) |
| { |
| details = details " # UNPLANNED"; |
| } |
| else if (result_obj["number"] != testno) |
| { |
| details = sprintf("%s # OUT-OF-ORDER (expecting %d)", |
| details, testno); |
| } |
| else if (result_obj["directive"]) |
| { |
| details = details " # " result_obj["directive"]; |
| if (length(result_obj["explanation"])) |
| details = details " " result_obj["explanation"] |
| } |
| |
| report(stringify_result_obj(result_obj), details) |
| } |
| |
| |
| function handle_tap_plan(planned, skip_reason) |
| { |
| planned += 0 |
| if (length(skip_reason) && planned > 0) |
| abort("in function handle_tap_plan()") |
| if (plan_seen) |
| { |
| |
| testsuite_error("multiple test plans") |
| return; |
| } |
| planned_tests = planned |
| |
| |
| |
| |
| |
| plan_seen = (testno >= 1 ? LATE_PLAN : EARLY_PLAN) |
| |
| |
| |
| |
| |
| |
| if (planned == 0 && testno == 0) |
| { |
| if (length(skip_reason)) |
| skip_reason = "- " skip_reason; |
| report("SKIP", skip_reason); |
| } |
| } |
| |
| function extract_tap_comment(line) |
| { |
| if (index(line, diag_string) == 1) |
| { |
| |
| line = substr(line, length(diag_string) + 1) |
| |
| sub("^[ \t]*", "", line) |
| sub("[ \t]*$", "", line) |
| |
| return line; |
| } |
| return ""; |
| } |
| |
| |
| |
| function setup_result_obj(line) |
| { |
| |
| result_obj["is_ok"] = (substr(line, 1, 2) == "ok" ? 1 : 0) |
| sub("^(not )?ok[ \t]*", "", line) |
| |
| |
| |
| if (line ~ /^[0-9]+$/ || line ~ /^[0-9]+[^a-zA-Z0-9_]/) |
| { |
| match(line, "^[0-9]+") |
| |
| result_obj["number"] = substr(line, 1, RLENGTH) + 0 |
| line = substr(line, RLENGTH + 1) |
| } |
| else |
| { |
| result_obj["number"] = testno |
| } |
| |
| if (plan_seen == LATE_PLAN) |
| |
| |
| result_obj["is_unplanned"] = 1 |
| else if (plan_seen && testno > planned_tests) |
| result_obj["is_unplanned"] = 1 |
| else |
| result_obj["is_unplanned"] = 0 |
| |
| |
| sub("^[ \t]*", "", line) |
| sub("[ \t]*$", "", line) |
| |
| |
| result_obj["description"] = line |
| result_obj["directive"] = "" |
| result_obj["explanation"] = "" |
| |
| if (index(line, "#") == 0) |
| return |
| |
| |
| rx = "[ \t]*#[ \t]*([tT][oO][dD][oO]|[sS][kK][iI][pP])[ \t]*" |
| |
| |
| pos = match(line, rx "$") |
| if (!pos) |
| pos = match(line, rx "[^a-zA-Z0-9_]") |
| |
| |
| if (!pos) |
| return |
| |
| |
| |
| |
| |
| |
| if (substr(line, pos, 1) == "#") |
| { |
| bslash_count = 0 |
| for (i = pos; i > 1 && substr(line, i - 1, 1) == "\\"; i--) |
| bslash_count += 1 |
| if (bslash_count % 2) |
| return |
| } |
| |
| |
| |
| result_obj["description"] = substr(line, 1, pos - 1) |
| |
| |
| line = substr(line, pos) |
| |
| sub("^[ \t]*#[ \t]*", "", line) |
| result_obj["directive"] = toupper(substr(line, 1, 4)) |
| line = substr(line, 5) |
| |
| |
| sub("^[ \t]*", "", line) |
| sub("[ \t]*$", "", line) |
| result_obj["explanation"] = line |
| } |
| |
| function get_test_exit_message(status) |
| { |
| if (status == 0) |
| return "" |
| if (status !~ /^[1-9][0-9]*$/) |
| abort("getting exit status") |
| if (status < 127) |
| exit_details = "" |
| else if (status == 127) |
| exit_details = " (command not found?)" |
| else if (status >= 128 && status <= 255) |
| exit_details = sprintf(" (terminated by signal %d?)", status - 128) |
| else if (status > 256 && status <= 384) |
| |
| |
| |
| |
| |
| |
| exit_details = sprintf(" (terminated by signal %d?)", status - 256) |
| else |
| |
| exit_details = " (abnormal termination)" |
| return sprintf("exited with status %d%s", status, exit_details) |
| } |
| |
| function write_test_results() |
| { |
| print ":global-test-result: " get_global_test_result() > trs_file |
| print ":recheck: " yn(must_recheck()) > trs_file |
| print ":copy-in-global-log: " yn(copy_in_global_log()) > trs_file |
| for (i = 0; i < test_results_index; i += 1) |
| print ":test-result: " test_results_list[i] > trs_file |
| close(trs_file); |
| } |
| |
| BEGIN { |
| |
| |
| |
| |
| |
| '"$init_colors"' |
| |
| |
| planned_tests = 0 |
| |
| COOKED_PASS = expect_failure ? "XPASS": "PASS"; |
| COOKED_FAIL = expect_failure ? "XFAIL": "FAIL"; |
| |
| |
| |
| |
| NO_PLAN = 0 |
| EARLY_PLAN = 1 |
| LATE_PLAN = 2 |
| |
| testno = 0 |
| bailed_out = 0 |
| |
| |
| |
| plan_seen = NO_PLAN |
| |
| |
| |
| |
| |
| is_first_read = 1 |
| |
| while (1) |
| { |
| |
| |
| st = getline |
| if (st < 0) |
| fatal("I/O error while reading from input stream") |
| else if (st == 0) |
| { |
| if (is_first_read) |
| abort("in input loop: only one input line") |
| break |
| } |
| if (is_first_read) |
| { |
| is_first_read = 0 |
| nextline = $0 |
| continue |
| } |
| else |
| { |
| curline = nextline |
| nextline = $0 |
| $0 = curline |
| } |
| |
| print | "cat >&3" |
| |
| if (bailed_out) |
| continue |
| |
| |
| if ($0 ~ /^(not )?ok$/ || $0 ~ /^(not )?ok[^a-zA-Z0-9_]/) |
| { |
| testno += 1 |
| setup_result_obj($0) |
| handle_tap_result() |
| } |
| |
| else if ($0 ~ /^1\.\.[0-9]+[ \t]*$/) |
| { |
| |
| sub("^1\\.\\.", "") |
| sub("[^0-9]*$", "") |
| handle_tap_plan($0, "") |
| continue |
| } |
| |
| else if ($0 ~ /^1\.\.0+[ \t]* |
| { |
| |
| |
| |
| |
| sub("^[^#]*#[ \t]*(SKIP[: \t][ \t]*)?", "") |
| sub("[ \t]*$", ""); |
| handle_tap_plan(0, $0) |
| } |
| |
| |
| |
| |
| |
| else if ($0 ~ /^[ \t]*Bail out!/) |
| { |
| bailed_out = 1 |
| |
| |
| sub("^[ \t]*Bail out![ \t]*", ""); |
| sub("[ \t]*$", ""); |
| |
| bailout_message = "Bail out!" |
| if (length($0)) |
| bailout_message = bailout_message " " $0 |
| testsuite_error(bailout_message) |
| } |
| |
| else if (comments != 0) |
| { |
| comment = extract_tap_comment($0); |
| if (length(comment)) |
| report("#", comment); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| if (!bailed_out) |
| { |
| if (!plan_seen) |
| { |
| testsuite_error("missing test plan") |
| } |
| else if (planned_tests != testno) |
| { |
| bad_amount = testno > planned_tests ? "many" : "few" |
| testsuite_error(sprintf("too %s tests run (expected %d, got %d)", |
| bad_amount, planned_tests, testno)) |
| } |
| if (!ignore_exit) |
| { |
| |
| exit_message = get_test_exit_message(nextline) |
| if (exit_message) |
| testsuite_error(exit_message) |
| } |
| } |
| |
| write_test_results() |
| |
| exit 0 |
| |
| } |
| ' |
| |
| |
| } 3>"$log_file" |
| |
| test $? -eq 0 || fatal "I/O or internal error" |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |