From 2281dcf7cdbda4d891ea0a310d6b35eadfd56ce3 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Sat, 28 Dec 2024 10:41:51 -0500 Subject: [PATCH] Add tests --- .../PackageTests/ReplProjectTarget/cabal.out | 33 +++++++++++++++++++ .../ReplProjectTarget/cabal.project | 1 + .../ReplProjectTarget/cabal.test.hs | 22 +++++++++++++ .../ReplProjectTarget/empty.project | 0 .../ReplProjectTarget/pkg-one/pkg-one.cabal | 9 +++++ .../ReplProjectTarget/pkg-two/pkg-one.cabal | 9 +++++ .../ReplProjectTarget/reverse.project | 1 + .../ReplProjectTarget/some.project | 1 + 8 files changed, 76 insertions(+) create mode 100644 cabal-testsuite/PackageTests/ReplProjectTarget/cabal.out create mode 100644 cabal-testsuite/PackageTests/ReplProjectTarget/cabal.project create mode 100644 cabal-testsuite/PackageTests/ReplProjectTarget/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/ReplProjectTarget/empty.project create mode 100644 cabal-testsuite/PackageTests/ReplProjectTarget/pkg-one/pkg-one.cabal create mode 100644 cabal-testsuite/PackageTests/ReplProjectTarget/pkg-two/pkg-one.cabal create mode 100644 cabal-testsuite/PackageTests/ReplProjectTarget/reverse.project create mode 100644 cabal-testsuite/PackageTests/ReplProjectTarget/some.project diff --git a/cabal-testsuite/PackageTests/ReplProjectTarget/cabal.out b/cabal-testsuite/PackageTests/ReplProjectTarget/cabal.out new file mode 100644 index 00000000000..68cb7fc70ef --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplProjectTarget/cabal.out @@ -0,0 +1,33 @@ +# checking repl command with a project using an implicit default 'cabal.project' +# cabal repl +Configuration is affected by the following files: +- cabal.project +Error: [Cabal-7076] +With a project, the REPL command requires a single target. The packages in this project are: + - pkg-one + - pkg-two +# checking repl command with a project using an explicit 'cabal.project' +# cabal repl +Configuration is affected by the following files: +- some.project +Error: [Cabal-7076] +With a project, the REPL command requires a single target. The packages in this project, 'some.project', are: + - pkg-one + - pkg-two +# checking repl command with a project listing packages in reverse order +# cabal repl +Configuration is affected by the following files: +- reverse.project +Error: [Cabal-7076] +With a project, the REPL command requires a single target. The packages in this project, 'reverse.project', are: + - pkg-one + - pkg-two +# checking repl command with a project with no packages +# cabal repl +Configuration is affected by the following files: +- empty.project +Warning: There are no packages or optional-packages in the project +Error: [Cabal-7076] +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. +# checking repl command with a missing project +# cabal repl diff --git a/cabal-testsuite/PackageTests/ReplProjectTarget/cabal.project b/cabal-testsuite/PackageTests/ReplProjectTarget/cabal.project new file mode 100644 index 00000000000..80c5979562a --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplProjectTarget/cabal.project @@ -0,0 +1 @@ +packages: pkg-one pkg-two diff --git a/cabal-testsuite/PackageTests/ReplProjectTarget/cabal.test.hs b/cabal-testsuite/PackageTests/ReplProjectTarget/cabal.test.hs new file mode 100644 index 00000000000..a85dc7db625 --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplProjectTarget/cabal.test.hs @@ -0,0 +1,22 @@ +import Test.Cabal.Prelude + +main = cabalTest . recordMode RecordMarked $ do + let log = recordHeader . pure + + log "checking repl command with a project using an implicit default 'cabal.project'" + _ <- fails $ cabal' "repl" [] + + log "checking repl command with a project using an explicit 'cabal.project'" + _ <- fails $ cabal' "repl" [ "--project-file=some.project" ] + + log "checking repl command with a project listing packages in reverse order" + _ <- fails $ cabal' "repl" [ "--project-file=reverse.project" ] + + log "checking repl command with a project with no packages" + _ <- fails $ cabal' "repl" [ "--project-file=empty.project" ] + + log "checking repl command with a missing project" + missing <- fails $ cabal' "repl" [ "--project-file=missing.project" ] + assertOutputContains "The given project file 'missing.project' does not exist." missing + + return () diff --git a/cabal-testsuite/PackageTests/ReplProjectTarget/empty.project b/cabal-testsuite/PackageTests/ReplProjectTarget/empty.project new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cabal-testsuite/PackageTests/ReplProjectTarget/pkg-one/pkg-one.cabal b/cabal-testsuite/PackageTests/ReplProjectTarget/pkg-one/pkg-one.cabal new file mode 100644 index 00000000000..11d300a05a6 --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplProjectTarget/pkg-one/pkg-one.cabal @@ -0,0 +1,9 @@ +name: pkg-one +version: 0.1 +license: BSD3 +cabal-version: >= 1.2 +build-type: Simple + +library + exposed-modules: Foo + build-depends: base diff --git a/cabal-testsuite/PackageTests/ReplProjectTarget/pkg-two/pkg-one.cabal b/cabal-testsuite/PackageTests/ReplProjectTarget/pkg-two/pkg-one.cabal new file mode 100644 index 00000000000..11d300a05a6 --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplProjectTarget/pkg-two/pkg-one.cabal @@ -0,0 +1,9 @@ +name: pkg-one +version: 0.1 +license: BSD3 +cabal-version: >= 1.2 +build-type: Simple + +library + exposed-modules: Foo + build-depends: base diff --git a/cabal-testsuite/PackageTests/ReplProjectTarget/reverse.project b/cabal-testsuite/PackageTests/ReplProjectTarget/reverse.project new file mode 100644 index 00000000000..763852bc0c1 --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplProjectTarget/reverse.project @@ -0,0 +1 @@ +packages: pkg-two pkg-one diff --git a/cabal-testsuite/PackageTests/ReplProjectTarget/some.project b/cabal-testsuite/PackageTests/ReplProjectTarget/some.project new file mode 100644 index 00000000000..80c5979562a --- /dev/null +++ b/cabal-testsuite/PackageTests/ReplProjectTarget/some.project @@ -0,0 +1 @@ +packages: pkg-one pkg-two