diff options
Diffstat (limited to 'compiler_wrapper/errors_test.go')
-rw-r--r-- | compiler_wrapper/errors_test.go | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/compiler_wrapper/errors_test.go b/compiler_wrapper/errors_test.go index 626d3148..29c941df 100644 --- a/compiler_wrapper/errors_test.go +++ b/compiler_wrapper/errors_test.go @@ -2,12 +2,14 @@ package main import ( "errors" + "fmt" + "syscall" "testing" ) func TestNewErrorwithSourceLocfMessage(t *testing.T) { err := newErrorwithSourceLocf("a%sc", "b") - if err.Error() != "errors_test.go:9: abc" { + if err.Error() != "errors_test.go:11: abc" { t.Errorf("Error message incorrect. Got: %s", err.Error()) } } @@ -15,7 +17,7 @@ func TestNewErrorwithSourceLocfMessage(t *testing.T) { func TestWrapErrorwithSourceLocfMessage(t *testing.T) { cause := errors.New("someCause") err := wrapErrorwithSourceLocf(cause, "a%sc", "b") - if err.Error() != "errors_test.go:17: abc: someCause" { + if err.Error() != "errors_test.go:19: abc: someCause" { t.Errorf("Error message incorrect. Got: %s", err.Error()) } } @@ -26,3 +28,41 @@ func TestNewUserErrorf(t *testing.T) { t.Errorf("Error message incorrect. Got: %s", err.Error()) } } + +func TestSubprocessOk(t *testing.T) { + exitCode, err := wrapSubprocessErrorWithSourceLoc(nil, nil) + if exitCode != 0 { + t.Errorf("unexpected exit code. Got: %d", exitCode) + } + if err != nil { + t.Errorf("unexpected error. Got: %s", err) + } +} + +func TestSubprocessExitCodeError(t *testing.T) { + exitCode, err := wrapSubprocessErrorWithSourceLoc(nil, newExitCodeError(23)) + if exitCode != 23 { + t.Errorf("unexpected exit code. Got: %d", exitCode) + } + if err != nil { + t.Errorf("unexpected error. Got: %s", err) + } +} + +func TestSubprocessCCacheError(t *testing.T) { + _, err := wrapSubprocessErrorWithSourceLoc(&command{path: "/usr/bin/ccache"}, syscall.ENOENT) + if _, ok := err.(userError); !ok { + t.Errorf("unexpected error type. Got: %T", err) + } + if err.Error() != "ccache not found under /usr/bin/ccache. Please install it" { + t.Errorf("unexpected error message. Got: %s", err) + } +} + +func TestSubprocessGeneralError(t *testing.T) { + cmd := &command{path: "somepath"} + _, err := wrapSubprocessErrorWithSourceLoc(cmd, errors.New("someerror")) + if err.Error() != fmt.Sprintf("errors_test.go:64: failed to execute %#v: someerror", cmd) { + t.Errorf("Error message incorrect. Got: %s", err.Error()) + } +} |