Browse Source

Properly implement feature flags

github-actions
Garrit Franke 3 years ago
parent
commit
b4580fff7b
  1. 10
      src/generator/mod.rs
  2. 3
      src/main.rs
  3. 2
      src/tests/mod.rs
  4. 20
      src/tests/test_examples.rs

10
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")
}
}

3
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);
}

2
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;

20
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(())

Loading…
Cancel
Save