Skip to content

Commit 1e83bc3

Browse files
committed
make: targeted packages
This commit lets us perform make commands of the following form: `make unit pkg=accounts` which will run all the tests in the specified package. Or you can do `make unit pkg=accounts case=TestAccountStore` to run a specific test in the specified package.
1 parent 2b0ffff commit 1e83bc3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

make/testing_flags.mk

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,35 @@ endif
1212
# If a specific unit test case is being targeted, construct test.run filter.
1313
ifneq ($(case),)
1414
TEST_FLAGS += -test.run=$(case)
15+
UNIT_TARGETED = yes
16+
endif
17+
18+
# If specific package is being unit tested, construct the full name of the
19+
# subpackage.
20+
ifneq ($(pkg),)
21+
UNITPKG := $(PKG)/$(pkg)
22+
COVER_PKG := $(PKG)/$(pkg)
23+
UNIT_TARGETED = yes
24+
GOLIST = echo '$(PKG)/$(pkg)'
1525
endif
1626

1727
# Add any additional tags that are passed in to make.
1828
ifneq ($(tags),)
1929
DEV_TAGS += ${tags}
2030
endif
2131

32+
# UNIT_TARGETED is undefined iff a specific package and/or unit test case is
33+
# not being targeted.
34+
UNIT_TARGETED ?= no
35+
36+
# If a specific package/test case was requested, run the unit test for the
37+
# targeted case. Otherwise, default to running all tests.
38+
ifeq ($(UNIT_TARGETED), yes)
39+
UNIT := $(GOTEST) -tags="$(DEV_TAGS) $(COMPILE_TAGS)" $(TEST_FLAGS) $(UNITPKG)
40+
endif
41+
42+
ifeq ($(UNIT_TARGETED), no)
2243
UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) -tags="$(DEV_TAGS) $(COMPILE_TAGS)" $(TEST_FLAGS)
23-
UNIT_RACE := $(UNIT) -race
44+
endif
45+
46+
UNIT_RACE := $(UNIT) -race

0 commit comments

Comments
 (0)