Problem launching (configuring?) unit tests with tinygo

83 Views Asked by At

I have a working project in tinygo for the Raspberry pi pico microcontroller.

The project is straightforward and involves the ADC and a ssd1366 display.

https://github.com/ettore-galli/tinygo-rpi-adc-viewer

I tried to add unit tests and this is where problems arose.

The unit test I tried to write first is simple:

File: adcviewer/adc_viewer_test.go [not yet pushed to the repo at the time of writing the question]

package main

import (
    "testing"
)

func TestScaleSensorValueToTraceDisplayRange(t *testing.T) {
    got := ScaleSensorValueToTraceDisplayRange(32760)

    want := byte(64)

    if want != got {
        t.Errorf("Result expected to be %v, got %v", want, got)
    }

}

For reference, the function is the following:

func ScaleSensorValueToTraceDisplayRange(value uint16) byte {
    return byte(value >> 10) // 0-65535 --> 0-64
}

Then, I tried to run the unit tests:

tinygo test -target=pico .

and I got the following error:

FAIL    adcviewer       0.010s
error: failed to run compiled binary /var/folders/x1/b4zb0kr95bg2cw0qfmm53_6m0000gn/T/tinygo1605005046/main: fork/exec /var/folders/x1/b4zb0kr95bg2cw0qfmm53_6m0000gn/T/tinygo1605005046/main: exec format error

The project itself compiles and flashes (and runs) correctly onto the device.

If I try to test directly using go (and not tinygo) I get other errors that I can understand (machine is a tinygo package, not a go one) and that I report just for completeness and reference.


go test .             
adc_viewer.go:5:2: package machine is not in GOROOT (/usr/local/go/src/machine)

I really can't understand what I'm doing wrong...

Which is the (or at least "a") "right" way to set up unit testing with tinygo from ground up?

0

There are 0 best solutions below