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

Tests are broken #60

Open
QuLogic opened this issue Feb 27, 2023 · 7 comments
Open

Tests are broken #60

QuLogic opened this issue Feb 27, 2023 · 7 comments

Comments

@QuLogic
Copy link
Contributor

QuLogic commented Feb 27, 2023

Ever since #52, tests have been broken and do not compile. This makes it difficult to confirm everything is working as expected.

Also, please consider setting up some CI, which could have caught this before merging the PR.

@rdallman
Copy link
Member

uh oh. thanks for running the tests. I ran them to make sure on my machine, and with go 1.18 they do still work for me when running go test from the refactoring/ directory. I will try to update go and reproduce though. can you provide any more info possibly? macos/linux? go version?

@QuLogic
Copy link
Contributor Author

QuLogic commented Feb 28, 2023

Sorry, I should have mentioned those details earlier. I am using:

$ go version
go version go1.19.6 linux/amd64

But I am not just running refactoring though, so other items fail as well. Besides the compile failures, there is also engine/cli:

ok  	github.com/godoctor/godoctor/engine	(cached)
--- FAIL: TestRenameDiff (0.09s)
    cli_test.go:206: Rename expected exit code 0; got 3
--- FAIL: TestRenameComplete (0.17s)
    cli_test.go:217: Rename expected exit code 0; got 3
--- FAIL: TestOneRefactoringOneParam (0.05s)
    cli_test.go:348: One refactoring with one arg, no input expected exit 0
FAIL
FAIL	github.com/godoctor/godoctor/engine/cli	0.456s

And for refactoring I get something like:

Extract Function testdata/extractfunc/005-param-passing-and-return/main.go
>>>>> Output does not match /home/elliott/code/go/godoctor/refactoring/testdata/extractfunc/005-param-passing-and-return/main.golden
EXPECTED OUTPUT
vvvvvvvvvvvvvvv
//<<<<<extract,10,2,14,15,Foo,pass
package main

import "fmt"

func main() {
	a := 3 + 0
	b := a
	c := 1 + 0
	a, x := Foo(a, b)
	z := a + x + c
	fmt.Println(z)
}

func Foo(a int, b int) (int, int) {
	for a <= b {
		a += b
	}
	x := a + b
	fmt.Println(x)
	return a, x
}
^^^^^^^^^^^^^^^
ACTUAL OUTPUT
vvvvvvvvvvvvv
// <<<<<extract,10,2,14,15,Foo,pass
package main

import "fmt"

func main() {
	a := 3 + 0
	b := a
	c := 1 + 0
	a, x := Foo(a, b)
	z := a + x + c
	fmt.Println(z)
}

func Foo(a int, b int) (int, int) {
	for a <= b {
		a += b
	}
	x := a + b
	fmt.Println(x)
	return a, x
}
^^^^^^^^^^^^^
Length of expected output is 268; length of actual output is 269
Strings differ at index 2
Substrings starting at that index are:
Expected: [<<<<<extra]
Actual: [ <<<<<extr]

for many tests. But there's also a small space change in, e.g.,:

Add GoDoc testdata/godoc/014-consistent-comment-style/main.go
>>>>> Output does not match /home/elliott/code/go/godoctor/refactoring/testdata/godoc/014-consistent-comment-style/main.golden
EXPECTED OUTPUT
vvvvvvvvvvvvvvv
package main // <<<<< godoc,1,1,1,1,pass

type (
	// A is a type
	A int
	// B TODO: NEEDS COMMENT INFO
	B int
	c string
)

const (
	// StatusOk TODO: NEEDS COMMENT INFO
	StatusOk = 1
	// StatusBad is bad
	StatusBad = 2
)

//  TODO: NEEDS COMMENT INFO
var (
	Foo = "Foo"
	Bar = "Bar"
)

func main() {
}
^^^^^^^^^^^^^^^
ACTUAL OUTPUT
vvvvvvvvvvvvv
package main // <<<<< godoc,1,1,1,1,pass

type (
	// A is a type
	A int
	// B TODO: NEEDS COMMENT INFO
	B int
	c string
)

const (
	// StatusOk TODO: NEEDS COMMENT INFO
	StatusOk = 1
	// StatusBad is bad
	StatusBad = 2
)

// TODO: NEEDS COMMENT INFO
var (
	Foo = "Foo"
	Bar = "Bar"
)

