Skip to content

Commit 810888c

Browse files
neildavisdeadprogram
authored andcommitted
Makefile recursively finds unit-tests
This commit modifies how the Makefile selects dirs for the unit-test target Instead of assuming all dirs have tests and manually excluding those that don't, it now recursively finds all dirs containing files with names matching "*_test.go" A manual exclusion list is maintained for operational use.
1 parent cafe8df commit 810888c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,14 @@ endif
242242
tinygo build -size short -o ./build/test.uf2 -target=circuitplay-express ./examples/makeybutton/main.go
243243
@md5sum ./build/test.uf2
244244

245-
DRIVERS = $(wildcard */)
246-
NOTESTS = build examples flash semihosting pcd8544 shiftregister st7789 microphone mcp3008 gps microbitmatrix \
247-
hcsr04 ssd1331 ws2812 thermistor apa102 easystepper ssd1351 ili9341 wifinina shifter hub75 \
248-
hd44780 buzzer ssd1306 espat l9110x st7735 bmi160 l293x keypad4x4 max72xx p1am tone tm1637 \
249-
pcf8563 mcp2515 servo sdcard rtl8720dn image cmd i2csoft hts221 lps22hb apds9960 axp192 xpt2046 \
250-
ft6336 sx126x ssd1289 irremote uc8151 makeybutton
251-
TESTS = $(filter-out $(addsuffix /%,$(NOTESTS)),$(DRIVERS))
245+
# rwildcard is a recursive version of $(wildcard)
246+
# https://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html
247+
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
248+
# Recursively find all *_test.go files from cwd & reduce to unique dir names
249+
HAS_TESTS = $(sort $(dir $(call rwildcard,,*_test.go)))
250+
# Exclude anything we explicitly don't want to test for whatever reason
251+
EXCLUDE_TESTS = image
252+
TESTS = $(filter-out $(addsuffix /%,$(EXCLUDE_TESTS)),$(HAS_TESTS))
252253

253254
unit-test:
254255
@go test -v $(addprefix ./,$(TESTS))

0 commit comments

Comments
 (0)