Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ clap = "4.5.54"
clap_complete = "4.5.65"
clap_mangen = "0.2.26"
color-eyre = "0.6.3"
comemo = "0.5.1"
ctrlc = "3.4.5"
dirs = "6.0.0"
ecow = "0.2.2"
Expand Down Expand Up @@ -61,14 +62,15 @@ tracing = "0.1.44"
tracing-subscriber = "0.3.18"
tracing-tree = "0.4.1"
toml = "0.8.19"
unicode-ident = "1.0.24"
uuid = "1.20.0"

# Keep the git dependencies in but commented out for ease of switching during development and before
# Typst releases.

typst = "0.15.1"
typst-assets = "0.15.1"
typst-kit = "0.15.1"
typst-kit = { version = "0.15.1", features = ["datetime", "emit-diagnostics", "system-packages"] }
typst-layout = "0.15.1"
typst-library = "0.15.1"
typst-render = "0.15.1"
Expand Down
1 change: 1 addition & 0 deletions crates/tytanic-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typst-layout.workspace = true
typst-library.workspace = true
typst-render.workspace = true
typst-utils.workspace = true
unicode-ident.workspace = true
uuid = { workspace = true, features = ["v4", "serde"] }

[dev-dependencies]
Expand Down
39 changes: 9 additions & 30 deletions crates/tytanic-core/src/doc/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ pub fn compile(world: &dyn World, warnings: Warnings) -> Warned<Result<PagedDocu
#[cfg(test)]
mod tests {
use typst::syntax::Source;
use typst::{Library, LibraryExt};
use typst_utils::LazyHash;

use super::*;
use crate::world_builder::file::VirtualFileProvider;
use crate::world_builder::test_utils;

const TEST_PASS: &str = "Hello World";
Expand All @@ -94,10 +91,8 @@ mod tests {

#[test]
fn test_compile_pass_ignore_warnings() {
let mut files = VirtualFileProvider::new();
let library = LazyHash::new(Library::default());
let source = Source::detached(TEST_PASS);
let world = test_utils::virtual_world(source, &mut files, &library);
let world = test_utils::virtual_world(source);

let Warned { output, warnings } = compile(&world, Warnings::Ignore);
assert!(output.is_ok());
Expand All @@ -106,10 +101,8 @@ mod tests {

#[test]
fn test_compile_pass_emit_warnings() {
let mut files = VirtualFileProvider::new();
let library = LazyHash::new(Library::default());
let source = Source::detached(TEST_PASS);
let world = test_utils::virtual_world(source, &mut files, &library);
let world = test_utils::virtual_world(source);

let Warned { output, warnings } = compile(&world, Warnings::Emit);
assert!(output.is_ok());
Expand All @@ -118,10 +111,8 @@ mod tests {

#[test]
fn test_compile_pass_promote_warnings() {
let mut files = VirtualFileProvider::new();
let library = LazyHash::new(Library::default());
let source = Source::detached(TEST_PASS);
let world = test_utils::virtual_world(source, &mut files, &library);
let world = test_utils::virtual_world(source);

let Warned { output, warnings } = compile(&world, Warnings::Promote);
assert!(output.is_ok());
Expand All @@ -130,10 +121,8 @@ mod tests {

#[test]
fn test_compile_warn_ignore_warnings() {
let mut files = VirtualFileProvider::new();
let library = LazyHash::new(Library::default());
let source = Source::detached(TEST_WARN);
let world = test_utils::virtual_world(source, &mut files, &library);
let world = test_utils::virtual_world(source);

let Warned { output, warnings } = compile(&world, Warnings::Ignore);
assert!(output.is_ok());
Expand All @@ -142,10 +131,8 @@ mod tests {

#[test]
fn test_compile_warn_emit_warnings() {
let mut files = VirtualFileProvider::new();
let library = LazyHash::new(Library::default());
let source = Source::detached(TEST_WARN);
let world = test_utils::virtual_world(source, &mut files, &library);
let world = test_utils::virtual_world(source);

let Warned { output, warnings } = compile(&world, Warnings::Emit);
assert!(output.is_ok());
Expand All @@ -154,10 +141,8 @@ mod tests {

#[test]
fn test_compile_warn_promote_warnings() {
let mut files = VirtualFileProvider::new();
let library = LazyHash::new(Library::default());
let source = Source::detached(TEST_WARN);
let world = test_utils::virtual_world(source, &mut files, &library);
let world = test_utils::virtual_world(source);

let Warned { output, warnings } = compile(&world, Warnings::Promote);
assert_eq!(output.unwrap_err().0.len(), 1);
Expand All @@ -166,10 +151,8 @@ mod tests {

#[test]
fn test_compile_fail_ignore_warnings() {
let mut files = VirtualFileProvider::new();
let library = LazyHash::new(Library::default());
let source = Source::detached(TEST_FAIL);
let world = test_utils::virtual_world(source, &mut files, &library);
let world = test_utils::virtual_world(source);

let Warned { output, warnings } = compile(&world, Warnings::Ignore);
assert_eq!(output.unwrap_err().0.len(), 1);
Expand All @@ -178,10 +161,8 @@ mod tests {

#[test]
fn test_compile_fail_emit_warnings() {
let mut files = VirtualFileProvider::new();
let library = LazyHash::new(Library::default());
let source = Source::detached(TEST_FAIL);
let world = test_utils::virtual_world(source, &mut files, &library);
let world = test_utils::virtual_world(source);

let Warned { output, warnings } = compile(&world, Warnings::Emit);
assert_eq!(output.unwrap_err().0.len(), 1);
Expand All @@ -190,10 +171,8 @@ mod tests {

#[test]
fn test_compile_fail_promote_warnings() {
let mut files = VirtualFileProvider::new();
let library = LazyHash::new(Library::default());
let source = Source::detached(TEST_FAIL);
let world = test_utils::virtual_world(source, &mut files, &library);
let world = test_utils::virtual_world(source);

let Warned { output, warnings } = compile(&world, Warnings::Promote);
assert_eq!(output.unwrap_err().0.len(), 2);
Expand Down
63 changes: 40 additions & 23 deletions crates/tytanic-core/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,32 @@
use std::convert::Infallible;

use crate::project::Project;
use crate::test::Test;
use crate::test::AsTestRef;
use crate::test::TestRef;

/// A filter from which a [`FilterState`] can be created.
///
/// To use a filter create its state and apply it to a set of tests.
/// ```
/// # use tytanic_core::project::Project;
/// # use tytanic_core::test::Id;
/// # use tytanic_core::test::IdRef;
/// # use tytanic_core::test::Test;
/// # use tytanic_core::test::TestRef;
/// # use tytanic_core::test::UnitTest;
/// # use tytanic_core::test::unit::Kind as UnitKind;
/// # use tytanic_core::test::UnitKind;
/// # let project = Project::new(".");
/// use tytanic_core::filter::Filter as _;
/// use tytanic_core::filter::FilterState as _;
/// use tytanic_core::filter::FnFilter;
///
/// let tests = [
/// Test::Unit(UnitTest::new(Id::new("foo")?, UnitKind::CompileOnly)),
/// Test::Unit(UnitTest::new(Id::new("bar")?, UnitKind::CompileOnly)),
/// Test::Unit(UnitTest::new(Id::new("qux")?, UnitKind::CompileOnly)),
/// Test::try_new_unit("foo", UnitKind::CompileOnly)?,
/// Test::try_new_unit("bar", UnitKind::CompileOnly)?,
/// Test::try_new_unit("qux", UnitKind::CompileOnly)?,
/// ];
///
/// let filter = FnFilter(|_, t| t.id() != "foo");
/// let filter = FnFilter(|_, t| t.id().as_str() != "foo");
/// let mut state = filter.state();
///
/// let mut filtered = vec![];
Expand All @@ -42,10 +45,10 @@ use crate::test::Test;
///
/// state.finish(&project)?;
///
/// assert_eq!(filtered, [
/// &Id::new("bar")?,
/// &Id::new("qux")?,
/// ]);
/// assert_eq!(
/// filtered.into_iter().map(IdRef::as_str).collect::<Vec<_>>(),
/// ["bar", "qux"],
/// );
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub trait Filter {
Expand Down Expand Up @@ -74,7 +77,9 @@ pub trait FilterState: Sized {
/// Whether the test should be included in the test run.
///
/// This must be called exactly once for each test in a suite.
fn filter(&mut self, project: &Project, test: &Test) -> Result<bool, Self::Error>;
fn filter<T>(&mut self, project: &Project, test: T) -> Result<bool, Self::Error>
where
T: AsTestRef;

/// Finishes the filter, emitting any delayed errors if there are any.
///
Expand Down Expand Up @@ -106,7 +111,10 @@ impl Filter for NoneFilter {
impl FilterState for NoneFilter {
type Error = Infallible;

fn filter(&mut self, _project: &Project, _test: &Test) -> Result<bool, Self::Error> {
fn filter<T>(&mut self, _project: &Project, _test: T) -> Result<bool, Self::Error>
where
T: AsTestRef,
{
Ok(false)
}
}
Expand All @@ -131,7 +139,10 @@ impl Filter for AllFilter {
impl FilterState for AllFilter {
type Error = Infallible;

fn filter(&mut self, _project: &Project, _test: &Test) -> Result<bool, Self::Error> {
fn filter<T>(&mut self, _project: &Project, _test: T) -> Result<bool, Self::Error>
where
T: AsTestRef,
{
Ok(true)
}
}
Expand All @@ -144,11 +155,11 @@ impl FilterState for AllFilter {
#[derive(Debug, Default, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct FnFilter<F>(pub F)
where
F: Fn(&Project, &Test) -> bool;
F: Fn(&Project, TestRef<'_>) -> bool;

impl<F> Filter for FnFilter<F>
where
F: Fn(&Project, &Test) -> bool,
F: Fn(&Project, TestRef<'_>) -> bool,
{
type State<'a>
= &'a Self
Expand All @@ -162,12 +173,15 @@ where

impl<F> FilterState for &FnFilter<F>
where
F: Fn(&Project, &Test) -> bool,
F: Fn(&Project, TestRef<'_>) -> bool,
{
type Error = Infallible;

fn filter(&mut self, project: &Project, test: &Test) -> Result<bool, Self::Error> {
Ok((self.0)(project, test))
fn filter<T>(&mut self, project: &Project, test: T) -> Result<bool, Self::Error>
where
T: AsTestRef,
{
Ok((self.0)(project, test.as_test_ref()))
}
}

Expand All @@ -179,12 +193,12 @@ where
#[derive(Debug, Default, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct TryFnFilter<F, E>(pub F)
where
F: Fn(&Project, &Test) -> Result<bool, E>,
F: Fn(&Project, TestRef<'_>) -> Result<bool, E>,
E: std::error::Error;

impl<F, E> Filter for TryFnFilter<F, E>
where
F: Fn(&Project, &Test) -> Result<bool, E>,
F: Fn(&Project, TestRef<'_>) -> Result<bool, E>,
E: std::error::Error,
{
type State<'a>
Expand All @@ -199,12 +213,15 @@ where

impl<F, E> FilterState for &TryFnFilter<F, E>
where
F: Fn(&Project, &Test) -> Result<bool, E>,
F: Fn(&Project, TestRef<'_>) -> Result<bool, E>,
E: std::error::Error,
{
type Error = E;

fn filter(&mut self, project: &Project, test: &Test) -> Result<bool, Self::Error> {
(self.0)(project, test)
fn filter<T>(&mut self, project: &Project, test: T) -> Result<bool, Self::Error>
where
T: AsTestRef,
{
(self.0)(project, test.as_test_ref())
}
}
9 changes: 9 additions & 0 deletions crates/tytanic-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ pub mod world_builder;
pub use project::Project;
pub use suite::FilteredSuite;
pub use suite::Suite;
pub use test::AsTestRef;
pub use test::DocId;
pub use test::DocTest;
pub use test::Id;
pub use test::IdRef;
pub use test::TemplateId;
pub use test::TemplateTest;
pub use test::Test;
pub use test::TestRef;
pub use test::UnitId;
pub use test::UnitTest;
pub use test::UnitTestRef;

/// The tool name, this is used in various places like config file directories,
/// manifest tool sections, and more.
Expand Down
Loading
Loading