rundoc 4.1.3 → 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 (59) 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 +12 -0
  5. data/README.md +36 -9
  6. data/lib/rundoc/cli.rb +6 -3
  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 +9 -5
  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 +25 -7
  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 +26 -14
  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/integration/background_stdin_test.rb +65 -15
  45. data/test/integration/website_test.rb +19 -0
  46. data/test/rundoc/code_commands/append_file_test.rb +35 -10
  47. data/test/rundoc/code_commands/background_test.rb +26 -22
  48. data/test/rundoc/code_commands/bash_test.rb +10 -5
  49. data/test/rundoc/code_commands/comment_test.rb +116 -0
  50. data/test/rundoc/code_commands/pipe_test.rb +2 -2
  51. data/test/rundoc/code_commands/print_test.rb +13 -25
  52. data/test/rundoc/code_commands/remove_contents_test.rb +8 -3
  53. data/test/rundoc/code_section_test.rb +28 -21
  54. data/test/rundoc/peg_parser_test.rb +17 -1
  55. data/test/test_helper.rb +32 -2
  56. metadata +7 -10
  57. data/lib/rundoc/code_command/rundoc/depend_on.rb +0 -13
  58. data/test/fixtures/depend_on/dependency/rundoc.md +0 -5
  59. data/test/fixtures/depend_on/main/rundoc.md +0 -10
@@ -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,31 +71,33 @@ 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
 
89
91
  run!("echo 'bar' >> #{file}")
90
92
 
91
- log_read = Rundoc::CodeCommand::Background::Log::Read.new(name: "tail")
93
+ background_start.background.wait("bar")
94
+
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"))
92
96
  output = log_read.call
93
97
 
94
98
  assert_equal("bar", output.chomp)
95
99
 
96
- 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"))
97
101
  background_stop.call
98
102
 
99
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
@@ -0,0 +1,116 @@
1
+ require "test_helper"
2
+
3
+ class CommentTest < Minitest::Test
4
+ def test_comment_runner_call_returns_empty_string
5
+ io = StringIO.new
6
+ runner = Rundoc::CodeCommand::CommentRunner.new(
7
+ render_command: false,
8
+ render_result: false,
9
+ io: io,
10
+ user_args: Rundoc::CodeCommand::CommentArgs.new("$ cat hello")
11
+ )
12
+ assert_equal "", runner.call
13
+ assert_equal "", runner.to_md
14
+ assert_equal "Skipping command (commented out): # $ cat hello\n", io.string
15
+ end
16
+
17
+ def test_comment_with_contents
18
+ io = StringIO.new
19
+ runner = Rundoc::CodeCommand::CommentRunner.new(
20
+ render_command: false,
21
+ render_result: false,
22
+ io: io,
23
+ user_args: Rundoc::CodeCommand::CommentArgs.new("$ tail -n 2"),
24
+ contents: "foo\nbar\nbaz\n"
25
+ )
26
+ assert_equal "", runner.call
27
+ expected = <<~EOF
28
+ Skipping command (commented out): # $ tail -n 2
29
+ foo
30
+ bar
31
+ baz
32
+ EOF
33
+ assert_equal expected.strip, io.string.strip
34
+ end
35
+
36
+ def test_comment_is_noop_in_document
37
+ contents = <<~EOF
38
+ before
39
+
40
+ ```
41
+ :::>> # $ cat hello
42
+ ```
43
+
44
+ after
45
+ EOF
46
+
47
+ Dir.mktmpdir do |dir|
48
+ Dir.chdir(dir) do
49
+ parsed = parse_contents(contents)
50
+ actual = strip_autogen_warning(parsed.to_md)
51
+ assert_equal "before\n\n\nafter\n", actual
52
+ end
53
+ end
54
+ end
55
+
56
+ def test_smudged_comment
57
+ contents = <<~EOF
58
+ before
59
+
60
+ ```
61
+ :::>> #$ cat hello
62
+ ```
63
+
64
+ after
65
+ EOF
66
+
67
+ Dir.mktmpdir do |dir|
68
+ Dir.chdir(dir) do
69
+ parsed = parse_contents(contents)
70
+ actual = strip_autogen_warning(parsed.to_md)
71
+ assert_equal "before\n\n\nafter\n", actual
72
+ end
73
+ end
74
+ end
75
+
76
+ def test_bare_comment_is_noop
77
+ contents = <<~EOF
78
+ before
79
+
80
+ ```
81
+ :::>> #
82
+ ```
83
+
84
+ after
85
+ EOF
86
+
87
+ Dir.mktmpdir do |dir|
88
+ Dir.chdir(dir) do
89
+ parsed = parse_contents(contents)
90
+ actual = strip_autogen_warning(parsed.to_md)
91
+ assert_equal "before\n\n\nafter\n", actual
92
+ end
93
+ end
94
+ end
95
+
96
+ def test_comment_does_not_affect_other_commands
97
+ contents = <<~EOF
98
+ before
99
+
100
+ ```
101
+ :::>> # this is commented out
102
+ :::>> $ echo "hello"
103
+ ```
104
+
105
+ after
106
+ EOF
107
+
108
+ Dir.mktmpdir do |dir|
109
+ Dir.chdir(dir) do
110
+ parsed = parse_contents(contents)
111
+ actual = strip_autogen_warning(parsed.to_md)
112
+ assert_equal "before\n\n```\n$ echo \"hello\"\nhello\n```\n\nafter\n", actual
113
+ end
114
+ end
115
+ end
116
+ end
@@ -5,7 +5,7 @@ class PipeTest < Minitest::Test
5
5
  pipe_cmd = "tail -n 2"
