@@ -1170,9 +1170,53 @@ they are up to date.
1170
1170
cabal test
1171
1171
^^^^^^^^^^
1172
1172
1173
- ``cabal test [TARGETS] [FLAGS] `` runs the specified test suites
1174
- (all the test suites in the current package by default), first ensuring
1175
- they are up to date.
1173
+ ``cabal test [TARGETS] [FLAGS] `` tests test suites specified as targets
1174
+ after ensuring they are up to date and building them, if necessary.
1175
+
1176
+ .. Warning ::
1177
+
1178
+ For a test suite, there's a difference between testing it with ``cabal
1179
+ test `` and running it with ``cabal run `` to do with the working directory.
1180
+ The former tests the test suite; that is to say that it "runs" the test suite
1181
+ from the package directory (from the directory of the package that has the
1182
+ test suite as a component), while the latter runs the test suite from
1183
+ whatever directory is current when the ``cabal run `` command is issued.
1184
+ This is important because the test suite may depend on files in the package
1185
+ directory, and so may not work correctly if run from another directory.
1186
+
1187
+ .. Note ::
1188
+
1189
+ Even though ``[TARGETS] `` are optional, ``cabal test `` will only test test
1190
+ suites without specifying a target if in the directory of a package,
1191
+ alongside a ``.cabal `` file. Being in the directory of a package implicitly
1192
+ selects that package for the test command.
1193
+
1194
+ Taking the cabal project as an example that has a ``Cabal-tests `` package
1195
+ with multiple test suites, the following two commands are effectively the
1196
+ same and will test the test suites of the ``Cabal-tests `` package:
1197
+
1198
+ ::
1199
+
1200
+ $ cabal test Cabal-tests
1201
+ $ cd Cabal-tests && cabal test && cd ..
1202
+
1203
+ If you want to test all of the test suites in a project then from the
1204
+ project directory ``cabal build `` with no target will fail:
1205
+
1206
+ .. code-block :: text
1207
+
1208
+ $ cabal test
1209
+ Error: [Cabal-7134]
1210
+ No targets given and there is no package in the current directory. Use
1211
+ the target 'all' for all packages in the project or specify packages or
1212
+ components by name or location. See 'cabal build --help' for more
1213
+ details on target options.
1214
+
1215
+ Both ``cabal test all:tests `` and ``cabal test all `` use explicit targets
1216
+ for testing all test suites of a project; the former's ``all:tests `` target
1217
+ will select all test suites of the project, while the latter's ``all ``
1218
+ target will select all packages of the project and, from those, test all
1219
+ their test suites.
1176
1220
1177
1221
``cabal test `` inherits flags of the ``test `` subcommand of ``Setup.hs ``
1178
1222
(:ref: `see the corresponding section <setup-test >`) with one caveat: every
0 commit comments