packages feed

staversion 0.2.1.4 → 0.2.2.0

raw patch · 15 files changed

+389/−25 lines, 15 filesdep +heredocdep +processdep ~aesondep ~megaparsec

Dependencies added: heredoc, process

Dependency ranges changed: aeson, megaparsec

Files

ChangeLog.md view
@@ -1,5 +1,14 @@ # Revision history for staversion +## 0.2.2.0  -- 2018-07-01++* Add `--stack` and `--stack-default` (`-S`) options (#4).+* Now `--stack-default` option is implied if there is no package source specified (#4).+* Support `aeson-1.4` and `megaparsec-6.5.0`.+* [Bug fix] `-H` option: It now proceed if hackage returns 404+  error. That is probably because the user specified a package not on+  hackage, so it's not fatal.+ ## 0.2.1.4  -- 2018-03-26  * Support `base-4.11.0.0`.
README.md view
@@ -32,6 +32,15 @@  staversion first reads build plan YAML files that are stored locally in your computer, then it tries to fetch them over network. +## Package version of your current stack project++If you omit `--resolver` (`-r`) option (or explicitly specify `--stack-default` (`-S`) option), staversion reads `stack.yaml` of your current project, and searches for package versions in the resolver specified in the `stack.yaml`.++    $ staversion conduit+    ------ default stack resolver (lts-10.8)+    conduit ==1.2.13.1++ ## Package version in Hackage  You can also look up the latest version numbers hosted on hackage with `--hackage` (`-H`) option.
src/Staversion/Internal/BuildPlan.hs view
@@ -12,6 +12,7 @@          buildPlanSource,          BuildPlanManager,          newBuildPlanManager,+         manStackCommand,          loadBuildPlan,          -- * Low-level APIs          BuildPlanMap,@@ -61,6 +62,7 @@     PartialResolver(..), ExactResolver(..),     fetchBuildPlanYAML   )+import qualified Staversion.Internal.BuildPlan.StackYaml as StackYaml import Staversion.Internal.BuildPlan.Version (unVersionJSON) import Staversion.Internal.Version (Version) @@ -103,12 +105,19 @@ -- | Stateful manager for 'BuildPlan's. data BuildPlanManager =   BuildPlanManager { manBuildPlanDir :: FilePath,-                     -- ^ path to the directory where build plans are hold.+                     -- ^ (accessor function) path to the directory+                     -- where build plans are hold.                      manHttpManager :: Maybe Manager,-                     -- ^ low-level HTTP connection manager. If 'Nothing', it won't fetch build plans over the network.+                     -- ^ (accessor function) low-level HTTP+                     -- connection manager. If 'Nothing', it won't+                     -- fetch build plans over the network.                      manDisambiguator :: IORef (Maybe Disambiguator),-                     -- ^ cache of resolver disambigutor-                     manLogger :: Logger+                     -- ^ (accessor function) cache of resolver+                     -- disambigutor+                     manLogger :: Logger,+                     manStackCommand :: String+                     -- ^ (accessor function) Shell command for the+                     -- @stack@ tool.                    }  newBuildPlanManager :: FilePath -- ^ path to the directory where build plans are hold.@@ -123,7 +132,8 @@   return $ BuildPlanManager { manBuildPlanDir = plan_dir,                               manHttpManager = mman,                               manDisambiguator = disam,-                              manLogger = logger+                              manLogger = logger,+                              manStackCommand = "stack"                             }  type LoadM = ExceptT ErrorMsg IO@@ -167,9 +177,24 @@     build_plan_map <- (mconcat . zipWith registeredVersionToBuildPlanMap names) <$> mapM (doFetch http_man) names     return $ BuildPlan { buildPlanMap = build_plan_map, buildPlanSource = SourceHackage }   logDebug' msg = liftIO $ logDebug (manLogger man) msg+  logWarn' msg = liftIO $ logWarn (manLogger man) msg   doFetch http_man name = do     logDebug' ("Ask hackage for the latest version of " ++ unpack name)-    ExceptT $ fetchPreferredVersions http_man name+    reg_ver <- ExceptT $ fetchPreferredVersions http_man name+    case latestVersion reg_ver of+     Nothing -> logWarn' ("Cannot find package version of " ++ unpack name ++ ". Maybe it's not on hackage.")+     Just _ -> return ()+    return reg_ver+loadBuildPlan man names (SourceStackYaml file) = do+  eresolver <- StackYaml.readResolver file+  case eresolver of+   Left err -> return $ Left err+   Right resolver -> loadBuildPlan man names (SourceStackage resolver)+loadBuildPlan man names SourceStackDefault = do+  efile <- StackYaml.configLocation (manLogger man) (manStackCommand man)+  case efile of+   Left err -> return $ Left err+   Right f -> loadBuildPlan man names (SourceStackYaml f)  loadBuildPlan_stackageLocalFile :: BuildPlanManager -> Resolver -> LoadM BuildPlan loadBuildPlan_stackageLocalFile man resolver = ExceptT $ catchJust handleIOError doLoad (return . Left) where
src/Staversion/Internal/BuildPlan/Hackage.hs view
@@ -22,7 +22,7 @@  import Staversion.Internal.BuildPlan.Version (unVersionJSON) import Staversion.Internal.Query (ErrorMsg, PackageName)-import Staversion.Internal.HTTP (Manager, fetchURL, OurHttpException)+import Staversion.Internal.HTTP (Manager, fetchURL, OurHttpException, asStatusFailureException) import Staversion.Internal.Version (Version)  data RegisteredVersions = RegisteredVersions { regPreferredVersions :: [Version]@@ -47,5 +47,11 @@ fetchPreferredVersions man text_name = Exception.handle handler $ parsePreferredVersionsJSON <$> fetchURL man url where   name = unpack text_name   url = "http://hackage.haskell.org/package/" ++ name ++ "/preferred.json"-  handler :: OurHttpException -> IO (Either ErrorMsg a)-  handler e = return $ Left ("HTTP error while fetching versions of " ++ name ++ " in hackage: " ++ show e)+  handler :: OurHttpException -> IO (Either ErrorMsg RegisteredVersions)+  handler e = case asStatusFailureException e of+    Nothing -> return $ Left err+    Just code -> case code of+      404 -> return $ Right $ RegisteredVersions []+      _ -> return $ Left err+    where+      err = "HTTP error while fetching versions of " ++ name ++ " in hackage: " ++ show e
+ src/Staversion/Internal/BuildPlan/StackYaml.hs view
@@ -0,0 +1,99 @@+-- |+-- Module: Staversion.Internal.BuildPlan.StackYaml+-- Description: Get PackageSource from stack.yaml+-- Maintainer: Toshio Ito <debug.ito@gmail.com>+--+-- __This is an internal module. End-users should not use it.__+--+-- This module is meant to be exposed only to+-- "Staversion.Internal.BuildPlan" and test modules.+module Staversion.Internal.BuildPlan.StackYaml+       ( readResolver,+         configLocation,+         configLocationFromText+       ) where++import Control.Applicative (empty, many, some)+import Control.Monad (void, when)+import Data.Char (isSpace)+import Data.Monoid ((<>))+import Data.Yaml (FromJSON(..), Value(..), (.:), decodeEither)+import Data.Text (Text, pack)+import qualified Data.Text as T+import qualified Data.ByteString as BS+import System.Exit (ExitCode(ExitFailure))+import System.Process+  ( shell, readCreateProcessWithExitCode+  )++import Staversion.Internal.Log (Logger, logWarn, logDebug)+import Staversion.Internal.Query (Resolver, ErrorMsg)+import Staversion.Internal.Megaparsec (Parser, runParser, satisfy, space)++newtype Resolver' = Resolver' { unResolver' :: Resolver }+                  deriving (Show,Eq,Ord)++instance FromJSON Resolver' where+  parseJSON (Object o) = fmap Resolver' $ o .: "resolver"+  parseJSON _ = empty++-- | Read the @resolver@ field in stack.yaml.+readResolver :: FilePath -- ^ path to stack.yaml+             -> IO (Either ErrorMsg Resolver)+readResolver file = fmap (fmap unResolver' . decodeEither) $ BS.readFile file++-- | Get the path to stack.yaml that @stack@ uses as the current+-- config.+configLocation :: Logger+               -> String -- ^ shell command for @stack@+               -> IO (Either ErrorMsg FilePath)+configLocation logger command = do+  pout <- getProcessOutput logger command+  case configLocationFromText =<< pout of+   e@(Right path) -> logDebug logger ("Project stack config: " <> path) >> return e+   e -> return e++getProcessOutput :: Logger -> String -> IO (Either ErrorMsg Text)+getProcessOutput logger command = handleResult =<< readCreateProcessWithExitCode cmd ""+  where+    cmd_str = command <> " path"+    cmd = shell cmd_str+    warnErr err = when (length err /= 0) $ logWarn logger err+    handleResult (code, out, err) = do+      case code of+       ExitFailure c -> do+         let code_err = "'" <> cmd_str <> "' returns non-zero exit code: " <> show c <> "."+             hint = "It requires the 'stack' tool. Maybe you have to specify the command by --stack-command option."+         logWarn logger code_err+         warnErr err+         return $ Left (code_err <> "\n" <> hint)+       _ -> do+         warnErr err+         return $ Right $ pack out++configLocationFromText :: Text -> Either ErrorMsg FilePath+configLocationFromText input = toEither $ findField =<< T.lines input+  where+    fieldName = "config-location"+    findField :: Text -> [FilePath]+    findField line = do+      (fname, fvalue) <- maybe [] return $ parseField line+      if fname == fieldName+        then return $ T.unpack fvalue+        else []+    toEither :: [FilePath] -> Either ErrorMsg FilePath+    toEither [] = Left ("Cannot find '" <> T.unpack fieldName <> "' field in stack path")+    toEither (r:_) = Right r+    parseField :: Text -> Maybe (Text, Text)+    parseField = either (const Nothing) return . runParser parser ""+    parser :: Parser (Text,Text)+    parser = do+      space+      fname <- term+      void $ many $ satisfy isSep+      fval <- term+      return (fname, fval)+      where+        isSep c = c == ':' || isSpace c+        term = fmap T.pack $ some $ satisfy (not . isSep)+      
src/Staversion/Internal/Command.hs view
@@ -7,10 +7,11 @@ module Staversion.Internal.Command        ( Command(..),          parseCommandArgs,-         defFormatConfig+         defFormatConfig,+         _parseCommandStrings        ) where -import Control.Applicative ((<$>), (<*>), optional, some, (<|>))+import Control.Applicative ((<$>), (<*>), optional, some, (<|>), many) import Data.Function (on) import Data.Monoid (mconcat, (<>)) import Data.Text (pack)@@ -40,6 +41,8 @@ data Command =   Command { commBuildPlanDir :: FilePath,             -- ^ path to the directory where build plan files are stored.+            commStackCommand :: String,+            -- ^ shell command to invoke @stack@ tool.             commLogger :: Logger,             -- ^ the logger             commSources :: [PackageSource],@@ -65,7 +68,7 @@     return $ home </> ".stack" </> "build-plan"  commandParser :: DefCommand -> Opt.Parser Command-commandParser def_comm = Command <$> build_plan_dir <*> logger <*> sources+commandParser def_comm = Command <$> build_plan_dir <*> stack_command <*> logger <*> sources                          <*> queries <*> network <*> aggregate <*> format_config where   logger = makeLogger <$> is_verbose   makeLogger True = defaultLogger { loggerThreshold = Just LogDebug }@@ -81,7 +84,12 @@                                Opt.value (defBuildPlanDir def_comm),                                Opt.showDefault                              ]-  sources = some $ resolver <|> hackage+  withDefault :: Functor m => [a] -> m [a] -> m [a]+  withDefault def_vals = fmap applyDef+    where+      applyDef [] = def_vals+      applyDef vs = vs+  sources = withDefault [SourceStackDefault] $ many $ resolver <|> hackage <|> stack_explicit <|> stack_default   resolver = fmap SourceStackage $ Opt.strOption              $ mconcat [ Opt.long "resolver",                          Opt.short 'r',@@ -93,6 +101,20 @@                         Opt.short 'H',                         Opt.help "Search hackage.org for the latest version."                       ]+  stack_explicit = fmap SourceStackYaml $ Opt.strOption+                   $ mconcat [ Opt.long "stack",+                               Opt.help ( "Path to stack.yaml file."+                                          ++ " It searches for package versions of the resolver of the specified stack.yaml file."+                                        ),+                               Opt.metavar "FILE"+                             ]+  stack_default = Opt.flag' SourceStackDefault+                  $ mconcat [ Opt.long "stack-default",+                              Opt.short 'S',+                              Opt.help ( "Search the resolver that 'stack' command would use by default."+                                         ++ " This option is implied if there is no options about package source (e.g. -r and -H)."+                                       )+                            ]   queries = some $ parseQuery <$> (query_package <|> query_cabal)   query_package = Opt.strArgument                   $ mconcat [ Opt.help "Name of package whose version you want to check.",@@ -119,6 +141,13 @@                                Opt.helpDoc $ Just $ docFormatVersions "FORMAT",                                Opt.value $ fconfFormatVersion defFormatConfig                              ]+  stack_command = Opt.strOption+                  $ mconcat [ Opt.long "stack-command",+                              Opt.help "Shell command for stack tool.",+                              Opt.metavar "COMMAND",+                              Opt.value "stack",+                              Opt.showDefault+                            ]  maybeReader :: String -> (String -> Maybe a) -> Opt.ReadM a maybeReader metavar mfunc = do@@ -208,3 +237,12 @@  parseCommandArgs :: IO Command parseCommandArgs = Opt.execParser . programDescription . commandParser =<< defCommand++-- | Just for testing.+_parseCommandStrings :: [String] -> IO (Maybe Command)+_parseCommandStrings args = fmap (doParse . programDescription . commandParser) defCommand+  where+    doParse pinfo = Opt.getParseResult $ Opt.execParserPure prefs pinfo args+    prefs = Opt.prefs mempty++
src/Staversion/Internal/Exec.hs view
@@ -24,7 +24,7 @@ import Staversion.Internal.BuildPlan   ( BuildPlan, packageVersion, buildPlanSource,     newBuildPlanManager, loadBuildPlan,-    BuildPlanManager+    BuildPlanManager, manStackCommand   ) import Staversion.Internal.Command   ( parseCommandArgs,@@ -64,10 +64,15 @@ processCommand :: Command -> IO [Result] processCommand = _processCommandWithCustomBuildPlanManager return +makeBuildPlanManager :: Command -> IO BuildPlanManager+makeBuildPlanManager comm = do+  man <- newBuildPlanManager (commBuildPlanDir comm) (commLogger comm) (commAllowNetwork comm)+  return $ man { manStackCommand = commStackCommand comm }+ _processCommandWithCustomBuildPlanManager :: (BuildPlanManager -> IO BuildPlanManager) -> Command -> IO [Result] _processCommandWithCustomBuildPlanManager customBPM comm = impl where   impl = do-    bp_man <- customBPM =<< newBuildPlanManager (commBuildPlanDir comm) (commLogger comm) (commAllowNetwork comm)+    bp_man <- customBPM =<< makeBuildPlanManager comm     query_pairs <- resolveQueries' logger $ commQueries comm     fmap concat $ mapM (processQueriesIn bp_man query_pairs) $ commSources comm   logger = commLogger comm
src/Staversion/Internal/HTTP.hs view
@@ -12,7 +12,8 @@        ( Manager,          OurHttpException,          niceHTTPManager,-         fetchURL+         fetchURL,+         asStatusFailureException        ) where  import Control.Applicative ((<$>))@@ -55,3 +56,10 @@     else return ()   rethrower :: H.HttpException -> IO a   rethrower e = throwIO $ OtherHttpException e++asStatusFailureException :: OurHttpException+                         -> Maybe Int -- ^ HTTP status code+asStatusFailureException (StatusFailureException _ res) = Just code+  where+    code = fromEnum $ H.responseStatus res+asStatusFailureException _ = Nothing
src/Staversion/Internal/Query.hs view
@@ -25,6 +25,12 @@ -- | Source of packages. data PackageSource = SourceStackage Resolver -- ^ stackage.                    | SourceHackage -- ^ hackage (latest)+                   | SourceStackYaml FilePath+                     -- ^ stack.yaml file. Its \"resolver\" field is+                     -- used as the package source.+                   | SourceStackDefault+                     -- ^ the resolver that the @stack@ command would+                     -- use by default.                    deriving (Show,Eq,Ord)  -- | Query for package version(s).@@ -38,6 +44,8 @@ sourceDesc :: PackageSource -> Text sourceDesc (SourceStackage r) = pack r sourceDesc SourceHackage = "latest in hackage"+sourceDesc (SourceStackYaml p) = pack p+sourceDesc SourceStackDefault = "default stack resolver"  parseQuery :: String -> Query parseQuery s = if ".cabal" `isSuffixOf` s
staversion.cabal view
@@ -1,5 +1,5 @@ name:                   staversion-version:                0.2.1.4+version:                0.2.2.0 author:                 Toshio Ito <debug.ito@gmail.com> maintainer:             Toshio Ito <debug.ito@gmail.com> license:                BSD3@@ -20,7 +20,8 @@                         test/data/doctest.cabal_test,                         test/data/conduit.cabal_test,                         test/data/foobar.cabal_test,-                        test/data/braces.cabal_test+                        test/data/braces.cabal_test,+                        test/data/stack_sample.yaml                          homepage:               https://github.com/debug-ito/staversion bug-reports:            https://github.com/debug-ito/staversion/issues@@ -33,6 +34,7 @@   other-extensions:     CPP, DeriveDataTypeable, TupleSections   exposed-modules:      Staversion.Internal.BuildPlan,                         Staversion.Internal.BuildPlan.Stackage,+                        Staversion.Internal.BuildPlan.StackYaml,                         Staversion.Internal.BuildPlan.Hackage,                         Staversion.Internal.BuildPlan.Version,                         Staversion.Internal.Query,@@ -49,7 +51,7 @@                         Staversion.Internal.Megaparsec   build-depends:        base >=4.8 && <4.12,                         unordered-containers >=0.2.3 && <0.3,-                        aeson >=0.8.0 && <1.4,+                        aeson >=0.8.0 && <1.5,                         text >=0.11.3 && <1.3,                         bytestring >=0.10.0 && <0.11,                         yaml >=0.8.3 && <0.9,@@ -62,11 +64,12 @@                         http-types >=0.8.6 && <0.13,                         transformers >=0.3.0 && <0.6,                         transformers-compat >=0.4.0 && <0.7,-                        megaparsec >=4.2.0 && <6.5,+                        megaparsec >=4.2.0 && <6.6,                         semigroups >=0.18.0.1 && <0.19,                         Cabal >=1.22.6.0 && <2.3,                         pretty >=1.1.2.0 && <1.2,-                        ansi-wl-pprint >=0.6.7.3 && <0.7+                        ansi-wl-pprint >=0.6.7.3 && <0.7,+                        process >=1.2.3.0 && <1.7  executable staversion   default-language:     Haskell2010@@ -84,21 +87,24 @@   hs-source-dirs:       test   ghc-options:          -Wall -fno-warn-unused-imports -fno-warn-orphans "-with-rtsopts=-M512m"   main-is:              Spec.hs-  default-extensions:   OverloadedStrings+  default-extensions:   OverloadedStrings, QuasiQuotes   -- other-extensions:        other-modules:        Staversion.Internal.BuildPlanSpec,                         Staversion.Internal.BuildPlan.StackageSpec,                         Staversion.Internal.BuildPlan.HackageSpec,                         Staversion.Internal.BuildPlan.VersionSpec,+                        Staversion.Internal.BuildPlan.StackYamlSpec,                         Staversion.Internal.ExecSpec,                         Staversion.Internal.FormatSpec,                         Staversion.Internal.CabalSpec,                         Staversion.Internal.AggregateSpec,+                        Staversion.Internal.CommandSpec,                         Staversion.Internal.TestUtil   build-depends:        base, staversion, text, filepath, bytestring,                         Cabal, semigroups,                         hspec >=2.1.7,-                        QuickCheck >=2.8.1 && <2.12+                        QuickCheck >=2.8.1 && <2.12,+                        heredoc >=0.2.0.0 && <0.3  flag network-test   description: Enable network tests.
+ test/Staversion/Internal/BuildPlan/StackYamlSpec.hs view
@@ -0,0 +1,42 @@+{-# LANGUAGE QuasiQuotes, OverloadedStrings #-}+module Staversion.Internal.BuildPlan.StackYamlSpec (main,spec) where++import Data.Text (Text)+import Test.Hspec+import Text.Heredoc (here)++import Staversion.Internal.BuildPlan.StackYaml (configLocationFromText)++main :: IO ()+main = hspec spec++spec :: Spec+spec = describe "configLocationFromText" $ do+  it "should load config-location field" $ do+    configLocationFromText sample `shouldBe` Right "/home/debugito/programs/git/staversion/stack.yaml"++sample :: Text+sample = [here|stack-root: /home/debugito/.stack+project-root: /home/debugito/programs/git/staversion+config-location: /home/debugito/programs/git/staversion/stack.yaml+bin-path: /home/debugito/.stack/snapshots/x86_64-linux/lts-10.8/8.2.2/bin:/home/debugito/.stack/compiler-tools/x86_64-linux/ghc-8.2.2/bin:/home/debugito/.stack/programs/x86_64-linux/ghc-8.2.2/bin:/home/debugito/.plenv/shims:/home/debugito/.plenv/bin:/opt/gradle/bin:/home/debugito/.local/bin:/home/debugito/gems/bin:/home/debugito/perl5/bin:/home/debugito/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin+programs: /home/debugito/.stack/programs/x86_64-linux+compiler-exe: /home/debugito/.stack/programs/x86_64-linux/ghc-8.2.2/bin/ghc+compiler-bin: /home/debugito/.stack/programs/x86_64-linux/ghc-8.2.2/bin+compiler-tools-bin: /home/debugito/.stack/compiler-tools/x86_64-linux/ghc-8.2.2/bin+local-bin: /home/debugito/.local/bin+extra-include-dirs: +extra-library-dirs: +snapshot-pkg-db: /home/debugito/.stack/snapshots/x86_64-linux/lts-10.8/8.2.2/pkgdb+local-pkg-db: /home/debugito/programs/git/staversion/.stack-work/install/x86_64-linux/lts-10.8/8.2.2/pkgdb+global-pkg-db: /home/debugito/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/package.conf.d+ghc-package-path: /home/debugito/programs/git/staversion/.stack-work/install/x86_64-linux/lts-10.8/8.2.2/pkgdb:/home/debugito/.stack/snapshots/x86_64-linux/lts-10.8/8.2.2/pkgdb:/home/debugito/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/package.conf.d+snapshot-install-root: /home/debugito/.stack/snapshots/x86_64-linux/lts-10.8/8.2.2+local-install-root: /home/debugito/programs/git/staversion/.stack-work/install/x86_64-linux/lts-10.8/8.2.2+snapshot-doc-root: /home/debugito/.stack/snapshots/x86_64-linux/lts-10.8/8.2.2/doc+local-doc-root: /home/debugito/programs/git/staversion/.stack-work/install/x86_64-linux/lts-10.8/8.2.2/doc+dist-dir: .stack-work/dist/x86_64-linux/Cabal-2.0.1.0+local-hpc-root: /home/debugito/programs/git/staversion/.stack-work/install/x86_64-linux/lts-10.8/8.2.2/hpc+local-bin-path: /home/debugito/.local/bin+ghc-paths: /home/debugito/.stack/programs/x86_64-linux+|]
test/Staversion/Internal/BuildPlanSpec.hs view
@@ -70,8 +70,14 @@  loadBuildPlan_spec :: Spec loadBuildPlan_spec = describe "loadBuildPlan" $ do+  let expRight = either (\e -> error ("Error: " ++ e)) return   it "reads local file after disambiguation" $ do     bp_man <- mockBuildPlanManager 4 2-    bp <- either (\e -> error ("Error: " ++ e)) return =<< loadBuildPlan bp_man [] (SourceStackage "lts")+    bp <- expRight =<< loadBuildPlan bp_man [] (SourceStackage "lts")     packageVersion bp "base" `shouldBe` (Just $ ver [4,8,2,0])+    buildPlanSource bp `shouldBe` SourceStackage "lts-4.2"+  it "reads the given stack.yaml for resolver" $ do+    bp_man <- mockBuildPlanManager 4 2+    bp <- expRight =<< loadBuildPlan bp_man [] (SourceStackYaml ("test" </> "data" </> "stack_sample.yaml"))+    packageVersion bp "optparse-applicative" `shouldBe` (Just $ ver [0,12,0,0])     buildPlanSource bp `shouldBe` SourceStackage "lts-4.2"
+ test/Staversion/Internal/CommandSpec.hs view
@@ -0,0 +1,25 @@+{-# LANGUAGE OverloadedStrings #-}+module Staversion.Internal.CommandSpec (main,spec) where++import Test.Hspec++import Staversion.Internal.Command+  ( _parseCommandStrings, Command(..)+  )+import Staversion.Internal.Query+  ( PackageSource(..), Query(..)+  )++main :: IO ()+main = hspec spec++spec :: Spec+spec = describe "_parseCommandStrings" $ do+  it "should use SourceStackDefault if no source is specified." $ do+    (Just com) <- _parseCommandStrings ["aeson"]+    commQueries com `shouldBe` [QueryName "aeson"]+    commSources com `shouldBe` [SourceStackDefault]+  it "should use the given sources when there are some." $ do+    (Just com) <- _parseCommandStrings ["-r", "lts-10", "base"]+    commQueries com `shouldBe` [QueryName "base"]+    commSources com `shouldBe` [SourceStackage "lts-10"]
test/Staversion/Internal/ExecSpec.hs view
@@ -136,7 +136,8 @@                         commQueries = [],                         commAllowNetwork = False,                         commAggregator = Nothing,-                        commFormatConfig = defFormatConfig+                        commFormatConfig = defFormatConfig,+                        commStackCommand = "stack"                       }  spec_processCommand_disambiguates :: Spec
+ test/data/stack_sample.yaml view
@@ -0,0 +1,77 @@+# This file was automatically generated by 'stack init'+#+# Some commonly used options have been documented as comments in this file.+# For advanced use and comprehensive documentation of the format, please see:+# https://docs.haskellstack.org/en/stable/yaml_configuration/++# Resolver to choose a 'specific' stackage snapshot or a compiler version.+# A snapshot resolver dictates the compiler version and the set of packages+# to be used for project dependencies. For example:+#+# resolver: lts-3.5+# resolver: nightly-2015-09-21+# resolver: ghc-7.10.2+# resolver: ghcjs-0.1.0_ghc-7.10.2+# resolver:+#  name: custom-snapshot+#  location: "./custom-snapshot.yaml"+resolver: lts-4.2++# User packages to be built.+# Various formats can be used as shown in the example below.+#+# packages:+# - some-directory+# - https://example.com/foo/bar/baz-0.0.2.tar.gz+# - location:+#    git: https://github.com/commercialhaskell/stack.git+#    commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a+# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a+#   extra-dep: true+#  subdirs:+#  - auto-update+#  - wai+#+# A package marked 'extra-dep: true' will only be built if demanded by a+# non-dependency (i.e. a user package), and its test suites and benchmarks+# will not be run. This is useful for tweaking upstream packages.+packages:+- .++# Dependency packages to be pulled from upstream that are not in the resolver+# (e.g., acme-missiles-0.3)+extra-deps: []++#### confirmed on 2018-03-12+## - aeson-1.3.0.0+## - QuickCheck-2.11.3+## - doctest-0.14.1+## - text-1.2.3.0+## - hspec-core-2.4.8+## - hspec-2.4.8+## - hspec-discover-2.4.8+## - hspec-expectations-0.8.2++# Override default flag values for local packages and extra-deps+flags: {}++# Extra package databases containing global packages+extra-package-dbs: []++# Control whether we use the GHC we find on the path+# system-ghc: true+#+# Require a specific version of stack, using version ranges+# require-stack-version: -any # Default+# require-stack-version: ">=1.5"+#+# Override the architecture used by stack, especially useful on Windows+# arch: i386+# arch: x86_64+#+# Extra directories used by stack for building+# extra-include-dirs: [/path/to/dir]+# extra-lib-dirs: [/path/to/dir]+#+# Allow a newer minor version of GHC than the snapshot specifies+# compiler-check: newer-minor