diff --git a/Cargo.lock b/Cargo.lock index 5fa3763..547444e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,6 +114,7 @@ dependencies = [ "tracing", "tracing-error", "tracing-subscriber", + "tracing-tracy", ] [[package]] @@ -218,6 +219,19 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "generator" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb949699c3e4df3a183b1d2142cb24277057055ed23c68ed58894f76c517223" +dependencies = [ + "cfg-if", + "libc", + "log", + "rustversion", + "windows", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -289,6 +303,19 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "loom" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "419e0dc8046cb947daa77eb95ae174acfbddb7673b4151f56d1eed8e93fbfaca" +dependencies = [ + "cfg-if", + "generator", + "scoped-tls", + "tracing", + "tracing-subscriber", +] + [[package]] name = "matchers" version = "0.1.0" @@ -537,6 +564,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + [[package]] name = "rusty-fork" version = "0.3.0" @@ -549,6 +582,12 @@ dependencies = [ "wait-timeout", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "sharded-slab" version = "0.1.7" @@ -681,6 +720,38 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "tracing-tracy" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc775fdaf33c3dfd19dc354729e65e87914bc67dcdc390ca1210807b8bee5902" +dependencies = [ + "tracing-core", + "tracing-subscriber", + "tracy-client", +] + +[[package]] +name = "tracy-client" +version = "0.17.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "746b078c6a09ebfd5594609049e07116735c304671eaab06ce749854d23435bc" +dependencies = [ + "loom", + "once_cell", + "tracy-client-sys", +] + +[[package]] +name = "tracy-client-sys" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3637e734239e12ab152cd269302500bd063f37624ee210cd04b4936ed671f3b1" +dependencies = [ + "cc", + "windows-targets", +] + [[package]] name = "unarray" version = "0.1.4" @@ -742,6 +813,70 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core", + "windows-targets", +] + +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index a676895..f04ed00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ eyre.workspace = true tracing.workspace = true tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-error = "0.2" +tracing-tracy = "0.11" cogs_ast.workspace = true cogs_codegen.workspace = true @@ -41,3 +42,7 @@ ariadne = "0.5.0" [profile.dev.package] insta.opt-level = 3 similar.opt-level = 3 + +[features] +default = [] +tracy = ["tracing-tracy/enable"] diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index a83e84f..4506cf8 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -34,7 +34,7 @@ pub fn parse_consecutive_proper_elements(input: &str) -> IResult<&str, Vec IResult<&str, Element> { let (input, _) = multispace0(input)?; - alt((context("html", parse_html), context("code block", parse_code_block)))(input) + alt((parse_html, context("code block", parse_code_block)))(input) } fn parse_proper_element(input: &str) -> IResult<&str, Element> { diff --git a/src/lib.rs b/src/lib.rs index 7607a8f..0c5230b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,14 +27,37 @@ pub fn parse_cog(input: String, file: &str) -> eyre::Result #[doc(hidden)] pub fn init_tracing() -> eyre::Result<()> { color_eyre::install()?; - tracing_subscriber::registry() - .with( - tracing_subscriber::EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(), + let registry = tracing_subscriber::registry().with( + tracing_subscriber::EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy(), + ); + fn do_init< + R: tracing::Subscriber + + SubscriberExt + + for<'span> tracing_subscriber::registry::LookupSpan<'span> + + Into + + Sync + + Send + + 'static, + >( + registry: R, + ) -> eyre::Result<()> { + tracing::subscriber::set_global_default( + registry + .with(tracing_error::ErrorLayer::default()) + .with(tracing_subscriber::fmt::layer()), ) - .with(tracing_error::ErrorLayer::default()) - .with(tracing_subscriber::fmt::layer()) - .try_init()?; + .map_err(Into::into) + } + #[cfg(feature = "tracy")] + { + do_init(registry.with(tracing_tracy::TracyLayer::default()))?; + } + #[cfg(not(feature = "tracy"))] + { + do_init(registry)?; + } + Ok(()) } diff --git a/src/snapshots/cogs__tests__codegen@1.snap b/src/snapshots/cogs__tests__codegen@1.snap new file mode 100644 index 0000000..5e04bdb --- /dev/null +++ b/src/snapshots/cogs__tests__codegen@1.snap @@ -0,0 +1,6 @@ +--- +source: src/tests.rs +expression: "cogs_codegen::generate(&ast).unwrap()" +snapshot_kind: text +--- +not yet implemented diff --git a/src/snapshots/cogs__tests__cogs@1.snap b/src/snapshots/cogs__tests__cogs@1.snap new file mode 100644 index 0000000..70d72a1 --- /dev/null +++ b/src/snapshots/cogs__tests__cogs@1.snap @@ -0,0 +1,79 @@ +--- +source: src/tests.rs +expression: ast +snapshot_kind: text +--- +Component { + elements: [ + Html( + HtmlTag { + tag: "body", + attributes: [], + content: [ + Html( + HtmlTag { + tag: "h1", + attributes: [], + content: [ + Text( + "Yo.", + ), + ], + }, + ), + Html( + HtmlTag { + tag: "a", + attributes: [ + Attribute { + name: Text( + "src", + ), + value: Some( + Text( + "https://www.youtube.com/watch?v=dQw4w9WgXcQ", + ), + ), + }, + ], + content: [ + Text( + "Click this", + ), + ], + }, + ), + Block( + CodeBlock { + content: [ + Text( + "println!(\"test\");", + ), + Html( + HtmlTag { + tag: "p", + attributes: [], + content: [ + Text( + "More Html", + ), + ], + }, + ), + Text( + "\n ", + ), + ], + }, + ), + Text( + "\n", + ), + ], + }, + ), + Text( + "\n", + ), + ], +} diff --git a/src/tests.rs b/src/tests.rs index 8a11f2c..6ab8e22 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,15 +1,14 @@ -use proptest::prelude::*; - -proptest! { - // Update when new tests are added - #[test] - fn test_cogs(test_index in 1..=1) { - crate::init_tracing().unwrap(); - let file = std::fs::read_to_string(format!("tests/{}.cog", test_index)).unwrap(); - let ast = crate::parse_cog(file).unwrap(); +#[test] +fn test_cogs() { + let _ = crate::init_tracing(); + let tests = 1..=1; + for test_index in tests { + let name = format!("tests/{}.cog", test_index); + let file = std::fs::read_to_string(&name).unwrap(); + let ast = crate::parse_cog(file, &name).unwrap(); insta::with_settings!({ snapshot_suffix => format!("{test_index}") }, { insta::assert_debug_snapshot!(ast); - insta::assert_snapshot!(cogs_codegen::generate(&ast).unwrap()); + insta::assert_snapshot!("codegen", cogs_codegen::generate(&ast).unwrap()); }); } } diff --git a/tests/1.cog b/tests/1.cog index 73ef184..aa6af23 100644 --- a/tests/1.cog +++ b/tests/1.cog @@ -1,8 +1,8 @@

Yo.

- Click this + Click this { - println!(\"test\"); + println!("test");

More Html

}