rundoc 3.1.0 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +28 -0
- data/lib/rundoc/cli.rb +1 -1
- data/lib/rundoc/cli_argument_parser.rb +1 -1
- data/lib/rundoc/code_command/rundoc/require.rb +8 -3
- data/lib/rundoc/code_section.rb +3 -1
- data/lib/rundoc/parser.rb +20 -1
- data/lib/rundoc/version.rb +1 -1
- data/test/integration/failure_test.rb +52 -1
- data/test/integration/require_test.rb +34 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c2298eda9572df3a7acbb3d9a81ba5bdc2b5c80ba5ebc913d22308780aeff47
|
4
|
+
data.tar.gz: d9b2f86f1cfe167657f4d0d76c23f44340b6f992b959864401c1496241fbcbea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0db0233ad2b0773f453f2eb487bebc2d3cd3fb114f44aaf2295206250722ca3c4a29ceb558d1546de88865cdb120bc113ac828397b9a50c04c06b50e9aa0a0d2
|
7
|
+
data.tar.gz: d89e65b47bca1d1bd76f5894621c2ea53a957215008b043e3be6e672e87093e3a6af3a8696c9ab03e1dcf2ebb39b8362b882bc38235a0e4c1718744f30d2592c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## HEAD
|
2
2
|
|
3
|
+
## 3.1.2
|
4
|
+
|
5
|
+
- Fix: Using `rundoc.require` inside of a document that was `rundoc.require`-d now sources files from the correct relative document path (https://github.com/zombocom/rundoc/pull/84)
|
6
|
+
- Fix: `rundoc <file> --with-contents <dir>` now expands the path passed in to the `--with-contents` so relative paths can safely be used (https://github.com/zombocom/rundoc/pull/83)
|
7
|
+
|
8
|
+
## 3.1.1
|
9
|
+
|
10
|
+
- Fix: Include all code sections in the event of a failure, not just the last one (https://github.com/zombocom/rundoc/pull/71)
|
11
|
+
|
3
12
|
## 3.1.0
|
4
13
|
|
5
14
|
- Add: `--with-contents` flag that accepts a directory. The **contents** of the directory (and not the directory itself) will be copied into the working dir before execution. This is useful for debugging a single rundoc step. ()
|
data/README.md
CHANGED
@@ -88,6 +88,7 @@ This will generate a project folder with your project in it, and a markdown `REA
|
|
88
88
|
- [background.stop](#background)
|
89
89
|
- [background.log.read](#background)
|
90
90
|
- [background.log.clear](#background)
|
91
|
+
- [background.wait](#background)
|
91
92
|
- Take screenshots
|
92
93
|
- [website.visit](#screenshots)
|
93
94
|
- [website.nav](#screenshots)
|
@@ -410,6 +411,13 @@ To start a process, pass in the command as the first arg, and give it a name (so
|
|
410
411
|
:::>> background.start("rails server", name: "server")
|
411
412
|
```
|
412
413
|
|
414
|
+
- Arguments
|
415
|
+
- name: Identifier of the background process, used in later invocations.
|
416
|
+
- wait (Optional): A string to wait for before continuing. This is useful to block moving on until an event happend such as a server was booted or web request was received. Also see `background.wait`
|
417
|
+
- timeout (Optional): A number of seconds to wait for a given string to be found in the logs.
|
418
|
+
- out (Optional): A bash redirect. Defaults to `2>&1` to merge stderr and stdout together.
|
419
|
+
- allow_fail (Optional): Set to `true` if the command exiting shouldn't halt doc generation. Poorly named, may be renamed in the future.
|
420
|
+
|
413
421
|
You can make the background process wait until it receives a certain string in the logs. For instance to make sure that the server is fully booted:
|
414
422
|
|
415
423
|
```
|
@@ -422,18 +430,38 @@ You can stop the process by referencing the name:
|
|
422
430
|
:::-- background.stop(name: "server")
|
423
431
|
```
|
424
432
|
|
433
|
+
- Arguments
|
434
|
+
- name
|
435
|
+
|
425
436
|
You can also get the log contents:
|
426
437
|
|
427
438
|
```
|
428
439
|
:::>> background.log.read(name: "server")
|
429
440
|
```
|
430
441
|
|
442
|
+
- Arguments
|
443
|
+
- name
|
444
|
+
|
431
445
|
You can also truncate the logs:
|
432
446
|
|
433
447
|
```
|
434
448
|
:::>> background.log.clear(name: "server")
|
435
449
|
```
|
436
450
|
|
451
|
+
- Arguments
|
452
|
+
- name
|
453
|
+
|
454
|
+
You can also wait for a given string to appear in the logs:
|
455
|
+
|
456
|
+
```
|
457
|
+
:::>> background.wait(name: "server", wait: "method=GET")
|
458
|
+
```
|
459
|
+
|
460
|
+
- Arguments
|
461
|
+
- name
|
462
|
+
- wait: Same as `background.start` a string value to look for before continuing.
|
463
|
+
- timeout: Maximum number of seconds to wait
|
464
|
+
|
437
465
|
## Screenshots
|
438
466
|
|
439
467
|
You'll need selenium and `chromedriver` installed on your system to make screenshots work. On a mac you can run:
|
data/lib/rundoc/cli.rb
CHANGED
@@ -203,7 +203,7 @@ module Rundoc
|
|
203
203
|
to: on_failure_dir
|
204
204
|
)
|
205
205
|
|
206
|
-
on_failure_dir.join("RUNDOC_FAILED.md").write(Rundoc::
|
206
|
+
on_failure_dir.join("RUNDOC_FAILED.md").write(Rundoc::Parser.partial_result_to_doc)
|
207
207
|
end
|
208
208
|
|
209
209
|
private def on_success(output)
|
@@ -111,7 +111,7 @@ module Rundoc
|
|
111
111
|
end
|
112
112
|
|
113
113
|
opts.on("--with-contents <dir>", "Copies contents of directory into the tmp working dir") do |v|
|
114
|
-
options[:with_contents_dir] = v
|
114
|
+
options[:with_contents_dir] = File.expand_path(v)
|
115
115
|
end
|
116
116
|
|
117
117
|
opts.on("--on-success-dir <dir>", "Success dir, relative to CWD. i.e. `<rundoc.md/dir>/#{CLI::DEFAULTS::ON_SUCCESS_DIR}/`.") do |v|
|
@@ -14,12 +14,17 @@ class ::Rundoc::CodeCommand
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(env = {})
|
17
|
-
|
17
|
+
execution_context = env[:context]
|
18
|
+
document_path = @path.expand_path(execution_context.source_dir)
|
18
19
|
|
19
|
-
puts "rundoc.require: Start executing #{@path.to_s.inspect}"
|
20
20
|
output = Rundoc::Parser.new(
|
21
21
|
document_path.read,
|
22
|
-
context:
|
22
|
+
context: Rundoc::Context::Execution.new(
|
23
|
+
source_path: document_path,
|
24
|
+
output_dir: execution_context.output_dir,
|
25
|
+
screenshots_dirname: execution_context.screenshots_dir,
|
26
|
+
with_contents_dir: execution_context.with_contents_dir
|
27
|
+
)
|
23
28
|
).to_md
|
24
29
|
|
25
30
|
if render_result?
|
data/lib/rundoc/code_section.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Rundoc
|
4
|
-
#
|
4
|
+
# A code secttion respesents a block of fenced code
|
5
|
+
#
|
6
|
+
# A document can have multiple code sections
|
5
7
|
class CodeSection
|
6
8
|
class ParseError < StandardError
|
7
9
|
def initialize(options = {})
|
data/lib/rundoc/parser.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
module Rundoc
|
2
|
+
# This poorly named class is responsible for taking in the raw markdown and running it
|
3
|
+
#
|
4
|
+
# It works by pulling out the code blocks (CodeSection), and putting them onto a stack.
|
5
|
+
# It then executes each in turn and records the results.
|
2
6
|
class Parser
|
3
7
|
DEFAULT_KEYWORD = ":::"
|
4
8
|
INDENT_BLOCK = '(?<before_indent>(^\s*$\n|\A)(^(?:[ ]{4}|\t))(?<indent_contents>.*)(?<after_indent>[^\s].*$\n?(?:(?:^\s*$\n?)*^(?:[ ]{4}|\t).*[^\s].*$\n?)*))'
|
@@ -7,6 +11,7 @@ module Rundoc
|
|
7
11
|
COMMAND_REGEX = ->(keyword) {
|
8
12
|
/^#{keyword}(?<tag>(\s|=|-|>)?(=|-|>)?)\s*(?<command>(\S)+)\s+(?<statement>.*)$/
|
9
13
|
}
|
14
|
+
PARTIAL_RESULT = []
|
10
15
|
|
11
16
|
attr_reader :contents, :keyword, :stack, :context
|
12
17
|
|
@@ -17,6 +22,7 @@ module Rundoc
|
|
17
22
|
@keyword = keyword
|
18
23
|
@stack = []
|
19
24
|
partition
|
25
|
+
PARTIAL_RESULT.clear
|
20
26
|
end
|
21
27
|
|
22
28
|
def to_md
|
@@ -27,13 +33,26 @@ module Rundoc
|
|
27
33
|
else
|
28
34
|
s
|
29
35
|
end
|
36
|
+
PARTIAL_RESULT.replace(result)
|
30
37
|
end
|
31
|
-
|
38
|
+
|
39
|
+
self.class.to_doc(result: result)
|
32
40
|
rescue => e
|
33
41
|
File.write("README.md", result.join(""))
|
34
42
|
raise e
|
35
43
|
end
|
36
44
|
|
45
|
+
def self.partial_result_to_doc
|
46
|
+
out = to_doc(result: PARTIAL_RESULT)
|
47
|
+
unfinished = CodeSection.partial_result_to_doc
|
48
|
+
out << unfinished if unfinished
|
49
|
+
out
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.to_doc(result:)
|
53
|
+
result.join("")
|
54
|
+
end
|
55
|
+
|
37
56
|
# split into [before_code, code, after_code], process code, and re-run until tail is empty
|
38
57
|
def partition
|
39
58
|
until contents.empty?
|
data/lib/rundoc/version.rb
CHANGED
@@ -1,7 +1,58 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class IntegrationFailureTest < Minitest::Test
|
4
|
-
def
|
4
|
+
def test_writes_to_dir_on_failure_two_block
|
5
|
+
Dir.mktmpdir do |dir|
|
6
|
+
Dir.chdir(dir) do
|
7
|
+
dir = Pathname(dir)
|
8
|
+
|
9
|
+
source_path = dir.join("RUNDOC.md")
|
10
|
+
source_path.write <<~EOF
|
11
|
+
```
|
12
|
+
:::>> $ mkdir one
|
13
|
+
:::>> $ touch one/rofl.txt
|
14
|
+
```
|
15
|
+
|
16
|
+
```
|
17
|
+
:::>> $ mkdir two
|
18
|
+
:::>> $ touch two/rofl.txt
|
19
|
+
:::>> $ touch does/not/exist.txt
|
20
|
+
```
|
21
|
+
EOF
|
22
|
+
|
23
|
+
io = StringIO.new
|
24
|
+
|
25
|
+
error = nil
|
26
|
+
begin
|
27
|
+
Rundoc::CLI.new(
|
28
|
+
io: io,
|
29
|
+
source_path: source_path,
|
30
|
+
on_success_dir: dir.join(SUCCESS_DIRNAME)
|
31
|
+
).call
|
32
|
+
rescue => e
|
33
|
+
error = e
|
34
|
+
end
|
35
|
+
|
36
|
+
assert error
|
37
|
+
assert_includes error.message, "exited with non zero status"
|
38
|
+
|
39
|
+
refute dir.join(SUCCESS_DIRNAME).join("two").exist?
|
40
|
+
refute dir.join(SUCCESS_DIRNAME).join("two").join("rofl.txt").exist?
|
41
|
+
|
42
|
+
assert dir.join(FAILURE_DIRNAME).join("two").exist?
|
43
|
+
assert dir.join(FAILURE_DIRNAME).join("two").join("rofl.txt").exist?
|
44
|
+
|
45
|
+
doc = dir.join(FAILURE_DIRNAME).join("RUNDOC_FAILED.md").read
|
46
|
+
assert_includes doc, "$ mkdir one"
|
47
|
+
assert_includes doc, "$ touch one/rofl.txt"
|
48
|
+
|
49
|
+
assert_includes doc, "$ mkdir two"
|
50
|
+
assert_includes doc, "$ touch two/rofl.txt"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_writes_to_dir_on_failure_one_block
|
5
56
|
Dir.mktmpdir do |dir|
|
6
57
|
Dir.chdir(dir) do
|
7
58
|
dir = Pathname(dir)
|
@@ -60,4 +60,38 @@ class IntegrationRequireTest < Minitest::Test
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
|
+
|
64
|
+
def test_require_is_relative_to_current_file_not_source_file
|
65
|
+
Dir.mktmpdir do |dir|
|
66
|
+
Dir.chdir(dir) do
|
67
|
+
dir = Pathname(dir)
|
68
|
+
|
69
|
+
source_path = dir.join("RUNDOC.md")
|
70
|
+
source_path.write <<~EOF
|
71
|
+
```
|
72
|
+
:::>> rundoc.require "./src/a.md"
|
73
|
+
```
|
74
|
+
EOF
|
75
|
+
|
76
|
+
dir.join("src").tap(&:mkpath).join("a.md").write <<~EOF
|
77
|
+
```
|
78
|
+
:::-> rundoc.require "./b.md"
|
79
|
+
```
|
80
|
+
EOF
|
81
|
+
|
82
|
+
dir.join("src").join("b.md").write <<~EOF
|
83
|
+
```
|
84
|
+
:::-> print.text Hello World!
|
85
|
+
```
|
86
|
+
EOF
|
87
|
+
|
88
|
+
parsed = parse_contents(
|
89
|
+
source_path.read,
|
90
|
+
source_path: source_path
|
91
|
+
)
|
92
|
+
actual = parsed.to_md.gsub(Rundoc::CodeSection::AUTOGEN_WARNING, "")
|
93
|
+
assert_equal "Hello World!", actual.strip
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
63
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rundoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Schneeman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|