.*)\]:.*").unwrap();
+// // Store all covered error codes
+// let mut found_codes = BTreeMap::new();
+// let re = Regex::new(r"Error \[(?P.*)\]:.*").unwrap();
- for (path, content) in tests.into_iter() {
- if let Some(config) = extract_test_config(&content) {
- // Skip passing tests.
- if config.expectation == Expectation::Pass {
- continue;
- }
+// for (path, content) in tests.into_iter() {
+// if let Some(config) = extract_test_config(&content) {
+// // Skip passing tests.
+// if config.expectation == Expectation::Pass {
+// continue;
+// }
- let mut expectation_path = expectation_dir.clone();
+// let mut expectation_path = expectation_dir.clone();
- let path = PathBuf::from(path);
- let relative_path = path.strip_prefix(&test_dir).expect("path error for test");
+// let path = PathBuf::from(path);
+// let relative_path = path.strip_prefix(&test_dir).expect("path error for test");
- let mut relative_expectation_path = relative_path.to_str().unwrap().to_string();
- relative_expectation_path += ".out";
+// let mut relative_expectation_path = relative_path.to_str().unwrap().to_string();
+// relative_expectation_path += ".out";
- // Add expectation category
- if relative_expectation_path.starts_with("compiler") {
- expectation_path.push("compiler");
- } else {
- expectation_path.push("parser");
- }
- expectation_path.push(&relative_expectation_path);
+// // Add expectation category
+// if relative_expectation_path.starts_with("compiler") {
+// expectation_path.push("compiler");
+// } else {
+// expectation_path.push("parser");
+// }
+// expectation_path.push(&relative_expectation_path);
- if expectation_path.exists() {
- let raw = std::fs::read_to_string(&expectation_path).expect("failed to read expectations file");
- let expectation: TestExpectation =
- serde_yaml::from_str(&raw).expect("invalid yaml in expectations file");
+// if expectation_path.exists() {
+// let raw = std::fs::read_to_string(&expectation_path).expect("failed to read expectations file");
+// let expectation: TestExpectation =
+// serde_yaml::from_str(&raw).expect("invalid yaml in expectations file");
- for value in expectation.outputs {
- if let serde_yaml::Value::String(message) = value {
- if let Some(caps) = re.captures(&message) {
- if let Some(code) = caps.name("code") {
- let files = found_codes
- .entry(code.as_str().to_string())
- .or_insert_with(HashSet::new);
- let path = expectation_path
- .strip_prefix(test_dir.clone())
- .expect("invalid prefix for expectation path");
- files.insert(PathBuf::from(path));
- }
- }
- }
- }
- }
- }
- }
+// for value in expectation.outputs {
+// if let serde_yaml::Value::String(message) = value {
+// if let Some(caps) = re.captures(&message) {
+// if let Some(code) = caps.name("code") {
+// let files = found_codes
+// .entry(code.as_str().to_string())
+// .or_insert_with(HashSet::new);
+// let path = expectation_path
+// .strip_prefix(test_dir.clone())
+// .expect("invalid prefix for expectation path");
+// files.insert(PathBuf::from(path));
+// }
+// }
+// }
+// }
+// }
+// }
+// }
- // Collect all defined error codes.
- let mut all_codes = HashSet::new();
- collect_error_codes(
- &mut all_codes,
- AstError::message_type(),
- AstError::code_identifier(),
- AstError::code_mask(),
- AstError::num_exit_codes(),
- );
- collect_error_codes(
- &mut all_codes,
- InputError::message_type(),
- InputError::code_identifier(),
- InputError::code_mask(),
- InputError::num_exit_codes(),
- );
- collect_error_codes(
- &mut all_codes,
- PackageError::message_type(),
- PackageError::code_identifier(),
- PackageError::code_mask(),
- PackageError::num_exit_codes(),
- );
- collect_error_codes(
- &mut all_codes,
- ParserError::message_type(),
- ParserError::code_identifier(),
- ParserError::code_mask(),
- ParserError::num_exit_codes(),
- );
+// // Collect all defined error codes.
+// let mut all_codes = HashSet::new();
+// collect_error_codes(
+// &mut all_codes,
+// AstError::message_type(),
+// AstError::code_identifier(),
+// AstError::code_mask(),
+// AstError::num_exit_codes(),
+// );
+// collect_error_codes(
+// &mut all_codes,
+// InputError::message_type(),
+// InputError::code_identifier(),
+// InputError::code_mask(),
+// InputError::num_exit_codes(),
+// );
+// collect_error_codes(
+// &mut all_codes,
+// PackageError::message_type(),
+// PackageError::code_identifier(),
+// PackageError::code_mask(),
+// PackageError::num_exit_codes(),
+// );
+// collect_error_codes(
+// &mut all_codes,
+// ParserError::message_type(),
+// ParserError::code_identifier(),
+// ParserError::code_mask(),
+// ParserError::num_exit_codes(),
+// );
- // Repackage data into values compatible with serde_yaml
- let mut covered_errors = serde_yaml::Mapping::new();
- let mut unknown_errors = serde_yaml::Mapping::new();
+// // Repackage data into values compatible with serde_yaml
+// let mut covered_errors = serde_yaml::Mapping::new();
+// let mut unknown_errors = serde_yaml::Mapping::new();
- for (code, paths) in found_codes.iter() {
- let mut yaml_paths = Vec::with_capacity(paths.len());
- for path in paths {
- yaml_paths.push(path.to_str().unwrap());
- }
- yaml_paths.sort_unstable();
- let yaml_paths = yaml_paths.iter().map(|s| Value::String(s.to_string())).collect();
+// for (code, paths) in found_codes.iter() {
+// let mut yaml_paths = Vec::with_capacity(paths.len());
+// for path in paths {
+// yaml_paths.push(path.to_str().unwrap());
+// }
+// yaml_paths.sort_unstable();
+// let yaml_paths = yaml_paths.iter().map(|s| Value::String(s.to_string())).collect();
- if all_codes.contains(code) {
- covered_errors.insert(Value::String(code.to_owned()), Value::Sequence(yaml_paths));
- } else {
- unknown_errors.insert(Value::String(code.to_owned()), Value::Sequence(yaml_paths));
- }
- all_codes.remove(code);
- }
+// if all_codes.contains(code) {
+// covered_errors.insert(Value::String(code.to_owned()), Value::Sequence(yaml_paths));
+// } else {
+// unknown_errors.insert(Value::String(code.to_owned()), Value::Sequence(yaml_paths));
+// }
+// all_codes.remove(code);
+// }
- let mut codes: Vec = all_codes.drain().collect();
- codes.sort();
+// let mut codes: Vec = all_codes.drain().collect();
+// codes.sort();
- let mut uncovered_errors = Vec::new();
- for code in codes {
- uncovered_errors.push(Value::String(code))
- }
+// let mut uncovered_errors = Vec::new();
+// for code in codes {
+// uncovered_errors.push(Value::String(code))
+// }
- let mut uncovered_information = serde_yaml::Mapping::new();
- uncovered_information.insert(
- Value::String(String::from("count")),
- Value::Number(serde_yaml::Number::from(uncovered_errors.len())),
- );
- uncovered_information.insert(Value::String(String::from("codes")), Value::Sequence(uncovered_errors));
+// let mut uncovered_information = serde_yaml::Mapping::new();
+// uncovered_information.insert(
+// Value::String(String::from("count")),
+// Value::Number(serde_yaml::Number::from(uncovered_errors.len())),
+// );
+// uncovered_information.insert(Value::String(String::from("codes")), Value::Sequence(uncovered_errors));
- let mut covered_information = serde_yaml::Mapping::new();
- covered_information.insert(
- Value::String(String::from("count")),
- Value::Number(serde_yaml::Number::from(covered_errors.len())),
- );
- covered_information.insert(Value::String(String::from("codes")), Value::Mapping(covered_errors));
+// let mut covered_information = serde_yaml::Mapping::new();
+// covered_information.insert(
+// Value::String(String::from("count")),
+// Value::Number(serde_yaml::Number::from(covered_errors.len())),
+// );
+// covered_information.insert(Value::String(String::from("codes")), Value::Mapping(covered_errors));
- let mut unknown_information = serde_yaml::Mapping::new();
- unknown_information.insert(
- Value::String(String::from("count")),
- Value::Number(serde_yaml::Number::from(unknown_errors.len())),
- );
- unknown_information.insert(Value::String(String::from("codes")), Value::Mapping(unknown_errors));
+// let mut unknown_information = serde_yaml::Mapping::new();
+// unknown_information.insert(
+// Value::String(String::from("count")),
+// Value::Number(serde_yaml::Number::from(unknown_errors.len())),
+// );
+// unknown_information.insert(Value::String(String::from("codes")), Value::Mapping(unknown_errors));
- let mut results = serde_yaml::Mapping::new();
- results.insert(
- Value::String(String::from("uncovered")),
- Value::Mapping(uncovered_information),
- );
+// let mut results = serde_yaml::Mapping::new();
+// results.insert(
+// Value::String(String::from("uncovered")),
+// Value::Mapping(uncovered_information),
+// );
- results.insert(
- Value::String(String::from("covered")),
- Value::Mapping(covered_information),
- );
- results.insert(
- Value::String(String::from("unknown")),
- Value::Mapping(unknown_information),
- );
+// results.insert(
+// Value::String(String::from("covered")),
+// Value::Mapping(covered_information),
+// );
+// results.insert(
+// Value::String(String::from("unknown")),
+// Value::Mapping(unknown_information),
+// );
- // Output error coverage results
- if let Some(pathbuf) = opt.output {
- let file = fs::File::create(pathbuf).expect("error creating output file");
- serde_yaml::to_writer(file, &results).expect("serialization failed for error coverage report");
- } else {
- serde_yaml::to_writer(io::stdout(), &results).expect("serialization failed for error coverage report");
- }
+// // Output error coverage results
+// if let Some(pathbuf) = opt.output {
+// let file = fs::File::create(pathbuf).expect("error creating output file");
+// serde_yaml::to_writer(file, &results).expect("serialization failed for error coverage report");
+// } else {
+// serde_yaml::to_writer(io::stdout(), &results).expect("serialization failed for error coverage report");
+// }
- Ok(())
-}
+// Ok(())
+// }
-fn collect_error_codes(
- codes: &mut HashSet,
- error_type: String,
- code_identifier: i8,
- exit_code_mask: i32,
- num_exit_codes: i32,
-) {
- for exit_code in 0..num_exit_codes {
- codes.insert(format!(
- "E{}{:0>3}{:0>4}",
- error_type,
- code_identifier,
- exit_code_mask + exit_code,
- ));
- }
-}
+// fn collect_error_codes(
+// codes: &mut HashSet,
+// error_type: String,
+// code_identifier: i8,
+// exit_code_mask: i32,
+// num_exit_codes: i32,
+// ) {
+// for exit_code in 0..num_exit_codes {
+// codes.insert(format!(
+// "E{}{:0>3}{:0>4}",
+// error_type,
+// code_identifier,
+// exit_code_mask + exit_code,
+// ));
+// }
+// }
-fn handle_error(res: Result<(), Box>) {
- match res {
- Ok(_) => (),
- Err(err) => {
- eprintln!("Error: {}", err);
- std::process::exit(1);
- }
- }
-}
+// fn handle_error(res: Result<(), Box>) {
+// match res {
+// Ok(_) => (),
+// Err(err) => {
+// eprintln!("Error: {}", err);
+// std::process::exit(1);
+// }
+// }
+// }
+
+fn main() {}
diff --git a/tests/test-framework/src/fetch.rs b/tests/test-framework/src/fetch.rs
index 4bb1b1b502..643f65b945 100644
--- a/tests/test-framework/src/fetch.rs
+++ b/tests/test-framework/src/fetch.rs
@@ -18,22 +18,20 @@ use std::{fs, path::Path};
use walkdir::WalkDir;
-pub fn find_tests + Copy>(path: T, filter: T) -> Vec<(String, String)> {
- let count = WalkDir::new(path)
+pub fn find_tests + Copy>(path: T) -> Vec<(String, String)> {
+ WalkDir::new(path)
.into_iter()
.flatten()
.filter_map(|f| {
let path = f.path();
- if matches!(path.extension(), Some(s) if s == "leo") && !path.starts_with(filter) {
+ if matches!(path.extension(), Some(s) if s == "leo") {
let content = fs::read_to_string(path).expect("failed to read test");
Some((path.to_str().unwrap_or_default().to_string(), content))
} else {
None
}
})
- .collect::>();
- dbg!("find_tests count {}", count.len());
- count
+ .collect::>()
}
pub fn split_tests_one_line(source: &str) -> Vec<&str> {
diff --git a/tests/test-framework/src/runner.rs b/tests/test-framework/src/runner.rs
index 2d21c31e4e..4033e5f2d7 100644
--- a/tests/test-framework/src/runner.rs
+++ b/tests/test-framework/src/runner.rs
@@ -88,9 +88,13 @@ pub struct TestCases {
}
impl TestCases {
- fn new(additional_check: impl Fn(&TestConfig) -> bool) -> (Self, Vec) {
+ fn new(expectation_category: &str, additional_check: impl Fn(&TestConfig) -> bool) -> (Self, Vec) {
let mut path_prefix = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path_prefix.push("../../tests/");
+ path_prefix.push(expectation_category);
+ if let Ok(p) = std::env::var("TEST_FILTER") {
+ path_prefix.push(p)
+ }
let mut expectation_dir = path_prefix.clone();
expectation_dir.push("expectations");
@@ -105,10 +109,9 @@ impl TestCases {
}
fn load_tests(&mut self, additional_check: impl Fn(&TestConfig) -> bool) -> Vec {
- let filter = PathBuf::from(std::env::var("TEST_FILTER").unwrap_or_default().trim());
let mut configs = Vec::new();
- self.tests = find_tests(&self.path_prefix, &filter)
+ self.tests = find_tests(&self.path_prefix)
.into_iter()
.filter(|(path, content)| {
let config = match extract_test_config(content) {
@@ -131,12 +134,7 @@ impl TestCases {
configs
}
- pub(crate) fn process_tests(
- &mut self,
- configs: Vec,
- expectation_category: &str,
- mut process: P,
- ) -> Vec
+ pub(crate) fn process_tests(&mut self, configs: Vec, mut process: P) -> Vec
where
P: FnMut(&mut Self, (&Path, &str, &str, TestConfig)) -> O,
{
@@ -144,12 +142,10 @@ impl TestCases {
std::env::set_var("LEO_TESTFRAMEWORK", "true");
let mut output = Vec::new();
- dbg!("in proccesing: tests {}, configs {}", self.tests.len(), configs.len());
for ((path, content), config) in self.tests.clone().iter().zip(configs.into_iter()) {
let path = Path::new(&path);
- let relative_path = path.strip_prefix(&self.path_prefix).expect("path error for test");
- let test_name = relative_path
+ let test_name = path
.file_stem()
.expect("no file name for test")
.to_str()
@@ -202,107 +198,94 @@ impl TestCases {
}
pub fn run_tests(runner: &T, expectation_category: &str) {
- let (mut cases, configs) = Self::new(|_| false);
+ let (mut cases, configs) = Self::new(expectation_category, |_| true);
let mut pass_categories = 0;
let mut pass_tests = 0;
let mut fail_tests = 0;
let mut outputs = vec![];
- dbg!("running tests");
- cases.process_tests(
- configs,
- expectation_category,
- |cases, (path, content, test_name, config)| {
- dbg!("processing tests");
- let namespace = match runner.resolve_namespace(&config.namespace) {
- None => todo!("continue"),
- Some(ns) => ns,
- };
+ cases.process_tests(configs, |cases, (path, content, test_name, config)| {
+ let namespace = match runner.resolve_namespace(&config.namespace) {
+ Some(ns) => ns,
+ None => return,
+ };
- let (expectation_path, expectations) = cases.clear_expectations(path, expectation_category);
+ let (expectation_path, expectations) = cases.clear_expectations(path, expectation_category);
- let tests = match namespace.parse_type() {
- ParseType::Line => crate::fetch::split_tests_one_line(content)
- .into_iter()
- .map(|x| x.to_string())
- .collect(),
- ParseType::ContinuousLines => crate::fetch::split_tests_two_line(content),
- ParseType::Whole => vec![content.to_string()],
- };
- dbg!("tests len{}", tests.len());
+ let tests = match namespace.parse_type() {
+ ParseType::Line => crate::fetch::split_tests_one_line(content)
+ .into_iter()
+ .map(|x| x.to_string())
+ .collect(),
+ ParseType::ContinuousLines => crate::fetch::split_tests_two_line(content),
+ ParseType::Whole => vec![content.to_string()],
+ };
- let mut errors = vec![];
- if let Some(expectations) = expectations.as_ref() {
- if tests.len() != expectations.outputs.len() {
- errors.push(TestError::MismatchedTestExpectationLength);
- }
+ let mut errors = vec![];
+ if let Some(expectations) = expectations.as_ref() {
+ if tests.len() != expectations.outputs.len() {
+ errors.push(TestError::MismatchedTestExpectationLength);
}
+ }
- let mut new_outputs = vec![];
- let mut expected_output = expectations.as_ref().map(|x| x.outputs.iter());
- for (i, test) in tests.into_iter().enumerate() {
- let expected_output = expected_output.as_mut().and_then(|x| x.next()).cloned();
- println!("running test {} @ '{}'", test_name, path.to_str().unwrap());
- let panic_buf = set_hook();
- let leo_output = panic::catch_unwind(|| {
- namespace.run_test(Test {
- name: test_name.to_string(),
- content: test.clone(),
- path: path.into(),
- config: config.extra.clone(),
- })
- });
- let output = take_hook(leo_output, panic_buf);
- if let Some(error) = emit_errors(&test, &output, &config.expectation, expected_output, i) {
- fail_tests += 1;
- errors.push(error);
- } else {
- pass_tests += 1;
- new_outputs.push(
- output
- .unwrap()
- .as_ref()
- .map(|x| serde_yaml::to_value(x).expect("serialization failed"))
- .unwrap_or_else(|e| Value::String(e.clone())),
- );
- }
- }
-
- if errors.is_empty() {
- if expectations.is_none() {
- outputs.push((
- expectation_path,
- TestExpectation {
- namespace: config.namespace,
- expectation: config.expectation,
- outputs: new_outputs,
- },
- ));
- }
- pass_categories += 1;
- } else {
- cases.fail_categories.push(TestFailure {
- path: path.to_str().unwrap().to_string(),
- errors,
+ let mut new_outputs = vec![];
+ let mut expected_output = expectations.as_ref().map(|x| x.outputs.iter());
+ for (i, test) in tests.into_iter().enumerate() {
+ let expected_output = expected_output.as_mut().and_then(|x| x.next()).cloned();
+ println!("running test {} @ '{}'", test_name, path.to_str().unwrap());
+ let panic_buf = set_hook();
+ let leo_output = panic::catch_unwind(|| {
+ namespace.run_test(Test {
+ name: test_name.to_string(),
+ content: test.clone(),
+ path: path.into(),
+ config: config.extra.clone(),
})
+ });
+ let output = take_hook(leo_output, panic_buf);
+ if let Some(error) = emit_errors(&test, &output, &config.expectation, expected_output, i) {
+ fail_tests += 1;
+ errors.push(error);
+ } else {
+ pass_tests += 1;
+ new_outputs.push(
+ output
+ .unwrap()
+ .as_ref()
+ .map(|x| serde_yaml::to_value(x).expect("serialization failed"))
+ .unwrap_or_else(|e| Value::String(e.clone())),
+ );
}
- },
- );
- }
-}
+ }
-struct Bencher;
-
-impl Bencher {
- fn get_benches() -> Vec<(String, String)> {
- let (mut cases, configs) = TestCases::new(|config| config.expectation == TestExpectationMode::Fail);
-
- let expectation_category = "compiler";
- let tests = cases.process_tests(configs, expectation_category, |_, (_, content, test_name, _)| {
- (test_name.to_string(), content.to_string())
+ if errors.is_empty() {
+ if expectations.is_none() {
+ outputs.push((
+ expectation_path,
+ TestExpectation {
+ namespace: config.namespace,
+ expectation: config.expectation,
+ outputs: new_outputs,
+ },
+ ));
+ }
+ pass_categories += 1;
+ } else {
+ cases.fail_categories.push(TestFailure {
+ path: path.to_str().unwrap().to_string(),
+ errors,
+ })
+ }
});
-
- tests
}
}
+
+/// returns (name, content) for all benchmark samples
+pub fn get_benches() -> Vec<(String, String)> {
+ let (mut cases, configs) = TestCases::new("compiler", |config| config.expectation != TestExpectationMode::Fail);
+
+ cases.process_tests(configs, |_, (_, content, test_name, _)| {
+ (test_name.to_string(), content.to_string())
+ })
+}