Skip to content

Commit

Permalink
[app][test] Revert monkey patch for sh -c
Browse files Browse the repository at this point in the history
- rename test.sh -> travis-test.sh and change Makefile
- add new test.sh to call from Ayi

Issue #7
  • Loading branch information
at15 committed Jul 8, 2016
1 parent 4e813c5 commit 34bcf1f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .ayi.example.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
debug: true
test:
- go test -v -cover $(glide novendor)
# FIXME: why sh is needed.... why can't just run the script
- sh ./scripts/test.sh
user: example-user
project:
name: example
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ build-all:
.PHONY: build-all

test:
./scripts/test.sh
./scripts/travis-test.sh
.PHONY: test

install:
Expand Down
38 changes: 1 addition & 37 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
#!/usr/bin/env bash

# FIXME: should put this in makefile, but I don't know how to make $(glide novendor) works in make file

# switch folder
# get the script path http://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself
pushd `dirname $0` > /dev/null
SCRIPTPATH=`pwd -P`
popd > /dev/null
# get current working directory
ORIGINAL_WD=${PWD}
# switch to script directory
cd ${SCRIPTPATH}
# switch to parent folder
cd ..

# run the test
# FIXME: the backup seems to have folder issue, will generate a nested fixture folder

echo "backup the fixture"
cp -r fixture fixture-bak

# TODO: only do this in travis
# add glide to path
export PATH=$PATH:${SCRIPTPATH}/linux-amd64
# show it is working
glide -v

# enable go vendor feature for 1.5
echo "enable go vendor feature"
export GO15VENDOREXPERIMENT=1

go test -v -cover $(glide novendor)
echo "recover the fixture"
rm -r fixture
mv fixture-bak fixture

# go back to the old working directory
cd ${ORIGINAL_WD}
go test -v -cover $(glide novendor)
39 changes: 39 additions & 0 deletions scripts/travis-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

# FIXME: should put this in makefile, but I don't know how to make $(glide novendor) works in make file

# switch folder
# get the script path http://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself
pushd `dirname $0` > /dev/null
SCRIPTPATH=`pwd -P`
popd > /dev/null
# get current working directory
ORIGINAL_WD=${PWD}
# switch to script directory
cd ${SCRIPTPATH}
# switch to parent folder
cd ..

# run the test
# FIXME: the backup seems to have folder issue, will generate a nested fixture folder

echo "backup the fixture"
cp -r fixture fixture-bak

# TODO: only do this in travis
# add glide to path
export PATH=$PATH:${SCRIPTPATH}/linux-amd64
# show it is working
glide -v

# enable go vendor feature for 1.5
echo "enable go vendor feature"
export GO15VENDOREXPERIMENT=1

go test -v -cover $(glide novendor)
echo "recover the fixture"
rm -r fixture
mv fixture-bak fixture

# go back to the old working directory
cd ${ORIGINAL_WD}
12 changes: 6 additions & 6 deletions util/command.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package util

import (
"fmt"
"os"
"os/exec"
"strings"
Expand All @@ -11,11 +10,12 @@ import (
func Command(cmd string) *exec.Cmd {
segments := strings.Fields(cmd)
name := segments[0]
if (name == "sh") && (segments[1] == "-c") {
// TODO: this does not support use like go test $(glide novendor)
fmt.Println(strings.Join(segments[2:], " "))
return exec.Command("sh", "-c", strings.Join(segments[2:], " "))
}
// FIXME: this is not working ...
// if (name == "sh") && (segments[1] == "-c") {
// // TODO: this does not support use like go test $(glide novendor)
// fmt.Println(strings.Join(segments[2:], " "))
// return exec.Command("sh", "-c", strings.Join(segments[2:], " "))
// }
return exec.Command(name, segments[1:]...)
}

Expand Down
5 changes: 3 additions & 2 deletions util/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ func TestCommand(t *testing.T) {
assert := assert.New(t)
cmd := Command("ls")
assert.Equal(1, len(cmd.Args))
// FIXME: using $(glide novendor) will no work
// FIXME: $(glide novendor) will not be interpreted
// TODO: try sh -c "go test -v -cover $(glide novendor)"
cmd = Command("go test -v -cover $(glide novendor)")
assert.Equal("test", cmd.Args[1])
assert.Nil(RunCommand("sh -c \"echo Hi\""))
// FIXME: this is also broken
// assert.Nil(RunCommand("sh -c \"echo Hi\""))
}

0 comments on commit 34bcf1f

Please sign in to comment.