Skip to content

Commit 51c22e4

Browse files
authored
Use normalized filepaths in dhall testsuite (#2593)
* Updated hnix dependencies in all Stack configurations Also added `mkParsec` method to MonadParsec instance for megaparsec>=9.4 * Require turtle >=1.6 * Removed depecated functions * Use normalized filepaths in tests * Made normalization tests a bit more chatty * Fix: Exclude unit test from beta-normalization in Dhall.Test.Normalization * Improved usage of guards for path selection in test suite * Normalize filepath in guards for path selection * Added turtle-1.6.2 to Nix setup * Unconditionally import Data.List in Dhall.Test.Util * Added small comment on the use of toDhallPath in Dhall.Test.Tags * Ran stylish-haskell * Log pkg-config path of libsodium in the CI * Log the libsodium version in the CI * Do not install a GHC with ghcup in the CI * Fixed pkg-config output in the CI * Bump cache_generation * Bumped version of some GH actions * Changed cache key * Small comment on pkg-config output * Added .envrc to .gitignore * Fixed deprecation warnings in dhall-nixpkgs package
1 parent e615993 commit 51c22e4

23 files changed

+149
-115
lines changed

.github/workflows/main.yml

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
env:
2-
cache_generation: 2021-06-22
2+
cache_generation: 2024-06-13
33

44
# NOTE: Please keep .mergify.yml in sync when adding or removing any jobs.
55
name: main
@@ -45,20 +45,23 @@ jobs:
4545
with:
4646
enable-stack: true
4747
stack-version: "latest"
48+
stack-no-global: true
4849
- name: "Cache"
49-
uses: actions/cache@v3
50+
uses: actions/cache@v4
5051
with:
51-
key: ${{ matrix.os.runner }}-${{ runner.arch }}-${{ hashFiles(matrix.stack-yaml) }}-${{ env.cache_generation }}
52+
key: ${{ matrix.os.runner }}-${{ runner.arch }}-${{ env.cache_generation }}-${{ hashFiles(matrix.stack-yaml) }}
5253
restore-keys: |
53-
${{ matrix.os.runner }}-${{ runner.arch }}-
54+
${{ matrix.os.runner }}-${{ runner.arch }}-${{ env.cache_generation }}-
5455
path: |
5556
${{ steps.setup-haskell-cabal.outputs.stack-root }}
56-
- name: Install libsodium
57+
- name: "Install libsodium"
5758
shell: bash
5859
run: |
5960
if [ '${{matrix.os.runner}}' == 'ubuntu-latest' ]; then
6061
sudo apt-get install -y libsodium-dev
6162
fi
63+
echo "::debug::'pkg-config libsodium' output:"
64+
pkg-config --print-errors --libs libsodium || true
6265
- name: "Build"
6366
shell: bash
6467
run: |
@@ -155,7 +158,7 @@ jobs:
155158
package 'dhall-yaml' "bin/dhall-to-yaml-ng${exe}" "bin/yaml-to-dhall${exe}"
156159
- name: "Upload package"
157160
if: ${{ matrix.stack-yaml == 'stack.yaml' }}
158-
uses: actions/upload-artifact@v3
161+
uses: actions/upload-artifact@v4
159162
with:
160163
name: 'dhall-${{ runner.os }}-${{ runner.arch }}.${{ matrix.os.file-extension }}'
161164
path: 'dhall-*${{ runner.os }}-${{ runner.arch }}.${{ matrix.os.file-extension }}'

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cabal.sandbox.config
1919
cabal.project.local
2020
cabal.project.local~
2121
.HTF/
22+
.envrc
2223
.ghc.environment.*
2324
.cache
2425
.history

dhall-docs/dhall-docs.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Test-Suite tasty
152152
tasty < 1.5 ,
153153
tasty-silver < 3.4 ,
154154
tasty-hunit >= 0.10 && < 0.11,
155-
turtle < 1.7 ,
155+
turtle >= 1.6 && < 1.7 ,
156156
text
157157
GHC-Options: -Wall
158158
Default-Language: Haskell2010

dhall-nixpkgs/Main.hs

+12-23
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ githubToNixpkgs GitHub{ name, uri, rev = maybeRev, hash, fetchSubmodules, direct
681681
ExitFailure _ -> die (FailedToFetchGitHubArchive args)
682682

683683
case Text.lines text of
684-
[ sha256, path ] -> return (r, sha256, Turtle.fromText path)
684+
[ sha256, path ] -> return (r, sha256, Text.unpack path)
685685
_ -> die (FailedToParseNixPrefetchURL args)
686686

687687
_ -> do
@@ -706,7 +706,7 @@ githubToNixpkgs GitHub{ name, uri, rev = maybeRev, hash, fetchSubmodules, direct
706706
Right n -> do
707707
return n
708708

709-
return (rev, sha256, Turtle.fromText path)
709+
return (rev, sha256, Text.unpack path)
710710

711711
let finalName =
712712
case name of
@@ -723,15 +723,11 @@ githubToNixpkgs GitHub{ name, uri, rev = maybeRev, hash, fetchSubmodules, direct
723723
then return ()
724724
else die (MissingFile expressionFile)
725725

726-
expressionText <- Turtle.readTextFile expressionFile
726+
expressionText <- Text.IO.readFile expressionFile
727727

728-
let expressionFileString = Turtle.encodeString expressionFile
728+
expression <- Dhall.Core.throws (Dhall.Parser.exprFromText expressionFile expressionText)
729729

730-
expression <- Dhall.Core.throws (Dhall.Parser.exprFromText expressionFileString expressionText)
731-
732-
let status = Dhall.Import.emptyStatus baseDirectoryString
733-
where
734-
baseDirectoryString = Turtle.encodeString baseDirectory
730+
let status = Dhall.Import.emptyStatus baseDirectory
735731

736732
dependencies <- Turtle.reduce Foldl.nub (State.evalStateT (findExternalDependencies expression) status)
737733

@@ -781,16 +777,11 @@ directoryToNixpkgs Directory{ name, directory, file, source, document, fixedOutp
781777
else do
782778
die (MissingFile expressionFile)
783779

784-
expressionText <- Turtle.readTextFile expressionFile
785-
786-
let expressionFileString = Turtle.encodeString expressionFile
780+
expressionText <- Text.IO.readFile expressionFile
787781

788-
expression <- Dhall.Core.throws (Dhall.Parser.exprFromText expressionFileString expressionText)
782+
expression <- Dhall.Core.throws (Dhall.Parser.exprFromText expressionFile expressionText)
789783

790-
let status = Dhall.Import.emptyStatus directoryString
791-
where
792-
directoryString =
793-
Turtle.encodeString (Turtle.directory expressionFile)
784+
let status = Dhall.Import.emptyStatus (Turtle.directory expressionFile)
794785

795786
dependencies <- Turtle.reduce Foldl.nub (State.evalStateT (findExternalDependencies expression) status)
796787

@@ -804,11 +795,9 @@ directoryToNixpkgs Directory{ name, directory, file, source, document, fixedOutp
804795

805796
let buildDhallDirectoryPackage = "buildDhallDirectoryPackage"
806797

807-
let src | null directoryString = directoryString
808-
| last directoryString == '/' = init directoryString
809-
| otherwise = directoryString
810-
where
811-
directoryString = Turtle.encodeString directory
798+
let src | null directory = directory
799+
| last directory == '/' = init directory
800+
| otherwise = directory
812801

813802
let functionParams =
814803
makeNixFunctionParams buildDhallDirectoryPackage nixDependencies
@@ -852,7 +841,7 @@ data Error
852841
| FailedToCloneRepository [Text]
853842
| FailedToParseNixPrefetchGit [Text] String
854843
| MissingFile FilePath
855-
844+
856845
renderError :: Error -> Text
857846
renderError e = case e of
858847
MissingSemanticIntegrityCheck url ->

dhall-nixpkgs/dhall-nixpkgs.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Executable dhall-to-nixpkgs
3434
, prettyprinter >= 1.7.0 && < 1.8
3535
, text >= 0.11.1.0 && < 2.1
3636
, transformers >= 0.2.0.0 && < 0.6
37-
, turtle < 1.6
37+
, turtle >= 1.6 && < 1.7
3838
, network-uri < 2.8
3939
Default-Language: Haskell2010
4040
GHC-Options: -Wall -threaded

dhall/dhall.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ Test-Suite tasty
452452
tasty-quickcheck >= 0.9.2 && < 0.11,
453453
tasty-silver < 3.4 ,
454454
temporary >= 1.2.1 && < 1.4 ,
455-
turtle < 1.7 ,
455+
turtle >= 1.6 && < 1.7 ,
456456
Default-Language: Haskell2010
457457

458458
Test-Suite doctest

dhall/src/Dhall/Diff.hs

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ import Dhall.Syntax
4141
import Numeric.Natural (Natural)
4242
import Prettyprinter (Doc, Pretty)
4343

44-
import qualified Data.Algorithm.Diff as Algo.Diff
44+
import qualified Data.Algorithm.Diff as Algo.Diff
4545
import qualified Data.List.NonEmpty
4646
import qualified Data.Set
4747
import qualified Data.Text
48-
import qualified Data.Time as Time
48+
import qualified Data.Time as Time
4949
import qualified Dhall.Map
50-
import qualified Dhall.Normalize as Normalize
51-
import qualified Dhall.Pretty.Internal as Internal
52-
import qualified Dhall.Syntax as Syntax
53-
import qualified Prettyprinter as Pretty
50+
import qualified Dhall.Normalize as Normalize
51+
import qualified Dhall.Pretty.Internal as Internal
52+
import qualified Dhall.Syntax as Syntax
53+
import qualified Prettyprinter as Pretty
5454

5555
{-| This type is a `Doc` enriched with a `same` flag to efficiently track if
5656
any difference was detected

dhall/src/Dhall/Parser/Combinators.hs

+4
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ instance Text.Megaparsec.MonadParsec Void Text Parser where
169169

170170
updateParserState f = Parser (Text.Megaparsec.updateParserState f)
171171

172+
#if MIN_VERSION_megaparsec(9,4,0)
173+
mkParsec f = Parser (Text.Megaparsec.mkParsec f)
174+
#endif
175+
172176
instance Semigroup a => Semigroup (Parser a) where
173177
(<>) = liftA2 (<>)
174178

dhall/tests/Dhall/Test/Diff.hs

-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
module Dhall.Test.Diff where
44

55
import Data.Text (Text)
6-
import Prelude hiding (FilePath)
76
import Test.Tasty (TestTree)
8-
import Turtle (FilePath)
97

108
import qualified Data.Text as Text
119
import qualified Data.Text.IO as Text.IO

dhall/tests/Dhall/Test/Format.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import Dhall.Parser (Header (..))
77
import Dhall.Pretty (CharacterSet (..))
88
import Test.Tasty (TestTree)
99

10-
import qualified Control.Monad as Monad
1110
import qualified Data.Text as Text
1211
import qualified Data.Text.IO as Text.IO
1312
import qualified Dhall.Core as Core
@@ -27,7 +26,7 @@ getTests = do
2726

2827
let skip = [ "./tests/format/asciiA.dhall" ]
2928

30-
Monad.guard (path `notElem` skip)
29+
path `Test.Util.pathNotIn` skip
3130

3231
return path
3332

dhall/tests/Dhall/Test/Freeze.hs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
{-# LANGUAGE OverloadedStrings #-}
22

3-
-- FIXME: Re-enable deprecation warnings after removing support for turtle < 1.6.
4-
{-# OPTIONS_GHC -Wno-deprecations #-}
5-
63
module Dhall.Test.Freeze where
74

85
import Data.Text (Text)
96
import Dhall.Freeze (Intent (..), Scope (..))
10-
import Prelude hiding (FilePath)
117
import Test.Tasty (TestTree)
12-
import Turtle (FilePath)
138

149
import qualified Data.Text as Text
1510
import qualified Data.Text.IO as Text.IO
@@ -53,7 +48,7 @@ freezeTest dir intent prefix =
5348

5449
parsedInput <- Core.throws (Parser.exprFromText mempty inputText)
5550

56-
actualExpression <- Freeze.freezeExpression (Turtle.encodeString dir) AllImports intent parsedInput
51+
actualExpression <- Freeze.freezeExpression dir AllImports intent parsedInput
5752

5853
let actualText = Core.pretty actualExpression <> "\n"
5954

dhall/tests/Dhall/Test/Import.hs

+9-14
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,15 @@
22
{-# LANGUAGE OverloadedStrings #-}
33
{-# LANGUAGE TypeApplications #-}
44

5-
-- FIXME: Re-enable deprecation warnings after removing support for turtle < 1.6.
6-
{-# OPTIONS_GHC -Wno-deprecations #-}
7-
85
module Dhall.Test.Import where
96

107
import Control.Exception (SomeException)
11-
import Data.Foldable (fold)
12-
import Data.Text (Text, isSuffixOf)
8+
import Data.Text (Text)
139
import Data.Void (Void)
14-
import Prelude hiding (FilePath)
10+
import System.FilePath ((</>))
1511
import Test.Tasty (TestTree)
16-
import Turtle (FilePath, toText, (</>))
1712

1813
import qualified Control.Exception as Exception
19-
import qualified Control.Monad as Monad
2014
import qualified Control.Monad.Trans.State.Strict as State
2115
import qualified Data.Text as Text
2216
import qualified Data.Text.IO as Text.IO
@@ -31,8 +25,8 @@ import qualified Test.Tasty.HUnit as Tasty.HUnit
3125
import qualified Turtle
3226

3327
#if defined(WITH_HTTP) && defined(NETWORK_TESTS)
34-
import qualified Network.HTTP.Client as HTTP
35-
import qualified Network.HTTP.Client.TLS as HTTP
28+
import qualified Network.HTTP.Client as HTTP
29+
import qualified Network.HTTP.Client.TLS as HTTP
3630
#endif
3731

3832

@@ -77,7 +71,7 @@ getTests = do
7771
successTests <- Test.Util.discover (Turtle.chars <* "A.dhall") successTest (do
7872
path <- Turtle.lstree (importDirectory </> "success")
7973

80-
Monad.guard (path `notElem` flakyTests)
74+
path `Test.Util.pathNotIn` flakyTests
8175

8276
return path )
8377

@@ -101,8 +95,9 @@ getTests = do
10195
#endif
10296
]
10397

104-
_ <- Monad.guard (path `notElem` expectedSuccesses)
105-
_ <- Monad.guard (not ("ENV.dhall" `isSuffixOf` (fold (toText path))))
98+
path `Test.Util.pathNotIn` expectedSuccesses
99+
"ENV.dhall" `Test.Util.pathNotSuffixOf` path
100+
106101
return path )
107102

108103
let testTree =
@@ -176,7 +171,7 @@ successTest prefix = do
176171
not (null (Turtle.match (Turtle.ends path') (Test.Util.toDhallPath prefix)))
177172

178173
let buildNewCache = do
179-
tempdir <- fmap Turtle.decodeString (Turtle.managed (Temp.withSystemTempDirectory "dhall-cache"))
174+
tempdir <- Turtle.managed (Temp.withSystemTempDirectory "dhall-cache")
180175
Turtle.liftIO (Turtle.cptree originalCache tempdir)
181176
return tempdir
182177

dhall/tests/Dhall/Test/Lint.hs

-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ module Dhall.Test.Lint where
44

55
import Data.Text (Text)
66
import Dhall.Parser (Header (..))
7-
import Prelude hiding (FilePath)
87
import Test.Tasty (TestTree)
9-
import Turtle (FilePath)
108

119
import qualified Data.Text as Text
1210
import qualified Data.Text.IO as Text.IO

0 commit comments

Comments
 (0)