1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

test(std/wasi): add wasi-testsuite as a submodule (#7042)

This commit is contained in:
Casper Beyer 2020-08-25 20:36:50 +08:00 committed by GitHub
parent 54d336ab20
commit f7174267e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 87 additions and 390 deletions

3
.gitmodules vendored
View file

@ -1,3 +1,6 @@
[submodule "deno_third_party"] [submodule "deno_third_party"]
path = third_party path = third_party
url = https://github.com/denoland/deno_third_party.git url = https://github.com/denoland/deno_third_party.git
[submodule "std/wasi/testdata"]
path = std/wasi/testdata
url = git@github.com:khronosproject/wasi-test-suite.git

View file

@ -1,17 +1,32 @@
/* eslint-disable */ /* eslint-disable */
import { assert, assertEquals } from "../testing/asserts.ts"; import { assert, assertEquals } from "../testing/asserts.ts";
import { copy } from "../fs/mod.ts";
import * as path from "../path/mod.ts"; import * as path from "../path/mod.ts";
import Context from "./snapshot_preview1.ts"; import Context from "./snapshot_preview1.ts";
const ignore = [
"wasi_clock_time_get_realtime.wasm",
];
// TODO(caspervonb) investigate why these tests are failing on windows and fix
// them.
if (Deno.build.os == "windows") {
ignore.push("std_fs_metadata_absolute.wasm");
ignore.push("std_fs_metadata_relative.wasm");
ignore.push("std_fs_read_dir_absolute.wasm");
ignore.push("std_fs_read_dir_relative.wasm");
}
if (import.meta.main) { if (import.meta.main) {
const options = JSON.parse(Deno.args[0]); const options = JSON.parse(Deno.args[0]);
const binary = await Deno.readFile(Deno.args[1]); const pathname = Deno.args[1];
const binary = await Deno.readFile(pathname);
const module = await WebAssembly.compile(binary); const module = await WebAssembly.compile(binary);
const context = new Context({ const context = new Context({
env: options.env, env: options.env,
args: options.args, args: [pathname].concat(options.args),
preopens: options.preopens, preopens: options.preopens,
}); });
@ -25,58 +40,31 @@ if (import.meta.main) {
} else { } else {
const rootdir = path.dirname(path.fromFileUrl(import.meta.url)); const rootdir = path.dirname(path.fromFileUrl(import.meta.url));
const testdir = path.join(rootdir, "testdata"); const testdir = path.join(rootdir, "testdata");
const outdir = path.join(testdir, "snapshot_preview1");
for await (const entry of Deno.readDir(testdir)) { for await (const entry of Deno.readDir(testdir)) {
if (!entry.name.endsWith(".rs")) {
continue;
}
const process = Deno.run({
cmd: [
"rustc",
"--target",
"wasm32-wasi",
"--out-dir",
outdir,
path.join(testdir, entry.name),
],
stdout: "inherit",
stderr: "inherit",
});
const status = await process.status();
assert(status.success);
process.close();
// TODO(caspervonb) allow the prelude to span multiple lines
const source = await Deno.readTextFile(path.join(testdir, entry.name));
const prelude = source.match(/^\/\/\s*\{.*/);
if (prelude) {
const basename = entry.name.replace(/.rs$/, ".json");
await Deno.writeTextFile(
path.join(outdir, basename),
prelude[0].slice(2),
);
}
}
for await (const entry of Deno.readDir(outdir)) {
if (!entry.name.endsWith(".wasm")) { if (!entry.name.endsWith(".wasm")) {
continue; continue;
} }
Deno.test(entry.name, async function () { Deno.test({
name: entry.name,
ignore: ignore.includes(entry.name),
fn: async function () {
const basename = entry.name.replace(/\.wasm$/, ".json"); const basename = entry.name.replace(/\.wasm$/, ".json");
const prelude = await Deno.readTextFile(path.resolve(outdir, basename)); const prelude = await Deno.readTextFile(
path.resolve(testdir, basename),
);
const options = JSON.parse(prelude); const options = JSON.parse(prelude);
await Deno.mkdir(`${testdir}/scratch`); const workdir = await Deno.makeTempDir();
await copy(
path.join(testdir, "fixtures"),
path.join(workdir, "fixtures"),
);
try { try {
const process = await Deno.run({ const process = await Deno.run({
cwd: testdir, cwd: workdir,
cmd: [ cmd: [
`${Deno.execPath()}`, `${Deno.execPath()}`,
"run", "run",
@ -85,7 +73,7 @@ if (import.meta.main) {
"--allow-all", "--allow-all",
import.meta.url, import.meta.url,
prelude, prelude,
path.resolve(outdir, entry.name), path.resolve(testdir, entry.name),
], ],
stdin: "piped", stdin: "piped",
stdout: "piped", stdout: "piped",
@ -119,12 +107,6 @@ if (import.meta.main) {
process.stderr.close(); process.stderr.close();
if (options.files) {
for (const [key, value] of Object.entries(options.files)) {
assertEquals(value, await Deno.readTextFile(`${testdir}/${key}`));
}
}
const status = await process.status(); const status = await process.status();
assertEquals(status.code, options.exitCode ? +options.exitCode : 0); assertEquals(status.code, options.exitCode ? +options.exitCode : 0);
@ -132,8 +114,9 @@ if (import.meta.main) {
} catch (err) { } catch (err) {
throw err; throw err;
} finally { } finally {
await Deno.remove(`${testdir}/scratch`, { recursive: true }); await Deno.remove(workdir, { recursive: true });
} }
},
}); });
} }
} }

1
std/wasi/testdata Submodule

@ -0,0 +1 @@
Subproject commit 419874edc0dd334df55760ba626ecc94a1df7cc9

View file

@ -1 +0,0 @@
directory/file

View file

@ -1 +0,0 @@
file

View file

@ -1 +0,0 @@
file

View file

@ -1 +0,0 @@
directory

View file

@ -1 +0,0 @@
file

View file

@ -1,9 +0,0 @@
// { "args": ["one", "two", "three" ]}
fn main() {
let mut args = std::env::args();
assert_eq!(args.len(), 3);
assert_eq!(args.next().unwrap(), "one");
assert_eq!(args.next().unwrap(), "two");
assert_eq!(args.next().unwrap(), "three");
}

View file

@ -1,6 +0,0 @@
// { "env": { "one": "1", "two": "2", "three": "3" } }
fn main() {
let vars = std::env::vars();
assert_eq!(vars.count(), 3);
}

View file

@ -1,6 +0,0 @@
// { "preopens": { "/scratch": "scratch" } }
fn main() {
assert!(std::fs::create_dir("/scratch/directory").is_ok());
assert!(std::fs::metadata("/scratch/directory").unwrap().is_dir());
}

View file

@ -1,6 +0,0 @@
// { "preopens": { "/scratch": "scratch" } }
fn main() {
assert!(std::fs::File::create("/scratch/file").is_ok());
assert!(std::fs::metadata("/scratch/file").unwrap().is_file());
}

View file

@ -1,23 +0,0 @@
// { "preopens": { "/fixture": "fixture" } }
fn main() {
let file = std::fs::File::open("/fixture/file").unwrap();
let metadata = file.metadata().unwrap();
assert!(metadata.is_file());
assert!(metadata.len() == 5);
let file = std::fs::File::open("/fixture/symlink_to_file").unwrap();
let metadata = file.metadata().unwrap();
assert!(metadata.is_file());
assert!(metadata.len() == 5);
let file = std::fs::File::open("/fixture/directory/file").unwrap();
let metadata = file.metadata().unwrap();
assert!(metadata.is_file());
assert!(metadata.len() == 15);
let file = std::fs::File::open("/fixture/directory/symlink_to_file").unwrap();
let metadata = file.metadata().unwrap();
assert!(metadata.is_file());
assert!(metadata.len() == 15);
}

View file

@ -1,16 +0,0 @@
// { "preopens": { "/fixture": "fixture" } }
use std::io::Read;
fn main() {
let mut file = std::fs::File::open("/fixture/file").unwrap();
let mut buffer = [0; 2];
assert_eq!(file.read(&mut buffer).unwrap(), 2);
assert_eq!(&buffer, b"fi");
assert_eq!(file.read(&mut buffer).unwrap(), 2);
assert_eq!(&buffer, b"le");
assert_eq!(file.read(&mut buffer).unwrap(), 1);
}

View file

@ -1,33 +0,0 @@
// { "preopens": { "/fixture": "fixture" } }
use std::io::Seek;
fn main() {
let mut file = std::fs::File::open("/fixture/file").unwrap();
assert_eq!(file.seek(std::io::SeekFrom::Current(0)).unwrap(), 0);
assert_eq!(file.seek(std::io::SeekFrom::Start(1)).unwrap(), 1);
assert_eq!(file.seek(std::io::SeekFrom::Start(2)).unwrap(), 2);
assert_eq!(file.seek(std::io::SeekFrom::Start(3)).unwrap(), 3);
assert_eq!(file.seek(std::io::SeekFrom::Start(4)).unwrap(), 4);
assert_eq!(file.seek(std::io::SeekFrom::Start(5)).unwrap(), 5);
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 4);
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 3);
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 2);
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 1);
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 0);
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 1);
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 2);
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 3);
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 4);
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 5);
assert_eq!(file.seek(std::io::SeekFrom::End(0)).unwrap(), 5);
assert_eq!(file.seek(std::io::SeekFrom::End(-1)).unwrap(), 4);
assert_eq!(file.seek(std::io::SeekFrom::End(-2)).unwrap(), 3);
assert_eq!(file.seek(std::io::SeekFrom::End(-3)).unwrap(), 2);
assert_eq!(file.seek(std::io::SeekFrom::End(-4)).unwrap(), 1);
assert_eq!(file.seek(std::io::SeekFrom::End(-5)).unwrap(), 0);
}

