Skip to content

Commit 4915e79

Browse files
authored
Add --suite flag to tbots.py to run entire test suites (#3586)
* Add --suite flag to run test suites * Add running test suite from tbots to docs * Add option for no search query when --suite is specified * Remove repeated -t flag * Refactor tbots.py a bit, now running test suite works * Revert docs update * Merge master
1 parent 21cd689 commit 4915e79

2 files changed

Lines changed: 65 additions & 28 deletions

File tree

src/cli/cli_params.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typer import Option
1+
from typer import Option, Argument
22
from enum import Enum
33
from typing import Annotated
44

@@ -17,6 +17,10 @@ class DebugBinary(str, Enum):
1717
yellow = "yellow"
1818

1919

20+
SearchQueryArgument = Annotated[
21+
str | None, Argument(help="Search query for bazel target")
22+
]
23+
2024
PrintCommandOption: type[bool] = Annotated[
2125
bool, Option("-p", "--print_command", help="Print the generated Bazel command")
2226
]
@@ -76,6 +80,11 @@ class DebugBinary(str, Enum):
7680
bool, Option("--tracy", help="Run the binary with the TRACY_ENABLE macro defined")
7781
]
7882

83+
TestSuiteOption = Annotated[
84+
bool,
85+
Option("--suite", help="Run entire test suite instead of searching for a target"),
86+
]
87+
7988
EnableThunderscopeOption = Annotated[bool, Option("-t", "--enable_thunderscope")]
8089
EnableVisualizerOption = Annotated[bool, Option("-v", "--enable_visualizer")]
8190
StopAIOnStartOption = Annotated[bool, Option("-s", "--stop_ai_on_start")]

src/tbots.py

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
EnableThunderscopeOption,
2222
EnableVisualizerOption,
2323
StopAIOnStartOption,
24+
SearchQueryArgument,
25+
TestSuiteOption,
2426
DebugBinary,
2527
JobsOption,
2628
)
@@ -37,33 +39,11 @@
3739
app = Typer()
3840

3941

40-
@app.command(
41-
context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
42-
no_args_is_help=True,
43-
)
44-
def main(
45-
ctx: Context,
42+
def fuzzy_find_target(
4643
action: ActionArgument,
47-
search_query: str,
48-
print_command: PrintCommandOption = False,
49-
no_optimized_build: NoOptimizedBuildOption = False,
50-
debug_build: DebugBuildOption = False,
51-
select_debug_binaries: SelectDebugBinariesOption = None,
52-
flash_robots: FlashRobotsOption = None,
53-
ssh_password: SSHPasswordOption = None,
54-
interactive_search: InteractiveModeOption = False,
55-
tracy: TracyOption = False,
56-
enable_thunderscope: EnableThunderscopeOption = False,
57-
enable_visualizer: EnableVisualizerOption = False,
58-
stop_ai_on_start: StopAIOnStartOption = False,
59-
jobs_option: JobsOption = None,
60-
) -> None:
61-
if bool(flash_robots) ^ bool(ssh_password):
62-
print(
63-
"If you want to flash robots, both the robot IDs and password must be provided"
64-
)
65-
sys.exit(1)
66-
44+
search_query: SearchQueryArgument,
45+
interactive_search: InteractiveModeOption,
46+
) -> str:
6747
test_query = ["bazel", "query", "tests(//...)"]
6848
binary_query = ["bazel", "query", "kind(.*_binary,//...)"]
6949
library_query = ["bazel", "query", "kind(.*_library,//...)"]
@@ -109,7 +89,53 @@ def main(
10989
target = str(iterfzf.iterfzf(iter(targets)), encoding="utf-8")
11090
print("User selected {}".format(target))
11191

112-
command = ["bazel", action.value, target]
92+
return target
93+
94+
95+
@app.command(
96+
context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
97+
no_args_is_help=True,
98+
)
99+
def main(
100+
ctx: Context,
101+
action: ActionArgument,
102+
search_query: SearchQueryArgument = None,
103+
print_command: PrintCommandOption = False,
104+
no_optimized_build: NoOptimizedBuildOption = False,
105+
debug_build: DebugBuildOption = False,
106+
select_debug_binaries: SelectDebugBinariesOption = None,
107+
flash_robots: FlashRobotsOption = None,
108+
ssh_password: SSHPasswordOption = None,
109+
interactive_search: InteractiveModeOption = False,
110+
tracy: TracyOption = False,
111+
enable_thunderscope: EnableThunderscopeOption = False,
112+
enable_visualizer: EnableVisualizerOption = False,
113+
stop_ai_on_start: StopAIOnStartOption = False,
114+
test_suite: TestSuiteOption = False,
115+
jobs_option: JobsOption = "",
116+
) -> None:
117+
if bool(flash_robots) ^ bool(ssh_password):
118+
print(
119+
"If you want to flash robots, both the robot IDs and password must be provided"
120+
)
121+
sys.exit(1)
122+
123+
if search_query is None and (not test_suite or not action == ActionArgument.test):
124+
print(
125+
"You must specify a search query unless you are running the test suite, use ./tbots.py test --suite instead"
126+
)
127+
sys.exit(1)
128+
129+
if test_suite and action == ActionArgument.test:
130+
target = """-- //... \\
131+
-//software/field_tests/... \\
132+
-//toolchains/cc/... \\
133+
-//software:unix_full_system_tar_gen"""
134+
print("Running software and simulated gameplay test suite")
135+
else:
136+
target = fuzzy_find_target(action, search_query, interactive_search)
137+
138+
command = ["bazel", action.value]
113139
unknown_args = ctx.args
114140

115141
# Trigger a debug build
@@ -151,6 +177,8 @@ def main(
151177
if action == ActionArgument.run:
152178
command += ["--"]
153179

180+
command.append(target)
181+
154182
bazel_arguments = unknown_args
155183
if stop_ai_on_start:
156184
bazel_arguments += ["--stop_ai_on_start"]

0 commit comments

Comments
 (0)