diff --git a/samples/APL/UT.dyalog b/samples/APL/UT.dyalog new file mode 100644 index 00000000..6c5f28fa --- /dev/null +++ b/samples/APL/UT.dyalog @@ -0,0 +1,367 @@ +:NameSpace UT + + sac ← 0 + expect_orig ← expect ← ⎕NS⍬ + exception ← ⍬ + nexpect_orig ← nexpect ← ⎕NS⍬ + + ∇ {Z}←{Conf}run Argument;PRE_test;POST_test;TEST_step;COVER_step;FromSpace + + load_display_if_not_already_loaded + load_salt_scripts_into_current_namespace_if_configured + + FromSpace←1⊃⎕RSI + + PRE_test←{} + POST_test←{} + COVER_step←{} + :If 0≠⎕NC'Conf' + :If Conf has'cover_target' + PRE_test←{{}⎕PROFILE'start'} + POST_test←{{}⎕PROFILE'stop'} + :EndIf + :EndIf + + :If is_function Argument + TEST_step←single_function_test_function + COVER_file←Argument,'_coverage.html' + + :ElseIf is_list_of_functions Argument + TEST_step←list_of_functions_test_function + COVER_file←'list_coverage.html' + + :ElseIf is_file Argument + TEST_step←file_test_function + COVER_file←(get_file_name Argument),'_coverage.html' + + :ElseIf is_dir Argument + test_files←test_files_in_dir Argument + TEST_step←test_dir_function + Argument←test_files + :EndIf + + :If 0≠⎕NC'Conf' + :If Conf has'cover_target' + COVER_step←{Conf,←⊂('cover_file'COVER_file) + generate_coverage_page Conf} + :EndIf + :EndIf + + PRE_test ⍬ + Z←FromSpace TEST_step Argument + POST_test ⍬ + COVER_step ⍬ + ∇ + + ∇ load_display_if_not_already_loaded + :If 0=⎕NC'#.DISPLAY' + 'DISPLAY'#.⎕CY'display' + :EndIf + ∇ + + ∇ load_salt_scripts_into_current_namespace_if_configured + :If 0≠⎕NC'#.UT.appdir' + :If ⍬≢#.UT.appdir + ⎕SE.SALT.Load #.UT.appdir,'src/*.dyalog -target=#' + ⎕SE.SALT.Load #.UT.appdir,'test/*.dyalog -target=#' + :EndIf + :EndIf + ∇ + + ∇ Z←FromSpace single_function_test_function TestName + Z←run_ut FromSpace TestName + ∇ + + ∇ Z←FromSpace list_of_functions_test_function ListOfNames;t + t←⎕TS + Z←run_ut¨{FromSpace ⍵}¨ListOfNames + t←⎕TS-t + ('Test execution report')print_passed_crashed_failed Z t + ∇ + + ∇ Z←FromSpace file_test_function FilePath;FileNS;Functions;TestFunctions;t + FileNS←⎕SE.SALT.Load FilePath,' -target=#' + Functions←↓FileNS.⎕NL 3 + TestFunctions←(is_test¨Functions)/Functions + :If (0/⍬,⊂0/'')≡TestFunctions + ⎕←'No test functions found' + Z←⍬ + :Else + t←⎕TS + Z←run_ut¨{FileNS ⍵}¨TestFunctions + t←⎕TS-t + (FilePath,' tests')print_passed_crashed_failed Z t + :EndIf + ∇ + + ∇ Z←FromSpace test_dir_function Test_files + :If Test_files≡⍬/⍬,⊂'' + ⎕←'No test files found' + Z←⍬ + :Else + Z←#.UT.run¨Test_files + :EndIf + ∇ + + ∇ Z←get_file_name Argument;separator + separator←⊃⌽(Argument∊'/\')/⍳⍴Argument + Z←¯7↓separator↓Argument + ∇ + + ∇ generate_coverage_page Conf;ProfileData;CoverResults;HTML + ProfileData←⎕PROFILE'data' + ToCover←retrieve_coverables¨(⊃'cover_target'in Conf) + :If (⍴ToCover)≡(⍴⊂1) + ToCover←⊃ToCover + :EndIf + Representations←get_representation¨ToCover + CoverResults←ProfileData∘generate_cover_result¨↓ToCover,[1.5]Representations + HTML←generate_html CoverResults + Conf write_html_to_page HTML + ⎕PROFILE'clear' + ∇ + + ∇ Z←retrieve_coverables Something;nc;functions + nc←⎕NC Something + :If nc=3 + Z←Something + :ElseIf nc=9 + functions←strip¨↓⍎Something,'.⎕NL 3' + Z←{(Something,'.',⍵)}¨functions + :EndIf + ∇ + + ∇ Z←strip input + Z←(input≠' ')/input + ∇ + + ∇ Z←get_representation Function;nc;rep + nc←⎕NC⊂Function + :If nc=3.1 + rep←↓⎕CR Function + rep[1]←⊂'∇',⊃rep[1] + rep,←⊂'∇' + rep←↑rep + :Else + rep←⎕CR Function + :EndIf + Z←rep + ∇ + + ∇ Z←ProfileData generate_cover_result(name representation);Indices;lines;functionlines;covered_lines + Indices←({name≡⍵}¨ProfileData[;1])/⍳⍴ProfileData[;1] + lines←ProfileData[Indices;2] + nc←⎕NC⊂name + :If 3.1=nc + functionlines←¯2+⍴↓representation + :Else + functionlines←⊃⍴↓representation + :EndIf + covered_lines←(⍬∘≢¨lines)/lines + Z←(nc lines functionlines covered_lines representation) + ∇ + + ∇ Z←generate_html CoverResults;Covered;Total;Percentage;CoverageText;ColorizedCode;Timestamp;Page + Covered←⊃⊃+/{⍴4⊃⍵}¨CoverResults + Total←⊃⊃+/{3⊃⍵}¨CoverResults + Percentage←100×Covered÷Total + CoverageText←'Coverage: ',Percentage,'% (',Covered,'/',Total,')' + ColorizedCode←⊃,/{colorize_code_by_coverage ⍵}¨CoverResults + Timestamp←generate_timestamp_text + Page←⍬ + Page,←⊂⍬,'' + Page,←⊂⍬,'' + Page,←⊂⍬,'' + Page,←⊂⍬,CoverageText + Page,←⊂⍬,'
' + Page,←ColorizedCode + Page,←⊂⍬,'' + Page,←Timestamp + Page,←⊂⍬,'' + Z←Page + ∇ + + ∇ Z←colorize_code_by_coverage CoverResult;Colors;Ends;Code + :If 3.1=⊃CoverResult + Colors←(2+3⊃CoverResult)⍴⊂'