Skip to content

Commit 4a3fcaa

Browse files
committed
External commands: Add tests for #9402 #9403 #9404
This adds 4 tests which test the new external commands feature: * ExternalCommand - Tests the expected usage of external command invoked via cabal-install * ExternalCommandSetup - Tests that the ./Setup interface does not support external commands (#9403) * ExternalCommandEnv - Tests that environment variables are set and preserved appropiately (#9402) * ExternalCommandHelp - Test that `cabal help <cmd>` is interpreted appropiately (#9404)
1 parent 15b5b05 commit 4a3fcaa

31 files changed

+488
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# cabal v2-build
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- setup-test-0.1.0.0 (exe:cabal-aaaa) (first run)
6+
Configuring executable 'cabal-aaaa' for setup-test-0.1.0.0...
7+
Preprocessing executable 'cabal-aaaa' for setup-test-0.1.0.0...
8+
Building executable 'cabal-aaaa' for setup-test-0.1.0.0...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: setup-test/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Test.Cabal.Prelude
2+
import qualified System.Process as Process
3+
import Control.Concurrent (threadDelay)
4+
import System.Directory (removeFile)
5+
import Control.Exception (catch, throwIO)
6+
import System.IO.Error (isDoesNotExistError)
7+
import qualified Data.Time.Clock as Time
8+
import qualified Data.Time.Format as Time
9+
import Data.Maybe
10+
import System.Environment
11+
12+
main = do
13+
cabalTest $ do
14+
res <- cabalWithStdin "v2-build" ["all"] ""
15+
exe_path <- withPlan $ planExePath "setup-test" "cabal-aaaa"
16+
env <- getTestEnv
17+
path <- liftIO $ getEnv "PATH"
18+
let newpath = takeDirectory exe_path ++ ":" ++ path
19+
let new_env = (("PATH", Just newpath) : (testEnvironment env))
20+
withEnv new_env $ do
21+
res <- cabal_raw_action ["aaaa"] (\h -> () <$ Process.waitForProcess h)
22+
assertOutputContains "aaaa" res
23+
24+
25+
cabal_raw_action :: [String] -> (Process.ProcessHandle -> IO ()) -> TestM Result
26+
cabal_raw_action args action = do
27+
configured_prog <- requireProgramM cabalProgram
28+
env <- getTestEnv
29+
r <- liftIO $ runAction (testVerbosity env)
30+
(Just (testCurrentDir env))
31+
(testEnvironment env)
32+
(programPath configured_prog)
33+
args
34+
Nothing
35+
action
36+
recordLog r
37+
requireSuccess r
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Main where
2+
3+
main = do
4+
putStrLn "aaaa"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for setup-test
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2023, Matthew Pickering
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Matthew Pickering nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cabal-version: 3.0
2+
name: setup-test
3+
version: 0.1.0.0
4+
-- synopsis:
5+
-- description:
6+
license: BSD-3-Clause
7+
license-file: LICENSE
8+
author: Matthew Pickering
9+
maintainer: [email protected]
10+
-- copyright:
11+
build-type: Simple
12+
extra-doc-files: CHANGELOG.md
13+
-- extra-source-files:
14+
15+
common warnings
16+
ghc-options: -Wall
17+
18+
executable cabal-aaaa
19+
import: warnings
20+
main-is: AAAA.hs
21+
-- other-modules:
22+
-- other-extensions:
23+
build-depends: base ^>=4.18.0.0
24+
hs-source-dirs: .
25+
default-language: Haskell2010
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# cabal v2-build
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- setup-test-0.1.0.0 (exe:cabal-aaaa) (first run)
6+
Configuring executable 'cabal-aaaa' for setup-test-0.1.0.0...
7+
Preprocessing executable 'cabal-aaaa' for setup-test-0.1.0.0...
8+
Building executable 'cabal-aaaa' for setup-test-0.1.0.0...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: setup-test/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Test.Cabal.Prelude
2+
import qualified System.Process as Process
3+
import Control.Concurrent (threadDelay)
4+
import System.Directory (removeFile)
5+
import Control.Exception (catch, throwIO)
6+
import System.IO.Error (isDoesNotExistError)
7+
import qualified Data.Time.Clock as Time
8+
import qualified Data.Time.Format as Time
9+
import Data.Maybe
10+
import System.Environment
11+
12+
main = do
13+
cabalTest $ expectBroken 9402 $ do
14+
res <- cabalWithStdin "v2-build" ["all"] ""
15+
exe_path <- withPlan $ planExePath "setup-test" "cabal-aaaa"
16+
env <- getTestEnv
17+
path <- liftIO $ getEnv "PATH"
18+
let newpath = takeDirectory exe_path ++ ":" ++ path
19+
let new_env = (("OTHER_VAR", Just "is set") : ("PATH", Just newpath) : (testEnvironment env))
20+
21+
withEnv new_env $ do
22+
res <- cabal_raw_action ["aaaa"] (\h -> () <$ Process.waitForProcess h)
23+
assertOutputContains "cabal-install" res
24+
assertOutputContains "is set" res
25+
26+
27+
cabal_raw_action :: [String] -> (Process.ProcessHandle -> IO ()) -> TestM Result
28+
cabal_raw_action args action = do
29+
configured_prog <- requireProgramM cabalProgram
30+
env <- getTestEnv
31+
r <- liftIO $ runAction (testVerbosity env)
32+
(Just (testCurrentDir env))
33+
(testEnvironment env)
34+
(programPath configured_prog)
35+
args
36+
Nothing
37+
action
38+
recordLog r
39+
requireSuccess r
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Main where
2+
3+
import System.Environment
4+
import System.Process
5+
6+
main = do
7+
cabal_proc <- getEnv "CABAL"
8+
other_var <- getEnv "OTHER_VAR"
9+
putStrLn ("OTHER_VAR is set to: " ++ other_var)
10+
callProcess cabal_proc ["--version"]
11+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for setup-test
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2023, Matthew Pickering
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Matthew Pickering nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cabal-version: 3.0
2+
name: setup-test
3+
version: 0.1.0.0
4+
-- synopsis:
5+
-- description:
6+
license: BSD-3-Clause
7+
license-file: LICENSE
8+
author: Matthew Pickering
9+
maintainer: [email protected]
10+
-- copyright:
11+
build-type: Simple
12+
extra-doc-files: CHANGELOG.md
13+
-- extra-source-files:
14+
15+
common warnings
16+
ghc-options: -Wall
17+
18+
executable cabal-aaaa
19+
import: warnings
20+
main-is: AAAA.hs
21+
-- other-modules:
22+
-- other-extensions:
23+
build-depends: base ^>=4.18.0.0, process
24+
hs-source-dirs: .
25+
default-language: Haskell2010
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# cabal v2-build
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- setup-test-0.1.0.0 (exe:cabal-aaaa) (first run)
6+
- setup-test-0.1.0.0 (exe:setup) (first run)
7+
Configuring executable 'cabal-aaaa' for setup-test-0.1.0.0...
8+
Preprocessing executable 'cabal-aaaa' for setup-test-0.1.0.0...
9+
Building executable 'cabal-aaaa' for setup-test-0.1.0.0...
10+
Configuring executable 'setup' for setup-test-0.1.0.0...
11+
Preprocessing executable 'setup' for setup-test-0.1.0.0...
12+
Building executable 'setup' for setup-test-0.1.0.0...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: setup-test/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Test.Cabal.Prelude
2+
import qualified System.Process as Process
3+
import Control.Concurrent (threadDelay)
4+
import System.Directory (removeFile)
5+
import Control.Exception (catch, throwIO)
6+
import System.IO.Error (isDoesNotExistError)
7+
import qualified Data.Time.Clock as Time
8+
import qualified Data.Time.Format as Time
9+
import Data.Maybe
10+
import System.Environment
11+
12+
main = do
13+
cabalTest $ expectBroken 9404 $ do
14+
res <- cabalWithStdin "v2-build" ["all"] ""
15+
exe_path <- withPlan $ planExePath "setup-test" "cabal-aaaa"
16+
env <- getTestEnv
17+
path <- liftIO $ getEnv "PATH"
18+
let newpath = takeDirectory exe_path ++ ":" ++ path
19+
let new_env = (("PATH", Just newpath) : (testEnvironment env))
20+
withEnv new_env $ do
21+
res <- cabal_raw_action ["help", "aaaa"] (\h -> () <$ Process.waitForProcess h)
22+
assertOutputContains "I am helping with the aaaa command" res
23+
24+
25+
cabal_raw_action :: [String] -> (Process.ProcessHandle -> IO ()) -> TestM Result
26+
cabal_raw_action args action = do
27+
configured_prog <- requireProgramM cabalProgram
28+
env <- getTestEnv
29+
r <- liftIO $ runAction (testVerbosity env)
30+
(Just (testCurrentDir env))
31+
(testEnvironment env)
32+
(programPath configured_prog)
33+
args
34+
Nothing
35+
action
36+
recordLog r
37+
requireSuccess r
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Main where
2+
3+
import System.Environment
4+
5+
main = do
6+
args <- getArgs
7+
case args of
8+
["--help"] -> putStrLn "I am helping with the aaaa command"
9+
_ -> putStrLn "aaaa"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for setup-test
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2023, Matthew Pickering
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Matthew Pickering nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cabal-version: 3.0
2+
name: setup-test
3+
version: 0.1.0.0
4+
-- synopsis:
5+
-- description:
6+
license: BSD-3-Clause
7+
license-file: LICENSE
8+
author: Matthew Pickering
9+
maintainer: [email protected]
10+
-- copyright:
11+
build-type: Simple
12+
extra-doc-files: CHANGELOG.md
13+
-- extra-source-files:
14+
15+
common warnings
16+
ghc-options: -Wall
17+
18+
executable cabal-aaaa
19+
import: warnings
20+
main-is: AAAA.hs
21+
-- other-modules:
22+
-- other-extensions:
23+
build-depends: base ^>=4.18.0.0
24+
hs-source-dirs: .
25+
default-language: Haskell2010

cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/LICENSE

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Main where
2+
3+
main = putStrLn "aaaa"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cabal-version: 3.0
2+
name: aaaa
3+
version: 0.1.0.0
4+
license: BSD-3-Clause
5+
license-file: LICENSE
6+
author: Matthew Pickering
7+
maintainer: [email protected]
8+
build-type: Simple
9+
extra-doc-files: CHANGELOG.md
10+
-- extra-source-files:
11+
12+
common warnings
13+
ghc-options: -Wall
14+
15+
executable cabal-aaaa
16+
import: warnings
17+
main-is: Main.hs
18+
-- other-modules:
19+
-- other-extensions:
20+
build-depends: base ^>=4.18.0.0
21+
hs-source-dirs: .
22+
default-language: Haskell2010

0 commit comments

Comments
 (0)