Skip to content

Commit c4086d8

Browse files
committed
simulator: print simulator msgs only in simulator, not in unit tests
The `c-unit-testing` is also active in Rust unit tests, so the simulator msgs were printed there. This commit moves the stdout prints to `ui_stub_c_unit_tests.rs`, which is only used in the simulator.
1 parent 8ff20de commit c4086d8

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

src/rust/bitbox02-rust/src/workflow/confirm.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,5 @@ pub async fn confirm(params: &Params<'_>) -> Result<(), UserAbort> {
3131
};
3232
});
3333
component.screen_stack_push();
34-
#[cfg(feature = "c-unit-testing")]
35-
bitbox02::print_stdout(&format!("CONFIRM SCREEN START\nTITLE: {}\nBODY: {}\nCONFIRM SCREEN END\n", params.title, params.body));
3634
option_no_screensaver(&result).await
3735
}

src/rust/bitbox02-rust/src/workflow/status.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,5 @@ pub async fn status(title: &str, status_success: bool) {
2121
*result.borrow_mut() = Some(());
2222
});
2323
component.screen_stack_push();
24-
#[cfg(feature = "c-unit-testing")]
25-
bitbox02::print_stdout(&format!("STATUS SCREEN START\nTITLE: {}\nSTATUS SCREEN END\n", title));
2624
option_no_screensaver(&result).await
2725
}

src/rust/bitbox02-rust/src/workflow/trinary_input_string.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ pub async fn enter(
4949
bitbox02::ui::trinary_input_string_set_input(&mut component, preset);
5050
}
5151
component.screen_stack_push();
52-
#[cfg(feature = "c-unit-testing")]
53-
bitbox02::print_stdout(&format!("ENTER SCREEN START\nTITLE: {}\nENTER SCREEN END\n", params.title));
5452
option(&result)
5553
.await
5654
.or(Err(super::cancel::Error::Cancelled))

src/rust/bitbox02/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020
#[macro_use]
2121
extern crate std;
2222

23+
// allow unused as we use format!() only in some build configs (for
24+
// the simulator), but replicating the conditions under which it is
25+
// used here is not worth it.
26+
#[allow(unused_imports)]
27+
// for `format!`
28+
#[macro_use]
2329
extern crate alloc;
30+
2431
use alloc::string::String;
2532

2633
#[cfg(feature = "testing")]

src/rust/bitbox02/src/ui.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
mod types;
1717

1818
#[cfg_attr(feature = "testing", path = "ui/ui_stub.rs")]
19-
#[cfg_attr(not(feature = "testing"), cfg_attr(feature = "c-unit-testing", path = "ui/ui_stub_c_unit_tests.rs"))]
19+
#[cfg_attr(
20+
not(feature = "testing"),
21+
cfg_attr(feature = "c-unit-testing", path = "ui/ui_stub_c_unit_tests.rs")
22+
)]
2023
// We don't actually use ui::ui anywhere, we re-export below.
2124
#[allow(clippy::module_inception)]
2225
mod ui;

src/rust/bitbox02/src/ui/ui_stub_c_unit_tests.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,34 @@ impl<'a> Drop for Component<'a> {
4848
}
4949

5050
pub fn trinary_input_string_create<'a, F>(
51-
_params: &TrinaryInputStringParams,
51+
params: &TrinaryInputStringParams,
5252
mut confirm_callback: F,
5353
_cancel_callback: Option<ContinueCancelCb<'a>>,
5454
) -> Component<'a>
5555
where
5656
F: FnMut(SafeInputString) + 'a,
5757
{
58+
crate::print_stdout(&format!(
59+
"ENTER SCREEN START\nTITLE: {}\nENTER SCREEN END\n",
60+
params.title
61+
));
62+
5863
confirm_callback(SafeInputString::new());
5964
Component {
6065
is_pushed: false,
6166
_p: PhantomData,
6267
}
6368
}
6469

65-
pub fn confirm_create<'a, F>(_params: &ConfirmParams, mut result_callback: F) -> Component<'a>
70+
pub fn confirm_create<'a, F>(params: &ConfirmParams, mut result_callback: F) -> Component<'a>
6671
where
6772
F: FnMut(bool) + 'a,
6873
{
74+
crate::print_stdout(&format!(
75+
"CONFIRM SCREEN START\nTITLE: {}\nBODY: {}\nCONFIRM SCREEN END\n",
76+
params.title, params.body
77+
));
78+
6979
result_callback(true);
7080
Component {
7181
is_pushed: false,
@@ -75,10 +85,14 @@ where
7585

7686
pub fn screen_process() {}
7787

78-
pub fn status_create<'a, F>(_text: &str, _status_success: bool, mut callback: F) -> Component<'a>
88+
pub fn status_create<'a, F>(text: &str, _status_success: bool, mut callback: F) -> Component<'a>
7989
where
8090
F: FnMut() + 'a,
8191
{
92+
crate::print_stdout(&format!(
93+
"STATUS SCREEN START\nTITLE: {}\nSTATUS SCREEN END\n",
94+
text,
95+
));
8296
callback();
8397
Component {
8498
is_pushed: false,
@@ -160,4 +174,4 @@ pub fn empty_create<'a>() -> Component<'a> {
160174
is_pushed: false,
161175
_p: PhantomData,
162176
}
163-
}
177+
}

0 commit comments

Comments
 (0)