diff --git a/cabal-install/src/Distribution/Client/CmdBench.hs b/cabal-install/src/Distribution/Client/CmdBench.hs index a1a691d45452d56f16a06ffae4f939caef9a5d90..0942b7c775923a3b1e07e1b4994e7c1a52b8a95b 100644 --- a/cabal-install/src/Distribution/Client/CmdBench.hs +++ b/cabal-install/src/Distribution/Client/CmdBench.hs @@ -29,6 +29,8 @@ import Distribution.Client.NixStyleOptions ( NixStyleFlags (..), nixStyleOptions, defaultNixStyleFlags ) import Distribution.Client.Setup ( GlobalFlags, ConfigFlags(..) ) +import Distribution.Client.Utils + ( occursOnlyOrBefore, giveRTSWarning ) import Distribution.Simple.Flag ( fromFlagOrDefault ) import Distribution.Simple.Command @@ -36,7 +38,10 @@ import Distribution.Simple.Command import Distribution.Verbosity ( normal ) import Distribution.Simple.Utils - ( wrapText, die' ) + ( wrapText, die', warn ) + +import GHC.Environment + ( getFullArgs ) benchCommand :: CommandUI (NixStyleFlags ()) benchCommand = CommandUI { @@ -96,6 +101,10 @@ benchAction flags@NixStyleFlags {..} targetStrings globalFlags = do ++ "You may wish to use 'build --only-dependencies' and then " ++ "use 'bench'." + fullArgs <- getFullArgs + when (occursOnlyOrBefore fullArgs "+RTS" "--") $ + warn verbosity $ giveRTSWarning "bench" + -- Interpret the targets on the command line as bench targets -- (as opposed to say build or haddock targets). targets <- either (reportTargetProblems verbosity) return diff --git a/cabal-install/src/Distribution/Client/CmdRun.hs b/cabal-install/src/Distribution/Client/CmdRun.hs index 14f0810db170c643b73638432ef74de69c723a69..664ffb30fca787fac0976bf7732907a62fe1defe 100644 --- a/cabal-install/src/Distribution/Client/CmdRun.hs +++ b/cabal-install/src/Distribution/Client/CmdRun.hs @@ -65,7 +65,7 @@ import Distribution.Types.UnitId import Distribution.Client.ScriptUtils ( AcceptNoTargets(..), withContextAndSelectors, updateContextAndWriteProjectFile, TargetContext(..) ) import Distribution.Client.Utils - ( occursOnlyOrBefore ) + ( occursOnlyOrBefore, giveRTSWarning ) import Data.List ( group ) import qualified Data.Set as Set @@ -147,11 +147,7 @@ runAction flags@NixStyleFlags {..} targetAndArgs globalFlags fullArgs <- getFullArgs when (occursOnlyOrBefore fullArgs "+RTS" "--") $ - warn verbosity $ - "Your RTS options are applied to cabal, not the executable. " - ++ "Use '--' to separate cabal options from your " - ++ "executable options. For example, use 'cabal run -- +RTS -N " - ++ "to pass the '-N' RTS option to your executable." + warn verbosity $ giveRTSWarning "run" -- Interpret the targets on the command line as build targets -- (as opposed to say repl or haddock targets). diff --git a/cabal-install/src/Distribution/Client/CmdTest.hs b/cabal-install/src/Distribution/Client/CmdTest.hs index 451e40eb9eebeeba0aa7cca959d5794b5f5edcad..9095b2f0a446094c1a8f269af289d7b8e070065f 100644 --- a/cabal-install/src/Distribution/Client/CmdTest.hs +++ b/cabal-install/src/Distribution/Client/CmdTest.hs @@ -29,6 +29,8 @@ import Distribution.Client.NixStyleOptions ( NixStyleFlags (..), nixStyleOptions, defaultNixStyleFlags ) import Distribution.Client.Setup ( GlobalFlags(..), ConfigFlags(..) ) +import Distribution.Client.Utils + ( occursOnlyOrBefore, giveRTSWarning ) import Distribution.Simple.Setup ( TestFlags(..), fromFlagOrDefault ) import Distribution.Simple.Command @@ -38,10 +40,12 @@ import Distribution.Simple.Flag import Distribution.Verbosity ( normal ) import Distribution.Simple.Utils - ( notice, wrapText, die' ) + ( notice, wrapText, die', warn ) import qualified System.Exit (exitSuccess) +import GHC.Environment + ( getFullArgs ) testCommand :: CommandUI (NixStyleFlags ()) testCommand = CommandUI @@ -108,6 +112,10 @@ testAction flags@NixStyleFlags {..} targetStrings globalFlags = do ++ "You may wish to use 'build --only-dependencies' and then " ++ "use 'test'." + fullArgs <- getFullArgs + when (occursOnlyOrBefore fullArgs "+RTS" "--") $ + warn verbosity $ giveRTSWarning "test" + -- Interpret the targets on the command line as test targets -- (as opposed to say build or haddock targets). targets <- either (reportTargetProblems verbosity failWhenNoTestSuites) return diff --git a/cabal-install/src/Distribution/Client/Utils.hs b/cabal-install/src/Distribution/Client/Utils.hs index 7d7da70b74f1e782e1131af03aaf91891e820828..c9c07737ae44ac0f2ddc4a978cb16f89fd0b0c48 100644 --- a/cabal-install/src/Distribution/Client/Utils.hs +++ b/cabal-install/src/Distribution/Client/Utils.hs @@ -30,6 +30,7 @@ module Distribution.Client.Utils , safeRead , hasElem , occursOnlyOrBefore + , giveRTSWarning ) where import Prelude () @@ -496,3 +497,21 @@ occursOnlyOrBefore xs x y = case (elemIndex x xs, elemIndex y xs) of (Just i, Just j) -> i < j (Just _, _) -> True _ -> False + +giveRTSWarning :: String -> String +giveRTSWarning "run" = "Your RTS options are applied to cabal, not the " + ++ "executable. Use '--' to separate cabal options from your " + ++ "executable options. For example, use 'cabal run -- +RTS -N " + ++ "to pass the '-N' RTS option to your executable." +giveRTSWarning "test" = "Your RTS options are applied to cabal, not the " + ++ "executable. Use '--test-options' to separate cabal options " + ++ "from your executable options. For example, use 'cabal test " + ++ "--test-options=\"+RTS -N\" to pass the '-N' RTS option " + ++ "to your executable." +giveRTSWarning "bench" = "Your RTS options are applied to cabal, not the " + ++ "executable. Use '--benchmark-options' to separate cabal " + ++ "options from your executable options. For example, " + ++ "use 'cabal bench --benchmark-options=\"+RTS -N\" to " + ++ "pass the '-N' RTS option to your executable." +giveRTSWarning _ = "Your RTS options are applied to cabal, not the " + ++ "executable." diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/Main.hs b/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/Main.hs new file mode 100644 index 0000000000000000000000000000000000000000..73566f6f203d62f83ca75e2b89abab90101d87c9 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/Main.hs @@ -0,0 +1 @@ +main = putStrLn "Hello World" diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/WarningRTS.cabal b/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/WarningRTS.cabal new file mode 100644 index 0000000000000000000000000000000000000000..5e2f9ab0d8510fbf362e522847ce5ac3d502d28e --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/WarningRTS.cabal @@ -0,0 +1,14 @@ +name: WarningRTS +version: 1.0 +build-type: Simple +cabal-version: >= 1.10 + +benchmark foo + type: exitcode-stdio-1.0 + main-is: Main.hs + build-depends: base + default-language: Haskell2010 + +library + exposed-modules: Main + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/cabal.out new file mode 100644 index 0000000000000000000000000000000000000000..7931709141339b24bd80774ea04bb40052f9fce0 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/cabal.out @@ -0,0 +1,31 @@ +# cabal bench +Resolving dependencies... +Warning: Your RTS options are applied to cabal, not the executable. Use '--benchmark-options' to separate cabal options from your executable options. For example, use 'cabal bench --benchmark-options="+RTS -N" to pass the '-N' RTS option to your executable. +Build profile: -w ghc-<GHCVER> -O1 +In order, the following will be built: + - WarningRTS-1.0 (bench:foo) (first run) +Configuring benchmark 'foo' for WarningRTS-1.0.. +Preprocessing benchmark 'foo' for WarningRTS-1.0.. +Building benchmark 'foo' for WarningRTS-1.0.. +Running 1 benchmarks... +Benchmark foo: RUNNING... +Benchmark foo: FINISH +# cabal bench +Warning: Your RTS options are applied to cabal, not the executable. Use '--benchmark-options' to separate cabal options from your executable options. For example, use 'cabal bench --benchmark-options="+RTS -N" to pass the '-N' RTS option to your executable. +Build profile: -w ghc-<GHCVER> -O1 +In order, the following will be built: + - WarningRTS-1.0 (bench:foo) (first run) +Preprocessing benchmark 'foo' for WarningRTS-1.0.. +Building benchmark 'foo' for WarningRTS-1.0.. +Running 1 benchmarks... +Benchmark foo: RUNNING... +Benchmark foo: FINISH +# cabal bench +Build profile: -w ghc-<GHCVER> -O1 +In order, the following will be built: + - WarningRTS-1.0 (bench:foo) (first run) +Preprocessing benchmark 'foo' for WarningRTS-1.0.. +Building benchmark 'foo' for WarningRTS-1.0.. +Running 1 benchmarks... +Benchmark foo: RUNNING... +Benchmark foo: FINISH diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/cabal.project b/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/cabal.project new file mode 100644 index 0000000000000000000000000000000000000000..e6fdbadb4398bc0e333947b5fb8021778310d943 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/cabal.test.hs b/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/cabal.test.hs new file mode 100644 index 0000000000000000000000000000000000000000..77fd6f84ca87c62f4280c956fdd4623f536d41e0 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdBench/WarningRTS/cabal.test.hs @@ -0,0 +1,11 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + res <- cabal' "bench" ["foo", "+RTS"] + assertOutputContains "Your RTS options are applied to cabal, not the executable. Use '--benchmark-options' " res + + res <- cabal' "bench" ["foo", "+RTS", "--"] + assertOutputContains "Your RTS options are applied to cabal, not the executable. Use '--benchmark-options' " res + + res <- cabal' "bench" ["foo", "--benchmark-options=\"+RTS\""] + assertOutputDoesNotContain "Warning: Your RTS options" res diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/Main.hs b/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/Main.hs new file mode 100644 index 0000000000000000000000000000000000000000..73566f6f203d62f83ca75e2b89abab90101d87c9 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/Main.hs @@ -0,0 +1 @@ +main = putStrLn "Hello World" diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/WarningRTS.cabal b/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/WarningRTS.cabal new file mode 100644 index 0000000000000000000000000000000000000000..c8214a6097cd7b6c055b59f692991c5278626bfa --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/WarningRTS.cabal @@ -0,0 +1,14 @@ +name: WarningRTS +version: 1.0 +build-type: Simple +cabal-version: >= 1.10 + +test-suite foo + type: exitcode-stdio-1.0 + main-is: Main.hs + build-depends: base + default-language: Haskell2010 + +library + exposed-modules: Main + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/cabal.out new file mode 100644 index 0000000000000000000000000000000000000000..a0862a0010e7fdf0c1cffd29867ac6ded2b61de6 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/cabal.out @@ -0,0 +1,37 @@ +# cabal test +Resolving dependencies... +Warning: Your RTS options are applied to cabal, not the executable. Use '--test-options' to separate cabal options from your executable options. For example, use 'cabal test --test-options="+RTS -N" to pass the '-N' RTS option to your executable. +Build profile: -w ghc-<GHCVER> -O1 +In order, the following will be built: + - WarningRTS-1.0 (test:foo) (first run) +Configuring test suite 'foo' for WarningRTS-1.0.. +Preprocessing test suite 'foo' for WarningRTS-1.0.. +Building test suite 'foo' for WarningRTS-1.0.. +Running 1 test suites... +Test suite foo: RUNNING... +Test suite foo: PASS +Test suite logged to: <ROOT>/cabal.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/WarningRTS-1.0/t/foo/test/WarningRTS-1.0-foo.log +1 of 1 test suites (1 of 1 test cases) passed. +# cabal test +Warning: Your RTS options are applied to cabal, not the executable. Use '--test-options' to separate cabal options from your executable options. For example, use 'cabal test --test-options="+RTS -N" to pass the '-N' RTS option to your executable. +Build profile: -w ghc-<GHCVER> -O1 +In order, the following will be built: + - WarningRTS-1.0 (test:foo) (first run) +Preprocessing test suite 'foo' for WarningRTS-1.0.. +Building test suite 'foo' for WarningRTS-1.0.. +Running 1 test suites... +Test suite foo: RUNNING... +Test suite foo: PASS +Test suite logged to: <ROOT>/cabal.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/WarningRTS-1.0/t/foo/test/WarningRTS-1.0-foo.log +1 of 1 test suites (1 of 1 test cases) passed. +# cabal test +Build profile: -w ghc-<GHCVER> -O1 +In order, the following will be built: + - WarningRTS-1.0 (test:foo) (first run) +Preprocessing test suite 'foo' for WarningRTS-1.0.. +Building test suite 'foo' for WarningRTS-1.0.. +Running 1 test suites... +Test suite foo: RUNNING... +Test suite foo: PASS +Test suite logged to: <ROOT>/cabal.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/WarningRTS-1.0/t/foo/test/WarningRTS-1.0-foo.log +1 of 1 test suites (1 of 1 test cases) passed. diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/cabal.project b/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/cabal.project new file mode 100644 index 0000000000000000000000000000000000000000..e6fdbadb4398bc0e333947b5fb8021778310d943 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/cabal.test.hs b/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/cabal.test.hs new file mode 100644 index 0000000000000000000000000000000000000000..e7c70e2a63f95f3e22543556d182bf518ebd53f6 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdTest/WarningRTS/cabal.test.hs @@ -0,0 +1,11 @@ +import Test.Cabal.Prelude + +main = cabalTest $ do + res <- cabal' "test" ["foo", "+RTS"] + assertOutputContains "Your RTS options are applied to cabal, not the executable. Use '--test-options'" res + + res <- cabal' "test" ["foo", "+RTS", "--"] + assertOutputContains "Your RTS options are applied to cabal, not the executable. Use '--test-options'" res + + res <- cabal' "test" ["foo", "--test-options=\"+RTS\""] + assertOutputDoesNotContain "Your RTS options" res