Skip to content

Commit

Permalink
Fix tests after nightly breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
celinval committed Oct 10, 2023
1 parent f0f892f commit a28a6b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
-->
![project group status: active](https://img.shields.io/badge/status-active-brightgreen.svg)
[![project group documentation](https://img.shields.io/badge/MDBook-View%20Documentation-blue)][gh-pages]
[![Run compiler tests](https://github.com/rust-lang/project-stable-mir/actions/workflows/nightly.yml/badge.svg)](https://github.com/rust-lang/project-stable-mir/actions/workflows/nightly.yml)


<!--
Expand Down Expand Up @@ -47,4 +48,3 @@ yourself over there and ask us any questions you have.
[open issues]: https://github.com/rust-lang/project-stable-mir/issues
[chat-link]: https://rust-lang.zulipchat.com/#narrow/stream/320896-project-stable-mir
[team-toml]: https://github.com/rust-lang/team/blob/master/teams/project-stable-mir.toml

3 changes: 2 additions & 1 deletion tools/test-drive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ mod sanity_checks;

extern crate rustc_middle;
extern crate rustc_smir;
extern crate stable_mir;

use rustc_middle::ty::TyCtxt;
use rustc_smir::rustc_internal;
use rustc_smir::stable_mir::CompilerError;
use stable_mir::CompilerError;
use std::ops::ControlFlow;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::process::ExitCode;
Expand Down
26 changes: 12 additions & 14 deletions tools/test-drive/src/sanity_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! These checks should only depend on StableMIR APIs. See other modules for tests that compare
//! the result between StableMIR and internal APIs.
use crate::TestResult;
use rustc_smir::stable_mir;
use stable_mir;
use std::fmt::Debug;
use std::hint::black_box;

Expand Down Expand Up @@ -83,34 +83,32 @@ pub fn test_traits() -> TestResult {

pub fn test_crates() -> TestResult {
for krate in stable_mir::external_crates() {
check_equal(
stable_mir::find_crate(&krate.name.as_str()),
Some(krate),
"external crate mismatch",
check(
stable_mir::find_crates(&krate.name.as_str()).contains(&krate),
format!("Cannot find {krate:?}"),
)?;
}

let local = stable_mir::local_crate();
check_equal(
stable_mir::find_crate(&local.name.as_str()),
Some(local),
"local crate mismatch",
check(
stable_mir::find_crates(&local.name.as_str()).contains(&local),
format!("Cannot find {local:?}"),
)
}

/// Visit all local types, statements and terminator to ensure nothing crashes.
fn check_body(body: stable_mir::mir::Body) {
for bb in body.blocks {
for stmt in bb.statements {
black_box(matches!(stmt, stable_mir::mir::Statement::Assign(..)));
for stable_mir::mir::Statement { kind, .. } in bb.statements {
black_box(matches!(kind, stable_mir::mir::StatementKind::Assign(..)));
}
black_box(matches!(
bb.terminator,
stable_mir::mir::Terminator::Goto { .. }
bb.terminator.kind,
stable_mir::mir::TerminatorKind::Goto { .. }
));
}

for local in body.locals {
black_box(matches!(local.kind(), stable_mir::ty::TyKind::Alias(..)));
black_box(matches!(local.ty.kind(), stable_mir::ty::TyKind::Alias(..)));
}
}

0 comments on commit a28a6b0

Please sign in to comment.