Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
refactor(cache): remove unused CAIRO_FOUNDRY_COMPILED_CONTRACT_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
haroune-mohammedi authored and tdelabro committed Feb 20, 2023
1 parent 54c1f6b commit cf91f94
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
7 changes: 2 additions & 5 deletions src/cli/commands/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Display for CleanOutput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for (dir, deleted) in self.dirs.iter() {
if *deleted {
writeln!(f, "cleaned : {}", dir.display())?;
writeln!(f, "cleaned: {}", dir.display())?;
} else {
writeln!(f, "not found: {}", dir.display())?;
}
Expand All @@ -59,10 +59,7 @@ impl CommandExecution<CleanOutput, CleanCommandError> for CleanArgs {

let mut dirs: Vec<(PathBuf, bool)> = Vec::new();

let paths_to_clean = [
cache::CAIRO_FOUNDRY_CACHE_DIR,
cache::CAIRO_FOUNDRY_COMPILED_CONTRACT_DIR,
];
let paths_to_clean = [cache::CAIRO_FOUNDRY_CACHE_DIR];

for path in paths_to_clean.iter() {
let dir = cache_dir.join(path);
Expand Down
33 changes: 18 additions & 15 deletions src/cli/commands/clean/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,25 @@ fn output_can_display_as_string() {
],
};

let expected_output = "cleaned : /dir1\nnot found: /dir2\nCache cleaned successfully.\n";
let expected_output = "cleaned: /dir1\nnot found: /dir2\nCache cleaned successfully.\n";

assert_eq!(expected_output, format!("{output}"));
}

#[test]
fn clean_cache_dirs() -> Result<(), CleanCommandError> {
let test_cache_dir = cache::cache_dir()?;
fs::create_dir_all(test_cache_dir.join(cache::CAIRO_FOUNDRY_CACHE_DIR)).map_err(|e| {
CleanCommandError::DirCreation {
dir: test_cache_dir.as_path().display().to_string(),
err: e,
}
})?;

remove_dir_all_if_exists(&test_cache_dir.join(cache::CAIRO_FOUNDRY_COMPILED_CONTRACT_DIR))?;
let cairo_foundry_cache_dir = test_cache_dir.join(cache::CAIRO_FOUNDRY_CACHE_DIR);

fs::create_dir_all(&cairo_foundry_cache_dir).map_err(|e| CleanCommandError::DirCreation {
dir: test_cache_dir.as_path().display().to_string(),
err: e,
})?;

let output = CleanArgs {}.exec()?;

let expected_dirs = vec![
(test_cache_dir.join(cache::CAIRO_FOUNDRY_CACHE_DIR), true),
(
test_cache_dir.join(cache::CAIRO_FOUNDRY_COMPILED_CONTRACT_DIR),
false,
),
];
let expected_dirs = vec![(cairo_foundry_cache_dir.clone(), true)];

let expected_output = CleanOutput {
dirs: expected_dirs,
Expand All @@ -53,5 +46,15 @@ fn clean_cache_dirs() -> Result<(), CleanCommandError> {

remove_dir_all_if_exists(&test_cache_dir)?;

let output = CleanArgs {}.exec()?;

let expected_dirs = vec![(cairo_foundry_cache_dir, false)];

let expected_output = CleanOutput {
dirs: expected_dirs,
};

assert_eq!(expected_output, output);

Ok(())
}
1 change: 0 additions & 1 deletion src/compile/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pub enum CacheError {

pub const JSON_FILE_EXTENTION: &str = "json";
pub const CAIRO_FOUNDRY_CACHE_DIR: &str = "cairo-foundry-cache";
pub const CAIRO_FOUNDRY_COMPILED_CONTRACT_DIR: &str = "compiled-cairo-files";

#[cfg(not(test))]
pub fn cache_dir() -> Result<PathBuf, CacheDirNotSupported> {
Expand Down
6 changes: 2 additions & 4 deletions src/compile/cache/tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::{fs};
use std::fs;

use assert_matches::assert_matches;

use super::{
CacheError, CompileCacheItem,
};
use super::{CacheError, CompileCacheItem};

#[test]
fn read_cache_with_valid_input() {
Expand Down

0 comments on commit cf91f94

Please sign in to comment.