rundoc 4.1.4 → 5.0.0

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +2 -1
  3. data/.standard.yml +1 -1
  4. data/CHANGELOG.md +7 -0
  5. data/README.md +36 -9
  6. data/lib/rundoc/cli.rb +4 -1
  7. data/lib/rundoc/code_command/background/log/clear.rb +12 -2
  8. data/lib/rundoc/code_command/background/log/read.rb +12 -2
  9. data/lib/rundoc/code_command/background/process_spawn.rb +3 -1
  10. data/lib/rundoc/code_command/background/start.rb +25 -6
  11. data/lib/rundoc/code_command/background/stdin_write.rb +21 -8
  12. data/lib/rundoc/code_command/background/stop.rb +12 -2
  13. data/lib/rundoc/code_command/background/wait.rb +15 -3
  14. data/lib/rundoc/code_command/background.rb +2 -0
  15. data/lib/rundoc/code_command/bash/cd.rb +7 -7
  16. data/lib/rundoc/code_command/bash.rb +43 -19
  17. data/lib/rundoc/code_command/comment.rb +33 -0
  18. data/lib/rundoc/code_command/deferred.rb +66 -0
  19. data/lib/rundoc/code_command/file_command/append.rb +29 -8
  20. data/lib/rundoc/code_command/file_command/remove.rb +27 -5
  21. data/lib/rundoc/code_command/no_such_command.rb +8 -3
  22. data/lib/rundoc/code_command/pipe.rb +36 -16
  23. data/lib/rundoc/code_command/pre/erb.rb +28 -18
  24. data/lib/rundoc/code_command/print/erb.rb +28 -4
  25. data/lib/rundoc/code_command/print/text.rb +27 -8
  26. data/lib/rundoc/code_command/raw.rb +17 -5
  27. data/lib/rundoc/code_command/rundoc/require.rb +25 -17
  28. data/lib/rundoc/code_command/rundoc_command.rb +21 -8
  29. data/lib/rundoc/code_command/website/driver.rb +2 -0
  30. data/lib/rundoc/code_command/website/navigate.rb +18 -12
  31. data/lib/rundoc/code_command/website/screenshot.rb +17 -11
  32. data/lib/rundoc/code_command/website/visit.rb +23 -12
  33. data/lib/rundoc/code_command/website.rb +2 -0
  34. data/lib/rundoc/code_command/write.rb +37 -9
  35. data/lib/rundoc/code_command.rb +5 -48
  36. data/lib/rundoc/context/after_build.rb +2 -0
  37. data/lib/rundoc/context/execution.rb +2 -0
  38. data/lib/rundoc/document.rb +6 -2
  39. data/lib/rundoc/fenced_code_block.rb +10 -7
  40. data/lib/rundoc/peg_parser.rb +17 -9
  41. data/lib/rundoc/version.rb +3 -1
  42. data/lib/rundoc.rb +52 -17
  43. data/rundoc.gemspec +2 -0
  44. data/test/rundoc/code_commands/append_file_test.rb +35 -10
  45. data/test/rundoc/code_commands/background_test.rb +24 -22
  46. data/test/rundoc/code_commands/bash_test.rb +10 -5
  47. data/test/rundoc/code_commands/comment_test.rb +116 -0
  48. data/test/rundoc/code_commands/pipe_test.rb +2 -2
  49. data/test/rundoc/code_commands/print_test.rb +13 -25
  50. data/test/rundoc/code_commands/remove_contents_test.rb +8 -3
  51. data/test/rundoc/code_section_test.rb +28 -21
  52. data/test/rundoc/peg_parser_test.rb +17 -1
  53. data/test/test_helper.rb +4 -2
  54. metadata +6 -6
  55. data/lib/rundoc/code_command/rundoc/depend_on.rb +0 -13
  56. data/test/fixtures/depend_on/dependency/rundoc.md +0 -5
  57. data/test/fixtures/depend_on/main/rundoc.md +0 -10
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rundoc
2
- class CodeCommand
4
+ module CodeCommand
3
5
  module FileUtil
4
6
  def filename
5
7
  files = Dir.glob(@filename)
@@ -15,16 +17,42 @@ module Rundoc
15
17
  end
16
18
  end
17
19
 
