Skip to content

Commit

Permalink
Add tests which check build/dist-newstyle folders are not created wit…
Browse files Browse the repository at this point in the history
…h v2-run

The existing test CmdRun/Script is modified to test the case when v2-run
is executed in a project context. This test checks that a "build" folder
is not created in the CWD (#10772)

A new test is also added which checks what happens in the "no context"
case. A separate bug was fixed in this area recently but no test added
which verifies the change (#10686)
  • Loading branch information
mpickering committed Feb 25, 2025
1 parent 6ddbdcf commit 45e0730
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- fake-package-0 (exe:script-script.hs) (first run)
Configuring executable 'script-script.hs' for fake-package-0...
Building executable 'script-script.hs' for fake-package-0...
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Test.Cabal.Prelude

main = cabalTest $ do
-- NB: Uses cabal_raw' here to direct simulate what a user would write (#10772)
res <- defaultRecordMode RecordMarked $ do
recordHeader ["cabal", "v2-run"]
cabal_raw' ["v2-run", "script.hs", marked_verbose] Nothing
assertOutputContains "Hello World" res

env <- getTestEnv
cacheDir <- getScriptCacheDirectory (testCurrentDir env </> "script.hs")
liftIO $ print (testTmpDir env </> "build")

shouldExist $ cacheDir </> "fake-package.cabal"
shouldExist $ cacheDir </> "scriptlocation"
shouldDirectoryNotExist $ testTmpDir env </> "build"
shouldDirectoryNotExist $ testTmpDir env </> "dist-newstyle"
11 changes: 11 additions & 0 deletions cabal-testsuite/PackageTests/NewBuild/CmdRun/NoContext/script.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /usr/bin/env cabal
{- cabal:
build-depends: base >= 4.3 && <5
-}
{-# LANGUAGE BangPatterns #-}

Check warning on line 5 in cabal-testsuite/PackageTests/NewBuild/CmdRun/NoContext/script.hs

View workflow job for this annotation

GitHub Actions / hlint

Warning in module Main: Unused LANGUAGE pragma ▫︎ Found: "{-# LANGUAGE BangPatterns #-}"

Check warning on line 5 in cabal-testsuite/PackageTests/NewBuild/CmdRun/NoContext/script.hs

View workflow job for this annotation

GitHub Actions / hlint

Warning in module Main: Unused LANGUAGE pragma ▫︎ Found: "{-# LANGUAGE BangPatterns #-}"
{-# LANGUAGE ScopedTypeVariables #-}

import Prelude

main :: IO ()
main = putStrLn "Hello World"
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import Test.Cabal.Prelude

main = cabalTest $ do
res <- cabal' "v2-run" ["script.hs"]
-- NB: Uses cabal_raw' here to direct simulate what a user would write (#10772)
res <- defaultRecordMode RecordMarked $ do
recordHeader ["cabal", "v2-run"]
cabal_raw' ["v2-run", "script.hs", marked_verbose] Nothing
assertOutputContains "Hello World" res

env <- getTestEnv
cacheDir <- getScriptCacheDirectory (testCurrentDir env </> "script.hs")
liftIO $ print (testTmpDir env </> "build")

shouldExist $ cacheDir </> "fake-package.cabal"
shouldExist $ cacheDir </> "scriptlocation"
shouldDirectoryNotExist $ testTmpDir env </> "build"
-- "dist-newstyle" should exist, because the folder has a cabal.project in
-- so the v2-run command runs in that context.
shouldDirectoryExist $ testTmpDir env </> "dist-newstyle"

0 comments on commit 45e0730

Please sign in to comment.