Skip to content

Commit

Permalink
fix(dev-cli): adapt cli for new arch
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLucqs committed Aug 14, 2024
1 parent bdb3e14 commit 5abe5da
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/cairo-lint-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(let_chains, is_none_or)]
#![feature(let_chains)]
pub mod db;
pub mod fix;
pub mod lints;
Expand Down
20 changes: 14 additions & 6 deletions crates/cairo-lint-dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use std::fs;
use std::io::{self, Write};
use std::path::{Path, PathBuf};

fn create_new_test(lint_name: &str) -> io::Result<()> {
fn create_new_test(lint_group: &str, lint_name: &str) -> io::Result<()> {
let test_content = "//! > Test name\n\n//! > cairo_code\nfn main() {\n let a: Option<felt252> = \
Option::Some(1);\n}\n"
.to_string();

let test_files_dir = PathBuf::from("crates/cairo-lint-core/tests/test_files");
let test_files_dir = PathBuf::from(format!("crates/cairo-lint-core/tests/test_files/{lint_group}"));
if !test_files_dir.exists() {
fs::create_dir_all(&test_files_dir)?;
}
Expand All @@ -26,7 +26,7 @@ fn create_new_test(lint_name: &str) -> io::Result<()> {
return Ok(());
}

let new_test_entry = format!(r#"test_file!({}, "Test name");"#, lint_name);
let new_test_entry = format!(r#"test_file!({}, {}, "Test name");"#, lint_group, lint_name);

let mut tests_rs_content = fs::read_to_string(tests_rs_path)?;
tests_rs_content.push('\n');
Expand All @@ -39,16 +39,24 @@ fn create_new_test(lint_name: &str) -> io::Result<()> {
}

fn main() {
let lint_name = if let Some(arg1) = std::env::args().nth(1) {
let lint_group = if let Some(arg1) = std::env::args().nth(1) {
arg1
} else {
println!("Enter the name of the lint:");
println!("Enter the name of the lint group:");
let mut lint_group = String::new();
io::stdin().read_line(&mut lint_group).expect("Failed to read line");
lint_group.trim().to_string()
};
let lint_name = if let Some(arg1) = std::env::args().nth(2) {
arg1
} else {
println!("Enter the name of the lint group:");
let mut lint_name = String::new();
io::stdin().read_line(&mut lint_name).expect("Failed to read line");
lint_name.trim().to_string()
};

if let Err(e) = create_new_test(&lint_name) {
if let Err(e) = create_new_test(&lint_group, &lint_name) {
eprintln!("Error creating test file: {}", e);
}
}
1 change: 0 additions & 1 deletion crates/cairo-lint-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ macro_rules! test_file {
new_tests.tests.insert(test_name.to_string(), new_test);
}
assert_eq!(formatted_diags, test.attributes["diagnostics"]);
println!("{file}");
assert_eq!(file, test.attributes["fixed"]);
}
}
Expand Down

0 comments on commit 5abe5da

Please sign in to comment.