defmastership 1.0.6 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/bin/defmastership +12 -7
  3. data/features/changeref.feature +33 -0
  4. data/features/definition_checksum.feature +298 -0
  5. data/features/definition_version.feature +204 -0
  6. data/features/export.feature +21 -74
  7. data/features/modify.feature +23 -1
  8. data/lib/defmastership.rb +6 -0
  9. data/lib/defmastership/batch_modifier.rb +2 -0
  10. data/lib/defmastership/change_ref_line_modifier.rb +2 -1
  11. data/lib/defmastership/change_ref_modifier.rb +2 -2
  12. data/lib/defmastership/constants.rb +4 -2
  13. data/lib/defmastership/csv_formatter.rb +12 -6
  14. data/lib/defmastership/csv_formatter_body.rb +8 -5
  15. data/lib/defmastership/csv_formatter_header.rb +5 -1
  16. data/lib/defmastership/definition.rb +4 -4
  17. data/lib/defmastership/document.rb +33 -27
  18. data/lib/defmastership/modifier_base.rb +1 -1
  19. data/lib/defmastership/rename_included_files_modifier.rb +2 -17
  20. data/lib/defmastership/update_def_checksum_line_modifier.rb +38 -0
  21. data/lib/defmastership/update_def_checksum_modifier.rb +21 -0
  22. data/lib/defmastership/update_def_version_line_modifier.rb +58 -0
  23. data/lib/defmastership/update_def_version_modifier.rb +25 -0
  24. data/lib/defmastership/version.rb +1 -1
  25. data/spec/unit/defmastership/batch_modifier_spec.rb +8 -0
  26. data/spec/unit/defmastership/change_ref_line_modifier_spec.rb +15 -0
  27. data/spec/unit/defmastership/csv_formatter_body_spec.rb +42 -60
  28. data/spec/unit/defmastership/csv_formatter_header_spec.rb +23 -1
  29. data/spec/unit/defmastership/csv_formatter_spec.rb +204 -67
  30. data/spec/unit/defmastership/definition_spec.rb +19 -4
  31. data/spec/unit/defmastership/document_spec.rb +129 -5
  32. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +78 -0
  33. data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +75 -0
  34. data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +127 -0
  35. data/spec/unit/defmastership/update_def_version_modifier_spec.rb +80 -0
  36. metadata +12 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2cd7a521f197f1ab374863af89ab7a24c50bc27d5dfef6161bc47e8fff27825f
4
- data.tar.gz: a92ef2ee968e39a48e20fbf2a7d6f3040393c727a422e4f39c935978a29e187f
3
+ metadata.gz: a3085b336c6d1b3854964192456e63b586bb0841ca62be7a4e33b7a3f7e2b5e9
4
+ data.tar.gz: 190eb91c0e040f064044a9b720eeb737cf3a0064eb88c718f1f2f387d0edf47f
5
5
  SHA512:
6
- metadata.gz: ee7d58f8392a43fe5b45e234f9c4965037e2864a37a669c191d33b58016cf7094a99fe29443c3fc60678bab3e591b19188579771d14aa762fba8d4b34b01bd89
7
- data.tar.gz: 526ae0002d2f5d66f2ad555d09bc8cf9786b567098e6bc071a8b119b2cbfe6b664e84eaf3fc68e453ca16f41552a4004f23bab6323ed62cba526322f27e88b15
6
+ metadata.gz: f8c55be957d580ad9ab71f15f58be76a43fc3e2b169d7b8397383a1a6a128c93aac5c33eab85cdf3da584d005eb92699730f2ae3560947ad25f13e478f5bff1d
7
+ data.tar.gz: 8d7b95ad1db59a90e96f0caacc8040307366ae7be67baab172fe57f64c9101a065fef8718d8c2f123d03c808b1669aa406c05712872c05424b6de22150db6acf
data/bin/defmastership CHANGED
@@ -2,7 +2,6 @@
2
2
  # Copyright (c) 2020 Jerome Arbez-Gindre
3
3
  # frozen_string_literal: true
4
4
 
5
- require('asciidoctor')
6
5
  require('csv')
