936 Commits

Author SHA1 Message Date
dearblue 4cd858f93d Update test/t/kernel.rb
- Remove unnecessoury assert
- Fix typo
2020-06-09 20:33:56 +09:00
Mark Delk 3157efa57c only use GEMNAME if defined in assert.rb
Check if the constant GEMNAME is defined before use in `assert.rb`.

This is added to prevent an undefined constant error when using
`assert.rb` in other environments - for example, testing CRuby.
2020-06-08 00:30:46 -05:00
KOBAYASHI Shuji 52ab095ccf Print exception backtrace if possible without -v in test
Backtrace is useful for debugging.
2020-05-29 13:46:16 +09:00
Yusuke Endoh 6f4c585bd7 Do not destruct rest arguments for __send__
Formerly, `__send__(*args)` modified `args` with `Array#shift`.
This bug affects optcarrot.

This changeset avoids the array destruction by using
`args = args[1, len-1]`.
2020-05-24 01:25:03 +09:00
dearblue 81c8352179 Integrate class EnsureYieldBreak under test 2020-04-26 21:16:44 +09:00
Yukihiro "Matz" Matsumoto c181d89c9d Kernel#clone and Kernel#dup no longer raise TypeError; fix #4974
In ISO, those methods should raise `TypeError`, but the spec has been
changed.  The change was discussed in [Feature#12979].
2020-04-21 13:21:12 +09:00
Yukihiro "Matz" Matsumoto 364c47610f Fixed backtrace message for top-level blocks; fix #4936
In top-level, `mid` is `NULL`. We used to ignore 'mid` update for `NULL`.
2020-01-27 14:34:54 +09:00
Yukihiro "Matz" Matsumoto 06e09fc7a9 Numbered parameters should not be available in the lambda bodies.
`mruby` does not warn like `CRuby` for cases like #4893.
Fix #4890, fix #4891, fix #4893.
2019-12-21 22:41:32 +09:00
KOBAYASHI Shuji 74f564b0bb _0 is not numbered parameter
#### Before this patch:

  ```console
  $ bin/mruby rb -e '_0=:l; p ->{_0}.()'
  -e:1:13: _0 is not available
  -e:1:13: syntax error, unexpected $end, expecting '}'
  ```

#### After this patch (same as Ruby):

  ```console
  $ bin/mruby rb -e '_0=:l; p ->{_0}.()'
  :l
  ```
2019-12-21 18:54:15 +09:00
Yukihiro "Matz" Matsumoto 429f6defdd Reimplement vformat tests; close #4868
Avoid creating `Data` object that refers `mruby` objects.
Also close #4622 ref #4613
2019-12-19 09:35:51 +09:00
Yukihiro "Matz" Matsumoto 7f0e1fc90b Revert "%C value need not to be saved in TestVFormat::Native; close #4868"
This reverts commit f507ff4842.
It makes AppVeyor tests fail.
2019-12-19 00:07:08 +09:00
Yukihiro "Matz" Matsumoto 815e0c400a Merge pull request #4875 from shuujii/remove-location-info-from-Exception-inspect
Remove location info from `Exception#inspect`
2019-12-18 01:55:23 +09:00
Yukihiro "Matz" Matsumoto f507ff4842 %C value need not to be saved in TestVFormat::Native; close #4868 2019-12-18 01:40:11 +09:00
KOBAYASHI Shuji d2f2f9db51 Remove location info from Exception#inspect
Because location info (file name and line number) is kept in the backtrace,
it should not be kept in the result of `inspect` (and the exception object
itself), I think.

### Example

  ```ruby
  # example.rb
  begin
    raise "err"
  rescue => e
    p e
  end
  ```

#### Before this patch:

  ```
  $ bin/mruby example.rb
  example.rb:2: err (RuntimeError)
  ```

#### After this patch:

  ```
  $ bin/mruby example.rb
  err (RuntimeError)
  ```
2019-12-14 22:29:37 +09:00
KOBAYASHI Shuji 7192429e83 Fix behavior of Kernel#Integer to numbers ending with _ and spaces
#### Before this patch:

  ```ruby
  Integer("1_ ")  #=> 1
  ```

#### After this patch (same as Ruby):

  ```ruby
  Integer("1_ ")  #=> ArgumentError
  ```
2019-12-11 16:40:39 +09:00
KOBAYASHI Shuji bf431e77b8 Fix behavior of String#to_i/Kernel#Integer to numbers starting with _
#### Before this patch:

  ```ruby
  Integer("_1")  #=> 1
  "_1".to_i      #=> 1
  ```

#### After this patch (same as Ruby):

  ```ruby
  Integer("_1")  #=> ArgumentError
  "_1".to_i      #=> 0
  ```
2019-12-10 21:31:30 +09:00
Yukihiro "Matz" Matsumoto 543a9f84d1 Merge pull request #4858 from shuujii/fix-that-String-to_f-accepts-consecutive-_-as-a-numeric-expression
Fix that `String#to_f` accepts consecutive `_` as a numeric expression
2019-12-10 11:09:55 +09:00
KOBAYASHI Shuji 0893ee492c Fix that String#to_f accepts consecutive _ as a numeric expression
Consecutive `_` is not allowed as a numeric expression:

  1_2__3             #=> SyntaxError
  Float("1_2__3")    #=> ArgumentError
  Integer("1_2__3")  #=> ArgumentError
  "1_2__3".to_i      #=> 12

But `String#to_f` accept it, so I fixed the issue.

Before this patch:

  "1_2__3".to_f      #=> 123

After this patch:

  "1_2__3".to_f      #=> 12
2019-12-09 21:47:59 +09:00
Yukihiro "Matz" Matsumoto 0011652a28 Support new numbered parameter syntax _1 instead of @1. 2019-12-09 20:50:41 +09:00
Ukrainskiy Sergey 72d57ad094 Implement numbered parameters 2019-12-09 20:50:41 +09:00
KOBAYASHI Shuji 4b14c4633a Squeeze redundant spaces in test/t/numeric.rb [ci skip] 2019-10-25 19:39:31 +09:00
KOBAYASHI Shuji 7ce5d33947 Integrate mrb_str_inspect and mrb_str_dump 2019-10-10 19:50:48 +09:00
KOBAYASHI Shuji 882bc80dd0 Add tests for #4746 2019-10-03 16:59:18 +09:00
KOBAYASHI Shuji 198683e914 Simplify arguments check in String#rindex
Also fix document about type of the first argument.
2019-09-27 17:13:57 +09:00
KOBAYASHI Shuji 549317a36b Fix Fixnum overflow test in Integer#<< test
- Skip when `MRB_WITHOUT_FLOAT` is defined.
- Make `Fixnum` overflow even when `MRB_INT64` is defined.
2019-09-23 21:59:35 +09:00
KOBAYASHI Shuji e61095426b Simplify arguments check in String#index
Also fix document about type of the first argument.
2019-09-19 20:19:38 +09:00
KOBAYASHI Shuji 2f7175442f Fix Fixnum#(to_s|inspect) argument specs
Before this patch:

  $ bin/mruby -e 'p 3.to_s(2)'
  trace (most recent call last):
    [0] -e:1
  -e:1: 'to_s': wrong number of arguments (1 for 0) (ArgumentError)

After this patch:

  $ bin/mruby -e 'p 3.to_s(2)'
  "11"
2019-09-17 09:28:51 +09:00
Yukihiro "Matz" Matsumoto 04b098d000 Move tests related to getbyte, setbyte, byteslice` to core. 2019-09-11 18:49:08 +09:00
Yukihiro "Matz" Matsumoto 9d08025b8b Revert part of #4225
Since in mruby, Integer and Float interchange frequently (mostly on
overflow), so adding explicit `.0` can cause problems sometimes.

For example:
https://github.com/mattn/mruby-json/pull/40
https://github.com/pepabo/mruby-msd/pull/13
https://github.com/mattn/mruby-json/pull/42
2019-09-07 22:27:30 +09:00
takumakume 6c4278144a add assert_not_nil method 2019-09-05 19:51:54 +09:00
dearblue 414ab682f3 Add String#rindex test for invalid UTF-8 string 2019-08-17 11:44:27 +09:00
dearblue cf5f290fa0 Fix String#rindex test for UTF-8 string 2019-08-17 11:44:27 +09:00
KOBAYASHI Shuji 1e9cb74cc6 Change second argument to %l of mrb_vformat() to size_t from mrb_int
- `size_t` is more commonly used.
- `len` argument of `mrb_str_new()` is `size_t`.

NOTE:

The test for `%l` is temporarily disabled because adding a new type to
`mrbgems/mruby-test/vformat.c` causes an error (memory error?) on Visual
Studio 2017 in AppVeyor.
2019-08-03 19:42:22 +09:00
KOBAYASHI Shuji a4243360a2 Fix mrb_vformat("%f") with MRB_USE_FLOAT
It potentially not work when `mrb_float` is `float` because `float` variable
in variable length arguments is promoted to `double`.

Also I fixed build with `MRB_WITHOUT_FLOAT`.
2019-08-03 11:54:45 +09:00
KOBAYASHI Shuji d1817e7791 Change the mrb_vformat specifier %d for int
It potentially breaks, for example, in the case of `mrb_int` is 64-bit
and more smaller type is passed by `%d`. In fact, the problem could
become apparent when I used `%d` to `backtrace_location::lineno` in
`src/backtrace.c:mrb_unpack_backtrace()` on AppVeyor.

Therefore, change `%d` for `int` (not `mrb_int`) so that it can be
used mostly without casting.
2019-08-02 19:22:08 +09:00
KOBAYASHI Shuji eea42e06af Add new specifiers/modifiers to format string of mrb_vfromat()
Format sequence syntax:

  %[modifier]specifier

Modifiers:

  ----------+------------------------------------------------------------
  Modifier  | Meaning
  ----------+------------------------------------------------------------
      !     | Convert to string by corresponding `inspect` instead of
            | corresponding `to_s`.
  ----------+------------------------------------------------------------

Specifiers:

  ----------+----------------+--------------------------------------------
  Specifier | Argument Type  | Note
  ----------+----------------+--------------------------------------------
      c     | char           |
     d,i    | mrb_int        |
      f     | mrb_float      |
      l     | char*, mrb_int | Arguments are string and length.
      n     | mrb_sym        |
      s     | char*          | Argument is NUL terminated string.
      t     | mrb_value      | Convert to type (class) of object.
     v,S    | mrb_value      |
      C     | struct RClass* |
      T     | mrb_value      | Convert to real type (class) of object.
      Y     | mrb_value      | Same as `!v` if argument is `true`, `false`
            |                | or `nil`, otherwise same as `T`.
      %     | -              | Convert to percent sign itself (no argument
            |                | taken).
  ----------+----------------+--------------------------------------------

This change will increase the binary size, but replacing all format strings
with new specifiers/modifiers will decrease the size because it reduces
inline expansion of `mrb_obj_value()`, etc. at the caller.
2019-08-01 13:24:52 +09:00
Yukihiro "Matz" Matsumoto 7dae0ec74c Merge pull request #4606 from shuujii/refine-message-to-skip-in-nested-assert
Refine message to `skip` in nested `assert`
2019-07-30 14:41:09 +09:00
KOBAYASHI Shuji 44381f0a0c Refine message to skip in nested assert
- I think "Info" is used only to `skip`, so change to "Skip".
- Changed the default value of `assert` and specify the argument explicitly
  at the caller of `assert` because it is unnatural "Assertion failed" is
  output even though the assertion doesn't fail.

== Example:

  def assert_foo(exp, act)
    assert do
      assert_equal exp[0], act[0]
      assert_equal exp[1], act[1]
    end
  end

  def assert_bar(exp, act)
    assert do
      skip
    end
  end

  def assert_baz(exp, act)
    assert do
      assert_equal exp, act
      assert_bar exp, act
    end
  end

  assert 'test#skip_in_nested_assert' do
    assert_baz 1, 1
  end

  === Before this patch:

    ?..
    Info: test#skip_in_nested_assert (core)
     - Assertion[1]
        Info: Assertion failed (core)
         - Assertion[1-2]
            Skip: Assertion failed (core)
      Total: 3
         OK: 2
         KO: 0
      Crash: 0
    Warning: 0
       Skip: 1

  === After this patch:

    ???
    Skip: test#skip_in_nested_assert (core)
     - Assertion[1]
        Skip: assert (core)
         - Assertion[1-2]
            Skip: assert (core)
      Total: 3
         OK: 0
         KO: 0
      Crash: 0
    Warning: 0
       Skip: 3
2019-07-30 13:05:01 +09:00
KOBAYASHI Shuji 5091d047c0 Fix "Warn if assertion is missing inside assert"; ref ff43b2b9 2019-07-29 21:40:58 +09:00
Yukihiro "Matz" Matsumoto ff43b2b97c Fixed a conflict between #4407 and #4540 2019-07-29 01:25:58 +09:00
Yukihiro "Matz" Matsumoto 2ebc6d5b6f Merge pull request #4407 from shuujii/add-assert_raise_with_message-and-assert_raise_with_message_pattern
Add `assert_raise_with_message` and `assert_raise_with_message_pattern`
2019-07-29 01:05:26 +09:00
Yukihiro "Matz" Matsumoto cd8fc9bcb8 Resolved conflicts in #4320 2019-07-29 01:02:03 +09:00
KOBAYASHI Shuji 7675fcb5d3 Fix Module#dup to frozen module
Before this patch:

  $ bin/mruby -e 'p Module.new.freeze.dup.frozen?'  #=> true

After this patch (same as Ruby):

  $ bin/mruby -e 'p Module.new.freeze.dup.frozen?'  #=> false
2019-07-20 22:41:57 +09:00
KOBAYASHI Shuji 9873d5e0b9 Fix String#* test with MRB_WITHOUT_FLOAT 2019-07-18 17:51:02 +09:00
KOBAYASHI Shuji 9d2272ec2c Fix String#[] test 2019-07-17 20:09:37 +09:00
Yukihiro "Matz" Matsumoto d605b72c1d Merge branch 'master' into i110/inspect-recursion 2019-07-17 10:35:41 +09:00
Yukihiro "Matz" Matsumoto b4cdced22f Enumerable#detect {and #find} should call ifnone; fix #4484
It's an error in ISO specification; 15.3.2.2.4 and 15.3.2.2.7
2019-07-13 18:05:01 +09:00
dearblue e4249b1b9e Add UTF-8 test for String#index 2019-07-11 22:09:16 +09:00
KOBAYASHI Shuji c8a7d0ab95 Fix the order of "expected" and "actual" in test/t/range.rb 2019-07-09 13:13:13 +09:00
KOBAYASHI Shuji 32c2aa10c7 Fix Numeric#step to infinity; ref. #4555 2019-07-07 22:10:32 +09:00