git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 18/20] t0210: refactor trace2 scrubbing to not use Perl

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 27, 2025, 10:37 UTC
Message-ID
<20250327-b4-pks-t-perlless-v3-18-b436de9da1b8@pks.im>
In-Reply-To
<20250327-b4-pks-t-perlless-v3-0-b436de9da1b8@pks.im>

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 <ps@pks.im>
---
 t/t0210-trace2-normal.sh  | 61 +++++++++++++++++++++++++++++++++--------------
 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 ba4c0442b85..96c68f65df2 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 7cc4de392a0..00000000000
--- 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";
-    }
-}
-- 
2.49.0.472.ge94155a9ec.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 94 of 125 in “t: drop Perl as a mandatory prerequisite”
  1. 00/20 t: drop Perl as a mandatory prerequisitePatrick Steinhardt, Mar 20, 2025
  2. 01/20 t: skip chain lint when PERL_PATH is unsetPatrick Steinhardt, Mar 20, 2025
  3. Eric SunshineMar 20, 2025
  4. 02/20 t: refactor environment sanitization to not use PerlPatrick Steinhardt, Mar 20, 2025
  5. Karthik NayakMar 21, 2025
  6. 03/20 t: adapt character translation helpers to not use PerlPatrick Steinhardt, Mar 20, 2025
  7. 04/20 t: adapt `test_copy_bytes()` to not use PerlPatrick Steinhardt, Mar 20, 2025
  8. Karthik NayakMar 21, 2025
  9. 05/20 t: adapt `test_readlink()` to not use PerlPatrick Steinhardt, Mar 20, 2025
  10. 06/20 t: introduce PERL_TEST_HELPERS prerequisitePatrick Steinhardt, Mar 20, 2025
  11. Eric SunshineMar 20, 2025
  12. Patrick SteinhardtMar 24, 2025
  13. 07/20 t: adapt existing PERL prerequisitesPatrick Steinhardt, Mar 20, 2025
  14. 08/20 meson: stop requiring Perl when tests are enabledPatrick Steinhardt, Mar 20, 2025
  15. 09/20 Makefile: stop requiring Perl when running testsPatrick Steinhardt, Mar 20, 2025
  16. 11/20 t: refactor tests depending on Perl substitution operatorPatrick Steinhardt, Mar 20, 2025
  17. Phillip WoodMar 24, 2025
  18. 10/20 t: refactor tests depending on Perl transliteration operatorPatrick Steinhardt, Mar 20, 2025
  19. 13/20 t: refactor tests depending on Perl for textconv scriptsPatrick Steinhardt, Mar 20, 2025
  20. Eric SunshineMar 20, 2025
  21. Patrick SteinhardtMar 24, 2025
  22. Eric SunshineMar 24, 2025
  23. Patrick SteinhardtMar 25, 2025
  24. Phillip WoodMar 24, 2025
  25. Patrick SteinhardtMar 25, 2025
  26. 12/20 t: refactor tests depending on Perl to print dataPatrick Steinhardt, Mar 20, 2025
  27. Eric SunshineMar 20, 2025
  28. Patrick SteinhardtMar 24, 2025
  29. 14/20 t/lib-gpg: refactor `sanitize_pgp()` to not depend on PerlPatrick Steinhardt, Mar 20, 2025
  30. 15/20 t/lib-t6000: refactor `name_from_description()` to not depend on PerlPatrick Steinhardt, Mar 20, 2025
  31. Eric SunshineMar 20, 2025
  32. Patrick SteinhardtMar 24, 2025
  33. 16/20 t/lib-httpd: refactor "one-time-perl" CGI script to not depend on PerlPatrick Steinhardt, Mar 20, 2025
  34. 17/20 t0021: refactor `generate_random_characters()` to not depend on PerlPatrick Steinhardt, Mar 20, 2025
  35. 18/20 t0210: refactor trace2 scrubbing to not use PerlPatrick Steinhardt, Mar 20, 2025
  36. 19/20 t5316: refactor `max_chain()` to not depend on PerlPatrick Steinhardt, Mar 20, 2025
  37. 20/20 t5703: refactor test to not depend on PerlPatrick Steinhardt, Mar 20, 2025
  38. 00/20 t: drop Perl as a mandatory prerequisitePatrick Steinhardt, Mar 25, 2025
  39. 01/20 t: skip chain lint when PERL_PATH is unsetPatrick Steinhardt, Mar 25, 2025
  40. 02/20 t: refactor environment sanitization to not use PerlPatrick Steinhardt, Mar 25, 2025
  41. 03/20 t: adapt character translation helpers to not use PerlPatrick Steinhardt, Mar 25, 2025
  42. 05/20 t: adapt `test_readlink()` to not use PerlPatrick Steinhardt, Mar 25, 2025
  43. 04/20 t: adapt `test_copy_bytes()` to not use PerlPatrick Steinhardt, Mar 25, 2025
  44. 06/20 t: introduce PERL_TEST_HELPERS prerequisitePatrick Steinhardt, Mar 25, 2025
  45. 08/20 meson: stop requiring Perl when tests are enabledPatrick Steinhardt, Mar 25, 2025
  46. 07/20 t: adapt existing PERL prerequisitesPatrick Steinhardt, Mar 25, 2025
  47. 09/20 Makefile: stop requiring Perl when running testsPatrick Steinhardt, Mar 25, 2025
  48. 10/20 t: refactor tests depending on Perl transliteration operatorPatrick Steinhardt, Mar 25, 2025
  49. 11/20 t: refactor tests depending on Perl substitution operatorPatrick Steinhardt, Mar 25, 2025
  50. Phillip WoodMar 25, 2025
  51. Patrick SteinhardtMar 27, 2025
  52. 13/20 t: refactor tests depending on Perl for textconv scriptsPatrick Steinhardt, Mar 25, 2025
  53. 12/20 t: refactor tests depending on Perl to print dataPatrick Steinhardt, Mar 25, 2025
  54. 14/20 t/lib-gpg: refactor `sanitize_pgp()` to not depend on PerlPatrick Steinhardt, Mar 25, 2025
  55. 15/20 t/lib-t6000: refactor `name_from_description()` to not depend on PerlPatrick Steinhardt, Mar 25, 2025
  56. 16/20 t/lib-httpd: refactor "one-time-perl" CGI script to not depend on PerlPatrick Steinhardt, Mar 25, 2025
  57. 17/20 t0021: refactor `generate_random_characters()` to not depend on PerlPatrick Steinhardt, Mar 25, 2025
  58. 18/20 t0210: refactor trace2 scrubbing to not use PerlPatrick Steinhardt, Mar 25, 2025
  59. 19/20 t5316: refactor `max_chain()` to not depend on PerlPatrick Steinhardt, Mar 25, 2025
  60. 20/20 t5703: refactor test to not depend on PerlPatrick Steinhardt, Mar 25, 2025
  61. 00/20 t: drop Perl as a mandatory prerequisitePatrick Steinhardt, Mar 27, 2025
  62. 01/20 t: skip chain lint when PERL_PATH is unsetPatrick Steinhardt, Mar 27, 2025
  63. 03/20 t: adapt character translation helpers to not use PerlPatrick Steinhardt, Mar 27, 2025
  64. 02/20 t: refactor environment sanitization to not use PerlPatrick Steinhardt, Mar 27, 2025
  65. 04/20 t: adapt `test_copy_bytes()` to not use PerlPatrick Steinhardt, Mar 27, 2025
  66. 05/20 t: adapt `test_readlink()` to not use PerlPatrick Steinhardt, Mar 27, 2025
  67. 07/20 t: adapt existing PERL prerequisitesPatrick Steinhardt, Mar 27, 2025
  68. 06/20 t: introduce PERL_TEST_HELPERS prerequisitePatrick Steinhardt, Mar 27, 2025
  69. Johannes SchindelinApr 1, 2025
  70. Patrick SteinhardtApr 2, 2025
  71. Johannes SchindelinApr 2, 2025
  72. Patrick SteinhardtApr 3, 2025
  73. 09/20 Makefile: stop requiring Perl when running testsPatrick Steinhardt, Mar 27, 2025
  74. 08/20 meson: stop requiring Perl when tests are enabledPatrick Steinhardt, Mar 27, 2025
  75. 10/20 t: refactor tests depending on Perl transliteration operatorPatrick Steinhardt, Mar 27, 2025
  76. 11/20 t: refactor tests depending on Perl substitution operatorPatrick Steinhardt, Mar 27, 2025
  77. Johannes SchindelinApr 1, 2025
  78. Patrick SteinhardtApr 2, 2025
  79. 12/20 t: refactor tests depending on Perl to print dataPatrick Steinhardt, Mar 27, 2025
  80. Johannes SchindelinApr 1, 2025
  81. Patrick SteinhardtApr 2, 2025
  82. 13/20 t: refactor tests depending on Perl for textconv scriptsPatrick Steinhardt, Mar 27, 2025
  83. Johannes SchindelinApr 1, 2025
  84. Patrick SteinhardtApr 2, 2025
  85. Johannes SchindelinApr 2, 2025
  86. 14/20 t/lib-gpg: refactor `sanitize_pgp()` to not depend on PerlPatrick Steinhardt, Mar 27, 2025
  87. Johannes SchindelinApr 1, 2025
  88. Patrick SteinhardtApr 2, 2025
  89. 15/20 t/lib-t6000: refactor `name_from_description()` to not depend on PerlPatrick Steinhardt, Mar 27, 2025
  90. 16/20 t/lib-httpd: refactor "one-time-perl" CGI script to not depend on PerlPatrick Steinhardt, Mar 27, 2025
  91. 17/20 t0021: refactor `generate_random_characters()` to not depend on PerlPatrick Steinhardt, Mar 27, 2025
  92. Johannes SchindelinApr 1, 2025
  93. Patrick SteinhardtApr 2, 2025
  94. 18/20 t0210: refactor trace2 scrubbing to not use PerlPatrick Steinhardt, Mar 27, 2025
  95. 19/20 t5316: refactor `max_chain()` to not depend on PerlPatrick Steinhardt, Mar 27, 2025
  96. 20/20 t5703: refactor test to not depend on PerlPatrick Steinhardt, Mar 27, 2025
  97. Phillip WoodMar 28, 2025
  98. Johannes SchindelinApr 2, 2025
  99. 00/20 t: drop Perl as a mandatory prerequisitePatrick Steinhardt, Apr 3, 2025
  100. 01/20 t: skip chain lint when PERL_PATH is unsetPatrick Steinhardt, Apr 3, 2025
  101. 02/20 t: refactor environment sanitization to not use PerlPatrick Steinhardt, Apr 3, 2025
  102. 03/20 t: adapt character translation helpers to not use PerlPatrick Steinhardt, Apr 3, 2025
  103. 04/20 t: adapt `test_copy_bytes()` to not use PerlPatrick Steinhardt, Apr 3, 2025
  104. 05/20 t: adapt `test_readlink()` to not use PerlPatrick Steinhardt, Apr 3, 2025
  105. 06/20 t: introduce PERL_TEST_HELPERS prerequisitePatrick Steinhardt, Apr 3, 2025
  106. 07/20 t: adapt existing PERL prerequisitesPatrick Steinhardt, Apr 3, 2025
  107. 08/20 meson: stop requiring Perl when tests are enabledPatrick Steinhardt, Apr 3, 2025
  108. 09/20 Makefile: stop requiring Perl when running testsPatrick Steinhardt, Apr 3, 2025
  109. 10/20 t: refactor tests depending on Perl transliteration operatorPatrick Steinhardt, Apr 3, 2025
  110. 11/20 t: refactor tests depending on Perl substitution operatorPatrick Steinhardt, Apr 3, 2025
  111. 13/20 t: refactor tests depending on Perl for textconv scriptsPatrick Steinhardt, Apr 3, 2025
  112. 14/20 t/lib-gpg: refactor `sanitize_pgp()` to not depend on PerlPatrick Steinhardt, Apr 3, 2025
  113. 12/20 t: refactor tests depending on Perl to print dataPatrick Steinhardt, Apr 3, 2025
  114. SZEDER GáborJun 10, 2025
  115. Junio C HamanoJun 10, 2025
  116. Patrick SteinhardtJul 7, 2025
  117. Junio C HamanoJun 10, 2025
  118. 15/20 t/lib-t6000: refactor `name_from_description()` to not depend on PerlPatrick Steinhardt, Apr 3, 2025
  119. 17/20 t0021: refactor `generate_random_characters()` to not depend on PerlPatrick Steinhardt, Apr 3, 2025
  120. 16/20 t/lib-httpd: refactor "one-time-perl" CGI script to not depend on PerlPatrick Steinhardt, Apr 3, 2025
  121. 18/20 t0210: refactor trace2 scrubbing to not use PerlPatrick Steinhardt, Apr 3, 2025
  122. 19/20 t5316: refactor `max_chain()` to not depend on PerlPatrick Steinhardt, Apr 3, 2025
  123. 20/20 t5703: refactor test to not depend on PerlPatrick Steinhardt, Apr 3, 2025
  124. Johannes SchindelinApr 3, 2025
  125. Junio C HamanoApr 8, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.