Skip to content
This repository was archived by the owner on Feb 1, 2018. It is now read-only.
Open
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
18 changes: 11 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
PATH
remote: .
specs:
bwoken (2.1.0.rc.2)
bwoken (2.1.0.rc.4)
coffee-script-source
colorful
execjs
json_pure
nokogiri (~> 1.6.5)
rake
slop
slop (~> 3.6.0)

GEM
remote: https://rubygems.org/
specs:
coffee-script-source (1.6.3)
coffee-script-source (1.9.1)
colorful (0.0.3)
diff-lcs (1.2.1)
execjs (2.0.1)
execjs (2.3.0)
ffi (1.0.11)
guard (1.0.1)
ffi (>= 0.5.0)
thor (~> 0.14.6)
guard-rspec (0.6.0)
guard (>= 0.10.0)
json_pure (1.8.0)
rake (10.1.0)
json_pure (1.8.2)
mini_portile (0.6.2)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
rake (10.4.2)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
Expand All @@ -32,7 +36,7 @@ GEM
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.0)
slop (3.4.6)
slop (3.6.0)
thor (0.14.6)

PLATFORMS
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ $ bwoken test -h
--configuration The build configruation to use (e.g., --configuration=Release)
--sdk-version The SDK version to use (e.g., --sdk-version=6.1)
--verbose Be verbose
--junit To output results in junit xml format
-h, --help Display this help message.
</code></pre>

Expand Down
31 changes: 3 additions & 28 deletions bin/unix_instruments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,10 @@
set -e # Bomb on any script errors

