def testGNATcheckHideExempted(self): PROJECT = Project.simple_with_hide_exempted() # Define 'obj' folder name and path OBJ_FOLDER = 'obj' OBJ_PATH = os.path.join(PROJECT.install_dir, OBJ_FOLDER) # 1st step: Run GNAThub without '--gnatcheck-hide-exempted' switch assert not os.path.exists(OBJ_PATH), 'Object folder should not exist' gnathub = GNAThub(PROJECT, plugins=['gnatcheck']) assert os.path.exists(OBJ_PATH), 'Object folder should exist' # Check that results are generated in /obj GNATCHECK_FILES_COUNT = 0 GNATCHECK_FILES_FOUND = False GNATHUB_DIR_FOUND = False GNATHUB_DIR_LEN = 0 for entry in os.listdir(OBJ_PATH): if entry.startswith('gnatcheck') and entry.endswith('.out'): GNATCHECK_FILES_COUNT += 1 elif os.path.isdir(os.path.join(OBJ_PATH, entry)): crt_path = os.path.join(OBJ_PATH, entry) if entry == 'gnathub': GNATHUB_DIR_FOUND = True GNATHUB_DIR_LEN = len(os.listdir(crt_path)) GNATCHECK_FILE_FOUND = GNATCHECK_FILES_COUNT != 0 assert GNATCHECK_FILE_FOUND, 'GNATcheck files should be generated in /obj folder' assert GNATHUB_DIR_FOUND, 'GNAThub directory should be generated in /obj folder' # Check DB content after gnatcheck run gnathub.run(script='check-db-gnatcheck.py') # 2nd step: Run GNAThub with '--gnatcheck-hide-exempted' switch gnathub = GNAThub(PROJECT, plugins=['gnatcheck'], gnatcheck_hide_exempted=True) GNATHUB_DIR_FOUND = False GNATHUB_DIR_LEN = 0 for entry in os.listdir(OBJ_PATH): if entry.startswith('gnatcheck') and entry.endswith('.out'): GNATCHECK_FILES_COUNT += 1 elif os.path.isdir(os.path.join(OBJ_PATH, entry)): crt_path = os.path.join(OBJ_PATH, entry) if entry == 'gnathub': GNATHUB_DIR_FOUND = True GNATHUB_DIR_LEN = len(os.listdir(crt_path)) elif entry == 'codepeer': CODEPEER_DIR_FOUND = True CODEPEER_DIR_LEN = len(os.listdir(crt_path)) GNATCHECK_FILE_FOUND = GNATCHECK_FILES_COUNT != 0 assert GNATCHECK_FILE_FOUND, 'GNATcheck files should be generated in /obj folder' assert GNATHUB_DIR_FOUND, 'GNAThub directory should be generated in /obj folder' # Check DB content after gnatcheck run with '--gnatcheck-hide-exempted' switch gnathub.run(script='check-db-gnatcheck-hide.py')
def setUp(self): self.longMessage = True plugins = ['gnatcheck'] if os.environ["WITH_SONAR"]: plugins = ['gnatcheck', 'sonar-config', 'sonar-scanner'] self.gnathub = GNAThub(Project.simple_sonar(), plugins=plugins)
def setUp(self): self.longMessage = True self.project = Project.simple_gnatstack() self.project.build() self.gnathub = GNAThub(self.project, plugins=['gnatstack']) script_output_file = os.path.abspath('script.out') self.gnathub.run(script=Script.db2cfg(), output=script_output_file) self.parser = SafeConfigParser() self.parser.optionxform = str self.parser.read(script_output_file)
def testDryRunModeNoSideEffect(self): PROJECT = Project.disabled() PLUGINS = ['sonar-config'] DB = os.path.join(PROJECT.install_dir, 'obj', 'gnathub', 'gnathub.db') # Execute GNAThub with option --dry-run # Run GNAThub with only the sonar-config plugin gnathub = GNAThub(PROJECT, plugins=PLUGINS, dry_run=True) assert not os.path.exists(DB), 'Database should not have been created' # Execute GNAThub without option --dry-run gnathub.run(plugins=PLUGINS) assert os.path.exists(DB), 'Database should have been created'
def setUp(self): self.longMessage = True # Just import the project. Do no try to build it nor to run it: we # don't expect GNATcoverage to be available during testsuite runs, so # use the precomputed coverage reports instead. self.project = Project.coverage_exhaustive() # Run GNAThub with only the GNATcoverage plugin self.gnathub = GNAThub(self.project, plugins=['gnatcoverage']) # Extract coverage information from the database script_output_file = os.path.abspath('script.out') self.gnathub.run(script=Script.db2cfg(), output=script_output_file) self.parser = ConfigParser() self.parser.optionxform = str self.parser.read(script_output_file)
def setUp(self): self.longMessage = True # Import the project, build it and run it self.project = Project.gcov_multi_object_dir() self.project.build() self.project.run() # Run GNAThub with only the gcov plugin self.gnathub = GNAThub(self.project, plugins=['gcov']) # Extract coverage information from the database script_output_file = os.path.abspath('script.out') self.gnathub.run(script=Script.db2cfg(), output=script_output_file) self.parser = SafeConfigParser() self.parser.optionxform = str self.parser.read(script_output_file)
def setUp(self): self.longMessage = True # Just import the project. Do no try to build it nor to run it: we # don't expect GNATcoverage to be available during testsuite runs, so # use the precomputed coverage reports instead. self.project = Project.coverage_exhaustive() # Run GNAThub with only the GNATcoverage plugin self.gnathub = GNAThub(self.project, plugins=['gnatcoverage']) # Extract coverage information from the database script_output_file = os.path.abspath('script.out') self.gnathub.run(script=Script.db2cfg(), output=script_output_file) self.parser = SafeConfigParser() self.parser.optionxform = str self.parser.read(script_output_file)
def setUp(self): self.longMessage = True self.gnathub = GNAThub(Project.simple(), plugins=['gnatmetric'])
def setUp(self): self.longMessage = True self.project = Project.simple() self.project.build() self.gnathub = GNAThub(self.project, plugins=['gnatstack'])
def setUp(self): plugins = ['gnatcheck', 'sonar-config'] self.gnathub = GNAThub(Project.aggregate_prj(), plugins=plugins)
def testIncrementalSwitch(self): PROJECT = Project.simple() # Define 'obj' folder name and path OBJ_FOLDER = 'obj' OBJ_PATH = os.path.join(PROJECT.install_dir, OBJ_FOLDER) # 1st step: Run GNAThub without '--incremental' switch assert not os.path.exists(OBJ_PATH), 'Object folder should not exist' gnathub = GNAThub(PROJECT, plugins=['codepeer']) assert os.path.exists(OBJ_PATH), 'Object folder should exist' # Check that results are generated in /obj METRIX_FILES_COUNT = 0 METRIX_FILES_FOUND = False GNATHUB_DIR_FOUND = False GNATHUB_DIR_LEN = 0 CODEPEER_DIR_FOUND = False CODEPEER_DIR_LEN = 0 for entry in os.listdir(OBJ_PATH): if entry.endswith('.metrix') or entry.startswith('metrix'): METRIX_FILES_COUNT += 1 elif os.path.isdir(os.path.join(OBJ_PATH, entry)): crt_path = os.path.join(OBJ_PATH, entry) if entry == 'gnathub': GNATHUB_DIR_FOUND = True GNATHUB_DIR_LEN = len(os.listdir(crt_path)) elif entry == 'codepeer': CODEPEER_DIR_FOUND = True CODEPEER_DIR_LEN = len(os.listdir(crt_path)) METRIX_FILE_FOUND = METRIX_FILES_COUNT != 0 assert not METRIX_FILE_FOUND, 'No metrix should be generated in /obj folder' assert GNATHUB_DIR_FOUND, 'GNAThub directory should be generated in /obj folder' assert CODEPEER_DIR_FOUND, 'Codepeer directory should be generated in /obj folder' # Check DB content gnathub.run(script='check-db-codepeer.py') # 2nd step: Run GNAThub without '--incremental' switch gnathub = GNAThub(PROJECT, plugins=['gnatmetric']) GNATHUB_DIR_FOUND = False GNATHUB_DIR_LEN = 0 CODEPEER_DIR_FOUND = False CODEPEER_DIR_LEN = 0 for entry in os.listdir(OBJ_PATH): if entry.endswith('.metrix') or entry.startswith('metrix'): METRIX_FILES_COUNT += 1 elif os.path.isdir(os.path.join(OBJ_PATH, entry)): crt_path = os.path.join(OBJ_PATH, entry) if entry == 'gnathub': GNATHUB_DIR_FOUND = True GNATHUB_DIR_LEN = len(os.listdir(crt_path)) elif entry == 'codepeer': CODEPEER_DIR_FOUND = True CODEPEER_DIR_LEN = len(os.listdir(crt_path)) METRIX_FILE_FOUND = METRIX_FILES_COUNT != 0 assert METRIX_FILE_FOUND, 'Metrix should be generated in /obj folder' assert GNATHUB_DIR_FOUND, 'GNAThub directory should be generated in /obj folder' assert CODEPEER_DIR_FOUND, 'Codepeer directory should be generated in /obj folder' # Check DB content after gnatmetric run gnathub.run(script='check-db-metrics.py') # 3rd step: Run GNAThub with '--incremental' switch gnathub = GNAThub(PROJECT, plugins=['codepeer'], incremental=True) # Check DB content after gnatmetric run gnathub.run(script='check-db-incremental.py') # 4th step: Run GNAThub with '--incremental' switch gnathub = GNAThub(PROJECT, plugins=['codepeer'], incremental=True) # Check DB content after gnatmetric run gnathub.run(script='check-db-incremental.py') # 5th step: Run GNAThub with '--incremental' switch gnathub = GNAThub(PROJECT, plugins=['gnatmetric'], incremental=True) # Check DB content after gnatmetric run gnathub.run(script='check-db-incremental.py')
def setUp(self): self.longMessage = True # Run GNAThub with only the sonar-config plugin self.gnathub = GNAThub(Project.disabled(), plugins=['sonar-config'])
def setUp(self): self.longMessage = True self.gnathub = GNAThub(Project.simple_gnatcheck(), plugins=['gnatcheck'])
def setUp(self): plugins = ['gnatmetric', 'gnatcheck', 'sonar-config'] self.gnathub = GNAThub(Project.simple(), plugins=plugins)
def setUp(self): self.longMessage = True self.gnathub = GNAThub( Project.simple(), plugins=['codepeer'], mocks=[CodePeerExecutable])
def setUp(self): self.longMessage = True os.environ['USE_LIBADALANG_TOOLS'] = '1' self.gnathub = GNAThub(Project.simple(), plugins=['gnatmetric'])
def testDatabaseContent(self): PROJECT = Project.simple() # Create path to /obj and /codepeer folders OBJ_FOLDER = 'obj' OBJ_PATH = os.path.join(Project.simple().install_dir, OBJ_FOLDER) CODEPEER_FOLDER = 'codepeer' CODEPEER_PATH = os.path.join(OBJ_PATH, CODEPEER_FOLDER) # Run GNAThub with Codepeer gnathub = GNAThub(PROJECT, plugins=['codepeer']) # Check that /obj and /codepeer folders exists assert os.path.exists(OBJ_PATH), 'Object folder should exist' assert os.path.exists(CODEPEER_PATH), 'Codepeer folder should exist' # Check the existence of expected simple.csv file CSV_COUNT = 0 CSV_PATH = CODEPEER_PATH for entry in os.listdir(CODEPEER_PATH): if entry.endswith('.csv') and entry.startswith('simple'): CSV_COUNT += 1 CSV_PATH = os.path.join(CSV_PATH, entry) assert CSV_COUNT == 1, 'simple.csv should be generated in /obj/codepeer folder' assert os.path.isfile(CSV_PATH), 'simple.csv is a file' # Check .csv content columns = defaultdict( list) # each value in each column is appended to a list with open(CSV_PATH) as f: # read rows into a dictionary format reader = csv.DictReader(f) # read a row as {column1: value1, column2: value2,...} for row in reader: # go over each column name and value for (k, v) in row.items(): # append the value into the appropriate list based on column name k columns[k].append(v) # Check column 'Line' self.assertListEqual(columns['Line'], EXPECTED_LINES_FROM_CSV) # Check column 'Column' self.assertListEqual(columns['Column'], EXPECTED_COLUMNS_FROM_CSV) # Check column 'Category' self.assertListEqual(columns['Category'], EXPECTED_CATEGORIES_FROM_CSV) # Check column 'Ranking' self.assertListEqual(columns['Ranking'], EXPECTED_RANKINGS_FROM_CSV) # Check column 'Kind' self.assertListEqual(columns['Kind'], EXPECTED_KINDS_FROM_CSV) # Check column 'Message' self.assertListEqual(columns['Message'], EXPECTED_MESSAGES_FROM_CSV) # Checks the analysis report results are as expected script_output_file = os.path.abspath('script.out') gnathub.run(script=Script.db2cfg(), output=script_output_file) parser = SafeConfigParser() parser.optionxform = str parser.read(script_output_file) self.assertListEqual(sorted(parser.sections()), RESULTS)
def setUp(self): self.longMessage = True # Run GNAThub with only the sonar-config plugin self.gnathub = GNAThub(Project.simple(), plugins=['gnatmetric'])
def setUp(self): self.longMessage = True self.project = Project.simple() self.project.build() self.project.run() self.gnathub = GNAThub(self.project, plugins=['gnatstack'])
def setUp(self): self.longMessage = True self.project = Project.abstract_with_multi_obj_dir() self.gnathub = GNAThub(self.project, plugins=['gnatmetric'], tool_args={'gnatmetric': ['-U']})
def testFlowAnalysisMultiObjDirDBContent(self): self.gnathub = GNAThub(Project.fa_multi_obj(), plugins=['spark2014']) self.gnathub.run(script='check_flow_analysis_multi_obj_db.py')
def setUp(self): self.longMessage = True self.gnathub = GNAThub(Project.flow_analysis(), plugins=['spark2014'])
def testDatabaseContent(self): PROJECT = Project.simple() # Create path to /obj and /codepeer folders OBJ_FOLDER = 'obj' OBJ_PATH = os.path.join(Project.simple().install_dir, OBJ_FOLDER) CODEPEER_FOLDER = 'codepeer' CODEPEER_PATH = os.path.join(OBJ_PATH, CODEPEER_FOLDER) # Run GNAThub with Codepeer gnathub = GNAThub(PROJECT, plugins=['codepeer']) # Check that /obj and /codepeer folders exists assert os.path.exists(OBJ_PATH), 'Object folder should exist' assert os.path.exists(CODEPEER_PATH), 'Codepeer folder should exist' # Check the existence of expected simple.csv file CSV_COUNT = 0 CSV_PATH = CODEPEER_PATH for entry in os.listdir(CODEPEER_PATH): if entry.endswith('.csv') and entry.startswith('simple'): CSV_COUNT += 1 CSV_PATH = os.path.join(CSV_PATH, entry) assert CSV_COUNT == 1, 'simple.csv should be generated in /obj/codepeer folder' assert os.path.isfile(CSV_PATH), 'simple.csv is a file' # Check .csv content columns = defaultdict(list) # each value in each column is appended to a list with open(CSV_PATH) as f: # read rows into a dictionary format reader = csv.DictReader(f) # read a row as {column1: value1, column2: value2,...} for row in reader: # go over each column name and value for (k,v) in row.items(): # append the value into the appropriate list based on column name k columns[k].append(v) # Check column 'Line' self.assertListEqual(columns['Line'], EXPECTED_LINES_FROM_CSV) # Check column 'Column' self.assertListEqual(columns['Column'], EXPECTED_COLUMNS_FROM_CSV) # Check column 'Category' self.assertListEqual(columns['Category'], EXPECTED_CATEGORIES_FROM_CSV) # Check column 'Ranking' self.assertListEqual(columns['Ranking'], EXPECTED_RANKINGS_FROM_CSV) # Check column 'Kind' self.assertListEqual(columns['Kind'], EXPECTED_KINDS_FROM_CSV) # Check column 'Message' self.assertListEqual(columns['Message'], EXPECTED_MESSAGES_FROM_CSV) # Checks the analysis report results are as expected script_output_file = os.path.abspath('script.out') gnathub.run(script=Script.db2cfg(), output=script_output_file) parser = SafeConfigParser() parser.optionxform = str parser.read(script_output_file) self.assertListEqual(sorted(parser.sections()), RESULTS)
def testSubdirsSwitch(self): PROJECT = Project.simple() PLUGINS = ['gnatmetric', 'gnatcheck', 'codepeer'] # Define 'obj' folder name and path OBJ_FOLDER = 'obj' OBJ_PATH = os.path.join(PROJECT.install_dir, OBJ_FOLDER) # Define 'test_metrix' as target folder name and path of --subdirs switch SUBDIRS_FOLDER = 'test_metrix' NEW_OBJ_PATH = os.path.join(PROJECT.install_dir, OBJ_FOLDER, SUBDIRS_FOLDER) # 1st step of test : Run GNAThub without '--subdirs' switch only for gnatmetric plugin assert not os.path.exists(OBJ_PATH), 'Object folder should not exist' gnathub = GNAThub(PROJECT, plugins=PLUGINS) assert os.path.exists(OBJ_PATH), 'Object folder should exist' assert not os.path.exists( NEW_OBJ_PATH), 'New object folder should not have been created yet' # Check that metrix and gnatcheck results are generated in /obj METRIX_FILES_COUNT = 0 METRIX_FILES_FOUND = False GNATCHECK_FILES_COUNT = 0 GNATCHECK_FILES_FOUND = False GNATHUB_DIR_FOUND = False GNATHUB_DIR_LEN = 0 CODEPEER_DIR_FOUND = False CODEPEER_DIR_LEN = 0 for entry in os.listdir(OBJ_PATH): if entry.endswith('.metrix') or entry.startswith('metrix'): METRIX_FILES_COUNT += 1 elif entry.startswith('gnatcheck') and entry.endswith('.out'): GNATCHECK_FILES_COUNT += 1 elif os.path.isdir(os.path.join(OBJ_PATH, entry)): crt_path = os.path.join(OBJ_PATH, entry) if entry == 'gnathub': GNATHUB_DIR_FOUND = True GNATHUB_DIR_LEN = len(os.listdir(crt_path)) elif entry == 'codepeer': CODEPEER_DIR_FOUND = True CODEPEER_DIR_LEN = len(os.listdir(crt_path)) METRIX_FILE_FOUND = METRIX_FILES_COUNT != 0 GNATCHECK_FILES_FOUND = GNATCHECK_FILES_COUNT == 2 # expected value is 2 assert METRIX_FILE_FOUND, 'Metrix should be generated in /obj folder' assert GNATCHECK_FILES_FOUND, 'Gnatcheck out files should be generated in /obj folder' assert CODEPEER_DIR_FOUND, 'Codepeer directory should be generated in /obj folder' # Run GNAThub with option '--subdirs=test_metrix' only for gnatmetric plugin gnathub = GNAThub(PROJECT, plugins=PLUGINS, subdirs=SUBDIRS_FOLDER) assert os.path.exists( NEW_OBJ_PATH), 'New object folder should have been created' # Check that metrix and gnatcheck results are present in '/obj/test_metrix' folder NEW_METRIX_FILES_COUNT = 0 NEW_GNATCHECK_FILES_COUNT = 0 NEW_GNATHUB_DIR_FOUND = False NEW_GNATHUB_DIR_LEN = 0 NEW_CODEPEER_DIR_FOUND = False NEW_CODEPEER_DIR_LEN = 0 for entry in os.listdir(NEW_OBJ_PATH): filename, ext = os.path.splitext(entry) if entry.endswith('.metrix') or entry.startswith('metrix'): NEW_METRIX_FILES_COUNT += 1 elif entry.startswith('gnatcheck') and entry.endswith('.out'): NEW_GNATCHECK_FILES_COUNT += 1 elif os.path.isdir(os.path.join(NEW_OBJ_PATH, entry)): crt_path = os.path.join(OBJ_PATH, entry) if entry == 'gnathub': NEW_GNATHUB_DIR_FOUND = True NEW_GNATHUB_DIR_LEN = len(os.listdir(crt_path)) elif entry == 'codepeer': NEW_CODEPEER_DIR_FOUND = True NEW_CODEPEER_DIR_LEN = len(os.listdir(crt_path)) self.assertEqual( METRIX_FILES_COUNT, NEW_METRIX_FILES_COUNT, 'All metrix results should be generated in /obj/test_metrix folder' ) self.assertEqual( GNATCHECK_FILES_COUNT, NEW_GNATCHECK_FILES_COUNT, 'All expected gnatchek results should be generated in /obj/test_metrix folder' ) assert NEW_GNATHUB_DIR_FOUND, 'Codepeer directory should be in /obj/test_metrix folder' self.assertEqual(NEW_GNATHUB_DIR_LEN, GNATHUB_DIR_LEN, 'GNAThub directories should have same length') assert NEW_CODEPEER_DIR_FOUND, 'Codepeer directory should be in /obj/test_metrix folder' self.assertEqual(NEW_CODEPEER_DIR_LEN, CODEPEER_DIR_LEN, 'Codepeer directories should have same length')