Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
aac68d2
Add logging to example app.Export log form iOS systems to easily disc…
paulstringer Aug 1, 2018
fc96c14
Add notes for platform differences related to Logging
paulstringer Aug 2, 2018
c688ee2
Add examples to OS X and iOS Fixtures with exanples matching differen…
paulstringer Aug 2, 2018
5fbc887
Refactor logging in Mac scripts
paulstringer Aug 2, 2018
204d2e7
Fix examples of stderror logs that trigger a fail of the build
paulstringer Aug 2, 2018
cc49160
Wrap os_log call in conditional to fix compile error
paulstringer Aug 2, 2018
cdabb34
Improve log messages OS X
paulstringer Aug 2, 2018
c32686b
Refactor logging message from test runner script
paulstringer Aug 2, 2018
6ae0668
Add write to log file for OS X platform for consistency with iOS
paulstringer Aug 3, 2018
4996609
Updates Logging platform docs in Fitnesse pages
paulstringer Aug 3, 2018
6e0e49b
xcpretty output on travis ci
paulstringer Aug 3, 2018
1812480
Fix travis config typo.Use travis xcpretty formatter
paulstringer Aug 3, 2018
bafa0cb
Wrap os.log on ios with ifavailable to fix build error on ci
paulstringer Aug 3, 2018
6ced29b
OSX NSLog statements are now supportedTidy documentation on logging
paulstringer Aug 4, 2018
ab40a61
- Do not delete logs if empty.- Ensure logs are not empty by always o…
paulstringer Aug 7, 2018
421a587
Add shell script to group logging to file utilities
paulstringer Aug 12, 2018
a3db1fc
Adds Bash Assert Repo\n Create new-log-file command
paulstringer Aug 22, 2018
8c686ea
Generated logfile name not uniqued
paulstringer Aug 22, 2018
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
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ podfile: Example/Podfile
osx_image: xcode9
before_install:
- gem install cocoapods # Since Travis is not always on latest version

- gem install xcpretty-travis-formatter # Tidy up Xcode Logs to make it easier to read when the build fails
script:
# OCSlimProject Example Acceptance Tests (iOS, macOS)
- set -o pipefail && xcodebuild -workspace Example/OCSlimProject.xcworkspace -scheme OCSlimProject_Example -destination 'platform=iOS Simulator,name=iPhone X' -destination-timeout 300 test
- set -o pipefail && xcodebuild -workspace Example/OCSlimProject.xcworkspace -scheme OCSlimProject_ExampleMac test
- set -o pipefail && xcodebuild -workspace Example/OCSlimProject.xcworkspace -scheme OCSlimProject_Example -destination 'platform=iOS Simulator,name=iPhone X' -destination-timeout 300 test | xcpretty -f `xcpretty-travis-formatter`
- set -o pipefail && xcodebuild -workspace Example/OCSlimProject.xcworkspace -scheme OCSlimProject_ExampleMac test | xcpretty -f `xcpretty-travis-formatter`
# OCSlimProjectTestBundleSupport Pod Unit Tests (iOS, macOS)
- set -o pipefail && xcodebuild -workspace Example/OCSlimProject.xcworkspace -scheme OCSlimProjectTestBundleSupportTests -destination 'platform=iOS Simulator,name=iPhone X' test
- set -o pipefail && xcodebuild -workspace Example/OCSlimProject.xcworkspace -scheme OCSlimProjectTestBundleSupportTestsMac test
- set -o pipefail && xcodebuild -workspace Example/OCSlimProject.xcworkspace -scheme OCSlimProjectTestBundleSupportTests -destination 'platform=iOS Simulator,name=iPhone X' test | xcpretty -f `xcpretty-travis-formatter`
- set -o pipefail && xcodebuild -workspace Example/OCSlimProject.xcworkspace -scheme OCSlimProjectTestBundleSupportTestsMac test | xcpretty -f `xcpretty-travis-formatter`
# Pod Lib Lint (unavailable on xcode 8)
#- pod lib lint OCSlimProject.podspec --allow-warnings
#- pod lib lint OCSlimProjectTestBundleSupport.podspec --use-libraries --allow-warnings
4 changes: 2 additions & 2 deletions Example/OCSlimProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
INFOPLIST_FILE = OCSlimProject_AcceptanceTestsMac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.12;
PRODUCT_BUNDLE_IDENTIFIER = "net.stringerstheory.OCSlimProject-AcceptanceTestsMac";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
Expand All @@ -1441,7 +1441,7 @@
CODE_SIGN_IDENTITY = "-";
INFOPLIST_FILE = OCSlimProject_AcceptanceTestsMac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.12;
PRODUCT_BUNDLE_IDENTIFIER = "net.stringerstheory.OCSlimProject-AcceptanceTestsMac";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
Expand Down
30 changes: 27 additions & 3 deletions Example/OCSlimProject_AcceptanceTests/FixtureExample.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation

