def main(): """Main processing function. """ files = [] totfiles = 0 testfile = "test.txt" sharpfile = "test-csharp.txt" # initialization libastyle.set_text_color("yellow") os.chdir(libastyle.get_file_py_directory()) if not os.path.exists(testfile): libastyle.system_exit("Run regression2-test.py to create " + testfile) print(libastyle.get_python_version()) print("extracting C# test data") # process formatted files files = libtest.get_formatted_files(testfile) outfile = open(sharpfile, 'w') for filepath in files: filepath = filepath.replace('\\', '/') # replace file separators filepath = '\"' + filepath + '\",' # add quotes to filepath outfile.write(filepath + '\n') totfiles += 1 outfile.close() print("saved " + sharpfile) print("files extracted " + str(totfiles)) formatted, unused, unused, unused = libtest.get_astyle_totals(testfile) if totfiles != formatted: libastyle.system_exit("totals not equal {0} {1}".format( totfiles, formatted))
def test_recursive_1(): """Test multi-byte recursive option. This is the same test as Recursive1 in AStyleTestI18n_I18n except this tests the astyle input. """ print "Running test_recursive_1" # create test files clean_test_directory(testdir) fileNames = create_test_files() # run the test filepaths = testdir + "/*.cpp" excludes = [] astyle = set_astyle_args(filepaths, excludes, astyleexe) testfile = "test1.txt" call_artistic_style(astyle, testfile) # check the fileName vector fileName = libtest.get_formatted_files(testfile) if len(fileNames) != len(fileName): print "Error 1 in test_recursive_1" return for i in range(0, len(fileNames)): fileName[i] = fileName[i].replace('\\', '/') # NOTE: to print the unicode files use "print repr(filename)" if fileNames[i] != fileName[i]: print "Error 2 in test_recursive_1" return
def test_recursive_suffix(): """Test multi-byte recursive option with a multi-byte backup suffix. This is the same test as RecursiveSuffix in AStyleTestI18n_I18n except this tests the astyle input. """ print "Running test_recursive_suffix" # create test files clean_test_directory(testdir) fileNames = create_test_files() # create the suffix as an exclude option # must encode the Japanese suffix to astyle excludes = [] suffix = u".ラルヰ".encode(japanese) excludes.append("--suffix=" + suffix) # run the test filepaths = testdir + "/*" astyle = set_astyle_args(filepaths, excludes, astyleexe) testfile = "testsx.txt" call_artistic_style(astyle, testfile) # check the fileName vector fileName = libtest.get_formatted_files(testfile) if len(fileNames) != len(fileName): print "Error 1 in test_recursive_suffix" return for i in range(0, len(fileNames)): fileSuffix = fileNames[i] + suffix if not os.path.isfile(fileSuffix): print "Error 2 in test_recursive_suffix" return
def test_recursive_2(): """Test multi-byte recursive option with a multi-byte directory. This is the same test as Recursive2 in AStyleTestI18n_I18n except this tests the astyle input. """ print "Running test_recursive_2" # create test files clean_test_directory(testdir) fileNames = create_test_files() # delete the entries that are not in the path # do not use remove in a "for" loop fileNames.remove(testdir + "/recursive1.cpp") fileNames.remove(testdir + subdir2 + "/recursive8.cpp") fileNames.remove(testdir + subdir2 + "/recursive9.cpp") # run the test filepaths = testdir + subdir1 + "/*.cpp" excludes = [] astyle = set_astyle_args(filepaths, excludes, astyleexe) testfile = "test2.txt" call_artistic_style(astyle, testfile) # check the fileName vector fileName = libtest.get_formatted_files(testfile) if len(fileNames) != len(fileName): print "Error 1 in test_recursive_2" return for i in range(0, len(fileNames)): fileName[i] = fileName[i].replace('\\', '/') # NOTE: to print the unicode files use "print repr(filename)" if fileNames[i] != fileName[i]: print "Error 2 in test_recursive_2" return
def process_diffs(): """Main processing function. """ libastyle.set_text_color() os.chdir(libastyle.get_file_py_directory()) testfile = "test.txt" formatted, unchanged, min, sec = libtest.get_astyle_totals(testfile) files = libtest.get_formatted_files(testfile) verify_formatted_files(len(files), formatted) libtest.diff_formatted_files(files)
def main(): """Main processing function. """ libastyle.set_text_color() print(libastyle.get_python_version()) os.chdir(libastyle.get_file_py_directory()) testfile = "test.txt" formatted, unused, unused, unused = libtest.get_astyle_totals(testfile) files = libtest.get_formatted_files(testfile) verify_formatted_files(len(files), formatted) libtest.diff_formatted_files(files)
def check_formatted_files(testfile, brackets, index): """Check the output for files that were formatted. Return is the number of files formatted. """ # check for conditions that are not errors if index == 0: return [] if (brackets[index] != brackets[index - 1] and brackets[index] != '_'): return [] # get formatted files from the astyle report files = libtest.get_formatted_files(testfile) return files
def test_recursive_exclude(): """Test multi-byte recursive option with a multi-byte excludes. This is the same test as RecursiveExclude in AStyleTestI18n_I18n except this tests the astyle input. """ print "Running test_recursive_exclude" # create test files clean_test_directory(testdir) fileNames = create_test_files() # create the excludes excludes = [] # file excludes.append("--exclude=recursive1.cpp") # directory - subdir1a, 2nd directory lastSep = subdir1a.rfind('/') if lastSep == -1: print "Error in subdir1a.rfind" excludes.append("--exclude=" + subdir1a[lastSep:]) # sub directory excludes.append("--exclude=" + subdir1b) # full path file filePath9 = testdir + subdir2 + "/recursive9.cpp" excludes.append("--exclude=" + filePath9) # delete the excluded entries # do not use remove in a "for" loop fileNames.remove(testdir + "/recursive1.cpp") fileNames.remove(testdir + subdir1a + "/recursive4.cpp") fileNames.remove(testdir + subdir1a + "/recursive5.cpp") fileNames.remove(testdir + subdir1b + "/recursive6.cpp") fileNames.remove(testdir + subdir1b + "/recursive7.cpp") fileNames.remove(testdir + subdir2 + "/recursive9.cpp") # run the test filepaths = testdir + "/*" astyle = set_astyle_args(filepaths, excludes, astyleexe) testfile = "testex.txt" call_artistic_style(astyle, testfile) # check the fileName vector fileName = libtest.get_formatted_files(testfile) if len(fileNames) != len(fileName): print "Error 1 in test_recursive_exclude" return for i in range(0, len(fileNames)): fileName[i] = fileName[i].replace('\\', '/') if fileNames[i] != fileName[i]: print "Error 2 in test_recursive_exclude" return
def test_recursive_3(): """Test multi-byte recursive option with a multi-byte filename and extension. This is the same test as Recursive3 in AStyleTestI18n_I18n except this tests the astyle input. """ print "Running test_recursive_3" # create test files clean_test_directory(testdir) fileNames = create_test_files() # write the multi-byte filename and extension # create the test files text = ( "\nvoid foo()\n" "{\n" "bar();\n" "}\n" ) # filename and extension converted to multi-byte Russian fileNameJ = u"/ЧШЪЫ".encode(russian) fileExtJ = u".ЭЮЯ".encode(russian) file = testdir + subdir1 + fileNameJ + fileExtJ; outfile = open(file, 'w') outfile.write(text) outfile.close() # run the test filepaths = testdir + "/*" + fileExtJ excludes = [] astyle = set_astyle_args(filepaths, excludes, astyleexe) testfile = "test3.txt" call_artistic_style(astyle, testfile) # check the fileName vector fileName = libtest.get_formatted_files(testfile) if len(fileName) != 1 : print "Error 1 in test_recursive_3" return fileName[0] = fileName[0].replace('\\', '/') # NOTE: to print the unicode files use "print repr(filename)" if fileName[0] != file: print "Error 2 in test_recursive_3" return
def main(): """Main processing function. """ # initialization starttime = time.time() libastyle.set_text_color("yellow") print(libastyle.get_python_version()) locale.setlocale(locale.LC_ALL, "") if os.name == "nt": process_windows_ramdrive() verify_options_x_variable() print_run_header() os.chdir(libastyle.get_file_py_directory()) libastyle.build_astyle_executable(get_astyle_config()) verify_astyle_executables(__astyleexe1, __astyleexe2) filepaths = libastyle.get_project_filepaths(__project) excludes = libastyle.get_project_excludes(__project) testfile = "test.txt" if __extract_files: print("\nExtracting") libextract.extract_project(__project, __all_files_option) # run test 1 print_test_header(1, __astyleexe1) astyle = set_astyle_args(filepaths, excludes, __astyleexe1) print_formatting_message(astyle, __project) call_artistic_style(astyle, testfile) print_astyle_totals(testfile) # run test 2 print_test_header(2, __astyleexe2) astyle = set_astyle_args(filepaths, excludes, __astyleexe2) print_formatting_message(astyle, __project) call_artistic_style(astyle, testfile) totformat, unused = print_astyle_totals(testfile) files = libtest.get_formatted_files(testfile) verify_formatted_files(len(files), totformat) # process formatted files print_run_total(starttime) libtest.diff_formatted_files(files)
def process_files(): """Main processing function. """ # initialization starttime = time.time() libastyle.set_text_color() locale.setlocale(locale.LC_ALL, "") print_run_header() os.chdir(libastyle.get_file_py_directory()) libastyle.build_astyle_executable(get_astyle_config()) verify_astyle_executables(astyleexe1, astyleexe2) filepaths = libastyle.get_project_filepaths(project) excludes = libastyle.get_project_excludes(project) testfile = "test.txt" if extractfiles: print "\nExtracting files" libextract.extract_project(project, all_files_option) # run test 1 print_test_header(1, astyleexe1) astyle = set_astyle_args(filepaths, excludes, astyleexe1) print_formatting_message(astyle, project) call_artistic_style(astyle, testfile) print_astyle_totals(testfile) # run test 2 print_test_header(2, astyleexe2) astyle = set_astyle_args(filepaths, excludes, astyleexe2) print_formatting_message(astyle, project) call_artistic_style(astyle, testfile) totformat, totfiles = print_astyle_totals(testfile) files = libtest.get_formatted_files(testfile) verify_formatted_files(len(files), totformat) # process formatted files print_run_total(starttime) libtest.diff_formatted_files(files)