Changeset 4119


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/

Location:
icGREP/icgrep-devel/QA
Files:
2 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__':
  • icGREP/icgrep-devel/QA/greptest.xml

    r4087 r4119  
    114114<grepcase regexp="[^-]" datafile="special_characters" grepcount="14"/>
    115115<grepcase regexp="[^]-]" datafile="special_characters" grepcount="13"/>
     116
     117<datafile id = "CRLF">line with CRLF &#13;&#10;two lines with LFCR &#10;&#13;final line
     118</datafile>
     119 <grepcase regexp="^$" datafile="CRLF" grepcount="1"/>
     120 <grepcase regexp="^.*$" datafile="CRLF" grepcount="4"/>
     121
     122 <datafile id = "LU_test">
     123The following line has LATIN CAPITAL LETTER G WITH MACRON in single quotes.
     124'&#x1E20;'
     125</datafile>
     126<!-- . should match a unique character, even if it is 3 bytes. -->
     127<grepcase regexp="'.'" datafile="LU_test" grepcount="1"/>
     128<grepcase regexp="'...'" datafile="LU_test" grepcount="0"/>
     129<grepcase regexp="\u{1e20}" datafile="LU_test" grepcount="1"/>
     130<grepcase regexp="\u{1e21}" datafile="LU_test" grepcount="0"/>
     131<grepcase regexp="\p{Lu}" datafile="LU_test" grepcount="2"/>
     132<grepcase regexp="'\p{Lu}'" datafile="LU_test" grepcount="1"/>
     133<grepcase regexp="\p{Ll}" datafile="LU_test" grepcount="1"/>
    116134</greptest>
    117 
    118 
Note: See TracChangeset for help on using the changeset viewer.