guardian-angel 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e448d846f7832faaf993bc66da560f47df9f9e7
4
- data.tar.gz: 7ee0374d51306fcba167848fcec8adf014e7cdca
3
+ metadata.gz: aa1d8955513a660d1b1d388fd12325528fa3f392
4
+ data.tar.gz: a4cf0ea6e13f48e6bdc59dd79d6146cbca6447c5
5
5
  SHA512:
6
- metadata.gz: 25fc3c497a2a8f6ef1b36aeb962deea5343b4da4294e0b7fcc9e076e64866751e9d489306e278fedf7e64953f7785cc662570fc61b4da0a43dade895eb394241
7
- data.tar.gz: ab080ed038aea304e99ee068414c7315193b58d69074ccc2e273dd48bb8b5e0c4471c4f331ffba64acb803ce4a33f07dc332b0f271b341cd98447c2691312a9e
6
+ metadata.gz: 5a091afeeb1b9a16f63df72fe85a19ed1f119371dfef0a48ecc500da3cf59db2d7565bcd7d1d89591ce97f69a90fa03aab44c08d6b1cab6d78efcdebf2517203
7
+ data.tar.gz: 0e6e83763a3f99afb4a1d64b75faea84661d35a6724b28d9b2c78f1892956fb5979b5ad891156f2db846540ff012210db381c4cbb821aded36521235a8685f7d
@@ -5,8 +5,8 @@ require 'ga_runner'
5
5
 
6
6
  trap("INT") { exit }
7
7
 
8
- fileToTest = GALoader.getFileFromArgv(ARGV)
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()
@@ -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
- @scheme = other.scheme
103
- end
104
- unless other.workspace.nil?
105
- @workspace = other.workspace
106
- end
107
- unless other.target.nil?
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
@@ -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
- workspace = `find . -maxdepth 1 -name '*.xcworkspace'`
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
- project = `find . -maxdepth 1 -name '*.xcodeproj'`
46
- return nil if project.empty?
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(project, ".*")
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
- if configuration.project.nil?
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
- if configurationMerge.nil?
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 = nil
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
- puts configuration.to_s
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 argv [Array<String>] an array of strings
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.getFileFromArgv(argv)
144
- fileToTest = nil
145
- argv.each do|a|
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
@@ -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) + '### ' + message + ' ###' + sequenceForType(:Default)
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
@@ -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
- @configuration=configuration
14
- @filename=filename
15
- @runner=XctoolRunner.new(configuration)
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
- if isTest()
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guardian-angel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vittorio Monaco