Test in a git repo

This commit is contained in:
Tom Sydney Kerckhove 2023-01-18 11:38:21 +01:00
parent f6c3d5d819
commit 3448bebcf1
3 changed files with 67 additions and 2 deletions

View File

View File

@ -8,7 +8,7 @@ import qualified Data.ByteString as SB
import Path
import Path.IO
import System.IO
import System.Posix
import System.Posix (fdToHandle, openPseudoTerminal)
import System.Process.Typed
import Test.Syd
import Test.Syd.Path
@ -120,7 +120,69 @@ spec = sequential . tempDirSpec "feedback" . coverageSpec $ do
afterContents <- SB.readFile (fromAbsFile dateFile)
afterContents `shouldNotBe` beforeContents
waitABit
it "can run in a git repository and ignore .gitignored files" $ \tdir -> do
-- Set up the repository
let runGit args =
runProcess_ $ setEnv [] $ setWorkingDir (fromAbsDir tdir) $ proc "git" args
runGit ["init"]
runGit ["config", "user.email", "you@example.com"]
runGit ["config", "user.name", "Your Name"]
notIgnoredFile <- resolveFile tdir "file.not-ignored"
ignoredFile <- resolveFile tdir "file.ignored"
gitignoreFile <- resolveFile tdir ".gitignore"
SB.writeFile (fromAbsFile gitignoreFile) "*.ignored"
runGit ["add", "."]
runGit ["commit", "-m", "Initial commit"]
SB.writeFile (fromAbsFile notIgnoredFile) "foo"
SB.writeFile (fromAbsFile ignoredFile) "bar"
runGit ["add", "."]
runGit ["commit", "-m", "commit with files."]
(_, slaveFd) <- openPseudoTerminal
-- masterHandle <- fdToHandle masterFd
slaveHandle <- fdToHandle slaveFd
dateFile <- resolveFile tdir "datefile.ignored"
let cp =
setStdout nullStream
. setStdin (useHandleOpen slaveHandle)
. setWorkingDir (fromAbsDir tdir)
$ proc "feedback" ["--no-clear", "--debug", "--", "bash", "-c", "date +%N >" <> fromAbsFile dateFile]
withProcessTerm cp $ \ph -> do
waitABit
-- Feedback is running.
mExitCode <- getExitCode ph
mExitCode `shouldBe` Nothing
-- Make sure the file exists now
beforeContents <- SB.readFile (fromAbsFile dateFile)
-- Change the ignored file file, this should _not_ cause the loop to rerun.
SB.writeFile (fromAbsFile ignoredFile) "go go go"
-- Make sure the loop is rerun
waitABit
-- Make sure the loop is rerun
middleContents <- SB.readFile (fromAbsFile dateFile)
middleContents `shouldBe` beforeContents
-- Change the not-ignored file file, this should cause the loop to rerun.
SB.writeFile (fromAbsFile notIgnoredFile) "go go go"
-- Make sure the loop is rerun
waitABit
-- Make sure the loop is rerun
afterContents <- SB.readFile (fromAbsFile dateFile)
afterContents `shouldNotBe` beforeContents
-- It's really annoying that this is necessary, but hear me out.
-- `feedback` is run in a tempdir.

View File

@ -48,6 +48,9 @@ with final.haskell.lib;
})));
feedback-test-harness = buildStrictly
(overrideCabal (self.callPackage ../feedback-test-harness { }) (old: {
buildDepends = (old.buildDepends or [ ]) ++ [
final.git
];
# Ugly hack because we can't just add flags to the 'test' invocation.
# Show test output as we go, instead of all at once afterwards.
testTarget = (old.testTarget or "") + " --show-details=direct";