mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-12-24 20:35:03 -07:00
feat(golang-rewrite): create Makefile
* Address Go linter warnings * Fix Github workflow
This commit is contained in:
parent
d79027a8f6
commit
dab4657784
36
Makefile
Normal file
36
Makefile
Normal 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
|
44
main_test.go
44
main_test.go
@ -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)
|
||||
|
@ -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"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user