diff --git a/TestFile.py b/TestFile.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bears/java/CheckstyleBear.py b/bears/java/CheckstyleBear.py index e5c7771d49..866e3f0394 100644 --- a/bears/java/CheckstyleBear.py +++ b/bears/java/CheckstyleBear.py @@ -10,6 +10,11 @@ "geosoft": "http://geosoft.no/development/geosoft_checks.xml"} +def invalid_configuration(checkstyle_configs, use_spaces, indent_size): + return (checkstyle_configs == 'google' and + (not use_spaces or indent_size != 2)) + + def known_checkstyle_or_path(setting): if str(setting) in known_checkstyles.keys(): return str(setting) @@ -42,9 +47,9 @@ def setup_dependencies(self): '/checkstyle-6.15-all.jar', "checkstyle.jar") - def create_arguments( - self, filename, file, config_file, - checkstyle_configs: known_checkstyle_or_path="google"): + def create_arguments(self, filename, file, config_file, + checkstyle_configs: known_checkstyle_or_path="google", + use_spaces: bool=True, indent_size: int = 2): """ :param checkstyle_configs: A file containing configs to use in ``checkstyle``. It can also @@ -64,6 +69,9 @@ def create_arguments( - geosoft - The Java style followed by GeoSoft. More info at """ + if invalid_configuration(checkstyle_configs, use_spaces, indent_size): + raise ValueError('Invalid configuration! Cannot proceed.') + if checkstyle_configs in known_checkstyles: checkstyle_configs = self.download_cached_file( known_checkstyles[checkstyle_configs], diff --git a/tests/java/CheckstyleBearTest.py b/tests/java/CheckstyleBearTest.py index 8f283e2eed..feb10258a0 100644 --- a/tests/java/CheckstyleBearTest.py +++ b/tests/java/CheckstyleBearTest.py @@ -30,6 +30,18 @@ def test_known_configs(self): self.section["checkstyle_configs"] = "google" self.check_validity(self.uut, [], self.good_file) + def test_config_failure_use_spaces(self): + self.section["checkstyle_configs"] = "google" + self.section.append(Setting('use_spaces', False)) + with self.assertRaises(AssertionError): + self.check_validity(self.uut, [], self.good_file) + + def test_config_failure_indent_size(self): + self.section["checkstyle_configs"] = "google" + self.section.append(Setting('indent_size', 3)) + with self.assertRaises(AssertionError): + self.check_validity(self.uut, [], self.good_file) + def test_with_custom_configfile(self): self.section["checkstyle_configs"] = self.empty_config self.check_validity(self.uut, [], self.good_file)