Exemplo n.º 1
0
int
main ()
{
\treturn 0;
}""".split("\n")


test_file4 = """
int main() {
  return 0;
}""".split("\n")


IndentBear1Test = verify_local_bear(IndentBear,
                                    valid_files=(test_file1,),
                                    invalid_files=(test_file3,),
                                    settings={"use_spaces": "true",
                                              "max_line_length": "80"})


IndentBear2Test = verify_local_bear(IndentBear,
                                    valid_files=(test_file3,),
                                    invalid_files=(),
                                    settings={"use_spaces": "nope",
                                              "max_line_length": "80"})


IndentBear3Test = verify_local_bear(IndentBear,
                                    valid_files=(test_file2,),
                                    invalid_files=(),
                                    settings={"use_spaces": "true",
Exemplo n.º 2
0
from bears.c_languages.CPPLintBear import CPPLintBear
from bears.tests.LocalBearTestHelper import verify_local_bear


test_file = """
int main() {
    return 0;
}
""".split("\n")

CPPLintBear1Test = verify_local_bear(CPPLintBear,
                                     valid_files=(),
                                     invalid_files=(test_file,),
                                     tempfile_kwargs={"suffix": ".cpp"})

CPPLintBear2Test = verify_local_bear(CPPLintBear,
                                     valid_files=(test_file,),
                                     invalid_files=(),
                                     settings={'cpplint_ignore': 'legal'},
                                     tempfile_kwargs={"suffix": ".cpp"})

CPPLintBear3Test = verify_local_bear(CPPLintBear,
                                     valid_files=(),
                                     invalid_files=(test_file,),
                                     settings={'cpplint_ignore': 'legal',
                                               'max_line_length': '13'},
                                     tempfile_kwargs={"suffix": ".cpp"})
Exemplo n.º 3
0
from bears.ruby.RubyLintBear import RubyLintBear
from bears.tests.LocalBearTestHelper import verify_local_bear

good_file = """
class HelloWorld
    def initialize(name)
        @name = name.capitalize
    end
    def sayHi
        puts "Hello #{@name}!"
    end
end
""".split("\n")


bad_file = """
class HelloWorld
    def initialize(name)
        @name = name.capitalize
    end
    def sayHi
        x = 1 # unused variables invoke a warning
        puts "Hello #{@name}!"
    end
