From a67be3dfa331c7532fb6422cf2dc665f192c6e77 Mon Sep 17 00:00:00 2001 From: Joseph Spurrier Date: Fri, 3 Jul 2020 11:32:25 -0400 Subject: [PATCH] Test in Travis with Makefile --- .gitignore | 2 ++ .travis.yml | 7 ++++--- Makefile | 26 ++++++++++++++++++++++++++ testdata/bash/build.sh | 22 ++++++++-------------- 4 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 Makefile mode change 100644 => 100755 testdata/bash/build.sh diff --git a/.gitignore b/.gitignore index c74929c..b83ed98 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ vendor/ cmd/goversioninfo/goversioninfo *.exe *.syso +versioninfo.go +/bin # OS Files .DS_Store diff --git a/.travis.yml b/.travis.yml index 6676d76..5af5bd7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bbaa672 --- /dev/null +++ b/Makefile @@ -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 \ No newline at end of file diff --git a/testdata/bash/build.sh b/testdata/bash/build.sh old mode 100644 new mode 100755 index d583a3f..5b81e49 --- a/testdata/bash/build.sh +++ b/testdata/bash/build.sh @@ -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 \ No newline at end of file +rm example64.exe +rm resource.syso +cd ../../ \ No newline at end of file