tap_report_parser 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 441006e2fd8efd6863b0143c79c98bd6b5bc10c3
4
+ data.tar.gz: 104dfa944e078867d1075be2537e8e9b5d7de8df
5
+ SHA512:
6
+ metadata.gz: 4d4ac757cb99a3ffdbdcc07198dab47a9e5b96d3555773feabcde02f72b8d295f3e631f7329f859f5bd8e284f4f0057de5532a0cc192cdff03cabdcab2a1b036
7
+ data.tar.gz: ea94d39fe4af33674052a47e73e933796a3a857b448fb824bb3e1277cd7111dd6be9e3b8fe4ebf8ac093a546d4794d8c249cc1e689efc44fde362a8ffa2d3e41
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at abhisinghabhimanyu@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in tap_report_parser.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Abhimanyu Singh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # TapReportParser
2
+
3
+ This gem parses a TAP report per the specifications listed on https://testanything.org/tap-specification.html. Each of the tests has six attributes: `number`, `description`, `status`, `directive`, `diagnostic` and `passing`.
4
+
5
+ - The `number` is test number. If the `number` is not present, the parser maintains its own count.
6
+ - The `description` is the text describing the test. If the `description` is not present, then its value is empty string.
7
+ - The `status` is represented by one of the four values: `success` (when test is passing), `failure` (when test is failing), `skipped` (when test is marked as skipped irrespective of success or failure), and `ignore` (when test is marked as todo irrespective of success or failure).
8
+ - The `directive` is either skipped or todo.
9
+ - The `diagnostic` is a YAML block or text. If it is YAML then its value is ruby Hash, otherwise string. If the `diagnostic` is not present, then its value is empty string.
10
+ - The value of the `passing` is `true` if test status is either `passing` or `ignored`.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'tap_report_parser'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install tap_report_parser
27
+
28
+ ## Usage
29
+
30
+ You can parse report either from file or text, i.e.,
31
+ ```ruby
32
+ report = TapReportParser::Report.from_text(text)
33
+ report = TapReportParser::Report.from_file(file)
34
+ ```
35
+
36
+ For example, consider the following TAP report:
37
+ ```tap
38
+ TAP version 13
39
+ 1..6
40
+ #
41
+ # Create a new Board and Tile, then place
42
+ # the Tile onto the board.
43
+ #
44
+ ok 1 - The object is a Board
45
+ ok 2 - Board size is zero
46
+ ok 3 - The object is a Tile
47
+ ok 4 - Get possible places to put the Tile
48
+ ok 5 - Placing the tile produces no error
49
+ ok 6 - Board size is 1
50
+ ```
51
+
52
+ Parsing the report from text will return the `TapReportParser::Report` object, which has the following three attributes:
53
+
54
+ - `test_count`: The test count
55
+ - `tests`: Array of `TapReportParser::Test` objects each describing the test. Each of the test object has six attributes: `number`, `description`, `status`, `directive`, `diagnostic` and `passing`.
56
+ - `passing`: A boolean value which is `true` if all the tests are passing, i.e., the status is either `success` or `ignored`, otherwise `false`.
57
+
58
+ ```ruby
59
+ # Tests count
60
+ report.test_count
61
+ => 6
62
+ # All the tests passing?
63
+ report.passing
64
+ => true
65
+ # Tests
66
+ => [#<TapReportParser::Test:0x00007f943a97d968 @status="success", @directive="", @passing=true, @number=1, @description="The object is a Board", @diagnostic="">, #<TapReportParser::Test:0x00007f943a97d580 @status="success", @directive="", @passing=true, @number=2, @description="Board size is zero", @diagnostic="">, #<TapReportParser::Test:0x00007f943a97d198 @status="success", @directive="", @passing=true, @number=3, @description="The object is a Tile", @diagnostic="">, #<TapReportParser::Test:0x00007f943a97cd88 @status="success", @directive="", @passing=true, @number=4, @description="Get possible places to put the Tile", @diagnostic="">, #<TapReportParser::Test:0x00007f943a97c978 @status="success", @directive="", @passing=true, @number=5, @description="Placing the tile produces no error", @diagnostic="">, #<TapReportParser::Test:0x00007f943a97c590 @status="success", @directive="", @passing=true, @number=6, @description="Board size is 1", @diagnostic="">]
67
+ # Test number
68
+ report.tests.first.number
69
+ => 1
70
+ # Test description
71
+ report.tests.first.description
72
+ => "The object is a Board"
73
+ # Test status
74
+ report.tests.first.status
75
+ => "success"
76
+ # Test passing?
77
+ report.tests.first.passing
78
+ => true
79
+ # Test directive
80
+ report.tests.first.directive
81
+ => ""
82
+ # Test diagnostic
83
+ report.tests.first.diagnostic
84
+ => ""
85
+ ```
86
+
87
+ ## Development
88
+
89
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
90
+
91
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
92
+
93
+ ## Contributing
94
+
95
+ Bug reports and pull requests are welcome on GitHub at https://github.com/avmnu-sng/tap_report_parser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
96
+
97
+ ## License
98
+
99
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
100
+
101
+ ## Code of Conduct
102
+
103
+ Everyone interacting in the TapReportParser project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/avmnu-sng/tap_report_parser/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tap_report_parser"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module TapReportParser
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,117 @@
1
+ require "active_support/core_ext/object/blank"
2
+ require "yaml"
3
+ require "tap_report_parser/version"
4
+
5
+ module TapReportParser
6
+ class Report
7
+ attr_reader :test_count, :tests, :passing
8
+
9
+ def initialize(report)
10
+ @report = report
11
+ @test_count = 0
12
+ @tests = []
13
+ end
14
+
15
+ def self.from_file(file)
16
+ parser = Report.new(File.read(file))
17
+ parser.parse_report
18
+
19
+ parser
20
+ end
21
+
22
+ def self.from_text(text)
23
+ parser = Report.new(text)
24
+ parser.parse_report
25
+
26
+ parser
27
+ end
28
+
29
+ def parse_report
30
+ test_number = 1
31
+
32
+ @report.strip.split("\n").each do |line|
33
+ test_number = parse_line(line, test_number)
34
+ end
35
+
36
+ if @test_count != 0
37
+ ((1..@test_count).to_a - @tests.map(&:number)).each do |num|
38
+ @tests << Test.new("failure", num, "", "")
39
+ end
40
+ else
41
+ @test_count = @tests.count
42
+ end
43
+
44
+ @passing = @test_count != 0 && @tests.map(&:passing).count(true) == @test_count
45
+ @tests.each { |test| test.convert_diagnostic_yaml_to_hash }
46
+ end
47
+
48
+ def parse_line(line, test_number)
49
+ test_count = /1\.\.(\d+)(\s*#\s*.*)?/.match(line)&.captures&.first.to_i
50
+
51
+ if test_count != 0
52
+ @test_count = test_count
53
+
54
+ return test_number
55
+ end
56
+
57
+ matches = /^(ok|not ok)\s*(\d*)\s*-?\s*([^#]*)\s*(#\s*(.*))?/.match(line)&.captures&.map(&:to_s)
58
+
59
+ if matches.present?
60
+ matches = matches.map(&:strip)
61
+
62
+ matches[0] = matches[0] == "ok" ? "success" : "failure"
63
+ matches[1] = matches[1].present? ? matches[1].to_i : test_number
64
+
65
+ @tests << Test.new(matches[0], matches[1], matches[2], matches[4])
66
+
67
+ return matches[1] + 1
68
+ end
69
+
70
+ diagnostic = /^(#\s*)?(.*)$/.match(line)&.captures&.last&.rstrip
71
+
72
+ @tests.last.add_diagnostic(diagnostic) if @tests.present?
73
+
74
+ test_number
75
+ end
76
+ end
77
+
78
+ class Test
79
+ attr_reader :status, :passing, :number, :description, :directive, :diagnostic
80
+
81
+ def initialize(status, number, description, directive)
82
+ if (directive =~ /^skip.*/i).present?
83
+ @status = "skipped"
84
+ @directive = /(^skip)(.*)/i.match(directive)&.captures&.last&.strip
85
+ elsif (directive =~ /^todo.*/i).present?
86
+ @status = "ignored"
87
+ @directive = /(^todo)(.*)/i.match(directive)&.captures&.last&.strip
88
+ else
89
+ @status = status
90
+ @directive = directive
91
+ end
92
+
93
+ @passing = ["success", "ignored"].include?(@status)
94
+
95
+ @number = number
96
+ @description = description
97
+
98
+ @diagnostic = ""
99
+ end
100
+
101
+ def add_diagnostic(diagnostic)
102
+ return if /\s*?\.\.\./.match?(diagnostic)
103
+
104
+ if @diagnostic.empty?
105
+ @diagnostic = diagnostic
106
+ else
107
+ @diagnostic = "#{@diagnostic}\n#{diagnostic}"
108
+ end
109
+ end
110
+
111
+ def convert_diagnostic_yaml_to_hash
112
+ leading_spaces = @diagnostic[/\A */].length
113
+
114
+ @diagnostic = YAML.safe_load(@diagnostic.split("\n").map { |s| s[leading_spaces..-1] }.join("\n")) || ""
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,46 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tap_report_parser/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tap_report_parser"
8
+ spec.version = TapReportParser::VERSION
9
+ spec.authors = ["Abhimanyu Singh"]
10
+ spec.email = ["abhisinghabhimanyu@gmail.com"]
11
+
12
+ spec.summary = %q{Parse a TAP test report.}
13
+ spec.description = %q{A TAP test report defines several properties for each tests.
14
+ The objective of the gem is to provide all the specified properties
15
+ after parsing the report either from the file or text.}
16
+ spec.homepage = "https://www.github.com/avmnu-sng/tap_report_parser"
17
+ spec.license = "MIT"
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ # if spec.respond_to?(:metadata)
22
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
23
+ # else
24
+ # raise "RubyGems 2.0 or newer is required to protect against " \
25
+ # "public gem pushes."
26
+ # end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject do |f|
33
+ f.match(%r{^(test|spec|features)/})
34
+ end
35
+ end
36
+
37
+ spec.bindir = "exe"
38
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
+ spec.require_paths = ["lib"]
40
+
41
+ spec.add_dependency "rails"
42
+
43
+ spec.add_development_dependency "bundler", "~> 1.16"
44
+ spec.add_development_dependency "rake", "~> 10.0"
45
+ spec.add_development_dependency "rspec", "~> 3.0"
46
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tap_report_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Abhimanyu Singh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: |-
70
+ A TAP test report defines several properties for each tests.
71
+ The objective of the gem is to provide all the specified properties
72
+ after parsing the report either from the file or text.
73
+ email:
74
+ - abhisinghabhimanyu@gmail.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".travis.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - lib/tap_report_parser.rb
90
+ - lib/tap_report_parser/version.rb
91
+ - tap_report_parser.gemspec
92
+ homepage: https://www.github.com/avmnu-sng/tap_report_parser
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.14
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Parse a TAP test report.
116
+ test_files: []