Граф коммитов

581 Коммитов

Автор SHA1 Сообщение Дата
tomoya ishida eaad44adb2 [ruby/irb] Always add \n at the end of the test input in RubyLex
test
(https://github.com/ruby/irb/pull/614)

https://github.com/ruby/irb/commit/e68c6128aa
2023-06-27 10:19:03 +00:00
tomoya ishida 00216c8aa0 [ruby/irb] Fix process_continue(rename to should_continue?) and
check_code_block(rename to check_code_syntax)
(https://github.com/ruby/irb/pull/611)

https://github.com/ruby/irb/commit/b7f4bfaaa4
2023-06-25 05:12:16 +00:00
tomoya ishida 406799cae8 [ruby/irb] Omit nesting_level, use indent_level to build prompt
string
(https://github.com/ruby/irb/pull/610)

https://github.com/ruby/irb/commit/f01ff0811b
2023-06-24 22:20:43 +00:00
tomoya ishida e25403d0d9 [ruby/irb] Improve indentation: bugfix, heredoc, embdoc, strings
(https://github.com/ruby/irb/pull/515)

* Implement heredoc embdoc and string indentation with bugfix

* Fix test_ruby_lex's indentation value

* Add embdoc indent test

* Add workaround for lines==[nil] passed to auto_indent when exit IRB with CTRL+d
2023-06-20 15:13:43 +00:00
tomoya ishida b8cd79c82f [ruby/irb] Add missing token that ignored by ripper
(https://github.com/ruby/irb/pull/608)

https://github.com/ruby/irb/commit/1cd3b45402
2023-06-19 10:38:24 +00:00
tomoya ishida 364a6d56d7 [ruby/irb] Rewrite RubyLex to fix some bugs and make it possible to
add new features easily
(https://github.com/ruby/irb/pull/500)

* Add nesting level parser for multiple use (indent, prompt, termination check)

* Rewrite RubyLex using NestingParser

* Add nesting parser tests, fix some existing tests

* Add description comment, rename method to NestingParser

* Add comments and tweak code to RubyLex

* Update NestingParser test

* Extract list of ltype tokens to constants
2023-06-15 15:39:58 +00:00
Stan Lo 91b106fe4b [ruby/irb] Stanardise test class names with `Test` postfix instead
of prefix
(https://github.com/ruby/irb/pull/603)

https://github.com/ruby/irb/commit/359cb28def
2023-06-13 11:02:26 +00:00
tomoya ishida 5d91be7c1f [ruby/irb] Use symbol.inspect instead of ":"+symbol.id2name to avoid
completion candidates including newline characters
(https://github.com/ruby/irb/pull/539)

https://github.com/ruby/irb/commit/aaf0c46645
2023-06-13 10:46:38 +00:00
ima1zumi 76ee4edb97 [ruby/irb] Fixed string escaping omissions
(https://github.com/ruby/irb/pull/599)

I received a `RegexpError` when I typed `::Array[`.
::Array[/Users/mi/ghq/github.com/ruby/irb/lib/irb/completion.rb:236:in `retrieve_completion_data': premature end of char-class: /^Array[/ (RegexpError)
2023-06-05 18:34:10 +00:00
Stan Lo 8305681729 [ruby/irb] Require `test/lib` helpers from main test helper
(https://github.com/ruby/irb/pull/595)

Because they are handled differently in `ruby/irb` and `ruby/ruby`.
2023-06-02 13:54:07 +00:00
Stan Lo 2d2893f206 [ruby/irb] Improve debug command tests
(https://github.com/ruby/irb/pull/594)

* Use require_relative for envutil.rb

Requiring test helper files with `require_relative` allows running the tests
with `ruby -Itest test/irb/test_debug_cmd.rb` without having to set up
the load path.

* Replace reline hack with TERM=dumb
2023-06-01 20:10:13 +00:00
TSUYUSATO Kitsune 92d6c9a7b1 [ruby/irb] Allow `show_source` for private methods
(https://github.com/ruby/irb/pull/589)

* Allow `show_source` for private methods

Fix https://github.com/ruby/irb/pull/577

* Pend tests on TruffleRuby

It seems `eval(..., __LINE__ + 1)` does not work.
Other similar tests are also pended on TruffleRuby, so I think it
is acceptable.

* Use `private_method_defined?` instead of `defined?`
2023-05-23 16:16:37 +00:00
ima1zumi 64e156f20c [ruby/irb] Fix typo (https://github.com/ruby/irb/pull/587)
* Fix typo

* s/braking/breaking/g

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

---------

https://github.com/ruby/irb/commit/5f8e69f5f2

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-05-21 02:57:50 +00:00
Stan Lo 9ce6c08caf [ruby/irb] Add assertion for dynamic_prompt's assertion execution
(https://github.com/ruby/irb/pull/586)

Because the assertions for `dynamic_prompt` lives inside a block given to
`RubyLex`, they could be skipped unnoticed if the setup is not correct.

This commit adds a simple assertion to check if the block was actually
executed.
2023-05-20 04:28:23 +00:00
tomoya ishida 6d9875ccbf [ruby/irb] Fix dynamic_prompt test not executed, remove unnecessary
set_input
(https://github.com/ruby/irb/pull/585)

https://github.com/ruby/irb/commit/b5f3efdcf0
2023-05-20 01:08:58 +00:00
tomoya ishida e8c9f727e8 [ruby/irb] Simplify each_top_level_statement
(https://github.com/ruby/irb/pull/576)

* Simplify each_top_level_statement, reduce instance vars

* Update lib/irb/ruby-lex.rb

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

* Remove unused ltype from TestRubyLex#check_state response

* Remove unnecessary const path of TerminateLineInput

* Combine duplicated code state check into method

---------

https://github.com/ruby/irb/commit/172453cec4

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-05-19 13:48:08 +00:00
Stan Lo cfb7997353 [ruby/irb] Refactor RubyLex's input/io methods
(https://github.com/ruby/irb/pull/583)

1. Make `RubyLex#set_input` simply assign the input block. This matches
   the behavior of `RubyLex#set_prompt`.
2. Merge `RubyLex#set_input`'s IO configuration logic with `#set_auto_indent`
   into `#configure_io`.
2023-05-18 19:00:33 +00:00
Stan Lo b695f58d52 [ruby/irb] Print deprecation warning for `help` command
(https://github.com/ruby/irb/pull/567)

* Give show_doc its own command class

* Print deprecation warning for `help` command
2023-05-18 03:28:31 +00:00
tomoya ishida 264ba0f89a [ruby/irb] Fix Test timedout in test_debug_cmd
(https://github.com/ruby/irb/pull/582)

* Suppress Reline::IOGate.cursor_pos writing escape sequence in test_debug_cmd

* Force use Reline::GeneralIO as Reline::IOGate and remove RUBY_DEBUG_NO_RELINE option for debug test
2023-05-17 04:42:32 +00:00
Stan Lo 92466e440d [ruby/irb] Use a more tolerant way to check Locale#find's return
path
(https://github.com/ruby/irb/pull/572)

https://github.com/ruby/irb/commit/0b648adf38
2023-04-26 16:52:51 +00:00
Stan Lo 3340a24634 [ruby/irb] Add tests for Locale#find and Locale#load
(https://github.com/ruby/irb/pull/570)

https://github.com/ruby/irb/commit/710d5b1af5
2023-04-26 16:39:19 +00:00
Stan Lo 299d17a2f1
[ruby/irb] Fix Locale's encoding lookup for Japanese encodings
(https://github.com/ruby/irb/pull/568)

In 3ee79e89ad,
`encoding_aliases.rb` was introduced to return the correct encoding object for
`ujis` and `euc` encodings.

However, the return value of `@@legacy_encoding_alias_map[@encoding_name]`
is always overridden by a second look up with `Encoding.find(@encoding_name)`.
So the logic didn't work as expected.

This commit fixes the problem.
2023-04-26 13:13:25 +09:00
Hiroshi SHIBATA 5154d6beed
Revert "Temporary skipped failing assertions"
This reverts commit e7cdce83e8.
2023-04-26 13:13:25 +09:00
Hiroshi SHIBATA e7cdce83e8
Temporary skipped failing assertions 2023-04-25 15:05:14 +09:00
Stan Lo 9ccf0a066d [ruby/irb] Add tests for Locale class
(https://github.com/ruby/irb/pull/566)

https://github.com/ruby/irb/commit/df32e024be
2023-04-25 14:41:06 +09:00
Stan Lo 73fc81199d [ruby/irb] Simplify the help command's implementation
(https://github.com/ruby/irb/pull/564)

The current method-redefining approach brings little benefit, makes it
harder to understand the code, and causes warnings like:

> warning: method redefined; discarding old execute

This patch simplifies it while displaying more helpful message when rdoc
couldn't be loaded.
2023-04-24 14:10:36 +00:00
Stan Lo 805899dda2 [ruby/irb] Filter out top-level methods when using `ls
<Class/Module>`
(https://github.com/ruby/irb/pull/562)

Instead of always printing methods inherited from Class or Module, IRB by
default should filter them out unless `<Class/Module>` is specified to be
either of those.
2023-04-24 14:05:16 +00:00
tomoya ishida f8115ec727 [ruby/irb] Fix RubyLex's heredoc_with_hembexpr test to avoid ripper
tokenizing issue
(https://github.com/ruby/irb/pull/558)

https://github.com/ruby/irb/commit/f68e891ed1
2023-04-07 11:03:28 +00:00
Stan Lo 2f8e5c80e6 [ruby/irb] Drop Ruby 2.6 support
(https://github.com/ruby/irb/pull/555)

* Remove all Ruby 2.6 support

* Drop Ruby 2.6 specific testing conditions

* Only run Ruby 2.7+ on CI

* Bump Ruby requirement to 2.7+

https://github.com/ruby/irb/commit/3f714b616c
2023-04-05 21:40:40 +00:00
Stan Lo cd94bcdc46 [ruby/irb] Don't check RUBY_ENGINE when deciding whether to accept kargs
Ruby implementations like JRuby and TruffleRuby already indicate their
compatibility target with RUBY_VERSION. We don't need to exclude
them from accepting keyword arguments as long as they target 2.7+.

https://github.com/ruby/irb/commit/bf20faa4e6

Co-authored-by: Kevin Menard <kevin@nirvdrum.com>
2023-04-02 15:34:28 +00:00
Stan Lo 23892d95f5 [ruby/irb] Drop unnecessary pends for truffleruby
https://github.com/ruby/irb/commit/2517039812
2023-03-31 22:02:58 +00:00
lukeg 418cf344fb [ruby/irb] Fix 2 minor issues in test suite
* undefine Kernel#irb_original_require in without_rdoc method
* Don't rescue all LoadErrors/NameErrors in test_rendering.rb, just
the one for require 'yamatanooroti'

https://github.com/ruby/irb/commit/52b79806ea
2023-03-17 15:19:40 +00:00
Stan Lo 1095baed34 [ruby/irb] Support inspecting BasicObject
(https://github.com/ruby/irb/pull/541)

https://github.com/ruby/irb/commit/1dc2a406a3
2023-03-13 14:31:37 +00:00
tomoya ishida 0463c5806a [ruby/irb] Improve method completion for string and regexp that
includes word break characters
(https://github.com/ruby/irb/pull/523)

* Improve method completion for string and regexp that includes word break characters

* Remove completion-test's assert_not_include because candidates no longer include every possible methods

* Add comment about string's method completion regexp

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

* Add comment about regexp's method completion regexp

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

---------

https://github.com/ruby/irb/commit/aa8128c533

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-03-06 05:52:46 +00:00
Stan Lo 191e4ae33f [ruby/irb] Drop chained methods' completion support
(https://github.com/ruby/irb/pull/529)

Consider completion for this example: `foo.bar.b`

Without type information, it is hard to know the return value of the `bar`
method, so the current implementation interates through `ObjectSpace` to
get all possible candidates for the second method.

In small projects, the performance and accuracy are acceptable. But in
bigger projects, the performance is unacceptable and the accuracy is mostly
poor.

So this commit drops the support for chained methods' completion.
2023-03-04 15:34:49 +00:00
Kevin Menard 8e13e705f9 [ruby/irb] Remove no longer necessary TruffleRuby test exclusions.
(https://github.com/ruby/irb/pull/527)

https://github.com/ruby/irb/commit/8473d0bc0f

Co-authored-by: Stan Lo <stan.lo@shopify.com>
2023-03-03 15:25:29 +00:00
tomoya ishida b49053a6be [ruby/irb] Avoid slow symbol completion when completion target is an
empty symbol
(https://github.com/ruby/irb/pull/534)

https://github.com/ruby/irb/commit/35697f3ef3
2023-03-03 13:41:21 +00:00
tomoya ishida a2b776a9b7 [ruby/irb] Fix prompt test not to change STDIO.external_encoding
(https://github.com/ruby/irb/pull/535)

https://github.com/ruby/irb/commit/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.
```

https://github.com/ruby/irb/commit/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 9ddd73060b [ruby/irb] Display and prioritise instance methods in `ls
<module/class>`
(https://github.com/ruby/irb/pull/496)

https://github.com/ruby/irb/commit/e3d21f9329
2023-02-28 14:36:12 +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 07403de5a8 [ruby/irb] Cleanup completion tests
(https://github.com/ruby/irb/pull/520)

* Remove redundant completion test

The test case was introduced to guard an old implementation, which relied
on `Module#name`. Commit:

8827d18274

However, the current implementation has avoided calling `Module#name`
completely, so the test case is no longer necessary. Commit:

88311ce3c8

* Remove unnecessary pend
2023-02-24 13:34:40 +00:00
Stan Lo 50e77b6a9c [ruby/irb] Improve RubyLex's tests
(https://github.com/ruby/irb/pull/484)

* Improve assert_indenting helper

Instead of putting assertions inside the `auto_indent` block, we
can just make `auto_indent` return the calculated space count, and use
it for assertion outside of the `auto_indent` block call.

This simplifies the setup code and makes the intention easier to
understand.

* Introduce assert_row_indenting helper

1. Helper users shouldn't need to write 2 assertions for the current and
   the next line's indentation.
2. With this new approach, we can generate clearer error message for
   both cases:

When the current line's space count doesn't match

```
  Incorrect spaces calculation for line:

  ```
> def each_top_level_statement
  ```

  All lines:

  ```
  def each_top_level_statement
  ```

<0> expected but was
<nil>
```

When the next line's space count doesn't match

```
  Incorrect spaces calculation for line after the current line:

  ```
  def each_top_level_statement
>
  ```

  All lines:

  ```
  def each_top_level_statement
  ```

<3> expected but was
<2>
```

* Replace assert_indenting with assert_row_indenting
2023-02-21 19:38:09 +00:00
tomoya ishida f313514563 [ruby/irb] Fix colorize backtick symbol
(https://github.com/ruby/irb/pull/508)

https://github.com/ruby/irb/commit/dd7f25cd45

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-02-12 20:27:32 +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>

---------

https://github.com/ruby/irb/commit/6fdf4f3e97

Co-authored-by: Kevin Menard <kevin@nirvdrum.com>
2023-02-09 15:33:37 +00:00
Stan Lo 295fc59eda [ruby/irb] Add tests for workspaces commands
(https://github.com/ruby/irb/pull/512)

https://github.com/ruby/irb/commit/874dbcad81
2023-02-04 22:31:17 +00:00
Stan Lo cb9b885e78 [ruby/irb] Store context in RubyLex
Some background for this refactor:

1. Through a RubyLex instance's lifetime, the context passed to its methods
   should be the same.
   Given that `Context` is only initialised in `Irb#initialize`,
   this should be true.

2. When `RubyLex` is initialised, the context object should be accessible.
   This is also true in all 3 of `RubyLex.new`'s invocations.

With the above observations, we should be able to store the context in `RubyLex`
as an instance variable. And doing so will make `RubyLex`'s instance methods
easier to use and maintain.

https://github.com/ruby/irb/commit/5c8d3df2df
2023-01-14 09:19:09 +00:00
Stan Lo 207f8d0027 [ruby/irb] Avoid calling private methods on the main object
(https://github.com/ruby/irb/pull/498)

When the main object is frozen, `IRB` wraps a `SimpleDelegator` around it.
But because `SimpleDelegator` doesn't delegate private methods, methods like
`require_relative` or `const_get` would cause error, which are needed for
lazily loading commands.

This commit works around this limitation by avoiding those private method calls
when setting up command execution.
2023-01-12 11:49:16 +00:00
Stan Lo c693dfd7ef [ruby/irb] Drop unused arguments in `RubyLex`
(https://github.com/ruby/irb/pull/504)

* Simplify `RubyLex#set_prompt`

It's optional argument is never used by any caller.

* Remove the optional `p` argument from `RubyLex#set_input`

The argument is only used in a test case, which can be easily replaced by
a block argument.
2023-01-11 21:26:18 +00:00
Stan Lo f9148d1580 [ruby/irb] Group command test cases with class
(https://github.com/ruby/irb/pull/491)

Currently, IRB has 35 test cases for 10 non-debugging commands, with the
rest 10 commands untested. So in the long-term, it could have around 70
test cases for all existing commands.

With this number of test cases, I think it's easier to manage them by grouping
them in classes (by command).
2023-01-05 13:06:23 +00:00
tomoya ishida 34f8ca1714 [ruby/irb] Fix prompt and code mismatch
(https://github.com/ruby/irb/pull/386)

* fix prompt and code mismatch

* Add test for prompt and code mismatch bug

https://github.com/ruby/irb/commit/a5765d8177

Co-authored-by: Stan Lo <stan001212@gmail.com>
2023-01-02 19:25:11 +00:00
Stan Lo 140c93e2dc [ruby/irb] Add dynamic prompt test case for quoted heredoc
(https://github.com/ruby/irb/pull/486)

https://github.com/ruby/irb/commit/31cfbeacbb
2022-12-27 16:43:44 +00:00
Takashi Kokubun d5985049c7 Sync IRB master: tool/sync_default_gems.rb irb
It looks like tool/sync_default_gems.rb is not capable of cherry-picking
commits from ruby/irb. I just executed `tool/sync_default_gems.rb irb`
to fix the sync status.

I'm not sure if what's the cause. It could be related to some diff that
doesn't exist in ruby/ruby, or it might be related to non-linear history
due to merge commits. For next time, I'd like to at least exclude the
second possibility, so I disabled merge commits in ruby/irb.
2022-12-26 13:10:37 -08:00
Nobuyoshi Nakada d01bcf378b [ruby/irb] Suppress "switching inspect mode" messages
https://github.com/ruby/irb/commit/565eeb3c19
2022-12-26 13:04:04 -08:00
Stan Lo 87988756d0 [ruby/irb] Remove unnecessary warning check on help command
It's not an intentional behavior of the command and it behaves
differently in different environments. So checking it actually brings
more problem than benefit.

https://github.com/ruby/irb/commit/b3203bc784
2022-12-26 13:04:04 -08:00
Stan Lo 148eb05ec1 [ruby/irb] Remove unnecessary test setup
https://github.com/ruby/irb/commit/cc6e6d26b6
2022-12-26 13:04:03 -08:00
st0012 8038bf239a [ruby/irb] Add test for the help command
https://github.com/ruby/irb/commit/9cacb5f352
2022-12-26 13:04:03 -08:00
Nobuyoshi Nakada a968d783a3 [ruby/irb] Test colors with enabling colors
https://github.com/ruby/irb/commit/998b7a74fa
2022-12-26 15:28:38 +00:00
Nobuyoshi Nakada 1148636e3d [ruby/irb] PTY module is platform dependent
https://github.com/ruby/irb/commit/dbb3dc72ff
2022-12-19 17:49:59 +09:00
Hiroshi SHIBATA d6624db926 [ruby/irb] Prefer to use File.open instead of Kernel.open
https://github.com/ruby/irb/commit/ed9e435a6b
2022-12-16 01:10:46 +00:00
Stan Lo f88f2bd92f [ruby/irb] Group show_doc tests and update the expectation
(https://github.com/ruby/irb/pull/479)

https://github.com/ruby/irb/commit/bede04c14a
2022-12-12 21:05:03 +00:00
Stan Lo 223d4448c8 [ruby/irb] `show_doc` command should take non-string argument too
(https://github.com/ruby/irb/pull/478)

Given that `show_doc` already supports syntax like `String#gsub`, it
should be able to take it in non-string form too, like `edit` and
`show_source` do. This ensures users can have a consistent syntax on
argument between different commands.
2022-12-12 17:35:48 +00:00
Stan Lo 381e128c13 [ruby/irb] Fix step command (https://github.com/ruby/irb/pull/477)
The current `next` pre-command workaround on IRB source stepping
moves the location by 1 extra line. A better way is to make `debug`
skip IRB frames completely, which is what this commit does.

It also fixes the step command's test. The `|` in regexp was not escaped
so it was always incorrectly matched.
2022-12-09 23:39:17 +00:00
Stan Lo c9076d546a [ruby/irb] Add show_doc as an alias to the help command
(https://github.com/ruby/irb/pull/475)

In the long-term, we want to align with `Pry`, `byebug` and `debug` to
use the `help` command to list all commands, which is what `show_cmds`
currently does. And `show_doc` will be the command to look up Ruby APIs.

By aliasing `show_doc` to the current `help` now, users will have time
to get use to it.
2022-12-08 21:46:55 +00:00
Stan Lo 12b7c129bf [ruby/irb] Gracefully handle missing command argument
(https://github.com/ruby/irb/pull/473)

* Handle file loading commands' argument error gracefully

Currently, if users don't provide an argument to `source`,
`irb_load`, and `irb_require`, IRB raises `ArgumentError` with full
stacktrace. This is confusing because it looks similar to when IRB has
internal issues. The message also isn't helpful on helping users avoid
the error.

So in this commit, I add a new `CommandArgumentError` for commands to
raise explicitly when users' input doesn't satisfy a command's argument
requirement.

* Gracefully handle `fg` command's argument requirement
2022-12-08 21:05:37 +00:00
Stan Lo a87f802f1e [ruby/irb] Kill PTY process after test is finished
(https://github.com/ruby/irb/pull/471)

The killing/waiting logic is borrowed from ruby/debug:

ec5ae5aebd/test/support/test_case.rb (L107-L136)
2022-12-08 19:11:51 +00:00
Stan Lo 3956bb859c [ruby/irb] Add "show_cmds" command to list all commands'
descriptions
(https://github.com/ruby/irb/pull/463)

https://github.com/ruby/irb/commit/7e857655ac
2022-12-08 19:10:23 +00:00
Stan Lo 9aa18f61f2 [ruby/irb] Allow disabling autocompletion with
`IRB_USE_AUTOCOMPLETE=false`
(https://github.com/ruby/irb/pull/469)

* Allow using IRB_USE_AUTOCOMPLETE=false to disable autocompletion

Currently, the only 2 ways to disable autocompletion are:

1. Create `.irbrc` and set `IRB.conf[:USE_AUTOCOMPLETE] = false`
2. Add the `--noautocomplete` flag when using the `irb` executable

Both of them are less convenient than setting a env var and are
lesser known to devs.

And given the number of problems the autocompletion has (see #445), I
think we should allow disabling it with a simple `IRB_USE_AUTOCOMPLETE=false`.

* Mention some env var configs in the README
2022-12-06 00:53:32 +00:00
Nobuyoshi Nakada 74923aaf31 [ruby/irb] Close leaked pty IOs
https://github.com/ruby/irb/commit/cc9b1d7ba8
2022-12-05 12:03:57 +00:00
Stan Lo 7161bf34e1 [ruby/irb] Require pathname in test helper
(https://github.com/ruby/irb/pull/467)

https://github.com/ruby/irb/commit/39c6924c12
2022-12-02 22:00:42 +00:00
Stan Lo 69fd673b1a [ruby/irb] Disable debug cmd tests based on project structure
instead of env
(https://github.com/ruby/irb/pull/466)

It's hard to find an env var that's universally set in all Ruby CI
environments but not in local. Checking gemspec seems to be a better way
as `syntax_suggest` already uses it for a while.

d8f1bca297/spec/spec_helper.rb (L47)
2022-12-02 20:43:59 +00:00
Takashi Kokubun f01bfa8af7 [ruby/irb] This doesn't work on RubyCI either
http://rubyci.s3.amazonaws.com/rhel_zlinux/ruby-master/log/20221202T063302Z.fail.html.gz
http://rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20221202T053006Z.fail.html.gz
http://rubyci.s3.amazonaws.com/freebsd12/ruby-master/log/20221202T063002Z.fail.html.gz
http://rubyci.s3.amazonaws.com/osx1013/ruby-master/log/20221202T054503Z.fail.html.gz

https://github.com/ruby/irb/commit/13c2484d59
2022-12-02 07:41:18 +00:00
Takashi Kokubun 7e3b42d008 [ruby/irb] Skip debug command tests on ruby/ruby
Stan has said these tests could be excluded if they don't work on
ruby/ruby CI.

https://github.com/ruby/irb/commit/11e779ecb7
2022-12-02 04:43:36 +00:00
Nobuyoshi Nakada b6c66ead9d [ruby/irb] Use the proper ruby command and library path
https://github.com/ruby/irb/commit/1416cc1871
2022-12-02 03:14:51 +00:00
Stan Lo 8abf9e6ad0 [ruby/irb] Test debug commands without yamatanooroti
(https://github.com/ruby/irb/pull/464)

* Add debug command tests that don't require yamatanooroti

* Remove debug command related yamatanooroti tests

As discussed in https://github.com/ruby/irb/pull/449#pullrequestreview-1187255149,
we should avoid adding new tests that need yamatanooroti because it's
not maintained by the Ruby org. And since debug commands are now tested
in `test/irb/test_debug_cmd.rb`, we don't need these tests anymore.

* Test against latest debug gem

https://github.com/ruby/irb/commit/78a8aa8834
2022-12-02 01:05:22 +00:00
Stan Lo ec76c9868b [ruby/irb] Activate yamatanooroti tests on CI
(https://github.com/ruby/irb/pull/459)

* Activate yamatanooroti tests on CI

* Fix delete test

https://github.com/ruby/irb/commit/750cf4c480
2022-11-27 06:09:50 +00:00
Takashi Kokubun c9fbc779a6 [ruby/irb] Add commands to start and use the debugger
(https://github.com/ruby/irb/pull/449)

* Seamlessly integrate a few debug commands

* Improve the break command support

* Utilize skip_src option if available

* Add step and delete commands

* Write end-to-end tests for each debugger command

* Add documentation

* Add backtrace, info, catch commands

https://github.com/ruby/irb/commit/976100c1c2
2022-11-21 08:46:27 +00:00
Yusuke Endoh 730b841f8d Prevent a "warning: ambiguity between regexp and two divisions" 2022-11-21 16:13:15 +09:00
Takashi Kokubun 66ac288ae2 [ruby/irb] Push an accidentally uncommitted diff
https://github.com/ruby/irb/commit/7e9f27afd7
2022-11-20 05:38:43 +00:00
Takashi Kokubun 67034ac7e2 [ruby/irb] Deal with inconsistency with ruby/ruby
https://github.com/ruby/irb/commit/41d5012849
2022-11-20 05:34:51 +00:00
Takashi Kokubun 8512b97d27 [ruby/irb] Require missing EnvUtil
https://github.com/ruby/irb/commit/9bb1757b02
2022-11-20 05:32:11 +00:00
Takashi Kokubun fa2e0cc018 [ruby/irb] Try using a different file name
hoping to address:
https://github.com/ruby/ruby/actions/runs/3506561941/jobs/5873689640

https://github.com/ruby/irb/commit/de9a6b9d00
2022-11-20 05:31:56 +00:00
Takashi Kokubun f47251671d [ruby/irb] Require rubygems for ruby/ruby
You can't take rubygems for granted in a default gem.
https://github.com/ruby/ruby/actions/runs/3506561943/jobs/5873689466

https://github.com/ruby/irb/commit/58bb3954d0
2022-11-20 05:19:50 +00:00
Takashi Kokubun e0f0367ab5 [ruby/irb] Fix CI failure on ruby/ruby
https://github.com/ruby/irb/commit/ea8c716922
2022-11-20 05:06:07 +00:00
Stan Lo 180ed611b2 [ruby/irb] Add edit command (https://github.com/ruby/irb/pull/453)
* Add edit command

* Make find_source a public singleton method

* Add document for the edit command

* Make find_end private

* Remove duplicated private

https://github.com/ruby/irb/commit/4321674aa7
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2022-11-20 04:47:54 +00:00
Yusuke Endoh ca1aa7afea Prevent a "method redefined" warning
http://rubyci.s3.amazonaws.com/ubuntu2004-arm/ruby-master/log/20221118T033003Z.log.html.gz
```
[21350/22024] TestIRB::ExtendCommandTest#test_show_source_end_finder/home/chkbuild/chkbuild/tmp/build/20221118T033003Z/ruby/test/irb/test_cmd.rb:523: warning: method redefined; discarding old show_source_test_method
/home/chkbuild/chkbuild/tmp/build/20221118T033003Z/ruby/test/irb/test_cmd.rb:523: warning: previous definition of show_source_test_method was here
 ```
2022-11-18 15:39:50 +09: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
Stan Lo 9751b54971 [ruby/irb] Improve testing infra
(https://github.com/ruby/irb/pull/442)

* Add test_in_isolation task to run tests in isolation

This simulates how tests are run in Ruby CI and can detect some issues
before they're merged and break Ruby CI later.

* Run test_in_isolation task on CI

* Fix TestRaiseNoBacktraceException's setup

https://github.com/ruby/irb/commit/51f23c58b0
2022-11-15 17:26:51 +00:00
Hiroshi SHIBATA 36dc99af5a
Added empty class for test methods in TestIRB cases 2022-11-15 20:19:43 +09:00
st0012 1eae15142f [ruby/irb] Remove duplicated TestInputMethod definitions
https://github.com/ruby/irb/commit/4b831d02e1
2022-11-15 10:07:32 +00:00
Stan Lo 14a1394bcd [ruby/irb] Simplify info command's tests
(https://github.com/ruby/irb/pull/440)

https://github.com/ruby/irb/commit/5942949226
2022-11-11 21:05:35 +00:00
Takashi Kokubun 8fa83fa0b2 [ruby/irb] Transform ls's --grep/-G option to keyword args
(https://github.com/ruby/irb/pull/437)

* Transform ls's --grep/-G option to keyword args

* Make --grep less flexible

* Support -g instead of --grep

* Suppress warnings from symbol aliases
2022-11-10 22:55:15 +00:00
Takashi Kokubun 0de3bc92b4 [ruby/irb] Make $ and @ default aliases
(https://github.com/ruby/irb/pull/438)

https://github.com/ruby/irb/commit/0613589476
2022-11-10 17:31:15 +00:00
Stan Lo b7b78f062f [ruby/irb] Add execute_lines to reduce command tests' boilerplate
code
(https://github.com/ruby/irb/pull/436)

https://github.com/ruby/irb/commit/1595337149
2022-11-08 17:19:59 +00:00
Takashi Kokubun 9001e53e68 [ruby/irb] Support non-string input in show_source
(https://github.com/ruby/irb/pull/430)

* Support non-string input in show_source

* Test show_source as a method
2022-11-07 17:29:28 +00:00
Stan Lo 367c072ac6 [ruby/irb] Silent the noise created when building Context in tests
https://github.com/ruby/irb/commit/27e4274b3c
2022-11-04 18:29:54 +00:00
Nobuyoshi Nakada b83074dac7 [ruby/irb] Suppress "switching inspect mode" messages
https://github.com/ruby/irb/commit/ee068d039b
2022-11-04 11:43:21 +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.

https://github.com/ruby/irb/commit/c2874ec121
2022-11-03 22:13:11 +00:00
Takashi Kokubun a13836e70d [ruby/irb] Allow non-identifier aliases like Pry's @ and $
(https://github.com/ruby/irb/pull/426)

* Allow non-identifier aliases

* Move the configuration to IRB.conf

* Avoid abusing method lookup for symbol aliases

* Add more alias tests

* A small optimization

* Assume non-nil Context

* Load IRB.conf earlier

https://github.com/ruby/irb/commit/e23db5132e
2022-11-03 22:09:55 +00:00
Takashi Kokubun 56884b64de [ruby/irb] Require rubygems to run the test alone on ruby/ruby
`Gem` is not undefined on test-all

https://github.com/ruby/irb/commit/08ac803d61
2022-11-03 17:42:45 +00:00
Takashi Kokubun 611b5e7f40 [ruby/irb] Fix build_context for ruby/ruby CI
Co-Authored-By: Stan Lo <stan.lo@shopify.com>

https://github.com/ruby/irb/commit/d1fe234a9a
2022-11-03 17:35:15 +00:00
Stan Lo 00f559641a [ruby/irb] Require the entire irb lib in RubyLex test
(https://github.com/ruby/irb/pull/428)

RubyLex is not designed to be used alone. It's usually used with an IRB
context, which requires workspace. So its tests should have access to
those components too.

https://github.com/ruby/irb/commit/608f261da4
2022-11-03 17:12:35 +00:00
Stan Lo c5d6a483f5 [ruby/irb] Refactor RubyLex and its tests
(https://github.com/ruby/irb/pull/427)

* Make sure `RubyLex#set_input`'s context is always present in tests

In real-world scenarios, the context should always be non-nil:
https://github.com/ruby/irb/blob/master/lib/irb.rb#L489

So we should make sure our test setup reflects that.

* Make context a required keyword

Since in practice, `set_input`'s context should always be non-nil, its
parameters should reflect that.

And since `RubyLex#check_state` is only called by `#lex` and
`#set_input`, both of which now always require context, we can assume
its context should be non-nil too.

https://github.com/ruby/irb/commit/1aeeb86203
2022-11-03 16:32:22 +00:00
Nobuyoshi Nakada 4021c6565f [ruby/irb] Do not make non-existent XDG directory on start
(https://github.com/ruby/irb/pull/357)


https://github.com/ruby/irb/commit/298b134792
2022-10-28 09:36:28 +00:00
Nobuyoshi Nakada 56c97a6621 [ruby/irb] Update regarding NO_COLOR value
https://no-color.org has been updated (jcs/no_color#83):

> Command-line software which adds ANSI color to its output by default
should check for a `NO_COLOR` environment variable that, when present
and **not an empty string** (regardless of its value), prevents the
addition of ANSI color.

https://github.com/ruby/irb/commit/46e0f7e370

Co-authored-by: Stan Lo <stan001212@gmail.com>
2022-10-28 09:30:24 +00:00
Nobuyoshi Nakada 13e968c1cd [ruby/irb] Suppress sequence to inspect asian ambiguous width
https://github.com/ruby/irb/commit/a7097c5b80
2022-10-28 08:29:38 +00:00
Nobuyoshi Nakada 7440fc3eb4 [ruby/irb] Suppress "switching inspect mode" messages
https://github.com/ruby/irb/commit/565eeb3c19
2022-10-28 08:29:37 +00:00
Peter Zhu ea5972572b [ruby/irb] Fix warnings in test_cmd.rb
Fixes this warning:

    warning: assigned but unused variable - err

https://github.com/ruby/irb/commit/298fcb57a3
2022-10-27 15:29:52 -04:00
Stan Lo b260c1e8c8 [ruby/irb] Remove unnecessary test setup 2022-10-27 15:29:11 -04:00
Benoit Daloze bb7067cbdf [ruby/irb] Suppress warning for test which uses a locale non-existing on GitHub Actions 2022-10-27 19:16:52 +00:00
Benoit Daloze 8d7844235c [ruby/irb] Remove unecesary and harmful pend for TruffleRuby in TestRaiseNoBacktraceException
* Specifically the second one causes `$HOME` to be unset, which breaks `File.expand_path('~')`.

https://github.com/ruby/irb/commit/61963305f5
2022-10-27 19:16:51 +00:00
Stan Lo 7cf7e6c332 [ruby/irb] Add missing require 2022-10-27 15:36:18 +00:00
st0012 26b913c88b [ruby/irb] Add test for IRB::InputCompletor::PerfectMatchedProc
This proc displays rdoc document when the input matches certain symbols
perfectly, like "String". It's commonly triggered with autocompletion
but only has 1 test case. So this commit increases its test coverage.

https://github.com/ruby/irb/commit/d85d719313
2022-10-27 15:25:39 +00:00
Stan Lo 0dc2e1a764 [ruby/irb] Remove unnecessary warning check on help command
It's not an intentional behavior of the command and it behaves
differently in different environments. So checking it actually brings
more problem than benefit.

https://github.com/ruby/irb/commit/b3203bc784
2022-10-26 15:15:30 +00:00
Peter Zhu 73a0223f95 [ruby/irb] Rename test_helper.rb to helper.rb
The name test_helper.rb conflicts with the test_helper.rb in JSON,
causing build failures. This commit renames test_helper.rb to helper.rb.

https://github.com/ruby/irb/commit/b6a92bf6b3

Co-Authored-By: Stan Lo <stan001212@gmail.com>
2022-10-26 15:13:44 +00:00
st0012 cb95d834cc [ruby/irb] Don't insert new methods to Test::Unit::TestCase
Ruby CI runs irb and other Ruby core/stdlib tests in the same process.
So adding irb-specific helper to Test::Unit::TestCase could potentially
pollute other components' tests and should be avoided.
2022-10-26 10:44:29 -04:00
Stan Lo 2022470a95 [ruby/irb] Suppress warnings
Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2022-10-26 10:44:26 -04:00
st0012 d889e810f3 [ruby/irb] Add test for the help command 2022-10-26 10:44:23 -04:00
st0012 40f8a781a3 [ruby/irb] Extract without_rdoc helper 2022-10-26 10:44:03 -04:00
Stan Lo 48339d5c5b [ruby/irb] Make sure Encoding's defaults are restored 2022-10-25 20:50:07 +00:00
Stan Lo abeef41c95 [ruby/irb] Restore standard input/output encodings after input method tests 2022-10-24 17:02:34 +00:00
st0012 5a86155249 [ruby/irb] Add a test case to cover rdoc unintalled scenario 2022-10-24 13:36:58 +00:00
st0012 d377cc4530 [ruby/irb] Add tests for RelineInputMethod 2022-10-24 13:36:56 +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

https://github.com/ruby/irb/commit/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
tomoya ishida 344e6c915f [ruby/irb] Fix code terminated check with heredoc and backtick (https://github.com/ruby/irb/pull/390)
* Fix backtick method def method call handled as backtick open

* Fix handling heredoc in check_string_literal

* Sort result of lexer.parse by pos in ruby<2.7. It's not sorted when the given code includes heredoc.

* Update lib/irb/ruby-lex.rb

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

* Update lib/irb/ruby-lex.rb

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

* Add check_string_literal test for heredoc code that does not end with newline

https://github.com/ruby/irb/commit/44bc712460

Co-authored-by: Stan Lo <stan001212@gmail.com>
2022-10-18 05:30:33 +00:00
st0012 1c83469fc6 [ruby/irb] Remove unnecessary coloring support check
https://github.com/ruby/irb/commit/ddd7dbe2c5
2022-10-17 21:14:50 +00:00
yui-knk 4bfdf6d06d Move `error` from top_stmts and top_stmt to stmt
By this change, syntax error is recovered smaller units.
In the case below, "DEFN :bar" is same level with "CLASS :Foo"
now.

```
module Z
  class Foo
    foo.
  end

  def bar
  end
end
```

[Feature #19013]
2022-10-08 17:59:11 +09:00
st0012 5b3079a8a5 [ruby/irb] Sort constant completion's candidates
https://github.com/ruby/irb/commit/ee9b33c817
2022-10-08 03:17:42 +09:00
st0012 7be5e9b971 [ruby/irb] Correct assert_equal's usage in completion tests
https://test-unit.github.io/test-unit/en/Test/Unit/Assertions.html#assert_equal-instance_method

https://github.com/ruby/irb/commit/00f90d40ad
2022-10-08 03:17:41 +09:00
st0012 afc1f4fba4 [ruby/irb] Add constant completion test
https://github.com/ruby/irb/commit/39f8fcb058
2022-10-08 03:17:40 +09:00
st0012 3e18bb916f [ruby/irb] Regroup completion tests
https://github.com/ruby/irb/commit/71631287c8
2022-10-08 03:17:39 +09:00
st0012 83a9b91522 [ruby/irb] Add tests for primitive types' method completion
https://github.com/ruby/irb/commit/2e12fac38e
2022-10-08 03:17:38 +09:00
Imir Kiyamov 83a6213f31 [ruby/irb] Fixed sort of variables in completion
https://github.com/ruby/irb/commit/5842888255
2022-10-05 19:22:13 +09:00
osyo-manga 7b88ffb34f [ruby/irb] Change to explicit method call in completion (https://github.com/ruby/irb/pull/369)
Ensure that methods are called even when local variables are defined.
see: https://github.com/ruby/irb/issues/368

https://github.com/ruby/irb/commit/c34d54b8bb
2022-10-03 06:55:53 +09:00
tompng 641310ce37 [ruby/irb] Fix ripper_lex_without_warning duplicated heredoc token
https://github.com/ruby/irb/commit/45b539af39
2022-10-01 04:17:15 +09:00
tompng 78cb638002 [ruby/irb] Update expected colorize result that were uncolored before
https://github.com/ruby/irb/commit/52446eb77f
2022-09-22 00:37:39 +09:00
tompng 9f68687879 [ruby/irb] Scan every single characters in IRB::Color.scan
https://github.com/ruby/irb/commit/d14e56a65d
2022-09-22 00:37:38 +09:00
Stan Lo c21f820b49 [ruby/irb] Fix completion tests
https://github.com/ruby/irb/commit/eb1691f636
2022-09-21 22:59:45 +09:00
st0012 6325fc8854 [ruby/irb] Handle non-String $LOAD_PATH values more carefully
In addition to String values, $LOAD_PATH can also take objects that
respond_to the `to_path` method, like Pathname objects. So `irb` should
be able to handle those objects too.

And if $LOAD_PATH contains objects that can't be converted into String,
`irb` should simply ignore it.

https://github.com/ruby/irb/commit/b2f562176b
2022-09-21 22:24:27 +09:00
Hiroshi SHIBATA c287deecb6 backup IRBRC environmental variable. It's used by test methods when it's defined. 2022-09-21 14:25:42 +09:00
Hiroshi SHIBATA d6e84d97fe Fix the missing locale error 2022-09-21 14:25:42 +09:00
Jeremy Evans b07db96744 [ruby/irb] Support --noscript option to not use first non-option argument as script
Also add --script option to turn the option back on.

Previously there wasn't a way to get an interactive IRB session
and access arguments provided on the command line.

Additionally, handle `-` as script as stdin. In Unix-like tools, `-`
means to take standard input instead of a file.  This doesn't
result in exactly the same output for:

```
echo 'p ARGV' > args.rb; irb args.rb a b c
```

and

```
echo 'p ARGV' | irb - a b c
```

Due to how irb handles whether stdin is a tty.

However, this change allows use of `-` as a argument, instead of
giving an unrecognized switch error. This required some small
changes to context.rb (to handle `-` as standard input) and
input-method.rb (to have FileInputMethod accept IO arguments in
addition to strings).

Implements [Feature #15371]

https://github.com/ruby/irb/commit/4192683ba2
2022-09-17 02:25:26 +09:00
Nobuyoshi Nakada 752ae81ed1 [ruby/irb] Refine assertion for failures
https://github.com/ruby/irb/commit/fd047512b3
2022-09-15 08:25:53 +09:00
Nobuyoshi Nakada ae2e8d364f [ruby/irb] `Dir.mktmpdir` creates a directory including the process ID
https://github.com/ruby/irb/commit/a15f68ffdb
2022-09-15 08:25:52 +09:00
Jeremy Evans 9299db49f5 [ruby/irb] Fix history file saving with concurrent irb sessions when history file doesn't exist
If history file didn't exist when irb was started, @loaded_history_mtime
would be nil.  However, if the history file didn't exist before, but it
exists when saving history, that means the history file was modified,
and we should handle it the same way as we handle the other case where
the history file was modified.

Fixes #388

https://github.com/ruby/irb/commit/8d277aafcb
2022-09-14 10:15:45 +09: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.

https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/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

https://github.com/ruby/irb/commit/7db93f9326
2022-06-26 15:23:33 +09:00
Nobuyoshi Nakada a2b3f2014c [ruby/irb] Require stringio to use StringIO
https://github.com/ruby/irb/commit/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.

https://github.com/ruby/irb/commit/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
https://github.com/ruby/irb/commit/de561cafeb
2021-12-21 15:50:32 +09:00
aycabta 7b0f2d618e [ruby/irb] Remove unnecessary space in regexp
https://github.com/ruby/irb/commit/c24a8e2483
2021-12-20 16:19:37 +09:00
aycabta b96ef7684c [ruby/irb] Add East Asian Ambiguous Width to irb_info command
https://github.com/ruby/irb/commit/4cade4b7e5
2021-12-20 16:19:36 +09:00
Kaíque Kandy Koga 6b64e78823 [ruby/irb] Examine indentation of in keyword when trying to type include
Use in_keyword_case_scope?

Return fast

https://github.com/ruby/irb/commit/8acc7f8dc7
2021-12-03 00:56:43 +09:00
schneems 2b22c93533 Compatibility with IRB
Instead of accessing the struct as an array, access it via methods. There are other places inside of this file already using this API (for example e0a5c3d2b7/lib/irb/ruby-lex.rb (L829-L830)).

This commit moves all struct array-ish calls to use their method calls instead. It is also ~1.23 faster accessing values via a method instead of as an array according to this microbenchmark:

```ruby
Elem = Struct.new(:pos, :event, :tok, :state, :message) do
  def initialize(pos, event, tok, state, message = nil)
    super(pos, event, tok, State.new(state), message)
  end

  # ...

  def to_a
    a = super
    a.pop unless a.empty?
    a
  end
end

class ElemClass
  attr_accessor :pos, :event, :tok, :state, :message

  def initialize(pos, event, tok, state, message = nil)
    @pos = pos
    @event = event
    @tok = tok
    @state = State.new(state)
    @message = message
  end

  def to_a
    if @message
      [@pos, @event, @tok, @state, @message]
    else
      [@pos, @event, @tok, @state]
    end
  end
end

# stub state class creation for now
class State; def initialize(val); end; end
```

```ruby
Benchmark.ips do |x|
  x.report("struct") { struct[1] }
  x.report("class ") { from_class.event }
  x.compare!
end; nil
```

```
Warming up --------------------------------------
              struct     1.624M i/100ms
              class      1.958M i/100ms
Calculating -------------------------------------
              struct     17.139M (± 2.6%) i/s -     86.077M in   5.025801s
              class      21.104M (± 3.4%) i/s -    105.709M in   5.015193s

Comparison:
              class : 21103826.3 i/s
              struct: 17139201.5 i/s - 1.23x  (± 0.00) slower
```
2021-12-02 15:55:42 +09:00
Yusuke Endoh 56119c5245 Skip TestIRB::TestInit#test_recovery_sigint on Solaris
The test randomly gets stuck on Solaris:

http://rubyci.s3.amazonaws.com/solaris11-sunc/ruby-master/log/20211105T060014Z.fail.html.gz
```
  1) Error:
TestIRB::TestInit#test_recovery_sigint:
Timeout::Error: execution of assert_in_out_err expired timeout (100.0 sec)
pid 3195 killed by SIGTERM (signal 15)
| Switch to inspect mode.
| exit
|
```

I investigated the issue but I couldn't figure it out.
This random failure is noisy, which makes it difficult to track the CI.
So I skip the test on Soalris. Contribution is welcome.
2021-11-05 20:03:11 +09:00
Kaíque Kandy Koga 5c646ca0a0 [ruby/irb] Ignore parenthesis during completion
Rename method

https://github.com/ruby/irb/commit/619aecb412
2021-10-13 06:33:48 +09:00
aycabta 340fabca2c [ruby/irb] Set default return_format
https://github.com/ruby/irb/commit/7ee15bc668
2021-10-11 15:39:48 +09:00
Takashi Kokubun 82b87a8dc4 [ruby/irb] Clean up a duplicated definition
I simply forgot deleting it.

https://github.com/ruby/irb/commit/65399d5e9f
2021-10-11 15:25:05 +09:00
Takashi Kokubun 2e183c6273 [ruby/irb] trufflruby fails on the show_source test
https://github.com/ruby/irb/commit/460bd12b87
2021-10-10 23:23:48 -07:00
Takashi Kokubun b33caa5bbc [ruby/irb] Add a test of find_end for show_source command
https://github.com/ruby/irb/commit/68e6ca95a0
2021-10-10 23:23:47 -07:00
aycabta 1251edd1db [ruby/irb] Add tests for truncated show doc dialog
But pending them now because they need dummy document data to show doc.

https://github.com/ruby/irb/commit/ac471ee14e
2021-10-08 10:34:20 +09:00
aycabta 40a65030e5 Pend test_complete_require_library_name_first 2021-09-24 22:56:38 +09:00
Nobuyoshi Nakada ede95f541b [ruby/irb] Ignore any encoding errors while symbol completion
https://github.com/ruby/irb/commit/daa65cded1
2021-09-23 18:01:36 +09:00
Kaíque Kandy Koga 782d1d876b [ruby/irb] Use typed spaces when the line is inside the here documents
Use first method instead of square brackets to support 2.5 and 2.6 versions

Use tokens

Clear check_newline_depth_difference

https://github.com/ruby/irb/commit/6fec2a5d46
2021-09-22 23:26:41 +09:00
Nobuyoshi Nakada 4576cdca73 [ruby/irb] Fix argument order
https://github.com/ruby/irb/commit/05c65858a0
2021-09-21 23:28:02 +09:00
aycabta 3e038ab1c7 [ruby/irb] Ignore invalid 3 colons in completion
https://github.com/ruby/irb/commit/5e29e3e39c
2021-09-11 04:41:20 +09:00
Nobuyoshi Nakada 7983fb9658 [ruby/irb] Tests may not execute in the source directory
https://github.com/ruby/irb/commit/f4aaa70cfc
2021-09-10 08:34:51 +09:00
aycabta 62cecea073 Find irb command path in test 2021-09-10 07:43:01 +09:00
aycabta 7cc298a484 [ruby/irb] Pend on truffleruby
https://github.com/ruby/irb/commit/fbf52d9608
2021-09-10 06:37:07 +09:00
aycabta 3bd596efa4 [ruby/irb] Remove an unused variable
https://github.com/ruby/irb/commit/5bf1cb2078
2021-09-10 06:37:07 +09:00
Marc-Andre Lafortune 3503c94af5 [ruby/irb] Avoid loading files' local variables [Bug #17623]
https://github.com/ruby/irb/commit/b12f0cb8e2
2021-09-10 06:37:06 +09:00
aycabta d86c1a3161 [ruby/irb] Add yamatanooroti test for symbol with backtick
https://github.com/ruby/irb/commit/4d32f0e88e
2021-09-10 04:59:25 +09:00
aycabta f085a6fb69 [ruby/irb] Support symbol with backtick
https://github.com/ruby/irb/commit/0aa2425883
2021-09-10 04:59:17 +09:00
aycabta 580f340c33 [ruby/irb] Use "csv" for test
The "csv" doesn't conflict with other stdlib names in any Ruby processing
system.

https://github.com/ruby/irb/commit/49203a1c83
2021-09-08 05:24:04 +09:00
aycabta bc24af0f35 [ruby/irb] Show lib name first because it's the most common use case
https://github.com/ruby/irb/commit/74d635758b
2021-09-08 05:23:56 +09:00
aycabta ff372ed74b [ruby/irb] Suppress "assigned but unused variable" warning
https://github.com/ruby/irb/commit/a1ddf64c69
2021-09-04 17:48:31 +09:00
aycabta 9ac32e87bb [ruby/irb] Add an assertion to check completion "var.method" to get correct "class.method"
https://github.com/ruby/irb/commit/cc1ddb37a9
2021-09-04 17:48:26 +09:00
aycabta 6fa37d2666 [ruby/irb] Retrieve completed receiver that is a module or class correctly
https://github.com/ruby/irb/commit/b2324727e1
2021-09-04 17:48:20 +09:00
aycabta f6bc4b9b97 [ruby/irb] Use autocomplete with show doc dialog that uses Reline::Key in tests
https://github.com/ruby/irb/commit/142fc53e9c
2021-09-04 02:32:04 +09:00
aycabta 5458f23de2 [ruby/irb] Add TODO comment to remove disabling autocomplete later
https://github.com/ruby/irb/commit/856f001b60
2021-09-03 04:28:45 +09:00
aycabta 864b40176d [ruby/irb] Disable autocomplete in yamatanooroti test
https://github.com/ruby/irb/commit/cb9c9c64df
2021-09-03 04:28:38 +09:00
aycabta 4e40b7ddb0 [ruby/irb] Detect the variable class to show doc
https://github.com/ruby/irb/commit/33b9bec954
2021-09-02 21:39:55 +09:00
Nobuyoshi Nakada 66a4768f65 [ruby/irb] Relax backtrace nest levels
https://github.com/ruby/irb/commit/fb637bc68f
2021-08-30 13:16:46 +09:00
Hiroshi SHIBATA b17dc55017 [ruby/irb] Added the extra stdout message with test-unit
https://github.com/ruby/irb/commit/b153d587a1
2021-08-30 12:39:37 +09:00
Hiroshi SHIBATA f3ae14cbde [ruby/irb] Use capture_output instead of capture_io
https://github.com/ruby/irb/commit/077e4ae7de
2021-08-30 12:39:31 +09:00
Hiroshi SHIBATA 598f4f4219 [ruby/irb] Use pend instead of skip
https://github.com/ruby/irb/commit/f441ce35bf
2021-08-30 12:39:23 +09:00
aycabta ece4ed0da7 Add --autocomplete / --noautocomplete options 2021-08-30 02:45:13 +09:00
aycabta 3bbe860e50 [ruby/irb] Remove path settings for debugging
https://github.com/ruby/irb/commit/48029944a5
2021-08-30 02:33:29 +09:00
aycabta f1035248af [ruby/irb] Show code page by irb_info on Windows
https://github.com/ruby/irb/commit/6160d74199
2021-07-16 01:55:25 +09:00
aycabta 456d0019dd [ruby/irb] Escape space in free-spacing mode
https://github.com/ruby/irb/commit/085ac42947
2021-07-16 01:55:16 +09:00
aycabta 947d0198e0 [ruby/irb] Show LANG and LC_ALL env by irb_info
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>

https://github.com/ruby/irb/commit/b431742430
2021-07-11 06:12:07 +09:00
Masataka Pocke Kuwabara e8c2b03ee1 [ruby/irb] Fix error on `ls object_cant_define_singleton`
such as `ls 42`, `ls :sym` and so on

https://github.com/ruby/irb/commit/b1d436a853
2021-06-30 20:55:18 +09:00
Nobuyoshi Nakada 3b615f4353
Strip trailing spaces 2021-06-23 10:08:51 +09:00
Keiko Kaneko de779f4a62 [ruby/irb] Sort ls result ordered by anscestry
https://github.com/ruby/irb/commit/fdd5c0a71e
2021-06-22 22:32:42 +09:00
aycabta f57968e329 Set USE_COLORIZE to the default value in a test 2021-05-24 12:13:46 +09:00
jethrodaniel d06d4560a1 [ruby/irb] update test/irb/test_init.rb to avoid useless eval
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>

https://github.com/ruby/irb/commit/2dfdc031ec
2021-05-24 11:56:05 +09:00
Mark Delk b8ffb1c46f [ruby/irb] respect NO_COLOR environment variable
When `NO_COLOR` is set to any non-nil value, output is not colorized.

See https://no-color.org/

https://github.com/ruby/irb/commit/401d0916fe
2021-05-24 11:55:58 +09:00
Nobuyoshi Nakada 34bc8210ed
test/irb/test_raise_no_backtrace_exception.rb: fix test file path
Create a file for test under the temporary directory.
2021-05-18 16:04:37 +09:00