[git] cherry-pick test refactoring:

move creation of conflicting commits into from background into scenarios: easier to refer from these scenarios, less to execute for scenarios that don't need these commits.
This commit is contained in:
Kirill Likhodedov
2013-01-02 17:23:28 +04:00
parent 45f001f7ad
commit b3a3d8583c
3 changed files with 118 additions and 27 deletions
@@ -2,13 +2,10 @@ Feature: Git Cherry-Pick When Auto-Commit is selected
Background:
Given enabled auto-commit in the settings
Given new committed file file.txt 'initial'
And new committed file f2.txt 'initial'
And new committed file conflict.txt 'initial content for conflict'
Given new committed files file.txt, a.txt, conflict.txt with initial content
Given branch feature
And commit f5027a3 on branch feature
Given commit f5027a3 on branch feature
"""
fix #1
-----
@@ -17,23 +14,6 @@ Background:
M file.txt "feature changes"
"""
# conflicting commits
Given commit aff6453 on branch master
"""
master content
-----
Changes:
M conflict.txt "master version"
"""
Given commit bb6453c on branch feature
"""
feature content
-----
Changes:
M conflict.txt "feature version"
"""
Scenario: Simple cherry-pick
When I cherry-pick the commit f5027a3
Then the last commit is
@@ -50,7 +30,8 @@ Background:
Scenario: Dirty tree, conflicting with the commit
Given file.txt is locally modified:
"""
master content"""
master content
"""
When I cherry-pick the commit f5027a3
Then nothing is committed
And error notification is shown 'Cherry-pick failed'
@@ -79,10 +60,38 @@ Background:
"""
Scenario: Conflict with cherry-picked commit should show merge dialog
Given commit aff6453 on branch master
"""
master content
-----
Changes:
M conflict.txt "master version"
"""
Given commit bb6453c on branch feature
"""
feature content
-----
Changes:
M conflict.txt "feature version"
"""
When I cherry-pick the commit bb6453c
Then merge dialog should be shown
Scenario: Unresolved conflict with cherry-picked commit should produce a changelist
Given commit aff6453 on branch master
"""
master content
-----
Changes:
M conflict.txt "master version"
"""
Given commit bb6453c on branch feature
"""
feature content
-----
Changes:
M conflict.txt "feature version"
"""
When I cherry-pick the commit bb6453c and don't resolve conflicts
Then active changelist is 'feature content (cherry picked from commit bb6453c)'
And warning notification is shown 'Cherry-picked with conflicts'
@@ -92,10 +101,38 @@ Background:
"""
Scenario: Resolved conflict should show commit dialog
Given commit aff6453 on branch master
"""
master content
-----
Changes:
M conflict.txt "master version"
"""
Given commit bb6453c on branch feature
"""
feature content
-----
Changes:
M conflict.txt "feature version"
"""
When I cherry-pick the commit bb6453c and resolve conflicts
Then commit dialog should be shown
Scenario: Resolve conflict and agree to commit
Given commit aff6453 on branch master
"""
master content
-----
Changes:
M conflict.txt "master version"
"""
Given commit bb6453c on branch feature
"""
feature content
-----
Changes:
M conflict.txt "feature version"
"""
When I cherry-pick the commit bb6453c, resolve conflicts and commit
Then the last commit is
"""
@@ -108,6 +145,20 @@ Background:
And no new changelists are created
Scenario: Resolve conflict, but cancel commit
Given commit aff6453 on branch master
"""
master content
-----
Changes:
M conflict.txt "master version"
"""
Given commit bb6453c on branch feature
"""
feature content
-----
Changes:
M conflict.txt "feature version"
"""
When I cherry-pick the commit bb6453c, resolve conflicts and don't commit
Then active changelist is 'feature content (cherry picked from commit bb6453c)'
And no notification is shown
@@ -143,6 +194,13 @@ Background:
Changes:
M file.txt "feature changes\nmore feature changes"
"""
Given commit bb6453c on branch feature
"""
feature content
-----
Changes:
M conflict.txt "feature version"
"""
Given conflict.txt is locally modified:
"""
master uncommitted content
@@ -171,7 +229,21 @@ Background:
Changes:
M file.txt "feature changes\nmore feature changes"
"""
When I cherry-pick commits f5027a3, bb6453c and f5027a3
Given commit bb6453c on branch feature
"""
feature content
-----
Changes:
M conflict.txt "feature version"
"""
Given commit aff6453 on branch master
"""
master content
-----
Changes:
M conflict.txt "master version"
"""
When I cherry-pick commits f5027a3, bb6453c and c123abc
Then the last commit is
"""
fix #1
@@ -214,14 +286,14 @@ Background:
# fix for f2
# -----
# Changes:
# M f2.txt "feature changes"
# M a.txt "feature changes"
# """
# Given commit e098fed on branch master
# """
# fix for f2 manually incorporated
# -----
# Changes:
# M f2.txt "feature changes"
# M a.txt "feature changes"
# """
# When I cherry-pick commits c123abc, d123abc and e123abc
# Then `git log -2` should return
@@ -20,6 +20,7 @@ import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import cucumber.annotation.After;
import cucumber.annotation.Before;
import cucumber.annotation.en.And;
@@ -31,6 +32,8 @@ import git4idea.test.TestNotificator;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static com.intellij.dvcs.test.Executor.cd;
import static com.intellij.dvcs.test.Executor.mkdir;
@@ -127,4 +130,19 @@ public class GeneralStepdefs {
public void no_notification_is_shown() throws Throwable {
assertNull("Notification should not be shown", lastNotification());
}
@Given("^new committed files (.+) with initial content$")
public void new_committed_files_file_txt_a_txt_b_txt_with_initial_content(String listOfFiles) throws Throwable {
List<String> files = splitByComma(listOfFiles);
for (String file : files) {
touch(file, "initial content");
}
git("add %s", StringUtil.join(files, " "));
git("commit -m 'adding files with initial content'");
}
private static List<String> splitByComma(String listOfFiles) {
return Arrays.asList(listOfFiles.split(", ?"));
}
}
@@ -63,6 +63,7 @@ public class GitCherryPickStepdefs {
@When("^I cherry-pick commits (.+) and (.+)$")
public void I_cherry_pick_commits(String severalCommits, String hash2) throws Throwable {
String[] hashes = severalCommits.split(",");
String[] allHashes = new String[hashes.length + 1];
for (int i = 0; i < allHashes.length - 1; i++) {