Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] assertions.go: CallerInfo() Not Get Actual File Path When Workdir Changed #1268

Closed
yishangru opened this issue Sep 20, 2022 · 1 comment · Fixed by #1288
Closed

[BUG] assertions.go: CallerInfo() Not Get Actual File Path When Workdir Changed #1268

yishangru opened this issue Sep 20, 2022 · 1 comment · Fixed by #1288

Comments

@yishangru
Copy link

file = parts[len(parts)-1]

Above link directs to the line to blame. This will remove the absolute path info retrieved from runtime.Caller(i).

parts := strings.Split(file, "/")
file = parts[len(parts)-1]

Reproduce:

  1. set workdir before test start
  2. call assert.True(t, false)
@yishangru yishangru changed the title [ISSUE] assertions.go: CallerInfo() Not Get Actual File Path When Workdir [BUG] assertions.go: CallerInfo() Not Get Actual File Path When Workdir Sep 20, 2022
@yishangru yishangru changed the title [BUG] assertions.go: CallerInfo() Not Get Actual File Path When Workdir [BUG] assertions.go: CallerInfo() Not Get Actual File Path When Workdir Changed Sep 20, 2022
@yishangru
Copy link
Author

yishangru commented Sep 20, 2022

A simple fix would be like this:

		parts := strings.Split(file, "/")
		// file := parts[len(parts)-1]
		filename := parts[len(parts)-1]
		if len(parts) > 1 {
			dir := parts[len(parts)-2]
			//if (dir != "assert" && dir != "mock" && dir != "require") || file == "mock_test.go" {
			if (dir != "assert" && dir != "mock" && dir != "require") || filename == "mock_test.go" {
				//path, _ := filepath.Abs(file)
				callers = append(callers, fmt.Sprintf("%s:%d", file, line))
			}
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant