Example #1
0
def test_gui_project_loads_absolute_vs_solution():
    create_gui_project_file('test.cppcheck',
                            root_path=os.path.join(os.getcwd(), 'proj2').replace('\\', '/'),
                            import_project=os.path.join(os.getcwd(), 'proj2', 'proj2.sln').replace('\\', '/'))
    ret, stdout, stderr = cppcheck('--project=test.cppcheck')
    assert stderr == ('[a/a.c:1]: (error) Division by zero.\n'
                      '[b/b.c:1]: (error) Division by zero.\n')
Example #2
0
def test_gui_project_loads_absolute_vs_solution():
    create_gui_project_file('test.cppcheck',
                            root_path=os.path.join(os.getcwd(), 'proj2').replace('\\', '/'),
                            import_project=os.path.join(os.getcwd(), 'proj2', 'proj2.sln').replace('\\', '/'))
    ret, stdout, stderr = cppcheck('--project=test.cppcheck')
    assert stderr == ('[a/a.c:1]: (error) Division by zero.\n'
                      '[b/b.c:1]: (error) Division by zero.\n')
Example #3
0
def test_gui_project_loads_absolute_vs_solution_2():
    create_gui_project_file('test.cppcheck',
                            root_path=realpath('proj2'),
                            import_project=realpath('proj2/proj2.sln'))
    ret, stdout, stderr = cppcheck(['--project=test.cppcheck'])
    assert ret == 0, stdout
    assert stderr == ERR_A + ERR_B
Example #4
0
def test_gui_project_loads_relative_vs_solution_with_exclude():
    create_gui_project_file('test.cppcheck',
                            root_path='proj2',
                            import_project='proj2/proj2.sln',
                            exclude_paths=['b'])
    ret, stdout, stderr = cppcheck(['--project=test.cppcheck'])
    assert stderr == ERR_A
Example #5
0
def test_gui_project_loads_relative_vs_solution():
    create_gui_project_file('test.cppcheck',
                            root_path='proj2',
                            import_project='proj2/proj2.sln',
                            exclude_paths=['b'])
    ret, stdout, stderr = cppcheck(['--project=test.cppcheck'])
    assert stderr == '[a/a.c:1]: (error) Division by zero.\n'
