-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Read environment variables for hspec tests
--   
--   Read environment variables for hspec tests. See
--   <a>Test.Hspec.NeedEnv</a>.
@package hspec-need-env
@version 0.1.0.3


-- | <a>Synopsis</a>:
--   
--   <pre>
--   module Synopsis (main,spec) where
--   
--   import Control.Applicative ((&lt;$&gt;), (&lt;*&gt;))
--   import Test.Hspec (Spec, SpecWith, hspec, before, describe, it, shouldBe)
--   import Test.Hspec.NeedEnv (EnvMode(Need), needEnv, needEnvRead)
--   
--   main :: IO ()
--   main = hspec spec
--   
--   -- | Read environment variables for parameters necessary for testing.
--   getEnvs :: IO (String, Int)
--   getEnvs = (,)
--             &lt;$&gt; needEnv mode "TEST_USER_NAME"
--             &lt;*&gt; needEnvRead mode "TEST_SEED"
--     where
--       mode = Need
--   
--   spec :: Spec
--   spec = before getEnvs $ specWithUserAndSeed
--          -- ^ Use 'before' and similar functions to write 'SpecWith'
--          -- that takes parameters.
--   
--   -- | Test spec that depends on the environment variables.
--   specWithUserAndSeed :: SpecWith (String, Int)
--   specWithUserAndSeed = describe "funcUnderTest" $ do
--     it "should do something" $ \(user_name, seed) -&gt; do
--       funcUnderTest user_name seed `shouldBe` "SOMETHING"
--   
--   funcUnderTest :: String -&gt; Int -&gt; String
--   funcUnderTest = undefined
--   </pre>
--   
--   This module exports <a>needEnv</a> and other similar functions that
--   read environment variables in hspec tests. They are useful to write
--   tests that depend on some external entities, e.g. Web servers,
--   database servers and random number generators.
module Test.Hspec.NeedEnv

-- | How to treat missing environment variable.
data EnvMode

-- | If the environment variable is not set, the test fails.
Need :: EnvMode

-- | If the environment variable is not set, the test gets pending.
Want :: EnvMode

-- | Get value of the specified environment variable. If the environment
--   variable is not set, it executes the action specified by the
--   <a>EnvMode</a>.
needEnv :: EnvMode -> String -> IO String

-- | Get environment variable by <a>needEnv</a>, and parse the value. If it
--   fails to parse, the test fails.
needEnvParse :: EnvMode -> (String -> Either String a) -> String -> IO a

-- | Parse the environment variable with <a>Read</a> class.
needEnvRead :: Read a => EnvMode -> String -> IO a

-- | Get the pair of hostname and port number from environment variables.
--   
--   It reads environment variables <tt>(prefix ++ "_HOST")</tt> and
--   <tt>(prefix ++ "_PORT")</tt>.
needEnvHostPort :: EnvMode -> String -> IO (String, Int)
instance GHC.Enum.Bounded Test.Hspec.NeedEnv.EnvMode
instance GHC.Enum.Enum Test.Hspec.NeedEnv.EnvMode
instance GHC.Classes.Ord Test.Hspec.NeedEnv.EnvMode
instance GHC.Classes.Eq Test.Hspec.NeedEnv.EnvMode
instance GHC.Show.Show Test.Hspec.NeedEnv.EnvMode
