diff options
author | Peter Melnichenko <mpeterval@gmail.com> | 2018-09-21 19:01:32 +0300 |
---|---|---|
committer | Peter Melnichenko <mpeterval@gmail.com> | 2018-09-21 19:03:14 +0300 |
commit | 52a1a249dc186403ffa673924cf526cfce68a90a (patch) | |
tree | 759a52cdd62672f0c9d882fa30b09f03d6118469 | |
parent | 4d5aacf59ff277a1ad7505d0c915cc6f35085bf4 (diff) |
Fix test.assertraise treating return value of a call as its error
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | lua/pl/test.lua | 8 |
2 files changed, 6 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index eefc643..4541f24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,8 @@ - Fixed `pl.import_into` not importing some Penlight modules (#268). - Fixed version number stuck at 1.5.2 (#260). - Fixed `types.is_empty` returning `true` on tables containing `false` key (#267). - - Fixed `test.assertraise` throwing an error when passes an array with a function to call plus its arguments (#272). + - Fixed `test.assertraise` throwing an error when passed an array with a function to call plus its arguments (#272). + - Fixed `test.assertraise` not throwing an error when given function does not error but instead returns a string matching given error pattern. - Fixed placeholder expressions being evaluated with wrong precedence of binary and unary negation. - Fixed placeholder expressions being evaluated assuming wrong binary operator associativity (e.g. `_1-(_2+_3)` was evaluated as `(_1-_2)+_3`. - Fixed placeholder expressions being evaluated as if unary operators take precedence over power operator (e.g. `(-_1)^_2`) was evaluated as `-(_1^2)`). diff --git a/lua/pl/test.lua b/lua/pl/test.lua index 2c3a5da..694bbc5 100644 --- a/lua/pl/test.lua +++ b/lua/pl/test.lua @@ -85,13 +85,13 @@ end -- @param e a string to match the error against -- @param where extra level offset function test.assertraise(fn,e,where) - local _, err + local ok, err if type(fn) == 'table' then - _, err = pcall(unpack(fn)) + ok, err = pcall(unpack(fn)) else - _, err = pcall(fn) + ok, err = pcall(fn) end - if not err or err:match(e)==nil then + if ok or err:match(e)==nil then complain (err,e,"these errors did not match",where) end end |