Browse Source

feat: enable test_examples tests for other backends

github-actions
Garrit Franke 2 years ago
parent
commit
047a9585ec
  1. 4
      examples/playground.sb
  2. 3
      src/tests/mod.rs
  3. 30
      src/tests/test_examples.rs

4
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)
}
}

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

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

Loading…
Cancel
Save