Skip to content

Commit

Permalink
Fix exit code in case of undefined variable. Closes #48.
Browse files Browse the repository at this point in the history
  • Loading branch information
kblomqvist committed May 14, 2018
1 parent 1ba6233 commit af443e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Major release, unreleased
- The option `--keep-trailing-newline` was removed in favor of making
it default. The old behaviour can be achieved with the new option
`--remove-trailing-newline`.
- Fixed an exit code in case of undefined variable from 0 to 1.

Version 4.3
-----------
Expand Down
10 changes: 6 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,12 @@ def test_mode_is_none():


def test_mode_is_pedantic():
"""gh-42"""
cmd = r'echo -n "{{ foo }}" | yasha --mode=pedantic -'
out = check_output(cmd, shell=True, stderr=subprocess.STDOUT)
assert out == b"UndefinedError: 'foo' is undefined\n"
"""gh-42, and gh-48"""
with pytest.raises(subprocess.CalledProcessError) as err:
cmd = r'echo -n "{{ foo }}" | yasha --mode=pedantic -'
out = check_output(cmd, shell=True, stderr=subprocess.STDOUT)
out = err.value.output
assert out == b"Error: Variable 'foo' is undefined\n"


def test_mode_is_debug():
Expand Down
2 changes: 1 addition & 1 deletion yasha/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,4 @@ def cli(
t_stream.enable_buffering(size=5)
t_stream.dump(output, encoding=yasha.ENCODING)
except JinjaUndefinedError as e:
click.echo("UndefinedError: {}".format(e), err=True)
raise ClickException("Variable {}".format(e))

0 comments on commit af443e9

Please sign in to comment.