-
Notifications
You must be signed in to change notification settings - Fork 727
Add tests for active-repositories feature #11684
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
erikd
wants to merge
1
commit into
haskell:master
Choose a base branch
from
erikd:master
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.
Open
Changes from all commits
Commits
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
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
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
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
169 changes: 169 additions & 0 deletions
169
cabal-install/tests/UnitTests/Distribution/Client/IndexUtils/ActiveRepos.hs
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 |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| module UnitTests.Distribution.Client.IndexUtils.ActiveRepos (tests) where | ||
|
|
||
| import Distribution.Client.IndexUtils.ActiveRepos | ||
| import Distribution.Client.Types.RepoName (RepoName (..)) | ||
| import Distribution.Parsec (simpleParsec) | ||
| import Distribution.Pretty (prettyShow) | ||
|
|
||
| import UnitTests.Distribution.Client.ArbitraryInstances () | ||
|
|
||
| import Test.Tasty | ||
| import Test.Tasty.HUnit | ||
| import Test.Tasty.QuickCheck | ||
|
|
||
| tests :: [TestTree] | ||
| tests = | ||
| [ testGroup "organizeByRepos" organizeByReposTests | ||
| , testGroup "filterSkippedActiveRepos" filterSkippedTests | ||
| , testGroup | ||
| "parse/pretty roundtrip" | ||
| [ testProperty "ActiveRepos roundtrips" prop_activeReposRoundtrip | ||
| ] | ||
| ] | ||
|
|
||
| ------------------------------------------------------------------------------- | ||
| -- organizeByRepos | ||
| ------------------------------------------------------------------------------- | ||
|
|
||
| -- Convenience: run organizeByRepos over a fixed three-element repo list. | ||
| organize :: ActiveRepos -> Either String [(RepoName, CombineStrategy)] | ||
| organize ar = organizeByRepos ar id [RepoName "a", RepoName "b", RepoName "c"] | ||
|
|
||
| organizeByReposTests :: [TestTree] | ||
| organizeByReposTests = | ||
| [ testCase ":rest assigns strategy to all repos in order" $ | ||
| organize (ActiveRepos [ActiveRepoRest CombineStrategyMerge]) | ||
| @?= Right | ||
| [ (RepoName "a", CombineStrategyMerge) | ||
| , (RepoName "b", CombineStrategyMerge) | ||
| , (RepoName "c", CombineStrategyMerge) | ||
| ] | ||
| , testCase ":none yields empty result" $ | ||
| organize (ActiveRepos []) | ||
| @?= Right [] | ||
| , testCase "named repo before :rest is placed first" $ | ||
| organize | ||
| ( ActiveRepos | ||
| [ ActiveRepo (RepoName "b") CombineStrategyOverride | ||
| , ActiveRepoRest CombineStrategyMerge | ||
| ] | ||
| ) | ||
| @?= Right | ||
| [ (RepoName "b", CombineStrategyOverride) | ||
| , (RepoName "a", CombineStrategyMerge) | ||
| , (RepoName "c", CombineStrategyMerge) | ||
| ] | ||
| , testCase "named repo after :rest is placed last" $ | ||
| organize | ||
| ( ActiveRepos | ||
| [ ActiveRepoRest CombineStrategyMerge | ||
| , ActiveRepo (RepoName "b") CombineStrategyOverride | ||
| ] | ||
| ) | ||
| @?= Right | ||
| [ (RepoName "a", CombineStrategyMerge) | ||
| , (RepoName "c", CombineStrategyMerge) | ||
| , (RepoName "b", CombineStrategyOverride) | ||
| ] | ||
| , testCase "named repo absent from provided list gives Left" $ | ||
| organize | ||
| ( ActiveRepos | ||
| [ ActiveRepoRest CombineStrategyMerge | ||
| , ActiveRepo (RepoName "d") CombineStrategyOverride | ||
| ] | ||
| ) | ||
| @?= Left "no repository provided d" | ||
| , testCase "named repo against empty list gives Left" $ | ||
| organizeByRepos | ||
| (ActiveRepos [ActiveRepo (RepoName "a") CombineStrategyMerge]) | ||
| id | ||
| ([] :: [RepoName]) | ||
| @?= Left "no repository provided a" | ||
| , testCase "skip strategy is preserved in output" $ | ||
| organize | ||
| ( ActiveRepos | ||
| [ ActiveRepo (RepoName "a") CombineStrategySkip | ||
| , ActiveRepoRest CombineStrategyMerge | ||
| ] | ||
| ) | ||
| @?= Right | ||
| [ (RepoName "a", CombineStrategySkip) | ||
| , (RepoName "b", CombineStrategyMerge) | ||
| , (RepoName "c", CombineStrategyMerge) | ||
| ] | ||
| , testCase ":rest with skip strategy skips all remaining repos" $ | ||
| organize (ActiveRepos [ActiveRepoRest CombineStrategySkip]) | ||
| @?= Right | ||
| [ (RepoName "a", CombineStrategySkip) | ||
| , (RepoName "b", CombineStrategySkip) | ||
| , (RepoName "c", CombineStrategySkip) | ||
| ] | ||
| , testCase "multiple :rest entries cause each repo to appear once per :rest" $ | ||
| -- Documented edge case: if ActiveRepoRest appears more than once, | ||
| -- the rest-repositories appear multiple times in the output. | ||
| organize | ||
| ( ActiveRepos | ||
| [ ActiveRepoRest CombineStrategyMerge | ||
| , ActiveRepoRest CombineStrategyOverride | ||
| ] | ||
| ) | ||
| @?= Right | ||
| [ (RepoName "a", CombineStrategyMerge) | ||
| , (RepoName "b", CombineStrategyMerge) | ||
| , (RepoName "c", CombineStrategyMerge) | ||
| , (RepoName "a", CombineStrategyOverride) | ||
| , (RepoName "b", CombineStrategyOverride) | ||
| , (RepoName "c", CombineStrategyOverride) | ||
| ] | ||
| ] | ||
|
|
||
| ------------------------------------------------------------------------------- | ||
| -- filterSkippedActiveRepos | ||
| ------------------------------------------------------------------------------- | ||
|
|
||
| filterSkippedTests :: [TestTree] | ||
| filterSkippedTests = | ||
| [ testCase "skipped entries are removed when no :rest is present" $ | ||
| filterSkippedActiveRepos | ||
| ( ActiveRepos | ||
| [ ActiveRepo (RepoName "a") CombineStrategyMerge | ||
| , ActiveRepo (RepoName "b") CombineStrategySkip | ||
| ] | ||
| ) | ||
| @?= ActiveRepos [ActiveRepo (RepoName "a") CombineStrategyMerge] | ||
| , testCase "all-skipped list with no :rest yields empty" $ | ||
| filterSkippedActiveRepos | ||
| ( ActiveRepos | ||
| [ ActiveRepo (RepoName "a") CombineStrategySkip | ||
| , ActiveRepo (RepoName "b") CombineStrategySkip | ||
| ] | ||
| ) | ||
| @?= ActiveRepos [] | ||
| , testCase "list without any skipped entries is unchanged" $ | ||
| let ar = | ||
| ActiveRepos | ||
| [ ActiveRepo (RepoName "a") CombineStrategyMerge | ||
| , ActiveRepo (RepoName "b") CombineStrategyOverride | ||
| ] | ||
| in filterSkippedActiveRepos ar @?= ar | ||
| , testCase "skipped entries are kept when :rest is present" $ | ||
| -- filterSkippedActiveRepos is a no-op when ActiveRepoRest appears | ||
| let ar = | ||
| ActiveRepos | ||
| [ ActiveRepoRest CombineStrategyMerge | ||
| , ActiveRepo (RepoName "b") CombineStrategySkip | ||
| ] | ||
| in filterSkippedActiveRepos ar @?= ar | ||
| , testCase ":rest with skip strategy is kept unchanged" $ | ||
| let ar = ActiveRepos [ActiveRepoRest CombineStrategySkip] | ||
| in filterSkippedActiveRepos ar @?= ar | ||
| ] | ||
|
|
||
| ------------------------------------------------------------------------------- | ||
| -- Parse/pretty roundtrip | ||
| ------------------------------------------------------------------------------- | ||
|
|
||
| prop_activeReposRoundtrip :: ActiveRepos -> Property | ||
| prop_activeReposRoundtrip ar = | ||
| counterexample ("prettyShow: " ++ prettyShow ar) $ | ||
| simpleParsec (prettyShow ar) === Just ar |
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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| synopsis: Add unit tests for active-repositories feature | ||
| packages: [cabal-install] | ||
| prs: 11684 | ||
| --- | ||
|
|
||
| Add unit tests for the `active-repositories` cabal configuration field: | ||
|
|
||
| - `organizeByRepos`: ordering and strategy assignment with `:rest`, named repos, and error cases | ||
| - `filterSkippedActiveRepos`: filtering of skipped entries in the absence of `:rest` | ||
| - `CombineStrategy` index-combining logic (Skip/Merge/Override) | ||
| - Parse/pretty roundtrip for `ActiveRepos` (QuickCheck) |
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.
This comments seems wrong. Below we have
So
repoFoo12hasfoo-1.0andfoo-2.0. I am not sure what was intended.Uh oh!
There was an error while loading. Please reload this page.
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.
The full test case is:
So the test is to ensure that
CombineStrategyOverridedoes in fact completely overrideCombineStrategyMerge.Am I missing something?
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 was just referring to the comment
repoFoo12 has foo-1.0 and foo-1.1. It seems to me that repoFoo12 has foo-1.0 and foo-2.0. Maybe I misunderstood.