fastlane-plugin-xcodetestcoverage 1.0.2 → 1.1.0

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
  SHA256:
3
- metadata.gz: fbbeb5ada9ae797c979dc0400ea7bb0e20fec4fa20c50c7541e340fa179de39a
4
- data.tar.gz: eaf4dd8e7c14280ea49ca6df7ee8692b78d3bfad85ff35353b47f3f0f8273175
3
+ metadata.gz: e23696404cf27741d5c3fa1476463c0592c3841d19b511c6af84297a60327cce
4
+ data.tar.gz: 1a89337d4669faac257af5e0336149bdbe6755c4390ac4b4841777eb7d909f2d
5
5
  SHA512:
6
- metadata.gz: f5283f51ab7317c0184c4df2cf22c21151c1e46daed21c1e1fad5ef30336656c84c042f3d6852f4cc04385bac94f88b34ff76983498d3332c02e93e9c0b24f59
7
- data.tar.gz: '09cf0f7cbb343d30e0b7eee1c46735389d11f68b58239ed9b6755b93a10edde78c07ccada618b9fba9c9c8965029bfc80cacae886648d872cf473ee68dedb487'
6
+ metadata.gz: d7e83365dff6854378304635c136328c23f19e72e7112e1a74ff62a37abc4525bb98b62504b683b4f8f4dac22a21f754b0b445b929b3bfccbd00b0c77ce6fc1c
7
+ data.tar.gz: 3110536aee3831265ac50ef3be6f003119dd6f955f937514737ba010b283a0106894b592732dae2d2a2100ec6d2c699f775632c46465fc9067952b16d1a99752
data/README.md CHANGED
@@ -15,13 +15,14 @@ fastlane add_plugin xcodetestcoverage
15
15
  Plugin for getting test data from Xcode
16
16
 
17
17
  It has to be run after tests.
18
- Returns hash contains keys: coverage, coveredLines, executableLines:
18
+ Returns hash contains keys: name, coverage, coveredLines, executableLines:
19
19
 
20
20
  ```bash
21
21
  run_tests()
22
22
  result = xcodetestcoverage()
23
- puts(result["coverage"])
24
- puts(result["coveredLines"])
23
+ puts(result["name"]) #current test target name
24
+ puts(result["coverage"]) #current coverage percentage
25
+ puts(result["coveredLines"])
25
26
  puts(result["executableLines"])
26
27
  ```
27
28
 
@@ -38,6 +39,10 @@ type: Proc
38
39
 
39
40
  coverageExceptionCallback - Optional coverage exception callback argument" optional: true, type: Proc
40
41
 
42
+ testTargetName - searches test target to display coverage percentages, if it is empty the results contains the target with the highest percentage value, optional: true, type: String
43
+
44
+ xcresultPath - alternative path to xcresult, optional: true, type: String
45
+
41
46
  ## Example
42
47
 
43
48
  Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane tests`.
@@ -62,7 +67,13 @@ xcodetestcoverage(minimumCoveragePercentage: 45.0,
62
67
  }
63
68
  )
64
69
  ```
65
-
70
+ You can use alternative path to xcresult. In this case, running a test via fastlane (with the command scan or run_tests) before xcodetestcoverage is optional.
71
+ ```bash
72
+ reportPath = "test.xcresult"
73
+ xcodetestcoverage(minimumCoveragePercentage: 30.0,
74
+ enableDataFailedException: true,
75
+ xcresultPath: reportPath)
76
+ ```
66
77
 
67
78
  ## Issues and Feedback
68
79
 
@@ -8,30 +8,56 @@ module Fastlane
8
8
  enableDataFailedException = params[:enableDataFailedException]
9
9
  minimumCoveragePercentage = params[:minimumCoveragePercentage]
10
10
  enableDefaultCoverageException = params[:enableDefaultCoverageException]
11
- lineCoverage = nil
12
- coveredLines = nil
13
- executableLines = nil
11
+ targetName = params[:testTargetName]
12
+ filePath = params[:xcresultPath]
13
+ foundElement = nil
14
14
 
15
- filePath = lane_context[SharedValues::SCAN_GENERATED_XCRESULT_PATH]
15
+ if !filePath
16
+ filePath = lane_context[SharedValues::SCAN_GENERATED_XCRESULT_PATH]
17
+ end
16
18
 
17
19
  if filePath && File.exists?(filePath)
18
20
  jsonResult = sh "xcrun xccov view --only-targets --report '#{filePath}' --json"
19
- if lineCoverageMatch = jsonResult.match('.*lineCoverage":(\d+.\d+).*')
20
- lineCoverage = lineCoverageMatch.captures[0].to_f * 100
21
- UI.message("Xcodetestcoverage: coverage: #{lineCoverage}")
21
+
22
+ #regex, reason: json parse does not work correctly
23
+ if resultMatch = jsonResult.match('(\[.*lineCoverage.*\])')
24
+ jsonArray = resultMatch.captures[0]
22
25
  end
23
26
 
