Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Move the remaining C++-specific assumptions out of dxr.testing.
Browse files Browse the repository at this point in the history
SingleFileTestCase is now language-agnostic but still concrete.

Deleted a few MINIMAL_MAINs that were there only to make the compiler happy. Now we don't run the compiler in those cases. As a bonus, those tests will be a bit faster.
  • Loading branch information
erikrose committed Nov 6, 2015
1 parent 4cd40cc commit ea076e8
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 95 deletions.
22 changes: 21 additions & 1 deletion dxr/plugins/clang/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
"""Tests specific to the clang plugin"""
from dxr.testing import SingleFileTestCase


class CSingleFileTestCase(SingleFileTestCase):
source_filename = 'main.cpp'

@classmethod
def config_input(cls, config_dir_path):
input = super(CSingleFileTestCase, cls).config_input(config_dir_path)
input['DXR']['enabled_plugins'] = 'pygmentize clang'
input['code']['build_command'] = '$CXX -o main main.cpp'
return input


# Tests that don't otherwise need a main() can append this one just to get
# their code to compile:
MINIMAL_MAIN = """
int main(int argc, char* argv[]) {
return 0;
}
"""
6 changes: 3 additions & 3 deletions dxr/plugins/clang/tests/test_callers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Tests for searches using callers"""

from dxr.testing import SingleFileTestCase, MINIMAL_MAIN
from dxr.plugins.clang.tests import CSingleFileTestCase, MINIMAL_MAIN


class DirectCallTests(SingleFileTestCase):
class DirectCallTests(CSingleFileTestCase):
"""Tests for searches involving direct calls"""

source = r"""
Expand Down Expand Up @@ -48,7 +48,7 @@ def test_two_callers(self):
('<b>called_twice()</b>;', 22)])


class IndirectCallTests(SingleFileTestCase):
class IndirectCallTests(CSingleFileTestCase):
"""Tests for searches involving indirect (virtual) calls"""

source = r"""
Expand Down
8 changes: 4 additions & 4 deletions dxr/plugins/clang/tests/test_decl.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Tests for searches for declarations"""

from dxr.testing import SingleFileTestCase, MINIMAL_MAIN
from dxr.plugins.clang.tests import CSingleFileTestCase, MINIMAL_MAIN


class TypeDeclarationTests(SingleFileTestCase):
class TypeDeclarationTests(CSingleFileTestCase):
"""Tests for declarations of types"""

source = r"""
Expand All @@ -19,7 +19,7 @@ def test_type(self):
'type-decl:MyClass', 'class <b>MyClass</b>;')


class FunctionDeclarationTests(SingleFileTestCase):
class FunctionDeclarationTests(CSingleFileTestCase):
"""Tests for declarations of functions"""

source = r"""
Expand All @@ -35,7 +35,7 @@ def test_function(self):
'function-decl:foo', 'void <b>foo</b>();')


class VariableDeclarationTests(SingleFileTestCase):
class VariableDeclarationTests(CSingleFileTestCase):
"""Tests for declarations of variables"""

source = r"""
Expand Down
6 changes: 3 additions & 3 deletions dxr/plugins/clang/tests/test_direct.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os.path

from dxr.query import Query
from dxr.testing import SingleFileTestCase, MINIMAL_MAIN
from dxr.plugins.clang.tests import CSingleFileTestCase, MINIMAL_MAIN

from nose.tools import eq_


class TypeAndMethodTests(SingleFileTestCase):
class TypeAndMethodTests(CSingleFileTestCase):
source = """
class MemberFunction {
public:
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_type_sensitive(self):
self.direct_result_eq('MemberFunction', 2)


class MacroTypedefTests(SingleFileTestCase):
class MacroTypedefTests(CSingleFileTestCase):
source = """
#ifndef MACRO_NAME
#define MACRO_NAME(arg1, arg2) 0
Expand Down
10 changes: 5 additions & 5 deletions dxr/plugins/clang/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from nose import SkipTest

from dxr.testing import SingleFileTestCase, MINIMAL_MAIN
from dxr.plugins.clang.tests import CSingleFileTestCase, MINIMAL_MAIN


class DefinitionTests(SingleFileTestCase):
class DefinitionTests(CSingleFileTestCase):
"""Tests for finding where functions are defined"""

source = r"""
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_qualnames_caseless(self):
self.found_nothing('+function:SPACE::FOO(int)', is_case_sensitive=False)


class TemplateClassMemberReferenceTests(SingleFileTestCase):
class TemplateClassMemberReferenceTests(CSingleFileTestCase):
"""Tests for finding out where member functions of a template class are referenced or declared"""

source = r"""
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_function_ref(self):
[('Foo&lt;int&gt;().<b>bar</b>();', 16)])


class ConstTests(SingleFileTestCase):
class ConstTests(CSingleFileTestCase):
source = """
class ConstOverload
{
Expand All @@ -125,7 +125,7 @@ def test_const_functions(self):
'void ConstOverload::<b>foo</b>() const {')


class PrototypeParamTests(SingleFileTestCase):
class PrototypeParamTests(CSingleFileTestCase):
source = """
int prototype_parameter_function(int prototype_parameter);
Expand Down
4 changes: 2 additions & 2 deletions dxr/plugins/clang/tests/test_inheritance.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Tests for queries about superclasses and subclasses"""

from dxr.testing import SingleFileTestCase, MINIMAL_MAIN
from dxr.plugins.clang.tests import CSingleFileTestCase, MINIMAL_MAIN


class InheritanceTests(SingleFileTestCase):
class InheritanceTests(CSingleFileTestCase):
source = r"""
class A {
};
Expand Down
12 changes: 6 additions & 6 deletions dxr/plugins/clang/tests/test_macros.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dxr.testing import SingleFileTestCase, MINIMAL_MAIN
from dxr.plugins.clang.tests import CSingleFileTestCase, MINIMAL_MAIN


class MacroTests(SingleFileTestCase):
class MacroTests(CSingleFileTestCase):
"""Tests for ``macro`` queries"""

source = """
Expand All @@ -19,7 +19,7 @@ def test_parametrized(self):
self.found_line_eq('macro:ADD', '#define <b>ADD</b>(x, y) ((x) + (y))')


class MacroRefTests(SingleFileTestCase):
class MacroRefTests(CSingleFileTestCase):
"""Tests for ``+macro-ref`` queries"""

source = """
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_refs(self):
('#undef <b>MACRO</b>', 13)])


class MacroArgumentReferenceTests(SingleFileTestCase):
class MacroArgumentReferenceTests(CSingleFileTestCase):
source = """
#define ID2(x) (x)
#define ID(x) ID2(x)
Expand All @@ -82,7 +82,7 @@ def test_refs(self):
('ADD(x, <b>y</b>);', 12)])


