test: add git reset for refactor test

上级 6f6729ad
polymorphism.Overload.demo -> polymorphism.Overload.demoA
polymorphism.Overload.demoA -> polymorphism.Overload.demo
package cocatest
import (
"fmt"
"log"
"os/exec"
)
func ResetGitDir(codePath string) {
cmd := exec.Command("git", "checkout", "--ignore-skip-worktree-bits", "--", codePath)
out, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(string(out))
log.Fatalf("cmd.Run() failed with %s\n", err)
}
}
package unused
import (
"fmt"
. "github.com/onsi/gomega"
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/cocatest"
"github.com/phodal/coca/core/context/analysis"
"path/filepath"
"sync"
"testing"
)
func TestRenameMethodApp(t *testing.T) {
g := NewGomegaWithT(t)
var wg sync.WaitGroup
codePath := "../../../../_fixtures/refactor/unused"
configPath := "../../../../_fixtures/refactor/rename.config"
codePath = filepath.FromSlash(codePath)
......@@ -25,35 +25,15 @@ func TestRenameMethodApp(t *testing.T) {
classes = append(classes, node.Package+"."+node.ClassName)
}
wg.Add(1)
callApp := analysis.NewJavaFullApp()
callNodes := callApp.AnalysisPath(codePath, classes, identifiers)
wg.Add(1)
go func() {
RenameMethodApp(callNodes).Refactoring("")
defer wg.Done()
newnodes := callApp.AnalysisPath(codePath, classes, identifiers)
g.Expect(newnodes[0].Methods[0].Name).To(Equal("demoA"))
}()
wg.Add(1)
go func() {
wg.Wait()
configPath2 := "../../../../_fixtures/refactor/rename_back.config"
configPath2 = filepath.FromSlash(configPath2)
RenameMethodApp(callNodes).Refactoring("")
defer wg.Done()
renameBackNodes := callApp.AnalysisPath(codePath, classes, identifiers)
g.Expect(renameBackNodes[0].Methods[0].Name).To(Equal("demo"))
fmt.Println(callNodes)
configBytes := cmd_util.ReadFile(configPath)
RenameMethodApp(callNodes).Refactoring(string(configBytes))
wg.Wait()
}()
newnodes := callApp.AnalysisPath(codePath, classes, identifiers)
g.Expect(newnodes[0].Methods[0].Name).To(Equal("demo"))
cocatest.ResetGitDir(codePath)
}
......@@ -2,6 +2,7 @@ package unused
import (
. "github.com/onsi/gomega"
"github.com/phodal/coca/cocatest"
"path/filepath"
"testing"
)
......@@ -9,9 +10,13 @@ import (
func TestRemoveUnusedImportApp_Analysis(t *testing.T) {
g := NewGomegaWithT(t)
codePath := "../../../../_fixtures/refactor/unused"
codePath = filepath.FromSlash(codePath)
cocatest.ResetGitDir(codePath)
deps1, _, _ := cocatest.BuildAnalysisDeps(codePath)
g.Expect(len(deps1[0].Imports)).To(Equal(3))
app := NewRemoveUnusedImportApp(codePath)
results := app.Analysis()
......@@ -19,4 +24,10 @@ func TestRemoveUnusedImportApp_Analysis(t *testing.T) {
errorLines := BuildErrorLines(results[0])
g.Expect(errorLines).To(Equal([]int{3,4,5}))
app.Refactoring(results)
deps, _, _ := cocatest.BuildAnalysisDeps(codePath)
g.Expect(len(deps[0].Imports)).To(Equal(0))
cocatest.ResetGitDir(codePath)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册