mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
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:
parent
37a7afddfa
commit
46921a8c28
11
.github/workflows/rust.yml
vendored
11
.github/workflows/rust.yml
vendored
@ -20,13 +20,6 @@ jobs:
|
|||||||
- name: Checkout source code
|
- name: Checkout source code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install Rust
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
profile: minimal
|
|
||||||
toolchain: ${{ matrix.rust }}
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: Dependency cache
|
- name: Dependency cache
|
||||||
uses: Swatinem/rust-cache@v1
|
uses: Swatinem/rust-cache@v1
|
||||||
|
|
||||||
@ -34,10 +27,10 @@ jobs:
|
|||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: build
|
command: build
|
||||||
args: --all-features
|
args: --all
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
args: --all-features
|
args: --all
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,6 +7,7 @@ desktop.ini
|
|||||||
# Tests and benchmarks
|
# Tests and benchmarks
|
||||||
tests/png
|
tests/png
|
||||||
tests/pdf
|
tests/pdf
|
||||||
|
tests/target
|
||||||
tarpaulin-report.html
|
tarpaulin-report.html
|
||||||
|
|
||||||
# Rust
|
# Rust
|
||||||
|
20
Cargo.lock
generated
20
Cargo.lock
generated
@ -1111,9 +1111,7 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"comemo",
|
"comemo",
|
||||||
"elsa",
|
|
||||||
"flate2",
|
"flate2",
|
||||||
"iai",
|
|
||||||
"image",
|
"image",
|
||||||
"miniz_oxide",
|
"miniz_oxide",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@ -1131,13 +1129,11 @@ dependencies = [
|
|||||||
"syntect",
|
"syntect",
|
||||||
"tiny-skia",
|
"tiny-skia",
|
||||||
"ttf-parser 0.17.1",
|
"ttf-parser 0.17.1",
|
||||||
"typst-library",
|
|
||||||
"typst-macros",
|
"typst-macros",
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
"unscanny",
|
"unscanny",
|
||||||
"usvg",
|
"usvg",
|
||||||
"walkdir",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1194,6 +1190,22 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "unicode-bidi"
|
name = "unicode-bidi"
|
||||||
version = "0.3.8"
|
version = "0.3.8"
|
||||||
|
20
Cargo.toml
20
Cargo.toml
@ -5,7 +5,11 @@ authors = ["The Typst Project Developers"]
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["cli", "library", "macros"]
|
members = ["cli", "library", "macros", "tests"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
doctest = false
|
||||||
|
bench = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
typst-macros = { path = "macros" }
|
typst-macros = { path = "macros" }
|
||||||
@ -35,22 +39,8 @@ unicode-xid = "0.2"
|
|||||||
unscanny = "0.1"
|
unscanny = "0.1"
|
||||||
usvg = { version = "0.22", default-features = false }
|
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]
|
[profile.dev]
|
||||||
debug = 0
|
debug = 0
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
[profile.dev.package."*"]
|
||||||
opt-level = 2
|
opt-level = 2
|
||||||
|
|
||||||
[[test]]
|
|
||||||
name = "typeset"
|
|
||||||
harness = false
|
|
||||||
|
|
||||||
[[bench]]
|
|
||||||
name = "oneshot"
|
|
||||||
harness = false
|
|
||||||
|
@ -7,6 +7,9 @@ edition = "2021"
|
|||||||
[[bin]]
|
[[bin]]
|
||||||
name = "typst"
|
name = "typst"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
test = false
|
||||||
|
doctest = false
|
||||||
|
bench = false
|
||||||
doc = false
|
doc = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -4,6 +4,11 @@ version = "0.1.0"
|
|||||||
authors = ["The Typst Project Developers"]
|
authors = ["The Typst Project Developers"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
test = false
|
||||||
|
doctest = false
|
||||||
|
bench = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
typst = { path = ".." }
|
typst = { path = ".." }
|
||||||
comemo = "0.1"
|
comemo = "0.1"
|
||||||
|
@ -6,6 +6,9 @@ edition = "2021"
|
|||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
test = false
|
||||||
|
doctest = false
|
||||||
|
bench = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "1"
|
proc-macro2 = "1"
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//! Procedural macros for Typst.
|
||||||
|
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
|
27
tests/Cargo.toml
Normal file
27
tests/Cargo.toml
Normal 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
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## Directory structure
|
## Directory structure
|
||||||
Top level directory structure:
|
Top level directory structure:
|
||||||
|
- `src`: Testing code.
|
||||||
- `typ`: Input files.
|
- `typ`: Input files.
|
||||||
- `res`: Resource files used by tests.
|
- `res`: Resource files used by tests.
|
||||||
- `ref`: Reference images which the output is compared with to determine whether
|
- `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.
|
- `pdf`: PDF files produced by tests.
|
||||||
|
|
||||||
## Running the tests
|
## Running the tests
|
||||||
Running the integration tests (the tests in this directory).
|
Running all tests (including unit tests):
|
||||||
```bash
|
```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`.
|
Running all tests whose paths contain the string `page` or `stack`.
|
||||||
```bash
|
```bash
|
||||||
cargo test --test typeset page stack
|
testit page stack
|
||||||
```
|
```
|
||||||
|
|
||||||
Running a test with the exact filename `page.typ`.
|
Running a test with the exact filename `page.typ`.
|
||||||
```bash
|
```bash
|
||||||
cargo test --test typeset -- --exact page.typ
|
testit --exact page.typ
|
||||||
```
|
```
|
||||||
|
|
||||||
Debug-printing the layout trees for all executed tests.
|
Debug-printing the layout trees for all executed tests.
|
||||||
```bash
|
```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.
|
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
|
automatically at the moment, so you should always check the output manually when
|
||||||
making changes.
|
making changes.
|
||||||
```bash
|
```bash
|
||||||
cargo test --test typeset -- --pdf
|
testit --pdf
|
||||||
```
|
```
|
||||||
|
|
||||||
## Creating new tests
|
## Creating new tests
|
||||||
@ -50,23 +61,23 @@ oxipng -o max path/to/image.png
|
|||||||
oxipng -r -o max tests/ref
|
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
|
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:
|
to your shell profile so that you can simply write something like:
|
||||||
```bash
|
```bash
|
||||||
tests --debug empty.typ
|
testit empty.typ
|
||||||
```
|
|
||||||
|
|
||||||
### PowerShell
|
|
||||||
Open your PowerShell profile by executing `notepad $profile`.
|
|
||||||
```ps
|
|
||||||
function tests {
|
|
||||||
cargo test --test typeset -- $args
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Bash
|
### Bash
|
||||||
Open your Bash configuration by executing `nano ~/.bashrc`.
|
Open your Bash configuration by executing `nano ~/.bashrc`.
|
||||||
```bash
|
```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
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
@ -10,8 +10,8 @@ use typst::syntax::{Source, SourceId, TokenMode, Tokens};
|
|||||||
use typst::util::Buffer;
|
use typst::util::Buffer;
|
||||||
use typst::{Config, World};
|
use typst::{Config, World};
|
||||||
|
|
||||||
const TEXT: &str = include_str!("bench.typ");
|
const TEXT: &str = include_str!("../typ/benches/bench.typ");
|
||||||
const FONT: &[u8] = include_bytes!("../fonts/IBMPlexSans-Regular.ttf");
|
const FONT: &[u8] = include_bytes!("../../fonts/IBMPlexSans-Regular.ttf");
|
||||||
|
|
||||||
main!(
|
main!(
|
||||||
bench_decode,
|
bench_decode,
|
||||||
@ -113,6 +113,7 @@ impl BenchWorld {
|
|||||||
let book = FontBook::from_fonts([&font]);
|
let book = FontBook::from_fonts([&font]);
|
||||||
let id = SourceId::from_u16(0);
|
let id = SourceId::from_u16(0);
|
||||||
let source = Source::new(id, Path::new("bench.typ"), TEXT.into());
|
let source = Source::new(id, Path::new("bench.typ"), TEXT.into());
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
config: Prehashed::new(config),
|
config: Prehashed::new(config),
|
||||||
book: Prehashed::new(book),
|
book: Prehashed::new(book),
|
@ -25,26 +25,28 @@ use typst::{Config, World};
|
|||||||
use typst_library::layout::PageNode;
|
use typst_library::layout::PageNode;
|
||||||
use typst_library::text::{TextNode, TextSize};
|
use typst_library::text::{TextNode, TextSize};
|
||||||
|
|
||||||
const TYP_DIR: &str = "./typ";
|
const TYP_DIR: &str = "typ";
|
||||||
const REF_DIR: &str = "./ref";
|
const REF_DIR: &str = "ref";
|
||||||
const PNG_DIR: &str = "./png";
|
const PNG_DIR: &str = "png";
|
||||||
const PDF_DIR: &str = "./pdf";
|
const PDF_DIR: &str = "pdf";
|
||||||
const FONT_DIR: &str = "../fonts";
|
const FONT_DIR: &str = "../fonts";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env::set_current_dir(env::current_dir().unwrap().join("tests")).unwrap();
|
|
||||||
|
|
||||||
let args = Args::new(env::args().skip(1));
|
let args = Args::new(env::args().skip(1));
|
||||||
let mut filtered = Vec::new();
|
let mut filtered = Vec::new();
|
||||||
|
|
||||||
// Since differents tests can affect each other through the memoization
|
// Since differents tests can affect each other through the memoization
|
||||||
// cache, a deterministic order is important for reproducibility.
|
// 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();
|
let entry = entry.unwrap();
|
||||||
if entry.depth() <= 1 {
|
if entry.depth() <= 1 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if entry.path().starts_with("typ/benches") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let src_path = entry.into_path();
|
let src_path = entry.into_path();
|
||||||
if src_path.extension() != Some(OsStr::new("typ")) {
|
if src_path.extension() != Some(OsStr::new("typ")) {
|
||||||
continue;
|
continue;
|
Loading…
x
Reference in New Issue
Block a user