Changeset: dee13696596b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/dee13696596b
Modified Files:
        testing/Mtest.py.in
        testing/sqllogictest.py
Branch: Mar2025
Log Message:

New option --approve+replace to approve tests and replace the old .test file in 
one go.
Also some fixes to fixing up the Q-variables in .test.in files.


diffs (99 lines):

diff --git a/testing/Mtest.py.in b/testing/Mtest.py.in
--- a/testing/Mtest.py.in
+++ b/testing/Mtest.py.in
@@ -48,6 +48,7 @@ MonetDB_VERSION = '@MONETDB_VERSION@'.sp
 procdebug = False
 verbosity = 0
 approve = False
+replace = False
 stop_crash = False
 
 initdb = None
@@ -2984,11 +2985,14 @@ def DoIt(env, SERVER, CALL, TST, EXT, Te
                             testfile = TST+EXT
                             if lang == 'sql' and 
os.path.exists(os.path.join(TSTTRGDIR, TST+'.test.in')):
                                 testfile = TST+'.test.in'
+                                
defines.append(f'QTSTDATAPATH={TSTDATAPATH.replace("\\","\\\\")}')
                                 defines.append(f'TSTDATAPATH={TSTDATAPATH}')
-                                defines.append(f'TSTSRCBASE={TSTSRCBASE}')
+                                
defines.append(f'UTSTSRCDIR=file://{url(TSTSRCDIR)}')
+                                
defines.append(f'QTSTSRCDIR={TSTSRCDIR.replace("\\","\\\\")}')
                                 defines.append(f'TSTSRCDIR={TSTSRCDIR}')
+                                
defines.append(f'QTSTTRGDIR={TSTTRGDIR.replace("\\","\\\\")}')
                                 defines.append(f'TSTTRGDIR={TSTTRGDIR}')
-                                
defines.append(f'UTSTSRCDIR=file://{url(TSTSRCDIR)}')
+                                defines.append(f'TSTSRCBASE={TSTSRCBASE}')
                                 defines.append(f'TSTDB={TSTDB}')
                                 defines.append(f'MAPIPORT={pSrvr.port}')
                             try:
@@ -3014,6 +3018,12 @@ def DoIt(env, SERVER, CALL, TST, EXT, Te
                                     returncode = 'error'
                                 elif sql.timedout:
                                     returncode = 'timeout'
+                                if approve and replace and not sql.timedout:
+                                    with openutf8(os.path.join(TSTTRGDIR, 
TST+'.newtest')) as fin, \
+                                         openutf8(os.path.join(TSTSRCDIR, 
testfile + 'new'), 'w') as fout:
+                                        fout.write(fin.read())
+                                        fout.flush()
+                                    os.replace(os.path.join(TSTSRCDIR, 
testfile + 'new'), os.path.join(TSTSRCDIR, testfile))
             elif CALL == 'sql':
                 TSTs = []
                 test = re.compile('^'+TST+EXT+'$', re.MULTILINE)
@@ -3513,6 +3523,7 @@ def main(argv) :
     parser.add_argument('--initdb', action='store', dest='initdb', 
metavar='<zipfile>', help='zip file with contents for initial database')
     parser.add_argument('--single-in-memory', action='store_true', 
dest='single_in_memory', help='use --in-memory for SingleServer directories')
     parser.add_argument('--approve', action='store_true', help='produce 
.newtest file in testing directory with calculated content')
+    parser.add_argument('--approve+replace', action='store_true', 
dest='approve_replace', help='produce .newtest file in testing directory with 
calculated content')
     parser.add_argument('--ignore-conditions', action='store_true', 
dest='ignore_conditions', help='ignore conditions in All file')
     parser.add_argument('--skip-test-with-timeout', action='store_true', 
help='skip tests that have a .timeout file')
     parser.add_argument('--stop-at-crash', action='store_true', 
dest='stop_crash', help='stop testing when the server crashes')
@@ -3548,9 +3559,12 @@ def main(argv) :
     global procdebug
     procdebug = opts.procdebug
     global approve
-    approve = opts.approve
+    global replace
+    approve = opts.approve or opts.approve_replace
     if approve:
         os.environ['MTEST_APPROVE'] = 'TRUE'
+    if opts.approve_replace:
+        replace = True
     global stop_crash
     stop_crash = opts.stop_crash
     global ignore_conditions
diff --git a/testing/sqllogictest.py b/testing/sqllogictest.py
--- a/testing/sqllogictest.py
+++ b/testing/sqllogictest.py
@@ -763,9 +763,7 @@ class SQLLogic:
                 val = val.strip()
                 defs.append((re.compile(r'\$(' + key + r'\b|{' + key + '})'),
                              val, key))
-                defs.append((re.compile(r'\$(Q' + key + r'\b|{Q' + key + '})'),
-                             val.replace('\\', '\\\\'), 'Q'+key))
-        self.defines = sorted(defs, key=lambda x: (-len(x[1]), x[1], x[2]))
+        self.defines = defs
         self.lines = []
 
     def readline(self):
@@ -795,10 +793,10 @@ class SQLLogic:
                     # line = line.replace('\''+val.replace('\\', '\\\\'),
                     #                     '\'${Q'+key+'}')
                     # line = line.replace(val, '${'+key+'}')
+                    if key.startswith('Q') and (("r'"+val) in line or 
("R'"+val) in line):
+                        continue
                     line = line.replace("r'"+val, "r'$"+key)
                     line = line.replace("R'"+val, "R'$"+key)
-                    line = line.replace("'"+val.replace('\\', '\\\\'),
-                                        "'$Q"+key)
                     line = line.replace(val, '$'+key)
             i = 0
             while i < len(self.lines):
@@ -1033,6 +1031,8 @@ class SQLLogic:
                 self.writeline()
             else:
                 self.raise_error(f'unrecognized command {words[0]}')
+        if approve:
+            approve.flush()
 
 if __name__ == '__main__':
     import argparse
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to