Ignore:
Timestamp:
Sep 1, 2014, 12:07:49 PM (5 years ago)
Author:
cameron
Message:

Update greptest.py to generate UTF-8 test files; add some CRLF and Unicode tests/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/QA/greptest.py

    r4096 r4119  
    1919
    2020
    21 import sys, subprocess, os, optparse, re
     21import sys, subprocess, os, optparse, re, codecs
    2222import xml.parsers.expat
    2323
     
    3636                        print "Expecting id attribute for datafile, but none found."
    3737                        exit(-1)
    38                 outf = open(os.path.join(options.datafile_dir, filename), 'w')
     38                outf = codecs.open(os.path.join(options.datafile_dir, filename), encoding='utf-8', mode='w')
    3939                in_datafile = True
    4040
     
    5959def escape_quotes(e):  return e.replace("'", "'\\''")
    6060
     61
     62failure_count = 0
     63
    6164def start_element_do_test(name, attrs):
     65        global failure_count
    6266        if name == 'grepcase':
    6367                regexp = None
     
    7680                #execute grep test
    7781                grep_cmd = "%s -c '%s' %s" % (grep_program_under_test, escape_quotes(regexp), os.path.join(options.datafile_dir, datafile))
    78                 grep_out = subprocess.check_output(grep_cmd, cwd=options.exec_dir, shell=True)
     82                try:
     83                    grep_out = subprocess.check_output(grep_cmd, cwd=options.exec_dir, shell=True)
     84                except subprocess.CalledProcessError, e:
     85                    grep_out = e.output
    7986                if grep_out[-1] == '\n': grep_out = grep_out[:-1]
    8087                m = re.search('[0-9]+', grep_out)
    8188                if m == None or m.group(0) != expected_count:
    8289                        print("Test failure: regexp {%s} on datafile {%s} expecting {%s} got {%s}" % (regexp, datafile, expected_count, grep_out))
    83                         exit(1)
     90                        failure_count += 1
    8491                else:
    8592                        if options.verbose:
     
    8794
    8895def run_tests(greptest_xml):
     96        global failure_count
    8997        p = xml.parsers.expat.ParserCreate()
    9098        p.StartElementHandler = start_element_do_test
    9199        p.Parse(greptest_xml, 1)
    92 
     100        if failure_count > 0: exit(1)
    93101
    94102if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.