Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
Respect inferred extension in integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrisbin committed Aug 1, 2023
1 parent 627297c commit d824033
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions promote/src/Restyled/Promote/IntegrationTest/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import Data.Aeson
import qualified Data.Yaml as Yaml
import RIO.Directory (createDirectoryIfMissing)
import RIO.FilePath (takeDirectory, (<.>), (</>))
import RIO.List (headMaybe)
import qualified RIO.Map as Map
import RIO.Text (unpack)
import qualified RIO.Text as T
import Restyled.Promote.Channel

data Restyler = Restyler
{ name :: Text
, include :: [Text]
, metadata :: Maybe Metadata
}
deriving stock (Generic)
Expand All @@ -31,7 +33,7 @@ newtype Metadata = Metadata

data TestCase = TestCase
{ support :: Maybe SupportFile
, extension :: Maybe String
, extension :: Maybe Text
, contents :: Text
}
deriving stock (Generic)
Expand All @@ -40,23 +42,25 @@ data TestCase = TestCase
testCaseFiles
:: Text
-- ^ Restyler name
-> Maybe Text
-- ^ Inferred extension
-> Int
-- ^ Index
-> TestCase
-> [(FilePath, Text)]
testCaseFiles name n TestCase {support, extension, contents}
testCaseFiles name inferredExtension n TestCase {support, extension, contents}
| "\r\n" `T.isInfixOf` contents =
[]
| otherwise =
maybeToList (supportFile <$> support)
<> [
( unpack name
</> "test-file-"
<> show @Int n
<.> fromMaybe "example" extension
( unpack name </> baseName
, contents
)
]
where
baseName = "test-file-" <> show @Int n <.> unpack finalExtension
finalExtension = fromMaybe "example" $ extension <|> inferredExtension

data SupportFile = SupportFile
{ path :: FilePath
Expand Down Expand Up @@ -110,9 +114,16 @@ toFiles channel restylers =
}

toTestFiles :: Restyler -> [(FilePath, Text)]
toTestFiles Restyler {name, metadata} = fromMaybe [] $ do
toTestFiles Restyler {name, include, metadata} = fromMaybe [] $ do
Metadata {tests} <- metadata
concat . zipWith (testCaseFiles name) [0 ..] <$> tests

let mExtension =
headMaybe
. filter ("." `T.isInfixOf`)
. filter (not . ("!" `T.isPrefixOf`))
$ include

concat . zipWith (testCaseFiles name mExtension) [0 ..] <$> tests

writeFiles
:: (MonadIO m, MonadReader env m, HasLogFunc env)
Expand Down

0 comments on commit d824033

Please sign in to comment.