@@ -46,7 +46,8 @@ import System.IO.UTF8 (readUTF8File)
4646import Text.Regex.Base (RegexContext (.. ), RegexMaker (.. ))
4747import Text.Regex.TDFA (Regex )
4848
49- import TestUtils (ExpectedModuleName (.. ), SupportModules , compile , createOutputFile , getTestFiles , goldenVsString , modulesDir , trim )
49+ import Data.Set qualified as S
50+ import TestUtils (ExpectedModuleName (.. ), SupportModules , compile , compile' , createOutputFile , getTestFiles , goldenVsString , modulesDir , trim )
5051import Test.Hspec (Expectation , SpecWith , beforeAllWith , describe , expectationFailure , it , runIO )
5152
5253spec :: SpecWith SupportModules
@@ -134,7 +135,11 @@ assertCompiles
134135 -> Handle
135136 -> Expectation
136137assertCompiles support inputFiles outputFile = do
137- (fileContents, (result, _)) <- compile (Just IsMain ) support inputFiles
138+ extraFfiExts <- getFfiExts (getTestMain inputFiles)
139+ let opts = if null extraFfiExts
140+ then P. defaultOptions
141+ else P. defaultOptions { P. optionsFFIExts = S. fromList extraFfiExts `S.union` P. optionsFFIExts P. defaultOptions }
142+ (fileContents, (result, _)) <- compile' opts (Just IsMain ) support inputFiles
138143 let errorOptions = P. defaultPPEOptions { P. ppeFileContents = fileContents }
139144 case result of
140145 Left errs -> expectationFailure . P. prettyPrintMultipleErrors errorOptions $ errs
@@ -253,6 +258,11 @@ getShouldFailWith = extractPragma "shouldFailWith"
253258getShouldWarnWith :: FilePath -> IO [String ]
254259getShouldWarnWith = extractPragma " shouldWarnWith"
255260
261+ -- Scans a file for @ffiExts directives in the comments, used to
262+ -- determine additional FFI file extensions for the test
263+ getFfiExts :: FilePath -> IO [String ]
264+ getFfiExts = extractPragma " ffiExts"
265+
256266extractPragma :: String -> FilePath -> IO [String ]
257267extractPragma pragma = fmap go . readUTF8File
258268 where
0 commit comments