-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/Added CLI option to initialize fuzz tests or poc tests only (#124)
* ✨ Init Template * Init template updates * 🐛 Build command to execute only if trdelnik is initialized * 🐛 fixes
- Loading branch information
Showing
12 changed files
with
394 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
use anyhow::Error; | ||
use anyhow::{bail, Error}; | ||
use fehler::throws; | ||
use trdelnik_client::*; | ||
|
||
use crate::_discover; | ||
|
||
use super::fuzz::TRDELNIK_TOML; | ||
|
||
#[throws] | ||
pub async fn build(root: String) { | ||
let commander = Commander::with_root(root); | ||
commander.create_program_client_crate().await?; | ||
commander.build_programs().await?; | ||
commander.generate_program_client_deps().await?; | ||
commander.generate_program_client_lib_rs(None).await?; | ||
pub async fn build(root: Option<String>) { | ||
// if the root is present from the command line we will use it | ||
// if the root is not present we will look for the Cargo.toml file | ||
// Trdelnik does not have to be already defined to actually create/build | ||
// program client | ||
let root = match root { | ||
Some(r) => r, | ||
_ => { | ||
if let Some(r) = _discover(TRDELNIK_TOML)? { | ||
r | ||
} else { | ||
bail!("It does not seem that Trdelnik is initialized because the Trdelnik.toml file was not found in any parent directory!"); | ||
} | ||
} | ||
}; | ||
let mut generator: TestGenerator = TestGenerator::new_with_root(root); | ||
generator.build().await?; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,39 @@ | ||
use anyhow::Error; | ||
use anyhow::{bail, Error}; | ||
use clap::ValueEnum; | ||
use fehler::throws; | ||
use trdelnik_client::TestGenerator; | ||
|
||
use crate::_discover; | ||
|
||
pub const ANCHOR_TOML: &str = "Anchor.toml"; | ||
|
||
#[derive(ValueEnum, Clone)] | ||
pub enum TestsType { | ||
Both, | ||
Fuzz, | ||
Poc, | ||
} | ||
|
||
#[throws] | ||
pub async fn init(skip_fuzzer: bool) { | ||
let generator = TestGenerator::new(); | ||
generator.generate(skip_fuzzer).await?; | ||
pub async fn init(tests_type: TestsType) { | ||
// look for Anchor.toml | ||
let root = if let Some(r) = _discover(ANCHOR_TOML)? { | ||
r | ||
} else { | ||
bail!("It does not seem that Anchor is initialized because the Anchor.toml file was not found in any parent directory!"); | ||
}; | ||
|
||
let mut generator: TestGenerator = TestGenerator::new_with_root(root); | ||
|
||
match tests_type { | ||
TestsType::Poc => { | ||
generator.generate_poc().await?; | ||
} | ||
TestsType::Both => { | ||
generator.generate_both().await?; | ||
} | ||
TestsType::Fuzz => { | ||
generator.generate_fuzz().await?; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
use anyhow::Error; | ||
use anyhow::{bail, Error}; | ||
use fehler::throws; | ||
use trdelnik_client::*; | ||
|
||
use crate::_discover; | ||
|
||
use super::fuzz::TRDELNIK_TOML; | ||
|
||
#[throws] | ||
pub async fn test(root: String) { | ||
pub async fn test(root: Option<String>) { | ||
// if the root is present from the command line we will use it | ||
// if the root is not present we will look for the Trdelnik.toml file | ||
let root = match root { | ||
Some(r) => r, | ||
_ => { | ||
if let Some(r) = _discover(TRDELNIK_TOML)? { | ||
r | ||
} else { | ||
bail!("It does not seem that Trdelnik is initialized because the Cargo.toml file was not found in any parent directory!"); | ||
} | ||
} | ||
}; | ||
let commander = Commander::with_root(root); | ||
commander.run_tests().await?; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.