Skip to content

Commit eefdbfe

Browse files
committed
Better new-run error reporting
Report possible tests and benchmarks too when erroring because of multiple available targets.
1 parent 5e92bcf commit eefdbfe

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

cabal-install/Distribution/Client/CmdRun.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Distribution.Simple.Setup
2929
import Distribution.Simple.Command
3030
( CommandUI(..), usageAlternatives )
3131
import Distribution.Types.ComponentName
32-
( componentNameString )
32+
( showComponentName )
3333
import Distribution.Text
3434
( display )
3535
import Distribution.Verbosity
@@ -396,12 +396,13 @@ renderTargetProblem (TargetProblemNoTargets targetSelector) =
396396
renderTargetProblem (TargetProblemMatchesMultiple targetSelector targets) =
397397
"The run command is for running a single executable at once. The target '"
398398
++ showTargetSelector targetSelector ++ "' refers to "
399-
++ renderTargetSelector targetSelector ++ " which includes the executables "
400-
++ renderListCommaAnd
401-
[ display name
402-
| cname@CExeName{} <- map availableTargetComponentName targets
403-
, let Just name = componentNameString cname
404-
]
399+
++ renderTargetSelector targetSelector ++ " which includes "
400+
++ renderListCommaAnd ( ("the "++) <$>
401+
showComponentName <$>
402+
availableTargetComponentName <$>
403+
foldMap
404+
(\kind -> filterTargetsKind kind targets)
405+
[ExeKind, TestKind, BenchKind] )
405406
++ "."
406407

407408
renderTargetProblem (TargetProblemMultipleTargets selectorMap) =

cabal-testsuite/PackageTests/NewBuild/CmdRun/MultipleExes/cabal.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ Building executable 'bar' for MultipleExes-1.0..
1616
# cabal new-run
1717
Up to date
1818
# cabal new-run
19-
cabal: The run command is for running a single executable at once. The target '' refers to the package MultipleExes-1.0 which includes the executables foo and bar.
19+
cabal: The run command is for running a single executable at once. The target '' refers to the package MultipleExes-1.0 which includes the executable 'foo' and the executable 'bar'.
2020
# cabal new-run
21-
cabal: The run command is for running a single executable at once. The target 'MultipleExes' refers to the package MultipleExes-1.0 which includes the executables foo and bar.
21+
cabal: The run command is for running a single executable at once. The target 'MultipleExes' refers to the package MultipleExes-1.0 which includes the executable 'foo' and the executable 'bar'.

cabal-testsuite/PackageTests/NewBuild/CmdRun/MultiplePackages/cabal.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Building executable 'foo-exe' for bar-1.0..
2525
# cabal new-run
2626
cabal: No targets given and there is no package in the current directory. Use the target 'all' for all packages in the project or specify packages or components by name or location. See 'cabal build --help' for more details on target options.
2727
# cabal new-run
28-
cabal: The run command is for running a single executable at once. The target 'bar' refers to the package bar-1.0 which includes the executables foo-exe and bar-exe.
28+
cabal: The run command is for running a single executable at once. The target 'bar' refers to the package bar-1.0 which includes the executable 'foo-exe' and the executable 'bar-exe'.
2929
# cabal new-run
3030
cabal: Ambiguous target 'foo-exe'. It could be:
3131
bar:foo-exe (component)

0 commit comments

Comments
 (0)