Skip to content

Commit

Permalink
Merge Fix xcpretty swallowing up errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashin Arab authored and steipete committed Apr 17, 2016
1 parent 34c63f8 commit 01b8a11
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 6 deletions.
13 changes: 12 additions & 1 deletion lib/xcpretty/formatters/formatter.rb
Expand Up @@ -20,6 +20,7 @@ def format_clean_remove; EMPTY; end
def format_compile(file_name, file_path); EMPTY; end
def format_compile_command(compiler_command, file_path); EMPTY; end
def format_compile_storyboard(file_name, file_path); EMPTY; end
def format_compile_storyboard_error(file_name, error); EMPTY; end
def format_compile_xib(file_name, file_path); EMPTY; end
def format_copy_header_file(source, target); EMPTY; end
def format_copy_plist_file(source, target); EMPTY; end
Expand All @@ -35,7 +36,8 @@ def format_failing_test(suite, test, time, file_path); EMPTY; end
def format_process_pch(file); EMPTY; end
def format_process_pch_command(file_path); EMPTY; end
def format_phase_success(phase_name); EMPTY; end
def format_phase_script_execution(script_name); EMPTY; end
def format_phase_script_execution(phase_name); EMPTY; end
def format_phase_script_error(error, output) EMPTY; end
def format_process_info_plist(file_name, file_path); EMPTY; end
def format_codesign(file); EMPTY; end
def format_preprocess(file); EMPTY; end
Expand Down Expand Up @@ -119,11 +121,20 @@ def format_error(message)
"\n#{red(error_symbol + " " + message)}\n\n"
end

def format_phase_script_error(error, output)
indented_output = output.join(" ")
"\n#{red(error_symbol + " ")}#{error}: #{red(indented_output)}\n\n"
end

def format_compile_error(file, file_path, reason, line, cursor)
"\n#{red(error_symbol + " ")}#{file_path}: #{red(reason)}\n\n" \
"#{line}\n#{cyan(cursor)}\n\n"
end

def format_compile_storyboard_error(file_name, error)
format_error(file_name + ": " + error)
end

def format_file_missing_error(reason, file_path)
"\n#{red(error_symbol + " " + reason)} #{file_path}\n\n"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/xcpretty/formatters/simple.rb
Expand Up @@ -102,8 +102,8 @@ def format_phase_success(phase_name)
format(phase_name.capitalize, "Succeeded")
end

def format_phase_script_execution(script_name)
format("Running script", "'#{script_name}'")
def format_phase_script_execution(phase_name)
format("Running phase", "'#{phase_name}'")
end

def format_process_info_plist(file_name, file_path)
Expand Down
70 changes: 69 additions & 1 deletion lib/xcpretty/parser.rb
Expand Up @@ -133,7 +133,6 @@ module Matchers

PHASE_SUCCESS_MATCHER = /^\*\*\s(.*)\sSUCCEEDED\s\*\*/

# @regex Captured groups
# $1 = script_name
PHASE_SCRIPT_EXECUTION_MATCHER = /^PhaseScriptExecution\s((\\\ |\S)*)\s/

Expand Down Expand Up @@ -187,6 +186,21 @@ module Matchers
# @regex Captured groups
WRITE_AUXILIARY_FILES = /^Write auxiliary files/

module PhaseScript
# @regex Captured groups
# $1 = phase_details
PHASE_SCRIPT_EXECUTION_MATCHER = /^PhaseScriptExecution\s(.*)/

# @regex Captured groups
# $1 = file not found
PHASE_SCRIPT_NO_SUCH_FILE_OR_DIRECTORY_MATCHER = /: (.*): (No such file or directory)$/

# @regex Captured groups
# $1 = command
# $2 = exit code
PHASE_SCRIPT_COMMAND_FAILED_MATCHER = /^Command (.*) failed with exit code (\d+)/
end

module Warnings
# $1 = file_path
# $2 = file_name
Expand Down Expand Up @@ -250,19 +264,28 @@ module Errors
# $1 reason
LINKER_UNDEFINED_SYMBOLS_MATCHER = /^(Undefined symbols for architecture .*):$/

# @regex Captured groups
# $1 storyboard
# $2 error
COMPILE_STORYBOARD_ERROR_MATCHER = /([^\/]*\.storyboard).*:\serror:\s(.*)$/

# @regex Captured groups
# $1 reason
PODS_ERROR_MATCHER = /^(error:\s.*)/

# @regex Captured groups
# $1 = reference
SYMBOL_REFERENCED_FROM_MATCHER = /\s+"(.*)", referenced from:$/

# @regex Captured groups
GENERIC_ERROR_MATCHER = /error:\s(.*)$/
end
end

class Parser

include Matchers
include Matchers::PhaseScript
include Matchers::Errors
include Matchers::Warnings

Expand All @@ -276,11 +299,13 @@ def parse(text)
update_test_state(text)
update_error_state(text)
update_linker_failure_state(text)
update_phase_script_state(text)

