Changeset 987


Ignore:
Timestamp:
07/08/20 23:35:17 (4 years ago)
Author:
Maciej Komosinski
Message:

When tests fail, create failed result files with filenames similar to the filenames of goal files

Location:
tester
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tester/comparison.py

    r798 r987  
    77class Comparison:
    88        def __init__(self, l1, l2):
     9                self.list2_file = '' # (last if there are many) file name with goal results (if they are stored in a file)
    910                self.list1 = self.prepare_fill_in_files(l1)
    1011                self.list2 = self.prepare_fill_in_files(l2)
    1112                self.p1 = 0  # updated position within list1
    1213                self.p2 = 0  # updated position within list2
    13                 self.ok = True  # the final comparison result
     14                self.equal = True  # the final comparison result
    1415                self.result = ""  # details of comparing individual lines
    1516
    1617                while not self.finished():
    1718                        if not self.compare_element():
    18                                 self.ok = False
     19                                self.equal = False
    1920
    2021        @staticmethod
     
    3839                                file_name = l[len(globals.SPEC_INSERTPLATFORMDEPENDENTFILE):]
    3940                                new_list += self.load_platform_specific(file_name)
     41                                self.list2_file = file_name
    4042                        else:
    4143                                new_list.append(l)
     
    6668                        waiting = False
    6769                if e2.startswith(globals.SPEC_REGEXP):
    68                         ok = re.match(e2[len(globals.SPEC_REGEXP):], e1)
     70                        equal = re.match(e2[len(globals.SPEC_REGEXP):], e1)
    6971                else:
    70                         ok = self.compare_strings(e1, e2)  # ignoring the discrimination of /\ will work only when regexp's are not used
     72                        equal = self.compare_strings(e1, e2)  # ignoring the discrimination of /\ will work only when regexp's are not used
    7173                self.result += repr(e1) + " "
    72                 if ok:
     74                if equal:
    7375                        self.p2 += 1
    7476                else:
     
    7779                                        self.p2 += 1
    7880                                else:
    79                                         ok = True
     81                                        equal = True
    8082                        else:
    8183                                self.p2 += 1
    82                 if ok:
     84                if equal:
    8385                        self.result += globals.ANSI_SETGREEN + "ok" + globals.ANSI_RESET + "\n"  # if both are identical, we display only the left one
    8486                else:
     
    8688                        self.result += repr(e2disp) + "\n"
    8789                self.p1 += 1
    88                 return ok
     90                return equal
  • tester/tester.py

    r985 r987  
    1515#       if 'cyg' in a or 'cyg' in b: #...that contain 'cyg' and therefore may be useful for detecting that we are running under cygwin
    1616#               print(a,b)
    17 CYGWIN='cygwin' in os.environ['HOME']
     17CYGWIN='HOME' in os.environ and 'cygwin' in os.environ['HOME']
    1818if CYGWIN:
    1919        os.linesep='\n' #fix wrong value (suitable for Windows)
     
    8484
    8585def compare(jest, goal, was_compared_to):
    86         p = comparison.Comparison(jest, goal)
    87         if p.ok:
     86        compare = comparison.Comparison(jest, goal)
     87        if compare.equal:
    8888                print("\r", globals.ANSI_SETGREEN + " ok" + globals.ANSI_RESET)
    8989        else:
    9090                print("\r", globals.ANSI_SETRED + " FAIL\7" + globals.ANSI_RESET)
    91                 print(p.result)
    92                 f = open(os.path.join(globals.THISDIR, '_last_failed' + was_compared_to + '.output'), 'w')  # files are easier to compare than stdout
     91                print(compare.result)
     92                failed_result_filename = compare.list2_file + was_compared_to
     93                if failed_result_filename == '':
     94                        failed_result_filename = '_test'
     95                f = open(os.path.join(globals.THISDIR, failed_result_filename + '.Failed-output'), 'w')  # files are easier to compare than stdout
    9396                print('\n'.join(jest), end="", file=f)
    94                 f = open(os.path.join(globals.THISDIR, '_last_failed' + was_compared_to + '.goal'), 'w')  # files are easier to compare than stdout
     97                f = open(os.path.join(globals.THISDIR, failed_result_filename + '.Failed-goal'), 'w')  # files are easier to compare than stdout
    9598                print('\n'.join(goal), end="", file=f)
    96         return p.ok
     99        return compare.equal
    97100
    98101
     
    264267                                                for line in main_test_filename:
    265268                                                        contents.append(globals.stripEOL(line))
    266                                         ok = compare(contents, outfile, '_file')
     269                                        ok = compare(contents, outfile, '_file') # +line[1]
    267270                                except Exception as e: # could also 'raise' for some types of exceptions if we wanted
    268271                                        print_exception()
Note: See TracChangeset for help on using the changeset viewer.