guardian-angel 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/xctestfile +2 -2
- data/lib/ga_configuration.rb +7 -21
- data/lib/ga_loader.rb +38 -50
- data/lib/ga_logger.rb +4 -2
- data/lib/ga_runner.rb +17 -12
- data/lib/xctool_runner.rb +1 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa1d8955513a660d1b1d388fd12325528fa3f392
|
4
|
+
data.tar.gz: a4cf0ea6e13f48e6bdc59dd79d6146cbca6447c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a091afeeb1b9a16f63df72fe85a19ed1f119371dfef0a48ecc500da3cf59db2d7565bcd7d1d89591ce97f69a90fa03aab44c08d6b1cab6d78efcdebf2517203
|
7
|
+
data.tar.gz: 0e6e83763a3f99afb4a1d64b75faea84661d35a6724b28d9b2c78f1892956fb5979b5ad891156f2db846540ff012210db381c4cbb821aded36521235a8685f7d
|
data/bin/xctestfile
CHANGED
@@ -5,8 +5,8 @@ require 'ga_runner'
|
|
5
5
|
|
6
6
|
trap("INT") { exit }
|
7
7
|
|
8
|
-
fileToTest = GALoader.
|
9
|
-
configuration = GALoader.readConfiguration()
|
8
|
+
fileToTest = GALoader.getFileFromArray(ARGV)
|
9
|
+
configuration = GALoader.readConfiguration(silent = true)
|
10
10
|
|
11
11
|
runner = GARunner.new(configuration, fileToTest)
|
12
12
|
runner.test()
|
data/lib/ga_configuration.rb
CHANGED
@@ -98,27 +98,13 @@ class GAConfiguration
|
|
98
98
|
# @param other [GAConfiguration] another instance of GAConfiguration you want to merge
|
99
99
|
# @note nil values will not overwrite valid values of self
|
100
100
|
def merge(other)
|
101
|
-
unless other.scheme.nil?
|
102
|
-
|
103
|
-
|
104
|
-
unless other.
|
105
|
-
|
106
|
-
|
107
|
-
unless other.
|
108
|
-
@target = other.target
|
109
|
-
end
|
110
|
-
unless other.suffix.nil?
|
111
|
-
@suffix = other.suffix
|
112
|
-
end
|
113
|
-
unless other.reporter.nil?
|
114
|
-
@reporter = other.reporter
|
115
|
-
end
|
116
|
-
unless other.xctool_path.nil?
|
117
|
-
@xctool_path = other.xctool_path
|
118
|
-
end
|
119
|
-
unless other.project.nil?
|
120
|
-
@project = other.project
|
121
|
-
end
|
101
|
+
@scheme = other.scheme unless other.scheme.nil?
|
102
|
+
@workspace = other.workspace unless other.workspace.nil?
|
103
|
+
@target = other.target unless other.target.nil?
|
104
|
+
@suffix = other.suffix unless other.suffix.nil?
|
105
|
+
@reporter = other.reporter unless other.reporter.nil?
|
106
|
+
@xctool_path = other.xctool_path unless other.xctool_path.nil?
|
107
|
+
@project = other.project unless other.project.nil?
|
122
108
|
|
123
109
|
return self
|
124
110
|
end
|
data/lib/ga_loader.rb
CHANGED
@@ -11,7 +11,7 @@ class GALoader
|
|
11
11
|
# @note if the file is not found, it will try to build with default values instead
|
12
12
|
# @note this also outputs the final GAConfiguration built on the console
|
13
13
|
# (see #GAConfiguration)
|
14
|
-
def self.readConfiguration()
|
14
|
+
def self.readConfiguration(silent = false)
|
15
15
|
configuration = GAConfiguration.new
|
16
16
|
|
17
17
|
begin
|
@@ -19,11 +19,11 @@ class GALoader
|
|
19
19
|
configurationMerge = GAConfiguration.new(jsonDictionary)
|
20
20
|
configuration = configuration.merge(configurationMerge)
|
21
21
|
rescue
|
22
|
-
GALogger.log("#{CONFIG_FILENAME} not found, using defaults", :Warning)
|
22
|
+
GALogger.log("#{CONFIG_FILENAME} not found or not a valid JSON, using defaults", :Warning) unless silent
|
23
23
|
end
|
24
24
|
|
25
25
|
validateConfiguration(configuration)
|
26
|
-
outputConfiguration(configuration)
|
26
|
+
outputConfiguration(configuration) unless silent
|
27
27
|
|
28
28
|
return configuration
|
29
29
|
end
|
@@ -32,20 +32,25 @@ class GALoader
|
|
32
32
|
#
|
33
33
|
# @note this searches only in the top level directory
|
34
34
|
def self.findWorkspace
|
35
|
-
|
36
|
-
return nil if workspace.empty?
|
37
|
-
|
38
|
-
return File.basename(workspace, ".*")
|
35
|
+
return findFile("xcworkspace")
|
39
36
|
end
|
40
37
|
|
41
38
|
# Returns a possible project, in case one is not provided in the configuration
|
42
39
|
#
|
43
40
|
# @note this searches only in the top level directory
|
44
41
|
def self.findProject
|
45
|
-
|
46
|
-
|
42
|
+
return findFile("xcodeproj")
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns the first file with the given extension
|
46
|
+
#
|
47
|
+
# @param extension [String] the file extension you want to search
|
48
|
+
# @return nil if no file is found, the first file with the given extension otherwise
|
49
|
+
def self.findFile(extension)
|
50
|
+
files = Dir.glob("*.#{extension}")
|
51
|
+
return nil if files.empty?
|
47
52
|
|
48
|
-
return File.basename(
|
53
|
+
return File.basename(files.first, ".*")
|
49
54
|
end
|
50
55
|
|
51
56
|
# Validates a given configuration
|
@@ -60,17 +65,17 @@ class GALoader
|
|
60
65
|
possibleWorkspace = findWorkspace()
|
61
66
|
|
62
67
|
if !possibleWorkspace
|
63
|
-
|
68
|
+
possibleProject = configuration.project
|
69
|
+
if possibleProject.nil?
|
64
70
|
possibleProject = findProject()
|
65
71
|
|
66
72
|
if !possibleProject
|
67
|
-
GALogger.log("workspace or project was not specified, exiting", :Error)
|
68
|
-
outputSampleConfiguration()
|
69
|
-
abort
|
70
|
-
else
|
71
|
-
configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationProject => possibleProject)
|
73
|
+
GALogger.log("workspace or project was not specified and cannot be found, exiting", :Error)
|
74
|
+
outputSampleConfiguration(eventuallyAbort = true)
|
72
75
|
end
|
73
76
|
end
|
77
|
+
|
78
|
+
configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationProject => possibleProject)
|
74
79
|
else
|
75
80
|
configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationWorkspace => possibleWorkspace)
|
76
81
|
end
|
@@ -79,8 +84,6 @@ class GALoader
|
|
79
84
|
end
|
80
85
|
|
81
86
|
if configuration.scheme.nil?
|
82
|
-
configurationMerge = nil
|
83
|
-
|
84
87
|
unless configuration.project.nil?
|
85
88
|
configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationScheme => configuration.project)
|
86
89
|
end
|
@@ -88,29 +91,12 @@ class GALoader
|
|
88
91
|
configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationScheme => configuration.workspace)
|
89
92
|
end
|
90
93
|
|
91
|
-
|
92
|
-
GALogger.log("scheme was not specified, exiting", :Error)
|
93
|
-
outputSampleConfiguration()
|
94
|
-
abort
|
95
|
-
else
|
96
|
-
configuration = configuration.merge(configurationMerge)
|
97
|
-
end
|
94
|
+
configuration = configuration.merge(configurationMerge)
|
98
95
|
end
|
99
96
|
|
100
97
|
if configuration.target.nil?
|
101
|
-
configurationMerge =
|
102
|
-
|
103
|
-
unless configuration.scheme.nil?
|
104
|
-
configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationTarget => configuration.scheme + 'Tests')
|
105
|
-
end
|
106
|
-
|
107
|
-
if configurationMerge.nil?
|
108
|
-
GALogger.log("target was not specified, exiting", :Error)
|
109
|
-
outputSampleConfiguration()
|
110
|
-
abort
|
111
|
-
else
|
112
|
-
configuration = configuration.merge(configurationMerge)
|
113
|
-
end
|
98
|
+
configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationTarget => configuration.scheme + 'Tests')
|
99
|
+
configuration = configuration.merge(configurationMerge)
|
114
100
|
end
|
115
101
|
|
116
102
|
xctoolExists = system("which #{configuration.xctool_path} > /dev/null")
|
@@ -121,36 +107,38 @@ class GALoader
|
|
121
107
|
end
|
122
108
|
|
123
109
|
# Outputs a sample configuration to let the user know how to create a valid one
|
110
|
+
#
|
111
|
+
# @param eventuallyAbort [Bool] pass true if you want to abort after printing out the sample configuration. Default is false.
|
124
112
|
#
|
125
113
|
# (see #GAConfiguration)
|
126
|
-
def self.outputSampleConfiguration()
|
127
|
-
GALogger.log('Sample configuration JSON: ' + GAConfiguration.sample.to_s, :Warning)
|
114
|
+
def self.outputSampleConfiguration(eventuallyAbort = false)
|
115
|
+
GALogger.log('Sample configuration JSON: ' + GAConfiguration.sample.to_s, :Warning, '')
|
116
|
+
if eventuallyAbort
|
117
|
+
abort
|
118
|
+
end
|
128
119
|
end
|
129
120
|
|
130
121
|
# Outputs a given configuration on the console
|
131
122
|
#
|
132
123
|
# @param [GAConfiguration] the configuration you want to print
|
133
124
|
def self.outputConfiguration(configuration)
|
134
|
-
|
125
|
+
GALogger.log(configuration.to_s, :Default, '')
|
135
126
|
end
|
136
127
|
|
137
128
|
# Returns a filename from a given array
|
138
129
|
#
|
139
|
-
# @param
|
130
|
+
# @param files [Array<String>] an array of strings
|
140
131
|
#
|
141
132
|
# @note the method will take the last element of the array
|
142
133
|
# @note the method will take only the filename if the element of the array is a file, removing the extension and the path
|
143
|
-
def self.
|
144
|
-
fileToTest =
|
145
|
-
|
146
|
-
fileToTest = File.basename(a, ".*")
|
147
|
-
end
|
148
|
-
|
134
|
+
def self.getFileFromArray(files)
|
135
|
+
fileToTest = files.first
|
136
|
+
|
149
137
|
if fileToTest.nil?
|
150
138
|
GALogger.log('Failed to get file', :Error)
|
151
139
|
abort
|
140
|
+
else
|
141
|
+
return File.basename(fileToTest, ".*")
|
152
142
|
end
|
153
|
-
|
154
|
-
return fileToTest
|
155
143
|
end
|
156
144
|
end
|
data/lib/ga_logger.rb
CHANGED
@@ -9,9 +9,11 @@ class GALogger
|
|
9
9
|
#
|
10
10
|
# @param message [String] a string to log
|
11
11
|
# @param type [Symbol] specifies the type of message. This can be :Error, :Warning, :Success or :Default
|
12
|
+
# @param padding [String] the padding to put before and after the message
|
13
|
+
#
|
12
14
|
# @note depending on the message type, a different color will be used to print the message on the console
|
13
|
-
def self.log(message, type = :Default)
|
14
|
-
puts sequenceForType(type) +
|
15
|
+
def self.log(message, type = :Default, padding = ' ### ')
|
16
|
+
puts sequenceForType(type) + padding + message + padding + sequenceForType(:Default)
|
15
17
|
end
|
16
18
|
|
17
19
|
# Returns the character code to print with the right color given a message type
|
data/lib/ga_runner.rb
CHANGED
@@ -10,9 +10,9 @@ class GARunner
|
|
10
10
|
# @param filename [String] the name of the file you want to run the tests for
|
11
11
|
# @note filename can also be a tests file
|
12
12
|
def initialize(configuration, filename)
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
@configuration=configuration
|
14
|
+
@filename=filename
|
15
|
+
@runner=XctoolRunner.new(configuration)
|
16
16
|
end
|
17
17
|
|
18
18
|
# Runs unit tests for the given filename, if a tests file exists
|
@@ -38,15 +38,8 @@ class GARunner
|
|
38
38
|
# (see #buildIfNeeded)
|
39
39
|
# (see #testIfAvailable)
|
40
40
|
def test()
|
41
|
-
filename = @filename
|
42
|
-
suffix = @configuration.suffix
|
43
|
-
|
44
41
|
buildIfNeeded()
|
45
|
-
|
46
|
-
filename = @filename.slice(/(?<file>.*)#{suffix}$/, "file")
|
47
|
-
end
|
48
|
-
|
49
|
-
testIfAvailable(filename)
|
42
|
+
testIfAvailable(codeFilename())
|
50
43
|
end
|
51
44
|
|
52
45
|
# @return true if the filename is a tests file
|
@@ -54,12 +47,24 @@ class GARunner
|
|
54
47
|
return @filename.end_with? @configuration.suffix
|
55
48
|
end
|
56
49
|
|
50
|
+
# @return [String] the code file corresponding to @filename, stripping the suffix if @filename is a test file
|
51
|
+
def codeFilename()
|
52
|
+
suffix = @configuration.suffix
|
53
|
+
stripped = @filename
|
54
|
+
if isTest()
|
55
|
+
stripped = @filename.slice(/(?<file>.*)#{suffix}$/, "file")
|
56
|
+
end
|
57
|
+
|
58
|
+
return stripped
|
59
|
+
end
|
60
|
+
|
57
61
|
# This method builds the tests project if the filename setup during initialization is a tests file
|
58
62
|
# (see #isTest)
|
59
63
|
def buildIfNeeded()
|
60
64
|
if isTest()
|
61
65
|
GALogger.log(@filename + ' is a test, building all the tests...')
|
62
|
-
GuardianAngel.buildWithConfiguration(@configuration)
|
63
66
|
end
|
67
|
+
|
68
|
+
GuardianAngel.buildWithConfiguration(@configuration)
|
64
69
|
end
|
65
70
|
end
|
data/lib/xctool_runner.rb
CHANGED
@@ -20,9 +20,7 @@ class XctoolRunner
|
|
20
20
|
xctool = @configuration.xctool_path
|
21
21
|
|
22
22
|
building = workspace
|
23
|
-
if workspace.nil?
|
24
|
-
building = project
|
25
|
-
end
|
23
|
+
building = project if workspace.nil?
|
26
24
|
|
27
25
|
GALogger.log("Building " + building + " with scheme " + scheme + "...")
|
28
26
|
|
@@ -45,7 +43,6 @@ class XctoolRunner
|
|
45
43
|
project = @configuration.project
|
46
44
|
|
47
45
|
toBuild = ''
|
48
|
-
|
49
46
|
if workspace.nil?
|
50
47
|
toBuild = " -project '" + project + ".xcodeproj'"
|
51
48
|
else
|
@@ -60,10 +57,8 @@ class XctoolRunner
|
|
60
57
|
# @param filename [String] the file you wish to run the tests for
|
61
58
|
# @note This method supports both workspace- and project-based environments
|
62
59
|
def test(filename)
|
63
|
-
workspace = @configuration.workspace
|
64
60
|
scheme = @configuration.scheme
|
65
61
|
target = @configuration.target
|
66
|
-
project = @configuration.project
|
67
62
|
xctool = @configuration.xctool_path
|
68
63
|
reporter = @configuration.reporter
|
69
64
|
suffix = @configuration.suffix
|