View file

@ -1,17 +0,0 @@
// { "preopens": { "/scratch": "scratch" } }
fn main() {
let file = std::fs::File::create("/scratch/file").unwrap();
assert!(file.set_len(0).is_ok());
assert_eq!(file.metadata().unwrap().len(), 0);
assert!(file.set_len(5).is_ok());
assert_eq!(file.metadata().unwrap().len(), 5);
assert!(file.set_len(25).is_ok());
assert_eq!(file.metadata().unwrap().len(), 25);
assert!(file.set_len(0).is_ok());
assert_eq!(file.metadata().unwrap().len(), 0);
}

View file

@ -1,15 +0,0 @@
// { "preopens": { "/scratch": "scratch" } }
fn main() {
let file = std::fs::File::create("/scratch/file").unwrap();
assert!(file.set_len(5).is_ok());
assert!(file.sync_all().is_ok());
let metadata = std::fs::metadata("/scratch/file").unwrap();
assert_eq!(metadata.len(), 5);
assert!(file.set_len(25).is_ok());
assert!(file.sync_all().is_ok());
let metadata = std::fs::metadata("/scratch/file").unwrap();
assert_eq!(metadata.len(), 25);
}

View file

@ -1,15 +0,0 @@
// { "preopens": { "/scratch": "scratch" } }
use std::io::Write;
fn main() {
let mut file = std::fs::File::create("/scratch/file").unwrap();
assert!(file.write(b"Hello").is_ok());
assert!(file.sync_data().is_ok());
assert_eq!(std::fs::read("/scratch/file").unwrap(), b"Hello");
assert!(file.write(b", world!").is_ok());
assert!(file.sync_data().is_ok());
assert_eq!(std::fs::read("/scratch/file").unwrap(), b"Hello, world!");
}

