Skip to content

Commit

Permalink
Allow test mode for console apps on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Sep 10, 2024
1 parent 1a5ec17 commit 2a3df3d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/briefcase/platforms/macOS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,10 @@ def run_app(
# Console apps must operate in non-streaming mode so that console input can
# be handled correctly. However, if we're in test mode, we *must* stream so
# that we can see the test exit sentinel
if app.console_app and not test_mode:
if app.console_app:
self.run_console_app(
app,
test_mode=test_mode,
passthrough=passthrough,
**kwargs,
)
Expand All @@ -268,16 +269,18 @@ def run_app(
def run_console_app(
self,
app: AppConfig,
test_mode: bool,
passthrough: list[str],
**kwargs,
):
"""Start the console application.
:param app: The config object for the app
:param test_mode: Boolean; Is the app running in test mode?
:param passthrough: The list of arguments to pass to the app
"""
try:
kwargs = self._prepare_app_kwargs(app=app, test_mode=False)
sub_kwargs = self._prepare_app_kwargs(app=app, test_mode=False)

# Start the app directly
self.logger.info("=" * 75)
Expand All @@ -286,10 +289,14 @@ def run_console_app(
+ (passthrough if passthrough else []),
cwd=self.tools.home_path,
check=True,
stream_output=False,
**kwargs,
# Stream the app's output for testing.
# When a console app runs normally, its stdout should be connected
# directly to the terminal to properly display the app. When its test
# suite is running, though, Briefcase should stream the output to
# capture the testing outcome.
stream_output=test_mode,
**sub_kwargs,
)

except subprocess.CalledProcessError:
# The command line app *could* returns an error code, which is entirely legal.
# Ignore any subprocess error here.
Expand Down Expand Up @@ -347,7 +354,7 @@ def run_gui_app(
app_pid = None
try:
# Set up the log stream
kwargs = self._prepare_app_kwargs(app=app, test_mode=test_mode)
sub_kwargs = self._prepare_app_kwargs(app=app, test_mode=test_mode)

# Start the app in a way that lets us stream the logs
self.tools.subprocess.run(
Expand All @@ -356,7 +363,7 @@ def run_gui_app(
+ ((["--args"] + passthrough) if passthrough else []),
cwd=self.tools.home_path,
check=True,
**kwargs,
**sub_kwargs,
)

# Find the App process ID so log streaming can exit when the app exits
Expand Down

0 comments on commit 2a3df3d

Please sign in to comment.