1// Copyright 2025 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
45//! Abstractions enabling test-only behavior.
67pub use inner::{TestOnlyFrom, TestOnlyPartialEq};
89// The implementation for test code.
10#[cfg(any(test, feature = "testutils"))]
11mod inner {
12pub use crate::Counter;
1314/// Applies `PartialEq` bounds, only in tests.
15pub trait TestOnlyPartialEq: PartialEq {}
1617impl<T: PartialEq> TestOnlyPartialEq for T {}
1819// This implementation is necessary to satisfy trait bounds, but it's
20 // likely a programming error to try to use it.
21impl PartialEq for Counter {
22fn eq(&self, _other: &Self) -> bool {
23panic!("The `Counter` type shouldn't be checked for equality")
24 }
25 }
2627/// Applies `From` bounds, only in tests.
28pub trait TestOnlyFrom<T>: From<T> {}
2930impl<T1, T2: From<T1>> TestOnlyFrom<T1> for T2 {}
31}
3233// The implementation for non-test code
34#[cfg(not(any(test, feature = "testutils")))]
35mod inner {
3637/// Applies `PartialEq` bounds, only in tests.
38pub trait TestOnlyPartialEq {}
3940impl<T> TestOnlyPartialEq for T {}
4142/// Applies `From` bounds, only in tests.
43pub trait TestOnlyFrom<T> {}
4445impl<T1, T2> TestOnlyFrom<T1> for T2 {}
46}