guardian-angel 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b756688b60516c6856da9c1cff4576f846f52056
4
- data.tar.gz: d896fceb43a6d3291435f69fab862f073c3f1a4e
3
+ metadata.gz: 1e8a07cc9d415e7805881f31d56576a065f0b0ae
4
+ data.tar.gz: 60e6055cda8f7621571eca4ba028883553eff487
5
5
  SHA512:
6
- metadata.gz: 61cea12f91402ba6a541d27a2d8aaa606deea1c2bc954dd0b17f9179cee9ee633179d466283b9428e030156ebb3f0e07087fe708a33369f1304952d3ab7a20b2
7
- data.tar.gz: 58148addf0594055fd9a76ccff0b8502781bf72f21ee24f8913d69633adad37a8c308cb1f3bc24688d9bd633dd78276f5e1f4ac1961b182f6059bc06a5d77b0c
6
+ metadata.gz: 757379efb86edd265634fafbe27d69574c9ee4aae22235e116d433dfa9f1ceaf6ab8f72b3a504cbd4027785f4bd785b69749e1b9e9bdc90b395e1d0a5de8ad15
7
+ data.tar.gz: f2135736d1d9760211d793a552b776ba3fc0b19e5690e16ba54d4e8b1968ade9c6dba6f1224aaf1e3781046eae7067435a16e75a4b15a59db05c2092cd2d4b92
@@ -6,13 +6,23 @@ class GAConfiguration
6
6
  GAConfigurationSuffix = "suffix"
7
7
  GAConfigurationReporter = "reporter"
8
8
  GAConfigurationXctoolPath = "xctool"
9
+ GAConfigurationProject = "project"
10
+
11
+ GAConfigurationDefaultReporter = "pretty"
12
+ GAConfigurationDefaultXctoolPath = "xctool"
13
+ GAConfigurationDefaultSuffix = "Test"
9
14
 
10
15
  # @return the configured xcode scheme
11
16
  def scheme
12
17
  @scheme
13
18
  end
14
19
 
15
- # @return the configured xcode workspace
20
+ # @return the configured xcode project, if not using workspaces
21
+ def project
22
+ @project
23
+ end
24
+
25
+ # @return the configured xcode workspace, if not using projects
16
26
  def workspace
17
27
  @workspace
18
28
  end
@@ -46,12 +56,29 @@ class GAConfiguration
46
56
  GAConfigurationTarget => @target,
47
57
  GAConfigurationSuffix => @suffix,
48
58
  GAConfigurationReporter => @reporter,
49
- GAConfigurationXctoolPath => @xctool_path
59
+ GAConfigurationXctoolPath => @xctool_path,
60
+ GAConfigurationProject => @project
50
61
  }
51
62
 
52
63
  return hashForOutput.to_s
53
64
  end
54
65
 
66
+ # Creates a sample GAConfiguration instance to instruct the user
67
+ #
68
+ # @return [GAConfiguration] an instance that should not be used apart from outputting on the console
69
+ def self.sample
70
+ sample = GAConfiguration.new({
71
+ GAConfigurationWorkspace => 'MyProject',
72
+ GAConfigurationScheme => 'MyProject-Dev',
73
+ GAConfigurationTarget => 'MyProjectTests',
74
+ GAConfigurationSuffix => GAConfigurationDefaultSuffix,
75
+ GAConfigurationReporter => GAConfigurationDefaultReporter,
76
+ GAConfigurationXctoolPath => GAConfigurationDefaultXctoolPath
77
+ })
78
+
79
+ return sample
80
+ end
81
+
55
82
  # Creates an instance with the given configuration, or uses a default one if not provided
56
83
  # @param configuration [GAConfiguration]
57
84
  #
@@ -63,6 +90,7 @@ class GAConfiguration
63
90
  @suffix = configuration[GAConfigurationSuffix]
64
91
  @reporter = configuration[GAConfigurationReporter]
65
92
  @xctool_path = configuration[GAConfigurationXctoolPath]
