Skip to content

Commit

Permalink
feat: update makefile and apply parallel pattern (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrop committed Nov 29, 2022
1 parent b261b45 commit 63f1cf4
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 25 deletions.
50 changes: 27 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ test: test-all
test-all: test-clean init-sources $(TEST_ALL)
test-unit: test-clean init-sources $(TEST_UNIT)
test-clean:
@if [ -f "$(TEST_ALL)" ]; then rm -v $(TEST_ALL); fi; \
if [ -f "$(TEST_UNIT)" ]; then rm -v $(TEST_UNIT); fi;
@if [ -f "$(TEST_ALL)" ]; then rm -vf $(TEST_ALL); fi; \
if [ -f "$(TEST_UNIT)" ]; then rm -vf $(TEST_UNIT); fi;
test-upload:
test-cover:
@if [ "$(TEST_ALL)" -nt "$(TEST_UNIT)" ]; then \
Expand All @@ -335,30 +335,34 @@ test-cover:
fi; \


define testcase
for ARG in $(RUNARGS); do \
if [ -z "$${PACKAGES}" ]; then PACKAGES="$${ARG%%/*}"; \
else PACKAGES="$${PACKAGES}\n$${ARG%%/*}"; fi; \
if [ -z "$${TESTCASE}" ]; then TESTCASES="-run $${ARG#*/}"; \
else TESTCASES="$${TESTCASES} -run $${ARG#*/}"; fi; \
done; \
echo -en "$${PACKAGES}" | sort -u | sed "s/^/.\//"; \
echo "$${TESTCASES}"
define testargs
if [ -n "$(RUNARGS)" ]; then ARGS=($(RUNARGS)); \
if [[ -f "$${ARGS[0]}" && ! -d "$${ARGS[0]}" && \
"$${ARGS[0]}" == *_test.go ]]; then \
find $$(dirname $(RUNARGS) | sort -u) \
-maxdepth 1 -a -name "*.go" -a ! -name "*_test.go" \
-o -name "common_test.go" -o -name "mock_*_test.go" | \
sed -e "s/^/.\//"; \
echo $(addprefix ./,$(RUNARGS)); \
elif [[ -d "$${ARGS[0]}" && ! -f "$${ARGS[0]}" ]]; then \
echo $(addprefix ./,$(RUNARGS)); \
elif [[ ! -f "$${ARGS[0]}" && ! -d "$${ARGS[0]}" ]]; then \
for ARG in $${ARGS[0]}; do \
if [ -z "$${PACKAGES}" ]; then PACKAGES="$${ARG%/*}"; \
else PACKAGES="$${PACKAGES}\n$${ARG%/*}"; fi; \
if [ -z "$${TESTCASE}" ]; then TESTCASES="-run $${ARG##*/}"; \
else TESTCASES="$${TESTCASES} -run $${ARG##*/}"; fi; \
done; \
echo -en "$${PACKAGES}" | sort -u | sed "s/^/.\//"; \
echo "$${TESTCASES}"; \
else
echo "warning: invalid test parameters [$${ARGS[@]}]" > /dev/stderr;
fi;\
else echo "./..."; fi
endef

TESTFLAGS ?= -race -mod=readonly -count=1
TESTARGS ?= $(shell \
if [[ "$(RUNARGS)" == *_test.go ]]; then \
find $$(dirname $(RUNARGS) | sort -u) -maxdepth 1 -a -name "*.go" -a \
! -name "*_test.go" -o -name "common_test.go" -o -name "mock_*_test.go" | \
sed -e "s/^/.\//"; \
echo $(addprefix ./,$(RUNARGS)); \
elif [[ "$(RUNARGS)" == [a-z_-/]*/* ]]; then \
echo "$(shell $(testcase))"; \
elif [ -n "$(RUNARGS)" ]; then \
echo $(addprefix ./,$(RUNARGS)); \
else echo "./..."; fi \
)
TESTARGS ?= $(shell $(testargs))

$(TEST_ALL): $(SOURCES) init-sources $(TEST_DEPS)
@if [ ! -d "$(BUILDIR)" ]; then mkdir -p $(BUILDIR); fi;
Expand Down
2 changes: 1 addition & 1 deletion gock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on testing it does not support the networking and observation features of
is mainly compatible with.


## Migration from Gock to Tock
## Migration from Gock

Migration from [Gock][gock] to this package is straigt forward. You can just
add the controller creation as at the begin of your test giving it the name
Expand Down
1 change: 1 addition & 0 deletions gock/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var testControllerParams = map[string]struct {

func TestController(t *testing.T) {
t.Parallel()

for message, param := range testControllerParams {
message, param := message, param
t.Run(message, func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions gock/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ var testMatchParams = map[string]struct {

func TestMatch(t *testing.T) {
t.Parallel()

for message, param := range testMatchParams {
message, param := message, param
t.Run(message, func(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ var testSetupParams = perm.ExpectMap{

func TestSetup(t *testing.T) {
t.Parallel()

for message, expect := range testSetupParams.Remain(test.ExpectSuccess) {
message, expect := message, expect
t.Run(message, test.Run(expect, func(t *test.TestingT) {
Expand Down Expand Up @@ -158,6 +159,7 @@ var testChainParams = perm.ExpectMap{

func TestChain(t *testing.T) {
t.Parallel()

for message, expect := range testChainParams.Remain(test.ExpectFailure) {
message, expect := message, expect
t.Run(message, test.Run(expect, func(t *test.TestingT) {
Expand Down Expand Up @@ -195,6 +197,7 @@ var testSetupChainParams = perm.ExpectMap{

func TestSetupChain(t *testing.T) {
t.Parallel()

for message, expect := range testSetupChainParams.Remain(test.ExpectFailure) {
message, expect := message, expect
t.Run(message, test.Run(expect, func(t *test.TestingT) {
Expand Down Expand Up @@ -227,6 +230,7 @@ func TestSetupChain(t *testing.T) {

func TestChainSetup(t *testing.T) {
t.Parallel()

for message, expect := range testSetupChainParams.Remain(test.ExpectFailure) {
message, expect := message, expect
t.Run(message, test.Run(expect, func(t *test.TestingT) {
Expand Down Expand Up @@ -274,6 +278,7 @@ var testParallelChainParams = perm.ExpectMap{

func TestParallelChain(t *testing.T) {
t.Parallel()

for message, expect := range testParallelChainParams.Remain(test.ExpectFailure) {
message, expect := message, expect
t.Run(message, test.Run(expect, func(t *test.TestingT) {
Expand Down Expand Up @@ -327,6 +332,7 @@ var testChainSubParams = perm.ExpectMap{

func TestChainSub(t *testing.T) {
t.Parallel()

perms := testChainSubParams
// perms := PermRemain(testChainSubParams, test.ExpectFailure)
for message, expect := range perms {
Expand Down Expand Up @@ -370,6 +376,7 @@ var testDetachParams = perm.ExpectMap{

func TestDetach(t *testing.T) {
t.Parallel()

for message, expect := range testDetachParams.Remain(test.ExpectFailure) {
message, expect := message, expect
t.Run(message, test.Run(expect, func(t *test.TestingT) {
Expand Down Expand Up @@ -432,6 +439,7 @@ var testPanicParams = map[string]struct {

func TestPanic(t *testing.T) {
t.Parallel()

for message, param := range testPanicParams {
message, param := message, param
t.Run(message, func(t *testing.T) {
Expand Down Expand Up @@ -500,6 +508,7 @@ var testGetSubSliceParams = map[string]struct {

func TestGetSubSlice(t *testing.T) {
t.Parallel()

for message, param := range testGetSubSliceParams {
message, param := message, param
t.Run(message, func(t *testing.T) {
Expand Down Expand Up @@ -532,6 +541,7 @@ var testGetDoneParams = map[string]struct {

func TestGetDone(t *testing.T) {
t.Parallel()

for message, param := range testGetDoneParams {
message, param := message, param
t.Run(message, func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions perm/perm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var testTestParams = perm.ExpectMap{

func TestTest(t *testing.T) {
t.Parallel()

for message, expect := range testTestParams.Remain(test.ExpectFailure) {
message, expect := message, expect
t.Run(message, test.Run(expect, func(t *test.TestingT) {
Expand Down
6 changes: 5 additions & 1 deletion sync/waitgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
)

func TestWaitGroup(t *testing.T) {
defer func() { recover() }()
t.Parallel()

// Given
defer func() { recover() }()
wg := NewWaitGroup()

// When
Expand All @@ -23,6 +25,8 @@ func TestWaitGroup(t *testing.T) {
}

func TestLenientWaitGroup(t *testing.T) {
t.Parallel()

// Given
wg := NewLenientWaitGroup()

Expand Down
2 changes: 2 additions & 0 deletions test/testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func Call(t *TestingT, mocks *mock.Mocks, expect Expect, test func(*TestingT)) {

func TestRun(t *testing.T) {
t.Parallel()

for message, param := range testRunParams {
message, param := message, param
t.Run(message, Run(param.expect, func(t *TestingT) {
Expand All @@ -161,6 +162,7 @@ func TestRun(t *testing.T) {

func TestOther(t *testing.T) {
t.Parallel()

for message, param := range testRunParams {
message, param := message, param
switch param.expect {
Expand Down

0 comments on commit 63f1cf4

Please sign in to comment.