Skip to content

Commit

Permalink
Make 'spec' pay attention to --print=json
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Oct 21, 2024
1 parent 4133fc8 commit 296e6fd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bikeshed/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import contextlib
import dataclasses
import io
import json
import sys
from collections import Counter

Expand Down Expand Up @@ -253,6 +254,19 @@ def formatMessage(type: str, text: str, lineNum: str | int | None = None) -> str
return f"<final-success>{text}</final-success>"
if type == "failure":
return f"<final-failure>{text}</final-failure>"
elif state.printMode == "json":
if not state.seenMessages:
jsonText = "[\n"
else:
jsonText = ""
msg = {"lineNum":lineNum, "messageType":type, "text":text}
jsonText += " " + json.dumps(msg)
if type in ("success", "failure"):
jsonText += "\n]"
else:
jsonText += ", "
return jsonText

if type == "message":
return text
if type == "success":
Expand Down

0 comments on commit 296e6fd

Please sign in to comment.