-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from mbland/stack-trace
Add @go.print_stack_trace to public API, show trace when module import fails
- Loading branch information
Showing
6 changed files
with
123 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#! /usr/bin/env bats | ||
|
||
load ../environment | ||
|
||
teardown() { | ||
remove_test_go_rootdir | ||
} | ||
|
||
@test "$SUITE: stack trace from top level of main ./go script" { | ||
create_test_go_script '@go.print_stack_trace' | ||
run "$TEST_GO_SCRIPT" | ||
assert_success " $TEST_GO_SCRIPT:3 main" | ||
} | ||
|
||
@test "$SUITE: stack trace from top level of main ./go script without caller" { | ||
create_test_go_script '@go.print_stack_trace omit_caller' | ||
run "$TEST_GO_SCRIPT" | ||
assert_success '' | ||
} | ||
|
||
@test "$SUITE: stack trace from function inside main ./go script" { | ||
create_test_go_script \ | ||
'print_stack() {' \ | ||
' @go.print_stack_trace' \ | ||
'}' \ | ||
'print_stack' | ||
run "$TEST_GO_SCRIPT" | ||
|
||
local expected=(" $TEST_GO_SCRIPT:4 print_stack" | ||
" $TEST_GO_SCRIPT:6 main") | ||
local IFS=$'\n' | ||
assert_success "${expected[*]}" | ||
} | ||
|
||
@test "$SUITE: omit function caller from stack trace" { | ||
create_test_go_script \ | ||
'print_stack() {' \ | ||
" @go.print_stack_trace omit_caller" \ | ||
'}' \ | ||
'print_stack' | ||
run "$TEST_GO_SCRIPT" | ||
assert_success " $TEST_GO_SCRIPT:6 main" | ||
} | ||
|
||
@test "$SUITE: stack trace from subcommand script" { | ||
create_test_go_script '@go "$@"' | ||
create_test_command_script 'foo' \ | ||
'foo_func() {' \ | ||
' @go foo bar' \ | ||
'}' \ | ||
'foo_func' | ||
create_test_command_script 'foo.d/bar' \ | ||
'bar_func() {' \ | ||
' @go.print_stack_trace omit_caller' \ | ||
'}' \ | ||
'bar_func' | ||
|
||
run "$TEST_GO_SCRIPT" foo | ||
|
||
local go_core_pattern="$_GO_CORE_DIR/go-core.bash:[0-9]+" | ||
assert_success | ||
assert_line_equals 0 " $TEST_GO_SCRIPTS_DIR/foo.d/bar:5 source" | ||
assert_line_matches 1 " $go_core_pattern [email protected]_command_script" | ||
assert_line_matches 2 " $go_core_pattern @go" | ||
assert_line_equals 3 " $TEST_GO_SCRIPTS_DIR/foo:3 foo_func" | ||
assert_line_equals 4 " $TEST_GO_SCRIPTS_DIR/foo:5 source" | ||
assert_line_matches 5 " $go_core_pattern [email protected]_command_script" | ||
assert_line_matches 6 " $go_core_pattern @go" | ||
assert_line_equals 7 " $TEST_GO_SCRIPT:3 main" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters