Skip to content

Commit

Permalink
CPPCheckBearTest.py: Convert test to new style
Browse files Browse the repository at this point in the history
Converted to ease the migration of the bear to a global bear.
  • Loading branch information
khanchi97 authored and gitmate-bot committed Jan 3, 2018
1 parent 9223889 commit b90b72b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 36 deletions.
70 changes: 34 additions & 36 deletions tests/c_languages/CPPCheckBearTest.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import os
from queue import Queue

from bears.c_languages.CPPCheckBear import CPPCheckBear
from coalib.testing.LocalBearTestHelper import verify_local_bear

good_file = """
using namespace std;
int main() {
cout << "Hello, world!" << endl;
return 0;
}"""

warn_file = """
void f1(struct fred_t *p)
{
int x;
if (p)
do_something(x);
}"""

bad_file = """
#define f(c) { \
char s[10]; \
s[c] = 42; \
}
int main() {
f(100);
return 0;
}"""


CPPCheckBearTest1 = verify_local_bear(CPPCheckBear,
valid_files=(good_file, warn_file),
invalid_files=(bad_file,))

CPPCheckBearTest2 = verify_local_bear(CPPCheckBear,
valid_files=(good_file,),
invalid_files=(warn_file, bad_file),
settings={'enable': 'unusedFunction'})
from coalib.testing.BearTestHelper import generate_skip_decorator
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper
from coalib.settings.Section import Section
from coalib.settings.Setting import Setting


def get_absolute_test_path(file):
return os.path.join(os.path.dirname(__file__),
'cppcheck_test_files', file)


@generate_skip_decorator(CPPCheckBear)
class CPPCheckBearTest(LocalBearTestHelper):

def setUp(self):
self.section = Section('cppcheck')
self.uut = CPPCheckBear(self.section, Queue())
self.good_file = get_absolute_test_path('good_file.cpp')
self.bad_file = get_absolute_test_path('bad_file.cpp')
self.warn_file = get_absolute_test_path('warn_file.cpp')

def test_default(self):
self.check_validity(self.uut, [], self.good_file)
self.check_invalidity(self.uut, [], self.bad_file)
self.check_validity(self.uut, [], self.warn_file)

def test_enable(self):
self.section.append(Setting('enable', 'unusedFunction'))
self.check_validity(self.uut, [], self.good_file)
self.check_invalidity(self.uut, [], self.bad_file)
self.check_invalidity(self.uut, [], self.warn_file)
8 changes: 8 additions & 0 deletions tests/c_languages/cppcheck_test_files/bad_file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#define f(c) { \
char s[10]; \
s[c] = 42; \
}
int main() {
f(100);
return 0;
}
5 changes: 5 additions & 0 deletions tests/c_languages/cppcheck_test_files/good_file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using namespace std;
int main() {
cout << "Hello, world!" << endl;
return 0;
}
6 changes: 6 additions & 0 deletions tests/c_languages/cppcheck_test_files/warn_file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void f1(struct fred_t *p)
{
int x;
if (p)
do_something(x);
}

0 comments on commit b90b72b

Please sign in to comment.