Skip to content

Commit cd85dc3

Browse files
lucasborinlarshp
andauthored
1.08.0 (#241)
* solves #225 (#231) * Update changelog.txt * y_object_creation_date, fix newlines between methods (#233) * solves #219 (#235) * Update changelog.txt * solves 234 (#237) and improve buffer * Update changelog.txt * Minor Refactoring (#240) * Version 1.08.0 * disabling sorter unit test (compatibility to 7.40) * Deprecated AUnit (#238) * solves #236 * solves #236 * Update changelog.txt * Reverting IF_ABAP_UNIT_CONSTANT Not compatible to ABAP 7.40 (see #241) Co-authored-by: Lars Hvam <[email protected]>
1 parent 1390741 commit cd85dc3

24 files changed

+564
-373
lines changed

changelog.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ Legend
1010

1111
2020-11-16 v1.08.0
1212
------------------
13-
14-
13+
! deprecated classes/interfaces (aunit)
14+
* short dump in unit test fixed
15+
! unit test using buffer with shared memory
16+
* prefer is not exempts line_exists( )
17+
* check order in sci
1518

1619
2020-11-11 v1.07.0
1720
------------------

src/checks/y_check_branch_coverage.clas.abap

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ CLASS y_check_branch_coverage IMPLEMENTATION.
2828

2929
METHOD execute_check.
3030

31-
DATA(unit_test_coverage) = y_unit_test_coverage=>get_instance( ).
32-
33-
unit_test_coverage->execute( me ).
34-
35-
DATA(coverage) = unit_test_coverage->get_branch_coverage( ).
31+
TRY.
32+
DATA(coverage) = y_unit_test_coverage=>get( program_name = program_name
33+
object = VALUE #( object = object_type obj_name = object_name )
34+
coverage_type = ce_scv_coverage_type=>branch ).
35+
CATCH cx_scv_execution_error.
36+
RETURN.
37+
ENDTRY.
3638

3739
DATA(check_configuration) = detect_check_configuration( error_count = CONV #( coverage )
3840
statement = VALUE #( level = 1 ) ).

src/checks/y_check_cx_root_usage.clas.abap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ENDCLASS.
1616

1717

1818

19-
CLASS Y_CHECK_CX_ROOT_USAGE IMPLEMENTATION.
19+
CLASS y_check_cx_root_usage IMPLEMENTATION.
2020

2121

2222
METHOD constructor.

src/checks/y_check_cx_root_usage.clas.testclasses.abap

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
CLASS local_test_class DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
1+
CLASS ltc_single_exception DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
22
PROTECTED SECTION.
33
METHODS get_cut REDEFINITION.
44
METHODS get_code_with_issue REDEFINITION.
55
METHODS get_code_without_issue REDEFINITION.
66
METHODS get_code_with_exemption REDEFINITION.
77
ENDCLASS.
88

9-
CLASS local_test_class IMPLEMENTATION.
9+
CLASS ltc_single_exception IMPLEMENTATION.
1010

1111
METHOD get_cut.
1212
result ?= NEW y_check_cx_root_usage( ).
@@ -17,17 +17,16 @@ CLASS local_test_class IMPLEMENTATION.
1717
( ' REPORT y_example. ' )
1818

1919
( ' CLASS y_example_class DEFINITION. ' )
20-
( ' PUBLIC SECTION. ' )
2120
( ' PROTECTED SECTION. ' )
2221
( ' METHODS example RETURNING VALUE(result) TYPE abap_bool. ' )
2322
( ' ENDCLASS. ' )
2423

2524
( ' CLASS y_example_class IMPLEMENTATION.' )
2625
( ' METHOD example.' )
2726
( ' TRY.' )
28-
( ' RAISE EXCEPTION TYPE cx_demo_constructor.' )
29-
( ' CATCH cx_failed cx_root.' )
30-
( ' result = abap_true.' )
27+
( ' RAISE EXCEPTION TYPE cx_demo_constructor.' )
28+
( ' CATCH cx_root.' )
29+
( ' result = abap_true.' )
3130
( ' ENDTRY.' )
3231
( ' ENDMETHOD.' )
3332
( 'ENDCLASS.' )
@@ -39,17 +38,16 @@ CLASS local_test_class IMPLEMENTATION.
3938
( ' REPORT y_example. ' )
4039

4140
( ' CLASS y_example_class DEFINITION. ' )
42-
( ' PUBLIC SECTION. ' )
4341
( ' PROTECTED SECTION. ' )
4442
( ' METHODS example RETURNING VALUE(result) TYPE abap_bool. ' )
4543
( ' ENDCLASS. ' )
4644

4745
( ' CLASS y_example_class IMPLEMENTATION.' )
4846
( ' METHOD example.' )
4947
( ' TRY. ' )
50-
( ' RAISE EXCEPTION TYPE cx_demo_constructor.' )
51-
( ' CATCH cx_failed.' )
52-
( ' result = abap_true.' )
48+
( ' RAISE EXCEPTION TYPE cx_demo_constructor.' )
49+
( ' CATCH cx_failed.' )
50+
( ' result = abap_true.' )
5351
( ' ENDTRY.' )
5452
( ' ENDMETHOD.' )
5553
( 'ENDCLASS.' )
@@ -61,17 +59,95 @@ CLASS local_test_class IMPLEMENTATION.
6159
( ' REPORT y_example. ' )
6260

6361
( ' CLASS y_example_class DEFINITION. ' )
64-
( ' PUBLIC SECTION. ' )
6562
( ' PROTECTED SECTION. ' )
6663
( ' METHODS example RETURNING VALUE(result) TYPE abap_bool. ' )
6764
( ' ENDCLASS. ' )
6865

6966
( ' CLASS y_example_class IMPLEMENTATION.' )
7067
( ' METHOD example.' )
7168
( ' TRY.' )
72-
( ' RAISE EXCEPTION TYPE cx_demo_constructor.' )
73-
( ' CATCH cx_root. "#EC NEED_CX_ROOT' )
74-
( ' result = abap_true.' )
69+
( ' RAISE EXCEPTION TYPE cx_demo_constructor.' )
70+
( ' CATCH cx_root. "#EC NEED_CX_ROOT' )
71+
( ' result = abap_true.' )
72+
( ' ENDTRY. ' )
73+
( ' ENDMETHOD.' )
74+
( 'ENDCLASS.' )
75+
).
76+
ENDMETHOD.
77+
78+
ENDCLASS.
79+
80+
CLASS ltc_multiple_exceptions DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
81+
PROTECTED SECTION.
82+
METHODS get_cut REDEFINITION.
83+
METHODS get_code_with_issue REDEFINITION.
84+
METHODS get_code_without_issue REDEFINITION.
85+
METHODS get_code_with_exemption REDEFINITION.
86+
ENDCLASS.
87+
88+
CLASS ltc_multiple_exceptions IMPLEMENTATION.
89+
90+
METHOD get_cut.
91+
result ?= NEW y_check_cx_root_usage( ).
92+
ENDMETHOD.
93+
94+
METHOD get_code_with_issue.
95+
result = VALUE #(
96+
( ' REPORT y_example. ' )
97+
98+
( ' CLASS y_example_class DEFINITION. ' )
99+
( ' PROTECTED SECTION. ' )
100+
( ' METHODS example RETURNING VALUE(result) TYPE abap_bool. ' )
101+
( ' ENDCLASS. ' )
102+
103+
( ' CLASS y_example_class IMPLEMENTATION.' )
104+
( ' METHOD example.' )
105+
( ' TRY.' )
106+
( ' RAISE EXCEPTION TYPE cx_demo_constructor.' )
107+
( ' CATCH cx_failed cx_root.' )
108+
( ' result = abap_true.' )
109+
( ' ENDTRY.' )
110+
( ' ENDMETHOD.' )
111+
( 'ENDCLASS.' )
112+
).
113+
ENDMETHOD.
114+
115+
METHOD get_code_without_issue.
116+
result = VALUE #(
117+
( ' REPORT y_example. ' )
118+
119+
( ' CLASS y_example_class DEFINITION. ' )
120+
( ' PROTECTED SECTION. ' )
121+
( ' METHODS example RETURNING VALUE(result) TYPE abap_bool. ' )
122+
( ' ENDCLASS. ' )
123+
124+
( ' CLASS y_example_class IMPLEMENTATION.' )
125+
( ' METHOD example.' )
126+
( ' TRY. ' )
127+
( ' RAISE EXCEPTION TYPE cx_demo_constructor.' )
128+
( ' CATCH cx_failed cx_demo_constructor.' )
129+
( ' result = abap_true.' )
130+
( ' ENDTRY.' )
131+
( ' ENDMETHOD.' )
132+
( 'ENDCLASS.' )
133+
).
134+
ENDMETHOD.
135+
136+
METHOD get_code_with_exemption.
137+
result = VALUE #(
138+
( ' REPORT y_example. ' )
139+
140+
( ' CLASS y_example_class DEFINITION. ' )
141+
( ' PROTECTED SECTION. ' )
142+
( ' METHODS example RETURNING VALUE(result) TYPE abap_bool. ' )
143+
( ' ENDCLASS. ' )
144+
145+
( ' CLASS y_example_class IMPLEMENTATION.' )
146+
( ' METHOD example.' )
147+
( ' TRY.' )
148+
( ' RAISE EXCEPTION TYPE cx_demo_constructor.' )
149+
( ' CATCH cx_failed cx_root. "#EC NEED_CX_ROOT' )
150+
( ' result = abap_true.' )
75151
( ' ENDTRY. ' )
76152
( ' ENDMETHOD.' )
77153
( 'ENDCLASS.' )

