From 047a9585ec6473646ace500207f5d3578e772811 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Sun, 7 Feb 2021 20:56:08 +0100 Subject: [PATCH] feat: enable test_examples tests for other backends --- examples/playground.sb | 4 ++-- src/tests/mod.rs | 3 --- src/tests/test_examples.rs | 30 +++++++++++++++++++----------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/examples/playground.sb b/examples/playground.sb index 41575ae..502a6ee 100644 --- a/examples/playground.sb +++ b/examples/playground.sb @@ -1,8 +1,8 @@ fn main() { - let arr = [1, "Two", 3] + let arr = ["Foo", "Bar"] for x in arr { - println(x) + _printf(x) } } \ No newline at end of file diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 8affd18..0797029 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -13,7 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/// This test currently only runs on the node backend, and has to be disabled for the C backend -#[cfg(feature = "backend_node")] mod test_examples; diff --git a/src/tests/test_examples.rs b/src/tests/test_examples.rs index 9a7f24c..ee33056 100644 --- a/src/tests/test_examples.rs +++ b/src/tests/test_examples.rs @@ -25,6 +25,14 @@ fn test_directory(dir_in: &str) -> Result<(), Error> { let _ = fs::create_dir(&dir_out); + let out_file_suffix = if cfg!(feature = "backend_node") { + ".js" + } else if cfg!(feature = "backend_c") { + ".c" + } else { + todo!() + }; + for ex in examples { let example = ex?; let in_file = dir.join(dir_in).join(example.file_name()); @@ -33,7 +41,7 @@ fn test_directory(dir_in: &str) -> Result<(), Error> { .file_name() .into_string() .unwrap() - .replace(".sb", ".js"), + .replace(".sb", out_file_suffix), ); let success = Command::new("cargo") .arg("run") @@ -46,28 +54,28 @@ fn test_directory(dir_in: &str) -> Result<(), Error> { .success(); assert_eq!(success, true, "{:?}", &in_file); - let node_installed = Command::new("node").arg("-v").spawn()?.wait()?.success(); - if node_installed { - let execution = Command::new("node") - .arg(out_file) - .spawn()? - .wait()? - .success(); - assert_eq!(execution, true, "{:?}", &in_file) + if cfg!(feature = "backend_node") { + let node_installed = Command::new("node").arg("-v").spawn()?.wait()?.success(); + if node_installed { + let execution = Command::new("node") + .arg(out_file) + .spawn()? + .wait()? + .success(); + assert_eq!(execution, true, "{:?}", &in_file) + } } } Ok(()) } #[test] -#[cfg(feature = "backend_node")] fn test_examples() -> Result<(), Error> { test_directory("examples")?; Ok(()) } #[test] -#[cfg(feature = "backend_node")] fn test_testcases() -> Result<(), Error> { test_directory("tests")?; Ok(())