From 17636fca11b1a09dcebdef9f29866ba0c6b03236 Mon Sep 17 00:00:00 2001 From: mb Date: Thu, 6 Oct 2022 18:10:07 +0200 Subject: [PATCH 01/10] improved checks --- src/check.rs | 8 +++----- src/check/formatting.rs | 17 +++++++++++++++++ src/check/testables.rs | 31 +++++++++++++++++++++---------- src/main.rs | 1 + src/tasks.rs | 20 +++++++++++++++----- 5 files changed, 57 insertions(+), 20 deletions(-) create mode 100644 src/check/formatting.rs diff --git a/src/check.rs b/src/check.rs index 32990c2..1cd9d9d 100644 --- a/src/check.rs +++ b/src/check.rs @@ -7,9 +7,7 @@ use crate::{ utils::{log_failure, log_process, log_success}, }; -/// TODO: fill with appropriate rules -const FORMAT_CONFIG: &str = r#"{BasedOnStyle: llvm}"#; - +mod formatting; mod testables; pub fn main(files: Vec) { @@ -35,7 +33,7 @@ pub enum Diff { fn check_formatting(file: String) { let content = fs::read_to_string(&file).unwrap(); - let formatted = FormatTask::new(file.clone(), FORMAT_CONFIG.into()).run(); + let formatted = FormatTask::new(file.clone(), formatting::formatted_config()).run(); let mut line_number = 0usize; let mut invalid = false; let differences = diff::lines(&content, &formatted) @@ -94,7 +92,7 @@ fn check_formatting(file: String) { pub fn format(files: Vec) { for file in files { - let mut formatted = FormatTask::new(file.clone(), FORMAT_CONFIG.into()).run(); + let mut formatted = FormatTask::new(file.clone(), formatting::formatted_config()).run(); if !formatted.ends_with('\n') { formatted += "\n"; } diff --git a/src/check/formatting.rs b/src/check/formatting.rs new file mode 100644 index 0000000..01aacda --- /dev/null +++ b/src/check/formatting.rs @@ -0,0 +1,17 @@ +pub type StaticConf = [(&'static str, &'static str)]; + +/// TODO: fill with appropriate rules +pub const FORMAT_CONFIG: &StaticConf = &[ + // (key, value) + ("BasedOnStyle", "GNU"), + ("IndentWidth", "4"), +]; + +pub fn formatted_config() -> String { + let middle = FORMAT_CONFIG + .into_iter() + .map(|(key, value)| format!("{key}: {value}")) + .collect::>() + .join(", "); + format!("{{ {middle} }}") +} diff --git a/src/check/testables.rs b/src/check/testables.rs index a696f19..9226aab 100644 --- a/src/check/testables.rs +++ b/src/check/testables.rs @@ -1,18 +1,12 @@ -fn ends_with_newline(source: String) -> Result<(), String> { - if !source.ends_with('\n') { - Err("source does not end with newline".into()) - } else { - Ok(()) - } -} +pub type RuleResult = Result<(), String>; pub struct Rule { name: String, - test: Box Result<(), String>>, + test: Box RuleResult>, } impl Rule { - pub fn new(name: impl ToString, test: impl 'static + Fn(String) -> Result<(), String>) -> Self { + pub fn new(name: impl ToString, test: impl 'static + Fn(String) -> RuleResult) -> Self { let name = name.to_string(); let test = Box::new(test); Self { name, test } @@ -22,15 +16,32 @@ impl Rule { &self.name } - pub fn test(&self, source: String) -> Result<(), String> { + pub fn test(&self, source: String) -> RuleResult { (self.test)(source) } } +fn ends_with_newline(source: String) -> RuleResult { + if !source.ends_with('\n') { + Err("source does not end with newline".into()) + } else { + Ok(()) + } +} + +fn function_under_50l(source: String) -> RuleResult { + for character in source.chars() { + let c: char = character; + } + + Ok(()) +} + /// TODO: fill with appropriate rules pub fn tests() -> Vec { vec![ // rules Rule::new("ends_with_newline", ends_with_newline), + Rule::new("function_under_50l", function_under_50l), ] } diff --git a/src/main.rs b/src/main.rs index 138d37e..0b44c4b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,6 +84,7 @@ fn append_includes(list: &mut Vec) { fn compilation_args() -> Vec { let mut args = vec![ "-Wall".to_string(), + "-fsanitize=address".to_string(), "-Wextra".to_string(), "-std=c99".to_string(), ]; diff --git a/src/tasks.rs b/src/tasks.rs index 86be5a4..aa17132 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -1,11 +1,11 @@ use std::{ fs, path::PathBuf, - process::{Command, ExitStatus, Stdio}, + process::{exit, Command, ExitStatus, Stdio}, }; use crate::utils::{ - log_command_run, log_separator_bottom, log_separator_top, tmp_file_path, Apply, + log_command_run, log_failure, log_separator_bottom, log_separator_top, tmp_file_path, Apply, }; pub struct CompileTask { @@ -145,10 +145,20 @@ impl FormatTask { .arg(format!("-style={config}")) .stdout(Stdio::piped()) .stderr(Stdio::piped()); - command.status().unwrap(); - let result = command.output().unwrap().stdout; - String::from_utf8(result).unwrap() + let status = command.status().unwrap(); + let out = command.output().unwrap().stdout; + let out = String::from_utf8(out).unwrap(); + let err = command.output().unwrap().stderr; + let err = String::from_utf8(err).unwrap(); + if !status.success() { + log_failure("failed formatting"); + println!("{out}"); + eprintln!("{err}"); + exit(1); + } + + out } } From e188609c18d95e8ad40085405ecece2f7785b90b Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Mon, 17 Oct 2022 23:07:46 +0200 Subject: [PATCH 02/10] written roadmap --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 24cac95..7e8eaa4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Description -A little helper tool meant to ease the developpment of the C piscine at +A little helper tool meant to ease the developpment of the C homeworks at EPITA/Toulouse. ## Usage @@ -19,7 +19,7 @@ OPTIONS: SUBCOMMANDS: check Checks a source file for conformance with piscine limitations help Print this message or the help of the given subcommand(s) - init + init Initializes a project directory configuration, useful for custom flags, includes and custop push messages run Runs a set of files or the default target test Runs tests contained within a particular test file or the default test file watch Watches changes to the project included files and runs a command on changes @@ -34,4 +34,6 @@ SUBCOMMANDS: - [ ] add support and switch on run/test for strict mode. - [ ] add `--` syntax to run subcommand for parameter piping. +- [ ] flag on push to add automatically - [ ] prevent double includes. +- [ ] flag on init to copy personnal environment From 7c6b9c3b2a4aa4782f6eb8e7285fbd70a5603d49 Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Tue, 8 Nov 2022 00:37:27 +0100 Subject: [PATCH 03/10] shameful pile of providencial junk --- README.md | 3 ++- src/check/formatting.rs | 2 +- src/check/testables.rs | 2 +- src/config.rs | 25 +++++++++++++++++++------ src/main.rs | 35 +++++++++++++++++++++++------------ src/run.rs | 3 ++- src/tasks.rs | 21 +++++++++++++++++---- src/test.rs | 12 ++++++++---- src/utils.rs | 14 +++++++++++++- 9 files changed, 86 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 7e8eaa4..51bda8d 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,8 @@ SUBCOMMANDS: ## TODO - [ ] add support and switch on run/test for strict mode. -- [ ] add `--` syntax to run subcommand for parameter piping. +- [x] add `-p` flag to run subcommand with parameter piping. - [ ] flag on push to add automatically - [ ] prevent double includes. - [ ] flag on init to copy personnal environment +- [ ] gc subcommand to free cache diff --git a/src/check/formatting.rs b/src/check/formatting.rs index 01aacda..e47db26 100644 --- a/src/check/formatting.rs +++ b/src/check/formatting.rs @@ -9,7 +9,7 @@ pub const FORMAT_CONFIG: &StaticConf = &[ pub fn formatted_config() -> String { let middle = FORMAT_CONFIG - .into_iter() + .iter() .map(|(key, value)| format!("{key}: {value}")) .collect::>() .join(", "); diff --git a/src/check/testables.rs b/src/check/testables.rs index 9226aab..78c8b21 100644 --- a/src/check/testables.rs +++ b/src/check/testables.rs @@ -31,7 +31,7 @@ fn ends_with_newline(source: String) -> RuleResult { fn function_under_50l(source: String) -> RuleResult { for character in source.chars() { - let c: char = character; + let _c: char = character; } Ok(()) diff --git a/src/config.rs b/src/config.rs index aa65dad..0db4e9e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -63,6 +63,7 @@ impl Config { Self::try_get(&path).or_else(|| path.parent().and_then(Self::get)) } + // get path of the current config file pub fn get_path(path: &Path) -> Option { let path = path.to_path_buf().canonicalize().unwrap(); Self::try_get_path(&path).or_else(|| path.parent().and_then(Self::get_path)) @@ -72,16 +73,28 @@ impl Config { &self.identifier } - pub fn main_file(&self) -> &str { - &self.main_file + pub fn main_file(&self) -> String { + Self::try_absolute(self.main_file.clone()) } - pub fn test_file(&self) -> &str { - &self.test_file + pub fn test_file(&self) -> String { + Self::try_absolute(self.test_file.clone()) } - pub fn includes(&self) -> &Vec { - &self.includes + fn try_absolute(path: String) -> String { + if let Some(conf_path) = Self::get_local_path() { + let dir_path = conf_path.parent().unwrap(); + dir_path.join(path).to_str().unwrap().to_string() + } else { + path + } + } + + pub fn includes(&self) -> Vec { + self.includes + .iter() + .map(|p| Self::try_absolute(p.clone())) + .collect() } pub fn strict_mode(&self) -> bool { diff --git a/src/main.rs b/src/main.rs index 32db48a..426d6a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,8 +35,13 @@ pub enum Commands { /// Runs a set of files or the default target. run { + // disables fsanitize + #[clap(short, long)] + disable_sanitize: bool, /// Files to run. files: Vec, + #[clap(short, long)] + pass: Vec, }, /// Runs tests contained within a particular test file or the default test file. @@ -84,16 +89,17 @@ fn append_includes(list: &mut Vec) { ); } -fn compilation_args() -> Vec { +fn compilation_args(sanitize: bool) -> Vec { let mut args = vec![ "-Wall".to_string(), - "-fsanitize=address".to_string(), "-Wextra".to_string(), "-std=c99".to_string(), "-g".to_string(), - "-fsanitize=address".to_string(), - // "-pedantic".to_string(), + "-pedantic".to_string(), ]; + if sanitize { + args.push("-fsanitize=address".to_string()) + } if Config::get_local_or_default().strict_mode() { args.push("-Werror".to_string()); } @@ -108,13 +114,17 @@ fn main() { Commands::format { files } => check::format(files), - Commands::run { mut files } => { + Commands::run { + disable_sanitize, + mut files, + pass, + } => { if files.is_empty() { - files.push(Config::get_local_or_default().main_file().to_string()); + files.push(Config::get_local_or_default().main_file()); } append_includes(&mut files); - let args = compilation_args(); - run::main(files, args); + let args = compilation_args(!disable_sanitize); + run::main(files, args, pass); } Commands::test { @@ -123,11 +133,12 @@ fn main() { // tests, } => { if files.is_empty() { - files.push(Config::get_local_or_default().test_file().to_string()); + files.push(Config::get_local_or_default().test_file()); } - append_includes(&mut files); - let args = compilation_args(); - test::main(capture, files, args) + let mut includes = vec![]; + append_includes(&mut includes); + let args = compilation_args(true); + test::main(capture, files, includes, args) } Commands::watch { command, files } => { let mut files = files.unwrap_or_default(); diff --git a/src/run.rs b/src/run.rs index f6dc3c8..7c3572f 100644 --- a/src/run.rs +++ b/src/run.rs @@ -3,7 +3,7 @@ use crate::{ utils::{log_failure, log_process}, }; -pub fn main(files: Vec, flags: Vec) -> Option<()> { +pub fn main(files: Vec, flags: Vec, passed: Vec) -> Option<()> { let source_file = files.into_iter().map(|f| f.into()).collect(); log_process("compiling"); let mut task = CompileTask::new(source_file); @@ -19,6 +19,7 @@ pub fn main(files: Vec, flags: Vec) -> Option<()> { log_process("running"); RunTask::new(compiled) + .with_args(passed) .run() .map(Option::from) .unwrap_or_else(|_| { diff --git a/src/tasks.rs b/src/tasks.rs index ff2eaaf..759875a 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -5,7 +5,8 @@ use std::{ }; use crate::utils::{ - log_command_run, log_failure, log_separator_bottom, log_separator_top, tmp_file_path, Apply, + log_command_run, log_failure, log_separator_bottom, log_separator_top, remove_dupes, + tmp_file_path, Apply, }; pub struct CompileTask { @@ -55,13 +56,18 @@ impl CompileTask { } pub fn compile(&self, sources: Vec) -> Result { + let mut sources = sources + .iter() + .map(|s| s.to_str().unwrap().to_string()) + .collect(); + remove_dupes(&mut sources); let output_path = tmp_file_path().apply(|o| o.set_extension("b")); let output_path_ref = output_path.to_str().unwrap(); let mut command = Command::new("gcc"); command .args(["-o", output_path_ref]) .args(self.flags.clone()) - .args(sources.iter().map(|s| s.to_str().unwrap())); + .args(sources); if self.verbose { log_command_run(&command); log_separator_top(); @@ -77,6 +83,7 @@ impl CompileTask { pub struct RunTask { file: PathBuf, verbose: bool, + args: Vec, } impl RunTask { @@ -84,17 +91,23 @@ impl RunTask { Self { file, verbose: false, + args: vec![], } } + pub fn with_args(mut self, mut args: Vec) -> Self { + self.args.append(&mut args); + self + } + pub fn with_verbose(mut self) -> Self { self.verbose = true; self } pub fn run(self) -> Result<(), ExitStatus> { - let mut command = Command::new("sh"); - command.args(["-c", self.file.to_str().unwrap()]); + let mut command = Command::new(self.file.to_str().unwrap()); + command.args(self.args); if self.verbose { log_command_run(&command); log_separator_top(); diff --git a/src/test.rs b/src/test.rs index 23576d1..5264cd8 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,13 +1,14 @@ -use std::{fs, thread, time::Duration}; +use std::{fs, path::PathBuf, thread, time::Duration}; use crate::{ tasks::{CompileTask, GenTask, RunTask}, utils::{log_failure, log_process, log_success}, }; -pub fn main(_capture: bool, files: Vec, args: Vec) { +pub fn main(_capture: bool, test_files: Vec, includes: Vec, args: Vec) { log_process("testing"); - for path in files { + let includes: Vec<_> = includes.into_iter().map(PathBuf::from).collect(); + for path in test_files { let content = fs::read_to_string(&path).unwrap(); let tests = find_tests(content); for test in tests { @@ -18,7 +19,10 @@ pub fn main(_capture: bool, files: Vec, args: Vec) { thread::sleep(Duration::from_millis(100)); // compile with all files - let mut task = CompileTask::new(vec![generated_code]); + let mut files = vec![generated_code]; + let mut local_includes = includes.clone(); + files.append(&mut local_includes); + let mut task = CompileTask::new(files); for flag in args.clone() { task = task.with_flag(flag); } diff --git a/src/utils.rs b/src/utils.rs index c09bbe3..c68da8d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,4 @@ -use std::{fs, path::PathBuf, process::Command}; +use std::{collections::HashSet, fs, mem::swap, path::PathBuf, process::Command}; use chrono::Utc; use termion::color; @@ -97,3 +97,15 @@ pub fn log_error(input: impl AsRef) { log_pi_prefix(); println!("error: {input}"); } + +pub fn remove_dupes(input: &mut Vec) { + let mut tmp = vec![]; + swap(input, &mut tmp); + let mut set = HashSet::new(); + for str in tmp { + set.insert(str); + } + for str in set { + input.push(str); + } +} From 7958763bd4b1eeb230350504569d76e8c377613d Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Tue, 8 Nov 2022 00:39:41 +0100 Subject: [PATCH 04/10] updated dependencies, version bump --- Cargo.lock | 6 +++--- Cargo.toml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e5dd17a..fe47473 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,7 +138,7 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "epitls-pi" -version = "1.3.1" +version = "1.4.0" dependencies = [ "chrono", "clap", @@ -475,9 +475,9 @@ dependencies = [ [[package]] name = "termion" -version = "1.5.6" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" +checksum = "659c1f379f3408c7e5e84c7d0da6d93404e3800b6b9d063ba24436419302ec90" dependencies = [ "libc", "numtoa", diff --git a/Cargo.toml b/Cargo.toml index 0f404f3..8136546 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "epitls-pi" -version = "1.3.1" +version = "1.4.0" edition = "2021" license = "GPL-3.0+" description = "A little helper tool meant to ease the developpment of the C piscine at EPITA/Toulouse." @@ -22,7 +22,7 @@ notify = "5.0" notify-debouncer-mini = "0.2" ron = "0.8" serde = { version = "1.0", features = ["derive"] } -termion = "1.5" +termion = "2.0" [profile.release] lto = true From ad18c69f28bb1d3a783f55090f65ac7d6f69538c Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Sun, 20 Nov 2022 01:49:15 +0100 Subject: [PATCH 05/10] fixed empty unit bug --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/tasks.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe47473..4366547 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,7 +138,7 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "epitls-pi" -version = "1.4.0" +version = "1.4.1" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 8136546..136ea53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "epitls-pi" -version = "1.4.0" +version = "1.4.1" edition = "2021" license = "GPL-3.0+" description = "A little helper tool meant to ease the developpment of the C piscine at EPITA/Toulouse." diff --git a/src/tasks.rs b/src/tasks.rs index 759875a..3ab3fd1 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -42,9 +42,9 @@ impl CompileTask { } pub fn run(self) -> Result { - let proc_source = self.gen_source(); - let mut sources = self.files.clone(); - sources.push(proc_source); + // let proc_source = self.gen_source(); + let sources = self.files.clone(); + // sources.push(proc_source); self.compile(sources) } From 058ea6a2f005401b9ed3223d299b90838bc7989a Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Wed, 4 Jan 2023 15:54:36 +0100 Subject: [PATCH 06/10] added support for globs in pi.ron --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/config.rs | 10 ++++++++++ src/main.rs | 11 ++++------- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4366547..39a505d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,7 +138,7 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "epitls-pi" -version = "1.4.1" +version = "1.5.0" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 136ea53..21a8b9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "epitls-pi" -version = "1.4.1" +version = "1.5.0" edition = "2021" license = "GPL-3.0+" description = "A little helper tool meant to ease the developpment of the C piscine at EPITA/Toulouse." diff --git a/src/config.rs b/src/config.rs index 0db4e9e..f13f95d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -94,6 +94,16 @@ impl Config { self.includes .iter() .map(|p| Self::try_absolute(p.clone())) + .flat_map(|p| { + if p.contains('*') { + glob::glob(&p) + .unwrap() + .map(|p| p.unwrap().to_str().unwrap().to_string()) + .collect() + } else { + vec![p] + } + }) .collect() } diff --git a/src/main.rs b/src/main.rs index 426d6a1..547288f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -use std::env; - use clap::{Parser, Subcommand}; use config::Config; @@ -67,10 +65,10 @@ pub enum Commands { /// Initializes a project directory configuration, useful for custom flags, includes and custop push messages. init { - /// Identifier for the automated tests. - prefix: String, /// Path to the folder containing the project. - path: Option, + path: String, + /// Identifier for the automated tests. + prefix: Option, /// e #[clap(short, long)] tests: bool, @@ -151,8 +149,7 @@ fn main() { prefix, tests, } => { - let path = - path.unwrap_or_else(|| env::current_dir().unwrap().to_str().unwrap().to_string()); + let prefix = prefix.unwrap_or_else(|| ".".to_string()); let prefix = prefix.trim().trim_end_matches('*'); config::create(path.clone(), prefix.to_string()); if tests { From 96e984244b19cbf28f5f755078a854a5a0e5c330 Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Wed, 4 Jan 2023 19:38:48 +0100 Subject: [PATCH 07/10] colored command logs on compilation --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/tasks.rs | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39a505d..9c9e4bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,7 +138,7 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "epitls-pi" -version = "1.5.0" +version = "1.5.1" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 21a8b9c..ea4d1b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "epitls-pi" -version = "1.5.0" +version = "1.5.1" edition = "2021" license = "GPL-3.0+" description = "A little helper tool meant to ease the developpment of the C piscine at EPITA/Toulouse." diff --git a/src/tasks.rs b/src/tasks.rs index 3ab3fd1..7bc307a 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -4,6 +4,8 @@ use std::{ process::{exit, Command, ExitStatus, Stdio}, }; +use termion::color; + use crate::utils::{ log_command_run, log_failure, log_separator_bottom, log_separator_top, remove_dupes, tmp_file_path, Apply, @@ -72,6 +74,11 @@ impl CompileTask { log_command_run(&command); log_separator_top(); } + println!( + "{}{command:?}{}", + color::Fg(color::AnsiValue(8)), + color::Fg(color::Reset) + ); let status = command.status().unwrap(); if self.verbose { log_separator_bottom(); From 77f0a9b9a39bfe14cd9864f36bb0d4cfe44b096b Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Wed, 11 Jan 2023 16:47:17 +0100 Subject: [PATCH 08/10] now ignores previous definitions of main in tests --- src/test.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test.rs b/src/test.rs index 5264cd8..d8f7e04 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,12 +1,14 @@ use std::{fs, path::PathBuf, thread, time::Duration}; use crate::{ + config::Config, tasks::{CompileTask, GenTask, RunTask}, utils::{log_failure, log_process, log_success}, }; pub fn main(_capture: bool, test_files: Vec, includes: Vec, args: Vec) { log_process("testing"); + let main_file = Config::get_local_or_default().main_file(); let includes: Vec<_> = includes.into_iter().map(PathBuf::from).collect(); for path in test_files { let content = fs::read_to_string(&path).unwrap(); @@ -20,7 +22,7 @@ pub fn main(_capture: bool, test_files: Vec, includes: Vec, args // compile with all files let mut files = vec![generated_code]; - let mut local_includes = includes.clone(); + let mut local_includes = includes.clone(); // TODO : filter out current test : already included files.append(&mut local_includes); let mut task = CompileTask::new(files); for flag in args.clone() { @@ -58,6 +60,8 @@ int main(int argc, char** argv) {{ return 0; }} +#define main __pi_hidden_main + #include \"{path}\" void __pi_test() {{ From 851593ee55f859e5b9150466f741becfabc977ed Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Wed, 11 Jan 2023 16:47:48 +0100 Subject: [PATCH 09/10] version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c9e4bb..8f89719 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,7 +138,7 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "epitls-pi" -version = "1.5.1" +version = "1.5.2" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index ea4d1b8..177b2f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "epitls-pi" -version = "1.5.1" +version = "1.5.2" edition = "2021" license = "GPL-3.0+" description = "A little helper tool meant to ease the developpment of the C piscine at EPITA/Toulouse." From cf316fe012a7df0ca0365fdb6387a37349d40775 Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Wed, 11 Jan 2023 16:48:23 +0100 Subject: [PATCH 10/10] removed warnings --- src/test.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test.rs b/src/test.rs index d8f7e04..ed4cac6 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,14 +1,12 @@ use std::{fs, path::PathBuf, thread, time::Duration}; use crate::{ - config::Config, tasks::{CompileTask, GenTask, RunTask}, utils::{log_failure, log_process, log_success}, }; pub fn main(_capture: bool, test_files: Vec, includes: Vec, args: Vec) { log_process("testing"); - let main_file = Config::get_local_or_default().main_file(); let includes: Vec<_> = includes.into_iter().map(PathBuf::from).collect(); for path in test_files { let content = fs::read_to_string(&path).unwrap();