From fb73d5df78d29f7948e709b98126201034d40150 Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Fri, 3 Nov 2023 14:56:34 +0000 Subject: [PATCH] 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 ` is interpreted appropiately (#9404) --- .../PackageTests/ExternalCommand/cabal.out | 8 ++++ .../ExternalCommand/cabal.project | 1 + .../ExternalCommand/cabal.test.hs | 37 ++++++++++++++++++ .../ExternalCommand/setup-test/AAAA.hs | 4 ++ .../ExternalCommand/setup-test/CHANGELOG.md | 5 +++ .../ExternalCommand/setup-test/LICENSE | 30 ++++++++++++++ .../setup-test/setup-test.cabal | 25 ++++++++++++ .../PackageTests/ExternalCommandEnv/cabal.out | 8 ++++ .../ExternalCommandEnv/cabal.project | 1 + .../ExternalCommandEnv/cabal.test.hs | 39 +++++++++++++++++++ .../ExternalCommandEnv/setup-test/AAAA.hs | 11 ++++++ .../setup-test/CHANGELOG.md | 5 +++ .../ExternalCommandEnv/setup-test/LICENSE | 30 ++++++++++++++ .../setup-test/setup-test.cabal | 25 ++++++++++++ .../ExternalCommandHelp/cabal.out | 12 ++++++ .../ExternalCommandHelp/cabal.project | 1 + .../ExternalCommandHelp/cabal.test.hs | 37 ++++++++++++++++++ .../ExternalCommandHelp/setup-test/AAAA.hs | 9 +++++ .../setup-test/CHANGELOG.md | 5 +++ .../ExternalCommandHelp/setup-test/LICENSE | 30 ++++++++++++++ .../setup-test/setup-test.cabal | 25 ++++++++++++ .../ExternalCommandSetup/aaaa/LICENSE | 0 .../ExternalCommandSetup/aaaa/Main.hs | 3 ++ .../ExternalCommandSetup/aaaa/aaaa.cabal | 22 +++++++++++ .../ExternalCommandSetup/custom/CHANGELOG.md | 5 +++ .../ExternalCommandSetup/custom/LICENSE | 30 ++++++++++++++ .../ExternalCommandSetup/custom/Setup.hs | 3 ++ .../ExternalCommandSetup/custom/custom.cabal | 29 ++++++++++++++ .../ExternalCommandSetup/custom/src/MyLib.hs | 4 ++ .../ExternalCommandSetup/setup.cabal.hs | 17 ++++++++ .../ExternalCommandSetup/setup.out | 22 +++++++++++ cabal-testsuite/src/Test/Cabal/Prelude.hs | 12 ++++-- 32 files changed, 492 insertions(+), 3 deletions(-) create mode 100644 cabal-testsuite/PackageTests/ExternalCommand/cabal.out create mode 100644 cabal-testsuite/PackageTests/ExternalCommand/cabal.project create mode 100644 cabal-testsuite/PackageTests/ExternalCommand/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/ExternalCommand/setup-test/AAAA.hs create mode 100644 cabal-testsuite/PackageTests/ExternalCommand/setup-test/CHANGELOG.md create mode 100644 cabal-testsuite/PackageTests/ExternalCommand/setup-test/LICENSE create mode 100644 cabal-testsuite/PackageTests/ExternalCommand/setup-test/setup-test.cabal create mode 100644 cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.out create mode 100644 cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.project create mode 100644 cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/AAAA.hs create mode 100644 cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/CHANGELOG.md create mode 100644 cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/LICENSE create mode 100644 cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/setup-test.cabal create mode 100644 cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.out create mode 100644 cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.project create mode 100644 cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/AAAA.hs create mode 100644 cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/CHANGELOG.md create mode 100644 cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/LICENSE create mode 100644 cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/setup-test.cabal create mode 100644 cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/LICENSE create mode 100644 cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/Main.hs create mode 100644 cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/aaaa.cabal create mode 100644 cabal-testsuite/PackageTests/ExternalCommandSetup/custom/CHANGELOG.md create mode 100644 cabal-testsuite/PackageTests/ExternalCommandSetup/custom/LICENSE create mode 100644 cabal-testsuite/PackageTests/ExternalCommandSetup/custom/Setup.hs create mode 100644 cabal-testsuite/PackageTests/ExternalCommandSetup/custom/custom.cabal create mode 100644 cabal-testsuite/PackageTests/ExternalCommandSetup/custom/src/MyLib.hs create mode 100644 cabal-testsuite/PackageTests/ExternalCommandSetup/setup.cabal.hs create mode 100644 cabal-testsuite/PackageTests/ExternalCommandSetup/setup.out diff --git a/cabal-testsuite/PackageTests/ExternalCommand/cabal.out b/cabal-testsuite/PackageTests/ExternalCommand/cabal.out new file mode 100644 index 00000000000..1c4c24db55c --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommand/cabal.out @@ -0,0 +1,8 @@ +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - setup-test-0.1.0.0 (exe:cabal-aaaa) (first run) +Configuring executable 'cabal-aaaa' for setup-test-0.1.0.0... +Preprocessing executable 'cabal-aaaa' for setup-test-0.1.0.0... +Building executable 'cabal-aaaa' for setup-test-0.1.0.0... diff --git a/cabal-testsuite/PackageTests/ExternalCommand/cabal.project b/cabal-testsuite/PackageTests/ExternalCommand/cabal.project new file mode 100644 index 00000000000..1a33bb5a25e --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommand/cabal.project @@ -0,0 +1 @@ +packages: setup-test/ diff --git a/cabal-testsuite/PackageTests/ExternalCommand/cabal.test.hs b/cabal-testsuite/PackageTests/ExternalCommand/cabal.test.hs new file mode 100644 index 00000000000..850c8bfbcec --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommand/cabal.test.hs @@ -0,0 +1,37 @@ +import Test.Cabal.Prelude +import qualified System.Process as Process +import Control.Concurrent (threadDelay) +import System.Directory (removeFile) +import Control.Exception (catch, throwIO) +import System.IO.Error (isDoesNotExistError) +import qualified Data.Time.Clock as Time +import qualified Data.Time.Format as Time +import Data.Maybe +import System.Environment + +main = do + cabalTest $ do + res <- cabalWithStdin "v2-build" ["all"] "" + exe_path <- withPlan $ planExePath "setup-test" "cabal-aaaa" + env <- getTestEnv + path <- liftIO $ getEnv "PATH" + let newpath = takeDirectory exe_path ++ ":" ++ path + let new_env = (("PATH", Just newpath) : (testEnvironment env)) + withEnv new_env $ do + res <- cabal_raw_action ["aaaa"] (\h -> () <$ Process.waitForProcess h) + assertOutputContains "aaaa" res + + +cabal_raw_action :: [String] -> (Process.ProcessHandle -> IO ()) -> TestM Result +cabal_raw_action args action = do + configured_prog <- requireProgramM cabalProgram + env <- getTestEnv + r <- liftIO $ runAction (testVerbosity env) + (Just (testCurrentDir env)) + (testEnvironment env) + (programPath configured_prog) + args + Nothing + action + recordLog r + requireSuccess r diff --git a/cabal-testsuite/PackageTests/ExternalCommand/setup-test/AAAA.hs b/cabal-testsuite/PackageTests/ExternalCommand/setup-test/AAAA.hs new file mode 100644 index 00000000000..5bee0ebbef1 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommand/setup-test/AAAA.hs @@ -0,0 +1,4 @@ +module Main where + +main = do + putStrLn "aaaa" diff --git a/cabal-testsuite/PackageTests/ExternalCommand/setup-test/CHANGELOG.md b/cabal-testsuite/PackageTests/ExternalCommand/setup-test/CHANGELOG.md new file mode 100644 index 00000000000..7ae8ff6113d --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommand/setup-test/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for setup-test + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/cabal-testsuite/PackageTests/ExternalCommand/setup-test/LICENSE b/cabal-testsuite/PackageTests/ExternalCommand/setup-test/LICENSE new file mode 100644 index 00000000000..cd8ad2ac8ae --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommand/setup-test/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2023, Matthew Pickering + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Matthew Pickering nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cabal-testsuite/PackageTests/ExternalCommand/setup-test/setup-test.cabal b/cabal-testsuite/PackageTests/ExternalCommand/setup-test/setup-test.cabal new file mode 100644 index 00000000000..5661dcf0c3c --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommand/setup-test/setup-test.cabal @@ -0,0 +1,25 @@ +cabal-version: 3.0 +name: setup-test +version: 0.1.0.0 +-- synopsis: +-- description: +license: BSD-3-Clause +license-file: LICENSE +author: Matthew Pickering +maintainer: matthewtpickering@gmail.com +-- copyright: +build-type: Simple +extra-doc-files: CHANGELOG.md +-- extra-source-files: + +common warnings + ghc-options: -Wall + +executable cabal-aaaa + import: warnings + main-is: AAAA.hs + -- other-modules: + -- other-extensions: + build-depends: base ^>=4.18.0.0 + hs-source-dirs: . + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.out b/cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.out new file mode 100644 index 00000000000..1c4c24db55c --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.out @@ -0,0 +1,8 @@ +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - setup-test-0.1.0.0 (exe:cabal-aaaa) (first run) +Configuring executable 'cabal-aaaa' for setup-test-0.1.0.0... +Preprocessing executable 'cabal-aaaa' for setup-test-0.1.0.0... +Building executable 'cabal-aaaa' for setup-test-0.1.0.0... diff --git a/cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.project b/cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.project new file mode 100644 index 00000000000..1a33bb5a25e --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.project @@ -0,0 +1 @@ +packages: setup-test/ diff --git a/cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.test.hs b/cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.test.hs new file mode 100644 index 00000000000..891c9e43d4b --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.test.hs @@ -0,0 +1,39 @@ +import Test.Cabal.Prelude +import qualified System.Process as Process +import Control.Concurrent (threadDelay) +import System.Directory (removeFile) +import Control.Exception (catch, throwIO) +import System.IO.Error (isDoesNotExistError) +import qualified Data.Time.Clock as Time +import qualified Data.Time.Format as Time +import Data.Maybe +import System.Environment + +main = do + cabalTest $ expectBroken 9402 $ do + res <- cabalWithStdin "v2-build" ["all"] "" + exe_path <- withPlan $ planExePath "setup-test" "cabal-aaaa" + env <- getTestEnv + path <- liftIO $ getEnv "PATH" + let newpath = takeDirectory exe_path ++ ":" ++ path + let new_env = (("OTHER_VAR", Just "is set") : ("PATH", Just newpath) : (testEnvironment env)) + + withEnv new_env $ do + res <- cabal_raw_action ["aaaa"] (\h -> () <$ Process.waitForProcess h) + assertOutputContains "cabal-install" res + assertOutputContains "is set" res + + +cabal_raw_action :: [String] -> (Process.ProcessHandle -> IO ()) -> TestM Result +cabal_raw_action args action = do + configured_prog <- requireProgramM cabalProgram + env <- getTestEnv + r <- liftIO $ runAction (testVerbosity env) + (Just (testCurrentDir env)) + (testEnvironment env) + (programPath configured_prog) + args + Nothing + action + recordLog r + requireSuccess r diff --git a/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/AAAA.hs b/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/AAAA.hs new file mode 100644 index 00000000000..99af61e9c03 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/AAAA.hs @@ -0,0 +1,11 @@ +module Main where + +import System.Environment +import System.Process + +main = do + cabal_proc <- getEnv "CABAL" + other_var <- getEnv "OTHER_VAR" + putStrLn ("OTHER_VAR is set to: " ++ other_var) + callProcess cabal_proc ["--version"] + diff --git a/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/CHANGELOG.md b/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/CHANGELOG.md new file mode 100644 index 00000000000..7ae8ff6113d --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for setup-test + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/LICENSE b/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/LICENSE new file mode 100644 index 00000000000..cd8ad2ac8ae --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2023, Matthew Pickering + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Matthew Pickering nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/setup-test.cabal b/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/setup-test.cabal new file mode 100644 index 00000000000..9b3883ad2a1 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandEnv/setup-test/setup-test.cabal @@ -0,0 +1,25 @@ +cabal-version: 3.0 +name: setup-test +version: 0.1.0.0 +-- synopsis: +-- description: +license: BSD-3-Clause +license-file: LICENSE +author: Matthew Pickering +maintainer: matthewtpickering@gmail.com +-- copyright: +build-type: Simple +extra-doc-files: CHANGELOG.md +-- extra-source-files: + +common warnings + ghc-options: -Wall + +executable cabal-aaaa + import: warnings + main-is: AAAA.hs + -- other-modules: + -- other-extensions: + build-depends: base ^>=4.18.0.0, process + hs-source-dirs: . + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.out b/cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.out new file mode 100644 index 00000000000..0a3edf696f9 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.out @@ -0,0 +1,12 @@ +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - setup-test-0.1.0.0 (exe:cabal-aaaa) (first run) + - setup-test-0.1.0.0 (exe:setup) (first run) +Configuring executable 'cabal-aaaa' for setup-test-0.1.0.0... +Preprocessing executable 'cabal-aaaa' for setup-test-0.1.0.0... +Building executable 'cabal-aaaa' for setup-test-0.1.0.0... +Configuring executable 'setup' for setup-test-0.1.0.0... +Preprocessing executable 'setup' for setup-test-0.1.0.0... +Building executable 'setup' for setup-test-0.1.0.0... diff --git a/cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.project b/cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.project new file mode 100644 index 00000000000..1a33bb5a25e --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.project @@ -0,0 +1 @@ +packages: setup-test/ diff --git a/cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.test.hs b/cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.test.hs new file mode 100644 index 00000000000..a3a8acfa5c7 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandHelp/cabal.test.hs @@ -0,0 +1,37 @@ +import Test.Cabal.Prelude +import qualified System.Process as Process +import Control.Concurrent (threadDelay) +import System.Directory (removeFile) +import Control.Exception (catch, throwIO) +import System.IO.Error (isDoesNotExistError) +import qualified Data.Time.Clock as Time +import qualified Data.Time.Format as Time +import Data.Maybe +import System.Environment + +main = do + cabalTest $ expectBroken 9404 $ do + res <- cabalWithStdin "v2-build" ["all"] "" + exe_path <- withPlan $ planExePath "setup-test" "cabal-aaaa" + env <- getTestEnv + path <- liftIO $ getEnv "PATH" + let newpath = takeDirectory exe_path ++ ":" ++ path + let new_env = (("PATH", Just newpath) : (testEnvironment env)) + withEnv new_env $ do + res <- cabal_raw_action ["help", "aaaa"] (\h -> () <$ Process.waitForProcess h) + assertOutputContains "I am helping with the aaaa command" res + + +cabal_raw_action :: [String] -> (Process.ProcessHandle -> IO ()) -> TestM Result +cabal_raw_action args action = do + configured_prog <- requireProgramM cabalProgram + env <- getTestEnv + r <- liftIO $ runAction (testVerbosity env) + (Just (testCurrentDir env)) + (testEnvironment env) + (programPath configured_prog) + args + Nothing + action + recordLog r + requireSuccess r diff --git a/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/AAAA.hs b/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/AAAA.hs new file mode 100644 index 00000000000..10fe05988d8 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/AAAA.hs @@ -0,0 +1,9 @@ +module Main where + +import System.Environment + +main = do + args <- getArgs + case args of + ["--help"] -> putStrLn "I am helping with the aaaa command" + _ -> putStrLn "aaaa" diff --git a/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/CHANGELOG.md b/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/CHANGELOG.md new file mode 100644 index 00000000000..7ae8ff6113d --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for setup-test + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/LICENSE b/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/LICENSE new file mode 100644 index 00000000000..cd8ad2ac8ae --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2023, Matthew Pickering + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Matthew Pickering nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/setup-test.cabal b/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/setup-test.cabal new file mode 100644 index 00000000000..5661dcf0c3c --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandHelp/setup-test/setup-test.cabal @@ -0,0 +1,25 @@ +cabal-version: 3.0 +name: setup-test +version: 0.1.0.0 +-- synopsis: +-- description: +license: BSD-3-Clause +license-file: LICENSE +author: Matthew Pickering +maintainer: matthewtpickering@gmail.com +-- copyright: +build-type: Simple +extra-doc-files: CHANGELOG.md +-- extra-source-files: + +common warnings + ghc-options: -Wall + +executable cabal-aaaa + import: warnings + main-is: AAAA.hs + -- other-modules: + -- other-extensions: + build-depends: base ^>=4.18.0.0 + hs-source-dirs: . + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/LICENSE b/cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/LICENSE new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/Main.hs b/cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/Main.hs new file mode 100644 index 00000000000..b3fcf560699 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/Main.hs @@ -0,0 +1,3 @@ +module Main where + +main = putStrLn "aaaa" diff --git a/cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/aaaa.cabal b/cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/aaaa.cabal new file mode 100644 index 00000000000..db78e81694f --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandSetup/aaaa/aaaa.cabal @@ -0,0 +1,22 @@ +cabal-version: 3.0 +name: aaaa +version: 0.1.0.0 +license: BSD-3-Clause +license-file: LICENSE +author: Matthew Pickering +maintainer: matthewtpickering@gmail.com +build-type: Simple +extra-doc-files: CHANGELOG.md +-- extra-source-files: + +common warnings + ghc-options: -Wall + +executable cabal-aaaa + import: warnings + main-is: Main.hs + -- other-modules: + -- other-extensions: + build-depends: base ^>=4.18.0.0 + hs-source-dirs: . + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/CHANGELOG.md b/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/CHANGELOG.md new file mode 100644 index 00000000000..063fef7c698 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/CHANGELOG.md @@ -0,0 +1,5 @@ +# Revision history for custom + +## 0.1.0.0 -- YYYY-mm-dd + +* First version. Released on an unsuspecting world. diff --git a/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/LICENSE b/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/LICENSE new file mode 100644 index 00000000000..cd8ad2ac8ae --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2023, Matthew Pickering + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Matthew Pickering nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/Setup.hs b/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/Setup.hs new file mode 100644 index 00000000000..e8efd11bddb --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/Setup.hs @@ -0,0 +1,3 @@ +module Main where +import Distribution.Simple +main = defaultMain diff --git a/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/custom.cabal b/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/custom.cabal new file mode 100644 index 00000000000..7311063da5f --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/custom.cabal @@ -0,0 +1,29 @@ +cabal-version: 3.0 +name: custom +version: 0.1.0.0 +-- synopsis: +-- description: +license: BSD-3-Clause +license-file: LICENSE +author: Matthew Pickering +maintainer: matthewtpickering@gmail.com +-- copyright: +build-type: Custom +extra-doc-files: CHANGELOG.md +-- extra-source-files: + +common warnings + ghc-options: -Wall + +custom-setup + build-depends: base, Cabal + +library + import: warnings + exposed-modules: MyLib + -- other-modules: + -- other-extensions: + build-depends: base ^>=4.18.0.0 + hs-source-dirs: src + default-language: Haskell2010 + diff --git a/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/src/MyLib.hs b/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/src/MyLib.hs new file mode 100644 index 00000000000..e657c4403f6 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandSetup/custom/src/MyLib.hs @@ -0,0 +1,4 @@ +module MyLib (someFunc) where + +someFunc :: IO () +someFunc = putStrLn "someFunc" diff --git a/cabal-testsuite/PackageTests/ExternalCommandSetup/setup.cabal.hs b/cabal-testsuite/PackageTests/ExternalCommandSetup/setup.cabal.hs new file mode 100644 index 00000000000..7de624d4530 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandSetup/setup.cabal.hs @@ -0,0 +1,17 @@ +import Test.Cabal.Prelude +import System.Environment + +main = setupTest $ expectBroken 9403 $ do + withPackageDb $ do + withDirectory "aaaa" $ setup_install [] + r <- runInstalledExe' "cabal-aaaa" [] + env <- getTestEnv + path <- liftIO $ getEnv "PATH" + let exe_path = testPrefixDir env "bin" + let newpath = exe_path ++ ":" ++ path + let new_env = (("PATH", Just newpath) : (testEnvironment env)) + withEnv new_env $ do + res <- withDirectory "custom" $ setup' "aaaa" [] + assertOutputContains "did you mean" res + + diff --git a/cabal-testsuite/PackageTests/ExternalCommandSetup/setup.out b/cabal-testsuite/PackageTests/ExternalCommandSetup/setup.out new file mode 100644 index 00000000000..e234d5e2a48 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExternalCommandSetup/setup.out @@ -0,0 +1,22 @@ +# Setup configure +Configuring aaaa-0.1.0.0... +# Setup build +Preprocessing executable 'aaaa' for aaaa-0.1.0.0... +Building executable 'aaaa' for aaaa-0.1.0.0... +# Setup copy +Installing executable aaaa in +Warning: The directory /setup.dist/usr/bin is not in the system search path. +# Setup register +Package contains no library to register: aaaa-0.1.0.0... +# aaaa +aaaa +# Setup configure +Warning: custom.cabal:19:3: Unknown field: "build-depends" +Configuring custom-0.1.0.0... +# Setup build +Preprocessing library for custom-0.1.0.0... +Building library for custom-0.1.0.0... +# Setup copy +Installing library in +# Setup register +Registering library for custom-0.1.0.0... diff --git a/cabal-testsuite/src/Test/Cabal/Prelude.hs b/cabal-testsuite/src/Test/Cabal/Prelude.hs index e0e63ac18f6..0581fc21ab2 100644 --- a/cabal-testsuite/src/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/src/Test/Cabal/Prelude.hs @@ -357,15 +357,21 @@ runPlanExe pkg_name cname args = void $ runPlanExe' pkg_name cname args runPlanExe' :: String {- package name -} -> String {- component name -} -> [String] -> TestM Result runPlanExe' pkg_name cname args = do + exePath <- planExePath pkg_name cname + defaultRecordMode RecordAll $ do + recordHeader [pkg_name, cname] + runM exePath args Nothing + +planExePath :: String {- package name -} -> String {- component name -} + -> TestM FilePath +planExePath pkg_name cname = do Just plan <- testPlan `fmap` getTestEnv let distDirOrBinFile = planDistDir plan (mkPackageName pkg_name) (CExeName (mkUnqualComponentName cname)) exePath = case distDirOrBinFile of DistDir dist_dir -> dist_dir "build" cname cname BinFile bin_file -> bin_file - defaultRecordMode RecordAll $ do - recordHeader [pkg_name, cname] - runM exePath args Nothing + return exePath ------------------------------------------------------------------------ -- * Running ghc-pkg