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 | |
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')
-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 | ||||
-rw-r--r-- | testsuite/tests/ghci/scripts/T10508.script | 21 | ||||
-rw-r--r-- | testsuite/tests/ghci/scripts/T10508.stderr | 8 | ||||
-rw-r--r-- | testsuite/tests/ghci/scripts/T10508.stdout | 6 | ||||
-rwxr-xr-x | testsuite/tests/ghci/scripts/all.T | 1 |
8 files changed, 81 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']) diff --git a/testsuite/tests/ghci/scripts/T10508.script b/testsuite/tests/ghci/scripts/T10508.script new file mode 100644 index 0000000000..5ac770060b --- /dev/null +++ b/testsuite/tests/ghci/scripts/T10508.script @@ -0,0 +1,21 @@ +-- :cmd accepts an expr of type 'IO String' +let cmd = return "0" +:cmd cmd + +-- works with multiline mode, handles indention correctly +:{ +:cmd return $ unlines + [ "1" + , "2" + ] +:} + +-- it should work even 'IO' or 'String' is not in scope +import Prelude () +:cmd cmd + +-- or even when a different 'String' is in scope +import Prelude +type String = ShowS +:def macro \_ -> return id +:macro diff --git a/testsuite/tests/ghci/scripts/T10508.stderr b/testsuite/tests/ghci/scripts/T10508.stderr new file mode 100644 index 0000000000..c5aff2361c --- /dev/null +++ b/testsuite/tests/ghci/scripts/T10508.stderr @@ -0,0 +1,8 @@ + +<interactive>:1:15: + Couldn't match type ‘a0 -> a0’ with ‘[Char]’ + Expected type: Prelude.String + Actual type: a0 -> a0 + Probable cause: ‘id’ is applied to too few arguments + In the first argument of ‘return’, namely ‘id’ + In the expression: return id
\ No newline at end of file diff --git a/testsuite/tests/ghci/scripts/T10508.stdout b/testsuite/tests/ghci/scripts/T10508.stdout new file mode 100644 index 0000000000..c6c8d3a447 --- /dev/null +++ b/testsuite/tests/ghci/scripts/T10508.stdout @@ -0,0 +1,6 @@ +0 +1 +2 +0 +unknown command ':macro' +use :? for help. diff --git a/testsuite/tests/ghci/scripts/all.T b/testsuite/tests/ghci/scripts/all.T index df02add5b4..c2c75ecb94 100755 --- a/testsuite/tests/ghci/scripts/all.T +++ b/testsuite/tests/ghci/scripts/all.T @@ -221,3 +221,4 @@ test('T10110', normal, ghci_script, ['T10110.script']) test('T10322', normal, ghci_script, ['T10322.script']) test('T10466', normal, ghci_script, ['T10466.script']) test('T10501', normal, ghci_script, ['T10501.script']) +test('T10508', normal, ghci_script, ['T10508.script']) |