diff --git a/golden-files/input/clojure-util.java b/golden-files/input/clojure-util.java new file mode 100644 index 0000000..02b5466 --- /dev/null +++ b/golden-files/input/clojure-util.java @@ -0,0 +1,197 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) + * which can be found in the file epl-v10.html at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + **/ + +/* rich Apr 19, 2008 */ + +package clojure.lang; + +import java.lang.ref.Reference; +import java.math.BigInteger; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.lang.ref.SoftReference; +import java.lang.ref.ReferenceQueue; + +public class Util{ +static public boolean equiv(Object k1, Object k2){ + if(k1 == k2) + return true; + if(k1 != null) + { + if(k1 instanceof Number && k2 instanceof Number) + return Numbers.equal((Number)k1, (Number)k2); + else if(k1 instanceof IPersistentCollection || k2 instanceof IPersistentCollection) + return pcequiv(k1,k2); + return k1.equals(k2); + } + return false; +} + +static public boolean equiv(long k1, long k2){ + return k1 == k2; +} + +static public boolean equiv(Object k1, long k2){ + return equiv(k1, (Object)k2); +} + +static public boolean equiv(long k1, Object k2){ + return equiv((Object)k1, k2); +} + +static public boolean equiv(double k1, double k2){ + return k1 == k2; +} + +static public boolean equiv(Object k1, double k2){ + return equiv(k1, (Object)k2); +} + +static public boolean equiv(double k1, Object k2){ + return equiv((Object)k1, k2); +} + +static public boolean equiv(boolean k1, boolean k2){ + return k1 == k2; +} + +static public boolean equiv(Object k1, boolean k2){ + return equiv(k1, (Object)k2); +} + +static public boolean equiv(boolean k1, Object k2){ + return equiv((Object)k1, k2); +} + +static public boolean equiv(char c1, char c2) { + return c1 == c2; +} + +static public boolean pcequiv(Object k1, Object k2){ + if(k1 instanceof IPersistentCollection) + return ((IPersistentCollection)k1).equiv(k2); + return ((IPersistentCollection)k2).equiv(k1); +} + +static public boolean equals(Object k1, Object k2){ + if(k1 == k2) + return true; + return k1 != null && k1.equals(k2); +} + +static public boolean identical(Object k1, Object k2){ + return k1 == k2; +} + +static public Class classOf(Object x){ + if(x != null) + return x.getClass(); + return null; +} + +static public int compare(Object k1, Object k2){ + if(k1 == k2) + return 0; + if(k1 != null) + { + if(k2 == null) + return 1; + if(k1 instanceof Number) + return Numbers.compare((Number) k1, (Number) k2); + return ((Comparable) k1).compareTo(k2); + } + return -1; +} + +static public int hash(Object o){ + if(o == null) + return 0; + return o.hashCode(); +} + +static public int hasheq(Object o){ + if(o == null) + return 0; + if(o instanceof Number) + return Numbers.hasheq((Number)o); + else if(o instanceof IHashEq) + return ((IHashEq)o).hasheq(); + return o.hashCode(); +} + +static public int hashCombine(int seed, int hash){ + //a la boost + seed ^= hash + 0x9e3779b9 + (seed << 6) + (seed >> 2); + return seed; +} + +static public boolean isPrimitive(Class c){ + return c != null && c.isPrimitive() && !(c == Void.TYPE); +} + +static public boolean isInteger(Object x){ + return x instanceof Integer + || x instanceof Long + || x instanceof BigInt + || x instanceof BigInteger; +} + +static public Object ret1(Object ret, Object nil){ + return ret; +} + +static public ISeq ret1(ISeq ret, Object nil){ + return ret; +} + +static public void clearCache(ReferenceQueue rq, ConcurrentHashMap> cache){ + //cleanup any dead entries + if(rq.poll() != null) + { + while(rq.poll() != null) + ; + for(Map.Entry> e : cache.entrySet()) + { + Reference val = e.getValue(); + if(val != null && val.get() == null) + cache.remove(e.getKey(), val); + } + } +} + +static public RuntimeException runtimeException(String s){ + return new RuntimeException(s); +} + +static public RuntimeException runtimeException(String s, Throwable e){ + return new RuntimeException(s, e); +} + +/** + * Throw even checked exceptions without being required + * to declare them or catch them. Suggested idiom: + *

+ * throw sneakyThrow( some exception ); + */ +static public RuntimeException sneakyThrow(Throwable t) { + // http://www.mail-archive.com/javaposse@googlegroups.com/msg05984.html + if (t == null) + throw new NullPointerException(); + Util.sneakyThrow0(t); + return null; +} + +@SuppressWarnings("unchecked") +static private void sneakyThrow0(Throwable t) throws T { + throw (T) t; +} + +} + diff --git a/golden-files/input/hello.c b/golden-files/input/hello.c new file mode 100644 index 0000000..c3ce445 --- /dev/null +++ b/golden-files/input/hello.c @@ -0,0 +1,7 @@ +#include + +int main() +{ + printf("Hello World\n"); + return 0; +} diff --git a/golden-files/input/hello.h b/golden-files/input/hello.h new file mode 100644 index 0000000..f19e5d3 --- /dev/null +++ b/golden-files/input/hello.h @@ -0,0 +1,6 @@ +#ifndef HELLO_H +#define HELLO_H + +void hello(); + +#endif diff --git a/golden-files/results/antic-closure-util_java b/golden-files/results/antic-closure-util_java new file mode 100644 index 0000000..60fa776 --- /dev/null +++ b/golden-files/results/antic-closure-util_java @@ -0,0 +1 @@ +Verification completed: 0 reported messages diff --git a/golden-files/results/splint-hello_c b/golden-files/results/splint-hello_c new file mode 100644 index 0000000..87164bf --- /dev/null +++ b/golden-files/results/splint-hello_c @@ -0,0 +1,3 @@ +Splint 3.1.2 --- 03 May 2009 + +Finished checking --- no warnings \ No newline at end of file diff --git a/golden-files/results/splint-hello_h b/golden-files/results/splint-hello_h new file mode 100644 index 0000000..87164bf --- /dev/null +++ b/golden-files/results/splint-hello_h @@ -0,0 +1,3 @@ +Splint 3.1.2 --- 03 May 2009 + +Finished checking --- no warnings \ No newline at end of file diff --git a/golden-files/results/uncrustify-closure-util_java b/golden-files/results/uncrustify-closure-util_java new file mode 100644 index 0000000..9941620 --- /dev/null +++ b/golden-files/results/uncrustify-closure-util_java @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/golden-files/results/uncrustify-hello_c b/golden-files/results/uncrustify-hello_c new file mode 100644 index 0000000..7a28916 --- /dev/null +++ b/golden-files/results/uncrustify-hello_c @@ -0,0 +1,8 @@ +#include  + +int main() +{ + printf("Hello World\n"); + return 0; +} +  \ No newline at end of file diff --git a/golden-files/results/uncrustify-hello_h b/golden-files/results/uncrustify-hello_h new file mode 100644 index 0000000..3bbd8f4 --- /dev/null +++ b/golden-files/results/uncrustify-hello_h @@ -0,0 +1,7 @@ +#ifndef HELLO_H +#define HELLO_H + +void hello(); + +#endif +  \ No newline at end of file diff --git a/tools.py b/tools.py index d4906af..8a2eac5 100644 --- a/tools.py +++ b/tools.py @@ -431,7 +431,7 @@ perl6_syntax.dependencies = {"perl6"} def _jlint_tool(tool_type, path): stdout, *rest = _do_command([tool_type, path]) status = (Status.ok - if b"Verification completed: 0 reported messages." in stdout + if "Verification completed: 0 reported messages." in stdout else Status.problem) return status, fill3.Text(stdout) @@ -543,10 +543,9 @@ def uncrustify(path): config_path = os.path.join(temp_dir, "uncrustify.cfg") stdout, stderr, returncode = _do_command( ["uncrustify", "--detect", "-f", path, "-o", config_path]) - if returncode != 0: - raise AssertionError - stdout, stderr, returncode = _do_command( - ["uncrustify", "-c", config_path, "-f", path]) + if returncode == 0: + stdout, stderr, returncode = _do_command( + ["uncrustify", "-c", config_path, "-f", path]) status = Status.normal if returncode == 0 else Status.problem source_widget = _syntax_highlight_code(stdout, path) return status, source_widget diff --git a/tools_test.py b/tools_test.py index b663396..8f7ffe6 100755 --- a/tools_test.py +++ b/tools_test.py @@ -43,11 +43,13 @@ def run_tool(tool, input_filename): class ToolsTestCase(unittest.TestCase): - def _test_tool(self, tool, input_filename, expected_status): - status, result = run_tool(tool, input_filename) - golden_path = result_path(tool, input_filename) - golden.assertGolden(widget_to_string(result), golden_path) - self.assertEqual(status, expected_status) + def _sub_tests(self, sub_tests): + for tool, input_filename, expected_status in sub_tests: + with self.subTest(input_filename=input_filename): + status, result = run_tool(tool, input_filename) + golden_path = result_path(tool, input_filename) + golden.assertGolden(widget_to_string(result), golden_path) + self.assertEqual(status, expected_status) def test_metadata(self): mock_stat_result = unittest.mock.Mock( @@ -59,57 +61,73 @@ class ToolsTestCase(unittest.TestCase): return_value=mock_stat_result): with unittest.mock.patch.object(tools.pwd, "getpwuid", return_value=mock_pw_entry): - self._test_tool(tools.metadata, "hi3.py", - tools.Status.normal) + self._sub_tests([ + (tools.metadata, "hi3.py", tools.Status.normal)]) def test_contents(self): - self._test_tool(tools.contents, "hi3.py", tools.Status.normal) + self._sub_tests([(tools.contents, "hi3.py", tools.Status.normal)]) def test_python_syntax(self): - self._test_tool(tools.python_syntax, "hi3.py", tools.Status.ok) + self._sub_tests([(tools.python_syntax, "hi3.py", tools.Status.ok)]) def test_unittests(self): - self._test_tool(tools.python_unittests, "hi3.py", - tools.Status.not_applicable) + self._sub_tests([ + (tools.python_unittests, "hi3.py", tools.Status.not_applicable)]) def test_pydoc(self): - self._test_tool(tools.pydoc, "hi3.py", tools.Status.normal) + self._sub_tests([(tools.pydoc, "hi3.py", tools.Status.normal)]) def test_python_coverage(self): - self._test_tool(tools.python_coverage, "hi3.py", tools.Status.normal) + self._sub_tests([ + (tools.python_coverage, "hi3.py", tools.Status.normal)]) def test_pep8(self): - self._test_tool(tools.pep8, "hi3.py", tools.Status.ok) + self._sub_tests([(tools.pep8, "hi3.py", tools.Status.ok)]) def test_pyflakes(self): - self._test_tool(tools.pyflakes, "hi3.py", tools.Status.ok) + self._sub_tests([(tools.pyflakes, "hi3.py", tools.Status.ok)]) def test_pylint(self): - self._test_tool(tools.pylint, "hi3.py", tools.Status.ok) + self._sub_tests([(tools.pylint, "hi3.py", tools.Status.ok)]) def test_python_gut(self): - self._test_tool(tools.python_gut, "hi3.py", tools.Status.normal) + self._sub_tests([(tools.python_gut, "hi3.py", tools.Status.normal)]) def test_python_modulefinder(self): - self._test_tool(tools.python_modulefinder, "hi3.py", - tools.Status.normal) + self._sub_tests([ + (tools.python_modulefinder, "hi3.py", tools.Status.normal)]) def test_python_mccable(self): - self._test_tool(tools.python_mccabe, "hi3.py", tools.Status.ok) + self._sub_tests([(tools.python_mccabe, "hi3.py", tools.Status.ok)]) def test_perl_syntax(self): - self._test_tool(tools.perl_syntax, "perl.pl", tools.Status.ok) + self._sub_tests([(tools.perl_syntax, "perl.pl", tools.Status.ok)]) def test_perldoc(self): - self._test_tool(tools.perldoc, "perl.pl", - tools.Status.not_applicable) - self._test_tool(tools.perldoc, "contents.pod", tools.Status.normal) + self._sub_tests([ + (tools.perldoc, "perl.pl", tools.Status.not_applicable), + (tools.perldoc, "contents.pod", tools.Status.normal)]) def test_perltidy(self): - self._test_tool(tools.perltidy, "perl.pl", tools.Status.normal) + self._sub_tests([(tools.perltidy, "perl.pl", tools.Status.normal)]) def test_perl6_syntax(self): - self._test_tool(tools.perl6_syntax, "perl6.p6", tools.Status.problem) + self._sub_tests([ + (tools.perl6_syntax, "perl6.p6", tools.Status.problem)]) + + def test_antic(self): + self._sub_tests([ + (tools.antic, "closure-util.java", tools.Status.problem)]) + + def test_uncrustify(self): + self._sub_tests([ + (tools.uncrustify, "closure-util.java", tools.Status.problem), + (tools.uncrustify, "hello.c", tools.Status.normal), + (tools.uncrustify, "hello.h", tools.Status.normal)]) + + def test_splint(self): + self._sub_tests([(tools.splint, "hello.c", tools.Status.ok), + (tools.splint, "hello.h", tools.Status.ok)]) if __name__ == "__main__":