Skip to content

Commit

Permalink
Mosts tests now pass
Browse files Browse the repository at this point in the history
The remaining tests that fail are due to what appears to be a ghc bug.

[17:19]  <edsko> dcoutts: it does seem that ghc remembers what filenames correspond to which modules though
[17:19]  <edsko> when I update one and give it a different module name it suddenly starts to complain
[17:19]  <dcoutts> edsko: you mean, if you edit a file, change its module name and reload
[17:19]  <edsko> uh
[17:20]  <edsko> 'reload' -- not sur eyou can do that with ghc or ghci
[17:20]  <edsko> but yes
[17:20]  <edsko> with an ide-session
[17:20]  <edsko> I load all of cabal
[17:20]  <edsko> with the paths I mention above
[17:20]  <edsko> and that all works fine
[17:20]  <dcoutts> 'k
[17:20]  <edsko> then one of the unit tests replaces the contents of one of those files
[17:20]  <edsko> with "a = unknownX"
[17:20]  <edsko> and I get
[17:20]  <edsko> Unexpected source errors: SourceError {errorKind = KindError, errorSpan = test/Cabal/Distribution/Compat/CopyFile.hs@1:1-1:1, errorMsg = "File name does not match module name:\nSaw: `Main'\nExpected: `Distribution.Compat.CopyFile'\n"}
[17:21]  <edsko> that doesn't quite fit your description above, does it?
[17:21]  <dcoutts> no, indeed
[17:21]  <dcoutts> and if you started from scratch with those file contents, I expect you'd get a different error
[17:21]  <edsko> because if it rescans all of the files, it might regard this one as "Main" and then simply would be unable to find Distribution.Compat.CopyFile
[17:22]  <dcoutts> namely that it fails to find the module (the one in the file that you edited)
[17:22]  <dcoutts> edsko: indeed
[17:22]  <edsko> right
[17:22]  <edsko> *snap :)
[17:22]  <edsko> or don't british kids say that? :)
[17:22]  <dcoutts> edsko: so I would classify this as a ghc quirk, it's caching the modulename -> filename mapping
[17:22]  <edsko> yeah, seems so
[17:22]  <dcoutts> technically that should be classified as a bug
[17:23]  <edsko> ok
[17:23]  <edsko> so I shouldn't worry about it in my unit test? just ignore this one?
[17:23]  <dcoutts> not unless we find it's a problem in practice for the ide
[17:23]  <edsko> me wonders if we can query's filename-module name mapping
[17:23]  <dcoutts> we should file a ticket though, and note it in our internal list of ghc issues
  • Loading branch information
