From 2f2b895aecba046113059a8f0f1ca339767cb066 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Thu, 18 Aug 2022 14:57:51 +0300 Subject: [PATCH] tests/integration/cli: test that giving object as input to create-exe works --- tests/integration/cli/tests/create_exe.rs | 78 +++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/integration/cli/tests/create_exe.rs b/tests/integration/cli/tests/create_exe.rs index 67a75cb117a..65b4433d4ef 100644 --- a/tests/integration/cli/tests/create_exe.rs +++ b/tests/integration/cli/tests/create_exe.rs @@ -329,3 +329,81 @@ fn create_obj_serialized() -> anyhow::Result<()> { "serialized", ) } + +fn create_exe_with_object_input(args: Vec<&'static str>) -> anyhow::Result<()> { + let temp_dir = tempfile::tempdir()?; + let operating_dir: PathBuf = temp_dir.path().to_owned(); + + let wasm_path = operating_dir.join(create_exe_test_wasm_path()); + + #[cfg(not(windows))] + let object_path = operating_dir.join("wasm.o"); + #[cfg(windows)] + let object_path = operating_dir.join("wasm.obj"); + + WasmerCreateObj { + current_dir: operating_dir.clone(), + wasm_path, + output_object_path: object_path.clone(), + compiler: Compiler::Cranelift, + extra_cli_flags: args, + ..Default::default() + } + .run() + .context("Failed to create-obj wasm with Wasmer")?; + + assert!( + object_path.exists(), + "create-obj successfully completed but object output file `{}` missing", + object_path.display() + ); + let mut object_header_path = object_path.clone(); + object_header_path.set_extension("h"); + assert!( + object_header_path.exists(), + "create-obj successfully completed but object output header file `{}` missing", + object_header_path.display() + ); + + #[cfg(not(windows))] + let executable_path = operating_dir.join("wasm.out"); + #[cfg(windows)] + let executable_path = operating_dir.join("wasm.exe"); + + WasmerCreateExe { + current_dir: operating_dir.clone(), + wasm_path: object_path, + native_executable_path: executable_path.clone(), + compiler: Compiler::Cranelift, + extra_cli_flags: vec!["--header", "wasm.h"], + ..Default::default() + } + .run() + .context("Failed to create-exe wasm with Wasmer")?; + + let result = run_code( + &operating_dir, + &executable_path, + &["--eval".to_string(), "function greet(name) { return JSON.stringify('Hello, ' + name); }; print(greet('World'));".to_string()], + ) + .context("Failed to run generated executable")?; + let result_lines = result.lines().collect::>(); + assert_eq!(result_lines, vec!["\"Hello, World\""],); + + Ok(()) +} + +#[test] +fn create_exe_with_object_input_default() -> anyhow::Result<()> { + create_exe_with_object_input(vec![]) +} + +#[test] +fn create_exe_with_object_input_symbols() -> anyhow::Result<()> { + create_exe_with_object_input(vec!["--object-format", "symbols"]) +} + +#[test] +fn create_exe_with_object_input_serialized() -> anyhow::Result<()> { + create_exe_with_object_input(vec!["--object-format", "serialized"]) +}