class MacroArgumentFieldReferenceTests(SingleFileTestCase):
class MacroArgumentFieldReferenceTests(CSingleFileTestCase):
source = """
#define ID2(x) (x)
#define ID(x) ID2(x)
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_refs(self):
('FIELD(foo, <b>bar</b>);', 18)])


class MacroArgumentDeclareTests(SingleFileTestCase):
class MacroArgumentDeclareTests(CSingleFileTestCase):

source = """
#define ID2(x) x
Expand Down
12 changes: 6 additions & 6 deletions dxr/plugins/clang/tests/test_members.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dxr.testing import SingleFileTestCase, MINIMAL_MAIN
from dxr.plugins.clang.tests import CSingleFileTestCase, MINIMAL_MAIN


class MemberVariableTests(SingleFileTestCase):
class MemberVariableTests(CSingleFileTestCase):
source = """
class MemberVariable {
public:
Expand All @@ -16,7 +16,7 @@ def test_member_variable(self):
'int <b>member_variable</b>;')


class MemberVariableCtorTests(SingleFileTestCase):
class MemberVariableCtorTests(CSingleFileTestCase):
"""Members that do not have an explicit initializer on the constructor
should not show the constructor as having a reference to that member.
There's no convenient place in the source to use for the extents for such
Expand Down Expand Up @@ -44,7 +44,7 @@ def test_explicit_init(self):
self.found_line_eq('+var-ref:Foo::baz', 'Foo() : <b>baz</b>(0) {}')


