pry--pry/test
Kyrylo Silin 704cc6e859 Store `hist --replay <i>` calls in history
Fix issue #484 (hist --replay N isn't stored in history).

First, make some small amendments to existing code:

  * Make helper methods of "hist" command private;

  * What an irony! Amend the name of the duplicated test in
    `test_input.rb` ("should not contain duplicated lines" test).

Secondly, resolve the issue. There is one notable moment in current
implementation. Although `hist --replay` calls are being stored in
history, you cannot "replay" entries of this kind (you cannot replay
another call request to replay). Let me show an example:

  [1] pry(main)> hist --show 46894
  46894: hist --replay 46675..46677
  [2] pry(main)> hist --show 46675..46677
  46675: 1+1
  46676: a = 100
  46677: hist --tail
  [3] pry(main)> hist --replay 46894
  Error: Replay index 46894 points out to another replay call: `hist -r 46675..46677`
  [4] pry(main)>

There are two reasons for that.

Reason one or my incompetence
-----------------------------

First of all, I simply failed to implement such behaviour. With current
state of things (that are introduced in this commit), if you do not
raise `Pry::CommandError`, you cannot guarantee that only user's input
is getting stored in history. Here's an example when we get unwanted
entry in history:

  [1] pry(main)> hist --show 46894
  46894: hist --replay 46675..46677
  [2] pry(main)> hist --show 46675..46677
  46675: 1+1
  46676: a = 100
  46677: hist --tail 4
  [3] pry(main)> hist --replay 46894
  => 2
  => 100
  47021: hist --show 46894
  47022: hist --show 46675..46677
  47023: hist --replay 46894
  47024: hist --replay 46675..46677
  [8] pry(main)>

Note that a user typed only `hist --replay 46894`. But the last saved
entry in history is the entry to which user's input, actually, pointed
out (`hist --replay 46675..46677`). So if you press up-arrow key, you
will get not what you expected.

Reason two or "Whoa, whoa, boy! There is a real reason"
-------------------------------------------------------

But the main reason is that you can fall into a loop trap, when both
"hist --replay" calls point to each other. Example of a loop trap:

  [31] pry(main)> hist --tail 4
  47027: hist --tail
  47028: hist --replay 47028
  47029: hist --tail
  47030: hist --replay 47032
  [32] pry(main)> hist -r 47030
  # We've just fallen into a loop trap. Let's break out of it.
  ^C
  [416] pry(main)> hist --tail 5
  47409: hist --replay 47032
  47410: hist --replay 47030
  47411: hist --replay 47032
  47412: hist --replay 47030
  47413: hist --replay 47032
  [417] pry(main)>

Note the number of current line (417).

Finally, add some unit tests for this commit.

Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
2012-08-23 02:27:02 +03:00
..
test_default_commands Store `hist --replay <i>` calls in history 2012-08-23 02:27:02 +03:00
candidate_helper1.rb added tests for module candidate API 2012-06-23 20:14:10 +12:00
candidate_helper2.rb added tests for module candidate API 2012-06-23 20:14:10 +12:00
example_nesting.rb Add Module.nesting extraction to Pry::Indent 2012-07-28 14:31:20 -07:00
helper.rb Don't load ./.pryrc when it is ~/.pryrc [Fixes #682] 2012-08-05 12:05:35 -07:00
test_cli.rb updated cli.rb for new API and added tests for cli 2011-12-11 04:13:42 +13:00
test_code.rb Remember the initial pwd [Fixes #675] 2012-08-12 22:58:40 -07:00
test_command.rb Bond completion includes commands 2012-08-20 23:57:51 -07:00
test_command_helpers.rb update commands and tests to use Pry::Method 2011-09-22 01:20:32 -07:00
test_command_integration.rb Move all commands into individual files 2012-08-11 17:33:37 -07:00
test_command_set.rb Bond completion includes commands 2012-08-20 23:57:51 -07:00
test_completion.rb Add Bond completion (when available) cirwin++ 2012-08-18 22:49:20 +00:00
test_control_d_handler.rb Add unit tests for DEFAULT_CONTROL_D_HANDLER 2012-06-17 11:25:33 +12:00
test_exception_whitelist.rb Tidy up tests and remove some repeating code 2012-06-11 19:33:04 +02:00
test_history_array.rb Test that HistAry keeps correct number of entries 2012-08-21 00:24:57 +03:00
test_hooks.rb passing extra prompt data via an OpenStruct 2012-07-13 02:53:19 +12:00
test_indent.rb Add Module.nesting extraction to Pry::Indent 2012-07-28 14:31:20 -07:00
test_input_stack.rb Tidy up tests and remove some repeating code 2012-06-11 19:33:04 +02:00
test_method.rb Fix show-source and show-doc on __binding__/__binding_impl__ 2012-06-10 23:42:14 -07:00
test_prompt.rb passing extra prompt data via an OpenStruct 2012-07-13 02:53:19 +12:00
test_pry.rb Don't load ./.pryrc when it is ~/.pryrc [Fixes #682] 2012-08-05 12:05:35 -07:00
test_pry_defaults.rb Eliminate test failure 2012-06-26 22:34:13 -07:00
test_pry_history.rb clean up history tests a bit 2011-12-01 21:26:22 -08:00
test_pry_output.rb loosened test in test_pry_output.rb 2011-09-22 02:51:14 +12:00
test_sticky_locals.rb added Pry.config.extra_sticky_locals config option 2012-03-14 15:35:24 +13:00
test_syntax_checking.rb Don't rstrip strings [Fixes #657] 2012-07-18 09:27:43 -07:00
test_wrapped_module.rb more tightly spec WrappedModule, and ensure WM#source_location doesn't raise 2012-06-25 04:04:43 +12:00
testrc
testrcbad Be robust to errors in ~/.pryrc 2011-11-02 00:46:38 -07:00