-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fixer.go): introduce ErrFuncNotFound for standardized error hand…
…ling refactor(fixer.go): use fmt.Errorf with %w for error wrapping test(fixer_test.go): update tests to use errors.Is for error comparison feat(fixer_test.go): add test case for ErrFuncNotFound build(go.mod, go.sum): add dependencies for rsc.io/script and golang.org/x/tools test(main_test.go): add golden file testing for main function feat(testdata/golden.json): add golden file for testing expected output feat(testdata): add lookup.go and main.go.golden for testing purposes chore: remove output.json to clean up test data artifacts
- Loading branch information
1 parent
6135a87
commit be073f1
Showing
9 changed files
with
171 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
module github.com/yyoshiki41/rm-deadcode | ||
|
||
go 1.22.2 | ||
|
||
require rsc.io/script v0.0.2 | ||
|
||
require golang.org/x/tools v0.14.0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= | ||
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= | ||
rsc.io/script v0.0.2 h1:eYoG7A3GFC3z1pRx3A2+s/vZ9LA8cxojHyCvslnj4RI= | ||
rsc.io/script v0.0.2/go.mod h1:cKBjCtFBBeZ0cbYFRXkRoxP+xGqhArPa9t3VWhtXfzU= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"rsc.io/script" | ||
) | ||
|
||
func TestGolden(t *testing.T) { | ||
ctx := context.Background() | ||
state, err := script.NewState(ctx, "./", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
_, err = script.Cp().Run(state, "testdata/main.go", "testdata/main.go.backup") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer func() { | ||
_, err = script.Mv().Run(state, "testdata/main.go.backup", "testdata/main.go") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}() | ||
|
||
f, err := os.Open("testdata/golden.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer f.Close() | ||
|
||
os.Stdin = f | ||
main() | ||
|
||
got, err := os.Stat("testdata/main.go") | ||
expected, err := os.Stat("testdata/main.go.golden") | ||
if !os.SameFile(got, expected) { | ||
t.Errorf("unexpected file content") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[ | ||
{ | ||
"Name": "main", | ||
"Path": "github.com/yyoshiki41/rm-deadcode/testdata", | ||
"Funcs": [ | ||
{ | ||
"Name": "Unreachable", | ||
"Position": { | ||
"File": "testdata/main.go", | ||
"Line": 18, | ||
"Col": 6 | ||
}, | ||
"Generated": false | ||
}, | ||
{ | ||
"Name": "myString.String", | ||
"Position": { | ||
"File": "testdata/main.go", | ||
"Line": 33, | ||
"Col": 19 | ||
}, | ||
"Generated": false | ||
}, | ||
{ | ||
"Name": "myString.Unreachable", | ||
"Position": { | ||
"File": "testdata/main.go", | ||
"Line": 41, | ||
"Col": 20 | ||
}, | ||
"Generated": false | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
Reachable() | ||
} | ||
|
||
func init() { | ||
s := myString{Value: "hello"} | ||
s.Reachable() | ||
} | ||
|
||
func Reachable() { | ||
fmt.Println("reachable") | ||
} | ||
|
||
func Unreachable() { | ||
fmt.Println("unreachable") | ||
} | ||
|
||
func ReachableByTest() { | ||
fmt.Println("reachableByTest") | ||
} | ||
|
||
var _ fmt.Stringer = myString{} | ||
|
||
type myString struct { | ||
Value string | ||
} | ||
|
||
// NOTE: This function is unreachable but it is neccessary to implement the fmt.Stringer interface | ||
func (s myString) String() string { | ||
return s.Value | ||
} | ||
|
||
func (s myString) Reachable() { | ||
return | ||
} | ||
|
||
func (s *myString) Unreachable() { | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
Reachable() | ||
} | ||
|
||
func init() { | ||
s := myString{Value: "hello"} | ||
s.Reachable() | ||
} | ||
|
||
func Reachable() { | ||
fmt.Println("reachable") | ||
} | ||
|
||
func ReachableByTest() { | ||
fmt.Println("reachableByTest") | ||
} | ||
|
||
var _ fmt.Stringer = myString{} | ||
|
||
type myString struct { | ||
Value string | ||
} | ||
|
||
// NOTE: This function is unreachable but it is neccessary to implement the fmt.Stringer interface | ||
|
||
func (s myString) Reachable() { | ||
return | ||
} |
This file was deleted.
Oops, something went wrong.