|
| 1 | +module PackageTests.AutogenModules.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 | + package_dir <- packageDir |
| 13 | + |
| 14 | + -- Calling sdist without running configure first makes test fail with: |
| 15 | + -- "Exception: Run the 'configure' command first." |
| 16 | + -- Test Result output is: "Warning: Cannot run preprocessors. Run |
| 17 | + -- 'configure' command first." |
| 18 | + configureResult <- cabal' "configure" [] |
| 19 | + sdistResult <- cabal' "sdist" [] |
| 20 | + |
| 21 | + -- Now check that all the correct modules were parsed. |
| 22 | + lbi <- liftIO $ getPersistBuildConfig dist_dir |
| 23 | + let (Just gotLibrary) = library (localPkgDescr lbi) |
| 24 | + let gotExecutable = head $ executables (localPkgDescr lbi) |
| 25 | + let gotTestSuite = head $ testSuites (localPkgDescr lbi) |
| 26 | + let gotBenchmark = head $ benchmarks (localPkgDescr lbi) |
| 27 | + assertEqual "library 'autogen-modules' field does not match expected" |
| 28 | + [fromString "MyHelperModule", fromString "MyLibHelperModule"] |
| 29 | + (libModulesAutogen gotLibrary) |
| 30 | + assertEqual "executable 'autogen-modules' field does not match expected" |
| 31 | + [fromString "MyHelperModule", fromString "MyExeHelperModule"] |
| 32 | + (exeModulesAutogen gotExecutable) |
| 33 | + assertEqual "test-suite 'autogen-modules' field does not match expected" |
| 34 | + [fromString "MyHelperModule", fromString "MyTestHelperModule"] |
| 35 | + (testModulesAutogen gotTestSuite) |
| 36 | + assertEqual "benchmark 'autogen-modules' field does not match expected" |
| 37 | + [fromString "MyHelperModule", fromString "MyBenchHelperModule"] |
| 38 | + (benchmarkModulesAutogen gotBenchmark) |
| 39 | + |
| 40 | + -- Package check messages. |
| 41 | + let libAutogenMsg = |
| 42 | + "An 'autogen-module' is neither on 'exposed-modules' or " |
| 43 | + ++ "'other-modules'" |
| 44 | + let exeAutogenMsg = |
| 45 | + "On executable 'Exe' an 'autogen-module' is not on " |
| 46 | + ++ "'other-modules'" |
| 47 | + let testAutogenMsg = |
| 48 | + "On test suite 'Test' an 'autogen-module' is not on " |
| 49 | + ++ "'other-modules'" |
| 50 | + let benchAutogenMsg = |
| 51 | + "On benchmark 'Bench' an 'autogen-module' is not on " |
| 52 | + ++ "'other-modules'" |
| 53 | + |
| 54 | + -- Asserts for the desired check messages after configure. |
| 55 | + let warn = \str -> "Warning: " ++ str |
| 56 | + assertOutputContains (warn libAutogenMsg) configureResult |
| 57 | + assertOutputContains (warn exeAutogenMsg) configureResult |
| 58 | + assertOutputContains (warn testAutogenMsg) configureResult |
| 59 | + assertOutputContains (warn benchAutogenMsg) configureResult |
| 60 | + |
| 61 | + -- Asserts for the desired check messages after sdist. |
| 62 | + assertOutputContains "Distribution quality errors:" sdistResult |
| 63 | + assertOutputContains libAutogenMsg configureResult |
| 64 | + assertOutputContains exeAutogenMsg configureResult |
| 65 | + assertOutputContains testAutogenMsg configureResult |
| 66 | + assertOutputContains benchAutogenMsg configureResult |
| 67 | + assertOutputContains "Distribution quality warnings:" sdistResult |
| 68 | + assertOutputContains |
| 69 | + "From version 1.25 autogenerated modules are included on the" |
| 70 | + sdistResult |
| 71 | + |
| 72 | + -- Assert sdist --list-sources output. |
| 73 | + -- If called before configure fails, sdist directory is not created. |
| 74 | + let listSourcesFileGot = dist_dir ++ "/" ++ "list-sources.txt" |
| 75 | + cabal "sdist" ["--list-sources=" ++ listSourcesFileGot] |
| 76 | + let listSourcesStrExpected = |
| 77 | +#if defined(mingw32_HOST_OS) |
| 78 | + ".\\MyLibrary.hs\n" |
| 79 | + ++ ".\\MyLibModule.hs\n" |
| 80 | + ++ ".\\Dummy.hs\n" |
| 81 | + ++ ".\\MyExeModule.hs\n" |
| 82 | + ++ ".\\Dummy.hs\n" |
| 83 | + ++ ".\\MyTestModule.hs\n" |
| 84 | + ++ ".\\Dummy.hs\n" |
| 85 | + ++ ".\\MyBenchModule.hs\n" |
| 86 | + ++ ".\\my.cabal\n" |
| 87 | +#else |
| 88 | + "./MyLibrary.hs\n" |
| 89 | + ++ "./MyLibModule.hs\n" |
| 90 | + ++ "./Dummy.hs\n" |
| 91 | + ++ "./MyExeModule.hs\n" |
| 92 | + ++ "./Dummy.hs\n" |
| 93 | + ++ "./MyTestModule.hs\n" |
| 94 | + ++ "./Dummy.hs\n" |
| 95 | + ++ "./MyBenchModule.hs\n" |
| 96 | + ++ "./my.cabal\n" |
| 97 | +#endif |
| 98 | + listSourcesStrGot <- liftIO $ readFile listSourcesFileGot |
| 99 | + assertEqual "sdist --list-sources does not match the expected files" |
| 100 | + listSourcesStrExpected |
| 101 | + listSourcesStrGot |
| 102 | + |
| 103 | + return () |
0 commit comments