edsko committed Mar 7, 2013
1 parent 0a142c9 commit f2e5603
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions test/ghc-errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ multipleTests =
assertNoErrors msgs
-- Overwrite one of the copied files.
(_, ms) <- getModules session
let update = loadModule (head ms) "a = unknownX"
-- let update = loadModule (head ms) "a = unknownX"
let update = updateModule (head ms) $ BSLC.pack "a = unknownX"
updateSessionD session update 1 -- at most 1 recompiled
msgs2 <- getSourceErrors session
-- Error reported due to the overwrite.
case msgs2 of
[SourceError _ _ "Not in scope: `unknownX'"] -> return ()
_ -> assertFailure "Unexpected source errors"
_ -> assertFailure $ "Unexpected source errors: " ++ show3errors msgs2
)
, ( "Overwrite with the same module name in all files"
, \session originalUpdate lm -> do
Expand All @@ -114,7 +115,7 @@ multipleTests =
[SourceError _ (TextSpan _) s ] ->
assertBool "Wrong error message"
$ isPrefixOf "module `main:Wrong' is defined in multiple files" s
_ -> assertFailure "Unexpected source errors"
_ -> assertFailure $ "Unexpected source errors: " ++ show3errors msgs
else assertNoErrors msgs
)
, ( "Overwrite modules many times"
Expand All @@ -133,12 +134,12 @@ multipleTests =
msgs1 <- getSourceErrors session
case msgs1 of
[SourceError _ _ "Not in scope: `unknownX'"] -> return ()
_ -> assertFailure "Unexpected source errors"
_ -> assertFailure $ "Unexpected source errors: " ++ show3errors msgs1
updateSessionD session mempty 1 -- was an error, so trying again
msgs2 <- getSourceErrors session
case msgs2 of
[SourceError _ _ "Not in scope: `unknownX'"] -> return ()
_ -> assertFailure "Unexpected source errors"
_ -> assertFailure $ "Unexpected source errors: " ++ show3errors msgs2
-- Overwrite all files, many times, with correct code eventually.
let upd m = loadModule m "x = unknownX"
<> loadModule m "y = 2"
Expand All @@ -152,7 +153,7 @@ multipleTests =
msgs5 <- getSourceErrors session
case msgs5 of
[SourceError _ _ "Not in scope: `unknownX'"] -> return ()
_ -> assertFailure "Unexpected source errors"
_ -> assertFailure $ "Unexpected source errors: " ++ show3errors msgs5
assertRaises "runStmt session Main main"
(== userError "Cannot run before the code is generated.")
(runStmt session "Main" "main")
Expand Down Expand Up @@ -329,8 +330,8 @@ syntheticTests =
$ isSuffixOf "A.hs" fn
assertBool "Wrong error message"
$ isPrefixOf "No instance for (Num (IO ()))" s
_ -> assertFailure "Unexpected source errors"
)
_ -> assertFailure $ "Unexpected source errors: " ++ show3errors msgs
)
, ( "Compile a project: A depends on B, error in B"
, withConfiguredSession defOpts $ \session -> do
loadModulesFrom session "test/ABerror"
Expand All @@ -341,7 +342,7 @@ syntheticTests =
$ isSuffixOf "B.hs" fn
assertBool "Wrong error message"
$ isPrefixOf "No instance for (Num (IO ()))" s
_ -> assertFailure "Unexpected source errors"
_ -> assertFailure $ "Unexpected source errors: " ++ show3errors msgs
)
, ( "Reject a program requiring -XNamedFieldPuns, then set the option"
, let packageOpts = [ "-hide-all-packages"
Expand Down Expand Up @@ -451,14 +452,14 @@ syntheticTests =
msgs <- getSourceErrors session
case msgs of
[SourceError _ _ "parse error on input `very'\n"] -> return ()
_ -> assertFailure "Unexpected source errors"
_ -> assertFailure $ "Unexpected source errors: " ++ show3errors msgs
let update2 = updateModule "M.hs"
(BSLC.pack "module M.1.2.3.8.T where")
updateSessionD session update2 1
msgs2 <- getSourceErrors session
case msgs2 of
[SourceError _ _ "parse error on input `.'\n"] -> return ()
_ -> assertFailure "Unexpected source errors"
_ -> assertFailure $ "Unexpected source errors: " ++ show3errors msgs2
)
, ( "Interrupt runStmt (after 1 sec)"
, withConfiguredSession defOpts $ \session -> do
Expand Down Expand Up @@ -845,7 +846,7 @@ syntheticTests =
case msgs of
-- We expect a 'top-level identifier without type' warning
[SourceError KindWarning _ _] -> return ()
_ -> assertFailure "Unexpected source errors"
_ -> assertFailure $ "Unexpected source errors: " ++ show3errors msgs
_runActions <- runStmt session "M" "loop"
msgs' <- getSourceErrors session
assertEqual "Running code does not affect getSourceErrors" msgs msgs'
Expand Down Expand Up @@ -1604,6 +1605,7 @@ updateSessionD session update i = do

loadModule :: FilePath -> String -> IdeSessionUpdate
loadModule file contents =
-- This is a hack: construct a module name from a filename
let mod = takeBaseName file
in updateModule file . BSLC.pack
$ "module " ++ mod ++ " where\n" ++ contents
Expand Down

0 comments on commit f2e5603

Please sign in to comment.