18
- class Write < Rundoc::CodeCommand
19
- include FileUtil
20
+ class WriteArgs
21
+ attr_reader :path
22
+
23
+ def initialize(path)
24
+ @path = Pathname(path)
25
+ end
26
+ end
27
+
28
+ class WriteRunner
29
+ NEWLINE = Object.new
30
+ def NEWLINE.to_s
31
+ ""
32
+ end
33
+
34
+ def NEWLINE.empty?
35
+ false
36
+ end
37
+
38
+ include Rundoc::CodeCommand::FileUtil
39
+
40
+ attr_reader :io, :contents
41
+
42
+ def initialize(user_args:, render_command:, render_result:, io:, contents: nil)
43
+ @filename = user_args.path.to_s
44
+ @io = io
45
+ @render_command = render_command
46
+ @contents = contents.dup if contents && !contents.empty?
47
+ end
20
48
 
21
- def initialize(filename)
22
- @filename = filename
49
+ def render_command?
50
+ @render_command
23
51
  end
24
52
 
25
53
  def to_md(env)
26
54
  if render_command?
27
- if env[:commands].any? { |c| c[:object].not_hidden? }
55
+ if env[:commands].any? { |c| c[:visibility].not_hidden? }
28
56
  raise "must call write in its own code section"
29
57
  end
30
58
  env[:before] << "In file `#{filename}` write:"
@@ -34,7 +62,7 @@ module Rundoc
34
62
  end
35
63
 
36
64
  def call(env = {})
37
- puts "Writing to: '#{filename}'"
65
+ io.puts "Writing to: '#{filename}'"
38
66
  mkdir_p
39
67
  File.write(filename, contents)
40
68
  contents
@@ -43,8 +71,8 @@ module Rundoc
43
71
  end
44
72
  end
45
73
 
46
- Rundoc.register_code_command(:write, Rundoc::CodeCommand::Write)
47
- Rundoc.register_code_command(:"file.write", Rundoc::CodeCommand::Write)
74
+ Rundoc.register_code_command(keyword: :write, args_klass: Rundoc::CodeCommand::WriteArgs, runner_klass: Rundoc::CodeCommand::WriteRunner)
75
+ Rundoc.register_code_command(keyword: :"file.write", args_klass: Rundoc::CodeCommand::WriteArgs, runner_klass: Rundoc::CodeCommand::WriteRunner)
48
76
 
49
77
  require "rundoc/code_command/file_command/append"
50
78
  require "rundoc/code_command/file_command/remove"
@@ -1,55 +1,11 @@
1
- module Rundoc
2
- # Generic CodeCommand class to be inherited
3
- #
4
- class CodeCommand
5
- # Newlines are stripped and re-added, this tells the project that
6
- # we're intentionally wanting an extra newline
7
- NEWLINE = Object.new
8
- def NEWLINE.to_s
9
- ""
10
- end
11
-
12
- def NEWLINE.empty?
13
- false
14
- end
15
-
16
- attr_accessor :render_result, :render_command,
17
- :command, :contents, :keyword,
18
- :original_args
19
-
20
- alias_method :render_result?, :render_result
21
- alias_method :render_command?, :render_command
22
-
23
- def initialize(*args)
24
- end
1
+ # frozen_string_literal: true
25
2
 
26
- def hidden?
27
- !render_command? && !render_result?
28
- end
29
-
30
- def not_hidden?
31
- !hidden?
32
- end
33
-
34
- def push(contents)
35
- @contents ||= ""
36
- @contents << contents
37
- end
38
- alias_method :<<, :push
39
-
40
- # Executes command to build project
41
- # Is expected to return the result of the command
42
- def call(env = {})
43
- raise "not implemented on #{inspect}"
44
- end
45
-
46
- # the output of the command, i.e. `$ cat foo.txt`
47
- def to_md(env = {})
48
- raise "not implemented on #{inspect}"
49
- end
3
+ module Rundoc
4
+ module CodeCommand
50
5
  end
51
6
  end
52
7
 
8
+ require "rundoc/code_command/deferred"
53
9
  require "rundoc/code_command/bash"
54
10
  require "rundoc/code_command/pipe"
55
11
  require "rundoc/code_command/write"
@@ -61,3 +17,4 @@ require "rundoc/code_command/website"
61
17
  require "rundoc/code_command/print/text"