24
- if coveredLinesMatch = jsonResult.match('.*coveredLines":(\d+).*')
25
- coveredLines = coveredLinesMatch.captures[0].to_i
26
- UI.message("Xcodetestcoverage: coveredLines: #{coveredLines}")
27
+ elements = Array.new()
28
+ element = ""
29
+ for pos in 0...jsonArray.length
30
+ if jsonArray[pos].chr == "}"
31
+ elements.push Helper::XcodetestcoverageHelper.buildElement(element: element)
32
+ element = ""
33
+ else
34
+ element = element + jsonArray[pos].chr
35
+ end
27
36
  end
28
37
 
29
- if executableLineMatch = jsonResult.match('.*executableLines":(\d+).*')
30
- executableLines = executableLineMatch.captures[0].to_i
31
- UI.message("Xcodetestcoverage: executableLines: #{executableLines}")
38
+ if elements.length > 0
39
+ for index in 0...elements.length
40
+ if targetName && elements[index]["name"] && elements[index]["name"] == targetName
41
+ foundElement = elements[index]
42
+ break
43
+ end
44
+
45
+ if !foundElement || (elements[index]["coverage"] && elements[index]["coverage"] > foundElement["coverage"])
46
+ foundElement = elements[index]
47
+ end
48
+ end
49
+ else
50
+ foundElement = Helper::XcodetestcoverageHelper.buildElement(element: jsonResult)
32
51
  end
33
52
  end
34
-
53
+
54
+ lineCoverage = foundElement["coverage"]
55
+
56
+ UI.message("Xcodetestcoverage: name: #{foundElement["name"]}")
57
+ UI.message("Xcodetestcoverage: coverage: #{lineCoverage}")
58
+ UI.message("Xcodetestcoverage: coveredLines: #{foundElement["coveredLines"]}")
59
+ UI.message("Xcodetestcoverage: executableLines: #{foundElement["executableLines"]}")
60
+
35
61
  if !lineCoverage
36
62
  params[:dataFailedExceptionCallback].call() if params[:dataFailedExceptionCallback]
37
63
  UI.user_error!("Xcodetestcoverage: Test data reading error!") if enableDataFailedException
@@ -43,11 +69,7 @@ module Fastlane
43
69
  UI.user_error!("Xcodetestcoverage: Coverage percentage is less than #{minimumCoveragePercentage} (minimumCoveragePercentage)") if enableDefaultCoverageException
44
70
  end
45
71
 
46
- return {
47
- "coverage" => lineCoverage,
48
- "coveredLines" => coveredLines,
49
- "executableLines" => executableLines,
50
- }
72
+ return foundElement
51
73
  end
52
74
 
53
75
  def self.description
@@ -101,7 +123,21 @@ module Fastlane
101
123
  key: :coverageExceptionCallback,
102
124
  description: "Optional coverage exception callback argument",
103
125
  optional: true,
104
- type: Proc)
126
+ type: Proc),
127
+
128
+ FastlaneCore::ConfigItem.new(
129
+ key: :testTargetName,
130
+ env_name: "XCODETESTCOVERAGE_TEST_TARGET_NAME",
131
+ description: "Alternative path to xcresult",
132
+ type: String,
133
+ optional: true),
134
+
135
+ FastlaneCore::ConfigItem.new(
136
+ key: :xcresultPath,
137
+ env_name: "XCODETESTCOVERAGE_XCRESULTPATH",
138
+ description: "Alternative path to xcresult",
139
+ type: String,
140
+ optional: true)
105
141
  ]
106
142
  end
107
143
 
@@ -5,11 +5,36 @@ module Fastlane
5
5
 
6
6
  module Helper
7
7
  class XcodetestcoverageHelper
8
- # class methods that you define here become available in your action
9
- # as `Helper::XcodetestcoverageHelper.your_method`
10
- #
11
- def self.show_message
12
- UI.message("Hello from the xcodetestcoverage plugin helper!")
8
+ def self.buildElement(element:)
9
+ name = nil
10
+ lineCoverage = nil
11
+ coveredLines = nil
12
+ executableLines = nil
13
+
14
+ if nameMatch = element.match('"name":"(.*?)"')
15
+ name = nameMatch.captures[0]
16
+ end
17
+
18
+ if lineCoverageFloatMatch = element.match('lineCoverage":(\d+.\d+)')
19
+ lineCoverage = lineCoverageFloatMatch.captures[0].to_f * 100
20
+ else
21
+ if lineCoverageIntMatch = element.match('lineCoverage":(\d+)')
22
+ lineCoverage = lineCoverageIntMatch.captures[0].to_f * 100
23
+ end
24
+ end
25
+
26
+ if coveredLinesMatch = element.match('coveredLines":(\d+)')
27
+ coveredLines = coveredLinesMatch.captures[0].to_i
28
+ end
29
+
30
+ if executableLineMatch = element.match('executableLines":(\d+)')
31
+ executableLines = executableLineMatch.captures[0].to_i
32
+ end
33
+
34
+ return {"name" => name,
35
+ "coverage" => lineCoverage,
36
+ "coveredLines" => coveredLines,
37
+ "executableLines" => executableLines}
13
38
  end
14
39
  end
15
40
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Xcodetestcoverage
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-xcodetestcoverage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Savitsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-20 00:00:00.000000000 Z
11
+ date: 2023-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler