Added more tool tests.
This commit is contained in:
parent
803ee80427
commit
fb93897ac7
11 changed files with 282 additions and 31 deletions
197
golden-files/input/clojure-util.java
Normal file
197
golden-files/input/clojure-util.java
Normal file
|
|
@ -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 <K,V> void clearCache(ReferenceQueue rq, ConcurrentHashMap<K, Reference<V>> cache){
|
||||||
|
//cleanup any dead entries
|
||||||
|
if(rq.poll() != null)
|
||||||
|
{
|
||||||
|
while(rq.poll() != null)
|
||||||
|
;
|
||||||
|
for(Map.Entry<K, Reference<V>> e : cache.entrySet())
|
||||||
|
{
|
||||||
|
Reference<V> 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:
|
||||||
|
* <p>
|
||||||
|
* <code>throw sneakyThrow( some exception );</code>
|
||||||
|
*/
|
||||||
|
static public RuntimeException sneakyThrow(Throwable t) {
|
||||||
|
// http://www.mail-archive.com/javaposse@googlegroups.com/msg05984.html
|
||||||
|
if (t == null)
|
||||||
|
throw new NullPointerException();
|
||||||
|
Util.<RuntimeException>sneakyThrow0(t);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
static private <T extends Throwable> void sneakyThrow0(Throwable t) throws T {
|
||||||
|
throw (T) t;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
7
golden-files/input/hello.c
Normal file
7
golden-files/input/hello.c
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("Hello World\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
6
golden-files/input/hello.h
Normal file
6
golden-files/input/hello.h
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef HELLO_H
|
||||||
|
#define HELLO_H
|
||||||
|
|
||||||
|
void hello();
|
||||||
|
|
||||||
|
#endif
|
||||||
1
golden-files/results/antic-closure-util_java
Normal file
1
golden-files/results/antic-closure-util_java
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Verification completed: 0 reported messages
|
||||||
3
golden-files/results/splint-hello_c
Normal file
3
golden-files/results/splint-hello_c
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
Splint 3.1.2 --- 03 May 2009
|
||||||
|
|
||||||
|
Finished checking --- no warnings
|
||||||
3
golden-files/results/splint-hello_h
Normal file
3
golden-files/results/splint-hello_h
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
Splint 3.1.2 --- 03 May 2009
|
||||||
|
|
||||||
|
Finished checking --- no warnings
|
||||||
2
golden-files/results/uncrustify-closure-util_java
Normal file
2
golden-files/results/uncrustify-closure-util_java
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||||
|
[0m
|
||||||
8
golden-files/results/uncrustify-hello_c
Normal file
8
golden-files/results/uncrustify-hello_c
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
[0m[38;2;205;40;40m[48;2;0;0;0m[1m#include <stdio.h>[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||||
|
|
||||||
|
[0m[38;2;106;184;37m[48;2;0;0;0m[1mint[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;68;127;207m[48;2;0;0;0mmain[0m[38;2;208;208;208m[48;2;0;0;0m()[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||||
|
[0m[38;2;208;208;208m[48;2;0;0;0m{[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||||
|
[0m[38;2;208;208;208m[48;2;0;0;0m printf([0m[38;2;237;157;19m[48;2;0;0;0m"Hello World\n"[0m[38;2;208;208;208m[48;2;0;0;0m);[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||||
|
[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;106;184;37m[48;2;0;0;0m[1mreturn[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;54;119;169m[48;2;0;0;0m0[0m[38;2;208;208;208m[48;2;0;0;0m;[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||||
|
[0m[38;2;208;208;208m[48;2;0;0;0m}[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||||
|
[0m
|
||||||
7
golden-files/results/uncrustify-hello_h
Normal file
7
golden-files/results/uncrustify-hello_h
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
[0m[38;2;205;40;40m[48;2;0;0;0m[1m#ifndef HELLO_H[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||||
|
[0m[38;2;205;40;40m[48;2;0;0;0m[1m#define HELLO_H[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||||
|
|
||||||
|
[0m[38;2;106;184;37m[48;2;0;0;0m[1mvoid[0m[38;2;208;208;208m[48;2;0;0;0m [0m[38;2;68;127;207m[48;2;0;0;0mhello[0m[38;2;208;208;208m[48;2;0;0;0m();[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||||
|
|
||||||
|
[0m[38;2;205;40;40m[48;2;0;0;0m[1m#endif[0m[38;2;255;255;255m[48;2;0;0;0m
|
||||||
|
[0m
|
||||||
9
tools.py
9
tools.py
|
|
@ -431,7 +431,7 @@ perl6_syntax.dependencies = {"perl6"}
|
||||||
def _jlint_tool(tool_type, path):
|
def _jlint_tool(tool_type, path):
|
||||||
stdout, *rest = _do_command([tool_type, path])
|
stdout, *rest = _do_command([tool_type, path])
|
||||||
status = (Status.ok
|
status = (Status.ok
|
||||||
if b"Verification completed: 0 reported messages." in stdout
|
if "Verification completed: 0 reported messages." in stdout
|
||||||
else Status.problem)
|
else Status.problem)
|
||||||
return status, fill3.Text(stdout)
|
return status, fill3.Text(stdout)
|
||||||
|
|
||||||
|
|
@ -543,10 +543,9 @@ def uncrustify(path):
|
||||||
config_path = os.path.join(temp_dir, "uncrustify.cfg")
|
config_path = os.path.join(temp_dir, "uncrustify.cfg")
|
||||||
stdout, stderr, returncode = _do_command(
|
stdout, stderr, returncode = _do_command(
|
||||||
["uncrustify", "--detect", "-f", path, "-o", config_path])
|
["uncrustify", "--detect", "-f", path, "-o", config_path])
|
||||||
if returncode != 0:
|
if returncode == 0:
|
||||||
raise AssertionError
|
stdout, stderr, returncode = _do_command(
|
||||||
stdout, stderr, returncode = _do_command(
|
["uncrustify", "-c", config_path, "-f", path])
|
||||||
["uncrustify", "-c", config_path, "-f", path])
|
|
||||||
status = Status.normal if returncode == 0 else Status.problem
|
status = Status.normal if returncode == 0 else Status.problem
|
||||||
source_widget = _syntax_highlight_code(stdout, path)
|
source_widget = _syntax_highlight_code(stdout, path)
|
||||||
return status, source_widget
|
return status, source_widget
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,13 @@ def run_tool(tool, input_filename):
|
||||||
|
|
||||||
class ToolsTestCase(unittest.TestCase):
|
class ToolsTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def _test_tool(self, tool, input_filename, expected_status):
|
def _sub_tests(self, sub_tests):
|
||||||
status, result = run_tool(tool, input_filename)
|
for tool, input_filename, expected_status in sub_tests:
|
||||||
golden_path = result_path(tool, input_filename)
|
with self.subTest(input_filename=input_filename):
|
||||||
golden.assertGolden(widget_to_string(result), golden_path)
|
status, result = run_tool(tool, input_filename)
|
||||||
self.assertEqual(status, expected_status)
|
golden_path = result_path(tool, input_filename)
|
||||||
|
golden.assertGolden(widget_to_string(result), golden_path)
|
||||||
|
self.assertEqual(status, expected_status)
|
||||||
|
|
||||||
def test_metadata(self):
|
def test_metadata(self):
|
||||||
mock_stat_result = unittest.mock.Mock(
|
mock_stat_result = unittest.mock.Mock(
|
||||||
|
|
@ -59,57 +61,73 @@ class ToolsTestCase(unittest.TestCase):
|
||||||
return_value=mock_stat_result):
|
return_value=mock_stat_result):
|
||||||
with unittest.mock.patch.object(tools.pwd, "getpwuid",
|
with unittest.mock.patch.object(tools.pwd, "getpwuid",
|
||||||
return_value=mock_pw_entry):
|
return_value=mock_pw_entry):
|
||||||
self._test_tool(tools.metadata, "hi3.py",
|
self._sub_tests([
|
||||||
tools.Status.normal)
|
(tools.metadata, "hi3.py", tools.Status.normal)])
|
||||||
|
|
||||||
def test_contents(self):
|
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):
|
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):
|
def test_unittests(self):
|
||||||
self._test_tool(tools.python_unittests, "hi3.py",
|
self._sub_tests([
|
||||||
tools.Status.not_applicable)
|
(tools.python_unittests, "hi3.py", tools.Status.not_applicable)])
|
||||||
|
|
||||||
def test_pydoc(self):
|
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):
|
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):
|
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):
|
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):
|
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):
|
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):
|
def test_python_modulefinder(self):
|
||||||
self._test_tool(tools.python_modulefinder, "hi3.py",
|
self._sub_tests([
|
||||||
tools.Status.normal)
|
(tools.python_modulefinder, "hi3.py", tools.Status.normal)])
|
||||||
|
|
||||||
def test_python_mccable(self):
|
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):
|
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):
|
def test_perldoc(self):
|
||||||
self._test_tool(tools.perldoc, "perl.pl",
|
self._sub_tests([
|
||||||
tools.Status.not_applicable)
|
(tools.perldoc, "perl.pl", tools.Status.not_applicable),
|
||||||
self._test_tool(tools.perldoc, "contents.pod", tools.Status.normal)
|
(tools.perldoc, "contents.pod", tools.Status.normal)])
|
||||||
|
|
||||||
def test_perltidy(self):
|
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):
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue