-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--color | ||
--require spec_helper | ||
--format d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,77 @@ | ||
require './spec/spec_helper' | ||
require 'pty' | ||
require 'expect' | ||
|
||
describe "pry-timetravel commands" do | ||
describe "checkpoint" do | ||
it "forks a child" | ||
# pry_timetravel_cmd = "pry -f -e 'Pry.config.correct_indent=false;' --no-pager --no-history --noprompt -s timetravel" | ||
pry_timetravel_cmd = "TERM=dumb pry -f --no-color --no-pager --no-history --noprompt -s timetravel" | ||
|
||
def strip_ansi(str) | ||
str.gsub(/\e\[[0-9;]*[a-zA-Z]/, '') | ||
end | ||
|
||
def get_line(pry_read) | ||
# puts "ignore1: [#{strip_ansi(pry_read.gets.chomp)}]" | ||
# puts "ignore2: [#{strip_ansi(pry_read.gets.chomp)}]" | ||
result = pry_read.gets.chomp | ||
puts "result: [#{result}]" | ||
result | ||
result = pry_read.gets.chomp | ||
puts "result: [#{result}]" | ||
result | ||
# strip_ansi(pry_read.gets.chomp) | ||
# strip_ansi(result) | ||
end | ||
|
||
|
||
describe "pry-timetravel" do | ||
it "starts with no snapshots" do | ||
PTY.spawn(pry_timetravel_cmd) do |reader, writer| | ||
writer.puts("snap --list") | ||
found = reader.expect(/No snapshots/) | ||
expect(found).to be_truthy | ||
end | ||
end | ||
it "creates one snapshot" do | ||
PTY.spawn(pry_timetravel_cmd) do |reader, writer, cmd_pid| | ||
writer.puts("snap") | ||
writer.puts("snap --list") | ||
|
||
all1, pid1 = reader.expect(/^(\d+) <main> 1/) | ||
all2, pid2 = reader.expect(/^ (\d+) <main> 1 \*\*\*/) | ||
|
||
expect(pid1.to_i).to be > 0 | ||
expect(pid2.to_i).to be > 0 | ||
|
||
pid_list = `ps h -o pid,ppid -g #{cmd_pid}`.split(/\n/) | ||
expect(pid_list.count).to be == 4 | ||
end | ||
end | ||
describe "timetravel" do | ||
it "reinvokes the saved checkpoint and kills itself" | ||
it "Can time-travel to before a var existed" do | ||
PTY.spawn(pry_timetravel_cmd) do |reader, writer, cmd_pid| | ||
writer.puts("snap") | ||
writer.puts("x = 7") | ||
reader.expect(/^=> 7/,1) | ||
writer.puts("x") | ||
reader.expect(/^=> 7/,1) | ||
writer.puts("back") | ||
writer.puts("x") | ||
result = reader.expect(/^NameError: undefined local variable or method `x' for main:Object/,1) | ||
expect(result).to be_truthy | ||
end | ||
end | ||
# it "creates one snapshot" # it "forks a child" do | ||
# PTY.spawn(pry_timetravel_cmd) do |pry_read, pry_write, pid| | ||
# pry_write.puts "5+5" | ||
# expect(strip_ansi(pry_read.gets.chomp)).to eq("5+5") # input | ||
# expect(strip_ansi(pry_read.gets.chomp)).to eq("5+5") # echo | ||
# expect(strip_ansi(pry_read.gets.chomp)).to eq("5+5=> 10") | ||
# end | ||
# end | ||
# it "forks a child" do | ||
# ReplTester.start do | ||
# input '5+5' | ||
# output '10' | ||
# end | ||
# end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
require 'rspec' | ||
require 'rspec/autorun' | ||
require './lib/pry-timetravel' | ||
|
||
require 'pry/test/helper' | ||
#require 'pry/test/helper' | ||
|
||
require './lib/pry-timetravel' | ||
# in case the tests call reset_defaults, ensure we reset them to | ||
# amended (test friendly) values | ||
# class << Pry | ||
# alias_method :orig_reset_defaults, :reset_defaults | ||
# def reset_defaults | ||
# orig_reset_defaults | ||
|
||
# Pry.config.color = false | ||
# Pry.config.pager = false | ||
# Pry.config.should_load_rc = false | ||
# Pry.config.should_load_local_rc= false | ||
# Pry.config.should_load_plugins = false | ||
# Pry.config.history.should_load = false | ||
# Pry.config.history.should_save = false | ||
# Pry.config.correct_indent = false | ||
# Pry.config.hooks = Pry::Hooks.new | ||
# Pry.config.collision_warning = false | ||
# end | ||
# end | ||
# Pry.reset_defaults |