-- SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com -- SPDX-License-Identifier: MIT module YamlSpec where import Control.Exception (Exception (displayException), SomeException) import Control.Monad import Data.List (isInfixOf) import Misc import System.FilePath import Test.Hspec (Spec, describe, it, runIO, shouldReturn, shouldThrow) import Yaml (yamlRule) spec :: Spec spec = do describe "parses yaml rule" $ do let resources = "test-resources/yaml-packs" packs <- runIO (allPathsIn resources) forM_ packs ( \pth -> it (makeRelative resources pth) $ do _ <- yamlRule pth pure () `shouldReturn` () ) describe "fails on yaml typos" $ do let resources = "test-resources/yaml-typos" packs <- runIO (allPathsIn resources) forM_ packs ( \pth -> it (makeRelative resources pth) $ shouldThrow (yamlRule pth) ( \e -> let msg = displayException (e :: SomeException) in "Unknown" `isInfixOf` msg || "Exactly one" `isInfixOf` msg ) )