func main() {
}
^^^^^^^^^^^^^
Length of expected output is 302; length of actual output is 301
Strings differ at index 225
Substrings starting at that index are:
Expected: [ TODO: NEE]
Actual: [TODO: NEED]

@QuLogic
Copy link
Contributor Author

QuLogic commented Feb 28, 2023

I attempted to fix the compile in #61 (but not the other issues).

@rdallman
Copy link
Member

rdallman commented Mar 1, 2023

got a repro. updating go to 1.20 has cropped up numerous errors, as posted. thanks for the info! I'll try to whittle away the rest of the tests.

@rdallman rdallman mentioned this issue Mar 1, 2023
@rdallman
Copy link
Member

rdallman commented Mar 1, 2023

gonna leave this open for now even though it is scary :) hope to fix the cgo and cli test issues too, but things are in a decent state now from #63

@QuLogic
Copy link
Contributor Author

QuLogic commented Jul 27, 2023

New test failures with Go 1.21rc3:

Debug Refactoring testdata/debug/showast/main.go
>>>>> Debug output does not match contents of testdata/debug/showast/main.go.debugOutput
>>>>> NOTE: All occurrences of the working directory name are replaced by "."
EXPECTED OUTPUT
vvvvvvvvvvvvvvv
     0  *ast.File {
     1  .  Doc: nil
     2  .  Package: ./testdata/debug/showast/main.go:1:1
     3  .  Name: *ast.Ident {
     4  .  .  NamePos: ./testdata/debug/showast/main.go:1:9
     5  .  .  Name: "main"
     6  .  .  Obj: nil
     7  .  }
     8  .  Decls: nil
     9  .  FileStart: ./testdata/debug/showast/main.go:1:1
    10  .  FileEnd: ./testdata/debug/showast/main.go:1:48
    11  .  Scope: *ast.Scope {
    12  .  .  Outer: nil
    13  .  .  Objects: map[string]*ast.Object (len = 0) {}
    14  .  }
    15  .  Imports: nil
    16  .  Unresolved: nil
    17  .  Comments: []*ast.CommentGroup (len = 1) {
    18  .  .  0: *ast.CommentGroup {
    19  .  .  .  List: []*ast.Comment (len = 1) {
    20  .  .  .  .  0: *ast.Comment {
    21  .  .  .  .  .  Slash: ./testdata/debug/showast/main.go:1:14
    22  .  .  .  .  .  Text: "//<<<<<debug,1,1,1,1,showast,pass"
    23  .  .  .  .  }
    24  .  .  .  }
    25  .  .  }
    26  .  }
    27  }
^^^^^^^^^^^^^^^
ACTUAL OUTPUT
vvvvvvvvvvvvv
     0  *ast.File {
     1  .  Doc: nil
     2  .  Package: ./testdata/debug/showast/main.go:1:1
     3  .  Name: *ast.Ident {
     4  .  .  NamePos: ./testdata/debug/showast/main.go:1:9
     5  .  .  Name: "main"
     6  .  .  Obj: nil
     7  .  }
     8  .  Decls: nil
     9  .  FileStart: ./testdata/debug/showast/main.go:1:1
    10  .  FileEnd: ./testdata/debug/showast/main.go:1:48
    11  .  Scope: *ast.Scope {
    12  .  .  Outer: nil
    13  .  .  Objects: map[string]*ast.Object (len = 0) {}
    14  .  }
    15  .  Imports: nil
    16  .  Unresolved: nil
    17  .  Comments: []*ast.CommentGroup (len = 1) {
    18  .  .  0: *ast.CommentGroup {
    19  .  .  .  List: []*ast.Comment (len = 1) {
    20  .  .  .  .  0: *ast.Comment {
    21  .  .  .  .  .  Slash: ./testdata/debug/showast/main.go:1:14
    22  .  .  .  .  .  Text: "//<<<<<debug,1,1,1,1,showast,pass"
    23  .  .  .  .  }
    24  .  .  .  }
    25  .  .  }
    26  .  }
    27  .  GoVersion: ""
    28  }
^^^^^^^^^^^^^
Length of expected output is 959; length of actual output is 984
Strings differ at index 957
Substrings starting at that index are:
Expected: [}\n]
Actual: [.  GoVersi]

It appears that ast.File now has a GoVersion member.

@rdallman
Copy link
Member

thanks @QuLogic for catching this - I'm going to wait until release of 1.21 and try to add build constraints to make this somewhat obvious.

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

No branches or pull requests

2 participants