class MemberFunctionTests(SingleFileTestCase):
class MemberFunctionTests(CSingleFileTestCase):
source = """
class MemberFunction {
public:
Expand All @@ -62,7 +62,7 @@ def test_member_function(self):
u'void MemberFunction::<b>member_function</b>() {')


class StaticMemberTests(SingleFileTestCase):
class StaticMemberTests(CSingleFileTestCase):
source = """
class StaticMember {
public:
Expand All @@ -76,7 +76,7 @@ def test_static_members(self):
self.found_line_eq('+var:StaticMember::static_member', 'int StaticMember::<b>static_member</b> = 0;')


class MemberTests(SingleFileTestCase):
class MemberTests(CSingleFileTestCase):
# We could probably strip this down a fair bit:
source = """
#include <stdint.h>
Expand Down
14 changes: 7 additions & 7 deletions dxr/plugins/clang/tests/test_namespaces.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Tests for searches about namespaces"""

from dxr.testing import SingleFileTestCase, MINIMAL_MAIN
from dxr.plugins.clang.tests import CSingleFileTestCase, MINIMAL_MAIN


class NamespaceDefTests(SingleFileTestCase):
class NamespaceDefTests(CSingleFileTestCase):
"""Tests for finding definitions of namespaces"""

source = r"""
Expand All @@ -22,7 +22,7 @@ def test_namespace_definitions(self):
self.found_line_eq('+namespace:Outer::Inner', 'namespace <b>Inner</b> {')


class NamespaceExprRefTests(SingleFileTestCase):
class NamespaceExprRefTests(CSingleFileTestCase):
"""Tests for finding references to namespaces in expressions"""

source = r"""
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_namespace_expression_references(self):
self.found_line_eq('+namespace-ref:Outer::Inner', 'Outer::<b>Inner</b>::bar();')


class NamespaceDeclRefTests(SingleFileTestCase):
class NamespaceDeclRefTests(CSingleFileTestCase):
"""Tests for finding references to namespaces in declarations"""

source = r"""
Expand All @@ -75,7 +75,7 @@ def test_namespace_declaration_references(self):
self.found_line_eq('+namespace-ref:Outer::Inner', 'Outer::<b>Inner</b>::MyClass *y;')


class NamespaceUsingDirectiveTests(SingleFileTestCase):
class NamespaceUsingDirectiveTests(CSingleFileTestCase):
"""Tests for the 'using' directive"""

source = r"""
Expand All @@ -94,7 +94,7 @@ def test_namespace_using_directive_references(self):
self.found_line_eq('+namespace-ref:Outer::Inner', 'using namespace Outer::<b>Inner</b>;')


class NamespaceUsingDeclarationTests(SingleFileTestCase):
class NamespaceUsingDeclarationTests(CSingleFileTestCase):
"""Tests for the 'using' declaration"""

source = r"""
Expand All @@ -121,7 +121,7 @@ def test_namespace_using_declaration_references(self):
self.found_line_eq('+namespace-ref:Outer::Inner', 'using Outer::<b>Inner</b>::bar;')


class NamespaceAliasTests(SingleFileTestCase):
class NamespaceAliasTests(CSingleFileTestCase):
"""Tests for namespace aliases"""

source = r"""
Expand Down
6 changes: 3 additions & 3 deletions dxr/plugins/clang/tests/test_operator_call.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dxr.testing import SingleFileTestCase
from dxr.plugins.clang.tests import CSingleFileTestCase


class OperatorCallTests(SingleFileTestCase):
class OperatorCallTests(CSingleFileTestCase):
source = """
struct Foo
{
Expand Down Expand Up @@ -41,7 +41,7 @@ def test_subscript_argument(self):
'foo[<b>beta</b>];')


class ExplicitOperatorCallTests(SingleFileTestCase):
class ExplicitOperatorCallTests(CSingleFileTestCase):
source = """
struct Foo
{
Expand Down
12 changes: 6 additions & 6 deletions dxr/plugins/clang/tests/test_overrides.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Tests for searches about overrides of virtual methods"""

from dxr.testing import SingleFileTestCase, MINIMAL_MAIN
from dxr.plugins.clang.tests import CSingleFileTestCase, MINIMAL_MAIN
import nose.tools


class SingleOverrideTests(SingleFileTestCase):
class SingleOverrideTests(CSingleFileTestCase):
source = r"""
class Base {
virtual void foo();
Expand All @@ -29,7 +29,7 @@ def test_overrides(self):
'+overrides:Base::foo()', 'void Derived::<b>foo</b>() {')


class ParallelOverrideTests(SingleFileTestCase):
class ParallelOverrideTests(CSingleFileTestCase):
"""Test overrides for two classes that both directly inherit from one base
class."""

Expand Down Expand Up @@ -63,7 +63,7 @@ def test_overrides(self):
('void DerivedB::<b>foo</b>() {', 15)])


class HierarchyOverrideTests(SingleFileTestCase):
class HierarchyOverrideTests(CSingleFileTestCase):
"""Test overrides in a three class hierarchy."""

source = r"""
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_overrides(self):
'void Derived2::<b>foo</b>() {')


class HierarchyImplicitOverrideTests(SingleFileTestCase):
class HierarchyImplicitOverrideTests(CSingleFileTestCase):
"""Test overrides in a three class hierarchy where the middle class does
not explictly define the method."""

Expand Down Expand Up @@ -128,7 +128,7 @@ def test_overrides(self):
'void Derived2::<b>foo</b>() {')


class MultipleOverrides(SingleFileTestCase):
class MultipleOverrides(CSingleFileTestCase):
"""Test overrides when one method simultanously overrides more than one
other method."""

Expand Down
8 changes: 4 additions & 4 deletions dxr/plugins/clang/tests/test_type_templates.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dxr.testing import SingleFileTestCase, MINIMAL_MAIN
from dxr.plugins.clang.tests import CSingleFileTestCase, MINIMAL_MAIN


class TypeTests(SingleFileTestCase):
class TypeTests(CSingleFileTestCase):
source = r"""
template <typename T>
class Foo
Expand All @@ -19,7 +19,7 @@ def test_simple_type(self):
self.found_line_eq('type-ref:Foo',
'<b>Foo</b>&lt;int&gt;();')

class BaseClassTests(SingleFileTestCase):
class BaseClassTests(CSingleFileTestCase):
source = r"""
template <typename T>
class Foo
Expand All @@ -35,7 +35,7 @@ def test_base_class(self):
self.found_line_eq('type-ref:Foo',
'class Bar : public <b>Foo</b>&lt;T&gt;')

class TemplateParameterTests(SingleFileTestCase):
class TemplateParameterTests(CSingleFileTestCase):
source = r"""
template <typename T>
class Foo
Expand Down
Loading

0 comments on commit ea076e8

Please sign in to comment.