93
+ @project = configuration[GAConfigurationProject]
66
94
  end
67
95
 
68
96
  # Merges two GAConfiguration instances
@@ -88,6 +116,9 @@ class GAConfiguration
88
116
  unless other.xctool_path.nil?
89
117
  @xctool_path = other.xctool_path
90
118
  end
119
+ unless other.project.nil?
120
+ @project = other.project
121
+ end
91
122
 
92
123
  return self
93
124
  end
@@ -12,8 +12,6 @@ class GALoader
12
12
  # @note this also outputs the final GAConfiguration built on the console
13
13
  # (see #GAConfiguration)
14
14
  def self.readConfiguration()
15
- GALogger.log("Reading #{CONFIG_FILENAME}...")
16
-
17
15
  configuration = GAConfiguration.new
18
16
 
19
17
  begin
@@ -21,8 +19,6 @@ class GALoader
21
19
  configurationMerge = GAConfiguration.new(jsonDictionary)
22
20
  configuration = configuration.merge(configurationMerge)
23
21
  rescue
24
- #Find workspace, scheme and target
25
- #merge and return
26
22
  GALogger.log("#{CONFIG_FILENAME} not found, using defaults", :Warning)
27
23
  end
28
24
 
@@ -32,23 +28,72 @@ class GALoader
32
28
  return configuration
33
29
  end
34
30
 
31
+ # Returns a possible workspace, in case one is not provided in the configuration
32
+ #
33
+ # @note this searches only in the current directory
34
+ def self.findWorkspace
35
+ workspace = value = `find . -maxdepth 1 -name '*.xcworkspace'`
36
+ return nil if workspace.empty?
37
+
38
+ return File.basename(workspace, ".*")
39
+ end
40
+
35
41
  # Validates a given configuration
36
42
  #
37
43
  # @param configuration [GAConfiguration] the configuration to validate
38
- # @note required attributes are workspace, scheme and target
44
+ # @note required attribute is workspace/project
45
+ # @note if scheme is not specified, the same as the workspace/project will be used
46
+ # @note if target is not specified, '{workspace|project}Tests' will be used
39
47
  # @note the method will also make sure that the configured xctool executable can be found, or aborts otherwise
40
48
  def self.validateConfiguration(configuration)
41
49
  if configuration.workspace.nil?
42
- GALogger.log("workspace was not specified, exiting", :Error)
43
- abort
50
+ possibleWorkspace = findWorkspace()
51
+
52
+ if !possibleWorkspace
53
+ if configuration.project.nil?
54
+ GALogger.log("workspace or project was not specified, exiting", :Error)
55
+ outputSampleConfiguration()
56
+ abort
57
+ end
58
+ end
59
+
60
+ configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationWorkspace => possibleWorkspace)
61
+ configuration = configuration.merge(configurationMerge)
44
62
  end
63
+
45
64
  if configuration.scheme.nil?
46
- GALogger.log("scheme was not specified, exiting", :Error)
47
- abort
65
+ configurationMerge = nil
66
+
67
+ unless configuration.project.nil?
68
+ configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationScheme => configuration.project)
69
+ end
70
+ unless configuration.workspace.nil?
71
+ configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationScheme => configuration.workspace)
72
+ end
73
+
74
+ if configurationMerge.nil?
75
+ GALogger.log("scheme was not specified, exiting", :Error)
76
+ outputSampleConfiguration()
77
+ abort
78
+ else
79
+ configuration = configuration.merge(configurationMerge)
80
+ end
48
81
  end
82
+
49
83
  if configuration.target.nil?
50
- GALogger.log("target was not specified, exiting", :Error)
51
- abort
84
+ configurationMerge = nil
85
+
86
+ unless configuration.scheme.nil?
87
+ configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationTarget => configuration.scheme + 'Tests')
88
+ end
89
+
90
+ if configurationMerge.nil?
91
+ GALogger.log("target was not specified, exiting", :Error)
92
+ outputSampleConfiguration()
93
+ abort
94
+ else
95
+ configuration = configuration.merge(configurationMerge)
96
+ end
52
97
  end
