Skip to content

Commit

Permalink
feat: migrate builtin test expectations to static file
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra committed Jul 14, 2024
1 parent 89127dc commit e814e89
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 133 deletions.
19 changes: 19 additions & 0 deletions include/harness/abi-cafe-rules.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# i128 types are fake on windows so this is all random garbage that might
# not even compile, but that datapoint is a little interesting/useful
# so let's keep running them and just ignore the result for now.
#
# Anyone who cares about this situation more can make the expectations more precise.
[targets.x86_64-pc-windows-msvc."i128::cc_toolchain"]
random = true
[targets.x86_64-pc-windows-msvc."u128::cc_toolchain"]
random = true

# FIXME: investigate why this is failing to build
[targets.x86_64-pc-windows-msvc."EmptyStruct::cc_toolchain"]
busted = "build"
[targets.x86_64-pc-windows-msvc."EmptyStructInside::cc_toolchain"]
busted = "build"

# CI GCC is too old to support _Float16
[targets.x86_64-unknown-liinux-gnu."f16::conv_c"]
random = true
2 changes: 1 addition & 1 deletion kdl-script/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub enum Repr {
Transparent,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, serde::Serialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize)]
pub enum LangRepr {
Rust,
C,
Expand Down
6 changes: 5 additions & 1 deletion src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,16 @@ pub fn load_file(file: &File) -> String {
clean_newlines(string)
}

pub fn tests() -> &'static Dir<'static> {
pub fn static_tests() -> &'static Dir<'static> {
INCLUDES
.get_dir("tests")
.expect("includes didn't contain ./test")
}

pub fn static_rules() -> String {
get_file("harness/abi-cafe-rules.toml")
}

fn clean_newlines(input: &str) -> String {
input.replace('\r', "")
}
71 changes: 2 additions & 69 deletions src/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct TestHarness {
paths: Paths,
toolchains: Toolchains,
tests: SortedMap<TestId, Arc<Test>>,
test_rules: ExpectFile,
test_rules: Vec<ExpectFile>,
tests_with_vals: Memoized<(TestId, ValueGeneratorKind), Arc<TestWithVals>>,
tests_with_toolchain:
Memoized<(TestId, ValueGeneratorKind, ToolchainId), Arc<TestWithToolchain>>,
Expand All @@ -41,7 +41,7 @@ pub struct TestHarness {
}

impl TestHarness {
pub fn new(test_rules: ExpectFile, tests: SortedMap<TestId, Arc<Test>>, cfg: &Config) -> Self {
pub fn new(test_rules: Vec<ExpectFile>, tests: SortedMap<TestId, Arc<Test>>, cfg: &Config) -> Self {
let toolchains = toolchains::create_toolchains(cfg);
Self {
paths: cfg.paths.clone(),
Expand Down Expand Up @@ -275,73 +275,6 @@ impl TestHarness {
output
}

pub fn parse_test_pattern(&self, input: &str) -> Result<TestKeyPattern, String> {
let separator = "::";
let parts = input.split(separator).collect::<Vec<_>>();

let [test, rest @ ..] = &parts[..] else {
todo!();
};
let mut key = TestKeyPattern {
test: (!test.is_empty()).then(|| test.to_string()),
caller: None,
callee: None,
toolchain: None,
options: TestOptionsPattern {
convention: None,
repr: None,
functions: None,
val_writer: None,
val_generator: None,
},
};
for part in rest {
// pairs
if let Some((caller, callee)) = part.split_once("_calls_") {
key.caller = Some(caller.to_owned());
key.callee = Some(callee.to_owned());
continue;
}
if let Some(caller) = part.strip_suffix("_caller") {
key.caller = Some(caller.to_owned());
continue;
}
if let Some(callee) = part.strip_suffix("_callee") {
key.callee = Some(callee.to_owned());
continue;
}
if let Some(toolchain) = part.strip_suffix("_toolchain") {
key.toolchain = Some(toolchain.to_owned());
continue;
}

// repr
if let Some(repr) = part.strip_prefix("repr_") {
key.options.repr = Some(repr.parse()?);
continue;
}

// conv
if let Some(conv) = part.strip_prefix("conv_") {
key.options.convention = Some(conv.parse()?);
continue;
}
// generator
if let Ok(val_generator) = part.parse() {
key.options.val_generator = Some(val_generator);
continue;
}
// writer
if let Ok(val_writer) = part.parse() {
key.options.val_writer = Some(val_writer);
continue;
}

return Err(format!("unknown testkey part: {part}"));
}
Ok(key)
}

/// The name of a test for pretty-printing.
pub fn full_test_name(&self, key: &TestKey) -> String {
self.base_id(key, None, "::")
Expand Down
11 changes: 9 additions & 2 deletions src/harness/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ impl Pathish {
}
}

pub fn find_test_rules(cfg: &Config) -> Result<ExpectFile, GenerateError> {
pub fn find_test_rules(cfg: &Config) -> Result<Vec<ExpectFile>, GenerateError> {
let static_rules = find_test_rules_static()?;
let rules = find_test_rules_runtime(&cfg.paths.runtime_rules_file)?;
Ok(vec![static_rules, rules])
}

pub fn find_test_rules_static() -> Result<ExpectFile, GenerateError> {
let data = files::static_rules();
let rules = toml::from_str(&data)?;
Ok(rules)
}

Expand Down Expand Up @@ -92,7 +99,7 @@ pub fn find_tests_static(
return Ok(tests);
}

let mut dirs = vec![crate::files::tests()];
let mut dirs = vec![crate::files::static_tests()];
while let Some(dir) = dirs.pop() {
for entry in dir.entries() {
// If it's a dir, add it to the working set
Expand Down
Loading

0 comments on commit e814e89

Please sign in to comment.