Skip to content

Commit 783cf64

Browse files
committed
Tests for 'autogen-modules' field
1 parent 17dfb7b commit 783cf64

22 files changed

+358
-0
lines changed

Cabal/Cabal.cabal

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ extra-source-files:
3838
tests/PackageTests/AllowOlder/benchmarks/Bench.hs
3939
tests/PackageTests/AllowOlder/src/Foo.hs
4040
tests/PackageTests/AllowOlder/tests/Test.hs
41+
tests/PackageTests/AutogenModules/Package/Dummy.hs
42+
tests/PackageTests/AutogenModules/Package/LICENSE
43+
tests/PackageTests/AutogenModules/Package/MyBenchModule.hs
44+
tests/PackageTests/AutogenModules/Package/MyExeModule.hs
45+
tests/PackageTests/AutogenModules/Package/MyLibModule.hs
46+
tests/PackageTests/AutogenModules/Package/MyLibrary.hs
47+
tests/PackageTests/AutogenModules/Package/MyTestModule.hs
48+
tests/PackageTests/AutogenModules/Package/my.cabal
49+
tests/PackageTests/AutogenModules/SrcDist/Dummy.hs
50+
tests/PackageTests/AutogenModules/SrcDist/LICENSE
51+
tests/PackageTests/AutogenModules/SrcDist/MyBenchModule.hs
52+
tests/PackageTests/AutogenModules/SrcDist/MyExeModule.hs
53+
tests/PackageTests/AutogenModules/SrcDist/MyLibModule.hs
54+
tests/PackageTests/AutogenModules/SrcDist/MyLibrary.hs
55+
tests/PackageTests/AutogenModules/SrcDist/MyTestModule.hs
56+
tests/PackageTests/AutogenModules/SrcDist/list-sources.txt
57+
tests/PackageTests/AutogenModules/SrcDist/my.cabal
4158
tests/PackageTests/BenchmarkExeV10/Foo.hs
4259
tests/PackageTests/BenchmarkExeV10/benchmarks/bench-Foo.hs
4360
tests/PackageTests/BenchmarkExeV10/my.cabal
@@ -435,6 +452,8 @@ test-suite package-tests
435452
type: exitcode-stdio-1.0
436453
main-is: PackageTests.hs
437454
other-modules:
455+
PackageTests.AutogenModules.Package.Check
456+
PackageTests.AutogenModules.SrcDist.Check
438457
PackageTests.BenchmarkStanza.Check
439458
PackageTests.TestStanza.Check
440459
PackageTests.DeterministicAr.Check
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module PackageTests.AutogenModules.Package.Check where
2+
3+
import PackageTests.PackageTester
4+
5+
suite :: TestM ()
6+
suite = do
7+
8+
configureResult <- shouldFail $ cabal' "configure" []
9+
sdistResult <- shouldFail $ cabal' "sdist" []
10+
11+
-- Package check messages.
12+
let libAutogenMsg =
13+
"An 'autogen-module' is neither on 'exposed-modules' or "
14+
++ "'other-modules'"
15+
let exeAutogenMsg =
16+
"On executable 'Exe' an 'autogen-module' is not on "
17+
++ "'other-modules'"
18+
let testAutogenMsg =
19+
"On test suite 'Test' an 'autogen-module' is not on "
20+
++ "'other-modules'"
21+
let benchAutogenMsg =
22+
"On benchmark 'Bench' an 'autogen-module' is not on "
23+
++ "'other-modules'"
24+
25+
-- Asserts for the desired check messages after configure.
26+
assertOutputContains libAutogenMsg configureResult
27+
assertOutputContains exeAutogenMsg configureResult
28+
assertOutputContains testAutogenMsg configureResult
29+
assertOutputContains benchAutogenMsg configureResult
30+
31+
-- Asserts for the desired check messages after sdist.
32+
assertOutputContains "Distribution quality errors:" sdistResult
33+
assertOutputContains libAutogenMsg sdistResult
34+
assertOutputContains exeAutogenMsg sdistResult
35+
assertOutputContains testAutogenMsg sdistResult
36+
assertOutputContains benchAutogenMsg sdistResult
37+
assertOutputContains
38+
"Packages using 'cabal-version: >= 1.25' and the autogenerated"
39+
sdistResult
40+
assertOutputContains
41+
"module Paths_* must include it also on the 'autogen-modules'"
42+
sdistResult
43+
assertOutputContains
44+
"Error: Could not find module: MyLibHelperModule with any suffix"
45+
sdistResult
46+
assertOutputContains
47+
"module is autogenerated it should be added to 'autogen-modules'"
48+
sdistResult
49+
-- Asserts for the undesired check messages after sdist.
50+
assertOutputDoesNotContain "Distribution quality warnings:" sdistResult
51+
52+
return ()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Dummy where
2+
3+
main :: IO ()
4+
main = error ""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LICENSE
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyBenchModule where
2+
3+
main :: IO ()
4+
main = error ""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyExeModule where
2+
3+
main :: IO ()
4+
main = error ""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyLibModule where
2+
3+
main :: IO ()
4+
main = error ""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyLibrary where
2+
3+
main :: IO ()
4+
main = error ""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyTestModule where
2+
3+
main :: IO ()
4+
main = error ""
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: AutogenModules
2+
version: 0.1
3+
license: BSD3
4+
license-file: LICENSE
5+
author: Federico Mastellone
6+
maintainer: Federico Mastellone
7+
synopsis: AutogenModules
8+
category: PackageTests
9+
build-type: Simple
10+
cabal-version: >= 1.25
11+
12+
description:
13+
Check that Cabal recognizes the autogen-modules fields below.
14+
15+
Library
16+
default-language: Haskell2010
17+
build-depends: base
18+
exposed-modules:
19+
MyLibrary
20+
Paths_AutogenModules
21+
MyLibHelperModule
22+
other-modules:
23+
MyLibModule
24+
autogen-modules:
25+
MyHelperModule
26+
27+
Executable Exe
28+
default-language: Haskell2010
29+
main-is: Dummy.hs
30+
build-depends: base
31+
other-modules:
32+
MyExeModule
33+
Paths_AutogenModules
34+
MyExeHelperModule
35+
autogen-modules:
36+
MyHelperModule
37+
38+
Test-Suite Test
39+
default-language: Haskell2010
40+
main-is: Dummy.hs
41+
type: exitcode-stdio-1.0
42+
build-depends: base
43+
other-modules:
44+
MyTestModule
45+
Paths_AutogenModules
46+
MyTestHelperModule
47+
autogen-modules:
48+
MyHelperModule
49+
50+
Benchmark Bench
51+
default-language: Haskell2010
52+
main-is: Dummy.hs
53+
type: exitcode-stdio-1.0
54+
build-depends: base
55+
other-modules:
56+
MyBenchModule
57+
Paths_AutogenModules
58+
MyBenchHelperModule
59+
autogen-modules:
60+
MyHelperModule

