Skip to content

Commit 388910f

Browse files
committed
Add a straight forward test
1 parent 4645429 commit 388910f

File tree

1 file changed

+66
-10
lines changed

1 file changed

+66
-10
lines changed

tests/basic.rs

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,52 @@ new
7171
);
7272
}
7373

74+
#[test]
75+
fn simple_straightline_commits() {
76+
let td = assert_fs::TempDir::new().unwrap();
77+
git_init(&td);
78+
79+
for n in &["a", "b"] {
80+
git_file_commit(n, &td);
81+
}
82+
git(&["checkout", "-b", "changes"], &td);
83+
git(&["branch", "-u", "main"], &td);
84+
for n in &["target", "d"] {
85+
git_file_commit(&n, &td);
86+
}
87+
88+
let log = git_log(&td);
89+
assert_eq!(
90+
log,
91+
"\
92+
* d HEAD -> changes
93+
* target
94+
* b main
95+
* a
96+
",
97+
"log:\n{}",
98+
log
99+
);
100+
101+
td.child("new").touch().unwrap();
102+
git(&["add", "new"], &td);
103+
104+
fixup(&td).args(&["-P", "target"]).assert().success();
105+
106+
let (files, err) = git_changed_files("target", &td);
107+
108+
assert_eq!(
109+
files,
110+
"\
111+
file_target
112+
new
113+
",
114+
"out: {} err: {}",
115+
files,
116+
err
117+
);
118+
}
119+
74120
#[test]
75121
fn test_no_commit_in_range() {
76122
let td = assert_fs::TempDir::new().unwrap();
@@ -81,7 +127,7 @@ fn test_no_commit_in_range() {
81127
}
82128
git(&["checkout", "-b", "changes", ":/c"], &td);
83129
git(&["branch", "-u", "main"], &td);
84-
for n in &["e", "f", "g"] {
130+
for n in &["target", "f", "g"] {
85131
git_file_commit(&n, &td);
86132
}
87133

@@ -91,7 +137,7 @@ fn test_no_commit_in_range() {
91137
"\
92138
* g HEAD -> changes
93139
* f
94-
* e
140+
* target
95141
| * d main
96142
|/
97143
* c
@@ -109,19 +155,14 @@ fn test_no_commit_in_range() {
109155
let out = string(assertion.get_output().stdout.clone());
110156
assert!(out.contains("No commit contains the pattern"), out);
111157

112-
fixup(&td).args(&["-P", "e"]).assert().success();
158+
fixup(&td).args(&["-P", "target"]).assert().success();
113159

114-
let shown = git_out(
115-
&["diff-tree", "--no-commit-id", "--name-only", "-r", ":/e"],
116-
&td,
117-
);
118-
let files = string(shown.stdout);
119-
let err = string(shown.stderr);
160+
let (files, err) = git_changed_files("target", &td);
120161

121162
assert_eq!(
122163
files,
123164
"\
124-
file_e
165+
file_target
125166
new
126167
",
127168
"out: {} err: {}",
@@ -146,6 +187,21 @@ fn git_file_commit(name: &str, tempdir: &assert_fs::TempDir) {
146187
git(&["commit", "-m", &name], &tempdir);
147188
}
148189

190+
/// Get the git shown output for the target commit
191+
fn git_changed_files(name: &str, tempdir: &assert_fs::TempDir) -> (String, String) {
192+
let out = git_out(
193+
&[
194+
"diff-tree",
195+
"--no-commit-id",
196+
"--name-only",
197+
"-r",
198+
&format!(":/{}", name),
199+
],
200+
&tempdir,
201+
);
202+
(string(out.stdout), string(out.stderr))
203+
}
204+
149205
/// Run git in tempdir with args and panic if theres an error
150206
fn git(args: &[&str], tempdir: &assert_fs::TempDir) {
151207
git_inner(args, tempdir).ok().unwrap();

0 commit comments

Comments
 (0)