Skip to content

Commit

Permalink
Remove test_setups
Browse files Browse the repository at this point in the history
Attribute test_setups is replaced by verification_methods. This
PR removes the backward compatibility for test_setups.

Fixes: esrlabs#24
  • Loading branch information
sudeeptarlekar committed Dec 3, 2024
1 parent 9433d73 commit 46755ac
Show file tree
Hide file tree
Showing 64 changed files with 120 additions and 474 deletions.
2 changes: 0 additions & 2 deletions dim/lib/dim/commands/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ def format_file(data)

req.delete_if { |_key, value| value.nil? }

req.delete('test_setups')

%w[tags verification_methods refs].each do |e|
req[e] = req[e].cleanUniqString if req.key?(e) && req[e].is_a?(String)
end
Expand Down
32 changes: 1 addition & 31 deletions dim/lib/dim/consistency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,9 @@ def insert_default_values(req)
def insert_property_file_definitions(ref)
@loader.property_table.fetch(ref.document, {}).each do |attr, value|
ref.data[attr] = value if ref.data[attr].nil?

if attr == 'test_setups' && (ref.data['verification_methods'].nil? || ref.data['verification_methods'] == '')
ref.data['verification_methods'] = value
end
end
end

def merge_test_setups_and_verification_methods(ref)
return if ref.data.key?('verification_methods') && !ref.data['verification_methods'].nil?

ref.data['verification_methods'] = ref.data['test_setups'].clone
end

def calculate_test_setups(ref)
return unless ref.data['test_setups'].nil?

tags = ref.data['tags'].cleanArray

ref.data['test_setups'] = if ref.data['type'] != 'requirement' || tags.include?('process')
'none'
elsif ref.category == 'input' || ref.category == 'unspecified'
'none'
elsif ref.category == 'module'
'off_target'
elsif tags.include?('tool')
'off_target'
else
'on_target'
end
end

def calculate_verification_methods(ref)
return unless ref.data['verification_methods'].nil?

Expand Down Expand Up @@ -106,7 +78,7 @@ def calculate_review_status(ref)
end

def clean_comma_separated(ref)
%w[tags developer tester refs test_setups verification_methods].each do |var|
%w[tags developer tester refs verification_methods].each do |var|
ref.data[var] = ref.data[var].cleanString
end
end
Expand Down Expand Up @@ -141,8 +113,6 @@ def check(allow_missing:)
@loader.requirements.each do |_id, r|
insert_property_file_definitions(r)
insert_default_values(r)
merge_test_setups_and_verification_methods(r)
calculate_test_setups(r)
calculate_verification_methods(r)
calculate_review_status(r)
calculate_developer_tester(r)
Expand Down
1 change: 0 additions & 1 deletion dim/lib/dim/exporter/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Csv < ExporterInterface

def header(content)
@keys = @loader.all_attributes.keys
@keys.delete('test_setups')
content.puts 'Sep=,'
content.puts "id,document_name,originator,#{@keys.join(',')}"
end
Expand Down
2 changes: 0 additions & 2 deletions dim/lib/dim/exporter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def requirement(_f, r)
vals = { 'id' => r.id, 'document_name' => r.document, 'originator' => r.origin }

@loader.all_attributes.keys.each do |k|
next if k == 'test_setups'

