Description
This tool returns exitcode 0 if two Go files has equivalent source code (which
is expected to have the same machine code after compilation), and returns
exitcode 1 if not.
This is supposed to be used to check if a change after a code review requires
an additional review. For example:
- Often in review one may accept a change and propose to optionally add a
comment. In this case the author of the change has to choose between adding
a comment (which leads to resetting the code review approval) or deliver
the code as is. To avoid this dilemma this tool allows validating if the code
change is safe (for example a change in comments).
Install
go get github.com/xaionaro-go/safechange/cmd/safechange
Run
safechange <file1> <file2>
Example
/tmp/1.go
:
package pkg
import (
"fmt"
"io"
)
import "io/ioutil"
import "errors"
func main() {
// some comment
}
/tmp/2.go
:
package pkg
import (
"errors"
"fmt"
"io/ioutil"
"io"
)
func main() {
}
/tmp/3.go
:
package pkg
import (
"errors"
"fmt"
"io/ioutil"
"io"
)
func main() {
fmt.Println("hello!")
}
Files 1.go
and 2.go
are equivalent:
$ safechange /tmp/1.go /tmp/2.go
$ echo $?
0
Files 1.go
and 3.go
are not equivalent (because 3.go
has fmt.Println
, while 1.go
hasn't):
$ safechange /tmp/1.go /tmp/3.go
$ echo $?
1