Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 18fd0a4

Browse files
committed
Add tests using implicit java_test args attr
1 parent 8bfea4b commit 18fd0a4

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("@dwtj_rules_java//java:defs.bzl", "dwtj_java_test")
2+
3+
dwtj_java_test(
4+
name = "expect_zero_args",
5+
main_class = "attrs.args.ExpectNumArgs",
6+
srcs = ["ExpectNumArgs.java"],
7+
args = [],
8+
)
9+
10+
dwtj_java_test(
11+
name = "expect_one_arg",
12+
main_class = "attrs.args.ExpectNumArgs",
13+
srcs = ["ExpectNumArgs.java"],
14+
args = ["1"],
15+
)
16+
17+
dwtj_java_test(
18+
name = "expect_five_args",
19+
main_class = "attrs.args.ExpectNumArgs",
20+
srcs = ["ExpectNumArgs.java"],
21+
args = [
22+
"5",
23+
"a",
24+
"b",
25+
"c",
26+
"d",
27+
],
28+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package attrs.args;
2+
3+
public class ExpectNumArgs {
4+
public static void main(String[] args) {
5+
if (args.length == 0) {
6+
System.exit(0);
7+
}
8+
9+
int numArgs = Integer.parseInt(args[0]);
10+
if (args.length != numArgs) {
11+
System.err.println("Wrong number of arguments found.");
12+
System.err.println("Expected number of args: " + numArgs);
13+
System.err.println("Actual number of args: " + args.length);
14+
System.exit(-1);
15+
} else {
16+
for (String arg : args) {
17+
System.out.println(arg);
18+
}
19+
System.exit(0);
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)