rundoc 0.0.2 → 1.1.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 (60) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/check_changelog.yml +13 -0
  3. data/.gitignore +7 -0
  4. data/.travis.yml +8 -0
  5. data/CHANGELOG.md +26 -0
  6. data/Dockerfile +24 -0
  7. data/Gemfile +1 -0
  8. data/README.md +261 -92
  9. data/bin/rundoc +4 -60
  10. data/lib/rundoc.rb +15 -1
  11. data/lib/rundoc/cli.rb +84 -0
  12. data/lib/rundoc/code_command.rb +20 -5
  13. data/lib/rundoc/code_command/background.rb +9 -0
  14. data/lib/rundoc/code_command/background/log/clear.rb +17 -0
  15. data/lib/rundoc/code_command/background/log/read.rb +16 -0
  16. data/lib/rundoc/code_command/background/process_spawn.rb +96 -0
  17. data/lib/rundoc/code_command/background/start.rb +38 -0
  18. data/lib/rundoc/code_command/background/stop.rb +17 -0
  19. data/lib/rundoc/code_command/background/wait.rb +19 -0
  20. data/lib/rundoc/code_command/bash.rb +1 -1
  21. data/lib/rundoc/code_command/bash/cd.rb +21 -3
  22. data/lib/rundoc/code_command/file_command/append.rb +2 -0
  23. data/lib/rundoc/code_command/no_such_command.rb +4 -0
  24. data/lib/rundoc/code_command/pipe.rb +17 -4
  25. data/lib/rundoc/code_command/raw.rb +18 -0
  26. data/lib/rundoc/code_command/rundoc/depend_on.rb +37 -0
  27. data/lib/rundoc/code_command/rundoc/require.rb +41 -0
  28. data/lib/rundoc/code_command/rundoc_command.rb +6 -2
  29. data/lib/rundoc/code_command/website.rb +7 -0
  30. data/lib/rundoc/code_command/website/driver.rb +111 -0
  31. data/lib/rundoc/code_command/website/navigate.rb +29 -0
  32. data/lib/rundoc/code_command/website/screenshot.rb +28 -0
  33. data/lib/rundoc/code_command/website/visit.rb +47 -0
  34. data/lib/rundoc/code_section.rb +34 -78
  35. data/lib/rundoc/parser.rb +4 -3
  36. data/lib/rundoc/peg_parser.rb +282 -0
  37. data/lib/rundoc/version.rb +1 -1
  38. data/rundoc.gemspec +9 -3
  39. data/test/fixtures/build_logs/rundoc.md +56 -0
  40. data/test/fixtures/depend_on/dependency/rundoc.md +5 -0
  41. data/test/fixtures/depend_on/main/rundoc.md +10 -0
  42. data/test/fixtures/java/rundoc.md +9 -0
  43. data/test/fixtures/rails_4/rundoc.md +1 -1
  44. data/test/fixtures/rails_5/rundoc.md +76 -74
  45. data/test/fixtures/{rails_5_beta → rails_6}/rundoc.md +93 -87
  46. data/test/fixtures/require/dependency/rundoc.md +5 -0
  47. data/test/fixtures/require/main/rundoc.md +10 -0
  48. data/test/fixtures/screenshot/rundoc.md +10 -0
  49. data/test/rundoc/code_commands/append_file_test.rb +2 -2
  50. data/test/rundoc/code_commands/background_test.rb +69 -0
  51. data/test/rundoc/code_commands/bash_test.rb +1 -1
  52. data/test/rundoc/code_commands/pipe_test.rb +12 -2
  53. data/test/rundoc/code_commands/remove_contents_test.rb +1 -1
  54. data/test/rundoc/code_section_test.rb +6 -5
  55. data/test/rundoc/parser_test.rb +2 -8
  56. data/test/rundoc/peg_parser_test.rb +391 -0
  57. data/test/rundoc/regex_test.rb +1 -1
  58. data/test/rundoc/test_parse_java.rb +1 -1
  59. data/test/test_helper.rb +1 -1
  60. metadata +120 -12
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class BashTest < Test::Unit::TestCase
3
+ class BashTest < Minitest::Test
4
4
 
