refactor: rename api for expose

上级 147dd59b
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestApi(t *testing.T) {
path := "../_fixtures/call"
analysis := []CmdTestCase{{
analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -p " + path,
Golden: "",
}}
RunTestCmd(t, analysis)
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "api",
Cmd: "api -c -f -p " + path,
Golden: "testdata/api.txt",
......@@ -25,14 +26,14 @@ func TestApi(t *testing.T) {
func Test_ApiWithSortRemove(t *testing.T) {
path := "../_fixtures/call"
analysis := []CmdTestCase{{
analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -p " + path,
Golden: "",
}}
RunTestCmd(t, analysis)
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "api",
Cmd: "api -c -s -r com.phodal.pholedge.book. -p" + path,
Golden: "testdata/api_sort_remove.txt",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestArch(t *testing.T) {
abs := "../_fixtures/arch"
analysis := []CmdTestCase{{
analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -p " + abs,
Golden: "",
}}
RunTestCmd(t, analysis)
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "arch",
Cmd: "arch -P ",
Golden: "",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestBadSmell(t *testing.T) {
abs := "../_fixtures/bs"
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "bs",
Cmd: "bs -s type -p " + abs,
Golden: "",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestCall(t *testing.T) {
abs := "../_fixtures/arch"
analysis := []CmdTestCase{{
analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -p " + abs,
Golden: "",
}}
RunTestCmd(t, analysis)
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "call",
Cmd: "call -r com",
Golden: "",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestCloc(t *testing.T) {
analysis := []CmdTestCase{{
analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -p .",
Golden: "",
}}
RunTestCmd(t, analysis)
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "cloc",
Cmd: "cloc",
Golden: "",
......
......@@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"github.com/mattn/go-shellwords"
"github.com/phodal/coca/cocatest/testcase"
"github.com/spf13/cobra"
"os"
"path/filepath"
......@@ -10,19 +11,15 @@ import (
"testing"
)
// CmdTestCase describes a test case that works with releases.
type CmdTestCase struct {
Name string
Cmd string
Golden string
WantError bool
func RunTestCmd(t *testing.T, tests []testcase.CmdTestCase) {
RunTestCaseWithCmd(t, tests)
}
func RunTestCmd(t *testing.T, tests []CmdTestCase) {
func RunTestCaseWithCmd(t *testing.T, tests []testcase.CmdTestCase) {
t.Helper()
for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
defer resetEnv()()
defer ResetEnv()()
t.Log("running Cmd: ", tt.Cmd)
_, output, err := executeActionCommandC(tt.Cmd)
......@@ -47,7 +44,6 @@ func executeActionCommandC(cmd string) (*cobra.Command, string, error) {
buf := new(bytes.Buffer)
command := NewRootCmd(buf)
command.SetOut(buf)
command.SetArgs(args)
c, err := command.ExecuteC()
......@@ -55,7 +51,7 @@ func executeActionCommandC(cmd string) (*cobra.Command, string, error) {
return c, buf.String(), err
}
func resetEnv() func() {
func ResetEnv() func() {
origEnv := os.Environ()
return func() {
os.Clearenv()
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestConcept(t *testing.T) {
analysis := []CmdTestCase{{
analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -p ../_fixtures/examples/api",
Golden: "",
}}
RunTestCmd(t, analysis)
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "concept",
Cmd: "concept",
Golden: "",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestCount(t *testing.T) {
abs := "../_fixtures/examples/rename"
analysis := []CmdTestCase{{
analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -p " + abs,
Golden: "",
}}
RunTestCmd(t, analysis)
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "count",
Cmd: "count -t 1",
Golden: "testdata/count.txt",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func Test_Dep_MavenFindUnused(t *testing.T) {
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "dep",
Cmd: "deps -p ../_fixtures/deps/maven_sample",
Golden: "testdata/deps_maven.txt",
......@@ -14,7 +15,7 @@ func Test_Dep_MavenFindUnused(t *testing.T) {
}
func Test_Dep_GradleFindUnused(t *testing.T) {
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "dep",
Cmd: "deps -p ../_fixtures/deps/gradle_sample",
Golden: "testdata/deps_gradle.txt",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestEvaluate(t *testing.T) {
analysis := []CmdTestCase{{
analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -p ../_fixtures/arch",
Golden: "",
}}
RunTestCmd(t, analysis)
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "evaluate",
Cmd: "evaluate",
Golden: "testdata/evaluate.txt",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
// Todo: fake it
func TestGit(t *testing.T) {
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "git",
Cmd: "git -a -f -t -b -o -r com -s 10 -m",
Golden: "",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestRCall(t *testing.T) {
analysis := []CmdTestCase{{
analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -p ../_fixtures/call",
Golden: "",
}}
RunTestCmd(t, analysis)
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "rcall",
Cmd: "rcall -r com -c com",
Golden: "testdata/rcall_normal.txt",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestRefactorMove(t *testing.T) {
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "refactor",
Cmd: "refactor -p . -m .",
Golden: "",
......@@ -14,7 +15,7 @@ func TestRefactorMove(t *testing.T) {
}
func TestRefactorRename(t *testing.T) {
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "refactor",
Cmd: "refactor -p . -R . -m .",
Golden: "",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestSuggest(t *testing.T) {
analysis := []CmdTestCase{{
analysis := []testcase.CmdTestCase{{
Name: "analysis",
Cmd: "analysis -p ../_fixtures/suggest",
Golden: "",
}}
RunTestCmd(t, analysis)
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "suggest",
Cmd: "suggest",
Golden: "testdata/suggest_normal.txt",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestTbs(t *testing.T) {
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "tbs",
Cmd: "tbs -p ../_fixtures/tbs/code -s ",
Golden: "testdata/tbs_normal.txt",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func Test_ShouldOutputCount(t *testing.T) {
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "todo",
Cmd: "todo -p ../_fixtures/todo",
Golden: "testdata/todo_normal.txt",
......@@ -15,7 +16,7 @@ func Test_ShouldOutputCount(t *testing.T) {
//TODO: update func for CI which clone depth = 1
func TestTodo(t *testing.T) {
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "todo",
Cmd: "todo -p ../_fixtures/todo -g",
Golden: "",
......
package cmd
import (
"github.com/phodal/coca/cocatest/testcase"
"testing"
)
func TestVersion(t *testing.T) {
tests := []CmdTestCase{{
tests := []testcase.CmdTestCase{{
Name: "version",
Cmd: "version",
Golden: "",
......
package testcase
// CmdTestCase describes a test case that works with releases.
type CmdTestCase struct {
Name string
Cmd string
Golden string
WantError bool
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册