Skip to content

Commit 852430c

Browse files
mpickeringMikolaj
authored andcommitted
Add tests which check build/dist-newstyle folders are not created with 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)
1 parent 85ef030 commit 852430c

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# cabal v2-run
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- fake-package-0 (exe:script-script.hs) (first run)
6+
Configuring executable 'script-script.hs' for fake-package-0...
7+
Building executable 'script-script.hs' for fake-package-0...
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $ do
4+
-- NB: Uses cabal_raw' here to direct simulate what a user would write (#10772)
5+
res <- defaultRecordMode RecordMarked $ do
6+
recordHeader ["cabal", "v2-run"]
7+
cabal_raw' ["v2-run", "script.hs", marked_verbose] Nothing
8+
assertOutputContains "Hello World" res
9+
10+
env <- getTestEnv
11+
cacheDir <- getScriptCacheDirectory (testCurrentDir env </> "script.hs")
12+
liftIO $ print (testTmpDir env </> "build")
13+
14+
shouldExist $ cacheDir </> "fake-package.cabal"
15+
shouldExist $ cacheDir </> "scriptlocation"
16+
shouldDirectoryNotExist $ testTmpDir env </> "build"
17+
shouldDirectoryNotExist $ testTmpDir env </> "dist-newstyle"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /usr/bin/env cabal
2+
{- cabal:
3+
build-depends: base >= 4.3 && <5
4+
-}
5+
{-# LANGUAGE ScopedTypeVariables #-}
6+
7+
import Prelude
8+
9+
main :: IO ()
10+
main = putStrLn "Hello World"
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import Test.Cabal.Prelude
22

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

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

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

0 commit comments

Comments
 (0)