[libc++] Verify base substitutions earlier in the testing format
authorLouis Dionne <ldionne@apple.com>
Mon, 21 Sep 2020 19:27:40 +0000 (15:27 -0400)
committerLouis Dionne <ldionne@apple.com>
Mon, 21 Sep 2020 19:30:29 +0000 (15:30 -0400)
This allows diagnosing missing substitution issues even when doing
availability feature detection in the DSL.

libcxx/utils/libcxx/test/format.py

index 4390166..5333617 100644 (file)
@@ -41,6 +41,11 @@ def _getTempPaths(test):
     tmpBase = os.path.join(tmpDir, 't')
     return tmpDir, tmpBase
 
+def _checkBaseSubstitutions(substitutions):
+    substitutions = [s for (s, _) in substitutions]
+    for s in ['%{cxx}', '%{compile_flags}', '%{link_flags}', '%{flags}', '%{exec}']:
+        assert s in substitutions, "Required substitution {} was not provided".format(s)
+
 def parseScript(test, preamble):
     """
     Extract the script from a test, with substitutions applied.
@@ -63,7 +68,8 @@ def parseScript(test, preamble):
     substitutions = lit.TestRunner.getDefaultSubstitutions(test, tmpDir, tmpBase,
                                                            normalize_slashes=useExternalSh)
 
-    # Add the %{build} and %{run} convenience substitutions
+    # Check base substitutions and add the %{build} and %{run} convenience substitutions
+    _checkBaseSubstitutions(substitutions)
     substitutions.append(('%{build}', '%{cxx} %s %{flags} %{compile_flags} %{link_flags} -o %t.exe'))
     substitutions.append(('%{run}', '%{exec} %t.exe'))
 
@@ -207,18 +213,12 @@ class CxxStandardLibraryTest(lit.formats.TestFormat):
                 if any([re.search(ext, filename) for ext in SUPPORTED_SUFFIXES]):
                     yield lit.Test.Test(testSuite, pathInSuite + (filename,), localConfig)
 
-    def _checkBaseSubstitutions(self, substitutions):
-        substitutions = [s for (s, _) in substitutions]
-        for s in ['%{cxx}', '%{compile_flags}', '%{link_flags}', '%{flags}', '%{exec}']:
-            assert s in substitutions, "Required substitution {} was not provided".format(s)
-
     def _disableWithModules(self, test):
         with open(test.getSourcePath(), 'rb') as f:
             contents = f.read()
         return b'#define _LIBCPP_ASSERT' in contents
 
     def execute(self, test, litConfig):
-        self._checkBaseSubstitutions(test.config.substitutions)
         VERIFY_FLAGS = '-Xclang -verify -Xclang -verify-ignore-unexpected=note -ferror-limit=0'
         supportsVerify = _supportsVerify(test.config)
         filename = test.path_in_suite[-1]