6
6
  cmd = "ls"
7
7
  out = `#{cmd}`
8
- pipe = Rundoc::CodeCommand::Pipe.new(pipe_cmd)
8
+ pipe = Rundoc::CodeCommand::PipeRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::PipeArgs.new(pipe_cmd))
9
9
  actual = pipe.call(commands: [{command: cmd, output: out}])
10
10
 
11
11
  expected = `#{cmd} | #{pipe_cmd}`
@@ -16,7 +16,7 @@ class PipeTest < Minitest::Test
16
16
  pipe_cmd = "tail -n 2"
17
17
  cmd = "ls"
18
18
  out = `#{cmd}`
19
- pipe = Rundoc::CodeCommand::Pipe.new("$ #{pipe_cmd}")
19
+ pipe = Rundoc::CodeCommand::PipeRunner.new(render_command: false, render_result: false, io: StringIO.new, user_args: Rundoc::CodeCommand::PipeArgs.new("$ #{pipe_cmd}"))
20
20
  actual = pipe.call(commands: [{command: cmd, output: out}])
21
21
 
22
22
  expected = `#{cmd} | #{pipe_cmd}`
@@ -6,9 +6,7 @@ class PrintTest < Minitest::Test
6
6
  env[:before] = []
7
7
 
8
8
  input = %($ rails new myapp # Not a command since it's missing the ":::>>")
9
- cmd = Rundoc::CodeCommand::PrintText.new(input)
10
- cmd.render_command = false
11
- cmd.render_result = true
9
+ cmd = Rundoc::CodeCommand::PrintTextRunner.new(user_args: Rundoc::CodeCommand::PrintTextArgs.new(input), io: StringIO.new, render_command: false, render_result: true)
12
10
 
13
11
  assert_equal "", cmd.to_md(env)
14
12
  assert_equal "", cmd.call
@@ -20,9 +18,7 @@ class PrintTest < Minitest::Test
20
18
  env[:before] = []
21
19
 
22
20
  input = %($ rails new myapp # Not a command since it's missing the ":::>>")
23
- cmd = Rundoc::CodeCommand::PrintText.new(input)
24
- cmd.render_command = true
25
- cmd.render_result = true
21
+ cmd = Rundoc::CodeCommand::PrintTextRunner.new(user_args: Rundoc::CodeCommand::PrintTextArgs.new(input), io: StringIO.new, render_command: true, render_result: true)
26
22
 
27
23
  assert_equal "", cmd.to_md(env)
28
24
  assert_equal input, cmd.call
@@ -35,9 +31,7 @@ class PrintTest < Minitest::Test
35
31
  env[:before] = []
36
32
 
37
33
  input = %($ rails new <%= 'myapp' %> # Not a command since it's missing the ":::>>")
38
- cmd = Rundoc::CodeCommand::PrintERB.new(input)
39
- cmd.render_command = false
40
- cmd.render_result = true
34
+ cmd = Rundoc::CodeCommand::PrintERBRunner.new(user_args: Rundoc::CodeCommand::PrintERBArgs.new(input), io: StringIO.new, render_command: false, render_result: true)
41
35
 
42
36
  assert_equal "", cmd.to_md(env)
43
37
  assert_equal "", cmd.call
@@ -49,10 +43,7 @@ class PrintTest < Minitest::Test
49
43
  env = {}
50
44
  env[:before] = []
51
45
 
52
- cmd = Rundoc::CodeCommand::PrintERB.new
53
- cmd.contents = %(<%= "foo" %>)
54
- cmd.render_command = true
55
- cmd.render_result = true
46
+ cmd = Rundoc::CodeCommand::PrintERBRunner.new(user_args: Rundoc::CodeCommand::PrintERBArgs.new, io: StringIO.new, render_command: true, render_result: true, contents: %(<%= "foo" %>))
56
47
 
57
48
  assert_equal "", cmd.to_md(env)
58
49
  assert_equal "foo", cmd.call
@@ -62,10 +53,13 @@ class PrintTest < Minitest::Test
62
53
  def test_binding_is_preserved
63
54
  env = {}
64
55
  env[:before] = []
65
- cmd = Rundoc::CodeCommand::PrintERB.new
66
- cmd.contents = %{<%= @foo = SecureRandom.hex(16) %>}
67
- cmd.render_command = true
68
- cmd.render_result = true
56
+ cmd = Rundoc::CodeCommand::PrintERBRunner.new(
57
+ user_args: Rundoc::CodeCommand::PrintERBArgs.new,
58
+ io: StringIO.new,
59
+ contents: %{<%= @foo = SecureRandom.hex(16) %>},
60
+ render_command: true,
61
+ render_result: true
62
+ )
69
63
 
70
64
  assert_equal "", cmd.to_md(env)
71
65
  assert_equal [], env[:before]
@@ -73,19 +67,13 @@ class PrintTest < Minitest::Test
73
67
 
74
68
  assert !expected.empty?
75
69
 
76
- cmd = Rundoc::CodeCommand::PrintERB.new
77
- cmd.contents = %(<%= @foo %>)
78
- cmd.render_command = true
79
- cmd.render_result = true
70
+ cmd = Rundoc::CodeCommand::PrintERBRunner.new(user_args: Rundoc::CodeCommand::PrintERBArgs.new, io: StringIO.new, render_command: true, render_result: true, contents: %(<%= @foo %>))
80
71
 
81
72
  assert_equal "", cmd.to_md(env)
82
73
  assert_equal expected, cmd.call
83
74
  assert_equal [], env[:before]
84
75
 
85
- cmd = Rundoc::CodeCommand::PrintERB.new(binding: "different")
86
- cmd.contents = %(<%= @foo %>)
87
- cmd.render_command = true
88
- cmd.render_result = true
76
+ cmd = Rundoc::CodeCommand::PrintERBRunner.new(user_args: Rundoc::CodeCommand::PrintERBArgs.new(binding: "different"), io: StringIO.new, render_command: true, render_result: true, contents: %(<%= @foo %>))
89
77
 
90
78
  assert_equal "", cmd.to_md(env)
91
79
  assert_equal "", cmd.call
@@ -21,8 +21,13 @@ class RemoveContentsTest < Minitest::Test
21
21
 
22
22
  assert_match(/sqlite3/, File.read(@file))
23
23
 
24
- cc = Rundoc::CodeCommand::FileCommand::Remove.new(@file)
25
- cc << "gem 'sqlite3'"
24
+ cc = Rundoc::CodeCommand::FileCommand::RemoveRunner.new(
25
+ render_command: false,
26
+ render_result: false,
27
+ user_args: Rundoc::CodeCommand::FileCommand::RemoveArgs.new(@file),
28
+ contents: "gem 'sqlite3'",
29
+ io: StringIO.new
30
+ )
26
31
  cc.call
27
32
 
28
33
  refute_match(/sqlite3/, File.read(@file))
@@ -33,7 +38,7 @@ class RemoveContentsTest < Minitest::Test
33
38
  env[:fence_start] = "```ruby"
34
39
  cc.to_md(env)
35
40
 
36
- assert_equal ["In file `foo.rb` remove:", Rundoc::CodeCommand::NEWLINE], env[:before]
41
+ assert_equal ["In file `foo.rb` remove:", Rundoc::CodeCommand::FileCommand::RemoveRunner::NEWLINE], env[:before]
37
42
  end
38
43
  end
39
44
  end
@@ -19,7 +19,8 @@ class CodeSectionTest < Minitest::Test
19
19
  fence: match[:fence],
20
20
  lang: match[:lang],
21
21
  code: match[:contents],
22
- context: default_context
22
+ context: default_context,
23
+ io: StringIO.new
23
24
  ).render
24
25
  assert_equal "", result
25
26
  end
@@ -39,7 +40,8 @@ class CodeSectionTest < Minitest::Test
39
40
  fence: match[:fence],
40
41
  lang: match[:lang],
41
42
  code: match[:contents],
42
- context: default_context
43
+ context: default_context,
44
+ io: StringIO.new
43
45
  ).render
44
46
  assert_equal contents, result.gsub(Rundoc::FencedCodeBlock::AUTOGEN_WARNING, "\n")
45
47
  end
@@ -56,13 +58,14 @@ class CodeSectionTest < Minitest::Test
56
58
  fence: match[:fence],
57
59
  lang: match[:lang],
58
60
  code: match[:contents],
59
- context: default_context
61
+ context: default_context,
62
+ io: StringIO.new
60
63
  )
