qubit_fs_testkit/contract_check.rs
1// =============================================================================
2// Copyright (c) 2026 Haixing Hu.
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6// Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Stable identity and outcome for one contract check.
9
10use qubit_fs::metadata::FileSystemCapability;
11
12use crate::ContractCheckId;
13use crate::ContractCheckOutcome;
14
15/// One named check in a contract report.
16///
17/// # Examples
18///
19/// ```
20/// # mod support { include!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/common/rustdoc_support.rs")); }
21/// # use support::RustdocSyncFixture;
22/// use qubit_fs_testkit::{ContractCheckOutcome, FileSystemContract, FileSystemContractSuite};
23///
24/// let fixture = RustdocSyncFixture::new();
25/// let mut suite = FileSystemContractSuite::new(&fixture);
26/// suite.run_contract(FileSystemContract::Properties);
27/// let check = &suite.run().report().checks()[0];
28/// assert!(matches!(check.outcome(), ContractCheckOutcome::Passed | ContractCheckOutcome::Failed { .. }));
29/// ```
30#[must_use]
31#[derive(Clone, Debug, Eq, PartialEq)]
32pub struct ContractCheck {
33 /// Stable identifier used to correlate this check across reports.
34 pub(crate) id: ContractCheckId,
35 /// Capability required by the check, if it depends on one.
36 pub(crate) capability: Option<FileSystemCapability>,
37 /// Outcome recorded after evaluating the check.
38 pub(crate) outcome: ContractCheckOutcome,
39}
40
41impl ContractCheck {
42 /// Returns the stable check identifier.
43 #[inline]
44 pub const fn id(&self) -> ContractCheckId {
45 self.id
46 }
47
48 /// Returns the capability associated with this check, when one exists.
49 #[inline]
50 pub const fn capability(&self) -> Option<FileSystemCapability> {
51 self.capability
52 }
53
54 /// Returns the recorded check outcome.
55 #[must_use = "the recorded outcome should be inspected"]
56 #[inline]
57 pub const fn outcome(&self) -> &ContractCheckOutcome {
58 &self.outcome
59 }
60}