packages feed

mdoc-0.1.0.0: test/Mdoc/Gen/ExitStatusSpec.hs

module Mdoc.Gen.ExitStatusSpec
  ( spec
  ) where

import Mdoc.Prelude

import Mdoc.Gen.ExitStatus
import Mdoc.MdocLine
import Mdoc.Pretty
import Mdoc.Pretty.MdocLine
import Test.Hspec

spec :: Spec
spec = do
  describe "renderExitStatuses" $ do
    it "can re-create Ex -std format" $ do
      let nzs = pure $ NonZeroStatus ">0" "if an error occurs"

      render (renderExitStatuses nzs)
        `shouldBe` mconcat
          [ "The\n"
          , ".Nm\n"
          , "utility exits 0 on success,\n"
          , "and >0 if an error occurs.\n"
          ]

    it "is flexible to more non-zero statuses" $ do
      -- https://github.com/ocharles/weeder#exit-codes
      let nzs =
            NonZeroStatus "228" "if one or more weeds found"
              :| [ NonZeroStatus "1" "for generic failing exit code"
                 , NonZeroStatus "2" "due to failure to read HIE file due to GHC version mismatch"
                 , NonZeroStatus "3" "due to failure to parse config file"
                 , NonZeroStatus "4" "when no HIE files found"
                 ]

      render (renderExitStatuses nzs)
        `shouldBe` mconcat
          [ "The\n"
          , ".Nm\n"
          , "utility exits 0 on success,\n"
          , "228 if one or more weeds found,\n"
          , "1 for generic failing exit code,\n"
          , "2 due to failure to read HIE file due to GHC version mismatch,\n"
          , "3 due to failure to parse config file,\n"
          , "and 4 when no HIE files found.\n"
          ]

render :: NonEmpty MdocLine -> Text
render = renderPlain . vsep . map prettyMdocLine . toList