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

581 Коммитов

Автор SHA1 Сообщение Дата
Stan Lo e973f9cbb3 [ruby/irb] Clarify that the context is IRB context
(https://github.com/ruby/irb/pull/950)

https://github.com/ruby/irb/commit/8cde57f55a
2024-05-05 10:44:52 +00:00
Stan Lo bd42f0898d [ruby/irb] Improve help message for no meta commands
(https://github.com/ruby/irb/pull/948)

* Remove unnecessary code from command tests

* Improve help message for no meta commands

1. Add placeholder values for both command category and description
2. Update help command's output to give different types of categories
   more explicit ordering

https://github.com/ruby/irb/commit/b1ef58aeff
2024-05-04 03:32:34 +00:00
Stan Lo fb2ea7084f [ruby/irb] Use flag instead of caller for `debug`'s binding.irb
check
(https://github.com/ruby/irb/pull/947)

https://github.com/ruby/irb/commit/4a4d7a4279
2024-05-04 03:22:17 +00:00
Kenichi Kamiya a510175e8f [ruby/irb] Avoid raising errors while running help for custom
commands
(https://github.com/ruby/irb/pull/944)

* Avoid raising errors while running help for custom commands

Raising an error from the help command is not a pleasure for the
end user, even if the command does not define any attributes

* Update test/irb/command/test_custom_command.rb

---------

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

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-05-03 22:08:49 +00:00
Kenichi Kamiya 70db150fbc [ruby/irb] Fix typos in test/irb/command/test_custom_command.rb
(https://github.com/ruby/irb/pull/945)

https://github.com/ruby/irb/commit/f2b5fc192f
2024-05-03 21:34:34 +00:00
Stan Lo 945a99e81a Sync IRB 241e061 2024-05-02 14:33:30 -04:00
Stan Lo 1000c27db8 [ruby/irb] Support `IRB.conf[:BACKTRACE_FILTER]`
(https://github.com/ruby/irb/pull/917)

* Use 'irbtest-' instead if 'irb-' as prefix of test files.

Otherwise IRB would mis-recognize exceptions raised in test files as
exceptions raised in IRB itself.

* Support `IRB.conf[:BACKTRACE_FILTER]``

This config allows users to customize the backtrace of exceptions raised
and displayed in IRB sessions. This is useful for filtering out library
frames from the backtrace.

IRB expects the given value to response to `call` method and return
the filtered backtrace.

https://github.com/ruby/irb/commit/6f6e87d769
2024-05-01 14:23:09 +00:00
tomoya ishida 8fb430c1da [ruby/irb] Restore MAIN_CONTEXT correctly
(https://github.com/ruby/irb/pull/937)

https://github.com/ruby/irb/commit/c41f460a70
2024-04-30 10:29:38 +00:00
Stan Lo 148518baa0 [ruby/irb] Suppress command return values
(https://github.com/ruby/irb/pull/934)

Since commands can't be chained with methods, their return values are
not intended to be used. But if IRB keeps storing command return values
as the last value, and print them, users may rely on such implicit
behaviour.

So to avoid such confusion, this commit suppresses command's
return values. It also updates some commands that currently rely on
this implicit behaviour.

https://github.com/ruby/irb/commit/fa96bea76f
2024-04-26 17:52:12 +00:00
Stan Lo 25a8b76c76 [ruby/irb] Command registration should take both strings and symbols
as names
(https://github.com/ruby/irb/pull/932)

This will save users some heads scratching when they try to register a
command with a string name and found that it doesn't work.

I also rewrote converted custom command tests into integration tests to
make test setup/cleanup easier.

https://github.com/ruby/irb/commit/a91a212dbe
2024-04-26 12:12:31 +00:00
Stan Lo 4349c7909f [ruby/irb] Memoize helper method instances with Singleton module
(https://github.com/ruby/irb/pull/931)

Some helpers, like Rails console's `app`, requires memoization of the
helper's ivars. To support it IRB needs to memoize helper method instances
as well.

https://github.com/ruby/irb/commit/a96c7a6668
2024-04-24 18:32:55 +00:00
Stan Lo 9bba999be7 [ruby/irb] Revert "Memoize helper method instances with Singleton module"
This reverts commit https://github.com/ruby/irb/commit/169a9a2c3097.

https://github.com/ruby/irb/commit/221b0a4928
2024-04-24 16:01:23 +00:00
Stan Lo e5ca3d072f [ruby/irb] Memoize helper method instances with Singleton module
Some helpers, like Rails console's `app`, requires memoization of the
helper's ivars. To support it IRB needs to memoize helper method instances
as well.

https://github.com/ruby/irb/commit/169a9a2c30
2024-04-24 16:01:02 +00:00
Stan Lo e11237904c
Sync IRB f9347b1 (#10611) 2024-04-23 21:00:56 +00:00
Stan Lo f16c6ac4fd [ruby/irb] Stop using ExtendCommandBundle internally
(https://github.com/ruby/irb/pull/925)

This module was used to extend both commands and helpers when they're not
separated. Now that they are, and we have a Command module, we should move
command-related logic to the Command module and update related references.

This will make the code easier to understand and refactor in the future.

https://github.com/ruby/irb/commit/f74ec97236
2024-04-20 18:55:54 +00:00
tomoya ishida 125e1ed5f7 [ruby/irb] Remove exit command workaround, handle IRB_EXIT in
debug_readline
(https://github.com/ruby/irb/pull/923)

* Remove exit and exti! command workaround when executed outside of IRB

Command was a method. It could be executed outside of IRB.
Workaround for it is no longer needed.

* Handle IRB_EXIT in debug mode

* Add exit and exit! command in rdbg mode

https://github.com/ruby/irb/commit/0b5dd6afd0
2024-04-20 07:45:41 +00:00
Kuniaki Igarashi 6cfd929034 [ruby/irb] Add MultiIRB commands test
(https://github.com/ruby/irb/pull/929)

https://github.com/ruby/irb/commit/c6bbc424c3
2024-04-19 15:01:36 +00:00
tomoya ishida ff599aea7c [ruby/irb] Fix % escape in prompt format
(https://github.com/ruby/irb/pull/927)

https://github.com/ruby/irb/commit/08eee25d28
2024-04-18 14:46:55 +00:00
tomoya ishida 57a262e325 [ruby/irb] Accept " " for colorizing "\t" test
(https://github.com/ruby/irb/pull/924)

https://github.com/ruby/irb/commit/c8182fa490
2024-04-18 11:48:13 +00:00
Stan Lo 04ba96e619 [ruby/irb] Allow defining custom commands in IRB
(https://github.com/ruby/irb/pull/886)

This is a feature that has been requested for a long time. It is now
possible to define custom commands in IRB.

Example usage:

```ruby
require "irb/command"

class HelloCommand < IRB::Command::Base
  description "Prints hello world"
  category "My commands"
  help_message "It doesn't do more than printing hello world."

  def execute
    puts "Hello world"
  end
end

IRB::Command.register(:hello, HelloCommand)
```

https://github.com/ruby/irb/commit/888643467c
2024-04-14 11:01:43 +00:00
Stan Lo f1d9e895b9 [ruby/irb] Pass statements to Context#evaluate
(https://github.com/ruby/irb/pull/920)

This has a few benefits:

- We can keep hiding the evaluation logic inside the Context level, which
  has always been the convention until #824 was merged recently.
- Although not an official API, gems like `debug` and `mission_control-jobs`
  patch `Context#evaluate` to wrap their own logic around it. This implicit
  contract was broken after #824, and this change restores it.

In addition to the refactor, I also converted some context-level evaluation
tests into integration tests, which are more robust and easier to maintain.

https://github.com/ruby/irb/commit/b32aee4068
2024-04-12 12:01:03 +00:00
tomoya ishida 6a505d1b59 [ruby/irb] Command implementation not by method
(https://github.com/ruby/irb/pull/824)

* Command is not a method

* Fix command test

* Implement non-method command name completion

* Add test for ExtendCommandBundle.def_extend_command

* Add helper method install test

* Remove spaces in command input parse

* Remove command arg unquote in help command

* Simplify Statement and handle execution in IRB::Irb

* Tweak require, const name

* Always install CommandBundle module to main object

* Remove considering local variable in command or expression check

* Remove unused method, tweak

* Remove outdated comment for help command arg

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

---------

https://github.com/ruby/irb/commit/8fb776e379

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-04-10 16:52:53 +00:00
tomoya ishida f53209f023 [ruby/irb] Cache RDoc::RI::Driver.new
(https://github.com/ruby/irb/pull/911)

* Cache RDoc::RI::Driver.new to improve performance and to avoid flaky test

* Insert sleep to fix flaky rendering test that renders document dialog

https://github.com/ruby/irb/commit/da84e6cb56
2024-03-25 11:48:11 +00:00
tomoya ishida 82f4cff1f3 [ruby/irb] Fix indent test for new reline
(https://github.com/ruby/irb/pull/908)

https://github.com/ruby/irb/commit/7c16ce033e
2024-03-24 12:54:40 +00:00
tomoya ishida bda5b09937 [ruby/irb] Fix irb_history saved to current directory
(https://github.com/ruby/irb/pull/901)

* Always save irb_history in HOME or XDG_CONFIG_HOME

Also split irbrc search logic from irb_history search logic as a refactor

* Remove IRB.conf[:RC_NAME_GENERATOR] because it's not configurable

This conf is used to specify which irbrc to load. Need to configure before irbrc is loaded, so it's actually not configurable.
This conf is also used for history file search, but it is configurable by conf[:HISTORY_FILE].

* remove rc_file_test because it is tested with rc_files, remove useless test setup

* Make internal irbrc searching method private

https://github.com/ruby/irb/commit/11d03a6ff7
2024-03-16 15:20:03 +00:00
Nobuyoshi Nakada 0c2e976894 [ruby/irb] Clear temporary directories
(https://github.com/ruby/irb/pull/894)

https://github.com/ruby/irb/commit/dc0dd25a39
2024-03-06 08:28:16 +00:00
Stan Lo 97d32bb2fc [ruby/irb] Prevent `irb_history`'s creation during HistoryTest
(https://github.com/ruby/irb/pull/893)

Some cases of it currently create `~/.irb_history` files unintentionally
while others don't. This is caused by the varying levels of setup/cleanup between
them. This commit fixes the issue by wrapping every single test inside a
consistent test setup and teardown callbacks.

https://github.com/ruby/irb/commit/a2a3cbb0ef
2024-03-06 04:12:49 +00:00
Haroon Ahmed 8f6113a91e [ruby/irb] Add the ability to fetch and load multiple irb files.
(https://github.com/ruby/irb/pull/859)

This allows hierarchy when loading rc files for example both files below
are loaded;

project/.irbrc
~/.irbrc

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

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-03-05 16:07:45 +00:00
Peter Zhu 6da8f04e01 [ruby/irb] Escape closing square brackets in regexp
Fixes the following warning:

    test/irb/test_command.rb:546: warning: regular expression has ']' without escape

https://github.com/ruby/irb/commit/7efadc243b
2024-03-01 19:57:11 +00:00
Stan Lo 57ca5960ad [ruby/irb] Restructure workspace management
(https://github.com/ruby/irb/pull/888)

* Remove dead irb_level method

* Restructure workspace management

Currently, workspace is an attribute of IRB::Context in most use cases.
But when some workspace commands are used, like `pushws` or `popws`, a
workspace will be created and used along side with the original workspace
attribute.

This complexity is not necessary and will prevent us from expanding
multi-workspace support in the future.

So this commit introduces a @workspace_stack ivar to IRB::Context so IRB
can have a more natural way to manage workspaces.

* Fix pushws without args

* Always display workspace stack after related commands are used

https://github.com/ruby/irb/commit/61560b99b3
2024-03-01 15:51:29 +00:00
Nobuyoshi Nakada d9b61e228f
Omit a bizzarre test in IRB 2024-02-19 16:33:27 +09:00
Hiroshi SHIBATA 1dca87cf53
Load rubygems explicitly for tests of test/irb 2024-02-19 11:34:32 +09:00
Stan Lo 7e577e150a [ruby/irb] Fix `irb:rdbg` for ruby head
(https://github.com/ruby/irb/pull/876)

* Update binding.irb check for Ruby head

With https://github.com/ruby/ruby/pull/9605, backtrace in Ruby head
now has a new format. This commit updates the check for binding.irb
to work with Ruby head.

* Do not include a backtick in error messages and backtraces

[Feature #16495]

---------

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

Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
2024-02-19 11:01:30 +09:00
Stan Lo 9ec9910081 [ruby/irb] Update error message assertions for Ruby 3.4
(https://github.com/ruby/irb/pull/874)

https://github.com/ruby/ruby/pull/9605 changes both quotes and format for
exception messages. So we need to update the assertions in the tests.

https://github.com/ruby/irb/commit/9359d4b51d
2024-02-19 10:48:38 +09:00
Hiroshi SHIBATA 11a6bb8195
Revert 25d74b9527 at test/irb 2024-02-19 10:47:42 +09:00
Stan Lo 07c774e85c [ruby/irb] Revamp `help` command
(https://github.com/ruby/irb/pull/877)

* Make help command display help for individual commands

Usage: `help [command]`

If the command is not specified, it will display a list of all available commands.

If the command is specified, it will display the banner OR description of the command.

If the command is not found, it will display a message saying that the command is not found.

* Rename test/irb/cmd to test/irb/command

* Add banner to edit and ls commands

* Promote help command in the help message

1. Make `show_cmds` an alias of `help` so it's not displayed in the help message
2. Update description of the help command to reflect `help <command>` syntax

* Rename banner to help_message

https://github.com/ruby/irb/commit/43a2c99f3f
2024-02-18 18:21:08 +00:00
Stan Lo f5801e2bf4 [ruby/irb] Standardize command related names
(https://github.com/ruby/irb/pull/873)

* Replace ExtendCommand with Command and standardize command related names

1. Rename lib/irb/extend-command.rb to lib/irb/command.rb
2. Rename lib/irb/cmd/*.rb to lib/irb/command/*.rb
3. Rename test/irb/test_cmd.rb to test/irb/test_command.rb
4. Rename ExtendCommand to Command

* Alias ExtendCommand to Command and deprecate it

* Rename Command::Nop to Command::Base

* Not deprecate old constants just yet

* Add lib/irb/cmd/nop.rb back

https://github.com/ruby/irb/commit/462c1284af
2024-02-16 16:47:36 +00:00
Stan Lo b315826377 [ruby/irb] Support repeating debugger input by passing empty input
to it
(https://github.com/ruby/irb/pull/856)

* Test IRB's behaviour with empty input

* Handle empty input and pass it to debugger

Since `rdbg` accepts empty input to repeat the previous command, IRB
should take empty input in `irb:rdbg` sessions and pass them to the
debugger.

Currently, IRB simply ignores empty input and does nothing. This commit
creates `EmptyInput` to represent empty input so it can fit into the
current IRB's input processing flow in `Irb#eval_input`.

https://github.com/ruby/irb/commit/0e9db419be
2024-02-16 16:12:54 +00:00
Yusuke Endoh 9d1b000bd1 Show the method owner in backtraces
```
test.rb:1:in 'Object#toplevel_meth': unhandled exception
        from test.rb:4:in 'Foo.class_meth'
        from test.rb:6:in 'Foo#instance_meth'
        from test.rb:11:in 'singleton_meth'
        from test.rb:13:in '<main>'
```

[Feature #19117]
2024-02-15 19:11:58 +09:00
Yusuke Endoh 25d74b9527 Do not include a backtick in error messages and backtraces
[Feature #16495]
2024-02-15 18:42:31 +09:00
Stan Lo c84581f1d9 [ruby/irb] Repurpose the help command to display the help message
(https://github.com/ruby/irb/pull/872)

See #787 for more details.

https://github.com/ruby/irb/commit/d9192d92d0
2024-02-14 13:47:45 +00:00
tomoya ishida d0412599e0 [ruby/irb] Improve constant lookup in SourceFinder
(https://github.com/ruby/irb/pull/871)

https://github.com/ruby/irb/commit/87c279ccf2
2024-02-14 13:46:49 +00:00
Stan Lo 2f0f95235a [ruby/irb] Fix SourceFinder's constant evaluation issue
(https://github.com/ruby/irb/pull/869)

Currently, if the signature's constant part is not defined, a NameError
would be raised.

```
irb(main):001> show_source Foo
(eval):1:in `<top (required)>': uninitialized constant Foo (NameError)

Foo
^^^
        from (irb):1:in `<main>'
```

This commit fixes the issue and simplifies the `edit` command's implementation.

https://github.com/ruby/irb/commit/8c16e029d1
2024-02-13 13:36:32 +00:00
Stan Lo ec26786b1a [ruby/irb] Refactor eval_path and `SourceFinder::Source`
(https://github.com/ruby/irb/pull/870)

* Assign `@eval_path` through `irb_path=` method

This simplifies the original caching logic for the `eval_path` method
and makes it easier to understand.

* Refactor SourceFinder::Source

https://github.com/ruby/irb/commit/c63e4c4035
2024-02-13 13:33:36 +00:00
tomoya ishida 7af97dc71f [ruby/irb] Powerup show_source by enabling RubyVM.keep_script_lines
(https://github.com/ruby/irb/pull/862)

* Powerup show_source by enabling RubyVM.keep_script_lines

* Add file_content field to avoid reading file twice while show_source

* Change path passed to eval, don't change irb_path.

* Encapsulate source coloring logic and binary file check insode class Source

* Add edit command testcase when irb_path does not exist

* Memoize irb_path existence to reduce file existence check calculating eval_path

https://github.com/ruby/irb/commit/239683a937
2024-02-12 18:38:30 +00:00
tomoya ishida 06995eb45b [ruby/irb] Fix exit! command warning and method behavior
(https://github.com/ruby/irb/pull/868)

* Fix exit! command warning and method behavior

* Remove arg(0) from Kernel.exit and Kernel.exit!

https://github.com/ruby/irb/commit/372bc59bf5
2024-02-12 11:28:54 +00:00
Stan Lo 5c4657f883 [ruby/irb] Polish the exit! command and its tests
(https://github.com/ruby/irb/pull/867)

* Remove IRB.irb_exit! method

It's not necessary to introduce a new method just for the exit! command
at this moment.

* Rename ExitForcedAction to ForceExit

* Move force exit tests to a dedicated file

* Fix nested history saving with exit! command

Because we switched to use `Kernel#exit` instead of `exit!`, the outer
session's ensure block in `Irb#run` will be run, which will save the
history. This means the separate check to save history when force exiting
is no longer necessary.

* execute_lines helper should also capture IRB setup's output

This prevents setup warnings from being printed to test output
while allowing those output to be tested.

* Update readme

https://github.com/ruby/irb/commit/899d10ade1
2024-02-11 05:17:40 +00:00
Ignacio Chiazzo Cardarello 429eeb09f2 [ruby/irb] Introduce exit! command
(https://github.com/ruby/irb/pull/851)

* Added failing test for when writing history on exit

* Save history on exit

* Exit early when calling Kernel.exit

* use status 0 for kernel.exit

* Added test for nested sessions

* Update lib/irb.rb

---------

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

Co-authored-by: Stan Lo <stan001212@gmail.com>
2024-02-10 22:07:53 +00:00
Stan Lo 5f4245e74b [ruby/irb] Polish tracer integration and tests
(https://github.com/ruby/irb/pull/864)

* Remove useless ivar

* Simplify tracer test setup

* Treat tracer like a normal development dependency

* Only require ext/tracer when value is truthy

* Make tracer integration skip IRB traces

https://github.com/ruby/irb/commit/a97a4129a7
2024-02-07 14:59:10 +00:00
Nuno Silva 300dee1fe8 [ruby/irb] Fix usage of tracer gem and add tests
(https://github.com/ruby/irb/pull/857)

The new tests are skipped when ruby below 3.1, as it was a default gem on it, and in a version we do not support.

This also move definition of `use_tracer` to module Context instead of monkey patch.

https://github.com/ruby/irb/commit/08834fbd5f
2024-02-06 16:46:50 +00:00