Skip to content

Commit

Permalink
Re-design test-cases for show-build-info
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor committed Jul 14, 2021
1 parent 8ce27f2 commit 6bef1c7
Show file tree
Hide file tree
Showing 68 changed files with 415 additions and 385 deletions.
10 changes: 6 additions & 4 deletions cabal-testsuite/PackageTests/Configure/include/HsZlibConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H

/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H

/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H

/* Define to 1 if you have the <stdio.h> header file. */
#undef HAVE_STDIO_H

/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H

Expand Down Expand Up @@ -45,5 +45,7 @@
/* Define to the version of this package. */
#undef PACKAGE_VERSION

/* Define to 1 if you have the ANSI C header files. */
/* Define to 1 if all of the C90 standard headers exist (not just the ones
required in a freestanding environment). This macro is provided for
backward compatibility; new code need not use it. */
#undef STDC_HEADERS
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/ShowBuildInfo/A/A.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ executable A
test-suite A-tests
type: exitcode-stdio-1.0
main-is: Test.hs
build-depends: base >=4
build-depends: base >=4, A
hs-source-dirs: src
default-language: Haskell2010
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 0.1.0.0
license: BSD-3-Clause

library
exposed-modules: A
exposed-modules: B
build-depends: base >=4.0.0.0, A
hs-source-dirs: src
hs-source-dirs: lib
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module A where
module B where

foo :: Int -> Int
foo = id
2 changes: 0 additions & 2 deletions cabal-testsuite/PackageTests/ShowBuildInfo/A/Setup.hs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude
import Test.Cabal.DecodeShowBuildInfo

