Browse Source

Fix merge conflict and cleanup extraneous code

pull/9/head
Ian Chamberlain 1 year ago
parent
commit
6322b80c58
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 4
      run-tests/Dockerfile
  2. 10
      test-runner/src/console.rs
  3. 7
      test-runner/src/gdb.rs
  4. 57
      test-runner/src/lib.rs

4
run-tests/Dockerfile

@ -8,11 +8,7 @@ ARG CITRA_CHANNEL=nightly
ARG CITRA_RELEASE=1995 ARG CITRA_RELEASE=1995
RUN download_citra ${CITRA_CHANNEL} ${CITRA_RELEASE} RUN download_citra ${CITRA_CHANNEL} ${CITRA_RELEASE}
<<<<<<< Updated upstream:run-tests/Dockerfile
FROM devkitpro/devkitarm:latest as devkitarm FROM devkitpro/devkitarm:latest as devkitarm
=======
FROM devkitpro/devkitarm as devkitarm
>>>>>>> Stashed changes:Dockerfile
# For some reason, citra isn't always happy when you try to run it for the first time, # For some reason, citra isn't always happy when you try to run it for the first time,
# so we build a simple dummy program to force it to create its directory structure # so we build a simple dummy program to force it to create its directory structure

10
test-runner/src/console.rs

@ -1,8 +1,9 @@
use std::process::Termination;
use ctru::prelude::*; use ctru::prelude::*;
use ctru::services::gfx::{Flush, Swap}; use ctru::services::gfx::{Flush, Swap};
use super::TestRunner; use super::TestRunner;
use crate::TestResult;
pub struct ConsoleRunner { pub struct ConsoleRunner {
gfx: Gfx, gfx: Gfx,
@ -29,11 +30,10 @@ impl TestRunner for ConsoleRunner {
Console::new(self.gfx.top_screen.borrow_mut()) Console::new(self.gfx.top_screen.borrow_mut())
} }
fn cleanup<T: TestResult>(mut self, result: T) -> T { fn cleanup<T: Termination>(mut self, result: T) -> T {
// We don't actually care about the test result, either way we'll stop // We don't actually care about the output of the test result, either
// and show the results to the user // way we'll stop and show the results to the user.
// Wait to make sure the user can actually see the results before we exit
println!("Press START to exit."); println!("Press START to exit.");
while self.apt.main_loop() { while self.apt.main_loop() {

7
test-runner/src/gdb.rs

@ -1,7 +1,8 @@
use std::process::Termination;
use ctru::error::ResultCode; use ctru::error::ResultCode;
use super::TestRunner; use super::TestRunner;
use crate::TestResult;
#[derive(Default)] #[derive(Default)]
pub struct GdbRunner; pub struct GdbRunner;
@ -28,10 +29,10 @@ impl TestRunner for GdbRunner {
.expect("failed to redirect I/O streams to GDB"); .expect("failed to redirect I/O streams to GDB");
} }
fn cleanup<T: TestResult>(self, test_result: T) -> T { fn cleanup<T: Termination>(self, test_result: T) -> T {
// GDB actually has the opportunity to inspect the exit code, // GDB actually has the opportunity to inspect the exit code,
// unlike other runners, so let's follow the default behavior of the // unlike other runners, so let's follow the default behavior of the
// stdlib test runner. // stdlib test runner.
std::process::exit(if test_result.succeeded() { 0 } else { 101 }) test_result.report().exit_process()
} }
} }

57
test-runner/src/lib.rs

@ -15,9 +15,7 @@ mod console;
mod gdb; mod gdb;
mod socket; mod socket;
use std::any::Any; use std::process::{ExitCode, Termination};
use std::error::Error;
use std::fmt::Display;
pub use console::ConsoleRunner; pub use console::ConsoleRunner;
pub use gdb::GdbRunner; pub use gdb::GdbRunner;
@ -126,17 +124,6 @@ macro_rules! doctest {
}; };
} }
#[derive(Debug)]
struct TestsFailed;
impl Display for TestsFailed {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "some tests failed!")
}
}
impl Error for TestsFailed {}
fn run<Runner: TestRunner>(tests: &[&TestDescAndFn]) { fn run<Runner: TestRunner>(tests: &[&TestDescAndFn]) {
std::env::set_var("RUST_BACKTRACE", "1"); std::env::set_var("RUST_BACKTRACE", "1");
@ -162,7 +149,13 @@ fn run<Runner: TestRunner>(tests: &[&TestDescAndFn]) {
drop(ctx); drop(ctx);
let _ = runner.cleanup(result); let reportable_result = match result {
Ok(true) => Ok(()),
// Try to match stdlib console test runner behavior as best we can
_ => Err(ExitCode::from(101)),
};
let _ = runner.cleanup(reportable_result);
} }
/// Adapted from [`test::make_owned_test`]. /// Adapted from [`test::make_owned_test`].
@ -189,9 +182,6 @@ mod private {
impl Sealed for super::ConsoleRunner {} impl Sealed for super::ConsoleRunner {}
impl Sealed for super::GdbRunner {} impl Sealed for super::GdbRunner {}
impl Sealed for super::SocketRunner {} impl Sealed for super::SocketRunner {}
impl Sealed for () {}
impl<T, E> Sealed for Result<T, E> {}
} }
/// A helper trait to make the behavior of test runners consistent. /// A helper trait to make the behavior of test runners consistent.
@ -209,38 +199,13 @@ pub trait TestRunner: private::Sealed + Sized + Default {
/// Handle the results of the test and perform any necessary cleanup. /// Handle the results of the test and perform any necessary cleanup.
/// The [`Context`](Self::Context) will be dropped just before this is called. /// The [`Context`](Self::Context) will be dropped just before this is called.
fn cleanup<T: TestResult>(self, test_result: T) -> T { ///
/// This returns `T` so that the result can be used in doctests.
fn cleanup<T: Termination>(self, test_result: T) -> T {
test_result test_result
} }
} }
// A helper trait to determine whether tests succeeded. This trait is implemented
// for
pub trait TestResult: private::Sealed {
fn succeeded(&self) -> bool;
}
impl TestResult for () {
fn succeeded(&self) -> bool {
true
}
}
impl<T: Any, E> TestResult for Result<T, E> {
fn succeeded(&self) -> bool {
// This is sort of a hack workaround for lack of specialized trait impls.
// Basically, check if T is a boolean and use it if so. Otherwise default
// to mapping Ok to success and Err to failure.
match self
.as_ref()
.map(|val| (val as &dyn Any).downcast_ref::<bool>())
{
Ok(Some(&result)) => result,
other => other.is_ok(),
}
}
}
/// This module has stubs needed to link the test library, but they do nothing /// This module has stubs needed to link the test library, but they do nothing
/// because we don't actually need them for the runner to work. /// because we don't actually need them for the runner to work.
mod link_fix { mod link_fix {

Loading…
Cancel
Save