Skip to content

Commit

Permalink
Ensure restylers are tested on only their test files
Browse files Browse the repository at this point in the history
Testing multiple restylers at once, that operate on the same files, were
operating on each others test files and causing failures.

To address this, we take the files created for each restyler and then
put only them as the configured `include` for that restyler when the
tests are run. This ensures isolation.

It's possible we still have isolation bugs with shebang-based restyling,
but we'll cross that bridge when it causes a failure.
  • Loading branch information
pbrisbin committed Oct 9, 2024
1 parent 926cf4b commit efcdc02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions _tools/restylers/src/Restylers/Info/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ writeTestFiles
-> RestylerName
-> [Text]
-> Test
-> m ()
-> m FilePath
writeTestFiles number name include test@Test {contents, support} = do
logInfo $ "CREATE" :# ["path" .= path]
liftIO $ T.writeFile path contents
traverse_ writeSupportFile support
path <$ traverse_ writeSupportFile support
where
path = testFilePath number name include test

Expand Down
14 changes: 11 additions & 3 deletions _tools/restylers/src/Restylers/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ import Test.Hspec
import UnliftIO.Directory
import UnliftIO.Temporary (withTempDirectory)

data CRestyler = CRestyler
{ name :: RestylerName
, include :: [FilePath]
}
deriving stock (Generic)
deriving anyclass (ToJSON)

testRestylers
:: ( MonadUnliftIO m
, MonadLogger m
Expand All @@ -50,15 +57,16 @@ testRestylers pull restylers hspecArgs = do

withTempDirectory cwd "restylers-test" $ \tmp ->
withCurrentDirectory tmp $ do
for_ restylers $ \restyler -> do
for_ (restylerTests restyler) $ \(number, test) -> do
crestylers <- for restylers $ \restyler -> do
files <- for (restylerTests restyler) $ \(number, test) -> do
writeTestFiles number restyler.name restyler.include test
pure $ CRestyler restyler.name files

writeYaml testManifest restylers
writeYaml ".restyled.yaml"
$ object
[ "restylers_version" .= ("testing" :: Text)
, "restylers" .= ((.name) <$> restylers)
, "restylers" .= crestylers
]

let code = cwd </> takeBaseName tmp
Expand Down

0 comments on commit efcdc02

Please sign in to comment.