66
77#![ feature( test) ]
88#![ feature( custom_test_frameworks) ]
9+ #![ feature( exitcode_exit_method) ]
910#![ test_runner( run_gdb) ]
1011
1112extern crate test;
1213
1314mod console;
1415mod gdb;
16+ mod macros;
1517mod socket;
1618
17- use console:: ConsoleRunner ;
18- use gdb:: GdbRunner ;
19- use socket:: SocketRunner ;
19+ use std:: process:: { ExitCode , Termination } ;
2020
21+ pub use console:: ConsoleRunner ;
22+ pub use gdb:: GdbRunner ;
23+ pub use socket:: SocketRunner ;
2124use test:: { ColorConfig , OutputFormat , TestDescAndFn , TestFn , TestOpts } ;
2225
2326/// Show test output in GDB, using the [File I/O Protocol] (called HIO in some 3DS
2427/// homebrew resources). Both stdout and stderr will be printed to the GDB console.
2528///
2629/// [File I/O Protocol]: https://sourceware.org/gdb/onlinedocs/gdb/File_002dI_002fO-Overview.html#File_002dI_002fO-Overview
2730pub fn run_gdb ( tests : & [ & TestDescAndFn ] ) {
28- run :: < GdbRunner > ( tests)
31+ run :: < GdbRunner > ( tests) ;
2932}
3033
3134/// Run tests using the `ctru` [`Console`] (print results to the 3DS screen).
3235/// This is mostly useful for running tests manually, especially on real hardware.
3336///
3437/// [`Console`]: ctru::console::Console
3538pub fn run_console ( tests : & [ & TestDescAndFn ] ) {
36- run :: < ConsoleRunner > ( tests)
39+ run :: < ConsoleRunner > ( tests) ;
3740}
3841
3942/// Show test output via a network socket to `3dslink`. This runner is only useful
@@ -43,7 +46,7 @@ pub fn run_console(tests: &[&TestDescAndFn]) {
4346///
4447/// [`Soc::redirect_to_3dslink`]: ctru::services::soc::Soc::redirect_to_3dslink
4548pub fn run_socket ( tests : & [ & TestDescAndFn ] ) {
46- run :: < SocketRunner > ( tests)
49+ run :: < SocketRunner > ( tests) ;
4750}
4851
4952fn run < Runner : TestRunner > ( tests : & [ & TestDescAndFn ] ) {
@@ -71,7 +74,13 @@ fn run<Runner: TestRunner>(tests: &[&TestDescAndFn]) {
7174
7275 drop ( ctx) ;
7376
74- runner. cleanup ( result) ;
77+ let reportable_result = match result {
78+ Ok ( true ) => Ok ( ( ) ) ,
79+ // Try to match stdlib console test runner behavior as best we can
80+ _ => Err ( ExitCode :: from ( 101 ) ) ,
81+ } ;
82+
83+ let _ = runner. cleanup ( reportable_result) ;
7584}
7685
7786/// Adapted from [`test::make_owned_test`].
@@ -92,8 +101,16 @@ fn make_owned_test(test: &TestDescAndFn) -> TestDescAndFn {
92101 }
93102}
94103
104+ mod private {
105+ pub trait Sealed { }
106+
107+ impl Sealed for super :: ConsoleRunner { }
108+ impl Sealed for super :: GdbRunner { }
109+ impl Sealed for super :: SocketRunner { }
110+ }
111+
95112/// A helper trait to make the behavior of test runners consistent.
96- trait TestRunner : Sized + Default {
113+ pub trait TestRunner : private :: Sealed + Sized + Default {
97114 /// Any context the test runner needs to remain alive for the duration of
98115 /// the test. This can be used for things that need to borrow the test runner
99116 /// itself.
@@ -107,7 +124,11 @@ trait TestRunner: Sized + Default {
107124
108125 /// Handle the results of the test and perform any necessary cleanup.
109126 /// The [`Context`](Self::Context) will be dropped just before this is called.
110- fn cleanup ( self , test_result : std:: io:: Result < bool > ) ;
127+ ///
128+ /// This returns `T` so that the result can be used in doctests.
129+ fn cleanup < T : Termination > ( self , test_result : T ) -> T {
130+ test_result
131+ }
111132}
112133
113134/// This module has stubs needed to link the test library, but they do nothing
@@ -132,17 +153,6 @@ mod link_fix {
132153 }
133154}
134155
135- /// Verify that doctests work as expected
136- /// ```
137- /// assert_eq!(2 + 2, 4);
138- /// ```
139- ///
140- /// ```should_panic
141- /// assert_eq!(2 + 2, 5);
142- /// ```
143- #[ cfg( doctest) ]
144- struct Dummy ;
145-
146156#[ cfg( test) ]
147157mod tests {
148158 #[ test]
0 commit comments