diff --git a/lib/rundoc/cli.rb b/lib/rundoc/cli.rb index 7371a96..173e4b5 100644 --- a/lib/rundoc/cli.rb +++ b/lib/rundoc/cli.rb @@ -190,6 +190,8 @@ def call from: execution_context.output_dir, to: on_failure_dir ) + + on_failure_dir.join("RUNDOC_FAILED.md").write(Rundoc::CodeSection.partial_result_to_doc) end private def on_success(output) diff --git a/lib/rundoc/code_section.rb b/lib/rundoc/code_section.rb index 2be28e6..ed2af35 100644 --- a/lib/rundoc/code_section.rb +++ b/lib/rundoc/code_section.rb @@ -84,6 +84,10 @@ def render self.class.to_doc(result: result, env: env) end + def self.partial_result_to_doc + self.to_doc(result: PARTIAL_RESULT, env: PARTIAL_ENV) + end + def self.to_doc(result: , env: ) array = [env[:before]] diff --git a/test/integration/failure_test.rb b/test/integration/failure_test.rb new file mode 100644 index 0000000..4dac8af --- /dev/null +++ b/test/integration/failure_test.rb @@ -0,0 +1,46 @@ +require "test_helper" + +class IntegrationFailureTest < Minitest::Test + def test_writes_to_dir_on_failure + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + dir = Pathname(dir) + + source_path = dir.join("RUNDOC.md") + source_path.write <<~EOF + ``` + :::>> $ mkdir lol + :::>> $ touch lol/rofl.txt + :::>> $ touch does/not/exist.txt + ``` + EOF + + io = StringIO.new + + error = nil + begin + Rundoc::CLI.new( + io: io, + source_path: source_path, + on_success_dir: dir.join(SUCCESS_DIRNAME) + ).call + rescue => e + error = e + end + + assert error + assert_includes error.message, "exited with non zero status" + + refute dir.join(SUCCESS_DIRNAME).join("lol").exist? + refute dir.join(SUCCESS_DIRNAME).join("lol").join("rofl.txt").exist? + + assert dir.join(FAILURE_DIRNAME).join("lol").exist? + assert dir.join(FAILURE_DIRNAME).join("lol").join("rofl.txt").exist? + + doc = dir.join(FAILURE_DIRNAME).join("RUNDOC_FAILED.md").read + assert_includes doc, "$ mkdir lol" + assert_includes doc, "$ touch lol/rofl.txt" + end + end + end +end