From 06f47a7cb918db1b6ad82a704fadc07d40d9f806 Mon Sep 17 00:00:00 2001 From: Veronika Romashkina Date: Tue, 28 Jul 2020 09:07:05 +0100 Subject: [PATCH] [#484] Generated source files improvements (#492) --- CHANGELOG.md | 2 + summoner-cli/examples/cabal-full/app/Main.hs | 4 +- .../examples/cabal-full/benchmark/Main.hs | 4 +- .../examples/cabal-full/cabal-full.cabal | 3 +- .../examples/cabal-full/src/CabalFull.hs | 8 +-- summoner-cli/examples/cabal-full/test/Spec.hs | 4 +- .../examples/cabal-minimal/app/Main.hs | 2 +- .../examples/full-batteries/app/Main.hs | 4 +- .../examples/full-batteries/benchmark/Main.hs | 4 +- .../full-batteries/full-batteries.cabal | 3 +- .../full-batteries/src/FullBatteries.hs | 8 +-- .../examples/full-batteries/test/Spec.hs | 4 +- summoner-cli/examples/stack-full/app/Main.hs | 4 +- .../examples/stack-full/benchmark/Main.hs | 4 +- .../examples/stack-full/src/StackFull.hs | 8 +-- .../examples/stack-full/stack-full.cabal | 3 +- summoner-cli/examples/stack-full/test/Spec.hs | 4 +- summoner-cli/src/Summoner/Template/Cabal.hs | 9 ++- summoner-cli/src/Summoner/Template/Haskell.hs | 63 +++++++------------ 19 files changed, 67 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 780ee859..b9ecee7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ The changelog is available [on GitHub][2]. Add README link in the `.cabal` file's description field. * [#453](https://github.com/kowainik/summoner/issues/453): Drop support of `GHC-7.10` in the generated projects. +* [#484](https://github.com/kowainik/summoner/issues/484): + Improve generated files content. ## 2.0.1.1 — May 29, 2020 diff --git a/summoner-cli/examples/cabal-full/app/Main.hs b/summoner-cli/examples/cabal-full/app/Main.hs index cb69c944..db3e9ddd 100644 --- a/summoner-cli/examples/cabal-full/app/Main.hs +++ b/summoner-cli/examples/cabal-full/app/Main.hs @@ -1,7 +1,7 @@ module Main (main) where -import CabalFull (someFunc) +import CabalFull (projectName) main :: IO () -main = someFunc +main = putStrLn ("Executable for " ++ projectName) diff --git a/summoner-cli/examples/cabal-full/benchmark/Main.hs b/summoner-cli/examples/cabal-full/benchmark/Main.hs index f84a18d6..1d20c0db 100644 --- a/summoner-cli/examples/cabal-full/benchmark/Main.hs +++ b/summoner-cli/examples/cabal-full/benchmark/Main.hs @@ -1,7 +1,7 @@ module Main (main) where -import Gauge.Main +import CabalFull (projectName) main :: IO () -main = defaultMain [bench "const" (whnf const ())] +main = putStrLn ("Benchmarks for " ++ projectName) diff --git a/summoner-cli/examples/cabal-full/cabal-full.cabal b/summoner-cli/examples/cabal-full/cabal-full.cabal index 21f25813..317911ab 100644 --- a/summoner-cli/examples/cabal-full/cabal-full.cabal +++ b/summoner-cli/examples/cabal-full/cabal-full.cabal @@ -81,8 +81,7 @@ benchmark cabal-full-benchmark type: exitcode-stdio-1.0 hs-source-dirs: benchmark main-is: Main.hs - build-depends: gauge - , cabal-full + build-depends: cabal-full ghc-options: -threaded -rtsopts -with-rtsopts=-N diff --git a/summoner-cli/examples/cabal-full/src/CabalFull.hs b/summoner-cli/examples/cabal-full/src/CabalFull.hs index 873050a9..79208361 100644 --- a/summoner-cli/examples/cabal-full/src/CabalFull.hs +++ b/summoner-cli/examples/cabal-full/src/CabalFull.hs @@ -7,9 +7,9 @@ Cabal-only example with all integrations -} module CabalFull - ( someFunc - ) where + ( projectName + ) where -someFunc :: IO () -someFunc = putStrLn ("someFunc" :: String) +projectName :: String +projectName = "cabal-full" diff --git a/summoner-cli/examples/cabal-full/test/Spec.hs b/summoner-cli/examples/cabal-full/test/Spec.hs index 1a448469..6971ce62 100644 --- a/summoner-cli/examples/cabal-full/test/Spec.hs +++ b/summoner-cli/examples/cabal-full/test/Spec.hs @@ -1,5 +1,7 @@ module Main (main) where +import CabalFull (projectName) + main :: IO () -main = putStrLn ("Test suite is not implemented" :: String) +main = putStrLn ("Tests for " ++ projectName) diff --git a/summoner-cli/examples/cabal-minimal/app/Main.hs b/summoner-cli/examples/cabal-minimal/app/Main.hs index aa7e0125..f7187ed0 100644 --- a/summoner-cli/examples/cabal-minimal/app/Main.hs +++ b/summoner-cli/examples/cabal-minimal/app/Main.hs @@ -2,4 +2,4 @@ module Main (main) where main :: IO () -main = putStrLn ("Hello, world!" :: String) +main = putStrLn ("Executable not implemented" :: String) diff --git a/summoner-cli/examples/full-batteries/app/Main.hs b/summoner-cli/examples/full-batteries/app/Main.hs index 8173f8f4..2bfa9209 100644 --- a/summoner-cli/examples/full-batteries/app/Main.hs +++ b/summoner-cli/examples/full-batteries/app/Main.hs @@ -1,7 +1,7 @@ module Main (main) where -import FullBatteries (someFunc) +import FullBatteries (projectName) main :: IO () -main = someFunc +main = putStrLn ("Executable for " ++ projectName) diff --git a/summoner-cli/examples/full-batteries/benchmark/Main.hs b/summoner-cli/examples/full-batteries/benchmark/Main.hs index f84a18d6..d3bd763c 100644 --- a/summoner-cli/examples/full-batteries/benchmark/Main.hs +++ b/summoner-cli/examples/full-batteries/benchmark/Main.hs @@ -1,7 +1,7 @@ module Main (main) where -import Gauge.Main +import FullBatteries (projectName) main :: IO () -main = defaultMain [bench "const" (whnf const ())] +main = putStrLn ("Benchmarks for " ++ projectName) diff --git a/summoner-cli/examples/full-batteries/full-batteries.cabal b/summoner-cli/examples/full-batteries/full-batteries.cabal index da6bf2a2..2be6bf3e 100644 --- a/summoner-cli/examples/full-batteries/full-batteries.cabal +++ b/summoner-cli/examples/full-batteries/full-batteries.cabal @@ -71,8 +71,7 @@ benchmark full-batteries-benchmark type: exitcode-stdio-1.0 hs-source-dirs: benchmark main-is: Main.hs - build-depends: gauge - , full-batteries + build-depends: full-batteries ghc-options: -threaded -rtsopts -with-rtsopts=-N diff --git a/summoner-cli/examples/full-batteries/src/FullBatteries.hs b/summoner-cli/examples/full-batteries/src/FullBatteries.hs index c6205f35..10291168 100644 --- a/summoner-cli/examples/full-batteries/src/FullBatteries.hs +++ b/summoner-cli/examples/full-batteries/src/FullBatteries.hs @@ -7,9 +7,9 @@ Full-featured test project -} module FullBatteries - ( someFunc - ) where + ( projectName + ) where -someFunc :: IO () -someFunc = putStrLn ("someFunc" :: String) +projectName :: String +projectName = "full-batteries" diff --git a/summoner-cli/examples/full-batteries/test/Spec.hs b/summoner-cli/examples/full-batteries/test/Spec.hs index 1a448469..b8ec8301 100644 --- a/summoner-cli/examples/full-batteries/test/Spec.hs +++ b/summoner-cli/examples/full-batteries/test/Spec.hs @@ -1,5 +1,7 @@ module Main (main) where +import FullBatteries (projectName) + main :: IO () -main = putStrLn ("Test suite is not implemented" :: String) +main = putStrLn ("Tests for " ++ projectName) diff --git a/summoner-cli/examples/stack-full/app/Main.hs b/summoner-cli/examples/stack-full/app/Main.hs index fff8c67a..3dca2ab1 100644 --- a/summoner-cli/examples/stack-full/app/Main.hs +++ b/summoner-cli/examples/stack-full/app/Main.hs @@ -1,7 +1,7 @@ module Main (main) where -import StackFull (someFunc) +import StackFull (projectName) main :: IO () -main = someFunc +main = putStrLn ("Executable for " ++ projectName) diff --git a/summoner-cli/examples/stack-full/benchmark/Main.hs b/summoner-cli/examples/stack-full/benchmark/Main.hs index f84a18d6..c9c8ff5d 100644 --- a/summoner-cli/examples/stack-full/benchmark/Main.hs +++ b/summoner-cli/examples/stack-full/benchmark/Main.hs @@ -1,7 +1,7 @@ module Main (main) where -import Gauge.Main +import StackFull (projectName) main :: IO () -main = defaultMain [bench "const" (whnf const ())] +main = putStrLn ("Benchmarks for " ++ projectName) diff --git a/summoner-cli/examples/stack-full/src/StackFull.hs b/summoner-cli/examples/stack-full/src/StackFull.hs index 339804b2..001d7a2f 100644 --- a/summoner-cli/examples/stack-full/src/StackFull.hs +++ b/summoner-cli/examples/stack-full/src/StackFull.hs @@ -7,9 +7,9 @@ Stack-only example with all integrations -} module StackFull - ( someFunc - ) where + ( projectName + ) where -someFunc :: IO () -someFunc = putStrLn ("someFunc" :: String) +projectName :: String +projectName = "stack-full" diff --git a/summoner-cli/examples/stack-full/stack-full.cabal b/summoner-cli/examples/stack-full/stack-full.cabal index c5ae44de..6868824f 100644 --- a/summoner-cli/examples/stack-full/stack-full.cabal +++ b/summoner-cli/examples/stack-full/stack-full.cabal @@ -81,8 +81,7 @@ benchmark stack-full-benchmark type: exitcode-stdio-1.0 hs-source-dirs: benchmark main-is: Main.hs - build-depends: gauge - , stack-full + build-depends: stack-full ghc-options: -threaded -rtsopts -with-rtsopts=-N diff --git a/summoner-cli/examples/stack-full/test/Spec.hs b/summoner-cli/examples/stack-full/test/Spec.hs index 1a448469..7e722471 100644 --- a/summoner-cli/examples/stack-full/test/Spec.hs +++ b/summoner-cli/examples/stack-full/test/Spec.hs @@ -1,5 +1,7 @@ module Main (main) where +import StackFull (projectName) + main :: IO () -main = putStrLn ("Test suite is not implemented" :: String) +main = putStrLn ("Tests for " ++ projectName) diff --git a/summoner-cli/src/Summoner/Template/Cabal.hs b/summoner-cli/src/Summoner/Template/Cabal.hs index 9c88a77d..c1416cae 100644 --- a/summoner-cli/src/Summoner/Template/Cabal.hs +++ b/summoner-cli/src/Summoner/Template/Cabal.hs @@ -38,7 +38,7 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte , memptyIfFalse settingsIsLib libraryStanza , memptyIfFalse settingsIsExe executableStanza , memptyIfFalse settingsTest testSuiteStanza - , memptyIfFalse settingsBench $ benchmarkStanza $ memptyIfFalse settingsIsLib $ ", " <> settingsRepo + , memptyIfFalse settingsBench benchmarkStanza ] cabalHeader :: Text @@ -175,17 +175,16 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte <> buildDepends <> rtsOptions - benchmarkStanza :: Text -> Text - benchmarkStanza commaRepo = unlines $ + benchmarkStanza :: Text + benchmarkStanza = unlines $ [ "" , "benchmark " <> settingsRepo <> "-benchmark" , " import: common-options" , " type: exitcode-stdio-1.0" , " hs-source-dirs: benchmark" , " main-is: Main.hs" - , " build-depends: gauge" - , " " <> commaRepo ] + <> buildDepends <> rtsOptions -- | @build-depends@ for the repo, only if the library is on. diff --git a/summoner-cli/src/Summoner/Template/Haskell.hs b/summoner-cli/src/Summoner/Template/Haskell.hs index cc497c59..dc0efb73 100644 --- a/summoner-cli/src/Summoner/Template/Haskell.hs +++ b/summoner-cli/src/Summoner/Template/Haskell.hs @@ -36,13 +36,13 @@ haskellFiles Settings{..} = concat , settingsDescription , "-}" , "" - , "module " <>libModuleName - , " ( someFunc" - , " ) where" + , "module " <> libModuleName + , " ( projectName" + , " ) where" , "" , "" - , "someFunc :: IO ()" - , "someFunc = putStrLn (" <> quote "someFunc" <> " :: String)" + , "projectName :: String" + , "projectName = " <> quote settingsRepo ] libModuleName :: Text @@ -52,44 +52,29 @@ haskellFiles Settings{..} = concat licenseName = show settingsLicenseName exeFile :: TreeFs - exeFile = File "Main.hs" $ if settingsIsLib then createExe else createOnlyExe - - createOnlyExe :: Text - createOnlyExe = unlines - [ "module Main (main) where" - , "" - , "" - , "main :: IO ()" - , "main = putStrLn (" <> quote "Hello, world!" <> " :: String)" - ] - - createExe :: Text - createExe = unlines - [ "module Main (main) where" - , "" - , "import " <> libModuleName <> " (someFunc)" - , "" - , "" - , "main :: IO ()" - , "main = someFunc" - ] + exeFile = File "Main.hs" $ stanza "Executable" testFile :: TreeFs - testFile = File "Spec.hs" $ unlines - [ "module Main (main) where" - , "" - , "" - , "main :: IO ()" - , "main = putStrLn (" <> quote "Test suite is not implemented" <> " :: String)" - ] + testFile = File "Spec.hs" $ stanza "Tests" benchmarkFile :: TreeFs - benchmarkFile = File "Main.hs" $ unlines - [ "module Main (main) where" - , "" - , "import Gauge.Main" - , "" + benchmarkFile = File "Main.hs" $ stanza "Benchmarks" + + stanza :: Text -> Text + stanza st = unlines $ + "module Main (main) where" + : memptyIfFalse settingsIsLib + [ "" + , "import " <> libModuleName <> " (projectName)" + ] + <> + [ "" , "" , "main :: IO ()" - , "main = defaultMain [bench " <> quote "const" <> " (whnf const ())]" + , mainContent ] + where + mainContent :: Text + mainContent = if settingsIsLib + then "main = putStrLn (" <> quote (st <> " for ") <> " ++ projectName)" + else "main = putStrLn (" <> quote (st <> " not implemented") <> " :: String)"