Skip to content

Commit 88c7a58

Browse files
committed
Update tests, adding more assertions
Improve test descriptions
1 parent 1b3e797 commit 88c7a58

File tree

7 files changed

+95
-32
lines changed

7 files changed

+95
-32
lines changed

cabal-install/src/Distribution/Client/CmdRepl.hs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ import System.FilePath
201201
, (</>)
202202
)
203203
import Text.PrettyPrint hiding ((<>))
204-
import qualified Text.PrettyPrint as Pretty
205204

206205
replCommand :: CommandUI (NixStyleFlags ReplFlags)
207206
replCommand =
@@ -314,22 +313,28 @@ replAction flags@NixStyleFlags{extraFlags = r@ReplFlags{..}, ..} targetStrings'
314313
ProjectContext -> do
315314
let pkgs = projectPackages $ projectConfig ctx
316315
when (null targetStrings && length pkgs /= 1) $
317-
let singleTarget = text "With a project, the REPL command requires a single target"
318-
project = case projectConfigProjectFile . projectConfigShared $ projectConfig ctx of
319-
Flag projectName -> comma <+> (quotes (text projectName))
320-
_ -> Pretty.empty
316+
let projectName = case projectConfigProjectFile . projectConfigShared $ projectConfig ctx of
317+
Flag "" -> Nothing
318+
Flag n -> Just $ quotes (text n)
319+
_ -> Nothing
321320
msg =
322-
if null pkgs
323-
then
324-
(singleTarget <> comma)
325-
<+> (text "but there are no packages in this project" <> project <> comma)
326-
<+> text "to choose a package (library) or other component from"
327-
<+> "as the target for this command."
328-
else
329-
(singleTarget <> (char '.'))
330-
<+> (text "The packages in this project" <> project <> comma)
321+
case (null pkgs, projectName) of
322+
(True, Just project) ->
323+
text "There are no packages in"
324+
<+> (project <> char '.')
325+
<+> text "Please add a package to the project and pick a component to use as the target of the REPL command."
326+
(True, Nothing) ->
327+
text "Please add a package to the project and pick a component to use as the target of the REPL command."
328+
(False, Just project) ->
329+
text "Please pick a single component as target for the REPL command."
330+
<+> text "The packages in"
331+
<+> project
331332
<+> (text "are" <> colon)
332333
$+$ nest 1 (vcat [text "-" <+> text pkg | pkg <- sort pkgs])
334+
(False, Nothing) ->
335+
text "Please pick a single component as target for the REPL command."
336+
<+> (text "The packages in 'cabal.project', the implicit default as if `--project-file=cabal.project` was added as a command option, are" <> colon)
337+
$+$ nest 1 (vcat [text "-" <+> text pkg | pkg <- sort pkgs])
333338
in dieWithException verbosity $ RenderReplTargetProblem [render msg]
334339
return ctx
335340
GlobalContext -> do
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# checking repl command with no project and --ignore-project
2+
# cabal repl
3+
Resolving dependencies...
4+
# checking repl command with no project and no project options
5+
# cabal repl
6+
Resolving dependencies...
7+
# checking repl command with a missing project
8+
# cabal repl
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest . recordMode RecordMarked $ do
4+
let log = recordHeader . pure
5+
6+
log "checking repl command with no project and --ignore-project"
7+
_ <- fails $ cabal' "repl" ["--ignore-project"]
8+
9+
log "checking repl command with no project and no project options"
10+
_ <- fails $ cabal' "repl" []
11+
12+
log "checking repl command with a missing project"
13+
missing <- fails $ cabal' "repl" [ "--project-file=missing.project" ]
14+
assertOutputContains "The given project file 'missing.project' does not exist." missing
15+
16+
return ()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: pkg-one
2+
version: 0.1
3+
license: BSD3
4+
cabal-version: >= 1.2
5+
build-type: Simple
6+
7+
library
8+
exposed-modules: Foo
9+
build-depends: base
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: pkg-one
2+
version: 0.1
3+
license: BSD3
4+
cabal-version: >= 1.2
5+
build-type: Simple
6+
7+
library
8+
exposed-modules: Foo
9+
build-depends: base
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1-
# checking repl command with a project using an implicit default 'cabal.project'
1+
# checking repl command with a 'cabal.project' and --ignore-project
2+
# cabal repl
3+
Resolving dependencies...
4+
# checking repl command with a 'cabal.project' and no project options
25
# cabal repl
36
Configuration is affected by the following files:
47
- cabal.project
58
Error: [Cabal-7076]
6-
With a project, the REPL command requires a single target. The packages in this project are:
9+
Please pick a single component as target for the REPL command. The packages in 'cabal.project', the implicit default as if `--project-file=cabal.project` was added as a command option, are:
710
- pkg-one
811
- pkg-two
9-
# checking repl command with a project using an explicit 'cabal.project'
12+
# checking repl command using an explicit 'some.project'
1013
# cabal repl
1114
Configuration is affected by the following files:
1215
- some.project
1316
Error: [Cabal-7076]
14-
With a project, the REPL command requires a single target. The packages in this project, 'some.project', are:
17+
Please pick a single component as target for the REPL command. The packages in 'some.project' are:
1518
- pkg-one
1619
- pkg-two
17-
# checking repl command with a project listing packages in reverse order
20+
# checking repl command using an explicit 'reverse.project', listing packages in reverse order
1821
# cabal repl
1922
Configuration is affected by the following files:
2023
- reverse.project
2124
Error: [Cabal-7076]
22-
With a project, the REPL command requires a single target. The packages in this project, 'reverse.project', are:
25+
Please pick a single component as target for the REPL command. The packages in 'reverse.project' are:
2326
- pkg-one
2427
- pkg-two
25-
# checking repl command with a project with no packages
28+
# checking repl command with an 'empty.project' with no packages
2629
# cabal repl
2730
Configuration is affected by the following files:
2831
- empty.project
2932
Warning: There are no packages or optional-packages in the project
3033
Error: [Cabal-7076]
31-
With a project, the REPL command requires a single target but there are no packages in this project, 'empty.project', to choose a package (library) or other component from as the target for this command.
32-
# checking repl command with a missing project
34+
There are no packages in 'empty.project'. Please add a package to the project and pick a component to use as the target of the REPL command.
35+
# checking repl command with a missing 'missing.project'
3336
# cabal repl

