pub struct TestCodeChange {
pub file_path: PathBuf,
pub original_content: String,
pub modified_content: String,
pub change_id: String,
}Expand description
Represents a test modification to source code.
The change is designed to be:
- Minimal: Single file modification
- Detectable: Produces a different binary hash
- Reversible: Can be applied and reverted cleanly
- Deterministic: Same change always produces same result
Fields§
§file_path: PathBufPath to the file being modified.
original_content: StringOriginal file content before modification.
modified_content: StringContent with the test change applied.
change_id: StringUnique identifier for this change (appears in binary).
Implementations§
Source§impl TestCodeChange
impl TestCodeChange
Sourcepub fn for_file(file_path: &Path) -> Result<Self>
pub fn for_file(file_path: &Path) -> Result<Self>
Create a test change that adds a unique marker constant.
This adds a const string to the specified file that will be compiled into the binary, allowing verification that compilation actually occurred.
§Arguments
file_path- Path to the source file to modify
§Example
use std::path::Path;
use rch_common::test_change::TestCodeChange;
let change = TestCodeChange::for_file(Path::new("src/main.rs")).unwrap();
println!("Change ID: {}", change.change_id);Sourcepub fn for_main_rs(project_dir: &Path) -> Result<Self>
pub fn for_main_rs(project_dir: &Path) -> Result<Self>
Create a test change for the main.rs file in a project directory.
§Arguments
project_dir- Path to the Rust project root
Sourcepub fn for_lib_rs(project_dir: &Path) -> Result<Self>
pub fn for_lib_rs(project_dir: &Path) -> Result<Self>
Create a test change for lib.rs in a project directory.
§Arguments
project_dir- Path to the Rust project root
Sourcepub fn apply(&self) -> Result<()>
pub fn apply(&self) -> Result<()>
Apply the test change to the file.
This writes the modified content to the file path.
Sourcepub fn verify_in_binary(&self, binary_path: &Path) -> Result<bool>
pub fn verify_in_binary(&self, binary_path: &Path) -> Result<bool>
Trait Implementations§
Source§impl Clone for TestCodeChange
impl Clone for TestCodeChange
Source§fn clone(&self) -> TestCodeChange
fn clone(&self) -> TestCodeChange
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TestCodeChange
impl RefUnwindSafe for TestCodeChange
impl Send for TestCodeChange
impl Sync for TestCodeChange
impl Unpin for TestCodeChange
impl UnsafeUnpin for TestCodeChange
impl UnwindSafe for TestCodeChange
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more