[GH-ISSUE #591] run helloworld as a test will panic #432

Closed
opened 2026-03-04 01:04:55 +03:00 by kerem · 1 comment
Owner

Originally created by @axiaoxin on GitHub (Apr 23, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/591

define the helloworld demo as a function:

func Run() {
	box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!")
	if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil {
		panic(err)
	}
}

write a testing:


func TestRun(t *testing.T) {
	Run()
}

run test:

go test -run TestRun
--- FAIL: TestRun (0.00s)
panic: operation not supported by device [recovered]
	panic: operation not supported by device

goroutine 18 [running]:
testing.tRunner.func1.2(0x118e680, 0x12b4218)
	/usr/local/Cellar/go/1.16/libexec/src/testing/testing.go:1144 +0x332
testing.tRunner.func1(0xc000082600)
	/usr/local/Cellar/go/1.16/libexec/src/testing/testing.go:1147 +0x4b6
panic(0x118e680, 0x12b4218)
	/usr/local/Cellar/go/1.16/libexec/src/runtime/panic.go:965 +0x1b9
github.com/axiaoxin-com/x-stock/ui/terminal.Run()
	/Users/axiaoxin/go/src/github.com/axiaoxin-com/x-stock/ui/terminal/terminal.go:11 +0x20c
github.com/axiaoxin-com/x-stock/ui/terminal.TestRun(0xc000082600)
	/Users/axiaoxin/go/src/github.com/axiaoxin-com/x-stock/ui/terminal/terminal_test.go:6 +0x25
testing.tRunner(0xc000082600, 0x11bf890)
	/usr/local/Cellar/go/1.16/libexec/src/testing/testing.go:1194 +0xef
created by testing.(*T).Run
	/usr/local/Cellar/go/1.16/libexec/src/testing/testing.go:1239 +0x2b3
exit status 2
Originally created by @axiaoxin on GitHub (Apr 23, 2021). Original GitHub issue: https://github.com/rivo/tview/issues/591 define the helloworld demo as a function: ``` func Run() { box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!") if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil { panic(err) } } ``` write a testing: ``` func TestRun(t *testing.T) { Run() } ``` run test: ``` go test -run TestRun --- FAIL: TestRun (0.00s) panic: operation not supported by device [recovered] panic: operation not supported by device goroutine 18 [running]: testing.tRunner.func1.2(0x118e680, 0x12b4218) /usr/local/Cellar/go/1.16/libexec/src/testing/testing.go:1144 +0x332 testing.tRunner.func1(0xc000082600) /usr/local/Cellar/go/1.16/libexec/src/testing/testing.go:1147 +0x4b6 panic(0x118e680, 0x12b4218) /usr/local/Cellar/go/1.16/libexec/src/runtime/panic.go:965 +0x1b9 github.com/axiaoxin-com/x-stock/ui/terminal.Run() /Users/axiaoxin/go/src/github.com/axiaoxin-com/x-stock/ui/terminal/terminal.go:11 +0x20c github.com/axiaoxin-com/x-stock/ui/terminal.TestRun(0xc000082600) /Users/axiaoxin/go/src/github.com/axiaoxin-com/x-stock/ui/terminal/terminal_test.go:6 +0x25 testing.tRunner(0xc000082600, 0x11bf890) /usr/local/Cellar/go/1.16/libexec/src/testing/testing.go:1194 +0xef created by testing.(*T).Run /usr/local/Cellar/go/1.16/libexec/src/testing/testing.go:1239 +0x2b3 exit status 2 ```
kerem closed this issue 2026-03-04 01:04:55 +03:00
Author
Owner

@rivo commented on GitHub (Apr 26, 2021):

Your call stack doesn't list any tview code and this panic is not generated by it. I'm pretty sure what you're trying to do won't work anyway. Running a tview application captures the entire screen and it's interactive. It won't even exit unless you hit Ctrl-C. But unit tests are supposed to run unsupervised so this is at the very least not a good fit.

If you insist on trying to get this to work, please try it with a small tcell application first. If that works, it's likely we can make it work with tview as well.

<!-- gh-comment-id:826790196 --> @rivo commented on GitHub (Apr 26, 2021): Your call stack doesn't list any `tview` code and this panic is not generated by it. I'm pretty sure what you're trying to do won't work anyway. Running a `tview` application captures the entire screen and it's interactive. It won't even exit unless you hit Ctrl-C. But unit tests are supposed to run unsupervised so this is at the very least not a good fit. If you insist on trying to get this to work, please try it with a small `tcell` application first. If that works, it's likely we can make it work with `tview` as well.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#432
No description provided.