Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Sep 8, 2024
1 parent b1fb37f commit cc4324c
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 11 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Install
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Test VM
uses: actions-rs/cargo@v1
with:
command: test
args: --manifest-path crates/dash_vm/Cargo.toml # no --all-features because jit
run: cargo t -p dash_vm # no --all-features because jit

- name: Test lints
run: cargo t -p lints

- name: Lints
run: ./lints.sh

- name: Benchmark VM
run: eval $(cargo test --release --benches -p dash_vm |& grep -o -P 'target/release/deps/full-[^\)]+') --bench --output-format bencher | tee output.txt

- name: Store output
if: github.ref == 'refs/heads/master'
uses: benchmark-action/[email protected]
Expand Down
4 changes: 4 additions & 0 deletions lints.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

cargo b -p lints
RUSTC_WRAPPER="./target/debug/lints" cargo c -p dash-cli --all-features
7 changes: 7 additions & 0 deletions lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@ edition = "2021"
[dependencies]
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "7d7b298" }

[dev-dependencies]
prettydiff = "0.7.0"

[[test]]
name = "uitest"
harness = false

[package.metadata.rust-analyzer]
rustc_private = true
10 changes: 10 additions & 0 deletions lints/tests/ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "ui"
version = "0.1.0"
edition = "2021"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(dash_lints)'] }

[dependencies]
dash_vm = { path = "../../../crates/dash_vm" }
69 changes: 69 additions & 0 deletions lints/tests/ui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#![cfg_attr(dash_lints, feature(register_tool))]
#![cfg_attr(dash_lints, register_tool(dash_lints))]
#![allow(path_statements, dead_code, clippy::no_effect)]

use dash_vm::localscope::LocalScope;
use dash_vm::value::Unrooted;
use dash_vm::Vm;

fn make_unrooted() -> Unrooted {
todo!()
}
fn make_unrooted_res(_: &mut LocalScope<'_>) -> Result<Unrooted, Unrooted> {
todo!()
}
fn transform_unrooted(_: &mut LocalScope<'_>, _: Unrooted) -> Unrooted {
todo!()
}
fn use_vm(_: &mut Vm) {}
fn use_scope(_: &mut LocalScope<'_>) {}
#[cfg_attr(dash_lints, dash_lints::trusted_no_gc)]
fn use_scope_ok(_: &mut LocalScope<'_>) {}

fn with_vm(vm: &mut Vm, unrooted: Unrooted) {
use_vm(vm);
unrooted; // killed
}

fn with_scope(scope: &mut LocalScope<'_>, unrooted: Unrooted) {
use_scope(scope);
unrooted; // killed
}

fn kill_after_fn(scope: &mut LocalScope, u1: Unrooted, u2: Unrooted) {
let v = transform_unrooted(scope, u1);
u2; // killed
v; // live
}

fn controlflow(scope: &mut LocalScope, cond: u8, u1: Unrooted) {
match cond {
0 => {
use_scope(scope);
}
1 => {
std::hint::black_box(());
}
_ => {
std::hint::black_box(());
}
} // join = use

u1; // killed
}

fn try_err(scope: &mut LocalScope<'_>) -> Result<(), Unrooted> {
let u1 = make_unrooted_res(scope)?;
let x = &u1;

let u2 = make_unrooted_res(scope)?;
x; // killed;
u1; // killed
u2;
Ok(())
}

fn attribute_works(scope: &mut LocalScope<'_>, unrooted: Unrooted) {
use_scope_ok(scope);
unrooted;
}
74 changes: 74 additions & 0 deletions lints/tests/ui/ui.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
error: use of unrooted value after mutable scope borrow
--> lints/tests/ui/src/lib.rs:25:5
|
25 | unrooted; // killed
| ^^^^^^^^
|
note: scope mutably borrowed here
--> lints/tests/ui/src/lib.rs:24:5
|
24 | use_vm(vm);
| ^^^^^^^^^^
= note: `#[deny(missing_root)]` on by default

error: use of unrooted value after mutable scope borrow
--> lints/tests/ui/src/lib.rs:30:5
|
30 | unrooted; // killed
| ^^^^^^^^
|
note: scope mutably borrowed here
--> lints/tests/ui/src/lib.rs:29:5
|
29 | use_scope(scope);
| ^^^^^^^^^^^^^^^^

error: use of unrooted value after mutable scope borrow
--> lints/tests/ui/src/lib.rs:35:5
|
35 | u2; // killed
| ^^
|
note: scope mutably borrowed here
--> lints/tests/ui/src/lib.rs:34:13
|
34 | let v = transform_unrooted(scope, u1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: use of unrooted value after mutable scope borrow
--> lints/tests/ui/src/lib.rs:52:5
|
52 | u1; // killed
| ^^
|
note: scope mutably borrowed here
--> lints/tests/ui/src/lib.rs:42:13
|
42 | use_scope(scope);
| ^^^^^^^^^^^^^^^^

error: use of unrooted value after mutable scope borrow
--> lints/tests/ui/src/lib.rs:60:5
|
60 | x; // killed;
| ^
|
note: scope mutably borrowed here
--> lints/tests/ui/src/lib.rs:59:14
|
59 | let u2 = make_unrooted_res(scope)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: use of unrooted value after mutable scope borrow
--> lints/tests/ui/src/lib.rs:61:5
|
61 | u1; // killed
| ^^
|
note: scope mutably borrowed here
--> lints/tests/ui/src/lib.rs:59:14
|
59 | let u2 = make_unrooted_res(scope)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `ui` (lib) due to 6 previous errors
34 changes: 34 additions & 0 deletions lints/tests/uitest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::error::Error;
use std::process::Command;
use std::{env, fs, io};

fn main() -> Result<(), Box<dyn Error>> {
let command = Command::new("cargo")
.current_dir("tests/ui")
.arg("-q")
.arg("c")
.env("RUSTC_WRAPPER", "../../../target/debug/lints")
.output()?;

assert_eq!(command.stdout, b"");
let now = std::str::from_utf8(&command.stderr).expect("cargo c never emits invalid utf8");
match fs::read_to_string("tests/ui/ui.stderr") {
Ok(before) => {
if before != now {
if env::args().any(|arg| arg == "--bless") {
fs::write("tests/ui/ui.stderr", now)?;
} else {
let diff = prettydiff::diff_lines(&before, now);
println!("{diff}");
return Err("stderr has changed! rerun with --bless to update".into());
}
}
}
Err(err) if err.kind() == io::ErrorKind::NotFound => {
fs::write("tests/ui/ui.stderr", now)?;
}
Err(err) => return Err(err.into()),
}

Ok(())
}
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-09-05"
components = ["clippy"]
components = ["clippy", "rust-src", "rustc-dev", "llvm-tools-preview"]

0 comments on commit cc4324c

Please sign in to comment.