Skip to content
Snippets Groups Projects
Commit e9032c0b authored by Patrick Augusto's avatar Patrick Augusto
Browse files

Interactive workflow for standalone tests

parent 11ffc583
No related branches found
No related tags found
No related merge requests found
......@@ -135,7 +135,11 @@ getExtraDocFiles = pure
-- | Ask whether the project builds a library or executable.
getPackageType :: Interactive m => InitFlags -> m PackageType -> m PackageType
getPackageType flags = fromFlagOrPrompt (packageType flags)
getPackageType InitFlags
{ initializeTestSuite = Flag True
, packageType = NoFlag
} _ = return TestSuite
getPackageType flags act = fromFlagOrPrompt (packageType flags) act
getMainFile :: Interactive m => InitFlags -> m HsFilePath -> m HsFilePath
getMainFile flags act = case mainIs flags of
......@@ -238,12 +242,14 @@ packageTypePrompt flags = getPackageType flags $ do
[ "Library"
, "Executable"
, "Library and Executable"
, "Test suite"
]
parsePackageType = \case
"Library" -> Just Library
"Executable" -> Just Executable
"Library and Executable" -> Just LibraryAndExecutable
"Test suite" -> Just TestSuite
_ -> Nothing
testMainPrompt :: Interactive m => m HsFilePath
......
......@@ -137,6 +137,16 @@ createProject v pkgIx srcDb initFlags = do
return $ ProjectSettings
(mkOpts comments cabalSpec) pkgDesc (Just libTarget)
(Just exeTarget) testTarget
TestSuite -> do
testTarget <- addLibDepToTest pkgName <$>
genTestTarget initFlags pkgIx
comments <- noCommentsPrompt initFlags
return $ ProjectSettings
(mkOpts comments cabalSpec) pkgDesc
Nothing Nothing testTarget
where
-- Add package name as dependency of test suite
--
......@@ -229,7 +239,7 @@ genTestTarget
=> InitFlags
-> InstalledPackageIndex
-> m (Maybe TestTarget)
genTestTarget flags pkgs = initializeTestSuitePrompt flags >>= go
genTestTarget flags pkgs = initializeTestSuitePrompt (flags {initializeTestSuite = NoFlag}) >>= go
where
go initialized
| not initialized = return Nothing
......
......@@ -71,7 +71,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
, dependencies = Flag []
}
case (_runPrompt $ createProject silent pkgIx srcDb dummyFlags') (fromList ["3", "quxTest/Main.hs"]) of
case (_runPrompt $ createProject silent pkgIx srcDb dummyFlags') (fromList ["y", "3", "quxTest/Main.hs"]) of
Right (ProjectSettings opts desc (Just lib) (Just exe) (Just test), _) -> do
_optOverwrite opts @?= False
_optMinimal opts @?= False
......@@ -164,6 +164,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
-- language
, "2"
-- test target
, "y"
-- main file
, "1"
-- test dir
......@@ -174,7 +175,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
, "y"
]
case (_runPrompt $ createProject silent pkgIx srcDb (emptyFlags {initializeTestSuite = Flag True})) inputs of
case (_runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
Right (ProjectSettings opts desc (Just lib) (Just exe) (Just test), _) -> do
_optOverwrite opts @?= False
_optMinimal opts @?= False
......@@ -258,6 +259,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
-- language
, "2"
-- test target
, "y"
-- main file
, "1"
-- test dir
......@@ -268,7 +270,7 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
, "y"
]
case (_runPrompt $ createProject silent pkgIx srcDb (emptyFlags {initializeTestSuite = Flag True})) inputs of
case (_runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
Right (ProjectSettings opts desc (Just lib) Nothing (Just test), _) -> do
_optOverwrite opts @?= False
_optMinimal opts @?= False
......@@ -311,6 +313,80 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
exe @?= Nothing
test @?! Nothing
Left e -> assertFailure $ show e
, testCase "Check the interactive library workflow" $ do
let inputs = fromList
-- package type
[ "4"
-- package dir
, "test-package"
-- package description
-- cabal version
, "4"
-- package name
, "test-package"
, "test-package"
-- version
, "3.1.2.3"
-- license
, "3"
-- author
, "Foobar"
-- email
, "foobar@qux.com"
-- homepage
, "qux.com"
-- synopsis
, "Qux's package"
-- category
, "3"
-- test target
, "y"
-- main file
, "1"
-- test dir
, "test"
-- language
, "1"
-- comments
, "y"
]
case (_runPrompt $ createProject silent pkgIx srcDb emptyFlags) inputs of
Right (ProjectSettings opts desc Nothing Nothing (Just test), _) -> do
_optOverwrite opts @?= False
_optMinimal opts @?= False
_optNoComments opts @?= False
_optVerbosity opts @?= silent
_optPkgDir opts @?= "/home/test/test-package"
_optPkgType opts @?= TestSuite
_optPkgName opts @?= mkPackageName "test-package"
_pkgCabalVersion desc @?= CabalSpecV2_4
_pkgName desc @?= mkPackageName "test-package"
_pkgVersion desc @?= mkVersion [3,1,2,3]
_pkgLicense desc @?! SPDX.NONE
_pkgAuthor desc @?= "Foobar"
_pkgEmail desc @?= "foobar@qux.com"
_pkgHomePage desc @?= "qux.com"
_pkgSynopsis desc @?= "Qux's package"
_pkgCategory desc @?= "Control"
_pkgExtraSrcFiles desc @?= mempty
_pkgExtraDocFiles desc @?= pure (Set.singleton "CHANGELOG.md")
_testMainIs test @?= HsFilePath "Main.hs" Standard
_testDirs test @?= ["test"]
_testLanguage test @?= Haskell2010
_testOtherModules test @?= []
_testOtherExts test @?= []
_testDependencies test @?! []
_testBuildTools test @?= []
Right (ProjectSettings _ _ lib exe test, _) -> do
lib @?= Nothing
exe @?= Nothing
test @?! Nothing
Left e -> assertFailure $ show e
]
, testGroup "without tests"
[ testCase "Check the interactive library and executable workflow" $ do
......@@ -668,13 +744,13 @@ fileCreatorTests pkgIx srcDb _pkgName = testGroup "generators"
, testGroup "genTestTarget"
[ testCase "Check test package flags workflow" $ do
let inputs = fromList
[ "1" -- pick the first main file option in the list
[ "y" -- say yes to tests
, "1" -- pick the first main file option in the list
, "test" -- package test dir
, "1" -- pick the first language in the list
]
runGenTest inputs $ genTestTarget
(emptyFlags {initializeTestSuite = Flag True}) pkgIx
runGenTest inputs $ genTestTarget emptyFlags pkgIx
]
]
where
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment