aboutsummaryrefslogtreecommitdiff
path: root/tests/ref.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ref.rs')
-rw-r--r--tests/ref.rs143
1 files changed, 61 insertions, 82 deletions
diff --git a/tests/ref.rs b/tests/ref.rs
index be0150ef..c91fdc78 100644
--- a/tests/ref.rs
+++ b/tests/ref.rs
@@ -1,99 +1,78 @@
extern crate alacritty;
-extern crate serde_json;
+extern crate serde_json as json;
+extern crate test;
-/// ref tests
-mod reference {
- use std::fs::File;
- use std::io::{self, Read};
- use std::path::Path;
+use std::env;
+use std::fs::File;
+use std::io::{self, Read};
+use std::path::{Path, PathBuf};
+use test::{TestDescAndFn, TestDesc, TestFn, ShouldPanic, TestName, test_main};
- use serde_json as json;
+use alacritty::Grid;
+use alacritty::Term;
+use alacritty::term::Cell;
+use alacritty::term::SizeInfo;
+use alacritty::ansi;
- use alacritty::Grid;
- use alacritty::Term;
- use alacritty::term::Cell;
- use alacritty::term::SizeInfo;
- use alacritty::ansi;
+fn main() {
+ let test_dir = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/ref"));
- /// The /dev/null of io::Write
- struct Void;
+ let args = env::args().collect::<Vec<_>>();
- impl io::Write for Void {
- fn write(&mut self, bytes: &[u8]) -> io::Result<usize> {
- Ok(bytes.len())
- }
+ let tests = test_dir
+ .read_dir()
+ .unwrap()
+ .map(|e| desc(e.unwrap().path()))
+ .collect();
- fn flush(&mut self) -> io::Result<()> {
- Ok(())
- }
- }
+ test_main(&args, tests);
+}
- macro_rules! ref_file {
- ($ref_name:ident, $file:expr) => {
- concat!(
- env!("CARGO_MANIFEST_DIR"),
- "/tests/ref/", stringify!($ref_name), "/", $file
- )
- }
+fn desc(dir: PathBuf) -> TestDescAndFn {
+ TestDescAndFn {
+ desc: TestDesc {
+ name: TestName::DynTestName(dir.file_name().unwrap().to_string_lossy().into_owned()),
+ ignore: false,
+ should_panic: ShouldPanic::No,
+ },
+ testfn: TestFn::dyn_test_fn(move || ref_test(&dir)),
}
+}
- fn read_u8<P>(path: P) -> Vec<u8>
- where P: AsRef<Path>
- {
- let mut res = Vec::new();
- File::open(path.as_ref()).unwrap()
- .read_to_end(&mut res).unwrap();
+fn read_u8<P>(path: P) -> Vec<u8>
+ where P: AsRef<Path>
+{
+ let mut res = Vec::new();
+ File::open(path.as_ref()).unwrap()
+ .read_to_end(&mut res).unwrap();
- res
- }
+ res
+}
- fn read_string<P>(path: P) -> String
- where P: AsRef<Path>
- {
- let mut res = String::new();
- File::open(path.as_ref()).unwrap()
- .read_to_string(&mut res).unwrap();
+fn read_string<P>(path: P) -> String
+ where P: AsRef<Path>
+{
+ let mut res = String::new();
+ File::open(path.as_ref()).unwrap()
+ .read_to_string(&mut res).unwrap();
- res
- }
+ res
+}
- macro_rules! ref_test {
- ($name:ident) => {
- #[test]
- fn $name() {
- let recording = read_u8(ref_file!($name, "alacritty.recording"));
- let serialized_size = read_string(ref_file!($name, "size.json"));
- let serialized_grid = read_string(ref_file!($name, "grid.json"));
-
- let size: SizeInfo = json::from_str(&serialized_size).unwrap();
- let grid: Grid<Cell> = json::from_str(&serialized_grid).unwrap();
-
- let mut terminal = Term::new(size);
- let mut parser = ansi::Processor::new();
-
- for byte in recording {
- parser.advance(&mut terminal, byte, &mut Void);
- }
-
- assert_eq!(grid, *terminal.grid());
- }
- };
-
- ($( $name:ident ),*) => {
- $(
- ref_test! { $name }
- )*
- };
- }
+fn ref_test(dir: &Path) {
+ let recording = read_u8(dir.join("alacritty.recording"));
+ let serialized_size = read_string(dir.join("size.json"));
+ let serialized_grid = read_string(dir.join("grid.json"));
+
+ let size: SizeInfo = json::from_str(&serialized_size).unwrap();
+ let grid: Grid<Cell> = json::from_str(&serialized_grid).unwrap();
- // Ref tests!
- ref_test! {
- ll,
- vim_simple_edit,
- tmux_htop,
- tmux_git_log,
- vim_large_window_scroll,
- indexed_256_colors,
- fish_cc
+ let mut terminal = Term::new(size);
+ let mut parser = ansi::Processor::new();
+
+ for byte in recording {
+ parser.advance(&mut terminal, byte, &mut io::sink());
}
+
+ assert_eq!(grid, *terminal.grid());
}