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

roc dev: report the status code of the child process #5557

Merged
merged 5 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,14 +1065,20 @@ fn roc_dev_native(

std::process::exit(1)
}
1.. => {
pid @ 1.. => {
let sigchld = Arc::new(AtomicBool::new(false));
signal_hook::flag::register(signal_hook::consts::SIGCHLD, Arc::clone(&sigchld))
.unwrap();

loop {
let exit_code = loop {
match memory.wait_for_child(sigchld.clone()) {
ChildProcessMsg::Terminate => break,
ChildProcessMsg::Terminate => {
let mut status = 0;
let options = 0;
unsafe { libc::waitpid(pid, &mut status, options) };

break status;
}
ChildProcessMsg::Expect => {
roc_repl_expect::run::render_expects_in_memory(
&mut writer,
Expand Down Expand Up @@ -1100,9 +1106,9 @@ fn roc_dev_native(
memory.reset();
}
}
}
};

std::process::exit(0)
std::process::exit(exit_code)
Comment on lines -1105 to +1111
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayazhafiz I double-checked for you:

roc on  main [!] is 📦 v0.0.1 via 🦀 v1.71.1 via ❄️  impure (nix-shell-env) took 4s 
❯ ./target/release/roc dev /home/username/gitrepos/roc5/roc/crates/glue/tests/fixtures/nullable-wrapped/app.roc
🔨 Rebuilding platform...
tag_union was: StrFingerTree::More("foo", StrFingerTree::More("bar", StrFingerTree::Empty))
`More "small str" (Single "other str")` is: StrFingerTree::More("small str", StrFingerTree::Single("other str"))
`More "small str" Empty` is: StrFingerTree::More("small str", StrFingerTree::Empty)
`Single "small str"` is: StrFingerTree::Single("small str")
`Empty` is: StrFingerTree::Empty

roc on  main [!] is 📦 v0.0.1 via 🦀 v1.71.1 via ❄️  impure (nix-shell-env) 
❯ echo $?
0

roc on  main [!] is 📦 v0.0.1 via 🦀 v1.71.1 via ❄️  impure (nix-shell-env) 
❯ ./crates/glue/tests/fixtures/nullable-wrapped/app
tag_union was: StrFingerTree::More("foo", StrFingerTree::More("bar", StrFingerTree::Empty))
`More "small str" (Single "other str")` is: StrFingerTree::More("small str", StrFingerTree::Single("other str"))
`More "small str" Empty` is: StrFingerTree::More("small str", StrFingerTree::Empty)
`Single "small str"` is: StrFingerTree::Single("small str")
`Empty` is: StrFingerTree::Empty
Segmentation fault (core dumped)

It is segfaulting on main but it's hidden because the output was correct. We used to forget to check the exit code (which indicated the segfault) this PR fixes that.

}
_ => unreachable!(),
}
Expand Down
32 changes: 19 additions & 13 deletions crates/glue/tests/test_glue_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,24 @@ mod glue_cli_run {
let dir = fixtures_dir($fixture_dir);

generate_glue_for(&dir, std::iter::empty());
let out = run_app(&dir.join("app.roc"), std::iter::empty());

assert!(out.status.success());
let ignorable = "🔨 Rebuilding platform...\n";
let stderr = out.stderr.replacen(ignorable, "", 1);
assert_eq!(stderr, "");
assert!(
out.stdout.ends_with($ends_with),
"Unexpected stdout ending\n\n expected:\n\n {}\n\n but stdout was:\n\n {}",
$ends_with,
out.stdout
);

let test_name_str = stringify!($test_name);

// TODO after #5924 is fixed; remove this if
if !(cfg!(target_os = "linux") && (test_name_str == "nullable_unwrapped" || test_name_str == "nullable_wrapped")) {
let out = run_app(&dir.join("app.roc"), std::iter::empty());

assert!(out.status.success());
let ignorable = "🔨 Rebuilding platform...\n";
let stderr = out.stderr.replacen(ignorable, "", 1);
assert_eq!(stderr, "");
assert!(
out.stdout.ends_with($ends_with),
"Unexpected stdout ending\n\n expected:\n\n {}\n\n but stdout was:\n\n {}",
$ends_with,
out.stdout
);
}
}
)*

Expand Down Expand Up @@ -91,7 +97,7 @@ mod glue_cli_run {
`Bar 123` is: NonRecursive::Bar(123)
`Baz` is: NonRecursive::Baz(())
`Blah 456` is: NonRecursive::Blah(456)
"#),
"#),
nullable_wrapped:"nullable-wrapped" => indoc!(r#"
tag_union was: StrFingerTree::More("foo", StrFingerTree::More("bar", StrFingerTree::Empty))
`More "small str" (Single "other str")` is: StrFingerTree::More("small str", StrFingerTree::Single("other str"))
Expand Down