@@ -49,7 +49,9 @@ import Distribution.Package
49
49
import Distribution.PackageDescription
50
50
import Distribution.InstalledPackageInfo (InstalledPackageInfo )
51
51
import Distribution.Simple.Setup (toFlag , HaddockFlags (.. ), defaultHaddockFlags )
52
+ import Distribution.Client.Setup (globalCommand )
52
53
import Distribution.Simple.Compiler
54
+ import Distribution.Simple.Command
53
55
import Distribution.System
54
56
import Distribution.Version
55
57
import Distribution.ModuleName (ModuleName )
@@ -71,6 +73,9 @@ import Test.Tasty.Options
71
73
import Data.Tagged (Tagged (.. ))
72
74
73
75
import qualified Data.ByteString as BS
76
+ import Distribution.Client.GlobalFlags (GlobalFlags , globalNix )
77
+ import Distribution.Simple.Flag (Flag (Flag , NoFlag ))
78
+ import Data.Maybe (fromJust )
74
79
75
80
#if !MIN_VERSION_directory(1,2,7)
76
81
removePathForcibly :: FilePath -> IO ()
@@ -139,9 +144,12 @@ tests config =
139
144
, testCase " program options scope local" (testProgramOptionsLocal config)
140
145
, testCase " program options scope specific" (testProgramOptionsSpecific config)
141
146
]
147
+ , testGroup " Flag tests" $
148
+ [
149
+ testCase " Test Nix Flag" testNixFlags
150
+ ]
142
151
]
143
152
144
-
145
153
testFindProjectRoot :: Assertion
146
154
testFindProjectRoot = do
147
155
Left (BadProjectRootExplicitFile file) <- findProjectRoot (Just testdir)
@@ -1927,3 +1935,25 @@ tryFewTimes action = go (3 :: Int) where
1927
1935
hPutStrLn stderr $ " Trying " ++ show n ++ " after " ++ show e
1928
1936
threadDelay 10000
1929
1937
go (n - 1 )
1938
+
1939
+ testNixFlags :: Assertion
1940
+ testNixFlags = do
1941
+ let gc = globalCommand []
1942
+ -- changing from the v1 to v2 build command does not change whether the "--enable-nix" flag
1943
+ -- sets the globalNix param of the GlobalFlags type to True even though the v2 command doesn't use it
1944
+ let nixEnabledFlags = getFlags gc . commandParseArgs gc True $ [" --enable-nix" , " build" ]
1945
+ let nixDisabledFlags = getFlags gc . commandParseArgs gc True $ [" --disable-nix" , " build" ]
1946
+ let nixDefaultFlags = getFlags gc . commandParseArgs gc True $ [" build" ]
1947
+ True @=? isJust nixDefaultFlags
1948
+ True @=? isJust nixEnabledFlags
1949
+ True @=? isJust nixDisabledFlags
1950
+ Just True @=? (fromFlag . globalNix . fromJust $ nixEnabledFlags)
1951
+ Just False @=? (fromFlag . globalNix . fromJust $ nixDisabledFlags)
1952
+ Nothing @=? (fromFlag . globalNix . fromJust $ nixDefaultFlags)
1953
+ where
1954
+ fromFlag :: Flag Bool -> Maybe Bool
1955
+ fromFlag (Flag x) = Just x
1956
+ fromFlag NoFlag = Nothing
1957
+ getFlags :: CommandUI GlobalFlags -> CommandParse (GlobalFlags -> GlobalFlags , [String ]) -> Maybe GlobalFlags
1958
+ getFlags cui (CommandReadyToGo (mkflags, _)) = Just . mkflags . commandDefaultFlags $ cui
1959
+ getFlags _ _ = Nothing
0 commit comments