53
98
 
54
99
  xctoolExists = system("which #{configuration.xctool_path} > /dev/null")
@@ -58,6 +103,13 @@ class GALoader
58
103
  end
59
104
  end
60
105
 
106
+ # Outputs a sample configuration to let the user know how to create a valid one
107
+ #
108
+ # (see #GAConfiguration)
109
+ def self.outputSampleConfiguration()
110
+ GALogger.log('Sample configuration JSON: ' + GAConfiguration.sample.to_s, :Warning)
111
+ end
112
+
61
113
  # Outputs a given configuration on the console
62
114
  #
63
115
  # @param [GAConfiguration] the configuration you want to print
@@ -1,5 +1,6 @@
1
1
  require 'ga_logger'
2
2
  require 'guardian_angel'
3
+ require 'xctool_runner'
3
4
 
4
5
  # @author Vittorio Monaco
5
6
  class GARunner
@@ -11,6 +12,7 @@ class GARunner
11
12
  def initialize(configuration, filename)
12
13
  @configuration=configuration
13
14
  @filename=filename
15
+ @runner=XctoolRunner.new(configuration)
14
16
  end
15
17
 
16
18
  # Runs unit tests for the given filename, if a tests file exists
@@ -19,26 +21,15 @@ class GARunner
19
21
  # @note filename must be a code file, not a tests file. If you're not sure whether the file is a tests file or not, use #test instead
20
22
  # @note if a corresponding tests file cannot be found, outputs a warning line
21
23
  def testIfAvailable(filename)
22
- workspace = @configuration.workspace
23
- scheme = @configuration.scheme
24
- target = @configuration.target
25
24
  suffix = @configuration.suffix
26
- reporter = @configuration.reporter
27
- xctool = @configuration.xctool_path
28
25
 
29
- fileExists = system('find . | grep ' + filename + suffix + ' > /dev/null')
26
+ fileExists = system("find . | grep '" + filename + suffix + "' > /dev/null")
30
27
  if !fileExists
31
- GALogger.log(filename + " doesn't seem to have associated tests. You may think about it.", :Warning)
28
+ GALogger.log(filename + " doesn't seem to have associated tests. You should think about creating some.", :Warning)
32
29
  return
33
30
  end
34
31
 
35
- GALogger.log("Running tests for file " + filename + '...')
36
- system(xctool + ' -workspace -workspace ' + workspace + '.xcworkspace' +
37
- ' -scheme ' + scheme +
38
- ' -sdk iphonesimulator' +
39
- ' run-tests' +
40
- ' -reporter ' + reporter
41
- ' only ' + target + ':' + filename + suffix, out: $stdout, err: :out)
32
+ @runner.test(filename)
42
33
  end
43
34
 
44
35
  # Tries to run unit tests for the filename setup during initialization
@@ -1,4 +1,5 @@
1
1
  require 'ga_logger'
2
+ require 'xctool_runner'
2
3
 
3
4
  # @author Vittorio Monaco
4
5
  class GuardianAngel
@@ -7,6 +8,7 @@ class GuardianAngel
7
8
  # @param configuration [GAConfiguration] the configuration you want to use to run the tests (see #GAConfiguration)
8
9
  def initialize(configuration)
9
10
  @configuration=configuration
11
+ @runner=XctoolRunner.new(configuration)
10
12
  end
11
13
 
12
14
  # Convenience method to build tests in a stand-alone fashion
@@ -19,17 +21,10 @@ class GuardianAngel
19
21
 
20
22
  # Builds the tests target through xctool
21
23
  #
24
+ # (see #XctoolRunner)
22
25
  # @note a configuration must be already setup for this method to work
23
26
  def buildTests()
