diff --git a/src/generator/mod.rs b/src/generator/mod.rs index 2e96df1..8f2f045 100644 --- a/src/generator/mod.rs +++ b/src/generator/mod.rs @@ -26,13 +26,11 @@ pub trait Generator { } pub fn generate(prog: Program) -> String { - #[cfg(feature = "backend_c")] - { + if cfg!(feature = "backend_c") { c::CGenerator::generate(prog) - } - - #[cfg(feature = "backend_node")] - { + } else if cfg!(feature = "backend_node") { js::JsGenerator::generate(prog) + } else { + panic!("No backend specified") } } diff --git a/src/main.rs b/src/main.rs index 9c97f71..1fb0f38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,8 +65,7 @@ fn main() -> Result<(), String> { let mut program = parser::parse(tokens, Some(contents))?; // C Backend currently does not support stdlib yet, since not all features are implemented - #[cfg(features = "backend_node")] - { + if cfg!(feature = "backend_node") { let stdlib = build_stdlib(); program.merge_with(stdlib); } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 8d00b6a..8affd18 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -15,5 +15,5 @@ */ /// This test currently only runs on the node backend, and has to be disabled for the C backend -#[cfg(backend_node)] +#[cfg(feature = "backend_node")] mod test_examples; diff --git a/src/tests/test_examples.rs b/src/tests/test_examples.rs index ee974dc..eee69c5 100644 --- a/src/tests/test_examples.rs +++ b/src/tests/test_examples.rs @@ -17,6 +17,7 @@ use std::fs; use std::io::Error; use std::process::Command; #[test] +#[cfg(feature = "backend_node")] fn test_examples() -> Result<(), Error> { let dir = std::env::current_dir().unwrap(); @@ -45,17 +46,14 @@ fn test_examples() -> Result<(), Error> { .success(); assert_eq!(success, true, "{:?}", &in_file); - #[cfg(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) - } + 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(())