Skip to content

Commit 7726a1e

Browse files
AndrewAltimitAI Agent BotclaudeAI Review Agent
authored
chore(hygiene): tighten test panics, error context, PSP USB lint policy (#165)
* chore(hygiene): tighten test panics, propagate error context, lint policy for PSP USB crates Three small, behavior-preserving cleanups picked up from the pre-launch backlog: * Replace the `assert!(matches!(...))` + `let-else { unreachable!() }` test pattern with a single `let-else { panic!("expected ...", x) }`. The let-else already panics on mismatch, so the leading assert is redundant. Drops ~116 `unreachable!()` calls in non-target source (165 → 49) and shortens 30 test files. The `assert_text!` macro in oasis-terminal/src/test_helpers.rs already follows this shape; doc comment updated to match. * Two test panic!() callers were discarding the underlying error: the text-editor SDI lookup and the radio source poll error case. Capture `e` so test failures print what actually went wrong. * The four standalone PSP USB crates (`oasis-usb-vbus-psp`, `oasis-usb-client-psp`, `oasis-usb-debug-psp`, `oasis-usb-trace-psp`) declare their own `[workspace]`, so they inherit none of the parent's clippy policy. Add a `[lints]` section to each mirroring the workspace policy (`undocumented_unsafe_blocks`, `unsafe_op_in_unsafe_fn`, etc. — all `warn` to track the parent), so unsafe-block discipline starts surfacing on those builds too. Verified locally: `cargo build --workspace --tests`, `cargo test --workspace`, `cargo clippy --workspace -- -D warnings`, `cargo fmt --all -- --check` all pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix: address AI review feedback (iteration 1) Automated fix by Claude in response to AI review feedback. Iteration: 1/5 Co-Authored-By: AI Review Agent <noreply@anthropic.com> --------- Co-authored-by: AI Agent Bot <ai-agent@localhost> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: AI Review Agent <ai-review-agent@localhost>
1 parent 13a140f commit 7726a1e

31 files changed

Lines changed: 178 additions & 614 deletions

File tree

crates/oasis-app-text-editor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ mod tests {
569569
] {
570570
let obj = sdi
571571
.get(name)
572-
.unwrap_or_else(|_| panic!("{name} should exist after update_sdi"));
572+
.unwrap_or_else(|e| panic!("{name} should exist after update_sdi: {e:?}"));
573573
assert!(obj.visible, "{name} should be visible");
574574
}
575575
// Menu labels present.

crates/oasis-audio/src/radio/source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ mod tests {
10251025
break;
10261026
}
10271027
},
1028-
Err(_) => panic!("unexpected error"),
1028+
Err(e) => panic!("unexpected error: {e:?}"),
10291029
}
10301030
}
10311031
assert_eq!(total, 100);

