From: Huck Boles Date: Fri, 5 May 2023 16:05:03 +0000 (-0500) Subject: tmp_dir struct X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=2ff32794e178fdd035e88f908bf8d6879b113b16;p=metaforge.git tmp_dir struct --- diff --git a/Cargo.lock b/Cargo.lock index c893209..a428742 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,6 +85,22 @@ dependencies = [ "typenum", ] +[[package]] +name = "ctor" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "digest" version = "0.10.6" @@ -162,6 +178,7 @@ dependencies = [ "pandoc", "pest", "pest_derive", + "pretty_assertions", "walkdir", ] @@ -189,6 +206,15 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +[[package]] +name = "output_vt100" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" +dependencies = [ + "winapi", +] + [[package]] name = "owo-colors" version = "1.3.0" @@ -234,7 +260,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn", + "syn 2.0.15", ] [[package]] @@ -248,6 +274,18 @@ dependencies = [ "sha2", ] +[[package]] +name = "pretty_assertions" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755" +dependencies = [ + "ctor", + "diff", + "output_vt100", + "yansi", +] + [[package]] name = "proc-macro2" version = "1.0.56" @@ -292,6 +330,17 @@ dependencies = [ "digest", ] +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.15" @@ -320,7 +369,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.15", ] [[package]] @@ -387,3 +436,9 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" diff --git a/Cargo.toml b/Cargo.toml index ba31c7b..881d1ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,5 +7,8 @@ edition = "2021" pandoc = "0.8" color-eyre = { version = "0.5", default-features = false } walkdir = "2" -pest = "2.0" -pest_derive = "2.0" +pest = "2" +pest_derive = "2" + +[dev-dependencies] +pretty_assertions = "1" diff --git a/src/tests/test_files/test_site/pattern/base/default.meta b/src/tests/test_files/test_site/pattern/base/default.meta new file mode 100644 index 0000000..e69de29 diff --git a/src/tests/test_files/test_site/pattern/pat/default.meta b/src/tests/test_files/test_site/pattern/pat/default.meta new file mode 100644 index 0000000..e69de29 diff --git a/src/tests/test_files/test_site/pattern/pat/pattern.meta b/src/tests/test_files/test_site/pattern/pat/pattern.meta new file mode 100644 index 0000000..e69de29 diff --git a/src/tests/test_files/test_pattern.meta b/src/tests/test_files/test_site/pattern/test/pattern.meta similarity index 100% rename from src/tests/test_files/test_pattern.meta rename to src/tests/test_files/test_site/pattern/test/pattern.meta diff --git a/src/tests/test_files/test_expand.meta b/src/tests/test_files/test_site/source/expand.meta similarity index 100% rename from src/tests/test_files/test_expand.meta rename to src/tests/test_files/test_site/source/expand.meta diff --git a/src/tests/test_files/test_site/source/root.meta b/src/tests/test_files/test_site/source/root.meta new file mode 100644 index 0000000..e69de29 diff --git a/src/tests/test_files/test_site/source/sub_dir/sub_source.meta b/src/tests/test_files/test_site/source/sub_dir/sub_source.meta new file mode 100644 index 0000000..e69de29 diff --git a/src/tests/test_files/test_source.meta b/src/tests/test_files/test_site/source/test_source.meta similarity index 100% rename from src/tests/test_files/test_source.meta rename to src/tests/test_files/test_site/source/test_source.meta diff --git a/src/tests/test_metafile.rs b/src/tests/test_metafile.rs index 1727a75..68b7ab3 100644 --- a/src/tests/test_metafile.rs +++ b/src/tests/test_metafile.rs @@ -1,13 +1,34 @@ -#![allow(dead_code, unused)] use crate::{metafile_to_string, parse_file, source, RootDirs, Source, Substitution}; use color_eyre::Result; +use pretty_assertions::assert_eq; use std::path::PathBuf; -static SOURCE: &str = include_str!("./test_files/test_source.meta"); -static PATTERN: &str = include_str!("./test_files/test_pattern.meta"); -static PRE_EXPAND: &str = include_str!("./test_files/test_expand.meta"); +static SOURCE: &str = include_str!("./test_files/test_site/source/test_source.meta"); +static PATTERN: &str = include_str!("./test_files/test_site/pattern/test/pattern.meta"); +static PRE_EXPAND: &str = include_str!("./test_files/test_site/source/expand.meta"); static POST_EXPAND: &str = include_str!("./test_files/test_expanded"); +// builds a tmp_dir then runs multiple tests on it, then deletes the tmpdir +// so we don't have to rebuild entire tmpdir every test +fn test_on_tmp_dir(tests: Vec Result<()>>) -> Result<()> { + let tmp_dir = std::env::temp_dir(); + + let dirs = RootDirs { + source: tmp_dir.join("source"), + build: tmp_dir.join("site"), + pattern: tmp_dir.join("pattern"), + }; + + for test in tests.iter() { + std::fs::remove_dir_all(&dirs.build)?; + std::fs::create_dir(&dirs.build)?; + test(&dirs)?; + } + + std::fs::remove_dir_all(tmp_dir)?; + Ok(()) +} + #[test] fn test_metafile_gets() -> Result<()> { let source = parse_file(SOURCE)?; @@ -78,17 +99,19 @@ fn parse_pattern_file() -> Result<()> { Ok(()) } -#[ignore = "todo: build tmp directory"] #[test] -fn test_metafile_to_str() -> Result<()> { +fn builder_tests() -> Result<()> { + // vector of tests to perform on tmp_dir + let mut tests: Vec Result<()>> = Vec::default(); + tests.push(test_metafile_to_str); + test_on_tmp_dir(tests)?; + Ok(()) +} + +fn test_metafile_to_str(dirs: &RootDirs) -> Result<()> { let metafile = parse_file(PRE_EXPAND)?; - let dirs = RootDirs { - source: PathBuf::new(), - build: PathBuf::new(), - pattern: PathBuf::new(), - }; - let file = metafile_to_string(&metafile, &dirs, None)?; + let file = metafile_to_string(&metafile, dirs, None)?; assert_eq!(file, POST_EXPAND);