Skip to content
Draft
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
1 change: 0 additions & 1 deletion crates/lean_compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ pub fn try_compile_and_run(
let bytecode = try_compile_program(input)?;
let witness = ExecutionWitness::default();
let result = try_execute_bytecode(&bytecode, public_input, &witness, profiler)?;
println!("{}", result.metadata.display());
Ok(result.metadata.display())
}

Expand Down
52 changes: 52 additions & 0 deletions crates/lean_compiler/tests/try_compile_and_run_output.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::process::Command;

use backend::PrimeCharacteristicRing;
use lean_compiler::{ProgramSource, try_compile_and_run};
use lean_vm::{DIGEST_LEN, F};

const CHILD_TEST: &str = "child_calls_try_compile_and_run";
const CHILD_ENV: &str = "LEAN_COMPILER_TRY_COMPILE_AND_RUN_CHILD";

#[test]
fn try_compile_and_run_does_not_print_summary() {
// Re-exec this test binary so stdout capture stays process-local and does not
// depend on global test harness state. `--exact` avoids recursively running
// this parent test in the child process.
let output = Command::new(std::env::current_exe().unwrap())
.arg("--exact")
.arg(CHILD_TEST)
.arg("--nocapture")
.env(CHILD_ENV, "1")
.output()
.unwrap();

assert!(
output.status.success(),
"child test failed\nstdout:\n{}\nstderr:\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr),
);

let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
!stdout.contains("STATS"),
"try_compile_and_run unexpectedly printed the execution summary:\n{stdout}"
);
}

#[test]
fn child_calls_try_compile_and_run() {
// This test only does real work in the child process spawned above.
if std::env::var_os(CHILD_ENV).is_none() {
return;
}

let summary = try_compile_and_run(
&ProgramSource::Raw("def main():\n return\n".to_string()),
&[F::ZERO; DIGEST_LEN],
false,
)
.unwrap();

assert!(summary.contains("STATS"));
}