From: Huck Boles Date: Sat, 20 May 2023 22:04:24 +0000 (-0500) Subject: added: scope tests X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=d8dbeea08914e9c9d4489deb8566c9b02b2b6f16;p=metaforge.git added: scope tests --- diff --git a/files/test_site/pattern/test/bad.meta b/files/test_site/pattern/test/bad.meta new file mode 100644 index 0000000..7b3a785 --- /dev/null +++ b/files/test_site/pattern/test/bad.meta @@ -0,0 +1 @@ +BAD diff --git a/files/test_site/pattern/test/good.meta b/files/test_site/pattern/test/good.meta new file mode 100644 index 0000000..f49b816 --- /dev/null +++ b/files/test_site/pattern/test/good.meta @@ -0,0 +1 @@ +GOOD diff --git a/files/test_site/pattern/test/scope.meta b/files/test_site/pattern/test/scope.meta new file mode 100644 index 0000000..43881ee --- /dev/null +++ b/files/test_site/pattern/test/scope.meta @@ -0,0 +1,5 @@ +${ *var = 'good' } + +${var} + +&{SOURCE} diff --git a/files/test_site/source/unit_tests/global/local_in_pattern.meta b/files/test_site/source/unit_tests/global/local_in_pattern.meta new file mode 100644 index 0000000..5db16f6 --- /dev/null +++ b/files/test_site/source/unit_tests/global/local_in_pattern.meta @@ -0,0 +1,8 @@ +${ var = 'bad' } + +&{ + body = DEFAULT + test = 'scope' +} + +${var} diff --git a/src/builder/tests.rs b/src/builder/tests.rs index 4ac2c09..1d7d2ed 100644 --- a/src/builder/tests.rs +++ b/src/builder/tests.rs @@ -84,6 +84,14 @@ fn builder_tests() -> Result<()> { } } + if let Err(e) = test_filetype_header() { + errs.push(e.into()); + } + + if let Err(e) = test_global() { + errs.push(e.into()); + } + if err { for e in errs.iter() { eprintln!("{}", e); @@ -94,7 +102,6 @@ fn builder_tests() -> Result<()> { Ok(()) } -#[test] fn test_filetype_header() -> Result<()> { let dir = PathBuf::from("files/test_site").canonicalize()?; @@ -106,18 +113,21 @@ fn test_filetype_header() -> Result<()> { let path = opts.source.join("unit_tests/header/filetype.meta"); let file = MetaFile::build(path, &opts)?; - assert_eq!( - file.dest()?, - opts.build.join("unit_tests/header/filetype.rss") - ); - - Ok(()) + if file.dest()? == opts.build.join("unit_tests/header/filetype.rss") { + Ok(()) + } else { + let err = eyre::eyre!("filetype - failed"); + eprintln!("{:?}", err); + eprintln!( + "\nTEST:\n{}\nOUTPUT:\n{}", + opts.build.join("unit_tests/header/filetype.rss").display(), + file.dest()?.display() + ); + Err(err) + } } -#[test] -#[ignore = "interferes with unit_tests"] fn test_global() -> Result<()> { - clean_build_dir()?; let dir = PathBuf::from("files/test_site/").canonicalize()?; let mut opts = Options::new(); @@ -132,12 +142,12 @@ fn test_global() -> Result<()> { dir_node.build_dir()?; assert_eq!( - std::fs::read_to_string(dir.join("build/unit_tests/global/pattern.html"))?, + fs::read_to_string(dir.join("build/unit_tests/global/pattern.html"))?, "

GOOD GOOD

\n" ); assert_eq!( - std::fs::read_to_string(dir.join("build/unit_tests/global/variable.html"))?, + fs::read_to_string(dir.join("build/unit_tests/global/variable.html"))?, "

GOODGOOD

\n" );