trace2: use system/global config for default trace2 settings
[git/git.git] / t / t0210-trace2-normal.sh
CommitLineData
a15860dc
JH
1#!/bin/sh
2
3test_description='test trace2 facility (normal target)'
4. ./test-lib.sh
5
bce9db6d
JH
6# Turn off any inherited trace2 settings for this test.
7sane_unset GIT_TR2 GIT_TR2_PERF GIT_TR2_EVENT
8sane_unset GIT_TR2_BRIEF
9sane_unset GIT_TR2_CONFIG_PARAMS
10
a15860dc
JH
11# Add t/helper directory to PATH so that we can use a relative
12# path to run nested instances of test-tool.exe (see 004child).
13# This helps with HEREDOC comparisons later.
14TTDIR="$GIT_BUILD_DIR/t/helper/" && export TTDIR
15PATH="$TTDIR:$PATH" && export PATH
16
17# Warning: use of 'test_cmp' may run test-tool.exe and/or git.exe
18# Warning: to do the actual diff/comparison, so the HEREDOCs here
19# Warning: only cover our actual calls to test-tool and/or git.
20# Warning: So you may see extra lines in artifact files when
21# Warning: interactively debugging.
22
a15860dc
JH
23V=$(git version | sed -e 's/^git version //') && export V
24
25# There are multiple trace2 targets: normal, perf, and event.
26# Trace2 events will/can be written to each active target (subject
27# to whatever filtering that target decides to do).
28# This script tests the normal target in isolation.
29#
30# Defer setting GIT_TR2 until the actual command line we want to test
31# because hidden git and test-tool commands run by the test harness
32# can contaminate our output.
33
34# Enable "brief" feature which turns off "<clock> <file>:<line> " prefix.
35GIT_TR2_BRIEF=1 && export GIT_TR2_BRIEF
36
37# Basic tests of the trace2 normal stream. Since this stream is used
38# primarily with printf-style debugging/tracing, we do limited testing
39# here.
40#
41# We do confirm the following API features:
42# [] the 'version <v>' event
43# [] the 'start <argv>' event
44# [] the 'cmd_name <name>' event
45# [] the 'exit <time> code:<code>' event
46# [] the 'atexit <time> code:<code>' event
47#
48# Fields of the form _FIELD_ are tokens that have been replaced (such
49# as the elapsed time).
50
51# Verb 001return
52#
53# Implicit return from cmd_<verb> function propagates <code>.
54
55test_expect_success 'normal stream, return code 0' '
56 test_when_finished "rm trace.normal actual expect" &&
57 GIT_TR2="$(pwd)/trace.normal" test-tool trace2 001return 0 &&
58 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
59 cat >expect <<-EOF &&
60 version $V
61 start _EXE_ trace2 001return 0
62 cmd_name trace2 (trace2)
63 exit elapsed:_TIME_ code:0
64 atexit elapsed:_TIME_ code:0
65 EOF
66 test_cmp expect actual
67'
68
69test_expect_success 'normal stream, return code 1' '
70 test_when_finished "rm trace.normal actual expect" &&
71 test_must_fail env GIT_TR2="$(pwd)/trace.normal" test-tool trace2 001return 1 &&
72 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
73 cat >expect <<-EOF &&
74 version $V
75 start _EXE_ trace2 001return 1
76 cmd_name trace2 (trace2)
77 exit elapsed:_TIME_ code:1
78 atexit elapsed:_TIME_ code:1
79 EOF
80 test_cmp expect actual
81'
82
83# Verb 002exit
84#
85# Explicit exit(code) from within cmd_<verb> propagates <code>.
86
87test_expect_success 'normal stream, exit code 0' '
88 test_when_finished "rm trace.normal actual expect" &&
89 GIT_TR2="$(pwd)/trace.normal" test-tool trace2 002exit 0 &&
90 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
91 cat >expect <<-EOF &&
92 version $V
93 start _EXE_ trace2 002exit 0
94 cmd_name trace2 (trace2)
95 exit elapsed:_TIME_ code:0
96 atexit elapsed:_TIME_ code:0
97 EOF
98 test_cmp expect actual
99'
100
101test_expect_success 'normal stream, exit code 1' '
102 test_when_finished "rm trace.normal actual expect" &&
103 test_must_fail env GIT_TR2="$(pwd)/trace.normal" test-tool trace2 002exit 1 &&
104 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
105 cat >expect <<-EOF &&
106 version $V
107 start _EXE_ trace2 002exit 1
108 cmd_name trace2 (trace2)
109 exit elapsed:_TIME_ code:1
110 atexit elapsed:_TIME_ code:1
111 EOF
112 test_cmp expect actual
113'
114
115# Verb 003error
116#
117# To the above, add multiple 'error <msg>' events
118
119test_expect_success 'normal stream, error event' '
120 test_when_finished "rm trace.normal actual expect" &&
121 GIT_TR2="$(pwd)/trace.normal" test-tool trace2 003error "hello world" "this is a test" &&
122 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
123 cat >expect <<-EOF &&
124 version $V
125 start _EXE_ trace2 003error '\''hello world'\'' '\''this is a test'\''
126 cmd_name trace2 (trace2)
127 error hello world
128 error this is a test
129 exit elapsed:_TIME_ code:0
130 atexit elapsed:_TIME_ code:0
131 EOF
132 test_cmp expect actual
133'
134
bce9db6d
JH
135sane_unset GIT_TR2_BRIEF
136
137# Now test without environment variables and get all Trace2 settings
138# from the global config.
139
140test_expect_success 'using global config, normal stream, return code 0' '
141 test_when_finished "rm trace.normal actual expect" &&
142 test_config_global trace2.normalBrief 1 &&
143 test_config_global trace2.normalTarget "$(pwd)/trace.normal" &&
144 test-tool trace2 001return 0 &&
145 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
146 cat >expect <<-EOF &&
147 version $V
148 start _EXE_ trace2 001return 0
149 cmd_name trace2 (trace2)
150 exit elapsed:_TIME_ code:0
151 atexit elapsed:_TIME_ code:0
152 EOF
153 test_cmp expect actual
154'
155
156test_expect_success 'using global config with include' '
157 test_when_finished "rm trace.normal actual expect real.gitconfig" &&
158 test_config_global trace2.normalBrief 1 &&
159 test_config_global trace2.normalTarget "$(pwd)/trace.normal" &&
160 mv "$(pwd)/.gitconfig" "$(pwd)/real.gitconfig" &&
161 test_config_global include.path "$(pwd)/real.gitconfig" &&
162 test-tool trace2 001return 0 &&
163 perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
164 cat >expect <<-EOF &&
165 version $V
166 start _EXE_ trace2 001return 0
167 cmd_name trace2 (trace2)
168 exit elapsed:_TIME_ code:0
169 atexit elapsed:_TIME_ code:0
170 EOF
171 test_cmp expect actual
172'
173
a15860dc 174test_done