check-api-annotations utility loads by filename
authorAlan Zimmerman <alan.zimm@gmail.com>
Sun, 10 Jul 2016 19:38:01 +0000 (21:38 +0200)
committerAlan Zimmerman <alan.zimm@gmail.com>
Sun, 10 Jul 2016 19:38:01 +0000 (21:38 +0200)
Previously it loaded by modulename, which prevented loading files with a
Main module.

testsuite/tests/ghc-api/annotations/.gitignore
testsuite/tests/ghc-api/annotations/Makefile
testsuite/tests/ghc-api/annotations/all.T
testsuite/tests/ghc-api/annotations/load-main.hs [new file with mode: 0644]
testsuite/tests/ghc-api/annotations/load-main.stdout [new file with mode: 0644]
utils/check-api-annotations/Main.hs

index 045cd40..c557c66 100644 (file)
@@ -29,7 +29,7 @@ comments:
 
 .PHONY: exampleTest
 exampleTest:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" AnnotationTuple
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" AnnotationTuple.hs
 
 .PHONY: listcomps
 listcomps:
@@ -39,64 +39,64 @@ listcomps:
 
 .PHONY: T10358
 T10358:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10358.hs
 
 .PHONY: T10396
 T10396:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10396
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10396.hs
 
 .PHONY: T10255
 T10255:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10255
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10255.hs
 
 .PHONY: T10357
 T10357:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10357
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10357.hs
 
 .PHONY: T10268
 T10268:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10268
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10268.hs
 
 .PHONY: T10280
 T10280:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10280
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10280.hs
 
 .PHONY: T10269
 T10269:
        # Ignore result code, we have an unattached (superfluous) AnnVal
-       - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10269
+       - $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10269.hs
 
 .PHONY: T10312
 T10312:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10312
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10312.hs
 
 .PHONY: T10307
 T10307:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10307
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10307.hs
 
 .PHONY: T10309
 T10309:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10309
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10309.hs
 
 .PHONY: boolFormula
 boolFormula:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" TestBoolFormula
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" TestBoolFormula.hs
 
 .PHONY: T10278
 T10278:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10278
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10278.hs
 
 .PHONY: T10354
 T10354:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10354
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10354.hs
 
 .PHONY: T10399
 T10399:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10399
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10399.hs
 
 .PHONY: bundle-export
 bundle-export:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" BundleExport
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" BundleExport.hs
 
 .PHONY: T10313
 T10313:
@@ -106,22 +106,26 @@ T10313:
 
 .PHONY: T11018
 T11018:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test11018
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test11018.hs
 
 .PHONY: T10276
 T10276:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10276
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test10276.hs
 
 .PHONY: T11321
 T11321:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test11321
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test11321.hs
 
 .PHONY: T11332
 T11332:
-       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test11332
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test11332.hs
 
 .PHONY: T11430
 T11430:
        rm -f t11430.o t11430.hi t11430
        '$(TEST_HC)' $(TEST_HC_OPTS) --make -v0 -package ghc t11430
        ./t11430 "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" Test11430
+
+.PHONY: load-main
+load-main:
+       $(CHECK_API_ANNOTATIONS) "`'$(TEST_HC)' $(TEST_HC_OPTS) --print-libdir | tr -d '\r'`" load-main.hs
index 64f69e2..c14153d 100644 (file)
@@ -24,3 +24,4 @@ test('T10276',      normal, run_command, ['$MAKE -s --no-print-directory T10276'
 test('T11321',      normal, run_command, ['$MAKE -s --no-print-directory T11321'])
 test('T11332',      normal, run_command, ['$MAKE -s --no-print-directory T11332'])
 test('T11430',      normal, run_command, ['$MAKE -s --no-print-directory T11430'])
+test('load-main',   normal, run_command, ['$MAKE -s --no-print-directory load-main'])
diff --git a/testsuite/tests/ghc-api/annotations/load-main.hs b/testsuite/tests/ghc-api/annotations/load-main.hs
new file mode 100644 (file)
index 0000000..4628a42
--- /dev/null
@@ -0,0 +1,4 @@
+module Main where
+
+-- Testing that check-api-annotations can load a main module file
+main = putStrLn "hello"
diff --git a/testsuite/tests/ghc-api/annotations/load-main.stdout b/testsuite/tests/ghc-api/annotations/load-main.stdout
new file mode 100644 (file)
index 0000000..b12cec2
--- /dev/null
@@ -0,0 +1,14 @@
+---Problems (should be empty list)---
+[]
+---Annotations-----------------------
+-- SrcSpan the annotation is attached to, AnnKeywordId,
+--    list of locations the keyword item appears in
+[
+((load-main.hs:1:1,AnnModule), [load-main.hs:1:1-6]),
+((load-main.hs:1:1,AnnWhere), [load-main.hs:1:13-17]),
+((load-main.hs:4:1-23,AnnEqual), [load-main.hs:4:6]),
+((load-main.hs:4:1-23,AnnFunId), [load-main.hs:4:1-4]),
+((load-main.hs:4:1-23,AnnSemi), [load-main.hs:5:1]),
+((<no location info>,AnnEofPos), [load-main.hs:5:1])
+]
+
index 20e6aa0..1d57742 100644 (file)
@@ -20,15 +20,23 @@ main = do
 
 testOneFile :: FilePath -> String -> IO ()
 testOneFile libdir fileName = do
+       let modByFile m =
+             case ml_hs_file $ ms_location m of
+               Nothing -> False
+               Just fn -> fn == fileName
        ((anns,_cs),p) <- runGhc (Just libdir) $ do
                         dflags <- getSessionDynFlags
                         _ <- setSessionDynFlags dflags
-                        let mn =mkModuleName fileName
-                        addTarget Target { targetId = TargetModule mn
+                        addTarget Target { targetId = TargetFile fileName Nothing
                                          , targetAllowObjCode = True
                                          , targetContents = Nothing }
                         _ <- load LoadAllTargets
-                        modSum <- getModSummary mn
+                        graph <- getModuleGraph
+                        let
+                          modSum = case filter modByFile graph of
+                                    [x] -> x
+                                    xs -> error $ "Can't find module, got:"
+                                             ++ show (map (ml_hs_file . ms_location) xs)
                         p <- parseModule modSum
                         return (pm_annotations p,p)