# How build_and_test.py Manages and Displays Verbose Build Output Selectively

> Discover how build_and_test.py uses a verbose flag to control detailed build output selectively. Learn to display errors and warnings efficiently.

- Repository: [Conor/ios-simulator-skill](https://github.com/conorluddy/ios-simulator-skill)
- Tags: internals
- Published: 2026-02-27

---

**The [`build_and_test.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/build_and_test.py) script uses a command-line `--verbose` flag to toggle between minimal token-efficient output and a detailed multi-section report that selectively displays errors and warnings only when they exist.**

Managing build output verbosity is critical for CI pipelines and developer workflows where token efficiency matters. In the `conorluddy/ios-simulator-skill` repository, the [`build_and_test.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/build_and_test.py) script implements a selective verbose build output system that balances detail with brevity. This article examines how the script parses arguments, delegates formatting to `OutputFormatter`, and conditionally renders diagnostic information based on the presence of actual errors or warnings.

## Argument Parsing and the --verbose Flag

The verbose behavior is controlled through an explicit command-line argument defined in the *Output Options* group. In [`ios-simulator-skill/scripts/build_and_test.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/ios-simulator-skill/scripts/build_and_test.py), lines 100-107 define the `--verbose` flag that determines whether the script uses ultra-minimal default output or detailed reporting.

## Collecting Build Results

After the build runner completes execution, the script aggregates diagnostic data through the **XCResultParser** utility. Lines 55-62 of [`build_and_test.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/build_and_test.py) gather the **overall success flag** (`success`), **error and warning counts** (`error_count`, `warning_count`), and parsed diagnostic arrays (`errors` and `warnings`) that feed into the formatting pipeline.

## Conditional Verbose Output Branching

The script implements a clear conditional branch at lines 79-94 to handle output formatting. When `args.verbose` evaluates to true, the code invokes `OutputFormatter.format_verbose` and prints the returned string; otherwise, it maintains the default minimal output mode optimized for token efficiency.

## Selective Formatting Logic in reporter.py

The `OutputFormatter` class in [`ios-simulator-skill/scripts/xcode/reporter.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/ios-simulator-skill/scripts/xcode/reporter.py) constructs the verbose display through a multi-step pipeline that only includes sections when corresponding data exists.

### Header and XCResult Identification

Lines 76-88 of [`reporter.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/reporter.py) generate the section header displaying "Build: SUCCESS/FAILED" or test-summary status, followed by the **XCResult bundle identifier** which always appears for traceability regardless of build status.

### Capped Error Display

When the `errors` list contains items, the formatter calls `format_errors` (lines 22-33) to render up to **5 error entries** maximum. Each entry includes the error message and file location, preventing output overflow while preserving critical diagnostic information.

### Capped Warning Display

Similarly, `format_warnings` at lines 55-67 handles warning visualization with an identical **5-item cap**. This selective inclusion ensures that clean builds remain concise while problematic builds reveal actionable diagnostics without overwhelming the terminal buffer.

### Summary Statistics Line

The formatter concludes with a summary line (lines 31-34) reporting the total counts of errors and warnings, providing immediate quantitative context even when the detailed lists are truncated due to the 5-item cap.

## Practical Usage Examples

Run the script without flags for minimal token-efficient output suitable for automated agents:

```bash
python scripts/build_and_test.py --project MyApp.xcodeproj

```

Enable verbose mode to display detailed diagnostics with errors and warnings capped at 5 items each:

```bash
python scripts/build_and_test.py --project MyApp.xcodeproj --verbose

```

Use verbose mode with test runs to include test summary headers:

```bash
python scripts/build_and_test.py --project MyApp.xcodeproj --test --verbose

```

### Sample Verbose Output Structure

A failed build with verbose output produces a structured report like this:

```text
Build: FAILED
XCResult: 20251018-143052

Errors (3):
1. Provisioning profile not found
   Location: /path/to/project/Info.plist:line 12

2. Code signing required
   Location: /path/to/project/AppDelegate.swift:line 45

...

Warnings (2):
1. Deprecated API usage
   Location: /path/to/project/Legacy.m:line 78

...

Summary: 3 errors, 2 warnings

```

## Summary

- The `--verbose` flag in [`build_and_test.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/build_and_test.py) controls output granularity through an explicit command-line argument defined at lines 100-107.
- Build results are collected via `XCResultParser` including success status, error/warning counts, and diagnostic details at lines 55-62.
- Verbose formatting is delegated to `OutputFormatter.format_verbose` in [`reporter.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/reporter.py) when the verbose argument is true (lines 79-94).
- Output sections are conditionally rendered: errors and warnings only appear when present, capped at 5 items each via `format_errors` and `format_warnings`.
- The XCResult bundle identifier always displays for build traceability, and a summary line shows total counts regardless of build status.

## Frequently Asked Questions

### How do I enable verbose build output in build_and_test.py?

Pass the `--verbose` flag when executing the script. This argument is defined in the Output Options group at lines 100-107 of [`build_and_test.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/build_and_test.py), triggering the detailed formatter instead of the default minimal mode.

### Why does verbose output limit errors and warnings to 5 items?

The caps prevent token overflow and terminal clutter while still providing actionable diagnostics. The `format_errors` and `format_warnings` methods in [`reporter.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/reporter.py) (lines 22-33 and 55-67) enforce this limit to balance information density with readability.

### What information appears in every verbose output regardless of build status?

The XCResult bundle identifier always prints for traceability, along with the build/test status header and the final summary line showing total error and warning counts (lines 31-34). Detailed error and warning lists only appear when those issues actually exist.

### Where is the verbose formatting logic implemented?

The `OutputFormatter.format_verbose` method in [`ios-simulator-skill/scripts/xcode/reporter.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/ios-simulator-skill/scripts/xcode/reporter.py) (lines 76-88) implements the verbose display logic, calling helper methods to format errors, warnings, and summaries based on the data collected by [`build_and_test.py`](https://github.com/conorluddy/ios-simulator-skill/blob/main/build_and_test.py).