-
Notifications
You must be signed in to change notification settings - Fork 724
Per-field GenericPackageDescription golden test
#11285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leana8959
wants to merge
8
commits into
haskell:master
Choose a base branch
from
leana8959:accessor-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+708
−694
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9c98990
tests: add tests for accessors
leana8959 791eb8c
test: check equality on each field
leana8959 70813d1
tests: use distinct file for each field
leana8959 6f81ea8
tests: improve import list
leana8959 1da8c79
tests: remove unused tuple instance
leana8959 a8944c3
tests: use @? operator
leana8959 eba877b
tests: use a tuple to store all gpd fields
leana8959 340c4c7
tests: update expected
leana8959 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,19 @@ import Control.Monad (unless, void) | |
| import Data.Algorithm.Diff (PolyDiff (..), getGroupedDiff) | ||
| import Data.Maybe (isNothing) | ||
| import Distribution.Fields (pwarning) | ||
| import Distribution.PackageDescription (GenericPackageDescription) | ||
| import Distribution.PackageDescription | ||
| ( GenericPackageDescription | ||
| ( packageDescription | ||
| , gpdScannedVersion | ||
| , genPackageFlags | ||
| , condLibrary | ||
| , condSubLibraries | ||
| , condForeignLibs | ||
| , condExecutables | ||
| , condTestSuites | ||
| , condBenchmarks | ||
| ) | ||
| ) | ||
| import Distribution.PackageDescription.Parsec (parseGenericPackageDescription) | ||
| import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription) | ||
| import Distribution.Parsec (PWarnType (..), PWarning (..), showPErrorWithSource, showPWarningWithSource) | ||
|
|
@@ -237,7 +249,16 @@ treeDiffGoldenTest fp = ediffGolden goldenTest "expr" exprFile $ do | |
| let res = withSource (PCabalFile (fp, contents)) $ parseGenericPackageDescription contents | ||
| let (_, x) = runParseResult res | ||
| case x of | ||
| Right gpd -> pure (toExpr gpd) | ||
| Right gpd -> pure $ toExpr | ||
| ( gpd | ||
| -- Test accessors because they encapsulate the merging behaviour | ||
| , condLibrary gpd | ||
| , condSubLibraries gpd | ||
| , condForeignLibs gpd | ||
| , condExecutables gpd | ||
| , condTestSuites gpd | ||
| , condBenchmarks gpd | ||
| ) | ||
| Left (_, errs) -> fail $ unlines $ "ERROR" : map (showPErrorWithSource . fmap renderCabalFileSource) (NE.toList errs) | ||
| where | ||
| input = "tests" </> "ParserTests" </> "regressions" </> fp | ||
|
|
@@ -250,24 +271,38 @@ formatRoundTripTest fp = testCase "roundtrip" $ do | |
| x <- parse contents | ||
| let contents' = showGenericPackageDescription x | ||
| y <- parse (toUTF8BS contents') | ||
| -- previously we mangled licenses a bit | ||
| let y' = y | ||
|
|
||
| let checkField field = | ||
| unless (field x == field y) $ | ||
|
||
| {- FOURMOLU_DISABLE -} | ||
| unless (x == y') $ | ||
| #ifdef MIN_VERSION_tree_diff | ||
| assertFailure $ unlines | ||
| [ "re-parsed doesn't match" | ||
| , show $ ansiWlEditExpr $ ediff x y | ||
| ] | ||
| assertFailure $ unlines | ||
| [ "re-parsed doesn't match" | ||
| , show $ ansiWlEditExpr $ ediff x y | ||
| ] | ||
| #else | ||
| assertFailure $ unlines | ||
| [ "re-parsed doesn't match" | ||
| , "expected" | ||
| , show x | ||
| , "actual" | ||
| , show y | ||
| ] | ||
| assertFailure $ unlines | ||
| [ "re-parsed doesn't match" | ||
| , "expected" | ||
| , show x | ||
| , "actual" | ||
| , show y | ||
| ] | ||
| #endif | ||
| -- Due to the imports being merged, the structural comparison will fail | ||
| -- Instead, we check the equality after merging | ||
| sequence_ | ||
| [ checkField packageDescription | ||
| , checkField gpdScannedVersion | ||
| , checkField genPackageFlags | ||
| , checkField condLibrary | ||
| , checkField condSubLibraries | ||
| , checkField condForeignLibs | ||
| , checkField condExecutables | ||
| , checkField condTestSuites | ||
| , checkField condBenchmarks | ||
| ] | ||
|
|
||
| where | ||
| parse :: BS.ByteString -> IO GenericPackageDescription | ||
| parse c = do | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general it's more robust to
import Distribution.PackageDescription (GenericPackageDescription, fooField, bazField)thanimport Distribution.PackageDescription (GenericPackageDescription (fooField, bazField)). If in future the fields of GPD are changed and old accessors become simple functions (retained for backwards compatibility), the first form survives without a change, while the second would have to be amended.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know this is possible, I'll change this :)