Skip to content

Commit

Permalink
Merge pull request #99 from Ackee-Blockchain/feat/update-gitignore
Browse files Browse the repository at this point in the history
✨ Automatically add hfuzz_target to .gitignore file
  • Loading branch information
lukacan committed Sep 17, 2023
2 parents 1a2f9ee + cc58531 commit 72fbdea
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion crates/client/src/test_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ use crate::{
};
use fehler::{throw, throws};
use std::{
env, io,
env,
fs::OpenOptions,
io,
path::{Path, PathBuf},
};
use std::{fs::File, io::prelude::*};
use thiserror::Error;
use tokio::fs;
use toml::{
Expand Down Expand Up @@ -96,6 +99,7 @@ impl TestGenerator {
self.build_program_client(&commander).await?;
if !skip_fuzzer {
self.generate_fuzz_test_files(&root).await?;
self.update_gitignore(&root, "hfuzz_target")?;
}
}

Expand Down Expand Up @@ -257,6 +261,29 @@ impl TestGenerator {
fs::write(cargo, content.to_string()).await?;
}

/// Updates .gitignore file in the `root` directory and appends `ignored_path` to the end of the file
#[throws]
fn update_gitignore(&self, root: &Path, ignored_path: &str) {
let file_path = root.join(".gitignore");
if file_path.exists() {
let file = File::open(&file_path)?;
for line in io::BufReader::new(file).lines().flatten() {
if line == ignored_path {
// do not add the ignored path again if it is already in the .gitignore file
return;
}
}
let file = OpenOptions::new().write(true).append(true).open(file_path);

if let Ok(mut file) = file {
writeln!(file, "{}", ignored_path)?;
println!(".gitignore file sucessfully updated");
}
} else {
println!("Skipping updating .gitignore file");
}
}

/// Adds programs to Cargo.toml as a dependencies to be able to be used in tests and fuzz targets
#[throws]
async fn add_program_deps(&self, root: &Path, cargo_toml_path: &Path) {
Expand Down

0 comments on commit 72fbdea

Please sign in to comment.