[Git][ghc/ghc][master] 3 commits: gitlab-ci: Lint testsuite for framework failures

Marge Bot gitlab at gitlab.haskell.org
Sat Jun 15 03:10:12 UTC 2019



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
503e830c by Ben Gamari at 2019-06-15T03:10:08Z
gitlab-ci: Lint testsuite for framework failures

This introduces a new lint job checking for framework failures and
listing broken tests.

- - - - -
b5ea9323 by Ben Gamari at 2019-06-15T03:10:08Z
lint: Only apply --interactive lint to testsuite .T files

- - - - -
5c97211c by Ben Gamari at 2019-06-15T03:10:08Z
gitlab-ci: Lint the linters

- - - - -


5 changed files:

- .gitlab-ci.yml
- .gitlab/linters/check-makefiles.py
- .gitlab/linters/linter.py
- testsuite/driver/runtests.py
- testsuite/mk/test.mk


Changes:

=====================================
.gitlab-ci.yml
=====================================
@@ -27,6 +27,7 @@ stages:
   - hackage    # head.hackage testing
   - deploy     # push documentation
 
+# N.B.Don't run on wip/ branches, instead on run on merge requests.
 .only-default: &only-default
   only:
     - master
@@ -70,10 +71,31 @@ ghc-linters:
     refs:
       - merge_requests
 