"""


RubyLintBearTest = verify_local_bear(RubyLintBear,
                                     valid_files=(good_file,),
                                     invalid_files=(bad_file,))
Exemplo n.º 4
0

test_file2 = """{
    "b": 5,
    "a": 5
}""".split("\n")

test_file3 = """{
   "b": 5,
   "a": 5
}""".split("\n")


JSONFormatBear1Test = verify_local_bear(JSONFormatBear,
                                        valid_files=(test_file1, test_file2),
                                        invalid_files=(test_file3,
                                                       [""],
                                                       ["random stuff"],
                                                       ['{"a":5,"b":5}']))


JSONFormatBear2Test = verify_local_bear(JSONFormatBear,
                                        valid_files=(test_file1,),
                                        invalid_files=(test_file2,),
                                        settings={"json_sort": "true"})


JSONFormatBear3Test = verify_local_bear(JSONFormatBear,
                                        valid_files=(test_file3,),
                                        invalid_files=(test_file2),
                                        settings={"tab_width": "3"})
Exemplo n.º 5
0
from bears.general.LineLengthBear import LineLengthBear
from bears.tests.LocalBearTestHelper import verify_local_bear

test_file = """
test
too
er
e
""".split("\n")

LineLengthBear1Test = verify_local_bear(LineLengthBear,
                                        valid_files=(test_file, ),
                                        invalid_files=(["testa"],
                                                       ["test line"]),
                                        settings={"max_line_length": "4"})

LineLengthBear2Test = verify_local_bear(LineLengthBear,
                                        valid_files=(test_file,
                                                     ["http://a.domain.de"]),
                                        invalid_files=(["asdasd"], ),
                                        settings={
                                            "max_line_length": "4",
                                            "ignore_length_regex": "http://"
                                        })
Exemplo n.º 6
0
from bears.natural_language.MarkdownBear import MarkdownBear
from bears.tests.LocalBearTestHelper import verify_local_bear

test_file1 = """1. abc
1. def
""".splitlines()


test_file2 = """1. abc
2. def
""".splitlines()


MarkdownBear1Test = verify_local_bear(MarkdownBear,
                                      valid_files=(test_file2,),
                                      invalid_files=(test_file1,))

MarkdownBear2Test = verify_local_bear(MarkdownBear,
                                      valid_files=(test_file1,),
                                      invalid_files=(test_file2,),
                                      settings={
                                          "markdown_list_increment": False})
Exemplo n.º 7
0
from bears.css.CSSLintBear import CSSLintBear
from bears.tests.LocalBearTestHelper import verify_local_bear

good_file = """
.class {
  font-weight: 400;
  font-size: 5px;
}
""".split("\n")


bad_file = """
.class {
  font-weight: 400
  font-size: 5px;
}
""".split("\n")


CSSLintBear1Test = verify_local_bear(CSSLintBear,
                                     valid_files=(good_file,),
                                     invalid_files=(bad_file,))
Exemplo n.º 8
0
from bears.c_languages.CPPLintBear import CPPLintBear
from bears.tests.LocalBearTestHelper import verify_local_bear

test_file = """
int main() {
    return 0;
}
""".split(
    "\n"
)

CPPLintBear1Test = verify_local_bear(
    CPPLintBear, valid_files=(), invalid_files=(test_file,), tempfile_kwargs={"suffix": ".cpp"}
)

CPPLintBear2Test = verify_local_bear(
    CPPLintBear,
    valid_files=(test_file,),
    invalid_files=(),
    settings={"cpplint_ignore": "legal"},
    tempfile_kwargs={"suffix": ".cpp"},
)

CPPLintBear3Test = verify_local_bear(
    CPPLintBear,
    valid_files=(),
    invalid_files=(test_file,),
    settings={"cpplint_ignore": "legal", "max_line_length": "13"},
    tempfile_kwargs={"suffix": ".cpp"},
)
Exemplo n.º 9
0
from bears.general.KeywordBear import KeywordBear
from bears.tests.LocalBearTestHelper import verify_local_bear


test_file = """
test line fix me
to do
error fixme
""".split(
    "\n"
)


SpaceConsistencyBearTest = verify_local_bear(
    KeywordBear,
    valid_files=(test_file),
    invalid_files=("test line FIXME", "test line todo", "test line warNING", "test line ERROR"),
    settings={"cs_keywords": "FIXME, ERROR", "ci_keywords": "todo, warning"},
)
Exemplo n.º 10
0
import (
  // Don't gripe about these next two lines.
  _ "compress/zlib"
  _ "syscall"

  /* MATCH /blank import/ */ _ "path/filepath"
)

import (
  "go/ast"
  _ "go/scanner" // Don't gripe about this or the following line.
  _ "go/token"
)

var (
  _ fmt.Stringer // for "fmt"
  _ ast.Node     // for "go/ast"
)
""".split("\n")

GoLintBearTest = verify_local_bear(GoLintBear,
                                   valid_files=(good_file, ),
                                   invalid_files=(bad_file, ))

GoLintBearTest = verify_local_bear(
    GoLintBear,
    valid_files=(),
    invalid_files=(bad_file, ),
    settings={"golint_cli_options": "-min_confidence=0.8"})
from bears.matlab.MatlabIndentationBear import MatlabIndentationBear
from bears.tests.LocalBearTestHelper import verify_local_bear

MatlabIndentationBearTest = verify_local_bear(
    MatlabIndentationBear,
    valid_files=(["if a ~= b\n", "  a\n", "endif\n"],
                 ("if a ~= b\n", "  a\n", "endif\n"),
                 ["if a ~= b\n",
                  "  a\n",
                  "  \n",
                  "else\n",
                  "  a\n",
                  "endif\n"]),
    invalid_files=(["  A"],
                   ["if a ~= b\n", "a\n", "endif\n"],
                   ["if a ~= b\n", " a\n", "endif\n"],
                   ("if a ~= b\n", " a\n", "endif\n"),
                   ["if a ~= b\n",
                    "  a\n",
                    "  else\n",
                    "  a\n",
                    "endif\n"]))