7
6
  require('defmastership')
8
7
  require('gli')
@@ -52,18 +51,24 @@ module DefMastership
52
51
  arg_name 'asciidoctor_files'
53
52
  command :export, :exp, :e do |c|
54
53
  c.flag(%i[separator sep s], default_value: ',', desc: 'CSV separator')
54
+ c.switch(%i[no-fail], desc: 'Exit succes even in case of wrong explicit checksum')
55
+
55
56
  c.action do |_global_options, options, args|
56
- doc = Asciidoctor.load_file(args[0], safe: :unsafe, parse: false)
57
- # FIXME: also escape ifdef, ifndef, ifeval and endif directives
58
- # FIXME: do this more carefully by reading line by line; if input
59
- # differs by output by leading backslash, restore original line
60
- lines = doc.reader.read_lines
61
57
  my_doc = DefMastership::Document.new
62
- my_doc.parse(lines)
58
+ my_doc.parse_file_with_preprocessor(args[0])
63
59
 
64
60
  output_file = args[0].sub(/\.adoc$/, '.csv')
65
61
 
66
62
  DefMastership::CSVFormatter.new(my_doc, options['separator']).export_to(output_file)
63
+
64
+ if my_doc.wrong_explicit_checksum?
65
+ my_doc.definitions.each do |definition|
66
+ next if definition.wrong_explicit_checksum.nil?
67
+
68
+ warn("warning: #{definition.reference} has a wrong explicit checksum (should be #{definition.sha256})")
69
+ end
70
+ exit 1 unless options[:"no-fail"]
71
+ end
67
72
  end
68
73
  end
69
74
 
@@ -36,6 +36,39 @@ Feature: The changeref command
36
36
  [define, requirement, TOTO-0123]
37
37
  """
38
38
 
39
+ Scenario: Change a definition with explicit checksum and version
40
+ Given a file named "modifications.yml" with:
41
+ """
42
+ ---
43
+ :toto:
44
+ :type: change_ref
45
+ :config:
46
+ :from_regexp: TOTO-TEMP-[X\d]{4}
47
+ :to_template: TOTO-%<next_ref>04d
48
+ :next_ref: 123
49
+ """
50
+ And a file named "thedoc.adoc" with:
51
+ """
52
+ [define, requirement, TOTO-TEMP-XXX1(a~12345678)]
53
+ """
54
+ When I successfully run `defmastership modify --modifications toto thedoc.adoc`
55
+ Then the stdout should not contain anything
56
+ And the stderr should not contain anything
57
+ And the file "modifications.yml" should contain:
58
+ """
59
+ ---
60
+ :toto:
61
+ :type: change_ref
62
+ :config:
63
+ :from_regexp: TOTO-TEMP-[X\d]{4}
64
+ :to_template: TOTO-%<next_ref>04d
65
+ :next_ref: 124
66
+ """
67
+ And the file "thedoc.adoc" should contain:
68
+ """
69
+ [define, requirement, TOTO-0123(a~12345678)]
70
+ """
71
+
39
72
  Scenario: Change two definitions
40
73
  Given a file named "modifications.yml" with:
41
74
  """
