Skip to content

Commit

Permalink
toolkit: use --features instead of --dataframe and refactor a bit (
Browse files Browse the repository at this point in the history
…nushell#9425)

related to
- nushell#9357

# Description
with the new `extra` feature introduce in the `toolkit.nu` module in
nushell#9357, the `--dataframe` option
does not make sense anymore...

this PR changes that and replaces it with `--features: list<string>`.
this has the benefit of simplifying the commands because we can just
pass `--features ($features | str join ",")` to the `cargo` commands
regardless of whether the `$features` list is empty of not 👌

i've also refactored a bit the module:
- break the long `error make -u` lines
- break the long `cargo clippy` command

# User-Facing Changes
devs can now choose which feature to test with the `toolkit` commands.

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- ⚫ `toolkit test`
- ⚫ `toolkit test stdlib`

# After Submitting
```
$nothing
```
  • Loading branch information
amtoine committed Jun 18, 2023
1 parent fa957a1 commit 6af9fe5
Showing 1 changed file with 43 additions and 27 deletions.
70 changes: 43 additions & 27 deletions toolkit.nu
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export def fmt [
try {
cargo fmt --all -- --check
} catch {
error make -u { msg: $"\nplease run ('toolkit fmt' | pretty-print-command) to fix formatting!" }
error make --unspanned {
msg: $"\nplease run ('toolkit fmt' | pretty-print-command) to fix formatting!"
}
}
} else {
cargo fmt --all
Expand All @@ -31,36 +33,56 @@ export def fmt [
# > it is important to make `clippy` happy :relieved:
export def clippy [
--verbose: bool # print extra information about the command's progress
--dataframe: bool # use the dataframe feature
--features: list<string> # the list of features to run *Clippy* on
--workspace: bool # run the *Clippy* command on the whole workspace (overrides `--features`)
] {
if $verbose {
print $"running ('toolkit clippy' | pretty-print-command)"
}

try {
if $dataframe {
cargo clippy --workspace --features=dataframe,extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err
} else {
cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err
}
if $workspace {(
cargo clippy
--workspace
--
-D warnings
-D clippy::unwrap_used
-A clippy::needless_collect
-A clippy::result_large_err
)} else {(
cargo clippy
--features ($features | str join ",")
--
-D warnings
-D clippy::unwrap_used
-A clippy::needless_collect
-A clippy::result_large_err
)}
} catch {
error make -u { msg: $"\nplease fix the above ('clippy' | pretty-print-command) errors before continuing!" }
error make --unspanned {
msg: $"\nplease fix the above ('clippy' | pretty-print-command) errors before continuing!"
}
}
}

# check that all the tests pass
export def test [
--fast: bool # use the "nextext" `cargo` subcommand to speed up the tests (see [`cargo-nextest`](https://nexte.st/) and [`nextest-rs/nextest`](https://github.com/nextest-rs/nextest))
--dataframe: bool # use the dataframe feature
--features: list<string> # the list of features to run the tests on
--workspace: bool # run the *Clippy* command on the whole workspace (overrides `--features`)
] {
if ($fast and $dataframe) {
cargo nextest run --all --features=dataframe,extra
} else if ($fast) {
cargo nextest run --all
} else if ($dataframe) {
cargo test --workspace --features=dataframe,extra
if $fast {
if $workspace {
cargo nextest run --all
} else {
cargo nextest run --features ($features | str join ",")
}
} else {
cargo test --workspace
if $workspace {
cargo test --workspace
} else {
cargo test --features ($features | str join ",")
}
}
}

Expand Down Expand Up @@ -208,7 +230,7 @@ def report [
# now the whole `toolkit check pr` passes! :tada:
export def "check pr" [
--fast: bool # use the "nextext" `cargo` subcommand to speed up the tests (see [`cargo-nextest`](https://nexte.st/) and [`nextest-rs/nextest`](https://github.com/nextest-rs/nextest))
--dataframe: bool # use the dataframe feature
--features: list<string> # the list of features to check the current PR on
] {
let-env NU_TEST_LOCALE_OVERRIDE = 'en_US.utf8';
try {
Expand All @@ -218,23 +240,17 @@ export def "check pr" [
}

try {
if $dataframe {
clippy --dataframe --verbose
} else {
clippy --verbose
}
clippy --features $features --verbose
} catch {
return (report --fail-clippy)
}

print $"running ('toolkit test' | pretty-print-command)"
try {
if $fast and $dataframe {
test --fast --dataframe
} else if $fast {
test --fast
if $fast {
test --features $features --fast
} else {
test
test --features $features
}
} catch {
return (report --fail-test)
Expand Down

0 comments on commit 6af9fe5

Please sign in to comment.