Skip to content

Commit

Permalink
Project: Stop using xctool, use xcpretty to make xcodebuild output ni…
Browse files Browse the repository at this point in the history
…ce instead.
  • Loading branch information
russellhancox committed Apr 10, 2015
1 parent 0a51146 commit 460dd6a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 69 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
language: objective-c

before_install:
- gem install cocoapods
- brew update
- brew upgrade xctool
- gem install cocoapods xcpretty

script:
- xctool -workspace Santa.xcworkspace -scheme All build test CODE_SIGN_IDENTITY=''
- xcodebuild -workspace Santa.xcworkspace -scheme All build test CODE_SIGN_IDENTITY='' | xcpretty -sc && exit ${PIPESTATUS[0]}
67 changes: 20 additions & 47 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,24 @@
require 'timeout'

WORKSPACE = 'Santa.xcworkspace'
DEFAULT_SCHEME = 'All'
OUTPUT_PATH = 'Build'
DIST_PATH = 'Dist'
BINARIES = ['Santa.app', 'santa-driver.kext', 'santad', 'santactl']
XCTOOL_DEFAULTS = "-workspace #{WORKSPACE}"
XCODE_DEFAULTS = "-workspace #{WORKSPACE} -derivedDataPath #{OUTPUT_PATH} -parallelizeTargets"
WORKSPACE = 'Santa.xcworkspace'
DEFAULT_SCHEME = 'All'
OUTPUT_PATH = 'Build'
DIST_PATH = 'Dist'
BINARIES = ['Santa.app', 'santa-driver.kext', 'santad', 'santactl']
XCPRETTY_DEFAULTS = '-sc'
XCODEBUILD_DEFAULTS = "-workspace #{WORKSPACE} -derivedDataPath #{OUTPUT_PATH} -parallelizeTargets"

task :default do
system("rake -sT")
end

def xctool_available
return system 'xctool --version >/dev/null 2>&1'
end

def run_and_output_on_fail(cmd)
output=`#{cmd} 2>&1`
if not $?.success?
raise output
end
end

def run_and_output_with_color(cmd)
output=`#{cmd} 2>&1`

has_output = false
output.scan(/((Test Suite|Test Case|Executed).*)$/) do |match|
has_output = true
out = match[0]
if out.include?("passed")
puts "\e[32m#{out}\e[0m"
elsif out.include?("failed")
puts "\e[31m#{out}\e[0m"
else
puts out
end
end

if not has_output
raise output
def xcodebuild(opts)
if system "xcodebuild #{XCODEBUILD_DEFAULTS} #{opts} | " \
"xcpretty #{XCPRETTY_DEFAULTS} && " \
"exit ${PIPESTATUS[0]}"
puts "\e[32mPass\e[0m"
else
raise "\e[31mFail\e[0m"
end
end

Expand All @@ -49,6 +27,9 @@ task :init do
puts "Pods missing, running 'pod install'"
system "pod install" or raise "CocoaPods is not installed. Install with 'sudo gem install cocoapods'"
end
unless system 'xcpretty -v >/dev/null 2>&1'
puts "xcpretty is not installed. Install with 'sudo gem install xcpretty'"
end
end

task :remove_existing do
Expand All @@ -61,7 +42,7 @@ end
desc "Clean"
task :clean => :init do
puts "Cleaning"
system "xcodebuild #{XCODE_DEFAULTS} -scheme All clean"
xcodebuild("-scheme All clean")
FileUtils.rm_rf(OUTPUT_PATH)
FileUtils.rm_rf(DIST_PATH)
end
Expand All @@ -81,11 +62,7 @@ namespace :build do
task :build, [:configuration] => :init do |t, args|
config = args[:configuration]
puts "Building with configuration: #{config}"
if xctool_available
system "xctool #{XCTOOL_DEFAULTS} -scheme All -configuration #{config} build"
else
system "xcodebuild #{XCODE_DEFAULTS} -scheme All -configuration #{config} build"
end
xcodebuild("-scheme All -configuration #{config} build")
end
end

Expand Down Expand Up @@ -145,11 +122,7 @@ namespace :tests do
desc "Tests: Logic"
task :logic => [:init] do
puts "Running logic tests"
if xctool_available
system "xctool #{XCTOOL_DEFAULTS} -scheme LogicTests test"
else
system "xcodebuild #{XCODE_DEFAULTS} -scheme LogicTests test"
end
xcodebuild("-scheme LogicTests test")
end

desc "Tests: Kernel"
Expand Down
18 changes: 0 additions & 18 deletions Tests/LogicTests/SNTFileWatcherTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,6 @@ @interface SNTFileWatcherTest : XCTestCase

@implementation SNTFileWatcherTest

static int unusedFd1 = -1;
static int unusedFd2 = -1;

+ (void)setUp {
// xctest redirects the stdout/stderr FDs when starting tests. This is not a problem, except
// xctool intercepts stdout/stderr FDs (1 & 2) to put them in nice sections of the output.
// This causes problems with tests that write to files and is 'fixed' by opening two FDs just
// to be safe. Unfortunately this means that anything printed (e.g. with printf or NSLog) will
// not actually be printed in xctool output for this test suite, ho hum.
unusedFd1 = open("/dev/null", O_WRONLY);
unusedFd2 = open("/dev/null", O_WRONLY);
}

+ (void)tearDown {
close(unusedFd1);
close(unusedFd2);
}

- (void)setUp {
[super setUp];

Expand Down

0 comments on commit 460dd6a

Please sign in to comment.