-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add per subject inline disable configuration
* This allows to place `mutant:disable` comments next to subjects to mark them as disabled. * Inheritance is not supported currently, so a comment on a class will not make this entire class disabled.
- Loading branch information
Showing
21 changed files
with
270 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutant | ||
class Subject | ||
class Config | ||
include Adamantium, Anima.new(:inline_disable) | ||
|
||
DEFAULT = new(inline_disable: false) | ||
|
||
DISABLE_REGEXP = /(\s|^)mutant:disable(?:\s|$)/.freeze | ||
SYNTAX_REGEXP = /\A(?:#|=begin\n)/.freeze | ||
|
||
def self.parse(comments) | ||
new( | ||
inline_disable: comments.any? { |comment| DISABLE_REGEXP.match?(comment_body(comment)) } | ||
) | ||
end | ||
|
||
def self.comment_body(comment) | ||
comment.text.sub(SYNTAX_REGEXP, '') | ||
end | ||
private_class_method :comment_body | ||
end # Config | ||
end # Subject | ||
end # Mutant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
module Mutant | ||
# Current mutant version | ||
VERSION = '0.11.7' | ||
VERSION = '0.11.8' | ||
end # Mutant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Mutant::Subject::Config do | ||
describe '.parse' do | ||
def apply | ||
described_class.parse(comments) | ||
end | ||
|
||
let(:comments) do | ||
node, comments = Unparser.parse_with_comments(source) | ||
|
||
::Parser::Source::Comment.associate_by_identity(node, comments).fetch(node, []) | ||
end | ||
|
||
shared_examples 'returns default config' do | ||
it 'returns default config' do | ||
expect(apply).to eql(described_class::DEFAULT) | ||
end | ||
end | ||
|
||
shared_examples 'returns disabled config' do | ||
it 'returns default config' do | ||
expect(apply).to eql(described_class.new(inline_disable: true)) | ||
end | ||
end | ||
|
||
context 'on empty comments' do | ||
let(:source) do | ||
<<~'RUBY' | ||
def foo | ||
end | ||
RUBY | ||
end | ||
|
||
include_examples 'returns default config' | ||
end | ||
|
||
context 'on comment not mentioning a mutant disable' do | ||
context 'in a line comment' do | ||
let(:source) do | ||
<<~'RUBY' | ||
# rubocop:disable Metrics/Something | ||
def foo | ||
end | ||
RUBY | ||
end | ||
|
||
include_examples 'returns default config' | ||
end | ||
|
||
context 'in a block comment' do | ||
let(:source) do | ||
<<~'RUBY' | ||
=begin | ||
rubocop:disable Metrics/Something | ||
=end | ||
def foo | ||
end | ||
RUBY | ||
end | ||
|
||
include_examples 'returns default config' | ||
end | ||
end | ||
|
||
context 'on comment mentioning a mutant disable' do | ||
context 'in a block comment' do | ||
let(:source) do | ||
<<~'RUBY' | ||
=begin | ||
mutant:disable | ||
=end | ||
def foo | ||
end | ||
RUBY | ||
end | ||
|
||
include_examples 'returns disabled config' | ||
end | ||
|
||
context 'in a line comment' do | ||
context 'with space' do | ||
let(:source) do | ||
<<~'RUBY' | ||
# mutant:disable | ||
def foo | ||
end | ||
RUBY | ||
end | ||
|
||
include_examples 'returns disabled config' | ||
end | ||
|
||
context 'without space' do | ||
let(:source) do | ||
<<~'RUBY' | ||
#mutant:disable | ||
def foo | ||
end | ||
RUBY | ||
end | ||
|
||
include_examples 'returns disabled config' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.