Skip to content

A peer-to-peer stack for code collaboration

Add more e2e tests for rad patch (#575)

Merle Breitkreuz158ddfa08301
diff --git a/test/e2e/PatchAppTest.hs b/test/e2e/PatchAppTest.hs
index cf5a912..c0e0b1f 100644
--- a/test/e2e/PatchAppTest.hs
+++ b/test/e2e/PatchAppTest.hs
@@ -1,6 +1,9 @@
-- | Test the Radicle patch app.
module PatchAppTest
( test_patch_propose
+ , test_patch_checkout
+ , test_patch_comment
+ , test_patch_retract
, test_patch_accept
) where
@@ -8,22 +11,22 @@ import Protolude
import Test.E2ESupport
-initProjectWithCommit :: TestM Text
-initProjectWithCommit = do
+initProjectWithPatch :: TestM Text
+initProjectWithPatch = do
prepareRadicle
_ <- runTestCommand' "rad-project" ["init"] ["project-name", "project desc", "1"]
_ <- runTestCommand "git" ["checkout", "-b", "f/test"]
_ <- runTestCommand "touch" ["test"]
_ <- runTestCommand "git" ["add", "test"]
- runTestCommand "git" ["commit", "--message", "first commit"]
+ _ <- runTestCommand "git" ["commit", "--message", "first commit"]
+ runTestCommand "rad-patch" ["propose", "HEAD"]
test_patch_propose :: TestTree
test_patch_propose = testCaseSteps "patch propose" $ \step -> do
- initProjectWithCommit
+ step "init project with patch"
+ initProjectWithPatch
- step "rad patch propose"
commitSha <- runTestCommand "git" ["rev-parse", "--short", "HEAD"]
- _ <- runTestCommand "rad-patch" ["propose", "HEAD"]
listOutput <- runTestCommand "rad-patch" ["list"]
assertContains listOutput "state #"
@@ -34,12 +37,51 @@ test_patch_propose = testCaseSteps "patch propose" $ \step -> do
assertContains showOutput $ "From " <> commitSha
assertContains showOutput "Comments\n---"
+test_patch_checkout :: TestTree
+test_patch_checkout = testCaseSteps "patch checkout" $ \step -> do
+ step "init project with patch"
+ initProjectWithPatch
+
+ step "rad patch checkout"
+ _ <- runTestCommand "git" ["checkout", "master"]
+ _ <- runTestCommand "rad-patch" ["checkout", "0"]
+
+ branchOutput <- runTestCommand "git" ["branch"]
+ assertContains branchOutput "* patch/0"
+
+ logOutput <- runTestCommand "git" ["log"]
+ assertContains logOutput "first commit"
+
+ _ <- runTestCommand "git" ["checkout", "master"]
+ logMasterOutput <- runTestCommand "git" ["log"]
+ assertAbsence logMasterOutput "first commit"
+
+test_patch_comment :: TestTree
+test_patch_comment = testCaseSteps "patch comment" $ \step -> do
+ step "init project with patch"
+ initProjectWithPatch
+
+ step "rad patch comment"
+ _ <- runTestCommand "rad-patch" ["comment", "0", "Test commenting"]
+
+ showOutput <- runTestCommand "rad-patch" ["show", "0"]
+ assertContains showOutput "Test commenting"
+
+test_patch_retract :: TestTree
+test_patch_retract = testCaseSteps "patch retract" $ \step -> do
+ step "init project with patch"
+ initProjectWithPatch
+
+ step "rad patch retract"
+ _ <- runTestCommand "rad-patch" ["retract", "0"]
+
+ showAcceptedOutput <- runTestCommand "rad-patch" ["show", "0"]
+ assertContains showAcceptedOutput "retracted 0"
+
test_patch_accept :: TestTree
test_patch_accept = testCaseSteps "patch accept" $ \step -> do
- initProjectWithCommit
-
- step "rad patch propose"
- _ <- runTestCommand "rad-patch" ["propose", "HEAD"]
+ step "init project with patch"
+ initProjectWithPatch
step "rad patch accept"
_ <- runTestCommand "git" ["checkout", "master"]
diff --git a/test/e2e/Test/E2ESupport.hs b/test/e2e/Test/E2ESupport.hs
index d1df60f..f270d57 100644
--- a/test/e2e/Test/E2ESupport.hs
+++ b/test/e2e/Test/E2ESupport.hs
@@ -18,6 +18,7 @@ module Test.E2ESupport
, TestTree
, assertEqual
, assertContains
+ , assertAbsence
) where
import Prelude (String, unwords)
@@ -99,6 +100,14 @@ assertContains str substr =
then pure ()
else assertFailure $ "\"" <> substr <> "\" is not contained in \"" <> str <> "\""
+-- | @assertAbsence str substr@ throws as assertion error if @substr@ is
+-- contained in @str@
+assertAbsence :: (HasCallStack, MonadIO m) => Text -> Text -> m ()
+assertAbsence str substr =
+ if substr `T.isInfixOf` str
+ then assertFailure $ "\"" <> substr <> "\" should not be contained in \"" <> str <> "\""
+ else pure ()
+
-- * Setup
-- | Runs @rad key create@ and sets the Git user name and email.