From 9ead3f7f1557aa162b091a67014282f2b53816f4 Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Sat, 13 Jan 2024 07:44:27 +0100 Subject: [PATCH] Test that the last line `--help` is the name of the config file Ensure that the last line of the help text is the name of the config file. This invariant is used by clients such as the Haskell setup github action. See: https://github.com/haskell-actions/setup/pull/63 --- .../help-prints-config-file.out | 1 + .../help-prints-config-file.test.hs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 cabal-testsuite/PackageTests/Help/HelpPrintsConfigFile/help-prints-config-file.out create mode 100644 cabal-testsuite/PackageTests/Help/HelpPrintsConfigFile/help-prints-config-file.test.hs diff --git a/cabal-testsuite/PackageTests/Help/HelpPrintsConfigFile/help-prints-config-file.out b/cabal-testsuite/PackageTests/Help/HelpPrintsConfigFile/help-prints-config-file.out new file mode 100644 index 00000000000..8f859e4c506 --- /dev/null +++ b/cabal-testsuite/PackageTests/Help/HelpPrintsConfigFile/help-prints-config-file.out @@ -0,0 +1 @@ +# cabal --help diff --git a/cabal-testsuite/PackageTests/Help/HelpPrintsConfigFile/help-prints-config-file.test.hs b/cabal-testsuite/PackageTests/Help/HelpPrintsConfigFile/help-prints-config-file.test.hs new file mode 100644 index 00000000000..e725142bc24 --- /dev/null +++ b/cabal-testsuite/PackageTests/Help/HelpPrintsConfigFile/help-prints-config-file.test.hs @@ -0,0 +1,25 @@ +-- Andreas Abel, 2024-01-13 +-- +-- Ensure that the last line of the help text is the name of the config file. +-- This invariant is used by clients such as the Haskell setup github action. +-- See: https://github.com/haskell-actions/setup/pull/63 + +import Distribution.Utils.String (trim) +import Test.Cabal.Prelude + +main = cabalTest $ do + env <- getTestEnv + res <- cabal' "--help" [] + + -- The end of the help text should be something like: + -- + -- > You can edit the cabal configuration file to set defaults: + -- > <>/.cabal/config + -- + -- So trimming the last line will give us the name of the config file. + let configFile = trim . last . lines . resultOutput $ res + + -- Verify that this is indeed the config file. + assertEqual "Last line of help text should be name of the config file" + (testUserCabalConfigFile env) + configFile