Skip to content

Commit

Permalink
Tests for 'autogen-modules' field
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaste committed Aug 8, 2016
1 parent 6f5a3ac commit a00a30c
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ test-suite package-tests
type: exitcode-stdio-1.0
main-is: PackageTests.hs
other-modules:
PackageTests.AutogenModules.Check
PackageTests.BenchmarkStanza.Check
PackageTests.TestStanza.Check
PackageTests.DeterministicAr.Check
Expand Down
102 changes: 102 additions & 0 deletions Cabal/tests/PackageTests/AutogenModules/Check.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
module PackageTests.AutogenModules.Check where

import Distribution.ModuleName
import Distribution.Simple.LocalBuildInfo
import Distribution.PackageDescription
import PackageTests.PackageTester

suite :: TestM ()
suite = do

dist_dir <- distDir

-- Calling sdist without running configure first makes test fail with:
-- "Exception: Run the 'configure' command first."
-- Test Result output is: "Warning: Cannot run preprocessors. Run
-- 'configure' command first."
configureResult <- cabal' "configure" []
sdistResult <- cabal' "sdist" []

-- Now check that all the correct modules were parsed.
lbi <- liftIO $ getPersistBuildConfig dist_dir
let (Just gotLibrary) = library (localPkgDescr lbi)
let gotExecutable = head $ executables (localPkgDescr lbi)
let gotTestSuite = head $ testSuites (localPkgDescr lbi)
let gotBenchmark = head $ benchmarks (localPkgDescr lbi)
assertEqual "library 'autogen-modules' field does not match expected"
[fromString "MyHelperModule", fromString "MyLibHelperModule"]
(libModulesAutogen gotLibrary)
assertEqual "executable 'autogen-modules' field does not match expected"
[fromString "MyHelperModule", fromString "MyExeHelperModule"]
(exeModulesAutogen gotExecutable)
assertEqual "test-suite 'autogen-modules' field does not match expected"
[fromString "MyHelperModule", fromString "MyTestHelperModule"]
(testModulesAutogen gotTestSuite)
assertEqual "benchmark 'autogen-modules' field does not match expected"
[fromString "MyHelperModule", fromString "MyBenchHelperModule"]
(benchmarkModulesAutogen gotBenchmark)

-- Package check messages.
let libAutogenMsg =
"An 'autogen-module' is neither on 'exposed-modules' or "
++ "'other-modules'"
let exeAutogenMsg =
"On executable 'Exe' an 'autogen-module' is not on "
++ "'other-modules'"
let testAutogenMsg =
"On test suite 'Test' an 'autogen-module' is not on "
++ "'other-modules'"
let benchAutogenMsg =
"On benchmark 'Bench' an 'autogen-module' is not on "
++ "'other-modules'"

-- Asserts for the desired check messages after configure.
let warn = \str -> "Warning: " ++ str
assertOutputContains (warn libAutogenMsg) configureResult
assertOutputContains (warn exeAutogenMsg) configureResult
assertOutputContains (warn testAutogenMsg) configureResult
assertOutputContains (warn benchAutogenMsg) configureResult

-- Asserts for the desired check messages after sdist.
assertOutputContains "Distribution quality errors:" sdistResult
assertOutputContains libAutogenMsg configureResult
assertOutputContains exeAutogenMsg configureResult
assertOutputContains testAutogenMsg configureResult
assertOutputContains benchAutogenMsg configureResult
assertOutputContains "Distribution quality warnings:" sdistResult
assertOutputContains
"From version 1.25 autogenerated modules are included on the"
sdistResult

