Skip to content

Commit 9f4bce3

Browse files
pks-tgitster
authored andcommitted
t0210: refactor trace2 scrubbing to not use Perl
The output generated by our trace2 mechanism contains several fields that are dependent on the environment they're being run in, which makes it somewhat harder to test it. As a countermeasure we scrub the output and strip out any fields that contain such information. The logic to do so is implemented in Perl, but it can be trivially ported to instead use sed(1). Refactor the code accordingly so that we can drop the PERL_TEST_HELPERS prerequisite. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 88ed7b8 commit 9f4bce3

File tree

2 files changed

+43
-72
lines changed

2 files changed

+43
-72
lines changed

t/t0210-trace2-normal.sh

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ test_description='test trace2 facility (normal target)'
44

55
. ./test-lib.sh
66

7-
if ! test_have_prereq PERL_TEST_HELPERS
8-
then
9-
skip_all='skipping trace2 tests; Perl not available'
10-
test_done
11-
fi
12-
137
# Turn off any inherited trace2 settings for this test.
148
sane_unset GIT_TRACE2 GIT_TRACE2_PERF GIT_TRACE2_EVENT
159
sane_unset GIT_TRACE2_BRIEF
@@ -59,10 +53,41 @@ GIT_TRACE2_BRIEF=1 && export GIT_TRACE2_BRIEF
5953
#
6054
# Implicit return from cmd_<verb> function propagates <code>.
6155

