Skip to content

Commit

Permalink
Test in Travis with Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
josephspurrier committed Jul 3, 2020
1 parent 0ec8a0c commit a67be3d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ vendor/
cmd/goversioninfo/goversioninfo
*.exe
*.syso
versioninfo.go
/bin

# OS Files
.DS_Store
Expand Down
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ before_install:
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
script:
- pwd
# Install binary.
- go install github.com/$TRAVIS_REPO_SLUG/cmd/goversioninfo
#- go install github.com/$TRAVIS_REPO_SLUG/cmd/goversioninfo
# Test building 32 and 64 on Windows.
- bash $TRAVIS_BUILD_DIR/testdata/bash/build.sh
# Run tests and send coverage info.
- make test-integration
# Run Go tests and send coverage info.
- cd $TRAVIS_BUILD_DIR
- $GOPATH/bin/goveralls -service=travis-ci
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This Makefile is an easy way to run common operations.
# Execute commands this:
# * make test-go
# * make test-integration
#
# Tip: Each command is run on its own line so you can't CD unless you
# connect commands together using operators. See examples:
# A; B # Run A and then B, regardless of success of A
# A && B # Run B if and only if A succeeded
# A || B # Run B if and only if A failed
# A & # Run A in background.
# Source: https://askubuntu.com/a/539293
#
# Tip: Use $(shell app param) syntax when expanding a shell return value.

.PHONY: test-go
test-go:
# Run the Go tests.
go test ./...

.PHONY: test-integration
test-integration:
# Build the application.
mkdir -p bin && go build -o bin/goversioninfo cmd/goversioninfo/main.go
# Test the application.
PATH="${PATH}:$(shell pwd)/bin" ./testdata/bash/build.sh
22 changes: 8 additions & 14 deletions testdata/bash/build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@
# Exit on error.
set -e

# Copy the icon to test file closing.
cp $GOPATH/src/github.com/josephspurrier/goversioninfo/testdata/resource/icon.ico $GOPATH/src/github.com/josephspurrier/goversioninfo/testdata/resource/icon2.ico

# Test Windows 32.
cd $GOPATH/src/github.com/josephspurrier/goversioninfo/testdata/example32
cd testdata/example32
GOOS=windows GOARCH=386 go generate
GOOS=windows GOARCH=386 go build
rm $GOPATH/src/github.com/josephspurrier/goversioninfo/testdata/resource/icon.ico

# Restore the icon.
cp $GOPATH/src/github.com/josephspurrier/goversioninfo/testdata/resource/icon2.ico $GOPATH/src/github.com/josephspurrier/goversioninfo/testdata/resource/icon.ico
rm example32.exe
rm resource.syso
cd ../../

# Test Windows 64.
cd $GOPATH/src/github.com/josephspurrier/goversioninfo/testdata/example64
cd testdata/example64
GOOS=windows GOARCH=amd64 go generate
GOOS=windows GOARCH=amd64 go build
rm $GOPATH/src/github.com/josephspurrier/goversioninfo/testdata/resource/icon.ico

# Reset the icons.
mv $GOPATH/src/github.com/josephspurrier/goversioninfo/testdata/resource/icon2.ico $GOPATH/src/github.com/josephspurrier/goversioninfo/testdata/resource/icon.ico
cd $GOPATH/src/github.com/josephspurrier/goversioninfo
rm example64.exe
rm resource.syso
cd ../../

0 comments on commit a67be3d

Please sign in to comment.