-
Notifications
You must be signed in to change notification settings - Fork 712
Don't create spurious dirs on init #7262
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Testing `cabal-install` | ||
|
||
Local testing | ||
======= | ||
|
||
In order to effectively test the `cabal-install` library, the `cabal-install.cabal` file must be modified | ||
to build the targets in the `/test` directory. The current recommended way to set this up is to | ||
use the [makefile](../Makefile) supplied in the `Cabal` project parent directory, issuing the following command: | ||
|
||
|
||
``` | ||
> make cabal-install-dev | ||
``` | ||
|
||
This command will copy the dev `.cabal` generated by a project build into the `cabal-install.cabal`, and set your git index to ignore | ||
any changes to that file. Any subsequent changes to the `.cabal` should unset and reset the git index to make sure you don't end up committing it. | ||
From there, tests may be built with `cabal test` as usual. To choose a particular test so you don't end up running the whole thing, you can issue | ||
`tasty`-style pattern expressions like the following: | ||
|
||
``` | ||
> cabal run cabal-install:unit-tests -- -p /cabal init/ | ||
``` | ||
|
||
Please remember to test your changes! Happy hacking. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
module UnitTests.Distribution.Client.Init.FileCreators ( | ||
tests | ||
module UnitTests.Distribution.Client.Init | ||
( tests | ||
) where | ||
|
||
import Distribution.Client.Init.FileCreators | ||
( generateCabalFile ) | ||
|
||
import Test.Tasty | ||
import Test.Tasty.HUnit | ||
import Test.Tasty.Golden (goldenVsString) | ||
|
||
import System.FilePath | ||
( (</>) ) | ||
import qualified Data.ByteString.Lazy as BS | ||
import qualified Data.ByteString.Lazy.Char8 as BS8 | ||
|
||
import Distribution.Client.Init.Command | ||
( getLibOrExec, getAppDir, getSrcDir ) | ||
import Distribution.Client.Init.Types | ||
( InitFlags(..), PackageType(..), defaultInitFlags ) | ||
import Distribution.Simple.Setup | ||
|
@@ -40,6 +43,11 @@ tests = [ testGroup "cabal init goldens" | |
, checkCabalFileGolden libExeAndTestFlags "lib-exe-and-test-golden.cabal" | ||
, checkCabalFileGolden libExeAndTestWithCommentsFlags "lib-exe-and-test-with-comments-golden.cabal" | ||
] | ||
, testGroup "Check init flag outputs against init script builds" | ||
[ checkInitFlags "Check library-only build flags" libFlags Library | ||
, checkInitFlags "Check lib+exe build flags" libAndExeFlags LibraryAndExecutable | ||
, checkInitFlags "Check exe-only build flags" exeFlags Executable | ||
] | ||
] | ||
|
||
checkCabalFileGolden :: InitFlags -> FilePath -> TestTree | ||
|
@@ -52,6 +60,22 @@ checkCabalFileGolden flags goldenFileName = | |
generatedCabalFile :: IO BS.ByteString | ||
generatedCabalFile = pure . BS8.pack $ generateCabalFile goldenFileName flags | ||
|
||
checkInitFlags :: String -> InitFlags -> PackageType -> TestTree | ||
checkInitFlags label flags pkgType = testCase label $ do | ||
flags' <- getLibOrExec rawFlags | ||
>>= getAppDir | ||
>>= getSrcDir | ||
|
||
flags @=? flags' | ||
where | ||
rawFlags | ||
| pkgType == Executable = baseFlags | ||
{ packageType = Flag pkgType | ||
, exposedModules = Nothing | ||
} | ||
| otherwise = baseFlags { packageType = Flag pkgType } | ||
|
||
|
||
-- ================================================== | ||
-- Base flags to set common InitFlags values. | ||
|
||
|
@@ -90,12 +114,23 @@ baseFlags = defaultInitFlags { | |
, mainIs = Flag "Main.hs" | ||
, applicationDirs = Just ["app"] | ||
, sourceDirs = Nothing | ||
, exposedModules = Nothing | ||
, exposedModules = Just [ModuleName.fromString "MyLib"] | ||
, initializeTestSuite = Flag False | ||
, testDirs = Nothing | ||
} | ||
|
||
|
||
-- ================================================== | ||
-- Simple library flags | ||
|
||
libFlags :: InitFlags | ||
libFlags = baseFlags | ||
{ packageType = Flag Library | ||
, mainIs = NoFlag | ||
, sourceDirs = Just ["src"] | ||
, applicationDirs = Just [] | ||
} | ||
|
||
-- ================================================== | ||
-- Simple exe. | ||
|
||
|
@@ -104,7 +139,9 @@ exeFlags = baseFlags { | |
-- Create an executable only, with main living in app/Main.hs. | ||
packageType = Flag Executable | ||
, mainIs = Flag "Main.hs" | ||
, sourceDirs = Just [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
, applicationDirs = Just ["app"] | ||
, exposedModules = Nothing | ||
} | ||
|
||
|
||
|
@@ -127,7 +164,6 @@ libAndExeFlags = baseFlags { | |
|
||
-- Library sources live in src/ and expose the module MyLib. | ||
, sourceDirs = Just ["src"] | ||
, exposedModules = Just (map ModuleName.fromString ["MyLib"]) | ||
} | ||
|
||
|
||
|
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: Bugfix - stop creating spurious dirs on `init` | ||
packages: cabal-install | ||
prs: #7262 | ||
issues: #6772 | ||
|
||
description { | ||
|
||
- Add `TESTING.md` to `cabal-install` providing instructions for locally `cabal-install` testing, | ||
along with corresponding entry in `CONTRIBUTING.md`. | ||
- Base directory output on package type when using the `init` command. | ||
|
||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.