Skip to content

Commit

Permalink
Add support for skins and use for better color capability handling ac…
Browse files Browse the repository at this point in the history
…ross terminals (#8)

* Initial implementation of skins
* Improve color handling across different terminal types and color support
* Change test dir structure for better coverage and update tests accordingly
* Add coverage arg to specify files to exclude. Update coverage workflow with args
* Update PR template
* Change lint and test workflow to not run on PR as they already run as a result of the push
  • Loading branch information
emilevr committed Nov 11, 2023
1 parent 2772085 commit 577bf0d
Show file tree
Hide file tree
Showing 29 changed files with 905 additions and 297 deletions.
8 changes: 4 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
## Describe your changes
> **TIP**: Use the `Preview` tab to more easily read these notes. Remember to delete all the notes before you submit the PR.
> :construction_worker: Use bullet points to list the major changes or any change you feel is relevant.
> :construction_worker: DELETE THIS NOTE
-

## Issue ticket number(s) and link(s)
> :bulb: List any linked issues here by using the keywords and format described [here](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
> :construction_worker: DELETE THIS NOTE
-

> :construction_worker: Delete this whole section if this PR is not related to any open issues.
> :construction_worker: DELETE THIS NOTE
-

## PR requirements
> :exclamation: The following requirements must be met otherwise this PR will not be accepted:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ jobs:
tmux new-session -d -s tests -x 200 -y 20
# Send the command to run the tests with code coverage.
tmux send-keys -t tests 'buildit coverage --include-ignored ; tmux wait -S tests-finished' Enter
# - We exclude src/main.rs as it is fully covered, but some of the non-test code is incorrectly
# covered as well.
# - We exlude src/logging.rs as it is fully covered but the percentage is calculated
# incorrectly by grcov.
tmux send-keys -t tests 'buildit coverage --include-ignored --exclude-files src/main.rs src/logging.rs ; tmux wait -S tests-finished' Enter
# Wait for the tests-finished signal.
tmux wait-for tests-finished
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Lint
on:
pull_request:
push:
branches-ignore:
- ' '
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Test
on:
pull_request:
push:
branches-ignore:
- ' '
Expand Down
103 changes: 103 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 @@ -72,6 +72,7 @@ bumpalo-herd = "^0.1.2"
criterion = "^0.5.1"
id-arena = { version = "^2.2.1", features = ["rayon"] }
memory-stats = "^1.1.0"
mockall = "0.11.4"
regex = "^1.9.5"
rstest = "^0.18.2"
uuid = { version = "^1.4.1", features = ["v4"] }
3 changes: 2 additions & 1 deletion buildit/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::command::BuildItCommand;

#[derive(Args, Debug)]
pub struct BenchmarkCommandArgs {
/// One or more optional benchmarks to run. If not specified then all benchmarks will be run.
/// One or more optional benchmarks to run. If not specified then all benchmarks will be run. Separate
/// multiple names using spaces.
#[arg(long = "bench-names", value_parser, num_args = 1.., value_delimiter = ' ')]
pub bench_names: Option<Vec<String>>,
}
Expand Down
75 changes: 35 additions & 40 deletions buildit/src/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ pub struct CoverageCommandArgs {
#[arg(long = "package")]
pub package: Option<String>,

/// Optionally run only the ignored tests
#[arg(long = "ignored", default_value_t = false)]
pub ignored: bool,
/// One or more glob patterns of files to exclude from coverage. Separate multiple glob patterns using spaces.
#[arg(long = "exclude-files", value_parser, num_args = 1.., value_delimiter = ' ')]
pub exclude_file_globs: Option<Vec<String>>,

/// Optionally include the ignored tests
#[arg(long = "include-ignored", default_value_t = false)]
Expand All @@ -51,17 +51,17 @@ pub struct CoverageCommandArgs {
pub struct CoverageCommand {
output_types: Option<Vec<CoverageReportType>>,
package: Option<String>,
ignored: bool,
include_ignored: bool,
exclude_file_globs: Option<Vec<String>>,
}

impl CoverageCommand {
pub fn new(args: CoverageCommandArgs) -> Self {
CoverageCommand {
output_types: args.output_types,
package: args.package,
ignored: args.ignored,
include_ignored: args.include_ignored,
exclude_file_globs: args.exclude_file_globs,
}
}
}
Expand Down Expand Up @@ -90,13 +90,9 @@ impl BuildItCommand for CoverageCommand {
args.push(package);
}
// Now the test params, i.e. after a '--' in the params.
if self.include_ignored || self.ignored {
if self.include_ignored {
args.push("--");
if self.ignored {
args.push("--ignored");
} else if self.include_ignored {
args.push("--include-ignored");
}
args.push("--include-ignored");
}
cmd("cargo", args)
.env("RUSTFLAGS", "-Cinstrument-coverage")
Expand All @@ -114,18 +110,15 @@ impl BuildItCommand for CoverageCommand {
_ => "html,lcov".to_string(),
};

// Call grcov, which has to be available on the path.
cmd!(
"grcov",
".",
"--binary-path",
format!("{}/debug/deps", target_coverage_dir),
"-s",
let output_path_string = output_path.to_string_lossy().to_string();
let bin_path = format!("{}/debug/deps", target_coverage_dir);

#[rustfmt::skip]
let mut grcov_args = vec![
".",
"-t",
output_types,
"--branch",
"--excl-line",
"--binary-path", bin_path.as_str(),
"-s", ".",
"-t", output_types.as_str(),
// Exclude the following lines:
// ^\\s*(debug_)?assert(_eq|_ne)?! => debug_assert and assert variants
// ^\\s*#\\[.*$ => lines containing only an attribute
Expand All @@ -142,6 +135,7 @@ impl BuildItCommand for CoverageCommand {
// ^\\s*impl(<.*>)?\\s*[^ ]+\\s*\\{\\s*$ => lines containing only an impl declaration
// ^\\s*impl(<.*>)?\\s*[^ ]+\\s+for\\s+[^ ]*\\s*\\{\\s*$ => lines containing only an impl for declaration
// ^\\s*(pub|pub\\s*\\(\\s*crate\\s*\\)\\s*)?\\s*const\\s+.*\\s*[(){}]*\\s*$ => lines containing only a const definition
"--excl-line",
"^\\s*(debug_)?assert(_eq|_ne)?!\
|^\\s*#\\[.*$\
|^\\s*#!\\[.*$\
Expand All @@ -159,24 +153,25 @@ impl BuildItCommand for CoverageCommand {
|^\\s*impl(<.*>)?\\s*[^ ]+\\s+for\\s+[^ ]*\\s*\\{\\s*$\
|^\\s*(pub|pub\\s*\\(\\s*crate\\s*\\)\\s*)?\\s*const\\s+.*\\s*[(){}]*\\s*$",
"--ignore-not-existing",
"--ignore",
"buildit/*",
"--ignore",
"src/tests/*",
"--ignore",
"src/benches/*",
"--ignore",
"**/*_test.rs",
"--ignore",
"**/test_*.rs",
"--ignore",
"**/*_test_*.rs",
"--ignore",
"**/.cargo/registry/*",
"-o",
&output_path,
)
.run()?;
"--keep-only", "src/*",
"--ignore", "src/tests/*",
"--ignore", "src/benches/*",
"--ignore", "**/*_test.rs",
"--ignore", "**/test_*.rs",
"--ignore", "**/*_test_*.rs",
"--ignore", "**/.cargo/*",
"-o", output_path_string.as_str(),
];

if let Some(exclude_file_globs) = &self.exclude_file_globs {
exclude_file_globs.iter().for_each(|glob| {
grcov_args.push("--ignore");
grcov_args.push(glob);
});
}

// Call grcov, which has to be available on the path.
cmd("grcov", grcov_args).run()?;
output_path.push("html");
output_path.push("index.html");
println!(
Expand Down
2 changes: 1 addition & 1 deletion buildit/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct VersionCommandArgs {
pub pre_release_name: String,

/// One or more glob patterns used to find Cargo.toml manifests, which will be updated to the calculated
/// version.
/// version. Separate multiple globs using spaces.
#[arg(
short = 'm',
long = "manifest-globs",
Expand Down
Loading

0 comments on commit 577bf0d

Please sign in to comment.