src/checks/y_check_db_access_in_ut.clas.testclasses.abap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ CLASS ltc_osql_framework IMPLEMENTATION.
546546
( ' ENDMETHOD. ' )
547547

548548
( ' METHOD then_has_entry. ' )
549-
( ' cl_aunit_assert=>assert_not_initial( cut ). ' )
549+
( ' cl_abap_unit_assert=>assert_not_initial( cut ). ' )
550550
( ' ENDMETHOD. ' )
551551

552552
( ' METHOD scenario. ' )

src/checks/y_check_prefer_is_not.clas.abap

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ CLASS y_check_prefer_is_not DEFINITION PUBLIC INHERITING FROM y_check_base CREAT
22
PUBLIC SECTION.
33
METHODS constructor.
44
PROTECTED SECTION.
5+
METHODS execute_check REDEFINITION.
56
METHODS inspect_tokens REDEFINITION.
67
PRIVATE SECTION.
78
ENDCLASS.
@@ -23,27 +24,61 @@ CLASS y_check_prefer_is_not IMPLEMENTATION.
2324
ENDMETHOD.
2425

2526

26-
METHOD inspect_tokens.
27+
METHOD execute_check.
28+
LOOP AT ref_scan_manager->get_structures( ) ASSIGNING FIELD-SYMBOL(<structure>)
29+
WHERE stmnt_type = scan_struc_stmnt_type-if.
30+
31+
is_testcode = test_code_detector->is_testcode( <structure> ).
32+
33+
TRY.
34+
DATA(check_configuration) = check_configurations[ apply_on_testcode = abap_true ].
35+
CATCH cx_sy_itab_line_not_found.
36+
IF is_testcode EQ abap_true.
37+
CONTINUE.
38+
ENDIF.
39+
ENDTRY.
40+
41+
DATA(index) = <structure>-stmnt_from.
42+
43+
LOOP AT ref_scan_manager->get_statements( ) ASSIGNING FIELD-SYMBOL(<statement>)
44+
FROM <structure>-stmnt_from TO <structure>-stmnt_to.
45+
inspect_tokens( index = index
46+
structure = <structure>
47+
statement = <statement> ).
48+
index = index + 1.
49+
ENDLOOP.
50+
ENDLOOP.
51+
ENDMETHOD.
2752

