Commit graph

57 commits

Author SHA1 Message Date
Stan Lo
1095baed34 [ruby/irb] Support inspecting BasicObject
(https://github.com/ruby/irb/pull/541)

1dc2a406a3
2023-03-13 14:31:37 +00:00
Kevin Menard
8e13e705f9 [ruby/irb] Remove no longer necessary TruffleRuby test exclusions.
(https://github.com/ruby/irb/pull/527)

8473d0bc0f

Co-authored-by: Stan Lo <stan.lo@shopify.com>
2023-03-03 15:25:29 +00:00
tomoya ishida
a2b776a9b7 [ruby/irb] Fix prompt test not to change STDIO.external_encoding
(https://github.com/ruby/irb/pull/535)

09f16259db
2023-03-03 10:18:51 +00:00
Nobuyoshi Nakada
bd17bea6c5 [ruby/irb] Fix warnings because of @context.main.delete
If the main object of the context has `#delete` method, the following
warning is printed.

```
irb: warn: can't alias delete from irb_delete.
```

00b39be61f
2023-03-03 02:44:35 +00:00
tomoya ishida
556439613a [ruby/irb] Handle long inspect and control character in prompt
string
(https://github.com/ruby/irb/pull/528)

* Handle long inspect and control characters in prompt string

* Add constants for prompt truncate length, omission and replace pattern

* Simply compare string instead of regexp in prompt truncation test
2023-03-02 13:53:44 +00:00
Stan Lo
0aa50a03b1 [ruby/irb] Provide more useful message when
`IRB::Inspector#inspect_value` errors
(https://github.com/ruby/irb/pull/511)

**Before**

```
irb(main):001:0> c = Cat.new "foo"
(Object doesn't support #inspect)
=>
```

**After**

```
irb(main):001:0> c = Cat.new "foo"
An error occurred when inspecting the object: #<NoMethodError: undefined method `is_a?' for foo:Cat

      if obj.is_a?(String)
            ^^^^^^>
Result of Kernel#inspect: #<Cat:0x0000000109090d80 @name="foo">
=>
```
2023-02-27 11:07:19 +00:00
Stan Lo
970e7cdec3 [ruby/irb] Make tests more compatible with TruffleRuby
(https://github.com/ruby/irb/pull/514)

* Improve encoding error test case

The test input IRB currently uses happen to hit a compatibility bug in
TruffleRuby, which has been documented in
https://github.com/oracle/truffleruby/issues/2848

Although it'll eventually be fixed, we can make the test case support TruffleRuby
now by tweaking it just a little bit.

Co-authored-by: Kevin Menard <kevin@nirvdrum.com>

* Remove redundant TruffleRuby omits/pends

Co-authored-by: Kevin Menard <kevin@nirvdrum.com>

* Use a different way to test warning emission

The test case was added in d08ef68d2d
to verify that IRB emits Ruby warning as expected.

But the subject it uses relies on CRuby's regexp engine, which isn't always
used in other language implementations, like TruffleRuby. That's why we
ended up skipping TruffleRuby in this test case.

Since the test isn't about regexp itself, we can change the testing subject
and just remove the special condition for TruffleRuby.

Co-authored-by: Kevin Menard <kevin@nirvdrum.com>

---------

6fdf4f3e97

Co-authored-by: Kevin Menard <kevin@nirvdrum.com>
2023-02-09 15:33:37 +00:00
st0012
923c1aaed7
Drop Ruby 2.5 support
Because it has reached EOL for more than 1.5 years and it won't be
supported by the next reline version either.
2022-11-17 13:06:32 +09:00
st0012
1eae15142f [ruby/irb] Remove duplicated TestInputMethod definitions
4b831d02e1
2022-11-15 10:07:32 +00:00
Stan Lo
a923203811 [ruby/irb] Provide a base test class and let tests restore encodings
conveniently
(https://github.com/ruby/irb/pull/429)

* Create a base TestIRB::TestCase class

* Save/restore encodings for tests that initializes InputMethod classes

Because `RelineInputMethod#initializes` calls `set_encoding`, which
changes stdio/out/err and Encoding's default encoding values, we need to
make sure any test that directly or indirectly (e.g. through Context)
initializes `RelineInputMethod` restores encodings.

`ReadlineInputMethod` also changes encodings but currently no tests
cover it.

* Remove unnecessary TestHelper module

Since we now have a base TestCase, without_rdoc can just live there.

c2874ec121
2022-11-03 22:13:11 +00:00
tomoya ishida
a09f764ce5 [ruby/irb] Always use local variables in current context to parse code (https://github.com/ruby/irb/pull/397)
* Use local_variables for colorize, code_block_open check, nesting_level and assignment_expression check

* Check if expression is an assignment BEFORE evaluating it. evaluate might define new localvars and change result of assignment_expression?

* Add local_variables dependent code test

* pend local variable dependent test on truffleruby

code_block_open is not working on truffleruby

* Always pass context to RubyLex#lex

* Rename local_variable_assign_code generator method name

* Add assignment expression truncate test

* Add Context#local_variables and make generate_local_variables_assign_code more simple

* Update lib/irb/input-method.rb

Co-authored-by: Stan Lo <stan001212@gmail.com>

* Add a comment why assignment expression check should be done before evaluate

c8b3877281

Co-authored-by: Stan Lo <stan001212@gmail.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2022-10-18 05:44:07 +00:00
st0012
a415a3de05 [ruby/irb] Properly reset USE_COLORIZE after changing it in tests
Some context tests assigns USE_COLORIZE to false and never change it
back. This can potentially affect other tests' result as the default
should be nil (activated) instead.

986eb16ece
2022-06-29 00:23:18 +09:00
Stan Lo
44c1316293 [ruby/irb] Centralize coloring control (https://github.com/ruby/irb/pull/374)
* Use colorable: argument as the only coloring control

* Centalize color controling logic at Color.colorable?

There are 2 requirements for coloring output:

1. It's supported on the platform
2. The user wants it: `IRB.conf[:USE_COLORIZE] == true`

Right now we check 1 and 2 separately whenever we colorize things.
But it's error-prone because while 1 is the default of `colorable`
parameter, 2 always need to manually checked. When 2 is overlooked, it
causes issues like https://github.com/ruby/irb/pull/362

And there's 0 case where we may want to colorize even when the user
disables it. So I think we should merge 2 into `Color.colorable?` so it
can be automatically picked up.

* Add tests for all inspect modes

* Simplify inspectors' coloring logic

* Replace use_colorize? with Color.colorable?

* Remove Context#use_colorize cause it's redundant

1c53023ac4
2022-06-28 22:30:42 +09:00
Nobuyoshi Nakada
0e5f9afff6 [ruby/irb] Set prompt mode explictly
Fix https://github.com/ruby/irb/pull/353

7db93f9326
2022-06-26 15:23:33 +09:00
Nobuyoshi Nakada
a2b3f2014c [ruby/irb] Require stringio to use StringIO
e024ab716b
2022-06-26 15:23:32 +09:00
Peter Jones
e0bfdb23af [ruby/irb] Ensure stdout is a TTY before calling winsize
When outputting a (possibly truncated) value, IRB will query the
window size.  However, if IRB was piped to another process, stdout
will no longer be a TTY and will not support the `winsize` method.

This fix ensure that stdout is a TTY.

125de5eeea
2022-06-26 14:40:48 +09:00
aycabta
1855f901c8 [ruby/irb] Check colorize option correctly to clear char attr and don't use it for tests
de561cafeb
2021-12-21 15:50:32 +09:00
aycabta
340fabca2c [ruby/irb] Set default return_format
7ee15bc668
2021-10-11 15:39:48 +09:00
Nobuyoshi Nakada
66a4768f65 [ruby/irb] Relax backtrace nest levels
fb637bc68f
2021-08-30 13:16:46 +09:00
Hiroshi SHIBATA
b17dc55017 [ruby/irb] Added the extra stdout message with test-unit
b153d587a1
2021-08-30 12:39:37 +09:00
Hiroshi SHIBATA
f3ae14cbde [ruby/irb] Use capture_output instead of capture_io
077e4ae7de
2021-08-30 12:39:31 +09:00
Hiroshi SHIBATA
598f4f4219 [ruby/irb] Use pend instead of skip
f441ce35bf
2021-08-30 12:39:23 +09:00
aycabta
ece4ed0da7 Add --autocomplete / --noautocomplete options 2021-08-30 02:45:13 +09:00
Nobuhiro IMAI
b0fb208218 [ruby/irb] follow up the actual line number
7aed8fe3b1
2021-02-03 00:09:32 +09:00
Takashi Kokubun
e6af81bde1 [ruby/irb] Stub a screen size for test_context
http://ci.rvm.jp/logfiles/brlog.trunk-random1.20210119-074232

ea87592d4a
2021-01-19 00:14:48 -08:00
Takashi Kokubun
4da4ad69bb [ruby/irb] Support GitHub Actions
8e9e6c4037
2021-01-18 23:55:51 -08:00
Nobuhiro IMAI
166f33d0d1 [ruby/irb] skip a failling test on TruffleRuby
* due to the difference of backtrace pointed out by @aycabta

5e00a0ae61
2021-01-18 02:13:01 +09:00
Nobuhiro IMAI
d290a02bd7 [ruby/irb] handle repeated exception separately
fcf6b34bc5
2021-01-18 02:12:53 +09:00
aycabta
111fddd543 [ruby/irb] Fix BACK_TRACE_LIMIT logic
30dc5d43fe
2021-01-08 13:25:18 +09:00
aycabta
917050220a [ruby/irb] Use Exception#full_message to show backtrace in the correct order
[Bug #17466]

1c76845cca
2021-01-08 13:25:18 +09:00
Nobuhiro IMAI
ed3264d37a [ruby/irb] refactoring an error handling in IRB::Inspector
* moved rescue clause to `#inspect_value` to catch all failures in inspectors
* test with all (currently five kind of) inspect modes
  - tweaked the input due to only `Marshal` can inspect(dump) a `BasicObject`

9d112fab8e
2021-01-08 13:25:18 +09:00
Takashi Kokubun
af9d4ee133 [ruby/irb] Fix failing tests
7723ade899
2020-12-28 23:01:01 -08:00
Benoit Daloze
336fe648b0 [ruby/irb] Skip the few failing tests on TruffleRuby
22717844c0
2020-12-17 20:23:27 +09:00
aycabta
555ea83344 [ruby/irb] Drop OMIT_ON_ASSIGNMENT and add :truncate option for ECHO_ON_ASSIGNMENT
4c89b0775b
2020-09-19 05:13:08 +09:00
aycabta
8f9b1902f4 [ruby/irb] Omit output if first line of multiline is too long
0feeae38c5
2020-09-14 02:13:18 +09:00
aycabta
e468d9f49c [ruby/irb] Add OMIT_ON_ASSIGNMENT
Omit the results evaluated at assignment if they are too long.

The behavior of ECHO_ON_ASSIGNMENT being on by default is hard to understand,
so I change it to off by default. Instead, we turn OMIT_ON_ASSIGNMENT on by
default. The result is displayed on assignment, but it will always be short
and within one line of the screen.

c5ea79d5ce
2020-09-14 02:13:11 +09:00
aycabta
ee2529dffe Sometimes result indicator (=>) isn't shown 2020-07-22 03:49:17 +09:00
aycabta
0faf02718a Use simple assersion 2020-07-22 03:13:17 +09:00
aycabta
22d38d5475 [ruby/irb] Add test_eval_object_without_inspect_method
c0d9a26bce
2020-07-22 02:31:47 +09:00
aycabta
22477128cd [ruby/irb] Suppress crashing when EncodingError has occurred without lineno
13572d8cdc
2020-03-26 17:41:21 +09:00
Kenta Murata
51a8055d7d [ruby/irb] Add newline_before_multiline_output
9eb1801a66
2020-01-21 09:51:16 +09:00
aycabta
91bf3b7a77 Use singleline/multiline instead of readline/reidline 2019-11-21 02:44:35 +09:00
aycabta
a5b6d7bca8 Suppress warnings except for when last evaluation
Co-authored-by: Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
2019-11-13 15:15:28 +09:00
aycabta
1b02f6c020 Set IRB::Context#return_format on test clarify 2019-08-16 07:10:45 +09:00
Steven Willis
9d2fed2ccd Don't echo results of assignment expressions 2019-08-16 06:02:45 +09:00
Hiroshi SHIBATA
b39efb163d
Aliases capture_output to capture_io for test-unit compatiblity. 2019-08-08 17:19:23 +09:00
aycabta
43b52ac0a5 Revert "Don't echo results of assignment expressions"
This reverts commit 1ee88c51b3.
2019-08-06 20:28:48 +09:00
Steven Willis
1ee88c51b3 Don't echo results of assignment expressions 2019-08-06 20:15:07 +09:00
Nobuyoshi Nakada
0aa9b003de
context.rb: hide wrapping lines
* lib/irb/context.rb (IRB::Context#evaluate): separate the code
  from wrapping lines to propagate the given exception, not to show
  the wrapping lines when SyntaxError.
2019-05-27 11:05:51 +09:00
Takashi Kokubun
32ed85f601
Copy config to make IRB::Context#use_colorize? functional
on initialize

This fixes https://github.com/ruby/ruby/pull/2188
2019-05-21 04:32:17 -07:00