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
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ anyhow = "1.0.95"
clap = "4.5.26"
config = { version = "0.15.11", features = ["toml"] }
normpath = "1.3"
numeric-sort = "0.1.5"
regex = "1.11.1"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.138"
Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ anyhow.workspace = true
clap.workspace = true
config.workspace = true
normpath.workspace = true
numeric-sort.workspace = true
regex.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down
8 changes: 3 additions & 5 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const ABOUT: &str = env!("CARGO_PKG_DESCRIPTION");

fn main() -> Result<()> {
let about_text = format!("{} {}\n{}", NAME, VERSION, ABOUT);
let after_help_text = format!(
"See '{} help <command>' for more information on a command",
BIN_NAME
);
let about_text = format!("{NAME} {VERSION}\n{ABOUT}");
let after_help_text =
format!("See '{BIN_NAME} help <command>' for more information on a command");

let cli = Command::new(NAME)
.bin_name(BIN_NAME)
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/problem/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn check(problems_dir: PathBuf, problem_name: &str) -> Result<()> {
if !exists {
bail!("The folder structure is not valid! Missing file {file}");
}
eprintln!("Folder structure for '{}' is valid", problem_name);
eprintln!("Folder structure for '{problem_name}' is valid");

// Check that test files are valid, i.e.:
// - A .in file must have a corresponding .out file
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/problem/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn compare(settings: &Settings, compare_args: &CompareArgs) -> Result<()> {
eprintln!("Running the solution files for each test case...");

for test_file in test_files {
let input_file_path = problem_path.join(format!("tests/{}", test_file));
let input_file_path = problem_path.join(format!("tests/{test_file}"));

let mut results: Vec<RunResult> = Vec::new();
for (i, run_cmd) in run_commands.iter().enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/problem/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn create(problems_dir: &Path, problem_name: &str, difficulty: u16) -> Resul
let difficulty_str = if difficulty == 0 {
"unrated".to_string()
} else {
format!("{:0>4}", bucketed_difficulty)
format!("{bucketed_difficulty:0>4}")
};
let re = Regex::new(PROBLEM_NAME_REGEX_PATTERN)?;
if !re.is_match(problem_name) {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/problem/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn fuzz(settings: &Settings, fuzz_args: &FuzzArgs) -> Result<()> {
generate::generate(settings, problems_dir, problem_name, generator, &test_name)
.context("Failed to generate test case")?;

let input_file_path = problem_path.join(format!("tests/{}.in", test_name));
let input_file_path = problem_path.join(format!("tests/{test_name}.in"));

let mut results: Vec<RunResult> = Vec::new();
for (i, run_cmd) in run_commands.iter().enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/problem/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl RunCommand {
bin_file: PathBuf,
script_file: PathBuf,
) -> Result<Self> {
let mut file_path = problem.join(format!("{}", file));
let mut file_path = problem.join(format!("{file}"));
file_path = file_path
.normalize()
.context(format!(
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/src/problem/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn solve(
let problem = project_root.join(get_problem(problems_dir, problem_name)?);

let solution_lang = solution_lang.unwrap_or(&settings.problem.default_lang);
let mut solution_file = problem.join(format!("solutions/solution.{}", solution_lang));
let mut solution_file = problem.join(format!("solutions/solution.{solution_lang}"));
if solution_file_name.is_some() {
solution_file = problem.join(format!(
"solutions/{}",
Expand All @@ -38,7 +38,7 @@ pub fn solve(
eprintln!("Using solution file at: {}", solution_file.display());

let bin_file = problem.join("solutions/solution.out");
let script_file = problem.join(format!("solutions/solution.{}", solution_lang));
let script_file = problem.join(format!("solutions/solution.{solution_lang}"));

let lang_settings = settings
.problem
Expand Down Expand Up @@ -84,7 +84,7 @@ pub fn solve(
eprintln!("Running the solution file for each test case...");
// Run the file for every test input and generate the corresponding output
for test_file in test_files {
let input_file_path = problem.join(format!("tests/{}", test_file));
let input_file_path = problem.join(format!("tests/{test_file}"));
let output_file_path = problem.join(format!(
"tests/{}.out",
test_file
Expand Down Expand Up @@ -114,7 +114,7 @@ pub fn solve(

final_cmd = final_cmd.stdin(input_file).stdout(output_file);
final_cmd.capture()?;
eprintln!(" - generated output for test file: {}", test_file);
eprintln!(" - generated output for test file: {test_file}");
}
eprintln!("Finished generating outputs for all test cases");

Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/problem/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn test(
let problem = project_root.join(get_problem(problems_dir, problem_name)?);

let solution_lang = solution_lang.unwrap_or(&settings.problem.default_lang);
let mut solution_file = problem.join(format!("solutions/solution.{}", solution_lang));
let mut solution_file = problem.join(format!("solutions/solution.{solution_lang}"));
if solution_file_name.is_some() {
solution_file = problem.join(format!(
"solutions/{}",
Expand All @@ -41,7 +41,7 @@ pub fn test(
eprintln!("Using solution file at: {}", solution_file.display());

let bin_file = problem.join("solutions/solution.out");
let script_file = problem.join(format!("solutions/solution.{}", solution_lang));
let script_file = problem.join(format!("solutions/solution.{solution_lang}"));

let lang_settings = settings
.problem
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn test(
let mut total_time: Duration = Duration::new(0, 0);

for test_file in test_files {
let input_file_path = problem.join(format!("tests/{}", test_file));
let input_file_path = problem.join(format!("tests/{test_file}"));
let output_file_path = problem.join(format!(
"tests/{}.out",
test_file
Expand Down
4 changes: 3 additions & 1 deletion crates/cli/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fs;
use std::path::{Path, PathBuf};

use anyhow::{bail, Context, Result};
use numeric_sort::sort_unstable;

use crate::config::SETTINGS_FILE_NAME;
use crate::problem::sync_mappings::problem_exists;
Expand Down Expand Up @@ -60,10 +61,11 @@ pub fn get_files_in_directory<P: AsRef<Path>>(path: P) -> Result<Vec<String>> {
}

pub fn get_input_files_in_directory<P: AsRef<Path>>(path: P) -> Result<Vec<String>> {
let files = get_files_in_directory(path)?
let mut files: Vec<_> = get_files_in_directory(path)?
.into_iter()
.filter(|name| name.ends_with(".in"))
.collect();
sort_unstable(&mut files);
Ok(files)
}

Expand Down
Loading