diff options
author | Simon Marlow <marlowsd@gmail.com> | 2015-06-12 13:15:18 +0100 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2015-06-12 13:15:18 +0100 |
commit | d20031d4c88b256cdae264cb05d9d850e973d956 (patch) | |
tree | 84af3e055d60d87058cfe48a7260e75859f9fefe /testsuite/tests/ghc-api | |
parent | c14bd01756ffaf3a0bf34c766cfc1d611dba0dc4 (diff) | |
download | haskell-d20031d4c88b256cdae264cb05d9d850e973d956.tar.gz |
Add parseExpr and compileParsedExpr and use them in GHC API and GHCi
Summary:
This commit brings following changes and fixes:
* Implement parseExpr and compileParsedExpr;
* Fix compileExpr and dynCompilerExpr, which returned `()` for empty expr;
* Fix :def and :cmd, which didn't work if `IO` or `String` is not in scope;
* Use GHCiMonad instead IO in :def and :cmd;
* Clean PrelInfo: delete dead comment and duplicate entries, add assertion.
See new tests for more details.
Test Plan: ./validate
Reviewers: austin, dterei, simonmar
Reviewed By: simonmar
Subscribers: thomie, bgamari
Differential Revision: https://phabricator.haskell.org/D974
GHC Trac Issues: #10508
Diffstat (limited to 'testsuite/tests/ghc-api')
-rw-r--r-- | testsuite/tests/ghc-api/T10508_api.hs | 32 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/T10508_api.stderr | 4 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/T10508_api.stdout | 3 | ||||
-rw-r--r-- | testsuite/tests/ghc-api/all.T | 7 |
4 files changed, 45 insertions, 1 deletions
diff --git a/testsuite/tests/ghc-api/T10508_api.hs b/testsuite/tests/ghc-api/T10508_api.hs new file mode 100644 index 0000000000..afe8e50e73 --- /dev/null +++ b/testsuite/tests/ghc-api/T10508_api.hs @@ -0,0 +1,32 @@ +module Main where + +import DynFlags +import GHC + +import Control.Monad (forM_) +import Control.Monad.IO.Class (liftIO) +import System.Environment (getArgs) + +main :: IO () +main = do + [libdir] <- getArgs + runGhc (Just libdir) $ do + dflags <- getSessionDynFlags + setSessionDynFlags $ dflags + `gopt_unset` Opt_ImplicitImportQualified + `xopt_unset` Opt_ImplicitPrelude + + forM_ exprs $ \expr -> + handleSourceError printException $ do + dyn <- dynCompileExpr expr + liftIO $ print dyn + where + exprs = + [ "" + , "(),()" + , "()" + , "\"test\"" + , unlines [ "[()]" + , " :: [()]" + ] + ] diff --git a/testsuite/tests/ghc-api/T10508_api.stderr b/testsuite/tests/ghc-api/T10508_api.stderr new file mode 100644 index 0000000000..29533435f3 --- /dev/null +++ b/testsuite/tests/ghc-api/T10508_api.stderr @@ -0,0 +1,4 @@ + +<no location info>: error: not an expression: ‘’ + +<interactive>:1:3: error: parse error on input ‘,’ diff --git a/testsuite/tests/ghc-api/T10508_api.stdout b/testsuite/tests/ghc-api/T10508_api.stdout new file mode 100644 index 0000000000..9a6eb4c38f --- /dev/null +++ b/testsuite/tests/ghc-api/T10508_api.stdout @@ -0,0 +1,3 @@ +<<()>> +<<[Char]>> +<<[()]>> diff --git a/testsuite/tests/ghc-api/all.T b/testsuite/tests/ghc-api/all.T index 11e8c422b6..c4783ea15d 100644 --- a/testsuite/tests/ghc-api/all.T +++ b/testsuite/tests/ghc-api/all.T @@ -8,4 +8,9 @@ test('T8639_api', normal, test('T8628', normal, run_command, ['$MAKE -s --no-print-directory T8628']) -test('T9595', extra_run_opts('"' + config.libdir + '"'), compile_and_run, ['-package ghc']) +test('T9595', extra_run_opts('"' + config.libdir + '"'), + compile_and_run, + ['-package ghc']) +test('T10508_api', extra_run_opts('"' + config.libdir + '"'), + compile_and_run, + ['-package ghc']) |