2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-07-11 21:12:26 -04:00
|
|
|
|
|
|
|
use std::process::Command;
|
|
|
|
use test_util::deno_cmd;
|
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
const BUILD_VARIANT: &str = "debug";
|
|
|
|
|
|
|
|
#[cfg(not(debug_assertions))]
|
|
|
|
const BUILD_VARIANT: &str = "release";
|
|
|
|
|
2022-01-10 10:33:25 -05:00
|
|
|
fn build() {
|
2021-07-11 21:12:26 -04:00
|
|
|
let mut build_plugin_base = Command::new("cargo");
|
|
|
|
let mut build_plugin =
|
2021-08-06 17:28:10 -04:00
|
|
|
build_plugin_base.arg("build").arg("-p").arg("test_ffi");
|
2021-07-11 21:12:26 -04:00
|
|
|
if BUILD_VARIANT == "release" {
|
|
|
|
build_plugin = build_plugin.arg("--release");
|
|
|
|
}
|
|
|
|
let build_plugin_output = build_plugin.output().unwrap();
|
|
|
|
assert!(build_plugin_output.status.success());
|
2022-01-10 10:33:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn basic() {
|
|
|
|
build();
|
|
|
|
|
2021-07-11 21:12:26 -04:00
|
|
|
let output = deno_cmd()
|
|
|
|
.arg("run")
|
2021-08-06 17:28:10 -04:00
|
|
|
.arg("--allow-ffi")
|
|
|
|
.arg("--allow-read")
|
2021-07-11 21:12:26 -04:00
|
|
|
.arg("--unstable")
|
2022-01-05 02:25:31 -05:00
|
|
|
.arg("--quiet")
|
2021-07-11 21:12:26 -04:00
|
|
|
.arg("tests/test.js")
|
2021-08-06 17:28:10 -04:00
|
|
|
.env("NO_COLOR", "1")
|
2021-07-11 21:12:26 -04:00
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
let stdout = std::str::from_utf8(&output.stdout).unwrap();
|
|
|
|
let stderr = std::str::from_utf8(&output.stderr).unwrap();
|
|
|
|
if !output.status.success() {
|
|
|
|
println!("stdout {}", stdout);
|
|
|
|
println!("stderr {}", stderr);
|
|
|
|
}
|
|
|
|
println!("{:?}", output.status);
|
|
|
|
assert!(output.status.success());
|
|
|
|
let expected = "\
|
2021-08-06 17:28:10 -04:00
|
|
|
something\n\
|
2021-10-05 18:27:05 -04:00
|
|
|
[1, 2, 3, 4, 5, 6, 7, 8]\n\
|
2021-10-10 09:18:02 -04:00
|
|
|
[1, 2, 3, 4, 5, 6, 7, 8] [9, 10]\n\
|
2021-12-15 09:41:49 -05:00
|
|
|
[1, 2, 3, 4, 5, 6, 7, 8]\n\
|
|
|
|
[ 1, 2, 3, 4, 5, 6 ]\n\
|
|
|
|
[ 4, 5, 6 ]\n\
|
|
|
|
[ 4, 5, 6 ]\n\
|
|
|
|
Hello from pointer!\n\
|
|
|
|
pointer!\n\
|
|
|
|
false\n\
|
|
|
|
true\n\
|
|
|
|
false\n\
|
2021-08-06 17:28:10 -04:00
|
|
|
579\n\
|
2022-01-12 06:38:26 -05:00
|
|
|
true\n\
|
|
|
|
579\n\
|
2021-09-20 14:38:28 -04:00
|
|
|
579\n\
|
|
|
|
579\n\
|
|
|
|
579\n\
|
|
|
|
579\n\
|
|
|
|
579\n\
|
|
|
|
579.9119873046875\n\
|
|
|
|
579.912\n\
|
2022-01-11 01:21:16 -05:00
|
|
|
After sleep_blocking\n\
|
|
|
|
true\n\
|
2021-10-05 08:50:00 -04:00
|
|
|
Before\n\
|
|
|
|
true\n\
|
2022-02-18 07:21:19 -05:00
|
|
|
Static u32: 42\n\
|
|
|
|
Static ptr: true\n\
|
|
|
|
Static ptr value: 42\n\
|
2021-10-05 08:50:00 -04:00
|
|
|
After\n\
|
|
|
|
true\n\
|
2021-08-06 17:28:10 -04:00
|
|
|
Correct number of resources\n";
|
2021-07-11 21:12:26 -04:00
|
|
|
assert_eq!(stdout, expected);
|
|
|
|
assert_eq!(stderr, "");
|
|
|
|
}
|
2022-01-10 10:33:25 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn symbol_types() {
|
|
|
|
build();
|
|
|
|
|
|
|
|
let output = deno_cmd()
|
|
|
|
.arg("cache")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--quiet")
|
|
|
|
.arg("tests/ffi_types.ts")
|
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
let stdout = std::str::from_utf8(&output.stdout).unwrap();
|
|
|
|
let stderr = std::str::from_utf8(&output.stderr).unwrap();
|
|
|
|
if !output.status.success() {
|
|
|
|
println!("stdout {}", stdout);
|
|
|
|
println!("stderr {}", stderr);
|
|
|
|
}
|
|
|
|
println!("{:?}", output.status);
|
|
|
|
assert!(output.status.success());
|
|
|
|
assert_eq!(stderr, "");
|
|
|
|
}
|