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 { pub fn generate(prog: Program) -> String {
#[cfg(feature = "backend_c")] if cfg!(feature = "backend_c") {
{
c::CGenerator::generate(prog) c::CGenerator::generate(prog)
} } else if cfg!(feature = "backend_node") {
#[cfg(feature = "backend_node")]
{
js::JsGenerator::generate(prog) 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))?; let mut program = parser::parse(tokens, Some(contents))?;
// C Backend currently does not support stdlib yet, since not all features are implemented // 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(); let stdlib = build_stdlib();
program.merge_with(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 /// 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; mod test_examples;

20
src/tests/test_examples.rs

@ -17,6 +17,7 @@ use std::fs;
use std::io::Error; use std::io::Error;
use std::process::Command; use std::process::Command;
#[test] #[test]
#[cfg(feature = "backend_node")]
fn test_examples() -> Result<(), Error> { fn test_examples() -> Result<(), Error> {
let dir = std::env::current_dir().unwrap(); let dir = std::env::current_dir().unwrap();
@ -45,17 +46,14 @@ fn test_examples() -> Result<(), Error> {
.success(); .success();
assert_eq!(success, true, "{:?}", &in_file); assert_eq!(success, true, "{:?}", &in_file);
#[cfg(backend_node)] let node_installed = Command::new("node").arg("-v").spawn()?.wait()?.success();
{ if node_installed {
let node_installed = Command::new("node").arg("-v").spawn()?.wait()?.success(); let execution = Command::new("node")
if node_installed { .arg(out_file)
let execution = Command::new("node") .spawn()?
.arg(out_file) .wait()?
.spawn()? .success();
.wait()? assert_eq!(execution, true, "{:?}", &in_file)
.success();
assert_eq!(execution, true, "{:?}", &in_file)
}
} }
} }
Ok(()) Ok(())

Loading…
Cancel
Save