tinygo-org / drivers

TinyGo drivers for sensors, displays, wireless adaptors, and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.
https://tinygo.org
BSD 3-Clause "New" or "Revised" License
604 stars 188 forks source link

Makefile: unit-tests target improvements #426

Closed neildavis closed 1 year ago

neildavis commented 2 years ago

Currently Makefile assumes all dirs (drivers or not) either have unit tests, or will at least run under go test A manual list ($(NOTESTS)) variable is used to exclude anything problematic (usually code that imports machine which doesn't compile under 'vanilla go' used for running go test)

This is rather inflexible and has a few problems:

  1. It requires manually updating for each new driver that uses the 'machine` package (or non-driver content)
  2. It's impossible to nest packages, in particular say parent/child where child may have unit tests.
  3. The output of make unit-test contains many superfluous lines like: ? tinygo.org/x/drivers/adxl345 [no test files] where the package doesn't have any tests but doesn't fail either.

I propose an improvement to recursively identify which dirs contain files with names matching *_test.go and only run go test on those dirs. A manual exclusion list can be retained for convenience.

I've submitted #427 as a candidate to resolve this.

neildavis commented 2 years ago

In case you wonder "Why?" - my motivation for this stems from fixing #422 and adding support for #421. Whilst the devices are GPIO based (requiring importing machine package) there are some protocol packet assembly/disassembly logic functions indpendent of that, which I'd like to include unit tests for.

Currently this isn't possible if the tests are included in the same package (irremote in my case) as any code that imports machine, even in separate .go files. So I decided to split the protocol specifics out into a separate package. The choices then are:

  1. Another top level package, e.g. irprotocol as a sibling of irremote (and all other drivers)
  2. A nested package, e.g. irremote/irprotocol

I think the second option is preferable from an organization viewpoint. This necessitates the change to Makefile to allow testing of irremote/irprotocol whilst excluding irremote

neildavis commented 1 year ago

Closing since merged in v0.22.0