diff --git a/.gitignore b/.gitignore index c80ceb3..9f3013b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ stack.yaml.lock agent_* agent.* version +hie.yaml \ No newline at end of file diff --git a/README.md b/README.md index 0d53c41..6617d98 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,15 @@ stack exec -- yesod devel As your code changes, your site will be automatically recompiled and redeployed to localhost. +### Development tools + +`ghcid "-c=stack ghci --test"` + +- Clone [HIE](https://github.com/haskell/haskell-ide-engine) +- Checkout latest reslease ie. `git checkout tags/1.3` +- Follow github instructions to install for specific GHC version ie. `stack ./install.hs hie` +- Install VSCode Haskell Language Server Extension + ## Tests ``` @@ -36,6 +45,13 @@ stack test --flag start9-companion-server:library-only --flag start9-companion-s (Because `yesod devel` passes the `library-only` and `dev` flags, matching those flags means you don't need to recompile between tests and development, and it disables optimization to speed up your test compile times). +### Tests with HIE Setup +- install hspec-discover globally `cabal install hspec-discover` (requires cabal installation) +- Current [issue](https://github.com/haskell/haskell-ide-engine/issues/1564) open for error pertaining to obtaining flags for test files + - recommended to setup hie.yaml + - recommended to run `stack build --test --no-run-tests` *before* any test files are open and that test files compile without error + - helps to debug a specific file: `hie --debug test/Main.hs` + ## Documentation * Read the [Yesod Book](https://www.yesodweb.com/book) online for free @@ -51,4 +67,4 @@ stack test --flag start9-companion-server:library-only --flag start9-companion-s * Ask the [Yesod Google Group](https://groups.google.com/forum/#!forum/yesodweb) * There are several chatrooms you can ask for help: * For IRC, try Freenode#yesod and Freenode#haskell - * [Functional Programming Slack](https://fpchat-invite.herokuapp.com/), in the #haskell, #haskell-beginners, or #yesod channels. + * [Functional Programming Slack](https://fpchat-invite.herokuapp.com/), in the #haskell, #haskell-beginners, or #yesod channels. \ No newline at end of file diff --git a/config/compatability.json b/config/compatability.json deleted file mode 100644 index 379a014..0000000 --- a/config/compatability.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "0.1.0": "1.0.0", - "0.1.1": "1.0.0", - "0.1.2": "1.1.0", - "0.1.3": "1.1.0" -} \ No newline at end of file diff --git a/package.yaml b/package.yaml index 6af4e39..9f9fed6 100644 --- a/package.yaml +++ b/package.yaml @@ -1,40 +1,14 @@ -flags: - library-only: - manual: false - default: false - description: Build for use with "yesod devel" - dev: - manual: false - default: false - description: Turn on development settings, like auto-reload templates. -library: - source-dirs: src - when: - - then: - cpp-options: -DDEVELOPMENT - ghc-options: - - -Wall - - -fwarn-tabs - - -O0 - - -fdefer-typed-holes - else: - ghc-options: - - -Wall - - -fwarn-tabs - - -O2 - - -fdefer-typed-holes - condition: (flag(dev)) || (flag(library-only)) -tests: - start9-registry-test: - source-dirs: test - main: Spec.hs - ghc-options: - - -Wall - - -fdefer-typed-holes - dependencies: - - start9-registry - - hspec >=2.0.0 - - yesod-test +name: start9-registry +version: 0.0.0 + +default-extensions: +- NoImplicitPrelude +- GeneralizedNewtypeDeriving +- LambdaCase +- MultiWayIf +- NamedFieldPuns +- NumericUnderscores +- OverloadedStrings dependencies: - base >=4.9.1.0 && <5 @@ -88,27 +62,58 @@ dependencies: - yesod-static - yesod-persistent >= 1.6 && < 1.7 -default-extensions: -- NoImplicitPrelude -- GeneralizedNewtypeDeriving -- LambdaCase -- MultiWayIf -- NamedFieldPuns -- NumericUnderscores -- OverloadedStrings -name: start9-registry -version: 0.0.0 +library: + source-dirs: src + when: + - condition: (flag(dev)) || (flag(library-only)) + then: + cpp-options: -DDEVELOPMENT + ghc-options: + - -Wall + - -fwarn-tabs + - -O0 + - -fdefer-typed-holes + else: + ghc-options: + - -Wall + - -fwarn-tabs + - -O2 + - -fdefer-typed-holes + executables: start9-registry: source-dirs: app main: main.hs ghc-options: - - -threaded - - -rtsopts - - -with-rtsopts=-N - - -fdefer-typed-holes + - -threaded + - -rtsopts + - -with-rtsopts=-N + - -fdefer-typed-holes dependencies: - - start9-registry + - start9-registry when: - - buildable: false - condition: flag(library-only) + - condition: flag(library-only) + buildable: false + +tests: + start9-registry-test: + source-dirs: test + main: Main.hs + ghc-options: + - -Wall + - -fdefer-typed-holes + dependencies: + - start9-registry + - hspec + - yesod-test + - hedgehog + +flags: + library-only: + manual: false + default: false + description: Build for use with "yesod devel" + dev: + manual: false + default: false + description: Turn on development settings, like auto-reload templates. \ No newline at end of file diff --git a/src/Handler/Apps.hs b/src/Handler/Apps.hs index 7fe6e69..d622b9e 100644 --- a/src/Handler/Apps.hs +++ b/src/Handler/Apps.hs @@ -40,20 +40,17 @@ instance Show FileExtension where getAppsManifestR :: Handler TypedContent getAppsManifestR = do - AppSettings{..} <- appSettings <$> getYesod - let appResourceDir = (resourcesDir . appSettings <$> getYesod) "apps" "apps.yaml" + appResourceDir <- ( "apps" "apps.yaml") . resourcesDir . appSettings <$> getYesod respondSource typePlain $ CB.sourceFile appResourceDir .| awaitForever sendChunkBS getSysR :: Extension "" -> Handler TypedContent getSysR e = do - AppSettings{..} <- appSettings <$> getYesod - let sysResourceDir = resourcesDir "sys" + sysResourceDir <- ( "sys") . resourcesDir . appSettings <$> getYesod getApp sysResourceDir e getAppR :: Extension "s9pk" -> Handler TypedContent getAppR e = do - AppSettings{..} <- appSettings <$> getYesod - let appResourceDir = resourcesDir "apps" "apps.yaml" + appResourceDir <- ( "apps" "apps.yaml") . resourcesDir . appSettings <$> getYesod getApp appResourceDir e getApp :: KnownSymbol a => FilePath -> Extension a -> Handler TypedContent diff --git a/src/Handler/Version.hs b/src/Handler/Version.hs index a230b9d..7cb7a45 100644 --- a/src/Handler/Version.hs +++ b/src/Handler/Version.hs @@ -26,20 +26,20 @@ import System.FilePath (()) getVersionR :: Handler AppVersionRes getVersionR = do - AppSettings{..} <- appSettings <$> getYesod - pure . AppVersionRes registryVersion $ Nothing + rv <- AppVersionRes . registryVersion . appSettings <$> getYesod + pure . rv $ Nothing getVersionAppR :: Text -> Handler (Maybe AppVersionRes) getVersionAppR appId = do - AppSettings{..} <- appSettings <$> getYesod - getVersionWSpec (resourcesDir "apps") appExt + appsDir <- ( "apps") . resourcesDir . appSettings <$> getYesod + getVersionWSpec appsDir appExt where appExt = Extension (toS appId) :: Extension "s9pk" getVersionSysR :: Text -> Handler (Maybe AppVersionRes) getVersionSysR sysAppId = runMaybeT $ do - AppSettings{..} <- appSettings <$> getYesod - avr <- MaybeT $ getVersionWSpec (resourcesDir "sys") sysExt + sysDir <- ( "sys") . resourcesDir . appSettings <$> getYesod + avr <- MaybeT $ getVersionWSpec sysDir sysExt minComp <- lift $ case sysAppId of "agent" -> Just <$> meshCompanionCompatibility (appVersionVersion avr) _ -> pure Nothing @@ -58,7 +58,7 @@ getVersionWSpec rootDir ext = do pure $ liftA2 AppVersionRes av (pure Nothing) meshCompanionCompatibility :: AppVersion -> Handler AppVersion -meshCompanionCompatibility av = getsYesod appCompatibilityMap >>= \hm -> do +meshCompanionCompatibility av = getsYesod appCompatibilityMap >>= \hm -> case HM.lookup av hm of Nothing -> do $logError [i|MESH DEPLOYMENT "#{av}" HAS NO COMPATIBILITY ENTRY! FIX IMMEDIATELY|] diff --git a/stack.yaml b/stack.yaml index bd856aa..efd76a5 100644 --- a/stack.yaml +++ b/stack.yaml @@ -43,6 +43,7 @@ extra-deps: - protolude-0.2.4 - git: https://github.com/CaptJakk/jose-jwt.git commit: 63210e8d05543dac932ddfe5c212450beb88374c + - haskell-src-exts-1.21.1@sha256:11d18ec3f463185f81b7819376b532e3087f8192cffc629aac5c9eec88897b35,4541 # Override default flag values for local packages and extra-deps # flags: {} diff --git a/test/Handler/AppSpec.hs b/test/Handler/AppSpec.hs index 5092972..83ac4c7 100644 --- a/test/Handler/AppSpec.hs +++ b/test/Handler/AppSpec.hs @@ -6,15 +6,11 @@ import Startlude import TestImport spec :: Spec -spec = do - describe "GET /apps" $ do +spec = describe "GET /apps" $ withApp $ it "returns list of apps" $ do request $ do setMethod "GET" setUrl ("/apps" :: Text) - printBody - bodyContains "" - statusIs 200 - - - + bodyContains "bitcoind" + bodyContains "version: 0.18.1" + statusIs 200 \ No newline at end of file diff --git a/test/Main.hs b/test/Main.hs index 37c4d99..f3031d9 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -3,9 +3,11 @@ module Main where import Test.Hspec.Runner import qualified Spec import Test.Hspec.Formatters -import qualified Handler.AppSpec as A +import Startlude +import GHC.IO.Encoding + main :: IO () main = do - _ <- A.spec + setLocaleEncoding utf8 hspecWith defaultConfig { configFormatter = Just progress } Spec.spec diff --git a/test/Spec.hs b/test/Spec.hs index a824f8c..b7fb4ef 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1 +1 @@ -{-# OPTIONS_GHC -F -pgmF hspec-discover #-} +{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --module-name=Spec #-} \ No newline at end of file