run_instruments() {
# Because instruments buffers it's output if it determines that it is being
# piped to another process, we have to use ptys to get around that so that we
# can use `tee` to save the output for grepping and print to stdout in real
# time at the same time.
#
# I don't like this because I'm hard coding a tty/pty pair in here. Suggestions
# to make this cleaner?

# Pipe to `tee` using a temporary file so everything is sent to standard out
# and we have the output to check for errors.
output=$(mktemp -t unix-instruments)
instruments "$@" &> /dev/ttyvf &
pid_instruments=$!

# Cat the instruments output to tee which outputs to stdout and saves to
# $output at the same time
cat < /dev/ptyvf | tee $output

# Clear the process id we saved when forking instruments so the cleanup
# function called on exit knows it doesn't have to kill anything
pid_instruments=0
instruments "$@" 2>&1 | tee $output

# Process the instruments output looking for anything that resembles a fail
# message
Expand All @@ -72,16 +57,6 @@ get_error_status() {
ruby -e 'exit 1 if STDIN.read =~ /Instruments Usage Error|Instruments Trace Error|^\d+-\d+-\d+ \d+:\d+:\d+ [-+]\d+ (Fail:|Error:|None: Script threw an uncaught JavaScript error)/'
}

trap cleanup_instruments EXIT
cleanup_instruments() {
# Because we fork instruments in this script, we need to clean up if it's
# still running because of an error or the user pressed Ctrl-C
if [[ $pid_instruments -gt 0 ]]; then
echo "Cleaning up instruments..."
kill -9 $pid_instruments
fi
}

# Running this file with "----test" will try to parse an error out of whatever
# is handed in to it from stdin. Use this method to double check your work if
# you need a custom "get_error_status" function above.
Expand Down
3 changes: 2 additions & 1 deletion bwoken.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Gem::Specification.new do |gem|
gem.add_dependency 'execjs'
gem.add_dependency 'json_pure'
gem.add_dependency 'rake'
gem.add_dependency 'slop'
gem.add_dependency 'slop', '~> 3.6.0'
gem.add_dependency 'nokogiri', '~> 1.6.5'

gem.add_development_dependency 'rspec'
gem.add_development_dependency 'guard-rspec'
Expand Down
1 change: 1 addition & 0 deletions lib/bwoken/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
on :configuration=, 'The build configruation to use (e.g., --configuration=Release)', :default => 'Debug'
on :'sdk-version=', 'The SDK version to use (e.g., --sdk-version=6.1)'
on :verbose, 'Be verbose'
on :junit, 'Create junit xml test results'

run { ran_command = 'test' }
end
Expand Down
11 changes: 9 additions & 2 deletions lib/bwoken/cli/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
require 'bwoken/device'
#TODO: make formatters dynamically loadable during runtime
require 'bwoken/formatter'
require 'bwoken/formatters/fanout_formatter'
require 'bwoken/formatters/passthru_formatter'
require 'bwoken/formatters/colorful_formatter'
require 'bwoken/formatters/junit_formatter'
require 'bwoken/script_runner'

module Bwoken
Expand Down Expand Up @@ -43,6 +45,7 @@ def self.help_banner
# :flags - custom build flag array (default: []) TODO: not yet implmented
# :focus - which tests to run (default: [], meaning "all")
# :formatter - custom formatter (default: 'colorful')
# :junit - create junit xml test results
# :scheme - custom scheme (default: nil)
# :simulator - should force simulator use (default: nil)
# :skip-build - do not build the iOS binary
Expand All @@ -54,8 +57,12 @@ def self.help_banner
def initialize opts
opts = opts.to_hash if opts.is_a?(Slop)
self.options = opts.to_hash.tap do |o|
o[:formatter] = 'passthru' if o[:verbose]
o[:formatter] = select_formatter(o[:formatter])
output_format_type = o[:verbose] ? 'passthru' : o[:formatter]
formatter = Bwoken::FanoutFormatter.new
formatter.add_recipient(select_formatter(output_format_type))
formatter.add_recipient(Bwoken::JUnitFormatter.new) if o[:junit]

o[:formatter] = formatter
o[:simulator] = use_simulator?(o[:simulator])
o[:family] = o[:family]
end
Expand Down
79 changes: 1 addition & 78 deletions lib/bwoken/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@ module Bwoken
class Formatter

class << self
def format stdout
new.format stdout
end

def format_build stdout
new.format_build stdout
end

def on name, &block
define_method "_on_#{name}_callback" do |*line|
block.call(*line)
instance_exec(*line, &block)
end
end

Expand All @@ -25,81 +17,12 @@ def method_missing(method_name, *args, &block)
end
end

def line_demuxer line, exit_status
if line =~ /Instruments Trace Error/
exit_status = 1
_on_fail_callback(line)
elsif line =~ /^\d{4}/
tokens = line.split(' ')

if tokens[3] =~ /Pass/
_on_pass_callback(line)
elsif tokens[3] =~ /Start/
_on_start_callback(line)
elsif tokens[3] =~ /Fail/ || line =~ /Script threw an uncaught JavaScript error/
exit_status = 1
_on_fail_callback(line)
elsif tokens[3] =~ /Error/
_on_error_callback(line)
else
_on_debug_callback(line)
end
elsif line =~ /Instruments Trace Complete/
_on_complete_callback(line)
else
_on_other_callback(line)
end
exit_status
end

%w(pass fail debug other).each do |log_level|
on log_level.to_sym do |line|
puts line
end
end

def format stdout
exit_status = 0

stdout.each_line do |line|
exit_status = line_demuxer line, exit_status
end

exit_status
end

def format_build stdout
out_string = ''
stdout.each_line do |line|
out_string << line
if line.length > 1
_on_build_line_callback(line)
end
end
out_string
end

on :before_build_start do
puts 'Building'
end

on :build_line do |line|
print '.'
end

on :build_successful do |build_log|
puts
puts
puts "### Build Successful ###"
puts
end

on :build_failed do |build_log, error_log|
puts build_log
puts "Standard Error:"
puts error_log
puts '## Build failed ##'
end

end
end
72 changes: 72 additions & 0 deletions lib/bwoken/formatters/fanout_formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require 'bwoken/formatters/line_demuxer'
module Bwoken

# Forwards any messages sent to this object to all recipients
# that respond to that message.
class FanoutFormatter < BasicObject
attr_reader :recipients
attr_reader :line_demuxer

def initialize(line_demuxer = LineDemuxer.new)
@recipients = []
@line_demuxer = line_demuxer
end

def add_recipient(recipient)
recipients << recipient
end

def format stdout
exit_status = 0

stdout.each_line do |line|
exit_status = @line_demuxer.demux(line, exit_status, recipients)
end

exit_status
end

def format_build stdout
out_string = ''
stdout.each_line do |line|
out_string << line
if line.length > 1
send_to_recipients('_on_build_line_callback', line)
end
end
out_string
end

def before_script_run(path)
send_to_recipients('_on_before_script_run_callback', path)
end

def after_script_run
send_to_recipients('_on_after_script_run_callback')
end

def before_build_start
send_to_recipients('_on_before_build_start_callback')
end

def build_successful(line)
send_to_recipients('_on_build_successful_callback', line)
end

def build_failed(build_log, error_log)
send_to_recipients('_on_build_failed_callback', *[build_log, error_log])
end

def send_to_recipients(message, *line)
message = message.to_sym
recipients.each do |recipient|
recipient.send(message, *line) if recipient.respond_to?(message)
end
end

def to_s

end
end

end
Loading