github.com/nuvolaris/nuv@v0.0.0-20240511174247-a74e3a52bfd8/difftest.py (about)

     1  #!/usr/bin/env python3
     2  # Licensed to the Apache Software Foundation (ASF) under one
     3  # or more contributor license agreements.  See the NOTICE file
     4  # distributed with this work for additional information
     5  # regarding copyright ownership.  The ASF licenses this file
     6  # to you under the Apache License, Version 2.0 (the
     7  # "License"); you may not use this file except in compliance
     8  # with the License.  You may obtain a copy of the License at
     9  #
    10  #   http://www.apache.org/licenses/LICENSE-2.0
    11  #
    12  # Unless required by applicable law or agreed to in writing,
    13  # software distributed under the License is distributed on an
    14  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    15  # KIND, either express or implied.  See the License for the
    16  # specific language governing permissions and limitations
    17  # under the License.
    18  
    19  
    20  print("\n=== FAILING TESTS:")
    21  import sys
    22  tests = {}
    23  base = "_difftest"
    24  f = open(base, 'r')
    25  lines = f.readlines()
    26  
    27  fails=[]
    28  gots = []
    29  wants = []
    30  
    31  i=0
    32  while i < len(lines):
    33      line = lines[i]
    34      if(line.startswith("=== RUN")):
    35          if lines[i+1].startswith("--- FAIL:"):
    36              fails.append(i+1)
    37      i+=1
    38  
    39  if len(sys.argv) == 1:
    40      n = 0
    41      for i in fails:
    42          print(n, lines[i], end='')
    43          n += 1
    44      print("=== use 'task utestdiff N=<n>' to see the diff")
    45      sys.exit(len(fails))
    46  
    47  n = int(sys.argv[1])
    48  k = fails[n]+2
    49  got = []
    50  want = []
    51  while not lines[k].startswith("want:"):
    52      #print(lines[k])
    53      got.append(lines[k])
    54      k += 1
    55  k += 1
    56  while not (lines[k].startswith("FAIL") or lines[k].startswith("=== RUN")):
    57      #print(lines[k])
    58      want.append(lines[k])
    59      k += 1
    60  
    61  import tempfile
    62  import os
    63  
    64  f1n = "%s.got"%base
    65  
    66  f2n = "%s.want"%base
    67  
    68  with open(f1n, "w") as f1:
    69      with open(f2n, "w") as f2:
    70          f1.writelines(got)
    71          f2.writelines(want)
    72  
    73  os.system("diff %s %s" % (f1n, f2n))