Repository navigation
Commit 7d859ed
authored
[api_summary] Add expectApiSummaryClean and --write/--check CLI flags (#2603)
Adds a `build_verify`-style one-liner test helper (`expectApiSummaryClean`) and companion `--write` (`-w`), `--check` (`-c`), and `--output` (`-o`) CLI flags to `package:api_summary` (`v1.1.0`).
- **Programmatic Tear-Off (`expectApiSummaryClean`)**:
- Verifies that a package's generated `ApiSummary` matches its checked-in golden file (`api.txt`, `api.json`, or `api.yaml`).
- Because all parameters are optional and named (`packagePath` defaults to `Directory.current`), it can be passed directly as a tear-off to `test()`:
```dart
import 'package:api_summary/api_summary.dart';
import 'package:test/scaffolding.dart';
void main() {
test('api_summary', expectApiSummaryClean);
}
```
- Throws `ApiSummaryVerificationException` with a compact line diff and copy-pasteable remediation command (`dart run api_summary --write`) without requiring `package:test` in `api_summary`'s runtime `dependencies`.
- **CLI Enhancements (`bin/api_summary.dart`)**:
- `-w, --write`: Writes the summary to the default golden file (`api.txt`, `api.json`, or `api.yaml`) in the package root.
- `-c, --check`: Verifies that the existing golden file matches the current public API, exiting with code `1` on mismatch.
- `-o, --output <file>`: Writes the summary to a custom file path instead of `stdout` (relative paths resolve relative to `--package-path`).
- Enforces mutual exclusivity between `--write`, `--check`, and `--output` via an exhaustive record switch (exiting with code `64` on invalid combinations or unexpected positional arguments).
- **Self-Dogfooding & Tests (`test/app_test.dart`)**:
- Dogfoods `expectApiSummaryClean` for `api.txt`, `api.json`, and `api.yaml` and pre-compiles `bin/api_summary.dart` to a kernel `.dill` in `setUpAll` (cutting `test/app_test.dart` execution time from ~105s to ~44s).1 parent d87eaf7 commit 7d859ed
10 files changed
Lines changed: 1038 additions & 116 deletions
File tree
- pkgs/api_summary
- bin
- lib
- src
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
1 | 9 | | |
2 | 10 | | |
3 | 11 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
54 | 60 | | |
55 | 61 | | |
| 62 | + | |
| 63 | + | |
56 | 64 | | |
57 | 65 | | |
58 | 66 | | |
| |||
61 | 69 | | |
62 | 70 | | |
63 | 71 | | |
64 | | - | |
65 | | - | |
| 72 | + | |
| 73 | + | |
66 | 74 | | |
67 | 75 | | |
68 | 76 | | |
| |||
71 | 79 | | |
72 | 80 | | |
73 | 81 | | |
74 | | - | |
75 | 82 | | |
76 | 83 | | |
77 | 84 | | |
| |||
125 | 132 | | |
126 | 133 | | |
127 | 134 | | |
128 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
129 | 141 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
135 | 145 | | |
136 | | - | |
137 | | - | |
| 146 | + | |
138 | 147 | | |
139 | 148 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | 149 | | |
| 150 | + | |
144 | 151 | | |
145 | 152 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 153 | + | |
161 | 154 | | |
162 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
0 commit comments