Skip to content

Commit

Permalink
Consolidate uses of test-case to rstest (nushell#14250)
Browse files Browse the repository at this point in the history
With nushell#14083 a dependency on `test-case` was introduced, we already
depend on the more exp(a/e)nsive `rstest` for our macro-based test case
generation (with fixtures on top)

To save on some compilation for proc macros unify to `rstest`
  • Loading branch information
sholderbach authored Nov 4, 2024
1 parent 9f09930 commit e172a62
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 49 deletions.
34 changes: 0 additions & 34 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions crates/nu-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ nu-command = { path = "../nu-command", version = "0.99.2" }
nu-test-support = { path = "../nu-test-support", version = "0.99.2" }
rstest = { workspace = true, default-features = false }
tempfile = { workspace = true }
test-case = "3.3.1"

[dependencies]
nu-cmd-base = { path = "../nu-cmd-base", version = "0.99.2" }
Expand Down Expand Up @@ -49,4 +48,4 @@ plugin = ["nu-plugin-engine"]
system-clipboard = ["reedline/system_clipboard"]

[lints]
workspace = true
workspace = true
15 changes: 6 additions & 9 deletions crates/nu-cli/src/commands/history/history_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fn backup(path: &Path) -> Result<Option<PathBuf>, ShellError> {
#[cfg(test)]
mod tests {
use chrono::DateTime;
use test_case::case;
use rstest::rstest;

use super::*;

Expand Down Expand Up @@ -378,14 +378,11 @@ mod tests {
Value::record(rec, span)
}

#[case(&["history.dat"], "history.dat.bak"; "no_backup")]
#[case(&["history.dat", "history.dat.bak"], "history.dat.bak.1"; "backup_exists")]
#[case(
&["history.dat", "history.dat.bak", "history.dat.bak.1"],
"history.dat.bak.2";
"multiple_backups_exists"
)]
fn test_find_backup_path(existing: &[&str], want: &str) {
#[rstest]
#[case::no_backup(&["history.dat"], "history.dat.bak")]
#[case::backup_exists(&["history.dat", "history.dat.bak"], "history.dat.bak.1")]
#[case::multiple_backups_exists( &["history.dat", "history.dat.bak", "history.dat.bak.1"], "history.dat.bak.2")]
fn test_find_backup_path(#[case] existing: &[&str], #[case] want: &str) {
let dir = tempfile::tempdir().unwrap();
for name in existing {
std::fs::File::create_new(dir.path().join(name)).unwrap();
Expand Down
9 changes: 5 additions & 4 deletions crates/nu-cli/tests/commands/history_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use reedline::{
FileBackedHistory, History, HistoryItem, HistoryItemId, ReedlineError, SearchQuery,
SqliteBackedHistory,
};
use rstest::rstest;
use tempfile::TempDir;
use test_case::case;

struct Test {
cfg_dir: TempDir,
Expand Down Expand Up @@ -251,9 +251,10 @@ fn to_empty_sqlite() {
.run()
}

#[case(HistoryFileFormat::Plaintext; "plaintext")]
#[case(HistoryFileFormat::Sqlite; "sqlite")]
fn to_existing(dst_format: HistoryFileFormat) {
#[rstest]
#[case::plaintext(HistoryFileFormat::Plaintext)]
#[case::sqlite(HistoryFileFormat::Sqlite)]
fn to_existing(#[case] dst_format: HistoryFileFormat) {
TestCase {
dst_format,
dst_history: vec![
Expand Down

0 comments on commit e172a62

Please sign in to comment.