28-
CHECK get_token_abs( statement-from ) = 'IF'.
53+
54+
METHOD inspect_tokens.
2955

3056
DATA(tokens) = ref_scan_manager->get_tokens( ).
3157

3258
LOOP AT tokens ASSIGNING FIELD-SYMBOL(<token>)
3359
FROM statement-from TO statement-to
3460
WHERE str = 'IF'
61+
OR str = 'ELSEIF'
3562
OR str = 'AND'
3663
OR str = 'OR'.
3764

65+
DATA(position) = sy-tabix.
66+
3867
TRY.
39-
DATA(next_token) = tokens[ sy-tabix + 1 ].
68+
IF tokens[ position + 1 ]-str <> 'NOT'.
69+
CONTINUE.
70+
ENDIF.
4071
CATCH cx_sy_itab_line_not_found.
4172
CONTINUE.
4273
ENDTRY.
4374

44-
IF next_token-str <> 'NOT'.
45-
CONTINUE.
46-
ENDIF.
75+
TRY.
76+
IF tokens[ position + 2 ]-str = 'LINE_EXISTS('.
77+
CONTINUE.
78+
ENDIF.
79+
CATCH cx_sy_itab_line_not_found.
80+
CONTINUE.
81+
ENDTRY.
4782

4883
DATA(configuration) = detect_check_configuration( statement ).
4984

@@ -56,9 +91,6 @@ CLASS y_check_prefer_is_not IMPLEMENTATION.
5691
statement_from = statement-from
5792
error_priority = configuration-prio ).
5893