Exemplo n.º 12
0
from bears.tests.LocalBearTestHelper import verify_local_bear
from bears.go.GofmtBear import GofmtBear


GofmtBear = verify_local_bear(
    GofmtBear,
    (["package main", "", "func main() {", "\treturn 1", "}"],),
    (["package main", "func main() {", "    return 1", "}"],),
)
Exemplo n.º 13
0
import sys
import unittest

sys.path.insert(0, ".")
from bears.tests.LocalBearTestHelper import verify_local_bear
from bears.natural_language.LanguageToolBear import LanguageToolBear

LanguageToolBearTest = verify_local_bear(
    LanguageToolBear,
    valid_files=([
        "A correct English sentence sounds nice in everyone's "
        "ears."
    ], ),
    invalid_files=(["  "], ["asdgaasdfgahsadf"], ['"quoted"']),
    settings={'use_spaces': 'true'})

if __name__ == '__main__':
    unittest.main(verbosity=2)
Exemplo n.º 14
0
from bears.html.HTMLLintBear import HTMLLintBear
from bears.tests.LocalBearTestHelper import verify_local_bear

test_file = """
<html>
  <body>
    <h1>Hello, world!</h1>
  </body>
</html>
""".split("\n")

HTMLLintBear1Test = verify_local_bear(HTMLLintBear,
                                      valid_files=(),
                                      invalid_files=(test_file, ),
                                      tempfile_kwargs={"suffix": ".html"})

HTMLLintBear2Test = verify_local_bear(
    HTMLLintBear,
    valid_files=(test_file, ),
    invalid_files=(),
    settings={'htmllint_ignore': 'optional_tag'},
    tempfile_kwargs={"suffix": ".html"})

HTMLLintBear3Test = verify_local_bear(
    HTMLLintBear,
    valid_files=(),
    invalid_files=(test_file, ),
    settings={'htmllint_ignore': 'quotation'},
    tempfile_kwargs={"suffix": ".html"})
Exemplo n.º 15
0
from bears.c_languages.ClangBear import ClangBear
from bears.tests.LocalBearTestHelper import verify_local_bear

ClangBearTest = verify_local_bear(
    ClangBear,
    (["int main() {}"], ),
    (
        ["bad things, this is no C code"],  # Has no fixit
        ["struct { int f0; } x = { f0 :1 };"],  # Has a fixit and no range
        ["int main() {int *b; return b}"]),  # Has a fixit and a range
    'test.c')

ClangBearIgnoreTest = verify_local_bear(
    ClangBear,
    # Should ignore the warning, valid!
    (
        ["struct { int f0; } x = { f0 :1 };"], ),
    (),
    'test.c',
    settings={'clang_cli_options': '-w'})
Exemplo n.º 16
0
from bears.natural_language.LanguageToolBear import LanguageToolBear
from bears.tests.BearTestHelper import generate_skip_decorator
from bears.tests.LocalBearTestHelper import verify_local_bear

try:
    import language_check
    import guess_language
except ImportError as err:
    raise SkipTest(str(err))


LanguageToolBear1Test = verify_local_bear(
    LanguageToolBear,
    valid_files=(["A correct English sentence sounds nice in everyone."],
                 ["Eine korrekte englische Satz klingt nett zu jedermann."]),
    invalid_files=(["  "],
                   ["asdgaasdfgahsadf"],
                   ['"quoted"']))


LanguageToolBear2Test = verify_local_bear(
    LanguageToolBear,
    valid_files=(["A correct English sentence sounds nice in everyone."],),
    invalid_files=(["Eine korrekte englische Satz klingt nett zu jedermann."],),
    settings={'locale': 'en-US'})


@generate_skip_decorator(LanguageToolBear)
class LanguageToolBearTest(unittest.TestCase):
Exemplo n.º 17
0
from bears.html.HTMLLintBear import HTMLLintBear
from bears.tests.LocalBearTestHelper import verify_local_bear


test_file = """
<html>
  <body>
    <h1>Hello, world!</h1>
  </body>
</html>
""".split("\n")

