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

Projects
None yet
3 participants
@shivakumargn
Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor Author

commented Jul 30, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.