Skip to content

Commit

Permalink
make: targeted packages
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ellemouton committed Jan 6, 2025
1 parent 7d39645 commit 8eacc63
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion make/testing_flags.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,35 @@ endif
# If a specific unit test case is being target, construct test.run filter.
ifneq ($(case),)
TEST_FLAGS += -test.run=$(case)
UNIT_TARGETED = yes
endif

# If specific package is being unit tested, construct the full name of the
# subpackage.
ifneq ($(pkg),)
UNITPKG := $(PKG)/$(pkg)
COVER_PKG := $(PKG)/$(pkg)
UNIT_TARGETED = yes
GOLIST = echo '$(PKG)/$(pkg)'
endif

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

# UNIT_TARGETED is undefined iff a specific package and/or unit test case is
# not being targeted.
UNIT_TARGETED ?= no

# If a specific package/test case was requested, run the unit test for the
# targeted case. Otherwise, default to running all tests.
ifeq ($(UNIT_TARGETED), yes)
UNIT := $(GOTEST) -tags="$(DEV_TAGS) $(COMPILE_TAGS)" $(TEST_FLAGS) $(UNITPKG)
UNIT_RACE := $(GOTEST) -tags="$(DEV_TAGS) $(COMPILE_TAGS)" $(TEST_FLAGS) -race $(UNITPKG)
endif

ifeq ($(UNIT_TARGETED), no)
UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) -tags="$(DEV_TAGS) $(COMPILE_TAGS)" $(TEST_FLAGS)
UNIT_RACE := $(UNIT) -race
UNIT_RACE := $(UNIT) -race
endif

0 comments on commit 8eacc63

Please sign in to comment.