|
1 | | -# Contains the class definitions outlining the schema of the test data |
| 1 | +"""Contains the class definitions outlining the schema of the test data. For LLDB conversion |
| 2 | +from/into these types, see `./from_lldb.py`""" |
2 | 3 |
|
3 | 4 | import enum |
4 | 5 | import json |
@@ -78,7 +79,7 @@ def from_dict(ty: type[Any], data: JsonType): |
78 | 79 | """Translates a dictionary into an instance of the given dataclass type (with possibly nested |
79 | 80 | dataclasses). |
80 | 81 |
|
81 | | - Relies on accurate type hints for the dataclass's fields, and the standard `dataclass.__init__` |
| 82 | + Relies on accurate type hints for the dataclass's fields, and the default `dataclass.__init__` |
82 | 83 | definition.""" |
83 | 84 |
|
84 | 85 | # Optional isn't a constructor, so we have to "unwrap" it. |
@@ -295,19 +296,31 @@ def initialize() -> "TargetData": |
295 | 296 | return result |
296 | 297 |
|
297 | 298 | def save_blessing(self, metadata: BlessMetadata): |
298 | | - """Writes the entirety of `self` to the input file. Used to finalize changes made by |
299 | | - one or more `TestData.bless_variable` calls.""" |
| 299 | + """Writes the entirety of `self` to the env var `LLDB_BATCHMODE_INPUT_DATA_PATH`, which is |
| 300 | + set by `compiletest` before running `lldb_batchmode. Used to finalize changes made by one or |
| 301 | + more `from_lldb.bless_variable` calls. |
| 302 | +
|
| 303 | + This function should be called exactly once, right before |
| 304 | + `lldb_batchmode.runner.main` exits if the following conditions are met: |
| 305 | +
|
| 306 | + 1. No other exceptions or error states occurred |
| 307 | + 2. `BLESS == True` |
| 308 | + 3. At least one `repr` pseudo-command was processed |
| 309 | +
|
| 310 | + This prevents us from saving incomplete data or invalid data. It also prevents us from |
| 311 | + creating input data files for tests that do not need it. |
| 312 | + """ |
300 | 313 |
|
301 | 314 | self.bless_metadata = metadata |
302 | 315 | path = os.environ["LLDB_BATCHMODE_INPUT_DATA_PATH"] |
303 | | - # dumping directly to a file is somewhat unsafe. If the json ends up malformed, we could |
304 | | - # end up overwriting valid test data with a complete mess. Since the in-memory data |
305 | | - # typically *isn't* malformed, the `--bless` will pass and make it seem like nothing is |
306 | | - # wrong. |
| 316 | + # dumping directly to a file is somewhat unsafe. If the `Variable`/`Type` data ends up in a |
| 317 | + # state that cannot be serialized correctly, the json ends up malformed, and we could end up |
| 318 | + # overwriting valid test data with a complete mess. Since the in-memory data is typically |
| 319 | + # completely valid, the testing logic will pass and make it seem like nothing is wrong. |
307 | 320 |
|
308 | 321 | # While we could rely on git to help revert the test file, it's better to just not allow it |
309 | | - # to save malformed json in the first place. Thus, we dump the JSON, re-read it, and then |
310 | | - # only when that succeeds do we save it. |
| 322 | + # to save malformed json in the first place. Thus, we dump the JSON, re-read it to check |
| 323 | + # for `JSONDecodeError`, and write it to the target file if no error occurred. |
311 | 324 | x = json.dumps(asdict(self), indent=" ") |
312 | 325 | _ = json.loads(x) |
313 | 326 |
|
|
0 commit comments