niri-config: add test to see if all snippets inside of the wiki compile
Browse files at this commit7b3bef124d85dccb3ebe21cc1a3dda45eafa0d78Parent: 3be6e383 changed files +257 -1
- Cargo.lock +148 -1
- niri-config/Cargo.toml +1 -0
- niri-config/tests/wiki-parses.rs +108 -0
Cargo.lockmodified+148 -1
| @@ -2,6 +2,15 @@ | |||
| 2 | # It is not intended for manual editing. | 2 | # It is not intended for manual editing. |
| 3 | version = 3 | 3 | version = 3 |
| 4 | 4 | ||
| 5 | +[[package]] | ||
| 6 | +name = "addr2line" | ||
| 7 | +version = "0.22.0" | ||
| 8 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 9 | +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" | ||
| 10 | +dependencies = [ | ||
| 11 | + "gimli", | ||
| 12 | +] | ||
| 13 | + | ||
| 5 | [[package]] | 14 | [[package]] |
| 6 | name = "adler" | 15 | name = "adler" |
| 7 | version = "1.0.2" | 16 | version = "1.0.2" |
| @@ -354,6 +363,30 @@ version = "1.3.0" | |||
| 354 | source = "registry+https://github.com/rust-lang/crates.io-index" | 363 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 355 | checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" | 364 | checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" |
| 356 | 365 | ||
| 366 | +[[package]] | ||
| 367 | +name = "backtrace" | ||
| 368 | +version = "0.3.73" | ||
| 369 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 370 | +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" | ||
| 371 | +dependencies = [ | ||
| 372 | + "addr2line", | ||
| 373 | + "cc", | ||
| 374 | + "cfg-if", | ||
| 375 | + "libc", | ||
| 376 | + "miniz_oxide", | ||
| 377 | + "object", | ||
| 378 | + "rustc-demangle", | ||
| 379 | +] | ||
| 380 | + | ||
| 381 | +[[package]] | ||
| 382 | +name = "backtrace-ext" | ||
| 383 | +version = "0.2.1" | ||
| 384 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 385 | +checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" | ||
| 386 | +dependencies = [ | ||
| 387 | + "backtrace", | ||
| 388 | +] | ||
| 389 | + | ||
| 357 | [[package]] | 390 | [[package]] |
| 358 | name = "base64" | 391 | name = "base64" |
| 359 | version = "0.21.7" | 392 | version = "0.21.7" |
| @@ -1368,6 +1401,12 @@ dependencies = [ | |||
| 1368 | "wasi", | 1401 | "wasi", |
| 1369 | ] | 1402 | ] |
| 1370 | 1403 | ||
| 1404 | +[[package]] | ||
| 1405 | +name = "gimli" | ||
| 1406 | +version = "0.29.0" | ||
| 1407 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1408 | +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" | ||
| 1409 | + | ||
| 1371 | [[package]] | 1410 | [[package]] |
| 1372 | name = "gio" | 1411 | name = "gio" |
| 1373 | version = "0.19.8" | 1412 | version = "0.19.8" |
| @@ -1713,6 +1752,23 @@ version = "2.0.3" | |||
| 1713 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1752 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1714 | checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c" | 1753 | checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c" |
| 1715 | 1754 | ||
| 1755 | +[[package]] | ||
| 1756 | +name = "is-terminal" | ||
| 1757 | +version = "0.4.12" | ||
| 1758 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1759 | +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" | ||
| 1760 | +dependencies = [ | ||
| 1761 | + "hermit-abi 0.3.9", | ||
| 1762 | + "libc", | ||
| 1763 | + "windows-sys 0.52.0", | ||
| 1764 | +] | ||
| 1765 | + | ||
| 1766 | +[[package]] | ||
| 1767 | +name = "is_ci" | ||
| 1768 | +version = "1.2.0" | ||
| 1769 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1770 | +checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45" | ||
| 1771 | + | ||
| 1716 | [[package]] | 1772 | [[package]] |
| 1717 | name = "is_terminal_polyfill" | 1773 | name = "is_terminal_polyfill" |
| 1718 | version = "1.70.0" | 1774 | version = "1.70.0" |
| @@ -1788,7 +1844,7 @@ dependencies = [ | |||
| 1788 | "proc-macro2", | 1844 | "proc-macro2", |
| 1789 | "regex", | 1845 | "regex", |
| 1790 | "syn 2.0.69", | 1846 | "syn 2.0.69", |
| 1791 | - "terminal_size", | 1847 | + "terminal_size 0.2.6", |
| 1792 | ] | 1848 | ] |
| 1793 | 1849 | ||
| 1794 | [[package]] | 1850 | [[package]] |
| @@ -2094,8 +2150,17 @@ version = "5.10.0" | |||
| 2094 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2150 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2095 | checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" | 2151 | checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e" |
| 2096 | dependencies = [ | 2152 | dependencies = [ |
| 2153 | + "backtrace", | ||
| 2154 | + "backtrace-ext", | ||
| 2155 | + "is-terminal", | ||
| 2097 | "miette-derive", | 2156 | "miette-derive", |
| 2098 | "once_cell", | 2157 | "once_cell", |
| 2158 | + "owo-colors", | ||
| 2159 | + "supports-color", | ||
| 2160 | + "supports-hyperlinks", | ||
| 2161 | + "supports-unicode", | ||
| 2162 | + "terminal_size 0.1.17", | ||
| 2163 | + "textwrap", | ||
| 2099 | "thiserror", | 2164 | "thiserror", |
| 2100 | "unicode-width", | 2165 | "unicode-width", |
| 2101 | ] | 2166 | ] |
| @@ -2572,6 +2637,15 @@ dependencies = [ | |||
| 2572 | "objc", | 2637 | "objc", |
| 2573 | ] | 2638 | ] |
| 2574 | 2639 | ||
| 2640 | +[[package]] | ||
| 2641 | +name = "object" | ||
| 2642 | +version = "0.36.1" | ||
| 2643 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2644 | +checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" | ||
| 2645 | +dependencies = [ | ||
| 2646 | + "memchr", | ||
| 2647 | +] | ||
| 2648 | + | ||
| 2575 | [[package]] | 2649 | [[package]] |
| 2576 | name = "once_cell" | 2650 | name = "once_cell" |
| 2577 | version = "1.19.0" | 2651 | version = "1.19.0" |
| @@ -2618,6 +2692,12 @@ version = "0.1.1" | |||
| 2618 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2692 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2619 | checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" | 2693 | checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" |
| 2620 | 2694 | ||
| 2695 | +[[package]] | ||
| 2696 | +name = "owo-colors" | ||
| 2697 | +version = "3.5.0" | ||
| 2698 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2699 | +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" | ||
| 2700 | + | ||
| 2621 | [[package]] | 2701 | [[package]] |
| 2622 | name = "pango" | 2702 | name = "pango" |
| 2623 | version = "0.19.8" | 2703 | version = "0.19.8" |
| @@ -3140,6 +3220,12 @@ version = "0.8.4" | |||
| 3140 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3220 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3141 | checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" | 3221 | checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" |
| 3142 | 3222 | ||
| 3223 | +[[package]] | ||
| 3224 | +name = "rustc-demangle" | ||
| 3225 | +version = "0.1.24" | ||
| 3226 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3227 | +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" | ||
| 3228 | + | ||
| 3143 | [[package]] | 3229 | [[package]] |
| 3144 | name = "rustc-hash" | 3230 | name = "rustc-hash" |
| 3145 | version = "1.1.0" | 3231 | version = "1.1.0" |
| @@ -3352,6 +3438,12 @@ version = "1.13.2" | |||
| 3352 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3438 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3353 | checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" | 3439 | checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" |
| 3354 | 3440 | ||
| 3441 | +[[package]] | ||
| 3442 | +name = "smawk" | ||
| 3443 | +version = "0.3.2" | ||
| 3444 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3445 | +checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" | ||
| 3446 | + | ||
| 3355 | [[package]] | 3447 | [[package]] |
| 3356 | name = "smithay" | 3448 | name = "smithay" |
| 3357 | version = "0.3.0" | 3449 | version = "0.3.0" |
| @@ -3466,6 +3558,34 @@ version = "0.10.0" | |||
| 3466 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3558 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3467 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" | 3559 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" |
| 3468 | 3560 | ||
| 3561 | +[[package]] | ||
| 3562 | +name = "supports-color" | ||
| 3563 | +version = "2.1.0" | ||
| 3564 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3565 | +checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89" | ||
| 3566 | +dependencies = [ | ||
| 3567 | + "is-terminal", | ||
| 3568 | + "is_ci", | ||
| 3569 | +] | ||
| 3570 | + | ||
| 3571 | +[[package]] | ||
| 3572 | +name = "supports-hyperlinks" | ||
| 3573 | +version = "2.1.0" | ||
| 3574 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3575 | +checksum = "f84231692eb0d4d41e4cdd0cabfdd2e6cd9e255e65f80c9aa7c98dd502b4233d" | ||
| 3576 | +dependencies = [ | ||
| 3577 | + "is-terminal", | ||
| 3578 | +] | ||
| 3579 | + | ||
| 3580 | +[[package]] | ||
| 3581 | +name = "supports-unicode" | ||
| 3582 | +version = "2.1.0" | ||
| 3583 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3584 | +checksum = "f850c19edd184a205e883199a261ed44471c81e39bd95b1357f5febbef00e77a" | ||
| 3585 | +dependencies = [ | ||
| 3586 | + "is-terminal", | ||
| 3587 | +] | ||
| 3588 | + | ||
| 3469 | [[package]] | 3589 | [[package]] |
| 3470 | name = "syn" | 3590 | name = "syn" |
| 3471 | version = "1.0.109" | 3591 | version = "1.0.109" |
| @@ -3529,6 +3649,16 @@ dependencies = [ | |||
| 3529 | "windows-sys 0.52.0", | 3649 | "windows-sys 0.52.0", |
| 3530 | ] | 3650 | ] |
| 3531 | 3651 | ||
| 3652 | +[[package]] | ||
| 3653 | +name = "terminal_size" | ||
| 3654 | +version = "0.1.17" | ||
| 3655 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3656 | +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" | ||
| 3657 | +dependencies = [ | ||
| 3658 | + "libc", | ||
| 3659 | + "winapi", | ||
| 3660 | +] | ||
| 3661 | + | ||
| 3532 | [[package]] | 3662 | [[package]] |
| 3533 | name = "terminal_size" | 3663 | name = "terminal_size" |
| 3534 | version = "0.2.6" | 3664 | version = "0.2.6" |
| @@ -3539,6 +3669,17 @@ dependencies = [ | |||
| 3539 | "windows-sys 0.48.0", | 3669 | "windows-sys 0.48.0", |
| 3540 | ] | 3670 | ] |
| 3541 | 3671 | ||
| 3672 | +[[package]] | ||
| 3673 | +name = "textwrap" | ||
| 3674 | +version = "0.15.2" | ||
| 3675 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3676 | +checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d" | ||
| 3677 | +dependencies = [ | ||
| 3678 | + "smawk", | ||
| 3679 | + "unicode-linebreak", | ||
| 3680 | + "unicode-width", | ||
| 3681 | +] | ||
| 3682 | + | ||
| 3542 | [[package]] | 3683 | [[package]] |
| 3543 | name = "thiserror" | 3684 | name = "thiserror" |
| 3544 | version = "1.0.61" | 3685 | version = "1.0.61" |
| @@ -3787,6 +3928,12 @@ version = "1.0.12" | |||
| 3787 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3928 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3788 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" | 3929 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" |
| 3789 | 3930 | ||
| 3931 | +[[package]] | ||
| 3932 | +name = "unicode-linebreak" | ||
| 3933 | +version = "0.1.5" | ||
| 3934 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3935 | +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" | ||
| 3936 | + | ||
| 3790 | [[package]] | 3937 | [[package]] |
| 3791 | name = "unicode-normalization" | 3938 | name = "unicode-normalization" |
| 3792 | version = "0.1.23" | 3939 | version = "0.1.23" |
niri-config/Cargo.tomlmodified+1 -0
| @@ -20,3 +20,4 @@ tracy-client.workspace = true | |||
| 20 | 20 | ||
| 21 | [dev-dependencies] | 21 | [dev-dependencies] |
| 22 | pretty_assertions = "1.4.0" | 22 | pretty_assertions = "1.4.0" |
| 23 | +miette = { version = "5.10.0", features = ["fancy"] } | ||
niri-config/tests/wiki-parses.rsadded+108 -0
| @@ -0,0 +1,108 @@ | |||
| 1 | +use std::fs; | ||
| 2 | +use std::path::PathBuf; | ||
| 3 | + | ||
| 4 | +const NO_TEST_COMMENT: &str = "<!-- no-test -->"; | ||
| 5 | + | ||
| 6 | +struct KdlCodeBlock { | ||
| 7 | + filename: String, | ||
| 8 | + code: String, | ||
| 9 | + line_number: usize, | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +fn extract_kdl_from_file(file_contents: &str, filename: &str) -> Vec<KdlCodeBlock> { | ||
| 13 | + // Removes the > from callouts that might contain ```kdl``` | ||
| 14 | + let lines: Vec<_> = file_contents | ||
| 15 | + .lines() | ||
| 16 | + .map(|line| { | ||
| 17 | + let line = line.trim(); | ||
| 18 | + if line.starts_with(">") { | ||
| 19 | + if line.len() == 1 { | ||
| 20 | + "" | ||
| 21 | + } else { | ||
| 22 | + &line[2..] | ||
| 23 | + } | ||
| 24 | + } else { | ||
| 25 | + line | ||
| 26 | + } | ||
| 27 | + }) | ||
| 28 | + .enumerate() | ||
| 29 | + .collect(); | ||
| 30 | + | ||
| 31 | + let mut lines_iter = lines.iter(); | ||
| 32 | + let mut kdl_code_blocks = vec![]; | ||
| 33 | + | ||
| 34 | + while let Some((line_number, line)) = lines_iter.next() { | ||
| 35 | + let start_snippet = | ||
| 36 | + line.starts_with("```kdl") && lines[line_number - 1].1 != NO_TEST_COMMENT; | ||
| 37 | + | ||
| 38 | + if !start_snippet { | ||
| 39 | + continue; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + let mut snippet = String::new(); | ||
| 43 | + for (_, line) in lines_iter | ||
| 44 | + .by_ref() | ||
| 45 | + .take_while(|(_, line)| !line.starts_with("```")) | ||
| 46 | + { | ||
| 47 | + snippet.push_str(line); | ||
| 48 | + snippet.push('\n'); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + kdl_code_blocks.push(KdlCodeBlock { | ||
| 52 | + code: snippet, | ||
| 53 | + line_number: *line_number, | ||
| 54 | + filename: filename.to_string(), | ||
| 55 | + }); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + kdl_code_blocks | ||
| 59 | +} | ||
| 60 | + | ||
| 61 | +#[test] | ||
| 62 | +fn wiki_docs_parses() { | ||
| 63 | + let wiki_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../wiki"); | ||
| 64 | + | ||
| 65 | + let code_blocks = fs::read_dir(&wiki_dir) | ||
| 66 | + .unwrap() | ||
| 67 | + .filter_map(|entry| entry.ok()) | ||
| 68 | + .filter(|entry| entry.file_type().is_ok_and(|ft| ft.is_file())) | ||
| 69 | + .filter(|file| { | ||
| 70 | + file.path() | ||
| 71 | + .extension() | ||
| 72 | + .map(|ext| ext == "md") | ||
| 73 | + .unwrap_or(false) | ||
| 74 | + }) | ||
| 75 | + .map(|file| { | ||
| 76 | + let file_contents = fs::read_to_string(file.path()).unwrap(); | ||
| 77 | + let file_path = file.path(); | ||
| 78 | + let filename = file_path.to_str().unwrap(); | ||
| 79 | + extract_kdl_from_file(&file_contents, filename) | ||
| 80 | + }) | ||
| 81 | + .flatten(); | ||
| 82 | + | ||
| 83 | + let mut errors = vec![]; | ||
| 84 | + | ||
| 85 | + for KdlCodeBlock { | ||
| 86 | + code, | ||
| 87 | + line_number, | ||
| 88 | + filename, | ||
| 89 | + } in code_blocks | ||
| 90 | + { | ||
| 91 | + if let Err(error) = niri_config::Config::parse(&filename, &code) { | ||
| 92 | + errors.push(format!( | ||
| 93 | + "Error parsing wiki KDL code block at {}:{}: {:?}", | ||
| 94 | + filename, | ||
| 95 | + line_number, | ||
| 96 | + miette::Report::new(error) | ||
| 97 | + )) | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + if !errors.is_empty() { | ||
| 102 | + panic!( | ||
| 103 | + "Errors parsing {} wiki KDL code blocks:\n{}", | ||
| 104 | + errors.len(), | ||
| 105 | + errors.join("\n") | ||
| 106 | + ); | ||
| 107 | + } | ||
| 108 | +} | ||