Merge pull request #31 from asdf-vm/tb/add-makefile

feat(golang-rewrite): create Makefile
This commit is contained in:
Trevor Brown 2024-03-20 20:48:38 -04:00 committed by Trevor Brown
commit c10d22fa27
4 changed files with 59 additions and 24 deletions

36
Makefile Normal file
View File

@ -0,0 +1,36 @@
MAIN_PACKAGE_PATH := .
TARGET_DIR := .
TARGET := asdf
# Not sure what the default location should be for builds
build: test lint
go build -o=${TARGET_DIR}/${TARGET} ${MAIN_PACKAGE_PATH}
fmt:
go fmt ./...
verify:
go mod verify
tidy:
go mod tidy -v
audit: verify vet test
test:
go test -coverprofile=/tmp/coverage.out -bench= -v -race ./...
cover: test
go tool cover -html=/tmp/coverage.out
lint: fmt
staticcheck -tests -show-ignored ./...
revive
vet: fmt
go vet .
run: build
${TARGET_DIR}/${TARGET}
.PHONY: fmt lint vet build test run

View File

@ -1,3 +1,4 @@
// Main entrypoint for the CLI app
package main
import (

View File

@ -1,9 +1,7 @@
package main
import (
"fmt"
"os/exec"
"strings"
"testing"
)
@ -120,32 +118,32 @@ func TestBatsTests(t *testing.T) {
//})
}
func runBatsFile(t *testing.T, dir, filename string) {
t.Helper()
//func runBatsFile(t *testing.T, dir, filename string) {
// t.Helper()
cmd := exec.Command("bats", "--verbose-run", fmt.Sprintf("test/%s", filename))
// cmd := exec.Command("bats", "--verbose-run", fmt.Sprintf("test/%s", filename))
// Capture stdout and stderr
var stdout strings.Builder
var stderr strings.Builder
cmd.Stdout = &stdout
cmd.Stderr = &stderr
// // Capture stdout and stderr
// var stdout strings.Builder
// var stderr strings.Builder
// cmd.Stdout = &stdout
// cmd.Stderr = &stderr
// Add dir to asdf test variables
asdfTestHome := fmt.Sprintf("HOME=%s", dir)
asdfBinPath := fmt.Sprintf("ASDF_BIN=%s", dir)
cmd.Env = []string{asdfBinPath, asdfTestHome}
// // Add dir to asdf test variables
// asdfTestHome := fmt.Sprintf("HOME=%s", dir)
// asdfBinPath := fmt.Sprintf("ASDF_BIN=%s", dir)
// cmd.Env = []string{asdfBinPath, asdfTestHome}
err := cmd.Run()
if err != nil {
// If command fails print both stderr and stdout
fmt.Println("stdout:", stdout.String())
fmt.Println("stderr:", stderr.String())
t.Fatal("bats command failed to run test file successfully")
// err := cmd.Run()
// if err != nil {
// // If command fails print both stderr and stdout
// fmt.Println("stdout:", stdout.String())
// fmt.Println("stderr:", stderr.String())
// t.Fatal("bats command failed to run test file successfully")
return
}
}
// return
// }
//}
func buildAsdf(t *testing.T, dir string) {
cmd := exec.Command("go", "build", "-o", dir)

View File

@ -27,7 +27,7 @@ setup_asdf_dir() {
# ASDF_BIN is now defined by the Golang test code in main_test.go
#ASDF_BIN="$(dirname "$BATS_TEST_DIRNAME")/bin"
# shellcheck disable=SC2031
# shellcheck disable=SC2031,SC2153
PATH="$ASDF_BIN:$ASDF_DIR/shims:$PATH"
}