59-
" Report the issue only once
60-
RETURN.
61-
6294
ENDLOOP.
6395

6496
ENDMETHOD.

src/checks/y_check_prefer_is_not.clas.testclasses.abap

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ CLASS ltc_or IMPLEMENTATION.
269269
ENDCLASS.
270270

271271

272-
CLASS ltc_multiple_issues DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
272+
CLASS ltc_elseif DEFINITION INHERITING FROM y_unit_test_base FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
273273
PROTECTED SECTION.
274274
METHODS get_cut REDEFINITION.
275275
METHODS get_code_with_issue REDEFINITION.
276276
METHODS get_code_without_issue REDEFINITION.
277277
METHODS get_code_with_exemption REDEFINITION.
278278
ENDCLASS.
279279

280-
CLASS ltc_multiple_issues IMPLEMENTATION.
280+
CLASS ltc_elseif IMPLEMENTATION.
281281

282282
METHOD get_cut.
283283
result ?= NEW y_check_prefer_is_not( ).
@@ -287,13 +287,13 @@ CLASS ltc_multiple_issues IMPLEMENTATION.
287287
result = VALUE #(
288288
( 'REPORT y_example. ' )
289289

290-
( ' START-OF-SELECTION. ' )
291-
( ' DATA(count) = 0. ' )
292-
( ' IF sy-subrc = 0 ' )
293-
( ' OR NOT count = 1 ' )
294-
( ' OR NOT count = 5. ' )
295-
( ' count = 1. ' )
296-
( ' ENDIF. ' )
290+
( ' START-OF-SELECTION. ' )
291+
( ' DATA(count) = 0. ' )
292+
( ' IF sy-subrc = 0. ' )
293+
( ' count = 1. ' )
294+
( ' ELSEIF NOT count = 5. ' )
295+
( ' count = 1. ' )
296+
( ' ENDIF. ' )
297297
).
298298
ENDMETHOD.
299299

@@ -302,26 +302,48 @@ CLASS ltc_multiple_issues IMPLEMENTATION.
302302
( 'REPORT y_example. ' )
303303

304304
( ' START-OF-SELECTION. ' )
305-
( ' DATA(count) = 0. ' )
306-
( ' IF sy-subrc = 0 ' )
307-
( ' OR count <> 1 ' )
308-
( ' OR count <> 5. ' )
309-
( ' count = 1. ' )
310-
( ' ENDIF. ' )
305+
( ' DATA(count) = 0. ' )
306+
( ' IF sy-subrc = 0. ' )
307+
( ' count = 1. ' )
308+
( ' ELSEIF count <> 5. ' )
309+
( ' count = 1. ' )
310+
( ' ENDIF. ' )
311311
).
312312
ENDMETHOD.
313313

314314
METHOD get_code_with_exemption.
315315
result = VALUE #(
316316
( 'REPORT y_example. ' )
317317

318-
( ' START-OF-SELECTION. ' )
319-
( ' DATA(count) = 0. ' )
320-
( ' IF sy-subrc = 0 ' )
321-
( ' OR NOT count = 1 ' )
322-
( ' OR NOT count = 5. "#EC PREFER_IS_NOT ' )
323-
( ' count = 1. ' )
324-
( ' ENDIF. ' )
318+
( ' START-OF-SELECTION. ' )
319+
320+
( ' DATA(count) = 0. ' )
321+
( ' IF sy-subrc = 0. ' )
322+
( ' count = 1. ' )
323+
( ' ELSEIF NOT count = 5. "#EC PREFER_IS_NOT ' )
324+
( ' count = 1. ' )
325+
( ' ENDIF. ' )
326+
).
327+
ENDMETHOD.
328+
329+
ENDCLASS.
330+
331+
332+
CLASS ltc_line_exists DEFINITION INHERITING FROM ltc_not_value FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
333+
PROTECTED SECTION.
334+
METHODS get_code_without_issue REDEFINITION.
335+
ENDCLASS.
336+
337+
CLASS ltc_line_exists IMPLEMENTATION.
338+
339+
METHOD get_code_without_issue.
340+
result = VALUE #(
341+
( 'REPORT y_example. ' )
342+
343+
( ' START-OF-SELECTION. ' )
344+
( ' DATA itab TYPE TABLE OF tadir. ' )
345+
( ' IF NOT line_exists( itab[ 0 ] ). ' )
346+
( ' ENDIF. ' )
325347
).
326348
ENDMETHOD.
327349

0 commit comments

Comments
 (0)