Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How run tests? #4609

Open
eleimt opened this issue Nov 17, 2024 · 5 comments
Open

How run tests? #4609

eleimt opened this issue Nov 17, 2024 · 5 comments
Labels
info-needed We need further information to help resolve

Comments

@eleimt
Copy link

eleimt commented Nov 17, 2024

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
Copy link
Member

aykevl commented Nov 18, 2024

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
Copy link
Author

eleimt commented Nov 18, 2024

@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.

@eleimt
Copy link
Author

eleimt commented Dec 6, 2024

@aykevl

@deadprogram
Copy link
Member

Hello @eleimt could you please provide a complete code sample that shows your specific issue? Thank you.

@deadprogram deadprogram added the info-needed We need further information to help resolve label Dec 12, 2024
@eleimt
Copy link
Author

eleimt commented Dec 18, 2024

Hello @eleimt could you please provide a complete code sample that shows your specific issue? Thank you.

File 1: cmd/abc/main.go

package main

import (
	"machine"
	"time"
)

func main() {
	led := machine.LED
	led.Configure(machine.PinConfig{Mode: machine.PinOutput})
	for {
		led.Low()
		time.Sleep(time.Millisecond * 500)

		led.High()
		time.Sleep(time.Millisecond * 500)
	}
}

File 2 cmd/abc/main_test.go

package main

import (
	"testing"
)

func TestBuild(t *testing.T) {
	t.Errorf("Should not produce an error")
}

Run command tinygo test ./cmd/abc result:

FAIL    abc/cmd/abc     0.000s
# abc/cmd/abc
cmd\abc\main.go:10:17: undefined: machine.LED

I'm expecting

--- FAIL: TestBuild (0.00s)
    Should not produce an error
FAIL
FAIL    abc/cmd/abc     0.042s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed We need further information to help resolve
Projects
None yet
Development

No branches or pull requests

3 participants