View file

@ -1,9 +0,0 @@
// { "preopens": { "/scratch": "scratch" }, "files": { "scratch/file": "file" } }
use std::io::Write;
fn main() {
let mut file = std::fs::File::create("/scratch/file").unwrap();
assert_eq!(file.write(b"fi").unwrap(), 2);
assert_eq!(file.write(b"le").unwrap(), 2);
}

View file

@ -1,11 +0,0 @@
// { "preopens": { "/fixture": "fixture", "/scratch": "scratch" } }
fn main() {
assert!(
std::fs::hard_link("/fixture/file", "/scratch/hardlink_to_file").is_ok()
);
assert_eq!(
std::fs::read("/fixture/file").unwrap(),
std::fs::read("/scratch/hardlink_to_file").unwrap()
);
}

View file

@ -1,26 +0,0 @@
// { "preopens": { "/fixture": "fixture" } }
fn main() {
let metadata = std::fs::metadata("/fixture/directory").unwrap();
assert!(metadata.is_dir());
let metadata = std::fs::metadata("/fixture/symlink_to_directory").unwrap();
assert!(metadata.is_dir());
let metadata = std::fs::metadata("/fixture/file").unwrap();
assert!(metadata.is_file());
assert_eq!(metadata.len(), 5);
let metadata = std::fs::metadata("/fixture/symlink_to_file").unwrap();
assert!(metadata.is_file());
assert_eq!(metadata.len(), 5);
let metadata = std::fs::metadata("/fixture/directory/file").unwrap();
assert!(metadata.is_file());
assert_eq!(metadata.len(), 15);
let metadata =
std::fs::metadata("/fixture/directory/symlink_to_file").unwrap();
assert!(metadata.is_file());
assert_eq!(metadata.len(), 15);
}

