Skip to content

Commit

Permalink
Go 1.21
Browse files Browse the repository at this point in the history
And minor `Makefile` improvements.
  • Loading branch information
otaviof committed Aug 19, 2023
1 parent 3623ae4 commit 4423ea6
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ runs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: 1.21.x
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
run: make test-unit

- shell: bash
run: make test-e2e
run: make test-e2e
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.ci
.env
.vscode
_output/
coverage*
bin/
coverage*
17 changes: 9 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
project_name: path-helper
dist: ./_output/dist
dist: ./bin/dist

builds:
- id: linux
Expand All @@ -9,23 +9,24 @@ builds:
goos:
- linux
env:
- CGO_ENABLED=0
- GO111MODULE=on
- GOFLAGS="-v -a"
- CGO_LDFLAGS="-s -w"
flags:
- -a
- -mod=vendor
- -v
goarch:
- amd64

- id: darwin
binary: path-helper
main: cmd/path-helper/main.go
goos:
- darwin
env:
- CGO_ENABLED=0
- GO111MODULE=on
- GOFLAGS="-v -a"
- CGO_LDFLAGS="-s -w"
flags:
- -a
- -mod=vendor
- -v
goarch:
- amd64
- amd64
26 changes: 16 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
APP = path-helper
OUTPUT_DIR ?= _output
OUTPUT_DIR ?= bin
VERSION ?= $(shell cat ./version)

BIN ?= $(OUTPUT_DIR)/$(APP)
CMD ?= cmd/$(APP)/*
PKG ?= pkg/$(APP)/*
CMD ?= ./cmd/$(APP)/...
PKG ?= ./pkg/$(APP)/...

GOFLAGS ?= -v -a
CGO_LDFLAGS ?= -s -w

E2E_DIR ?= test/e2e
GOFLAGS_TEST ?= -failfast -race -coverprofile=coverage.txt -covermode=atomic -cover -v
GOFLAGS ?= -v -a -ldflags=-s -mod=vendor

BATS_CORE ?= test/e2e/bats/core/bin/bats
E2E_DIR ?= test/e2e
E2E_TEST_GLOB ?= *.bats
E2E_TESTS = $(E2E_DIR)/$(E2E_TEST_GLOB)

ARGS ?=

.EXPORT_ALL_VARIABLES:

default: build

.PHONY: $(BIN)
$(BIN):
go build -o $(BIN) $(CMD)

build: $(BIN)

.PHONY: run
Expand All @@ -30,17 +36,17 @@ install: build

.PHONY: clean
clean:
rm -rf $(OUTPUT_DIR) > /dev/null
rm -rf $(OUTPUT_DIR) >/dev/null

test: test-unit test-e2e

.PHONY: test-unit
test-unit:
go test $(GOFLAGS_TEST) pkg/$(APP)/*
go test $(GOFLAGS_TEST) $(CMD) $(PKG)

.PHONY: test-e2e
test-e2e:
./test/e2e/bats/core/bin/bats --recursive $(E2E_DIR)/*.bats
test-e2e: $(BIN)
$(BATS_CORE) --trace --verbose-run --recursive $(E2E_TESTS)

codecov:
mkdir .ci || true
Expand Down
30 changes: 22 additions & 8 deletions test/e2e/path-helper.bats
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
#!/usr/bin/env bats

BASE_DIR="./test/paths.d"
PATH_HELPER="./_output/path-helper -p $BASE_DIR -m $BASE_DIR"
declare -r BIN="${BIN:-}"

BASE_DIR="${PWD}/test/paths.d"
PATH_HELPER="${BIN} -p ${BASE_DIR} -m ${BASE_DIR}"

PATHS="/a/a/a:/b/b/b:/c/c/c:/d/d/d"
PATHS_DUP="/a/a/a:/b/b/b:/c/c/c:/d/d/d:/d/d/d"

EXPR="PATH=\"$PATHS\" ; MANPATH=\"$PATHS\" ; export PATH MANPATH ;"
EXPR_DUP="PATH=\"$PATHS_DUP\" ; MANPATH=\"$PATHS_DUP\" ; export PATH MANPATH ;"
EXPR="PATH=\"${PATHS}\" ; MANPATH=\"${PATHS}\" ; export PATH MANPATH ;"
EXPR_DUP="PATH=\"${PATHS_DUP}\" ; MANPATH=\"${PATHS_DUP}\" ; export PATH MANPATH ;"

@test "without-duplicates-and-witout-not-founds" {
run $PATH_HELPER
[ -f "${BIN}" && -n "${PATH_HELPER}" && -d "${BASE_DIR}" ]

run ${PATH_HELPER}

[ "$status" = 0 ]
[ "$output" = "PATH=\"\" ; MANPATH=\"\" ; export PATH MANPATH ;" ]
}

@test "with-duplicates" {
run $PATH_HELPER -s=false
[ -f "${BIN}" && -n "${PATH_HELPER}" && -d "${BASE_DIR}" ]

run ${PATH_HELPER} -s=false

[ "$status" = 0 ]
[ "$output" = "PATH=\"\" ; MANPATH=\"\" ; export PATH MANPATH ;" ]
}

@test "with-not-founds" {
run $PATH_HELPER -d=false
[ -f "${BIN}" && -n "${PATH_HELPER}" && -d "${BASE_DIR}" ]

run ${PATH_HELPER} -d=false

[ "$status" = 0 ]
[ "$output" = "$EXPR" ]
}

@test "with-duplicates-and-with-not-founds" {
run $PATH_HELPER -s=false -d=false
[ -f "${BIN}" && -n "${PATH_HELPER}" && -d "${BASE_DIR}" ]

run ${PATH_HELPER} -s=false -d=false

[ "$status" = 0 ]
[ "$output" = "$EXPR_DUP" ]
}

0 comments on commit 4423ea6

Please sign in to comment.