aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuyashtnt <suyashtnt@gmail.com>2024-07-08 15:13:44 +0200
committerIvan Molodetskikh <yalterz@gmail.com>2024-07-08 17:42:09 +0300
commit7b3bef124d85dccb3ebe21cc1a3dda45eafa0d78 (patch)
tree697026e070dad2d0336929f6b6fb44ab10df7c71
parent3be6e38af3c788be3d32ff006c72ad0b1787a879 (diff)
downloadniri-7b3bef124d85dccb3ebe21cc1a3dda45eafa0d78.tar.gz
niri-7b3bef124d85dccb3ebe21cc1a3dda45eafa0d78.tar.bz2
niri-7b3bef124d85dccb3ebe21cc1a3dda45eafa0d78.zip
niri-config: add test to see if all snippets inside of the wiki compile
Signed-off-by: Suyashtnt <suyashtnt@gmail.com>
-rw-r--r--Cargo.lock149
-rw-r--r--niri-config/Cargo.toml1
-rw-r--r--niri-config/tests/wiki-parses.rs108
3 files changed, 257 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 40d4af7a..87165de1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,15 @@
version = 3
[[package]]
+name = "addr2line"
+version = "0.22.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678"
+dependencies = [
+ "gimli",
+]
+
+[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -355,6 +364,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
+name = "backtrace"
+version = "0.3.73"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a"
+dependencies = [
+ "addr2line",
+ "cc",
+ "cfg-if",
+ "libc",
+ "miniz_oxide",
+ "object",
+ "rustc-demangle",
+]
+
+[[package]]
+name = "backtrace-ext"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50"
+dependencies = [
+ "backtrace",
+]
+
+[[package]]
name = "base64"
version = "0.21.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1369,6 +1402,12 @@ dependencies = [
]
[[package]]
+name = "gimli"
+version = "0.29.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd"
+
+[[package]]
name = "gio"
version = "0.19.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1714,6 +1753,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c"
[[package]]
+name = "is-terminal"
+version = "0.4.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b"
+dependencies = [
+ "hermit-abi 0.3.9",
+ "libc",
+ "windows-sys 0.52.0",
+]
+
+[[package]]
+name = "is_ci"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45"
+
+[[package]]
name = "is_terminal_polyfill"
version = "1.70.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1788,7 +1844,7 @@ dependencies = [
"proc-macro2",
"regex",
"syn 2.0.69",
- "terminal_size",
+ "terminal_size 0.2.6",
]
[[package]]
@@ -2094,8 +2150,17 @@ version = "5.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e"
dependencies = [
+ "backtrace",
+ "backtrace-ext",
+ "is-terminal",
"miette-derive",
"once_cell",
+ "owo-colors",
+ "supports-color",
+ "supports-hyperlinks",
+ "supports-unicode",
+ "terminal_size 0.1.17",
+ "textwrap",
"thiserror",
"unicode-width",
]
@@ -2573,6 +2638,15 @@ dependencies = [
]
[[package]]
+name = "object"
+version = "0.36.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2619,6 +2693,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
+name = "owo-colors"
+version = "3.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
+
+[[package]]
name = "pango"
version = "0.19.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3141,6 +3221,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]]
+name = "rustc-demangle"
+version = "0.1.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
+
+[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3353,6 +3439,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
+name = "smawk"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
+
+[[package]]
name = "smithay"
version = "0.3.0"
source = "git+https://github.com/Smithay/smithay.git#f58a259c2bdeffb9ec87b3beb9edf87cf3c10f01"
@@ -3467,6 +3559,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
+name = "supports-color"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89"
+dependencies = [
+ "is-terminal",
+ "is_ci",
+]
+
+[[package]]
+name = "supports-hyperlinks"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f84231692eb0d4d41e4cdd0cabfdd2e6cd9e255e65f80c9aa7c98dd502b4233d"
+dependencies = [
+ "is-terminal",
+]
+
+[[package]]
+name = "supports-unicode"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f850c19edd184a205e883199a261ed44471c81e39bd95b1357f5febbef00e77a"
+dependencies = [
+ "is-terminal",
+]
+
+[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3531,6 +3651,16 @@ dependencies = [
[[package]]
name = "terminal_size"
+version = "0.1.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
+dependencies = [
+ "libc",
+ "winapi",
+]
+
+[[package]]
+name = "terminal_size"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e6bf6f19e9f8ed8d4048dc22981458ebcf406d67e94cd422e5ecd73d63b3237"
@@ -3540,6 +3670,17 @@ dependencies = [
]
[[package]]
+name = "textwrap"
+version = "0.15.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d"
+dependencies = [
+ "smawk",
+ "unicode-linebreak",
+ "unicode-width",
+]
+
+[[package]]
name = "thiserror"
version = "1.0.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3788,6 +3929,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
+name = "unicode-linebreak"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
+
+[[package]]
name = "unicode-normalization"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/niri-config/Cargo.toml b/niri-config/Cargo.toml
index 28bd1b37..e498d257 100644
--- a/niri-config/Cargo.toml
+++ b/niri-config/Cargo.toml
@@ -20,3 +20,4 @@ tracy-client.workspace = true
[dev-dependencies]
pretty_assertions = "1.4.0"
+miette = { version = "5.10.0", features = ["fancy"] }
diff --git a/niri-config/tests/wiki-parses.rs b/niri-config/tests/wiki-parses.rs
new file mode 100644
index 00000000..9c03b471
--- /dev/null
+++ b/niri-config/tests/wiki-parses.rs
@@ -0,0 +1,108 @@
+use std::fs;
+use std::path::PathBuf;
+
+const NO_TEST_COMMENT: &str = "<!-- no-test -->";
+
+struct KdlCodeBlock {
+ filename: String,
+ code: String,
+ line_number: usize,
+}
+
+fn extract_kdl_from_file(file_contents: &str, filename: &str) -> Vec<KdlCodeBlock> {
+ // Removes the > from callouts that might contain ```kdl```
+ let lines: Vec<_> = file_contents
+ .lines()
+ .map(|line| {
+ let line = line.trim();
+ if line.starts_with(">") {
+ if line.len() == 1 {
+ ""
+ } else {
+ &line[2..]
+ }
+ } else {
+ line
+ }
+ })
+ .enumerate()
+ .collect();
+
+ let mut lines_iter = lines.iter();
+ let mut kdl_code_blocks = vec![];
+
+ while let Some((line_number, line)) = lines_iter.next() {
+ let start_snippet =
+ line.starts_with("```kdl") && lines[line_number - 1].1 != NO_TEST_COMMENT;
+
+ if !start_snippet {
+ continue;
+ }
+
+ let mut snippet = String::new();
+ for (_, line) in lines_iter
+ .by_ref()
+ .take_while(|(_, line)| !line.starts_with("```"))
+ {
+ snippet.push_str(line);
+ snippet.push('\n');
+ }
+
+ kdl_code_blocks.push(KdlCodeBlock {
+ code: snippet,
+ line_number: *line_number,
+ filename: filename.to_string(),
+ });
+ }
+
+ kdl_code_blocks
+}
+
+#[test]
+fn wiki_docs_parses() {
+ let wiki_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../wiki");
+
+ let code_blocks = fs::read_dir(&wiki_dir)
+ .unwrap()
+ .filter_map(|entry| entry.ok())
+ .filter(|entry| entry.file_type().is_ok_and(|ft| ft.is_file()))
+ .filter(|file| {
+ file.path()
+ .extension()
+ .map(|ext| ext == "md")
+ .unwrap_or(false)
+ })
+ .map(|file| {
+ let file_contents = fs::read_to_string(file.path()).unwrap();
+ let file_path = file.path();
+ let filename = file_path.to_str().unwrap();
+ extract_kdl_from_file(&file_contents, filename)
+ })
+ .flatten();
+
+ let mut errors = vec![];
+
+ for KdlCodeBlock {
+ code,
+ line_number,
+ filename,
+ } in code_blocks
+ {
+ if let Err(error) = niri_config::Config::parse(&filename, &code) {
+ errors.push(format!(
+ "Error parsing wiki KDL code block at {}:{}: {:?}",
+ filename,
+ line_number,
+ miette::Report::new(error)
+ ))
+ }
+ }
+
+ if !errors.is_empty() {
+ panic!(
+ "Errors parsing {} wiki KDL code blocks:\n{}",
+ errors.len(),
+ errors.join("\n")
+ );
+ }
+}