yap-shell 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -24
  3. data/Gemfile +1 -5
  4. data/LICENSE.txt +17 -18
  5. data/README.md +28 -14
  6. data/Rakefile +4 -1
  7. data/bin/yap +1 -3
  8. data/lib/.gitkeep +0 -0
  9. data/yap-shell.gemspec +12 -11
  10. metadata +19 -184
  11. data/.rspec +0 -2
  12. data/.travis.yml +0 -11
  13. data/DESIGN.md +0 -87
  14. data/Gemfile.travis +0 -8
  15. data/Gemfile.travis.lock +0 -104
  16. data/WISHLIST.md +0 -54
  17. data/bin/yap-dev +0 -45
  18. data/lib/tasks/gem.rake +0 -62
  19. data/lib/yap.rb +0 -52
  20. data/lib/yap/addon.rb +0 -24
  21. data/lib/yap/addon/base.rb +0 -52
  22. data/lib/yap/addon/export_as.rb +0 -12
  23. data/lib/yap/addon/loader.rb +0 -84
  24. data/lib/yap/addon/path.rb +0 -56
  25. data/lib/yap/addon/rc_file.rb +0 -21
  26. data/lib/yap/addon/reference.rb +0 -22
  27. data/lib/yap/cli.rb +0 -4
  28. data/lib/yap/cli/commands.rb +0 -6
  29. data/lib/yap/cli/commands/addon.rb +0 -14
  30. data/lib/yap/cli/commands/addon/disable.rb +0 -35
  31. data/lib/yap/cli/commands/addon/enable.rb +0 -35
  32. data/lib/yap/cli/commands/addon/list.rb +0 -37
  33. data/lib/yap/cli/commands/addon/search.rb +0 -99
  34. data/lib/yap/cli/commands/generate.rb +0 -13
  35. data/lib/yap/cli/commands/generate/addon.rb +0 -258
  36. data/lib/yap/cli/commands/generate/addonrb.template +0 -22
  37. data/lib/yap/cli/commands/generate/gemspec.template +0 -25
  38. data/lib/yap/cli/commands/generate/license.template +0 -21
  39. data/lib/yap/cli/commands/generate/rakefile.template +0 -6
  40. data/lib/yap/cli/commands/generate/readme.template +0 -40
  41. data/lib/yap/cli/options.rb +0 -162
  42. data/lib/yap/cli/options/addon.rb +0 -64
  43. data/lib/yap/cli/options/addon/disable.rb +0 -62
  44. data/lib/yap/cli/options/addon/enable.rb +0 -63
  45. data/lib/yap/cli/options/addon/list.rb +0 -65
  46. data/lib/yap/cli/options/addon/search.rb +0 -76
  47. data/lib/yap/cli/options/generate.rb +0 -59
  48. data/lib/yap/cli/options/generate/addon.rb +0 -63
  49. data/lib/yap/configuration.rb +0 -74
  50. data/lib/yap/gem_helper.rb +0 -195
  51. data/lib/yap/gem_tasks.rb +0 -6
  52. data/lib/yap/shell.rb +0 -116
  53. data/lib/yap/shell/aliases.rb +0 -58
  54. data/lib/yap/shell/builtins.rb +0 -18
  55. data/lib/yap/shell/builtins/alias.rb +0 -42
  56. data/lib/yap/shell/builtins/cd.rb +0 -57
  57. data/lib/yap/shell/builtins/env.rb +0 -11
  58. data/lib/yap/shell/commands.rb +0 -163
  59. data/lib/yap/shell/evaluation.rb +0 -439
  60. data/lib/yap/shell/evaluation/shell_expansions.rb +0 -99
  61. data/lib/yap/shell/event_emitter.rb +0 -18
  62. data/lib/yap/shell/execution.rb +0 -16
  63. data/lib/yap/shell/execution/builtin_command_execution.rb +0 -20
  64. data/lib/yap/shell/execution/command_execution.rb +0 -30
  65. data/lib/yap/shell/execution/context.rb +0 -128
  66. data/lib/yap/shell/execution/file_system_command_execution.rb +0 -137
  67. data/lib/yap/shell/execution/result.rb +0 -18
  68. data/lib/yap/shell/execution/ruby_command_execution.rb +0 -80
  69. data/lib/yap/shell/execution/shell_command_execution.rb +0 -30
  70. data/lib/yap/shell/prompt.rb +0 -21
  71. data/lib/yap/shell/repl.rb +0 -237
  72. data/lib/yap/shell/version.rb +0 -5
  73. data/lib/yap/world.rb +0 -286
  74. data/rcfiles/yaprc +0 -390
  75. data/scripts/4 +0 -8
  76. data/scripts/bg-vim +0 -4
  77. data/scripts/fail +0 -3
  78. data/scripts/letters +0 -8
  79. data/scripts/lots-of-output +0 -6
  80. data/scripts/pass +0 -3
  81. data/scripts/simulate-long-running +0 -4
  82. data/scripts/write-to-stderr.rb +0 -3
  83. data/scripts/write-to-stdout.rb +0 -3
  84. data/spec/features/addons/generating_an_addon_spec.rb +0 -55
  85. data/spec/features/addons/using_an_addon_spec.rb +0 -182
  86. data/spec/features/aliases_spec.rb +0 -78
  87. data/spec/features/environment_variables_spec.rb +0 -69
  88. data/spec/features/filesystem_commands_spec.rb +0 -61
  89. data/spec/features/first_time_spec.rb +0 -45
  90. data/spec/features/grouping_spec.rb +0 -81
  91. data/spec/features/line_editing_spec.rb +0 -174
  92. data/spec/features/range_spec.rb +0 -35
  93. data/spec/features/redirection_spec.rb +0 -234
  94. data/spec/features/repetition_spec.rb +0 -118
  95. data/spec/features/shell_expansions_spec.rb +0 -127
  96. data/spec/spec_helper.rb +0 -172
  97. data/spec/support/matchers/have_not_printed.rb +0 -30
  98. data/spec/support/matchers/have_printed.rb +0 -68
  99. data/spec/support/very_soon.rb +0 -9
  100. data/spec/support/yap_spec_dsl.rb +0 -258
  101. data/test.rb +0 -206
  102. data/update-rawline.sh +0 -6
