. ./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
#
# 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
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
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
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
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
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'\''
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
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
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
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
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
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
+++ /dev/null
-#!/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";
- }
-}