From 6c18592331d000ebc17335b0c66056539de1d74d Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Tue, 26 Mar 2024 05:25:20 +0100 Subject: chore: add working tree changes to smoke tests --- app/Backend.hs | 3 +- test/Main.hs | 121 ++++++++++++++++++--------------------------------------- 2 files changed, 39 insertions(+), 85 deletions(-) diff --git a/app/Backend.hs b/app/Backend.hs index 0a61ce3..af6cebd 100644 --- a/app/Backend.hs +++ b/app/Backend.hs @@ -39,6 +39,7 @@ import Git.Libgit2 (LgRepo, lgFactory) import Patch qualified as A import Process (proc, sh, sh_) import Safe (headMay) +import System.Environment (lookupEnv) import Text.Printf (printf) getCommitHashes :: Maybe CommitHash -> Maybe CommitHash -> IO [CommitHash] @@ -166,7 +167,7 @@ data Author = Author getCommitOf :: CommitHash -> IO Commit getCommitOf commitHash@WorkingTree = do - date <- getCurrentTime + date <- maybe getCurrentTime (pure . read) =<< lookupEnv "FAKETIME" authorName <- sh "git config user.name" authorEmail <- sh "git config user.email" pure diff --git a/test/Main.hs b/test/Main.hs index 46b4e06..7bd7fc7 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -4,37 +4,55 @@ import Process.Shell (sh) import Test.Hspec (describe, hspec, it, shouldBe) main :: IO () -main = do +main = hspec do + describe "issue events" do + it "smoke" do + ( `shouldBe` + concat + [ " created issue 3\n", + "df7c026 created issue 1\n", + "55b493c deleted issue 1\n", + "618907d changed issue 1\n", + "618907d created issue 2\n", + "e95b4ec created issue 1" + ] + ) + . fst + =<< smokeScript "anissue log" + describe "issues" do + it "smoke" do + ( `shouldBe` + concat + [ "issue 3 on 1970-01-01 by Jane Doe\n", + "\n", + "issue 2 on 1970-01-01 by Jane Doe\n", + "\n", + "issue 1 on 1970-01-01 by Jane Doe" + ] + ) + . fst + =<< smokeScript "anissue list" + +smokeScript :: String -> IO (String, ()) +smokeScript cmd = do anissue :: String <- [sh|realpath dist-newstyle/build/*/*/anissue-*/x/anissue/build/anissue|] - hspec do - describe "issue events" do - it "smoke" do - ( `shouldBe` - concat - [ "df7c026 created issue 1\n", - "55b493c deleted issue 1\n", - "618907d changed issue 1\n", - "618907d created issue 2\n", - "e95b4ec created issue 1" - ] - ) - . fst @String @() - =<< [sh| + [sh| set -efu PATH=#{anissue}${PATH+:$PATH}; export PATH readonly tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT cd "$tmp" +( GIT_AUTHOR_DATE="Thu Jan 1 00:00:00 1970 +0000"; export GIT_AUTHOR_DATE GIT_AUTHOR_EMAIL="jane@example.com"; export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME="Jane Doe"; export GIT_AUTHOR_NAME GIT_COMMITTER_DATE="Thu Jan 1 00:00:00 1970 +0000"; export GIT_COMMITTER_DATE GIT_COMMITTER_EMAIL="jane@example.com"; export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME="Jane Doe"; export GIT_COMMITTER_NAME - -( git init --initial-branch=main +git config --local user.name "$GIT_AUTHOR_NAME" +git config --local user.email "$GIT_AUTHOR_EMAIL" cat >main.hs <<'EOF' module Main where @@ -80,80 +98,15 @@ module Main where EOF git add main.hs lib.hs git commit -m 'reopen issue 1' -) 1>/dev/null - -anissue log|] - describe "issues" do - it "smoke" do - ( `shouldBe` - concat - [ "issue 2 on 1970-01-01 by Jane Doe\n", - "\n", - "issue 1 on 1970-01-01 by Jane Doe" - ] - ) - . fst @String @() - =<< [sh| -set -efu -PATH=#{anissue}${PATH+:$PATH}; export PATH -readonly tmp=$(mktemp -d) -trap 'rm -rf "$tmp"' EXIT -cd "$tmp" - -GIT_AUTHOR_DATE="Thu Jan 1 00:00:00 1970 +0000"; export GIT_AUTHOR_DATE -GIT_AUTHOR_EMAIL="jane@example.com"; export GIT_AUTHOR_EMAIL -GIT_AUTHOR_NAME="Jane Doe"; export GIT_AUTHOR_NAME -GIT_COMMITTER_DATE="Thu Jan 1 00:00:00 1970 +0000"; export GIT_COMMITTER_DATE -GIT_COMMITTER_EMAIL="jane@example.com"; export GIT_COMMITTER_EMAIL -GIT_COMMITTER_NAME="Jane Doe"; export GIT_COMMITTER_NAME - -( -git init --initial-branch=main - -cat >main.hs <<'EOF' -module Main where -EOF -git add main.hs -git commit -m 'no issues' - -cat >main.hs <<'EOF' -module Main where - --- TODO issue 1 -EOF -git add main.hs -git commit -m 'create issue 1' cat >main.hs <<'EOF' module Main where -- TODO issue 2 -EOF -cat >lib.hs <<'EOF' -module Main where - --- TODO issue 1 --- --- remark: file modifications are not considered changes! -EOF -git add main.hs lib.hs -git commit -m 'create issue 2, modify issue 1' -cat >lib.hs <<'EOF' -module Main where +-- TODO issue 3 EOF -git add lib.hs -git commit -m 'close issue 1' - -cat >lib.hs <<'EOF' -module Main where --- TODO issue 1 --- --- remark: file changes are not considered changes! -EOF -git add main.hs lib.hs -git commit -m 'reopen issue 1' ) 1>/dev/null -anissue list|] +FAKETIME='1970-01-01 00:00:00' eval '#{cmd}'|] -- cgit v1.2.3