Add diagnostics and testing
This commit is contained in:
parent
0fce67c7d7
commit
caedb752b7
8 changed files with 268 additions and 21 deletions
135
Cargo.lock
generated
135
Cargo.lock
generated
|
@ -114,6 +114,7 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-error",
|
"tracing-error",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
"tracing-tracy",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -218,6 +219,19 @@ version = "1.0.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
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]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
|
@ -289,6 +303,19 @@ version = "0.4.22"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
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]]
|
[[package]]
|
||||||
name = "matchers"
|
name = "matchers"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -537,6 +564,12 @@ dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"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]]
|
[[package]]
|
||||||
name = "rusty-fork"
|
name = "rusty-fork"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
@ -549,6 +582,12 @@ dependencies = [
|
||||||
"wait-timeout",
|
"wait-timeout",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scoped-tls"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sharded-slab"
|
name = "sharded-slab"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
|
@ -681,6 +720,38 @@ dependencies = [
|
||||||
"tracing-log",
|
"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]]
|
[[package]]
|
||||||
name = "unarray"
|
name = "unarray"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
|
@ -742,6 +813,70 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
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]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.52.0"
|
version = "0.52.0"
|
||||||
|
|
|
@ -29,6 +29,7 @@ eyre.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
tracing-error = "0.2"
|
tracing-error = "0.2"
|
||||||
|
tracing-tracy = "0.11"
|
||||||
|
|
||||||
cogs_ast.workspace = true
|
cogs_ast.workspace = true
|
||||||
cogs_codegen.workspace = true
|
cogs_codegen.workspace = true
|
||||||
|
@ -41,3 +42,7 @@ ariadne = "0.5.0"
|
||||||
[profile.dev.package]
|
[profile.dev.package]
|
||||||
insta.opt-level = 3
|
insta.opt-level = 3
|
||||||
similar.opt-level = 3
|
similar.opt-level = 3
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
tracy = ["tracing-tracy/enable"]
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub fn parse_consecutive_proper_elements(input: &str) -> IResult<&str, Vec<Eleme
|
||||||
|
|
||||||
fn parse_element(input: &str) -> IResult<&str, Element> {
|
fn parse_element(input: &str) -> IResult<&str, Element> {
|
||||||
let (input, _) = multispace0(input)?;
|
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> {
|
fn parse_proper_element(input: &str) -> IResult<&str, Element> {
|
||||||
|
|
33
src/lib.rs
33
src/lib.rs
|
@ -27,14 +27,37 @@ pub fn parse_cog(input: String, file: &str) -> eyre::Result<cogs_ast::Component>
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn init_tracing() -> eyre::Result<()> {
|
pub fn init_tracing() -> eyre::Result<()> {
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
tracing_subscriber::registry()
|
let registry = tracing_subscriber::registry().with(
|
||||||
.with(
|
|
||||||
tracing_subscriber::EnvFilter::builder()
|
tracing_subscriber::EnvFilter::builder()
|
||||||
.with_default_directive(LevelFilter::INFO.into())
|
.with_default_directive(LevelFilter::INFO.into())
|
||||||
.from_env_lossy(),
|
.from_env_lossy(),
|
||||||
)
|
);
|
||||||
|
fn do_init<
|
||||||
|
R: tracing::Subscriber
|
||||||
|
+ SubscriberExt
|
||||||
|
+ for<'span> tracing_subscriber::registry::LookupSpan<'span>
|
||||||
|
+ Into<tracing::Dispatch>
|
||||||
|
+ Sync
|
||||||
|
+ Send
|
||||||
|
+ 'static,
|
||||||
|
>(
|
||||||
|
registry: R,
|
||||||
|
) -> eyre::Result<()> {
|
||||||
|
tracing::subscriber::set_global_default(
|
||||||
|
registry
|
||||||
.with(tracing_error::ErrorLayer::default())
|
.with(tracing_error::ErrorLayer::default())
|
||||||
.with(tracing_subscriber::fmt::layer())
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
6
src/snapshots/cogs__tests__codegen@1.snap
Normal file
6
src/snapshots/cogs__tests__codegen@1.snap
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
source: src/tests.rs
|
||||||
|
expression: "cogs_codegen::generate(&ast).unwrap()"
|
||||||
|
snapshot_kind: text
|
||||||
|
---
|
||||||
|
not yet implemented
|
79
src/snapshots/cogs__tests__cogs@1.snap
Normal file
79
src/snapshots/cogs__tests__cogs@1.snap
Normal file
|
@ -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",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
}
|
19
src/tests.rs
19
src/tests.rs
|
@ -1,15 +1,14 @@
|
||||||
use proptest::prelude::*;
|
#[test]
|
||||||
|
fn test_cogs() {
|
||||||
proptest! {
|
let _ = crate::init_tracing();
|
||||||
// Update when new tests are added
|
let tests = 1..=1;
|
||||||
#[test]
|
for test_index in tests {
|
||||||
fn test_cogs(test_index in 1..=1) {
|
let name = format!("tests/{}.cog", test_index);
|
||||||
crate::init_tracing().unwrap();
|
let file = std::fs::read_to_string(&name).unwrap();
|
||||||
let file = std::fs::read_to_string(format!("tests/{}.cog", test_index)).unwrap();
|
let ast = crate::parse_cog(file, &name).unwrap();
|
||||||
let ast = crate::parse_cog(file).unwrap();
|
|
||||||
insta::with_settings!({ snapshot_suffix => format!("{test_index}") }, {
|
insta::with_settings!({ snapshot_suffix => format!("{test_index}") }, {
|
||||||
insta::assert_debug_snapshot!(ast);
|
insta::assert_debug_snapshot!(ast);
|
||||||
insta::assert_snapshot!(cogs_codegen::generate(&ast).unwrap());
|
insta::assert_snapshot!("codegen", cogs_codegen::generate(&ast).unwrap());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<body>
|
<body>
|
||||||
<h1>Yo.</h1>
|
<h1>Yo.</h1>
|
||||||
<a src=\"https://www.youtube.com/watch?v=dQw4w9WgXcQ\">Click this</a>
|
<a src="https://www.youtube.com/watch?v=dQw4w9WgXcQ">Click this</a>
|
||||||
{
|
{
|
||||||
println!(\"test\");
|
println!("test");
|
||||||
<p>More Html</p>
|
<p>More Html</p>
|
||||||
}
|
}
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue