Skip to content

Commit

Permalink
feat(pegboard): create robust testing system
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterPtato committed Oct 1, 2024
1 parent a32cb52 commit 1949c59
Show file tree
Hide file tree
Showing 28 changed files with 1,668 additions and 86 deletions.
18 changes: 9 additions & 9 deletions lib/bolt/core/src/context/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,22 @@ impl ProjectContextData {

let mut svc_ctxs_map = HashMap::new();

let mut source_diff = String::new();
let mut source_diff = Vec::new();

// Load sub projects
for (_, additional_root) in &config.additional_roots {
let path = project_root.join(&additional_root.path);
Self::load_root_dir(&mut svc_ctxs_map, path.clone()).await;

// Compute the git diff between the current branch and the local changes
source_diff.push_str(&get_source_diff(&path).await.unwrap());
source_diff.extend(&get_source_diff(&path).await.unwrap());
}

// Load main project after sub projects so it overrides sub project services
Self::load_root_dir(&mut svc_ctxs_map, project_root.clone()).await;

// Compute the git diff between the current branch and the local changes
source_diff.push_str(&get_source_diff(&project_root).await.unwrap());
source_diff.extend(&get_source_diff(&project_root).await.unwrap());

// If there is no diff, use the git commit hash
let source_hash = if source_diff.is_empty() {
Expand All @@ -142,7 +142,7 @@ impl ProjectContextData {
.to_string()
} else {
// Get hash of diff
hex::encode(Sha256::digest(source_diff.as_bytes()))
hex::encode(Sha256::digest(source_diff))
};

let mut svc_ctxs = svc_ctxs_map.values().cloned().collect::<Vec<_>>();
Expand Down Expand Up @@ -1231,7 +1231,7 @@ impl ProjectContextData {
}
}

async fn get_source_diff(path: &Path) -> Result<String> {
async fn get_source_diff(path: &Path) -> Result<Vec<u8>> {
use tokio::io::AsyncReadExt;
use tokio::process::Command;

Expand All @@ -1241,7 +1241,7 @@ async fn get_source_diff(path: &Path) -> Result<String> {
.args(&["--no-pager", "diff", "HEAD", "--minimal"])
.output()
.await?;
let mut result = String::from_utf8(diff_output.stdout)?;
let mut result = diff_output.stdout;

// Add diff for untracked files
let ls_files_output = Command::new("git")
Expand All @@ -1257,12 +1257,12 @@ async fn get_source_diff(path: &Path) -> Result<String> {
.await?;
for file in String::from_utf8(ls_files_output.stdout)?.split('\0') {
if !file.is_empty() {
let mut file_content = String::new();
let mut file_content = Vec::new();
tokio::fs::File::open(path.join(file))
.await?
.read_to_string(&mut file_content)
.read(&mut file_content)
.await?;
result.push_str(&file_content);
result.extend(file_content);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/formatted-error/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct FrontMatter {

struct Ctx {
matter: Matter<TOML>,
base_path: PathBuf,
_base_path: PathBuf,
hash_items: Vec<String>,
const_items: Vec<String>,
existing_keys: HashMap<String, PathBuf>,
Expand All @@ -25,7 +25,7 @@ impl Ctx {
fn new(base_path: PathBuf) -> Ctx {
Ctx {
matter: Matter::<TOML>::new(),
base_path,
_base_path: base_path,
hash_items: Vec::new(),
const_items: Vec::new(),
existing_keys: HashMap::new(),
Expand Down
Loading

0 comments on commit 1949c59

Please sign in to comment.