Skip to content

Fix #8400 by marking output of cabal list-bin #8670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions cabal-install/src/Distribution/Client/CmdListBin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import Distribution.Client.TargetProblem (TargetProblem (..))
import Distribution.Simple.BuildPaths (dllExtension, exeExtension)
import Distribution.Simple.Command (CommandUI (..))
import Distribution.Simple.Setup (configVerbosity, fromFlagOrDefault)
import Distribution.Simple.Utils (die', info, wrapText)
import Distribution.Simple.Utils (die', withOutputMarker, wrapText)
import Distribution.System (Platform)
import Distribution.Types.ComponentName (showComponentName)
import Distribution.Types.UnitId (UnitId)
import Distribution.Types.UnqualComponentName (UnqualComponentName)
import Distribution.Verbosity (normal, silent, verboseStderr)
import Distribution.Verbosity (silent, verboseStderr)
import System.FilePath ((<.>), (</>))

import qualified Data.Map as Map
Expand Down Expand Up @@ -133,7 +133,14 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do

case binfiles of
[] -> die' verbosity "No target found"
[exe] -> info normal exe
[exe] -> putStr $ withOutputMarker verbosity exe
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not putStrLn?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, all tests had EOF at the end, so this wasn't visible.

Copy link
Member Author

@andreasabel andreasabel Jan 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, putStrLn would be better in the normal operation. I guess I got pulled towards putStr because the withOutputMarker puts the EOL character there:

withOutputMarker _ xs =
"-----BEGIN CABAL OUTPUT-----\n" ++
withTrailingNewline xs ++
"-----END CABAL OUTPUT-----\n"

So maybe the correct way is:

  putStr $ withOutputMarker verbosity $ exe ++ "\n"

-- Andreas, 2023-01-13, issue #8400:
-- Regular output of `list-bin` should go to stdout unconditionally,
-- but for the sake of the testsuite, we want to mark it so it goes
-- into the golden value for the test.
-- Note: 'withOutputMarker' only checks 'isVerboseMarkOutput',
-- thus, we can reuse @verbosity@ here, even if other components
-- of @verbosity@ may be wrong (like 'VStderr', verbosity level etc.).
_ -> die' verbosity "Multiple targets found"
where
defaultVerbosity = verboseStderr silent
Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/ListBin/Script/cabal.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- fake-package-0 (exe:cabal-script-script.hs) (first run)
<ROOT>/cabal.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/fake-package-0/x/cabal-script-script.hs/build/cabal-script-script.hs/cabal-script-script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- SelectedComponent-1.0.0 (exe:testexe) (first run)
<ROOT>/cabal.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/SelectedComponent-1.0.0/build/testexe/testexe
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import System.FilePath ( joinPath )

import Test.Cabal.Prelude

-- https://github.com/haskell/cabal/issues/7679
-- https://github.com/haskell/cabal/issues/8400

main = cabalTest . void $ do
res <- cabal' "list-bin" ["exe:testexe"]

assertOutputContains "SelectedComponent-1.0.0" res
assertOutputContains "testexe" res
let path = joinPath ["SelectedComponent-1.0.0", "build", "testexe", "testexe"]
assertOutputContains path res