The post Compiling Objective-C without GUI says the following:
To compile Objective-C on OSX the easy way you have to get XCode, which is free to obtain from the Application Store. Getting XCode will ensure you obtain the necessary frameworks (headers), like Foundation, Cocoa, etc. This will, however, not provide you with the necessary command line tools to compile Object-C from the command line. Open up XCode, go to Preference > Downloads > Components and Install Command Line Tools. This will install gcc, clang, make, etc.
I am looking for a non-Xcode-based tool to address this my question, I've just opened: Is it possible to make an Objective-C project to be tested on Travis?
This tool should meet the following requirements:
- It should be not related to Xcode in any way.
- The following level of simplicity is pretty enough: just some
int main {}
code collecting all test-cases files nearby and running test assertions on the code I want to test (likeST-
in SetTestingKit orGH-
in GHUnit) - I don't need UI, GUI, Xcode, simulator.
- It will be great if it could work both on Mac and Ubuntu (yeah, Travis), possibly using GNUstep like the quoted post describes.
UPDATE BASED ON ACCEPTED ANSWER:
The following simple setup, based on what Malte Tancred have said in the accepted answer, seems pretty enough for my current needs:
Three files, all in the tests directory of my project:
octest.m
#import <Foundation/Foundation.h>
#import <SenTestingKit/SenTestingKit.h>
int main() {
@autoreleasepool {
SenSelfTestMain();
}
return 0;
}
Makefile
CC=clang # or gcc
# Trick to get current dir: https://stackoverflow.com/questions/322936/common-gnu-makefile-directory-path
TESTS_DIR:= $(dir $(lastword $(MAKEFILE_LIST)))
PROJECT_DIR:= $(TESTS_DIR)/..
FRAMEWORKS_PATH:= -F/Applications/Xcode.app/Contents/Developer/Library/Frameworks
FRAMEWORKS:= -framework Foundation -framework SenTestingKit
LIBRARIES:= -lobjc
INCLUDE_PATHS:= -I$(PROJECT_DIR)/Projectfiles\
-I$(TESTS_DIR)/TestHelpers
SOURCE_FILES = $(wildcard $(PROJECT_DIR)/Projectfiles/*.m)
SOURCE_TEST_SUITE = $(wildcard $(TESTS_DIR)/Tests/*.m)
SOURCE_TESTS = $(TESTS_DIR)/TestHelpers/TestHelpers.m\
octest.m
CFLAGS=-Wall -Werror -fobjc-arc -g -v $(SOURCE_FILES) $(SOURCE_TEST_SUITE) $(SOURCE_TESTS)
LDFLAGS=$(LIBRARIES) $(FRAMEWORKS)
OUT=-o octest
all:
$(CC) $(FRAMEWORKS_PATH) $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(OUT)
runtests
#!/bin/bash
export DYLD_FRAMEWORK_PATH=/Applications/Xcode.app/Contents/Developer/Library/Frameworks
make
./octest
UPDATE TO CAPTURE EXIT CODE:
A few days after I had asked this question, Travis announced Objective-C support:
http://about.travis-ci.org/blog/introducing-mac-ios-rubymotion-testing/
Though there are default scripts they suggest to use to make builds, I have decided to take the approach described here and still use octest instead of approach with xcodebuild that Travis uses.
By default travis setup relies on the build scripts written by Justin Spahr-Summers: https://github.com/jspahrsummers/objc-build-scripts:
They use awk to capture exit code from xcodebuild's output, since it always exists with 0 exit code, even if the whole test suite has failing!
OCTest behaves the same way - it always exists with 0 code, and here is how I've used simplified version of Travis awk script for my needs of building it the way I decribed above:
octest.awk
# Exit statuses:
#
# 0 - No errors found.
# 1 - Build or test failure. Errors will be logged automatically.
BEGIN {
status = 0;
}
{
print;
fflush(stdout);
}
/[0-9]+: (error|warning):/ {
errors = errors $0 "\n";
}
/with [1-9]+ failures?/ {
status = 1;
}
END {
if (length(errors) > 0) {
print "\n*** All errors:\n" errors;
}
fflush(stdout);
exit status;
}
runtests
#!/bin/bash
export DYLD_FRAMEWORK_PATH=/Applications/Xcode.app/Contents/Developer/Library/Frameworks
make
runtests ()
{
./octest 2>&1 | awk -f "octest.awk"
local awkstatus=$?
if [ "$awkstatus" -eq "1" ]
then
echo "Test suite failed"
return $awkstatus
else
echo "Test suite passed"
return 0
fi
}
echo "*** Building..."
runtests || exit $?