61
64
  code_section.render
62
65
 
63
66
  code_command = code_section.executed_commands.first
64
- assert_equal true, code_command.render_command
65
- assert_equal false, code_command.render_result
67
+ assert_equal true, code_command.render_command?
68
+ assert_equal false, code_command.render_result?
66
69
 
67
70
  contents = <<~RUBY
68
71
  ```
@@ -75,13 +78,14 @@ class CodeSectionTest < Minitest::Test
75
78
  fence: match[:fence],
76
79
  lang: match[:lang],
77
80
  code: match[:contents],
78
- context: default_context
81
+ context: default_context,
82
+ io: StringIO.new
79
83
  )
80
84
  code_section.render
81
85
 
82
86
  code_command = code_section.executed_commands.first
83
- assert_equal true, code_command.render_command
84
- assert_equal false, code_command.render_result
87
+ assert_equal true, code_command.render_command?
88
+ assert_equal false, code_command.render_result?
85
89
  end
86
90
 
87
91
  def test_show_command_show_render
@@ -96,14 +100,14 @@ class CodeSectionTest < Minitest::Test
96
100
  fence: match[:fence],
97
101
  lang: match[:lang],
98
102
  code: match[:contents],
99
- context: default_context
103
+ context: default_context,
104
+ io: StringIO.new
100
105
  )
101
106
  code_section.render
102
107
 
103
- puts code_section.executed_commands.inspect
104
108
  code_command = code_section.executed_commands.first
105
- assert_equal true, code_command.render_command
106
- assert_equal true, code_command.render_result
109
+ assert_equal true, code_command.render_command?
110
+ assert_equal true, code_command.render_result?
107
111
  end
108
112
 
109
113
  def test_hide_command_hide_render
@@ -118,13 +122,14 @@ class CodeSectionTest < Minitest::Test
118
122
  fence: match[:fence],
119
123
  lang: match[:lang],
120
124
  code: match[:contents],
121
- context: default_context
125
+ context: default_context,
126
+ io: StringIO.new
122
127
  )
123
128
  code_section.render
124
129
 
125
130
  code_command = code_section.executed_commands.first
126
- assert_equal false, code_command.render_command
127
- assert_equal false, code_command.render_result
131
+ assert_equal false, code_command.render_command?
132
+ assert_equal false, code_command.render_result?
128
133
 
129
134
  contents = <<~RUBY
130
135
  ```
