[Git][ghc/ghc][master] Add warn_and_run test kind
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Sat Jul 8 09:08:30 UTC 2023
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
a9bc20cb by Oleg Grenrus at 2023-07-08T05:07:31-04:00
Add warn_and_run test kind
This is a compile_and_run variant which also captures the GHC's
stderr. The warn_and_run name is best I can come up with,
as compile_and_run is taken.
This is useful specifically for testing warnings. We want to test that
when warning triggers, and it's not a false positive, i.e. that the
runtime behaviour is indeed "incorrect".
As an example a single test is altered to use warn_and_run
- - - - -
5 changed files:
- testsuite/driver/testlib.py
- testsuite/tests/rename/should_compile/all.T
- testsuite/tests/rename/should_compile/rn039.stderr → testsuite/tests/rename/should_compile/rn039.ghc.stderr
- testsuite/tests/rename/should_compile/rn039.hs
- + testsuite/tests/rename/should_compile/rn039.stdout
Changes:
=====================================
testsuite/driver/testlib.py
=====================================
@@ -1653,7 +1653,8 @@ async def compile_and_run__(name: TestName,
top_mod: Path,
extra_mods: List[str],
extra_hc_opts: str,
- backpack: bool=False
+ backpack: bool=False,
+ compile_stderr: bool=False
) -> PassFail:
# print 'Compile and run, extra args = ', extra_hc_opts
@@ -1670,6 +1671,23 @@ async def compile_and_run__(name: TestName,
if badResult(result):
return result
+ if compile_stderr:
+ expected_stderr_file = find_expected_file(name, 'ghc.stderr')
+ actual_stderr_file = add_suffix(name, 'comp.stderr')
+ diff_file_name = in_testdir(add_suffix(name, 'comp.diff'))
+
+ if not await compare_outputs(way, 'stderr',
+ join_normalisers(getTestOpts().extra_errmsg_normaliser,
+ normalise_errmsg),
+ expected_stderr_file, actual_stderr_file,
+ diff_file=diff_file_name,
+ whitespace_normaliser=getattr(getTestOpts(),
+ "whitespace_normaliser",
+ normalise_whitespace)):
+ stderr = diff_file_name.read_text()
+ diff_file_name.unlink()
+ return failBecause('ghc.stderr mismatch', stderr=stderr)
+#
cmd = './' + name + exe_extension()
# we don't check the compiler's stderr for a compile-and-run test
@@ -1684,6 +1702,9 @@ async def multimod_compile_and_run( name, way, top_mod, extra_hc_opts ):
async def multi_compile_and_run( name, way, top_mod, extra_mods, extra_hc_opts ):
return await compile_and_run__( name, way, top_mod, extra_mods, extra_hc_opts)
+async def warn_and_run( name, way, extra_hc_opts ):
+ return await compile_and_run__( name, way, None, [], extra_hc_opts, compile_stderr = True)
+
def stats( name, way, stats_file ):
opts = getTestOpts()
return check_stats(name, way, in_testdir(stats_file), opts.stats_range_fields)
=====================================
testsuite/tests/rename/should_compile/all.T
=====================================
@@ -31,7 +31,7 @@ test('rn037', normal, compile, [''])
# Missing:
# test('rn038', normal, compile, [''])
-test('rn039', normal, compile, [''])
+test('rn039', normal, warn_and_run, [''])
test('rn040', normal, compile, ['-fwarn-unused-binds -fwarn-unused-matches'])
test('rn041', normal, compile, [''])
test('rn042', [extra_files(['Rn042_A.hs'])], multimod_compile, ['rn042', '-v0'])
=====================================
testsuite/tests/rename/should_compile/rn039.stderr → testsuite/tests/rename/should_compile/rn039.ghc.stderr
=====================================
@@ -1,5 +1,7 @@
+[1 of 2] Compiling Main ( rn039.hs, rn039.o )
-rn039.hs:6:16: warning: [GHC-63397] [-Wname-shadowing (in -Wall)]
+rn039.hs:6:20: warning: [GHC-63397] [-Wname-shadowing (in -Wall)]
This binding for ‘-’ shadows the existing binding
- imported from ‘Prelude’ at rn039.hs:2:8-20
+ imported from ‘Prelude’ at rn039.hs:2:8-11
(and originally defined in ‘GHC.Num’)
+[2 of 2] Linking rn039
=====================================
testsuite/tests/rename/should_compile/rn039.hs
=====================================
@@ -1,6 +1,9 @@
{-# OPTIONS -fwarn-name-shadowing #-}
-module ShouldCompile where
+module Main (main) where
-- !!! test shadowing of a global name
-g = 42 where f -1 = -1 -- shadows (-), probably by accident!
+g = 42 - 1 where f -1 = -1 -- shadows (-), probably by accident!
+
+main :: IO ()
+main = print g
=====================================
testsuite/tests/rename/should_compile/rn039.stdout
=====================================
@@ -0,0 +1 @@
+-1
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a9bc20cb3d772671317caf0a642d574f34493d23
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a9bc20cb3d772671317caf0a642d574f34493d23
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230708/4f624e02/attachment-0001.html>
More information about the ghc-commits
mailing list