Skip to content

Commit 4258d4f

Browse files
Implement compilation filter for failing tests
1 parent e8c3415 commit 4258d4f

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ test: check-llvm needs-cairo2 build-alexandria
6666

6767
.PHONY: test-cairo
6868
test-cairo: check-llvm needs-cairo2
69-
cargo r --profile ci --bin cairo-native-test -- corelib
69+
cargo r --profile ci --bin cairo-native-test -- corelib \
70+
--skip-compilation core::test::dict_test::test_array_from_squash_dict \
71+
--skip-compilation core::test::hash_test::test_blake2s \
72+
--skip-compilation core::test::testing_test::test_get_unspent_gas
7073

7174
.PHONY: proptest
7275
proptest: check-llvm needs-cairo2

src/bin/cairo-native-test.rs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use cairo_lang_compiler::{
66
};
77
use cairo_lang_filesystem::cfg::{Cfg, CfgSet};
88
use cairo_lang_starknet::starknet_plugin_suite;
9-
use cairo_lang_test_plugin::{compile_test_prepared_db, test_plugin_suite, TestsCompilationConfig};
9+
use cairo_lang_test_plugin::{
10+
compile_test_prepared_db, test_plugin_suite, TestCompilation, TestsCompilationConfig,
11+
};
1012
use clap::Parser;
1113
use colored::Colorize;
1214
use std::path::PathBuf;
@@ -34,6 +36,13 @@ struct Args {
3436
/// The filter for the tests, running only tests containing the filter string.
3537
#[arg(short, long, default_value_t = String::default())]
3638
filter: String,
39+
/// Skips compilation for tests/functions containing any of the given filters.
40+
/// Unlike `--filter`, the matching tests are not even compiled by native.
41+
///
42+
/// DISCLAIMER: This is a hacky and temporary flag, used to run corelib tests
43+
/// when not all libfuncs are implemented.
44+
#[arg(long)]
45+
skip_compilation: Vec<String>,
3746
/// Should we run ignored tests as well.
3847
#[arg(long, default_value_t = false)]
3948
include_ignored: bool,
@@ -104,6 +113,8 @@ fn main() -> anyhow::Result<()> {
104113
args.filter.clone(),
105114
);
106115

116+
let compiled = filter_test_case_compilation(compiled, &args.skip_compilation);
117+
107118
let summary = run_tests(
108119
compiled.metadata.named_tests,
109120
compiled.sierra_program.program,
@@ -127,3 +138,50 @@ fn main() -> anyhow::Result<()> {
127138

128139
Ok(())
129140
}
141+
142+
/// Removes matching tests from `TestCompilation`. This not only includes the
143+
/// test cases, but also the function definition in the inner sierra program.
144+
/// This means that the matching tests are not even compiled.
145+
///
146+
/// DISCLAIMER: This is a hacky and temporary function, used to run corelib tests
147+
/// when not all libfuncs are implemented.
148+
fn filter_test_case_compilation(
149+
mut compiled: TestCompilation,
150+
compilation_filter: &[String],
151+
) -> TestCompilation {
152+
let should_skip_test = |name: &str| -> bool {
153+
compilation_filter
154+
.iter()
155+
.any(|filter| name.contains(filter))
156+
};
157+
158+
// Remove matching function definitions.
159+
compiled.sierra_program.program.funcs.retain(|f| {
160+
let name =
161+
f.id.debug_name
162+
.as_ref()
163+
.map(|s| s.to_string())
164+
.unwrap_or_default();
165+
166+
let skipped = should_skip_test(name.as_str());
167+
168+
if skipped {
169+
println!("skipping compilation of: {}", name);
170+
}
171+
172+
!skipped
173+
});
174+
175+
// Ignore matching test cases.
176+
compiled
177+
.metadata
178+
.named_tests
179+
.iter_mut()
180+
.for_each(|(test, case)| {
181+
if should_skip_test(&test) {
182+
case.ignored = true
183+
}
184+
});
185+
186+
compiled
187+
}

0 commit comments

Comments
 (0)