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

cmd/go: TestGoTestImportErrorStack fails if wanted output is indented with spaces #26686

Closed
shivakumargn opened this issue Jul 30, 2018 · 3 comments

Comments

@shivakumargn
Copy link
Contributor

shivakumargn commented Jul 30, 2018

What version of Go are you using (go version)?

go version devel +5ad0a524d2 Sat Jul 28 09:06:26 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

Apply the below patch and run the test on cmd/go (the tabs are changed to spaces).
In my case this happened accidentally due to text editor settings. The program was gofmt compliant since the code itself is a string inside the go file and gofmt does not interpret it.

go_test.patch.txt

diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index dc4bad4987..42d269f957 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -3682,8 +3682,8 @@ func TestGoTestRaceFailures(t *testing.T) {
 
 func TestGoTestImportErrorStack(t *testing.T) {
 	const out = `package testdep/p1 (test)
-	imports testdep/p2
-	imports testdep/p3: build constraints exclude all Go files `
+        imports testdep/p2
+        imports testdep/p3: build constraints exclude all Go files `
 
 	tg := testgo(t)
 	defer tg.cleanup()

What did you expect to see?

Success
Even though tabs are the recommended indentation, space should not result in test failure.

What did you see instead?

Failed test

@shivakumargn shivakumargn changed the title Test code fail with spaces instead of tab Test code (cmd/go/go_test.go) fail with spaces instead of tab Jul 30, 2018
@meirf
Copy link
Contributor

meirf commented Jul 30, 2018

Even though tabs are the recommended indentation, space should not result in test failure.

The test is just verifying what the import stack error looks like. Seems like this issue should be focused on the what the import stack error looks like as opposed to the test that verifies it. So perhaps you're saying that the import stack error should have spaces instead of tabs.

But it looks like it's standard practice to have tabs in error messages. For example, this panic uses a tab. (Highlight the empty space and compare to that of the spaces in the first line to see that it is a tab.)

@mvdan mvdan changed the title Test code (cmd/go/go_test.go) fail with spaces instead of tab cmd/go: test code fails if indented with spaces Jul 30, 2018
@mvdan
Copy link
Member

mvdan commented Jul 30, 2018

I'm not sure what we could do here. It should be fine for a test to require specific output via a multiline literal string - why should an editor automatically modify these?

@mvdan mvdan changed the title cmd/go: test code fails if indented with spaces cmd/go: TestGoTestImportErrorStack fails if wanted output is indented with spaces Jul 30, 2018
@shivakumargn
Copy link
Contributor Author

The intent of the test is now clear that it is the expected output. From the code I was of the impression it is attempting to import/compile it.
The problem was accidental that when one types, visual code (and several editors) automatically give empty spaces and not tabs. One runs gofmt to fix it. In this case obviously that does not help.

Will close the ticket as not a bug.

@golang golang locked and limited conversation to collaborators Jul 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants