put common part of error messages into variable
Patch status: merged
Patch by Sascha Kruse
Long description:
This makes future changes easier when new tokens are added to the parser.
To apply this patch, use:
curl http://cr.i3wm.org/patch/28/raw.patch | git am
b/testcases/t/201-config-parser.t
| 15 |
@@ -391,8 +391,11 @@ hide_edge_border both |
| 16 |
client.focused #4c7899 #285577 #ffffff #2e9ef4 |
| 17 |
EOT |
| 18 |
|
| 19 |
-$expected = <<'EOT'; |
| 20 |
+my $expected_all_tokens = <<'EOT'; |
| 21 |
ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent' |
| 22 |
+EOT |
| 23 |
+ |
| 24 |
+my $expected_end = <<'EOT'; |
| 25 |
ERROR: CONFIG: (in file <stdin>) |
| 26 |
ERROR: CONFIG: Line 1: hide_edge_border both |
| 27 |
ERROR: CONFIG: ^^^^^^^^^^^^^^^^^^^^^ |
| 28 |
@@ -400,6 +403,8 @@ ERROR: CONFIG: Line 2: client.focused #4c7899 #285577 #ffffff #2e9ef4 |
| 29 |
cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4) |
| 30 |
EOT |
| 31 |
|
| 32 |
+$expected = $expected_all_tokens . $expected_end; |
| 33 |
+ |
| 34 |
is(parser_calls($config), |
| 35 |
$expected, |
| 36 |
'errors dont harm subsequent statements'); |
| 37 |
@@ -438,9 +443,11 @@ unknown qux |
| 38 |
# this should not show up |
| 39 |
EOT |
| 40 |
|
| 41 |
-$expected = <<'EOT'; |
| 42 |
+my $expected_head = <<'EOT'; |
| 43 |
cfg_font(foobar) |
| 44 |
-ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent' |
| 45 |
+EOT |
| 46 |
+ |
| 47 |
+my $expected_tail = <<'EOT'; |
| 48 |
ERROR: CONFIG: (in file <stdin>) |
| 49 |
ERROR: CONFIG: Line 3: font foobar |
| 50 |
ERROR: CONFIG: Line 4: |
| 51 |
@@ -450,6 +457,8 @@ ERROR: CONFIG: Line 6: |
| 52 |
ERROR: CONFIG: Line 7: # yay |
| 53 |
EOT |
| 54 |
|
| 55 |
+$expected = $expected_head . $expected_all_tokens . $expected_tail; |
| 56 |
+ |
| 57 |
is(parser_calls($config), |
| 58 |
$expected, |
| 59 |
'error message (2+2 context) ok'); |
| 60 |
@@ -462,13 +471,14 @@ $config = <<'EOT'; |
| 61 |
unknown qux |
| 62 |
EOT |
| 63 |
|
| 64 |
-$expected = <<'EOT'; |
| 65 |
-ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent' |
| 66 |
+$expected_tail = <<'EOT'; |
| 67 |
ERROR: CONFIG: (in file <stdin>) |
| 68 |
ERROR: CONFIG: Line 1: unknown qux |
| 69 |
ERROR: CONFIG: ^^^^^^^^^^^ |
| 70 |
EOT |
| 71 |
|
| 72 |
+$expected = $expected_all_tokens . $expected_tail; |
| 73 |
+ |
| 74 |
is(parser_calls($config), |
| 75 |
$expected, |
| 76 |
'error message (0+0 context) ok'); |
| 77 |
@@ -482,14 +492,15 @@ $config = <<'EOT'; |
| 78 |
unknown qux |
| 79 |
EOT |
| 80 |
|
| 81 |
-$expected = <<'EOT'; |
| 82 |
-ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent' |
| 83 |
+$expected_tail = <<'EOT'; |
| 84 |
ERROR: CONFIG: (in file <stdin>) |
| 85 |
ERROR: CONFIG: Line 1: # context before |
| 86 |
ERROR: CONFIG: Line 2: unknown qux |
| 87 |
ERROR: CONFIG: ^^^^^^^^^^^ |
| 88 |
EOT |
| 89 |
|
| 90 |
+$expected = $expected_all_tokens . $expected_tail; |
| 91 |
+ |
| 92 |
is(parser_calls($config), |
| 93 |
$expected, |
| 94 |
'error message (1+0 context) ok'); |
| 95 |
@@ -503,14 +514,15 @@ unknown qux |
| 96 |
# context after |
| 97 |
EOT |
| 98 |
|
| 99 |
-$expected = <<'EOT'; |
| 100 |
-ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent' |
| 101 |
+$expected_tail = <<'EOT'; |
| 102 |
ERROR: CONFIG: (in file <stdin>) |
| 103 |
ERROR: CONFIG: Line 1: unknown qux |
| 104 |
ERROR: CONFIG: ^^^^^^^^^^^ |
| 105 |
ERROR: CONFIG: Line 2: # context after |
| 106 |
EOT |
| 107 |
|
| 108 |
+$expected = $expected_all_tokens . $expected_tail; |
| 109 |
+ |
| 110 |
is(parser_calls($config), |
| 111 |
$expected, |
| 112 |
'error message (0+1 context) ok'); |
| 113 |
@@ -525,8 +537,7 @@ unknown qux |
| 114 |
# context 2 after |
| 115 |
EOT |
| 116 |
|
| 117 |
-$expected = <<'EOT'; |
| 118 |
-ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent' |
| 119 |
+$expected_tail = <<'EOT'; |
| 120 |
ERROR: CONFIG: (in file <stdin>) |
| 121 |
ERROR: CONFIG: Line 1: unknown qux |
| 122 |
ERROR: CONFIG: ^^^^^^^^^^^ |
| 123 |
@@ -534,6 +545,8 @@ ERROR: CONFIG: Line 2: # context after |
| 124 |
ERROR: CONFIG: Line 3: # context 2 after |
| 125 |
EOT |
| 126 |
|
| 127 |
+$expected = $expected_all_tokens . $expected_tail; |
| 128 |
+ |
| 129 |
is(parser_calls($config), |
| 130 |
$expected, |
| 131 |
'error message (0+2 context) ok'); |