Skip to content

Commit

Permalink
Add alt.project tests for ReplOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Dec 29, 2024
1 parent 62073c9 commit b0c404f
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 3 deletions.
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/ReplOptions/alt.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: alt
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/ReplOptions/alt/ModuleA.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ModuleA where

a :: Int
a = 42
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/ReplOptions/alt/ModuleC.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ModuleC where

c :: Int
c = 42
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/ReplOptions/alt/alt.cabal
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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-<GHCVER> -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...
Original file line number Diff line number Diff line change
@@ -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-<GHCVER> -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...
Original file line number Diff line number Diff line change
Expand Up @@ -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-<GHCVER> -O1
In order, the following will be built:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-<GHCVER> -O1
In order, the following will be built:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-<GHCVER> -O1
In order, the following will be built:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-<GHCVER> -O1
In order, the following will be built:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-<GHCVER> -O1
In order, the following will be built:
Expand Down
23 changes: 20 additions & 3 deletions cabal-testsuite/PackageTests/ReplOptions/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -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" [
Expand Down

0 comments on commit b0c404f

Please sign in to comment.