Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ version = "0.4.0"
edition = "2024"

[workspace.dependencies]
cairo-lang-sierra = "2.10.1"
cairo-lang-sierra-to-casm = "2.10.1"
cairo-lang-starknet-classes = "2.10.1"
cairo-annotations = "0.2.2"

anyhow = "1.0.96"
assert_fs = "1.1.2"
camino = "1.1.9"
clap = { version = "4.5.30", features = ["derive"] }
criterion = "0.5"
cairo-annotations = "0.2.2"
cairo-lang-sierra = "2.10.1"
cairo-lang-sierra-to-casm = "2.10.1"
cairo-lang-starknet-classes = "2.10.1"
console = "0.15.10"
itertools = "0.14.0"
ignore = "0.4.23"
serde = "1.0.218"
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-coverage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition.workspace = true

[dependencies]
cairo-coverage-core = { path = "../cairo-coverage-core" }
console.workspace = true
camino.workspace = true
anyhow.workspace = true
clap.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions crates/cairo-coverage/src/args/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ pub enum IncludedComponent {
fn parse_trace_file(path: &str) -> Result<Utf8PathBuf> {
let trace_file = Utf8PathBuf::from(path);

ensure!(trace_file.exists(), "Trace file does not exist");
ensure!(trace_file.is_file(), "Trace file is not a file");
ensure!(trace_file.exists(), "trace file does not exist");
ensure!(trace_file.is_file(), "trace file is not a file");
ensure!(
matches!(trace_file.extension(), Some("json")),
"Trace file must have a JSON extension"
"trace file must have a JSON extension"
);

Ok(trace_file)
Expand All @@ -47,8 +47,8 @@ fn parse_trace_file(path: &str) -> Result<Utf8PathBuf> {
fn parse_project_path(path: &str) -> Result<Utf8PathBuf> {
let project_path = Utf8PathBuf::from(path);

ensure!(project_path.exists(), "Project path does not exist");
ensure!(project_path.is_dir(), "Project path is not a directory");
ensure!(project_path.exists(), "project path does not exist");
ensure!(project_path.is_dir(), "project path is not a directory");

Ok(project_path)
}
10 changes: 6 additions & 4 deletions crates/cairo-coverage/src/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::args::clean::CleanArgs;
use crate::ui;
use anyhow::{Context, Result};
use std::fs;
use walkdir::WalkDir;
Expand All @@ -13,7 +14,7 @@ pub fn run(
) -> Result<()> {
let target_file_name = files_to_delete
.file_name()
.context("Failed to obtain the file name from `files_to_delete`.")?;
.context("failed to obtain the file name from `--files-to-delete`")?;

WalkDir::new(root_dir)
.into_iter()
Expand All @@ -24,16 +25,17 @@ pub fn run(

if let Some(file_name) = path.file_name() {
if file_name == target_file_name {
println!("Deleting file: {}", path.display());
let path_display = path.display();
ui::msg(format!("deleting file: {path_display}"));
fs::remove_file(path)
.with_context(|| format!("Failed to delete file: {}", path.display()))?;
.with_context(|| format!("failed to delete file: {path_display}"))?;
}
}

Ok(())
})?;

println!("Cleanup complete.");
ui::msg("cleanup complete");
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions crates/cairo-coverage/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ pub fn run(
.append(true)
.create(true)
.open(&output_path)
.context(format!("Failed to open output file at path: {output_path}"))?
.context(format!("failed to open output file at path: {output_path}"))?
.write_all(lcov.as_bytes())
.context("Failed to write to output file")?;
.context("failed to write to output file")?;

Ok(())
}
Expand Down
31 changes: 23 additions & 8 deletions crates/cairo-coverage/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
use crate::args::{CairoCoverageArgs, Command};
use anyhow::Result;

use clap::Parser;
use std::process::ExitCode;

mod args;
mod commands;
mod ui;

fn main() -> ExitCode {
if let Err(error) = main_inner() {
ui::error(error);
ExitCode::FAILURE
} else {
ExitCode::SUCCESS
}
}

fn main() -> Result<()> {
fn main_inner() -> Result<()> {
let cairo_coverage_args = CairoCoverageArgs::parse();

let command = match cairo_coverage_args.command {
Some(command) => command,
// TODO:
// * In 0.5.0 add deprecation warning
// * In 0.6.0 remove the default command
None => Command::Run(cairo_coverage_args.run_args.unwrap_or_else(|| {
// TODO:
// * In 0.6.0 remove the default command
let command = if let Some(command) = cairo_coverage_args.command {
command
} else {
ui::warning("running `cairo-coverage` without a subcommand is deprecated");
ui::help("consider using `cairo-coverage run`");

Command::Run(cairo_coverage_args.run_args.unwrap_or_else(|| {
unreachable!("`run_args` should be set when no subcommand is provided")
})),
}))
};

commands::run(command)
Expand Down
28 changes: 28 additions & 0 deletions crates/cairo-coverage/src/ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//! UI utilities for the Cairo coverage tool.
//! All human-oriented messaging must use this module to communicate with the user.
//! Messages should be lowercased and should not end with a period.
use console::style;
use std::fmt::Display;

/// Print a warning message.
pub fn warning(message: impl Display) {
let tag = style("warning").yellow();
println!("{tag}: {message}");
}

/// Print an error message.
pub fn error(message: impl Display) {
let tag = style("error").red();
println!("{tag}: {message}");
}

/// Print a help message.
pub fn help(message: impl Display) {
let tag = style("help").bold();
println!("{tag}: {message}");
}

/// Print a message.
pub fn msg(message: impl Display) {
println!("{message}");
}
Loading