|
55 | 55 | defmodule Kernel.CLI.SyntaxErrorTest do
|
56 | 56 | use ExUnit.Case, async: true
|
57 | 57 |
|
| 58 | + def check_output(elixir_cmd, expected_msg) do |
| 59 | + o = elixir(elixir_cmd) |
| 60 | + expected_msg = to_char_list(:unicode.characters_to_binary expected_msg) |
| 61 | + assert :string.str(o, expected_msg) == 1, "Expected this output: `#{expected_msg}`\nbut got this output: `#{o}`" |
| 62 | + end |
| 63 | + |
58 | 64 | test :syntax_code_error do
|
59 |
| - message = '** (TokenMissingError) nofile:1: syntax error: expression is incomplete' |
60 |
| - assert :string.str(message, elixir('-e "[1,2"')) == 0 |
61 |
| - message = '** (SyntaxError) nofile:1: syntax error before: \'end\'' |
62 |
| - assert :string.str(message, elixir('-e "case 1 end"')) == 0 |
63 |
| - message = '** (SyntaxError) nofile:1: invalid token: あ' |
64 |
| - assert :string.str(message, elixir('-e "あ"')) == 0 |
65 |
| - message = '** (SyntaxError) nofile:1: invalid token: æ' |
66 |
| - assert :string.str(message, elixir('-e "æ"')) == 0 |
| 65 | + check_output('-e "[1,2"', '** (TokenMissingError) nofile:1: missing terminator: ]') |
| 66 | + check_output('-e "case 1 end"', %C"** (SyntaxError) nofile:1: unexpected token: end") |
| 67 | + thischar = "あ" |
| 68 | + if is_win? do |
| 69 | + thatchar = %B"\x{3042}" |
| 70 | + else |
| 71 | + thatchar = :unicode.characters_to_binary(thischar) |
| 72 | + end |
| 73 | + check_output('-e "#{thischar}"', '** (SyntaxError) nofile:1: invalid token: #{thatchar}') |
| 74 | + check_output('-e "æ"', '** (SyntaxError) nofile:1: invalid token: æ') |
67 | 75 | end
|
68 | 76 | end
|
69 | 77 |
|
|
0 commit comments