62
18
  require "rundoc/code_command/print/erb"
63
19
  require "rundoc/code_command/pre/erb"
20
+ require "rundoc/code_command/comment"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rundoc
2
4
  module Context
3
5
  # Public interface for the `Rundoc.after_build` proc
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rundoc
2
4
  module Context
3
5
  # Holds configuration for the currently executing script
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rundoc
2
4
  # Represents a single rundoc file on disk,
3
5
  #
@@ -11,7 +13,8 @@ module Rundoc
11
13
 
12
14
  attr_reader :contents, :stack, :context
13
15
 
14
- def initialize(contents, context:)
16
+ def initialize(contents, context:, io: $stdout)
17
+ @io = io
15
18
  @context = context
16
19
  @contents = contents
17
20
  @original = contents.dup
@@ -59,7 +62,8 @@ module Rundoc
59
62
  fence: match[:fence],
60
63
  lang: match[:lang],
61
64
  code: match[:contents],
62
- context: context
65
+ context: context,
66
+ io: @io
63
67
  )
64
68
  end
65
69
  @contents = tail
@@ -15,7 +15,7 @@ module Rundoc
15
15
  def executed_commands
16
16
  raise "Nothing executed" unless @env[:commands].any?
17
17
 
18
- @env[:commands].map { |c| c[:object] }
18
+ @env[:commands].map { |c| c[:visibility] }
19
19
  end
20
20
 
21
21
  # @param fence [String] the fence used to start the code block like "```".
@@ -24,7 +24,8 @@ module Rundoc
24
24
  # @param code [String] the code block contents inside the fence.
25
25
  # @param context [Context::Execution] The details about where
26
26
  # the code block came from.
27
- def initialize(fence:, lang:, code:, context:)
27
+ def initialize(fence:, lang:, code:, context:, io: $stdout)
28
+ @io = io
28
29
  @fence = fence
29
30
  @lang = lang
30
31
  @code = code
@@ -54,12 +55,13 @@ module Rundoc
54
55
  env[:after] = []
55
56
  env[:context] = @context
56
57
  env[:stack] = @stack
58
+ while (item = @stack.pop)
59
+ code_command = item.build(io: @io)
57
60
 
58
- while (code_command = @stack.pop)
59
61
  code_output = code_command.call(env) || ""
60
62
  code_line = code_command.to_md(env) || ""
61
- result << code_line if code_command.render_command?
62
- result << code_output if code_command.render_result?
63
+ result << code_line if item.render_command?
64
+ result << code_output if item.render_result?
63
65
 
64
66
  PARTIAL_RESULT.replace(result)
65
67
  PARTIAL_ENV.replace(env)
@@ -67,11 +69,12 @@ module Rundoc
67
69
  env[:commands] << {
68
70
  object: code_command,
69
71
  output: code_output,
70
- command: code_line
72
+ command: code_line,
73
+ visibility: item
71
74
  }
72
75
  end
73
76
 
74
- if env[:commands].any? { |c| c[:object].not_hidden? }
77
+ if env[:commands].any? { |c| c[:visibility].not_hidden? }
75
78
  @rendered = self.class.to_doc(result: result, env: env)
76
79
  end
77
80
  self
@@ -1,9 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "parslet"
2
4
 
3
5
  module Rundoc
4
6
  class PegParser < Parslet::Parser
5
7
  rule(:spaces) { match('\s').repeat(1) }
6
8
  rule(:spaces?) { spaces.maybe }
9
+ rule(:horizontal_spaces) { match('[ \t]').repeat(1) }
7
10
  rule(:comma) { spaces? >> str(",") >> spaces? }
8
11
  rule(:digit) { match("[0-9]") }
9
12
  rule(:lparen) { str("(") >> spaces? }
@@ -87,7 +90,7 @@ module Rundoc
87
90
  }
88
91
 
89
92
  rule(:seattle_method) {
90
- funcall >> spaces >>
93
+ funcall >> horizontal_spaces >>
91
94
  args.as(:args)
92
95
  }
93
96
 
@@ -242,8 +245,8 @@ module Rundoc
242
245
  raise TransformError.new(message: message, line_and_column: line_and_column)
243
246
  end
244
247
  Visability.new(
245
- command: command.to_s == ">".freeze,
246
- result: result.to_s == ">".freeze
248
+ command: command.to_s == ">",
249
+ result: result.to_s == ">"
247
250
  )
