Skip to content

Commit

Permalink
Skylint: add integration tests for the java binary
Browse files Browse the repository at this point in the history
RELNOTES: none
PiperOrigin-RevId: 171526636
  • Loading branch information
fanzier authored and hlopko committed Oct 10, 2017
1 parent 0bdc2ba commit 8880b7a
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/test/skylark/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package(default_visibility = ["//src:__subpackages__"])

filegroup(
name = "srcs",
srcs = glob(["**"]),
srcs = glob(["**"]) + ["//src/test/skylark/skylint:srcs"],
)

py_test(
Expand Down
17 changes: 17 additions & 0 deletions src/test/skylark/skylint/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package(default_visibility = ["//src:__subpackages__"])

filegroup(
name = "srcs",
srcs = glob(["**"]),
)

py_test(
name = "skylint_test",
srcs = [
"skylint_test.py",
"testenv.py",
],
data = ["//src/tools/skylark/java/com/google/devtools/skylark/skylint:Skylint"] + glob([
"testdata/*",
]),
)
51 changes: 51 additions & 0 deletions src/test/skylark/skylint/skylint_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os.path
import subprocess
import unittest

from src.test.skylark.skylint import testenv


class SkylintTest(unittest.TestCase):

def testGoodFile(self):
output = subprocess.check_output([
testenv.SKYLINT_BINARY_PATH,
os.path.join(testenv.SKYLINT_TESTDATA_PATH, "good.bzl.test")
])
self.assertEqual(output, "")

def testBadFile(self):
try:
issues = ""
subprocess.check_output([
testenv.SKYLINT_BINARY_PATH,
os.path.join(testenv.SKYLINT_TESTDATA_PATH, "bad.bzl.test")
])
except subprocess.CalledProcessError as e:
issues = e.output
self.assertIn("no module docstring", issues)

def testDisablingChecker(self):
output = subprocess.check_output([
testenv.SKYLINT_BINARY_PATH, "--disable=docstring",
os.path.join(testenv.SKYLINT_TESTDATA_PATH, "bad.bzl.test")
])
self.assertEqual(output, "")


if __name__ == "__main__":
unittest.main()
15 changes: 15 additions & 0 deletions src/test/skylark/skylint/testdata/bad.bzl.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

print('Docstring missing')
15 changes: 15 additions & 0 deletions src/test/skylark/skylint/testdata/good.bzl.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This is a docstring."""
17 changes: 17 additions & 0 deletions src/test/skylark/skylint/testenv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test constants for src/test/skylark/skylint."""

SKYLINT_BINARY_PATH = "src/tools/skylark/java/com/google/devtools/skylark/skylint/Skylint"
SKYLINT_TESTDATA_PATH = "src/test/skylark/skylint/testdata/"
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ java_binary(
name = "Skylint",
srcs = [],
main_class = "com.google.devtools.skylark.skylint.Skylint",
visibility = ["//src/test/skylark/skylint:__pkg__"],
runtime_deps = [
":skylint_lib",
],
Expand Down

0 comments on commit 8880b7a

Please sign in to comment.