Files
linguist/samples/APL/UT.dyalog
Arfon Smith 9d8ab16a38 Merge branch 'master' into 1623-local
Conflicts:
	lib/linguist/heuristics.rb
2014-11-02 20:11:49 -06:00

368 lines
11 KiB
APL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

: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
FromSpace1⎕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_stepsingle_function_test_function
COVER_fileArgument,'_coverage.html'
:ElseIf is_list_of_functions Argument
TEST_steplist_of_functions_test_function
COVER_file'list_coverage.html'
:ElseIf is_file Argument
TEST_stepfile_test_function
COVER_file(get_file_name Argument),'_coverage.html'
:ElseIf is_dir Argument
test_filestest_files_in_dir Argument
TEST_steptest_dir_function
Argumenttest_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
ZFromSpace 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
ZFromSpace single_function_test_function TestName
Zrun_ut FromSpace TestName
ZFromSpace list_of_functions_test_function ListOfNames;t
t⎕TS
Zrun_ut¨{FromSpace }¨ListOfNames
t⎕TS-t
('Test execution report')print_passed_crashed_failed Z t
ZFromSpace file_test_function FilePath;FileNS;Functions;TestFunctions;t
FileNS⎕SE.SALT.Load FilePath,' -target=#'
FunctionsFileNS.⎕NL 3
TestFunctions(is_test¨Functions)/Functions
:If (0/,0/'')TestFunctions
'No test functions found'
Z
:Else
t⎕TS
Zrun_ut¨{FileNS }¨TestFunctions
t⎕TS-t
(FilePath,' tests')print_passed_crashed_failed Z t
:EndIf
ZFromSpace test_dir_function Test_files
:If Test_files/,''
'No test files found'
Z
:Else
Z#.UT.run¨Test_files
:EndIf
Zget_file_name Argument;separator
separator(Argument'/\')/Argument
Z¯7separatorArgument
generate_coverage_page Conf;ProfileData;CoverResults;HTML
ProfileData⎕PROFILE'data'
ToCoverretrieve_coverables¨('cover_target'in Conf)
:If (ToCover)(1)
ToCoverToCover
:EndIf
Representationsget_representation¨ToCover
CoverResultsProfileDatagenerate_cover_result¨ToCover,[1.5]Representations
HTMLgenerate_html CoverResults
Conf write_html_to_page HTML
⎕PROFILE'clear'
Zretrieve_coverables Something;nc;functions
nc⎕NC Something
:If nc=3
ZSomething
:ElseIf nc=9
functionsstrip¨Something,'.⎕NL 3'
Z{(Something,'.',)}¨functions
:EndIf
Zstrip input
Z(input' ')/input
Zget_representation Function;nc;rep
nc⎕NCFunction
:If nc=3.1
rep⎕CR Function
rep[1]'∇',rep[1]
rep,'∇'
reprep
:Else
rep⎕CR Function
:EndIf
Zrep
ZProfileData generate_cover_result(name representation);Indices;lines;functionlines;covered_lines
Indices({name}¨ProfileData[;1])/ProfileData[;1]
linesProfileData[Indices;2]
nc⎕NCname
:If 3.1=nc
functionlines¯2+representation
:Else
functionlinesrepresentation
:EndIf
covered_lines(¨lines)/lines
Z(nc lines functionlines covered_lines representation)
Zgenerate_html CoverResults;Covered;Total;Percentage;CoverageText;ColorizedCode;Timestamp;Page
Covered+/{4}¨CoverResults
Total+/{3}¨CoverResults
Percentage100×Covered÷Total
CoverageText'Coverage: ',Percentage,'% (',Covered,'/',Total,')'
ColorizedCode,/{colorize_code_by_coverage }¨CoverResults
Timestampgenerate_timestamp_text
Page
Page,,'<html>'
Page,,'<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>'
Page,,'<style>pre cov {line-height:80%;}'
Page,,'pre cov {color: green;}'
Page,,'pre uncov {line-height:80%;}'
Page,,'pre uncov {color:red;}</style>'
Page,,CoverageText
Page,,'<pre>'
Page,ColorizedCode
Page,,'</pre>'
Page,Timestamp
Page,,'</html>'
ZPage
Zcolorize_code_by_coverage CoverResult;Colors;Ends;Code
:If 3.1=CoverResult
Colors(2+3CoverResult)'<uncov>'
Colors[1]''
Colors[Colors]''
Ends(2+3CoverResult)'</uncov>'
Ends[1]''
Ends[Ends]''
:Else
Colors(3CoverResult)'<uncov>'
Ends(3CoverResult)'</uncov>'
:EndIf
Colors[1+4CoverResult]'<cov>'
Ends[1+4CoverResult]'</cov>'
Code5CoverResult
ZColors,[1.5]Code
Z{,(⎕UCS 13),}/Z,Ends
Zgenerate_timestamp_text;TS;YYMMDD;HHMMSS
TS⎕TS
YYMMDD{,'-',}/3TS
HHMMSS{,':',}/33TS
Z'Page generated: ',YYMMDD,'|',HHMMSS
Conf write_html_to_page Page;tie;filename
filename('cover_out'in Conf),('cover_file'in Conf)
:Trap 22
tiefilename ⎕NTIE 0
filename ⎕NERASE tie
filename ⎕NCREATE tie
:Else
tiefilename ⎕NCREATE 0
:EndTrap
Simple_array,/Page
(⎕UCS'UTF-8'⎕UCS Simple_array)⎕NAPPEND tie
Zis_function Argument
Z'_TEST'¯5Argument
Zis_list_of_functions Argument
Z2=Argument
Zis_file Argument
Z'.dyalog'¯7Argument
Zis_dir Argument;attr
:If 'Linux'5'.'⎕WG'APLVersion'
Z'yes'⎕CMD'test -d ',Argument,' && echo yes || echo no'
:Else
'gfa'⎕NA'I kernel32|GetFileAttributes* <0t'
:If Z¯1attrgfaArgument ⍝ If file exists
Z2 16attr ⍝ Return bit 4
:EndIf
:EndIf
Ztest_files_in_dir Argument
:If 'Linux'5'.'⎕WG'APLVersion'
Z⎕SH'find ',Argument,' -name \*_tests.dyalog'
:Else
#.⎕CY'files'
Z#.Files.Dir Argument,'\*_tests.dyalog'
Z(Argument,'\'),¨Z
:EndIf
Zrun_ut ut_data;returned;crashed;pass;crash;fail;message
(returned crashed time)execute_function ut_data
(pass crash fail)determine_pass_crash_or_fail returned crashed
messagedetermine_message pass fail crashed(2ut_data)returned time
print_message_to_screen message
Z(pass crash fail)
Zexecute_function ut_data;function;t
reset_UT_globals
function((ut_data[1])),'.',ut_data[2]
:Trap sac
:If 3.2⎕NCfunction
t⎕TS
Z(function,' ⍬')0
t⎕TS-t
:Else
t⎕TS
Z(function)0
t⎕TS-t
:EndIf
:Else
Z(⎕DM)1
:If exception
expectexception
Z[2]0
t⎕TS-t
:EndIf
:EndTrap
Z,t
reset_UT_globals
expect_orig expect ⎕NS
exception
nexpect_orig nexpect ⎕NS
Zis_test FunctionName;wsIndex
wsIndexFunctionName' '
FunctionName(wsIndex-1)FunctionName
Z'_TEST'¯5FunctionName
Heading print_passed_crashed_failed(ArrayRes time)
'-----------------------------------------'
Heading
' ⍋ Passed: ',+/{1}¨ArrayRes
' ⍟ Crashed: ',+/{2}¨ArrayRes
' ⍒ Failed: ',+/{3}¨ArrayRes
' ○ Runtime: ',time[5],'m',time[6],'s',time[7],'ms'
determine_pass_crash_or_fail{
r c 0c:0 1 0 z(0 0 1)(1 0 0)
expect_origexpect:(⎕IO+expectr)z (⎕IO+nexpectr)z
}
Zdetermine_message(pass fail crashed name returned time)
:If crashed
Z'CRASHED: 'failure_message name returned
:ElseIf pass
Z'Passed ',time[5],'m',time[6],'s',time[7],'ms'
:Else
Z'FAILED: 'failure_message name returned
:EndIf
print_message_to_screen message
message
Zterm_to_text Term;Text;Rows
Text#.DISPLAY Term
Rows1Text
Z(Rows 4''),Text
ZCause failure_message(name returned);hdr;exp;expterm;got;gotterm
hdrCause,name
exp'Expected'
exptermterm_to_text #.UT.expect
got'Got'
gottermterm_to_text returned
Zalign_and_join_message_parts hdr exp expterm got gotterm
Zalign_and_join_message_parts Parts;hdr;exp;expterm;got;gotterm;R1;C1;R2;C2;W
(hdr exp expterm got gotterm)Parts
(R1 C1)expterm
(R2 C2)gotterm
W/C1 C2(hdr)(exp)(got)
Z(Whdr),[0.5](Wexp)
ZZ(R1 Wexpterm)
ZZ(Wgot)
ZZ(R2 Wgotterm)
Zconfparam in config
Z1({confparam}¨config)/config
Zconfig has confparam
Z/{confparam}¨config
:EndNameSpace