Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## HEAD (unreleased)

- CLI returns non-zero exit code when syntax error is found (https://github.com/zombocom/dead_end/pull/86)
- Let -v respond with gem version instead of 'unknown' (https://github.com/zombocom/dead_end/pull/82)

## 2.0.0
Expand Down
8 changes: 7 additions & 1 deletion exe/dead_end
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ options[:record_dir] = "tmp" if ENV["DEBUG"]

warn "Record dir: #{options[:record_dir]}" if options[:record_dir]

DeadEnd.call(
display = DeadEnd.call(
source: file.read,
filename: file.expand_path,
terminal: options[:terminal],
record_dir: options[:record_dir]
)

if display.document_ok?
exit(0)
else
exit(1)
end
10 changes: 7 additions & 3 deletions lib/dead_end/display_invalid_blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ def initialize(code_lines:, blocks:, io: $stderr, filename: nil, terminal: false
@invalid_obj = invalid_obj
end

def document_ok?
@blocks.none? { |b| !b.hidden? }
end

def call
if @blocks.any? { |b| !b.hidden? }
found_invalid_blocks
else
if document_ok?
@io.puts "Syntax OK"
else
found_invalid_blocks
end
self
end
Expand Down
5 changes: 4 additions & 1 deletion spec/integration/exe_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def exe_path
end

def exe(cmd)
out = run!("#{exe_path} #{cmd}")
out = run!("#{exe_path} #{cmd}", raise_on_nonzero_exit: false)
puts out if ENV["DEBUG"]
out
end
Expand All @@ -18,6 +18,7 @@ def exe(cmd)
ruby_file = exe_path
out = exe(ruby_file)
expect(out.strip).to include("Syntax OK")
expect($?.success?).to be_truthy
end

it "parses invalid code" do
Expand All @@ -26,6 +27,8 @@ def exe(cmd)

expect(out.strip).to include("Missing `end` detected")
expect(out.strip).to include("❯ 36 def filename")

expect($?.success?).to be_falsey
end

it "handles heredocs" do
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def code_line_array(source)
DeadEnd::CleanDocument.new(source: source).call.lines
end

def run!(cmd)
def run!(cmd, raise_on_nonzero_exit: true)
out = `#{cmd} 2>&1`
raise "Command: #{cmd} failed: #{out}" unless $?.success?
raise "Command: #{cmd} failed: #{out}" if !$?.success? && raise_on_nonzero_exit
out
end

Expand Down