Changeset 6029

Show
Ignore:
Timestamp:
11/03/12 22:43:34 (7 years ago)
Author:
leonwlaw
Message:

Support for checking strings that span multiple lines (#1118)

Location:
seattle/trunk/utf
Files:
5 added
1 modified

Legend:

Unmodified
Added
Removed
  • seattle/trunk/utf/utf.py

    r5970 r6029  
    507507  (out, error) = utfutil.execute(popen_args) 
    508508 
     509  report = {} 
     510   
     511  verify_results(OUT_PRAGMA, pragma_dictionary, out, report) 
     512  verify_results(ERROR_PRAGMA, pragma_dictionary, error, report) 
     513   
     514   
     515  return report 
     516 
     517 
     518 
     519 
     520 
     521def verify_results(pragma_type, pragma_dictionary, output, report): 
     522  ''' 
     523  <Purpose> 
     524    Checks output to ensure that what is expected to be printed to the screen 
     525    has been printed.  
     526     
     527  <Arguments> 
     528    pragma_type: string 
     529      A token indicating which pragma to check.  
     530    pragma_dictionary: dict 
     531      The pragma_dictionary generated by parse_pragma() 
     532    output: string 
     533      This should be the contents of stdout or stderr. 
     534    report: 
     535      A dictionary to store the report in.  This value will be modified.  
     536   
     537  <Side Effects> 
     538    If an expected string is not found in the given output string, a tuple 
     539    corresponding to the current pragma will be added to the report, in the 
     540    form: (expected output, actual output). 
     541   
     542  <Exceptions> 
     543    InvalidPragmaError: 
     544      The specified pragma already exists in the report.  This indicates an  
     545      internal error with the UTF. 
     546     
     547  <Return> 
     548    None 
     549     
     550  ''' 
     551   
     552  # Check to make sure this report does not already exist. 
     553  # This is to ensure we don't mask any bugs. 
     554  if pragma_type in report: 
     555    raise InvalidPragmaError("Pragma already exists in report") 
     556   
     557  # Standardize newlines 
     558  out = output.replace('\r\n', '\n') 
     559 
    509560  # Get rid of an escape sequence that Mac's readline prints out on import. #1110 
    510561  # I'm assuming this will only occur at the very beginning of stdout. Possible bug? 
     
    518569   
    519570  # Is this executable suppose to produce any output on standard out? 
    520   if pragma_dictionary.has_key(OUT_PRAGMA): 
    521     expected_out = pragma_dictionary[OUT_PRAGMA] 
    522      
    523     if not expected_out and not out: # pragma out 
    524       report[OUT_PRAGMA] = (None, expected_out) 
    525     elif not expected_out in out: # pragma out [ARGUMENT] 
    526       report[OUT_PRAGMA] = (out, expected_out) 
    527      
     571  if pragma_dictionary.has_key(pragma_type): 
     572    outlines = out.split('\n') 
     573    expected_out_lines = pragma_dictionary[pragma_type] 
     574     
     575    # Preserve the original 
     576    remaining_out_lines = expected_out_lines[:] 
     577     
     578    for outline in outlines: 
     579      # Are there any wildcards?   
     580      # We use '' to indicate wildcards. 
     581      while remaining_out_lines and not remaining_out_lines[0]: 
     582        remaining_out_lines = remaining_out_lines[1:] 
     583       
     584      # Are there remaining expected lines? 
     585      if remaining_out_lines and remaining_out_lines[0] in outline: 
     586        remaining_out_lines = remaining_out_lines[1:] 
     587     
     588    # Get rid of any remaining wildcards that may still exist 
     589    while remaining_out_lines and not remaining_out_lines[0]: 
     590      remaining_out_lines = remaining_out_lines[1:] 
     591     
     592    if remaining_out_lines: 
     593      # Mark wildcards 
     594      expected_output = "" 
     595      for line in expected_out_lines: 
     596        # Don't display wildcards 
     597        if not line: 
     598          continue 
     599        expected_output += line + '\n' 
     600         
     601      report[pragma_type] = (out, expected_output) 
    528602  elif out: # If not, make sure the standard out is empty. 
    529     report[OUT_PRAGMA] = (out, None) 
    530  
    531   # Is this executable suppose to produce any output on standard error? 
    532   if pragma_dictionary.has_key(ERROR_PRAGMA): 
    533     expected_error = pragma_dictionary[ERROR_PRAGMA] 
    534      
    535     if not expected_error and not  error: # pragma error 
    536       report[ERROR_PRAGMA] = (None, expected_error) 
    537     elif not expected_error in error: # pragma error [ARGUMENT] 
    538       report[ERROR_PRAGMA] = (error, expected_error) 
    539        
    540   elif error: # If not, make sure the standard error is empty. 
    541     report[ERROR_PRAGMA] = (error, None) 
    542  
    543  
    544   return report 
    545  
    546   
     603    report[pragma_type] = (out, None) 
     604 
     605 
     606 
     607 
     608 
    547609 
    548610def parse_pragma(source_text): 
     
    574636 
    575637  for (directive, pragma_type, arg) in pragma_directives: 
    576     if pragma_type in (OUT_PRAGMA, ERROR_PRAGMA, REPY_PRAGMA): 
     638    if pragma_type == REPY_PRAGMA: 
    577639      pragma_dictionary[pragma_type] = arg 
     640       
     641    # Only out and error pragmas are used for output checking 
     642    elif pragma_type in (OUT_PRAGMA, ERROR_PRAGMA): 
     643      if not pragma_type in pragma_dictionary: 
     644        pragma_dictionary[pragma_type] = [] 
     645      pragma_dictionary[pragma_type].append(arg) 
     646       
    578647    else:  
     648      print "Unknown pragma: ", pragma_type 
    579649      raise InvalidPragmaError(pragma_type) 
    580650