248
251
  }
249
252
 
@@ -265,16 +268,21 @@ module Rundoc
265
268
  code_command
266
269
  }
267
270
 
268
- # The lines before a CodeCommand are rendered
269
- # without running any code
270
271
  rule(raw_code: simple(:raw_code)) {
271
- CodeCommand::Raw.new(raw_code)
272
+ deferred = CodeCommand::Deferred.new(args_instance: nil, runner_klass: CodeCommand::Raw)
273
+ deferred.render_command = false
274
+ deferred.render_result = true
275
+ deferred.push(raw_code.to_s)
276
+ deferred
272
277
  }
273
278
 
274
- # Sometimes
275
279
  rule(raw_code: sequence(:raw_code)) {
276
- hidden = raw_code.nil? || raw_code.empty?
277
- CodeCommand::Raw.new(raw_code, visible: !hidden)
280
+ visible = !raw_code.nil? && !raw_code.empty?
281
+ deferred = CodeCommand::Deferred.new(args_instance: nil, runner_klass: CodeCommand::Raw)
282
+ deferred.render_command = false
283
+ deferred.render_result = visible
284
+ deferred.push(raw_code.map(&:to_s).join)
285
+ deferred
278
286
  }
279
287
  end
280
288
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rundoc
2
- VERSION = "4.1.4"
4
+ VERSION = "5.0.0"
3
5
  end
data/lib/rundoc.rb CHANGED
@@ -5,43 +5,78 @@ require "rundoc/version"
5
5
  module Rundoc
6
6
  extend self
7
7
 
8
+ class UnknownCommand < StandardError; end
9
+
8
10
  def code_command_from_keyword(keyword, args)
9
- klass = code_command(keyword.to_sym) || Rundoc::CodeCommand::NoSuchCommand
10
- original_args = args.dup
11
- if args.is_a?(Array) && args.last.is_a?(Hash)
12
- kwargs = args.pop
13
- cc = klass.new(*args, **kwargs)
14
- elsif args.is_a?(Hash)
15
- cc = klass.new(**args)
11
+ args_klass = code_command(keyword.to_sym)
12
+ original_args = args&.dup
13
+
14
+ if args_klass
15
+ runner_klass = user_args_runner[keyword]
16
+
17
+ if args.is_a?(Array) && args.last.is_a?(Hash)
18
+ kwargs = args.pop
19
+ user_args = args_klass.new(*args, **kwargs)
20
+ elsif args.is_a?(Hash)
21
+ user_args = args_klass.new(**args)
22
+ else
23
+ user_args = args_klass.new(*args)
24
+ end
25
+ elsif keyword.start_with?("#")
26
+ args_klass = Rundoc::CodeCommand::CommentArgs
27
+ runner_klass = Rundoc::CodeCommand::CommentRunner
28
+ remainder = keyword.to_s.delete_prefix("#")
29
+ comment_text = [remainder, args].compact.join(" ").strip
30
+ user_args = args_klass.new(comment_text.empty? ? nil : comment_text)
16
31
  else
17
- cc = klass.new(*args)
32
+ runner_klass = Rundoc::CodeCommand::NoSuchCommand
33
+ user_args = nil
18
34
  end
19
35
 
20
- cc.original_args = original_args
21
- cc.keyword = keyword
22
- cc
36
+ deferred = CodeCommand::Deferred.new(
37
+ args_instance: user_args,
38
+ runner_klass: runner_klass,
39
+ always_hidden: always_hidden_commands[keyword] || keyword.start_with?("#")
40
+ )
41
+ deferred.original_args = original_args
42
+ deferred.keyword = keyword
43
+ deferred
23
44
  rescue ArgumentError => e
24
45
  raise ArgumentError, "Wrong method signature for #{keyword} with arguments: #{original_args.inspect}, error:\n #{e.message}"
25
46
  end
26
47
 
48
+ def user_code_runner_klass
49
+ @user_code_runner_klass ||= {}
50
+ end
51
+
27
52
  def parser_options
28
53
  @parser_options ||= {}
29
54
  end
30
55
 
31
- def code_lookup
32
- @code_lookup ||= {}
56
+ def user_args_runner
57
+ @user_args_runner ||= {}
58
+ end
59
+
60
+ def user_args
61
+ @user_args ||= {}
33
62
  end
