Skip to content

Commit c91dbcb

Browse files
authored
1.14.1 (#382)
* 1.14.1 * Update changelog.txt * unit test assertion (#383) * fix #381 * Update changelog.txt * Update changelog.txt * Update changelog.txt
1 parent e45ffb4 commit c91dbcb

File tree

4 files changed

+305
-29
lines changed

4 files changed

+305
-29
lines changed

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ Upgrade Note
1212
------------------
1313
Whenever you upgrade code pal for ABAP, it is highly recommended to execute the Y_CI_CHECK_REGISTRATION report to activate/reactivate the Checks (SE38 transaction) and regenerate the respective Code Inspector Variant (SCI transaction)
1414

15+
2021-05-03 v.1.14.1
16+
------------------
17+
+ Assert Classes (#378)
18+
* Unit Test Assertion (#383)
19+
1520
2021-04-23 v.1.14.0
1621
------------------
1722
! Notification as Default Severity (#368)

src/checks/y_check_unit_test_assert.clas.abap

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ CLASS y_check_unit_test_assert DEFINITION PUBLIC INHERITING FROM y_check_base CR
66
METHODS inspect_tokens REDEFINITION.
77

88
PRIVATE SECTION.
9-
METHODS get_act_and_exp IMPORTING statement TYPE sstmnt
10-
EXPORTING act TYPE stokesx
11-
exp TYPE stokesx.
9+
METHODS get_parameter_reference IMPORTING statement TYPE sstmnt
10+
parameter TYPE string
11+
RETURNING VALUE(result) TYPE string
12+
RAISING cx_sy_itab_line_not_found.
1213

1314
METHODS is_variable IMPORTING token TYPE stokesx
1415
RETURNING VALUE(result) TYPE abap_bool.
@@ -37,20 +38,23 @@ CLASS y_check_unit_test_assert IMPLEMENTATION.
3738

3839

3940
METHOD inspect_tokens.
40-
CHECK get_token_abs( statement-from ) CP 'CL_ABAP_UNIT_ASSERT=>ASSERT*'
41-
OR get_token_abs( statement-from ) CP 'CL_AUNIT_ASSERT=>ASSERT*'.
41+
DATA(token) = ref_scan_manager->tokens[ statement-from ].
4242

43-
get_act_and_exp( EXPORTING statement = statement
44-
IMPORTING act = DATA(act)
45-
exp = DATA(exp) ).
46-
47-
IF act IS INITIAL
48-
OR exp IS INITIAL.
43+
IF token-str NP '*ASSERT*'
44+
OR token-type = scan_token_type-comment.
4945
RETURN.
5046
ENDIF.
5147

52-
IF act-str <> exp-str
53-
AND ( is_variable( act ) = abap_true OR is_variable( exp ) = abap_true ).
48+
TRY.
49+
DATA(act) = get_parameter_reference( statement = statement
50+
parameter = 'ACT' ).
51+
DATA(exp) = get_parameter_reference( statement = statement
52+
parameter = 'EXP' ).
53+
CATCH cx_sy_itab_line_not_found.
54+
RETURN.
55+
ENDTRY.
56+
57+
IF act <> exp.
5458
RETURN.
5559
ENDIF.
5660

@@ -67,25 +71,65 @@ CLASS y_check_unit_test_assert IMPLEMENTATION.
6771
ENDMETHOD.
6872

6973

70-
METHOD get_act_and_exp.
71-
LOOP AT ref_scan_manager->tokens ASSIGNING FIELD-SYMBOL(<token>)
72-
FROM statement-from TO statement-to.
73-
DATA(tabix) = sy-tabix.
74-
CASE <token>-str.
75-
WHEN 'ACT'.
76-
act = ref_scan_manager->tokens[ tabix + 2 ].
77-
WHEN 'EXP'.
78-
exp = ref_scan_manager->tokens[ tabix + 2 ].
79-
WHEN OTHERS.
80-
CONTINUE.
81-
ENDCASE.
82-
ENDLOOP.
74+
METHOD get_parameter_reference.
75+
DATA(in) = abap_false.
76+
DATA(depth) = 0.
77+
DATA(position) = statement-from.
78+
79+
DO.
80+
IF position = statement-to.
81+
RETURN.
82+
ENDIF.
83+
84+
DATA(token) = ref_scan_manager->tokens[ position ].
85+
86+
IF token-type = scan_token_type-comment.
87+
position = position + 1.
88+
CONTINUE.
89+
ENDIF.
90+
91+
IF token-str = parameter.
92+
in = abap_true.
93+
depth = 0.
94+
position = position + 2.
95+
CONTINUE.
96+
ENDIF.
97+
98+
IF in = abap_false.
99+
position = position + 1.
100+
CONTINUE.
101+
ENDIF.
102+
103+
IF token-str CP '*(*'.
104+
depth = depth + 1.
105+
ELSEIF token-str CP '*)*'.
106+
depth = depth - 1.
107+
ENDIF.
108+
109+
IF depth = 0
110+
AND line_exists( ref_scan_manager->tokens[ position + 1 ] ).
111+
DATA(next) = ref_scan_manager->tokens[ position + 1 ].
112+
IF next-str = '='.
113+
in = abap_false.
114+
RETURN.
115+
ENDIF.
116+
ENDIF.
117+
118+
IF is_variable( token ) = abap_false.
119+
token-str = '*'.
120+
ENDIF.
121+
122+
result = COND #( WHEN result IS INITIAL THEN token-str
123+
ELSE |{ result } { token-str }| ).
124+
125+
position = position + 1.
126+
ENDDO.
83127
ENDMETHOD.
84128

85129

86130
METHOD is_variable.
87-
result = COND #( WHEN token-type = scan_token_type-literal THEN abap_false
88-
WHEN token-type = scan_token_type-identifier THEN xsdbool( token-str CN '0123456789' ) ).
131+
CHECK token-type = scan_token_type-identifier.
132+
result = xsdbool( token-str CN '0123456789' ).
89133
ENDMETHOD.
90134

91135

src/checks/y_check_unit_test_assert.clas.testclasses.abap

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,230 @@ CLASS ltc_protected_data IMPLEMENTATION.
305305
ENDMETHOD.
306306

307307
ENDCLASS.
308+
309+
310+
311+
CLASS ltc_comments DEFINITION INHERITING FROM ltc_same_variable FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
312+
PROTECTED SECTION.
313+
METHODS get_code_without_issue REDEFINITION.
314+
ENDCLASS.
315+
316+
CLASS ltc_comments IMPLEMENTATION.
317+
318+
METHOD get_code_without_issue.
319+
result = VALUE #(
320+
( ' REPORT y_example. ' )
321+
322+
( ' CLASS y_example DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. ' )
323+
( ' PUBLIC SECTION. ' )
324+
( ' METHODS example FOR TESTING. ' )
325+
( ' PROTECTED SECTION. ' )
326+
( ' DATA system TYPE string. ' )
327+
( ' ENDCLASS. ' )
328+
329+
( ' CLASS y_example IMPLEMENTATION. ' )
330+
( ' METHOD example. ' )
331+
( |* cl_aunit_assert=>assert_differs( act = system | )
332+
( |* exp = system ). | )
333+
( ' ENDMETHOD. ' )
334+
( ' ENDCLASS. ' )
335+
).
336+
ENDMETHOD.
337+
338+
ENDCLASS.
339+
340+
341+
342+
CLASS ltc_non_standard_assert DEFINITION INHERITING FROM ltc_same_variable FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
343+
PROTECTED SECTION.
344+
METHODS get_cut REDEFINITION.
345+
METHODS get_code_with_issue REDEFINITION.
346+
METHODS get_code_without_issue REDEFINITION.
347+
METHODS get_code_with_exemption REDEFINITION.
348+
ENDCLASS.
349+
350+
CLASS ltc_non_standard_assert IMPLEMENTATION.
351+
352+
METHOD get_cut.
353+
result ?= NEW y_check_unit_test_assert( ).
354+
ENDMETHOD.
355+
356+
METHOD get_code_with_issue.
357+
result = VALUE #(
358+
( ' REPORT y_example. ' )
359+
360+
( ' CLASS y_assert DEFINITION. ' )
361+
( ' PUBLIC SECTION. ' )
362+
( ' CLASS-METHODS assert IMPORTING VALUE(exp) TYPE any ' )
363+
( ' VALUE(act) TYPE any ' )
364+
( ' RETURNING VALUE(result) TYPE abap_bool. ' )
365+
( ' ENDCLASS. ' )
366+
367+
( ' CLASS y_assert IMPLEMENTATION. ' )
368+
( ' METHOD assert. ' )
369+
( ' result = cl_abap_unit_assert=>assert_equals( exp = exp ' )
370+
( ' act = act ). ' )
371+
( ' ENDMETHOD. ' )
372+
( ' ENDCLASS. ' )
373+
374+
( ' CLASS y_example DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. ' )
375+
( ' PUBLIC SECTION. ' )
376+
( ' METHODS example FOR TESTING. ' )
377+
( ' PROTECTED SECTION. ' )
378+
( ' DATA system TYPE string. ' )
379+
( ' ENDCLASS. ' )
380+
381+
( ' CLASS y_example IMPLEMENTATION. ' )
382+
( ' METHOD example. ' )
383+
( ' y_assert=>assert( act = system ' )
384+
( ' exp = system ). ' )
385+
( ' ENDMETHOD. ' )
386+
( ' ENDCLASS. ' )
387+
).
388+
ENDMETHOD.
389+
390+
METHOD get_code_without_issue.
391+
result = VALUE #(
392+
( ' REPORT y_example. ' )
393+
394+
( ' CLASS y_assert DEFINITION. ' )
395+
( ' PUBLIC SECTION. ' )
396+
( ' CLASS-METHODS assert IMPORTING VALUE(exp) TYPE any ' )
397+
( ' VALUE(act) TYPE any ' )
398+
( ' RETURNING VALUE(result) TYPE abap_bool. ' )
399+
( ' ENDCLASS. ' )
400+
401+
( ' CLASS y_assert IMPLEMENTATION. ' )
402+
( ' METHOD assert. ' )
403+
( ' result = cl_abap_unit_assert=>assert_equals( exp = exp ' )
404+
( ' act = act ). ' )
405+
( ' ENDMETHOD. ' )
406+
( ' ENDCLASS. ' )
407+
408+
( ' CLASS y_example DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. ' )
409+
( ' PUBLIC SECTION. ' )
410+
( ' METHODS example FOR TESTING. ' )
411+
( ' PROTECTED SECTION. ' )
412+
( ' DATA system TYPE string. ' )
413+
( ' ENDCLASS. ' )
414+
415+
( ' CLASS y_example IMPLEMENTATION. ' )
416+
( ' METHOD example. ' )
417+
( ' y_assert=>assert( act = sy-sysid ' )
418+
( ' exp = system ). ' )
419+
( ' ENDMETHOD. ' )
420+
( ' ENDCLASS. ' )
421+
).
422+
ENDMETHOD.
423+
424+
METHOD get_code_with_exemption.
425+
result = VALUE #(
426+
( ' REPORT y_example. ' )
427+
428+
( ' CLASS y_assert DEFINITION. ' )
429+
( ' PUBLIC SECTION. ' )
430+
( ' CLASS-METHODS assert IMPORTING VALUE(exp) TYPE any ' )
431+
( ' VALUE(act) TYPE any ' )
432+
( ' RETURNING VALUE(result) TYPE abap_bool. ' )
433+
( ' ENDCLASS. ' )
434+
435+
( ' CLASS y_assert IMPLEMENTATION. ' )
436+
( ' METHOD assert. ' )
437+
( ' result = cl_abap_unit_assert=>assert_equals( exp = exp ' )
438+
( ' act = act ). ' )
439+
( ' ENDMETHOD. ' )
440+
( ' ENDCLASS. ' )
441+
442+
( ' CLASS y_example DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. ' )
443+
( ' PUBLIC SECTION. ' )
444+
( ' METHODS example FOR TESTING. ' )
445+
( ' PROTECTED SECTION. ' )
446+
( ' DATA system TYPE string. ' )
447+
( ' ENDCLASS. ' )
448+
449+
( ' CLASS y_example IMPLEMENTATION. ' )
450+
( ' METHOD example. ' )
451+
( ' y_assert=>assert( act = system ' )
452+
( ' exp = system ). "#EC UT_ASSERT ' )
453+
( ' ENDMETHOD. ' )
454+
( ' ENDCLASS. ' )
455+
).
456+
ENDMETHOD.
457+
458+
459+
ENDCLASS.
460+
461+
462+
463+
CLASS ltc_lines DEFINITION INHERITING FROM ltc_hardcoded_string FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
464+
PROTECTED SECTION.
465+
METHODS get_code_without_issue REDEFINITION.
466+
ENDCLASS.
467+
468+
CLASS ltc_lines IMPLEMENTATION.
469+
470+
METHOD get_code_without_issue.
471+
result = VALUE #(
472+
( ' REPORT y_example. ' )
473+
474+
( ' CLASS y_example DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. ' )
475+
( ' PUBLIC SECTION. ' )
476+
( ' METHODS example FOR TESTING. ' )
477+
( ' ENDCLASS. ' )
478+
479+
( ' CLASS y_example IMPLEMENTATION. ' )
480+
( ' METHOD example. ' )
481+
( ' DATA atc_tadir TYPE TABLE OF tadir. ' )
482+
( ' DATA exp_tadir TYPE TABLE OF tadir. ' )
483+
( | cl_aunit_assert=>assert_equals( act = lines( atc_tadir ) | )
484+
( | exp = lines( exp_tadir ) ). | )
485+
( ' ENDMETHOD. ' )
486+
( ' ENDCLASS. ' )
487+
).
488+
ENDMETHOD.
489+
490+
ENDCLASS.
491+
492+
493+
494+
CLASS ltc_call_static DEFINITION INHERITING FROM ltc_hardcoded_string FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
495+
PROTECTED SECTION.
496+
METHODS get_code_with_issue REDEFINITION.
497+
ENDCLASS.
498+
499+
CLASS ltc_call_static IMPLEMENTATION.
500+
501+
METHOD get_code_with_issue.
502+
result = VALUE #(
503+
( ' REPORT y_example. ' )
504+
505+
( ' CLASS y_fake DEFINITION. ' )
506+
( ' PUBLIC SECTION. ' )
507+
( ' CLASS-METHODS get_fullname IMPORTING name TYPE string ' )
508+
( ' surname TYPE string ' )
509+
( ' RETURNING VALUE(result) TYPE string. ' )
510+
( ' ENDCLASS. ' )
511+
512+
( ' CLASS y_fake IMPLEMENTATION. ' )
513+
( ' METHOD get_fullname. ' )
514+
( ' result = |{ name } { surname }|. ' )
515+
( ' ENDMETHOD. ' )
516+
( ' ENDCLASS. ' )
517+
518+
519+
( ' CLASS y_example DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT. ' )
520+
( ' PUBLIC SECTION. ' )
521+
( ' METHODS example FOR TESTING. ' )
522+
( ' ENDCLASS. ' )
523+
524+
( ' CLASS y_example IMPLEMENTATION. ' )
525+
( ' METHOD example. ' )
526+
( | cl_aunit_assert=>assert_equals( act = y_fake=>get_fullname( name = 'code pal' surname = 'for ABAP' ) | )
527+
( | exp = y_fake=>get_fullname( name = 'code pal' | )
528+
( | surname = 'for ABAP' ) ). | )
529+
( ' ENDMETHOD. ' )
530+
( ' ENDCLASS. ' )
531+
).
532+
ENDMETHOD.
533+
534+
ENDCLASS.

src/y_code_pal_version.intf.abap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
INTERFACE y_code_pal_version PUBLIC.
2-
CONSTANTS abap TYPE string VALUE '1.14.0' ##NO_TEXT.
2+
CONSTANTS abap TYPE string VALUE '1.14.1' ##NO_TEXT.
33
ENDINTERFACE.

0 commit comments

Comments
 (0)