Skip to content

Commit

Permalink
Merge 1fffed9 into 4d438d1
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Apr 2, 2019
2 parents 4d438d1 + 1fffed9 commit e94228c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
51 changes: 44 additions & 7 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import (
"testing"
)

func setup(t *testing.T) string {
tmpd, err := ioutil.TempDir("", "goxz-")
if err != nil {
t.Fatal(err)
}
return tmpd
}

func TestCliRun(t *testing.T) {
testCases := []struct {
name string
Expand Down Expand Up @@ -61,13 +69,6 @@ func TestCliRun(t *testing.T) {
errStr: "can't load package",
},
}
setup := func(t *testing.T) string {
tmpd, err := ioutil.TempDir("", "goxz-")
if err != nil {
t.Fatal(err)
}
return tmpd
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down Expand Up @@ -106,3 +107,39 @@ func TestCliRun(t *testing.T) {
})
}
}

func TestCliRun_projDir(t *testing.T) {
if err := os.Chdir("./testdata"); err != nil {
t.Fatal(err)
}
defer os.Chdir("../")

input := []string{"-o=abc", "-C=../", "-pv=0.1.1", "-os=freebsd", "./testdata/hello"}
builtFiles := []string{"goxz_0.1.1_freebsd_amd64.tar.gz"}

cl := &cli{outStream: ioutil.Discard, errStream: ioutil.Discard}
tmpd := setup(t)
defer os.RemoveAll(tmpd)
args := append([]string{"-d=" + tmpd}, input...)
err := cl.run(args)

if err != nil {

t.Errorf("error should be nil but: %s", err)
}

files, err := ioutil.ReadDir(tmpd)
if err != nil {
t.Fatal(err)
}
var outs []string
for _, f := range files {
if !f.IsDir() {
outs = append(outs, f.Name())
}
}
if !reflect.DeepEqual(builtFiles, outs) {
t.Errorf("files are not built correctly\n out: %v\nexpect: %v", outs, files)
}

}
10 changes: 10 additions & 0 deletions goxz.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ func (gx *goxz) run() error {
if gx.work {
log.Printf("working dir: %s\n", gx.workDir)
}
wd, err := filepath.Abs(".")
if err != nil {
return err
}
if wd != gx.projDir {
if err := os.Chdir(gx.projDir); err != nil {
return err
}
defer os.Chdir(wd)
}
err = gx.buildAll()
if err == nil {
log.Println("Success!")
Expand Down

0 comments on commit e94228c

Please sign in to comment.