34
63
 
35
64
  def code_command(keyword)
36
- code_lookup[:"#{keyword}"]
65
+ user_args[:"#{keyword}"]
37
66
  end
38
67
 
39
68
  def known_commands
40
- code_lookup.keys
69
+ user_args.keys
70
+ end
71
+
72
+ def register_code_command(keyword:, args_klass:, runner_klass:, always_hidden: false)
73
+ user_args[keyword] = args_klass
74
+ user_args_runner[keyword] = runner_klass
75
+ always_hidden_commands[keyword] = always_hidden
41
76
  end
42
77
 
43
- def register_code_command(keyword, klass)
44
- code_lookup[keyword] = klass
78
+ def always_hidden_commands
79
+ @always_hidden_commands ||= {}
45
80
  end
46
81
 
47
82
  def configure(&block)
data/rundoc.gemspec CHANGED
@@ -16,6 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
17
17
  gem.require_paths = ["lib"]
18
18
 
19
+ gem.required_ruby_version = ">= 3.2"
20
+
19
21
  gem.add_dependency "thor"
20
22
  gem.add_dependency "parslet", "~> 2"
21
23
  gem.add_dependency "capybara", "~> 3"
@@ -7,8 +7,13 @@ class AppendFileTest < Minitest::Test
7
7
  file = "foo.rb"
8
8
  `echo 'foo' >> #{file}`
9
9
 
10
- cc = Rundoc::CodeCommand::FileCommand::Append.new(file)
11
- cc << "bar"
10
+ cc = Rundoc::CodeCommand::FileCommand::AppendRunner.new(
11
+ render_command: false,
12
+ render_result: false,
13
+ io: StringIO.new,
14
+ user_args: Rundoc::CodeCommand::FileCommand::AppendArgs.new(file),
15
+ contents: "bar"
16
+ )
12
17
  cc.call
13
18
 
14
19
  result = File.read(file)
@@ -16,8 +21,13 @@ class AppendFileTest < Minitest::Test
16
21
  assert_match(/foo/, result)
17
22
  assert_match(/bar/, result)
18
23
 
19
- cc = Rundoc::CodeCommand::FileCommand::Append.new(file)
20
- cc << "baz"
24
+ cc = Rundoc::CodeCommand::FileCommand::AppendRunner.new(
25
+ render_command: false,
26
+ render_result: false,
27
+ io: StringIO.new,
28
+ user_args: Rundoc::CodeCommand::FileCommand::AppendArgs.new(file),
29
+ contents: "baz"
30
+ )
21
31
  cc.call
22
32
 
23
33
  actual = File.read(file)
@@ -39,8 +49,13 @@ class AppendFileTest < Minitest::Test
39
49
  line = 2
40
50
  `echo '#{contents}' >> #{file}`
41
51
 
42
- cc = Rundoc::CodeCommand::FileCommand::Append.new("#{file}##{line}")
43
- cc << "gem 'pg'"
52
+ cc = Rundoc::CodeCommand::FileCommand::AppendRunner.new(
53
+ render_command: false,
54
+ render_result: false,
55
+ io: StringIO.new,
56
+ user_args: Rundoc::CodeCommand::FileCommand::AppendArgs.new("#{file}##{line}"),
57
+ contents: "gem 'pg'"
58
+ )
44
59
  cc.call
45
60
 
46
61
  expected = "source https://rubygems.org\ngem 'pg'\ngem rails, 4.0.0\n\n"
@@ -54,8 +69,13 @@ class AppendFileTest < Minitest::Test
54
69
  Dir.chdir(dir) do
55
70
  filename = "file-#{Time.now.utc.strftime("%Y%m%d%H%M%S")}.txt"
56
71
  FileUtils.touch(filename)
57
- cc = Rundoc::CodeCommand::FileCommand::Append.new("file-*.txt")
58
- cc << "some text"
72
+ cc = Rundoc::CodeCommand::FileCommand::AppendRunner.new(
73
+ render_command: false,
74
+ render_result: false,
75
+ io: StringIO.new,
76
+ user_args: Rundoc::CodeCommand::FileCommand::AppendArgs.new("file-*.txt"),
77
+ contents: "some text"
78
+ )
59
79
  cc.call