main = cabalTest $ do
buildInfo <- runShowBuildInfo ["lib:B"]
assertCommonBuildInfo buildInfo
assertEqual "Number of Components" 1 (length $ components buildInfo)
let [libComp] = components buildInfo
assertLibComponent libComp "lib" ["B"] ["lib"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Test.Cabal.Prelude
import Test.Cabal.DecodeShowBuildInfo

main = cabalTest $ do
buildInfo <- runShowBuildInfo ["lib:B", "lib:A"]
assertCommonBuildInfo buildInfo
assertEqual "Number of Components" 2 (length $ components buildInfo)
let [libAComp, libBComp] = components buildInfo
assertLibComponent libAComp "lib" ["A"] ["src"]
assertLibComponent libBComp "lib" ["B"] ["lib"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import Test.Cabal.Prelude
import Test.Cabal.DecodeShowBuildInfo

main = cabalTest $ do
buildInfo <- runShowBuildInfo ["-v0"] -- hide verbose output so we can parse
let comps = components buildInfo
assertEqual "Components, exactly three" 3 (length comps)
assertEqual "Test components, exactly one" 1 $
length $ filter (\c -> "test" == componentType c) comps
buildInfo <- runShowBuildInfo ["all", "--enable-tests"]
assertCommonBuildInfo buildInfo
assertEqual "Number of Components" 4 (length $ components buildInfo)
let [libAComp, exeComp, testComp, libBComp] = components buildInfo
assertExeComponent exeComp "exe:A" ["Main.hs"] ["src"]
assertLibComponent libAComp "lib" ["A"] ["src"]
assertLibComponent libBComp "lib" ["B"] ["lib"]
assertTestComponent testComp "test:A-tests" ["Test.hs"] ["src"]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Test.Cabal.Prelude
import Test.Cabal.DecodeShowBuildInfo

main = cabalTest $ do
buildInfo <- runShowBuildInfo ["exe:A"]
assertCommonBuildInfo buildInfo
assertEqual "Number of Components" 1 (length $ components buildInfo)
let [exeComp] = components buildInfo
assertExeComponent exeComp "exe:A" ["Main.hs"] ["src"]

-- Must not have library as a dependency as "exe:A" does not depend on it.
assertBool "Does not contain library as dependency"
(all (/= "A-0.1.0.0-inplace") $ componentCompilerArgs exeComp)

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# cabal show-build-info
Resolving dependencies...
Configuring library for A-0.1.0.0..
Configuring executable 'A' for A-0.1.0.0..
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Test.Cabal.Prelude
import Test.Cabal.DecodeShowBuildInfo

main = cabalTest $ withSourceCopy $ do
cwd <- fmap testCurrentDir getTestEnv
let fp = cwd </> "unit.json"
_ <- cabal' "show-build-info" ["--buildinfo-json-output=" ++ fp, "exe:A", "lib:A"]
buildInfo <- decodeBuildInfoFile fp
assertCommonBuildInfo buildInfo
assertEqual "Number of Components" 2 (length $ components buildInfo)
let [libBuildInfo, exeBuildInfo] = components buildInfo
assertExeComponent exeBuildInfo "exe:A" ["Main.hs"] ["src"]
assertLibComponent libBuildInfo "lib" ["A"] ["src"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude
import Test.Cabal.DecodeShowBuildInfo

main = cabalTest $ do
buildInfo <- runShowBuildInfo ["exe:A", "lib:A"]
assertCommonBuildInfo buildInfo
let [libBuildInfo, exeBuildInfo] = components buildInfo
assertExeComponent exeBuildInfo "exe:A" ["Main.hs"] ["src"]
assertLibComponent libBuildInfo "lib" ["A"] ["src"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Test.Cabal.Prelude
import Test.Cabal.DecodeShowBuildInfo

main = cabalTest $ do
buildInfo <- runShowBuildInfo []
assertCommonBuildInfo buildInfo
let comps = components buildInfo
assertEqual "Number of Components" 2 (length comps)
assertBool "Contains main component executable"
(any (\c -> "exe:A" == componentName c) comps)
assertBool "Contains main component library"
(any (\c -> "lib" == componentName c) comps)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Test.Cabal.Prelude
import Test.Cabal.DecodeShowBuildInfo

main = cabalTest $ do
buildInfo <- runShowBuildInfo ["test:A-tests"]
assertCommonBuildInfo buildInfo
assertEqual "Number of Components" 1 (length $ components buildInfo)
let [testComp] = components buildInfo
assertTestComponent testComp "test:A-tests" ["Test.hs"] ["src"]

-- Must have library as a dependency as "test:A-tests" depends on it.
assertBool "Contains internal dependency"
(any (== "A-0.1.0.0-inplace") $ componentCompilerArgs testComp)
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
# cabal show-build-info
cabal: Internal error in target matching. It should always be possible to find a syntax that's sufficiently qualified to give an unambiguous match. However when matching 'exe:B' we found exe:B (unknown-component) which does not have an unambiguous syntax. The possible syntax and the targets they match are as follows:
'exe:B' which matches exe:B (unknown-component), :pkg:exe:lib:exe:module:B (unknown-module), :pkg:exe:lib:exe:file:B (unknown-file)
# cabal show-build-info
Resolving dependencies...
cabal: No unit B-inplace-0.1.0.0
# cabal show-build-info
cabal: No unit B-inplace-0.1.0.0
# cabal show-build-info
cabal: Internal error in target matching. It should always be possible to find a syntax that's sufficiently qualified to give an unambiguous match. However when matching 'exe:B' we found exe:B (unknown-component) which does not have an unambiguous syntax. The possible syntax and the targets they match are as follows:
'exe:B' which matches exe:B (unknown-component), :pkg:exe:lib:exe:module:B (unknown-module), :pkg:exe:lib:exe:file:B (unknown-file)
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Test.Cabal.Prelude

main = cabalTest $ do
r <- fails $ cabal' "show-build-info" ["exe:B"]
r <- fails $ cabal' "show-build-info" ["exe:B", "-v1"]
assertOutputContains "Internal error in target matching." r

r <- fails $ cabal' "show-build-info" ["--unit-ids-json=B-inplace-0.1.0.0"]
assertOutputContains "No unit B-inplace-0.1.0.0" r
r <- fails $ cabal' "show-build-info" ["C", "-v1"]
assertOutputContains "Cannot show-build-info the package C, it is not in this project (either directly or indirectly)." r

r <- fails $ cabal' "show-build-info" ["--unit-ids-json=A-0.1.0.0-inplace B-inplace-0.1.0.0"]
assertOutputContains "No unit B-inplace-0.1.0.0" r

r <- fails $ cabal' "show-build-info" ["--unit-ids-json=A-0.1.0.0-inplace", "exe:B"]
r <- fails $ cabal' "show-build-info" ["lib:C", "-v1"]
assertOutputContains "Internal error in target matching." r

r <- fails $ cabal' "show-build-info" ["benchmarks", "-v1"]
assertOutputContains "Cannot show-build-info the benchmarks in the package A-0.1.0.0 because it does not contain any benchmarks." r

2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/ShowBuildInfo/A/cabal.project
Original file line number Diff line number Diff line change
@@ -1 +1 @@
packages: .
packages: . ./B/
2 changes: 0 additions & 2 deletions cabal-testsuite/PackageTests/ShowBuildInfo/B/Setup.hs

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions cabal-testsuite/PackageTests/ShowBuildInfo/B/cabal.project

This file was deleted.

15 changes: 0 additions & 15 deletions cabal-testsuite/PackageTests/ShowBuildInfo/C/C.cabal

This file was deleted.

3 changes: 0 additions & 3 deletions cabal-testsuite/PackageTests/ShowBuildInfo/C/Lib.hs

This file was deleted.

1 change: 0 additions & 1 deletion cabal-testsuite/PackageTests/ShowBuildInfo/C/Test.hs

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion cabal-testsuite/PackageTests/ShowBuildInfo/C/cabal.project

This file was deleted.

Loading

0 comments on commit 6bef1c7

Please sign in to comment.