HTMLLintBear1Test = verify_local_bear(HTMLLintBear,
                                      valid_files=(),
                                      invalid_files=(test_file,),
                                      tempfile_kwargs={"suffix": ".html"})

HTMLLintBear2Test = verify_local_bear(HTMLLintBear,
                                      valid_files=(test_file,),
                                      invalid_files=(),
                                      settings={
                                          'htmllint_ignore': 'optional_tag'},
                                      tempfile_kwargs={"suffix": ".html"})

HTMLLintBear3Test = verify_local_bear(HTMLLintBear,
                                      valid_files=(),
                                      invalid_files=(test_file,),
                                      settings={'htmllint_ignore': 'quotation'},
                                      tempfile_kwargs={"suffix": ".html"})
Exemplo n.º 18
0
from bears.c_languages.CPPLintBear import CPPLintBear
from bears.tests.LocalBearTestHelper import verify_local_bear

test_file = """
int main() {
    return 0;
}
""".split("\n")

CPPLintBear1Test = verify_local_bear(CPPLintBear,
                                     valid_files=(),
                                     invalid_files=(test_file,),
                                     tempfile_kwargs={"suffix": ".cpp"})

CPPLintBear2Test = verify_local_bear(CPPLintBear,
                                     valid_files=(test_file,),
                                     invalid_files=(),
                                     settings={'cpplint_ignore': 'legal'},
                                     tempfile_kwargs={"suffix": ".cpp"})

CPPLintBear3Test = verify_local_bear(CPPLintBear,
                                     valid_files=(),
                                     invalid_files=(test_file,),
                                     settings={'cpplint_ignore': 'legal',
                                               'max_line_length': '13'},
                                     tempfile_kwargs={"suffix": ".cpp"})
Exemplo n.º 19
0
from bears.ruby.RubyLintBear import RubyLintBear
from bears.tests.LocalBearTestHelper import verify_local_bear

good_file = """
class HelloWorld
    def initialize(name)
        @name = name.capitalize
    end
    def sayHi
        puts "Hello #{@name}!"
    end
end
""".split("\n")

bad_file = """
class HelloWorld
    def initialize(name)
        @name = name.capitalize
    end
    def sayHi
        x = 1 # unused variables invoke a warning
        puts "Hello #{@name}!"
    end
"""

RubyLintBearTest = verify_local_bear(RubyLintBear,
                                     valid_files=(good_file, ),
                                     invalid_files=(bad_file, ))
Exemplo n.º 20
0
from bears.tests.LocalBearTestHelper import verify_local_bear
from bears.go.GoImportsBear import GoImportsBear

GoImportsBearTest = verify_local_bear(GoImportsBear, ([
    'package main', '', 'import "os"', '', 'func main() {',
    '\tf, _ := os.Open("foo")', '}'
], ), ([
    'package main', '', '', 'func main() {', '\tf, _ := os.Open("foo")', '}'
], ))
Exemplo n.º 21
0
from bears.general.KeywordBear import KeywordBear
from bears.tests.LocalBearTestHelper import verify_local_bear

test_file = """
test line fix me
to do
error fixme
""".split("\n")

SpaceConsistencyBearTest = verify_local_bear(
    KeywordBear,
    valid_files=(test_file),
    invalid_files=("test line FIXME", "test line todo", "test line warNING",
                   "test line ERROR"),
    settings={
        "cs_keywords": "FIXME, ERROR",
        "ci_keywords": "todo, warning"
    })
Exemplo n.º 22
0
from bears.tests.LocalBearTestHelper import verify_local_bear
from bears.go.GoImportsBear import GoImportsBear

GoImportsBearTest = verify_local_bear(
    GoImportsBear,
    (['package main', '', 'import "os"', '',
      'func main() {', '\tf, _ := os.Open("foo")', '}'],),
    (['package main', '', '',
      'func main() {', '\tf, _ := os.Open("foo")', '}'],))
Exemplo n.º 23
0
from bears.python.PyImportSortBear import PyImportSortBear
from bears.tests.LocalBearTestHelper import verify_local_bear


PyImportSortBearTest = verify_local_bear(PyImportSortBear,
                                         (["import os\n", "import sys\n"],),
                                         (["import sys\n", "import os\n"],))