cabal-testsuite/PackageTests/ReplProjectTarget/cabal.test.hs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,32 @@ import Test.Cabal.Prelude
33
main = cabalTest . recordMode RecordMarked $ do
44
let log = recordHeader . pure
55

6-
log "checking repl command with a project using an implicit default 'cabal.project'"
7-
_ <- fails $ cabal' "repl" []
6+
log "checking repl command with a 'cabal.project' and --ignore-project"
7+
ignored <- fails $ cabal' "repl" ["--ignore-project"]
8+
assertOutputDoesNotContain "Configuration is affected by the following files:" ignored
9+
assertOutputDoesNotContain "- cabal.project" ignored
810

9-
log "checking repl command with a project using an explicit 'cabal.project'"
10-
_ <- fails $ cabal' "repl" [ "--project-file=some.project" ]
11+
log "checking repl command with a 'cabal.project' and no project options"
12+
defaultProject <- fails $ cabal' "repl" []
13+
assertOutputContains "Configuration is affected by the following files:" defaultProject
14+
assertOutputContains "- cabal.project" defaultProject
1115

12-
log "checking repl command with a project listing packages in reverse order"
13-
_ <- fails $ cabal' "repl" [ "--project-file=reverse.project" ]
16+
log "checking repl command using an explicit 'some.project'"
17+
someProject <- fails $ cabal' "repl" [ "--project-file=some.project" ]
18+
assertOutputContains "Configuration is affected by the following files:" someProject
19+
assertOutputContains "- some.project" someProject
1420

15-
log "checking repl command with a project with no packages"
16-
_ <- fails $ cabal' "repl" [ "--project-file=empty.project" ]
21+
log "checking repl command using an explicit 'reverse.project', listing packages in reverse order"
22+
reverseProject <- fails $ cabal' "repl" [ "--project-file=reverse.project" ]
23+
assertOutputContains "Configuration is affected by the following files:" reverseProject
24+
assertOutputContains "- reverse.project" reverseProject
1725

18-
log "checking repl command with a missing project"
26+
log "checking repl command with an 'empty.project' with no packages"
27+
emptyProject <- fails $ cabal' "repl" [ "--project-file=empty.project" ]
28+
assertOutputContains "Configuration is affected by the following files:" emptyProject
29+
assertOutputContains "- empty.project" emptyProject
30+
31+
log "checking repl command with a missing 'missing.project'"
1932
missing <- fails $ cabal' "repl" [ "--project-file=missing.project" ]
2033
assertOutputContains "The given project file 'missing.project' does not exist." missing
2134

0 commit comments

Comments
 (0)