File: OptionsSpec.hs

package info (click to toggle)
haskell-doctest 0.22.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: haskell: 3,148; makefile: 5; ansic: 3
file content (99 lines) | stat: -rw-r--r-- 3,445 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
module OptionsSpec (spec) where

import           Imports

import           Data.List

import           Test.Hspec
import           Test.QuickCheck hiding (verbose)

import           Options

newtype NonInteractive = NonInteractive String
  deriving (Eq, Show)

instance Arbitrary NonInteractive where
  arbitrary = NonInteractive <$> elements (nonInteractiveGhcOptions \\ ["--info"])

spec :: Spec
spec = do
  describe "parseOptions" $ do
    let
      run :: [String] -> Run
      run ghcOptions = defaultRun {
        runWarnings = ["WARNING: --optghc is deprecated, doctest now accepts arbitrary GHC options\ndirectly."]
      , runMagicMode = True
      , runConfig = defaultConfig { ghcOptions }
      }

    it "strips --optghc" $
      parseOptions ["--optghc", "foobar"] `shouldBe` Result (run ["foobar"])

    it "strips --optghc=" $
      parseOptions ["--optghc=foobar"] `shouldBe` Result (run ["foobar"])

    context "with ghc options that are not valid with --interactive" $ do
      it "returns ProxyToGhc" $ do
        property $ \ (NonInteractive x) xs -> do
          let options = x : xs
          parseOptions options `shouldBe` ProxyToGhc options

    context "with --interactive" $ do
      let options = ["--interactive", "--foo", "--bar"]

      it "disables magic mode" $ do
        runMagicMode <$> parseOptions options `shouldBe` Result False

      it "filters out --interactive" $ do
        ghcOptions . runConfig <$> parseOptions options `shouldBe` Result ["--foo", "--bar"]

      it "accepts --fast" $ do
        fastMode . runConfig <$> parseOptions ("--fast" : options) `shouldBe` Result True

    describe "--no-magic" $ do
      context "without --no-magic" $ do
        it "enables magic mode" $ do
          runMagicMode <$> parseOptions [] `shouldBe` Result True

      context "with --no-magic" $ do
        it "disables magic mode" $ do
          runMagicMode <$> parseOptions ["--no-magic"] `shouldBe` Result False

    describe "--fast" $ do
      context "without --fast" $ do
        it "disables fast mode" $ do
          fastMode . runConfig <$> parseOptions [] `shouldBe` Result False

      context "with --fast" $ do
        it "enabled fast mode" $ do
          fastMode . runConfig <$> parseOptions ["--fast"] `shouldBe` Result True

    describe "--preserve-it" $ do
      context "without --preserve-it" $ do
        it "does not preserve the `it` variable" $ do
          preserveIt . runConfig <$> parseOptions [] `shouldBe` Result False

      context "with --preserve-it" $ do
        it "preserves the `it` variable" $ do
          preserveIt . runConfig <$> parseOptions ["--preserve-it"] `shouldBe` Result True

    context "with --help" $ do
      it "outputs usage information" $ do
        parseOptions ["--help"] `shouldBe` Output usage

    context "with --version" $ do
      it "outputs version information" $ do
        parseOptions ["--version"] `shouldBe` Output versionInfo

    context "with --info" $ do
      it "outputs machine readable version information" $ do
        parseOptions ["--info"] `shouldBe` Output info

    describe "--verbose" $ do
      context "without --verbose" $ do
        it "is not verbose by default" $ do
          verbose . runConfig <$> parseOptions [] `shouldBe` Result False

      context "with --verbose" $ do
        it "parses verbose option" $ do
          verbose . runConfig <$> parseOptions ["--verbose"] `shouldBe` Result True