def run_test(label, slug, main, helper, recursive, projects=[], units=[], projects_warned=[], expected_cov_list=[]): """ Produce a coverage report for the given parameters and check the emitted warnings. :param str label: Label for this test. :param str slug: Unique short string for this test (used to create directories). :param ProjectConfig main: Configuration for the "main" project. :param ProjectConfig helper: Configuration for the "helper" project. :param bool recursive: Whether to not pass --no-subprojects. :param list[str] projects: List of projects to pass with --projects. :param list[str] units: List of units to pass with --units. :param list[str] projects_warned: List of projects for which we expected warnings. :param expected_cov: List of expected coverage reports. """ thistest.log('== [{}] {} =='.format(slug, label)) tmp.to_subdir('wd_/{}'.format(slug)) expected_output = '\n'.join( 'warning: project {} provides no unit of interest' .format(project) for project in projects_warned) # Generate projects for this test (see below for the description of each # project). ProjectConfig().generate('empty') helper.generate('helper') main_prj = main.generate('main', deps=['empty', 'helper'], mains=['main.adb']) mkdir('obj-empty') mkdir('obj-helper') mkdir('obj-main') # Generate a coverage report for them build_run_and_coverage( gprsw=GPRswitches(root_project=main_prj, projects=projects, units=units, no_subprojects=not recursive), covlevel='stmt', mains=['main'], gpr_obj_dir='obj-main', extra_coverage_args=['-axcov']) log_file = ('coverage.log' if thistest.options.trace_mode == 'bin' else 'instrument.log') thistest.fail_if_not_equal( '[{}/{}] gnatcov output'.format(label, slug), expected_output, contents_of(log_file).strip()) expected_cov = {} for c in expected_cov_list: expected_cov.update(c) check_xcov_reports('obj-*/*.xcov', expected_cov)
from SUITE.tutils import gprfor tmp = Wdir('wd_') build_run_and_coverage(gprsw=GPRswitches( root_project=gprfor('main.adb', srcdirs='..'), units=['no_such_unit', 'main', 'helper.say_hello']), covlevel='stmt', mains=['main'], extra_coverage_args=['-axcov']) log_file = ('coverage.log' if thistest.options.trace_mode == 'bin' else 'instrument.log') # Split and re-join lines to avoid spurious CR/LF diffs on Windows. Also sort # lines, as the order in which these warnings is emitted is not deterministic. log_lines = '\n'.join( sorted(line.rstrip() for line in contents_of(log_file).splitlines())).rstrip() thistest.fail_if_not_equal( 'gnatcov output', 'warning: no unit helper.say_hello (from --units) in the projects of' ' interest' '\nwarning: no unit no_such_unit (from --units) in the projects of' ' interest', log_lines) check_xcov_reports('obj/*.xcov', {'obj/main.adb.xcov': {'+': {5}}}) thistest.result()
""" Check that invalid units passed as project attributes are properly reported. """ from SCOV.minicheck import build_run_and_coverage, check_xcov_reports from SUITE.context import thistest from SUITE.gprutils import GPRswitches, gprcov_for from SUITE.cutils import Wdir, contents_of from SUITE.tutils import gprfor tmp = Wdir('wd_') build_run_and_coverage(gprsw=GPRswitches( root_project=gprfor('main.adb', srcdirs='..', extra=gprcov_for(units_in=['no_such_unit', 'main']))), covlevel='stmt', mains=['main'], extra_coverage_args=['-axcov']) log_file = ('coverage.log' if thistest.options.trace_mode == 'bin' else 'instrument.log') thistest.fail_if_not_equal( 'gnatcov output', 'warning: no unit no_such_unit in project gen (coverage.units attribute)', contents_of(log_file).strip()) check_xcov_reports('obj/*.xcov', {'obj/main.adb.xcov': {'+': {5}}}) thistest.result()
tmp = Wdir('wd_', clean=True) mkdir('obj-helper') mkdir('obj-main') helper_prj = gprfor(prjid='helper', mains=[], langs=['Ada'], srcdirs='../src-helper', objdir='obj-helper') main_prj = gprfor(prjid='main', mains=['main.adb'], langs=['Ada'], deps=['helper'], srcdirs='../src-main', objdir='obj-main') build_run_and_coverage( gprsw=GPRswitches(root_project=main_prj, projects=['helper'], units=['helper', 'main']), covlevel='stmt', mains=['main'], gpr_obj_dir='obj-main', extra_coverage_args=['-axcov']) log_file = ('coverage.log' if thistest.options.trace_mode == 'bin' else 'instrument.log') thistest.fail_if_not_equal( 'gnatcov output', 'warning: no unit main (from --units) in the projects of interest', contents_of(log_file).strip()) check_xcov_reports('obj-*/*.xcov', {'obj-main/helper.adb.xcov': {'+': {3}}}) thistest.result()