Skip to content

Commit

Permalink
Fix checking of diagnostics on fatal level
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrdz committed Sep 15, 2015
1 parent 60ad69e commit 5e10263
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 144 deletions.
2 changes: 1 addition & 1 deletion Handlers/DiagnosticHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DiagnosticHandler::DiagnosticHandler(Context& context)

void DiagnosticHandler::HandleDiagnostic(DiagnosticsEngine::Level level, const Diagnostic& info)
{
if (level == DiagnosticsEngine::Level::Error)
if (level == DiagnosticsEngine::Level::Error || level == DiagnosticsEngine::Level::Fatal)
{
if (m_context.areWeInFakeHeaderSourceFile)
{
Expand Down
5 changes: 3 additions & 2 deletions Tests/block_placement_rule_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ def test_for_loop(self):
def test_initializer_list(self):
self.assert_colobot_lint_result(
source_file_lines = [
'#include <vector>',
'#include <initializer_list>',
'struct Foo { Foo(std::initializer_list<int>); };',
'void foo()',
'{',
' std::vector<int> vec{1,2,3,4,5};',
' Foo foo{1,2,3,4,5};',
'}'
],
expected_errors = [])
Expand Down
15 changes: 15 additions & 0 deletions Tests/diagnostic_handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ def test_compile_error_in_source_file(self):
}
])

def test_fatal_compile_error_in_source_file(self):
self.assert_colobot_lint_result(
source_file_lines = [
'#include "nonexistent_include_file.h"',
''
],
expected_errors = [
{
'id': 'compile error',
'severity': 'error',
'msg': "'nonexistent_include_file.h' file not found",
'line': '1'
}
])

def test_compile_error_in_fake_header_source(self):
with test_support.TempBuildDir() as temp_dir:
os.mkdir(temp_dir + '/foo')
Expand Down
117 changes: 90 additions & 27 deletions Tests/include_style_rule_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,36 @@ def assert_colobot_lint_result_with_project_headers(self,
source_file_lines,
cpp_file_path,
project_header_paths,
system_header_paths,
expected_errors):
with test_support.TempBuildDir() as temp_dir:
src_dir = temp_dir + '/src'
os.mkdir(src_dir)
project_dir = temp_dir + '/project'
os.mkdir(project_dir)

system_headers_dir = temp_dir + '/system'
os.mkdir(system_headers_dir)

cpp_file_name = src_dir + '/' + cpp_file_path
cpp_file_name = project_dir + '/' + cpp_file_path
os.makedirs(os.path.dirname(cpp_file_name), exist_ok = True)
test_support.write_file_lines(cpp_file_name, source_file_lines)

for header_path in project_header_paths:
header_file_name = src_dir + '/' + header_path
os.makedirs(os.path.dirname(header_file_name), exist_ok = True)
test_support.write_file_lines(header_file_name, [''])
for project_header_path in project_header_paths:
project_header_file_name = project_dir + '/' + project_header_path
os.makedirs(os.path.dirname(project_header_file_name), exist_ok = True)
test_support.write_file_lines(project_header_file_name, [''])

for system_header_path in system_header_paths:
system_header_file_name = system_headers_dir + '/' + system_header_path
os.makedirs(os.path.dirname(system_header_file_name), exist_ok = True)
test_support.write_file_lines(system_header_file_name, [''])

test_support.write_compilation_database(
build_directory = temp_dir,
source_file_names = [cpp_file_name],
additional_compile_flags = '-I' + src_dir)
additional_compile_flags = '-I{0} -I{1}'.format(project_dir, system_headers_dir))

xml_output = test_support.run_colobot_lint(build_directory = temp_dir,
source_dir = src_dir,
source_dir = project_dir,
source_paths = [cpp_file_name],
rules_selection = self.default_rules_selection)
self.assert_xml_output_match(xml_output, expected_errors)
Expand All @@ -41,12 +50,19 @@ def assert_colobot_lint_result_with_project_headers_and_fake_header_source(self,
header_file_path,
fake_header_source_path,
project_headers,
system_header_paths,
expected_errors):
with test_support.TempBuildDir() as temp_dir:
src_dir = temp_dir + '/src'
project_dir = temp_dir + '/project'
os.mkdir(project_dir)

