Browse Source

feat: enable test_examples tests for other backends

github-actions
Garrit Franke 3 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() { fn main() {
let arr = [1, "Two", 3] let arr = ["Foo", "Bar"]
for x in arr { 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 * See the License for the specific language governing permissions and
* limitations under the License. * 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; 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 _ = 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 { for ex in examples {
let example = ex?; let example = ex?;
let in_file = dir.join(dir_in).join(example.file_name()); 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() .file_name()
.into_string() .into_string()
.unwrap() .unwrap()
.replace(".sb", ".js"), .replace(".sb", out_file_suffix),
); );
let success = Command::new("cargo") let success = Command::new("cargo")
.arg("run") .arg("run")
@ -46,28 +54,28 @@ fn test_directory(dir_in: &str) -> Result<(), Error> {
.success(); .success();
assert_eq!(success, true, "{:?}", &in_file); assert_eq!(success, true, "{:?}", &in_file);
let node_installed = Command::new("node").arg("-v").spawn()?.wait()?.success(); if cfg!(feature = "backend_node") {
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(())
} }
#[test] #[test]
#[cfg(feature = "backend_node")]
fn test_examples() -> Result<(), Error> { fn test_examples() -> Result<(), Error> {
test_directory("examples")?; test_directory("examples")?;
Ok(()) Ok(())
} }
#[test] #[test]
#[cfg(feature = "backend_node")]
fn test_testcases() -> Result<(), Error> { fn test_testcases() -> Result<(), Error> {
test_directory("tests")?; test_directory("tests")?;
Ok(()) Ok(())

Loading…
Cancel
Save