Cabal/tests/PackageTests/AutogenModules/Package/tmp

Whitespace-only changes.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
module PackageTests.AutogenModules.SrcDist.Check where
2+
3+
import Distribution.ModuleName
4+
import Distribution.Simple.LocalBuildInfo
5+
import Distribution.PackageDescription
6+
import PackageTests.PackageTester
7+
8+
suite :: TestM ()
9+
suite = do
10+
11+
dist_dir <- distDir
12+
13+
-- Calling sdist without running configure first makes test fail with:
14+
-- "Exception: Run the 'configure' command first."
15+
-- Test Result output is: "Warning: Cannot run preprocessors. Run
16+
-- 'configure' command first."
17+
-- This is becuase we are calling getPersistBuildConfig
18+
19+
configureResult <- cabal' "configure" []
20+
sdistResult <- cabal' "sdist" []
21+
22+
-- Now check that all the correct modules were parsed.
23+
lbi <- liftIO $ getPersistBuildConfig dist_dir
24+
let (Just gotLibrary) = library (localPkgDescr lbi)
25+
let gotExecutable = head $ executables (localPkgDescr lbi)
26+
let gotTestSuite = head $ testSuites (localPkgDescr lbi)
27+
let gotBenchmark = head $ benchmarks (localPkgDescr lbi)
28+
assertEqual "library 'autogen-modules' field does not match expected"
29+
[fromString "MyLibHelperModule"]
30+
(libModulesAutogen gotLibrary)
31+
assertEqual "executable 'autogen-modules' field does not match expected"
32+
[fromString "MyExeHelperModule"]
33+
(exeModulesAutogen gotExecutable)
34+
assertEqual "test-suite 'autogen-modules' field does not match expected"
35+
[fromString "MyTestHelperModule"]
36+
(testModulesAutogen gotTestSuite)
37+
assertEqual "benchmark 'autogen-modules' field does not match expected"
38+
[fromString "MyBenchHelperModule"]
39+
(benchmarkModulesAutogen gotBenchmark)
40+
41+
-- Package check messages.
42+
let libAutogenMsg =
43+
"An 'autogen-module' is neither on 'exposed-modules' or "
44+
++ "'other-modules'"
45+
let exeAutogenMsg =
46+
"On executable 'Exe' an 'autogen-module' is not on "
47+
++ "'other-modules'"
48+
let testAutogenMsg =
49+
"On test suite 'Test' an 'autogen-module' is not on "
50+
++ "'other-modules'"
51+
let benchAutogenMsg =
52+
"On benchmark 'Bench' an 'autogen-module' is not on "
53+
++ "'other-modules'"
54+
55+
-- Asserts for the undesired check messages after configure.
56+
assertOutputDoesNotContain libAutogenMsg configureResult
57+
assertOutputDoesNotContain exeAutogenMsg configureResult
58+
assertOutputDoesNotContain testAutogenMsg configureResult
59+
assertOutputDoesNotContain benchAutogenMsg configureResult
60+
61+
-- Asserts for the undesired check messages after sdist.
62+
assertOutputDoesNotContain "Distribution quality errors:" sdistResult
63+
assertOutputDoesNotContain libAutogenMsg sdistResult
64+
assertOutputDoesNotContain exeAutogenMsg sdistResult
65+
assertOutputDoesNotContain testAutogenMsg sdistResult
66+
assertOutputDoesNotContain benchAutogenMsg sdistResult
67+
68+
-- Asserts for the desired check messages after sdist.
69+
assertOutputContains "Distribution quality warnings:" sdistResult
70+
assertOutputContains
71+
"From version 1.25 autogenerated modules are included on the"
72+
sdistResult
73+
assertOutputContains
74+
"'autogen-modules' field besides 'exposed-modules' and"
75+
sdistResult
76+
77+
-- Assert sdist --list-sources output.
78+
-- If called before configure fails, dist directory is not created.
79+
let listSourcesFileGot = dist_dir ++ "/" ++ "list-sources.txt"
80+
cabal "sdist" ["--list-sources=" ++ listSourcesFileGot]
81+
let listSourcesStrExpected =
82+
#if defined(mingw32_HOST_OS)
83+
".\\MyLibrary.hs\n"
84+
++ ".\\MyLibModule.hs\n"
85+
++ ".\\Dummy.hs\n"
86+
++ ".\\MyExeModule.hs\n"
87+
++ ".\\Dummy.hs\n"
88+
++ ".\\MyTestModule.hs\n"
89+
++ ".\\Dummy.hs\n"
90+
++ ".\\MyBenchModule.hs\n"
91+
++ "LICENSE\n"
92+
++ ".\\my.cabal\n"
93+
#else
94+
"./MyLibrary.hs\n"
95+
++ "./MyLibModule.hs\n"
96+
++ "./Dummy.hs\n"
97+
++ "./MyExeModule.hs\n"
98+
++ "./Dummy.hs\n"
99+
++ "./MyTestModule.hs\n"
100+
++ "./Dummy.hs\n"
101+
++ "./MyBenchModule.hs\n"
102+
++ "LICENSE\n"
103+
++ "./my.cabal\n"
104+
#endif
105+
listSourcesStrGot <- liftIO $ readFile listSourcesFileGot
106+
assertEqual "sdist --list-sources does not match the expected files"
107+
listSourcesStrExpected
108+
listSourcesStrGot
109+
110+
return ()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Dummy where
2+
3+
main :: IO ()
4+
main = error ""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LICENSE
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyBenchModule where
2+
3+
main :: IO ()
4+
main = error ""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyExeModule where
2+
3+
main :: IO ()
4+
main = error ""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyLibModule where
2+
3+
main :: IO ()
4+
main = error ""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyLibrary where
2+
3+
main :: IO ()
4+
main = error ""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyTestModule where
2+
3+
main :: IO ()
4+
main = error ""

