From b3a3d8583cc29210b948b76fd63836367d2eec4b Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 2 Jan 2013 15:43:12 +0400 Subject: [PATCH] [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. --- .../git4idea/cherry-pick-auto-commit.feature | 126 ++++++++++++++---- .../git4idea/GeneralStepdefs.java | 18 +++ .../git4idea/GitCherryPickStepdefs.java | 1 + 3 files changed, 118 insertions(+), 27 deletions(-) diff --git a/plugins/git4idea/test-features/git4idea/cherry-pick-auto-commit.feature b/plugins/git4idea/test-features/git4idea/cherry-pick-auto-commit.feature index d7288c1fb5ff..f9ccabfcf582 100644 --- a/plugins/git4idea/test-features/git4idea/cherry-pick-auto-commit.feature +++ b/plugins/git4idea/test-features/git4idea/cherry-pick-auto-commit.feature @@ -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 diff --git a/plugins/git4idea/test-stepdefs/git4idea/GeneralStepdefs.java b/plugins/git4idea/test-stepdefs/git4idea/GeneralStepdefs.java index 1085b22a7e77..4b6f8540163a 100644 --- a/plugins/git4idea/test-stepdefs/git4idea/GeneralStepdefs.java +++ b/plugins/git4idea/test-stepdefs/git4idea/GeneralStepdefs.java @@ -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 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 splitByComma(String listOfFiles) { + return Arrays.asList(listOfFiles.split(", ?")); + } + } diff --git a/plugins/git4idea/test-stepdefs/git4idea/GitCherryPickStepdefs.java b/plugins/git4idea/test-stepdefs/git4idea/GitCherryPickStepdefs.java index 3d9d4cb34518..91a6d585c022 100644 --- a/plugins/git4idea/test-stepdefs/git4idea/GitCherryPickStepdefs.java +++ b/plugins/git4idea/test-stepdefs/git4idea/GitCherryPickStepdefs.java @@ -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++) {