Add basic testsuite using ui_test

This commit is contained in:
nora 2023-08-01 11:57:44 +02:00
parent 1551847d8c
commit b68d775671
13 changed files with 1524 additions and 79 deletions

1
tests/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1224
tests/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

9
tests/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "tests"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ui_test = "0.12.1"

View file

@ -0,0 +1,35 @@
fn main() {
let mut args = std::env::args().skip(1).collect::<Vec<_>>();
let mut after_edition = false;
args.retain(|arg| {
// drop some stuff we dont care about
if arg.starts_with("--crate-type") {
return false;
}
if arg == "--edition" {
after_edition = true;
return false;
}
if after_edition {
after_edition = false;
return false;
}
true
});
// We don't want out.wat polluting things.
args.push("--no-output".into());
let result = std::process::Command::new("node")
.arg(".")
.args(args)
.spawn()
.unwrap()
.wait()
.unwrap();
let code = result.code().unwrap_or(1);
std::process::exit(code);
}

54
tests/src/main.rs Normal file
View file

@ -0,0 +1,54 @@
use ui_test::{
clap::Parser, default_filter_by_arg, default_per_file_config, status_emitter, Args,
CommandBuilder, Config, Mode, OutputConflictHandling,
};
fn main() {
std::process::Command::new("cargo")
.args(&[
"build",
"--manifest-path",
"tests/Cargo.toml",
"--bin",
"nilc-wrapper",
])
.spawn()
.unwrap()
.wait()
.unwrap()
.success()
.then_some(())
.unwrap_or_else(|| std::process::exit(1));
let mut config = Config::rustc("tests/ui");
config.host = Some("wasm :3".into());
config.program = CommandBuilder::cmd("tests/target/debug/nilc-wrapper");
config.mode = Mode::Fail {
require_patterns: false,
};
let args = Args::parse();
let text = if args.quiet {
status_emitter::Text::quiet()
} else {
status_emitter::Text::verbose()
};
if !args.check && std::env::var_os("GITHUB_ACTIONS").is_none() {
config.output_conflict_handling = OutputConflictHandling::Bless;
}
let result = ui_test::run_tests_generic(
config,
args,
|path, args| {
path.extension().is_some_and(|ext| ext == "nil") && default_filter_by_arg(path, args)
},
default_per_file_config,
(text, status_emitter::Gha::<true> { name: "ui".into() }),
);
if let Err(result) = result {
println!("{:?}", result);
}
}

View file

@ -0,0 +1,19 @@
//@check-pass
function main() = (
noArgs();
singleArg("hi!");
manyArgs(1,2,3,4,5,6);
let a: () = returnNothing();
let b: () = returnExplicitUnit();
let c: String = returnString();
);
function noArgs() =;
function singleArg(a: String) =;
function manyArgs(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) =;
function returnNothing() =;
function returnExplicitUnit(): () =;
function returnString(): String = "uwu";

2
tests/ui/hello_world.nil Normal file
View file

@ -0,0 +1,2 @@
//@check-pass
function main() = print("Hello, world!\n");

View file

@ -0,0 +1,21 @@
//@check-pass
type CustomType = {};
function main() = ();
function assigns(
a: Int,
b: I32,
c: String,
d: Bool,
e: CustomType,
f: (Int, I32),
) = (
let a1: Int = a;
let b1: I32 = b;
let c1: String = c;
let d1: Bool = d;
let e1: CustomType = e;
let f1: (Int, I32) = f;
);