60
80
 
61
81
  assert_equal "\nsome text\n", File.read(filename)
@@ -69,8 +89,13 @@ class AppendFileTest < Minitest::Test
69
89
  FileUtils.touch("file-1234.txt")
70
90
  FileUtils.touch("file-5678.txt")
71
91
  assert_raises do
72
- cc = Rundoc::CodeCommand::FileCommand::Append.new("file-*.txt")
73
- cc << "some text"
92
+ cc = Rundoc::CodeCommand::FileCommand::AppendRunner.new(
93
+ render_command: false,
94
+ render_result: false,
95
+ io: StringIO.new,
96
+ user_args: Rundoc::CodeCommand::FileCommand::AppendArgs.new("file-*.txt"),
97
+ contents: "some text"
98
+ )
74
99
  cc.call
75
100
  end
76
101
  end
@@ -6,33 +6,35 @@ class BackgroundTest < Minitest::Test
6
6
  Dir.chdir(dir) do
7
7
  # Intentionally out of order, should not raise an error as long as "cat"
8
8
  # command exists at execution time
9
- stdin_write = Rundoc::CodeCommand::Background::StdinWrite.new(
9
+ stdin_write = Rundoc::CodeCommand::Background::StdinWriteRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::Background::StdinWriteArgs.new(
10
10
  "hello there",
11
11
  name: "cat",
12
12
  wait: "hello"
13
- )
13
+ ))
14
14
 
15
- background_start = Rundoc::CodeCommand::Background::Start.new("cat",
16
- name: "cat")
15
+ background_start = Rundoc::CodeCommand::Background::StartRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::Background::StartArgs.new("cat",
16
+ name: "cat"))
17
17
 
18
18
  background_start.call
19
19
  output = stdin_write.call
20
20
  assert_equal("hello there" + $/, output)
21
21
 
22
- Rundoc::CodeCommand::Background::Wait.new(
23
- name: "cat",
24
- wait: "hello"
25
- ).call
22
+ Rundoc::CodeCommand::Background::WaitRunner.new(render_command: false, render_result: false, io: StringIO.new,
23
+ user_args: Rundoc::CodeCommand::Background::WaitArgs.new(
24
+ name: "cat",
25
+ wait: "hello"
26
+ )).call
26
27
 
27
- Rundoc::CodeCommand::Background::Log::Clear.new(
28
- name: "cat"
29
- ).call
28
+ Rundoc::CodeCommand::Background::Log::ClearRunner.new(render_command: false, render_result: false, io: StringIO.new,
29
+ user_args: Rundoc::CodeCommand::Background::Log::ClearArgs.new(
30
+ name: "cat"
31
+ )).call
30
32
 
31
- output = Rundoc::CodeCommand::Background::StdinWrite.new(
33
+ output = Rundoc::CodeCommand::Background::StdinWriteRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::Background::StdinWriteArgs.new(
32
34
  "general kenobi",
33
35
  name: "cat",
34
36
  wait: "general"
35
- ).call
37
+ )).call
36
38
  assert_equal("general kenobi" + $/, output)
37
39
  end
38
40
  end
@@ -44,9 +46,9 @@ class BackgroundTest < Minitest::Test
44
46
  file = "foo.txt"
45
47
  run!("echo 'foo' >> #{file}")
46
48
 
47
- background_start = Rundoc::CodeCommand::Background::Start.new("tail -f #{file}",
49
+ background_start = Rundoc::CodeCommand::Background::StartRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::Background::StartArgs.new("tail -f #{file}",
48
50
  name: "tail2",
49
- wait: "f")
51
+ wait: "f"))
50
52
 
51
53
  GC.start
52
54
 
@@ -55,7 +57,7 @@ class BackgroundTest < Minitest::Test
55
57
  assert_match("foo", output)
56
58
  assert_equal(true, background_start.alive?)
57
59
 
58
- background_stop = Rundoc::CodeCommand::Background::Stop.new(name: "tail2")
60
+ background_stop = Rundoc::CodeCommand::Background::StopRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::Background::StopArgs.new(name: "tail2"))
59
61
  background_stop.call
60
62
 
61
63
  assert_equal(false, background_start.alive?)
@@ -69,20 +71,20 @@ class BackgroundTest < Minitest::Test
69
71
  file = "foo.txt"
