Separate test crate

This removes the not-really-cyclic dependency that confuses rust-analyzer. See also: https://github.com/rust-lang/rust-analyzer/issues/2414
This commit is contained in:
Laurenz 2022-11-03 16:13:35 +01:00
parent 37a7afddfa
commit 46921a8c28
13 changed files with 104 additions and 54 deletions

View File

@ -20,13 +20,6 @@ jobs:
- name: Checkout source code
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- name: Dependency cache
uses: Swatinem/rust-cache@v1
@ -34,10 +27,10 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --all-features
args: --all
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features
args: --all

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ desktop.ini
# Tests and benchmarks
tests/png
tests/pdf
tests/target
tarpaulin-report.html
# Rust

20
Cargo.lock generated
View File

@ -1111,9 +1111,7 @@ dependencies = [
"bitflags",
"bytemuck",
"comemo",
"elsa",
"flate2",
"iai",
"image",
"miniz_oxide",
"once_cell",
@ -1131,13 +1129,11 @@ dependencies = [
"syntect",
"tiny-skia",
"ttf-parser 0.17.1",
"typst-library",
"typst-macros",
"unicode-segmentation",
"unicode-xid",
"unscanny",
"usvg",
"walkdir",
]
[[package]]
@ -1194,6 +1190,22 @@ dependencies = [
"syn",
]
[[package]]
name = "typst-tests"
version = "0.1.0"
dependencies = [
"comemo",
"elsa",
"iai",
"once_cell",
"tiny-skia",
"ttf-parser 0.17.1",
"typst",
"typst-library",
"unscanny",
"walkdir",
]
[[package]]
name = "unicode-bidi"
version = "0.3.8"

View File

@ -5,7 +5,11 @@ authors = ["The Typst Project Developers"]
edition = "2021"
[workspace]
members = ["cli", "library", "macros"]
members = ["cli", "library", "macros", "tests"]
[lib]
doctest = false
bench = false
[dependencies]
typst-macros = { path = "macros" }
@ -35,22 +39,8 @@ unicode-xid = "0.2"
unscanny = "0.1"
usvg = { version = "0.22", default-features = false }
[dev-dependencies]
typst-library = { path = "library" }
iai = { git = "https://github.com/reknih/iai" }
elsa = "1.7"
walkdir = "2"
[profile.dev]
debug = 0
[profile.dev.package."*"]
opt-level = 2
[[test]]
name = "typeset"
harness = false
[[bench]]
name = "oneshot"
harness = false

View File

@ -7,6 +7,9 @@ edition = "2021"
[[bin]]
name = "typst"
path = "src/main.rs"
test = false
doctest = false
bench = false
doc = false
[dependencies]

View File

@ -4,6 +4,11 @@ version = "0.1.0"
authors = ["The Typst Project Developers"]
edition = "2021"
[lib]
test = false
doctest = false
bench = false
[dependencies]
typst = { path = ".." }
comemo = "0.1"

View File

@ -6,6 +6,9 @@ edition = "2021"
[lib]
proc-macro = true
test = false
doctest = false
bench = false
[dependencies]
proc-macro2 = "1"

View File

@ -1,3 +1,5 @@
//! Procedural macros for Typst.
extern crate proc_macro;
use proc_macro::TokenStream;

27
tests/Cargo.toml Normal file
View File

@ -0,0 +1,27 @@
[package]
name = "typst-tests"
version = "0.1.0"
authors = ["The Typst Project Developers"]
edition = "2021"
[dev-dependencies]
typst = { path = ".." }
typst-library = { path = "../library" }
comemo = "0.1"
elsa = "1.7"
iai = { git = "https://github.com/reknih/iai" }
once_cell = "1"
tiny-skia = "0.6.2"
ttf-parser = "0.17"
unscanny = "0.1"
walkdir = "2"
[[test]]
name = "tests"
path = "src/tests.rs"
harness = false
[[bench]]
name = "benches"
path = "src/benches.rs"
harness = false

View File

@ -2,6 +2,7 @@
## Directory structure
Top level directory structure:
- `src`: Testing code.
- `typ`: Input files.
- `res`: Resource files used by tests.
- `ref`: Reference images which the output is compared with to determine whether
@ -10,24 +11,34 @@ Top level directory structure:
- `pdf`: PDF files produced by tests.
## Running the tests
Running the integration tests (the tests in this directory).
Running all tests (including unit tests):
```bash
cargo test --test typeset
cargo test --all
```
Running just the integration tests (the tests in this directory):
```bash
cargo test --all --test tests
```
You may want to [make yourself an alias](#making-an-alias) like:
```bash
testit
```
Running all tests whose paths contain the string `page` or `stack`.
```bash
cargo test --test typeset page stack
testit page stack
```
Running a test with the exact filename `page.typ`.
```bash
cargo test --test typeset -- --exact page.typ
testit --exact page.typ
```
Debug-printing the layout trees for all executed tests.
```bash
cargo test --test typeset -- --debug empty.typ
testit --debug empty.typ
```
To make the integration tests go faster they don't generate PDFs by default.
@ -35,7 +46,7 @@ Pass the `--pdf` flag to generate those. Mind that PDFs are not tested
automatically at the moment, so you should always check the output manually when
making changes.
```bash
cargo test --test typeset -- --pdf
testit --pdf
```
## Creating new tests
@ -50,23 +61,23 @@ oxipng -o max path/to/image.png
oxipng -r -o max tests/ref
```
## Shorthand for running tests
## Making an alias
If you want to have a quicker way to run the tests, consider adding a shortcut
to your shell profile so that you can simply write something like:
```bash
tests --debug empty.typ
```
### PowerShell
Open your PowerShell profile by executing `notepad $profile`.
```ps
function tests {
cargo test --test typeset -- $args
}
testit empty.typ
```
### Bash
Open your Bash configuration by executing `nano ~/.bashrc`.
```bash
alias tests="cargo test --test typeset --"
alias testit="cargo test --all --test tests --"
```
### PowerShell
Open your PowerShell profile by executing `notepad $profile`.
```ps
function testit {
cargo test --all --test tests -- $args
}
```

View File

@ -10,8 +10,8 @@ use typst::syntax::{Source, SourceId, TokenMode, Tokens};
use typst::util::Buffer;
use typst::{Config, World};
const TEXT: &str = include_str!("bench.typ");
const FONT: &[u8] = include_bytes!("../fonts/IBMPlexSans-Regular.ttf");
const TEXT: &str = include_str!("../typ/benches/bench.typ");
const FONT: &[u8] = include_bytes!("../../fonts/IBMPlexSans-Regular.ttf");
main!(
bench_decode,
@ -113,6 +113,7 @@ impl BenchWorld {
let book = FontBook::from_fonts([&font]);
let id = SourceId::from_u16(0);
let source = Source::new(id, Path::new("bench.typ"), TEXT.into());
Self {
config: Prehashed::new(config),
book: Prehashed::new(book),

View File

@ -25,26 +25,28 @@ use typst::{Config, World};
use typst_library::layout::PageNode;
use typst_library::text::{TextNode, TextSize};
const TYP_DIR: &str = "./typ";
const REF_DIR: &str = "./ref";
const PNG_DIR: &str = "./png";
const PDF_DIR: &str = "./pdf";
const TYP_DIR: &str = "typ";
const REF_DIR: &str = "ref";
const PNG_DIR: &str = "png";
const PDF_DIR: &str = "pdf";
const FONT_DIR: &str = "../fonts";
fn main() {
env::set_current_dir(env::current_dir().unwrap().join("tests")).unwrap();
let args = Args::new(env::args().skip(1));
let mut filtered = Vec::new();
// Since differents tests can affect each other through the memoization
// cache, a deterministic order is important for reproducibility.
for entry in WalkDir::new(".").sort_by_file_name() {
for entry in WalkDir::new("typ").sort_by_file_name() {
let entry = entry.unwrap();
if entry.depth() <= 1 {
continue;
}
if entry.path().starts_with("typ/benches") {
continue;
}
let src_path = entry.into_path();
if src_path.extension() != Some(OsStr::new("typ")) {
continue;