-- Assert sdist --list-sources output.
-- If called before configure fails, sdist directory is not created.
let listSourcesFileGot = dist_dir ++ "/" ++ "list-sources.txt"
cabal "sdist" ["--list-sources=" ++ listSourcesFileGot]
let listSourcesStrExpected =
#if defined(mingw32_HOST_OS)
".\\MyLibrary.hs\n"
++ ".\\MyLibModule.hs\n"
++ ".\\Dummy.hs\n"
++ ".\\MyExeModule.hs\n"
++ ".\\Dummy.hs\n"
++ ".\\MyTestModule.hs\n"
++ ".\\Dummy.hs\n"
++ ".\\MyBenchModule.hs\n"
++ ".\\my.cabal\n"
#else
"./MyLibrary.hs\n"
++ "./MyLibModule.hs\n"
++ "./Dummy.hs\n"
++ "./MyExeModule.hs\n"
++ "./Dummy.hs\n"
++ "./MyTestModule.hs\n"
++ "./Dummy.hs\n"
++ "./MyBenchModule.hs\n"
++ "./my.cabal\n"
#endif
listSourcesStrGot <- liftIO $ readFile listSourcesFileGot
assertEqual "sdist --list-sources does not match the expected files"
listSourcesStrExpected
listSourcesStrGot

return ()
4 changes: 4 additions & 0 deletions Cabal/tests/PackageTests/AutogenModules/Dummy.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Dummy where

main :: IO ()
main = error ""
4 changes: 4 additions & 0 deletions Cabal/tests/PackageTests/AutogenModules/MyBenchModule.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyBenchModule where

main :: IO ()
main = error ""
4 changes: 4 additions & 0 deletions Cabal/tests/PackageTests/AutogenModules/MyExeModule.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyExeModule where

main :: IO ()
main = error ""
4 changes: 4 additions & 0 deletions Cabal/tests/PackageTests/AutogenModules/MyLibModule.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyLibModule where

main :: IO ()
main = error ""
4 changes: 4 additions & 0 deletions Cabal/tests/PackageTests/AutogenModules/MyLibrary.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyLibrary where

main :: IO ()
main = error ""
4 changes: 4 additions & 0 deletions Cabal/tests/PackageTests/AutogenModules/MyTestModule.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyTestModule where

main :: IO ()
main = error ""
63 changes: 63 additions & 0 deletions Cabal/tests/PackageTests/AutogenModules/my.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: AutogenModules
version: 0.1
license: BSD3
author: Federico Mastellone
maintainer: Federico Mastellone
synopsis: AutogenModules
category: PackageTests
build-type: Simple
cabal-version: >= 1.10

description:
Check that Cabal recognizes the autogen-modules fields below.

Library
default-language: Haskell2010
build-depends: base
exposed-modules:
MyLibrary
Paths_AutogenModules
MyLibHelperModule
other-modules:
MyLibModule
autogen-modules:
MyHelperModule
MyLibHelperModule

Executable Exe
default-language: Haskell2010
main-is: Dummy.hs
build-depends: base
other-modules:
MyExeModule
Paths_AutogenModules
MyExeHelperModule
autogen-modules:
MyHelperModule
MyExeHelperModule

Test-Suite Test
default-language: Haskell2010
main-is: Dummy.hs
type: exitcode-stdio-1.0
build-depends: base
other-modules:
MyTestModule
Paths_AutogenModules
MyTestHelperModule
autogen-modules:
MyHelperModule
MyTestHelperModule

Benchmark Bench
default-language: Haskell2010
main-is: Dummy.hs
type: exitcode-stdio-1.0
build-depends: base
other-modules:
MyBenchModule
Paths_AutogenModules
MyBenchHelperModule
autogen-modules:
MyHelperModule
MyBenchHelperModule
4 changes: 4 additions & 0 deletions Cabal/tests/PackageTests/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module PackageTests.Tests(tests) where

import PackageTests.PackageTester

import qualified PackageTests.AutogenModules.Check
import qualified PackageTests.BenchmarkStanza.Check
import qualified PackageTests.TestStanza.Check
import qualified PackageTests.DeterministicAr.Check
Expand Down Expand Up @@ -31,6 +32,9 @@ tests config = do
---------------------------------------------------------------------
-- * External tests

-- Test that Cabal parses and uses 'autogen-modules' fields correctly
tc "AutogenModules" PackageTests.AutogenModules.Check.suite

-- Test that Cabal parses 'benchmark' sections correctly
tc "BenchmarkStanza" PackageTests.BenchmarkStanza.Check.suite

Expand Down

0 comments on commit a00a30c

Please sign in to comment.