#![cfg(any(
not(any(
feature = "parser_tests",
feature = "analyzer_tests",
feature = "codegen_tests",
feature = "interpreter_tests",
feature = "conformance_tests",
feature = "integration_tests",
)),
feature = "integration_tests",
))]
#[path = "common/test_utils.rs"]
mod test_utils;
use anyhow::Result;
use std::fs;
use std::process::Command;
use tempfile::tempdir;
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_ffi_dependencies_copied_to_test_library() -> Result<()> {
let _tmp = tempdir()?;
let temp_dir = _tmp.path().to_path_buf();
let src_dir = temp_dir.join("src");
fs::create_dir_all(&src_dir)?;
let simple_wj = src_dir.join("simple.wj");
fs::write(
&simple_wj,
r#"
fn add(a: i32, b: i32) -> i32 {
a + b
}
"#,
)?;
let src_ffi_dir = temp_dir.join("src").join("ffi");
fs::create_dir_all(&src_ffi_dir)?;
let ffi_mod_rs = src_ffi_dir.join("mod.rs");
fs::write(
&ffi_mod_rs,
r#"
pub mod gpu;
pub use gpu::*;
"#,
)?;
let ffi_gpu_rs = src_ffi_dir.join("gpu.rs");
fs::write(
&ffi_gpu_rs,
r#"
use wgpu;
pub fn gpu_init() -> bool {
// Uses wgpu
true
}
"#,
)?;
let cargo_toml = temp_dir.join("Cargo.toml");
fs::write(
&cargo_toml,
r#"
[package]
name = "ffi-deps-test"
version = "0.1.0"
edition = "2021"
[dependencies]
wgpu = "0.19"
"#,
)?;
let wj_toml = temp_dir.join("wj.toml");
fs::write(
&wj_toml,
r#"
[package]
name = "ffi-deps-test"
version = "0.1.0"
[dependencies]
"#,
)?;
let tests_wj_dir = temp_dir.join("tests_wj");
fs::create_dir_all(&tests_wj_dir)?;
let test_wj = tests_wj_dir.join("simple_test.wj");
fs::write(
&test_wj,
r#"
@test
fn test_simple() {
assert!(true);
}
"#,
)?;
let wj_compiler = test_utils::wj_binary();
let output = Command::new(&wj_compiler)
.arg("test")
.arg(&test_wj)
.current_dir(&temp_dir)
.output()?;
let stderr = String::from_utf8_lossy(&output.stderr);
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
!stderr.contains("no external crate `wgpu`")
&& !stdout.contains("no external crate `wgpu`"),
"Test library should have wgpu dependency when FFI uses it.\nSTDOUT:\n{}\nSTDERR:\n{}",
stdout,
stderr
);
assert!(
stdout.contains("Library compiled successfully")
|| stdout.contains("test result:")
|| stderr.contains("test result:"),
"Test library should compile successfully with FFI dependencies.\nSTDOUT:\n{}\nSTDERR:\n{}",
stdout,
stderr
);
Ok(())
}