Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion json5/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def main(argv=None, host=None):
host.print(__version__)
return 0

if args.cmd:
if args.cmd is not None:
inp = args.cmd
elif args.file == '-':
inp = host.stdin.read()
Expand Down
12 changes: 12 additions & 0 deletions tests/tool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ def test_keys_are_quoted_by_default(self):
def test_read_command(self):
self.check(['-c', '"foo"'], out='"foo"\n')

def test_read_empty_command(self):
# An empty -c string is still the input; stdin and FILE are not read.
err = 'Empty strings are not legal JSON5\n'
self.check(['-c', ''], stdin='"foo"', returncode=1, out='', err=err)
self.check(
['-c', '', 'foo.json5'],
files={'foo.json5': '"foo"\n'},
returncode=1,
out='',
err=err,
)

def test_read_from_stdin(self):
self.check([], stdin='"foo"\n', out='"foo"\n')

Expand Down