24
- workspace = @configuration.workspace
25
- scheme = @configuration.scheme
26
- xctool = @configuration.xctool_path
27
-
28
- GALogger.log("Building workspace " + workspace + " with scheme " + scheme + "...")
29
- system(xctool + ' -workspace ' + workspace + '.xcworkspace' +
30
- ' -scheme ' + scheme +
31
- ' -sdk iphonesimulator' +
32
- ' build-tests', out: $stdout, err: :out)
27
+ @runner.build()
33
28
  end
34
29
 
35
30
  # Starts watching for changes to .m or .swift files in the caller directory
@@ -0,0 +1,81 @@
1
+ require 'ga_logger'
2
+
3
+ # @author Vittorio Monaco
4
+ class XctoolRunner
5
+ # Creates a new instance given a GAConfiguration object
6
+ #
7
+ # @param configuration [GAConfiguration] the configuration you want to use to build and run the tests (see #GAConfiguration)
8
+ def initialize(configuration)
9
+ @configuration=configuration
10
+ end
11
+
12
+ # Builds the tests target through xctool
13
+ #
14
+ # @note This method supports both workspace- and project-based environments
15
+ def build()
16
+ workspace = @configuration.workspace
17
+ scheme = @configuration.scheme
18
+ target = @configuration.target
19
+ project = @configuration.project
20
+ xctool = @configuration.xctool_path
21
+
22
+ building = workspace
23
+ if workspace.nil?
24
+ building = project
25
+ end
26
+
27
+ GALogger.log("Building " + building + " with scheme " + scheme + "...")
28
+
29
+ toBuild = buildArgument()
30
+ system(xctool + toBuild +
31
+ ' -scheme ' + scheme +
32
+ ' -sdk iphonesimulator' +
33
+ ' build-tests', out: $stdout, err: :out)
34
+ end
35
+
36
+ # Returns the main argument for xctool to build the project/workspace
37
+ #
38
+ # Example:
39
+ # -workspace 'MyWorkspace.xcworkspace'
40
+ # or
41
+ # -project 'MyProject.xcodeproj'
42
+ def buildArgument()
43
+ workspace = @configuration.workspace
44
+ scheme = @configuration.scheme
45
+ project = @configuration.project
46
+
47
+ toBuild = ''
48
+
49
+ if workspace.nil?
50
+ toBuild = " -project '" + project + ".xcodeproj'"
51
+ else
52
+ toBuild = " -workspace '" + workspace + ".xcworkspace'"
53
+ end
54
+
55
+ return toBuild
56
+ end
57
+
58
+ # Runs tests for the specified file
59
+ #
60
+ # @param filename [String] the file you wish to run the tests for
61
+ # @note This method supports both workspace- and project-based environments
62
+ def test(filename)
63
+ workspace = @configuration.workspace
64
+ scheme = @configuration.scheme
65
+ target = @configuration.target
66
+ project = @configuration.project
67
+ xctool = @configuration.xctool_path
68
+ reporter = @configuration.reporter
69
+ suffix = @configuration.suffix
70
+
71
+ GALogger.log("Running tests for file " + filename + '...')
72
+
73
+ toBuild = buildArgument()
74
+ system(xctool + toBuild +
75
+ ' -scheme ' + scheme +
76
+ ' -sdk iphonesimulator' +
77
+ ' run-tests' +
78
+ ' only ' + target + ':' + filename + suffix +
79
+ ' -reporter ' + reporter, out: $stdout, err: :out)
80
+ end
81
+ end
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vittorio Monaco
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
- description: A file watcher that runs tests for the modified files
41
+ description: A file watcher for iOS developers that runs tests for the modified files
42
42
  email: vittorio.monaco1@gmail.com
43
43
  executables:
44
44
  - guardian-angel
@@ -53,7 +53,8 @@ files:
53
53
  - lib/ga_logger.rb
54
54
  - lib/ga_runner.rb
55
55
  - lib/guardian_angel.rb
56
- homepage: http://vittoriomonaco.it
56
+ - lib/xctool_runner.rb
57
+ homepage: http://vittoriomonaco.it/guardian-angel
57
58
  licenses:
58
59
  - MIT
59
60
  metadata: {}