summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-03-13 14:18:31 +0100
committerLaurenz <laurmaedje@gmail.com>2021-03-13 14:18:31 +0100
commit3c74e4566a645b4f955a3805952e2f2af8506f22 (patch)
treea46d5d4d7698f00725384c6eabe0e300925e8ee1
parent1584b09708a81a96f52b20a29dfb36c04d6e71ab (diff)
Faster compile times and test execution ⚡
- Optimize only dependencies, not the main crate - Don't generate debug info - Don't generate PDFs for all tets by default
-rw-r--r--Cargo.toml22
-rw-r--r--tests/typeset.rs47
2 files changed, 42 insertions, 27 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 89bfe4de..267a4bda 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,14 +4,22 @@ version = "0.1.0"
authors = ["The Typst Project Developers"]
edition = "2018"
-[workspace]
-members = ["bench"]
-
[features]
-default = ["cli", "fs"]
+default = ["fs"]
cli = ["fs", "anyhow"]
fs = ["fontdock/fs"]
+[workspace]
+members = ["bench"]
+
+[profile.dev]
+# Faster compilation
+debug = 0
+
+[profile.dev.package."*"]
+# Faster test execution
+opt-level = 2
+
[dependencies]
fontdock = { path = "../fontdock", default-features = false }
image = { version = "0.23", default-features = false, features = ["jpeg", "png"] }
@@ -26,12 +34,6 @@ serde = { version = "1", features = ["derive"], optional = true }
tiny-skia = "0.2"
walkdir = "2"
-[profile.dev]
-opt-level = 2
-
-[profile.release]
-lto = true
-
[[bin]]
name = "typst"
required-features = ["cli"]
diff --git a/tests/typeset.rs b/tests/typeset.rs
index 051fd92b..0cd146f4 100644
--- a/tests/typeset.rs
+++ b/tests/typeset.rs
@@ -37,7 +37,7 @@ const FONT_DIR: &str = "../fonts";
fn main() {
env::set_current_dir(env::current_dir().unwrap().join("tests")).unwrap();
- let filter = TestFilter::new(env::args().skip(1));
+ let args = Args::new(env::args().skip(1));
let mut filtered = Vec::new();
for entry in WalkDir::new(".").into_iter() {
@@ -51,7 +51,7 @@ fn main() {
continue;
}
- if filter.matches(&src_path.to_string_lossy()) {
+ if args.matches(&src_path.to_string_lossy()) {
filtered.push(src_path);
}
}
@@ -73,11 +73,19 @@ fn main() {
let mut ok = true;
for src_path in filtered {
- let trailer = src_path.strip_prefix(TYP_DIR).unwrap();
- let png_path = Path::new(PNG_DIR).join(trailer).with_extension("png");
- let pdf_path = Path::new(PDF_DIR).join(trailer).with_extension("pdf");
- let ref_path = Path::new(REF_DIR).join(trailer).with_extension("png");
- ok &= test(&src_path, &png_path, &pdf_path, &ref_path, &mut env);
+ let path = src_path.strip_prefix(TYP_DIR).unwrap();
+ let png_path = Path::new(PNG_DIR).join(path).with_extension("png");
+ let ref_path = Path::new(REF_DIR).join(path).with_extension("png");
+ let pdf_path =
+ args.pdf.then(|| Path::new(PDF_DIR).join(path).with_extension("pdf"));
+
+ ok &= test(
+ &mut env,
+ &src_path,
+ &png_path,
+ &ref_path,
+ pdf_path.as_deref(),
+ );
}
if !ok {
@@ -85,25 +93,28 @@ fn main() {
}
}
-struct TestFilter {
+struct Args {
filter: Vec<String>,
+ pdf: bool,
perfect: bool,
}
-impl TestFilter {
+impl Args {
fn new(args: impl Iterator<Item = String>) -> Self {
let mut filter = Vec::new();
let mut perfect = false;
+ let mut pdf = false;
for arg in args {
match arg.as_str() {
"--nocapture" => {}
+ "--pdf" => pdf = true,
"=" => perfect = true,
_ => filter.push(arg),
}
}
- Self { filter, perfect }
+ Self { filter, pdf, perfect }
}
fn matches(&self, name: &str) -> bool {
@@ -116,11 +127,11 @@ impl TestFilter {
}
fn test(
+ env: &mut Env,
src_path: &Path,
png_path: &Path,
- pdf_path: &Path,
ref_path: &Path,
- env: &mut Env,
+ pdf_path: Option<&Path>,
) -> bool {
let name = src_path.strip_prefix(TYP_DIR).unwrap_or(src_path);
println!("Testing {}", name.display());
@@ -149,7 +160,7 @@ fn test(
}
} else {
let (part_ok, compare_here, part_frames) =
- test_part(part, i, compare_ref, lines, env);
+ test_part(env, part, i, compare_ref, lines);
ok &= part_ok;
compare_ever |= compare_here;
frames.extend(part_frames);
@@ -159,9 +170,11 @@ fn test(
}
if compare_ever {
- let pdf_data = pdf::export(&env, &frames);
- fs::create_dir_all(&pdf_path.parent().unwrap()).unwrap();
- fs::write(pdf_path, pdf_data).unwrap();
+ if let Some(pdf_path) = pdf_path {
+ let pdf_data = pdf::export(&env, &frames);
+ fs::create_dir_all(&pdf_path.parent().unwrap()).unwrap();
+ fs::write(pdf_path, pdf_data).unwrap();
+ }
let canvas = draw(&env, &frames, 2.0);
fs::create_dir_all(&png_path.parent().unwrap()).unwrap();
@@ -186,11 +199,11 @@ fn test(
}
fn test_part(
+ env: &mut Env,
src: &str,
i: usize,
compare_ref: bool,
lines: u32,
- env: &mut Env,
) -> (bool, bool, Vec<Frame>) {
let map = LineMap::new(src);
let (local_compare_ref, ref_diags) = parse_metadata(src, &map);