From b6845765e6f5e3093bf12020fa1ce2ba4f4190c8 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Mon, 23 Apr 2018 22:05:55 +0200
Subject: [PATCH] Come up with runtest.py script.

The script runs a single test. Example usage:

./scripts/runtest.py ./test/unit/org/openstreetmap/josm/tools/GeometryTest.java
Compiling test
Running test
JUnit version 4.12
..System property josm.test.data is not set, using 'test/data'
.System property josm.test.data is not set, using 'test/data'
..System property josm.test.data is not set, using 'test/data'

Time: 1.063

OK (5 tests)
---
 scripts/runtest.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100755 scripts/runtest.py

diff --git a/scripts/runtest.py b/scripts/runtest.py
new file mode 100755
index 000000000..7098f4ca8
--- /dev/null
+++ b/scripts/runtest.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+# License: CC0
+
+"""
+Helper script that runs a single test.
+"""
+
+import argparse
+import subprocess
+
+from itertools import *
+
+josm_env = '.:test/unit:test/functional:dist/josm-custom.jar:test/lib/commons-testing/*:test/lib/fest/*:test/lib/junit/*:test/lib/*:test/lib/unitils-core/*:tools/*:tools/spotbugs/*'
+
+def main():
+    parser = argparse.ArgumentParser(description = 'Run single JOSM test')
+    parser.add_argument('testpath',
+            help = 'Relative path to test. Example: ./test/unit/org/openstreetmap/josm/tools/GeometryTest.java')
+    args = parser.parse_args()
+
+    print('Compiling test')
+    subprocess.check_output('javac -cp %s %s' % (josm_env, args.testpath), shell = True)
+
+    # parse parh to tests and start with 'org' folder
+    parts = list(dropwhile(lambda x: x != 'org', args.testpath.split('/')))
+    parts[-1] = parts[-1].split('.')[0]
+    class_name = '.'.join(parts)
+
+    print('Running test')
+    subprocess.run('java -cp %s org.junit.runner.JUnitCore %s' % (josm_env, class_name), shell = True)
+    
+main()
-- 
2.16.3