system_headers_dir = temp_dir + '/system'
os.mkdir(system_headers_dir)

src_dir = project_dir + '/src'
os.mkdir(src_dir)

fake_header_source_file_name = temp_dir + '/' + fake_header_source_path
fake_header_source_file_name = project_dir + '/' + fake_header_source_path
os.makedirs(os.path.dirname(fake_header_source_file_name), exist_ok = True)
test_support.write_file_lines(fake_header_source_file_name, [
'#include "{0}"'.format(header_file_path)
Expand All @@ -61,10 +77,15 @@ def assert_colobot_lint_result_with_project_headers_and_fake_header_source(self,
os.makedirs(os.path.dirname(header_file_name), exist_ok = True)
test_support.write_file_lines(header_file_name, header.get('source_lines', []))

for system_header_path in system_header_paths:
system_header_file_name = system_headers_dir + '/' + system_header_path
os.makedirs(os.path.dirname(system_header_file_name), exist_ok = True)
test_support.write_file_lines(system_header_file_name, [''])

test_support.write_compilation_database(
build_directory = temp_dir,
source_file_names = [fake_header_source_file_name],
additional_compile_flags = '-I' + src_dir)
additional_compile_flags = '-I{0} -I{1}'.format(src_dir, system_headers_dir))

xml_output = test_support.run_colobot_lint(build_directory = temp_dir,
source_dir = src_dir,
Expand Down Expand Up @@ -95,6 +116,7 @@ def test_local_includes_sorted_alphabetically(self):
'def/abc.h',
'def/def.h'
],
system_header_paths = [],
expected_errors = [])

def test_local_includes_not_sorted_alphabetically(self):
Expand All @@ -113,6 +135,7 @@ def test_local_includes_not_sorted_alphabetically(self):
'def/abc.h',
'def/def.h'
],
system_header_paths = [],
expected_errors = [
{
'msg': "Broken alphabetical ordering, expected 'def/abc.h', not 'def/def.h'",
Expand All @@ -135,6 +158,7 @@ def test_local_includes_from_different_subpaths_in_one_block(self):
'def/abc.h',
'def/def.h'
],
system_header_paths = [],
expected_errors = [
{
'msg': "Expected empty line between include directives",
Expand All @@ -143,10 +167,16 @@ def test_local_includes_from_different_subpaths_in_one_block(self):
])

def test_system_includes_dont_need_to_be_sorted_alphabetically(self):
self.assert_colobot_lint_result(
self.assert_colobot_lint_result_with_project_headers(
source_file_lines = [
'#include <string>',
'#include <iostream>',
'#include <system_header2.h>',
'#include <system_header1.h>'
],
cpp_file_path = 'src.cpp',
project_header_paths = [],
system_header_paths = [
'system_header1.h',
'system_header2.h'
],
expected_errors = [])

Expand All @@ -166,6 +196,7 @@ def test_local_include_in_angle_brackets(self):
'def/abc.h',
'def/def.h'
],
system_header_paths = [],
expected_errors = [
{
'msg': "Local include 'def/abc.h' should be included with quotes, not angled brackets",
Expand All @@ -174,15 +205,22 @@ def test_local_include_in_angle_brackets(self):
])

def test_global_include_in_quotes(self):
self.assert_colobot_lint_result(
self.assert_colobot_lint_result_with_project_headers(
source_file_lines = [
'#include <string>',
'#include "sstream"',
'#include <iostream>',
'#include <system_header1.h>',
'#include "system_header2.h"',
'#include <system_header3.h>',
],
cpp_file_path = 'src.cpp',
project_header_paths = [],
system_header_paths = [
'system_header1.h',
'system_header2.h',
'system_header3.h',
],
expected_errors = [
{
'msg': "Global include 'sstream' should be included with angled brackets, not quotes",
'msg': "Global include 'system_header2.h' should be included with angled brackets, not quotes",
'line': '2'
}
])
Expand All @@ -203,6 +241,7 @@ def test_local_include_not_full_path_from_project_root(self):
'def/ghi.h',
'def/jkl.h'
],
system_header_paths = [],
expected_errors = [
{
'msg': "Expected local include to be full relative path from project local include search path: 'def/jkl.h', not 'jkl.h'",
Expand All @@ -215,14 +254,18 @@ def test_local_and_global_includes_in_one_block(self):
source_file_lines = [
'#include "abc.h"',
'#include "def.h"',
'#include <iostream>',
'#include "<sstream>',
'#include <system_header1.h>',
'#include <system_header2.h>'
],
cpp_file_path = 'def/ghi.cpp',
project_header_paths = [
'abc.h',
'def.h'
],
system_header_paths = [
'system_header1.h',
'system_header2.h',
],
expected_errors = [
{
'msg': "Expected empty line between include directives",
Expand All @@ -236,30 +279,38 @@ def test_local_and_global_includes_in_separate_blocks(self):
'#include "abc.h"',
'#include "def.h"',
'',
'#include <iostream>',
'#include <sstream>',
'#include <system_header1.h>',
'#include <system_header2.h>',
],
cpp_file_path = 'def/ghi.cpp',
project_header_paths = [
'abc.h',
'def.h'
],
system_header_paths = [
'system_header1.h',
'system_header2.h'
],
expected_errors = [])

def test_local_include_after_global_include(self):
self.assert_colobot_lint_result_with_project_headers(
source_file_lines = [
'#include "abc.h"',
'',
'#include <iostream>',
'#include <sstream>',
'#include <system_header1.h>',
'#include <system_header2.h>',
'#include "def.h"'
],
cpp_file_path = 'def/ghi.cpp',
project_header_paths = [
'abc.h',
'def.h'
],
system_header_paths = [
'system_header1.h',
'system_header2.h'
],
expected_errors = [
{
'msg': "Local include 'def.h' should not be placed after global includes",
Expand All @@ -286,6 +337,7 @@ def test_config_header_at_the_top(self):
'def/abc.h',
'def/def.h'
],
system_header_paths = [],
expected_errors = [])

def test_config_header_in_one_block_at_the_top(self):
Expand All @@ -306,6 +358,7 @@ def test_config_header_in_one_block_at_the_top(self):
'def/abc.h',
'def/def.h'
],
system_header_paths = [],
expected_errors = [
{
'msg': "Expected empty line between include directives",
Expand All @@ -332,6 +385,7 @@ def test_config_header_not_at_the_top(self):
'def/abc.h',
'def/def.h'
],
system_header_paths = [],
expected_errors = [
{
'msg': "Expected config include directive: 'config/config.h', not 'abc.h'",
Expand Down Expand Up @@ -362,6 +416,7 @@ def test_matching_header_at_the_top(self):
'def/abc.h',
'def/def.h'
],
system_header_paths = [],
expected_errors = [])

def test_matching_header_in_one_block(self):
Expand All @@ -382,6 +437,7 @@ def test_matching_header_in_one_block(self):
'def/abc.h',
'def/def.h'
],
system_header_paths = [],
expected_errors = [
{
'msg': "Expected empty line between include directives",
Expand Down Expand Up @@ -411,6 +467,7 @@ def test_matching_header_and_config_file(self):
'def/abc.h',
'def/def.h'
],
system_header_paths = [],
expected_errors = [])

def test_matching_header_not_at_the_top(self):
Expand All @@ -431,6 +488,7 @@ def test_matching_header_not_at_the_top(self):
'def/abc.h',
'def/def.h'
],
system_header_paths = [],
expected_errors = [
{
'msg': "Expected first include directive to be matching header file: 'src.h', not 'abc.h'",
Expand Down Expand Up @@ -473,6 +531,7 @@ def test_base_class_header_at_the_top(self):
]
},
],
system_header_paths = [],
expected_errors = [])

def test_base_class_header_in_one_block(self):
Expand Down Expand Up @@ -501,6 +560,7 @@ def test_base_class_header_in_one_block(self):
]
},
],
system_header_paths = [],
expected_errors = [
{
'id': 'include style',
Expand All @@ -523,7 +583,7 @@ def test_base_class_header_and_config_file(self):
'#include "def/abc.h"',
'#include "def/def.h"',
'',
'#include <string>',
'#include <system_header.h>',
'',
'class Derived : public Base {};'
],
Expand All @@ -542,4 +602,7 @@ def test_base_class_header_and_config_file(self):
]
},
],
system_header_paths = [
'system_header.h'
],
expected_errors = [])
Loading

0 comments on commit 5e10263

Please sign in to comment.