summaryrefslogtreecommitdiff
path: root/testsuite/tests
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2022-01-31 19:08:01 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2022-02-03 15:21:46 +0000
commitd29412537467cc4617da5e8859554e9ccd1924b7 (patch)
tree1595803ce81a7b2bcefcc8697fffe7a449452591 /testsuite/tests
parente59446c6a682587c21424e5830f305ab2f8f8cfa (diff)
downloadhaskell-wip/lint-testsuite.tar.gz
testsuite: Run testsuite dependency calculation before GHC is builtwip/lint-testsuite
The main motivation for this patch is to allow tests to be added to the testsuite which test things about the source tree without needing to build GHC. In particular the notes linter can easily start failing and by integrating it into the testsuite the process of observing these changes is caught by normal validation procedures rather than having to run the linter specially. With this patch I can run ``` ./hadrian/build test --flavour=devel2 --only="uniques" ``` In a clean tree to run the checkUniques linter without having to build GHC. Fixes #21029
Diffstat (limited to 'testsuite/tests')
-rw-r--r--testsuite/tests/linters/Makefile4
-rw-r--r--testsuite/tests/linters/all.T1
-rwxr-xr-xtestsuite/tests/linters/checkUniques/check-uniques.py49
3 files changed, 54 insertions, 0 deletions
diff --git a/testsuite/tests/linters/Makefile b/testsuite/tests/linters/Makefile
new file mode 100644
index 0000000000..aeaef050e1
--- /dev/null
+++ b/testsuite/tests/linters/Makefile
@@ -0,0 +1,4 @@
+TOP=../..
+
+uniques:
+ python3 checkUniques/check-uniques.py $(TOP)/..
diff --git a/testsuite/tests/linters/all.T b/testsuite/tests/linters/all.T
new file mode 100644
index 0000000000..b4cc4bb8b3
--- /dev/null
+++ b/testsuite/tests/linters/all.T
@@ -0,0 +1 @@
+test('uniques', [no_deps, extra_files(["checkUniques"])], makefile_test, ['uniques'])
diff --git a/testsuite/tests/linters/checkUniques/check-uniques.py b/testsuite/tests/linters/checkUniques/check-uniques.py
new file mode 100755
index 0000000000..dd5891b0d8
--- /dev/null
+++ b/testsuite/tests/linters/checkUniques/check-uniques.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+import os.path
+import sys
+import re
+import glob
+import io
+from collections import defaultdict
+
+# keyed on unique type, values are lists of (unique, name) pairs
+def find_uniques(source_files):
+ uniques = defaultdict(lambda: defaultdict(lambda: set()))
+ unique_re = re.compile(r"([\w\d]+)\s*=\s*mk([\w\d']+)Unique\s+(\d+)")
+ for f in source_files:
+ ms = unique_re.findall(io.open(f, encoding='utf8').read())
+ for name, _type, n in ms:
+ uniques[_type][int(n)].add(name)
+
+ return uniques
+
+def print_all(uniques):
+ for _type, uniqs in uniques.items():
+ print('{_type} uniques'.format(**locals()))
+ for n,names in uniqs.items():
+ all_names = ', '.join(names)
+ print(' {n} = {all_names}'.format(**locals()))
+
+def find_conflicts(uniques):
+ return [ (uniqueType, number, names)
+ for uniqueType, uniqs in uniques.items()
+ for number, names in uniqs.items()
+ if len(names) > 1
+ ]
+
+top_dir = sys.argv[1]
+uniques = find_uniques(glob.glob(os.path.join(top_dir, 'compiler', 'GHC', '**', '*.hs'), recursive=True))
+#print_all(uniques)
+conflicts = find_conflicts(uniques)
+if len(uniques) < 5:
+ print("Error: check-uniques: run from wrong directory?")
+ sys.exit(1)
+
+if len(conflicts) > 0:
+ print("Error: check-uniques: Found Unique conflict")
+ print()
+ for (ty, n, names) in conflicts:
+ print(' %s unique %d conflict: %s' % (ty, n, ', '.join(names)))
+ print()
+ sys.exit(1)