import os.log
@objc(FixtureExample)

class FixtureExample : NSObject, SlimDecisionTable {
Expand All @@ -16,7 +16,7 @@ class FixtureExample : NSObject, SlimDecisionTable {
// 2. Run your SUT
// 3. Take values from the SUT and return via outputs
}

//MARK: Outputs

var output: NSString? {
Expand All @@ -31,5 +31,29 @@ class FixtureExample : NSObject, SlimDecisionTable {
}
}
}


//MARK: Calling Methods

func log() -> Bool {

// Only prints to a running Xcode console

print("*WARNING* Swift's print function on iOS only print to the Xcode console not to logs.")

// Use NSLog to print to the system log as a default message type

NSLog("NSLog() statement")

// Use os_log to print to the system log with related type (recommended)

if #available(iOS 10.0, *) {
os_log("os_log() .default log statement", type: .default)
os_log("os_log() .info log statement", type: .info)
os_log("os_log() .error log statement", type: .error)
}

return true
}

}
}
21 changes: 20 additions & 1 deletion Example/OCSlimProject_AcceptanceTestsMac/FixtureExample.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import os.log

@objc(FixtureExample)

Expand Down Expand Up @@ -31,5 +32,23 @@ class FixtureExample : NSObject, SlimDecisionTable {
}
}
}

//MARK: Calling Methods

func log() -> Bool {

// Logging Examples

print("Swift print() (OSX only)")
NSLog("NSLog() statement (recommended)")

// os_log is unsupported

if #available(OSX 10.12, *) {
os_log("*WARNING* os_log() statements such as this one are not captured on OS X")
}

