Skip to content

Commit

Permalink
[#519] Implement a golden generator executable (#549)
Browse files Browse the repository at this point in the history
* [#519] Implement golden generator

Resolves #519

* [#519] Update year in examples using gg

Resolves #519
  • Loading branch information
chshersh authored Sep 18, 2021
1 parent 3f66f31 commit 19fb050
Show file tree
Hide file tree
Showing 19 changed files with 347 additions and 252 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,14 @@ stack exec summon -- SOME_COMMAND
stack exec summon-tui -- SOME_COMMAND
```

### Generate golden tests

To regenerate the content of all projects on disk, use the following command:

```shell
cabal run gg
```

## Acknowledgments

[[Back to the Table of Contents]](#structure)
Expand Down
2 changes: 1 addition & 1 deletion summoner-cli/examples/cabal-full/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2020, Kowainik
Copyright (c) 2021, Kowainik
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion summoner-cli/examples/cabal-full/cabal-full.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license: BSD-3-Clause
license-file: LICENSE
author: Kowainik
maintainer: Kowainik <xrom.xkov@gmail.com>
copyright: 2020 Kowainik
copyright: 2021 Kowainik
category: Testing
build-type: Simple
extra-doc-files: README.md
Expand Down
2 changes: 1 addition & 1 deletion summoner-cli/examples/cabal-full/src/CabalFull.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{- |
Copyright: (c) 2020 Kowainik
Copyright: (c) 2021 Kowainik
SPDX-License-Identifier: BSD-3-Clause
Maintainer: Kowainik <xrom.xkov@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion summoner-cli/examples/cabal-minimal/cabal-minimal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description:
license: NONE
author: Kowainik
maintainer: Kowainik <xrom.xkov@gmail.com>
copyright: 2020 Kowainik
copyright: 2021 Kowainik
build-type: Simple
extra-doc-files: README.md
CHANGELOG.md
Expand Down
8 changes: 8 additions & 0 deletions summoner-cli/examples/cabalScript.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env cabal
{- cabal:
build-depends:
, base ^>= 4.14.3.0
-}

main :: IO ()
main = putStrLn "Hello, World!"
2 changes: 1 addition & 1 deletion summoner-cli/examples/full-batteries/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Kowainik
Copyright (c) 2021 Kowainik

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion summoner-cli/examples/full-batteries/full-batteries.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license: MIT
license-file: LICENSE
author: Kowainik
maintainer: Kowainik <xrom.xkov@gmail.com>
copyright: 2020 Kowainik
copyright: 2021 Kowainik
category: Testing
build-type: Simple
extra-doc-files: README.md
Expand Down
2 changes: 1 addition & 1 deletion summoner-cli/examples/full-batteries/src/FullBatteries.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{- |
Copyright: (c) 2020 Kowainik
Copyright: (c) 2021 Kowainik
SPDX-License-Identifier: MIT
Maintainer: Kowainik <xrom.xkov@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion summoner-cli/examples/stack-full/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2020, Kowainik
Copyright (c) 2021, Kowainik
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion summoner-cli/examples/stack-full/src/StackFull.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{- |
Copyright: (c) 2020 Kowainik
Copyright: (c) 2021 Kowainik
SPDX-License-Identifier: BSD-3-Clause
Maintainer: Kowainik <xrom.xkov@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion summoner-cli/examples/stack-full/stack-full.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license: BSD-3-Clause
license-file: LICENSE
author: Kowainik
maintainer: Kowainik <xrom.xkov@gmail.com>
copyright: 2020 Kowainik
copyright: 2021 Kowainik
category: Testing
build-type: Simple
extra-doc-files: README.md
Expand Down
9 changes: 9 additions & 0 deletions summoner-cli/examples/stackScript.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env stack
{- stack
--resolver lts-18.10
script
--package base
-}

main :: IO ()
main = putStrLn "Hello, World!"
9 changes: 9 additions & 0 deletions summoner-cli/golden/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Main (main) where

import Summoner.Golden (generateProjects, generateScripts, generateTomlConfig)

main :: IO ()
main = do
generateScripts
generateTomlConfig
generateProjects
270 changes: 270 additions & 0 deletions summoner-cli/src/Summoner/Golden.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
{- |
Module : Summoner.Golden
Copyright : (c) 2021 Kowainik
SPDX-License-Identifier : MPL-2.0
Maintainer : Kowainik <xrom.xkov@gmail.com>
Stability : Stable
Portability : Portable
This module contains test data for golden examples.
It is used for both purposes:
* To test new implementation against the old one
* In the @gg@ executable to generate new golden examples boilerplate
-}

module Summoner.Golden
( -- * Executable scripts
generateScripts
-- * Default TOML config
, generateTomlConfig
-- * Projects
-- ** Generator
, generateProjects
-- ** Project settings
, cabalMinimal
, cabalFull
, stackFull
, fullBatteries
) where

import Colourista (infoMessage)
import Colourista.Short (b)
import System.Directory (withCurrentDirectory)

import Summoner.CustomPrelude (CustomPrelude (..))
import Summoner.Default (defaultConfigFileContent, defaultGHC)
import Summoner.GhcVer (GhcVer (..))
import Summoner.License (License (..), LicenseName (..))
import Summoner.Settings (Settings (..), Tool (..))
import Summoner.Template (createProjectTemplate)
import Summoner.Template.Script (scriptFile)
import Summoner.Text (quote)
import Summoner.Tree (TreeFs (..), traverseTree)


generateScripts :: IO ()
generateScripts = do
generateCabalScript
generateStackScript

generateCabalScript :: IO ()
generateCabalScript = do
let path = "summoner-cli/examples/cabalScript.hs"
infoMessage $ "Writing Cabal script to: " <> toText path
writeFileText path $ scriptFile defaultGHC Cabal

generateStackScript :: IO ()
generateStackScript = do
let path = "summoner-cli/examples/stackScript.hs"
infoMessage $ "Writing Stack script to: " <> toText path
writeFileText path $ scriptFile defaultGHC Stack

generateTomlConfig :: IO ()
generateTomlConfig = do
let path = "summoner-cli/examples/summoner-default.toml"
infoMessage $ "Writing default TOML config to: " <> toText path
writeFileText path defaultConfigFileContent

----------------------------------------------------------------------------
-- Entire projects
----------------------------------------------------------------------------

generateProjects :: IO ()
generateProjects = withCurrentDirectory "summoner-cli/examples" $ do
mkProject cabalMinimal
mkProject cabalFull
mkProject stackFull
mkProject fullBatteries

mkProject :: Settings -> IO ()
mkProject settings = do
infoMessage $ "Creating project: " <> b (settingsRepo settings)
traverseTree $ createProjectTemplate settings

cabalMinimal :: Settings
cabalMinimal = Settings
{ settingsRepo = "cabal-minimal"
, settingsOwner = "kowainik"
, settingsDescription = "Minimal cabal-only test project"
, settingsFullName = "Kowainik"
, settingsEmail = "xrom.xkov@gmail.com"
, settingsYear = "2021"
, settingsCategories = ""
, settingsLicenseName = NONE
, settingsLicenseText = ""
, settingsGitHub = False
, settingsGhActions = False
, settingsPrivate = False
, settingsTravis = False
, settingsAppVeyor = False
, settingsIsLib = False
, settingsIsExe = True
, settingsTest = False
, settingsBench = False
, settingsTestedVersions = [defaultGHC]
, settingsPrelude = Nothing
, settingsExtensions = []
, settingsGhcOptions = []
, settingsGitignore = []
, settingsCabal = True
, settingsStack = False
, settingsNoUpload = True
, settingsFiles = mempty
}

cabalFull :: Settings
cabalFull = Settings
{ settingsRepo = "cabal-full"
, settingsOwner = "kowainik"
, settingsDescription = "Cabal-only example with all integrations"
, settingsFullName = "Kowainik"
, settingsEmail = "xrom.xkov@gmail.com"
, settingsYear = "2021"
, settingsCategories = "Testing"
, settingsLicenseName = BSD3
, settingsLicenseText = bsd3License
, settingsGitHub = True
, settingsGhActions = True
, settingsPrivate = False
, settingsTravis = True
, settingsAppVeyor = True
, settingsIsLib = True
, settingsIsExe = True
, settingsTest = True
, settingsBench = True
, settingsTestedVersions = [Ghc844 .. defaultGHC]
, settingsPrelude = Just $ CustomPrelude "relude" "Relude"
, settingsExtensions = ["DeriveGeneric", "TypeApplications"]
, settingsGitignore = []
, settingsGhcOptions = []
, settingsCabal = True
, settingsStack = False
, settingsNoUpload = False
, settingsFiles = []
}

stackFull :: Settings
stackFull = Settings
{ settingsRepo = "stack-full"
, settingsOwner = "kowainik"
, settingsDescription = "Stack-only example with all integrations"
, settingsFullName = "Kowainik"
, settingsEmail = "xrom.xkov@gmail.com"
, settingsYear = "2021"
, settingsCategories = "Testing"
, settingsLicenseName = BSD3
, settingsLicenseText = bsd3License
, settingsGitHub = True
, settingsGhActions = True
, settingsPrivate = False
, settingsTravis = True
, settingsAppVeyor = True
, settingsIsLib = True
, settingsIsExe = True
, settingsTest = True
, settingsBench = True
, settingsTestedVersions = [Ghc844 .. defaultGHC]
, settingsPrelude = Just $ CustomPrelude "relude" "Relude"
, settingsExtensions = ["DeriveGeneric", "TypeApplications"]
, settingsGitignore = []
, settingsGhcOptions = []
, settingsCabal = False
, settingsStack = True
, settingsNoUpload = False
, settingsFiles = []
}

fullBatteries :: Settings
fullBatteries = Settings
{ settingsRepo = "full-batteries"
, settingsOwner = "kowainik"
, settingsDescription = "Full-featured test project"
, settingsFullName = "Kowainik"
, settingsEmail = "xrom.xkov@gmail.com"
, settingsYear = "2021"
, settingsCategories = "Testing"
, settingsLicenseName = MIT
, settingsLicenseText = mitLicense
, settingsGitHub = True
, settingsGhActions = True
, settingsPrivate = True
, settingsTravis = True
, settingsAppVeyor = True
, settingsIsLib = True
, settingsIsExe = True
, settingsTest = True
, settingsBench = True
, settingsTestedVersions = [minBound .. defaultGHC]
, settingsPrelude = Just $ CustomPrelude "relude" "Relude"
, settingsExtensions = ["ConstraintKinds", "LambdaCase", "OverloadedStrings"]
, settingsGitignore = [".secret"]
, settingsGhcOptions = ["-Wcompat", "-Widentities"]
, settingsCabal = True
, settingsStack = True
, settingsNoUpload = True
, settingsFiles =
[ File "extra.txt" "See full content of the file [here](@github)\n"
, Dir ".github" [File "CODEOWNERS" "* @chshersh @vrom911\n"]
, File ".stylish-haskell.yaml" "This is stylish-haskell.yaml\n"
, File "CONTRIBUTING.md" "This is contributing guide\n"
]
}
where
mitLicense :: License
mitLicense = License $ unlines
[ "MIT License"
, ""
, "Copyright (c) 2021 Kowainik"
, ""
, "Permission is hereby granted, free of charge, to any person obtaining a copy"
, "of this software and associated documentation files (the " <> quote "Software" <> "), to deal"
, "in the Software without restriction, including without limitation the rights"
, "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell"
, "copies of the Software, and to permit persons to whom the Software is"
, "furnished to do so, subject to the following conditions:"
, ""
, "The above copyright notice and this permission notice shall be included in all"
, "copies or substantial portions of the Software."
, ""
, "THE SOFTWARE IS PROVIDED " <> quote "AS IS" <> ", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR"
, "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,"
, "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE"
, "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER"
, "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,"
, "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE"
, "SOFTWARE."
]

bsd3License :: License
bsd3License = License $ unlines
[ "BSD 3-Clause License"
, ""
, "Copyright (c) 2021, Kowainik"
, "All rights reserved."
, ""
, "Redistribution and use in source and binary forms, with or without"
, "modification, are permitted provided that the following conditions are met:"
, ""
, "1. Redistributions of source code must retain the above copyright notice, this"
, " list of conditions and the following disclaimer."
, ""
, "2. Redistributions in binary form must reproduce the above copyright notice,"
, " this list of conditions and the following disclaimer in the documentation"
, " and/or other materials provided with the distribution."
, ""
, "3. Neither the name of the copyright holder nor the names of its"
, " contributors may be used to endorse or promote products derived from"
, " this software without specific prior written permission."
, ""
, "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " <> quote "AS IS"
, "AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE"
, "IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE"
, "DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE"
, "FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL"
, "DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR"
, "SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER"
, "CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,"
, "OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE"
, "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
]
Loading

0 comments on commit 19fb050

Please sign in to comment.