diff --git a/languages/java/runnables.scm b/languages/java/runnables.scm index 75f786e..a8a2b2e 100644 --- a/languages/java/runnables.scm +++ b/languages/java/runnables.scm @@ -64,6 +64,39 @@ (#set! tag java-test-method) ) +; Run nested test function +( + (package_declaration + (scoped_identifier) @java_package_name + ) + (class_declaration + name: (identifier) @java_outer_class_name + body: (class_body + (class_declaration + (modifiers + (marker_annotation + name: (identifier) @nested_annotation + ) + ) + name: (identifier) @java_class_name + body: (class_body + (method_declaration + (modifiers + (marker_annotation + name: (identifier) @annotation_name + ) + ) + name: (identifier) @run @java_method_name + (#eq? @annotation_name "Test") + ) + ) + (#eq? @nested_annotation "Nested") + ) @_ + ) + ) + (#set! tag java-test-method-nested) +) + ; Run test class ( (package_declaration @@ -84,3 +117,35 @@ ) @_ (#set! tag java-test-class) ) + +; Run nested test class +( + (package_declaration + (scoped_identifier) @java_package_name + ) + (class_declaration + name: (identifier) @java_outer_class_name + body: (class_body + (class_declaration + (modifiers + (marker_annotation + name: (identifier) @nested_annotation + ) + ) + name: (identifier) @run @java_class_name + body: (class_body + (method_declaration + (modifiers + (marker_annotation + name: (identifier) @annotation_name + ) + ) + (#eq? @annotation_name "Test") + ) + ) + (#eq? @nested_annotation "Nested") + ) @_ + ) + ) + (#set! tag java-test-class-nested) +) diff --git a/languages/java/tasks.json b/languages/java/tasks.json index 280bfc7..4816928 100644 --- a/languages/java/tasks.json +++ b/languages/java/tasks.json @@ -1,23 +1,23 @@ [ - { - "label": "Run $ZED_CUSTOM_java_class_name", - "command": "pkg=\"${ZED_CUSTOM_java_package_name:}\"; cls=\"$ZED_CUSTOM_java_class_name\"; if [ -n \"$pkg\" ]; then c=\"$pkg.$cls\"; else c=\"$cls\"; fi; if [ -f pom.xml ]; then ./mvnw clean compile exec:java -Dexec.mainClass=\"$c\"; elif [ -f gradlew ]; then ./gradlew run -PmainClass=\"$c\"; else find . -name '*.java' -not -path './bin/*' -not -path './target/*' -not -path './build/*' -print0 | xargs -0 javac -d bin && java -cp bin \"$c\"; fi;", - "use_new_terminal": false, - "reveal": "always", - "tags": ["java-main"], - "shell": { - "with_arguments": { - "program": "/bin/sh", - "args": ["-c"] - } + { + "label": "Run $ZED_CUSTOM_java_class_name", + "command": "pkg=\"${ZED_CUSTOM_java_package_name:}\"; cls=\"$ZED_CUSTOM_java_class_name\"; if [ -n \"$pkg\" ]; then c=\"$pkg.$cls\"; else c=\"$cls\"; fi; if [ -f pom.xml ]; then ./mvnw clean compile exec:java -Dexec.mainClass=\"$c\"; elif [ -f gradlew ]; then ./gradlew run -PmainClass=\"$c\"; else find . -name '*.java' -not -path './bin/*' -not -path './target/*' -not -path './build/*' -print0 | xargs -0 javac -d bin && java -cp bin \"$c\"; fi;", + "use_new_terminal": false, + "reveal": "always", + "tags": ["java-main"], + "shell": { + "with_arguments": { + "program": "/bin/sh", + "args": ["-c"] } - }, + } + }, { - "label": "Test $ZED_CUSTOM_java_class_name.$ZED_CUSTOM_java_method_name", - "command": "c=\"$ZED_CUSTOM_java_package_name.$ZED_CUSTOM_java_class_name\"; m=\"$ZED_CUSTOM_java_method_name\"; if [ -f pom.xml ]; then ./mvnw clean test -Dtest=\"$c#$m\"; elif [ -f gradlew ]; then ./gradlew test --tests $c.$m; else >&2 echo 'No build system found'; exit 1; fi;", + "label": "$ZED_CUSTOM_java_class_name.${ZED_CUSTOM_java_outer_class_name:}.$ZED_CUSTOM_java_method_name", + "command": "package=\"$ZED_CUSTOM_java_package_name\"; outer=\"${ZED_CUSTOM_java_outer_class_name:}\"; inner=\"$ZED_CUSTOM_java_class_name\"; method=\"$ZED_CUSTOM_java_method_name\"; sep=\"$\"; if [ -n \"$outer\" ]; then c=\"$outer$sep$inner\"; else c=\"$inner\"; fi; if [ -f pom.xml ]; then ./mvnw clean test -Dtest=\"$package.$c#$method\"; elif [ -f gradlew ]; then ./gradlew test --tests \"$package.$c.$method\"; else >&2 echo 'No build system found'; exit 1; fi;", "use_new_terminal": false, "reveal": "always", - "tags": ["java-test-method"], + "tags": ["java-test-method", "java-test-method-nested"], "shell": { "with_arguments": { "program": "/bin/sh", @@ -27,10 +27,10 @@ }, { "label": "Test class $ZED_CUSTOM_java_class_name", - "command": "c=\"$ZED_CUSTOM_java_package_name.$ZED_CUSTOM_java_class_name\"; if [ -f pom.xml ]; then ./mvnw clean test -Dtest=\"$c\"; elif [ -f gradlew ]; then ./gradlew test --tests $c; else >&2 echo 'No build system found'; exit 1; fi;", + "command": "package=\"$ZED_CUSTOM_java_package_name\"; outer=\"${ZED_CUSTOM_java_outer_class_name:}\"; inner=\"$ZED_CUSTOM_java_class_name\"; sep=\"$\"; if [ -n \"$outer\" ]; then c=\"$outer$sep$inner\"; else c=\"$inner\"; fi; if [ -f pom.xml ]; then ./mvnw clean test -Dtest=\"$package.$c\"; elif [ -f gradlew ]; then ./gradlew test --tests \"$package.$c\"; else >&2 echo 'No build system found'; exit 1; fi;", "use_new_terminal": false, "reveal": "always", - "tags": ["java-test-class"], + "tags": ["java-test-class", "java-test-class-nested"], "shell": { "with_arguments": { "program": "/bin/sh",