5
5
  def test_bash_returns_cd
6
6
  original_dir = `pwd`
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class PipeTest < Test::Unit::TestCase
4
-
3
+ class PipeTest < Minitest::Test
5
4
  def test_pipe
6
5
  pipe_cmd = "tail -n 2"
7
6
  cmd = "ls"
@@ -12,4 +11,15 @@ class PipeTest < Test::Unit::TestCase
12
11
  expected = `#{cmd} | #{pipe_cmd}`
13
12
  assert_equal expected, actual
14
13
  end
14
+
15
+ def test_moar_pipe_with_dollar
16
+ pipe_cmd = "tail -n 2"
17
+ cmd = "ls"
18
+ out = `#{cmd}`
19
+ pipe = Rundoc::CodeCommand::Pipe.new("$ #{pipe_cmd}")
20
+ actual = pipe.call(commands: [{command: cmd, output: out}])
21
+
22
+ expected = `#{cmd} | #{pipe_cmd}`
23
+ assert_equal expected, actual
24
+ end
15
25
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class RemoveContentsTest < Test::Unit::TestCase
3
+ class RemoveContentsTest < Minitest::Test
4
4
 
5
5
  def setup
6
6
  @gemfile = <<-RUBY
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class CodeSectionTest < Test::Unit::TestCase
3
+ class CodeSectionTest < Minitest::Test
4
4
 
5
5
  def setup
6
6
  end
@@ -10,7 +10,7 @@ class CodeSectionTest < Test::Unit::TestCase
10
10
  sup
11
11
 
12
12
  ```
13
- :::- $ mkdir foo
13
+ :::-- $ mkdir foo
14
14
  ```
15
15
 
16
16
  yo
@@ -42,7 +42,7 @@ RUBY
42
42
  def test_show_command_hide_render
43
43
  contents = <<-RUBY
44
44
  ```
45
- :::> $ echo "foo"
45
+ :::>- $ echo "foo"
46
46
  ```
47
47
  RUBY
48
48
 
@@ -80,15 +80,16 @@ RUBY
80
80
  code_section = Rundoc::CodeSection.new(match, keyword: ":::")
81
81
  code_section.render
82
82
 
83
+ puts code_section.commands.inspect
83
84
  code_command = code_section.commands.first
84
- assert_equal true, code_command.render_command
85
+ assert_equal true, code_command.render_command
85
86
  assert_equal true, code_command.render_result
86
87
  end
87
88
 
88
89
  def test_hide_command_hide_render
89
90
  contents = <<-RUBY
90
91
  ```
91
- :::- $ echo "foo"
92
+ :::-- $ echo "foo"
92
93
  ```
93
94
  RUBY
94
95
 
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class ParserTest < Test::Unit::TestCase
3
+ class ParserTest < Minitest::Test
4
4
 
5
5
  def setup
6
6
  end
@@ -10,7 +10,7 @@ class ParserTest < Test::Unit::TestCase
10
10
  sup
11
11
 
12
12
  ```
13
- :::> $ mkdir foo
13
+ :::>- $ mkdir foo
14
14
  :::>> $ ls
15
15
  ```
16
16
 
@@ -24,11 +24,6 @@ RUBY
24
24
  parsed = Rundoc::Parser.new(contents)
25
25
  actual = parsed.to_md
26
26
  assert_equal expected, actual
27
-
28
- parsed = Rundoc::Parser.new("\n```\n:::= $ ls\n```\n")
29
- actual = parsed.to_md
30
- expected = "\n```\n$ ls\nfoo\n```\n"
31
- assert_equal expected, actual
32
27
  end
