Skip to content

Commit 9c3d67d

Browse files
committed
fix unittest
1 parent 813dc4a commit 9c3d67d

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/stash.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ extern "C" fn stash_apply_progress_cb(
216216
mod tests {
217217
use crate::stash::{StashApplyOptions, StashSaveOptions};
218218
use crate::test::repo_init;
219-
use crate::{Repository, StashFlags, Status};
219+
use crate::{IndexAddOption, Repository, StashFlags, Status};
220220
use std::fs;
221221
use std::io::Write;
222-
use std::path::Path;
222+
use std::path::{Path, PathBuf};
223223

224224
fn make_stash<C>(next: C)
225225
where
@@ -322,30 +322,39 @@ mod tests {
322322
assert!(stash_name.starts_with("WIP on main:"));
323323
}
324324

325+
fn create_file(r: &Repository, name: &str, data: &str) -> PathBuf {
326+
let p = Path::new(r.workdir().unwrap()).join(name);
327+
fs::File::create(&p)
328+
.unwrap()
329+
.write(data.as_bytes())
330+
.unwrap();
331+
p
332+
}
333+
325334
#[test]
326335
fn test_stash_save_ext() {
327336
let (_td, mut repo) = repo_init();
328337
let signature = repo.signature().unwrap();
329338

330-
let path_a = Path::new(repo.workdir().unwrap()).join("file_a");
331-
fs::File::create(&path_a)
332-
.unwrap()
333-
.write("data".as_bytes())
334-
.unwrap();
339+
create_file(&repo, "file_a", "foo");
340+
create_file(&repo, "file_b", "foo");
335341

336-
let path_b = Path::new(repo.workdir().unwrap()).join("file_b");
337-
fs::File::create(&path_b)
338-
.unwrap()
339-
.write("data".as_bytes())
342+
let mut index = repo.index().unwrap();
343+
index
344+
.add_all(["*"].iter(), IndexAddOption::DEFAULT, None)
340345
.unwrap();
346+
index.write().unwrap();
341347

342348
assert_eq!(repo.statuses(None).unwrap().len(), 2);
343349

344350
let mut opt = StashSaveOptions::new(signature);
345351
opt.pathspec("file_a");
346-
opt.flags(Some(StashFlags::INCLUDE_UNTRACKED));
347352
repo.stash_save_ext(Some(&mut opt)).unwrap();
348353

354+
assert_eq!(repo.statuses(None).unwrap().len(), 0);
355+
356+
repo.stash_pop(0, None).unwrap();
357+
349358
assert_eq!(repo.statuses(None).unwrap().len(), 1);
350359
}
351360
}

0 commit comments

Comments
 (0)