Skip to content

Commit

Permalink
use make in GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-codes committed Sep 27, 2024
1 parent bad8472 commit d0b98ef
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 411 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,4 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- run: go version
- run: go mod verify
- name: go mod tidy
run: |
go mod tidy
git diff --exit-code
- run: go vet ./...
- name: go fmt
run: |
go fmt ./...
git diff --exit-code
- name: go test
run: go test -v -count=1 -shuffle=on ./...
- run: make check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
tmp
.vscode/*
!.vscode/extensions.json
83 changes: 59 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,75 @@
.DEFAULT_GOAL = check
.PHONY: FORCE
.DEFAULT_GOAL = all

CC = /usr/local/musl/bin/musl-gcc
GOCC ?= /usr/local/musl/bin/musl-gcc
GOFLAGS = -ldflags '-linkmode external -extldflags "-static"'
OUTDIR = bin
TESTGEN_BINARY = $(OUTDIR)/testgen
BINDIR = bin
TMPDIR = tmp
TESTGEN_SRC = cmd/testgen/main.go
TESTGEN_BIN = $(BINDIR)/testgen
GOPKG = github.com/jon-codes/getopt

build-testgen: $(TESTGEN_BINARY)
.PHONY: build-testgen
## all: run development tasks (default target)
.PHONY: all
all: deps fmt vet test

clean:
rm -f $(TESTGEN_BINARY)
.PHONY: clean
.PHONY: check
check: deps-check fmt-check vet test

## deps: clean deps
.PHONY: deps
deps:
go mod tidy -v

.PHONY: deps-check
deps-check:
go mod tidy -diff
go mod verify

## fmt: go fmt
.PHONY: fmt
fmt:
go fmt ./...
.PHONY: fmt

.PHONY: fmt-check
fmt-check:
test -z "$(shell gofmt -l .)"

## vet: go vet
.PHONY: vet
vet:
go vet ./...
.PHONY: vet

test:
go test -v -p=4 ./...
## test: go test
.PHONY: test
test:
go test -v ./...

check: fmt vet test
.PHONY: check
## cover: go test coverage
.PHONY: cover
cover: temp
go test -v -coverprofile $(TMPDIR)/cover.out $(GOPKG)
go tool cover -html=$(TMPDIR)/cover.out

$(TESTGEN_BINARY): FORCE
@mkdir -p $(OUTDIR)
CC=$(CC) go build $(GOFLAGS) -o $@ ./cmd/testgen/main.go
## build-testgen: build test generator
.PHONY: build-testgen
build-testgen:
CC=$(GOCC) go build $(GOFLAGS) -o $(TESTGEN_BIN) $(TESTGEN_SRC)

deps: FORCE
go mod verify
go mod tidy
## testgen: generate tests
.PHONY: testgen
testgen:
$(TESTGEN_BIN)

all: clean deps
.PHONY: all
## clean: clean output
.PHONY: clean
clean:
rm -r $(BINDIR) $(TMPDIR)

temp:
mkdir -p tmp

## help: display this help
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
4 changes: 1 addition & 3 deletions getopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ func (s *State) readOpt(p Params) (res Result, err error) {
}

if checkNext && hasArg != NoArgument && s.OptIndex < len(s.Args) {
if s.Args[s.OptIndex] == "--" {
s.OptIndex++
} else {
if s.Args[s.OptIndex] != "--" {
res.OptArg = s.Args[s.OptIndex]
s.OptIndex++
}
Expand Down
14 changes: 13 additions & 1 deletion getopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,23 @@ func TestGetOpt(t *testing.T) {
})

t.Run("it treats arguments after '--' as parameters", func(t *testing.T) {
s := NewState(argsStr(`prgm -a -- -b`))
p := Params{Opts: OptStr(`ab`), Function: function}

wants := []assertion{
{char: 'a', args: argsStr(`prgm -a -- -b`), optIndex: 2},
{err: ErrDone, args: argsStr(`prgm -a -- -b`), optIndex: 3},
}

assertSeq(t, s, p, wants)
})

t.Run("it does not treat '--' as a potential option arguments", func(t *testing.T) {
s := NewState(argsStr(`prgm -a -- p1`))
p := Params{Opts: OptStr(`a::`), Function: function}

wants := []assertion{
{char: 'a', args: argsStr(`prgm -a -- p1`), optIndex: 3},
{char: 'a', args: argsStr(`prgm -a -- p1`), optIndex: 2},
{err: ErrDone, args: argsStr(`prgm -a -- p1`), optIndex: 3},
}

Expand Down
4 changes: 1 addition & 3 deletions testdata/cases.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[
{ "label": "kitchen_sink", "args": "prgm -h --h --he -l -longa --longa a", "opts": "hl", "longopts": "help,longa:" }
]
[]
Loading

0 comments on commit d0b98ef

Please sign in to comment.