From 3821cff54289d8c94e54d483e15e828a565ce685 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Sat, 28 Dec 2024 15:05:15 -0500 Subject: [PATCH] Add alt.project tests for ReplOptions --- .../PackageTests/ReplOptions/alt.project | 1 + .../PackageTests/ReplOptions/alt/ModuleA.hs | 4 ++++ .../PackageTests/ReplOptions/alt/ModuleC.hs | 4 ++++ .../PackageTests/ReplOptions/alt/alt.cabal | 10 ++++++++ .../cabal.alt-multiple-repl-options.out | 12 ++++++++++ .../cabal.alt-single-repl-options.out | 12 ++++++++++ ...l.multiple-repl-options-multiple-flags.out | 2 ++ .../cabal.multiple-repl-options.out | 2 ++ ...e-repl-options-multiple-flags-negative.out | 2 ++ ...bal.single-repl-options-multiple-flags.out | 2 ++ .../ReplOptions/cabal.single-repl-options.out | 2 ++ .../PackageTests/ReplOptions/cabal.test.hs | 23 ++++++++++++++++--- 12 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 cabal-testsuite/PackageTests/ReplOptions/alt.project create mode 100644 cabal-testsuite/PackageTests/ReplOptions/alt/ModuleA.hs create mode 100644 cabal-testsuite/PackageTests/ReplOptions/alt/ModuleC.hs create mode 100644 cabal-testsuite/PackageTests/ReplOptions/alt/alt.cabal create mode 100644 cabal-testsuite/PackageTests/ReplOptions/cabal.alt-multiple-repl-options.out create mode 100644 cabal-testsuite/PackageTests/ReplOptions/cabal.alt-single-repl-options.out diff --git a/cabal-testsuite/PackageTests/ReplOptions/alt.project b/cabal-testsuite/PackageTests/ReplOptions/alt.project new file mode 100644 index 00000000000..42e62e64527 --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplOptions/alt.project @@ -0,0 +1 @@ +packages: alt diff --git a/cabal-testsuite/PackageTests/ReplOptions/alt/ModuleA.hs b/cabal-testsuite/PackageTests/ReplOptions/alt/ModuleA.hs new file mode 100644 index 00000000000..c449728173e --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplOptions/alt/ModuleA.hs @@ -0,0 +1,4 @@ +module ModuleA where + +a :: Int +a = 42 diff --git a/cabal-testsuite/PackageTests/ReplOptions/alt/ModuleC.hs b/cabal-testsuite/PackageTests/ReplOptions/alt/ModuleC.hs new file mode 100644 index 00000000000..45bcb062103 --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplOptions/alt/ModuleC.hs @@ -0,0 +1,4 @@ +module ModuleC where + +c :: Int +c = 42 diff --git a/cabal-testsuite/PackageTests/ReplOptions/alt/alt.cabal b/cabal-testsuite/PackageTests/ReplOptions/alt/alt.cabal new file mode 100644 index 00000000000..57dcd758380 --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplOptions/alt/alt.cabal @@ -0,0 +1,10 @@ +name: alt +version: 0.1 +build-type: Simple +cabal-version: >= 1.10 + +library + exposed-modules: ModuleA, ModuleC + build-depends: base + default-language: Haskell2010 + diff --git a/cabal-testsuite/PackageTests/ReplOptions/cabal.alt-multiple-repl-options.out b/cabal-testsuite/PackageTests/ReplOptions/cabal.alt-multiple-repl-options.out new file mode 100644 index 00000000000..68e181e38c0 --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplOptions/cabal.alt-multiple-repl-options.out @@ -0,0 +1,12 @@ +# cabal clean +# cabal v2-repl +Configuration is affected by the following files: +- alt.project +Configuration is affected by the following files: +- alt.project +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - alt-0.1 (interactive) (lib) (first run) +Configuring library for alt-0.1... +Preprocessing library for alt-0.1... diff --git a/cabal-testsuite/PackageTests/ReplOptions/cabal.alt-single-repl-options.out b/cabal-testsuite/PackageTests/ReplOptions/cabal.alt-single-repl-options.out new file mode 100644 index 00000000000..68e181e38c0 --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplOptions/cabal.alt-single-repl-options.out @@ -0,0 +1,12 @@ +# cabal clean +# cabal v2-repl +Configuration is affected by the following files: +- alt.project +Configuration is affected by the following files: +- alt.project +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - alt-0.1 (interactive) (lib) (first run) +Configuring library for alt-0.1... +Preprocessing library for alt-0.1... diff --git a/cabal-testsuite/PackageTests/ReplOptions/cabal.multiple-repl-options-multiple-flags.out b/cabal-testsuite/PackageTests/ReplOptions/cabal.multiple-repl-options-multiple-flags.out index e45e9385218..5df15c6a07c 100644 --- a/cabal-testsuite/PackageTests/ReplOptions/cabal.multiple-repl-options-multiple-flags.out +++ b/cabal-testsuite/PackageTests/ReplOptions/cabal.multiple-repl-options-multiple-flags.out @@ -2,6 +2,8 @@ # cabal v2-repl Configuration is affected by the following files: - cabal.project +Configuration is affected by the following files: +- cabal.project Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: diff --git a/cabal-testsuite/PackageTests/ReplOptions/cabal.multiple-repl-options.out b/cabal-testsuite/PackageTests/ReplOptions/cabal.multiple-repl-options.out index e45e9385218..5df15c6a07c 100644 --- a/cabal-testsuite/PackageTests/ReplOptions/cabal.multiple-repl-options.out +++ b/cabal-testsuite/PackageTests/ReplOptions/cabal.multiple-repl-options.out @@ -2,6 +2,8 @@ # cabal v2-repl Configuration is affected by the following files: - cabal.project +Configuration is affected by the following files: +- cabal.project Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: diff --git a/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options-multiple-flags-negative.out b/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options-multiple-flags-negative.out index 9368db4d3dd..08156116812 100644 --- a/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options-multiple-flags-negative.out +++ b/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options-multiple-flags-negative.out @@ -2,6 +2,8 @@ # cabal v2-repl Configuration is affected by the following files: - cabal.project +Configuration is affected by the following files: +- cabal.project Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: diff --git a/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options-multiple-flags.out b/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options-multiple-flags.out index e45e9385218..5df15c6a07c 100644 --- a/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options-multiple-flags.out +++ b/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options-multiple-flags.out @@ -2,6 +2,8 @@ # cabal v2-repl Configuration is affected by the following files: - cabal.project +Configuration is affected by the following files: +- cabal.project Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: diff --git a/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options.out b/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options.out index e45e9385218..5df15c6a07c 100644 --- a/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options.out +++ b/cabal-testsuite/PackageTests/ReplOptions/cabal.single-repl-options.out @@ -2,6 +2,8 @@ # cabal v2-repl Configuration is affected by the following files: - cabal.project +Configuration is affected by the following files: +- cabal.project Resolving dependencies... Build profile: -w ghc- -O1 In order, the following will be built: diff --git a/cabal-testsuite/PackageTests/ReplOptions/cabal.test.hs b/cabal-testsuite/PackageTests/ReplOptions/cabal.test.hs index 6c72166ed5f..ba8cebe9a3e 100644 --- a/cabal-testsuite/PackageTests/ReplOptions/cabal.test.hs +++ b/cabal-testsuite/PackageTests/ReplOptions/cabal.test.hs @@ -1,29 +1,46 @@ import Test.Cabal.Prelude +singleOpts = ["--repl-options=-fwrite-interface"] +multiOpts = "--repl-options=-fdefer-typed-holes" : singleOpts +altProject = ("--project-file=alt.project" :) + main = do cabalTest' "single-repl-options" $ do cabal' "clean" [] - res <- cabalWithStdin "v2-repl" ["--repl-options=-fwrite-interface"] ":set" + res <- cabalWithStdin "v2-repl" singleOpts ":set" assertOutputContains "Ok, two modules loaded." res - assertOutputContains " -fwrite-interface" res + + cabalTest' "alt-single-repl-options" $ do + cabal' "clean" [] + -- Can we 'cabal repl' without a target when the project has a single package? + void $ cabalWithStdin "v2-repl" (altProject singleOpts) ":set" + cabalTest' "multiple-repl-options" $ do cabal' "clean" [] - res <- cabalWithStdin "v2-repl" ["--repl-options=-fwrite-interface", "--repl-options=-fdefer-typed-holes"] ":set" + res <- cabalWithStdin "v2-repl" multiOpts ":set" assertOutputContains "Ok, two modules loaded." res assertOutputContains " -fwrite-interface" res assertOutputContains " -fdefer-typed-holes" res + + cabalTest' "alt-multiple-repl-options" $ do + cabal' "clean" [] + -- Can we 'cabal repl' without a target when the project has a single package? + void $ cabalWithStdin "v2-repl" (altProject multiOpts) ":set" + cabalTest' "single-repl-options-multiple-flags" $ do cabal' "clean" [] res <- cabalWithStdin "v2-repl" ["--repl-options=-fdefer-typed-holes -fwrite-interface"] ":set" assertOutputContains "Ok, two modules loaded." res assertOutputContains " -fwrite-interface" res assertOutputContains " -fdefer-typed-holes" res + cabalTest' "single-repl-options-multiple-flags-negative" $ do cabal' "clean" [] res <- fails $ cabalWithStdin "v2-repl" ["--repl-options=-fwrite-interface -fdiagnostics-show-baret"] ":set" assertOutputDoesNotContain "Ok, two modules loaded." res assertOutputContains "unrecognised flag: -fdiagnostics-show-baret" res assertOutputContains "did you mean one of:" res + cabalTest' "multiple-repl-options-multiple-flags" $ do cabal' "clean" [] res <- cabalWithStdin "v2-repl" [