Skip to content

Commit

Permalink
fixes #526
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Borin committed Nov 11, 2021
1 parent 8438f07 commit d0fd397
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 57 deletions.
29 changes: 8 additions & 21 deletions src/checks/y_check_function.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ CLASS y_check_function DEFINITION PUBLIC INHERITING FROM y_check_base CREATE PUB
METHODS inspect_tokens REDEFINITION.

PRIVATE SECTION.
METHODS is_rfc_enabled IMPORTING name TYPE rs38l_fnam
RETURNING VALUE(result) TYPE abap_bool.
METHODS is_normal_mode RETURNING VALUE(result) TYPE abap_bool.

ENDCLASS.



CLASS Y_CHECK_FUNCTION IMPLEMENTATION.

CLASS y_check_function IMPLEMENTATION.

METHOD constructor.
super->constructor( ).
Expand All @@ -32,17 +30,8 @@ CLASS Y_CHECK_FUNCTION IMPLEMENTATION.


METHOD inspect_tokens.
CHECK statement-type <> scan_stmnt_type-comment.
CHECK statement-type <> scan_stmnt_type-comment_in_stmnt.
CHECK statement-type <> scan_stmnt_type-pragma.

CHECK get_token_abs( statement-from ) = 'FUNCTION'.

DATA(fm_name) = get_token_abs( statement-from + 1 ).

IF is_rfc_enabled( CONV #( fm_name ) ) = abap_true.
RETURN.
ENDIF.
CHECK keyword( ) = if_kaizen_keywords_c=>gc_function.
CHECK is_normal_mode( ) = abap_true.

DATA(check_configuration) = detect_check_configuration( statement ).

Expand All @@ -53,12 +42,10 @@ CLASS Y_CHECK_FUNCTION IMPLEMENTATION.
ENDMETHOD.


METHOD is_rfc_enabled.
SELECT SINGLE @abap_true
FROM tfdir
INTO @result
WHERE funcname = @name
AND fmode = 'R'.
METHOD is_normal_mode.
DATA(function_module) = next1( CONV #( if_kaizen_keywords_c=>gc_function ) ).
SELECT SINGLE pname INTO @DATA(function_group) FROM tfdir WHERE funcname = @function_module AND fmode = @space.
result = xsdbool( sy-subrc = 0 ).
ENDMETHOD.

ENDCLASS.
63 changes: 27 additions & 36 deletions src/checks/y_check_function.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,44 @@ CLASS lth_function DEFINITION.
PROTECTED SECTION.
DATA cut TYPE REF TO ltd_check_function.

METHODS given_rfc_enabled.
METHODS given_rfc_disabled.
METHODS given_function_group.
METHODS when_run.
METHODS then_has_issue.
METHODS then_no_issue.
METHODS then_finds.

PRIVATE SECTION.
DATA expected_issues TYPE i.

ENDCLASS.


CLASS lth_function IMPLEMENTATION.

METHOD given_rfc_enabled.
SELECT SINGLE pname FROM tfdir INTO @DATA(function_group) WHERE fmode = 'R'.
cut->set_ref_scan( y_code_pal_ref_scan_double=>get_from_fuction_group( function_group ) ).
ENDMETHOD.
METHOD given_function_group.
" Get one that has RFC enabled and disabled
SELECT SINGLE tfdir~pname
FROM tfdir AS tfdir
INNER JOIN tfdir AS enabled ON enabled~pname = tfdir~pname
AND enabled~fmode <> @space
WHERE tfdir~fmode = @space
INTO @DATA(function_group).

SELECT COUNT( * )
FROM tfdir
WHERE pname = @function_group
AND tfdir~fmode = @space
INTO @expected_issues.

METHOD given_rfc_disabled.
SELECT SINGLE pname FROM tfdir INTO @DATA(function_group) WHERE fmode = 'X'.
cut->set_ref_scan( y_code_pal_ref_scan_double=>get_from_fuction_group( function_group ) ).
ENDMETHOD.

METHOD when_run.
cut->run( ).
ENDMETHOD.

METHOD then_no_issue.
cl_abap_unit_assert=>assert_initial( act = cut->get_statistics( )->count-errors
quit = if_aunit_constants=>quit-no ).
cl_abap_unit_assert=>assert_initial( act = cut->get_statistics( )->count-warnings
quit = if_aunit_constants=>quit-no ).
cl_abap_unit_assert=>assert_initial( act = cut->get_statistics( )->count-notes
quit = if_aunit_constants=>quit-no ).
cl_abap_unit_assert=>assert_initial( act = cut->get_statistics( )->count-pseudo_comments
quit = if_aunit_constants=>quit-no ).
ENDMETHOD.

METHOD then_has_issue.
cl_abap_unit_assert=>assert_not_initial( act = cut->get_statistics( )->count-notes
quit = if_aunit_constants=>quit-no ).

METHOD then_finds.
cl_abap_unit_assert=>assert_equals( act = cut->get_statistics( )->count-notes
exp = expected_issues
quit = if_aunit_constants=>quit-no ).
cl_abap_unit_assert=>assert_initial( act = cut->get_statistics( )->count-errors
quit = if_aunit_constants=>quit-no ).
cl_abap_unit_assert=>assert_initial( act = cut->get_statistics( )->count-warnings
Expand All @@ -56,8 +54,7 @@ ENDCLASS.

CLASS ltc_function DEFINITION FOR TESTING INHERITING FROM lth_function RISK LEVEL HARMLESS.
PUBLIC SECTION.
METHODS rfc_enabled FOR TESTING.
METHODS rfc_disabled FOR TESTING.
METHODS test FOR TESTING.

PRIVATE SECTION.
METHODS setup.
Expand All @@ -71,16 +68,10 @@ CLASS ltc_function IMPLEMENTATION.
cut = NEW #( ).
ENDMETHOD.

METHOD rfc_enabled.
given_rfc_enabled( ).
when_run( ).
then_no_issue( ).
ENDMETHOD.

METHOD rfc_disabled.
given_rfc_disabled( ).
METHOD test.
given_function_group( ).
when_run( ).
then_has_issue( ).
then_finds( ).
ENDMETHOD.

ENDCLASS.

0 comments on commit d0fd397

Please sign in to comment.