tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.48k stars 913 forks source link

How run tests? #4609

Open eleimt opened 23 hours ago

eleimt commented 23 hours ago

Hello! I tried run simple test

func TestSimple(t *testing.T) {
    t.Errorf("error")
}

but get error

$ tinygo test -target=pico ./cmd/myproject
FAIL    myproject/cmd/myproject     0.000s
# myproject/internal/config
..\..\internal\config\config.go:34:22: undefined: machine.UART0_TX_PIN
..\..\internal\config\config.go:35:22: undefined: machine.UART0_RX_PIN
..\..\internal\config\config.go:40:22: undefined: machine.UART0_TX_PIN
..\..\internal\config\config.go:41:22: undefined: machine.UART0_RX_PIN

I have config.go file

func MustLoad() *Config {
    return &Config{
        Receiver: Uart{
            Uart:     machine.UART0,
            Tx:       machine.UART0_TX_PIN,
            Rx:       machine.UART0_RX_PIN,
            BaudRate: 115200,
        },
        // ...
    }
}

Help me please...

aykevl commented 11 hours ago

You are leaving out a lot of code. What's this Config struct? What's this Uart struct?

Note that you probably don't want to use UART on the pico, most people use the default serial output over USB (which is USB-CDC, not UART), and is available from machine.Serial.

eleimt commented 9 hours ago

@aykevl It's just structure, example:

type Config struct {
    Receiver    Uart
    Transmitter Uart
}

type Uart struct {
    Uart     *machine.UART
    Tx       machine.Pin
    Rx       machine.Pin
    BaudRate uint
}

For run tests I using USB. Without mapping Pins tests works normal.