-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Dummy where | ||
|
||
main :: IO () | ||
main = error "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module MyBenchModule where | ||
|
||
main :: IO () | ||
main = error "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module MyExeModule where | ||
|
||
main :: IO () | ||
main = error "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module MyLibModule where | ||
|
||
main :: IO () | ||
main = error "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module MyLibrary where | ||
|
||
main :: IO () | ||
main = error "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module MyTestModule where | ||
|
||
main :: IO () | ||
main = error "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters