From 0051e931c67aae6d82a9ee9495c28421dcce46fb Mon Sep 17 00:00:00 2001 From: JothamWong <45916998+JothamWong@users.noreply.github.com> Date: Fri, 12 Apr 2024 07:09:26 +0800 Subject: [PATCH] Add a test case to demonstrate that main function ends everything --- src/tests/test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/tests/test.ts b/src/tests/test.ts index b8854e4..51d70fb 100644 --- a/src/tests/test.ts +++ b/src/tests/test.ts @@ -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);