-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10a3f87
commit 3f9f2ad
Showing
4 changed files
with
66 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::env; | ||
use std::fs::{self, File}; | ||
use std::io::Write; | ||
use std::path::Path; | ||
|
||
fn main() { | ||
let input_path = Path::new("tests/input"); | ||
let output_path = Path::new("tests/output"); | ||
|
||
let var = env::var("OUT_DIR").unwrap(); | ||
let out_dir = Path::new(&var); | ||
let convert_path = out_dir.join("convert.rs"); | ||
let idempotent_path = out_dir.join("idempotent.rs"); | ||
|
||
let mut convert = File::create(&convert_path).unwrap(); | ||
let mut idempotent = File::create(&idempotent_path).unwrap(); | ||
|
||
for entry in fs::read_dir(input_path).unwrap() { | ||
let entry = entry.unwrap(); | ||
let path = entry.path(); | ||
if !path.is_file() { | ||
continue; | ||
} | ||
let file_name = path.file_name().unwrap(); | ||
let test_name = path.file_stem().unwrap().to_str().unwrap(); | ||
let file_name = file_name.to_str().unwrap(); | ||
let input_file = input_path.join(file_name).to_str().unwrap().to_owned(); | ||
let output_file = output_path.join(file_name).to_str().unwrap().to_owned(); | ||
writeln!( | ||
convert, | ||
r#" | ||
#[test] | ||
fn test_{}() {{ | ||
compare("{}", "{}", "{}"); | ||
}} | ||
"#, | ||
test_name, file_name, input_file, output_file | ||
) | ||
.unwrap(); | ||
writeln!( | ||
idempotent, | ||
r#" | ||
#[test] | ||
fn test_{}() {{ | ||
compare("{}", "{}"); | ||
}} | ||
"#, | ||
test_name, file_name, output_file | ||
) | ||
.unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
use std::{ffi::OsString, path::PathBuf}; | ||
use std::{path::PathBuf, str::FromStr}; | ||
mod common; | ||
use common::{get_json, read, run}; | ||
use common::{read, run}; | ||
|
||
fn compare(name: &OsString, input: &PathBuf, output: &PathBuf) { | ||
fn compare(name: &str, input: &str, output: &str) { | ||
println!("comparing {:?}", name); | ||
let input = read(input).expect("failed to read input"); | ||
let expected_output = read(output).expect("failed to read output file"); | ||
let input = PathBuf::from_str(input).unwrap(); | ||
let output = PathBuf::from_str(output).unwrap(); | ||
let input = read(&input).expect("failed to read input"); | ||
let expected_output = read(&output).expect("failed to read output file"); | ||
let output = run(input).expect("failed to execute a program"); | ||
assert!(expected_output == output); | ||
} | ||
|
||
#[test] | ||
fn convert() { | ||
let input = get_json("tests/input").expect("failed to read input dir"); | ||
assert!(!input.is_empty()); | ||
let output = get_json("tests/output").expect("failed to read output dir"); | ||
assert!(!output.is_empty()); | ||
input | ||
.into_iter() | ||
.filter_map(|i| output.get(&i.0).map(|o| (i.0, i.1, o))) | ||
.for_each(|x| compare(&x.0, &x.1, x.2)); | ||
} | ||
include!(concat!(env!("OUT_DIR"), "/convert.rs")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
use std::{ffi::OsString, path::PathBuf}; | ||
use std::{path::PathBuf, str::FromStr}; | ||
mod common; | ||
use common::{get_json, read, run}; | ||
use common::{read, run}; | ||
|
||
fn compare(name: &OsString, input: &PathBuf) { | ||
fn compare(name: &str, input: &str) { | ||
println!("comparing {:?}", name); | ||
let input = read(input).expect("failed to read input"); | ||
let input = PathBuf::from_str(input).unwrap(); | ||
let input = read(&input).expect("failed to read input"); | ||
let output = run(input.clone()).expect("failed to execute a program"); | ||
assert!(input == output); | ||
} | ||
|
||
#[test] | ||
fn idempotent() { | ||
let input = get_json("tests/output").expect("failed to read input dir"); | ||
assert!(!input.is_empty()); | ||
input.into_iter().for_each(|x| compare(&x.0, &x.1)); | ||
} | ||
include!(concat!(env!("OUT_DIR"), "/idempotent.rs")); |