1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

Dynamically generate test harness

This uses the rustc-test crate, a copy of the standard test crate, to
dynamically create tests for each reference test. No need to remember to
update the macro, just add the directory to ref!
This commit is contained in:
Steven Fackler 2017-01-21 10:11:55 +00:00 committed by Joe Wilm
parent 6229477190
commit 41f99dc4c0
5 changed files with 106 additions and 90 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
target
FlameGraph
.idea
*.iml

30
Cargo.lock generated
View file

@ -15,6 +15,7 @@ dependencies = [
"mio 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"notify 2.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-test 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.8.19 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 0.8.19 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -320,6 +321,11 @@ dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "getopts"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "gl_generator"
version = "0.5.2"
@ -774,6 +780,18 @@ name = "rustc-serialize"
version = "0.3.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-test"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc_version"
version = "0.1.7"
@ -944,6 +962,15 @@ dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "term"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "time"
version = "0.1.35"
@ -1145,6 +1172,7 @@ dependencies = [
"checksum fsevent-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "72e33a926306442d961595c3a325864326ca4287795e106dae8993afe484ede6"
"checksum gcc 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "872db9e59486ef2b14f8e8c10e9ef02de2bccef6363d7f34835dedb386b3d950"
"checksum gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "65256ec4dc2592e6f05bfc1ca3b956a4e0698aa90b1dff1f5687d55a5a3fd59a"
"checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685"
"checksum gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1d8edc81c5ae84605a62f5dac661a2313003b26d59839f81d47d46cf0f16a55"
"checksum gleam 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b83402229bde9d923f0b92811be017f9df5946ee86f8647367b1e02bcf5c293"
"checksum glutin 0.6.1 (git+https://github.com/jwilm/glutin?rev=af7fe340bd4a2af53ea521defcb4f377cdc588cf)" = "<none>"
@ -1196,6 +1224,7 @@ dependencies = [
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957"
"checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b"
"checksum rustc-test 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5a8a7c2bc3cd2df4e0da9e548cd1b50c4c7b68d72410d34eba98a2d5393a2875"
"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
"checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f"
@ -1217,6 +1246,7 @@ dependencies = [
"checksum syn 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94e7d81ecd16d39f16193af05b8d5a0111b9d8d2f3f78f31760f327a247da777"
"checksum target_build_utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "54c550e226618cd35334b75e92bfa5437c61474bdb75c38bf330ab5a8037b77c"
"checksum tempfile 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9270837a93bad1b1dac18fe67e786b3c960513af86231f6f4f57fddd594ff0c8"
"checksum term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3deff8a2b3b6607d6d7cc32ac25c0b33709453ca9cceac006caac51e963cf94a"
"checksum time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7ec6d62a20df54e07ab3b78b9a3932972f4b7981de295563686849eb3989af"
"checksum toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "0590d72182e50e879c4da3b11c6488dae18fccb1ae0c7a3eda18e16795844796"
"checksum unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "26643a2f83bac55f1976fb716c10234485f9202dcd65cfbdf9da49867b271172"

View file

@ -10,6 +10,10 @@ doc = false
path = "src/main.rs"
name = "alacritty"
[[test]]
name = "ref"
harness = false
[dependencies]
libc = "*"
cgmath = "0.7"
@ -44,6 +48,8 @@ gl_generator = "0.5"
git = "https://github.com/jwilm/glutin"
rev = "af7fe340bd4a2af53ea521defcb4f377cdc588cf"
[dev-dependencies]
rustc-test = "0.1"
[profile.release]
lto = true

View file

@ -19,7 +19,6 @@
#![cfg_attr(feature = "clippy", deny(enum_glob_use))]
#![cfg_attr(feature = "clippy", deny(if_not_else))]
#![cfg_attr(feature = "clippy", deny(wrong_pub_self_convention))]
#![cfg_attr(test, feature(test))]
#![cfg_attr(feature = "nightly", feature(core_intrinsics))]
#[macro_use]

View file

@ -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 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
}
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
}
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 }
)*
};
}
// Ref tests!
ref_test! {
ll,
vim_simple_edit,
tmux_htop,
tmux_git_log,
vim_large_window_scroll,
indexed_256_colors,
fish_cc
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();
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();
res
}
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();
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());
}