@@ -9,6 +9,8 @@ module Stack.Build.Execute
99 ( printPlan
1010 , preFetch
1111 , executePlan
12+ -- TESTING
13+ , compareTestsComponents
1214 ) where
1315
1416import Control.Applicative ((<$>) , (<*>) )
@@ -680,11 +682,19 @@ singleTest ac ee task =
680682 _ -> assert False True )
681683 || True -- FIXME above logic is incorrect, see: https://github.com/commercialhaskell/stack/issues/319
682684 needHpc = boptsCoverage (eeBuildOpts ee)
685+
686+ componentsRaw =
687+ case taskType task of
688+ TTLocal lp -> Set. toList $ lpComponents lp
689+ TTUpstream _ _ -> assert False []
690+ testsToRun = compareTestsComponents componentsRaw $ Set. toList $ packageTests package
691+ components = map (T. unpack . T. append " test:" ) testsToRun
692+
683693 when needBuild $ do
684694 announce " build (test)"
685695 fileModTimes <- getPackageFileModTimes package cabalfp
686696 writeBuildCache pkgDir fileModTimes
687- cabal (console && configHideTHLoading config) [ " build" ]
697+ cabal (console && configHideTHLoading config) $ " build" : components
688698
689699 bconfig <- asks getBuildConfig
690700 buildDir <- distDirFromDir pkgDir
@@ -696,7 +706,7 @@ singleTest ac ee task =
696706 Platform _ Windows -> " .exe"
697707 _ -> " "
698708
699- errs <- liftM Map. unions $ forM ( Set. toList $ packageTests package) $ \ testName -> do
709+ errs <- liftM Map. unions $ forM testsToRun $ \ testName -> do
700710 nameDir <- parseRelDir $ T. unpack testName
701711 nameExe <- parseRelFile $ T. unpack testName ++ exeExtension
702712 nameTix <- liftM (pkgDir </> ) $ parseRelFile $ T. unpack testName ++ " .tix"
@@ -778,6 +788,22 @@ singleTest ac ee task =
778788 (fmap fst mlogFile)
779789 bs
780790
791+ -- | Determine the tests to be run based on the list of components.
792+ compareTestsComponents :: [Text ] -- ^ components
793+ -> [Text ] -- ^ all test names
794+ -> [Text ] -- ^ tests to be run
795+ compareTestsComponents [] tests = tests -- no components -- all tests
796+ compareTestsComponents comps tests2 =
797+ Set. toList $ Set. intersection tests1 $ Set. fromList tests2
798+ where
799+ tests1 = Set. unions $ map toSet comps
800+
801+ toSet x =
802+ case T. break (== ' :' ) x of
803+ (y, " " ) -> assert (x == y) (Set. singleton x)
804+ (" test" , y) -> Set. singleton $ T. drop 1 y
805+ _ -> Set. empty
806+
781807-- | Generate the HTML report and
782808generateHpcReport
783809 :: M env m
0 commit comments