crates/oasis-browser/src/css/cascade/tests.rs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -713,12 +713,8 @@ fn only_child_pseudo_class() {
713713
// Single child.
714714
let doc = make_doc(vec![(TagName::P, vec![])]);
715715
let __out = &doc.nodes[3].kind;
716-
assert!(
717-
matches!(&__out, NodeKind::Element(_)),
718-
"expected NodeKind::Element, got {__out:?}"
719-
);
720716
let NodeKind::Element(e) = __out else {
721-
unreachable!()
717+
panic!("expected NodeKind::Element, got {__out:?}");
722718
};
723719
assert!(matching::match_pseudo_class(
724720
&doc,
@@ -731,12 +727,8 @@ fn only_child_pseudo_class() {
731727
// Multiple children.
732728
let doc2 = make_doc(vec![(TagName::P, vec![]), (TagName::Div, vec![])]);
733729
let __out = &doc2.nodes[3].kind;
734-
assert!(
735-
matches!(&__out, NodeKind::Element(_)),
736-
"expected NodeKind::Element, got {__out:?}"
737-
);
738730
let NodeKind::Element(e2) = __out else {
739-
unreachable!()
731+
panic!("expected NodeKind::Element, got {__out:?}");
740732
};
741733
assert!(!matching::match_pseudo_class(
742734
&doc2,
@@ -828,12 +820,8 @@ fn hover_matches_hovered_node() {
828820
global_layers: None,
829821
};
830822
let __out = &doc.nodes[3].kind;
831-
assert!(
832-
matches!(&__out, NodeKind::Element(_)),
833-
"expected NodeKind::Element, got {__out:?}"
834-
);
835823
let NodeKind::Element(elem) = __out else {
836-
unreachable!()
824+
panic!("expected NodeKind::Element, got {__out:?}");
837825
};
838826
assert!(matching::match_pseudo_class(&doc, 3, elem, "hover", &hctx));
839827
assert!(!matching::match_pseudo_class(
@@ -870,12 +858,8 @@ fn hover_matches_ancestor_of_hovered_node() {
870858
};
871859
// <div> (ancestor) should also match :hover.
872860
let __out = &doc.nodes[3].kind;
873-
assert!(
874-
matches!(&__out, NodeKind::Element(_)),
875-
"expected NodeKind::Element, got {__out:?}"
876-
);
877861
let NodeKind::Element(div_elem) = __out else {
878-
unreachable!()
862+
panic!("expected NodeKind::Element, got {__out:?}");
879863
};
880864
assert!(matching::match_pseudo_class(
881865
&doc, 3, div_elem, "hover", &hctx
@@ -902,12 +886,8 @@ fn visited_matches_with_visited_url() {
902886
global_layers: None,
903887
};
904888
let __out = &doc.nodes[3].kind;
905-
assert!(
906-
matches!(&__out, NodeKind::Element(_)),
907-
"expected NodeKind::Element, got {__out:?}"
908-
);
909889
let NodeKind::Element(elem) = __out else {
910-
unreachable!()
890+
panic!("expected NodeKind::Element, got {__out:?}");
911891
};
912892
assert!(matching::match_pseudo_class(
913893
&doc, 3, elem, "visited", &vctx
@@ -934,12 +914,8 @@ fn link_matches_unvisited_anchor() {
934914
global_layers: None,
935915
};
936916
let __out = &doc.nodes[3].kind;
937-
assert!(
938-
matches!(&__out, NodeKind::Element(_)),
939-
"expected NodeKind::Element, got {__out:?}"
940-
);
941917
let NodeKind::Element(elem) = __out else {
942-
unreachable!()
918+
panic!("expected NodeKind::Element, got {__out:?}");
943919
};
944920
assert!(matching::match_pseudo_class(&doc, 3, elem, "link", &vctx));
945921
assert!(!matching::match_pseudo_class(

crates/oasis-browser/src/forms/manager.rs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -489,23 +489,15 @@ mod tests {
489489
mgr.toggle_checkbox(0, "remember");
490490
// Check the internal state directly.
491491
let __out = &mgr.forms[0].elements[2];
492-
assert!(
493-
matches!(&__out, FormElement::Checkbox { .. }),
494-
"expected FormElement::Checkbox, got {__out:?}"
495-
);
496492
let FormElement::Checkbox { checked, .. } = __out else {
497-
unreachable!()
493+
panic!("expected FormElement::Checkbox, got {__out:?}");
498494
};
499495
assert!(*checked);
500496

501497
mgr.toggle_checkbox(0, "remember");
502498
let __out = &mgr.forms[0].elements[2];
503-
assert!(
504-
matches!(&__out, FormElement::Checkbox { .. }),
505-
"expected FormElement::Checkbox, got {__out:?}"
506-
);
507499
let FormElement::Checkbox { checked, .. } = __out else {
508-
unreachable!()
500+
panic!("expected FormElement::Checkbox, got {__out:?}");
509501
};
510502
assert!(!*checked);
511503
}
@@ -623,12 +615,8 @@ mod tests {
623615

624616
mgr.select_option(fid, "size", 1);
625617
let __out = &mgr.forms[fid].elements[0];
626-
assert!(
627-
matches!(&__out, FormElement::SelectBox { .. }),
628-
"expected FormElement::SelectBox, got {__out:?}"
629-
);
630618
let FormElement::SelectBox { selected_index, .. } = __out else {
631-
unreachable!()
619+
panic!("expected FormElement::SelectBox, got {__out:?}");
632620
};
633621
assert_eq!(*selected_index, Some(1));
634622
}
@@ -661,12 +649,8 @@ mod tests {
661649
mgr.select_option(fid, "size", 1);
662650
// Should remain at 0 because index 1 is disabled.
663651
let __out = &mgr.forms[fid].elements[0];
664-
assert!(
665-
matches!(&__out, FormElement::SelectBox { .. }),
666-
"expected FormElement::SelectBox, got {__out:?}"
667-
);
668652
let FormElement::SelectBox { selected_index, .. } = __out else {
669-
unreachable!()
653+
panic!("expected FormElement::SelectBox, got {__out:?}");
670654
};
671655
assert_eq!(*selected_index, Some(0));
672656
}
@@ -859,12 +843,8 @@ mod tests {
859843

860844
let result = mgr.handle_input(FormKey::Enter);
861845
let __out = result;
862-
assert!(
863-
matches!(&__out, FormAction::Submit(_)),
864-
"expected FormAction::Submit, got {__out:?}"
865-
);
866846
let FormAction::Submit(data) = __out else {
867-
unreachable!()
847+
panic!("expected FormAction::Submit, got {__out:?}");
868848
};
869849
assert_eq!(data.action, "/login");
870850
}
@@ -1314,12 +1294,8 @@ mod tests {
13141294

13151295
let result = mgr.handle_input(FormKey::Enter);
13161296
let __out = result;
1317-
assert!(
1318-
matches!(&__out, FormAction::Submit(_)),
1319-
"expected FormAction::Submit, got {__out:?}"
1320-
);
13211297
let FormAction::Submit(data) = __out else {
1322-
unreachable!()
1298+
panic!("expected FormAction::Submit, got {__out:?}");
13231299
};
13241300
assert_eq!(data.action, "/login");
13251301
assert!(data.fields.iter().any(|(k, v)| k == "user" && v == "test"));

crates/oasis-browser/src/forms/state.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,8 @@ mod tests {
569569
fn element_kind_radio_button() {
570570
let elem = radio("color", "red", "colors", true);
571571
let __out = ElementKind::of(&elem);
572-
assert!(
573-
matches!(&__out, ElementKind::RadioButton { .. }),
574-
"expected RadioButton kind, got {__out:?}"
575-
);
576572
let ElementKind::RadioButton { group, value } = __out else {
577-
unreachable!()
573+
panic!("expected RadioButton kind, got {__out:?}");
578574
};
579575
assert_eq!(group, "colors");
580576
assert_eq!(value, "red");

crates/oasis-core/src/dashboard/vector_icons.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,8 @@ mod tests {
781781
let icon = icon_for_app("altimit", &app, 0, 0, &cfg);
782782
// First op should use the app's color.
783783
let __out = &icon.ops[0];
784-
assert!(
785-
matches!(&__out, oasis_vector::op::VectorOp::StrokeRect { .. }),
786-
"expected StrokeRect for the_world icon, got {__out:?}"
787-
);
788784
let oasis_vector::op::VectorOp::StrokeRect { color, .. } = __out else {
789-
unreachable!()
785+
panic!("expected StrokeRect for the_world icon, got {__out:?}");
790786
};
791787
assert_eq!(*color, Color::rgb(255, 0, 0));
792788
}
@@ -923,12 +919,8 @@ mod tests {
923919
assert_eq!(icon.name, "the_world");
924920
// Inner element should be a FillPolygon (rotated rect) instead of FillRect
925921
let __out = &icon.ops[1];
926-
assert!(
927-
matches!(&__out, oasis_vector::op::VectorOp::FillPolygon { .. }),
928-
"expected FillPolygon for animated the_world inner element, got {__out:?}"
929-
);
930922
let oasis_vector::op::VectorOp::FillPolygon { points, .. } = __out else {
931-
unreachable!()
923+
panic!("expected FillPolygon for animated the_world inner element, got {__out:?}");
932924
};
933925
assert_eq!(points.len(), 4);
934926

crates/oasis-core/src/plugin/examples.rs

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,8 @@ mod tests {
331331
stderr: String::new(),
332332
};
333333
let __out = cmds.execute("hello", &mut env).unwrap();
334-
assert!(
335-
matches!(&__out, CommandOutput::Text(_)),
336-
"expected text, got {__out:?}"
337-
);
338334
let CommandOutput::Text(s) = __out else {
339-
unreachable!()
335+
panic!("expected text, got {__out:?}");
340336
};
341337
assert_eq!(s, "Hello, World!");
342338
}
@@ -359,12 +355,8 @@ mod tests {
359355
stderr: String::new(),
360356
};
361357
let __out = cmds.execute("hello OASIS", &mut env).unwrap();
362-
assert!(
363-
matches!(&__out, CommandOutput::Text(_)),
364-
"expected text, got {__out:?}"
365-
);
366358
let CommandOutput::Text(s) = __out else {
367-
unreachable!()
359+
panic!("expected text, got {__out:?}");
368360
};
369361
assert_eq!(s, "Hello, OASIS!");
370362
}
@@ -417,12 +409,8 @@ mod tests {
417409
stderr: String::new(),
418410
};
419411
let __out = cmds.execute("pclock", &mut env).unwrap();
420-
assert!(
421-
matches!(&__out, CommandOutput::Text(_)),
422-
"expected text, got {__out:?}"
423-
);
424412
let CommandOutput::Text(s) = __out else {
425-
unreachable!()
413+
panic!("expected text, got {__out:?}");
426414
};
427415
assert!(s.contains("plugin active"));
428416
}
@@ -455,23 +443,15 @@ mod tests {
455443
let __out = cmds
456444
.execute("note write todo Fix the bug", &mut env)
457445
.unwrap();
458-
assert!(
459-
matches!(&__out, CommandOutput::Text(_)),
460-
"expected text, got {__out:?}"
461-
);
462446
let CommandOutput::Text(s) = __out else {
463-
unreachable!()
447+
panic!("expected text, got {__out:?}");
464448
};
465449
assert!(s.contains("saved"));
466450

467451
// Read it back.
468452
let __out = cmds.execute("note read todo", &mut env).unwrap();
469-
assert!(
470-
matches!(&__out, CommandOutput::Text(_)),
471-
"expected text, got {__out:?}"
472-
);
473453
let CommandOutput::Text(s) = __out else {
474-
unreachable!()
454+
panic!("expected text, got {__out:?}");
475455
};
476456
assert_eq!(s, "Fix the bug");
477457
}
@@ -495,25 +475,17 @@ mod tests {
495475
};
496476
// Initially empty.
497477
let __out = cmds.execute("note list", &mut env).unwrap();
498-
assert!(
499-
matches!(&__out, CommandOutput::Text(_)),
500-
"expected text, got {__out:?}"
501-
);
502478
let CommandOutput::Text(s) = __out else {
503-
unreachable!()
479+
panic!("expected text, got {__out:?}");
504480
};
505481
assert!(s.contains("no notes"));
506482

507483
// Write a note and list again.
508484
cmds.execute("note write memo Remember to test", &mut env)
509485
.unwrap();
510486
let __out = cmds.execute("note list", &mut env).unwrap();
511-
assert!(
512-
matches!(&__out, CommandOutput::Text(_)),
513-
"expected text, got {__out:?}"
514-
);
515487
let CommandOutput::Text(s) = __out else {
516-
unreachable!()
488+
panic!("expected text, got {__out:?}");
517489
};
518490
assert!(s.contains("memo"));
519491
}

0 commit comments

Comments
 (0)