+lint-linters:
+  <<: *only-default
+  stage: lint
+  image: "registry.gitlab.haskell.org/ghc/ci-images/linters:$DOCKER_REV"
+  script:
+    - mypy .gitlab/linters/*.py
+  dependencies: []
+  tags:
+    - lint
+
+lint-testsuite:
+  <<: *only-default
+  stage: lint
+  image: "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb9:$DOCKER_REV"
+  script:
+    - make -Ctestsuite list_broken TEST_HC=ghc
+  dependencies: []
+  tags:
+    - lint
+
 # We allow the submodule checker to fail when run on merge requests (to
 # accomodate, e.g., haddock changes not yet upstream) but not on `master` or
 # Marge jobs.
 .lint-submods:
+  <<: *only-default
   stage: lint
   image: "registry.gitlab.haskell.org/ghc/ci-images/linters:$DOCKER_REV"
   script:
@@ -118,6 +140,7 @@ lint-submods-branch:
       - /ghc-[0-9]+\.[0-9]+/
 
 .lint-changelogs:
+  <<: *only-default
   stage: lint
   image: "registry.gitlab.haskell.org/ghc/ci-images/linters:$DOCKER_REV"
   dependencies: []


=====================================
.gitlab/linters/check-makefiles.py
=====================================
@@ -12,9 +12,10 @@ from linter import run_linters, RegexpLinter
 
 linters = [
     RegexpLinter(r'--interactive',
-                 message = "Warning: Use `$(TEST_HC_OPTS_INTERACTIVE)` instead of `--interactive -ignore-dot-ghci -v0`.",
-                 path_filter = lambda path: path == 'Makefile')
+                 message = "Warning: Use `$(TEST_HC_OPTS_INTERACTIVE)` instead of `--interactive -ignore-dot-ghci -v0`."
+                ).add_path_filter(lambda path: path.suffix == '.T')
 ]
 
 if __name__ == '__main__':
-    run_linters(linters, subdir='testsuite')
+    run_linters(linters,
+                subdir='testsuite')


=====================================
.gitlab/linters/linter.py
=====================================
@@ -7,10 +7,11 @@ import sys
 import re
 import textwrap
 import subprocess
-from typing import List, Optional
+from pathlib import Path
+from typing import List, Optional, Callable, Sequence
 from collections import namedtuple
 
-def lint_failure(file, line_no, line_content, message):
+def lint_failure(file, line_no: int, line_content: str, message: str):
     """ Print a lint failure message. """
     wrapper = textwrap.TextWrapper(initial_indent='  ',
                                    subsequent_indent='    ')
@@ -29,7 +30,7 @@ def lint_failure(file, line_no, line_content, message):
 
     print(textwrap.dedent(msg))
 
-def get_changed_files(base_commit, head_commit,
+def get_changed_files(base_commit: str, head_commit: str,
                       subdir: str = '.'):
     """ Get the files changed by the given range of commits. """
     cmd = ['git', 'diff', '--name-only',
@@ -46,12 +47,21 @@ class Linter(object):
     """
     def __init__(self):
         self.warnings = [] # type: List[Warning]
+        self.path_filters = [] # type: List[Callable[[Path], bool]]
 
     def add_warning(self, w: Warning):
         self.warnings.append(w)
 
-    def lint(self, path):
-        pass
+    def add_path_filter(self, f: Callable[[Path], bool]) -> "Linter":
+        self.path_filters.append(f)
+        return self
+
+    def do_lint(self, path: Path):
+        if all(f(path) for f in self.path_filters):
+            self.lint(path)
+
+    def lint(self, path: Path):
+        raise NotImplementedError
 
 class LineLinter(Linter):
     """
@@ -59,33 +69,32 @@ class LineLinter(Linter):
     the given line from a file and calls :func:`add_warning` for any lint
     issues found.
     """
-    def lint(self, path):
-        if os.path.isfile(path):
-            with open(path, 'r') as f:
+    def lint(self, path: Path):
+        if path.is_file():
+            with path.open('r') as f:
                 for line_no, line in enumerate(f):
                     self.lint_line(path, line_no+1, line)
 
-    def lint_line(self, path, line_no, line):
-        pass
+    def lint_line(self, path: Path, line_no: int, line: str):
+        raise NotImplementedError
 
 class RegexpLinter(LineLinter):
     """
     A :class:`RegexpLinter` produces the given warning message for
     all lines matching the given regular expression.
     """
-    def __init__(self, regex, message, path_filter=lambda path: True):
+    def __init__(self, regex: str, message: str):
         LineLinter.__init__(self)
         self.re = re.compile(regex)
         self.message = message
-        self.path_filter = path_filter
 
-    def lint_line(self, path, line_no, line):
-        if self.path_filter(path) and self.re.search(line):
+    def lint_line(self, path: Path, line_no: int, line: str):
+        if self.re.search(line):
             w = Warning(path=path, line_no=line_no, line_content=line[:-1],
                         message=self.message)
             self.add_warning(w)
 
-def run_linters(linters: List[Linter],
+def run_linters(linters: Sequence[Linter],
                 subdir: str = '.') -> None:
     import argparse
     parser = argparse.ArgumentParser()
@@ -97,7 +106,7 @@ def run_linters(linters: List[Linter],
         if path.startswith('.gitlab/linters'):
             continue
         for linter in linters:
-            linter.lint(path)
+            linter.do_lint(Path(path))
 
     warnings = [warning
                 for linter in linters


=====================================
testsuite/driver/runtests.py
=====================================
@@ -350,7 +350,7 @@ for name in config.only:
 if config.list_broken:
     print('')
     print('Broken tests:')
-    print(' '.join(map (lambda bdn: '#' + str(bdn[0]) + '(' + bdn[1] + '/' + bdn[2] + ')', brokens)))
+    print('\n  '.join(map (lambda bdn: '#' + str(bdn[0]) + '(' + bdn[1] + '/' + bdn[2] + ')', brokens)))
     print('')
 
     if t.framework_failures:


=====================================
testsuite/mk/test.mk
=====================================
@@ -81,7 +81,11 @@ endif
 
 RUNTEST_OPTS += -e "ghc_compiler_always_flags='$(TEST_HC_OPTS)'"
 
-RUNTEST_OPTS += -e config.compiler_debugged=$(GhcDebugged)
+ifeq "$(GhcDebugged)" "YES"
+RUNTEST_OPTS += -e "config.compiler_debugged=True"
+else
+RUNTEST_OPTS += -e "config.compiler_debugged=False"
+endif
 
 ifeq "$(GhcWithNativeCodeGen)" "YES"
 RUNTEST_OPTS += -e ghc_with_native_codegen=True



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/5279dda861f6a5cc804be88dc5f0ff2442660149...5c97211cf21d2eb99db1a5cf473a630ffe245064

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/5279dda861f6a5cc804be88dc5f0ff2442660149...5c97211cf21d2eb99db1a5cf473a630ffe245064
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/20190614/cf9faf85/attachment-0001.html>


More information about the ghc-commits mailing list