Merge branch 'ab/bug-if-bug'
A new bug() and BUG_if_bug() API is introduced to make it easier to uniformly log "detect multiple bugs and abort in the end" pattern. * ab/bug-if-bug: cache-tree.c: use bug() and BUG_if_bug() receive-pack: use bug() and BUG_if_bug() parse-options.c: use optbug() instead of BUG() "opts" check parse-options.c: use new bug() API for optbug() usage.c: add a non-fatal bug() function to go with BUG() common-main.c: move non-trace2 exit() behavior out of trace2.c
This commit is contained in:
@ -198,7 +198,7 @@ static int ut_006data(int argc, const char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ut_007bug(int argc, const char **argv)
|
||||
static int ut_007BUG(int argc, const char **argv)
|
||||
{
|
||||
/*
|
||||
* Exercise BUG() to ensure that the message is printed to trace2.
|
||||
@ -206,6 +206,28 @@ static int ut_007bug(int argc, const char **argv)
|
||||
BUG("the bug message");
|
||||
}
|
||||
|
||||
static int ut_008bug(int argc, const char **argv)
|
||||
{
|
||||
bug("a bug message");
|
||||
bug("another bug message");
|
||||
BUG_if_bug("an explicit BUG_if_bug() following bug() call(s) is nice, but not required");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ut_009bug_BUG(int argc, const char **argv)
|
||||
{
|
||||
bug("a bug message");
|
||||
bug("another bug message");
|
||||
/* The BUG_if_bug(...) isn't here, but we'll spot bug() calls on exit()! */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ut_010bug_BUG(int argc, const char **argv)
|
||||
{
|
||||
bug("a bug message");
|
||||
BUG("a BUG message");
|
||||
}
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
* test-tool trace2 <ut_name_1> <ut_usage_1>
|
||||
@ -222,7 +244,10 @@ static struct unit_test ut_table[] = {
|
||||
{ ut_004child, "004child", "[<child_command_line>]" },
|
||||
{ ut_005exec, "005exec", "<git_command_args>" },
|
||||
{ ut_006data, "006data", "[<category> <key> <value>]+" },
|
||||
{ ut_007bug, "007bug", "" },
|
||||
{ ut_007BUG, "007bug", "" },
|
||||
{ ut_008bug, "008bug", "" },
|
||||
{ ut_009bug_BUG, "009bug_BUG","" },
|
||||
{ ut_010bug_BUG, "010bug_BUG","" },
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
|
@ -168,6 +168,82 @@ test_expect_success 'BUG messages are written to trace2' '
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'bug messages with BUG_if_bug() are written to trace2' '
|
||||
test_when_finished "rm trace.normal actual expect" &&
|
||||
test_expect_code 99 env GIT_TRACE2="$(pwd)/trace.normal" \
|
||||
test-tool trace2 008bug 2>err &&
|
||||
cat >expect <<-\EOF &&
|
||||
a bug message
|
||||
another bug message
|
||||
an explicit BUG_if_bug() following bug() call(s) is nice, but not required
|
||||
EOF
|
||||
sed "s/^.*: //" <err >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
|
||||
cat >expect <<-EOF &&
|
||||
version $V
|
||||
start _EXE_ trace2 008bug
|
||||
cmd_name trace2 (trace2)
|
||||
error a bug message
|
||||
error another bug message
|
||||
error an explicit BUG_if_bug() following bug() call(s) is nice, but not required
|
||||
exit elapsed:_TIME_ code:99
|
||||
atexit elapsed:_TIME_ code:99
|
||||
EOF
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'bug messages without explicit BUG_if_bug() are written to trace2' '
|
||||
test_when_finished "rm trace.normal actual expect" &&
|
||||
test_expect_code 99 env GIT_TRACE2="$(pwd)/trace.normal" \
|
||||
test-tool trace2 009bug_BUG 2>err &&
|
||||
cat >expect <<-\EOF &&
|
||||
a bug message
|
||||
another bug message
|
||||
had bug() call(s) in this process without explicit BUG_if_bug()
|
||||
EOF
|
||||
sed "s/^.*: //" <err >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
|
||||
cat >expect <<-EOF &&
|
||||
version $V
|
||||
start _EXE_ trace2 009bug_BUG
|
||||
cmd_name trace2 (trace2)
|
||||
error a bug message
|
||||
error another bug message
|
||||
error on exit(): had bug() call(s) in this process without explicit BUG_if_bug()
|
||||
exit elapsed:_TIME_ code:99
|
||||
atexit elapsed:_TIME_ code:99
|
||||
EOF
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'bug messages followed by BUG() are written to trace2' '
|
||||
test_when_finished "rm trace.normal actual expect" &&
|
||||
test_expect_code 99 env GIT_TRACE2="$(pwd)/trace.normal" \
|
||||
test-tool trace2 010bug_BUG 2>err &&
|
||||
cat >expect <<-\EOF &&
|
||||
a bug message
|
||||
a BUG message
|
||||
EOF
|
||||
sed "s/^.*: //" <err >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
perl "$TEST_DIRECTORY/t0210/scrub_normal.perl" <trace.normal >actual &&
|
||||
cat >expect <<-EOF &&
|
||||
version $V
|
||||
start _EXE_ trace2 010bug_BUG
|
||||
cmd_name trace2 (trace2)
|
||||
error a bug message
|
||||
error a BUG message
|
||||
exit elapsed:_TIME_ code:99
|
||||
atexit elapsed:_TIME_ code:99
|
||||
EOF
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
sane_unset GIT_TRACE2_BRIEF
|
||||
|
||||
# Now test without environment variables and get all Trace2 settings
|
||||
|
Reference in New Issue
Block a user