
Hannes Siebenhandl pushed to branch wip/fendor/ghci-multiple-home-units at Glasgow Haskell Compiler / GHC Commits: 3e0b1649 by fendor at 2025-04-16T09:24:17+02:00 Add testcases for GHCi multiple home units Adds the following testcases: * Evaluate code with a single home unit using 'initMulti' initialisation logic * More complicated testcase with multiple home units, testing reload logic and code evaluation. - - - - - 20 changed files: - testsuite/driver/testlib.py - + testsuite/tests/ghci/prog-mhu001/Makefile - + testsuite/tests/ghci/prog-mhu001/e/E.hs - + testsuite/tests/ghci/prog-mhu001/prog-mhu001.T - + testsuite/tests/ghci/prog-mhu001/prog-mhu001.script - + testsuite/tests/ghci/prog-mhu001/prog-mhu001.stdout - + testsuite/tests/ghci/prog-mhu001/unitE - + testsuite/tests/ghci/prog-mhu002/Makefile - + testsuite/tests/ghci/prog-mhu002/a/A.hs - + testsuite/tests/ghci/prog-mhu002/b/B.hs - + testsuite/tests/ghci/prog-mhu002/c/C.hs - + testsuite/tests/ghci/prog-mhu002/d/Main.hs - + testsuite/tests/ghci/prog-mhu002/prog-mhu002.T - + testsuite/tests/ghci/prog-mhu002/prog-mhu002.script - + testsuite/tests/ghci/prog-mhu002/prog-mhu002.stderr - + testsuite/tests/ghci/prog-mhu002/prog-mhu002.stdout - + testsuite/tests/ghci/prog-mhu002/unitA - + testsuite/tests/ghci/prog-mhu002/unitB - + testsuite/tests/ghci/prog-mhu002/unitC - + testsuite/tests/ghci/prog-mhu002/unitD Changes: ===================================== testsuite/driver/testlib.py ===================================== @@ -1543,7 +1543,7 @@ async def test_common_work(name: TestName, opts, all_ways = config.compile_ways elif func in [compile_and_run, multi_compile_and_run, multimod_compile_and_run]: all_ways = config.run_ways - elif func == ghci_script: + elif func == ghci_script or func == ghci_multiunit_script: if config.have_interp: all_ways = [WayName('ghci'), WayName('ghci-opt')] else: @@ -1874,6 +1874,20 @@ async def ghci_script( name, way, script): getTestOpts().stdin = script return await simple_run( name, way, cmd, getTestOpts().extra_run_opts ) +async def ghci_multiunit_script( name, way, units, script): + flags = ' '.join(get_compiler_flags()) + way_flags = ' '.join(config.way_flags[way]) + unit_flags = ' '.join(['-unit @%s' % unit for unit in units]) + + # We pass HC and HC_OPTS as environment variables, so that the + # script can invoke the correct compiler by using ':! $HC $HC_OPTS' + cmd = ('HC={{compiler}} HC_OPTS="{flags}" {{compiler}} {way_flags} {flags} {units}' + ).format(flags=flags, way_flags=way_flags, units=unit_flags) + # NB: put way_flags before flags so that flags in all.T can override others + + getTestOpts().stdin = script + return await simple_run( name, way, cmd, getTestOpts().extra_run_opts ) + # ----------------------------------------------------------------------------- # Compile-only tests ===================================== testsuite/tests/ghci/prog-mhu001/Makefile ===================================== @@ -0,0 +1,3 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk ===================================== testsuite/tests/ghci/prog-mhu001/e/E.hs ===================================== @@ -0,0 +1,11 @@ +module E where + +foo = 4 + +main = putStrLn "Hello, World" + +class Test a where + test :: a -> String + +instance Test Int where + test = show ===================================== testsuite/tests/ghci/prog-mhu001/prog-mhu001.T ===================================== @@ -0,0 +1,5 @@ +test('prog-mhu001', + [extra_files(['../shell.hs', 'e/', 'unitE', 'prog-mhu001.script']), + cmd_prefix('ghciWayFlags=' + config.ghci_way_flags), + req_interp], + ghci_multiunit_script, [['unitE'], 'prog-mhu001.script']) ===================================== testsuite/tests/ghci/prog-mhu001/prog-mhu001.script ===================================== @@ -0,0 +1,5 @@ +:m + E +foo +test (5 :: Int) +main +:main ===================================== testsuite/tests/ghci/prog-mhu001/prog-mhu001.stdout ===================================== @@ -0,0 +1,4 @@ +4 +"5" +Hello, World +Hello, World ===================================== testsuite/tests/ghci/prog-mhu001/unitE ===================================== @@ -0,0 +1,5 @@ +-i +-ie/ +E +-this-unit-id e-0.0.0 +-package base ===================================== testsuite/tests/ghci/prog-mhu002/Makefile ===================================== @@ -0,0 +1,3 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk ===================================== testsuite/tests/ghci/prog-mhu002/a/A.hs ===================================== @@ -0,0 +1,12 @@ +module A where + +import B + +baz = foo + foobar + +foobar = 18 + +data A = A deriving (Show) + +instance Test A where + test = show ===================================== testsuite/tests/ghci/prog-mhu002/b/B.hs ===================================== @@ -0,0 +1,9 @@ +module B where + +foo = 50 + +class Test a where + test :: a -> String + +instance Test Int where + test = show ===================================== testsuite/tests/ghci/prog-mhu002/c/C.hs ===================================== @@ -0,0 +1,4 @@ +module C (bar) where + +bar = 3 +foo = 4 ===================================== testsuite/tests/ghci/prog-mhu002/d/Main.hs ===================================== @@ -0,0 +1,5 @@ +module Main where + +main = putStrLn "Hello, World" + +test = 5 ===================================== testsuite/tests/ghci/prog-mhu002/prog-mhu002.T ===================================== @@ -0,0 +1,8 @@ +test('prog-mhu002', + [extra_files(['../shell.hs', 'a/', 'b/', 'c/', 'd/' + , 'unitA', 'unitB', 'unitC', 'unitD', + ]), + cmd_prefix('ghciWayFlags=' + config.ghci_way_flags), + unless(opsys('mingw32') or not config.have_RTS_linker, extra_ways(['ghci-ext'])), + req_interp], + ghci_multiunit_script, [['unitA', 'unitB', 'unitC', 'unitD'], 'prog-mhu002.script']) ===================================== testsuite/tests/ghci/prog-mhu002/prog-mhu002.script ===================================== @@ -0,0 +1,12 @@ +:m + A B C Main +baz +foobar +:m - A B C Main +baz +foobar +:m + C +bar +foo +:m + Main +main + ===================================== testsuite/tests/ghci/prog-mhu002/prog-mhu002.stderr ===================================== @@ -0,0 +1,6 @@ +<interactive>:5:1: error: [GHC-88464] Variable not in scope: baz + +<interactive>:6:1: error: [GHC-88464] Variable not in scope: foobar + +<interactive>:9:1: error: [GHC-88464] Variable not in scope: foo + ===================================== testsuite/tests/ghci/prog-mhu002/prog-mhu002.stdout ===================================== @@ -0,0 +1,4 @@ +68 +18 +3 +Hello, World ===================================== testsuite/tests/ghci/prog-mhu002/unitA ===================================== @@ -0,0 +1,6 @@ +-i +-ia/ +A +-this-unit-id a-0.0.0 +-package base +-package-id b-0.0.0 ===================================== testsuite/tests/ghci/prog-mhu002/unitB ===================================== @@ -0,0 +1,5 @@ +-i +-ib/ +B +-this-unit-id b-0.0.0 +-package base ===================================== testsuite/tests/ghci/prog-mhu002/unitC ===================================== @@ -0,0 +1,6 @@ +-i +-ic/ +C +-this-unit-id c-0.0.0 +-package base +-package-id b-0.0.0 ===================================== testsuite/tests/ghci/prog-mhu002/unitD ===================================== @@ -0,0 +1,5 @@ +-i +-id/ +d/Main.hs +-this-unit-id d-0.0.0 +-package base View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3e0b1649b2ca60207aa57e144af655cc... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/3e0b1649b2ca60207aa57e144af655cc... You're receiving this email because of your account on gitlab.haskell.org.