Skip to content

Commit

Permalink
Use normalized filepaths in dhall testsuite (#2593)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mmhat authored Jun 17, 2024
1 parent e615993 commit 51c22e4
Show file tree
Hide file tree
Showing 23 changed files with 149 additions and 115 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env:
cache_generation: 2021-06-22
cache_generation: 2024-06-13

# NOTE: Please keep .mergify.yml in sync when adding or removing any jobs.
name: main
Expand Down Expand Up @@ -45,20 +45,23 @@ jobs:
with:
enable-stack: true
stack-version: "latest"
stack-no-global: true
- name: "Cache"
uses: actions/cache@v3
uses: actions/cache@v4
with:
key: ${{ matrix.os.runner }}-${{ runner.arch }}-${{ hashFiles(matrix.stack-yaml) }}-${{ env.cache_generation }}
key: ${{ matrix.os.runner }}-${{ runner.arch }}-${{ env.cache_generation }}-${{ hashFiles(matrix.stack-yaml) }}
restore-keys: |
${{ matrix.os.runner }}-${{ runner.arch }}-
${{ matrix.os.runner }}-${{ runner.arch }}-${{ env.cache_generation }}-
path: |
${{ steps.setup-haskell-cabal.outputs.stack-root }}
- name: Install libsodium
- name: "Install libsodium"
shell: bash
run: |
if [ '${{matrix.os.runner}}' == 'ubuntu-latest' ]; then
sudo apt-get install -y libsodium-dev
fi
echo "::debug::'pkg-config libsodium' output:"
pkg-config --print-errors --libs libsodium || true
- name: "Build"
shell: bash
run: |
Expand Down Expand Up @@ -155,7 +158,7 @@ jobs:
package 'dhall-yaml' "bin/dhall-to-yaml-ng${exe}" "bin/yaml-to-dhall${exe}"
- name: "Upload package"
if: ${{ matrix.stack-yaml == 'stack.yaml' }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: 'dhall-${{ runner.os }}-${{ runner.arch }}.${{ matrix.os.file-extension }}'
path: 'dhall-*${{ runner.os }}-${{ runner.arch }}.${{ matrix.os.file-extension }}'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cabal.sandbox.config
cabal.project.local
cabal.project.local~
.HTF/
.envrc
.ghc.environment.*
.cache
.history
Expand Down
2 changes: 1 addition & 1 deletion dhall-docs/dhall-docs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Test-Suite tasty
tasty < 1.5 ,
tasty-silver < 3.4 ,
tasty-hunit >= 0.10 && < 0.11,
turtle < 1.7 ,
turtle >= 1.6 && < 1.7 ,
text
GHC-Options: -Wall
Default-Language: Haskell2010
35 changes: 12 additions & 23 deletions dhall-nixpkgs/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ githubToNixpkgs GitHub{ name, uri, rev = maybeRev, hash, fetchSubmodules, direct
ExitFailure _ -> die (FailedToFetchGitHubArchive args)

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

_ -> do
Expand All @@ -706,7 +706,7 @@ githubToNixpkgs GitHub{ name, uri, rev = maybeRev, hash, fetchSubmodules, direct
Right n -> do
return n

return (rev, sha256, Turtle.fromText path)
return (rev, sha256, Text.unpack path)

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

expressionText <- Turtle.readTextFile expressionFile
expressionText <- Text.IO.readFile expressionFile

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

expression <- Dhall.Core.throws (Dhall.Parser.exprFromText expressionFileString expressionText)

let status = Dhall.Import.emptyStatus baseDirectoryString
where
baseDirectoryString = Turtle.encodeString baseDirectory
let status = Dhall.Import.emptyStatus baseDirectory

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

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

expressionText <- Turtle.readTextFile expressionFile

let expressionFileString = Turtle.encodeString expressionFile
expressionText <- Text.IO.readFile expressionFile

expression <- Dhall.Core.throws (Dhall.Parser.exprFromText expressionFileString expressionText)
expression <- Dhall.Core.throws (Dhall.Parser.exprFromText expressionFile expressionText)

let status = Dhall.Import.emptyStatus directoryString
where
directoryString =
Turtle.encodeString (Turtle.directory expressionFile)
let status = Dhall.Import.emptyStatus (Turtle.directory expressionFile)

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

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

let buildDhallDirectoryPackage = "buildDhallDirectoryPackage"

let src | null directoryString = directoryString
| last directoryString == '/' = init directoryString
| otherwise = directoryString
where
directoryString = Turtle.encodeString directory
let src | null directory = directory
| last directory == '/' = init directory
| otherwise = directory

let functionParams =
makeNixFunctionParams buildDhallDirectoryPackage nixDependencies
Expand Down Expand Up @@ -852,7 +841,7 @@ data Error
| FailedToCloneRepository [Text]
| FailedToParseNixPrefetchGit [Text] String
| MissingFile FilePath

renderError :: Error -> Text
renderError e = case e of
MissingSemanticIntegrityCheck url ->
Expand Down
2 changes: 1 addition & 1 deletion dhall-nixpkgs/dhall-nixpkgs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Executable dhall-to-nixpkgs
, prettyprinter >= 1.7.0 && < 1.8
, text >= 0.11.1.0 && < 2.1
, transformers >= 0.2.0.0 && < 0.6
, turtle < 1.6
, turtle >= 1.6 && < 1.7
, network-uri < 2.8
Default-Language: Haskell2010
GHC-Options: -Wall -threaded
2 changes: 1 addition & 1 deletion dhall/dhall.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ Test-Suite tasty
tasty-quickcheck >= 0.9.2 && < 0.11,
tasty-silver < 3.4 ,
temporary >= 1.2.1 && < 1.4 ,
turtle < 1.7 ,
turtle >= 1.6 && < 1.7 ,
Default-Language: Haskell2010

Test-Suite doctest
Expand Down
12 changes: 6 additions & 6 deletions dhall/src/Dhall/Diff.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ import Dhall.Syntax
import Numeric.Natural (Natural)
import Prettyprinter (Doc, Pretty)

import qualified Data.Algorithm.Diff as Algo.Diff
import qualified Data.Algorithm.Diff as Algo.Diff
import qualified Data.List.NonEmpty
import qualified Data.Set
import qualified Data.Text
import qualified Data.Time as Time
import qualified Data.Time as Time
import qualified Dhall.Map
import qualified Dhall.Normalize as Normalize
import qualified Dhall.Pretty.Internal as Internal
import qualified Dhall.Syntax as Syntax
import qualified Prettyprinter as Pretty
import qualified Dhall.Normalize as Normalize
import qualified Dhall.Pretty.Internal as Internal
import qualified Dhall.Syntax as Syntax
import qualified Prettyprinter as Pretty

{-| This type is a `Doc` enriched with a `same` flag to efficiently track if
any difference was detected
Expand Down
4 changes: 4 additions & 0 deletions dhall/src/Dhall/Parser/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ instance Text.Megaparsec.MonadParsec Void Text Parser where

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

#if MIN_VERSION_megaparsec(9,4,0)
mkParsec f = Parser (Text.Megaparsec.mkParsec f)
#endif

instance Semigroup a => Semigroup (Parser a) where
(<>) = liftA2 (<>)

Expand Down
2 changes: 0 additions & 2 deletions dhall/tests/Dhall/Test/Diff.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
module Dhall.Test.Diff where

import Data.Text (Text)
import Prelude hiding (FilePath)
import Test.Tasty (TestTree)
import Turtle (FilePath)

import qualified Data.Text as Text
import qualified Data.Text.IO as Text.IO
Expand Down
3 changes: 1 addition & 2 deletions dhall/tests/Dhall/Test/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Dhall.Parser (Header (..))
import Dhall.Pretty (CharacterSet (..))
import Test.Tasty (TestTree)

import qualified Control.Monad as Monad
import qualified Data.Text as Text
import qualified Data.Text.IO as Text.IO
import qualified Dhall.Core as Core
Expand All @@ -27,7 +26,7 @@ getTests = do

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

Monad.guard (path `notElem` skip)
path `Test.Util.pathNotIn` skip

return path

Expand Down
7 changes: 1 addition & 6 deletions dhall/tests/Dhall/Test/Freeze.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
{-# LANGUAGE OverloadedStrings #-}

-- FIXME: Re-enable deprecation warnings after removing support for turtle < 1.6.
{-# OPTIONS_GHC -Wno-deprecations #-}

module Dhall.Test.Freeze where

import Data.Text (Text)
import Dhall.Freeze (Intent (..), Scope (..))
import Prelude hiding (FilePath)
import Test.Tasty (TestTree)
import Turtle (FilePath)

import qualified Data.Text as Text
import qualified Data.Text.IO as Text.IO
Expand Down Expand Up @@ -53,7 +48,7 @@ freezeTest dir intent prefix =

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

actualExpression <- Freeze.freezeExpression (Turtle.encodeString dir) AllImports intent parsedInput
actualExpression <- Freeze.freezeExpression dir AllImports intent parsedInput

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

Expand Down
23 changes: 9 additions & 14 deletions dhall/tests/Dhall/Test/Import.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}

-- FIXME: Re-enable deprecation warnings after removing support for turtle < 1.6.
{-# OPTIONS_GHC -Wno-deprecations #-}

module Dhall.Test.Import where

import Control.Exception (SomeException)
import Data.Foldable (fold)
import Data.Text (Text, isSuffixOf)
import Data.Text (Text)
import Data.Void (Void)
import Prelude hiding (FilePath)
import System.FilePath ((</>))
import Test.Tasty (TestTree)
import Turtle (FilePath, toText, (</>))

import qualified Control.Exception as Exception
import qualified Control.Monad as Monad
import qualified Control.Monad.Trans.State.Strict as State
import qualified Data.Text as Text
import qualified Data.Text.IO as Text.IO
Expand All @@ -31,8 +25,8 @@ import qualified Test.Tasty.HUnit as Tasty.HUnit
import qualified Turtle

#if defined(WITH_HTTP) && defined(NETWORK_TESTS)
import qualified Network.HTTP.Client as HTTP
import qualified Network.HTTP.Client.TLS as HTTP
import qualified Network.HTTP.Client as HTTP
import qualified Network.HTTP.Client.TLS as HTTP
#endif


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

Monad.guard (path `notElem` flakyTests)
path `Test.Util.pathNotIn` flakyTests

return path )

Expand All @@ -101,8 +95,9 @@ getTests = do
#endif
]

_ <- Monad.guard (path `notElem` expectedSuccesses)
_ <- Monad.guard (not ("ENV.dhall" `isSuffixOf` (fold (toText path))))
path `Test.Util.pathNotIn` expectedSuccesses
"ENV.dhall" `Test.Util.pathNotSuffixOf` path

return path )

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

let buildNewCache = do
tempdir <- fmap Turtle.decodeString (Turtle.managed (Temp.withSystemTempDirectory "dhall-cache"))
tempdir <- Turtle.managed (Temp.withSystemTempDirectory "dhall-cache")
Turtle.liftIO (Turtle.cptree originalCache tempdir)
return tempdir

Expand Down
2 changes: 0 additions & 2 deletions dhall/tests/Dhall/Test/Lint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ module Dhall.Test.Lint where

import Data.Text (Text)
import Dhall.Parser (Header (..))
import Prelude hiding (FilePath)
import Test.Tasty (TestTree)
import Turtle (FilePath)

import qualified Data.Text as Text
import qualified Data.Text.IO as Text.IO
Expand Down
Loading

0 comments on commit 51c22e4

Please sign in to comment.