Text file comparison

Introduction

The text files comparison will compare files without a structure, such as reports or log files. More precisely, it will compare either all files with the same path inside two folders defined in the configuration, or two files defined in the configuration.  
The lines in the text files are compared as a whole, since there is no structure. Some portions may be ignored using options and/or regular expressions. 

Configuration file

A minimal bacmp configuration file for text files will be as below. It will scan the default left and right folders and compare each file found with the same name. 

{"comparisonType“: "Textfile“} 

Folder mode and file mode

By default, the tool will compare all pairs of files with the same path in the left folder and the right folder. This means that if a file appears in both folders, or in the same subfolder in both folders, they will be compared. You can also supply two options ‘leftFile’ and ‘rightFile’. In this case, the folders are disregarded and only the two files are compared. This enables you to compare files with different names. See Additional properties for the exact syntax. 

Filter options

If nothing else is specified, the lines in the files are rejected as a whole if they are different. Property files may be added to the comparison to define exceptions. These may be defined at several levels:  

Common property files can be specified as semicolon-separated files using the ‘propertiesFiles’ option in the configuration. Specific property files can also be added at folder or file level (‘regularExpressionsFilesMapping’ option).

{ 
"comparisonType“: "Textfile", 
"textFile": { 
"propertiesFiles": "compare/data/p1.properties;compare/data/p2.properties", 
"regularExpressionsFilesMapping": { 
"folder1": ["compare/data/p1.properties","compare/data/p2.properties"], "folder2/file1": ["compare/data/p1.properties"] } ... } 
} 

In file mode, only the ‘propertiesFile’ option is used.  
In folder mode, “propertiesFile” option is used first, then additional properties files may be used, taken into account in this order: 

  • Folder level: Property files named ‘filter.properties’ are applied to files in the same folder and in all sub-folders. (the name can be customized, see Additional properties)
  • Folder level: ‘regularExpressionsFilesMapping’ mappings at folder level are applied to the files in the same folder and in all sub-folders.
  • File level: Property files named ‘xxx.properties’ are applied to the “xxx” files (where xxx is the file name with its extension).
  • File level: ‘regularExpressionsFilesMapping’ mappings at file level are applied to the given file.


The properties syntax is as follows: one or more regular expressions are matched with a replacement value. regex=<regex1> regex=<regex2> ... value=<replacement>  

For instance, these values: regex=Date: [0-9]{4}/[0-9]{2}/[0-9]{2} ([a-zA-Z0-9-\.\(\) ]{100}) value=Date: xxxx/xx/xx $1  
will allow to replace some dates and thus ignore the corresponding date differences in a report. This avoids comparing acceptable differences such as the dates which differ due to a different execution date of the test case. 

Additional properties

In addition to the configurations above, there are additional properties. Most have default values that are used if the property does not appear in the file, but can also be specified to another value. Others are not used if left unspecified.  

Default values are written in green below when they exist, a red ‘no value’ otherwise.

TextFileCOmp-AdditionalProp.PNG
fileFilterComma-separated extension list to compare.  
For instance, setting to "txt" will compare only the txt in the folders.  
If enablePdfConversion is not disabled, the pdfs are automatically compared regardless of this option.  
This option is ignored in file mode.
 
propertiesFilesCommon property filesSee Filter options
regularExpressionsFilesMappingExplicit property files mappingsSee Filter options
leftFolderCustomize the left folder for the files to compare 
rightFolderCustomize the right folder for the files to compare 
leftFileSpecify a left file to be compared (file mode)See Folder mode and file mode
rightFileSpecify a right file to be compared (file mode)See Folder mode and file mode
folderFileFilterNameDefault name for the properties files in foldersSee Filter options
enablePdfConversionWhether to automatically convert Pdfs to txt so as to compare them. Necessary to compare PDFsSee Additional properties
keepConvertedTextFilesIf used, the temporary txt files coming from PDF conversion will be kept (useful for debugging) 
convertedTextFilesFolderIf keepConvertedTextFiles is used, the temporary txt files coming from PDF conversion are stored in this folder.