Example #6
0
def test_addon_relative_path():
    project_file = 'helloworld/test.cppcheck'
    create_gui_project_file(project_file, paths=['.'], addon='misra')
    ret, stdout, stderr = cppcheck('--project=%s' % (project_file))
    filename = os.path.join('helloworld', 'main.c')
    assert ret == 0
    assert stdout == 'Checking %s ...\n' % (filename)
    assert stderr == ('[%s:5]: (error) Division by zero.\n'
                      '[%s:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))
def test_gui_project_loads_absolute_vs_solution():
    create_gui_project_file('test.cppcheck',
                            root_path=os.path.join(os.getcwd(),
                                                   'proj2').replace('\\', '/'),
                            import_project=os.path.join(
                                os.getcwd(), 'proj2',
                                'proj2.sln').replace('\\', '/'))
    ret, stdout, stderr = cppcheck(['--project=test.cppcheck'])
    assert stderr == ERR_A + ERR_B
Example #8
0
def test_gui_project_loads_compile_commands_2():
    create_compile_commands()
    exclude_path_1 = realpath('proj2/b')
    create_gui_project_file('proj2/test.cppcheck',
                            import_project='compile_commands.json',
                            exclude_paths=[exclude_path_1])
    ret, stdout, stderr = cppcheck(['--project=proj2/test.cppcheck'])
    file1 = os.path.realpath('proj2/a/a.c')
    file2 = os.path.realpath('proj2/b/b.c')  # Excluded by test.cppcheck
    assert ret == 0
    assert stdout.find('Checking %s ...' % file1) >= 0
    assert stdout.find('Checking %s ...' % file2) < 0
Example #9
0
def test_gui_project_loads_compile_commands_2():
    create_compile_commands()
    exclude_path_1 = os.path.join(os.getcwd(), 'proj2', 'b').replace('\\', '/')
    create_gui_project_file('proj2/test.cppcheck',
                            import_project='compile_commands.json',
                            exclude_paths=[exclude_path_1])
    ret, stdout, stderr = cppcheck('--project=proj2/test.cppcheck')
    cwd = os.getcwd()
    file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
    file2 = os.path.join(cwd, 'proj2', 'b', 'b.c') # Excluded by test.cppcheck
    assert ret == 0
    assert stdout.find('Checking %s ...' % (file1)) >= 0
    assert stdout.find('Checking %s ...' % (file2)) < 0
def test_gui_project_loads_compile_commands_2():
    create_compile_commands()
    exclude_path_1 = os.path.join(os.getcwd(), 'proj2', 'b').replace('\\', '/')
    create_gui_project_file('proj2/test.cppcheck',
                            import_project='compile_commands.json',
                            exclude_paths=[exclude_path_1])
    ret, stdout, stderr = cppcheck(['--project=proj2/test.cppcheck'])
    cwd = os.getcwd()
    file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
    file2 = os.path.join(cwd, 'proj2', 'b', 'b.c')  # Excluded by test.cppcheck
    assert ret == 0
    assert stdout.find('Checking %s ...' % (file1)) >= 0
    assert stdout.find('Checking %s ...' % (file2)) < 0
Example #11
0
def test_gui_project_loads_relative_vs_solution():
    create_gui_project_file('test.cppcheck', import_project='proj2/proj2.sln')
    ret, stdout, stderr = cppcheck(['--project=test.cppcheck'])
    file1 = os.path.join('proj2', 'a', 'a.c')
    file2 = os.path.join('proj2', 'b', 'b.c')
    assert ret == 0
    assert stdout.find('Checking %s Debug|Win32...' % file1) >= 0
    assert stdout.find('Checking %s Debug|x64...' % file1) >= 0
    assert stdout.find('Checking %s Release|Win32...' % file1) >= 0
    assert stdout.find('Checking %s Release|x64...' % file1) >= 0
    assert stdout.find('Checking %s Debug|Win32...' % file2) >= 0
    assert stdout.find('Checking %s Debug|x64...' % file2) >= 0
    assert stdout.find('Checking %s Release|Win32...' % file2) >= 0
    assert stdout.find('Checking %s Release|x64...' % file2) >= 0
Example #12
0
def test_gui_project_loads_relative_vs_solution():
    create_gui_project_file('test.cppcheck', import_project='proj2/proj2.sln')
    ret, stdout, stderr = cppcheck('--project=test.cppcheck')
    file1 = os.path.join('proj2', 'a', 'a.c')
    file2 = os.path.join('proj2', 'b', 'b.c')
    assert ret == 0
    assert stdout.find('Checking %s Debug|Win32...' % (file1)) >= 0
    assert stdout.find('Checking %s Debug|x64...' % (file1)) >= 0
    assert stdout.find('Checking %s Release|Win32...' % (file1)) >= 0
    assert stdout.find('Checking %s Release|x64...' % (file1)) >= 0
    assert stdout.find('Checking %s Debug|Win32...' % (file2)) >= 0
    assert stdout.find('Checking %s Debug|x64...' % (file2)) >= 0
    assert stdout.find('Checking %s Release|Win32...' % (file2)) >= 0
    assert stdout.find('Checking %s Release|x64...' % (file2)) >= 0
Example #13
0
def test_suppress_project():
    project_file = os.path.join('helloworld', 'test.cppcheck')
    create_gui_project_file(project_file,
                            paths=['.'],
                            suppressions=[{'fileName':'main.c', 'id':'zerodiv'}])

    # Relative path
    ret, stdout, stderr = cppcheck('--project=%s' % (project_file))
    assert ret == 0
    assert stderr == ''

    # Absolute path
    ret, stdout, stderr = cppcheck('--project=%s' % (os.path.join(os.getcwd(), 'helloworld', 'test.cppcheck')))
    assert ret == 0
    assert stderr == ''
Example #14
0
def test_gui_project_loads_absolute_vs_solution():
    create_gui_project_file('test.cppcheck', import_project=os.path.join(os.getcwd(),'proj2', 'proj2.sln').replace('\\', '/'))
    ret, stdout, stderr = cppcheck('--project=test.cppcheck')
    file1 = os.path.join(os.getcwd(), 'proj2', 'a', 'a.c')
    file2 = os.path.join(os.getcwd(), 'proj2', 'b', 'b.c')
    print(stdout)
    assert ret == 0
    assert stdout.find('Checking %s Debug|Win32...' % (file1)) >= 0
    assert stdout.find('Checking %s Debug|x64...' % (file1)) >= 0
    assert stdout.find('Checking %s Release|Win32...' % (file1)) >= 0
    assert stdout.find('Checking %s Release|x64...' % (file1)) >= 0
    assert stdout.find('Checking %s Debug|Win32...' % (file2)) >= 0
    assert stdout.find('Checking %s Debug|x64...' % (file2)) >= 0
    assert stdout.find('Checking %s Release|Win32...' % (file2)) >= 0
    assert stdout.find('Checking %s Release|x64...' % (file2)) >= 0
Example #15
0
def test_gui_project_loads_absolute_vs_solution():
    create_gui_project_file('test.cppcheck', import_project=os.path.join(os.getcwd(),'proj2', 'proj2.sln').replace('\\', '/'))
    ret, stdout, stderr = cppcheck('--project=test.cppcheck')
    file1 = os.path.join(os.getcwd(), 'proj2', 'a', 'a.c')
    file2 = os.path.join(os.getcwd(), 'proj2', 'b', 'b.c')
    print(stdout)
    assert ret == 0
    assert stdout.find('Checking %s Debug|Win32...' % (file1)) >= 0
    assert stdout.find('Checking %s Debug|x64...' % (file1)) >= 0
    assert stdout.find('Checking %s Release|Win32...' % (file1)) >= 0
    assert stdout.find('Checking %s Release|x64...' % (file1)) >= 0
    assert stdout.find('Checking %s Debug|Win32...' % (file2)) >= 0
    assert stdout.find('Checking %s Debug|x64...' % (file2)) >= 0
    assert stdout.find('Checking %s Release|Win32...' % (file2)) >= 0
    assert stdout.find('Checking %s Release|x64...' % (file2)) >= 0
Example #16
0
def test_gui_project_loads_absolute_vs_solution():
    create_gui_project_file('test.cppcheck',
                            import_project=realpath('proj2/proj2.sln'))
    ret, stdout, stderr = cppcheck(['--project=test.cppcheck'])
    file1 = os.path.realpath('proj2/a/a.c')
    file2 = os.path.realpath('proj2/b/b.c')
    print(stdout)
    assert ret == 0
    assert stdout.find('Checking %s Debug|Win32...' % file1) >= 0
    assert stdout.find('Checking %s Debug|x64...' % file1) >= 0
    assert stdout.find('Checking %s Release|Win32...' % file1) >= 0
    assert stdout.find('Checking %s Release|x64...' % file1) >= 0
    assert stdout.find('Checking %s Debug|Win32...' % file2) >= 0
    assert stdout.find('Checking %s Debug|x64...' % file2) >= 0
    assert stdout.find('Checking %s Release|Win32...' % file2) >= 0
    assert stdout.find('Checking %s Release|x64...' % file2) >= 0
Example #17
0
def test_gui_project_loads_relative_vs_solution():
    create_gui_project_file('test.cppcheck', root_path='proj2', import_project='proj2/proj2.sln', exclude_paths=['b'])
    ret, stdout, stderr = cppcheck('--project=test.cppcheck')
    assert stderr == '[a/a.c:1]: (error) Division by zero.\n'