@@ -137,13 +142,14 @@ class CodeSectionTest < Minitest::Test
137
142
  fence: match[:fence],
138
143
  lang: match[:lang],
139
144
  code: match[:contents],
140
- context: default_context
145
+ context: default_context,
146
+ io: StringIO.new
141
147
  )
142
148
  code_section.render
143
149
 
144
150
  code_command = code_section.executed_commands.first
145
- assert_equal false, code_command.render_command
146
- assert_equal false, code_command.render_result
151
+ assert_equal false, code_command.render_command?
152
+ assert_equal false, code_command.render_result?
147
153
  end
148
154
 
149
155
  def test_hide_command_show_render
@@ -158,12 +164,13 @@ class CodeSectionTest < Minitest::Test
158
164
  fence: match[:fence],
159
165
  lang: match[:lang],
160
166
  code: match[:contents],
161
- context: default_context
167
+ context: default_context,
168
+ io: StringIO.new
162
169
  )
163
170
  code_section.render
164
171
 
165
172
  code_command = code_section.executed_commands.first
166
- assert_equal false, code_command.render_command
167
- assert_equal true, code_command.render_result
173
+ assert_equal false, code_command.render_command?
174
+ assert_equal true, code_command.render_result?
168
175
  end
169
176
  end
@@ -249,7 +249,8 @@ class PegParserTest < Minitest::Test
249
249
 
250
250
  actual = @transformer.apply(tree)
251
251
  assert_equal :rundoc, actual.keyword
252
- assert_equal("email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`", actual.original_args)
252
+ assert_nil actual.original_args
253
+ assert_equal("email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`\n", actual.contents)
253
254
  end
254
255
 
255
256
  def test_rundoc_sub_commands_no_quotes
@@ -351,4 +352,19 @@ class PegParserTest < Minitest::Test
351
352
  assert_equal :"background.start", actual.keyword
352
353
  assert_equal ["rails server", {name: "server"}], actual.original_args
353
354
  end
355
+
356
+ def test_no_args_preserves_newlines_in_stdin
357
+ input = <<~EOF.strip
358
+ :::>> rundoc
359
+ first = 1 # comment
360
+ second = 2
361
+ EOF
362
+
363
+ parser = Rundoc::PegParser.new.command_with_stdin
364
+ tree = parser.parse_with_debug(input)
365
+
366
+ actual = @transformer.apply(tree)
367
+ assert_equal :rundoc, actual.keyword
368
+ assert_equal "first = 1 # comment\nsecond = 2".strip, actual.contents.strip
369
+ end
354
370
  end