33
28
  end
34
29
  end
@@ -88,7 +83,6 @@ puts b
88
83
  ```
89
84
  RUBY
90
85
 
91
-
92
86
  Dir.mktmpdir do |dir|
93
87
  Dir.chdir(dir) do
94
88
 
@@ -0,0 +1,391 @@
1
+ require 'test_helper'
2
+ require 'parslet/convenience'
3
+
4
+ class PegParserTest < Minitest::Test
5
+ def setup
6
+ @transformer = Rundoc::PegTransformer.new
7
+ end
8
+
9
+ def test_string
10
+ input = %Q{"hello world"}
11
+ parser = Rundoc::PegParser.new.string
12
+ tree = parser.parse_with_debug(input)
13
+ expected = {:string => "hello world"}
14
+ assert_equal expected, tree
15
+
16
+ actual = @transformer.apply(tree)
17
+ assert_equal "hello world", actual
18
+ end
19
+
20
+ def test_keyword_args
21
+ input = %Q{foo: 'bar', baz: "boo"}
22
+ parser = Rundoc::PegParser.new.named_args
23
+ tree = parser.parse_with_debug(input)
24
+ actual = @transformer.apply(tree)
25
+ expected = {foo: 'bar', baz: "boo"}
26
+ assert_equal expected, actual
27
+ end
28
+
29
+ def test_method_call
30
+ input = %Q{sup(foo: 'bar')}
31
+ parser = Rundoc::PegParser.new.method_call
32
+ tree = parser.parse_with_debug(input)
33
+
34
+ actual = @transformer.apply(tree)
35
+ assert_equal :sup, actual.keyword
36
+ assert_equal({foo: 'bar'}, actual.original_args)
37
+
38
+ # seattle style
39
+ input = %Q{sup foo: 'bar' }
40
+ parser = Rundoc::PegParser.new.method_call
41
+ tree = parser.parse_with_debug(input)
42
+ actual = @transformer.apply(tree)
43
+ assert_equal :sup, actual.keyword
44
+ assert_equal({foo: 'bar'}, actual.original_args)
45
+
46
+ # with a dot
47
+ input = %Q{sup.you foo: 'bar' }
48
+ parser = Rundoc::PegParser.new.method_call
49
+ tree = parser.parse_with_debug(input)
50
+ actual = @transformer.apply(tree)
51
+ assert_equal :"sup.you", actual.keyword
52
+ assert_equal({foo: 'bar'}, actual.original_args)
53
+ end
54
+
55
+ def test_with_string_arg
56
+ input = %Q{sup("hey")}
57
+ parser = Rundoc::PegParser.new.method_call
58
+ tree = parser.parse_with_debug(input)
59
+
60
+ actual = @transformer.apply(tree)
61
+ assert_equal :sup, actual.keyword
62
+ assert_equal("hey", actual.original_args)
63
+
64
+ input = %Q{sup "hey"}
65
+ parser = Rundoc::PegParser.new.method_call
66
+ tree = parser.parse_with_debug(input)
67
+
68
+ actual = @transformer.apply(tree)
69
+ assert_equal :sup, actual.keyword
70
+ assert_equal("hey", actual.original_args)
71
+
72
+ input = %Q{sup hey}
73
+ parser = Rundoc::PegParser.new.method_call
74
+ tree = parser.parse_with_debug(input)
75
+
76
+ actual = @transformer.apply(tree)
77
+ assert_equal :sup, actual.keyword
78
+ assert_equal("hey", actual.original_args)
79
+
80
+ input = %Q{ $ cat foo.rb}
81
+ parser = Rundoc::PegParser.new.method_call
82
+ tree = parser.parse_with_debug(input)
83
+
84
+ actual = @transformer.apply(tree)
85
+ assert_equal :"$", actual.keyword
86
+ assert_equal("cat foo.rb", actual.original_args)
87
+ end
88
+
89
+ def test_visability
90
+ input = %Q{>>}
91
+ parser = Rundoc::PegParser.new.visability
92
+ tree = parser.parse_with_debug(input)
93
+ actual = @transformer.apply(tree)
94
+ assert_equal true, actual.command?
95
+ assert_equal true, actual.result?
96
+
97
+ input = %Q{->}
98
+ parser = Rundoc::PegParser.new.visability
99
+ tree = parser.parse_with_debug(input)
100
+ actual = @transformer.apply(tree)
101
+ assert_equal false, actual.command?
102
+ assert_equal true, actual.result?
103
+
104
+ input = %Q{--}
105
+ parser = Rundoc::PegParser.new.visability
106
+ tree = parser.parse_with_debug(input)
107
+ actual = @transformer.apply(tree)
108
+ assert_equal false, actual.command?
109
+ assert_equal false, actual.result?
110
+
111
+ input = %Q{>-}
112
+ parser = Rundoc::PegParser.new.visability
113
+ tree = parser.parse_with_debug(input)
114
+ actual = @transformer.apply(tree)
115
+ assert_equal true, actual.command?
116
+ assert_equal false, actual.result?
117
+ end
118
+
119
+ def test_blerg_method_call
120
+ input = %Q{$ cat foo.rb}
121
+ parser = Rundoc::PegParser.new.method_call
122
+ tree = parser.parse_with_debug(input)
123
+
124
+ actual = @transformer.apply(tree)
125
+ assert_equal :"$", actual.keyword
126
+ assert_equal("cat foo.rb", actual.original_args)
127
+ end
128
+
129
+ def test_command
130
+ input = %Q{:::>> $ cat foo.rb\n}
131
+ parser = Rundoc::PegParser.new.command
132
+ tree = parser.parse_with_debug(input)
133
+
134
+ actual = @transformer.apply(tree)
135
+ assert_equal :"$", actual.keyword
136
+ assert_equal("cat foo.rb", actual.original_args)
137
+ end
138
+
139
+ def test_command_with_stdin
140
+ input = String.new
141
+ input << ":::>> file.write hello.txt\n"
142
+ input << "world\n"
143
+
144
+ parser = Rundoc::PegParser.new.command_with_stdin
145
+ tree = parser.parse_with_debug(input)
146
+
147
+ actual = @transformer.apply(tree)
148
+ assert_equal :"file.write", actual.keyword
149
+ assert_equal("hello.txt", actual.original_args)
150
+ assert_equal("world\n", actual.contents)
151
+ end
152
+
153
+ def test_command_with_stdin_no_string
154
+ input = String.new
155
+ input << ":::>> file.write hello.txt\n"
156
+
157
+ parser = Rundoc::PegParser.new.command_with_stdin
158
+ tree = parser.parse_with_debug(input)
159
+
160
+ actual = @transformer.apply(tree)
161
+
162
+ assert_equal :"file.write", actual.keyword
163
+ assert_equal("hello.txt", actual.original_args)
164
+ end
165
+
166
+ def test_multiple_commands_stdin
167
+ input = String.new
168
+ input << ":::>> file.write hello.txt\n"
169
+ input << "world\n"
170
+ input << ":::>> file.write cinco.txt\n"
171
+ input << "\n\n\n"
172
+ input << " river\n"
173
+
174
+ parser = Rundoc::PegParser.new.multiple_commands
175
+ tree = parser.parse_with_debug(input)
176
+
177
+ actual = @transformer.apply(tree)
178
+
179
+ assert_equal :"file.write", actual.first.keyword
180
+ assert_equal("hello.txt", actual.first.original_args)
181
+ assert_equal("world\n", actual.first.contents)
182
+
183
+ assert_equal :"file.write", actual.last.keyword
184
+ assert_equal("cinco.txt", actual.last.original_args)
185
+ assert_equal("\n\n\n river\n", actual.last.contents)
186
+ end
187
+
188
+ def test_multiple_commands_with_fence
189
+ input = String.new
190
+ input << "```\n"
191
+ input << ":::>> file.write hello.txt\n"
192
+ input << "world\n"
193
+ input << "```\n"
194
+
195
+ parser = Rundoc::PegParser.new.fenced_commands
196
+ tree = parser.parse_with_debug(input)
197
+
198
+ actual = @transformer.apply(tree)
199
+
200
+ assert_equal :"file.write", actual.first.keyword
201
+ assert_equal("hello.txt", actual.first.original_args)
202
+ assert_equal("world\n", actual.first.contents)
203
+ end
204
+
205
+ def test_raw
206
+ input = String.new
207
+ input << "hello.txt\n"
208
+ input << "world\n"
209
+ input << ":::>> $ cd foo\n"
210
+
211
+ parser = Rundoc::PegParser.new.raw_code
212
+ tree = parser.parse_with_debug(input)
213
+
214
+ actual = @transformer.apply(tree)
215
+
216
+ assert_equal "hello.txt\nworld\n", actual.first.contents
217
+ assert_equal :"$", actual.last.keyword
218
+ assert_equal("cd foo", actual.last.original_args)
219
+ end
220
+
221
+
222
+ def test_quotes_in_shell_commands
223
+ input = %Q{:::>- $ git commit -m "init"\n}
224
+ parser = Rundoc::PegParser.new.code_block
225
+ tree = parser.parse_with_debug(input)
226
+
227
+ actual = @transformer.apply(tree)
228
+
229
+ assert_equal :"$", actual.last.keyword
230
+ assert_equal('git commit -m "init"', actual.last.original_args)
231
+ end
232
+
233
+ def test_raises_on_syntax
234
+ input = %Q{:::> $ git commit -m "init"\n}
235
+ assert_raises(Rundoc::PegTransformer::TransformError) do
236
+ parser = Rundoc::PegParser.new.code_block
237
+ tree = parser.parse_with_debug(input)
238
+
239
+ actual = @transformer.apply(tree)
240
+ end
241
+ end
242
+
243
+
244
+ def test_no_args
245
+ # input = String.new
246
+ # input << %Q{rundoc}
247
+ # parser = Rundoc::PegParser.new.no_args_method
248
+ # tree = parser.parse_with_debug(input)
249
+ # actual = @transformer.apply(tree)
250
+ # assert_equal("rundoc", actual.to_s)
251
+
252
+ # input = String.new
253
+ # input << %Q{:::-- rundoc\n}
254
+ # parser = Rundoc::PegParser.new.command
255
+ # tree = parser.parse_with_debug(input)
256
+
257
+ # actual = @transformer.apply(tree)
258
+ # assert_equal :rundoc, actual.keyword
259
+ # assert_nil(actual.original_args)
260
+
261
+
262
+ input = String.new
263
+ input << %Q{:::-- rundoc\n}
264
+ input << %Q{email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`\n}
265
+
266
+ parser = Rundoc::PegParser.new.command_with_stdin
267
+ tree = parser.parse_with_debug(input)
268
+
269
+ actual = @transformer.apply(tree)
270
+ assert_equal :rundoc, actual.keyword
271
+ assert_equal("email = ENV['HEROKU_EMAIL'] || `heroku auth:whoami`", actual.original_args)
272
+ end
273
+
274
+ def test_rundoc_sub_commands_no_quotes
275
+ input = String.new
276
+ input << %Q{:::-- rundoc.depend_on ../foo/bar.md\n}
277
+
278
+ parser = Rundoc::PegParser.new.command_with_stdin
279
+ tree = parser.parse_with_debug(input)
280
+
281
+ actual = @transformer.apply(tree)
282
+ assert_equal :"rundoc.depend_on", actual.keyword
283
+ end
284
+
285
+ def test_seattle_style_method_call
286
+ input = String.new
287
+ input << %Q{rundoc.depend_on '../foo/bar.md'}
288
+ parser = Rundoc::PegParser.new.method_call
289
+ tree = parser.parse_with_debug(input)
290
+
291
+ actual = @transformer.apply(tree)
292
+
293
+ assert_equal :"rundoc.depend_on", actual.keyword
294
+ end
295
+
296
+ def test_rundoc_seattle_sub_command
297
+ input = String.new
298
+ input << %Q{:::>> rundoc.depend_on '../foo/bar.md'\n}
299
+
300
+ parser = Rundoc::PegParser.new.command
301
+ tree = parser.parse_with_debug(input)
302
+
303
+ actual = @transformer.apply(tree)
304
+
305
+ assert_equal :"rundoc.depend_on", actual.keyword
306
+ end
307
+
308
+ def test_positional_args
309
+ input = +""
310
+ input << %Q{call("foo", "bar", biz: "baz")}
311
+
312
+ parser = Rundoc::PegParser.new.method_call
313
+ tree = parser.parse_with_debug(input)
314
+
315
+ # =====================================
316
+ #
317
+ # Handles more than one value, but not only one value
318
+ actual = @transformer.apply(tree)
319
+ assert_equal ["foo", "bar", { biz: "baz"}], actual.original_args
320
+
321
+ input = +""
322
+ input << %Q{call("foo", biz: "baz")}
323
+
324
+ parser = Rundoc::PegParser.new.method_call
325
+ tree = parser.parse_with_debug(input)
326
+
327
+ actual = @transformer.apply(tree)
328
+ assert_equal ["foo", { biz: "baz"}], actual.original_args
329
+
330
+ input = +""
331
+ input << %Q{call("rails server", name: "server")}
332
+
333
+ parser = Rundoc::PegParser.new.method_call
334
+ tree = parser.parse_with_debug(input)
335
+
336
+ actual = @transformer.apply(tree)
337
+ assert_equal ["rails server", {name: "server"}], actual.original_args
338
+
339
+ # input = +""
340
+ # input << %Q{background.start("rails server", name: "server")}
341
+ # parser = Rundoc::PegParser.new.method_call
342
+
343
+ # tree = parser.parse_with_debug(input)
344
+
345
+ # puts tree.inspect
346
+
347
+ # actual = @transformer.apply(tree)
348
+ # assert_equal :"background.start", actual.keyword
349
+
350
+ # ================
351
+
352
+ input = +""
353
+ input << %Q{call("foo", "bar")}
354
+
355
+ parser = Rundoc::PegParser.new.method_call
356
+ tree = parser.parse_with_debug(input)
357
+
358
+ # puts tree.inspect
359
+
360
+ actual = @transformer.apply(tree)
361
+ assert_equal ["foo", "bar"], actual.original_args
362
+
363
+ # ======================
364
+
365
+ input = +""
366
+ input << %Q{call("foo", "bar", biz: "baz")}
367
+
368
+ parser = Rundoc::PegParser.new.method_call
369
+ tree = parser.parse_with_debug(input)
370
+
371
+ actual = @transformer.apply(tree)
372
+ assert_equal ["foo", "bar", { biz: "baz"}], actual.original_args
373
+ end
374
+
375
+ def test_positional_args_code_block
376
+
377
+ input = +""
378
+ input << %Q{:::>> background.start("rails server", name: "server")\n}
379
+ # input << %Q{:::-- background.stop(name: "server")\n}
380
+
381
+ parser = Rundoc::PegParser.new.command
382
+
383
+ tree = parser.parse_with_debug(input)
384
+
385
+ # puts tree.inspect
386
+
387
+ actual = @transformer.apply(tree)
388
+ assert_equal :"background.start", actual.keyword
389
+ assert_equal ["rails server", {:name=>"server"}], actual.original_args
390
+ end
391
+ end