Skip to content

Commit fcf1027

Browse files
committed
t0211: Demonstrate missing 'def_param' events for certain commands
Some Git commands fail to emit 'def_param' events for interesting config and environment variable settings. Add unit tests to demonstrate this. Most commands are considered "builtin" and are based upon git.c. These typically do emit 'def_param' events. Exceptions are some of the "query" commands, the "run-dashed" mechanism, and alias handling. Commands built from remote-curl.c (instead of git.c), such as "git-remote-https", do not emit 'def_param' events. Likewise, "git-http-fetch" is built http-fetch.c and does not emit them. Signed-off-by: Jeff Hostetler <[email protected]>
1 parent 0f9d4d2 commit fcf1027

File tree

1 file changed

+225
-0
lines changed

1 file changed

+225
-0
lines changed

t/t0211-trace2-perf.sh

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,229 @@ test_expect_success 'unsafe URLs are redacted by default' '
287287
grep "d0|main|def_param|.*|remote.origin.url:https://user:[email protected]" actual
288288
'
289289

290+
# Confirm that the requested command produces a "cmd_name" and a
291+
# set of "def_param" events.
292+
#
293+
try_simple () {
294+
test_when_finished "rm prop.perf actual" &&
295+
296+
cmd=$1 &&
297+
cmd_name=$2 &&
298+
299+
test_config_global "trace2.configParams" "cfg.prop.*" &&
300+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
301+
302+
test_config_global "cfg.prop.foo" "red" &&
303+
304+
ENV_PROP_FOO=blue \
305+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
306+
$cmd &&
307+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
308+
grep "d0|main|cmd_name|.*|$cmd_name" actual &&
309+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
310+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual
311+
}
312+
313+
# Representative mainstream builtin Git command dispatched
314+
# in run_builtin() in git.c
315+
#
316+
test_expect_success 'expect def_params for normal builtin command' '
317+
try_simple "git version" "version"
318+
'
319+
320+
# Representative query command dispatched in handle_options()
321+
# in git.c
322+
#
323+
test_expect_failure 'expect def_params for query command' '
324+
try_simple "git --man-path" "_query_"
325+
'
326+
327+
# remote-curl.c does not use the builtin setup in git.c, so confirm
328+
# that executables built from remote-curl.c emit def_params.
329+
#
330+
# Also tests the dashed-command handling where "git foo" silently
331+
# spawns "git-foo". Make sure that both commands should emit
332+
# def_params.
333+
#
334+
# Pass bogus arguments to remote-https and allow the command to fail
335+
# because we don't actually have a remote to fetch from. We just want
336+
# to see the run-dashed code run and an executable built from
337+
# remote-curl.c rather than git.c
338+
#
339+
test_expect_failure 'expect def_params for remote-curl and _run_dashed_' '
340+
test_when_finished "rm prop.perf actual" &&
341+
342+
test_config_global "trace2.configParams" "cfg.prop.*" &&
343+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
344+
345+
test_config_global "cfg.prop.foo" "red" &&
346+
347+
ENV_PROP_FOO=blue \
348+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
349+
test_might_fail \
350+
git remote-http x y &&
351+
352+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
353+
354+
grep "d0|main|cmd_name|.*|_run_dashed_" actual &&
355+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
356+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
357+
358+
grep "d1|main|cmd_name|.*|remote-curl" actual &&
359+
grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
360+
grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
361+
'
362+
363+
test_expect_failure 'expect def_params for http-fetch and _run_dashed_' '
364+
test_when_finished "rm prop.perf actual" &&
365+
366+
test_config_global "trace2.configParams" "cfg.prop.*" &&
367+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
368+
369+
test_config_global "cfg.prop.foo" "red" &&
370+
371+
ENV_PROP_FOO=blue \
372+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
373+
test_might_fail \
374+
git http-fetch --stdin file:/// <<-EOF &&
375+
EOF
376+
377+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
378+
379+
grep "d0|main|cmd_name|.*|_run_dashed_" actual &&
380+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
381+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
382+
383+
grep "d1|main|cmd_name|.*|http-fetch" actual &&
384+
grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
385+
grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
386+
'
387+
388+
# Historically, alias expansion explicitly emitted the def_param
389+
# events (independent of whether the command was a builtin, a Git
390+
# command or arbitrary shell command) so that it wasn't dependent
391+
# upon the unpeeling of the alias. Let's make sure that we preserve
392+
# the net effect.
393+
#
394+
test_expect_success 'expect def_params during git alias expansion' '
395+
test_when_finished "rm prop.perf actual" &&
396+
397+
test_config_global "trace2.configParams" "cfg.prop.*" &&
398+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
399+
400+
test_config_global "cfg.prop.foo" "red" &&
401+
402+
test_config_global "alias.xxx" "version" &&
403+
404+
ENV_PROP_FOO=blue \
405+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
406+
git xxx &&
407+
408+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
409+
410+
# "git xxx" is first mapped to "git-xxx" and the child will fail.
411+
grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_)" actual &&
412+
413+
# We unpeel that and substitute "version" into "xxx" (giving
414+
# "git version") and update the cmd_name event.
415+
grep "d0|main|cmd_name|.*|_run_git_alias_ (_run_dashed_/_run_git_alias_)" actual &&
416+
417+
# These def_param events could be associated with either of the
418+
# above cmd_name events. It does not matter.
419+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
420+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
421+
422+
# The "git version" child sees a different cmd_name hierarchy.
423+
# Also test the def_param (only for completeness).
424+
grep "d1|main|cmd_name|.*|version (_run_dashed_/_run_git_alias_/version)" actual &&
425+
grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
426+
grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
427+
'
428+
429+
test_expect_success 'expect def_params during shell alias expansion' '
430+
test_when_finished "rm prop.perf actual" &&
431+
432+
test_config_global "trace2.configParams" "cfg.prop.*" &&
433+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
434+
435+
test_config_global "cfg.prop.foo" "red" &&
436+
437+
test_config_global "alias.xxx" "!git version" &&
438+
439+
ENV_PROP_FOO=blue \
440+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
441+
git xxx &&
442+
443+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
444+
445+
# "git xxx" is first mapped to "git-xxx" and the child will fail.
446+
grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_)" actual &&
447+
448+
# We unpeel that and substitute "git version" for "git xxx" (as a
449+
# shell command. Another cmd_name event is emitted as we unpeel.
450+
grep "d0|main|cmd_name|.*|_run_shell_alias_ (_run_dashed_/_run_shell_alias_)" actual &&
451+
452+
# These def_param events could be associated with either of the
453+
# above cmd_name events. It does not matter.
454+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
455+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
456+
457+
# We get the following only because we used a git command for the
458+
# shell command. In general, it could have been a shell script and
459+
# we would see nothing.
460+
#
461+
# The child knows the cmd_name hierarchy so it includes it.
462+
grep "d1|main|cmd_name|.*|version (_run_dashed_/_run_shell_alias_/version)" actual &&
463+
grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
464+
grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
465+
'
466+
467+
test_expect_failure 'expect def_params during nested git alias expansion' '
468+
test_when_finished "rm prop.perf actual" &&
469+
470+
test_config_global "trace2.configParams" "cfg.prop.*" &&
471+
test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
472+
473+
test_config_global "cfg.prop.foo" "red" &&
474+
475+
test_config_global "alias.xxx" "yyy" &&
476+
test_config_global "alias.yyy" "version" &&
477+
478+
ENV_PROP_FOO=blue \
479+
GIT_TRACE2_PERF="$(pwd)/prop.perf" \
480+
git xxx &&
481+
482+
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
483+
484+
# "git xxx" is first mapped to "git-xxx" and try to spawn "git-xxx"
485+
# and the child will fail.
486+
grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_)" actual &&
487+
grep "d0|main|child_start|.*|.* class:dashed argv:\[git-xxx\]" actual &&
488+
489+
# We unpeel that and substitute "yyy" into "xxx" (giving "git yyy")
490+
# and spawn "git-yyy" and the child will fail.
491+
grep "d0|main|alias|.*|alias:xxx argv:\[yyy\]" actual &&
492+
grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_/_run_dashed_)" actual &&
493+
grep "d0|main|child_start|.*|.* class:dashed argv:\[git-yyy\]" actual &&
494+
495+
# We unpeel that and substitute "version" into "xxx" (giving
496+
# "git version") and update the cmd_name event.
497+
grep "d0|main|alias|.*|alias:yyy argv:\[version\]" actual &&
498+
grep "d0|main|cmd_name|.*|_run_git_alias_ (_run_dashed_/_run_dashed_/_run_git_alias_)" actual &&
499+
500+
# These def_param events could be associated with any of the
501+
# above cmd_name events. It does not matter.
502+
grep "d0|main|def_param|.*|cfg.prop.foo:red" actual >actual.matches &&
503+
grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
504+
505+
# However, we do not want them repeated each time we unpeel.
506+
test_line_count = 1 actual.matches &&
507+
508+
# The "git version" child sees a different cmd_name hierarchy.
509+
# Also test the def_param (only for completeness).
510+
grep "d1|main|cmd_name|.*|version (_run_dashed_/_run_dashed_/_run_git_alias_/version)" actual &&
511+
grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
512+
grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
513+
'
514+
290515
test_done

0 commit comments

Comments
 (0)