Skip to content

Commit e5a3202

Browse files
hyperpolymathclaude
andcommitted
fix(rust): revert anti-pattern .expect("TODO") to .unwrap() in tests (12 sites)
12 test-only sites in src/rust/src/{crypto,ecm}/ were using .expect("TODO: handle error") — identical panic to .unwrap() but with a fake debt marker that makes future review noisier. Standing rule treats this as an anti-pattern: revert on sight. All sites are inside #[cfg(test)] / #[test] functions where panicking on Err/None is the correct test verdict, so .unwrap() is the right form. cargo test --lib: 20/20 green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1f144f6 commit e5a3202

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/rust/src/crypto/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,27 +233,27 @@ mod tests {
233233

234234
#[test]
235235
fn kyber1024_round_trip() {
236-
let keypair = kem_keygen(KemAlgorithm::Kyber1024).expect("TODO: handle error");
237-
let encap = kem_encapsulate(&keypair.public_key, KemAlgorithm::Kyber1024).expect("TODO: handle error");
238-
let decap = kem_decapsulate(&encap.ciphertext, &keypair.secret_key, KemAlgorithm::Kyber1024).expect("TODO: handle error");
236+
let keypair = kem_keygen(KemAlgorithm::Kyber1024).unwrap();
237+
let encap = kem_encapsulate(&keypair.public_key, KemAlgorithm::Kyber1024).unwrap();
238+
let decap = kem_decapsulate(&encap.ciphertext, &keypair.secret_key, KemAlgorithm::Kyber1024).unwrap();
239239
assert_eq!(encap.shared_secret, decap);
240240
}
241241

242242
#[test]
243243
fn dilithium5_sign_verify() {
244-
let keypair = sig_keygen(SignatureAlgorithm::Dilithium5).expect("TODO: handle error");
244+
let keypair = sig_keygen(SignatureAlgorithm::Dilithium5).unwrap();
245245
let message = b"DEFENSIVE USE ONLY";
246-
let signed = sign(message, &keypair.secret_key, SignatureAlgorithm::Dilithium5).expect("TODO: handle error");
247-
let opened = verify(&signed, &keypair.public_key, SignatureAlgorithm::Dilithium5).expect("TODO: handle error");
246+
let signed = sign(message, &keypair.secret_key, SignatureAlgorithm::Dilithium5).unwrap();
247+
let opened = verify(&signed, &keypair.public_key, SignatureAlgorithm::Dilithium5).unwrap();
248248
assert_eq!(opened, message);
249249
}
250250

251251
#[test]
252252
fn sphincs_sign_verify() {
253-
let keypair = sig_keygen(SignatureAlgorithm::SphincsPlusSha2256f).expect("TODO: handle error");
253+
let keypair = sig_keygen(SignatureAlgorithm::SphincsPlusSha2256f).unwrap();
254254
let message = b"post-quantum fallback";
255-
let signed = sign(message, &keypair.secret_key, SignatureAlgorithm::SphincsPlusSha2256f).expect("TODO: handle error");
256-
let opened = verify(&signed, &keypair.public_key, SignatureAlgorithm::SphincsPlusSha2256f).expect("TODO: handle error");
255+
let signed = sign(message, &keypair.secret_key, SignatureAlgorithm::SphincsPlusSha2256f).unwrap();
256+
let opened = verify(&signed, &keypair.public_key, SignatureAlgorithm::SphincsPlusSha2256f).unwrap();
257257
assert_eq!(opened, message);
258258
}
259259
}

src/rust/src/ecm/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ mod tests {
173173
let (peak_freq, _peak_power) = spectrum
174174
.iter()
175175
.copied()
176-
.max_by(|a, b| a.1.partial_cmp(&b.1).expect("TODO: handle error"))
177-
.expect("TODO: handle error");
176+
.max_by(|a, b| a.1.partial_cmp(&b.1).unwrap())
177+
.unwrap();
178178

179179
// Peak should be within one frequency bin of 1000 Hz.
180180
let bin_width = sig.sample_rate_hz / sig.num_samples as f64;

src/rust/src/ecm/signals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,6 @@ mod tests {
147147

148148
assert!(snapshot.has_jamming());
149149
assert_eq!(snapshot.count_by_class(SignalClassification::SuspectedJamming), 1);
150-
assert_eq!(snapshot.strongest_signal().expect("TODO: handle error").snr_db, 60.0);
150+
assert_eq!(snapshot.strongest_signal().unwrap().snr_db, 60.0);
151151
}
152152
}

0 commit comments

Comments
 (0)