Cabal/tests/PackageTests/AutogenModules/SrcDist/list-sources.txt

Whitespace-only changes.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: AutogenModules
2+
version: 0.1
3+
license: BSD3
4+
license-file: LICENSE
5+
author: Federico Mastellone
6+
maintainer: Federico Mastellone
7+
synopsis: AutogenModules
8+
category: PackageTests
9+
build-type: Simple
10+
cabal-version: >= 1.24
11+
12+
description:
13+
Check that Cabal recognizes the autogen-modules fields below.
14+
15+
Library
16+
default-language: Haskell2010
17+
build-depends: base
18+
exposed-modules:
19+
MyLibrary
20+
Paths_AutogenModules
21+
MyLibHelperModule
22+
other-modules:
23+
MyLibModule
24+
autogen-modules:
25+
MyLibHelperModule
26+
27+
Executable Exe
28+
default-language: Haskell2010
29+
main-is: Dummy.hs
30+
build-depends: base
31+
other-modules:
32+
MyExeModule
33+
Paths_AutogenModules
34+
MyExeHelperModule
35+
autogen-modules:
36+
MyExeHelperModule
37+
38+
Test-Suite Test
39+
default-language: Haskell2010
40+
main-is: Dummy.hs
41+
type: exitcode-stdio-1.0
42+
build-depends: base
43+
other-modules:
44+
MyTestModule
45+
Paths_AutogenModules
46+
MyTestHelperModule
47+
autogen-modules:
48+
MyTestHelperModule
49+
50+
Benchmark Bench
51+
default-language: Haskell2010
52+
main-is: Dummy.hs
53+
type: exitcode-stdio-1.0
54+
build-depends: base
55+
other-modules:
56+
MyBenchModule
57+
Paths_AutogenModules
58+
MyBenchHelperModule
59+
autogen-modules:
60+
MyBenchHelperModule

0 commit comments

Comments
 (0)