return format_compile_error if should_format_error?
return format_compile_warning if should_format_warning?
return format_undefined_symbols if should_format_undefined_symbols?
return format_duplicate_symbols if should_format_duplicate_symbols?
return format_phase_script_error if should_format_phase_script_error?

case text
when ANALYZE_MATCHER
Expand Down Expand Up @@ -315,6 +340,8 @@ def parse(text)
formatter.format_compile_xib($2, $1)
when COMPILE_STORYBOARD_MATCHER
formatter.format_compile_storyboard($2, $1)
when COMPILE_STORYBOARD_ERROR_MATCHER
formatter.format_compile_storyboard_error($1, $2)
when COPY_HEADER_MATCHER
formatter.format_copy_header_file($1, $2)
when COPY_PLIST_MATCHER
Expand Down Expand Up @@ -379,13 +406,32 @@ def parse(text)
formatter.format_shell_command($1, $2)
when GENERIC_WARNING_MATCHER
formatter.format_warning($1)
when GENERIC_ERROR_MATCHER
formatter.format_error($1)
else
""
end
end

private

def update_phase_script_state(text)
case text
when PHASE_SCRIPT_EXECUTION_MATCHER
@current_phase_script_output = [text]
when PHASE_SCRIPT_COMMAND_FAILED_MATCHER, PHASE_SCRIPT_NO_SUCH_FILE_OR_DIRECTORY_MATCHER
unless @current_phase_script_output.nil?
@current_phase_script_output << text
current_phase_script_failure[:output] = @current_phase_script_output
current_phase_script_failure[:error] = text
end
else
unless @current_phase_script_output.nil?
@current_phase_script_output << text
end
end
end

def update_test_state(text)
case text
when TESTS_RUN_START_MATCHER
Expand Down Expand Up @@ -459,6 +505,10 @@ def should_format_duplicate_symbols?
current_linker_failure[:message] && current_linker_failure[:files].count > 1
end

def should_format_phase_script_error?
current_phase_script_failure[:error] && current_phase_script_failure[:output]
end

def current_issue
@current_issue ||= {}
end
Expand All @@ -467,6 +517,10 @@ def current_linker_failure
@linker_failure ||= {files: []}
end

def current_phase_script_failure
@phase_script_failure ||= {}
end

def format_compile_error
error = current_issue.dup
@current_issue = {}
Expand Down Expand Up @@ -508,6 +562,20 @@ def format_duplicate_symbols
result
end

def format_phase_script_error
result = formatter.format_phase_script_error(current_phase_script_failure[:error],
current_phase_script_failure[:output]
)

reset_phase_script_state
result
end

def reset_phase_script_state
@phase_script_failure = nil
@current_phase_script_output = nil
end

def reset_linker_format_state
@linker_failure = nil
@formatting_linker_failure = false
Expand Down
10 changes: 10 additions & 0 deletions spec/fixtures/constants.rb
Expand Up @@ -128,6 +128,12 @@
cd /Users/musalj/code/OSS/Alcatraz
/usr/bin/tiffutil -cathidpicheck /Users/musalj/code/OSS/Alcatraz/Alcatraz/eye_icon@2x.png /Users/musalj/code/OSS/Alcatraz/Alcatraz/eye_icon.png -out /Users/musalj/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin/Contents/Resources/eye_icon.tiff
)
SAMPLE_RUN_SCRIPT_ERROR = %Q(
PhaseScriptExecution Run\\ Script DerivedData/Build/Intermediates/Blah.build/Debug-iphonesimulator/Blah.build/Script-F07128051BCF177900851764.sh
cd /Users/blah/iosapps/test/iOS
/bin/sh -c /Users/blah/iosapps/test/iOS/DerivedData/Build/Intermediates/Blah.build/Debug-iphonesimulator/Blah.build/Script-F07128051BCF177900851764.sh
/bin/sh: blah: No such file or directory
)
SAMPLE_RUN_SCRIPT = %Q(
PhaseScriptExecution Check\\ Pods\\ Manifest.lock /Users/musalj/Library/Developer/Xcode/DerivedData/ObjectiveSugar-ayzdhqmmwtqgysdpznmovjlupqjy/Build/Intermediates/ObjectiveSugar.build/Debug-iphonesimulator/ObjectiveSugar.build/Script-468DABF301EC4EC1A00CC4C2.sh
cd /Users/musalj/code/OSS/ObjectiveSugar/Example
Expand Down Expand Up @@ -462,6 +468,7 @@
setenv variant normal
/bin/sh -c /Users/musalj/Library/Developer/Xcode/DerivedData/ObjectiveSugar-ayzdhqmmwtqgysdpznmovjlupqjy/Build/Intermediates/ObjectiveSugar.build/Debug-iphonesimulator/ObjectiveSugar.build/Script-468DABF301EC4EC1A00CC4C2.sh
)

