diff options
| -rwxr-xr-x | t/t0210-trace2-normal.sh | 61 | ||||
| -rw-r--r-- | t/t0210/scrub_normal.perl | 54 |
2 files changed, 43 insertions, 72 deletions
diff --git a/t/t0210-trace2-normal.sh b/t/t0210-trace2-normal.sh index ba4c0442b8..96c68f65df 100755 --- a/t/t0210-trace2-normal.sh +++ b/t/t0210-trace2-normal.sh @@ -4,12 +4,6 @@ test_description='test trace2 facility (normal target)' . ./test-lib.sh -if ! test_have_prereq PERL_TEST_HELPERS -then - skip_all='skipping trace2 tests; Perl not available' - test_done -fi - # Turn off any inherited trace2 settings for this test. sane_unset GIT_TRACE2 GIT_TRACE2_PERF GIT_TRACE2_EVENT sane_unset GIT_TRACE2_BRIEF @@ -59,10 +53,41 @@ GIT_TRACE2_BRIEF=1 && export GIT_TRACE2_BRIEF # # Implicit return from cmd_<verb> function propagates <code>. +scrub_normal () { + # Scrub the variable fields from the normal trace2 output to make + # testing easier: + # + # 1. Various messages include an elapsed time in the middle of the + # message. Replace the time with a placeholder to simplify our + # HEREDOC in the test script. + # + # 2. We expect: + # + # start <argv0> [<argv1> [<argv2> [...]]] + # + # where argv0 might be a relative or absolute path, with or + # without quotes, and platform dependent. Replace argv0 with a + # token for HEREDOC matching in the test script. + # + # 3. Likewise, the 'cmd_path' message breaks out argv[0]. + # + # This line is only emitted when RUNTIME_PREFIX is defined, + # so just omit it for testing purposes. + # + # 4. 'cmd_ancestry' is not implemented everywhere, so for portability's + # sake, skip it when parsing normal. + sed \ + -e 's/elapsed:[0-9]*\.[0-9][0-9]*\([eE][-+]\{0,1\}[0-9][0-9]*\)\{0,1\}/elapsed:_TIME_/g' \ + -e "s/^start '[^']*' \(.*\)/start _EXE_ \1/" \ + -e 's/^start [^ ][^ ]* \(.*\)/start _EXE_ \1/' \ + -e '/^cmd_path/d' \ + -e '/^cmd_ancestry/d' +} + test_expect_success 'normal stream, return code 0' ' test_when_finished "rm trace.normal actual expect" && GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 001return 0 && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + scrub_normal <trace.normal >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 001return 0 @@ -76,7 +101,7 @@ test_expect_success 'normal stream, return code 0' ' test_expect_success 'normal stream, return code 1' ' test_when_finished "rm trace.normal actual expect" && test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 001return 1 && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + scrub_normal <trace.normal >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 001return 1 @@ -91,7 +116,7 @@ test_expect_success 'automatic filename' ' test_when_finished "rm -r traces actual expect" && mkdir traces && GIT_TRACE2="$(pwd)/traces" test-tool trace2 001return 0 && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <"$(ls traces/*)" >actual && + scrub_normal <"$(ls traces/*)" >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 001return 0 @@ -109,7 +134,7 @@ test_expect_success 'automatic filename' ' test_expect_success 'normal stream, exit code 0' ' test_when_finished "rm trace.normal actual expect" && GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 002exit 0 && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + scrub_normal <trace.normal >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 002exit 0 @@ -123,7 +148,7 @@ test_expect_success 'normal stream, exit code 0' ' test_expect_success 'normal stream, exit code 1' ' test_when_finished "rm trace.normal actual expect" && test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 002exit 1 && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + scrub_normal <trace.normal >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 002exit 1 @@ -141,7 +166,7 @@ test_expect_success 'normal stream, exit code 1' ' test_expect_success 'normal stream, error event' ' test_when_finished "rm trace.normal actual expect" && GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 003error "hello world" "this is a test" && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + scrub_normal <trace.normal >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\'' @@ -161,7 +186,7 @@ test_expect_success 'normal stream, error event' ' test_expect_success 'BUG messages are written to trace2' ' test_when_finished "rm trace.normal actual expect" && test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 007bug && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + scrub_normal <trace.normal >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 007bug @@ -185,7 +210,7 @@ test_expect_success 'bug messages with BUG_if_bug() are written to trace2' ' sed "s/^.*: //" <err >actual && test_cmp expect actual && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + scrub_normal <trace.normal >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 008bug @@ -211,7 +236,7 @@ test_expect_success 'bug messages without explicit BUG_if_bug() are written to t sed "s/^.*: //" <err >actual && test_cmp expect actual && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + scrub_normal <trace.normal >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 009bug_BUG @@ -236,7 +261,7 @@ test_expect_success 'bug messages followed by BUG() are written to trace2' ' sed "s/^.*: //" <err >actual && test_cmp expect actual && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + scrub_normal <trace.normal >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 010bug_BUG @@ -268,7 +293,7 @@ test_expect_success 'using global config, normal stream, return code 0' ' test_config_global trace2.normalBrief 1 && test_config_global trace2.normalTarget "$(pwd)/trace.normal" && test-tool trace2 001return 0 && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + scrub_normal <trace.normal >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 001return 0 @@ -286,7 +311,7 @@ test_expect_success 'using global config with include' ' mv "$(pwd)/.gitconfig" "$(pwd)/real.gitconfig" && test_config_global include.path "$(pwd)/real.gitconfig" && test-tool trace2 001return 0 && - perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual && + scrub_normal <trace.normal >actual && cat >expect <<-EOF && version $V start _EXE_ trace2 001return 0 diff --git a/t/t0210/scrub_normal.perl b/t/t0210/scrub_normal.perl deleted file mode 100644 index 7cc4de392a..0000000000 --- a/t/t0210/scrub_normal.perl +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/perl -# -# Scrub the variable fields from the normal trace2 output to -# make testing easier. - -use strict; -use warnings; - -my $float = '[0-9]*\.[0-9]+([eE][-+]?[0-9]+)?'; - -# This code assumes that the trace2 data was written with bare -# turned on (which omits the "<clock> <file>:<line>" prefix. - -while (<>) { - # Various messages include an elapsed time in the middle - # of the message. Replace the time with a placeholder to - # simplify our HEREDOC in the test script. - s/elapsed:$float/elapsed:_TIME_/g; - - my $line = $_; - - # we expect: - # start <argv0> [<argv1> [<argv2> [...]]] - # - # where argv0 might be a relative or absolute path, with - # or without quotes, and platform dependent. Replace argv0 - # with a token for HEREDOC matching in the test script. - - if ($line =~ m/^start/) { - $line =~ /^start\s+(.*)/; - my $argv = $1; - $argv =~ m/(\'[^\']*\'|[^ ]+)\s+(.*)/; - my $argv_0 = $1; - my $argv_rest = $2; - - print "start _EXE_ $argv_rest\n"; - } - elsif ($line =~ m/^cmd_path/) { - # Likewise, the 'cmd_path' message breaks out argv[0]. - # - # This line is only emitted when RUNTIME_PREFIX is defined, - # so just omit it for testing purposes. - # print "cmd_path _EXE_\n"; - } - elsif ($line =~ m/^cmd_ancestry/) { - # 'cmd_ancestry' is not implemented everywhere, so for portability's - # sake, skip it when parsing normal. - # - # print "$line"; - } - else { - print "$line"; - } -} |
