Skip to content

Commit 89b3bd3

Browse files
Merge pull request #3 from SomeRandomiOSDev/UnitTests
Added Unit Tests
2 parents 7fc4be1 + 15800f3 commit 89b3bd3

File tree

12 files changed

+407
-48
lines changed

12 files changed

+407
-48
lines changed

.github/workflows/unittests.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Unit Tests
2+
on: [push, workflow_dispatch]
3+
4+
jobs:
5+
test:
6+
name: Test
7+
runs-on: macOS-11
8+
9+
steps:
10+
- name: Checkout Code
11+
uses: actions/checkout@v2
12+
13+
- name: Run Tests
14+
run: |
15+
./scripts/unittests.sh

scripts/carthage.sh

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,8 @@
55
# carthage.sh
66
# Usage example: ./carthage.sh build --platform iOS
77

8-
function compare_versions() {
9-
if [ $1 = $2 ]; then
10-
return 0
11-
fi
12-
13-
local IFS=.
14-
local i LHS=($1) RHS=($2)
15-
16-
for ((i=${#LHS[@]}; i<${#RHS[@]}; i++)); do
17-
LHS[i]=0
18-
done
19-
20-
for ((i=0; i<${#LHS[@]}; i++)); do
21-
if [ -z ${RHS[i]} ]; then
22-
RHS[i]=0
23-
fi
24-
25-
if ((10#${LHS[i]} > 10#${RHS[i]})); then
26-
return 1
27-
elif ((10#${LHS[i]} < 10#${RHS[i]})); then
28-
return -1
29-
fi
30-
done
31-
32-
return 0
33-
}
34-
35-
VERSION=`carthage version`
36-
compare_versions "$VERSION" "0.37.0"
8+
VERSION="$(carthage version)"
9+
"$(dirname "$0")/versions.sh" "$VERSION" "0.37.0"
3710

3811
if [ $? -ge 0 ]; then
3912
# Carthage version is greater than or equal to 0.37.0 meaning we can use the --use-xcframeworks flag

scripts/config.sh

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
# config.sh
44
# Usage example: ./config.sh -name <project_name> [-test] [-verbose]
55

6+
# Set Script Variables
7+
8+
SCRIPT="$(realpath $0)"
9+
SCRIPTS="$(basename "$SCRIPT")"
10+
ROOT_DIR="$(dirname "$(dirname "$SCRIPT")")"
11+
612
# Help
713

814
function print_help() {
9-
echo "./config.sh -name <project_name> [-help] [-test] [-verbose]"
15+
echo "./config.sh -name <project_name> [-output <output_folder>] [-help] [-test] [-verbose]"
1016
exit 1
1117
}
1218

@@ -20,6 +26,12 @@ while [[ $# -gt 0 ]]; do
2026
shift # <project_name>
2127
;;
2228

29+
-output)
30+
OUTPUT_DIR="$2"
31+
shift # -output
32+
shift # <output_folder>
33+
;;
34+
2335
-help)
2436
print_help
2537
;;
@@ -46,10 +58,9 @@ if [ -z ${PROJECT_NAME+x} ]; then
4658
print_help
4759
fi
4860

49-
# Set Script Variables
50-
51-
SCRIPT="$(realpath $0)"
52-
ROOT_DIR="$(dirname "$(dirname "$SCRIPT")")"
61+
if [ -z ${OUTPUT_DIR+x} ]; then
62+
OUTPUT_DIR="$(dirname "$ROOT_DIR")"
63+
fi
5364

5465
# Initialize Environment Variables
5566

@@ -93,27 +104,32 @@ function setup_git() {
93104

94105
# Copy Project Template
95106

96-
if [ "$(basename "$ROOT_DIR")" != "${PROJECT_NAME}" ]; then
97-
if [ -e "$(dirname "$ROOT_DIR")/$PROJECT_NAME" ]; then
98-
echo "Destination project folder already exits: \"$(dirname "$ROOT_DIR")/$PROJECT_NAME\""
99-
exit 1
100-
elif [ "$VERBOSE" = "1" ]; then
101-
echo "Copying \"$ROOT_DIR\" to \"$(dirname "$ROOT_DIR")/$PROJECT_NAME\""
107+
if [ ! -e "$OUTPUT_DIR/$PROJECT_NAME" ]; then
108+
if [ "$VERBOSE" = "1" ]; then
109+
echo "Copying \"$ROOT_DIR\" to \"$OUTPUT_DIR/$PROJECT_NAME\""
102110
fi
103111

104-
cp -R "$ROOT_DIR" "$(dirname "$ROOT_DIR")/$PROJECT_NAME"
112+
mkdir "$OUTPUT_DIR/$PROJECT_NAME"
113+
cp -R "${ROOT_DIR%/}/" "$OUTPUT_DIR/$PROJECT_NAME"
105114

106-
ROOT_DIR="$(dirname "$ROOT_DIR")/$PROJECT_NAME"
107-
SCRIPT="$ROOT_DIR/$(basename "$(dirname "$SCRIPT")")/$(basename "$SCRIPT")"
115+
ROOT_DIR="$OUTPUT_DIR/$PROJECT_NAME"
116+
SCRIPT="$ROOT_DIR/$SCRIPTS/$(basename "$SCRIPT")"
108117

109118
rm -f "$SCRIPT"
110-
rm -f "$(dirname "$SCRIPT")/env.sh"
119+
rm -f "$ROOT_DIR/$SCRIPTS/env.sh"
120+
rm -f "$ROOT_DIR/$SCRIPTS/unittests.sh"
111121
rm -f "$ROOT_DIR/README.md"
112122
rm -rf "$ROOT_DIR/.git"
113123

124+
rm -rf "$ROOT_DIR/.github/workflows"
125+
mv "$ROOT_DIR/workflows" "$ROOT_DIR/.github/workflows"
126+
114127
find "$ROOT_DIR" -regex ".*\.gitkeep" -delete
115128

116129
setup_git "$ROOT_DIR"
130+
else
131+
echo "Destination project folder already exits: \"$OUTPUT_DIR/$PROJECT_NAME\""
132+
exit 1
117133
fi
118134

119135
# Rename files with placeholders

scripts/unittests.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env ruby
2+
3+
# Imports
4+
5+
require 'xcodeproj'
6+
7+
# Local Variables
8+
9+
project_path = ARGV[0]
10+
project_name = File.basename(project_path, ".xcodeproj")
11+
project = Xcodeproj::Project.open(project_path)
12+
13+
source_file = ARGV[1]
14+
test_file = ARGV[2]
15+
16+
# Add Files
17+
18+
top_group = project.groups.find { |group| group.name == project_name }
19+
sources_group = top_group.groups.find { |group| File.basename(group.path) == "Sources" }.groups.find { |group| File.basename(group.path) == project_name }
20+
tests_group = top_group.groups.find { |group| File.basename(group.path) == "Tests" }.groups.find { |group| File.basename(group.path) == "#{project_name}Tests" }
21+
22+
source_file_ref = sources_group.new_file(source_file)
23+
test_file_ref = tests_group.new_file(test_file)
24+
25+
project.native_targets.each do |target|
26+
if target.test_target_type?
27+
target.source_build_phase.add_file_reference(test_file_ref)
28+
else
29+
target.source_build_phase.add_file_reference(source_file_ref)
30+
end
31+
end
32+
33+
project.save()

0 commit comments

Comments
 (0)