70
72
  run!("echo 'foo' >> #{file}")
71
73
 
72
- background_start = Rundoc::CodeCommand::Background::Start.new("tail -f #{file}",
74
+ background_start = Rundoc::CodeCommand::Background::StartRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::Background::StartArgs.new("tail -f #{file}",
73
75
  name: "tail",
74
- wait: "f")
76
+ wait: "f"))
75
77
  output = background_start.call
76
78
 
77
79
  assert_match("foo", output)
78
80
  assert_equal(true, background_start.alive?)
79
81
 
80
- log_read = Rundoc::CodeCommand::Background::Log::Read.new(name: "tail")
82
+ log_read = Rundoc::CodeCommand::Background::Log::ReadRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::Background::Log::ReadArgs.new(name: "tail"))
81
83
  output = log_read.call
82
84
 
83
85
  assert_equal("foo", output.chomp)
84
86
 
85
- log_clear = Rundoc::CodeCommand::Background::Log::Clear.new(name: "tail")
87
+ log_clear = Rundoc::CodeCommand::Background::Log::ClearRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::Background::Log::ClearArgs.new(name: "tail"))
86
88
  output = log_clear.call
87
89
  assert_equal("", output)
88
90
 
@@ -90,12 +92,12 @@ class BackgroundTest < Minitest::Test
90
92
 
91
93
  background_start.background.wait("bar")
92
94
 
93
- log_read = Rundoc::CodeCommand::Background::Log::Read.new(name: "tail")
95
+ log_read = Rundoc::CodeCommand::Background::Log::ReadRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::Background::Log::ReadArgs.new(name: "tail"))
94
96
  output = log_read.call
95
97
 
96
98
  assert_equal("bar", output.chomp)
97
99
 
98
- background_stop = Rundoc::CodeCommand::Background::Stop.new(name: "tail")
100
+ background_stop = Rundoc::CodeCommand::Background::StopRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::Background::StopArgs.new(name: "tail"))
99
101
  background_stop.call
100
102
 
101
103
  assert_equal(false, background_start.alive?)
@@ -3,7 +3,7 @@ require "test_helper"
3
3
  class BashTest < Minitest::Test
4
4
  def test_bash_returns_cd
5
5
  original_dir = `pwd`
6
- Rundoc::CodeCommand::Bash.new("cd ..").call
6
+ Rundoc::CodeCommand::BashRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::BashArgs.new("cd ..")).call
7
7
  now_dir = `pwd`
8
8
  refute_equal original_dir, now_dir
9
9
  ensure
@@ -12,14 +12,14 @@ class BashTest < Minitest::Test
12
12
 
13
13
  def test_bash_stderr_with_or_is_capture
14
14
  command = "1>&2 echo 'msg to STDERR 1' || 1>&2 echo 'msg to STDERR 2'"
15
- bash = Rundoc::CodeCommand::Bash.new(command)
15
+ bash = Rundoc::CodeCommand::BashRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::BashArgs.new(command))
16
16
  assert_equal "$ #{command}", bash.to_md
17
17
  assert_equal "msg to STDERR 1\n", bash.call
18
18
  end
19
19
 
20
20
  def test_bash_shells_and_shows_correctly
21
21
  ["pwd", "ls"].each do |command|
22
- bash = Rundoc::CodeCommand::Bash.new(command)
22
+ bash = Rundoc::CodeCommand::BashRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::BashArgs.new(command))
23
23
  assert_equal "$ #{command}", bash.to_md
24
24
  assert_equal `#{command}`, bash.call
25
25
  end
@@ -27,8 +27,13 @@ class BashTest < Minitest::Test
27
27
 
28
28
  def test_stdin
29
29
  command = "tail -n 2"
30
- bash = Rundoc::CodeCommand::Bash.new(command)
31
- bash << "foo\nbar\nbaz\n"
30
+ bash = Rundoc::CodeCommand::BashRunner.new(
31
+ render_command: false,
32
+ render_result: false,
33
+ io: StringIO.new,
34
+ user_args: Rundoc::CodeCommand::BashArgs.new(command),
35
+ contents: "foo\nbar\nbaz\n"
36
+ )
32
37
  assert_equal "bar\nbaz\n", bash.call
33
38
  end
34
39
  end