@@ -1,127 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Shell expansions', type: :feature do
4
- describe 'aliases' do
5
- before do
6
- type 'alias foo="echo bar"'
7
- enter
8
- expect { output }.to have_printed('Setting alias foo')
9
- end
10
-
11
- it 'expands aliases found in command position' do
12
- type 'foo'
13
- enter
14
- expect { output }.to have_printed('bar')
15
- end
16
-
17
- it 'does not expand aliases found in argument position' do
18
- type 'echo foo'
19
- enter
20
- expect { output }.to have_printed('foo')
21
- expect { output }.to have_not_printed('bar')
22
- end
23
- end
24
-
25
- describe 'environment variable expansion' do
26
- it 'expands upper-case env vars with a preceding $' do
27
- type 'FOO=bar echo $FOO'
28
- enter
29
- expect { output }.to have_printed('bar')
30
- end
31
-
32
- it 'expands lower-case vars with a preceding $' do
33
- type 'foo=bar echo $foo'
34
- enter
35
- expect { output }.to have_printed('bar')
36
- end
37
-
38
- it 'is case sensitive' do
39
- type 'foo=bar echo $foo'
40
- enter
41
- expect { output }.to have_printed('bar')
42
-
43
- type 'echo $FOO'
44
- enter
45
- expect { output }.to have_printed('$FOO')
46
- end
47
-
48
- it 'does not expand escaped env vars' do
49
- type 'FOO=bar echo \\$FOO'
50
- enter
51
- expect { output }.to have_printed('$FOO')
52
- end
53
- end
54
-
55
- describe 'exit status for last command: $?' do
56
- it 'prints whatever the exit status of the last command was' do
57
- write_executable_script 'exit-with-status-code', <<-SCRIPT.strip_heredoc
58
- |#!/bin/sh
59
- |exit $1
60
- SCRIPT
61
-
62
- type './exit-with-status-code 0 ; echo $?'
63
- enter
64
- expect { output }.to have_printed('0')
65
-
66
- type './exit-with-status-code 1 ; echo $?'
67
- enter
68
- expect { output }.to have_printed('1')
69
-
70
- type './exit-with-status-code 99 ; echo $?'
71
- enter
72
- expect { output }.to have_printed('99')
73
- end
74
- end
75
-
76
- describe 'word expansions using curly braces' do
77
- it 'expands in command position' do
78
- type 'foo_{}'
79
- enter
80
- expect { error_output }.to have_printed('yap: command not found: foo_')
81
- end
82
-
83
- describe 'arguments' do
84
- it 'expands no words' do
85
- type 'echo foo_{}'
86
- enter
87
- expect { output }.to have_printed('foo_')
88
- end
89
-
90
- it 'expands single words' do
91
- type 'echo foo_{bar}'
92
- enter
93
- expect { output }.to have_printed('foo_bar')
94
- end
95
-
96
- it 'multiple words in comma-separated list' do
97
- type 'echo foo_{bar,bay,baz}'
98
- enter
99
- expect { output }.to have_printed('foo_bar foo_bay')
100
- end
101
-
102
- it 'expands environment variables' do
103
- type 'FOO=huzzah echo foo_{$FOO}'
104
- enter
105
- expect { output }.to have_printed('foo_huzzah')
106
- end
107
-
108
- it 'does not expand environment variables in double quotes' do
109
- type 'FOO=huzzah echo foo_{"$FOO"}'
110
- enter
111
- expect { output }.to have_printed('foo_{$FOO}')
112
- end
113
-
114
- it 'does not expand environment variables in single quotes' do
115
- type %|FOO=huzzah echo foo_{'$FOO'}|
116
- enter
117
- expect { output }.to have_printed('foo_{$FOO}')
118
- end
119
-
120
- it 'treats ~ as any a normal character, not home directory expansion' do
121
- type 'echo foo_{~}'
122
- enter
123
- expect { output }.to have_printed('foo_~')
124
- end
125
- end
126
- end
127
- end
@@ -1,172 +0,0 @@
1
- require 'ansi_string'
2
- require 'childprocess'
3
- require 'pry'
4
-
5
- Dir[File.dirname(__FILE__) + '/support/**/**/*.rb'].each do |file|
6
- require file
7
- end
8
-
9
- class String
10
- def strip_heredoc
11
- gsub(/^\s*\|/, '')
12
- end
13
- end
14
-
15
- # This file was generated by the `rspec --init` command. Conventionally, all
16
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
17
- # The generated `.rspec` file contains `--require spec_helper` which will cause
18
- # this file to always be loaded, without a need to explicitly require it in any
19
- # files.
20
- #
21
- # Given that it is always loaded, you are encouraged to keep this file as
22
- # light-weight as possible. Requiring heavyweight dependencies from this file
23
- # will add to the boot time of your test suite on EVERY test run, even for an
24
- # individual file that may not need all of that loaded. Instead, consider making
25
- # a separate helper file that requires the additional dependencies and performs
26
- # the additional setup, and require it from the spec files that actually need
27
- # it.
28
- #
29
- # The `.rspec` file also contains a few flags that are not defaults but that
30
- # users commonly want.
31
- #
32
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
33
- RSpec.configure do |config|
34
- config.include Yap::Spec::DSL
35
-
36
- config.before(:all, type: :feature) do
37
- ENV['HOME'] = tmp_dir.to_s
38
-
39
- mkdir tmp_dir
40
- Dir.chdir tmp_dir
41
-
42
- set_yap_command_line_arguments \
43
- '--no-history', '--no-addons', '--no-rcfiles', '--skip-first-time'
44
-
45
- turn_on_debug_log(debug: 'editor')
46
- initialize_shell
47
-
48
- if self.class.metadata[:repl] == false
49
- # no-op if the test specificaly says it doesn't use a repl
50
- # This is likely when we're expecting yap to print information
51
- # and exit immediately
52
- else
53
- type "cd #{tmp_dir}"
54
- enter
55
-
56
- type "pwd"
57
- enter
58
- expect { output }.to have_printed(File.expand_path(tmp_dir))
59
- end
60
- clear_all_output
61
- end
62
-
63
- config.after(:all, type: :feature) do
64
- shell.stop if shell
65
- end
66
-
67
- config.after(:each, type: :feature) do
68
- begin
69
- if self.class.metadata[:forks]
70
- # no-op because the example will cause yap to fork inside the child
71
- # childprocess and will break the IO pipes we know about in the test
72
- elsif self.class.metadata[:repl] == false
73
- # no-op if the test specificaly says it doesn't use a repl
74
- # This is likely when we're expecting yap to print information
75
- # and exit immediately
76
- else
77
- enter if typed_content_awaiting_enter?
78
-
79
- # Use yap to tell us when it's done doing whatever is was doing.
80
- # This ensures we don'try to clean up before yap is done!
81
- clear_all_output(console: true)
82
- type 'echo done with this test'
83
- enter
84
- expect { output }.to have_printed('done with this test')
85
- end
86
- ensure
87
- clear_all_output(console: false)
88
- Dir.chdir(tmp_dir) do
89
- # remove all files including hidden but not current directory and
90
- # parent directory
91
- FileUtils.rm_rf Dir.glob('{.,}*') - %w(. ..)
92
- end
93
- end
94
- end
95
-
96
- # rspec-expectations config goes here. You can use an alternate
97
- # assertion/expectation library such as wrong or the stdlib/minitest
98
- # assertions if you prefer.
99
- config.expect_with :rspec do |expectations|
100
- # This option will default to `true` in RSpec 4. It makes the `description`
101
- # and `failure_message` of custom matchers include text for helper methods
102
- # defined using `chain`, e.g.:
103
- # be_bigger_than(2).and_smaller_than(4).description
104
- # # => "be bigger than 2 and smaller than 4"
105
- # ...rather than:
106
- # # => "be bigger than 2"
107
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
108
- end
109
-
110
- # rspec-mocks config goes here. You can use an alternate test double
111
- # library (such as bogus or mocha) by changing the `mock_with` option here.
112
- config.mock_with :rspec do |mocks|
113
- # Prevents you from mocking or stubbing a method that does not exist on
114
- # a real object. This is generally recommended, and will default to
115
- # `true` in RSpec 4.
116
- mocks.verify_partial_doubles = true
117
- end
118
-
119
- # The settings below are suggested to provide a good initial experience
120
- # with RSpec, but feel free to customize to your heart's content.
121
- =begin
122
- # These two settings work together to allow you to limit a spec run
123
- # to individual examples or groups you care about by tagging them with
124
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
125
- # get run.
126
- config.filter_run :focus
127
- config.run_all_when_everything_filtered = true
128
-
129
- # Allows RSpec to persist some state between runs in order to support
130
- # the `--only-failures` and `--next-failure` CLI options. We recommend
131
- # you configure your source control system to ignore this file.
132
- config.example_status_persistence_file_path = "spec/examples.txt"
133
-
134
- # Limits the available syntax to the non-monkey patched syntax that is
135
- # recommended. For more details, see:
136
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
137
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
138
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
139
- config.disable_monkey_patching!
140
-
141
- # This setting enables warnings. It's recommended, but in some cases may
142
- # be too noisy due to issues in dependencies.
143
- config.warnings = true
144
-
145
- # Many RSpec users commonly either run the entire suite or an individual
146
- # file, and it's useful to allow more verbose output when running an
147
- # individual spec file.
148
- if config.files_to_run.one?
149
- # Use the documentation formatter for detailed output,
150
- # unless a formatter has already been configured
151
- # (e.g. via a command-line flag).
152
- config.default_formatter = 'doc'
153
- end
154
-
155
- # Print the 10 slowest examples and example groups at the
156
- # end of the spec run, to help surface which specs are running
157
- # particularly slow.
158
- config.profile_examples = 10
159
-
160
- # Run specs in random order to surface order dependencies. If you find an
161
- # order dependency and want to debug it, you can fix the order by providing
162
- # the seed, which is printed after each run.
163
- # --seed 1234
164
- config.order = :random
165
-
166
- # Seed global randomization in this process using the `--seed` CLI option.
167
- # Setting this allows you to use `--seed` to deterministically reproduce
168
- # test failures related to randomization by passing the same `--seed` value
169
- # as the one that triggered the failure.
170
- Kernel.srand config.seed
171
- =end
172
- end
@@ -1,30 +0,0 @@
1
- RSpec::Matchers.define :have_not_printed do |expected|
2
- output_seen_so_far = ""
3
-
4
- match do |block|
5
- regex = expected
6
- regex = /#{Regexp.escape(regex)}/m unless regex.is_a?(Regexp)
7
- begin
8
- very_soon do
9
- current_output = block.call
10
- output_seen_so_far << current_output
11
- current_output.length > 0
12
- end
13
- rescue Timeout::Error
14
- return true # we didn't see it, make the assumption we're good
15
- end
16
- !regex.match(output_seen_so_far)
17
- end
18
-
19
- failure_message do |actual|
20
- if expected.is_a?(Regexp)
21
- "expected that #{expected.inspect} would not match #{output_seen_so_far.inspect}"
22
- else
23
- "expected that #{expected.inspect} would not appear in #{output_seen_so_far.inspect}"
24
- end
25
- end
26
-
27
- def supports_block_expectations?
28
- true
29
- end
30
- end
@@ -1,68 +0,0 @@
1
- RSpec::Matchers.define :have_printed do |expected|
2
- output_seen_so_far = ""
3
-
4
- match do |block|
5
- begin
6
- regex = expected
7
- regex = /#{Regexp.escape(regex)}/m unless regex.is_a?(Regexp)
8
- very_soon do
9
- current_output = block.call
10
- output_seen_so_far << current_output
11
- regex.match(current_output)
12
- end
13
- true
14
- rescue Timeout::Error
15
- false
16
- end
17
- end
18
-
19
- failure_message do |actual|
20
- if expected.is_a?(Regexp)
21
- "expected that #{expected.inspect} would match #{output_seen_so_far.inspect}"
22
- else
23
- "expected that #{expected.inspect} would appear in #{output_seen_so_far.inspect}"
24
- end
25
- end
26
-
27
- def supports_block_expectations?
28
- true
29
- end
30
- end
31
-
32
-
33
- RSpec::Matchers.define :have_printed_lines do |expected|
34
- output_seen_so_far = ""
35
- current_line = nil
36
-
37
- match do |block|
38
- begin
39
- expected.lines.each do |line|
40
- current_line = line
41
- regex = /#{Regexp.escape(line)}/m
42
- very_soon do
43
- current_output = block.call
44
- output_seen_so_far = current_output
45
- regex.match(current_output)
46
- end
47
- end
48
- true
49
- rescue Timeout::Error
50
- false
51
- end
52
- end
53
-
54
- failure_message do |actual|
55
- if expected.is_a?(Regexp)
56
- "expected that #{current_line.inspect} would match #{output_seen_so_far.inspect}"
57
- else
58
- "expected that #{current_line.inspect} would appear in #{output_seen_so_far.inspect}"
59
- end
60
- end
61
-
62
- def supports_block_expectations?
63
- true
64
- end
65
- end
66
-
67
- RSpec::Matchers.alias_matcher :have_printed_line, :have_printed_lines
68
- RSpec::Matchers.alias_matcher :have_line, :have_printed_lines
@@ -1,9 +0,0 @@
1
- def very_soon(timeout: 5, &block)
2
- Timeout.timeout(timeout) do
3
- loop do
4
- result = block.call
5
- break result if result
6
- sleep 0.1
7
- end
8
- end
9
- end
@@ -1,258 +0,0 @@
1
- require 'fileutils'
2
- require 'pathname'
3
- require 'timeout'
4
- require 'ostruct'
5
-
6
- module Yap
7
- module Spec
8
- class OutputFile
9
- def initialize(filepath)
10
- @filepath = filepath
11
- end
12
-
13
- def clear
14
- `> #{@filepath}`
15
- end
16
-
17
- def read
18
- file = File.open(@filepath, 'rb')
19
- file.read.gsub(/\u0000/, '')
20
- end
21
- end
22
-
23
- class Shell
24
- def self.current
25
- @instance
26
- end
27
-
28
- def self.new(**kwargs)
29
- if @instance
30
- @instance.stop
31
- end
32
- @instance = allocate.tap do |instance|
33
- instance.send :initialize, **kwargs
34
- instance.start
35
- end
36
- end
37
-
38
- def initialize(dir:, args:, stdout:, stderr:)
39
- @childprocess = nil
40
- @dir = dir
41
- @args = args
42
- @stdout = stdout
43
- @stderr = stderr
44
- end
45
-
46
- def io
47
- @childprocess.io if @childprocess
48
- end
49
-
50
- def stop
51
- if @childprocess
52
- @childprocess.stop
53
- @childprocess.wait
54
- end
55
- end
56
-
57
- def start
58
- return @childprocess if @childprocess
59
- @childprocess = begin
60
- process = ChildProcess.build(
61
- 'ruby',
62
- @dir,
63
- *@args
64
- )
65
-
66
- process.io.stdout = @stdout
67
- process.io.stderr = @stderr
68
-
69
- # make stdin available, writable
70
- process.duplex = true
71
-
72
- process.cwd = Dir.pwd
73
- process.start
74
-
75
- # make sure clean-up child processes, hang if any fail
76
- # to stop
77
- at_exit do
78
- process.stop
79
- process.wait
80
- end
81
-
82
- process
83
- end
84
- end
85
- end
86
-
87
- module DSL
88
- def very_soon(timeout: self.timeout, &block)
89
- @wait_for_last_exception = nil
90
- begin
91
- Timeout.timeout(timeout) do
92
- begin
93
- block.call
94
- rescue RSpec::Expectations::ExpectationNotMetError => ex
95
- @wait_for_last_exception = ex
96
- sleep 0.1
97
- retry
98
- end
99
- end
100
- rescue Timeout::Error
101
- raise @wait_for_last_exception
102
- rescue Exception => ex
103
- raise ex
104
- end
105
- end
106
-
107
- def touch(path)
108
- FileUtils.touch path
109
- end
110
-
111
- def mkdir(path)
112
- mkdir_p path
113
- end
114
-
115
- def mkdir_p(path)
116
- unless File.expand_path(path.to_s).include?(tmp_dir.to_s)
117
- path = tmp_dir.join(path)
118
- end
119
- FileUtils.mkdir_p Pathname.new(path).expand_path
120
- end
121
-
122
- def chdir(path, &blk)
123
- Dir.chdir(path, &blk)
124
- end
125
-
126
- def rmdir(path)
127
- path = tmp_dir.join(path) unless path == tmp_dir
128
- FileUtils.rm_rf Pathname.new(path).expand_path
129
- end
130
-
131
- def write_file(filename, contents)
132
- filename = tmp_dir.join(filename) unless filename.to_s.include?(tmp_dir.to_s)
133
- file = File.new(filename, 'w+')
134
- file.write contents
135
- file.close
136
- end
137
-
138
- def write_executable_script(filename, contents)
139
- filename = tmp_dir.join(filename) unless filename.to_s.include?(tmp_dir.to_s)
140
- file = File.new(filename, 'w+')
141
- file.write contents
142
- file.chmod 0755
143
- file.close
144
- end
145
-
146
- def tmp_dir
147
- yap_dir.join('tmp/specroot').expand_path
148
- end
149
-
150
- def yap_dir
151
- Pathname.new File.dirname(__FILE__) + '/../../'
152
- end
153
-
154
- def turn_on_debug_log(file: '/tmp/yap-debug.log', debug: '*')
155
- ENV['TREEFELL_OUT'] = file
156
- ENV['DEBUG'] = debug
157
- end
158
-
159
- def set_yap_command_line_arguments(*args)
160
- @yap_command_line_arguments = args.flatten
161
- end
162
-
163
- def yap_command_line_arguments
164
- @yap_command_line_arguments
165
- end
166
-
167
- def initialize_shell
168
- Shell.new(
169
- dir: yap_dir.join('bin/yap-dev').to_s,
170
- args: yap_command_line_arguments,
171
- stdout: stdout,
172
- stderr: stderr
173
- )
174
- end
175
-
176
- def reinitialize_shell
177
- initialize_shell
178
- clear_all_output(console: false)
179
- end
180
-
181
- def shell
182
- Shell.current
183
- end
184
-
185
- def set_prompt(str)
186
- shell.io.stdin.print "!prompt = '#{str}'"
187
- enter
188
- end
189
-
190
- def typed_content_awaiting_enter?
191
- @typed_content_awaiting_enter
192
- end
193
-
194
- def type(str)
195
- @typed_content_awaiting_enter = true
196
- shell.io.stdin.print str
197
- end
198
-
199
- def enter
200
- @typed_content_awaiting_enter = false
201
- shell.io.stdin.print "\r"
202
- end
203
-
204
- def clear_all_output(console: true)
205
- if console
206
- type 'echo done'
207
- enter
208
- expect { output }.to have_printed_line('done')
209
- end
210
- output_file.clear
211
- error_output_file.clear
212
- end
213
-
214
- def output
215
- str = ANSIString.new output_file.read
216
- without_ansi_str = str.without_ansi.force_encoding(
217
- Encoding::ASCII_8BIT
218
- ).gsub(/(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]/n, '')
219
- end
220
-
221
- def error_output
222
- str = ANSIString.new error_output_file.read
223
- str.without_ansi.force_encoding(
224
- Encoding::ASCII_8BIT
225
- ).gsub(/(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]/n, '')
226
- end
227
-
228
- def output_file
229
- @output_file ||= OutputFile.new(stdout.path)
230
- end
231
-
232
- def error_output_file
233
- @error_output_file ||= OutputFile.new(stderr.path)
234
- end
235
-
236
- def stdout
237
- yap_dir
238
- @stdout ||= begin
239
- File.open yap_dir.join('stdout.log').expand_path, 'wb'
240
- end
241
- @stdout.sync = true
242
- @stdout
243
- end
244
-
245
- def stderr
246
- @stderr ||= begin
247
- File.open yap_dir.join('stderr.log').expand_path, 'wb'
248
- end
249
- @stderr.sync = true
250
- @stderr
251
- end
252
-
253
- def timeout
254
- @timeout ||= 2 # seconds
255
- end
256
- end
257
- end
258
- end