diff options
| author | Stan Lo <stan001212@gmail.com> | 2023-06-30 18:41:56 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2023-06-30 17:42:00 +0000 |
| commit | 136fcd5118b844bb8399d69dc44414cb3bd2028a (patch) | |
| tree | dd5fb9e08bf8d97423ad981e71f6ae8fc527f65a /test | |
| parent | 94788a6d13a136f28daca2a51ad7945c52b2311d (diff) | |
[ruby/irb] Reduce internal operations' exposure to benchmarking
(https://github.com/ruby/irb/pull/618)
* Test last value is assigned with measure enabled
* Remove unnecessary `result` variable
`Context#evaluate` always assigns the result of the evaluation to `_` so
we don't need to do it in `Irb#eval_input`.
* Move benchmarking logic into `Context#evaluate`
Current location of the benchmarking logic is too high up and includes
operations like command loading and argument transformation, which should
be excluded. So this commit moves it into `Context#evaluate` to reduce the
noise.
We don't move it further down to `Workspace#evaluate` because `Context`
is an argument of the measure block, which is not available in `Workspace`.
Diffstat (limited to 'test')
| -rw-r--r-- | test/irb/test_cmd.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb index c8c163c82d..71df60db14 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -252,6 +252,34 @@ module TestIRB assert_empty(c.class_variables) end + def test_measure_keeps_previous_value + conf = { + PROMPT: { + DEFAULT: { + PROMPT_I: '> ', + PROMPT_S: '> ', + PROMPT_C: '> ', + PROMPT_N: '> ' + } + }, + PROMPT_MODE: :DEFAULT, + MEASURE: false + } + + c = Class.new(Object) + out, err = execute_lines( + "measure\n", + "3\n", + "_\n", + conf: conf, + main: c + ) + + assert_empty err + assert_match(/\ATIME is added\.\n=> nil\nprocessing time: .+\n=> 3\nprocessing time: .+\n=> 3/, out) + assert_empty(c.class_variables) + end + def test_measure_enabled_by_rc conf = { PROMPT: { |