Exemplo n.º 24
0
from bears.tests.LocalBearTestHelper import verify_local_bear
from bears.natural_language.LanguageToolBear import LanguageToolBear


LanguageToolBearTest = verify_local_bear(
    LanguageToolBear,
    valid_files=(["A correct English sentence sounds nice in everyone's "
                  "ears."], ),
    invalid_files=(["  "],
                   ["asdgaasdfgahsadf"],
                   ['"quoted"']),
    settings={'use_spaces': 'true'})
Exemplo n.º 25
0
test_file3 = """
int
main ()
{
\treturn 0;
}""".split("\n")

test_file4 = """
int main() {
  return 0;
}""".split("\n")

IndentBear1Test = verify_local_bear(IndentBear,
                                    valid_files=(test_file1, ),
                                    invalid_files=(test_file3, ),
                                    settings={
                                        "use_spaces": "true",
                                        "max_line_length": "80"
                                    })

IndentBear2Test = verify_local_bear(IndentBear,
                                    valid_files=(test_file3, ),
                                    invalid_files=(),
                                    settings={
                                        "use_spaces": "nope",
                                        "max_line_length": "80"
                                    })

IndentBear3Test = verify_local_bear(IndentBear,
                                    valid_files=(test_file2, ),
                                    invalid_files=(),
Exemplo n.º 26
0
from bears.python.PyImportSortBear import PyImportSortBear
from bears.tests.LocalBearTestHelper import verify_local_bear

PyImportSortBearTest = verify_local_bear(PyImportSortBear,
                                         (["import os\n", "import sys\n"],
                                          ("import os\n", "import sys\n")),
                                         (["import sys\n", "import os\n"],
                                          ("import sys\n", "import os\n")))
Exemplo n.º 27
0
from bears.general.LineLengthBear import LineLengthBear
from bears.tests.LocalBearTestHelper import verify_local_bear

test_file = """
test
too
er
e
""".split(
    "\n"
)


LineLengthBear1Test = verify_local_bear(
    LineLengthBear,
    valid_files=(test_file,),
    invalid_files=(["testa"], ["test line"]),
    settings={"max_line_length": "4"},
)


LineLengthBear2Test = verify_local_bear(
    LineLengthBear,
    valid_files=(test_file, ["http://a.domain.de"]),
    invalid_files=(["asdasd"],),
    settings={"max_line_length": "4", "ignore_length_regex": "http://"},
)
Exemplo n.º 28
0
from bears.natural_language.AlexBear import AlexBear
from bears.tests.LocalBearTestHelper import verify_local_bear

good_file = ["Their network looks good."]

bad_file = ["His network looks good."]

AlexBearTest = verify_local_bear(AlexBear,
                                 valid_files=(good_file, ),
                                 invalid_files=(bad_file, ))
Exemplo n.º 29
0
    yes
""".split("\n")


warning_file = """
# Nested string interpolation
str = "Book by #{"#{firstName} #{lastName}".toUpperCase()}"
""".split("\n")


error_file = """
# Wrong capitalization
class theGangster

  wasItAGoodDay : () ->
    yes
""".split("\n")


invalid_file = """
# Coffeelint is buggy here and will generate an error with invalid CSV on this
var test
""".split("\n")


CoffeeLintBear1Test = verify_local_bear(CoffeeLintBear,
                                        valid_files=(good_file,),
                                        invalid_files=(warning_file,
                                                       error_file,
                                                       invalid_file))
Exemplo n.º 30
0
from bears.tests.LocalBearTestHelper import verify_local_bear
from bears.natural_language.MarkdownBear import MarkdownBear


MarkdownBearTest = verify_local_bear(MarkdownBear,
                                     (["```\n", "some code\n", "```\n"],),
                                     (['    some code'],))
Exemplo n.º 31
0
    "b": 5,
    "a": 5
}""".split("\n")

test_file3 = """{
   "b": 5,
   "a": 5
}""".split("\n")

unicode_file = """{
    "⌘": 5
}""".split("\n")

JSONFormatBear1Test = verify_local_bear(JSONFormatBear,
                                        valid_files=(test_file1, test_file2),
                                        invalid_files=(test_file3,
                                                       unicode_file, [""],
                                                       ["random stuff"
                                                        ], ['{"a":5,"b":5}']))

JSONFormatBear2Test = verify_local_bear(JSONFormatBear,
                                        valid_files=(test_file1, ),
                                        invalid_files=(test_file2, ),
                                        settings={"json_sort": "true"})

JSONFormatBear3Test = verify_local_bear(JSONFormatBear,
                                        valid_files=(test_file3, ),
                                        invalid_files=(test_file2),
                                        settings={"tab_width": "3"})

JSONFormatBearUnicodeTest = verify_local_bear(
    JSONFormatBear,
Exemplo n.º 32
0
var _ os.File // for "os"
""".split("\n")


bad_file = """
package pkg

func addOne(x int) int {
  x += 1
  return x
}

func subOneInLoop(y int) {
  for ; y > 0; y -= 1 {
  }
}
""".split("\n")


GoLintBear1Test = verify_local_bear(GoLintBear,
                                    valid_files=(good_file,),
                                    invalid_files=(bad_file,))


GoLintBear2Test = verify_local_bear(
    GoLintBear,
    valid_files=(bad_file, good_file),
    invalid_files=(),
    settings={"golint_cli_options": "-min_confidence=1"})
Exemplo n.º 33
0
from bears.python.RadonBear import RadonBear
from bears.tests.LocalBearTestHelper import verify_local_bear

test_file1 = """
def simple():
    pass
""".splitlines()

test_file2 = """
class class1():
    pass
""".splitlines()

RadonBear1Test = verify_local_bear(RadonBear,
                                   valid_files=(test_file1, test_file2),
                                   invalid_files=(),
                                   settings={
                                       "radon_ranks_info": "",
                                       "radon_ranks_normal": "",
                                       "radon_ranks_major": ""
                                   })

RadonBear2Test = verify_local_bear(RadonBear,
                                   valid_files=(),
                                   invalid_files=(test_file1, test_file2),
                                   settings={
                                       "radon_ranks_info": "",
                                       "radon_ranks_normal": "A",
                                       "radon_ranks_major": ""
                                   })
Exemplo n.º 34
0
bad_file1 = """
func F() (*MyType, int, error) { return errors.New("foo") }
""".split('\n')

bad_file2 = """
package main

func main() {
    f, _ := os.Open("foo")
    return nil, 0, errors.New("foo")
}

""".split('\n')

a = [
    'import "errors"', '',
    'func F() (*MyType, int, error) { return nil, 0, errors.New("foo") }'
]
b = [
    'package main', '', 'import "os"', '', 'func main() {',
    '\tf, _ := os.Open("foo")', '}'
]

GoReturnsBearTest = verify_local_bear(GoReturnsBear, (
    good_file1,
    good_file2,
), (
    bad_file1,
    bad_file2,
))
Exemplo n.º 35
0
from bears.tests.LocalBearTestHelper import verify_local_bear

test_file1 = """
def simple():
    pass
""".splitlines()


test_file2 = """
class class1():
    pass
""".splitlines()


RadonBear1Test = verify_local_bear(RadonBear,
                                   valid_files=(test_file1, test_file2),
                                   invalid_files=(),
                                   settings={
                                       "radon_ranks_info": "",
                                       "radon_ranks_normal": "",
                                       "radon_ranks_major": ""})


RadonBear2Test = verify_local_bear(RadonBear,
                                   valid_files=(),
                                   invalid_files=(test_file1, test_file2),
                                   settings={
                                       "radon_ranks_info": "",
                                       "radon_ranks_normal": "A",
                                       "radon_ranks_major": ""})
Exemplo n.º 36
0
import "os"

func main() {
\tf, _ := os.Open("foo")
}""".split('\n')

bad_file1 = """
func F() (*MyType, int, error) { return errors.New("foo") }
""".split('\n')

bad_file2 = """
package main

func main() {
    f, _ := os.Open("foo")
    return nil, 0, errors.New("foo")
}

""".split('\n')

a = ['import "errors"', '',
     'func F() (*MyType, int, error) { return nil, 0, errors.New("foo") }']
b = ['package main', '', 'import "os"', '',
     'func main() {', '\tf, _ := os.Open("foo")', '}']

GoReturnsBearTest = verify_local_bear(
    GoReturnsBear,
    (good_file1,
     good_file2,),
    (bad_file1, bad_file2,))
Exemplo n.º 37
0
print "Hello World\n";
""".split("\n")


config_file = """
severity  = 5
# for signatures
[-Subroutines::ProhibitSubroutinePrototypes]

[TestingAndDebugging::RequireUseStrict]

[TestingAndDebugging::RequireUseWarnings]
""".split("\n")


PerlCriticBear1Test = verify_local_bear(PerlCriticBear,
                                        valid_files=(good_file,),
                                        invalid_files=(bad_file,))


with prepare_file(config_file,
                  filename=None,
                  force_linebreaks=True,
                  create_tempfile=True) as (conf_lines, conf_file):
    PerlCriticBear2Test = verify_local_bear(PerlCriticBear,
                                            valid_files=(bad_file),
                                            invalid_files=(),
                                            settings={
                                                "perlcritic_config": conf_file})
Exemplo n.º 38
0
import sys
import unittest

sys.path.insert(0, ".")
from bears.tests.LocalBearTestHelper import verify_local_bear
from bears.c_languages.ClangBear import ClangBear


ClangBearTest = verify_local_bear(
    ClangBear,
    (["int main() {}"], ),
    (["bad things, this is no C code"],  # Has no fixit
     ["struct { int f0; } x = { f0 :1 };"],  # Has a fixit and no range
     ["int main() {int *b; return b}"]),  # Has a fixit and a range
    'test.c')


ClangBearIgnoreTest = verify_local_bear(
    ClangBear,
    # Should ignore the warning, valid!
    (["struct { int f0; } x = { f0 :1 };"],),
    (),
    'test.c',
    settings={'clang_cli_options': '-w'})


if __name__ == '__main__':
    unittest.main(verbosity=2)
Exemplo n.º 39
0
from bears.tests.LocalBearTestHelper import verify_local_bear
from bears.matlab.MatlabIndentationBear import MatlabIndentationBear

MatlabIndentationBearTest = verify_local_bear(
    MatlabIndentationBear,
    valid_files=(["if a ~= b\n", "  a\n", "endif\n"], [
        "if a ~= b\n", "  a\n", "  \n", "else\n", "  a\n", "endif\n"
    ]),
    invalid_files=(["  A"], ["if a ~= b\n", "a\n",
                             "endif\n"], ["if a ~= b\n", " a\n", "endif\n"],
                   ["if a ~= b\n", "  a\n", "  else\n", "  a\n", "endif\n"]))
Exemplo n.º 40
0
import sys

sys.path.insert(0, ".")
import unittest
from bears.tests.LocalBearTestHelper import verify_local_bear
from bears.go.GofmtBear import GofmtBear


GofmtBear = verify_local_bear(
    GofmtBear,
    (['package main', '', 'func main() {', '\treturn 1', '}'],),
    (['package main', 'func main() {', '    return 1', '}'],))


if __name__ == '__main__':
    unittest.main(verbosity=2)
Exemplo n.º 41
0
from bears.general.LineLengthBear import LineLengthBear
from bears.tests.LocalBearTestHelper import verify_local_bear

test_file = """
test
too
er
e
""".split("\n")

LineLengthBear1Test = verify_local_bear(LineLengthBear,
                                        valid_files=(test_file, ),
                                        invalid_files=(["testa"],
                                                       ["test line"]),
                                        settings={"max_line_length": "4"})

LineLengthBear2Test = verify_local_bear(LineLengthBear,
                                        valid_files=(test_file,
                                                     ["http://a.domain.de"]),
                                        invalid_files=(["asdasd"], ),
                                        settings={
                                            "max_line_length": "4",
                                            "ignore_length_regex": "http://, "
                                        })

LineLengthBear3Test = verify_local_bear(LineLengthBear,
                                        valid_files=(test_file,
                                                     ["hi there ftp://!"]),
                                        invalid_files=(["asdasd"], ),
                                        settings={
                                            "max_line_length": "4",
Exemplo n.º 42
0
bad_file = """
#!/usr/bin/perl

print "Hello World\n";
""".split("\n")

config_file = """
severity  = 5
# for signatures
[-Subroutines::ProhibitSubroutinePrototypes]

[TestingAndDebugging::RequireUseStrict]

[TestingAndDebugging::RequireUseWarnings]
""".split("\n")

PerlCriticBear1Test = verify_local_bear(PerlCriticBear,
                                        valid_files=(good_file, ),
                                        invalid_files=(bad_file, ))

with prepare_file(config_file,
                  filename=None,
                  force_linebreaks=True,
                  create_tempfile=True) as (conf_lines, conf_file):
    PerlCriticBear2Test = verify_local_bear(
        PerlCriticBear,
        valid_files=(bad_file),
        invalid_files=(),
        settings={"perlcritic_config": conf_file})
Exemplo n.º 43
0
from bears.css.CSSLintBear import CSSLintBear
from bears.tests.LocalBearTestHelper import verify_local_bear

good_file = """
.class {
  font-weight: 400;
  font-size: 5px;
}
""".split("\n")

bad_file = """
.class {
  font-weight: 400
  font-size: 5px;
}
""".split("\n")

CSSLintBear1Test = verify_local_bear(CSSLintBear,
                                     valid_files=(good_file, ),
                                     invalid_files=(bad_file, ))
Exemplo n.º 44
0
import sys
import unittest

sys.path.insert(0, ".")
from bears.tests.LocalBearTestHelper import verify_local_bear
from bears.natural_language.MarkdownBear import MarkdownBear


MarkdownBearTest = verify_local_bear(MarkdownBear,
                                     (["```\n", "some code\n", "```\n"],),
                                     (['    some code'],))


if __name__ == '__main__':
    unittest.main(verbosity=2)
Exemplo n.º 45
0
""".split("\n")


test_file2 = """
function () {
}()
""".split("\n")


config_file = """
{
  "lastsemic": true,
  "maxlen": 80
}
""".split("\n")


JSHintBear1Test = verify_local_bear(JSHintBear,
                                    valid_files=(),
                                    invalid_files=(test_file1, test_file2))


with prepare_file(config_file,
                  filename=None,
                  force_linebreaks=True,
                  create_tempfile=True) as (conf_lines, conf_file):
    JSHintBear2Test = verify_local_bear(JSHintBear,
                                        valid_files=(test_file1),
                                        invalid_files=(),
                                        settings={"jshint_config": conf_file})
Exemplo n.º 46
0
from bears.go.GofmtBear import GofmtBear
from bears.tests.LocalBearTestHelper import verify_local_bear

GofmtBear = verify_local_bear(
    GofmtBear, (['package main', '', 'func main() {', '\treturn 1', '}'], ),
    (['package main', 'func main() {', '    return 1', '}'], ))
Exemplo n.º 47
0
from bears.natural_language.AlexBear import AlexBear
from bears.tests.LocalBearTestHelper import verify_local_bear

good_file = ["Their network looks good."]

bad_file = ["His network looks good."]


AlexBearTest = verify_local_bear(AlexBear,
                                 valid_files=(good_file,),
                                 invalid_files=(bad_file,))
Exemplo n.º 48
0
from bears.general.LineLengthBear import LineLengthBear
from bears.tests.LocalBearTestHelper import verify_local_bear

test_file = """
test
too
er
e
""".split("\n")


LineLengthBear1Test = verify_local_bear(LineLengthBear,
                                        valid_files=(test_file,),
                                        invalid_files=(["testa"],
                                                       ["test line"]),
                                        settings={"max_line_length": "4"})


LineLengthBear2Test = verify_local_bear(LineLengthBear,
                                        valid_files=(test_file,
                                                     ["http://a.domain.de"]),
                                        invalid_files=(["asdasd"],),
                                        settings={
                                            "max_line_length": "4",
                                            "ignore_length_regex": "http://, "})

LineLengthBear3Test = verify_local_bear(LineLengthBear,
                                        valid_files=(test_file,
                                                     ["hi there ftp://!"]),
                                        invalid_files=(["asdasd"],),
                                        settings={