SAMPLE_ANALYZE = %Q(
Analyze CocoaChip/CCChip8DisplayView.m
cd /Users/dustin/Source/CocoaChip
Expand All @@ -486,6 +493,9 @@
export XCODE_DEVELOPER_USR_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin/..
/Applications/Xcode.app/Contents/Developer/usr/bin/ibtool --target-device iphone --target-device ipad --errors --warnings --notices --module sample --minimum-deployment-target 7.0 --output-partial-info-plist /Users/chipp/Library/Developer/Xcode/DerivedData/sample-etjztiverddwaddrudeteewjzfxw/Build/Intermediates/ArchiveIntermediates/sample/IntermediateBuildFilesPath/sample.build/Release-iphoneos/sample.build/SJMetroPickerStoryboard-SBPartialInfo.plist --auto-activate-custom-fonts --output-format human-readable-text --compilation-directory /Users/chipp/Library/Developer/Xcode/DerivedData/sample-etjztiverddwaddrudeteewjzfxw/Build/Intermediates/ArchiveIntermediates/sample/InstallationBuildProductsLocation/Applications/sample.app /Users/chipp/Developer/sample/sample/Main.storyboard
)
SAMPLE_COMPILE_STORYBOARD_ERROR = %Q(
/Users/blah/iosapps/test/blah-Blah-ios/Blah/Resources/Views/LaunchScreen.storyboard: error: Line 11: error parsing attribute name
)
SAMPLE_CODESIGN = %Q(
CodeSign build/Release/CocoaChip.app
cd /Users/dustin/Source/CocoaChip
Expand Down
2 changes: 1 addition & 1 deletion spec/xcpretty/formatters/simple_spec.rb
Expand Up @@ -125,7 +125,7 @@ module XCPretty

it "formats Phase Script Execution" do
@formatter.format_phase_script_execution("Check Pods Manifest.lock").should ==
"> Running script 'Check Pods Manifest.lock'"
"> Running phase 'Check Pods Manifest.lock'"
end

it "formats precompiling output" do
Expand Down
25 changes: 24 additions & 1 deletion spec/xcpretty/parser_spec.rb
Expand Up @@ -116,6 +116,11 @@ module XCPretty
@parser.parse(SAMPLE_COMPILE_STORYBOARD)
end

it "parses compiling storyboard errors" do
@formatter.should receive(:format_compile_storyboard_error).with("LaunchScreen.storyboard", "Line 11: error parsing attribute name")
@parser.parse(SAMPLE_COMPILE_STORYBOARD_ERROR)
end

it 'parses CopyPlistFile' do
@formatter.should receive(:format_copy_plist_file).with(
'/path/to/Some.plist', '/some other/File.plist')
Expand Down Expand Up @@ -219,10 +224,23 @@ module XCPretty
end

it "parses PhaseScriptExecution" do
@formatter.should receive(:format_phase_script_execution).with('Check Pods Manifest.lock')
@formatter.should receive(:format_phase_script_execution).with('Check Pods Manifest.lock /Users/musalj/Library/Developer/Xcode/DerivedData/ObjectiveSugar-ayzdhqmmwtqgysdpznmovjlupqjy/Build/Intermediates/ObjectiveSugar.build/Debug-iphonesimulator/ObjectiveSugar.build/Script-468DABF301EC4EC1A00CC4C2.sh')
@parser.parse(SAMPLE_RUN_SCRIPT)
end

it "parses PhaseScriptExecution Error" do
@formatter.should receive(:format_phase_script_execution).with('Run Script DerivedData/Build/Intermediates/Blah.build/Debug-iphonesimulator/Blah.build/Script-F07128051BCF177900851764.sh')
@formatter.should receive(:format_phase_script_error).with('/bin/sh: blah: No such file or directory',
['PhaseScriptExecution Run\\ Script DerivedData/Build/Intermediates/Blah.build/Debug-iphonesimulator/Blah.build/Script-F07128051BCF177900851764.sh',
'cd /Users/blah/iosapps/test/iOS',
'/bin/sh -c /Users/blah/iosapps/test/iOS/DerivedData/Build/Intermediates/Blah.build/Debug-iphonesimulator/Blah.build/Script-F07128051BCF177900851764.sh',
'/bin/sh: blah: No such file or directory'])

SAMPLE_RUN_SCRIPT_ERROR.each_line do |line|
@parser.parse(line.chomp)
end
end

it "parses process PCH" do
@formatter.should receive(:format_process_pch).with("Pods-CocoaLumberjack-prefix.pch")
@parser.parse(SAMPLE_PRECOMPILE)
Expand Down Expand Up @@ -457,6 +475,11 @@ module XCPretty
@formatter.should_not receive(:format_compile_error)
@parser.parse("hohohoooo")
end

it 'parses generic errors' do
@formatter.should receive(:format_error).with("Hi there. I'm a really nasty error. Can you fix me")
@parser.parse(" error: Hi there. I'm a really nasty error. Can you fix me")
end
end

context "warnings" do
Expand Down

0 comments on commit 01b8a11

Please sign in to comment.