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

[sc-508] Fix hang run test #235

Merged
merged 2 commits into from
Mar 12, 2024
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
15 changes: 9 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@

export CARGO_TERM_COLOR := "always"

all: rustup-show test clippy fmt sort audit
all: rustup-show check fmt clippy test sort audit

rustup-show:
rustup show

test:
cargo insta test --workspace

clippy:
cargo clippy
check:
cargo check --all-targets

fmt:
cargo fmt --all -- --check

clippy:
cargo clippy --all-targets

test:
cargo insta test --workspace

sort:
cargo sort --check --workspace

Expand Down
28 changes: 10 additions & 18 deletions tests/golden_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use std::{
io::Read,
path::{Path, PathBuf},
str::FromStr,
sync::{Arc, RwLock},
};
use stdext::function_name;
use walkdir::WalkDir;
Expand All @@ -36,10 +35,9 @@ fn do_parse_net(code: &str) -> Result<hvmc::ast::Net, String> {

const TESTS_PATH: &str = "/tests/golden_tests/";

fn run_single_golden_test(
path: &Path,
run: &[&dyn Fn(&str, &Path) -> Result<String, Diagnostics>],
) -> Result<(), String> {
type RunFn = dyn Fn(&str, &Path) -> Result<String, Diagnostics>;

fn run_single_golden_test(path: &Path, run: &[&RunFn]) -> Result<(), String> {
let code = std::fs::read_to_string(path).map_err(|e| e.to_string())?;
let file_name = path.to_str().and_then(|path| path.rsplit_once(TESTS_PATH)).unwrap().1;

Expand Down Expand Up @@ -68,14 +66,11 @@ fn run_single_golden_test(
Ok(())
}

fn run_golden_test_dir(test_name: &str, run: &dyn Fn(&str, &Path) -> Result<String, Diagnostics>) {
fn run_golden_test_dir(test_name: &str, run: &RunFn) {
run_golden_test_dir_multiple(test_name, &[run])
}

fn run_golden_test_dir_multiple(
test_name: &str,
run: &[&dyn Fn(&str, &Path) -> Result<String, Diagnostics>],
) {
fn run_golden_test_dir_multiple(test_name: &str, run: &[&RunFn]) {
let root = PathBuf::from(format!(
"{}{TESTS_PATH}{}",
env!("CARGO_MANIFEST_DIR"),
Expand Down Expand Up @@ -293,19 +288,16 @@ fn desugar_file() {
fn hangs() {
let expected_normalization_time = 5;

run_golden_test_dir(function_name!(), &|code, path| {
let diagnostics_cfg = DiagnosticsConfig::new(Severity::Error, true);
run_golden_test_dir(function_name!(), &move |code, path| {
let diagnostics_cfg = DiagnosticsConfig::new(Severity::Warning, true);
let book = do_parse_book(code, path)?;

let lck = Arc::new(RwLock::new(false));
let got = lck.clone();
std::thread::spawn(move || {
let _ = run_book(book, 1 << 20, RunOpts::default(), CompileOpts::heavy(), diagnostics_cfg, None);
*got.write().unwrap() = true;
let thread = std::thread::spawn(move || {
run_book(book, 1 << 20, RunOpts::default(), CompileOpts::heavy(), diagnostics_cfg, None)
});
std::thread::sleep(std::time::Duration::from_secs(expected_normalization_time));

if !*lck.read().unwrap() { Ok("Hangs".into()) } else { Err("Doesn't hang".to_string().into()) }
if !thread.is_finished() { Ok("Hangs".into()) } else { Err("Doesn't hang".to_string().into()) }
})
}

Expand Down
Loading