56+
scrub_normal () {
57+
# Scrub the variable fields from the normal trace2 output to make
58+
# testing easier:
59+
#
60+
# 1. Various messages include an elapsed time in the middle of the
61+
# message. Replace the time with a placeholder to simplify our
62+
# HEREDOC in the test script.
63+
#
64+
# 2. We expect:
65+
#
66+
# start <argv0> [<argv1> [<argv2> [...]]]
67+
#
68+
# where argv0 might be a relative or absolute path, with or
69+
# without quotes, and platform dependent. Replace argv0 with a
70+
# token for HEREDOC matching in the test script.
71+
#
72+
# 3. Likewise, the 'cmd_path' message breaks out argv[0].
73+
#
74+
# This line is only emitted when RUNTIME_PREFIX is defined,
75+
# so just omit it for testing purposes.
76+
#
77+
# 4. 'cmd_ancestry' is not implemented everywhere, so for portability's
78+
# sake, skip it when parsing normal.
79+
sed \
80+
-e 's/elapsed:[0-9]*\.[0-9][0-9]*\([eE][-+]\{0,1\}[0-9][0-9]*\)\{0,1\}/elapsed:_TIME_/g' \
81+
-e "s/^start '[^']*' \(.*\)/start _EXE_ \1/" \
82+
-e 's/^start [^ ][^ ]* \(.*\)/start _EXE_ \1/' \
83+
-e '/^cmd_path/d' \
84+
-e '/^cmd_ancestry/d'
85+
}
86+
6287
test_expect_success 'normal stream, return code 0' '
6388
test_when_finished "rm trace.normal actual expect" &&
6489
GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 001return 0 &&
65-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
90+
scrub_normal <trace.normal >actual &&
6691
cat >expect <<-EOF &&
6792
version $V
6893
start _EXE_ trace2 001return 0
@@ -76,7 +101,7 @@ test_expect_success 'normal stream, return code 0' '
76101
test_expect_success 'normal stream, return code 1' '
77102
test_when_finished "rm trace.normal actual expect" &&
78103
test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 001return 1 &&
79-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
104+
scrub_normal <trace.normal >actual &&
80105
cat >expect <<-EOF &&
81106
version $V
82107
start _EXE_ trace2 001return 1
@@ -91,7 +116,7 @@ test_expect_success 'automatic filename' '
91116
test_when_finished "rm -r traces actual expect" &&
92117
mkdir traces &&
93118
GIT_TRACE2="$(pwd)/traces" test-tool trace2 001return 0 &&
94-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <"$(ls traces/*)" >actual &&
119+
scrub_normal <"$(ls traces/*)" >actual &&
95120
cat >expect <<-EOF &&
96121
version $V
97122
start _EXE_ trace2 001return 0
@@ -109,7 +134,7 @@ test_expect_success 'automatic filename' '
109134
test_expect_success 'normal stream, exit code 0' '
110135
test_when_finished "rm trace.normal actual expect" &&
111136
GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 002exit 0 &&
112-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
137+
scrub_normal <trace.normal >actual &&
113138
cat >expect <<-EOF &&
114139
version $V
115140
start _EXE_ trace2 002exit 0
@@ -123,7 +148,7 @@ test_expect_success 'normal stream, exit code 0' '
123148
test_expect_success 'normal stream, exit code 1' '
124149
test_when_finished "rm trace.normal actual expect" &&
125150
test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 002exit 1 &&
126-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
151+
scrub_normal <trace.normal >actual &&
127152
cat >expect <<-EOF &&
128153
version $V
129154
start _EXE_ trace2 002exit 1
@@ -141,7 +166,7 @@ test_expect_success 'normal stream, exit code 1' '
141166
test_expect_success 'normal stream, error event' '
142167
test_when_finished "rm trace.normal actual expect" &&
143168
GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 003error "hello world" "this is a test" &&
144-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
169+
scrub_normal <trace.normal >actual &&
145170
cat >expect <<-EOF &&
146171
version $V
147172
start _EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\''
@@ -161,7 +186,7 @@ test_expect_success 'normal stream, error event' '
161186
test_expect_success 'BUG messages are written to trace2' '
162187
test_when_finished "rm trace.normal actual expect" &&
163188
test_must_fail env GIT_TRACE2="$(pwd)/trace.normal" test-tool trace2 007bug &&
164-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
189+
scrub_normal <trace.normal >actual &&
165190
cat >expect <<-EOF &&
166191
version $V
167192
start _EXE_ trace2 007bug
@@ -185,7 +210,7 @@ test_expect_success 'bug messages with BUG_if_bug() are written to trace2' '
185210
sed "s/^.*: //" <err >actual &&
186211
test_cmp expect actual &&
187212
188-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
213+
scrub_normal <trace.normal >actual &&
189214
cat >expect <<-EOF &&
190215
version $V
191216
start _EXE_ trace2 008bug
@@ -211,7 +236,7 @@ test_expect_success 'bug messages without explicit BUG_if_bug() are written to t
211236
sed "s/^.*: //" <err >actual &&
212237
test_cmp expect actual &&
213238
214-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
239+
scrub_normal <trace.normal >actual &&
215240
cat >expect <<-EOF &&
216241
version $V
217242
start _EXE_ trace2 009bug_BUG
@@ -236,7 +261,7 @@ test_expect_success 'bug messages followed by BUG() are written to trace2' '
236261
sed "s/^.*: //" <err >actual &&
237262
test_cmp expect actual &&
238263
239-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
264+
scrub_normal <trace.normal >actual &&
240265
cat >expect <<-EOF &&
241266
version $V
242267
start _EXE_ trace2 010bug_BUG
@@ -268,7 +293,7 @@ test_expect_success 'using global config, normal stream, return code 0' '
268293
test_config_global trace2.normalBrief 1 &&
269294
test_config_global trace2.normalTarget "$(pwd)/trace.normal" &&
270295
test-tool trace2 001return 0 &&
271-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
296+
scrub_normal <trace.normal >actual &&
272297
cat >expect <<-EOF &&
273298
version $V
274299
start _EXE_ trace2 001return 0
@@ -286,7 +311,7 @@ test_expect_success 'using global config with include' '
286311
mv "$(pwd)/.gitconfig" "$(pwd)/real.gitconfig" &&
287312
test_config_global include.path "$(pwd)/real.gitconfig" &&
288313
test-tool trace2 001return 0 &&
289-
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
314+
scrub_normal <trace.normal >actual &&
290315
cat >expect <<-EOF &&
291316
version $V
292317
start _EXE_ trace2 001return 0

t/t0210/scrub_normal.perl

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)