Skip to content

Commit

Permalink
Add a test case to demonstrate that main function ends everything
Browse files Browse the repository at this point in the history
  • Loading branch information
JothamWong committed Apr 11, 2024
1 parent d741026 commit 0051e93
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1257,3 +1257,24 @@ for i := 0; i < 100; i++ {
`, 10,
'"before foo"\n"after foo"\n"before goo"\n"after goo"\n"before hoo"\n"Jotham Wong"\n"after hoo"'
, defaultNumWords);


// test that main will expire before blocking progresses
testProgram(`
func foo(x chan int) {
var y = <-x; // blocking since no actual value in x yet
print("This will not show");
}
func goo(x chan int) {
x <- 5; // unblocking write to channel
print("This will show");
}
var x chan int = make(chan int, 1); // buffered channel
go foo(x);
go goo(x);
print("This is the end");
10; // do not give time for foo to read
`, 10,
'"This will show"\n"This is the end"', defaultNumWords);

0 comments on commit 0051e93

Please sign in to comment.