diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2019-05-25 13:57:45 +0200 |
---|---|---|
committer | Ben Gamari <ben@well-typed.com> | 2019-06-03 23:42:12 -0400 |
commit | c2707d271107a9877b8a0060914b9130d6510f38 (patch) | |
tree | ca5b765fe34ca0e79114b6be2a7f3063700c3cea /testsuite | |
parent | 23f8525f4171fc220787e121e54f2a2705703047 (diff) | |
download | haskell-c2707d271107a9877b8a0060914b9130d6510f38.tar.gz |
Catch preprocessor errors in downsweep
This changes the way preprocessor failures are presented to the
user. Previously the user would simply get an unlocated message on stderr
such as:
`gcc' failed in phase `C pre-processor'. (Exit code: 1)
Now at the problematic source file is mentioned:
A.hs:1:1: error:
`gcc' failed in phase `C pre-processor'. (Exit code: 1)
This also makes live easier for GHC API clients as the preprocessor error
is now thrown as a SourceError exception.
Diffstat (limited to 'testsuite')
5 files changed, 80 insertions, 12 deletions
diff --git a/testsuite/tests/driver/T8602/T8602.stderr b/testsuite/tests/driver/T8602/T8602.stderr index eb28842f54..4b0c4a5373 100644 --- a/testsuite/tests/driver/T8602/T8602.stderr +++ b/testsuite/tests/driver/T8602/T8602.stderr @@ -1,2 +1,4 @@ A B C -`t8602.sh' failed in phase `Haskell pre-processor'. (Exit code: 1) + +A.hs:1:1: error: + `t8602.sh' failed in phase `Haskell pre-processor'. (Exit code: 1) diff --git a/testsuite/tests/ghc-api/downsweep/PartialDownsweep.darwin.stderr b/testsuite/tests/ghc-api/downsweep/PartialDownsweep.darwin.stderr new file mode 100644 index 0000000000..c9cd0f216d --- /dev/null +++ b/testsuite/tests/ghc-api/downsweep/PartialDownsweep.darwin.stderr @@ -0,0 +1,16 @@ +== Parse error in export list +== Parse error in export list with bypass module +== Parse error in import list +== CPP preprocessor error + +B.hs:2:2: #elif without #if + #elif <- cpp error here + ^ +1 error generated. +== CPP preprocessor error with bypass + +B.hs:2:2: #elif without #if + #elif <- cpp error here + ^ +1 error generated. +== Import error diff --git a/testsuite/tests/ghc-api/downsweep/PartialDownsweep.hs b/testsuite/tests/ghc-api/downsweep/PartialDownsweep.hs index f3c379a3fb..fb91fb6c1f 100644 --- a/testsuite/tests/ghc-api/downsweep/PartialDownsweep.hs +++ b/testsuite/tests/ghc-api/downsweep/PartialDownsweep.hs @@ -45,7 +45,8 @@ main = do runGhc (Just libdir) $ do dflags0 <- getSessionDynFlags (dflags1, _, _) <- parseDynamicFlags dflags0 $ map noLoc $ - [ -- "-v3" + [ "-fno-diagnostics-show-caret" + -- , "-v3" ] ++ args _ <- setSessionDynFlags dflags1 @@ -65,6 +66,23 @@ main = do sort (map (moduleNameString . moduleName . ms_mod) mss) == ["A"] ) + go "Parse error in export list with bypass module" + [ [ "module A where" + , "import B" + , "import C" + ] + , [ "module B !parse_error where" + , "import D" + ] + , [ "module C where" + , "import D" + ] + , [ "module D where" + ] + ] + (\mss -> return $ + sort (map (moduleNameString . moduleName . ms_mod) mss) == ["A", "C", "D"] + ) go "Parse error in import list" [ [ "module A where" , "import B" @@ -83,24 +101,40 @@ main = do sort (map (moduleNameString . moduleName . ms_mod) mss) == ["A", "B"] ) - go "Parse error in export list with bypass module" + go "CPP preprocessor error" [ [ "module A where" , "import B" - , "import C" ] - , [ "module B !parse_error where" - , "import D" + , [ "{-# LANGUAGE CPP #-}" + , "#elif <- cpp error here" + , "module B where" + , "import C" ] , [ "module C where" - , "import D" ] - , [ "module D where" + ] + (\mss -> return $ + sort (map (moduleNameString . moduleName . ms_mod) mss) == ["A"] + ) + + go "CPP preprocessor error with bypass" + [ [ "module A where" + , "import B" + , "import C" + ] + , [ "{-# LANGUAGE CPP #-}" + , "#elif <- cpp error here" + , "module B where" + , "import C" + ] + , [ "module C where" ] ] (\mss -> return $ - sort (map (moduleNameString . moduleName . ms_mod) mss) == ["A", "C", "D"] + sort (map (moduleNameString . moduleName . ms_mod) mss) == ["A", "C"] ) + errored <- readIORef any_failed when errored $ exitFailure return () @@ -125,5 +159,8 @@ go label mods cnd = writeMod :: [String] -> IO () -writeMod src@(head -> stripPrefix "module " -> Just (takeWhile (/=' ') -> mod)) - = writeFile (mod++".hs") $ unlines src +writeMod src = + writeFile (mod++".hs") $ unlines src + where + Just modline = find ("module" `isPrefixOf`) src + Just (takeWhile (/=' ') -> mod) = stripPrefix "module " modline diff --git a/testsuite/tests/ghc-api/downsweep/PartialDownsweep.stderr b/testsuite/tests/ghc-api/downsweep/PartialDownsweep.stderr index 11fd4b73c8..9e5f6d83dc 100644 --- a/testsuite/tests/ghc-api/downsweep/PartialDownsweep.stderr +++ b/testsuite/tests/ghc-api/downsweep/PartialDownsweep.stderr @@ -1,3 +1,15 @@ == Parse error in export list -== Parse error in import list == Parse error in export list with bypass module +== Parse error in import list +== CPP preprocessor error + +B.hs:2:0: error: + error: #elif without #if + #elif <- cpp error here + +== CPP preprocessor error with bypass + +B.hs:2:0: error: + error: #elif without #if + #elif <- cpp error here + diff --git a/testsuite/tests/ghc-api/downsweep/all.T b/testsuite/tests/ghc-api/downsweep/all.T index d7ed778f8e..8ca54b0bc6 100644 --- a/testsuite/tests/ghc-api/downsweep/all.T +++ b/testsuite/tests/ghc-api/downsweep/all.T @@ -1,5 +1,6 @@ test('PartialDownsweep', [ extra_run_opts('"' + config.libdir + '"') + , when(opsys('darwin'), skip) # use_specs doesn't exist on this branch yet ], compile_and_run, ['-package ghc']) |