return true
}

}
}
72 changes: 63 additions & 9 deletions Pod/Support/OSX/RunTestsTargetWithSlimPort
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,73 @@
source $1
ENVIRONMENT_SRC=$1
SLIM_PORT=$2
APPLICATION_PATH=${TARGET_BUILD_DIR}/${EXECUTABLE_PATH}
EXECUTABLE_PATH=${TARGET_BUILD_DIR}/${EXECUTABLE_PATH}
APP_PATH=${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app

run_test_system() {
echo "Test System Executable Folder Path: $APPLICATION_PATH"
$APPLICATION_PATH $SLIM_PORT
return $?
}
# Main Subroutines

main() {
echo "== OCSlimProject: RunSlimTestTargetWithSlimPort~OSX:$SLIM_PORT =="
echo "Test System Executable Environment: $ENVIRONMENT_SRC"
log "RunSlimTestTargetWithSlimPort~macOSX"
log "Fitnesse Slim Port: $SLIM_PORT"
log "Xcode Build Product $APP_PATH"
run_test_system
exit $?
}

main
run_test_system() {

local LOGFILE=$(get_log_file_path)
launch_osx_app $LOGFILE
write_logs_to_console $LOGFILE
return $?
}

launch_osx_app() {
log "Launching '${PRODUCT_NAME}.app'"
local LOGFILE=$1
log "macOS System log started" > $LOGFILE
$EXECUTABLE_PATH $SLIM_PORT >> $LOGFILE 2>&1
log "macOS System log ended" >> $LOGFILE
}

## Logging Subroutines

write_logs_to_console() {
local LOGFILE=$1
log "Reading log file: $LOGFILE"
cat $LOGFILE
}

get_log_file_path() {
local LOGDIR="Logs"
local LOGPATH="$(pwd)/$LOGDIR"
local LOGFILENAME="$(date +%Y%m%d-%H%M%S).log"
local LOGFILE="$LOGPATH/$LOGFILENAME"
mkdir -p $LOGPATH
echo $LOGFILE
}

tidy_zero_line_app_log_file(){
Copy link
Copy Markdown
Collaborator

@mabidakun mabidakun Aug 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary.
The log should always contain something (e.g. start_slim() would write something), no?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logs now always generate some head and tail output. Files not deleted 👍

# Check number of lines in logfile before returning a log file
if [ ! $(grep -c '' $1) ]; then
rm $1
return 0
else
return 1
fi
}

# Logging Subroutined

log() {
echo "[OCSP_RUN] INFO: $1"
}

error() {
>&2 echo "[OCSP_RUN] ERROR: $1"
exit 1
}

# Main Routine

main
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
!1 OCSlimProject Example Test Page

Below is a simple Decision Table based Acceptance Test. It sends input to an instance of a Fixture which is implemented in your Xcode project. This is done by adding a class of the same name e.g. 'FixtureExample.swift' to your Acceptance Test target.
Below is a simple Decision Table based Acceptance Test. It sends input to an instance of a Fixture which is implemented in your Xcode project. This is done by adding a class of the same name e.g. 'FixtureExample.swift' to your Acceptance Test target.
Copy link
Copy Markdown
Collaborator

@mabidakun mabidakun Aug 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great introductory comment to re-inforce information that is hard to grok if you don't really understand how it all works.


The first column 'input' will set a property of the same name. The expected 'output?' denoted by columns with '?' at the end of the property name are returned by your Fixture and verified against the expected value in that column.

Click 'Test' to run this page and see this in action. After that check out ''!-FixtureExample.swift-!'' in your Xcode project to see the 'FixtureExample.swift' implementation.

|Fixture Example|
|input |output? |
|foo |bar |
|bar |baz |
!2 Simple Decision Table Example
| Fixture Example |
| input | output? |
| foo | bar |
| bar | baz |

!2 Logging Example
| script | Fixture Example |
| ensure | log |

!3 Logging

* Find log files for each test run in the current directory ./Logs/<DATE>.log.
* Log statements are reported in the 'Execution Log' (see the button after running a test located in the top right navigation).
* Test runs that generate no log statements will not generate a log file.

!4 iOS:
* NSLog()
* os_log()
* print() does not work!

!4 macOS X:
* NSLog()
* print()
* os_log() does not work!
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ ERROR_LOG_FILE=%s
$TEST_RUNNER_SCRIPT $ENV_FILE_PATH $SLIM_PORT 2> >(tee $ERROR_LOG_FILE >&2)

ERROR_LOG_NO_WHITESPACE=$(more "$ERROR_LOG_FILE" | sed 's/ *$//')


log() {
echo "[OCSP_RUN] INFO: $1"
}

error() {
>&2 echo "[OCSP_RUN] ERROR: $1"
exit 1
}

if [ -z "$ERROR_LOG_NO_WHITESPACE" ]; then
rm $ERROR_LOG_FILE
echo "[OCSP_RUN] Slim Test System Exited Normally"
log "Slim Test System Exited OK"
exit 0
else
echo "[OCSP_RUN] Slim Test System Exited Abnormally With Reported Errors"
error "Slim Test System Exited Abnormally With Reported Errors"
fi
20 changes: 20 additions & 0 deletions Pod/Support/SharedSupport/ocsp-logger-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
source '../../../assert.sh/assert.sh'

LOGPATH=$(./ocsp-logger.sh new-log-file)
LOGBASENAME=$(basename $LOGPATH)
LOGDIR=$(dirname $LOGPATH)

assert_not_empty "$LOGPATH"
[ "$?" == 1 ] && log_failure "new-log-file should not be empty"

test -d "$LOGDIR"
assert_eq 0 $?
[ "$?" == 1 ] && log_failure "new-log-file '$LOGDIR' is not a valid directory"

expected="slim_system.log"
assert_eq "$LOGBASENAME" "$expected"
[ "$?" == 1 ] && log_failure "new-log-file '$LOGBASENAME' is not the expected '$expected' filename"



18 changes: 18 additions & 0 deletions Pod/Support/SharedSupport/ocsp-logger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

ACTION=LOG_PATH

function main() {

if [ "$ACTION" == "LOG_PATH" ]; then
local LOGDIR="Logs"
local LOGPATH="$(pwd)/$LOGDIR"
local LOGFILENAME="slim_system.log"
local LOGFILE="$LOGPATH/$LOGFILENAME"
mkdir -p $LOGPATH
echo "$LOGFILE"
fi

}

main
61 changes: 44 additions & 17 deletions Pod/Support/iOS/RunTestsTargetWithSlimPort
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,69 @@ get_app_devicetypeid() {
slim_system_wait() {

local EXECUTABLE_PID=$(<.simctl.pid)

log "Waiting for Slim System... ($EXECUTABLE_PID) $(date)"

while ps -p $EXECUTABLE_PID
local INTERVAL=1
local COUNT=0

log_hrule
log "Waiting for System Under Test... (ProcessID: $EXECUTABLE_PID)";
while ps -p $EXECUTABLE_PID > /dev/null
do
sleep 1
sleep $INTERVAL;
((COUNT++))
done

log "Slim System Exited $(date)"
log "System Under Test exited (running for $COUNT second(s))"
}

run_test_system() {
log "Start Slim Test Sytem"
$MYPATH/simctl $APPLICATION_PATH $SLIM_PORT

local START_TIME=$(date '+%Y-%m-%d %H:%M:%S')
start_slim

if [ $? == 0 ]; then
slim_system_wait;
slim_system_wait
print_test_system_log $START_TIME
else
log "**ABORTING** For details click the red/green 'Execution Log' button in Fitnesse to view stdout and stderr logs"
error "**ABORTING** Exit Code error detected when executing Slim Test Sytem with ($MYPATH/simctl)"
log_simctl_error
fi
}

start_slim() {
log "Starting System Under Test"
log_hrule
$MYPATH/simctl $APPLICATION_PATH $SLIM_PORT
}

print_test_system_log() {
local STARTTIME=$1
local LOGFILE=$($MYPATH/simctl log $STARTTIME)
log "Reading log file: $LOGFILE"
cat $LOGFILE
}

log_simctl_error() {
log "**ABORTING** Slim Test System reported an error. Check the executiong log for more details"
error "**ABORTING** Exit Code error detected when executing Slim Test Sytem with ($MYPATH/simctl)"
}

main() {
log "== RunSlimTestTargetWithSlimPort~iOS:$SLIM_PORT $(date)=="
log "Info: Test System Suggested SDK: $DEPLOYMENT_TARGET_VALUE"
log "Info: Test System Path: $APPLICATION_PATH"
log "RunSlimTestTargetWithSlimPort~iOS"
log "Fitnesse Slim Port: $SLIM_PORT"
log "Xcode Suggested SDK: $DEPLOYMENT_TARGET_VALUE"
log "Xcode Build Product: $APPLICATION_PATH"
run_test_system
exit $?
}

log() {
echo "[OCSP_RUN] $1"
echo "[OCSP_RUN] INFO: $1"
}

log_hrule() {
log "------------------------------------------------"
}

error() {
>&2 echo "[OCSP_RUN] $1"
>&2 echo "[OCSP_RUN] ERROR: $1"
exit 1
}

Expand Down
Loading