@@ -0,0 +1,298 @@
1
+ Feature: definition checksum
2
+ As a Responsible of definitions for a given document
3
+ In order to detect modifications of defintiions
4
+ I want defmastership to export and update checksum in definitions
5
+
6
+ Scenario: Extract one definition with WRONG explicit checksum to CSV
7
+ Given a file named "thedoc.adoc" with:
8
+ """
9
+ [define, requirement, TOTO-0001(~babe1234)]
10
+ def one
11
+ """
12
+ When I run `defmastership export thedoc.adoc`
13
+ Then it should fail with:
14
+ """
15
+ warning: TOTO-0001 has a wrong explicit checksum (should be ~d27cb5c3)
16
+ """
17
+ And the file "thedoc.csv" should contain:
18
+ """
19
+ Type,Reference,Value,Checksum,Wrong explicit checksum
20
+ requirement,TOTO-0001,def one,~d27cb5c3,~babe1234
21
+ """
22
+ And the stdout should not contain anything
23
+
24
+ Scenario: Extract two definitions with one WRONG explicit checksum to CSV
25
+ Given a file named "thedoc.adoc" with:
26
+ """
27
+ [define, requirement, TOTO-0001(~d27cb5c3)]
28
+ def one
29
+
30
+ [define, requirement, TOTO-0002(~babe1234)]
31
+ def two
32
+ """
33
+ When I run `defmastership export thedoc.adoc`
34
+ Then it should fail with:
35
+ """
36
+ warning: TOTO-0002 has a wrong explicit checksum (should be ~b80e1be5)
37
+ """
38
+ Then the file "thedoc.csv" should contain:
39
+ """
40
+ Type,Reference,Value,Checksum,Wrong explicit checksum
41
+ requirement,TOTO-0001,def one,~d27cb5c3,\"\"
42
+ requirement,TOTO-0002,def two,~b80e1be5,~babe1234
43
+ """
44
+ And the stdout should not contain anything
45
+
46
+ Scenario: Export not failing even if WRONG explicit checksum
47
+ Given a file named "thedoc.adoc" with:
48
+ """
49
+ [define, requirement, TOTO-0001(~d27cb5c3)]
50
+ def one
51
+
52
+ [define, requirement, TOTO-0002(~babe1234)]
53
+ def two
54
+ """
55
+ When I successfully run `defmastership export --no-fail thedoc.adoc`
56
+ Then the file "thedoc.csv" should contain:
57
+ """
58
+ Type,Reference,Value,Checksum,Wrong explicit checksum
59
+ requirement,TOTO-0001,def one,~d27cb5c3,\"\"
60
+ requirement,TOTO-0002,def two,~b80e1be5,~babe1234
61
+ """
62
+ And the stdout should not contain anything
63
+ And the stderr should contain:
64
+ """
65
+ warning: TOTO-0002 has a wrong explicit checksum (should be ~b80e1be5)
66
+ """
67
+
68
+ Scenario: Extract one definition with explicit checksum to CSV
69
+ Given a file named "thedoc.adoc" with:
70
+ """
71
+ [define, requirement, TOTO-0001(~b86dcbde)]
72
+ --
73
+ Exemple of multiline requirement.
74
+ Second line.
75
+ --
76
+ """
77
+ When I successfully run `defmastership export thedoc.adoc`
78
+ Then the file "thedoc.csv" should contain:
79
+ """
80
+ Type,Reference,Value,Checksum
81
+ requirement,TOTO-0001,"Exemple of multiline requirement.
82
+ Second line.",~b86dcbde
83
+ """
84
+ And the stdout should not contain anything
85
+ And the stderr should not contain anything
86
+
87
+ Scenario: Change one modifier
88
+ Given a file named "modifications.yml" with:
89
+ """
90
+ ---
91
+ :update_requirement_checksum:
92
+ :type: update_def_checksum
93
+ :config:
94
+ :def_type: requirement
95
+ """
96
+ And a file named "thedoc.adoc" with:
97
+ """
98
+ [define, requirement, TOTO-TEMP-XXX1]
99
+ --
100
+ the requirement value.
101
+ --
102
+ """
103
+ When I successfully run `defmastership modify --modifications update_requirement_checksum thedoc.adoc`
104
+ Then the stdout should not contain anything
105
+ And the stderr should not contain anything
106
+ And the file "thedoc.adoc" should contain:
107
+ """
108
+ [define, requirement, TOTO-TEMP-XXX1(~244eed18)]
109
+ --
110
+ the requirement value.
111
+ --
112
+ """
113
+
114
+ Scenario: Change one modifier with already set checksum
115
+ Given a file named "modifications.yml" with:
116
+ """
117
+ ---
118
+ :update_requirement_checksum:
119
+ :type: update_def_checksum
120
+ :config:
121
+ :def_type: requirement
122
+ """
123
+ And a file named "thedoc.adoc" with:
124
+ """
125
+ [define, requirement, TOTO-TEMP-XXX1(~abcd1234)]
126
+ --
127
+ the requirement value.
128
+ --
129
+ """
130
+ When I successfully run `defmastership modify --modifications update_requirement_checksum thedoc.adoc`
131
+ Then the stdout should not contain anything
132
+ And the stderr should not contain anything
133
+ And the file "thedoc.adoc" should contain:
134
+ """
135
+ [define, requirement, TOTO-TEMP-XXX1(~244eed18)]
136
+ --
137
+ the requirement value.
138
+ --
139
+ """
140
+
141
+ Scenario: Checksum is calculated on included file for export
142
+ Given a file named "thedoc.adoc" with:
143
+ """
144
+ [define, requirement, TOTO-0001]
145
+ --
146
+ include::included.txt[]
147
+ --
148
+ """
149
+ And a file named "included.txt" with:
150
+ """
151
+ Exemple of multiline requirement.
152
+ Second line.
153
+ """
154
+ When I successfully run `defmastership export thedoc.adoc`
155
+ Then the file "thedoc.csv" should contain:
156
+ """
157
+ Type,Reference,Value,Checksum
158
+ requirement,TOTO-0001,"Exemple of multiline requirement.
159
+ Second line.",~b86dcbde
160
+ """
161
+ And the stdout should not contain anything
162
+ And the stderr should not contain anything
163
+
164
+ Scenario: Checksum is calculated on included file in ref modification
165
+ Given a file named "modifications.yml" with:
166
+ """
167
+ ---
168
+ :update_requirement_checksum:
169
+ :type: update_def_checksum
170
+ :config:
171
+ :def_type: requirement
172
+ """
173
+ And a file named "thedoc.adoc" with:
174
+ """
175
+ [define, requirement, TOTO-0001]
176
+ --
177
+ include::included.txt[]
178
+ --
179
+ """
180
+ And a file named "included.txt" with:
181
+ """
182
+ Exemple of multiline requirement.
183
+ Second line.
184
+ """
185
+ When I successfully run `defmastership modify --modifications update_requirement_checksum thedoc.adoc`
186
+ Then the file "thedoc.adoc" should contain:
187
+ """
188
+ [define, requirement, TOTO-0001(~b86dcbde)]
189
+ --
190
+ include::included.txt[]
191
+ --
192
+ """
193
+ And the stdout should not contain anything
194
+ And the stderr should not contain anything
195
+
196
+ Scenario: Checksum take into account variables in CSV export
197
+ Given a file named "thedoc.adoc" with:
198
+ """
199
+ :variable: multiline
200
+ [define, requirement, TOTO-0001]
201
+ --
202
+ Exemple of {variable} requirement.
203
+ Second line.
204
+ --
205
+ """
206
+ When I successfully run `defmastership export thedoc.adoc`
207
+ Then the file "thedoc.csv" should contain:
208
+ """
209
+ Type,Reference,Value,Checksum
210
+ requirement,TOTO-0001,"Exemple of multiline requirement.
211
+ Second line.",~b86dcbde
212
+ """
213
+ And the stdout should not contain anything
214
+ And the stderr should not contain anything
215
+
216
+ Scenario: Checksum take into account variables in ref modification
217
+ Given a file named "modifications.yml" with:
218
+ """
219
+ ---
220
+ :update_requirement_checksum:
221
+ :type: update_def_checksum
222
+ :config:
223
+ :def_type: requirement
224
+ """
225
+ And a file named "thedoc.adoc" with:
226
+ """
227
+ :variable: multiline
228
+ [define, requirement, TOTO-0001]
229
+ --
230
+ Exemple of {variable} requirement.
231
+ Second line.
232
+ --
233
+ """
234
+ When I successfully run `defmastership modify --modifications update_requirement_checksum thedoc.adoc`
235
+ Then the file "thedoc.adoc" should contain:
236
+ """
237
+ [define, requirement, TOTO-0001(~b86dcbde)]
238
+ --
239
+ Exemple of {variable} requirement.
240
+ Second line.
241
+ --
242
+ """
243
+ And the stdout should not contain anything
244
+ And the stderr should not contain anything
245
+
246
+ Scenario: Checksum keep explicit version in ref modification
247
+ Given a file named "modifications.yml" with:
248
+ """
249
+ ---
250
+ :update_requirement_checksum:
251
+ :type: update_def_checksum
252
+ :config:
253
+ :def_type: requirement
254
+ """
255
+ And a file named "thedoc.adoc" with:
256
+ """
257
+ [define, requirement, TOTO-TEMP-XXX1(toto~abcd1234)]
258
+ --
259
+ the requirement value.
260
+ --
261
+ """
262
+ When I successfully run `defmastership modify --modifications update_requirement_checksum thedoc.adoc`
263
+ Then the stdout should not contain anything
264
+ And the stderr should not contain anything
265
+ And the file "thedoc.adoc" should contain:
266
+ """
267
+ [define, requirement, TOTO-TEMP-XXX1(toto~244eed18)]
268
+ --
269
+ the requirement value.
270
+ --
271
+ """
272
+
273
+ Scenario: Checksum keep explicit version in ref setting
274
+ Given a file named "modifications.yml" with:
275
+ """
276
+ ---
277
+ :update_requirement_checksum:
278
+ :type: update_def_checksum
279
+ :config:
280
+ :def_type: requirement
281
+ """
282
+ And a file named "thedoc.adoc" with:
283
+ """
284
+ [define, requirement, TOTO-TEMP-XXX1(toto)]
285
+ --
286
+ the requirement value.
287
+ --
288
+ """
289
+ When I successfully run `defmastership modify --modifications update_requirement_checksum thedoc.adoc`
290
+ Then the stdout should not contain anything
291
+ And the stderr should not contain anything
292
+ And the file "thedoc.adoc" should contain:
293
+ """
294
+ [define, requirement, TOTO-TEMP-XXX1(toto~244eed18)]
295
+ --
296
+ the requirement value.
297
+ --
298
+ """
@@ -0,0 +1,204 @@
1
+ Feature: definitions version
2
+ As a Responsible of definitions for a given document
3
+ In order to detect handle versions definitions
4
+ I want defmastership to export explicit versions in definitions
5
+
6
+ Scenario: Extract one definition with explicit version to CSV
7
+ Given a file named "thedoc.adoc" with:
8
+ """
9
+ [define, requirement, TOTO-0001(pouet)]
10
+ --
11
+ Exemple of multiline requirement.
12
+ Second line.
13
+ --
14
+ """
15
+ When I successfully run `defmastership export thedoc.adoc`
16
+ Then the file "thedoc.csv" should contain:
17
+ """
18
+ Type,Reference,Value,Checksum,Version
19
+ requirement,TOTO-0001,"Exemple of multiline requirement.
20
+ Second line.",~b86dcbde,pouet
21
+ """
22
+ And the stdout should not contain anything
23
+ And the stderr should not contain anything
24
+
25
+ Scenario: Set initial explicit version when definition has changed
26
+ Given a file named "ref_doc.adoc" with:
27
+ """
28
+ [define, requirement, TOTO-0001]
29
+ --
30
+ initial text.
31
+ --
32
+ """
33
+ Given a file named "thedoc.adoc" with:
34
+ """
35
+ [define, requirement, TOTO-0001(whatever)]
36
+ --
37
+ modified text.
38
+ --
39
+ """
40
+ And a file named "modifications.yml" with:
41
+ """
42
+ ---
43
+ :update_requirement_version:
44
+ :type: update_def_version
45
+ :config:
46
+ :def_type: requirement
47
+ :first_version: a
48
+ :ref_document: ./ref_doc.adoc
49
+ """
50
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
51
+ And the stdout should not contain anything
52
+ And the stderr should not contain anything
53
+ Then the file "thedoc.adoc" should contain:
54
+ """
55
+ [define, requirement, TOTO-0001(a)]
56
+ --
57
+ modified text.
58
+ --
59
+ """
60
+
61
+ Scenario: Do not set initial explicit version when definition has NOT changed
62
+ Given a file named "ref_doc.adoc" with:
63
+ """
64
+ [define, requirement, TOTO-0001]
65
+ --
66
+ initial text.
67
+ --
68
+ """
69
+ Given a file named "thedoc.adoc" with:
70
+ """
71
+ [define, requirement, TOTO-0001(whatever)]
72
+ --
73
+ initial text.
74
+ --
75
+ """
76
+ And a file named "modifications.yml" with:
77
+ """
78
+ ---
79
+ :update_requirement_version:
80
+ :type: update_def_version
81
+ :config:
82
+ :def_type: requirement
83
+ :first_version: a
84
+ :ref_document: ./ref_doc.adoc
85
+ """
86
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
87
+ And the stdout should not contain anything
88
+ And the stderr should not contain anything
89
+ Then the file "thedoc.adoc" should contain:
90
+ """
91
+ [define, requirement, TOTO-0001]
92
+ --
93
+ initial text.
94
+ --
95
+ """
96
+
97
+ Scenario: Set initial explicit version when definition has changed and ref is not an initial version
98
+ Given a file named "ref_doc.adoc" with:
99
+ """
100
+ [define, requirement, TOTO-0001(3)]
101
+ --
102
+ initial text.
103
+ --
104
+ """
105
+ Given a file named "thedoc.adoc" with:
106
+ """
107
+ [define, requirement, TOTO-0001(whatever)]
108
+ --
109
+ modified text.
110
+ --
111
+ """
112
+ And a file named "modifications.yml" with:
113
+ """
114
+ ---
115
+ :update_requirement_version:
116
+ :type: update_def_version
117
+ :config:
118
+ :def_type: requirement
119
+ :first_version: 1
120
+ :ref_document: ./ref_doc.adoc
121
+ """
122
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
123
+ And the stdout should not contain anything
124
+ And the stderr should not contain anything
125
+ Then the file "thedoc.adoc" should contain:
126
+ """
127
+ [define, requirement, TOTO-0001(4)]
128
+ --
129
+ modified text.
130
+ --
131
+ """
132
+
133
+ Scenario: No initial explicit version when definition is new
134
+ Given a file named "ref_doc.adoc" with:
135
+ """
136
+ [define, requirement, TOTO-0002]
137
+ --
138
+ initial text.
139
+ --
140
+ """
141
+ Given a file named "thedoc.adoc" with:
142
+ """
143
+ [define, requirement, TOTO-0001(whatever)]
144
+ --
145
+ modified text.
146
+ --
147
+ """
148
+ And a file named "modifications.yml" with:
149
+ """
150
+ ---
151
+ :update_requirement_version:
152
+ :type: update_def_version
153
+ :config:
154
+ :def_type: requirement
155
+ :first_version: 1
156
+ :ref_document: ./ref_doc.adoc
157
+ """
158
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
159
+ And the stdout should not contain anything
160
+ And the stderr should not contain anything
161
+ Then the file "thedoc.adoc" should contain:
162
+ """
163
+ [define, requirement, TOTO-0001]
164
+ --
165
+ modified text.
166
+ --
167
+ """
168
+
169
+ Scenario: update explicit version whith explicit checksum
170
+ Given a file named "ref_doc.adoc" with:
171
+ """
172
+ [define, requirement, TOTO-0001]
173
+ --
174
+ initial text.
175
+ --
176
+ """
177
+ Given a file named "thedoc.adoc" with:
178
+ """
179
+ [define, requirement, TOTO-0001(whatever~abcd1234)]
180
+ --
181
+ modified text.
182
+ --
183
+ """
184
+ And a file named "modifications.yml" with:
185
+ """
186
+ ---
187
+ :update_requirement_version:
188
+ :type: update_def_version
189
+ :config:
190
+ :def_type: requirement
191
+ :first_version: a
192
+ :ref_document: ./ref_doc.adoc
193
+ """
194
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
195
+ And the stdout should not contain anything
196
+ And the stderr should not contain anything
197
+ Then the file "thedoc.adoc" should contain:
198
+ """
199
+ [define, requirement, TOTO-0001(a~abcd1234)]
200
+ --
201
+ modified text.
202
+ --
203
+ """
204
+