-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathtest_case_metadata.rb
More file actions
113 lines (93 loc) · 2.95 KB
/
test_case_metadata.rb
File metadata and controls
113 lines (93 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require 'pathname'
require 'yaml'
module SassSpec
class TestCaseMetadata
def self.cache
@metadata_cache ||= {}
end
# If you change this, also change Annotate::CLI#annotate_path
def self.merge_options(existing_opts, new_opts)
existing_opts = existing_opts.dup
new_opts.each do |key, value|
if key =~ /add_(.*)/
key = $1.to_sym
existing_opts[key] ||= []
value.each do |v|
existing_opts[key] << v
end
existing_opts[key].uniq!
elsif key =~ /remove_(.*)/
key = $1.to_sym
existing_opts[key] ||= []
value.each do |v|
existing_opts[key].delete(v)
end
existing_opts.delete(key) if existing_opts[key].empty?
elsif value.nil?
existing_opts.delete(key)
else
existing_opts[key] = value
end
end
existing_opts
end
ACCUMULATED_OPTIONS = [:todo, :warning_todo, :ignore_for, :ignore_warning_for, :only_on, :warning_only_on]
attr_reader :options
# The name of the test.
#
# This is a standardized format of the test's directory name.
attr_reader :name
# Parses metadata for the test case at the given SassSpec::Directory.
def initialize(test_case_dir)
@name = test_case_dir.to_s
@options = resolve_options(test_case_dir).freeze
end
def _resolve_options(dir)
return {} unless parent = dir.parent
parent_options = resolve_options(parent)
self_options = if dir.file?("options.yml")
YAML.load(dir.read("options.yml"))
else
{}
end
raise "#{dir.path}/options.yml is not a map!" unless self_options.is_a?(Hash)
rv = parent_options.merge(self_options) do |key, parent_value, self_value|
if ACCUMULATED_OPTIONS.include?(key)
(Array(parent_value) + Array(self_value)).uniq
else
self_value
end
end
rv
end
def resolve_options(dir)
self.class.cache[dir.path] ||= _resolve_options(dir).freeze
end
def todo?(impl)
@options[:todo] && @options[:todo].include?(impl)
end
def warning_todo?(impl)
@options[:warning_todo] && @options[:warning_todo].include?(impl)
end
def all_warning_todos
@options[:warning_todo] || []
end
def ignore_for?(impl)
(@options[:ignore_for] && @options[:ignore_for].include?(impl)) ||
(@options[:only_on] && !@options[:only_on].include?(impl))
end
def ignore_warning_for?(impl)
(@options[:ignore_warning_for] && @options[:ignore_warning_for].include?(impl)) ||
(@options[:warning_only_on] && @options[:warning_only_on].include?(impl))
end
def warnings_ignored_for
@options[:ignore_warning_for] || []
end
def precision
@options[:precision]
end
def valid_for_impl?(impl)
!ignore_for?(impl)
end
end
end