Commit e00910b0 authored by Alan Zimmerman's avatar Alan Zimmerman
Browse files

ApiAnnotations : rationalise tests

Summary:
At the moment the API Annotations tests have a driver that has been
copy/pasted multiple times.

Compile it once, and run it for each test case.

Test Plan: ./validate

Reviewers: hvr, austin

Reviewed By: austin

Subscribers: bgamari, thomie

Differential Revision: https://phabricator.haskell.org/D913

GHC Trac Issues: #10452
parent f6ca6959
......@@ -3,20 +3,20 @@ parseTree
comments
exampleTest
listcomps
t10309
t10357
t10358
boolFormula
t10255
t10268
t10269
t10278
t10280
t10312
t10307
t10399
boolFormula
t10278
t10309
t10312
t10354
t10357
t10358
t10396
t10399
*.hi
*.o
*.run.*
......
{-# LANGUAGE RankNTypes #-}
-- This program must be called with GHC's libdir and the file to be checked as
-- the command line arguments.
module CheckUtils where
import Data.Data
import Data.List
import System.IO
import GHC
import BasicTypes
import DynFlags
import MonadUtils
import Outputable
import ApiAnnotation
import Bag (filterBag,isEmptyBag)
import System.Directory (removeFile)
import System.Environment( getArgs )
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Dynamic ( fromDynamic,Dynamic )
_main::IO()
_main = do
[libdir,fileName] <- getArgs
testOneFile libdir fileName
testOneFile libdir fileName = do
((anns,cs),p) <- runGhc (Just libdir) $ do
dflags <- getSessionDynFlags
setSessionDynFlags dflags
let mn =mkModuleName fileName
addTarget Target { targetId = TargetModule mn
, targetAllowObjCode = True
, targetContents = Nothing }
load LoadAllTargets
modSum <- getModSummary mn
p <- parseModule modSum
return (pm_annotations p,p)
let spans = Set.fromList $ getAllSrcSpans (pm_parsed_source p)
problems = filter (\(s,a) -> not (Set.member s spans))
$ getAnnSrcSpans (anns,cs)
exploded = [((kw,ss),[anchor])
| ((anchor,kw),sss) <- Map.toList anns,ss <- sss]
exploded' = Map.toList $ Map.fromListWith (++) exploded
problems' = filter (\(_,anchors)
-> not (any (\a -> Set.member a spans) anchors))
exploded'
putStrLn "---Problems---------------------"
putStrLn (intercalate "\n" [showAnns $ Map.fromList $ map snd problems])
putStrLn "---Problems'--------------------"
putStrLn (intercalate "\n" [pp $ Map.fromList $ map fst problems'])
putStrLn "--------------------------------"
putStrLn (intercalate "\n" [showAnns anns])
where
getAnnSrcSpans :: ApiAnns -> [(SrcSpan,(ApiAnnKey,[SrcSpan]))]
getAnnSrcSpans (anns,_) = map (\a@((ss,_),_) -> (ss,a)) $ Map.toList anns
getAllSrcSpans :: (Data t) => t -> [SrcSpan]
getAllSrcSpans ast = everything (++) ([] `mkQ` getSrcSpan) ast
where
getSrcSpan :: SrcSpan -> [SrcSpan]
getSrcSpan ss = [ss]
showAnns anns = "[\n" ++ (intercalate "\n"
$ map (\((s,k),v)
-> ("(AK " ++ pp s ++ " " ++ show k ++" = " ++ pp v ++ ")\n"))
$ Map.toList anns)
++ "]\n"
pp a = showPpr unsafeGlobalDynFlags a
-- ---------------------------------------------------------------------
-- Copied from syb for the test
-- | Generic queries of type \"r\",
-- i.e., take any \"a\" and return an \"r\"
--
type GenericQ r = forall a. Data a => a -> r
-- | Make a generic query;
-- start from a type-specific case;
-- return a constant otherwise
--
mkQ :: ( Typeable a
, Typeable b
)
=> r
-> (b -> r)
-> a
-> r
(r `mkQ` br) a = case cast a of
Just b -> br b
Nothing -> r
-- | Summarise all nodes in top-down, left-to-right order
everything :: (r -> r -> r) -> GenericQ r -> GenericQ r
-- Apply f to x to summarise top-level node;
-- use gmapQ to recurse into immediate subterms;
-- use ordinary foldl to reduce list of intermediate results
everything k f x = foldl k (f x) (gmapQ (everything k f) x)
......@@ -5,135 +5,162 @@ include $(TOP)/mk/test.mk
clean:
rm -f *.o *.hi
rm -f annotations comments parseTree exampleTest
rm -f listcomps
rm -f boolFormula
rm -f t10255
rm -f t10268
rm -f t10269
rm -f t10255 t10312
rm -f t1037
rm -f t10309
rm -f listcomps boolFormula
rm -f t10357
rm -f t10278
rm -f t10280
rm -f t10307
rm -f t10309
rm -f t10312
rm -f t10354
rm -f t10357
rm -f t10358
rm -f t10396
rm -f t10399
annotations:
.PHONY: annotations
annotations:
rm -f annotations.o annotations.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc annotations
./annotations "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
parseTree:
.PHONY: parseTree
parseTree:
rm -f parseTree.o parseTree.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc parseTree
./parseTree "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
comments:
.PHONY: comments
comments:
rm -f comments.o comments.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc comments
./comments "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: exampleTest
exampleTest:
rm -f exampleTest.o exampleTest.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc exampleTest
./exampleTest "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_exampleTest \
exampleTest
./exampleTest "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" AnnotationTuple
.PHONY: listcomps
listcomps:
rm -f listcomps.o listcomps.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc listcomps
./listcomps "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
t10358:
.PHONY: T10358
T10358:
rm -f t10358.o t10358.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10358
./t10358 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: t10358
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10358 \
t10358
./t10358 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358
.PHONY: T10396
T10396:
rm -f T10396.o T10396.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10396
./t10396 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: t10396
t10255:
rm -f t10396.o t10396.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10396 \
t10396
./t10396 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10396
.PHONY: T10255
T10255:
rm -f t10255.o t10255.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10255
./t10255 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10255 \
t10255
./t10255 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10255
t10357:
.PHONY: T10357
T10357:
rm -f t10357.o t10357.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10357
./t10357 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: t10357
.PHONY: clean annotations parseTree comments exampleTest listcomps t10255
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10357 \
t10357
./t10357 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10357
.PHONY: T10268
T10268:
rm -f t10268.o t10268.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10268
./t10268 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10268 \
t10268
./t10268 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10268
.PHONY: T10280
T10280:
rm -f t10280.o t10280.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10280
./t10280 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: clean annotations parseTree comments exampleTest listcomps
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10280 \
t10280
./t10280 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10280
.PHONY: T10269
T10269:
rm -f T10269.o T10269.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10269
./t10269 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: t10269
t10312:
rm -f t10269.o t10269.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10269 \
t10269
./t10269 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10269
.PHONY: T10312
T10312:
rm -f t10312.o t10312.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10312
./t10312 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: clean annotations parseTree comments exampleTest listcomps t10255 t10312
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10312 \
t10312
./t10312 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10312
t10307:
.PHONY: T10307
T10307:
rm -f t10307.o t10307.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10307
./t10307 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: t10307
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10307 \
t10307
./t10307 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10307
t10309:
.PHONY: T10309
T10309:
rm -f t10309.o t10309.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10309
./t10309 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: t10309
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10309 \
t10309
./t10309 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10309
.PHONY: boolFormula
boolFormula:
rm -f boolFormula.o boolFormula.hi
# Disable all warnings to make sure boolFormula.stderr is repeatable
'$(TEST_HC)' $(TEST_HC_OPTS) --make -w -v0 -package ghc boolFormula
./boolFormula "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: clean annotations parseTree comments exampleTest listcomps boolFormula
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_boolFormula \
boolFormula
./boolFormula "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" TestBoolFormula
.PHONY: T10278
T10278:
rm -f t10278.o t10278.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10278
./t10278 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: T10278
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10278 \
t10278
./t10278 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10278
.PHONY: T10354
T10354:
rm -f t10354.o t10354.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10354
./t10354 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10354 \
t10354
./t10354 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10354
.PHONY: t10354
t10399:
.PHONY: T10399
T10399:
rm -f t10399.o t10399.hi
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t10399
./t10399 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`"
.PHONY: t10399
'$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc \
-outputdir tmp_T10399 \
t10399
./t10399 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10399
Test10255.hs:1:14: Warning:
-XPatternSignatures is deprecated: use -XScopedTypeVariables or pragma {-# LANGUAGE ScopedTypeVariables #-} instead
......@@ -3,6 +3,8 @@
(AK <no location info> AnnEofPos = [Test10255.hs:8:1])
]
---Problems'--------------------
[(AnnEofPos, Test10255.hs:8:1)]
--------------------------------
[
(AK Test10255.hs:1:1 AnnModule = [Test10255.hs:2:1-6])
......
Test10268.hs:5:6:
Test10268.hs:5:6: error:
Not in scope: ‘footemplate’
In the untyped splice: $footemplate
Test10268.hs:7:14:
Test10268.hs:7:14: error:
Not in scope: type constructor or class ‘Pattern’
Test10268.hs:10:10:
Test10268.hs:10:10: error:
Not in scope: type constructor or class ‘Pattern’
......@@ -2,6 +2,8 @@
[
]
---Problems'--------------------
[]
--------------------------------
[
(AK Test10268.hs:1:1 AnnModule = [Test10268.hs:3:1-6])
......
......@@ -9,6 +9,8 @@
(AK <no location info> AnnEofPos = [Test10269.hs:5:1])
]
---Problems'--------------------
[(AnnVal, Test10269.hs:4:4-6), (AnnEofPos, Test10269.hs:5:1)]
--------------------------------
[
(AK Test10269.hs:1:1 AnnModule = [Test10269.hs:1:1-6])
......
Test10280.hs:4:8: Not in scope: ‘atomicModifyIORef’
Test10280.hs:4:8: error: Not in scope: ‘atomicModifyIORef’
Test10280.hs:4:26: Not in scope: ‘ciTokens’
Test10280.hs:4:26: error: Not in scope: ‘ciTokens’
Test10280.hs:4:44: Not in scope: ‘f’
Test10280.hs:4:44: error: Not in scope: ‘f’
......@@ -3,6 +3,8 @@
(AK <no location info> AnnEofPos = [Test10280.hs:5:1])
]
---Problems'--------------------
[(AnnEofPos, Test10280.hs:5:1)]
--------------------------------
[
(AK Test10280.hs:1:1 AnnModule = [Test10280.hs:2:1-6])
......
......@@ -3,6 +3,8 @@
(AK Test10307.hs:6:8-34 AnnEqual = [Test10307.hs:6:31])
]
---Problems'--------------------
[]
--------------------------------
[
(AK Test10307.hs:1:1 AnnModule = [Test10307.hs:2:1-6])
......
......@@ -3,6 +3,8 @@
(AK Test10309.hs:(5,20)-(6,34) AnnRarrow = [Test10309.hs:6:22-23])
]
---Problems'--------------------
[]
--------------------------------
[
(AK Test10309.hs:1:1 AnnModule = [Test10309.hs:2:1-6])
......
......@@ -2,6 +2,8 @@
[
]
---Problems'--------------------
[]
--------------------------------
[
(AK Test10312.hs:1:1 AnnModule = [Test10312.hs:4:1-6])
......
Test10358.hs:5:14: error: Not in scope: ‘x’
Test10358.hs:5:16: error: Not in scope: ‘x’
Test10358.hs:6:12: error: Not in scope: ‘v’
Test10358.hs:6:14: error: Not in scope: ‘v’
Test10358.hs:6:16: error: Not in scope: ‘v’
Test10358.hs:7:12: error: Not in scope: ‘d’
......@@ -11,7 +11,7 @@
(AK Test10358.hs:1:1 AnnWhere = [Test10358.hs:2:18-22])
(AK Test10358.hs:(4,1)-(8,6) AnnEqual = [Test10358.hs:4:13])
(AK Test10358.hs:(4,1)-(8,6) AnnEqual = [Test10358.hs:4:15])
(AK Test10358.hs:(4,1)-(8,6) AnnFunId = [Test10358.hs:4:1-7])
......
Test10399.hs:7:27: error:
Test10399.hs:10:27: error:
Not in scope: type constructor or class ‘MPISecret’
Test10399.hs:9:10: error: Not in scope: ‘mkBila’
Test10399.hs:12:10: error: Not in scope: ‘mkBila’
Test10399.hs:9:24: error: Illegal tuple section: use TupleSections
Test10399.hs:12:39: error: Not in scope: ‘P.base’
Test10399.hs:9:39: error: Not in scope: ‘P.base
Test10399.hs:12:50: error: Not in scope: ‘P.pos
Test10399.hs:9:50: error: Not in scope: ‘P.pos’
Test10399.hs:9:60: error: Not in scope: ‘P.form’
Test10399.hs:12:60: error: Not in scope: ‘P.form’
---Problems---------------------
[
(AK Test10399.hs:(13,27)-(14,69) AnnCloseP = [Test10399.hs:14:69])
(AK Test10399.hs:(16,27)-(17,69) AnnCloseP = [Test10399.hs:17:69])
(AK Test10399.hs:(13,27)-(14,69) AnnOpenP = [Test10399.hs:13:27])
(AK Test10399.hs:(16,27)-(17,69) AnnOpenP = [Test10399.hs:16:27])
]
---Problems'--------------------
[]
--------------------------------
[
(AK Test10399.hs:1:1 AnnModule = [Test10399.hs:5:1-6])
(AK Test10399.hs:1:1 AnnModule = [Test10399.hs:8:1-6])
(AK Test10399.hs:1:1 AnnWhere = [Test10399.hs:5:18-22])
(AK Test10399.hs:1:1 AnnWhere = [Test10399.hs:8:18-22])
(AK Test10399.hs:7:1-35 AnnEqual = [Test10399.hs:7:10])
(AK Test10399.hs:10:1-35 AnnEqual = [Test10399.hs:10:10])
(AK Test10399.hs:7:1-35 AnnSemi = [Test10399.hs:9:1])
(AK Test10399.hs:10:1-35 AnnSemi = [Test10399.hs:12:1])
(AK Test10399.hs:7:1-35 AnnType = [Test10399.hs:7:1-4])
(AK Test10399.hs:10:1-35 AnnType = [Test10399.hs:10:1-4])
(AK Test10399.hs:7:12-35 AnnDcolon = [Test10399.hs:7:24-25])
(AK Test10399.hs:10:12-35 AnnDcolon = [Test10399.hs:10:24-25])
(AK Test10399.hs:7:12-35 AnnVal = [Test10399.hs:7:12-22])
(AK Test10399.hs:10:12-35 AnnVal = [Test10399.hs:10:12-22])
(AK Test10399.hs:9:1-66 AnnEqual = [Test10399.hs:9:8])
(AK Test10399.hs:12:1-66 AnnEqual = [Test10399.hs:12:8])
(AK Test10399.hs:9:1-66 AnnFunId = [Test10399.hs:9:1-6])
(AK Test10399.hs:12:1-66 AnnFunId = [Test10399.hs:12:1-6])
(AK Test10399.hs:9:1-66 AnnSemi = [Test10399.hs:11:1])
(AK Test10399.hs:12:1-66 AnnSemi = [Test10399.hs:14:1])
(AK Test10399.hs:9:10-66 AnnVal = [Test10399.hs:9:17])
(AK Test10399.hs:12:10-66 AnnVal = [Test10399.hs:12:17])
(AK Test10399.hs:9:23-66 AnnCloseP = [Test10399.hs:9:66])
(AK Test10399.hs:12:23-66 AnnCloseP = [Test10399.hs:12:66])
(AK Test10399.hs:9:23-66 AnnOpenP = [Test10399.hs:9:23])
(AK Test10399.hs:12:23-66 AnnOpenP = [Test10399.hs:12:23])
(AK Test10399.hs:9:24-33 AnnCloseP = [Test10399.hs:9:33])
(AK Test10399.hs:12:24-33 AnnCloseP = [Test10399.hs:12:33])
(AK Test10399.hs:9:24-33 AnnOpenP = [Test10399.hs:9:24])
(AK Test10399.hs:12:24-33 AnnOpenP = [Test10399.hs:12:24])
(AK Test10399.hs:9:24-44 AnnVal = [Test10399.hs:9:35-37])
(AK Test10399.hs:12:24-44 AnnVal = [Test10399.hs:12:35-37])
(AK Test10399.hs:9:24-54 AnnVal = [Test10399.hs:9:46-48])
(AK Test10399.hs:12:24-54 AnnVal = [Test10399.hs:12:46-48])
(AK Test10399.hs:9:24-65 AnnVal = [Test10399.hs:9:56-58])
(AK Test10399.hs:12:24-65 AnnVal = [Test10399.hs:12:56-58])
(AK Test10399.hs:9:25 AnnComma = [Test10399.hs:9:25])
(AK Test10399.hs:12:25 AnnComma = [Test10399.hs:12:25])