Skip to content

testsuite: Add test for #9334 #9452

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Cabal-QuickCheck/src/Test/QuickCheck/Instances/Cabal.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Test.QuickCheck.Instances.Cabal () where
module Test.QuickCheck.Instances.Cabal ( ShortPath(..) ) where

import Control.Applicative (liftA2)
import Data.Bits (shiftR)
Expand Down Expand Up @@ -56,6 +56,15 @@ import qualified Distribution.Compat.NonEmptySet as NES
import Control.Applicative (pure, (<$>), (<*>))
#endif

-------------------------------------------------------------------------------
-- ShortPath
-------------------------------------------------------------------------------

newtype ShortPath = ShortPath FilePath deriving (Show)

instance Arbitrary ShortPath where
arbitrary = ShortPath <$> arbitraryShortPath

-------------------------------------------------------------------------------
-- CabalSpecVersion
-------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ test-suite unit-tests
UnitTests.Distribution.Solver.Modular.DSL.TestCaseUtils
UnitTests.Distribution.Solver.Modular.WeightedPSQ
UnitTests.Distribution.Solver.Types.OptionalStanza
UnitTests.Distribution.Client.ScriptUtils
UnitTests.Options

build-depends:
Expand Down
4 changes: 4 additions & 0 deletions cabal-install/tests/UnitTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import qualified UnitTests.Distribution.Client.Store
import qualified UnitTests.Distribution.Client.Tar
import qualified UnitTests.Distribution.Client.Targets
import qualified UnitTests.Distribution.Client.UserConfig
import qualified UnitTests.Distribution.Client.ScriptUtils
import qualified UnitTests.Distribution.Solver.Modular.Builder
import qualified UnitTests.Distribution.Solver.Modular.RetryLog
import qualified UnitTests.Distribution.Solver.Modular.Solver
Expand All @@ -43,6 +44,9 @@ main = do
, testGroup
"UnitTests.Distribution.Client.Get"
UnitTests.Distribution.Client.Get.tests
, testGroup
"UnitTests.Distribution.Client.ScriptUtils"
UnitTests.Distribution.Client.ScriptUtils.tests
, testGroup
"UnitTests.Distribution.Client.Glob"
UnitTests.Distribution.Client.Glob.tests
Expand Down
37 changes: 37 additions & 0 deletions cabal-install/tests/UnitTests/Distribution/Client/ScriptUtils.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}

module UnitTests.Distribution.Client.ScriptUtils (tests) where

import Distribution.Client.ScriptUtils
import Distribution.Client.Config
import Test.Tasty
import Test.Tasty.QuickCheck
import Test.QuickCheck.Instances.Cabal
import System.FilePath

tests :: [TestTree]
tests =
[ testGroup
"ScriptUtils"
[ testProperty "valid_script_path" testScriptPath
]
]

-- ------------------------------------------------------------

-- * Unit tests

-- ------------------------------------------------------------

testScriptPath :: ShortPath -> Property
testScriptPath (ShortPath p) = withMaxSuccess 10000 $ ioProperty $ do
hashed_path <- getScriptCacheDirectory p
script_build_dir <- defaultScriptBuildsDir
return $ and
-- 1. Is it a valid path at all
[ isValid hashed_path
-- 2. Is the computed hashed path in the expected directory?
, (script_build_dir </> takeFileName hashed_path) `equalFilePath` hashed_path
]

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- fake-package-0 (exe:script-main.hs) --enable-profiling (first run)
Configuring executable 'script-main.hs' for fake-package-0...
Building executable 'script-main.hs' for fake-package-0...
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest $ do
res <- cabal' "v2-run" ["--enable-profiling", "./main.hs"]
assertOutputContains "2" res
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/NewBuild/CmdRun/RunProf/main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{- cabal:
build-depends: base
-}

main = print $ 1 + 1