v = r.data[k]
v = v.cleanUniqArray.join(',') if k == 'refs'
vals[k] = v.strip
Expand Down
3 changes: 0 additions & 3 deletions dim/lib/dim/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,6 @@ def load_file(filename:, origin:, silent:, category:, disable_naming_convention_
else
Dim::ExitHelper.exit(code: 1, filename: filename, msg: "attributes for id \"#{id}\" must be key-value pairs")
end
unless attr.key?('verification_methods')
attr['verification_methods'] = attr['test_setups'] if attr.key?('test_setups')
end
attr.each do |key, value|
unless value.is_a?(String)
Dim::ExitHelper.exit(code: 1, filename: filename,
Expand Down
22 changes: 2 additions & 20 deletions dim/lib/dim/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ class Requirement
allowed: %w[QM CAL_1 CAL_2 CAL_3 CAL_4 not_set] },
'developer' => { check: nil, format_style: :list, format_shift: 0, default: nil, allowed: nil },
'tester' => { check: nil, format_style: :list, format_shift: 0, default: nil, allowed: nil },
'test_setups' => { check: :check_multi_enum, format_style: :multi, format_shift: 0, default: nil,
allowed: %w[none off_target on_target manual] },
'verification_methods' => { check: :check_multi_enum, format_style: :multi, format_shift: 0, default: nil,
'verification_methods' => { check: :check_multi_enum, format_style: :multi, format_shift: 0, default: nil,
allowed: %w[none off_target on_target manual] },
'status' => { check: :check_single_enum, format_style: :single, format_shift: 0, default: nil,
allowed: %w[valid draft invalid] },
Expand Down Expand Up @@ -101,8 +99,6 @@ def initialize(id, document, filename, attr, origin, loader, category, line_numb

check_unknown_keys
check_invalid_values
# TODO: Remove after completely removing test_setups
merge_test_setups_and_verification_methods
check_verification_methods
end

Expand Down Expand Up @@ -208,28 +204,14 @@ def check_invalid_values
end
end

def merge_test_setups_and_verification_methods
# Given verification_methods is empty
# Given test_setups contains None
# Then return None
ts = @data['test_setups']&.cleanArray || []
vm = @data['verification_methods']&.cleanArray || []

return if vm.empty? && ts.empty?

merged = ts.union(vm).join(', ')
@data['test_setups'] = merged
@data['verification_methods'] = merged
end

def check_verification_methods
vm = @data['verification_methods']&.cleanArray || []
return unless vm.include?('none') && vm.length > 1

vm.delete('none')
Dim::ExitHelper.exit(code: 1,
filename: filename,
msg: "verification_methods or test_setups for \"#{@id}\" can't include 'none' along with #{vm.join(', ')}.")
msg: "verification_methods for \"#{@id}\" can't include 'none' along with #{vm.join(', ')}.")
end
end
end
29 changes: 0 additions & 29 deletions dim/req/dim.dim
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,6 @@ Dim_ReqFiles_tester:
lib/dim/loader.rb,
lib/dim/consistency.rb

Dim_ReqFiles_testSetups:
text: |
A requirements object shall have an optional "test_setups" attribute.
Allowed values: one or more of "none", "off_target", "on_target", "manual"
If test_setups is missing, it is resolved to:
- "none" if
- type is not "requirement" or
- "process" is in tags or
- category is "input" or "unspecified"
- "off_target" if
- category is "module" or
- tags include "tool"
- "on_target" otherwise
tags: tool, covered, tested
status: valid
sources: >
lib/dim/requirement.rb,
lib/dim/loader.rb,
lib/dim/consistency.rb

Dim_ReqFiles_verificationMethods:
text: |
A requirement object shall have an optional 'verification_methods' attribute.
Expand All @@ -291,15 +271,6 @@ Dim_ReqFiles_verificationMethods:
status: valid
sources: lib/dim/requirement.rb lib/dim/loader.rb lib/dim/consistency.rb

Dim_ReqFiles_verificationMethods_backward:
text: |
"verification_methods" replaces "test_setups".
For backward compatibility, the requirements file can include both "test_setups" and "verification_methods".
During loading, Dim shall merge values from both attributes.
tags: tool, covered, tested
status: valid
sources: lib/dim/requirement.rb lib/dim/consistency.rb lib/dim/loader.rb

Dim_ReqFiles_status:
text: |
A requirements object shall have an optional "status" attribute.
Expand Down
29 changes: 0 additions & 29 deletions dim/spec/export_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,35 +266,6 @@ module Dim
end
end

context 'verification_methods' do
context 'to json' do
it 'shall not add test_setups in exported format', doc_refs: ['Dim_export_verificationMethods'] do
Test.main("export -i #{TEST_INPUT_DIR}/verification_methods/verification_methods.dim -o #{TEST_OUTPUT_DIR} -f json")
expected = File.read("#{TEST_INPUT_DIR}/verification_methods/output/verification_methods/Requirements.json")
actual = File.read("#{TEST_OUTPUT_DIR}/verification_method_test/Requirements.json")
expect(actual).to eq expected
end
end

context 'to RST' do
it 'shall not add test_setups in exported output', doc_refs: ['Dim_export_verificationMethods'] do
Test.main("export -i #{TEST_INPUT_DIR}/verification_methods/verification_methods.dim -o #{TEST_OUTPUT_DIR} -f rst")
expected = File.read("#{TEST_INPUT_DIR}/verification_methods/output/verification_methods/Requirements.rst").universal_newline
actual = File.read("#{TEST_OUTPUT_DIR}/verification_method_test/Requirements.rst").universal_newline
expect(actual).to eq expected
end
end

context 'to csv' do
it 'shall not add test_setups in exported output', doc_refs: ['Dim_export_verificationMethods'] do
Test.main("export -i #{TEST_INPUT_DIR}/verification_methods/verification_methods.dim -o #{TEST_OUTPUT_DIR} -f csv")
expected = File.read("#{TEST_INPUT_DIR}/verification_methods/output/verification_methods/Requirement.csv")
actual = File.read("#{TEST_OUTPUT_DIR}/verification_method_test/Requirements.csv")
expect(actual).to eq expected
end
end
end

context 'document' do
context 'to json' do
it 'shall export document dim file', doc_refs: %w[Dim_export_general] do
Expand Down
26 changes: 0 additions & 26 deletions dim/spec/format_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def compareFormat(f)

it 'multi enums', doc_refs: %w[Dim_format_whitespaces Dim_format_default Dim_format_duplicated] do
compareFormat('collection/tags.dim')
compareFormat('collection/test_setups.dim')
compareFormat('collection/verification_methods.dim')
end

Expand Down Expand Up @@ -152,31 +151,6 @@ def compareFormat(f)
end
end

context 'shall not include test_setups' do
it 'shall format the document with verification_methods and not test_setups',
doc_refs: %w[Dim_format_verificationMethods] do
Test.main("format -i #{TEST_INPUT_DIR}/verification_methods/verification_methods.dim --output-format extra")
expected = File.read("#{TEST_INPUT_DIR}/verification_methods/verification_methods.dim.expected")
actual = File.read("#{TEST_INPUT_DIR}/verification_methods/verification_methods.dim.formatted")
expect(actual).to eq expected

Test.main("format -i #{TEST_INPUT_DIR}/verification_methods/single_none.dim --output-format extra")
expected = File.read("#{TEST_INPUT_DIR}/verification_methods/single_none.dim.expected")
actual = File.read("#{TEST_INPUT_DIR}/verification_methods/single_none.dim.formatted")
expect(actual).to eq expected

Test.main("format -i #{TEST_INPUT_DIR}/verification_methods/all_none.dim --output-format extra")
expected = File.read("#{TEST_INPUT_DIR}/verification_methods/all_none.dim.expected")
actual = File.read("#{TEST_INPUT_DIR}/verification_methods/all_none.dim.formatted")
expect(actual).to eq expected

Test.main("format -i #{TEST_INPUT_DIR}/verification_methods/single_none.dim --output-format extra")
expected = File.read("#{TEST_INPUT_DIR}/verification_methods/single_none.dim.expected")
actual = File.read("#{TEST_INPUT_DIR}/verification_methods/single_none.dim.formatted")
expect(actual).to eq expected
end
end

context 'shall ignore different line-endings:' do
it 'LF compared to OS default', doc_refs: ['Dim_format_checkOnly'] do
content = File.read("#{TEST_INPUT_DIR}/format_lineendings/lf.dim", mode: 'rb')
Expand Down
2 changes: 0 additions & 2 deletions dim/spec/property_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ module Dim
expect(loader.requirements['test_module_for_insertion_empty'].data['tags']).to eql 'legal, sys'
expect(loader.requirements['test_module_for_insertion_empty'].data['developer']).to eql 'inserted developer'
expect(loader.requirements['test_module_for_insertion_empty'].data['tester']).to eql 'inserted tester'
expect(loader.requirements['test_module_for_insertion_empty'].data['test_setups']).to eql 'manual'
expect(loader.requirements['test_module_for_insertion_empty'].data['verification_methods']).to eql 'manual'
expect(loader.requirements['test_module_for_insertion_empty'].data['status']).to eql 'valid'
expect(loader.requirements['test_module_for_insertion_empty'].data['review_status']).to eql 'rejected'
Expand All @@ -91,7 +90,6 @@ module Dim
expect(loader.requirements['test_module_for_insertion_not_empty'].data['change_request']).to eql 'test_CR'
expect(loader.requirements['test_module_for_insertion_not_empty'].data['tags']).to eql 'swa'
expect(loader.requirements['test_module_for_insertion_not_empty'].data['developer']).to eql 'test_developer'
expect(loader.requirements['test_module_for_insertion_not_empty'].data['test_setups']).to eql 'none'
expect(loader.requirements['test_module_for_insertion_not_empty'].data['verification_methods']).to eql 'none'
expect(loader.requirements['test_module_for_insertion_not_empty'].data['status']).to eql 'invalid'
expect(loader.requirements['test_module_for_insertion_not_empty'].data['review_status']).to eql 'unclear'
Expand Down
Loading

0 comments on commit 46755ac

Please sign in to comment.