View file

@ -1,17 +0,0 @@
// { "preopens": { "/fixture": "fixture" } }
fn main() {
assert_eq!(std::fs::read("/fixture/file").unwrap(), b"file\n");
assert_eq!(
std::fs::read("/fixture/symlink_to_file").unwrap(),
b"file\n"
);
assert_eq!(
std::fs::read("/fixture/directory/file").unwrap(),
b"directory/file\n"
);
assert_eq!(
std::fs::read("/fixture/directory/symlink_to_file").unwrap(),
b"directory/file\n"
);
}

View file

@ -1,9 +0,0 @@
// { "preopens": { "/fixture": "fixture" } }
fn main() {
let entries = std::fs::read_dir("/fixture").unwrap();
assert_eq!(entries.count(), 4);
let entries = std::fs::read_dir("/fixture/directory").unwrap();
assert_eq!(entries.count(), 2);
}

View file

@ -1,11 +0,0 @@
// { "preopens": { "/scratch": "scratch" } }
fn main() {
let old_path = "/scratch/old_file";
let new_path = "/scratch/new_file";
assert!(std::fs::write(old_path, b"Hello, world!").is_ok());
assert!(std::fs::rename(old_path, new_path).is_ok());
assert!(std::fs::read(old_path).is_err());
assert_eq!(std::fs::read(new_path).unwrap(), b"Hello, world!");
}

View file

@ -1,23 +0,0 @@
// { "preopens": { "/fixture": "fixture" } }
fn main() {
let metadata = std::fs::symlink_metadata("/fixture/directory").unwrap();
assert!(metadata.file_type().is_dir());
let metadata =
std::fs::symlink_metadata("/fixture/symlink_to_directory").unwrap();
assert!(metadata.file_type().is_symlink());
let metadata = std::fs::symlink_metadata("/fixture/file").unwrap();
assert!(metadata.file_type().is_file());
let metadata = std::fs::symlink_metadata("/fixture/symlink_to_file").unwrap();
assert!(metadata.file_type().is_symlink());
let metadata = std::fs::symlink_metadata("/fixture/directory/file").unwrap();
assert!(metadata.file_type().is_file());
let metadata =
std::fs::symlink_metadata("/fixture/directory/symlink_to_file").unwrap();
assert!(metadata.file_type().is_symlink());
}

View file

@ -1,5 +0,0 @@
// { "preopens": { "/scratch": "scratch" }, "files": { "scratch/file": "file" } }
fn main() {
assert!(std::fs::write("/scratch/file", b"file").is_ok())
}

View file

@ -1,7 +0,0 @@
// { "stderr": "Hello, stderr!" }
use std::io::Write;
fn main() {
assert!(std::io::stderr().write_all(b"Hello, stderr!").is_ok())
}

View file

@ -1,9 +0,0 @@
// { "stdin": "Hello, stdin!" }
use std::io::Read;
fn main() {
let mut buffer = String::new();
assert!(std::io::stdin().read_to_string(&mut buffer).is_ok());
assert_eq!(buffer, "Hello, stdin!")
}

View file

@ -1,7 +0,0 @@
// { "stdout": "Hello, stdout!" }
use std::io::Write;
fn main() {
assert!(std::io::stdout().write_all(b"Hello, stdout!").is_ok())
}

View file

@ -1,5 +0,0 @@
// { "exitCode": "120" }
fn main() {
std::process::exit(120);
}