Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
wip: convert tests to simpler format
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorenzi committed Jun 23, 2021
1 parent b518b7d commit 560c013
Show file tree
Hide file tree
Showing 499 changed files with 3,921 additions and 200 deletions.
60 changes: 21 additions & 39 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,61 +25,43 @@ fn generate_tests()
println!("{:?}", destination);
let mut f = std::fs::File::create(&destination).unwrap();

generate_tests_from_folder(&mut f, &std::env::current_dir().unwrap().join("tests"));
generate_tests_from_folder(
&mut f,
&std::env::current_dir().unwrap().join("tests2"),
&String::new());
}


fn generate_tests_from_folder(f: &mut dyn std::io::Write, folder: &std::path::Path)
fn generate_tests_from_folder(f: &mut dyn std::io::Write, folder: &std::path::Path, test_name: &String)
{
for entry in std::fs::read_dir(folder).unwrap()
{
let entry = entry.unwrap();
let path = entry.path();
let file_stem = path.file_stem().unwrap().to_string_lossy();
println!("cargo:rerun-if-changed={}", path.to_string_lossy());

if path.is_file()
{
let contents = std::fs::read_to_string(&path).unwrap();
//println!("{:?}: {:?}", &path, &contents);
generate_tests_from_file(f, &path, &contents);
}
else
{
generate_tests_from_folder(f, &path);
}
}
}


fn generate_tests_from_file(f: &mut dyn std::io::Write, filepath: &std::path::PathBuf, contents: &str)
{
let filename = filepath.file_stem().unwrap().to_string_lossy();
let mut auto_subfile_index = 1;

for line in contents.lines()
{
if line.starts_with("; :::")
{
let mut name = format!("{}", &line.get(5..).unwrap().trim());
if name.len() > 0
{
continue;
}

if name.len() == 0
{
name = format!("{}", auto_subfile_index);
auto_subfile_index += 1;
}

let mut new_test_name = test_name.clone();
new_test_name.push_str(&file_stem);

write!(f,
"#[test]
fn {}_{}()
fn {}()
{{
test_subfile({:?}, {:?});
test_file({:?});
}}",
filename, name,
filepath, name).unwrap();
new_test_name.replace(".", "_"),
path).unwrap();
}
else
{
let mut new_test_name = test_name.clone();
new_test_name.push_str(&file_stem);
new_test_name.push_str("_");

generate_tests_from_folder(f, &path, &new_test_name);
}
}
}
101 changes: 99 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,107 @@ extern crate customasm;

fn main()
{
let args: Vec<String> = std::env::args().collect();
split_tests();
/*let args: Vec<String> = std::env::args().collect();
let mut fileserver = customasm::util::FileServerReal::new();
if let Err(()) = customasm::driver::drive(&args, &mut fileserver)
{ std::process::exit(1); }
{ std::process::exit(1); }*/
}




fn split_tests()
{
let out_folder = std::env::current_dir().unwrap().join("tests2");
split_tests_from_folder(&std::env::current_dir().unwrap().join("tests"), &out_folder);
}


fn split_tests_from_folder(folder: &std::path::Path, out_folder: &std::path::Path)
{
for entry in std::fs::read_dir(folder).unwrap()
{
let entry = entry.unwrap();
let path = entry.path();

if path.is_file()
{
let contents = std::fs::read_to_string(&path).unwrap();
//println!("{:?}: {:?}", &path, &contents);
split_tests_from_file(&path, &out_folder, &contents);
}
else
{
split_tests_from_folder(&path, &out_folder);
}
}
}


fn split_tests_from_file(filepath: &std::path::PathBuf, out_folder: &std::path::Path, contents: &str)
{
let filename = filepath.file_stem().unwrap().to_string_lossy();
let mut auto_subfile_index = 1;

let lines = contents.lines().collect::<Vec<_>>();
let mut i = 0;

println!("{}.asm", &filename.as_ref());

let mut cur_include_data = String::new();

while i < lines.len()
{
if lines[i].starts_with("; :::")
{
let mut name = format!("{}", &lines[i].get(5..).unwrap().trim());

if name.len() == 0
{
name = format!("{}.asm", auto_subfile_index);
auto_subfile_index += 1;
}

let mut data = String::new();

if name != "include"
{
data.push_str(&cur_include_data);
}

i += 1;
while i < lines.len() && !lines[i].starts_with("; :::")
{
if !lines[i].starts_with("; ==")
{
data.push_str(&lines[i].replace("error: :", "error:_:").replace("note: :", "note:_:"));
data.push_str("\n");
}

i += 1;
}

if name == "include"
{
cur_include_data = data;
continue;
}

let mut out_path = out_folder.to_path_buf();
out_path.push(&filename.as_ref());
out_path.push(&name);

println!("{}/{}.asm", &filename.as_ref(), name);

std::fs::create_dir(out_path.parent().unwrap()).unwrap();
std::fs::write(out_path, &data.trim()).unwrap();
}
else
{
i += 1;
}
}
}
Loading

0 comments on commit 560c013

Please sign in to comment.