diff options
124 files changed, 28084 insertions, 23675 deletions
diff --git a/bootstrap/lib/compiler/ebin/beam_block.beam b/bootstrap/lib/compiler/ebin/beam_block.beam Binary files differindex 2854b91bae..7a96ad3196 100644 --- a/bootstrap/lib/compiler/ebin/beam_block.beam +++ b/bootstrap/lib/compiler/ebin/beam_block.beam diff --git a/bootstrap/lib/stdlib/ebin/epp.beam b/bootstrap/lib/stdlib/ebin/epp.beam Binary files differindex d19b427124..e2a528f9fc 100644 --- a/bootstrap/lib/stdlib/ebin/epp.beam +++ b/bootstrap/lib/stdlib/ebin/epp.beam diff --git a/erts/emulator/test/nif_SUITE.erl b/erts/emulator/test/nif_SUITE.erl index 7ce37b04b3..c6c617f97f 100644 --- a/erts/emulator/test/nif_SUITE.erl +++ b/erts/emulator/test/nif_SUITE.erl @@ -1711,7 +1711,9 @@ tmpmem() -> false -> undefined; MemInfo -> MSBCS = lists:foldl( - fun ({instance, _, L}, Acc) -> + fun ({instance, 0, _}, Acc) -> + Acc; % Ignore instance 0 + ({instance, _, L}, Acc) -> {value,{_,MBCS}} = lists:keysearch(mbcs, 1, L), {value,{_,SBCS}} = lists:keysearch(sbcs, 1, L), [MBCS,SBCS | Acc] diff --git a/lib/common_test/doc/src/Makefile b/lib/common_test/doc/src/Makefile index cedddd75ac..a0c89b1222 100644 --- a/lib/common_test/doc/src/Makefile +++ b/lib/common_test/doc/src/Makefile @@ -36,26 +36,24 @@ RELSYSDIR = $(RELEASE_PATH)/lib/$(APPLICATION)-$(VSN) # Target Specs # ---------------------------------------------------- -# REMEMBER: links to HTML files for these modules in ref_man.xml -CT_MODULES = \ - ct \ - ct_master \ - ct_cover \ - ct_telnet \ - ct_ftp \ - ct_ssh \ - ct_rpc \ - ct_snmp \ - unix_telnet \ - ct_slave \ - ct_property_test \ - ct_netconfc - CT_XML_FILES = $(CT_MODULES:=.xml) XML_APPLICATION_FILES = ref_man.xml XML_REF1_FILES = ct_run.xml -XML_REF3_FILES = $(CT_XML_FILES) ct_hooks.xml +# REMEMBER: links to HTML files for these modules in ref_man.xml +XML_REF3_FILES = ct.xml \ + ct_master.xml \ + ct_cover.xml \ + ct_telnet.xml \ + ct_ftp.xml \ + ct_ssh.xml \ + ct_rpc.xml \ + ct_snmp.xml \ + unix_telnet.xml \ + ct_slave.xml \ + ct_property_test.xml \ + ct_netconfc.xml \ + ct_hooks.xml XML_REF6_FILES = common_test_app.xml XML_PART_FILES = part.xml @@ -80,8 +78,6 @@ XML_CHAPTER_FILES = \ notes.xml \ notes_history.xml -MAKE_EDOC = make_edoc - BOOK_FILES = book.xml GIF_FILES = \ @@ -92,7 +88,7 @@ GIF_FILES = \ INSTALL_NOTES = ../../notes.html XML_FILES=$(XML_APPLICATION_FILES) $(XML_REF1_FILES) $(XML_REF3_FILES) $(XML_REF6_FILES) \ - $(XML_PART_FILES) $(XML_CHAPTER_FILES) $(XML_REF_FILES) $(BOOK_FILES) + $(XML_PART_FILES) $(XML_CHAPTER_FILES) $(BOOK_FILES) # ---------------------------------------------------- @@ -119,19 +115,11 @@ DVIPS_FLAGS += # Targets # ---------------------------------------------------- -CT_SRC_DIR = $(ERL_TOP)/../internal_tools/common_test/src - $(HTMLDIR)/%.gif: %.gif $(INSTALL_DATA) $< $@ docs: pdf html man -$(CT_XML_FILES): %.xml: ../../src/%.erl - escript $(DOCGEN)/priv/bin/xml_from_edoc.escript -preprocess true -i $(XMERL_DIR)/include \ - -i ../../../test_server/include -i ../../include \ - -i ../../../../erts/lib/kernel/include -i ../../../../lib/kernel/include \ - -i ../../../../erts/lib/snmp/include -i ../../../../lib/snmp/include ../../src/$(@:%.xml=%.erl) - $(TOP_PDF_FILE): $(XML_FILES) pdf: $(TOP_PDF_FILE) @@ -146,7 +134,6 @@ man: $(MAN6_FILES) $(MAN3_FILES) $(MAN1_FILES) debug opt: clean clean_docs: - rm -f $(CT_XML_FILES) rm -rf $(HTMLDIR)/* rm -f $(MAN1DIR)/* rm -f $(MAN3DIR)/* diff --git a/lib/common_test/doc/src/basics_chapter.xml b/lib/common_test/doc/src/basics_chapter.xml index a01e3a9272..1a5a686fa0 100644 --- a/lib/common_test/doc/src/basics_chapter.xml +++ b/lib/common_test/doc/src/basics_chapter.xml @@ -31,74 +31,74 @@ </header> <marker id="basics"></marker> <section> - <title>Introduction</title> + <title>General</title> - <p>The <em>Common Test</em> framework (CT) is a tool which supports - implementation and automated execution of test cases towards arbitrary - types of target systems. The CT framework is based on the OTP Test - Server and it's the main tool being used in all testing- and verification - activities that are part of Erlang/OTP system development- and maintenance. + <p>The <c>Common Test</c> framework is a tool that supports + implementation and automated execution of test cases to any + types of target systems. <c>Common Test</c> is the main tool being used + in all testing- and verification activities that are part of Erlang/OTP + system development and maintenance. </p> - <p>Test cases can be executed individually or in batches. Common Test - also features a distributed testing mode with central control and logging - (a feature that makes it possible to test multiple systems independently in - one common session, useful e.g. for running automated large-scale regression - tests). + <p>Test cases can be executed individually or in batches. <c>Common Test</c> + also features a distributed testing mode with central control and logging. + With this feature, multiple systems can be tested independently in + one common session. This is useful, for example, when running automated + large-scale regression tests. </p> <p> - The SUT (System Under Test) may consist of one or several target - nodes. CT contains a generic test server which, together with - other test utilities, is used to perform test case execution. - It is possible to start the tests from a GUI or from the OS- or + The System Under Test (SUT) can consist of one or more target + nodes. <c>Common Test</c> contains a generic test server that, + together with other test utilities, is used to perform test case execution. + The tests can be started from a GUI, from the OS shell, or from an Erlang shell. <em>Test suites</em> are files (Erlang modules) that contain the <em>test cases</em> (Erlang functions) to be executed. <em>Support modules</em> provide functions - that the test cases utilize in order to carry out the tests. + that the test cases use to do the tests. </p> - <p>In a black-box testing scenario, CT based test programs connect to - the target system(s) via standard O&M and CLI protocols. CT + <p>In a black-box testing scenario, <c>Common Test</c>-based test programs connect to + the target system(s) through standard O&M and CLI protocols. <c>Common Test</c> provides implementations of, and wrapper interfaces to, some of these - protocols (most of which exist as stand-alone components and + protocols (most of which exist as standalone components and applications in OTP). The wrappers simplify configuration and add - verbosity for logging purposes. CT will be continously extended with - useful support modules. (Note however that it's - a straightforward task to use any arbitrary Erlang/OTP component - for testing purposes with Common Test, without needing a CT wrapper - for it. It's as simple as calling Erlang functions). There - are a number of target independent interfaces supported in CT, such as - Generic Telnet, FTP, etc, which can be specialized or used - directly for controlling instruments, traffic load generators, etc. + verbosity for logging purposes. <c>Common Test</c> is continously extended with + useful support modules. However, notice that it is + a straightforward task to use any Erlang/OTP component + for testing purposes with <c>Common Test</c>, without needing a <c>Common Test</c> + wrapper for it. It is as simple as calling Erlang functions. A number of + target-independent interfaces are supported in <c>Common Test</c>, such as + Generic Telnet and FTP. These can be specialized or used + directly for controlling instruments, traffic load generators, and so on. </p> - <p>Common Test is also a very useful tool for white-box testing Erlang - code (e.g. module testing), since the test programs can call exported Erlang - functions directly and there's very little overhead required for + <p><c>Common Test</c> is also a very useful tool for white-box testing Erlang + code (for example, module testing), as the test programs can call exported Erlang + functions directly. there is very little overhead required for implementing basic test suites and executing simple tests. For black-box - testing Erlang software, Erlang RPC as well as standard O&M interfaces - can for example be used. + testing Erlang software, Erlang RPC and standard O&M interfaces + can be used for example. </p> - <p>A test case can handle several connections towards one or - several target systems, instruments and traffic generators in - parallel in order to perform the necessary actions for a - test. The handling of many connections in parallel is one of - the major strengths of Common Test (thanks to the efficient - support for concurrency in the Erlang runtime system - which CT users - can take great advantage of!). + <p>A test case can handle several connections to one or + more target systems, instruments, and traffic generators in + parallel to perform the necessary actions for a test. + The handling of many connections in parallel is one of + the major strengths of <c>Common Test</c>, thanks to the efficient + support for concurrency in the Erlang runtime system, which <c>Common Test</c> + users can take great advantage of. </p> </section> <section> <title>Test Suite Organisation</title> <p> - The test suites are organized in test directories and each test suite - may have a separate data directory. Typically, these files and directories - are version controlled similarly to other forms of source code (possibly by - means of a version control system like GIT or Subversion). However, CT does - not itself put any requirements on (or has any form of awareness of) + Test suites are organized in test directories and each test suite + can have a separate data directory. Typically, these files and directories + are version-controlled similar to other forms of source code (possibly by + a version control system like GIT or Subversion). However, <c>Common Test</c> + does not itself put any requirements on (or has any awareness of) possible file and directory versions. </p> </section> @@ -109,8 +109,8 @@ Support libraries contain functions that are useful for all test suites, or for test suites in a specific functional area or subsystem. In addition to the general support libraries provided by the - CT framework, and the various libraries and applications provided by - Erlang/OTP, there might also be a need for customized (user specific) + <c>Common Test</c> framework, and the various libraries and applications provided by + Erlang/OTP, there can also be a need for customized (user specific) support libraries. </p> </section> @@ -121,118 +121,122 @@ Testing is performed by running test suites (sets of test cases) or individual test cases. A test suite is implemented as an Erlang module named <c><![CDATA[<suite_name>_SUITE.erl]]></c> which contains a number of test cases. - A test case is an Erlang function which tests one or more things. - The test case is the smallest unit that the CT test server deals with. + A test case is an Erlang function that tests one or more things. + The test case is the smallest unit that the <c>Common Test</c> test server deals with. </p> <p> - Subsets of test cases, called test case groups, may also be defined. A test case + Subsets of test cases, called test case groups, can also be defined. A test case group can have execution properties associated with it. Execution properties - specify whether the test cases in the group should be executed in - random order, in parallel, in sequence, and if the execution of the group - should be repeated. Test case groups may also be nested (i.e. a group may, - besides test cases, contain sub-groups). + specify if the test cases in the group are to be executed in + random order, in parallel, or in sequence, and if the execution of the group + is to be repeated. Test case groups can also be nested (that is, a group can, + besides test cases, contain subgroups). </p> <p> - Besides test cases and groups, the test suite may also contain configuration + Besides test cases and groups, the test suite can also contain configuration functions. These functions are meant to be used for setting up (and verifying) - environment and state on the SUT (and/or the CT host node), required for - the tests to execute correctly. Examples of operations: Opening a connection - to the SUT, initializing a database, running an installation script, etc. - Configuration may be performed per suite, per test case group and per - individual test case. + environment and state in the SUT (and/or the <c>Common Test</c> host node), + required for the tests to execute correctly. Examples of operations are: + Opening a connection to the SUT, initializing a database, running an installation + script, and so on. Configuration can be performed per suite, per test case group, + and per individual test case. </p> <p> The test suite module must conform to a <seealso marker="common_test">callback interface</seealso> - specified by the CT test server. See the - <seealso marker="write_test_chapter#intro">Writing Test Suites</seealso> chapter - for more information. + specified by the <c>Common Test</c> test server. For details, see section + <seealso marker="write_test_chapter#intro">Writing Test Suites</seealso>. </p> <p> A test case is considered successful if it returns to the caller, no matter - what the returned value is. A few return values have special meaning however - (such as <c>{skip,Reason}</c> which indicates that the test case is skipped, - <c>{comment,Comment}</c> which prints a comment in the log for the test case and - <c>{save_config,Config}</c> which makes the CT test server pass <c>Config</c> to - the next test case). + what the returned value is. However, a few return values have special meaning + as follows:</p> + <list type="bulleted"> + <item><c>{skip,Reason}</c> indicates that the test case is skipped.</item> + <item><c>{comment,Comment}</c> prints a comment in the log for the test case.</item> + <item><c>{save_config,Config}</c> makes the <c>Common Test</c> test server pass + <c>Config</c> to the next test case.</item> + </list> + <p> A test case failure is specified as a runtime error (a crash), no matter what the reason for termination is. If you use Erlang pattern matching effectively, - you can take advantage of this property. The result will be concise and + you can take advantage of this property. The result is concise and readable test case functions that look much more like scripts than actual programs. - Simple example: + A simple example: </p> <pre> - session(_Config) -> - {started,ServerId} = my_server:start(), - {clients,[]} = my_server:get_clients(ServerId), - MyId = self(), - connected = my_server:connect(ServerId, MyId), - {clients,[MyId]} = my_server:get_clients(ServerId), - disconnected = my_server:disconnect(ServerId, MyId), - {clients,[]} = my_server:get_clients(ServerId), - stopped = my_server:stop(ServerId). - </pre> + session(_Config) -> + {started,ServerId} = my_server:start(), + {clients,[]} = my_server:get_clients(ServerId), + MyId = self(), + connected = my_server:connect(ServerId, MyId), + {clients,[MyId]} = my_server:get_clients(ServerId), + disconnected = my_server:disconnect(ServerId, MyId), + {clients,[]} = my_server:get_clients(ServerId), + stopped = my_server:stop(ServerId).</pre> <p> As a test suite runs, all information (including output to <c>stdout</c>) is - recorded in several different log files. A minimum of information is displayed + recorded in many different log files. A minimum of information is displayed in the user console (only start and stop information, plus a note for each failed test case). </p> <p> The result from each test case is recorded in a dedicated HTML log file, created for the particular test run. An overview page displays each test case represented - by row in a table showing total execution time, whether the case was successful, - failed or skipped, plus an optional user comment. (For a failed test case, the - reason for termination is also printed in the comment field). The overview page + by a table row showing total execution time, if the case was successful, + failed, or skipped, plus an optional user comment. For a failed test case, the + reason for termination is also printed in the comment field. The overview page has a link to each test case log file, providing simple navigation with any standard HTML browser. </p> </section> <section> +<marker id="External_Interfaces"></marker> <title>External Interfaces</title> <p> - The CT test server requires that the test suite defines and exports the + The <c>Common Test</c> test server requires that the test suite defines and exports the following mandatory or optional callback functions: </p> <taglist> - <tag>all()</tag> - <item>Returns a list of all test cases and groups in the suite. (Mandatory)</item> - <tag>suite()</tag> - <item>Info function used to return properties for the suite. (Optional)</item> - <tag>groups()</tag> - <item>For declaring test case groups. (Optional)</item> - <tag>init_per_suite(Config)</tag> - <item>Suite level configuration function, executed before the first - test case. (Optional)</item> - <tag>end_per_suite(Config)</tag> - <item>Suite level configuration function, executed after the last - test case. (Optional)</item> - <tag>group(GroupName)</tag> - <item>Info function used to return properties for a test case group. (Optional)</item> - <tag>init_per_group(GroupName, Config)</tag> - <item>Configuration function for a group, executed before the first - test case. (Optional)</item> - <tag>end_per_group(GroupName, Config)</tag> - <item>Configuration function for a group, executed after the last - test case. (Optional)</item> - <tag>init_per_testcase(TestCase, Config)</tag> - <item>Configuration function for a testcase, executed before each - test case. (Optional)</item> - <tag>end_per_testcase(TestCase, Config)</tag> - <item>Configuration function for a testcase, executed after each - test case. (Optional)</item> + <tag><c>all()</c></tag> + <item><p>Returns a list of all test cases and groups in the suite. (Mandatory)</p></item> + <tag><c>suite()</c></tag> + <item><p>Information function used to return properties for the suite. (Optional)</p></item> + <tag><c>groups()</c></tag> + <item><p>For declaring test case groups. (Optional)</p></item> + <tag><c>init_per_suite(Config)</c></tag> + <item><p>Suite level configuration function, executed before the first + test case. (Optional)</p></item> + <tag><c>end_per_suite(Config)</c></tag> + <item><p>Suite level configuration function, executed after the last + test case. (Optional)</p></item> + <tag><c>group(GroupName)</c></tag> + <item><p>Information function used to return properties for a test case group. (Optional)</p></item> + <tag><c>init_per_group(GroupName, Config)</c></tag> + <item><p>Configuration function for a group, executed before the first + test case. (Optional)</p></item> + <tag><c>end_per_group(GroupName, Config)</c></tag> + <item><p>Configuration function for a group, executed after the last + test case. (Optional)</p></item> + <tag><c>init_per_testcase(TestCase, Config)</c></tag> + <item><p>Configuration function for a testcase, executed before each + test case. (Optional)</p></item> + <tag><c>end_per_testcase(TestCase, Config)</c></tag> + <item><p>Configuration function for a testcase, executed after each + test case. (Optional)</p></item> </taglist> <p> - For each test case the CT test server expects these functions: + For each test case, the <c>Common Test</c> test server expects the + following functions: </p> <taglist> <tag>Testcasename()</tag> - <item>Info function that returns a list of test case properties. (Optional)</item> + <item><p>Information function that returns a list of test case properties. (Optional)</p></item> <tag>Testcasename(Config)</tag> - <item>The actual test case function.</item> + <item><p>The test case function.</p></item> </taglist> </section> </chapter> diff --git a/lib/common_test/doc/src/common_test_app.xml b/lib/common_test/doc/src/common_test_app.xml index cc554eb84e..10c93e2ed1 100644 --- a/lib/common_test/doc/src/common_test_app.xml +++ b/lib/common_test/doc/src/common_test_app.xml @@ -33,89 +33,84 @@ <file>common_test_app.sgml</file> </header> <module>common_test</module> - <modulesummary>A framework for automated testing of arbitrary target nodes</modulesummary> + <modulesummary>A framework for automated testing of any target nodes.</modulesummary> <description> - <p>The <em>Common Test</em> framework is an environment for + <p>The <c>Common Test</c> framework is an environment for implementing and performing automatic and semi-automatic execution of - test cases. + test cases.</p> - Common Test uses the OTP Test Server as engine for test case - execution and logging.</p> - - <p>In brief, Common Test supports:</p> + <p>In brief, <c>Common Test</c> supports:</p> <list> - <item>Automated execution of test suites (sets of test cases).</item> - <item>Logging of the events during execution.</item> - <item>HTML presentation of test suite results.</item> - <item>HTML presentation of test suite code.</item> - <item>Support functions for test suite authors.</item> - <item>Step by step execution of test cases.</item> + <item>Automated execution of test suites (sets of test cases)</item> + <item>Logging of events during execution</item> + <item>HTML presentation of test suite results</item> + <item>HTML presentation of test suite code</item> + <item>Support functions for test suite authors</item> + <item>Step-by-step execution of test cases</item> </list> - - <p>The following sections describe the mandatory and optional test suite - functions Common Test will call during test execution. For more details - see <seealso marker="write_test_chapter">Common Test User's - Guide.</seealso> </p> - + + <p>The following section describes the mandatory and optional test suite + functions that <c>Common Test</c> calls during test execution. + For more details, see section + <seealso marker="write_test_chapter">Writing Test Suites</seealso> + in the User's Guide.</p> + </description> <section> - <title>TEST CASE CALLBACK FUNCTIONS</title> + <title>Test Case Callback Functions</title> <p>The following functions define the callback interface for a test suite.</p> </section> - + <funcs> <func> <name>Module:all() -> Tests | {skip,Reason} </name> <fsummary>Returns the list of all test case groups and test cases in the module.</fsummary> <type> - <v>Tests = [TestCase | {group,GroupName} | - {group,GroupName,Properties} | - {group,GroupName,Properties,SubGroups}]</v> + <v>Tests = [TestCase | {group,GroupName} | {group,GroupName,Properties} | {group,GroupName,Properties,SubGroups}]</v> <v>TestCase = atom()</v> <v>GroupName = atom()</v> - <v>Properties = [parallel | sequence | Shuffle | {RepeatType,N}] | - default</v> - <v>SubGroups = [{GroupName,Properties} | - {GroupName,Properties,SubGroups}]</v> + <v>Properties = [parallel | sequence | Shuffle | {RepeatType,N}] | default</v> + <v>SubGroups = [{GroupName,Properties} | {GroupName,Properties,SubGroups}]</v> <v>Shuffle = shuffle | {shuffle,Seed}</v> <v>Seed = {integer(),integer(),integer()}</v> - <v>RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | - repeat_until_any_ok | repeat_until_any_fail</v> + <v>RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | repeat_until_any_ok | repeat_until_any_fail</v> <v>N = integer() | forever</v> <v>Reason = term()</v> </type> - + <desc> - <p> MANDATORY </p> - - <p>This function must return the list of all test cases and test - case groups in the test suite module that are to be executed. - This list also specifies the order the cases and groups will - be executed by Common Test. A test case is represented by an atom, + <p>MANDATORY</p> + + <p>Returns the list of all test cases and test case groups in the + test suite module to be executed. This list also specifies the + order the cases and groups are executed by <c>Common Test</c>. + A test case is represented by an atom, the name of the test case function. A test case group is represented by a <c>group</c> tuple, where <c>GroupName</c>, - an atom, is the name of the group (defined in <seealso marker="#Module:groups-0"><c>groups/0</c></seealso>). - Execution properties for groups may also be specified, both - for a top level group and for any of its sub-groups. - Group execution properties specified here, will override - properties in the group definition (see <seealso marker="#Module:groups-0"><c>groups/0</c></seealso>). + an atom, is the name of the group (defined in + <seealso marker="#Module:groups-0"><c>groups/0</c></seealso>). + Execution properties for groups can also be specified, both + for a top-level group and for any of its subgroups. + Group execution properties specified here override + properties in the group definition (see + <seealso marker="#Module:groups-0"><c>groups/0</c></seealso>). (With value <c>default</c>, the group definition properties - will be used).</p> - - <p> If <c>{skip,Reason}</c> is returned, all test cases - in the module will be skipped, and the <c>Reason</c> will - be printed on the HTML result page.</p> - - <p>For details on groups, see - <seealso marker="write_test_chapter#test_case_groups">Test case - groups</seealso> in the User's Guide.</p> - + are used).</p> + + <p>If <c>{skip,Reason}</c> is returned, all test cases + in the module are skipped and <c>Reason</c> + is printed on the HTML result page.</p> + + <p>For details on groups, see section + <seealso marker="write_test_chapter#test_case_groups">Test Case + Groups</seealso> in the User's Guide.</p> + </desc> </func> @@ -123,25 +118,24 @@ <name>Module:groups() -> GroupDefs</name> <fsummary>Returns a list of test case group definitions.</fsummary> <type> - <v>GroupDefs = [Group]</v> - <v>Group = {GroupName,Properties,GroupsAndTestCases}</v> - <v>GroupName = atom()</v> - <v>Properties = [parallel | sequence | Shuffle | {RepeatType,N}]</v> - <v>GroupsAndTestCases = [Group | {group,GroupName} | TestCase]</v> - <v>TestCase = atom()</v> - <v>Shuffle = shuffle | {shuffle,Seed}</v> - <v>Seed = {integer(),integer(),integer()}</v> - <v>RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | - repeat_until_any_ok | repeat_until_any_fail</v> - <v>N = integer() | forever</v> + <v>GroupDefs = [Group]</v> + <v>Group = {GroupName,Properties,GroupsAndTestCases}</v> + <v>GroupName = atom()</v> + <v>Properties = [parallel | sequence | Shuffle | {RepeatType,N}]</v> + <v>GroupsAndTestCases = [Group | {group,GroupName} | TestCase]</v> + <v>TestCase = atom()</v> + <v>Shuffle = shuffle | {shuffle,Seed}</v> + <v>Seed = {integer(),integer(),integer()}</v> + <v>RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | repeat_until_any_ok | repeat_until_any_fail</v> + <v>N = integer() | forever</v> </type> - + <desc> - <p> OPTIONAL </p> - - <p>Function for defining test case groups. Please see - <seealso marker="write_test_chapter#test_case_groups">Test case - groups</seealso> in the User's Guide for details.</p> + <p>OPTIONAL</p> + + <p>Defines test case groups. For details, see section + <seealso marker="write_test_chapter#test_case_groups">Test Case + Groups</seealso> in the User's Guide.</p> </desc> </func> @@ -150,75 +144,71 @@ <fsummary>Test suite info function (providing default data for the suite).</fsummary> <type> - <v> Info = {timetrap,Time} | {require,Required} | - {require,Name,Required} | {userdata,UserData} | - {silent_connections,Conns} | {stylesheet,CSSFile} | - {ct_hooks, CTHs}</v> - <v> Time = TimeVal | TimeFunc</v> - <v> TimeVal = MilliSec | {seconds,integer()} | {minutes,integer()} | - {hours,integer()}</v> - <v> TimeFunc = {Mod,Func,Args} | Fun</v> - <v> MilliSec = integer()</v> - <v> Mod = atom()</v> - <v> Func = atom()</v> - <v> Args = list()</v> - <v> Fun = fun()</v> - <v> Required = Key | {Key,SubKeys} | {Key,SubKey} | {Key,SubKey,SubKeys}</v> - <v> Key = atom()</v> - <v> SubKeys = SubKey | [SubKey]</v> - <v> SubKey = atom()</v> - <v> Name = atom()</v> - <v> UserData = term()</v> - <v> Conns = [atom()]</v> - <v> CSSFile = string()</v> - <v> CTHs = [CTHModule |</v> - <v> {CTHModule, CTHInitArgs} |</v> - <v> {CTHModule, CTHInitArgs, CTHPriority}]</v> - <v> CTHModule = atom()</v> - <v> CTHInitArgs = term()</v> + <v>Info = {timetrap,Time} | {require,Required} | {require,Name,Required} | {userdata,UserData} | {silent_connections,Conns} | {stylesheet,CSSFile} | {ct_hooks, CTHs}</v> + <v>Time = TimeVal | TimeFunc</v> + <v>TimeVal = MilliSec | {seconds,integer()} | {minutes,integer()} | {hours,integer()}</v> + <v>TimeFunc = {Mod,Func,Args} | Fun</v> + <v>MilliSec = integer()</v> + <v>Mod = atom()</v> + <v>Func = atom()</v> + <v>Args = list()</v> + <v>Fun = fun()</v> + <v>Required = Key | {Key,SubKeys} | {Key,SubKey} | {Key,SubKey,SubKeys}</v> + <v>Key = atom()</v> + <v>SubKeys = SubKey | [SubKey]</v> + <v>SubKey = atom()</v> + <v>Name = atom()</v> + <v>UserData = term()</v> + <v>Conns = [atom()]</v> + <v>CSSFile = string()</v> + <v>CTHs = [CTHModule |</v> + <v> {CTHModule, CTHInitArgs} |</v> + <v> {CTHModule, CTHInitArgs, CTHPriority}]</v> + <v>CTHModule = atom()</v> + <v>CTHInitArgs = term()</v> </type> <desc> - - <p> OPTIONAL </p> - - <p>This is the test suite info function. It is supposed to - return a list of tagged tuples that specify various properties - related to the execution of this test suite (common for all - test cases in the suite).</p> - - <p>The <c>timetrap</c> tag sets the maximum time each - test case is allowed to execute (including <seealso marker="#Module:init_per_testcase-2"><c>init_per_testcase/2</c></seealso> - and <seealso marker="#Module:end_per_testcase-2"><c>end_per_testcase/2</c></seealso>). If the timetrap time is - exceeded, the test case fails with reason + + <p>OPTIONAL</p> + + <p>The test suite information function. Returns a list of tagged + tuples specifying various properties related to the execution of + this test suite (common for all test cases in the suite).</p> + + <p>Tag <c>timetrap</c> sets the maximum time that each + test case is allowed to execute (including + <seealso marker="#Module:init_per_testcase-2"><c>init_per_testcase/2</c></seealso> + and + <seealso marker="#Module:end_per_testcase-2"><c>end_per_testcase/2</c></seealso>). + If the timetrap time is exceeded, the test case fails with reason <c>timetrap_timeout</c>. A <c>TimeFunc</c> function can be used to - set a new timetrap by returning a <c>TimeVal</c>. It may also be - used to trigger a timetrap timeout by, at some point, returning a - value other than a <c>TimeVal</c>. (See the - <seealso marker="write_test_chapter#timetraps">User's Guide</seealso> - for details). - </p> - - <p>The <c>require</c> tag specifies configuration variables - that are required by test cases (and/or configuration functions) + set a new timetrap by returning a <c>TimeVal</c>. It can also be + used to trigger a timetrap time-out by, at some point, returning a + value other than a <c>TimeVal</c>. For details, see section + <seealso marker="write_test_chapter#timetraps">Timetrap Time-Outs</seealso> + in the User's Guide.</p> + + <p>Tag <c>require</c> specifies configuration variables + required by test cases (or configuration functions) in the suite. If the required configuration variables are not found - in any of the configuration files, all test cases are skipped. For more - information about the 'require' functionality, see the - reference manual for the function - <seealso marker="ct#require-1"><c>ct:require/1/2</c></seealso>.</p> + in any of the configuration files, all test cases are skipped. + For details about the <c>require</c> functionality, see funtion + <seealso marker="ct#require-1"><c>ct:require/1,2</c></seealso>.</p> - <p>With <c>userdata</c>, it is possible for the user to - specify arbitrary test suite related information which can be - read by calling <seealso marker="ct#userdata-2"><c>ct:userdata/2</c></seealso>.</p> + <p>With <c>userdata</c>, the user can + specify any test suite-related information, which can be + read by calling + <seealso marker="ct#userdata-2"><c>ct:userdata/2</c></seealso>.</p> - <p>The <c>ct_hooks</c> tag specifies which + <p>Tag <c>ct_hooks</c> specifies the <seealso marker="ct_hooks_chapter">Common Test Hooks</seealso> - are to be run together with this suite.</p> - - <p>Other tuples than the ones defined will simply be ignored.</p> + to be run with this suite.</p> - <p>For more information about the test suite info function, - see <seealso marker="write_test_chapter#suite">Test - suite info function</seealso> in the User's Guide.</p> + <p>Other tuples than the ones defined are ignored.</p> + + <p>For details about the test suite information function, see section + <seealso marker="write_test_chapter#suite">Test + Suite Information Function</seealso> in the User's Guide.</p> </desc> </func> @@ -227,129 +217,133 @@ {skip_and_save,Reason,SaveConfig}</name> <fsummary>Test suite initializations.</fsummary> <type> - <v> Config = NewConfig = SaveConfig = [{Key,Value}]</v> - <v> Key = atom()</v> - <v> Value = term()</v> - <v> Reason = term()</v> + <v>Config = NewConfig = SaveConfig = [{Key,Value}]</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> <desc> - - <p> OPTIONAL </p> - + + <p>OPTIONAL</p> + <p>This configuration function is called as the first function in the - suite. It typically contains initializations which are common for - all test cases in the suite, and which shall only be done - once. The <c>Config</c> parameter is the configuration data - which can be modified here. Whatever is returned from this - function is given as <c>Config</c> to all configuration functions - and test cases in the suite. If <c>{skip,Reason}</c> - is returned, all test cases in the suite will be skipped - and <c>Reason</c> printed in the overview log for the suite.</p> - <p>For information on <c>save_config</c> and <c>skip_and_save</c>, - please see - <seealso marker="dependencies_chapter#save_config">Dependencies - between Test Cases and Suites</seealso> in the User's Guide.</p> - </desc> + suite. It typically contains initializations that are common for + all test cases in the suite, and that must only be done + once. Parameter <c>Config</c> is the configuration data + that can be modified. Whatever is returned from this + function is specified as <c>Config</c> to all configuration functions + and test cases in the suite.</p> + + <p>If <c>{skip,Reason}</c> + is returned, all test cases in the suite are skipped + and <c>Reason</c> is printed in the overview log for the suite.</p> + + <p>For information on <c>save_config</c> and <c>skip_and_save</c>, + see section + <seealso marker="dependencies_chapter#save_config">Saving + Configuration Data</seealso> in the User's Guide.</p> + </desc> </func> - + <func> <name>Module:end_per_suite(Config) -> term() | {save_config,SaveConfig}</name> - <fsummary>Test suite finalization. </fsummary> + <fsummary>Test suite finalization.</fsummary> <type> - <v> Config = SaveConfig = [{Key,Value}]</v> - <v> Key = atom()</v> - <v> Value = term()</v> + <v>Config = SaveConfig = [{Key,Value}]</v> + <v>Key = atom()</v> + <v>Value = term()</v> </type> - + <desc> - <p> OPTIONAL </p> + <p>OPTIONAL</p> <p>This function is called as the last test case in the suite. It is meant to be used for cleaning up after - <seealso marker="#Module:init_per_suite-1"><c>init_per_suite/1</c></seealso>. - For information on <c>save_config</c>, please see - <seealso marker="dependencies_chapter#save_config">Dependencies - between Test Cases and Suites</seealso> in the User's Guide.</p> + <seealso marker="#Module:init_per_suite-1"><c>init_per_suite/1</c></seealso>.</p> + <p>For information on <c>save_config</c>, see section + <seealso marker="dependencies_chapter#save_config">Saving + Configuration Data</seealso> in the User's Guide.</p> </desc> </func> <func> <name>Module:group(GroupName) -> [Info] </name> - <fsummary>Test case group info function (providing default data - for a test case group, i.e. its test cases and sub-groups).</fsummary> + <fsummary>Test case group information function (providing default data + for a test case group, that is, its test cases and + subgroups).</fsummary> <type> - <v> Info = {timetrap,Time} | {require,Required} | - {require,Name,Required} | {userdata,UserData} | - {silent_connections,Conns} | {stylesheet,CSSFile} | - {ct_hooks, CTHs}</v> - <v> Time = TimeVal | TimeFunc</v> - <v> TimeVal = MilliSec | {seconds,integer()} | {minutes,integer()} | - {hours,integer()}</v> - <v> TimeFunc = {Mod,Func,Args} | Fun</v> - <v> MilliSec = integer()</v> - <v> Mod = atom()</v> - <v> Func = atom()</v> - <v> Args = list()</v> - <v> Fun = fun()</v> - <v> Required = Key | {Key,SubKeys} | {Key,Subkey} | {Key,Subkey,SubKeys}</v> - <v> Key = atom()</v> - <v> SubKeys = SubKey | [SubKey]</v> - <v> SubKey = atom()</v> - <v> Name = atom()</v> - <v> UserData = term()</v> - <v> Conns = [atom()]</v> - <v> CSSFile = string()</v> - <v> CTHs = [CTHModule |</v> - <v> {CTHModule, CTHInitArgs} |</v> - <v> {CTHModule, CTHInitArgs, CTHPriority}]</v> - <v> CTHModule = atom()</v> - <v> CTHInitArgs = term()</v> - </type> - <desc> - - <p> OPTIONAL </p> - - <p>This is the test case group info function. It is supposed to + <v>Info = {timetrap,Time} | {require,Required} | {require,Name,Required} | {userdata,UserData} | {silent_connections,Conns} | {stylesheet,CSSFile} | {ct_hooks, CTHs}</v> + <v>Time = TimeVal | TimeFunc</v> + <v>TimeVal = MilliSec | {seconds,integer()} | {minutes,integer()} | {hours,integer()}</v> + <v>TimeFunc = {Mod,Func,Args} | Fun</v> + <v>MilliSec = integer()</v> + <v>Mod = atom()</v> + <v>Func = atom()</v> + <v>Args = list()</v> + <v>Fun = fun()</v> + <v>Required = Key | {Key,SubKeys} | {Key,Subkey} | {Key,Subkey,SubKeys}</v> + <v>Key = atom()</v> + <v>SubKeys = SubKey | [SubKey]</v> + <v>SubKey = atom()</v> + <v>Name = atom()</v> + <v>UserData = term()</v> + <v>Conns = [atom()]</v> + <v>CSSFile = string()</v> + <v>CTHs = [CTHModule |</v> + <v> {CTHModule, CTHInitArgs} |</v> + <v> {CTHModule, CTHInitArgs, CTHPriority}]</v> + <v>CTHModule = atom()</v> + <v>CTHInitArgs = term()</v> + </type> + <desc> + + <p>OPTIONAL</p> + + <p>The test case group information function. It is supposed to return a list of tagged tuples that specify various properties - related to the execution of a test case group (i.e. its test cases - and sub-groups). Properties set by + related to the execution of a test case group (that is, its test + cases and subgroups). Properties set by <seealso marker="#Module:group-1"><c>group/1</c></seealso> override - properties with the same key that have been previously set by + properties with the same key that have been set previously by <seealso marker="#Module:suite-0"><c>suite/0</c></seealso>.</p> - <p>The <c>timetrap</c> tag sets the maximum time each - test case is allowed to execute (including <seealso marker="#Module:init_per_testcase-2"><c>init_per_testcase/2</c></seealso> - and <seealso marker="#Module:end_per_testcase-2"><c>end_per_testcase/2</c></seealso>). If the timetrap time is + <p>Tag <c>timetrap</c> sets the maximum time that each + test case is allowed to execute (including + <seealso marker="#Module:init_per_testcase-2"><c>init_per_testcase/2</c></seealso> + and + <seealso marker="#Module:end_per_testcase-2"><c>end_per_testcase/2</c></seealso>). + If the timetrap time is exceeded, the test case fails with reason <c>timetrap_timeout</c>. A <c>TimeFunc</c> function can be used to - set a new timetrap by returning a <c>TimeVal</c>. It may also be - used to trigger a timetrap timeout by, at some point, returning a - value other than a <c>TimeVal</c>. (See the - <seealso marker="write_test_chapter#timetraps">User's Guide</seealso> - for details).</p> + set a new timetrap by returning a <c>TimeVal</c>. It can also be + used to trigger a timetrap time-out by, at some point, returning a + value other than a <c>TimeVal</c>. For details, see section + <seealso marker="write_test_chapter#timetraps">Timetrap + Time-Outs</seealso> in the User's Guide.</p> - <p>The <c>require</c> tag specifies configuration variables - that are required by test cases (and/or configuration functions) + <p>Tag <c>require</c> specifies configuration variables + required by test cases (or configuration functions) in the suite. If the required configuration variables are not found - in any of the configuration files, all test cases in this group are skipped. - For more information about the 'require' functionality, see the - reference manual for the function - <seealso marker="ct#require-1"><c>ct:require/1/2</c></seealso>.</p> + in any of the configuration files, all test cases in this group are + skipped. For details about the <c>require</c> functionality, see + function + <seealso marker="ct#require-1"><c>ct:require/1,2</c></seealso>.</p> - <p>With <c>userdata</c>, it is possible for the user to - specify arbitrary test case group related information which can be - read by calling <seealso marker="ct#userdata-2"><c>ct:userdata/2</c></seealso>.</p> + <p>With <c>userdata</c>, the user can + specify any test case group related information that can be + read by calling + <seealso marker="ct#userdata-2"><c>ct:userdata/2</c></seealso>.</p> - <p>The <c>ct_hooks</c> tag specifies which + <p>Tag <c>ct_hooks</c> specifies the <seealso marker="ct_hooks_chapter">Common Test Hooks</seealso> - are to be run together with this suite.</p> - - <p>Other tuples than the ones defined will simply be ignored.</p> + to be run with this suite.</p> - <p>For more information about the test case group info function, - see <seealso marker="write_test_chapter#suite">Test - case group info function</seealso> in the User's Guide.</p> + <p>Other tuples than the ones defined are ignored.</p> + + <p>For details about the test case group information function, + see section <seealso marker="write_test_chapter#group_info">Group + Information Function</seealso> in the User's Guide.</p> </desc> </func> @@ -358,59 +352,66 @@ {skip,Reason}</name> <fsummary>Test case group initializations.</fsummary> <type> - <v> GroupName = atom()</v> - <v> Config = NewConfig = [{Key,Value}]</v> - <v> Key = atom()</v> - <v> Value = term()</v> - <v> Reason = term()</v> + <v>GroupName = atom()</v> + <v>Config = NewConfig = [{Key,Value}]</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> <desc> - - <p> OPTIONAL </p> - + + <p>OPTIONAL</p> + <p>This configuration function is called before execution of a - test case group. It typically contains initializations which are - common for all test cases and sub-groups in the group, and which - shall only be performed once. <c>GroupName</c> is the name of the - group, as specified in the group definition (see <seealso marker="#Module:groups-0"><c>groups/0</c></seealso>). The - <c>Config</c> parameter is the configuration data which can be modified - here. The return value of this function is given as <c>Config</c> - to all test cases and sub-groups in the group. If <c>{skip,Reason}</c> - is returned, all test cases in the group will be skipped and - <c>Reason</c> printed in the overview log for the group.</p> - - <p>For information about test case groups, please see - <seealso marker="write_test_chapter#test_case_groups">Test case - groups</seealso> chapter in the User's Guide.</p> + test case group. It typically contains initializations that are + common for all test cases and subgroups in the group, and that + must only be performed once. <c>GroupName</c> is the name of the + group, as specified in the group definition (see + <seealso marker="#Module:groups-0"><c>groups/0</c></seealso>). + Parameter <c>Config</c> is the configuration data that can be + modified. + The return value of this function is given as <c>Config</c> + to all test cases and subgroups in the group.</p> + + <p>If <c>{skip,Reason}</c> + is returned, all test cases in the group are skipped and + <c>Reason</c> is printed in the overview log for the group.</p> + + <p>For information about test case groups, see section + <seealso marker="write_test_chapter#test_case_groups">Test Case + Groups</seealso> in the User's Guide.</p> </desc> </func> - + <func> <name>Module:end_per_group(GroupName, Config) -> term() | {return_group_result,Status}</name> <fsummary>Test case group finalization.</fsummary> <type> - <v> GroupName = atom()</v> - <v> Config = [{Key,Value}]</v> - <v> Key = atom()</v> - <v> Value = term()</v> - <v> Status = ok | skipped | failed</v> + <v>GroupName = atom()</v> + <v>Config = [{Key,Value}]</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Status = ok | skipped | failed</v> </type> - + <desc> - <p> OPTIONAL </p> - - <p>This function is called after the execution of a test case group is finished. - It is meant to be used for cleaning up after <seealso marker="#Module:init_per_group-2"><c>init_per_group/2</c></seealso>. - By means of <c>{return_group_result,Status}</c>, it is possible to return a - status value for a nested sub-group. The status can be retrieved in - <seealso marker="#Module:end_per_group-2"><c>end_per_group/2</c></seealso> for the group on the level above. The status will also - be used by Common Test for deciding if execution of a group should proceed in - case the property <c>sequence</c> or <c>repeat_until_*</c> is set.</p> - - <p>For more information about test case groups, please see - <seealso marker="write_test_chapter#test_case_groups">Test case - groups</seealso> chapter in the User's Guide.</p> + <p>OPTIONAL</p> + + <p>This function is called after the execution of a test case group + is finished. It is meant to be used for cleaning up after + <seealso marker="#Module:init_per_group-2"><c>init_per_group/2</c></seealso>. + A status value for a nested subgroup can be returned with + <c>{return_group_result,Status}</c>. The status can be retrieved in + <seealso marker="#Module:end_per_group-2"><c>end_per_group/2</c></seealso> + for the group on the level above. The status is also used by + <c>Common Test</c> for deciding if execution of a group is to + proceed if property <c>sequence</c> or <c>repeat_until_*</c> + is set.</p> + + <p>For details about test case groups, see section + <seealso marker="write_test_chapter#test_case_groups">Test Case + Groups</seealso> in the User's Guide.</p> </desc> </func> @@ -424,168 +425,173 @@ <v> Value = term()</v> <v> Reason = term()</v> </type> - <desc> - + <desc> + <p>OPTIONAL</p> - - <p>This function is called before each test case. The - <c>TestCase</c> argument is the name of the test case, and + + <p>This function is called before each test case. Argument + <c>TestCase</c> is the test case name, and <c>Config</c> (list of key-value tuples) is the configuration - data that can be modified here. The <c>NewConfig</c> list returned + data that can be modified. The <c>NewConfig</c> list returned from this function is given as <c>Config</c> to the test case. If <c>{fail,Reason}</c> is returned, the test case is - marked as failed without being executed. If <c>{skip,Reason}</c> is - returned, the test case will be skipped and <c>Reason</c> printed - in the overview log for the suite.</p> + marked as failed without being executed.</p> + + <p>If <c>{skip,Reason}</c> is returned, the test case is skipped + and <c>Reason</c> is printed in the overview log for the suite.</p> </desc> </func> - + <func> <name>Module:end_per_testcase(TestCase, Config) -> term() | {fail,Reason} | {save_config,SaveConfig}</name> <fsummary>Test case finalization.</fsummary> <type> - <v> TestCase = atom()</v> - <v> Config = SaveConfig = [{Key,Value}]</v> - <v> Key = atom()</v> - <v> Value = term()</v> - <v> Reason = term()</v> + <v>TestCase = atom()</v> + <v>Config = SaveConfig = [{Key,Value}]</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> <desc> - - <p> OPTIONAL </p> - - <p> This function is called after each test case, and can be used - to clean up after <seealso marker="#Module:init_per_testcase-2"><c>init_per_testcase/2</c></seealso> and the test case. - Any return value (besides <c>{fail,Reason}</c> and <c>{save_config,SaveConfig}</c>) - is ignored. By returning <c>{fail,Reason}</c>, <c>TestCase</c> will be marked as - failed (even though it was actually successful in the sense that it returned - a value instead of terminating). For information on <c>save_config</c>, please see - <seealso marker="dependencies_chapter#save_config">Dependencies between - Test Cases and Suites</seealso> in the User's Guide</p> + + <p>OPTIONAL</p> + + <p>This function is called after each test case, and can be used + to clean up after + <seealso marker="#Module:init_per_testcase-2"><c>init_per_testcase/2</c></seealso> + and the test case. Any return value (besides <c>{fail,Reason}</c> + and <c>{save_config,SaveConfig}</c>) is ignored. By returning + <c>{fail,Reason}</c>, <c>TestCase</c> is marked as faulty (even + though it was successful in the sense that it returned + a value instead of terminating).</p> + + <p>For information on <c>save_config</c>, see section + <seealso marker="dependencies_chapter#save_config">Saving + Configuration Data</seealso> in the User's Guide.</p> </desc> </func> - + <func> <name>Module:Testcase() -> [Info] </name> - <fsummary>Test case info function. </fsummary> + <fsummary>Test case information function.</fsummary> <type> - <v> Info = {timetrap,Time} | {require,Required} | - {require,Name,Required} | {userdata,UserData} | - {silent_connections,Conns}</v> - <v> Time = TimeVal | TimeFunc</v> - <v> TimeVal = MilliSec | {seconds,integer()} | {minutes,integer()} | - {hours,integer()}</v> - <v> TimeFunc = {Mod,Func,Args} | Fun</v> - <v> MilliSec = integer()</v> - <v> Mod = atom()</v> - <v> Func = atom()</v> - <v> Args = list()</v> - <v> Fun = fun()</v> - <v> Required = Key | {Key,SubKeys} | {Key,Subkey} | {Key,Subkey,SubKeys}</v> - <v> Key = atom()</v> - <v> SubKeys = SubKey | [SubKey]</v> - <v> SubKey = atom()</v> - <v> Name = atom()</v> - <v> UserData = term()</v> - <v> Conns = [atom()]</v> + <v>Info = {timetrap,Time} | {require,Required} | {require,Name,Required} | {userdata,UserData} | {silent_connections,Conns}</v> + <v>Time = TimeVal | TimeFunc</v> + <v>TimeVal = MilliSec | {seconds,integer()} | {minutes,integer()} | {hours,integer()}</v> + <v>TimeFunc = {Mod,Func,Args} | Fun</v> + <v>MilliSec = integer()</v> + <v>Mod = atom()</v> + <v>Func = atom()</v> + <v>Args = list()</v> + <v>Fun = fun()</v> + <v>Required = Key | {Key,SubKeys} | {Key,Subkey} | {Key,Subkey,SubKeys}</v> + <v>Key = atom()</v> + <v>SubKeys = SubKey | [SubKey]</v> + <v>SubKey = atom()</v> + <v>Name = atom()</v> + <v>UserData = term()</v> + <v>Conns = [atom()]</v> </type> - - <desc> + + <desc> <p>OPTIONAL</p> - - <p>This is the test case info function. It is supposed to + + <p>The test case information function. It is supposed to return a list of tagged tuples that specify various properties related to the execution of this particular test case. - Properties set by <seealso marker="#Module:Testcase-0"><c>Testcase/0</c></seealso> override - properties that have been previously set for the test case - by <seealso marker="#Module:group-1"><c>group/1</c></seealso> or <seealso marker="#Module:suite-0"><c>suite/0</c></seealso>.</p> - - <p>The <c>timetrap</c> tag sets the maximum time the + Properties set by + <seealso marker="#Module:Testcase-0"><c>Testcase/0</c></seealso> + override properties set previously for the test case by + <seealso marker="#Module:group-1"><c>group/1</c></seealso> or + <seealso marker="#Module:suite-0"><c>suite/0</c></seealso>.</p> + + <p>Tag <c>timetrap</c> sets the maximum time that the test case is allowed to execute. If the timetrap time is - exceeded, the test case fails with reason - <c>timetrap_timeout</c>. <seealso marker="#Module:init_per_testcase-2"><c>init_per_testcase/2</c></seealso> - and <seealso marker="#Module:end_per_testcase-2"><c>end_per_testcase/2</c></seealso> are included in the - timetrap time. A <c>TimeFunc</c> function can be used to - set a new timetrap by returning a <c>TimeVal</c>. It may also be - used to trigger a timetrap timeout by, at some point, returning a - value other than a <c>TimeVal</c>. (See the - <seealso marker="write_test_chapter#timetraps">User's Guide</seealso> - for details).</p> + exceeded, the test case fails with reason <c>timetrap_timeout</c>. + <seealso marker="#Module:init_per_testcase-2"><c>init_per_testcase/2</c></seealso> + and + <seealso marker="#Module:end_per_testcase-2"><c>end_per_testcase/2</c></seealso> + are included in the timetrap time. + A <c>TimeFunc</c> function can be used to + set a new timetrap by returning a <c>TimeVal</c>. It can also be + used to trigger a timetrap time-out by, at some point, returning a + value other than a <c>TimeVal</c>. For details, see section + <seealso marker="write_test_chapter#timetraps">Timetrap + Time-Outs</seealso> in the User's Guide.</p> - <p>The <c>require</c> tag specifies configuration variables - that are required by the test case (and/or <c>init/end_per_testcase/2</c>). + <p>Tag <c>require</c> specifies configuration variables + that are required by the test case (or <c>init_per_testcase/2</c> + or <c>end_per_testcase/2</c>). If the required configuration variables are not found in any of the - configuration files, the test case is skipped. For more - information about the 'require' functionality, see the - reference manual for the function - <seealso marker="ct#require-1"><c>ct:require/1/2</c></seealso>.</p> - - <p>If <c>timetrap</c> and/or <c>require</c> is not set, the - default values specified by <seealso marker="#Module:suite-0"><c>suite/0</c></seealso> (or - <seealso marker="#Module:group-1"><c>group/1</c></seealso>) will be used.</p> - - <p>With <c>userdata</c>, it is possible for the user to - specify arbitrary test case related information which can be - read by calling <seealso marker="ct#userdata-3"><c>ct:userdata/3</c></seealso>.</p> - - <p>Other tuples than the ones defined will simply be ignored.</p> + configuration files, the test case is skipped. For details about + the <c>require</c> functionality, see function + <seealso marker="ct#require-1"><c>ct:require/1,2</c></seealso>.</p> + + <p>If <c>timetrap</c> or <c>require</c> is not set, the + default values specified by + <seealso marker="#Module:suite-0"><c>suite/0</c></seealso> (or + <seealso marker="#Module:group-1"><c>group/1</c></seealso>) are used.</p> + + <p>With <c>userdata</c>, the user can specify any test case-related + information that can be read by calling + <seealso marker="ct#userdata-3"><c>ct:userdata/3</c></seealso>.</p> + + <p>Other tuples than the ones defined are ignored.</p> - <p>For more information about the test case info function, - see <seealso marker="write_test_chapter#info_function">Test - case info function</seealso> in the User's Guide.</p> + <p>For details about the test case information function, see section + <seealso marker="write_test_chapter#info_function">Test + Case Information Function</seealso> in the User's Guide.</p> </desc> </func> - - + <func> <name>Module:Testcase(Config) -> term() | {skip,Reason} | {comment,Comment} | {save_config,SaveConfig} | {skip_and_save,Reason,SaveConfig} | exit() </name> - <fsummary>A test case</fsummary> + <fsummary>A test case.</fsummary> <type> - <v> Config = SaveConfig = [{Key,Value}]</v> - <v> Key = atom()</v> - <v> Value = term()</v> - <v> Reason = term()</v> - <v> Comment = string()</v> + <v>Config = SaveConfig = [{Key,Value}]</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> + <v>Comment = string()</v> </type> - + <desc> - <p> MANDATORY </p> - - <p>This is the implementation of a test case. Here you must - call the functions you want to test, and do whatever you - need to check the result. If something fails, make sure the - function causes a runtime error, or call <seealso marker="ct#fail-1"><c>ct:fail/1/2</c></seealso> + <p>MANDATORY</p> + + <p>The implementation of a test case. Call the functions to test and + check the result. If something fails, ensure the + function causes a runtime error or call + <seealso marker="ct#fail-1"><c>ct:fail/1,2</c></seealso> (which also causes the test case process to terminate).</p> - - <p>Elements from the <c>Config</c> list can e.g. be read - with <c>proplists:get_value/2</c> (or the macro <c>?config</c> - defined in <c>ct.hrl</c>).</p> - <p>You can return <c>{skip,Reason}</c> if you decide not to - run the test case after all. <c>Reason</c> will then be - printed in 'Comment' field on the HTML result page.</p> - - <p>You can return <c>{comment,Comment}</c> if you wish to - print some information in the 'Comment' field on the HTML - result page.</p> - - <p>If the function returns anything else, the test case is - considered successful. (The return value always gets printed - in the test case log file).</p> + <p>Elements from the <c>Config</c> list can, for example, be read + with <c>proplists:get_value/2</c> in <c>STDLIB</c> + (or the macro <c>?config</c> defined in <c>ct.hrl</c>).</p> + + <p>If you decide not to run the test case after all, return + <c>{skip,Reason}</c>. <c>Reason</c> is then + printed in field <c>Comment</c> on the HTML result page.</p> + + <p>To print some information in field <c>Comment</c> on the HTML + result page, return <c>{comment,Comment}</c>.</p> - <p>For more information about test case implementation, please - see <seealso marker="write_test_chapter#test_cases">Test - cases</seealso> in the User's Guide.</p> + <p>If the function returns anything else, the test case is + considered successful. The return value always gets printed + in the test case log file.</p> - <p>For information on <c>save_config</c> and <c>skip_and_save</c>, please see - <seealso marker="dependencies_chapter#save_config">Dependencies between - Test Cases and Suites</seealso> in the User's Guide.</p> + <p>For details about test case implementation, see section + <seealso marker="write_test_chapter#test_cases">Test Cases</seealso> + in the User's Guide.</p> + + <p>For information on <c>save_config</c> and <c>skip_and_save</c>, + see section + <seealso marker="dependencies_chapter#save_config">Saving + Configuration Data</seealso> in the User's Guide.</p> </desc> </func> - + </funcs> </erlref> - diff --git a/lib/common_test/doc/src/config_file_chapter.xml b/lib/common_test/doc/src/config_file_chapter.xml index c7fd6e0b28..62ebfccb98 100644 --- a/lib/common_test/doc/src/config_file_chapter.xml +++ b/lib/common_test/doc/src/config_file_chapter.xml @@ -35,18 +35,18 @@ <section> <title>General</title> - <p>To avoid hard coding data values related to the test and/or SUT (System - Under Test) in the test suites, the data may instead be specified by means - of configuration files or strings that Common Test reads before + <p>To avoid hard-coding data values related to the test and/or System + Under Test (SUT) in the test suites, the data can instead be specified through + configuration files or strings that <c>Common Test</c> reads before the start of a test run. External configuration data makes it possible to - change test properties without having to modify the actual test suites - using the data. Examples of configuration data:</p> + change test properties without modifying the test suites + using the data. Examples of configuration data follows:</p> - <list> + <list type="bulleted"> <item>Addresses to the test plant or other instruments</item> <item>User login information</item> <item>Names of files needed by the test</item> - <item>Names of programs that should be executed during the test</item> + <item>Names of programs to be executed during the test</item> <item>Any other variable needed by the test</item> </list> @@ -57,154 +57,150 @@ <p>A configuration file can contain any number of elements of the type:</p> <pre> - {CfgVarName,Value}.</pre> + {CfgVarName,Value}.</pre> <p>where</p> <pre> - CfgVarName = atom() - Value = term() | [{CfgVarName,Value}]</pre> + CfgVarName = atom() + Value = term() | [{CfgVarName,Value}]</pre> </section> <section> - <title>Requiring and reading configuration data</title> + <title>Requiring and Reading Configuration Data</title> <marker id="require_config_data"></marker> <p>In a test suite, one must <em>require</em> that a configuration - variable (<c>CfgVarName</c> in the definition above) exists before - attempting to read the associated value in a test case or config function.</p> - - <p><c>require</c> is an assert statement that can be part of the <seealso - marker="write_test_chapter#suite">test suite info function</seealso> or - <seealso marker="write_test_chapter#info_function">test case info - function</seealso>. If the required variable is not available, the - test is skipped (unless a default value has been specified, see the - <seealso marker="write_test_chapter#info_function">test case info - function</seealso> chapter for details). There is also a function - <seealso marker="ct#require-1"><c>ct:require/1/2</c></seealso> which can be called from a test case - in order to check if a specific variable is available. The return + variable (<c>CfgVarName</c> in the previous definition) exists before + attempting to read the associated value in a test case or configuration function.</p> + + <p><c>require</c> is an assert statement, which can be part of the <seealso + marker="write_test_chapter#suite">Test Suite Information Function</seealso> or + <seealso marker="write_test_chapter#info_function">Test Case Information + Function</seealso>. If the required variable is unavailable, the + test is skipped (unless a default value has been specified, see section + <seealso marker="write_test_chapter#info_function">Test Case Information + Function</seealso> for details). Also, function + <seealso marker="ct#require-1"><c>ct:require/1/2</c></seealso> can be called + from a test case to check if a specific variable is available. The return value from this function must be checked explicitly and appropriate - action be taken depending on the result (e.g. to skip the test case - if the variable in question doesn't exist).</p> + action be taken depending on the result (for example, to skip the test case + if the variable in question does not exist).</p> - <p>A <c>require</c> statement in the test suite info- or test case - info-list should look like this: + <p>A <c>require</c> statement in the test suite information case or test case + information-list is to look like <c>{require,CfgVarName}</c> or <c>{require,AliasName,CfgVarName}</c>. The arguments <c>AliasName</c> and <c>CfgVarName</c> are the same as the - arguments to <seealso marker="ct#require-1"><c>ct:require/1/2</c></seealso> which are described in the - reference manual for <seealso marker="ct">ct</seealso>. + arguments to <seealso marker="ct#require-1"><c>ct:require/1,2</c></seealso>. <c>AliasName</c> becomes an alias for the configuration variable, and can be used as reference to the configuration data value. - The configuration variable may be associated with an - arbitrary number of alias names, but each name must be unique within - the same test suite. There are two main uses for alias names:</p> - <list> - <item>They may be introduced to identify connections (see below).</item> - <item>They may used to help adapt configuration data to a test suite + The configuration variable can be associated with any + number of alias names, but each name must be unique within + the same test suite. The two main uses for alias names follows:</p> + <list type="bulleted"> + <item>To identify connections (described later).</item> + <item>To help adapt configuration data to a test suite (or test case) and improve readability.</item> </list> - <p>To read the value of a config variable, use the function - <seealso marker="ct#get_config-1"><c>get_config/1/2/3</c></seealso> - which is also described in the reference - manual for <seealso marker="ct">ct</seealso>.</p> - <p>Example:</p> + <p>To read the value of a configuration variable, use function + <seealso marker="ct#get_config-1"><c>get_config/1,2,3</c></seealso>. + </p> + <p><em>Example:</em></p> <pre> - suite() -> - [{require, domain, 'CONN_SPEC_DNS_SUFFIX'}]. + suite() -> + [{require, domain, 'CONN_SPEC_DNS_SUFFIX'}]. - ... - - testcase(Config) -> - Domain = ct:get_config(domain), - ...</pre> + ... + + testcase(Config) -> + Domain = ct:get_config(domain), + ...</pre> </section> <section> - <title>Using configuration variables defined in multiple files</title> + <title>Using Configuration Variables Defined in Multiple Files</title> <p>If a configuration variable is defined in multiple files and you - want to access all possible values, you may use the <seealso marker="ct#get_config-3"><c>ct:get_config/3</c></seealso> - function and specify <c>all</c> in the options list. The values will then - be returned in a list and the order of the elements corresponds to the order - that the config files were specified at startup. Please see - the <seealso marker="ct">ct</seealso> reference manual for details.</p> + want to access all possible values, use function + <seealso marker="ct#get_config-3"><c>ct:get_config/3</c></seealso> + and specify <c>all</c> in the options list. The values are then + returned in a list and the order of the elements corresponds to the order + that the configuration files were specified at startup.</p> </section> <section> - <title>Encrypted configuration files</title> + <title>Encrypted Configuration Files</title> <marker id="encrypted_config_files"></marker> - <p>It is possible to encrypt configuration files containing sensitive data - if these files must be stored in open and shared directories.</p> - <p>Call <seealso marker="ct#encrypt_config_file-2"><c>ct:encrypt_config_file/2/3</c></seealso> to have Common Test encrypt a - specified file using the DES3 function in the OTP <c>crypto</c> application. - The encrypted file can then be used as a regular configuration file, - in combination with other encrypted files or normal text files. The key - for decrypting the configuration file must be provided when running the test, - however. This can be done by means of the <c>decrypt_key</c> or - <c>decrypt_file</c> flag/option, or a key file in a predefined location.</p> + <p>Configuration files containing sensitive data can be encrypted + if they must be stored in open and shared directories.</p> + <p>To have <c>Common Test</c> encrypt a + specified file using function <c>DES3</c> in application <c>Crypto</c>, + call <seealso marker="ct#encrypt_config_file-2"><c>ct:encrypt_config_file/2,3</c></seealso> + The encrypted file can then be used as a regular configuration file + in combination with other encrypted files or normal text files. However, the + key for decrypting the configuration file must be provided when running the test. + This can be done with flag/option <c>decrypt_key</c> or + <c>decrypt_file</c>, or a key file in a predefined location.</p> - <p>Common Test also provides decryption functions, - <seealso marker="ct#decrypt_config_file-2"><c>ct:decrypt_config_file/2/3</c></seealso>, for recreating the original text - files.</p> - - <p>Please see the <seealso marker="ct">ct</seealso> reference manual for - more information.</p> + <p><c>Common Test</c> also provides decryption functions, + <seealso marker="ct#decrypt_config_file-2"><c>ct:decrypt_config_file/2,3</c></seealso>, + for recreating the original text files.</p> </section> <section> - <title>Opening connections by using configuration data</title> - <p>There are two different methods for opening a connection - by means of the support functions in e.g. <seealso marker="ct_ssh"><c>ct_ssh</c></seealso>, <seealso marker="ct_ftp"><c>ct_ftp</c></seealso>, - and <seealso marker="ct_telnet"><c>ct_telnet</c></seealso>:</p> - <list> + <title>Opening Connections Using Configuration Data</title> + <p>Two different methods for opening a connection using the support functions + in, for example, <seealso marker="ct_ssh"><c>ct_ssh</c></seealso>, + <seealso marker="ct_ftp"><c>ct_ftp</c></seealso>, and + <seealso marker="ct_telnet"><c>ct_telnet</c></seealso> follows:</p> + <list type="bulleted"> <item>Using a configuration target name (an alias) as reference.</item> <item>Using the configuration variable as reference.</item> </list> <p>When a target name is used for referencing the configuration data - (that specifies the connection to be opened), the same name may be used + (that specifies the connection to be opened), the same name can be used as connection identity in all subsequent calls related to the connection - (also for closing it). It's only possible to have one open connection - per target name. If attempting to open a new connection using a name - already associated with an open connection, Common Test will - return the already existing handle so that the previously opened connection - will be used. This is a practical feature since it makes it possible to + (also for closing it). Only one open connection per target name + is possible. If you attempt to open a new connection using a name + already associated with an open connection, <c>Common Test</c> + returns the already existing handle so the previously opened connection + is used. This feature makes it possible to call the function for opening a particular connection whenever - useful. An action like this will not necessarily open any new - connections unless it's required (which could be the case if e.g. the - previous connection has been closed unexpectedly by the server). - Another benefit of using named connections is that it's not - necessary to pass handle references around in the suite for these - connections. + useful. An action like this does not necessarily open any new + connections unless it is required (which could be the case if, for example, + the previous connection has been closed unexpectedly by the server). + Using named connections also removes the need to pass handle references + around in the suite for these connections. </p> <p>When a configuration variable name is used as reference to the data specifying the connection, the handle returned as a result of opening the connection must be used in all subsequent calls (also for closing the connection). Repeated calls to the open function with the same - variable name as reference will result in multiple connections - being opened. This can be useful e.g. if a test case needs to open + variable name as reference results in multiple connections being opened. + This can be useful, for example, if a test case needs to open multiple connections to the same server on the target node (using the same configuration data for each connection). </p> </section> <section> - <title>User specific configuration data formats</title> + <title>User-Specific Configuration Data Formats</title> - <p>It is possible for the user to specify configuration data on a + <p>The user can specify configuration data on a different format than key-value tuples in a text file, as described - so far. The data can e.g. be read from arbitrary files, fetched from - the web over http, or requested from a user specific process. - To support this, Common Test provides a callback module plugin + so far. The data can, for example, be read from any files, fetched from + the web over HTTP, or requested from a user-specific process. + To support this, <c>Common Test</c> provides a callback module plugin mechanism to handle configuration data.</p> <section> - <title>Default callback modules for handling configuration data</title> - <p>The Common Test application includes default callback modules - for handling configuration data specified in standard config files - (see above) and in xml files:</p> - <list> + <title>Default Callback Modules for Handling Configuration Data</title> + <p><c>Common Test</c> includes default callback modules + for handling configuration data specified in standard configuration files + (described earlier) and in XML files as follows:</p> + <list type="bulleted"> <item> <c>ct_config_plain</c> - for reading configuration files with - key-value tuples (standard format). This handler will be used to + key-value tuples (standard format). This handler is used to parse configuration files if no user callback is specified. </item> <item> @@ -215,59 +211,59 @@ </section> <section> - <title>Using XML configuration files</title> - <p>This is an example of an XML configuration file:</p> - <pre><![CDATA[ -<config> + <title>Using XML Configuration Files</title> + <p>An example of an XML configuration file follows:</p> + <pre> + <![CDATA[ + <config> <ftp_host> <ftp>"targethost"</ftp> <username>"tester"</username> <password>"letmein"</password> </ftp_host> <lm_directory>"/test/loadmodules"</lm_directory> -</config>]]></pre> + </config>]]></pre> - <p>This configuration file, once read, will produce the same configuration + <p>Once read, this file produces the same configuration variables as the following text file:</p> <pre> -{ftp_host, [{ftp,"targethost"}, - {username,"tester"}, - {password,"letmein"}]}. + {ftp_host, [{ftp,"targethost"}, + {username,"tester"}, + {password,"letmein"}]}. -{lm_directory, "/test/loadmodules"}.</pre> + {lm_directory, "/test/loadmodules"}.</pre> </section> <section> - <title>How to implement a user specific handler</title> + <title>Implement a User-Specific Handler</title> - <p>The user specific handler can be written to handle special + <p>The user-specific handler can be written to handle special configuration file formats. The parameter can be either file - name(s) or configuration string(s) (the empty list is valid).</p> + names or configuration strings (the empty list is valid).</p> <p>The callback module implementing the handler is responsible for - checking correctness of configuration strings.</p> + checking the correctness of configuration strings.</p> - <p>To perform validation of the configuration strings, the callback module - should have the following function exported:</p> + <p>To validate the configuration strings, the callback module + is to have function <c>Callback:check_parameter/1</c> exported.</p> - <p><c>Callback:check_parameter/1</c></p> - <p>The input argument will be passed from Common Test, as defined in the test - specification or given as an option to <c>ct_run</c> or <c>ct:run_test</c>.</p> + <p>The input argument is passed from <c>Common Test</c>, as defined in the test + specification, or specified as an option to <c>ct_run</c> or <c>ct:run_test</c>.</p> - <p>The return value should be any of the following values indicating if given + <p>The return value is to be any of the following values, indicating if the specified configuration parameter is valid:</p> - <list> + <list type="bulleted"> <item> - <c>{ok, {file, FileName}}</c> - parameter is a file name and - the file exists, + <c>{ok, {file, FileName}}</c> - the parameter is a file name and + the file exists. </item> <item> - <c>{ok, {config, ConfigString}}</c> - parameter is a config string - and it is correct, + <c>{ok, {config, ConfigString}}</c> - the parameter is a configuration string + and it is correct. </item> <item> - <c>{error, {nofile, FileName}}</c> - there is no file with the given - name in the current directory, + <c>{error, {nofile, FileName}}</c> - there is no file with the specified + name in the current directory. </item> <item> <c>{error, {wrong_config, ConfigString}}</c> - the configuration string @@ -275,196 +271,196 @@ </item> </list> - <p>To perform reading of configuration data - initially before the tests - start, or as a result of data being reloaded during test execution - - the following function should be exported from the callback module:</p> - - <p><c>Callback:read_config/1</c></p> + <p>The function <c>Callback:read_config/1</c> is to be exported from the + callback module to read configuration data, initially before the tests + start, or as a result of data being reloaded during test execution. + The input argument is the same as for function <c>check_parameter/1</c>.</p> - <p>The input argument is the same as for the <c>check_parameter/1</c> function.</p> - <p>The return value should be either:</p> + <p>The return value is to be either of the following:</p> - <list> + <list type="bulleted"> <item> - <c>{ok, Config}</c> - if the configuration variables are read successfully, + <c>{ok, Config}</c> - if the configuration variables are read successfully. </item> <item> <c>{error, {Error, ErrorDetails}}</c> - if the callback module fails to - proceed with the given configuration parameters. + proceed with the specified configuration parameters. </item> </list> <p><c>Config</c> is the proper Erlang key-value list, with possible - key-value sublists as values, like for the configuration file - example above:</p> + key-value sublists as values, like the earlier configuration file + example:</p> <pre> - [{ftp_host, [{ftp, "targethost"}, {username, "tester"}, {password, "letmein"}]}, - {lm_directory, "/test/loadmodules"}]</pre> + [{ftp_host, [{ftp, "targethost"}, {username, "tester"}, {password, "letmein"}]}, + {lm_directory, "/test/loadmodules"}]</pre> </section> </section> <section> - <title>Examples of configuration data handling</title> + <title>Examples of Configuration Data Handling</title> - <p>A config file for using the FTP client to access files on a remote - host could look like this:</p> + <p>A configuration file for using the FTP client to access files on a remote + host can look as follows:</p> <pre> - {ftp_host, [{ftp,"targethost"}, - {username,"tester"}, - {password,"letmein"}]}. + {ftp_host, [{ftp,"targethost"}, + {username,"tester"}, + {password,"letmein"}]}. - {lm_directory, "/test/loadmodules"}.</pre> + {lm_directory, "/test/loadmodules"}.</pre> - <p>The XML version shown in the chapter above can also be used, but it should be + <p>The XML version shown earlier can also be used, but it is to be explicitly specified that the <c>ct_config_xml</c> callback module is to be - used by Common Test.</p> + used by <c>Common Test</c>.</p> - <p>Example of how to assert that the configuration data is available and - use it for an FTP session:</p> + <p>The following is an example of how to assert that the configuration data is available + and can be used for an FTP session:</p> <pre> - init_per_testcase(ftptest, Config) -> - {ok,_} = ct_ftp:open(ftp), - Config. - - end_per_testcase(ftptest, _Config) -> - ct_ftp:close(ftp). - - ftptest() -> - [{require,ftp,ftp_host}, - {require,lm_directory}]. - - ftptest(Config) -> - Remote = filename:join(ct:get_config(lm_directory), "loadmodX"), - Local = filename:join(?config(priv_dir,Config), "loadmodule"), - ok = ct_ftp:recv(ftp, Remote, Local), - ...</pre> + init_per_testcase(ftptest, Config) -> + {ok,_} = ct_ftp:open(ftp), + Config. + + end_per_testcase(ftptest, _Config) -> + ct_ftp:close(ftp). + + ftptest() -> + [{require,ftp,ftp_host}, + {require,lm_directory}]. + + ftptest(Config) -> + Remote = filename:join(ct:get_config(lm_directory), "loadmodX"), + Local = filename:join(?config(priv_dir,Config), "loadmodule"), + ok = ct_ftp:recv(ftp, Remote, Local), + ...</pre> - <p>An example of how the above functions could be rewritten - if necessary to open multiple connections to the FTP server:</p> + <p>The following is an example of how the functions in the previous example + can be rewritten if it is necessary to open multiple connections to the + FTP server:</p> <pre> - init_per_testcase(ftptest, Config) -> - {ok,Handle1} = ct_ftp:open(ftp_host), - {ok,Handle2} = ct_ftp:open(ftp_host), - [{ftp_handles,[Handle1,Handle2]} | Config]. - - end_per_testcase(ftptest, Config) -> - lists:foreach(fun(Handle) -> ct_ftp:close(Handle) end, - ?config(ftp_handles,Config)). - - ftptest() -> - [{require,ftp_host}, - {require,lm_directory}]. - - ftptest(Config) -> - Remote = filename:join(ct:get_config(lm_directory), "loadmodX"), - Local = filename:join(?config(priv_dir,Config), "loadmodule"), - [Handle | MoreHandles] = ?config(ftp_handles,Config), - ok = ct_ftp:recv(Handle, Remote, Local), - ...</pre> + init_per_testcase(ftptest, Config) -> + {ok,Handle1} = ct_ftp:open(ftp_host), + {ok,Handle2} = ct_ftp:open(ftp_host), + [{ftp_handles,[Handle1,Handle2]} | Config]. + + end_per_testcase(ftptest, Config) -> + lists:foreach(fun(Handle) -> ct_ftp:close(Handle) end, + ?config(ftp_handles,Config)). + + ftptest() -> + [{require,ftp_host}, + {require,lm_directory}]. + + ftptest(Config) -> + Remote = filename:join(ct:get_config(lm_directory), "loadmodX"), + Local = filename:join(?config(priv_dir,Config), "loadmodule"), + [Handle | MoreHandles] = ?config(ftp_handles,Config), + ok = ct_ftp:recv(Handle, Remote, Local), + ...</pre> </section> <section> - <title>Example of user specific configuration handler</title> - <p>A simple configuration handling driver which will ask an external server for - configuration data can be implemented this way:</p> + <title>Example of User-Specific Configuration Handler</title> + <p>A simple configuration handling driver, asking an external server for + configuration data, can be implemented as follows:</p> <pre> --module(config_driver). --export([read_config/1, check_parameter/1]). - -read_config(ServerName)-> - ServerModule = list_to_atom(ServerName), - ServerModule:start(), - ServerModule:get_config(). - -check_parameter(ServerName)-> - ServerModule = list_to_atom(ServerName), - case code:is_loaded(ServerModule) of - {file, _}-> - {ok, {config, ServerName}}; - false-> - case code:load_file(ServerModule) of - {module, ServerModule}-> - {ok, {config, ServerName}}; - {error, nofile}-> - {error, {wrong_config, "File not found: " ++ ServerName ++ ".beam"}} - end - end.</pre> - - <p>The configuration string for this driver may be "config_server", if the - config_server.erl module below is compiled and exists in the code path + -module(config_driver). + -export([read_config/1, check_parameter/1]). + + read_config(ServerName)-> + ServerModule = list_to_atom(ServerName), + ServerModule:start(), + ServerModule:get_config(). + + check_parameter(ServerName)-> + ServerModule = list_to_atom(ServerName), + case code:is_loaded(ServerModule) of + {file, _}-> + {ok, {config, ServerName}}; + false-> + case code:load_file(ServerModule) of + {module, ServerModule}-> + {ok, {config, ServerName}}; + {error, nofile}-> + {error, {wrong_config, "File not found: " ++ ServerName ++ ".beam"}} + end + end.</pre> + + <p>The configuration string for this driver can be <c>config_server</c>, if the + <c>config_server.erl</c> module that follows is compiled and exists in the code path during test execution:</p> <pre> --module(config_server). --export([start/0, stop/0, init/1, get_config/0, loop/0]). - --define(REGISTERED_NAME, ct_test_config_server). - -start()-> - case whereis(?REGISTERED_NAME) of - undefined-> - spawn(?MODULE, init, [?REGISTERED_NAME]), - wait(); - _Pid-> - ok - end, - ?REGISTERED_NAME. - -init(Name)-> - register(Name, self()), - loop(). - -get_config()-> - call(self(), get_config). - -stop()-> - call(self(), stop). - -call(Client, Request)-> - case whereis(?REGISTERED_NAME) of - undefined-> - {error, {not_started, Request}}; - Pid-> - Pid ! {Client, Request}, - receive - Reply-> - {ok, Reply} - after 4000-> - {error, {timeout, Request}} - end - end. - -loop()-> - receive - {Pid, stop}-> - Pid ! ok; - {Pid, get_config}-> - {D,T} = erlang:localtime(), - Pid ! - [{localtime, [{date, D}, {time, T}]}, - {node, erlang:node()}, - {now, erlang:now()}, - {config_server_pid, self()}, - {config_server_vsn, ?vsn}], - ?MODULE:loop() - end. - -wait()-> - case whereis(?REGISTERED_NAME) of - undefined-> - wait(); - _Pid-> - ok - end.</pre> - - <p>In this example, the handler also provides the ability to dynamically reload - configuration variables. If <c>ct:reload_config(localtime)</c> is called from + -module(config_server). + -export([start/0, stop/0, init/1, get_config/0, loop/0]). + + -define(REGISTERED_NAME, ct_test_config_server). + + start()-> + case whereis(?REGISTERED_NAME) of + undefined-> + spawn(?MODULE, init, [?REGISTERED_NAME]), + wait(); + _Pid-> + ok + end, + ?REGISTERED_NAME. + + init(Name)-> + register(Name, self()), + loop(). + + get_config()-> + call(self(), get_config). + + stop()-> + call(self(), stop). + + call(Client, Request)-> + case whereis(?REGISTERED_NAME) of + undefined-> + {error, {not_started, Request}}; + Pid-> + Pid ! {Client, Request}, + receive + Reply-> + {ok, Reply} + after 4000-> + {error, {timeout, Request}} + end + end. + + loop()-> + receive + {Pid, stop}-> + Pid ! ok; + {Pid, get_config}-> + {D,T} = erlang:localtime(), + Pid ! + [{localtime, [{date, D}, {time, T}]}, + {node, erlang:node()}, + {now, erlang:now()}, + {config_server_pid, self()}, + {config_server_vsn, ?vsn}], + ?MODULE:loop() + end. + + wait()-> + case whereis(?REGISTERED_NAME) of + undefined-> + wait(); + _Pid-> + ok + end.</pre> + + <p>Here, the handler also provides for dynamically reloading of + configuration variables. If + <seealso marker="ct#reload_config-1"><c>ct:reload_config(localtime)</c></seealso> is called from the test case function, all variables loaded with <c>config_driver:read_config/1</c> - will be updated with their latest values, and the new value for variable - <c>localtime</c> will be returned.</p> + are updated with their latest values, and the new value for variable + <c>localtime</c> is returned.</p> </section> </chapter> diff --git a/lib/common_test/doc/src/cover_chapter.xml b/lib/common_test/doc/src/cover_chapter.xml index f164fff0ad..094aa7d80c 100644 --- a/lib/common_test/doc/src/cover_chapter.xml +++ b/lib/common_test/doc/src/cover_chapter.xml @@ -33,256 +33,251 @@ <section> <marker id="cover"></marker> <title>General</title> - <p>Although Common Test was created primarly for the purpose of - black box testing, nothing prevents it from working perfectly as - a white box testing tool as well. This is especially true when + <p>Although <c>Common Test</c> was created primarily for + black-box testing, nothing prevents it from working perfectly as + a white-box testing tool as well. This is especially true when the application to test is written in Erlang. Then the test - ports are easily realized by means of Erlang function calls.</p> + ports are easily realized with Erlang function calls.</p> - <p>When white box testing an Erlang application, it is useful to - be able to measure the code coverage of the test. Common Test + <p>When white-box testing an Erlang application, it is useful to + be able to measure the code coverage of the test. <c>Common Test</c> provides simple access to the OTP Cover tool for this - purpose. Common Test handles all necessary communication with - the Cover tool (starting, compiling, analysing, etc). All the - Common Test user needs to do is to specify the extent of the + purpose. <c>Common Test</c> handles all necessary communication with + the Cover tool (starting, compiling, analysing, and so on). + The <c>Common Test</c> user only needs to specify the extent of the code coverage analysis.</p> </section> <section> - <title>Usage</title> - <p>To specify what modules should be included - in the code coverage test, you provide a cover specification - file. Using this file you can point out specific modules or - specify directories that contain modules which should all be - included in the analysis. You can also, in the same fashion, - specify modules that should be excluded from the analysis.</p> + <title>Use</title> + <p>To specify the modules to be included in the code coverage test, + provide a cover specification file. With this file you can point + out specific modules or specify directories containing modules to be + included in the analysis. You can also specify modules to be excluded + from the analysis.</p> <p>If you are testing a distributed Erlang application, it is likely that code you want included in the code coverage analysis - gets executed on an Erlang node other than the one Common Test - is running on. If this is the case you need to specify these - other nodes in the cover specification file or add them - dynamically to the code coverage set of nodes. See the - <c>ct_cover</c> page in the reference manual for details on the - latter.</p> + gets executed on another Erlang node than the one <c>Common Test</c> + is running on. If so, you must specify these other nodes in the + cover specification file or add them dynamically to the code coverage + set of nodes. For details on the latter, see module + <seealso marker="ct_cover"><c>ct_cover</c></seealso>.</p> <p>In the cover specification file you can also specify your required level of the code coverage analysis; <c>details</c> or <c>overview</c>. In detailed mode, you get a coverage overview - page, showing you per module and total coverage percentages, as - well as one HTML file printed for each module included in the - analysis that shows exactly what parts of the code have been + page, showing per module and total coverage percentages. + You also get an HTML file printed for each module included in the + analysis showing exactly what parts of the code have been executed during the test. In overview mode, only the code - coverage overview page gets printed.</p> + coverage overview page is printed.</p> <p>You can choose to export and import code coverage data between tests. If you specify the name of an export file in the cover - specification file, Common Test will export collected coverage - data to this file at the end of the test. You may similarly - specify that previously exported data should be imported and - included in the analysis for a test (you can specify multiple - import files). This way it is possible to analyse total code coverage - without necessarily running all tests at once.</p> - - <p>To activate the code coverage support, you simply specify the - name of the cover specification file as you start Common Test. - This you do either by using the <c>-cover</c> flag with <c>ct_run</c>. - Example:</p> - - <p><c>$ ct_run -dir $TESTOBJS/db -cover $TESTOBJS/db/config/db.coverspec</c></p> + specification file, <c>Common Test</c> exports collected coverage + data to this file at the end of the test. You can similarly + specify previously exported data to be imported and + included in the analysis for a test (multiple import files can be specified). + This way, the total code coverage can be analyzed without necessarily + running all tests at once.</p> + + <p>To activate the code coverage support, specify the name of the cover + specification file as you start <c>Common Test</c>. + Do this by using flag <c>-cover</c> with + <seealso marker="ct_run"><c>ct_run</c></seealso>, + for example:</p> + <pre> + $ ct_run -dir $TESTOBJS/db -cover $TESTOBJS/db/config/db.coverspec</pre> - <p>You may also pass the cover specification file name in a - call to <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>, by adding a <c>{cover,CoverSpec}</c> - tuple to the <c>Opts</c> argument. Also, you can of course - enable code coverage in your test specifications (read - more in the chapter about - <seealso marker="run_test_chapter#test_specifications">using test - specifications</seealso>).</p> + <p>You can also pass the cover specification file name in a + call to <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>, + by adding a <c>{cover,CoverSpec}</c> tuple to argument <c>Opts</c>.</p> + <p>You can also enable code coverage in your test specifications (see section + <seealso marker="run_test_chapter#test_specifications">Test Specifications</seealso> + in section Running Tests and Analyzing Results).</p> </section> <section> <marker id="cover_stop"></marker> - <title>Stopping the cover tool when tests are completed</title> - <p>By default the Cover tool is automatically stopped when the - tests are completed. This causes the original (non cover - compiled) modules to be loaded back in to the test node. If a - process at this point is still running old code of any of the + <title>Stopping the Cover Tool When Tests Are Completed</title> + <p>By default, the Cover tool is automatically stopped when the + tests are completed. This causes the original (non-cover + compiled) modules to be loaded back into the test node. If a + process at this point still runs old code of any of the modules that are cover compiled, meaning that it has not done any fully qualified function call after the cover compilation, - the process will now be killed. To avoid this it is possible to - set the value of the <c>cover_stop</c> option to - <c>false</c>. This means that the modules will stay cover - compiled, and it is therefore only recommended if the erlang - node(s) under test is terminated after the test is completed - or if cover can be manually stopped.</p> - - <p>The option can be set by using the <c>-cover_stop</c> flag with - <c>ct_run</c>, by adding <c>{cover_stop,true|false}</c> to the - Opts argument to <seealso - marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>, or by adding - a <c>cover_stop</c> term in your test specification (see chapter - about <seealso - marker="run_test_chapter#test_specifications">test - specifications</seealso>).</p> + the process is killed. To avoid this, set the value of option + <c>cover_stop</c> to <c>false</c>. This means that the + modules stay cover compiled. Therefore, this is only recommended + if the Erlang nodes under test are terminated after the test is + completed, or if cover can be manually stopped.</p> + + <p>The option can be set by using flag <c>-cover_stop</c> with + <c>ct_run</c>, by adding <c>{cover_stop,true|false}</c> to argument + <c>Opts</c> to + <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>, + or by adding a <c>cover_stop</c> term in the test specification (see section + <seealso marker="run_test_chapter#test_specifications">Test Specifications</seealso> + in section Running Tests and Analyzing Results).</p> </section> <section> - <title>The cover specification file</title> - <p>These are the terms allowed in a cover specification file:</p> + <title>The Cover Specification File</title> + <p>The following terms are allowed in a cover specification file:</p> <pre> - %% List of Nodes on which cover will be active during test. - %% Nodes = [atom()] - {nodes, Nodes}. - - %% Files with previously exported cover data to include in analysis. - %% CoverDataFiles = [string()] - {import, CoverDataFiles}. - - %% Cover data file to export from this session. - %% CoverDataFile = string() - {export, CoverDataFile}. - - %% Cover analysis level. - %% Level = details | overview - {level, Level}. - - %% Directories to include in cover. - %% Dirs = [string()] - {incl_dirs, Dirs}. - - %% Directories, including subdirectories, to include. - {incl_dirs_r, Dirs}. - - %% Specific modules to include in cover. - %% Mods = [atom()] - {incl_mods, Mods}. - - %% Directories to exclude in cover. - {excl_dirs, Dirs}. - - %% Directories, including subdirectories, to exclude. - {excl_dirs_r, Dirs}. - - %% Specific modules to exclude in cover. - {excl_mods, Mods}. - - %% Cross cover compilation - %% Tag = atom(), an identifier for a test run - %% Mod = [atom()], modules to compile for accumulated analysis - {cross,[{Tag,Mods}]}. - </pre> - - <p>The <c>incl_dirs_r</c> and <c>excl_dirs_r</c> terms tell Common - Test to search the given directories recursively and include - or exclude any module found during the search. The - <c>incl_dirs</c> and <c>excl_dirs</c> terms result in a - non-recursive search for modules (i.e. only modules found in - the given directories are included or excluded).</p> - <p><em>Note:</em> Directories containing Erlang modules that are - to be included in a code coverage test must exist in the code - server path, or the cover tool will fail to recompile the modules. - (It is not sufficient to specify these directories in the cover - specification file for Common Test).</p> + %% List of Nodes on which cover will be active during test. + %% Nodes = [atom()] + {nodes, Nodes}. + + %% Files with previously exported cover data to include in analysis. + %% CoverDataFiles = [string()] + {import, CoverDataFiles}. + + %% Cover data file to export from this session. + %% CoverDataFile = string() + {export, CoverDataFile}. + + %% Cover analysis level. + %% Level = details | overview + {level, Level}. + + %% Directories to include in cover. + %% Dirs = [string()] + {incl_dirs, Dirs}. + + %% Directories, including subdirectories, to include. + {incl_dirs_r, Dirs}. + + %% Specific modules to include in cover. + %% Mods = [atom()] + {incl_mods, Mods}. + + %% Directories to exclude in cover. + {excl_dirs, Dirs}. + + %% Directories, including subdirectories, to exclude. + {excl_dirs_r, Dirs}. + + %% Specific modules to exclude in cover. + {excl_mods, Mods}. + + %% Cross cover compilation + %% Tag = atom(), an identifier for a test run + %% Mod = [atom()], modules to compile for accumulated analysis + {cross,[{Tag,Mods}]}.</pre> + + <p>The terms <c>incl_dirs_r</c> and <c>excl_dirs_r</c> tell <c>Common + Test</c> to search the specified directories recursively and include + or exclude any module found during the search. The terms + <c>incl_dirs</c> and <c>excl_dirs</c> result in a + non-recursive search for modules (that is, only modules found in + the specified directories are included or excluded).</p> + <note><p>Directories containing Erlang modules to be included in a code + coverage test must exist in the code server path. Otherwise, + the Cover tool fails to recompile the modules. It is not sufficient to + specify these directories in the cover specification file for + <c>Common Test</c>.</p></note> </section> <section> <marker id="cross_cover"/> - <title>Cross cover analysis</title> + <title>Cross Cover Analysis</title> <p>The cross cover mechanism allows cover analysis of modules - across multiple tests. It is useful if some code, e.g. a library - module, is used by many different tests and the accumulated cover - result is desirable.</p> + across multiple tests. It is useful if some code, for example, a + library module, is used by many different tests and the accumulated + cover result is desirable.</p> - <p>This can of course also be achieved in a more customized way by - using the <c>export</c> parameter in the cover specification and - analysing the result off line, but the cross cover mechanism is a - build in solution which also provides the logging.</p> + <p>This can also be achieved in a more customized way by + using parameter <c>export</c> in the cover specification and + analysing the result off line. However, the cross cover mechanism is a + built-in solution that also provides logging.</p> - <p>The mechanism is easiest explained via an example:</p> + <p>The mechanism is easiest explained by an example:</p> - <p>Let's say that there are two systems, <c>s1</c> and <c>s2</c>, - which are tested in separate test runs. System <c>s1</c> contains - a library module <c>m1</c> which is tested by the <c>s1</c> test - run and is included in <c>s1</c>'s cover specification:</p> + <p>Assume that there are two systems, <c>s1</c> and <c>s2</c>, + that are tested in separate test runs. System <c>s1</c> contains + a library module <c>m1</c> tested by test run <c>s1</c> and + is included in the cover specification of <c>s1</c> as follows:</p> <code type="none"> -s1.cover: - {incl_mods,[m1]}.</code> + s1.cover: + {incl_mods,[m1]}.</code> <p>When analysing code coverage, the result for <c>m1</c> can be seen in the cover log in the <c>s1</c> test result.</p> - <p>Now, let's imagine that since <c>m1</c> is a library module, it - is also used quite a bit by system <c>s2</c>. The <c>s2</c> test - run does not specifically test <c>m1</c>, but it might still be - interesting to see which parts of <c>m1</c> is actually covered by - the <c>s2</c> tests. To do this, <c>m1</c> could be included also - in <c>s2</c>'s cover specification:</p> + <p>Now, imagine that as <c>m1</c> is a library module, it + is also often used by system <c>s2</c>. Test run <c>s2</c> + does not specifically test <c>m1</c>, but it can still be + interesting to see which parts of <c>m1</c> that are covered + by the <c>s2</c> tests. To do this, <c>m1</c> can be included also + in the cover specification of <c>s2</c> as follows:</p> <code type="none"> -s2.cover: - {incl_mods,[m1]}.</code> + s2.cover: + {incl_mods,[m1]}.</code> - <p>This would give an entry for <c>m1</c> also in the cover log - for the <c>s2</c> test run. The problem is that this would only - reflect the coverage by <c>s2</c> tests, not the accumulated - result over <c>s1</c> and <c>s2</c>. And this is where the cross + <p>This gives an entry for <c>m1</c> also in the cover log + for test run <c>s2</c>. The problem is that this only + reflects the coverage by <c>s2</c> tests, not the accumulated + result over <c>s1</c> and <c>s2</c>. This is where the cross cover mechanism comes in handy.</p> - <p>If instead the cover specification for <c>s2</c> was like - this:</p> + <p>If instead the cover specification for <c>s2</c> is like + the following:</p> <code type="none"> -s2.cover: - {cross,[{s1,[m1]}]}.</code> + s2.cover: + {cross,[{s1,[m1]}]}.</code> - <p>then <c>m1</c> would be cover compiled in the <c>s2</c> test - run, but not shown in the coverage log. Instead, if - <c>ct_cover:cross_cover_analyse/2</c> is called after both - <c>s1</c> and <c>s2</c> test runs are completed, the accumulated - result for <c>m1</c> would be available in the cross cover log for - the <c>s1</c> test run.</p> + <p>Then <c>m1</c> is cover compiled in test run <c>s2</c>, + but not shown in the coverage log. Instead, if + <seealso marker="ct_cover#cross_cover_analyse-2"><c>ct_cover:cross_cover_analyse/2</c></seealso> + is called after both <c>s1</c> and <c>s2</c> test runs are completed, + the accumulated result for <c>m1</c> is available in the cross cover + log for test run <c>s1</c>.</p> - <p>The call to the analyse function must be like this:</p> + <p>The call to the analyze function must be as follows:</p> <code type="none"> -ct_cover:cross_cover_analyse(Level, [{s1,S1LogDir},{s2,S2LogDir}]).</code> + ct_cover:cross_cover_analyse(Level, [{s1,S1LogDir},{s2,S2LogDir}]).</code> - <p>where <c>S1LogDir</c> and <c>S2LogDir</c> are the directories + <p>Here, <c>S1LogDir</c> and <c>S2LogDir</c> are the directories named <c><TestName>.logs</c> for each test respectively.</p> - <p>Note the tags <c>s1</c> and <c>s2</c> which are used in the + <p>Notice the tags <c>s1</c> and <c>s2</c>, which are used in the cover specification file and in the call to - <c>ct_cover:cross_cover_analyse/2</c>. The point of these are only + <c>ct_cover:cross_cover_analyse/2</c>. The purpose of these is only to map the modules specified in the cover specification to the log - directory specified in the call to the analyse function. The name - of the tag has no meaning beyond this.</p> + directory specified in the call to the analyze function. The tag name + has no meaning beyond this.</p> </section> <section> <title>Logging</title> <p>To view the result of a code coverage test, click the button - labled "COVER LOG" in the top level index page for the test run.</p> + labeled "COVER LOG" in the top-level index page for the test run.</p> - <p>Prior to Erlang/OTP 17.1, if your test run consisted of + <p>Before Erlang/OTP 17.1, if your test run consisted of multiple tests, cover would be started and stopped for each test - within the test run. Separate logs would be available via the + within the test run. Separate logs would be available through the "Coverage log" link on the test suite result pages. These links are still available, but now they all point to the same page as - the button on the top level index page. The log contains the - accumulated results for the complete test run. See the release - notes for more information about this change.</p> + the button on the top-level index page. The log contains the + accumulated results for the complete test run. For details about + this change, see the release notes.</p> - <p>The buttonc takes you to the code coverage overview page. If you - have successfully performed a detailed coverage analysis, you - find links to each individual module coverage page here.</p> + <p>The button takes you to the code coverage overview page. If you + have successfully performed a detailed coverage analysis, + links to each individual module coverage page are found here.</p> - <p>If cross cover analysis has been performed, and there are - accumulated coverage results for the current test, then the - - "Coverdata collected over all tests" link will take you to these + <p>If cross cover analysis is performed, and there are + accumulated coverage results for the current test, the link + "Coverdata collected over all tests" takes you to these results.</p> </section> diff --git a/lib/common_test/doc/src/ct.xml b/lib/common_test/doc/src/ct.xml new file mode 100644 index 0000000000..a87be21d73 --- /dev/null +++ b/lib/common_test/doc/src/ct.xml @@ -0,0 +1,1412 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>ct</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>ct.xml</file> + </header> + <module>ct</module> + <modulesummary>Main user interface for the Common Test framework.</modulesummary> + + <description> + + <p>Main user interface for the <c>Common Test</c> framework.</p> + + <p>This module implements the command-line interface for running + tests and basic functions for <c>Common Test</c> case issues, such as + configuration and logging.</p> + + <p><em>Test Suite Support Macros</em></p> + + <p>The <c>config</c> macro is defined in <c>ct.hrl</c>. This macro is + to be used to retrieve information from the <c>Config</c> variable sent + to all test cases. It is used with two arguments; the first is the name + of the configuration variable to retrieve, the second is the + <c>Config</c> variable supplied to the test case.</p> + + <p>Possible configuration variables include:</p> + + <list type="bulleted"> + <item><p><c>data_dir</c> - Data file directory</p></item> + <item><p><c>priv_dir</c> - Scratch file directory</p></item> + <item><p>Whatever added by + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite/1</c></seealso> + or + <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase/2</c></seealso> + in the test suite.</p></item> + </list> + + </description> + + <section> + <title>Data Types</title> + <marker id="types"/> + <taglist> + + <tag><c>handle() = pid()</c></tag> + <item><marker id="type-handle"/> + <p>The identity (handle) of a connection.</p></item> + + <tag><c>target_name() = atom()</c></tag> + <item><marker id="type-target_name"/> + <p>A name and association to configuration data introduced + through a require statement, or a call to + <seealso marker="#require-2"><c>ct:require/2</c></seealso>, + for example, + <c>ct:require(mynodename,{node,[telnet]})</c>.</p></item> + + </taglist> + </section> + + <funcs> + <func> + <name>abort_current_testcase(Reason) -> ok | {error, ErrorReason}</name> + <fsummary>Aborts the currently executing test case.</fsummary> + <type> + <v>Reason = term()</v> + <v>ErrorReason = no_testcase_running | parallel_group</v> + </type> + <desc><marker id="abort_current_testcase-1"/> + <p>Aborts the currently executing test case. The user must know with + certainty which test case is currently executing. The function is + therefore only safe to call from a function that has been called + (or synchronously invoked) by the test case.</p> + + <p><c>Reason</c>, the reason for aborting the test case, is printed + in the test case log.</p> + </desc> + </func> + + <func> + <name>add_config(Callback, Config) -> ok | {error, Reason}</name> + <fsummary>Loads configuration variables using the specified callback + module and configuration string.</fsummary> + <type> + <v>Callback = atom()</v> + <v>Config = string()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="add_config-2"/> + <p>Loads configuration variables using the specified callback module and + configuration string. The callback module is to be either loaded or + present in the code part. Loaded configuration variables can later + be removed using function + <seealso marker="#remove_config-2"><c>ct:remove_config/2</c></seealso>. + </p> + </desc> + </func> + + <func> + <name>break(Comment) -> ok | {error, Reason}</name> + <fsummary>Cancels any active timetrap and pause the execution of the + current test case until the user calls function continue/0.</fsummary> + <type> + <v>Comment = string()</v> + <v>Reason = {multiple_cases_running, TestCases} | 'enable break with release_shell option'</v> + <v>TestCases = [atom()]</v> + </type> + <desc><marker id="break-1"/> + <p>Cancels any active timetrap and pauses the execution of the + current test case until the user calls function <c>continue/0</c>. + The user can then interact with the Erlang node running the tests, + for example, for debugging purposes or for manually executing a + part of the test case. If a parallel group is executing, + <seealso marker="#break-2"><c>ct:break/2</c></seealso> is to be + called instead.</p> + <p>A cancelled timetrap is not automatically reactivated after the + break, but must be started exlicitly with + <seealso marker="#timetrap-1"><c>ct:timetrap/1</c></seealso>.</p> + <p>In order for the break/continue functionality to work, <c>Common + Test</c> must release the shell process controlling <c>stdin</c>. + This is done by setting start option <c>release_shell</c> + to <c>true</c>. For details, see section + <seealso marker="run_test_chapter#erlang_shell_or_program">Running + Tests from the Erlang Shell or from an Erlang Program</seealso> + in the User's Guide.</p> + </desc> + </func> + + <func> + <name>break(TestCase, Comment) -> ok | {error, Reason}</name> + <fsummary>Works the same way as break/1, only argument TestCase makes it + possible to pause a test case executing in a parallel group.</fsummary> + <type> + <v>TestCase = atom()</v> + <v>Comment = string()</v> + <v>Reason = 'test case not running' | 'enable break with release_shell option'</v> + </type> + <desc><marker id="break-2"/> + <p>Works the same way as + <seealso marker="#break-1"><c>ct:break/1</c></seealso>, only + argument <c>TestCase</c> makes it possible to pause a test case + executing in a parallel group. Function + <seealso marker="#continue-1"><c>ct:continue/1</c></seealso> is to + be used to resume execution of <c>TestCase</c>.</p> + + <p>For details, see + <seealso marker="#break/1"><c>ct:break/1</c></seealso>.</p> + </desc> + </func> + + <func> + <name>capture_get() -> ListOfStrings</name> + <fsummary>Equivalent to capture_get([default]).</fsummary> + <type> + <v>ListOfStrings = [string()]</v> + </type> + <desc><marker id="capture_get-0"/> + <p>Equivalent to + <seealso marker="#capture_get-1">ct:capture_get([default])</seealso>.</p> + </desc> + </func> + + <func> + <name>capture_get(ExclCategories) -> ListOfStrings</name> + <fsummary>Returns and purges the list of text strings buffered during + the latest session of capturing printouts to stdout.</fsummary> + <type> + <v>ExclCategories = [atom()]</v> + <v>ListOfStrings = [string()]</v> + </type> + <desc><marker id="capture_get-1"/> + <p>Returns and purges the list of text strings buffered during the + latest session of capturing printouts to <c>stdout</c>. Log + categories that are to be ignored in <c>ListOfStrings</c> can be + specified with <c>ExclCategories</c>. + If <c>ExclCategories = []</c>, no filtering takes place.</p> + + <p>See also + <seealso marker="#capture_start-0"><c>ct:capture_start/0</c></seealso>, + <seealso marker="#capture_stop-0"><c>ct:capture_stop/0</c></seealso>, + <seealso marker="#log-3"><c>ct:log/3</c></seealso>.</p> + </desc> + </func> + + <func> + <name>capture_start() -> ok</name> + <fsummary>Starts capturing all text strings printed to stdout + during execution of the test case.</fsummary> + <desc><marker id="capture_start-0"/> + <p>Starts capturing all text strings printed to <c>stdout</c> + during execution of the test case.</p> + + <p>See also + <seealso marker="#capture_get-1"><c>ct:capture_get/1</c></seealso>, + <seealso marker="#capture_stop-0"><c>ct:capture_stop/0</c></seealso>.</p> + </desc> + </func> + + <func> + <name>capture_stop() -> ok</name> + <fsummary>Stops capturing text strings (a session started with + capture_start/0).</fsummary> + <desc><marker id="capture_stop-0"/> + <p>Stops capturing text strings (a session started with + <c>capture_start/0</c>).</p> + + <p>See also + <seealso marker="#capture_get-1"><c>ct:capture_get/1</c></seealso>, + <seealso marker="#capture_start-0"><c>ct:capture_start/0</c></seealso>.</p> + </desc> + </func> + + <func> + <name>comment(Comment) -> ok</name> + <fsummary>Prints the specified Comment in the comment field in the + table on the test suite result page.</fsummary> + <type> + <v>Comment = term()</v> + </type> + <desc><marker id="comment-1"/> + <p>Prints the specified <c>Comment</c> in the comment field in the + table on the test suite result page.</p> + + <p>If called several times, only the last comment is printed. The + test case return value <c>{comment,Comment}</c> overwrites the + string set by this function.</p> + </desc> + </func> + + <func> + <name>comment(Format, Args) -> ok</name> + <fsummary>Prints the formatted string in the comment field in the + table on the test suite result page.</fsummary> + <type> + <v>Format = string()</v> + <v>Args = list()</v> + </type> + <desc><marker id="comment-2"/> + <p>Prints the formatted string in the comment field in the table + on the test suite result page.</p> + + <p>Arguments <c>Format</c> and <c>Args</c> are used in a call to + <c>io_lib:format/2</c> to create the comment string. The behavior + of <c>comment/2</c> is otherwise the same as function + <seealso marker="#comment-1"><c>ct:comment/1</c></seealso>.</p> + </desc> + </func> + + <func> + <name>continue() -> ok</name> + <fsummary>This function must be called to continue after a test + case (not executing in a parallel group) has called break/1.</fsummary> + <desc><marker id="continue-0"/> + <p>This function must be called to continue after a test case + (not executing in a parallel group) has called function + <seealso marker="#break-1"><c>ct:break/1</c></seealso>.</p> + </desc> + </func> + + <func> + <name>continue(TestCase) -> ok</name> + <fsummary>This function must be called to continue after a test case + has called break/2.</fsummary> + <type> + <v>TestCase = atom()</v> + </type> + <desc><marker id="continue-1"/> + <p>This function must be called to continue after a test case has + called <seealso marker="#break-2"><c>ct:break/2</c></seealso>. + If the paused test case, <c>TestCase</c>, executes in a parallel + group, this function, rather than <c>continue/0</c>, must be used + to let the test case proceed.</p> + </desc> + </func> + + <func> + <name>decrypt_config_file(EncryptFileName, TargetFileName) -> ok | {error, Reason}</name> + <fsummary>Decrypts EncryptFileName, previously generated with + encrypt_config_file/2,3.</fsummary> + <type> + <v>EncryptFileName = string()</v> + <v>TargetFileName = string()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="decrypt_config_file-2"/> + <p>Decrypts <c>EncryptFileName</c>, previously generated with + <seealso marker="#encrypt_config_file-2"><c>ct:encrypt_config_file/2,3</c></seealso>. + The original file contents is saved in the target file. The + encryption key, a string, must be available in a text file named + <c>.ct_config.crypt</c>, either in the current directory, or the + home directory of the user (it is searched for in that order).</p> + </desc> + </func> + + <func> + <name>decrypt_config_file(EncryptFileName, TargetFileName, KeyOrFile) -> ok | {error, Reason}</name> + <fsummary>Decrypts EncryptFileName, previously generated with + encrypt_config_file/2,3.</fsummary> + <type> + <v>EncryptFileName = string()</v> + <v>TargetFileName = string()</v> + <v>KeyOrFile = {key, string()} | {file, string()}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="decrypt_config_file-3"/> + <p>Decrypts <c>EncryptFileName</c>, previously generated with + <seealso marker="#encrypt_config_file-2"><c>ct:encrypt_config_file/2,3</c></seealso>. + The original file contents is saved in the target file. The key + must have the same value as that used for encryption.</p> + </desc> + </func> + + <func> + <name>encrypt_config_file(SrcFileName, EncryptFileName) -> ok | {error, Reason}</name> + <fsummary>Encrypts the source configuration file with DES3 and saves the + result in file EncryptFileName.</fsummary> + <type> + <v>SrcFileName = string()</v> + <v>EncryptFileName = string()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="encrypt_config_file-2"/> + <p>Encrypts the source configuration file with DES3 and saves the result + in file <c>EncryptFileName</c>. The key, a string, must be + available in a text file named <c>.ct_config.crypt</c>, either + in the current directory, or the home directory of the user (it + is searched for in that order).</p> + + <p>For information about using encrypted configuration files when + running tests, see section + <seealso marker="config_file_chapter#encrypted_config_files">Encrypted + Configuration Files</seealso> in the User's Guide.</p> + + <p>For details on DES3 encryption/decryption, see application + <seealso marker="crypto:index"><c>Crypto</c></seealso>.</p> + </desc> + </func> + + <func> + <name>encrypt_config_file(SrcFileName, EncryptFileName, KeyOrFile) -> ok | {error, Reason}</name> + <fsummary>Encrypts the source configuration file with DES3 and saves the + result in the target file EncryptFileName.</fsummary> + <type> + <v>SrcFileName = string()</v> + <v>EncryptFileName = string()</v> + <v>KeyOrFile = {key, string()} | {file, string()}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="encrypt_config_file-3"/> + <p>Encrypts the source configuration file with DES3 and saves the result + in the target file <c>EncryptFileName</c>. The encryption key + to use is either the value in <c>{key,Key}</c> or the value + stored in the file specified by <c>{file,File}</c>.</p> + + <p>For information about using encrypted configuration files when + running tests, see section + <seealso marker="config_file_chapter#encrypted_config_files">Encrypted + Configuration Files</seealso> in the User's Guide.</p> + + <p>For details on DES3 encryption/decryption, see application + <seealso marker="crypto:index"><c>Crypto</c></seealso>.</p> + </desc> + </func> + + <func> + <name>fail(Reason) -> ok</name> + <fsummary>Terminates a test case with the specified error + Reason.</fsummary> + <type> + <v>Reason = term()</v> + </type> + <desc><marker id="fail-1"/> + <p>Terminates a test case with the specified error <c>Reason</c>.</p> + </desc> + </func> + + <func> + <name>fail(Format, Args) -> ok</name> + <fsummary>Terminates a test case with an error message specified by + a format string and a list of values (used as arguments to + io_lib:format/2).</fsummary> + <type> + <v>Format = string()</v> + <v>Args = list()</v> + </type> + <desc><marker id="fail-2"/> + <p>Terminates a test case with an error message specified by a + format string and a list of values (used as arguments to + <c>io_lib:format/2</c>).</p> + </desc> + </func> + + <func> + <name>get_config(Required) -> Value</name> + <fsummary>Equivalent to get_config(Required, undefined, []).</fsummary> + <desc><marker id="get_config-1"/> + <p>Equivalent to <seealso marker="#get_config-3"><c>ct:get_config(Required, + undefined, [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>get_config(Required, Default) -> Value</name> + <fsummary>Equivalent to get_config(Required, Default, []).</fsummary> + <desc><marker id="get_config-2"/> + <p>Equivalent to <seealso marker="#get_config-3"><c>ct:get_config(Required, + Default, [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>get_config(Required, Default, Opts) -> ValueOrElement</name> + <fsummary>Reads configuration data values.</fsummary> + <type> + <v>Required = KeyOrName | {KeyOrName, SubKey} | {KeyOrName, SubKey, SubKey}</v> + <v>KeyOrName = atom()</v> + <v>SubKey = atom()</v> + <v>Default = term()</v> + <v>Opts = [Opt] | []</v> + <v>Opt = element | all</v> + <v>ValueOrElement = term() | Default</v> + </type> + <desc><marker id="get_config-3"/> + <p>Reads configuration data values.</p> + + <p>Returns the matching values or configuration elements, given a + configuration variable key or its associated name (if one has been + specified with + <seealso marker="#require-2"><c>ct:require/2</c></seealso> + or a <c>require</c> statement).</p> + + <p><em>Example:</em></p> + + <p>Given the following configuration file:</p> + + <pre> + {unix,[{telnet,IpAddr}, + {user,[{username,Username}, + {password,Password}]}]}.</pre> + + <p>Then:</p> + + <pre> + ct:get_config(unix,Default) -> [{telnet,IpAddr}, + {user, [{username,Username}, {password,Password}]}] + ct:get_config({unix,telnet},Default) -> IpAddr + ct:get_config({unix,user,username},Default) -> Username + ct:get_config({unix,ftp},Default) -> Default + ct:get_config(unknownkey,Default) -> Default</pre> + + <p>If a configuration variable key has been associated with a name (by + <seealso marker="#require-2"><c>ct:require/2</c></seealso> + or a <c>require</c> statement), the name can be used instead + of the key to read the value:</p> + + <pre> + ct:require(myuser,{unix,user}) -> ok. + ct:get_config(myuser,Default) -> [{username,Username}, {password,Password}]</pre> + + <p>If a configuration variable is defined in multiple files, use option + <c>all</c> to access all possible values. The values are returned + in a list. The order of the elements corresponds to the order + that the configuration files were specified at startup.</p> + + <p>If configuration elements (key-value tuples) are to be returned as + result instead of values, use option <c>element</c>. The + returned elements are then on the form <c>{Required,Value}</c>.</p> + + <p>See also + <seealso marker="#get_config-1"><c>ct:get_config/1</c></seealso>, + <seealso marker="#get_config-2"><c>ct:get_config/2</c></seealso>, + <seealso marker="#require-1"><c>ct:require/1</c></seealso>, + <seealso marker="#require-2"><c>ct:require/2</c></seealso>.</p> + </desc> + </func> + + <func> + <name>get_event_mgr_ref() -> EvMgrRef</name> + <fsummary>Gets a reference to the <c>Common Test</c> event manager.</fsummary> + <type> + <v>EvMgrRef = atom()</v> + </type> + <desc><marker id="get_event_mgr_ref-0"/> + <p>Gets a reference to the <c>Common Test</c> event manager. + The reference can be used to, for example, add a user-specific + event handler while tests are running.</p> + + <p><em>Example:</em></p> + + <pre> + gen_event:add_handler(ct:get_event_mgr_ref(), my_ev_h, [])</pre> + </desc> + </func> + + <func> + <name>get_status() -> TestStatus | {error, Reason} | no_tests_running</name> + <fsummary>Returns status of ongoing test.</fsummary> + <type> + <v>TestStatus = [StatusElem]</v> + <v>StatusElem = {current, TestCaseInfo} | {successful, Successful} | {failed, Failed} | {skipped, Skipped} | {total, Total}</v> + <v>TestCaseInfo = {Suite, TestCase} | [{Suite, TestCase}]</v> + <v>Suite = atom()</v> + <v>TestCase = atom()</v> + <v>Successful = integer()</v> + <v>Failed = integer()</v> + <v>Skipped = {UserSkipped, AutoSkipped}</v> + <v>UserSkipped = integer()</v> + <v>AutoSkipped = integer()</v> + <v>Total = integer()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="get_status-0"/> + <p>Returns status of ongoing test. The returned list contains + information about which test case is executing (a list of cases + when a parallel test case group is executing), as well as + counters for successful, failed, skipped, and total test cases + so far.</p> + </desc> + </func> + + <func> + <name>get_target_name(Handle) -> {ok, TargetName} | {error, Reason}</name> + <fsummary>Returns the name of the target that the specified connection + belongs to.</fsummary> + <type> + <v>Handle = handle()</v> + <v>TargetName = target_name()</v> + </type> + <desc><marker id="get_target_name-1"/> + <p>Returns the name of the target that the specified connection + belongs to.</p> + </desc> + </func> + + <func> + <name>get_testspec_terms() -> TestSpecTerms | undefined</name> + <fsummary>Gets a list of all test specification terms used to + configure and run this test.</fsummary> + <type> + <v>TestSpecTerms = [{Tag, Value}]</v> + <v>Value = [term()]</v> + </type> + <desc><marker id="get_testspec_terms-0"/> + <p>Gets a list of all test specification terms used to configure + and run this test.</p> + </desc> + </func> + + <func> + <name>get_testspec_terms(Tags) -> TestSpecTerms | undefined</name> + <fsummary>Reads one or more terms from the test specification used to + configure and run this test.</fsummary> + <type> + <v>Tags = [Tag] | Tag</v> + <v>Tag = atom()</v> + <v>TestSpecTerms = [{Tag, Value}] | {Tag, Value}</v> + <v>Value = [{Node, term()}] | [term()]</v> + <v>Node = atom()</v> + </type> + <desc><marker id="get_testspec_terms-1"/> + <p>Reads one or more terms from the test specification used to + configure and run this test. <c>Tag</c> is any valid test + specification tag, for example, <c>label</c>, <c>config</c>, or + <c>logdir</c>. User-specific terms are also available to read if + option <c>allow_user_terms</c> is set.</p> + <p>All value tuples returned, except user terms, have the node + name as first element.</p> + <p>To read test terms, use <c>Tag = tests</c> (rather than + <c>suites</c>, <c>groups</c>, or <c>cases</c>). <c>Value</c> is + then the list of <em>all</em> tests on the form + <c>[{Node,Dir,[{TestSpec,GroupsAndCases1},...]},...]</c>, where + <c>GroupsAndCases = [{Group,[Case]}] | [Case]</c>.</p> + </desc> + </func> + + <func> + <name>get_timetrap_info() -> {Time, Scale}</name> + <fsummary>Reads information about the timetrap set for the current + test case.</fsummary> + <type> + <v>Time = integer() | infinity</v> + <v>Scale = true | false</v> + </type> + <desc><marker id="get_timetrap_info-0"/> + <p>Reads information about the timetrap set for the current test + case. <c>Scale</c> indicates if <c>Common Test</c> will attempt + to compensate timetraps automatically for runtime delays + introduced by, for example, tools like cover.</p> + </desc> + </func> + + <func> + <name>install(Opts) -> ok | {error, Reason}</name> + <fsummary>Installs configuration files and event handlers.</fsummary> + <type> + <v>Opts = [Opt]</v> + <v>Opt = {config, ConfigFiles} | {event_handler, Modules} | {decrypt, KeyOrFile}</v> + <v>ConfigFiles = [ConfigFile]</v> + <v>ConfigFile = string()</v> + <v>Modules = [atom()]</v> + <v>KeyOrFile = {key, Key} | {file, KeyFile}</v> + <v>Key = string()</v> + <v>KeyFile = string()</v> + </type> + <desc><marker id="install-1"/> + <p>Installs configuration files and event handlers.</p> + + <p>Run this function once before the first test.</p> + + <p><em>Example:</em></p> + + <pre> + install([{config,["config_node.ctc","config_user.ctc"]}])</pre> + + <p>This function is automatically run by program <c>ct_run</c>.</p> + </desc> + </func> + + <func> + <name>listenv(Telnet) -> [Env]</name> + <fsummary>Performs command listenv on the specified Telnet connection + and returns the result as a list of key-value pairs.</fsummary> + <type> + <v>Telnet = term()</v> + <v>Env = {Key, Value}</v> + <v>Key = string()</v> + <v>Value = string()</v> + </type> + <desc><marker id="listenv-1"/> + <p>Performs command <c>listenv</c> on the specified Telnet connection + and returns the result as a list of key-value pairs.</p> + </desc> + </func> + + <func> + <name>log(Format) -> ok</name> + <fsummary>Equivalent to log(default, 50, Format, [], []).</fsummary> + <desc><marker id="log-1"/> + <p>Equivalent to + <seealso marker="#log-5"><c>ct:log(default, 50, Format, [], [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>log(X1, X2) -> ok</name> + <fsummary>Equivalent to log(Category, Importance, Format, + FormatArgs, []).</fsummary> + <type> + <v>X1 = Category | Importance | Format</v> + <v>X2 = Format | FormatArgs</v> + </type> + <desc><marker id="log-2"/> + <p>Equivalent to <seealso marker="#log-5"><c>ct:log(Category, + Importance, Format, FormatArgs, [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>log(X1, X2, X3) -> ok</name> + <fsummary>Equivalent to log(Category, Importance, Format, + FormatArgs, Opts).</fsummary> + <type> + <v>X1 = Category | Importance</v> + <v>X2 = Importance | Format</v> + <v>X3 = Format | FormatArgs | Opts</v> + </type> + <desc><marker id="log-3"/> + <p>Equivalent to <seealso marker="#log-5"><c>ct:log(Category, + Importance, Format, FormatArgs, Opts)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>log(X1, X2, X3, X4) -> ok</name> + <fsummary>Equivalent to log(Category, Importance, Format, + FormatArgs, Opts).</fsummary> + <type> + <v>X1 = Category | Importance</v> + <v>X2 = Importance | Format</v> + <v>X3 = Format | FormatArgs</v> + <v>X4 = FormatArgs | Opts</v> + </type> + <desc><marker id="log-4"/> + <p>Equivalent to <seealso marker="#log-5"><c>ct:log(Category, + Importance, Format, FormatArgs, Opts)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>log(Category, Importance, Format, FormatArgs, Opts) -> ok</name> + <fsummary>Prints from a test case to the log file.</fsummary> + <type> + <v>Category = atom()</v> + <v>Importance = integer()</v> + <v>Format = string()</v> + <v>FormatArgs = list()</v> + <v>Opts = [Opt]</v> + <v>Opt = no_css | esc_chars</v> + </type> + <desc><marker id="log-5"/> + <p>Prints from a test case to the log file.</p> + + <p>This function is meant for printing a string directly from a + test case to the test case log file.</p> + + <p>Default <c>Category</c> is <c>default</c>, + default <c>Importance</c> is <c>?STD_IMPORTANCE</c>, + and default value for <c>FormatArgs</c> is <c>[]</c>.</p> + + <p>For details on <c>Category</c>, <c>Importance</c> and the <c>no_css</c> + option, see section <seealso marker="write_test_chapter#logging"> + Logging - Categories and Verbosity Levels</seealso> in the User's Guide.</p> + + <p>Common Test will not escape special HTML characters (<, > and &) + in the text printed with this function, unless the <c>esc_chars</c> + option is used.</p> + </desc> + </func> + + <func> + <name>make_priv_dir() -> ok | {error, Reason}</name> + <fsummary>If the test has been started with option create_priv_dir + set to manual_per_tc, in order for the test case to use the private + directory, it must first create it by calling this function.</fsummary> + <type> + <v>Reason = term()</v> + </type> + <desc><marker id="make_priv_dir-0"/> + <p>If the test is started with option <c>create_priv_dir</c> + set to <c>manual_per_tc</c>, in order for the test case to use + the private directory, it must first create it by calling this + function.</p> + </desc> + </func> + + <func> + <name>notify(Name, Data) -> ok</name> + <fsummary>Sends an asynchronous notification of type Name with Data + to the <c>Common Test</c> event manager.</fsummary> + <type> + <v>Name = atom()</v> + <v>Data = term()</v> + </type> + <desc><marker id="notify-2"/> + <p>Sends an asynchronous notification of type <c>Name</c> with + <c>Data</c>to the Common Test event manager. This can later be + caught by any installed event manager.</p> + + <p>See also + <seealso marker="stdlib:gen_event"><c>stdlib:gen_event(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>pal(Format) -> ok</name> + <fsummary>Equivalent to pal(default, 50, Format, []).</fsummary> + <desc><marker id="pal-1"/> + <p>Equivalent to + <seealso marker="#pal-4"><c>ct:pal(default, 50, Format, + [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>pal(X1, X2) -> ok</name> + <fsummary>Equivalent to pal(Category, Importance, Format, + FormatArgs).</fsummary> + <type> + <v>X1 = Category | Importance | Format</v> + <v>X2 = Format | FormatArgs</v> + </type> + <desc><marker id="pal-2"/> + <p>Equivalent to <seealso marker="#pal-4"><c>ct:pal(Category, + Importance, Format, FormatArgs)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>pal(X1, X2, X3) -> ok</name> + <fsummary>Equivalent to pal(Category, Importance, Format, + FormatArgs).</fsummary> + <type> + <v>X1 = Category | Importance</v> + <v>X2 = Importance | Format</v> + <v>X3 = Format | FormatArgs</v> + </type> + <desc><marker id="pal-3"/> + <p>Equivalent to <seealso marker="#pal-4"><c>ct:pal(Category, + Importance, Format, FormatArgs)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>pal(Category, Importance, Format, FormatArgs) -> ok</name> + <fsummary>Prints and logs from a test case.</fsummary> + <type> + <v>Category = atom()</v> + <v>Importance = integer()</v> + <v>Format = string()</v> + <v>FormatArgs = list()</v> + </type> + <desc><marker id="pal-4"/> + <p>Prints and logs from a test case.</p> + + <p>This function is meant for printing a string from a test case, + both to the test case log file and to the console.</p> + + <p>Default <c>Category</c> is <c>default</c>, + default <c>Importance</c> is <c>?STD_IMPORTANCE</c>, + and default value for <c>FormatArgs</c> is <c>[]</c>.</p> + + <p>For details on <c>Category</c> and <c>Importance</c>, see section + <seealso marker="write_test_chapter#logging">Logging - Categories + and Verbosity Levels</seealso> in the User's Guide.</p> + + <p>Note that special characters in the text (<, > and &) will + be escaped by Common Test before the text is printed to the log + file.</p> + </desc> + </func> + + <func> + <name>parse_table(Data) -> {Heading, Table}</name> + <fsummary>Parses the printout from an SQL table and returns a list of + tuples.</fsummary> + <type> + <v>Data = [string()]</v> + <v>Heading = tuple()</v> + <v>Table = [tuple()]</v> + </type> + <desc><marker id="parse_table-1"/> + <p>Parses the printout from an SQL table and returns a list of + tuples.</p> + + <p>The printout to parse is typically the result of a <c>select</c> + command in SQL. The returned <c>Table</c> is a list of tuples, + where each tuple is a row in the table.</p> + + <p><c>Heading</c> is a tuple of strings representing the headings + of each column in the table.</p> + </desc> + </func> + + <func> + <name>print(Format) -> ok</name> + <fsummary>Equivalent to print(default, 50, Format, []).</fsummary> + <desc><marker id="print-1"/> + <p>Equivalent to <seealso marker="#print-4"><c>ct:print(default, + 50, Format, [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>print(X1, X2) -> ok</name> + <fsummary>Equivalent to print(Category, Importance, Format, + FormatArgs).</fsummary> + <type> + <v>X1 = Category | Importance | Format</v> + <v>X2 = Format | FormatArgs</v> + </type> + <desc><marker id="print-2"/> + <p>Equivalent to <seealso marker="#print-4"><c>ct:print(Category, + Importance, Format, FormatArgs)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>print(X1, X2, X3) -> ok</name> + <fsummary>Equivalent to print(Category, Importance, Format, + FormatArgs).</fsummary> + <type> + <v>X1 = Category | Importance</v> + <v>X2 = Importance | Format</v> + <v>X3 = Format | FormatArgs</v> + </type> + <desc><marker id="print-3"/> + <p>Equivalent to <seealso marker="#print-4"><c>ct:print(Category, + Importance, Format, FormatArgs)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>print(Category, Importance, Format, FormatArgs) -> ok</name> + <fsummary>Prints from a test case to the console.</fsummary> + <type> + <v>Category = atom()</v> + <v>Importance = integer()</v> + <v>Format = string()</v> + <v>FormatArgs = list()</v> + </type> + <desc><marker id="print-4"/> + <p>Prints from a test case to the console.</p> + + <p>This function is meant for printing a string from a test case to + the console.</p> + + <p>Default <c>Category</c> is <c>default</c>, + default <c>Importance</c> is <c>?STD_IMPORTANCE</c>, + and default value for <c>FormatArgs</c> is <c>[]</c>.</p> + + <p>For details on <c>Category</c> and <c>Importance</c>, see section + <seealso marker="write_test_chapter#logging">Logging - Categories + and Verbosity Levels</seealso> in the User's Guide.</p> + </desc> + </func> + + <func> + <name>reload_config(Required) -> ValueOrElement</name> + <fsummary>Reloads configuration file containing specified configuration + key.</fsummary> + <type> + <v>Required = KeyOrName | {KeyOrName, SubKey} | {KeyOrName, SubKey, SubKey}</v> + <v>KeyOrName = atom()</v> + <v>SubKey = atom()</v> + <v>ValueOrElement = term()</v> + </type> + <desc><marker id="reload_config-1"/> + <p>Reloads configuration file containing specified configuration key.</p> + + <p>This function updates the configuration data from which the + specified configuration variable was read, and returns the (possibly) + new value of this variable.</p> + + <p>If some variables were present in the configuration, but are + not loaded using this function, they are removed from the + configuration table together with their aliases.</p> + </desc> + </func> + + <func> + <name>remove_config(Callback, Config) -> ok</name> + <fsummary>Removes configuration variables (together with + their aliases) that were loaded with specified callback module and + configuration string.</fsummary> + <type> + <v>Callback = atom()</v> + <v>Config = string()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="remove_config-2"/> + <p>Removes configuration variables (together wih their aliases) + that were loaded with specified callback module and configuration + string.</p> + </desc> + </func> + + <func> + <name>require(Required) -> ok | {error, Reason}</name> + <fsummary>Checks if the required configuration is available.</fsummary> + <type> + <v>Required = Key | {Key, SubKeys} | {Key, SubKey, SubKeys}</v> + <v>Key = atom()</v> + <v>SubKeys = SubKey | [SubKey]</v> + <v>SubKey = atom()</v> + </type> + <desc><marker id="require-1"/> + <p>Checks if the required configuration is available. Arbitrarily + deep tuples can be specified as <c>Required</c>. Only the last + element of the tuple can be a list of <c>SubKey</c>s.</p> + + <p><em>Example 1.</em> Require the variable <c>myvar</c>:</p> + + <pre> + ok = ct:require(myvar).</pre> + + <p>In this case the configuration file must at least contain:</p> + + <pre> + {myvar,Value}.</pre> + + <p><em>Example 2.</em> Require key <c>myvar</c> with subkeys + <c>sub1</c> and <c>sub2</c>:</p> + + <pre> + ok = ct:require({myvar,[sub1,sub2]}).</pre> + + <p>In this case the configuration file must at least contain:</p> + + <pre> + {myvar,[{sub1,Value},{sub2,Value}]}.</pre> + + <p><em>Example 3.</em> Require key <c>myvar</c> with subkey + <c>sub1</c> with <c>subsub1</c>:</p> + + <pre> + ok = ct:require({myvar,sub1,sub2}).</pre> + + <p>In this case the configuration file must at least contain:</p> + + <pre> + {myvar,[{sub1,[{sub2,Value}]}]}.</pre> + + <p>See also + <seealso marker="#get_config-1"><c>ct:get_config/1</c></seealso>, + <seealso marker="#get_config-2"><c>ct:get_config/2</c></seealso>, + <seealso marker="#get_config-3"><c>ct:get_config/3</c></seealso>, + <seealso marker="#require-2"><c>ct:require/2</c></seealso>.</p> + </desc> + </func> + + <func> + <name>require(Name, Required) -> ok | {error, Reason}</name> + <fsummary>Checks if the required configuration is available and gives + it a name.</fsummary> + <type> + <v>Name = atom()</v> + <v>Required = Key | {Key, SubKey} | {Key, SubKey, SubKey}</v> + <v>SubKey = Key</v> + <v>Key = atom()</v> + </type> + <desc><marker id="require-2"/> + <p>Checks if the required configuration is available and gives it a + name. The semantics for <c>Required</c> is the same as in + <seealso marker="#require-1"><c>ct:require/1</c></seealso> except + that a list of <c>SubKey</c>s cannot be specified.</p> + + <p>If the requested data is available, the subentry is associated + with <c>Name</c> so that the value of the element can be read with + <seealso marker="#get_config-1"><c>ct:get_config/1,2</c></seealso> + provided <c>Name</c> is used instead of the whole <c>Required</c> + term.</p> + + <p><em>Example:</em></p> + + <p>Require one node with a Telnet connection and an FTP connection. + Name the node <c>a</c>:</p> + + <pre> + ok = ct:require(a,{machine,node}).</pre> + + <p>All references to this node can then use the node name. For + example, a file over FTP is fetched like follows:</p> + + <pre> + ok = ct:ftp_get(a,RemoteFile,LocalFile).</pre> + + <p>For this to work, the configuration file must at least contain:</p> + + <pre> + {machine,[{node,[{telnet,IpAddr},{ftp,IpAddr}]}]}.</pre> + + <note><p>The behavior of this function changed radically in + <c>Common Test</c> 1.6.2. To keep some backwards compatability, + it is still possible to do:<br/> + <c>ct:require(a,{node,[telnet,ftp]}).</c><br/> + This associates the name <c>a</c> with the top-level <c>node</c> + entry. For this to work, the configuration file must at least + contain:<br/> + <c>{node,[{telnet,IpAddr},{ftp,IpAddr}]}.</c></p> + </note> + + <p>See also + <seealso marker="#get_config-1"><c>ct:get_config/1</c></seealso>, + <seealso marker="#get_config-2"><c>ct:get_config/2</c></seealso>, + <seealso marker="#get_config-3"><c>ct:get_config/3</c></seealso>, + <seealso marker="#require-1"><c>ct:require/1</c></seealso>.</p> + </desc> + </func> + + <func> + <name>run(TestDirs) -> Result</name> + <fsummary>Runs all test cases in all suites in the specified + directories.</fsummary> + <type> + <v>TestDirs = TestDir | [TestDir]</v> + </type> + <desc><marker id="run-1"/> + <p>Runs all test cases in all suites in the specified directories.</p> + + <p>See also <seealso marker="#run-3"><c>ct:run/3</c></seealso>.</p> + </desc> + </func> + + <func> + <name>run(TestDir, Suite) -> Result</name> + <fsummary>Runs all test cases in the specified suite.</fsummary> + <desc><marker id="run-2"/> + <p>Runs all test cases in the specified suite.</p> + + <p>See also <seealso marker="#run-3"><c>ct:run/3</c></seealso>.</p> + </desc> + </func> + + <func> + <name>run(TestDir, Suite, Cases) -> Result</name> + <fsummary>Runs the specified test cases.</fsummary> + <type> + <v>TestDir = string()</v> + <v>Suite = atom()</v> + <v>Cases = atom() | [atom()]</v> + <v>Result = [TestResult] | {error, Reason}</v> + </type> + <desc><marker id="run-3"/> + <p>Runs the specified test cases.</p> + + <p>Requires that + <seealso marker="#install-1"><c>ct:install/1</c></seealso> has been + run first.</p> + + <p>Suites (<c>*_SUITE.erl</c>) files must be stored in <c>TestDir</c> + or <c>TestDir/test</c>. All suites are compiled when the test is + run.</p> + </desc> + </func> + + <func> + <name>run_test(Opts) -> Result</name> + <fsummary>Runs tests as specified by the combination of options in + Opts.</fsummary> + <type> + <v>Opts = [OptTuples]</v> + <v>OptTuples = {dir, TestDirs} | {suite, Suites} | {group, Groups} | {testcase, Cases} | {spec, TestSpecs} | {join_specs, Bool} | {label, Label} | {config, CfgFiles} | {userconfig, UserConfig} | {allow_user_terms, Bool} | {logdir, LogDir} | {silent_connections, Conns} | {stylesheet, CSSFile} | {cover, CoverSpecFile} | {cover_stop, Bool} | {step, StepOpts} | {event_handler, EventHandlers} | {include, InclDirs} | {auto_compile, Bool} | {abort_if_missing_suites, Bool} | {create_priv_dir, CreatePrivDir} | {multiply_timetraps, M} | {scale_timetraps, Bool} | {repeat, N} | {duration, DurTime} | {until, StopTime} | {force_stop, ForceStop} | {decrypt, DecryptKeyOrFile} | {refresh_logs, LogDir} | {logopts, LogOpts} | {verbosity, VLevels} | {basic_html, Bool} | {ct_hooks, CTHs} | {enable_builtin_hooks, Bool} | {release_shell, Bool}</v> + <v>TestDirs = [string()] | string()</v> + <v>Suites = [string()] | [atom()] | string() | atom()</v> + <v>Cases = [atom()] | atom()</v> + <v>Groups = GroupNameOrPath | [GroupNameOrPath]</v> + <v>GroupNameOrPath = [atom()] | atom() | all</v> + <v>TestSpecs = [string()] | string()</v> + <v>Label = string() | atom()</v> + <v>CfgFiles = [string()] | string()</v> + <v>UserConfig = [{CallbackMod, CfgStrings}] | {CallbackMod, CfgStrings}</v> + <v>CallbackMod = atom()</v> + <v>CfgStrings = [string()] | string()</v> + <v>LogDir = string()</v> + <v>Conns = all | [atom()]</v> + <v>CSSFile = string()</v> + <v>CoverSpecFile = string()</v> + <v>StepOpts = [StepOpt] | []</v> + <v>StepOpt = config | keep_inactive</v> + <v>EventHandlers = EH | [EH]</v> + <v>EH = atom() | {atom(), InitArgs} | {[atom()], InitArgs}</v> + <v>InitArgs = [term()]</v> + <v>InclDirs = [string()] | string()</v> + <v>CreatePrivDir = auto_per_run | auto_per_tc | manual_per_tc</v> + <v>M = integer()</v> + <v>N = integer()</v> + <v>DurTime = string(HHMMSS)</v> + <v>StopTime = string(YYMoMoDDHHMMSS) | string(HHMMSS)</v> + <v>ForceStop = skip_rest | Bool</v> + <v>DecryptKeyOrFile = {key, DecryptKey} | {file, DecryptFile}</v> + <v>DecryptKey = string()</v> + <v>DecryptFile = string()</v> + <v>LogOpts = [LogOpt]</v> + <v>LogOpt = no_nl | no_src</v> + <v>VLevels = VLevel | [{Category, VLevel}]</v> + <v>VLevel = integer()</v> + <v>Category = atom()</v> + <v>CTHs = [CTHModule | {CTHModule, CTHInitArgs}]</v> + <v>CTHModule = atom()</v> + <v>CTHInitArgs = term()</v> + <v>Result = {Ok, Failed, {UserSkipped, AutoSkipped}} | TestRunnerPid | {error, Reason}</v> + <v>Ok = integer()</v> + <v>Failed = integer()</v> + <v>UserSkipped = integer()</v> + <v>AutoSkipped = integer()</v> + <v>TestRunnerPid = pid()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="run_test-1"/> + <p>Runs tests as specified by the combination of options in + <c>Opts</c>. The options are the same as those used with program + <c>ct_run</c>, see <seealso marker="ct_run#ct_run">Run Tests from + Command Line</seealso> in the <c>ct_run</c> manual page.</p> + <p>Here a <c>TestDir</c> can be used to point out the path to a + <c>Suite</c>. Option <c>testcase</c> corresponds to option + <c>-case</c> in program <c>ct_run</c>. Configuration files + specified in <c>Opts</c> are installed automatically at startup.</p> + + <p><c>TestRunnerPid</c> is returned if <c>release_shell == true</c>. + For details, see + <seealso marker="#break-1"><c>ct:break/1</c></seealso>.</p> + + <p><c>Reason</c> indicates the type of error encountered.</p> + </desc> + </func> + + <func> + <name>run_testspec(TestSpec) -> Result</name> + <fsummary>Runs a test specified by TestSpec.</fsummary> + <type> + <v>TestSpec = [term()]</v> + <v>Result = {Ok, Failed, {UserSkipped, AutoSkipped}} | {error, Reason}</v> + <v>Ok = integer()</v> + <v>Failed = integer()</v> + <v>UserSkipped = integer()</v> + <v>AutoSkipped = integer()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="run_testspec-1"/> + <p>Runs a test specified by <c>TestSpec</c>. The same terms are used + as in test specification files.</p> + + <p><c>Reason</c> indicates the type of error encountered.</p> + </desc> + </func> + + <func> + <name>sleep(Time) -> ok</name> + <fsummary>This function, similar to timer:sleep/1, suspends the + test case for a specified time.</fsummary> + <type> + <v>Time = {hours, Hours} | {minutes, Mins} | {seconds, Secs} | Millisecs | infinity</v> + <v>Hours = integer()</v> + <v>Mins = integer()</v> + <v>Secs = integer()</v> + <v>Millisecs = integer() | float()</v> + </type> + <desc><marker id="sleep-1"/> + <p>This function, similar to <c>timer:sleep/1</c> in <c>STDLIB</c>, + suspends the test case for a specified time. + However, this function also multiplies <c>Time</c> with the + <c>multiply_timetraps</c> value (if set) and under certain + circumstances also scales up the time automatically if + <c>scale_timetraps</c> is set to <c>true</c> (default is + <c>false</c>).</p> + </desc> + </func> + + <func> + <name>start_interactive() -> ok</name> + <fsummary>Starts <c>Common Test</c> in interactive mode.</fsummary> + <desc><marker id="start_interactive-0"/> + <p>Starts <c>Common Test</c> in interactive mode.</p> + + <p>From this mode, all test case support functions can be executed + directly from the Erlang shell. The interactive mode can also be + started from the OS command line with <c>ct_run -shell + [-config File...]</c>.</p> + + <p>If any functions (for example, Telnet or FTP) using + "required configuration data" are to be called from the Erlang shell, + configuration data must first be required with + <seealso marker="#require-2"><c>ct:require/2</c></seealso>.</p> + + <p><em>Example:</em></p> + + <pre> + > ct:require(unix_telnet, unix). + ok + > ct_telnet:open(unix_telnet). + {ok,<0.105.0>} + > ct_telnet:cmd(unix_telnet, "ls ."). + {ok,["ls","file1 ...",...]}</pre> + </desc> + </func> + + <func> + <name>step(TestDir, Suite, Case) -> Result</name> + <fsummary>Steps through a test case with the debugger.</fsummary> + <type> + <v>Case = atom()</v> + </type> + <desc><marker id="step-3"/> + <p>Steps through a test case with the debugger.</p> + + <p>See also <seealso marker="#run-3"><c>ct:run/3</c></seealso>.</p> + </desc> + </func> + + <func> + <name>step(TestDir, Suite, Case, Opts) -> Result</name> + <fsummary>Steps through a test case with the debugger.</fsummary> + <type> + <v>Case = atom()</v> + <v>Opts = [Opt] | []</v> + <v>Opt = config | keep_inactive</v> + </type> + <desc><marker id="step-4"/> + <p>Steps through a test case with the debugger. If option + <c>config</c> has been specifed, breakpoints are also set on + the configuration functions in <c>Suite</c>.</p> + + <p>See also <seealso marker="#run-3"><c>ct:run/3</c></seealso>.</p> + </desc> + </func> + + <func> + <name>stop_interactive() -> ok</name> + <fsummary>Exits the interactive mode.</fsummary> + <desc><marker id="stop_interactive-0"/> + <p>Exits the interactive mode.</p> + + <p>See also + <seealso marker="#start_interactive-0"><c>ct:start_interactive/0</c></seealso>. + </p> + </desc> + </func> + + <func> + <name>sync_notify(Name, Data) -> ok</name> + <fsummary>Sends a synchronous notification of type Name with Data to + the <c>Common Test</c> event manager.</fsummary> + <type> + <v>Name = atom()</v> + <v>Data = term()</v> + </type> + <desc><marker id="sync_notify-2"/> + <p>Sends a synchronous notification of type <c>Name</c> with + <c>Data</c> to the <c>Common Test</c> event manager. This can later be + caught by any installed event manager.</p> + + <p>See also + <seealso marker="stdlib:gen_event"><c>stdlib:gen_event(3)</c></seealso>. + </p> + </desc> + </func> + + <func> + <name>testcases(TestDir, Suite) -> Testcases | {error, Reason}</name> + <fsummary>Returns all test cases in the specified suite.</fsummary> + <type> + <v>TestDir = string()</v> + <v>Suite = atom()</v> + <v>Testcases = list()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="testcases-2"/> + <p>Returns all test cases in the specified suite.</p> + </desc> + </func> + + <func> + <name>timetrap(Time) -> ok</name> + <fsummary>Sets a new timetrap for the running test case.</fsummary> + <type> + <v>Time = {hours, Hours} | {minutes, Mins} | {seconds, Secs} | Millisecs | infinity | Func</v> + <v>Hours = integer()</v> + <v>Mins = integer()</v> + <v>Secs = integer()</v> + <v>Millisecs = integer() | float()</v> + <v>Func = {M, F, A} | function()</v> + <v>M = atom()</v> + <v>F = atom()</v> + <v>A = list()</v> + </type> + <desc><marker id="timetrap-1"/> + <p>Sets a new timetrap for the running test case.</p> + + <p>If the argument is <c>Func</c>, the timetrap is triggered when + this function returns. <c>Func</c> can also return a new + <c>Time</c> value, which in that case is the value for the new + timetrap.</p> + </desc> + </func> + + <func> + <name>userdata(TestDir, Suite) -> SuiteUserData | {error, Reason}</name> + <fsummary>Returns any data specified with tag userdata in the list of + tuples returned from Suite:suite/0.</fsummary> + <type> + <v>TestDir = string()</v> + <v>Suite = atom()</v> + <v>SuiteUserData = [term()]</v> + <v>Reason = term()</v> + </type> + <desc><marker id="userdata-2"/> + <p>Returns any data specified with tag <c>userdata</c> in the list + of tuples returned from + <seealso marker="common_test#Module:suite-0"><c>suite/0</c></seealso>.</p> + </desc> + </func> + + <func> + <name>userdata(TestDir, Suite, Case::GroupOrCase) -> TCUserData | {error, Reason}</name> + <fsummary>Returns any data specified with tag userdata in the list of + tuples returned from Suite:group(GroupName) or Suite:Case().</fsummary> + <type> + <v>TestDir = string()</v> + <v>Suite = atom()</v> + <v>GroupOrCase = {group, GroupName} | atom()</v> + <v>GroupName = atom()</v> + <v>TCUserData = [term()]</v> + <v>Reason = term()</v> + </type> + <desc><marker id="userdata-3"/> + <p>Returns any data specified with tag <c>userdata</c> in the list + of tuples returned from <c>Suite:group(GroupName)</c> or + <c>Suite:Case()</c>.</p> + </desc> + </func> + </funcs> + +</erlref> + + diff --git a/lib/common_test/doc/src/ct_cover.xml b/lib/common_test/doc/src/ct_cover.xml new file mode 100644 index 0000000000..be09c08a68 --- /dev/null +++ b/lib/common_test/doc/src/ct_cover.xml @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>ct_cover</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>ct_cover.xml</file> + </header> + <module>ct_cover</module> + <modulesummary>Common Test framework code coverage support module. + </modulesummary> + +<description> + + <p><c>Common Test</c> framework code coverage support module.</p> + + <p>This module exports help functions for performing code coverage + analysis.</p> + +</description> + + <funcs> + <func> + <name>add_nodes(Nodes) -> {ok, StartedNodes} | {error, Reason}</name> + <fsummary>Adds nodes to current cover test (only works if cover support + is active).</fsummary> + <type> + <v>Nodes = [atom()]</v> + <v>StartedNodes = [atom()]</v> + <v>Reason = cover_not_running | not_main_node</v> + </type> + <desc><marker id="add_nodes-1"/> + <p>Adds nodes to current cover test. Notice that this only works if + cover support is active.</p> + + <p>To have effect, this function is to be called from + <c>init_per_suite/1</c> (see + <seealso marker="common_test"><c>common_test</c></seealso>) + before any tests are performed.</p> + </desc> + </func> + + <func> + <name>cross_cover_analyse(Level, Tests) -> ok</name> + <fsummary>Accumulates cover results over multiple tests.</fsummary> + <type> + <v>Level = overview | details</v> + <v>Tests = [{Tag, Dir}]</v> + <v>Tag = atom()</v> + <v>Dir = string()</v> + </type> + <desc><marker id="cross_cover_analyse-2"/> + <p>Accumulates cover results over multiple tests. See section + <seealso marker="cover_chapter#cross_cover">Cross Cover + Analysis</seealso> in the Users's Guide.</p> + </desc> + </func> + + <func> + <name>remove_nodes(Nodes) -> ok | {error, Reason}</name> + <fsummary>Removes nodes from the current cover test.</fsummary> + <type> + <v>Nodes = [atom()]</v> + <v>Reason = cover_not_running | not_main_node</v> + </type> + <desc><marker id="remove_nodes-1"/> + <p>Removes nodes from the current cover test.</p> + + <p>Call this function to stop cover test on nodes previously + added with + <seealso marker="#add_nodes-1"><c>ct_cover:add_nodes/1</c></seealso>. + Results on the remote node are transferred to the <c>Common Test</c> + node.</p> + </desc> + </func> + </funcs> + +</erlref> + + diff --git a/lib/common_test/doc/src/ct_ftp.xml b/lib/common_test/doc/src/ct_ftp.xml new file mode 100644 index 0000000000..0598dcbe3e --- /dev/null +++ b/lib/common_test/doc/src/ct_ftp.xml @@ -0,0 +1,277 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>ct_ftp</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>ct_ftp.xml</file> + </header> + <module>ct_ftp</module> + <modulesummary>FTP client module (based on the FTP support of the Inets + application).</modulesummary> + + <description> + + <p>FTP client module (based on the FTP support of the <c>Inets</c> + application).</p> + + </description> + + <section> + <title>Data Types</title> + <marker id="types"/> + <taglist> + <tag><c>connection() = handle() | target_name()</c></tag> + <item><marker id="type-connection"/> + <p>For <c>target_name</c>, see module + <seealso marker="ct"><c>ct</c></seealso>.</p></item> + + <tag><c>handle() = handle()</c></tag> + <item><marker id="type-handle"/> + <p>Handle for a specific FTP connection, see module + <seealso marker="ct"><c>ct</c></seealso>.</p></item> + </taglist> + </section> + + <funcs> + <func> + <name>cd(Connection, Dir) -> ok | {error, Reason}</name> + <fsummary>Changes directory on remote host.</fsummary> + <type> + <v>Connection = connection()</v> + <v>Dir = string()</v> + </type> + <desc><marker id="cd-2"/> + <p>Changes directory on remote host.</p> + </desc> + </func> + + <func> + <name>close(Connection) -> ok | {error, Reason}</name> + <fsummary>Closes the FTP connection.</fsummary> + <type> + <v>Connection = connection()</v> + </type> + <desc><marker id="close-1"/> + <p>Closes the FTP connection.</p> + </desc> + </func> + + <func> + <name>delete(Connection, File) -> ok | {error, Reason}</name> + <fsummary>Deletes a file on remote host.</fsummary> + <type> + <v>Connection = connection()</v> + <v>File = string()</v> + </type> + <desc><marker id="delete-2"/> + <p>Deletes a file on remote host.</p> + </desc> + </func> + + <func> + <name>get(KeyOrName, RemoteFile, LocalFile) -> ok | {error, Reason}</name> + <fsummary>Opens an FTP connection and fetches a file from the remote + host.</fsummary> + <type> + <v>KeyOrName = Key | Name</v> + <v>Key = atom()</v> + <v>Name = target_name()</v> + <v>RemoteFile = string()</v> + <v>LocalFile = string()</v> + </type> + <desc><marker id="get-3"/> + <p>Opens an FTP connection and fetches a file from the remote + host.</p> + + <p><c>RemoteFile</c> and <c>LocalFile</c> must be absolute paths.</p> + + <p>The configuration file must be as for + <seealso marker="#put-3"><c>ct_ftp:put/3</c></seealso>.</p> + + <p>For <c>target_name</c>, see module + <seealso marker="ct"><c>ct</c></seealso>.</p> + + <p>See also + <seealso marker="ct#require-2"><c>ct:require/2</c></seealso>.</p> + </desc> + </func> + + <func> + <name>ls(Connection, Dir) -> {ok, Listing} | {error, Reason}</name> + <fsummary>Lists directory Dir.</fsummary> + <type> + <v>Connection = connection()</v> + <v>Dir = string()</v> + <v>Listing = string()</v> + </type> + <desc><marker id="ls-2"/> + <p>Lists directory <c>Dir</c>.</p> + </desc> + </func> + + <func> + <name>open(KeyOrName) -> {ok, Handle} | {error, Reason}</name> + <fsummary>Opens an FTP connection to the specified node.</fsummary> + <type> + <v>KeyOrName = Key | Name</v> + <v>Key = atom()</v> + <v>Name = target_name()</v> + <v>Handle = handle()</v> + </type> + <desc><marker id="open-1"/> + <p>Opens an FTP connection to the specified node.</p> + + <p>You can open a connection for a particular <c>Name</c> and use the + same name as reference for all following subsequent operations. + If you want + the connection to be associated with <c>Handle</c> instead (if you, + for example, need to open multiple connections to a host), use + <c>Key</c>, the configuration variable name, to specify the target. + A connection without an associated target name can only be closed + with the handle value.</p> + + <p>For information on how to create a new <c>Name</c>, see + <seealso marker="ct#require-2"><c>ct:require/2</c></seealso>.</p> + + <p>For <c>target_name</c>, see module + <seealso marker="ct"><c>ct</c></seealso>.</p> + </desc> + </func> + + <func> + <name>put(KeyOrName, LocalFile, RemoteFile) -> ok | {error, Reason}</name> + <fsummary>Opens an FTP connection and sends a file to the remote + host.</fsummary> + <type> + <v>KeyOrName = Key | Name</v> + <v>Key = atom()</v> + <v>Name = target_name()</v> + <v>LocalFile = string()</v> + <v>RemoteFile = string()</v> + </type> + <desc><marker id="put-3"/> + <p>Opens an FTP connection and sends a file to the remote host.</p> + + <p><c>LocalFile</c> and <c>RemoteFile</c> must be absolute paths.</p> + + <p>For <c>target_name</c>, see module + <seealso marker="ct"><c>ct</c></seealso>.</p> + + <p>If the target host is a "special" node, the FTP address must be + specified in the configuration file as follows:</p> + + <pre> + {node,[{ftp,IpAddr}]}.</pre> + + <p>If the target host is something else, for example, a UNIX host, + the configuration file must also include the username and password + (both strings):</p> + + <pre> + {unix,[{ftp,IpAddr}, + {username,Username}, + {password,Password}]}.</pre> + + <p>See also + <seealso marker="ct#require-2"><c>ct:require/2</c></seealso>.</p> + </desc> + </func> + + <func> + <name>recv(Connection, RemoteFile) -> ok | {error, Reason}</name> + <fsummary>Fetches a file over FTP.</fsummary> + <desc><marker id="recv-2"/> + <p>Fetches a file over FTP.</p> + + <p>The file gets the same name on the local host.</p> + + <p>See also <seealso marker="#recv-3"><c>ct_ftp:recv/3</c></seealso>.</p> + </desc> + </func> + + <func> + <name>recv(Connection, RemoteFile, LocalFile) -> ok | {error, Reason}</name> + <fsummary>Fetches a file over FTP.</fsummary> + <type> + <v>Connection = connection()</v> + <v>RemoteFile = string()</v> + <v>LocalFile = string()</v> + </type> + <desc><marker id="recv-3"/> + <p>Fetches a file over FTP.</p> + + <p>The file is named <c>LocalFile</c> on the local host.</p> + </desc> + </func> + + <func> + <name>send(Connection, LocalFile) -> ok | {error, Reason}</name> + <fsummary>Sends a file over FTP.</fsummary> + <desc><marker id="send-2"/> + <p>Sends a file over FTP.</p> + + <p>The file gets the same name on the remote host.</p> + + <p>See also + <seealso marker="#send-3"><c>ct_ftp:send/3</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send(Connection, LocalFile, RemoteFile) -> ok | {error, Reason}</name> + <fsummary>Sends a file over FTP.</fsummary> + <type> + <v>Connection = connection()</v> + <v>LocalFile = string()</v> + <v>RemoteFile = string()</v> + </type> + <desc><marker id="send-3"/> + <p>Sends a file over FTP.</p> + + <p>The file is named <c>RemoteFile</c> on the remote host.</p> + </desc> + </func> + + <func> + <name>type(Connection, Type) -> ok | {error, Reason}</name> + <fsummary>Changes the file transfer type.</fsummary> + <type> + <v>Connection = connection()</v> + <v>Type = ascii | binary</v> + </type> + <desc><marker id="type-2"/> + <p>Changes the file transfer type.</p> + </desc> + </func> + </funcs> + +</erlref> + + diff --git a/lib/common_test/doc/src/ct_hooks.xml b/lib/common_test/doc/src/ct_hooks.xml index a9f9450dd7..12ec3bcec3 100644 --- a/lib/common_test/doc/src/ct_hooks.xml +++ b/lib/common_test/doc/src/ct_hooks.xml @@ -1,5 +1,4 @@ <?xml version="1.0" encoding="UTF-8" ?> - <!DOCTYPE erlref SYSTEM "erlref.dtd"> <erlref> @@ -12,7 +11,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software @@ -34,539 +33,572 @@ <file>ct_hooks.sgml</file> </header> <module>ct_hooks</module> - <modulesummary>A callback interface on top of Common Test</modulesummary> + <modulesummary>A callback interface on top of Common Test.</modulesummary> <description> - <p>The <em>Common Test Hook</em> (henceforth called CTH) framework allows - extensions of the default behaviour of Common Test by means of callbacks - before and after all test suite calls. It is meant for advanced users of - Common Test which want to abstract out behaviour which is common to - multiple test suites. </p> + <p>The <em>Common Test Hook (CTH)</em> framework allows extensions of the + default behavior of <c>Common Test</c> by callbacks before and after all + test suite calls. It is intended for advanced users of <c>Common Test</c> + who want to abstract out behavior that is common to multiple test suites. + </p> - <p>In brief, Common Test Hooks allows you to:</p> + <p>In brief, CTH allows you to:</p> - <list> - <item>Manipulate the runtime config before each suite - configuration call</item> - <item>Manipulate the return of all suite configuration calls and in - extension the result of the test themselves.</item> + <list type="bulleted"> + <item><p>Manipulate the runtime configuration before each suite + configuration call.</p></item> + <item><p>Manipulate the return of all suite configuration calls and by + extension the result of the test themselves.</p></item> </list> <p>The following sections describe the mandatory and optional CTH - functions Common Test will call during test execution. For more details - see <seealso marker="ct_hooks_chapter">Common Test Hooks</seealso> in - the User's Guide.</p> + functions that <c>Common Test</c> calls during test execution. + For more details, see section + <seealso marker="ct_hooks_chapter">Common Test Hooks</seealso> in the + User's Guide.</p> - <p>For information about how to add a CTH to your suite see - <seealso marker="ct_hooks_chapter#installing">Installing a CTH - </seealso> in the User's Guide.</p> + <p>For information about how to add a CTH to your suite, see section + <seealso marker="ct_hooks_chapter#installing">Installing a CTH</seealso> + in the User's Guide.</p> + + <note><p>For a minimal example of a CTH, see section + <seealso marker="ct_hooks_chapter#example">Example CTH</seealso> + in the User's Guide.</p></note> - <note><p>See the - <seealso marker="ct_hooks_chapter#example">Example CTH</seealso> - in the User's Guide for a minimal example of a CTH. </p></note> - </description> <section> - <title>CALLBACK FUNCTIONS</title> - <p>The following functions define the callback interface - for a Common Test Hook.</p> + <title>Callback Functions</title> + <p>The following functions define the callback interface for a CTH.</p> </section> <funcs> <func> - <name>Module:init(Id, Opts) -> {ok, State} | - {ok, State, Priority}</name> - <fsummary>Initiates the Common Test Hook</fsummary> + <name>Module:init(Id, Opts) -> {ok, State} | {ok, State, Priority}</name> + <fsummary>Initiates the Common Test Hook.</fsummary> <type> - <v>Id = reference() | term()</v> - <v>Opts = term()</v> - <v>State = term()</v> - <v>Priority = integer()</v> + <v>Id = reference() | term()</v> + <v>Opts = term()</v> + <v>State = term()</v> + <v>Priority = integer()</v> </type> - <desc> - <p> MANDATORY </p> - - <p>Always called before any other callback function. - Use this to initiate any common state. - It should return a state for this CTH.</p> - - <p><c>Id</c> is the return value of - <seealso marker="#Module:id-1">id/1</seealso>, or a <c>reference</c> - (created using - <seealso marker="erts:erlang#make_ref-0">make_ref/0</seealso>) - if <seealso marker="#Module:id-1">id/1</seealso> is not implemented. - </p> - - <p><c>Priority</c> is the relative priority of this hook. Hooks with a - lower priority will be executed first. If no priority is given, - it will be set to 0. </p> - - <p>For details about when init is called see - <seealso marker="ct_hooks_chapter#scope">scope</seealso> - in the User's Guide.</p> - + <p>MANDATORY</p> + + <p>This function is always called before any other callback function. + Use it to initiate any common state. It is to return a state for + this CTH.</p> + + <p><c>Id</c> is either the return value of + <seealso marker="#Module:id-1"><c>ct_hooks:id/1</c></seealso>, + or a <c>reference</c> (created using + <seealso marker="erts:erlang#make_ref-0">erlang:make_ref/0</seealso> + in <c>ERTS</c>) if + <seealso marker="#Module:id-1"><c>ct_hooks:id/1</c></seealso> + is not implemented.</p> + + <p><c>Priority</c> is the relative priority of this hook. Hooks with a + lower priority are executed first. If no priority is specified, it + is set to <c>0</c>.</p> + + <p>For details about when <c>init</c> is called, see section + <seealso marker="ct_hooks_chapter#scope">CTH Scope</seealso> + in the User's Guide.</p> </desc> </func> <func> - <name>Module:pre_init_per_suite(SuiteName, InitData, CTHState) -> - Result</name> - <fsummary>Called before init_per_suite</fsummary> + <name>Module:pre_init_per_suite(SuiteName, InitData, CTHState) -> Result</name> + <fsummary>Called before init_per_suite.</fsummary> <type> - <v>SuiteName = atom()</v> - <v>InitData = Config | SkipOrFail</v> - <v>Config = NewConfig = [{Key,Value}]</v> - <v>CTHState = NewCTHState = term()</v> - <v>Result = {Return, NewCTHState}</v> - <v>Return = NewConfig | SkipOrFail</v> - <v>SkipOrFail = {fail, Reason} | {skip, Reason}</v> - <v>Key = atom()</v> - <v>Value = term()</v> - <v>Reason = term()</v> + <v>SuiteName = atom()</v> + <v>InitData = Config | SkipOrFail</v> + <v>Config = NewConfig = [{Key,Value}]</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {Return, NewCTHState}</v> + <v>Return = NewConfig | SkipOrFail</v> + <v>SkipOrFail = {fail, Reason} | {skip, Reason}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>This function is called before - <seealso marker="common_test#Module:init_per_suite-1"> - init_per_suite</seealso> if it exists. - It typically contains initialization/logging which needs to be done - before init_per_suite is called. - If <c>{skip,Reason}</c> or <c>{fail,Reason}</c> is returned, - init_per_suite and all test cases of the suite will be skipped and - Reason printed in the overview log of the suite.</p> - - <p><c>SuiteName</c> is the name of the suite to be run.</p> - - <p><c>InitData</c> is the original config list of the test suite, or - a <c>SkipOrFail</c> tuple if a previous CTH has returned this.</p> - - <p><c>CTHState</c> is the current internal state of the CTH.</p> - - <p><c>Return</c> is the result of the init_per_suite function. - If it is <c>{skip,Reason}</c> or <c>{fail,Reason}</c> - <seealso marker="common_test#Module:init_per_suite-1">init_per_suite - </seealso> will never be called, instead the initiation is considered - to be skipped/failed respectively. If a <c>NewConfig</c> list - is returned, <seealso marker="common_test#Module:init_per_suite-1"> - init_per_suite</seealso> will be called with that <c>NewConfig</c> list. - See <seealso marker="ct_hooks_chapter#pre"> - Pre Hooks</seealso> in the User's Guide for more details.</p> - - - <p>Note that this function is only called if the CTH has been added - before init_per_suite is run, see - <seealso marker="ct_hooks_chapter#scope">CTH Scoping</seealso> - in the User's Guide for details.</p> + <p>OPTIONAL</p> + + <p>This function is called before + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso> + if it exists. It typically contains initialization/logging that must + be done before <c>init_per_suite</c> is called. If + <c>{skip,Reason}</c> or <c>{fail,Reason}</c> is returned, + <c>init_per_suite</c> and all test cases of the suite are skipped + and <c>Reason</c> printed in the overview log of the suite.</p> + + <p><c>SuiteName</c> is the name of the suite to be run.</p> + + <p><c>InitData</c> is the original configuration list of the test + suite, or a <c>SkipOrFail</c> tuple if a previous CTH has returned + this.</p> + + <p><c>CTHState</c> is the current internal state of the CTH.</p> + + <p><c>Return</c> is the result of the <c>init_per_suite</c> function. + If it is <c>{skip,Reason}</c> or <c>{fail,Reason}</c>, + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso> + is never called, instead the initiation is considered to be + skipped or failed, respectively. If a <c>NewConfig</c> list is + returned, + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso> + is called with that <c>NewConfig</c> list. For more details, see + section <seealso marker="ct_hooks_chapter#pre">Pre Hooks</seealso> + in the User's Guide.</p> + + <p>This function is called only if the CTH is added before + <c>init_per_suite is run</c>. For details, see section + <seealso marker="ct_hooks_chapter#scope">CTH Scope</seealso> + in the User's Guide.</p> </desc> </func> - + <func> - <name>Module:post_init_per_suite(SuiteName, Config, Return, CTHState) -> - Result</name> - <fsummary>Called after init_per_suite</fsummary> + <name>Module:post_init_per_suite(SuiteName, Config, Return, CTHState) -> Result</name> + <fsummary>Called after init_per_suite.</fsummary> <type> - <v>SuiteName = atom()</v> - <v>Config = [{Key,Value}]</v> - <v>Return = NewReturn = Config | SkipOrFail | term()</v> - <v>SkipOrFail = {fail, Reason} | {skip, Reason} | term()</v> - <v>CTHState = NewCTHState = term()</v> - <v>Result = {NewReturn, NewCTHState}</v> - <v>Key = atom()</v> - <v>Value = term()</v> - <v>Reason = term()</v> + <v>SuiteName = atom()</v> + <v>Config = [{Key,Value}]</v> + <v>Return = NewReturn = Config | SkipOrFail | term()</v> + <v>SkipOrFail = {fail, Reason} | {skip, Reason} | term()</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {NewReturn, NewCTHState}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> - <desc> - <p> OPTIONAL </p> + <p>OPTIONAL</p> + + <p>This function is called after + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso> + if it exists. It typically contains extra checks to ensure that all + the correct dependencies are started correctly.</p> + + <p><c>Return</c> is what + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso> + returned, that is, <c>{fail,Reason}</c>, <c>{skip,Reason}</c>, a + <c>Config</c> list, or a term describing how + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso> + failed.</p> + + <p><c>NewReturn</c> is the possibly modified return value of + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso>. + To recover from a failure in + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso>, + return <c>ConfigList</c> with the <c>tc_status</c> element removed. + For more details, see + <seealso marker="ct_hooks_chapter#post"> Post Hooks</seealso> in + section "Manipulating Tests" in the User's Guide.</p> + + <p><c>CTHState</c> is the current internal state of the CTH.</p> + + <p>This function is called only if the CTH is added before or in + <c>init_per_suite</c>. For details, see section + <seealso marker="ct_hooks_chapter#scope">CTH Scope</seealso> + in the User's Guide.</p> + </desc> + </func> - <p>This function is called after - <seealso marker="common_test#Module:init_per_suite-1"> - init_per_suite</seealso> if it exists. It typically contains extra - checks to make sure that all the correct dependencies have - been started correctly.</p> - - <p><c>Return</c> is what - <seealso marker="common_test#Module:init_per_suite-1">init_per_suite - </seealso> returned, i.e. {fail,Reason}, {skip,Reason}, a <c>Config</c> - list or a term describing how - <seealso marker="common_test#Module:init_per_suite-1">init_per_suite - </seealso> failed.</p> - - <p><c>NewReturn</c> is the possibly modified return value of - <seealso marker="common_test#Module:init_per_suite-1">init_per_suite - </seealso>. It is here possible to recover from a failure in - <seealso marker="common_test#Module:init_per_suite-1">init_per_suite - </seealso> by returning the <c>ConfigList</c> with the <c>tc_status</c> - element removed. See <seealso marker="ct_hooks_chapter#post"> - Post Hooks</seealso> in the User's Guide for more details.</p> - - <p><c>CTHState</c> is the current internal state of the CTH.</p> - - <p>Note that this function is only called if the CTH has been added - before or in init_per_suite, see - <seealso marker="ct_hooks_chapter#scope">CTH Scoping</seealso> - in the User's Guide for details.</p> + <func> + <name>Module:pre_init_per_group(GroupName, InitData, CTHState) -> Result</name> + <fsummary>Called before init_per_group.</fsummary> + <type> + <v>GroupName = atom()</v> + <v>InitData = Config | SkipOrFail</v> + <v>Config = NewConfig = [{Key,Value}]</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v> + <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> + </type> + <desc> + <p>OPTIONAL</p> + + <p>This function is called before + <seealso marker="common_test#Module:init_per_group-2"><c>init_per_group</c></seealso> + if it exists. It behaves the same way as + <seealso marker="ct_hooks#Module:pre_init_per_suite-3"><c>pre_init_per_suite</c></seealso>, + but for function + <seealso marker="common_test#Module:init_per_group-2"><c>init_per_group</c></seealso> + instead.</p> </desc> </func> - + <func> - <name>Module:pre_init_per_group(GroupName, InitData, CTHState) -> - Result</name> - <fsummary>Called before init_per_group</fsummary> + <name>Module:post_init_per_group(GroupName, Config, Return, CTHState) -> Result</name> + <fsummary>Called after init_per_group.</fsummary> <type> - <v>GroupName = atom()</v> - <v>InitData = Config | SkipOrFail</v> - <v>Config = NewConfig = [{Key,Value}]</v> - <v>CTHState = NewCTHState = term()</v> - <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v> - <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> - <v>Key = atom()</v> - <v>Value = term()</v> - <v>Reason = term()</v> + <v>GroupName = atom()</v> + <v>Config = [{Key,Value}]</v> + <v>Return = NewReturn = Config | SkipOrFail | term()</v> + <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {NewReturn, NewCTHState}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>This function is called before - <seealso marker="common_test#Module:init_per_group-2"> - init_per_group</seealso> if it exists. It behaves the same way as - <seealso marker="ct_hooks#Module:pre_init_per_suite-3"> - pre_init_per_suite</seealso>, but for the - <seealso marker="common_test#Module:init_per_group-2"> - init_per_group</seealso> instead.</p> + <p>OPTIONAL</p> + + <p>This function is called after + <seealso marker="common_test#Module:init_per_group-2"><c>init_per_group</c></seealso> + if it exists. It behaves the same way as + <seealso marker="ct_hooks#Module:post_init_per_suite-4"><c>post_init_per_suite</c></seealso>, + but for function + <seealso marker="common_test#Module:init_per_group-2"><c>init_per_group</c></seealso> + instead.</p> </desc> </func> - + <func> - <name>Module:post_init_per_group(GroupName, Config, Return, CTHState) -> - Result</name> - <fsummary>Called after init_per_group</fsummary> + <name>Module:pre_init_per_testcase(TestcaseName, InitData, CTHState) -> Result</name> + <fsummary>Called before init_per_testcase.</fsummary> <type> - <v>GroupName = atom()</v> - <v>Config = [{Key,Value}]</v> - <v>Return = NewReturn = Config | SkipOrFail | term()</v> - <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> - <v>CTHState = NewCTHState = term()</v> - <v>Result = {NewReturn, NewCTHState}</v> - <v>Key = atom()</v> - <v>Value = term()</v> - <v>Reason = term()</v> + <v>TestcaseName = atom()</v> + <v>InitData = Config | SkipOrFail</v> + <v>Config = NewConfig = [{Key,Value}]</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v> + <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>This function is called after - <seealso marker="common_test#Module:init_per_group-2"> - init_per_group</seealso> if it exists. It behaves the same way as - <seealso marker="ct_hooks#Module:post_init_per_suite-4"> - post_init_per_suite</seealso>, but for the - <seealso marker="common_test#Module:init_per_group-2"> - init_per_group</seealso> instead.</p> + <p>OPTIONAL</p> + + <p>This function is called before + <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase</c></seealso> + if it exists. It behaves the same way as + <seealso marker="ct_hooks#Module:pre_init_per_suite-3"><c>pre_init_per_suite</c></seealso>, + but for function + <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase</c></seealso> + instead.</p> + + <p>CTHs cannot be added here right now. That feature may be added in + a later release, but it would right now break backwards + compatibility.</p> </desc> </func> <func> - <name>Module:pre_init_per_testcase(TestcaseName, InitData, CTHState) -> - Result</name> - <fsummary>Called before init_per_testcase</fsummary> + <name>Module:post_init_per_testcase(TestcaseName, Config, Return, CTHState) -> Result</name> + <fsummary>Called after init_per_testcase.</fsummary> <type> - <v>TestcaseName = atom()</v> - <v>InitData = Config | SkipOrFail</v> - <v>Config = NewConfig = [{Key,Value}]</v> - <v>CTHState = NewCTHState = term()</v> - <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v> - <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> - <v>Key = atom()</v> - <v>Value = term()</v> - <v>Reason = term()</v> + <v>TestcaseName = atom()</v> + <v>Config = [{Key,Value}]</v> + <v>Return = NewReturn = Config | SkipOrFail | term()</v> + <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {NewReturn, NewCTHState}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>This function is called before - <seealso marker="common_test#Module:init_per_testcase-2"> - init_per_testcase</seealso> if it exists. It behaves the same way as - <seealso marker="ct_hooks#Module:pre_init_per_suite-3"> - pre_init_per_suite</seealso>, but for the - <seealso marker="common_test#Module:init_per_testcase-2"> - init_per_testcase</seealso> function instead.</p> - - <p>Note that it is not possible to add CTH's here right now, - that feature might be added later, - but it would right now break backwards compatibility.</p> + <p>OPTIONAL</p> + + <p>This function is called after + <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase</c></seealso> + if it exists. It behaves the same way as + <seealso marker="ct_hooks#Module:post_init_per_suite-4"><c>post_init_per_suite</c></seealso>, + but for function + <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase</c></seealso> + instead.</p> </desc> </func> <func> - <name>Module:post_end_per_testcase(TestcaseName, Config, Return, CTHState) - -> Result</name> - <fsummary>Called after end_per_testcase</fsummary> + <name>Module:pre_end_per_testcase(TestcaseName, InitData, CTHState) -> Result</name> + <fsummary>Called before end_per_testcase.</fsummary> <type> - <v>TestcaseName = atom()</v> - <v>Config = [{Key,Value}]</v> - <v>Return = NewReturn = Config | SkipOrFail | term()</v> - <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> - <v>CTHState = NewCTHState = term()</v> - <v>Result = {NewReturn, NewCTHState}</v> - <v>Key = atom()</v> - <v>Value = term()</v> - <v>Reason = term()</v> + <v>TestcaseName = atom()</v> + <v>InitData = Config</v> + <v>Config = NewConfig = [{Key,Value}]</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {NewConfig, NewCTHState}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>This function is called after - <seealso marker="common_test#Module:end_per_testcase-2"> - end_per_testcase</seealso> if it exists. It behaves the same way as - <seealso marker="ct_hooks#Module:post_init_per_suite-4"> - post_init_per_suite</seealso>, but for the - <seealso marker="common_test#Module:end_per_testcase-2"> - end_per_testcase</seealso> function instead.</p> + <p>OPTIONAL</p> + + <p>This function is called before + <seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso> + if it exists. It behaves the same way as + <seealso marker="ct_hooks#Module:pre_end_per_suite-3"><c>pre_end_per_suite</c></seealso>, + but for function + <seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso> + instead.</p> + + <p>This function can not change the result of the test case by returning skip or fail + tuples, but it may insert items in <c>Config</c> that can be read in + <c>end_per_testcase/2</c> or in <c>post_end_per_testcase/4</c>.</p> </desc> </func> <func> - <name>Module:pre_end_per_group(GroupName, EndData, CTHState) -> - Result</name> - <fsummary>Called before end_per_group</fsummary> + <name>Module:post_end_per_testcase(TestcaseName, Config, Return, CTHState) -> Result</name> + <fsummary>Called after end_per_testcase.</fsummary> <type> - <v>GroupName = atom()</v> - <v>EndData = Config | SkipOrFail</v> - <v>Config = NewConfig = [{Key,Value}]</v> - <v>CTHState = NewCTHState = term()</v> - <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v> - <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> - <v>Key = atom()</v> - <v>Value = term()</v> - <v>Reason = term()</v> + <v>TestcaseName = atom()</v> + <v>Config = [{Key,Value}]</v> + <v>Return = NewReturn = Config | SkipOrFail | term()</v> + <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {NewReturn, NewCTHState}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>This function is called before - <seealso marker="common_test#Module:end_per_group-2"> - end_per_group</seealso> if it exists. It behaves the same way as - <seealso marker="ct_hooks#Module:pre_init_per_suite-3"> - pre_init_per_suite</seealso>, but for the - <seealso marker="common_test#Module:end_per_group-2"> - end_per_group</seealso> function instead.</p> + <p>OPTIONAL</p> + + <p>This function is called after + <seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso> + if it exists. It behaves the same way as + <seealso marker="ct_hooks#Module:post_end_per_suite-4"><c>post_end_per_suite</c></seealso>, + but for function + <seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso> + instead.</p> + </desc> + </func> + + <func> + <name>Module:pre_end_per_group(GroupName, EndData, CTHState) -> Result</name> + <fsummary>Called before end_per_group.</fsummary> + <type> + <v>GroupName = atom()</v> + <v>EndData = Config | SkipOrFail</v> + <v>Config = NewConfig = [{Key,Value}]</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v> + <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> + </type> + <desc> + <p>OPTIONAL</p> + + <p>This function is called before + <seealso marker="common_test#Module:end_per_group-2"><c>end_per_group</c></seealso> + if it exists. It behaves the same way as + <seealso marker="ct_hooks#Module:pre_init_per_suite-3"><c>pre_init_per_suite</c></seealso>, + but for function + <seealso marker="common_test#Module:end_per_group-2"><c>end_per_group</c></seealso> + instead.</p> </desc> </func> <func> - <name>Module:post_end_per_group(GroupName, Config, Return, CTHState) -> - Result</name> - <fsummary>Called after end_per_group</fsummary> + <name>Module:post_end_per_group(GroupName, Config, Return, CTHState) -> Result</name> + <fsummary>Called after end_per_group.</fsummary> <type> - <v>GroupName = atom()</v> - <v>Config = [{Key,Value}]</v> - <v>Return = NewReturn = Config | SkipOrFail | term()</v> - <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> - <v>CTHState = NewCTHState = term()</v> - <v>Result = {NewReturn, NewCTHState}</v> - <v>Key = atom()</v> - <v>Value = term()</v> - <v>Reason = term()</v> + <v>GroupName = atom()</v> + <v>Config = [{Key,Value}]</v> + <v>Return = NewReturn = Config | SkipOrFail | term()</v> + <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {NewReturn, NewCTHState}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>This function is called after - <seealso marker="common_test#Module:end_per_group-2"> - end_per_group</seealso> if it exists. It behaves the same way as - <seealso marker="ct_hooks#Module:post_init_per_suite-4"> - post_init_per_suite</seealso>, but for the - <seealso marker="common_test#Module:end_per_group-2"> - end_per_group</seealso> function instead.</p> + <p>OPTIONAL</p> + + <p>This function is called after + <seealso marker="common_test#Module:end_per_group-2"><c>end_per_group</c></seealso> + if it exists. It behaves the same way as + <seealso marker="ct_hooks#Module:post_init_per_suite-4"><c>post_init_per_suite</c></seealso>, + but for function + <seealso marker="common_test#Module:end_per_group-2">end_per_group</seealso> + instead.</p> </desc> </func> <func> - <name>Module:pre_end_per_suite(SuiteName, EndData, CTHState) -> - Result</name> - <fsummary>Called before end_per_suite</fsummary> + <name>Module:pre_end_per_suite(SuiteName, EndData, CTHState) -> Result</name> + <fsummary>Called before end_per_suite.</fsummary> <type> - <v>SuiteName = atom()</v> - <v>EndData = Config | SkipOrFail</v> - <v>Config = NewConfig = [{Key,Value}]</v> - <v>CTHState = NewCTHState = term()</v> - <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v> - <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> - <v>Key = atom()</v> - <v>Value = term()</v> - <v>Reason = term()</v> + <v>SuiteName = atom()</v> + <v>EndData = Config | SkipOrFail</v> + <v>Config = NewConfig = [{Key,Value}]</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {NewConfig | SkipOrFail, NewCTHState}</v> + <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>This function is called before - <seealso marker="common_test#Module:end_per_suite-1"> - end_per_suite</seealso> if it exists. It behaves the same way as - <seealso marker="ct_hooks#Module:pre_init_per_suite-3"> - pre_init_per_suite</seealso>, but for the - <seealso marker="common_test#Module:end_per_suite-1"> - end_per_suite</seealso> function instead.</p> + <p>OPTIONAL</p> + + <p>This function is called before + <seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite</c></seealso> + if it exists. It behaves the same way as + <seealso marker="ct_hooks#Module:pre_init_per_suite-3"><c>pre_init_per_suite</c></seealso>, + but for function + <seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite</c></seealso> + instead.</p> </desc> </func> <func> - <name>Module:post_end_per_suite(SuiteName, Config, Return, CTHState) -> - Result</name> - <fsummary>Called after end_per_suite</fsummary> + <name>Module:post_end_per_suite(SuiteName, Config, Return, CTHState) -> Result</name> + <fsummary>Called after end_per_suite.</fsummary> <type> - <v>SuiteName = atom()</v> - <v>Config = [{Key,Value}]</v> - <v>Return = NewReturn = Config | SkipOrFail | term()</v> - <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> - <v>CTHState = NewCTHState = term()</v> - <v>Result = {NewReturn, NewCTHState}</v> - <v>Key = atom()</v> - <v>Value = term()</v> - <v>Reason = term()</v> + <v>SuiteName = atom()</v> + <v>Config = [{Key,Value}]</v> + <v>Return = NewReturn = Config | SkipOrFail | term()</v> + <v>SkipOrFail = {fail,Reason} | {skip, Reason}</v> + <v>CTHState = NewCTHState = term()</v> + <v>Result = {NewReturn, NewCTHState}</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>Reason = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>This function is called after - <seealso marker="common_test#Module:end_per_suite-1"> - end_per_suite</seealso> if it exists. It behaves the same way as - <seealso marker="ct_hooks#Module:post_init_per_suite-4"> - post_init_per_suite</seealso>, but for the - <seealso marker="common_test#Module:end_per_suite-1"> - end_per_suite</seealso> function instead.</p> + <p>OPTIONAL</p> + + <p>This function is called after + <seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite</c></seealso> + if it exists. It behaves the same way as + <seealso marker="ct_hooks#Module:post_init_per_suite-4"><c>post_init_per_suite</c></seealso>, + but for function + <seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite</c></seealso> + instead.</p> </desc> </func> <func> - <name>Module:on_tc_fail(TestName, Reason, CTHState) -> - NewCTHState</name> - <fsummary>Called after the CTH scope ends</fsummary> + <name>Module:on_tc_fail(TestName, Reason, CTHState) -> NewCTHState</name> + <fsummary>Called after the CTH scope ends.</fsummary> <type> - <v>TestName = init_per_suite | end_per_suite | - {init_per_group,GroupName} | {end_per_group,GroupName} | - {FuncName,GroupName} | FuncName</v> - <v>FuncName = atom()</v> - <v>GroupName = atom()</v> - <v>Reason = term()</v> - <v>CTHState = NewCTHState = term()</v> + <v>TestName = init_per_suite | end_per_suite | {init_per_group,GroupName} | {end_per_group,GroupName} | {FuncName,GroupName} | FuncName</v> + <v>FuncName = atom()</v> + <v>GroupName = atom()</v> + <v>Reason = term()</v> + <v>CTHState = NewCTHState = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>This function is called whenever a test case (or config function) - fails. It is called after the post function has been called for - the failed test case. I.e. if init_per_suite fails, this function - is called after - <seealso marker="#Module:post_init_per_suite-4"> - post_init_per_suite</seealso>, and if a test case fails, it is called - after <seealso marker="#Module:post_end_per_testcase-4"> - post_end_per_testcase</seealso>. If the failed test case belongs - to a test case group, the first argument is a tuple - <c>{FuncName,GroupName}</c>, otherwise simply the function name.</p> - - <p>The data which comes with the Reason follows the same format as the - <seealso marker="event_handler_chapter#failreason">FailReason - </seealso> in the <seealso marker="event_handler_chapter#tc_done">tc_done</seealso> event. - See <seealso marker="event_handler_chapter#events">Event Handling - </seealso> in the User's Guide for details.</p> + <p>OPTIONAL</p> + + <p>This function is called whenever a test case (or configuration + function) fails. It is called after the post function is called + for the failed test case, that is:</p> + + <list type="bulleted"> + <item><p>If <c>init_per_suite</c> fails, this function is called after + <seealso marker="#Module:post_init_per_suite-4"><c>post_init_per_suite</c></seealso>.</p></item> + <item><p>If a test case fails, this funcion is called after + <seealso marker="#Module:post_end_per_testcase-4"><c>post_end_per_testcase</c></seealso>.</p></item> + </list> + + <p>If the failed test case belongs to a test case group, the first + argument is a tuple <c>{FuncName,GroupName}</c>, otherwise only + the function name.</p> + + <p>The data that comes with <c>Reason</c> follows the same format as + <seealso marker="event_handler_chapter#failreason"><c>FailReason</c></seealso> + in event + <seealso marker="event_handler_chapter#tc_done"><c>tc_done</c></seealso>. + For details, see section + <seealso marker="event_handler_chapter#events">Event Handling</seealso> + in the User's Guide.</p> </desc> </func> <func> - <name>Module:on_tc_skip(TestName, Reason, CTHState) -> - NewCTHState</name> - <fsummary>Called after the CTH scope ends</fsummary> + <name>Module:on_tc_skip(TestName, Reason, CTHState) -> NewCTHState</name> + <fsummary>Called after the CTH scope ends.</fsummary> <type> - <v>TestName = init_per_suite | end_per_suite | - {init_per_group,GroupName} | {end_per_group,GroupName} | - {FuncName,GroupName} | FuncName</v> - <v>FuncName = atom()</v> - <v>GroupName = atom()</v> - <v>Reason = {tc_auto_skip | tc_user_skip, term()}</v> - <v>CTHState = NewCTHState = term()</v> + <v>TestName = init_per_suite | end_per_suite | {init_per_group,GroupName} | {end_per_group,GroupName} | {FuncName,GroupName} | FuncName</v> + <v>FuncName = atom()</v> + <v>GroupName = atom()</v> + <v>Reason = {tc_auto_skip | tc_user_skip, term()}</v> + <v>CTHState = NewCTHState = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>This function is called whenever a test case (or config function) - is skipped. It is called after the post function has been called - for the skipped test case. I.e. if init_per_group is skipped, this - function is called after - <seealso marker="#Module:post_init_per_group-4"> - post_init_per_group</seealso>, and if a test case is skipped, - it is called after - <seealso marker="#Module:post_end_per_testcase-4"> - post_end_per_testcase</seealso>. If the skipped test case belongs to a - test case group, the first argument is a tuple <c>{FuncName,GroupName}</c>, - otherwise simply the function name.</p> - - <p>The data which comes with the Reason follows the same format as - <seealso marker="event_handler_chapter#tc_auto_skip">tc_auto_skip - </seealso> and <seealso marker="event_handler_chapter#tc_user_skip"> - tc_user_skip</seealso> events. - See <seealso marker="event_handler_chapter#events">Event Handling - </seealso> in the User's Guide for details.</p> + <p>OPTIONAL</p> + + <p>This function is called whenever a test case (or configuration + function) is skipped. It is called after the post function is called + for the skipped test case, that is:</p> + + <list type="bulleted"> + <item><p>If <c>init_per_group</c> is skipped, this function is + called after + <seealso marker="#Module:post_init_per_group-4"><c>post_init_per_group</c></seealso>.</p></item> + <item><p>If a test case is skipped, this function is called after + <seealso marker="#Module:post_end_per_testcase-4"><c>post_end_per_testcase</c></seealso>.</p></item> + </list> + + <p>If the skipped test case belongs to a test case group, the first + argument is a tuple <c>{FuncName,GroupName}</c>, otherwise only + the function name.</p> + + <p>The data that comes with <c>Reason</c> follows the same format as + events + <seealso marker="event_handler_chapter#tc_auto_skip"><c>tc_auto_skip</c></seealso> + and + <seealso marker="event_handler_chapter#tc_user_skip"><c>tc_user_skip</c></seealso> + For details, see section + <seealso marker="event_handler_chapter#events">Event Handling</seealso> + in the User's Guide.</p> </desc> </func> <func> <name>Module:terminate(CTHState)</name> - <fsummary>Called after the CTH scope ends</fsummary> + <fsummary>Called after the CTH scope ends.</fsummary> <type> - <v>CTHState = term()</v> + <v>CTHState = term()</v> </type> - <desc> - <p> OPTIONAL </p> + <p>OPTIONAL</p> - <p>This function is called at the end of a CTH's - <seealso marker="ct_hooks_chapter#scope">scope</seealso>. - </p> + <p>This function is called at the end of a CTH + <seealso marker="ct_hooks_chapter#scope">scope</seealso>.</p> </desc> </func> <func> <name>Module:id(Opts) -> Id</name> - <fsummary>Called before the init function of a CTH</fsummary> + <fsummary>Called before the init function of a CTH.</fsummary> <type> - <v>Opts = term()</v> - <v>Id = term()</v> + <v>Opts = term()</v> + <v>Id = term()</v> </type> - <desc> - <p> OPTIONAL </p> - - <p>The <c>Id</c> is used to uniquely identify a CTH instance, - if two CTH's return the same <c>Id</c> the second CTH is ignored - and subsequent calls to the CTH will only be made to the first - instance. For more information see - <seealso marker="ct_hooks_chapter#installing">Installing a CTH - </seealso> in the User's Guide. - </p> - - <p>This function should NOT have any side effects as it might - be called multiple times by Common Test.</p> + <p>OPTIONAL</p> - <p>If not implemented the CTH will act as if this function returned a - call to <c>make_ref/0</c>.</p> - </desc> + <p>The <c>Id</c> identifies a CTH instance uniquely. If two CTHs return + the same <c>Id</c>, the second CTH is ignored and subsequent calls to + the CTH are only made to the first instance. For details, see section + <seealso marker="ct_hooks_chapter#installing">Installing a CTH</seealso> + in the User's Guide.</p> + + <p>This function is <em>not</em> to have any side effects, as it can + be called multiple times by <c>Common Test</c>.</p> + + <p>If not implemented, the CTH acts as if this function returned a call + to <c>make_ref/0</c>.</p> + </desc> </func> - </funcs> </erlref> diff --git a/lib/common_test/doc/src/ct_hooks_chapter.xml b/lib/common_test/doc/src/ct_hooks_chapter.xml index 3905e23dcc..3eb1945a61 100644 --- a/lib/common_test/doc/src/ct_hooks_chapter.xml +++ b/lib/common_test/doc/src/ct_hooks_chapter.xml @@ -34,28 +34,28 @@ <marker id="general"></marker> <title>General</title> <p> - The <em>Common Test Hook</em> (henceforth called CTH) framework allows - extensions of the default behaviour of Common Test by means of hooks - before and after all test suite calls. CTHs allow advanced Common Test - users to abstract out behaviour which is common to multiple test suites - without littering all test suites with library calls. Some example - usages are: logging, starting and monitoring external systems, - building C files needed by the tests and much more!</p> - - <p>In brief, Common Test Hooks allows you to:</p> - - <list> - <item>Manipulate the runtime config before each suite - configuration call</item> - <item>Manipulate the return of all suite configuration calls and in - extension the result of the test themselves.</item> + The <em>Common Test Hook (CTH)</em> framework allows + extensions of the default behavior of <c>Common Test</c> using hooks + before and after all test suite calls. CTHs allow advanced <c>Common Test</c> + users to abstract out behavior that is common to multiple test suites + without littering all test suites with library calls. this can be used + for logging, starting, and monitoring external systems, + building C files needed by the tests, and so on.</p> + + <p>In brief, CTH allows you to do the following:</p> + + <list type="bulleted"> + <item>Manipulate the runtime configuration before each suite + configuration call.</item> + <item>Manipulate the return of all suite configuration calls, and in + extension, the result of the tests themselves.</item> </list> - <p>The following sections describe how to use CTHs, when they are run - and how to manipulate your test results in a CTH</p> + <p>The following sections describe how to use CTHs, when they are run, + and how to manipulate the test results in a CTH.</p> - <warning><p>When executing within a CTH all timetraps are shutoff. So - if your CTH never returns, the entire test run will be stalled!</p> + <warning><p>When executing within a CTH, all timetraps are shut off. So + if your CTH never returns, the entire test run is stalled.</p> </warning> </section> @@ -63,144 +63,148 @@ <section> <marker id="installing"></marker> <title>Installing a CTH</title> - <p>There are multiple ways to install a CTH in your test run. You can do it - for all tests in a run, for specific test suites and for specific groups + <p>A CTH can be installed in multiple ways in your test run. You can do it + for all tests in a run, for specific test suites, and for specific groups within a test suite. If you want a CTH to be present in all test suites - within your test run there are three different ways to accomplish that. + within your test run, there are three ways to accomplish that, as follows: </p> - <list> + <list type="bulleted"> <item>Add <c>-ct_hooks</c> as an argument to <seealso marker="run_test_chapter#ct_run">ct_run</seealso>. - To add multiple CTHs using this method append them to each other - using the keyword <c>and</c>, i.e. + To add multiple CTHs using this method, append them to each other + using the keyword <c>and</c>, that is, <c>ct_run -ct_hooks cth1 [{debug,true}] and cth2 ...</c>.</item> - <item>Add the <c>ct_hooks</c> tag to your + <item>Add tag <c>ct_hooks</c> to your <seealso marker="run_test_chapter#test_specifications"> - Test Specification</seealso></item> - <item>Add the <c>ct_hooks</c> tag to your call to - <seealso marker="ct#run_test-1">ct:run_test/1</seealso></item> + Test Specification</seealso>.</item> + <item>Add tag <c>ct_hooks</c> to your call to + <seealso marker="ct#run_test-1">ct:run_test/1</seealso>.</item> </list> - <p>You can also add CTHs within a test suite. This is done by returning - <c>{ct_hooks,[CTH]}</c> in the config list from + <p>CTHs can also be added within a test suite. This is done by returning + <c>{ct_hooks,[CTH]}</c> in the configuration list from <seealso marker="common_test#Module:suite-0">suite/0</seealso>, <seealso marker="common_test#Module:init_per_suite-1"> - init_per_suite/1</seealso> or + init_per_suite/1</seealso>, or <seealso marker="common_test#Module:init_per_group-2"> - init_per_group/2</seealso>. <c>CTH</c> in this case can be either - only the module name of the CTH or a tuple with the module name and the - initial arguments and optionally the hook priority of the CTH. Eg: - <c>{ct_hooks,[my_cth_module]}</c> or - <c>{ct_hooks,[{my_cth_module,[{debug,true}]}]}</c> or - <c>{ct_hooks,[{my_cth_module,[{debug,true}],500}]}</c> - </p> + init_per_group/2</seealso>.</p> + + <p>In this case, <c>CTH</c> can either be only the module name of the CTH + or a tuple with the module name and the initial arguments, and optionally + the hook priority of the CTH. For example, one of the following:</p> + <list type="bulleted"> + <item><c>{ct_hooks,[my_cth_module]}</c></item> + <item><c>{ct_hooks,[{my_cth_module,[{debug,true}]}]}</c></item> + <item><c>{ct_hooks,[{my_cth_module,[{debug,true}],500}]}</c></item> + </list> <section> <title>Overriding CTHs</title> - <p>By default each installation of a CTH will cause a new instance of it - to be activated. This can cause problems if you want to be able to - override CTHs in test specifications while still having them in the - suite info function. The + <p>By default, each installation of a CTH causes a new instance of it + to be activated. This can cause problems if you want to override + CTHs in test specifications while still having them in the + suite information function. The <seealso marker="ct_hooks#Module:id-1">id/1</seealso> callback exists to address this problem. By returning the same - <c>id</c> in both places, Common Test knows that this CTH - has already been installed and will not try to install it again.</p> + <c>id</c> in both places, <c>Common Test</c> knows that this CTH + is already installed and does not try to install it again.</p> </section> <section> - <title>CTH Execution order</title> - <p>By default each CTH installed will be executed in the order which + <title>CTH Execution Order</title> + <p>By default, each CTH installed is executed in the order that they are installed for init calls, and then reversed for end calls. - This is not always wanted so common_test allows + This is not always desired, so <c>Common Test</c> allows the user to specify a priority for each hook. The priority can either - be specified in the CTH <seealso marker="ct_hooks#Module:init-2">init/2 - </seealso> function or when installing the hook. The priority given at - installation will override the priority returned by the CTH. </p> + be specified in the CTH function + <seealso marker="ct_hooks#Module:init-2">init/2</seealso> or when + installing the hook. The priority specified at installation overrides the + priority returned by the CTH.</p> </section> </section> <section> <marker id="scope"/> <title>CTH Scope</title> - <p>Once the CTH is installed into a certain test run it will be there until + <p>Once the CTH is installed into a certain test run it remains there until its scope is expired. The scope of a CTH depends on when it is - installed. - The <seealso marker="ct_hooks#Module:init-2">init/2</seealso> is - called at the beginning of the scope and the - <seealso marker="ct_hooks#Module:terminate-1">terminate/1 - </seealso> function is called when the scope ends.</p> + installed, see the following table. + Function <seealso marker="ct_hooks#Module:init-2">init/2</seealso> is + called at the beginning of the scope and function + <seealso marker="ct_hooks#Module:terminate-1">terminate/1</seealso> + is called when the scope ends.</p> <table> <row> - <cell><em>CTH Installed in</em></cell> + <cell><em>CTH installed in</em></cell> <cell><em>CTH scope begins before</em></cell> <cell><em>CTH scope ends after</em></cell> </row> <row> <cell><seealso marker="run_test_chapter#ct_run">ct_run</seealso></cell> - <cell>the first test suite is to be run.</cell> - <cell>the last test suite has been run.</cell> + <cell>the first test suite is to be run</cell> + <cell>the last test suite has been run</cell> </row> <row> <cell><seealso marker="ct#run_test-1">ct:run_test</seealso></cell> - <cell>the first test suite is to be run.</cell> - <cell>the last test suite has been run.</cell> + <cell>the first test suite is run</cell> + <cell>the last test suite has been run</cell> </row> <row> <cell><seealso marker="run_test_chapter#test_specifications"> Test Specification</seealso></cell> - <cell>the first test suite is to be run.</cell> - <cell>the last test suite has been run.</cell> + <cell>the first test suite is run</cell> + <cell>the last test suite has been run</cell> </row> <row> <cell><seealso marker="common_test#Module:suite-0">suite/0 </seealso></cell> <cell><seealso marker="ct_hooks#Module:pre_init_per_suite-3"> - pre_init_per_suite/3</seealso> is called.</cell> + pre_init_per_suite/3</seealso> is called</cell> <cell><seealso marker="ct_hooks#Module:post_end_per_suite-4"> - post_end_per_suite/4</seealso> has been called for that test suite.</cell> + post_end_per_suite/4</seealso> has been called for that test suite</cell> </row> <row> <cell><seealso marker="common_test#Module:init_per_suite-1"> init_per_suite/1</seealso></cell> <cell><seealso marker="ct_hooks#Module:post_init_per_suite-4"> - post_init_per_suite/4</seealso> is called.</cell> + post_init_per_suite/4</seealso> is called</cell> <cell><seealso marker="ct_hooks#Module:post_end_per_suite-4"> - post_end_per_suite/4</seealso> has been called for that test suite.</cell> + post_end_per_suite/4</seealso> has been called for that test suite</cell> </row> <row> <cell><seealso marker="common_test#Module:init_per_group-2"> init_per_group/2</seealso></cell> <cell><seealso marker="ct_hooks#Module:post_init_per_group-4"> - post_init_per_group/4</seealso> is called.</cell> + post_init_per_group/4</seealso> is called</cell> <cell><seealso marker="ct_hooks#Module:post_end_per_suite-4"> - post_end_per_group/4</seealso> has been called for that group.</cell> + post_end_per_group/4</seealso> has been called for that group</cell> </row> <tcaption>Scope of a CTH</tcaption> </table> <section> <title>CTH Processes and Tables</title> - <p>CTHs are run with the same process scoping as normal test suites - i.e. a different process will execute the init_per_suite hooks then the - init_per_group or per_testcase hooks. So if you want to spawn a - process in the CTH you cannot link with the CTH process as it will exit - after the post hook ends. Also if you for some reason need an ETS - table with your CTH, you will have to spawn a process which handles - it.</p> + <p>CTHs are run with the same process scoping as normal test suites, + that is, a different process executes the <c>init_per_suite</c> hooks then the + <c>init_per_group</c> or <c>per_testcase</c> hooks. So if you want to spawn a + process in the CTH, you cannot link with the CTH process, as it exits + after the post hook ends. Also, if you for some reason need an ETS + table with your CTH, you must spawn a process that handles it.</p> </section> <section> - <title>External configuration data and Logging</title> - <p>It's possible in the CTH to read configuration data values - by calling <seealso marker="ct#get_config-1"><c>ct:get_config/1/2/3</c></seealso> (as explained in the - <seealso marker="config_file_chapter#require_config_data"> - External configuration data</seealso> - chapter). The config variables in question must, as always, first have been - <c>required</c> by means of a suite-, group-, or test case info function, - or the <seealso marker="ct#require-1"><c>ct:require/1/2</c></seealso> function. Note that the latter can also be used - in CT hook functions.</p> - <p>The CT hook functions may call any of the logging functions available + <title>External Configuration Data and Logging</title> + <p>Configuration data values in the CTH can be read + by calling + <seealso marker="ct#get_config-1"><c>ct:get_config/1,2,3</c></seealso> + (as explained in section + <seealso marker="config_file_chapter#require_config_data">Requiring and Reading Configuration Data</seealso>). + The configuration variables in question must, as always, first have been + required by a suite-, group-, or test case information function, + or by function <seealso marker="ct#require-1"><c>ct:require/1/2</c></seealso>. + The latter can also be used in CT hook functions.</p> + <p>The CT hook functions can call any logging function in the <c>ct</c> interface to print information to the log files, or to add comments in the suite overview page. </p> @@ -209,306 +213,327 @@ </section> <section> - <marker id="manipulating"/> - <title>Manipulating tests</title> - <p>It is through CTHs possible to manipulate the results of tests and - configuration functions. The main purpose of doing this with CTHs is to - allow common patterns to be abstracted out from test test suites and applied to - multiple test suites without duplicating any code. All of the callback - functions for a CTH follow a common interface, this interface is - described below.</p> - - <p>Common Test will always call all available hook functions, even pre- and post - hooks for configuration functions that are not implemented in the suite. + <marker id="manipulating"/> + <title>Manipulating Tests</title> + <p>Through CTHs the results of tests and configuration functions can be manipulated. + The main purpose to do this with CTHs is to allow common + patterns to be abstracted out from test suites and applied to + multiple test suites without duplicating any code. All the callback + functions for a CTH follow a common interface described hereafter.</p> + + <p><c>Common Test</c> always calls all available hook functions, even pre- + and post hooks for configuration functions that are not implemented in the suite. For example, <c>pre_init_per_suite(x_SUITE, ...)</c> and - <c>post_init_per_suite(x_SUITE, ...)</c> will be called for test suite - <c>x_SUITE</c>, even if it doesn't export <c>init_per_suite/1</c>. This feature - makes it possible to use hooks as configuration fallbacks, or even - completely replace all configuration functions with hook functions.</p> + <c>post_init_per_suite(x_SUITE, ...)</c> are called for test suite + <c>x_SUITE</c>, even if it does not export <c>init_per_suite/1</c>. + With this feature hooks can be used as configuration fallbacks, and all + configuration functions can be replaced with hook functions.</p> <section> <marker id="pre"/> <title>Pre Hooks</title> <p> - It is possible in a CTH to hook in behaviour before - <seealso marker="common_test#Module:init_per_suite-1">init_per_suite</seealso>, - <seealso marker="common_test#Module:init_per_suite-1">init_per_group</seealso>, - <seealso marker="common_test#Module:init_per_suite-1">init_per_testcase</seealso>, - <seealso marker="common_test#Module:init_per_suite-1">end_per_group</seealso> and - <seealso marker="common_test#Module:init_per_suite-1">end_per_suite</seealso>. + In a CTH, the behavior can be hooked in before the following functions:</p> + + <list type="bulleted"> + <item><seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso></item> + <item><seealso marker="common_test#Module:init_per_group-2"><c>init_per_group</c></seealso></item> + <item><seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase</c></seealso></item> + <item><seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso></item> + <item><seealso marker="common_test#Module:end_per_group-2"><c>end_per_group</c></seealso></item> + <item><seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite</c></seealso></item> + </list> + + <p> This is done in the CTH functions called pre_<name of function>. - All of these functions take the same three arguments: <c>Name</c>, - <c>Config</c> and <c>CTHState</c>. The return value of the CTH function - is always a combination of an result for the suite/group/test and an - updated <c>CTHState</c>. If you want the test suite to continue on - executing you should return the config list which you want the test to - use as the result. If you for some reason want to skip/fail the test, - return a tuple with <c>skip</c> or <c>fail</c> and a reason as the - result. Example: - </p> - <code>pre_init_per_suite(SuiteName, Config, CTHState) -> - case db:connect() of - {error,_Reason} -> - {{fail, "Could not connect to DB"}, CTHState}; - {ok, Handle} -> - {[{db_handle, Handle} | Config], CTHState#state{ handle = Handle }} - end.</code> - <note><p>If using multiple CTHs, the first part of the return tuple will be - used as input for the next CTH. So in the case above the next CTH might + These functions take the same three arguments, <c>Name</c>, + <c>Config</c>, and <c>CTHState</c>. The return value of the CTH function + is always a combination of a result for the suite/group/test and an + updated <c>CTHState</c>.</p> + + <p>To let the test suite continue on executing, return the configuration + list that you want the test to use as the result. To skip or + fail the test, return a tuple with <c>skip</c> or <c>fail</c>, and a reason + as the result.</p> + + <p><em>Example:</em></p> + <code> + pre_init_per_suite(SuiteName, Config, CTHState) -> + case db:connect() of + {error,_Reason} -> + {{fail, "Could not connect to DB"}, CTHState}; + {ok, Handle} -> + {[{db_handle, Handle} | Config], CTHState#state{ handle = Handle }} + end.</code> + + <note><p>If you use multiple CTHs, the first part of the return tuple is + used as input for the next CTH. So in the previous example the next CTH can get <c>{fail,Reason}</c> as the second parameter. If you have many CTHs - which interact, it might be a good idea to not let each CTH return - <c>fail</c> or <c>skip</c>. Instead return that an action should be taken - through the <c>Config</c> list and implement a CTH which at the end takes - the correct action.</p></note> + interacting, do not let each CTH return <c>fail</c> or <c>skip</c>. + Instead, return that an action is to be taken through the <c>Config</c> + list and implement a CTH that, at the end, takes the correct action.</p></note> </section> <section> <marker id="post"/> <title>Post Hooks</title> - <p>It is also possible in a CTH to hook in behaviour after - <seealso marker="common_test#Module:init_per_suite-1">init_per_suite</seealso>, - <seealso marker="common_test#Module:init_per_suite-1">init_per_group</seealso>, - <seealso marker="common_test#Module:init_per_suite-1">end_per_testcase</seealso>, - <seealso marker="common_test#Module:init_per_suite-1">end_per_group</seealso> and - <seealso marker="common_test#Module:init_per_suite-1">end_per_suite</seealso>. - This is done in the CTH functions called post_<name of function>. - All of these function take the same four arguments: <c>Name</c>, - <c>Config</c>, <c>Return</c> and <c>CTHState</c>. <c>Config</c> in this + <p>In a CTH, behavior can be hooked in after the following functions:</p> + <list type="bulleted"> + <item><seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso></item> + <item><seealso marker="common_test#Module:init_per_group-2"><c>init_per_group</c></seealso></item> + <item><seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase</c></seealso></item> + <item><seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso></item> + <item><seealso marker="common_test#Module:end_per_group-2"><c>end_per_group</c></seealso></item> + <item><seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite</c></seealso></item> + </list> + + <p> + This is done in the CTH functions called <c>post_<name of function></c>. + These functions take the same four arguments, <c>Name</c>, + <c>Config</c>, <c>Return</c>, and <c>CTHState</c>. <c>Config</c> in this case is the same <c>Config</c> as the testcase is called with. <c>Return</c> is the value returned by the testcase. If the testcase - failed by crashing, <c>Return</c> will be + fails by crashing, <c>Return</c> is <c>{'EXIT',{{Error,Reason},Stacktrace}}</c>.</p> - <p>The return value of the CTH function is always a combination of an + <p>The return value of the CTH function is always a combination of a result for the suite/group/test and an updated <c>CTHState</c>. If - you want the callback to not affect the outcome of the test you should + you do not want the callback to affect the outcome of the test, return the <c>Return</c> data as it is given to the CTH. You can also - modify the result of the test. By returning the <c>Config</c> list - with the <c>tc_status</c> element removed you can recover from a test + modify the test result. By returning the <c>Config</c> list + with element <c>tc_status</c> removed, you can recover from a test failure. As in all the pre hooks, it is also possible to fail/skip - the test case in the post hook. Example: </p> - - <code>post_end_per_testcase(_TC, Config, {'EXIT',{_,_}}, CTHState) -> - case db:check_consistency() of - true -> - %% DB is good, pass the test. - {proplists:delete(tc_status, Config), CTHState}; - false -> - %% DB is not good, mark as skipped instead of failing - {{skip, "DB is inconsisten!"}, CTHState} - end; -post_end_per_testcase(_TC, Config, Return, CTHState) -> - %% Do nothing if tc does not crash. - {Return, CTHState}.</code> - - <note><p>Recovering from a testcase failure using CTHs should only be done as - a last resort. If used wrongly it could become very difficult to - determine which tests pass or fail in a test run</p></note> + the test case in the post hook.</p> + + <p><em>Example:</em></p> + <code> + post_end_per_testcase(_TC, Config, {'EXIT',{_,_}}, CTHState) -> + case db:check_consistency() of + true -> + %% DB is good, pass the test. + {proplists:delete(tc_status, Config), CTHState}; + false -> + %% DB is not good, mark as skipped instead of failing + {{skip, "DB is inconsisten!"}, CTHState} + end; + post_end_per_testcase(_TC, Config, Return, CTHState) -> + %% Do nothing if tc does not crash. + {Return, CTHState}.</code> + + <note><p>Do recover from a testcase failure using CTHs only a last resort. + If used wrongly, it can be very difficult to determine which tests that + pass or fail in a test run.</p></note> </section> <section> - <marker id="skip_n_fail"/> - <title>Skip and Fail hooks</title> + <title>Skip and Fail Hooks</title> <p> After any post hook has been executed for all installed CTHs, <seealso marker="ct_hooks#Module:on_tc_fail-3">on_tc_fail</seealso> - or <seealso marker="ct_hooks#Module:on_tc_fail-3">on_tc_skip</seealso> - might be called if the testcase failed or was skipped - respectively. You cannot affect the outcome of the tests any further at - this point. + or <seealso marker="ct_hooks#Module:on_tc_skip-3">on_tc_skip</seealso> + is called if the testcase failed or was skipped, respectively. + You cannot affect the outcome of the tests any further at this point. </p> </section> </section> <section> - <marker id="synchronizing"/> - <title>Synchronizing external user applications with Common Test</title> + <marker id="synchronizing"/> + <title>Synchronizing External User Applications with Common Test</title> <p>CTHs can be used to synchronize test runs with external user applications. - The init function may e.g. start and/or communicate with an application that - has the purpose of preparing the SUT for an upcoming test run, or maybe + The init function can, for example, start and/or communicate with an application that + has the purpose of preparing the SUT for an upcoming test run, or initialize a database for saving test data to during the test run. The - terminate function may similarly order such an application to reset the SUT + terminate function can similarly order such an application to reset the SUT after the test run, and/or tell the application to finish active sessions and terminate. Any system error- or progress reports generated during the init- or - termination stage will be saved in the - <seealso marker="run_test_chapter#pre_post_test_io_log">Pre- - and post test I/O log</seealso>. (This is also true for any printouts made + termination stage are saved in the + <seealso marker="run_test_chapter#pre_post_test_io_log">Pre- and Post Test I/O Log</seealso>. + (This is also true for any printouts made with <c>ct:log/2</c> and <c>ct:pal/2</c>).</p> - <p>In order to ensure that Common Test doesn't start executing tests, or + + <p>To ensure that <c>Common Test</c> does not start executing tests, or closes its log files and shuts down, before the external application - is ready for it, Common Test may be synchronized with the application. - During startup and shutdown, Common Test can be suspended, simply by + is ready for it, <c>Common Test</c> can be synchronized with the application. + During startup and shutdown, <c>Common Test</c> can be suspended, simply by having a CTH evaluate a <c>receive</c> expression in the init- or terminate function. The macros <c>?CT_HOOK_INIT_PROCESS</c> (the process executing the hook init function) and <c>?CT_HOOK_TERMINATE_PROCESS</c> (the process executing - the hook terminate function), each specifies the name of the correct Common Test - process to send a message to in order to return from the <c>receive</c>. + the hook terminate function) each specifies the name of the correct <c>Common Test</c> + process to send a message to. This is done to return from the <c>receive</c>. These macros are defined in <c>ct.hrl</c>. </p> </section> <section> - <marker id="example"/> + <marker id="example"/> <title>Example CTH</title> - <p>The CTH below will log information about a test run into a format - parseable by <seealso marker="kernel:file#consult-1">file:consult/1</seealso>. + <p>The following CTH logs information about a test run into a format + parseable by <seealso marker="kernel:file#consult-1">file:consult/1</seealso> + (in <c>Kernel</c>): </p> - <code>%%% @doc Common Test Example Common Test Hook module. --module(example_cth). - -%% Callbacks --export([id/1]). --export([init/2]). - --export([pre_init_per_suite/3]). --export([post_init_per_suite/4]). --export([pre_end_per_suite/3]). --export([post_end_per_suite/4]). - --export([pre_init_per_group/3]). --export([post_init_per_group/4]). --export([pre_end_per_group/3]). --export([post_end_per_group/4]). - --export([pre_init_per_testcase/3]). --export([post_end_per_testcase/4]). - --export([on_tc_fail/3]). --export([on_tc_skip/3]). - --export([terminate/1]). - --record(state, { file_handle, total, suite_total, ts, tcs, data }). - -%% @doc Return a unique id for this CTH. -id(Opts) -> - proplists:get_value(filename, Opts, "/tmp/file.log"). - -%% @doc Always called before any other callback function. Use this to initiate -%% any common state. -init(Id, Opts) -> - {ok,D} = file:open(Id,[write]), - {ok, #state{ file_handle = D, total = 0, data = [] }}. - -%% @doc Called before init_per_suite is called. -pre_init_per_suite(Suite,Config,State) -> - {Config, State#state{ suite_total = 0, tcs = [] }}. - -%% @doc Called after init_per_suite. -post_init_per_suite(Suite,Config,Return,State) -> - {Return, State}. - -%% @doc Called before end_per_suite. -pre_end_per_suite(Suite,Config,State) -> - {Config, State}. - -%% @doc Called after end_per_suite. -post_end_per_suite(Suite,Config,Return,State) -> - Data = {suites, Suite, State#state.suite_total, lists:reverse(State#state.tcs)}, - {Return, State#state{ data = [Data | State#state.data] , - total = State#state.total + State#state.suite_total } }. - -%% @doc Called before each init_per_group. -pre_init_per_group(Group,Config,State) -> - {Config, State}. - -%% @doc Called after each init_per_group. -post_init_per_group(Group,Config,Return,State) -> - {Return, State}. - -%% @doc Called after each end_per_group. -pre_end_per_group(Group,Config,State) -> - {Config, State}. - -%% @doc Called after each end_per_group. -post_end_per_group(Group,Config,Return,State) -> - {Return, State}. - -%% @doc Called before each test case. -pre_init_per_testcase(TC,Config,State) -> - {Config, State#state{ ts = now(), total = State#state.suite_total + 1 } }. - -%% @doc Called after each test case. -post_end_per_testcase(TC,Config,Return,State) -> - TCInfo = {testcase, TC, Return, timer:now_diff(now(), State#state.ts)}, - {Return, State#state{ ts = undefined, tcs = [TCInfo | State#state.tcs] } }. - -%% @doc Called after post_init_per_suite, post_end_per_suite, post_init_per_group, -%% post_end_per_group and post_end_per_testcase if the suite, group or test case failed. -on_tc_fail(TC, Reason, State) -> - State. - -%% @doc Called when a test case is skipped by either user action -%% or due to an init function failing. -on_tc_skip(TC, Reason, State) -> - State. - -%% @doc Called when the scope of the CTH is done -terminate(State) -> - io:format(State#state.file_handle, "~p.~n", - [{test_run, State#state.total, State#state.data}]), - file:close(State#state.file_handle), - ok.</code> + <code> + %%% @doc Common Test Example Common Test Hook module. + -module(example_cth). + + %% Callbacks + -export([id/1]). + -export([init/2]). + + -export([pre_init_per_suite/3]). + -export([post_init_per_suite/4]). + -export([pre_end_per_suite/3]). + -export([post_end_per_suite/4]). + + -export([pre_init_per_group/3]). + -export([post_init_per_group/4]). + -export([pre_end_per_group/3]). + -export([post_end_per_group/4]). + + -export([pre_init_per_testcase/3]). + -export([post_init_per_testcase/4]). + -export([pre_end_per_testcase/3]). + -export([post_end_per_testcase/4]). + + -export([on_tc_fail/3]). + -export([on_tc_skip/3]). + + -export([terminate/1]). + + -record(state, { file_handle, total, suite_total, ts, tcs, data }). + + %% @doc Return a unique id for this CTH. + id(Opts) -> + proplists:get_value(filename, Opts, "/tmp/file.log"). + + %% @doc Always called before any other callback function. Use this to initiate + %% any common state. + init(Id, Opts) -> + {ok,D} = file:open(Id,[write]), + {ok, #state{ file_handle = D, total = 0, data = [] }}. + + %% @doc Called before init_per_suite is called. + pre_init_per_suite(Suite,Config,State) -> + {Config, State#state{ suite_total = 0, tcs = [] }}. + + %% @doc Called after init_per_suite. + post_init_per_suite(Suite,Config,Return,State) -> + {Return, State}. + + %% @doc Called before end_per_suite. + pre_end_per_suite(Suite,Config,State) -> + {Config, State}. + + %% @doc Called after end_per_suite. + post_end_per_suite(Suite,Config,Return,State) -> + Data = {suites, Suite, State#state.suite_total, lists:reverse(State#state.tcs)}, + {Return, State#state{ data = [Data | State#state.data] , + total = State#state.total + State#state.suite_total } }. + + %% @doc Called before each init_per_group. + pre_init_per_group(Group,Config,State) -> + {Config, State}. + + %% @doc Called after each init_per_group. + post_init_per_group(Group,Config,Return,State) -> + {Return, State}. + + %% @doc Called before each end_per_group. + pre_end_per_group(Group,Config,State) -> + {Config, State}. + + %% @doc Called after each end_per_group. + post_end_per_group(Group,Config,Return,State) -> + {Return, State}. + + %% @doc Called before each init_per_testcase. + pre_init_per_testcase(TC,Config,State) -> + {Config, State#state{ ts = now(), total = State#state.suite_total + 1 } }. + + %% Called after each init_per_testcase (immediately before the test case). + post_init_per_testcase(TC,Config,Return,State) -> + {Return, State} + +%% @doc Called before each end_per_testcase (immediately after the test case). + pre_end_per_testcase(TC,Config,State) -> + {Config, State}. + + %% @doc Called after each end_per_testcase. + post_end_per_testcase(TC,Config,Return,State) -> + TCInfo = {testcase, TC, Return, timer:now_diff(now(), State#state.ts)}, + {Return, State#state{ ts = undefined, tcs = [TCInfo | State#state.tcs] } }. + + %% @doc Called after post_init_per_suite, post_end_per_suite, post_init_per_group, + %% post_end_per_group and post_end_per_testcase if the suite, group or test case failed. + on_tc_fail(TC, Reason, State) -> + State. + + %% @doc Called when a test case is skipped by either user action + %% or due to an init function failing. + on_tc_skip(TC, Reason, State) -> + State. + + %% @doc Called when the scope of the CTH is done + terminate(State) -> + io:format(State#state.file_handle, "~p.~n", + [{test_run, State#state.total, State#state.data}]), + file:close(State#state.file_handle), + ok.</code> </section> <section> - <marker id="builtin_cths"/> - <title>Built-in CTHs</title> - <p>Common Test is delivered with a couple of general purpose CTHs that - can be enabled by the user to provide some generic testing functionality. - Some of these are enabled by default when starting running common_test, - they can be disabled by setting <c>enable_builtin_hooks</c> to - <c>false</c> on the command line or in the test specification. In the - table below there is a list of all current CTHs which are delivered with - Common Test.</p> - - <table> - <row> - <cell align="left"><em>CTH Name</em></cell> - <cell align="left"><em>Is Built-in</em></cell> - <cell align="left"><em>Description</em></cell> - </row> - <row> - <cell align="left">cth_log_redirect</cell> - <cell align="left">yes</cell> - <cell align="left">Captures all error_logger and SASL logging events and prints them - to the current test case log. If an event can not be associated with a - testcase it will be printed in the common test framework log. This will - happen for testcases which are run in parallel and events which occur - inbetween testcases. You can configure the level of - <seealso marker="sasl:sasl_app">SASL</seealso> events report - using the normal SASL mechanisms. </cell> - </row> - <row> - <cell align="left">cth_surefire</cell> - <cell align="left">no</cell> - <cell align="left"><p>Captures all test results and outputs them as surefire - XML into a file. The file which is created is by default - called junit_report.xml. The file name can be changed by - setting the <c>path</c> option for this hook, e.g.</p> - - <code>-ct_hooks cth_surefire [{path,"/tmp/report.xml"}]</code> - - <p>If the <c>url_base</c> option is set, an additional - attribute named <c>url</c> will be added to each - <c>testsuite</c> and <c>testcase</c> XML element. The value will - be constructed from the <c>url_base</c> and a relative path - to the test suite or test case log respectively, e.g.</p> - - <code>-ct_hooks cth_surefire [{url_base, "http://myserver.com/"}]</code> - <p>will give a url attribute value similar to</p> - - <code>"http://myserver.com/[email protected]_11.19.39/ -x86_64-unknown-linux-gnu.my_test.logs/run.2012-12-12_11.19.39/suite.log.html"</code> - - <p>Surefire XML can for instance be used by Jenkins to display test - results.</p></cell> - </row> - </table> + <marker id="builtin_cths"/> + <title>Built-In CTHs</title> + <p><c>Common Test</c> is delivered with some general-purpose CTHs that + can be enabled by the user to provide generic testing functionality. + Some of these CTHs are enabled by default when <c>common_test</c> is started to run. + They can be disabled by setting <c>enable_builtin_hooks</c> to + <c>false</c> on the command line or in the test specification. The following + two CTHs are delivered with <c>Common Test</c>:</p> + + <taglist> + <tag><c>cth_log_redirect</c></tag> + <item> + <p>Built-in</p> + <p>Captures all <c>error_logger</c> and <c>SASL</c> logging + events and prints them to the current test case log. If an event cannot be + associated with a test case, it is printed in the <c>Common Test</c> framework log. + This happens for test cases running in parallel and events occuring + in-between test cases. You can configure the level of + <seealso marker="sasl:sasl_app"><c>SASL</c></seealso> events report + using the normal <c>SASL</c> mechanisms.</p> + </item> + <tag><c>cth_surefire</c></tag> + <item> + <p>Not built-in</p> + <p>Captures all test results and outputs them as surefire + XML into a file. The created file is by default + called <c>junit_report.xml</c>. The file name can be changed by + setting option <c>path</c> for this hook, for example:</p> + + <p><c>-ct_hooks cth_surefire [{path,"/tmp/report.xml"}]</c></p> + + <p>If option <c>url_base</c> is set, an extra + attribute named <c>url</c> is added to each + <c>testsuite</c> and <c>testcase</c> XML element. The value + is constructed from <c>url_base</c> and a relative path + to the test suite or test case log, respectively, for example:</p> + + <p><c>-ct_hooks cth_surefire [{url_base, "http://myserver.com/"}]</c></p> + + <p>gives an URL attribute value similar to</p> + + <p><c>"http://myserver.com/[email protected]_11.19.39/ +x86_64-unknown-linux-gnu.my_test.logs/run.2012-12-12_11.19.39/suite.log.html"</c></p> + + <p>Surefire XML can, for example, be used by Jenkins to display test + results.</p> + </item> + </taglist> </section> diff --git a/lib/common_test/doc/src/ct_master.xml b/lib/common_test/doc/src/ct_master.xml new file mode 100644 index 0000000000..06f9b04f1b --- /dev/null +++ b/lib/common_test/doc/src/ct_master.xml @@ -0,0 +1,220 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>ct_master</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>ct_master.xml</file> + </header> + <module>ct_master</module> + <modulesummary>Distributed test execution control for Common Test.</modulesummary> + +<description> + + <p>Distributed test execution control for <c>Common Test</c>.</p> + + <p>This module exports functions for running <c>Common Test</c> nodes on + multiple hosts in parallel.</p> + +</description> + + <funcs> + <func> + <name>abort() -> ok</name> + <fsummary>Stops all running tests.</fsummary> + <desc><marker id="abort-0"/> + <p>Stops all running tests.</p> + </desc> + </func> + + <func> + <name>abort(Nodes) -> ok</name> + <fsummary>Stops tests on specified nodes.</fsummary> + <type> + <v>Nodes = atom() | [atom()]</v> + </type> + <desc><marker id="abort-1"/> + <p>Stops tests on specified nodes.</p> + </desc> + </func> + + <func> + <name>basic_html(Bool) -> ok</name> + <fsummary>If set to true, the ct_master logs are written on a primitive + HTML format, not using the <c>Common Test</c> CSS style sheet.</fsummary> + <type> + <v>Bool = true | false</v> + </type> + <desc><marker id="basic_html-1"/> + <p>If set to <c>true</c>, the <c>ct_master logs</c> are written on a + primitive HTML format, not using the <c>Common Test</c> CSS style + sheet.</p> + </desc> + </func> + + <func> + <name>get_event_mgr_ref() -> MasterEvMgrRef</name> + <fsummary>Gets a reference to the <c>Common Test</c> master event + manager.</fsummary> + <type> + <v>MasterEvMgrRef = atom()</v> + </type> + <desc><marker id="get_event_mgr_ref-0"/> + <p>Gets a reference to the <c>Common Test</c> master event manager. + The reference can be used to, for example, add a user-specific + event handler while tests are running.</p> + + <p><em>Example:</em></p> + + <pre> + gen_event:add_handler(ct_master:get_event_mgr_ref(), my_ev_h, [])</pre> + </desc> + </func> + + <func> + <name>progress() -> [{Node, Status}]</name> + <fsummary>Returns test progress.</fsummary> + <type> + <v>Node = atom()</v> + <v>Status = finished_ok | ongoing | aborted | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="progress-0"/> + <p>Returns test progress. If <c>Status</c> is <c>ongoing</c>, tests + are running on the node and are not yet finished.</p> + </desc> + </func> + + <func> + <name>run(TestSpecs) -> ok</name> + <fsummary>Equivalent to run(TestSpecs, false, [], []).</fsummary> + <type> + <v>TestSpecs = string() | [SeparateOrMerged]</v> + </type> + <desc><marker id="run-1"/> + <p>Equivalent to <seealso marker="#run-4"><c>ct_master:run(TestSpecs, + false, [], [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>run(TestSpecs, InclNodes, ExclNodes) -> ok</name> + <fsummary>Equivalent to run(TestSpecs, false, InclNodes, ExclNodes). + </fsummary> + <type> + <v>TestSpecs = string() | [SeparateOrMerged]</v> + <v>SeparateOrMerged = string() | [string()]</v> + <v>InclNodes = [atom()]</v> + <v>ExclNodes = [atom()]</v> + </type> + <desc><marker id="run-3"/> + <p>Equivalent to <seealso marker="#run-4"><c>ct_master:run(TestSpecs, + false, InclNodes, ExclNodes)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>run(TestSpecs, AllowUserTerms, InclNodes, ExclNodes) -> ok</name> + <fsummary>Tests are spawned on the nodes as specified in TestSpecs. + </fsummary> + <type> + <v>TestSpecs = string() | [SeparateOrMerged]</v> + <v>SeparateOrMerged = string() | [string()]</v> + <v>AllowUserTerms = bool()</v> + <v>InclNodes = [atom()]</v> + <v>ExclNodes = [atom()]</v> + </type> + <desc><marker id="run-4"/> + <p>Tests are spawned on the nodes as specified in <c>TestSpecs</c>. + Each specification in <c>TestSpec</c> is handled separately. + However, it is also possible to specify a list of specifications to + be merged into one specification before the tests are executed. Any + test without a particular node specification is also executed on + the nodes in <c>InclNodes</c>. Nodes in the <c>ExclNodes</c> list + are excluded from the test.</p> + </desc> + </func> + + <func> + <name>run_on_node(TestSpecs, Node) -> ok</name> + <fsummary>Equivalent to run_on_node(TestSpecs, false, Node).</fsummary> + <type> + <v>TestSpecs = string() | [SeparateOrMerged]</v> + <v>SeparateOrMerged = string() | [string()]</v> + <v>Node = atom()</v> + </type> + <desc><marker id="run_on_node-2"/> + <p>Equivalent to + <seealso marker="#run_on_node-3"><c>ct_master:run_on_node(TestSpecs, + false, Node)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>run_on_node(TestSpecs, AllowUserTerms, Node) -> ok</name> + <fsummary>Tests are spawned on Node according to TestSpecs.</fsummary> + <type> + <v>TestSpecs = string() | [SeparateOrMerged]</v> + <v>SeparateOrMerged = string() | [string()]</v> + <v>AllowUserTerms = bool()</v> + <v>Node = atom()</v> + </type> + <desc><marker id="run_on_node-3"/> + <p>Tests are spawned on <c>Node</c> according to <c>TestSpecs</c>.</p> + </desc> + </func> + + <func> + <name>run_test(Node, Opts) -> ok</name> + <fsummary>Tests are spawned on Node using ct:run_test/1.</fsummary> + <type> + <v>Node = atom()</v> + <v>Opts = [OptTuples]</v> + <v>OptTuples = {config, CfgFiles} | {dir, TestDirs} | {suite, Suites} | {testcase, Cases} | {spec, TestSpecs} | {allow_user_terms, Bool} | {logdir, LogDir} | {event_handler, EventHandlers} | {silent_connections, Conns} | {cover, CoverSpecFile} | {cover_stop, Bool} | {userconfig, UserCfgFiles}</v> + <v>CfgFiles = string() | [string()]</v> + <v>TestDirs = string() | [string()]</v> + <v>Suites = atom() | [atom()]</v> + <v>Cases = atom() | [atom()]</v> + <v>TestSpecs = string() | [string()]</v> + <v>LogDir = string()</v> + <v>EventHandlers = EH | [EH]</v> + <v>EH = atom() | {atom(), InitArgs} | {[atom()], InitArgs}</v> + <v>InitArgs = [term()]</v> + <v>Conns = all | [atom()]</v> + </type> + <desc><marker id="run_test-2"/> + <p>Tests are spawned on <c>Node</c> using + <seealso marker="ct:run_test-1"><c>ct:run_test/1</c></seealso></p> + </desc> + </func> + </funcs> + +</erlref> + + diff --git a/lib/common_test/doc/src/ct_master_chapter.xml b/lib/common_test/doc/src/ct_master_chapter.xml index 16492f39b8..99555164e0 100644 --- a/lib/common_test/doc/src/ct_master_chapter.xml +++ b/lib/common_test/doc/src/ct_master_chapter.xml @@ -22,7 +22,7 @@ </legalnotice> - <title>Using Common Test for Large Scale Testing</title> + <title>Using Common Test for Large-Scale Testing</title> <prepared>Peter Andersson</prepared> <docno></docno> <date></date> @@ -33,217 +33,220 @@ <section> <marker id="general"></marker> <title>General</title> - <p>Large scale automated testing requires running multiple independent + <p>Large-scale automated testing requires running multiple independent test sessions in parallel. This is accomplished by running - a number of Common Test nodes on one or more hosts, testing - different target systems. Configuring, starting and controlling the + some <c>Common Test</c> nodes on one or more hosts, testing + different target systems. Configuring, starting, and controlling the test nodes independently can be a cumbersome operation. To aid - this kind of automated large scale testing, CT offers a master test - node component, CT Master, that handles central configuration and control - in a system of distributed CT nodes.</p> + this kind of automated large-scale testing, <c>Common Test</c> offers a master + test node component, <c>Common Test</c> Master, which handles central configuration and control + in a system of distributed <c>Common Test</c> nodes.</p> - <p>The CT Master server runs on one dedicated Erlang node and uses distributed - Erlang to communicate with any number of CT test nodes, each hosting a regular - CT server. Test specifications are used as input to specify what to test on which + <p>The <c>Common Test</c> Master server runs on one dedicated Erlang node and uses distributed + Erlang to communicate with any number of <c>Common Test</c> test nodes, each hosting a regular + <c>Common Test</c> server. Test specifications are used as input to specify what to test on which test nodes, using what configuration.</p> - <p>The CT Master server writes progress information to HTML log files similarly - to the regular CT server. The logs contain test statistics and links to the - log files written by each independent CT server.</p> + <p>The <c>Common Test</c> Master server writes progress information to HTML log files similarly + to the regular <c>Common Test</c> server. The logs contain test statistics and links to the + log files written by each independent <c>Common Test</c> server.</p> - <p>The CT master API is exported by the <c>ct_master</c> module.</p> + <p>The <c>Common Test</c> Master API is exported by module + <seealso marker="ct_master"><c>ct_master</c></seealso>.</p> </section> <section> - <title>Usage</title> - <p>CT Master requires all test nodes to be on the same network and share a common - file system. As of this date, CT Master can not start test nodes - automatically. The nodes must have been started in advance for CT Master to be + <title>Use</title> + <p><c>Common Test</c> Master requires all test nodes to be on the same network and share a common + file system. <c>Common Test</c> Master cannot start test nodes + automatically. The nodes must be started in advance for <c>Common Test</c> Master to be able to start test sessions on them.</p> - <p>Tests are started by calling:</p> - - <p><c>ct_master:run(TestSpecs)</c> or - <c>ct_master:run(TestSpecs, InclNodes, ExclNodes)</c></p> + <p>Tests are started by calling + <seealso marker="ct_master#run-1"><c>ct_master:run(TestSpecs)</c></seealso> or + <seealso marker="ct_master#run-3"><c>ct_master:run(TestSpecs, InclNodes, ExclNodes)</c></seealso></p> <p><c>TestSpecs</c> is either the name of a test specification file (string) or a list - of test specifications. In case of a list, the specifications will be handled (and + of test specifications. If it is a list, the specifications are handled (and the corresponding tests executed) in sequence. An element in a <c>TestSpecs</c> list - can also be list of test specifications. The specifications in such a list will be - merged into one combined specification prior to test execution. For example:</p> - - <p><c>ct_master:run(["ts1","ts2",["ts3","ts4"]])</c></p> + can also be list of test specifications. The specifications in such a list are + merged into one combined specification before test execution.</p> - <p>means first the tests specified by "ts1" will run, then the tests specified by "ts2" + <p><em>Example:</em></p> + <pre> + ct_master:run(["ts1","ts2",["ts3","ts4"]])</pre> + + <p>Here, the tests specified by "ts1" run first, then the tests specified by "ts2", and finally the tests specified by both "ts3" and "ts4".</p> - <p>The <c>InclNodes</c> argument to <c>run/3</c> is a list of node names. The <c>run/3</c> - function runs the tests in <c>TestSpecs</c> just like <c>run/1</c> but will also - take any test in <c>TestSpecs</c> that's not explicitly tagged with a particular - node name and execute it on the nodes listed in <c>InclNodes</c>. By using <c>run/3</c> - this way it is possible to use any test specification, with or without node information, - in a large scale test environment! <c>ExclNodes</c> is a list of nodes that should be - excluded from the test. I.e. tests that have been specified in the test specification - to run on a particular node will not be performed if that node is at runtime - listed in <c>ExclNodes</c>.</p> - - <p>If CT Master fails initially to connect to any of the test nodes specified in a - test specification or in the <c>InclNodes</c> list, the operator will be prompted with - the option to either start over again (after manually checking the status of the - node(s) in question), to run without the missing nodes, or to abort the operation.</p> + <p>The <c>InclNodes</c> argument to <c>run/3</c> is a list of node names. Function + <c>run/3</c> runs the tests in <c>TestSpecs</c> just like <c>run/1</c>, but also + takes any test in <c>TestSpecs</c>, which is not explicitly tagged with a particular + node name, and execute it on the nodes listed in <c>InclNodes</c>. By using <c>run/3</c> + this way, any test specification can be used, with or without node information, + in a large-scale test environment.</p> + + <p><c>ExclNodes</c> is a list of nodes to be + excluded from the test. That is, tests that are specified in the test specification + to run on a particular node are not performed if that node is + listed in <c>ExclNodes</c> at runtime.</p> - <p>When tests start, CT Master prints information to console about the nodes that are - involved. CT Master also reports when tests finish, successfully or unsuccessfully. If - connection is lost to a node, the test on that node is considered finished. CT Master - will not attempt to reestablish contact with the failing node. At any time to get the - current status of the test nodes, call the function:</p> + <p>If <c>Common Test</c> Master fails initially to connect to any of the test nodes specified in a + test specification or in the <c>InclNodes</c> list, the operator is prompted with + the option to either start over again (after manually checking the status of the + nodes in question), to run without the missing nodes, or to abort the operation.</p> - <p><c>ct_master:progress()</c></p> + <p>When tests start, <c>Common Test</c> Master displays information to console about the involved nodes. + <c>Common Test</c> Master also reports when tests finish, successfully or unsuccessfully. If + connection is lost to a node, the test on that node is considered finished. <c>Common Test</c> Master + does not attempt to re-establish contact with the failing node.</p> - <p>To stop one or more tests, use:</p> + <p>At any time, to get the current status of the test nodes, call function + <seealso marker="ct_master#progress-0"><c>ct_master:progress()</c></seealso>.</p> - <p><c>ct_master:abort()</c> (stop all) or <c>ct_master:abort(Nodes)</c></p> + <p>To stop one or more tests, use function + <seealso marker="ct_master#abort-0"><c>ct_master:abort()</c></seealso> (to stop all) or + <seealso marker="ct_master#abort-1"><c>ct_master:abort(Nodes)</c></seealso>.</p> - <p>For detailed information about the <c>ct_master</c> API, please see the - <seealso marker="ct_master">manual page</seealso> for this module.</p> + <p>For details about the <c>Common Test</c> Master API, see module + <seealso marker="ct_master"><c>ct_master</c></seealso>.</p> </section> <section> <marker id="test_specifications"></marker> <title>Test Specifications</title> - <p>The test specifications used as input to CT Master are fully compatible with the - specifications used as input to the regular CT server. The syntax is described in the - <seealso marker="run_test_chapter#test_specifications">Running Test Suites</seealso> - chapter.</p> + <p>The test specifications used as input to <c>Common Test</c> Master are fully compatible with the + specifications used as input to the regular <c>Common Test</c> server. The syntax is described in section + <seealso marker="run_test_chapter#test_specifications">Test Specifications</seealso> + in section Running Tests and Analyzing Results.</p> <p>All test specification terms can have a <c>NodeRefs</c> element. This element specifies which node or nodes a configuration operation or a test is to be executed - on. <c>NodeRefs</c> is defined as:</p> + on. <c>NodeRefs</c> is defined as follows:</p> <p><c>NodeRefs = all_nodes | [NodeRef] | NodeRef</c></p> - - <p>where</p> <p><c>NodeRef = NodeAlias | node() | master</c></p> <p>A <c>NodeAlias</c> (<c>atom()</c>) is used in a test specification as a - reference to a node name (so the actual node name only needs to be declared once, - which can of course also be achieved using constants). - The alias is declared with a <c>node</c> term:</p> + reference to a node name (so the node name only needs to be declared once, + which also can be achieved using constants). + The alias is declared with a <c>node</c> term as follows:</p> <p><c>{node, NodeAlias, NodeName}</c></p> - <p>If <c>NodeRefs</c> has the value <c>all_nodes</c>, the operation or test will - be performed on all given test nodes. (Declaring a term without a <c>NodeRefs</c> - element actually has the same effect). If <c>NodeRefs</c> has the value - <c>master</c>, the operation is only performed on the CT Master node (namely set + <p>If <c>NodeRefs</c> has the value <c>all_nodes</c>, the operation or test + is performed on all specified test nodes. (Declaring a term without a <c>NodeRefs</c> + element has the same effect). If <c>NodeRefs</c> has the value + <c>master</c>, the operation is only performed on the <c>Common Test</c> Master node (namely set the log directory or install an event handler).</p> - <p>Consider the example in the - <seealso marker="run_test_chapter#test_specifications">Running Test Suites</seealso> - chapter, now extended with node information and intended to be executed by the - CT Master:</p> + <p>Consider the example in section + <seealso marker="run_test_chapter#test_specifications">Test Specifications</seealso> + in section Running Tests and Analysing Results, + now extended with node information and intended to be executed by + <c>Common Test</c> Master:</p> <pre> - {define, 'Top', "/home/test"}. - {define, 'T1', "'Top'/t1"}. - {define, 'T2', "'Top'/t2"}. - {define, 'T3', "'Top'/t3"}. - {define, 'CfgFile', "config.cfg"}. - {define, 'Node', ct_node}. - - {node, node1, 'Node@host_x'}. - {node, node2, 'Node@host_y'}. - - {logdir, master, "'Top'/master_logs"}. - {logdir, "'Top'/logs"}. - - {config, node1, "'T1'/'CfgFile'"}. - {config, node2, "'T2'/'CfgFile'"}. - {config, "'T3'/'CfgFile'"}. - - {suites, node1, 'T1', all}. - {skip_suites, node1, 'T1', [t1B_SUITE,t1D_SUITE], "Not implemented"}. - {skip_cases, node1, 'T1', t1A_SUITE, [test3,test4], "Irrelevant"}. - {skip_cases, node1, 'T1', t1C_SUITE, [test1], "Ignore"}. - - {suites, node2, 'T2', [t2B_SUITE,t2C_SUITE]}. - {cases, node2, 'T2', t2A_SUITE, [test4,test1,test7]}. - - {skip_suites, 'T3', all, "Not implemented"}.</pre> + {define, 'Top', "/home/test"}. + {define, 'T1', "'Top'/t1"}. + {define, 'T2', "'Top'/t2"}. + {define, 'T3', "'Top'/t3"}. + {define, 'CfgFile', "config.cfg"}. + {define, 'Node', ct_node}. + + {node, node1, 'Node@host_x'}. + {node, node2, 'Node@host_y'}. + + {logdir, master, "'Top'/master_logs"}. + {logdir, "'Top'/logs"}. + + {config, node1, "'T1'/'CfgFile'"}. + {config, node2, "'T2'/'CfgFile'"}. + {config, "'T3'/'CfgFile'"}. + + {suites, node1, 'T1', all}. + {skip_suites, node1, 'T1', [t1B_SUITE,t1D_SUITE], "Not implemented"}. + {skip_cases, node1, 'T1', t1A_SUITE, [test3,test4], "Irrelevant"}. + {skip_cases, node1, 'T1', t1C_SUITE, [test1], "Ignore"}. + + {suites, node2, 'T2', [t2B_SUITE,t2C_SUITE]}. + {cases, node2, 'T2', t2A_SUITE, [test4,test1,test7]}. + + {skip_suites, 'T3', all, "Not implemented"}.</pre> <p>This example specifies the same tests as the original example. But - now if started with a call to <c>ct_master:run(TestSpecName)</c>, the - t1 test will be executed on node <c>ct_node@host_x</c> (node1), the - t2 test on <c>ct_node@host_y</c> (node2) and the t3 test on both - node1 and node2. The t1 config file will only be read on - node1 and the t2 config file only on node2, while the t3 config file - will be read on both node1 and node2. Both test nodes will write log - files to the same directory. (The CT Master node will however use a - different log directory than the test nodes).</p> + now if started with a call to <c>ct_master:run(TestSpecName)</c>, test + <c>t1</c> is executed on node <c>ct_node@host_x</c> (<c>node1</c>), test + <c>t2</c> on <c>ct_node@host_y</c> (<c>node2</c>) and test <c>t3</c> + on both <c>node1</c> and <c>node2</c>. Configuration file <c>t1</c> is only read on + <c>node1</c> and configuration file <c>t2</c> only on <c>node2</c>, while the + configuration file <c>t3</c> is read on both <c>node1</c> and <c>node2</c>. + Both test nodes write log files to the same directory. (However, the <c>Common Test</c> Master + node uses a different log directory than the test nodes.)</p> <p>If the test session is instead started with a call to <c>ct_master:run(TestSpecName, [ct_node@host_z], [ct_node@host_x])</c>, - the result is that the t1 test does not run on - <c>ct_node@host_x</c> (or any other node) while the t3 test runs on + the result is that test <c>t1</c> does not run on + <c>ct_node@host_x</c> (or any other node) while test <c>t3</c> runs on both <c>ct_node@host_y</c> and <c>ct_node@host_z</c>.</p> <p>A nice feature is that a test specification that includes node - information can still be used as input to the regular Common Test server - (as described in the - <seealso marker="run_test_chapter#test_specifications">Running Test Suites</seealso> - chapter). The result is that any test specified to run on a node with the same - name as the Common Test node in question (typically <c>ct@somehost</c> if started - with the <c>ct_run</c> program), will be performed. Tests without explicit - node association will always be performed too of course!</p> + information can still be used as input to the regular <c>Common Test</c> server + (as described in section + <seealso marker="run_test_chapter#test_specifications">Test Specifications</seealso>). + The result is that any test specified to run on a node with the same + name as the <c>Common Test</c> node in question (typically <c>ct@somehost</c> if started + with the <c>ct_run</c> program), is performed. Tests without explicit + node association are always performed too, of course.</p> </section> <section> - <title>Automatic startup of test target nodes</title> + <title>Automatic Startup of Test Target Nodes</title> <marker id="ct_slave"></marker> - <p>It is possible to automatically start, and perform initial actions, on - test target nodes by using the test specification term <c>init</c>.</p> - <p>Currently, two sub-terms are supported, <c>node_start</c> and <c>eval</c>.</p> - <p>Example:</p> + <p>Initial actions can be started and performed automatically on + test target nodes using test specification term <c>init</c>.</p> + <p>Two subterms are supported, <c>node_start</c> and <c>eval</c>.</p> + <p><em>Example:</em></p> <pre> - {node, node1, node1@host1}. - {node, node2, node1@host2}. - {node, node3, node2@host2}. - {node, node4, node1@host3}. - {init, node1, [{node_start, [{callback_module, my_slave_callback}]}]}. - {init, [node2, node3], {node_start, [{username, "ct_user"}, {password, "ct_password"}]}}. - {init, node4, {eval, {module, function, []}}}.</pre> + {node, node1, node1@host1}. + {node, node2, node1@host2}. + {node, node3, node2@host2}. + {node, node4, node1@host3}. + {init, node1, [{node_start, [{callback_module, my_slave_callback}]}]}. + {init, [node2, node3], {node_start, [{username, "ct_user"}, {password, "ct_password"}]}}. + {init, node4, {eval, {module, function, []}}}.</pre> <p>This test specification declares that <c>node1@host1</c> is to be started using the user callback function <c>callback_module:my_slave_callback/0</c>, and nodes - <c>node1@host2</c> and <c>node2@host2</c> will be started with the default callback - module <c>ct_slave</c>. The given user name and password is used to log into remote - host <c>host2</c>. Also, the function <c>module:function/0</c> will be evaluated on - <c>node1@host3</c>, and the result of this call will be printed to the log.</p> + <c>node1@host2</c> and <c>node2@host2</c> are to be started with the default callback + module <c>ct_slave</c>. The specified username and password are used to log on to remote + host <c>host2</c>. Also, function <c>module:function/0</c> is evaluated on + <c>node1@host3</c>, and the result of this call is printed to the log.</p> - <p>The default <seealso marker="ct_slave">ct_slave</seealso> callback module, - which is part of the Common Test application, has the following features: + <p>The default callback module <seealso marker="ct_slave">ct_slave</seealso>, + has the following features: </p> - <list> + <list type="bulleted"> <item>Starting Erlang target nodes on local or remote hosts - (ssh is used for communication). + (application <c>SSH</c> is used for communication). </item> - <item>Ability to start an Erlang emulator with additional flags + <item>Ability to start an Erlang emulator with more flags (any flags supported by <c>erl</c> are supported). </item> - <item>Supervision of a node being started by means of internal callback - functions. Used to prevent hanging nodes. (Configurable). + <item>Supervision of a node being started using internal callback + functions. Used to prevent hanging nodes. (Configurable.) </item> - <item>Monitoring of the master node by the slaves. A slave node may be - stopped in case the master node terminates. (Configurable). + <item>Monitoring of the master node by the slaves. A slave node can be + stopped if the master node terminates. (Configurable.) </item> - <item>Execution of user functions after a slave node is started. - Functions can be given as a list of {Module, Function, Arguments} tuples. + <item>Execution of user functions after a slave node is started. Functions can + be specified as a list of <c>{Module, Function, Arguments}</c> tuples. </item> </list> - <p>Note that it is possible to specify an <c>eval</c> term for the node as well - as <c>startup_functions</c> in the <c>node_start</c> options list. In this - case first the node will be started, then the <c>startup_functions</c> are + <note><p>An <c>eval</c> term for the node and + <c>startup_functions</c> in the <c>node_start</c> options list can be specified. + In this case, the node is started first, then the <c>startup_functions</c> are executed, and finally functions specified with <c>eval</c> are called. - </p> + </p></note> </section> </chapter> diff --git a/lib/common_test/doc/src/ct_netconfc.xml b/lib/common_test/doc/src/ct_netconfc.xml new file mode 100644 index 0000000000..d8c82c7f2c --- /dev/null +++ b/lib/common_test/doc/src/ct_netconfc.xml @@ -0,0 +1,1039 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>ct_netconfc</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>ct_netconfc.xml</file> + </header> + <module>ct_netconfc</module> + <modulesummary>NETCONF client module.</modulesummary> + +<description> + + <p>NETCONF client module.</p> + + <p>The NETCONF client is compliant with RFC 4741 NETCONF Configuration + Protocol and RFC 4742 Using the NETCONF Configuration Protocol over + Secure SHell (SSH)..</p> + + <p>For each server to test against, the following entry can be added to a + configuration file:</p> + + <pre> + {server_id(),options()}.</pre> + + <p>The <c>server_id()</c> or an associated <c>target_name()</c> (see + module <seealso marker="ct"><c>ct</c></seealso>) must then be used + in calls to + <seealso marker="#open-2"><c>ct_netconfc:open/2</c></seealso>.</p> + + <p>If no configuration exists for a server, a session can still be + opened by calling + <seealso marker="#open-2"><c>ct_netconfc:open/2</c></seealso> with + all necessary options specified in the call. The first argument to + <seealso marker="#open-2"><c>ct_netconfc:open/2</c></seealso> can + then be any atom.</p> + + </description> + + <section> + <marker id="Logging"/> + <title>Logging</title> + <p>The NETCONF server uses <c>error_logger</c> for logging of NETCONF + traffic. A special purpose error handler is implemented in + <c>ct_conn_log_h</c>. To use this error handler, add the + <c>cth_conn_log</c> hook in the test suite, for example:</p> + + <pre> + suite() -> + [{ct_hooks, [{cth_conn_log, [{conn_mod(),hook_options()}]}]}].</pre> + + <p><c>conn_mod()</c> is the name of the <c>Common Test</c> module + implementing the connection protocol, for example, <c>ct_netconfc</c>.</p> + + <p>Hook option <c>log_type</c> specifies the type of logging:</p> + + <taglist> + <tag><c>raw</c></tag> + <item><p>The sent and received NETCONF data is logged to a separate + text file "as is" without any formatting. A link to the file is + added to the test case HTML log.</p>.</item> + + <tag><c>pretty</c></tag> + <item><p>The sent and received NETCONF data is logged to a separate + text file with XML data nicely indented. A link to the file is + added to the test case HTML log.</p></item> + + <tag><c>html (default)</c></tag> + <item><p>The sent and received NETCONF traffic is pretty printed + directly in the test case HTML log.</p></item> + + <tag><c>silent</c></tag> + <item><p>NETCONF traffic is not logged.</p></item> + </taglist> + + <p>By default, all NETCONF traffic is logged in one single log file. + However, different connections can be logged in separate files. + To do this, use hook option <c>hosts</c> and list the names of the + servers/connections to be used in the suite. The connections + must be named for this to work, that is, they must be opened with + <seealso marker="#open-2"><c>ct_netconfc:open/2</c></seealso>.</p> + + <p>Option <c>hosts</c> has no effect if <c>log_type</c> is set to + <c>html</c> or <c>silent</c>.</p> + + <p>The hook options can also be specified in a configuration file with + configuration variable <c>ct_conn_log</c>:</p> + + <pre> + {ct_conn_log,[{conn_mod(),hook_options()}]}.</pre> + + <p>For example:</p> + + <pre> + {ct_conn_log,[{ct_netconfc,[{log_type,pretty}, + {hosts,[key_or_name()]}]}]}</pre> + + <note> + <p>Hook options specified in a configuration file overwrite the + hard-coded hook options in the test suite.</p> + </note> + + <p><em>Logging Example 1:</em></p> + <marker id="Logging_example_1"/> + + <p>The following <c>ct_hooks</c> statement causes pretty printing of + NETCONF traffic to separate logs for the connections named + <c>nc_server1</c> and <c>nc_server2</c>. Any other connections are + logged to default NETCONF log.</p> + + <pre> + suite() -> + [{ct_hooks, [{cth_conn_log, [{ct_netconfc,[{log_type,pretty}}, + {hosts,[nc_server1,nc_server2]}]} + ]}]}].</pre> + + <p>Connections must be opened as follows:</p> + + <pre> + open(nc_server1,[...]), + open(nc_server2,[...]).</pre> + + <p><em>Logging Example 2:</em></p> + <marker id="Logging_example_2"/> + + <p>The following configuration file causes raw logging of all NETCONF + traffic in to one single text file:</p> + + <pre> + {ct_conn_log,[{ct_netconfc,[{log_type,raw}]}]}.</pre> + + <p>The <c>ct_hooks</c> statement must look as follows:</p> + + <pre> + suite() -> + [{ct_hooks, [{cth_conn_log, []}]}].</pre> + + <p>The same <c>ct_hooks</c> statement without the configuration file + would cause HTML logging of all NETCONF connections in to the test + case HTML log.</p> + </section> + + <section> + <marker id="Notifications"/> + <title>Notifications</title> + + <p>The NETCONF client is also compliant with RFC 5277 NETCONF Event + Notifications, which defines a mechanism for an asynchronous message + notification delivery service for the NETCONF protocol.</p> + + <p>Specific functions to support this are + <seealso marker="#create_subscription-6"><c>ct_netconfc:create_subscription/6</c></seealso> + and + <seealso marker="#get_event_streams-3"><c>ct_netconfc:get_event_streams/3</c></seealso>. + (The functions also exist with other arities.)</p> + </section> + + <section> + <title>Data Types</title> + <marker id="types"/> + <taglist> + <tag><c>client() = handle() | key_or_name()</c></tag> + <item><marker id="type-client"/> + <p>For <c>handle()</c>, see module + <seealso marker="ct"><c>ct</c></seealso>.</p></item> + + <tag><c>error_reason() = term()</c></tag> + <item><marker id="type-error_reason"/> </item> + <tag><c>event_time() = {eventTime, xml_attributes(), [xs_datetime()]}</c></tag> + <item><marker id="type-event_time"/> </item> + + <tag><c>handle() = term()</c></tag> + <item><marker id="type-handle"/> + <p>Opaque reference for a connection (NETCONF session). For more + information, see module <seealso marker="ct"><c>ct</c></seealso>.</p> + </item> + + <tag><c>host() = <seealso marker="kernel:inet#type-hostname"><c>inet:hostname()</c></seealso> | <seealso marker="kernel:inet#type-ip_address"><c>inet:ip_address()</c></seealso></c></tag> + <item><marker id="type-host"/></item> + + <tag><c>key_or_name() = server_id() | target_name()</c></tag> + <item><marker id="type-key_or_name"/> + <p>For <c>target_name</c>, see module + <seealso marker="ct"><c>ct</c></seealso>.</p></item> + + <tag><c>netconf_db() = running | startup | candidate</c></tag> + <item><marker id="type-netconf_db"/> </item> + + <tag><c>notification() = {notification, xml_attributes(), notification_content()}</c></tag> + <item><marker id="type-notification"/> </item> + + <tag><c>notification_content() = [event_time() | simple_xml()]</c></tag> + <item><marker id="type-notification_content"/> </item> + + <tag><c>option() = {ssh, host()} | {port, <seealso marker="kernel:inet#type-port_number"><c>inet:port_number()</c></seealso>} | {timeout, timeout()} | SshConnectOption</c></tag> + <item><marker id="type-option"/> + + <p><c>SshConnectOption</c> is any valid option to + <seealso marker="ssh:ssh#connect-3"><c>ssh:connect/3,4</c></seealso>. + Common options used are <c>user</c>, <c>password</c> + and <c>user_dir</c>. The <c>SshConnectOptions</c> are + verfied by the SSH application.</p></item> + + <tag><c>options() = [option()]</c></tag> + <item><marker id="type-options"/> + <p>Options used for setting up an SSH connection to a NETCONF + server.</p></item> + + <tag><c>server_id() = atom()</c></tag> + <item><marker id="type-server_id"/> + <p>The identity of a server, specified in a configuration + file.</p></item> + + <tag><c>simple_xml() = {xml_tag(), xml_attributes(), xml_content()} | {xml_tag(), xml_content()} | xml_tag()</c></tag> + <item><marker id="type-simple_xml"/> + <p>This type is further described in application + <seealso marker="xmerl:index"><c>xmerl</c></seealso>.</p></item> + + <tag><c>stream_data() = {description, string()} | {replaySupport, string()} | {replayLogCreationTime, string()} | {replayLogAgedTime, string()}</c></tag> + <item><marker id="type-stream_data"/> + <p>For details about the data format for the string values, see + "XML Schema for Event Notifications" in RFC 5277.</p></item> + + <tag><c>stream_name() = string()</c></tag> + <item><marker id="type-stream_name"/> </item> + + <tag><c>streams() = [{stream_name(), [stream_data()]}]</c></tag> + <item><marker id="type-streams"/> </item> + + <tag><c>xml_attribute_tag() = atom()</c></tag> + <item><marker id="type-xml_attribute_tag"/> </item> + + <tag><c>xml_attribute_value() = string()</c></tag> + <item><marker id="type-xml_attribute_value"/> </item> + + <tag><c>xml_attributes() = [{xml_attribute_tag(), xml_attribute_value()}]</c></tag> + <item><marker id="type-xml_attributes"/> </item> + + <tag><c>xml_content() = [simple_xml() | iolist()]</c></tag> + <item><marker id="type-xml_content"/> </item> + + <tag><c>xml_tag() = atom()</c></tag> + <item><marker id="type-xml_tag"/> </item> + + <tag><c>xpath() = {xpath, string()}</c></tag> + <item><marker id="type-xpath"/> </item> + + <tag><c>xs_datetime() = string()</c></tag> + <item><marker id="type-xs_datetime"/> + <p>This date and time identifier has the same format as the XML type + <c>dateTime</c> and is compliant with RFC 3339 Date and Time on + the Internet Timestamps. The format is as follows:</p> + <pre> + [-]CCYY-MM-DDThh:mm:ss[.s][Z|(+|-)hh:mm]</pre> + </item> + </taglist> + </section> + + <funcs> + <func> + <name>action(Client, Action) -> Result</name> + <fsummary>Equivalent to action(Client, Action, infinity).</fsummary> + <desc><marker id="action-2"/> + <p>Equivalent to + <seealso marker="#action-3"><c>ct_netconfc:action(Client, Action, + infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>action(Client, Action, Timeout) -> Result</name> + <fsummary>Executes an action.</fsummary> + <type> + <v>Client = client()</v> + <v>Action = simple_xml()</v> + <v>Timeout = timeout()</v> + <v>Result = ok | {ok, [simple_xml()]} | {error, error_reason()}</v> + </type> + <desc><marker id="action-3"/> + <p>Executes an action. If the return type is void, <c>ok</c> is + returned instead of <c>{ok,[simple_xml()]}</c>.</p> + </desc> + </func> + + <func> + <name>close_session(Client) -> Result</name> + <fsummary>Equivalent to close_session(Client, infinity).</fsummary> + <desc><marker id="close_session-1"/> + <p>Equivalent to + <seealso marker="#close_session-2"><c>ct_netconfc:close_session(Client, + infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>close_session(Client, Timeout) -> Result</name> + <fsummary>Requests graceful termination of the session associated with + the client.</fsummary> + <type> + <v>Client = client()</v> + <v>Timeout = timeout()</v> + <v>Result = ok | {error, error_reason()}</v> + </type> + <desc><marker id="close_session-2"/> + <p>Requests graceful termination of the session associated with the + client.</p> + + <p>When a NETCONF server receives a <c>close-session</c> request, it + gracefully closes the session. The server releases any locks and + resources associated with the session and gracefully closes any + associated connections. Any NETCONF requests received after a + <c>close-session</c> request are ignored.</p> + </desc> + </func> + + <func> + <name>copy_config(Client, Source, Target) -> Result</name> + <fsummary>Equivalent to copy_config(Client, Source, Target, + infinity).</fsummary> + <desc><marker id="copy_config-3"/> + <p>Equivalent to + <seealso marker="#copy_config-4"><c>ct_netconfc:copy_config(Client, + Source, Target, infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>copy_config(Client, Target, Source, Timeout) -> Result</name> + <fsummary>Copies configuration data.</fsummary> + <type> + <v>Client = client()</v> + <v>Target = netconf_db()</v> + <v>Source = netconf_db()</v> + <v>Timeout = timeout()</v> + <v>Result = ok | {error, error_reason()}</v> + </type> + <desc><marker id="copy_config-4"/> + <p>Copies configuration data.</p> + + <p>Which source and target options that can be issued depends on the + capabilities supported by the server. That is, <c>:candidate</c> + and/or <c>:startup</c> are required.</p> + </desc> + </func> + + <func> + <name>create_subscription(Client) -> term()</name> + <fsummary>Creates a subscription for event notifications.</fsummary> + <desc><marker id="create_subscription-1"/></desc> + </func> + + <func> + <name>create_subscription(Client, Timeout) -> term()</name> + <fsummary>Creates a subscription for event notifications.</fsummary> + <desc><marker id="create_subscription-2"/></desc> + </func> + + <func> + <name>create_subscription(Client, Stream, Timeout) -> term()</name> + <fsummary>Creates a subscription for event notifications.</fsummary> + <desc><marker id="create_subscription-3"/></desc> + </func> + + <func> + <name>create_subscription(Client, StartTime, StopTime, Timeout) -> term()</name> + <fsummary>Creates a subscription for event notifications.</fsummary> + <desc><marker id="create_subscription-4"/></desc> + </func> + + <func> + <name>create_subscription(Client, Stream, StartTime, StopTime, Timeout) -> term()</name> + <fsummary>Creates a subscription for event notifications.</fsummary> + <desc><marker id="create_subscription-5"/></desc> + </func> + + <func> + <name>create_subscription(Client, Stream, Filter, StartTime, StopTime, Timeout) -> Result</name> + <fsummary>Creates a subscription for event notifications.</fsummary> + <type> + <v>Client = client()</v> + <v>Stream = stream_name()</v> + <v>Filter = simple_xml() | [simple_xml()]</v> + <v>StartTime = xs_datetime()</v> + <v>StopTime = xs_datetime()</v> + <v>Timeout = timeout()</v> + <v>Result = ok | {error, error_reason()}</v> + </type> + <desc><marker id="create_subscription-6"/> + <p>Creates a subscription for event notifications.</p> + + <p>This function sets up a subscription for NETCONF event + notifications of the specified stream type, matching the specified + filter. The calling process receives notifications as messages of + type <c>notification()</c>.</p> + + <taglist> + <tag><c>Stream</c></tag> + <item><p>Optional parameter that indicates which stream of event + is of interest. If not present, events in the default NETCONF + stream are sent.</p></item> + <tag><c>Filter</c></tag> + <item><p>Optional parameter that indicates which subset of all + possible events is of interest. The parameter format is the + same as that of the filter parameter in the NETCONF protocol + operations. If not present, all events not precluded by other + parameters are sent.</p></item> + <tag><c>StartTime</c></tag> + <item><p>Optional parameter used to trigger the replay feature and + indicate that the replay is to start at the time specified. + If <c>StartTime</c> is not present, this is not a replay + subscription.</p> + <p>It is not valid to specify start times that are later than + the current time. If <c>StartTime</c> is specified earlier + than the log can support, the replay begins with the earliest + available notification.</p> + <p>This parameter is of type <c>dateTime</c> and compliant to + RFC 3339. Implementations must support time zones.</p></item> + <tag><c>StopTime</c></tag> + <item><p>Optional parameter used with the optional replay feature + to indicate the newest notifications of interest. If + <c>StopTime</c> is not present, the notifications continues + until the subscription is terminated.</p> + <p>Must be used with and be later than <c>StartTime</c>. Values + of <c>StopTime</c> in the future are valid. This parameter is + of type <c>dateTime</c> and compliant to RFC 3339. + Implementations must support time zones.</p></item> + </taglist> + + <p>For more details about the event notification mechanism, see + RFC 5277.</p> + </desc> + </func> + + <func> + <name>delete_config(Client, Target) -> Result</name> + <fsummary>Equivalent to delete_config(Client, Target, + infinity).</fsummary> + <desc><marker id="delete_config-2"/> + <p>Equivalent to + <seealso marker="#delete_config-3"><c>ct_netconfc:delete_config(Client, Target, infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>delete_config(Client, Target, Timeout) -> Result</name> + <fsummary>Deletes configuration data.</fsummary> + <type> + <v>Client = client()</v> + <v>Target = startup | candidate</v> + <v>Timeout = timeout()</v> + <v>Result = ok | {error, error_reason()}</v> + </type> + <desc><marker id="delete_config-3"/> + <p>Deletes configuration data.</p> + + <p>The running configuration cannot be deleted and <c>:candidate</c> + or <c>:startup</c> must be advertised by the server.</p> + </desc> + </func> + + <func> + <name>edit_config(Client, Target, Config) -> Result</name> + <fsummary>Equivalent to edit_config(Client, Target, Config, [], + infinity).</fsummary> + <desc><marker id="edit_config-3"/> + <p>Equivalent to + <seealso marker="#edit_config-5"><c>ct_netconfc:edit_config(Client, + Target, Config, [], infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>edit_config(Client, Target, Config, OptParamsOrTimeout) -> Result</name> + <fsummary>If OptParamsOrTimeout is a time-out value, this function is + equivalent to ct_netconfc:edit_config(Client, Target, Config, [], + Timeout).</fsummary> + <type> + <v>Client = client()</v> + <v>Target = netconf_db()</v> + <v>Config = simple_xml()</v> + <v>OptParamsOrTimeout = [simple_xml()] | timeout()</v> + <v>Result = ok | {error, error_reason()}</v> + </type> + <desc><marker id="edit_config-4"/> + <p>If <c>OptParamsOrTimeout</c> is a time-out value, this function is + equivalent to + <seealso marker="#edit_config-5"><c>ct_netconfc:edit_config(Client, + Target, Config, [], Timeout)</c></seealso>.</p> + + <p>If <c>OptParamsOrTimeout</c> is a list of simple XML, this + function is equivalent to + <seealso marker="#edit_config-5"><c>ct_netconfc:edit_config(Client, + Target, Config, OptParams, infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>edit_config(Client, Target, Config, OptParams, Timeout) -> Result</name> + <fsummary>Edits configuration data.</fsummary> + <type> + <v>Client = client()</v> + <v>Target = netconf_db()</v> + <v>Config = simple_xml()</v> + <v>OptParams = [simple_xml()]</v> + <v>Timeout = timeout()</v> + <v>Result = ok | {error, error_reason()}</v> + </type> + <desc><marker id="edit_config-5"/> + <p>Edits configuration data.</p> + + <p>By default only the running target is available, unless the server + includes <c>:candidate</c> or <c>:startup</c> in its list of + capabilities.</p> + + <p><c>OptParams</c> can be used for specifying optional parameters + (<c>default-operation</c>, <c>test-option</c>, or + <c>error-option</c>) to be added to the <c>edit-config</c> + request. The value must be a list containing valid simple XML, + for example:</p> + + <pre> + [{'default-operation', ["none"]}, + {'error-option', ["rollback-on-error"]}]</pre> + </desc> + </func> + + <func> + <name>get(Client, Filter) -> Result</name> + <fsummary>Equivalent to get(Client, Filter, infinity).</fsummary> + <desc><marker id="get-2"/> + <p>Equivalent to + <seealso marker="#get-3"><c>ct_netconfc:get(Client, Filter, + infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>get(Client, Filter, Timeout) -> Result</name> + <fsummary>Gets data.</fsummary> + <type> + <v>Client = client()</v> + <v>Filter = simple_xml() | xpath()</v> + <v>Timeout = timeout()</v> + <v>Result = {ok, [simple_xml()]} | {error, error_reason()}</v> + </type> + <desc><marker id="get-3"/> + <p>Gets data.</p> + + <p>This operation returns both configuration and state data from the + server.</p> + + <p>Filter type <c>xpath</c> can be used only if the server supports + <c>:xpath</c>.</p> + </desc> + </func> + + <func> + <name>get_capabilities(Client) -> Result</name> + <fsummary>Equivalent to get_capabilities(Client, infinity).</fsummary> + <desc><marker id="get_capabilities-1"/> + <p>Equivalent to + <seealso marker="#get_capabilities-2"><c>ct_netconfc:get_capabilities(Client, + infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>get_capabilities(Client, Timeout) -> Result</name> + <fsummary>Returns the server side capabilities.</fsummary> + <type> + <v>Client = client()</v> + <v>Timeout = timeout()</v> + <v>Result = [string()] | {error, error_reason()}</v> + </type> + <desc><marker id="get_capabilities-2"/> + <p>Returns the server side capabilities.</p> + + <p>The following capability identifiers, defined in RFC 4741 NETCONF + Configuration Protocol, can be returned:</p> + + <list> + <item><p><c>"urn:ietf:params:netconf:base:1.0"</c></p></item> + <item><p><c>"urn:ietf:params:netconf:capability:writable-running:1.0"</c></p></item> + <item><p><c>"urn:ietf:params:netconf:capability:candidate:1.0"</c></p></item> + <item><p><c>"urn:ietf:params:netconf:capability:confirmed-commit:1.0"</c></p></item> + <item><p><c>"urn:ietf:params:netconf:capability:rollback-on-error:1.0"</c></p></item> + <item><p><c>"urn:ietf:params:netconf:capability:startup:1.0"</c></p></item> + <item><p><c>"urn:ietf:params:netconf:capability:url:1.0"</c></p></item> + <item><p><c>"urn:ietf:params:netconf:capability:xpath:1.0"</c></p></item> + </list> + + <p>More identifiers can exist, for example, server-side namespace.</p> + </desc> + </func> + + <func> + <name>get_config(Client, Source, Filter) -> Result</name> + <fsummary>Equivalent to get_config(Client, Source, Filter, + infinity).</fsummary> + <desc><marker id="get_config-3"/> + <p>Equivalent to + <seealso marker="#get_config-4"><c>ct_netconfc:get_config(Client, Source, Filter, infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>get_config(Client, Source, Filter, Timeout) -> Result</name> + <fsummary>Gets configuration data.</fsummary> + <type> + <v>Client = client()</v> + <v>Source = netconf_db()</v> + <v>Filter = simple_xml() | xpath()</v> + <v>Timeout = timeout()</v> + <v>Result = {ok, [simple_xml()]} | {error, error_reason()}</v> + </type> + <desc><marker id="get_config-4"/> + <p>Gets configuration data.</p> + + <p>To be able to access another source than <c>running</c>, the + server must advertise <c>:candidate</c> and/or <c>:startup</c>.</p> + + <p>Filter type <c>xpath</c> can be used only if the server supports + <c>:xpath</c>.</p> + </desc> + </func> + + <func> + <name>get_event_streams(Client, Timeout) -> Result</name> + <fsummary>Equivalent to get_event_streams(Client, [], Timeout).</fsummary> + <desc><marker id="get_event_streams-2"/> + <p>Equivalent to + <seealso marker="#get_event_streams-3"><c>ct_netconfc:get_event_streams(Client, + [], Timeout)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>get_event_streams(Client, Streams, Timeout) -> Result</name> + <fsummary>Sends a request to get the specified event streams.</fsummary> + <type> + <v>Client = client()</v> + <v>Streams = [stream_name()]</v> + <v>Timeout = timeout()</v> + <v>Result = {ok, streams()} | {error, error_reason()}</v> + </type> + <desc><marker id="get_event_streams-3"/> + <p>Sends a request to get the specified event streams.</p> + + <p><c>Streams</c> is a list of stream names. The following filter is + sent to the NETCONF server in a <c>get</c> request:</p> + + <pre> + <netconf xmlns="urn:ietf:params:xml:ns:netmod:notification"> + <streams> + <stream> + <name>StreamName1</name> + </stream> + <stream> + <name>StreamName2</name> + </stream> + ... + </streams> + </netconf></pre> + + <p>If <c>Streams</c> is an empty list, <em>all</em> streams are + requested by sending the following filter:</p> + + <pre> + <netconf xmlns="urn:ietf:params:xml:ns:netmod:notification"> + <streams/> + </netconf></pre> + + <p>If more complex filtering is needed, use + <seealso marker="#get-2"><c>ct_netconfc:get/2</c></seealso> or + <seealso marker="#get-3"><c>ct_netconfc:get/3</c></seealso> and + specify the exact filter according to "XML Schema for Event + Notifications" in RFC 5277.</p> + </desc> + </func> + + <func> + <name>get_session_id(Client) -> Result</name> + <fsummary>Equivalent to get_session_id(Client, infinity).</fsummary> + <desc><marker id="get_session_id-1"/> + <p>Equivalent to + <seealso marker="#get_session_id-2"><c>ct_netconfc:get_session_id(Client, + infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>get_session_id(Client, Timeout) -> Result</name> + <fsummary>Returns the session Id associated with the specified + client.</fsummary> + <type> + <v>Client = client()</v> + <v>Timeout = timeout()</v> + <v>Result = pos_integer() | {error, error_reason()}</v> + </type> + <desc><marker id="get_session_id-2"/> + <p>Returns the session Id associated with the specified client.</p> + </desc> + </func> + + <func> + <name>hello(Client) -> Result</name> + <fsummary>Equivalent to hello(Client, [], infinity).</fsummary> + <desc><marker id="hello-1"/> + <p>Equivalent to + <seealso marker="#hello-3"><c>ct_netconfc:hello(Client, [], + infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>hello(Client, Timeout) -> Result</name> + <fsummary>Equivalent to hello(Client, [], Timeout).</fsummary> + <desc><marker id="hello-2"/> + <p>Equivalent to + <seealso marker="#hello-3"><c>ct_netconfc:hello(Client, [], + Timeout)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>hello(Client, Options, Timeout) -> Result</name> + <fsummary>Exchanges hello messages with the server.</fsummary> + <type> + <v>Client = handle()</v> + <v>Options = [{capability, [string()]}]</v> + <v>Timeout = timeout()</v> + <v>Result = ok | {error, error_reason()}</v> + </type> + <desc><marker id="hello-3"/> + <p>Exchanges <c>hello</c> messages with the server.</p> + + <p>Adds optional capabilities and sends a <c>hello</c> message to the + server and waits for the return.</p> + </desc> + </func> + + <func> + <name>kill_session(Client, SessionId) -> Result</name> + <fsummary>Equivalent to kill_session(Client, SessionId, + infinity).</fsummary> + <desc><marker id="kill_session-2"/> + <p>Equivalent to + <seealso marker="#kill_session-3"><c>ct_netconfc:kill_session(Client, +SessionId, infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>kill_session(Client, SessionId, Timeout) -> Result</name> + <fsummary>Forces termination of the session associated with the supplied + session Id.</fsummary> + <type> + <v>Client = client()</v> + <v>SessionId = pos_integer()</v> + <v>Timeout = timeout()</v> + <v>Result = ok | {error, error_reason()}</v> + </type> + <desc><marker id="kill_session-3"/> + <p>Forces termination of the session associated with the supplied + session Id.</p> + + <p>The server side must abort any ongoing operations, release any + locks and resources associated with the session, and close any + associated connections.</p> + + <p>Only if the server is in the confirmed commit phase, the + configuration is restored to its state before entering the confirmed + commit phase. Otherwise, no configuration rollback is performed.</p> + + <p>If the specified <c>SessionId</c> is equal to the current session + Id, an error is returned.</p> + </desc> + </func> + + <func> + <name>lock(Client, Target) -> Result</name> + <fsummary>Equivalent to lock(Client, Target, infinity).</fsummary> + <desc><marker id="lock-2"/> + <p>Equivalent to + <seealso marker="#lock-3"><c>ct_netconfc:lock(Client, Target, + infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>lock(Client, Target, Timeout) -> Result</name> + <fsummary>Unlocks the configuration target.</fsummary> + <type> + <v>Client = client()</v> + <v>Target = netconf_db()</v> + <v>Timeout = timeout()</v> + <v>Result = ok | {error, error_reason()}</v> + </type> + <desc><marker id="lock-3"/> + <p>Unlocks the configuration target.</p> + + <p>Which target parameters that can be used depends on if + <c>:candidate</c> and/or <c>:startup</c> are supported by the + server. If successfull, the configuration system of the device is + unavailable to other clients (NETCONF, CORBA, SNMP, and so on). + Locks are intended to be short-lived.</p> + + <p>Operation + <seealso marker="#kill_session-2"><c>ct_netconfc:kill_session/2</c></seealso> + or + <seealso marker="#kill_session-3"><c>ct_netconfc:kill_session/3</c></seealso> + can be used to force the release of a lock owned by another NETCONF + session. How this is achieved by the server side is + implementation-specific.</p> + </desc> + </func> + + <func> + <name>only_open(Options) -> Result</name> + <fsummary>Opens a NETCONF session, but does not send hello.</fsummary> + <type> + <v>Options = options()</v> + <v>Result = {ok, handle()} | {error, error_reason()}</v> + </type> + <desc><marker id="only_open-1"/> + <p>Opens a NETCONF session, but does not send <c>hello</c>.</p> + + <p>As <seealso marker="#open-1"><c>ct_netconfc:open/1</c></seealso>, + but does not send a <c>hello</c> message.</p> + </desc> + </func> + + <func> + <name>only_open(KeyOrName, ExtraOptions) -> Result</name> + <fsummary>Opens a name NETCONF session, but does not send + hello.</fsummary> + <type> + <v>KeyOrName = key_or_name()</v> + <v>ExtraOptions = options()</v> + <v>Result = {ok, handle()} | {error, error_reason()}</v> + </type> + <desc><marker id="only_open-2"/> + <p>Opens a name NETCONF session, but does not send <c>hello</c>.</p> + + <p>As <seealso marker="#open-2"><c>ct_netconfc:open/2</c></seealso>, + but does not send a <c>hello</c> message.</p> + </desc> + </func> + + <func> + <name>open(Options) -> Result</name> + <fsummary>Opens a NETCONF session and exchanges hello messages.</fsummary> + <type> + <v>Options = options()</v> + <v>Result = {ok, handle()} | {error, error_reason()}</v> + </type> + <desc><marker id="open-1"/> + <p>Opens a NETCONF session and exchanges <c>hello</c> messages.</p> + + <p>If the server options are specified in a configuration file, + or if a named client is needed for logging purposes (see section + <seealso marker="#Logging">Logging</seealso> in this module), use + <seealso marker="#open-2"><c>ct_netconfc:open/2</c></seealso> + instead.</p> + + <p>The opaque <c>handle()</c> reference returned from this + function is required as client identifier when calling any other + function in this module.</p> + + <p>Option <c>timeout</c> (milliseconds) is used when setting up the + SSH connection and when waiting for the <c>hello</c> message from + the server. It is not used for any other purposes during the + lifetime of the connection.</p> + </desc> + </func> + + <func> + <name>open(KeyOrName, ExtraOptions) -> Result</name> + <fsummary>Opens a named NETCONF session and exchanges hello + messages.</fsummary> + <type> + <v>KeyOrName = key_or_name()</v> + <v>ExtraOptions = options()</v> + <v>Result = {ok, handle()} | {error, error_reason()}</v> + </type> + <desc><marker id="open-2"/> + <p>Opens a named NETCONF session and exchanges <c>hello</c> + messages.</p> + + <p>If <c>KeyOrName</c> is a configured <c>server_id()</c> or a + <c>target_name()</c> associated with such an Id, then the options + for this server are fetched from the configuration file.</p> + + <p>Argument <c>ExtraOptions</c> is added to the options found in the + configuration file. If the same options are specified, the values + from the configuration file overwrite <c>ExtraOptions</c>.</p> + + <p>If the server is not specified in a configuration file, use + <seealso marker="#open-1"><c>ct_netconfc:open/1</c></seealso> + instead.</p> + + <p>The opaque <c>handle()</c> reference returned from this + function can be used as client identifier when calling any other + function in this module. However, if <c>KeyOrName</c> is a + <c>target_name()</c>, that is, if the server is named through a + call to <seealso marker="ct#require-2"><c>ct:require/2</c></seealso> + or a <c>require</c> statement in the test suite, then this name can + be used instead of <c>handle()</c>.</p> + + <p>Option <c>timeout</c> (milliseconds) is used when setting up the + SSH connection and when waiting for the <c>hello</c> message from + the server. It is not used for any other purposes during the + lifetime of the connection.</p> + + <p>See also + <seealso marker="ct#require-2"><c>ct:require/2</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send(Client, SimpleXml) -> Result</name> + <fsummary>Equivalent to send(Client, SimpleXml, infinity).</fsummary> + <desc><marker id="send-2"/> + <p>Equivalent to + <seealso marker="#send-3"><c>ct_netconfc:send(Client, SimpleXml, + infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send(Client, SimpleXml, Timeout) -> Result</name> + <fsummary>Sends an XML document to the server.</fsummary> + <type> + <v>Client = client()</v> + <v>SimpleXml = simple_xml()</v> + <v>Timeout = timeout()</v> + <v>Result = simple_xml() | {error, error_reason()}</v> + </type> + <desc><marker id="send-3"/> + <p>Sends an XML document to the server.</p> + + <p>The specified XML document is sent "as is" to the server. This + function can be used for sending XML documents that cannot be + expressed by other interface functions in this module.</p> + </desc> + </func> + + <func> + <name>send_rpc(Client, SimpleXml) -> Result</name> + <fsummary>Equivalent to send_rpc(Client, SimpleXml, infinity).</fsummary> + <desc><marker id="send_rpc-2"/> + <p>Equivalent to + <seealso marker="#send_rpc-3"><c>ct_netconfc:send_rpc(Client, + SimpleXml, infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send_rpc(Client, SimpleXml, Timeout) -> Result</name> + <fsummary>Sends a NETCONF rpc request to the server.</fsummary> + <type> + <v>Client = client()</v> + <v>SimpleXml = simple_xml()</v> + <v>Timeout = timeout()</v> + <v>Result = [simple_xml()] | {error, error_reason()}</v> + </type> + <desc><marker id="send_rpc-3"/> + <p>Sends a NETCONF <c>rpc</c> request to the server.</p> + + <p>The specified XML document is wrapped in a valid NETCONF <c>rpc</c> + request and sent to the server. The <c>message-id</c> and namespace + attributes are added to element <c>rpc</c>.</p> + + <p>This function can be used for sending <c>rpc</c> requests that + cannot be expressed by other interface functions in this module.</p> + </desc> + </func> + + <func> + <name>unlock(Client, Target) -> Result</name> + <fsummary>Equivalent to unlock(Client, Target, infinity).</fsummary> + <desc><marker id="unlock-2"/> + <p>Equivalent to + <seealso marker="#unlock-3"><c>ct_netconfc:unlock(Client, Target, + infinity)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>unlock(Client, Target, Timeout) -> Result</name> + <fsummary>Unlocks the configuration target.</fsummary> + <type> + <v>Client = client()</v> + <v>Target = netconf_db()</v> + <v>Timeout = timeout()</v> + <v>Result = ok | {error, error_reason()}</v> + </type> + <desc><marker id="unlock-3"/> + <p>Unlocks the configuration target.</p> + + <p>If the client earlier has acquired a lock through + <seealso marker="#lock-2"><c>ct_netconfc:lock/2</c></seealso> or + <seealso marker="#lock-3"><c>ct_netconfc:lock/3</c></seealso>, this + operation releases the associated lock. To access another target + than <c>running</c>, the server must support <c>:candidate</c> + and/or <c>:startup</c>.</p> + </desc> + </func> + </funcs> + +</erlref> + + diff --git a/lib/common_test/doc/src/ct_property_test.xml b/lib/common_test/doc/src/ct_property_test.xml new file mode 100644 index 0000000000..2e9bd1969c --- /dev/null +++ b/lib/common_test/doc/src/ct_property_test.xml @@ -0,0 +1,116 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>ct_property_test</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>ct_property_test.xml</file> + </header> + <module>ct_property_test</module> + <modulesummary>EXPERIMENTAL support in Common Test for calling + property-based tests.</modulesummary> + + <description> + + <p>EXPERIMENTAL support in <c>Common Test</c> for calling property-based + tests.</p> + + <p>This module is a first step to run property-based tests in the + <c>Common Test</c> framework. A property testing tool like QuickCheck + or PropEr is assumed to be installed.</p> + + <p>The idea is to have a <c>Common Test</c> test suite calling a property + testing tool with special property test suites as defined by that tool. + The usual Erlang application directory structure is assumed. The tests + are collected in the <c>test</c> directory of the application. The + <c>test</c> directory has a subdirectory <c>property_test</c>, where + everything needed for the property tests is collected.</p> + + <p>A typical <c>Common Test</c> test suite using <c>ct_property_test</c> + is organized as follows:</p> + + <pre> + -include_lib("common_test/include/ct.hrl"). + + all() -> [prop_ftp_case]. + + init_per_suite(Config) -> + ct_property_test:init_per_suite(Config). + + %%%---- test case + prop_ftp_case(Config) -> + ct_property_test:quickcheck( + ftp_simple_client_server:prop_ftp(Config), + Config + ).</pre> + + <warning> + <p>This is experimental code that can be changed or removed anytime + without any warning.</p> + </warning> + + </description> + + <funcs> + <func> + <name>init_per_suite(Config) -> Config | {skip, Reason}</name> + <fsummary>Initializes Config for property testing.</fsummary> + <desc><marker id="init_per_suite-1"/> + <p>Initializes <c>Config</c> for property testing.</p> + + <p>This function investigates if support is available for either + Quickcheck, PropEr, or Triq. The options + <c>{property_dir,AbsPath}</c> and <c>{property_test_tool,Tool}</c> + are set in the <c>Config</c> returned.</p> + + <p>The function is intended to be called in function + <c>init_per_suite</c> in the test suite.</p> + + <p>The property tests are assumed to be in subdirectory + <c>property_test</c>.</p> + </desc> + </func> + + <func> + <name>quickcheck(Property, Config) -> true | {fail, Reason}</name> + <fsummary>Calls quickcheck and returns the result in a form suitable for + Common Test.</fsummary> + <desc><marker id="quickcheck-2"/> + <p>Calls quickcheck and returns the result in a form suitable for + <c>Common Test</c>.</p> + + <p>This function is intended to be called in the test cases in the + test suite.</p> + </desc> + </func> + </funcs> + +</erlref> + + diff --git a/lib/common_test/doc/src/ct_rpc.xml b/lib/common_test/doc/src/ct_rpc.xml new file mode 100644 index 0000000000..0169727581 --- /dev/null +++ b/lib/common_test/doc/src/ct_rpc.xml @@ -0,0 +1,220 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>ct_rpc</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>ct_rpc.xml</file> + </header> + <module>ct_rpc</module> + <modulesummary>Common Test specific layer on Erlang/OTP rpc.</modulesummary> + + <description> + + <p><c>Common Test</c> specific layer on Erlang/OTP <c>rpc</c>.</p> + + </description> + + <funcs> + <func> + <name>app_node(App, Candidates) -> NodeName</name> + <fsummary>From a set of candidate nodes determines which of them is + running the application App.</fsummary> + <type> + <v>App = atom()</v> + <v>Candidates = [NodeName]</v> + <v>NodeName = atom()</v> + </type> + <desc><marker id="app_node-2"/> + <p>From a set of candidate nodes determines which of them is running + the application <c>App</c>. If none of the candidate nodes is + running <c>App</c>, the function makes the test case calling + this function to fail. This function is the same as calling + <c>app_node(App, Candidates, true)</c>.</p> + </desc> + </func> + + <func> + <name>app_node(App, Candidates, FailOnBadRPC) -> NodeName</name> + <fsummary>Same as app_node/2, except that argument FailOnBadRPC + determines if the search for a candidate node is to stop if + badrpc is received at some point.</fsummary> + <type> + <v>App = atom()</v> + <v>Candidates = [NodeName]</v> + <v>NodeName = atom()</v> + <v>FailOnBadRPC = true | false</v> + </type> + <desc><marker id="app_node-3"/> + <p>Same as + <seealso marker="#app_node-2"><c>ct_rpc:app_node/2</c></seealso>, + except that argument <c>FailOnBadRPC</c> determines if the search + for a candidate node is to stop if <c>badrpc</c> is received at + some point.</p> + </desc> + </func> + + <func> + <name>app_node(App, Candidates, FailOnBadRPC, Cookie) -> NodeName</name> + <fsummary>Same as app_node/2, except that argument FailOnBadRPC + determines if the search for a candidate node is to stop if badrpc is + received at some point.</fsummary> + <type> + <v>App = atom()</v> + <v>Candidates = [NodeName]</v> + <v>NodeName = atom()</v> + <v>FailOnBadRPC = true | false</v> + <v>Cookie = atom()</v> + </type> + <desc><marker id="app_node-4"/> + <p>Same as + <seealso marker="#app_node-2"><c>ct_rpc:app_node/2</c></seealso>, + except that argument <c>FailOnBadRPC</c> determines if the search + for a candidate node is to stop if <c>badrpc</c> is received at + some point.</p> + + <p>The cookie on the client node is set to <c>Cookie</c> for this + <c>rpc</c> operation (used to match the server node cookie).</p> + </desc> + </func> + + <func> + <name>call(Node, Module, Function, Args) -> term() | {badrpc, Reason}</name> + <fsummary>Same as call(Node, Module, Function, Args, infinity).</fsummary> + <desc><marker id="call-4"/> + <p>Same as <c>call(Node, Module, Function, Args, infinity)</c>.</p> + </desc> + </func> + + <func> + <name>call(Node, Module, Function, Args, TimeOut) -> term() | {badrpc, Reason}</name> + <fsummary>Evaluates apply(Module, Function, Args) on the node + Node.</fsummary> + <type> + <v>Node = NodeName | {Fun, FunArgs}</v> + <v>Fun = function()</v> + <v>FunArgs = term()</v> + <v>NodeName = atom()</v> + <v>Module = atom()</v> + <v>Function = atom()</v> + <v>Args = [term()]</v> + <v>Reason = timeout | term()</v> + </type> + <desc><marker id="call-5"/> + <p>Evaluates <c>apply(Module, Function, Args)</c> on the node + <c>Node</c>. Returns either whatever <c>Function</c> returns, or + <c>{badrpc, Reason}</c> if the remote procedure call fails. If + <c>Node</c> is <c>{Fun, FunArgs}</c>, applying <c>Fun</c> to + <c>FunArgs</c> is to return a node name.</p> + </desc> + </func> + + <func> + <name>call(Node, Module, Function, Args, TimeOut, Cookie) -> term() | {badrpc, Reason}</name> + <fsummary>Evaluates apply(Module, Function, Args) on the node + Node.</fsummary> + <type> + <v>Node = NodeName | {Fun, FunArgs}</v> + <v>Fun = function()</v> + <v>FunArgs = term()</v> + <v>NodeName = atom()</v> + <v>Module = atom()</v> + <v>Function = atom()</v> + <v>Args = [term()]</v> + <v>Reason = timeout | term()</v> + <v>Cookie = atom()</v> + </type> + <desc><marker id="call-6"/> + <p>Evaluates <c>apply(Module, Function, Args)</c> on the node + <c>Node</c>. Returns either whatever <c>Function</c> returns, or + <c>{badrpc, Reason}</c> if the remote procedure call fails. If + <c>Node</c> is <c>{Fun, FunArgs}</c>, applying <c>Fun</c> to + <c>FunArgs</c> is to return a node name.</p> + + <p>The cookie on the client node is set to <c>Cookie</c> for this + <c>rpc</c> operation (used to match the server node cookie).</p> + </desc> + </func> + + <func> + <name>cast(Node, Module, Function, Args) -> ok</name> + <fsummary>Evaluates apply(Module, Function, Args) on the node + Node.</fsummary> + <type> + <v>Node = NodeName | {Fun, FunArgs}</v> + <v>Fun = function()</v> + <v>FunArgs = term()</v> + <v>NodeName = atom()</v> + <v>Module = atom()</v> + <v>Function = atom()</v> + <v>Args = [term()]</v> + <v>Reason = timeout | term()</v> + </type> + <desc><marker id="cast-4"/> + <p>Evaluates <c>apply(Module, Function, Args)</c> on the node + <c>Node</c>. No response is delivered and the process that makes + the call is not suspended until the evaluation is completed as in + the case of <c>call/3,4</c>. If <c>Node</c> is + <c>{Fun, FunArgs}</c>, applying <c>Fun</c> to <c>FunArgs</c> is to + return a node name.</p> + </desc> + </func> + + <func> + <name>cast(Node, Module, Function, Args, Cookie) -> ok</name> + <fsummary>Evaluates apply(Module, Function, Args) on the node + Node.</fsummary> + <type> + <v>Node = NodeName | {Fun, FunArgs}</v> + <v>Fun = function()</v> + <v>FunArgs = term()</v> + <v>NodeName = atom()</v> + <v>Module = atom()</v> + <v>Function = atom()</v> + <v>Args = [term()]</v> + <v>Reason = timeout | term()</v> + <v>Cookie = atom()</v> + </type> + <desc><marker id="cast-5"/> + <p>Evaluates <c>apply(Module, Function, Args)</c> on the node + <c>Node</c>. No response is delivered and the process that makes + the call is not suspended until the evaluation is completed as in + the case of <c>call/3,4</c>. If <c>Node</c> is + <c>{Fun, FunArgs}</c>, applying <c>Fun</c> to <c>FunArgs</c> is to + return a node name.</p> + + <p>The cookie on the client node is set to <c>Cookie</c> for this + <c>rpc</c> operation (used to match the server node cookie).</p> + </desc> + </func> + </funcs> + +</erlref> + + diff --git a/lib/common_test/doc/src/ct_run.xml b/lib/common_test/doc/src/ct_run.xml index 5518bb039b..d0ecc38564 100644 --- a/lib/common_test/doc/src/ct_run.xml +++ b/lib/common_test/doc/src/ct_run.xml @@ -34,178 +34,189 @@ </header> <com>ct_run</com> <comsummary>Program used for starting Common Test from the - OS command line. - </comsummary> + OS command line.</comsummary> <description> <p>The <c>ct_run</c> program is automatically installed with Erlang/OTP - and Common Test (please see the Installation chapter in the Common - Test User's Guide for more information). The program accepts a number - of different start flags. Some flags trigger <c>ct_run</c> - to start the Common Test application and pass on data to it. Some - flags start an Erlang node prepared for running Common Test in a - particular mode.</p> - - <p>There is an interface function that corresponds to this program, - called <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>, for starting Common Test from the Erlang - shell (or an Erlang program). Please see the <c>ct</c> man page for - details.</p> + and the <c>Common Test</c> application (for more information, see + section <seealso marker="install_chapter">Installation</seealso> + in the User's Guide). The program accepts different start flags. + Some flags trigger <c>ct_run</c> to start <c>Common Test</c> and + pass on data to it. Some flags start an Erlang node prepared for + running <c>Common Test</c> in a particular mode.</p> + + <p>The interface function + <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>, + corresponding to the <c>ct_run</c> program, is used for starting + <c>Common Test</c> from the Erlang shell (or an Erlang program). + For details, see the <seealso marker="ct"><c>ct</c></seealso> + manual page.</p> <p><c>ct_run</c> also accepts Erlang emulator flags. These are used - when <c>ct_run</c> calls <c>erl</c> to start the Erlang node - (making it possible to e.g. add directories to the code server path, - change the cookie on the node, start additional applications, etc).</p> - - <p>With the optional flag:</p> - <pre>-erl_args</pre> - <p>it's possible to divide the options on the <c>ct_run</c> command line into - two groups, one that Common Test should process (those preceding <c>-erl_args</c>), - and one it should completely ignore and pass on directly to the emulator - (those following <c>-erl_args</c>). Options preceding <c>-erl_args</c> that Common Test - doesn't recognize, also get passed on to the emulator untouched. - By means of <c>-erl_args</c> the user may specify flags with the same name, but + when <c>ct_run</c> calls <c>erl</c> to start the Erlang node (this + makes it possible to add directories to the code server path, + change the cookie on the node, start more applications, and so on).</p> + + <p>With the optional flag <c>-erl_args</c>, options on the <c>ct_run</c> + command line can be divided into two groups:</p> + + <list type="bulleted"> + <item>One group that <c>Common Test</c> is to process (those + preceding <c>-erl_args</c>).</item> + <item>One group that <c>Common Test</c> is to ignore and pass on + directly to the emulator (those following <c>-erl_args</c>).</item> + </list> + + <p>Options preceding <c>-erl_args</c> that <c>Common Test</c> + does not recognize are also passed on to the emulator untouched. + By <c>-erl_args</c> the user can specify flags with the same name, but with different destinations, on the <c>ct_run</c> command line.</p> - <p>If <c>-pa</c> or <c>-pz</c> flags are specified in the Common Test group of options - (preceding <c>-erl_args</c>), relative directories will be converted to - absolute and re-inserted into the code path by Common Test (to avoid - problems loading user modules when Common Test changes working directory - during test runs). Common Test will however ignore <c>-pa</c> and <c>-pz</c> flags - following <c>-erl_args</c> on the command line. These directories are added - to the code path normally (i.e. on specified form)</p> - - <p>Exit status is set before the program ends. Value <c>0</c> indicates a successful - test result, <c>1</c> indicates one or more failed or auto-skipped test cases, and - <c>2</c> indicates test execution failure.</p> - - <p>If <c>ct_run</c> is called with option:</p> - <pre>-help</pre> - <p>it prints all valid start flags to stdout.</p> - </description> + <p>If flags <c>-pa</c> or <c>-pz</c> are specified in the + <c>Common Test</c> group of options (preceding <c>-erl_args</c>), + relative directories are converted to absolute and reinserted into + the code path by <c>Common Test</c>. This is to avoid problems + loading user modules when <c>Common Test</c> changes working directory + during test runs. However, <c>Common Test</c> ignores flags <c>-pa</c> + and <c>-pz</c> following <c>-erl_args</c> on the command line. These + directories are added to the code path normally (that is, on specified + form).</p> + + <p>Exit status is set before the program ends. Value <c>0</c> indicates + a successful test result, <c>1</c> indicates one or more failed or + auto-skipped test cases, and <c>2</c> indicates test execution failure.</p> + + <p>If <c>ct_run</c> is called with option <c>-help</c>, it prints all + valid start flags to <c>stdout</c>.</p> + </description> <section> <marker id="ct_run"></marker> - <title>Run tests from command line</title> + <title>Run Tests from Command Line</title> <pre> - ct_run -dir TestDir1 TestDir2 .. TestDirN | - [-dir TestDir] -suite Suite1 Suite2 .. SuiteN - [-group Groups1 Groups2 .. GroupsN] [-case Case1 Case2 .. CaseN] - [-step [config | keep_inactive]] - [-config ConfigFile1 ConfigFile2 .. ConfigFileN] - [-userconfig CallbackModule1 ConfigString1 and CallbackModule2 - ConfigString2 and .. CallbackModuleN ConfigStringN] - [-decrypt_key Key] | [-decrypt_file KeyFile] - [-label Label] - [-logdir LogDir] - [-logopts LogOpts] - [-verbosity GenVLevel | [Category1 VLevel1 and - Category2 VLevel2 and .. CategoryN VLevelN]] - [-silent_connections [ConnType1 ConnType2 .. ConnTypeN]] - [-stylesheet CSSFile] - [-cover CoverCfgFile] - [-cover_stop Bool] - [-event_handler EvHandler1 EvHandler2 .. EvHandlerN] | - [-event_handler_init EvHandler1 InitArg1 and - EvHandler2 InitArg2 and .. EvHandlerN InitArgN] - [-include InclDir1 InclDir2 .. InclDirN] - [-no_auto_compile] - [-abort_if_missing_suites] - [-muliply_timetraps Multiplier] - [-scale_timetraps] - [-create_priv_dir auto_per_run | auto_per_tc | manual_per_tc] - [-repeat N] | - [-duration HHMMSS [-force_stop [skip_rest]]] | - [-until [YYMoMoDD]HHMMSS [-force_stop [skip_rest]]] - [-basic_html] - [-ct_hooks CTHModule1 CTHOpts1 and CTHModule2 CTHOpts2 and .. - CTHModuleN CTHOptsN] - [-exit_status ignore_config] - [-help] - </pre> + ct_run -dir TestDir1 TestDir2 .. TestDirN | + [-dir TestDir] -suite Suite1 Suite2 .. SuiteN + [-group Groups1 Groups2 .. GroupsN] [-case Case1 Case2 .. CaseN] + [-step [config | keep_inactive]] + [-config ConfigFile1 ConfigFile2 .. ConfigFileN] + [-userconfig CallbackModule1 ConfigString1 and CallbackModule2 + ConfigString2 and .. CallbackModuleN ConfigStringN] + [-decrypt_key Key] | [-decrypt_file KeyFile] + [-label Label] + [-logdir LogDir] + [-logopts LogOpts] + [-verbosity GenVLevel | [Category1 VLevel1 and + Category2 VLevel2 and .. CategoryN VLevelN]] + [-silent_connections [ConnType1 ConnType2 .. ConnTypeN]] + [-stylesheet CSSFile] + [-cover CoverCfgFile] + [-cover_stop Bool] + [-event_handler EvHandler1 EvHandler2 .. EvHandlerN] | + [-event_handler_init EvHandler1 InitArg1 and + EvHandler2 InitArg2 and .. EvHandlerN InitArgN] + [-include InclDir1 InclDir2 .. InclDirN] + [-no_auto_compile] + [-abort_if_missing_suites] + [-muliply_timetraps Multiplier] + [-scale_timetraps] + [-create_priv_dir auto_per_run | auto_per_tc | manual_per_tc] + [-repeat N] | + [-duration HHMMSS [-force_stop [skip_rest]]] | + [-until [YYMoMoDD]HHMMSS [-force_stop [skip_rest]]] + [-basic_html] + [-ct_hooks CTHModule1 CTHOpts1 and CTHModule2 CTHOpts2 and .. + CTHModuleN CTHOptsN] + [-exit_status ignore_config] + [-help]</pre> </section> + <section> - <title>Run tests using test specification</title> + <title>Run Tests using Test Specification</title> <pre> - ct_run -spec TestSpec1 TestSpec2 .. TestSpecN - [-join_specs] - [-config ConfigFile1 ConfigFile2 .. ConfigFileN] - [-userconfig CallbackModule1 ConfigString1 and CallbackModule2 - ConfigString2 and .. and CallbackModuleN ConfigStringN] - [-decrypt_key Key] | [-decrypt_file KeyFile] - [-label Label] - [-logdir LogDir] - [-logopts LogOpts] - [-verbosity GenVLevel | [Category1 VLevel1 and - Category2 VLevel2 and .. CategoryN VLevelN]] - [-allow_user_terms] - [-silent_connections [ConnType1 ConnType2 .. ConnTypeN]] - [-stylesheet CSSFile] - [-cover CoverCfgFile] - [-cover_stop Bool] - [-event_handler EvHandler1 EvHandler2 .. EvHandlerN] | - [-event_handler_init EvHandler1 InitArg1 and - EvHandler2 InitArg2 and .. EvHandlerN InitArgN] - [-include InclDir1 InclDir2 .. InclDirN] - [-no_auto_compile] - [-abort_if_missing_suites] - [-muliply_timetraps Multiplier] - [-scale_timetraps] - [-create_priv_dir auto_per_run | auto_per_tc | manual_per_tc] - [-repeat N] | - [-duration HHMMSS [-force_stop [skip_rest]]] | - [-until [YYMoMoDD]HHMMSS [-force_stop [skip_rest]]] - [-basic_html] - [-ct_hooks CTHModule1 CTHOpts1 and CTHModule2 CTHOpts2 and .. - CTHModuleN CTHOptsN] - [-exit_status ignore_config] - </pre> + ct_run -spec TestSpec1 TestSpec2 .. TestSpecN + [-join_specs] + [-config ConfigFile1 ConfigFile2 .. ConfigFileN] + [-userconfig CallbackModule1 ConfigString1 and CallbackModule2 + ConfigString2 and .. and CallbackModuleN ConfigStringN] + [-decrypt_key Key] | [-decrypt_file KeyFile] + [-label Label] + [-logdir LogDir] + [-logopts LogOpts] + [-verbosity GenVLevel | [Category1 VLevel1 and + Category2 VLevel2 and .. CategoryN VLevelN]] + [-allow_user_terms] + [-silent_connections [ConnType1 ConnType2 .. ConnTypeN]] + [-stylesheet CSSFile] + [-cover CoverCfgFile] + [-cover_stop Bool] + [-event_handler EvHandler1 EvHandler2 .. EvHandlerN] | + [-event_handler_init EvHandler1 InitArg1 and + EvHandler2 InitArg2 and .. EvHandlerN InitArgN] + [-include InclDir1 InclDir2 .. InclDirN] + [-no_auto_compile] + [-abort_if_missing_suites] + [-muliply_timetraps Multiplier] + [-scale_timetraps] + [-create_priv_dir auto_per_run | auto_per_tc | manual_per_tc] + [-repeat N] | + [-duration HHMMSS [-force_stop [skip_rest]]] | + [-until [YYMoMoDD]HHMMSS [-force_stop [skip_rest]]] + [-basic_html] + [-ct_hooks CTHModule1 CTHOpts1 and CTHModule2 CTHOpts2 and .. + CTHModuleN CTHOptsN] + [-exit_status ignore_config]</pre> </section> + <section> - <title>Run tests in web based GUI</title> + <title>Run Tests in Web-Based GUI</title> <pre> - ct_run -vts [-browser Browser] - [-dir TestDir1 TestDir2 .. TestDirN] | - [[dir TestDir] -suite Suite [[-group Group] [-case Case]]] - [-config ConfigFile1 ConfigFile2 .. ConfigFileN] - [-userconfig CallbackModule1 ConfigString1 and CallbackModule2 - ConfigString2 and .. and CallbackModuleN ConfigStringN] - [-logopts LogOpts] - [-verbosity GenVLevel | [Category1 VLevel1 and - Category2 VLevel2 and .. CategoryN VLevelN]] - [-decrypt_key Key] | [-decrypt_file KeyFile] - [-include InclDir1 InclDir2 .. InclDirN] - [-no_auto_compile] - [-abort_if_missing_suites] - [-muliply_timetraps Multiplier] - [-scale_timetraps] - [-create_priv_dir auto_per_run | auto_per_tc | manual_per_tc] - [-basic_html]</pre> + ct_run -vts [-browser Browser] + [-dir TestDir1 TestDir2 .. TestDirN] | + [[dir TestDir] -suite Suite [[-group Group] [-case Case]]] + [-config ConfigFile1 ConfigFile2 .. ConfigFileN] + [-userconfig CallbackModule1 ConfigString1 and CallbackModule2 + ConfigString2 and .. and CallbackModuleN ConfigStringN] + [-logopts LogOpts] + [-verbosity GenVLevel | [Category1 VLevel1 and + Category2 VLevel2 and .. CategoryN VLevelN]] + [-decrypt_key Key] | [-decrypt_file KeyFile] + [-include InclDir1 InclDir2 .. InclDirN] + [-no_auto_compile] + [-abort_if_missing_suites] + [-muliply_timetraps Multiplier] + [-scale_timetraps] + [-create_priv_dir auto_per_run | auto_per_tc | manual_per_tc] + [-basic_html]</pre> </section> + <section> - <title>Refresh the HTML index files</title> + <title>Refresh HTML Index Files</title> <pre> - ct_run -refresh_logs [-logdir LogDir] [-basic_html]</pre> + ct_run -refresh_logs [-logdir LogDir] [-basic_html]</pre> </section> + <section> - <title>Run CT in interactive mode</title> + <title>Run Common Test in Interactive Mode</title> <pre> - ct_run -shell - [-config ConfigFile1 ConfigFile2 ... ConfigFileN] - [-userconfig CallbackModule1 ConfigString1 and CallbackModule2 - ConfigString2 and .. and CallbackModuleN ConfigStringN] - [-decrypt_key Key] | [-decrypt_file KeyFile]</pre> + ct_run -shell + [-config ConfigFile1 ConfigFile2 ... ConfigFileN] + [-userconfig CallbackModule1 ConfigString1 and CallbackModule2 + ConfigString2 and .. and CallbackModuleN ConfigStringN] + [-decrypt_key Key] | [-decrypt_file KeyFile]</pre> </section> + <section> - <title>Start a Common Test Master node</title> + <title>Start a Common Test Master Node</title> <pre> - ct_run -ctmaster</pre> + ct_run -ctmaster</pre> </section> <section> - <title>See also</title> - <p>Please read the <seealso marker="run_test_chapter">Running Test Suites</seealso> - chapter in the Common Test User's Guide for information about the meaning of the - different start flags.</p> + <title>See Also</title> + <p>For information about the start flags, see section + <seealso marker="run_test_chapter">Running Tests and Analyzing + Results</seealso> in the User's Guide.</p> </section> </comref> + diff --git a/lib/common_test/doc/src/ct_slave.xml b/lib/common_test/doc/src/ct_slave.xml new file mode 100644 index 0000000000..44a7b7873f --- /dev/null +++ b/lib/common_test/doc/src/ct_slave.xml @@ -0,0 +1,221 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>ct_slave</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>ct_slave.xml</file> + </header> + <module>ct_slave</module> + <modulesummary>Common Test framework functions for starting and stopping + nodes for Large-Scale Testing.</modulesummary> + + <description> + + <p><c>Common Test</c> framework functions for starting and stopping nodes + for Large-Scale Testing.</p> + + <p>This module exports functions used by the <c>Common Test</c> + Master to start and stop "slave" nodes. It is the default callback + module for the <c>{init, node_start}</c> term in the Test + Specification.</p> + + </description> + + <funcs> + <func> + <name>start(Node) -> Result</name> + <fsummary>Starts an Erlang node with name Node on the local + host.</fsummary> + <type> + <v>Node = atom()</v> + <v>Result = {ok, NodeName} | {error, Reason, NodeName}</v> + <v>Reason = already_started | started_not_connected | boot_timeout | init_timeout | startup_timeout | not_alive</v> + <v>NodeName = atom()</v> + </type> + <desc><marker id="start-1"/> + <p>Starts an Erlang node with name <c>Node</c> on the local host.</p> + + <p>See also + <seealso marker="#start-3"><c>ct_slave:start/3</c></seealso>.</p> + </desc> + </func> + + <func> + <name>start(HostOrNode, NodeOrOpts) -> Result</name> + <fsummary>Starts an Erlang node with default options on a specified + host, or on the local host with specified options.</fsummary> + <type> + <v>HostOrNode = atom()</v> + <v>NodeOrOpts = atom() | list()</v> + <v>Result = {ok, NodeName} | {error, Reason, NodeName}</v> + <v>Reason = already_started | started_not_connected | boot_timeout | init_timeout | startup_timeout | not_alive</v> + <v>NodeName = atom()</v> + </type> + <desc><marker id="start-2"/> + <p>Starts an Erlang node with default options on a specified host, or + on the local host with specified options. That is, the call is + interpreted as <c>start(Host, Node)</c> when the second argument is + atom-valued and <c>start(Node, Opts)</c> when it is list-valued.</p> + + <p>See also + <seealso marker="#start-3"><c>ct_slave:start/3</c></seealso>.</p> + </desc> + </func> + + <func> + <name>start(Host, Node, Opts) -> Result</name> + <fsummary>Starts an Erlang node with name Node on host Host as + specified by the combination of options in Opts.</fsummary> + <type> + <v>Node = atom()</v> + <v>Host = atom()</v> + <v>Opts = [OptTuples]</v> + <v>OptTuples = {username, Username} | {password, Password} | {boot_timeout, BootTimeout} | {init_timeout, InitTimeout} | {startup_timeout, StartupTimeout} | {startup_functions, StartupFunctions} | {monitor_master, Monitor} | {kill_if_fail, KillIfFail} | {erl_flags, ErlangFlags} | {env, [{EnvVar, Value}]}</v> + <v>Username = string()</v> + <v>Password = string()</v> + <v>BootTimeout = integer()</v> + <v>InitTimeout = integer()</v> + <v>StartupTimeout = integer()</v> + <v>StartupFunctions = [StartupFunctionSpec]</v> + <v>StartupFunctionSpec = {Module, Function, Arguments}</v> + <v>Module = atom()</v> + <v>Function = atom()</v> + <v>Arguments = [term]</v> + <v>Monitor = bool()</v> + <v>KillIfFail = bool()</v> + <v>ErlangFlags = string()</v> + <v>EnvVar = string()</v> + <v>Value = string()</v> + <v>Result = {ok, NodeName} | {error, Reason, NodeName}</v> + <v>Reason = already_started | started_not_connected | boot_timeout | init_timeout | startup_timeout | not_alive</v> + <v>NodeName = atom()</v> + </type> + <desc><marker id="start-3"/> + <p>Starts an Erlang node with name <c>Node</c> on host <c>Host</c> as + specified by the combination of options in <c>Opts</c>.</p> + + <p>Options <c>Username</c> and <c>Password</c> are used to log on to the + remote host <c>Host</c>. <c>Username</c>, if omitted, defaults to + the current username. <c>Password</c> is empty by default.</p> + + <p>A list of functions specified in option <c>Startup</c> are + executed after startup of the node. Notice that all used modules + are to be present in the code path on <c>Host</c>.</p> + + <p>The time-outs are applied as follows:</p> + + <taglist> + <tag><c>BootTimeout</c></tag> + <item><p>The time to start the Erlang node, in seconds. Defaults to + 3 seconds. If the node is not pingable within this time, the result + <c>{error, boot_timeout, NodeName}</c> is returned.</p></item> + <tag><c>InitTimeout</c></tag> + <item><p>The time to wait for the node until it calls the internal + callback function informing master about a successful startup. + Defaults to 1 second. In case of a timed out message, the result + <c>{error, init_timeout, NodeName}</c> is returned.</p></item> + <tag><c>StartupTimeout</c></tag> + <item><p>The time to wait until the node stops to run + <c>StartupFunctions</c>. Defaults to 1 second. If this time-out + occurs, the result <c>{error, startup_timeout, NodeName}</c> is + returned.</p></item> + </taglist> + + <p><em>Options:</em></p> + + <taglist> + <tag><c>monitor_master</c></tag> + <item><p>Specifies if the slave node is to be stopped if the + master node stops. Defaults to <c>false</c>.</p></item> + <tag><c>kill_if_fail</c></tag> + <item><p>Specifies if the slave node is to be killed if a time-out + occurs during initialization or startup. Defaults to <c>true</c>. + Notice that the node can also be still alive it the boot time-out + occurred, but it is not killed in this case.</p></item> + <tag><c>erlang_flags</c></tag> + <item><p>Specifies which flags are added to the parameters of the + executable <c>erl</c>.</p></item> + <tag><c>env</c></tag> + <item><p>Specifies a list of environment variables that will extend + the environment.</p></item> + </taglist> + + <p><em>Special return values:</em></p> + + <list type="bulleted"> + <item><p><c>{error, already_started, NodeName}</c> if the node + with the specified name is already started on a specified + host.</p></item> + <item><p><c>{error, started_not_connected, NodeName}</c> if the + node is started, but not connected to the master node.</p></item> + <item><p><c>{error, not_alive, NodeName}</c> if the node on which + <seealso marker="#start-3"><c>ct_slave:start/3</c></seealso> is + called, is not alive. Notice that <c>NodeName</c> is the name of + the current node in this case.</p></item> + </list> + </desc> + </func> + + <func> + <name>stop(Node) -> Result</name> + <fsummary>Stops the running Erlang node with name Node on the local + host.</fsummary> + <type> + <v>Node = atom()</v> + <v>Result = {ok, NodeName} | {error, Reason, NodeName}</v> + <v>Reason = not_started | not_connected | stop_timeout</v> + </type> + <desc><marker id="stop-1"/> + <p>Stops the running Erlang node with name <c>Node</c> on the local + host.</p> + </desc> + </func> + + <func> + <name>stop(Host, Node) -> Result</name> + <fsummary>Stops the running Erlang node with name Node on host + Host.</fsummary> + <type> + <v>Host = atom()</v> + <v>Node = atom()</v> + <v>Result = {ok, NodeName} | {error, Reason, NodeName}</v> + <v>Reason = not_started | not_connected | stop_timeout</v> + <v>NodeName = atom()</v> + </type> + <desc><marker id="stop-2"/> + <p>Stops the running Erlang node with name <c>Node</c> on host + <c>Host</c>.</p> + </desc> + </func> + </funcs> + +</erlref> + + diff --git a/lib/common_test/doc/src/ct_snmp.xml b/lib/common_test/doc/src/ct_snmp.xml new file mode 100644 index 0000000000..d001fb24ec --- /dev/null +++ b/lib/common_test/doc/src/ct_snmp.xml @@ -0,0 +1,523 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>ct_snmp</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>ct_snmp.xml</file> + </header> + <module>ct_snmp</module> + <modulesummary>Common Test user interface module for the SNMP application.</modulesummary> + + <description> + + <p><c>Common Test</c> user interface module for the <c>SNMP</c> + application.</p> + + <p>The purpose of this module is to simplify SNMP configuration for the + test case writer. Many test cases can use default values for common + operations and then no SNMP configuration files need to be supplied. + When it is necessary to change particular configuration parameters, a + subset of the relevant SNMP configuration files can be passed to + <c>ct_snmp</c> by <c>Common Test</c> configuration files. For more + specialized configuration parameters, a simple SNMP configuration file + can be placed in the test suite data directory. To simplify the test + suite, <c>Common Test</c> keeps track of some of the SNMP manager + information. This way the test suite does not have to handle as many + input parameters as if it had to interface wthe OTP SNMP manager + directly.</p> + + <p><em>Configurable SNMP Manager and Agent Parameters:</em></p> + + <p>Manager configuration:</p> + + <taglist> + <tag><c>[{start_manager, boolean()}</c></tag> + <item><p>Optional. Default is <c>true</c>.</p></item> + <tag><c>{users, [{user_name(), [call_back_module(), user_data()]}]}</c></tag> + <item><p>Optional.</p></item> + <tag><c>{usm_users, [{usm_user_name(), [usm_config()]}]}</c></tag> + <item><p>Optional. SNMPv3 only.</p></item> + <tag><c>{managed_agents,[{agent_name(), [user_name(), agent_ip(), agent_port(), [agent_config()]]}]}</c></tag> + <item><p><c>managed_agents</c> is optional.</p></item> + <tag><c>{max_msg_size, integer()}</c></tag> + <item><p>Optional. Default is <c>484</c>.</p></item> + <tag><c>{mgr_port, integer()}</c></tag> + <item><p>Optional. Default is <c>5000</c>.</p></item> + <tag><c>{engine _id, string()}</c></tag> + <item><p>Optional. Default is <c>"mgrEngine"</c>.</p></item> + </taglist> + + <p>Agent configuration:</p> + + <taglist> + <tag><c>{start_agent, boolean()}</c></tag> + <item><p>Optional. Default is <c>false</c>.</p></item> + <tag><c>{agent_sysname, string()}</c></tag> + <item><p>Optional. Default is <c>"ct_test"</c>.</p></item> + <tag><c>{agent_manager_ip, manager_ip()}</c></tag> + <item><p>Optional. Default is <c>localhost</c>.</p></item> + <tag><c>{agent_vsns, list()}</c></tag> + <item><p>Optional. Default is <c>[v2]</c>.</p></item> + <tag><c>{agent_trap_udp, integer()}</c></tag> + <item><p>Optional. Default is <c>5000</c>.</p></item> + <tag><c>{agent_udp, integer()}</c></tag> + <item><p>Optional. Default is <c>4000</c>.</p></item> + <tag><c>{agent_notify_type, atom()}</c></tag> + <item><p>Optional. Default is <c>trap</c>.</p></item> + <tag><c>{agent_sec_type, sec_type()}</c></tag> + <item><p>Optional. Default is <c>none</c>.</p></item> + <tag><c>{agent_passwd, string()}</c></tag> + <item><p>Optional. Default is <c>""</c>.</p></item> + <tag><c>{agent_engine_id, string()}</c></tag> + <item><p>Optional. Default is <c>"agentEngine"</c>.</p></item> + <tag><c>{agent_max_msg_size, string()}</c></tag> + <item><p>Optional. Default is <c>484</c>.</p></item> + </taglist> + + <p>The following parameters represents the SNMP configuration files + <c>context.conf</c>, <c>standard.conf</c>, <c>community.conf</c>, + <c>vacm.conf</c>, <c>usm.conf</c>, <c>notify.conf</c>, + <c>target_addr.conf</c>, and <c>target_params.conf</c>. Notice that + all values in <c>agent.conf</c> can be modified by the parameters + listed above. All these configuration files have default values set by + the <c>SNMP</c> application. These values can be overridden by suppling + a list of valid configuration values or a file located in the test + suites data directory, which can produce a list of valid configuration + values if you apply function <c>file:consult/1</c> to the file.</p> + + <taglist> + <tag><c>{agent_contexts, [term()] | {data_dir_file, rel_path()}}</c></tag> + <item><p>Optional.</p></item> + <tag><c>{agent_community, [term()] | {data_dir_file, rel_path()}}</c></tag> + <item><p>Optional.</p></item> + <tag><c>{agent_sysinfo, [term()] | {data_dir_file, rel_path()}}</c></tag> + <item><p>Optional.</p></item> + <tag><c>{agent_vacm, [term()] | {data_dir_file, rel_path()}}</c></tag> + <item><p>Optional.</p></item> + <tag><c>{agent_usm, [term()] | {data_dir_file, rel_path()}}</c></tag> + <item><p>Optional.</p></item> + <tag><c>{agent_notify_def, [term()] | {data_dir_file, rel_path()}}</c></tag> + <item><p>Optional.</p></item> + <tag><c>{agent_target_address_def, [term()] | {data_dir_file, rel_path()}}</c></tag> + <item><p>Optional.</p></item> + <tag><c>{agent_target_param_def, [term()] | {data_dir_file, rel_path()}}</c></tag> + <item><p>Optional.</p></item> + </taglist> + + <p>Parameter <c>MgrAgentConfName</c> in the functions is to be a name + you allocate in your test suite using a <c>require</c> statement. + Example (where <c>MgrAgentConfName = snmp_mgr_agent</c>):</p> + + <pre> + suite() -> [{require, snmp_mgr_agent, snmp}].</pre> + + <p>or</p> + + <pre> + ct:require(snmp_mgr_agent, snmp).</pre> + + <p>Notice that USM users are needed for SNMPv3 configuration and are + not to be confused with users.</p> + + <p>SNMP traps, inform, and report messages are handled by the user + callback module. For details, see the + <seealso marker="snmp:index"><c>SNMP</c></seealso> application.</p> + + <p>It is recommended to use the <c>.hrl</c> files created by the + Erlang/OTP MIB compiler to define the Object Identifiers (OIDs). + For example, to get the Erlang node name from <c>erlNodeTable</c> + in the OTP-MIB:</p> + + <pre> + Oid = ?erlNodeEntry ++ [?erlNodeName, 1]</pre> + + <p>Furthermore, values can be set for <c>SNMP</c> application configuration + parameters, <c>config</c>, <c>server</c>, <c>net_if</c>, and so on (for + a list of valid parameters and types, see the <seealso marker="snmp:users_guide"><c>User's Guide for the SNMP application</c></seealso>). This is + done by defining a configuration data variable on the following form:</p> + + <pre> + {snmp_app, [{manager, [snmp_app_manager_params()]}, + {agent, [snmp_app_agent_params()]}]}.</pre> + + <p>A name for the data must be allocated in the suite using + <c>require</c> (see the example above). Pass this name as argument + <c>SnmpAppConfName</c> to + <seealso marker="#start-3"><c>ct_snmp:start/3</c></seealso>. + <c>ct_snmp</c> specifies default values for some <c>SNMP</c> application + configuration parameters (such as <c>{verbosity,trace}</c> for parameter + <c>config</c>). This set of defaults is merged with the parameters + specified by the user. The user values override <c>ct_snmp</c> + defaults.</p> + + </description> + + <section> + <title>Data Types</title> + <marker id="types"/> + <taglist> + <tag><c>agent_config() = {Item, Value}</c></tag> + <item><marker id="type-agent_config"/> </item> + <tag><c>agent_ip() = ip()</c></tag> + <item><marker id="type-agent_ip"/> </item> + <tag><c>agent_name() = atom()</c></tag> + <item><marker id="type-agent_name"/> </item> + <tag><c>agent_port() = integer()</c></tag> + <item><marker id="type-agent_port"/> </item> + <tag><c>call_back_module() = atom()</c></tag> + <item><marker id="type-call_back_module"/> </item> + <tag><c>error_index() = integer()</c></tag> + <item><marker id="type-error_index"/> </item> + <tag><c>error_status() = noError | atom()</c></tag> + <item><marker id="type-error_status"/> </item> + <tag><c>ip() = string() | {integer(), integer(), integer(), integer()}</c></tag> + <item><marker id="type-ip"/> </item> + <tag><c>manager_ip() = ip()</c></tag> + <item><marker id="type-manager_ip"/> </item> + <tag><c>oid() = [byte()]</c></tag> + <item><marker id="type-oid"/> </item> + <tag><c>oids() = [oid()]</c></tag> + <item><marker id="type-oids"/> </item> + <tag><c>rel_path() = string()</c></tag> + <item><marker id="type-rel_path"/> </item> + <tag><c>sec_type() = none | minimum | semi</c></tag> + <item><marker id="type-sec_type"/> </item> + <tag><c>snmp_app_agent_params() = term()</c></tag> + <item><marker id="type-snmp_app_agent_params"/> </item> + <tag><c>snmp_app_manager_params() = term()</c></tag> + <item><marker id="type-snmp_app_manager_params"/> </item> + <tag><c>snmpreply() = {error_status(), error_index(), varbinds()}</c></tag> + <item><marker id="type-snmpreply"/> </item> + <tag><c>user_data() = term()</c></tag> + <item><marker id="type-user_data"/> </item> + <tag><c>user_name() = atom()</c></tag> + <item><marker id="type-user_name"/> </item> + <tag><c>usm_config() = {Item, Value}</c></tag> + <item><marker id="type-usm_config"/> </item> + <tag><c>usm_user_name() = string()</c></tag> + <item><marker id="type-usm_user_name"/> </item> + <tag><c>value_type() = o('OBJECT IDENTIFIER') | i('INTEGER') | u('Unsigned32') | g('Unsigned32') | s('OCTET STRING')</c></tag> + <item><marker id="type-value_type"/> </item> + <tag><c>var_and_val() = {oid(), value_type(), value()}</c></tag> + <item><marker id="type-var_and_val"/> </item> + <tag><c>varbind() = term()</c></tag> + <item><marker id="type-varbind"/> </item> + <tag><c>varbinds() = [varbind()]</c></tag> + <item><marker id="type-varbinds"/> </item> + <tag><c>varsandvals() = [var_and_val()]</c></tag> + <item><marker id="type-varsandvals"/> </item> + </taglist> + <p>These data types are described in the documentation for + the <seealso marker="snmp:index"><c>SNMP</c></seealso> application.</p> + </section> + + <funcs> + <func> + <name>get_next_values(Agent, Oids, MgrAgentConfName) -> SnmpReply</name> + <fsummary>Issues a synchronous SNMP get next request.</fsummary> + <type> + <v>Agent = agent_name()</v> + <v>Oids = oids()</v> + <v>MgrAgentConfName = atom()</v> + <v>SnmpReply = snmpreply()</v> + </type> + <desc><marker id="get_next_values-3"/> + <p>Issues a synchronous SNMP <c>get next</c> request.</p> + </desc> + </func> + + <func> + <name>get_values(Agent, Oids, MgrAgentConfName) -> SnmpReply</name> + <fsummary>Issues a synchronous SNMP get request.</fsummary> + <type> + <v>Agent = agent_name()</v> + <v>Oids = oids()</v> + <v>MgrAgentConfName = atom()</v> + <v>SnmpReply = snmpreply()</v> + </type> + <desc><marker id="get_values-3"/> + <p>Issues a synchronous SNMP <c>get</c> request.</p> + </desc> + </func> + + <func> + <name>load_mibs(Mibs) -> ok | {error, Reason}</name> + <fsummary>Loads the MIBs into agent snmp_master_agent.</fsummary> + <type> + <v>Mibs = [MibName]</v> + <v>MibName = string()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="load_mibs-1"/> + <p>Loads the MIBs into agent <c>snmp_master_agent</c>.</p> + </desc> + </func> + + <func> + <name>register_agents(MgrAgentConfName, ManagedAgents) -> ok | {error, Reason}</name> + <fsummary>Explicitly instructs the manager to handle this + agent.</fsummary> + <type> + <v>MgrAgentConfName = atom()</v> + <v>ManagedAgents = [agent()]</v> + <v>Reason = term()</v> + </type> + <desc><marker id="register_agents-2"/> + <p>Explicitly instructs the manager to handle this agent. Corresponds + to making an entry in <c>agents.conf</c>.</p> + + <p>This function tries to register the specified managed agents, without + checking if any of them exist. To change a registered managed agent, + the agent must first be unregistered.</p> + </desc> + </func> + + <func> + <name>register_users(MgrAgentConfName, Users) -> ok | {error, Reason}</name> + <fsummary>Registers the manager entity (=user) responsible for specific + agent(s).</fsummary> + <type> + <v>MgrAgentConfName = atom()</v> + <v>Users = [user()]</v> + <v>Reason = term()</v> + </type> + <desc><marker id="register_users-2"/> + <p>Registers the manager entity (=user) responsible for specific + agent(s). Corresponds to making an entry in <c>users.conf</c>.</p> + + <p>This function tries to register the specified users, without checking + if any of them exist. To change a registered user, the user must + first be unregistered.</p> + </desc> + </func> + + <func> + <name>register_usm_users(MgrAgentConfName, UsmUsers) -> ok | {error, Reason}</name> + <fsummary>Explicitly instructs the manager to handle this USM user.</fsummary> + <type> + <v>MgrAgentConfName = atom()</v> + <v>UsmUsers = [usm_user()]</v> + <v>Reason = term()</v> + </type> + <desc><marker id="register_usm_users-2"/> + <p>Explicitly instructs the manager to handle this USM user. + Corresponds to making an entry in <c>usm.conf</c>.</p> + + <p>This function tries to register the specified users, without checking + if any of them exist. To change a registered user, the user must + first be unregistered.</p> + </desc> + </func> + + <func> + <name>set_info(Config) -> [{Agent, OldVarsAndVals, NewVarsAndVals}]</name> + <fsummary>Returns a list of all successful set requests performed in the + test case in reverse order.</fsummary> + <type> + <v>Config = [{Key, Value}]</v> + <v>Agent = agent_name()</v> + <v>OldVarsAndVals = varsandvals()</v> + <v>NewVarsAndVals = varsandvals()</v> + </type> + <desc><marker id="set_info-1"/> + <p>Returns a list of all successful <c>set</c> requests performed in + the test case in reverse order. The list contains the involved user + and agent, the value before <c>set</c>, and the new value. This is + intended to simplify the cleanup in function <c>end_per_testcase</c>, + that is, the undoing of the <c>set</c> requests and their possible + side-effects.</p> + </desc> + </func> + + <func> + <name>set_values(Agent, VarsAndVals, MgrAgentConfName, Config) -> SnmpReply</name> + <fsummary>Issues a synchronous SNMP set request.</fsummary> + <type> + <v>Agent = agent_name()</v> + <v>Oids = oids()</v> + <v>MgrAgentConfName = atom()</v> + <v>Config = [{Key, Value}]</v> + <v>SnmpReply = snmpreply()</v> + </type> + <desc><marker id="set_values-4"/> + <p>Issues a synchronous SNMP <c>set</c> request.</p> + </desc> + </func> + + <func> + <name>start(Config, MgrAgentConfName) -> ok</name> + <fsummary>Equivalent to start(Config, MgrAgentConfName, + undefined).</fsummary> + <desc><marker id="start-2"/> + <p>Equivalent to + <seealso marker="#start-3"><c>ct_snmp:start(Config, MgrAgentConfName, + undefined)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>start(Config, MgrAgentConfName, SnmpAppConfName) -> ok</name> + <fsummary>Starts an SNMP manager and/or agent.</fsummary> + <type> + <v>Config = [{Key, Value}]</v> + <v>Key = atom()</v> + <v>Value = term()</v> + <v>MgrAgentConfName = atom()</v> + <v>SnmpConfName = atom()</v> + </type> + <desc><marker id="start-3"/> + <p>Starts an SNMP manager and/or agent. In the manager case, + registrations of users and agents, as specified by the configuration + <c>MgrAgentConfName</c>, are performed. When using SNMPv3, called + USM users are also registered. Users, <c>usm_users</c>, and + managed agents can also be registered later using + <seealso marker="#register_users-2"><c>ct_snmp:register_users/2</c></seealso>, + <seealso marker="#register_agents-2"><c>ct_snmp:register_agents/2</c></seealso>, + and + <seealso marker="#register_usm_users-2"><c>ct_snmp:register_usm_users/2</c></seealso>.</p> + + <p>The agent started is called <c>snmp_master_agent</c>. Use + <seealso marker="#load_mibs-1"><c>ct_snmp:load_mibs/1</c></seealso> + to load MIBs into the agent.</p> + + <p>With <c>SnmpAppConfName</c> SNMP applications can be configured + with parameters <c>config</c>, <c>mibs</c>, <c>net_if</c>, and so on. + The values are merged with (and possibly override) default values + set by <c>ct_snmp</c>.</p> + </desc> + </func> + + <func> + <name>stop(Config) -> ok</name> + <fsummary>Stops the SNMP manager and/or agent, and removes all files + created.</fsummary> + <type> + <v>Config = [{Key, Value}]</v> + <v>Key = atom()</v> + <v>Value = term()</v> + </type> + <desc><marker id="stop-1"/> + <p>Stops the SNMP manager and/or agent, and removes all files + created.</p> + </desc> + </func> + + <func> + <name>unload_mibs(Mibs) -> ok | {error, Reason}</name> + <fsummary>Unloads the MIBs from agent snmp_master_agent.</fsummary> + <type> + <v>Mibs = [MibName]</v> + <v>MibName = string()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="unload_mibs-1"/> + <p>Unloads the MIBs from agent <c>snmp_master_agent</c>.</p> + </desc> + </func> + + <func> + <name>unregister_agents(MgrAgentConfName) -> ok</name> + <fsummary>Unregisters all managed agents.</fsummary> + <type> + <v>MgrAgentConfName = atom()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="unregister_agents-1"/> + <p>Unregisters all managed agents.</p> + </desc> + </func> + + <func> + <name>unregister_agents(MgrAgentConfName, ManagedAgents) -> ok</name> + <fsummary>Unregisters the specified managed agents.</fsummary> + <type> + <v>MgrAgentConfName = atom()</v> + <v>ManagedAgents = [agent_name()]</v> + <v>Reason = term()</v> + </type> + <desc><marker id="unregister_agents-2"/> + <p>Unregisters the specified managed agents.</p> + </desc> + </func> + + <func> + <name>unregister_users(MgrAgentConfName) -> ok</name> + <fsummary>Unregisters all users.</fsummary> + <type> + <v>MgrAgentConfName = atom()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="unregister_users-1"/> + <p>Unregisters all users.</p> + </desc> + </func> + + <func> + <name>unregister_users(MgrAgentConfName, Users) -> ok</name> + <fsummary>Unregisters the specified users.</fsummary> + <type> + <v>MgrAgentConfName = atom()</v> + <v>Users = [user_name()]</v> + <v>Reason = term()</v> + </type> + <desc><marker id="unregister_users-2"/> + <p>Unregisters the specified users.</p> + </desc> + </func> + + <func> + <name>unregister_usm_users(MgrAgentConfName) -> ok</name> + <fsummary>Unregisters all USM users.</fsummary> + <type> + <v>MgrAgentConfName = atom()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="unregister_usm_users-1"/> + <p>Unregisters all USM users.</p> + </desc> + </func> + + <func> + <name>unregister_usm_users(MgrAgentConfName, UsmUsers) -> ok</name> + <fsummary>Unregisters the specified USM users.</fsummary> + <type> + <v>MgrAgentConfName = atom()</v> + <v>UsmUsers = [usm_user_name()]</v> + <v>Reason = term()</v> + </type> + <desc><marker id="unregister_usm_users-2"/> + <p>Unregisters the specified USM users.</p> + </desc> + </func> + </funcs> + +</erlref> + + diff --git a/lib/common_test/doc/src/ct_ssh.xml b/lib/common_test/doc/src/ct_ssh.xml new file mode 100644 index 0000000000..92b1f60b8c --- /dev/null +++ b/lib/common_test/doc/src/ct_ssh.xml @@ -0,0 +1,1150 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>ct_ssh</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>ct_ssh.xml</file> + </header> + <module>ct_ssh</module> + <modulesummary>SSH/SFTP client module.</modulesummary> + +<description> + + <p>SSH/SFTP client module.</p> + + <p>This module uses application <c>SSH</c>, which provides detailed + information about, for example, functions, types, and options.</p> + + <p>Argument <c>Server</c> in the SFTP functions is only to be used for + SFTP sessions that have been started on existing SSH connections + (that is, when the original connection type is <c>ssh</c>). Whenever + the connection type is <c>sftp</c>, use the SSH connection reference + only.</p> + + <p>The following options are valid for specifying an SSH/SFTP + connection (that is, can be used as configuration elements):</p> + + <pre> + [{ConnType, Addr}, + {port, Port}, + {user, UserName} + {password, Pwd} + {user_dir, String} + {public_key_alg, PubKeyAlg} + {connect_timeout, Timeout} + {key_cb, KeyCallbackMod}]</pre> + + <p><c>ConnType = ssh | sftp</c>.</p> + + <p>For other types, see + <seealso marker="ssh:ssh"><c>ssh:ssh(3)</c></seealso>.</p> + + <p>All time-out parameters in <c>ct_ssh</c> functions are values in + milliseconds.</p> + + </description> + + <section> + <title>Data Types</title> + <marker id="types"/> + <taglist> + <tag><c>connection() = handle() | target_name()</c></tag> + <item><marker id="type-connection"/> + <p>For <c>target_name</c>, see module + <seealso marker="ct"><c>ct</c></seealso>.</p></item> + + <tag><c>handle() = handle()</c></tag> + <item><marker id="type-handle"/> + <p>Handle for a specific SSH/SFTP connection, see module + <seealso marker="ct"><c>ct</c></seealso>.</p></item> + + <tag><c>ssh_sftp_return() = term()</c></tag> + <item><marker id="type-ssh_sftp_return"/> + <p>Return value from an + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp</c></seealso> + function.</p></item> + </taglist> + </section> + + <funcs> + <func> + <name>apread(SSH, Handle, Position, Length) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="apread-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>apread(SSH, Server, Handle, Position, Length) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="apread-5"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>apwrite(SSH, Handle, Position, Data) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="apwrite-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>apwrite(SSH, Server, Handle, Position, Data) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="apwrite-5"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>aread(SSH, Handle, Len) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="aread-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>aread(SSH, Server, Handle, Len) -> Result</name> + <fsummary>For inforamtion and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="aread-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>awrite(SSH, Handle, Data) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="awrite-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>awrite(SSH, Server, Handle, Data) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="awrite-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>close(SSH, Handle) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="close-2"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>close(SSH, Server, Handle) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="close-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>connect(KeyOrName) -> {ok, Handle} | {error, Reason}</name> + <fsummary>Equivalent to connect(KeyOrName, host, []).</fsummary> + <desc><marker id="connect-1"/> + <p>Equivalent to + <seealso marker="#connect-3"><c>ct_ssh:connect(KeyOrName, host, + [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>connect(KeyOrName, ConnType) -> {ok, Handle} | {error, Reason}</name> + <fsummary>Equivalent to connect(KeyOrName, ConnType, []).</fsummary> + <desc><marker id="connect-2"/> + <p>Equivalent to + <seealso marker="#connect-3"><c>ct_ssh:connect(KeyOrName, ConnType, + [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>connect(KeyOrName, ConnType, ExtraOpts) -> {ok, Handle} | {error, Reason}</name> + <fsummary>Opens an SSH or SFTP connection using the information + associated with KeyOrName.</fsummary> + <type> + <v>KeyOrName = Key | Name</v> + <v>Key = atom()</v> + <v>Name = target_name()</v> + <v>ConnType = ssh | sftp | host</v> + <v>ExtraOpts = ssh_connect_options()</v> + <v>Handle = handle()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="connect-3"/> + <p>Opens an SSH or SFTP connection using the information associated + with <c>KeyOrName</c>.</p> + + <p>If <c>Name</c> (an alias name for <c>Key</c>) is used to identify + the connection, this name can be used as connection reference for + subsequent calls. Only one open connection at a time associated + with <c>Name</c> is possible. If <c>Key</c> is used, the returned + handle must be used for subsequent calls (multiple connections can + be opened using the configuration data specified by <c>Key</c>).</p> + + <p>For information on how to create a new <c>Name</c>, see + <seealso marker="ct#require-2"><c>ct:require/2</c></seealso>.</p> + + <p>For <c>target_name</c>, see module + <seealso marker="ct"><c>ct</c></seealso>.</p> + + <p><c>ConnType</c> always overrides the type specified in the + address tuple in the configuration data (and in <c>ExtraOpts</c>). + So it is possible to, for example, open an SFTP connection + directly using data originally specifying an SSH connection. Value + <c>host</c> means that the connection type specified by the host + option (either in the configuration data or in <c>ExtraOpts</c>) + is used.</p> + + <p><c>ExtraOpts</c> (optional) are extra SSH options to be added to + the configuration data for <c>KeyOrName</c>. The extra options + override any existing options with the same key in the + configuration data. For details on valid SSH options, see + application <seealso marker="ssh:index"><c>SSH</c></seealso>.</p> + </desc> + </func> + + <func> + <name>del_dir(SSH, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="del_dir-2"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>del_dir(SSH, Server, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="del_dir-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>delete(SSH, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="delete-2"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>delete(SSH, Server, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="delete-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>disconnect(SSH) -> ok | {error, Reason}</name> + <fsummary>Closes an SSH/SFTP connection.</fsummary> + <type> + <v>SSH = connection()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="disconnect-1"/> + <p>Closes an SSH/SFTP connection.</p> + </desc> + </func> + + <func> + <name>exec(SSH, Command) -> {ok, Data} | {error, Reason}</name> + <fsummary>Equivalent to exec(SSH, Command, DefaultTimeout).</fsummary> + <desc><marker id="exec-2"/> + <p>Equivalent to + <seealso marker="#exec-3"><c>ct_ssh:exec(SSH, Command, + DefaultTimeout)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>exec(SSH, Command, Timeout) -> {ok, Data} | {error, Reason}</name> + <fsummary>Requests server to perform Command.</fsummary> + <type> + <v>SSH = connection()</v> + <v>Command = string()</v> + <v>Timeout = integer()</v> + <v>Data = list()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="exec-3"/> + <p>Requests server to perform <c>Command</c>. A session channel is + opened automatically for the request. <c>Data</c> is received from + the server as a result of the command.</p> + </desc> + </func> + + <func> + <name>exec(SSH, ChannelId, Command, Timeout) -> {ok, Data} | {error, Reason}</name> + <fsummary>Requests server to perform Command.</fsummary> + <type> + <v>SSH = connection()</v> + <v>ChannelId = integer()</v> + <v>Command = string()</v> + <v>Timeout = integer()</v> + <v>Data = list()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="exec-4"/> + <p>Requests server to perform <c>Command</c>. A previously opened + session channel is used for the request. <c>Data</c> is received + from the server as a result of the command.</p> + </desc> + </func> + + <func> + <name>get_file_info(SSH, Handle) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="get_file_info-2"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>get_file_info(SSH, Server, Handle) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="get_file_info-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>list_dir(SSH, Path) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="list_dir-2"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>list_dir(SSH, Server, Path) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="list_dir-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>make_dir(SSH, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="make_dir-2"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>make_dir(SSH, Server, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="make_dir-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>make_symlink(SSH, Name, Target) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="make_symlink-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>make_symlink(SSH, Server, Name, Target) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="make_symlink-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>open(SSH, File, Mode) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="open-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>open(SSH, Server, File, Mode) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="open-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>opendir(SSH, Path) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="opendir-2"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>opendir(SSH, Server, Path) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="opendir-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>position(SSH, Handle, Location) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="position-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>position(SSH, Server, Handle, Location) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="position-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>pread(SSH, Handle, Position, Length) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="pread-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>pread(SSH, Server, Handle, Position, Length) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="pread-5"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>pwrite(SSH, Handle, Position, Data) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="pwrite-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>pwrite(SSH, Server, Handle, Position, Data) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="pwrite-5"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>read(SSH, Handle, Len) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="read-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>read(SSH, Server, Handle, Len) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="read-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>read_file(SSH, File) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="read_file-2"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>read_file(SSH, Server, File) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="read_file-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>read_file_info(SSH, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="read_file_info-2"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>read_file_info(SSH, Server, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="read_file_info-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>read_link(SSH, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="read_link-2"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>read_link(SSH, Server, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="read_link-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>read_link_info(SSH, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="read_link_info-2"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>read_link_info(SSH, Server, Name) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="read_link_info-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>receive_response(SSH, ChannelId) -> {ok, Data} | {error, Reason}</name> + <fsummary>Equivalent to receive_response(SSH, ChannelId, + close).</fsummary> + <desc><marker id="receive_response-2"/> + <p>Equivalent to + <seealso marker="#receive_response-3"><c>ct_ssh:receive_response(SSH, +ChannelId, close)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>receive_response(SSH, ChannelId, End) -> {ok, Data} | {error, Reason}</name> + <fsummary>Equivalent to receive_response(SSH, ChannelId, End, + DefaultTimeout).</fsummary> + <desc><marker id="receive_response-3"/> + <p>Equivalent to + <seealso marker="#receive_response-4"><c>ct_ssh:receive_response(SSH, +ChannelId, End, DefaultTimeout)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>receive_response(SSH, ChannelId, End, Timeout) -> {ok, Data} | {timeout, Data} | {error, Reason}</name> + <fsummary>Receives expected data from server on the specified session + channel.</fsummary> + <type> + <v>SSH = connection()</v> + <v>ChannelId = integer()</v> + <v>End = Fun | close | timeout</v> + <v>Timeout = integer()</v> + <v>Data = list()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="receive_response-4"/> + <p>Receives expected data from server on the specified session + channel.</p> + + <p>If <c>End == close</c>, data is returned to the caller when the + channel is closed by the server. If a time-out occurs before this + happens, the function returns <c>{timeout,Data}</c> (where + <c>Data</c> is the data received so far).</p> + <p>If <c>End == timeout</c>, a time-out is expected and + <c>{ok,Data}</c> is returned both in the case of a time-out and + when the channel is closed.</p> + + <p>If <c>End</c> is a fun, this fun is called with one argument, the + data value in a received <c>ssh_cm</c> message (see + <seealso marker="ssh:ssh_connection"><c>ssh:ssh_connection(3)</c></seealso>. + The fun is to return either <c>true</c> to end the receiving + operation (and have the so far collected data returned) or + <c>false</c> to wait for more data from the server. Even if a fun + is supplied, the function returns immediately if the server closes + the channel).</p> + </desc> + </func> + + <func> + <name>rename(SSH, OldName, NewName) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="rename-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>rename(SSH, Server, OldName, NewName) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="rename-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send(SSH, ChannelId, Data) -> ok | {error, Reason}</name> + <fsummary>Equivalent to send(SSH, ChannelId, 0, Data, + DefaultTimeout).</fsummary> + <desc><marker id="send-3"/> + <p>Equivalent to <seealso marker="#send-5"><c>ct_ssh:send(SSH, + ChannelId, 0, Data, DefaultTimeout)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send(SSH, ChannelId, Data, Timeout) -> ok | {error, Reason}</name> + <fsummary>Equivalent to send(SSH, ChannelId, 0, Data, Timeout).</fsummary> + <desc><marker id="send-4"/> + <p>Equivalent to <seealso marker="#send-5"><c>ct_ssh:send(SSH, + ChannelId, 0, Data, Timeout)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send(SSH, ChannelId, Type, Data, Timeout) -> ok | {error, Reason}</name> + <fsummary>Sends data to server on specified session channel.</fsummary> + <type> + <v>SSH = connection()</v> + <v>ChannelId = integer()</v> + <v>Type = integer()</v> + <v>Data = list()</v> + <v>Timeout = integer()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="send-5"/> + <p>Sends data to server on specified session channel.</p> + </desc> + </func> + + <func> + <name>send_and_receive(SSH, ChannelId, Data) -> {ok, Data} | {error, Reason}</name> + <fsummary>Equivalent to send_and_receive(SSH, ChannelId, Data, + close).</fsummary> + <desc><marker id="send_and_receive-3"/> + <p>Equivalent to + <seealso marker="#send_and_receive-4"><c>ct_ssh:send_and_receive(SSH, + ChannelId, Data, close)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send_and_receive(SSH, ChannelId, Data, End) -> {ok, Data} | {error, Reason}</name> + <fsummary>Equivalent to send_and_receive(SSH, ChannelId, 0, Data, End, + DefaultTimeout).</fsummary> + <desc><marker id="send_and_receive-4"/> + <p>Equivalent to + <seealso marker="#send_and_receive-6"><c>ct_ssh;send_and_receive(SSH, +ChannelId, 0, Data, End, DefaultTimeout)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send_and_receive(SSH, ChannelId, Data, End, Timeout) -> {ok, Data} | {error, Reason}</name> + <fsummary>Equivalent to send_and_receive(SSH, ChannelId, 0, Data, End, + Timeout).</fsummary> + <desc><marker id="send_and_receive-5"/> + <p>Equivalent to + <seealso marker="#send_and_receive-6"><c>ct_ssh:send_and_receive(SSH, +ChannelId, 0, Data, End, Timeout)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send_and_receive(SSH, ChannelId, Type, Data, End, Timeout) -> {ok, Data} | {error, Reason}</name> + <fsummary>Sends data to server on specified session channel and waits + to receive the server response.</fsummary> + <type> + <v>SSH = connection()</v> + <v>ChannelId = integer()</v> + <v>Type = integer()</v> + <v>Data = list()</v> + <v>End = Fun | close | timeout</v> + <v>Timeout = integer()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="send_and_receive-6"/> + <p>Sends data to server on specified session channel and waits to + receive the server response.</p> + + <p>For details on argument <c>End</c>, see + <seealso marker="#receive_response-4"><c>ct_ssh:receive_response/4</c></seealso>.</p> + </desc> + </func> + + <func> + <name>session_close(SSH, ChannelId) -> ok | {error, Reason}</name> + <fsummary>Closes an SSH session channel.</fsummary> + <type> + <v>SSH = connection()</v> + <v>ChannelId = integer()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="session_close-2"/> + <p>Closes an SSH session channel.</p> + </desc> + </func> + + <func> + <name>session_open(SSH) -> {ok, ChannelId} | {error, Reason}</name> + <fsummary>Equivalent to session_open(SSH, DefaultTimeout).</fsummary> + <desc><marker id="session_open-1"/> + <p>Equivalent to + <seealso marker="#session_open-2"><c>ct_ssh:session_open(SSH, + DefaultTimeout)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>session_open(SSH, Timeout) -> {ok, ChannelId} | {error, Reason}</name> + <fsummary>Opens a channel for an SSH session.</fsummary> + <type> + <v>SSH = connection()</v> + <v>Timeout = integer()</v> + <v>ChannelId = integer()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="session_open-2"/> + <p>Opens a channel for an SSH session.</p> + </desc> + </func> + + <func> + <name>sftp_connect(SSH) -> {ok, Server} | {error, Reason}</name> + <fsummary>Starts an SFTP session on an already existing SSH + connection.</fsummary> + <type> + <v>SSH = connection()</v> + <v>Server = pid()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="sftp_connect-1"/> + <p>Starts an SFTP session on an already existing SSH connection. + <c>Server</c> identifies the new session and must be specified + whenever SFTP requests are to be sent.</p> + </desc> + </func> + + <func> + <name>subsystem(SSH, ChannelId, Subsystem) -> Status | {error, Reason}</name> + <fsummary>Equivalent to subsystem(SSH, ChannelId, Subsystem, + DefaultTimeout).</fsummary> + <desc><marker id="subsystem-3"/> + <p>Equivalent to + <seealso marker="#subsystem-4"><c>ct_ssh:subsystem(SSH, ChannelId, + Subsystem, DefaultTimeout)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>subsystem(SSH, ChannelId, Subsystem, Timeout) -> Status | {error, Reason}</name> + <fsummary>Sends a request to execute a predefined subsystem.</fsummary> + <type> + <v>SSH = connection()</v> + <v>ChannelId = integer()</v> + <v>Subsystem = string()</v> + <v>Timeout = integer()</v> + <v>Status = success | failure</v> + <v>Reason = term()</v> + </type> + <desc><marker id="subsystem-4"/> + <p>Sends a request to execute a predefined subsystem.</p> + </desc> + </func> + + <func> + <name>write(SSH, Handle, Data) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="write-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>write(SSH, Server, Handle, Data) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="write-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>write_file(SSH, File, Iolist) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="write_file-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>write_file(SSH, Server, File, Iolist) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="write_file-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>write_file_info(SSH, Name, Info) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="write_file_info-3"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>write_file_info(SSH, Server, Name, Info) -> Result</name> + <fsummary>For information and other types, see ssh_sftp(3).</fsummary> + <type> + <v>SSH = connection()</v> + <v>Result = ssh_sftp_return() | {error, Reason}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="write_file_info-4"/> + <p>For information and other types, see + <seealso marker="ssh:ssh_sftp"><c>ssh:ssh_sftp(3)</c></seealso>.</p> + </desc> + </func> + </funcs> + +</erlref> + + diff --git a/lib/common_test/doc/src/ct_telnet.xml b/lib/common_test/doc/src/ct_telnet.xml new file mode 100644 index 0000000000..b7ba352104 --- /dev/null +++ b/lib/common_test/doc/src/ct_telnet.xml @@ -0,0 +1,601 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>ct_telnet</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>ct_telnet.xml</file> + </header> + <module>ct_telnet</module> + <modulesummary>Common Test specific layer on top of Telnet client ct_telnet_client.erl</modulesummary> + + <description> + + <p><c>Common Test</c> specific layer on top of Telnet client + <c>ct_telnet_client.erl</c>.</p> + + <p>Use this module to set up Telnet connections, send commands, and + perform string matching on the result. For information about how to use + <c>ct_telnet</c> and configure connections, specifically for UNIX hosts, + see the + <seealso marker="unix_telnet"><c>unix_telnet</c></seealso> manual page. + </p> + + <p>Default values defined in <c>ct_telnet</c>:</p> + <marker id="Default_values"/> + + <list type="bulleted"> + <item><p>Connection timeout (time to wait for connection) = 10 + seconds</p></item> + <item><p>Command timeout (time to wait for a command to return) = + 10 seconds</p></item> + <item><p>Max number of reconnection attempts = 3</p></item> + <item><p>Reconnection interval (time to wait in between + reconnection attempts) = 5 seconds</p></item> + <item><p>Keep alive (sends NOP to the server every 8 sec if + connection is idle) = <c>true</c></p></item> + <item><p>Polling limit (max number of times to poll to get a + remaining string terminated) = 0</p></item> + <item><p>Polling interval (sleep time between polls) = 1 second</p> + </item> + </list> + + <p>These parameters can be modified by the user with the following + configuration term:</p> + + <pre> + {telnet_settings, [{connect_timeout,Millisec}, + {command_timeout,Millisec}, + {reconnection_attempts,N}, + {reconnection_interval,Millisec}, + {keep_alive,Bool}, + {poll_limit,N}, + {poll_interval,Millisec}]}.</pre> + + <p><c>Millisec = integer(), N = integer()</c></p> + + <p>Enter the <c>telnet_settings</c> term in a configuration file included + in the test and <c>ct_telnet</c> retrieves the information + automatically.</p> + + <p><c>keep_alive</c> can be specified per connection, if necessary. For + details, see + <seealso marker="unix_telnet"><c>unix_telnet</c></seealso>.</p> + + </description> + + <section> + <title>Logging</title> + <marker id="Logging"/> + + <p>The default logging behavior of <c>ct_telnet</c> is to print information + about performed operations, commands, and their corresponding results to + the test case HTML log. The following is not printed to the HTML + log: text strings sent from the Telnet server that are not explicitly + received by a <c>ct_telnet</c> function, such as <c>expect/3</c>. + However, <c>ct_telnet</c> can be configured to use a special purpose + event handler, implemented in <c>ct_conn_log_h</c>, for logging + <em>all</em> Telnet traffic. To use this handler, install a <c>Common + Test</c> hook named <c>cth_conn_log</c>. Example (using the test suite + information function):</p> + + <pre> + suite() -> + [{ct_hooks, [{cth_conn_log, [{conn_mod(),hook_options()}]}]}].</pre> + + <p><c>conn_mod()</c> is the name of the <c>Common Test</c> module + implementing the connection protocol, that is, <c>ct_telnet</c>.</p> + + <p>The <c>cth_conn_log</c> hook performs unformatted logging of Telnet + data to a separate text file. All Telnet communication is captured and + printed, including any data sent from the server. The link to + this text file is located at the top of the test case HTML log.</p> + + <p>By default, data for all Telnet connections is logged in one common + file (named <c>default</c>), which can get messy, for example, if + multiple Telnet sessions are running in parallel. Therefore a separate + log file can be created for each connection. To configure this, use hook + option <c>hosts</c> and list the names of the servers/connections + to be used in the suite. The connections must be named for this to + work (see + <seealso marker="#open-1"><c>ct_telnet:open/1,2,3,4</c></seealso>).</p> + + <p>Hook option <c>log_type</c> can be used to change the + <c>cth_conn_log</c> behavior. The default value of this option is + <c>raw</c>, which results in the behavior described above. If the value + is set to <c>html</c>, all Telnet communication is printed to the test + case HTML log instead.</p> + + <p>All <c>cth_conn_log</c> hook options described can also be + specified in a configuration file with configuration variable + <c>ct_conn_log</c>.</p> + + <p><em>Example:</em></p> + + <pre> + {ct_conn_log, [{ct_telnet,[{log_type,raw}, + {hosts,[key_or_name()]}]}]}</pre> + + <note> + <p>Hook options specified in a configuration file overwrite any + hard-coded hook options in the test suite.</p> + </note> + + <marker id="Logging_example"/> + <p><em>Logging Example:</em></p> + + <p>The following <c>ct_hooks</c> statement causes printing of Telnet + traffic to separate logs for the connections <c>server1</c> and + <c>server2</c>. Traffic for any other connections is logged in the + default Telnet log.</p> + + <pre> + suite() -> + [{ct_hooks, + [{cth_conn_log, [{ct_telnet,[{hosts,[server1,server2]}]}]}]}].</pre> + + <p>As previously explained, this specification can also be provided by an + entry like the following in a configuration file:</p> + + <pre> + {ct_conn_log, [{ct_telnet,[{hosts,[server1,server2]}]}]}.</pre> + + <p>In this case the <c>ct_hooks</c> statement in the test suite can look + as follows:</p> + + <pre> + suite() -> + [{ct_hooks, [{cth_conn_log, []}]}].</pre> + </section> + + <section> + <title>Data Types</title> + <marker id="types"/> + <taglist> + <tag><c>connection() = handle() | {target_name(), connection_type()} | target_name()</c></tag> + <item><marker id="type-connection"/> + <p>For <c>target_name()</c>, see module + <seealso marker="ct"><c>ct</c></seealso>.</p></item> + + <tag><c>connection_type() = telnet | ts1 | ts2</c></tag> + <item><marker id="type-connection_type"/> </item> + + <tag><c>handle() = handle()</c></tag> + <item><marker id="type-handle"/> + <p>Handle for a specific Telnet connection, see module + <seealso marker="ct"><c>ct</c></seealso>.</p></item> + + <tag><c>prompt_regexp() = string()</c></tag> + <item><marker id="type-prompt_regexp"/> + <p>Regular expression matching all possible prompts for a specific + target type. <c>regexp</c> must not have any groups, that is, when + matching, <c>re:run/3</c> (in <c>STDLIB</c>) must return a list with + one single element.</p></item> + </taglist> + </section> + + <funcs> + <func> + <name>close(Connection) -> ok | {error, Reason}</name> + <fsummary>Closes the Telnet connection and stops the process managing + it.</fsummary> + <type> + <v>Connection = connection()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="close-1"/> + <p>Closes the Telnet connection and stops the process managing it.</p> + + <p>A connection can be associated with a target name and/or a handle. + If <c>Connection</c> has no associated target name, it can only + be closed with the handle value (see + <seealso marker="#open-4"><c>ct_telnet:open/4</c></seealso>).</p> + </desc> + </func> + + <func> + <name>cmd(Connection, Cmd) -> {ok, Data} | {error, Reason}</name> + <fsummary>Equivalent to cmd(Connection, Cmd, []).</fsummary> + <desc><marker id="cmd-2"/> + <p>Equivalent to + <seealso marker="#cmd-3"><c>ct_telnet:cmd(Connection, Cmd, + [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>cmd(Connection, Cmd, Opts) -> {ok, Data} | {error, Reason}</name> + <fsummary>Sends a command through Telnet and waits for prompt.</fsummary> + <type> + <v>Connection = connection()</v> + <v>Cmd = string()</v> + <v>Opts = [Opt]</v> + <v>Opt = {timeout, timeout()} | {newline, boolean()}</v> + <v>Data = [string()]</v> + <v>Reason = term()</v> + </type> + <desc><marker id="cmd-3"/> + <p>Sends a command through Telnet and waits for prompt.</p> + + <p>By default, this function adds a new line to the end of the + specified command. If this is not desired, use option + <c>{newline,false}</c>. This is necessary, for example, when + sending Telnet command sequences prefixed with character + Interprete As Command (IAC).</p> + + <p>Option <c>timeout</c> specifies how long the client must wait + for prompt. If the time expires, the function returns + <c>{error,timeout}</c>. For information about the default value + for the command timeout, see the + <seealso marker="#Default_values">list of default values</seealso> + in the beginning of this module.</p> + </desc> + </func> + + <func> + <name>cmdf(Connection, CmdFormat, Args) -> {ok, Data} | {error, Reason}</name> + <fsummary>Equivalent to cmdf(Connection, CmdFormat, Args, []).</fsummary> + <desc><marker id="cmdf-3"/> + <p>Equivalent to + <seealso marker="#cmdf-4"><c>ct_telnet:cmdf(Connection, CmdFormat, + Args, [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>cmdf(Connection, CmdFormat, Args, Opts) -> {ok, Data} | {error, Reason}</name> + <fsummary>Sends a Telnet command and waits for prompt (uses a format + string and a list of arguments to build the command).</fsummary> + <type> + <v>Connection = connection()</v> + <v>CmdFormat = string()</v> + <v>Args = list()</v> + <v>Opts = [Opt]</v> + <v>Opt = {timeout, timeout()} | {newline, boolean()}</v> + <v>Data = [string()]</v> + <v>Reason = term()</v> + </type> + <desc><marker id="cmdf-4"/> + <p>Sends a Telnet command and waits for prompt (uses a format string + and a list of arguments to build the command).</p> + + <p>For details, see + <seealso marker="#cmd-3"><c>ct_telnet:cmd/3</c></seealso>.</p> + </desc> + </func> + + <func> + <name>expect(Connection, Patterns) -> term()</name> + <fsummary>Equivalent to expect(Connections, Patterns, []).</fsummary> + <desc><marker id="expect-2"/> + <p>Equivalent to + <seealso marker="#expect-3"><c>ct_telnet:expect(Connections, + Patterns, [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>expect(Connection, Patterns, Opts) -> {ok, Match} | {ok, MatchList, HaltReason} | {error, Reason}</name> + <fsummary>Gets data from Telnet and waits for the expected + pattern.</fsummary> + <type> + <v>Connection = connection()</v> + <v>Patterns = Pattern | [Pattern]</v> + <v>Pattern = string() | {Tag, string()} | prompt | {prompt, Prompt}</v> + <v>Prompt = string()</v> + <v>Tag = term()</v> + <v>Opts = [Opt]</v> + <v>Opt = {idle_timeout, IdleTimeout} | {total_timeout, TotalTimeout} | repeat | {repeat, N} | sequence | {halt, HaltPatterns} | ignore_prompt | no_prompt_check | wait_for_prompt | {wait_for_prompt, Prompt}</v> + <v>IdleTimeout = infinity | integer()</v> + <v>TotalTimeout = infinity | integer()</v> + <v>N = integer()</v> + <v>HaltPatterns = Patterns</v> + <v>MatchList = [Match]</v> + <v>Match = RxMatch | {Tag, RxMatch} | {prompt, Prompt}</v> + <v>RxMatch = [string()]</v> + <v>HaltReason = done | Match</v> + <v>Reason = timeout | {prompt, Prompt}</v> + </type> + <desc><marker id="expect-3"/> + <p>Gets data from Telnet and waits for the expected pattern.</p> + + <p><c>Pattern</c> can be a POSIX regular expression. The function + returns when a pattern is successfully matched (at least one, in + the case of multiple patterns).</p> + + <p><c>RxMatch</c> is a list of matched strings. It looks as + follows <c>[FullMatch, SubMatch1, SubMatch2, ...]</c>, where + <c>FullMatch</c> is the string matched by the whole regular + expression, and <c>SubMatchN</c> is the string that matched + subexpression number <c>N</c>. Subexpressions are denoted with + <c>(' ')</c> in the regular expression.</p> + + <p>If a <c>Tag</c> is speciifed, the returned <c>Match</c> also + includes the matched <c>Tag</c>. Otherwise, only <c>RxMatch</c> + is returned.</p> + + <p><em>Options:</em></p> + + <taglist> + <tag><c>idle_timeout</c></tag> + <item><p>Indicates that the function must return if the Telnet + client is idle (that is, if no data is received) for more than + <c>IdleTimeout</c> milliseconds. Default time-out is 10 + seconds.</p></item> + <tag><c>total_timeout</c></tag> + <item><p>Sets a time limit for the complete <c>expect</c> operation. + After <c>TotalTimeout</c> milliseconds, <c>{error,timeout}</c> + is returned. Default is <c>infinity</c> (that is, no time + limit).</p></item> + <tag><c>ignore_prompt | no_prompt_check</c></tag> + <item><p>>The function returns when a prompt is received, even if + no pattern has yet been matched, and + <c>{error,{prompt,Prompt}}</c> is returned. However, this + behavior can be modified with option <c>ignore_prompt</c> or + option <c>no_prompt_check</c>, which tells <c>expect</c> to + return only when a match is found or after a time-out.</p></item> + <tag><c>ignore_prompt</c></tag> + <item><p><c>ct_telnet</c> ignores any prompt found. This option is + useful if data sent by the server can include a pattern + matching prompt <c>regexp</c> (as returned by + <c>TargedMod:get_prompt_regexp/0</c>), but is not to not cause + the function to return.</p></item> + <tag><c>no_prompt_check</c></tag> + <item><p><c>ct_telnet</c> does not search for a prompt at all. This + is useful if, for example, <c>Pattern</c> itself matches the + prompt.</p></item> + <tag><c>wait_for_prompt</c></tag> + <item><p>Forces <c>ct_telnet</c> to wait until the prompt string + is received before returning (even if a pattern has already been + matched). This is equal to calling + <c>expect(Conn, Patterns++[{prompt,Prompt}], [sequence|Opts])</c>. + Notice that option <c>idle_timeout</c> and <c>total_timeout</c> + can abort the operation of waiting for prompt.</p></item> + <tag><c>repeat | repeat, N</c></tag> + <item><p>The pattern(s) must be matched multiple times. If <c>N</c> + is speciified, the pattern(s) are matched <c>N</c> times, and + the function returns <c>HaltReason = done</c>. This option can be + interrupted by one or more <c>HaltPatterns</c>. <c>MatchList</c> + is always returned, that is, a list of <c>Match</c> instead of + only one <c>Match</c>. Also <c>HaltReason</c> is returned.</p> + </item> + <tag><c>sequence</c></tag> + <item><p>All patterns must be matched in a sequence. A match is not + concluded until all patterns are matched. This option can be + interrupted by one or more <c>HaltPatterns</c>. <c>MatchList</c> + is always returned, that is, a list of <c>Match</c> instead of + only one <c>Match</c>. Also <c>HaltReason</c> is returned.</p> + </item> + </taglist> + + <p><em>Example 1:</em></p> + + <pre> + expect(Connection,[{abc,"ABC"},{xyz,"XYZ"}],[sequence,{halt,[{nnn,"NNN"}]}])</pre> + + <p>First this tries to match <c>"ABC"</c>, and then <c>"XYZ"</c>, but + if <c>"NNN"</c> appears, the function returns + <c>{error,{nnn,["NNN"]}}</c>. If both <c>"ABC"</c> and <c>"XYZ"</c> + are matched, the function returns <c>{ok,[AbcMatch,XyzMatch]}</c>.</p> + + <p><em>Example 2:</em></p> + + <pre> + expect(Connection,[{abc,"ABC"},{xyz,"XYZ"}],[{repeat,2},{halt,[{nnn,"NNN"}]}])</pre> + + <p>This tries to match <c>"ABC"</c> or <c>"XYZ"</c> twice. If + <c>"NNN"</c> appears, the function returns + <c>HaltReason = {nnn,["NNN"]}</c>.</p> + + <p>Options <c>repeat</c> and <c>sequence</c> can be combined to + match a sequence multiple times.</p> + </desc> + </func> + + <func> + <name>get_data(Connection) -> {ok, Data} | {error, Reason}</name> + <fsummary>Gets all data received by the Telnet client since the last + command was sent.</fsummary> + <type> + <v>Connection = connection()</v> + <v>Data = [string()]</v> + <v>Reason = term()</v> + </type> + <desc><marker id="get_data-1"/> + <p>Gets all data received by the Telnet client since the last + command was sent. Only newline-terminated strings are returned. + If the last received string has not yet been terminated, the + connection can be polled automatically until the string is + complete.</p> + + <p>The polling feature is controlled by the configuration values + <c>poll_limit</c> and <c>poll_interval</c> and is by default + disabled. This means that the function immediately returns all + complete strings received and saves a remaining non-terminated + string for a later <c>get_data</c> call.</p> + </desc> + </func> + + <func> + <name>open(Name) -> {ok, Handle} | {error, Reason}</name> + <fsummary>Equivalent to open(Name, telnet).</fsummary> + <desc><marker id="open-1"/> + <p>Equivalent to + <seealso marker="#open-2"><c>ct_telnet:open(Name, + telnet)</c></seealso>.</p> + </desc> + </func> + + <func> + <name>open(Name, ConnType) -> {ok, Handle} | {error, Reason}</name> + <fsummary>Opens a Telnet connection to the specified target + host.</fsummary> + <type> + <v>Name = target_name()</v> + <v>ConnType = connection_type()</v> + <v>Handle = handle()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="open-2"/> + <p>Opens a Telnet connection to the specified target host.</p> + </desc> + </func> + + <func> + <name>open(KeyOrName, ConnType, TargetMod) -> {ok, Handle} | {error, Reason}</name> + <fsummary>Equivalent to open(KeyOrName, ConnType, TargetMod, []).</fsummary> + <desc><marker id="open-3"/> + <p>Equivalent to + <seealso marker="#open-4"><c>ct_telnet:ct_telnet:open(KeyOrName, + ConnType, TargetMod, [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>open(KeyOrName, ConnType, TargetMod, Extra) -> {ok, Handle} | {error, Reason}</name> + <fsummary>Opens a Telnet connection to the specified target + host.</fsummary> + <type> + <v>KeyOrName = Key | Name</v> + <v>Key = atom()</v> + <v>Name = target_name()</v> + <v>ConnType = connection_type()</v> + <v>TargetMod = atom()</v> + <v>Extra = term()</v> + <v>Handle = handle()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="open-4"/> + <p>Opens a Telnet connection to the specified target host.</p> + + <p>The target data must exist in a configuration file. The connection + can be associated with <c>Name</c> and/or the returned <c>Handle</c>. + To allocate a name for the target, use one of the following + alternatives:</p> + + <list type="bulleted"> + <item><p><seealso marker="ct#require-2"><c>ct:require/2</c></seealso> + in a test case</p></item> + <item><p>A <c>require</c> statement in the suite information + function (<c>suite/0</c>)</p></item> + <item><p>A <c>require</c> statement in a test case information + function</p></item> + </list> + + <p>If you want the connection to be associated with <c>Handle</c> only + (if you, for example, need to open multiple connections to a host), + use <c>Key</c>, the configuration variable name, to specify the + target. Notice that a connection without an associated target name + can only be closed with the <c>Handle</c> value.</p> + + <p><c>TargetMod</c> is a module that exports the functions + <c>connect(Ip, Port, KeepAlive, Extra)</c> and + <c>get_prompt_regexp()</c> for the specified <c>TargetType</c> + (for example, <c>unix_telnet</c>).</p> + + <p>For <c>target_name()</c>, see module + <seealso marker="ct"><c>ct</c></seealso>.</p> + + <p>See also + <seealso marker="ct#require-2"><c>ct:require/2</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send(Connection, Cmd) -> ok | {error, Reason}</name> + <fsummary>Equivalent to send(Connection, Cmd, []).</fsummary> + <desc><marker id="send-2"/> + <p>Equivalent to + <seealso marker="#send-3"><c>ct_telnet:send(Connection, Cmd, + [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>send(Connection, Cmd, Opts) -> ok | {error, Reason}</name> + <fsummary>Sends a Telnet command and returns immediately.</fsummary> + <type> + <v>Connection = connection()</v> + <v>Cmd = string()</v> + <v>Opts = [Opt]</v> + <v>Opt = {newline, boolean()}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="send-3"/> + <p>Sends a Telnet command and returns immediately.</p> + + <p>By default, this function adds a newline to the end of the + specified command. If this is not desired, option + <c>{newline,false}</c> can be used. This is necessary, for example, + when sending Telnet command sequences prefixed with character + Interprete As Command (IAC).</p> + + <p>The resulting output from the command can be read with + <seealso marker="#get_data-1"><c>ct_telnet:get_data/2</c></seealso> or + <seealso marker="#expect-2"><c>ct_telnet:expect/2,3</c></seealso>.</p> + </desc> + </func> + + <func> + <name>sendf(Connection, CmdFormat, Args) -> ok | {error, Reason}</name> + <fsummary>Equivalent to sendf(Connection, CmdFormat, Args, []).</fsummary> + <desc><marker id="sendf-3"/> + <p>Equivalent to + <seealso marker="#sendf-4"><c>ct_telnet:sendf(Connection, CmdFormat, + Args, [])</c></seealso>.</p> + </desc> + </func> + + <func> + <name>sendf(Connection, CmdFormat, Args, Opts) -> ok | {error, Reason}</name> + <fsummary>Sends a Telnet command and returns immediately (uses a format + string and a list of arguments to build the command).</fsummary> + <type> + <v>Connection = connection()</v> + <v>CmdFormat = string()</v> + <v>Args = list()</v> + <v>Opts = [Opt]</v> + <v>Opt = {newline, boolean()}</v> + <v>Reason = term()</v> + </type> + <desc><marker id="sendf-4"/> + <p>Sends a Telnet command and returns immediately (uses a format + string and a list of arguments to build the command).</p> + </desc> + </func> + </funcs> + + <section> + <title>See Also</title> + <p><seealso marker="unix_telnet"><c>unix_telnet</c></seealso></p> + </section> + +</erlref> + + diff --git a/lib/common_test/doc/src/dependencies_chapter.xml b/lib/common_test/doc/src/dependencies_chapter.xml index fb758d90df..29c54e819a 100644 --- a/lib/common_test/doc/src/dependencies_chapter.xml +++ b/lib/common_test/doc/src/dependencies_chapter.xml @@ -33,217 +33,220 @@ <section> <title>General</title> <p>When creating test suites, it is strongly recommended to not - create dependencies between test cases, i.e. letting test cases + create dependencies between test cases, that is, letting test cases depend on the result of previous test cases. There are various - reasons for this, for example:</p> + reasons for this, such as, the following:</p> - <list> + <list type="bulleted"> <item>It makes it impossible to run test cases individually.</item> - <item>It makes it impossible to run test cases in different order.</item> - <item>It makes debugging very difficult (since a fault could be + <item>It makes it impossible to run test cases in a different order.</item> + <item>It makes debugging difficult (as a fault can be the result of a problem in a different test case than the one failing).</item> - <item>There exists no good and explicit ways to declare dependencies, so - it may be very difficult to see and understand these in test suite + <item>There are no good and explicit ways to declare dependencies, so + it can be difficult to see and understand these in test suite code and in test logs.</item> - <item>Extending, restructuring and maintaining test suites with + <item>Extending, restructuring, and maintaining test suites with test case dependencies is difficult.</item> </list> <p>There are often sufficient means to work around the need for test case dependencies. Generally, the problem is related to the state of - the system under test (SUT). The action of one test case may alter the state - of the system and for some other test case to run properly, the new state + the System Under Test (SUT). The action of one test case can change the + system state. For some other test case to run properly, this new state must be known.</p> <p>Instead of passing data between test cases, it is recommended that the test cases read the state from the SUT and perform assertions - (i.e. let the test case run if the state is as expected, otherwise reset or fail) - and/or use the state to set variables necessary for the test case to execute - properly. Common actions can often be implemented as library functions for - test cases to call to set the SUT in a required state. (Such common actions - may of course also be separately tested if necessary, to ensure they are - working as expected). It is sometimes also possible, but not always desirable, - to group tests together in one test case, i.e. let a test case perform a - "scenario" test (a test that consists of subtests).</p> - - <p>Consider for example a server application under test. The following + (that is, let the test case run if the state is as expected, otherwise reset or fail). + It is also recommended to use the state to set variables necessary for the + test case to execute properly. Common actions can often be implemented as + library functions for test cases to call to set the SUT in a required state. + (Such common actions can also be separately tested, if necessary, + to ensure that they work as expected). It is sometimes also possible, + but not always desirable, to group tests together in one test case, that is, + let a test case perform a "scenario" test (a test consisting of subtests).</p> + + <p>Consider, for example, a server application under test. The following functionality is to be tested:</p> - <list> - <item>Starting the server.</item> - <item>Configuring the server.</item> - <item>Connecting a client to the server.</item> - <item>Disconnecting a client from the server.</item> - <item>Stopping the server.</item> + <list type="bulleted"> + <item>Starting the server</item> + <item>Configuring the server</item> + <item>Connecting a client to the server</item> + <item>Disconnecting a client from the server</item> + <item>Stopping the server</item> </list> - <p>There are obvious dependencies between the listed functions. We can't configure - the server if it hasn't first been started, we can't connect a client until - the server has been properly configured, etc. If we want to have one test - case for each of the functions, we might be tempted to try to always run the + <p>There are obvious dependencies between the listed functions. The server cannot + be configured if it has not first been started, a client connot be connectd until + the server is properly configured, and so on. If we want to have one test + case for each function, we might be tempted to try to always run the test cases in the stated order and carry possible data (identities, handles, - etc) between the cases and therefore introduce dependencies between them. - To avoid this we could consider starting and stopping the server for every test. - We would implement the start and stop action as common functions that may be - called from init_per_testcase and end_per_testcase. (We would of course test - the start and stop functionality separately). The configuration could perhaps also - be implemented as a common function, maybe grouped with the start function. - Finally the testing of connecting and disconnecting a client may be grouped into - one test case. The resulting suite would look something like this:</p> - + and so on) between the cases and therefore introduce dependencies between them.</p> + + <p>To avoid this, we can consider starting and stopping the server for every test. + We can thus implement the start and stop action as common functions to be + called from + <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase</c></seealso> and + <seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso>. + (Remember to test the start and stop functionality separately.) + The configuration can also be implemented as a common function, maybe grouped + with the start function. Finally, the testing of connecting and disconnecting a + client can be grouped into one test case. The resulting suite can look as + follows:</p> <pre> - -module(my_server_SUITE). - -compile(export_all). - -include_lib("ct.hrl"). + -module(my_server_SUITE). + -compile(export_all). + -include_lib("ct.hrl"). + + %%% init and end functions... - %%% init and end functions... + suite() -> [{require,my_server_cfg}]. - suite() -> [{require,my_server_cfg}]. + init_per_testcase(start_and_stop, Config) -> + Config; - init_per_testcase(start_and_stop, Config) -> - Config; + init_per_testcase(config, Config) -> + [{server_pid,start_server()} | Config]; - init_per_testcase(config, Config) -> - [{server_pid,start_server()} | Config]; + init_per_testcase(_, Config) -> + ServerPid = start_server(), + configure_server(), + [{server_pid,ServerPid} | Config]. - init_per_testcase(_, Config) -> - ServerPid = start_server(), - configure_server(), - [{server_pid,ServerPid} | Config]. + end_per_testcase(start_and_stop, _) -> + ok; - end_per_testcase(start_and_stop, _) -> - ok; + end_per_testcase(_, _) -> + ServerPid = ?config(server_pid), + stop_server(ServerPid). - end_per_testcase(_, _) -> - ServerPid = ?config(server_pid), - stop_server(ServerPid). + %%% test cases... - %%% test cases... + all() -> [start_and_stop, config, connect_and_disconnect]. - all() -> [start_and_stop, config, connect_and_disconnect]. + %% test that starting and stopping works + start_and_stop(_) -> + ServerPid = start_server(), + stop_server(ServerPid). - %% test that starting and stopping works - start_and_stop(_) -> - ServerPid = start_server(), - stop_server(ServerPid). + %% configuration test + config(Config) -> + ServerPid = ?config(server_pid, Config), + configure_server(ServerPid). - %% configuration test - config(Config) -> - ServerPid = ?config(server_pid, Config), - configure_server(ServerPid). + %% test connecting and disconnecting client + connect_and_disconnect(Config) -> + ServerPid = ?config(server_pid, Config), + {ok,SessionId} = my_server:connect(ServerPid), + ok = my_server:disconnect(ServerPid, SessionId). - %% test connecting and disconnecting client - connect_and_disconnect(Config) -> - ServerPid = ?config(server_pid, Config), - {ok,SessionId} = my_server:connect(ServerPid), - ok = my_server:disconnect(ServerPid, SessionId). + %%% common functions... - %%% common functions... + start_server() -> + {ok,ServerPid} = my_server:start(), + ServerPid. - start_server() -> - {ok,ServerPid} = my_server:start(), - ServerPid. + stop_server(ServerPid) -> + ok = my_server:stop(), + ok. - stop_server(ServerPid) -> - ok = my_server:stop(), - ok. + configure_server(ServerPid) -> + ServerCfgData = ct:get_config(my_server_cfg), + ok = my_server:configure(ServerPid, ServerCfgData), + ok.</pre> - configure_server(ServerPid) -> - ServerCfgData = ct:get_config(my_server_cfg), - ok = my_server:configure(ServerPid, ServerCfgData), - ok. - </pre> </section> <section> <marker id="save_config"></marker> - <title>Saving configuration data</title> + <title>Saving Configuration Data</title> - <p>There might be situations where it is impossible, or infeasible at least, to - implement independent test cases. Maybe it is simply not possible to read the - SUT state. Maybe resetting the SUT is impossible and it takes much too long + <p>Sometimes it is impossible, or infeasible, to + implement independent test cases. Maybe it is not possible to read the + SUT state. Maybe resetting the SUT is impossible and it takes too long time to restart the system. In situations where test case dependency is necessary, CT offers a structured way to carry data from one test case to the next. The - same mechanism may also be used to carry data from one test suite to the next.</p> + same mechanism can also be used to carry data from one test suite to the next.</p> <p>The mechanism for passing data is called <c>save_config</c>. The idea is that - one test case (or suite) may save the current value of Config - or any list of - key-value tuples - so that it can be read by the next executing test case - (or test suite). The configuration data is not saved permanently but can only - be passed from one case (or suite) to the next.</p> + one test case (or suite) can save the current value of <c>Config</c>, or any list of + key-value tuples, so that the next executing test case (or test suite) can read it. + The configuration data is not saved permanently but can only be passed from one + case (or suite) to the next.</p> - <p>To save <c>Config</c> data, return the tuple:</p> + <p>To save <c>Config</c> data, return tuple <c>{save_config,ConfigList}</c> + from <c>end_per_testcase</c> or from the main test case function.</p> - <p><c>{save_config,ConfigList}</c></p> - - <p>from <c>end_per_testcase</c> or from the main test case function. To read data - saved by a previous test case, use the <c>config</c> macro with a - <c>saved_config</c> key:</p> + <p>To read data saved by a previous test case, use macro <c>config</c> with a + <c>saved_config</c> key as follows:</p> <p><c>{Saver,ConfigList} = ?config(saved_config, Config)</c></p> <p><c>Saver</c> (<c>atom()</c>) is the name of the previous test case (where the - data was saved). The <c>config</c> macro may be used to extract particular data + data was saved). The <c>config</c> macro can be used to extract particular data also from the recalled <c>ConfigList</c>. It is strongly recommended that <c>Saver</c> is always matched to the expected name of the saving test case. - This way problems due to restructuring of the test suite may be avoided. Also it - makes the dependency more explicit and the test suite easier to read and maintain.</p> + This way, problems because of restructuring of the test suite can be avoided. + Also, it makes the dependency more explicit and the test suite easier to read + and maintain.</p> <p>To pass data from one test suite to another, the same mechanism is used. The data - should be saved by the <c>end_per_suite</c> function and read by <c>init_per_suite</c> + is to be saved by finction + <seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite</c></seealso> + and read by function + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite</c></seealso> in the suite that follows. When passing data between suites, <c>Saver</c> carries the name of the test suite.</p> - <p>Example:</p> + <p><em>Example:</em></p> <pre> - -module(server_b_SUITE). - -compile(export_all). - -include_lib("ct.hrl"). - - %%% init and end functions... - - init_per_suite(Config) -> - %% read config saved by previous test suite - {server_a_SUITE,OldConfig} = ?config(saved_config, Config), - %% extract server identity (comes from server_a_SUITE) - ServerId = ?config(server_id, OldConfig), - SessionId = connect_to_server(ServerId), - [{ids,{ServerId,SessionId}} | Config]. - - end_per_suite(Config) -> - %% save config for server_c_SUITE (session_id and server_id) - {save_config,Config} - - %%% test cases... - - all() -> [allocate, deallocate]. - - allocate(Config) -> - {ServerId,SessionId} = ?config(ids, Config), - {ok,Handle} = allocate_resource(ServerId, SessionId), - %% save handle for deallocation test - NewConfig = [{handle,Handle}], - {save_config,NewConfig}. - - deallocate(Config) -> - {ServerId,SessionId} = ?config(ids, Config), - {allocate,OldConfig} = ?config(saved_config, Config), - Handle = ?config(handle, OldConfig), - ok = deallocate_resource(ServerId, SessionId, Handle). - </pre> - - <p>It is also possible to save <c>Config</c> data from a test case that is to be - skipped. To accomplish this, return the following tuple:</p> - - <p><c>{skip_and_save,Reason,ConfigList}</c></p> - - <p>The result will be that the test case is skipped with <c>Reason</c> printed to - the log file (as described in previous chapters), and <c>ConfigList</c> is saved - for the next test case. <c>ConfigList</c> may be read by means of - <c>?config(saved_config, Config)</c>, as described above. <c>skip_and_save</c> - may also be returned from <c>init_per_suite</c>, in which case the saved data can + -module(server_b_SUITE). + -compile(export_all). + -include_lib("ct.hrl"). + + %%% init and end functions... + + init_per_suite(Config) -> + %% read config saved by previous test suite + {server_a_SUITE,OldConfig} = ?config(saved_config, Config), + %% extract server identity (comes from server_a_SUITE) + ServerId = ?config(server_id, OldConfig), + SessionId = connect_to_server(ServerId), + [{ids,{ServerId,SessionId}} | Config]. + + end_per_suite(Config) -> + %% save config for server_c_SUITE (session_id and server_id) + {save_config,Config} + + %%% test cases... + + all() -> [allocate, deallocate]. + + allocate(Config) -> + {ServerId,SessionId} = ?config(ids, Config), + {ok,Handle} = allocate_resource(ServerId, SessionId), + %% save handle for deallocation test + NewConfig = [{handle,Handle}], + {save_config,NewConfig}. + + deallocate(Config) -> + {ServerId,SessionId} = ?config(ids, Config), + {allocate,OldConfig} = ?config(saved_config, Config), + Handle = ?config(handle, OldConfig), + ok = deallocate_resource(ServerId, SessionId, Handle).</pre> + + <p>To save <c>Config</c> data from a test case that is to be + skipped, return tuple + <c>{skip_and_save,Reason,ConfigList}</c>.</p> + + <p>The result is that the test case is skipped with <c>Reason</c> printed to + the log file (as described earlier) and <c>ConfigList</c> is saved + for the next test case. <c>ConfigList</c> can be read using + <c>?config(saved_config, Config)</c>, as described earlier. <c>skip_and_save</c> + can also be returned from <c>init_per_suite</c>. In this case, the saved data can be read by <c>init_per_suite</c> in the suite that follows.</p> </section> @@ -251,60 +254,63 @@ <marker id="sequences"></marker> <title>Sequences</title> - <p>It is possible that test cases depend on each other so that - if one case fails, the following test(s) should not be executed. + <p>Sometimes test cases depend on each other so that + if one case fails, the following tests are not to be executed. Typically, if the <c>save_config</c> facility is used and a test case that is expected to save data crashes, the following - case can not run. CT offers a way to declare such dependencies, + case cannot run. <c>Common Test</c> offers a way to declare such dependencies, called sequences.</p> <p>A sequence of test cases is defined as a test case group - with a <c>sequence</c> property. Test case groups are defined by - means of the <c>groups/0</c> function in the test suite (see the - <seealso marker="write_test_chapter#test_case_groups">Test case groups</seealso> - chapter for details).</p> - - <p>For example, if we would like to make sure that if <c>allocate</c> - in <c>server_b_SUITE</c> (above) crashes, <c>deallocate</c> is skipped, - we may define a sequence like this:</p> + with a <c>sequence</c> property. Test case groups are defined + through function <c>groups/0</c> in the test suite (for details, see section + <seealso marker="write_test_chapter#test_case_groups">Test Case Groups</seealso>.</p> + + <p>For example, to ensure that if <c>allocate</c> + in <c>server_b_SUITE</c> crashes, <c>deallocate</c> is skipped, + the following sequence can be defined:</p> <pre> - groups() -> [{alloc_and_dealloc, [sequence], [alloc,dealloc]}].</pre> + groups() -> [{alloc_and_dealloc, [sequence], [alloc,dealloc]}].</pre> - <p>Let's also assume the suite contains the test case <c>get_resource_status</c>, - which is independent of the other two cases, then the <c>all</c> function could - look like this:</p> + <p>Assume that the suite contains the test case <c>get_resource_status</c> + that is independent of the other two cases, then function <c>all</c> can + look as follows:</p> <pre> - all() -> [{group,alloc_and_dealloc}, get_resource_status].</pre> + all() -> [{group,alloc_and_dealloc}, get_resource_status].</pre> <p>If <c>alloc</c> succeeds, <c>dealloc</c> is also executed. If <c>alloc</c> fails - however, <c>dealloc</c> is not executed but marked as SKIPPED in the html log. - <c>get_resource_status</c> will run no matter what happens to the <c>alloc_and_dealloc</c> + however, <c>dealloc</c> is not executed but marked as <c>SKIPPED</c> in the HTML log. + <c>get_resource_status</c> runs no matter what happens to the <c>alloc_and_dealloc</c> cases.</p> - <p>Test cases in a sequence will be executed in order until they have all succeeded or - until one case fails. If one fails, all following cases in the sequence are skipped. - The cases in the sequence that have succeeded up to that point are reported as successful - in the log. An arbitrary number of sequences may be specified. Example:</p> + <p>Test cases in a sequence are executed in order until all succeed or + one fails. If one fails, all following cases in the sequence are skipped. + The cases in the sequence that have succeeded up to that point are reported as + successful in the log. Any number of sequences can be specified.</p> + <p><em>Example:</em></p> <pre> - groups() -> [{scenarioA, [sequence], [testA1, testA2]}, - {scenarioB, [sequence], [testB1, testB2, testB3]}]. - - all() -> [test1, - test2, - {group,scenarioA}, - test3, - {group,scenarioB}, - test4].</pre> - - <p>It is possible to have sub-groups in a sequence group. Such sub-groups can have - any property, i.e. they are not required to also be sequences. If you want the status - of the sub-group to affect the sequence on the level above, return - <c>{return_group_result,Status}</c> from <c>end_per_group/2</c>, as described in the - <seealso marker="write_test_chapter#repeated_groups">Repeated groups</seealso> - chapter. A failed sub-group (<c>Status == failed</c>) will cause the execution of a + groups() -> [{scenarioA, [sequence], [testA1, testA2]}, + {scenarioB, [sequence], [testB1, testB2, testB3]}]. + + all() -> [test1, + test2, + {group,scenarioA}, + test3, + {group,scenarioB}, + test4].</pre> + + <p>A sequence group can have subgroups. Such subgroups can have + any property, that is, they are not required to also be sequences. If you want the + status of the subgroup to affect the sequence on the level above, return + <c>{return_group_result,Status}</c> from + <seealso marker="common_test#Module:end_per_group-2"><c>end_per_group/2</c></seealso>, + as described in section + <seealso marker="write_test_chapter#repeated_groups">Repeated Groups</seealso> + in Writing Test Suites. + A failed subgroup (<c>Status == failed</c>) causes the execution of a sequence to fail in the same way a test case does.</p> </section> </chapter> diff --git a/lib/common_test/doc/src/event_handler_chapter.xml b/lib/common_test/doc/src/event_handler_chapter.xml index 78e5bb5e70..31128a7114 100644 --- a/lib/common_test/doc/src/event_handler_chapter.xml +++ b/lib/common_test/doc/src/event_handler_chapter.xml @@ -33,144 +33,171 @@ <section> <marker id="event_handling"></marker> <title>General</title> - <p>It is possible for the operator of a Common Test system to receive - event notifications continously during a test run. It is reported e.g. - when a test case starts and stops, what the current count of successful, - failed and skipped cases is, etc. This information can be used for - different purposes such as logging progress and results on - other format than HTML, saving statistics to a database for report - generation and test system supervision.</p> - - <p>Common Test has a framework for event handling which is based on - the OTP event manager concept and gen_event behaviour. When the Common Test - server starts, it spawns an event manager. During test execution the - manager gets a notification from the server every time something - of potential interest happens. Any event handler plugged into the - event manager can match on events of interest, take action, or maybe - simply pass the information on. Event handlers are Erlang modules - implemented by the Common Test user according to the gen_event - behaviour (see the OTP User's Guide and Reference Manual for more - information).</p> - - <p>As already described, a Common Test server always starts an event manager. - The server also plugs in a default event handler which has as its only - purpose to relay notifications to a globally registered CT Master - event manager (if a CT Master server is running in the system). - The CT Master also spawns an event manager at startup. - Event handlers plugged into this manager will receive the events from - all the test nodes as well as information from the CT Master server - itself.</p> - - <p>User specific event handlers may be plugged into a Common Test event - manager, either by telling Common Test to install them before the test - run (see below), or by adding the handlers dynamically during the test - run by means of - <c>gen_event:add_handler/3</c> or <c>gen_event:add_sup_handler/3</c>. - In the latter scenario, the reference of the Common Test event manager is - required. To get it, call <c>ct:get_event_mgr_ref/0</c> or (on the CT - Master node) <c>ct_master:get_event_mgr_ref/0</c>.</p> + <p>The operator of a <c>Common Test</c> system can receive + event notifications continuously during a test run. For example, + <c>Common Test</c> reports when a test case starts and stops, + the current count of successful, failed, and skipped cases, and so on. + This information can be used for different purposes such as logging progress + and results in another format than HTML, saving statistics to a database + for report generation, and test system supervision.</p> + + <p><c>Common Test</c> has a framework for event handling based on + the OTP event manager concept and <c>gen_event</c> behavior. + When the <c>Common Test</c> server starts, it spawns an event manager. + During test execution the manager gets a notification from the server + when something of potential interest happens. Any event handler plugged into + the event manager can match on events of interest, take action, or + pass the information on. The event handlers are Erlang modules + implemented by the <c>Common Test</c> user according to the <c>gen_event</c> + behavior (for details, see module + <seealso marker="stdlib:gen_event"><c>stdlib:gen_event</c></seealso> and + section + <seealso marker="doc/design_principles:events"><c>gen_event Behaviour</c></seealso> + in OTP Design Principles in the System Documentation). + </p> + + <p>A <c>Common Test</c> server always starts an event manager. + The server also plugs in a default event handler, which only + purpose is to relay notifications to a globally registered <c>Common Test</c> + Master event manager (if a <c>Common Test</c> Master server is running in the system). + The <c>Common Test</c> Master also spawns an event manager at startup. + Event handlers plugged into this manager receives the events from + all the test nodes, plus information from the <c>Common Test</c> Master server. + </p> + + <p>User-specific event handlers can be plugged into a <c>Common Test</c> event + manager, either by telling <c>Common Test</c> to install them before the test + run (described later), or by adding the handlers dynamically during the test + run using + <seealso marker="stdlib:gen_event#add_handler-3"><c>stdlib:gen_event:add_handler/3</c></seealso> or + <seealso marker="stdlib:gen_event#add_sup_handler-3"><c>stdlib:gen_event:add_sup_handler/3</c></seealso>. + In the latter scenario, the reference of the <c>Common Test</c> event manager is + required. To get it, call + <seealso marker="ct#get_event_mgr_ref-0"><c>ct:get_event_mgr_ref/0</c></seealso> + or (on the <c>Common Test</c> Master node) + <seealso marker="ct_master#get_event_mgr_ref-0"><c>ct_master:get_event_mgr_ref/0</c></seealso>.</p> </section> <section> <marker id="usage"></marker> - <title>Usage</title> - <p>Event handlers may be installed by means of an <c>event_handler</c> - start flag (<c>ct_run</c>) or option (<seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>), where the - argument specifies the names of one or more event handler modules. - Example:</p> + <title>Use</title> + <p>Event handlers can be installed by an <c>event_handler</c> start flag + (<seealso marker="ct_run"><c>ct_run</c></seealso>) or option + <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>, where the + argument specifies the names of one or more event handler modules.</p> + + <p><em>Example:</em></p> <p><c>$ ct_run -suite test/my_SUITE -event_handler handlers/my_evh1 handlers/my_evh2 -pa $PWD/handlers</c></p> - <p>Use the <c><![CDATA[ct_run -event_handler_init]]></c> option instead of - <c><![CDATA[-event_handler]]></c> to pass start arguments to the event handler - init function.</p> - <p>All event handler modules must have gen_event behaviour. Note also that - these modules must be precompiled, and that their locations must be - added explicitly to the Erlang code server search path (like in the - example).</p> - <p>An event_handler tuple in the argument <c>Opts</c> has the following - definition (see also <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso> in the reference manual):</p> + <p>To pass start arguments to the event handler init function, use option + <c><![CDATA[ct_run -event_handler_init]]></c> instead of + <c><![CDATA[-event_handler]]></c>.</p> + + <note><p>All event handler modules must have <c>gen_event</c> behavior. + These modules must be precompiled and their locations must be + added explicitly to the Erlang code server search path (as in the previous + example).</p></note> + + <p>An event_handler tuple in argument <c>Opts</c> has the following definition + (see <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>):</p> <pre> - {event_handler,EventHandlers} + {event_handler,EventHandlers} - EventHandlers = EH | [EH] - EH = atom() | {atom(),InitArgs} | {[atom()],InitArgs} - InitArgs = [term()]</pre> + EventHandlers = EH | [EH] + EH = atom() | {atom(),InitArgs} | {[atom()],InitArgs} + InitArgs = [term()]</pre> - <p>Example:</p> + <p>In the following example, two event handlers for the <c>my_SUITE</c> test are installed:</p> <pre> - 1> ct:run_test([{suite,"test/my_SUITE"},{event_handler,[my_evh1,{my_evh2,[node()]}]}]).</pre> - <p>This will install two event handlers for the <c>my_SUITE</c> test. Event handler - <c>my_evh1</c> is started with <c>[]</c> as argument to the init function. Event handler - <c>my_evh2</c> is started with the name of the current node in the init argument list.</p> + 1> ct:run_test([{suite,"test/my_SUITE"},{event_handler,[my_evh1,{my_evh2,[node()]}]}]).</pre> + <p>Event handler <c>my_evh1</c> is started with <c>[]</c> as argument to the init function. + Event handler <c>my_evh2</c> is started with the name of the current node in the init argument list.</p> - <p>Event handlers can also be plugged in by means of + <p>Event handlers can also be plugged in using one of the following <seealso marker="run_test_chapter#test_specifications">test specification</seealso> terms:</p> - - <p><c>{event_handler, EventHandlers}</c>, or</p> - <p><c>{event_handler, EventHandlers, InitArgs}</c>, or</p> - <p><c>{event_handler, NodeRefs, EventHandlers}</c>, or</p> - <p><c>{event_handler, NodeRefs, EventHandlers, InitArgs}</c></p> + <list type="bulleted"> + <item><c>{event_handler, EventHandlers}</c></item> + <item><c>{event_handler, EventHandlers, InitArgs}</c></item> + <item><c>{event_handler, NodeRefs, EventHandlers}</c></item> + <item><c>{event_handler, NodeRefs, EventHandlers, InitArgs}</c></item> + </list> <p><c>EventHandlers</c> is a list of module names. Before a test session starts, the init function of each plugged in event handler - is called (with the InitArgs list as argument or [] if - no start arguments are given).</p> + is called (with the <c>InitArgs</c> list as argument or <c>[]</c> if + no start arguments are specified).</p> - <p>To plug a handler into the CT Master event manager, specify + <p>To plug in a handler to the <c>Common Test</c> Master event manager, specify <c>master</c> as the node in <c>NodeRefs</c>.</p> - <p>For an event handler to be able to match on events, the module must + <p>To be able to match on events, the event handler module must include the header file <c>ct_event.hrl</c>. An event is a record with the following definition:</p> <p><c>#event{name, node, data}</c></p> - <p><c>name</c> is the label (type) of the event. <c>node</c> is the name of the - node the event has originated from (only relevant for CT Master event handlers). - <c>data</c> is specific for the particular event.</p> + <taglist> + <tag><c>name</c></tag> + <item><p>Label (type) of the event.</p></item> + <tag><c>node</c></tag> + <item><p>Name of the node that the event originated from + (only relevant for <c>Common Test</c> Master event handlers).</p></item> + <tag><c>data</c></tag> + <item><p>Specific for the event.</p></item> + </taglist> + <marker id="events"></marker> - <p><em>General events:</em></p> + <section> + <title>General Events</title> - <list> - <item><c>#event{name = start_logging, data = LogDir}</c> - <p><c>LogDir = string()</c>, top level log directory for the test run.</p> - <p>Indicates that the logging process of Common Test - has started successfully and is ready to receive IO + <p>The general events are as follows:</p> + + <taglist> + <tag><c>#event{name = start_logging, data = LogDir}</c></tag> + <item> + <p><c>LogDir = string()</c>, top-level log directory for the test run.</p> + <p>This event indicates that the logging process of <c>Common Test</c> + has started successfully and is ready to receive I/O messages.</p></item> - <item><c>#event{name = stop_logging, data = []}</c> - <p>Indicates that the logging process of Common Test - has been shut down at the end of the test run. + <tag><c>#event{name = stop_logging, data = []}</c></tag> + <item> + <p>This event indicates that the logging process of <c>Common Test</c> + was shut down at the end of the test run. </p></item> - <item><c>#event{name = test_start, data = {StartTime,LogDir}}</c> + <tag><c>#event{name = test_start, data = {StartTime,LogDir}}</c></tag> + <item> <p><c>StartTime = {date(),time()}</c>, test run start date and time.</p> - <p><c>LogDir = string()</c>, top level log directory for the test run.</p> - <p>This event indicates that Common Test has finished initial preparations - and will begin executing test cases. + <p><c>LogDir = string()</c>, top-level log directory for the test run.</p> + <p>This event indicates that <c>Common Test</c> has finished initial preparations + and begins executing test cases. </p></item> - <item><c>#event{name = test_done, data = EndTime}</c> + <tag><c>#event{name = test_done, data = EndTime}</c></tag> + <item> <p><c>EndTime = {date(),time()}</c>, date and time the test run finished.</p> - <p>This indicates that the last test case has been executed and - Common Test is shutting down. + <p>This event indicates that the last test case has been executed and + <c>Common Test</c> is shutting down. </p></item> - <item><c>#event{name = start_info, data = {Tests,Suites,Cases}}</c> - <p><c>Tests = integer()</c>, the number of tests.</p> - <p><c>Suites = integer()</c>, the total number of suites.</p> - <p><c>Cases = integer() | unknown</c>, the total number of test cases.</p> - <p>Initial test run information that can be interpreted as: "This test - run will execute <c>Tests</c> separate tests, in total containing + <tag><c>#event{name = start_info, data = {Tests,Suites,Cases}}</c></tag> + <item> + <p><c>Tests = integer()</c>, number of tests.</p> + <p><c>Suites = integer()</c>, total number of suites.</p> + <p><c>Cases = integer() | unknown</c>, total number of test cases.</p> + <p>This event gives initial test run information that can be interpreted as: + "This test run will execute <c>Tests</c> separate tests, in total containing <c>Cases</c> number of test cases, in <c>Suites</c> number of suites". - Note that if a test case group with a repeat property exists in any test, - the total number of test cases can not be calculated (unknown). + However, if a test case group with a repeat property exists in any test, + the total number of test cases cannot be calculated (unknown). </p></item> - <item><c>#event{name = tc_start, data = {Suite,FuncOrGroup}}</c> + <tag><c>#event{name = tc_start, data = {Suite,FuncOrGroup}}</c></tag> + <item> <p><c>Suite = atom()</c>, name of the test suite.</p> <p><c>FuncOrGroup = Func | {Conf,GroupName,GroupProperties}</c></p> <p><c>Func = atom()</c>, name of test case or configuration function.</p> @@ -180,23 +207,24 @@ <p>This event informs about the start of a test case, or a group configuration function. The event is sent also for <c>init_per_suite</c> and <c>end_per_suite</c>, but not for <c>init_per_testcase</c> and <c>end_per_testcase</c>. If a group - configuration function is starting, the group name and execution properties - are also given. + configuration function starts, the group name and execution properties + are also specified. </p></item> - <item><c>#event{name = tc_logfile, data = {{Suite,Func},LogFileName}}</c> + <tag><c>#event{name = tc_logfile, data = {{Suite,Func},LogFileName}}</c></tag> + <item> <p><c>Suite = atom()</c>, name of the test suite.</p> <p><c>Func = atom()</c>, name of test case or configuration function.</p> - <p><c>LogFileName = string()</c>, full name of test case log file.</p> + <p><c>LogFileName = string()</c>, full name of the test case log file.</p> <p>This event is sent at the start of each test case (and configuration function except <c>init/end_per_testcase</c>) and carries information about the - full name (i.e. the file name including the absolute directory path) of + full name (that is, the file name including the absolute directory path) of the current test case log file. </p></item> + <tag><c>#event{name = tc_done, data = {Suite,FuncOrGroup,Result}}</c></tag> <item> - <marker id="tc_done"/> - <c>#event{name = tc_done, data = {Suite,FuncOrGroup,Result}}</c> + <marker id="tc_done"/> <p><c>Suite = atom()</c>, name of the suite.</p> <p><c>FuncOrGroup = Func | {Conf,GroupName,GroupProperties}</c></p> <p><c>Func = atom()</c>, name of test case or configuration function.</p> @@ -211,34 +239,37 @@ {require_failed_in_suite0,RequireInfo} | {failed,{Suite,init_per_testcase,FailInfo}} | UserTerm</c>, - the reason why the case has been skipped.</p> + why the case was skipped.</p> <marker id="failreason"/> <p><c>FailReason = {error,FailInfo} | {error,{RunTimeError,StackTrace}} | {timetrap_timeout,integer()} | {failed,{Suite,end_per_testcase,FailInfo}}</c>, reason for failure.</p> - <p><c>RequireInfo = {not_available,atom() | tuple()}</c>, why require has failed.</p> + <p><c>RequireInfo = {not_available,atom() | tuple()}</c>, why require failed.</p> <p><c>FailInfo = {timetrap_timeout,integer()} | {RunTimeError,StackTrace} | UserTerm</c>, - detailed information about an error.</p> - <p><c>RunTimeError = term()</c>, a run-time error, e.g. badmatch, undef, etc.</p> - <p><c>StackTrace = list()</c>, list of function calls preceeding a run-time error.</p> - <p><c>UserTerm = term()</c>, arbitrary data specified by user, or <c>exit/1</c> info.</p> - <p>This event informs about the end of a test case or a configuration function (see the - <c>tc_start</c> event for details on the FuncOrGroup element). With this event comes the - final result of the function in question. It is possible to determine on the top level - of <c>Result</c> if the function was successful, skipped (by the user), or if it failed. - It is of course possible to dig deeper and also perform pattern matching on the various - reasons for skipped or failed. Note that <c>{'EXIT',Reason}</c> tuples have been translated into - <c>{error,Reason}</c>. Note also that if a <c>{failed,{Suite,end_per_testcase,FailInfo}</c> - result is received, it actually means the test case was successful, but that + error details.</p> + <p><c>RunTimeError = term()</c>, a runtime error, for example, + <c>badmatch</c> or <c>undef</c>.</p> + <p><c>StackTrace = list()</c>, list of function calls preceding a runtime error.</p> + <p><c>UserTerm = term()</c>, any data specified by user, or <c>exit/1</c> information.</p> + <p>This event informs about the end of a test case or a configuration function (see event + <c>tc_start</c> for details on element <c>FuncOrGroup</c>). With this event + comes the final result of the function in question. It is possible to determine on the + top level of <c>Result</c> if the function was successful, skipped (by the user), + or if it failed.</p> + <p>It is also possible to dig deeper and, for example, perform pattern matching + on the various reasons for skipped or failed. Notice that <c>{'EXIT',Reason}</c> tuples + are translated into <c>{error,Reason}</c>. + Notice also that if a <c>{failed,{Suite,end_per_testcase,FailInfo}</c> + result is received, the test case was successful, but <c>end_per_testcase</c> for the case failed. </p></item> + <tag><c>#event{name = tc_auto_skip, data = {Suite,TestName,Reason}}</c></tag> <item> <marker id="tc_auto_skip"></marker> - <c>#event{name = tc_auto_skip, data = {Suite,TestName,Reason}}</c> <p><c>Suite = atom()</c>, the name of the suite.</p> <p><c>TestName = init_per_suite | end_per_suite | {init_per_group,GroupName} | {end_per_group,GroupName} | @@ -247,101 +278,116 @@ <p><c>GroupName = atom()</c>, the name of the test case group.</p> <p><c>Reason = {failed,FailReason} | {require_failed_in_suite0,RequireInfo}</c>, - reason for auto skipping <c>Func</c>.</p> + reason for auto-skipping <c>Func</c>.</p> <p><c>FailReason = {Suite,ConfigFunc,FailInfo}} | {Suite,FailedCaseInSequence}</c>, reason for failure.</p> - <p><c>RequireInfo = {not_available,atom() | tuple()}</c>, why require has failed.</p> + <p><c>RequireInfo = {not_available,atom() | tuple()}</c>, why require failed.</p> <p><c>ConfigFunc = init_per_suite | init_per_group</c></p> <p><c>FailInfo = {timetrap_timeout,integer()} | {RunTimeError,StackTrace} | bad_return | UserTerm</c>, - detailed information about an error.</p> - <p><c>FailedCaseInSequence = atom()</c>, name of a case that has failed in a sequence.</p> - <p><c>RunTimeError = term()</c>, a run-time error, e.g. badmatch, undef, etc.</p> - <p><c>StackTrace = list()</c>, list of function calls preceeding a run-time error.</p> - <p><c>UserTerm = term()</c>, arbitrary data specified by user, or <c>exit/1</c> info.</p> - <p>This event gets sent for every test case or configuration function that Common Test + error details.</p> + <p><c>FailedCaseInSequence = atom()</c>, the name of a case that failed in a sequence.</p> + <p><c>RunTimeError = term()</c>, a runtime error, for example <c>badmatch</c> or + <c>undef</c>.</p> + <p><c>StackTrace = list()</c>, list of function calls preceeding a runtime error.</p> + <p><c>UserTerm = term()</c>, any data specified by user, or <c>exit/1</c> information.</p> + <p>This event is sent for every test case or configuration function that <c>Common Test</c> has skipped automatically because of either a failed <c>init_per_suite</c> or <c>init_per_group</c>, a failed <c>require</c> in <c>suite/0</c>, or a failed test case - in a sequence. Note that this event is never received as a result of a test case getting - skipped because of <c>init_per_testcase</c> failing, since that information is carried with - the <c>tc_done</c> event. If a failed test case belongs to a test case group, the second - data element is a tuple <c>{FuncName,GroupName}</c>, otherwise simply the function name. + in a sequence. Notice that this event is never received as a result of a test case getting + skipped because of <c>init_per_testcase</c> failing, as that information is carried with + event <c>tc_done</c>. If a failed test case belongs to a test case group, the second + data element is a tuple <c>{FuncName,GroupName}</c>, otherwise only the function name. </p></item> + <tag><c>#event{name = tc_user_skip, data = {Suite,TestName,Comment}}</c></tag> <item> - <marker id="tc_user_skip"></marker> - <c>#event{name = tc_user_skip, data = {Suite,TestName,Comment}}</c> + <marker id="tc_user_skip"></marker> <p><c>Suite = atom()</c>, the name of the suite.</p> <p><c>TestName = init_per_suite | end_per_suite | {init_per_group,GroupName} | {end_per_group,GroupName} | {FuncName,GroupName} | FuncName</c></p> <p><c>FuncName = atom()</c>, the name of the test case or configuration function.</p> <p><c>GroupName = atom()</c>, the name of the test case group.</p> - <p><c>Comment = string()</c>, reason for skipping the test case.</p> - <p>This event specifies that a test case has been skipped by the user. - It is only ever received if the skip was declared in a test specification. + <p><c>Comment = string()</c>, why the test case was skipped.</p> + <p>This event specifies that a test case was skipped by the user. + It is only received if the skip is declared in a test specification. Otherwise, user skip information is received as a <c>{skipped,SkipReason}</c> - result in the <c>tc_done</c> event for the test case. If a skipped test case belongs + result in event <c>tc_done</c> for the test case. If a skipped test case belongs to a test case group, the second data element is a tuple <c>{FuncName,GroupName}</c>, - otherwise simply the function name. + otherwise only the function name. </p></item> - <item><c>#event{name = test_stats, data = {Ok,Failed,Skipped}}</c> - <p><c>Ok = integer()</c>, the current number of successful test cases.</p> - <p><c>Failed = integer()</c>, the current number of failed test cases.</p> + <tag><c>#event{name = test_stats, data = {Ok,Failed,Skipped}}</c></tag> + <item> + <p><c>Ok = integer()</c>, current number of successful test cases.</p> + <p><c>Failed = integer()</c>, current number of failed test cases.</p> <p><c>Skipped = {UserSkipped,AutoSkipped}</c></p> - <p><c>UserSkipped = integer()</c>, the current number of user skipped test cases.</p> - <p><c>AutoSkipped = integer()</c>, the current number of auto skipped test cases.</p> - <p>This is a statistics event with the current count of successful, skipped - and failed test cases so far. This event gets sent after the end of each test case, - immediately following the <c>tc_done</c> event. + <p><c>UserSkipped = integer()</c>, current number of user-skipped test cases.</p> + <p><c>AutoSkipped = integer()</c>, current number of auto-skipped test cases.</p> + <p>This is a statistics event with current count of successful, skipped, + and failed test cases so far. This event is sent after the end of each test case, + immediately following event <c>tc_done</c>. </p></item> - </list> + </taglist> + </section> + + <section> + <title>Internal Events</title> - <p><em>Internal events:</em></p> + <p>The internal events are as follows:</p> - <list> - <item><c>#event{name = start_make, data = Dir}</c> + <taglist> + <tag><c>#event{name = start_make, data = Dir}</c></tag> + <item> <p><c>Dir = string()</c>, running make in this directory.</p> - <p>An internal event saying that Common Test will start compiling + <p>This internal event says that <c>Common Test</c> starts compiling modules in directory <c>Dir</c>. </p></item> - <item><c>#event{name = finished_make, data = Dir}</c> + <tag><c>#event{name = finished_make, data = Dir}</c></tag> + <item> <p><c>Dir = string()</c>, finished running make in this directory.</p> - <p>An internal event saying that Common Test is finished compiling + <p>This internal event says that <c>Common Test</c> is finished compiling modules in directory <c>Dir</c>. </p></item> - <item><c>#event{name = start_write_file, data = FullNameFile}</c> + <tag><c>#event{name = start_write_file, data = FullNameFile}</c></tag> + <item> <p><c>FullNameFile = string(), full name of the file.</c></p> - <p>An internal event used by the Common Test Master process to + <p>This internal event is used by the <c>Common Test</c> Master process to synchronize particular file operations. </p></item> - <item><c>#event{name = finished_write_file, data = FullNameFile}</c> + <tag><c>#event{name = finished_write_file, data = FullNameFile}</c></tag> + <item> <p><c>FullNameFile = string(), full name of the file.</c></p> - <p>An internal event used by the Common Test Master process to + <p>This internal event is used by the <c>Common Test</c> Master process to synchronize particular file operations. </p></item> - </list> - + </taglist> + </section> + <section> + <title>Notes</title> + <p>The events are also documented in <c>ct_event.erl</c>. This module - may serve as an example of what an event handler for the CT event + can serve as an example of what an event handler for the <c>Common Test</c> event manager can look like.</p> - <note><p>To ensure that printouts to standard out (or printouts made with - <seealso marker="ct#log-2"><c>ct:log/2/3</c></seealso> or <seealso marker="ct:pal-2"><c>ct:pal/2/3</c></seealso>) get written to the test case log - file, and not to the Common Test framework log, you can syncronize - with the Common Test server by matching on the <c>tc_start</c> and <c>tc_done</c> - events. In the period between these events, all IO gets directed to the + <note><p>To ensure that printouts to <c>stdout</c> (or printouts made with + <seealso marker="ct#log-2"><c>ct:log/2,3</c></seealso> or + <seealso marker="ct:pal-2"><c>ct:pal,2,3</c></seealso>) get written to the test case log + file, and not to the <c>Common Test</c> framework log, you can synchronize + with the <c>Common Test</c> server by matching on evvents <c>tc_start</c> and <c>tc_done</c>. + In the period between these events, all I/O is directed to the test case log file. These events are sent synchronously to avoid potential - timing problems (e.g. that the test case log file gets closed just before - an IO message from an external process gets through). Knowing this, you - need to be careful that your <c>handle_event/2</c> callback function doesn't - stall the test execution, possibly causing unexpected behaviour as a result.</p></note> + timing problems (for example, that the test case log file is closed just before + an I/O message from an external process gets through). Knowing this, you + need to be careful that your <c>handle_event/2</c> callback function does not + stall the test execution, possibly causing unexpected behavior as a result.</p></note> + </section> </section> </chapter> diff --git a/lib/common_test/doc/src/example_chapter.xml b/lib/common_test/doc/src/example_chapter.xml index 8201107c04..8523c9f485 100644 --- a/lib/common_test/doc/src/example_chapter.xml +++ b/lib/common_test/doc/src/example_chapter.xml @@ -33,476 +33,472 @@ <marker id="top"></marker> <section> - <title>Test suite example</title> - <p>This example test suite shows some tests of a database server. + <title>Test Suite Example</title> + <p>The following example test suite shows some tests of a database server: </p> <code> --module(db_data_type_SUITE). - --include_lib("common_test/include/ct.hrl"). - -%% Test server callbacks --export([suite/0, all/0, - init_per_suite/1, end_per_suite/1, - init_per_testcase/2, end_per_testcase/2]). - -%% Test cases --export([string/1, integer/1]). - --define(CONNECT_STR, "DSN=sqlserver;UID=alladin;PWD=sesame"). - -%%-------------------------------------------------------------------- -%% COMMON TEST CALLBACK FUNCTIONS -%%-------------------------------------------------------------------- - -%%-------------------------------------------------------------------- -%% Function: suite() -> Info -%% -%% Info = [tuple()] -%% List of key/value pairs. -%% -%% Description: Returns list of tuples to set default properties -%% for the suite. -%%-------------------------------------------------------------------- -suite() -> - [{timetrap,{minutes,1}}]. - -%%-------------------------------------------------------------------- -%% Function: init_per_suite(Config0) -> Config1 -%% -%% Config0 = Config1 = [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% -%% Description: Initialization before the suite. -%%-------------------------------------------------------------------- -init_per_suite(Config) -> - {ok, Ref} = db:connect(?CONNECT_STR, []), - TableName = db_lib:unique_table_name(), - [{con_ref, Ref },{table_name, TableName}| Config]. - -%%-------------------------------------------------------------------- -%% Function: end_per_suite(Config) -> term() -%% -%% Config = [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% -%% Description: Cleanup after the suite. -%%-------------------------------------------------------------------- -end_per_suite(Config) -> - Ref = ?config(con_ref, Config), - db:disconnect(Ref), - ok. + -module(db_data_type_SUITE). + + -include_lib("common_test/include/ct.hrl"). + + %% Test server callbacks + -export([suite/0, all/0, + init_per_suite/1, end_per_suite/1, + init_per_testcase/2, end_per_testcase/2]). + + %% Test cases + -export([string/1, integer/1]). + + -define(CONNECT_STR, "DSN=sqlserver;UID=alladin;PWD=sesame"). + + %%-------------------------------------------------------------------- + %% COMMON TEST CALLBACK FUNCTIONS + %%-------------------------------------------------------------------- + + %%-------------------------------------------------------------------- + %% Function: suite() -> Info + %% + %% Info = [tuple()] + %% List of key/value pairs. + %% + %% Description: Returns list of tuples to set default properties + %% for the suite. + %%-------------------------------------------------------------------- + suite() -> + [{timetrap,{minutes,1}}]. + + %%-------------------------------------------------------------------- + %% Function: init_per_suite(Config0) -> Config1 + %% + %% Config0 = Config1 = [tuple()] + %% A list of key/value pairs, holding the test case configuration. + %% + %% Description: Initialization before the suite. + %%-------------------------------------------------------------------- + init_per_suite(Config) -> + {ok, Ref} = db:connect(?CONNECT_STR, []), + TableName = db_lib:unique_table_name(), + [{con_ref, Ref },{table_name, TableName}| Config]. + + %%-------------------------------------------------------------------- + %% Function: end_per_suite(Config) -> term() + %% + %% Config = [tuple()] + %% A list of key/value pairs, holding the test case configuration. + %% + %% Description: Cleanup after the suite. + %%-------------------------------------------------------------------- + end_per_suite(Config) -> + Ref = ?config(con_ref, Config), + db:disconnect(Ref), + ok. -%%-------------------------------------------------------------------- -%% Function: init_per_testcase(TestCase, Config0) -> Config1 -%% -%% TestCase = atom() -%% Name of the test case that is about to run. -%% Config0 = Config1 = [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% -%% Description: Initialization before each test case. -%%-------------------------------------------------------------------- -init_per_testcase(Case, Config) -> - Ref = ?config(con_ref, Config), - TableName = ?config(table_name, Config), - ok = db:create_table(Ref, TableName, table_type(Case)), - Config. - -%%-------------------------------------------------------------------- -%% Function: end_per_testcase(TestCase, Config) -> term() -%% -%% TestCase = atom() -%% Name of the test case that is finished. -%% Config = [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% -%% Description: Cleanup after each test case. -%%-------------------------------------------------------------------- -end_per_testcase(_Case, Config) -> - Ref = ?config(con_ref, Config), - TableName = ?config(table_name, Config), - ok = db:delete_table(Ref, TableName), - ok. - -%%-------------------------------------------------------------------- -%% Function: all() -> GroupsAndTestCases -%% -%% GroupsAndTestCases = [{group,GroupName} | TestCase] -%% GroupName = atom() -%% Name of a test case group. -%% TestCase = atom() -%% Name of a test case. -%% -%% Description: Returns the list of groups and test cases that -%% are to be executed. -%%-------------------------------------------------------------------- -all() -> - [string, integer]. - - -%%-------------------------------------------------------------------- -%% TEST CASES -%%-------------------------------------------------------------------- - -string(Config) -> - insert_and_lookup(dummy_key, "Dummy string", Config). - -integer(Config) -> - insert_and_lookup(dummy_key, 42, Config). - - -insert_and_lookup(Key, Value, Config) -> - Ref = ?config(con_ref, Config), - TableName = ?config(table_name, Config), - ok = db:insert(Ref, TableName, Key, Value), - [Value] = db:lookup(Ref, TableName, Key), - ok = db:delete(Ref, TableName, Key), - [] = db:lookup(Ref, TableName, Key), - ok. - -</code> + %%-------------------------------------------------------------------- + %% Function: init_per_testcase(TestCase, Config0) -> Config1 + %% + %% TestCase = atom() + %% Name of the test case that is about to run. + %% Config0 = Config1 = [tuple()] + %% A list of key/value pairs, holding the test case configuration. + %% + %% Description: Initialization before each test case. + %%-------------------------------------------------------------------- + init_per_testcase(Case, Config) -> + Ref = ?config(con_ref, Config), + TableName = ?config(table_name, Config), + ok = db:create_table(Ref, TableName, table_type(Case)), + Config. + + %%-------------------------------------------------------------------- + %% Function: end_per_testcase(TestCase, Config) -> term() + %% + %% TestCase = atom() + %% Name of the test case that is finished. + %% Config = [tuple()] + %% A list of key/value pairs, holding the test case configuration. + %% + %% Description: Cleanup after each test case. + %%-------------------------------------------------------------------- + end_per_testcase(_Case, Config) -> + Ref = ?config(con_ref, Config), + TableName = ?config(table_name, Config), + ok = db:delete_table(Ref, TableName), + ok. + + %%-------------------------------------------------------------------- + %% Function: all() -> GroupsAndTestCases + %% + %% GroupsAndTestCases = [{group,GroupName} | TestCase] + %% GroupName = atom() + %% Name of a test case group. + %% TestCase = atom() + %% Name of a test case. + %% + %% Description: Returns the list of groups and test cases that + %% are to be executed. + %%-------------------------------------------------------------------- + all() -> + [string, integer]. + + + %%-------------------------------------------------------------------- + %% TEST CASES + %%-------------------------------------------------------------------- + + string(Config) -> + insert_and_lookup(dummy_key, "Dummy string", Config). + + integer(Config) -> + insert_and_lookup(dummy_key, 42, Config). + + + insert_and_lookup(Key, Value, Config) -> + Ref = ?config(con_ref, Config), + TableName = ?config(table_name, Config), + ok = db:insert(Ref, TableName, Key, Value), + [Value] = db:lookup(Ref, TableName, Key), + ok = db:delete(Ref, TableName, Key), + [] = db:lookup(Ref, TableName, Key), + ok.</code> </section> <section> - <title>Test suite templates</title> - <p>The Erlang mode for the Emacs editor includes two Common Test test suite - templates, one with extensive information in the function headers, and + <title>Test Suite Templates</title> + <p>The Erlang mode for the Emacs editor includes two <c>Common Test</c> test + suite templates, one with extensive information in the function headers, and one with minimal information. A test suite template provides a quick start - for implementing a suite from scratch and gives you a good overview - of the available callback functions. Here are the templates in question: + for implementing a suite from scratch and gives a good overview + of the available callback functions. The two templates follows: </p> - <p><em>Large Common Test suite</em></p> + <p><em>Large Common Test Suite</em></p> <code> -%%%------------------------------------------------------------------- -%%% File : example_SUITE.erl -%%% Author : -%%% Description : -%%% -%%% Created : -%%%------------------------------------------------------------------- --module(example_SUITE). - -%% Note: This directive should only be used in test suites. --compile(export_all). - --include_lib("common_test/include/ct.hrl"). - -%%-------------------------------------------------------------------- -%% COMMON TEST CALLBACK FUNCTIONS -%%-------------------------------------------------------------------- - -%%-------------------------------------------------------------------- -%% Function: suite() -> Info -%% -%% Info = [tuple()] -%% List of key/value pairs. -%% -%% Description: Returns list of tuples to set default properties -%% for the suite. -%% -%% Note: The suite/0 function is only meant to be used to return -%% default data values, not perform any other operations. -%%-------------------------------------------------------------------- -suite() -> - [{timetrap,{minutes,10}}]. - -%%-------------------------------------------------------------------- -%% Function: init_per_suite(Config0) -> -%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} -%% -%% Config0 = Config1 = [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% Reason = term() -%% The reason for skipping the suite. -%% -%% Description: Initialization before the suite. -%% -%% Note: This function is free to add any key/value pairs to the Config -%% variable, but should NOT alter/remove any existing entries. -%%-------------------------------------------------------------------- -init_per_suite(Config) -> - Config. - -%%-------------------------------------------------------------------- -%% Function: end_per_suite(Config0) -> term() | {save_config,Config1} -%% -%% Config0 = Config1 = [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% -%% Description: Cleanup after the suite. -%%-------------------------------------------------------------------- -end_per_suite(_Config) -> - ok. - -%%-------------------------------------------------------------------- -%% Function: init_per_group(GroupName, Config0) -> -%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} -%% -%% GroupName = atom() -%% Name of the test case group that is about to run. -%% Config0 = Config1 = [tuple()] -%% A list of key/value pairs, holding configuration data for the group. -%% Reason = term() -%% The reason for skipping all test cases and subgroups in the group. -%% -%% Description: Initialization before each test case group. -%%-------------------------------------------------------------------- -init_per_group(_GroupName, Config) -> - Config. - -%%-------------------------------------------------------------------- -%% Function: end_per_group(GroupName, Config0) -> -%% term() | {save_config,Config1} -%% -%% GroupName = atom() -%% Name of the test case group that is finished. -%% Config0 = Config1 = [tuple()] -%% A list of key/value pairs, holding configuration data for the group. -%% -%% Description: Cleanup after each test case group. -%%-------------------------------------------------------------------- -end_per_group(_GroupName, _Config) -> - ok. - -%%-------------------------------------------------------------------- -%% Function: init_per_testcase(TestCase, Config0) -> -%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} -%% -%% TestCase = atom() -%% Name of the test case that is about to run. -%% Config0 = Config1 = [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% Reason = term() -%% The reason for skipping the test case. -%% -%% Description: Initialization before each test case. -%% -%% Note: This function is free to add any key/value pairs to the Config -%% variable, but should NOT alter/remove any existing entries. -%%-------------------------------------------------------------------- -init_per_testcase(_TestCase, Config) -> - Config. - -%%-------------------------------------------------------------------- -%% Function: end_per_testcase(TestCase, Config0) -> -%% term() | {save_config,Config1} | {fail,Reason} -%% -%% TestCase = atom() -%% Name of the test case that is finished. -%% Config0 = Config1 = [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% Reason = term() -%% The reason for failing the test case. -%% -%% Description: Cleanup after each test case. -%%-------------------------------------------------------------------- -end_per_testcase(_TestCase, _Config) -> - ok. - -%%-------------------------------------------------------------------- -%% Function: groups() -> [Group] -%% -%% Group = {GroupName,Properties,GroupsAndTestCases} -%% GroupName = atom() -%% The name of the group. -%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}] -%% Group properties that may be combined. -%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase] -%% TestCase = atom() -%% The name of a test case. -%% Shuffle = shuffle | {shuffle,Seed} -%% To get cases executed in random order. -%% Seed = {integer(),integer(),integer()} -%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | -%% repeat_until_any_ok | repeat_until_any_fail -%% To get execution of cases repeated. -%% N = integer() | forever -%% -%% Description: Returns a list of test case group definitions. -%%-------------------------------------------------------------------- -groups() -> - []. - -%%-------------------------------------------------------------------- -%% Function: all() -> GroupsAndTestCases | {skip,Reason} -%% -%% GroupsAndTestCases = [{group,GroupName} | TestCase] -%% GroupName = atom() -%% Name of a test case group. -%% TestCase = atom() -%% Name of a test case. -%% Reason = term() -%% The reason for skipping all groups and test cases. -%% -%% Description: Returns the list of groups and test cases that -%% are to be executed. -%%-------------------------------------------------------------------- -all() -> - [my_test_case]. - - -%%-------------------------------------------------------------------- -%% TEST CASES -%%-------------------------------------------------------------------- - -%%-------------------------------------------------------------------- -%% Function: TestCase() -> Info -%% -%% Info = [tuple()] -%% List of key/value pairs. -%% -%% Description: Test case info function - returns list of tuples to set -%% properties for the test case. -%% -%% Note: This function is only meant to be used to return a list of -%% values, not perform any other operations. -%%-------------------------------------------------------------------- -my_test_case() -> - []. - -%%-------------------------------------------------------------------- -%% Function: TestCase(Config0) -> -%% ok | exit() | {skip,Reason} | {comment,Comment} | -%% {save_config,Config1} | {skip_and_save,Reason,Config1} -%% -%% Config0 = Config1 = [tuple()] -%% A list of key/value pairs, holding the test case configuration. -%% Reason = term() -%% The reason for skipping the test case. -%% Comment = term() -%% A comment about the test case that will be printed in the html log. -%% -%% Description: Test case function. (The name of it must be specified in -%% the all/0 list or in a test case group for the test case -%% to be executed). -%%-------------------------------------------------------------------- -my_test_case(_Config) -> - ok. -</code> + %%%------------------------------------------------------------------- + %%% File : example_SUITE.erl + %%% Author : + %%% Description : + %%% + %%% Created : + %%%------------------------------------------------------------------- + -module(example_SUITE). + + %% Note: This directive should only be used in test suites. + -compile(export_all). + + -include_lib("common_test/include/ct.hrl"). + + %%-------------------------------------------------------------------- + %% COMMON TEST CALLBACK FUNCTIONS + %%-------------------------------------------------------------------- + + %%-------------------------------------------------------------------- + %% Function: suite() -> Info + %% + %% Info = [tuple()] + %% List of key/value pairs. + %% + %% Description: Returns list of tuples to set default properties + %% for the suite. + %% + %% Note: The suite/0 function is only meant to be used to return + %% default data values, not perform any other operations. + %%-------------------------------------------------------------------- + suite() -> + [{timetrap,{minutes,10}}]. + + %%-------------------------------------------------------------------- + %% Function: init_per_suite(Config0) -> + %% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} + %% + %% Config0 = Config1 = [tuple()] + %% A list of key/value pairs, holding the test case configuration. + %% Reason = term() + %% The reason for skipping the suite. + %% + %% Description: Initialization before the suite. + %% + %% Note: This function is free to add any key/value pairs to the Config + %% variable, but should NOT alter/remove any existing entries. + %%-------------------------------------------------------------------- + init_per_suite(Config) -> + Config. + + %%-------------------------------------------------------------------- + %% Function: end_per_suite(Config0) -> term() | {save_config,Config1} + %% + %% Config0 = Config1 = [tuple()] + %% A list of key/value pairs, holding the test case configuration. + %% + %% Description: Cleanup after the suite. + %%-------------------------------------------------------------------- + end_per_suite(_Config) -> + ok. + + %%-------------------------------------------------------------------- + %% Function: init_per_group(GroupName, Config0) -> + %% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} + %% + %% GroupName = atom() + %% Name of the test case group that is about to run. + %% Config0 = Config1 = [tuple()] + %% A list of key/value pairs, holding configuration data for the group. + %% Reason = term() + %% The reason for skipping all test cases and subgroups in the group. + %% + %% Description: Initialization before each test case group. + %%-------------------------------------------------------------------- + init_per_group(_GroupName, Config) -> + Config. + + %%-------------------------------------------------------------------- + %% Function: end_per_group(GroupName, Config0) -> + %% term() | {save_config,Config1} + %% + %% GroupName = atom() + %% Name of the test case group that is finished. + %% Config0 = Config1 = [tuple()] + %% A list of key/value pairs, holding configuration data for the group. + %% + %% Description: Cleanup after each test case group. + %%-------------------------------------------------------------------- + end_per_group(_GroupName, _Config) -> + ok. + + %%-------------------------------------------------------------------- + %% Function: init_per_testcase(TestCase, Config0) -> + %% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} + %% + %% TestCase = atom() + %% Name of the test case that is about to run. + %% Config0 = Config1 = [tuple()] + %% A list of key/value pairs, holding the test case configuration. + %% Reason = term() + %% The reason for skipping the test case. + %% + %% Description: Initialization before each test case. + %% + %% Note: This function is free to add any key/value pairs to the Config + %% variable, but should NOT alter/remove any existing entries. + %%-------------------------------------------------------------------- + init_per_testcase(_TestCase, Config) -> + Config. + + %%-------------------------------------------------------------------- + %% Function: end_per_testcase(TestCase, Config0) -> + %% term() | {save_config,Config1} | {fail,Reason} + %% + %% TestCase = atom() + %% Name of the test case that is finished. + %% Config0 = Config1 = [tuple()] + %% A list of key/value pairs, holding the test case configuration. + %% Reason = term() + %% The reason for failing the test case. + %% + %% Description: Cleanup after each test case. + %%-------------------------------------------------------------------- + end_per_testcase(_TestCase, _Config) -> + ok. + + %%-------------------------------------------------------------------- + %% Function: groups() -> [Group] + %% + %% Group = {GroupName,Properties,GroupsAndTestCases} + %% GroupName = atom() + %% The name of the group. + %% Properties = [parallel | sequence | Shuffle | {RepeatType,N}] + %% Group properties that may be combined. + %% GroupsAndTestCases = [Group | {group,GroupName} | TestCase] + %% TestCase = atom() + %% The name of a test case. + %% Shuffle = shuffle | {shuffle,Seed} + %% To get cases executed in random order. + %% Seed = {integer(),integer(),integer()} + %% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | + %% repeat_until_any_ok | repeat_until_any_fail + %% To get execution of cases repeated. + %% N = integer() | forever + %% + %% Description: Returns a list of test case group definitions. + %%-------------------------------------------------------------------- + groups() -> + []. + + %%-------------------------------------------------------------------- + %% Function: all() -> GroupsAndTestCases | {skip,Reason} + %% + %% GroupsAndTestCases = [{group,GroupName} | TestCase] + %% GroupName = atom() + %% Name of a test case group. + %% TestCase = atom() + %% Name of a test case. + %% Reason = term() + %% The reason for skipping all groups and test cases. + %% + %% Description: Returns the list of groups and test cases that + %% are to be executed. + %%-------------------------------------------------------------------- + all() -> + [my_test_case]. + + + %%-------------------------------------------------------------------- + %% TEST CASES + %%-------------------------------------------------------------------- + + %%-------------------------------------------------------------------- + %% Function: TestCase() -> Info + %% + %% Info = [tuple()] + %% List of key/value pairs. + %% + %% Description: Test case info function - returns list of tuples to set + %% properties for the test case. + %% + %% Note: This function is only meant to be used to return a list of + %% values, not perform any other operations. + %%-------------------------------------------------------------------- + my_test_case() -> + []. + + %%-------------------------------------------------------------------- + %% Function: TestCase(Config0) -> + %% ok | exit() | {skip,Reason} | {comment,Comment} | + %% {save_config,Config1} | {skip_and_save,Reason,Config1} + %% + %% Config0 = Config1 = [tuple()] + %% A list of key/value pairs, holding the test case configuration. + %% Reason = term() + %% The reason for skipping the test case. + %% Comment = term() + %% A comment about the test case that will be printed in the html log. + %% + %% Description: Test case function. (The name of it must be specified in + %% the all/0 list or in a test case group for the test case + %% to be executed). + %%-------------------------------------------------------------------- + my_test_case(_Config) -> + ok.</code> <br></br> - <p><em>Small Common Test suite</em></p> + <p><em>Small Common Test Suite</em></p> <code> -%%%------------------------------------------------------------------- -%%% File : example_SUITE.erl -%%% Author : -%%% Description : -%%% -%%% Created : -%%%------------------------------------------------------------------- --module(example_SUITE). - --compile(export_all). - --include_lib("common_test/include/ct.hrl"). - -%%-------------------------------------------------------------------- -%% Function: suite() -> Info -%% Info = [tuple()] -%%-------------------------------------------------------------------- -suite() -> - [{timetrap,{seconds,30}}]. - -%%-------------------------------------------------------------------- -%% Function: init_per_suite(Config0) -> -%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} -%% Config0 = Config1 = [tuple()] -%% Reason = term() -%%-------------------------------------------------------------------- -init_per_suite(Config) -> - Config. - -%%-------------------------------------------------------------------- -%% Function: end_per_suite(Config0) -> term() | {save_config,Config1} -%% Config0 = Config1 = [tuple()] -%%-------------------------------------------------------------------- -end_per_suite(_Config) -> - ok. - -%%-------------------------------------------------------------------- -%% Function: init_per_group(GroupName, Config0) -> -%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} -%% GroupName = atom() -%% Config0 = Config1 = [tuple()] -%% Reason = term() -%%-------------------------------------------------------------------- -init_per_group(_GroupName, Config) -> - Config. - -%%-------------------------------------------------------------------- -%% Function: end_per_group(GroupName, Config0) -> -%% term() | {save_config,Config1} -%% GroupName = atom() -%% Config0 = Config1 = [tuple()] -%%-------------------------------------------------------------------- -end_per_group(_GroupName, _Config) -> - ok. - -%%-------------------------------------------------------------------- -%% Function: init_per_testcase(TestCase, Config0) -> -%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} -%% TestCase = atom() -%% Config0 = Config1 = [tuple()] -%% Reason = term() -%%-------------------------------------------------------------------- -init_per_testcase(_TestCase, Config) -> - Config. - -%%-------------------------------------------------------------------- -%% Function: end_per_testcase(TestCase, Config0) -> -%% term() | {save_config,Config1} | {fail,Reason} -%% TestCase = atom() -%% Config0 = Config1 = [tuple()] -%% Reason = term() -%%-------------------------------------------------------------------- -end_per_testcase(_TestCase, _Config) -> - ok. - -%%-------------------------------------------------------------------- -%% Function: groups() -> [Group] -%% Group = {GroupName,Properties,GroupsAndTestCases} -%% GroupName = atom() -%% Properties = [parallel | sequence | Shuffle | {RepeatType,N}] -%% GroupsAndTestCases = [Group | {group,GroupName} | TestCase] -%% TestCase = atom() -%% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}} -%% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | -%% repeat_until_any_ok | repeat_until_any_fail -%% N = integer() | forever -%%-------------------------------------------------------------------- -groups() -> - []. - -%%-------------------------------------------------------------------- -%% Function: all() -> GroupsAndTestCases | {skip,Reason} -%% GroupsAndTestCases = [{group,GroupName} | TestCase] -%% GroupName = atom() -%% TestCase = atom() -%% Reason = term() -%%-------------------------------------------------------------------- -all() -> - [my_test_case]. - -%%-------------------------------------------------------------------- -%% Function: TestCase() -> Info -%% Info = [tuple()] -%%-------------------------------------------------------------------- -my_test_case() -> - []. - -%%-------------------------------------------------------------------- -%% Function: TestCase(Config0) -> -%% ok | exit() | {skip,Reason} | {comment,Comment} | -%% {save_config,Config1} | {skip_and_save,Reason,Config1} -%% Config0 = Config1 = [tuple()] -%% Reason = term() -%% Comment = term() -%%-------------------------------------------------------------------- -my_test_case(_Config) -> - ok. -</code> + %%%------------------------------------------------------------------- + %%% File : example_SUITE.erl + %%% Author : + %%% Description : + %%% + %%% Created : + %%%------------------------------------------------------------------- + -module(example_SUITE). + + -compile(export_all). + + -include_lib("common_test/include/ct.hrl"). + + %%-------------------------------------------------------------------- + %% Function: suite() -> Info + %% Info = [tuple()] + %%-------------------------------------------------------------------- + suite() -> + [{timetrap,{seconds,30}}]. + + %%-------------------------------------------------------------------- + %% Function: init_per_suite(Config0) -> + %% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} + %% Config0 = Config1 = [tuple()] + %% Reason = term() + %%-------------------------------------------------------------------- + init_per_suite(Config) -> + Config. + + %%-------------------------------------------------------------------- + %% Function: end_per_suite(Config0) -> term() | {save_config,Config1} + %% Config0 = Config1 = [tuple()] + %%-------------------------------------------------------------------- + end_per_suite(_Config) -> + ok. + + %%-------------------------------------------------------------------- + %% Function: init_per_group(GroupName, Config0) -> + %% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} + %% GroupName = atom() + %% Config0 = Config1 = [tuple()] + %% Reason = term() + %%-------------------------------------------------------------------- + init_per_group(_GroupName, Config) -> + Config. + + %%-------------------------------------------------------------------- + %% Function: end_per_group(GroupName, Config0) -> + %% term() | {save_config,Config1} + %% GroupName = atom() + %% Config0 = Config1 = [tuple()] + %%-------------------------------------------------------------------- + end_per_group(_GroupName, _Config) -> + ok. + + %%-------------------------------------------------------------------- + %% Function: init_per_testcase(TestCase, Config0) -> + %% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1} + %% TestCase = atom() + %% Config0 = Config1 = [tuple()] + %% Reason = term() + %%-------------------------------------------------------------------- + init_per_testcase(_TestCase, Config) -> + Config. + + %%-------------------------------------------------------------------- + %% Function: end_per_testcase(TestCase, Config0) -> + %% term() | {save_config,Config1} | {fail,Reason} + %% TestCase = atom() + %% Config0 = Config1 = [tuple()] + %% Reason = term() + %%-------------------------------------------------------------------- + end_per_testcase(_TestCase, _Config) -> + ok. + + %%-------------------------------------------------------------------- + %% Function: groups() -> [Group] + %% Group = {GroupName,Properties,GroupsAndTestCases} + %% GroupName = atom() + %% Properties = [parallel | sequence | Shuffle | {RepeatType,N}] + %% GroupsAndTestCases = [Group | {group,GroupName} | TestCase] + %% TestCase = atom() + %% Shuffle = shuffle | {shuffle,{integer(),integer(),integer()}} + %% RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | + %% repeat_until_any_ok | repeat_until_any_fail + %% N = integer() | forever + %%-------------------------------------------------------------------- + groups() -> + []. + + %%-------------------------------------------------------------------- + %% Function: all() -> GroupsAndTestCases | {skip,Reason} + %% GroupsAndTestCases = [{group,GroupName} | TestCase] + %% GroupName = atom() + %% TestCase = atom() + %% Reason = term() + %%-------------------------------------------------------------------- + all() -> + [my_test_case]. + + %%-------------------------------------------------------------------- + %% Function: TestCase() -> Info + %% Info = [tuple()] + %%-------------------------------------------------------------------- + my_test_case() -> + []. + + %%-------------------------------------------------------------------- + %% Function: TestCase(Config0) -> + %% ok | exit() | {skip,Reason} | {comment,Comment} | + %% {save_config,Config1} | {skip_and_save,Reason,Config1} + %% Config0 = Config1 = [tuple()] + %% Reason = term() + %% Comment = term() + %%-------------------------------------------------------------------- + my_test_case(_Config) -> + ok.</code> </section> </chapter> diff --git a/lib/common_test/doc/src/getting_started_chapter.xml b/lib/common_test/doc/src/getting_started_chapter.xml index ef9c409bf1..802f9ba397 100644 --- a/lib/common_test/doc/src/getting_started_chapter.xml +++ b/lib/common_test/doc/src/getting_started_chapter.xml @@ -31,235 +31,247 @@ </header> <section> - <title>Are you new around here?</title> + <title>Introduction for Newcomers</title> <p> - The purpose of this short chapter is to, with a "learning by example" - approach, give the newcomer a chance to get started quickly writing and - executing some first simple tests. The chapter will introduce some of the - basics, but leave most explanations and details for the later - chapters in this User's Guide. Hopefully though, after this chapter, you - will be inspired and unintimidated enough to go on and get into the - nitty-gritty that follows in this rather heavy User's Guide! If you're - not much into "learning by example" and prefer to get into more technical - detail right away, go ahead and skip to the next chapter. Again, the basics - presented here will be covered in detail in later chapters. + The purpose of this section is to let the newcomer get started in + quickly writing and executing some first simple tests with a + "learning by example" approach. Most explanations are left for later sections. + If you are not much into "learning by example" and prefer more technical + details, go ahead and skip to the next section. </p> <p> - This chapter also tries to demonstrate how dead simple it actually is - to write a very basic (yet for many module testing purposes, often sufficiently - complex) test suite, and execute its test cases. This is not necessarily - obvious when you read the rest of the chapters in the User's Guide. - </p> - <p> - A quick note before we start: In order to understand what's discussed and - examplified here, it is recommended that you first read through the - opening <seealso marker="basics_chapter#basics">Common Test Basics</seealso> - chapter. + This section demonstrates how simple it is to write a basic + (yet for many module testing purposes, often sufficiently complex) + test suite and execute its test cases. This is not necessarily + obvious when you read the remaining sections in this User's Guide. </p> + <note> + <p> + To understand what is discussed and examplified here, we recommended + you to first read section + <seealso marker="basics_chapter#basics">Common Test Basics</seealso>. + </p> + </note> </section> <section> - <title>Test case execution</title> - <p>Execution of test cases is handled this way:</p> + <title>Test Case Execution</title> + <p>Execution of test cases is handled as follows:</p> <image file="tc_execution.gif"> <icaption> - Successful vs unsuccessful test case execution. + Successful and Unsuccessful Test Case Execution </icaption> </image> - <p>For each test case that Common Test is told to execute, it spawns a - dedicated process on which the test case function in question starts + <p>For each test case that <c>Common Test</c> is ordered to execute, it spawns a + dedicated process on which the test case function starts running. (In parallel to the test case process, an idle waiting timer - process is started which is linked to the test case process. If the timer + process is started, which is linked to the test case process. If the timer process runs out of waiting time, it sends an exit signal to terminate - the test case process and this is what's called a <em>timetrap</em>). + the test case process. This is called a <em>timetrap</em>). </p> - <p>In scenario 1, the test case process terminates normally after case A has - finished executing its test code without detecting any errors. The test - case function simply returns a value and Common Test logs the test case as - successful. + <p>In scenario 1, the test case process terminates normally after + <c>case A</c> has finished executing its test code without detecting + any errors. The test case function returns a value and <c>Common Test</c> + logs the test case as successful. </p> - <p>In scenario 2, an error is detected during test case execution - which causes the test case B function to generate an exception. - This causes the test case process to exit with reason - other than normal, and as a result, Common Test will log this as an - unsuccessful test case. + <p>In scenario 2, an error is detected during test <c>case B</c> execution. + This causes the test <c>case B</c> function to generate an exception + and, as a result, the test case process exits with reason other than normal. + <c>Common Test</c> logs this as an unsuccessful (Failed) test case. </p> - <p>As you can understand from the illustration above, Common Test requires - that a test case generates a runtime error to indicate failure (e.g. - by causing a bad match error or by calling <c>exit/1</c>, preferrably - through the <seealso marker="ct#fail-1"><c>ct:fail/1,2</c></seealso> help function). A succesful execution is - indicated by means of a normal return from the test case function. + <p>As you can understand from the illustration, <c>Common Test</c> requires + a test case to generate a runtime error to indicate failure (for example, + by causing a bad match error or by calling <c>exit/1</c>, preferably + through the help function + <seealso marker="ct#fail-1"><c>ct:fail/1,2</c></seealso>). A successful + execution is indicated by a normal return from the test case function. </p> </section> <section> - <title>A simple test suite</title> - <p>As you've seen in the basics chapter, the test suite module implements + <title>A Simple Test Suite</title> + <p>As shown in section + <seealso marker="basics_chapter#External_Interfaces">Common Test Basics</seealso>, + the test suite module implements <seealso marker="common_test">callback functions</seealso> - (mandatory or optional) for various purposes, e.g: + (mandatory or optional) for various purposes, for example: </p> - <list> + <list type="bulleted"> <item>Init/end configuration function for the test suite</item> <item>Init/end configuration function for a test case</item> <item>Init/end configuration function for a test case group</item> <item>Test cases</item> </list> <p> - The configuration functions are optional and if you don't need them for - your test, a test suite with one simple test case could look like this: + The configuration functions are optional. The following example is a test suite + without configuration functions, including one simple test case, to + check that module <c>mymod</c> exists (that is, can be successfully loaded by the + code server): </p> <pre> - -module(my1st_SUITE). - -compile(export_all). + -module(my1st_SUITE). + -compile(export_all). - all() -> - [mod_exists]. + all() -> + [mod_exists]. - mod_exists(_) -> - {module,mymod} = code:load_file(mymod).</pre> + mod_exists(_) -> + {module,mymod} = code:load_file(mymod).</pre> <p> - In this example we check that the <c>mymod</c> module exists (i.e. can be - successfully loaded by the code server). If the operation fails, we will - get a bad match error which terminates the test case. + If the operation fails, a bad match error occurs that terminates the test case. </p> </section> <section> - <title>A test suite with configuration functions</title> + <title>A Test Suite with Configuration Functions</title> <p> - If we need to perform configuration operations in order to run our test, we - implement configuration functions in our suite. The result from a - configuration function is configuration data, or simply <em><c>Config</c></em>. - This is a list of key-value tuples which get passed from the configuration + If you need to perform configuration operations to run your test, you can + implement configuration functions in your suite. The result from a + configuration function is configuration data, or <c>Config</c>. + This is a list of key-value tuples that get passed from the configuration function to the test cases (possibly through configuration functions on - "lower level"). The data flow looks like this: + "lower level"). The data flow looks as follows: </p> <image file="config.gif"> <icaption> - Config data flow in the suite. + Configuration Data Flow in a Suite </icaption> </image> <p> - Here's an example of a test suite which uses configuration functions - to open and close a log file for the test cases (an operation that would - be unnecessary and irrelevant to perform by each test case): + The following example shows a test suite that uses configuration functions + to open and close a log file for the test cases (an operation that is + unnecessary and irrelevant to perform by each test case): </p> <pre> - -module(check_log_SUITE). - -export([all/0, init_per_suite/1, end_per_suite/1]). - -export([check_restart_result/1, check_no_errors/1]). - - -define(value(Key,Config), proplists:get_value(Key,Config)). + -module(check_log_SUITE). + -export([all/0, init_per_suite/1, end_per_suite/1]). + -export([check_restart_result/1, check_no_errors/1]). - all() -> [check_restart_result, check_no_errors]. + -define(value(Key,Config), proplists:get_value(Key,Config)). - init_per_suite(InitConfigData) -> - [{logref,open_log()} | InitConfigData]. + all() -> [check_restart_result, check_no_errors]. - end_per_suite(ConfigData) -> - close_log(?value(logref, ConfigData)). + init_per_suite(InitConfigData) -> + [{logref,open_log()} | InitConfigData]. - check_restart_result(ConfigData) -> - TestData = read_log(restart, ?value(logref, ConfigData)), - {match,_Line} = search_for("restart successful", TestData). - - check_no_errors(ConfigData) -> - TestData = read_log(all, ?value(logref, ConfigData)), - case search_for("error", TestData) of - {match,Line} -> ct:fail({error_found_in_log,Line}); - nomatch -> ok - end.</pre> + end_per_suite(ConfigData) -> + close_log(?value(logref, ConfigData)). + + check_restart_result(ConfigData) -> + TestData = read_log(restart, ?value(logref, ConfigData)), + {match,_Line} = search_for("restart successful", TestData). + + check_no_errors(ConfigData) -> + TestData = read_log(all, ?value(logref, ConfigData)), + case search_for("error", TestData) of + {match,Line} -> ct:fail({error_found_in_log,Line}); + nomatch -> ok + end.</pre> <p> - In this example we have test cases that verify, by parsing a - log file, that our SUT has performed a successful restart and - that no unexpected errors have been printed. + The test cases verify, by parsing a log file, that our SUT has performed + a successful restart and that no unexpected errors are printed. </p> - <p>To execute the test cases in the test suite above, we could type this on - the Unix/Linux command line (assuming for this example that the suite module + <p>To execute the test cases in the recent test suite, type the + following on the UNIX/Linux command line (assuming that the suite module is in the current working directory): </p> <pre> - $ ct_run -dir .</pre> - <p>or</p> + $ ct_run -dir .</pre> + <p>or:</p> <pre> - $ ct_run -suite check_log_SUITE</pre> + $ ct_run -suite check_log_SUITE</pre> - <p>If we want to use the Erlang shell to run our test, we could evaluate this call: + <p>To use the Erlang shell to run our test, you can evaluate the following call: </p> <pre> - 1> ct:run_test([{dir, "."}]).</pre> - <p>or</p> + 1> ct:run_test([{dir, "."}]).</pre> + <p>or:</p> <pre> - 1> ct:run_test([{suite, "check_log_SUITE"}]).</pre> + 1> ct:run_test([{suite, "check_log_SUITE"}]).</pre> <p> - The result from running our test is printed in log files in HTML format - (stored in unique log directories on different level). This illustration - shows the log file structure: + The result from running the test is printed in log files in HTML format + (stored in unique log directories on a different level). The following + illustration shows the log file structure: </p> <image file="html_logs.gif"> <icaption> - HTML log file structure. + HTML Log File Structure </icaption> </image> </section> <section> - <title>What happens next?</title> + <title>Questions and Answers</title> - <p>Well, you might already be asking yourself questions such as:</p> + <p>Here follows some questions that you might have after reading this section + with corresponding tips and links to the answers: + </p> - <list> - <item>"How and where can I specify variable data for my tests that mustn't - be hard-coded in the test suites (such as host names, addresses, - user login data, etc)?" The - <seealso marker="config_file_chapter#top">External Configuration Data</seealso> - chapter will give you that information. + <list type="bulleted"> + <item><p><em>Question:</em> + "How and where can I specify variable data for my tests that must not + be hard-coded in the test suites (such as hostnames, addresses, and + user login data)?"</p> + <p><em>Answer:</em> + See section <seealso marker="config_file_chapter#top">External Configuration Data</seealso>.</p> </item> - <item>"Is there a way to declare a number of different tests and run them - in one session without having to write my own scripts? And can such - declarations be used for regression testing?" The + + <item><p><em>Question:</em> "Is there a way to declare different tests and run them + in one session without having to write my own scripts? Also, can such + declarations be used for regression testing?"</p> + <p><em>Answer:</em> See section <seealso marker="run_test_chapter#test_specifications">Test Specifications</seealso> - chapter answers these questions. + in section Running Tests and Analyzing Results. + </p> </item> - <item>"Can test cases and/or test runs be automatically repeated?" Learn more about + + <item><p><em>Question:</em> "Can test cases and/or test runs be automatically repeated?"</p> + <p><em>Answer:</em> Learn more about <seealso marker="write_test_chapter#test_case_groups">Test Case Groups</seealso> - and also read about start flags/options in the - <seealso marker="run_test_chapter#ct_run">Running Tests</seealso> chapter and - the Reference Manual. + and read about start flags/options in section + <seealso marker="run_test_chapter#ct_run">Running Tests</seealso> and in + the Reference Manual.</p> </item> - <item>"Will Common Test execute my test cases in sequence or in parallel?" The + + <item><p><em>Question:</em> "Does <c>Common Test</c> execute my test cases in sequence or in parallel?"</p> + <p><em>Answer:</em> See <seealso marker="write_test_chapter#test_case_groups">Test Case Groups</seealso> - section in the Running Tests chapter will give you the answer. + in section Writing Test Suites.</p> </item> - <item>"What's the syntax for timetraps (mentioned above), and how do I set them?" - This is explained in the - <seealso marker="write_test_chapter#timetraps">Timetrap Timeouts</seealso> - part of the Writing Test Suites chapter. + + <item><p><em>Question:</em> "What is the syntax for timetraps (mentioned earlier), and how do I set them?"</p> + <p><em>Answer:</em> This is explained in the + <seealso marker="write_test_chapter#timetraps">Timetrap Time-Outs</seealso> + part of section Writing Test Suites.</p> </item> - <item>"What functions are available for logging and printing?" Check the + + <item><p><em>Question:</em> "What functions are available for logging and printing?"</p> + <p><em>Answer:</em> See <seealso marker="write_test_chapter#logging">Logging</seealso> - section in the Writing Test Suites chapter. + in section Writing Test Suites.</p> </item> - <item>"I need data files for my tests. Where do I store them preferrably?" - You should read about + + <item><p><em>Question:</em> "I need data files for my tests. Where do I store them preferably?"</p> + <p><em>Answer:</em> See <seealso marker="write_test_chapter#data_priv_dir">Data and Private - Directories</seealso> for information about this. + Directories</seealso>.</p> </item> - <item>"May I start with a test suite example, please?" - <seealso marker="example_chapter#top">Sure!</seealso> + + <item><p><em>Question:</em> "Can I start with a test suite example, please?"</p> + <p><em>Answer:</em> <seealso marker="example_chapter#top">Welcome!</seealso></p> </item> </list> - <p>You will probably want to get started on your own first test suites now, while - at the same time digging deeper into the Common Test User's Guide and Reference Manual. - You will find that there's lots more to learn about the things that have been introduced - in this chapter. You will of course also be presented many more useful features, such as the - ones listed above. Have fun! + <p>You probably want to get started on your own first test suites now, while + at the same time digging deeper into the <c>Common Test</c> User's Guide and Reference Manual. + There are much more to learn about the things that have been introduced + in this section. There are also many other useful features to learn, + so please continue to the other sections and have fun. </p> </section> </chapter> diff --git a/lib/common_test/doc/src/install_chapter.xml b/lib/common_test/doc/src/install_chapter.xml index 107b0e2eac..9dce1e31a4 100644 --- a/lib/common_test/doc/src/install_chapter.xml +++ b/lib/common_test/doc/src/install_chapter.xml @@ -32,22 +32,23 @@ <section> <marker id="general"></marker> - <title>General information</title> - - <p>The two main interfaces for running tests with Common Test - are an executable program named <c>ct_run</c> and an - erlang module named <c>ct</c>. The ct_run program - is compiled for the underlying operating system (e.g. Unix/Linux - or Windows) during the build of the Erlang/OTP system, and is - installed automatically with other executable programs in + <title>General Information</title> + + <p>The two main interfaces for running tests with <c>Common Test</c> + are an executable program named + <seealso marker="ct_run"><c>ct_run</c></seealso> and the + Erlang module <seealso marker="ct"><c>ct</c></seealso>. + <c>ct_run</c> is compiled for the underlying operating system (for example, + Unix/Linux or Windows) during the build of the Erlang/OTP system, + and is installed automatically with other executable programs in the top level <c>bin</c> directory of Erlang/OTP. The <c>ct</c> interface functions can be called from the Erlang shell, or from any Erlang function, on any supported platform.</p> - <p>The Common Test application is installed with the Erlang/OTP - system and no additional installation step is required to start using - Common Test by means of the <c>ct_run</c> executable program, and/or - the interface functions in the <c>ct</c> module.</p> + <p>The <c>Common Test</c> application is installed with the Erlang/OTP + system. No extra installation step is required to start using + <c>Common Test</c> through the <c>ct_run</c> executable program, + and/or the interface functions in the <c>ct</c> module.</p> </section> </chapter> diff --git a/lib/common_test/doc/src/introduction.xml b/lib/common_test/doc/src/introduction.xml new file mode 100644 index 0000000000..e2a42bfd33 --- /dev/null +++ b/lib/common_test/doc/src/introduction.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE chapter SYSTEM "chapter.dtd"> + +<chapter> + <header> + <copyright> + <year>2003</year><year>2013</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>Introduction</title> + <prepared></prepared> + <docno></docno> + <date>2015-10-05</date> + <rev></rev> + <file>introduction.xml</file> + </header> + <section> + <title>Scope</title> + <p><c>Common Test</c> is a portable application for automated + testing. It is suitable for:</p> + <list type="bulleted"> + <item><p>Black-box testing of target systems of any type (that + is, not necessarily implemented in Erlang). This is performed + through standard O&M interfaces (such as SNMP, HTTP, CORBA, + and Telnet) and, if necessary, through user-specific interfaces + (often called test ports).</p></item> + <item><p>White-box testing of Erlang/OTP programs. This is easily + done by calling the target API functions directly from the test + case functions.</p></item> + </list> + <p><c>Common Test</c> also integrates use of the OTP + <seealso marker="tools:cover">cover</seealso> tool in application + <c>Tools</c> for code coverage analysis of Erlang/OTP programs.</p> + + <p><c>Common Test</c> executes test suite programs automatically, + without operator interaction. Test progress and results are + printed to logs in HTML format, easily browsed with a standard + web browser. <c>Common Test</c> also sends notifications about progress + and results through an OTP event manager to event handlers plugged + in to the system. This way, users can integrate their own + programs for, for example, logging, database storing, or supervision with + <c>Common Test</c>.</p> + + <p><c>Common Test</c> provides libraries with useful support + functions to fill various testing needs and requirements. + There is, for example, support for flexible test declarations + through test specifications. There is also support + for central configuration and control of multiple + independent test sessions (to different target systems) + running in parallel.</p> + + </section> + + <section> + <title>Prerequisites</title> + <p>It is assumed that the reader is familiar with the Erlang + programming language.</p > + </section> + +</chapter> diff --git a/lib/common_test/doc/src/part.xml b/lib/common_test/doc/src/part.xml index 0f4c448787..41e74e57c6 100644 --- a/lib/common_test/doc/src/part.xml +++ b/lib/common_test/doc/src/part.xml @@ -31,40 +31,9 @@ </header> <description> - <p><em>Common Test</em> is a portable application for automated - testing. It is suitable for black-box testing of target - systems of any type (i.e. not necessarily implemented in Erlang), - as well as for white-box testing of Erlang/OTP programs. - Black-box testing is performed via standard O&M - interfaces (such as SNMP, HTTP, Corba, Telnet, etc) and, - if required, via user specific interfaces (often called test - ports). White-box testing of Erlang/OTP programs is easily - accomplished by calling the target API functions directly - from the test case functions. Common Test also integrates - usage of the OTP cover tool for code coverage analysis of - Erlang/OTP programs.</p> - - <p>Common Test executes test suite programs automatically, - without operator interaction. Test progress and results is - printed to logs on HTML format, easily browsed with a standard - web browser. Common Test also sends notifications about progress - and results via an OTP event manager to event handlers plugged - in to the system. This way users can integrate their own - programs for e.g. logging, database storing or supervision with - Common Test.</p> - - <p>Common Test provides libraries that contain useful support - functions to fill various testing needs and requirements. - There is for example support for flexible test declarations - by means of so called test specifications. There is also support - for central configuration and control of multiple - independent test sessions (towards different target systems) - running in parallel.</p> - - <p>Common Test is implemented as a framework based on the OTP Test - Server application.</p> </description> + <xi:include href="introduction.xml"/> <xi:include href="basics_chapter.xml"/> <xi:include href="getting_started_chapter.xml"/> <xi:include href="install_chapter.xml"/> diff --git a/lib/common_test/doc/src/ref_man.xml b/lib/common_test/doc/src/ref_man.xml index f98e2475a9..19960bfea7 100644 --- a/lib/common_test/doc/src/ref_man.xml +++ b/lib/common_test/doc/src/ref_man.xml @@ -30,43 +30,10 @@ <file>ref_man.xml</file> </header> <description> - <p><em>Common Test</em> is a portable application for automated - testing. It is suitable for black-box testing of target - systems of any type (i.e. not necessarily implemented in Erlang), - as well as for white-box testing of Erlang/OTP programs. - Black-box testing is performed via standard O&M - interfaces (such as SNMP, HTTP, Corba, Telnet, etc) and, - if required, via user specific interfaces (often called test - ports). White-box testing of Erlang/OTP programs is easily - accomplished by calling the target API functions directly - from the test case functions. Common Test also integrates - usage of the OTP cover tool for code coverage analysis of - Erlang/OTP programs.</p> - - <p>Common Test executes test suite programs automatically, - without operator interaction. Test progress and results is - printed to logs on HTML format, easily browsed with a standard - web browser. Common Test also sends notifications about progress - and results via an OTP event manager to event handlers plugged - in to the system. This way users can integrate their own - programs for e.g. logging, database storing or supervision with - Common Test.</p> - - <p>Common Test provides libraries that contain useful support - functions to fill various testing needs and requirements. - There is for example support for flexible test declarations - by means of so called test specifications. There is also support - for central configuration and control of multiple - independent test sessions (towards different target systems) - running in parallel.</p> - - <p>Common Test is implemented as a framework based on the OTP Test - Server application.</p> </description> + <xi:include href="common_test_app.xml"/> <xi:include href="ct_run.xml"/> - <!-- If you make modifications in the module list below, - you also need to update CT_MODULES in Makefile. --> <xi:include href="ct.xml"/> <xi:include href="ct_master.xml"/> <xi:include href="ct_cover.xml"/> @@ -83,6 +50,3 @@ </application> - - - diff --git a/lib/common_test/doc/src/run_test_chapter.xml b/lib/common_test/doc/src/run_test_chapter.xml index 082a587c8d..e04bb3e208 100644 --- a/lib/common_test/doc/src/run_test_chapter.xml +++ b/lib/common_test/doc/src/run_test_chapter.xml @@ -33,95 +33,96 @@ <section> <title>Using the Common Test Framework</title> - <p>The Common Test Framework provides a high level - operator interface for testing. It adds the following features to - the Erlang/OTP Test Server:</p> - - <list> - <item>Automatic compilation of test suites (and help modules).</item> - <item>Creation of additional HTML pages for better overview.</item> - <item>Single command interface for running all available tests.</item> + <p>The <c>Common Test</c> framework provides a high-level + operator interface for testing, providing the following features:</p> + + <list type="bulleted"> + <item>Automatic compilation of test suites (and help modules)</item> + <item>Creation of extra HTML pages for improved overview.</item> + <item>Single-command interface for running all available tests</item> <item>Handling of configuration files specifying data related to - the System Under Test (and any other variable data).</item> + the System Under Test (SUT) (and any other variable data)</item> <item>Mode for running multiple independent test sessions in parallel with - central control and configuration.</item> + central control and configuration</item> </list> </section> <section> - <title>Automatic compilation of test suites and help modules</title> - <p>When Common Test starts, it will automatically attempt to compile any + <title>Automatic Compilation of Test Suites and Help Modules</title> + <p>When <c>Common Test</c> starts, it automatically attempts to compile any suites included in the specified tests. If particular - suites have been specified, only those suites will be compiled. If a - particular test object directory has been specified (meaning all suites - in this directory should be part of the test), Common Test runs - make:all/1 in the directory to compile the suites.</p> + suites are specified, only those suites are compiled. If a + particular test object directory is specified (meaning all suites + in this directory are to be part of the test), <c>Common Test</c> runs + function <c>make:all/1</c> in the directory to compile the suites.</p> - <p>If compilation should fail for one or more suites, the compilation errors - are printed to tty and the operator is asked if the test run should proceed + <p>If compilation fails for one or more suites, the compilation errors + are printed to tty and the operator is asked if the test run is to proceed without the missing suites, or be aborted. If the operator chooses to proceed, - it is noted in the HTML log which tests have missing suites. Also, for each failed - compilation, the failed tests counter in the return value of - <c><![CDATA[ct:run_test/1]]></c> is incremented. If Common Test is unable to prompt - the user after compilation failure (if Common Test doesn't control stdin), the test - run will proceed automatically without the missing suites. In order to always - abort the test run (without operator interaction) if one or more suites fail - to compile, the <c><![CDATA[ct_run]]></c> flag <c><![CDATA[-abort_if_missing_suites]]></c>, - or the <c><![CDATA[ct:run_test/1]]></c> option - <c><![CDATA[{abort_if_missing_suites,true}]]></c> should be set.</p> - - <p>Any help module (i.e. regular Erlang module with name not ending with - "_SUITE") that resides in the same test object directory as a suite - which is part of the test, will also be automatically compiled. A help - module will not be mistaken for a test suite (unless it has a "_SUITE" - name of course). All help modules in a particular test object directory - are compiled no matter if all or only particular suites in the directory + the tests having missing suites are noted in the HTML log. If <c>Common Test</c> is + unable to prompt the user after compilation failure (if <c>Common Test</c> does not + control <c>stdin</c>), the test run proceeds automatically without the missing + suites. This behavior can however be modified with the + <c><![CDATA[ct_run]]></c> flag <c><![CDATA[-abort_if_missing_suites]]></c>, + or the <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso> option + <c><![CDATA[{abort_if_missing_suites,TrueOrFalse}]]></c>. If + <c><![CDATA[abort_if_missing_suites]]></c> is set to <c>true</c>, the test run + stops immediately if some suites fail to compile.</p> + + <p>Any help module (that is, regular Erlang module with name not ending with + "_SUITE") that resides in the same test object directory as a suite, + which is part of the test, is also automatically compiled. A help + module is not mistaken for a test suite (unless it has a "_SUITE" name). + All help modules in a particular test object directory + are compiled, no matter if all or only particular suites in the directory are part of the test.</p> <p>If test suites or help modules include header files stored in other - locations than the test directory, you may specify these include directories - by means of the <c><![CDATA[-include]]></c> flag with <c><![CDATA[ct_run]]></c>, - or the <c><![CDATA[include]]></c> option with <c><![CDATA[ct:run_test/1]]></c>. - In addition to this, an include path may be specified with an OS - environment variable; <c><![CDATA[CT_INCLUDE_PATH]]></c>. Example (bash):</p> + locations than the test directory, these include directories can be specified + by using flag <c><![CDATA[-include]]></c> with + <seealso marker="ct_run"><c>ct_run</c></seealso>, + or option <c><![CDATA[include]]></c> with <c><![CDATA[ct:run_test/1]]></c>. + Also, an include path can be specified with an OS + environment variable, <c><![CDATA[CT_INCLUDE_PATH]]></c>.</p> + <p><em>Example (bash):</em></p> <p><c>$ export CT_INCLUDE_PATH=~testuser/common_suite_files/include:~testuser/common_lib_files/include</c></p> - <p>Common Test will pass all include directories (specified either with the - <c><![CDATA[include]]></c> flag/option, or the <c><![CDATA[CT_INCLUDE_PATH]]></c> - variable, or both) to the compiler.</p> + <p><c>Common Test</c> passes all include directories (specified either with flag/option + <c><![CDATA[include]]></c>, or variable <c><![CDATA[CT_INCLUDE_PATH]]></c> + , or both, to the compiler.</p> - <p>It is also possible to specify include directories in test specifications - (see below).</p> + <p>Include directories can also be specified in test specifications, + see <seealso marker="#test_specifications">Test Specifications</seealso>.</p> - <p>If the user wants to run all test suites for a test object (or OTP application) - by specifying only the top directory (e.g. with the <c>dir</c> start flag/option), - Common Test will primarily look for test suite modules in a subdirectory named - <c>test</c>. If this subdirectory doesn't exist, the specified top directory - is assumed to be the actual test directory, and test suites will be read from + <p>If the user wants to run all test suites for a test object (or an OTP application) + by specifying only the top directory (for example, with start flag/option <c>dir</c>), + <c>Common Test</c> primarily looks for test suite modules in a subdirectory named + <c>test</c>. If this subdirectory does not exist, the specified top directory + is assumed to be the test directory, and test suites are read from there instead.</p> - <p>It is possible to disable the automatic compilation feature by using the - <c><![CDATA[-no_auto_compile]]></c> flag with <c><![CDATA[ct_run]]></c>, or - the <c><![CDATA[{auto_compile,false}]]></c> option with + <p>To disable the automatic compilation feature, use flag + <c><![CDATA[-no_auto_compile]]></c> with <c><![CDATA[ct_run]]></c>, or + option <c><![CDATA[{auto_compile,false}]]></c> with <c><![CDATA[ct:run_test/1]]></c>. With automatic compilation disabled, the user is responsible for compiling the test suite modules - (and any help modules) before the test run. If the modules can not be loaded - from the local file system during startup of Common Test, the user needs to - pre-load the modules before starting the test. Common Test will only verify - that the specified test suites exist (i.e. that they are, or can be, loaded). - This is useful e.g. if the test suites are transferred and loaded as binaries via - RPC from a remote node.</p> + (and any help modules) before the test run. If the modules cannot be loaded + from the local file system during startup of <c>Common Test</c>, the user must + preload the modules before starting the test. <c>Common Test</c> only verifies + that the specified test suites exist (that is, that they are, or can be, loaded). + This is useful, for example, if the test suites are transferred and loaded as + binaries through RPC from a remote node.</p> </section> <section> <marker id="ct_run"></marker> - <title>Running tests from the OS command line</title> + <title>Running Tests from the OS Command Line</title> - <p>The <c>ct_run</c> program can be used for running tests from - the OS command line, e.g. + <p>The <seealso marker="ct_run"><c>ct_run</c></seealso> program can be used + for running tests from the OS command line, for example, as follows: </p> - <list> + <list type="bulleted"> <item><c><![CDATA[ct_run -config <configfilenames> -dir <dirs>]]></c></item> <item><c><![CDATA[ct_run -config <configfilenames> -suite <suiteswithfullpath>]]></c> </item> @@ -130,824 +131,917 @@ <item><c><![CDATA[ct_run -config <configfilenames> -suite <suitewithfullpath> -group <groups> -case <casenames>]]></c></item> </list> - <p>Examples:</p> - <p><c>$ ct_run -config $CFGS/sys1.cfg $CFGS/sys2.cfg -dir $SYS1_TEST $SYS2_TEST</c></p> - <p><c>$ ct_run -userconfig ct_config_xml $CFGS/sys1.xml $CFGS/sys2.xml -dir $SYS1_TEST $SYS2_TEST</c></p> - <p><c>$ ct_run -suite $SYS1_TEST/setup_SUITE $SYS2_TEST/config_SUITE</c></p> - <p><c>$ ct_run -suite $SYS1_TEST/setup_SUITE -case start stop</c></p> - <p><c>$ ct_run -suite $SYS1_TEST/setup_SUITE -group installation -case start stop</c></p> + <p><em>Examples:</em></p> + <pre> + $ ct_run -config $CFGS/sys1.cfg $CFGS/sys2.cfg -dir $SYS1_TEST $SYS2_TEST + $ ct_run -userconfig ct_config_xml $CFGS/sys1.xml $CFGS/sys2.xml -dir $SYS1_TEST $SYS2_TEST + $ ct_run -suite $SYS1_TEST/setup_SUITE $SYS2_TEST/config_SUITE + $ ct_run -suite $SYS1_TEST/setup_SUITE -case start stop + $ ct_run -suite $SYS1_TEST/setup_SUITE -group installation -case start stop</pre> - <p>It is also possible to combine the <c>dir</c>, <c>suite</c> and <c>group/case</c> flags. E.g, to run - <c>x_SUITE</c> and <c>y_SUITE</c> in directory <c>testdir</c>:</p> - - <p><c>$ ct_run -dir ./testdir -suite x_SUITE y_SUITE</c></p> - - <p>This has the same effect as calling:</p> - - <p><c>$ ct_run -suite ./testdir/x_SUITE ./testdir/y_SUITE</c></p> - - <p>For more details on <seealso marker="run_test_chapter#group_execution">test case group execution</seealso>, please see below.</p> - - <p>Other flags that may be used with <c>ct_run</c>:</p> - <list> - <item><c><![CDATA[-help]]></c>, lists all available start flags.</item> - <item><c><![CDATA[-logdir <dir>]]></c>, specifies where the HTML log files are to be written.</item> - <item><c><![CDATA[-label <name_of_test_run>]]></c>, associates the test run with a name that gets printed - in the overview HTML log files.</item> - <item><c>-refresh_logs</c>, refreshes the top level HTML index files.</item> - <item><c>-vts</c>, start web based GUI (see below).</item> - <item><c>-shell</c>, start interactive shell mode (see below).</item> - <item><c>-step [step_opts]</c>, step through test cases using the Erlang Debugger (see below).</item> - <item><c><![CDATA[-spec <testspecs>]]></c>, use test specification as input (see below).</item> - <item><c>-allow_user_terms</c>, allows user specific terms in a test specification (see below).</item> - <item><c>-silent_connections [conn_types]</c>, tells Common Test to suppress printouts for - specified connections (see below).</item> - <item><c><![CDATA[-stylesheet <css_file>]]></c>, points out a user HTML style sheet (see below).</item> - <item><c><![CDATA[-cover <cover_cfg_file>]]></c>, to perform code coverage test (see - <seealso marker="cover_chapter#cover">Code Coverage Analysis</seealso>).</item> - <item><c><![CDATA[-cover_stop <bool>]]></c>, to specify if the cover tool shall be stopped after the test is completed (see - <seealso marker="cover_chapter#cover_stop">Code Coverage Analysis</seealso>).</item> - <item><c><![CDATA[-event_handler <event_handlers>]]></c>, to install - <seealso marker="event_handler_chapter#event_handling">event handlers</seealso>.</item> - <item><c><![CDATA[-event_handler_init <event_handlers>]]></c>, to install - <seealso marker="event_handler_chapter#event_handling">event handlers</seealso> including start arguments.</item> - <item><c><![CDATA[-ct_hooks <ct_hooks>]]></c>, to install - <seealso marker="ct_hooks_chapter#installing">Common Test Hooks</seealso> including start arguments.</item> - <item><c><![CDATA[-enable_builtin_hooks <bool>]]></c>, to enable/disable - <seealso marker="ct_hooks_chapter#builtin_cths">Built-in Common Test Hooks</seealso>. Default is <c>true</c>.</item> - <item><c><![CDATA[-include]]></c>, specifies include directories (see above).</item> - <item><c><![CDATA[-no_auto_compile]]></c>, disables the automatic test suite compilation feature (see above).</item> - <item><c><![CDATA[-abort_if_missing_suites]]></c>, aborts the test run if one or more suites fail to compile (see above).</item> - <item><c><![CDATA[-multiply_timetraps <n>]]></c>, extends <seealso marker="write_test_chapter#timetraps">timetrap - timeout</seealso> values.</item> - <item><c><![CDATA[-scale_timetraps <bool>]]></c>, enables automatic <seealso marker="write_test_chapter#timetraps">timetrap - timeout</seealso> scaling.</item> - <item><c><![CDATA[-repeat <n>]]></c>, tells Common Test to repeat the tests n times (see below).</item> - <item><c><![CDATA[-duration <time>]]></c>, tells Common Test to repeat the tests for duration of time (see below).</item> - <item><c><![CDATA[-until <stop_time>]]></c>, tells Common Test to repeat the tests until stop_time (see below).</item> - <item><c>-force_stop [skip_rest]</c>, on timeout, the test run will be aborted when current test job is finished. If <c>skip_rest</c> is provided the rest of the test cases in the current test job will be skipped (see below).</item> - <item><c><![CDATA[-decrypt_key <key>]]></c>, provides a decryption key for - <seealso marker="config_file_chapter#encrypted_config_files">encrypted configuration files</seealso>.</item> - <item><c><![CDATA[-decrypt_file <key_file>]]></c>, points out a file containing a decryption key for - <seealso marker="config_file_chapter#encrypted_config_files">encrypted configuration files</seealso>.</item> - <item><c><![CDATA[-basic_html]]></c>, switches off html enhancements that might not be compatible with older browsers.</item> - <item><c><![CDATA[-logopts <opts>]]></c>, makes it possible to modify aspects of the logging behaviour, see - <seealso marker="run_test_chapter#logopts">Log options</seealso> below.</item> - <item><c><![CDATA[-verbosity <levels>]]></c>, sets <seealso marker="write_test_chapter#logging">verbosity levels - for printouts</seealso>.</item> - </list> + <p>The flags <c>dir</c>, <c>suite</c>, and <c>group/case</c> can be combined. + For example, to run <c>x_SUITE</c> and <c>y_SUITE</c> + in directory <c>testdir</c>, as follows:</p> + <pre> + $ ct_run -dir ./testdir -suite x_SUITE y_SUITE</pre> + + <p>This has the same effect as the following:</p> + <pre> + $ ct_run -suite ./testdir/x_SUITE ./testdir/y_SUITE</pre> + + <p>For details, see + <seealso marker="run_test_chapter#group_execution">Test Case Group Execution</seealso>.</p> + + <p>The following flags can also be used with + <seealso marker="ct_run"><c>ct_run</c></seealso>:</p> + <taglist> + <tag><c><![CDATA[-help]]></c></tag> + <item><p>Lists all available start flags.</p></item> + + <tag><c><![CDATA[-logdir <dir>]]></c></tag> + <item><p>Specifies where the HTML log files are to be written.</p></item> + + <tag><c><![CDATA[-label <name_of_test_run>]]></c></tag> + <item><p>Associates the test run with a name that gets printed + in the overview HTML log files.</p></item> + + <tag><c>-refresh_logs</c></tag> + <item><p>Refreshes the top-level HTML index files.</p></item> + + <tag><c>-vts</c></tag> + <item><p>Starts web-based GUI (described later).</p></item> + + <tag><c>-shell</c></tag> + <item><p>Starts interactive shell mode (described later).</p></item> + + <tag><c>-step [step_opts]</c></tag> + <item><p>Steps through test cases using the Erlang Debugger (described later).</p></item> + + <tag><c><![CDATA[-spec <testspecs>]]></c></tag> + <item><p>Uses test specification as input (described later).</p></item> + + <tag><c>-allow_user_terms</c></tag> + <item><p>Allows user-specific terms in a test specification (described later).</p></item> + + <tag><c>-silent_connections [conn_types]</c></tag> + <item><p>, tells <c>Common Test</c> to suppress printouts for + specified connections (described later).</p></item> + + <tag><c><![CDATA[-stylesheet <css_file>]]></c></tag> + <item><p>Points out a user HTML style sheet (described later).</p></item> + + <tag><c><![CDATA[-cover <cover_cfg_file>]]></c></tag> + <item><p>To perform code coverage test (see + <seealso marker="cover_chapter#cover">Code Coverage Analysis</seealso>).</p></item> + + <tag><c><![CDATA[-cover_stop <bool>]]></c></tag> + <item><p>To specify if the <c>cover</c> tool is to be stopped + after the test is completed (see + <seealso marker="cover_chapter#cover_stop">Code Coverage Analysis</seealso>).</p></item> + + <tag><c><![CDATA[-event_handler <event_handlers>]]></c></tag> + <item><p>To install + <seealso marker="event_handler_chapter#event_handling">event handlers</seealso>.</p></item> + + <tag><c><![CDATA[-event_handler_init <event_handlers>]]></c></tag> + <item><p>To install + <seealso marker="event_handler_chapter#event_handling">event handlers</seealso> + including start arguments.</p></item> + + <tag><c><![CDATA[-ct_hooks <ct_hooks>]]></c></tag> + <item><p>To install + <seealso marker="ct_hooks_chapter#installing">Common Test Hooks</seealso> + including start arguments.</p></item> - <note><p>Directories passed to Common Test may have either relative or absolute paths.</p></note> + <tag><c><![CDATA[-enable_builtin_hooks <bool>]]></c></tag> + <item><p>To enable or disable + <seealso marker="ct_hooks_chapter#builtin_cths">Built-in Common Test Hooks</seealso>. + Default is <c>true</c>.</p></item> - <note><p>Arbitrary start flags to the Erlang Runtime System may also be passed as + <tag><c><![CDATA[-include]]></c></tag> + <item><p>Specifies include directories (described earlier).</p></item> + + <tag><c><![CDATA[-no_auto_compile]]></c></tag> + <item><p>Disables the automatic test suite compilation feature (described earlier).</p></item> + + <tag><c><![CDATA[-abort_if_missing_suites]]></c></tag> + <item><p>Aborts the test run if one or more suites fail to compile (described earlier).</p></item> + + <tag><c><![CDATA[-multiply_timetraps <n>]]></c></tag> + <item><p>Extends <seealso marker="write_test_chapter#timetraps">timetrap + time-out</seealso> values.</p></item> + + <tag><c><![CDATA[-scale_timetraps <bool>]]></c></tag> + <item><p>Enables automatic <seealso marker="write_test_chapter#timetraps">timetrap + time-out</seealso> scaling.</p></item> + + <tag><c><![CDATA[-repeat <n>]]></c></tag> + <item><p>Tells <c>Common Test</c> to repeat the tests <c>n</c> times (described later).</p></item> + + <tag><c><![CDATA[-duration <time>]]></c></tag> + <item><p>Tells <c>Common Test</c> to repeat the tests for duration of time (described later).</p></item> + + <tag><c><![CDATA[-until <stop_time>]]></c></tag> + <item><p>Tells <c>Common Test</c> to repeat the tests until <c>stop_time</c> (described later).</p></item> + + <tag><c>-force_stop [skip_rest]</c></tag> + <item><p>On time-out, the test run is aborted when the current test job is finished. If <c>skip_rest</c> + is provided, the remaining test cases in the current test job are skipped (described later).</p></item> + + <tag><c><![CDATA[-decrypt_key <key>]]></c></tag> + <item><p>Provides a decryption key for + <seealso marker="config_file_chapter#encrypted_config_files">encrypted configuration files</seealso>.</p></item> + + <tag><c><![CDATA[-decrypt_file <key_file>]]></c></tag> + <item><p>Points out a file containing a decryption key for + <seealso marker="config_file_chapter#encrypted_config_files">encrypted configuration files</seealso>.</p></item> + + <tag><c><![CDATA[-basic_html]]></c></tag> + <item><p>Switches off HTML enhancements that can be incompatible with older browsers.</p></item> + + <tag><c><![CDATA[-logopts <opts>]]></c></tag> + <item><p>Enables modification of the logging behavior, see + <seealso marker="run_test_chapter#logopts">Log options</seealso>.</p></item> + + <tag><c><![CDATA[-verbosity <levels>]]></c></tag> + <item><p>Sets <seealso marker="write_test_chapter#logging">verbosity levels + for printouts</seealso>.</p></item> + </taglist> + + <note><p>Directories passed to <c>Common Test</c> can have either relative or absolute paths.</p></note> + + <note><p>Any start flags to the Erlang runtime system (application <c>ERTS</c>) can also be passed as parameters to <c>ct_run</c>. It is, for example, useful to be able to - pass directories that should be added to the Erlang code server search path - with the <c>-pa</c> or <c>-pz</c> flag. If you have common help- or library + pass directories to be added to the Erlang code server search path + with flag <c>-pa</c> or <c>-pz</c>. If you have common help- or library modules for test suites (separately compiled), stored in other directories - than the test suite directories, these help/lib directories are preferrably - added to the code path this way. Example:</p> + than the test suite directories, these <c>help/lib</c> directories are preferably + added to the code path this way.</p> + <p><em>Example:</em></p> <p><c>$ ct_run -dir ./chat_server -logdir ./chat_server/testlogs -pa $PWD/chat_server/ebin</c></p> - <p>Note how in this example, the absolute path of the <c>chat_server/ebin</c> - directory is passed to the code server. This is essential since relative - paths are stored by the code server as relative, and Common Test changes - the current working directory of the Erlang Runtime System during the test run!</p> + <p>The absolute path of directory <c>chat_server/ebin</c> + is here passed to the code server. This is essential because relative + paths are stored by the code server as relative, and <c>Common Test</c> changes + the current working directory of <c>ERTS</c> during the test run.</p> </note> <p>The <c>ct_run</c> program sets the exit status before shutting down. The following values are defined:</p> - <list> - <item><c>0</c> indicates a successful testrun, i.e. one without failed or auto skipped test cases.</item> - <item><c>1</c> indicates that one or more test cases have failed, or have been auto skipped.</item> - <item><c>2</c> indicates that the test execution has failed because of e.g. compilation errors, an - illegal return value from an info function, etc.</item> + <list type="bulleted"> + <item><c>0</c> indicates a successful testrun, that is, without failed or auto-skipped test cases.</item> + <item><c>1</c> indicates that one or more test cases have failed, or have been auto-skipped.</item> + <item><c>2</c> indicates that the test execution has failed because of, for example, compilation errors, or an + illegal return value from an information function.</item> </list> - <p>If auto skipped test cases should not affect the exit status, you may change the default - behaviour using start flag:</p> - <pre>-exit_status ignore_config</pre> + <p>If auto-skipped test cases do not affect the exit status. The default + behavior can be changed using start flag:</p> + <pre> + -exit_status ignore_config</pre> - <note><p>Executing <c>ct_run</c> without start flags, is equal to the command: + <note><p>Executing <c>ct_run</c> without start flags is equal to the command: <c>ct_run -dir ./</c></p></note> - <p>For more information about the <c>ct_run</c> program, see the - <seealso marker="ct_run">Reference Manual</seealso> and the - <seealso marker="install_chapter#general">Installation</seealso> chapter. + <p>For more information about the <c>ct_run</c> program, see module + <seealso marker="ct_run"><c>ct_run</c></seealso> and section + <seealso marker="install_chapter#general">Installation</seealso>. </p> </section> <section> - <title>Running tests from the Erlang shell or from an Erlang program</title> + <marker id="erlang_shell_or_program"></marker> + <title>Running Tests from the Erlang Shell or from an Erlang Program</title> - <p>Common Test provides an Erlang API for running tests. The main (and most - flexible) function for specifying and executing tests is called + <p><c>Common Test</c> provides an Erlang API for running tests. The main + (and most flexible) function for specifying and executing tests is <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>. - This function takes the same start parameters as - the <seealso marker="run_test_chapter#ct_run"><c>ct_run</c></seealso> - program described above, only the flags are instead - given as options in a list of key-value tuples. E.g. a test specified - with <c>ct_run</c> like:</p> + It takes the same start parameters as + <seealso marker="run_test_chapter#ct_run"><c>ct_run</c></seealso>, + but the flags are instead specified as options in a list of key-value tuples. + For example, a test specified with <c>ct_run</c> as follows:</p> <p><c>$ ct_run -suite ./my_SUITE -logdir ./results</c></p> <p>is with <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso> specified as:</p> <p><c>1> ct:run_test([{suite,"./my_SUITE"},{logdir,"./results"}]).</c></p> - <p>The function returns the test result, represented by the tuple: + <p>The function returns the test result, represented by the tuple <c>{Ok,Failed,{UserSkipped,AutoSkipped}}</c>, where each element is an - integer. If test execution fails, the function returns the tuple: + integer. If test execution fails, the function returns the tuple <c>{error,Reason}</c>, where the term <c>Reason</c> explains the failure.</p> - <p>The default start option <c>{dir,Cwd}</c> (run all suites in the current + <p>The default start option <c>{dir,Cwd}</c> (to run all suites in the current working directory) is used if the function is called with an empty list of options.</p> <section> - <title>Releasing the Erlang shell</title> - <p>During execution of tests, started with + <title>Releasing the Erlang Shell</title> + <p>During execution of tests started with <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>, - the Erlang shell process, controlling stdin, will remain the top - level process of the Common Test system of processes. The result - is that the Erlang shell is not available for interaction during - the test run. If this is not desirable, maybe because the shell is needed - for debugging purposes or for interaction with the SUT during test - execution, you may set the <c>release_shell</c> start option to + the Erlang shell process, controlling <c>stdin</c>, remains the top-level + process of the <c>Common Test</c> system of processes. Consequently, + the Erlang shell is not available for interaction during + the test run. If this is not desirable, for example, because the shell + is needed for debugging purposes or for interaction with the SUT during test + execution, set start option <c>release_shell</c> to <c>true</c> (in the call to <c>ct:run_test/1</c> or by - using the corresponding test specification term, see below). This will - make Common Test release the shell immediately after the test suite + using the corresponding test specification term, described later). This + makes <c>Common Test</c> release the shell immediately after the test suite compilation stage. To accomplish this, a test runner process - is spawned to take control of the test execution, and the effect is that + is spawned to take control of the test execution. The effect is that <c>ct:run_test/1</c> returns the pid of this process rather than the - test result - which instead is printed to tty at the end of the test run.</p> - <note><p>Note that in order to use the - <seealso marker="ct#break-1"><c>ct:break/1/2</c></seealso> and - <seealso marker="ct#continue-0"><c>ct:continue/0/1</c></seealso> functions, + test result, which instead is printed to tty at the end of the test run.</p> + <note><p>To use the functions + <seealso marker="ct#break-1"><c>ct:break/1,2</c></seealso> and + <seealso marker="ct#continue-0"><c>ct:continue/0,1</c></seealso>, <c>release_shell</c> <em>must</em> be set to <c>true</c>.</p></note> </section> - <p>For detailed documentation about - <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>, - please see the - <seealso marker="ct#run_test-1"><c>ct</c></seealso> manual page.</p> + <p>For details, see + <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso> manual page.</p> </section> <section> <marker id="group_execution"></marker> - <title>Test case group execution</title> + <title>Test Case Group Execution</title> <p>With the <c>ct_run</c> flag, or <c>ct:run_test/1</c> option <c>group</c>, one or more test case groups can be specified, optionally in combination - with specific test cases. The syntax for specifying groups is as follows - (on the command line):</p> + with specific test cases. The syntax for specifying groups on the command line + is as follows:</p> <pre> - <![CDATA[$ ct_run -group <group_names_or_paths> [-case <cases>]]]></pre> - <p>or (in the Erlang shell):</p> + <![CDATA[$ ct_run -group <group_names_or_paths> [-case <cases>]]]></pre> + <p>The syntax in the Erlang shell is as follows:</p> <pre> - <![CDATA[1> ct:run_test([{group,GroupsNamesOrPaths}, {case,Cases}]).]]></pre> + <![CDATA[1> ct:run_test([{group,GroupsNamesOrPaths}, {case,Cases}]).]]></pre> - <p>The <c>group_names_or_paths</c> parameter specifies either one - or more group names and/or one or more group paths. At start up, - Common Test will search for matching groups in the group definitions - tree (i.e. the list returned from <c>Suite:groups/0</c>, please see the - <seealso marker="write_test_chapter#test_case_groups">Test case groups</seealso> - chapter for details). - Given a group name, say <c>g</c>, Common Test will search for all paths - that lead to <c>g</c>. By path here we mean a sequence of nested groups, - all of which have to be followed in order to get from the top level - group to <c>g</c>. Actually, what Common Test needs to do in order to - execute the test cases in group <c>g</c>, is to call the - <c>init_per_group/2</c> function for each group in the path to - <c>g</c>, as well as all corresponding <c>end_per_group/2</c> - functions afterwards. The obvious reason for this is that the configuration + <p>Parameter <c>group_names_or_paths</c> specifies one + or more group names and/or one or more group paths. At startup, + <c>Common Test</c> searches for matching groups in the group definitions + tree (that is, the list returned from <c>Suite:groups/0</c>; for details, see section + <seealso marker="write_test_chapter#test_case_groups">Test Case Groups</seealso>. + </p> + + <p>Given a group name, say <c>g</c>, <c>Common Test</c> searches for all paths + leading to <c>g</c>. By path is meant a sequence of nested groups, + which must be followed to get from the top-level + group to <c>g</c>. To execute the test cases in group <c>g</c>, + <c>Common Test</c> must call the <c>init_per_group/2</c> function for + each group in the path to <c>g</c>, and all corresponding <c>end_per_group/2</c> + functions afterwards. This is because the configuration of a test case in <c>g</c> (and its <c>Config</c> input data) depends on <c>init_per_testcase(TestCase, Config)</c> and its return value, which in turn depends on <c>init_per_group(g, Config)</c> and its return value, which in turn depends on <c>init_per_group/2</c> of the group above - <c>g</c>, etc, all the way up to the top level group.</p> + <c>g</c>, and so on, all the way up to the top-level group.</p> - <p>As you may have already realized, this means that if there is more than - one way to locate a group (and its test cases) in a path, the result of the - group search operation is a number of tests, all of which will be performed. - Common Test actually interprets a group specification that consists of a - single name this way:</p> + <p>This means that if there is more than one way to locate a group + (and its test cases) in a path, the result of the group search operation + is a number of tests, all of which are to be performed. + <c>Common Test</c> interprets a group specification that consists of a + single name as follows:</p> <p>"Search and find all paths in the group definitions tree that lead - to the specified group and, for each path, create a test which (1) executes - all configuration functions in the path to the specified group, then (2) - executes all - or all matching - test cases in this group, as well as (3) - all - or all matching - test cases in all sub groups of the group". - </p> + to the specified group and, for each path, create a test that does the following, + in order:</p> + <list type="ordered"> + <item>Executes all configuration functions in the path to the specified group.</item> + <item>Executes all, or all matching, test cases in this group.</item> + <item>Executes all, or all matching, test cases in all subgroups of the group."</item> + </list> - <p>It is also possible for the user to specify a specific group path with - the <c>group_names_or_paths</c> parameter. With this type of specification it's - possible to avoid execution of unwanted groups (in otherwise matching paths), - and/or the execution of sub groups. The syntax of the group path is a list of - group names in the path, e.g. on the command line: + <p>The user can specify a specific group path with + parameter <c>group_names_or_paths</c>. With this type of specification + execution of unwanted groups (in otherwise matching paths), + and/or the execution of subgroups can be avoided. The command line syntax of the + group path is a list of group names in the path, for example: </p> <p><c>$ ct_run -suite "./x_SUITE" -group [g1,g3,g4] -case tc1 tc5</c></p> - <p>or similarly in the Erlang shell (requires a list within the groups list):</p> + <p>The syntax in the Erlang shell is as follows (requires a list within the groups list):</p> <p><c>1> ct:run_test([{suite,"./x_SUITE"}, {group,[[g1,g3,g4]]}, {testcase,[tc1,tc5]}]).</c></p> - <p>The last group in the specified path will be the terminating group in - the test, i.e. no sub groups following this group will be executed. In the - example above, <c>g4</c> is the terminating group, hence Common Test will - execute a test that calls all init configuration functions in the path to - <c>g4</c>, i.e. <c>g1..g3..g4</c>. It will then call test cases <c>tc1</c> - and <c>tc5</c> in <c>g4</c> and finally all end configuration functions in order - <c>g4..g3..g1</c>.</p> + <p>The last group in the specified path is the terminating group in + the test, that is, no subgroups following this group are executed. In the + previous example, <c>g4</c> is the terminating group. Hence, <c>Common Test</c> + executes a test that calls all <c>init</c> configuration functions in the path to + <c>g4</c>, that is, <c>g1..g3..g4</c>. It then calls test cases <c>tc1</c> + and <c>tc5</c> in <c>g4</c>, and finally all <c>end</c> configuration functions + in order <c>g4..g3..g1</c>.</p> - <p>Note that the group path specification doesn't necessarily + <note><p>The group path specification does not necessarily have to include <em>all</em> groups in the path to the terminating group. - Common Test will search for all matching paths if given an incomplete group - path.</p> + <c>Common Test</c> searches for all matching paths if an incomplete + group path is specified.</p></note> - <p>Note also that it's possible to combine group names and group paths with the - <c>group_names_or_paths</c> parameter. Each element is treated as - an individual specification in combination with the <c>cases</c> parameter. - See examples below.</p> + <note><p>Group names and group paths can be combined with parameter + <c>group_names_or_paths</c>. Each element is treated as an individual specification + in combination with parameter <c>cases</c>. + The following examples illustrates this.</p></note> + + <p><em>Examples:</em></p> + <pre> + -module(x_SUITE). + ... + %% The group definitions: + groups() -> + [{top1,[],[tc11,tc12, + {sub11,[],[tc12,tc13]}, + {sub12,[],[tc14,tc15, + {sub121,[],[tc12,tc16]}]}]}, + + {top2,[],[{group,sub21},{group,sub22}]}, + {sub21,[],[tc21,{group,sub2X2}]}, + {sub22,[],[{group,sub221},tc21,tc22,{group,sub2X2}]}, + {sub221,[],[tc21,tc23]}, + {sub2X2,[],[tc21,tc24]}].</pre> + + <p>The following executes two tests, one for all cases and all subgroups + under <c>top1</c>, and one for all under <c>top2</c>:</p> + <pre> + $ ct_run -suite "x_SUITE" -group all + 1> ct:run_test([{suite,"x_SUITE"}, {group,all}]).</pre> + <p>Using <c>-group top1 top2</c>, or <c>{group,[top1,top2]}</c> gives the same result.</p> - <p>Examples:</p> + <p>The following executes one test for all cases and subgroups under <c>top1</c>:</p> <pre> - -module(x_SUITE). - ... - %% The group definitions: - groups() -> - [{top1,[],[tc11,tc12, - {sub11,[],[tc12,tc13]}, - {sub12,[],[tc14,tc15, - {sub121,[],[tc12,tc16]}]}]}, - - {top2,[],[{group,sub21},{group,sub22}]}, - {sub21,[],[tc21,{group,sub2X2}]}, - {sub22,[],[{group,sub221},tc21,tc22,{group,sub2X2}]}, - {sub221,[],[tc21,tc23]}, - {sub2X2,[],[tc21,tc24]}]. - </pre> - <br></br> - <p><c>$ ct_run -suite "x_SUITE" -group all</c></p> - <p><c>1> ct:run_test([{suite,"x_SUITE"}, {group,all}]).</c></p> - <p>Two tests will be executed, one for all cases and all sub groups under <c>top1</c>, - and one for all under <c>top2</c>. (We would get the same result with - <c>-group top1 top2</c>, or <c>{group,[top1,top2]}</c>.</p> - <br></br> - <p><c>$ ct_run -suite "x_SUITE" -group top1</c></p> - <p><c>1> ct:run_test([{suite,"x_SUITE"}, {group,[top1]}]).</c></p> - <p>This will execute one test for all cases and sub groups under <c>top1</c>.</p> - <br></br> - <p><c>$ ct_run -suite "x_SUITE" -group top1 -case tc12</c></p> - <p><c>1> ct:run_test([{suite,"x_SUITE"}, {group,[top1]}, {testcase,[tc12]}]).</c></p> - <p>This will run a test that executes <c>tc12</c> in <c>top1</c> and any sub group - under <c>top1</c> where it can be found (<c>sub11</c> and <c>sub121</c>).</p> - <br></br> - <p><c>$ ct_run -suite "x_SUITE" -group [top1] -case tc12</c></p> - <p><c>1> ct:run_test([{suite,"x_SUITE"}, {group,[[top1]]}, {testcase,[tc12]}]).</c></p> - <p>This will execute <c>tc12</c> <em>only</em> in group <c>top1</c>.</p> - <br></br> - <p><c>$ ct_run -suite "x_SUITE" -group top1 -case tc16</c></p> - <p><c>1> ct:run_test([{suite,"x_SUITE"}, {group,[top1]}, {testcase,[tc16]}]).</c></p> - <p>This will search <c>top1</c> and all its sub groups for <c>tc16</c> and the result - will be that this test case executes in group <c>sub121</c>. (The specific path: - <c>-group [sub121]</c> or <c>{group,[[sub121]]}</c>, would have given - us the same result in this example).</p> - <br></br> - <p><c>$ ct_run -suite "x_SUITE" -group sub12 [sub12]</c></p> - <p><c>1> ct:run_test([{suite,"x_SUITE"}, {group,[sub12,[sub12]]}]).</c></p> - <p>This will execute two tests, one that includes all cases and sub groups under - <c>sub12</c>, and one with <em>only</em> the test cases in <c>sub12</c>.</p> - <br></br> - <p><c>$ ct_run -suite "x_SUITE" -group sub2X2</c></p> - <p><c>1> ct:run_test([{suite,"x_SUITE"}, {group,[sub2X2]}]).</c></p> - <p>In this example, Common Test will find and execute two tests, one for the path from - <c>top2</c> to <c>sub2X2</c> via <c>sub21</c>, and one from <c>top2</c> to <c>sub2X2</c> - via <c>sub22</c>.</p> - <br></br> - <p><c>$ ct_run -suite "x_SUITE" -group [sub21,sub2X2]</c></p> - <p><c>1> ct:run_test([{suite,"x_SUITE"}, {group,[[sub21,sub2X2]]}]).</c></p> - <p>Here, by specifying the unique path: <c>top2 -> sub21 -> sub2X2</c>, only one test - is executed. The second possible path from <c>top2</c> to <c>sub2X2</c> (above) - will be discarded.</p> - <br></br> - <p><c>$ ct_run -suite "x_SUITE" -group [sub22] -case tc22 tc21</c></p> - <p><c>1> ct:run_test([{suite,"x_SUITE"}, {group,[[sub22]]}, {testcase,[tc22,tc21]}]).</c></p> - <p>In this example only the test cases for <c>sub22</c> will be executed, and in - reverse order compared to the group definition.</p> - <br></br> - - <p>If a test case that belongs to a group (according to the group definition), is executed - without a group specification, i.e. simply by means of (command line):</p> + $ ct_run -suite "x_SUITE" -group top1 + 1> ct:run_test([{suite,"x_SUITE"}, {group,[top1]}]).</pre> + + <p>The following runs a test executing <c>tc12</c> in <c>top1</c> and any subgroup + under <c>top1</c> where it can be found (<c>sub11</c> and <c>sub121</c>):</p> + <pre> + $ ct_run -suite "x_SUITE" -group top1 -case tc12 + 1> ct:run_test([{suite,"x_SUITE"}, {group,[top1]}, {testcase,[tc12]}]).</pre> + + <p>The following executes <c>tc12</c> <em>only</em> in group <c>top1</c>:</p> + <pre> + $ ct_run -suite "x_SUITE" -group [top1] -case tc12 + 1> ct:run_test([{suite,"x_SUITE"}, {group,[[top1]]}, {testcase,[tc12]}]).</pre> + + <p>The following searches <c>top1</c> and all its subgroups for <c>tc16</c> resulting + in that this test case executes in group <c>sub121</c>:</p> + <pre> + $ ct_run -suite "x_SUITE" -group top1 -case tc16 + 1> ct:run_test([{suite,"x_SUITE"}, {group,[top1]}, {testcase,[tc16]}]).</pre> + <p>Using the specific path <c>-group [sub121]</c> or <c>{group,[[sub121]]}</c> gives + the same result in this example.</p> + + <p>The following executes two tests, one including all cases and subgroups under + <c>sub12</c>, and one with <em>only</em> the test cases in <c>sub12</c>:</p> + <pre> + $ ct_run -suite "x_SUITE" -group sub12 [sub12] + 1> ct:run_test([{suite,"x_SUITE"}, {group,[sub12,[sub12]]}]).</pre> + + <p>In the following example, <c>Common Test</c> finds and executes two tests, + one for the path from <c>top2</c> to <c>sub2X2</c> through <c>sub21</c>, + and one from <c>top2</c> to <c>sub2X2</c> through <c>sub22</c>:</p> + <pre> + $ ct_run -suite "x_SUITE" -group sub2X2 + 1> ct:run_test([{suite,"x_SUITE"}, {group,[sub2X2]}]).</pre> + + <p>In the following example, by specifying the unique path <c>top2 -> sub21 -> sub2X2</c>, + only one test is executed. The second possible path, from <c>top2</c> to <c>sub2X2</c> + (from the former example) is discarded:</p> + <pre> + $ ct_run -suite "x_SUITE" -group [sub21,sub2X2] + 1> ct:run_test([{suite,"x_SUITE"}, {group,[[sub21,sub2X2]]}]).</pre> + + <p>The following executes only the test cases for <c>sub22</c> and in reverse order + compared to the group definition:</p> + <pre> + $ ct_run -suite "x_SUITE" -group [sub22] -case tc22 tc21 + 1> ct:run_test([{suite,"x_SUITE"}, {group,[[sub22]]}, {testcase,[tc22,tc21]}]).</pre> + + <p>If a test case belonging to a group (according to the group definition) is executed + without a group specification, that is, simply by + (using the command line):</p> <p><c>$ ct_run -suite "my_SUITE" -case my_tc</c></p> - <p>or (Erlang shell):</p> + <p>or (using the Erlang shell):</p> <p><c>1> ct:run_test([{suite,"my_SUITE"}, {testcase,my_tc}]).</c></p> - <p>then Common Test ignores the group definition and executes the test case in the scope of the - test suite only (no group configuration functions are called).</p> + <p>then <c>Common Test</c> ignores the group definition and executes the test case + in the scope of the test suite only (no group configuration functions are called).</p> - <p>The group specification feature, exactly as it has been presented in this section, can also + <p>The group specification feature, as presented in this section, can also be used in <seealso marker="run_test_chapter#test_specifications">Test - Specifications</seealso> (with some extra features added). Please see below.</p> + Specifications</seealso> (with some extra features added).</p> </section> <section> - <title>Running the interactive shell mode</title> + <title>Running the Interactive Shell Mode</title> - <p>You can start Common Test in an interactive shell mode where no - automatic testing is performed. Instead, in this mode, Common Test + <p>You can start <c>Common Test</c> in an interactive shell mode where no + automatic testing is performed. Instead, <c>Common Test</c> starts its utility processes, installs configuration data (if any), and waits for the user to call functions (typically test case support functions) from the Erlang shell.</p> - <p>The shell mode is useful e.g. for debugging test suites, for analysing + <p>The shell mode is useful, for example, for debugging test suites, analyzing and debugging the SUT during "simulated" test case execution, and - for trying out various operations during test suite development.</p> - - <p>To invoke the interactive shell mode, you can start an Erlang shell - manually and call <seealso marker="ct#install-1"><c>ct:install/1</c></seealso> to install any configuration - data you might need (use <c>[]</c> as argument otherwise), then - call <seealso marker="ct#start_interactive-0"><c>ct:start_interactive/0</c></seealso> to start Common Test. If you use - the <c>ct_run</c> program, you may start the Erlang shell and Common Test - in the same go by using the <c>-shell</c> and, optionally, the <c>-config</c> - and/or <c>-userconfig</c> flag. Examples: - </p> - <list> + trying out various operations during test suite development.</p> + + <p>To start the interactive shell mode, start an Erlang shell + manually and call <seealso marker="ct#install-1"><c>ct:install/1</c></seealso> + to install any configuration data you might need (use <c>[]</c> as argument otherwise). + Then call <seealso marker="ct#start_interactive-0"><c>ct:start_interactive/0</c></seealso> + to start <c>Common Test</c>.</p> + + <p>If you use the <c>ct_run</c> program, you can start + the Erlang shell and <c>Common Test</c> in one go by using the flag <c>-shell</c> and, + optionally, flag <c>-config</c> and/or <c>-userconfig</c>.</p> + <p><em>Examples:</em></p> + <list type="bulleted"> <item><c>ct_run -shell</c></item> <item><c><![CDATA[ct_run -shell -config cfg/db.cfg]]></c></item> <item><c><![CDATA[ct_run -shell -userconfig db_login testuser x523qZ]]></c></item> </list> - <p>If no config file is given with the <c>ct_run</c> command, - a warning will be displayed. If Common Test has been run from the same - directory earlier, the same config file(s) will be used - again. If Common Test has not been run from this directory before, no - config files will be available.</p> + <p>If no configuration file is specified with command <c>ct_run</c>, + a warning is displayed. If <c>Common Test</c> has been run from the same + directory earlier, the same configuration file(s) are used again. If <c>Common Test</c> + has not been run from this directory before, no configuration files are available.</p> - <p>If any functions using "required config data" (e.g. ct_telnet or - ct_ftp functions) are to be called from the erlang shell, config - data must first be required with <seealso marker="ct#require-1"><c> - ct:require/1/2</c></seealso>. This is - equivalent to a <c>require</c> statement in the <seealso - marker="write_test_chapter#suite">Test Suite Info - Function</seealso> or in the <seealso - marker="write_test_chapter#info_function">Test Case Info - Function</seealso>.</p> - - <p>Example:</p> + <p>If any functions using "required configuration data" (for example, functions + <c>ct_telnet</c> or <c>ct_ftp</c>) are to be called from the Erlang shell, first require + configuration data with <seealso marker="ct#require-1"><c> + ct:require/1,2</c></seealso>. This is equivalent to a <c>require</c> statement + in the <seealso marker="write_test_chapter#suite">Test Suite Information Function</seealso> + or in the <seealso marker="write_test_chapter#info_function">Test Case Information Function</seealso>.</p> + + <p><em>Example:</em></p> <pre> - 1> ct:require(unix_telnet, unix). - ok - 2> ct_telnet:open(unix_telnet). - {ok,<0.105.0>} - 4> ct_telnet:cmd(unix_telnet, "ls ."). - {ok,["ls .","file1 ...",...]} - </pre> + 1> ct:require(unix_telnet, unix). + ok + 2> ct_telnet:open(unix_telnet). + {ok,<0.105.0>} + 4> ct_telnet:cmd(unix_telnet, "ls ."). + {ok,["ls .","file1 ...",...]}</pre> - <p>Everything that Common Test normally prints in the test case logs, - will in the interactive mode be written to a log named - <c>ctlog.html</c> in the <c><![CDATA[ct_run.<timestamp>]]></c> - directory. A link to this file will be available in the file - named <c>last_interactive.html</c> in the directory from which - you executed <c>ct_run</c>. Currently, specifying a different - root directory for the logs than the current working directory, + <p>Everything that <c>Common Test</c> normally prints in the test case logs, + are in the interactive mode written to a log named <c>ctlog.html</c> + in directory <c><![CDATA[ct_run.<timestamp>]]></c>. A link to this + file is available in the file named <c>last_interactive.html</c> in the + directory from which you execute <c>ct_run</c>. Specifying a different + root directory for the logs than the current working directory is not supported.</p> - <p>If you wish to exit the interactive mode (e.g. to start an - automated test run with <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>), call the function - <seealso marker="ct#stop_interactive-0"><c>ct:stop_interactive/0</c></seealso>. This shuts down the - running <c>ct</c> application. Associations between + <p>If you wish to exit the interactive mode (for example, to start an automated + test run with <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>), + call function + <seealso marker="ct#stop_interactive-0"><c>ct:stop_interactive/0</c></seealso>. + This shuts down the running <c>ct</c> application. Associations between configuration names and data created with <c>require</c> are - consequently deleted. <seealso marker="ct#start_interactive-0"><c>ct:start_interactive/0</c></seealso> will get you - back into interactive mode, but the previous state is not restored.</p> + consequently deleted. Function + <seealso marker="ct#start_interactive-0"><c>ct:start_interactive/0</c></seealso> + takes you back into interactive mode, but the previous state is not restored.</p> </section> <section> - <title>Step by step execution of test cases with the Erlang Debugger</title> + <title>Step-by-Step Execution of Test Cases with the Erlang Debugger</title> - <p>By means of <c>ct_run -step [opts]</c>, or by passing the - <c>{step,Opts}</c> option to <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>, it is possible - to get the Erlang Debugger started automatically and use its - graphical interface to investigate the state of the current test - case and to execute it step by step and/or set execution breakpoints.</p> - <p>If no extra options are given with the <c>step</c> flag/option, - breakpoints will be set automatically on the test cases that - are to be executed by Common Test, and those functions only. If - the step option <c>config</c> is specified, breakpoints will - also be initially set on the configuration functions in the suite, i.e. + <p>Using <c>ct_run -step [opts]</c>, or by passing option <c>{step,Opts}</c> + to <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>, + the following is possible:</p> + <list type="bulleted"> + <item>Get the Erlang Debugger started automatically.</item> + <item>Use its graphical interface to investigate the state of the current test case.</item> + <item>Execute the test case step-by-step and/or set execution breakpoints.</item> + </list> + <p>If no extra options are specified with flag/option <c>step</c>, + breakpoints are set automatically on the test cases that + are to be executed by <c>Common Test</c>, and those functions only. If + step option <c>config</c> is specified, breakpoints are also initially + set on the configuration functions in the suite, that is, <c>init_per_suite/1</c>, <c>end_per_suite/1</c>, <c>init_per_group/2</c>, <c>end_per_group/2</c>, <c>init_per_testcase/2</c> and <c>end_per_testcase/2</c>.</p> - <p>Common Test enables the Debugger auto attach feature, which means + <p><c>Common Test</c> enables the Debugger auto-attach feature, which means that for every new interpreted test case function that starts to execute, - a new trace window will automatically pop up. (This is because each test + a new trace window automatically pops up (as each test case executes on a dedicated Erlang process). Whenever a new test case starts, - Common Test will attempt to close the inactive trace window of the previous - test case. However, if you prefer that Common Test leaves inactive trace - windows, use the <c>keep_inactive</c> option.</p> - <p>The step functionality can be used together with the <c>suite</c> and - the <c>suite</c> + <c>case/testcase</c> flag/option, but not together - with <c>dir</c>.</p> + <c>Common Test</c> attempts to close the inactive trace window of the previous + test case. However, if you prefer <c>Common Test</c> to leave inactive trace + windows, use option <c>keep_inactive</c>.</p> + <p>The step functionality can be used together with flag/option <c>suite</c> and + <c>suite</c> + <c>case/testcase</c>, but not together with <c>dir</c>.</p> </section> <section> <marker id="test_specifications"></marker> <title>Test Specifications</title> <section> - <title>General description</title> - <p>The most flexible way to specify what to test, is to use a so - called test specification. A test specification is a sequence of + <title>General Description</title> + <p>The most flexible way to specify what to test, is to use a + test specification, which is a sequence of Erlang terms. The terms are normally declared in one or more text files (see <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso>), but - may also be passed to Common Test on the form of a list (see + can also be passed to <c>Common Test</c> on the form of a list (see <seealso marker="ct#run_testspec-1"><c>ct:run_testspec/1</c></seealso>). There are two general types of terms: configuration terms and test specification terms.</p> - <p>With configuration terms it is possible to e.g. label the test - run (similar to <c>ct_run -label</c>), evaluate arbitrary expressions - before starting the test, import configuration data (similar to - <c>ct_run -config/-userconfig</c>), specify the top level HTML log - directory (similar to <c>ct_run -logdir</c>), enable code coverage - analysis (similar to <c>ct_run -cover</c>), install Common Test Hooks - (similar to <c>ct_run -ch_hooks</c>), install event_handler plugins - (similar to <c>ct_run -event_handler</c>), specify include directories - that should be passed to the compiler for automatic compilation - (similar to <c>ct_run -include</c>), disable the auto compilation - feature (similar to <c>ct_run -no_auto_compile</c>), set verbosity - levels (similar to <c>ct_run -verbosity</c>), and more.</p> - <p>Configuration terms can be combined with <c>ct_run</c> start flags, - or <c>ct:run_test/1</c> options. The result will for some flags/options - and terms be that the values are merged (e.g. configuration files, - include directories, verbosity levels, silent connections), and for + + <p>With configuration terms it is, for example, possible to do the following:</p> + <list type="bulleted"> + <item>Label the test run (similar to <c>ct_run -label</c>).</item> + <item>Evaluate any expressions before starting the test.</item> + <item>Import configuration data (similar to <c>ct_run -config/-userconfig</c>).</item> + <item>Specify the top-level HTML log directory (similar to <c>ct_run -logdir</c>).</item> + <item>Enable code coverage analysis (similar to <c>ct_run -cover</c>).</item> + <item>Install <c>Common Test Hooks</c> (similar to <c>ct_run -ch_hooks</c>).</item> + <item>Install <c>event_handler</c> plugins (similar to <c>ct_run -event_handler</c>).</item> + <item>Specify include directories to be passed to the compiler for + automatic compilation (similar to <c>ct_run -include</c>).</item> + <item>Disable the auto-compilation feature (similar to <c>ct_run -no_auto_compile</c>).</item> + <item>Set verbosity levels (similar to <c>ct_run -verbosity</c>).</item> + </list> + + <p>Configuration terms can be combined with <c>ct_run</c> start flags + or <c>ct:run_test/1</c> options. The result is, for some flags/options + and terms, that the values are merged (for example, configuration files, + include directories, verbosity levels, and silent connections) and for others that the start flags/options override the test specification - terms (e.g. log directory, label, style sheet, auto compilation).</p> - <p>With test specification terms it is possible to state exactly - which tests should run and in which order. A test term specifies + terms (for example, log directory, label, style sheet, and auto-compilation).</p> + + <p>With test specification terms, it is possible to state exactly + which tests to run and in which order. A test term specifies either one or more suites, one or more test case groups (possibly nested), or one or more test cases in a group (or in multiple groups) or in a suite.</p> - <p>An arbitrary number of test terms may be declared in sequence. - Common Test will by default compile the terms into one or more tests - to be performed in one resulting test run. Note that a term that - specifies a set of test cases will "swallow" one that only - specifies a subset of these cases. E.g. the result of merging - one term that specifies that all cases in suite S should be + + <p>Any number of test terms can be declared in sequence. + <c>Common Test</c> compiles by default the terms into one or more tests + to be performed in one resulting test run. A term that + specifies a set of test cases "swallows" one that only + specifies a subset of these cases. For example, the result of merging + one term specifying that all cases in suite S are to be executed, with another term specifying only test case X and Y in S, is a test of all cases in S. However, if a term specifying test case X and Y in S is merged with a term specifying case Z - in S, the result is a test of X, Y and Z in S. To disable this - behaviour, i.e. to instead perform each test sequentially in a "script-like" - manner, the term <c>merge_tests</c> can be set to <c>false</c> in - the test specification.</p> + in S, the result is a test of X, Y, and Z in S. To disable this + behavior, that is, to instead perform each test sequentially in a + "script-like" manner, set term <c>merge_tests</c> to <c>false</c> + in the test specification.</p> + <p>A test term can also specify one or more test suites, groups, - or test cases to be skipped. Skipped suites, groups and cases - are not executed and show up in the HTML log files as - SKIPPED.</p> + or test cases to be skipped. Skipped suites, groups, and cases + are not executed and show up in the HTML log files as <c>SKIPPED</c>.</p> </section> <section> - <title>Using multiple test specification files</title> + <title>Using Multiple Test Specification Files</title> - <p>When multiple test specification files are given at startup (either + <p>When multiple test specification files are specified at startup (either with <c>ct_run -spec file1 file2 ...</c> or <c>ct:run_test([{spec, [File1,File2,...]}])</c>), - Common Test will either execute one test run per specification file, or - join the files and perform all tests within one single test run. The first - behaviour is the default one. The latter requires that the start - flag/option <c>join_specs</c> is provided, e.g. + <c>Common Test</c> either executes one test run per specification file, + or joins the files and performs all tests within one single test run. + The first behavior is the default one. The latter requires that start + flag/option <c>join_specs</c> is provided, for example, <c>run_test -spec ./my_tests1.ts ./my_tests2.ts -join_specs</c>.</p> <p>Joining a number of specifications, or running them separately, can - also be accomplished with (and may be combined with) test specification - file inclusion, described next.</p> + also be accomplished with (and can be combined with) test specification + file inclusion.</p> </section> <section> - <title>Test specification file inclusion</title> - <p>With the <c>specs</c> term (see syntax below), it's possible to have - a test specification include other specifications. An included - specification may either be joined with the source specification, - or used to produce a separate test run (like with the <c>join_specs</c> - start flag/option above). Example:</p> + <title>Test Specification File Inclusion</title> + <p>With the term <c>specs</c>, a test specification can include + other specifications. An included specification can either be joined + with the source specification or used to produce a separate test run + (as with start flag/option <c>join_specs</c> above).</p> + <p><em>Example:</em></p> + <pre> - %% In specification file "a.spec" - {specs, join, ["b.spec", "c.spec"]}. - {specs, separate, ["d.spec", "e.spec"]}. - %% Config and test terms follow - ...</pre> + %% In specification file "a.spec" + {specs, join, ["b.spec", "c.spec"]}. + {specs, separate, ["d.spec", "e.spec"]}. + %% Config and test terms follow + ...</pre> + <p>In this example, the test terms defined in files "b.spec" and "c.spec" - will be joined with the terms in the source specification "a.spec" + are joined with the terms in source specification "a.spec" (if any). The inclusion of specifications "d.spec" and - "e.spec" will result in two separate, and independent, test runs (i.e. - one for each included specification).</p> - <p>Note that the <c>join</c> option does not imply that the test terms - will be merged (see <c>merge_tests</c> above), only that all tests are - executed in one single test run.</p> + "e.spec" results in two separate, and independent, test runs + (one for each included specification).</p> + + <p>Option <c>join</c> does not imply that the test terms + are merged, only that all tests are executed in one single test run.</p> + <p>Joined specifications share common configuration settings, such as the list of <c>config</c> files or <c>include</c> directories. - For configuration that can not be combined, such as settings for <c>logdir</c> + For configurations that cannot be combined, such as settings for <c>logdir</c> or <c>verbosity</c>, it is up to the user to ensure there are no clashes when the test specifications are joined. Specifications included with - the <c>separate</c> option, do not share configuration settings with the - source specification. This is useful e.g. if there are clashing - configuration settings in included specifications, making it impossible - to join them.</p> + option <c>separate</c> do not share configuration settings with the + source specification. This is useful, for example, if there are clashing + configuration settings in included specifications, making it them impossible + to join.</p> + <p>If <c>{merge_tests,true}</c> is set in the source specification - (which is the default setting), terms in joined specifications will be + (which is the default setting), terms in joined specifications are merged with terms in the source specification (according to the - description of <c>merge_tests</c> above).</p> - <p>Note that it is always the <c>merge_tests</c> setting in the source + description of <c>merge_tests</c> earlier).</p> + + <p>Notice that it is always the <c>merge_tests</c> setting in the source specification that is used when joined with other specifications. - Say e.g. that a source specification A, with tests TA1 and TA2, has - <c>{merge_tests,false}</c> set, and it includes another specification, + Say, for example, that a source specification A, with tests TA1 and TA2, has + <c>{merge_tests,false}</c> set, and that it includes another specification, B, with tests TB1 and TB2, that has <c>{merge_tests,true}</c> set. - The result will be that the test series: <c>TA1,TA2,merge(TB1,TB2)</c>, - is executed. The opposite <c>merge_tests</c> settings would result in the - following the test series: <c>merge(merge(TA1,TA2),TB1,TB2)</c>.</p> - <p>The <c>specs</c> term may of course be used to nest specifications, - i.e. have one specification include other specifications, which in turn - include others, etc.</p> + The result is that the test series <c>TA1,TA2,merge(TB1,TB2)</c> + is executed. The opposite <c>merge_tests</c> settings would result in + the test series <c>merge(merge(TA1,TA2),TB1,TB2)</c>.</p> + + <p>The term <c>specs</c> can be used to nest specifications, + that is, have one specification include other specifications, which in turn + include others, and so no</p> </section> <section> - <title>Test case groups</title> + <title>Test Case Groups</title> <p>When a test case group is specified, the resulting test - executes the <c>init_per_group</c> function, followed by all test - cases and sub groups (including their configuration functions), and - finally the <c>end_per_group</c> function. Also if particular + executes function <c>init_per_group</c>, followed by all test + cases and subgroups (including their configuration functions), and + finally function <c>end_per_group</c>. Also, if particular test cases in a group are specified, <c>init_per_group</c> - and <c>end_per_group</c> for the group in question are - called. If a group which is defined (in <c>Suite:group/0</c>) to - be a sub group of another group, is specified (or if particular test - cases of a sub group are), Common Test will call the configuration - functions for the top level groups as well as for the sub group + and <c>end_per_group</c>, for the group in question, are + called. If a group defined (in <c>Suite:group/0</c>) as + a subgroup of another group, is specified (or if particular test + cases of a subgroup are), <c>Common Test</c> calls the configuration + functions for the top-level groups and for the subgroup in question (making it possible to pass configuration data all the way from <c>init_per_suite</c> down to the test cases in the - sub group).</p> - <p>The test specification utilizes the same mechanism for specifying - test case groups by means of names and paths, as explained in the - <seealso marker="run_test_chapter#group_execution">Group Execution</seealso> - section above, with the addition of the <c>GroupSpec</c> element - described next.</p> - <p>The <c>GroupSpec</c> element makes it possible to specify - group execution properties that will override those in the - group definition (i.e. in <c>groups/0</c>). Execution properties for - sub-groups may be overridden as well. This feature makes it possible to + subgroup).</p> + + <p>The test specification uses the same mechanism for specifying + test case groups through names and paths, as explained in section + <seealso marker="run_test_chapter#group_execution">Test Case Group Execution</seealso>, + with the addition of element <c>GroupSpec</c>.</p> + + <p>Element <c>GroupSpec</c> makes it possible to specify + group execution properties that overrides those in the + group definition (that is, in <c>groups/0</c>). Execution properties for + subgroups might be overridden as well. This feature makes it possible to change properties of groups at the time of execution, - without even having to edit the test suite. The very same - feature is available for <c>group</c> elements in the <c>Suite:all/0</c> - list. Therefore, more detailed documentation, and examples, can be - found in the <seealso marker="write_test_chapter#test_case_groups"> - Test case groups</seealso> chapter.</p> + without having to edit the test suite. The same feature is available for + <c>group</c> elements in the <c>Suite:all/0</c> list. For details and examples, + see section <seealso marker="write_test_chapter#test_case_groups"> + Test Case Groups</seealso>.</p> </section> <section> - <title>Test specification syntax</title> - - <p>Below is the test specification syntax. Test specifications can - be used to run tests both in a single test host environment and - in a distributed Common Test environment (Large Scale - Testing). The node parameters in the <c>init</c> term are only - relevant in the latter (see the - <seealso marker="ct_master_chapter#test_specifications">Large - Scale Testing</seealso> chapter for information). For more information - about the various terms, please see the corresponding sections in the - User's Guide, such as e.g. the - <seealso marker="run_test_chapter#ct_run"><c>ct_run</c> + <title>Test Specification Syntax</title> + + <p>Test specifications can be used to run tests both in a single + test host environment and in a distributed <c>Common Test</c> environment + (Large Scale Testing). The node parameters in term <c>init</c> are only + relevant in the latter (see section + <seealso marker="ct_master_chapter#test_specifications">Test Specifications</seealso> + in Large Scale Testing). For details about the various terms, see the + corresponding sections in the User's Guide, for example, the following: + </p> + <list type="bulleted"> + <item>The <seealso marker="run_test_chapter#ct_run"><c>ct_run</c> program</seealso> for an overview of available start flags - (since most flags have a corresponding configuration term), and - more detailed explanation of e.g. - <seealso marker="write_test_chapter#logging">Logging</seealso> - (for the <c>verbosity</c>, <c>stylesheet</c> and <c>basic_html</c> terms), - <seealso marker="config_file_chapter#top">External Configuration Data</seealso> - (for the <c>config</c> and <c>userconfig</c> terms), - <seealso marker="event_handler_chapter#event_handling">Event - Handling</seealso> (for the <c>event_handler</c> term), - <seealso marker="ct_hooks_chapter#installing">Common Test Hooks</seealso> - (for the <c>ct_hooks</c> term), etc.</p> - </section> - - <p>Config terms:</p> + (as most flags have a corresponding configuration term)</item> + <item><seealso marker="write_test_chapter#logging">Logging</seealso> + (for terms <c>verbosity</c>, <c>stylesheet</c> and <c>basic_html</c>)</item> + <item><seealso marker="config_file_chapter#top">External Configuration Data</seealso> + (for terms <c>config</c> and <c>userconfig</c>)</item> + <item><seealso marker="event_handler_chapter#event_handling">Event + Handling</seealso> (for the <c>event_handler</c> term)</item> + <item><seealso marker="ct_hooks_chapter#installing">Common Test Hooks</seealso> + (for term <c>ct_hooks</c>)</item> + </list> + + <p><em>Configuration terms:</em></p> <pre> - {merge_tests, Bool}. - - {define, Constant, Value}. - - {specs, InclSpecsOption, TestSpecs}. - - {node, NodeAlias, Node}. - - {init, InitOptions}. - {init, [NodeAlias], InitOptions}. - - {label, Label}. - {label, NodeRefs, Label}. - - {verbosity, VerbosityLevels}. - {verbosity, NodeRefs, VerbosityLevels}. - - {stylesheet, CSSFile}. - {stylesheet, NodeRefs, CSSFile}. - - {silent_connections, ConnTypes}. - {silent_connections, NodeRefs, ConnTypes}. - - {multiply_timetraps, N}. - {multiply_timetraps, NodeRefs, N}. - - {scale_timetraps, Bool}. - {scale_timetraps, NodeRefs, Bool}. - - {cover, CoverSpecFile}. - {cover, NodeRefs, CoverSpecFile}. - - {cover_stop, Bool}. - {cover_stop, NodeRefs, Bool}. - - {include, IncludeDirs}. - {include, NodeRefs, IncludeDirs}. - - {auto_compile, Bool}, - {auto_compile, NodeRefs, Bool}, - - {abort_if_missing_suites, Bool}, - {abort_if_missing_suites, NodeRefs, Bool}, + {merge_tests, Bool}. - {config, ConfigFiles}. - {config, ConfigDir, ConfigBaseNames}. - {config, NodeRefs, ConfigFiles}. - {config, NodeRefs, ConfigDir, ConfigBaseNames}. - - {userconfig, {CallbackModule, ConfigStrings}}. - {userconfig, NodeRefs, {CallbackModule, ConfigStrings}}. - - {logdir, LogDir}. - {logdir, NodeRefs, LogDir}. - - {logopts, LogOpts}. - {logopts, NodeRefs, LogOpts}. - - {create_priv_dir, PrivDirOption}. - {create_priv_dir, NodeRefs, PrivDirOption}. - - {event_handler, EventHandlers}. - {event_handler, NodeRefs, EventHandlers}. - {event_handler, EventHandlers, InitArgs}. - {event_handler, NodeRefs, EventHandlers, InitArgs}. - - {ct_hooks, CTHModules}. - {ct_hooks, NodeRefs, CTHModules}. - - {enable_builtin_hooks, Bool}. - - {basic_html, Bool}. - {basic_html, NodeRefs, Bool}. - - {release_shell, Bool}.</pre> + {define, Constant, Value}. + + {specs, InclSpecsOption, TestSpecs}. + + {node, NodeAlias, Node}. + + {init, InitOptions}. + {init, [NodeAlias], InitOptions}. + + {label, Label}. + {label, NodeRefs, Label}. + + {verbosity, VerbosityLevels}. + {verbosity, NodeRefs, VerbosityLevels}. + + {stylesheet, CSSFile}. + {stylesheet, NodeRefs, CSSFile}. + + {silent_connections, ConnTypes}. + {silent_connections, NodeRefs, ConnTypes}. + + {multiply_timetraps, N}. + {multiply_timetraps, NodeRefs, N}. + + {scale_timetraps, Bool}. + {scale_timetraps, NodeRefs, Bool}. + + {cover, CoverSpecFile}. + {cover, NodeRefs, CoverSpecFile}. + + {cover_stop, Bool}. + {cover_stop, NodeRefs, Bool}. + + {include, IncludeDirs}. + {include, NodeRefs, IncludeDirs}. + + {auto_compile, Bool}, + {auto_compile, NodeRefs, Bool}, + + {abort_if_missing_suites, Bool}, + {abort_if_missing_suites, NodeRefs, Bool}, + + {config, ConfigFiles}. + {config, ConfigDir, ConfigBaseNames}. + {config, NodeRefs, ConfigFiles}. + {config, NodeRefs, ConfigDir, ConfigBaseNames}. + + {userconfig, {CallbackModule, ConfigStrings}}. + {userconfig, NodeRefs, {CallbackModule, ConfigStrings}}. + + {logdir, LogDir}. + {logdir, NodeRefs, LogDir}. + + {logopts, LogOpts}. + {logopts, NodeRefs, LogOpts}. + + {create_priv_dir, PrivDirOption}. + {create_priv_dir, NodeRefs, PrivDirOption}. + + {event_handler, EventHandlers}. + {event_handler, NodeRefs, EventHandlers}. + {event_handler, EventHandlers, InitArgs}. + {event_handler, NodeRefs, EventHandlers, InitArgs}. + + {ct_hooks, CTHModules}. + {ct_hooks, NodeRefs, CTHModules}. + + {enable_builtin_hooks, Bool}. + + {basic_html, Bool}. + {basic_html, NodeRefs, Bool}. + + {release_shell, Bool}.</pre> - <p>Test terms:</p> + <p><em>Test terms:</em></p> <pre> - {suites, Dir, Suites}. - {suites, NodeRefs, Dir, Suites}. - - {groups, Dir, Suite, Groups}. - {groups, NodeRefs, Dir, Suite, Groups}. - - {groups, Dir, Suite, Groups, {cases,Cases}}. - {groups, NodeRefs, Dir, Suite, Groups, {cases,Cases}}. - - {cases, Dir, Suite, Cases}. - {cases, NodeRefs, Dir, Suite, Cases}. - - {skip_suites, Dir, Suites, Comment}. - {skip_suites, NodeRefs, Dir, Suites, Comment}. - - {skip_groups, Dir, Suite, GroupNames, Comment}. - {skip_groups, NodeRefs, Dir, Suite, GroupNames, Comment}. - - {skip_cases, Dir, Suite, Cases, Comment}. - {skip_cases, NodeRefs, Dir, Suite, Cases, Comment}.</pre> - - <p>Types:</p> + {suites, Dir, Suites}. + {suites, NodeRefs, Dir, Suites}. + + {groups, Dir, Suite, Groups}. + {groups, NodeRefs, Dir, Suite, Groups}. + + {groups, Dir, Suite, Groups, {cases,Cases}}. + {groups, NodeRefs, Dir, Suite, Groups, {cases,Cases}}. + + {cases, Dir, Suite, Cases}. + {cases, NodeRefs, Dir, Suite, Cases}. + + {skip_suites, Dir, Suites, Comment}. + {skip_suites, NodeRefs, Dir, Suites, Comment}. + + {skip_groups, Dir, Suite, GroupNames, Comment}. + {skip_groups, NodeRefs, Dir, Suite, GroupNames, Comment}. + + {skip_cases, Dir, Suite, Cases, Comment}. + {skip_cases, NodeRefs, Dir, Suite, Cases, Comment}.</pre> + + <marker id="types"></marker> + <p><em>Types:</em></p> <pre> - Bool = true | false - Constant = atom() - Value = term() - InclSpecsOption = join | separate - TestSpecs = string() | [string()] - NodeAlias = atom() - Node = node() - NodeRef = NodeAlias | Node | master - NodeRefs = all_nodes | [NodeRef] | NodeRef - InitOptions = term() - Label = atom() | string() - VerbosityLevels = integer() | [{Category,integer()}] - Category = atom() - CSSFile = string() - ConnTypes = all | [atom()] - N = integer() - CoverSpecFile = string() - IncludeDirs = string() | [string()] - ConfigFiles = string() | [string()] - ConfigDir = string() - ConfigBaseNames = string() | [string()] - CallbackModule = atom() - ConfigStrings = string() | [string()] - LogDir = string() - LogOpts = [term()] - PrivDirOption = auto_per_run | auto_per_tc | manual_per_tc - EventHandlers = atom() | [atom()] - InitArgs = [term()] - CTHModules = [CTHModule | - {CTHModule, CTHInitArgs} | - {CTHModule, CTHInitArgs, CTHPriority}] - CTHModule = atom() - CTHInitArgs = term() - Dir = string() - Suites = atom() | [atom()] | all - Suite = atom() - Groups = GroupPath | [GroupPath] | GroupSpec | [GroupSpec] | all - GroupPath = [GroupName] - GroupSpec = GroupName | {GroupName,Properties} | {GroupName,Properties,GroupSpec} - GroupName = atom() - GroupNames = GroupName | [GroupName] - Cases = atom() | [atom()] | all - Comment = string() | ""</pre> - - <section> - <p>The difference between the <c>config</c> terms above, is that with + Bool = true | false + Constant = atom() + Value = term() + InclSpecsOption = join | separate + TestSpecs = string() | [string()] + NodeAlias = atom() + Node = node() + NodeRef = NodeAlias | Node | master + NodeRefs = all_nodes | [NodeRef] | NodeRef + InitOptions = term() + Label = atom() | string() + VerbosityLevels = integer() | [{Category,integer()}] + Category = atom() + CSSFile = string() + ConnTypes = all | [atom()] + N = integer() + CoverSpecFile = string() + IncludeDirs = string() | [string()] + ConfigFiles = string() | [string()] + ConfigDir = string() + ConfigBaseNames = string() | [string()] + CallbackModule = atom() + ConfigStrings = string() | [string()] + LogDir = string() + LogOpts = [term()] + PrivDirOption = auto_per_run | auto_per_tc | manual_per_tc + EventHandlers = atom() | [atom()] + InitArgs = [term()] + CTHModules = [CTHModule | + {CTHModule, CTHInitArgs} | + {CTHModule, CTHInitArgs, CTHPriority}] + CTHModule = atom() + CTHInitArgs = term() + Dir = string() + Suites = atom() | [atom()] | all + Suite = atom() + Groups = GroupPath | [GroupPath] | GroupSpec | [GroupSpec] | all + GroupPath = [GroupName] + GroupSpec = GroupName | {GroupName,Properties} | {GroupName,Properties,GroupSpec} + GroupName = atom() + GroupNames = GroupName | [GroupName] + Cases = atom() | [atom()] | all + Comment = string() | ""</pre> + + <p>The difference between the <c>config</c> terms above is that with <c>ConfigDir</c>, <c>ConfigBaseNames</c> is a list of base names, - i.e. without directory paths. <c>ConfigFiles</c> must be full names, - including paths. E.g, these two terms have the same meaning:</p> + that is, without directory paths. <c>ConfigFiles</c> must be full names, + including paths. For example, the following two terms have the same meaning:</p> <pre> - {config, ["/home/testuser/tests/config/nodeA.cfg", - "/home/testuser/tests/config/nodeB.cfg"]}. - - {config, "/home/testuser/tests/config", ["nodeA.cfg","nodeB.cfg"]}.</pre> + {config, ["/home/testuser/tests/config/nodeA.cfg", + "/home/testuser/tests/config/nodeB.cfg"]}. + + {config, "/home/testuser/tests/config", ["nodeA.cfg","nodeB.cfg"]}.</pre> - <note><p>Any relative paths specified in the test specification, will be - relative to the directory which contains the test specification file, if + <note><p>Any relative paths, specified in the test specification, are + relative to the directory containing the test specification file if <c>ct_run -spec TestSpecFile ...</c> or <c>ct:run:test([{spec,TestSpecFile},...])</c> - executes the test. The path will be relative to the top level log directory, if + executes the test.</p> + <p>The path is relative to the top-level log directory if <c>ct:run:testspec(TestSpec)</c> executes the test.</p></note> </section> <section> <title>Constants</title> - <p>The <c>define</c> term introduces a constant, which is used to - replace the name <c>Constant</c> with <c>Value</c>, wherever it's found in - the test specification. This replacement happens during an initial iteration - through the test specification. Constants may be used anywhere in the test - specification, e.g. in arbitrary lists and tuples, and even in strings - and inside the value part of other constant definitions! A constant can + <p>The term <c>define</c> introduces a constant that is used to + replace the name <c>Constant</c> with <c>Value</c>, wherever it is found in + the test specification. This replacement occurs during an initial iteration + through the test specification. Constants can be used anywhere in the test + specification, for example, in any lists and tuples, and even in strings + and inside the value part of other constant definitions. A constant can also be part of a node name, but that is the only place where a constant can be part of an atom.</p> <note><p>For the sake of readability, the name of the constant must always - begin with an upper case letter, or a <c>$</c>, <c>?</c>, or <c>_</c>. - This also means that it must always be single quoted (obviously, since - the constant name is actually an atom, not text).</p></note> + begin with an uppercase letter, or a <c>$</c>, <c>?</c>, or <c>_</c>. + This means that it must always be single quoted (as the constant name is + an atom, not text).</p></note> <p>The main benefit of constants is that they can be used to reduce the size - (and avoid repetition) of long strings, such as file paths. Compare these - terms:</p> + (and avoid repetition) of long strings, such as file paths.</p> + <p><em>Examples:</em></p> <pre> - %% 1a. no constant - {config, "/home/testuser/tests/config", ["nodeA.cfg","nodeB.cfg"]}. - {suites, "/home/testuser/tests/suites", all}. - - %% 1b. with constant - {define, 'TESTDIR', "/home/testuser/tests"}. - {config, "'TESTDIR'/config", ["nodeA.cfg","nodeB.cfg"]}. - {suites, "'TESTDIR'/suites", all}. - - %% 2a. no constants - {config, [testnode@host1, testnode@host2], "../config", ["nodeA.cfg","nodeB.cfg"]}. - {suites, [testnode@host1, testnode@host2], "../suites", [x_SUITE, y_SUITE]}. - - %% 2b. with constants - {define, 'NODE', testnode}. - {define, 'NODES', ['NODE'@host1, 'NODE'@host2]}. - {config, 'NODES', "../config", ["nodeA.cfg","nodeB.cfg"]}. - {suites, 'NODES', "../suites", [x_SUITE, y_SUITE]}.</pre> + %% 1a. no constant + {config, "/home/testuser/tests/config", ["nodeA.cfg","nodeB.cfg"]}. + {suites, "/home/testuser/tests/suites", all}. + + %% 1b. with constant + {define, 'TESTDIR', "/home/testuser/tests"}. + {config, "'TESTDIR'/config", ["nodeA.cfg","nodeB.cfg"]}. + {suites, "'TESTDIR'/suites", all}. + + %% 2a. no constants + {config, [testnode@host1, testnode@host2], "../config", ["nodeA.cfg","nodeB.cfg"]}. + {suites, [testnode@host1, testnode@host2], "../suites", [x_SUITE, y_SUITE]}. + + %% 2b. with constants + {define, 'NODE', testnode}. + {define, 'NODES', ['NODE'@host1, 'NODE'@host2]}. + {config, 'NODES', "../config", ["nodeA.cfg","nodeB.cfg"]}. + {suites, 'NODES', "../suites", [x_SUITE, y_SUITE]}.</pre> <p>Constants make the test specification term <c>alias</c>, in previous - versions of Common Test, redundant. This term has been deprecated but will - remain supported in upcoming Common Test releases. Replacing <c>alias</c> - terms with <c>define</c> is strongly recommended though! Here's an example - of such a replacement:</p> + versions of <c>Common Test</c>, redundant. This term is deprecated but + remains supported in upcoming <c>Common Test</c> releases. Replacing <c>alias</c> + terms with <c>define</c> is strongly recommended though. An example + of such replacement follows:</p> <pre> - %% using the old alias term - {config, "/home/testuser/tests/config/nodeA.cfg"}. - {alias, suite_dir, "/home/testuser/tests/suites"}. - {groups, suite_dir, x_SUITE, group1}. - - %% replacing with constants - {define, 'TestDir', "/home/testuser/tests"}. - {define, 'CfgDir', "'TestDir'/config"}. - {define, 'SuiteDir', "'TestDir'/suites"}. - {config, 'CfgDir', "nodeA.cfg"}. - {groups, 'SuiteDir', x_SUITE, group1}.</pre> + %% using the old alias term + {config, "/home/testuser/tests/config/nodeA.cfg"}. + {alias, suite_dir, "/home/testuser/tests/suites"}. + {groups, suite_dir, x_SUITE, group1}. + + %% replacing with constants + {define, 'TestDir', "/home/testuser/tests"}. + {define, 'CfgDir', "'TestDir'/config"}. + {define, 'SuiteDir', "'TestDir'/suites"}. + {config, 'CfgDir', "nodeA.cfg"}. + {groups, 'SuiteDir', x_SUITE, group1}.</pre> - <p>Actually, constants could well replace the <c>node</c> term too, but - this still has declarative value, mainly when used in combination - with <c>NodeRefs == all_nodes</c> (see types above).</p> + <p>Constants can well replace term <c>node</c> also, but + this still has a declarative value, mainly when used in combination + with <c>NodeRefs == all_nodes</c> + (see <seealso marker="#types">Types</seealso>).</p> </section> <section> @@ -955,104 +1049,104 @@ <p>Here follows a simple test specification example:</p> <pre> - {define, 'Top', "/home/test"}. - {define, 'T1', "'Top'/t1"}. - {define, 'T2', "'Top'/t2"}. - {define, 'T3', "'Top'/t3"}. - {define, 'CfgFile', "config.cfg"}. - - {logdir, "'Top'/logs"}. - - {config, ["'T1'/'CfgFile'", "'T2'/'CfgFile'", "'T3'/'CfgFile'"]}. - - {suites, 'T1', all}. - {skip_suites, 'T1', [t1B_SUITE,t1D_SUITE], "Not implemented"}. - {skip_cases, 'T1', t1A_SUITE, [test3,test4], "Irrelevant"}. - {skip_cases, 'T1', t1C_SUITE, [test1], "Ignore"}. - - {suites, 'T2', [t2B_SUITE,t2C_SUITE]}. - {cases, 'T2', t2A_SUITE, [test4,test1,test7]}. - - {skip_suites, 'T3', all, "Not implemented"}.</pre> + {define, 'Top', "/home/test"}. + {define, 'T1', "'Top'/t1"}. + {define, 'T2', "'Top'/t2"}. + {define, 'T3', "'Top'/t3"}. + {define, 'CfgFile', "config.cfg"}. + + {logdir, "'Top'/logs"}. + + {config, ["'T1'/'CfgFile'", "'T2'/'CfgFile'", "'T3'/'CfgFile'"]}. + + {suites, 'T1', all}. + {skip_suites, 'T1', [t1B_SUITE,t1D_SUITE], "Not implemented"}. + {skip_cases, 'T1', t1A_SUITE, [test3,test4], "Irrelevant"}. + {skip_cases, 'T1', t1C_SUITE, [test1], "Ignore"}. + + {suites, 'T2', [t2B_SUITE,t2C_SUITE]}. + {cases, 'T2', t2A_SUITE, [test4,test1,test7]}. + + {skip_suites, 'T3', all, "Not implemented"}.</pre> <p>The example specifies the following:</p> - <list> - <item>The specified logdir directory will be used for storing + <list type="bulleted"> + <item>The specified <c>logdir</c> directory is used for storing the HTML log files (in subdirectories tagged with node name, - date and time).</item> - <item>The variables in the specified test system config files will be + date, and time).</item> + <item>The variables in the specified test system configuration files are imported for the test.</item> - <item>The first test to run includes all suites for system t1. Excluded from - the test are however the t1B and t1D suites. Also test cases test3 and - test4 in t1A as well as the test1 case in t1C are excluded from - the test.</item> - <item>Secondly, the test for system t2 should run. The included suites are - t2B and t2C. Included are also test cases test4, test1 and test7 in suite - t2A. Note that the test cases will be executed in the specified order.</item> - <item>Lastly, all suites for systems t3 are to be completely skipped and this - should be explicitly noted in the log files.</item> + <item>The first test to run includes all suites for system <c>t1</c>. + Suites <c>t1B</c> and <c>t1D</c> are excluded from the test. Test cases + <c>test3</c> and <c>test4</c> in <c>t1A</c> and <c>test1</c> case in <c>t1C</c> + are also excluded from the test.</item> + <item>The second test to run is for system <c>t2</c>. The included suites are + <c>t2B</c> and <c>t2C</c>. Test cases <c>test4</c>, <c>test1</c>, and <c>test7</c> in suite + <c>t2A</c> are also included. The test cases are executed in the specified order.</item> + <item>The last test to run is for system <c>t3</c>. Here, all suites are skipped and this + is explicitly noted in the log files.</item> </list> </section> <section> - <title>The init term</title> - <p>With the <c>init</c> term it's possible to specify initialization options - for nodes defined in the test specification. Currently, there are options - to start the node and/or to evaluate any function on the node. - See the <seealso marker="ct_master_chapter#ct_slave">Automatic startup of - the test target nodes</seealso> chapter for details.</p> + <title>The init Term</title> + <p>With term <c>init</c> it is possible to specify initialization options + for nodes defined in the test specification. There are options + to start the node and to evaluate any function on the node. + For details, see section <seealso marker="ct_master_chapter#ct_slave">Automatic Startup of + Test Target Nodes</seealso> in section Using Common Test for Large Scale Testing.</p> </section> <section> - <title>User specific terms</title> - <p>It is possible for the user to provide a test specification that - includes (for Common Test) unrecognizable terms. If this is desired, - the <c>-allow_user_terms</c> flag should be used when starting tests with - <c>ct_run</c>. This forces Common Test to ignore unrecognizable terms. - Note that in this mode, Common Test is not able to check the specification - for errors as efficiently as if the scanner runs in default mode. + <title>User-Specific Terms</title> + <p>The user can provide a test specification including (for <c>Common Test</c>) + unrecognizable terms. If this is desired, use flag <c>-allow_user_terms</c> + when starting tests with <c>ct_run</c>. This forces <c>Common Test</c> to ignore + unrecognizable terms. In this mode, <c>Common Test</c> is not able to check the + specification for errors as efficiently as if the scanner runs in default mode. If <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso> is used - for starting the tests, the relaxed scanner - mode is enabled by means of the tuple: <c>{allow_user_terms,true}</c></p> + for starting the tests, the relaxed scanner mode is enabled by tuple + <c>{allow_user_terms,true}</c>.</p> </section> <section> - <title>Reading test specification terms</title> - <p>It's possible to look up terms in the current test specification - (i.e. the spec that's been used to configure and run the current test). - The function <c>get_testspec_terms()</c> returns a list of all test spec - terms (both config- and test terms) and <c>get_testspec_terms(Tags)</c> - returns the term (or a list of terms) matching the tag (or tags) in - <c>Tags</c>.</p> + <title>Reading Test Specification Terms</title> + <p>Terms in the current test specification + (that is, the specification that has been used to configure and run the current test) + can be looked up. + The function <seealso marker="ct#get_testspec_terms-0"><c>get_testspec_terms()</c></seealso> + returns a list of all test specification terms (both configuration terms and test terms), + and <c>get_testspec_terms(Tags)</c> returns the term (or a list of terms) matching the + tag (or tags) in <c>Tags</c>.</p> <p>For example, in the test specification:</p> <pre> - ... - {label, my_server_smoke_test}. - {config, "../../my_server_setup.cfg"}. - {config, "../../my_server_interface.cfg"}. - ...</pre> - <p>And in e.g. a test suite or a CT hook function:</p> + ... + {label, my_server_smoke_test}. + {config, "../../my_server_setup.cfg"}. + {config, "../../my_server_interface.cfg"}. + ...</pre> + <p>And in, for example, a test suite or a <c>Common Test Hook</c> function:</p> <pre> - ... - [{label,[{_Node,TestType}]}, {config,CfgFiles}] = - ct:get_testspec_terms([label,config]), + ... + [{label,[{_Node,TestType}]}, {config,CfgFiles}] = + ct:get_testspec_terms([label,config]), - [verify_my_server_cfg(TestType, CfgFile) || {Node,CfgFile} <- CfgFiles, - Node == node()]; - ...</pre> + [verify_my_server_cfg(TestType, CfgFile) || {Node,CfgFile} <- CfgFiles, + Node == node()]; + ...</pre> </section> </section> <section> - <title>Running tests from the Web based GUI</title> + <title>Running Tests from the Web-Based GUI</title> - <p>The web based GUI, VTS, is started with the + <p>The web-based GUI, Virtual Test Server (VTS), is started with the <seealso marker="run_test_chapter#ct_run"><c>ct_run</c></seealso> - program. From the GUI you can load config files, and select - directories, suites and cases to run. You can also state the - config files, directories, suites and cases on the command line - when starting the web based GUI. + program. From the GUI, you can load configuration files and select + directories, suites, and cases to run. You can also state the + configuration files, directories, suites, and cases on the command line + when starting the web-based GUI. </p> - - <list> + <p><em>Examples:</em></p> + <list type="bulleted"> <item><c>ct_run -vts</c></item> <item><c><![CDATA[ct_run -vts -config <configfilename>]]></c></item> <item><c><![CDATA[ct_run -vts -config <configfilename> -suite <suitewithfullpath> @@ -1062,454 +1156,464 @@ <p>From the GUI you can run tests and view the result and the logs. </p> - <p>Note that <c>ct_run -vts</c> will try to open the Common Test start - page in an existing web browser window or start the browser if it is - not running. Which browser should be started may be specified with + <p><c>ct_run -vts</c> tries to open the <c>Common Test</c> start + page in an existing web browser window, or start the browser if it is + not running. Which browser to start can be specified with the browser start command option:</p> <p><c><![CDATA[ct_run -vts -browser <browser_start_cmd>]]></c></p> - <p>Example:</p> + <p><em>Example:</em></p> <p><c><![CDATA[$ ct_run -vts -browser 'firefox&']]></c></p> - <p>Note that the browser must run as a separate OS process or VTS will hang!</p> - <p>If no specific browser start command is specified, Firefox will - be the default browser on Unix platforms and Internet Explorer on Windows. - If Common Test fails to start a browser automatically, or <c>'none'</c> is - specified as the value for -browser (i.e. <c>-browser none</c>), start your - favourite browser manually and type in the URL that Common Test + + <note><p>The browser must run as a separate OS process, otherwise VTS hangs.</p></note> + + <p>If no specific browser start command is specified, Firefox is + the default browser on Unix platforms, and Internet Explorer on Windows. + If <c>Common Test</c> fails to start a browser automatically, or <c>none</c> is + specified as the value for <c>-browser</c> (that is, <c>-browser none</c>), start your + favourite browser manually and type the URL that <c>Common Test</c> displays in the shell.</p> </section> <section> <marker id="log_files"></marker> - <title>Log files</title> + <title>Log Files</title> <p>As the execution of the test suites proceed, events are logged in - four different ways:</p> + the following four different ways:</p> - <list> - <item>Text to the operator's console.</item> - <item>Suite related information is sent to the major log file.</item> - <item>Case related information is sent to the minor log file.</item> - <item>The HTML overview log file gets updated with test results.</item> + <list type="bulleted"> + <item>Text to the operator console.</item> + <item>Suite-related information is sent to the major log file.</item> + <item>Case-related information is sent to the minor log file.</item> + <item>The HTML overview log file is updated with test results.</item> <item>A link to all runs executed from a certain directory is written in - the log named "all_runs.html" and direct links to all tests (the - latest results) are written to the top level "index.html".</item> + the log named <c>all_runs.html</c> and direct links to all tests (the + latest results) are written to the top-level <c>index.html</c>.</item> </list> - <p>Typically the operator, who may run hundreds or thousands of - test cases, doesn't want to fill the console with details - about, or printouts from, the specific test cases. By default, the - operator will only see:</p> + <p>Typically the operator, possibly running hundreds or thousands of + test cases, does not want to fill the console with details + about, or printouts from, specific test cases. By default, the + operator only sees the following:</p> - <list> + <list type="bulleted"> <item>A confirmation that the test has started and information about how - many test cases will be executed totally.</item> + many test cases are executed in total.</item> <item>A small note about each failed test case.</item> <item>A summary of all the run test cases.</item> - <item>A confirmation that the test run is complete.</item> - <item>Some special information like error reports and progress - reports, printouts written with erlang:display/1, or io:format/3 + <item>A confirmation when the test run is complete.</item> + <item>Some special information, such as error reports, progress + reports, and printouts written with <c>erlang:display/1</c>, or <c>io:format/3</c> specifically addressed to a receiver other than <c>standard_io</c> - (e.g. the default group leader process 'user').</item> + (for example, the default group leader process <c>user</c>).</item> </list> - <p>If/when the operator wants to dig deeper into the general results, or - the result of a specific test case, he should do so by - following the links in the HTML presentation and take a look in the - major or minor log files. The "all_runs.html" page is a practical - starting point usually. It's located in <c>logdir</c> and contains - a link to each test run including a quick overview (date and time, - node name, number of tests, test names and test result totals).</p> + <p>To dig deeper into the general results, or + the result of a specific test case, the operator can do so by + following the links in the HTML presentation and read the + major or minor log files. The "all_runs.html" page is a good + starting point. It is located in <c>logdir</c> and contains + a link to each test run, including a quick overview (with date and time, + node name, number of tests, test names, and test result totals).</p> - <p>An "index.html" page is written for each test run (i.e. stored in - the "ct_run" directory tagged with node name, date and time). This - file gives a short overview of all individual tests performed in the - same test run. The test names follow this convention:</p> - <list> - <item><em>TopLevelDir.TestDir</em> (all suites in TestDir executed)</item> - <item><em>TopLevelDir.TestDir:suites</em> (specific suites were executed)</item> - <item><em>TopLevelDir.TestDir.Suite</em> (all cases in Suite executed)</item> - <item><em>TopLevelDir.TestDir.Suite:cases</em> (specific test cases were executed)</item> - <item><em>TopLevelDir.TestDir.Suite.Case</em> (only Case was executed)</item> + <p>An "index.html" page is written for each test run (that is, stored in + the <c>ct_run</c> directory tagged with node name, date, and time). This + file provides an overview of all individual tests performed in the + same test run. The test names follow the following convention:</p> + <list type="bulleted"> + <item><c>TopLevelDir.TestDir</c> (all suites in <c>TestDir</c> executed)</item> + <item><c>TopLevelDir.TestDir:suites</c> (specific suites executed)</item> + <item><c>TopLevelDir.TestDir.Suite</c> (all cases in <c>Suite</c> executed)</item> + <item><c>TopLevelDir.TestDir.Suite:cases</c> (specific test cases executed)</item> + <item><c>TopLevelDir.TestDir.Suite.Case</c> (only <c>Case</c> executed)</item> </list> - <p>On the test run index page there is a link to the Common Test + <p>The "test run index" page includes a link to the <c>Common Test</c> Framework Log file in which information about imported configuration data and general test progress is written. This log file is useful to get snapshot information about the test - run during execution. It can also be very helpful when + run during execution. It can also be helpful when analyzing test results or debugging test suites.</p> - <p>On the test run index page it is noted if a test has missing - suites (i.e. suites that Common Test has failed to + <p>The "test run index" page indicates if a test has missing + suites (that is, suites that <c>Common Test</c> failed to compile). Names of the missing suites can be found in the - Common Test Framework Log file.</p> + <c>Common Test</c> Framework Log file.</p> <p>The major log file shows a detailed report of the test run. It includes test suite and test case names, execution time, the - exact reason for failures etc. The information is available in both + exact reason for failures, and so on. The information is available in both a file with textual and with HTML representation. The HTML file shows a - summary which gives a good overview of the test run. It also has links + summary that gives a good overview of the test run. It also has links to each individual test case log file for quick viewing with an HTML browser.</p> <p>The minor log files contain full details of every single test - case, each one in a separate file. This way, it should be + case, each in a separate file. This way, it is straightforward to compare the latest results to that of previous - test runs, even if the set of test cases changes. If SASL is running, - its logs will also be printed to the current minor log file by the + test runs, even if the set of test cases changes. If application <c>SASL</c> + is running, its logs are also printed to the current minor log file by the <seealso marker="common_test:ct_hooks_chapter#builtin_cths"> cth_log_redirect built-in hook</seealso>. </p> - <p>The full name of the minor log file (i.e. the name of the file + <p>The full name of the minor log file (that is, the name of the file including the absolute directory path) can be read during execution - of the test case. It comes as value in the tuple + of the test case. It comes as value in tuple <c>{tc_logfile,LogFileName}</c> in the <c>Config</c> list (which means it - can also be read by a pre- or post Common Test hook function). Also, + can also be read by a pre- or post <c>Common Test Hook</c> function). Also, at the start of a test case, this data is sent with an event - to any installed event handler. Please see the - <seealso marker="event_handler_chapter#event_handling">Event Handling</seealso> - chapter for details. + to any installed event handler. For details, see section + <seealso marker="event_handler_chapter#event_handling">Event Handling</seealso>. </p> - - <p>Which information goes where is user configurable via the - test server controller. Three threshold values determine what - comes out on screen, and in the major or minor log files. See - the OTP Test Server manual for information. The contents that - goes to the HTML log file is fixed however and cannot be altered.</p> - - <p>The log files are written continously during a test run and links are - always created initially when a test starts. This makes it possible - to follow test progress simply by refreshing pages in the HTML browser. + + <p>The log files are written continuously during a test run and links are + always created initially when a test starts. Thevtest progress can therefore + be followed simply by refreshing pages in the HTML browser. Statistics totals are not presented until a test is complete however.</p> <section> <marker id="logopts"></marker> - <title>Log options</title> - <p>With the <c>logopts</c> start flag, it's possible to specify - options that modify some aspects of the logging behaviour. - Currently, the following options are available:</p> - <list> - <item><c>no_src</c></item> - <item><c>no_nl</c></item> - </list> - <p>With <c>no_src</c>, the html version of the test suite source - code will not be generated during the test run (and consequently - not be available in the log file system).</p> - <p>With <c>no_nl</c>, Common Test will not add a newline character - (\n) to the end of an output string that it receives from a call to e.g. - <c>io:format/2</c>, and which it prints to the test case log.</p> + <title>Log Options</title> + <p>With start flag <c>logopts</c> options that modify some aspects + of the logging behavior can be specified. + The following options are available:</p> + <taglist> + <tag><c>no_src</c></tag> + <item><p>The HTML version of the test suite source code is not + generated during the test run (and is consequently not available + in the log file system).</p></item> + <tag><c>no_nl</c></tag> + <item><p><c>Common Test</c> does not add a newline character <c>(\n)</c> + to the end of an output string that it receives from a call to, for example, + <c>io:format/2</c>, and which it prints to the test case log.</p></item> + </taglist> + <p>For example, if a test is started with:</p> <p><c>$ ct_run -suite my_SUITE -logopts no_src</c></p> <p>then printouts during the test made by successive calls to <c>io:format("x")</c>, - will appear in the test case log as:</p> + appears in the test case log as:</p> <p><c>xxx</c></p> - <p>instead of each <c>x</c> printed on a new line, which is the default behaviour.</p> + <p>instead of each <c>x</c> printed on a new line, which is the default behavior.</p> </section> <section> <marker id="table_sorting"></marker> - <title>Sorting HTML table columns</title> - <p>By clicking the name in the column header of any table (e.g. "Ok", "Case", "Time", etc), - the table rows are sorted in whatever order makes sense for the type of value (e.g. - numerical for "Ok" or "Time", and alphabetical for "Case"). The sorting is performed - by means of JavaScript code, automatically inserted into the HTML log files. Common Test - uses the <url href="http://jquery.com">jQuery</url> library and the - <url href="http://tablesorter.com">tablesorter</url> plugin, with customized sorting - functions, for this implementation.</p> + <title>Sorting HTML Table Columns</title> + <p>By clicking the name in the column header of any table + (for example, "Ok", "Case", "Time", and so on), the table rows are sorted + in whatever order makes sense for the type of value (for example, + numerical for "Ok" or "Time", and alphabetical for "Case"). The sorting is + performed through JavaScript code, automatically inserted into the HTML + log files. <c>Common Test</c> uses the <url href="http://jquery.com">jQuery</url> + library and the + <url href="http://tablesorter.com">tablesorter</url> plugin, + with customized sorting functions, for this implementation.</p> </section> <section> <title>The Unexpected I/O Log</title> - <p>On the test suites overview page you find a link to the Unexpected I/O Log. - In this log, Common Test saves printouts made with - <c>ct:log/2</c> and <c>ct:pal/2</c>, as well as captured system error- and - progress reports, that cannot be associated with particular test cases and - therefore cannot be written to individual test case log files. This happens e.g. - if a log printout is made from an external process (not a test case process), - or if an error- or progress report comes in, during a short interval while Common - Test is not executing a test case or configuration function, <em>or</em> while - Common Test is currently executing a parallell test case group.</p> + <p>The test suites overview page includes a link to the Unexpected I/O Log. + In this log, <c>Common Test</c> saves printouts made with + <seealso marker="ct#log-2"><c>ct:log/2</c></seealso> and + <seealso marker="ct#pal-2"><c>ct:pal/2</c></seealso>, as well as captured system + error- and progress reports, which cannot be associated with particular test cases and + therefore cannot be written to individual test case log files. This occurs, + for example, if a log printout is made from an external process (not a test + case process), <em>or</em> if an error- or progress report comes in, during a short + interval while <c>Common Test</c> is not executing a test case or configuration + function, <em>or</em> while <c>Common Test</c> is currently executing a parallel + test case group.</p> </section> <section> <marker id="pre_post_test_io_log"></marker> <title>The Pre- and Post Test I/O Log</title> - <p>On the Common Test Framework Log page you find links to the so called - Pre- and Post Test I/O Log. In this log, Common Test saves printouts made with - <c>ct:log/2</c> and <c>ct:pal/2</c>, as well as captured system error- - and progress reports, that take place before - and after - the actual test run. + <p>The <c>Common Test</c> Framework Log page includes links to the + Pre- and Post Test I/O Log. In this log, <c>Common Test</c> saves printouts made + with <c>ct:log/2</c> and <c>ct:pal/2</c>, as well as captured system error- + and progress reports, which take place before, and after, the test run. Examples of this are printouts from a CT hook init- or terminate function, or progress reports generated when an OTP application is started from a CT hook - init function. Another example is an error report generated due to + init function. Another example is an error report generated because of a failure when an external application is stopped from a CT hook terminate function. All information in these examples ends up in the Pre- and Post Test I/O Log. For more information on how to synchronize test runs with external user - applications, please see the + applications, see section <seealso marker="ct_hooks_chapter#synchronizing">Synchronizing</seealso> - section in the Common Test Hooks chapter.</p> - <p>Note that logging to file with <c>ct:log/2</c> or <c>ct:pal/2</c> - only works when Common Test is running. Printouts with <c>ct:pal/2</c> - are however always displayed on screen.</p> + in section Common Test Hooks.</p> + <note><p>Logging to file with <c>ct:log/2</c> or <c>ct:pal/2</c> + only works when <c>Common Test</c> is running. Printouts with <c>ct:pal/2</c> + are however always displayed on screen.</p></note> </section> </section> <section> <marker id="html_stylesheet"></marker> <title>HTML Style Sheets</title> - <p>Common Test uses an HTML Style Sheet (CSS file) to control the look of - the HTML log files generated during test runs. If, for some reason, the - log files are not displayed correctly in the browser of your - choice, or you prefer a more primitive ("pre Common Test v1.6") look - of the logs, use the start flag/option:</p> - <pre>basic_html</pre> - <p>This disables the use of Style Sheets, as well as JavaScripts (see - table sorting above).</p> + <p><c>Common Test</c> uses an HTML Style Sheet (CSS file) to control the look of + the HTML log files generated during test runs. If the log files are not + displayed correctly in the browser of your choice, or you prefer a more + primitive ("pre <c>Common Test</c> v1.6") look of the logs, use the start + flag/option:</p> + <pre> + basic_html</pre> + <p>This disables the use of style sheets and JavaScripts (see + <seealso marker="#table_sorting">Sorting HTML Table Columns</seealso>).</p> - <p>Common Test includes an <em>optional</em> feature to allow + <p><c>Common Test</c> includes an <em>optional</em> feature to allow user HTML style sheets for customizing printouts. The functions in <c>ct</c> that print to a test case HTML log file (<c>log/3</c> and <c>pal/3</c>) accept <c>Category</c> - as first argument. With this argument it's possible to - specify a category that can be mapped to a selector in a CSS - definition. This is useful especially for coloring text + as first argument. With this argument a category can be specified + that can be mapped to a selector in a CSS + definition. This is useful, especially for coloring text differently depending on the type of (or reason for) the printout. Say you want one color for test system configuration information, a different one for test system - state information and finally one for errors detected by the - test case functions. The corresponding style sheet may - look like this:</p> + state information, and finally one for errors detected by the + test case functions. The corresponding style sheet can + look as follows:</p> <pre> - div.sys_config { background:blue; color:white } - div.sys_state { background:yellow; color:black } - div.error { background:red; color:white }</pre> + div.sys_config { background:blue; color:white } + div.sys_state { background:yellow; color:black } + div.error { background:red; color:white }</pre> - <p>To install the CSS file (Common Test inlines the definition in the - HTML code), the name may be provided when executing <c>ct_run</c>. - Example:</p> + <p>To install the CSS file (<c>Common Test</c> inlines the definition in the + HTML code), the name can be provided when executing <c>ct_run</c>.</p> + <p><em>Example:</em></p> <pre> - $ ct_run -dir $TEST/prog -stylesheet $TEST/styles/test_categories.css</pre> + $ ct_run -dir $TEST/prog -stylesheet $TEST/styles/test_categories.css</pre> - <p>Categories in a CSS file installed with the <c>-stylesheet</c> flag + <p>Categories in a CSS file installed with flag <c>-stylesheet</c> are on a global test level in the sense that they can be used in any - suite which is part of the test run.</p> + suite that is part of the test run.</p> - <p>It is also possible to install style sheets on a per suite and - per test case basis. Example:</p> + <p>Style sheets can also be installed on a per suite and + per test case basis.</p> + <p><em>Example:</em></p> <pre> - -module(my_SUITE). - ... - suite() -> [..., {stylesheet,"suite_categories.css"}, ...]. - ... - my_testcase(_) -> - ... - ct:log(sys_config, "Test node version: ~p", [VersionInfo]), - ... - ct:log(sys_state, "Connections: ~p", [ConnectionInfo]), - ... - ct:pal(error, "Error ~p detected! Info: ~p", [SomeFault,ErrorInfo]), - ct:fail(SomeFault).</pre> + -module(my_SUITE). + ... + suite() -> [..., {stylesheet,"suite_categories.css"}, ...]. + ... + my_testcase(_) -> + ... + ct:log(sys_config, "Test node version: ~p", [VersionInfo]), + ... + ct:log(sys_state, "Connections: ~p", [ConnectionInfo]), + ... + ct:pal(error, "Error ~p detected! Info: ~p", [SomeFault,ErrorInfo]), + ct:fail(SomeFault).</pre> <p>If the style sheet is installed as in this example, the categories are private to the suite in question. They can be used by all test cases in the - suite, but can not be used by other suites. A suite private style sheet, - if specified, will be used in favour of a global style sheet (one specified - with the <c>-stylesheet</c> flag). A stylesheet tuple (as returned by <c>suite/0</c> - above) can also be returned from a test case info function. In this case the + suite, but cannot be used by other suites. A suite private style sheet, + if specified, is used in favor of a global style sheet (one specified + with flag <c>-stylesheet</c>). A stylesheet tuple (as returned by <c>suite/0</c> + above) can also be returned from a test case information function. In this case the categories specified in the style sheet can only be used in that particular - test case. A test case private style sheet is used in favour of a suite or + test case. A test case private style sheet is used in favor of a suite or global level style sheet. </p> <p>In a tuple <c>{stylesheet,CSSFile}</c>, if <c>CSSFile</c> is specified - with a path, e.g. <c>"$TEST/styles/categories.css"</c>, this full - name will be used to locate the file. If only the file name is specified - however, e.g. "categories.css", then the CSS file is assumed to be located - in the data directory, <c>data_dir</c>, of the suite. The latter usage is - recommended since it is portable compared to hard coding path names in the - suite!</p> - - <p>The <c>Category</c> argument in the example above may have the + with a path, for example, <c>"$TEST/styles/categories.css"</c>, this full + name is used to locate the file. However, if only the file name is specified, + for example, <c>categories.css</c>, the CSS file is assumed to be located + in the data directory, <c>data_dir</c>, of the suite. The latter use is + recommended, as it is portable compared to hard coding path names in the + suite.</p> + + <p>Argument <c>Category</c> in the previous example can have the value (atom) <c>sys_config</c> (white on blue), <c>sys_state</c> - (black on yellow) or <c>error</c> (white on red).</p> + (black on yellow), or <c>error</c> (white on red).</p> </section> <section> <marker id="repeating_tests"></marker> - <title>Repeating tests</title> - <p>You can order Common Test to repeat the tests you specify. You can choose - to repeat tests a certain number of times, repeat tests for a specific period of time, + <title>Repeating Tests</title> + <p>You can order <c>Common Test</c> to repeat the tests you specify. You can choose + to repeat tests a number of times, repeat tests for a specific period of time, or repeat tests until a particular stop time is reached. If repetition is controlled by - means of time, it is also possible to specify what action Common Test should - take upon timeout. Either Common Test performs all tests in the current run before stopping, - or it stops as soon as the current test job is finished. Repetition can be activated by - means of <c>ct_run</c> start flags, or tuples in the <c>ct:run:test/1</c> - option list argument. The flags (options in parenthesis) are:</p> - <list> - <item><c>-repeat N ({repeat,N})</c>, where <c>N</c> is a positive integer.</item> - <item><c>-duration DurTime ({duration,DurTime})</c>, where <c>DurTime</c> is the duration, see below.</item> - <item><c>-until StopTime ({until,StopTime})</c>, where <c>StopTime</c> is finish time, see below.</item> + time, an action for <c>Common Test</c> to take upon time-out can be specified. + Either <c>Common Test</c> performs all tests in the current run + before stopping, or it stops when the current test job is finished. Repetition + can be activated by <c>ct_run</c> start flags, or tuples in the <c>ct:run:test/1</c> + option list argument. The flags (options in parentheses) are the following:</p> + <list type="bulleted"> + <item><c>-repeat N ({repeat,N})</c>, where <c>N</c> is a positive integer</item> + <item><c>-duration DurTime ({duration,DurTime})</c>, where <c>DurTime</c> is the duration</item> + <item><c>-until StopTime ({until,StopTime})</c>, where <c>StopTime</c> is finish time</item> <item><c>-force_stop ({force_stop,true})</c></item> <item><c>-force_stop skip_rest ({force_stop,skip_rest})</c></item> </list> - <p>The duration time, <c>DurTime</c>, is specified as <c>HHMMSS</c>. Example: - <c>-duration 012030</c> or <c>{duration,"012030"}</c>, means the tests will - be executed and (if time allows) repeated, until timeout occurs after 1 h, 20 min - and 30 secs. - <c>StopTime</c> can be specified as <c>HHMMSS</c> and is then interpreted as a time today - (or possibly tomorrow). <c>StopTime</c> can also be specified as <c>YYMoMoDDHHMMSS</c>. - Example: <c>-until 071001120000</c> or <c>{until,"071001120000"}</c>, which means the tests - will be executed and (if time allows) repeated, until 12 o'clock on the 1st of Oct 2007.</p> - - <p>When timeout occurs, Common Test will never abort the ongoing test case, since - this might leave the system under test in an undefined, and possibly bad, state. - Instead Common Test will by default finish the current test - run before stopping. If the <c>force_stop</c> flag is - given, Common Test will stop as soon as the current test job - is finished, and if the <c>force_stop</c> flag is given with - <c>skip_rest</c> Common Test will only complete the current - test case and skip the rest of the tests in the test job. - Note that since Common Test always finishes off at least the - current test case, - the time specified with <c>duration</c> or <c>until</c> is never definitive!</p> - - <p>Log files from every single repeated test run is saved in normal Common Test fashion (see above). - Common Test may later support an optional feature to only store the last (and possibly - the first) set of logs of repeated test runs, but for now the user must be careful not - to run out of disk space if tests are repeated during long periods of time.</p> - - <p>Note that for each test run that is part of a repeated session, information about the - particular test run is printed in the Common Test Framework Log. There you can read - the repetition number, remaining time, etc.</p> - - <p>Example 1:</p> + <taglist> + <tag><c>DurTime</c></tag> + <item><p>The duration time is specified as <c>HHMMSS</c>, for example, <c>-duration 012030</c> + or <c>{duration,"012030"}</c></p>, which means that the tests are executed and + (if time allows) repeated until time-out occurs after 1 hour, 20 minutes, and 30 seconds. + </item> + <tag><c>StopTime</c></tag> + <item><p>The finish time can be specified as <c>HHMMSS</c> and is then interpreted as a + time today (or possibly tomorrow), but can also be specified as <c>YYMoMoDDHHMMSS</c>, + for example, <c>-until 071001120000</c> or <c>{until,"071001120000"}</c>. This means + that the tests are executed and (if time allows) repeated, until 12 o'clock on the 1st + of October 2007.</p> + </item> + </taglist> + + <p>When time-out occurs, <c>Common Test</c> never aborts the ongoing test case, + as this can leave the SUT in an undefined, and possibly bad, state. + Instead <c>Common Test</c>, by default, finishes the current test + run before stopping. If flag <c>force_stop</c> is + specified, <c>Common Test</c> stops when the current test job + is finished. If flag <c>force_stop</c> is specified with + <c>skip_rest</c>, <c>Common Test</c> only completes the current + test case and skips the remaining tests in the test job.</p> + <note><p>As <c>Common Test</c> always finishes at least the current test case, + the time specified with <c>duration</c> or <c>until</c> is never definitive.</p></note> + + <p>Log files from every repeated test run is saved in normal <c>Common Test</c> + fashion (described earlier).</p> + <p><c>Common Test</c> might later support an optional feature to only store the last (and possibly + the first) set of logs of repeated test runs, but for now the user must be careful not + to run out of disk space if tests are repeated during long periods of time.</p> + + <p>For each test run that is part of a repeated session, information about the + particular test run is printed in the <c>Common Test</c> Framework Log. The information + includes the repetition number, remaining time, and so on.</p> + + <p><em>Example 1:</em></p> <pre> - $ ct_run -dir $TEST_ROOT/to1 $TEST_ROOT/to2 -duration 001000 -force_stop</pre> - <p>Here the suites in test directory to1, followed by the suites in to2, will be executed - in one test run. A timeout event will occur after 10 minutes. As long as there is time - left, Common Test will repeat the test run (i.e. starting over with the to1 test). - When the timeout occurs, Common Test will stop as soon as the current job is finished - (because of the <c>force_stop</c> flag). As a result, the specified test run might be - aborted after the to1 test and before the to2 test.</p> - - <p>Example 2:</p> + $ ct_run -dir $TEST_ROOT/to1 $TEST_ROOT/to2 -duration 001000 -force_stop</pre> + + <p>Here, the suites in test directory <c>to1</c>, followed by the suites in <c>to2</c>, are + executed in one test run. A time-out event occurs after 10 minutes. As long as there is + time left, <c>Common Test</c> repeats the test run (that is, starting over with test <c>to1</c>). + After time-out, <c>Common Test</c> stops when the current job is finished + (because of flag <c>force_stop</c>). As a result, the specified test run can be + aborted after test <c>to1</c> and before test <c>to2</c>.</p> + + <p><em>Example 2:</em></p> <pre> - $ ct_run -dir $TEST_ROOT/to1 $TEST_ROOT/to2 -duration 001000 -forces_stop skip_rest</pre> - <p>Here the same test run as in Example 1, but with the - <c>force_stop</c> flag set to <c>skip_rest</c>. If the timeout - occurs while executing tests in directory to1, the rest of the - test cases in to1 will be skipped and then the test will be - aborted without running the tests in to2 another time. If the - timeout occurs while executing tests in directory to2, then the - rest of the test cases in to2 will be skipped and then the test - will be aborted.</p> - - <p>Example 3:</p> + $ ct_run -dir $TEST_ROOT/to1 $TEST_ROOT/to2 -duration 001000 -forces_stop skip_rest</pre> + + <p>Here, the same tests as in Example 1 are run, but with flag <c>force_stop</c> set to + <c>skip_rest</c>. If time-out occurs while executing tests in directory <c>to1</c>, + the remaining test cases in <c>to1</c> are skipped and the test is aborted without + running the tests in <c>to2</c> another time. If time-out occurs while executing + tests in directory <c>to2</c>, the remaining test cases in <c>to2</c> are skipped and + the test is aborted.</p> + + <p><em>Example 3:</em></p> <pre> - $ date - Fri Sep 28 15:00:00 MEST 2007 - - $ ct_run -dir $TEST_ROOT/to1 $TEST_ROOT/to2 -until 160000</pre> - <p>Here the same test run as in the example above will be executed (and possibly repeated). - In this example, however, the timeout will occur after 1 hour and when that happens, - Common Test will finish the entire test run before stopping (i.e. the to1 and to2 test - will always both be executed in the same test run).</p> + $ date + Fri Sep 28 15:00:00 MEST 2007 + + $ ct_run -dir $TEST_ROOT/to1 $TEST_ROOT/to2 -until 160000</pre> + + <p>Here, the same test run as in the previous examples are executed (and possibly repeated). + However, when the time-out occurs, after 1 hour, <c>Common Test</c> finishes the entire + test run before stopping (that is, both <c>to1</c> and <c>to2</c> are always executed in + the same test run).</p> - <p>Example 4:</p> + <p><em>Example 4:</em></p> <pre> - $ ct_run -dir $TEST_ROOT/to1 $TEST_ROOT/to2 -repeat 5</pre> - <p>Here the test run, including both the to1 and the to2 test, will be repeated 5 times.</p> + $ ct_run -dir $TEST_ROOT/to1 $TEST_ROOT/to2 -repeat 5</pre> + + <p>Here, the test run, including both the <c>to1</c> and the <c>to2</c> test, is repeated + five times.</p> - <note><p>This feature should not be confused with the <c>repeat</c> property of a test + <note><p>Do not confuse this feature with the <c>repeat</c> property of a test case group. The options described here are used to repeat execution of entire test runs, while the <c>repeat</c> property of a test case group makes it possible to repeat execution of sets of test cases within a suite. For more information about the latter, - see the <seealso marker="write_test_chapter#test_case_groups">Writing Test Suites</seealso> - chapter.</p></note> + see section <seealso marker="write_test_chapter#test_case_groups">Test Case Groups </seealso> + in section Writing Test Suites.</p></note> </section> <section> <marker id="silent_connections"></marker> <title>Silent Connections</title> - <p>The protocol handling processes in Common Test, implemented by ct_telnet, - ct_ssh, ct_ftp etc, do verbose printing to the test case logs. This can be switched off - by means of the <c>-silent_connections</c> flag:</p> + <p>The protocol handling processes in <c>Common Test</c>, implemented by <c>ct_telnet</c>, + <c>ct_ssh</c>, <c>ct_ftp</c>, and so on, do verbose printing to the test case logs. + This can be switched off with flag <c>-silent_connections</c>:</p> <pre> - ct_run -silent_connections [conn_types] - </pre> + ct_run -silent_connections [conn_types]</pre> - <p>where <c>conn_types</c> specifies <c>ssh, telnet, ftp, rpc</c> and/or <c>snmp</c>.</p> + <p>Here, <c>conn_types</c> specifies SSH, Telnet, FTP, RPC, and/or SNMP.</p> - <p>Example:</p> + <p><em>Example 1:</em></p> <pre> - ct_run ... -silent_connections ssh telnet</pre> - <p>switches off logging for ssh and telnet connections.</p> + ct_run ... -silent_connections ssh telnet</pre> + <p>This switches off logging for SSH and Telnet connections.</p> + + <p><em>Example 2:</em></p> <pre> - ct_run ... -silent_connections</pre> - <p>switches off logging for all connection types.</p> + ct_run ... -silent_connections</pre> + <p>This switches off logging for all connection types.</p> - <p>Fatal communication error and reconnection attempts will always be printed even - if logging has been suppressed for the connection type in question. However, operations - such as sending and receiving data will be performed silently.</p> + <p>Fatal communication error and reconnection attempts are always printed, even if + logging has been suppressed for the connection type in question. However, operations + such as sending and receiving data are performed silently.</p> - <p>It is possible to also specify <c>silent_connections</c> in a test suite. This is + <p><c>silent_connections</c> can also be specified in a test suite. This is accomplished by returning a tuple, <c>{silent_connections,ConnTypes}</c>, in the - <c>suite/0</c> or test case info list. If <c>ConnTypes</c> is a list of atoms - (<c>ssh, telnet, ftp, rpc</c> and/or <c>snmp</c>), output for any corresponding connections - will be suppressed. Full logging is per default enabled for any connection of type not + <c>suite/0</c> or test case information list. If <c>ConnTypes</c> is a list of atoms + (SSH, Telnet, FTP, RPC and/or SNMP), output for any corresponding connections + are suppressed. Full logging is by default enabled for any connection of type not specified in <c>ConnTypes</c>. Hence, if <c>ConnTypes</c> is the empty list, logging is enabled for all connections.</p> - <p>Example:</p> + <p><em>Example 3:</em></p> <pre> - - -module(my_SUITE). + -module(my_SUITE). - suite() -> [..., {silent_connections,[telnet,ssh]}, ...]. + suite() -> [..., {silent_connections,[telnet,ssh]}, ...]. - ... + ... - my_testcase1() -> - [{silent_connections,[ssh]}]. + my_testcase1() -> + [{silent_connections,[ssh]}]. - my_testcase1(_) -> - ... + my_testcase1(_) -> + ... - my_testcase2(_) -> - ... - </pre> + my_testcase2(_) -> + ...</pre> - <p>In this example, <c>suite/0</c> tells Common Test to suppress - printouts from telnet and ssh connections. This is valid for + <p>In this example, <c>suite/0</c> tells <c>Common Test</c> to suppress + printouts from Telnet and SSH connections. This is valid for all test cases. However, <c>my_testcase1/0</c> specifies that - for this test case, only ssh should be silent. The result is - that <c>my_testcase1</c> will get telnet info (if any) printed - in the log, but not ssh info. <c>my_testcase2</c> will get no - info from either connection printed.</p> + for this test case, only SSH is to be silent. The result is + that <c>my_testcase1</c> gets Telnet information (if any) printed + in the log, but not SSH information. <c>my_testcase2</c> gets no + information from either connection printed.</p> - <p><c>silent_connections</c> may also be specified with a term + <p><c>silent_connections</c> can also be specified with a term in a test specification - (see <seealso marker="run_test_chapter#test_specifications">Test - Specifications</seealso>). Connections provided with the - <c>silent_connections</c> start flag/option, will be merged with - any connections listed in the test specification.</p> + (see section <seealso marker="run_test_chapter#test_specifications">Test + Specifications</seealso> in section Running Tests and Analyzing Results). + Connections provided with start flag/option <c>silent_connections</c> + are merged with any connections listed in the test specification.</p> - <p>The <c>silent_connections</c> start flag/option and test - specification term, overrides any settings made by the info functions + <p>Start flag/option <c>silent_connections</c> and the test + specification term override any settings made by the information functions inside the test suite.</p> - <note><p>Note that in the current Common Test version, the - <c>silent_connections</c> feature only works for telnet - and ssh connections! Support for other connection types will be added - in future Common Test versions.</p></note> + <note><p>In the current <c>Common Test</c> version, the + <c>silent_connections</c> feature only works for Telnet + and SSH connections. Support for other connection types can be added + in future <c>Common Test</c> versions.</p></note> </section> </chapter> diff --git a/lib/common_test/doc/src/test_structure_chapter.xml b/lib/common_test/doc/src/test_structure_chapter.xml index d5b92b163f..8076244928 100644 --- a/lib/common_test/doc/src/test_structure_chapter.xml +++ b/lib/common_test/doc/src/test_structure_chapter.xml @@ -31,167 +31,167 @@ </header> <section> - <title>Test structure</title> + <title>General</title> <p>A test is performed by running one or more test suites. A test suite - consists of test cases (as well as configuration functions and info - functions). Test cases may be grouped in so called test case groups. + consists of test cases, configuration functions, and information + functions. Test cases can be grouped in so called test case groups. A test suite is an Erlang module and test cases are implemented as Erlang functions. Test suites are stored in test directories.</p> </section> <section> - <title>Skipping test cases</title> + <marker id="skipping_test_cases"></marker> + <title>Skipping Test Cases</title> - <p>It is possible to skip certain test cases, for example if you - know beforehand that a specific test case fails. This might be - functionality which isn't yet implemented, a bug that is known but - not yet fixed or some functionality which doesn't work or isn't + <p>Certain test cases can be skipped, for example, if you + know beforehand that a specific test case fails. The reason can be + functionality that is not yet implemented, a bug that is known but + not yet fixed, or some functionality that does not work or is not applicable on a specific platform.</p> - <p>There are several different ways to state that one or more - test cases should be skipped:</p> - <list> + <p>Test cases can be skipped in the following ways:</p> + <list type="bulleted"> <item>Using <c>skip_suites</c> and <c>skip_cases</c> terms in <seealso marker="run_test_chapter#test_specifications">test specifications</seealso>. </item> - <item>Returning <c>{skip,Reason}</c> from the - <c>init_per_testcase/2</c> or <c>init_per_suite/1</c> functions.</item> + <item>Returning <c>{skip,Reason}</c> from function + <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase/2</c></seealso> or + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite/1</c></seealso>.</item> <item>Returning <c>{skip,Reason}</c> from the execution clause - of the test case.</item> + of the test case. The execution clause is called, so the author + must ensure that the test case does not run.</item> </list> - <p>The latter of course means that the execution clause is - actually called, so the author must make sure that the test case - does not run.</p> - - <p>When a test case is skipped, it will be noted as <c>SKIPPED</c> + <p>When a test case is skipped, it is noted as <c>SKIPPED</c> in the HTML log.</p> </section> <section> - <title>Definition of terms</title> + <title>Definition of Terms</title> <taglist> - <tag><em>Auto skipped test case</em></tag> + <tag><em>Auto-skipped test case</em></tag> <item> - When a configuration function fails (i.e. terminates unexpectedly), - the test cases that depend on the configuration function will be - skipped automatically by Common Test. The status of the test cases - is then "auto skipped". Test cases are also auto skipped by - Common Test if required configuration data is not available at - runtime. + <p>When a configuration function fails (that is, terminates unexpectedly), + the test cases depending on the configuration function are + skipped automatically by <c>Common Test</c>. The status of the test cases + is then "auto-skipped". Test cases are also "auto-skipped" by + <c>Common Test</c> if the required configuration data is unavailable at + runtime.</p> </item> <tag><em>Configuration function</em></tag> <item> - A function in a test suite that is meant to be used for + <p>A function in a test suite that is meant to be used for setting up, cleaning up, and/or verifying the state and - environment on the SUT (System Under Test) and/or the Common Test + environment on the System Under Test (SUT) and/or the <c>Common Test</c> host node, so that a test case (or a set of test cases) can - execute correctly. + execute correctly.</p> </item> <tag><em>Configuration file</em></tag> <item> - A file that contains data related to a test and/or an SUT - (System Under Test), e.g. protocol server addresses, client - login details, hardware interface addresses, etc - any data - that should be handled as variable in the suite and not - be hardcoded. + <p>A file containing data related to a test and/or an SUT, + for example, protocol server addresses, client + login details, and hardware interface addresses. That is, any data + that is to be handled as variable in the suite and not + be hard-coded.</p> </item> <tag><em>Configuration variable</em></tag> <item> - A name (an Erlang atom) associated with a data value read from - a configuration file. + <p>A name (an Erlang atom) associated with a data value read from + a configuration file.</p> </item> - <tag><em>data_dir</em></tag> + <tag><c>data_dir</c></tag> <item> - Data directory for a test suite. This directory contains - any files used by the test suite, e.g. additional Erlang - modules, binaries or data files. + <p>Data directory for a test suite. This directory contains + any files used by the test suite, for example, extra Erlang + modules, binaries, or data files.</p> </item> - <tag><em>Info function</em></tag> + <tag><em>Information function</em></tag> <item> - A function in a test suite that returns a list of properties - (read by the Common Test server) that describes the conditions - for executing the test cases in the suite. + <p>A function in a test suite that returns a list of properties + (read by the <c>Common Test</c> server) that describes the conditions + for executing the test cases in the suite.</p> </item> <tag><em>Major log file</em></tag> <item> - An overview and summary log file for one or more test suites. + <p>An overview and summary log file for one or more test suites.</p> </item> <tag><em>Minor log file</em></tag> <item> - A log file for one particular test case. Also called the - test case log file. + <p>A log file for one particular test case. Also called the + test case log file.</p> </item> - <tag><em>priv_dir</em></tag> + + <tag><c>priv_dir</c></tag> <item> - Private directory for a test suite. This directory should - be used when the test suite needs to write to files. + <p>Private directory for a test suite. This directory is to + be used when the test suite needs to write to files.</p> </item> - <tag><em>ct_run</em></tag> + <tag><c>ct_run</c></tag> <item> - The name of an executable program that may be + <p>The name of an executable program that can be used as an interface for specifying and running - tests with Common Test. + tests with <c>Common Test</c>.</p> </item> <tag><em>Test case</em></tag> <item> - A single test included in a test suite. A test case is - implemented as a function in a test suite module. + <p>A single test included in a test suite. A test case is + implemented as a function in a test suite module.</p> </item> <tag><em>Test case group</em></tag> <item> - A set of test cases that share configuration functions and - execution properties. The execution properties specify whether - the test cases in the group should be executed in random order, - in parallel, in sequence, and if the execution of the group - should be repeated. Test case groups may also be nested (i.e. a - group may, besides test cases, contain sub-groups). + <p>A set of test cases sharing configuration functions and + execution properties. The execution properties specify if + the test cases in the group are to be executed in random order, + in parallel, or in sequence, and if the execution of the group + is be repeated. Test case groups can also be nested. That is, + a group can, besides test cases, contain subgroups.</p> </item> <tag><em>Test suite</em></tag> <item> - An erlang module containing a collection of test cases for - a specific functional area. + <p>An Erlang module containing a collection of test cases for + a specific functional area.</p> </item> <tag><em>Test directory</em></tag> <item> - A directory that contains one or more test suite modules, i.e. - a group of test suites. + <p>A directory containing one or more test suite modules, + that is, a group of test suites.</p> </item> - <tag><em>The Config argument</em></tag> + <tag><em>Argument</em> <c>Config</c></tag> <item> - A list of key-value tuples (i.e. a property list) containing + <p>A list of key-value tuples (that is, a property list) containing runtime configuration data passed from the configuration - functions to the test cases. + functions to the test cases.</p> </item> - <tag><em>User skipped test case</em></tag> + <tag><em>User-skipped test case</em></tag> <item> - This is the status of a test case that has been explicitly - skipped in any of the ways described in the "Skipping test cases" - section above. + <p>The status of a test case explicitly skipped in any of + the ways described in section + <seealso marker="#skipping_test_cases">Skipping Test Cases</seealso>. + </p> </item> diff --git a/lib/common_test/doc/src/unix_telnet.xml b/lib/common_test/doc/src/unix_telnet.xml new file mode 100644 index 0000000000..189379c39a --- /dev/null +++ b/lib/common_test/doc/src/unix_telnet.xml @@ -0,0 +1,134 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE erlref SYSTEM "erlref.dtd"> + +<erlref> + <header> + <copyright> + <year>2010</year><year>2012</year> + <holder>Ericsson AB. All Rights Reserved.</holder> + </copyright> + <legalnotice> + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + </legalnotice> + + <title>unix_telnet</title> + <prepared></prepared> + <responsible></responsible> + <docno></docno> + <approved></approved> + <checked></checked> + <date></date> + <rev>A</rev> + <file>unix_telnet.xml</file> + </header> + <module>unix_telnet</module> + <modulesummary>Callback module for ct_telnet, for connecting to a Telnet + server on a UNIX host.</modulesummary> + + <description> + + <p>Callback module for + <seealso marker="ct_telnet"><c>ct_telnet</c></seealso>, + for connecting to a Telnet server on a UNIX host.</p> + + <p>It requires the following entry in the configuration file:</p> + + <pre> + {unix,[{telnet,HostNameOrIpAddress}, + {port,PortNum}, % optional + {username,UserName}, + {password,Password}, + {keep_alive,Bool}]}. % optional</pre> + + <p>To communicate through Telnet to the host specified by + <c>HostNameOrIpAddress</c>, use the interface functions in + <seealso marker="ct_telnet"><c>ct_telnet</c></seealso>, for example, + <c>open(Name)</c> and <c>cmd(Name,Cmd)</c>.</p> + + <p><c>Name</c> is the name you allocated to the Unix host in your + <c>require</c> statement, for example:</p> + + <pre> + suite() -> [{require,Name,{unix,[telnet]}}].</pre> + + <p>or</p> + + <pre> + ct:require(Name,{unix,[telnet]}).</pre> + + <p>The "keep alive" activity (that is, that <c>Common Test</c> sends NOP + to the server every 10 seconds if the connection is idle) can be + enabled or disabled for one particular connection as described here. + It can be disabled for all connections using <c>telnet_settings</c> + (see <seealso marker="ct_telnet"><c>ct_telnet</c></seealso>).</p> + + <p>The <c>{port,PortNum}</c> tuple is optional and if omitted, default + Telnet port 23 is used. Also the <c>keep_alive</c> tuple is optional, + and the value defauls to <c>true</c> (enabled).</p> + </description> + + <funcs> + <func> + <name>connect(ConnName, Ip, Port, Timeout, KeepAlive, Extra) -> {ok, Handle} | {error, Reason}</name> + <fsummary>Callback for ct_telnet.erl.</fsummary> + <type> + <v>ConnName = target_name()</v> + <v>Ip = string() | {integer(), integer(), integer(), integer()}</v> + <v>Port = integer()</v> + <v>Timeout = integer()</v> + <v>KeepAlive = bool()</v> + <v>Extra = target_name() | {Username, Password}</v> + <v>Username = string()</v> + <v>Password = string()</v> + <v>Handle = handle()</v> + <v>Reason = term()</v> + </type> + <desc><marker id="connect-6"/> + <p>Callback for <c>ct_telnet.erl</c>.</p> + + <p>Setup Telnet connection to a Unix host.</p> + + <p>For <c>target_name()</c>, see + <seealso marker="ct"><c>ct</c></seealso>. For <c>handle()</c>, see + <seealso marker="ct_telnet"><c>ct_telnet</c></seealso>.</p> + </desc> + </func> + + <func> + <name>get_prompt_regexp() -> PromptRegexp</name> + <fsummary>Callback for ct_telnet.erl.</fsummary> + <type> + <v>PromptRegexp = prompt_regexp()</v> + </type> + <desc><marker id="get_prompt_regexp-0"/> + <p>Callback for <c>ct_telnet.erl</c>.</p> + + <p>Returns a suitable <c>regexp</c> string matching common prompts + for users on Unix hosts.</p> + + <p>For <c>prompt_regexp()</c>, see + <seealso marker="ct_telnet"><c>ct_telnet</c></seealso>.</p> + </desc> + </func> + </funcs> + + <section> + <title>See Also</title> + <p><seealso marker="ct"><c>ct</c></seealso>, + <seealso marker="ct_telnet"><c>ct_telnet</c></seealso></p> + </section> + +</erlref> + + diff --git a/lib/common_test/doc/src/why_test_chapter.xml b/lib/common_test/doc/src/why_test_chapter.xml index 15eb1aaed4..ff6000628b 100644 --- a/lib/common_test/doc/src/why_test_chapter.xml +++ b/lib/common_test/doc/src/why_test_chapter.xml @@ -22,7 +22,7 @@ </legalnotice> - <title>Some thoughts about testing</title> + <title>Some Thoughts about Testing</title> <prepared>Siri Hansen</prepared> <docno></docno> <date></date> @@ -34,54 +34,53 @@ <section> <title>Goals</title> - <p>It's not possible to prove that a program is correct by + <p>It is not possible to prove that a program is correct by testing. On the contrary, it has been formally proven that it is impossible to prove programs in general by testing. Theoretical - program proofs or plain examination of code may be viable options - for those that wish to certify that a program is correct. The test + program proofs or plain examination of code can be viable options + for those wishing to certify that a program is correct. The test server, as it is based on testing, cannot be used for certification. Its intended use is instead to (cost effectively) <em>find bugs</em>. A successful test suite is one that reveals a - bug. If a test suite results in Ok, then we know very little that - we didn't know before.</p> + bug. If a test suite results in OK, then we know very little that + we did not know before.</p> </section> <section> - <title>What to test?</title> + <title>What to Test</title> <p> There are many kinds of test suites. Some concentrate on calling every function or command (in the documented way) in a certain interface. - Some other do the same, but uses all kinds of illegal - parameters, and verifies that the server stays alive and rejects + Some others do the same, but use all kinds of illegal + parameters, and verify that the server stays alive and rejects the requests with reasonable error codes. Some test suites simulate an application (typically consisting of a few modules of - an application), some try to do tricky requests in general, some + an application), some try to do tricky requests in general, and some test suites even test internal functions with help of special - load-modules on target.</p> + Load Modules on target.</p> - <p>Another interesting category of test suites are the ones that - check that fixed bugs don't reoccur. When a bugfix is introduced, - a test case that checks for that specific bug should be written - and submitted to the affected test suite(s).</p> + <p>Another interesting category of test suites is the one + checking that fixed bugs do not reoccur. When a bugfix is introduced, + a test case that checks for that specific bug is written + and submitted to the affected test suites.</p> <p>Aim for finding bugs. Write whatever test that has the highest probability of finding a bug, now or in the future. Concentrate - more on the critical parts. Bugs in critical subsystems are a lot + more on the critical parts. Bugs in critical subsystems are much more expensive than others.</p> <p>Aim for functionality testing rather than implementation details. Implementation details change quite often, and the test - suites should be long lived. Often implementation details differ + suites are to be long lived. Implementation details often differ on different platforms and versions. If implementation details - have to be tested, try to factor them out into separate test - cases. Later on these test cases may be rewritten, or just - skipped.</p> + must be tested, try to factor them out into separate test + cases. These test cases can later be rewritten or skipped.</p> - <p>Also, aim for testing everything once, no less, no more. It's - not effective having every test case fail just because one + <p>Also, aim for testing everything once, no less, no more. It is + not effective having every test case fail only because one function in the interface changed.</p> </section> diff --git a/lib/common_test/doc/src/write_test_chapter.xml b/lib/common_test/doc/src/write_test_chapter.xml index 1f5650651f..e3811ec4cf 100644 --- a/lib/common_test/doc/src/write_test_chapter.xml +++ b/lib/common_test/doc/src/write_test_chapter.xml @@ -32,84 +32,88 @@ <section> <marker id="intro"></marker> - <title>Support for test suite authors</title> + <title>Support for Test Suite Authors</title> - <p>The <c>ct</c> module provides the main interface for writing - test cases. This includes e.g:</p> + <p>The <seealso marker="ct"><c>ct</c></seealso> module provides the main + interface for writing test cases. This includes for example, the following:</p> - <list> + <list type="bulleted"> <item>Functions for printing and logging</item> <item>Functions for reading configuration data</item> <item>Function for terminating a test case with error reason</item> <item>Function for adding comments to the HTML overview page</item> </list> - <p>Please see the reference manual for the <c>ct</c> - module for details about these functions.</p> + <p>For details about these functions, see module <seealso marker="ct"><c>ct</c></seealso>.</p> - <p>The CT application also includes other modules named - <c><![CDATA[ct_<component>]]></c> that + <p>The <c>Common Test</c> application also includes other modules named + <c><![CDATA[ct_<component>]]></c>, which provide various support, mainly simplified use of communication - protocols such as rpc, snmp, ftp, telnet, etc.</p> + protocols such as RPC, SNMP, FTP, Telnet, and others.</p> </section> <section> - <title>Test suites</title> + <title>Test Suites</title> <p>A test suite is an ordinary Erlang module that contains test cases. It is recommended that the module has a name on the form <c>*_SUITE.erl</c>. Otherwise, the directory and auto compilation - function in CT will not be able to locate it (at least not per default). + function in <c>Common Test</c> cannot locate it (at least not by default). </p> <p>It is also recommended that the <c>ct.hrl</c> header file is included in all test suite modules. </p> - <p>Each test suite module must export the function <c>all/0</c> + <p>Each test suite module must export function + <seealso marker="common_test#Module:all-0"><c>all/0</c></seealso>, which returns the list of all test case groups and test cases to be executed in that module. </p> - <p>The callback functions that the test suite should implement, and - which will be described in more detail below, are - all listed in the <seealso marker="common_test">common_test - reference manual page</seealso>. + <p>The callback functions to be implemented by the test suite are + all listed in module <seealso marker="common_test">common_test + </seealso>. They are also described in more detail later in this User's Guide. </p> </section> <section> - <title>Init and end per suite</title> + <title>Init and End per Suite</title> - <p>Each test suite module may contain the optional configuration functions - <c>init_per_suite/1</c> and <c>end_per_suite/1</c>. If the init function - is defined, so must the end function be. + <p>Each test suite module can contain the optional configuration functions + <seealso marker="common_test#Module:init_per_suite-1"><c>init_per_suite/1</c></seealso> + and <seealso marker="common_test#Module:end_per_suite-1"><c>end_per_suite/1</c></seealso>. + If the init function is defined, so must the end function be. </p> - <p>If it exists, <c>init_per_suite</c> is called initially before the - test cases are executed. It typically contains initializations that are - common for all test cases in the suite, and that are only to be - performed once. It is recommended to be used for setting up and - verifying state and environment on the SUT (System Under Test) and/or - the CT host node, so that the test cases in the suite will execute - correctly. Examples of initial configuration operations: Opening a connection - to the SUT, initializing a database, running an installation script, etc. + <p>If <c>init_per_suite</c> exists, it is called initially before the + test cases are executed. It typically contains initializations common + for all test cases in the suite, which are only to be performed once. + <c>init_per_suite</c> is recommended for setting up and verifying state + and environment on the System Under Test (SUT) or the <c>Common Test</c> + host node, or both, so that the test cases in the suite executes correctly. + The following are examples of initial configuration operations: </p> + <list type="bulleted"> + <item>Opening a connection to the SUT</item> + <item>Initializing a database</item> + <item>Running an installation script</item> + </list> <p><c>end_per_suite</c> is called as the final stage of the test suite execution (after the last test case has finished). The function is meant to be used for cleaning up after <c>init_per_suite</c>. </p> - <p><c>init_per_suite</c> and <c>end_per_suite</c> will execute on dedicated + <p><c>init_per_suite</c> and <c>end_per_suite</c> execute on dedicated Erlang processes, just like the test cases do. The result of these functions - is however not included in the test run statistics of successful, failed and + is however not included in the test run statistics of successful, failed, and skipped cases. </p> - <p>The argument to <c>init_per_suite</c> is <c>Config</c>, the + <p>The argument to <c>init_per_suite</c> is <c>Config</c>, that is, the same key-value list of runtime configuration data that each test case takes as input argument. <c>init_per_suite</c> can modify this parameter with information that the test cases need. The possibly modified <c>Config</c> @@ -117,671 +121,683 @@ </p> <p>If <c>init_per_suite</c> fails, all test cases in the test - suite will be skipped automatically (so called <em>auto skipped</em>), + suite are skipped automatically (so called <em>auto skipped</em>), including <c>end_per_suite</c>. </p> - <p>Note that if <c>init_per_suite</c> and <c>end_per_suite</c> do not exist - in the suite, Common Test calls dummy functions (with the same names) - instead, so that output generated by hook functions may be saved to the log - files for these dummies - (see the <seealso marker="ct_hooks_chapter#manipulating">Common Test Hooks</seealso> - chapter for more information). + <p>Notice that if <c>init_per_suite</c> and <c>end_per_suite</c> do not exist + in the suite, <c>Common Test</c> calls dummy functions (with the same names) + instead, so that output generated by hook functions can be saved to the log + files for these dummies. For details, see + <seealso marker="ct_hooks_chapter#manipulating">Common Test Hooks</seealso>. </p> </section> <section> <marker id="per_testcase"/> - <title>Init and end per test case</title> + <title>Init and End per Test Case</title> <p>Each test suite module can contain the optional configuration functions - <c>init_per_testcase/2</c> and <c>end_per_testcase/2</c>. If the init function - is defined, so must the end function be.</p> + <seealso marker="common_test#Module:init_per_testcase-2"><c>init_per_testcase/2</c></seealso> + and <seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase/2</c></seealso>. + If the init function is defined, so must the end function be.</p> - <p>If it exists, <c>init_per_testcase</c> is called before each - test case in the suite. It typically contains initialization which - must be done for each test case (analogue to <c>init_per_suite</c> for the + <p>If <c>init_per_testcase</c> exists, it is called before each + test case in the suite. It typically contains initialization that + must be done for each test case (analog to <c>init_per_suite</c> for the suite).</p> <p><c>end_per_testcase/2</c> is called after each test case has - finished, giving the opportunity to perform clean-up after - <c>init_per_testcase</c>.</p> + finished, enabling cleanup after <c>init_per_testcase</c>.</p> <p>The first argument to these functions is the name of the test case. This value can be used with pattern matching in function clauses or conditional expressions to choose different initialization and cleanup - routines for different test cases, or perform the same routine for a number of, + routines for different test cases, or perform the same routine for many, or all, test cases.</p> <p>The second argument is the <c>Config</c> key-value list of runtime configuration data, which has the same value as the list returned by - <c>init_per_suite</c>. <c>init_per_testcase/2</c> may modify this - parameter or return it as is. The return value of <c>init_per_testcase/2</c> - is passed as the <c>Config</c> parameter to the test case itself.</p> + <c>init_per_suite</c>. <c>init_per_testcase/2</c> can modify this + parameter or return it "as is". The return value of <c>init_per_testcase/2</c> + is passed as parameter <c>Config</c> to the test case itself.</p> <p>The return value of <c>end_per_testcase/2</c> is ignored by the test server, with exception of the - <seealso marker="dependencies_chapter#save_config">save_config</seealso> + <seealso marker="dependencies_chapter#save_config"><c>save_config</c></seealso> and <c>fail</c> tuple.</p> - <p>It is possible in <c>end_per_testcase</c> to check if the - test case was successful or not (which consequently may determine - how cleanup should be performed). This is done by reading the value - tagged with <c>tc_status</c> from <c>Config</c>. The value is either - <c>ok</c>, <c>{failed,Reason}</c> (where <c>Reason</c> is <c>timetrap_timeout</c>, - info from <c>exit/1</c>, or details of a run-time error), or - <c>{skipped,Reason}</c> (where Reason is a user specific term). + <p><c>end_per_testcase</c> can check if the test case was successful. + (which in turn can determine how cleanup is to be performed). + This is done by reading the value tagged with <c>tc_status</c> from + <c>Config</c>. The value is one of the following: </p> - - <p>The <c>end_per_testcase/2</c> function is called even after a - test case terminates due to a call to <seealso marker="ct#abort_current_testcase-1"><c>ct:abort_current_testcase/1</c></seealso>, - or after a timetrap timeout. However, <c>end_per_testcase</c> - will then execute on a different process than the test case - function, and in this situation, <c>end_per_testcase</c> will - not be able to change the reason for test case termination by - returning <c>{fail,Reason}</c>, nor will it be able to save data with - <c>{save_config,Data}</c>.</p> - - <p>If <c>init_per_testcase</c> crashes, the test case itself gets skipped - automatically (so called <em>auto skipped</em>). If <c>init_per_testcase</c> - returns a tuple <c>{skip,Reason}</c>, also then the test case gets skipped - (so called <em>user skipped</em>). It is also possible, by returning a tuple - <c>{fail,Reason}</c> from <c>init_per_testcase</c>, to mark the test case - as failed without actually executing it. + <list type="bulleted"> + <item> + <p><c>ok</c></p> + </item> + <item> + <p><c>{failed,Reason}</c></p> + <p>where <c>Reason</c> is <c>timetrap_timeout</c>, information from <c>exit/1</c>, + or details of a runtime error</p></item> + <item> + <p><c>{skipped,Reason}</c></p> + <p>where <c>Reason</c> is a user-specific term</p></item> + </list> + + <p>Function <c>end_per_testcase/2</c> is even called if a + test case terminates because of a call to + <seealso marker="ct#abort_current_testcase-1"><c>ct:abort_current_testcase/1</c></seealso>, + or after a timetrap time-out. However, <c>end_per_testcase</c> + then executes on a different process than the test case + function. In this situation, <c>end_per_testcase</c> cannot + change the reason for test case termination by returning <c>{fail,Reason}</c> + or save data with <c>{save_config,Data}</c>.</p> + + <p>The test case is skipped in the following two cases: </p> + <list type="bulleted"> + <item>If <c>init_per_testcase</c> crashes (called <em>auto skipped</em>).</item> + <item>If <c>init_per_testcase</c> returns a tuple <c>{skip,Reason}</c> + (called <em>user skipped</em>).</item> + </list> + <p>The test case can also be marked as failed without executing it + by returning a tuple <c>{fail,Reason}</c> from <c>init_per_testcase</c>.</p> + <note><p>If <c>init_per_testcase</c> crashes, or returns <c>{skip,Reason}</c> - or <c>{fail,Reason}</c>, the <c>end_per_testcase</c> function is not called. + or <c>{fail,Reason}</c>, function <c>end_per_testcase</c> is not called. </p></note> <p>If it is determined during execution of <c>end_per_testcase</c> that - the status of a successful test case should be changed to failed, - <c>end_per_testcase</c> may return the tuple: <c>{fail,Reason}</c> + the status of a successful test case is to be changed to failed, + <c>end_per_testcase</c> can return the tuple <c>{fail,Reason}</c> (where <c>Reason</c> describes why the test case fails).</p> - <p><c>init_per_testcase</c> and <c>end_per_testcase</c> execute on the - same Erlang process as the test case and printouts from these - configuration functions can be found in the test case log file.</p> + <p>As <c>init_per_testcase</c> and <c>end_per_testcase</c> execute on the + same Erlang process as the test case, printouts from these + configuration functions are included in the test case log file.</p> </section> <section> <marker id="test_cases"></marker> - <title>Test cases</title> + <title>Test Cases</title> <p>The smallest unit that the test server is concerned with is a - test case. Each test case can actually test many things, for - example make several calls to the same interface function with + test case. Each test case can test many things, for + example, make several calls to the same interface function with different parameters. </p> - <p>It is possible to choose to put many or few tests into each test - case. What exactly each test case does is of course up to the - author, but here are some things to keep in mind: + <p>The author can choose to put many or few tests into each test + case. Some things to keep in mind follows: </p> - - <p>Having many small test cases tend to result in extra, and possibly + <list type="bulleted"> + <item><p>Many small test cases tend to result in extra, and possibly duplicated code, as well as slow test execution because of - large overhead for initializations and cleanups. Duplicated - code should be avoided, e.g. by means of common help functions, or - the resulting suite will be difficult to read and understand, and + large overhead for initializations and cleanups. Avoid duplicated + code, for example, by using common help functions. Otherwise, + the resulting suite becomes difficult to read and understand, and expensive to maintain. - </p> - - <p>Larger test cases make it harder to tell what went wrong if it - fails, and large portions of test code will potentially be skipped - when errors occur. Furthermore, readability and maintainability suffers - when test cases become too large and extensive. Also, the resulting log - files may not reflect very well the number of tests that have - actually been performed. - </p> + </p></item> + <item><p>Larger test cases make it harder to tell what went wrong if it + fails. Also, large portions of test code risk being skipped + when errors occur.</p> + </item> + <item><p>Readability and maintainability suffer + when test cases become too large and extensive. It is not certain + that the resulting log files reflect very well the number of tests + performed. + </p></item> + </list> <p>The test case function takes one argument, <c>Config</c>, which contains configuration information such as <c>data_dir</c> and - <c>priv_dir</c>. (See <seealso marker="#data_priv_dir">Data and - Private Directories</seealso> for more information about these). - The value of <c>Config</c> at the time of the call, is the same - as the return value from <c>init_per_testcase</c>, see above. + <c>priv_dir</c>. (For details about these, see section + <seealso marker="#data_priv_dir">Data and Private Directories</seealso>. + The value of <c>Config</c> at the time of the call, is the same + as the return value from <c>init_per_testcase</c>, mentioned earlier. </p> - <note><p>The test case function argument <c>Config</c> should not be - confused with the information that can be retrieved from + <note><p>The test case function argument <c>Config</c> is not to be + confused with the information that can be retrieved from the configuration files (using <seealso marker="ct#get_config-1"><c> - ct:get_config/1/2</c></seealso>). The Config argument - should be used for runtime configuration of the test suite and the - test cases, while configuration files should typically contain data + ct:get_config/1/2</c></seealso>). The test case argument <c>Config</c> + is to be used for runtime configuration of the test suite and the + test cases, while configuration files are to contain data related to the SUT. These two types of configuration data are handled - differently!</p></note> + differently.</p></note> - <p>Since the <c>Config</c> parameter is a list of key-value tuples, i.e. - a data type generally called a property list, it can be handled by means of the - <c>proplists</c> module in the OTP <c>stdlib</c>. A value can for example - be searched for and returned with the <c>proplists:get_value/2</c> function. - Also, or alternatively, you might want to look in the general <c>lists</c> module, - also in <c>stdlib</c>, for useful functions. Normally, the only operations you - ever perform on <c>Config</c> is insert (adding a tuple to the head of the list) - and lookup. Common Test provides a simple macro named <c>?config</c>, which returns - a value of an item in <c>Config</c> given the key (exactly like + <p>As parameter <c>Config</c> is a list of key-value tuples, that is, + a data type called a property list, it can be handled by the + <seealso marker="stdlib:proplists"><c>stdlib:proplists</c></seealso> module. + A value can, for example, be searched for and returned with function + <seealso marker="stdlib:proplists#get_value-2"><c>proplists:get_value/2</c></seealso>. + Also, or alternatively, the general <seealso marker="stdlib:lists"><c>stdlib:lists</c></seealso> + module contains useful functions. Normally, the only operations + performed on <c>Config</c> is insert (adding a tuple to the head of the list) + and lookup. <c>Common Test</c> provides a simple macro named <c>?config</c>, + which returns a value of an item in <c>Config</c> given the key (exactly like <c>proplists:get_value</c>). Example: <c>PrivDir = ?config(priv_dir, Config)</c>. </p> <p>If the test case function crashes or exits purposely, it is considered - <em>failed</em>. If it returns a value (no matter what actual value) it is + <em>failed</em>. If it returns a value (no matter what value), it is considered successful. An exception to this rule is the return value <c>{skip,Reason}</c>. If this tuple is returned, the test case is considered - skipped and gets logged as such.</p> + skipped and is logged as such.</p> <p>If the test case returns the tuple <c>{comment,Comment}</c>, the case - is considered successful and <c>Comment</c> is printed out in the overview - log file. This is by the way equal to calling <c>ct:comment(Comment)</c>. + is considered successful and <c>Comment</c> is printed in the overview + log file. This is equal to calling + <seealso marker="ct#comment-1"><c>ct:comment(Comment)</c></seealso>. </p> </section> <section> <marker id="info_function"></marker> - <title>Test case info function</title> + <title>Test Case Information Function</title> - <p>For each test case function there can be an additional function - with the same name but with no arguments. This is the test case - info function. The test case info function is expected to return a - list of tagged tuples that specifies various properties regarding the - test case. + <p>For each test case function there can be an extra function + with the same name but without arguments. This is the test case + information function. It is expected to return a list of tagged + tuples that specifies various properties regarding the test case. </p> <p>The following tags have special meaning:</p> <taglist> - <tag><em><c>timetrap</c></em></tag> + <tag><c>timetrap</c></tag> <item> <p> - Set the maximum time the test case is allowed to execute. If - the timetrap time is exceeded, the test case fails with - reason <c>timetrap_timeout</c>. Note that <c>init_per_testcase</c> + Sets the maximum time the test case is allowed to execute. If + this time is exceeded, the test case fails with + reason <c>timetrap_timeout</c>. Notice that <c>init_per_testcase</c> and <c>end_per_testcase</c> are included in the timetrap time. - Please see the <seealso marker="write_test_chapter#timetraps">Timetrap</seealso> - section for more details. + For details, see section + <seealso marker="write_test_chapter#timetraps">Timetrap Time-Outs</seealso>. </p> </item> - <tag><em><c>userdata</c></em></tag> + <tag><c>userdata</c></tag> <item> <p> - Use this to specify arbitrary data related to the testcase. This - data can be retrieved at any time using the <seealso marker="ct#userdata-3"><c>ct:userdata/3</c></seealso> + Specifies any data related to the test case. This + data can be retrieved at any time using the + <seealso marker="ct#userdata-3"><c>ct:userdata/3</c></seealso> utility function. </p> </item> - <tag><em><c>silent_connections</c></em></tag> + <tag><c>silent_connections</c></tag> <item> <p> - Please see the - <seealso marker="run_test_chapter#silent_connections">Silent Connections</seealso> - chapter for details. + For details, see section + <seealso marker="run_test_chapter#silent_connections">Silent Connections</seealso>. </p> </item> - <tag><em><c>require</c></em></tag> + <tag><c>require</c></tag> <item> <p> - Use this to specify configuration variables that are required by the + Specifies configuration variables required by the test case. If the required configuration variables are not found in any of the test system configuration files, the test case is skipped.</p> <p> - It is also possible to give a required variable a default value that will + A required variable can also be given a default value to be used if the variable is not found in any configuration file. To specify - a default value, add a tuple on the form: - <c>{default_config,ConfigVariableName,Value}</c> to the test case info list + a default value, add a tuple on the form + <c>{default_config,ConfigVariableName,Value}</c> to the test case information list (the position in the list is irrelevant). - Examples:</p> + </p> + <p><em>Examples:</em></p> <pre> - testcase1() -> - [{require, ftp}, - {default_config, ftp, [{ftp, "my_ftp_host"}, - {username, "aladdin"}, - {password, "sesame"}]}}].</pre> + testcase1() -> + [{require, ftp}, + {default_config, ftp, [{ftp, "my_ftp_host"}, + {username, "aladdin"}, + {password, "sesame"}]}}].</pre> <pre> - testcase2() -> - [{require, unix_telnet, unix}, - {require, {unix, [telnet, username, password]}}, - {default_config, unix, [{telnet, "my_telnet_host"}, - {username, "aladdin"}, - {password, "sesame"}]}}].</pre> + testcase2() -> + [{require, unix_telnet, unix}, + {require, {unix, [telnet, username, password]}}, + {default_config, unix, [{telnet, "my_telnet_host"}, + {username, "aladdin"}, + {password, "sesame"}]}}].</pre> </item> </taglist> - <p>See the <seealso marker="config_file_chapter#require_config_data">Config files</seealso> - chapter and the <seealso marker="ct#require-1"><c> - ct:require/1/2</c></seealso> function in the - <seealso marker="ct">ct</seealso> reference manual for more information about - <c>require</c>.</p> + <p>For more information about <c>require</c>, see section + <seealso marker="config_file_chapter#require_config_data"> + Requiring and Reading Configuration Data</seealso> + in section External Configuration Data and function + <seealso marker="ct#require-1"><c>ct:require/1/2</c></seealso>.</p> <note><p>Specifying a default value for a required variable can result - in a test case always getting executed. This might not be a desired behaviour!</p> + in a test case always getting executed. This might not be a desired behavior.</p> </note> - <p>If <c>timetrap</c> and/or <c>require</c> is not set specifically for - a particular test case, default values specified by the <c>suite/0</c> - function are used. + <p>If <c>timetrap</c> or <c>require</c>, or both, is not set specifically for + a particular test case, default values specified by function + <seealso marker="common_test#Module:suite-0"><c>suite/0</c></seealso> + are used. </p> - <p>Other tags than the ones mentioned above will simply be ignored by - the test server. + <p>Tags other than the earlier mentioned are ignored by the test server. </p> <p> - Example of a test case info function: + An example of a test case information function follows: </p> <pre> - reboot_node() -> - [ - {timetrap,{seconds,60}}, - {require,interfaces}, - {userdata, - [{description,"System Upgrade: RpuAddition Normal RebootNode"}, - {fts,"http://someserver.ericsson.se/test_doc4711.pdf"}]} - ].</pre> + reboot_node() -> + [ + {timetrap,{seconds,60}}, + {require,interfaces}, + {userdata, + [{description,"System Upgrade: RpuAddition Normal RebootNode"}, + {fts,"http://someserver.ericsson.se/test_doc4711.pdf"}]} + ].</pre> </section> <section> <marker id="suite"></marker> - <title>Test suite info function</title> - - <p>The <c>suite/0</c> function can be used in a test suite - module to e.g. set a default <c>timetrap</c> value and to - <c>require</c> external configuration data. If a test case-, or - group info function also specifies any of the info tags, it - overrides the default values set by <c>suite/0</c>. See the test - case info function above, and group info function below, for more - details. + <title>Test Suite Information Function</title> + + <p>Function <seealso marker="common_test#Module:suite-0"><c>suite/0</c></seealso> + can, for example, be used in a test suite module to set a default + <c>timetrap</c> value and to <c>require</c> external configuration data. + If a test case, or a group information function also specifies any of the information tags, it + overrides the default values set by <c>suite/0</c>. For details, + see + <seealso marker="#info_function">Test Case Information Function</seealso> and + <seealso marker="#test_case_groups">Test Case Groups</seealso>. </p> - <p>Other options that may be specified with the suite info list are:</p> - <list> + <p>The following options can also be specified with the suite information list:</p> + <list type="bulleted"> <item><c>stylesheet</c>, - see <seealso marker="run_test_chapter#html_stylesheet">HTML Style Sheets</seealso>.</item> + see <seealso marker="run_test_chapter#html_stylesheet">HTML Style Sheets</seealso></item> <item><c>userdata</c>, - see <seealso marker="#info_function">Test case info function</seealso>.</item> + see <seealso marker="#info_function">Test Case Information Function</seealso></item> <item><c>silent_connections</c>, - see <seealso marker="run_test_chapter#silent_connections">Silent Connections</seealso>.</item> + see <seealso marker="run_test_chapter#silent_connections">Silent Connections</seealso></item> </list> <p> - Example of the suite info function: + An example of the suite information function follows: </p> <pre> - suite() -> - [ - {timetrap,{minutes,10}}, - {require,global_names}, - {userdata,[{info,"This suite tests database transactions."}]}, - {silent_connections,[telnet]}, - {stylesheet,"db_testing.css"} - ].</pre> + suite() -> + [ + {timetrap,{minutes,10}}, + {require,global_names}, + {userdata,[{info,"This suite tests database transactions."}]}, + {silent_connections,[telnet]}, + {stylesheet,"db_testing.css"} + ].</pre> </section> <section> <marker id="test_case_groups"></marker> - <title>Test case groups</title> - <p>A test case group is a set of test cases that share configuration + <title>Test Case Groups</title> + <p>A test case group is a set of test cases sharing configuration functions and execution properties. Test case groups are defined by - means of the <c>groups/0</c> function according to the following syntax:</p> + function + <seealso marker="common_test#Module:groups-0"><c>groups/0</c></seealso> + according to the following syntax:</p> <pre> - groups() -> GroupDefs + groups() -> GroupDefs - Types: + Types: - GroupDefs = [GroupDef] - GroupDef = {GroupName,Properties,GroupsAndTestCases} - GroupName = atom() - GroupsAndTestCases = [GroupDef | {group,GroupName} | TestCase] - TestCase = atom()</pre> + GroupDefs = [GroupDef] + GroupDef = {GroupName,Properties,GroupsAndTestCases} + GroupName = atom() + GroupsAndTestCases = [GroupDef | {group,GroupName} | TestCase] + TestCase = atom()</pre> - <p><c>GroupName</c> is the name of the group and should be unique within - the test suite module. Groups may be nested, and this is accomplished - simply by including a group definition within the <c>GroupsAndTestCases</c> - list of another group. <c>Properties</c> is the list of execution - properties for the group. The possible values are:</p> + <p><c>GroupName</c> is the name of the group and must be unique within + the test suite module. Groups can be nested, by including a group definition + within the <c>GroupsAndTestCases</c> list of another group. + <c>Properties</c> is the list of execution + properties for the group. The possible values are as follows:</p> <pre> - Properties = [parallel | sequence | Shuffle | {RepeatType,N}] - Shuffle = shuffle | {shuffle,Seed} - Seed = {integer(),integer(),integer()} - RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | - repeat_until_any_ok | repeat_until_any_fail - N = integer() | forever</pre> - - <p>If the <c>parallel</c> property is specified, Common Test will execute - all test cases in the group in parallel. If <c>sequence</c> is specified, - the cases will be executed in a sequence, as described in the chapter - <seealso marker="dependencies_chapter#sequences">Dependencies between - test cases and suites</seealso>. If <c>shuffle</c> is specified, the cases - in the group will be executed in random order. The <c>repeat</c> property - orders Common Test to repeat execution of the cases in the group a given - number of times, or until any, or all, cases fail or succeed.</p> - - <p>Example:</p> + Properties = [parallel | sequence | Shuffle | {RepeatType,N}] + Shuffle = shuffle | {shuffle,Seed} + Seed = {integer(),integer(),integer()} + RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | + repeat_until_any_ok | repeat_until_any_fail + N = integer() | forever</pre> + + <p><em>Explanations:</em></p> + <taglist> + <tag><c>parallel</c></tag> + <item><p><c>Common Test</c> executes all test cases in the group in parallel.</p></item> + <tag><c>sequence</c></tag> + <item><p>The cases are executed in a sequence as described in section + <seealso marker="dependencies_chapter#sequences">Sequences</seealso> in section + Dependencies Between Test Cases and Suites.</p></item> + <tag><c>shuffle</c></tag> + <item><p>The cases in the group are executed in random order.</p></item> + <tag><c>repeat</c></tag> + <item><p>Orders <c>Common Test</c> to repeat execution of the cases in the + group a given number of times, or until any, or all, cases fail or succeed.</p></item> + </taglist> + + <p><em>Example:</em></p> <pre> - groups() -> [{group1, [parallel], [test1a,test1b]}, - {group2, [shuffle,sequence], [test2a,test2b,test2c]}].</pre> + groups() -> [{group1, [parallel], [test1a,test1b]}, + {group2, [shuffle,sequence], [test2a,test2b,test2c]}].</pre> - <p>To specify in which order groups should be executed (also with respect - to test cases that are not part of any group), tuples on the form - <c>{group,GroupName}</c> should be added to the <c>all/0</c> list. Example:</p> + <p>To specify in which order groups are to be executed (also with respect + to test cases that are not part of any group), add tuples on the form + <c>{group,GroupName}</c> to the <c>all/0</c> list.</p> + <p><em>Example:</em></p> <pre> - all() -> [testcase1, {group,group1}, testcase2, {group,group2}].</pre> + all() -> [testcase1, {group,group1}, testcase2, {group,group2}].</pre> - <p>It is also possible to specify execution properties with a group - tuple in <c>all/0</c>: <c>{group,GroupName,Properties}</c>. These - properties will override those specified in the group definition (see - <c>groups/0</c> above). This way, it's possible to run the same set of tests, + <p>Execution properties with a group tuple in + <c>all/0</c>: <c>{group,GroupName,Properties}</c> can also be specified. + These properties override those specified in the group definition (see + <c>groups/0</c> earlier). This way, the same set of tests can be run, but with different properties, without having to make copies of the group definition in question.</p> - <p>If a group contains sub-groups, the execution properties for these may + <p>If a group contains subgroups, the execution properties for these can also be specified in the group tuple: - <c>{group,GroupName,Properties,SubGroups}</c>, where <c>SubGroups</c> - is a list of tuples, <c>{GroupName,Properties}</c>, or - <c>{GroupName,Properties,SubGroups}</c>, representing the sub-groups. - Any sub-groups defined in <c>group/0</c> for a group, that are not specified - in the <c>SubGroups</c> list, will simply execute with their pre-defined + <c>{group,GroupName,Properties,SubGroups}</c> + Where, <c>SubGroups</c> is a list of tuples, <c>{GroupName,Properties}</c> or + <c>{GroupName,Properties,SubGroups}</c> representing the subgroups. + Any subgroups defined in <c>group/0</c> for a group, that are not specified + in the <c>SubGroups</c> list, executes with their predefined properties.</p> - <p>Example:</p> + <p><em>Example:</em></p> <pre> - groups() -> {tests1, [], [{tests2, [], [t2a,t2b]}, - {tests3, [], [t31,t3b]}]}.</pre> - <p>To execute group 'tests1' twice with different properties for 'tests2' + groups() -> {tests1, [], [{tests2, [], [t2a,t2b]}, + {tests3, [], [t31,t3b]}]}.</pre> + <p>To execute group <c>tests1</c> twice with different properties for <c>tests2</c> each time:</p> <pre> - all() -> - [{group, tests1, default, [{tests2, [parallel]}]}, - {group, tests1, default, [{tests2, [shuffle,{repeat,10}]}]}].</pre> - <p>Note that this is equivalent to this specification:</p> + all() -> + [{group, tests1, default, [{tests2, [parallel]}]}, + {group, tests1, default, [{tests2, [shuffle,{repeat,10}]}]}].</pre> + <p>This is equivalent to the following specification:</p> <pre> - all() -> - [{group, tests1, default, [{tests2, [parallel]}, - {tests3, default}]}, - {group, tests1, default, [{tests2, [shuffle,{repeat,10}]}, - {tests3, default}]}].</pre> - <p>The value <c>default</c> states that the pre-defined properties - should be used.</p> - <p>Here's an example of how to override properties in a scenario + all() -> + [{group, tests1, default, [{tests2, [parallel]}, + {tests3, default}]}, + {group, tests1, default, [{tests2, [shuffle,{repeat,10}]}, + {tests3, default}]}].</pre> + <p>Value <c>default</c> states that the predefined properties + are to be used.</p> + <p>The following example shows how to override properties in a scenario with deeply nested groups:</p> <pre> - groups() -> - [{tests1, [], [{group, tests2}]}, - {tests2, [], [{group, tests3}]}, - {tests3, [{repeat,2}], [t3a,t3b,t3c]}]. - - all() -> - [{group, tests1, default, - [{tests2, default, - [{tests3, [parallel,{repeat,100}]}]}]}].</pre> - - <p>The syntax described above may also be used in Test Specifications - in order to change properties of groups at the time of execution, - without even having to edit the test suite (please see the - <seealso marker="run_test_chapter#test_specifications">Test - Specifications</seealso> chapter for more info).</p> - - <p>As illustrated above, properties may be combined. If e.g. - <c>shuffle</c>, <c>repeat_until_any_fail</c> and <c>sequence</c> - are all specified, the test cases in the group will be executed + groups() -> + [{tests1, [], [{group, tests2}]}, + {tests2, [], [{group, tests3}]}, + {tests3, [{repeat,2}], [t3a,t3b,t3c]}]. + + all() -> + [{group, tests1, default, + [{tests2, default, + [{tests3, [parallel,{repeat,100}]}]}]}].</pre> + + <p>The described syntax can also be used in test specifications + to change group properties at the time of execution, + without having to edit the test suite. For more information, see + section <seealso marker="run_test_chapter#test_specifications">Test + Specifications</seealso> in section Running Tests and Analyzing Results.</p> + + <p>As illustrated, properties can be combined. If, for example, + <c>shuffle</c>, <c>repeat_until_any_fail</c>, and <c>sequence</c> + are all specified, the test cases in the group are executed repeatedly, and in random order, until a test case fails. Then - execution is immediately stopped and the rest of the cases skipped.</p> + execution is immediately stopped and the remaining cases are skipped.</p> <p>Before execution of a group begins, the configuration function - <c>init_per_group(GroupName, Config)</c> is called. The list of tuples - returned from this function is passed to the test cases in the usual - manner by means of the <c>Config</c> argument. <c>init_per_group/2</c> - is meant to be used for initializations common for the test cases in the - group. After execution of the group is finished, the - <c>end_per_group(GroupName, Config</c> function is called. This function - is meant to be used for cleaning up after <c>init_per_group/2</c>.</p> + <seealso marker="common_test#Module:init_per_group-2"><c>init_per_group(GroupName, Config)</c></seealso> + is called. The list of tuples returned from this function is passed to the + test cases in the usual manner by argument <c>Config</c>. + <c>init_per_group/2</c> is meant to be used for initializations common + for the test cases in the group. After execution of the group is finished, function + <seealso marker="common_test#Module:end_per_group-2"><c>end_per_group(GroupName, Config)</c></seealso> + is called. This function is meant to be used for cleaning up after + <c>init_per_group/2</c>.</p> <p>Whenever a group is executed, if <c>init_per_group</c> and - <c>end_per_group</c> do not exist in the suite, Common Test calls + <c>end_per_group</c> do not exist in the suite, <c>Common Test</c> calls dummy functions (with the same names) instead. Output generated by - hook functions will be saved to the log files for these dummies - (see the <seealso marker="ct_hooks_chapter#manipulating">Common Test - Hooks</seealso> chapter for more information). + hook functions are saved to the log files for these dummies. + For more information, see section + <seealso marker="ct_hooks_chapter#manipulating">Manipulating Tests</seealso> + in section Common Test Hooks. </p> <note><p><c>init_per_testcase/2</c> and <c>end_per_testcase/2</c> are always called for each individual test case, no matter if the case belongs to a group or not.</p></note> - <p>The properties for a group is always printed on the top of the HTML log - for <c>init_per_group/2</c>. Also, the total execution time for a group - can be found at the bottom of the log for <c>end_per_group/2</c>.</p> + <p>The properties for a group are always printed in the top of the HTML log + for <c>init_per_group/2</c>. The total execution time for a group is + included at the bottom of the log for <c>end_per_group/2</c>.</p> - <p>Test case groups may be nested so that sets of groups can be + <p>Test case groups can be nested so sets of groups can be configured with the same <c>init_per_group/2</c> and <c>end_per_group/2</c> - functions. Nested groups may be defined by including a group definition, - or a group name reference, in the test case list of another group. Example:</p> + functions. Nested groups can be defined by including a group definition, + or a group name reference, in the test case list of another group.</p> + <p><em>Example:</em></p> <pre> - groups() -> [{group1, [shuffle], [test1a, - {group2, [], [test2a,test2b]}, - test1b]}, - {group3, [], [{group,group4}, - {group,group5}]}, - {group4, [parallel], [test4a,test4b]}, - {group5, [sequence], [test5a,test5b,test5c]}].</pre> - - <p>In the example above, if <c>all/0</c> would return group name references - in this order: <c>[{group,group1},{group,group3}]</c>, the order of the - configuration functions and test cases will be the following (note that + groups() -> [{group1, [shuffle], [test1a, + {group2, [], [test2a,test2b]}, + test1b]}, + {group3, [], [{group,group4}, + {group,group5}]}, + {group4, [parallel], [test4a,test4b]}, + {group5, [sequence], [test5a,test5b,test5c]}].</pre> + + <p>In the previous example, if <c>all/0</c> returns group name references + in the order <c>[{group,group1},{group,group3}]</c>, the order of the + configuration functions and test cases becomes the following (notice that <c>init_per_testcase/2</c> and <c>end_per_testcase/2:</c> are also always called, but not included in this example for simplification):</p> <pre> -- init_per_group(group1, Config) -> Config1 (*) - --- test1a(Config1) - --- init_per_group(group2, Config1) -> Config2 - ---- test2a(Config2), test2b(Config2) - --- end_per_group(group2, Config2) - --- test1b(Config1) - -- end_per_group(group1, Config1) - -- init_per_group(group3, Config) -> Config3 - --- init_per_group(group4, Config3) -> Config4 - ---- test4a(Config4), test4b(Config4) (**) - --- end_per_group(group4, Config4) - --- init_per_group(group5, Config3) -> Config5 - ---- test5a(Config5), test5b(Config5), test5c(Config5) - --- end_per_group(group5, Config5) - -- end_per_group(group3, Config3) - - - (*) The order of test case test1a, test1b and group2 is not actually - defined since group1 has a shuffle property. - - (**) These cases are not executed in order, but in parallel.</pre> - - <p>Properties are not inherited from top level groups to nested - sub-groups. E.g, in the example above, the test cases in <c>group2</c> - will not be executed in random order (which is the property of - <c>group1</c>).</p> + init_per_group(group1, Config) -> Config1 (*) + test1a(Config1) + init_per_group(group2, Config1) -> Config2 + test2a(Config2), test2b(Config2) + end_per_group(group2, Config2) + test1b(Config1) + end_per_group(group1, Config1) + init_per_group(group3, Config) -> Config3 + init_per_group(group4, Config3) -> Config4 + test4a(Config4), test4b(Config4) (**) + end_per_group(group4, Config4) + init_per_group(group5, Config3) -> Config5 + test5a(Config5), test5b(Config5), test5c(Config5) + end_per_group(group5, Config5) + end_per_group(group3, Config3)</pre> + + <p>(*) The order of test case <c>test1a</c>, <c>test1b</c>, and <c>group2</c> is + undefined, as <c>group1</c> has a shuffle property.</p> + <p>(**) These cases are not executed in order, but in parallel.</p> + <p>Properties are not inherited from top-level groups to nested + subgroups. For instance, in the previous example, the test cases in <c>group2</c> + are not executed in random order (which is the property of <c>group1</c>).</p> </section> <section> - <title>The parallel property and nested groups</title> - <p>If a group has a parallel property, its test cases will be spawned - simultaneously and get executed in parallel. A test case is not allowed - to execute in parallel with <c>end_per_group/2</c> however, which means - that the time it takes to execute a parallel group is equal to the + <title>Parallel Property and Nested Groups</title> + <p>If a group has a parallel property, its test cases are spawned + simultaneously and get executed in parallel. However, a test case is not + allowed to execute in parallel with <c>end_per_group/2</c>, which means + that the time to execute a parallel group is equal to the execution time of the slowest test case in the group. A negative side effect of running test cases in parallel is that the HTML summary pages - are not updated with links to the individual test case logs until the - <c>end_per_group/2</c> function for the group has finished.</p> + are not updated with links to the individual test case logs until function + <c>end_per_group/2</c> for the group has finished.</p> - <p>A group nested under a parallel group will start executing in parallel + <p>A group nested under a parallel group starts executing in parallel with previous (parallel) test cases (no matter what properties the nested - group has). Since, however, test cases are never executed in parallel with - <c>init_per_group/2</c> or <c>end_per_group/2</c> of the same group, it's - only after a nested group has finished that any remaining parallel cases - in the previous group get spawned.</p> + group has). However, as test cases are never executed in parallel with + <c>init_per_group/2</c> or <c>end_per_group/2</c> of the same group, it is + only after a nested group has finished that remaining parallel cases + in the previous group become spawned.</p> </section> <section> - <title>Parallel test cases and IO</title> - <p>A parallel test case has a private IO server as its group leader. - (Please see the Erlang Run-Time System Application documentation for - a description of the group leader concept). The - central IO server process that handles the output from regular test - cases and configuration functions, does not respond to IO messages + <title>Parallel Test Cases and I/O</title> + <p>A parallel test case has a private I/O server as its group leader. + (For a description of the group leader concept, see + <seealso marker="erts:index"><c>ERTS</c></seealso>). + The central I/O server process, which handles the output from + regular test cases and configuration functions, does not respond to I/O messages during execution of parallel groups. This is important to understand - in order to avoid certain traps, like this one:</p> - <p>If a process, <c>P</c>, is spawned during execution of e.g. - <c>init_per_suite/1</c>, it will inherit the group leader of the - <c>init_per_suite</c> process. This group leader is the central IO server - process mentioned above. If, at a later time, <em>during parallel test case + to avoid certain traps, like the following:</p> + <p>If a process, <c>P</c>, is spawned during execution of, for example, + <c>init_per_suite/1</c>, it inherits the group leader of the + <c>init_per_suite</c> process. This group leader is the central I/O server + process mentioned earlier. If, at a later time, <em>during parallel test case execution</em>, some event triggers process <c>P</c> to call - <c>io:format/1/2</c>, that call will never return (since the group leader - is in a non-responsive state) and cause <c>P</c> to hang. + <c>io:format/1/2</c>, that call never returns (as the group leader + is in a non-responsive state) and causes <c>P</c> to hang. </p> </section> <section> - <title>Repeated groups</title> + <title>Repeated Groups</title> <marker id="repeated_groups"></marker> - <p>A test case group may be repeated a certain number of times + <p>A test case group can be repeated a certain number of times (specified by an integer) or indefinitely (specified by <c>forever</c>). - The repetition may also be stopped prematurely if any or all cases - fail or succeed, i.e. if the property <c>repeat_until_any_fail</c>, + The repetition can also be stopped too early if any or all cases + fail or succeed, that is, if any of the properties <c>repeat_until_any_fail</c>, <c>repeat_until_any_ok</c>, <c>repeat_until_all_fail</c>, or <c>repeat_until_all_ok</c> is used. If the basic <c>repeat</c> property is used, status of test cases is irrelevant for the repeat operation.</p> - <p>It is possible to return the status of a sub-group (ok or - failed), to affect the execution of the group on the level above. + <p>The status of a subgroup can be returned (<c>ok</c> or + <c>failed</c>), to affect the execution of the group on the level above. This is accomplished by, in <c>end_per_group/2</c>, looking up the value of <c>tc_group_properties</c> in the <c>Config</c> list and checking the - result of the test cases in the group. If status <c>failed</c> should be - returned from the group as a result, <c>end_per_group/2</c> should return - the value <c>{return_group_result,failed}</c>. The status of a sub-group - is taken into account by Common Test when evaluating if execution of a - group should be repeated or not (unless the basic <c>repeat</c> + result of the test cases in the group. If status <c>failed</c> is to be + returned from the group as a result, <c>end_per_group/2</c> is to return + the value <c>{return_group_result,failed}</c>. The status of a subgroup + is taken into account by <c>Common Test</c> when evaluating if execution of a + group is to be repeated or not (unless the basic <c>repeat</c> property is used).</p> - <p>The <c>tc_group_properties</c> value is a list of status tuples, - each with the key <c>ok</c>, <c>skipped</c> and <c>failed</c>. The - value of a status tuple is a list containing names of test cases + <p>The value of <c>tc_group_properties</c> is a list of status tuples, + each with the key <c>ok</c>, <c>skipped</c>, and <c>failed</c>. The + value of a status tuple is a list with names of test cases that have been executed with the corresponding status as result.</p> - <p>Here's an example of how to return the status from a group:</p> + <p>The following is an example of how to return the status from a group:</p> <pre> - end_per_group(_Group, Config) -> - Status = ?config(tc_group_result, Config), - case proplists:get_value(failed, Status) of - [] -> % no failed cases - {return_group_result,ok}; - _Failed -> % one or more failed - {return_group_result,failed} - end.</pre> - - <p>It is also possible in <c>end_per_group/2</c> to check the status of - a sub-group (maybe to determine what status the current group should also - return). This is as simple as illustrated in the example above, only the - name of the group is stored in a tuple <c>{group_result,GroupName}</c>, - which can be searched for in the status lists. Example:</p> + end_per_group(_Group, Config) -> + Status = ?config(tc_group_result, Config), + case proplists:get_value(failed, Status) of + [] -> % no failed cases + {return_group_result,ok}; + _Failed -> % one or more failed + {return_group_result,failed} + end.</pre> + + <p>It is also possible, in <c>end_per_group/2</c>, to check the status of + a subgroup (maybe to determine what status the current group is to + return). This is as simple as illustrated in the previous example, only the + group name is stored in a tuple <c>{group_result,GroupName}</c>, + which can be searched for in the status lists.</p> + <p><em>Example:</em></p> <pre> - end_per_group(group1, Config) -> - Status = ?config(tc_group_result, Config), - Failed = proplists:get_value(failed, Status), - case lists:member({group_result,group2}, Failed) of - true -> - {return_group_result,failed}; - false -> - {return_group_result,ok} - end; - ...</pre> + end_per_group(group1, Config) -> + Status = ?config(tc_group_result, Config), + Failed = proplists:get_value(failed, Status), + case lists:member({group_result,group2}, Failed) of + true -> + {return_group_result,failed}; + false -> + {return_group_result,ok} + end; + ...</pre> <note><p>When a test case group is repeated, the configuration - functions, <c>init_per_group/2</c> and <c>end_per_group/2</c>, are + functions <c>init_per_group/2</c> and <c>end_per_group/2</c> are also always called with each repetition.</p></note> </section> <section> - <title>Shuffled test case order</title> - <p>The order that test cases in a group are executed, is under normal + <title>Shuffled Test Case Order</title> + <p>The order in which test cases in a group are executed is under normal circumstances the same as the order specified in the test case list - in the group definition. With the <c>shuffle</c> property set, however, - Common Test will instead execute the test cases in random order.</p> + in the group definition. With property <c>shuffle</c> set, however, + <c>Common Test</c> instead executes the test cases in random order.</p> - <p>The user may provide a seed value (a tuple of three integers) with - the shuffle property: <c>{shuffle,Seed}</c>. This way, the same shuffling + <p>You can provide a seed value (a tuple of three integers) with + the shuffle property <c>{shuffle,Seed}</c>. This way, the same shuffling order can be created every time the group is executed. If no seed value - is given, Common Test creates a "random" seed for the shuffling operation - (using the return value of <c>erlang:now()</c>). The seed value is always + is specified, <c>Common Test</c> creates a "random" seed for the shuffling operation + (using the return value of <c>erlang:timestamp/0</c>). The seed value is always printed to the <c>init_per_group/2</c> log file so that it can be used to recreate the same execution order in a subsequent test run.</p> - <note><p>If a shuffled test case group is repeated, the seed will not - be reset in between turns.</p></note> + <note><p>If a shuffled test case group is repeated, the seed is not + reset between turns.</p></note> - <p>If a sub-group is specified in a group with a <c>shuffle</c> property, - the execution order of this sub-group in relation to the test cases - (and other sub-groups) in the group, is also random. The order of the - test cases in the sub-group is however not random (unless, of course, the - sub-group also has a <c>shuffle</c> property).</p> + <p>If a subgroup is specified in a group with a <c>shuffle</c> property, + the execution order of this subgroup in relation to the test cases + (and other subgroups) in the group, is random. The order of the + test cases in the subgroup is however not random (unless the + subgroup has a <c>shuffle</c> property).</p> </section> <section> <marker id="group_info"></marker> - <title>Group info function</title> + <title>Group Information Function</title> - <p>The test case group info function, <c>group(GroupName)</c>, - serves the same purpose as the suite- and test case info - functions previously described in this chapter. The scope for - the group info, however, is all test cases and sub-groups in the + <p>The test case group information function, <c>group(GroupName)</c>, + serves the same purpose as the suite- and test case information + functions previously described. However, the scope for + the group information function, is all test cases and subgroups in the group in question (<c>GroupName</c>).</p> - <p>Example:</p> + <p><em>Example:</em></p> <pre> - group(connection_tests) -> - [{require,login_data}, - {timetrap,1000}].</pre> + group(connection_tests) -> + [{require,login_data}, + {timetrap,1000}].</pre> - <p>The group info properties override those set with the - suite info function, and may in turn be overridden by test - case info properties. Please see the test case info - function above for a list of valid info properties and more - general information.</p> + <p>The group information properties override those set with the + suite information function, and can in turn be overridden by test + case information properties. For a list of valid information properties + and more general information, see the + <seealso marker="#info_function">Test Case Information Function</seealso>. + </p> </section> <section> - <title>Info functions for init- and end-configuration</title> - <p>It is possible to use info functions also for the <c>init_per_suite</c>, - <c>end_per_suite</c>, <c>init_per_group</c>, and <c>end_per_group</c> - functions, and it works the same way as with info functions - for test cases (see above). This is useful e.g. for setting - timetraps and requiring external configuration data relevant - only for the configuration function in question (without - affecting properties set for groups and test cases in the suite).</p> - - <p>The info function <c>init/end_per_suite()</c> is called for - <c>init/end_per_suite(Config)</c>, and info function + <title>Information Functions for Init- and End-Configuration</title> + <p>Information functions can also be used for functions <c>init_per_suite</c>, + <c>end_per_suite</c>, <c>init_per_group</c>, and <c>end_per_group</c>, + and they work the same way as with the + <seealso marker="#info_function">Test Case Information Function</seealso>. + This is useful, for example, for setting timetraps and requiring + external configuration data relevant only for the configuration + function in question (without affecting properties set for groups + and test cases in the suite).</p> + + <p>The information function <c>init/end_per_suite()</c> is called for + <c>init/end_per_suite(Config)</c>, and information function <c>init/end_per_group(GroupName)</c> is called for - <c>init/end_per_group(GroupName,Config)</c>. Info functions - can not be used with <c>init/end_per_testcase(TestCase, Config)</c>, - however, since these configuration functions execute on the test case process - and will use the same properties as the test case (i.e. the properties - set by the test case info function, <c>TestCase()</c>). Please see the test case - info function above for a list of valid info properties and more - general information. + <c>init/end_per_group(GroupName,Config)</c>. However, information functions + cannot be used with <c>init/end_per_testcase(TestCase, Config)</c>, + as these configuration functions execute on the test case process + and use the same properties as the test case (that is, the properties + set by the test case information function, <c>TestCase()</c>). For a list + of valid information properties and more general information, see the + <seealso marker="#info_function">Test Case Information Function</seealso>. </p> </section> @@ -789,77 +805,67 @@ <marker id="data_priv_dir"></marker> <title>Data and Private Directories</title> - <p>The data directory, <c>data_dir</c>, is the directory where the - test module has its own files needed for the testing. The name - of the <c>data_dir</c> is the the name of the test suite followed - by <c>"_data"</c>. For example, - <c>"some_path/foo_SUITE.beam"</c> has the data directory + <p>In the data directory, <c>data_dir</c>, the test module has + its own files needed for the testing. The name of <c>data_dir</c> + is the the name of the test suite followed by <c>"_data"</c>. + For example, <c>"some_path/foo_SUITE.beam"</c> has the data directory <c>"some_path/foo_SUITE_data/"</c>. Use this directory for portability, - i.e. to avoid hardcoding directory names in your suite. Since the data - directory is stored in the same directory as your test suite, you should - be able to rely on its existence at runtime, even if the path to your + that is, to avoid hardcoding directory names in your suite. As the data + directory is stored in the same directory as your test suite, you can + rely on its existence at runtime, even if the path to your test suite directory has changed between test suite implementation and execution. </p> - -<!-- - <p> - When using the Common Test framework <c>ct</c>, automatic - compilation of code in the data directory can be obtained by - placing a makefile source called Makefile.src in the data - directory. Makefile.src will be converted to a valid makefile by - <c>ct</c> when the test suite is run. See the reference manual for - the <c>ct</c> module for details about the syntax of Makefile.src. - </p> ---> <p> <c>priv_dir</c> is the private directory for the test cases. - This directory may be used whenever a test case (or configuration function) + This directory can be used whenever a test case (or configuration function) needs to write something to file. The name of the private directory is - generated by Common Test, which also creates the directory. + generated by <c>Common Test</c>, which also creates the directory. </p> - <p>By default, Common Test creates one central private directory - per test run that all test cases share. This may not always be suitable, - especially if the same test cases are executed multiple times during - a test run (e.g. if they belong to a test case group with repeat - property), and there's a risk that files in the private directory get - overwritten. Under these circumstances, it's possible to configure - Common Test to create one dedicated private directory per - test case and execution instead. This is accomplished by means of - the flag/option: <c>create_priv_dir</c> (to be used with the - <c>ct_run</c> program, the <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso> function, or + <p>By default, <c>Common Test</c> creates one central private directory + per test run, shared by all test cases. This is not always suitable. + Especially if the same test cases are executed multiple times during + a test run (that is, if they belong to a test case group with property + <c>repeat</c>) and there is a risk that files in the private directory get + overwritten. Under these circumstances, <c>Common Test</c> can be + configured to create one dedicated private directory per + test case and execution instead. This is accomplished with + the flag/option <c>create_priv_dir</c> (to be used with the + <seealso marker="ct_run"><c>ct_run</c></seealso> program, the + <seealso marker="ct#run_test-1"><c>ct:run_test/1</c></seealso> function, or as test specification term). There are three possible values - for this option: + for this option as follows: </p> - <list> + <list type="bulleted"> <item><c>auto_per_run</c></item> <item><c>auto_per_tc</c></item> <item><c>manual_per_tc</c></item> </list> <p> - The first value indicates the default priv_dir behaviour, i.e. + The first value indicates the default <c>priv_dir</c> behavior, that is, one private directory created per test run. The two latter - values tell Common Test to generate a unique test directory name + values tell <c>Common Test</c> to generate a unique test directory name per test case and execution. If the auto version is used, <em>all</em> - private directories will be created automatically. This can obviously - become very inefficient for test runs with many test cases and/or - repetitions. Therefore, in case the manual version is instead used, the - test case must tell Common Test to create priv_dir when it needs it. - It does this by calling the function <seealso marker="ct#make_priv_dir-0"><c>ct:make_priv_dir/0</c></seealso>. + private directories are created automatically. This can become very + inefficient for test runs with many test cases or repetitions, or both. + Therefore, if the manual version is used instead, the test case must tell + <c>Common Test</c> to create <c>priv_dir</c> when it needs it. + It does this by calling the function + <seealso marker="ct#make_priv_dir-0"><c>ct:make_priv_dir/0</c></seealso>. </p> - <note><p>You should not depend on current working directory for - reading and writing data files since this is not portable. All + <note><p>Do not depend on the current working directory for + reading and writing data files, as this is not portable. All scratch files are to be written in the <c>priv_dir</c> and all - data files should be located in <c>data_dir</c>. Note also that - the Common Test server sets current working directory to the test case - log directory at the start of every case. + data files are to be located in <c>data_dir</c>. Also, + the <c>Common Test</c> server sets the current working directory to + the test case log directory at the start of every case. </p></note> </section> <section> - <title>Execution environment</title> + <title>Execution Environment</title> <p>Each test case is executed by a dedicated Erlang process. The process is spawned when the test case starts, and terminated when @@ -876,236 +882,263 @@ <section> <marker id="timetraps"></marker> - <title>Timetrap timeouts</title> + <title>Timetrap Time-Outs</title> <p>The default time limit for a test case is 30 minutes, unless a <c>timetrap</c> is specified either by the suite-, group-, - or test case info function. The timetrap timeout value defined by - <c>suite/0</c> is the value that will be used for each test case - in the suite (as well as for the configuration functions + or test case information function. The timetrap time-out value defined by + <c>suite/0</c> is the value that is used for each test case + in the suite (and for the configuration functions <c>init_per_suite/1</c>, <c>end_per_suite/1</c>, <c>init_per_group/2</c>, and <c>end_per_group/2</c>). A timetrap value defined by <c>group(GroupName)</c> overrides one defined by <c>suite()</c> - and will be used for each test case in group <c>GroupName</c>, and any - of its sub-groups. If a timetrap value is defined by <c>group/1</c> - for a sub-group, it overrides that of its higher level groups. Timetrap - values set by individual test cases (by means of the test case info + and is used for each test case in group <c>GroupName</c>, and any + of its subgroups. If a timetrap value is defined by <c>group/1</c> + for a subgroup, it overrides that of its higher level groups. Timetrap + values set by individual test cases (by the test case information function) override both group- and suite- level timetraps.</p> - <p>It is also possible to dynamically set/reset a timetrap during the - excution of a test case, or configuration function. This is done by calling - <seealso marker="ct#timetrap-1"><c>ct:timetrap/1</c></seealso>. This function cancels the current timetrap - and starts a new one (that stays active until timeout, or end of the - current function).</p> + <p>A timetrap can also be set or reset dynamically during the + execution of a test case, or configuration function. + This is done by calling + <seealso marker="ct#timetrap-1"><c>ct:timetrap/1</c></seealso>. + This function cancels the current timetrap and starts a new one + (that stays active until time-out, or end of the current function).</p> <p>Timetrap values can be extended with a multiplier value specified at - startup with the <c>multiply_timetraps</c> option. It is also possible - to let the test server decide to scale up timetrap timeout values - automatically, e.g. if tools such as cover or trace are running during - the test. This feature is disabled by default and can be enabled with - the <c>scale_timetraps</c> start option.</p> + startup with option <c>multiply_timetraps</c>. It is also possible + to let the test server decide to scale up timetrap time-out values + automatically. That is, if tools such as <c>cover</c> or <c>trace</c> + are running during the test. This feature is disabled by default and + can be enabled with start option <c>scale_timetraps</c>.</p> <p>If a test case needs to suspend itself for a time that also gets multipled by <c>multiply_timetraps</c> (and possibly also scaled up if - <c>scale_timetraps</c> is enabled), the function <seealso marker="ct#sleep-1"><c>ct:sleep/1</c></seealso> - may be used (instead of e.g. <c>timer:sleep/1</c>).</p> + <c>scale_timetraps</c> is enabled), the function + <seealso marker="ct#sleep-1"><c>ct:sleep/1</c></seealso> + can be used (instead of, for example, <c>timer:sleep/1</c>).</p> - <p>A function (<c>fun/0</c> or <c>MFA</c>) may be specified as - timetrap value in the suite-, group- and test case info function, as - well as argument to the <seealso marker="ct#timetrap-1"><c>ct:timetrap/1</c></seealso> function. Examples:</p> + <p>A function (<c>fun/0</c> or <c>{Mod,Func,Args}</c> (MFA) tuple) can be + specified as timetrap value in the suite-, group- and test case information + function, and as argument to function + <seealso marker="ct#timetrap-1"><c>ct:timetrap/1</c></seealso>.</p> + <p><em>Examples:</em></p> <p><c>{timetrap,{my_test_utils,timetrap,[?MODULE,system_start]}}</c></p> <p><c>ct:timetrap(fun() -> my_timetrap(TestCaseName, Config) end)</c></p> - <p>The user timetrap function may be used for two things:</p> - <list> - <item>To act as a timetrap - the timeout is triggered when the + <p>The user timetrap function can be used for two things as follows:</p> + <list type="bulleted"> + <item>To act as a timetrap. The time-out is triggered when the function returns.</item> <item>To return a timetrap time value (other than a function).</item> </list> <p>Before execution of the timetrap function (which is performed - on a parallel, dedicated timetrap process), Common Test cancels + on a parallel, dedicated timetrap process), <c>Common Test</c> cancels any previously set timer for the test case or configuration function. - When the timetrap function returns, the timeout is triggered, <em>unless</em> + When the timetrap function returns, the time-out is triggered, <em>unless</em> the return value is a valid timetrap time, such as an integer, - or a <c>{SecMinOrHourTag,Time}</c> tuple (see the - <seealso marker="common_test">common_test reference manual</seealso> for - details). If a time value is returned, a new timetrap is started - to generate a timeout after the specified time.</p> + or a <c>{SecMinOrHourTag,Time}</c> tuple (for details, see module + <seealso marker="common_test">common_test</seealso>). If a time value + is returned, a new timetrap is started to generate a time-out after + the specified time.</p> - <p>The user timetrap function may of course return a time value after a delay, - and if so, the effective timetrap time is the delay time <em>plus</em> the + <p>The user timetrap function can return a time value after a delay. + The effective timetrap time is then the delay time <em>plus</em> the returned time.</p> </section> <section> <marker id="logging"></marker> - <title>Logging - categories and verbosity levels</title> - <p>Common Test provides three main functions for printing strings:</p> - <list> - <item><c>ct:log(Category, Importance, Format, Args)</c></item> - <item><c>ct:print(Category, Importance, Format, Args)</c></item> - <item><c>ct:pal(Category, Importance, Format, Args)</c></item> + <title>Logging - Categories and Verbosity Levels</title> + <p><c>Common Test</c> provides the following three main functions for + printing strings:</p> + <list type="bulleted"> + <item><c>ct:log(Category, Importance, Format, FormatArgs, Opts)</c></item> + <item><c>ct:print(Category, Importance, Format, FormatArgs)</c></item> + <item><c>ct:pal(Category, Importance, Format, FormatArgs)</c></item> </list> - <p>The <c>log/1/2/3/4</c> function will print a string to the test case - log file. The <c>print/1/2/3/4</c> function will print the string to screen, - and the <c>pal/1/2/3/4</c> function will print the same string both to file and - screen. (The functions are documented in the <c>ct</c> reference manual).</p> - - <p>The optional <c>Category</c> argument may be used to categorize the - log printout, and categories can be used for two things:</p> - <list> + <p>The <seealso marker="ct#log-1"><c>log/1,2,3,4,5</c></seealso> function + prints a string to the test case log file. + The <seealso marker="ct#print-1"><c>print/1,2,3,4</c></seealso> function + prints the string to screen. + The <seealso marker="ct#pal-1"><c>pal/1,2,3,4</c></seealso> function + prints the same string both to file and screen. The functions are described + in module <seealso marker="ct">ct</seealso>. + </p> + + <p>The optional <c>Category</c> argument can be used to categorize the + log printout. Categories can be used for two things as follows:</p> + <list type="bulleted"> <item>To compare the importance of the printout to a specific - verbosity level, and</item> - <item>to format the printout according to a user specific HTML + verbosity level.</item> + <item>To format the printout according to a user-specific HTML Style Sheet (CSS).</item> </list> - <p>The <c>Importance</c> argument specifies a level of importance - which, compared to a verbosity level (general and/or set per category), - determines if the printout should be visible or not. <c>Importance</c> - is an arbitrary integer in the range 0..99. Pre-defined constants + <p>Argument <c>Importance</c> specifies a level of importance + that, compared to a verbosity level (general and/or set per category), + determines if the printout is to be visible. <c>Importance</c> + is any integer in the range 0..99. Predefined constants exist in the <c>ct.hrl</c> header file. The default importance level, - <c>?STD_IMPORTANCE</c> (used if the <c>Importance</c> argument is not - provided), is 50. This is also the importance used for standard IO, e.g. - from printouts made with <c>io:format/2</c>, <c>io:put_chars/1</c>, etc.</p> + <c>?STD_IMPORTANCE</c> (used if argument <c>Importance</c> is not + provided), is 50. This is also the importance used for standard I/O, + for example, from printouts made with <c>io:format/2</c>, + <c>io:put_chars/1</c>, and so on.</p> - <p><c>Importance</c> is compared to a verbosity level set by means of the + <p><c>Importance</c> is compared to a verbosity level set by the <c>verbosity</c> start flag/option. The verbosity level can be set per - category and/or generally. The default verbosity level, <c>?STD_VERBOSITY</c>, - is 50, i.e. all standard IO gets printed. If a lower verbosity level is set, - standard IO printouts will be ignored. Common Test performs the following test:</p> - <pre>Importance >= (100-VerbosityLevel)</pre> + category or generally, or both. The default verbosity level, + <c>?STD_VERBOSITY</c>, is 50, that is, all standard I/O gets printed. + If a lower verbosity level is set, standard I/O printouts are ignored. + <c>Common Test</c> performs the following test:</p> + <pre> + Importance >= (100-VerbosityLevel)</pre> <p>This also means that verbosity level 0 effectively turns all logging off - (with the exception of printouts made by Common Test itself).</p> + (except from printouts made by <c>Common Test</c> itself).</p> <p>The general verbosity level is not associated with any particular - category. This level sets the threshold for the standard IO printouts, - uncategorized <c>ct:log/print/pal</c> printouts, as well as + category. This level sets the threshold for the standard I/O printouts, + uncategorized <c>ct:log/print/pal</c> printouts, and printouts for categories with undefined verbosity level.</p> - <p>Example:</p> - <pre> - Some printouts during test case execution: - - io:format("1. Standard IO, importance = ~w~n", [?STD_IMPORTANCE]), - ct:log("2. Uncategorized, importance = ~w", [?STD_IMPORTANCE]), - ct:log(info, "3. Categorized info, importance = ~w", [?STD_IMPORTANCE]]), - ct:log(info, ?LOW_IMPORTANCE, "4. Categorized info, importance = ~w", [?LOW_IMPORTANCE]), - ct:log(error, "5. Categorized error, importance = ~w", [?HI_IMPORTANCE]), - ct:log(error, ?HI_IMPORTANCE, "6. Categorized error, importance = ~w", [?MAX_IMPORTANCE]), - - If starting the test without specifying any verbosity levels: - - $ ct_run ... - - the following gets printed: - - 1. Standard IO, importance = 50 - 2. Uncategorized, importance = 50 - 3. Categorized info, importance = 50 - 5. Categorized error, importance = 75 - 6. Categorized error, importance = 99 - - If starting the test with: - - $ ct_run -verbosity 1 and info 75 - - the following gets printed: - - 3. Categorized info, importance = 50 - 4. Categorized info, importance = 25 - 6. Categorized error, importance = 99</pre> - - <p>How categories can be mapped to CSS tags is documented in the - <seealso marker="run_test_chapter#html_stylesheet">Running Tests</seealso> - chapter.</p> - - <p>The <c>Format</c> and <c>Args</c> arguments in <c>ct:log/print/pal</c> are - always passed on to the <c>io:format/3</c> function in <c>stdlib</c> - (please see the <c>io</c> manual page for details).</p> + <p><em>Examples:</em></p> + <p>Some printouts during test case execution:</p> + <pre> + io:format("1. Standard IO, importance = ~w~n", [?STD_IMPORTANCE]), + ct:log("2. Uncategorized, importance = ~w", [?STD_IMPORTANCE]), + ct:log(info, "3. Categorized info, importance = ~w", [?STD_IMPORTANCE]]), + ct:log(info, ?LOW_IMPORTANCE, "4. Categorized info, importance = ~w", [?LOW_IMPORTANCE]), + ct:log(error, "5. Categorized error, importance = ~w", [?HI_IMPORTANCE]), + ct:log(error, ?HI_IMPORTANCE, "6. Categorized error, importance = ~w", [?MAX_IMPORTANCE]),</pre> + + <p>If starting the test without specifying any verbosity levels as follows:</p> + <pre> + $ ct_run ...</pre> + <p>the following is printed:</p> + <pre> + 1. Standard IO, importance = 50 + 2. Uncategorized, importance = 50 + 3. Categorized info, importance = 50 + 5. Categorized error, importance = 75 + 6. Categorized error, importance = 99</pre> + + <p>If starting the test with:</p> + <pre> + $ ct_run -verbosity 1 and info 75</pre> + <p>the following is printed:</p> + <pre> + 3. Categorized info, importance = 50 + 4. Categorized info, importance = 25 + 6. Categorized error, importance = 99</pre> + + <p>The arguments <c>Format</c> and <c>FormatArgs</c> in <c>ct:log/print/pal</c> are + always passed on to the <c>stdlib</c> function <c>io:format/3</c> (For details, + see the <seealso marker="stdlib:io"><c>stdlib:io</c></seealso> manual page).</p> + + <p><c>ct:pal/4</c> and <c>ct:log/5</c> add headers to strings being printed to the + log file. The strings are also wrapped in div tags with a CSS class + attribute, so that stylesheet formatting can be applied. To disable this feature for + a printout (i.e. to get a result similar to using <c>io:format/2</c>), + call <c>ct:log/5</c> with the <c>no_css</c> option.</p> + + <p>How categories can be mapped to CSS tags is documented in section + <seealso marker="run_test_chapter#html_stylesheet">HTML Style Sheets</seealso> + in section Running Tests and Analyzing Results.</p> - <p>For more information about log files, please see the - <seealso marker="run_test_chapter#log_files">Running Tests</seealso> chapter.</p> + <p>Common Test will escape special HTML characters (<, > and &) in printouts + to the log file made with <c>ct:pal/4</c> and <c>io:format/2</c>. In order to print + strings with HTML tags to the log, use the <c>ct:log/5</c> function. The character escaping + feature is per default disabled for <c>ct:log/5</c>, but can be enabled with the + <c>esc_chars</c> option.</p> + + <p>For more information about log files, see section + <seealso marker="run_test_chapter#log_files">Log Files</seealso> + in section Running Tests and Analyzing Results.</p> </section> <section> - <title>Illegal dependencies</title> + <title>Illegal Dependencies</title> <p>Even though it is highly efficient to write test suites with - the Common Test framework, there will surely be mistakes made, - mainly due to illegal dependencies. Noted below are some of the + the <c>Common Test</c> framework, mistakes can be made, + mainly because of illegal dependencies. Some of the more frequent mistakes from our own experience with running the - Erlang/OTP test suites.</p> + Erlang/OTP test suites follows:</p> - <list> - <item>Depending on current directory, and writing there:<br></br> + <list type="bulleted"> + <item><p>Depending on current directory, and writing there:</p> <p>This is a common error in test suites. It is assumed that - the current directory is the same as what the author used as + the current directory is the same as the author used as current directory when the test case was developed. Many test cases even try to write scratch files to this directory. Instead - <c>data_dir</c> and <c>priv_dir</c> should be used to locate + <c>data_dir</c> and <c>priv_dir</c> are to be used to locate data and for writing scratch files. </p> </item> - <item>Depending on execution order:<br></br> + <item><p>Depending on execution order:</p> - <p>During development of test suites, no assumption should preferrably - be made about the execution order of the test cases or suites. - E.g. a test case should not assume that a server it depends on, - has already been started by a previous test case. There are - several reasons for this: - </p> - <p>Firstly, the user/operator may specify the order at will, and maybe - a different execution order is more relevant or efficient on - some particular occasion. Secondly, if the user specifies a whole - directory of test suites for his/her test, the order the suites are - executed will depend on how the files are listed by the operating - system, which varies between systems. Thirdly, if a user - wishes to run only a subset of a test suite, there is no way - one test case could successfully depend on another. + <p>During development of test suites, make no assumptions on the + execution order of the test cases or suites. For example, a test + case must not assume that a server it depends on is already + started by a previous test case. Reasons for this follows: </p> + <list type="bulleted"> + <item>The user/operator can specify the order at will, and maybe + a different execution order is sometimes more relevant or + efficient.</item> + <item>If the user specifies a whole directory of test suites + for the test, the execution order of the suites depends on + how the files are listed by the operating system, which varies + between systems.</item> + <item>If a user wants to run only a subset of a test suite, + there is no way one test case could successfully depend on + another.</item> + </list> </item> - <item>Depending on Unix:<br></br> + <item><p>Depending on Unix:</p> - <p>Running unix commands through <c>os:cmd</c> are likely - not to work on non-unix platforms. + <p>Running Unix commands through <c>os:cmd</c> are likely + not to work on non-Unix platforms. </p> </item> - <item>Nested test cases:<br></br> + <item><p>Nested test cases:</p> - <p>Invoking a test case from another not only tests the same - thing twice, but also makes it harder to follow what exactly - is being tested. Also, if the called test case fails for some - reason, so will the caller. This way one error gives cause to - several error reports, which is less than ideal. + <p>Starting a test case from another not only tests the same + thing twice, but also makes it harder to follow what is being + tested. Also, if the called test case fails for some + reason, so do the caller. This way, one error gives cause to + several error reports, which is to be avoided. </p> - <p>Functionality common for many test case functions may be implemented - in common help functions. If these functions are useful for test cases - across suites, put the help functions into common help modules. + <p>Functionality common for many test case functions can be + implemented in common help functions. If these functions are + useful for test cases across suites, put the help functions + into common help modules. </p> </item> - <item>Failure to crash or exit when things go wrong:<br></br> + <item><p>Failure to crash or exit when things go wrong:</p> <p>Making requests without checking that the return value - indicates success may be ok if the test case will fail at a - later stage, but it is never acceptable just to print an error - message (into the log file) and return successfully. Such test cases - do harm since they create a false sense of security when overviewing - the test results. + indicates success can be OK if the test case fails + later, but it is never acceptable just to print an error + message (into the log file) and return successfully. Such test + cases do harm, as they create a false sense of security when + overviewing the test results. </p> </item> - <item>Messing up for subsequent test cases:<br></br> + <item><p>Messing up for subsequent test cases:</p> - <p>Test cases should restore as much of the execution - environment as possible, so that the subsequent test cases will - not crash because of execution order of the test cases. - The function <c>end_per_testcase</c> is suitable for this. + <p>Test cases are to restore as much of the execution + environment as possible, so that subsequent test cases + do not crash because of their execution order. + The function + <seealso marker="common_test#Module:end_per_testcase-2"><c>end_per_testcase</c></seealso> + is suitable for this. </p> </item> </list> diff --git a/lib/common_test/src/ct.erl b/lib/common_test/src/ct.erl index 7958a349b4..538be514d6 100644 --- a/lib/common_test/src/ct.erl +++ b/lib/common_test/src/ct.erl @@ -64,7 +64,8 @@ -export([require/1, require/2, get_config/1, get_config/2, get_config/3, reload_config/1, - log/1, log/2, log/3, log/4, + escape_chars/1, escape_chars/2, + log/1, log/2, log/3, log/4, log/5, print/1, print/2, print/3, print/4, pal/1, pal/2, pal/3, pal/4, capture_start/0, capture_stop/0, capture_get/0, capture_get/1, @@ -509,44 +510,88 @@ get_testspec_terms(Tags) -> %%%----------------------------------------------------------------- +%%% @spec escape_chars(IoList1) -> IoList2 | {error,Reason} +%%% IoList1 = iolist() +%%% IoList2 = iolist() +%%% +%%% @doc Escape special characters to be printed in html log +%%% +escape_chars(IoList) -> + ct_logs:escape_chars(IoList). + +%%%----------------------------------------------------------------- +%%% @spec escape_chars(Format, Args) -> IoList | {error,Reason} +%%% Format = string() +%%% Args = list() +%%% +%%% @doc Escape special characters to be printed in html log +%%% +escape_chars(Format, Args) -> + try io_lib:format(Format, Args) of + IoList -> + ct_logs:escape_chars(IoList) + catch + _:Reason -> + {error,Reason} + end. + +%%%----------------------------------------------------------------- %%% @spec log(Format) -> ok -%%% @equiv log(default,50,Format,[]) +%%% @equiv log(default,50,Format,[],[]) log(Format) -> - log(default,?STD_IMPORTANCE,Format,[]). + log(default,?STD_IMPORTANCE,Format,[],[]). %%%----------------------------------------------------------------- %%% @spec log(X1,X2) -> ok %%% X1 = Category | Importance | Format %%% X2 = Format | Args -%%% @equiv log(Category,Importance,Format,Args) +%%% @equiv log(Category,Importance,Format,Args,[]) log(X1,X2) -> {Category,Importance,Format,Args} = if is_atom(X1) -> {X1,?STD_IMPORTANCE,X2,[]}; is_integer(X1) -> {default,X1,X2,[]}; is_list(X1) -> {default,?STD_IMPORTANCE,X1,X2} end, - log(Category,Importance,Format,Args). + log(Category,Importance,Format,Args,[]). %%%----------------------------------------------------------------- %%% @spec log(X1,X2,X3) -> ok +%%% X1 = Category | Importance | Format +%%% X2 = Importance | Format | Args +%%% X3 = Format | Args | Opts +%%% @equiv log(Category,Importance,Format,Args,Opts) +log(X1,X2,X3) -> + {Category,Importance,Format,Args,Opts} = + if is_atom(X1), is_integer(X2) -> {X1,X2,X3,[],[]}; + is_atom(X1), is_list(X2) -> {X1,?STD_IMPORTANCE,X2,X3,[]}; + is_integer(X1) -> {default,X1,X2,X3,[]}; + is_list(X1), is_list(X2) -> {default,?STD_IMPORTANCE,X1,X2,X3} + end, + log(Category,Importance,Format,Args,Opts). + +%%%----------------------------------------------------------------- +%%% @spec log(X1,X2,X3,X4) -> ok %%% X1 = Category | Importance %%% X2 = Importance | Format %%% X3 = Format | Args -%%% @equiv log(Category,Importance,Format,Args) -log(X1,X2,X3) -> - {Category,Importance,Format,Args} = - if is_atom(X1), is_integer(X2) -> {X1,X2,X3,[]}; - is_atom(X1), is_list(X2) -> {X1,?STD_IMPORTANCE,X2,X3}; - is_integer(X1) -> {default,X1,X2,X3} +%%% X4 = Args | Opts +%%% @equiv log(Category,Importance,Format,Args,Opts) +log(X1,X2,X3,X4) -> + {Category,Importance,Format,Args,Opts} = + if is_atom(X1), is_integer(X2) -> {X1,X2,X3,X4,[]}; + is_atom(X1), is_list(X2) -> {X1,?STD_IMPORTANCE,X2,X3,X4}; + is_integer(X1) -> {default,X1,X2,X3,X4} end, - log(Category,Importance,Format,Args). + log(Category,Importance,Format,Args,Opts). %%%----------------------------------------------------------------- -%%% @spec log(Category,Importance,Format,Args) -> ok +%%% @spec log(Category,Importance,Format,Args,Opts) -> ok %%% Category = atom() %%% Importance = integer() %%% Format = string() %%% Args = list() +%%% Opts = [Opt] +%%% Opt = esc_chars | no_css %%% %%% @doc Printout from a test case to the log file. %%% @@ -558,8 +603,8 @@ log(X1,X2,X3) -> %%% and default value for <c>Args</c> is <c>[]</c>.</p> %%% <p>Please see the User's Guide for details on <c>Category</c> %%% and <c>Importance</c>.</p> -log(Category,Importance,Format,Args) -> - ct_logs:tc_log(Category,Importance,Format,Args). +log(Category,Importance,Format,Args,Opts) -> + ct_logs:tc_log(Category,Importance,Format,Args,Opts). %%%----------------------------------------------------------------- diff --git a/lib/common_test/src/ct_conn_log_h.erl b/lib/common_test/src/ct_conn_log_h.erl index 93f358462d..034906a3ba 100644 --- a/lib/common_test/src/ct_conn_log_h.erl +++ b/lib/common_test/src/ct_conn_log_h.erl @@ -105,52 +105,62 @@ terminate(_,#state{logs=Logs}) -> %%% Writing reports write_report(_Time,#conn_log{header=false,module=ConnMod}=Info,Data,GL,State) -> case get_log(Info,GL,State) of - {silent,_} -> + {silent,_,_} -> ok; - {LogType,Fd} -> - io:format(Fd,"~n~ts",[format_data(ConnMod,LogType,Data)]) + {LogType,Dest,Fd} -> + Str = if LogType == html, Dest == gl -> ["$tc_html","~n~ts"]; + true -> "~n~ts" + end, + io:format(Fd,Str,[format_data(ConnMod,LogType,Data)]) end; write_report(Time,#conn_log{module=ConnMod}=Info,Data,GL,State) -> case get_log(Info,GL,State) of - {silent,_} -> + {silent,_,_} -> ok; - {LogType,Fd} -> + {LogType,Dest,Fd} -> case format_data(ConnMod,LogType,Data) of [] when Info#conn_log.action==send; Info#conn_log.action==recv -> ok; FormattedData -> - io:format(Fd,"~n~ts~ts~ts",[format_head(ConnMod,LogType,Time), - format_title(LogType,Info), - FormattedData]) + Str = if LogType == html, Dest == gl -> + ["$tc_html","~n~ts~ts~ts"]; + true -> + "~n~ts~ts~ts" + end, + io:format(Fd,Str,[format_head(ConnMod,LogType,Time), + format_title(LogType,Info), + FormattedData]) end end. write_error(Time,#conn_log{module=ConnMod}=Info,Report,GL,State) -> case get_log(Info,GL,State) of - {LogType,_} when LogType==html; LogType==silent -> + {LogType,_,_} when LogType==html; LogType==silent -> %% The error will anyway be written in the html log by the %% sasl error handler, so don't write it again. ok; - {LogType,Fd} -> - io:format(Fd,"~n~ts~ts~ts", - [format_head(ConnMod,LogType,Time," ERROR"), - format_title(LogType,Info), - format_error(LogType,Report)]) + {LogType,Dest,Fd} -> + Str = if LogType == html, Dest == gl -> ["$tc_html","~n~ts~ts~ts"]; + true -> "~n~ts~ts~ts" + end, + io:format(Fd,Str,[format_head(ConnMod,LogType,Time," ERROR"), + format_title(LogType,Info), + format_error(LogType,Report)]) end. get_log(Info,GL,State) -> case proplists:get_value(GL,State#state.logs) of undefined -> - {html,State#state.default_gl}; + {html,gl,State#state.default_gl}; ConnLogs -> case proplists:get_value(Info#conn_log.module,ConnLogs) of {html,_} -> - {html,GL}; + {html,gl,GL}; {LogType,Fds} -> - {LogType,get_fd(Info,Fds)}; + {LogType,file,get_fd(Info,Fds)}; undefined -> - {html,GL} + {html,gl,GL} end end. diff --git a/lib/common_test/src/ct_framework.erl b/lib/common_test/src/ct_framework.erl index 8e25bfece0..19a3a51b88 100644 --- a/lib/common_test/src/ct_framework.erl +++ b/lib/common_test/src/ct_framework.erl @@ -866,13 +866,13 @@ tag(_Other) -> %%% <code>Func</code> in suite <code>Mod</code> crashing. %%% <code>Error</code> specifies the reason for failing. error_notification(Mod,Func,_Args,{Error,Loc}) -> - ErrSpec = case Error of + ErrorSpec = case Error of {What={_E,_R},Trace} when is_list(Trace) -> What; What -> What end, - ErrStr = case ErrSpec of + ErrorStr = case ErrorSpec of {badmatch,Descr} -> Descr1 = lists:flatten(io_lib:format("~P",[Descr,10])), if length(Descr1) > 50 -> @@ -894,7 +894,8 @@ error_notification(Mod,Func,_Args,{Error,Loc}) -> Other -> io_lib:format("~P", [Other,5]) end, - ErrorHtml = "<font color=\"brown\">" ++ ErrStr ++ "</font>", + ErrorHtml = + "<font color=\"brown\">" ++ ct_logs:escape_chars(ErrorStr) ++ "</font>", case {Mod,Error} of %% some notifications come from the main test_server process %% and for these cases the existing comment may not be modified @@ -922,41 +923,43 @@ error_notification(Mod,Func,_Args,{Error,Loc}) -> end end, - PrintErr = fun(ErrFormat, ErrArgs) -> + PrintError = fun(ErrorFormat, ErrorArgs) -> Div = "~n- - - - - - - - - - - - - - - - - - - " "- - - - - - - - - - - - - - - - - - - - -~n", - io:format(user, lists:concat([Div,ErrFormat,Div,"~n"]), - ErrArgs), + ErrorStr2 = io_lib:format(ErrorFormat, ErrorArgs), + io:format(user, lists:concat([Div,ErrorStr2,Div,"~n"]), + []), Link = "\n\n<a href=\"#end\">" "Full error description and stacktrace" "</a>", + ErrorHtml2 = ct_logs:escape_chars(ErrorStr2), ct_logs:tc_log(ct_error_notify, ?MAX_IMPORTANCE, "CT Error Notification", - ErrFormat++Link, ErrArgs) + ErrorHtml2++Link, [], []) end, case Loc of [{?MODULE,error_in_suite}] -> - PrintErr("Error in suite detected: ~ts", [ErrStr]); + PrintError("Error in suite detected: ~ts", [ErrorStr]); R when R == unknown; R == undefined -> - PrintErr("Error detected: ~ts", [ErrStr]); + PrintError("Error detected: ~ts", [ErrorStr]); %% if a function specified by all/0 does not exist, we %% pick up undef here - [{LastMod,LastFunc}|_] when ErrStr == "undef" -> - PrintErr("~w:~w could not be executed~nReason: ~ts", - [LastMod,LastFunc,ErrStr]); + [{LastMod,LastFunc}|_] when ErrorStr == "undef" -> + PrintError("~w:~w could not be executed~nReason: ~ts", + [LastMod,LastFunc,ErrorStr]); [{LastMod,LastFunc}|_] -> - PrintErr("~w:~w failed~nReason: ~ts", [LastMod,LastFunc,ErrStr]); + PrintError("~w:~w failed~nReason: ~ts", [LastMod,LastFunc,ErrorStr]); [{LastMod,LastFunc,LastLine}|_] -> %% print error to console, we are only %% interested in the last executed expression - PrintErr("~w:~w failed on line ~w~nReason: ~ts", - [LastMod,LastFunc,LastLine,ErrStr]), + PrintError("~w:~w failed on line ~w~nReason: ~ts", + [LastMod,LastFunc,LastLine,ErrorStr]), case ct_util:read_suite_data({seq,Mod,Func}) of undefined -> diff --git a/lib/common_test/src/ct_logs.erl b/lib/common_test/src/ct_logs.erl index 78081380e7..4920383f39 100644 --- a/lib/common_test/src/ct_logs.erl +++ b/lib/common_test/src/ct_logs.erl @@ -37,15 +37,17 @@ -export([add_external_logs/1, add_link/3]). -export([make_last_run_index/0]). -export([make_all_suites_index/1,make_all_runs_index/1]). --export([get_ts_html_wrapper/5]). +-export([get_ts_html_wrapper/5, escape_chars/1]). -export([xhtml/2, locate_priv_file/1, make_relative/1]). -export([insert_javascript/1]). -export([uri/1]). %% Logging stuff directly from testcase --export([tc_log/3, tc_log/4, tc_log/5, tc_log_async/3, tc_log_async/5, +-export([tc_log/3, tc_log/4, tc_log/5, tc_log/6, + tc_log_async/3, tc_log_async/5, tc_print/3, tc_print/4, - tc_pal/3, tc_pal/4, ct_log/3, basic_html/0]). + tc_pal/3, tc_pal/4, ct_log/3, + basic_html/0]). %% Simulate logger process for use without ct environment running -export([simulate/0]). @@ -267,7 +269,7 @@ cast(Msg) -> %%% <p>This function is called by ct_framework:init_tc/3</p> init_tc(RefreshLog) -> call({init_tc,self(),group_leader(),RefreshLog}), - io:format(xhtml("", "<br />")), + io:format(["$tc_html",xhtml("", "<br />")]), ok. %%%----------------------------------------------------------------- @@ -314,9 +316,10 @@ unregister_groupleader(Pid) -> %%% data to log (as in <code>io:format(Format,Args)</code>).</p> log(Heading,Format,Args) -> cast({log,sync,self(),group_leader(),ct_internal,?MAX_IMPORTANCE, - [{int_header(),[log_timestamp(?now),Heading]}, + [{hd,int_header(),[log_timestamp(?now),Heading]}, {Format,Args}, - {int_footer(),[]}]}), + {ft,int_footer(),[]}], + true}), ok. %%%----------------------------------------------------------------- @@ -336,7 +339,7 @@ log(Heading,Format,Args) -> %%% @see end_log/0 start_log(Heading) -> cast({log,sync,self(),group_leader(),ct_internal,?MAX_IMPORTANCE, - [{int_header(),[log_timestamp(?now),Heading]}]}), + [{hd,int_header(),[log_timestamp(?now),Heading]}],false}), ok. %%%----------------------------------------------------------------- @@ -351,7 +354,7 @@ cont_log([],[]) -> cont_log(Format,Args) -> maybe_log_timestamp(), cast({log,sync,self(),group_leader(),ct_internal,?MAX_IMPORTANCE, - [{Format,Args}]}), + [{Format,Args}],true}), ok. %%%----------------------------------------------------------------- @@ -363,7 +366,7 @@ cont_log(Format,Args) -> %%% @see cont_log/2 end_log() -> cast({log,sync,self(),group_leader(),ct_internal,?MAX_IMPORTANCE, - [{int_footer(), []}]}), + [{ft,int_footer(), []}],false}), ok. @@ -400,32 +403,46 @@ add_link(Heading,File,Type) -> %%% @spec tc_log(Category,Format,Args) -> ok %%% @equiv tc_log(Category,?STD_IMPORTANCE,Format,Args) tc_log(Category,Format,Args) -> - tc_log(Category,?STD_IMPORTANCE,Format,Args). + tc_log(Category,?STD_IMPORTANCE,"User",Format,Args,[]). %%%----------------------------------------------------------------- %%% @spec tc_log(Category,Importance,Format,Args) -> ok %%% @equiv tc_log(Category,Importance,"User",Format,Args) tc_log(Category,Importance,Format,Args) -> - tc_log(Category,Importance,"User",Format,Args). + tc_log(Category,Importance,"User",Format,Args,[]). %%%----------------------------------------------------------------- -%%% @spec tc_log(Category,Importance,Printer,Format,Args) -> ok +%%% @spec tc_log(Category,Importance,Format,Args) -> ok +%%% @equiv tc_log(Category,Importance,"User",Format,Args) +tc_log(Category,Importance,Format,Args,Opts) -> + tc_log(Category,Importance,"User",Format,Args,Opts). + +%%%----------------------------------------------------------------- +%%% @spec tc_log(Category,Importance,Printer,Format,Args,Opts) -> ok %%% Category = atom() %%% Importance = integer() %%% Printer = string() %%% Format = string() %%% Args = list() +%%% Opts = list() %%% %%% @doc Printout from a testcase. %%% %%% <p>This function is called by <code>ct</code> when logging %%% stuff directly from a testcase (i.e. not from within the CT %%% framework).</p> -tc_log(Category,Importance,Printer,Format,Args) -> - cast({log,sync,self(),group_leader(),Category,Importance, - [{div_header(Category,Printer),[]}, - {Format,Args}, - {div_footer(),[]}]}), +tc_log(Category,Importance,Printer,Format,Args,Opts) -> + Data = + case lists:member(no_css, Opts) of + true -> + [{Format,Args}]; + false -> + [{hd,div_header(Category,Printer),[]}, + {Format,Args}, + {ft,div_footer(),[]}] + end, + cast({log,sync,self(),group_leader(),Category,Importance,Data, + lists:member(esc_chars, Opts)}), ok. %%%----------------------------------------------------------------- @@ -451,9 +468,10 @@ tc_log_async(Category,Format,Args) -> %%% asks ct_logs for an html wrapper.</p> tc_log_async(Category,Importance,Printer,Format,Args) -> cast({log,async,self(),group_leader(),Category,Importance, - [{div_header(Category,Printer),[]}, + [{hd,div_header(Category,Printer),[]}, {Format,Args}, - {div_footer(),[]}]}), + {ft,div_footer(),[]}], + true}), ok. %%%----------------------------------------------------------------- %%% @spec tc_print(Category,Format,Args) @@ -522,43 +540,45 @@ tc_pal(Category,Format,Args) -> tc_pal(Category,Importance,Format,Args) -> tc_print(Category,Importance,Format,Args), cast({log,sync,self(),group_leader(),Category,Importance, - [{div_header(Category),[]}, + [{hd,div_header(Category),[]}, {Format,Args}, - {div_footer(),[]}]}), + {ft,div_footer(),[]}], + true}), ok. %%%----------------------------------------------------------------- -%%% @spec ct_pal(Category,Format,Args) -> ok +%%% @spec ct_log(Category,Format,Args) -> ok %%% Category = atom() %%% Format = string() %%% Args = list() %%% -%%% @doc Print and log to the ct framework log +%%% @doc Print to the ct framework log %%% %%% <p>This function is called by internal ct functions to %%% force logging to the ct framework log</p> ct_log(Category,Format,Args) -> - cast({ct_log,[{div_header(Category),[]}, + cast({ct_log,[{hd,div_header(Category),[]}, {Format,Args}, - {div_footer(),[]}]}), + {ft,div_footer(),[]}], + true}), ok. %%%================================================================= %%% Internal functions int_header() -> - "<div class=\"ct_internal\"><b>*** CT ~s *** ~ts</b>". + "</pre>\n<div class=\"ct_internal\"><pre><b>*** CT ~s *** ~ts</b>". int_footer() -> - "</div>". + "</pre></div>\n<pre>". div_header(Class) -> div_header(Class,"User"). div_header(Class,Printer) -> - "\n<div class=\"" ++ atom_to_list(Class) ++ "\"><b>*** " ++ Printer ++ - " " ++ log_timestamp(?now) ++ " ***</b>". + "\n</pre>\n<div class=\"" ++ atom_to_list(Class) ++ "\"><pre><b>*** " + ++ Printer ++ " " ++ log_timestamp(?now) ++ " ***</b>". div_footer() -> - "</div>". + "</pre></div>\n<pre>". maybe_log_timestamp() -> @@ -568,7 +588,7 @@ maybe_log_timestamp() -> ok; _ -> cast({log,sync,self(),group_leader(),ct_internal,?MAX_IMPORTANCE, - [{"<i>~s</i>",[log_timestamp({MS,S,US})]}]}) + [{hd,"<i>~s</i>",[log_timestamp({MS,S,US})]}],false}) end. log_timestamp({MS,S,US}) -> @@ -729,7 +749,7 @@ copy_priv_files([], []) -> logger_loop(State) -> receive - {log,SyncOrAsync,Pid,GL,Category,Importance,List} -> + {log,SyncOrAsync,Pid,GL,Category,Importance,Content,EscChars} -> VLvl = case Category of ct_internal -> ?MAX_VERBOSITY; @@ -746,15 +766,15 @@ logger_loop(State) -> case erlang:is_process_alive(TCGL) of true -> State1 = print_to_log(SyncOrAsync, Pid, - Category, - TCGL, List, State), + Category, TCGL, Content, + EscChars, State), logger_loop(State1#logger_state{ tc_groupleaders = TCGLs}); false -> %% Group leader is dead, so write to the %% CtLog or unexpected_io log instead - unexpected_io(Pid,Category,Importance, - List,CtLogFd), + unexpected_io(Pid, Category, Importance, + Content, CtLogFd, EscChars), logger_loop(State) end; @@ -762,7 +782,8 @@ logger_loop(State) -> %% If category is ct_internal then write %% to ct_log, else write to unexpected_io %% log - unexpected_io(Pid,Category,Importance,List,CtLogFd), + unexpected_io(Pid, Category, Importance, Content, + CtLogFd, EscChars), logger_loop(State#logger_state{ tc_groupleaders = TCGLs}) end; @@ -818,10 +839,17 @@ logger_loop(State) -> logger_loop(State); {clear_stylesheet,_} -> logger_loop(State#logger_state{stylesheet = undefined}); - {ct_log, List} -> + {ct_log,Content,EscChars} -> + Str = lists:map(fun({_HdOrFt,Str,Args}) -> + [io_lib:format(Str,Args),io_lib:nl()]; + ({Str,Args}) when EscChars -> + Io = io_lib:format(Str,Args), + [escape_chars(Io),io_lib:nl()]; + ({Str,Args}) -> + [io_lib:format(Str,Args),io_lib:nl()] + end, Content), Fd = State#logger_state.ct_log_fd, - [begin io:format(Fd,Str,Args),io:nl(Fd) end || - {Str,Args} <- List], + io:format(Fd, "~ts", [Str]), logger_loop(State); {'DOWN',Ref,_,_Pid,_} -> %% there might be print jobs executing in parallel with ct_logs @@ -843,45 +871,74 @@ logger_loop(State) -> ok end. -create_io_fun(FromPid, CtLogFd) -> +create_io_fun(FromPid, CtLogFd, EscChars) -> %% we have to build one io-list of all strings %% before printing, or other io printouts (made in %% parallel) may get printed between this header %% and footer - fun({Str,Args}, IoList) -> - case catch io_lib:format(Str,Args) of - {'EXIT',_Reason} -> + fun(FormatData, IoList) -> + {Escapable,Str,Args} = + case FormatData of + {_HdOrFt,S,A} -> {false,S,A}; + {S,A} -> {true,S,A} + end, + try io_lib:format(Str,Args) of + IoStr when Escapable, EscChars, IoList == [] -> + escape_chars(IoStr); + IoStr when Escapable, EscChars -> + [IoList,"\n",escape_chars(IoStr)]; + IoStr when IoList == [] -> + IoStr; + IoStr -> + [IoList,"\n",IoStr] + catch + _:_Reason -> io:format(CtLogFd, "Logging fails! Str: ~p, Args: ~p~n", [Str,Args]), %% stop the testcase, we need to see the fault exit(FromPid, {log_printout_error,Str,Args}), - []; - IoStr when IoList == [] -> - [IoStr]; - IoStr -> - [IoList,"\n",IoStr] + [] end end. -print_to_log(sync, FromPid, Category, TCGL, List, State) -> +escape_chars([Bin | Io]) when is_binary(Bin) -> + [Bin | escape_chars(Io)]; +escape_chars([List | Io]) when is_list(List) -> + [escape_chars(List) | escape_chars(Io)]; +escape_chars([$< | Io]) -> + ["<" | escape_chars(Io)]; +escape_chars([$> | Io]) -> + [">" | escape_chars(Io)]; +escape_chars([$& | Io]) -> + ["&" | escape_chars(Io)]; +escape_chars([Char | Io]) when is_integer(Char) -> + [Char | escape_chars(Io)]; +escape_chars([]) -> + []; +escape_chars(Bin) -> + Bin. + +print_to_log(sync, FromPid, Category, TCGL, Content, EscChars, State) -> %% in some situations (exceptions), the printout is made from the %% test server IO process and there's no valid group leader to send to CtLogFd = State#logger_state.ct_log_fd, if FromPid /= TCGL -> - IoFun = create_io_fun(FromPid, CtLogFd), - io:format(TCGL,"~ts", [lists:foldl(IoFun, [], List)]); + IoFun = create_io_fun(FromPid, CtLogFd, EscChars), + IoList = lists:foldl(IoFun, [], Content), + io:format(TCGL,["$tc_html","~ts"], [IoList]); true -> - unexpected_io(FromPid,Category,?MAX_IMPORTANCE,List,CtLogFd) + unexpected_io(FromPid, Category, ?MAX_IMPORTANCE, Content, + CtLogFd, EscChars) end, State; -print_to_log(async, FromPid, Category, TCGL, List, State) -> +print_to_log(async, FromPid, Category, TCGL, Content, EscChars, State) -> %% in some situations (exceptions), the printout is made from the %% test server IO process and there's no valid group leader to send to CtLogFd = State#logger_state.ct_log_fd, Printer = if FromPid /= TCGL -> - IoFun = create_io_fun(FromPid, CtLogFd), + IoFun = create_io_fun(FromPid, CtLogFd, EscChars), fun() -> test_server:permit_io(TCGL, self()), @@ -894,25 +951,25 @@ print_to_log(async, FromPid, Category, TCGL, List, State) -> case erlang:is_process_alive(TCGL) of true -> - try io:format(TCGL, "~ts", - [lists:foldl(IoFun,[],List)]) of + try io:format(TCGL, ["$tc_html","~ts"], + [lists:foldl(IoFun,[],Content)]) of _ -> ok catch _:terminated -> unexpected_io(FromPid, Category, ?MAX_IMPORTANCE, - List, CtLogFd) + Content, CtLogFd, EscChars) end; false -> unexpected_io(FromPid, Category, ?MAX_IMPORTANCE, - List, CtLogFd) + Content, CtLogFd, EscChars) end end; true -> fun() -> unexpected_io(FromPid, Category, ?MAX_IMPORTANCE, - List, CtLogFd) + Content, CtLogFd, EscChars) end end, case State#logger_state.async_print_jobs of @@ -1087,12 +1144,6 @@ print_style(Fd,StyleSheet) -> print_style_error(Fd,StyleSheet,Reason) end. -%% Simple link version, doesn't work with all browsers unfortunately. :-( -%% print_style(Fd, StyleSheet) -> -%% io:format(Fd, -%% "<link href=~p rel=\"stylesheet\" type=\"text/css\">", -%% [StyleSheet]). - print_style_error(Fd,StyleSheet,Reason) -> io:format(Fd,"\n<!-- Failed to load stylesheet ~ts: ~p -->\n", [StyleSheet,Reason]), @@ -1364,11 +1415,11 @@ total_row(Success, Fail, UserSkip, AutoSkip, NotBuilt, All) -> [xhtml("<tr valign=top>\n", ["</tbody>\n<tfoot>\n<tr class=\"",odd_or_even(),"\">\n"]), "<td><b>Total</b></td>\n", Label, TimestampCell, - "<td align=right><b>",integer_to_list(Success),"<b></td>\n", - "<td align=right><b>",integer_to_list(Fail),"<b></td>\n", + "<td align=right><b>",integer_to_list(Success),"</b></td>\n", + "<td align=right><b>",integer_to_list(Fail),"</b></td>\n", "<td align=right>",integer_to_list(AllSkip), " (",UserSkipStr,"/",AutoSkipStr,")</td>\n", - "<td align=right><b>",integer_to_list(NotBuilt),"<b></td>\n", + "<td align=right><b>",integer_to_list(NotBuilt),"</b></td>\n", AllInfo, "</tr>\n", xhtml("","</tfoot>\n")]. @@ -1560,10 +1611,12 @@ header1(Title, SubTitle, TableCols) -> "<!-- autogenerated by '"++atom_to_list(?MODULE)++"' -->\n", "<head>\n", "<title>" ++ Title ++ " " ++ SubTitle ++ "</title>\n", - "<meta http-equiv=\"cache-control\" content=\"no-cache\">\n", - "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n", + "<meta http-equiv=\"cache-control\" content=\"no-cache\"></meta>\n", + "<meta http-equiv=\"content-type\" content=\"text/html; " + "charset=utf-8\"></meta>\n", xhtml("", - ["<link rel=\"stylesheet\" href=\"",uri(CSSFile),"\" type=\"text/css\">\n"]), + ["<link rel=\"stylesheet\" href=\"",uri(CSSFile), + "\" type=\"text/css\"></link>\n"]), xhtml("", ["<script type=\"text/javascript\" src=\"",JQueryFile, "\"></script>\n"]), @@ -1610,7 +1663,7 @@ footer() -> "Copyright © ", year(), " <a href=\"http://www.erlang.org\">Open Telecom Platform</a>", xhtml("<br>\n", "<br />\n"), - "Updated: <!date>", current_time(), "<!/date>", + "Updated: <!--date-->", current_time(), "<!--/date-->", xhtml("<br>\n", "<br />\n"), xhtml("</font></p>\n", "</div>\n"), "</center>\n" @@ -1985,9 +2038,9 @@ interactive_link() -> "<!-- autogenerated by '"++atom_to_list(?MODULE)++"' -->\n", "<head>\n", "<title>Last interactive run</title>\n", - "<meta http-equiv=\"cache-control\" content=\"no-cache\">\n", + "<meta http-equiv=\"cache-control\" content=\"no-cache\"></meta>\n", "<meta http-equiv=\"content-type\" content=\"text/html; " - "charset=utf-8\">\n", + "charset=utf-8\"></meta>\n", "</head>\n", "<body>\n", "Log from last interactive run: <a href=\"",uri(CtLog),"\">", @@ -2846,8 +2899,12 @@ simulate() -> simulate_logger_loop() -> receive - {log,_,_,_,_,_,List} -> - S = [[io_lib:format(Str,Args),io_lib:nl()] || {Str,Args} <- List], + {log,_,_,_,_,_,Content,_} -> + S = lists:map(fun({_,Str,Args}) -> + [io_lib:format(Str,Args),io_lib:nl()]; + ({Str,Args}) -> + [io_lib:format(Str,Args),io_lib:nl()] + end, Content), io:format("~ts",[S]), simulate_logger_loop(); stop -> @@ -3053,15 +3110,15 @@ get_ts_html_wrapper(TestName, Logdir, PrintLabel, Cwd, TableCols, Encoding) -> "Copyright © ", year(), " <a href=\"http://www.erlang.org\">", "Open Telecom Platform</a><br>\n", - "Updated: <!date>", current_time(), "<!/date>", + "Updated: <!--date-->", current_time(), "<!--/date-->", "<br>\n</font></p>\n"], {basic_html, ["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n", "<html>\n", "<head><title>", TestName1, "</title>\n", - "<meta http-equiv=\"cache-control\" content=\"no-cache\">\n", + "<meta http-equiv=\"cache-control\" content=\"no-cache\"></meta>\n", "<meta http-equiv=\"content-type\" content=\"text/html; charset=", - html_encoding(Encoding),"\">\n", + html_encoding(Encoding),"\"></meta>\n", "</head>\n", "<body", Bgr, " bgcolor=\"white\" text=\"black\" ", "link=\"blue\" vlink=\"purple\" alink=\"red\">\n", @@ -3078,7 +3135,7 @@ get_ts_html_wrapper(TestName, Logdir, PrintLabel, Cwd, TableCols, Encoding) -> "Copyright © ", year(), " <a href=\"http://www.erlang.org\">", "Open Telecom Platform</a><br />\n", - "Updated: <!date>", current_time(), "<!/date>", + "Updated: <!--date-->", current_time(), "<!--/date-->", "<br />\n</div>\n"], CSSFile = xhtml(fun() -> "" end, @@ -3105,9 +3162,11 @@ get_ts_html_wrapper(TestName, Logdir, PrintLabel, Cwd, TableCols, Encoding) -> "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n", "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n", "<head>\n<title>", TestName1, "</title>\n", - "<meta http-equiv=\"cache-control\" content=\"no-cache\">\n", - "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n", - "<link rel=\"stylesheet\" href=\"", uri(CSSFile), "\" type=\"text/css\">\n", + "<meta http-equiv=\"cache-control\" content=\"no-cache\"></meta>\n", + "<meta http-equiv=\"content-type\" content=\"text/html; ", + "charset=utf-8\"></meta>\n", + "<link rel=\"stylesheet\" href=\"", uri(CSSFile), + "\" type=\"text/css\"></link>\n", "<script type=\"text/javascript\" src=\"", JQueryFile, "\"></script>\n", "<script type=\"text/javascript\" src=\"", TableSorterFile, "\"></script>\n"] ++ TableSorterScript ++ ["</head>\n","<body>\n", LabelStr, "\n"], @@ -3233,11 +3292,11 @@ html_encoding(latin1) -> html_encoding(utf8) -> "utf-8". -unexpected_io(Pid,ct_internal,_Importance,List,CtLogFd) -> - IoFun = create_io_fun(Pid,CtLogFd), - io:format(CtLogFd, "~ts", [lists:foldl(IoFun, [], List)]); -unexpected_io(Pid,_Category,_Importance,List,CtLogFd) -> - IoFun = create_io_fun(Pid,CtLogFd), - Data = io_lib:format("~ts", [lists:foldl(IoFun, [], List)]), +unexpected_io(Pid, ct_internal, _Importance, Content, CtLogFd, EscChars) -> + IoFun = create_io_fun(Pid, CtLogFd, EscChars), + io:format(CtLogFd, "~ts", [lists:foldl(IoFun, [], Content)]); +unexpected_io(Pid, _Category, _Importance, Content, CtLogFd, EscChars) -> + IoFun = create_io_fun(Pid, CtLogFd, EscChars), + Data = io_lib:format("~ts", [lists:foldl(IoFun, [], Content)]), test_server_io:print_unexpected(Data), ok. diff --git a/lib/common_test/src/ct_master_logs.erl b/lib/common_test/src/ct_master_logs.erl index 2adced42ae..54190a8254 100644 --- a/lib/common_test/src/ct_master_logs.erl +++ b/lib/common_test/src/ct_master_logs.erl @@ -238,9 +238,9 @@ config_table1([]) -> ["</tbody>\n</table>\n"]. int_header() -> - "<div class=\"ct_internal\"><b>*** CT MASTER ~s *** ~ts</b>". + "</pre>\n<div class=\"ct_internal\"><pre><b>*** CT MASTER ~s *** ~ts</b>". int_footer() -> - "</div>". + "</pre></div>\n<pre>". %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% NodeDir Index functions %%% @@ -387,11 +387,12 @@ header(Title, TableCols) -> "<!-- autogenerated by '"++atom_to_list(?MODULE)++"' -->\n", "<head>\n", "<title>" ++ Title ++ "</title>\n", - "<meta http-equiv=\"cache-control\" content=\"no-cache\">\n", - "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n", + "<meta http-equiv=\"cache-control\" content=\"no-cache\"></meta>\n", + "<meta http-equiv=\"content-type\" content=\"text/html; ", + "charset=utf-8\"></meta>\n", xhtml("", ["<link rel=\"stylesheet\" href=\"",ct_logs:uri(CSSFile), - "\" type=\"text/css\">"]), + "\" type=\"text/css\"></link>\n"]), xhtml("", ["<script type=\"text/javascript\" src=\"",JQueryFile, "\"></script>\n"]), @@ -419,7 +420,7 @@ footer() -> "Copyright © ", year(), " <a href=\"http://www.erlang.org\">Open Telecom Platform</a>", xhtml("<br>\n", "<br />\n"), - "Updated: <!date>", current_time(), "<!/date>", + "Updated: <!--date-->", current_time(), "<--!/date-->", xhtml("<br>\n", "<br />\n"), xhtml("</font></p>\n", "</div>\n"), "</center>\n" diff --git a/lib/common_test/src/ct_release_test.erl b/lib/common_test/src/ct_release_test.erl index c4cbe0c424..6c38f51363 100644 --- a/lib/common_test/src/ct_release_test.erl +++ b/lib/common_test/src/ct_release_test.erl @@ -131,7 +131,7 @@ -include_lib("kernel/include/file.hrl"). %%----------------------------------------------------------------- --define(testnode, otp_upgrade). +-define(testnode, 'ct_release_test-upgrade'). -define(exclude_apps, [hipe, typer, dialyzer]). % never include these apps %%----------------------------------------------------------------- @@ -304,7 +304,13 @@ upgrade(Apps,Level,Callback,Config) -> %% Note, we will not reach this if the test fails with a %% timetrap timeout in the test suite! Thus we can have %% hanging nodes... - Nodes = nodes(), + Nodes = lists:filter(fun(Node) -> + case atom_to_list(Node) of + "ct_release_test-" ++_ -> true; + _ -> false + end + end, + nodes()), [rpc:call(Node,erlang,halt,[]) || Node <- Nodes] end. @@ -328,7 +334,14 @@ upgrade(Apps,Level,Callback,Config) -> %% ct_release_test:cleanup(Config).''' %% cleanup(Config) -> - Nodes = [node_name(?testnode)|nodes()], + AllNodes = [node_name(?testnode)|nodes()], + Nodes = lists:filter(fun(Node) -> + case atom_to_list(Node) of + "ct_release_test-" ++_ -> true; + _ -> false + end + end, + AllNodes), [rpc:call(Node,erlang,halt,[]) || Node <- Nodes], Config. @@ -455,9 +468,9 @@ get_rels(minor) -> {CurrentMajor,Current}. init_upgrade_test(FromVsn,ToVsn,OldRel) -> - OtpRel = list_to_atom("otp-"++FromVsn), + Name = list_to_atom("ct_release_test-otp-"++FromVsn), ct:log("Starting node to fetch application versions to upgrade from"), - {ok,Node} = test_server:start_node(OtpRel,peer,[{erl,[OldRel]}]), + {ok,Node} = test_server:start_node(Name,peer,[{erl,[OldRel]}]), {Apps,Path} = fetch_all_apps(Node), test_server:stop_node(Node), {FromVsn,ToVsn,Apps,Path}. @@ -723,7 +736,7 @@ do_callback(Node,Mod,Func,Args) -> ct:log("~p:~p/~w returned: ~p",[Mod,Func,length(Args),R]), case R of {badrpc,Error} -> - test_server:fail({test_upgrade_callback,Mod,Func,Args,Error}); + throw({fail,{test_upgrade_callback,Mod,Func,Args,Error}}); NewState -> NewState end. diff --git a/lib/common_test/src/ct_util.erl b/lib/common_test/src/ct_util.erl index 445fce1db8..b7fa7947e2 100644 --- a/lib/common_test/src/ct_util.erl +++ b/lib/common_test/src/ct_util.erl @@ -485,6 +485,8 @@ loop(Mode,TestData,StartDir) -> {'EXIT',Pid,Reason} -> case ets:lookup(?conn_table,Pid) of [#conn{address=A,callback=CB}] -> + ErrorStr = io_lib:format("~tp", [Reason]), + ErrorHtml = ct_logs:escape_chars(ErrorStr), %% A connection crashed - remove the connection but don't die ct_logs:tc_log_async(ct_error_notify, ?MAX_IMPORTANCE, @@ -492,8 +494,8 @@ loop(Mode,TestData,StartDir) -> "Connection process died: " "Pid: ~w, Address: ~p, " "Callback: ~w\n" - "Reason: ~p\n\n", - [Pid,A,CB,Reason]), + "Reason: ~ts\n\n", + [Pid,A,CB,ErrorHtml]), catch CB:close(Pid), %% in case CB:close failed to do this: unregister_connection(Pid), diff --git a/lib/common_test/src/cth_conn_log.erl b/lib/common_test/src/cth_conn_log.erl index 9b3dc0b5f1..954b4239af 100644 --- a/lib/common_test/src/cth_conn_log.erl +++ b/lib/common_test/src/cth_conn_log.erl @@ -132,7 +132,7 @@ pre_init_per_testcase(TestCase,Config,CthState) -> [S,ct_logs:uri(L),filename:basename(L)]) || {S,L} <- Ls] ++ "</table>", - io:format(Str,[]), + ct:log(Str,[],[no_css]), {ConnMod,{LogType,Ls}}; _ -> {ConnMod,{LogType,[]}} diff --git a/lib/common_test/src/erl2html2.erl b/lib/common_test/src/erl2html2.erl index e281c9de1b..d440d0940d 100644 --- a/lib/common_test/src/erl2html2.erl +++ b/lib/common_test/src/erl2html2.erl @@ -44,7 +44,7 @@ convert(File, Dest, InclPath) -> "<html>\n" "<head>\n" "<meta http-equiv=\"Content-Type\" content=\"text/html;" - "charset=",html_encoding(Encoding),"\"/>\n" + "charset=",html_encoding(Encoding),"\"/></meta>\n" "<title>", to_raw_list(File,Encoding), "</title>\n" "</head>\n\n" "<body bgcolor=\"white\" text=\"black\"" diff --git a/lib/common_test/src/test_server.erl b/lib/common_test/src/test_server.erl index f62eb88ccf..34acad6fd1 100644 --- a/lib/common_test/src/test_server.erl +++ b/lib/common_test/src/test_server.erl @@ -740,14 +740,10 @@ do_call_end_conf(Starter,Mod,Func,Data,TCExitReason,Conf,TVal) -> try apply(Mod,end_per_testcase,[Func,EndConf]) of _ -> ok catch - _:Why -> + _:Error -> timer:sleep(1), - GLMsg = {printout,12, - "WARNING! " - "~w:end_per_testcase(~w, ~p)" - " crashed!\n\tReason: ~p\n", - [Mod,Func,Conf,Why]}, - group_leader() ! GLMsg + print_end_conf_result(Mod,Func,Conf, + "crashed",Error) end, Supervisor ! {self(),end_conf} end, @@ -756,10 +752,7 @@ do_call_end_conf(Starter,Mod,Func,Data,TCExitReason,Conf,TVal) -> {Pid,end_conf} -> Starter ! {self(),{call_end_conf,Data,ok}}; {'EXIT',Pid,Reason} -> - group_leader() ! {printout,12, - "WARNING! ~w:end_per_testcase(~w, ~p)" - " failed!\n\tReason: ~p\n", - [Mod,Func,Conf,Reason]}, + print_end_conf_result(Mod,Func,Conf,"failed",Reason), Starter ! {self(),{call_end_conf,Data,{error,Reason}}}; {'EXIT',_OtherPid,Reason} -> %% Probably the parent - not much to do about that @@ -768,6 +761,23 @@ do_call_end_conf(Starter,Mod,Func,Data,TCExitReason,Conf,TVal) -> end, spawn_link(EndConfProc). +print_end_conf_result(Mod,Func,Conf,Cause,Error) -> + Str2Print = + fun(NoHTML) when NoHTML == stdout; NoHTML == major -> + io_lib:format("WARNING! " + "~w:end_per_testcase(~w, ~tp)" + " ~s!\n\tReason: ~tp\n", + [Mod,Func,Conf,Cause,Error]); + (minor) -> + ErrorStr = test_server_ctrl:escape_chars(Error), + io_lib:format("WARNING! " + "~w:end_per_testcase(~w, ~tp)" + " ~s!\n\tReason: ~ts\n", + [Mod,Func,Conf,Cause,ErrorStr]) + end, + group_leader() ! {printout,12,Str2Print}. + + spawn_fw_call(Mod,IPTC={init_per_testcase,Func},CurrConf,Pid, Why,Loc,SendTo) -> FwCall = @@ -1303,7 +1313,7 @@ do_init_per_testcase(Mod, Args) -> Bad -> group_leader() ! {printout,12, "ERROR! init_per_testcase has returned " - "bad elements in Config: ~p\n",[Bad]}, + "bad elements in Config: ~tp\n",[Bad]}, {skip,{failed,{Mod,init_per_testcase,bad_return}}} end; {fail,_Reason}=Res -> @@ -1321,25 +1331,33 @@ do_init_per_testcase(Mod, Args) -> throw:Other -> set_loc(erlang:get_stacktrace()), Line = get_loc(), - FormattedLoc = test_server_sup:format_loc(Line), - group_leader() ! {printout,12, - "ERROR! init_per_testcase thrown!\n" - "\tLocation: ~ts\n\tReason: ~p\n", - [FormattedLoc, Other]}, + print_init_conf_result(Line,"thrown",Other), {skip,{failed,{Mod,init_per_testcase,Other}}}; _:Reason0 -> Stk = erlang:get_stacktrace(), Reason = {Reason0,Stk}, set_loc(Stk), Line = get_loc(), - FormattedLoc = test_server_sup:format_loc(Line), - group_leader() ! {printout,12, - "ERROR! init_per_testcase crashed!\n" - "\tLocation: ~ts\n\tReason: ~p\n", - [FormattedLoc,Reason]}, + print_init_conf_result(Line,"crashed",Reason), {skip,{failed,{Mod,init_per_testcase,Reason}}} end. +print_init_conf_result(Line,Cause,Reason) -> + FormattedLoc = test_server_sup:format_loc(Line), + Str2Print = + fun(NoHTML) when NoHTML == stdout; NoHTML == major -> + io_lib:format("ERROR! init_per_testcase ~s!\n" + "\tLocation: ~p\n\tReason: ~tp\n", + [Cause,Line,Reason]); + (minor) -> + ReasonStr = test_server_ctrl:escape_chars(Reason), + io_lib:format("ERROR! init_per_testcase ~s!\n" + "\tLocation: ~ts\n\tReason: ~ts\n", + [Cause,FormattedLoc,ReasonStr]) + end, + group_leader() ! {printout,12,Str2Print}. + + end_per_testcase(Mod, Func, Conf) -> case erlang:function_exported(Mod,end_per_testcase,2) of true -> @@ -1374,12 +1392,7 @@ do_end_per_testcase(Mod,EndFunc,Func,Conf) -> comment(io_lib:format("~ts<font color=\"red\">" "WARNING: ~w thrown!" "</font>\n",[Comment0,EndFunc])), - group_leader() ! {printout,12, - "WARNING: ~w thrown!\n" - "Reason: ~p\n" - "Line: ~ts\n", - [EndFunc, Other, - test_server_sup:format_loc(get_loc())]}, + print_end_tc_warning(EndFunc,Other,"thrown",get_loc()), {failed,{Mod,end_per_testcase,Other}}; Class:Reason -> Stk = erlang:get_stacktrace(), @@ -1396,15 +1409,25 @@ do_end_per_testcase(Mod,EndFunc,Func,Conf) -> comment(io_lib:format("~ts<font color=\"red\">" "WARNING: ~w crashed!" "</font>\n",[Comment0,EndFunc])), - group_leader() ! {printout,12, - "WARNING: ~w crashed!\n" - "Reason: ~p\n" - "Line: ~ts\n", - [EndFunc, Reason, - test_server_sup:format_loc(get_loc())]}, + print_end_tc_warning(EndFunc,Reason,"crashed",get_loc()), {failed,{Mod,end_per_testcase,Why}} end. +print_end_tc_warning(EndFunc,Reason,Cause,Loc) -> + FormattedLoc = test_server_sup:format_loc(Loc), + Str2Print = + fun(NoHTML) when NoHTML == stdout; NoHTML == major -> + io_lib:format("WARNING: ~w ~s!\n" + "Reason: ~tp\nLine: ~p\n", + [EndFunc,Cause,Reason,Loc]); + (minor) -> + ReasonStr = test_server_ctrl:escape_chars(Reason), + io_lib:format("WARNING: ~w ~s!\n" + "Reason: ~ts\nLine: ~ts\n", + [EndFunc,Cause,ReasonStr,FormattedLoc]) + end, + group_leader() ! {printout,12,Str2Print}. + get_loc() -> get(test_server_loc). diff --git a/lib/common_test/src/test_server_ctrl.erl b/lib/common_test/src/test_server_ctrl.erl index cd08a25bd8..833d99907e 100644 --- a/lib/common_test/src/test_server_ctrl.erl +++ b/lib/common_test/src/test_server_ctrl.erl @@ -77,7 +77,7 @@ -export([handle_call/3, handle_cast/2, handle_info/2]). -export([do_test_cases/4]). -export([do_spec/2, do_spec_list/2]). --export([xhtml/2]). +-export([xhtml/2, escape_chars/1]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1825,13 +1825,14 @@ start_minor_log_file1(Mod, Func, LogDir, AbsName, MFA) -> case {filelib:is_file(filename:join(LogDir, SrcListing)), lists:member(no_src, get(test_server_logopts))} of {true,false} -> - print(Lev, Info ++ "<a href=\"~ts#~ts\">~w:~w/~w</a> " - "(click for source code)\n", + print(Lev, ["$tc_html", + Info ++ "<a href=\"~ts#~ts\">~w:~w/~w</a> " + "(click for source code)\n"], [uri_encode(SrcListing), uri_encode(atom_to_list(Func)++"-1",utf8), Mod,Func,Arity]); _ -> - print(Lev, Info ++ "~w:~w/~w\n", [Mod,Func,Arity]) + print(Lev, ["$tc_html",Info ++ "~w:~w/~w\n"], [Mod,Func,Arity]) end end, @@ -3747,7 +3748,10 @@ run_test_case1(Ref, Num, Mod, Func, Args, RunInit, true -> ok end, - print(minor, "Config value:\n\n ~tp\n", [Args2Print]), + + print(minor, + escape_chars(io_lib:format("Config value:\n\n ~tp\n", [Args2Print])), + []), print(minor, "Current directory is ~tp\n", [Cwd]), GrNameStr = case GrName of @@ -3762,7 +3766,7 @@ run_test_case1(Ref, Num, Mod, Func, Args, RunInit, "<td>" ++ Col0 ++ "~w" ++ Col1 ++ "</td>" "<td>" ++ Col0 ++ "~ts" ++ Col1 ++ "</td>" "<td><a href=\"~ts\">~w</a></td>" - "<td><a href=\"~ts#top\"><</a> <a href=\"~ts#end\">></a></td>", + "<td><a href=\"~ts#top\"><</a> <a href=\"~ts#end\">></a></td>", [num2str(Num),fw_name(Mod),GrNameStr,EncMinorBase,Func, EncMinorBase,EncMinorBase]), @@ -3939,7 +3943,7 @@ progress(skip, CaseNum, Mod, Func, GrName, Loc, Reason, Time, [get_info_str(Mod,Func, CaseNum, get(test_server_cases))]), test_server_sup:framework_call(report, [tc_done,{Mod,{Func,GrName}, {ReportTag,Reason1}}]), - ReasonStr = reason_to_string(Reason1), + ReasonStr = escape_chars(reason_to_string(Reason1)), ReasonStr1 = lists:flatten([string:strip(S,left) || S <- string:tokens(ReasonStr,[$\n])]), ReasonStr2 = @@ -4011,7 +4015,10 @@ progress(failed, CaseNum, Mod, Func, GrName, Loc, {testcase_aborted,Reason}, _T, [Comment]), FormatLoc = test_server_sup:format_loc(Loc), print(minor, "=== Location: ~ts", [FormatLoc]), - print(minor, "=== Reason: {testcase_aborted,~p}", [Reason]), + print(minor, + escape_chars(io_lib:format("=== Reason: {testcase_aborted,~p}", + [Reason])), + []), failed; progress(failed, CaseNum, Mod, Func, GrName, unknown, Reason, Time, @@ -4024,7 +4031,7 @@ progress(failed, CaseNum, Mod, Func, GrName, unknown, Reason, Time, TimeStr = io_lib:format(if is_float(Time) -> "~.3fs"; true -> "~w" end, [Time]), - ErrorReason = lists:flatten(io_lib:format("~p", [Reason])), + ErrorReason = escape_chars(lists:flatten(io_lib:format("~p", [Reason]))), ErrorReason1 = lists:flatten([string:strip(S,left) || S <- string:tokens(ErrorReason,[$\n])]), ErrorReason2 = @@ -4047,7 +4054,9 @@ progress(failed, CaseNum, Mod, Func, GrName, unknown, Reason, Time, [TimeStr,Comment]), print(minor, "=== Location: ~w", [unknown]), {FStr,FormattedReason} = format_exception(Reason), - print(minor, "=== Reason: " ++ FStr, [FormattedReason]), + print(minor, + escape_chars(io_lib:format("=== Reason: " ++ FStr, [FormattedReason])), + []), failed; progress(failed, CaseNum, Mod, Func, GrName, Loc, Reason, Time, @@ -4081,7 +4090,8 @@ progress(failed, CaseNum, Mod, Func, GrName, Loc, Reason, Time, FormatLoc = test_server_sup:format_loc(LocMin), print(minor, "=== Location: ~ts", [FormatLoc]), {FStr,FormattedReason} = format_exception(Reason), - print(minor, "=== Reason: " ++ FStr, [FormattedReason]), + print(minor, "=== Reason: " ++ + escape_chars(io_lib:format(FStr, [FormattedReason])), []), failed; progress(ok, _CaseNum, Mod, Func, GrName, _Loc, RetVal, Time, @@ -4110,11 +4120,36 @@ progress(ok, _CaseNum, Mod, Func, GrName, _Loc, RetVal, Time, "<td><font color=\"green\">Ok</font></td>" "~ts</tr>\n", [Time,Comment]), - print(minor, "=== Returned value: ~p", [RetVal]), + print(minor, + escape_chars(io_lib:format("=== Returned value: ~tp", [RetVal])), + []), ok. %%-------------------------------------------------------------------- %% various help functions +escape_chars(Term) when not is_list(Term), not is_binary(Term) -> + esc_chars_in_list(io_lib:format("~tp", [Term])); +escape_chars(List = [Term | _]) when not is_list(Term), not is_integer(Term) -> + esc_chars_in_list(io_lib:format("~tp", [List])); +escape_chars(List) -> + esc_chars_in_list(List). + +esc_chars_in_list([Bin | Io]) when is_binary(Bin) -> + [Bin | esc_chars_in_list(Io)]; +esc_chars_in_list([List | Io]) when is_list(List) -> + [esc_chars_in_list(List) | esc_chars_in_list(Io)]; +esc_chars_in_list([$< | Io]) -> + ["<" | esc_chars_in_list(Io)]; +esc_chars_in_list([$> | Io]) -> + [">" | esc_chars_in_list(Io)]; +esc_chars_in_list([$& | Io]) -> + ["&" | esc_chars_in_list(Io)]; +esc_chars_in_list([Char | Io]) when is_integer(Char) -> + [Char | esc_chars_in_list(Io)]; +esc_chars_in_list([]) -> + []; +esc_chars_in_list(Bin) -> + Bin. get_fw_mod(Mod) -> case get(test_server_framework) of @@ -4328,6 +4363,10 @@ print(Detail, Format) -> print(Detail, Format, Args) -> print(Detail, Format, Args, internal). +print(Detail, ["$tc_html",Format], Args, Printer) -> + Msg = io_lib:format(Format, Args), + print_or_buffer(Detail, ["$tc_html",Msg], Printer); + print(Detail, Format, Args, Printer) -> Msg = io_lib:format(Format, Args), print_or_buffer(Detail, Msg, Printer). @@ -5570,8 +5609,9 @@ html_header(Title) -> "<html>\n" "<head>\n" "<title>", Title, "</title>\n" - "<meta http-equiv=\"cache-control\" content=\"no-cache\">\n" - "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n" + "<meta http-equiv=\"cache-control\" content=\"no-cache\"></meta>\n" + "<meta http-equiv=\"content-type\" content=\"text/html; " + "charset=utf-8\"></meta>\n" "</head>\n" "<body bgcolor=\"white\" text=\"black\" " "link=\"blue\" vlink=\"purple\" alink=\"red\">\n"]. diff --git a/lib/common_test/src/test_server_gl.erl b/lib/common_test/src/test_server_gl.erl index 31098d9726..233e59172b 100644 --- a/lib/common_test/src/test_server_gl.erl +++ b/lib/common_test/src/test_server_gl.erl @@ -37,7 +37,8 @@ reject_io :: boolean(), %Reject I/O requests... permit_io, %... and exceptions auto_nl=true :: boolean(), %Automatically add NL - levels %{Stdout,Major,Minor} + levels, %{Stdout,Major,Minor} + escape_chars=true %Switch escaping HTML on/off }). %% start_link() @@ -137,7 +138,8 @@ init([]) -> reject_io=false, permit_io=gb_sets:empty(), auto_nl=true, - levels={1,19,10} + levels={1,19,10}, + escape_chars=true }}. req(GL, Req) -> @@ -182,7 +184,7 @@ handle_info({io_request,From,ReplyAs,Req}=IoReq, St) -> try io_req(Req, From, St) of passthrough -> group_leader() ! IoReq; - Data -> + {EscapeHtml,Data} -> case is_io_permitted(From, St) of false -> ok; @@ -193,7 +195,13 @@ handle_info({io_request,From,ReplyAs,Req}=IoReq, St) -> #st{capture=CapturePid} -> CapturePid ! {captured,Data} end, - output(minor, Data, From, From, St) + case EscapeHtml andalso St#st.escape_chars of + true -> + output(minor, test_server_ctrl:escape_chars(Data), + From, From, St); + false -> + output(minor, Data, From, From, St) + end end, From ! {io_reply,ReplyAs,ok} catch @@ -204,9 +212,20 @@ handle_info({io_request,From,ReplyAs,Req}=IoReq, St) -> handle_info({structured_io,ClientPid,{Detail,Str}}, St) -> output(Detail, Str, ClientPid, ClientPid, St), {noreply,St}; +handle_info({printout,Detail,["$tc_html",Format],Args}, St) -> + Str = io_lib:format(Format, Args), + output(Detail, ["$tc_html",Str], internal, none, St), + {noreply,St}; +handle_info({printout,Detail,Fun}, St) when is_function(Fun)-> + output(Detail, Fun, internal, none, St), + {noreply,St}; handle_info({printout,Detail,Format,Args}, St) -> Str = io_lib:format(Format, Args), - output(Detail, Str, internal, none, St), + if not St#st.escape_chars -> + output(Detail, ["$tc_html",Str], internal, none, St); + true -> + output(Detail, Str, internal, none, St) + end, {noreply,St}; handle_info(Msg, #st{tc_supervisor=Pid}=St) when is_pid(Pid) -> %% The process overseeing the testcase process also used to be @@ -231,25 +250,55 @@ do_set_props([{reject_io_reqs,Bool}|Ps], St) -> do_set_props(Ps, St#st{reject_io=Bool}); do_set_props([], St) -> St. -io_req({put_chars,Enc,Bytes}, _, _) when Enc =:= latin1; Enc =:= unicode -> - unicode:characters_to_list(Bytes, Enc); +io_req({put_chars,Enc,Str}, _, _) when Enc =:= latin1; Enc =:= unicode -> + case Str of + ["$tc_html",Str0] -> + {false,unicode:characters_to_list(Str0, Enc)}; + _ -> + {true,unicode:characters_to_list(Str, Enc)} + end; io_req({put_chars,Encoding,Mod,Func,[Format,Args]}, _, _) -> - Str = Mod:Func(Format, Args), - unicode:characters_to_list(Str, Encoding); + case Format of + ["$tc_html",Format0] -> + Str = Mod:Func(Format0, Args), + {false,unicode:characters_to_list(Str, Encoding)}; + _ -> + Str = Mod:Func(Format, Args), + {true,unicode:characters_to_list(Str, Encoding)} + end; io_req(_, _, _) -> passthrough. -output(Level, Str, Sender, From, St) when is_integer(Level) -> +output(Level, StrOrFun, Sender, From, St) when is_integer(Level) -> case selected_by_level(Level, stdout, St) of - true -> output(stdout, Str, Sender, From, St); - false -> ok + true when hd(StrOrFun) == "$tc_html" -> + output(stdout, tl(StrOrFun), Sender, From, St); + true when is_function(StrOrFun) -> + output(stdout, StrOrFun(stdout), Sender, From, St); + true -> + output(stdout, StrOrFun, Sender, From, St); + false -> + ok end, case selected_by_level(Level, major, St) of - true -> output(major, Str, Sender, From, St); - false -> ok + true when hd(StrOrFun) == "$tc_html" -> + output(major, tl(StrOrFun), Sender, From, St); + true when is_function(StrOrFun) -> + output(major, StrOrFun(major), Sender, From, St); + true -> + output(major, StrOrFun, Sender, From, St); + false -> + ok end, case selected_by_level(Level, minor, St) of - true -> output(minor, Str, Sender, From, St); - false -> ok + true when hd(StrOrFun) == "$tc_html" -> + output(minor, tl(StrOrFun), Sender, From, St); + true when is_function(StrOrFun) -> + output(minor, StrOrFun(minor), Sender, From, St); + true -> + output(minor, test_server_ctrl:escape_chars(StrOrFun), + Sender, From, St); + false -> + ok end; output(stdout, Str, _Sender, From, St) -> output_to_file(stdout, Str, From, St); diff --git a/lib/common_test/test/Makefile b/lib/common_test/test/Makefile index aa99fe1af1..fd96d06aab 100644 --- a/lib/common_test/test/Makefile +++ b/lib/common_test/test/Makefile @@ -68,7 +68,8 @@ MODULES= \ ct_telnet_SUITE \ erl2html2_SUITE \ test_server_SUITE \ - test_server_test_lib + test_server_test_lib \ + ct_release_test_SUITE ERL_FILES= $(MODULES:%=%.erl) HRL_FILES= test_server_test_lib.hrl diff --git a/lib/common_test/test/ct_release_test_SUITE.erl b/lib/common_test/test/ct_release_test_SUITE.erl new file mode 100644 index 0000000000..66d07155ac --- /dev/null +++ b/lib/common_test/test/ct_release_test_SUITE.erl @@ -0,0 +1,190 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2009-2014. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% + +%%%------------------------------------------------------------------- +%%% File: ct_release_test_SUITE +%%% +%%% Description: +%%% Test ct_release_test module +%%% +%%%------------------------------------------------------------------- +-module(ct_release_test_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("common_test/include/ct_event.hrl"). + +-define(eh, ct_test_support_eh). +-define(suite, release_test_SUITE). + +%%-------------------------------------------------------------------- +%% TEST SERVER CALLBACK FUNCTIONS +%%-------------------------------------------------------------------- + +%%-------------------------------------------------------------------- +%% Description: Since Common Test starts another Test Server +%% instance, the tests need to be performed on a separate node (or +%% there will be clashes with logging processes etc). +%%-------------------------------------------------------------------- +init_per_suite(Config) -> + case os:type() of + {win32,_} -> + {skipped, "Upgrade tests do currently not work on windows"}; + _ -> + ct_test_support:init_per_suite(Config) + end. + +end_per_suite(Config) -> + ct_test_support:end_per_suite(Config). + +init_per_testcase(TestCase, Config) -> + ct_test_support:init_per_testcase(TestCase, Config). + +end_per_testcase(TestCase, Config) -> + ct_test_support:end_per_testcase(TestCase, Config). + +suite() -> [{ct_hooks,[ts_install_cth]}]. + +all() -> + [ + minor, + major, + major_fail_init, + major_fail_upgraded, + major_fail_downgraded, + major_fail_no_init + ]. + +%%-------------------------------------------------------------------- +%% TEST CASES +%%-------------------------------------------------------------------- + +%%%----------------------------------------------------------------- +%%% +minor(Config) when is_list(Config) -> + {Suite,Cfg} = setup1(Config), + {Opts,ERPid} = setup([{suite,Suite}, + {testcase,minor}, + {label,minor}|Cfg], Config), + execute(minor, Opts, ERPid, Config). + +major(Config) when is_list(Config) -> + {Suite,Cfg} = setup1(Config), + {Opts,ERPid} = setup([{suite,Suite}, + {testcase,major}, + {label,major}|Cfg], Config), + execute(major, Opts, ERPid, Config). + +major_fail_init(Config) when is_list(Config) -> + {Suite,Cfg} = setup1(Config), + {Opts,ERPid} = setup([{suite,Suite}, + {testcase,major_fail_init}, + {label,major_fail_init}|Cfg], Config), + execute(major_fail_init, Opts, ERPid, Config). + +major_fail_upgraded(Config) when is_list(Config) -> + {Suite,Cfg} = setup1(Config), + {Opts,ERPid} = setup([{suite,Suite}, + {testcase,major_fail_upgraded}, + {label,major_fail_upgraded}|Cfg], Config), + execute(major_fail_upgraded, Opts, ERPid, Config). + +major_fail_downgraded(Config) when is_list(Config) -> + {Suite,Cfg} = setup1(Config), + {Opts,ERPid} = setup([{suite,Suite}, + {testcase,major_fail_downgraded}, + {label,major_fail_downgraded}|Cfg], Config), + execute(major_fail_downgraded, Opts, ERPid, Config). + +major_fail_no_init(Config) when is_list(Config) -> + {Suite,Cfg} = setup1(Config), + {Opts,ERPid} = setup([{suite,Suite}, + {testcase,major_fail_no_init}, + {label,major_fail_no_init}|Cfg], Config), + execute(major_fail_no_init, Opts, ERPid, Config). + + +%%%----------------------------------------------------------------- +%%% HELP FUNCTIONS +%%%----------------------------------------------------------------- +setup1(Config) -> + DataDir = ?config(data_dir, Config), + Suite = filename:join(DataDir, atom_to_list(?suite)), + Cfg = case ct:get_config(otp_releases) of + undefined -> + []; + Rels -> + CfgFile = filename:join(DataDir, "release_test.cfg"), + file:write_file(CfgFile, + io_lib:format("{otp_releases,~p}.",[Rels])), + [{config,CfgFile}] + end, + {Suite,Cfg}. + +setup(Test, Config) -> + Opts0 = ct_test_support:get_opts(Config), + Level = ?config(trace_level, Config), + EvHArgs = [{cbm,ct_test_support},{trace_level,Level}], + Opts = Opts0 ++ [{event_handler,{?eh,EvHArgs}}|Test], + ERPid = ct_test_support:start_event_receiver(Config), + {Opts,ERPid}. + +execute(Name, Opts, ERPid, Config) -> + ok = ct_test_support:run(Opts, Config), + Events = ct_test_support:get_events(ERPid, Config), + + ct_test_support:log_events(Name, + reformat(Events, ?eh), + ?config(priv_dir, Config), + Opts), + + verify_events(Name,Events,Config). + +reformat(Events, EH) -> + ct_test_support:reformat(Events, EH). + +%%%----------------------------------------------------------------- +%%% TEST EVENTS +%%%----------------------------------------------------------------- +verify_events(TC,Events,Config) -> + Ok = expected_events(TC,ok), + case ct_test_support:verify_events(Ok, Events, Config) of + ok -> + ok; + {event_not_found,{?eh,tc_done,{_Suite,TC,ok}}}=R1 -> + ct:log("Did not find 'ok', checking if skipped...",[]), + Skipped = expected_events(TC,{skipped,"Old release not available"}), + case ct_test_support:verify_events(Skipped, Events, Config) of + ok -> + {skipped,"Old release not available"}; + R2 -> + ct:log("Did not find skipped case either: ~n~p",[R2]), + exit(R1) + end + end. + +expected_events(TC,Result) -> + OneTest = + [{?eh,start_logging,{'DEF','RUNDIR'}}, + {?eh,tc_done,{?suite,TC,Result}}, + {?eh,stop_logging,[]}], + %% 2 tests (ct:run_test + script_start) is default + OneTest ++ OneTest. diff --git a/lib/common_test/test/ct_release_test_SUITE_data/release_test_SUITE.erl b/lib/common_test/test/ct_release_test_SUITE_data/release_test_SUITE.erl new file mode 100644 index 0000000000..04c92be0d1 --- /dev/null +++ b/lib/common_test/test/ct_release_test_SUITE_data/release_test_SUITE.erl @@ -0,0 +1,118 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 1997-2015. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% +%%%---------------------------------------------------------------- +%%% Purpose: Test the support for application upgrade/code_change test +%%%----------------------------------------------------------------- +-module(release_test_SUITE). +-include_lib("common_test/include/ct.hrl"). + +-compile(export_all). + +-define(APP,runtime_tools). % "randomly" selected 'application under test' + +%% +%% all/1 +%% +all() -> + [minor, + major, + major_fail_init, + major_fail_upgraded, + major_fail_downgraded, + major_fail_no_init]. + +init_per_suite(Config) -> + Config. + +end_per_suite(_Config) -> + ok. + +init_per_testcase(major_fail_no_init, Config) -> + Config; +init_per_testcase(_Case, Config) -> + ct_release_test:init(Config). +end_per_testcase(_Case, Config) -> + ct_release_test:cleanup(Config). + +%%%----------------------------------------------------------------- +%%% Test cases +minor(Config) -> + ct_release_test:upgrade(?APP,minor,{?MODULE,[]},Config). + +major(Config) -> + ct_release_test:upgrade(?APP,major,{?MODULE,[]},Config). + +major_fail_init(Config) -> + try ct_release_test:upgrade(?APP,major,{?MODULE,fail_init},Config) + catch exit:{test_case_failed, + {test_upgrade_callback,_Mod,_Func,_Args, + {'EXIT',{test_case_failed,upgrade_init_failed}}}} -> + ok + end. + +major_fail_upgraded(Config) -> + try ct_release_test:upgrade(?APP,major,{?MODULE,fail_upgraded},Config) + catch exit:{test_case_failed, + {test_upgrade_callback,_Mod,_Func,_Args, + {'EXIT',{test_case_failed,upgrade_upgraded_failed}}}} -> + ok + end. + +major_fail_downgraded(Config) -> + try ct_release_test:upgrade(?APP,major,{?MODULE,fail_downgraded},Config) + catch exit:{test_case_failed, + {test_upgrade_callback,_Mod,_Func,_Args, + {'EXIT',{test_case_failed,upgrade_downgraded_failed}}}} -> + ok + end. + +major_fail_no_init(Config) -> + try ct_release_test:upgrade(?APP,major,[],Config) + catch exit:{test_case_failed,"ct_release_test:init/1 not run"} -> + ok + end. + +%%%----------------------------------------------------------------- +%%% ct_release_test callbacks + +%% Version numbers are checked by ct_release_test, so there is nothing +%% more to check here... +upgrade_init(CtData,fail_init) -> + ct:fail(upgrade_init_failed); +upgrade_init(CtData,State) -> + {ok,{FromVsn,ToVsn}} = ct_release_test:get_app_vsns(CtData,?APP), + case ct_release_test:get_appup(CtData,?APP) of + {ok,{FromVsn,ToVsn,UpInstrs,DownInstrs}} -> + io:format("Upgrade/downgrade ~p: ~p <--> ~p~n" + "Upgrade instructions: ~p~n" + "Downgrade instructions: ~p", + [?APP,FromVsn,ToVsn,UpInstrs,DownInstrs]); + {error,{vsn_not_found,_}} when FromVsn==ToVsn -> + io:format("No upgrade test for ~p, same version",[?APP]) + end, + State. +upgrade_upgraded(CtData,fail_upgraded) -> + ct:fail(upgrade_upgraded_failed); +upgrade_upgraded(_CtData,State) -> + State. +upgrade_downgraded(CtData,fail_downgraded) -> + ct:fail(upgrade_downgraded_failed); +upgrade_downgraded(_CtData,State) -> + State. diff --git a/lib/common_test/test/ct_test_support.erl b/lib/common_test/test/ct_test_support.erl index 4a47d345e9..0ee83f45b8 100644 --- a/lib/common_test/test/ct_test_support.erl +++ b/lib/common_test/test/ct_test_support.erl @@ -1228,8 +1228,8 @@ log_events(TC, Events, EvLogDir, Opts) -> file:close(Dev), FullLogFile = join_abs_dirs(proplists:get_value(net_dir, Opts), LogFile), - io:format("Events written to logfile: <a href=\"file://~s\">~s</a>~n", - [FullLogFile,FullLogFile]), + ct:log("Events written to logfile: <a href=\"file://~s\">~s</a>~n", + [FullLogFile,FullLogFile],[no_css]), io:format(user, "Events written to logfile: ~p~n", [LogFile]). log_events1(Evs, Dev, "") -> diff --git a/lib/common_test/test/erl2html2_SUITE.erl b/lib/common_test/test/erl2html2_SUITE.erl index 9e6389109b..8e9f6e773a 100644 --- a/lib/common_test/test/erl2html2_SUITE.erl +++ b/lib/common_test/test/erl2html2_SUITE.erl @@ -31,7 +31,7 @@ "<html>\n", "<head><title>Module ", Src, "</title>\n", "<meta http-equiv=\"cache-control\" ", - "content=\"no-cache\">\n", + "content=\"no-cache\"></meta>\n", "</head>\n", "<body bgcolor=\"white\" text=\"black\" ", "link=\"blue\" vlink=\"purple\" alink=\"red\">\n"]). diff --git a/lib/compiler/src/beam_block.erl b/lib/compiler/src/beam_block.erl index 10dbaf462c..d1052303e0 100644 --- a/lib/compiler/src/beam_block.erl +++ b/lib/compiler/src/beam_block.erl @@ -58,6 +58,13 @@ blockify(Is) -> blockify([{loop_rec,{f,Fail},{x,0}},{loop_rec_end,_Lbl},{label,Fail}|Is], Acc) -> %% Useless instruction sequence. blockify(Is, Acc); +blockify([{get_map_elements,F,S,{list,Gets}}|Is0], Acc) -> + %% A get_map_elements instruction is only safe at the beginning of + %% a block because of the failure label. + {Ss,Ds} = beam_utils:split_even(Gets), + I = {set,Ds,[S|Ss],{get_map_elements,F}}, + {Block,Is} = collect_block(Is0, [I]), + blockify(Is, [{block,Block}|Acc]); blockify([I|Is0]=IsAll, Acc) -> case collect(I) of error -> blockify(Is0, [I|Acc]); @@ -101,9 +108,6 @@ collect({get_list,S,D1,D2}) -> {set,[D1,D2],[S],get_list}; collect(remove_message) -> {set,[],[],remove_message}; collect({put_map,F,Op,S,D,R,{list,Puts}}) -> {set,[D],[S|Puts],{alloc,R,{put_map,Op,F}}}; -collect({get_map_elements,F,S,{list,Gets}}) -> - {Ss,Ds} = beam_utils:split_even(Gets), - {set,Ds,[S|Ss],{get_map_elements,F}}; collect({'catch'=Op,R,L}) -> {set,[R],[],{try_catch,Op,L}}; collect({'try'=Op,R,L}) -> diff --git a/lib/compiler/test/Makefile b/lib/compiler/test/Makefile index c2d757da4d..85118502e3 100644 --- a/lib/compiler/test/Makefile +++ b/lib/compiler/test/Makefile @@ -8,6 +8,7 @@ include $(ERL_TOP)/make/$(TARGET)/otp.mk MODULES= \ andor_SUITE \ apply_SUITE \ + beam_block_SUITE \ beam_validator_SUITE \ beam_disasm_SUITE \ beam_except_SUITE \ @@ -44,6 +45,7 @@ MODULES= \ NO_OPT= \ andor \ apply \ + beam_block \ beam_except \ beam_reorder \ beam_type \ @@ -67,6 +69,7 @@ NO_OPT= \ INLINE= \ andor \ apply \ + beam_block \ beam_utils \ bs_bincomp \ bs_bit_binaries \ diff --git a/lib/compiler/test/beam_block_SUITE.erl b/lib/compiler/test/beam_block_SUITE.erl new file mode 100644 index 0000000000..7b6f2066be --- /dev/null +++ b/lib/compiler/test/beam_block_SUITE.erl @@ -0,0 +1,66 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2015. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% +-module(beam_block_SUITE). + +-export([all/0,suite/0,groups/0,init_per_suite/1,end_per_suite/1, + init_per_group/2,end_per_group/2, + get_map_elements/1]). + +suite() -> [{ct_hooks,[ts_install_cth]}]. + +all() -> + test_lib:recompile(?MODULE), + [{group,p}]. + +groups() -> + [{p,[parallel], + [get_map_elements + ]}]. + +init_per_suite(Config) -> + Config. + +end_per_suite(_Config) -> + ok. + +init_per_group(_GroupName, Config) -> + Config. + +end_per_group(_GroupName, Config) -> + Config. + +get_map_elements(_Config) -> + [{pred,var}] = get_map_elements([{pred,var}], #{}, []), + [{pred,var}] = get_map_elements([{pred,var}], #{pred=>[]}, []), + acc = get_map_elements([], #{pred=>[]}, acc), + ok. + +get_map_elements([{Pred,Var}|Left], Map, Acc) -> + case Map of + #{Var := List} -> + case lists:keyfind(Pred, 1, List) of + false -> + get_map_elements(Left, Map, [{Pred,Var}|Acc]) + end; + #{} -> + get_map_elements(Left, Map, [{Pred,Var}|Acc]) + end; +get_map_elements([], _Map, Acc) -> + Acc. diff --git a/lib/kernel/test/code_SUITE.erl b/lib/kernel/test/code_SUITE.erl index 0cd2c5d47c..298c1f7d6b 100644 --- a/lib/kernel/test/code_SUITE.erl +++ b/lib/kernel/test/code_SUITE.erl @@ -972,7 +972,8 @@ bad_erl_libs(Config) when is_list(Config) -> test_server:stop_node(Node2), %% Test that code path is not affected by the faulty ERL_LIBS - Code == Code2, + Code = Code2, + ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/lib/kernel/test/erl_prim_loader_SUITE.erl b/lib/kernel/test/erl_prim_loader_SUITE.erl index 00be5c99a8..3ea925ee9a 100644 --- a/lib/kernel/test/erl_prim_loader_SUITE.erl +++ b/lib/kernel/test/erl_prim_loader_SUITE.erl @@ -109,6 +109,12 @@ get_file(Config) when is_list(Config) -> ok. get_modules(_Config) -> + case test_server:is_cover() of + false -> do_get_modules(); + true -> {skip,"Cover"} + end. + +do_get_modules() -> MsGood = lists:sort([lists,gen_server,gb_trees,code_server]), Ms = [certainly_not_existing|MsGood], SuccExp = [begin @@ -118,6 +124,9 @@ get_modules(_Config) -> end || M <- MsGood], FailExp = [{certainly_not_existing,enoent}], + io:format("SuccExp = ~p\n", [SuccExp]), + io:format("FailExp = ~p\n", [FailExp]), + Path = code:get_path(), Process = fun(_, F, Code) -> {ok,{F,erlang:md5(Code)}} end, {ok,{Succ,FailExp}} = erl_prim_loader:get_modules(Ms, Process, Path), diff --git a/lib/kernel/test/multi_load_SUITE.erl b/lib/kernel/test/multi_load_SUITE.erl index 7ec4803114..9cba6fc06e 100644 --- a/lib/kernel/test/multi_load_SUITE.erl +++ b/lib/kernel/test/multi_load_SUITE.erl @@ -274,7 +274,12 @@ do_ensure_modules_loaded(Dir) -> true = is_loaded(Mod), true = is_loaded(OLMod), true = is_loaded(NativeMod), - true = NativeMod:module_info(native), + + ModuleNative = case erlang:system_info(hipe_architecture) of + undefined -> false; + _ -> true + end, + ModuleNative = NativeMod:module_info(native), ok. @@ -359,9 +364,9 @@ atomic_load_error(Modules, ErrorInFinishLoading) -> {B,B} -> Errors; {false,true} -> - ct:fail("LastAction fun must not be called"); + ct:fail("code:prepare_loading/1 should have failed"); {true,false} -> - ct:fail("LastAction fun was not called") + ct:fail("code:prepare_loading/1 should have succeeded") end. is_loaded(Mod) -> diff --git a/lib/stdlib/test/array_SUITE.erl b/lib/stdlib/test/array_SUITE.erl index 6fec03a2f7..8d031ed490 100644 --- a/lib/stdlib/test/array_SUITE.erl +++ b/lib/stdlib/test/array_SUITE.erl @@ -22,11 +22,6 @@ -include_lib("common_test/include/ct.hrl"). -%% Default timetrap timeout (set in init_per_testcase). -%% This should be set relatively high (10-15 times the expected -%% max testcasetime). --define(default_timeout, ?t:seconds(60)). - %% Test server specific exports -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2]). @@ -66,7 +61,9 @@ %% %% all/1 %% -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [new_test, fix_test, relax_test, resize_test, @@ -93,12 +90,9 @@ end_per_group(_GroupName, Config) -> init_per_testcase(_Case, Config) -> - ?line Dog=test_server:timetrap(?default_timeout), - [{watchdog, Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. -define(LEAFSIZE,10). @@ -111,19 +105,19 @@ end_per_testcase(_Case, Config) -> }). -define(_assert(What), - begin ?line true = What end + begin true = What end ). -define(_assertNot(What), - begin ?line false = What end + begin false = What end ). -define(_assertMatch(Res,What), begin - ?line case What of Res -> ok end + case What of Res -> ok end end ). -define(_assertError(Reas,What), - begin ?line fun() -> + begin fun() -> try What of A_Success -> exit({test_error, A_Success}) catch error:Reas -> ok end @@ -131,9 +125,9 @@ end_per_testcase(_Case, Config) -> end ). --define(LET(Var,Expr, Test), begin ?line fun() -> Var = Expr, Test end() end). +-define(LET(Var,Expr, Test), begin fun() -> Var = Expr, Test end() end). --define(_test(Expr), begin ?line Expr end). +-define(_test(Expr), begin Expr end). %%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Some helpers to be able to run the tests without testserver @@ -152,18 +146,7 @@ t(What) -> io:format("Failed ~p:~p ~p ~p~n ~p~n", [T,Line,_E,_R, erlang:get_stacktrace()]) end - end, expand(What)). - -expand(All) -> - lists:reverse(expand(All,[])). -expand([H|T], Acc) -> - case ?MODULE:H(suite) of - [] -> expand(T,[H|Acc]); - Cs -> - R = expand(Cs, Acc), - expand(T, R) - end; -expand([], Acc) -> Acc. + end, What). %%%%% extract tests @@ -173,8 +156,6 @@ extract_tests() -> try Tests = extract_tests(In,Out,[]), Call = fun(Test) -> - io:format(Out, "~s(doc) -> [];~n", [Test]), - io:format(Out, "~s(suite) -> [];~n", [Test]), io:format(Out, "~s(Config) when is_list(Config) -> ~s_(), ok.~n", [Test, Test]) end, @@ -775,54 +756,20 @@ sparse_foldr_test_() -> set(0,0,new()))))) ]. -new_test(doc) -> []; -new_test(suite) -> []; new_test(Config) when is_list(Config) -> new_test_(), ok. -fix_test(doc) -> []; -fix_test(suite) -> []; fix_test(Config) when is_list(Config) -> fix_test_(), ok. -relax_test(doc) -> []; -relax_test(suite) -> []; relax_test(Config) when is_list(Config) -> relax_test_(), ok. -resize_test(doc) -> []; -resize_test(suite) -> []; resize_test(Config) when is_list(Config) -> resize_test_(), ok. -set_get_test(doc) -> []; -set_get_test(suite) -> []; set_get_test(Config) when is_list(Config) -> set_get_test_(), ok. -to_list_test(doc) -> []; -to_list_test(suite) -> []; to_list_test(Config) when is_list(Config) -> to_list_test_(), ok. -sparse_to_list_test(doc) -> []; -sparse_to_list_test(suite) -> []; sparse_to_list_test(Config) when is_list(Config) -> sparse_to_list_test_(), ok. -from_list_test(doc) -> []; -from_list_test(suite) -> []; from_list_test(Config) when is_list(Config) -> from_list_test_(), ok. -to_orddict_test(doc) -> []; -to_orddict_test(suite) -> []; to_orddict_test(Config) when is_list(Config) -> to_orddict_test_(), ok. -sparse_to_orddict_test(doc) -> []; -sparse_to_orddict_test(suite) -> []; sparse_to_orddict_test(Config) when is_list(Config) -> sparse_to_orddict_test_(), ok. -from_orddict_test(doc) -> []; -from_orddict_test(suite) -> []; from_orddict_test(Config) when is_list(Config) -> from_orddict_test_(), ok. -map_test(doc) -> []; -map_test(suite) -> []; map_test(Config) when is_list(Config) -> map_test_(), ok. -sparse_map_test(doc) -> []; -sparse_map_test(suite) -> []; sparse_map_test(Config) when is_list(Config) -> sparse_map_test_(), ok. -foldl_test(doc) -> []; -foldl_test(suite) -> []; foldl_test(Config) when is_list(Config) -> foldl_test_(), ok. -sparse_foldl_test(doc) -> []; -sparse_foldl_test(suite) -> []; sparse_foldl_test(Config) when is_list(Config) -> sparse_foldl_test_(), ok. -foldr_test(doc) -> []; -foldr_test(suite) -> []; foldr_test(Config) when is_list(Config) -> foldr_test_(), ok. -sparse_foldr_test(doc) -> []; -sparse_foldr_test(suite) -> []; sparse_foldr_test(Config) when is_list(Config) -> sparse_foldr_test_(), ok. diff --git a/lib/stdlib/test/base64_SUITE.erl b/lib/stdlib/test/base64_SUITE.erl index f750145ef0..074047c7c5 100644 --- a/lib/stdlib/test/base64_SUITE.erl +++ b/lib/stdlib/test/base64_SUITE.erl @@ -34,19 +34,17 @@ roundtrip_1/1, roundtrip_2/1, roundtrip_3/1, roundtrip_4/1]). init_per_testcase(_, Config) -> - Dog = test_server:timetrap(?t:minutes(4)), - NewConfig = lists:keydelete(watchdog, 1, Config), - [{watchdog, Dog} | NewConfig]. + Config. -end_per_testcase(_, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_, _Config) -> ok. %%------------------------------------------------------------------------- %% Test cases starts here. %%------------------------------------------------------------------------- -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,4}}]. all() -> [base64_encode, base64_decode, base64_otp_5635, @@ -72,10 +70,7 @@ end_per_group(_GroupName, Config) -> %%------------------------------------------------------------------------- -base64_encode(doc) -> - ["Test base64:encode/1."]; -base64_encode(suite) -> - []; +%% Test base64:encode/1. base64_encode(Config) when is_list(Config) -> %% Two pads <<"QWxhZGRpbjpvcGVuIHNlc2FtZQ==">> = @@ -90,10 +85,7 @@ base64_encode(Config) when is_list(Config) -> base64:encode_to_string(<<"0123456789!@#0^&*();:<>,. []{}">>), ok. %%------------------------------------------------------------------------- -base64_decode(doc) -> - ["Test base64:decode/1."]; -base64_decode(suite) -> - []; +%% Test base64:decode/1. base64_decode(Config) when is_list(Config) -> %% Two pads <<"Aladdin:open sesame">> = @@ -117,28 +109,18 @@ base64_decode(Config) when is_list(Config) -> <<"MDEy MzQ1Njc4 \tOSFAIzBeJ \niooKTs6 PD4sLi \r\nBbXXt9">>), ok. %%------------------------------------------------------------------------- -base64_otp_5635(doc) -> - ["OTP-5635: Some data doesn't pass through base64:decode/1 " - "correctly"]; -base64_otp_5635(suite) -> - []; +%% OTP-5635: Some data doesn't pass through base64:decode/1 correctly. base64_otp_5635(Config) when is_list(Config) -> <<"===">> = base64:decode(base64:encode("===")), ok. %%------------------------------------------------------------------------- -base64_otp_6279(doc) -> - ["OTP-6279: Guard needed so that function fails in a correct" - "way for faulty input i.e. function_clause"]; -base64_otp_6279(suite) -> - []; +%% OTP-6279: Guard needed so that function fails in a correct +%% way for faulty input, i.e. function_clause. base64_otp_6279(Config) when is_list(Config) -> {'EXIT',{function_clause, _}} = (catch base64:decode("dGVzda==a")), ok. %%------------------------------------------------------------------------- -big(doc) -> - ["Encode and decode big binaries."]; -big(suite) -> - []; +%% Encode and decode big binaries. big(Config) when is_list(Config) -> Big = make_big_binary(300000), B = base64:encode(Big), @@ -148,10 +130,7 @@ big(Config) when is_list(Config) -> Big = base64:mime_decode(B), ok. %%------------------------------------------------------------------------- -illegal(doc) -> - ["Make sure illegal characters are rejected when decoding."]; -illegal(suite) -> - []; +%% Make sure illegal characters are rejected when decoding. illegal(Config) when is_list(Config) -> {'EXIT',{function_clause, _}} = (catch base64:decode("()")), ok. @@ -159,10 +138,8 @@ illegal(Config) when is_list(Config) -> %% mime_decode and mime_decode_to_string have different implementations %% so test both with the same input separately. Both functions have %% the same implementation for binary/string arguments. -mime_decode(doc) -> - ["Test base64:mime_decode/1."]; -mime_decode(suite) -> - []; +%% +%% Test base64:mime_decode/1. mime_decode(Config) when is_list(Config) -> %% Test correct padding <<"one">> = base64:mime_decode(<<"b25l">>), @@ -202,10 +179,8 @@ mime_decode(Config) when is_list(Config) -> %%------------------------------------------------------------------------- %% Repeat of mime_decode() tests -mime_decode_to_string(doc) -> - ["Test base64:mime_decode_to_string/1."]; -mime_decode_to_string(suite) -> - []; + +%% Test base64:mime_decode_to_string/1. mime_decode_to_string(Config) when is_list(Config) -> %% Test correct padding "one" = base64:mime_decode_to_string(<<"b25l">>), diff --git a/lib/stdlib/test/beam_lib_SUITE.erl b/lib/stdlib/test/beam_lib_SUITE.erl index 5de7b661e5..bf6e30ec83 100644 --- a/lib/stdlib/test/beam_lib_SUITE.erl +++ b/lib/stdlib/test/beam_lib_SUITE.erl @@ -19,7 +19,7 @@ %% -module(beam_lib_SUITE). -%-define(debug, true). +%%-define(debug, true). -ifdef(debug). -define(format(S, A), io:format(S, A)). @@ -30,7 +30,7 @@ -else. -include_lib("common_test/include/ct.hrl"). -define(format(S, A), ok). --define(privdir, ?config(priv_dir, Conf)). +-define(privdir, proplists:get_value(priv_dir, Conf)). -endif. -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, @@ -40,7 +40,9 @@ -export([init_per_testcase/2, end_per_testcase/2]). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,2}}]. all() -> [error, normal, cmp, cmp_literals, strip, otp_6711, @@ -63,78 +65,74 @@ end_per_group(_GroupName, Config) -> init_per_testcase(_Case, Config) -> - Dog=?t:timetrap(?t:minutes(2)), - [{watchdog, Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. -normal(suite) -> []; -normal(doc) -> ["Read correct beam file"]; +%% Read correct beam file. normal(Conf) when is_list(Conf) -> - ?line PrivDir = ?privdir, - ?line Simple = filename:join(PrivDir, "simple"), - ?line Source = Simple ++ ".erl", - ?line BeamFile = Simple ++ ".beam", - ?line simple_file(Source), + PrivDir = ?privdir, + Simple = filename:join(PrivDir, "simple"), + Source = Simple ++ ".erl", + BeamFile = Simple ++ ".beam", + simple_file(Source), - ?line NoOfTables = length(ets:all()), - ?line P0 = pps(), + NoOfTables = length(ets:all()), + P0 = pps(), CompileFlags = [{outdir,PrivDir}, debug_info], - ?line {ok,_} = compile:file(Source, CompileFlags), - ?line {ok, Binary} = file:read_file(BeamFile), + {ok,_} = compile:file(Source, CompileFlags), + {ok, Binary} = file:read_file(BeamFile), - ?line do_normal(BeamFile), - ?line do_normal(Binary), + do_normal(BeamFile), + do_normal(Binary), - ?line {ok,_} = compile:file(Source, [{outdir,PrivDir}, no_debug_info]), - ?line {ok, {simple, [{abstract_code, no_abstract_code}]}} = + {ok,_} = compile:file(Source, [{outdir,PrivDir}, no_debug_info]), + {ok, {simple, [{abstract_code, no_abstract_code}]}} = beam_lib:chunks(BeamFile, [abstract_code]), - %% ?line {ok,_} = compile:file(Source, [compressed | CompileFlags]), - %% ?line do_normal(BeamFile), + %% {ok,_} = compile:file(Source, [compressed | CompileFlags]), + %% do_normal(BeamFile), - ?line file:delete(BeamFile), - ?line file:delete(Source), - ?line NoOfTables = length(ets:all()), - ?line true = (P0 == pps()), + file:delete(BeamFile), + file:delete(Source), + NoOfTables = length(ets:all()), + true = (P0 == pps()), ok. do_normal(BeamFile) -> - ?line Imports = {imports, [{erlang, get_module_info, 1}, - {erlang, get_module_info, 2}, - {lists, member, 2}]}, - ?line Exports = {exports, [{module_info, 0}, {module_info, 1}, {t, 0}]}, - ?line Local = {locals, [{t, 1}]}, - ?line {ok, {simple, [Imports]}} = beam_lib:chunks(BeamFile, [imports]), - ?line {ok, {simple, [{"ImpT",_Bin}]}} = + Imports = {imports, [{erlang, get_module_info, 1}, + {erlang, get_module_info, 2}, + {lists, member, 2}]}, + Exports = {exports, [{module_info, 0}, {module_info, 1}, {t, 0}]}, + Local = {locals, [{t, 1}]}, + {ok, {simple, [Imports]}} = beam_lib:chunks(BeamFile, [imports]), + {ok, {simple, [{"ImpT",_Bin}]}} = beam_lib:chunks(BeamFile, ["ImpT"]), - ?line {ok, {simple, [Exports]}} = beam_lib:chunks(BeamFile, [exports]), - ?line {ok, {simple, [{attributes, [{vsn, [_]}]}]}} = + {ok, {simple, [Exports]}} = beam_lib:chunks(BeamFile, [exports]), + {ok, {simple, [{attributes, [{vsn, [_]}]}]}} = beam_lib:chunks(BeamFile, [attributes]), - ?line {ok, {simple, [{compile_info, _}=CompileInfo]}} = + {ok, {simple, [{compile_info, _}=CompileInfo]}} = beam_lib:chunks(BeamFile, [compile_info]), - ?line {ok, {simple, [Local]}} = beam_lib:chunks(BeamFile, [locals]), - ?line {ok, {simple, [{attributes, [{vsn, [_]}]}, CompileInfo, - Exports, Imports, Local]}} = + {ok, {simple, [Local]}} = beam_lib:chunks(BeamFile, [locals]), + {ok, {simple, [{attributes, [{vsn, [_]}]}, CompileInfo, + Exports, Imports, Local]}} = beam_lib:chunks(BeamFile, [attributes, compile_info, exports, imports, locals]), - ?line {ok, {simple, [{atoms, _Atoms}]}} = + {ok, {simple, [{atoms, _Atoms}]}} = beam_lib:chunks(BeamFile, [atoms]), - ?line {ok, {simple, [{labeled_exports, _LExports}]}} = + {ok, {simple, [{labeled_exports, _LExports}]}} = beam_lib:chunks(BeamFile, [labeled_exports]), - ?line {ok, {simple, [{labeled_locals, _LLocals}]}} = + {ok, {simple, [{labeled_locals, _LLocals}]}} = beam_lib:chunks(BeamFile, [labeled_locals]), - ?line {ok, {simple, [_Vsn]}} = beam_lib:version(BeamFile), - ?line {ok, {simple, [{abstract_code, _}]}} = + {ok, {simple, [_Vsn]}} = beam_lib:version(BeamFile), + {ok, {simple, [{abstract_code, _}]}} = beam_lib:chunks(BeamFile, [abstract_code]), - + %% Test reading optional chunks. All = ["Atom", "Code", "StrT", "ImpT", "ExpT", "FunT", "LitT"], - ?line {ok,{simple,Chunks}} = beam_lib:chunks(BeamFile, All, [allow_missing_chunks]), - ?line verify_simple(Chunks). + {ok,{simple,Chunks}} = beam_lib:chunks(BeamFile, All, [allow_missing_chunks]), + verify_simple(Chunks). verify_simple([{"Atom", AtomBin}, {"Code", CodeBin}, @@ -147,64 +145,61 @@ verify_simple([{"Atom", AtomBin}, is_binary(ImpBin), is_binary(ExpBin) -> ok. -error(suite) -> []; -error(doc) -> ["Read invalid beam files"]; +%% Read invalid beam files. error(Conf) when is_list(Conf) -> - ?line PrivDir = ?privdir, - ?line Simple = filename:join(PrivDir, "simple"), - ?line Source = Simple ++ ".erl", - ?line BeamFile = Simple ++ ".beam", - ?line WrongFile = Simple ++ "foo.beam", - ?line simple_file(Source), - - ?line NoOfTables = length(ets:all()), - ?line P0 = pps(), - ?line {ok,_} = compile:file(Source, [{outdir,PrivDir},debug_info]), - ?line ACopy = filename:join(PrivDir, "a_copy.beam"), - ?line copy_file(BeamFile, ACopy), - - ?line {ok, Binary} = file:read_file(BeamFile), - - ?line copy_file(ACopy, WrongFile), - ?line verify(file_error, beam_lib:info("./does_simply_not_exist")), - - ?line do_error(BeamFile, ACopy), - ?line do_error(Binary, ACopy), - - ?line copy_file(ACopy, BeamFile), - ?line verify(unknown_chunk, beam_lib:chunks(BeamFile, [not_a_chunk])), - - ?line ok = file:write_file(BeamFile, <<>>), - ?line verify(not_a_beam_file, beam_lib:info(BeamFile)), - ?line verify(not_a_beam_file, beam_lib:info(<<>>)), - ?line ok = file:write_file(BeamFile, <<"short">>), - ?line verify(not_a_beam_file, beam_lib:info(BeamFile)), - ?line verify(not_a_beam_file, beam_lib:info(<<"short">>)), - - ?line {Binary1, _} = split_binary(Binary, byte_size(Binary)-10), + PrivDir = ?privdir, + Simple = filename:join(PrivDir, "simple"), + Source = Simple ++ ".erl", + BeamFile = Simple ++ ".beam", + WrongFile = Simple ++ "foo.beam", + simple_file(Source), + + NoOfTables = length(ets:all()), + P0 = pps(), + {ok,_} = compile:file(Source, [{outdir,PrivDir},debug_info]), + ACopy = filename:join(PrivDir, "a_copy.beam"), + copy_file(BeamFile, ACopy), + + {ok, Binary} = file:read_file(BeamFile), + + copy_file(ACopy, WrongFile), + verify(file_error, beam_lib:info("./does_simply_not_exist")), + + do_error(BeamFile, ACopy), + do_error(Binary, ACopy), + + copy_file(ACopy, BeamFile), + verify(unknown_chunk, beam_lib:chunks(BeamFile, [not_a_chunk])), + + ok = file:write_file(BeamFile, <<>>), + verify(not_a_beam_file, beam_lib:info(BeamFile)), + verify(not_a_beam_file, beam_lib:info(<<>>)), + ok = file:write_file(BeamFile, <<"short">>), + verify(not_a_beam_file, beam_lib:info(BeamFile)), + verify(not_a_beam_file, beam_lib:info(<<"short">>)), + + {Binary1, _} = split_binary(Binary, byte_size(Binary)-10), LastChunk = last_chunk(Binary), - ?line verify(chunk_too_big, beam_lib:chunks(Binary1, [LastChunk])), - ?line Chunks = chunk_info(Binary), - ?line {value, {_, AbstractStart, _}} = lists:keysearch("Abst", 1, Chunks), - ?line {Binary2, _} = split_binary(Binary, AbstractStart), - ?line verify(chunk_too_big, beam_lib:chunks(Binary2, ["Abst"])), - ?line {Binary3, _} = split_binary(Binary, AbstractStart-4), - ?line verify(invalid_beam_file, beam_lib:chunks(Binary3, ["Abst"])), + verify(chunk_too_big, beam_lib:chunks(Binary1, [LastChunk])), + Chunks = chunk_info(Binary), + {value, {_, AbstractStart, _}} = lists:keysearch("Abst", 1, Chunks), + {Binary2, _} = split_binary(Binary, AbstractStart), + verify(chunk_too_big, beam_lib:chunks(Binary2, ["Abst"])), + {Binary3, _} = split_binary(Binary, AbstractStart-4), + verify(invalid_beam_file, beam_lib:chunks(Binary3, ["Abst"])), %% Instead of the 5:32 field below, there used to be control characters %% (including zero bytes) directly in the string. Because inferior programs %% such as sed and clearcasediff don't like zero bytes in text files, %% we have eliminated them. - ?line ok = file:write_file(BeamFile, <<"FOR1",5:32,"BEAMfel">>), -% ?line verify(invalid_beam_file, beam_lib:info(BeamFile)), -% ?line verify(invalid_beam_file, beam_lib:info(<<"FOR1",5:32,"BEAMfel">>)), - - ?line NoOfTables = length(ets:all()), - ?line true = (P0 == pps()), - ?line file:delete(Source), - ?line file:delete(WrongFile), - ?line file:delete(BeamFile), - ?line file:delete(ACopy), + ok = file:write_file(BeamFile, <<"FOR1",5:32,"BEAMfel">>), + + NoOfTables = length(ets:all()), + true = (P0 == pps()), + file:delete(Source), + file:delete(WrongFile), + file:delete(BeamFile), + file:delete(ACopy), ok. last_chunk(Bin) -> @@ -214,213 +209,210 @@ last_chunk(Bin) -> Last. do_error(BeamFile, ACopy) -> - % evil tests - ?line Chunks = chunk_info(BeamFile), - ?line {value, {_, AtomStart, _}} = lists:keysearch("Atom", 1, Chunks), - ?line {value, {_, ImportStart, _}} = lists:keysearch("ImpT", 1, Chunks), - ?line {value, {_, AbstractStart, _}} = lists:keysearch("Abst", 1, Chunks), - ?line {value, {_, AttributesStart, _}} = + %% evil tests + Chunks = chunk_info(BeamFile), + {value, {_, AtomStart, _}} = lists:keysearch("Atom", 1, Chunks), + {value, {_, ImportStart, _}} = lists:keysearch("ImpT", 1, Chunks), + {value, {_, AbstractStart, _}} = lists:keysearch("Abst", 1, Chunks), + {value, {_, AttributesStart, _}} = lists:keysearch("Attr", 1, Chunks), - ?line {value, {_, CompileInfoStart, _}} = + {value, {_, CompileInfoStart, _}} = lists:keysearch("CInf", 1, Chunks), - ?line verify(missing_chunk, beam_lib:chunks(BeamFile, ["__"])), - ?line BF2 = set_byte(ACopy, BeamFile, ImportStart+4, 17), - ?line verify(invalid_chunk, beam_lib:chunks(BF2, [imports])), - ?line BF3 = set_byte(ACopy, BeamFile, AtomStart-6, 17), - ?line verify(missing_chunk, beam_lib:chunks(BF3, [imports])), - ?line BF4 = set_byte(ACopy, BeamFile, AbstractStart+10, 17), - ?line verify(invalid_chunk, beam_lib:chunks(BF4, [abstract_code])), - ?line BF5 = set_byte(ACopy, BeamFile, AttributesStart+10, 17), - ?line verify(invalid_chunk, beam_lib:chunks(BF5, [attributes])), - - ?line BF6 = set_byte(ACopy, BeamFile, 1, 17), - ?line verify(not_a_beam_file, beam_lib:info(BF6)), - ?line BF7 = set_byte(ACopy, BeamFile, 9, 17), - ?line verify(not_a_beam_file, beam_lib:info(BF7)), - - ?line BF8 = set_byte(ACopy, BeamFile, 13, 17), - ?line verify(missing_chunk, beam_lib:chunks(BF8, ["Atom"])), - - ?line BF9 = set_byte(ACopy, BeamFile, CompileInfoStart+10, 17), - ?line verify(invalid_chunk, beam_lib:chunks(BF9, [compile_info])). - - -cmp(suite) -> []; -cmp(doc) -> ["Compare contents of BEAM files and directories"]; + verify(missing_chunk, beam_lib:chunks(BeamFile, ["__"])), + BF2 = set_byte(ACopy, BeamFile, ImportStart+4, 17), + verify(invalid_chunk, beam_lib:chunks(BF2, [imports])), + BF3 = set_byte(ACopy, BeamFile, AtomStart-6, 17), + verify(missing_chunk, beam_lib:chunks(BF3, [imports])), + BF4 = set_byte(ACopy, BeamFile, AbstractStart+10, 17), + verify(invalid_chunk, beam_lib:chunks(BF4, [abstract_code])), + BF5 = set_byte(ACopy, BeamFile, AttributesStart+10, 17), + verify(invalid_chunk, beam_lib:chunks(BF5, [attributes])), + + BF6 = set_byte(ACopy, BeamFile, 1, 17), + verify(not_a_beam_file, beam_lib:info(BF6)), + BF7 = set_byte(ACopy, BeamFile, 9, 17), + verify(not_a_beam_file, beam_lib:info(BF7)), + + BF8 = set_byte(ACopy, BeamFile, 13, 17), + verify(missing_chunk, beam_lib:chunks(BF8, ["Atom"])), + + BF9 = set_byte(ACopy, BeamFile, CompileInfoStart+10, 17), + verify(invalid_chunk, beam_lib:chunks(BF9, [compile_info])). + + +%% Compare contents of BEAM files and directories. cmp(Conf) when is_list(Conf) -> - ?line PrivDir = ?privdir, + PrivDir = ?privdir, - ?line Dir1 = filename:join(PrivDir, "dir1"), - ?line Dir2 = filename:join(PrivDir, "dir2"), + Dir1 = filename:join(PrivDir, "dir1"), + Dir2 = filename:join(PrivDir, "dir2"), ok = file:make_dir(Dir1), ok = file:make_dir(Dir2), - ?line {SourceD1, BeamFileD1} = make_beam(Dir1, simple, member), - ?line {Source2D1, BeamFile2D1} = make_beam(Dir1, simple2, concat), - ?line {SourceD2, BeamFileD2} = make_beam(Dir2, simple, concat), + {SourceD1, BeamFileD1} = make_beam(Dir1, simple, member), + {Source2D1, BeamFile2D1} = make_beam(Dir1, simple2, concat), + {SourceD2, BeamFileD2} = make_beam(Dir2, simple, concat), - ?line NoOfTables = length(ets:all()), - ?line P0 = pps(), + NoOfTables = length(ets:all()), + P0 = pps(), %% cmp - ?line ok = beam_lib:cmp(BeamFileD1, BeamFileD1), - ?line ver(modules_different, beam_lib:cmp(BeamFileD1, BeamFile2D1)), - ?line ver(chunks_different, beam_lib:cmp(BeamFileD1, BeamFileD2)), - ?line verify(file_error, beam_lib:cmp(foo, bar)), - - ?line {ok, B1} = file:read_file(BeamFileD1), - ?line ok = beam_lib:cmp(B1, BeamFileD1), - ?line {ok, B2} = file:read_file(BeamFileD2), - ?line ver(chunks_different, beam_lib:cmp(B1, B2)), + ok = beam_lib:cmp(BeamFileD1, BeamFileD1), + ver(modules_different, beam_lib:cmp(BeamFileD1, BeamFile2D1)), + ver(chunks_different, beam_lib:cmp(BeamFileD1, BeamFileD2)), + verify(file_error, beam_lib:cmp(foo, bar)), + + {ok, B1} = file:read_file(BeamFileD1), + ok = beam_lib:cmp(B1, BeamFileD1), + {ok, B2} = file:read_file(BeamFileD2), + ver(chunks_different, beam_lib:cmp(B1, B2)), %% cmp_dirs - ?line {[],[],[]} = beam_lib:cmp_dirs(Dir1, Dir1), - ?line true = {[BeamFile2D1], [], [{BeamFileD1,BeamFileD2}]} == - beam_lib:cmp_dirs(Dir1, Dir2), - ?line true = {[], [BeamFile2D1], [{BeamFileD2,BeamFileD1}]} == - beam_lib:cmp_dirs(Dir2, Dir1), - ?line ver(not_a_directory, beam_lib:cmp_dirs(foo, bar)), - + {[],[],[]} = beam_lib:cmp_dirs(Dir1, Dir1), + true = {[BeamFile2D1], [], [{BeamFileD1,BeamFileD2}]} == + beam_lib:cmp_dirs(Dir1, Dir2), + true = {[], [BeamFile2D1], [{BeamFileD2,BeamFileD1}]} == + beam_lib:cmp_dirs(Dir2, Dir1), + ver(not_a_directory, beam_lib:cmp_dirs(foo, bar)), + %% diff_dirs - ?line ok = beam_lib:diff_dirs(Dir1, Dir1), - ?line ver(not_a_directory, beam_lib:diff_dirs(foo, bar)), + ok = beam_lib:diff_dirs(Dir1, Dir1), + ver(not_a_directory, beam_lib:diff_dirs(foo, bar)), - ?line true = (P0 == pps()), - ?line NoOfTables = length(ets:all()), - ?line delete_files([SourceD1, BeamFileD1, Source2D1, - BeamFile2D1, SourceD2, BeamFileD2]), + true = (P0 == pps()), + NoOfTables = length(ets:all()), + delete_files([SourceD1, BeamFileD1, Source2D1, + BeamFile2D1, SourceD2, BeamFileD2]), file:del_dir(Dir1), file:del_dir(Dir2), ok. -cmp_literals(suite) -> []; -cmp_literals(doc) -> ["Compare contents of BEAM files having literals"]; +%% Compare contents of BEAM files having literals. cmp_literals(Conf) when is_list(Conf) -> - ?line PrivDir = ?privdir, + PrivDir = ?privdir, - ?line Dir1 = filename:join(PrivDir, "dir1"), - ?line Dir2 = filename:join(PrivDir, "dir2"), + Dir1 = filename:join(PrivDir, "dir1"), + Dir2 = filename:join(PrivDir, "dir2"), ok = file:make_dir(Dir1), ok = file:make_dir(Dir2), - ?line {SourceD1, BeamFileD1} = make_beam(Dir1, simple, constant), - ?line {SourceD2, BeamFileD2} = make_beam(Dir2, simple, constant2), + {SourceD1, BeamFileD1} = make_beam(Dir1, simple, constant), + {SourceD2, BeamFileD2} = make_beam(Dir2, simple, constant2), - ?line NoOfTables = length(ets:all()), - ?line P0 = pps(), + NoOfTables = length(ets:all()), + P0 = pps(), %% cmp - ?line ok = beam_lib:cmp(BeamFileD1, BeamFileD1), - ?line ver(chunks_different, beam_lib:cmp(BeamFileD1, BeamFileD2)), - - ?line {ok, B1} = file:read_file(BeamFileD1), - ?line ok = beam_lib:cmp(B1, BeamFileD1), - ?line {ok, B2} = file:read_file(BeamFileD2), - ?line ver(chunks_different, beam_lib:cmp(B1, B2)), + ok = beam_lib:cmp(BeamFileD1, BeamFileD1), + ver(chunks_different, beam_lib:cmp(BeamFileD1, BeamFileD2)), + + {ok, B1} = file:read_file(BeamFileD1), + ok = beam_lib:cmp(B1, BeamFileD1), + {ok, B2} = file:read_file(BeamFileD2), + ver(chunks_different, beam_lib:cmp(B1, B2)), - ?line true = (P0 == pps()), - ?line NoOfTables = length(ets:all()), + true = (P0 == pps()), + NoOfTables = length(ets:all()), - ?line delete_files([SourceD1, BeamFileD1, SourceD2, BeamFileD2]), + delete_files([SourceD1, BeamFileD1, SourceD2, BeamFileD2]), file:del_dir(Dir1), file:del_dir(Dir2), ok. -strip(suite) -> []; -strip(doc) -> ["Strip BEAM files"]; +%% Strip BEAM files. strip(Conf) when is_list(Conf) -> - ?line PrivDir = ?privdir, - ?line {SourceD1, BeamFileD1} = make_beam(PrivDir, simple, member), - ?line {Source2D1, BeamFile2D1} = make_beam(PrivDir, simple2, concat), - ?line {Source3D1, BeamFile3D1} = make_beam(PrivDir, make_fun, make_fun), - ?line {Source4D1, BeamFile4D1} = make_beam(PrivDir, constant, constant), - ?line {Source5D1, BeamFile5D1} = make_beam(PrivDir, lines, lines), + PrivDir = ?privdir, + {SourceD1, BeamFileD1} = make_beam(PrivDir, simple, member), + {Source2D1, BeamFile2D1} = make_beam(PrivDir, simple2, concat), + {Source3D1, BeamFile3D1} = make_beam(PrivDir, make_fun, make_fun), + {Source4D1, BeamFile4D1} = make_beam(PrivDir, constant, constant), + {Source5D1, BeamFile5D1} = make_beam(PrivDir, lines, lines), - ?line NoOfTables = length(ets:all()), - ?line P0 = pps(), + NoOfTables = length(ets:all()), + P0 = pps(), %% strip binary - ?line verify(not_a_beam_file, beam_lib:strip(<<>>)), - ?line {ok, B1} = file:read_file(BeamFileD1), - ?line {ok, {simple, NB1}} = beam_lib:strip(B1), - ?line BId1 = chunk_ids(B1), - ?line NBId1 = chunk_ids(NB1), - ?line true = length(BId1) > length(NBId1), - ?line compare_chunks(B1, NB1, NBId1), + verify(not_a_beam_file, beam_lib:strip(<<>>)), + {ok, B1} = file:read_file(BeamFileD1), + {ok, {simple, NB1}} = beam_lib:strip(B1), + BId1 = chunk_ids(B1), + NBId1 = chunk_ids(NB1), + true = length(BId1) > length(NBId1), + compare_chunks(B1, NB1, NBId1), %% strip file - ?line verify(file_error, beam_lib:strip(foo)), - ?line {ok, {simple, _}} = beam_lib:strip(BeamFileD1), - ?line compare_chunks(NB1, BeamFileD1, NBId1), + verify(file_error, beam_lib:strip(foo)), + {ok, {simple, _}} = beam_lib:strip(BeamFileD1), + compare_chunks(NB1, BeamFileD1, NBId1), %% strip_files - ?line {ok, B2} = file:read_file(BeamFile2D1), - ?line {ok, [{simple,_},{simple2,_}]} = beam_lib:strip_files([B1, B2]), - ?line {ok, [{simple,_},{simple2,_},{make_fun,_},{constant,_}]} = + {ok, B2} = file:read_file(BeamFile2D1), + {ok, [{simple,_},{simple2,_}]} = beam_lib:strip_files([B1, B2]), + {ok, [{simple,_},{simple2,_},{make_fun,_},{constant,_}]} = beam_lib:strip_files([BeamFileD1, BeamFile2D1, BeamFile3D1, BeamFile4D1]), %% check that each module can be loaded. - ?line {module, simple} = code:load_abs(filename:rootname(BeamFileD1)), - ?line {module, simple2} = code:load_abs(filename:rootname(BeamFile2D1)), - ?line {module, make_fun} = code:load_abs(filename:rootname(BeamFile3D1)), - ?line {module, constant} = code:load_abs(filename:rootname(BeamFile4D1)), + {module, simple} = code:load_abs(filename:rootname(BeamFileD1)), + {module, simple2} = code:load_abs(filename:rootname(BeamFile2D1)), + {module, make_fun} = code:load_abs(filename:rootname(BeamFile3D1)), + {module, constant} = code:load_abs(filename:rootname(BeamFile4D1)), %% check that line number information is still present after stripping - ?line {module, lines} = code:load_abs(filename:rootname(BeamFile5D1)), - ?line {'EXIT',{badarith,[{lines,t,1,Info}|_]}} = + {module, lines} = code:load_abs(filename:rootname(BeamFile5D1)), + {'EXIT',{badarith,[{lines,t,1,Info}|_]}} = (catch lines:t(atom)), - ?line true = code:delete(lines), - ?line false = code:purge(lines), - ?line {ok, {lines,BeamFile5D1}} = beam_lib:strip(BeamFile5D1), - ?line {module, lines} = code:load_abs(filename:rootname(BeamFile5D1)), - ?line {'EXIT',{badarith,[{lines,t,1,Info}|_]}} = + true = code:delete(lines), + false = code:purge(lines), + {ok, {lines,BeamFile5D1}} = beam_lib:strip(BeamFile5D1), + {module, lines} = code:load_abs(filename:rootname(BeamFile5D1)), + {'EXIT',{badarith,[{lines,t,1,Info}|_]}} = (catch lines:t(atom)), - ?line true = (P0 == pps()), - ?line NoOfTables = length(ets:all()), + true = (P0 == pps()), + NoOfTables = length(ets:all()), - ?line delete_files([SourceD1, BeamFileD1, - Source2D1, BeamFile2D1, - Source3D1, BeamFile3D1, - Source4D1, BeamFile4D1, - Source5D1, BeamFile5D1]), + delete_files([SourceD1, BeamFileD1, + Source2D1, BeamFile2D1, + Source3D1, BeamFile3D1, + Source4D1, BeamFile4D1, + Source5D1, BeamFile5D1]), ok. otp_6711(Conf) when is_list(Conf) -> - ?line {'EXIT',{function_clause,_}} = (catch {a, beam_lib:info(3)}), - ?line {'EXIT',{function_clause,_}} = (catch {a, beam_lib:chunks(a, b)}), - ?line {'EXIT',{function_clause,_}} = (catch {a, beam_lib:chunks(a,b,c)}), - ?line {'EXIT',{function_clause,_}} = (catch {a, beam_lib:all_chunks(3)}), - ?line {'EXIT',{function_clause,_}} = (catch {a, beam_lib:cmp(3,4)}), - ?line {'EXIT',{function_clause,_}} = (catch {a, beam_lib:strip(3)}), - ?line {'EXIT',{function_clause,_}} = + {'EXIT',{function_clause,_}} = (catch {a, beam_lib:info(3)}), + {'EXIT',{function_clause,_}} = (catch {a, beam_lib:chunks(a, b)}), + {'EXIT',{function_clause,_}} = (catch {a, beam_lib:chunks(a,b,c)}), + {'EXIT',{function_clause,_}} = (catch {a, beam_lib:all_chunks(3)}), + {'EXIT',{function_clause,_}} = (catch {a, beam_lib:cmp(3,4)}), + {'EXIT',{function_clause,_}} = (catch {a, beam_lib:strip(3)}), + {'EXIT',{function_clause,_}} = (catch {a, beam_lib:strip_files([3])}), - ?line PrivDir = ?privdir, - ?line Dir = filename:join(PrivDir, "dir"), - ?line Lib = filename:join(Dir, "lib"), - ?line App = filename:join(Lib, "app"), - ?line EBin = filename:join(App, "ebin"), + PrivDir = ?privdir, + Dir = filename:join(PrivDir, "dir"), + Lib = filename:join(Dir, "lib"), + App = filename:join(Lib, "app"), + EBin = filename:join(App, "ebin"), ok = file:make_dir(Dir), ok = file:make_dir(Lib), ok = file:make_dir(App), ok = file:make_dir(EBin), - - ?line {SourceD, BeamFileD} = make_beam(EBin, simple, member), + + {SourceD, BeamFileD} = make_beam(EBin, simple, member), unwritable(BeamFileD), %% There is no way that strip_release can fail with %% function_clause or something like that... - ?line {error,_,{file_error,_,_}} = beam_lib:strip_release(Dir), + {error,_,{file_error,_,_}} = beam_lib:strip_release(Dir), - ?line delete_files([SourceD, BeamFileD]), + delete_files([SourceD, BeamFileD]), file:del_dir(EBin), file:del_dir(App), file:del_dir(Lib), @@ -434,59 +426,58 @@ unwritable(Fname) -> Mode = Info#file_info.mode - 8#00200, file:write_file_info(Fname, Info#file_info{mode = Mode}). -building(doc) -> "Testing building of BEAM files."; +%% Testing building of BEAM files. building(Conf) when is_list(Conf) -> - ?line PrivDir = ?privdir, + PrivDir = ?privdir, - ?line Dir1 = filename:join(PrivDir, "b_dir1"), - ?line Dir2 = filename:join(PrivDir, "b_dir2"), + Dir1 = filename:join(PrivDir, "b_dir1"), + Dir2 = filename:join(PrivDir, "b_dir2"), ok = file:make_dir(Dir1), ok = file:make_dir(Dir2), - ?line {SourceD1, BeamFileD1} = make_beam(Dir1, building, member), + {SourceD1, BeamFileD1} = make_beam(Dir1, building, member), - ?line NoOfTables = length(ets:all()), - ?line P0 = pps(), + NoOfTables = length(ets:all()), + P0 = pps(), %% read all chunks - ?line ChunkIds = chunk_ids(BeamFileD1), - ?line {ok, _Mod, Chunks} = beam_lib:all_chunks(BeamFileD1), - ?line ChunkIds = lists:map(fun ({Id, Data}) when is_binary(Data) -> Id - end, Chunks), + ChunkIds = chunk_ids(BeamFileD1), + {ok, _Mod, Chunks} = beam_lib:all_chunks(BeamFileD1), + ChunkIds = lists:map(fun ({Id, Data}) when is_binary(Data) -> Id + end, Chunks), %% write a new beam file, with reversed chunk order - ?line BeamFileD2 = filename:join(Dir2, "building.beam"), - ?line {ok,RevBeam} = beam_lib:build_module(lists:reverse(Chunks)), - ?line file:write_file(BeamFileD2, RevBeam), + BeamFileD2 = filename:join(Dir2, "building.beam"), + {ok,RevBeam} = beam_lib:build_module(lists:reverse(Chunks)), + file:write_file(BeamFileD2, RevBeam), %% compare files - ?line compare_chunks(BeamFileD1, BeamFileD2, ChunkIds), + compare_chunks(BeamFileD1, BeamFileD2, ChunkIds), %% test that we can retrieve a chunk before the atom table %% (actually, try to retrieve all chunks) - ?line lists:foreach(fun(Id) -> - {ok, {building, [{Id, _Data}]}} = - beam_lib:chunks(BeamFileD1, [Id]) - end, ChunkIds), - ?line lists:foreach(fun(Id) -> - {ok, {building, [{Id, _Data}]}} = - beam_lib:chunks(BeamFileD2, [Id]) - end, ChunkIds), + lists:foreach(fun(Id) -> + {ok, {building, [{Id, _Data}]}} = + beam_lib:chunks(BeamFileD1, [Id]) + end, ChunkIds), + lists:foreach(fun(Id) -> + {ok, {building, [{Id, _Data}]}} = + beam_lib:chunks(BeamFileD2, [Id]) + end, ChunkIds), - ?line true = (P0 == pps()), - ?line NoOfTables = length(ets:all()), + true = (P0 == pps()), + NoOfTables = length(ets:all()), - ?line delete_files([SourceD1, BeamFileD1, BeamFileD2]), + delete_files([SourceD1, BeamFileD1, BeamFileD2]), file:del_dir(Dir1), file:del_dir(Dir2), ok. -md5(suite) -> []; -md5(doc) -> ["Compare beam_lib:md5/1 and code:module_md5/1."]; +%% Compare beam_lib:md5/1 and code:module_md5/1. md5(Conf) when is_list(Conf) -> - ?line Beams = collect_beams(), + Beams = collect_beams(), io:format("Found ~w beam files", [length(Beams)]), md5_1(Beams). @@ -497,7 +488,7 @@ md5_1([N|Ns]) -> {Mod,MD5} = {Mod,code:module_md5(Beam)}, md5_1(Ns); md5_1([]) -> ok. - + collect_beams() -> SuperDir = filename:dirname(filename:dirname(code:which(?MODULE))), TestDirs = filelib:wildcard(filename:join([SuperDir,"*_test"])), @@ -511,90 +502,89 @@ collect_beams_1([]) -> []. maybe_uncompress(<<"FOR1",_/binary>>=Beam) -> Beam; maybe_uncompress(Beam) -> zlib:gunzip(Beam). -encrypted_abstr(suite) -> []; -encrypted_abstr(doc) -> ["Test encrypted abstract format"]; +%% Test encrypted abstract format. encrypted_abstr(Conf) when is_list(Conf) -> run_if_crypto_works(fun() -> encrypted_abstr_1(Conf) end). encrypted_abstr_1(Conf) -> - ?line PrivDir = ?privdir, - ?line Simple = filename:join(PrivDir, "simple"), - ?line Source = Simple ++ ".erl", - ?line BeamFile = Simple ++ ".beam", - ?line simple_file(Source), + PrivDir = ?privdir, + Simple = filename:join(PrivDir, "simple"), + Source = Simple ++ ".erl", + BeamFile = Simple ++ ".beam", + simple_file(Source), %% Avoid getting an extra port when crypto starts erl_ddll. - ?line erl_ddll:start(), + erl_ddll:start(), - ?line NoOfTables = length(ets:all()), - ?line P0 = pps(), + NoOfTables = length(ets:all()), + P0 = pps(), Key = "#a_crypto_key", CompileFlags = [{outdir,PrivDir}, debug_info, {debug_info_key,Key}], - ?line {ok,_} = compile:file(Source, CompileFlags), - ?line {ok, Binary} = file:read_file(BeamFile), + {ok,_} = compile:file(Source, CompileFlags), + {ok, Binary} = file:read_file(BeamFile), - ?line do_encrypted_abstr(BeamFile, Key), - ?line do_encrypted_abstr(Binary, Key), + do_encrypted_abstr(BeamFile, Key), + do_encrypted_abstr(Binary, Key), - ?line ok = crypto:stop(), %To get rid of extra ets tables. - ?line file:delete(BeamFile), - ?line file:delete(Source), - ?line NoOfTables = length(ets:all()), - ?line true = (P0 == pps()), + ok = crypto:stop(), %To get rid of extra ets tables. + file:delete(BeamFile), + file:delete(Source), + NoOfTables = length(ets:all()), + true = (P0 == pps()), ok. do_encrypted_abstr(Beam, Key) -> - ?line verify(key_missing_or_invalid, beam_lib:chunks(Beam, [abstract_code])), + verify(key_missing_or_invalid, beam_lib:chunks(Beam, [abstract_code])), %% The raw chunk "Abst" can still be read even without a key. - ?line {ok,{simple,[{"Abst",Abst}]}} = beam_lib:chunks(Beam, ["Abst"]), - ?line <<0:8,8:8,"des3_cbc",_/binary>> = Abst, + {ok,{simple,[{"Abst",Abst}]}} = beam_lib:chunks(Beam, ["Abst"]), + <<0:8,8:8,"des3_cbc",_/binary>> = Abst, %% Try som invalid funs. - ?line bad_fun(badfun, fun() -> ok end), - ?line bad_fun(badfun, {a,b}), - ?line bad_fun(blurf), - ?line {function_clause,_} = bad_fun(fun(glurf) -> ok end), + bad_fun(badfun, fun() -> ok end), + bad_fun(badfun, {a,b}), + bad_fun(blurf), + {function_clause,_} = bad_fun(fun(glurf) -> ok end), %% Funs that return something strange. - ?line bad_fun(badfun, fun(init) -> {ok,fun() -> ok end} end), - ?line glurf = bad_fun(fun(init) -> {error,glurf} end), + bad_fun(badfun, fun(init) -> {ok,fun() -> ok end} end), + glurf = bad_fun(fun(init) -> {error,glurf} end), %% Try clearing (non-existing fun). - ?line undefined = beam_lib:clear_crypto_key_fun(), + undefined = beam_lib:clear_crypto_key_fun(), %% Install a fun which cannot retrieve a key. - ?line ok = beam_lib:crypto_key_fun(fun(init) -> ok end), - ?line {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), + ok = beam_lib:crypto_key_fun(fun(init) -> ok end), + {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), %% Install a fun which returns an incorrect key. - ?line {ok,_} = beam_lib:clear_crypto_key_fun(), - ?line ok = beam_lib:crypto_key_fun(simple_crypto_fun("wrong key...")), - ?line {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), - + {ok,_} = beam_lib:clear_crypto_key_fun(), + ok = beam_lib:crypto_key_fun(simple_crypto_fun("wrong key...")), + {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), + %% Installing a new key fun is not possible without clearing the old. - ?line verify(exists, beam_lib:crypto_key_fun(simple_crypto_fun(Key))), + verify(exists, beam_lib:crypto_key_fun(simple_crypto_fun(Key))), %% Install the simplest possible working key fun. - ?line {ok,_} = beam_lib:clear_crypto_key_fun(), - ?line ok = beam_lib:crypto_key_fun(simple_crypto_fun(Key)), - ?line verify_abstract(Beam), - ?line {ok,{simple,[{"Abst",Abst}]}} = beam_lib:chunks(Beam, ["Abst"]), + {ok,_} = beam_lib:clear_crypto_key_fun(), + ok = beam_lib:crypto_key_fun(simple_crypto_fun(Key)), + verify_abstract(Beam), + {ok,{simple,[{"Abst",Abst}]}} = beam_lib:chunks(Beam, ["Abst"]), %% Installing a new key fun is not possible without clearing the old. verify(exists, beam_lib:crypto_key_fun(ets_crypto_fun(Key))), %% Install a key using an ets table. - ?line {ok,_} = beam_lib:clear_crypto_key_fun(), - ?line ok = beam_lib:crypto_key_fun(ets_crypto_fun(Key)), - ?line verify_abstract(Beam), - ?line {ok,{simple,[{"Abst",Abst}]}} = beam_lib:chunks(Beam, ["Abst"]), + {ok,_} = beam_lib:clear_crypto_key_fun(), + ok = beam_lib:crypto_key_fun(ets_crypto_fun(Key)), + verify_abstract(Beam), + {ok,{simple,[{"Abst",Abst}]}} = beam_lib:chunks(Beam, ["Abst"]), - ?line {ok,cleared} = beam_lib:clear_crypto_key_fun(), + {ok,cleared} = beam_lib:clear_crypto_key_fun(), %% Try to force a stop/start race. - ?line start_stop_race(10000), + start_stop_race(10000), ok. @@ -635,69 +625,67 @@ ets_crypto_fun(Key) -> end} end. -encrypted_abstr_file(suite) -> []; -encrypted_abstr_file(doc) -> - ["Test encrypted abstract format with the key in .erlang.crypt"]; +%% Test encrypted abstract format with the key in .erlang.crypt. encrypted_abstr_file(Conf) when is_list(Conf) -> run_if_crypto_works(fun() -> encrypted_abstr_file_1(Conf) end). encrypted_abstr_file_1(Conf) -> - ?line PrivDir = ?privdir, - ?line Simple = filename:join(PrivDir, "simple"), - ?line Source = Simple ++ ".erl", - ?line BeamFile = Simple ++ ".beam", - ?line simple_file(Source), + PrivDir = ?privdir, + Simple = filename:join(PrivDir, "simple"), + Source = Simple ++ ".erl", + BeamFile = Simple ++ ".beam", + simple_file(Source), %% Avoid getting an extra port when crypto starts erl_ddll. - ?line erl_ddll:start(), + erl_ddll:start(), - ?line NoOfTables = length(ets:all()), - ?line P0 = pps(), + NoOfTables = length(ets:all()), + P0 = pps(), Key = "Long And niCe 99Krypto Key", CompileFlags = [{outdir,PrivDir}, debug_info, {debug_info_key,Key}], - ?line {ok,_} = compile:file(Source, CompileFlags), - ?line {ok, Binary} = file:read_file(BeamFile), - - ?line {ok,OldCwd} = file:get_cwd(), - ?line ok = file:set_cwd(PrivDir), - ?line do_encrypted_abstr_file(BeamFile, Key), - ?line do_encrypted_abstr_file(Binary, Key), - ?line ok = file:set_cwd(OldCwd), - - ?line ok = crypto:stop(), %To get rid of extra ets tables. - ?line file:delete(filename:join(PrivDir, ".erlang.crypt")), - ?line file:delete(BeamFile), - ?line file:delete(Source), - ?line NoOfTables = length(ets:all()), - ?line true = (P0 == pps()), + {ok,_} = compile:file(Source, CompileFlags), + {ok, Binary} = file:read_file(BeamFile), + + {ok,OldCwd} = file:get_cwd(), + ok = file:set_cwd(PrivDir), + do_encrypted_abstr_file(BeamFile, Key), + do_encrypted_abstr_file(Binary, Key), + ok = file:set_cwd(OldCwd), + + ok = crypto:stop(), %To get rid of extra ets tables. + file:delete(filename:join(PrivDir, ".erlang.crypt")), + file:delete(BeamFile), + file:delete(Source), + NoOfTables = length(ets:all()), + true = (P0 == pps()), ok. do_encrypted_abstr_file(Beam, Key) -> %% No key. - ?line write_crypt_file(""), - ?line {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), + write_crypt_file(""), + {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), %% A wrong key. - ?line write_crypt_file(["[{debug_info,des3_cbc,simple,\"A Wrong Key\"}].\n"]), - ?line {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), + write_crypt_file(["[{debug_info,des3_cbc,simple,\"A Wrong Key\"}].\n"]), + {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), %% Write correct key... - ?line write_crypt_file(["[{debug_info,des3_cbc,simple,\"",Key,"\"}].\n"]), + write_crypt_file(["[{debug_info,des3_cbc,simple,\"",Key,"\"}].\n"]), %% ... but the fun with the wrong key is still there. - ?line {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), + {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), %% Clear the fun. Now it should work. - ?line {ok,_} = beam_lib:clear_crypto_key_fun(), - ?line verify_abstract(Beam), - ?line verify_abstract(Beam), - ?line ok = file:delete(".erlang.crypt"), - ?line verify_abstract(Beam), + {ok,_} = beam_lib:clear_crypto_key_fun(), + verify_abstract(Beam), + verify_abstract(Beam), + ok = file:delete(".erlang.crypt"), + verify_abstract(Beam), %% Clear, otherwise the second pass will fail. - ?line {ok,_} = beam_lib:clear_crypto_key_fun(), - ?line {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), + {ok,_} = beam_lib:clear_crypto_key_fun(), + {error,beam_lib,Error} = beam_lib:chunks(Beam, [abstract_code]), ok. write_crypt_file(Contents0) -> @@ -706,45 +694,44 @@ write_crypt_file(Contents0) -> ok = file:write_file(".erlang.crypt", Contents). compare_chunks(File1, File2, ChunkIds) -> - ?line {ok, {_, Chunks1}} = beam_lib:chunks(File1, ChunkIds), - ?line {ok, {_, Chunks2}} = beam_lib:chunks(File2, ChunkIds), - ?line true = Chunks1 == Chunks2. + {ok, {_, Chunks1}} = beam_lib:chunks(File1, ChunkIds), + {ok, {_, Chunks2}} = beam_lib:chunks(File2, ChunkIds), + true = Chunks1 == Chunks2. chunk_ids(File) -> - ?line lists:map(fun({Id,_Start,_Size}) -> Id end, chunk_info(File)). - + lists:map(fun({Id,_Start,_Size}) -> Id end, chunk_info(File)). + chunk_info(File) -> - ?line {value, {chunks, Chunks}} = + {value, {chunks, Chunks}} = lists:keysearch(chunks, 1, beam_lib:info(File)), Chunks. - + make_beam(Dir, Module, F) -> - ?line FileBase = filename:join(Dir, atom_to_list(Module)), - ?line Source = FileBase ++ ".erl", - ?line BeamFile = FileBase ++ ".beam", - ?line simple_file(Source, Module, F), - ?line {ok, _} = compile:file(Source, [{outdir,Dir}, debug_info, report]), + FileBase = filename:join(Dir, atom_to_list(Module)), + Source = FileBase ++ ".erl", + BeamFile = FileBase ++ ".beam", + simple_file(Source, Module, F), + {ok, _} = compile:file(Source, [{outdir,Dir}, debug_info, report]), {Source, BeamFile}. set_byte(_Backup, Binary, Pos, Byte) when is_binary(Binary) -> - ?line <<B1:Pos/binary, _:1/binary, B2/binary>> = Binary, + <<B1:Pos/binary, _:1/binary, B2/binary>> = Binary, NB = <<B1/binary, Byte:8, B2/binary>>, NB; set_byte(Backup, File, Pos, Byte) -> - ?line copy_file(Backup, File), - ?line set_byte(File, Pos, Byte), + copy_file(Backup, File), + set_byte(File, Pos, Byte), File. set_byte(File, Pos, Byte) -> - ?line {ok, Fd} = file:open(File, [read, write]), - ?line {ok, _} = file:position(Fd, Pos), - ?line ok = file:write(Fd, [Byte]), - ?line file:close(Fd). + {ok, Fd} = file:open(File, [read, write]), + {ok, _} = file:position(Fd, Pos), + ok = file:write(Fd, [Byte]), + file:close(Fd). copy_file(Src, Dest) -> - % ?t:format("copying from ~p to ~p~n", [Src, Dest]), - ?line {ok, _} = file:copy(Src, Dest), - ?line ok = file:change_mode(Dest, 8#0666). + {ok, _} = file:copy(Src, Dest), + ok = file:change_mode(Dest, 8#0666). delete_files(Files) -> lists:foreach(fun(F) -> file:delete(F) end, Files). @@ -772,7 +759,7 @@ ver(S, {error, beam_lib, R}) -> [S|_] = tuple_to_list(R), case lists:flatten(beam_lib:format_error(R)) of [${ | _] -> - test_server:fail({bad_format_error, R}); + ct:fail({bad_format_error, R}); _ -> ok end. diff --git a/lib/stdlib/test/binary_module_SUITE.erl b/lib/stdlib/test/binary_module_SUITE.erl index 8bb29b6a26..285740d3e0 100644 --- a/lib/stdlib/test/binary_module_SUITE.erl +++ b/lib/stdlib/test/binary_module_SUITE.erl @@ -20,6 +20,7 @@ -module(binary_module_SUITE). -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, + init_per_testcase/2, end_per_testcase/2, init_per_group/2,end_per_group/2, interesting/1,scope_return/1,random_ref_comp/1,random_ref_sr_comp/1, random_ref_fla_comp/1,parts/1, bin_to_list/1, list_to_bin/1, @@ -27,45 +28,17 @@ -export([random_number/1, make_unaligned/1]). - - -%%-define(STANDALONE,1). - --ifdef(STANDALONE). - --define(line,erlang:display({?MODULE,?LINE}),). - --else. - -include_lib("common_test/include/ct.hrl"). --export([init_per_testcase/2, end_per_testcase/2]). -% Default timetrap timeout (set in init_per_testcase). -% Some of these testcases are really heavy... --define(default_timeout, ?t:minutes(30)). - --endif. - - - --ifdef(STANDALONE). --export([run/0]). - -run() -> - [ apply(?MODULE,X,[[]]) || X <- all(suite) ]. - --else. init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. + Config. -end_per_testcase(_Case, Config) -> - ?line Dog = ?config(watchdog, Config), - ?line test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. --endif. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,30}}]. all() -> [scope_return,interesting, random_ref_fla_comp, random_ref_sr_comp, @@ -92,300 +65,297 @@ end_per_group(_GroupName, Config) -> -define(MASK_ERROR(EXPR),mask_error((catch (EXPR)))). -badargs(doc) -> - ["Tests various badarg exceptions in the module"]; +%% Test various badarg exceptions in the module. badargs(Config) when is_list(Config) -> - ?line badarg = ?MASK_ERROR(binary:compile_pattern([<<1,2,3:3>>])), - ?line badarg = ?MASK_ERROR(binary:compile_pattern([<<1,2,3>>|<<1,2>>])), - ?line badarg = ?MASK_ERROR(binary:compile_pattern(<<1,2,3:3>>)), - ?line badarg = ?MASK_ERROR(binary:compile_pattern(<<>>)), - ?line badarg = ?MASK_ERROR(binary:match(<<1,2,3:3>>,<<1>>)), - ?line badarg = ?MASK_ERROR(binary:matches(<<1,2,3:3>>,<<1>>)), - ?line badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>, - [{scope,{0,1},1}])), - ?line badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>, - [{scape,{0,1}}])), - ?line badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>, - [{scope,{0,1,1}}])), - ?line badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>,[{scope,0,1}])), - ?line badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>,[{scope,[0,1]}])), - ?line badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>, - [{scope,{0.1,1}}])), - ?line badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>, - [{scope,{1,1.1}}])), - ?line badarg = + badarg = ?MASK_ERROR(binary:compile_pattern([<<1,2,3:3>>])), + badarg = ?MASK_ERROR(binary:compile_pattern([<<1,2,3>>|<<1,2>>])), + badarg = ?MASK_ERROR(binary:compile_pattern(<<1,2,3:3>>)), + badarg = ?MASK_ERROR(binary:compile_pattern(<<>>)), + badarg = ?MASK_ERROR(binary:match(<<1,2,3:3>>,<<1>>)), + badarg = ?MASK_ERROR(binary:matches(<<1,2,3:3>>,<<1>>)), + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>, + [{scope,{0,1},1}])), + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>, + [{scape,{0,1}}])), + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>, + [{scope,{0,1,1}}])), + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>,[{scope,0,1}])), + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>,[{scope,[0,1]}])), + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>, + [{scope,{0.1,1}}])), + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>, + [{scope,{1,1.1}}])), + badarg = ?MASK_ERROR( binary:match(<<1,2,3>>,<<1>>, [{scope,{16#FF, 16#FFFFFFFFFFFFFFFF}}])), - ?line badarg = + badarg = ?MASK_ERROR( binary:match(<<1,2,3>>,<<1>>, [{scope,{16#FFFFFFFFFFFFFFFF, -16#7FFFFFFFFFFFFFFF-1}}])), - ?line badarg = + badarg = ?MASK_ERROR( binary:match(<<1,2,3>>,<<1>>, [{scope,{16#FFFFFFFFFFFFFFFF, 16#7FFFFFFFFFFFFFFF}}])), - ?line badarg = + badarg = ?MASK_ERROR( binary:part(<<1,2,3>>,{16#FF, - 16#FFFFFFFFFFFFFFFF})), - ?line badarg = + 16#FFFFFFFFFFFFFFFF})), + badarg = ?MASK_ERROR( binary:part(<<1,2,3>>,{16#FFFFFFFFFFFFFFFF, - -16#7FFFFFFFFFFFFFFF-1})), - ?line badarg = + -16#7FFFFFFFFFFFFFFF-1})), + badarg = ?MASK_ERROR( binary:part(<<1,2,3>>,{16#FFFFFFFFFFFFFFFF, - 16#7FFFFFFFFFFFFFFF})), - ?line badarg = + 16#7FFFFFFFFFFFFFFF})), + badarg = ?MASK_ERROR( binary:part(make_unaligned(<<1,2,3>>),{1,1,1})), - ?line badarg = + badarg = ?MASK_ERROR( binary_part(make_unaligned(<<1,2,3>>),{1,1,1})), - ?line badarg = + badarg = ?MASK_ERROR( binary_part(make_unaligned(<<1,2,3>>),{16#FFFFFFFFFFFFFFFF, - -16#7FFFFFFFFFFFFFFF-1})), - ?line badarg = + -16#7FFFFFFFFFFFFFFF-1})), + badarg = ?MASK_ERROR( binary_part(make_unaligned(<<1,2,3>>),{16#FF, - 16#FFFFFFFFFFFFFFFF})), - ?line badarg = + 16#FFFFFFFFFFFFFFFF})), + badarg = ?MASK_ERROR( binary_part(make_unaligned(<<1,2,3>>),{16#FFFFFFFFFFFFFFFF, - 16#7FFFFFFFFFFFFFFF})), - ?line badarg = + 16#7FFFFFFFFFFFFFFF})), + badarg = ?MASK_ERROR( binary_part(make_unaligned(<<1,2,3>>),{16#FFFFFFFFFFFFFFFFFF, - -16#7FFF})), - ?line badarg = + -16#7FFF})), + badarg = ?MASK_ERROR( binary_part(make_unaligned(<<1,2,3>>),{16#FF, - -16#7FFF})), - ?line badarg = + -16#7FFF})), + badarg = ?MASK_ERROR( binary:bin_to_list(<<1,2,3>>,{16#FF, - 16#FFFFFFFFFFFFFFFF})), - ?line badarg = + 16#FFFFFFFFFFFFFFFF})), + badarg = ?MASK_ERROR( binary:bin_to_list(<<1,2,3>>,{16#FFFFFFFFFFFFFFFF, - -16#7FFFFFFFFFFFFFFF-1})), - ?line badarg = + -16#7FFFFFFFFFFFFFFF-1})), + badarg = ?MASK_ERROR( binary:bin_to_list(<<1,2,3>>,{16#FFFFFFFFFFFFFFFF, - 16#7FFFFFFFFFFFFFFF})), - ?line [1,2,3] = + 16#7FFFFFFFFFFFFFFF})), + [1,2,3] = ?MASK_ERROR( binary:bin_to_list(<<1,2,3>>)), - ?line badarg = + badarg = ?MASK_ERROR( binary:bin_to_list(<<1,2,3>>,[])), - ?line badarg = + badarg = ?MASK_ERROR( binary:bin_to_list(<<1,2,3>>,{1,2,3})), - ?line badarg = + badarg = ?MASK_ERROR( binary:bin_to_list(<<1,2,3>>,{1.0,1})), - ?line badarg = + badarg = ?MASK_ERROR( binary:bin_to_list(<<1,2,3>>,{1,1.0})), - ?line badarg = + badarg = ?MASK_ERROR( binary:bin_to_list(<<1,2,3:3>>,{1,1})), - ?line badarg = + badarg = ?MASK_ERROR( binary:bin_to_list(<<1,2,3:3>>)), - ?line badarg = + badarg = ?MASK_ERROR( binary:bin_to_list([1,2,3])), - ?line nomatch = + nomatch = ?MASK_ERROR(binary:match(<<1,2,3>>,<<1>>,[{scope,{0,0}}])), - ?line badarg = + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,{bm,<<>>},[{scope,{0,1}}])), - ?line badarg = + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,[],[{scope,{0,1}}])), - ?line badarg = + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,{ac,<<>>},[{scope,{0,1}}])), - ?line {bm,BMMagic} = binary:compile_pattern([<<1,2,3>>]), - ?line {ac,ACMagic} = binary:compile_pattern([<<1,2,3>>,<<4,5>>]), - ?line badarg = + {bm,BMMagic} = binary:compile_pattern([<<1,2,3>>]), + {ac,ACMagic} = binary:compile_pattern([<<1,2,3>>,<<4,5>>]), + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,{bm,ACMagic},[{scope,{0,1}}])), - ?line badarg = + badarg = ?MASK_ERROR(binary:match(<<1,2,3>>,{ac,BMMagic},[{scope,{0,1}}])), - ?line badarg = + badarg = ?MASK_ERROR( binary:match(<<1,2,3>>, {bm,ets:match_spec_compile([{'_',[],['$_']}])}, [{scope,{0,1}}])), - ?line badarg = + badarg = ?MASK_ERROR( binary:match(<<1,2,3>>, {ac,ets:match_spec_compile([{'_',[],['$_']}])}, [{scope,{0,1}}])), - ?line [] = + [] = ?MASK_ERROR(binary:matches(<<1,2,3>>,<<1>>,[{scope,{0,0}}])), - ?line badarg = + badarg = ?MASK_ERROR(binary:matches(<<1,2,3>>,{bm,<<>>},[{scope,{0,1}}])), - ?line badarg = + badarg = ?MASK_ERROR(binary:matches(<<1,2,3>>,[],[{scope,{0,1}}])), - ?line badarg = + badarg = ?MASK_ERROR(binary:matches(<<1,2,3>>,{ac,<<>>},[{scope,{0,1}}])), - ?line badarg = + badarg = ?MASK_ERROR(binary:matches(<<1,2,3>>,{bm,ACMagic},[{scope,{0,1}}])), - ?line badarg = + badarg = ?MASK_ERROR(binary:matches(<<1,2,3>>,{ac,BMMagic},[{scope,{0,1}}])), - ?line badarg = + badarg = ?MASK_ERROR( binary:matches(<<1,2,3>>, - {bm,ets:match_spec_compile([{'_',[],['$_']}])}, - [{scope,{0,1}}])), - ?line badarg = + {bm,ets:match_spec_compile([{'_',[],['$_']}])}, + [{scope,{0,1}}])), + badarg = ?MASK_ERROR( binary:matches(<<1,2,3>>, - {ac,ets:match_spec_compile([{'_',[],['$_']}])}, - [{scope,{0,1}}])), + {ac,ets:match_spec_compile([{'_',[],['$_']}])}, + [{scope,{0,1}}])), %% OTP-11350 badarg = ?MASK_ERROR( binary:matches(<<"foo">>, [<<>>, <<"f">>])), - ?line badarg = + badarg = ?MASK_ERROR(binary:longest_common_prefix( [<<0:10000,1,2,4,1:3>>, <<0:10000,1,2,3>>])), - ?line badarg = + badarg = ?MASK_ERROR(binary:longest_common_suffix( [<<0:10000,1,2,4,1:3>>, <<0:10000,1,2,3>>])), - ?line badarg = + badarg = ?MASK_ERROR(binary:encode_unsigned(-1)), - ?line badarg = + badarg = ?MASK_ERROR( binary:encode_unsigned(-16#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), - ?line badarg = + badarg = ?MASK_ERROR( binary:first(<<1,2,4,1:3>>)), - ?line badarg = + badarg = ?MASK_ERROR( binary:first([1,2,4])), - ?line badarg = + badarg = ?MASK_ERROR( binary:last(<<1,2,4,1:3>>)), - ?line badarg = + badarg = ?MASK_ERROR( binary:last([1,2,4])), - ?line badarg = + badarg = ?MASK_ERROR( binary:at(<<1,2,4,1:3>>,2)), - ?line badarg = + badarg = ?MASK_ERROR( binary:at(<<>>,2)), - ?line badarg = + badarg = ?MASK_ERROR( binary:at([1,2,4],2)), ok. -longest_common_trap(doc) -> - ["Whitebox test to force special trap conditions in longest_common_{prefix,suffix}"]; +%% Whitebox test to force special trap conditions in +%% longest_common_{prefix,suffix}. longest_common_trap(Config) when is_list(Config) -> - ?line erts_debug:set_internal_state(available_internal_state,true), - ?line io:format("oldlimit: ~p~n", - [erts_debug:set_internal_state(binary_loop_limit,10)]), + erts_debug:set_internal_state(available_internal_state,true), + io:format("oldlimit: ~p~n", + [erts_debug:set_internal_state(binary_loop_limit,10)]), erlang:bump_reductions(10000000), - ?line _ = binary:longest_common_prefix( - [<<0:10000,1,2,4>>, - <<0:10000,1,2,3>>, - <<0:10000,1,3,3>>, - <<0:10000,1,2,4>>, - <<0:10000,1,2,4>>, - <<0:10000,1,2,3>>, - <<0:10000,1,3,3>>, - <<0:10000,1,2,3>>, - <<0:10000,1,3,3>>, - <<0:10000,1,2,4>>, - <<0:10000,1,2,4>>, - <<0:10000,1,2,3>>, - <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0:10000,1,3,3>>, - <<0:10000,1,2,4>>]), - ?line _ = binary:longest_common_prefix( - [<<0:10000,1,2,4>>, - <<0:10000,1,2,3>>, - <<0:10000,1,3,3>>, - <<0:10000,1,2,4>>, - <<0:10000,1,2,4>>, - <<0:10000,1,2,3>>, - <<0:10000,1,3,3>>, - <<0:10000,1,2,3>>, - <<0:10000,1,3,3>>, - <<0:10000,1,2,4>>, - <<0:10000,1,2,4>>, - <<0:10000,1,2,3>>, - <<0,0,0,0,0,0,0,0,0,0,0,0,0,0>>, - <<0:10000,1,2,4>>]), + _ = binary:longest_common_prefix( + [<<0:10000,1,2,4>>, + <<0:10000,1,2,3>>, + <<0:10000,1,3,3>>, + <<0:10000,1,2,4>>, + <<0:10000,1,2,4>>, + <<0:10000,1,2,3>>, + <<0:10000,1,3,3>>, + <<0:10000,1,2,3>>, + <<0:10000,1,3,3>>, + <<0:10000,1,2,4>>, + <<0:10000,1,2,4>>, + <<0:10000,1,2,3>>, + <<0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0:10000,1,3,3>>, + <<0:10000,1,2,4>>]), + _ = binary:longest_common_prefix( + [<<0:10000,1,2,4>>, + <<0:10000,1,2,3>>, + <<0:10000,1,3,3>>, + <<0:10000,1,2,4>>, + <<0:10000,1,2,4>>, + <<0:10000,1,2,3>>, + <<0:10000,1,3,3>>, + <<0:10000,1,2,3>>, + <<0:10000,1,3,3>>, + <<0:10000,1,2,4>>, + <<0:10000,1,2,4>>, + <<0:10000,1,2,3>>, + <<0,0,0,0,0,0,0,0,0,0,0,0,0,0>>, + <<0:10000,1,2,4>>]), erlang:bump_reductions(10000000), - ?line _ = binary:longest_common_suffix( - [<<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,3,3,0:10000,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>, - <<1,2,4,0:10000>>]), - ?line _ = binary:longest_common_suffix( - [<<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<1,2,4,0:10000>>, - <<0,0,0,0,0,0,0,0,0,0,0,0,0,0>>, - <<1,2,4,0:10000>>]), + _ = binary:longest_common_suffix( + [<<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,3,3,0:10000,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>, + <<1,2,4,0:10000>>]), + _ = binary:longest_common_suffix( + [<<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<1,2,4,0:10000>>, + <<0,0,0,0,0,0,0,0,0,0,0,0,0,0>>, + <<1,2,4,0:10000>>]), Subj = subj(), Len = byte_size(Subj), - ?line Len = binary:longest_common_suffix( - [Subj,Subj,Subj]), - ?line io:format("limit was: ~p~n", - [erts_debug:set_internal_state(binary_loop_limit, - default)]), - ?line erts_debug:set_internal_state(available_internal_state,false), + Len = binary:longest_common_suffix( + [Subj,Subj,Subj]), + io:format("limit was: ~p~n", + [erts_debug:set_internal_state(binary_loop_limit, + default)]), + erts_debug:set_internal_state(available_internal_state,false), ok. subj() -> - Me = self(), - spawn(fun() -> - X0 = iolist_to_binary([ - "1234567890", - %lists:seq(16#21, 16#7e), - lists:duplicate(100, $x) - ]), - Me ! X0, - receive X -> X end - end), - X0 = receive A -> A end, - <<X1:32/binary,_/binary>> = X0, - Subject= <<X1/binary>>, - Subject. - - -scope_return(doc) -> - ["Test correct return values for scopes (OTP-9701)."]; + Me = self(), + spawn(fun() -> + X0 = iolist_to_binary([ + "1234567890", + lists:duplicate(100, $x) + ]), + Me ! X0, + receive X -> X end + end), + X0 = receive A -> A end, + <<X1:32/binary,_/binary>> = X0, + Subject= <<X1/binary>>, + Subject. + + +%% Test correct return values for scopes (OTP-9701). scope_return(Config) when is_list(Config) -> N=10000, Bin=binary:copy(<<"a">>,N), @@ -394,364 +364,362 @@ scope_return(Config) when is_list(Config) -> scope_loop(_,N,N) -> ok; scope_loop(Bin,N,M) -> - ?line {N,1} = binary:match(Bin,<<"a">>,[{scope,{N,1}}]), - ?line {N,1} = binary:match(Bin,[<<"a">>,<<"b">>],[{scope,{N,1}}]), + {N,1} = binary:match(Bin,<<"a">>,[{scope,{N,1}}]), + {N,1} = binary:match(Bin,[<<"a">>,<<"b">>],[{scope,{N,1}}]), scope_loop(Bin,N+1,M). -interesting(doc) -> - ["Try some interesting patterns"]; +%% Try some interesting patterns. interesting(Config) when is_list(Config) -> X = do_interesting(binary), X = do_interesting(binref). do_interesting(Module) -> - ?line {0,4} = Module:match(<<"123456">>, + {0,4} = Module:match(<<"123456">>, Module:compile_pattern([<<"12">>,<<"1234">>, <<"23">>,<<"3">>, <<"34">>,<<"456">>, <<"45">>,<<"6">>])), - ?line [{0,4},{5,1}] = Module:matches(<<"123456">>, + [{0,4},{5,1}] = Module:matches(<<"123456">>, Module:compile_pattern([<<"12">>,<<"1234">>, <<"23">>,<<"3">>, <<"34">>,<<"456">>, <<"45">>,<<"6">>])), - ?line [{0,4}] = Module:matches(<<"123456">>, + [{0,4}] = Module:matches(<<"123456">>, Module:compile_pattern([<<"12">>,<<"1234">>, <<"23">>,<<"3">>, <<"34">>,<<"456">>, <<"45">>])), - ?line [{0,2},{2,2}] = Module:matches(<<"123456">>, - Module:compile_pattern([<<"12">>, - <<"23">>,<<"3">>, - <<"34">>,<<"456">>, - <<"45">>])), - ?line {1,4} = Module:match(<<"123456">>, + [{0,2},{2,2}] = Module:matches(<<"123456">>, + Module:compile_pattern([<<"12">>, + <<"23">>,<<"3">>, + <<"34">>,<<"456">>, + <<"45">>])), + {1,4} = Module:match(<<"123456">>, Module:compile_pattern([<<"34">>,<<"34">>, <<"12347">>,<<"2345">>])), - ?line [{1,4}] = Module:matches(<<"123456">>, + [{1,4}] = Module:matches(<<"123456">>, Module:compile_pattern([<<"34">>,<<"34">>, <<"12347">>,<<"2345">>])), - ?line [{2,2}] = Module:matches(<<"123456">>, + [{2,2}] = Module:matches(<<"123456">>, Module:compile_pattern([<<"34">>,<<"34">>, <<"12347">>,<<"2346">>])), - ?line {0,4} = Module:match(<<"123456">>, + {0,4} = Module:match(<<"123456">>, [<<"12">>,<<"1234">>, <<"23">>,<<"3">>, <<"34">>,<<"456">>, <<"45">>,<<"6">>]), - ?line [{0,4},{5,1}] = Module:matches(<<"123456">>, + [{0,4},{5,1}] = Module:matches(<<"123456">>, [<<"12">>,<<"1234">>, <<"23">>,<<"3">>, <<"34">>,<<"456">>, <<"45">>,<<"6">>]), - ?line [{0,4}] = Module:matches(<<"123456">>, + [{0,4}] = Module:matches(<<"123456">>, [<<"12">>,<<"1234">>, <<"23">>,<<"3">>, <<"34">>,<<"456">>, <<"45">>]), - ?line [{0,2},{2,2}] = Module:matches(<<"123456">>, - [<<"12">>, - <<"23">>,<<"3">>, - <<"34">>,<<"456">>, - <<"45">>]), - ?line {1,4} = Module:match(<<"123456">>, - [<<"34">>,<<"34">>, - <<"12347">>,<<"2345">>]), - ?line [{1,4}] = Module:matches(<<"123456">>, - [<<"34">>,<<"34">>, - <<"12347">>,<<"2345">>]), - ?line [{2,2}] = Module:matches(<<"123456">>, - [<<"34">>,<<"34">>, - <<"12347">>,<<"2346">>]), - ?line nomatch = Module:match(<<1,2,3,4>>,<<2>>,[{scope,{0,1}}]), - ?line {1,1} = Module:match(<<1,2,3,4>>,<<2>>,[{scope,{0,2}}]), - ?line nomatch = Module:match(<<1,2,3,4>>,<<2,3>>,[{scope,{0,2}}]), - ?line {1,2} = Module:match(<<1,2,3,4>>,<<2,3>>,[{scope,{0,3}}]), - ?line {1,2} = Module:match(<<1,2,3,4>>,<<2,3>>,[{scope,{0,4}}]), - ?line badarg = ?MASK_ERROR(Module:match(<<1,2,3,4>>,<<2,3>>, - [{scope,{0,5}}])), - ?line {1,2} = Module:match(<<1,2,3,4>>,<<2,3>>,[{scope,{4,-4}}]), - ?line {0,3} = Module:match(<<1,2,3,4>>,<<1,2,3>>,[{scope,{4,-4}}]), - ?line {0,4} = Module:match(<<1,2,3,4>>,<<1,2,3,4>>,[{scope,{4,-4}}]), - ?line badarg = ?MASK_ERROR(Module:match(<<1,2,3,4>>,<<1,2,3,4>>, - [{scope,{3,-4}}])), - ?line [] = Module:matches(<<1,2,3,4>>,<<2>>,[{scope,{0,1}}]), - ?line [{1,1}] = Module:matches(<<1,2,3,4>>,[<<2>>,<<3>>],[{scope,{0,2}}]), - ?line [] = Module:matches(<<1,2,3,4>>,<<2,3>>,[{scope,{0,2}}]), - ?line [{1,2}] = Module:matches(<<1,2,3,4>>,<<2,3>>,[{scope,{0,3}}]), - ?line [{1,2}] = Module:matches(<<1,2,3,4>>,<<2,3>>,[{scope,{0,4}}]), - ?line [{1,2}] = Module:matches(<<1,2,3,4>>,[<<2,3>>,<<4>>], - [{scope,{0,3}}]), - ?line [{1,2},{3,1}] = Module:matches(<<1,2,3,4>>,[<<2,3>>,<<4>>], - [{scope,{0,4}}]), - ?line badarg = ?MASK_ERROR(Module:matches(<<1,2,3,4>>,<<2,3>>, - [{scope,{0,5}}])), - ?line [{1,2}] = Module:matches(<<1,2,3,4>>,<<2,3>>,[{scope,{4,-4}}]), - ?line [{1,2},{3,1}] = Module:matches(<<1,2,3,4>>,[<<2,3>>,<<4>>], - [{scope,{4,-4}}]), - ?line [{0,3}] = Module:matches(<<1,2,3,4>>,<<1,2,3>>,[{scope,{4,-4}}]), - ?line [{0,4}] = Module:matches(<<1,2,3,4>>,<<1,2,3,4>>,[{scope,{4,-4}}]), - ?line badarg = ?MASK_ERROR(Module:matches(<<1,2,3,4>>,<<1,2,3,4>>, - [{scope,{3,-4}}])), - ?line badarg = ?MASK_ERROR(Module:matches(<<1,2,3,4>>,[<<1,2,3,4>>], - [{scope,{3,-4}}])), - ?line [<<1,2,3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>,<<4,5>>), - ?line [<<1,2,3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>]), - ?line [<<1,2,3>>,<<6>>,<<8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>],[global]), - ?line [<<1,2,3>>,<<6>>,<<>>,<<>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>], - [global]), - ?line [<<1,2,3>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>], - [global,trim]), - ?line [<<1,2,3>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>], - [global,trim_all]), - ?line [<<1,2,3,4,5,6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>], - [global,trim,{scope,{0,4}}]), - ?line [<<1,2,3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [{0,2},{2,2}] = Module:matches(<<"123456">>, + [<<"12">>, + <<"23">>,<<"3">>, + <<"34">>,<<"456">>, + <<"45">>]), + {1,4} = Module:match(<<"123456">>, + [<<"34">>,<<"34">>, + <<"12347">>,<<"2345">>]), + [{1,4}] = Module:matches(<<"123456">>, + [<<"34">>,<<"34">>, + <<"12347">>,<<"2345">>]), + [{2,2}] = Module:matches(<<"123456">>, + [<<"34">>,<<"34">>, + <<"12347">>,<<"2346">>]), + nomatch = Module:match(<<1,2,3,4>>,<<2>>,[{scope,{0,1}}]), + {1,1} = Module:match(<<1,2,3,4>>,<<2>>,[{scope,{0,2}}]), + nomatch = Module:match(<<1,2,3,4>>,<<2,3>>,[{scope,{0,2}}]), + {1,2} = Module:match(<<1,2,3,4>>,<<2,3>>,[{scope,{0,3}}]), + {1,2} = Module:match(<<1,2,3,4>>,<<2,3>>,[{scope,{0,4}}]), + badarg = ?MASK_ERROR(Module:match(<<1,2,3,4>>,<<2,3>>, + [{scope,{0,5}}])), + {1,2} = Module:match(<<1,2,3,4>>,<<2,3>>,[{scope,{4,-4}}]), + {0,3} = Module:match(<<1,2,3,4>>,<<1,2,3>>,[{scope,{4,-4}}]), + {0,4} = Module:match(<<1,2,3,4>>,<<1,2,3,4>>,[{scope,{4,-4}}]), + badarg = ?MASK_ERROR(Module:match(<<1,2,3,4>>,<<1,2,3,4>>, + [{scope,{3,-4}}])), + [] = Module:matches(<<1,2,3,4>>,<<2>>,[{scope,{0,1}}]), + [{1,1}] = Module:matches(<<1,2,3,4>>,[<<2>>,<<3>>],[{scope,{0,2}}]), + [] = Module:matches(<<1,2,3,4>>,<<2,3>>,[{scope,{0,2}}]), + [{1,2}] = Module:matches(<<1,2,3,4>>,<<2,3>>,[{scope,{0,3}}]), + [{1,2}] = Module:matches(<<1,2,3,4>>,<<2,3>>,[{scope,{0,4}}]), + [{1,2}] = Module:matches(<<1,2,3,4>>,[<<2,3>>,<<4>>], + [{scope,{0,3}}]), + [{1,2},{3,1}] = Module:matches(<<1,2,3,4>>,[<<2,3>>,<<4>>], + [{scope,{0,4}}]), + badarg = ?MASK_ERROR(Module:matches(<<1,2,3,4>>,<<2,3>>, + [{scope,{0,5}}])), + [{1,2}] = Module:matches(<<1,2,3,4>>,<<2,3>>,[{scope,{4,-4}}]), + [{1,2},{3,1}] = Module:matches(<<1,2,3,4>>,[<<2,3>>,<<4>>], + [{scope,{4,-4}}]), + [{0,3}] = Module:matches(<<1,2,3,4>>,<<1,2,3>>,[{scope,{4,-4}}]), + [{0,4}] = Module:matches(<<1,2,3,4>>,<<1,2,3,4>>,[{scope,{4,-4}}]), + badarg = ?MASK_ERROR(Module:matches(<<1,2,3,4>>,<<1,2,3,4>>, + [{scope,{3,-4}}])), + badarg = ?MASK_ERROR(Module:matches(<<1,2,3,4>>,[<<1,2,3,4>>], + [{scope,{3,-4}}])), + [<<1,2,3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>,<<4,5>>), + [<<1,2,3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>]), + [<<1,2,3>>,<<6>>,<<8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>],[global]), + [<<1,2,3>>,<<6>>,<<>>,<<>>] = Module:split(<<1,2,3,4,5,6,7,8>>, [<<4,5>>,<<7>>,<<8>>], - [global,trim,{scope,{0,5}}]), - - ?line [<<>>,<<>>,<<3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<1>>,<<2>>,<<4,5>>], - [global,trim]), - ?line [<<3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<1>>,<<2>>,<<4,5>>], - [global,trim_all]), - - ?line [<<1,2,3>>,<<>>,<<7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<6>>], - [global,trim]), - ?line [<<1,2,3>>,<<7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<6>>], - [global,trim_all]), - ?line [<<>>,<<>>,<<3>>,<<>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<1>>,<<2>>,<<4>>,<<5>>,<<7>>,<<8>>], - [global,trim]), - ?line [<<3>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>, - [<<1>>,<<2>>,<<4>>,<<5>>,<<7>>,<<8>>], - [global,trim_all]), + [global]), + [<<1,2,3>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>], + [global,trim]), + [<<1,2,3>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>], + [global,trim_all]), + [<<1,2,3,4,5,6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>], + [global,trim,{scope,{0,4}}]), + [<<1,2,3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>], + [global,trim,{scope,{0,5}}]), + + [<<>>,<<>>,<<3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<1>>,<<2>>,<<4,5>>], + [global,trim]), + [<<3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<1>>,<<2>>,<<4,5>>], + [global,trim_all]), + + [<<1,2,3>>,<<>>,<<7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<6>>], + [global,trim]), + [<<1,2,3>>,<<7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<6>>], + [global,trim_all]), + [<<>>,<<>>,<<3>>,<<>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<1>>,<<2>>,<<4>>,<<5>>,<<7>>,<<8>>], + [global,trim]), + [<<3>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>, + [<<1>>,<<2>>,<<4>>,<<5>>,<<7>>,<<8>>], + [global,trim_all]), [<<>>] = binary:split(<<>>, <<",">>, []), [] = binary:split(<<>>, <<",">>, [trim]), [] = binary:split(<<>>, <<",">>, [trim_all]), [] = binary:split(<<>>, <<",">>, [global,trim]), [] = binary:split(<<>>, <<",">>, [global,trim_all]), - ?line badarg = ?MASK_ERROR( - Module:replace(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>],<<99>>, - [global,trim,{scope,{0,5}}])), - ?line <<1,2,3,99,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>],<<99>>,[]), - ?line <<1,2,3,99,6,99,99>> = Module:replace(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>],<<99>>, - [global]), - ?line <<1,2,3,99,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>],<<99>>, - [global,{scope,{0,5}}]), - ?line <<1,2,3,99,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>],<<99>>, - [global,{scope,{0,5}}]), - ?line <<1,2,3,99,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>],<<99>>, - [global,{scope,{0,5}}]), - ?line badarg = ?MASK_ERROR(Module:replace(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>],<<99>>, - [global,{scope,{0,5}}, - {insert,1}])), - ?line <<1,2,3,99,4,5,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>],<<99>>, - [global,{scope,{0,5}}, - {insert_replaced,1}]), - ?line <<1,2,3,9,4,5,9,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>], - <<9,9>>, - [global,{scope,{0,5}}, - {insert_replaced,1}]), - ?line badarg = ?MASK_ERROR(Module:replace(<<1,2,3,4,5,6,7,8>>, - [<<4,5>>,<<7>>,<<8>>],<<>>, - [global,{scope,{0,5}}, - {insert_replaced,1}])), - ?line 2 = Module:longest_common_prefix([<<1,2,4>>,<<1,2,3>>]), - ?line 2 = Module:longest_common_prefix([<<1,2,4>>,<<1,2>>]), - ?line 1 = Module:longest_common_prefix([<<1,2,4>>,<<1>>]), - ?line 0 = Module:longest_common_prefix([<<1,2,4>>,<<>>]), - ?line 1 = Module:longest_common_prefix([<<1,2,4>>,<<1,2,3>>,<<1,3,3>>]), - ?line 1 = Module:longest_common_prefix([<<1,2,4>>,<<1,2,3>>,<<1,3,3>>,<<1,2,4>>]), - ?line 1251 = Module:longest_common_prefix([<<0:10000,1,2,4>>, - <<0:10000,1,2,3>>, - <<0:10000,1,3,3>>, - <<0:10000,1,2,4>>]), - ?line 12501 = Module:longest_common_prefix([<<0:100000,1,2,4>>, - <<0:100000,1,2,3>>, - <<0:100000,1,3,3>>, - <<0:100000,1,2,4>>]), - ?line 1251 = Module:longest_common_prefix( - [make_unaligned(<<0:10000,1,2,4>>), - <<0:10000,1,2,3>>, - make_unaligned(<<0:10000,1,3,3>>), - <<0:10000,1,2,4>>]), - ?line 12501 = Module:longest_common_prefix( - [<<0:100000,1,2,4>>, - make_unaligned(<<0:100000,1,2,3>>), - <<0:100000,1,3,3>>, - make_unaligned(<<0:100000,1,2,4>>)]), - ?line 1250001 = Module:longest_common_prefix([<<0:10000000,1,2,4>>, - <<0:10000000,1,2,3>>, - <<0:10000000,1,3,3>>, - <<0:10000000,1,2,4>>]), + badarg = ?MASK_ERROR( + Module:replace(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>],<<99>>, + [global,trim,{scope,{0,5}}])), + <<1,2,3,99,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>],<<99>>,[]), + <<1,2,3,99,6,99,99>> = Module:replace(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>],<<99>>, + [global]), + <<1,2,3,99,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>],<<99>>, + [global,{scope,{0,5}}]), + <<1,2,3,99,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>],<<99>>, + [global,{scope,{0,5}}]), + <<1,2,3,99,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>],<<99>>, + [global,{scope,{0,5}}]), + badarg = ?MASK_ERROR(Module:replace(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>],<<99>>, + [global,{scope,{0,5}}, + {insert,1}])), + <<1,2,3,99,4,5,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>],<<99>>, + [global,{scope,{0,5}}, + {insert_replaced,1}]), + <<1,2,3,9,4,5,9,6,7,8>> = Module:replace(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>], + <<9,9>>, + [global,{scope,{0,5}}, + {insert_replaced,1}]), + badarg = ?MASK_ERROR(Module:replace(<<1,2,3,4,5,6,7,8>>, + [<<4,5>>,<<7>>,<<8>>],<<>>, + [global,{scope,{0,5}}, + {insert_replaced,1}])), + 2 = Module:longest_common_prefix([<<1,2,4>>,<<1,2,3>>]), + 2 = Module:longest_common_prefix([<<1,2,4>>,<<1,2>>]), + 1 = Module:longest_common_prefix([<<1,2,4>>,<<1>>]), + 0 = Module:longest_common_prefix([<<1,2,4>>,<<>>]), + 1 = Module:longest_common_prefix([<<1,2,4>>,<<1,2,3>>,<<1,3,3>>]), + 1 = Module:longest_common_prefix([<<1,2,4>>,<<1,2,3>>,<<1,3,3>>,<<1,2,4>>]), + 1251 = Module:longest_common_prefix([<<0:10000,1,2,4>>, + <<0:10000,1,2,3>>, + <<0:10000,1,3,3>>, + <<0:10000,1,2,4>>]), + 12501 = Module:longest_common_prefix([<<0:100000,1,2,4>>, + <<0:100000,1,2,3>>, + <<0:100000,1,3,3>>, + <<0:100000,1,2,4>>]), + 1251 = Module:longest_common_prefix( + [make_unaligned(<<0:10000,1,2,4>>), + <<0:10000,1,2,3>>, + make_unaligned(<<0:10000,1,3,3>>), + <<0:10000,1,2,4>>]), + 12501 = Module:longest_common_prefix( + [<<0:100000,1,2,4>>, + make_unaligned(<<0:100000,1,2,3>>), + <<0:100000,1,3,3>>, + make_unaligned(<<0:100000,1,2,4>>)]), + 1250001 = Module:longest_common_prefix([<<0:10000000,1,2,4>>, + <<0:10000000,1,2,3>>, + <<0:10000000,1,3,3>>, + <<0:10000000,1,2,4>>]), if % Too cruel for the reference implementation Module =:= binary -> - ?line erts_debug:set_internal_state(available_internal_state,true), - ?line io:format("oldlimit: ~p~n", - [erts_debug:set_internal_state( - binary_loop_limit,100)]), - ?line 1250001 = Module:longest_common_prefix( - [<<0:10000000,1,2,4>>, - <<0:10000000,1,2,3>>, - <<0:10000000,1,3,3>>, - <<0:10000000,1,2,4>>]), - ?line io:format("limit was: ~p~n", - [erts_debug:set_internal_state(binary_loop_limit, - default)]), - ?line erts_debug:set_internal_state(available_internal_state, - false); + erts_debug:set_internal_state(available_internal_state,true), + io:format("oldlimit: ~p~n", + [erts_debug:set_internal_state( + binary_loop_limit,100)]), + 1250001 = Module:longest_common_prefix( + [<<0:10000000,1,2,4>>, + <<0:10000000,1,2,3>>, + <<0:10000000,1,3,3>>, + <<0:10000000,1,2,4>>]), + io:format("limit was: ~p~n", + [erts_debug:set_internal_state(binary_loop_limit, + default)]), + erts_debug:set_internal_state(available_internal_state, + false); true -> ok end, - ?line 1 = Module:longest_common_suffix([<<0:100000000,1,2,4,5>>, - <<0:100000000,1,2,3,5>>, - <<0:100000000,1,3,3,5>>, - <<0:100000000,1,2,4,5>>]), - ?line 1 = Module:longest_common_suffix([<<1,2,4,5>>, - <<0:100000000,1,2,3,5>>, - <<0:100000000,1,3,3,5>>, - <<0:100000000,1,2,4,5>>]), - ?line 1 = Module:longest_common_suffix([<<1,2,4,5,5>>,<<5,5>>, - <<0:100000000,1,3,3,5,5>>, - <<0:100000000,1,2,4,5>>]), - ?line 0 = Module:longest_common_suffix([<<1,2,4,5,5>>,<<5,5>>, - <<0:100000000,1,3,3,5,5>>, - <<0:100000000,1,2,4>>]), - ?line 2 = Module:longest_common_suffix([<<1,2,4,5,5>>,<<5,5>>, - <<0:100000000,1,3,3,5,5>>, - <<0:100000000,1,2,4,5,5>>]), - ?line 1 = Module:longest_common_suffix([<<1,2,4,5,5>>,<<5>>, - <<0:100000000,1,3,3,5,5>>, - <<0:100000000,1,2,4,5,5>>]), - ?line 0 = Module:longest_common_suffix([<<1,2,4,5,5>>,<<>>, - <<0:100000000,1,3,3,5,5>>, - <<0:100000000,1,2,4,5,5>>]), - ?line 0 = Module:longest_common_suffix([<<>>,<<0:100000000,1,3,3,5,5>>, - <<0:100000000,1,2,4,5,5>>]), - ?line 0 = Module:longest_common_suffix([<<>>,<<0:100000000,1,3,3,5,5>>, - <<0:100000000,1,2,4,5,5>>]), - ?line 2 = Module:longest_common_suffix([<<5,5>>,<<0:100000000,1,3,3,5,5>>, - <<0:100000000,1,2,4,5,5>>]), - ?line 2 = Module:longest_common_suffix([<<5,5>>,<<5,5>>,<<4,5,5>>]), - ?line 2 = Module:longest_common_suffix([<<5,5>>,<<5,5>>,<<5,5>>]), - ?line 3 = Module:longest_common_suffix([<<4,5,5>>,<<4,5,5>>,<<4,5,5>>]), - ?line 0 = Module:longest_common_suffix([<<>>]), - ?line badarg = ?MASK_ERROR(Module:longest_common_suffix([])), - ?line badarg = ?MASK_ERROR(Module:longest_common_suffix([apa])), - ?line badarg = ?MASK_ERROR(Module:longest_common_suffix([[<<>>]])), - ?line badarg = ?MASK_ERROR(Module:longest_common_suffix([[<<0>>, - <<1:9>>]])), - ?line 0 = Module:longest_common_prefix([<<>>]), - ?line badarg = ?MASK_ERROR(Module:longest_common_prefix([])), - ?line badarg = ?MASK_ERROR(Module:longest_common_prefix([apa])), - ?line badarg = ?MASK_ERROR(Module:longest_common_prefix([[<<>>]])), - ?line badarg = ?MASK_ERROR(Module:longest_common_prefix([[<<0>>, - <<1:9>>]])), - - ?line <<1:6,Bin:3/binary,_:2>> = <<1:6,1,2,3,1:2>>, - ?line <<1,2,3>> = Bin, - ?line 1 = Module:first(Bin), - ?line 1 = Module:first(<<1>>), - ?line 1 = Module:first(<<1,2,3>>), - ?line badarg = ?MASK_ERROR(Module:first(<<>>)), - ?line badarg = ?MASK_ERROR(Module:first(apa)), - ?line 3 = Module:last(Bin), - ?line 1 = Module:last(<<1>>), - ?line 3 = Module:last(<<1,2,3>>), - ?line badarg = ?MASK_ERROR(Module:last(<<>>)), - ?line badarg = ?MASK_ERROR(Module:last(apa)), - ?line 1 = Module:at(Bin,0), - ?line 1 = Module:at(<<1>>,0), - ?line 1 = Module:at(<<1,2,3>>,0), - ?line 2 = Module:at(<<1,2,3>>,1), - ?line 3 = Module:at(<<1,2,3>>,2), - ?line badarg = ?MASK_ERROR(Module:at(<<1,2,3>>,3)), - ?line badarg = ?MASK_ERROR(Module:at(<<1,2,3>>,-1)), - ?line badarg = ?MASK_ERROR(Module:at(<<1,2,3>>,apa)), - ?line "hejsan" = [ Module:at(<<"hejsan">>,I) || I <- lists:seq(0,5) ], - - ?line badarg = ?MASK_ERROR(Module:bin_to_list(<<1,2,3>>,3,-4)), - ?line [1,2,3] = ?MASK_ERROR(Module:bin_to_list(<<1,2,3>>,3,-3)), - - ?line badarg = ?MASK_ERROR(Module:decode_unsigned(<<1,2,1:2>>,big)), - ?line badarg = ?MASK_ERROR(Module:decode_unsigned(<<1,2,1:2>>,little)), - ?line badarg = ?MASK_ERROR(Module:decode_unsigned(apa)), - ?line badarg = ?MASK_ERROR(Module:decode_unsigned(125,little)), - ?line 0 = ?MASK_ERROR(Module:decode_unsigned(<<>>,little)), - ?line 0 = ?MASK_ERROR(Module:decode_unsigned(<<>>,big)), - ?line 0 = ?MASK_ERROR(Module:decode_unsigned(<<0>>,little)), - ?line 0 = ?MASK_ERROR(Module:decode_unsigned(<<0>>,big)), - ?line 0 = ?MASK_ERROR(Module:decode_unsigned(make_unaligned(<<0>>), - little)), - ?line 0 = ?MASK_ERROR(Module:decode_unsigned(make_unaligned(<<0>>),big)), - ?line badarg = ?MASK_ERROR(Module:encode_unsigned(apa)), - ?line badarg = ?MASK_ERROR(Module:encode_unsigned(125.3,little)), - ?line badarg = ?MASK_ERROR(Module:encode_unsigned({1},little)), - ?line badarg = ?MASK_ERROR(Module:encode_unsigned([1],little)), - ?line <<0>> = ?MASK_ERROR(Module:encode_unsigned(0,little)), - ?line <<0>> = ?MASK_ERROR(Module:encode_unsigned(0,big)), + 1 = Module:longest_common_suffix([<<0:100000000,1,2,4,5>>, + <<0:100000000,1,2,3,5>>, + <<0:100000000,1,3,3,5>>, + <<0:100000000,1,2,4,5>>]), + 1 = Module:longest_common_suffix([<<1,2,4,5>>, + <<0:100000000,1,2,3,5>>, + <<0:100000000,1,3,3,5>>, + <<0:100000000,1,2,4,5>>]), + 1 = Module:longest_common_suffix([<<1,2,4,5,5>>,<<5,5>>, + <<0:100000000,1,3,3,5,5>>, + <<0:100000000,1,2,4,5>>]), + 0 = Module:longest_common_suffix([<<1,2,4,5,5>>,<<5,5>>, + <<0:100000000,1,3,3,5,5>>, + <<0:100000000,1,2,4>>]), + 2 = Module:longest_common_suffix([<<1,2,4,5,5>>,<<5,5>>, + <<0:100000000,1,3,3,5,5>>, + <<0:100000000,1,2,4,5,5>>]), + 1 = Module:longest_common_suffix([<<1,2,4,5,5>>,<<5>>, + <<0:100000000,1,3,3,5,5>>, + <<0:100000000,1,2,4,5,5>>]), + 0 = Module:longest_common_suffix([<<1,2,4,5,5>>,<<>>, + <<0:100000000,1,3,3,5,5>>, + <<0:100000000,1,2,4,5,5>>]), + 0 = Module:longest_common_suffix([<<>>,<<0:100000000,1,3,3,5,5>>, + <<0:100000000,1,2,4,5,5>>]), + 0 = Module:longest_common_suffix([<<>>,<<0:100000000,1,3,3,5,5>>, + <<0:100000000,1,2,4,5,5>>]), + 2 = Module:longest_common_suffix([<<5,5>>,<<0:100000000,1,3,3,5,5>>, + <<0:100000000,1,2,4,5,5>>]), + 2 = Module:longest_common_suffix([<<5,5>>,<<5,5>>,<<4,5,5>>]), + 2 = Module:longest_common_suffix([<<5,5>>,<<5,5>>,<<5,5>>]), + 3 = Module:longest_common_suffix([<<4,5,5>>,<<4,5,5>>,<<4,5,5>>]), + 0 = Module:longest_common_suffix([<<>>]), + badarg = ?MASK_ERROR(Module:longest_common_suffix([])), + badarg = ?MASK_ERROR(Module:longest_common_suffix([apa])), + badarg = ?MASK_ERROR(Module:longest_common_suffix([[<<>>]])), + badarg = ?MASK_ERROR(Module:longest_common_suffix([[<<0>>, + <<1:9>>]])), + 0 = Module:longest_common_prefix([<<>>]), + badarg = ?MASK_ERROR(Module:longest_common_prefix([])), + badarg = ?MASK_ERROR(Module:longest_common_prefix([apa])), + badarg = ?MASK_ERROR(Module:longest_common_prefix([[<<>>]])), + badarg = ?MASK_ERROR(Module:longest_common_prefix([[<<0>>, + <<1:9>>]])), + + <<1:6,Bin:3/binary,_:2>> = <<1:6,1,2,3,1:2>>, + <<1,2,3>> = Bin, + 1 = Module:first(Bin), + 1 = Module:first(<<1>>), + 1 = Module:first(<<1,2,3>>), + badarg = ?MASK_ERROR(Module:first(<<>>)), + badarg = ?MASK_ERROR(Module:first(apa)), + 3 = Module:last(Bin), + 1 = Module:last(<<1>>), + 3 = Module:last(<<1,2,3>>), + badarg = ?MASK_ERROR(Module:last(<<>>)), + badarg = ?MASK_ERROR(Module:last(apa)), + 1 = Module:at(Bin,0), + 1 = Module:at(<<1>>,0), + 1 = Module:at(<<1,2,3>>,0), + 2 = Module:at(<<1,2,3>>,1), + 3 = Module:at(<<1,2,3>>,2), + badarg = ?MASK_ERROR(Module:at(<<1,2,3>>,3)), + badarg = ?MASK_ERROR(Module:at(<<1,2,3>>,-1)), + badarg = ?MASK_ERROR(Module:at(<<1,2,3>>,apa)), + "hejsan" = [ Module:at(<<"hejsan">>,I) || I <- lists:seq(0,5) ], + + badarg = ?MASK_ERROR(Module:bin_to_list(<<1,2,3>>,3,-4)), + [1,2,3] = ?MASK_ERROR(Module:bin_to_list(<<1,2,3>>,3,-3)), + + badarg = ?MASK_ERROR(Module:decode_unsigned(<<1,2,1:2>>,big)), + badarg = ?MASK_ERROR(Module:decode_unsigned(<<1,2,1:2>>,little)), + badarg = ?MASK_ERROR(Module:decode_unsigned(apa)), + badarg = ?MASK_ERROR(Module:decode_unsigned(125,little)), + 0 = ?MASK_ERROR(Module:decode_unsigned(<<>>,little)), + 0 = ?MASK_ERROR(Module:decode_unsigned(<<>>,big)), + 0 = ?MASK_ERROR(Module:decode_unsigned(<<0>>,little)), + 0 = ?MASK_ERROR(Module:decode_unsigned(<<0>>,big)), + 0 = ?MASK_ERROR(Module:decode_unsigned(make_unaligned(<<0>>), + little)), + 0 = ?MASK_ERROR(Module:decode_unsigned(make_unaligned(<<0>>),big)), + badarg = ?MASK_ERROR(Module:encode_unsigned(apa)), + badarg = ?MASK_ERROR(Module:encode_unsigned(125.3,little)), + badarg = ?MASK_ERROR(Module:encode_unsigned({1},little)), + badarg = ?MASK_ERROR(Module:encode_unsigned([1],little)), + <<0>> = ?MASK_ERROR(Module:encode_unsigned(0,little)), + <<0>> = ?MASK_ERROR(Module:encode_unsigned(0,big)), ok. -encode_decode(doc) -> - ["test binary:encode_unsigned/1,2 and binary:decode_unsigned/1,2"]; +%% Test binary:encode_unsigned/1,2 and binary:decode_unsigned/1,2. encode_decode(Config) when is_list(Config) -> rand:seed(exsplus, {1271,769940,559934}), - ?line ok = encode_decode_loop({1,200},1000), % Need to be long enough - % to create offheap binaries + ok = encode_decode_loop({1,200},1000), % Need to be long enough + % to create offheap binaries ok. encode_decode_loop(_Range,0) -> ok; encode_decode_loop(Range, X) -> - ?line N = random_number(Range), - ?line A = binary:encode_unsigned(N), - ?line B = binary:encode_unsigned(N,big), - ?line C = binref:encode_unsigned(N), - ?line D = binref:encode_unsigned(N,big), - ?line E = binary:encode_unsigned(N,little), - ?line F = binref:encode_unsigned(N,little), - ?line G = binary:decode_unsigned(A), - ?line H = binary:decode_unsigned(A,big), - ?line I = binref:decode_unsigned(A), - ?line J = binary:decode_unsigned(E,little), - ?line K = binref:decode_unsigned(E,little), - ?line L = binary:decode_unsigned(make_unaligned(A)), - ?line M = binary:decode_unsigned(make_unaligned(E),little), - ?line PaddedBig = <<0:48,A/binary>>, - ?line PaddedLittle = <<E/binary,0:48>>, - ?line O = binary:decode_unsigned(PaddedBig), - ?line P = binary:decode_unsigned(make_unaligned(PaddedBig)), - ?line Q = binary:decode_unsigned(PaddedLittle,little), - ?line R = binary:decode_unsigned(make_unaligned(PaddedLittle),little), - ?line S = binref:decode_unsigned(PaddedLittle,little), - ?line T = binref:decode_unsigned(PaddedBig), + N = random_number(Range), + A = binary:encode_unsigned(N), + B = binary:encode_unsigned(N,big), + C = binref:encode_unsigned(N), + D = binref:encode_unsigned(N,big), + E = binary:encode_unsigned(N,little), + F = binref:encode_unsigned(N,little), + G = binary:decode_unsigned(A), + H = binary:decode_unsigned(A,big), + I = binref:decode_unsigned(A), + J = binary:decode_unsigned(E,little), + K = binref:decode_unsigned(E,little), + L = binary:decode_unsigned(make_unaligned(A)), + M = binary:decode_unsigned(make_unaligned(E),little), + PaddedBig = <<0:48,A/binary>>, + PaddedLittle = <<E/binary,0:48>>, + O = binary:decode_unsigned(PaddedBig), + P = binary:decode_unsigned(make_unaligned(PaddedBig)), + Q = binary:decode_unsigned(PaddedLittle,little), + R = binary:decode_unsigned(make_unaligned(PaddedLittle),little), + S = binref:decode_unsigned(PaddedLittle,little), + T = binref:decode_unsigned(PaddedBig), case (((A =:= B) and (B =:= C) and (C =:= D)) and - ((E =:= F)) and - ((N =:= G) and (G =:= H) and (H =:= I) and - (I =:= J) and (J =:= K) and (K =:= L) and (L =:= M)) and - ((M =:= O) and (O =:= P) and (P =:= Q) and (Q =:= R) and - (R =:= S) and (S =:= T)))of + ((E =:= F)) and + ((N =:= G) and (G =:= H) and (H =:= I) and + (I =:= J) and (J =:= K) and (K =:= L) and (L =:= M)) and + ((M =:= O) and (O =:= P) and (P =:= Q) and (Q =:= R) and + (R =:= S) and (S =:= T)))of true -> encode_decode_loop(Range,X-1); _ -> @@ -760,90 +728,86 @@ encode_decode_loop(Range, X) -> exit(mismatch) end. -guard(doc) -> - ["Smoke test of the guard BIFs binary_part/2,3"]; +%% Smoke test of the guard BIFs binary_part/2,3. guard(Config) when is_list(Config) -> {comment, "Guard tests are run in emulator test suite"}. -referenced(doc) -> - ["Test refernced_byte_size/1 bif."]; +%% Test referenced_byte_size/1 bif. referenced(Config) when is_list(Config) -> - ?line badarg = ?MASK_ERROR(binary:referenced_byte_size([])), - ?line badarg = ?MASK_ERROR(binary:referenced_byte_size(apa)), - ?line badarg = ?MASK_ERROR(binary:referenced_byte_size({})), - ?line badarg = ?MASK_ERROR(binary:referenced_byte_size(1)), - ?line A = <<1,2,3>>, - ?line B = binary:copy(A,1000), - ?line 3 = binary:referenced_byte_size(A), - ?line 3000 = binary:referenced_byte_size(B), - ?line <<_:8,C:2/binary>> = A, - ?line 3 = binary:referenced_byte_size(C), - ?line 2 = binary:referenced_byte_size(binary:copy(C)), - ?line <<_:7,D:2/binary,_:1>> = A, - ?line 2 = binary:referenced_byte_size(binary:copy(D)), - ?line 3 = binary:referenced_byte_size(D), - ?line <<_:8,E:2/binary,_/binary>> = B, - ?line 3000 = binary:referenced_byte_size(E), - ?line 2 = binary:referenced_byte_size(binary:copy(E)), - ?line <<_:7,F:2/binary,_:1,_/binary>> = B, - ?line 2 = binary:referenced_byte_size(binary:copy(F)), - ?line 3000 = binary:referenced_byte_size(F), + badarg = ?MASK_ERROR(binary:referenced_byte_size([])), + badarg = ?MASK_ERROR(binary:referenced_byte_size(apa)), + badarg = ?MASK_ERROR(binary:referenced_byte_size({})), + badarg = ?MASK_ERROR(binary:referenced_byte_size(1)), + A = <<1,2,3>>, + B = binary:copy(A,1000), + 3 = binary:referenced_byte_size(A), + 3000 = binary:referenced_byte_size(B), + <<_:8,C:2/binary>> = A, + 3 = binary:referenced_byte_size(C), + 2 = binary:referenced_byte_size(binary:copy(C)), + <<_:7,D:2/binary,_:1>> = A, + 2 = binary:referenced_byte_size(binary:copy(D)), + 3 = binary:referenced_byte_size(D), + <<_:8,E:2/binary,_/binary>> = B, + 3000 = binary:referenced_byte_size(E), + 2 = binary:referenced_byte_size(binary:copy(E)), + <<_:7,F:2/binary,_:1,_/binary>> = B, + 2 = binary:referenced_byte_size(binary:copy(F)), + 3000 = binary:referenced_byte_size(F), ok. -list_to_bin(doc) -> - ["Test list_to_bin/1 bif"]; +%% Test list_to_bin/1 BIF. list_to_bin(Config) when is_list(Config) -> %% Just some smoke_tests first, then go nuts with random cases - ?line badarg = ?MASK_ERROR(binary:list_to_bin({})), - ?line badarg = ?MASK_ERROR(binary:list_to_bin(apa)), - ?line badarg = ?MASK_ERROR(binary:list_to_bin(<<"apa">>)), + badarg = ?MASK_ERROR(binary:list_to_bin({})), + badarg = ?MASK_ERROR(binary:list_to_bin(apa)), + badarg = ?MASK_ERROR(binary:list_to_bin(<<"apa">>)), F1 = fun(L) -> ?MASK_ERROR(binref:list_to_bin(L)) end, F2 = fun(L) -> ?MASK_ERROR(binary:list_to_bin(L)) end, - ?line random_iolist:run(1000,F1,F2), + random_iolist:run(1000,F1,F2), ok. -copy(doc) -> - ["Test copy/1,2 bif's"]; +%% Test copy/1,2 BIFs. copy(Config) when is_list(Config) -> - ?line <<1,2,3>> = binary:copy(<<1,2,3>>), - ?line RS = random_string({1,10000}), - ?line RS = RS2 = binary:copy(RS), - ?line false = erts_debug:same(RS,RS2), - ?line <<>> = ?MASK_ERROR(binary:copy(<<1,2,3>>,0)), - ?line badarg = ?MASK_ERROR(binary:copy(<<1,2,3:3>>,2)), - ?line badarg = ?MASK_ERROR(binary:copy([],0)), - ?line <<>> = ?MASK_ERROR(binary:copy(<<>>,0)), - ?line badarg = ?MASK_ERROR(binary:copy(<<1,2,3>>,1.0)), - ?line badarg = ?MASK_ERROR(binary:copy(<<1,2,3>>, - 16#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), - ?line <<>> = binary:copy(<<>>,10000), + <<1,2,3>> = binary:copy(<<1,2,3>>), + RS = random_string({1,10000}), + RS = RS2 = binary:copy(RS), + false = erts_debug:same(RS,RS2), + <<>> = ?MASK_ERROR(binary:copy(<<1,2,3>>,0)), + badarg = ?MASK_ERROR(binary:copy(<<1,2,3:3>>,2)), + badarg = ?MASK_ERROR(binary:copy([],0)), + <<>> = ?MASK_ERROR(binary:copy(<<>>,0)), + badarg = ?MASK_ERROR(binary:copy(<<1,2,3>>,1.0)), + badarg = ?MASK_ERROR(binary:copy(<<1,2,3>>, + 16#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), + <<>> = binary:copy(<<>>,10000), rand:seed(exsplus, {1271,769940,559934}), - ?line ok = random_copy(3000), - ?line erts_debug:set_internal_state(available_internal_state,true), - ?line io:format("oldlimit: ~p~n", - [erts_debug:set_internal_state(binary_loop_limit,10)]), - ?line Subj = subj(), - ?line XX = binary:copy(Subj,1000), - ?line XX = binref:copy(Subj,1000), - ?line ok = random_copy(1000), - ?line kill_copy_loop(1000), - ?line io:format("limit was: ~p~n", - [erts_debug:set_internal_state(binary_loop_limit, - default)]), - ?line erts_debug:set_internal_state(available_internal_state,false), + ok = random_copy(3000), + erts_debug:set_internal_state(available_internal_state,true), + io:format("oldlimit: ~p~n", + [erts_debug:set_internal_state(binary_loop_limit,10)]), + Subj = subj(), + XX = binary:copy(Subj,1000), + XX = binref:copy(Subj,1000), + ok = random_copy(1000), + kill_copy_loop(1000), + io:format("limit was: ~p~n", + [erts_debug:set_internal_state(binary_loop_limit, + default)]), + erts_debug:set_internal_state(available_internal_state,false), ok. kill_copy_loop(0) -> ok; kill_copy_loop(N) -> {Pid,Ref} = spawn_monitor(fun() -> - ok = random_copy(1000) + ok = random_copy(1000) end), receive after 10 -> @@ -876,34 +840,33 @@ random_copy(N) -> exit(mismatch) end. -bin_to_list(doc) -> - ["Test bin_to_list/1,2,3 bif's"]; +%% Test bin_to_list/1,2,3 BIFs. bin_to_list(Config) when is_list(Config) -> %% Just some smoke_tests first, then go nuts with random cases - ?line X = <<1,2,3,4,0:1000000,5>>, - ?line Y = make_unaligned(X), - ?line LX = binary:bin_to_list(X), - ?line LX = binary:bin_to_list(X,0,byte_size(X)), - ?line LX = binary:bin_to_list(X,byte_size(X),-byte_size(X)), - ?line LX = binary:bin_to_list(X,{0,byte_size(X)}), - ?line LX = binary:bin_to_list(X,{byte_size(X),-byte_size(X)}), - ?line LY = binary:bin_to_list(Y), - ?line LY = binary:bin_to_list(Y,0,byte_size(Y)), - ?line LY = binary:bin_to_list(Y,byte_size(Y),-byte_size(Y)), - ?line LY = binary:bin_to_list(Y,{0,byte_size(Y)}), - ?line LY = binary:bin_to_list(Y,{byte_size(Y),-byte_size(Y)}), - ?line 1 = hd(LX), - ?line 5 = lists:last(LX), - ?line 1 = hd(LY), - ?line 5 = lists:last(LY), - ?line X = list_to_binary(LY), - ?line Y = list_to_binary(LY), - ?line X = list_to_binary(LY), - ?line [5] = lists:nthtail(byte_size(X)-1,LX), - ?line [0,5] = lists:nthtail(byte_size(X)-2,LX), - ?line [0,5] = lists:nthtail(byte_size(Y)-2,LY), + X = <<1,2,3,4,0:1000000,5>>, + Y = make_unaligned(X), + LX = binary:bin_to_list(X), + LX = binary:bin_to_list(X,0,byte_size(X)), + LX = binary:bin_to_list(X,byte_size(X),-byte_size(X)), + LX = binary:bin_to_list(X,{0,byte_size(X)}), + LX = binary:bin_to_list(X,{byte_size(X),-byte_size(X)}), + LY = binary:bin_to_list(Y), + LY = binary:bin_to_list(Y,0,byte_size(Y)), + LY = binary:bin_to_list(Y,byte_size(Y),-byte_size(Y)), + LY = binary:bin_to_list(Y,{0,byte_size(Y)}), + LY = binary:bin_to_list(Y,{byte_size(Y),-byte_size(Y)}), + 1 = hd(LX), + 5 = lists:last(LX), + 1 = hd(LY), + 5 = lists:last(LY), + X = list_to_binary(LY), + Y = list_to_binary(LY), + X = list_to_binary(LY), + [5] = lists:nthtail(byte_size(X)-1,LX), + [0,5] = lists:nthtail(byte_size(X)-2,LX), + [0,5] = lists:nthtail(byte_size(Y)-2,LY), rand:seed(exsplus, {1271,769940,559934}), - ?line ok = random_bin_to_list(5000), + ok = random_bin_to_list(5000), ok. random_bin_to_list(0) -> @@ -914,10 +877,10 @@ random_bin_to_list(N) -> Parts1 = Parts0 ++ [ {X+Y,-Y} || {X,Y} <- Parts0 ], [ begin try - true = ?MASK_ERROR(binary:bin_to_list(Str,Z)) =:= - ?MASK_ERROR(binref:bin_to_list(Str,Z)), - true = ?MASK_ERROR(binary:bin_to_list(Str,Z)) =:= - ?MASK_ERROR(binary:bin_to_list(make_unaligned(Str),Z)) + true = ?MASK_ERROR(binary:bin_to_list(Str,Z)) =:= + ?MASK_ERROR(binref:bin_to_list(Str,Z)), + true = ?MASK_ERROR(binary:bin_to_list(Str,Z)) =:= + ?MASK_ERROR(binary:bin_to_list(make_unaligned(Str),Z)) catch _:_ -> io:format("Error, Str = <<\"~s\">>.~nZ = ~p.~n", @@ -927,10 +890,10 @@ random_bin_to_list(N) -> end || Z <- Parts1 ], [ begin try - true = ?MASK_ERROR(binary:bin_to_list(Str,A,B)) =:= - ?MASK_ERROR(binref:bin_to_list(Str,A,B)), - true = ?MASK_ERROR(binary:bin_to_list(Str,A,B)) =:= - ?MASK_ERROR(binary:bin_to_list(make_unaligned(Str),A,B)) + true = ?MASK_ERROR(binary:bin_to_list(Str,A,B)) =:= + ?MASK_ERROR(binref:bin_to_list(Str,A,B)), + true = ?MASK_ERROR(binary:bin_to_list(Str,A,B)) =:= + ?MASK_ERROR(binary:bin_to_list(make_unaligned(Str),A,B)) catch _:_ -> io:format("Error, Str = <<\"~s\">>.~nA = ~p.~nB = ~p.~n", @@ -940,37 +903,36 @@ random_bin_to_list(N) -> end || {A,B} <- Parts1 ], random_bin_to_list(N-1). -parts(doc) -> - ["Test the part/2,3 bif's"]; +%% Test the part/2,3 BIFs. parts(Config) when is_list(Config) -> %% Some simple smoke tests to begin with - ?line Simple = <<1,2,3,4,5,6,7,8>>, - ?line <<1,2>> = binary:part(Simple,0,2), - ?line <<1,2>> = binary:part(Simple,{0,2}), - ?line Simple = binary:part(Simple,0,8), - ?line Simple = binary:part(Simple,{0,8}), - ?line badarg = ?MASK_ERROR(binary:part(Simple,0,9)), - ?line badarg = ?MASK_ERROR(binary:part(Simple,{0,9})), - ?line badarg = ?MASK_ERROR(binary:part(Simple,1,8)), - ?line badarg = ?MASK_ERROR(binary:part(Simple,{1,8})), - ?line badarg = ?MASK_ERROR(binary:part(Simple,{3,-4})), - ?line badarg = ?MASK_ERROR(binary:part(Simple,{3.0,1})), - ?line badarg = ?MASK_ERROR( - binary:part(Simple,{16#FFFFFFFFFFFFFFFFFFFFFFFFFFFFF - ,1})), - ?line <<2,3,4,5,6,7,8>> = binary:part(Simple,{1,7}), - ?line <<2,3,4,5,6,7,8>> = binary:part(Simple,{8,-7}), - ?line Simple = binary:part(Simple,{8,-8}), - ?line badarg = ?MASK_ERROR(binary:part(Simple,{1,-8})), - ?line badarg = ?MASK_ERROR(binary:part(Simple,{8,-9})), - ?line badarg = ?MASK_ERROR(binary:part(Simple,{0,-1})), - ?line <<>> = binary:part(Simple,{8,0}), - ?line badarg = ?MASK_ERROR(binary:part(Simple,{9,0})), - ?line badarg = ?MASK_ERROR(binary:part(Simple,{-1,0})), - ?line badarg = ?MASK_ERROR(binary:part(Simple,{7,2})), - ?line <<8>> = binary:part(Simple,{7,1}), + Simple = <<1,2,3,4,5,6,7,8>>, + <<1,2>> = binary:part(Simple,0,2), + <<1,2>> = binary:part(Simple,{0,2}), + Simple = binary:part(Simple,0,8), + Simple = binary:part(Simple,{0,8}), + badarg = ?MASK_ERROR(binary:part(Simple,0,9)), + badarg = ?MASK_ERROR(binary:part(Simple,{0,9})), + badarg = ?MASK_ERROR(binary:part(Simple,1,8)), + badarg = ?MASK_ERROR(binary:part(Simple,{1,8})), + badarg = ?MASK_ERROR(binary:part(Simple,{3,-4})), + badarg = ?MASK_ERROR(binary:part(Simple,{3.0,1})), + badarg = ?MASK_ERROR( + binary:part(Simple,{16#FFFFFFFFFFFFFFFFFFFFFFFFFFFFF + ,1})), + <<2,3,4,5,6,7,8>> = binary:part(Simple,{1,7}), + <<2,3,4,5,6,7,8>> = binary:part(Simple,{8,-7}), + Simple = binary:part(Simple,{8,-8}), + badarg = ?MASK_ERROR(binary:part(Simple,{1,-8})), + badarg = ?MASK_ERROR(binary:part(Simple,{8,-9})), + badarg = ?MASK_ERROR(binary:part(Simple,{0,-1})), + <<>> = binary:part(Simple,{8,0}), + badarg = ?MASK_ERROR(binary:part(Simple,{9,0})), + badarg = ?MASK_ERROR(binary:part(Simple,{-1,0})), + badarg = ?MASK_ERROR(binary:part(Simple,{7,2})), + <<8>> = binary:part(Simple,{7,1}), rand:seed(exsplus, {1271,769940,559934}), - ?line random_parts(5000), + random_parts(5000), ok. @@ -997,8 +959,7 @@ random_parts(X,N) -> Len = rand:uniform((Pos * 12) div 10), [{Pos,Len} | random_parts(X-1,N)]. -random_ref_comp(doc) -> - ["Test pseudorandomly generated cases against reference imlementation"]; +%% Test pseudorandomly generated cases against reference implementation. random_ref_comp(Config) when is_list(Config) -> put(success_counter,0), rand:seed(exsplus, {1271,769940,559934}), @@ -1027,8 +988,8 @@ random_ref_comp(Config) when is_list(Config) -> erts_debug:set_internal_state(available_internal_state,false), ok. -random_ref_sr_comp(doc) -> - ["Test pseudorandomly generated cases against reference imlementation of split and replace"]; +%% Test pseudorandomly generated cases against reference implementation +%% of split and replace. random_ref_sr_comp(Config) when is_list(Config) -> put(success_counter,0), rand:seed(exsplus, {1271,769940,559934}), @@ -1045,14 +1006,14 @@ random_ref_sr_comp(Config) when is_list(Config) -> io:format("Number of successes: ~p~n",[get(success_counter)]), ok. -random_ref_fla_comp(doc) -> - ["Test pseudorandomly generated cases against reference imlementation of split and replace"]; +%% Test pseudorandomly generated cases against reference implementation +%% of split and replace. random_ref_fla_comp(Config) when is_list(Config) -> - ?line put(success_counter,0), + put(success_counter,0), rand:seed(exsplus, {1271,769940,559934}), - ?line do_random_first_comp(5000,{1,1000}), - ?line do_random_last_comp(5000,{1,1000}), - ?line do_random_at_comp(5000,{1,1000}), + do_random_first_comp(5000,{1,1000}), + do_random_last_comp(5000,{1,1000}), + do_random_at_comp(5000,{1,1000}), io:format("Number of successes: ~p~n",[get(success_counter)]), ok. @@ -1332,7 +1293,7 @@ do_random_replace_comp(N,NeedleRange,HaystackRange) -> true = do_replace_comp(Needle,Haystack,Repl,[]), true = do_replace_comp(Needle,Haystack,Repl,[global]), true = do_replace_comp(Needle,Haystack,Repl, - [global,{insert_replaced,Insertat}]), + [global,{insert_replaced,Insertat}]), do_random_replace_comp(N-1,NeedleRange,HaystackRange). do_random_replace_comp2(0,_,_) -> ok; @@ -1346,7 +1307,7 @@ do_random_replace_comp2(N,NeedleRange,HaystackRange) -> true = do_replace_comp(Needles,Haystack,Repl,[]), true = do_replace_comp(Needles,Haystack,Repl,[global]), true = do_replace_comp(Needles,Haystack,Repl, - [global,{insert_replaced,Insertat}]), + [global,{insert_replaced,Insertat}]), do_random_replace_comp2(N-1,NeedleRange,HaystackRange). do_replace_comp(N,H,R,Opts) -> @@ -1382,7 +1343,7 @@ one_random(N) -> $Ä,$Ö,$0,$1,$2,$3,$4,$5,$6,$7,$8,$9}). random_number({Min,Max}) -> % Min and Max are *length* of number in - % decimal positions + % decimal positions X = rand:uniform(Max - Min + 1) + Min - 1, list_to_integer([one_random_number(rand:uniform(10)) || _ <- lists:seq(1,X)]). diff --git a/lib/stdlib/test/binref.erl b/lib/stdlib/test/binref.erl index a52ea98e5a..deb1ede4df 100644 --- a/lib/stdlib/test/binref.erl +++ b/lib/stdlib/test/binref.erl @@ -89,7 +89,7 @@ mloop(_Haystack,_Needles,N,M) when N >= M -> mloop(Haystack,Needles,N,M) -> case mloop2(Haystack,Needles,N,nomatch) of nomatch -> - % Not found + %% Not found <<_:8,NewStack/binary>> = Haystack, mloop(NewStack,Needles,N+1,M); {N,Len} -> @@ -104,7 +104,7 @@ msloop(_Haystack,_Needles,N,M) when N >= M -> msloop(Haystack,Needles,N,M) -> case mloop2(Haystack,Needles,N,nomatch) of nomatch -> - % Not found + %% Not found <<_:8,NewStack/binary>> = Haystack, msloop(NewStack,Needles,N+1,M); {N,Len} -> @@ -325,7 +325,7 @@ at(Subject,X) -> end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% bin_to_list +%% bin_to_list %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% bin_to_list(Subject) -> try @@ -358,7 +358,7 @@ bin_to_list(Subject,A,B) -> erlang:error(badarg) end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% list_to_bin +%% list_to_bin %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% list_to_bin(List) -> try diff --git a/lib/stdlib/test/c_SUITE.erl b/lib/stdlib/test/c_SUITE.erl index 47dd95f86b..266918581b 100644 --- a/lib/stdlib/test/c_SUITE.erl +++ b/lib/stdlib/test/c_SUITE.erl @@ -50,144 +50,117 @@ end_per_group(_GroupName, Config) -> %%% Write output to a directory other than current directory: -c_1(doc) -> - ["Checks that c:c works also with option 'outdir' [ticket OTP-1209]."]; -c_1(suite) -> - []; +%% OTP-1209: Check that c:c/2 works also with option 'outdir'. c_1(Config) when is_list(Config) -> - ?line R = filename:join(?config(data_dir, Config), "m.erl"), - ?line W = ?config(priv_dir, Config), - ?line Result = c(R,[{outdir,W}]), - ?line {ok, m} = Result. - -c_2(doc) -> - ["Checks that c:c works also with option 'outdir' [ticket OTP-1209]."]; -c_2(suite) -> - []; + R = filename:join(proplists:get_value(data_dir, Config), "m.erl"), + W = proplists:get_value(priv_dir, Config), + Result = c(R,[{outdir,W}]), + {ok, m} = Result. + +%% OTP-1209: Check that c:c/2 works also with option 'outdir'. c_2(Config) when is_list(Config) -> - ?line R = filename:join(?config(data_dir, Config), "m"), - ?line W = ?config(priv_dir, Config), - ?line Result = c(R,[{outdir,W}]), - ?line {ok, m} = Result. + R = filename:join(proplists:get_value(data_dir, Config), "m"), + W = proplists:get_value(priv_dir, Config), + Result = c(R,[{outdir,W}]), + {ok, m} = Result. %%% Put results in current directory (or rather, change current dir %%% to the output dir): -c_3(doc) -> - ["Checks that c:c works also with option 'outdir' (same as current" - "directory). [ticket OTP-1209]."]; -c_3(suite) -> - []; +%% OTP-1209: Check that c:c/2 works also with option 'outdir' +%% (same as current directory). c_3(Config) when is_list(Config) -> - ?line R = filename:join(?config(data_dir, Config), "m.erl"), - ?line W = ?config(priv_dir, Config), - ?line file:set_cwd(W), - ?line Result = c(R,[{outdir,W}]), - ?line {ok, m} = Result. - -c_4(doc) -> - ["Checks that c:c works also with option 'outdir' (same as current" - "directory). [ticket OTP-1209]."]; -c_4(suite) -> - []; + R = filename:join(proplists:get_value(data_dir, Config), "m.erl"), + W = proplists:get_value(priv_dir, Config), + file:set_cwd(W), + Result = c(R,[{outdir,W}]), + {ok, m} = Result. + +%% OTP-1209: Check that c:c/2 works also with option 'outdir' +%% (same as current directory). c_4(Config) when is_list(Config) -> - ?line R = filename:join(?config(data_dir, Config), "m"), - ?line W = ?config(priv_dir, Config), - ?line file:set_cwd(W), - ?line Result = c(R,[{outdir,W}]), - ?line {ok, m} = Result. + R = filename:join(proplists:get_value(data_dir, Config), "m"), + W = proplists:get_value(priv_dir, Config), + file:set_cwd(W), + Result = c(R,[{outdir,W}]), + {ok, m} = Result. %%% Write output to a directory other than current directory: -nc_1(doc) -> - ["Checks that c:nc works also with option 'outdir'."]; -nc_1(suite) -> - []; +%% Check that c:nc/2 works also with option 'outdir'. nc_1(Config) when is_list(Config) -> - ?line R = filename:join(?config(data_dir, Config), "m.erl"), - ?line W = ?config(priv_dir, Config), - ?line Result = nc(R,[{outdir,W}]), - ?line {ok, m} = Result. - -nc_2(doc) -> - ["Checks that c:nc works also with option 'outdir'."]; -nc_2(suite) -> - []; + R = filename:join(proplists:get_value(data_dir, Config), "m.erl"), + W = proplists:get_value(priv_dir, Config), + Result = nc(R,[{outdir,W}]), + {ok, m} = Result. + +%% Check that c:nc/2 works also with option 'outdir'. nc_2(Config) when is_list(Config) -> - ?line R = filename:join(?config(data_dir, Config), "m"), - ?line W = ?config(priv_dir, Config), - ?line Result = nc(R,[{outdir,W}]), - ?line {ok, m} = Result. + R = filename:join(proplists:get_value(data_dir, Config), "m"), + W = proplists:get_value(priv_dir, Config), + Result = nc(R,[{outdir,W}]), + {ok, m} = Result. %%% Put results in current directory (or rather, change current dir %%% to the output dir): -nc_3(doc) -> - ["Checks that c:nc works also with option 'outdir' (same as current" - "directory)."]; -nc_3(suite) -> - []; +%% Check that c:nc/2 works also with option 'outdir' +%% (same as current directory). nc_3(Config) when is_list(Config) -> - ?line R = filename:join(?config(data_dir, Config), "m.erl"), - ?line W = ?config(priv_dir, Config), - ?line file:set_cwd(W), - ?line Result = nc(R,[{outdir,W}]), - ?line {ok, m} = Result. - -nc_4(doc) -> - ["Checks that c:nc works also with option 'outdir' (same as current" - "directory)."]; -nc_4(suite) -> - []; + R = filename:join(proplists:get_value(data_dir, Config), "m.erl"), + W = proplists:get_value(priv_dir, Config), + file:set_cwd(W), + Result = nc(R,[{outdir,W}]), + {ok, m} = Result. + +%% Check that c:nc/2 works also with option 'outdir' +%% (same as current directory). nc_4(Config) when is_list(Config) -> - ?line R = filename:join(?config(data_dir, Config), "m"), - ?line W = ?config(priv_dir, Config), - ?line file:set_cwd(W), - ?line Result = nc(R,[{outdir,W}]), - ?line {ok, m} = Result. + R = filename:join(proplists:get_value(data_dir, Config), "m"), + W = proplists:get_value(priv_dir, Config), + file:set_cwd(W), + Result = nc(R,[{outdir,W}]), + {ok, m} = Result. ls(Config) when is_list(Config) -> - Directory = ?config(data_dir, Config), + Directory = proplists:get_value(data_dir, Config), ok = c:ls(Directory), File = filename:join(Directory, "m.erl"), ok = c:ls(File), ok = c:ls("no_such_file"). -memory(doc) -> - ["Checks that c:memory/[0,1] returns consistent results."]; -memory(suite) -> - []; +%% Check that c:memory/[0,1] returns consistent results. memory(Config) when is_list(Config) -> try - ?line ML = c:memory(), - ?line T = mget(total, ML), - ?line P = mget(processes, ML), - ?line S = mget(system, ML), - ?line A = mget(atom, ML), - ?line AU = mget(atom_used, ML), - ?line B = mget(binary, ML), - ?line C = mget(code, ML), - ?line E = mget(ets, ML), - ?line T = P + S, - ?line if S >= A + B + C + E -> ok end, - ?line if A >= AU -> ok end, - ?line ok + ML = c:memory(), + T = mget(total, ML), + P = mget(processes, ML), + S = mget(system, ML), + A = mget(atom, ML), + AU = mget(atom_used, ML), + B = mget(binary, ML), + C = mget(code, ML), + E = mget(ets, ML), + T = P + S, + if S >= A + B + C + E -> ok end, + if A >= AU -> ok end, + ok catch error:notsup -> - ?line {skipped, - "erlang:memory/[0,1] and c:memory/[0,1] not supported"} + {skipped, + "erlang:memory/[0,1] and c:memory/[0,1] not supported"} end. -% Help function for c_SUITE:memory/1 +%% Help function for c_SUITE:memory/1 mget(K, L) -> - ?line {value,{K,V}} = lists:keysearch(K, 1, L), - ?line test_v(c:memory(K)), % Check that c:memory/1 also accept this - % argument and returns an integer (usally - % *not* the same as V). - ?line test_v(V). + {value,{K,V}} = lists:keysearch(K, 1, L), + test_v(c:memory(K)), % Check that c:memory/1 also accept this + % argument and returns an integer (usally + % *not* the same as V). + test_v(V). -% Help function for c_SUITE:memory/1 +%% Help function for c_SUITE:memory/1 test_v(V) when is_integer(V) -> - ?line V. + V. diff --git a/lib/stdlib/test/calendar_SUITE.erl b/lib/stdlib/test/calendar_SUITE.erl index bddc3a4821..7372288492 100644 --- a/lib/stdlib/test/calendar_SUITE.erl +++ b/lib/stdlib/test/calendar_SUITE.erl @@ -57,69 +57,48 @@ init_per_group(_GroupName, Config) -> end_per_group(_GroupName, Config) -> Config. -gregorian_days(doc) -> - "Tests that date_to_gregorian_days and gregorian_days_to_date " - "are each others inverses from ?START_YEAR-01-01 up to ?END_YEAR-01-01. " - "At the same time valid_date is tested."; -gregorian_days(suite) -> - []; +%% Tests that date_to_gregorian_days and gregorian_days_to_date +%% are each others inverses from ?START_YEAR-01-01 up to ?END_YEAR-01-01. +%% At the same time valid_date is tested. gregorian_days(Config) when is_list(Config) -> - ?line Days = calendar:date_to_gregorian_days({?START_YEAR, 1, 1}), - ?line MaxDays = calendar:date_to_gregorian_days({?END_YEAR, 1, 1}), - ?line check_gregorian_days(Days, MaxDays). - -gregorian_seconds(doc) -> - "Tests that datetime_to_gregorian_seconds and " - "gregorian_seconds_to_date are each others inverses for a sampled " - "number of seconds from ?START_YEAR-01-01 up to ?END_YEAR-01-01: We check " - "every 2 days + 1 second."; -gregorian_seconds(suite) -> - []; + Days = calendar:date_to_gregorian_days({?START_YEAR, 1, 1}), + MaxDays = calendar:date_to_gregorian_days({?END_YEAR, 1, 1}), + check_gregorian_days(Days, MaxDays). + +%% Tests that datetime_to_gregorian_seconds and +%% gregorian_seconds_to_date are each others inverses for a sampled +%% number of seconds from ?START_YEAR-01-01 up to ?END_YEAR-01-01: We check +%% every 2 days + 1 second. gregorian_seconds(Config) when is_list(Config) -> - ?line Secs = calendar:datetime_to_gregorian_seconds({{?START_YEAR, 1, 1}, - {0, 0, 0}}), - ?line MaxSecs = calendar:datetime_to_gregorian_seconds({{?END_YEAR, 1, 1}, - {0, 0, 0}}), - ?line check_gregorian_seconds(Secs, MaxSecs). - -day_of_the_week(doc) -> - "Tests that day_of_the_week reports correctly the day of the week from " - "year ?START_YEAR up to ?END_YEAR."; -day_of_the_week(suite) -> - []; + Secs = calendar:datetime_to_gregorian_seconds({{?START_YEAR, 1, 1}, + {0, 0, 0}}), + MaxSecs = calendar:datetime_to_gregorian_seconds({{?END_YEAR, 1, 1}, + {0, 0, 0}}), + check_gregorian_seconds(Secs, MaxSecs). + +%% Tests that day_of_the_week reports correctly the day of the week from +%% year ?START_YEAR up to ?END_YEAR. day_of_the_week(Config) when is_list(Config) -> - ?line Days = calendar:date_to_gregorian_days({?START_YEAR, 1, 1}), - ?line MaxDays = calendar:date_to_gregorian_days({?END_YEAR, 1, 1}), - ?line DayNumber = calendar:day_of_the_week({?START_YEAR, 1, 1}), - ?line check_day_of_the_week(Days, MaxDays, DayNumber). + Days = calendar:date_to_gregorian_days({?START_YEAR, 1, 1}), + MaxDays = calendar:date_to_gregorian_days({?END_YEAR, 1, 1}), + DayNumber = calendar:day_of_the_week({?START_YEAR, 1, 1}), + check_day_of_the_week(Days, MaxDays, DayNumber). -day_of_the_week_calibrate(doc) -> - "Tests that day_of_the_week for 1997-11-11 is Tuesday (2)"; -day_of_the_week_calibrate(suite) -> - []; +%% Tests that day_of_the_week for 1997-11-11 is Tuesday (2). day_of_the_week_calibrate(Config) when is_list(Config) -> - ?line 2 = calendar:day_of_the_week({1997, 11, 11}). + 2 = calendar:day_of_the_week({1997, 11, 11}). -leap_years(doc) -> - "Tests that is_leap_year reports correctly the leap years from " - "year ?START_YEAR up to ?END_YEAR."; -leap_years(suite) -> - []; +%% Tests that is_leap_year reports correctly the leap years from +%% year ?START_YEAR up to ?END_YEAR. leap_years(Config) when is_list(Config) -> - ?line check_leap_years(?START_YEAR, ?END_YEAR). + check_leap_years(?START_YEAR, ?END_YEAR). -last_day_of_the_month(doc) -> - "Tests that last_day_of_the_month reports correctly from " - "year ?START_YEAR up to ?END_YEAR."; -last_day_of_the_month(suite) -> - []; +%% Tests that last_day_of_the_month reports correctly from +%% year ?START_YEAR up to ?END_YEAR. last_day_of_the_month(Config) when is_list(Config) -> - ?line check_last_day_of_the_month({?START_YEAR, 1}, {?END_YEAR, 1}). + check_last_day_of_the_month({?START_YEAR, 1}, {?END_YEAR, 1}). -local_time_to_universal_time_dst(doc) -> - "Tests local_time_to_universal_time_dst for MET"; -local_time_to_universal_time_dst(suite) -> - []; +%% Tests local_time_to_universal_time_dst for MET. local_time_to_universal_time_dst(Config) when is_list(Config) -> case os:type() of {unix,_} -> @@ -134,35 +113,35 @@ local_time_to_universal_time_dst(Config) when is_list(Config) -> end. local_time_to_universal_time_dst_x(Config) when is_list(Config) -> %% Assumes MET (UTC+1 / UTC+2(dst) - ?line LtW = {{2003,01,15},{14,00,00}}, % Winter - ?line UtW = {{2003,01,15},{13,00,00}}, % - ?line UtWd = {{2003,01,15},{12,00,00}}, % dst - ?line LtS = {{2003,07,15},{14,00,00}}, % Summer - ?line UtS = {{2003,07,15},{13,00,00}}, % - ?line UtSd = {{2003,07,15},{12,00,00}}, % dst - ?line LtWS = {{2003,03,30},{02,30,00}}, % Winter->Summer - ?line UtWS = {{2003,03,30},{01,30,00}}, % - ?line UtWSd = {{2003,03,30},{00,30,00}}, % dst - ?line LtSW = {{2003,10,26},{02,30,00}}, % Summer->Winter - ?line UtSW = {{2003,10,26},{01,30,00}}, % - ?line UtSWd = {{2003,10,26},{00,30,00}}, % dst + LtW = {{2003,01,15},{14,00,00}}, % Winter + UtW = {{2003,01,15},{13,00,00}}, % + UtWd = {{2003,01,15},{12,00,00}}, % dst + LtS = {{2003,07,15},{14,00,00}}, % Summer + UtS = {{2003,07,15},{13,00,00}}, % + UtSd = {{2003,07,15},{12,00,00}}, % dst + LtWS = {{2003,03,30},{02,30,00}}, % Winter->Summer + UtWS = {{2003,03,30},{01,30,00}}, % + UtWSd = {{2003,03,30},{00,30,00}}, % dst + LtSW = {{2003,10,26},{02,30,00}}, % Summer->Winter + UtSW = {{2003,10,26},{01,30,00}}, % + UtSWd = {{2003,10,26},{00,30,00}}, % dst %% - ?line UtW = calendar:local_time_to_universal_time(LtW, false), - ?line UtWd = calendar:local_time_to_universal_time(LtW, true), - ?line UtW = calendar:local_time_to_universal_time(LtW, undefined), + UtW = calendar:local_time_to_universal_time(LtW, false), + UtWd = calendar:local_time_to_universal_time(LtW, true), + UtW = calendar:local_time_to_universal_time(LtW, undefined), %% - ?line UtS = calendar:local_time_to_universal_time(LtS, false), - ?line UtSd = calendar:local_time_to_universal_time(LtS, true), - ?line UtSd = calendar:local_time_to_universal_time(LtS, undefined), + UtS = calendar:local_time_to_universal_time(LtS, false), + UtSd = calendar:local_time_to_universal_time(LtS, true), + UtSd = calendar:local_time_to_universal_time(LtS, undefined), %% case calendar:local_time_to_universal_time(LtWS, false) of UtWS -> - ?line UtWSd = calendar:local_time_to_universal_time(LtWS, true), - ?line [] = calendar:local_time_to_universal_time_dst(LtWS), + UtWSd = calendar:local_time_to_universal_time(LtWS, true), + [] = calendar:local_time_to_universal_time_dst(LtWS), %% - ?line UtSW = calendar:local_time_to_universal_time(LtSW, false), - ?line UtSWd = calendar:local_time_to_universal_time(LtSW, true), - ?line [UtSWd, UtSW] = calendar:local_time_to_universal_time_dst(LtSW), + UtSW = calendar:local_time_to_universal_time(LtSW, false), + UtSWd = calendar:local_time_to_universal_time(LtSW, true), + [UtSWd, UtSW] = calendar:local_time_to_universal_time_dst(LtSW), ok; {{1969,12,31},{23,59,59}} -> %% It seems that Apple has no intention of fixing this bug in @@ -171,15 +150,12 @@ local_time_to_universal_time_dst_x(Config) when is_list(Config) -> {comment,"Bug in mktime() in this OS"} end. -iso_week_number(doc) -> - "Test the iso week number calculation for all three possibilities." - " When the date falls on the last week of the previous year," - " when the date falls on a week within the given year and finally," - " when the date falls on the first week of the next year."; -iso_week_number(suite) -> - []; +%% Test the iso week number calculation for all three possibilities: +%% When the date falls on the last week of the previous year, +%% when the date falls on a week within the given year and finally, +%% when the date falls on the first week of the next year. iso_week_number(Config) when is_list(Config) -> - ?line check_iso_week_number(). + check_iso_week_number(). %% %% LOCAL FUNCTIONS @@ -188,10 +164,10 @@ iso_week_number(Config) when is_list(Config) -> %% check_gregorian_days %% check_gregorian_days(Days, MaxDays) when Days < MaxDays -> - ?line Date = calendar:gregorian_days_to_date(Days), - ?line true = calendar:valid_date(Date), - ?line Days = calendar:date_to_gregorian_days(Date), - ?line check_gregorian_days(Days + 1, MaxDays); + Date = calendar:gregorian_days_to_date(Days), + true = calendar:valid_date(Date), + Days = calendar:date_to_gregorian_days(Date), + check_gregorian_days(Days + 1, MaxDays); check_gregorian_days(_Days, _MaxDays) -> ok. @@ -200,9 +176,9 @@ check_gregorian_days(_Days, _MaxDays) -> %% We increment with something prime (172801 = 2 days + 1 second). %% check_gregorian_seconds(Secs, MaxSecs) when Secs < MaxSecs -> - ?line DateTime = calendar:gregorian_seconds_to_datetime(Secs), - ?line Secs = calendar:datetime_to_gregorian_seconds(DateTime), - ?line check_gregorian_seconds(Secs + 172801, MaxSecs); + DateTime = calendar:gregorian_seconds_to_datetime(Secs), + Secs = calendar:datetime_to_gregorian_seconds(DateTime), + check_gregorian_seconds(Secs + 172801, MaxSecs); check_gregorian_seconds(_Secs, _MaxSecs) -> ok. @@ -210,10 +186,10 @@ check_gregorian_seconds(_Secs, _MaxSecs) -> %% check_day_of_the_week %% check_day_of_the_week(Days, MaxDays, DayNumber) when Days < MaxDays -> - ?line Date = calendar:gregorian_days_to_date(Days), - ?line DayNumber = calendar:day_of_the_week(Date), - ?line check_day_of_the_week(Days + 1, MaxDays, - ((DayNumber rem 7) + 1)); + Date = calendar:gregorian_days_to_date(Days), + DayNumber = calendar:day_of_the_week(Date), + check_day_of_the_week(Days + 1, MaxDays, + ((DayNumber rem 7) + 1)); check_day_of_the_week(_Days, _MaxDays, _DayNumber) -> ok. @@ -222,59 +198,56 @@ check_day_of_the_week(_Days, _MaxDays, _DayNumber) -> %% SYr must be larger than 1800, and EYr must be less than ?END_YEAR. %% check_leap_years(SYr, EYr) when SYr < EYr -> - ?line Rem = SYr rem 4, + Rem = SYr rem 4, case Rem of 0 -> case SYr of 1900 -> - ?line false = calendar:is_leap_year(SYr); + false = calendar:is_leap_year(SYr); 2000 -> - ?line true = calendar:is_leap_year(SYr); + true = calendar:is_leap_year(SYr); _ -> - ?line true = calendar:is_leap_year(SYr) + true = calendar:is_leap_year(SYr) end; _ -> - ?line false = calendar:is_leap_year(SYr) + false = calendar:is_leap_year(SYr) end, check_leap_years(SYr + 1, EYr); check_leap_years(_SYr, _EYr) -> ok. check_last_day_of_the_month({SYr, SMon}, {EYr, EMon}) when SYr < EYr -> - ?line LastDay = calendar:last_day_of_the_month(SYr, SMon), - ?line LastDay = case SMon of - 1 -> 31; - 2 -> - case calendar:is_leap_year(SYr) of - true -> 29; - false -> 28 - end; - 3 -> 31; - 4 -> 30; - 5 -> 31; - 6 -> 30; - 7 -> 31; - 8 -> 31; - 9 -> 30; - 10 -> 31; - 11 -> 30; - 12 -> 31 - end, - ?line NYr = case SMon of - 12 -> SYr + 1; - _ -> SYr - end, - ?line check_last_day_of_the_month({NYr, (SMon rem 12) + 1}, - {EYr, EMon}); + LastDay = calendar:last_day_of_the_month(SYr, SMon), + LastDay = case SMon of + 1 -> 31; + 2 -> + case calendar:is_leap_year(SYr) of + true -> 29; + false -> 28 + end; + 3 -> 31; + 4 -> 30; + 5 -> 31; + 6 -> 30; + 7 -> 31; + 8 -> 31; + 9 -> 30; + 10 -> 31; + 11 -> 30; + 12 -> 31 + end, + NYr = case SMon of + 12 -> SYr + 1; + _ -> SYr + end, + check_last_day_of_the_month({NYr, (SMon rem 12) + 1}, + {EYr, EMon}); check_last_day_of_the_month(_, _) -> ok. %% check_iso_week_number %% check_iso_week_number() -> - ?line {2004, 53} = calendar:iso_week_number({2005, 1, 1}), - ?line {2007, 1} = calendar:iso_week_number({2007, 1, 1}), - ?line {2009, 1} = calendar:iso_week_number({2008, 12, 29}). - - - + {2004, 53} = calendar:iso_week_number({2005, 1, 1}), + {2007, 1} = calendar:iso_week_number({2007, 1, 1}), + {2009, 1} = calendar:iso_week_number({2008, 12, 29}). diff --git a/lib/stdlib/test/dets_SUITE.erl b/lib/stdlib/test/dets_SUITE.erl index ee3a812e24..8948f496c4 100644 --- a/lib/stdlib/test/dets_SUITE.erl +++ b/lib/stdlib/test/dets_SUITE.erl @@ -19,7 +19,7 @@ %% -module(dets_SUITE). -%-define(debug, true). +%%-define(debug, true). -ifdef(debug). -define(format(S, A), io:format(S, A)). @@ -30,8 +30,8 @@ -else. -include_lib("common_test/include/ct.hrl"). -define(format(S, A), ok). --define(privdir(Conf), ?config(priv_dir, Conf)). --define(datadir(Conf), ?config(data_dir, Conf)). +-define(privdir(Conf), proplists:get_value(priv_dir, Conf)). +-define(datadir(Conf), proplists:get_value(data_dir, Conf)). -endif. -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, @@ -83,15 +83,14 @@ -define(CLOSED_PROPERLY,1). init_per_testcase(_Case, Config) -> - Dog=?t:timetrap(?t:minutes(15)), - [{watchdog, Dog}|Config]. + Config. end_per_testcase(_Case, _Config) -> - Dog=?config(watchdog, _Config), - test_server:timetrap_cancel(Dog), ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,15}}]. all() -> [ @@ -130,10 +129,7 @@ init_per_group(_GroupName, Config) -> end_per_group(_GroupName, Config) -> Config. -newly_started(doc) -> - ["OTP-3621"]; -newly_started(suite) -> - []; +%% OTP-3621 newly_started(Config) when is_list(Config) -> true = is_alive(), {ok, Node} = test_server:start_node(slave1, slave, []), @@ -141,17 +137,11 @@ newly_started(Config) when is_list(Config) -> test_server:stop_node(Node), ok. -basic_v8(doc) -> - ["Basic test case."]; -basic_v8(suite) -> - []; +%% Basic test case. basic_v8(Config) when is_list(Config) -> basic(Config, 8). -basic_v9(doc) -> - ["Basic test case."]; -basic_v9(suite) -> - []; +%% Basic test case. basic_v9(Config) when is_list(Config) -> basic(Config, 9). @@ -184,17 +174,9 @@ basic(Config, Version) -> ok. -open_v8(doc) -> - []; -open_v8(suite) -> - []; open_v8(Config) when is_list(Config) -> open(Config, 8). -open_v9(doc) -> - []; -open_v9(suite) -> - []; open_v9(Config) when is_list(Config) -> open(Config, 9). @@ -283,17 +265,11 @@ bad(_Tab, _Item) -> ?format("Can't find item ~p in ~p ~n", [_Item, _Tab]), exit(badtab). -sets_v8(doc) -> - ["Performs traversal and match testing on set type dets tables."]; -sets_v8(suite) -> - []; +%% Perform traversal and match testing on set type dets tables. sets_v8(Config) when is_list(Config) -> sets(Config, 8). -sets_v9(doc) -> - ["Performs traversal and match testing on set type dets tables."]; -sets_v9(suite) -> - []; +%% Perform traversal and match testing on set type dets tables. sets_v9(Config) when is_list(Config) -> sets(Config, 9). @@ -325,17 +301,11 @@ sets(Config, Version) -> check_pps(P0), ok. -bags_v8(doc) -> - ["Performs traversal and match testing on bag type dets tables."]; -bags_v8(suite) -> - []; +%% Perform traversal and match testing on bag type dets tables. bags_v8(Config) when is_list(Config) -> bags(Config, 8). -bags_v9(doc) -> - ["Performs traversal and match testing on bag type dets tables."]; -bags_v9(suite) -> - []; +%% Perform traversal and match testing on bag type dets tables. bags_v9(Config) when is_list(Config) -> bags(Config, 9). @@ -365,17 +335,11 @@ bags(Config, Version) -> ok. -duplicate_bags_v8(doc) -> - ["Performs traversal and match testing on duplicate_bag type dets tables."]; -duplicate_bags_v8(suite) -> - []; +%% Perform traversal and match testing on duplicate_bag type dets tables. duplicate_bags_v8(Config) when is_list(Config) -> duplicate_bags(Config, 8). -duplicate_bags_v9(doc) -> - ["Performs traversal and match testing on duplicate_bag type dets tables."]; -duplicate_bags_v9(suite) -> - []; +%% Perform traversal and match testing on duplicate_bag type dets tables. duplicate_bags_v9(Config) when is_list(Config) -> duplicate_bags(Config, 9). @@ -405,17 +369,9 @@ duplicate_bags(Config, Version) when is_list(Config) -> ok. -access_v8(doc) -> - []; -access_v8(suite) -> - []; access_v8(Config) when is_list(Config) -> access(Config, 8). -access_v9(doc) -> - []; -access_v9(suite) -> - []; access_v9(Config) when is_list(Config) -> access(Config, 9). @@ -448,10 +404,7 @@ access(Config, Version) -> ok. -dirty_mark(doc) -> - ["Test that the table is not marked dirty if not written"]; -dirty_mark(suite) -> - []; +%% Test that the table is not marked dirty if not written. dirty_mark(Config) when is_list(Config) -> true = is_alive(), Tab = dets_dirty_mark_test, @@ -500,10 +453,7 @@ dirty_mark(Config) when is_list(Config) -> check_pps(P0), ok. -dirty_mark2(doc) -> - ["Test that the table is flushed when auto_save is in effect"]; -dirty_mark2(suite) -> - []; +%% Test that the table is flushed when auto_save is in effect. dirty_mark2(Config) when is_list(Config) -> true = is_alive(), Tab = dets_dirty_mark2_test, @@ -571,17 +521,11 @@ dets_dirty_loop() -> end. -bag_next_v8(suite) -> - []; -bag_next_v8(doc) -> - ["Check that bags and next work as expected."]; +%% Check that bags and next work as expected. bag_next_v8(Config) when is_list(Config) -> bag_next(Config, 8). -bag_next_v9(suite) -> - []; -bag_next_v9(doc) -> - ["Check that bags and next work as expected."]; +%% Check that bags and next work as expected. bag_next_v9(Config) when is_list(Config) -> Tab = dets_bag_next_test, FName = filename(Tab, Config), @@ -634,17 +578,9 @@ bag_next(Config, Version) -> check_pps(P0), ok. -oldbugs_v8(doc) -> - []; -oldbugs_v8(suite) -> - []; oldbugs_v8(Config) when is_list(Config) -> oldbugs(Config, 8). -oldbugs_v9(doc) -> - []; -oldbugs_v9(suite) -> - []; oldbugs_v9(Config) when is_list(Config) -> oldbugs(Config, 9). @@ -662,9 +598,7 @@ oldbugs(Config, Version) -> check_pps(P0), ok. -unsafe_assumptions(suite) -> []; -unsafe_assumptions(doc) -> - "Tests that shrinking an object and then expanding it works."; +%% Test that shrinking an object and then expanding it works. unsafe_assumptions(Config) when is_list(Config) -> FName = filename(dets_suite_unsafe_assumptions_test, Config), file:delete(FName), @@ -693,17 +627,13 @@ unsafe_assumptions(Config) when is_list(Config) -> check_pps(P0), ok. -truncated_segment_array_v8(suite) -> []; -truncated_segment_array_v8(doc) -> - "Tests that a file where the segment array has been truncated " - "is possible to repair."; +%% Test that a file where the segment array has been truncated +%% is possible to repair. truncated_segment_array_v8(Config) when is_list(Config) -> trunc_seg_array(Config, 8). -truncated_segment_array_v9(suite) -> []; -truncated_segment_array_v9(doc) -> - "Tests that a file where the segment array has been truncated " - "is possible to repair."; +%% Test that a file where the segment array has been truncated +%% is possible to repair. truncated_segment_array_v9(Config) when is_list(Config) -> trunc_seg_array(Config, 9). @@ -729,17 +659,11 @@ trunc_seg_array(Config, V) -> check_pps(P0), ok. -open_file_v8(doc) -> - ["open_file/1 test case."]; -open_file_v8(suite) -> - []; +%% Test open_file/1. open_file_v8(Config) when is_list(Config) -> open_1(Config, 8). -open_file_v9(doc) -> - ["open_file/1 test case."]; -open_file_v9(suite) -> - []; +%% Test open_file/1. open_file_v9(Config) when is_list(Config) -> T = open_v9, Fname = filename(T, Config), @@ -797,17 +721,11 @@ open_1(Config, V) -> check_pps(P0), ok. -init_table_v8(doc) -> - ["initialize_table/2 and from_ets/2 test case."]; -init_table_v8(suite) -> - []; +%% Test initialize_table/2 and from_ets/2. init_table_v8(Config) when is_list(Config) -> init_table(Config, 8). -init_table_v9(doc) -> - ["initialize_table/2 and from_ets/2 test case."]; -init_table_v9(suite) -> - []; +%% Test initialize_table/2 and from_ets/2. init_table_v9(Config) when is_list(Config) -> %% Objects are returned in "time order". T = init_table_v9, @@ -1270,17 +1188,11 @@ items(I, N, C, L) when I =:= N; C =:= 0 -> items(I, N, C, L) -> items(I+1, N, C-1, [{I, item(I)} | L]). -repair_v8(doc) -> - ["open_file and repair."]; -repair_v8(suite) -> - []; +%% Test open_file and repair. repair_v8(Config) when is_list(Config) -> repair(Config, 8). -repair_v9(doc) -> - ["open_file and repair."]; -repair_v9(suite) -> - []; +%% Test open_file and repair. repair_v9(Config) when is_list(Config) -> %% Convert from format 9 to format 8. T = convert_98, @@ -1617,11 +1529,9 @@ repair(Config, V) -> check_pps(P0), ok. -hash_v8b_v8c(doc) -> - ["Test the use of different hashing algorithms in v8b and v8c of the " - "Dets file format."]; -hash_v8b_v8c(suite) -> - []; + +%% Test the use of different hashing algorithms in v8b and v8c of the +%% Dets file format. hash_v8b_v8c(Config) when is_list(Config) -> Source = filename:join(?datadir(Config), "dets_test_v8b.dets"), @@ -1696,10 +1606,7 @@ hash_v8b_v8c(Config) when is_list(Config) -> check_pps(P0), {comment, Mess}. -phash(doc) -> - ["Test version 9(b) with erlang:phash/2 as hash function."]; -phash(suite) -> - []; +%% Test version 9(b) with erlang:phash/2 as hash function. phash(Config) when is_list(Config) -> T = phash, Phash_v9bS = filename:join(?datadir(Config), "version_9b_phash.dat"), @@ -1757,17 +1664,11 @@ phash(Config) when is_list(Config) -> file:delete(Fname), ok. -fold_v8(doc) -> - ["foldl, foldr, to_ets"]; -fold_v8(suite) -> - []; +%% Test foldl, foldr, to_ets. fold_v8(Config) when is_list(Config) -> fold(Config, 8). -fold_v9(doc) -> - ["foldl, foldr, to_ets"]; -fold_v9(suite) -> - []; +%% Test foldl, foldr, to_ets. fold_v9(Config) when is_list(Config) -> fold(Config, 9). @@ -1836,17 +1737,11 @@ fold(Config, Version) -> check_pps(P0), ok. -fixtable_v8(doc) -> - ["Add objects to a fixed table."]; -fixtable_v8(suite) -> - []; +%% Add objects to a fixed table. fixtable_v8(Config) when is_list(Config) -> fixtable(Config, 8). -fixtable_v9(doc) -> - ["Add objects to a fixed table."]; -fixtable_v9(suite) -> - []; +%% Add objects to a fixed table. fixtable_v9(Config) when is_list(Config) -> fixtable(Config, 9). @@ -1936,17 +1831,11 @@ fixtable(Config, Version) when is_list(Config) -> check_pps(P0), ok. -match_v8(doc) -> - ["Matching objects of a fixed table."]; -match_v8(suite) -> - []; +%% Matching objects of a fixed table. match_v8(Config) when is_list(Config) -> match(Config, 8). -match_v9(doc) -> - ["Matching objects of a fixed table."]; -match_v9(suite) -> - []; +%% Matching objects of a fixed table. match_v9(Config) when is_list(Config) -> match(Config, 9). @@ -2118,17 +2007,11 @@ match(Config, Version) -> check_pps(P0), ok. -select_v8(doc) -> - ["Selecting objects of a fixed table."]; -select_v8(suite) -> - []; +%% Selecting objects of a fixed table. select_v8(Config) when is_list(Config) -> select(Config, 8). -select_v9(doc) -> - ["Selecting objects of a fixed table."]; -select_v9(suite) -> - []; +%% Selecting objects of a fixed table. select_v9(Config) when is_list(Config) -> select(Config, 9). @@ -2232,10 +2115,7 @@ select(Config, Version) -> check_pps(P0), ok. -update_counter(doc) -> - ["Test update_counter/1."]; -update_counter(suite) -> - []; +%% Test update_counter/1. update_counter(Config) when is_list(Config) -> T = update_counter, Fname = filename(select, Config), @@ -2269,10 +2149,7 @@ update_counter(Config) when is_list(Config) -> ok. -badarg(doc) -> - ["Call some functions with bad arguments."]; -badarg(suite) -> - []; +%% Call some functions with bad arguments. badarg(Config) when is_list(Config) -> T = badarg, Fname = filename(select, Config), @@ -2281,7 +2158,6 @@ badarg(Config) when is_list(Config) -> Args = [{file,Fname},{keypos,3}], {ok, _} = dets:open_file(T, [{type,set} | Args]), - % dets:verbose(), %% badargs are tested in match, select and fixtable too. @@ -2404,17 +2280,11 @@ badarg(Config) when is_list(Config) -> check_pps(P0), ok. -cache_sets_v8(doc) -> - ["Test the write cache for sets."]; -cache_sets_v8(suite) -> - []; +%% Test the write cache for sets. cache_sets_v8(Config) when is_list(Config) -> cache_sets(Config, 8). -cache_sets_v9(doc) -> - ["Test the write cache for sets."]; -cache_sets_v9(suite) -> - []; +%% Test the write cache for sets. cache_sets_v9(Config) when is_list(Config) -> cache_sets(Config, 9). @@ -2548,7 +2418,7 @@ cache_sets(Config, DelayedWrite, Extra, Sz, Version) -> {[],[]} -> ok; {X,Y} -> NoBad = length(X) + length(Y), - test_server:fail({sets,DelayedWrite,Extra,Sz,NoBad}) + ct:fail({sets,DelayedWrite,Extra,Sz,NoBad}) end; true -> ok @@ -2559,17 +2429,11 @@ cache_sets(Config, DelayedWrite, Extra, Sz, Version) -> check_pps(P0), ok. -cache_bags_v8(doc) -> - ["Test the write cache for bags."]; -cache_bags_v8(suite) -> - []; +%% Test the write cache for bags. cache_bags_v8(Config) when is_list(Config) -> cache_bags(Config, 8). -cache_bags_v9(doc) -> - ["Test the write cache for bags."]; -cache_bags_v9(suite) -> - []; +%% Test the write cache for bags. cache_bags_v9(Config) when is_list(Config) -> cache_bags(Config, 9). @@ -2712,7 +2576,7 @@ cache_bags(Config, DelayedWrite, Extra, Sz, Version) -> {[],[]} -> ok; {X,Y} -> NoBad = length(X) + length(Y), - test_server:fail({bags,DelayedWrite,Extra,Sz,NoBad}) + ct:fail({bags,DelayedWrite,Extra,Sz,NoBad}) end; true -> ok @@ -2741,17 +2605,11 @@ cache_bags(Config, DelayedWrite, Extra, Sz, Version) -> check_pps(P0), ok. -cache_duplicate_bags_v8(doc) -> - ["Test the write cache for duplicate bags."]; -cache_duplicate_bags_v8(suite) -> - []; +%% Test the write cache for duplicate bags. cache_duplicate_bags_v8(Config) when is_list(Config) -> cache_duplicate_bags(Config, 8). -cache_duplicate_bags_v9(doc) -> - ["Test the write cache for duplicate bags."]; -cache_duplicate_bags_v9(suite) -> - []; +%% Test the write cache for duplicate bags. cache_duplicate_bags_v9(Config) when is_list(Config) -> cache_duplicate_bags(Config, 9). @@ -2870,7 +2728,7 @@ cache_dup_bags(Config, DelayedWrite, Extra, Sz, Version) -> {[],[]} -> ok; {X,Y} -> NoBad = length(X) + length(Y), - test_server:fail({dup_bags,DelayedWrite,Extra,Sz,NoBad}) + ct:fail({dup_bags,DelayedWrite,Extra,Sz,NoBad}) end; true -> ok @@ -2936,10 +2794,7 @@ symdiff(L1, L2) -> sofs:symmetric_partition(sofs:set(L1), sofs:set(L2)), {sofs:to_external(X), sofs:to_external(Y)}. -otp_4208(doc) -> - ["Read only table and traversal caused crash."]; -otp_4208(suite) -> - []; +%% Test read-only tables and traversal caused crashes. otp_4208(Config) when is_list(Config) -> Tab = otp_4208, FName = filename(Tab, Config), @@ -2958,10 +2813,7 @@ otp_4208(Config) when is_list(Config) -> ok. -otp_4989(doc) -> - ["Read only table and growth."]; -otp_4989(suite) -> - []; +%% Test read-only tables and growth. otp_4989(Config) when is_list(Config) -> Tab = otp_4989, FName = filename(Tab, Config), @@ -2989,10 +2841,7 @@ ets_init(Tab, N) -> ets:insert(Tab, {N,N}), ets_init(Tab, N - 1). -otp_8898(doc) -> - ["OTP-8898. Truncated Dets file."]; -otp_8898(suite) -> - []; +%% OTP-8898. Truncated Dets file. otp_8898(Config) when is_list(Config) -> Tab = otp_8898, FName = filename(Tab, Config), @@ -3012,10 +2861,7 @@ otp_8898(Config) when is_list(Config) -> ok. -otp_8899(doc) -> - ["OTP-8899. Several clients. Updated Head was ignored."]; -otp_8899(suite) -> - []; +%% OTP-8899. Several clients. Updated Head was ignored. otp_8899(Config) when is_list(Config) -> Tab = many_clients, FName = filename(Tab, Config), @@ -3040,10 +2886,7 @@ otp_8899(Config) when is_list(Config) -> ok. -many_clients(doc) -> - ["Several clients accessing a table simultaneously."]; -many_clients(suite) -> - []; +%% Test several clients accessing a table simultaneously. many_clients(Config) when is_list(Config) -> Tab = many_clients, FName = filename(Tab, Config), @@ -3229,10 +3072,7 @@ eval([{info,Tag,Expected} | L], Tab) -> eval(Else, _Tab) -> {error, {bad_request,Else}}. -otp_4906(doc) -> - ["More than 128k keys caused crash."]; -otp_4906(suite) -> - []; +%% More than 128k keys caused crash. otp_4906(Config) when is_list(Config) -> N = 256*512 + 400, Tab = otp_4906, @@ -3276,10 +3116,7 @@ ins_small(T, I, N) -> ok = dets:insert(T, {I}), ins_small(T, I+1, N). -otp_5402(doc) -> - ["Unwritable ramfile caused krasch."]; -otp_5402(suite) -> - []; +%% Unwritable ramfile caused crash. otp_5402(Config) when is_list(Config) -> Tab = otp_5402, File = filename:join(["cannot", "write", "this", "file"]), @@ -3306,10 +3143,7 @@ otp_5402(Config) when is_list(Config) -> {error,{file_error,_,_}} = dets:close(T), ok. -simultaneous_open(doc) -> - ["Several clients open and close tables simultaneously."]; -simultaneous_open(suite) -> - []; +%% Several clients open and close tables simultaneously. simultaneous_open(Config) -> Tab = sim_open, File = filename(Tab, Config), @@ -3528,10 +3362,7 @@ create_opened_log(File) -> crash(File, ?CLOSED_PROPERLY_POS+3, ?NOT_PROPERLY_CLOSED), ok. -insert_new(doc) -> - ["OTP-5075. insert_new/2"]; -insert_new(suite) -> - []; +%% OTP-5075. insert_new/2 insert_new(Config) -> Tab = insert_new, File = filename(Tab, Config), @@ -3559,10 +3390,7 @@ insert_new(Config) -> file:delete(File), ok. -repair_continuation(doc) -> - ["OTP-5126. repair_continuation/2"]; -repair_continuation(suite) -> - []; +%% OTP-5126. repair_continuation/2 repair_continuation(Config) -> Tab = repair_continuation_table, Fname = filename(repair_cont, Config), @@ -3585,10 +3413,7 @@ repair_continuation(Config) -> file:delete(Fname), ok. -otp_5487(doc) -> - ["OTP-5487. Growth of read-only table (again)."]; -otp_5487(suite) -> - []; +%% OTP-5487. Growth of read-only table (again). otp_5487(Config) -> otp_5487(Config, 9), otp_5487(Config, 8), @@ -3611,10 +3436,7 @@ otp_5487(Config, Version) -> ets:delete(Ets), file:delete(Fname). -otp_6206(doc) -> - ["OTP-6206. Badly formed free lists."]; -otp_6206(suite) -> - []; +%% OTP-6206. Badly formed free lists. otp_6206(Config) -> Tab = otp_6206, File = filename(Tab, Config), @@ -3633,10 +3455,7 @@ otp_6206(Config) -> file:delete(File), ok. -otp_6359(doc) -> - ["OTP-6359. select and match never return the empty list."]; -otp_6359(suite) -> - []; +%% OTP-6359. select and match never return the empty list. otp_6359(Config) -> Tab = otp_6359, File = filename(Tab, Config), @@ -3649,10 +3468,7 @@ otp_6359(Config) -> file:delete(File), ok. -otp_4738(doc) -> - ["OTP-4738. ==/2 and =:=/2."]; -otp_4738(suite) -> - []; +%% OTP-4738. ==/2 and =:=/2. otp_4738(Config) -> %% Version 8 has not been corrected. %% (The constant -12857447 is for version 9 only.) @@ -3804,10 +3620,7 @@ otp_4738_set(Version, Config) -> file:delete(File), ok. -otp_7146(doc) -> - ["OTP-7146. Bugfix: missing test when re-hashing."]; -otp_7146(suite) -> - []; +%% OTP-7146. Bugfix: missing test when re-hashing. otp_7146(Config) -> Tab = otp_7146, File = filename(Tab, Config), @@ -3830,10 +3643,7 @@ write_dets(Tab, N, Max) -> ok = dets:insert(Tab,{ N, {entry,N}}), write_dets(Tab, N+1, Max). -otp_8070(doc) -> - ["OTP-8070. Duplicated objects with insert_new() and duplicate_bag."]; -otp_8070(suite) -> - []; +%% OTP-8070. Duplicated objects with insert_new() and duplicate_bag. otp_8070(Config) when is_list(Config) -> Tab = otp_8070, File = filename(Tab, Config), @@ -3846,10 +3656,7 @@ otp_8070(Config) when is_list(Config) -> file:delete(File), ok. -otp_8856(doc) -> - ["OTP-8856. insert_new() bug."]; -otp_8856(suite) -> - []; +%% OTP-8856. insert_new() bug. otp_8856(Config) when is_list(Config) -> Tab = otp_8856, File = filename(Tab, Config), @@ -3871,10 +3678,7 @@ otp_8856(Config) when is_list(Config) -> file:delete(File), ok. -otp_8903(doc) -> - ["OTP-8903. bchunk/match/select bug."]; -otp_8903(suite) -> - []; +%% OTP-8903. bchunk/match/select bug. otp_8903(Config) when is_list(Config) -> Tab = otp_8903, File = filename(Tab, Config), @@ -3894,10 +3698,7 @@ otp_8903(Config) when is_list(Config) -> file:delete(File), ok. -otp_8923(doc) -> - ["OTP-8923. rehash due to lookup after initialization."]; -otp_8923(suite) -> - []; +%% OTP-8923. rehash due to lookup after initialization. otp_8923(Config) when is_list(Config) -> Tab = otp_8923, File = filename(Tab, Config), @@ -3927,10 +3728,7 @@ otp_8923(Config) when is_list(Config) -> file:delete(File), ok. -otp_9282(doc) -> - ["OTP-9282. The name of a table can be an arbitrary term"]; -otp_9282(suite) -> - []; +%% OTP-9282. The name of a table can be an arbitrary term. otp_9282(Config) when is_list(Config) -> some_calls(make_ref(), Config), some_calls({a,typical,name}, Config), @@ -3950,10 +3748,7 @@ some_calls(Tab, Config) -> file:delete(File). -otp_11245(doc) -> - ["OTP-11245. Tables remained fixed after traversal"]; -otp_11245(suite) -> - []; +%% OTP-11245. Tables remained fixed after traversal. otp_11245(Config) when is_list(Config) -> Tab = otp_11245, File = filename(Tab, Config), @@ -3972,10 +3767,7 @@ otp_11245(Config) when is_list(Config) -> file:delete(File), ok. -otp_11709(doc) -> - ["OTP-11709. Bugfixes."]; -otp_11709(suite) -> - []; +%% OTP-11709. Bugfixes. otp_11709(Config) when is_list(Config) -> Short = <<"foo">>, Long = <<"a sufficiently long text">>, @@ -4014,8 +3806,7 @@ otp_11709(Config) when is_list(Config) -> _ = file:delete(File), ok. -otp_13229(doc) -> - ["OTP-13229. open_file() exits with badarg when given binary file name."]; +%% OTP-13229. open_file() exits with badarg when given binary file name. otp_13229(_Config) -> F = <<"binfile.tab">>, try dets:open_file(name, [{file, F}]) of @@ -4026,8 +3817,7 @@ otp_13229(_Config) -> ok end. -otp_13260(doc) -> - ["OTP-13260. Race when opening a table."]; +%% OTP-13260. Race when opening a table. otp_13260(Config) -> [ok] = lists:usort([otp_13260_1(Config) || _ <- lists:seq(1, 3)]), ok. @@ -4490,7 +4280,7 @@ check_pps({Ports0,Procs0} = P0) -> show("New port", PortsDiff), show("Old proc", Procs0 -- Procs1), show("New proc", ProcsDiff), - ?t:fail() + ct:fail(failed) end end end. diff --git a/lib/stdlib/test/dict_SUITE.erl b/lib/stdlib/test/dict_SUITE.erl index 92d31bb748..d315e6f673 100644 --- a/lib/stdlib/test/dict_SUITE.erl +++ b/lib/stdlib/test/dict_SUITE.erl @@ -32,7 +32,9 @@ -import(lists, [foldl/3]). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,5}}]. all() -> [create, store, iterate]. @@ -54,12 +56,9 @@ end_per_group(_GroupName, Config) -> init_per_testcase(_Case, Config) -> - Dog = ?t:timetrap(?t:minutes(5)), - [{watchdog,Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. create(Config) when is_list(Config) -> diff --git a/lib/stdlib/test/digraph_SUITE.erl b/lib/stdlib/test/digraph_SUITE.erl index 97561196d8..8825d3fc15 100644 --- a/lib/stdlib/test/digraph_SUITE.erl +++ b/lib/stdlib/test/digraph_SUITE.erl @@ -19,7 +19,7 @@ %% -module(digraph_SUITE). -%-define(STANDALONE,1). +%%-define(STANDALONE,1). -ifdef(STANDALONE). -define(line, put(line, ?LINE), ). @@ -62,108 +62,100 @@ end_per_group(_GroupName, Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -opts(doc) -> []; -opts(suite) -> []; opts(Config) when is_list(Config) -> %% OTP-5985: the 'public' option has been removed - ?line {'EXIT',{badarg,_}} = (catch digraph:new([public])), - ?line {P2,G2} = spawn_graph([private]), - ?line {'EXIT',{badarg,_}} = (catch digraph:add_vertex(G2, x)), - ?line kill_graph(P2), - ?line {P3,G3} = spawn_graph([protected]), - ?line {'EXIT',{badarg,_}} = (catch digraph:add_vertex(G3, x)), - ?line kill_graph(P3), - ?line Template = [{v1,[v2]}, {v2,[v3]}, {v3,[v4]}, {v4,[]}], - ?line G4 = build_graph([], Template), - ?line e = digraph:add_edge(G4, e, v4, v1, []), - ?line digraph:delete(G4), - ?line G5 = build_graph([cyclic], Template), - ?line e = digraph:add_edge(G5, e, v4, v1, []), - ?line digraph:delete(G5), - ?line G6 = build_graph([acyclic], Template), - ?line acyclic = info(G6, cyclicity), - ?line {error, {bad_edge,_}} = digraph:add_edge(G6, v4, v1), - ?line digraph:delete(G6), + {'EXIT',{badarg,_}} = (catch digraph:new([public])), + {P2,G2} = spawn_graph([private]), + {'EXIT',{badarg,_}} = (catch digraph:add_vertex(G2, x)), + kill_graph(P2), + {P3,G3} = spawn_graph([protected]), + {'EXIT',{badarg,_}} = (catch digraph:add_vertex(G3, x)), + kill_graph(P3), + Template = [{v1,[v2]}, {v2,[v3]}, {v3,[v4]}, {v4,[]}], + G4 = build_graph([], Template), + e = digraph:add_edge(G4, e, v4, v1, []), + digraph:delete(G4), + G5 = build_graph([cyclic], Template), + e = digraph:add_edge(G5, e, v4, v1, []), + digraph:delete(G5), + G6 = build_graph([acyclic], Template), + acyclic = info(G6, cyclicity), + {error, {bad_edge,_}} = digraph:add_edge(G6, v4, v1), + digraph:delete(G6), ok. - + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -degree(doc) -> []; -degree(suite) -> []; degree(Config) when is_list(Config) -> - ?line G = build_graph([], [{x1,[]}, {x2,[x1]}, {x3,[x1,x2]}, - {x4,[x1,x2,x3]}, {x5,[x1,x2,x3,x4]}]), + G = build_graph([], [{x1,[]}, {x2,[x1]}, {x3,[x1,x2]}, + {x4,[x1,x2,x3]}, {x5,[x1,x2,x3,x4]}]), %% out degree - ?line 0 = digraph:out_degree(G, x1), - ?line 1 = digraph:out_degree(G, x2), - ?line 2 = digraph:out_degree(G, x3), - ?line 3 = digraph:out_degree(G, x4), - ?line 4 = digraph:out_degree(G, x5), + 0 = digraph:out_degree(G, x1), + 1 = digraph:out_degree(G, x2), + 2 = digraph:out_degree(G, x3), + 3 = digraph:out_degree(G, x4), + 4 = digraph:out_degree(G, x5), %% out neighbours - ?line [] = check(digraph:out_neighbours(G, x1), []), - ?line [] = check(digraph:out_neighbours(G, x2), [x1]), - ?line [] = check(digraph:out_neighbours(G, x3), [x1,x2]), - ?line [] = check(digraph:out_neighbours(G, x4), [x1,x2,x3]), - ?line [] = check(digraph:out_neighbours(G, x5), [x1,x2,x3,x4]), + [] = check(digraph:out_neighbours(G, x1), []), + [] = check(digraph:out_neighbours(G, x2), [x1]), + [] = check(digraph:out_neighbours(G, x3), [x1,x2]), + [] = check(digraph:out_neighbours(G, x4), [x1,x2,x3]), + [] = check(digraph:out_neighbours(G, x5), [x1,x2,x3,x4]), %% in degree - ?line 4 = digraph:in_degree(G, x1), - ?line 3 = digraph:in_degree(G, x2), - ?line 2 = digraph:in_degree(G, x3), - ?line 1 = digraph:in_degree(G, x4), - ?line 0 = digraph:in_degree(G, x5), + 4 = digraph:in_degree(G, x1), + 3 = digraph:in_degree(G, x2), + 2 = digraph:in_degree(G, x3), + 1 = digraph:in_degree(G, x4), + 0 = digraph:in_degree(G, x5), %% in neighbours - ?line [] = check(digraph:in_neighbours(G, x1), [x2,x3,x4,x5]), - ?line [] = check(digraph:in_neighbours(G, x2), [x3,x4,x5]), - ?line [] = check(digraph:in_neighbours(G, x3), [x4,x5]), - ?line [] = check(digraph:in_neighbours(G, x4), [x5]), - ?line [] = check(digraph:in_neighbours(G, x5), []), + [] = check(digraph:in_neighbours(G, x1), [x2,x3,x4,x5]), + [] = check(digraph:in_neighbours(G, x2), [x3,x4,x5]), + [] = check(digraph:in_neighbours(G, x3), [x4,x5]), + [] = check(digraph:in_neighbours(G, x4), [x5]), + [] = check(digraph:in_neighbours(G, x5), []), digraph:delete(G), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -path(doc) -> []; -path(suite) -> []; path(Config) when is_list(Config) -> - ?line G = build_graph([], [{x1,[x2,x3]}, {x2,[x4]}, {x3,[x4]}, - {x4,[x5,x6]}, {x5,[x7]}, {x6,[x7]}]), - ?line Vi = case digraph:get_path(G, x1, x7) of - [x1,x2,x4,x5,x7] -> digraph:del_vertex(G, x5), x6; - [x1,x2,x4,x6,x7] -> digraph:del_vertex(G, x6), x5; - [x1,x3,x4,x5,x7] -> digraph:del_vertex(G, x5), x6; - [x1,x3,x4,x6,x7] -> digraph:del_vertex(G, x6), x5 - end, - ?line Vj = case digraph:get_path(G, x1, x7) of - [x1,x2,x4,Vi,x7] -> digraph:del_vertex(G,x2), x3; - [x1,x3,x4,Vi,x7] -> digraph:del_vertex(G,x3), x2 - end, - ?line [x1,Vj,x4,Vi,x7] = digraph:get_path(G, x1, x7), - ?line digraph:del_vertex(G, Vj), - ?line false = digraph:get_path(G, x1, x7), - ?line [] = check(digraph:vertices(G), [x1,x4,Vi,x7]), + G = build_graph([], [{x1,[x2,x3]}, {x2,[x4]}, {x3,[x4]}, + {x4,[x5,x6]}, {x5,[x7]}, {x6,[x7]}]), + Vi = case digraph:get_path(G, x1, x7) of + [x1,x2,x4,x5,x7] -> digraph:del_vertex(G, x5), x6; + [x1,x2,x4,x6,x7] -> digraph:del_vertex(G, x6), x5; + [x1,x3,x4,x5,x7] -> digraph:del_vertex(G, x5), x6; + [x1,x3,x4,x6,x7] -> digraph:del_vertex(G, x6), x5 + end, + Vj = case digraph:get_path(G, x1, x7) of + [x1,x2,x4,Vi,x7] -> digraph:del_vertex(G,x2), x3; + [x1,x3,x4,Vi,x7] -> digraph:del_vertex(G,x3), x2 + end, + [x1,Vj,x4,Vi,x7] = digraph:get_path(G, x1, x7), + digraph:del_vertex(G, Vj), + false = digraph:get_path(G, x1, x7), + [] = check(digraph:vertices(G), [x1,x4,Vi,x7]), digraph:delete(G), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -cycle(doc) -> []; -cycle(suite) -> []; cycle(Config) when is_list(Config) -> - ?line G = build_graph([], [{x1,[x2,x3]}, {x2,[x4]}, {x3,[x4]}, - {x4,[x5,x6]}, {x5,[x7]}, {x6,[x7,x8]}, - {x8,[x3,x8]}]), - ?line false = digraph:get_cycle(G, x1), - ?line false = digraph:get_cycle(G, x2), - ?line false = digraph:get_cycle(G, x5), - ?line false = digraph:get_cycle(G, x7), - ?line [x3,x4,x6,x8,x3] = digraph:get_cycle(G, x3), - ?line [x4,x6,x8,x3,x4] = digraph:get_cycle(G, x4), - ?line [x6,x8,x3,x4,x6] = digraph:get_cycle(G, x6), - ?line [x8,x3,x4,x6,x8] = digraph:get_cycle(G, x8), - ?line digraph:del_vertex(G, x4), - ?line [x8] = digraph:get_cycle(G, x8), + G = build_graph([], [{x1,[x2,x3]}, {x2,[x4]}, {x3,[x4]}, + {x4,[x5,x6]}, {x5,[x7]}, {x6,[x7,x8]}, + {x8,[x3,x8]}]), + false = digraph:get_cycle(G, x1), + false = digraph:get_cycle(G, x2), + false = digraph:get_cycle(G, x5), + false = digraph:get_cycle(G, x7), + [x3,x4,x6,x8,x3] = digraph:get_cycle(G, x3), + [x4,x6,x8,x3,x4] = digraph:get_cycle(G, x4), + [x6,x8,x3,x4,x6] = digraph:get_cycle(G, x6), + [x8,x3,x4,x6,x8] = digraph:get_cycle(G, x8), + digraph:del_vertex(G, x4), + [x8] = digraph:get_cycle(G, x8), digraph:delete(G), ok. @@ -171,61 +163,55 @@ cycle(Config) when is_list(Config) -> -vertices(doc) -> []; -vertices(suite) -> []; vertices(Config) when is_list(Config) -> - ?line G = build_graph([], [{x,[]}, {y,[]}]), - ?line [] = check(digraph:vertices(G), [x,y]), - ?line digraph:del_vertices(G, [x,y]), - ?line [] = digraph:vertices(G), - ?line digraph:delete(G), + G = build_graph([], [{x,[]}, {y,[]}]), + [] = check(digraph:vertices(G), [x,y]), + digraph:del_vertices(G, [x,y]), + [] = digraph:vertices(G), + digraph:delete(G), ok. -edges(doc) -> []; -edges(suite) -> []; edges(Config) when is_list(Config) -> - ?line G = build_graph([], [{x, [{exy,y},{exx,x}]}, - {y, [{eyx,x}]} - ]), - ?line [] = check(digraph:edges(G), [exy, eyx, exx]), - ?line [] = check(digraph:out_edges(G, x), [exy,exx]), - ?line [] = check(digraph:in_edges(G, x), [eyx,exx]), - ?line [] = check(digraph:out_edges(G, y), [eyx]), - ?line [] = check(digraph:in_edges(G, y), [exy]), - ?line true = digraph:del_edges(G, [exy, eyx, does_not_exist]), - ?line [exx] = digraph:edges(G), - ?line [] = check(digraph:out_edges(G, x), [exx]), - ?line [] = check(digraph:in_edges(G, x), [exx]), - ?line [] = check(digraph:out_edges(G, y), []), - ?line [] = check(digraph:in_edges(G, y), []), - ?line digraph:del_vertices(G, [x,y]), - ?line [] = digraph:edges(G), - ?line [] = digraph:vertices(G), - ?line digraph:delete(G), + G = build_graph([], [{x, [{exy,y},{exx,x}]}, + {y, [{eyx,x}]} + ]), + [] = check(digraph:edges(G), [exy, eyx, exx]), + [] = check(digraph:out_edges(G, x), [exy,exx]), + [] = check(digraph:in_edges(G, x), [eyx,exx]), + [] = check(digraph:out_edges(G, y), [eyx]), + [] = check(digraph:in_edges(G, y), [exy]), + true = digraph:del_edges(G, [exy, eyx, does_not_exist]), + [exx] = digraph:edges(G), + [] = check(digraph:out_edges(G, x), [exx]), + [] = check(digraph:in_edges(G, x), [exx]), + [] = check(digraph:out_edges(G, y), []), + [] = check(digraph:in_edges(G, y), []), + digraph:del_vertices(G, [x,y]), + [] = digraph:edges(G), + [] = digraph:vertices(G), + digraph:delete(G), ok. -data(doc) -> []; -data(suite) -> []; data(Config) when is_list(Config) -> - ?line G = build_graph([], [{x, [{exy, y}]}, {y, []}]), - - ?line {x,[]} = digraph:vertex(G, x), - ?line {y,[]} = digraph:vertex(G, y), - ?line {exy,x,y,[]} = digraph:edge(G, exy), - - ?line digraph:add_edge(G, exy, x, y, {data,x,y}), - ?line E = digraph:add_edge(G, x, y, {data,y,x}), - ?line digraph:add_vertex(G, x, {any}), - ?line digraph:add_vertex(G, y, '_'), - - ?line {x,{any}} = digraph:vertex(G, x), - ?line {y,'_'} = digraph:vertex(G, y), - ?line {exy,x,y,{data,x,y}} = digraph:edge(G, exy), - ?line {E,x,y,{data,y,x}} = digraph:edge(G, E), - ?line true = digraph:del_edge(G, E), - ?line false = digraph:edge(G, E), - ?line true = sane(G), - ?line digraph:delete(G), + G = build_graph([], [{x, [{exy, y}]}, {y, []}]), + + {x,[]} = digraph:vertex(G, x), + {y,[]} = digraph:vertex(G, y), + {exy,x,y,[]} = digraph:edge(G, exy), + + digraph:add_edge(G, exy, x, y, {data,x,y}), + E = digraph:add_edge(G, x, y, {data,y,x}), + digraph:add_vertex(G, x, {any}), + digraph:add_vertex(G, y, '_'), + + {x,{any}} = digraph:vertex(G, x), + {y,'_'} = digraph:vertex(G, y), + {exy,x,y,{data,x,y}} = digraph:edge(G, exy), + {E,x,y,{data,y,x}} = digraph:edge(G, E), + true = digraph:del_edge(G, E), + false = digraph:edge(G, E), + true = sane(G), + digraph:delete(G), ok. @@ -233,87 +219,81 @@ data(Config) when is_list(Config) -> -otp_3522(doc) -> []; -otp_3522(suite) -> []; otp_3522(Config) when is_list(Config) -> - ?line G1 = build_graph([acyclic], [{x, []}]), - ?line {error, {bad_edge,_}} = digraph:add_edge(G1, x, x), - ?line true = digraph:delete(G1), - - ?line G = digraph:new(), - ?line 0 = digraph:no_vertices(G), - ?line 0 = digraph:no_edges(G), - ?line V1 = digraph:add_vertex(G), - ?line '$vid' = digraph:add_vertex(G, '$vid'), - ?line V2 = digraph:add_vertex(G), - ?line '$eid' = digraph:add_edge(G, '$eid', V1, V2, []), - ?line E = digraph:add_edge(G, V1, V2), - ?line 3 = digraph:no_vertices(G), - ?line 2 = digraph:no_edges(G), - ?line cyclic = info(G, cyclicity), - ?line protected = info(G, protection), - - ?line [] = check(digraph:in_edges(G, V2), ['$eid', E]), - ?line [] = check(digraph:out_edges(G, V1), ['$eid', E]), - ?line [] = check(digraph:vertices(G), [V1,V2,'$vid']), - ?line [] = check(digraph:edges(G), [E, '$eid']), - ?line true = sane(G), - ?line true = digraph:delete(G), + G1 = build_graph([acyclic], [{x, []}]), + {error, {bad_edge,_}} = digraph:add_edge(G1, x, x), + true = digraph:delete(G1), + + G = digraph:new(), + 0 = digraph:no_vertices(G), + 0 = digraph:no_edges(G), + V1 = digraph:add_vertex(G), + '$vid' = digraph:add_vertex(G, '$vid'), + V2 = digraph:add_vertex(G), + '$eid' = digraph:add_edge(G, '$eid', V1, V2, []), + E = digraph:add_edge(G, V1, V2), + 3 = digraph:no_vertices(G), + 2 = digraph:no_edges(G), + cyclic = info(G, cyclicity), + protected = info(G, protection), + + [] = check(digraph:in_edges(G, V2), ['$eid', E]), + [] = check(digraph:out_edges(G, V1), ['$eid', E]), + [] = check(digraph:vertices(G), [V1,V2,'$vid']), + [] = check(digraph:edges(G), [E, '$eid']), + true = sane(G), + true = digraph:delete(G), ok. -otp_3630(doc) -> []; -otp_3630(suite) -> []; otp_3630(Config) when is_list(Config) -> - ?line G = build_graph([], [{x, [{exy,y},{exx,x}]}, - {y, [{eyy,y},{eyx,x}]} - ]), - ?line [x,y] = digraph:get_path(G, x, y), - ?line [y,x] = digraph:get_path(G, y, x), - - ?line [x,x] = digraph:get_short_path(G, x, x), - ?line [y,y] = digraph:get_short_path(G, y, y), - ?line true = digraph:delete(G), - - ?line G1 = build_graph([], [{1, [{12,2},{13,3},{11,1}]}, - {2, [{23,3}]}, - {3, [{34,4},{35,5}]}, - {4, [{45,5}]}, - {5, [{56,6},{57,7}]}, - {6, [{67,7}]}, - {7, [{71,1}]} - ]), - - ?line [1,3,5,7] = digraph:get_short_path(G1, 1, 7), - ?line [3,5,7,1,3] = digraph:get_short_cycle(G1, 3), - ?line [1,1] = digraph:get_short_cycle(G1, 1), - ?line true = digraph:delete(G1), + G = build_graph([], [{x, [{exy,y},{exx,x}]}, + {y, [{eyy,y},{eyx,x}]} + ]), + [x,y] = digraph:get_path(G, x, y), + [y,x] = digraph:get_path(G, y, x), + + [x,x] = digraph:get_short_path(G, x, x), + [y,y] = digraph:get_short_path(G, y, y), + true = digraph:delete(G), + + G1 = build_graph([], [{1, [{12,2},{13,3},{11,1}]}, + {2, [{23,3}]}, + {3, [{34,4},{35,5}]}, + {4, [{45,5}]}, + {5, [{56,6},{57,7}]}, + {6, [{67,7}]}, + {7, [{71,1}]} + ]), + + [1,3,5,7] = digraph:get_short_path(G1, 1, 7), + [3,5,7,1,3] = digraph:get_short_cycle(G1, 3), + [1,1] = digraph:get_short_cycle(G1, 1), + true = digraph:delete(G1), F = 0.0, I = round(F), - ?line G2 = digraph:new([acyclic]), - ?line digraph:add_vertex(G2, F), - ?line digraph:add_vertex(G2, I), - ?line E = digraph:add_edge(G2, F, I), - ?line true = not is_tuple(E), - ?line true = sane(G2), - ?line true = digraph:delete(G2), + G2 = digraph:new([acyclic]), + digraph:add_vertex(G2, F), + digraph:add_vertex(G2, I), + E = digraph:add_edge(G2, F, I), + true = not is_tuple(E), + true = sane(G2), + true = digraph:delete(G2), ok. -otp_8066(doc) -> []; -otp_8066(suite) -> []; otp_8066(Config) when is_list(Config) -> fun() -> D = digraph:new(), V1 = digraph:add_vertex(D), V2 = digraph:add_vertex(D), _ = digraph:add_edge(D, V1, V2), - ?line [V1, V2] = digraph:get_path(D, V1, V2), - ?line true = sane(D), - ?line true = digraph:del_path(D, V1, V2), - ?line true = sane(D), - ?line false = digraph:get_path(D, V1, V2), - ?line true = digraph:del_path(D, V1, V2), - ?line true = digraph:delete(D) + [V1, V2] = digraph:get_path(D, V1, V2), + true = sane(D), + true = digraph:del_path(D, V1, V2), + true = sane(D), + false = digraph:get_path(D, V1, V2), + true = digraph:del_path(D, V1, V2), + true = digraph:delete(D) end(), fun() -> @@ -324,15 +304,15 @@ otp_8066(Config) when is_list(Config) -> _ = digraph:add_edge(D, V1, V2), _ = digraph:add_edge(D, V1, V1), _ = digraph:add_edge(D, V2, V2), - ?line [V1, V2] = digraph:get_path(D, V1, V2), - ?line true = sane(D), - ?line true = digraph:del_path(D, V1, V2), - ?line false = digraph:get_short_path(D, V2, V1), - - ?line true = sane(D), - ?line false = digraph:get_path(D, V1, V2), - ?line true = digraph:del_path(D, V1, V2), - ?line true = digraph:delete(D) + [V1, V2] = digraph:get_path(D, V1, V2), + true = sane(D), + true = digraph:del_path(D, V1, V2), + false = digraph:get_short_path(D, V2, V1), + + true = sane(D), + false = digraph:get_path(D, V1, V2), + true = digraph:del_path(D, V1, V2), + true = digraph:delete(D) end(), fun() -> @@ -342,18 +322,18 @@ otp_8066(Config) when is_list(Config) -> W3 = digraph:add_vertex(G), W4 = digraph:add_vertex(G), _ = digraph:add_edge(G,['$e'|0], W1, W2, {}), - ?line {error,{bad_vertex, bv}} = + {error,{bad_vertex, bv}} = digraph:add_edge(G, edge, bv, W1, {}), - ?line {error,{bad_vertex, bv}} = + {error,{bad_vertex, bv}} = digraph:add_edge(G, edge, W1, bv, {}), - ?line false = digraph:get_short_cycle(G, W1), - ?line {error, {bad_edge,_}} = + false = digraph:get_short_cycle(G, W1), + {error, {bad_edge,_}} = digraph:add_edge(G,['$e'|0], W3, W4, {}), - ?line true = sane(G), - ?line true = digraph:delete(G) + true = sane(G), + true = digraph:delete(G) end(), ok. - + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -422,7 +402,7 @@ sane1(G) -> end end, OutEs) end, Vs), - + InEs = lists:flatmap(fun(V) -> digraph:in_edges(G, V) end, Vs), OutEs = lists:flatmap(fun(V) -> digraph:out_edges(G, V) end, Vs), lists:foreach( @@ -450,7 +430,7 @@ sane1(G) -> end, Edges = [digraph:edge(G, E) || E <- Es], EVs = lists:usort([V || {_, V, _, _} <- Edges] ++ - [V || {_, _, V, _} <- Edges]), + [V || {_, _, V, _} <- Edges]), lists:foreach( fun(V) -> case digraph:vertex(G, V) of diff --git a/lib/stdlib/test/digraph_utils_SUITE.erl b/lib/stdlib/test/digraph_utils_SUITE.erl index e155857bd4..23520072f8 100644 --- a/lib/stdlib/test/digraph_utils_SUITE.erl +++ b/lib/stdlib/test/digraph_utils_SUITE.erl @@ -19,7 +19,7 @@ %% -module(digraph_utils_SUITE). -%-define(debug, true). +%%-define(debug, true). -ifdef(debug). -define(line, put(line, ?LINE), ). -else. @@ -59,205 +59,192 @@ end_per_group(_GroupName, Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -simple(doc) -> []; -simple(suite) -> []; simple(Config) when is_list(Config) -> - ?line G = digraph:new(), - ?line add_vertices(G, [a]), - ?line add_edges(G, [{b,c},{b,d},{e,f},{f,g},{g,e},{h,h},{i,i},{i,j}]), - ?line 10 = length(digraph_utils:postorder(G)), - ?line 10 = length(digraph_utils:preorder(G)), - ?line ok = evall(digraph_utils:components(G), - [[a],[b,c,d],[e,f,g],[h],[i,j]]), - ?line ok = evall(digraph_utils:strong_components(G), + G = digraph:new(), + add_vertices(G, [a]), + add_edges(G, [{b,c},{b,d},{e,f},{f,g},{g,e},{h,h},{i,i},{i,j}]), + 10 = length(digraph_utils:postorder(G)), + 10 = length(digraph_utils:preorder(G)), + ok = evall(digraph_utils:components(G), + [[a],[b,c,d],[e,f,g],[h],[i,j]]), + ok = evall(digraph_utils:strong_components(G), [[a],[b],[c],[d],[e,f,g],[h],[i],[j]]), - ?line ok = evall(digraph_utils:cyclic_strong_components(G), - [[e,f,g],[h],[i]]), - ?line true = path(G, e, e), - ?line false = path(G, e, j), - ?line false = path(G, a, a), - ?line false = digraph_utils:topsort(G), - ?line false = digraph_utils:is_acyclic(G), - ?line ok = eval(digraph_utils:loop_vertices(G), [h,i]), - ?line ok = eval(digraph_utils:reaching([e], G), [e,f,g]), - ?line ok = eval(digraph_utils:reaching_neighbours([e], G), [e,f,g]), - ?line ok = eval(digraph_utils:reachable([e], G), [e,f,g]), - ?line ok = eval(digraph_utils:reachable_neighbours([e], G), [e,f,g]), - ?line ok = eval(digraph_utils:reaching([b], G), [b]), - ?line ok = eval(digraph_utils:reaching_neighbours([b], G), []), - ?line ok = eval(digraph_utils:reachable([b], G), [b,c,d]), - ?line ok = eval(digraph_utils:reachable_neighbours([b], G), [c,d]), - ?line ok = eval(digraph_utils:reaching([h], G), [h]), - ?line ok = eval(digraph_utils:reaching_neighbours([h], G), [h]), - ?line ok = eval(digraph_utils:reachable([h], G), [h]), - ?line ok = eval(digraph_utils:reachable_neighbours([h], G), [h]), - ?line ok = eval(digraph_utils:reachable([e,f], G), [e,f,g]), - ?line ok = eval(digraph_utils:reachable_neighbours([e,f], G), [e,f,g]), - ?line ok = eval(digraph_utils:reachable([h,h,h], G), [h]), - ?line true = digraph:delete(G), + ok = evall(digraph_utils:cyclic_strong_components(G), + [[e,f,g],[h],[i]]), + true = path(G, e, e), + false = path(G, e, j), + false = path(G, a, a), + false = digraph_utils:topsort(G), + false = digraph_utils:is_acyclic(G), + ok = eval(digraph_utils:loop_vertices(G), [h,i]), + ok = eval(digraph_utils:reaching([e], G), [e,f,g]), + ok = eval(digraph_utils:reaching_neighbours([e], G), [e,f,g]), + ok = eval(digraph_utils:reachable([e], G), [e,f,g]), + ok = eval(digraph_utils:reachable_neighbours([e], G), [e,f,g]), + ok = eval(digraph_utils:reaching([b], G), [b]), + ok = eval(digraph_utils:reaching_neighbours([b], G), []), + ok = eval(digraph_utils:reachable([b], G), [b,c,d]), + ok = eval(digraph_utils:reachable_neighbours([b], G), [c,d]), + ok = eval(digraph_utils:reaching([h], G), [h]), + ok = eval(digraph_utils:reaching_neighbours([h], G), [h]), + ok = eval(digraph_utils:reachable([h], G), [h]), + ok = eval(digraph_utils:reachable_neighbours([h], G), [h]), + ok = eval(digraph_utils:reachable([e,f], G), [e,f,g]), + ok = eval(digraph_utils:reachable_neighbours([e,f], G), [e,f,g]), + ok = eval(digraph_utils:reachable([h,h,h], G), [h]), + true = digraph:delete(G), ok. -loop(doc) -> []; -loop(suite) -> []; loop(Config) when is_list(Config) -> - ?line G = digraph:new(), - ?line add_vertices(G, [a,b]), - ?line add_edges(G, [{a,a},{b,b}]), - ?line ok = evall(digraph_utils:components(G), [[a],[b]]), - ?line ok = evall(digraph_utils:strong_components(G), [[a],[b]]), - ?line ok = evall(digraph_utils:cyclic_strong_components(G), [[a],[b]]), - ?line [_,_] = digraph_utils:topsort(G), - ?line false = digraph_utils:is_acyclic(G), - ?line ok = eval(digraph_utils:loop_vertices(G), [a,b]), - ?line [_,_] = digraph_utils:preorder(G), - ?line [_,_] = digraph_utils:postorder(G), - ?line ok = eval(digraph_utils:reaching([b], G), [b]), - ?line ok = eval(digraph_utils:reaching_neighbours([b], G), [b]), - ?line ok = eval(digraph_utils:reachable([b], G), [b]), - ?line ok = eval(digraph_utils:reachable_neighbours([b], G), [b]), - ?line true = path(G, a, a), - ?line true = digraph:delete(G), + G = digraph:new(), + add_vertices(G, [a,b]), + add_edges(G, [{a,a},{b,b}]), + ok = evall(digraph_utils:components(G), [[a],[b]]), + ok = evall(digraph_utils:strong_components(G), [[a],[b]]), + ok = evall(digraph_utils:cyclic_strong_components(G), [[a],[b]]), + [_,_] = digraph_utils:topsort(G), + false = digraph_utils:is_acyclic(G), + ok = eval(digraph_utils:loop_vertices(G), [a,b]), + [_,_] = digraph_utils:preorder(G), + [_,_] = digraph_utils:postorder(G), + ok = eval(digraph_utils:reaching([b], G), [b]), + ok = eval(digraph_utils:reaching_neighbours([b], G), [b]), + ok = eval(digraph_utils:reachable([b], G), [b]), + ok = eval(digraph_utils:reachable_neighbours([b], G), [b]), + true = path(G, a, a), + true = digraph:delete(G), ok. -isolated(doc) -> []; -isolated(suite) -> []; isolated(Config) when is_list(Config) -> - ?line G = digraph:new(), - ?line add_vertices(G, [a,b]), - ?line ok = evall(digraph_utils:components(G), [[a],[b]]), - ?line ok = evall(digraph_utils:strong_components(G), [[a],[b]]), - ?line ok = evall(digraph_utils:cyclic_strong_components(G), []), - ?line [_,_] = digraph_utils:topsort(G), - ?line true = digraph_utils:is_acyclic(G), - ?line ok = eval(digraph_utils:loop_vertices(G), []), - ?line [_,_] = digraph_utils:preorder(G), - ?line [_,_] = digraph_utils:postorder(G), - ?line ok = eval(digraph_utils:reaching([b], G), [b]), - ?line ok = eval(digraph_utils:reaching_neighbours([b], G), []), - ?line ok = eval(digraph_utils:reachable([b], G), [b]), - ?line ok = eval(digraph_utils:reachable_neighbours([b], G), []), - ?line false = path(G, a, a), - ?line true = digraph:delete(G), + G = digraph:new(), + add_vertices(G, [a,b]), + ok = evall(digraph_utils:components(G), [[a],[b]]), + ok = evall(digraph_utils:strong_components(G), [[a],[b]]), + ok = evall(digraph_utils:cyclic_strong_components(G), []), + [_,_] = digraph_utils:topsort(G), + true = digraph_utils:is_acyclic(G), + ok = eval(digraph_utils:loop_vertices(G), []), + [_,_] = digraph_utils:preorder(G), + [_,_] = digraph_utils:postorder(G), + ok = eval(digraph_utils:reaching([b], G), [b]), + ok = eval(digraph_utils:reaching_neighbours([b], G), []), + ok = eval(digraph_utils:reachable([b], G), [b]), + ok = eval(digraph_utils:reachable_neighbours([b], G), []), + false = path(G, a, a), + true = digraph:delete(G), ok. -topsort(doc) -> []; -topsort(suite) -> []; topsort(Config) when is_list(Config) -> - ?line G = digraph:new(), - ?line add_edges(G, [{a,b},{b,c},{c,d},{d,e},{e,f}]), - ?line ok = eval(digraph_utils:topsort(G), [a,b,c,d,e,f]), - ?line true = digraph:delete(G), + G = digraph:new(), + add_edges(G, [{a,b},{b,c},{c,d},{d,e},{e,f}]), + ok = eval(digraph_utils:topsort(G), [a,b,c,d,e,f]), + true = digraph:delete(G), ok. -subgraph(doc) -> []; -subgraph(suite) -> []; subgraph(Config) when is_list(Config) -> - ?line G = digraph:new([acyclic]), - ?line add_edges(G, [{b,c},{b,d},{e,f},{f,fg,fgl,g},{f,fg2,fgl2,g},{g,e}, - {h,h},{i,i},{i,j}]), - ?line add_vertices(G, [{b,bl},{f,fl}]), - ?line SG = digraph_utils:subgraph(G, [u1,b,c,u2,f,g,i,u3]), - ?line [b,c,f,g,i] = lists:sort(digraph:vertices(SG)), - ?line {b,bl} = digraph:vertex(SG, b), - ?line {c,[]} = digraph:vertex(SG, c), - ?line {fg,f,g,fgl} = digraph:edge(SG, fg), - ?line {fg2,f,g,fgl2} = digraph:edge(SG, fg2), - ?line {_, {_, acyclic}} = lists:keysearch(cyclicity, 1, digraph:info(SG)), - ?line true = digraph:delete(SG), - - ?line SG1 = digraph_utils:subgraph(G, [f, g, h], - [{type, []}, {keep_labels, false}]), - ?line [f,g,h] = lists:sort(digraph:vertices(SG1)), - ?line {f,[]} = digraph:vertex(SG1, f), - ?line {fg,f,g,[]} = digraph:edge(SG1, fg), - ?line {_, {_, cyclic}} = lists:keysearch(cyclicity, 1, digraph:info(SG1)), - ?line true = digraph:delete(SG1), - - ?line SG2 = digraph_utils:subgraph(G, [f, g, h], - [{type, [acyclic]}, - {keep_labels, true}]), - ?line [f,g,h] = lists:sort(digraph:vertices(SG2)), - ?line {f,fl} = digraph:vertex(SG2, f), - ?line {fg,f,g,fgl} = digraph:edge(SG2, fg), - ?line {_, {_, acyclic}} = lists:keysearch(cyclicity, 1, digraph:info(SG2)), - ?line true = digraph:delete(SG2), - - ?line {'EXIT',{badarg,_}} = + G = digraph:new([acyclic]), + add_edges(G, [{b,c},{b,d},{e,f},{f,fg,fgl,g},{f,fg2,fgl2,g},{g,e}, + {h,h},{i,i},{i,j}]), + add_vertices(G, [{b,bl},{f,fl}]), + SG = digraph_utils:subgraph(G, [u1,b,c,u2,f,g,i,u3]), + [b,c,f,g,i] = lists:sort(digraph:vertices(SG)), + {b,bl} = digraph:vertex(SG, b), + {c,[]} = digraph:vertex(SG, c), + {fg,f,g,fgl} = digraph:edge(SG, fg), + {fg2,f,g,fgl2} = digraph:edge(SG, fg2), + {_, {_, acyclic}} = lists:keysearch(cyclicity, 1, digraph:info(SG)), + true = digraph:delete(SG), + + SG1 = digraph_utils:subgraph(G, [f, g, h], + [{type, []}, {keep_labels, false}]), + [f,g,h] = lists:sort(digraph:vertices(SG1)), + {f,[]} = digraph:vertex(SG1, f), + {fg,f,g,[]} = digraph:edge(SG1, fg), + {_, {_, cyclic}} = lists:keysearch(cyclicity, 1, digraph:info(SG1)), + true = digraph:delete(SG1), + + SG2 = digraph_utils:subgraph(G, [f, g, h], + [{type, [acyclic]}, + {keep_labels, true}]), + [f,g,h] = lists:sort(digraph:vertices(SG2)), + {f,fl} = digraph:vertex(SG2, f), + {fg,f,g,fgl} = digraph:edge(SG2, fg), + {_, {_, acyclic}} = lists:keysearch(cyclicity, 1, digraph:info(SG2)), + true = digraph:delete(SG2), + + {'EXIT',{badarg,_}} = (catch digraph_utils:subgraph(G, [f], [{invalid, opt}])), - ?line {'EXIT',{badarg,_}} = + {'EXIT',{badarg,_}} = (catch digraph_utils:subgraph(G, [f], [{keep_labels, not_Bool}])), - ?line {'EXIT',{badarg,_}} = + {'EXIT',{badarg,_}} = (catch digraph_utils:subgraph(G, [f], [{type, not_type}])), - ?line {'EXIT',{badarg,_}} = + {'EXIT',{badarg,_}} = (catch digraph_utils:subgraph(G, [f], [{type, [not_type]}])), - ?line {'EXIT',{badarg,_}} = + {'EXIT',{badarg,_}} = (catch digraph_utils:subgraph(G, [f], not_a_list)), - ?line true = digraph:delete(G), + true = digraph:delete(G), ok. -condensation(doc) -> []; -condensation(suite) -> []; condensation(Config) when is_list(Config) -> - ?line G = digraph:new([]), - ?line add_edges(G, [{b,c},{b,d},{e,f},{f,fg,fgl,g},{f,fg2,fgl2,g},{g,e}, - {h,h},{j,i},{i,j}]), - ?line add_vertices(G, [q]), - ?line CG = digraph_utils:condensation(G), - ?line Vs = sort_2(digraph:vertices(CG)), - ?line [[b],[c],[d],[e,f,g],[h],[i,j],[q]] = Vs, - ?line Fun = fun(E) -> - {_E, V1, V2, _L} = digraph:edge(CG, E), - {lists:sort(V1), lists:sort(V2)} - end, - ?line Es = lists:map(Fun, digraph:edges(CG)), - ?line [{[b],[c]},{[b],[d]}] = lists:sort(Es), - ?line true = digraph:delete(CG), - ?line true = digraph:delete(G), + G = digraph:new([]), + add_edges(G, [{b,c},{b,d},{e,f},{f,fg,fgl,g},{f,fg2,fgl2,g},{g,e}, + {h,h},{j,i},{i,j}]), + add_vertices(G, [q]), + CG = digraph_utils:condensation(G), + Vs = sort_2(digraph:vertices(CG)), + [[b],[c],[d],[e,f,g],[h],[i,j],[q]] = Vs, + Fun = fun(E) -> + {_E, V1, V2, _L} = digraph:edge(CG, E), + {lists:sort(V1), lists:sort(V2)} + end, + Es = lists:map(Fun, digraph:edges(CG)), + [{[b],[c]},{[b],[d]}] = lists:sort(Es), + true = digraph:delete(CG), + true = digraph:delete(G), ok. -tree(doc) -> ["OTP-7081"]; -tree(suite) -> []; +%% OTP-7081 tree(Config) when is_list(Config) -> - ?line false = is_tree([], []), - ?line true = is_tree([a], []), - ?line false = is_tree([a,b], []), - ?line true = is_tree([{a,b}]), - ?line false = is_tree([{a,b},{b,a}]), - ?line true = is_tree([{a,b},{a,c},{b,d},{b,e}]), - ?line false = is_tree([{a,b},{a,c},{b,d},{b,e}, {d,e}]), - ?line false = is_tree([{a,b},{a,c},{b,d},{b,e}, {b,e}]), - ?line true = is_tree([{a,c},{c,b}]), - ?line true = is_tree([{b,a},{c,a}]), + false = is_tree([], []), + true = is_tree([a], []), + false = is_tree([a,b], []), + true = is_tree([{a,b}]), + false = is_tree([{a,b},{b,a}]), + true = is_tree([{a,b},{a,c},{b,d},{b,e}]), + false = is_tree([{a,b},{a,c},{b,d},{b,e}, {d,e}]), + false = is_tree([{a,b},{a,c},{b,d},{b,e}, {b,e}]), + true = is_tree([{a,c},{c,b}]), + true = is_tree([{b,a},{c,a}]), %% Parallel edges. Acyclic and with one componets %% (according to the digraph module). - ?line false = is_tree([{a,b},{a,b}]), - - ?line no = arborescence_root([], []), - ?line {yes, a} = arborescence_root([a], []), - ?line no = arborescence_root([a,b], []), - ?line {yes, a} = arborescence_root([{a,b}]), - ?line no = arborescence_root([{a,b},{b,a}]), - ?line {yes, a} = arborescence_root([{a,b},{a,c},{b,d},{b,e}]), - ?line no = arborescence_root([{a,b},{a,c},{b,d},{b,e}, {d,e}]), - ?line no = arborescence_root([{a,b},{a,c},{b,d},{b,e}, {b,e}]), - ?line {yes, a} = arborescence_root([{a,c},{c,b}]), - ?line no = arborescence_root([{b,a},{c,a}]), - - ?line false = is_arborescence([], []), - ?line true = is_arborescence([a], []), - ?line false = is_arborescence([a,b], []), - ?line true = is_arborescence([{a,b}]), - ?line false = is_arborescence([{a,b},{b,a}]), - ?line true = is_arborescence([{a,b},{a,c},{b,d},{b,e}]), - ?line false = is_arborescence([{a,b},{a,c},{b,d},{b,e}, {d,e}]), - ?line false = is_arborescence([{a,b},{a,c},{b,d},{b,e}, {b,e}]), - ?line true = is_arborescence([{a,c},{c,b}]), - ?line false = is_arborescence([{b,a},{c,a}]), + false = is_tree([{a,b},{a,b}]), + + no = arborescence_root([], []), + {yes, a} = arborescence_root([a], []), + no = arborescence_root([a,b], []), + {yes, a} = arborescence_root([{a,b}]), + no = arborescence_root([{a,b},{b,a}]), + {yes, a} = arborescence_root([{a,b},{a,c},{b,d},{b,e}]), + no = arborescence_root([{a,b},{a,c},{b,d},{b,e}, {d,e}]), + no = arborescence_root([{a,b},{a,c},{b,d},{b,e}, {b,e}]), + {yes, a} = arborescence_root([{a,c},{c,b}]), + no = arborescence_root([{b,a},{c,a}]), + + false = is_arborescence([], []), + true = is_arborescence([a], []), + false = is_arborescence([a,b], []), + true = is_arborescence([{a,b}]), + false = is_arborescence([{a,b},{b,a}]), + true = is_arborescence([{a,b},{a,c},{b,d},{b,e}]), + false = is_arborescence([{a,b},{a,c},{b,d},{b,e}, {d,e}]), + false = is_arborescence([{a,b},{a,c},{b,d},{b,e}, {b,e}]), + true = is_arborescence([{a,c},{c,b}]), + false = is_arborescence([{b,a},{c,a}]), %% Parallel edges. - ?line false = is_arborescence([{a,b},{a,b}]), + false = is_arborescence([{a,b},{a,b}]), ok. @@ -325,7 +312,7 @@ eval(L, E) -> evall(L, E) -> F = fun(L1) -> lists:sort(L1) end, Fun = fun(LL) -> F(lists:map(F, LL)) end, - + Expected = Fun(E), Got = Fun(L), if diff --git a/lib/stdlib/test/dummy1_h.erl b/lib/stdlib/test/dummy1_h.erl index 5db23872c4..cdf9a305e1 100644 --- a/lib/stdlib/test/dummy1_h.erl +++ b/lib/stdlib/test/dummy1_h.erl @@ -37,7 +37,7 @@ handle_event(delete_event, _Parent) -> remove_handler; handle_event(do_crash, _State) -> erlang:error({badmatch,4}); -%Inverse of dummy_h +%%Inverse of dummy_h handle_event(hibernate, Parent) -> {ok,Parent}; handle_event(wakeup, Parent) -> diff --git a/lib/stdlib/test/dummy_via.erl b/lib/stdlib/test/dummy_via.erl index e405811cbe..026b329688 100644 --- a/lib/stdlib/test/dummy_via.erl +++ b/lib/stdlib/test/dummy_via.erl @@ -50,8 +50,10 @@ call(Req) -> {'DOWN', MRef, _, _, _} -> erlang:error(badarg); {MRef, badarg} -> + erlang:demonitor(MRef), erlang:error(badarg); {MRef, Reply} -> + erlang:demonitor(MRef), Reply after 5000 -> erlang:error(timeout) diff --git a/lib/stdlib/test/edlin_expand_SUITE.erl b/lib/stdlib/test/edlin_expand_SUITE.erl index b0a07a95a3..a53c5333d8 100644 --- a/lib/stdlib/test/edlin_expand_SUITE.erl +++ b/lib/stdlib/test/edlin_expand_SUITE.erl @@ -19,26 +19,21 @@ %% -module(edlin_expand_SUITE). -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, + init_per_testcase/2, end_per_testcase/2, init_per_group/2,end_per_group/2]). - -export([normal/1, quoted_fun/1, quoted_module/1, quoted_both/1]). --export([init_per_testcase/2, end_per_testcase/2]). - -include_lib("common_test/include/ct.hrl"). -%% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(1)). - init_per_testcase(_Case, Config) -> - Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), + Config. + +end_per_testcase(_Case, _Config) -> ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [normal, quoted_fun, quoted_module, quoted_both]. @@ -63,10 +58,6 @@ end_per_group(_GroupName, Config) -> Config. -normal(doc) -> - [""]; -normal(suite) -> - []; normal(Config) when is_list(Config) -> {module,expand_test} = c:l(expand_test), %% These tests might fail if another module with the prefix @@ -85,10 +76,7 @@ normal(Config) when is_list(Config) -> {yes,"arity_entirely()",[]} = do_expand("expand_test:expand0"), ok. -quoted_fun(doc) -> - ["Normal module name, some function names using quoted atoms"]; -quoted_fun(suite) -> - []; +%% Normal module name, some function names using quoted atoms. quoted_fun(Config) when is_list(Config) -> {module,expand_test} = c:l(expand_test), {module,expand_test1} = c:l(expand_test1), @@ -121,10 +109,6 @@ quoted_fun(Config) when is_list(Config) -> {yes,"(",[]} = do_expand("expand_test:module_info"), ok. -quoted_module(doc) -> - [""]; -quoted_module(suite) -> - []; quoted_module(Config) when is_list(Config) -> {module,'ExpandTestCaps'} = c:l('ExpandTestCaps'), {yes, "Caps':", []} = do_expand("'ExpandTest"), @@ -138,8 +122,6 @@ quoted_module(Config) when is_list(Config) -> {"a_less_fun_name",1}]} = do_expand("'ExpandTestCaps':a_"), ok. -quoted_both(suite) -> - []; quoted_both(Config) when is_list(Config) -> {module,'ExpandTestCaps'} = c:l('ExpandTestCaps'), {module,'ExpandTestCaps1'} = c:l('ExpandTestCaps1'), diff --git a/lib/stdlib/test/epp_SUITE.erl b/lib/stdlib/test/epp_SUITE.erl index 0c00e104b7..3e1aaef378 100644 --- a/lib/stdlib/test/epp_SUITE.erl +++ b/lib/stdlib/test/epp_SUITE.erl @@ -34,7 +34,7 @@ %% %% Define to run outside of test server %% -%-define(STANDALONE,1). +%%-define(STANDALONE,1). -ifdef(STANDALONE). -compile(export_all). @@ -50,19 +50,16 @@ config(data_dir, _) -> -include_lib("common_test/include/ct.hrl"). -export([init_per_testcase/2, end_per_testcase/2]). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(1)). - init_per_testcase(_, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. -end_per_testcase(_, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), + Config. + +end_per_testcase(_, _Config) -> ok. -endif. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [rec_1, {group, upcase_mac}, include_local, predef_mac, @@ -88,33 +85,26 @@ init_per_group(_GroupName, Config) -> end_per_group(_GroupName, Config) -> Config. -rec_1(doc) -> - ["Recursive macros hang or crash epp (OTP-1398)."]; -rec_1(suite) -> - []; +%% Recursive macros hang or crash epp (OTP-1398). rec_1(Config) when is_list(Config) -> - ?line File = filename:join(?config(data_dir, Config), "mac.erl"), - ?line {ok, List} = epp_parse_file(File, [], []), + File = filename:join(proplists:get_value(data_dir, Config), "mac.erl"), + {ok, List} = epp_parse_file(File, [], []), %% we should encounter errors - ?line {value, _} = lists:keysearch(error, 1, List), - ?line check_errors(List), + {value, _} = lists:keysearch(error, 1, List), + check_errors(List), ok. -include_local(doc) -> - []; -include_local(suite) -> - []; include_local(Config) when is_list(Config) -> - ?line DataDir = ?config(data_dir, Config), - ?line File = filename:join(DataDir, "include_local.erl"), + DataDir = proplists:get_value(data_dir, Config), + File = filename:join(DataDir, "include_local.erl"), FooHrl = filename:join([DataDir,"include","foo.hrl"]), BarHrl = filename:join([DataDir,"include","bar.hrl"]), %% include_local.erl includes include/foo.hrl which %% includes bar.hrl (also in include/) without requiring %% any additional include path, and overriding any file %% of the same name that the path points to - ?line {ok, List} = epp:parse_file(File, [DataDir], []), - ?line {value, {attribute,_,a,{true,true}}} = + {ok, List} = epp:parse_file(File, [DataDir], []), + {value, {attribute,_,a,{true,true}}} = lists:keysearch(a,3,List), [{File,1},{FooHrl,1},{BarHrl,1},{FooHrl,5},{File,5}] = [ FileLine || {attribute,_,file,FileLine} <- List ], @@ -170,108 +160,86 @@ epp_parse_erl_form(Epp, Parent) -> check_errors([]) -> ok; check_errors([{error, Info} | Rest]) -> - ?line {Line, Mod, Desc} = Info, - ?line case Line of - I when is_integer(I) -> ok; - {L,C} when is_integer(L), is_integer(C), C >= 1 -> ok - end, - ?line Str = lists:flatten(Mod:format_error(Desc)), - ?line [Str] = io_lib:format("~s", [Str]), + {Line, Mod, Desc} = Info, + case Line of + I when is_integer(I) -> ok; + {L,C} when is_integer(L), is_integer(C), C >= 1 -> ok + end, + Str = lists:flatten(Mod:format_error(Desc)), + [Str] = io_lib:format("~s", [Str]), check_errors(Rest); check_errors([_ | Rest]) -> check_errors(Rest). -upcase_mac_1(doc) -> - []; -upcase_mac_1(suite) -> - []; upcase_mac_1(Config) when is_list(Config) -> - ?line File = filename:join(?config(data_dir, Config), "mac2.erl"), - ?line {ok, List} = epp:parse_file(File, [], []), - ?line [_, {attribute, _, plupp, Tuple} | _] = List, - ?line Tuple = {1, 1, 3, 3}, + File = filename:join(proplists:get_value(data_dir, Config), "mac2.erl"), + {ok, List} = epp:parse_file(File, [], []), + [_, {attribute, _, plupp, Tuple} | _] = List, + Tuple = {1, 1, 3, 3}, ok. -upcase_mac_2(doc) -> - []; -upcase_mac_2(suite) -> - []; upcase_mac_2(Config) when is_list(Config) -> - ?line File = filename:join(?config(data_dir, Config), "mac2.erl"), - ?line {ok, List} = epp:parse_file(File, [], [{p, 5}, {'P', 6}]), - ?line [_, {attribute, _, plupp, Tuple} | _] = List, - ?line Tuple = {5, 5, 6, 6}, + File = filename:join(proplists:get_value(data_dir, Config), "mac2.erl"), + {ok, List} = epp:parse_file(File, [], [{p, 5}, {'P', 6}]), + [_, {attribute, _, plupp, Tuple} | _] = List, + Tuple = {5, 5, 6, 6}, ok. -predef_mac(doc) -> - []; -predef_mac(suite) -> - []; predef_mac(Config) when is_list(Config) -> - ?line File = filename:join(?config(data_dir, Config), "mac3.erl"), - ?line {ok, List} = epp:parse_file(File, [], []), - ?line [_, - {attribute, Anno, l, Line1}, - {attribute, _, f, File}, - {attribute, _, machine1, _}, - {attribute, _, module, mac3}, - {attribute, _, m, mac3}, - {attribute, _, ms, "mac3"}, - {attribute, _, machine2, _} - | _] = List, + File = filename:join(proplists:get_value(data_dir, Config), "mac3.erl"), + {ok, List} = epp:parse_file(File, [], []), + [_, + {attribute, Anno, l, Line1}, + {attribute, _, f, File}, + {attribute, _, machine1, _}, + {attribute, _, module, mac3}, + {attribute, _, m, mac3}, + {attribute, _, ms, "mac3"}, + {attribute, _, machine2, _} + | _] = List, Line1 = erl_anno:line(Anno), ok. -variable_1(doc) -> - []; -variable_1(suite) -> - []; variable_1(Config) when is_list(Config) -> - ?line DataDir = ?config(data_dir, Config), - ?line File = filename:join(DataDir, "variable_1.erl"), - ?line true = os:putenv("VAR", DataDir), + DataDir = proplists:get_value(data_dir, Config), + File = filename:join(DataDir, "variable_1.erl"), + true = os:putenv("VAR", DataDir), %% variable_1.erl includes variable_1_include.hrl and %% variable_1_include_dir.hrl. - ?line {ok, List} = epp:parse_file(File, [], []), - ?line {value, {attribute,_,a,{value1,value2}}} = + {ok, List} = epp:parse_file(File, [], []), + {value, {attribute,_,a,{value1,value2}}} = lists:keysearch(a,3,List), ok. -otp_4870(doc) -> - ["undef without module declaration"]; -otp_4870(suite) -> - []; +%% undef without module declaration. otp_4870(Config) when is_list(Config) -> Ts = [{otp_4870, <<"-undef(foo). ">>, []}], - ?line [] = check(Config, Ts), + [] = check(Config, Ts), ok. -otp_4871(doc) -> - ["crashing erl_scan"]; -otp_4871(suite) -> - []; +%% crashing erl_scan otp_4871(Config) when is_list(Config) -> - ?line Dir = ?config(priv_dir, Config), - ?line File = filename:join(Dir, "otp_4871.erl"), - ?line ok = file:write_file(File, "-module(otp_4871)."), + Dir = proplists:get_value(priv_dir, Config), + File = filename:join(Dir, "otp_4871.erl"), + ok = file:write_file(File, "-module(otp_4871)."), %% Testing crash in erl_scan. Unfortunately there currently is %% no known way to crash erl_scan so it is emulated by killing the %% file io server. This assumes lots of things about how %% the processes are started and how monitors are set up, %% so there are some sanity checks before killing. - ?line {ok,Epp} = epp:open(File, []), + {ok,Epp} = epp:open(File, []), timer:sleep(1), - ?line true = current_module(Epp, epp), - ?line {monitored_by,[Io]} = process_info(Epp, monitored_by), - ?line true = current_module(Io, file_io_server), - ?line exit(Io, emulate_crash), + true = current_module(Epp, epp), + {monitored_by,[Io]} = process_info(Epp, monitored_by), + true = current_module(Io, file_io_server), + exit(Io, emulate_crash), timer:sleep(1), - ?line {error,{_Line,epp,cannot_parse}} = otp_4871_parse_file(Epp), - ?line epp:close(Epp), + {error,{_Line,epp,cannot_parse}} = otp_4871_parse_file(Epp), + epp:close(Epp), ok. current_module(Pid, Mod) -> @@ -288,12 +256,9 @@ otp_4871_parse_file(Epp) -> Other -> Other end. -otp_5362(doc) -> - ["OTP-5362. The -file attribute is recognized."]; -otp_5362(suite) -> - []; +%% OTP-5362. The -file attribute is recognized. otp_5362(Config) when is_list(Config) -> - Dir = ?config(priv_dir, Config), + Dir = proplists:get_value(priv_dir, Config), Copts = [return, strong_validation,{i,Dir}], @@ -317,12 +282,12 @@ otp_5362(Config) when is_list(Config) -> Incl3 = <<"glurk(Foo) -> % line 1 bar. ">>, - ?line ok = file:write_file(File_Incl, Incl), - ?line ok = file:write_file(File_Incl2, Incl2), - ?line ok = file:write_file(File_Incl3, Incl3), + ok = file:write_file(File_Incl, Incl), + ok = file:write_file(File_Incl2, Incl2), + ok = file:write_file(File_Incl3, Incl3), - ?line {ok, incl_5362, InclWarnings} = compile:file(File_Incl, Copts), - ?line true = message_compare( + {ok, incl_5362, InclWarnings} = compile:file(File_Incl, Copts), + true = message_compare( [{File_Incl3,[{{1,1},erl_lint,{unused_function,{glurk,1}}}, {{1,7},erl_lint,{unused_var,'Foo'}}]}, {File_Incl,[{{7,15},erl_lint,{unused_function,{hi,1}}}, @@ -352,11 +317,11 @@ otp_5362(Config) when is_list(Config) -> -file(\"">>,File_Back,<<"\", 2). ">>], - ?line ok = file:write_file(File_Back, Back), - ?line ok = file:write_file(File_Back_hrl, list_to_binary(Back_hrl)), + ok = file:write_file(File_Back, Back), + ok = file:write_file(File_Back_hrl, list_to_binary(Back_hrl)), - ?line {ok, back_5362, BackWarnings} = compile:file(File_Back, Copts), - ?line true = message_compare( + {ok, back_5362, BackWarnings} = compile:file(File_Back, Copts), + true = message_compare( [{File_Back,[{{4,19},erl_lint,{unused_var,'V'}}]}], BackWarnings), file:delete(File_Back), @@ -380,11 +345,11 @@ otp_5362(Config) when is_list(Config) -> foo. ">>], - ?line ok = file:write_file(File_Change, list_to_binary(Change)), + ok = file:write_file(File_Change, list_to_binary(Change)), - ?line {ok, change_5362, ChangeWarnings} = + {ok, change_5362, ChangeWarnings} = compile:file(File_Change, Copts), - ?line true = message_compare( + true = message_compare( [{File_Change,[{{1002,21},erl_lint,{unused_var,'B'}}]}, {"other.file",[{{105,21},erl_lint,{unused_var,'A'}}]}], lists:usort(ChangeWarnings)), @@ -412,9 +377,9 @@ otp_5362(Config) when is_list(Config) -> -file(?FILE, ?LINE). c(C) -> % line 47 3. ">>, - ?line ok = file:write_file(File_Blank, Blank), - ?line {ok, blank_5362, BlankWarnings} = compile:file(File_Blank, Copts), - ?line true = message_compare( + ok = file:write_file(File_Blank, Blank), + {ok, blank_5362, BlankWarnings} = compile:file(File_Blank, Copts), + true = message_compare( [{File_Blank,[{{18,3},erl_lint,{unused_var,'Q'}}, {{20,18},erl_lint,{unused_var,'A'}}, {{44,18},erl_lint,{unused_var,'B'}}, @@ -438,16 +403,16 @@ otp_5362(Config) when is_list(Config) -> FILE1 = <<"ii() -> ?FILE. ">>, FILE_Mod = file_5362, - ?line ok = file:write_file(FILE_incl, FILE), - ?line ok = file:write_file(FILE_incl1, FILE1), + ok = file:write_file(FILE_incl, FILE), + ok = file:write_file(FILE_incl1, FILE1), FILE_Copts = [return, {i,Dir},{outdir,Dir}], - ?line {ok, file_5362, []} = compile:file(FILE_incl, FILE_Copts), + {ok, file_5362, []} = compile:file(FILE_incl, FILE_Copts), AbsFile = filename:rootname(FILE_incl, ".erl"), - ?line {module, FILE_Mod} = code:load_abs(AbsFile, FILE_Mod), - ?line II = FILE_Mod:ii(), - ?line "file_incl_5362.erl" = filename:basename(II), - ?line FF = FILE_Mod:ff(), - ?line "other_file" = filename:basename(FF), + {module, FILE_Mod} = code:load_abs(AbsFile, FILE_Mod), + II = FILE_Mod:ii(), + "file_incl_5362.erl" = filename:basename(II), + FF = FILE_Mod:ff(), + "other_file" = filename:basename(FF), code:purge(file_5362), file:delete(FILE_incl), @@ -456,12 +421,12 @@ otp_5362(Config) when is_list(Config) -> ok. pmod(Config) when is_list(Config) -> - ?line DataDir = ?config(data_dir, Config), - ?line Pmod = filename:join(DataDir, "pmod.erl"), - ?line case epp:parse_file([Pmod], [], []) of + DataDir = proplists:get_value(data_dir, Config), + Pmod = filename:join(DataDir, "pmod.erl"), + case epp:parse_file([Pmod], [], []) of {ok,Forms} -> - %% ?line io:format("~p\n", [Forms]), - ?line [] = [F || {error,_}=F <- Forms], + %% io:format("~p\n", [Forms]), + [] = [F || {error,_}=F <- Forms], ok end, ok. @@ -474,17 +439,14 @@ not_circular(Config) when is_list(Config) -> <<"-define(S(S), ??S).\n" "t() -> \"string\" = ?S(string), ok.\n">>, ok}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -skip_header(doc) -> - ["Skip some bytes in the beginning of the file."]; -skip_header(suite) -> - []; +%% Skip some bytes in the beginning of the file. skip_header(Config) when is_list(Config) -> - ?line PrivDir = ?config(priv_dir, Config), - ?line File = filename:join([PrivDir, "epp_test_skip_header.erl"]), - ?line ok = file:write_file(File, + PrivDir = proplists:get_value(priv_dir, Config), + File = filename:join([PrivDir, "epp_test_skip_header.erl"]), + ok = file:write_file(File, <<"some bytes in the beginning of the file that should be skipped @@ -494,23 +456,20 @@ skip_header(Config) when is_list(Config) -> main(_) -> ?MODULE. ">>), - ?line {ok, Fd} = file:open(File, [read]), - ?line io:get_line(Fd, ''), - ?line io:get_line(Fd, ''), - ?line io:get_line(Fd, ''), - ?line {ok, Epp} = epp:open(list_to_atom(File), Fd, 4, [], []), - - ?line Forms = epp:parse_file(Epp), - ?line [] = [Reason || {error, Reason} <- Forms], - ?line ok = epp:close(Epp), - ?line ok = file:close(Fd), + {ok, Fd} = file:open(File, [read]), + io:get_line(Fd, ''), + io:get_line(Fd, ''), + io:get_line(Fd, ''), + {ok, Epp} = epp:open(list_to_atom(File), Fd, 4, [], []), + + Forms = epp:parse_file(Epp), + [] = [Reason || {error, Reason} <- Forms], + ok = epp:close(Epp), + ok = file:close(Fd), ok. -otp_6277(doc) -> - ["?MODULE before module declaration."]; -otp_6277(suite) -> - []; +%% ?MODULE before module declaration. otp_6277(Config) when is_list(Config) -> Ts = [{otp_6277, <<"-undef(ASSERT). @@ -518,15 +477,12 @@ otp_6277(Config) when is_list(Config) -> ?ASSERT().">>, [{error,{{4,16},epp,{undefined,'MODULE', none}}}]}], - ?line [] = check(Config, Ts), + [] = check(Config, Ts), ok. -otp_7702(doc) -> - ["OTP-7702. Wrong line number in stringifying macro expansion."]; -otp_7702(suite) -> - []; +%% OTP-7702. Wrong line number in stringifying macro expansion. otp_7702(Config) when is_list(Config) -> - Dir = ?config(priv_dir, Config), + Dir = proplists:get_value(priv_dir, Config), File = filename:join(Dir, "file_7702.erl"), Contents = <<"-module(file_7702). @@ -542,8 +498,8 @@ otp_7702(Config) when is_list(Config) -> end). t() -> ?RECEIVE(foo, bar).">>, - ?line ok = file:write_file(File, Contents), - ?line {ok, file_7702, []} = + ok = file:write_file(File, Contents), + {ok, file_7702, []} = compile:file(File, [debug_info,return,{outdir,Dir}]), BeamFile = filename:join(Dir, "file_7702.beam"), @@ -551,8 +507,7 @@ otp_7702(Config) when is_list(Config) -> {file_7702,[{abstract_code,{_,Forms}}]} = AC, Forms2 = unopaque_forms(Forms), - ?line - [{attribute,1,file,_}, + [{attribute,1,file,_}, _, _, {function,_,t,0, @@ -586,10 +541,7 @@ otp_7702(Config) when is_list(Config) -> ok. -otp_8130(doc) -> - ["OTP-8130. Misc tests."]; -otp_8130(suite) -> - []; +%% OTP-8130. Misc tests. otp_8130(Config) when is_list(Config) -> true = os:putenv("epp_inc1", "stdlib"), Ts = [{otp_8130_1, @@ -689,7 +641,7 @@ otp_8130(Config) when is_list(Config) -> {1,1}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), Cs = [{otp_8130_c1, <<"-define(M1(A), if\n" @@ -823,7 +775,7 @@ otp_8130(Config) when is_list(Config) -> {{3,19},epp,{undefined,'A',none}}],[]}} ], - ?line [] = compile(Config, Cs), + [] = compile(Config, Cs), Cks = [{otp_check_1, <<"\n-include_lib(\"epp_test.erl\").\n">>, @@ -833,25 +785,25 @@ otp_8130(Config) when is_list(Config) -> <<"\n-include(\"epp_test.erl\").\n">>, [{error,{{2,2},epp,{depth,"include"}}}]} ], - ?line [] = check(Config, Cks), + [] = check(Config, Cks), - ?line Dir = ?config(priv_dir, Config), - ?line File = filename:join(Dir, "otp_8130.erl"), - ?line ok = file:write_file(File, + Dir = proplists:get_value(priv_dir, Config), + File = filename:join(Dir, "otp_8130.erl"), + ok = file:write_file(File, "-module(otp_8130).\n" "-define(a, 3.14).\n" "t() -> ?a.\n"), - ?line {ok,Epp} = epp:open(File, []), + {ok,Epp} = epp:open(File, []), PreDefMacs = macs(Epp), ['BASE_MODULE','BASE_MODULE_STRING','BEAM','FILE', 'FUNCTION_ARITY','FUNCTION_NAME', 'LINE','MACHINE','MODULE','MODULE_STRING'] = PreDefMacs, - ?line {ok,[{'-',_},{atom,_,file}|_]} = epp:scan_erl_form(Epp), - ?line {ok,[{'-',_},{atom,_,module}|_]} = epp:scan_erl_form(Epp), - ?line {ok,[{atom,_,t}|_]} = epp:scan_erl_form(Epp), - ?line {eof,_} = epp:scan_erl_form(Epp), + {ok,[{'-',_},{atom,_,file}|_]} = epp:scan_erl_form(Epp), + {ok,[{'-',_},{atom,_,module}|_]} = epp:scan_erl_form(Epp), + {ok,[{atom,_,t}|_]} = epp:scan_erl_form(Epp), + {eof,_} = epp:scan_erl_form(Epp), [a] = macs(Epp) -- PreDefMacs, - ?line epp:close(Epp), + epp:close(Epp), %% escript ModuleStr = "any_name", @@ -860,27 +812,27 @@ otp_8130(Config) when is_list(Config) -> PreDefMacros = [{'MODULE', Module, redefine}, {'MODULE_STRING', ModuleStr, redefine}, a, {b,2}], - ?line {ok,Epp2} = epp:open(File, [], PreDefMacros), - ?line [{atom,_,true}] = macro(Epp2, a), - ?line [{integer,_,2}] = macro(Epp2, b), - ?line false = macro(Epp2, c), - ?line epp:close(Epp2) + {ok,Epp2} = epp:open(File, [], PreDefMacros), + [{atom,_,true}] = macro(Epp2, a), + [{integer,_,2}] = macro(Epp2, b), + false = macro(Epp2, c), + epp:close(Epp2) end(), fun() -> PreDefMacros = [{a,b,c}], - ?line {error,{bad,{a,b,c}}} = epp:open(File, [], PreDefMacros) + {error,{bad,{a,b,c}}} = epp:open(File, [], PreDefMacros) end(), fun() -> PreDefMacros = [a, {a,1}], - ?line {error,{redefine,a}} = epp:open(File, [], PreDefMacros) + {error,{redefine,a}} = epp:open(File, [], PreDefMacros) end(), fun() -> PreDefMacros = [{a,1},a], - ?line {error,{redefine,a}} = epp:open(File, [], PreDefMacros) + {error,{redefine,a}} = epp:open(File, [], PreDefMacros) end(), - ?line {error,enoent} = epp:open("no such file", []), - ?line {error,enoent} = epp:parse_file("no such file", [], []), + {error,enoent} = epp:open("no such file", []), + {error,enoent} = epp:parse_file("no such file", [], []), _ = ifdef(Config), @@ -1020,7 +972,7 @@ ifdef(Config) -> "t() -> a.\n">>, {errors,[{{2,2},epp,{'NYI','if'}}],[]}} ], - ?line [] = compile(Config, Cs), + [] = compile(Config, Cs), Ts = [{ifdef_1, <<"-ifdef(a).\n" @@ -1101,14 +1053,11 @@ ifdef(Config) -> ok} ], - ?line [] = run(Config, Ts). + [] = run(Config, Ts). -overload_mac(doc) -> - ["Advanced test on overloading macros."]; -overload_mac(suite) -> - []; +%% Advanced test on overloading macros. overload_mac(Config) when is_list(Config) -> Cs = [ %% '-undef' removes all definitions of a macro @@ -1139,7 +1088,7 @@ overload_mac(Config) when is_list(Config) -> "t() -> ?A(1).">>, {errors,[{{4,9},epp,{mismatch,'A'}}],[]}} ], - ?line [] = compile(Config, Cs), + [] = compile(Config, Cs), Ts = [ {overload_mac_r1, @@ -1163,27 +1112,24 @@ overload_mac(Config) when is_list(Config) -> "t() -> ?A(1).">>, 1} ], - ?line [] = run(Config, Ts). + [] = run(Config, Ts). -otp_8388(doc) -> - ["OTP-8388. More tests on overloaded macros."]; -otp_8388(suite) -> - []; +%% OTP-8388. More tests on overloaded macros. otp_8388(Config) when is_list(Config) -> - Dir = ?config(priv_dir, Config), - ?line File = filename:join(Dir, "otp_8388.erl"), - ?line ok = file:write_file(File, <<"-module(otp_8388)." + Dir = proplists:get_value(priv_dir, Config), + File = filename:join(Dir, "otp_8388.erl"), + ok = file:write_file(File, <<"-module(otp_8388)." "-define(LINE, a).">>), fun() -> PreDefMacros = [{'LINE', a}], - ?line {error,{redefine_predef,'LINE'}} = + {error,{redefine_predef,'LINE'}} = epp:open(File, [], PreDefMacros) end(), fun() -> PreDefMacros = ['LINE'], - ?line {error,{redefine_predef,'LINE'}} = + {error,{redefine_predef,'LINE'}} = epp:open(File, [], PreDefMacros) end(), @@ -1213,28 +1159,22 @@ otp_8388(Config) when is_list(Config) -> "test() -> ?BAR(1).\n">>, {errors,[{{4,12},epp,{undefined,'FOO',1}}],[]}} ], - ?line [] = compile(Config, Ts), + [] = compile(Config, Ts), ok. -otp_8470(doc) -> - ["OTP-8470. Bugfix (one request - two replies)."]; -otp_8470(suite) -> - []; +%% OTP-8470. Bugfix (one request - two replies). otp_8470(Config) when is_list(Config) -> - Dir = ?config(priv_dir, Config), + Dir = proplists:get_value(priv_dir, Config), C = <<"-file(\"erl_parse.yrl\", 486).\n" "-file(\"erl_parse.yrl\", 488).\n">>, - ?line File = filename:join(Dir, "otp_8470.erl"), - ?line ok = file:write_file(File, C), - ?line {ok, _List} = epp:parse_file(File, [], []), + File = filename:join(Dir, "otp_8470.erl"), + ok = file:write_file(File, C), + {ok, _List} = epp:parse_file(File, [], []), file:delete(File), - ?line receive _ -> fail() after 0 -> ok end, + receive _ -> fail() after 0 -> ok end, ok. -otp_8562(doc) -> - ["OTP-8562. Record with no fields is considered typed."]; -otp_8562(suite) -> - []; +%% OTP-8562. Record with no fields is considered typed. otp_8562(Config) when is_list(Config) -> Cs = [{otp_8562, <<"-define(P(), {a,b}.\n" @@ -1242,13 +1182,10 @@ otp_8562(Config) when is_list(Config) -> {errors,[{{1,60},epp,missing_parenthesis}, {{2,13},epp,missing_parenthesis}], []}} ], - ?line [] = compile(Config, Cs), + [] = compile(Config, Cs), ok. -otp_8911(doc) -> - ["OTP-8911. -file and file inclusion bug"]; -otp_8911(suite) -> - []; +%% OTP-8911. -file and file inclusion bug. otp_8911(Config) when is_list(Config) -> case test_server:is_cover() of true -> @@ -1257,8 +1194,8 @@ otp_8911(Config) when is_list(Config) -> do_otp_8911(Config) end. do_otp_8911(Config) -> - ?line {ok, CWD} = file:get_cwd(), - ?line ok = file:set_cwd(?config(priv_dir, Config)), + {ok, CWD} = file:get_cwd(), + ok = file:set_cwd(proplists:get_value(priv_dir, Config)), File = "i.erl", Cont = <<"-module(i). @@ -1268,40 +1205,34 @@ do_otp_8911(Config) -> t() -> a. ">>, - ?line ok = file:write_file(File, Cont), + ok = file:write_file(File, Cont), Incl = <<"-file(\"fil2\", 35). t1() -> b. ">>, File1 = "i1.erl", - ?line ok = file:write_file(File1, Incl), + ok = file:write_file(File1, Incl), - ?line {ok, i} = cover:compile(File), - ?line a = i:t(), - ?line {ok,[{{i,6},1}]} = cover:analyse(i, calls, line), - ?line cover:stop(), + {ok, i} = cover:compile(File), + a = i:t(), + {ok,[{{i,6},1}]} = cover:analyse(i, calls, line), + cover:stop(), file:delete(File), file:delete(File1), - ?line file:set_cwd(CWD), + file:set_cwd(CWD), ok. -otp_8665(doc) -> - ["OTP-8665. Bugfix premature end."]; -otp_8665(suite) -> - []; +%% OTP-8665. Bugfix premature end. otp_8665(Config) when is_list(Config) -> Cs = [{otp_8562, <<"-define(A, a)\n">>, {errors,[{{1,54},epp,premature_end}],[]}} ], - ?line [] = compile(Config, Cs), + [] = compile(Config, Cs), ok. -otp_10302(doc) -> - "OTP-10302. Unicode characters scanner/parser."; -otp_10302(suite) -> - []; +%% OTP-10302. Unicode characters scanner/parser. otp_10302(Config) when is_list(Config) -> %% Two messages (one too many). Keeps otp_4871 happy. Cs = [{otp_8562, @@ -1310,7 +1241,7 @@ otp_10302(Config) when is_list(Config) -> {3,file_io_server,invalid_unicode}],[]}} ], [] = compile(Config, Cs), - Dir = ?config(priv_dir, Config), + Dir = proplists:get_value(priv_dir, Config), File = filename:join(Dir, "otp_10302.erl"), utf8 = encoding("coding: utf-8", File), utf8 = encoding("coding: UTF-8", File), @@ -1372,13 +1303,10 @@ encoding_nocom(Enc, File) -> ok = file:close(Fd), E = epp:read_encoding(File, Options). -otp_10820(doc) -> - "OTP-10820. Unicode filenames."; -otp_10820(suite) -> - []; +%% OTP-10820. Unicode filenames. otp_10820(Config) when is_list(Config) -> L = [915,953,959,973,957,953,954,959,957,964], - Dir = ?config(priv_dir, Config), + Dir = proplists:get_value(priv_dir, Config), File = filename:join(Dir, L++".erl"), C1 = <<"%% coding: utf-8\n -module(any).">>, ok = do_otp_10820(File, C1, "+pc latin1"), @@ -1397,12 +1325,9 @@ do_otp_10820(File, C, PC) -> true = test_server:stop_node(Node), ok. -otp_11728(doc) -> - ["OTP-11728. Bugfix circular macro."]; -otp_11728(suite) -> - []; +%% OTP-11728. Bugfix circular macro. otp_11728(Config) when is_list(Config) -> - Dir = ?config(priv_dir, Config), + Dir = proplists:get_value(priv_dir, Config), H = <<"-define(MACRO,[[]++?MACRO]).">>, HrlFile = filename:join(Dir, "otp_11728.hrl"), ok = file:write_file(HrlFile, H), @@ -1424,7 +1349,7 @@ otp_11728(Config) when is_list(Config) -> %% Check the new API for setting the default encoding. encoding(Config) when is_list(Config) -> - Dir = ?config(priv_dir, Config), + Dir = proplists:get_value(priv_dir, Config), ErlFile = filename:join(Dir, "encoding.erl"), %% Try a latin-1 file with no encoding given. @@ -1592,7 +1517,7 @@ eval_tests(Config, Fun, Tests) -> true -> BadL; false -> - ?t:format("~nTest ~p failed. Expected~n ~p~n" + io:format("~nTest ~p failed. Expected~n ~p~n" "but got~n ~p~n", [N, E, Return]), fail() end @@ -1602,7 +1527,7 @@ eval_tests(Config, Fun, Tests) -> check_test(Config, Test) -> Filename = "epp_test.erl", - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), File = filename:join(PrivDir, Filename), ok = file:write_file(File, Test), case epp:parse_file(File, [PrivDir], []) of @@ -1617,9 +1542,9 @@ check_test(Config, Test) -> compile_test(Config, Test0) -> Test = [<<"-module(epp_test). -compile(export_all). ">>, Test0], Filename = "epp_test.erl", - ?line PrivDir = ?config(priv_dir, Config), - ?line File = filename:join(PrivDir, Filename), - ?line ok = file:write_file(File, Test), + PrivDir = proplists:get_value(priv_dir, Config), + File = filename:join(PrivDir, Filename), + ok = file:write_file(File, Test), Opts = [export_all,return,nowarn_unused_record,{outdir,PrivDir}], case compile_file(File, Opts) of {ok, Ws} -> warnings(File, Ws); @@ -1671,20 +1596,19 @@ unopaque_forms(Forms) -> run_test(Config, Test0) -> Test = [<<"-module(epp_test). -compile(export_all). ">>, Test0], Filename = "epp_test.erl", - ?line PrivDir = ?config(priv_dir, Config), - ?line File = filename:join(PrivDir, Filename), - ?line ok = file:write_file(File, Test), + PrivDir = proplists:get_value(priv_dir, Config), + File = filename:join(PrivDir, Filename), + ok = file:write_file(File, Test), Opts = [return, {i,PrivDir},{outdir,PrivDir}], - ?line {ok, epp_test, []} = compile:file(File, Opts), + {ok, epp_test, []} = compile:file(File, Opts), AbsFile = filename:rootname(File, ".erl"), - ?line {module, epp_test} = code:load_abs(AbsFile, epp_test), - ?line Reply = epp_test:t(), + {module, epp_test} = code:load_abs(AbsFile, epp_test), + Reply = epp_test:t(), code:purge(epp_test), Reply. fail() -> - io:format("failed~n"), - test_server:fail(). + ct:fail(failed). message_compare(T, T) -> true; @@ -1718,5 +1642,5 @@ ln2(M) -> %% +fnu means a peer node has to be started; slave will not do start_node(Name, Xargs) -> - ?line PA = filename:dirname(code:which(?MODULE)), + PA = filename:dirname(code:which(?MODULE)), test_server:start_node(Name, peer, [{args, "-pa " ++ PA ++ " " ++ Xargs}]). diff --git a/lib/stdlib/test/erl_anno_SUITE.erl b/lib/stdlib/test/erl_anno_SUITE.erl index 79b27c6217..637a390c70 100644 --- a/lib/stdlib/test/erl_anno_SUITE.erl +++ b/lib/stdlib/test/erl_anno_SUITE.erl @@ -19,7 +19,7 @@ %% -module(erl_anno_SUITE). -%-define(debug, true). +%%-define(debug, true). -ifdef(debug). -include_lib("common_test/include/ct.hrl"). @@ -46,7 +46,9 @@ groups() -> line, location, record, text, bad]}, {parse, [], [parse_abstract, mapfold_anno]}]. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. init_per_suite(Config) -> Config. @@ -61,26 +63,21 @@ end_per_group(_GroupName, Config) -> Config. init_per_testcase(_Case, Config) -> - Dog=?t:timetrap(?t:minutes(1)), - [{watchdog, Dog}|Config]. + Config. end_per_testcase(_Case, _Config) -> - Dog=?config(watchdog, _Config), - test_server:timetrap_cancel(Dog), ok. -define(INFO(T, V), {T, V}). -dialyzer({no_fail_call, new/1}). -new(doc) -> - ["Test erl_anno:new/1"]; +%% Test erl_anno:new/1. new(_Config) -> {'EXIT', {badarg, _}} = (catch erl_anno:new([{location,1},{text, "text"}])), % badarg ok. -is_anno(doc) -> - ["Test erl_anno:is_anno/1"]; +%% Test erl_anno:is_anno/1. is_anno(_Config) -> false = erl_anno:is_anno(a), false = erl_anno:is_anno({a}), @@ -106,8 +103,7 @@ is_anno(_Config) -> true = erl_anno:is_anno(A5), ok. -generated(doc) -> - ["Test 'generated'"]; +%% Test 'generated'. generated(_Config) -> test(1, [{generated, true}, {generated, false}]), test(1, [{generated, false}, {generated, true}, {generated, false}]), @@ -127,8 +123,7 @@ generated(_Config) -> {generated, false}]), ok. -end_location(doc) -> - ["Test 'end_location'"]; +%% Test 'end_location'. end_location(_Config) -> test({1, 17}, [{text, "TEXT", [{end_location, {1, 21}}, {length, 4}]}, {text, "TEXT\n", [{end_location, {2, 1}}, {length, 5}]}, @@ -138,23 +133,20 @@ end_location(_Config) -> {text, "TEXT\ntxt", [{end_location, 2}, {length, 8}]}]), ok. -file(doc) -> - ["Test 'file'"]; +%% Test 'file'. file(_Config) -> test(1, [{file, "name"}, {file, ""}]), test({1, 17}, [{file, "name"}, {file, ""}]), ok. -line(doc) -> - ["Test 'line'"]; +%% Test 'line'. line(_Config) -> test(1, [{line, 17, [{location, 17}]}, {location, {9, 8}, [{line, 9}, {column, 8}]}, {line, 14, [{location, {14, 8}}]}]), ok. -location(doc) -> - ["Test 'location'"]; +%% Test 'location'. location(_Config) -> test(1, [{location, 2, [{line,2}]}, {location, {1, 17}, [{line, 1}, {column, 17}]}, @@ -172,8 +164,7 @@ location(_Config) -> {location, 9, [{column, undefined}]}]), ok. -record(doc) -> - ["Test 'record'"]; +%% Test 'record'. record(_Config) -> test({1, 17}, [{record, true}, {record, false}]), test(1, [{record, true}, {record, false}]), @@ -193,8 +184,7 @@ record(_Config) -> {generated, false}]), ok. -text(doc) -> - ["Test 'text'"]; +%% Test 'text'. text(_Config) -> test(1, [{text, "text", [{end_location, 1}, {length, 4}]}, {text, "", [{end_location, 1}, {length, 0}]}]), @@ -203,8 +193,7 @@ text(_Config) -> ok. -dialyzer({[no_opaque, no_fail_call], bad/1}). -bad(doc) -> - ["Test bad annotations"]; +%% Test bad annotations. bad(_Config) -> Line = erl_anno:new(1), LineColumn = erl_anno:new({1, 17}), @@ -229,9 +218,8 @@ bad(_Config) -> (catch erl_anno:record(bad)), % 1st arg not opaque ok. -parse_abstract(doc) -> - ["Test erl_parse:new_anno/1, erl_parse:anno_to_term/1" - ", and erl_parse:anno_from_term/1"]; +%% Test erl_parse:new_anno/1, erl_parse:anno_to_term/1, +%% and erl_parse:anno_from_term/1. parse_abstract(_Config) -> T = sample_term(), A = erl_parse:abstract(T, [{line,17}]), @@ -242,8 +230,7 @@ parse_abstract(_Config) -> T = erl_parse:normalise(Abstr2), ok. -mapfold_anno(doc) -> - ["Test erl_parse:{map_anno/2,fold_anno/3, and mapfold_anno/3}"]; +%% Test erl_parse:{map_anno/2,fold_anno/3, and mapfold_anno/3}. mapfold_anno(_Config) -> T = sample_term(), Abstr = erl_parse:abstract(T), diff --git a/lib/stdlib/test/erl_eval_SUITE.erl b/lib/stdlib/test/erl_eval_SUITE.erl index 1874ee1a1d..c3ef4eb051 100644 --- a/lib/stdlib/test/erl_eval_SUITE.erl +++ b/lib/stdlib/test/erl_eval_SUITE.erl @@ -19,6 +19,7 @@ -module(erl_eval_SUITE). -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, + init_per_testcase/2, end_per_testcase/2, init_per_group/2,end_per_group/2]). -export([guard_1/1, guard_2/1, @@ -65,19 +66,17 @@ config(priv_dir,_) -> ".". -else. -include_lib("common_test/include/ct.hrl"). --export([init_per_testcase/2, end_per_testcase/2]). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(1)). +-endif. + init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), + Config. + +end_per_testcase(_Case, _Config) -> ok. --endif. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [guard_1, guard_2, match_pattern, string_plusplus, @@ -103,125 +102,101 @@ init_per_group(_GroupName, Config) -> end_per_group(_GroupName, Config) -> Config. -guard_1(doc) -> - ["(OTP-2405)"]; -guard_1(suite) -> - []; +%% OTP-2405 guard_1(Config) when is_list(Config) -> - ?line {ok,Tokens ,_} = + {ok,Tokens ,_} = erl_scan:string("if a+4 == 4 -> yes; true -> no end. "), - ?line {ok, [Expr]} = erl_parse:parse_exprs(Tokens), - ?line no = guard_1_compiled(), - ?line {value, no, []} = erl_eval:expr(Expr, []), + {ok, [Expr]} = erl_parse:parse_exprs(Tokens), + no = guard_1_compiled(), + {value, no, []} = erl_eval:expr(Expr, []), ok. guard_1_compiled() -> if a+4 == 4 -> yes; true -> no end. -guard_2(doc) -> - ["Similar to guard_1, but type-correct"]; -guard_2(suite) -> - []; +%% Similar to guard_1, but type-correct. guard_2(Config) when is_list(Config) -> - ?line {ok,Tokens ,_} = + {ok,Tokens ,_} = erl_scan:string("if 6+4 == 4 -> yes; true -> no end. "), - ?line {ok, [Expr]} = erl_parse:parse_exprs(Tokens), - ?line no = guard_2_compiled(), - ?line {value, no, []} = erl_eval:expr(Expr, []), + {ok, [Expr]} = erl_parse:parse_exprs(Tokens), + no = guard_2_compiled(), + {value, no, []} = erl_eval:expr(Expr, []), ok. guard_2_compiled() -> if 6+4 == 4 -> yes; true -> no end. -string_plusplus(doc) -> - ["OTP-3069: syntactic sugar string ++ ..."]; -string_plusplus(suite) -> - []; +%% OTP-3069: syntactic sugar string ++ ... string_plusplus(Config) when is_list(Config) -> - ?line check(fun() -> case "abc" of "ab" ++ L -> L end end, - "case \"abc\" of \"ab\" ++ L -> L end. ", - "c"), - ?line check(fun() -> case "abcde" of "ab" ++ "cd" ++ L -> L end end, - "case \"abcde\" of \"ab\" ++ \"cd\" ++ L -> L end. ", - "e"), - ?line check(fun() -> case "abc" of [97, 98] ++ L -> L end end, - "case \"abc\" of [97, 98] ++ L -> L end. ", - "c"), + check(fun() -> case "abc" of "ab" ++ L -> L end end, + "case \"abc\" of \"ab\" ++ L -> L end. ", + "c"), + check(fun() -> case "abcde" of "ab" ++ "cd" ++ L -> L end end, + "case \"abcde\" of \"ab\" ++ \"cd\" ++ L -> L end. ", + "e"), + check(fun() -> case "abc" of [97, 98] ++ L -> L end end, + "case \"abc\" of [97, 98] ++ L -> L end. ", + "c"), ok. -match_pattern(doc) -> - ["OTP-2983: match operator in pattern"]; -match_pattern(suite) -> - []; +%% OTP-2983: match operator in pattern. match_pattern(Config) when is_list(Config) -> - ?line check(fun() -> case {a, b} of {a, _X}=Y -> {x,Y} end end, - "case {a, b} of {a, X}=Y -> {x,Y} end. ", - {x, {a, b}}), - ?line check(fun() -> case {a, b} of Y={a, _X} -> {x,Y} end end, - "case {a, b} of Y={a, X} -> {x,Y} end. ", - {x, {a, b}}), - ?line check(fun() -> case {a, b} of Y={a, _X}=Z -> {Z,Y} end end, - "case {a, b} of Y={a, X}=Z -> {Z,Y} end. ", - {{a, b}, {a, b}}), - ?line check(fun() -> A = 4, B = 28, <<13:(A+(X=B))>>, X end, - "begin A = 4, B = 28, <<13:(A+(X=B))>>, X end.", - 28), + check(fun() -> case {a, b} of {a, _X}=Y -> {x,Y} end end, + "case {a, b} of {a, X}=Y -> {x,Y} end. ", + {x, {a, b}}), + check(fun() -> case {a, b} of Y={a, _X} -> {x,Y} end end, + "case {a, b} of Y={a, X} -> {x,Y} end. ", + {x, {a, b}}), + check(fun() -> case {a, b} of Y={a, _X}=Z -> {Z,Y} end end, + "case {a, b} of Y={a, X}=Z -> {Z,Y} end. ", + {{a, b}, {a, b}}), + check(fun() -> A = 4, B = 28, <<13:(A+(X=B))>>, X end, + "begin A = 4, B = 28, <<13:(A+(X=B))>>, X end.", + 28), ok. -match_bin(doc) -> - ["binary match problems"]; -match_bin(suite) -> - []; +%% Binary match problems. match_bin(Config) when is_list(Config) -> - ?line check(fun() -> <<"abc">> = <<"abc">> end, - "<<\"abc\">> = <<\"abc\">>. ", - <<"abc">>), - ?line check(fun() -> - <<Size,B:Size/binary,Rest/binary>> = <<2,"AB","CD">>, - {Size,B,Rest} - end, - "begin <<Size,B:Size/binary,Rest/binary>> = <<2,\"AB\",\"CD\">>, " - "{Size,B,Rest} end. ", - {2,<<"AB">>,<<"CD">>}), + check(fun() -> <<"abc">> = <<"abc">> end, + "<<\"abc\">> = <<\"abc\">>. ", + <<"abc">>), + check(fun() -> + <<Size,B:Size/binary,Rest/binary>> = <<2,"AB","CD">>, + {Size,B,Rest} + end, + "begin <<Size,B:Size/binary,Rest/binary>> = <<2,\"AB\",\"CD\">>, " + "{Size,B,Rest} end. ", + {2,<<"AB">>,<<"CD">>}), ok. -pattern_expr(doc) -> - ["OTP-3144: compile-time expressions in pattern"]; -pattern_expr(suite) -> - []; +%% OTP-3144: compile-time expressions in pattern. pattern_expr(Config) when is_list(Config) -> - ?line check(fun() -> case 4 of 2+2 -> ok end end, - "case 4 of 2+2 -> ok end. ", - ok), - ?line check(fun() -> case 2 of +2 -> ok end end, - "case 2 of +2 -> ok end. ", - ok), + check(fun() -> case 4 of 2+2 -> ok end end, + "case 4 of 2+2 -> ok end. ", + ok), + check(fun() -> case 2 of +2 -> ok end end, + "case 2 of +2 -> ok end. ", + ok), ok. -guard_3(doc) -> - ["OTP-4518."]; -guard_3(suite) -> - []; +%% OTP-4518. guard_3(Config) when is_list(Config) -> - ?line check(fun() -> if false -> false; true -> true end end, - "if false -> false; true -> true end.", - true), - ?line check(fun() -> if <<"hej">> == <<"hopp">> -> true; - true -> false end end, - "begin if <<\"hej\">> == <<\"hopp\">> -> true; + check(fun() -> if false -> false; true -> true end end, + "if false -> false; true -> true end.", + true), + check(fun() -> if <<"hej">> == <<"hopp">> -> true; + true -> false end end, + "begin if <<\"hej\">> == <<\"hopp\">> -> true; true -> false end end.", false), - ?line check(fun() -> if <<"hej">> == <<"hej">> -> true; - true -> false end end, - "begin if <<\"hej\">> == <<\"hej\">> -> true; + check(fun() -> if <<"hej">> == <<"hej">> -> true; + true -> false end end, + "begin if <<\"hej\">> == <<\"hej\">> -> true; true -> false end end.", true), ok. -guard_4(doc) -> - ["OTP-4885."]; -guard_4(suite) -> - []; +%% OTP-4885. guard_4(Config) when is_list(Config) -> check(fun() -> if erlang:'+'(3,a) -> true ; true -> false end end, "if erlang:'+'(3,a) -> true ; true -> false end.", @@ -230,31 +205,28 @@ guard_4(Config) when is_list(Config) -> end, "if erlang:is_integer(3) -> true ; true -> false end.", true), - ?line check(fun() -> [X || X <- [1,2,3], erlang:is_integer(X)] end, - "[X || X <- [1,2,3], erlang:is_integer(X)].", - [1,2,3]), - ?line check(fun() -> if is_atom(is_integer(a)) -> true ; true -> false end - end, - "if is_atom(is_integer(a)) -> true ; true -> false end.", - true), + check(fun() -> [X || X <- [1,2,3], erlang:is_integer(X)] end, + "[X || X <- [1,2,3], erlang:is_integer(X)].", + [1,2,3]), + check(fun() -> if is_atom(is_integer(a)) -> true ; true -> false end + end, + "if is_atom(is_integer(a)) -> true ; true -> false end.", + true), check(fun() -> if erlang:is_atom(erlang:is_integer(a)) -> true; true -> false end end, "if erlang:is_atom(erlang:is_integer(a)) -> true; " "true -> false end.", true), - ?line check(fun() -> if is_atom(3+a) -> true ; true -> false end end, - "if is_atom(3+a) -> true ; true -> false end.", - false), - ?line check(fun() -> if erlang:is_atom(3+a) -> true ; true -> false end - end, - "if erlang:is_atom(3+a) -> true ; true -> false end.", - false), + check(fun() -> if is_atom(3+a) -> true ; true -> false end end, + "if is_atom(3+a) -> true ; true -> false end.", + false), + check(fun() -> if erlang:is_atom(3+a) -> true ; true -> false end + end, + "if erlang:is_atom(3+a) -> true ; true -> false end.", + false), ok. -guard_5(doc) -> - ["Guards with erlang:'=='/2"]; -guard_5(suite) -> - []; +%% Guards with erlang:'=='/2. guard_5(Config) when is_list(Config) -> {ok,Tokens ,_} = erl_scan:string("case 1 of A when erlang:'=='(A, 1) -> true end."), @@ -266,293 +238,278 @@ guard_5(Config) when is_list(Config) -> guard_5_compiled() -> case 1 of A when erlang:'=='(A, 1) -> true end. -lc(doc) -> - ["OTP-4518."]; -lc(suite) -> - []; +%% OTP-4518. lc(Config) when is_list(Config) -> - ?line check(fun() -> X = 32, [X || X <- [1,2,3]] end, - "begin X = 32, [X || X <- [1,2,3]] end.", - [1,2,3]), - ?line check(fun() -> X = 32, - [X || <<X:X>> <- [<<1:32>>,<<2:32>>,<<3:8>>]] end, - %% "binsize variable" ^ - "begin X = 32, + check(fun() -> X = 32, [X || X <- [1,2,3]] end, + "begin X = 32, [X || X <- [1,2,3]] end.", + [1,2,3]), + check(fun() -> X = 32, + [X || <<X:X>> <- [<<1:32>>,<<2:32>>,<<3:8>>]] end, + %% "binsize variable" ^ + "begin X = 32, [X || <<X:X>> <- [<<1:32>>,<<2:32>>,<<3:8>>]] end.", [1,2]), - ?line check(fun() -> Y = 13,[X || {X,Y} <- [{1,2}]] end, - "begin Y = 13,[X || {X,Y} <- [{1,2}]] end.", - [1]), - ?line error_check("begin [A || X <- [{1,2}], 1 == A] end.", - {unbound_var,'A'}), - ?line error_check("begin X = 32, + check(fun() -> Y = 13,[X || {X,Y} <- [{1,2}]] end, + "begin Y = 13,[X || {X,Y} <- [{1,2}]] end.", + [1]), + error_check("begin [A || X <- [{1,2}], 1 == A] end.", + {unbound_var,'A'}), + error_check("begin X = 32, [{Y,W} || X <- [1,2,32,Y=4], Z <- [1,2,W=3]] end.", {unbound_var,'Y'}), - ?line error_check("begin X = 32,<<A:B>> = <<100:X>> end.", - {unbound_var,'B'}), - ?line check(fun() -> [X || X <- [1,2,3,4], not (X < 2)] end, - "begin [X || X <- [1,2,3,4], not (X < 2)] end.", - [2,3,4]), - ?line check(fun() -> [X || X <- [true,false], X] end, - "[X || X <- [true,false], X].", [true]), + error_check("begin X = 32,<<A:B>> = <<100:X>> end.", + {unbound_var,'B'}), + check(fun() -> [X || X <- [1,2,3,4], not (X < 2)] end, + "begin [X || X <- [1,2,3,4], not (X < 2)] end.", + [2,3,4]), + check(fun() -> [X || X <- [true,false], X] end, + "[X || X <- [true,false], X].", [true]), ok. -simple_cases(doc) -> - ["Simple cases, just to cover some code."]; -simple_cases(suite) -> - []; +%% Simple cases, just to cover some code. simple_cases(Config) when is_list(Config) -> - ?line check(fun() -> A = $C end, "A = $C.", $C), - %% ?line check(fun() -> A = 3.14 end, "A = 3.14.", 3.14), - ?line check(fun() -> self() ! a, A = receive a -> true end end, - "begin self() ! a, A = receive a -> true end end.", - true), - ?line check(fun() -> c:flush(), self() ! a, self() ! b, self() ! c, - receive b -> b end, - {messages, [a,c]} = - erlang:process_info(self(), messages), - c:flush() end, - "begin c:flush(), self() ! a, self() ! b, self() ! c," - "receive b -> b end," - "{messages, [a,c]} =" - " erlang:process_info(self(), messages), c:flush() end.", - ok), - ?line check(fun() -> self() ! a, A = receive a -> true - after 0 -> false end end, - "begin self() ! a, A = receive a -> true" - " after 0 -> false end end.", - true), - ?line check(fun() -> c:flush(), self() ! a, self() ! b, self() ! c, - receive b -> b after 0 -> true end, - {messages, [a,c]} = - erlang:process_info(self(), messages), - c:flush() end, - "begin c:flush(), self() ! a, self() ! b, self() ! c," - "receive b -> b after 0 -> true end," - "{messages, [a,c]} =" - " erlang:process_info(self(), messages), c:flush() end.", - ok), - ?line check(fun() -> receive _ -> true after 10 -> false end end, - "receive _ -> true after 10 -> false end.", - false), - ?line check(fun() -> F = fun(A) -> A end, true = 3 == F(3) end, - "begin F = fun(A) -> A end, true = 3 == F(3) end.", - true), - ?line check(fun() -> F = fun(A) -> A end, true = 3 == apply(F, [3]) end, - "begin F = fun(A) -> A end, true = 3 == apply(F,[3]) end.", - true), - ?line check(fun() -> catch throw(a) end, "catch throw(a).", a), - ?line check(fun() -> catch a end, "catch a.", a), - ?line check(fun() -> 4 == 3 end, "4 == 3.", false), - ?line check(fun() -> not true end, "not true.", false), - ?line check(fun() -> -3 end, "-3.", -3), - - ?line error_check("3.0 = 4.0.", {badmatch,4.0}), - ?line check(fun() -> <<(3.0+2.0):32/float>> = <<5.0:32/float>> end, - "<<(3.0+2.0):32/float>> = <<5.0:32/float>>.", - <<5.0:32/float>>), - - ?line check(fun() -> false andalso kludd end, "false andalso kludd.", - false), - ?line check(fun() -> true andalso true end, "true andalso true.", - true), - ?line check(fun() -> true andalso false end, "true andalso false.", - false), - ?line check(fun() -> true andalso kludd end, "true andalso kludd.", - kludd), - ?line error_check("kladd andalso kludd.", {badarg,kladd}), - - ?line check(fun() -> if false andalso kludd -> a; true -> b end end, - "if false andalso kludd -> a; true -> b end.", - b), - ?line check(fun() -> if true andalso true -> a; true -> b end end, - "if true andalso true -> a; true -> b end.", - a), - ?line check(fun() -> if true andalso false -> a; true -> b end end, - "if true andalso false -> a; true -> b end.", - b), - - ?line check(fun() -> true orelse kludd end, - "true orelse kludd.", true), - ?line check(fun() -> false orelse false end, - "false orelse false.", false), - ?line check(fun() -> false orelse true end, - "false orelse true.", true), - ?line check(fun() -> false orelse kludd end, - "false orelse kludd.", kludd), - ?line error_check("kladd orelse kludd.", {badarg,kladd}), - ?line error_check("[X || X <- [1,2,3], begin 1 end].",{bad_filter,1}), - ?line error_check("[X || X <- a].",{bad_generator,a}), - - ?line check(fun() -> if true orelse kludd -> a; true -> b end end, - "if true orelse kludd -> a; true -> b end.", a), - ?line check(fun() -> if false orelse false -> a; true -> b end end, - "if false orelse false -> a; true -> b end.", b), - ?line check(fun() -> if false orelse true -> a; true -> b end end, - "if false orelse true -> a; true -> b end.", a), - - ?line check(fun() -> [X || X <- [1,2,3], X+2] end, - "[X || X <- [1,2,3], X+2].", []), - - ?line check(fun() -> [X || X <- [1,2,3], [X] == [X || X <- [2]]] end, - "[X || X <- [1,2,3], [X] == [X || X <- [2]]].", - [2]), - ?line check(fun() -> F = fun(1) -> ett; (2) -> zwei end, - ett = F(1), zwei = F(2) end, - "begin F = fun(1) -> ett; (2) -> zwei end, + check(fun() -> A = $C end, "A = $C.", $C), + %% check(fun() -> A = 3.14 end, "A = 3.14.", 3.14), + check(fun() -> self() ! a, A = receive a -> true end end, + "begin self() ! a, A = receive a -> true end end.", + true), + check(fun() -> c:flush(), self() ! a, self() ! b, self() ! c, + receive b -> b end, + {messages, [a,c]} = + erlang:process_info(self(), messages), + c:flush() end, + "begin c:flush(), self() ! a, self() ! b, self() ! c," + "receive b -> b end," + "{messages, [a,c]} =" + " erlang:process_info(self(), messages), c:flush() end.", + ok), + check(fun() -> self() ! a, A = receive a -> true + after 0 -> false end end, + "begin self() ! a, A = receive a -> true" + " after 0 -> false end end.", + true), + check(fun() -> c:flush(), self() ! a, self() ! b, self() ! c, + receive b -> b after 0 -> true end, + {messages, [a,c]} = + erlang:process_info(self(), messages), + c:flush() end, + "begin c:flush(), self() ! a, self() ! b, self() ! c," + "receive b -> b after 0 -> true end," + "{messages, [a,c]} =" + " erlang:process_info(self(), messages), c:flush() end.", + ok), + check(fun() -> receive _ -> true after 10 -> false end end, + "receive _ -> true after 10 -> false end.", + false), + check(fun() -> F = fun(A) -> A end, true = 3 == F(3) end, + "begin F = fun(A) -> A end, true = 3 == F(3) end.", + true), + check(fun() -> F = fun(A) -> A end, true = 3 == apply(F, [3]) end, + "begin F = fun(A) -> A end, true = 3 == apply(F,[3]) end.", + true), + check(fun() -> catch throw(a) end, "catch throw(a).", a), + check(fun() -> catch a end, "catch a.", a), + check(fun() -> 4 == 3 end, "4 == 3.", false), + check(fun() -> not true end, "not true.", false), + check(fun() -> -3 end, "-3.", -3), + + error_check("3.0 = 4.0.", {badmatch,4.0}), + check(fun() -> <<(3.0+2.0):32/float>> = <<5.0:32/float>> end, + "<<(3.0+2.0):32/float>> = <<5.0:32/float>>.", + <<5.0:32/float>>), + + check(fun() -> false andalso kludd end, "false andalso kludd.", + false), + check(fun() -> true andalso true end, "true andalso true.", + true), + check(fun() -> true andalso false end, "true andalso false.", + false), + check(fun() -> true andalso kludd end, "true andalso kludd.", + kludd), + error_check("kladd andalso kludd.", {badarg,kladd}), + + check(fun() -> if false andalso kludd -> a; true -> b end end, + "if false andalso kludd -> a; true -> b end.", + b), + check(fun() -> if true andalso true -> a; true -> b end end, + "if true andalso true -> a; true -> b end.", + a), + check(fun() -> if true andalso false -> a; true -> b end end, + "if true andalso false -> a; true -> b end.", + b), + + check(fun() -> true orelse kludd end, + "true orelse kludd.", true), + check(fun() -> false orelse false end, + "false orelse false.", false), + check(fun() -> false orelse true end, + "false orelse true.", true), + check(fun() -> false orelse kludd end, + "false orelse kludd.", kludd), + error_check("kladd orelse kludd.", {badarg,kladd}), + error_check("[X || X <- [1,2,3], begin 1 end].",{bad_filter,1}), + error_check("[X || X <- a].",{bad_generator,a}), + + check(fun() -> if true orelse kludd -> a; true -> b end end, + "if true orelse kludd -> a; true -> b end.", a), + check(fun() -> if false orelse false -> a; true -> b end end, + "if false orelse false -> a; true -> b end.", b), + check(fun() -> if false orelse true -> a; true -> b end end, + "if false orelse true -> a; true -> b end.", a), + + check(fun() -> [X || X <- [1,2,3], X+2] end, + "[X || X <- [1,2,3], X+2].", []), + + check(fun() -> [X || X <- [1,2,3], [X] == [X || X <- [2]]] end, + "[X || X <- [1,2,3], [X] == [X || X <- [2]]].", + [2]), + check(fun() -> F = fun(1) -> ett; (2) -> zwei end, + ett = F(1), zwei = F(2) end, + "begin F = fun(1) -> ett; (2) -> zwei end, ett = F(1), zwei = F(2) end.", zwei), - ?line check(fun() -> F = fun(X) when X == 1 -> ett; - (X) when X == 2 -> zwei end, - ett = F(1), zwei = F(2) end, - "begin F = fun(X) when X == 1 -> ett; + check(fun() -> F = fun(X) when X == 1 -> ett; + (X) when X == 2 -> zwei end, + ett = F(1), zwei = F(2) end, + "begin F = fun(X) when X == 1 -> ett; (X) when X == 2 -> zwei end, - ett = F(1), zwei = F(2) end.", + ett = F(1), zwei = F(2) end.", zwei), - ?line error_check("begin F = fun(1) -> ett end, zwei = F(2) end.", - function_clause), - ?line check(fun() -> if length([1]) == 1 -> yes; - true -> no end end, - "if length([1]) == 1 -> yes; + error_check("begin F = fun(1) -> ett end, zwei = F(2) end.", + function_clause), + check(fun() -> if length([1]) == 1 -> yes; + true -> no end end, + "if length([1]) == 1 -> yes; true -> no end.", yes), - ?line check(fun() -> if is_integer(3) -> true; true -> false end end, - "if is_integer(3) -> true; true -> false end.", true), - ?line check(fun() -> if integer(3) -> true; true -> false end end, - "if integer(3) -> true; true -> false end.", true), - ?line check(fun() -> if is_float(3) -> true; true -> false end end, - "if is_float(3) -> true; true -> false end.", false), - ?line check(fun() -> if float(3) -> true; true -> false end end, - "if float(3) -> true; true -> false end.", false), - ?line check(fun() -> if is_number(3) -> true; true -> false end end, - "if is_number(3) -> true; true -> false end.", true), - ?line check(fun() -> if number(3) -> true; true -> false end end, - "if number(3) -> true; true -> false end.", true), - ?line check(fun() -> if is_atom(a) -> true; true -> false end end, - "if is_atom(a) -> true; true -> false end.", true), - ?line check(fun() -> if atom(a) -> true; true -> false end end, - "if atom(a) -> true; true -> false end.", true), - ?line check(fun() -> if is_list([]) -> true; true -> false end end, - "if is_list([]) -> true; true -> false end.", true), - ?line check(fun() -> if list([]) -> true; true -> false end end, - "if list([]) -> true; true -> false end.", true), - ?line check(fun() -> if is_tuple({}) -> true; true -> false end end, - "if is_tuple({}) -> true; true -> false end.", true), - ?line check(fun() -> if tuple({}) -> true; true -> false end end, - "if tuple({}) -> true; true -> false end.", true), - ?line check(fun() -> if is_pid(self()) -> true; true -> false end end, - "if is_pid(self()) -> true; true -> false end.", true), - ?line check(fun() -> if pid(self()) -> true; true -> false end end, - "if pid(self()) -> true; true -> false end.", true), - ?line check(fun() -> R = make_ref(), if is_reference(R) -> true; - true -> false end end, - "begin R = make_ref(), if is_reference(R) -> true;" - "true -> false end end.", true), - ?line check(fun() -> R = make_ref(), if reference(R) -> true; - true -> false end end, - "begin R = make_ref(), if reference(R) -> true;" - "true -> false end end.", true), - ?line check(fun() -> if is_port(a) -> true; true -> false end end, - "if is_port(a) -> true; true -> false end.", false), - ?line check(fun() -> if port(a) -> true; true -> false end end, - "if port(a) -> true; true -> false end.", false), - ?line check(fun() -> if is_function(a) -> true; true -> false end end, - "if is_function(a) -> true; true -> false end.", false), - ?line check(fun() -> if function(a) -> true; true -> false end end, - "if function(a) -> true; true -> false end.", false), - ?line check(fun() -> if is_binary(<<>>) -> true; true -> false end end, - "if is_binary(<<>>) -> true; true -> false end.", true), - ?line check(fun() -> if binary(<<>>) -> true; true -> false end end, - "if binary(<<>>) -> true; true -> false end.", true), - ?line check(fun() -> if is_integer(a) == true -> yes; - true -> no end end, - "if is_integer(a) == true -> yes; + check(fun() -> if is_integer(3) -> true; true -> false end end, + "if is_integer(3) -> true; true -> false end.", true), + check(fun() -> if integer(3) -> true; true -> false end end, + "if integer(3) -> true; true -> false end.", true), + check(fun() -> if is_float(3) -> true; true -> false end end, + "if is_float(3) -> true; true -> false end.", false), + check(fun() -> if float(3) -> true; true -> false end end, + "if float(3) -> true; true -> false end.", false), + check(fun() -> if is_number(3) -> true; true -> false end end, + "if is_number(3) -> true; true -> false end.", true), + check(fun() -> if number(3) -> true; true -> false end end, + "if number(3) -> true; true -> false end.", true), + check(fun() -> if is_atom(a) -> true; true -> false end end, + "if is_atom(a) -> true; true -> false end.", true), + check(fun() -> if atom(a) -> true; true -> false end end, + "if atom(a) -> true; true -> false end.", true), + check(fun() -> if is_list([]) -> true; true -> false end end, + "if is_list([]) -> true; true -> false end.", true), + check(fun() -> if list([]) -> true; true -> false end end, + "if list([]) -> true; true -> false end.", true), + check(fun() -> if is_tuple({}) -> true; true -> false end end, + "if is_tuple({}) -> true; true -> false end.", true), + check(fun() -> if tuple({}) -> true; true -> false end end, + "if tuple({}) -> true; true -> false end.", true), + check(fun() -> if is_pid(self()) -> true; true -> false end end, + "if is_pid(self()) -> true; true -> false end.", true), + check(fun() -> if pid(self()) -> true; true -> false end end, + "if pid(self()) -> true; true -> false end.", true), + check(fun() -> R = make_ref(), if is_reference(R) -> true; + true -> false end end, + "begin R = make_ref(), if is_reference(R) -> true;" + "true -> false end end.", true), + check(fun() -> R = make_ref(), if reference(R) -> true; + true -> false end end, + "begin R = make_ref(), if reference(R) -> true;" + "true -> false end end.", true), + check(fun() -> if is_port(a) -> true; true -> false end end, + "if is_port(a) -> true; true -> false end.", false), + check(fun() -> if port(a) -> true; true -> false end end, + "if port(a) -> true; true -> false end.", false), + check(fun() -> if is_function(a) -> true; true -> false end end, + "if is_function(a) -> true; true -> false end.", false), + check(fun() -> if function(a) -> true; true -> false end end, + "if function(a) -> true; true -> false end.", false), + check(fun() -> if is_binary(<<>>) -> true; true -> false end end, + "if is_binary(<<>>) -> true; true -> false end.", true), + check(fun() -> if binary(<<>>) -> true; true -> false end end, + "if binary(<<>>) -> true; true -> false end.", true), + check(fun() -> if is_integer(a) == true -> yes; + true -> no end end, + "if is_integer(a) == true -> yes; true -> no end.", no), - ?line check(fun() -> if [] -> true; true -> false end end, - "if [] -> true; true -> false end.", false), - ?line error_check("if lists:member(1,[1]) -> true; true -> false end.", - illegal_guard_expr), - ?line error_check("if false -> true end.", if_clause), - ?line check(fun() -> if a+b -> true; true -> false end end, - "if a + b -> true; true -> false end.", false), - ?line check(fun() -> if + b -> true; true -> false end end, - "if + b -> true; true -> false end.", false), - ?line error_check("case foo of bar -> true end.", {case_clause,foo}), - ?line error_check("case 4 of 2+a -> true; _ -> false end.", - illegal_pattern), - ?line error_check("case 4 of +a -> true; _ -> false end.", - illegal_pattern), - ?line check(fun() -> case a of - X when X == b -> one; - X when X == a -> two - end end, - "begin case a of + check(fun() -> if [] -> true; true -> false end end, + "if [] -> true; true -> false end.", false), + error_check("if lists:member(1,[1]) -> true; true -> false end.", + illegal_guard_expr), + error_check("if false -> true end.", if_clause), + check(fun() -> if a+b -> true; true -> false end end, + "if a + b -> true; true -> false end.", false), + check(fun() -> if + b -> true; true -> false end end, + "if + b -> true; true -> false end.", false), + error_check("case foo of bar -> true end.", {case_clause,foo}), + error_check("case 4 of 2+a -> true; _ -> false end.", + illegal_pattern), + error_check("case 4 of +a -> true; _ -> false end.", + illegal_pattern), + check(fun() -> case a of + X when X == b -> one; + X when X == a -> two + end end, + "begin case a of X when X == b -> one; - X when X == a -> two - end end.", two), - ?line error_check("3 = 4.", {badmatch,4}), - ?line error_check("a = 3.", {badmatch,3}), - %% ?line error_check("3.1 = 2.7.",{badmatch,2.7}), - ?line error_check("$c = 4.", {badmatch,4}), - ?line check(fun() -> $c = $c end, "$c = $c.", $c), - ?line check(fun() -> _ = bar end, "_ = bar.", bar), - ?line check(fun() -> A = 14, A = 14 end, + X when X == a -> two + end end.", two), + error_check("3 = 4.", {badmatch,4}), + error_check("a = 3.", {badmatch,3}), + %% error_check("3.1 = 2.7.",{badmatch,2.7}), + error_check("$c = 4.", {badmatch,4}), + check(fun() -> $c = $c end, "$c = $c.", $c), + check(fun() -> _ = bar end, "_ = bar.", bar), + check(fun() -> A = 14, A = 14 end, "begin A = 14, A = 14 end.", 14), - ?line error_check("begin A = 14, A = 16 end.", {badmatch,16}), - ?line error_check("\"hej\" = \"san\".", {badmatch,"san"}), - ?line check(fun() -> "hej" = "hej" end, + error_check("begin A = 14, A = 16 end.", {badmatch,16}), + error_check("\"hej\" = \"san\".", {badmatch,"san"}), + check(fun() -> "hej" = "hej" end, "\"hej\" = \"hej\".", "hej"), - ?line error_check("[] = [a].", {badmatch,[a]}), - ?line check(fun() -> [] = [] end, "[] = [].", []), - ?line error_check("[a] = [].", {badmatch,[]}), - ?line error_check("{a,b} = 34.", {badmatch,34}), - ?line check(fun() -> <<X:7>> = <<8:7>>, X end, + error_check("[] = [a].", {badmatch,[a]}), + check(fun() -> [] = [] end, "[] = [].", []), + error_check("[a] = [].", {badmatch,[]}), + error_check("{a,b} = 34.", {badmatch,34}), + check(fun() -> <<X:7>> = <<8:7>>, X end, "begin <<X:7>> = <<8:7>>, X end.", 8), - ?line error_check("<<34:32>> = \"hej\".", {badmatch,"hej"}), - ?line check(fun() -> trunc((1 * 3 div 3 + 4 - 3) / 1) rem 2 end, + error_check("<<34:32>> = \"hej\".", {badmatch,"hej"}), + check(fun() -> trunc((1 * 3 div 3 + 4 - 3) / 1) rem 2 end, "begin trunc((1 * 3 div 3 + 4 - 3) / 1) rem 2 end.", 0), - ?line check(fun() -> (2#101 band 2#10101) bor (2#110 bxor 2#010) end, + check(fun() -> (2#101 band 2#10101) bor (2#110 bxor 2#010) end, "(2#101 band 2#10101) bor (2#110 bxor 2#010).", 5), - ?line check(fun() -> (2#1 bsl 4) + (2#10000 bsr 3) end, + check(fun() -> (2#1 bsl 4) + (2#10000 bsr 3) end, "(2#1 bsl 4) + (2#10000 bsr 3).", 18), - ?line check(fun() -> ((1<3) and ((1 =:= 2) or (1 =/= 2))) xor (1=<2) end, + check(fun() -> ((1<3) and ((1 =:= 2) or (1 =/= 2))) xor (1=<2) end, "((1<3) and ((1 =:= 2) or (1 =/= 2))) xor (1=<2).", false), - ?line check(fun() -> (a /= b) or (2 > 4) or (3 >= 3) end, + check(fun() -> (a /= b) or (2 > 4) or (3 >= 3) end, "(a /= b) or (2 > 4) or (3 >= 3).", true), - ?line check(fun() -> "hej" ++ "san" =/= "hejsan" -- "san" end, + check(fun() -> "hej" ++ "san" =/= "hejsan" -- "san" end, "\"hej\" ++ \"san\" =/= \"hejsan\" -- \"san\".", true), - ?line check(fun() -> (bnot 1) < -0 end, "(bnot (+1)) < -0.", true), - ok. + check(fun() -> (bnot 1) < -0 end, "(bnot (+1)) < -0.", true), + ok. -unary_plus(doc) -> - ["OTP-4929. Unary plus rejects non-numbers."]; -unary_plus(suite) -> - []; +%% OTP-4929. Unary plus rejects non-numbers. unary_plus(Config) when is_list(Config) -> - ?line check(fun() -> F = fun(X) -> + X end, - true = -1 == F(-1) end, - "begin F = fun(X) -> + X end," - " true = -1 == F(-1) end.", true, ['F'], none, none), - ?line error_check("+a.", badarith), + check(fun() -> F = fun(X) -> + X end, + true = -1 == F(-1) end, + "begin F = fun(X) -> + X end," + " true = -1 == F(-1) end.", true, ['F'], none, none), + error_check("+a.", badarith), ok. -apply_atom(doc) -> - ["OTP-5064. Can no longer apply atoms."]; -apply_atom(suite) -> - []; +%% OTP-5064. Can no longer apply atoms. apply_atom(Config) when is_list(Config) -> - ?line error_check("[X || X <- [[1],[2]], + error_check("[X || X <- [[1],[2]], begin L = length, L(X) =:= 1 end].", {badfun,length}), ok. -otp_5269(doc) -> - ["OTP-5269. Bugs in the bit syntax."]; -otp_5269(suite) -> - []; +%% OTP-5269. Bugs in the bit syntax. otp_5269(Config) when is_list(Config) -> - ?line check(fun() -> L = 8, + check(fun() -> L = 8, F = fun(<<A:L,B:A>>) -> B end, F(<<16:8, 7:16>>) end, @@ -560,7 +517,7 @@ otp_5269(Config) when is_list(Config) -> L = 8, F = fun(<<A:L,B:A>>) -> B end, F(<<16:8, 7:16>>) end.", 7), - ?line check(fun() -> L = 8, + check(fun() -> L = 8, F = fun(<<L:L,B:L>>) -> B end, F(<<16:8, 7:16>>) end, @@ -568,31 +525,31 @@ otp_5269(Config) when is_list(Config) -> L = 8, F = fun(<<L:L,B:L>>) -> B end, F(<<16:8, 7:16>>) end.", 7), - ?line check(fun() -> L = 8, <<A:L,B:A>> = <<16:8, 7:16>>, B end, + check(fun() -> L = 8, <<A:L,B:A>> = <<16:8, 7:16>>, B end, "begin L = 8, <<A:L,B:A>> = <<16:8, 7:16>>, B end.", 7), - ?line error_check("begin L = 8, <<L:L,B:L>> = <<16:8, 7:16>> end.", + error_check("begin L = 8, <<L:L,B:L>> = <<16:8, 7:16>> end.", {badmatch,<<16:8,7:16>>}), - ?line error_check("begin <<L:16,L:L>> = <<16:16,8:16>>, L end.", + error_check("begin <<L:16,L:L>> = <<16:16,8:16>>, L end.", {badmatch, <<16:16,8:16>>}), - ?line check(fun() -> U = 8, (fun(<<U:U>>) -> U end)(<<32:8>>) end, + check(fun() -> U = 8, (fun(<<U:U>>) -> U end)(<<32:8>>) end, "begin U = 8, (fun(<<U:U>>) -> U end)(<<32:8>>) end.", 32), - ?line check(fun() -> U = 8, [U || <<U:U>> <- [<<32:8>>]] end, + check(fun() -> U = 8, [U || <<U:U>> <- [<<32:8>>]] end, "begin U = 8, [U || <<U:U>> <- [<<32:8>>]] end.", [32]), - ?line error_check("(fun({3,<<A:32,A:32>>}) -> a end) + error_check("(fun({3,<<A:32,A:32>>}) -> a end) ({3,<<17:32,19:32>>}).", function_clause), - ?line check(fun() -> [X || <<A:8, + check(fun() -> [X || <<A:8, B:A>> <- [<<16:8,19:16>>], <<X:8>> <- [<<B:8>>]] end, "[X || <<A:8, B:A>> <- [<<16:8,19:16>>], <<X:8>> <- [<<B:8>>]].", [19]), - ?line check(fun() -> + check(fun() -> (fun (<<A:1/binary, B:8/integer, _C:B/binary>>) -> case A of B -> wrong; @@ -605,12 +562,9 @@ otp_5269(Config) when is_list(Config) -> ok), ok. -otp_6539(doc) -> - ["OTP-6539. try/catch bugs."]; -otp_6539(suite) -> - []; +%% OTP-6539. try/catch bugs. otp_6539(Config) when is_list(Config) -> - ?line check(fun() -> + check(fun() -> F = fun(A,B) -> try A+B catch _:_ -> dontthinkso @@ -629,152 +583,149 @@ otp_6539(Config) when is_list(Config) -> [3, 5]), ok. -otp_6543(doc) -> - ["OTP-6543. bitlevel binaries."]; -otp_6543(suite) -> - []; +%% OTP-6543. bitlevel binaries. otp_6543(Config) when is_list(Config) -> - ?line check(fun() -> + check(fun() -> << <<X>> || <<X>> <- [1,2,3] >> end, "<< <<X>> || <<X>> <- [1,2,3] >>.", <<>>), - ?line check(fun() -> + check(fun() -> << <<X>> || X <- [1,2,3] >> end, "<< <<X>> || X <- [1,2,3] >>.", <<1,2,3>>), - ?line check(fun() -> + check(fun() -> << <<X:8>> || <<X:2>> <= <<"hej">> >> end, "<< <<X:8>> || <<X:2>> <= <<\"hej\">> >>.", <<1,2,2,0,1,2,1,1,1,2,2,2>>), - ?line check(fun() -> + check(fun() -> << <<X:8>> || <<65,X:4>> <= <<65,7:4,65,3:4,66,8:4>> >> end, "<< <<X:8>> || <<65,X:4>> <= <<65,7:4,65,3:4,66,8:4>> >>.", <<7,3>>), - ?line check(fun() -> <<34:18/big>> end, + check(fun() -> <<34:18/big>> end, "<<34:18/big>>.", <<0,8,2:2>>), - ?line check(fun() -> <<34:18/big-unit:2>> end, + check(fun() -> <<34:18/big-unit:2>> end, "<<34:18/big-unit:2>>.", <<0,0,0,2,2:4>>), - ?line check(fun() -> <<34:18/little>> end, + check(fun() -> <<34:18/little>> end, "<<34:18/little>>.", <<34,0,0:2>>), - ?line case eval_string("<<34:18/native>>.") of + case eval_string("<<34:18/native>>.") of <<0,8,2:2>> -> ok; <<34,0,0:2>> -> ok end, - ?line check(fun() -> <<34:18/big-signed>> end, + check(fun() -> <<34:18/big-signed>> end, "<<34:18/big-signed>>.", <<0,8,2:2>>), - ?line check(fun() -> <<34:18/little-signed>> end, + check(fun() -> <<34:18/little-signed>> end, "<<34:18/little-signed>>.", <<34,0,0:2>>), - ?line case eval_string("<<34:18/native-signed>>.") of + case eval_string("<<34:18/native-signed>>.") of <<0,8,2:2>> -> ok; <<34,0,0:2>> -> ok end, - ?line check(fun() -> <<34:18/big-unsigned>> end, + check(fun() -> <<34:18/big-unsigned>> end, "<<34:18/big-unsigned>>.", <<0,8,2:2>>), - ?line check(fun() -> <<34:18/little-unsigned>> end, + check(fun() -> <<34:18/little-unsigned>> end, "<<34:18/little-unsigned>>.", <<34,0,0:2>>), - ?line case eval_string("<<34:18/native-unsigned>>.") of + case eval_string("<<34:18/native-unsigned>>.") of <<0,8,2:2>> -> ok; <<34,0,0:2>> -> ok end, - ?line check(fun() -> <<3.14:32/float-big>> end, + check(fun() -> <<3.14:32/float-big>> end, "<<3.14:32/float-big>>.", <<64,72,245,195>>), - ?line check(fun() -> <<3.14:32/float-little>> end, + check(fun() -> <<3.14:32/float-little>> end, "<<3.14:32/float-little>>.", <<195,245,72,64>>), - ?line case eval_string("<<3.14:32/float-native>>.") of + case eval_string("<<3.14:32/float-native>>.") of <<64,72,245,195>> -> ok; <<195,245,72,64>> -> ok end, - ?line error_check("<<(<<17,3:2>>)/binary>>.", badarg), - ?line check(fun() -> <<(<<17,3:2>>)/bitstring>> end, + error_check("<<(<<17,3:2>>)/binary>>.", badarg), + check(fun() -> <<(<<17,3:2>>)/bitstring>> end, "<<(<<17,3:2>>)/bitstring>>.", <<17,3:2>>), - ?line check(fun() -> <<(<<17,3:2>>):10/bitstring>> end, + check(fun() -> <<(<<17,3:2>>):10/bitstring>> end, "<<(<<17,3:2>>):10/bitstring>>.", <<17,3:2>>), - ?line check(fun() -> <<<<344:17>>/binary-unit:17>> end, + check(fun() -> <<<<344:17>>/binary-unit:17>> end, "<<<<344:17>>/binary-unit:17>>.", <<344:17>>), - ?line check(fun() -> <<X:18/big>> = <<34:18/big>>, X end, + check(fun() -> <<X:18/big>> = <<34:18/big>>, X end, "begin <<X:18/big>> = <<34:18/big>>, X end.", 34), - ?line check(fun() -> <<X:18/big-unit:2>> = <<34:18/big-unit:2>>, X end, + check(fun() -> <<X:18/big-unit:2>> = <<34:18/big-unit:2>>, X end, "begin <<X:18/big-unit:2>> = <<34:18/big-unit:2>>, X end.", 34), - ?line check(fun() -> <<X:18/little>> = <<34:18/little>>, X end, + check(fun() -> <<X:18/little>> = <<34:18/little>>, X end, "begin <<X:18/little>> = <<34:18/little>>, X end.", 34), - ?line check(fun() -> <<X:18/native>> = <<34:18/native>>, X end, + check(fun() -> <<X:18/native>> = <<34:18/native>>, X end, "begin <<X:18/native>> = <<34:18/native>>, X end.", 34), - ?line check(fun() -> <<X:18/big-signed>> = <<34:18/big-signed>>, X end, + check(fun() -> <<X:18/big-signed>> = <<34:18/big-signed>>, X end, "begin <<X:18/big-signed>> = <<34:18/big-signed>>, X end.", 34), - ?line check(fun() -> <<X:18/little-signed>> = <<34:18/little-signed>>, + check(fun() -> <<X:18/little-signed>> = <<34:18/little-signed>>, X end, "begin <<X:18/little-signed>> = <<34:18/little-signed>>, X end.", 34), - ?line check(fun() -> <<X:18/native-signed>> = <<34:18/native-signed>>, + check(fun() -> <<X:18/native-signed>> = <<34:18/native-signed>>, X end, "begin <<X:18/native-signed>> = <<34:18/native-signed>>, X end.", 34), - ?line check(fun() -> <<X:18/big-unsigned>> = <<34:18/big-unsigned>>, + check(fun() -> <<X:18/big-unsigned>> = <<34:18/big-unsigned>>, X end, "begin <<X:18/big-unsigned>> = <<34:18/big-unsigned>>, X end.", 34), - ?line check(fun() -> + check(fun() -> <<X:18/little-unsigned>> = <<34:18/little-unsigned>>, X end, "begin <<X:18/little-unsigned>> = <<34:18/little-unsigned>>, X end.", 34), - ?line check(fun() -> + check(fun() -> <<X:18/native-unsigned>> = <<34:18/native-unsigned>>, X end, "begin <<X:18/native-unsigned>> = <<34:18/native-unsigned>>, X end.", 34), - ?line check(fun() -> <<X:32/float-big>> = <<2.0:32/float-big>>, X end, + check(fun() -> <<X:32/float-big>> = <<2.0:32/float-big>>, X end, "begin <<X:32/float-big>> = <<2.0:32/float-big>>, X end.", 2.0), - ?line check(fun() -> <<X:32/float-little>> = <<2.0:32/float-little>>, + check(fun() -> <<X:32/float-little>> = <<2.0:32/float-little>>, X end, "begin <<X:32/float-little>> = <<2.0:32/float-little>>, X end.", 2.0), - ?line check(fun() -> <<X:32/float-native>> = <<2.0:32/float-native>>, + check(fun() -> <<X:32/float-native>> = <<2.0:32/float-native>>, X end, "begin <<X:32/float-native>> = <<2.0:32/float-native>>, X end.", 2.0), - ?line check( + check( fun() -> [X || <<"hej",X:8>> <= <<"hej",8,"san",9,"hej",17,"hej">>] end, "[X || <<\"hej\",X:8>> <= <<\"hej\",8,\"san\",9,\"hej\",17,\"hej\">>].", [8,17]), - ?line check( + check( fun() -> L = 8, << <<B:32>> || <<L:L,B:L>> <= <<16:8, 7:16>> >> end, @@ -783,41 +734,41 @@ otp_6543(Config) when is_list(Config) -> <<0,0,0,7>>), %% Test the Value part of a binary segment. %% "Old" bugs have been fixed (partial_eval is called on Value). - ?line check(fun() -> [ 3 || <<17/float>> <= <<17.0/float>>] end, + check(fun() -> [ 3 || <<17/float>> <= <<17.0/float>>] end, "[ 3 || <<17/float>> <= <<17.0/float>>].", [3]), - ?line check(fun() -> [ 3 || <<17/float>> <- [<<17.0/float>>]] end, + check(fun() -> [ 3 || <<17/float>> <- [<<17.0/float>>]] end, "[ 3 || <<17/float>> <- [<<17.0/float>>]].", [3]), - ?line check(fun() -> [ X || <<17/float,X:3>> <= <<17.0/float,2:3>>] end, + check(fun() -> [ X || <<17/float,X:3>> <= <<17.0/float,2:3>>] end, "[ X || <<17/float,X:3>> <= <<17.0/float,2:3>>].", [2]), - ?line check(fun() -> + check(fun() -> [ foo || <<(1 bsl 1023)/float>> <= <<(1 bsl 1023)/float>>] end, "[ foo || <<(1 bsl 1023)/float>> <= <<(1 bsl 1023)/float>>].", [foo]), - ?line check(fun() -> + check(fun() -> [ foo || <<(1 bsl 1023)/float>> <- [<<(1 bsl 1023)/float>>]] end, "[ foo || <<(1 bsl 1023)/float>> <- [<<(1 bsl 1023)/float>>]].", [foo]), - ?line error_check("[ foo || <<(1 bsl 1024)/float>> <- + error_check("[ foo || <<(1 bsl 1024)/float>> <- [<<(1 bsl 1024)/float>>]].", badarg), - ?line check(fun() -> + check(fun() -> [ foo || <<(1 bsl 1024)/float>> <- [<<(1 bsl 1023)/float>>]] end, "[ foo || <<(1 bsl 1024)/float>> <- [<<(1 bsl 1023)/float>>]].", []), - ?line check(fun() -> + check(fun() -> [ foo || <<(1 bsl 1024)/float>> <= <<(1 bsl 1023)/float>>] end, "[ foo || <<(1 bsl 1024)/float>> <= <<(1 bsl 1023)/float>>].", []), - ?line check(fun() -> + check(fun() -> L = 8, [{L,B} || <<L:L,B:L/float>> <= <<32:8,7:32/float>>] end, @@ -825,7 +776,7 @@ otp_6543(Config) when is_list(Config) -> [{L,B} || <<L:L,B:L/float>> <= <<32:8,7:32/float>>] end.", [{32,7.0}]), - ?line check(fun() -> + check(fun() -> L = 8, [{L,B} || <<L:L,B:L/float>> <- [<<32:8,7:32/float>>]] end, @@ -833,127 +784,117 @@ otp_6543(Config) when is_list(Config) -> [{L,B} || <<L:L,B:L/float>> <- [<<32:8,7:32/float>>]] end.", [{32,7.0}]), - ?line check(fun() -> + check(fun() -> [foo || <<"s">> <= <<"st">>] end, "[foo || <<\"s\">> <= <<\"st\">>].", [foo]), - ?line check(fun() -> <<_:32>> = <<17:32>> end, + check(fun() -> <<_:32>> = <<17:32>> end, "<<_:32>> = <<17:32>>.", <<17:32>>), - ?line check(fun() -> [foo || <<_:32>> <= <<17:32,20:32>>] end, + check(fun() -> [foo || <<_:32>> <= <<17:32,20:32>>] end, "[foo || <<_:32>> <= <<17:32,20:32>>].", [foo,foo]), - ?line check(fun() -> << <<X:32>> || X <- [1,2,3], X > 1 >> end, + check(fun() -> << <<X:32>> || X <- [1,2,3], X > 1 >> end, "<< <<X:32>> || X <- [1,2,3], X > 1 >>.", <<0,0,0,2,0,0,0,3>>), - ?line error_check("[X || <<X>> <= [a,b]].",{bad_generator,[a,b]}), + error_check("[X || <<X>> <= [a,b]].",{bad_generator,[a,b]}), ok. -otp_6787(doc) -> - ["OTP-6787. bitlevel binaries."]; -otp_6787(suite) -> - []; +%% OTP-6787. bitlevel binaries. otp_6787(Config) when is_list(Config) -> - ?line check( + check( fun() -> <<16:(1024*1024)>> = <<16:(1024*1024)>> end, "<<16:(1024*1024)>> = <<16:(1024*1024)>>.", <<16:1048576>>), ok. -otp_6977(doc) -> - ["OTP-6977. ++ bug."]; -otp_6977(suite) -> - []; +%% OTP-6977. ++ bug. otp_6977(Config) when is_list(Config) -> - ?line check( + check( fun() -> (fun([$X] ++ _) -> ok end)("X") end, "(fun([$X] ++ _) -> ok end)(\"X\").", ok), ok. -otp_7550(doc) -> - ["OTP-7550. Support for UTF-8, UTF-16, UTF-32."]; +%% OTP-7550. Support for UTF-8, UTF-16, UTF-32. otp_7550(Config) when is_list(Config) -> %% UTF-8. - ?line check( + check( fun() -> <<65>> = <<65/utf8>> end, "<<65>> = <<65/utf8>>.", <<65>>), - ?line check( + check( fun() -> <<350/utf8>> = <<197,158>> end, "<<350/utf8>> = <<197,158>>.", <<197,158>>), - ?line check( + check( fun() -> <<$b,$j,$\303,$\266,$r,$n>> = <<"bj\366rn"/utf8>> end, "<<$b,$j,$\303,$\266,$r,$n>> = <<\"bj\366rn\"/utf8>>.", <<$b,$j,$\303,$\266,$r,$n>>), %% UTF-16. - ?line check( + check( fun() -> <<0,65>> = <<65/utf16>> end, "<<0,65>> = <<65/utf16>>.", <<0,65>>), - ?line check( + check( fun() -> <<16#D8,16#08,16#DF,16#45>> = <<16#12345/utf16>> end, "<<16#D8,16#08,16#DF,16#45>> = <<16#12345/utf16>>.", <<16#D8,16#08,16#DF,16#45>>), - ?line check( + check( fun() -> <<16#08,16#D8,16#45,16#DF>> = <<16#12345/little-utf16>> end, "<<16#08,16#D8,16#45,16#DF>> = <<16#12345/little-utf16>>.", <<16#08,16#D8,16#45,16#DF>>), - ?line check( + check( fun() -> <<350/utf16>> = <<1,94>> end, "<<350/utf16>> = <<1,94>>.", <<1,94>>), - ?line check( + check( fun() -> <<350/little-utf16>> = <<94,1>> end, "<<350/little-utf16>> = <<94,1>>.", <<94,1>>), - ?line check( + check( fun() -> <<16#12345/utf16>> = <<16#D8,16#08,16#DF,16#45>> end, "<<16#12345/utf16>> = <<16#D8,16#08,16#DF,16#45>>.", <<16#D8,16#08,16#DF,16#45>>), - ?line check( + check( fun() -> <<16#12345/little-utf16>> = <<16#08,16#D8,16#45,16#DF>> end, "<<16#12345/little-utf16>> = <<16#08,16#D8,16#45,16#DF>>.", <<16#08,16#D8,16#45,16#DF>>), %% UTF-32. - ?line check( + check( fun() -> <<16#12345/utf32>> = <<16#0,16#01,16#23,16#45>> end, "<<16#12345/utf32>> = <<16#0,16#01,16#23,16#45>>.", <<16#0,16#01,16#23,16#45>>), - ?line check( + check( fun() -> <<16#0,16#01,16#23,16#45>> = <<16#12345/utf32>> end, "<<16#0,16#01,16#23,16#45>> = <<16#12345/utf32>>.", <<16#0,16#01,16#23,16#45>>), - ?line check( + check( fun() -> <<16#12345/little-utf32>> = <<16#45,16#23,16#01,16#00>> end, "<<16#12345/little-utf32>> = <<16#45,16#23,16#01,16#00>>.", <<16#45,16#23,16#01,16#00>>), - ?line check( + check( fun() -> <<16#12345/little-utf32>> end, "<<16#12345/little-utf32>>.", <<16#45,16#23,16#01,16#00>>), %% Mixed. - ?line check( + check( fun() -> <<16#41,16#12345/utf32,16#0391:16,16#2E:8>> end, "<<16#41,16#12345/utf32,16#0391:16,16#2E:8>>.", <<16#41,16#00,16#01,16#23,16#45,16#03,16#91,16#2E>>), ok. -otp_8133(doc) -> - ["OTP-8133. Bit comprehension bug."]; -otp_8133(suite) -> - []; +%% OTP-8133. Bit comprehension bug. otp_8133(Config) when is_list(Config) -> - ?line check( + check( fun() -> E = fun(N) -> if @@ -976,7 +917,7 @@ otp_8133(Config) when is_list(Config) -> end end.", ok), - ?line check( + check( fun() -> E = fun(N) -> if @@ -1002,10 +943,7 @@ otp_8133(Config) when is_list(Config) -> ok), ok. -otp_10622(doc) -> - ["OTP-10622. Bugs."]; -otp_10622(suite) -> - []; +%% OTP-10622. Bugs. otp_10622(Config) when is_list(Config) -> check(fun() -> <<0>> = <<"\x{400}">> end, "<<0>> = <<\"\\x{400}\">>. ", @@ -1044,51 +982,47 @@ otp_10622(Config) when is_list(Config) -> ok. -otp_13228(doc) -> - ["OTP-13228. ERL-32: non-local function handler bug."]; +%% OTP-13228. ERL-32: non-local function handler bug. otp_13228(_Config) -> LFH = {value, fun(foo, [io_fwrite]) -> worked end}, EFH = {value, fun({io, fwrite}, [atom]) -> io_fwrite end}, {value, worked, []} = parse_and_run("foo(io:fwrite(atom)).", LFH, EFH). -funs(doc) -> - ["Simple cases, just to cover some code."]; -funs(suite) -> - []; +%% Simple cases, just to cover some code. funs(Config) when is_list(Config) -> do_funs(none, none), do_funs(lfh(), none), do_funs(lfh(), efh()), - ?line error_check("nix:foo().", {access_not_allowed,nix}, lfh(), efh()), - ?line error_check("bar().", undef, none, none), + error_check("nix:foo().", {access_not_allowed,nix}, lfh(), efh()), + error_check("bar().", undef, none, none), - ?line check(fun() -> F1 = fun(F,N) -> ?MODULE:count_down(F, N) end, + check(fun() -> F1 = fun(F,N) -> ?MODULE:count_down(F, N) end, F1(F1, 1000) end, "begin F1 = fun(F,N) -> count_down(F, N) end," "F1(F1,1000) end.", 0, ['F1'], lfh(), none), - ?line check(fun() -> F1 = fun(F,N) -> ?MODULE:count_down(F, N) end, + check(fun() -> F1 = fun(F,N) -> ?MODULE:count_down(F, N) end, F1(F1, 1000) end, "begin F1 = fun(F,N) -> count_down(F, N) end," "F1(F1,1000) end.", 0, ['F1'], lfh_value(), none), - ?line check(fun() -> F1 = fun(F,N) -> ?MODULE:count_down(F, N) end, + check(fun() -> F1 = fun(F,N) -> ?MODULE:count_down(F, N) end, F1(F1, 1000) end, "begin F1 = fun(F,N) -> count_down(F, N) end," "F1(F1,1000) end.", 0, ['F1'], lfh_value_extra(), none), - ?line check(fun() -> F1 = fun(F,N) -> ?MODULE:count_down(F, N) end, + check(fun() -> F1 = fun(F,N) -> ?MODULE:count_down(F, N) end, F1(F1, 1000) end, "begin F1 = fun(F,N) -> count_down(F, N) end," "F1(F1,1000) end.", 0, ['F1'], {?MODULE,local_func_value}, none), %% This is not documented, and only for backward compatibility (good!). B0 = erl_eval:new_bindings(), - ?line check(fun() -> is_function(?MODULE:count_down_fun()) end, + check(fun() -> is_function(?MODULE:count_down_fun()) end, "begin is_function(count_down_fun()) end.", true, [], {?MODULE,local_func,[B0]},none), @@ -1096,19 +1030,19 @@ funs(Config) when is_list(Config) -> ({M,F}, As) -> apply(M, F, As) end, EFH = {value, EF}, - ?line error_check("apply(timer, sleep, [1]).", got_it, none, EFH), - ?line error_check("begin F = fun(T) -> timer:sleep(T) end,F(1) end.", + error_check("apply(timer, sleep, [1]).", got_it, none, EFH), + error_check("begin F = fun(T) -> timer:sleep(T) end,F(1) end.", got_it, none, EFH), - ?line error_check("fun c/1.", undef), - ?line error_check("fun a:b/0().", undef), + error_check("fun c/1.", undef), + error_check("fun a:b/0().", undef), MaxArgs = 20, - ?line [true] = + [true] = lists:usort([run_many_args(SAs) || SAs <- many_args(MaxArgs)]), - ?line {'EXIT',{{argument_limit,_},_}} = + {'EXIT',{{argument_limit,_},_}} = (catch run_many_args(many_args1(MaxArgs+1))), - ?line check(fun() -> M = lists, F = fun M:reverse/1, + check(fun() -> M = lists, F = fun M:reverse/1, [1,2] = F([2,1]), ok end, "begin M = lists, F = fun M:reverse/1," " [1,2] = F([2,1]), ok end.", @@ -1142,17 +1076,17 @@ do_funs(LFH, EFH) -> %% manually with 1000 replaced by 1000000. M = atom_to_list(?MODULE), - ?line check(fun() -> F1 = fun(F,N) -> ?MODULE:count_down(F, N) end, + check(fun() -> F1 = fun(F,N) -> ?MODULE:count_down(F, N) end, F1(F1, 1000) end, concat(["begin F1 = fun(F,N) -> ", M, ":count_down(F, N) end, F1(F1,1000) end."]), 0, ['F1'], LFH, EFH), - ?line check(fun() -> F1 = fun(F,N) -> apply(?MODULE,count_down,[F,N]) + check(fun() -> F1 = fun(F,N) -> apply(?MODULE,count_down,[F,N]) end, F1(F1, 1000) end, concat(["begin F1 = fun(F,N) -> apply(", M, ",count_down,[F, N]) end, F1(F1,1000) end."]), 0, ['F1'], LFH, EFH), - ?line check(fun() -> F = fun(F,N) when N > 0 -> apply(F,[F,N-1]); + check(fun() -> F = fun(F,N) when N > 0 -> apply(F,[F,N-1]); (_F,0) -> ok end, F(F, 1000) end, @@ -1160,7 +1094,7 @@ do_funs(LFH, EFH) -> "(_F,0) -> ok end," "F(F, 1000) end.", ok, ['F'], LFH, EFH), - ?line check(fun() -> F = fun(F,N) when N > 0 -> + check(fun() -> F = fun(F,N) when N > 0 -> apply(erlang,apply,[F,[F,N-1]]); (_F,0) -> ok end, F(F, 1000) @@ -1170,7 +1104,7 @@ do_funs(LFH, EFH) -> "(_F,0) -> ok end," "F(F, 1000) end.", ok, ['F'], LFH, EFH), - ?line check(fun() -> F = count_down_fun(), + check(fun() -> F = count_down_fun(), SF = fun(SF, F1, N) -> F(SF, F1, N) end, SF(SF, F, 1000) end, concat(["begin F = ", M, ":count_down_fun()," @@ -1179,7 +1113,7 @@ do_funs(LFH, EFH) -> ok, ['F','SF'], LFH, EFH), - ?line check(fun() -> F = fun(X) -> A = 1+X, {X,A} end, + check(fun() -> F = fun(X) -> A = 1+X, {X,A} end, true = {2,3} == F(2) end, "begin F = fun(X) -> A = 1+X, {X,A} end, true = {2,3} == F(2) end.", true, ['F'], LFH, EFH), @@ -1188,13 +1122,13 @@ do_funs(LFH, EFH) -> "begin F = fun(X) -> erlang:'+'(X,2) end," " true = 3 == F(1) end.", true, ['F'], LFH, EFH), - ?line check(fun() -> F = fun(X) -> byte_size(X) end, + check(fun() -> F = fun(X) -> byte_size(X) end, ?MODULE:do_apply(F,<<"hej">>) end, concat(["begin F = fun(X) -> size(X) end,", M,":do_apply(F,<<\"hej\">>) end."]), 3, ['F'], LFH, EFH), - ?line check(fun() -> F1 = fun(X, Z) -> {X,Z} end, + check(fun() -> F1 = fun(X, Z) -> {X,Z} end, Z = 5, F2 = fun(X, Y) -> F1(Z,{X,Y}) end, F3 = fun(X, Y) -> {a,F1(Z,{X,Y})} end, @@ -1211,26 +1145,26 @@ do_funs(LFH, EFH) -> {5,{5,y}} = F2(Z,y), true = {5,{x,5}} == F2(x,Z) end.", true, ['F1','Z','F2','F3'], LFH, EFH), - ?line check(fun() -> F = fun(X) -> byte_size(X) end, + check(fun() -> F = fun(X) -> byte_size(X) end, F2 = fun(Y) -> F(Y) end, ?MODULE:do_apply(F2,<<"hej">>) end, concat(["begin F = fun(X) -> size(X) end,", "F2 = fun(Y) -> F(Y) end,", M,":do_apply(F2,<<\"hej\">>) end."]), 3, ['F','F2'], LFH, EFH), - ?line check(fun() -> Z = 5, F = fun(X) -> {Z,X} end, + check(fun() -> Z = 5, F = fun(X) -> {Z,X} end, F2 = fun(Z) -> F(Z) end, F2(3) end, "begin Z = 5, F = fun(X) -> {Z,X} end, F2 = fun(Z) -> F(Z) end, F2(3) end.", {5,3},['F','F2','Z'], LFH, EFH), - ?line check(fun() -> F = fun(Z) -> Z end, + check(fun() -> F = fun(Z) -> Z end, F2 = fun(X) -> F(X), Z = {X,X}, Z end, {1,1} = F2(1), Z = 7, Z end, "begin F = fun(Z) -> Z end, F2 = fun(X) -> F(X), Z = {X,X}, Z end, {1,1} = F2(1), Z = 7, Z end.", 7, ['F','F2','Z'], LFH, EFH), - ?line check(fun() -> F = fun(F, N) -> [?MODULE:count_down(F,N) || X <-[1]] + check(fun() -> F = fun(F, N) -> [?MODULE:count_down(F,N) || X <-[1]] end, F(F,2) end, concat(["begin F = fun(F, N) -> [", M, ":count_down(F,N) || X <-[1]] end, F(F,2) end."]), @@ -1289,45 +1223,42 @@ external_func({M,F}, As) -> -try_catch(doc) -> - ["Test try-of-catch-after-end statement"]; -try_catch(suite) -> - []; +%% Test try-of-catch-after-end statement. try_catch(Config) when is_list(Config) -> %% Match in of with catch - ?line check(fun() -> try 1 of 1 -> 2 catch _:_ -> 3 end end, + check(fun() -> try 1 of 1 -> 2 catch _:_ -> 3 end end, "try 1 of 1 -> 2 catch _:_ -> 3 end.", 2), - ?line check(fun() -> try 1 of 1 -> 2; 3 -> 4 catch _:_ -> 5 end end, + check(fun() -> try 1 of 1 -> 2; 3 -> 4 catch _:_ -> 5 end end, "try 1 of 1 -> 2; 3 -> 4 catch _:_ -> 5 end.", 2), - ?line check(fun() -> try 3 of 1 -> 2; 3 -> 4 catch _:_ -> 5 end end, + check(fun() -> try 3 of 1 -> 2; 3 -> 4 catch _:_ -> 5 end end, "try 3 of 1 -> 2; 3 -> 4 catch _:_ -> 5 end.", 4), %% Just after - ?line check(fun () -> X = try 1 after put(try_catch, 2) end, + check(fun () -> X = try 1 after put(try_catch, 2) end, {X,get(try_catch)} end, "begin X = try 1 after put(try_catch, 2) end, " "{X,get(try_catch)} end.", {1,2}), %% Match in of with after - ?line check(fun() -> X = try 1 of 1 -> 2 after put(try_catch, 3) end, + check(fun() -> X = try 1 of 1 -> 2 after put(try_catch, 3) end, {X,get(try_catch)} end, "begin X = try 1 of 1 -> 2 after put(try_catch, 3) end, " "{X,get(try_catch)} end.", {2,3}), - ?line check(fun() -> X = try 1 of 1 -> 2; 3 -> 4 + check(fun() -> X = try 1 of 1 -> 2; 3 -> 4 after put(try_catch, 5) end, {X,get(try_catch)} end, "begin X = try 1 of 1 -> 2; 3 -> 4 " " after put(try_catch, 5) end, " " {X,get(try_catch)} end.", {2,5}), - ?line check(fun() -> X = try 3 of 1 -> 2; 3 -> 4 + check(fun() -> X = try 3 of 1 -> 2; 3 -> 4 after put(try_catch, 5) end, {X,get(try_catch)} end, "begin X = try 3 of 1 -> 2; 3 -> 4 " " after put(try_catch, 5) end, " " {X,get(try_catch)} end.", {4,5}), %% Nomatch in of - ?line error_check("try 1 of 2 -> 3 catch _:_ -> 4 end.", + error_check("try 1 of 2 -> 3 catch _:_ -> 4 end.", {try_clause,1}), %% Nomatch in of with after - ?line check(fun () -> {'EXIT',{{try_clause,1},_}} = + check(fun () -> {'EXIT',{{try_clause,1},_}} = begin catch try 1 of 2 -> 3 after put(try_catch, 4) end end, get(try_catch) end, @@ -1336,14 +1267,14 @@ try_catch(Config) when is_list(Config) -> " after put(try_catch, 4) end end, " " get(try_catch) end. ", 4), %% Exception in try - ?line check(fun () -> try 1=2 catch error:{badmatch,2} -> 3 end end, + check(fun () -> try 1=2 catch error:{badmatch,2} -> 3 end end, "try 1=2 catch error:{badmatch,2} -> 3 end.", 3), - ?line check(fun () -> try 1=2 of 3 -> 4 + check(fun () -> try 1=2 of 3 -> 4 catch error:{badmatch,2} -> 5 end end, "try 1=2 of 3 -> 4 " "catch error:{badmatch,2} -> 5 end.", 5), %% Exception in try with after - ?line check(fun () -> X = try 1=2 + check(fun () -> X = try 1=2 catch error:{badmatch,2} -> 3 after put(try_catch, 4) end, {X,get(try_catch)} end, @@ -1351,7 +1282,7 @@ try_catch(Config) when is_list(Config) -> " catch error:{badmatch,2} -> 3 " " after put(try_catch, 4) end, " " {X,get(try_catch)} end. ", {3,4}), - ?line check(fun () -> X = try 1=2 of 3 -> 4 + check(fun () -> X = try 1=2 of 3 -> 4 catch error:{badmatch,2} -> 5 after put(try_catch, 6) end, {X,get(try_catch)} end, @@ -1360,12 +1291,12 @@ try_catch(Config) when is_list(Config) -> " after put(try_catch, 6) end, " " {X,get(try_catch)} end. ", {5,6}), %% Uncaught exception - ?line error_check("try 1=2 catch error:undefined -> 3 end. ", + error_check("try 1=2 catch error:undefined -> 3 end. ", {badmatch,2}), - ?line error_check("try 1=2 of 3 -> 4 catch error:undefined -> 5 end. ", + error_check("try 1=2 of 3 -> 4 catch error:undefined -> 5 end. ", {badmatch,2}), %% Uncaught exception with after - ?line check(fun () -> {'EXIT',{{badmatch,2},_}} = + check(fun () -> {'EXIT',{{badmatch,2},_}} = begin catch try 1=2 after put(try_catch, 3) end end, get(try_catch) end, @@ -1373,7 +1304,7 @@ try_catch(Config) when is_list(Config) -> " begin catch try 1=2 " " after put(try_catch, 3) end end, " " get(try_catch) end. ", 3), - ?line check(fun () -> {'EXIT',{{badmatch,2},_}} = + check(fun () -> {'EXIT',{{badmatch,2},_}} = begin catch try 1=2 of 3 -> 4 after put(try_catch, 5) end end, get(try_catch) end, @@ -1381,7 +1312,7 @@ try_catch(Config) when is_list(Config) -> " begin catch try 1=2 of 3 -> 4" " after put(try_catch, 5) end end, " " get(try_catch) end. ", 5), - ?line check(fun () -> {'EXIT',{{badmatch,2},_}} = + check(fun () -> {'EXIT',{{badmatch,2},_}} = begin catch try 1=2 catch error:undefined -> 3 after put(try_catch, 4) end end, get(try_catch) end, @@ -1389,7 +1320,7 @@ try_catch(Config) when is_list(Config) -> " begin catch try 1=2 catch error:undefined -> 3 " " after put(try_catch, 4) end end, " " get(try_catch) end. ", 4), - ?line check(fun () -> {'EXIT',{{badmatch,2},_}} = + check(fun () -> {'EXIT',{{badmatch,2},_}} = begin catch try 1=2 of 3 -> 4 catch error:undefined -> 5 after put(try_catch, 6) end end, @@ -1402,26 +1333,23 @@ try_catch(Config) when is_list(Config) -> ok. -eval_expr_5(doc) -> - ["(OTP-7933)"]; -eval_expr_5(suite) -> - []; +%% OTP-7933. eval_expr_5(Config) when is_list(Config) -> - ?line {ok,Tokens ,_} = + {ok,Tokens ,_} = erl_scan:string("if a+4 == 4 -> yes; true -> no end. "), - ?line {ok, [Expr]} = erl_parse:parse_exprs(Tokens), - ?line {value, no, []} = erl_eval:expr(Expr, [], none, none, none), - ?line no = erl_eval:expr(Expr, [], none, none, value), + {ok, [Expr]} = erl_parse:parse_exprs(Tokens), + {value, no, []} = erl_eval:expr(Expr, [], none, none, none), + no = erl_eval:expr(Expr, [], none, none, value), try erl_eval:expr(Expr, [], none, none, 4711), - ?line function_clause = should_never_reach_here + function_clause = should_never_reach_here catch error:function_clause -> ok end. zero_width(Config) when is_list(Config) -> - ?line check(fun() -> + check(fun() -> {'EXIT',{badarg,_}} = (catch <<not_a_number:0>>), ok end, "begin {'EXIT',{badarg,_}} = (catch <<not_a_number:0>>), " @@ -1524,7 +1452,7 @@ check1(F, String, Result) -> {value, Result, _} -> ok; Other -> - test_server:fail({eval, Other, Result}) + ct:fail({eval, Other, Result}) end. check(F, String, Result, BoundVars, LFH, EFH) -> @@ -1537,11 +1465,11 @@ check(F, String, Result, BoundVars, LFH, EFH) -> true -> ok; false -> - test_server:fail({check, BoundVars, Keys}) + ct:fail({check, BoundVars, Keys}) end, ok; Other -> - test_server:fail({check, Other, Result}) + ct:fail({check, Other, Result}) end. error_check(String, Result) -> @@ -1549,7 +1477,7 @@ error_check(String, Result) -> {'EXIT', {Result,_}} -> ok; Other -> - test_server:fail({eval, Other, Result}) + ct:fail({eval, Other, Result}) end. error_check(String, Result, LFH, EFH) -> @@ -1557,7 +1485,7 @@ error_check(String, Result, LFH, EFH) -> {'EXIT', {Result,_}} -> ok; Other -> - test_server:fail({eval, Other, Result}) + ct:fail({eval, Other, Result}) end. eval_string(String) -> diff --git a/lib/stdlib/test/erl_expand_records_SUITE.erl b/lib/stdlib/test/erl_expand_records_SUITE.erl index 2cc4757c04..7fed7fce56 100644 --- a/lib/stdlib/test/erl_expand_records_SUITE.erl +++ b/lib/stdlib/test/erl_expand_records_SUITE.erl @@ -20,7 +20,7 @@ -module(erl_expand_records_SUITE). -%-define(debug, true). +%%-define(debug, true). -ifdef(debug). -define(line, put(line, ?LINE), ). @@ -29,7 +29,7 @@ -define(t, test_server). -else. -include_lib("common_test/include/ct.hrl"). --define(privdir, ?config(priv_dir, Config)). +-define(privdir, proplists:get_value(priv_dir, Config)). -endif. -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, @@ -41,19 +41,15 @@ otp_5915/1, otp_7931/1, otp_5990/1, otp_7078/1, otp_7101/1, maps/1]). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(1)). - init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. + Config. end_per_testcase(_Case, _Config) -> - Dog = ?config(watchdog, _Config), - test_server:timetrap_cancel(Dog), ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [attributes, expr, guard, init, @@ -76,30 +72,26 @@ end_per_group(_GroupName, Config) -> Config. -attributes(doc) -> - "Import module and functions."; -attributes(suite) -> []; +%% Import module and functions. attributes(Config) when is_list(Config) -> Ts = [ - <<"-import(lists, [append/2, reverse/1]). + <<"-import(lists, [append/2, reverse/1]). -record(r, {a,b}). - t() -> - [2,1] = reverse(append([1],[2])), - 3 = length([1,2,3]), - 3 = record_info(size, r), - [a, b] = record_info(fields, r), - [] = erl_expand_records_SUITE:attributes(suite), - ok. - ">> +t() -> + [2,1] = reverse(append([1],[2])), + 3 = length([1,2,3]), + 3 = record_info(size, r), + [a, b] = record_info(fields, r), + [_|_] = erl_expand_records_SUITE:all(), + ok. +">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -expr(doc) -> - "Some expressions."; -expr(suite) -> []; +%% Some expressions. expr(Config) when is_list(Config) -> Ts = [ <<" @@ -159,14 +151,12 @@ expr(Config) when is_list(Config) -> %% The code above should run equally well with and without %% strict record tests. - ?line run(Config, Ts, [no_strict_record_tests]), - ?line run(Config, Ts, [strict_record_tests]), + run(Config, Ts, [no_strict_record_tests]), + run(Config, Ts, [strict_record_tests]), ok. -guard(doc) -> - "is_record in guards."; -guard(suite) -> []; +%% is_record in guards. guard(Config) when is_list(Config) -> File = filename("guard.erl", Config), Beam = filename("guard.beam", Config), @@ -202,18 +192,16 @@ guard(Config) when is_list(Config) -> 12. ">>, - ?line ok = file:write_file(File, Test), - ?line {ok, guard, Ws} = compile:file(File, [return,{outdir,?privdir}]), - ?line Warnings = [L || {_File,WL} <- Ws, {L,_M,nomatch_guard} <- WL], - ?line [7,9,11,13,15,17,19,21,23,25,27] = Warnings, + ok = file:write_file(File, Test), + {ok, guard, Ws} = compile:file(File, [return,{outdir,?privdir}]), + Warnings = [L || {_File,WL} <- Ws, {L,_M,nomatch_guard} <- WL], + [7,9,11,13,15,17,19,21,23,25,27] = Warnings, - ?line ok = file:delete(File), - ?line ok = file:delete(Beam), + ok = file:delete(File), + ok = file:delete(Beam), ok. -init(doc) -> - "Wildcard initialisation."; -init(suite) -> []; +%% Wildcard initialisation. init(Config) when is_list(Config) -> Ts = [ <<" @@ -228,12 +216,10 @@ init(Config) when is_list(Config) -> end. ">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -pattern(doc) -> - "Some patterns."; -pattern(suite) -> []; +%% Some patterns. pattern(Config) when is_list(Config) -> Ts = [ <<"-import(lists, [append/2, reverse/1]). @@ -317,12 +303,9 @@ pattern(Config) when is_list(Config) -> 16. ">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -strict(doc) -> - ""; -strict(suite) -> []; strict(Config) when is_list(Config) -> Ts1 = [ <<"-record(r1, {a,b}). @@ -345,7 +328,7 @@ strict(Config) when is_list(Config) -> error(wrong_element). ">> ], - ?line run(Config, Ts1, [strict_record_tests]), + run(Config, Ts1, [strict_record_tests]), Ts2 = [ <<"-record(r1, {a,b}). @@ -361,12 +344,10 @@ strict(Config) when is_list(Config) -> error(wrong_element). ">> ], - ?line run(Config, Ts2, [no_strict_record_tests]), + run(Config, Ts2, [no_strict_record_tests]), ok. -update(doc) -> - "Record updates."; -update(suite) -> []; +%% Record updates. update(Config) when is_list(Config) -> Ts = [ <<"-record(r, {a,b,c,d,e,f}). @@ -401,7 +382,7 @@ update(Config) when is_list(Config) -> erlang:error(wrong_setelement_called). ">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. maps(Config) when is_list(Config) -> @@ -420,9 +401,7 @@ maps(Config) when is_list(Config) -> run(Config, Ts, [strict_record_tests]), ok. -otp_5915(doc) -> - "Strict record tests in guards."; -otp_5915(suite) -> []; +%% Strict record tests in guards. otp_5915(Config) when is_list(Config) -> %% These tests are also run by the compiler's record_SUITE. Ts = [ @@ -565,12 +544,10 @@ otp_5915(Config) when is_list(Config) -> ok. ">> ], - ?line run(Config, Ts, [strict_record_tests]), + run(Config, Ts, [strict_record_tests]), ok. -otp_7931(doc) -> - "Test optimization of record accesses and is_record/3 tests in guards"; -otp_7931(suite) -> []; +%% Test optimization of record accesses and is_record/3 tests in guards. otp_7931(Config) when is_list(Config) -> Ts = [ <<"-record(r, {a = 4,b}). @@ -654,12 +631,10 @@ otp_7931(Config) when is_list(Config) -> ok. ">> ], - ?line run(Config, Ts, [strict_record_tests]), + run(Config, Ts, [strict_record_tests]), ok. -otp_5990(doc) -> - "OTP-5990. {erlang,is_record}."; -otp_5990(suite) -> []; +%% OTP-5990. {erlang,is_record}. otp_5990(Config) when is_list(Config) -> Ts = [ <<" @@ -690,13 +665,11 @@ otp_5990(Config) when is_list(Config) -> ok. ">> ], - ?line run(Config, Ts, [strict_record_tests]), + run(Config, Ts, [strict_record_tests]), ok. -otp_7078(doc) -> - "OTP-7078. Record update: missing test."; -otp_7078(suite) -> []; +%% OTP-7078. Record update: missing test. otp_7078(Config) when is_list(Config) -> Ts = [ <<" @@ -724,14 +697,12 @@ otp_7078(Config) when is_list(Config) -> ">> ], - ?line run(Config, Ts, [strict_record_tests]), + run(Config, Ts, [strict_record_tests]), ok. -record(otp_7101, {a,b,c=[],d=[],e=[]}). -otp_7101(doc) -> - "OTP-7101. Record update: more than one call to setelement/3."; -otp_7101(suite) -> []; +%% OTP-7101. Record update: more than one call to setelement/3. otp_7101(Config) when is_list(Config) -> Rec = #otp_7101{}, @@ -739,28 +710,28 @@ otp_7101(Config) when is_list(Config) -> %% The tracer will forward all trace messages to us. Self = self(), Tracer = spawn_link(fun() -> otp_7101_tracer(Self, 0) end), - ?line 1 = erlang:trace_pattern({erlang,setelement,3}, true), - ?line erlang:trace(self(), true, [{tracer,Tracer},call]), + 1 = erlang:trace_pattern({erlang,setelement,3}, true), + erlang:trace(self(), true, [{tracer,Tracer},call]), %% Update the record. - ?line #otp_7101{a=2,b=1,c=[],d=[],e=[]} = otp_7101_update1(Rec), - ?line #otp_7101{a=1,b=2,c=[],d=[],e=[]} = otp_7101_update2(Rec), - ?line #otp_7101{a=2,b=1,c=[],d=[],e=[]} = otp_7101_update3(Rec), - ?line #otp_7101{a=1,b=2,c=[],d=[],e=[]} = otp_7101_update4(Rec), + #otp_7101{a=2,b=1,c=[],d=[],e=[]} = otp_7101_update1(Rec), + #otp_7101{a=1,b=2,c=[],d=[],e=[]} = otp_7101_update2(Rec), + #otp_7101{a=2,b=1,c=[],d=[],e=[]} = otp_7101_update3(Rec), + #otp_7101{a=1,b=2,c=[],d=[],e=[]} = otp_7101_update4(Rec), %% Verify that setelement/3 was called the same number of times as %% the number of record updates. - ?line Ref = erlang:trace_delivered(Self), + Ref = erlang:trace_delivered(Self), receive {trace_delivered, Self, Ref} -> Tracer ! done end, - ?line 1 = erlang:trace_pattern({erlang,setelement,3}, false), + 1 = erlang:trace_pattern({erlang,setelement,3}, false), receive 4 -> ok; Other -> - ?line ?t:fail({unexpected,Other}) + ct:fail({unexpected,Other}) end. otp_7101_tracer(Parent, N) -> @@ -797,10 +768,9 @@ run(Config, Tests, Opts) -> AbsFile = filename:rootname(SourceFile, ".erl"), code:purge(Mod), code:load_abs(AbsFile, Mod), -%io:format("run~n"), case catch Mod:t() of {'EXIT', _Reason} = Error -> - ?t:format("failed, got ~p~n", [Error]), + io:format("failed, got ~p~n", [Error]), fail(); ok -> ok @@ -837,5 +807,4 @@ warnings(File, Ws) -> end. fail() -> - io:format("failed~n"), - ?t:fail(). + ct:fail(failed). diff --git a/lib/stdlib/test/erl_internal_SUITE.erl b/lib/stdlib/test/erl_internal_SUITE.erl index ad0b37aae3..45e67226b7 100644 --- a/lib/stdlib/test/erl_internal_SUITE.erl +++ b/lib/stdlib/test/erl_internal_SUITE.erl @@ -28,7 +28,9 @@ -include_lib("common_test/include/ct.hrl"). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,2}}]. all() -> [behav]. @@ -49,20 +51,13 @@ end_per_group(_GroupName, Config) -> Config. --define(default_timeout, ?t:minutes(2)). - init_per_testcase(_Case, Config) -> - Dog = test_server:timetrap(?default_timeout), - [{watchdog, Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. -behav(suite) -> []; -behav(doc) -> - ["Check that the behaviour callbacks are correctly defined"]; +%% Check that the behaviour callbacks are correctly defined. behav(_) -> Modules = [application, gen_server, gen_fsm, gen_event, supervisor_bridge, supervisor], diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl index d946469625..29a389d4b8 100644 --- a/lib/stdlib/test/erl_lint_SUITE.erl +++ b/lib/stdlib/test/erl_lint_SUITE.erl @@ -19,7 +19,7 @@ %% -module(erl_lint_SUITE). -%-define(debug, true). +%%-define(debug, true). -ifdef(debug). -define(line, put(line, ?LINE), ). @@ -29,8 +29,8 @@ -define(t, test_server). -else. -include_lib("common_test/include/ct.hrl"). --define(datadir, ?config(data_dir, Conf)). --define(privdir, ?config(priv_dir, Conf)). +-define(datadir, proplists:get_value(data_dir, Conf)). +-define(privdir, proplists:get_value(priv_dir, Conf)). -endif. -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, @@ -69,19 +69,15 @@ record_errors/1 ]). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(1)). - init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. + Config. end_per_testcase(_Case, _Config) -> - Dog = ?config(watchdog, _Config), - test_server:timetrap_cancel(Dog), ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [{group, unused_vars_warn}, export_vars_warn, @@ -119,50 +115,48 @@ end_per_group(_GroupName, Config) -> -unused_vars_warn_basic(doc) -> - "Warnings for unused variables in some simple cases."; -unused_vars_warn_basic(suite) -> []; +%% Warnings for unused variables in some simple cases. unused_vars_warn_basic(Config) when is_list(Config) -> Ts = [{basic1, <<"f(F) -> % F unused. ok. - f(F, F) -> - ok. +f(F, F) -> + ok. - g(_X) -> - y. +g(_X) -> + y. - h(P) -> - P. +h(P) -> + P. - x(N) -> - case a:b() of - [N|Y] -> % Y unused. - ok - end. +x(N) -> + case a:b() of + [N|Y] -> % Y unused. + ok + end. - y(N, L) -> - lists:map(fun(T) -> T*N end, L). +y(N, L) -> + lists:map(fun(T) -> T*N end, L). - z(N, L) -> % N unused - lists:map(fun(N, T) -> T*N end, L). % N shadowed. +z(N, L) -> % N unused + lists:map(fun(N, T) -> T*N end, L). % N shadowed. - c(A) -> - case A of - 1 -> B = []; % B unused. - 2 -> B = []; % B unused. - 3 -> B = f, B - end. - ">>, +c(A) -> + case A of + 1 -> B = []; % B unused. + 2 -> B = []; % B unused. + 3 -> B = f, B + end. +">>, [warn_unused_vars], - {warnings,[{1,erl_lint,{unused_var,'F'}}, - {15,erl_lint,{unused_var,'Y'}}, - {22,erl_lint,{unused_var,'N'}}, - {23,erl_lint,{shadowed_var,'N','fun'}}, - {28,erl_lint,{unused_var,'B'}}, - {29,erl_lint,{unused_var,'B'}}]}}, +{warnings,[{1,erl_lint,{unused_var,'F'}}, + {15,erl_lint,{unused_var,'Y'}}, + {22,erl_lint,{unused_var,'N'}}, + {23,erl_lint,{shadowed_var,'N','fun'}}, + {28,erl_lint,{unused_var,'B'}}, + {29,erl_lint,{unused_var,'B'}}]}}, {basic2, <<"-record(r, {x,y}). f({X,Y}) -> {Z=X,Z=Y}; @@ -172,12 +166,10 @@ unused_vars_warn_basic(Config) when is_list(Config) -> g({M, F, Arg}) -> (Z=M):F(Z=Arg). h(X, Y) -> (Z=X) + (Z=Y).">>, [warn_unused_vars], []}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -unused_vars_warn_lc(doc) -> - "Warnings for unused variables in list comprehensions."; -unused_vars_warn_lc(suite) -> []; +%% Warnings for unused variables in list comprehensions. unused_vars_warn_lc(Config) when is_list(Config) -> Ts = [{lc1, <<"bin([X]) -> @@ -404,9 +396,7 @@ unused_vars_warn_lc(Config) when is_list(Config) -> {error,[{22,erl_lint,{unsafe_var,'U',{'case',2}}}, {27,erl_lint,{unsafe_var,'U',{'case',2}}}], [{16,erl_lint,{unused_var,'Y'}}, - % {24,erl_lint,{exported_var,'X',{'case',8}}}, {24,erl_lint,{unused_var,'U'}}, - % {26,erl_lint,{exported_var,'X',{'case',8}}}, {26,erl_lint,{unused_var,'U'}}]}}, {lc17, @@ -436,7 +426,6 @@ unused_vars_warn_lc(Config) when is_list(Config) -> [warn_unused_vars], {error,[{22,erl_lint,{unsafe_var,'U',{'case',3}}}], [{17,erl_lint,{unused_var,'Y'}}, - % {21,erl_lint,{exported_var,'X',{'case',9}}}, {21,erl_lint,{unused_var,'U'}}]}}, {lc18, @@ -461,14 +450,12 @@ unused_vars_warn_lc(Config) when is_list(Config) -> end, [B || <<U: % U unused U>> <- X, <<B:Y>> <- Z]. % U unsafe. Y unsafe. - % U shadowed. (X exported.) + % U shadowed. (X exported.) ">>, [warn_unused_vars], {error,[{21,erl_lint,{unsafe_var,'U',{'case',2}}}, {21,erl_lint,{unsafe_var,'Y',{'case',14}}}], [{20,erl_lint,{unused_var,'U'}} - % ,{21,erl_lint,{exported_var,'X',{'case',8}}} - % ,{21,erl_lint,{shadowed_var,'U',generate}} ]}}, {lc19, @@ -522,13 +509,11 @@ unused_vars_warn_lc(Config) when is_list(Config) -> [{14,erl_lint,{unused_var,'Q'}}]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -unused_vars_warn_rec(doc) -> - "Warnings for unused variables in records."; -unused_vars_warn_rec(suite) -> []; +%% Warnings for unused variables in records. unused_vars_warn_rec(Config) when is_list(Config) -> Ts = [{rec1, % An example provided by Bjorn. <<"-record(edge, @@ -580,12 +565,10 @@ unused_vars_warn_rec(Config) when is_list(Config) -> {error,[{2,erl_lint,{redefine_field,r,a}}, {2,erl_lint,{redefine_field,r,a}}], [{2,erl_lint,{unused_var,'X'}}]}}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -unused_vars_warn_fun(doc) -> - "Warnings for unused variables in funs."; -unused_vars_warn_fun(suite) -> []; +%% Warnings for unused variables in funs. unused_vars_warn_fun(Config) when is_list(Config) -> Ts = [{fun1, <<"a({A,B}) -> % A unused. @@ -707,12 +690,10 @@ unused_vars_warn_fun(Config) when is_list(Config) -> {33,erl_lint,{unused_var,'U'}}, {33,erl_lint,{shadowed_var,'U','fun'}}]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -unused_vars_OTP_4858(doc) -> - "Bit syntax, binsize variable used in the same matching."; -unused_vars_OTP_4858(suite) -> []; +%% Bit syntax, binsize variable used in the same matching. unused_vars_OTP_4858(Config) when is_list(Config) -> Ts = [{otp_4858, <<"objs(<<Size:4/unit:8, B:Size/binary>>) -> @@ -731,7 +712,7 @@ unused_vars_OTP_4858(Config) when is_list(Config) -> {8,erl_lint,{unused_var,'B'}}, {8,erl_lint,{unused_var,'Rest'}}]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. unused_unsafe_vars_warn(Config) when is_list(Config) -> @@ -776,9 +757,7 @@ unused_unsafe_vars_warn(Config) when is_list(Config) -> run(Config, Ts), ok. -export_vars_warn(doc) -> - "Warnings for exported variables"; -export_vars_warn(suite) -> []; +%% Warnings for exported variables. export_vars_warn(Config) when is_list(Config) -> Ts = [{exp1, <<"u() -> @@ -868,13 +847,11 @@ export_vars_warn(Config) when is_list(Config) -> [], {warnings,[{7,erl_lint,{exported_var,'Z',{'if',2}}}]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -shadow_vars(doc) -> - "Shadowed variables are tested in other places, but here we test " - "that the warning can be turned off."; -shadow_vars(suite) -> []; +%% Shadowed variables are tested in other places, but here we test +%% that the warning can be turned off. shadow_vars(Config) when is_list(Config) -> Ts = [{shadow1, <<"bin(A) -> @@ -899,12 +876,10 @@ shadow_vars(Config) when is_list(Config) -> ">>, [], []}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -unused_import(doc) -> - "Test that the 'warn_unused_import' option works."; -unused_import(suite) -> []; +%% Test that the 'warn_unused_import' option works. unused_import(Config) when is_list(Config) -> Ts = [{imp1, <<"-import(lists, [map/2,foldl/3]). @@ -913,12 +888,10 @@ unused_import(Config) when is_list(Config) -> ">>, [warn_unused_import], {warnings,[{1,erl_lint,{unused_import,{{foldl,3},lists}}}]}}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -unused_function(doc) -> - "Test warnings for unused functions."; -unused_function(suite) -> []; +%% Test warnings for unused functions. unused_function(Config) when is_list(Config) -> Ts = [{func1, <<"-export([t/1]). @@ -961,12 +934,10 @@ unused_function(Config) when is_list(Config) -> {[]}, %Tuple indicates no 'export_all'. []}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -unsafe_vars(doc) -> - "OTP-4671. Errors for unsafe variables"; -unsafe_vars(suite) -> []; +%% OTP-4671. Errors for unsafe variables. unsafe_vars(Config) when is_list(Config) -> Ts = [{unsafe1, <<"t() -> @@ -1042,7 +1013,7 @@ unsafe_vars(Config) when is_list(Config) -> D = 1; 2 -> A = 2, - % B not bound here + %% B not bound here C = 2, catch D = 2; % unsafe in two clauses 3 -> @@ -1064,12 +1035,10 @@ unsafe_vars(Config) when is_list(Config) -> {24,erl_lint,{unsafe_var,'D',{'case',2}}}], []}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -unsafe_vars2(doc) -> - "OTP-4831, seq8202. No warn_unused_vars and unsafe variables"; -unsafe_vars2(suite) -> []; +%% OTP-4831, seq8202. No warn_unused_vars and unsafe variables. unsafe_vars2(Config) when is_list(Config) -> Ts = [{unsafe2_1, <<"foo(State) -> @@ -1098,12 +1067,10 @@ unsafe_vars2(Config) when is_list(Config) -> [], {errors,[{9,erl_lint,{unsafe_var,'State1',{'if',4}}}],[]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -unsafe_vars_try(doc) -> - "Errors for unsafe variables in try/catch constructs."; -unsafe_vars_try(suite) -> []; +%% Errors for unsafe variables in try/catch constructs. unsafe_vars_try(Config) when is_list(Config) -> Ts = [{unsafe_try1, <<"foo2() -> @@ -1288,12 +1255,10 @@ unsafe_vars_try(Config) when is_list(Config) -> ">>, [], {errors,[{13,erl_lint,{unsafe_var,'Acc',{'try',6}}}],[]}}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -unsized_binary_in_bin_gen_pattern(doc) -> - "Unsized binary fields are forbidden in patterns of bit string generators"; -unsized_binary_in_bin_gen_pattern(suite) -> []; +%% Unsized binary fields are forbidden in patterns of bit string generators. unsized_binary_in_bin_gen_pattern(Config) when is_list(Config) -> Ts = [{unsized_binary_in_bin_gen_pattern, <<"t({bc,binary,Bin}) -> @@ -1326,9 +1291,7 @@ unsized_binary_in_bin_gen_pattern(Config) when is_list(Config) -> [] = run(Config, Ts), ok. -guard(doc) -> - "OTP-4670. Guards, is_record in particular."; -guard(suite) -> []; +%% OTP-4670. Guards, is_record in particular. guard(Config) when is_list(Config) -> %% Well, these could be plain code... Ts = [{guard1, @@ -1543,7 +1506,7 @@ guard(Config) when is_list(Config) -> ">>, [nowarn_obsolete_guard], []}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), Ts1 = [{guard5, <<"-record(apa, {}). t3(A) when record(A, {apa}) -> @@ -1614,12 +1577,10 @@ guard(Config) when is_list(Config) -> {2,erl_lint,illegal_guard_expr}], []}} ], - ?line [] = run(Config, Ts1), + [] = run(Config, Ts1), ok. -otp_4886(doc) -> - "OTP-4886. Calling is_record with given record name."; -otp_4886(suite) -> []; +%% OTP-4886. Calling is_record with given record name. otp_4886(Config) when is_list(Config) -> Ts = [{otp_4886, <<"t() -> @@ -1638,12 +1599,10 @@ otp_4886(Config) when is_list(Config) -> {4,erl_lint,{undefined_record,foo}}, {5,erl_lint,{undefined_record,foo}}], []}}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_4988(doc) -> - "OTP-4988. Error when in-lining non-existent functions."; -otp_4988(suite) -> []; +%% OTP-4988. Error when in-lining non-existent functions. otp_4988(Config) when is_list(Config) -> Ts = [{otp_4988, <<"-compile({inline, [{f,3},{f,4},{f,2},{f,a},{1,foo}]}). @@ -1665,12 +1624,10 @@ otp_4988(Config) when is_list(Config) -> {1,erl_lint,{bad_inline,{f,a}}}, {3,erl_lint,{bad_inline,{g,12}}}], []}}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_5091(doc) -> - "OTP-5091. Patterns and the bit syntax: invalid warnings."; -otp_5091(suite) -> []; +%% OTP-5091. Patterns and the bit syntax: invalid warnings. otp_5091(Config) when is_list(Config) -> Ts = [{otp_5091_1, <<"t() -> @@ -1883,12 +1840,10 @@ otp_5091(Config) when is_list(Config) -> <<"-record(r, {f1,f2}). t(#r{f1 = A, f2 = A}) -> a.">>, [], []}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_5276(doc) -> - "OTP-5276. Check the 'deprecated' attributed."; -otp_5276(suite) -> []; +%% OTP-5276. Check the 'deprecated' attributed. otp_5276(Config) when is_list(Config) -> Ts = [{otp_5276_1, <<"-deprecated([{frutt,0,next_version}]). @@ -1915,12 +1870,10 @@ otp_5276(Config) when is_list(Config) -> {9,erl_lint,{invalid_deprecated,{{badly,formed},1}}}, {11,erl_lint,{bad_deprecated,{atom_to_list,1}}}], [{13,erl_lint,{unused_function,{frutt,0}}}]}}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_5917(doc) -> - "OTP-5917. Check the 'deprecated' attributed."; -otp_5917(suite) -> []; +%% OTP-5917. Check the 'deprecated' attributed. otp_5917(Config) when is_list(Config) -> Ts = [{otp_5917_1, <<"-compile(export_all). @@ -1932,12 +1885,10 @@ otp_5917(Config) when is_list(Config) -> ">>, {[]}, []}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_6585(doc) -> - "OTP-6585. Check the deprecated guards list/1, pid/1, ...."; -otp_6585(suite) -> []; +%% OTP-6585. Check the deprecated guards list/1, pid/1, .... otp_6585(Config) when is_list(Config) -> Ts = [{otp_6585_1, <<"-compile(export_all). @@ -1955,12 +1906,10 @@ otp_6585(Config) when is_list(Config) -> {warnings,[{5,erl_lint,{obsolete_guard,{list,1}}}, {6,erl_lint,{obsolete_guard,{record,2}}}, {7,erl_lint,{obsolete_guard,{pid,1}}}]}}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_5338(doc) -> - "OTP-5338. Bad warning in record initialization."; -otp_5338(suite) -> []; +%% OTP-5338. Bad warning in record initialization. otp_5338(Config) when is_list(Config) -> %% OTP-5878: variables like X are no longer allowed in initialisations Ts = [{otp_5338, @@ -1972,13 +1921,11 @@ otp_5338(Config) when is_list(Config) -> [], {error,[{1,erl_lint,{unbound_var,'X'}}], [{3,erl_lint,{unused_var,'X'}}]}}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_5362(doc) -> - "OTP-5362. deprecated_function, " - "{nowarn_unused_funtion,FAs}, 'better' line numbers."; -otp_5362(suite) -> []; +%% OTP-5362. deprecated_function, +%% {nowarn_unused_funtion,FAs}, 'better' line numbers. otp_5362(Config) when is_list(Config) -> Ts = [{otp_5362_1, <<"-include_lib(\"stdlib/include/qlc.hrl\"). @@ -2178,12 +2125,10 @@ otp_5362(Config) when is_list(Config) -> ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_5371(doc) -> - "OTP-5371. Aliases for bit syntax expressions are no longer allowed."; -otp_5371(suite) -> []; +%% OTP-5371. Aliases for bit syntax expressions are no longer allowed. otp_5371(Config) when is_list(Config) -> Ts = [{otp_5371_1, <<"t(<<A:8>> = <<B:8>>) -> @@ -2237,10 +2182,10 @@ otp_5371(Config) when is_list(Config) -> {6,v3_core,nomatch}, {8,v3_core,nomatch}]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_7227(doc) -> "OTP_7227. Some aliases for bit syntax expressions were still allowed."; +%% OTP_7227. Some aliases for bit syntax expressions were still allowed. otp_7227(Config) when is_list(Config) -> Ts = [{otp_7227_1, <<"t([<<A:8>> = {C,D} = <<B:8>>]) -> @@ -2307,12 +2252,10 @@ otp_7227(Config) when is_list(Config) -> [], {errors,[{2,erl_lint,illegal_bin_pattern}],[]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_5494(doc) -> - "OTP-5494. Warnings for functions exported more than once."; -otp_5494(suite) -> []; +%% OTP-5494. Warnings for functions exported more than once. otp_5494(Config) when is_list(Config) -> Ts = [{otp_5494_1, <<"-export([t/0]). @@ -2321,12 +2264,10 @@ otp_5494(Config) when is_list(Config) -> ">>, [], {warnings,[{2,erl_lint,{duplicated_export,{t,0}}}]}}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_5644(doc) -> - "OTP-5644. M:F/A in record initialization."; -otp_5644(suite) -> []; +%% OTP-5644. M:F/A in record initialization. otp_5644(Config) when is_list(Config) -> %% This test is a no-op. Although {function,mfa,i,1} was %% transformed into {function,Line,i,1} by copy_expr, the module @@ -2342,12 +2283,10 @@ otp_5644(Config) when is_list(Config) -> ">>, [], []}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_5878(doc) -> - "OTP-5878. Record declaration: forward references, introduced variables."; -otp_5878(suite) -> []; +%% OTP-5878. Record declaration: forward references, introduced variables. otp_5878(Config) when is_list(Config) -> Ts = [{otp_5878_10, <<"-record(rec1, {a = #rec2{}}). @@ -2463,7 +2402,7 @@ otp_5878(Config) when is_list(Config) -> [{1,erl_lint,{unused_record,r}}]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), Abstr = <<"-module(lint_test, [A, B]). ">>, @@ -2480,7 +2419,7 @@ otp_5878(Config) when is_list(Config) -> X <- Z ++ [A,Y]])}). t() -> {#r1{},#r2{},#r3{}}. ">>, - ?line {error,[{8,qlc,{used_generator_variable,'A'}}, + {error,[{8,qlc,{used_generator_variable,'A'}}, {8,qlc,{used_generator_variable,'Y'}}, {8,qlc,{used_generator_variable,'Z'}}], [{6,erl_lint,{unused_var,'V'}}]} = @@ -2521,7 +2460,7 @@ otp_5878(Config) when is_list(Config) -> bar. ">>, - ?line {errors,[{6,erl_lint,{unbound_var,'A'}}, + {errors,[{6,erl_lint,{unbound_var,'A'}}, {13,erl_lint,illegal_guard_expr}, {15,erl_lint,{undefined_field,r3,q}}, {17,erl_lint,{undefined_field,r,q}}, @@ -2540,14 +2479,14 @@ otp_5878(Config) when is_list(Config) -> foo end. ">>, - ?line {errors,[{4,erl_lint,{undefined_function,{x,0}}}, + {errors,[{4,erl_lint,{undefined_function,{x,0}}}, {5,erl_lint,illegal_guard_expr}, {7,erl_lint,illegal_guard_expr}], []} = run_test2(Config, Ill2, [warn_unused_record]), Ill3 = <<"t() -> ok.">>, - ?line {errors,[{1,erl_lint,undefined_module}],[]} = + {errors,[{1,erl_lint,undefined_module}],[]} = run_test2(Config, Ill3, [warn_unused_record]), Usage1 = <<"-module(lint_test). @@ -2560,7 +2499,7 @@ otp_5878(Config) when is_list(Config) -> t() -> {#u2{}}. ">>, - ?line {warnings,[{5,erl_lint,{unused_record,u3}}, + {warnings,[{5,erl_lint,{unused_record,u3}}, {6,erl_lint,{unused_record,u4}}]} = run_test2(Config, Usage1, [warn_unused_record]), @@ -2575,7 +2514,7 @@ otp_5878(Config) when is_list(Config) -> t() -> {#u2{}}. ">>, - ?line [] = run_test2(Config, Usage2, [warn_unused_record]), + [] = run_test2(Config, Usage2, [warn_unused_record]), %% This a completely different story... %% The linter checks if qlc.hrl hasn't been included @@ -2589,7 +2528,7 @@ otp_5878(Config) when is_list(Config) -> H3 = q([X || X <- [1,2]], []), {H1,H2,H3}. ">>, - ?line {warnings,[{6,erl_lint,{missing_qlc_hrl,1}}, + {warnings,[{6,erl_lint,{missing_qlc_hrl,1}}, {7,erl_lint,{missing_qlc_hrl,2}}, {8,erl_lint,{missing_qlc_hrl,2}}]} = run_test2(Config, QLC2, [warn_unused_record]), @@ -2605,7 +2544,7 @@ otp_5878(Config) when is_list(Config) -> foo(#request{}) -> ok. ">>, - ?line [] = run_test2(Config, UsedByType, [warn_unused_record]), + [] = run_test2(Config, UsedByType, [warn_unused_record]), %% Abstract code generated by OTP 18. Note that the type info for %% record fields has been put in a separate form. @@ -2626,9 +2565,8 @@ otp_5878(Config) when is_list(Config) -> ok. -otp_6885(doc) -> - "OTP-6885. Binary fields in bit syntax matching is now only allowed at the end."; -otp_6885(suite) -> []; +%% OTP-6885. Binary fields in bit syntax matching is now only +%% allowed at the end. otp_6885(Config) when is_list(Config) -> Ts = <<"-module(otp_6885). -export([t/1]). @@ -2655,7 +2593,7 @@ otp_6885(Config) when is_list(Config) -> ok. ">>, - ?line {errors,[{3,erl_lint,unsized_binary_not_at_end}, + {errors,[{3,erl_lint,unsized_binary_not_at_end}, {4,erl_lint,unsized_binary_not_at_end}, {5,erl_lint,unsized_binary_not_at_end}, {10,erl_lint,typed_literal_string}, @@ -2665,9 +2603,7 @@ otp_6885(Config) when is_list(Config) -> []} = run_test2(Config, Ts, []), ok. -otp_10436(doc) -> - "OTP-6885. Warnings for opaque types."; -otp_10436(suite) -> []; +%% OTP-6885. Warnings for opaque types. otp_10436(Config) when is_list(Config) -> Ts = <<"-module(otp_10436). -export_type([t1/0]). @@ -2687,9 +2623,7 @@ otp_10436(Config) when is_list(Config) -> run_test2(Config, Ts2, []), ok. -otp_11254(doc) -> - "OTP-11254. M:F/A could crash the linter."; -otp_11254(suite) -> []; +%% OTP-11254. M:F/A could crash the linter. otp_11254(Config) when is_list(Config) -> Ts = <<"-module(p2). -export([manifest/2]). @@ -2701,9 +2635,7 @@ otp_11254(Config) when is_list(Config) -> run_test2(Config, Ts, []), ok. -otp_11772(doc) -> - "OTP-11772. Reintroduce errors for redefined builtin types."; -otp_11772(suite) -> []; +%% OTP-11772. Reintroduce errors for redefined builtin types. otp_11772(Config) when is_list(Config) -> Ts = <<" -module(newly). @@ -2728,9 +2660,7 @@ otp_11772(Config) when is_list(Config) -> []} = run_test2(Config, Ts, []), ok. -otp_11771(doc) -> - "OTP-11771. Do not allow redefinition of the types arity(_) &c.."; -otp_11771(suite) -> []; +%% OTP-11771. Do not allow redefinition of the types arity(_) &c.. otp_11771(Config) when is_list(Config) -> Ts = <<" -module(newly). @@ -2757,9 +2687,7 @@ otp_11771(Config) when is_list(Config) -> []} = run_test2(Config, Ts, []), ok. -otp_11872(doc) -> - "OTP-11872. The type map() undefined when exported."; -otp_11872(suite) -> []; +%% OTP-11872. The type map() undefined when exported. otp_11872(Config) when is_list(Config) -> Ts = <<" -module(map). @@ -2781,22 +2709,19 @@ otp_11872(Config) when is_list(Config) -> run_test2(Config, Ts, []), ok. -export_all(doc) -> - "OTP-7392. Warning for export_all."; +%% OTP-7392. Warning for export_all. export_all(Config) when is_list(Config) -> Ts = <<"-module(export_all_module). -compile([export_all]). id(I) -> I. ">>, - ?line [] = run_test2(Config, Ts, []), - ?line {warnings,[{2,erl_lint,export_all}]} = + [] = run_test2(Config, Ts, []), + {warnings,[{2,erl_lint,export_all}]} = run_test2(Config, Ts, [warn_export_all]), ok. -bif_clash(doc) -> - "Test warnings for functions that clash with BIFs."; -bif_clash(suite) -> []; +%% Test warnings for functions that clash with BIFs. bif_clash(Config) when is_list(Config) -> Ts = [{clash1, <<"t(X) -> @@ -3063,12 +2988,10 @@ bif_clash(Config) when is_list(Config) -> []} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -behaviour_basic(doc) -> - "Basic tests with one behaviour."; -behaviour_basic(suite) -> []; +%% Basic tests with one behaviour. behaviour_basic(Config) when is_list(Config) -> Ts = [{behaviour1, <<"-behaviour(application). @@ -3102,12 +3025,10 @@ behaviour_basic(Config) when is_list(Config) -> [], {warnings,[{1,erl_lint,{undefined_behaviour_func,{start,2},application}}]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -behaviour_multiple(doc) -> - "Basic tests with multiple behaviours."; -behaviour_multiple(suite) -> []; +%% Basic tests with multiple behaviours. behaviour_multiple(Config) when is_list(Config) -> Ts = [{behaviour1, <<"-behaviour(application). @@ -3205,12 +3126,10 @@ behaviour_multiple(Config) when is_list(Config) -> erl_lint, {conflicting_behaviours,{init,1},supervisor,1,gen_server}}]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_11861(doc) -> - "OTP-11861. behaviour_info() and -callback."; -otp_11861(suite) -> []; +%% OTP-11861. behaviour_info() and -callback. otp_11861(Conf) when is_list(Conf) -> CallbackFiles = [callback1, callback2, callback3, bad_behaviour1, bad_behaviour2], @@ -3391,12 +3310,12 @@ otp_11861(Conf) when is_list(Conf) -> [], []} ], - ?line [] = run(Conf, Ts), + [] = run(Conf, Ts), true = code:set_path(CodePath), ok. -otp_7550(doc) -> - "Test that the new utf8/utf16/utf32 types do not allow size or unit specifiers."; +%% Test that the new utf8/utf16/utf32 types do not allow size or +%% unit specifiers. otp_7550(Config) when is_list(Config) -> Ts = [{otp_7550, <<"f8(A) -> @@ -3432,12 +3351,11 @@ otp_7550(Config) when is_list(Config) -> {20,erl_lint,utf_bittype_size_or_unit} ], []}}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -otp_8051(doc) -> - "Bugfix: -opaque with invalid type."; +%% Bugfix: -opaque with invalid type. otp_8051(Config) when is_list(Config) -> Ts = [{otp_8051, <<"-opaque foo() :: bar(). @@ -3445,12 +3363,10 @@ otp_8051(Config) when is_list(Config) -> ">>, [], {errors,[{1,erl_lint,{undefined_type,{bar,0}}}],[]}}], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -format_warn(doc) -> - "Check that format warnings are generated."; -format_warn(suite) -> []; +%% Check that format warnings are generated. format_warn(Config) when is_list(Config) -> L1 = 14, L2 = 4, @@ -3460,18 +3376,18 @@ format_warn(Config) when is_list(Config) -> ok. format_level(Level, Count, Config) -> - ?line W = get_compilation_result(Config, "format", + W = get_compilation_result(Config, "format", [{warn_format, Level}]), %% Pick out the 'format' warnings. - ?line FW = lists:filter(fun({_Line, erl_lint, {format_error, _}}) -> true; + FW = lists:filter(fun({_Line, erl_lint, {format_error, _}}) -> true; (_) -> false end, W), - ?line case length(FW) of + case length(FW) of Count -> ok; Other -> - ?t:format("Expected ~w warning(s); got ~w", [Count,Other]), + io:format("Expected ~w warning(s); got ~w", [Count,Other]), fail() end, ok. @@ -3507,7 +3423,7 @@ on_load_successful(Config) when is_list(Config) -> {[]}, %Tuple indicates no 'export_all'. []} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. on_load_failing(Config) when is_list(Config) -> @@ -3555,12 +3471,10 @@ on_load_failing(Config) when is_list(Config) -> {errors, [{1,erl_lint,{undefined_on_load,{non_existing,0}}}],[]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. -too_many_arguments(doc) -> - "Test that too many arguments is not accepted."; -too_many_arguments(suite) -> []; +%% Test that too many arguments is not accepted. too_many_arguments(Config) when is_list(Config) -> Ts = [{too_many_1, <<"f(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_) -> ok.">>, @@ -3569,7 +3483,7 @@ too_many_arguments(Config) when is_list(Config) -> [{1,erl_lint,{too_many_arguments,256}}],[]}} ], - ?line [] = run(Config, Ts), + [] = run(Config, Ts), ok. @@ -3652,9 +3566,7 @@ bin_syntax_errors(Config) -> [] = run(Config, Ts), ok. -predef(doc) -> - "OTP-10342: No longer predefined types: array(), digraph(), and so on"; -predef(suite) -> []; +%% OTP-10342: No longer predefined types: array(), digraph(), and so on. predef(Config) when is_list(Config) -> W = get_compilation_result(Config, "predef", []), [] = W, @@ -3781,8 +3693,7 @@ maps_type(Config) when is_list(Config) -> [] = run(Config, Ts), ok. -otp_11851(doc) -> - "OTP-11851: More atoms can be used as type names + bug fixes."; +%% OTP-11851: More atoms can be used as type names + bug fixes. otp_11851(Config) when is_list(Config) -> Ts = [ {otp_11851_1, @@ -3868,9 +3779,8 @@ otp_11851(Config) when is_list(Config) -> [] = run(Config, Ts), ok. -otp_11879(doc) -> - "OTP-11879: The -spec f/a :: (As) -> B; syntax removed, " - "and is_subtype/2 deprecated"; +%% OTP-11879: The -spec f/a :: (As) -> B; syntax removed, +%% and is_subtype/2 deprecated. otp_11879(_Config) -> Fs = [{attribute,0,file,{"file.erl",0}}, {attribute,0,module,m}, @@ -3891,8 +3801,7 @@ otp_11879(_Config) -> []} = compile:forms(Fs, [return,report]), ok. -otp_13230(doc) -> - "OTP-13230: -deprecated without -module"; +%% OTP-13230: -deprecated without -module. otp_13230(Config) when is_list(Config) -> Abstr = <<"-deprecated([{frutt,0,next_version}]).">>, {errors,[{1,erl_lint,undefined_module}, @@ -3917,7 +3826,7 @@ run(Config, Tests) -> E -> BadL; Bad -> - ?t:format("~nTest ~p failed. Expected~n ~p~n" + io:format("~nTest ~p failed. Expected~n ~p~n" "but got~n ~p~n", [N, E, Bad]), fail() end @@ -3927,8 +3836,8 @@ run(Config, Tests) -> %% Compiles a test file and returns the list of warnings/errors. get_compilation_result(Conf, Filename, Warnings) -> - ?line DataDir = ?datadir, - ?line File = filename:join(DataDir, Filename), + DataDir = ?datadir, + File = filename:join(DataDir, Filename), {ok,Bin} = file:read_file(File++".erl"), FileS = binary_to_list(Bin), {match,[{Start,Length}|_]} = re:run(FileS, "-module.*\\n"), @@ -3992,5 +3901,4 @@ call_format_error(L) -> L. fail() -> - io:format("failed~n"), - ?t:fail(). + ct:fail(failed). diff --git a/lib/stdlib/test/erl_pp_SUITE.erl b/lib/stdlib/test/erl_pp_SUITE.erl index f7418b1f5f..4d44f7686a 100644 --- a/lib/stdlib/test/erl_pp_SUITE.erl +++ b/lib/stdlib/test/erl_pp_SUITE.erl @@ -22,7 +22,7 @@ %%%----------------------------------------------------------------- -module(erl_pp_SUITE). -%-define(debug, true). +%%-define(debug, true). -ifdef(debug). -define(line, put(line, ?LINE), ). @@ -32,8 +32,8 @@ -define(t, test_server). -else. -include_lib("common_test/include/ct.hrl"). --define(datadir, ?config(data_dir, Config)). --define(privdir, ?config(priv_dir, Config)). +-define(datadir, proplists:get_value(data_dir, Config)). +-define(privdir, proplists:get_value(priv_dir, Config)). -endif. -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, @@ -55,19 +55,15 @@ %% Internal export. -export([ehook/6]). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(2)). - init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. + Config. end_per_testcase(_Case, _Config) -> - Dog = ?config(watchdog, _Config), - test_server:timetrap_cancel(Dog), ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,2}}]. all() -> [{group, expr}, {group, attributes}, hook, neg_indent, @@ -99,8 +95,6 @@ end_per_group(_GroupName, Config) -> -func(suite) -> - []; func(Config) when is_list(Config) -> Ts = [{func_1, <<"-record(r1, {a,b}). @@ -154,11 +148,9 @@ func(Config) when is_list(Config) -> true end)().">>} ], - ?line compile(Config, Ts), + compile(Config, Ts), ok. -call(suite) -> - []; call(Config) when is_list(Config) -> Ts = [{call_1, <<"t() -> @@ -167,11 +159,9 @@ call(Config) when is_list(Config) -> sfds,sdfsdf,sfds). ">>} ], - ?line compile(Config, Ts), + compile(Config, Ts), ok. -recs(suite) -> - []; recs(Config) when is_list(Config) -> %% Evolved while testing strict record tests in guards... Ts = [{recs_1, @@ -328,18 +318,16 @@ recs(Config) when is_list(Config) -> R = #r2{}, R#r2{c = R, d = #r1{}}.">>} ], - ?line compile(Config, Ts), + compile(Config, Ts), - ?line ok = pp_expr(<<"case #r{a={1,2},b=#r{}} of + ok = pp_expr(<<"case #r{a={1,2},b=#r{}} of X=Y=#r{a=foo,b=bar} -> {(foooo:baaaar(X))#r{a = rep},Y,#r.b} end">>), - ?line ok = pp_expr(<<"R#r{a = {kljasdklf,sdkfjsdl,sdafjkllsdf,sdfkjsd, + ok = pp_expr(<<"R#r{a = {kljasdklf,sdkfjsdl,sdafjkllsdf,sdfkjsd, sdafjsd,sdf,sdafsd,sdfdsf,sdfdsf,dsfds}}">>), ok. -try_catch(suite) -> - []; try_catch(Config) when is_list(Config) -> Ts = [{try_1, % copied from erl_eval_SUITE <<"t() -> try 1 of 1 -> 2 catch _:_ -> 3 end.">>}, @@ -381,8 +369,8 @@ try_catch(Config) when is_list(Config) -> <<"t() -> catch begin begin foo, bar, foo:bar(kljsldkfjdls,kljsdl), (catch bar:foo(foo)) end end.">>} ], - ?line compile(Config, Ts), - ?line ok = pp_expr(<<"try + compile(Config, Ts), + ok = pp_expr(<<"try erl_internal:bif(M,F,length(Args)) of true -> @@ -392,8 +380,6 @@ try_catch(Config) when is_list(Config) -> after foo end">>), ok. -if_then(suite) -> - []; if_then(Config) when is_list(Config) -> Ts = [{if_1, <<"t() -> if 1 > 2 -> 1; true -> b end.">>}, @@ -402,11 +388,9 @@ if_then(Config) when is_list(Config) -> {if_3, <<"t() -> if 1 == 2 -> a; 1 > 2 -> b; 1 < 2 -> c end.">>} ], - ?line compile(Config, Ts), + compile(Config, Ts), ok. -receive_after(suite) -> - []; receive_after(Config) when is_list(Config) -> Ts = [{rec_1, <<"t() -> receive foo -> bar; bar -> foo end.">>}, @@ -427,11 +411,9 @@ receive_after(Config) when is_list(Config) -> {3,4} end.">>} ], - ?line compile(Config, Ts), + compile(Config, Ts), ok. -bits(suite) -> - []; bits(Config) when is_list(Config) -> Ts = [{bit_1, % copied from shell_SUITE <<"t() -> <<(<<\"abc\">>):3/binary>>.">>}, @@ -452,21 +434,19 @@ bits(Config) when is_list(Config) -> {bit_9, <<"">>} ], - ?line compile(Config, Ts), - ?line ok = pp_expr(<<"<<(list_to_binary([1,2]))/binary>>">>), - ?line ok = pp_expr( + compile(Config, Ts), + ok = pp_expr(<<"<<(list_to_binary([1,2]))/binary>>">>), + ok = pp_expr( <<"<<(list_to_binary([1,2])):all/binary-unit:8-unsigned-big>>">>), - ?line ok = pp_expr(<<"<<<<\"hej\">>/binary>>">>), - ?line ok = pp_expr(<<"<<(foo:bar())/binary>>">>), - ?line ok = pp_expr(<<"<<(a)/binary>>">>), - ?line ok = pp_expr(<<"<<a/binary>>">>), - ?line ok = pp_expr(<<"<<{a,b}/binary>>">>), - ?line ok = pp_expr(<<"<<{foo:bar(),b}/binary>>">>), - ?line ok = pp_expr(<<"<<(foo:bar()):(foo:bar())/binary>>">>), + ok = pp_expr(<<"<<<<\"hej\">>/binary>>">>), + ok = pp_expr(<<"<<(foo:bar())/binary>>">>), + ok = pp_expr(<<"<<(a)/binary>>">>), + ok = pp_expr(<<"<<a/binary>>">>), + ok = pp_expr(<<"<<{a,b}/binary>>">>), + ok = pp_expr(<<"<<{foo:bar(),b}/binary>>">>), + ok = pp_expr(<<"<<(foo:bar()):(foo:bar())/binary>>">>), ok. -head_tail(suite) -> - []; head_tail(Config) when is_list(Config) -> Ts = [{list_1, <<"t() -> [a | b].">>}, @@ -481,43 +461,30 @@ head_tail(Config) when is_list(Config) -> [foo:bar(lkjljlskdfj, klsdajflds, sdafkljsdlfkjdas, kjlsdadjl), bar:foo(kljlkjsdf, lkjsdlfj, [kljsfj, sdfdsfsad])].">>} ], - ?line compile(Config, Ts), + compile(Config, Ts), ok. -cond1(suite) -> - []; cond1(Config) when is_list(Config) -> C = {'cond',1,[{clause,2,[],[[{tuple,2,[{atom,2,foo},{atom,2,bar}]}]], [{cons,3,{atom,3,a},{cons,3,{atom,3,b},{nil,3}}}]}, {clause,4,[],[[{atom,4,true}]], [{tuple,5,[{atom,5,x},{atom,5,y}]}]}]}, CChars = flat_expr1(C), -% ?line "cond {foo,bar} -> [a,b]; true -> {x,y} end" = CChars, - ?line "cond\n" + "cond\n" " {foo,bar} ->\n" " [a,b];\n" " true ->\n" " {x,y}\n" "end" = CChars, -% ?line ok = pp_expr(<<"cond -% {foo,bar} -> -% [a,b]; -% true -> -% {x,y} -% end">>), ok. -block(suite) -> - []; block(Config) when is_list(Config) -> Ts = [{block_1, <<"t() -> begin a,{c,d} end.">>} ], - ?line compile(Config, Ts), + compile(Config, Ts), ok. -case1(suite) -> - []; case1(Config) when is_list(Config) -> Ts = [{case_1, <<"t() -> case {foo,bar} of @@ -527,8 +494,8 @@ case1(Config) when is_list(Config) -> foo end.">>} ], - ?line compile(Config, Ts), - ?line ok = pp_expr(<<"case + compile(Config, Ts), + ok = pp_expr(<<"case erl_internal:bif(M,F,length(Args)) of true -> @@ -538,8 +505,6 @@ case1(Config) when is_list(Config) -> end">>), ok. -ops(suite) -> - []; ops(Config) when is_list(Config) -> Ts = [{ops_1, <<"t() -> {a,b} + (3 - 2) + 4.">>}, @@ -548,21 +513,17 @@ ops(Config) when is_list(Config) -> {ops_3, <<"t() -> - (- (- (- (- 3)))).">>} ], - ?line compile(Config, Ts), + compile(Config, Ts), ok. -messages(suite) -> - []; messages(Config) when is_list(Config) -> - ?line true = "{error,{some,\"error\"}}\n" =:= + true = "{error,{some,\"error\"}}\n" =:= lists:flatten(erl_pp:form({error,{some,"error"}})), - ?line true = "{warning,{some,\"warning\"}}\n" =:= + true = "{warning,{some,\"warning\"}}\n" =:= lists:flatten(erl_pp:form({warning,{some,"warning"}})), "\n" = flat_form({eof,0}), ok. -import_export(suite) -> - []; import_export(Config) when is_list(Config) -> Ts = [{import_1, <<"-import(lists, [max/1, reverse/1]). @@ -577,11 +538,9 @@ import_export(Config) when is_list(Config) -> <<"-include_lib(\"stdlib/include/qlc.hrl\"). t() -> qlc:q([X || X <- []]).">>} ], - ?line compile(Config, Ts), + compile(Config, Ts), ok. -misc_attrs(suite) -> - []; misc_attrs(Config) when is_list(Config) -> ok = pp_forms(<<"-module(m). ">>), ok = pp_forms(<<"-module(m, [Aafjlksfjdlsjflsdfjlsdjflkdsfjlk," @@ -599,8 +558,6 @@ misc_attrs(Config) when is_list(Config) -> ok = pp_forms(<<"-custom1(#{test1 => init/2, test2 => [val/1, val/2]}). ">>), ok. -dialyzer_attrs(suite) -> - []; dialyzer_attrs(Config) when is_list(Config) -> ok = pp_forms(<<"-type foo() :: #bar{}. ">>), ok = pp_forms(<<"-opaque foo() :: {bar, fun((X, [42,...]) -> X)}. ">>), @@ -608,8 +565,6 @@ dialyzer_attrs(Config) when is_list(Config) -> ok = pp_forms(<<"-callback foo(<<_:32,_:_*4>>, T) -> T. ">>), ok. -hook(suite) -> - []; hook(Config) when is_list(Config) -> F = fun(H) -> H end, do_hook(F). @@ -623,29 +578,29 @@ do_hook(HookFun) -> Call = {call,A0,{atom,A0,foo},[Lc]}, Expr2 = {call,A0,{atom,A0,fff},[Call,Call,Call]}, EChars2 = erl_pp:exprs([Expr2]), - ?line true = EChars =:= lists:flatten(EChars2), + true = EChars =:= lists:flatten(EChars2), EsChars = erl_pp:exprs([Expr], H), - ?line true = EChars =:= lists:flatten(EsChars), + true = EChars =:= lists:flatten(EsChars), A1 = erl_anno:new(1), F = {function,A1,ffff,0,[{clause,A1,[],[],[Expr]}]}, FuncChars = lists:flatten(erl_pp:function(F, H)), F2 = {function,A1,ffff,0,[{clause,A1,[],[],[Expr2]}]}, FuncChars2 = erl_pp:function(F2), - ?line true = FuncChars =:= lists:flatten(FuncChars2), + true = FuncChars =:= lists:flatten(FuncChars2), FFormChars = erl_pp:form(F, H), - ?line true = FuncChars =:= lists:flatten(FFormChars), + true = FuncChars =:= lists:flatten(FFormChars), A = {attribute,A1,record,{r,[{record_field,A1,{atom,A1,a},Expr}]}}, AChars = lists:flatten(erl_pp:attribute(A, H)), A2 = {attribute,A1,record,{r,[{record_field,A1,{atom,A1,a},Expr2}]}}, AChars2 = erl_pp:attribute(A2), - ?line true = AChars =:= lists:flatten(AChars2), + true = AChars =:= lists:flatten(AChars2), AFormChars = erl_pp:form(A, H), - ?line true = AChars =:= lists:flatten(AFormChars), + true = AChars =:= lists:flatten(AFormChars), - ?line "INVALID-FORM:{foo,bar}:" = lists:flatten(erl_pp:expr({foo,bar})), + "INVALID-FORM:{foo,bar}:" = lists:flatten(erl_pp:expr({foo,bar})), %% A list (as before R6), not a list of lists. G = [{op,A1,'>',{atom,A1,a},{foo,{atom,A1,b}}}], % not a proper guard @@ -653,26 +608,26 @@ do_hook(HookFun) -> G2 = [{op,A1,'>',{atom,A1,a}, {call,A0,{atom,A0,foo},[{atom,A1,b}]}}], % not a proper guard GChars2 = erl_pp:guard(G2), - ?line true = GChars =:= lists:flatten(GChars2), + true = GChars =:= lists:flatten(GChars2), EH = HookFun({?MODULE, ehook, [foo,bar]}), XEChars = erl_pp:expr(Expr, -1, EH), - ?line true = remove_indentation(EChars) =:= lists:flatten(XEChars), + true = remove_indentation(EChars) =:= lists:flatten(XEChars), XEChars2 = erl_pp:expr(Expr, EH), - ?line true = EChars =:= lists:flatten(XEChars2), + true = EChars =:= lists:flatten(XEChars2), %% Note: no leading spaces before "begin". Block = {block,A0,[{match,A0,{var,A0,'A'},{integer,A0,3}}, {atom,A0,true}]}, - ?line "begin\n A =" ++ _ = + "begin\n A =" ++ _ = lists:flatten(erl_pp:expr(Block, 17, none)), %% Special... - ?line true = + true = "{some,value}" =:= lists:flatten(erl_pp:expr({value,A0,{some,value}})), %% Silly... - ?line true = + true = "if true -> 0 end" =:= flat_expr({'if',0,[{clause,0,[],[],[{atom,0,0}]}]}), @@ -681,7 +636,7 @@ do_hook(HookFun) -> NewIf = {'if',A0,[{clause,A0,[],[[{atom,A0,true}]],[{atom,A0,b}]}]}, OldIfChars = lists:flatten(erl_pp:expr(OldIf)), NewIfChars = lists:flatten(erl_pp:expr(NewIf)), - ?line true = OldIfChars =:= NewIfChars, + true = OldIfChars =:= NewIfChars, ok. @@ -697,18 +652,16 @@ hook({foo,E}, I, P, H) -> A = erl_anno:new(0), erl_pp:expr({call,A,{atom,A,foo},[E]}, I, P, H). -neg_indent(suite) -> - []; neg_indent(Config) when is_list(Config) -> - ?line ok = pp_expr(<<"begin a end">>), - ?line ok = pp_expr(<<"begin a,b end">>), - ?line ok = pp_expr(<<"try a,b,c + ok = pp_expr(<<"begin a end">>), + ok = pp_expr(<<"begin a,b end">>), + ok = pp_expr(<<"try a,b,c catch exit:_ -> d; throw:_ -> t; error:{foo,bar} -> foo, bar end">>), - ?line ok = pp_expr( + ok = pp_expr( <<"fun() -> F = fun(A, B) when ((A#r1.a) orelse (B#r2.a)) or (B#r2.b) or (A#r1.b) -> @@ -722,43 +675,41 @@ neg_indent(Config) when is_list(Config) -> ok end()">>), - ?line ok = pp_expr(<<"[X || X <- a, true]">>), - ?line ok = pp_expr(<<"{[a,b,c],[d,e|f]}">>), - ?line ok = pp_expr(<<"f(a,b,c)">>), - ?line ok = pp_expr(<<"fun() when a,b;c,d -> a end">>), - ?line ok = pp_expr(<<"fun A() when a,b;c,d -> a end">>), - ?line ok = pp_expr(<<"<<34:32,17:32>>">>), - ?line ok = pp_expr(<<"if a,b,c -> d; e,f,g -> h,i end">>), - ?line ok = pp_expr(<<"if a -> d; c -> d end">>), - ?line ok = pp_expr(<<"receive after 1 -> 2 end">>), - ?line ok = pp_expr(<<"begin a,b,c end">>), - - ?line "\"\"" = flat_expr({string,0,""}), - ?line ok = pp_expr(<<"\"abc\"">>), - ?line ok = pp_expr(<<"\"abc\n\n\n\n\nkjsd\n\n\n\n\nkljsddf\n\n\n\n\n" - "klafd\n\n\n\n\nkljsdf\n\n\n\n\nsdf\n\n\n\n\n\"">>), - ?line ok = pp_expr(<<"fkjlskljklkkljlkjlkjkljlkjsljklf" - "lsdjlfdsjlfjsdlfjdslfjdlsjfsdjfklsdkfjsdf(" - "\"abc\n\n\n\n\nkjsd\n\n\n\n\nkljsddf\n\n\n\n\n" - "kljsafd\n\n\n\n\nkljsdf\n\n\n\n\nkjsdf" - "\n\n\n\n\n\")">>), + ok = pp_expr(<<"[X || X <- a, true]">>), + ok = pp_expr(<<"{[a,b,c],[d,e|f]}">>), + ok = pp_expr(<<"f(a,b,c)">>), + ok = pp_expr(<<"fun() when a,b;c,d -> a end">>), + ok = pp_expr(<<"fun A() when a,b;c,d -> a end">>), + ok = pp_expr(<<"<<34:32,17:32>>">>), + ok = pp_expr(<<"if a,b,c -> d; e,f,g -> h,i end">>), + ok = pp_expr(<<"if a -> d; c -> d end">>), + ok = pp_expr(<<"receive after 1 -> 2 end">>), + ok = pp_expr(<<"begin a,b,c end">>), + + "\"\"" = flat_expr({string,0,""}), + ok = pp_expr(<<"\"abc\"">>), + ok = pp_expr(<<"\"abc\n\n\n\n\nkjsd\n\n\n\n\nkljsddf\n\n\n\n\n" + "klafd\n\n\n\n\nkljsdf\n\n\n\n\nsdf\n\n\n\n\n\"">>), + ok = pp_expr(<<"fkjlskljklkkljlkjlkjkljlkjsljklf" + "lsdjlfdsjlfjsdlfjdslfjdlsjfsdjfklsdkfjsdf(" + "\"abc\n\n\n\n\nkjsd\n\n\n\n\nkljsddf\n\n\n\n\n" + "kljsafd\n\n\n\n\nkljsdf\n\n\n\n\nkjsdf" + "\n\n\n\n\n\")">>), %% fun-info is skipped when everything is to fit on one single line Fun1 = {'fun',1,{function,t,0},{0,45353021,'-t/0-fun-0-'}}, - ?line "fun t/0" = flat_expr(Fun1), + "fun t/0" = flat_expr(Fun1), Fun2 = {'fun',2,{clauses,[{clause,2,[],[],[{atom,3,true}]}]}, {0,108059557,'-t/0-fun-0-'}}, - ?line "fun() -> true end" = flat_expr(Fun2), + "fun() -> true end" = flat_expr(Fun2), Fun3 = {named_fun,3,'True',[{clause,3,[],[],[{atom,3,true}]}], {0,424242424,'-t/0-True-0-'}}, - ?line "fun True() -> true end" = flat_expr(Fun3), + "fun True() -> true end" = flat_expr(Fun3), ok. -otp_6321(doc) -> - "OTP_6321. Bug fix of exprs()."; -otp_6321(suite) -> []; +%% OTP_6321. Bug fix of exprs(). otp_6321(Config) when is_list(Config) -> Str = "S = hopp, {hej, S}. ", {done, {ok, Tokens, _EndLine}, ""} = erl_scan:tokens("", Str, _L=1), @@ -766,9 +717,7 @@ otp_6321(Config) when is_list(Config) -> "S = hopp, {hej,S}" = lists:flatten(erl_pp:exprs(Exprs)), ok. -otp_6911(doc) -> - "OTP_6911. More newlines."; -otp_6911(suite) -> []; +%% OTP_6911. More newlines. otp_6911(Config) when is_list(Config) -> F = {function,5,thomas,1, [{clause,5, @@ -779,38 +728,32 @@ otp_6911(Config) when is_list(Config) -> [{clause,7,[{atom,7,true}],[],[{integer,7,12}]}, {clause,8,[{atom,8,false}],[],[{integer,8,14}]}]}]}]}, Chars = flat_form(F), - ?line "thomas(X) ->\n" + "thomas(X) ->\n" " case X of\n" " true ->\n" " 12;\n" " false ->\n" " 14\n" " end.\n" = Chars, - ?line ok = pp_expr(<<"case X of true -> 12; false -> 14 end">>), - ?line ok = pp_expr(<<"receive after 1 -> ok end">>), + ok = pp_expr(<<"case X of true -> 12; false -> 14 end">>), + ok = pp_expr(<<"receive after 1 -> ok end">>), ok. -otp_6914(doc) -> - "OTP_6914. Binary comprehensions."; -otp_6914(suite) -> []; +%% OTP_6914. Binary comprehensions. otp_6914(Config) when is_list(Config) -> - ?line ok = pp_expr(<<"<< <<B:1>> || B <- [0,1,1] >>">>), - ?line ok = pp_expr(<<"[ B || <<B:1>> <= <<\"hi\">>]">>), - ?line ok = pp_expr(<<"<< <<1:1>> || true >>">>), + ok = pp_expr(<<"<< <<B:1>> || B <- [0,1,1] >>">>), + ok = pp_expr(<<"[ B || <<B:1>> <= <<\"hi\">>]">>), + ok = pp_expr(<<"<< <<1:1>> || true >>">>), ok. -otp_8150(doc) -> - "OTP_8150. Types."; -otp_8150(suite) -> []; +%% OTP_8150. Types. otp_8150(Config) when is_list(Config) -> - ?line _ = [{N,ok} = {N,pp_forms(B)} || + _ = [{N,ok} = {N,pp_forms(B)} || {N,B} <- type_examples() ], ok. -otp_8238(doc) -> - "OTP_8238. Bugfix 'E'."; -otp_8238(suite) -> []; +%% OTP_8238. Bugfix 'E'. otp_8238(Config) when is_list(Config) -> Ex = [<<"-record(rec1, {}).\n" "-record(rec2, {a, b}).\n" @@ -825,7 +768,7 @@ otp_8238(Config) when is_list(Config) -> "t2() ->\n" " #r{}.\n">> ], - ?line compile(Config, [{otp_8238,iolist_to_binary(Ex)}]), + compile(Config, [{otp_8238,iolist_to_binary(Ex)}]), ok. type_examples() -> @@ -880,13 +823,13 @@ type_examples() -> %% Erlang/OTP 19.0, but as long as the parser recognizes the %% is_subtype(V, T) syntax, we need a few examples of the syntax. {ex31,<<"-spec t1(FooBar :: t99()) -> t99();" - "(t2()) -> t2();" - "('\\'t::4'()) -> '\\'t::4'() when is_subtype('\\'t::4'(), t24);" - "(t23()) -> t23() when is_subtype(t23(), atom())," - " is_subtype(t23(), t14());" - "(t24()) -> t24() when is_subtype(t24(), atom())," - " is_subtype(t24(), t14())," - " is_subtype(t24(), '\\'t::4'()).">>}, + "(t2()) -> t2();" + "('\\'t::4'()) -> '\\'t::4'() when is_subtype('\\'t::4'(), t24);" + "(t23()) -> t23() when is_subtype(t23(), atom())," + " is_subtype(t23(), t14());" + "(t24()) -> t24() when is_subtype(t24(), atom())," + " is_subtype(t24(), t14())," + " is_subtype(t24(), '\\'t::4'()).">>}, {ex32,<<"-spec mod:t2() -> any(). ">>}, {ex33,<<"-opaque attributes_data() :: " "[{'column', column()} | {'line', info_line()} |" @@ -906,19 +849,15 @@ type_examples() -> "f19 = 3 :: integer()|undefined," "f5 = 3 :: undefined|integer()}). ">>}]. -otp_8473(doc) -> - "OTP_8473. Bugfix abstract type 'fun'."; -otp_8473(suite) -> []; +%% OTP_8473. Bugfix abstract type 'fun'. otp_8473(Config) when is_list(Config) -> Ex = [{ex1,<<"-type 'fun'(A) :: A.\n" "-type funkar() :: 'fun'(fun((integer()) -> atom())).\n">>}], - ?line _ = [{N,ok} = {N,pp_forms(B)} || + _ = [{N,ok} = {N,pp_forms(B)} || {N,B} <- Ex], ok. -otp_8522(doc) -> - "OTP_8522. Avoid duplicated 'undefined' in record field types."; -otp_8522(suite) -> []; +%% OTP_8522. Avoid duplicated 'undefined' in record field types. otp_8522(Config) when is_list(Config) -> FileName = filename('otp_8522.erl', Config), C = <<"-module(otp_8522).\n" @@ -927,13 +866,13 @@ otp_8522(Config) when is_list(Config) -> " f3 :: (undefined),\n" " f4 :: x | y | undefined | z,\n" " f5 :: a}).\n">>, - ?line ok = file:write_file(FileName, C), - ?line {ok, _} = compile:file(FileName, [{outdir,?privdir},debug_info]), + ok = file:write_file(FileName, C), + {ok, _} = compile:file(FileName, [{outdir,?privdir},debug_info]), BF = filename("otp_8522", Config), - ?line {ok, A} = beam_lib:chunks(BF, [abstract_code]), + {ok, A} = beam_lib:chunks(BF, [abstract_code]), %% OTP-12719: Since 'undefined' is no longer added by the Erlang %% Parser, the number of 'undefined' is 4. It used to be 5. - ?line 4 = count_atom(A, undefined), + 4 = count_atom(A, undefined), ok. count_atom(A, A) -> @@ -945,8 +884,6 @@ count_atom(L, A) when is_list(L) -> count_atom(_, _) -> 0. -maps_syntax(doc) -> "Maps syntax"; -maps_syntax(suite) -> []; maps_syntax(Config) when is_list(Config) -> Ts = [{map_fun_1, <<"t() ->\n" @@ -977,9 +914,7 @@ maps_syntax(Config) when is_list(Config) -> ok. -otp_8567(doc) -> - "OTP_8567. Avoid duplicated 'undefined' in record field types."; -otp_8567(suite) -> []; +%% OTP_8567. Avoid duplicated 'undefined' in record field types. otp_8567(Config) when is_list(Config) -> FileName = filename('otp_8567.erl', Config), C = <<"-module otp_8567.\n" @@ -988,8 +923,8 @@ otp_8567(Config) when is_list(Config) -> "-record r, {a}.\n" "-record s, {a :: integer()}.\n" "-type t() :: {#r{},#s{}}.\n">>, - ?line ok = file:write_file(FileName, C), - ?line {error,[{_,[{3,erl_parse,["syntax error before: ","')'"]}]}],_} = + ok = file:write_file(FileName, C), + {error,[{_,[{3,erl_parse,["syntax error before: ","')'"]}]}],_} = compile:file(FileName, [return]), F = <<"-module(otp_8567).\n" @@ -1010,13 +945,11 @@ otp_8567(Config) when is_list(Config) -> "-spec(otp_8567:t4 (ot()) -> ot1()).\n" "t4(A) ->\n" " A.\n">>, - ?line ok = pp_forms(F), + ok = pp_forms(F), ok. -otp_8664(doc) -> - "OTP_8664. Types with integer expressions."; -otp_8664(suite) -> []; +%% OTP_8664. Types with integer expressions. otp_8664(Config) when is_list(Config) -> FileName = filename('otp_8664.erl', Config), C1 = <<"-module(otp_8664).\n" @@ -1033,42 +966,38 @@ otp_8664(Config) when is_list(Config) -> "-type t() :: t1() | t2() | t3() | b1() | u().\n" "-spec t() -> t().\n" "t() -> 3.\n">>, - ?line ok = file:write_file(FileName, C1), - ?line {ok, _, []} = compile:file(FileName, [return]), + ok = file:write_file(FileName, C1), + {ok, _, []} = compile:file(FileName, [return]), C2 = <<"-module(otp_8664).\n" "-export([t/0]).\n" "-spec t() -> 9 and 4.\n" "t() -> 0.\n">>, - ?line ok = file:write_file(FileName, C2), - ?line {error,[{_,[{3,erl_lint,{type_syntax,integer}}]}],_} = + ok = file:write_file(FileName, C2), + {error,[{_,[{3,erl_lint,{type_syntax,integer}}]}],_} = compile:file(FileName, [return]), ok. -otp_9147(doc) -> - "OTP_9147. Create well-formed types when adding 'undefined'."; -otp_9147(suite) -> []; +%% OTP-9147. Create well-formed types when adding 'undefined'. otp_9147(Config) when is_list(Config) -> FileName = filename('otp_9147.erl', Config), C1 = <<"-module(otp_9147).\n" "-export_type([undef/0]).\n" "-record(undef, {f1 :: F1 :: a | b}).\n" "-type undef() :: #undef{}.\n">>, - ?line ok = file:write_file(FileName, C1), - ?line {ok, _, []} = + ok = file:write_file(FileName, C1), + {ok, _, []} = compile:file(FileName, [return,'P',{outdir,?privdir}]), PFileName = filename('otp_9147.P', Config), - ?line {ok, Bin} = file:read_file(PFileName), + {ok, Bin} = file:read_file(PFileName), %% The parentheses around "F1 :: a | b" are new (bugfix). - ?line true = + true = lists:member("-record(undef,{f1 :: F1 :: a | b}).", string:tokens(binary_to_list(Bin), "\n")), ok. -otp_10302(doc) -> - "OTP-10302. Unicode characters scanner/parser."; -otp_10302(suite) -> []; +%% OTP-10302. Unicode characters scanner/parser. otp_10302(Config) when is_list(Config) -> Ts = [{uni_1, <<"t() -> <<(<<\"abc\\x{aaa}\">>):3/binary>>.">>} @@ -1105,9 +1034,7 @@ unicode_hook({foo,E}, I, P, H) -> A = erl_anno:new(0), erl_pp:expr({call,A,{atom,A,foo},[E]}, I, P, H). -otp_10820(doc) -> - "OTP-10820. Unicode filenames."; -otp_10820(suite) -> []; +%% OTP-10820. Unicode filenames. otp_10820(Config) when is_list(Config) -> C1 = <<"%% coding: utf-8\n -module(any).">>, ok = do_otp_10820(Config, C1, "+pc latin1"), @@ -1133,9 +1060,7 @@ file_attr_is_string("-file(\"" ++ _) -> true; file_attr_is_string([_ | L]) -> file_attr_is_string(L). -otp_11100(doc) -> - "OTP-11100. Fix printing of invalid forms."; -otp_11100(suite) -> []; +%% OTP-11100. Fix printing of invalid forms. otp_11100(Config) when is_list(Config) -> %% There are a few places where the added code ("options(none)") %% doesn't make a difference (pp:bit_elem_type/1 is an example). @@ -1170,9 +1095,7 @@ otp_11100(Config) when is_list(Config) -> []}}), ok. -otp_11861(doc) -> - "OTP-11861. behaviour_info() and -callback."; -otp_11861(suite) -> []; +%% OTP-11861. behaviour_info() and -callback. otp_11861(Config) when is_list(Config) -> "-optional_callbacks([bar/0]).\n" = pf({attribute,3,optional_callbacks,[{bar,0}]}), @@ -1193,11 +1116,11 @@ compile(Config, Tests) -> ok -> BadL; not_ok -> - ?t:format("~nTest ~p failed.~n", [N]), + io:format("~nTest ~p failed.~n", [N]), fail() end; Bad -> - ?t:format("~nTest ~p failed. got~n ~p~n", + io:format("~nTest ~p failed. got~n ~p~n", [N, Bad]), fail() end @@ -1363,10 +1286,9 @@ filename(Name, Config) -> filename:join(?privdir, Name). fail() -> - io:format("failed~n"), - ?t:fail(). + ct:fail(failed). %% +fnu means a peer node has to be started; slave will not do start_node(Name, Xargs) -> - ?line PA = filename:dirname(code:which(?MODULE)), + PA = filename:dirname(code:which(?MODULE)), test_server:start_node(Name, peer, [{args, "-pa " ++ PA ++ " " ++ Xargs}]). diff --git a/lib/stdlib/test/erl_scan_SUITE.erl b/lib/stdlib/test/erl_scan_SUITE.erl index 941703b5dd..9432edc00f 100644 --- a/lib/stdlib/test/erl_scan_SUITE.erl +++ b/lib/stdlib/test/erl_scan_SUITE.erl @@ -18,11 +18,12 @@ %% %CopyrightEnd% -module(erl_scan_SUITE). --export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, +-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, + init_per_testcase/2, end_per_testcase/2, init_per_group/2,end_per_group/2]). --export([ error_1/1, error_2/1, iso88591/1, otp_7810/1, otp_10302/1, - otp_10990/1, otp_10992/1, otp_11807/1]). +-export([error_1/1, error_2/1, iso88591/1, otp_7810/1, otp_10302/1, + otp_10990/1, otp_10992/1, otp_11807/1]). -import(lists, [nth/2,flatten/1]). -import(io_lib, [print/1]). @@ -30,7 +31,7 @@ %% %% Define to run outside of test server %% -%-define(STANDALONE,1). +%%-define(STANDALONE,1). -ifdef(STANDALONE). -compile(export_all). @@ -43,22 +44,17 @@ %% ".". -else. -include_lib("common_test/include/ct.hrl"). --export([init_per_testcase/2, end_per_testcase/2]). +-endif. -init_per_testcase(_Case, Config) when is_list(Config) -> - ?line Dog=test_server:timetrap(test_server:seconds(1200)), - [{watchdog, Dog}|Config]. +init_per_testcase(_Case, Config) -> + Config. -end_per_testcase(_Case, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. --endif. -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(1)). - -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,20}}]. all() -> [{group, error}, iso88591, otp_7810, otp_10302, otp_10990, otp_10992, @@ -81,20 +77,14 @@ end_per_group(_GroupName, Config) -> -error_1(doc) -> - ["(OTP-2347)"]; -error_1(suite) -> - []; +%% (OTP-2347) error_1(Config) when is_list(Config) -> - ?line {error, _, _} = erl_scan:string("'a"), + {error, _, _} = erl_scan:string("'a"), ok. -error_2(doc) -> - ["Checks that format_error works on the error cases."]; -error_2(suite) -> - []; +%% Checks that format_error works on the error cases. error_2(Config) when is_list(Config) -> - ?line lists:foreach(fun check/1, error_cases()), + lists:foreach(fun check/1, error_cases()), ok. error_cases() -> @@ -107,7 +97,7 @@ error_cases() -> "2.3e", "2.3e-", "91#9" -]. + ]. assert_type(N, integer) when is_integer(N) -> ok; @@ -128,70 +118,66 @@ check_error({error, Info, EndLine}, Module0) -> String = lists:flatten(Module0:format_error(Desc)), true = io_lib:printable_list(String). -iso88591(doc) -> ["Tests the support for ISO-8859-1 i.e Latin-1"]; -iso88591(suite) -> []; +%% Tests the support for ISO-8859-1 i.e Latin-1. iso88591(Config) when is_list(Config) -> - ?line ok = - case catch begin - %% Some atom and variable names - V1s = [$Á,$á,$é,$ë], - V2s = [$N,$ä,$r], - A1s = [$h,$ä,$r], - A2s = [$ö,$r,$e], - %% Test parsing atom and variable characters. - {ok,Ts1,_} = erl_scan_string(V1s ++ " " ++ V2s ++ - "\327" ++ - A1s ++ " " ++ A2s), - V1s = atom_to_list(element(3, nth(1, Ts1))), - V2s = atom_to_list(element(3, nth(2, Ts1))), - A1s = atom_to_list(element(3, nth(4, Ts1))), - A2s = atom_to_list(element(3, nth(5, Ts1))), - %% Test printing atoms - A1s = flatten(print(element(3, nth(4, Ts1)))), - A2s = flatten(print(element(3, nth(5, Ts1)))), - %% Test parsing and printing strings. - S1 = V1s ++ "\327" ++ A1s ++ "\250" ++ A2s, - S1s = "\"" ++ S1 ++ "\"", - {ok,Ts2,_} = erl_scan_string(S1s), - S1 = element(3, nth(1, Ts2)), - S1s = flatten(print(element(3, nth(1, Ts2)))), - ok %It all worked - end of - {'EXIT',R} -> %Something went wrong! - {error,R}; - ok -> ok %Aok - end. - -otp_7810(doc) -> - ["OTP-7810. White spaces, comments, and more.."]; -otp_7810(suite) -> - []; + ok = + case catch begin + %% Some atom and variable names + V1s = [$Á,$á,$é,$ë], + V2s = [$N,$ä,$r], + A1s = [$h,$ä,$r], + A2s = [$ö,$r,$e], + %% Test parsing atom and variable characters. + {ok,Ts1,_} = erl_scan_string(V1s ++ " " ++ V2s ++ + "\327" ++ + A1s ++ " " ++ A2s), + V1s = atom_to_list(element(3, nth(1, Ts1))), + V2s = atom_to_list(element(3, nth(2, Ts1))), + A1s = atom_to_list(element(3, nth(4, Ts1))), + A2s = atom_to_list(element(3, nth(5, Ts1))), + %% Test printing atoms + A1s = flatten(print(element(3, nth(4, Ts1)))), + A2s = flatten(print(element(3, nth(5, Ts1)))), + %% Test parsing and printing strings. + S1 = V1s ++ "\327" ++ A1s ++ "\250" ++ A2s, + S1s = "\"" ++ S1 ++ "\"", + {ok,Ts2,_} = erl_scan_string(S1s), + S1 = element(3, nth(1, Ts2)), + S1s = flatten(print(element(3, nth(1, Ts2)))), + ok %It all worked + end of + {'EXIT',R} -> %Something went wrong! + {error,R}; + ok -> ok %Aok + end. + +%% OTP-7810. White spaces, comments, and more... otp_7810(Config) when is_list(Config) -> - ?line ok = reserved_words(), - ?line ok = atoms(), - ?line ok = punctuations(), - ?line ok = comments(), - ?line ok = errors(), - ?line ok = integers(), - ?line ok = base_integers(), - ?line ok = floats(), - ?line ok = dots(), - ?line ok = chars(), - ?line ok = variables(), - ?line ok = eof(), - ?line ok = illegal(), - ?line ok = crashes(), - - ?line ok = options(), - ?line ok = token_info(), - ?line ok = column_errors(), - ?line ok = white_spaces(), - - ?line ok = unicode(), - - ?line ok = more_chars(), - ?line ok = more_options(), - ?line ok = anno_info(), + ok = reserved_words(), + ok = atoms(), + ok = punctuations(), + ok = comments(), + ok = errors(), + ok = integers(), + ok = base_integers(), + ok = floats(), + ok = dots(), + ok = chars(), + ok = variables(), + ok = eof(), + ok = illegal(), + ok = crashes(), + + ok = options(), + ok = token_info(), + ok = column_errors(), + ok = white_spaces(), + + ok = unicode(), + + ok = more_chars(), + ok = more_options(), + ok = anno_info(), ok. @@ -202,10 +188,10 @@ reserved_words() -> 'rem', 'band', 'and', 'bor', 'bxor', 'bsl', 'bsr', 'or', 'xor'], [begin - ?line {RW, true} = {RW, erl_scan:reserved_word(RW)}, + {RW, true} = {RW, erl_scan:reserved_word(RW)}, S = atom_to_list(RW), Ts = [{RW,{1,1}}], - ?line test_string(S, Ts) + test_string(S, Ts) end || RW <- L], ok. @@ -214,14 +200,14 @@ atoms() -> test_string("a b", [{atom,{1,1},a},{atom,{2,18},b}]), test_string("'a b'", [{atom,{1,1},'a b'}]), - test_string("a", [{atom,{1,1},a}]), - test_string("a@2", [{atom,{1,1},a@2}]), - test_string([39,65,200,39], [{atom,{1,1},'AÈ'}]), - test_string("ärlig östen", [{atom,{1,1},ärlig},{atom,{1,7},östen}]), - ?line {ok,[{atom,_,'$a'}],{1,6}} = - erl_scan_string("'$\\a'", {1,1}), - ?line test("'$\\a'"), - ok. + test_string("a", [{atom,{1,1},a}]), + test_string("a@2", [{atom,{1,1},a@2}]), + test_string([39,65,200,39], [{atom,{1,1},'AÈ'}]), + test_string("ärlig östen", [{atom,{1,1},ärlig},{atom,{1,7},östen}]), + {ok,[{atom,_,'$a'}],{1,6}} = + erl_scan_string("'$\\a'", {1,1}), + test("'$\\a'"), + ok. punctuations() -> L = ["<<", "<-", "<=", "<", ">>", ">=", ">", "->", "--", @@ -231,7 +217,7 @@ punctuations() -> [begin W = list_to_atom(S), Ts = [{W,{1,1}}], - ?line test_string(S, Ts) + test_string(S, Ts) end || S <- L], Three = ["/=:=", "<=:=", "==:=", ">=:="], % three tokens... No = Three ++ L, @@ -247,18 +233,18 @@ punctuations() -> W1 = list_to_atom(S1), W2 = list_to_atom(S2), Ts = [{W1,{1,1}},{W2,{1,-L2+1}}], - ?line test_string(S, Ts) + test_string(S, Ts) end || {S,[{L2,S1,S2}|_]} <- SL], PTs1 = [{'!',{1,1}},{'(',{1,2}},{')',{1,3}},{',',{1,4}},{';',{1,5}}, {'=',{1,6}},{'[',{1,7}},{']',{1,8}},{'{',{1,9}},{'|',{1,10}}, {'}',{1,11}}], - ?line test_string("!(),;=[]{|}", PTs1), + test_string("!(),;=[]{|}", PTs1), PTs2 = [{'#',{1,1}},{'&',{1,2}},{'*',{1,3}},{'+',{1,4}},{'/',{1,5}}, {':',{1,6}},{'<',{1,7}},{'>',{1,8}},{'?',{1,9}},{'@',{1,10}}, {'\\',{1,11}},{'^',{1,12}},{'`',{1,13}},{'~',{1,14}}], - ?line test_string("#&*+/:<>?@\\^`~", PTs2), + test_string("#&*+/:<>?@\\^`~", PTs2), test_string(".. ", [{'..',{1,1}}]), test_string("1 .. 2", @@ -267,9 +253,9 @@ punctuations() -> ok. comments() -> - ?line test("a %%\n b"), - ?line {ok,[],1} = erl_scan_string("%"), - ?line test("a %%\n b"), + test("a %%\n b"), + {ok,[],1} = erl_scan_string("%"), + test("a %%\n b"), {ok,[{atom,{1,1},a},{atom,{2,2},b}],{2,3}} = erl_scan_string("a %%\n b", {1,1}), {ok,[{atom,{1,1},a},{comment,{1,3},"%%"},{atom,{2,2},b}],{2,3}} = @@ -289,30 +275,30 @@ comments() -> ok. errors() -> - ?line {error,{1,erl_scan,{string,$',"qa"}},1} = erl_scan:string("'qa"), %' + {error,{1,erl_scan,{string,$',"qa"}},1} = erl_scan:string("'qa"), %' {error,{{1,1},erl_scan,{string,$',"qa"}},{1,4}} = %' erl_scan:string("'qa", {1,1}, []), %' - ?line {error,{1,erl_scan,{string,$","str"}},1} = %" + {error,{1,erl_scan,{string,$","str"}},1} = %" erl_scan:string("\"str"), %" {error,{{1,1},erl_scan,{string,$","str"}},{1,5}} = %" erl_scan:string("\"str", {1,1}, []), %" - ?line {error,{1,erl_scan,char},1} = erl_scan:string("$"), + {error,{1,erl_scan,char},1} = erl_scan:string("$"), {error,{{1,1},erl_scan,char},{1,2}} = erl_scan:string("$", {1,1}, []), test_string([34,65,200,34], [{string,{1,1},"AÈ"}]), test_string("\\", [{'\\',{1,1}}]), - ?line {'EXIT',_} = + {'EXIT',_} = (catch {foo, erl_scan:string('$\\a', {1,1})}), % type error - ?line {'EXIT',_} = + {'EXIT',_} = (catch {foo, erl_scan:tokens([], '$\\a', {1,1})}), % type error - ?line "{a,tuple}" = erl_scan:format_error({a,tuple}), + "{a,tuple}" = erl_scan:format_error({a,tuple}), ok. integers() -> [begin I = list_to_integer(S), Ts = [{integer,{1,1},I}], - ?line test_string(S, Ts) + test_string(S, Ts) end || S <- [[N] || N <- lists:seq($0, $9)] ++ ["2323","000"] ], ok. @@ -321,11 +307,11 @@ base_integers() -> B = list_to_integer(BS), I = erlang:list_to_integer(S, B), Ts = [{integer,{1,1},I}], - ?line test_string(BS++"#"++S, Ts) + test_string(BS++"#"++S, Ts) end || {BS,S} <- [{"2","11"}, {"5","23234"}, {"12","05a"}, {"16","abcdef"}, {"16","ABCDEF"}] ], - ?line {error,{1,erl_scan,{base,1}},1} = erl_scan:string("1#000"), + {error,{1,erl_scan,{base,1}},1} = erl_scan:string("1#000"), {error,{{1,1},erl_scan,{base,1}},{1,2}} = erl_scan:string("1#000", {1,1}, []), @@ -333,11 +319,11 @@ base_integers() -> [begin Str = BS ++ "#" ++ S, - ?line {error,{1,erl_scan,{illegal,integer}},1} = + {error,{1,erl_scan,{illegal,integer}},1} = erl_scan:string(Str) end || {BS,S} <- [{"3","3"},{"15","f"}, {"12","c"}] ], - ?line {ok,[{integer,1,239},{'@',1}],1} = erl_scan_string("16#ef@"), + {ok,[{integer,1,239},{'@',1}],1} = erl_scan_string("16#ef@"), {ok,[{integer,{1,1},239},{'@',{1,6}}],{1,7}} = erl_scan_string("16#ef@", {1,1}, []), {ok,[{integer,{1,1},14},{atom,{1,5},g@}],{1,7}} = @@ -349,12 +335,12 @@ floats() -> [begin F = list_to_float(FS), Ts = [{float,{1,1},F}], - ?line test_string(FS, Ts) + test_string(FS, Ts) end || FS <- ["1.0","001.17","3.31200","1.0e0","1.0E17", "34.21E-18", "17.0E+14"]], test_string("1.e2", [{integer,{1,1},1},{'.',{1,2}},{atom,{1,3},e2}]), - ?line {error,{1,erl_scan,{illegal,float}},1} = + {error,{1,erl_scan,{illegal,float}},1} = erl_scan:string("1.0e400"), {error,{{1,1},erl_scan,{illegal,float}},{1,8}} = erl_scan:string("1.0e400", {1,1}, []), @@ -375,11 +361,11 @@ dots() -> {".% öh",{ok,[{dot,1}],1}, {ok,[{dot,{1,1}}],{1,6}}}, {".%\n", {ok,[{dot,1}],2}, {ok,[{dot,{1,1}}],{2,1}}}, {".$", {error,{1,erl_scan,char},1}, - {error,{{1,2},erl_scan,char},{1,3}}}, + {error,{{1,2},erl_scan,char},{1,3}}}, {".$\\", {error,{1,erl_scan,char},1}, {error,{{1,2},erl_scan,char},{1,4}}}, {".a", {ok,[{'.',1},{atom,1,a}],1}, - {ok,[{'.',{1,1}},{atom,{1,2},a}],{1,3}}} + {ok,[{'.',{1,1}},{atom,{1,2},a}],{1,3}}} ], [begin R = erl_scan_string(S), @@ -425,27 +411,27 @@ chars() -> [begin L = lists:flatten(io_lib:format("$\\~.8b", [C])), Ts = [{char,{1,1},C}], - ?line test_string(L, Ts) + test_string(L, Ts) end || C <- lists:seq(0, 255)], %% Leading zeroes... [begin L = lists:flatten(io_lib:format("$\\~3.8.0b", [C])), Ts = [{char,{1,1},C}], - ?line test_string(L, Ts) + test_string(L, Ts) end || C <- lists:seq(0, 255)], %% $\^\n now increments the line... [begin L = "$\\^" ++ [C], Ts = [{char,{1,1},C band 2#11111}], - ?line test_string(L, Ts) + test_string(L, Ts) end || C <- lists:seq(0, 255)], [begin L = "$\\" ++ [C], Ts = [{char,{1,1},V}], - ?line test_string(L, Ts) + test_string(L, Ts) end || {C,V} <- [{$n,$\n}, {$r,$\r}, {$t,$\t}, {$v,$\v}, {$b,$\b}, {$f,$\f}, {$e,$\e}, {$s,$\s}, {$d,$\d}]], @@ -458,13 +444,13 @@ chars() -> [begin L = "$\\" ++ [C], Ts = [{char,{1,1},C}], - ?line test_string(L, Ts) + test_string(L, Ts) end || C <- lists:seq(0, 255) -- No], [begin L = "'$\\" ++ [C] ++ "'", Ts = [{atom,{1,1},list_to_atom("$"++[C])}], - ?line test_string(L, Ts) + test_string(L, Ts) end || C <- lists:seq(0, 255) -- No], test_string("\"\\013a\\\n\"", [{string,{1,1},"\va\n"}]), @@ -476,17 +462,17 @@ chars() -> [begin L = "$" ++ [C], Ts = [{char,{1,1},C}], - ?line test_string(L, Ts) + test_string(L, Ts) end || C <- lists:seq(0, 255) -- (No ++ [$\\])], test_string("$\n", [{char,{1,1},$\n}]), - ?line {error,{{1,1},erl_scan,char},{1,4}} = + {error,{{1,1},erl_scan,char},{1,4}} = erl_scan:string("$\\^",{1,1}), test_string("$\\\n", [{char,{1,1},$\n}]), %% Robert's scanner returns line 1: test_string("$\\\n", [{char,{1,1},$\n}]), test_string("$\n\n", [{char,{1,1},$\n}]), - ?line test("$\n\n"), + test("$\n\n"), ok. @@ -499,30 +485,30 @@ variables() -> ok. eof() -> - ?line {done,{eof,1},eof} = erl_scan:tokens([], eof, 1), + {done,{eof,1},eof} = erl_scan:tokens([], eof, 1), {more, C1} = erl_scan:tokens([]," \n", 1), - ?line {done,{eof,2},eof} = erl_scan:tokens(C1, eof, 1), + {done,{eof,2},eof} = erl_scan:tokens(C1, eof, 1), {more, C2} = erl_scan:tokens([], "abra", 1), %% An error before R13A. - %% ?line {done,Err={error,{1,erl_scan,scan},1},eof} = - ?line {done,{ok,[{atom,1,abra}],1},eof} = + %% {done,Err={error,{1,erl_scan,scan},1},eof} = + {done,{ok,[{atom,1,abra}],1},eof} = erl_scan_tokens(C2, eof, 1), %% With column. - ?line {more, C3} = erl_scan:tokens([]," \n",{1,1}), - ?line {done,{eof,{2,1}},eof} = erl_scan:tokens(C3, eof, 1), + {more, C3} = erl_scan:tokens([]," \n",{1,1}), + {done,{eof,{2,1}},eof} = erl_scan:tokens(C3, eof, 1), {more, C4} = erl_scan:tokens([], "abra", {1,1}), %% An error before R13A. - %% ?line {done,{error,{{1,1},erl_scan,scan},{1,5}},eof} = - ?line {done,{ok,[{atom,_,abra}],{1,5}},eof} = + %% {done,{error,{{1,1},erl_scan,scan},{1,5}},eof} = + {done,{ok,[{atom,_,abra}],{1,5}},eof} = erl_scan_tokens(C4, eof, 1), %% Robert's scanner returns "" as LeftoverChars; %% the R12B scanner returns eof as LeftoverChars: (eof is correct) - ?line {more, C5} = erl_scan:tokens([], "a", 1), + {more, C5} = erl_scan:tokens([], "a", 1), %% An error before R13A. - %% ?line {done,{error,{1,erl_scan,scan},1},eof} = - ?line {done,{ok,[{atom,1,a}],1},eof} = + %% {done,{error,{1,erl_scan,scan},1},eof} = + {done,{ok,[{atom,1,a}],1},eof} = erl_scan_tokens(C5,eof,1), %% With column. @@ -533,9 +519,9 @@ eof() -> erl_scan_tokens(C6,eof,1), %% A dot followed by eof is special: - ?line {more, C} = erl_scan:tokens([], "a.", 1), - ?line {done,{ok,[{atom,1,a},{dot,1}],1},eof} = erl_scan_tokens(C,eof,1), - ?line {ok,[{atom,1,foo},{dot,1}],1} = erl_scan_string("foo."), + {more, C} = erl_scan:tokens([], "a.", 1), + {done,{ok,[{atom,1,a},{dot,1}],1},eof} = erl_scan_tokens(C,eof,1), + {ok,[{atom,1,foo},{dot,1}],1} = erl_scan_string("foo."), %% With column. {more, CCol} = erl_scan:tokens([], "a.", {1,1}), @@ -548,100 +534,100 @@ eof() -> illegal() -> Atom = lists:duplicate(1000, $a), - ?line {error,{1,erl_scan,{illegal,atom}},1} = erl_scan:string(Atom), - ?line {done,{error,{1,erl_scan,{illegal,atom}},1},". "} = + {error,{1,erl_scan,{illegal,atom}},1} = erl_scan:string(Atom), + {done,{error,{1,erl_scan,{illegal,atom}},1},". "} = erl_scan:tokens([], Atom++". ", 1), QAtom = "'" ++ Atom ++ "'", - ?line {error,{1,erl_scan,{illegal,atom}},1} = erl_scan:string(QAtom), - ?line {done,{error,{1,erl_scan,{illegal,atom}},1},". "} = + {error,{1,erl_scan,{illegal,atom}},1} = erl_scan:string(QAtom), + {done,{error,{1,erl_scan,{illegal,atom}},1},". "} = erl_scan:tokens([], QAtom++". ", 1), Var = lists:duplicate(1000, $A), - ?line {error,{1,erl_scan,{illegal,var}},1} = erl_scan:string(Var), - ?line {done,{error,{1,erl_scan,{illegal,var}},1},". "} = + {error,{1,erl_scan,{illegal,var}},1} = erl_scan:string(Var), + {done,{error,{1,erl_scan,{illegal,var}},1},". "} = erl_scan:tokens([], Var++". ", 1), Float = "1" ++ lists:duplicate(400, $0) ++ ".0", - ?line {error,{1,erl_scan,{illegal,float}},1} = erl_scan:string(Float), - ?line {done,{error,{1,erl_scan,{illegal,float}},1},". "} = + {error,{1,erl_scan,{illegal,float}},1} = erl_scan:string(Float), + {done,{error,{1,erl_scan,{illegal,float}},1},". "} = erl_scan:tokens([], Float++". ", 1), String = "\"43\\x{aaaaaa}34\"", - ?line {error,{1,erl_scan,{illegal,character}},1} = erl_scan:string(String), - ?line {done,{error,{1,erl_scan,{illegal,character}},1},"34\". "} = + {error,{1,erl_scan,{illegal,character}},1} = erl_scan:string(String), + {done,{error,{1,erl_scan,{illegal,character}},1},"34\". "} = %% Would be nice if `34\"' were skipped... %% Maybe, but then the LeftOverChars would not be the characters %% immediately following the end location of the error. erl_scan:tokens([], String++". ", 1), - ?line {error,{{1,1},erl_scan,{illegal,atom}},{1,1001}} = + {error,{{1,1},erl_scan,{illegal,atom}},{1,1001}} = erl_scan:string(Atom, {1,1}), - ?line {done,{error,{{1,5},erl_scan,{illegal,atom}},{1,1005}},". "} = + {done,{error,{{1,5},erl_scan,{illegal,atom}},{1,1005}},". "} = erl_scan:tokens([], "foo "++Atom++". ", {1,1}), - ?line {error,{{1,1},erl_scan,{illegal,atom}},{1,1003}} = + {error,{{1,1},erl_scan,{illegal,atom}},{1,1003}} = erl_scan:string(QAtom, {1,1}), - ?line {done,{error,{{1,5},erl_scan,{illegal,atom}},{1,1007}},". "} = + {done,{error,{{1,5},erl_scan,{illegal,atom}},{1,1007}},". "} = erl_scan:tokens([], "foo "++QAtom++". ", {1,1}), - ?line {error,{{1,1},erl_scan,{illegal,var}},{1,1001}} = + {error,{{1,1},erl_scan,{illegal,var}},{1,1001}} = erl_scan:string(Var, {1,1}), - ?line {done,{error,{{1,5},erl_scan,{illegal,var}},{1,1005}},". "} = + {done,{error,{{1,5},erl_scan,{illegal,var}},{1,1005}},". "} = erl_scan:tokens([], "foo "++Var++". ", {1,1}), - ?line {error,{{1,1},erl_scan,{illegal,float}},{1,404}} = + {error,{{1,1},erl_scan,{illegal,float}},{1,404}} = erl_scan:string(Float, {1,1}), - ?line {done,{error,{{1,5},erl_scan,{illegal,float}},{1,408}},". "} = + {done,{error,{{1,5},erl_scan,{illegal,float}},{1,408}},". "} = erl_scan:tokens([], "foo "++Float++". ", {1,1}), - ?line {error,{{1,4},erl_scan,{illegal,character}},{1,14}} = + {error,{{1,4},erl_scan,{illegal,character}},{1,14}} = erl_scan:string(String, {1,1}), - ?line {done,{error,{{1,4},erl_scan,{illegal,character}},{1,14}},"34\". "} = + {done,{error,{{1,4},erl_scan,{illegal,character}},{1,14}},"34\". "} = erl_scan:tokens([], String++". ", {1,1}), ok. crashes() -> - ?line {'EXIT',_} = (catch {foo, erl_scan:string([-1])}), % type error - ?line {'EXIT',_} = (catch {foo, erl_scan:string("$"++[-1])}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string("$\\"++[-1])}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string("$\\^"++[-1])}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string([$",-1,$"],{1,1})}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string("\"\\v"++[-1,$"])}), %$" - ?line {'EXIT',_} = (catch {foo, erl_scan:string([$",-1,$"])}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string("% foo"++[-1])}), - ?line {'EXIT',_} = + {'EXIT',_} = (catch {foo, erl_scan:string([-1])}), % type error + {'EXIT',_} = (catch {foo, erl_scan:string("$"++[-1])}), + {'EXIT',_} = (catch {foo, erl_scan:string("$\\"++[-1])}), + {'EXIT',_} = (catch {foo, erl_scan:string("$\\^"++[-1])}), + {'EXIT',_} = (catch {foo, erl_scan:string([$",-1,$"],{1,1})}), + {'EXIT',_} = (catch {foo, erl_scan:string("\"\\v"++[-1,$"])}), %$" + {'EXIT',_} = (catch {foo, erl_scan:string([$",-1,$"])}), + {'EXIT',_} = (catch {foo, erl_scan:string("% foo"++[-1])}), + {'EXIT',_} = (catch {foo, erl_scan:string("% foo"++[-1],{1,1})}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string([a])}), % type error - ?line {'EXIT',_} = (catch {foo, erl_scan:string("$"++[a])}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string("$\\"++[a])}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string("$\\^"++[a])}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string([$",a,$"],{1,1})}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string("\"\\v"++[a,$"])}), %$" - ?line {'EXIT',_} = (catch {foo, erl_scan:string([$",a,$"])}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string("% foo"++[a])}), - ?line {'EXIT',_} = + {'EXIT',_} = (catch {foo, erl_scan:string([a])}), % type error + {'EXIT',_} = (catch {foo, erl_scan:string("$"++[a])}), + {'EXIT',_} = (catch {foo, erl_scan:string("$\\"++[a])}), + {'EXIT',_} = (catch {foo, erl_scan:string("$\\^"++[a])}), + {'EXIT',_} = (catch {foo, erl_scan:string([$",a,$"],{1,1})}), + {'EXIT',_} = (catch {foo, erl_scan:string("\"\\v"++[a,$"])}), %$" + {'EXIT',_} = (catch {foo, erl_scan:string([$",a,$"])}), + {'EXIT',_} = (catch {foo, erl_scan:string("% foo"++[a])}), + {'EXIT',_} = (catch {foo, erl_scan:string("% foo"++[a],{1,1})}), - ?line {'EXIT',_} = (catch {foo, erl_scan:string([3.0])}), % type error + {'EXIT',_} = (catch {foo, erl_scan:string([3.0])}), % type error ok. options() -> %% line and column are not options, but tested here - ?line {ok,[{atom,1,foo},{white_space,1," "},{comment,1,"% bar"}], 1} = + {ok,[{atom,1,foo},{white_space,1," "},{comment,1,"% bar"}], 1} = erl_scan_string("foo % bar", 1, return), - ?line {ok,[{atom,1,foo},{white_space,1," "}],1} = + {ok,[{atom,1,foo},{white_space,1," "}],1} = erl_scan_string("foo % bar", 1, return_white_spaces), - ?line {ok,[{atom,1,foo},{comment,1,"% bar"}],1} = + {ok,[{atom,1,foo},{comment,1,"% bar"}],1} = erl_scan_string("foo % bar", 1, return_comments), - ?line {ok,[{atom,17,foo}],17} = + {ok,[{atom,17,foo}],17} = erl_scan_string("foo % bar", 17), - ?line {'EXIT',{function_clause,_}} = + {'EXIT',{function_clause,_}} = (catch {foo, erl_scan:string("foo % bar", {a,1}, [])}), % type error - ?line {ok,[{atom,_,foo}],{17,18}} = + {ok,[{atom,_,foo}],{17,18}} = erl_scan_string("foo % bar", {17,9}, []), - ?line {'EXIT',{function_clause,_}} = + {'EXIT',{function_clause,_}} = (catch {foo, erl_scan:string("foo % bar", {1,0}, [])}), % type error - ?line {ok,[{foo,1}],1} = + {ok,[{foo,1}],1} = erl_scan_string("foo % bar",1, [{reserved_word_fun, fun(W) -> W =:= foo end}]), - ?line {'EXIT',{badarg,_}} = + {'EXIT',{badarg,_}} = (catch {foo, erl_scan:string("foo % bar",1, % type error [{reserved_word_fun, @@ -716,40 +702,40 @@ anno_info() -> ok. column_errors() -> - ?line {error,{{1,1},erl_scan,{string,$',""}},{1,3}} = % $' + {error,{{1,1},erl_scan,{string,$',""}},{1,3}} = % $' erl_scan:string("'\\",{1,1}), - ?line {error,{{1,1},erl_scan,{string,$",""}},{1,3}} = % $" + {error,{{1,1},erl_scan,{string,$",""}},{1,3}} = % $" erl_scan:string("\"\\",{1,1}), - ?line {error,{{1,1},erl_scan,{string,$',""}},{1,2}} = % $' + {error,{{1,1},erl_scan,{string,$',""}},{1,2}} = % $' erl_scan:string("'",{1,1}), - ?line {error,{{1,1},erl_scan,{string,$",""}},{1,2}} = % $" + {error,{{1,1},erl_scan,{string,$",""}},{1,2}} = % $" erl_scan:string("\"",{1,1}), - ?line {error,{{1,1},erl_scan,char},{1,2}} = + {error,{{1,1},erl_scan,char},{1,2}} = erl_scan:string("$",{1,1}), - ?line {error,{{1,2},erl_scan,{string,$',"1234567890123456"}},{1,20}} = %' + {error,{{1,2},erl_scan,{string,$',"1234567890123456"}},{1,20}} = %' erl_scan:string(" '12345678901234567", {1,1}), - ?line {error,{{1,2},erl_scan,{string,$',"123456789012345 "}}, {1,20}} = %' + {error,{{1,2},erl_scan,{string,$',"123456789012345 "}}, {1,20}} = %' erl_scan:string(" '123456789012345\\s", {1,1}), - ?line {error,{{1,2},erl_scan,{string,$","1234567890123456"}},{1,20}} = %" + {error,{{1,2},erl_scan,{string,$","1234567890123456"}},{1,20}} = %" erl_scan:string(" \"12345678901234567", {1,1}), - ?line {error,{{1,2},erl_scan,{string,$","123456789012345 "}}, {1,20}} = %" + {error,{{1,2},erl_scan,{string,$","123456789012345 "}}, {1,20}} = %" erl_scan:string(" \"123456789012345\\s", {1,1}), - ?line {error,{{1,2},erl_scan,{string,$',"1234567890123456"}},{2,1}} = %' + {error,{{1,2},erl_scan,{string,$',"1234567890123456"}},{2,1}} = %' erl_scan:string(" '12345678901234567\n", {1,1}), ok. white_spaces() -> - ?line {ok,[{white_space,_,"\r"}, + {ok,[{white_space,_,"\r"}, {white_space,_," "}, {atom,_,a}, {white_space,_,"\n"}], _} = erl_scan_string("\r a\n", {1,1}, return), - ?line test("\r a\n"), + test("\r a\n"), L = "{\"a\nb\", \"a\\nb\",\nabc\r,def}.\n\n", - ?line {ok,[{'{',_}, + {ok,[{'{',_}, {string,_,"a\nb"}, {',',_}, {white_space,_," "}, @@ -764,33 +750,33 @@ white_spaces() -> {dot,_}, {white_space,_,"\n"}], _} = erl_scan_string(L, {1,1}, return), - ?line test(L), - ?line test("\"\n\"\n"), - ?line test("\n\r\n"), - ?line test("\n\r"), - ?line test("\r\n"), - ?line test("\n\f"), - ?line [test(lists:duplicate(N, $\t)) || N <- lists:seq(1, 20)], - ?line [test([$\n|lists:duplicate(N, $\t)]) || N <- lists:seq(1, 20)], - ?line [test(lists:duplicate(N, $\s)) || N <- lists:seq(1, 20)], - ?line [test([$\n|lists:duplicate(N, $\s)]) || N <- lists:seq(1, 20)], - ?line test("\v\f\n\v "), - ?line test("\n\e\n\b\f\n\da\n"), + test(L), + test("\"\n\"\n"), + test("\n\r\n"), + test("\n\r"), + test("\r\n"), + test("\n\f"), + [test(lists:duplicate(N, $\t)) || N <- lists:seq(1, 20)], + [test([$\n|lists:duplicate(N, $\t)]) || N <- lists:seq(1, 20)], + [test(lists:duplicate(N, $\s)) || N <- lists:seq(1, 20)], + [test([$\n|lists:duplicate(N, $\s)]) || N <- lists:seq(1, 20)], + test("\v\f\n\v "), + test("\n\e\n\b\f\n\da\n"), ok. unicode() -> - ?line {ok,[{char,1,83},{integer,1,45}],1} = + {ok,[{char,1,83},{integer,1,45}],1} = erl_scan_string("$\\12345"), % not unicode - ?line {error,{1,erl_scan,{illegal,character}},1} = + {error,{1,erl_scan,{illegal,character}},1} = erl_scan:string([1089]), - ?line {error,{{1,1},erl_scan,{illegal,character}},{1,2}} = + {error,{{1,1},erl_scan,{illegal,character}},{1,2}} = erl_scan:string([1089], {1,1}), {error,{1,erl_scan,{illegal,atom}},1} = erl_scan:string("'a"++[1089]++"b'", 1), {error,{{1,1},erl_scan,{illegal,atom}},{1,6}} = erl_scan:string("'a"++[1089]++"b'", {1,1}), - ?line test("\"a"++[1089]++"b\""), + test("\"a"++[1089]++"b\""), {ok,[{char,1,1}],1} = erl_scan_string([$$,$\\,$^,1089], 1), @@ -798,7 +784,7 @@ unicode() -> erl_scan:string("\"qa\x{aaa}", 1), "unterminated string starting with \"qa"++[2730]++"\"" = erl_scan:format_error(Error), - ?line {error,{{1,1},erl_scan,_},{1,11}} = + {error,{{1,1},erl_scan,_},{1,11}} = erl_scan:string("\"qa\\x{aaa}",{1,1}), {error,{{1,1},erl_scan,{illegal,atom}},{1,12}} = erl_scan:string("'qa\\x{aaa}'",{1,1}), @@ -832,17 +818,17 @@ unicode() -> {ok,[{string,1,[$\n,$\x{aaa},$\n]}],3} = erl_scan_string(U4, 1), %% Keep these tests: - ?line test(Qs), - ?line test(U1), - ?line test(U2), - ?line test(U3), - ?line test(U4), + test(Qs), + test(U1), + test(U2), + test(U3), + test(U4), Str1 = "\"ab" ++ [1089] ++ "cd\"", {ok,[{string,1,[$a,$b,1089,$c,$d]}],1} = erl_scan_string(Str1, 1), {ok,[{string,{1,1},[$a,$b,1089,$c,$d]}],{1,8}} = erl_scan_string(Str1, {1,1}), - ?line test(Str1), + test(Str1), Comment = "%% "++[1089], {ok,[{comment,1,[$%,$%,$\s,1089]}],1} = erl_scan_string(Comment, 1, [return]), @@ -855,70 +841,67 @@ more_chars() -> %% $\x{...}, $\xHH %% All kinds of tests... - ?line {ok,[{char,_,123}],{1,4}} = + {ok,[{char,_,123}],{1,4}} = erl_scan_string("$\\{",{1,1}), - ?line {more, C1} = erl_scan:tokens([], "$\\{", {1,1}), - ?line {done,{ok,[{char,_,123}],{1,4}},eof} = + {more, C1} = erl_scan:tokens([], "$\\{", {1,1}), + {done,{ok,[{char,_,123}],{1,4}},eof} = erl_scan_tokens(C1, eof, 1), - ?line {ok,[{char,1,123},{atom,1,a},{'}',1}],1} = + {ok,[{char,1,123},{atom,1,a},{'}',1}],1} = erl_scan_string("$\\{a}"), - ?line {error,{{1,1},erl_scan,char},{1,4}} = + {error,{{1,1},erl_scan,char},{1,4}} = erl_scan:string("$\\x", {1,1}), - ?line {error,{{1,1},erl_scan,char},{1,5}} = + {error,{{1,1},erl_scan,char},{1,5}} = erl_scan:string("$\\x{",{1,1}), - ?line {more, C3} = erl_scan:tokens([], "$\\x", {1,1}), - ?line {done,{error,{{1,1},erl_scan,char},{1,4}},eof} = + {more, C3} = erl_scan:tokens([], "$\\x", {1,1}), + {done,{error,{{1,1},erl_scan,char},{1,4}},eof} = erl_scan:tokens(C3, eof, 1), - ?line {error,{{1,1},erl_scan,char},{1,5}} = + {error,{{1,1},erl_scan,char},{1,5}} = erl_scan:string("$\\x{",{1,1}), - ?line {more, C2} = erl_scan:tokens([], "$\\x{", {1,1}), - ?line {done,{error,{{1,1},erl_scan,char},{1,5}},eof} = + {more, C2} = erl_scan:tokens([], "$\\x{", {1,1}), + {done,{error,{{1,1},erl_scan,char},{1,5}},eof} = erl_scan:tokens(C2, eof, 1), - ?line {error,{1,erl_scan,{illegal,character}},1} = + {error,{1,erl_scan,{illegal,character}},1} = erl_scan:string("$\\x{g}"), - ?line {error,{{1,1},erl_scan,{illegal,character}},{1,5}} = + {error,{{1,1},erl_scan,{illegal,character}},{1,5}} = erl_scan:string("$\\x{g}", {1,1}), - ?line {error,{{1,1},erl_scan,{illegal,character}},{1,6}} = + {error,{{1,1},erl_scan,{illegal,character}},{1,6}} = erl_scan:string("$\\x{}",{1,1}), - ?line test("\"\\{0}\""), - ?line test("\"\\x{0}\""), - ?line test("\'\\{0}\'"), - ?line test("\'\\x{0}\'"), + test("\"\\{0}\""), + test("\"\\x{0}\""), + test("\'\\{0}\'"), + test("\'\\x{0}\'"), - ?line {error,{{2,3},erl_scan,{illegal,character}},{2,6}} = + {error,{{2,3},erl_scan,{illegal,character}},{2,6}} = erl_scan:string("\"ab \n $\\x{g}\"",{1,1}), - ?line {error,{{2,3},erl_scan,{illegal,character}},{2,6}} = + {error,{{2,3},erl_scan,{illegal,character}},{2,6}} = erl_scan:string("\'ab \n $\\x{g}\'",{1,1}), - ?line test("$\\{34}"), - ?line test("$\\x{34}"), - ?line test("$\\{377}"), - ?line test("$\\x{FF}"), - ?line test("$\\{400}"), - ?line test("$\\x{100}"), - ?line test("$\\x{10FFFF}"), - ?line test("$\\x{10ffff}"), - ?line test("\"$\n \\{1}\""), - ?line {error,{1,erl_scan,{illegal,character}},1} = + test("$\\{34}"), + test("$\\x{34}"), + test("$\\{377}"), + test("$\\x{FF}"), + test("$\\{400}"), + test("$\\x{100}"), + test("$\\x{10FFFF}"), + test("$\\x{10ffff}"), + test("\"$\n \\{1}\""), + {error,{1,erl_scan,{illegal,character}},1} = erl_scan:string("$\\x{110000}"), - ?line {error,{{1,1},erl_scan,{illegal,character}},{1,12}} = + {error,{{1,1},erl_scan,{illegal,character}},{1,12}} = erl_scan:string("$\\x{110000}", {1,1}), - ?line {error,{{1,1},erl_scan,{illegal,character}},{1,4}} = + {error,{{1,1},erl_scan,{illegal,character}},{1,4}} = erl_scan:string("$\\xfg", {1,1}), - ?line test("$\\xffg"), + test("$\\xffg"), - ?line {error,{{1,1},erl_scan,{illegal,character}},{1,4}} = + {error,{{1,1},erl_scan,{illegal,character}},{1,4}} = erl_scan:string("$\\xg", {1,1}), ok. -otp_10302(doc) -> - "OTP-10302. Unicode characters scanner/parser."; -otp_10302(suite) -> - []; +%% OTP-10302. Unicode characters scanner/parser. otp_10302(Config) when is_list(Config) -> %% From unicode(): {error,{1,erl_scan,{illegal,atom}},1} = @@ -1088,18 +1071,12 @@ otp_10302(Config) when is_list(Config) -> erl_parse_abstract("a"++[1024]++"c", [{encoding,latin1}]), ok. -otp_10990(doc) -> - "OTP-10990. Floating point number in input string."; -otp_10990(suite) -> - []; +%% OTP-10990. Floating point number in input string. otp_10990(Config) when is_list(Config) -> {'EXIT',_} = (catch {foo, erl_scan:string([$",42.0,$"],1)}), ok. -otp_10992(doc) -> - "OTP-10992. List of floats to abstract format."; -otp_10992(suite) -> - []; +%% OTP-10992. List of floats to abstract format. otp_10992(Config) when is_list(Config) -> {cons,0,{float,0,42.0},{nil,0}} = erl_parse_abstract([42.0], [{encoding,unicode}]), @@ -1111,10 +1088,7 @@ otp_10992(Config) when is_list(Config) -> erl_parse_abstract([$A,42.0], [{encoding,utf8}]), ok. -otp_11807(doc) -> - "OTP-11807. Generalize erl_parse:abstract/2."; -otp_11807(suite) -> - []; +%% OTP-11807. Generalize erl_parse:abstract/2. otp_11807(Config) when is_list(Config) -> {cons,0,{integer,0,97},{cons,0,{integer,0,98},{nil,0}}} = erl_parse_abstract("ab", [{encoding,none}]), diff --git a/lib/stdlib/test/error_logger_h_SUITE.erl b/lib/stdlib/test/error_logger_h_SUITE.erl index b2f1618ff5..30811f3fb4 100644 --- a/lib/stdlib/test/error_logger_h_SUITE.erl +++ b/lib/stdlib/test/error_logger_h_SUITE.erl @@ -48,7 +48,7 @@ end_per_group(_GroupName, Config) -> Config. logfile(Config) -> - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), LogDir = filename:join(PrivDir, ?MODULE), Log = filename:join(LogDir, "logfile.log"), ok = filelib:ensure_dir(Log), @@ -77,7 +77,7 @@ logfile(Config) -> ok. logfile_truncated(Config) -> - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), LogDir = filename:join(PrivDir, ?MODULE), Log = filename:join(LogDir, "logfile_truncated.log"), ok = filelib:ensure_dir(Log), @@ -102,7 +102,7 @@ do_one_logfile(Log, Ev, Depth) -> analyse_events(Log, Ev, [], Depth). tty(Config) -> - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), LogDir = filename:join(PrivDir, ?MODULE), Log = filename:join(LogDir, "tty.log"), ok = filelib:ensure_dir(Log), @@ -125,7 +125,7 @@ tty(Config) -> ok. tty_truncated(Config) -> - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), LogDir = filename:join(PrivDir, ?MODULE), Log = filename:join(LogDir, "tty_truncated.log"), ok = filelib:ensure_dir(Log), @@ -335,7 +335,7 @@ start_node(Name, Args) -> {ok,Node} -> {ok,Node}; Error -> - test_server:fail(Error) + ct:fail(Error) end. cleanup(File) -> diff --git a/lib/stdlib/test/escript_SUITE.erl b/lib/stdlib/test/escript_SUITE.erl index a8d646c044..30aaac70c2 100644 --- a/lib/stdlib/test/escript_SUITE.erl +++ b/lib/stdlib/test/escript_SUITE.erl @@ -19,7 +19,7 @@ -module(escript_SUITE). -export([ - all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, + all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2, init_per_testcase/2, end_per_testcase/2, @@ -43,7 +43,9 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("kernel/include/file.hrl"). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,5}}]. all() -> [basic, errors, strange_name, emulator_flags, @@ -68,103 +70,100 @@ end_per_group(_GroupName, Config) -> Config. init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?t:minutes(5)), - [{watchdog,Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% basic(Config) when is_list(Config) -> - Data = ?config(data_dir, Config), + Data = proplists:get_value(data_dir, Config), Dir = filename:absname(Data), %Get rid of trailing slash. - ?line run(Dir, "factorial 5", - <<"factorial 5 = 120\nExitCode:0">>), - ?line run(Dir, "factorial_compile 10", - <<"factorial 10 = 3628800\nExitCode:0">>), - ?line run(Dir, "factorial_compile_main 7", - <<"factorial 7 = 5040\nExitCode:0">>), - ?line run(Dir, "factorial_warning 20", - [data_dir,<<"factorial_warning:12: Warning: function bar/0 is unused\n" - "factorial 20 = 2432902008176640000\nExitCode:0">>]), - ?line run_with_opts(Dir, "-s", "factorial_warning", - [data_dir,<<"factorial_warning:12: Warning: function bar/0 is unused\nExitCode:0">>]), - ?line run_with_opts(Dir, "-s -i", "factorial_warning", - [data_dir,<<"factorial_warning:12: Warning: function bar/0 is unused\nExitCode:0">>]), - ?line run_with_opts(Dir, "-c -s", "factorial_warning", - [data_dir,<<"factorial_warning:12: Warning: function bar/0 is unused\nExitCode:0">>]), - ?line run(Dir, "filesize "++filename:join(?config(data_dir, Config),"filesize"), - [data_dir,<<"filesize:11: Warning: function id/1 is unused\n324\nExitCode:0">>]), - ?line run(Dir, "test_script_name", - [data_dir,<<"test_script_name\nExitCode:0">>]), - ?line run(Dir, "tail_rec 1000", - [<<"ok\nExitCode:0">>]), + run(Dir, "factorial 5", + <<"factorial 5 = 120\nExitCode:0">>), + run(Dir, "factorial_compile 10", + <<"factorial 10 = 3628800\nExitCode:0">>), + run(Dir, "factorial_compile_main 7", + <<"factorial 7 = 5040\nExitCode:0">>), + run(Dir, "factorial_warning 20", + [data_dir,<<"factorial_warning:12: Warning: function bar/0 is unused\n" + "factorial 20 = 2432902008176640000\nExitCode:0">>]), + run_with_opts(Dir, "-s", "factorial_warning", + [data_dir,<<"factorial_warning:12: Warning: function bar/0 is unused\nExitCode:0">>]), + run_with_opts(Dir, "-s -i", "factorial_warning", + [data_dir,<<"factorial_warning:12: Warning: function bar/0 is unused\nExitCode:0">>]), + run_with_opts(Dir, "-c -s", "factorial_warning", + [data_dir,<<"factorial_warning:12: Warning: function bar/0 is unused\nExitCode:0">>]), + run(Dir, "filesize "++filename:join(proplists:get_value(data_dir, Config),"filesize"), + [data_dir,<<"filesize:11: Warning: function id/1 is unused\n324\nExitCode:0">>]), + run(Dir, "test_script_name", + [data_dir,<<"test_script_name\nExitCode:0">>]), + run(Dir, "tail_rec 1000", + [<<"ok\nExitCode:0">>]), %% We expect the trap_exit flag for the process to be false, %% since that is the default state for newly spawned processes. - ?line run(Dir, "trap_exit", - <<"false\nExitCode:0">>), + run(Dir, "trap_exit", + <<"false\nExitCode:0">>), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% errors(Config) when is_list(Config) -> - Data = ?config(data_dir, Config), + Data = proplists:get_value(data_dir, Config), Dir = filename:absname(Data), %Get rid of trailing slash. - ?line run(Dir, "compile_error", - [data_dir,<<"compile_error:5: syntax error before: '*'\n">>, - data_dir,<<"compile_error:8: syntax error before: blarf\n">>, - <<"escript: There were compilation errors.\nExitCode:127">>]), - ?line run(Dir, "lint_error", - [data_dir,<<"lint_error:6: function main/1 already defined\n">>, - data_dir,"lint_error:8: variable 'ExitCode' is unbound\n", - <<"escript: There were compilation errors.\nExitCode:127">>]), - ?line run_with_opts(Dir, "-s", "lint_error", - [data_dir,<<"lint_error:6: function main/1 already defined\n">>, - data_dir,"lint_error:8: variable 'ExitCode' is unbound\n", - <<"escript: There were compilation errors.\nExitCode:127">>]), + run(Dir, "compile_error", + [data_dir,<<"compile_error:5: syntax error before: '*'\n">>, + data_dir,<<"compile_error:8: syntax error before: blarf\n">>, + <<"escript: There were compilation errors.\nExitCode:127">>]), + run(Dir, "lint_error", + [data_dir,<<"lint_error:6: function main/1 already defined\n">>, + data_dir,"lint_error:8: variable 'ExitCode' is unbound\n", + <<"escript: There were compilation errors.\nExitCode:127">>]), + run_with_opts(Dir, "-s", "lint_error", + [data_dir,<<"lint_error:6: function main/1 already defined\n">>, + data_dir,"lint_error:8: variable 'ExitCode' is unbound\n", + <<"escript: There were compilation errors.\nExitCode:127">>]), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% strange_name(Config) when is_list(Config) -> - Data = ?config(data_dir, Config), + Data = proplists:get_value(data_dir, Config), Dir = filename:absname(Data), %Get rid of trailing slash. - ?line run(Dir, "strange.name -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "ExitCode:0">>]), + run(Dir, "strange.name -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "ExitCode:0">>]), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% emulator_flags(Config) when is_list(Config) -> - Data = ?config(data_dir, Config), + Data = proplists:get_value(data_dir, Config), Dir = filename:absname(Data), %Get rid of trailing slash. - ?line run(Dir, "emulator_flags -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[{nostick,[]}]\n" - "mnesia:[{mnesia,[\"dir\",\"a/directory\"]},{mnesia,[\"debug\",\"verbose\"]}]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), + run(Dir, "emulator_flags -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[{nostick,[]}]\n" + "mnesia:[{mnesia,[\"dir\",\"a/directory\"]},{mnesia,[\"debug\",\"verbose\"]}]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% emulator_flags_no_shebang(Config) when is_list(Config) -> - Data = ?config(data_dir, Config), + Data = proplists:get_value(data_dir, Config), Dir = filename:absname(Data), %Get rid of trailing slash. %% Need run_with_opts, to always use "escript" explicitly - ?line run_with_opts(Dir, "", "emulator_flags_no_shebang -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[{nostick,[]}]\n" - "mnesia:[{mnesia,[\"dir\",\"a/directory\"]},{mnesia,[\"debug\",\"verbose\"]}]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), + run_with_opts(Dir, "", "emulator_flags_no_shebang -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[{nostick,[]}]\n" + "mnesia:[{mnesia,[\"dir\",\"a/directory\"]},{mnesia,[\"debug\",\"verbose\"]}]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -173,14 +172,14 @@ emulator_flags_no_shebang(Config) when is_list(Config) -> module_script(Config) when is_list(Config) -> %% Read orig file - Data = ?config(data_dir, Config), + Data = proplists:get_value(data_dir, Config), OrigFile = filename:join([Data,"emulator_flags"]), {ok, OrigBin} = file:read_file(OrigFile), - ?line [Shebang, Mode, Flags | Source] = string:tokens(binary_to_list(OrigBin), "\n"), - ?line {ok, OrigFI} = file:read_file_info(OrigFile), + [Shebang, Mode, Flags | Source] = string:tokens(binary_to_list(OrigBin), "\n"), + {ok, OrigFI} = file:read_file_info(OrigFile), %% Write source file - Priv = ?config(priv_dir, Config), + Priv = proplists:get_value(priv_dir, Config), Dir = filename:absname(Priv), % Get rid of trailing slash. Base = "module_script", ErlFile = filename:join([Priv, Base ++ ".erl"]), @@ -188,85 +187,85 @@ module_script(Config) when is_list(Config) -> "-export([main/1]).\n\n", string:join(Source, "\n"), "\n"], - ?line ok = file:write_file(ErlFile, ErlCode), + ok = file:write_file(ErlFile, ErlCode), - %%%%%%% +%%%%%%% %% Create and run scripts without emulator flags %% With shebang NoArgsBase = Base ++ "_no_args_with_shebang", NoArgsFile = filename:join([Priv, NoArgsBase]), - ?line ok = file:write_file(NoArgsFile, - [Shebang, "\n", - ErlCode]), - ?line ok = file:write_file_info(NoArgsFile, OrigFI), - - ?line run(Dir, NoArgsBase ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[]\n" - "mnesia:[]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), - - ?line run_with_opts(Dir, "", NoArgsBase ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[]\n" - "mnesia:[]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), + ok = file:write_file(NoArgsFile, + [Shebang, "\n", + ErlCode]), + ok = file:write_file_info(NoArgsFile, OrigFI), + + run(Dir, NoArgsBase ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[]\n" + "mnesia:[]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), + + run_with_opts(Dir, "", NoArgsBase ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[]\n" + "mnesia:[]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), %% Without shebang NoArgsBase2 = Base ++ "_no_args_without_shebang", NoArgsFile2 = filename:join([Priv, NoArgsBase2]), - ?line ok = file:write_file(NoArgsFile2, - ["Something else than shebang!!!", "\n", - ErlCode]), - ?line ok = file:write_file_info(NoArgsFile2, OrigFI), - - ?line run_with_opts(Dir, "", NoArgsBase2 ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[]\n" - "mnesia:[]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), + ok = file:write_file(NoArgsFile2, + ["Something else than shebang!!!", "\n", + ErlCode]), + ok = file:write_file_info(NoArgsFile2, OrigFI), + + run_with_opts(Dir, "", NoArgsBase2 ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[]\n" + "mnesia:[]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), %% Plain module without header NoArgsBase3 = Base ++ "_no_args_without_header", NoArgsFile3 = filename:join([Priv, NoArgsBase3]), - ?line ok = file:write_file(NoArgsFile3, [ErlCode]), - ?line ok = file:write_file_info(NoArgsFile3, OrigFI), - - ?line run_with_opts(Dir, "", NoArgsBase3 ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[]\n" - "mnesia:[]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), - - %%%%%%% + ok = file:write_file(NoArgsFile3, [ErlCode]), + ok = file:write_file_info(NoArgsFile3, OrigFI), + + run_with_opts(Dir, "", NoArgsBase3 ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[]\n" + "mnesia:[]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), + +%%%%%%% %% Create and run scripts with emulator flags %% With shebang ArgsBase = Base ++ "_args_with_shebang", ArgsFile = filename:join([Priv, ArgsBase]), - ?line ok = file:write_file(ArgsFile, - [Shebang, "\n", - Mode, "\n", - Flags, "\n", - ErlCode]), - ?line ok = file:write_file_info(ArgsFile, OrigFI), - - ?line run(Dir, ArgsBase ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[{nostick,[]}]\n" - "mnesia:[{mnesia,[\"dir\",\"a/directory\"]},{mnesia,[\"debug\",\"verbose\"]}]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), + ok = file:write_file(ArgsFile, + [Shebang, "\n", + Mode, "\n", + Flags, "\n", + ErlCode]), + ok = file:write_file_info(ArgsFile, OrigFI), + + run(Dir, ArgsBase ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[{nostick,[]}]\n" + "mnesia:[{mnesia,[\"dir\",\"a/directory\"]},{mnesia,[\"debug\",\"verbose\"]}]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), ok. @@ -275,103 +274,103 @@ module_script(Config) when is_list(Config) -> %% Generate a new escript containing the beam code and the escript header beam_script(Config) when is_list(Config) -> %% Read orig file - Data = ?config(data_dir, Config), + Data = proplists:get_value(data_dir, Config), OrigFile = filename:join([Data,"emulator_flags"]), {ok, OrigBin} = file:read_file(OrigFile), - ?line [Shebang, Mode, Flags | Source] = string:tokens(binary_to_list(OrigBin), "\n"), - ?line {ok, OrigFI} = file:read_file_info(OrigFile), + [Shebang, Mode, Flags | Source] = string:tokens(binary_to_list(OrigBin), "\n"), + {ok, OrigFI} = file:read_file_info(OrigFile), %% Write source file - Priv = ?config(priv_dir, Config), + Priv = proplists:get_value(priv_dir, Config), Dir = filename:absname(Priv), % Get rid of trailing slash. Base = "beam_script", ErlFile = filename:join([Priv, Base ++ ".erl"]), - ?line ok = file:write_file(ErlFile, - ["\n-module(", Base, ").\n", - "-export([main/1]).\n\n", - string:join(Source, "\n"), - "\n"]), + ok = file:write_file(ErlFile, + ["\n-module(", Base, ").\n", + "-export([main/1]).\n\n", + string:join(Source, "\n"), + "\n"]), %% Compile the code - ?line {ok, _Mod, BeamCode} = compile:file(ErlFile, [binary]), + {ok, _Mod, BeamCode} = compile:file(ErlFile, [binary]), - %%%%%%% +%%%%%%% %% Create and run scripts without emulator flags %% With shebang NoArgsBase = Base ++ "_no_args_with_shebang", NoArgsFile = filename:join([Priv, NoArgsBase]), - ?line ok = file:write_file(NoArgsFile, - [Shebang, "\n", - BeamCode]), - ?line ok = file:write_file_info(NoArgsFile, OrigFI), - - ?line run(Dir, NoArgsBase ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[]\n" - "mnesia:[]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), - - ?line run_with_opts(Dir, "", NoArgsBase ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[]\n" - "mnesia:[]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), + ok = file:write_file(NoArgsFile, + [Shebang, "\n", + BeamCode]), + ok = file:write_file_info(NoArgsFile, OrigFI), + + run(Dir, NoArgsBase ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[]\n" + "mnesia:[]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), + + run_with_opts(Dir, "", NoArgsBase ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[]\n" + "mnesia:[]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), %% Without shebang NoArgsBase2 = Base ++ "_no_args_without_shebang", NoArgsFile2 = filename:join([Priv, NoArgsBase2]), - ?line ok = file:write_file(NoArgsFile2, - ["Something else than shebang!!!", "\n", - BeamCode]), - ?line ok = file:write_file_info(NoArgsFile2, OrigFI), - - ?line run_with_opts(Dir, "", NoArgsBase2 ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[]\n" - "mnesia:[]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), + ok = file:write_file(NoArgsFile2, + ["Something else than shebang!!!", "\n", + BeamCode]), + ok = file:write_file_info(NoArgsFile2, OrigFI), + + run_with_opts(Dir, "", NoArgsBase2 ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[]\n" + "mnesia:[]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), %% Plain beam file without header NoArgsBase3 = Base ++ "_no_args_without_header", NoArgsFile3 = filename:join([Priv, NoArgsBase3]), - ?line ok = file:write_file(NoArgsFile3, [BeamCode]), - ?line ok = file:write_file_info(NoArgsFile3, OrigFI), - - ?line run_with_opts(Dir, "", NoArgsBase3 ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[]\n" - "mnesia:[]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), - - %%%%%%% + ok = file:write_file(NoArgsFile3, [BeamCode]), + ok = file:write_file_info(NoArgsFile3, OrigFI), + + run_with_opts(Dir, "", NoArgsBase3 ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[]\n" + "mnesia:[]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), + +%%%%%%% %% Create and run scripts with emulator flags %% With shebang ArgsBase = Base ++ "_args", ArgsFile = filename:join([Priv, ArgsBase]), - ?line ok = file:write_file(ArgsFile, - [Shebang, "\n", - Mode, "\n", - Flags, "\n", - BeamCode]), - ?line ok = file:write_file_info(ArgsFile, OrigFI), - - ?line run(Dir, ArgsBase ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "nostick:[{nostick,[]}]\n" - "mnesia:[{mnesia,[\"dir\",\"a/directory\"]},{mnesia,[\"debug\",\"verbose\"]}]\n" - "ERL_FLAGS=false\n" - "unknown:[]\n" - "ExitCode:0">>]), + ok = file:write_file(ArgsFile, + [Shebang, "\n", + Mode, "\n", + Flags, "\n", + BeamCode]), + ok = file:write_file_info(ArgsFile, OrigFI), + + run(Dir, ArgsBase ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "nostick:[{nostick,[]}]\n" + "mnesia:[{mnesia,[\"dir\",\"a/directory\"]},{mnesia,[\"debug\",\"verbose\"]}]\n" + "ERL_FLAGS=false\n" + "unknown:[]\n" + "ExitCode:0">>]), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -381,107 +380,107 @@ beam_script(Config) when is_list(Config) -> archive_script(Config) when is_list(Config) -> %% Copy the orig files to priv_dir - DataDir = ?config(data_dir, Config), - PrivDir = ?config(priv_dir, Config), + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), Archive = filename:join([PrivDir, "archive_script.zip"]), - ?line {ok, _} = zip:create(Archive, ["archive_script"], - [{compress, []}, {cwd, DataDir}]), - ?line {ok, _} = zip:extract(Archive, [{cwd, PrivDir}]), + {ok, _} = zip:create(Archive, ["archive_script"], + [{compress, []}, {cwd, DataDir}]), + {ok, _} = zip:extract(Archive, [{cwd, PrivDir}]), TopDir = filename:join([PrivDir, "archive_script"]), %% Compile the code - ?line ok = compile_app(TopDir, "archive_script_dict"), - ?line ok = compile_app(TopDir, "archive_script_dummy"), - ?line {ok, MainFiles} = file:list_dir(TopDir), - ?line ok = compile_files(MainFiles, TopDir, TopDir), + ok = compile_app(TopDir, "archive_script_dict"), + ok = compile_app(TopDir, "archive_script_dummy"), + {ok, MainFiles} = file:list_dir(TopDir), + ok = compile_files(MainFiles, TopDir, TopDir), %% Create the archive {ok, TopFiles} = file:list_dir(TopDir), - ?line {ok, {_, ArchiveBin}} = zip:create(Archive, TopFiles, - [memory, {compress, []}, {cwd, TopDir}]), + {ok, {_, ArchiveBin}} = zip:create(Archive, TopFiles, + [memory, {compress, []}, {cwd, TopDir}]), %% Read the source script OrigFile = filename:join([DataDir, "emulator_flags"]), {ok, OrigBin} = file:read_file(OrigFile), - ?line [Shebang, Mode, _Flags | _Source] = + [Shebang, Mode, _Flags | _Source] = string:tokens(binary_to_list(OrigBin), "\n"), Flags = "%%! -archive_script_dict foo bar" " -archive_script_dict foo" " -archive_script_dummy bar", - ?line {ok, OrigFI} = file:read_file_info(OrigFile), + {ok, OrigFI} = file:read_file_info(OrigFile), - %%%%%%% +%%%%%%% %% Create and run scripts without emulator flags MainBase = "archive_script_main", MainScript = filename:join([PrivDir, MainBase]), %% With shebang - ?line ok = file:write_file(MainScript, - [Shebang, "\n", - Flags, "\n", - ArchiveBin]), - ?line ok = file:write_file_info(MainScript, OrigFI), - - ?line run(PrivDir, MainBase ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "dict:[{archive_script_dict,[\"foo\",\"bar\"]},{archive_script_dict,[\"foo\"]}]\n" - "dummy:[{archive_script_dummy,[\"bar\"]}]\n" - "priv:{ok,<<\"Some private data...\\n\">>}\n" - "ExitCode:0">>]), - - ?line run_with_opts(PrivDir, "", MainBase ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "dict:[{archive_script_dict,[\"foo\",\"bar\"]},{archive_script_dict,[\"foo\"]}]\n" - "dummy:[{archive_script_dummy,[\"bar\"]}]\n" - "priv:{ok,<<\"Some private data...\\n\">>}\n" - "ExitCode:0">>]), - - ?line ok = file:rename(MainScript, MainScript ++ "_with_shebang"), + ok = file:write_file(MainScript, + [Shebang, "\n", + Flags, "\n", + ArchiveBin]), + ok = file:write_file_info(MainScript, OrigFI), + + run(PrivDir, MainBase ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "dict:[{archive_script_dict,[\"foo\",\"bar\"]},{archive_script_dict,[\"foo\"]}]\n" + "dummy:[{archive_script_dummy,[\"bar\"]}]\n" + "priv:{ok,<<\"Some private data...\\n\">>}\n" + "ExitCode:0">>]), + + run_with_opts(PrivDir, "", MainBase ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "dict:[{archive_script_dict,[\"foo\",\"bar\"]},{archive_script_dict,[\"foo\"]}]\n" + "dummy:[{archive_script_dummy,[\"bar\"]}]\n" + "priv:{ok,<<\"Some private data...\\n\">>}\n" + "ExitCode:0">>]), + + ok = file:rename(MainScript, MainScript ++ "_with_shebang"), %% Without shebang (no flags) - ?line ok = file:write_file(MainScript, - ["Something else than shebang!!!", "\n", - ArchiveBin]), - ?line ok = file:write_file_info(MainScript, OrigFI), - - ?line run_with_opts(PrivDir, "", MainBase ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "dict:[]\n" - "dummy:[]\n" - "priv:{ok,<<\"Some private data...\\n\">>}\n" - "ExitCode:0">>]), - ?line ok = file:rename(MainScript, MainScript ++ "_without_shebang"), + ok = file:write_file(MainScript, + ["Something else than shebang!!!", "\n", + ArchiveBin]), + ok = file:write_file_info(MainScript, OrigFI), + + run_with_opts(PrivDir, "", MainBase ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "dict:[]\n" + "dummy:[]\n" + "priv:{ok,<<\"Some private data...\\n\">>}\n" + "ExitCode:0">>]), + ok = file:rename(MainScript, MainScript ++ "_without_shebang"), %% Plain archive without header (no flags) - ?line ok = file:write_file(MainScript, [ArchiveBin]), - ?line ok = file:write_file_info(MainScript, OrigFI), + ok = file:write_file(MainScript, [ArchiveBin]), + ok = file:write_file_info(MainScript, OrigFI), - ?line run_with_opts(PrivDir, "", MainBase ++ " -arg1 arg2 arg3", - [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "dict:[]\n" - "dummy:[]\n" - "priv:{ok,<<\"Some private data...\\n\">>}\n" - "ExitCode:0">>]), - ?line ok = file:rename(MainScript, MainScript ++ "_without_header"), + run_with_opts(PrivDir, "", MainBase ++ " -arg1 arg2 arg3", + [<<"main:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "dict:[]\n" + "dummy:[]\n" + "priv:{ok,<<\"Some private data...\\n\">>}\n" + "ExitCode:0">>]), + ok = file:rename(MainScript, MainScript ++ "_without_header"), - %%%%%%% +%%%%%%% %% Create and run scripts with emulator flags AltBase = "archive_script_alternate_main", AltScript = filename:join([PrivDir, AltBase]), - ?line ok = file:write_file(AltScript, - [Shebang, "\n", - Mode, "\n", - Flags, " -escript main archive_script_main2\n", - ArchiveBin]), - ?line ok = file:write_file_info(AltScript, OrigFI), - - ?line run(PrivDir, AltBase ++ " -arg1 arg2 arg3", - [<<"main2:[\"-arg1\",\"arg2\",\"arg3\"]\n" - "dict:[{archive_script_dict,[\"foo\",\"bar\"]},{archive_script_dict,[\"foo\"]}]\n" - "dummy:[{archive_script_dummy,[\"bar\"]}]\n" - "priv:{ok,<<\"Some private data...\\n\">>}\n" - "ExitCode:0">>]), + ok = file:write_file(AltScript, + [Shebang, "\n", + Mode, "\n", + Flags, " -escript main archive_script_main2\n", + ArchiveBin]), + ok = file:write_file_info(AltScript, OrigFI), + + run(PrivDir, AltBase ++ " -arg1 arg2 arg3", + [<<"main2:[\"-arg1\",\"arg2\",\"arg3\"]\n" + "dict:[{archive_script_dict,[\"foo\",\"bar\"]},{archive_script_dict,[\"foo\"]}]\n" + "dummy:[{archive_script_dummy,[\"bar\"]}]\n" + "priv:{ok,<<\"Some private data...\\n\">>}\n" + "ExitCode:0">>]), ok. @@ -508,21 +507,21 @@ archive_script(Config) when is_list(Config) -> %% archive_script_file_access(Config) when is_list(Config) -> %% Copy the orig files to priv_dir - DataDir = ?config(data_dir, Config), - PrivDir = ?config(priv_dir, Config), + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), MainMod = "archive_script_file_access", MainSrc = MainMod ++ ".erl", MainBeam = MainMod ++ ".beam", Archive = filename:join([PrivDir, "archive_script_file_access.zip"]), - ?line {ok, _} = zip:create(Archive, ["archive_script_file_access"], - [{compress, []}, {cwd, DataDir}]), - ?line {ok, _} = zip:extract(Archive, [{cwd, PrivDir}]), + {ok, _} = zip:create(Archive, ["archive_script_file_access"], + [{compress, []}, {cwd, DataDir}]), + {ok, _} = zip:extract(Archive, [{cwd, PrivDir}]), TopDir = filename:join([PrivDir, "archive_script_file_access"]), %% Compile the code - ?line ok = compile_files([MainSrc], TopDir, TopDir), + ok = compile_files([MainSrc], TopDir, TopDir), %% First, create a file structure which will be included in the archive: %% @@ -630,7 +629,7 @@ compile_app(TopDir, AppName) -> AppDir = filename:join([TopDir, AppName]), SrcDir = filename:join([AppDir, "src"]), OutDir = filename:join([AppDir, "ebin"]), - ?line {ok, Files} = file:list_dir(SrcDir), + {ok, Files} = file:list_dir(SrcDir), compile_files(Files, SrcDir, OutDir). compile_files([File | Files], SrcDir, OutDir) -> @@ -652,10 +651,10 @@ compile_files([], _, _) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% epp(Config) when is_list(Config) -> - Data = ?config(data_dir, Config), + Data = proplists:get_value(data_dir, Config), Dir = filename:absname(Data), %Get rid of trailing slash. - ?line run(Dir, "factorial_epp 5", - <<"factorial 5 = 120\nExitCode:0">>), + run(Dir, "factorial_epp 5", + <<"factorial 5 = 120\nExitCode:0">>), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -695,9 +694,9 @@ create_and_extract(Config) when is_list(Config) -> %% Verify the compile_source option file:delete(NewFile), - ?line ok = escript:create(NewFile, [{source, Source}]), - ?line {ok, [_, _, _, {source, Source}]} = escript:extract(NewFile, []), - ?line {ok, [_, _, _, {source, BeamCode2}]} = + ok = escript:create(NewFile, [{source, Source}]), + {ok, [_, _, _, {source, Source}]} = escript:extract(NewFile, []), + {ok, [_, _, _, {source, BeamCode2}]} = escript:extract(NewFile, [compile_source]), verify_sections(NewFile, FileInfo, [{shebang, default}, @@ -709,15 +708,15 @@ create_and_extract(Config) when is_list(Config) -> prepare_creation(Base, Config) -> %% Read the source - PrivDir = ?config(priv_dir, Config), - DataDir = ?config(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), + DataDir = proplists:get_value(data_dir, Config), OrigFile = filename:join([DataDir,"emulator_flags"]), - ?line {ok, FileInfo} = file:read_file_info(OrigFile), + {ok, FileInfo} = file:read_file_info(OrigFile), NewFile = filename:join([PrivDir, Base]), - ?line {ok, [{shebang, default}, - {comment, _}, - {emu_args, EmuArg}, - {source, Source}]} = + {ok, [{shebang, default}, + {comment, _}, + {emu_args, EmuArg}, + {source, Source}]} = escript:extract(OrigFile, []), %% Compile the code @@ -725,14 +724,14 @@ prepare_creation(Base, Config) -> ErlCode = list_to_binary(["\n-module(", Base, ").\n", "-export([main/1]).\n\n", Source, "\n\n"]), - ?line ok = file:write_file(ErlFile, ErlCode), + ok = file:write_file(ErlFile, ErlCode), %% Compile the code - ?line {ok, _Mod, BeamCode} = + {ok, _Mod, BeamCode} = compile:file(ErlFile, [binary, debug_info]), %% Create an archive - ?line {ok, {_, ArchiveBin}} = + {ok, {_, ArchiveBin}} = zip:create("dummy_archive_name", [{Base ++ ".erl", ErlCode}, {Base ++ ".beam", BeamCode}], @@ -749,8 +748,8 @@ verify_sections(File, FileInfo, Sections) -> %% Create file:delete(File), - ?line ok = escript:create(File, Sections), - ?line ok = file:write_file_info(File, FileInfo), + ok = escript:create(File, Sections), + ok = file:write_file_info(File, FileInfo), %% Run Dir = filename:absname(filename:dirname(File)), @@ -780,21 +779,21 @@ verify_sections(File, FileInfo, Sections) -> Expected = <<ExpectedMain/binary, ExpectedOutput/binary>>, case HasArg(shebang) of true -> - ?line run(Dir, InputArgs, [Expected]); + run(Dir, InputArgs, [Expected]); false -> - ?line run_with_opts(Dir, [], InputArgs, [Expected]) + run_with_opts(Dir, [], InputArgs, [Expected]) end, %% Verify - ?line {ok, Bin} = escript:create(binary, Sections), - ?line {ok, Read} = file:read_file(File), - ?line Bin = Read, % Assert + {ok, Bin} = escript:create(binary, Sections), + {ok, Read} = file:read_file(File), + Bin = Read, % Assert Normalized = normalize_sections(Sections), - ?line {ok, Extracted} = escript:extract(File, []), + {ok, Extracted} = escript:extract(File, []), io:format("Normalized; ~p\n", [Normalized]), io:format("Extracted ; ~p\n", [Extracted]), - ?line Normalized = Extracted, % Assert + Normalized = Extracted, % Assert ok. normalize_sections(Sections) -> @@ -806,27 +805,27 @@ normalize_sections(Sections) -> end end, case lists:map(AtomToTuple, [{K, V} || {K, V} <- Sections, V =/= undefined]) of - [{shebang, Shebang} | Rest] -> - [{shebang, Shebang} | - case Rest of - [{comment, Comment} | Rest2] -> - [{comment, Comment} | - case Rest2 of - [{emu_args, EmuArgs}, Body] -> - [{emu_args, EmuArgs}, Body]; - [Body] -> - [{emu_args, undefined}, Body] - end - ]; - [{emu_args, EmuArgs}, Body] -> - [{comment, undefined}, {emu_args, EmuArgs}, Body]; - [Body] -> - [{comment, undefined}, {emu_args, undefined}, Body] - end - ]; - [Body] -> - [{shebang, undefined}, {comment, undefined}, {emu_args, undefined}, Body] - end. + [{shebang, Shebang} | Rest] -> + [{shebang, Shebang} | + case Rest of + [{comment, Comment} | Rest2] -> + [{comment, Comment} | + case Rest2 of + [{emu_args, EmuArgs}, Body] -> + [{emu_args, EmuArgs}, Body]; + [Body] -> + [{emu_args, undefined}, Body] + end + ]; + [{emu_args, EmuArgs}, Body] -> + [{comment, undefined}, {emu_args, EmuArgs}, Body]; + [Body] -> + [{comment, undefined}, {emu_args, undefined}, Body] + end + ]; + [Body] -> + [{shebang, undefined}, {comment, undefined}, {emu_args, undefined}, Body] + end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -846,36 +845,36 @@ foldl(Config) when is_list(Config) -> %% Get line numbers and the file attribute right SourceFile = NewFile ++ ".erl", <<_:1/binary, ErlCode2/binary>> = ErlCode, - ?line ok = file:write_file(SourceFile, ErlCode2), - ?line {ok, _Mod, BeamCode} = + ok = file:write_file(SourceFile, ErlCode2), + {ok, _Mod, BeamCode} = compile:file(SourceFile, [binary, debug_info]), %% Verify source script - ?line ok = escript:create(SourceFile, [{source, ErlCode}]), - ?line {ok, [{".", _, BeamCode2}]} + ok = escript:create(SourceFile, [{source, ErlCode}]), + {ok, [{".", _, BeamCode2}]} = escript_foldl(Collect, [], SourceFile), - ?line {ok, Abstr} = beam_lib:chunks(BeamCode, [abstract_code]), - ?line {ok, Abstr2} = beam_lib:chunks(BeamCode2, [abstract_code]), + {ok, Abstr} = beam_lib:chunks(BeamCode, [abstract_code]), + {ok, Abstr2} = beam_lib:chunks(BeamCode2, [abstract_code]), %% io:format("abstr1=~p\n", [Abstr]), %% io:format("abstr2=~p\n", [Abstr2]), - ?line Abstr = Abstr2, % Assert + Abstr = Abstr2, % Assert %% Verify beam script - ?line ok = escript:create(NewFile, [{beam, BeamCode}]), - ?line {ok, [{".", _, BeamCode}]} + ok = escript:create(NewFile, [{beam, BeamCode}]), + {ok, [{".", _, BeamCode}]} = escript_foldl(Collect, [], NewFile), %% Verify archive scripts - ?line ok = escript:create(NewFile, [{archive, ArchiveBin}]), - ?line {ok, [{BeamBase, #file_info{}, _}, - {ErlBase, #file_info{}, _}]} + ok = escript:create(NewFile, [{archive, ArchiveBin}]), + {ok, [{BeamBase, #file_info{}, _}, + {ErlBase, #file_info{}, _}]} = escript_foldl(Collect, [], NewFile), ArchiveFiles = [{ErlBase, ErlCode}, {BeamBase, BeamCode}], - ?line ok = escript:create(NewFile, [{archive, ArchiveFiles, []}]), - ?line {ok, [{BeamBase, _, _}, - {ErlBase, _, _}]} + ok = escript:create(NewFile, [{archive, ArchiveFiles, []}]), + {ok, [{BeamBase, _, _}, + {ErlBase, _, _}]} = escript_foldl(Collect, [], NewFile), ok. @@ -909,7 +908,7 @@ emulate_escript_foldl(Fun, Acc, File) -> end. unicode(Config) when is_list(Config) -> - Data = ?config(data_dir, Config), + Data = proplists:get_value(data_dir, Config), Dir = filename:absname(Data), %Get rid of trailing slash. run(Dir, "unicode1", [<<"escript: exception error: an error occurred when evaluating" @@ -928,12 +927,12 @@ unicode(Config) when is_list(Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% overflow(Config) when is_list(Config) -> - Data = ?config(data_dir, Config), + Data = proplists:get_value(data_dir, Config), Dir = filename:absname(Data), %Get rid of trailing slash. - ?line run(Dir, "arg_overflow", - [<<"ExitCode:0">>]), - ?line run(Dir, "linebuf_overflow", - [<<"ExitCode:0">>]), + run(Dir, "arg_overflow", + [<<"ExitCode:0">>]), + run(Dir, "linebuf_overflow", + [<<"ExitCode:0">>]), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -968,7 +967,7 @@ do_run(Dir, Cmd, Expected0) -> Actual -> io:format("Expected: ~p\n", [Expected]), io:format("Actual: ~p\n", [Actual]), - ?t:fail() + ct:fail(failed) end end. diff --git a/lib/stdlib/test/ets_SUITE.erl b/lib/stdlib/test/ets_SUITE.erl index 6f9be9b179..678c225d25 100644 --- a/lib/stdlib/test/ets_SUITE.erl +++ b/lib/stdlib/test/ets_SUITE.erl @@ -34,7 +34,7 @@ -export([ match1/1, match2/1, match_object/1, match_object2/1]). -export([ dups/1, misc1/1, safe_fixtable/1, info/1, tab2list/1]). -export([ tab2file/1, tab2file2/1, tabfile_ext1/1, - tabfile_ext2/1, tabfile_ext3/1, tabfile_ext4/1, badfile/1]). + tabfile_ext2/1, tabfile_ext3/1, tabfile_ext4/1, badfile/1]). -export([ heavy_lookup/1, heavy_lookup_element/1, heavy_concurrent/1]). -export([ lookup_element_mult/1]). -export([]). @@ -43,8 +43,6 @@ t_delete_all_objects/1, t_insert_list/1, t_test_ms/1, t_select_delete/1,t_ets_dets/1]). --export([do_lookup/2, do_lookup_element/3]). - -export([ordered/1, ordered_match/1, interface_equality/1, fixtable_next/1, fixtable_insert/1, rename/1, rename_unnamed/1, evil_rename/1, update_element/1, update_counter/1, evil_update_counter/1, partly_bound/1, match_heavy/1]). @@ -85,7 +83,7 @@ %% Convenience for manual testing -export([random_test/0]). -% internal exports +%% internal exports -export([dont_make_worse_sub/0, make_better_sub1/0, make_better_sub2/0]). -export([t_repair_continuation_do/1, t_bucket_disappears_do/1, select_fail_do/1, whitebox_1/1, whitebox_2/1, t_delete_all_objects_do/1, @@ -109,26 +107,25 @@ -include_lib("common_test/include/ct.hrl"). --define(m(A,B), ?line assert_eq(A,B)). +-define(m(A,B), assert_eq(A,B)). init_per_testcase(Case, Config) -> rand:seed(exsplus), io:format("*** SEED: ~p ***\n", [rand:export_seed()]), start_spawn_logger(), wait_for_test_procs(), %% Ensure previous case cleaned up - Dog=test_server:timetrap(test_server:minutes(20)), put('__ETS_TEST_CASE__', Case), - [{watchdog, Dog}, {test_case, Case} | Config]. + [{test_case, Case} | Config]. + +end_per_testcase(_Func, _Config) -> + wait_for_test_procs(true). -end_per_testcase(_Func, Config) -> - Dog=?config(watchdog, Config), - wait_for_test_procs(true), - test_server:timetrap_cancel(Dog). - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,20}}]. all() -> [{group, new}, {group, insert}, {group, lookup}, @@ -158,7 +155,7 @@ all() -> otp_9423, ets_all, take, - + memory_check_summary]. % MUST BE LAST groups() -> @@ -199,10 +196,10 @@ end_per_suite(_Config) -> ok. init_per_group(_GroupName, Config) -> - Config. + Config. end_per_group(_GroupName, Config) -> - Config. + Config. %% Test that we did not have "too many" failed verify_etsmem()'s %% in the test suite. @@ -212,7 +209,7 @@ end_per_group(_GroupName, Config) -> memory_check_summary(_Config) -> case whereis(ets_test_spawn_logger) of undefined -> - ?t:fail("No spawn logger exist"); + ct:fail("No spawn logger exist"); _ -> ets_test_spawn_logger ! {self(), get_failed_memchecks}, receive {get_failed_memchecks, FailedMemchecks} -> ok end, @@ -228,45 +225,39 @@ memory_check_summary(_Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -t_bucket_disappears(suite) -> - []; -t_bucket_disappears(doc) -> - ["Test that a disappearing bucket during select of a non-fixed table works."]; +%% Test that a disappearing bucket during select of a non-fixed table works. t_bucket_disappears(Config) when is_list(Config) -> repeat_for_opts(t_bucket_disappears_do). t_bucket_disappears_do(Opts) -> - ?line EtsMem = etsmem(), - ?line ets_new(abcd, [named_table, public, {keypos, 2} | Opts]), - ?line ets:insert(abcd, {abcd,1,2}), - ?line ets:insert(abcd, {abcd,2,2}), - ?line ets:insert(abcd, {abcd,3,2}), - ?line {_, Cont} = ets:select(abcd, [{{'_', '$1', '_'}, - [{'<', '$1', {const, 10}}], - ['$1']}], 1), - ?line ets:delete(abcd, 2), - ?line ets:select(Cont), - ?line true = ets:delete(abcd), - ?line verify_etsmem(EtsMem). - - -t_match_spec_run(suite) -> - []; -t_match_spec_run(doc) -> - ["Check ets:match_spec_run/2."]; + EtsMem = etsmem(), + ets_new(abcd, [named_table, public, {keypos, 2} | Opts]), + ets:insert(abcd, {abcd,1,2}), + ets:insert(abcd, {abcd,2,2}), + ets:insert(abcd, {abcd,3,2}), + {_, Cont} = ets:select(abcd, [{{'_', '$1', '_'}, + [{'<', '$1', {const, 10}}], + ['$1']}], 1), + ets:delete(abcd, 2), + ets:select(Cont), + true = ets:delete(abcd), + verify_etsmem(EtsMem). + + +%% Check ets:match_spec_run/2. t_match_spec_run(Config) when is_list(Config) -> init_externals(), - ?line EtsMem = etsmem(), + EtsMem = etsmem(), t_match_spec_run_test([{1},{2},{3}], [{{'$1'},[{'>','$1',1}],['$1']}], [2,3]), - ?line Huge = [{X} || X <- lists:seq(1,2500)], - ?line L = lists:seq(2476,2500), + Huge = [{X} || X <- lists:seq(1,2500)], + L = lists:seq(2476,2500), t_match_spec_run_test(Huge, [{{'$1'},[{'>','$1',2475}],['$1']}], L), - ?line L2 = [{X*16#FFFFFFF} || X <- L], + L2 = [{X*16#FFFFFFF} || X <- L], t_match_spec_run_test(Huge, [{{'$1'}, [{'>','$1',2475}], [{{{'*','$1',16#FFFFFFF}}}]}], L2), @@ -343,7 +334,7 @@ t_match_spec_run(Config) when is_list(Config) -> end, test_terms(Fun, skip_refc_check), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). t_match_spec_run_test(List, MS, Result) -> @@ -371,14 +362,12 @@ t_match_spec_run_test(List, MS, Result) -> erlang:trace(Tracee, true, [call]), Tracee ! start, TRes = ms_tracer_collect(Tracee, MonRef, []), - %erlang:trace(Tracee, false, [call]), - %Tracee ! stop, case TRes of SRes -> ok; _ -> io:format("TRACE MATCH FAILED\n"), io:format("Input = ~p\nMST = ~p\nExpected = ~p\nGot = ~p\n", [List, MST, SRes, TRes]), - ?t:fail("TRACE MATCH FAILED") + ct:fail("TRACE MATCH FAILED") end, ok. @@ -387,32 +376,27 @@ t_match_spec_run_test(List, MS, Result) -> ms_tracer_collect(Tracee, Ref, Acc) -> receive {trace, Tracee, call, _Args, [Msg]} -> - %io:format("trace Args=~p Msg=~p\n", [_Args, Msg]), ms_tracer_collect(Tracee, Ref, [Msg | Acc]); {'DOWN', Ref, process, Tracee, _} -> - %io:format("monitor DOWN for ~p\n", [Tracee]), TDRef = erlang:trace_delivered(Tracee), ms_tracer_collect(Tracee, TDRef, Acc); {trace_delivered, Tracee, Ref} -> - %%io:format("trace delivered for ~p\n", [Tracee]), lists:sort(Acc); Other -> io:format("Unexpected message = ~p\n", [Other]), - ?t:fail("Unexpected tracer msg") + ct:fail("Unexpected tracer msg") end. ms_tracee(Parent, CallArgList) -> - %io:format("ms_tracee ~p started with ArgList = ~p\n", [self(), CallArgList]), Parent ! {self(), ready}, receive start -> ok end, lists:foreach(fun(Args) -> erlang:apply(?MODULE, ms_tracee_dummy, tuple_to_list(Args)) end, CallArgList). - %%receive stop -> ok end. @@ -427,189 +411,181 @@ ms_clause_ets_to_trace({Head, Guard, Body}) -> assert_eq(A,A) -> ok; assert_eq(A,B) -> io:format("FAILED MATCH:\n~p\n =/=\n~p\n",[A,B]), - ?t:fail("assert_eq failed"). + ct:fail("assert_eq failed"). -t_repair_continuation(suite) -> - []; -t_repair_continuation(doc) -> - ["Check ets:repair_continuation/2."]; +%% Test ets:repair_continuation/2. t_repair_continuation(Config) when is_list(Config) -> repeat_for_opts(t_repair_continuation_do). t_repair_continuation_do(Opts) -> - ?line EtsMem = etsmem(), - ?line MS = [{'_',[],[true]}], - ?line MS2 = [{{{'$1','_'},'_'},[],['$1']}], + EtsMem = etsmem(), + MS = [{'_',[],[true]}], + MS2 = [{{{'$1','_'},'_'},[],['$1']}], (fun() -> - ?line T = ets_new(x,[ordered_set|Opts]), - ?line F = fun(0,_)->ok;(N,F) -> ets:insert(T,{N,N}), F(N-1,F) end, - ?line F(1000,F), - ?line {_,C} = ets:select(T,MS,5), - ?line C2 = erlang:setelement(5,C,<<>>), - ?line {'EXIT',{badarg,_}} = (catch ets:select(C2)), - ?line C3 = ets:repair_continuation(C2,MS), - ?line {[true,true,true,true,true],_} = ets:select(C3), - ?line {[true,true,true,true,true],_} = ets:select(C), - ?line true = ets:delete(T) + T = ets_new(x,[ordered_set|Opts]), + F = fun(0,_)->ok;(N,F) -> ets:insert(T,{N,N}), F(N-1,F) end, + F(1000,F), + {_,C} = ets:select(T,MS,5), + C2 = erlang:setelement(5,C,<<>>), + {'EXIT',{badarg,_}} = (catch ets:select(C2)), + C3 = ets:repair_continuation(C2,MS), + {[true,true,true,true,true],_} = ets:select(C3), + {[true,true,true,true,true],_} = ets:select(C), + true = ets:delete(T) end)(), (fun() -> - ?line T = ets_new(x,[ordered_set|Opts]), - ?line F = fun(0,_)->ok;(N,F) -> ets:insert(T,{N,N}), F(N-1,F) end, - ?line F(1000,F), - ?line {_,C} = ets:select(T,MS,1001), - ?line C = '$end_of_table', - ?line C3 = ets:repair_continuation(C,MS), - ?line '$end_of_table' = ets:select(C3), - ?line '$end_of_table' = ets:select(C), - ?line true = ets:delete(T) + T = ets_new(x,[ordered_set|Opts]), + F = fun(0,_)->ok;(N,F) -> ets:insert(T,{N,N}), F(N-1,F) end, + F(1000,F), + {_,C} = ets:select(T,MS,1001), + C = '$end_of_table', + C3 = ets:repair_continuation(C,MS), + '$end_of_table' = ets:select(C3), + '$end_of_table' = ets:select(C), + true = ets:delete(T) end)(), - + (fun() -> - ?line T = ets_new(x,[ordered_set|Opts]), - ?line F = fun(0,_)->ok;(N,F) -> - ets:insert(T,{integer_to_list(N),N}), - F(N-1,F) - end, - ?line F(1000,F), - ?line {_,C} = ets:select(T,MS,5), - ?line C2 = erlang:setelement(5,C,<<>>), - ?line {'EXIT',{badarg,_}} = (catch ets:select(C2)), - ?line C3 = ets:repair_continuation(C2,MS), - ?line {[true,true,true,true,true],_} = ets:select(C3), - ?line {[true,true,true,true,true],_} = ets:select(C), - ?line true = ets:delete(T) + T = ets_new(x,[ordered_set|Opts]), + F = fun(0,_)->ok;(N,F) -> + ets:insert(T,{integer_to_list(N),N}), + F(N-1,F) + end, + F(1000,F), + {_,C} = ets:select(T,MS,5), + C2 = erlang:setelement(5,C,<<>>), + {'EXIT',{badarg,_}} = (catch ets:select(C2)), + C3 = ets:repair_continuation(C2,MS), + {[true,true,true,true,true],_} = ets:select(C3), + {[true,true,true,true,true],_} = ets:select(C), + true = ets:delete(T) end)(), (fun() -> - ?line T = ets_new(x,[ordered_set|Opts]), - ?line F = fun(0,_)->ok;(N,F) -> - ets:insert(T,{{integer_to_list(N),N},N}), - F(N-1,F) - end, - ?line F(1000,F), - ?line {_,C} = ets:select(T,MS2,5), - ?line C2 = erlang:setelement(5,C,<<>>), - ?line {'EXIT',{badarg,_}} = (catch ets:select(C2)), - ?line C3 = ets:repair_continuation(C2,MS2), - ?line {[_,_,_,_,_],_} = ets:select(C3), - ?line {[_,_,_,_,_],_} = ets:select(C), - ?line true = ets:delete(T) + T = ets_new(x,[ordered_set|Opts]), + F = fun(0,_)->ok;(N,F) -> + ets:insert(T,{{integer_to_list(N),N},N}), + F(N-1,F) + end, + F(1000,F), + {_,C} = ets:select(T,MS2,5), + C2 = erlang:setelement(5,C,<<>>), + {'EXIT',{badarg,_}} = (catch ets:select(C2)), + C3 = ets:repair_continuation(C2,MS2), + {[_,_,_,_,_],_} = ets:select(C3), + {[_,_,_,_,_],_} = ets:select(C), + true = ets:delete(T) end)(), - + (fun() -> - ?line T = ets_new(x,[set|Opts]), - ?line F = fun(0,_)->ok;(N,F) -> - ets:insert(T,{N,N}), - F(N-1,F) - end, - ?line F(1000,F), - ?line {_,C} = ets:select(T,MS,5), - ?line C2 = erlang:setelement(4,C,<<>>), - ?line {'EXIT',{badarg,_}} = (catch ets:select(C2)), - ?line C3 = ets:repair_continuation(C2,MS), - ?line {[true,true,true,true,true],_} = ets:select(C3), - ?line {[true,true,true,true,true],_} = ets:select(C), - ?line true = ets:delete(T) + T = ets_new(x,[set|Opts]), + F = fun(0,_)->ok;(N,F) -> + ets:insert(T,{N,N}), + F(N-1,F) + end, + F(1000,F), + {_,C} = ets:select(T,MS,5), + C2 = erlang:setelement(4,C,<<>>), + {'EXIT',{badarg,_}} = (catch ets:select(C2)), + C3 = ets:repair_continuation(C2,MS), + {[true,true,true,true,true],_} = ets:select(C3), + {[true,true,true,true,true],_} = ets:select(C), + true = ets:delete(T) end)(), (fun() -> - ?line T = ets_new(x,[set|Opts]), - ?line F = fun(0,_)->ok;(N,F) -> - ets:insert(T,{integer_to_list(N),N}), - F(N-1,F) - end, - ?line F(1000,F), - ?line {_,C} = ets:select(T,MS,5), - ?line C2 = erlang:setelement(4,C,<<>>), - ?line {'EXIT',{badarg,_}} = (catch ets:select(C2)), - ?line C3 = ets:repair_continuation(C2,MS), - ?line {[true,true,true,true,true],_} = ets:select(C3), - ?line {[true,true,true,true,true],_} = ets:select(C), - ?line true = ets:delete(T) + T = ets_new(x,[set|Opts]), + F = fun(0,_)->ok;(N,F) -> + ets:insert(T,{integer_to_list(N),N}), + F(N-1,F) + end, + F(1000,F), + {_,C} = ets:select(T,MS,5), + C2 = erlang:setelement(4,C,<<>>), + {'EXIT',{badarg,_}} = (catch ets:select(C2)), + C3 = ets:repair_continuation(C2,MS), + {[true,true,true,true,true],_} = ets:select(C3), + {[true,true,true,true,true],_} = ets:select(C), + true = ets:delete(T) end)(), (fun() -> - ?line T = ets_new(x,[bag|Opts]), - ?line F = fun(0,_)->ok;(N,F) -> - ets:insert(T,{integer_to_list(N),N}), - F(N-1,F) - end, - ?line F(1000,F), - ?line {_,C} = ets:select(T,MS,5), - ?line C2 = erlang:setelement(4,C,<<>>), - ?line {'EXIT',{badarg,_}} = (catch ets:select(C2)), - ?line C3 = ets:repair_continuation(C2,MS), - ?line {[true,true,true,true,true],_} = ets:select(C3), - ?line {[true,true,true,true,true],_} = ets:select(C), - ?line true = ets:delete(T) + T = ets_new(x,[bag|Opts]), + F = fun(0,_)->ok;(N,F) -> + ets:insert(T,{integer_to_list(N),N}), + F(N-1,F) + end, + F(1000,F), + {_,C} = ets:select(T,MS,5), + C2 = erlang:setelement(4,C,<<>>), + {'EXIT',{badarg,_}} = (catch ets:select(C2)), + C3 = ets:repair_continuation(C2,MS), + {[true,true,true,true,true],_} = ets:select(C3), + {[true,true,true,true,true],_} = ets:select(C), + true = ets:delete(T) end)(), (fun() -> - ?line T = ets_new(x,[duplicate_bag|Opts]), - ?line F = fun(0,_)->ok;(N,F) -> - ets:insert(T,{integer_to_list(N),N}), - F(N-1,F) - end, - ?line F(1000,F), - ?line {_,C} = ets:select(T,MS,5), - ?line C2 = erlang:setelement(4,C,<<>>), - ?line {'EXIT',{badarg,_}} = (catch ets:select(C2)), - ?line C3 = ets:repair_continuation(C2,MS), - ?line {[true,true,true,true,true],_} = ets:select(C3), - ?line {[true,true,true,true,true],_} = ets:select(C), - ?line true = ets:delete(T) + T = ets_new(x,[duplicate_bag|Opts]), + F = fun(0,_)->ok;(N,F) -> + ets:insert(T,{integer_to_list(N),N}), + F(N-1,F) + end, + F(1000,F), + {_,C} = ets:select(T,MS,5), + C2 = erlang:setelement(4,C,<<>>), + {'EXIT',{badarg,_}} = (catch ets:select(C2)), + C3 = ets:repair_continuation(C2,MS), + {[true,true,true,true,true],_} = ets:select(C3), + {[true,true,true,true,true],_} = ets:select(C), + true = ets:delete(T) end)(), - ?line false = ets:is_compiled_ms(<<>>), - ?line true = ets:is_compiled_ms(ets:match_spec_compile(MS)), - ?line verify_etsmem(EtsMem). + false = ets:is_compiled_ms(<<>>), + true = ets:is_compiled_ms(ets:match_spec_compile(MS)), + verify_etsmem(EtsMem). -default(doc) -> - ["Check correct default vaules of a new ets table"]; -default(suite) -> []; +%% Test correct default vaules of a new ets table. default(Config) when is_list(Config) -> %% Default should be set,protected - ?line EtsMem = etsmem(), - ?line Def = ets_new(def,[]), - ?line set = ets:info(Def,type), - ?line protected = ets:info(Def,protection), + EtsMem = etsmem(), + Def = ets_new(def,[]), + set = ets:info(Def,type), + protected = ets:info(Def,protection), Compressed = erlang:system_info(ets_always_compress), - ?line Compressed = ets:info(Def,compressed), + Compressed = ets:info(Def,compressed), Self = self(), - ?line Self = ets:info(Def,owner), - ?line none = ets:info(Def, heir), - ?line false = ets:info(Def,named_table), - ?line ets:delete(Def), - ?line verify_etsmem(EtsMem). - -select_fail(doc) -> - ["Test that select fails even if nothing can match"]; -select_fail(suite) -> - []; + Self = ets:info(Def,owner), + none = ets:info(Def, heir), + false = ets:info(Def,named_table), + ets:delete(Def), + verify_etsmem(EtsMem). + +%% Test that select fails even if nothing can match. select_fail(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), repeat_for_opts(select_fail_do, [all_types,write_concurrency]), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). select_fail_do(Opts) -> - ?line T = ets_new(x,Opts), - ?line ets:insert(T,{a,a}), - ?line case (catch - ets:select(T,[{{a,'_'},[],[{snuffla}]}])) of - {'EXIT',{badarg,_}} -> - ok; - Else0 -> - exit({type,ets:info(T,type), - expected,'EXIT',got,Else0}) - end, - ?line case (catch - ets:select(T,[{{b,'_'},[],[{snuffla}]}])) of - {'EXIT',{badarg,_}} -> - ok; - Else1 -> - exit({type,ets:info(T,type), - expected,'EXIT',got,Else1}) - end, - ?line ets:delete(T). - + T = ets_new(x,Opts), + ets:insert(T,{a,a}), + case (catch + ets:select(T,[{{a,'_'},[],[{snuffla}]}])) of + {'EXIT',{badarg,_}} -> + ok; + Else0 -> + exit({type,ets:info(T,type), + expected,'EXIT',got,Else0}) + end, + case (catch + ets:select(T,[{{b,'_'},[],[{snuffla}]}])) of + {'EXIT',{badarg,_}} -> + ok; + Else1 -> + exit({type,ets:info(T,type), + expected,'EXIT',got,Else1}) + end, + ets:delete(T). + -define(S(T),ets:info(T,memory)). -define(TAB_STRUCT_SZ, erts_debug:get_internal_state('DbTable_words')). @@ -618,202 +594,180 @@ select_fail_do(Opts) -> %% The hardcoded expected memory sizes (in words) are the ones we expect on: %% SunOS5.8, 32-bit, non smp, private heap %% -memory(doc) -> ["Whitebox test of ets:info(X,memory)"]; -memory(suite) -> []; + +%% Whitebox test of ets:info(X, memory). memory(Config) when is_list(Config) -> - ?line ok = chk_normal_tab_struct_size(), + ok = chk_normal_tab_struct_size(), repeat_for_opts(memory_do,[compressed]), - ?line catch erts_debug:set_internal_state(available_internal_state, false). + catch erts_debug:set_internal_state(available_internal_state, false). memory_do(Opts) -> - ?line L = [T1,T2,T3,T4] = fill_sets_int(1000,Opts), + L = [T1,T2,T3,T4] = fill_sets_int(1000,Opts), XR1 = case mem_mode(T1) of - {normal,_} -> {13836,13046,13046,13052}; %{13862,13072,13072,13078}; - {compressed,4} -> {11041,10251,10251,10252}; %{11067,10277,10277,10278}; - {compressed,8} -> {10050,9260,9260,9260} %{10076,9286,9286,9286} + {normal,_} -> {13836,13046,13046,13052}; %{13862,13072,13072,13078}; + {compressed,4} -> {11041,10251,10251,10252}; %{11067,10277,10277,10278}; + {compressed,8} -> {10050,9260,9260,9260} %{10076,9286,9286,9286} end, - ?line XRes1 = adjust_xmem(L, XR1), - ?line Res1 = {?S(T1),?S(T2),?S(T3),?S(T4)}, - ?line lists:foreach(fun(T) -> - Before = ets:info(T,size), - Key = 2, %894, %%ets:first(T), - Objs = ets:lookup(T,Key), - ?line ets:delete(T,Key), - io:format("deleted key ~p from ~p changed size ~p to ~p: ~p\n", - [Key, ets:info(T,type), Before, ets:info(T,size), Objs]) + XRes1 = adjust_xmem(L, XR1), + Res1 = {?S(T1),?S(T2),?S(T3),?S(T4)}, + lists:foreach(fun(T) -> + Before = ets:info(T,size), + Key = 2, %894, %%ets:first(T), + Objs = ets:lookup(T,Key), + ets:delete(T,Key), + io:format("deleted key ~p from ~p changed size ~p to ~p: ~p\n", + [Key, ets:info(T,type), Before, ets:info(T,size), Objs]) end, L), XR2 = case mem_mode(T1) of - {normal,_} -> {13826,13037,13028,13034}; %{13852,13063,13054,13060}; - {compressed,4} -> {11031,10242,10233,10234}; %{11057,10268,10259,10260}; - {compressed,8} -> {10040,9251,9242,9242} %10066,9277,9268,9268} + {normal,_} -> {13826,13037,13028,13034}; %{13852,13063,13054,13060}; + {compressed,4} -> {11031,10242,10233,10234}; %{11057,10268,10259,10260}; + {compressed,8} -> {10040,9251,9242,9242} %10066,9277,9268,9268} end, - ?line XRes2 = adjust_xmem(L, XR2), - ?line Res2 = {?S(T1),?S(T2),?S(T3),?S(T4)}, - ?line lists:foreach(fun(T) -> - Before = ets:info(T,size), - Key = 4, %802, %ets:first(T), - Objs = ets:lookup(T,Key), - ?line ets:match_delete(T,{Key,'_'}), - io:format("match_deleted key ~p from ~p changed size ~p to ~p: ~p\n", - [Key, ets:info(T,type), Before, ets:info(T,size), Objs]) - end, - L), + XRes2 = adjust_xmem(L, XR2), + Res2 = {?S(T1),?S(T2),?S(T3),?S(T4)}, + lists:foreach(fun(T) -> + Before = ets:info(T,size), + Key = 4, %802, %ets:first(T), + Objs = ets:lookup(T,Key), + ets:match_delete(T,{Key,'_'}), + io:format("match_deleted key ~p from ~p changed size ~p to ~p: ~p\n", + [Key, ets:info(T,type), Before, ets:info(T,size), Objs]) + end, + L), XR3 = case mem_mode(T1) of - {normal,_} -> {13816,13028,13010,13016}; %{13842,13054,13036,13042}; - {compressed,4} -> {11021,10233,10215,10216}; %{11047,10259,10241,10242}; - {compressed,8} -> {10030,9242,9224,9224} %{10056,9268,9250,9250} + {normal,_} -> {13816,13028,13010,13016}; %{13842,13054,13036,13042}; + {compressed,4} -> {11021,10233,10215,10216}; %{11047,10259,10241,10242}; + {compressed,8} -> {10030,9242,9224,9224} %{10056,9268,9250,9250} end, - ?line XRes3 = adjust_xmem(L, XR3), - ?line Res3 = {?S(T1),?S(T2),?S(T3),?S(T4)}, - ?line lists:foreach(fun(T) -> - ?line ets:delete_all_objects(T) + XRes3 = adjust_xmem(L, XR3), + Res3 = {?S(T1),?S(T2),?S(T3),?S(T4)}, + lists:foreach(fun(T) -> + ets:delete_all_objects(T) end, L), - ?line XRes4 = adjust_xmem(L, {50,260,260,260}), %{76,286,286,286}), - ?line Res4 = {?S(T1),?S(T2),?S(T3),?S(T4)}, + XRes4 = adjust_xmem(L, {50,260,260,260}), %{76,286,286,286}), + Res4 = {?S(T1),?S(T2),?S(T3),?S(T4)}, lists:foreach(fun(T) -> - ?line ets:delete(T) + ets:delete(T) end, L), - ?line L2 = [T11,T12,T13,T14] = fill_sets_int(1000), - ?line lists:foreach(fun(T) -> - ?line ets:select_delete(T,[{'_',[],[true]}]) + L2 = [T11,T12,T13,T14] = fill_sets_int(1000), + lists:foreach(fun(T) -> + ets:select_delete(T,[{'_',[],[true]}]) end, L2), - ?line XRes5 = adjust_xmem(L2, {50,260,260,260}), %{76,286,286,286}), - ?line Res5 = {?S(T11),?S(T12),?S(T13),?S(T14)}, - ?line io:format("XRes1 = ~p~n" - " Res1 = ~p~n~n" - "XRes2 = ~p~n" - " Res2 = ~p~n~n" - "XRes3 = ~p~n" - " Res3 = ~p~n~n" - "XRes4 = ~p~n" - " Res4 = ~p~n~n" - "XRes5 = ~p~n" - " Res5 = ~p~n~n", - [XRes1, Res1, - XRes2, Res2, - XRes3, Res3, - XRes4, Res4, - XRes5, Res5]), - ?line XRes1 = Res1, - ?line XRes2 = Res2, - ?line XRes3 = Res3, - ?line XRes4 = Res4, - ?line XRes5 = Res5, - ?line ok. + XRes5 = adjust_xmem(L2, {50,260,260,260}), %{76,286,286,286}), + Res5 = {?S(T11),?S(T12),?S(T13),?S(T14)}, + io:format("XRes1 = ~p~n" + " Res1 = ~p~n~n" + "XRes2 = ~p~n" + " Res2 = ~p~n~n" + "XRes3 = ~p~n" + " Res3 = ~p~n~n" + "XRes4 = ~p~n" + " Res4 = ~p~n~n" + "XRes5 = ~p~n" + " Res5 = ~p~n~n", + [XRes1, Res1, + XRes2, Res2, + XRes3, Res3, + XRes4, Res4, + XRes5, Res5]), + XRes1 = Res1, + XRes2 = Res2, + XRes3 = Res3, + XRes4 = Res4, + XRes5 = Res5, + ok. mem_mode(T) -> {case ets:info(T,compressed) of - true -> compressed; - false -> normal + true -> compressed; + false -> normal end, erlang:system_info(wordsize)}. chk_normal_tab_struct_size() -> - ?line System = {os:type(), - os:version(), - erlang:system_info(wordsize), - erlang:system_info(smp_support), - erlang:system_info(heap_type)}, - ?line ?t:format("System = ~p~n", [System]), - %%?line ?t:format("?NORMAL_TAB_STRUCT_SZ=~p~n", [?NORMAL_TAB_STRUCT_SZ]), - ?line ?t:format("?TAB_STRUCT_SZ=~p~n", [?TAB_STRUCT_SZ]), + System = {os:type(), + os:version(), + erlang:system_info(wordsize), + erlang:system_info(smp_support), + erlang:system_info(heap_type)}, + io:format("System = ~p~n", [System]), + io:format("?TAB_STRUCT_SZ=~p~n", [?TAB_STRUCT_SZ]), ok. -% ?line case System of -% {{unix, sunos}, {5, 8, 0}, 4, false, private} -> -% ?line ?NORMAL_TAB_STRUCT_SZ = ?TAB_STRUCT_SZ, -% ?line ok; -% _ -> -% ?line ok -% end. adjust_xmem([T1,T2,T3,T4], {A0,B0,C0,D0} = _Mem0) -> %% Adjust for 64-bit, smp, and os: %% Table struct size may differ. -% Mem1 = case ?TAB_STRUCT_SZ of -% ?NORMAL_TAB_STRUCT_SZ -> -% Mem0; -% TabStructSz -> -% TabDiff = TabStructSz - ?NORMAL_TAB_STRUCT_SZ, -% {A0+TabDiff, B0+TabDiff, C0+TabDiff, D0+TabDiff} -% end, - TabDiff = ?TAB_STRUCT_SZ, {A0+TabDiff, B0+TabDiff, C0+TabDiff, D0+TabDiff}. -t_whitebox(doc) -> - ["Diverse whitebox testes"]; -t_whitebox(suite) -> - []; +%% Misc. whitebox tests t_whitebox(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), repeat_for_opts(whitebox_1), repeat_for_opts(whitebox_1), repeat_for_opts(whitebox_1), repeat_for_opts(whitebox_2), repeat_for_opts(whitebox_2), repeat_for_opts(whitebox_2), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). whitebox_1(Opts) -> - ?line T=ets_new(x,[bag | Opts]), - ?line ets:insert(T,[{du,glade},{ta,en}]), - ?line ets:insert(T,[{hej,hopp2},{du,glade2},{ta,en2}]), - ?line {_,C}=ets:match(T,{ta,'$1'},1), - ?line ets:select(C), - ?line ets:match(C), - ?line ets:delete(T), + T=ets_new(x,[bag | Opts]), + ets:insert(T,[{du,glade},{ta,en}]), + ets:insert(T,[{hej,hopp2},{du,glade2},{ta,en2}]), + {_,C}=ets:match(T,{ta,'$1'},1), + ets:select(C), + ets:match(C), + ets:delete(T), ok. whitebox_2(Opts) -> - ?line T=ets_new(x,[ordered_set, {keypos,2} | Opts]), - ?line T2=ets_new(x,[set, {keypos,2}| Opts]), - ?line 0 = ets:select_delete(T,[{{hej},[],[true]}]), - ?line 0 = ets:select_delete(T,[{{hej,hopp},[],[true]}]), - ?line 0 = ets:select_delete(T2,[{{hej},[],[true]}]), - ?line 0 = ets:select_delete(T2,[{{hej,hopp},[],[true]}]), - ?line ets:delete(T), - ?line ets:delete(T2), + T=ets_new(x,[ordered_set, {keypos,2} | Opts]), + T2=ets_new(x,[set, {keypos,2}| Opts]), + 0 = ets:select_delete(T,[{{hej},[],[true]}]), + 0 = ets:select_delete(T,[{{hej,hopp},[],[true]}]), + 0 = ets:select_delete(T2,[{{hej},[],[true]}]), + 0 = ets:select_delete(T2,[{{hej,hopp},[],[true]}]), + ets:delete(T), + ets:delete(T2), ok. - - -t_ets_dets(doc) -> - ["Test ets:to/from_dets"]; -t_ets_dets(suite) -> - []; + + +%% Test ets:to/from_dets. t_ets_dets(Config) when is_list(Config) -> repeat_for_opts(fun(Opts) -> t_ets_dets(Config,Opts) end). t_ets_dets(Config, Opts) -> - ?line Fname = gen_dets_filename(Config,1), - ?line (catch file:delete(Fname)), - ?line {ok,DTab} = dets:open_file(testdets_1, + Fname = gen_dets_filename(Config,1), + (catch file:delete(Fname)), + {ok,DTab} = dets:open_file(testdets_1, [{file, Fname}]), - ?line ETab = ets_new(x,Opts), - ?line filltabint(ETab,3000), - ?line DTab = ets:to_dets(ETab,DTab), - ?line ets:delete_all_objects(ETab), - ?line 0 = ets:info(ETab,size), - ?line true = ets:from_dets(ETab,DTab), - ?line 3000 = ets:info(ETab,size), - ?line ets:delete(ETab), - ?line check_badarg(catch ets:to_dets(ETab,DTab), - ets, to_dets, [ETab,DTab]), - ?line check_badarg(catch ets:from_dets(ETab,DTab), - ets, from_dets, [ETab,DTab]), - ?line ETab2 = ets_new(x,Opts), - ?line filltabint(ETab2,3000), - ?line dets:close(DTab), - ?line check_badarg(catch ets:to_dets(ETab2,DTab), - ets, to_dets, [ETab2,DTab]), - ?line check_badarg(catch ets:from_dets(ETab2,DTab), - ets, from_dets, [ETab2,DTab]), - ?line ets:delete(ETab2), - ?line (catch file:delete(Fname)), + ETab = ets_new(x,Opts), + filltabint(ETab,3000), + DTab = ets:to_dets(ETab,DTab), + ets:delete_all_objects(ETab), + 0 = ets:info(ETab,size), + true = ets:from_dets(ETab,DTab), + 3000 = ets:info(ETab,size), + ets:delete(ETab), + check_badarg(catch ets:to_dets(ETab,DTab), + ets, to_dets, [ETab,DTab]), + check_badarg(catch ets:from_dets(ETab,DTab), + ets, from_dets, [ETab,DTab]), + ETab2 = ets_new(x,Opts), + filltabint(ETab2,3000), + dets:close(DTab), + check_badarg(catch ets:to_dets(ETab2,DTab), + ets, to_dets, [ETab2,DTab]), + check_badarg(catch ets:from_dets(ETab2,DTab), + ets, from_dets, [ETab2,DTab]), + ets:delete(ETab2), + (catch file:delete(Fname)), ok. check_badarg({'EXIT', {badarg, [{M,F,Args,_} | _]}}, M, F, Args) -> @@ -821,14 +775,11 @@ check_badarg({'EXIT', {badarg, [{M,F,Args,_} | _]}}, M, F, Args) -> check_badarg({'EXIT', {badarg, [{M,F,A,_} | _]}}, M, F, Args) -> true = test_server:is_native(M) andalso length(Args) =:= A. -t_delete_all_objects(doc) -> - ["Test ets:delete_all_objects/1"]; -t_delete_all_objects(suite) -> - []; +%% Test ets:delete_all_objects/1. t_delete_all_objects(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), repeat_for_opts(t_delete_all_objects_do), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). get_kept_objects(T) -> case ets:info(T,stats) of @@ -839,80 +790,77 @@ get_kept_objects(T) -> end. t_delete_all_objects_do(Opts) -> - ?line T=ets_new(x,Opts), - ?line filltabint(T,4000), - ?line O=ets:first(T), - ?line ets:next(T,O), - ?line ets:safe_fixtable(T,true), - ?line true = ets:delete_all_objects(T), - ?line '$end_of_table' = ets:next(T,O), - ?line 0 = ets:info(T,size), - ?line 4000 = get_kept_objects(T), - ?line ets:safe_fixtable(T,false), - ?line 0 = ets:info(T,size), - ?line 0 = get_kept_objects(T), - ?line filltabint(T,4000), - ?line 4000 = ets:info(T,size), - ?line true = ets:delete_all_objects(T), - ?line 0 = ets:info(T,size), - ?line ets:delete(T). - - -t_delete_object(doc) -> - ["Test ets:delete_object/2"]; -t_delete_object(suite) -> - []; + T=ets_new(x,Opts), + filltabint(T,4000), + O=ets:first(T), + ets:next(T,O), + ets:safe_fixtable(T,true), + true = ets:delete_all_objects(T), + '$end_of_table' = ets:next(T,O), + 0 = ets:info(T,size), + 4000 = get_kept_objects(T), + ets:safe_fixtable(T,false), + 0 = ets:info(T,size), + 0 = get_kept_objects(T), + filltabint(T,4000), + 4000 = ets:info(T,size), + true = ets:delete_all_objects(T), + 0 = ets:info(T,size), + ets:delete(T). + + +%% Test ets:delete_object/2. t_delete_object(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), repeat_for_opts(t_delete_object_do), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). t_delete_object_do(Opts) -> - ?line T = ets_new(x,Opts), - ?line filltabint(T,4000), - ?line del_one_by_one_set(T,1,4001), - ?line filltabint(T,4000), - ?line del_one_by_one_set(T,4000,0), - ?line filltabint(T,4000), - ?line First = ets:first(T), - ?line Next = ets:next(T,First), - ?line ets:safe_fixtable(T,true), - ?line ets:delete_object(T,{First, integer_to_list(First)}), - ?line Next = ets:next(T,First), - ?line 3999 = ets:info(T,size), - ?line 1 = get_kept_objects(T), - ?line ets:safe_fixtable(T,false), - ?line 3999 = ets:info(T,size), - ?line 0 = get_kept_objects(T), - ?line ets:delete(T), - ?line T1 = ets_new(x,[ordered_set | Opts]), - ?line filltabint(T1,4000), - ?line del_one_by_one_set(T1,1,4001), - ?line filltabint(T1,4000), - ?line del_one_by_one_set(T1,4000,0), - ?line ets:delete(T1), - ?line T2 = ets_new(x,[bag | Opts]), - ?line filltabint2(T2,4000), - ?line del_one_by_one_bag(T2,1,4001), - ?line filltabint2(T2,4000), - ?line del_one_by_one_bag(T2,4000,0), - ?line ets:delete(T2), - ?line T3 = ets_new(x,[duplicate_bag | Opts]), - ?line filltabint3(T3,4000), - ?line del_one_by_one_dbag_1(T3,1,4001), - ?line filltabint3(T3,4000), - ?line del_one_by_one_dbag_1(T3,4000,0), - ?line filltabint(T3,4000), - ?line filltabint3(T3,4000), - ?line del_one_by_one_dbag_2(T3,1,4001), - ?line filltabint(T3,4000), - ?line filltabint3(T3,4000), - ?line del_one_by_one_dbag_2(T3,4000,0), - - ?line filltabint2(T3,4000), - ?line filltabint(T3,4000), - ?line del_one_by_one_dbag_3(T3,4000,0), - ?line ets:delete(T3), + T = ets_new(x,Opts), + filltabint(T,4000), + del_one_by_one_set(T,1,4001), + filltabint(T,4000), + del_one_by_one_set(T,4000,0), + filltabint(T,4000), + First = ets:first(T), + Next = ets:next(T,First), + ets:safe_fixtable(T,true), + ets:delete_object(T,{First, integer_to_list(First)}), + Next = ets:next(T,First), + 3999 = ets:info(T,size), + 1 = get_kept_objects(T), + ets:safe_fixtable(T,false), + 3999 = ets:info(T,size), + 0 = get_kept_objects(T), + ets:delete(T), + T1 = ets_new(x,[ordered_set | Opts]), + filltabint(T1,4000), + del_one_by_one_set(T1,1,4001), + filltabint(T1,4000), + del_one_by_one_set(T1,4000,0), + ets:delete(T1), + T2 = ets_new(x,[bag | Opts]), + filltabint2(T2,4000), + del_one_by_one_bag(T2,1,4001), + filltabint2(T2,4000), + del_one_by_one_bag(T2,4000,0), + ets:delete(T2), + T3 = ets_new(x,[duplicate_bag | Opts]), + filltabint3(T3,4000), + del_one_by_one_dbag_1(T3,1,4001), + filltabint3(T3,4000), + del_one_by_one_dbag_1(T3,4000,0), + filltabint(T3,4000), + filltabint3(T3,4000), + del_one_by_one_dbag_2(T3,1,4001), + filltabint(T3,4000), + filltabint3(T3,4000), + del_one_by_one_dbag_2(T3,4000,0), + + filltabint2(T3,4000), + filltabint(T3,4000), + del_one_by_one_dbag_3(T3,4000,0), + ets:delete(T3), ok. make_init_fun(N) when N > 4000-> @@ -934,21 +882,18 @@ make_init_fun(N) -> exit(close_not_expected) end. -t_init_table(doc) -> - ["Test ets:init_table/2"]; -t_init_table(suite) -> - []; +%% Test ets:init_table/2. t_init_table(Config) when is_list(Config)-> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), repeat_for_opts(t_init_table_do), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). t_init_table_do(Opts) -> - ?line T = ets_new(x,[duplicate_bag | Opts]), - ?line filltabint(T,4000), - ?line ets:init_table(T, make_init_fun(1)), - ?line del_one_by_one_dbag_1(T,4000,0), - ?line ets:delete(T), + T = ets_new(x,[duplicate_bag | Opts]), + filltabint(T,4000), + ets:init_table(T, make_init_fun(1)), + del_one_by_one_dbag_1(T,4000,0), + ets:delete(T), ok. do_fill_dbag_using_lists(T,0) -> @@ -959,132 +904,120 @@ do_fill_dbag_using_lists(T,N) -> do_fill_dbag_using_lists(T,N - 1). -t_insert_new(doc) -> - ["Test the insert_new function"]; -t_insert_new(suite) -> - []; +%% Test the insert_new function. t_insert_new(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line L = fill_sets_int(1000) ++ fill_sets_int(1000,[{write_concurrency,true}]), + EtsMem = etsmem(), + L = fill_sets_int(1000) ++ fill_sets_int(1000,[{write_concurrency,true}]), lists:foreach(fun(Tab) -> - ?line false = ets:insert_new(Tab,{2,"2"}), - ?line true = ets:insert_new(Tab,{2002,"2002"}), - ?line false = ets:insert_new(Tab,{2002,"2002"}), - ?line true = ets:insert(Tab,{2002,"2002"}), - ?line false = ets:insert_new(Tab,[{2002,"2002"}]), - ?line false = ets:insert_new(Tab,[{2002,"2002"}, + false = ets:insert_new(Tab,{2,"2"}), + true = ets:insert_new(Tab,{2002,"2002"}), + false = ets:insert_new(Tab,{2002,"2002"}), + true = ets:insert(Tab,{2002,"2002"}), + false = ets:insert_new(Tab,[{2002,"2002"}]), + false = ets:insert_new(Tab,[{2002,"2002"}, {2003,"2003"}]), - ?line false = ets:insert_new(Tab,[{2001,"2001"}, + false = ets:insert_new(Tab,[{2001,"2001"}, {2002,"2002"}, {2003,"2003"}]), - ?line false = ets:insert_new(Tab,[{2001,"2001"}, + false = ets:insert_new(Tab,[{2001,"2001"}, {2002,"2002"}]), - ?line true = ets:insert_new(Tab,[{2001,"2001"}, + true = ets:insert_new(Tab,[{2001,"2001"}, {2003,"2003"}]), - ?line false = ets:insert_new(Tab,{2001,"2001"}), - ?line false = ets:insert_new(Tab,{2002,"2002"}), - ?line false = ets:insert_new(Tab,{2003,"2003"}), - ?line true = ets:insert_new(Tab,{2004,"2004"}), - ?line true = ets:insert_new(Tab,{2000,"2000"}), - ?line true = ets:insert_new(Tab,[{2005,"2005"}, - {2006,"2006"}, - {2007,"2007"}]), - ?line Num = + false = ets:insert_new(Tab,{2001,"2001"}), + false = ets:insert_new(Tab,{2002,"2002"}), + false = ets:insert_new(Tab,{2003,"2003"}), + true = ets:insert_new(Tab,{2004,"2004"}), + true = ets:insert_new(Tab,{2000,"2000"}), + true = ets:insert_new(Tab,[{2005,"2005"}, + {2006,"2006"}, + {2007,"2007"}]), + Num = case ets:info(Tab,type) of bag -> - ?line true = + true = ets:insert(Tab,{2004,"2004-2"}), - ?line false = + false = ets:insert_new(Tab,{2004,"2004-3"}), 1009; duplicate_bag -> - ?line true = + true = ets:insert(Tab,{2004,"2004"}), - ?line false = + false = ets:insert_new(Tab,{2004,"2004"}), 1010; _ -> 1008 end, - ?line Num = ets:info(Tab,size), - ?line List = ets:tab2list(Tab), - ?line ets:delete_all_objects(Tab), - ?line true = ets:insert_new(Tab,List), - ?line false = ets:insert_new(Tab,List), - ?line ets:delete(Tab) + Num = ets:info(Tab,size), + List = ets:tab2list(Tab), + ets:delete_all_objects(Tab), + true = ets:insert_new(Tab,List), + false = ets:insert_new(Tab,List), + ets:delete(Tab) end, L), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). -t_insert_list(doc) -> - ["Test ets:insert/2 with list of objects."]; -t_insert_list(suite) -> - []; +%% Test ets:insert/2 with list of objects. t_insert_list(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), repeat_for_opts(t_insert_list_do), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). t_insert_list_do(Opts) -> - ?line T = ets_new(x,[duplicate_bag | Opts]), - ?line do_fill_dbag_using_lists(T,4000), - ?line del_one_by_one_dbag_2(T,4000,0), - ?line ets:delete(T). + T = ets_new(x,[duplicate_bag | Opts]), + do_fill_dbag_using_lists(T,4000), + del_one_by_one_dbag_2(T,4000,0), + ets:delete(T). -t_test_ms(doc) -> - ["Test interface of ets:test_ms/2"]; -t_test_ms(suite) -> - []; +%% Test interface of ets:test_ms/2. t_test_ms(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line {ok,[a,b]} = ets:test_ms({a,b}, - [{{'$1','$2'},[{'<','$1','$2'}],['$$']}]), - ?line {ok,false} = ets:test_ms({a,b}, - [{{'$1','$2'},[{'>','$1','$2'}],['$$']}]), + EtsMem = etsmem(), + {ok,[a,b]} = ets:test_ms({a,b}, + [{{'$1','$2'},[{'<','$1','$2'}],['$$']}]), + {ok,false} = ets:test_ms({a,b}, + [{{'$1','$2'},[{'>','$1','$2'}],['$$']}]), Tpl = {a,gb_sets:new()}, - ?line {ok,Tpl} = ets:test_ms(Tpl, [{{'_','_'}, [], ['$_']}]), % OTP-10190 - ?line {error,[{error,String}]} = ets:test_ms({a,b}, - [{{'$1','$2'}, - [{'flurp','$1','$2'}], - ['$$']}]), - ?line true = (if is_list(String) -> true; true -> false end), - ?line verify_etsmem(EtsMem). - -t_select_reverse(doc) -> - ["Test the select reverse BIF's"]; -t_select_reverse(suite) -> - []; + {ok,Tpl} = ets:test_ms(Tpl, [{{'_','_'}, [], ['$_']}]), % OTP-10190 + {error,[{error,String}]} = ets:test_ms({a,b}, + [{{'$1','$2'}, + [{'flurp','$1','$2'}], + ['$$']}]), + true = (if is_list(String) -> true; true -> false end), + verify_etsmem(EtsMem). + +%% Test the select reverse BIFs. t_select_reverse(Config) when is_list(Config) -> - ?line Table = ets_new(xxx, [ordered_set]), - ?line filltabint(Table,1000), - ?line A = lists:reverse(ets:select(Table,[{{'$1', '_'}, + Table = ets_new(xxx, [ordered_set]), + filltabint(Table,1000), + A = lists:reverse(ets:select(Table,[{{'$1', '_'}, [{'>', {'rem', '$1', 5}, 2}], ['$_']}])), - ?line A = ets:select_reverse(Table,[{{'$1', '_'}, + A = ets:select_reverse(Table,[{{'$1', '_'}, [{'>', {'rem', '$1', 5}, 2}], ['$_']}]), - ?line A = reverse_chunked(Table,[{{'$1', '_'}, - [{'>', - {'rem', - '$1', 5}, - 2}], - ['$_']}],3), - % A set/bag/duplicate_bag should get the same result regardless - % of select or select_reverse - ?line Table2 = ets_new(xxx, [set]), - ?line filltabint(Table2,1000), - ?line Table3 = ets_new(xxx, [bag]), - ?line filltabint(Table3,1000), - ?line Table4 = ets_new(xxx, [duplicate_bag]), - ?line filltabint(Table4,1000), - ?line lists:map(fun(Tab) -> + A = reverse_chunked(Table,[{{'$1', '_'}, + [{'>', + {'rem', + '$1', 5}, + 2}], + ['$_']}],3), + %% A set/bag/duplicate_bag should get the same result regardless + %% of select or select_reverse + Table2 = ets_new(xxx, [set]), + filltabint(Table2,1000), + Table3 = ets_new(xxx, [bag]), + filltabint(Table3,1000), + Table4 = ets_new(xxx, [duplicate_bag]), + filltabint(Table4,1000), + lists:map(fun(Tab) -> B = ets:select(Tab,[{{'$1', '_'}, [{'>', {'rem', @@ -1112,52 +1045,49 @@ do_reverse_chunked({L,C},Acc) -> do_reverse_chunked(ets:select_reverse(C), NewAcc). -t_select_delete(doc) -> - ["Test the ets:select_delete/2 and ets:select_count/2 BIF's"]; -t_select_delete(suite) -> - []; +%% Test the ets:select_delete/2 and ets:select_count/2 BIFs. t_select_delete(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line Tables = fill_sets_int(10000) ++ fill_sets_int(10000,[{write_concurrency,true}]), + EtsMem = etsmem(), + Tables = fill_sets_int(10000) ++ fill_sets_int(10000,[{write_concurrency,true}]), lists:foreach (fun(Table) -> - ?line 4000 = ets:select_count(Table,[{{'$1', '_'}, - [{'>', - {'rem', - '$1', 5}, - 2}], - [true]}]), - ?line 4000 = ets:select_delete(Table,[{{'$1', '_'}, - [{'>', - {'rem', - '$1', 5}, - 2}], - [true]}]), - ?line check(Table, - fun({N,_}) when (N rem 5) =< 2 -> - true; - (_) -> - false - end, - 6000) + 4000 = ets:select_count(Table,[{{'$1', '_'}, + [{'>', + {'rem', + '$1', 5}, + 2}], + [true]}]), + 4000 = ets:select_delete(Table,[{{'$1', '_'}, + [{'>', + {'rem', + '$1', 5}, + 2}], + [true]}]), + check(Table, + fun({N,_}) when (N rem 5) =< 2 -> + true; + (_) -> + false + end, + 6000) end, Tables), lists:foreach (fun(Table) -> - ?line ets:select_delete(Table,[{'_',[],[true]}]), - ?line xfilltabint(Table,4000), - ?line successive_delete(Table,1,4001,bound), - ?line 0 = ets:info(Table,size), - ?line xfilltabint(Table,4000), - ?line successive_delete(Table,4000,0, bound), - ?line 0 = ets:info(Table,size), - ?line xfilltabint(Table,4000), - ?line successive_delete(Table,1,4001,unbound), - ?line 0 = ets:info(Table,size), - ?line xfilltabint(Table,4000), - ?line successive_delete(Table,4000,0, unbound), - ?line 0 = ets:info(Table,size) + ets:select_delete(Table,[{'_',[],[true]}]), + xfilltabint(Table,4000), + successive_delete(Table,1,4001,bound), + 0 = ets:info(Table,size), + xfilltabint(Table,4000), + successive_delete(Table,4000,0, bound), + 0 = ets:info(Table,size), + xfilltabint(Table,4000), + successive_delete(Table,1,4001,unbound), + 0 = ets:info(Table,size), + xfilltabint(Table,4000), + successive_delete(Table,4000,0, unbound), + 0 = ets:info(Table,size) end, Tables), @@ -1169,162 +1099,152 @@ t_select_delete(Config) when is_list(Config) -> _ -> 1 end, - ?line xfilltabstr(Table, 4000), - ?line 1000 = ets:select_count(Table, - [{{[$3 | '$1'], '_'}, - [{'==', - {'length', '$1'}, - 3}],[true]}]) div F, - ?line 1000 = ets:select_delete(Table, - [{{[$3 | '$1'], '_'}, - [{'==', - {'length', '$1'}, - 3}],[true]}]) div F, - ?line check(Table, fun({[3,_,_,_],_}) -> false; - (_) -> true - end, 3000*F), - ?line 8 = ets:select_count(Table, - [{{"7",'_'},[],[false]}, - {{['_'], '_'}, - [],[true]}]) div F, - ?line 8 = ets:select_delete(Table, - [{{"7",'_'},[],[false]}, - {{['_'], '_'}, - [],[true]}]) div F, - ?line check(Table, fun({"7",_}) -> true; - ({[_],_}) -> false; - (_) -> true - end, 2992*F), - ?line xfilltabstr(Table, 4000), + xfilltabstr(Table, 4000), + 1000 = ets:select_count(Table, + [{{[$3 | '$1'], '_'}, + [{'==', + {'length', '$1'}, + 3}],[true]}]) div F, + 1000 = ets:select_delete(Table, + [{{[$3 | '$1'], '_'}, + [{'==', + {'length', '$1'}, + 3}],[true]}]) div F, + check(Table, fun({[3,_,_,_],_}) -> false; + (_) -> true + end, 3000*F), + 8 = ets:select_count(Table, + [{{"7",'_'},[],[false]}, + {{['_'], '_'}, + [],[true]}]) div F, + 8 = ets:select_delete(Table, + [{{"7",'_'},[],[false]}, + {{['_'], '_'}, + [],[true]}]) div F, + check(Table, fun({"7",_}) -> true; + ({[_],_}) -> false; + (_) -> true + end, 2992*F), + xfilltabstr(Table, 4000), %% This happens to be interesting for other select types too - ?line 200 = length(ets:select(Table, - [{{[$3,'_','_'],'_'}, - [],[true]}, - {{[$1,'_','_'],'_'}, - [],[true]}])) div F, - ?line 200 = ets:select_count(Table, - [{{[$3,'_','_'],'_'}, - [],[true]}, - {{[$1,'_','_'],'_'}, - [],[true]}]) div F, - ?line 200 = length(element(1,ets:select(Table, - [{{[$3,'_','_'],'_'}, - [],[true]}, - {{[$1,'_','_'],'_'}, - [],[true]}], - 1000))) div F, - ?line 200 = length( - ets:select_reverse(Table, - [{{[$3,'_','_'],'_'}, - [],[true]}, - {{[$1,'_','_'],'_'}, - [],[true]}])) div F, - ?line 200 = length( - element(1, - ets:select_reverse - (Table, + 200 = length(ets:select(Table, + [{{[$3,'_','_'],'_'}, + [],[true]}, + {{[$1,'_','_'],'_'}, + [],[true]}])) div F, + 200 = ets:select_count(Table, [{{[$3,'_','_'],'_'}, [],[true]}, {{[$1,'_','_'],'_'}, - [],[true]}], - 1000))) div F, - ?line 200 = ets:select_delete(Table, - [{{[$3,'_','_'],'_'}, - [],[true]}, - {{[$1,'_','_'],'_'}, - [],[true]}]) div F, - ?line 0 = ets:select_count(Table, + [],[true]}]) div F, + 200 = length(element(1,ets:select(Table, + [{{[$3,'_','_'],'_'}, + [],[true]}, + {{[$1,'_','_'],'_'}, + [],[true]}], + 1000))) div F, + 200 = length( + ets:select_reverse(Table, [{{[$3,'_','_'],'_'}, [],[true]}, {{[$1,'_','_'],'_'}, - [],[true]}]) div F, - ?line check(Table, fun({[$3,_,_],_}) -> false; - ({[$1,_,_],_}) -> false; - (_) -> true - end, 3800*F) + [],[true]}])) div F, + 200 = length( + element(1, + ets:select_reverse + (Table, + [{{[$3,'_','_'],'_'}, + [],[true]}, + {{[$1,'_','_'],'_'}, + [],[true]}], + 1000))) div F, + 200 = ets:select_delete(Table, + [{{[$3,'_','_'],'_'}, + [],[true]}, + {{[$1,'_','_'],'_'}, + [],[true]}]) div F, + 0 = ets:select_count(Table, + [{{[$3,'_','_'],'_'}, + [],[true]}, + {{[$1,'_','_'],'_'}, + [],[true]}]) div F, + check(Table, fun({[$3,_,_],_}) -> false; + ({[$1,_,_],_}) -> false; + (_) -> true + end, 3800*F) end, Tables), lists:foreach(fun(Tab) -> ets:delete(Tab) end,Tables), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). -partly_bound(doc) -> - ["Test that partly bound keys gives faster matches"]; -partly_bound(suite) -> - []; +%% Test that partly bound keys gives faster matches. partly_bound(Config) when is_list(Config) -> case os:type() of {win32,_} -> {skip,"Inaccurate measurements on Windows"}; _ -> - ?line EtsMem = etsmem(), - ?line dont_make_worse(), - ?line make_better(), - ?line verify_etsmem(EtsMem) + EtsMem = etsmem(), + dont_make_worse(), + make_better(), + verify_etsmem(EtsMem) end. dont_make_worse() -> seventyfive_percent_success({?MODULE,dont_make_worse_sub,[]},0,0,10). dont_make_worse_sub() -> - ?line T = build_table([a,b],[a,b],15000), - ?line T1 = time_match_object(T,{'_',a,a,1500}, [{{a,a,1500},a,a,1500}]), - ?line T2 = time_match_object(T,{{a,a,'_'},a,a,1500}, - [{{a,a,1500},a,a,1500}]), - ?line ets:delete(T), - ?line true = (T1 > T2), + T = build_table([a,b],[a,b],15000), + T1 = time_match_object(T,{'_',a,a,1500}, [{{a,a,1500},a,a,1500}]), + T2 = time_match_object(T,{{a,a,'_'},a,a,1500}, + [{{a,a,1500},a,a,1500}]), + ets:delete(T), + true = (T1 > T2), ok. - + make_better() -> fifty_percent_success({?MODULE,make_better_sub2,[]},0,0,10), fifty_percent_success({?MODULE,make_better_sub1,[]},0,0,10). make_better_sub1() -> - ?line T = build_table2([a,b],[a,b],15000), - ?line T1 = time_match_object(T,{'_',1500,a,a}, [{{1500,a,a},1500,a,a}]), - ?line T2 = time_match_object(T,{{1500,a,'_'},1500,a,a}, - [{{1500,a,a},1500,a,a}]), - ?line ets:delete(T), - ?line io:format("~p>~p~n",[(T1 / 100),T2]), - ?line true = ((T1 / 100) > T2), % More marginal than needed. + T = build_table2([a,b],[a,b],15000), + T1 = time_match_object(T,{'_',1500,a,a}, [{{1500,a,a},1500,a,a}]), + T2 = time_match_object(T,{{1500,a,'_'},1500,a,a}, + [{{1500,a,a},1500,a,a}]), + ets:delete(T), + io:format("~p>~p~n",[(T1 / 100),T2]), + true = ((T1 / 100) > T2), % More marginal than needed. ok. make_better_sub2() -> - ?line T = build_table2([a,b],[a,b],15000), - ?line T1 = time_match(T,{'$1',1500,a,a}), - ?line T2 = time_match(T,{{1500,a,'$1'},1500,a,a}), - ?line ets:delete(T), - ?line io:format("~p>~p~n",[(T1 / 100),T2]), - ?line true = ((T1 / 100) > T2), % More marginal than needed. + T = build_table2([a,b],[a,b],15000), + T1 = time_match(T,{'$1',1500,a,a}), + T2 = time_match(T,{{1500,a,'$1'},1500,a,a}), + ets:delete(T), + io:format("~p>~p~n",[(T1 / 100),T2]), + true = ((T1 / 100) > T2), % More marginal than needed. ok. -match_heavy(doc) -> - ["Heavy random matching, comparing set with ordered_set."]; -match_heavy(suite) -> - []; +%% Heavy random matching, comparing set with ordered_set. match_heavy(Config) when is_list(Config) -> - PrivDir = ?config(priv_dir,Config), - DataDir = ?config(data_dir, Config), + PrivDir = proplists:get_value(priv_dir,Config), + DataDir = proplists:get_value(data_dir, Config), %% Easier to have in process dictionary when manually %% running the test function. put(where_to_read,DataDir), put(where_to_write,PrivDir), - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), - NewDog=test_server:timetrap(test_server:seconds(1000)), - NewConfig = [{watchdog, NewDog} | lists:keydelete(watchdog,1,Config)], random_test(), drop_match(), - NewConfig. + ok. %%% Extra safety for the very low probability that this is not %%% caught by the random test (Statistically impossible???) drop_match() -> - ?line EtsMem = etsmem(), - ?line T = build_table([a,b],[a],1500), - ?line [{{a,a,1},a,a,1},{{b,a,1},b,a,1}] = + EtsMem = etsmem(), + T = build_table([a,b],[a],1500), + [{{a,a,1},a,a,1},{{b,a,1},b,a,1}] = ets:match_object(T, {'_','_','_',1}), - ?line true = ets:delete(T), - ?line verify_etsmem(EtsMem). + true = ets:delete(T), + verify_etsmem(EtsMem). @@ -1361,11 +1281,11 @@ match_object_chunked_collect({Results, Continuation}) -> Results ++ match_object_chunked_collect(ets:match_object(Continuation)). - + random_test() -> - ?line ReadDir = get(where_to_read), - ?line WriteDir = get(where_to_write), - ?line (catch file:make_dir(WriteDir)), + ReadDir = get(where_to_read), + WriteDir = get(where_to_write), + (catch file:make_dir(WriteDir)), case file:consult(filename:join([ReadDir,"preset_random_seed.txt"])) of {ok,[X]} -> rand:seed(X); @@ -1374,152 +1294,152 @@ random_test() -> end, Seed = rand:export_seed(), {ok,F} = file:open(filename:join([WriteDir,"last_random_seed.txt"]), - [write]), + [write]), io:format(F,"~p. ~n",[Seed]), file:close(F), io:format("Random seed ~p written to ~s, copy to ~s to rerun with " "same seed.",[Seed, filename:join([WriteDir, "last_random_seed.txt"]), filename:join([ReadDir, - "preset_random_seed.txt"])]), + "preset_random_seed.txt"])]), do_random_test(). do_random_test() -> - ?line EtsMem = etsmem(), - ?line OrdSet = ets_new(xxx,[ordered_set]), - ?line Set = ets_new(xxx,[]), - ?line do_n_times(fun() -> - ?line Key = create_random_string(25), - ?line Value = create_random_tuple(25), - ?line ets:insert(OrdSet,{Key,Value}), - ?line ets:insert(Set,{Key,Value}) + EtsMem = etsmem(), + OrdSet = ets_new(xxx,[ordered_set]), + Set = ets_new(xxx,[]), + do_n_times(fun() -> + Key = create_random_string(25), + Value = create_random_tuple(25), + ets:insert(OrdSet,{Key,Value}), + ets:insert(Set,{Key,Value}) end, 5000), - ?line io:format("~nData inserted~n"), - ?line do_n_times(fun() -> + io:format("~nData inserted~n"), + do_n_times(fun() -> I = rand:uniform(25), - ?line Key = create_random_string(I) ++ '_', - ?line L1 = ets_match_object(OrdSet,{Key,'_'}), - ?line L2 = lists:sort(ets_match_object(Set,{Key,'_'})), + Key = create_random_string(I) ++ '_', + L1 = ets_match_object(OrdSet,{Key,'_'}), + L2 = lists:sort(ets_match_object(Set,{Key,'_'})), case L1 == L2 of false -> io:format("~p != ~p~n", [L1,L2]), - ?line exit({not_eq, L1, L2}); + exit({not_eq, L1, L2}); true -> ok end end, 2000), - ?line io:format("~nData matched~n"), - ?line ets:match_delete(OrdSet,'_'), - ?line ets:match_delete(Set,'_'), - ?line do_n_times(fun() -> - ?line Value = create_random_string(25), - ?line Key = create_random_tuple(25), - ?line ets:insert(OrdSet,{Key,Value}), - ?line ets:insert(Set,{Key,Value}) + io:format("~nData matched~n"), + ets:match_delete(OrdSet,'_'), + ets:match_delete(Set,'_'), + do_n_times(fun() -> + Value = create_random_string(25), + Key = create_random_tuple(25), + ets:insert(OrdSet,{Key,Value}), + ets:insert(Set,{Key,Value}) end, 2000), - ?line io:format("~nData inserted~n"), + io:format("~nData inserted~n"), (fun() -> - ?line Key = list_to_tuple(lists:duplicate(25,'_')), - ?line L1 = ets_match_object(OrdSet,{Key,'_'}), - ?line L2 = lists:sort(ets_match_object(Set,{Key,'_'})), - ?line 2000 = length(L1), + Key = list_to_tuple(lists:duplicate(25,'_')), + L1 = ets_match_object(OrdSet,{Key,'_'}), + L2 = lists:sort(ets_match_object(Set,{Key,'_'})), + 2000 = length(L1), case L1 == L2 of false -> io:format("~p != ~p~n", [L1,L2]), - ?line exit({not_eq, L1, L2}); + exit({not_eq, L1, L2}); true -> ok end end)(), (fun() -> - ?line Key = {'$1','$2','$3','$4', - '$5','$6','$7','$8', - '$9','$10','$11','$12', - '$13','$14','$15','$16', - '$17','$18','$19','$20', - '$21','$22','$23','$24', - '$25'}, - ?line L1 = ets_match_object(OrdSet,{Key,'_'}), - ?line L2 = lists:sort(ets_match_object(Set,{Key,'_'})), - ?line 2000 = length(L1), + Key = {'$1','$2','$3','$4', + '$5','$6','$7','$8', + '$9','$10','$11','$12', + '$13','$14','$15','$16', + '$17','$18','$19','$20', + '$21','$22','$23','$24', + '$25'}, + L1 = ets_match_object(OrdSet,{Key,'_'}), + L2 = lists:sort(ets_match_object(Set,{Key,'_'})), + 2000 = length(L1), case L1 == L2 of false -> io:format("~p != ~p~n", [L1,L2]), - ?line exit({not_eq, L1, L2}); + exit({not_eq, L1, L2}); true -> ok end end)(), (fun() -> - ?line Key = {'$1','$2','$3','$4', - '$5','$6','$7','$8', - '$9','$10','$11','$12', - '$13','$14','$15','$16', - '$17','$18','$19','$20', - '$21','$22','$23','$24', - '$25'}, - ?line L1 = ets_match(OrdSet,{Key,'_'}), - ?line L2 = lists:sort(ets_match(Set,{Key,'_'})), - ?line 2000 = length(L1), + Key = {'$1','$2','$3','$4', + '$5','$6','$7','$8', + '$9','$10','$11','$12', + '$13','$14','$15','$16', + '$17','$18','$19','$20', + '$21','$22','$23','$24', + '$25'}, + L1 = ets_match(OrdSet,{Key,'_'}), + L2 = lists:sort(ets_match(Set,{Key,'_'})), + 2000 = length(L1), case L1 == L2 of false -> io:format("~p != ~p~n", [L1,L2]), - ?line exit({not_eq, L1, L2}); + exit({not_eq, L1, L2}); true -> ok end end)(), - ?line ets:match_delete(OrdSet,'_'), - ?line ets:match_delete(Set,'_'), - ?line do_n_times(fun() -> - ?line Value = create_random_string(25), - ?line Key = create_random_tuple(25), - ?line ets:insert(OrdSet,{Key,Value}), - ?line ets:insert(Set,{Key,Value}) + ets:match_delete(OrdSet,'_'), + ets:match_delete(Set,'_'), + do_n_times(fun() -> + Value = create_random_string(25), + Key = create_random_tuple(25), + ets:insert(OrdSet,{Key,Value}), + ets:insert(Set,{Key,Value}) end, 2000), - ?line io:format("~nData inserted~n"), + io:format("~nData inserted~n"), do_n_times(fun() -> - ?line Key = create_partly_bound_tuple(25), - ?line L1 = ets_match_object(OrdSet,{Key,'_'}), - ?line L2 = lists:sort(ets_match_object(Set,{Key,'_'})), + Key = create_partly_bound_tuple(25), + L1 = ets_match_object(OrdSet,{Key,'_'}), + L2 = lists:sort(ets_match_object(Set,{Key,'_'})), case L1 == L2 of false -> io:format("~p != ~p~n", [L1,L2]), - ?line exit({not_eq, L1, L2}); + exit({not_eq, L1, L2}); true -> ok end end, 2000), - ?line do_n_times(fun() -> - ?line Key = create_partly_bound_tuple2(25), - ?line L1 = ets_match_object(OrdSet,{Key,'_'}), - ?line L2 = lists:sort(ets_match_object(Set,{Key,'_'})), + do_n_times(fun() -> + Key = create_partly_bound_tuple2(25), + L1 = ets_match_object(OrdSet,{Key,'_'}), + L2 = lists:sort(ets_match_object(Set,{Key,'_'})), case L1 == L2 of false -> io:format("~p != ~p~n", [L1,L2]), - ?line exit({not_eq, L1, L2}); + exit({not_eq, L1, L2}); true -> ok end end, 2000), do_n_times(fun() -> - ?line Key = create_partly_bound_tuple2(25), - ?line L1 = ets_match(OrdSet,{Key,'_'}), - ?line L2 = lists:sort(ets_match(Set,{Key,'_'})), + Key = create_partly_bound_tuple2(25), + L1 = ets_match(OrdSet,{Key,'_'}), + L2 = lists:sort(ets_match(Set,{Key,'_'})), case L1 == L2 of false -> io:format("~p != ~p~n", [L1,L2]), - ?line exit({not_eq, L1, L2}); + exit({not_eq, L1, L2}); true -> ok end @@ -1530,15 +1450,15 @@ do_random_test() -> ets:match_delete(Set,'_'), do_n_times(fun() -> do_n_times(fun() -> - ?line Value = + Value = create_random_string(25), - ?line Key = create_random_tuple(25), - ?line ets:insert(OrdSet,{Key,Value}), - ?line ets:insert(Set,{Key,Value}) + Key = create_random_tuple(25), + ets:insert(OrdSet,{Key,Value}), + ets:insert(Set,{Key,Value}) end, 500), io:format("~nData inserted~n"), do_n_times(fun() -> - ?line Key = + Key = create_partly_bound_tuple(25), ets:match_delete(OrdSet,{Key,'_'}), ets:match_delete(Set,{Key,'_'}), @@ -1563,16 +1483,13 @@ do_random_test() -> 10), ets:delete(OrdSet), ets:delete(Set), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). -update_element(doc) -> - ["test various variants of update_element"]; -update_element(suite) -> - []; +%% Ttest various variants of update_element. update_element(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), repeat_for_opts(update_element_opts), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). update_element_opts(Opts) -> TupleCases = [{{key,val}, 1 ,2}, @@ -1582,12 +1499,12 @@ update_element_opts(Opts) -> {{val,key,val,val}, 2, [3,4,1]}, {{val,val,key,val}, 3, [1,4,1,2]}, % update pos1 twice {{val,val,val,key}, 4, [2,1,2,3]}],% update pos2 twice - + lists:foreach(fun({Tuple,KeyPos,UpdPos}) -> update_element_opts(Tuple,KeyPos,UpdPos,Opts) end, TupleCases), - + update_element_neg(Opts). - + update_element_opts(Tuple,KeyPos,UpdPos,Opts) -> @@ -1606,16 +1523,15 @@ update_element(T,Tuple,KeyPos,UpdPos) -> update_element_do(T,TupleWithKey,Key,UpdPos) end, KeyList). - + update_element_do(Tab,Tuple,Key,UpdPos) -> - % Strategy: Step around in Values array and call ets:update_element for the values. - % Take Length number of steps of size 1, then of size 2, ..., Length-1. - % This will try all combinations of {fromValue,toValue} - % - % IMPORTANT: size(Values) must be a prime number for this to work!!! + %% Strategy: Step around in Values array and call ets:update_element for the values. + %% Take Length number of steps of size 1, then of size 2, ..., Length-1. + %% This will try all combinations of {fromValue,toValue} + %% + %% IMPORTANT: size(Values) must be a prime number for this to work!!! - %io:format("update_element_do for key=~p\n",[Key]), Big32 = 16#12345678, Big64 = 16#123456789abcdef0, Values = { 623, -27, 0, Big32, -Big32, Big64, -Big64, Big32*Big32, @@ -1625,14 +1541,14 @@ update_element_do(Tab,Tuple,Key,UpdPos) -> (fun(X) -> X*Big32 end), make_ref(), make_ref(), self(), ok, update_element, 28, 29 }, Length = size(Values), - + PosValArgF = fun(ToIx, ResList, [Pos | PosTail], Rand, MeF) -> NextIx = (ToIx+Rand) rem Length, MeF(NextIx, [{Pos,element(ToIx+1,Values)} | ResList], PosTail, Rand, MeF); (_ToIx, ResList, [], _Rand, _MeF) -> ResList; - + (ToIx, [], Pos, _Rand, _MeF) -> {Pos, element(ToIx+1,Values)} % single {pos,value} arg end, @@ -1641,10 +1557,10 @@ update_element_do(Tab,Tuple,Key,UpdPos) -> PosValArg = PosValArgF(ToIx,[],UpdPos,Rand,PosValArgF), %%io:format("update_element(~p)~n",[PosValArg]), ArgHash = erlang:phash2({Tab,Key,PosValArg}), - ?line true = ets:update_element(Tab, Key, PosValArg), - ?line ArgHash = erlang:phash2({Tab,Key,PosValArg}), + true = ets:update_element(Tab, Key, PosValArg), + ArgHash = erlang:phash2({Tab,Key,PosValArg}), NewTuple = update_tuple(PosValArg,Tuple), - ?line [NewTuple] = ets:lookup(Tab,Key) + [NewTuple] = ets:lookup(Tab,Key) end, LoopF = fun(_FromIx, Incr, _Times, Checksum, _MeF) when Incr >= Length -> @@ -1664,11 +1580,11 @@ update_element_do(Tab,Tuple,Key,UpdPos) -> end, FirstTuple = Tuple, - ?line true = ets:insert(Tab,FirstTuple), - ?line [FirstTuple] = ets:lookup(Tab,Key), - + true = ets:insert(Tab,FirstTuple), + [FirstTuple] = ets:lookup(Tab,Key), + Checksum = LoopF(0, 1, Length, 0, LoopF), - ?line Checksum = (Length-1)*Length*(Length+1) div 2, % if Length is a prime + Checksum = (Length-1)*Length*(Length+1) div 2, % if Length is a prime ok. update_tuple({Pos,Val}, Tpl) -> @@ -1686,14 +1602,14 @@ update_element_neg(Opts) -> update_element_neg_do(Set), update_element_neg_do(OrdSet), ets:delete(Set), - ?line {'EXIT',{badarg,_}} = (catch ets:update_element(Set,key,{2,1})), + {'EXIT',{badarg,_}} = (catch ets:update_element(Set,key,{2,1})), ets:delete(OrdSet), - ?line {'EXIT',{badarg,_}} = (catch ets:update_element(OrdSet,key,{2,1})), + {'EXIT',{badarg,_}} = (catch ets:update_element(OrdSet,key,{2,1})), - ?line Bag = ets_new(bag,[bag | Opts]), - ?line DBag = ets_new(duplicate_bag,[duplicate_bag | Opts]), - ?line {'EXIT',{badarg,_}} = (catch ets:update_element(Bag,key,{2,1})), - ?line {'EXIT',{badarg,_}} = (catch ets:update_element(DBag,key,{2,1})), + Bag = ets_new(bag,[bag | Opts]), + DBag = ets_new(duplicate_bag,[duplicate_bag | Opts]), + {'EXIT',{badarg,_}} = (catch ets:update_element(Bag,key,{2,1})), + {'EXIT',{badarg,_}} = (catch ets:update_element(DBag,key,{2,1})), true = ets:delete(Bag), true = ets:delete(DBag), ok. @@ -1701,13 +1617,13 @@ update_element_neg(Opts) -> update_element_neg_do(T) -> Object = {key, 0, "Hej"}, - ?line true = ets:insert(T,Object), + true = ets:insert(T,Object), UpdateF = fun(Arg3) -> ArgHash = erlang:phash2({T,key,Arg3}), - ?line {'EXIT',{badarg,_}} = (catch ets:update_element(T,key,Arg3)), - ?line ArgHash = erlang:phash2({T,key,Arg3}), - ?line [Object] = ets:lookup(T,key) + {'EXIT',{badarg,_}} = (catch ets:update_element(T,key,Arg3)), + ArgHash = erlang:phash2({T,key,Arg3}), + [Object] = ets:lookup(T,key) end, %% List of invalid {Pos,Value} tuples @@ -1723,22 +1639,19 @@ update_element_neg_do(T) -> UpdateF([{2,1} | {3,1}]), lists:foreach(fun(InvTpl) -> UpdateF([{2,1} | InvTpl]) end, InvList), - ?line true = ets:update_element(T,key,[]), - ?line false = ets:update_element(T,false,[]), - ?line false = ets:update_element(T,false,{2,1}), - ?line ets:delete(T,key), - ?line false = ets:update_element(T,key,{2,1}), + true = ets:update_element(T,key,[]), + false = ets:update_element(T,false,[]), + false = ets:update_element(T,false,{2,1}), + ets:delete(T,key), + false = ets:update_element(T,key,{2,1}), ok. -update_counter(doc) -> - ["test various variants of update_counter"]; -update_counter(suite) -> - []; +%% test various variants of update_counter. update_counter(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), repeat_for_opts(update_counter_do), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). update_counter_do(Opts) -> Set = ets_new(set,Opts), @@ -1758,26 +1671,26 @@ update_counter_do(Opts) -> update_counter_neg(Opts). update_counter_for(T) -> - ?line ets:insert(T,{a,1,1}), - ?line 101 = ets:update_counter(T,a,100), - ?line [{a,101,1}] = ets:lookup(T,a), - ?line 101 = ets:update_counter(T,a,{3,100}), - ?line [{a,101,101}] = ets:lookup(T,a), + ets:insert(T,{a,1,1}), + 101 = ets:update_counter(T,a,100), + [{a,101,1}] = ets:lookup(T,a), + 101 = ets:update_counter(T,a,{3,100}), + [{a,101,101}] = ets:lookup(T,a), LooperF = fun(Obj, 0, _, _) -> Obj; - + (Obj, Times, Arg3, Myself) -> - ?line {NewObj, Ret} = uc_mimic(Obj,Arg3), + {NewObj, Ret} = uc_mimic(Obj,Arg3), ArgHash = erlang:phash2({T,a,Arg3}), %%io:format("update_counter(~p, ~p, ~p) expecting ~p\n",[T,a,Arg3,Ret]), [DefaultObj] = ets:lookup(T, a), - ?line Ret = ets:update_counter(T,a,Arg3), + Ret = ets:update_counter(T,a,Arg3), Ret = ets:update_counter(T, b, Arg3, DefaultObj), % Use other key - ?line ArgHash = erlang:phash2({T,a,Arg3}), + ArgHash = erlang:phash2({T,a,Arg3}), %%io:format("NewObj=~p~n ",[NewObj]), - ?line [NewObj] = ets:lookup(T,a), + [NewObj] = ets:lookup(T,a), true = ets:lookup(T, b) =:= [setelement(1, NewObj, b)], ets:delete(T, b), Myself(NewObj,Times-1,Arg3,Myself) @@ -1795,78 +1708,78 @@ update_counter_for(T) -> Steps = 100, Obj0 = {a,0,0,0,0}, - ?line ets:insert(T,Obj0), - ?line Obj1 = LoopF(Obj0, Steps, {2,(SmallMax32 div Steps)*2}), - ?line Obj2 = LoopF(Obj1, Steps, {3,(SmallMax64 div Steps)*2}), - ?line Obj3 = LoopF(Obj2, Steps, {4,(Big1Max32 div Steps)*2}), - ?line Obj4 = LoopF(Obj3, Steps, {5,(Big1Max64 div Steps)*2}), - - ?line Obj5 = LoopF(Obj4, Steps, {2,-(SmallMax32 div Steps)*4}), - ?line Obj6 = LoopF(Obj5, Steps, {3,-(SmallMax64 div Steps)*4}), - ?line Obj7 = LoopF(Obj6, Steps, {4,-(Big1Max32 div Steps)*4}), - ?line Obj8 = LoopF(Obj7, Steps, {5,-(Big1Max64 div Steps)*4}), - - ?line Obj9 = LoopF(Obj8, Steps, {2,(SmallMax32 div Steps)*2}), - ?line ObjA = LoopF(Obj9, Steps, {3,(SmallMax64 div Steps)*2}), - ?line ObjB = LoopF(ObjA, Steps, {4,(Big1Max32 div Steps)*2}), - ?line Obj0 = LoopF(ObjB, Steps, {5,(Big1Max64 div Steps)*2}), + ets:insert(T,Obj0), + Obj1 = LoopF(Obj0, Steps, {2,(SmallMax32 div Steps)*2}), + Obj2 = LoopF(Obj1, Steps, {3,(SmallMax64 div Steps)*2}), + Obj3 = LoopF(Obj2, Steps, {4,(Big1Max32 div Steps)*2}), + Obj4 = LoopF(Obj3, Steps, {5,(Big1Max64 div Steps)*2}), + + Obj5 = LoopF(Obj4, Steps, {2,-(SmallMax32 div Steps)*4}), + Obj6 = LoopF(Obj5, Steps, {3,-(SmallMax64 div Steps)*4}), + Obj7 = LoopF(Obj6, Steps, {4,-(Big1Max32 div Steps)*4}), + Obj8 = LoopF(Obj7, Steps, {5,-(Big1Max64 div Steps)*4}), + + Obj9 = LoopF(Obj8, Steps, {2,(SmallMax32 div Steps)*2}), + ObjA = LoopF(Obj9, Steps, {3,(SmallMax64 div Steps)*2}), + ObjB = LoopF(ObjA, Steps, {4,(Big1Max32 div Steps)*2}), + Obj0 = LoopF(ObjB, Steps, {5,(Big1Max64 div Steps)*2}), %% back at zero, same trip again with lists - ?line Obj4 = LoopF(Obj0,Steps,[{2, (SmallMax32 div Steps)*2}, - {3, (SmallMax64 div Steps)*2}, - {4, (Big1Max32 div Steps)*2}, - {5, (Big1Max64 div Steps)*2}]), + Obj4 = LoopF(Obj0,Steps,[{2, (SmallMax32 div Steps)*2}, + {3, (SmallMax64 div Steps)*2}, + {4, (Big1Max32 div Steps)*2}, + {5, (Big1Max64 div Steps)*2}]), - ?line Obj8 = LoopF(Obj4,Steps,[{4, -(Big1Max32 div Steps)*4}, - {2, -(SmallMax32 div Steps)*4}, - {5, -(Big1Max64 div Steps)*4}, - {3, -(SmallMax64 div Steps)*4}]), + Obj8 = LoopF(Obj4,Steps,[{4, -(Big1Max32 div Steps)*4}, + {2, -(SmallMax32 div Steps)*4}, + {5, -(Big1Max64 div Steps)*4}, + {3, -(SmallMax64 div Steps)*4}]), - ?line Obj0 = LoopF(Obj8,Steps,[{5, (Big1Max64 div Steps)*2}, - {2, (SmallMax32 div Steps)*2}, - {4, (Big1Max32 div Steps)*2}, - {3, (SmallMax64 div Steps)*2}]), + Obj0 = LoopF(Obj8,Steps,[{5, (Big1Max64 div Steps)*2}, + {2, (SmallMax32 div Steps)*2}, + {4, (Big1Max32 div Steps)*2}, + {3, (SmallMax64 div Steps)*2}]), %% make them shift size at the same time - ?line ObjC = LoopF(Obj0,Steps,[{5, (Big1Max64 div Steps)*2}, - {3, (Big1Max64 div Steps)*2 + 1}, - {2, -(Big1Max64 div Steps)*2}, - {4, -(Big1Max64 div Steps)*2 + 1}]), + ObjC = LoopF(Obj0,Steps,[{5, (Big1Max64 div Steps)*2}, + {3, (Big1Max64 div Steps)*2 + 1}, + {2, -(Big1Max64 div Steps)*2}, + {4, -(Big1Max64 div Steps)*2 + 1}]), %% update twice in same list - ?line ObjD = LoopF(ObjC,Steps,[{5, -(Big1Max64 div Steps) + 1}, - {3, -(Big1Max64 div Steps)*2 - 1}, - {5, -(Big1Max64 div Steps) - 1}, - {4, (Big1Max64 div Steps)*2 - 1}]), + ObjD = LoopF(ObjC,Steps,[{5, -(Big1Max64 div Steps) + 1}, + {3, -(Big1Max64 div Steps)*2 - 1}, + {5, -(Big1Max64 div Steps) - 1}, + {4, (Big1Max64 div Steps)*2 - 1}]), - ?line Obj0 = LoopF(ObjD,Steps,[{2, (Big1Max64 div Steps) - 1}, - {4, Big1Max64*2}, - {2, (Big1Max64 div Steps) + 1}, - {4, -Big1Max64*2}]), + Obj0 = LoopF(ObjD,Steps,[{2, (Big1Max64 div Steps) - 1}, + {4, Big1Max64*2}, + {2, (Big1Max64 div Steps) + 1}, + {4, -Big1Max64*2}]), %% warping with list - ?line ObjE = LoopF(Obj0,1000, - [{3,SmallMax32*4 div 5,SmallMax32*2,-SmallMax32*2}, - {5,-SmallMax64*4 div 7,-SmallMax64*2,SmallMax64*2}, - {4,-Big1Max32*4 div 11,-Big1Max32*2,Big1Max32*2}, - {2,Big1Max64*4 div 13,Big1Max64*2,-Big1Max64*2}]), + ObjE = LoopF(Obj0,1000, + [{3,SmallMax32*4 div 5,SmallMax32*2,-SmallMax32*2}, + {5,-SmallMax64*4 div 7,-SmallMax64*2,SmallMax64*2}, + {4,-Big1Max32*4 div 11,-Big1Max32*2,Big1Max32*2}, + {2,Big1Max64*4 div 13,Big1Max64*2,-Big1Max64*2}]), %% warping without list - ?line ObjF = LoopF(ObjE,1000,{3,SmallMax32*4 div 5,SmallMax32*2,-SmallMax32*2}), - ?line ObjG = LoopF(ObjF,1000,{5,-SmallMax64*4 div 7,-SmallMax64*2,SmallMax64*2}), - ?line ObjH = LoopF(ObjG,1000,{4,-Big1Max32*4 div 11,-Big1Max32*2,Big1Max32*2}), - ?line ObjI = LoopF(ObjH,1000,{2,Big1Max64*4 div 13,Big1Max64*2,-Big1Max64*2}), + ObjF = LoopF(ObjE,1000,{3,SmallMax32*4 div 5,SmallMax32*2,-SmallMax32*2}), + ObjG = LoopF(ObjF,1000,{5,-SmallMax64*4 div 7,-SmallMax64*2,SmallMax64*2}), + ObjH = LoopF(ObjG,1000,{4,-Big1Max32*4 div 11,-Big1Max32*2,Big1Max32*2}), + ObjI = LoopF(ObjH,1000,{2,Big1Max64*4 div 13,Big1Max64*2,-Big1Max64*2}), %% mixing it up - ?line LoopF(ObjI,1000, - [{3,SmallMax32*4 div 5,SmallMax32*2,-SmallMax32*2}, - {5,-SmallMax64*4 div 3}, - {3,-SmallMax32*4 div 11}, - {5,0}, - {4,1}, - {5,-SmallMax64*4 div 7,-SmallMax64*2,SmallMax64*2}, - {2,Big1Max64*4 div 13,Big1Max64*2,-Big1Max64*2}]), + LoopF(ObjI,1000, + [{3,SmallMax32*4 div 5,SmallMax32*2,-SmallMax32*2}, + {5,-SmallMax64*4 div 3}, + {3,-SmallMax32*4 div 11}, + {5,0}, + {4,1}, + {5,-SmallMax64*4 div 7,-SmallMax64*2,SmallMax64*2}, + {2,Big1Max64*4 div 13,Big1Max64*2,-Big1Max64*2}]), ok. %% uc_mimic works kind of like the real ets:update_counter @@ -1874,19 +1787,19 @@ update_counter_for(T) -> %% Pits = {Pos,Incr} | {Pos,Incr,Thres,Warp} %% Returns {Updated tuple in ets, Return value from update_counter} uc_mimic(Obj, Pits) when is_tuple(Pits) -> - ?line Pos = element(1,Pits), - ?line NewObj = setelement(Pos, Obj, uc_adder(element(Pos,Obj),Pits)), - ?line {NewObj, element(Pos,NewObj)}; + Pos = element(1,Pits), + NewObj = setelement(Pos, Obj, uc_adder(element(Pos,Obj),Pits)), + {NewObj, element(Pos,NewObj)}; uc_mimic(Obj, PitsList) when is_list(PitsList) -> - ?line {NewObj,ValList} = uc_mimic(Obj,PitsList,[]), - ?line {NewObj,lists:reverse(ValList)}. + {NewObj,ValList} = uc_mimic(Obj,PitsList,[]), + {NewObj,lists:reverse(ValList)}. uc_mimic(Obj, [], Acc) -> - ?line {Obj,Acc}; + {Obj,Acc}; uc_mimic(Obj, [Pits|Tail], Acc) -> - ?line {NewObj,NewVal} = uc_mimic(Obj,Pits), - ?line uc_mimic(NewObj,Tail,[NewVal|Acc]). + {NewObj,NewVal} = uc_mimic(Obj,Pits), + uc_mimic(NewObj,Tail,[NewVal|Acc]). uc_adder(Init, {_Pos, Add}) -> Init + Add; @@ -1899,34 +1812,34 @@ uc_adder(Init, {_Pos, Add, Thres, Warp}) -> Z -> Z end. - + update_counter_neg(Opts) -> Set = ets_new(set,Opts), OrdSet = ets_new(ordered_set,[ordered_set | Opts]), update_counter_neg_for(Set), update_counter_neg_for(OrdSet), ets:delete(Set), - ?line {'EXIT',{badarg,_}} = (catch ets:update_counter(Set,key,1)), + {'EXIT',{badarg,_}} = (catch ets:update_counter(Set,key,1)), ets:delete(OrdSet), - ?line {'EXIT',{badarg,_}} = (catch ets:update_counter(OrdSet,key,1)), + {'EXIT',{badarg,_}} = (catch ets:update_counter(OrdSet,key,1)), - ?line Bag = ets_new(bag,[bag | Opts]), - ?line DBag = ets_new(duplicate_bag,[duplicate_bag | Opts]), - ?line {'EXIT',{badarg,_}} = (catch ets:update_counter(Bag,key,1)), - ?line {'EXIT',{badarg,_}} = (catch ets:update_counter(DBag,key,1)), + Bag = ets_new(bag,[bag | Opts]), + DBag = ets_new(duplicate_bag,[duplicate_bag | Opts]), + {'EXIT',{badarg,_}} = (catch ets:update_counter(Bag,key,1)), + {'EXIT',{badarg,_}} = (catch ets:update_counter(DBag,key,1)), true = ets:delete(Bag), true = ets:delete(DBag), ok. update_counter_neg_for(T) -> Object = {key,0,false,1}, - ?line true = ets:insert(T,Object), + true = ets:insert(T,Object), UpdateF = fun(Arg3) -> ArgHash = erlang:phash2({T,key,Arg3}), - ?line {'EXIT',{badarg,_}} = (catch ets:update_counter(T,key,Arg3)), - ?line ArgHash = erlang:phash2({T,key,Arg3}), - ?line [Object] = ets:lookup(T,key) + {'EXIT',{badarg,_}} = (catch ets:update_counter(T,key,Arg3)), + ArgHash = erlang:phash2({T,key,Arg3}), + [Object] = ets:lookup(T,key) end, %% List of invalid arg3-tuples @@ -1944,12 +1857,12 @@ update_counter_neg_for(T) -> UpdateF([{2,1} | {4,1}]), lists:foreach(fun(Inv) -> UpdateF([{2,1} | Inv]) end, InvList), - ?line {'EXIT',{badarg,_}} = (catch ets:update_counter(T,false,1)), - ?line ets:delete(T,key), - ?line {'EXIT',{badarg,_}} = (catch ets:update_counter(T,key,1)), + {'EXIT',{badarg,_}} = (catch ets:update_counter(T,false,1)), + ets:delete(T,key), + {'EXIT',{badarg,_}} = (catch ets:update_counter(T,key,1)), ok. - + evil_update_counter(Config) when is_list(Config) -> %% The code server uses ets table. Pre-load modules that might not be %% already loaded. @@ -1961,11 +1874,11 @@ evil_update_counter(Config) when is_list(Config) -> repeat_for_opts(evil_update_counter_do). evil_update_counter_do(Opts) -> - ?line EtsMem = etsmem(), - ?line process_flag(trap_exit, true), - ?line Pids = [my_spawn_link(fun() -> evil_counter(I,Opts) end) || I <- lists:seq(1, 40)], - ?line wait_for_all(gb_sets:from_list(Pids)), - ?line verify_etsmem(EtsMem), + EtsMem = etsmem(), + process_flag(trap_exit, true), + Pids = [my_spawn_link(fun() -> evil_counter(I,Opts) end) || I <- lists:seq(1, 40)], + wait_for_all(gb_sets:from_list(Pids)), + verify_etsmem(EtsMem), ok. wait_for_all(Pids0) -> @@ -1975,21 +1888,21 @@ wait_for_all(Pids0) -> false -> receive {'EXIT',Pid,normal} -> - ?line Pids = gb_sets:delete(Pid, Pids0), + Pids = gb_sets:delete(Pid, Pids0), wait_for_all(Pids); Other -> io:format("unexpected: ~p\n", [Other]), - ?line ?t:fail() + ct:fail(failed) end end. evil_counter(I,Opts) -> T = ets_new(a, Opts), Start0 = case I rem 3 of - 0 -> 16#12345678; - 1 -> 16#12345678FFFFFFFF; - 2 -> 16#7777777777FFFFFFFF863648726743 - end, + 0 -> 16#12345678; + 1 -> 16#12345678FFFFFFFF; + 2 -> 16#7777777777FFFFFFFF863648726743 + end, Start = Start0 + rand:uniform(100000), ets:insert(T, {dracula,Start}), Iter = 40000, @@ -2005,7 +1918,7 @@ evil_counter_1(Iter, T) -> evil_counter_1(Iter-1, T). update_counter_with_default(Config) when is_list(Config) -> - repeat_for_opts(update_counter_with_default_do). + repeat_for_opts(update_counter_with_default_do). update_counter_with_default_do(Opts) -> T1 = ets_new(a, [set | Opts]), @@ -2042,20 +1955,17 @@ update_counter_with_default_do(Opts) -> ok. -fixtable_next(doc) -> - ["Check that a first-next sequence always works on a fixed table"]; -fixtable_next(suite) -> - []; +%% Check that a first-next sequence always works on a fixed table. fixtable_next(Config) when is_list(Config) -> repeat_for_opts(fixtable_next_do, [write_concurrency,all_types]). fixtable_next_do(Opts) -> - ?line EtsMem = etsmem(), - ?line do_fixtable_next(ets_new(set,[public | Opts])), - ?line verify_etsmem(EtsMem). - + EtsMem = etsmem(), + do_fixtable_next(ets_new(set,[public | Opts])), + verify_etsmem(EtsMem). + do_fixtable_next(Tab) -> - ?line F = fun(X,T,FF) -> case X of + F = fun(X,T,FF) -> case X of 0 -> true; _ -> ets:insert(T, {X, @@ -2064,74 +1974,70 @@ do_fixtable_next(Tab) -> FF(X-1,T,FF) end end, - ?line F(100,Tab,F), - ?line ets:safe_fixtable(Tab,true), - ?line First = ets:first(Tab), - ?line ets:delete(Tab, First), - ?line ets:next(Tab, First), - ?line ets:match_delete(Tab,{'_','_','_'}), - ?line '$end_of_table' = ets:next(Tab, First), - ?line true = ets:info(Tab, fixed), - ?line ets:safe_fixtable(Tab, false), - ?line false = ets:info(Tab, fixed), - ?line ets:delete(Tab). - -fixtable_insert(doc) -> - ["Check inserts of deleted keys in fixed bags"]; -fixtable_insert(suite) -> - []; + F(100,Tab,F), + ets:safe_fixtable(Tab,true), + First = ets:first(Tab), + ets:delete(Tab, First), + ets:next(Tab, First), + ets:match_delete(Tab,{'_','_','_'}), + '$end_of_table' = ets:next(Tab, First), + true = ets:info(Tab, fixed), + ets:safe_fixtable(Tab, false), + false = ets:info(Tab, fixed), + ets:delete(Tab). + +%% Check inserts of deleted keys in fixed bags. fixtable_insert(Config) when is_list(Config) -> Combos = [[Type,{write_concurrency,WC}] || Type<- [bag,duplicate_bag], WC <- [false,true]], lists:foreach(fun(Opts) -> fixtable_insert_do(Opts) end, Combos), ok. - + fixtable_insert_do(Opts) -> io:format("Opts = ~p\n",[Opts]), Ets = make_table(ets, Opts, [{a,1}, {a,2}, {b,1}, {b,2}]), ets:safe_fixtable(Ets,true), ets:match_delete(Ets,{b,1}), First = ets:first(Ets), - ?line Next = case First of - a -> b; - b -> a - end, - ?line Next = ets:next(Ets,First), + Next = case First of + a -> b; + b -> a + end, + Next = ets:next(Ets,First), ets:delete(Ets,Next), - ?line '$end_of_table' = ets:next(Ets,First), + '$end_of_table' = ets:next(Ets,First), ets:insert(Ets, {Next,1}), - ?line false = ets:insert_new(Ets, {Next,1}), - ?line Next = ets:next(Ets,First), - ?line '$end_of_table' = ets:next(Ets,Next), + false = ets:insert_new(Ets, {Next,1}), + Next = ets:next(Ets,First), + '$end_of_table' = ets:next(Ets,Next), ets:delete(Ets,Next), '$end_of_table' = ets:next(Ets,First), ets:insert(Ets, {Next,2}), - ?line false = ets:insert_new(Ets, {Next,1}), + false = ets:insert_new(Ets, {Next,1}), Next = ets:next(Ets,First), '$end_of_table' = ets:next(Ets,Next), ets:delete(Ets,First), - ?line Next = ets:first(Ets), - ?line '$end_of_table' = ets:next(Ets,Next), + Next = ets:first(Ets), + '$end_of_table' = ets:next(Ets,Next), ets:delete(Ets,Next), - ?line '$end_of_table' = ets:next(Ets,First), - ?line true = ets:insert_new(Ets,{Next,1}), - ?line false = ets:insert_new(Ets,{Next,2}), - ?line Next = ets:next(Ets,First), + '$end_of_table' = ets:next(Ets,First), + true = ets:insert_new(Ets,{Next,1}), + false = ets:insert_new(Ets,{Next,2}), + Next = ets:next(Ets,First), ets:delete_object(Ets,{Next,1}), - ?line '$end_of_table' = ets:next(Ets,First), - ?line true = ets:insert_new(Ets,{Next,2}), - ?line false = ets:insert_new(Ets,{Next,1}), - ?line Next = ets:next(Ets,First), + '$end_of_table' = ets:next(Ets,First), + true = ets:insert_new(Ets,{Next,2}), + false = ets:insert_new(Ets,{Next,1}), + Next = ets:next(Ets,First), ets:delete(Ets,First), ets:safe_fixtable(Ets,false), {'EXIT',{badarg,_}} = (catch ets:next(Ets,First)), ok. -write_concurrency(doc) -> ["The 'write_concurrency' option"]; -write_concurrency(suite) -> []; +%% Test the 'write_concurrency' option. write_concurrency(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), Yes1 = ets_new(foo,[public,{write_concurrency,true}]), Yes2 = ets_new(foo,[protected,{write_concurrency,true}]), No1 = ets_new(foo,[private,{write_concurrency,true}]), @@ -2151,50 +2057,49 @@ write_concurrency(Config) when is_list(Config) -> No7 = ets_new(foo,[public,{write_concurrency,false}]), No8 = ets_new(foo,[protected,{write_concurrency,false}]), - ?line YesMem = ets:info(Yes1,memory), - ?line NoHashMem = ets:info(No1,memory), - ?line NoTreeMem = ets:info(No4,memory), + YesMem = ets:info(Yes1,memory), + NoHashMem = ets:info(No1,memory), + NoTreeMem = ets:info(No4,memory), io:format("YesMem=~p NoHashMem=~p NoTreeMem=~p\n",[YesMem,NoHashMem,NoTreeMem]), - ?line YesMem = ets:info(Yes2,memory), - ?line YesMem = ets:info(Yes3,memory), - ?line YesMem = ets:info(Yes4,memory), - ?line YesMem = ets:info(Yes5,memory), - ?line YesMem = ets:info(Yes6,memory), - ?line NoHashMem = ets:info(No2,memory), - ?line NoHashMem = ets:info(No3,memory), - ?line NoTreeMem = ets:info(No5,memory), - ?line NoTreeMem = ets:info(No6,memory), - ?line NoHashMem = ets:info(No7,memory), - ?line NoHashMem = ets:info(No8,memory), - + YesMem = ets:info(Yes2,memory), + YesMem = ets:info(Yes3,memory), + YesMem = ets:info(Yes4,memory), + YesMem = ets:info(Yes5,memory), + YesMem = ets:info(Yes6,memory), + NoHashMem = ets:info(No2,memory), + NoHashMem = ets:info(No3,memory), + NoTreeMem = ets:info(No5,memory), + NoTreeMem = ets:info(No6,memory), + NoHashMem = ets:info(No7,memory), + NoHashMem = ets:info(No8,memory), + case erlang:system_info(smp_support) of true -> - ?line true = YesMem > NoHashMem, - ?line true = YesMem > NoTreeMem; + true = YesMem > NoHashMem, + true = YesMem > NoTreeMem; false -> - ?line true = YesMem =:= NoHashMem + true = YesMem =:= NoHashMem end, - ?line {'EXIT',{badarg,_}} = (catch ets_new(foo,[public,{write_concurrency,foo}])), - ?line {'EXIT',{badarg,_}} = (catch ets_new(foo,[public,{write_concurrency}])), - ?line {'EXIT',{badarg,_}} = (catch ets_new(foo,[public,{write_concurrency,true,foo}])), - ?line {'EXIT',{badarg,_}} = (catch ets_new(foo,[public,write_concurrency])), + {'EXIT',{badarg,_}} = (catch ets_new(foo,[public,{write_concurrency,foo}])), + {'EXIT',{badarg,_}} = (catch ets_new(foo,[public,{write_concurrency}])), + {'EXIT',{badarg,_}} = (catch ets_new(foo,[public,{write_concurrency,true,foo}])), + {'EXIT',{badarg,_}} = (catch ets_new(foo,[public,write_concurrency])), lists:foreach(fun(T) -> ets:delete(T) end, [Yes1,Yes2,Yes3,Yes4,Yes5,Yes6, No1,No2,No3,No4,No5,No6,No7,No8]), - ?line verify_etsmem(EtsMem), + verify_etsmem(EtsMem), ok. - - -heir(doc) -> ["The 'heir' option"]; -heir(suite) -> []; + + +%% The 'heir' option. heir(Config) when is_list(Config) -> repeat_for_opts(heir_do). heir_do(Opts) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), Master = self(), %% Different types of heir data and link/monitor relations @@ -2203,33 +2108,33 @@ heir_do(Opts) -> lists:seq(1,10), {17,TestFun,self()}, "The busy heir"], Mode<-[none,link,monitor]], - ?line lists:foreach(fun({Data,Mode})-> heir_1(Data,Mode,Opts) end, - Combos), - + lists:foreach(fun({Data,Mode})-> heir_1(Data,Mode,Opts) end, + Combos), + %% No heir {Founder1,MrefF1} = my_spawn_monitor(fun()->heir_founder(Master,foo_data,Opts)end), Founder1 ! {go, none}, - ?line {"No heir",Founder1} = receive_any(), - ?line {'DOWN', MrefF1, process, Founder1, normal} = receive_any(), - ?line undefined = ets:info(foo), + {"No heir",Founder1} = receive_any(), + {'DOWN', MrefF1, process, Founder1, normal} = receive_any(), + undefined = ets:info(foo), %% An already dead heir {Heir2,MrefH2} = my_spawn_monitor(fun()->die end), - ?line {'DOWN', MrefH2, process, Heir2, normal} = receive_any(), + {'DOWN', MrefH2, process, Heir2, normal} = receive_any(), {Founder2,MrefF2} = my_spawn_monitor(fun()->heir_founder(Master,foo_data,Opts)end), Founder2 ! {go, Heir2}, - ?line {"No heir",Founder2} = receive_any(), - ?line {'DOWN', MrefF2, process, Founder2, normal} = receive_any(), - ?line undefined = ets:info(foo), + {"No heir",Founder2} = receive_any(), + {'DOWN', MrefF2, process, Founder2, normal} = receive_any(), + undefined = ets:info(foo), %% When heir dies before founder {Founder3,MrefF3} = my_spawn_monitor(fun()->heir_founder(Master,"The dying heir",Opts)end), {Heir3,MrefH3} = my_spawn_monitor(fun()->heir_heir(Founder3)end), Founder3 ! {go, Heir3}, - ?line {'DOWN', MrefH3, process, Heir3, normal} = receive_any(), + {'DOWN', MrefH3, process, Heir3, normal} = receive_any(), Founder3 ! die_please, - ?line {'DOWN', MrefF3, process, Founder3, normal} = receive_any(), - ?line undefined = ets:info(foo), + {'DOWN', MrefF3, process, Founder3, normal} = receive_any(), + undefined = ets:info(foo), %% When heir dies and pid reused before founder dies repeat_while(fun() -> @@ -2237,238 +2142,235 @@ heir_do(Opts) -> {Founder4,MrefF4} = my_spawn_monitor(fun()->heir_founder(Master,"The dying heir",Opts)end), {Heir4,MrefH4} = my_spawn_monitor(fun()->heir_heir(Founder4)end), Founder4 ! {go, Heir4}, - ?line {'DOWN', MrefH4, process, Heir4, normal} = receive_any(), + {'DOWN', MrefH4, process, Heir4, normal} = receive_any(), erts_debug:set_internal_state(next_pid, NextPidIx), DoppelGanger = spawn_monitor_with_pid(Heir4, - fun()-> ?line die_please = receive_any() end), + fun()-> die_please = receive_any() end), Founder4 ! die_please, - ?line {'DOWN', MrefF4, process, Founder4, normal} = receive_any(), + {'DOWN', MrefF4, process, Founder4, normal} = receive_any(), case DoppelGanger of {Heir4,MrefH4_B} -> Heir4 ! die_please, - ?line {'DOWN', MrefH4_B, process, Heir4, normal} = receive_any(), - ?line undefined = ets:info(foo), + {'DOWN', MrefH4_B, process, Heir4, normal} = receive_any(), + undefined = ets:info(foo), false; failed -> io:format("Failed to spawn process with pid ~p\n", [Heir4]), true % try again end end), - - ?line verify_etsmem(EtsMem). + + verify_etsmem(EtsMem). heir_founder(Master, HeirData, Opts) -> - ?line {go,Heir} = receive_any(), + {go,Heir} = receive_any(), HeirTpl = case Heir of none -> {heir,none}; _ -> {heir, Heir, HeirData} end, - ?line T = ets_new(foo,[named_table, private, HeirTpl | Opts]), - ?line true = ets:insert(T,{key,1}), - ?line [{key,1}] = ets:lookup(T,key), + T = ets_new(foo,[named_table, private, HeirTpl | Opts]), + true = ets:insert(T,{key,1}), + [{key,1}] = ets:lookup(T,key), Self = self(), - ?line Self = ets:info(T,owner), - ?line case ets:info(T,heir) of - none -> - ?line true = (Heir =:= none) orelse (not is_process_alive(Heir)), - Master ! {"No heir",self()}; - - Heir -> - ?line true = is_process_alive(Heir), - Heir ! {table,T,HeirData}, - die_please = receive_any() - end. + Self = ets:info(T,owner), + case ets:info(T,heir) of + none -> + true = (Heir =:= none) orelse (not is_process_alive(Heir)), + Master ! {"No heir",self()}; + + Heir -> + true = is_process_alive(Heir), + Heir ! {table,T,HeirData}, + die_please = receive_any() + end. heir_heir(Founder) -> heir_heir(Founder, none). heir_heir(Founder, Mode) -> - ?line {table,T,HeirData} = receive_any(), - ?line {'EXIT',{badarg,_}} = (catch ets:lookup(T,key)), - ?line case HeirData of - "The dying heir" -> exit(normal); - _ -> ok - end, + {table,T,HeirData} = receive_any(), + {'EXIT',{badarg,_}} = (catch ets:lookup(T,key)), + case HeirData of + "The dying heir" -> exit(normal); + _ -> ok + end, - ?line Mref = case Mode of - link -> process_flag(trap_exit, true), - link(Founder); - monitor -> erlang:monitor(process,Founder); - none -> ok - end, - ?line Founder ! die_please, - ?line Msg = case HeirData of - "The busy heir" -> receive_any_spinning(); - _ -> receive_any() - end, - ?line {'ETS-TRANSFER', T, Founder, HeirData} = Msg, - ?line foo = T, - ?line Self = self(), - ?line Self = ets:info(T,owner), - ?line Self = ets:info(T,heir), - ?line [{key,1}] = ets:lookup(T,key), - ?line true = ets:insert(T,{key,2}), - ?line [{key,2}] = ets:lookup(T,key), - ?line case Mode of % Verify that EXIT or DOWN comes after ETS-TRANSFER - link -> - {'EXIT',Founder,normal} = receive_any(), - process_flag(trap_exit, false); - monitor -> - {'DOWN', Mref, process, Founder, normal} = receive_any(); - none -> ok - end. + Mref = case Mode of + link -> process_flag(trap_exit, true), + link(Founder); + monitor -> erlang:monitor(process,Founder); + none -> ok + end, + Founder ! die_please, + Msg = case HeirData of + "The busy heir" -> receive_any_spinning(); + _ -> receive_any() + end, + {'ETS-TRANSFER', T, Founder, HeirData} = Msg, + foo = T, + Self = self(), + Self = ets:info(T,owner), + Self = ets:info(T,heir), + [{key,1}] = ets:lookup(T,key), + true = ets:insert(T,{key,2}), + [{key,2}] = ets:lookup(T,key), + case Mode of % Verify that EXIT or DOWN comes after ETS-TRANSFER + link -> + {'EXIT',Founder,normal} = receive_any(), + process_flag(trap_exit, false); + monitor -> + {'DOWN', Mref, process, Founder, normal} = receive_any(); + none -> ok + end. heir_1(HeirData,Mode,Opts) -> io:format("test with heir_data = ~p\n", [HeirData]), Master = self(), - ?line Founder = my_spawn_link(fun() -> heir_founder(Master,HeirData,Opts) end), + Founder = my_spawn_link(fun() -> heir_founder(Master,HeirData,Opts) end), io:format("founder spawned = ~p\n", [Founder]), - ?line {Heir,Mref} = my_spawn_monitor(fun() -> heir_heir(Founder,Mode) end), + {Heir,Mref} = my_spawn_monitor(fun() -> heir_heir(Founder,Mode) end), io:format("heir spawned = ~p\n", [{Heir,Mref}]), - ?line Founder ! {go, Heir}, - ?line {'DOWN', Mref, process, Heir, normal} = receive_any(). + Founder ! {go, Heir}, + {'DOWN', Mref, process, Heir, normal} = receive_any(). -give_away(doc) -> ["ets:give_way/3"]; -give_away(suite) -> []; +%% Test ets:give_way/3. give_away(Config) when is_list(Config) -> repeat_for_opts(give_away_do). give_away_do(Opts) -> - ?line T = ets_new(foo,[named_table, private | Opts]), - ?line true = ets:insert(T,{key,1}), - ?line [{key,1}] = ets:lookup(T,key), + T = ets_new(foo,[named_table, private | Opts]), + true = ets:insert(T,{key,1}), + [{key,1}] = ets:lookup(T,key), Parent = self(), %% Give and then give back - ?line {Receiver,Mref} = my_spawn_monitor(fun()-> give_away_receiver(T,Parent) end), - ?line give_me = receive_any(), - ?line true = ets:give_away(T,Receiver,here_you_are), - ?line {'EXIT',{badarg,_}} = (catch ets:lookup(T,key)), - ?line Receiver ! give_back, - ?line {'ETS-TRANSFER',T,Receiver,"Tillbakakaka"} = receive_any(), - ?line [{key,2}] = ets:lookup(T,key), - ?line {'DOWN', Mref, process, Receiver, normal} = receive_any(), + {Receiver,Mref} = my_spawn_monitor(fun()-> give_away_receiver(T,Parent) end), + give_me = receive_any(), + true = ets:give_away(T,Receiver,here_you_are), + {'EXIT',{badarg,_}} = (catch ets:lookup(T,key)), + Receiver ! give_back, + {'ETS-TRANSFER',T,Receiver,"Tillbakakaka"} = receive_any(), + [{key,2}] = ets:lookup(T,key), + {'DOWN', Mref, process, Receiver, normal} = receive_any(), %% Give and then let receiver keep it - ?line true = ets:insert(T,{key,1}), - ?line {Receiver3,Mref3} = my_spawn_monitor(fun()-> give_away_receiver(T,Parent) end), - ?line give_me = receive_any(), - ?line true = ets:give_away(T,Receiver3,here_you_are), - ?line {'EXIT',{badarg,_}} = (catch ets:lookup(T,key)), - ?line Receiver3 ! die_please, - ?line {'DOWN', Mref3, process, Receiver3, normal} = receive_any(), - ?line undefined = ets:info(T), + true = ets:insert(T,{key,1}), + {Receiver3,Mref3} = my_spawn_monitor(fun()-> give_away_receiver(T,Parent) end), + give_me = receive_any(), + true = ets:give_away(T,Receiver3,here_you_are), + {'EXIT',{badarg,_}} = (catch ets:lookup(T,key)), + Receiver3 ! die_please, + {'DOWN', Mref3, process, Receiver3, normal} = receive_any(), + undefined = ets:info(T), %% Give and then kill receiver to get back - ?line T2 = ets_new(foo,[private | Opts]), - ?line true = ets:insert(T2,{key,1}), - ?line ets:setopts(T2,{heir,self(),"Som en gummiboll..."}), - ?line {Receiver2,Mref2} = my_spawn_monitor(fun()-> give_away_receiver(T2,Parent) end), - ?line give_me = receive_any(), - ?line true = ets:give_away(T2,Receiver2,here_you_are), - ?line {'EXIT',{badarg,_}} = (catch ets:lookup(T2,key)), - ?line Receiver2 ! die_please, - ?line {'ETS-TRANSFER',T2,Receiver2,"Som en gummiboll..."} = receive_any(), - ?line [{key,2}] = ets:lookup(T2,key), - ?line {'DOWN', Mref2, process, Receiver2, normal} = receive_any(), + T2 = ets_new(foo,[private | Opts]), + true = ets:insert(T2,{key,1}), + ets:setopts(T2,{heir,self(),"Som en gummiboll..."}), + {Receiver2,Mref2} = my_spawn_monitor(fun()-> give_away_receiver(T2,Parent) end), + give_me = receive_any(), + true = ets:give_away(T2,Receiver2,here_you_are), + {'EXIT',{badarg,_}} = (catch ets:lookup(T2,key)), + Receiver2 ! die_please, + {'ETS-TRANSFER',T2,Receiver2,"Som en gummiboll..."} = receive_any(), + [{key,2}] = ets:lookup(T2,key), + {'DOWN', Mref2, process, Receiver2, normal} = receive_any(), %% Some negative testing - ?line {'EXIT',{badarg,_}} = (catch ets:give_away(T2,Receiver,"To a dead one")), - ?line {'EXIT',{badarg,_}} = (catch ets:give_away(T2,self(),"To myself")), - ?line {'EXIT',{badarg,_}} = (catch ets:give_away(T2,"not a pid","To wrong type")), + {'EXIT',{badarg,_}} = (catch ets:give_away(T2,Receiver,"To a dead one")), + {'EXIT',{badarg,_}} = (catch ets:give_away(T2,self(),"To myself")), + {'EXIT',{badarg,_}} = (catch ets:give_away(T2,"not a pid","To wrong type")), - ?line true = ets:delete(T2), - ?line {ReceiverNeg,MrefNeg} = my_spawn_monitor(fun()-> give_away_receiver(T2,Parent) end), - ?line give_me = receive_any(), - ?line {'EXIT',{badarg,_}} = (catch ets:give_away(T2,ReceiverNeg,"A deleted table")), + true = ets:delete(T2), + {ReceiverNeg,MrefNeg} = my_spawn_monitor(fun()-> give_away_receiver(T2,Parent) end), + give_me = receive_any(), + {'EXIT',{badarg,_}} = (catch ets:give_away(T2,ReceiverNeg,"A deleted table")), - ?line T3 = ets_new(foo,[public | Opts]), + T3 = ets_new(foo,[public | Opts]), my_spawn_link(fun()-> {'EXIT',{badarg,_}} = (catch ets:give_away(T3,ReceiverNeg,"From non owner")), - Parent ! done - end), - ?line done = receive_any(), - ?line ReceiverNeg ! no_soup_for_you, - ?line {'DOWN', MrefNeg, process, ReceiverNeg, normal} = receive_any(), + Parent ! done + end), + done = receive_any(), + ReceiverNeg ! no_soup_for_you, + {'DOWN', MrefNeg, process, ReceiverNeg, normal} = receive_any(), ok. give_away_receiver(T, Giver) -> - ?line {'EXIT',{badarg,_}} = (catch ets:lookup(T,key)), - ?line Giver ! give_me, - ?line case receive_any() of - {'ETS-TRANSFER',T,Giver,here_you_are} -> - ?line [{key,1}] = ets:lookup(T,key), - ?line true = ets:insert(T,{key,2}), - ?line case receive_any() of - give_back -> - ?line true = ets:give_away(T,Giver,"Tillbakakaka"), - ?line {'EXIT',{badarg,_}} = (catch ets:lookup(T,key)); - die_please -> - ok - end; - no_soup_for_you -> - ok - end. - - -setopts(doc) -> ["ets:setopts/2"]; -setopts(suite) -> []; + {'EXIT',{badarg,_}} = (catch ets:lookup(T,key)), + Giver ! give_me, + case receive_any() of + {'ETS-TRANSFER',T,Giver,here_you_are} -> + [{key,1}] = ets:lookup(T,key), + true = ets:insert(T,{key,2}), + case receive_any() of + give_back -> + true = ets:give_away(T,Giver,"Tillbakakaka"), + {'EXIT',{badarg,_}} = (catch ets:lookup(T,key)); + die_please -> + ok + end; + no_soup_for_you -> + ok + end. + + +%% Test ets:setopts/2. setopts(Config) when is_list(Config) -> repeat_for_opts(setopts_do,[write_concurrency,all_types]). setopts_do(Opts) -> Self = self(), - ?line T = ets_new(foo,[named_table, private | Opts]), - ?line none = ets:info(T,heir), + T = ets_new(foo,[named_table, private | Opts]), + none = ets:info(T,heir), Heir = my_spawn_link(fun()->heir_heir(Self) end), - ?line ets:setopts(T,{heir,Heir,"Data"}), - ?line Heir = ets:info(T,heir), - ?line ets:setopts(T,{heir,self(),"Data"}), - ?line Self = ets:info(T,heir), - ?line ets:setopts(T,[{heir,Heir,"Data"}]), - ?line Heir = ets:info(T,heir), - ?line ets:setopts(T,[{heir,none}]), - ?line none = ets:info(T,heir), - - ?line {'EXIT',{badarg,_}} = (catch ets:setopts(T,[{heir,self(),"Data"},false])), - ?line {'EXIT',{badarg,_}} = (catch ets:setopts(T,{heir,self()})), - ?line {'EXIT',{badarg,_}} = (catch ets:setopts(T,{heir,false})), - ?line {'EXIT',{badarg,_}} = (catch ets:setopts(T,heir)), - ?line {'EXIT',{badarg,_}} = (catch ets:setopts(T,{heir,false,"Data"})), - ?line {'EXIT',{badarg,_}} = (catch ets:setopts(T,{false,self(),"Data"})), - - ?line ets:setopts(T,{protection,protected}), - ?line ets:setopts(T,{protection,public}), - ?line ets:setopts(T,{protection,private}), - ?line ets:setopts(T,[{protection,protected}]), - ?line ets:setopts(T,[{protection,public}]), - ?line ets:setopts(T,[{protection,private}]), - - ?line {'EXIT',{badarg,_}} = (catch ets:setopts(T,{protection})), - ?line {'EXIT',{badarg,_}} = (catch ets:setopts(T,{protection,false})), - ?line {'EXIT',{badarg,_}} = (catch ets:setopts(T,{protection,private,false})), - ?line {'EXIT',{badarg,_}} = (catch ets:setopts(T,protection)), - ?line ets:delete(T), + ets:setopts(T,{heir,Heir,"Data"}), + Heir = ets:info(T,heir), + ets:setopts(T,{heir,self(),"Data"}), + Self = ets:info(T,heir), + ets:setopts(T,[{heir,Heir,"Data"}]), + Heir = ets:info(T,heir), + ets:setopts(T,[{heir,none}]), + none = ets:info(T,heir), + + {'EXIT',{badarg,_}} = (catch ets:setopts(T,[{heir,self(),"Data"},false])), + {'EXIT',{badarg,_}} = (catch ets:setopts(T,{heir,self()})), + {'EXIT',{badarg,_}} = (catch ets:setopts(T,{heir,false})), + {'EXIT',{badarg,_}} = (catch ets:setopts(T,heir)), + {'EXIT',{badarg,_}} = (catch ets:setopts(T,{heir,false,"Data"})), + {'EXIT',{badarg,_}} = (catch ets:setopts(T,{false,self(),"Data"})), + + ets:setopts(T,{protection,protected}), + ets:setopts(T,{protection,public}), + ets:setopts(T,{protection,private}), + ets:setopts(T,[{protection,protected}]), + ets:setopts(T,[{protection,public}]), + ets:setopts(T,[{protection,private}]), + + {'EXIT',{badarg,_}} = (catch ets:setopts(T,{protection})), + {'EXIT',{badarg,_}} = (catch ets:setopts(T,{protection,false})), + {'EXIT',{badarg,_}} = (catch ets:setopts(T,{protection,private,false})), + {'EXIT',{badarg,_}} = (catch ets:setopts(T,protection)), + ets:delete(T), unlink(Heir), exit(Heir, bang), ok. -bad_table(doc) -> ["All kinds of operations with bad table argument"]; -bad_table(suite) -> []; +%% All kinds of operations with bad table argument. bad_table(Config) when is_list(Config) -> %% Open and close disk_log to stabilize etsmem. Name = make_ref(), - ?line File = filename:join([?config(priv_dir, Config),"bad_table.dummy"]), - ?line {ok, Name} = disk_log:open([{name, Name}, {file, File}]), - ?line disk_log:close(Name), + File = filename:join([proplists:get_value(priv_dir, Config),"bad_table.dummy"]), + {ok, Name} = disk_log:open([{name, Name}, {file, File}]), + disk_log:close(Name), file:delete(File), - ?line EtsMem = etsmem(), + EtsMem = etsmem(), repeat_for_opts(fun(Opts) -> bad_table_do(Opts,File) end, [write_concurrency, all_types]), - ?line verify_etsmem(EtsMem), + verify_etsmem(EtsMem), ok. bad_table_do(Opts, DummyFile) -> @@ -2552,26 +2454,23 @@ bad_table_op({Opts,Priv,Prot}, Op) -> end. bad_table_call(T,{F,Args,_}) -> - ?line {'EXIT',{badarg,_}} = (catch apply(ets, F, [T|Args])); + {'EXIT',{badarg,_}} = (catch apply(ets, F, [T|Args])); bad_table_call(T,{F,Args,_,tabarg_last}) -> - ?line {'EXIT',{badarg,_}} = (catch apply(ets, F, Args++[T])); + {'EXIT',{badarg,_}} = (catch apply(ets, F, Args++[T])); bad_table_call(T,{F,Args,_,{return,Return}}) -> try - ?line Return = apply(ets, F, [T|Args]) + Return = apply(ets, F, [T|Args]) catch error:badarg -> ok end. -rename(doc) -> - ["Check rename of ets tables"]; -rename(suite) -> - []; +%% Check rename of ets tables. rename(Config) when is_list(Config) -> repeat_for_opts(rename_do, [write_concurrency, all_types]). rename_do(Opts) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), ets_new(foobazz,[named_table, public | Opts]), ets:insert(foobazz,{foo,bazz}), ungermanbazz = ets:rename(foobazz,ungermanbazz), @@ -2579,42 +2478,38 @@ rename_do(Opts) -> [{foo,bazz}] = ets:lookup(ungermanbazz,foo), {'EXIT',{badarg,_}} = (catch ets:rename(ungermanbazz,"no atom")), ets:delete(ungermanbazz), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). -rename_unnamed(doc) -> - ["Check rename of unnamed ets table"]; -rename_unnamed(suite) -> - []; +%% Check rename of unnamed ets table. rename_unnamed(Config) when is_list(Config) -> repeat_for_opts(rename_unnamed_do,[write_concurrency,all_types]). rename_unnamed_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(bonkz,[public | Opts]), - ?line {'EXIT',{badarg, _}} = (catch ets:insert(bonkz,{foo,bazz})), - ?line bonkz = ets:info(Tab, name), - ?line Tab = ets:rename(Tab, tjabonkz), - ?line {'EXIT',{badarg, _}} = (catch ets:insert(tjabonkz,{foo,bazz})), - ?line tjabonkz = ets:info(Tab, name), - ?line ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -evil_rename(doc) -> - "Rename a table with many fixations, and at the same time delete it."; + EtsMem = etsmem(), + Tab = ets_new(bonkz,[public | Opts]), + {'EXIT',{badarg, _}} = (catch ets:insert(bonkz,{foo,bazz})), + bonkz = ets:info(Tab, name), + Tab = ets:rename(Tab, tjabonkz), + {'EXIT',{badarg, _}} = (catch ets:insert(tjabonkz,{foo,bazz})), + tjabonkz = ets:info(Tab, name), + ets:delete(Tab), + verify_etsmem(EtsMem). + +%% Rename a table with many fixations, and at the same time delete it. evil_rename(Config) when is_list(Config) -> - ?line evil_rename_1(old_hash, new_hash, [public,named_table]), - ?line EtsMem = etsmem(), - ?line evil_rename_1(old_tree, new_tree, [public,ordered_set,named_table]), - ?line verify_etsmem(EtsMem). + evil_rename_1(old_hash, new_hash, [public,named_table]), + EtsMem = etsmem(), + evil_rename_1(old_tree, new_tree, [public,ordered_set,named_table]), + verify_etsmem(EtsMem). evil_rename_1(Old, New, Flags) -> - ?line process_flag(trap_exit, true), - ?line Old = ets_new(Old, Flags), - ?line Fixer = fun() -> ets:safe_fixtable(Old, true) end, - ?line crazy_fixtable(15000, Fixer), - ?line erlang:yield(), - ?line New = ets:rename(Old, New), - ?line erlang:yield(), + process_flag(trap_exit, true), + Old = ets_new(Old, Flags), + Fixer = fun() -> ets:safe_fixtable(Old, true) end, + crazy_fixtable(15000, Fixer), + erlang:yield(), + New = ets:rename(Old, New), + erlang:yield(), ets:delete(New), ok. @@ -2657,19 +2552,16 @@ evil_create_fixed_tab() -> ets:safe_fixtable(T, true), T. -interface_equality(doc) -> - ["Tests that the return values and errors are equal for set's and" - " ordered_set's where applicable"]; -interface_equality(suite) -> - []; +%% Tests that the return values and errors are equal for set's and +%% ordered_set's where applicable. interface_equality(Config) when is_list(Config) -> repeat_for_opts(interface_equality_do). interface_equality_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Set = ets_new(set,[set | Opts]), - ?line OrderedSet = ets_new(ordered_set,[ordered_set | Opts]), - ?line F = fun(X,T,FF) -> case X of + EtsMem = etsmem(), + Set = ets_new(set,[set | Opts]), + OrderedSet = ets_new(ordered_set,[ordered_set | Opts]), + F = fun(X,T,FF) -> case X of 0 -> true; _ -> ets:insert(T, {X, @@ -2678,38 +2570,38 @@ interface_equality_do(Opts) -> FF(X-1,T,FF) end end, - ?line F(100,Set,F), - ?line F(100,OrderedSet,F), - ?line equal_results(ets, insert, Set, OrderedSet, [{a,"a"}]), - ?line equal_results(ets, insert, Set, OrderedSet, [{1,1,"1"}]), - ?line equal_results(ets, lookup, Set, OrderedSet, [10]), - ?line equal_results(ets, lookup, Set, OrderedSet, [1000]), - ?line equal_results(ets, delete, Set, OrderedSet, [10]), - ?line equal_results(ets, delete, Set, OrderedSet, [nott]), - ?line equal_results(ets, lookup, Set, OrderedSet, [1000]), - ?line equal_results(ets, insert, Set, OrderedSet, [10]), - ?line equal_results(ets, next, Set, OrderedSet, ['$end_of_table']), - ?line equal_results(ets, prev, Set, OrderedSet, ['$end_of_table']), - ?line equal_results(ets, match, Set, OrderedSet, [{'_','_','_'}]), - ?line equal_results(ets, match, Set, OrderedSet, [{'_','_','_','_'}]), - ?line equal_results(ets, match, Set, OrderedSet, [{$3,$2,2}]), - ?line equal_results(ets, match, Set, OrderedSet, ['_']), - ?line equal_results(ets, match, Set, OrderedSet, ['$1']), - ?line equal_results(ets, match, Set, OrderedSet, [{'_','$50',3}]), - ?line equal_results(ets, match, Set, OrderedSet, [['_','$50',3]]), - ?line equal_results(ets, match_delete, Set, OrderedSet, [{'_','_',4}]), - ?line equal_results(ets, match_delete, Set, OrderedSet, [{'_','_',4}]), - ?line equal_results(ets, match_object, Set, OrderedSet, [{'_','_',4}]), - ?line equal_results(ets, match_object, Set, OrderedSet, [{'_','_',5}]), - ?line equal_results(ets, match_object, Set, OrderedSet, [{'_','_',4}]), - ?line equal_results(ets, match_object, Set, OrderedSet, ['_']), - ?line equal_results(ets, match_object, Set, OrderedSet, ['$5011']), - ?line equal_results(ets, match_delete, Set, OrderedSet, ['$20']), - ?line equal_results(ets, lookup_element, Set, OrderedSet, [13,2]), - ?line equal_results(ets, lookup_element, Set, OrderedSet, [13,4]), - ?line equal_results(ets, lookup_element, Set, OrderedSet, [14,2]), - ?line equal_results(ets, delete, Set, OrderedSet, []), - ?line verify_etsmem(EtsMem). + F(100,Set,F), + F(100,OrderedSet,F), + equal_results(ets, insert, Set, OrderedSet, [{a,"a"}]), + equal_results(ets, insert, Set, OrderedSet, [{1,1,"1"}]), + equal_results(ets, lookup, Set, OrderedSet, [10]), + equal_results(ets, lookup, Set, OrderedSet, [1000]), + equal_results(ets, delete, Set, OrderedSet, [10]), + equal_results(ets, delete, Set, OrderedSet, [nott]), + equal_results(ets, lookup, Set, OrderedSet, [1000]), + equal_results(ets, insert, Set, OrderedSet, [10]), + equal_results(ets, next, Set, OrderedSet, ['$end_of_table']), + equal_results(ets, prev, Set, OrderedSet, ['$end_of_table']), + equal_results(ets, match, Set, OrderedSet, [{'_','_','_'}]), + equal_results(ets, match, Set, OrderedSet, [{'_','_','_','_'}]), + equal_results(ets, match, Set, OrderedSet, [{$3,$2,2}]), + equal_results(ets, match, Set, OrderedSet, ['_']), + equal_results(ets, match, Set, OrderedSet, ['$1']), + equal_results(ets, match, Set, OrderedSet, [{'_','$50',3}]), + equal_results(ets, match, Set, OrderedSet, [['_','$50',3]]), + equal_results(ets, match_delete, Set, OrderedSet, [{'_','_',4}]), + equal_results(ets, match_delete, Set, OrderedSet, [{'_','_',4}]), + equal_results(ets, match_object, Set, OrderedSet, [{'_','_',4}]), + equal_results(ets, match_object, Set, OrderedSet, [{'_','_',5}]), + equal_results(ets, match_object, Set, OrderedSet, [{'_','_',4}]), + equal_results(ets, match_object, Set, OrderedSet, ['_']), + equal_results(ets, match_object, Set, OrderedSet, ['$5011']), + equal_results(ets, match_delete, Set, OrderedSet, ['$20']), + equal_results(ets, lookup_element, Set, OrderedSet, [13,2]), + equal_results(ets, lookup_element, Set, OrderedSet, [13,4]), + equal_results(ets, lookup_element, Set, OrderedSet, [14,2]), + equal_results(ets, delete, Set, OrderedSet, []), + verify_etsmem(EtsMem). equal_results(M, F, FirstArg1, FirstArg2 ,ACommon) -> Res = maybe_sort((catch apply(M,F, [FirstArg1 | ACommon]))), @@ -2717,8 +2609,6 @@ equal_results(M, F, FirstArg1, FirstArg2 ,ACommon) -> maybe_sort(L) when is_list(L) -> lists:sort(L); -%maybe_sort({'EXIT',{Reason, [{Module, Function, _}|_]}}) -> -% {'EXIT',{Reason, [{Module, Function, '_'}]}}; maybe_sort({'EXIT',{Reason, List}}) when is_list(List) -> {'EXIT',{Reason, lists:map(fun({Module, Function, _, _}) -> {Module, Function, '_'} @@ -2727,30 +2617,27 @@ maybe_sort({'EXIT',{Reason, List}}) when is_list(List) -> maybe_sort(Any) -> Any. -ordered_match(doc) -> - ["Test match, match_object and match_delete in ordered set's"]; -ordered_match(suite) -> - []; +%% Test match, match_object and match_delete in ordered set's. ordered_match(Config) when is_list(Config)-> repeat_for_opts(ordered_match_do). ordered_match_do(Opts) -> - ?line EtsMem = etsmem(), - ?line F = fun(X,T,FF) -> case X of - 0 -> true; - _ -> - ets:insert(T, {X, - integer_to_list(X), - X rem 10, - X rem 100, - X rem 1000}), - FF(X-1,T,FF) - end + EtsMem = etsmem(), + F = fun(X,T,FF) -> case X of + 0 -> true; + _ -> + ets:insert(T, {X, + integer_to_list(X), + X rem 10, + X rem 100, + X rem 1000}), + FF(X-1,T,FF) + end end, - ?line T1 = ets_new(xxx,[ordered_set| Opts]), - ?line F(3000,T1,F), - ?line [[3,3],[3,3],[3,3]] = ets:match(T1, {'_','_','$1','$2',3}), - ?line F2 = fun(X,Rem,Res,FF) -> case X of + T1 = ets_new(xxx,[ordered_set| Opts]), + F(3000,T1,F), + [[3,3],[3,3],[3,3]] = ets:match(T1, {'_','_','$1','$2',3}), + F2 = fun(X,Rem,Res,FF) -> case X of 0 -> []; _ -> case X rem Rem of @@ -2766,166 +2653,153 @@ ordered_match_do(Opts) -> end end end, - ?line OL1 = F2(3000,100,2,F2), - ?line OL1 = ets:match_object(T1, {'_','_','_',2,'_'}), - ?line true = ets:match_delete(T1,{'_','_','_',2,'_'}), - ?line [] = ets:match_object(T1, {'_','_','_',2,'_'}), - ?line OL2 = F2(3000,100,3,F2), - ?line OL2 = ets:match_object(T1, {'_','_','_',3,'_'}), - ?line ets:delete(T1), - ?line verify_etsmem(EtsMem). - - -ordered(doc) -> - ["Test basic functionality in ordered_set's."]; -ordered(suite) -> - []; + OL1 = F2(3000,100,2,F2), + OL1 = ets:match_object(T1, {'_','_','_',2,'_'}), + true = ets:match_delete(T1,{'_','_','_',2,'_'}), + [] = ets:match_object(T1, {'_','_','_',2,'_'}), + OL2 = F2(3000,100,3,F2), + OL2 = ets:match_object(T1, {'_','_','_',3,'_'}), + ets:delete(T1), + verify_etsmem(EtsMem). + + +%% Test basic functionality in ordered_set's. ordered(Config) when is_list(Config) -> repeat_for_opts(ordered_do). ordered_do(Opts) -> - ?line EtsMem = etsmem(), - ?line T = ets_new(oset, [ordered_set | Opts]), - ?line InsList = [ - 25,26,27,28, - 5,6,7,8, - 21,22,23,24, - 9,10,11,12, - 1,2,3,4, - 17,18,19,20, - 13,14,15,16, - 1 bsl 33 - ], - ?line lists:foreach(fun(X) -> + EtsMem = etsmem(), + T = ets_new(oset, [ordered_set | Opts]), + InsList = [ + 25,26,27,28, + 5,6,7,8, + 21,22,23,24, + 9,10,11,12, + 1,2,3,4, + 17,18,19,20, + 13,14,15,16, + 1 bsl 33 + ], + lists:foreach(fun(X) -> ets:insert(T,{X,integer_to_list(X)}) end, InsList), - ?line IL2 = lists:map(fun(X) -> {X,integer_to_list(X)} end, InsList), - ?line L1 = pick_all_forward(T), - ?line L2 = pick_all_backwards(T), - ?line S1 = lists:sort(IL2), - ?line S2 = lists:reverse(lists:sort(IL2)), - ?line S1 = L1, - ?line S2 = L2, - ?line [{1,"1"}] = ets:slot(T,0), - ?line [{28,"28"}] = ets:slot(T,27), - ?line [{1 bsl 33,_}] = ets:slot(T,28), - ?line 27 = ets:prev(T,28), - ?line [{7,"7"}] = ets:slot(T,6), - ?line '$end_of_table' = ets:next(T,1 bsl 33), - ?line [{12,"12"}] = ets:slot(T,11), - ?line '$end_of_table' = ets:slot(T,29), - ?line [{1,"1"}] = ets:slot(T,0), - ?line 28 = ets:prev(T,1 bsl 33), - ?line 1 = ets:next(T,0), - ?line pick_all_forward(T), - ?line [{7,"7"}] = ets:slot(T,6), - ?line L2 = pick_all_backwards(T), - ?line [{7,"7"}] = ets:slot(T,6), - ?line ets:delete(T), - ?line verify_etsmem(EtsMem). + IL2 = lists:map(fun(X) -> {X,integer_to_list(X)} end, InsList), + L1 = pick_all_forward(T), + L2 = pick_all_backwards(T), + S1 = lists:sort(IL2), + S2 = lists:reverse(lists:sort(IL2)), + S1 = L1, + S2 = L2, + [{1,"1"}] = ets:slot(T,0), + [{28,"28"}] = ets:slot(T,27), + [{1 bsl 33,_}] = ets:slot(T,28), + 27 = ets:prev(T,28), + [{7,"7"}] = ets:slot(T,6), + '$end_of_table' = ets:next(T,1 bsl 33), + [{12,"12"}] = ets:slot(T,11), + '$end_of_table' = ets:slot(T,29), + [{1,"1"}] = ets:slot(T,0), + 28 = ets:prev(T,1 bsl 33), + 1 = ets:next(T,0), + pick_all_forward(T), + [{7,"7"}] = ets:slot(T,6), + L2 = pick_all_backwards(T), + [{7,"7"}] = ets:slot(T,6), + ets:delete(T), + verify_etsmem(EtsMem). pick_all(_T,'$end_of_table',_How) -> []; pick_all(T,Last,How) -> - ?line This = case How of + This = case How of next -> - ?line ets:next(T,Last); + ets:next(T,Last); prev -> - ?line ets:prev(T,Last) + ets:prev(T,Last) end, - ?line [LastObj] = ets:lookup(T,Last), - ?line [LastObj | pick_all(T,This,How)]. + [LastObj] = ets:lookup(T,Last), + [LastObj | pick_all(T,This,How)]. pick_all_forward(T) -> - ?line pick_all(T,ets:first(T),next). + pick_all(T,ets:first(T),next). pick_all_backwards(T) -> - ?line pick_all(T,ets:last(T),prev). - - + pick_all(T,ets:last(T),prev). -setbag(doc) -> ["Small test case for both set and bag type ets tables."]; -setbag(suite) -> []; + + +%% Small test case for both set and bag type ets tables. setbag(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line Set = ets_new(set,[set]), - ?line Bag = ets_new(bag,[bag]), - ?line Key = {foo,bar}, - + EtsMem = etsmem(), + Set = ets_new(set,[set]), + Bag = ets_new(bag,[bag]), + Key = {foo,bar}, + %% insert some value - ?line ets:insert(Set,{Key,val1}), - ?line ets:insert(Bag,{Key,val1}), - + ets:insert(Set,{Key,val1}), + ets:insert(Bag,{Key,val1}), + %% insert new value for same key again - ?line ets:insert(Set,{Key,val2}), - ?line ets:insert(Bag,{Key,val2}), - + ets:insert(Set,{Key,val2}), + ets:insert(Bag,{Key,val2}), + %% check - ?line [{Key,val2}] = ets:lookup(Set,Key), - ?line [{Key,val1},{Key,val2}] = ets:lookup(Bag,Key), + [{Key,val2}] = ets:lookup(Set,Key), + [{Key,val1},{Key,val2}] = ets:lookup(Bag,Key), true = ets:delete(Set), true = ets:delete(Bag), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). -badnew(doc) -> - ["Test case to check proper return values for illegal ets_new() calls."]; -badnew(suite) -> []; +%% Test case to check proper return values for illegal ets_new() calls. badnew(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line {'EXIT',{badarg,_}} = (catch ets_new(12,[])), - ?line {'EXIT',{badarg,_}} = (catch ets_new({a,b},[])), - ?line {'EXIT',{badarg,_}} = (catch ets_new(name,[foo])), - ?line {'EXIT',{badarg,_}} = (catch ets_new(name,{bag})), - ?line {'EXIT',{badarg,_}} = (catch ets_new(name,bag)), - ?line verify_etsmem(EtsMem). - -verybadnew(doc) -> - ["Test case to check that a not well formed list does not crash the " - "emulator. OTP-2314 "]; -verybadnew(suite) -> []; + EtsMem = etsmem(), + {'EXIT',{badarg,_}} = (catch ets_new(12,[])), + {'EXIT',{badarg,_}} = (catch ets_new({a,b},[])), + {'EXIT',{badarg,_}} = (catch ets_new(name,[foo])), + {'EXIT',{badarg,_}} = (catch ets_new(name,{bag})), + {'EXIT',{badarg,_}} = (catch ets_new(name,bag)), + verify_etsmem(EtsMem). + +%% OTP-2314. Test case to check that a non-proper list does not +%% crash the emulator. verybadnew(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line {'EXIT',{badarg,_}} = (catch ets_new(verybad,[set|protected])), - ?line verify_etsmem(EtsMem). + EtsMem = etsmem(), + {'EXIT',{badarg,_}} = (catch ets_new(verybad,[set|protected])), + verify_etsmem(EtsMem). -named(doc) -> ["Small check to see if named tables work."]; -named(suite) -> []; +%% Small check to see if named tables work. named(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line Tab = make_table(foo, - [named_table], - [{key,val}]), - ?line [{key,val}] = ets:lookup(foo,key), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -keypos2(doc) -> ["Test case to check if specified keypos works."]; -keypos2(suite) -> []; + EtsMem = etsmem(), + Tab = make_table(foo, + [named_table], + [{key,val}]), + [{key,val}] = ets:lookup(foo,key), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + +%% Test case to check if specified keypos works. keypos2(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line Tab = make_table(foo, - [set,{keypos,2}], - [{val,key}, {val2,key}]), - ?line [{val2,key}] = ets:lookup(Tab,key), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -privacy(doc) -> - ["Privacy check. Check that a named(public/private/protected) table " - "cannot be read by", - "the wrong process(es)."]; -privacy(suite) -> []; + EtsMem = etsmem(), + Tab = make_table(foo, + [set,{keypos,2}], + [{val,key}, {val2,key}]), + [{val2,key}] = ets:lookup(Tab,key), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + +%% Privacy check. Check that a named(public/private/protected) table +%% cannot be read by the wrong process(es). privacy(Config) when is_list(Config) -> repeat_for_opts(privacy_do). privacy_do(Opts) -> - ?line EtsMem = etsmem(), - ?line process_flag(trap_exit,true), - ?line Owner = my_spawn_link(?MODULE,privacy_owner,[self(),Opts]), + EtsMem = etsmem(), + process_flag(trap_exit,true), + Owner = my_spawn_link(?MODULE,privacy_owner,[self(),Opts]), receive {'EXIT',Owner,Reason} -> - ?line exit({privacy_test,Reason}); + exit({privacy_test,Reason}); ok -> ok end, @@ -2946,21 +2820,21 @@ privacy_do(Opts) -> Owner ! die, receive {'EXIT',Owner,_} -> ok end, - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). privacy_check(Pub,Prot,Priv) -> %% check read rights - ?line [] = ets:lookup(Pub, foo), - ?line [] = ets:lookup(Prot,foo), - ?line {'EXIT',{badarg,_}} = (catch ets:lookup(Priv,foo)), + [] = ets:lookup(Pub, foo), + [] = ets:lookup(Prot,foo), + {'EXIT',{badarg,_}} = (catch ets:lookup(Priv,foo)), %% check write rights - ?line true = ets:insert(Pub, {1,foo}), - ?line {'EXIT',{badarg,_}} = (catch ets:insert(Prot,{2,foo})), - ?line {'EXIT',{badarg,_}} = (catch ets:insert(Priv,{3,foo})), + true = ets:insert(Pub, {1,foo}), + {'EXIT',{badarg,_}} = (catch ets:insert(Prot,{2,foo})), + {'EXIT',{badarg,_}} = (catch ets:insert(Priv,{3,foo})), %% check that it really wasn't written, either - ?line [] = ets:lookup(Prot,foo). + [] = ets:lookup(Prot,foo). privacy_owner(Boss, Opts) -> ets_new(pub, [public,named_table | Opts]), @@ -2973,7 +2847,7 @@ privacy_owner_loop(Boss) -> receive {shift,N,Pub_Prot_Priv} -> {Pub,Prot,Priv} = rotate_tuple(Pub_Prot_Priv, N), - + ets:setopts(Pub,{protection,public}), ets:setopts(Prot,{protection,protected}), ets:setopts(Priv,{protection,private}), @@ -2993,82 +2867,81 @@ rotate_tuple(Tuple, N) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -empty(doc) -> - ["Check lookup in an empty table and lookup of a non-existing key"]; -empty(suite) -> []; +%% Check lookup in an empty table and lookup of a non-existing key. empty(Config) when is_list(Config) -> repeat_for_opts(empty_do). empty_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(foo,Opts), - ?line [] = ets:lookup(Tab,key), - ?line true = ets:insert(Tab,{key2,val}), - ?line [] = ets:lookup(Tab,key), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -badinsert(doc) -> - ["Check proper return values for illegal insert operations."]; -badinsert(suite) -> []; + EtsMem = etsmem(), + Tab = ets_new(foo,Opts), + [] = ets:lookup(Tab,key), + true = ets:insert(Tab,{key2,val}), + [] = ets:lookup(Tab,key), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + +%% Check proper return values for illegal insert operations. badinsert(Config) when is_list(Config) -> repeat_for_opts(badinsert_do). badinsert_do(Opts) -> - ?line EtsMem = etsmem(), - ?line {'EXIT',{badarg,_}} = (catch ets:insert(foo,{key,val})), - - ?line Tab = ets_new(foo,Opts), - ?line {'EXIT',{badarg,_}} = (catch ets:insert(Tab,{})), + EtsMem = etsmem(), + {'EXIT',{badarg,_}} = (catch ets:insert(foo,{key,val})), + + Tab = ets_new(foo,Opts), + {'EXIT',{badarg,_}} = (catch ets:insert(Tab,{})), - ?line Tab3 = ets_new(foo,[{keypos,3}| Opts]), - ?line {'EXIT',{badarg,_}} = (catch ets:insert(Tab3,{a,b})), + Tab3 = ets_new(foo,[{keypos,3}| Opts]), + {'EXIT',{badarg,_}} = (catch ets:insert(Tab3,{a,b})), - ?line {'EXIT',{badarg,_}} = (catch ets:insert(Tab,[key,val2])), - ?line true = ets:delete(Tab), - ?line true = ets:delete(Tab3), - ?line verify_etsmem(EtsMem). + {'EXIT',{badarg,_}} = (catch ets:insert(Tab,[key,val2])), + true = ets:delete(Tab), + true = ets:delete(Tab3), + verify_etsmem(EtsMem). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -time_lookup(doc) -> ["Lookup timing."]; -time_lookup(suite) -> []; +%% Test lookup timing. time_lookup(Config) when is_list(Config) -> %% just for timing, really - ?line EtsMem = etsmem(), + EtsMem = etsmem(), Values = repeat_for_opts(time_lookup_do), - ?line verify_etsmem(EtsMem), - ?line {comment,lists:flatten(io_lib:format( - "~p ets lookups/s",[Values]))}. + verify_etsmem(EtsMem), + {comment,lists:flatten(io_lib:format( + "~p ets lookups/s",[Values]))}. time_lookup_do(Opts) -> Tab = ets_new(foo,Opts), fill_tab(Tab,foo), ets:insert(Tab,{{a,key},foo}), - {Time,_} = ?t:timecall(test_server,do_times, - [100000,ets,lookup,[Tab,{a,key}]]), + N = 100000, + {Time,_} = timer:tc(fun() -> time_lookup_many(N, Tab) end), + Seconds = Time / 1000000, true = ets:delete(Tab), - round(100000 / Time). % lookups/s + round(N / Seconds). % lookups/s + +time_lookup_many(0, _Tab) -> + ok; +time_lookup_many(N, Tab) -> + ets:lookup(Tab, {a,key}), + time_lookup_many(N-1, Tab). -badlookup(doc) -> - ["Check proper return values from bad lookups in existing/non existing " - " ets tables"]; -badlookup(suite) -> []; +%% Check proper return values from bad lookups in existing/non existing +%% ets tables. badlookup(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line {'EXIT',{badarg,_}} = (catch ets:lookup(foo,key)), - ?line Tab = ets_new(foo,[]), - ?line ets:delete(Tab), - ?line {'EXIT',{badarg,_}} = (catch ets:lookup(Tab,key)), - ?line verify_etsmem(EtsMem). - -lookup_order(doc) -> ["Test that lookup returns objects in order of insertion for bag and dbag."]; -lookup_order(suite) -> []; + EtsMem = etsmem(), + {'EXIT',{badarg,_}} = (catch ets:lookup(foo,key)), + Tab = ets_new(foo,[]), + ets:delete(Tab), + {'EXIT',{badarg,_}} = (catch ets:lookup(Tab,key)), + verify_etsmem(EtsMem). + +%% Test that lookup returns objects in order of insertion for bag and dbag. lookup_order(Config) when is_list(Config) -> EtsMem = etsmem(), repeat_for_opts(lookup_order_do, [write_concurrency,[bag,duplicate_bag]]), - ?line verify_etsmem(EtsMem), + verify_etsmem(EtsMem), ok. lookup_order_do(Opts) -> @@ -3105,7 +2978,7 @@ lookup_order_2(Opts, Fixed) -> true = ets:delete(T) end, Combos). - + check_insert({T,List0,Key},Val) -> %%io:format("insert ~p into ~p\n",[Val,List0]), @@ -3120,7 +2993,7 @@ check_insert({T,List0,Key},Val) -> check_insert_new({T,List0,Key},Val) -> %%io:format("insert_new ~p into ~p\n",[Val,List0]), Ret = ets:insert_new(T,{Key,Val}), - ?line Ret = (List0 =:= []), + Ret = (List0 =:= []), List1 = case Ret of true -> [{Key,Val}]; false -> List0 @@ -3139,40 +3012,39 @@ check_check(S={T,List,Key}) -> case lists:reverse(ets:lookup(T,Key)) of List -> ok; ETS -> io:format("check failed:\nETS: ~p\nCHK: ~p\n", [ETS,List]), - ?t:fail("Invalid return value from ets:lookup") + ct:fail("Invalid return value from ets:lookup") end, - ?line Items = ets:info(T,size), - ?line Items = length(List), + Items = ets:info(T,size), + Items = length(List), S. - + fill_tab(Tab,Val) -> - ?line ets:insert(Tab,{key,Val}), - ?line ets:insert(Tab,{{a,144},Val}), - ?line ets:insert(Tab,{{a,key2},Val}), - ?line ets:insert(Tab,{14,Val}), + ets:insert(Tab,{key,Val}), + ets:insert(Tab,{{a,144},Val}), + ets:insert(Tab,{{a,key2},Val}), + ets:insert(Tab,{14,Val}), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -lookup_element_mult(doc) -> ["Multiple return elements (OTP-2386)"]; -lookup_element_mult(suite) -> []; +%% OTP-2386. Multiple return elements. lookup_element_mult(Config) when is_list(Config) -> repeat_for_opts(lookup_element_mult_do). lookup_element_mult_do(Opts) -> - ?line EtsMem = etsmem(), - ?line T = ets_new(service, [bag, {keypos, 2} | Opts]), - ?line D = lists:reverse(lem_data()), - ?line lists:foreach(fun(X) -> ets:insert(T, X) end, D), - ?line ok = lem_crash_3(T), - ?line ets:insert(T, {0, "heap_key"}), - ?line ets:lookup_element(T, "heap_key", 2), - ?line true = ets:delete(T), - ?line verify_etsmem(EtsMem). + EtsMem = etsmem(), + T = ets_new(service, [bag, {keypos, 2} | Opts]), + D = lists:reverse(lem_data()), + lists:foreach(fun(X) -> ets:insert(T, X) end, D), + ok = lem_crash_3(T), + ets:insert(T, {0, "heap_key"}), + ets:lookup_element(T, "heap_key", 2), + true = ets:delete(T), + verify_etsmem(EtsMem). lem_data() -> [ @@ -3199,69 +3071,64 @@ lem_crash_3(T) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -delete_elem(doc) -> - ["Check delete of an element inserted in a `filled' table."]; -delete_elem(suite) -> []; +%% Check delete of an element inserted in a `filled' table. delete_elem(Config) when is_list(Config) -> repeat_for_opts(delete_elem_do, [write_concurrency, all_types]). delete_elem_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(foo,Opts), - ?line fill_tab(Tab,foo), - ?line ets:insert(Tab,{{b,key},foo}), - ?line ets:insert(Tab,{{c,key},foo}), - ?line true = ets:delete(Tab,{b,key}), - ?line [] = ets:lookup(Tab,{b,key}), - ?line [{{c,key},foo}] = ets:lookup(Tab,{c,key}), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -delete_tab(doc) -> - ["Check that ets:delete() works and releases the name of the deleted " - "table."]; -delete_tab(suite) -> []; + EtsMem = etsmem(), + Tab = ets_new(foo,Opts), + fill_tab(Tab,foo), + ets:insert(Tab,{{b,key},foo}), + ets:insert(Tab,{{c,key},foo}), + true = ets:delete(Tab,{b,key}), + [] = ets:lookup(Tab,{b,key}), + [{{c,key},foo}] = ets:lookup(Tab,{c,key}), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + +%% Check that ets:delete() works and releases the name of the +%% deleted table. delete_tab(Config) when is_list(Config) -> repeat_for_opts(delete_tab_do,[write_concurrency,all_types]). delete_tab_do(Opts) -> Name = foo, - ?line EtsMem = etsmem(), - ?line Name = ets_new(Name, [named_table | Opts]), - ?line true = ets:delete(foo), + EtsMem = etsmem(), + Name = ets_new(Name, [named_table | Opts]), + true = ets:delete(foo), %% The name should be available again. - ?line Name = ets_new(Name, [named_table | Opts]), - ?line true = ets:delete(Name), - ?line verify_etsmem(EtsMem). + Name = ets_new(Name, [named_table | Opts]), + true = ets:delete(Name), + verify_etsmem(EtsMem). -delete_large_tab(doc) -> - "Check that ets:delete/1 works and that other processes can run."; +%% Check that ets:delete/1 works and that other processes can run. delete_large_tab(Config) when is_list(Config) -> - ?line Data = [{erlang:phash2(I, 16#ffffff),I} || I <- lists:seq(1, 200000)], - ?line EtsMem = etsmem(), + Data = [{erlang:phash2(I, 16#ffffff),I} || I <- lists:seq(1, 200000)], + EtsMem = etsmem(), repeat_for_opts(fun(Opts) -> delete_large_tab_do(Opts,Data) end), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). delete_large_tab_do(Opts,Data) -> - ?line delete_large_tab_1(foo_hash, Opts, Data, false), - ?line delete_large_tab_1(foo_tree, [ordered_set | Opts], Data, false), - ?line delete_large_tab_1(foo_hash, Opts, Data, true). + delete_large_tab_1(foo_hash, Opts, Data, false), + delete_large_tab_1(foo_tree, [ordered_set | Opts], Data, false), + delete_large_tab_1(foo_hash, Opts, Data, true). delete_large_tab_1(Name, Flags, Data, Fix) -> - ?line Tab = ets_new(Name, Flags), - ?line ets:insert(Tab, Data), + Tab = ets_new(Name, Flags), + ets:insert(Tab, Data), case Fix of false -> ok; true -> - ?line true = ets:safe_fixtable(Tab, true), - ?line lists:foreach(fun({K,_}) -> ets:delete(Tab, K) end, Data) + true = ets:safe_fixtable(Tab, true), + lists:foreach(fun({K,_}) -> ets:delete(Tab, K) end, Data) end, {priority, Prio} = process_info(self(), priority), - ?line Deleter = self(), - ?line [SchedTracer] + Deleter = self(), + [SchedTracer] = start_loopers(1, Prio, fun (SC) -> @@ -3281,59 +3148,59 @@ delete_large_tab_1(Name, Flags, Data, Fix) -> end, 0), SchedTracerMon = monitor(process, SchedTracer), - ?line Loopers = start_loopers(erlang:system_info(schedulers), - Prio, - fun (_) -> erlang:yield() end, - ok), - ?line erlang:yield(), - ?line 1 = erlang:trace(self(),true,[running,procs,{tracer,SchedTracer}]), - ?line true = ets:delete(Tab), + Loopers = start_loopers(erlang:system_info(schedulers), + Prio, + fun (_) -> erlang:yield() end, + ok), + erlang:yield(), + 1 = erlang:trace(self(),true,[running,procs,{tracer,SchedTracer}]), + true = ets:delete(Tab), %% The register stuff is just a trace marker - ?line true = register(delete_large_tab_done_marker, self()), - ?line true = unregister(delete_large_tab_done_marker), - ?line undefined = ets:info(Tab), - ?line ok = stop_loopers(Loopers), - ?line receive - {schedule_count, N} -> - ?line io:format("~s: context switches: ~p", [Name,N]), - if - N >= 5 -> ?line ok; - true -> ?line ?t:fail() - end - end, + true = register(delete_large_tab_done_marker, self()), + true = unregister(delete_large_tab_done_marker), + undefined = ets:info(Tab), + ok = stop_loopers(Loopers), + receive + {schedule_count, N} -> + io:format("~s: context switches: ~p", [Name,N]), + if + N >= 5 -> ok; + true -> ct:fail(failed) + end + end, receive {'DOWN',SchedTracerMon,process,SchedTracer,_} -> ok end, ok. -delete_large_named_table(doc) -> - "Delete a large name table and try to create a new table with the same name in another process."; +%% Delete a large name table and try to create a new table with +%% the same name in another process. delete_large_named_table(Config) when is_list(Config) -> - ?line Data = [{erlang:phash2(I, 16#ffffff),I} || I <- lists:seq(1, 200000)], - ?line EtsMem = etsmem(), + Data = [{erlang:phash2(I, 16#ffffff),I} || I <- lists:seq(1, 200000)], + EtsMem = etsmem(), repeat_for_opts(fun(Opts) -> delete_large_named_table_do(Opts,Data) end), - ?line verify_etsmem(EtsMem), + verify_etsmem(EtsMem), ok. delete_large_named_table_do(Opts,Data) -> - ?line delete_large_named_table_1(foo_hash, [named_table | Opts], Data, false), - ?line delete_large_named_table_1(foo_tree, [ordered_set,named_table | Opts], Data, false), - ?line delete_large_named_table_1(foo_hash, [named_table | Opts], Data, true). + delete_large_named_table_1(foo_hash, [named_table | Opts], Data, false), + delete_large_named_table_1(foo_tree, [ordered_set,named_table | Opts], Data, false), + delete_large_named_table_1(foo_hash, [named_table | Opts], Data, true). delete_large_named_table_1(Name, Flags, Data, Fix) -> - ?line Tab = ets_new(Name, Flags), - ?line ets:insert(Tab, Data), + Tab = ets_new(Name, Flags), + ets:insert(Tab, Data), case Fix of false -> ok; true -> - ?line true = ets:safe_fixtable(Tab, true), - ?line lists:foreach(fun({K,_}) -> ets:delete(Tab, K) end, Data) + true = ets:safe_fixtable(Tab, true), + lists:foreach(fun({K,_}) -> ets:delete(Tab, K) end, Data) end, Parent = self(), {Pid, MRef} = my_spawn_opt(fun() -> - receive - ets_new -> - ets_new(Name, [named_table]) - end + receive + ets_new -> + ets_new(Name, [named_table]) + end end, [link, monitor]), true = ets:delete(Tab), @@ -3341,139 +3208,128 @@ delete_large_named_table_1(Name, Flags, Data, Fix) -> receive {'DOWN',MRef,process,Pid,_} -> ok end, ok. -evil_delete(doc) -> - "Delete a large table, and kill the process during the delete."; +%% Delete a large table, and kill the process during the delete. evil_delete(Config) when is_list(Config) -> - ?line Data = [{I,I*I} || I <- lists:seq(1, 100000)], + Data = [{I,I*I} || I <- lists:seq(1, 100000)], repeat_for_opts(fun(Opts) -> evil_delete_do(Opts,Data) end). evil_delete_do(Opts,Data) -> - ?line EtsMem = etsmem(), - ?line evil_delete_owner(foo_hash, Opts, Data, false), - ?line verify_etsmem(EtsMem), - ?line evil_delete_owner(foo_hash, Opts, Data, true), - ?line verify_etsmem(EtsMem), - ?line evil_delete_owner(foo_tree, [ordered_set | Opts], Data, false), - ?line verify_etsmem(EtsMem), - ?line TabA = evil_delete_not_owner(foo_hash, Opts, Data, false), - ?line verify_etsmem(EtsMem), - ?line TabB = evil_delete_not_owner(foo_hash, Opts, Data, true), - ?line verify_etsmem(EtsMem), - ?line TabC = evil_delete_not_owner(foo_tree, [ordered_set | Opts], Data, false), - ?line verify_etsmem(EtsMem), - ?line lists:foreach(fun(T) -> undefined = ets:info(T) end, - [TabA,TabB,TabC]). + EtsMem = etsmem(), + evil_delete_owner(foo_hash, Opts, Data, false), + verify_etsmem(EtsMem), + evil_delete_owner(foo_hash, Opts, Data, true), + verify_etsmem(EtsMem), + evil_delete_owner(foo_tree, [ordered_set | Opts], Data, false), + verify_etsmem(EtsMem), + TabA = evil_delete_not_owner(foo_hash, Opts, Data, false), + verify_etsmem(EtsMem), + TabB = evil_delete_not_owner(foo_hash, Opts, Data, true), + verify_etsmem(EtsMem), + TabC = evil_delete_not_owner(foo_tree, [ordered_set | Opts], Data, false), + verify_etsmem(EtsMem), + lists:foreach(fun(T) -> undefined = ets:info(T) end, + [TabA,TabB,TabC]). evil_delete_not_owner(Name, Flags, Data, Fix) -> io:format("Not owner: ~p, fix = ~p", [Name,Fix]), - ?line Tab = ets_new(Name, [public|Flags]), - ?line ets:insert(Tab, Data), + Tab = ets_new(Name, [public|Flags]), + ets:insert(Tab, Data), case Fix of false -> ok; true -> - ?line true = ets:safe_fixtable(Tab, true), - ?line lists:foreach(fun({K,_}) -> ets:delete(Tab, K) end, Data) + true = ets:safe_fixtable(Tab, true), + lists:foreach(fun({K,_}) -> ets:delete(Tab, K) end, Data) end, - ?line Pid = my_spawn(fun() -> - P = my_spawn_link( - fun() -> - receive kill -> ok end, - erlang:yield(), - exit(kill_linked_processes_now) - end), - erlang:yield(), - P ! kill, - true = ets:delete(Tab) - end), - ?line Ref = erlang:monitor(process, Pid), - ?line receive {'DOWN',Ref,_,_,_} -> ok end, + Pid = my_spawn(fun() -> + P = my_spawn_link( + fun() -> + receive kill -> ok end, + erlang:yield(), + exit(kill_linked_processes_now) + end), + erlang:yield(), + P ! kill, + true = ets:delete(Tab) + end), + Ref = erlang:monitor(process, Pid), + receive {'DOWN',Ref,_,_,_} -> ok end, Tab. evil_delete_owner(Name, Flags, Data, Fix) -> - ?line Fun = fun() -> - ?line Tab = ets_new(Name, [public|Flags]), - ?line ets:insert(Tab, Data), - case Fix of - false -> ok; - true -> - ?line true = ets:safe_fixtable(Tab, true), - ?line lists:foreach(fun({K,_}) -> - ets:delete(Tab, K) - end, Data) - end, - erlang:yield(), - my_spawn_link(fun() -> - erlang:yield(), - exit(kill_linked_processes_now) - end), - true = ets:delete(Tab) - end, - ?line Pid = my_spawn(Fun), - ?line Ref = erlang:monitor(process, Pid), - ?line receive {'DOWN',Ref,_,_,_} -> ok end. - - -exit_large_table_owner(doc) -> - []; -exit_large_table_owner(suite) -> - []; + Fun = fun() -> + Tab = ets_new(Name, [public|Flags]), + ets:insert(Tab, Data), + case Fix of + false -> ok; + true -> + true = ets:safe_fixtable(Tab, true), + lists:foreach(fun({K,_}) -> + ets:delete(Tab, K) + end, Data) + end, + erlang:yield(), + my_spawn_link(fun() -> + erlang:yield(), + exit(kill_linked_processes_now) + end), + true = ets:delete(Tab) + end, + Pid = my_spawn(Fun), + Ref = erlang:monitor(process, Pid), + receive {'DOWN',Ref,_,_,_} -> ok end. + + exit_large_table_owner(Config) when is_list(Config) -> - %%?line Data = [{erlang:phash2(I, 16#ffffff),I} || I <- lists:seq(1, 500000)], - ?line FEData = fun(Do) -> repeat_while(fun(500000) -> {false,ok}; - (I) -> Do({erlang:phash2(I, 16#ffffff),I}), - {true, I+1} - end, 1) - end, - ?line EtsMem = etsmem(), + %%Data = [{erlang:phash2(I, 16#ffffff),I} || I <- lists:seq(1, 500000)], + FEData = fun(Do) -> repeat_while(fun(500000) -> {false,ok}; + (I) -> Do({erlang:phash2(I, 16#ffffff),I}), + {true, I+1} + end, 1) + end, + EtsMem = etsmem(), repeat_for_opts({exit_large_table_owner_do,{FEData,Config}}), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). exit_large_table_owner_do(Opts,{FEData,Config}) -> - ?line verify_rescheduling_exit(Config, FEData, [named_table | Opts], true, 1, 1), - ?line verify_rescheduling_exit(Config, FEData, Opts, false, 1, 1). + verify_rescheduling_exit(Config, FEData, [named_table | Opts], true, 1, 1), + verify_rescheduling_exit(Config, FEData, Opts, false, 1, 1). -exit_many_large_table_owner(doc) -> []; -exit_many_large_table_owner(suite) -> []; exit_many_large_table_owner(Config) when is_list(Config) -> - %%?line Data = [{erlang:phash2(I, 16#ffffff),I} || I <- lists:seq(1, 500000)], - ?line FEData = fun(Do) -> repeat_while(fun(500000) -> {false,ok}; - (I) -> Do({erlang:phash2(I, 16#ffffff),I}), - {true, I+1} - end, 1) - end, - ?line EtsMem = etsmem(), + %%Data = [{erlang:phash2(I, 16#ffffff),I} || I <- lists:seq(1, 500000)], + FEData = fun(Do) -> repeat_while(fun(500000) -> {false,ok}; + (I) -> Do({erlang:phash2(I, 16#ffffff),I}), + {true, I+1} + end, 1) + end, + EtsMem = etsmem(), repeat_for_opts(fun(Opts) -> exit_many_large_table_owner_do(Opts,FEData,Config) end), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). exit_many_large_table_owner_do(Opts,FEData,Config) -> - ?line verify_rescheduling_exit(Config, FEData, Opts, true, 1, 4), - ?line verify_rescheduling_exit(Config, FEData, [named_table | Opts], false, 1, 4). + verify_rescheduling_exit(Config, FEData, Opts, true, 1, 4), + verify_rescheduling_exit(Config, FEData, [named_table | Opts], false, 1, 4). -exit_many_tables_owner(doc) -> []; -exit_many_tables_owner(suite) -> []; exit_many_tables_owner(Config) when is_list(Config) -> NoData = fun(_Do) -> ok end, - ?line EtsMem = etsmem(), - ?line verify_rescheduling_exit(Config, NoData, [named_table], false, 1000, 1), - ?line verify_rescheduling_exit(Config, NoData, [named_table,{write_concurrency,true}], false, 1000, 1), - ?line verify_etsmem(EtsMem). + EtsMem = etsmem(), + verify_rescheduling_exit(Config, NoData, [named_table], false, 1000, 1), + verify_rescheduling_exit(Config, NoData, [named_table,{write_concurrency,true}], false, 1000, 1), + verify_etsmem(EtsMem). -exit_many_many_tables_owner(doc) -> []; -exit_many_many_tables_owner(suite) -> []; exit_many_many_tables_owner(Config) when is_list(Config) -> - ?line Data = [{erlang:phash2(I, 16#ffffff),I} || I <- lists:seq(1, 50)], - ?line FEData = fun(Do) -> lists:foreach(Do, Data) end, + Data = [{erlang:phash2(I, 16#ffffff),I} || I <- lists:seq(1, 50)], + FEData = fun(Do) -> lists:foreach(Do, Data) end, repeat_for_opts(fun(Opts) -> exit_many_many_tables_owner_do(Opts,FEData,Config) end). exit_many_many_tables_owner_do(Opts,FEData,Config) -> - ?line verify_rescheduling_exit(Config, FEData, [named_table | Opts], true, 200, 5), - ?line verify_rescheduling_exit(Config, FEData, Opts, false, 200, 5), - ?line wait_for_test_procs(), - ?line EtsMem = etsmem(), - ?line verify_rescheduling_exit(Config, FEData, Opts, true, 200, 5), - ?line verify_rescheduling_exit(Config, FEData, [named_table | Opts], false, 200, 5), - ?line verify_etsmem(EtsMem). - + verify_rescheduling_exit(Config, FEData, [named_table | Opts], true, 200, 5), + verify_rescheduling_exit(Config, FEData, Opts, false, 200, 5), + wait_for_test_procs(), + EtsMem = etsmem(), + verify_rescheduling_exit(Config, FEData, Opts, true, 200, 5), + verify_rescheduling_exit(Config, FEData, [named_table | Opts], false, 200, 5), + verify_etsmem(EtsMem). + count_exit_sched(TP) -> receive @@ -3515,11 +3371,11 @@ vre_fix_tables(Tab) -> ok. verify_rescheduling_exit(Config, ForEachData, Flags, Fix, NOTabs, NOProcs) -> - ?line NoFix = 5, - ?line TestCase = atom_to_list(?config(test_case, Config)), - ?line Parent = self(), - ?line KillMe = make_ref(), - ?line PFun = + NoFix = 5, + TestCase = atom_to_list(proplists:get_value(test_case, Config)), + Parent = self(), + KillMe = make_ref(), + PFun = fun () -> repeat( fun () -> @@ -3537,7 +3393,7 @@ verify_rescheduling_exit(Config, ForEachData, Flags, Fix, NOTabs, NOProcs) -> lists:seq(1,NoFix)), KeyPos = ets:info(Tab,keypos), ForEachData(fun(Data) -> - ets:delete(Tab, element(KeyPos,Data)) + ets:delete(Tab, element(KeyPos,Data)) end) end end, @@ -3545,89 +3401,82 @@ verify_rescheduling_exit(Config, ForEachData, Flags, Fix, NOTabs, NOProcs) -> Parent ! {KillMe, self()}, receive after infinity -> ok end end, - ?line TPs = lists:map(fun (_) -> - ?line TP = my_spawn_link(PFun), - ?line 1 = erlang:trace(TP, true, [exiting]), - TP - end, - lists:seq(1, NOProcs)), - ?line lists:foreach(fun (TP) -> - receive {KillMe, TP} -> ok end - end, - TPs), - ?line LPs = start_loopers(erlang:system_info(schedulers), - normal, - fun (_) -> - erlang:yield() - end, - ok), - ?line lists:foreach(fun (TP) -> - ?line unlink(TP), - ?line exit(TP, bang) - end, - TPs), - ?line lists:foreach(fun (TP) -> - ?line XScheds = count_exit_sched(TP), - ?line ?t:format("~p XScheds=~p~n", - [TP, XScheds]), - ?line true = XScheds >= 5 + TPs = lists:map(fun (_) -> + TP = my_spawn_link(PFun), + 1 = erlang:trace(TP, true, [exiting]), + TP + end, + lists:seq(1, NOProcs)), + lists:foreach(fun (TP) -> + receive {KillMe, TP} -> ok end + end, + TPs), + LPs = start_loopers(erlang:system_info(schedulers), + normal, + fun (_) -> + erlang:yield() end, - TPs), - ?line stop_loopers(LPs), - ?line ok. + ok), + lists:foreach(fun (TP) -> + unlink(TP), + exit(TP, bang) + end, + TPs), + lists:foreach(fun (TP) -> + XScheds = count_exit_sched(TP), + io:format("~p XScheds=~p~n", + [TP, XScheds]), + true = XScheds >= 5 + end, + TPs), + stop_loopers(LPs), + ok. - -table_leak(doc) -> - "Make sure that slots for ets tables are cleared properly."; + +%% Make sure that slots for ets tables are cleared properly. table_leak(Config) when is_list(Config) -> repeat_for_opts(fun(Opts) -> table_leak_1(Opts,20000) end). table_leak_1(_,0) -> ok; table_leak_1(Opts,N) -> - ?line T = ets_new(fooflarf, Opts), - ?line true = ets:delete(T), + T = ets_new(fooflarf, Opts), + true = ets:delete(T), table_leak_1(Opts,N-1). -baddelete(doc) -> - ["Check proper return values for illegal delete operations."]; -baddelete(suite) -> []; +%% Check proper return values for illegal delete operations. baddelete(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line {'EXIT',{badarg,_}} = (catch ets:delete(foo)), - ?line Tab = ets_new(foo,[]), - ?line true = ets:delete(Tab), - ?line {'EXIT',{badarg,_}} = (catch ets:delete(Tab)), - ?line verify_etsmem(EtsMem). - -match_delete(doc) -> - ["Check that match_delete works. Also tests tab2list function."]; -match_delete(suite) -> []; + EtsMem = etsmem(), + {'EXIT',{badarg,_}} = (catch ets:delete(foo)), + Tab = ets_new(foo,[]), + true = ets:delete(Tab), + {'EXIT',{badarg,_}} = (catch ets:delete(Tab)), + verify_etsmem(EtsMem). + +%% Check that match_delete works. Also tests tab2list function. match_delete(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), repeat_for_opts(match_delete_do,[write_concurrency,all_types]), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). match_delete_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(kad,Opts), - ?line fill_tab(Tab,foo), - ?line ets:insert(Tab,{{c,key},bar}), - ?line _ = ets:match_delete(Tab,{'_',foo}), - ?line [{{c,key},bar}] = ets:tab2list(Tab), - ?line _ = ets:match_delete(Tab,'_'), - ?line [] = ets:tab2list(Tab), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -match_delete3(doc) -> - ["OTP-3005: check match_delete with constant argument."]; -match_delete3(suite) -> []; + EtsMem = etsmem(), + Tab = ets_new(kad,Opts), + fill_tab(Tab,foo), + ets:insert(Tab,{{c,key},bar}), + _ = ets:match_delete(Tab,{'_',foo}), + [{{c,key},bar}] = ets:tab2list(Tab), + _ = ets:match_delete(Tab,'_'), + [] = ets:tab2list(Tab), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + +%% OTP-3005: check match_delete with constant argument. match_delete3(Config) when is_list(Config) -> repeat_for_opts(match_delete3_do). match_delete3_do(Opts) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), T = make_table(test, [duplicate_bag | Opts], [{aa,17}, @@ -3642,41 +3491,40 @@ match_delete3_do(Opts) -> ets:match_delete(T, {cA,1000}), [] = ets:match_object(T, {'_', 1000}), ets:delete(T), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -firstnext(doc) -> ["Tests ets:first/1 & ets:next/2."]; -firstnext(suite) -> []; +%% Test ets:first/1 & ets:next/2. firstnext(Config) when is_list(Config) -> repeat_for_opts(firstnext_do). firstnext_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(foo,Opts), - ?line [] = firstnext_collect(Tab,ets:first(Tab),[]), - ?line fill_tab(Tab,foo), - ?line Len = length(ets:tab2list(Tab)), - ?line Len = length(firstnext_collect(Tab,ets:first(Tab),[])), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). + EtsMem = etsmem(), + Tab = ets_new(foo,Opts), + [] = firstnext_collect(Tab,ets:first(Tab),[]), + fill_tab(Tab,foo), + Len = length(ets:tab2list(Tab)), + Len = length(firstnext_collect(Tab,ets:first(Tab),[])), + true = ets:delete(Tab), + verify_etsmem(EtsMem). firstnext_collect(_Tab,'$end_of_table',List) -> - ?line List; + List; firstnext_collect(Tab,Key,List) -> - ?line firstnext_collect(Tab,ets:next(Tab,Key),[Key|List]). + firstnext_collect(Tab,ets:next(Tab,Key),[Key|List]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -firstnext_concurrent(doc) -> "Tests ets:first/1 & ets:next/2."; +%% Tests ets:first/1 & ets:next/2. firstnext_concurrent(Config) when is_list(Config) -> register(master, self()), ets_init(?MODULE, 20), [dynamic_go() || _ <- lists:seq(1, 2)], receive - after 5000 -> ok + after 5000 -> ok end. ets_init(Tab, N) -> @@ -3707,98 +3555,94 @@ dyn_lookup(T, K) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -slot(suite) -> []; slot(Config) when is_list(Config) -> repeat_for_opts(slot_do). slot_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(foo,Opts), - ?line fill_tab(Tab,foo), - ?line Elts = ets:info(Tab,size), - ?line Elts = slot_loop(Tab,0,0), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). + EtsMem = etsmem(), + Tab = ets_new(foo,Opts), + fill_tab(Tab,foo), + Elts = ets:info(Tab,size), + Elts = slot_loop(Tab,0,0), + true = ets:delete(Tab), + verify_etsmem(EtsMem). slot_loop(Tab,SlotNo,EltsSoFar) -> - ?line case ets:slot(Tab,SlotNo) of - '$end_of_table' -> - ?line {'EXIT',{badarg,_}} = - (catch ets:slot(Tab,SlotNo+1)), - ?line EltsSoFar; - Elts -> - ?line slot_loop(Tab,SlotNo+1,EltsSoFar+length(Elts)) + case ets:slot(Tab,SlotNo) of + '$end_of_table' -> + {'EXIT',{badarg,_}} = + (catch ets:slot(Tab,SlotNo+1)), + EltsSoFar; + Elts -> + slot_loop(Tab,SlotNo+1,EltsSoFar+length(Elts)) end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -match1(suite) -> []; match1(Config) when is_list(Config) -> repeat_for_opts(match1_do). match1_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(foo,Opts), - ?line fill_tab(Tab,foo), - ?line [] = ets:match(Tab,{}), - ?line ets:insert(Tab,{{one,4},4}), - ?line ets:insert(Tab,{{one,5},5}), - ?line ets:insert(Tab,{{two,4},4}), - ?line ets:insert(Tab,{{two,5},6}), - ?line case ets:match(Tab,{{one,'_'},'$0'}) of - [[4],[5]] -> ok; - [[5],[4]] -> ok - end, - ?line case ets:match(Tab,{{two,'$1'},'$0'}) of - [[4,4],[6,5]] -> ok; - [[6,5],[4,4]] -> ok - end, - ?line case ets:match(Tab,{{two,'$9'},'$4'}) of - [[4,4],[6,5]] -> ok; - [[6,5],[4,4]] -> ok - end, - ?line case ets:match(Tab,{{two,'$9'},'$22'}) of - [[4,4],[5,6]] -> ok; - [[5,6],[4,4]] -> ok - end, - ?line [[4]] = ets:match(Tab,{{two,'$0'},'$0'}), - ?line Len = length(ets:match(Tab,'$0')), - ?line Len = length(ets:match(Tab,'_')), - ?line if Len > 4 -> ok end, - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -match2(doc) -> ["Tests match with specified keypos bag table."]; -match2(suite) -> []; + EtsMem = etsmem(), + Tab = ets_new(foo,Opts), + fill_tab(Tab,foo), + [] = ets:match(Tab,{}), + ets:insert(Tab,{{one,4},4}), + ets:insert(Tab,{{one,5},5}), + ets:insert(Tab,{{two,4},4}), + ets:insert(Tab,{{two,5},6}), + case ets:match(Tab,{{one,'_'},'$0'}) of + [[4],[5]] -> ok; + [[5],[4]] -> ok + end, + case ets:match(Tab,{{two,'$1'},'$0'}) of + [[4,4],[6,5]] -> ok; + [[6,5],[4,4]] -> ok + end, + case ets:match(Tab,{{two,'$9'},'$4'}) of + [[4,4],[6,5]] -> ok; + [[6,5],[4,4]] -> ok + end, + case ets:match(Tab,{{two,'$9'},'$22'}) of + [[4,4],[5,6]] -> ok; + [[5,6],[4,4]] -> ok + end, + [[4]] = ets:match(Tab,{{two,'$0'},'$0'}), + Len = length(ets:match(Tab,'$0')), + Len = length(ets:match(Tab,'_')), + if Len > 4 -> ok end, + true = ets:delete(Tab), + verify_etsmem(EtsMem). + +%% Test match with specified keypos bag table. match2(Config) when is_list(Config) -> repeat_for_opts(match2_do). match2_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = make_table(foobar, - [bag, named_table, {keypos, 2} | Opts], - [{value1, key1}, - {value2_1, key2}, - {value2_2, key2}, - {value3_1, key3}, - {value3_2, key3}, - {value2_1, key2_wannabe}]), - ?line case length(ets:match(Tab, '$1')) of - 6 -> ok; - _ -> ?t:fail("Length of matched list is wrong.") - end, - ?line [[value3_1],[value3_2]] = ets:match(Tab, {'$1', key3}), - ?line [[key1]] = ets:match(Tab, {value1, '$1'}), - ?line [[key2_wannabe],[key2]] = ets:match(Tab, {value2_1, '$2'}), - ?line [] = ets:match(Tab,{'$1',nosuchkey}), - ?line [] = ets:match(Tab,{'$1',kgY2}), % same hash as key2 - ?line [] = ets:match(Tab,{nosuchvalue,'$1'}), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -match_object(doc) -> ["Some ets:match_object test."]; -match_object(suite) -> []; + EtsMem = etsmem(), + Tab = make_table(foobar, + [bag, named_table, {keypos, 2} | Opts], + [{value1, key1}, + {value2_1, key2}, + {value2_2, key2}, + {value3_1, key3}, + {value3_2, key3}, + {value2_1, key2_wannabe}]), + case length(ets:match(Tab, '$1')) of + 6 -> ok; + _ -> ct:fail("Length of matched list is wrong.") + end, + [[value3_1],[value3_2]] = ets:match(Tab, {'$1', key3}), + [[key1]] = ets:match(Tab, {value1, '$1'}), + [[key2_wannabe],[key2]] = ets:match(Tab, {value2_1, '$2'}), + [] = ets:match(Tab,{'$1',nosuchkey}), + [] = ets:match(Tab,{'$1',kgY2}), % same hash as key2 + [] = ets:match(Tab,{nosuchvalue,'$1'}), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + +%% Some ets:match_object tests. match_object(Config) when is_list(Config) -> repeat_for_opts(match_object_do). @@ -3823,25 +3667,25 @@ match_object_do(Opts) -> case ets:match_object(Tab, {{one, '_'}, '$0'}) of [{{one,5},5},{{one,4},4}] -> ok; [{{one,4},4},{{one,5},5}] -> ok; - _ -> ?t:fail("ets:match_object() returned something funny.") + _ -> ct:fail("ets:match_object() returned something funny.") end, case ets:match_object(Tab, {{two, '$1'}, '$0'}) of [{{two,5},6},{{two,4},4}] -> ok; [{{two,4},4},{{two,5},6}] -> ok; - _ -> ?t:fail("ets:match_object() returned something funny.") + _ -> ct:fail("ets:match_object() returned something funny.") end, case ets:match_object(Tab, {{two, '$9'}, '$4'}) of [{{two,5},6},{{two,4},4}] -> ok; [{{two,4},4},{{two,5},6}] -> ok; - _ -> ?t:fail("ets:match_object() returned something funny.") + _ -> ct:fail("ets:match_object() returned something funny.") end, case ets:match_object(Tab, {{two, '$9'}, '$22'}) of [{{two,5},6},{{two,4},4}] -> ok; [{{two,4},4},{{two,5},6}] -> ok; - _ -> ?t:fail("ets:match_object() returned something funny.") + _ -> ct:fail("ets:match_object() returned something funny.") end, - % Check that maps are inspected for variables. + %% Check that maps are inspected for variables. [{#{camembert:=cabécou},7}] = ets:match_object(Tab, {#{camembert=>'_'},7}), [{#{"hi":="hello",#{"wazzup"=>3}:="awesome","1337":="42"},9}] = @@ -3860,13 +3704,13 @@ match_object_do(Opts) -> {#{"1337" := "42","hi" := "hello","wazzup" := #{"awesome" := 3}},10}] -> ok; [{#{"1337" := "42","hi" := "hello","wazzup" := #{"awesome" := 3}},10}, {#{"1337" := "42","hi" := "hello","wazzup" := "awesome"},8}] -> ok; - _ -> ?t:fail("ets:match_object() returned something funny.") + _ -> ct:fail("ets:match_object() returned something funny.") end, case ets:match_object(Tab, {#{"hi"=>'_'},'_'}) of [{#{"1337":="42", "hi":="hello"},_}, {#{"1337":="42", "hi":="hello"},_}, {#{"1337":="42", "hi":="hello"},_}] -> ok; - _ -> ?t:fail("ets:match_object() returned something funny.") + _ -> ct:fail("ets:match_object() returned something funny.") end, %% match large maps @@ -3876,98 +3720,93 @@ match_object_do(Opts) -> %% only match a part of the map [{#{1:=1,5:=5,99:=99,100:=100},11},{#{1:="hi",6:="hi",99:="hi"},12}] -> ok; [{#{1:="hi",2:="hi",59:="hi"},12},{#{1:=1,2:=2,39:=39,100:=100},11}] -> ok; - _ -> ?t:fail("ets:match_object() returned something funny.") + _ -> ct:fail("ets:match_object() returned something funny.") end, case ets:match_object(Tab, {maps:from_list([{I,'_'}||I<-Is]),'_'}) of %% only match a part of the map [{#{1:=1,5:=5,99:=99,100:=100},11},{#{1:="hi",6:="hi",99:="hi"},12}] -> ok; [{#{1:="hi",2:="hi",59:="hi"},12},{#{1:=1,2:=2,39:=39,100:=100},11}] -> ok; - _ -> ?t:fail("ets:match_object() returned something funny.") + _ -> ct:fail("ets:match_object() returned something funny.") end, {'EXIT',{badarg,_}} = (catch ets:match_object(Tab, {#{'$1'=>'_'},7})), Mve = maps:from_list([{list_to_atom([$$|integer_to_list(I)]),'_'}||I<-Is]), {'EXIT',{badarg,_}} = (catch ets:match_object(Tab, {Mve,11})), - % Check that unsuccessful match returns an empty list. + %% Check that unsuccessful match returns an empty list. [] = ets:match_object(Tab, {{three,'$0'}, '$92'}), - % Check that '$0' equals '_'. + %% Check that '$0' equals '_'. Len = length(ets:match_object(Tab, '$0')), Len = length(ets:match_object(Tab, '_')), if Len > 4 -> ok end, true = ets:delete(Tab), verify_etsmem(EtsMem). -match_object2(suite) -> []; -match_object2(doc) -> ["Tests that db_match_object does not generate " - "a `badarg' when resuming a search with no " - "previous matches."]; +%% Tests that db_match_object does not generate a `badarg' when +%% resuming a search with no previous matches. match_object2(Config) when is_list(Config) -> repeat_for_opts(match_object2_do). match_object2_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(foo, [bag, {keypos, 2} | Opts]), - ?line fill_tab2(Tab, 0, 13005), % match_db_object does 1000 - % elements per pass, might - % change in the future. - ?line case catch ets:match_object(Tab, {hej, '$1'}) of - {'EXIT', _} -> - ets:delete(Tab), - ?t:fail("match_object EXIT:ed"); - [] -> - io:format("Nothing matched."); - List -> - io:format("Matched:~p~n",[List]) - end, + EtsMem = etsmem(), + Tab = ets_new(foo, [bag, {keypos, 2} | Opts]), + fill_tab2(Tab, 0, 13005), % match_db_object does 1000 + % elements per pass, might + % change in the future. + case catch ets:match_object(Tab, {hej, '$1'}) of + {'EXIT', _} -> + ets:delete(Tab), + ct:fail("match_object EXIT:ed"); + [] -> + io:format("Nothing matched."); + List -> + io:format("Matched:~p~n",[List]) + end, ets:delete(Tab), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -tab2list(doc) -> ["Tests tab2list (OTP-3319)"]; -tab2list(suite) -> []; +%% OTP-3319. Test tab2list. tab2list(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line Tab = make_table(foo, - [ordered_set], - [{a,b}, {c,b}, {b,b}, {a,c}]), - ?line [{a,c},{b,b},{c,b}] = ets:tab2list(Tab), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -misc1(doc) -> ["Simple general small test. ", - "If this fails, ets is in really bad shape."]; -misc1(suite) -> []; + EtsMem = etsmem(), + Tab = make_table(foo, + [ordered_set], + [{a,b}, {c,b}, {b,b}, {a,c}]), + [{a,c},{b,b},{c,b}] = ets:tab2list(Tab), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + +%% Simple general small test. If this fails, ets is in really bad +%% shape. misc1(Config) when is_list(Config) -> repeat_for_opts(misc1_do). misc1_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(foo,Opts), - ?line true = lists:member(Tab,ets:all()), - ?line ets:delete(Tab), - ?line false = lists:member(Tab,ets:all()), - ?line case catch ets:delete(Tab) of - {'EXIT',_Reason} -> - ?line verify_etsmem(EtsMem); - true -> - ?t:fail("Delete of nonexisting table returned `true'.") - end, + EtsMem = etsmem(), + Tab = ets_new(foo,Opts), + true = lists:member(Tab,ets:all()), + ets:delete(Tab), + false = lists:member(Tab,ets:all()), + case catch ets:delete(Tab) of + {'EXIT',_Reason} -> + verify_etsmem(EtsMem); + true -> + ct:fail("Delete of nonexisting table returned `true'.") + end, ok. -safe_fixtable(doc) -> ["Check the safe_fixtable function."]; -safe_fixtable(suite) -> []; +%% Check the safe_fixtable function. safe_fixtable(Config) when is_list(Config) -> repeat_for_opts(safe_fixtable_do). safe_fixtable_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(foo, Opts), - ?line fill_tab(Tab, foobar), - ?line true = ets:safe_fixtable(Tab, true), - ?line receive after 1 -> ok end, - ?line true = ets:safe_fixtable(Tab, false), + EtsMem = etsmem(), + Tab = ets_new(foo, Opts), + fill_tab(Tab, foobar), + true = ets:safe_fixtable(Tab, true), + receive after 1 -> ok end, + true = ets:safe_fixtable(Tab, false), false = ets:info(Tab,safe_fixed_monotonic_time), false = ets:info(Tab,safe_fixed), SysBefore = erlang:timestamp(), @@ -4000,90 +3839,86 @@ safe_fixtable_do(Opts) -> {FixMonTime,[{Self,1}]} = ets:info(Tab,safe_fixed_monotonic_time), {FixSysTime,[{Self,1}]} = ets:info(Tab,safe_fixed), %% badarg's - ?line {'EXIT', {badarg, _}} = (catch ets:safe_fixtable(Tab, foobar)), - ?line true = ets:info(Tab,fixed), - ?line true = ets:safe_fixtable(Tab, false), - ?line false = ets:info(Tab,fixed), - ?line {'EXIT', {badarg, _}} = (catch ets:safe_fixtable(Tab, foobar)), - ?line false = ets:info(Tab,fixed), - ?line ets:delete(Tab), - ?line case catch ets:safe_fixtable(Tab, true) of - {'EXIT', _Reason} -> - ?line verify_etsmem(EtsMem); - _ -> - ?t:fail("Fixtable on nonexisting table returned `true'") - end, + {'EXIT', {badarg, _}} = (catch ets:safe_fixtable(Tab, foobar)), + true = ets:info(Tab,fixed), + true = ets:safe_fixtable(Tab, false), + false = ets:info(Tab,fixed), + {'EXIT', {badarg, _}} = (catch ets:safe_fixtable(Tab, foobar)), + false = ets:info(Tab,fixed), + ets:delete(Tab), + case catch ets:safe_fixtable(Tab, true) of + {'EXIT', _Reason} -> + verify_etsmem(EtsMem); + _ -> + ct:fail("Fixtable on nonexisting table returned `true'") + end, ok. -info(doc) -> ["Tests ets:info result for required tuples."]; -info(suite) -> []; +%% Tests ets:info result for required tuples. info(Config) when is_list(Config) -> repeat_for_opts(info_do). info_do(Opts) -> - ?line EtsMem = etsmem(), - ?line MeMyselfI=self(), - ?line ThisNode=node(), - ?line Tab = ets_new(foobar, [{keypos, 2} | Opts]), + EtsMem = etsmem(), + MeMyselfI=self(), + ThisNode=node(), + Tab = ets_new(foobar, [{keypos, 2} | Opts]), %% Note: ets:info/1 used to return a tuple, but from R11B onwards it %% returns a list. - ?line Res = ets:info(Tab), - ?line {value, {memory, _Mem}} = lists:keysearch(memory, 1, Res), - ?line {value, {owner, MeMyselfI}} = lists:keysearch(owner, 1, Res), - ?line {value, {name, foobar}} = lists:keysearch(name, 1, Res), - ?line {value, {size, 0}} = lists:keysearch(size, 1, Res), - ?line {value, {node, ThisNode}} = lists:keysearch(node, 1, Res), - ?line {value, {named_table, false}} = lists:keysearch(named_table, 1, Res), - ?line {value, {type, set}} = lists:keysearch(type, 1, Res), - ?line {value, {keypos, 2}} = lists:keysearch(keypos, 1, Res), - ?line {value, {protection, protected}} = + Res = ets:info(Tab), + {value, {memory, _Mem}} = lists:keysearch(memory, 1, Res), + {value, {owner, MeMyselfI}} = lists:keysearch(owner, 1, Res), + {value, {name, foobar}} = lists:keysearch(name, 1, Res), + {value, {size, 0}} = lists:keysearch(size, 1, Res), + {value, {node, ThisNode}} = lists:keysearch(node, 1, Res), + {value, {named_table, false}} = lists:keysearch(named_table, 1, Res), + {value, {type, set}} = lists:keysearch(type, 1, Res), + {value, {keypos, 2}} = lists:keysearch(keypos, 1, Res), + {value, {protection, protected}} = lists:keysearch(protection, 1, Res), - ?line true = ets:delete(Tab), - ?line undefined = ets:info(non_existing_table_xxyy), - ?line undefined = ets:info(non_existing_table_xxyy,type), - ?line undefined = ets:info(non_existing_table_xxyy,node), - ?line undefined = ets:info(non_existing_table_xxyy,named_table), - ?line undefined = ets:info(non_existing_table_xxyy,safe_fixed_monotonic_time), - ?line undefined = ets:info(non_existing_table_xxyy,safe_fixed), - ?line verify_etsmem(EtsMem). - -dups(doc) -> ["Test various duplicate_bags stuff"]; -dups(suite) -> []; + true = ets:delete(Tab), + undefined = ets:info(non_existing_table_xxyy), + undefined = ets:info(non_existing_table_xxyy,type), + undefined = ets:info(non_existing_table_xxyy,node), + undefined = ets:info(non_existing_table_xxyy,named_table), + undefined = ets:info(non_existing_table_xxyy,safe_fixed_monotonic_time), + undefined = ets:info(non_existing_table_xxyy,safe_fixed), + verify_etsmem(EtsMem). + +%% Test various duplicate_bags stuff. dups(Config) when is_list(Config) -> repeat_for_opts(dups_do). dups_do(Opts) -> - ?line EtsMem = etsmem(), - ?line T = make_table(funky, - [duplicate_bag | Opts], - [{1, 2}, {1, 2}]), - ?line 2 = length(ets:tab2list(T)), - ?line ets:delete(T, 1), - ?line [] = ets:lookup(T, 1), - - ?line ets:insert(T, {1, 2, 2}), - ?line ets:insert(T, {1, 2, 4}), - ?line ets:insert(T, {1, 2, 2}), - ?line ets:insert(T, {1, 2, 2}), - ?line ets:insert(T, {1, 2, 4}), - - ?line 5 = length(ets:tab2list(T)), - - ?line 5 = length(ets:match(T, {'$1', 2, '$2'})), - ?line 3 = length(ets:match(T, {'_', '$1', '$1'})), - ?line ets:match_delete(T, {'_', '$1', '$1'}), - ?line 0 = length(ets:match(T, {'_', '$1', '$1'})), - ?line ets:delete(T), - ?line verify_etsmem(EtsMem). + EtsMem = etsmem(), + T = make_table(funky, + [duplicate_bag | Opts], + [{1, 2}, {1, 2}]), + 2 = length(ets:tab2list(T)), + ets:delete(T, 1), + [] = ets:lookup(T, 1), + + ets:insert(T, {1, 2, 2}), + ets:insert(T, {1, 2, 4}), + ets:insert(T, {1, 2, 2}), + ets:insert(T, {1, 2, 2}), + ets:insert(T, {1, 2, 4}), + + 5 = length(ets:tab2list(T)), + + 5 = length(ets:match(T, {'$1', 2, '$2'})), + 3 = length(ets:match(T, {'_', '$1', '$1'})), + ets:match_delete(T, {'_', '$1', '$1'}), + 0 = length(ets:match(T, {'_', '$1', '$1'})), + ets:delete(T), + verify_etsmem(EtsMem). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -tab2file(doc) -> ["Check the ets:tab2file function on an empty " - "ets table."]; -tab2file(suite) -> []; +%% Test the ets:tab2file function on an empty ets table. tab2file(Config) when is_list(Config) -> - ?line FName = filename:join([?config(priv_dir, Config),"tab2file_case"]), + FName = filename:join([proplists:get_value(priv_dir, Config),"tab2file_case"]), tab2file_do(FName, []), tab2file_do(FName, [{sync,true}]), tab2file_do(FName, [{sync,false}]), @@ -4093,62 +3928,60 @@ tab2file(Config) when is_list(Config) -> tab2file_do(FName, Opts) -> %% Write an empty ets table to a file, read back and check properties. - ?line Tab = ets_new(ets_SUITE_foo_tab, [named_table, set, public, - {keypos, 2}, - compressed, - {write_concurrency,true}, - {read_concurrency,true}]), + Tab = ets_new(ets_SUITE_foo_tab, [named_table, set, public, + {keypos, 2}, + compressed, + {write_concurrency,true}, + {read_concurrency,true}]), catch file:delete(FName), Res = ets:tab2file(Tab, FName, Opts), true = ets:delete(Tab), ok = Res, - % - ?line EtsMem = etsmem(), - ?line {ok, Tab2} = ets:file2tab(FName), + %% + EtsMem = etsmem(), + {ok, Tab2} = ets:file2tab(FName), public = ets:info(Tab2, protection), - ?line true = ets:info(Tab2, named_table), - ?line 2 = ets:info(Tab2, keypos), - ?line set = ets:info(Tab2, type), + true = ets:info(Tab2, named_table), + 2 = ets:info(Tab2, keypos), + set = ets:info(Tab2, type), true = ets:info(Tab2, compressed), Smp = erlang:system_info(smp_support), Smp = ets:info(Tab2, read_concurrency), Smp = ets:info(Tab2, write_concurrency), - ?line true = ets:delete(Tab2), - ?line verify_etsmem(EtsMem). + true = ets:delete(Tab2), + verify_etsmem(EtsMem). + - -tab2file2(doc) -> ["Check the ets:tab2file function on a ", - "filled set/bag type ets table."]; -tab2file2(suite) -> []; +%% Check the ets:tab2file function on a filled set/bag type ets table. tab2file2(Config) when is_list(Config) -> repeat_for_opts({tab2file2_do,Config}, [[set,bag],compressed]). tab2file2_do(Opts, Config) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(ets_SUITE_foo_tab, [named_table, private, - {keypos, 2} | Opts]), - ?line FName = filename:join([?config(priv_dir, Config),"tab2file2_case"]), - ?line ok = fill_tab2(Tab, 0, 10000), % Fill up the table (grucho mucho!) - ?line Len = length(ets:tab2list(Tab)), - ?line Mem = ets:info(Tab, memory), - ?line Type = ets:info(Tab, type), + EtsMem = etsmem(), + Tab = ets_new(ets_SUITE_foo_tab, [named_table, private, + {keypos, 2} | Opts]), + FName = filename:join([proplists:get_value(priv_dir, Config),"tab2file2_case"]), + ok = fill_tab2(Tab, 0, 10000), % Fill up the table (grucho mucho!) + Len = length(ets:tab2list(Tab)), + Mem = ets:info(Tab, memory), + Type = ets:info(Tab, type), %%io:format("org tab: ~p\n",[ets:info(Tab)]), - ?line ok = ets:tab2file(Tab, FName), - ?line true = ets:delete(Tab), + ok = ets:tab2file(Tab, FName), + true = ets:delete(Tab), - ?line EtsMem4 = etsmem(), + EtsMem4 = etsmem(), - ?line {ok, Tab2} = ets:file2tab(FName), + {ok, Tab2} = ets:file2tab(FName), %%io:format("loaded tab: ~p\n",[ets:info(Tab2)]), - ?line private = ets:info(Tab2, protection), - ?line true = ets:info(Tab2, named_table), - ?line 2 = ets:info(Tab2, keypos), - ?line Type = ets:info(Tab2, type), - ?line Len = length(ets:tab2list(Tab2)), - ?line Mem = ets:info(Tab2, memory), - ?line true = ets:delete(Tab2), + private = ets:info(Tab2, protection), + true = ets:info(Tab2, named_table), + 2 = ets:info(Tab2, keypos), + Type = ets:info(Tab2, type), + Len = length(ets:tab2list(Tab2)), + Mem = ets:info(Tab2, memory), + true = ets:delete(Tab2), io:format("Between = ~p\n", [EtsMem4]), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). -define(test_list, [8,5,4,1,58,125,255, 250, 245, 240, 235, 230, Num rem 255, 255, 125, 130, 135, 140, 145, @@ -4163,33 +3996,30 @@ tab2file2_do(Opts, Config) -> fill_tab2(_Tab, _Val, 0) -> ok; fill_tab2(Tab, Val, Num) -> - ?line Item = + Item = case Num rem 10 of 0 -> "String"; - 1 -> ?line ?test_atom; - 2 -> ?line ?test_tuple; - 3 -> ?line ?test_integer; - 4 -> ?line ?test_float; - 5 -> ?line list_to_binary(?test_list); %Heap binary - 6 -> ?line list_to_binary(?big_test_list); %Refc binary - 7 -> ?line make_sub_binary(?test_list, Num); %Sub binary - 8 -> ?line ?test_list; - 9 -> ?line fun(X) -> {Tab,Val,X*Num} end + 1 -> ?test_atom; + 2 -> ?test_tuple; + 3 -> ?test_integer; + 4 -> ?test_float; + 5 -> list_to_binary(?test_list); %Heap binary + 6 -> list_to_binary(?big_test_list); %Refc binary + 7 -> make_sub_binary(?test_list, Num); %Sub binary + 8 -> ?test_list; + 9 -> fun(X) -> {Tab,Val,X*Num} end end, - ?line true=ets:insert(Tab, {Item, Val}), - ?line fill_tab2(Tab, Val+1, Num-1), + true=ets:insert(Tab, {Item, Val}), + fill_tab2(Tab, Val+1, Num-1), ok. -tabfile_ext1(suite) -> - []; -tabfile_ext1(doc) -> - ["Tests verification of tables with object count extended_info"]; +%% Test verification of tables with object count extended_info. tabfile_ext1(Config) when is_list(Config) -> repeat_for_opts(fun(Opts) -> tabfile_ext1_do(Opts, Config) end). tabfile_ext1_do(Opts,Config) -> - ?line FName = filename:join([?config(priv_dir, Config),"nisse.dat"]), - ?line FName2 = filename:join([?config(priv_dir, Config),"countflip.dat"]), + FName = filename:join([proplists:get_value(priv_dir, Config),"nisse.dat"]), + FName2 = filename:join([proplists:get_value(priv_dir, Config),"countflip.dat"]), L = lists:seq(1,10), T = ets_new(x,Opts), Name = make_ref(), @@ -4220,16 +4050,14 @@ tabfile_ext1_do(Opts,Config) -> file:delete(FName2), ok. -tabfile_ext2(suite) -> - []; -tabfile_ext2(doc) -> - ["Tests verification of tables with md5sum extended_info"]; + +%% Test verification of tables with md5sum extended_info. tabfile_ext2(Config) when is_list(Config) -> repeat_for_opts(fun(Opts) -> tabfile_ext2_do(Opts,Config) end). tabfile_ext2_do(Opts,Config) -> - ?line FName = filename:join([?config(priv_dir, Config),"olle.dat"]), - ?line FName2 = filename:join([?config(priv_dir, Config),"bitflip.dat"]), + FName = filename:join([proplists:get_value(priv_dir, Config),"olle.dat"]), + FName2 = filename:join([proplists:get_value(priv_dir, Config),"bitflip.dat"]), L = lists:seq(1,10), T = ets_new(x,Opts), Name = make_ref(), @@ -4260,13 +4088,10 @@ tabfile_ext2_do(Opts,Config) -> file:delete(FName2), ok. -tabfile_ext3(suite) -> - []; -tabfile_ext3(doc) -> - ["Tests verification of (named) tables without extended info"]; +%% Test verification of (named) tables without extended info. tabfile_ext3(Config) when is_list(Config) -> - ?line FName = filename:join([?config(priv_dir, Config),"namn.dat"]), - ?line FName2 = filename:join([?config(priv_dir, Config),"ncountflip.dat"]), + FName = filename:join([proplists:get_value(priv_dir, Config),"namn.dat"]), + FName2 = filename:join([proplists:get_value(priv_dir, Config),"ncountflip.dat"]), L = lists:seq(1,10), Name = make_ref(), ?MODULE = ets_new(?MODULE,[named_table]), @@ -4294,12 +4119,9 @@ tabfile_ext3(Config) when is_list(Config) -> file:delete(FName2), ok. -tabfile_ext4(suite) -> - []; -tabfile_ext4(doc) -> - ["Tests verification of large table with md5 sum"]; +%% Tests verification of large table with md5 sum. tabfile_ext4(Config) when is_list(Config) -> - ?line FName = filename:join([?config(priv_dir, Config),"bauta.dat"]), + FName = filename:join([proplists:get_value(priv_dir, Config),"bauta.dat"]), LL = lists:seq(1,10000), TL = ets_new(x,[]), Name2 = make_ref(), @@ -4336,12 +4158,9 @@ tabfile_ext4(Config) when is_list(Config) -> file:delete(FName), ok. -badfile(suite) -> - []; -badfile(doc) -> - ["Tests that no disk_log is left open when file has been corrupted"]; +%% Test that no disk_log is left open when file has been corrupted. badfile(Config) when is_list(Config) -> - PrivDir = ?config(priv_dir,Config), + PrivDir = proplists:get_value(priv_dir,Config), File = filename:join(PrivDir, "badfile"), _ = file:delete(File), T = ets:new(table, []), @@ -4397,32 +4216,31 @@ make_sub_binary(List, Num) when is_list(List) -> %% Lookup stuff like crazy... -heavy_lookup(doc) -> ["Performs multiple lookups for every key ", - "in a large table."]; -heavy_lookup(suite) -> []; + +%% Perform multiple lookups for every key in a large table. heavy_lookup(Config) when is_list(Config) -> repeat_for_opts(heavy_lookup_do). heavy_lookup_do(Opts) -> - ?line EtsMem = etsmem(), - ?line Tab = ets_new(foobar_table, [set, protected, {keypos, 2} | Opts]), - ?line ok = fill_tab2(Tab, 0, 7000), - ?line ?t:do_times(50, ?MODULE, do_lookup, [Tab, 6999]), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). + EtsMem = etsmem(), + Tab = ets_new(foobar_table, [set, protected, {keypos, 2} | Opts]), + ok = fill_tab2(Tab, 0, 7000), + _ = [do_lookup(Tab, 6999) || _ <- lists:seq(1, 50)], + true = ets:delete(Tab), + verify_etsmem(EtsMem). do_lookup(_Tab, 0) -> ok; do_lookup(Tab, N) -> case ets:lookup(Tab, N) of - [] -> ?t:format("Set #~p was reported as empty. Not valid.", - [N]), - exit('Invalid lookup'); - _ -> do_lookup(Tab, N-1) + [] -> + io:format("Set #~p was reported as empty. Not valid.", + [N]), + exit('Invalid lookup'); + _ -> + do_lookup(Tab, N-1) end. -heavy_lookup_element(doc) -> ["Performs multiple lookups for ", - "every element in a large table."]; -heavy_lookup_element(suite) -> []; +%% Perform multiple lookups for every element in a large table. heavy_lookup_element(Config) when is_list(Config) -> repeat_for_opts(heavy_lookup_element_do). @@ -4430,22 +4248,22 @@ heavy_lookup_element_do(Opts) -> EtsMem = etsmem(), Tab = ets_new(foobar_table, [set, protected, {keypos, 2} | Opts]), ok = fill_tab2(Tab, 0, 7000), - % lookup ALL elements 50 times - ?t:do_times(50, ?MODULE, do_lookup_element, [Tab, 6999, 1]), + %% lookup ALL elements 50 times + _ = [do_lookup_element(Tab, 6999, 1) || _ <- lists:seq(1, 50)], true = ets:delete(Tab), verify_etsmem(EtsMem). do_lookup_element(_Tab, 0, _) -> ok; do_lookup_element(Tab, N, M) -> - ?line case catch ets:lookup_element(Tab, N, M) of - {'EXIT', {badarg, _}} -> - case M of - 1 -> ?t:fail("Set #~p reported as empty. Not valid.", - [N]), - exit('Invalid lookup_element'); - _ -> ?line do_lookup_element(Tab, N-1, 1) - end; - _ -> ?line do_lookup_element(Tab, N, M+1) + case catch ets:lookup_element(Tab, N, M) of + {'EXIT', {badarg, _}} -> + case M of + 1 -> ct:fail("Set #~p reported as empty. Not valid.", + [N]), + exit('Invalid lookup_element'); + _ -> do_lookup_element(Tab, N-1, 1) + end; + _ -> do_lookup_element(Tab, N, M+1) end. @@ -4453,28 +4271,28 @@ heavy_concurrent(Config) when is_list(Config) -> repeat_for_opts(do_heavy_concurrent). do_heavy_concurrent(Opts) -> - ?line Size = 10000, - ?line EtsMem = etsmem(), - ?line Tab = ets_new(blupp, [set, public, {keypos, 2} | Opts]), - ?line ok = fill_tab2(Tab, 0, Size), - ?line Procs = lists:map( - fun (N) -> - my_spawn_link( - fun () -> - do_heavy_concurrent_proc(Tab, Size, N) - end) - end, - lists:seq(1, 500)), - ?line lists:foreach(fun (P) -> - M = erlang:monitor(process, P), - receive - {'DOWN', M, process, P, _} -> - ok - end - end, - Procs), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). + Size = 10000, + EtsMem = etsmem(), + Tab = ets_new(blupp, [set, public, {keypos, 2} | Opts]), + ok = fill_tab2(Tab, 0, Size), + Procs = lists:map( + fun (N) -> + my_spawn_link( + fun () -> + do_heavy_concurrent_proc(Tab, Size, N) + end) + end, + lists:seq(1, 500)), + lists:foreach(fun (P) -> + M = erlang:monitor(process, P), + receive + {'DOWN', M, process, P, _} -> + ok + end + end, + Procs), + true = ets:delete(Tab), + verify_etsmem(EtsMem). do_heavy_concurrent_proc(_Tab, 0, _Offs) -> done; @@ -4488,96 +4306,78 @@ do_heavy_concurrent_proc(Tab, N, Offs) -> do_heavy_concurrent_proc(Tab, N-1, Offs). -fold_empty(doc) -> - []; -fold_empty(suite) -> []; fold_empty(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line Tab = make_table(a, [], []), - ?line [] = ets:foldl(fun(_X) -> exit(hej) end, [], Tab), - ?line [] = ets:foldr(fun(_X) -> exit(hej) end, [], Tab), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -foldl(doc) -> - []; -foldl(suite) -> []; + EtsMem = etsmem(), + Tab = make_table(a, [], []), + [] = ets:foldl(fun(_X) -> exit(hej) end, [], Tab), + [] = ets:foldr(fun(_X) -> exit(hej) end, [], Tab), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + foldl(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line L = [{a,1}, {c,3}, {b,2}], - ?line LS = lists:sort(L), - ?line Tab = make_table(a, [bag], L), - ?line LS = lists:sort(ets:foldl(fun(E,A) -> [E|A] end, [], Tab)), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -foldr(doc) -> - []; -foldr(suite) -> []; + EtsMem = etsmem(), + L = [{a,1}, {c,3}, {b,2}], + LS = lists:sort(L), + Tab = make_table(a, [bag], L), + LS = lists:sort(ets:foldl(fun(E,A) -> [E|A] end, [], Tab)), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + foldr(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line L = [{a,1}, {c,3}, {b,2}], - ?line LS = lists:sort(L), - ?line Tab = make_table(a, [bag], L), - ?line LS = lists:sort(ets:foldr(fun(E,A) -> [E|A] end, [], Tab)), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -foldl_ordered(doc) -> - []; -foldl_ordered(suite) -> []; + EtsMem = etsmem(), + L = [{a,1}, {c,3}, {b,2}], + LS = lists:sort(L), + Tab = make_table(a, [bag], L), + LS = lists:sort(ets:foldr(fun(E,A) -> [E|A] end, [], Tab)), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + foldl_ordered(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line L = [{a,1}, {c,3}, {b,2}], - ?line LS = lists:sort(L), - ?line Tab = make_table(a, [ordered_set], L), - ?line LS = lists:reverse(ets:foldl(fun(E,A) -> [E|A] end, [], Tab)), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -foldr_ordered(doc) -> - []; -foldr_ordered(suite) -> []; + EtsMem = etsmem(), + L = [{a,1}, {c,3}, {b,2}], + LS = lists:sort(L), + Tab = make_table(a, [ordered_set], L), + LS = lists:reverse(ets:foldl(fun(E,A) -> [E|A] end, [], Tab)), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + foldr_ordered(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), - ?line L = [{a,1}, {c,3}, {b,2}], - ?line LS = lists:sort(L), - ?line Tab = make_table(a, [ordered_set], L), - ?line LS = ets:foldr(fun(E,A) -> [E|A] end, [], Tab), - ?line true = ets:delete(Tab), - ?line verify_etsmem(EtsMem). - -member(suite) -> - []; -member(doc) -> - ["Tests ets:member BIF"]; + EtsMem = etsmem(), + L = [{a,1}, {c,3}, {b,2}], + LS = lists:sort(L), + Tab = make_table(a, [ordered_set], L), + LS = ets:foldr(fun(E,A) -> [E|A] end, [], Tab), + true = ets:delete(Tab), + verify_etsmem(EtsMem). + +%% Test ets:member BIF. member(Config) when is_list(Config) -> repeat_for_opts(member_do, [write_concurrency, all_types]). member_do(Opts) -> - ?line EtsMem = etsmem(), - ?line T = ets_new(xxx, Opts), - ?line false = ets:member(T,hej), - ?line E = fun(0,_F)->ok; - (N,F) -> - ?line ets:insert(T,{N,N rem 10}), - F(N-1,F) - end, - ?line E(10000,E), - ?line false = ets:member(T,hej), - ?line true = ets:member(T,1), - ?line false = ets:member(T,20000), - ?line ets:delete(T,5), - ?line false = ets:member(T,5), - ?line ets:safe_fixtable(T,true), - ?line ets:delete(T,6), - ?line false = ets:member(T,6), - ?line ets:safe_fixtable(T,false), - ?line false = ets:member(T,6), - ?line ets:delete(T), - ?line {'EXIT',{badarg,_}} = (catch ets:member(finnsinte, 23)), - ?line {'EXIT',{badarg,_}} = (catch ets:member(T, 23)), - ?line verify_etsmem(EtsMem). + EtsMem = etsmem(), + T = ets_new(xxx, Opts), + false = ets:member(T,hej), + E = fun(0,_F)->ok; + (N,F) -> + ets:insert(T,{N,N rem 10}), + F(N-1,F) + end, + E(10000,E), + false = ets:member(T,hej), + true = ets:member(T,1), + false = ets:member(T,20000), + ets:delete(T,5), + false = ets:member(T,5), + ets:safe_fixtable(T,true), + ets:delete(T,6), + false = ets:member(T,6), + ets:safe_fixtable(T,false), + false = ets:member(T,6), + ets:delete(T), + {'EXIT',{badarg,_}} = (catch ets:member(finnsinte, 23)), + {'EXIT',{badarg,_}} = (catch ets:member(T, 23)), + verify_etsmem(EtsMem). build_table(L1,L2,Num) -> @@ -4664,10 +4464,10 @@ create_random_string(0) -> create_random_string(OfLength) -> C = case rand:uniform(2) of - 1 -> - (rand:uniform($Z - $A + 1) - 1) + $A; - _ -> - (rand:uniform($z - $a + 1) - 1) + $a + 1 -> + (rand:uniform($Z - $A + 1) - 1) + $A; + _ -> + (rand:uniform($z - $a + 1) - 1) + $a end, [C | create_random_string(OfLength - 1)]. @@ -4680,9 +4480,9 @@ create_random_tuple(OfLength) -> create_partly_bound_tuple(OfLength) -> case rand:uniform(2) of 1 -> - create_partly_bound_tuple1(OfLength); + create_partly_bound_tuple1(OfLength); _ -> - create_partly_bound_tuple3(OfLength) + create_partly_bound_tuple3(OfLength) end. create_partly_bound_tuple1(OfLength) -> @@ -4757,7 +4557,7 @@ xfilltabint(Tab,N) -> _ -> filltabint(Tab,N) end. - + filltabstr(Tab,N) -> filltabstr(Tab,0,N). @@ -4928,7 +4728,7 @@ successive_delete(Table,From,To,Type,TType) -> end, case TType of X when X == bag; X == duplicate_bag -> - %erlang:display(From), + %%erlang:display(From), case From rem 2 of 0 -> 2 = ets:select_delete(Table,MS); @@ -4947,19 +4747,19 @@ successive_delete(Table,From,To,Type,TType) -> successive_delete(Table, Next, To, Type,TType). gen_dets_filename(Config,N) -> - filename:join(?config(priv_dir,Config), + filename:join(proplists:get_value(priv_dir,Config), "testdets_" ++ integer_to_list(N) ++ ".dets"). otp_6842_select_1000(Config) when is_list(Config) -> - ?line Tab = ets_new(xxx,[ordered_set]), - ?line [ets:insert(Tab,{X,X}) || X <- lists:seq(1,10000)], - ?line AllTrue = lists:duplicate(10,true), - ?line AllTrue = + Tab = ets_new(xxx,[ordered_set]), + [ets:insert(Tab,{X,X}) || X <- lists:seq(1,10000)], + AllTrue = lists:duplicate(10,true), + AllTrue = [ length( element(1, ets:select(Tab,[{'_',[],['$_']}],X*1000))) =:= - X*1000 || X <- lists:seq(1,10) ], - ?line Sequences = [[1000,1000,1000,1000,1000,1000,1000,1000,1000,1000], + X*1000 || X <- lists:seq(1,10) ], + Sequences = [[1000,1000,1000,1000,1000,1000,1000,1000,1000,1000], [2000,2000,2000,2000,2000], [3000,3000,3000,1000], [4000,4000,2000], @@ -4969,9 +4769,9 @@ otp_6842_select_1000(Config) when is_list(Config) -> [8000,2000], [9000,1000], [10000]], - ?line AllTrue = [ check_seq(Tab, ets:select(Tab,[{'_',[],['$_']}],hd(L)),L) || + AllTrue = [ check_seq(Tab, ets:select(Tab,[{'_',[],['$_']}],hd(L)),L) || L <- Sequences ], - ?line ets:delete(Tab), + ets:delete(Tab), ok. check_seq(_,'$end_of_table',[]) -> @@ -5005,7 +4805,7 @@ w(_,0, _) -> ok; w(T,N, Id) -> ets:insert(T, {N, Id}), w(T,N-1,Id). - + verify(T, Ids) -> List = my_tab_to_list(T), Errors = lists:filter(fun(Bucket) -> @@ -5016,7 +4816,7 @@ verify(T, Ids) -> ok; _ -> io:format("Failed:\n~p\n", [Errors]), - ?t:fail() + ct:fail(failed) end. verify2([{_N,Id}|RL], [Id|R]) -> @@ -5025,8 +4825,7 @@ verify2([],[]) -> false; verify2(_Err, _) -> true. -otp_7665(doc) -> ["delete_object followed by delete on fixed bag failed to delete objects."]; -otp_7665(suite) -> []; +%% delete_object followed by delete on fixed bag failed to delete objects. otp_7665(Config) when is_list(Config) -> repeat_for_opts(otp_7665_do). @@ -5036,30 +4835,30 @@ otp_7665_do(Opts) -> Max = 10, lists:foreach(fun(N)-> otp_7665_act(Tab,Min,Max,N) end, lists:seq(Min,Max)), - ?line true = ets:delete(Tab). - + true = ets:delete(Tab). + otp_7665_act(Tab,Min,Max,DelNr) -> List1 = [{key,N} || N <- lists:seq(Min,Max)], - ?line true = ets:insert(Tab, List1), - ?line true = ets:safe_fixtable(Tab, true), - ?line true = ets:delete_object(Tab, {key,DelNr}), + true = ets:insert(Tab, List1), + true = ets:safe_fixtable(Tab, true), + true = ets:delete_object(Tab, {key,DelNr}), List2 = lists:delete({key,DelNr}, List1), %% Now verify that we find all remaining objects - ?line List2 = ets:lookup(Tab,key), - ?line EList2 = lists:map(fun({key,N})-> N end, - List2), - ?line EList2 = ets:lookup_element(Tab,key,2), - ?line true = ets:delete(Tab, key), - ?line [] = ets:lookup(Tab, key), - ?line true = ets:safe_fixtable(Tab, false), + List2 = ets:lookup(Tab,key), + EList2 = lists:map(fun({key,N})-> N end, + List2), + EList2 = ets:lookup_element(Tab,key,2), + true = ets:delete(Tab, key), + [] = ets:lookup(Tab, key), + true = ets:safe_fixtable(Tab, false), ok. %% Whitebox testing of meta name table hashing. meta_wb(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), repeat_for_opts(meta_wb_do), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). meta_wb_do(Opts) -> @@ -5072,7 +4871,7 @@ meta_wb_do(Opts) -> Len = length(Names), OpFuns = {fun meta_wb_new/4, fun meta_wb_delete/4, fun meta_wb_rename/4}, - ?line true = (Len >= 3), + true = (Len >= 3), io:format("Colliding names = ~p\n",[Names]), F = fun(0,_,_) -> ok; @@ -5085,41 +4884,41 @@ meta_wb_do(Opts) -> end, F(Len*100, [], F), - % cleanup + %% cleanup lists:foreach(fun(Name)->catch ets:delete(Name) end, Names). - + meta_wb_new(Name, _, Tabs, Opts) -> case (catch ets_new(Name,[named_table|Opts])) of Name -> - ?line false = lists:member(Name, Tabs), + false = lists:member(Name, Tabs), [Name | Tabs]; {'EXIT',{badarg,_}} -> - ?line true = lists:member(Name, Tabs), + true = lists:member(Name, Tabs), Tabs end. meta_wb_delete(Name, _, Tabs, _) -> case (catch ets:delete(Name)) of true -> - ?line true = lists:member(Name, Tabs), + true = lists:member(Name, Tabs), lists:delete(Name, Tabs); {'EXIT',{badarg,_}} -> - ?line false = lists:member(Name, Tabs), + false = lists:member(Name, Tabs), Tabs end. meta_wb_rename(Old, New, Tabs, _) -> case (catch ets:rename(Old,New)) of New -> - ?line true = lists:member(Old, Tabs) + true = lists:member(Old, Tabs) andalso not lists:member(New, Tabs), [New | lists:delete(Old, Tabs)]; {'EXIT',{badarg,_}} -> - ?line true = not lists:member(Old, Tabs) + true = not lists:member(Old, Tabs) orelse lists:member(New,Tabs), Tabs end. - - + + colliding_names(Name) -> erts_debug:set_internal_state(colliding_names, {Name,5}). @@ -5127,17 +4926,13 @@ colliding_names(Name) -> %% OTP_6913: Grow and shrink. grow_shrink(Config) when is_list(Config) -> - ?line EtsMem = etsmem(), + EtsMem = etsmem(), Set = ets_new(a, [set]), grow_shrink_0(0, 3071, 3000, 5000, Set), ets:delete(Set), - %OrdSet = ets_new(a, [ordered_set]), - %grow_shrink_0(0, lists:seq(3071, 5000), OrdSet), - %ets:delete(OrdSet), - - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). grow_shrink_0(N, _, _, Max, _) when N >= Max -> ok; @@ -5150,21 +4945,18 @@ grow_shrink_1(N0, GrowN, ShrinkN, T) -> grow_shrink_3(N1, N1 - ShrinkN, T). grow_shrink_2(N, GrowTo, _) when N > GrowTo -> - %io:format("Grown to ~p\n", [GrowTo]), GrowTo; grow_shrink_2(N, GrowTo, T) -> true = ets:insert(T, {N,a}), grow_shrink_2(N+1, GrowTo, T). grow_shrink_3(N, ShrinkTo, _) when N =< ShrinkTo -> - %io:format("Shrunk to ~p\n", [ShrinkTo]), ShrinkTo; grow_shrink_3(N, ShrinkTo, T) -> true = ets:delete(T, N), grow_shrink_3(N-1, ShrinkTo, T). - -grow_pseudo_deleted(doc) -> ["Grow a table that still contains pseudo-deleted objects"]; -grow_pseudo_deleted(suite) -> []; + +%% Grow a table that still contains pseudo-deleted objects. grow_pseudo_deleted(Config) when is_list(Config) -> only_if_smp(fun() -> grow_pseudo_deleted_do() end). @@ -5175,17 +4967,17 @@ grow_pseudo_deleted_do() -> grow_pseudo_deleted_do(Type) -> process_flag(scheduler,1), Self = self(), - ?line T = ets_new(kalle,[Type,public,{write_concurrency,true}]), + T = ets_new(kalle,[Type,public,{write_concurrency,true}]), Mod = 7, Mult = 10000, filltabint(T,Mod*Mult), - ?line true = ets:safe_fixtable(T,true), - ?line Mult = ets:select_delete(T, - [{{'$1', '_'}, - [{'=:=', {'rem', '$1', Mod}, 0}], - [true]}]), + true = ets:safe_fixtable(T,true), + Mult = ets:select_delete(T, + [{{'$1', '_'}, + [{'=:=', {'rem', '$1', Mod}, 0}], + [true]}]), Left = Mult*(Mod-1), - ?line Left = ets:info(T,size), - ?line Mult = get_kept_objects(T), + Left = ets:info(T,size), + Mult = get_kept_objects(T), filltabstr(T,Mult), my_spawn_opt( fun() -> @@ -5201,7 +4993,7 @@ grow_pseudo_deleted_do(Type) -> end), Self ! done end, [link, {scheduler,2}]), - ?line start = receive_any(), + start = receive_any(), io:format("Unfixing table... nitems=~p\n", [ets:info(T, size)]), do_tc(fun() -> true = ets:safe_fixtable(T, false) @@ -5210,15 +5002,14 @@ grow_pseudo_deleted_do(Type) -> io:format("Unfix table done in ~p ms. nitems=~p\n", [Elapsed,ets:info(T, size)]) end), - ?line false = ets:info(T,fixed), - ?line 0 = get_kept_objects(T), - ?line done = receive_any(), + false = ets:info(T,fixed), + 0 = get_kept_objects(T), + done = receive_any(), %%verify_table_load(T), % may fail if concurrency is poor (genny) ets:delete(T), process_flag(scheduler,0). -shrink_pseudo_deleted(doc) -> ["Shrink a table that still contains pseudo-deleted objects"]; -shrink_pseudo_deleted(suite) -> []; +%% Shrink a table that still contains pseudo-deleted objects. shrink_pseudo_deleted(Config) when is_list(Config) -> only_if_smp(fun()->shrink_pseudo_deleted_do() end). @@ -5229,16 +5020,16 @@ shrink_pseudo_deleted_do() -> shrink_pseudo_deleted_do(Type) -> process_flag(scheduler,1), Self = self(), - ?line T = ets_new(kalle,[Type,public,{write_concurrency,true}]), + T = ets_new(kalle,[Type,public,{write_concurrency,true}]), Half = 10000, filltabint(T,Half*2), - ?line true = ets:safe_fixtable(T,true), - ?line Half = ets:select_delete(T, - [{{'$1', '_'}, - [{'>', '$1', Half}], - [true]}]), - ?line Half = ets:info(T,size), - ?line Half = get_kept_objects(T), + true = ets:safe_fixtable(T,true), + Half = ets:select_delete(T, + [{{'$1', '_'}, + [{'>', '$1', Half}], + [true]}]), + Half = ets:info(T,size), + Half = get_kept_objects(T), my_spawn_opt( fun()-> true = ets:info(T,fixed), Self ! start, @@ -5249,10 +5040,10 @@ shrink_pseudo_deleted_do(Type) -> fun(Elapsed) -> io:format("Done with delete in ~p ms.\n", [Elapsed]) - end), + end), Self ! done end, [link, {scheduler,2}]), - ?line start = receive_any(), + start = receive_any(), io:format("Unfixing table... nitems=~p\n", [ets:info(T, size)]), do_tc(fun() -> true = ets:safe_fixtable(T, false) @@ -5261,20 +5052,19 @@ shrink_pseudo_deleted_do(Type) -> io:format("Unfix table done in ~p ms. nitems=~p\n", [Elapsed,ets:info(T, size)]) end), - ?line false = ets:info(T,fixed), - ?line 0 = get_kept_objects(T), - ?line done = receive_any(), + false = ets:info(T,fixed), + 0 = get_kept_objects(T), + done = receive_any(), %%verify_table_load(T), % may fail if concurrency is poor (genny) ets:delete(T), process_flag(scheduler,0). - -meta_lookup_unnamed_read(suite) -> []; + meta_lookup_unnamed_read(Config) when is_list(Config) -> InitF = fun(_) -> Tab = ets_new(unnamed,[]), - true = ets:insert(Tab,{key,data}), - Tab + true = ets:insert(Tab,{key,data}), + Tab end, ExecF = fun(Tab) -> [{key,data}] = ets:lookup(Tab,key), Tab @@ -5283,10 +5073,9 @@ meta_lookup_unnamed_read(Config) when is_list(Config) -> end, run_workers(InitF,ExecF,FiniF,10000). -meta_lookup_unnamed_write(suite) -> []; meta_lookup_unnamed_write(Config) when is_list(Config) -> InitF = fun(_) -> Tab = ets_new(unnamed,[]), - {Tab,0} + {Tab,0} end, ExecF = fun({Tab,N}) -> true = ets:insert(Tab,{key,N}), {Tab,N+1} @@ -5295,7 +5084,6 @@ meta_lookup_unnamed_write(Config) when is_list(Config) -> end, run_workers(InitF,ExecF,FiniF,10000). -meta_lookup_named_read(suite) -> []; meta_lookup_named_read(Config) when is_list(Config) -> InitF = fun([ProcN|_]) -> Name = list_to_atom(integer_to_list(ProcN)), Tab = ets_new(Name,[named_table]), @@ -5309,11 +5097,10 @@ meta_lookup_named_read(Config) when is_list(Config) -> end, run_workers(InitF,ExecF,FiniF,10000). -meta_lookup_named_write(suite) -> []; meta_lookup_named_write(Config) when is_list(Config) -> InitF = fun([ProcN|_]) -> Name = list_to_atom(integer_to_list(ProcN)), - Tab = ets_new(Name,[named_table]), - {Tab,0} + Tab = ets_new(Name,[named_table]), + {Tab,0} end, ExecF = fun({Tab,N}) -> true = ets:insert(Tab,{key,N}), {Tab,N+1} @@ -5322,7 +5109,6 @@ meta_lookup_named_write(Config) when is_list(Config) -> end, run_workers(InitF,ExecF,FiniF,10000). -meta_newdel_unnamed(suite) -> []; meta_newdel_unnamed(Config) when is_list(Config) -> InitF = fun(_) -> ok end, ExecF = fun(_) -> Tab = ets_new(unnamed,[]), @@ -5331,7 +5117,6 @@ meta_newdel_unnamed(Config) when is_list(Config) -> FiniF = fun(_) -> ok end, run_workers(InitF,ExecF,FiniF,10000). -meta_newdel_named(suite) -> []; meta_newdel_named(Config) when is_list(Config) -> InitF = fun([ProcN|_]) -> list_to_atom(integer_to_list(ProcN)) end, @@ -5342,8 +5127,7 @@ meta_newdel_named(Config) when is_list(Config) -> FiniF = fun(_) -> ok end, run_workers(InitF,ExecF,FiniF,10000). -smp_insert(doc) -> ["Concurrent insert's on same table"]; -smp_insert(suite) -> []; +%% Concurrent insert's on same table. smp_insert(Config) when is_list(Config) -> ets_new(smp_insert,[named_table,public,{write_concurrency,true}]), InitF = fun(_) -> ok end, @@ -5354,8 +5138,7 @@ smp_insert(Config) when is_list(Config) -> verify_table_load(smp_insert), ets:delete(smp_insert). -smp_fixed_delete(doc) -> ["Concurrent delete's on same fixated table"]; -smp_fixed_delete(suite) -> []; +%% Concurrent deletes on same fixated table. smp_fixed_delete(Config) when is_list(Config) -> only_if_smp(fun()->smp_fixed_delete_do() end). @@ -5375,21 +5158,20 @@ smp_fixed_delete_do() -> end, FiniF = fun(_) -> ok end, run_workers_do(InitF,ExecF,FiniF,NumOfObjs), - ?line 0 = ets:info(T,size), - ?line true = ets:info(T,fixed), - ?line Buckets = num_of_buckets(T), - ?line NumOfObjs = get_kept_objects(T), + 0 = ets:info(T,size), + true = ets:info(T,fixed), + Buckets = num_of_buckets(T), + NumOfObjs = get_kept_objects(T), ets:safe_fixtable(T,false), %% Will fail as unfix does not shrink the table: - %%?line Mem = ets:info(T,memory), + %%Mem = ets:info(T,memory), %%verify_table_load(T), ets:delete(T). num_of_buckets(T) -> - ?line element(1,ets:info(T,stats)). + element(1,ets:info(T,stats)). -smp_unfix_fix(doc) -> ["Fixate hash table while other process is busy doing unfix"]; -smp_unfix_fix(suite) -> []; +%% Fixate hash table while other process is busy doing unfix. smp_unfix_fix(Config) when is_list(Config) -> only_if_smp(fun()-> smp_unfix_fix_do() end). @@ -5403,15 +5185,15 @@ smp_unfix_fix_do() -> filltabint(T,NumOfObjs), ets:safe_fixtable(T,true), Buckets = num_of_buckets(T), - ?line Deleted = ets:select_delete(T,[{{'$1', '_'}, - [{'=<','$1', Deleted}], - [true]}]), - ?line Buckets = num_of_buckets(T), + Deleted = ets:select_delete(T,[{{'$1', '_'}, + [{'=<','$1', Deleted}], + [true]}]), + Buckets = num_of_buckets(T), Left = NumOfObjs - Deleted, - ?line Left = ets:info(T,size), - ?line true = ets:info(T,fixed), - ?line Deleted = get_kept_objects(T), - + Left = ets:info(T,size), + true = ets:info(T,fixed), + Deleted = get_kept_objects(T), + {Child, Mref} = my_spawn_opt( fun()-> @@ -5438,9 +5220,9 @@ smp_unfix_fix_do() -> done = receive_any() end, [link, monitor, {scheduler,2}]), - - ?line start = receive_any(), - ?line true = ets:info(T,fixed), + + start = receive_any(), + true = ets:info(T,fixed), io:put_chars("Parent starting to unfix... ~p\n"), do_tc(fun() -> ets:safe_fixtable(T, false) @@ -5451,14 +5233,13 @@ smp_unfix_fix_do() -> end), Child ! done, {'DOWN', Mref, process, Child, normal} = receive_any(), - ?line false = ets:info(T,fixed), - ?line 0 = get_kept_objects(T), + false = ets:info(T,fixed), + 0 = get_kept_objects(T), %%verify_table_load(T), ets:delete(T), process_flag(scheduler,0). -otp_8166(doc) -> ["Unsafe unfix was done by trapping select/match"]; -otp_8166(suite) -> []; +%% Unsafe unfix was done by trapping select/match. otp_8166(Config) when is_list(Config) -> only_if_smp(3, fun()-> otp_8166_do(false), otp_8166_do(true) @@ -5489,8 +5270,8 @@ otp_8166_do(WC) -> {'DOWN', ReaderMref, process, ReaderPid, normal} = receive_any(), ZombieCrPid ! quit, {'DOWN', ZombieCrMref, process, ZombieCrPid, normal} = receive_any(), - ?line false = ets:info(T,fixed), - ?line 0 = get_kept_objects(T), + false = ets:info(T,fixed), + 0 = get_kept_objects(T), %%verify_table_load(T), ets:delete(T), process_flag(scheduler,0). @@ -5531,9 +5312,9 @@ otp_8166_zombie_creator(T,Deleted) -> {loop,Pid} -> filltabint(T,Deleted), ets:safe_fixtable(T,true), - ?line Deleted = ets:select_delete(T,[{{'$1', '_'}, - [{'=<','$1', Deleted}], - [true]}]), + Deleted = ets:select_delete(T,[{{'$1', '_'}, + [{'=<','$1', Deleted}], + [true]}]), Pid ! zombies_created, repeat_while(fun() -> case ets:info(T,safe_fixed_monotonic_time) of {_,[_P1,_P2]} -> @@ -5551,47 +5332,45 @@ otp_8166_zombie_creator(T,Deleted) -> io:format("ignore unfix in outer loop?\n",[]), otp_8166_zombie_creator(T,Deleted) end. - - - + + + verify_table_load(T) -> - ?line Stats = ets:info(T,stats), - ?line {Buckets,AvgLen,StdDev,ExpSD,_MinLen,_MaxLen,_} = Stats, - ?line ok = if - AvgLen > 7 -> - io:format("Table overloaded: Stats=~p\n~p\n", - [Stats, ets:info(T)]), - false; - - Buckets>256, AvgLen < 6 -> - io:format("Table underloaded: Stats=~p\n~p\n", - [Stats, ets:info(T)]), - false; - - StdDev > ExpSD*2 -> - io:format("Too large standard deviation (poor hashing?)," - " stats=~p\n~p\n",[Stats, ets:info(T)]), - false; - - true -> - io:format("Stats = ~p\n",[Stats]), - ok - end. - - -otp_8732(doc) -> ["ets:select on a tree with NIL key object"]; + Stats = ets:info(T,stats), + {Buckets,AvgLen,StdDev,ExpSD,_MinLen,_MaxLen,_} = Stats, + ok = if + AvgLen > 7 -> + io:format("Table overloaded: Stats=~p\n~p\n", + [Stats, ets:info(T)]), + false; + + Buckets>256, AvgLen < 6 -> + io:format("Table underloaded: Stats=~p\n~p\n", + [Stats, ets:info(T)]), + false; + + StdDev > ExpSD*2 -> + io:format("Too large standard deviation (poor hashing?)," + " stats=~p\n~p\n",[Stats, ets:info(T)]), + false; + + true -> + io:format("Stats = ~p\n",[Stats]), + ok + end. + + +%% ets:select on a tree with NIL key object. otp_8732(Config) when is_list(Config) -> Tab = ets_new(noname,[ordered_set]), filltabstr(Tab,999), ets:insert(Tab,{[],"nasty NIL object"}), - ?line [] = ets:match(Tab,{'_',nomatch}), %% Will hang if bug not fixed + [] = ets:match(Tab,{'_',nomatch}), %% Will hang if bug not fixed ok. -smp_select_delete(suite) -> []; -smp_select_delete(doc) -> - ["Run concurrent select_delete (and inserts) on same table."]; +%% Run concurrent select_delete (and inserts) on same table. smp_select_delete(Config) when is_list(Config) -> T = ets_new(smp_select_delete,[named_table,public,{write_concurrency,true}]), Mod = 17, @@ -5612,65 +5391,65 @@ smp_select_delete(Config) when is_list(Config) -> _ -> Key = rand:uniform(10000), Eq = Key rem Mod, - ?line case ets:insert_new(T,{Key,Key}) of - true -> - Diffs1 = setelement(Eq+1, Diffs0, - element(Eq+1,Diffs0)+1), - Diffs1; - false -> Diffs0 - end + case ets:insert_new(T,{Key,Key}) of + true -> + Diffs1 = setelement(Eq+1, Diffs0, + element(Eq+1,Diffs0)+1), + Diffs1; + false -> Diffs0 + end end end, FiniF = fun(Result) -> Result end, Results = run_workers_do(InitF,ExecF,FiniF,20000), - ?line TotCnts = lists:foldl(fun(Diffs, Sum) -> add_lists(Sum,tuple_to_list(Diffs)) end, - lists:duplicate(Mod, 0), Results), + TotCnts = lists:foldl(fun(Diffs, Sum) -> add_lists(Sum,tuple_to_list(Diffs)) end, + lists:duplicate(Mod, 0), Results), io:format("TotCnts = ~p\n",[TotCnts]), - ?line LeftInTab = lists:foldl(fun(N,Sum) -> Sum+N end, - 0, TotCnts), + LeftInTab = lists:foldl(fun(N,Sum) -> Sum+N end, + 0, TotCnts), io:format("LeftInTab = ~p\n",[LeftInTab]), - ?line LeftInTab = ets:info(T,size), + LeftInTab = ets:info(T,size), lists:foldl(fun(Cnt,Eq) -> WasCnt = ets:select_count(T, [{{'_', '$1'}, [{'=:=', {'rem', '$1', Mod}, Eq}], [true]}]), io:format("~p: ~p =?= ~p\n",[Eq,Cnt,WasCnt]), - ?line Cnt = WasCnt, + Cnt = WasCnt, Eq+1 end, 0, TotCnts), verify_table_load(T), - ?line LeftInTab = ets:select_delete(T, [{{'$1','$1'}, [], [true]}]), - ?line 0 = ets:info(T,size), - ?line false = ets:info(T,fixed), + LeftInTab = ets:select_delete(T, [{{'$1','$1'}, [], [true]}]), + 0 = ets:info(T,size), + false = ets:info(T,fixed), ets:delete(T). -types(doc) -> ["Test different types"]; +%% Test different types. types(Config) when is_list(Config) -> init_externals(), repeat_for_opts(types_do,[[set,ordered_set],compressed]). types_do(Opts) -> EtsMem = etsmem(), - ?line T = ets_new(xxx,Opts), + T = ets_new(xxx,Opts), Fun = fun(Term) -> - ets:insert(T,{Term}), - ?line [{Term}] = ets:lookup(T,Term), - ets:insert(T,{Term,xxx}), - ?line [{Term,xxx}] = ets:lookup(T,Term), - ets:insert(T,{Term,"xxx"}), - ?line [{Term,"xxx"}] = ets:lookup(T,Term), - ets:insert(T,{xxx,Term}), - ?line [{xxx,Term}] = ets:lookup(T,xxx), - ets:insert(T,{"xxx",Term}), - ?line [{"xxx",Term}] = ets:lookup(T,"xxx"), - ets:delete_all_objects(T), - ?line 0 = ets:info(T,size) + ets:insert(T,{Term}), + [{Term}] = ets:lookup(T,Term), + ets:insert(T,{Term,xxx}), + [{Term,xxx}] = ets:lookup(T,Term), + ets:insert(T,{Term,"xxx"}), + [{Term,"xxx"}] = ets:lookup(T,Term), + ets:insert(T,{xxx,Term}), + [{xxx,Term}] = ets:lookup(T,xxx), + ets:insert(T,{"xxx",Term}), + [{"xxx",Term}] = ets:lookup(T,"xxx"), + ets:delete_all_objects(T), + 0 = ets:info(T,size) end, test_terms(Fun, strict), ets:delete(T), - ?line verify_etsmem(EtsMem). + verify_etsmem(EtsMem). %% OTP-9932: Memory overwrite when inserting large integers in compressed bag. @@ -5687,9 +5466,10 @@ otp_9932(Config) when is_list(Config) -> end, lists:foreach(Fun, lists:seq(0, 16)), ets:delete(T). - -otp_9423(doc) -> ["vm-deadlock caused by race between ets:delete and others on write_concurrency table"]; + +%% vm-deadlock caused by race between ets:delete and others on +%% write_concurrency table. otp_9423(Config) when is_list(Config) -> InitF = fun(_) -> {0,0} end, ExecF = fun({S,F}) -> @@ -5716,10 +5496,10 @@ otp_9423(Config) when is_list(Config) -> [P ! stop || P <- Pids], wait_pids(Pids), ok; - + Skipped -> Skipped end. - + %% Corrupted binary in compressed table otp_10182(Config) when is_list(Config) -> @@ -5747,7 +5527,7 @@ ets_all_run() -> ets:delete(Table), false = lists:member(Table, ets:all()), ets_all_run(). - + take(Config) when is_list(Config) -> %% Simple test for set tables. @@ -5786,9 +5566,9 @@ take(Config) when is_list(Config) -> ok. -% -% Utility functions: -% +%% +%% Utility functions: +%% add_lists(L1,L2) -> add_lists(L1,L2,[]). @@ -5810,9 +5590,9 @@ run_workers(InitF,ExecF,FiniF,Laps, Exclude) -> run_workers_do(InitF,ExecF,FiniF,Laps) -> run_workers_do(InitF,ExecF,FiniF,Laps, 0). run_workers_do(InitF,ExecF,FiniF,Laps, Exclude) -> - ?line NumOfProcs = case erlang:system_info(schedulers) of - N when (N > Exclude) -> N - Exclude - end, + NumOfProcs = case erlang:system_info(schedulers) of + N when (N > Exclude) -> N - Exclude + end, io:format("smp starting ~p workers\n",[NumOfProcs]), Seeds = [{ProcN,rand:uniform(9999)} || ProcN <- lists:seq(1,NumOfProcs)], Parent = self(), @@ -5822,7 +5602,7 @@ run_workers_do(InitF,ExecF,FiniF,Laps, Exclude) -> infinite -> Pids; _ -> wait_pids(Pids) end. - + worker({ProcN,Seed}, InitF, ExecF, FiniF, Laps, Parent, NumOfProcs) -> io:format("smp worker ~p, seed=~p~n",[self(),Seed]), rand:seed(exsplus, {Seed,Seed,Seed}), @@ -5840,7 +5620,7 @@ worker_loop(infinite, ExecF, State) -> worker_loop(infinite,ExecF,ExecF(State)); worker_loop(N, ExecF, State) -> worker_loop(N-1,ExecF,ExecF(State)). - + wait_pids(Pids) -> wait_pids(Pids,[]). wait_pids([],Acc) -> @@ -5848,7 +5628,7 @@ wait_pids([],Acc) -> wait_pids(Pids, Acc) -> receive {Pid,Result} -> - ?line true = lists:member(Pid,Pids), + true = lists:member(Pid,Pids), Others = lists:delete(Pid,Pids), io:format("wait_pid got ~p from ~p, still waiting for ~p\n",[Result,Pid,Others]), wait_pids(Others,[Result | Acc]) @@ -5874,7 +5654,7 @@ wait_for_memory_deallocations() -> erts_debug:set_internal_state(available_internal_state, true), wait_for_memory_deallocations() end. - + etsmem() -> wait_for_memory_deallocations(), @@ -5887,35 +5667,35 @@ etsmem() -> ErlangMemoryEts = try erlang:memory(ets) catch error:notsup -> notsup end, Mem = - {ErlangMemoryEts, - case EtsAllocInfo of - false -> undefined; - MemInfo -> - CS = lists:foldl( - fun ({instance, _, L}, Acc) -> - {value,{mbcs,MBCS}} = lists:keysearch(mbcs, 1, L), - {value,{sbcs,SBCS}} = lists:keysearch(sbcs, 1, L), - NewAcc = [MBCS, SBCS | Acc], - case lists:keysearch(mbcs_pool, 1, L) of - {value,{mbcs_pool, MBCS_POOL}} -> - [MBCS_POOL|NewAcc]; - _ -> NewAcc - end - end, - [], - MemInfo), - lists:foldl( - fun(L, {Bl0,BlSz0}) -> - {value,BlTup} = lists:keysearch(blocks, 1, L), - blocks = element(1, BlTup), - Bl = element(2, BlTup), - {value,BlSzTup} = lists:keysearch(blocks_size, 1, L), - blocks_size = element(1, BlSzTup), - BlSz = element(2, BlSzTup), - {Bl0+Bl,BlSz0+BlSz} - end, {0,0}, CS) - end}, - {Mem,AllTabs}. + {ErlangMemoryEts, + case EtsAllocInfo of + false -> undefined; + MemInfo -> + CS = lists:foldl( + fun ({instance, _, L}, Acc) -> + {value,{mbcs,MBCS}} = lists:keysearch(mbcs, 1, L), + {value,{sbcs,SBCS}} = lists:keysearch(sbcs, 1, L), + NewAcc = [MBCS, SBCS | Acc], + case lists:keysearch(mbcs_pool, 1, L) of + {value,{mbcs_pool, MBCS_POOL}} -> + [MBCS_POOL|NewAcc]; + _ -> NewAcc + end + end, + [], + MemInfo), + lists:foldl( + fun(L, {Bl0,BlSz0}) -> + {value,BlTup} = lists:keysearch(blocks, 1, L), + blocks = element(1, BlTup), + Bl = element(2, BlTup), + {value,BlSzTup} = lists:keysearch(blocks_size, 1, L), + blocks_size = element(1, BlSzTup), + BlSz = element(2, BlSzTup), + {Bl0+Bl,BlSz0+BlSz} + end, {0,0}, CS) + end}, + {Mem,AllTabs}. verify_etsmem({MemInfo,AllTabs}) -> wait_for_test_procs(), @@ -6101,7 +5881,7 @@ receive_any_spinning(Loops,0,Tries) -> end; receive_any_spinning(Loops, N, Tries) when N>0 -> receive_any_spinning(Loops, N-1, Tries). - + spawn_monitor_with_pid(Pid, Fun) when is_pid(Pid) -> @@ -6136,130 +5916,130 @@ only_if_smp(Schedulers, Func) -> -define(heap_binary_size, 64). test_terms(Test_Func, Mode) -> garbage_collect(), - ?line Pib0 = process_info(self(),binary), - - ?line Test_Func(atom), - ?line Test_Func(''), - ?line Test_Func('a'), - ?line Test_Func('ab'), - ?line Test_Func('abc'), - ?line Test_Func('abcd'), - ?line Test_Func('abcde'), - ?line Test_Func('abcdef'), - ?line Test_Func('abcdefg'), - ?line Test_Func('abcdefgh'), - - ?line Test_Func(fun() -> ok end), + Pib0 = process_info(self(),binary), + + Test_Func(atom), + Test_Func(''), + Test_Func('a'), + Test_Func('ab'), + Test_Func('abc'), + Test_Func('abcd'), + Test_Func('abcde'), + Test_Func('abcdef'), + Test_Func('abcdefg'), + Test_Func('abcdefgh'), + + Test_Func(fun() -> ok end), X = id([a,{b,c},c]), Y = id({x,y,z}), Z = id(1 bsl 8*257), - ?line Test_Func(fun() -> X end), - ?line Test_Func(fun() -> {X,Y} end), - ?line Test_Func([fun() -> {X,Y,Z} end, - fun() -> {Z,X,Y} end, - fun() -> {Y,Z,X} end]), - - ?line Test_Func({trace_ts,{even_bigger,{some_data,fun() -> ok end}},{1,2,3}}), - ?line Test_Func({trace_ts,{even_bigger,{some_data,<<1,2,3,4,5,6,7,8,9,10>>}}, - {1,2,3}}), - - ?line Test_Func(1), - ?line Test_Func(42), - ?line Test_Func(-23), - ?line Test_Func(256), - ?line Test_Func(25555), - ?line Test_Func(-3333), - - ?line Test_Func(1.0), - - ?line Test_Func(183749783987483978498378478393874), - ?line Test_Func(-37894183749783987483978498378478393874), + Test_Func(fun() -> X end), + Test_Func(fun() -> {X,Y} end), + Test_Func([fun() -> {X,Y,Z} end, + fun() -> {Z,X,Y} end, + fun() -> {Y,Z,X} end]), + + Test_Func({trace_ts,{even_bigger,{some_data,fun() -> ok end}},{1,2,3}}), + Test_Func({trace_ts,{even_bigger,{some_data,<<1,2,3,4,5,6,7,8,9,10>>}}, + {1,2,3}}), + + Test_Func(1), + Test_Func(42), + Test_Func(-23), + Test_Func(256), + Test_Func(25555), + Test_Func(-3333), + + Test_Func(1.0), + + Test_Func(183749783987483978498378478393874), + Test_Func(-37894183749783987483978498378478393874), Very_Big = very_big_num(), - ?line Test_Func(Very_Big), - ?line Test_Func(-Very_Big+1), + Test_Func(Very_Big), + Test_Func(-Very_Big+1), - ?line Test_Func([]), - ?line Test_Func("abcdef"), - ?line Test_Func([a, b, 1, 2]), - ?line Test_Func([a|b]), + Test_Func([]), + Test_Func("abcdef"), + Test_Func([a, b, 1, 2]), + Test_Func([a|b]), - ?line Test_Func({}), - ?line Test_Func({1}), - ?line Test_Func({a, b}), - ?line Test_Func({a, b, c}), - ?line Test_Func(list_to_tuple(lists:seq(0, 255))), - ?line Test_Func(list_to_tuple(lists:seq(0, 256))), + Test_Func({}), + Test_Func({1}), + Test_Func({a, b}), + Test_Func({a, b, c}), + Test_Func(list_to_tuple(lists:seq(0, 255))), + Test_Func(list_to_tuple(lists:seq(0, 256))), - ?line Test_Func(make_ref()), - ?line Test_Func([make_ref(), make_ref()]), + Test_Func(make_ref()), + Test_Func([make_ref(), make_ref()]), - ?line Test_Func(make_port()), + Test_Func(make_port()), - ?line Test_Func(make_pid()), - ?line Test_Func(make_ext_pid()), - ?line Test_Func(make_ext_port()), - ?line Test_Func(make_ext_ref()), + Test_Func(make_pid()), + Test_Func(make_ext_pid()), + Test_Func(make_ext_port()), + Test_Func(make_ext_ref()), Bin0 = list_to_binary(lists:seq(0, 14)), - ?line Test_Func(Bin0), + Test_Func(Bin0), Bin1 = list_to_binary(lists:seq(0, ?heap_binary_size)), - ?line Test_Func(Bin1), + Test_Func(Bin1), Bin2 = list_to_binary(lists:seq(0, ?heap_binary_size+1)), - ?line Test_Func(Bin2), + Test_Func(Bin2), Bin3 = list_to_binary(lists:seq(0, 255)), garbage_collect(), Pib = process_info(self(),binary), - ?line Test_Func(Bin3), + Test_Func(Bin3), garbage_collect(), case Mode of - strict -> ?line Pib = process_info(self(),binary); + strict -> Pib = process_info(self(),binary); skip_refc_check -> ok end, - ?line Test_Func(make_unaligned_sub_binary(Bin0)), - ?line Test_Func(make_unaligned_sub_binary(Bin1)), - ?line Test_Func(make_unaligned_sub_binary(Bin2)), - ?line Test_Func(make_unaligned_sub_binary(Bin3)), - - ?line Test_Func(make_sub_binary(lists:seq(42, 43))), - ?line Test_Func(make_sub_binary([42,43,44])), - ?line Test_Func(make_sub_binary([42,43,44,45])), - ?line Test_Func(make_sub_binary([42,43,44,45,46])), - ?line Test_Func(make_sub_binary([42,43,44,45,46,47])), - ?line Test_Func(make_sub_binary([42,43,44,45,46,47,48])), - ?line Test_Func(make_sub_binary(lists:seq(42, 49))), - ?line Test_Func(make_sub_binary(lists:seq(0, 14))), - ?line Test_Func(make_sub_binary(lists:seq(0, ?heap_binary_size))), - ?line Test_Func(make_sub_binary(lists:seq(0, ?heap_binary_size+1))), - ?line Test_Func(make_sub_binary(lists:seq(0, 255))), - - ?line Test_Func(make_unaligned_sub_binary(lists:seq(42, 43))), - ?line Test_Func(make_unaligned_sub_binary([42,43,44])), - ?line Test_Func(make_unaligned_sub_binary([42,43,44,45])), - ?line Test_Func(make_unaligned_sub_binary([42,43,44,45,46])), - ?line Test_Func(make_unaligned_sub_binary([42,43,44,45,46,47])), - ?line Test_Func(make_unaligned_sub_binary([42,43,44,45,46,47,48])), - ?line Test_Func(make_unaligned_sub_binary(lists:seq(42, 49))), - ?line Test_Func(make_unaligned_sub_binary(lists:seq(0, 14))), - ?line Test_Func(make_unaligned_sub_binary(lists:seq(0, ?heap_binary_size))), - ?line Test_Func(make_unaligned_sub_binary(lists:seq(0, ?heap_binary_size+1))), - ?line Test_Func(make_unaligned_sub_binary(lists:seq(0, 255))), + Test_Func(make_unaligned_sub_binary(Bin0)), + Test_Func(make_unaligned_sub_binary(Bin1)), + Test_Func(make_unaligned_sub_binary(Bin2)), + Test_Func(make_unaligned_sub_binary(Bin3)), + + Test_Func(make_sub_binary(lists:seq(42, 43))), + Test_Func(make_sub_binary([42,43,44])), + Test_Func(make_sub_binary([42,43,44,45])), + Test_Func(make_sub_binary([42,43,44,45,46])), + Test_Func(make_sub_binary([42,43,44,45,46,47])), + Test_Func(make_sub_binary([42,43,44,45,46,47,48])), + Test_Func(make_sub_binary(lists:seq(42, 49))), + Test_Func(make_sub_binary(lists:seq(0, 14))), + Test_Func(make_sub_binary(lists:seq(0, ?heap_binary_size))), + Test_Func(make_sub_binary(lists:seq(0, ?heap_binary_size+1))), + Test_Func(make_sub_binary(lists:seq(0, 255))), + + Test_Func(make_unaligned_sub_binary(lists:seq(42, 43))), + Test_Func(make_unaligned_sub_binary([42,43,44])), + Test_Func(make_unaligned_sub_binary([42,43,44,45])), + Test_Func(make_unaligned_sub_binary([42,43,44,45,46])), + Test_Func(make_unaligned_sub_binary([42,43,44,45,46,47])), + Test_Func(make_unaligned_sub_binary([42,43,44,45,46,47,48])), + Test_Func(make_unaligned_sub_binary(lists:seq(42, 49))), + Test_Func(make_unaligned_sub_binary(lists:seq(0, 14))), + Test_Func(make_unaligned_sub_binary(lists:seq(0, ?heap_binary_size))), + Test_Func(make_unaligned_sub_binary(lists:seq(0, ?heap_binary_size+1))), + Test_Func(make_unaligned_sub_binary(lists:seq(0, 255))), %% Bit level binaries. - ?line Test_Func(<<1:1>>), - ?line Test_Func(<<2:2>>), - ?line Test_Func(<<42:10>>), - ?line Test_Func(list_to_bitstring([<<5:6>>|lists:seq(0, 255)])), + Test_Func(<<1:1>>), + Test_Func(<<2:2>>), + Test_Func(<<42:10>>), + Test_Func(list_to_bitstring([<<5:6>>|lists:seq(0, 255)])), - ?line Test_Func(F = fun(A) -> 42*A end), - ?line Test_Func(lists:duplicate(32, F)), + Test_Func(F = fun(A) -> 42*A end), + Test_Func(lists:duplicate(32, F)), - ?line Test_Func(FF = fun binary_SUITE:all/1), - ?line Test_Func(lists:duplicate(32, FF)), + Test_Func(FF = fun binary_SUITE:all/1), + Test_Func(lists:duplicate(32, FF)), garbage_collect(), case Mode of - strict -> ?line Pib0 = process_info(self(),binary); + strict -> Pib0 = process_info(self(),binary); skip_refc_check -> ok end, ok. @@ -6271,18 +6051,18 @@ very_big_num() -> very_big_num(33, 1). very_big_num(Left, Result) when Left > 0 -> - ?line very_big_num(Left-1, Result*256); + very_big_num(Left-1, Result*256); very_big_num(0, Result) -> - ?line Result. + Result. make_port() -> - ?line open_port({spawn, "efile"}, [eof]). + open_port({spawn, "efile"}, [eof]). make_pid() -> - ?line spawn_link(?MODULE, sleeper, []). + spawn_link(?MODULE, sleeper, []). sleeper() -> - ?line receive after infinity -> ok end. + receive after infinity -> ok end. make_ext_pid() -> {Pid, _, _} = get(externals), @@ -6340,11 +6120,11 @@ mk_pid({NodeName, Creation}, Number, Serial) when is_atom(NodeName) -> mk_pid({NodeNameExt, Creation}, Number, Serial); mk_pid({NodeNameExt, Creation}, Number, Serial) -> case catch binary_to_term(list_to_binary([?VERSION_MAGIC, - ?PID_EXT, - NodeNameExt, - uint32_be(Number), - uint32_be(Serial), - uint8(Creation)])) of + ?PID_EXT, + NodeNameExt, + uint32_be(Number), + uint32_be(Serial), + uint8(Creation)])) of Pid when is_pid(Pid) -> Pid; {'EXIT', {badarg, _}} -> @@ -6434,7 +6214,7 @@ repeat_for_opts(F, [], Acc) -> _ -> [RV | RV_Acc] end end - end, [], Acc); + end, [], Acc); repeat_for_opts(F, [OptList | Tail], []) when is_list(OptList) -> repeat_for_opts(F, Tail, [[Opt] || Opt <- OptList]); repeat_for_opts(F, [OptList | Tail], AccList) when is_list(OptList) -> @@ -6446,7 +6226,7 @@ repeat_for_opts_atom2list(all_types) -> [set,ordered_set,bag,duplicate_bag]; repeat_for_opts_atom2list(write_concurrency) -> [{write_concurrency,false},{write_concurrency,true}]; repeat_for_opts_atom2list(read_concurrency) -> [{read_concurrency,false},{read_concurrency,true}]; repeat_for_opts_atom2list(compressed) -> [compressed,void]. - + ets_new(Name, Opts) -> %%ets:new(Name, [compressed | Opts]). ets:new(Name, Opts). diff --git a/lib/stdlib/test/ets_tough_SUITE.erl b/lib/stdlib/test/ets_tough_SUITE.erl index 5c2ab4747c..c83c17217b 100644 --- a/lib/stdlib/test/ets_tough_SUITE.erl +++ b/lib/stdlib/test/ets_tough_SUITE.erl @@ -25,7 +25,9 @@ -compile([export_all]). -include_lib("common_test/include/ct.hrl"). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,5}}]. all() -> [ex1]. @@ -52,34 +54,31 @@ end_per_group(_GroupName, Config) -> -define(GLOBAL_PARAMS,ets_tough_SUITE_global_params). init_per_testcase(_Func, Config) -> - Dog=test_server:timetrap(test_server:seconds(300)), - [{watchdog, Dog}|Config]. + Config. -end_per_testcase(_Func, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Func, _Config) -> ets:delete(?GLOBAL_PARAMS). ex1(Config) when is_list(Config) -> - ?line ets:new(?GLOBAL_PARAMS,[named_table,public]), - ?line ets:insert(?GLOBAL_PARAMS,{a,set}), - ?line ets:insert(?GLOBAL_PARAMS,{b,set}), - ?line ex1_sub(Config), - ?line ets:insert(?GLOBAL_PARAMS,{a,ordered_set}), - ?line ets:insert(?GLOBAL_PARAMS,{b,set}), - ?line ex1_sub(Config), - ?line ets:insert(?GLOBAL_PARAMS,{a,ordered_set}), - ?line ets:insert(?GLOBAL_PARAMS,{b,ordered_set}), - ?line ex1_sub(Config). - - + ets:new(?GLOBAL_PARAMS,[named_table,public]), + ets:insert(?GLOBAL_PARAMS,{a,set}), + ets:insert(?GLOBAL_PARAMS,{b,set}), + ex1_sub(Config), + ets:insert(?GLOBAL_PARAMS,{a,ordered_set}), + ets:insert(?GLOBAL_PARAMS,{b,set}), + ex1_sub(Config), + ets:insert(?GLOBAL_PARAMS,{a,ordered_set}), + ets:insert(?GLOBAL_PARAMS,{b,ordered_set}), + ex1_sub(Config). + + ex1_sub(Config) -> {A,B} = prep(Config), N = - case ?config(ets_tough_SUITE_iters,Config) of + case proplists:get_value(ets_tough_SUITE_iters,Config) of undefined -> 5000; Other -> @@ -94,7 +93,7 @@ ex1_sub(Config) -> prep(Config) -> rand:seed(exsplus), put(dump_ticket,none), - DumpDir = filename:join(?config(priv_dir,Config), "ets_tough"), + DumpDir = filename:join(proplists:get_value(priv_dir,Config), "ets_tough"), file:make_dir(DumpDir), put(dump_dir,DumpDir), process_flag(trap_exit,true), @@ -188,9 +187,9 @@ operate(dump,A,_B) -> NewTicket = ddump_next(A,Units,Ticket), put(dump_ticket,NewTicket), _Result = case NewTicket of - done -> done; - _ -> dump_more - end, + done -> done; + _ -> dump_more + end, ?DEBUG(io:format("dump ~w (~w)\n",[Units,_Result])); _ -> DumpDir = get(dump_dir), @@ -211,7 +210,7 @@ operate(dump,A,_B) -> ok end end. - + random_operation() -> Ops = {get,put,erase,dirty_get,dump}, random_element(Ops). @@ -246,7 +245,7 @@ show_table(N) -> _ -> error end. - + show_entries(Fd) -> case phys_read_len(Fd) of {ok,Len} -> @@ -370,7 +369,7 @@ derase(ServerPid,Class,Key) -> dget_class(ServerPid,Class,Condition) -> gen_server:call(ServerPid, - {handle_get_class,Class,Condition},infinity). + {handle_get_class,Class,Condition},infinity). %%% derase_class(ServerPid,Class) -> ok %%% @@ -828,7 +827,7 @@ table_lookup_batch([],_Class,_Cond) -> []; table_lookup_batch([Table|Tables],Class,Cond) -> table_lookup_batch([],Tables,Table,ets:first(Table),Class,Cond,[]). - + table_lookup_batch(_Passed,[],_,'$end_of_table',_Class,_Cond,Ack) -> Ack; table_lookup_batch(Passed,[NewTable|Tables],Table,'$end_of_table', @@ -838,7 +837,7 @@ table_lookup_batch(Passed,[NewTable|Tables],Table,'$end_of_table', table_lookup_batch(Passed,Tables,Table,?ERASE_MARK(Key),Class,Cond,Ack) -> table_lookup_batch(Passed,Tables,Table,?ets_next(Table,?ERASE_MARK(Key)), Class,Cond,Ack); - + table_lookup_batch(Passed,Tables,Table,Key,Class,Cond,Ack) -> NewAck = case table_lookup(Passed,Key) of @@ -1069,7 +1068,7 @@ phys_load_table(DumpDir,N,Tab) -> Other -> {error,{open_error,Other}} end. - + phys_load_entries(Fd,Tab) -> case phys_read_len(Fd) of {ok,Len} -> diff --git a/lib/stdlib/test/file_sorter_SUITE.erl b/lib/stdlib/test/file_sorter_SUITE.erl index 947dc2ad8d..379f4d609b 100644 --- a/lib/stdlib/test/file_sorter_SUITE.erl +++ b/lib/stdlib/test/file_sorter_SUITE.erl @@ -19,7 +19,7 @@ %% -module(file_sorter_SUITE). -%-define(debug, true). +%%-define(debug, true). -ifdef(debug). -define(format(S, A), io:format(S, A)). @@ -30,7 +30,7 @@ -else. -include_lib("common_test/include/ct.hrl"). -define(format(S, A), ok). --define(privdir(Conf), ?config(priv_dir, Conf)). +-define(privdir(Conf), proplists:get_value(priv_dir, Conf)). -endif. -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, @@ -49,15 +49,14 @@ -export([init_per_testcase/2, end_per_testcase/2]). init_per_testcase(_Case, Config) -> - Dog=?t:timetrap(?t:minutes(2)), - [{watchdog, Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,2}}]. all() -> [basic, badarg, term_sort, term_keysort, @@ -83,377 +82,323 @@ end_per_group(_GroupName, Config) -> Config. -basic(doc) -> - ["Basic test case."]; -basic(suite) -> - []; +%% Basic test case. basic(Config) when is_list(Config) -> Fmt = binary, Arg = {format,Fmt}, Foo = outfile("foo", Config), P0 = pps(), - ?line F1s = [F1] = to_files([[]], Fmt, Config), - ?line ok = file_sorter:sort(F1), - ?line [] = from_files(F1, Fmt), - ?line ok = file_sorter:keysort(17, F1), - ?line [] = from_files(F1, Fmt), - ?line ok = file_sorter:merge(F1s, Foo), - ?line [] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line ok = file_sorter:keymerge(17, F1s, Foo), - ?line [] = from_files(Foo, Fmt), - ?line delete_files([Foo | F1s]), - - ?line [F2] = to_files([[foo,bar]], Fmt, Config), - ?line ok = file_sorter:sort([F2], F2, Arg), - ?line [bar,foo] = from_files(F2, Fmt), - ?line delete_files(F2), - - ?line Fs1 = to_files([[foo],[bar]], Fmt, Config), - ?line ok = file_sorter:sort(Fs1, Foo, Arg), - ?line [bar,foo] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line ok = file_sorter:merge(Fs1, Foo, Arg), - ?line [bar,foo] = from_files(Foo, Fmt), - ?line delete_files([Foo | Fs1]), - - ?line Fmt2 = binary_term, - ?line Arg2 = {format, Fmt2}, - ?line [F3] = to_files([[{foo,1},{bar,2}]], Fmt2, Config), - ?line ok = file_sorter:keysort([2], [F3], F3, Arg2), - ?line [{foo,1},{bar,2}] = from_files(F3, Fmt2), - ?line delete_files(F3), - - ?line Fs2 = to_files([[{foo,1}],[{bar,2}]], Fmt2, Config), - ?line ok = file_sorter:keysort(1, Fs2, Foo, Arg2), - ?line [{bar,2},{foo,1}] = from_files(Foo, Fmt2), - ?line delete_files(Foo), - ?line ok = file_sorter:keymerge(1, Fs2, Foo, Arg2), - ?line [{bar,2},{foo,1}] = from_files(Foo, Fmt2), - ?line delete_files([Foo | Fs2]), - - ?line true = P0 =:= pps(), + F1s = [F1] = to_files([[]], Fmt, Config), + ok = file_sorter:sort(F1), + [] = from_files(F1, Fmt), + ok = file_sorter:keysort(17, F1), + [] = from_files(F1, Fmt), + ok = file_sorter:merge(F1s, Foo), + [] = from_files(Foo, Fmt), + delete_files(Foo), + ok = file_sorter:keymerge(17, F1s, Foo), + [] = from_files(Foo, Fmt), + delete_files([Foo | F1s]), + + [F2] = to_files([[foo,bar]], Fmt, Config), + ok = file_sorter:sort([F2], F2, Arg), + [bar,foo] = from_files(F2, Fmt), + delete_files(F2), + + Fs1 = to_files([[foo],[bar]], Fmt, Config), + ok = file_sorter:sort(Fs1, Foo, Arg), + [bar,foo] = from_files(Foo, Fmt), + delete_files(Foo), + ok = file_sorter:merge(Fs1, Foo, Arg), + [bar,foo] = from_files(Foo, Fmt), + delete_files([Foo | Fs1]), + + Fmt2 = binary_term, + Arg2 = {format, Fmt2}, + [F3] = to_files([[{foo,1},{bar,2}]], Fmt2, Config), + ok = file_sorter:keysort([2], [F3], F3, Arg2), + [{foo,1},{bar,2}] = from_files(F3, Fmt2), + delete_files(F3), + + Fs2 = to_files([[{foo,1}],[{bar,2}]], Fmt2, Config), + ok = file_sorter:keysort(1, Fs2, Foo, Arg2), + [{bar,2},{foo,1}] = from_files(Foo, Fmt2), + delete_files(Foo), + ok = file_sorter:keymerge(1, Fs2, Foo, Arg2), + [{bar,2},{foo,1}] = from_files(Foo, Fmt2), + delete_files([Foo | Fs2]), + + true = P0 =:= pps(), ok. -badarg(doc) -> - ["Call functions with bad arguments."]; -badarg(suite) -> - []; +%% Call functions with bad arguments. badarg(Config) when is_list(Config) -> PrivDir = ?privdir(Config), BadFile = filename:join(PrivDir, "not_a_file"), ABadFile = filename:absname(BadFile), - ?line file:delete(BadFile), - ?line {error,{file_error,ABadFile,enoent}} = + file:delete(BadFile), + {error,{file_error,ABadFile,enoent}} = file_sorter:sort(BadFile), - ?line {'EXIT', {{badarg, {flipp}}, _}} = + {'EXIT', {{badarg, {flipp}}, _}} = (catch file_sorter:sort({flipp})), - ?line {error,{file_error,ABadFile,enoent}} = + {error,{file_error,ABadFile,enoent}} = file_sorter:keysort(1, BadFile), - ?line {'EXIT', {{badarg, {flipp}}, _}} = + {'EXIT', {{badarg, {flipp}}, _}} = (catch file_sorter:keysort(1, {flipp})), - ?line {'EXIT', {{badarg, {flipp}}, _}} = + {'EXIT', {{badarg, {flipp}}, _}} = (catch file_sorter:merge([{flipp}],foo)), - ?line {error,{file_error,ABadFile,enoent}} = + {error,{file_error,ABadFile,enoent}} = file_sorter:keymerge(1,[BadFile],foo), - ?line {'EXIT', {{badarg, {flipp}}, _}} = + {'EXIT', {{badarg, {flipp}}, _}} = (catch file_sorter:keymerge(1,[{flipp}],foo)), - ?line {'EXIT', {{badarg, _}, _}} = + {'EXIT', {{badarg, _}, _}} = (catch file_sorter:merge(fun(X) -> X end, foo)), - ?line {'EXIT', {{badarg, _}, _}} = + {'EXIT', {{badarg, _}, _}} = (catch file_sorter:keymerge(1, fun(X) -> X end, foo)), - ?line {error,{file_error,ABadFile,enoent}} = + {error,{file_error,ABadFile,enoent}} = file_sorter:check(BadFile), - ?line {'EXIT', {{badarg, {flipp}}, _}} = + {'EXIT', {{badarg, {flipp}}, _}} = (catch file_sorter:check({flipp})), - ?line {error,{file_error,ABadFile,enoent}} = + {error,{file_error,ABadFile,enoent}} = file_sorter:keycheck(1, BadFile), - ?line {'EXIT', {{badarg, {flipp}}, _}} = + {'EXIT', {{badarg, {flipp}}, _}} = (catch file_sorter:keycheck(1, {flipp})), - ?line {'EXIT', {{badarg, {flipp}}, _}} = + {'EXIT', {{badarg, {flipp}}, _}} = (catch file_sorter:check([{flipp}],foo)), - ?line {'EXIT', {{badarg, {flipp}}, _}} = + {'EXIT', {{badarg, {flipp}}, _}} = (catch file_sorter:keycheck(1,[{flipp}],foo)), - ?line {'EXIT', {{badarg, _}, _}} = + {'EXIT', {{badarg, _}, _}} = (catch file_sorter:check(fun(X) -> X end, foo)), - ?line {'EXIT', {{badarg, _}, _}} = + {'EXIT', {{badarg, _}, _}} = (catch file_sorter:keycheck(1, fun(X) -> X end, foo)), - ?line Fs1 = to_files([[1,2,3]], binary_term, Config), - ?line {'EXIT', {{badarg, flipp}, _}} = + Fs1 = to_files([[1,2,3]], binary_term, Config), + {'EXIT', {{badarg, flipp}, _}} = (catch file_sorter:check(Fs1 ++ flipp, [])), [F1] = Fs1, - ?line {error,{file_error,_,_}} = + {error,{file_error,_,_}} = file_sorter:sort(Fs1, foo, [{tmpdir,F1},{size,0}]), - ?line delete_files(Fs1), - ?line Fs2 = to_files([[1,2,3]], binary_term, Config), + delete_files(Fs1), + Fs2 = to_files([[1,2,3]], binary_term, Config), {error,{file_error,_,enoent}} = file_sorter:sort(Fs2, foo, [{tmpdir,filename:absname(BadFile)}, {size,0}]), - ?line delete_files(Fs2), + delete_files(Fs2), - ?line {'EXIT', {{badarg, bad}, _}} = + {'EXIT', {{badarg, bad}, _}} = (catch file_sorter:check([], [{format,term} | bad])), - ?line {'EXIT', {{badarg, [{flipp}]}, _}} = + {'EXIT', {{badarg, [{flipp}]}, _}} = (catch file_sorter:check([{flipp}])), - ?line {'EXIT', {{badarg, {flipp}}, _}} = + {'EXIT', {{badarg, {flipp}}, _}} = (catch file_sorter:keycheck(1, {flipp})), - ?line {'EXIT', {{badarg, [{flipp}]}, _}} = + {'EXIT', {{badarg, [{flipp}]}, _}} = (catch file_sorter:keycheck(2, [{flipp}])), - ?line {error,{file_error,_,eisdir}} = file_sorter:keycheck(1, []), - ?line {'EXIT', {{badarg, kp}, _}} = (catch file_sorter:keycheck(kp, [])), - ?line {'EXIT', {{badarg, kp}, _}} = + {error,{file_error,_,eisdir}} = file_sorter:keycheck(1, []), + {'EXIT', {{badarg, kp}, _}} = (catch file_sorter:keycheck(kp, [])), + {'EXIT', {{badarg, kp}, _}} = (catch file_sorter:keycheck([1, kp], [])), - ?line {'EXIT', {{badarg, kp}, _}} = + {'EXIT', {{badarg, kp}, _}} = (catch file_sorter:keycheck([1 | kp], [])), - ?line {'EXIT', {{badarg, []}, _}} = (catch file_sorter:keycheck([], [])), - ?line {'EXIT', {{badarg, {format, foo}}, _}} = + {'EXIT', {{badarg, []}, _}} = (catch file_sorter:keycheck([], [])), + {'EXIT', {{badarg, {format, foo}}, _}} = (catch file_sorter:check([], {format,foo})), - ?line {'EXIT', {{badarg, not_an_option}, _}} = + {'EXIT', {{badarg, not_an_option}, _}} = (catch file_sorter:keycheck(7, [], [not_an_option])), - ?line {'EXIT', {{badarg, format}, _}} = + {'EXIT', {{badarg, format}, _}} = (catch file_sorter:keycheck(1, [], [{format, binary}])), - ?line {'EXIT', {{badarg, order}, _}} = + {'EXIT', {{badarg, order}, _}} = (catch file_sorter:keycheck(1, [], [{order, fun compare/2}])), - ?line do_badarg(fun(I, O) -> file_sorter:sort(I, O) end, - fun(Kp, I, O) -> file_sorter:keysort(Kp, I, O) end, - BadFile), - ?line do_badarg_opt(fun(I, O, X) -> file_sorter:sort(I, O, X) end, - fun(Kp, I, O, X) -> file_sorter:keysort(Kp, I, O, X) - end), - ?line do_badarg(fun(I, O) -> file_sorter:merge(I, O) end, - fun(Kp, I, O) -> file_sorter:keymerge(Kp, I, O) end, - BadFile), - ?line do_badarg_opt(fun(I, O, X) -> file_sorter:merge(I, O, X) end, - fun(Kp, I, O, X) -> file_sorter:keymerge(Kp, I, O, X) - end). + do_badarg(fun(I, O) -> file_sorter:sort(I, O) end, + fun(Kp, I, O) -> file_sorter:keysort(Kp, I, O) end, + BadFile), + do_badarg_opt(fun(I, O, X) -> file_sorter:sort(I, O, X) end, + fun(Kp, I, O, X) -> file_sorter:keysort(Kp, I, O, X) + end), + do_badarg(fun(I, O) -> file_sorter:merge(I, O) end, + fun(Kp, I, O) -> file_sorter:keymerge(Kp, I, O) end, + BadFile), + do_badarg_opt(fun(I, O, X) -> file_sorter:merge(I, O, X) end, + fun(Kp, I, O, X) -> file_sorter:keymerge(Kp, I, O, X) + end). do_badarg(F, KF, BadFile) -> [Char | _] = BadFile, AFlipp = filename:absname(flipp), - ?line {error,{file_error,AFlipp,enoent}} = F([flipp | flopp], foo), - ?line {'EXIT', {{badarg, {foo,bar}}, _}} = (catch F([], {foo,bar})), - ?line {'EXIT', {{badarg, Char}, _}} = (catch F(BadFile, [])), - ?line {'EXIT', {{badarg, {flipp}}, _}} = (catch F({flipp}, [])), - - ?line {'EXIT', {{badarg, Char}, _}} = (catch KF(1, BadFile, [])), - ?line {'EXIT', {{badarg, {flipp}}, _}} = (catch KF(1, {flipp}, [])), - ?line {error,{file_error,AFlipp,enoent}} = + {error,{file_error,AFlipp,enoent}} = F([flipp | flopp], foo), + {'EXIT', {{badarg, {foo,bar}}, _}} = (catch F([], {foo,bar})), + {'EXIT', {{badarg, Char}, _}} = (catch F(BadFile, [])), + {'EXIT', {{badarg, {flipp}}, _}} = (catch F({flipp}, [])), + + {'EXIT', {{badarg, Char}, _}} = (catch KF(1, BadFile, [])), + {'EXIT', {{badarg, {flipp}}, _}} = (catch KF(1, {flipp}, [])), + {error,{file_error,AFlipp,enoent}} = KF(2, [flipp | flopp], foo), - ?line {'EXIT', {{badarg, {foo,bar}}, _}} = (catch KF(1, [], {foo,bar})), - ?line {'EXIT', {{badarg, kp}, _}} = (catch KF(kp, [], foo)), - ?line {'EXIT', {{badarg, kp}, _}} = (catch KF([1, kp], [], foo)), - ?line {'EXIT', {{badarg, kp}, _}} = (catch KF([1 | kp], [], foo)), - ?line {'EXIT', {{badarg, []}, _}} = (catch KF([], [], foo)), + {'EXIT', {{badarg, {foo,bar}}, _}} = (catch KF(1, [], {foo,bar})), + {'EXIT', {{badarg, kp}, _}} = (catch KF(kp, [], foo)), + {'EXIT', {{badarg, kp}, _}} = (catch KF([1, kp], [], foo)), + {'EXIT', {{badarg, kp}, _}} = (catch KF([1 | kp], [], foo)), + {'EXIT', {{badarg, []}, _}} = (catch KF([], [], foo)), ok. do_badarg_opt(F, KF) -> AFlipp = filename:absname(flipp), - ?line {error,{file_error,AFlipp,enoent}} = - F([flipp | flopp], foo, []), - ?line {'EXIT', {{badarg, {flipp}}, _}} = (catch F([{flipp}], foo, [])), - ?line {'EXIT', {{badarg, {out,put}}, _}} = (catch F([], {out,put}, [])), - ?line {'EXIT', {{badarg, not_an_option}, _}} = + {error,{file_error,AFlipp,enoent}} = + F([flipp | flopp], foo, []), + {'EXIT', {{badarg, {flipp}}, _}} = (catch F([{flipp}], foo, [])), + {'EXIT', {{badarg, {out,put}}, _}} = (catch F([], {out,put}, [])), + {'EXIT', {{badarg, not_an_option}, _}} = (catch F([], foo, [not_an_option])), - ?line {'EXIT', {{badarg, {format, foo}}, _}} = - (catch F([], foo, {format,foo})), - ?line {'EXIT', {{badarg, {size,foo}}, _}} = (catch F([], foo, {size,foo})), + {'EXIT', {{badarg, {format, foo}}, _}} = + (catch F([], foo, {format,foo})), + {'EXIT', {{badarg, {size,foo}}, _}} = (catch F([], foo, {size,foo})), - ?line {'EXIT', {{badarg, {size, -1}}, _}} = (catch F([], foo, {size,-1})), - ?line {'EXIT', {{badarg, {no_files, foo}}, _}} = + {'EXIT', {{badarg, {size, -1}}, _}} = (catch F([], foo, {size,-1})), + {'EXIT', {{badarg, {no_files, foo}}, _}} = (catch F([], foo, {no_files,foo})), - ?line {'EXIT', {{badarg, {no_files, 1}}, _}} = + {'EXIT', {{badarg, {no_files, 1}}, _}} = (catch F([], foo, {no_files,1})), - ?line {'EXIT', {{badarg, 1}, _}} = (catch F([], foo, {tmpdir,1})), - ?line {'EXIT', {{badarg, {order,1}}, _}} = (catch F([], foo, {order,1})), - ?line {'EXIT', {{badarg, {compressed, flopp}}, _}} = - (catch F([], foo, {compressed,flopp})), - ?line {'EXIT', {{badarg, {unique,flopp}}, _}} = - (catch F([], foo, {unique,flopp})), - ?line {'EXIT', {{badarg, {header,foo}}, _}} = + {'EXIT', {{badarg, 1}, _}} = (catch F([], foo, {tmpdir,1})), + {'EXIT', {{badarg, {order,1}}, _}} = (catch F([], foo, {order,1})), + {'EXIT', {{badarg, {compressed, flopp}}, _}} = + (catch F([], foo, {compressed,flopp})), + {'EXIT', {{badarg, {unique,flopp}}, _}} = + (catch F([], foo, {unique,flopp})), + {'EXIT', {{badarg, {header,foo}}, _}} = (catch F([], foo, {header,foo})), - ?line {'EXIT', {{badarg, {header, 0}}, _}} = + {'EXIT', {{badarg, {header, 0}}, _}} = (catch F([], foo, {header,0})), - ?line {'EXIT', {{badarg, {header, 1 bsl 35}}, _}} = + {'EXIT', {{badarg, {header, 1 bsl 35}}, _}} = (catch F([], foo, {header,1 bsl 35})), - ?line {'EXIT', {{badarg, header}, _}} = + {'EXIT', {{badarg, header}, _}} = (catch F([], foo, [{header,1},{format,term}])), - ?line {'EXIT', {{badarg, not_an_option}, _}} = + {'EXIT', {{badarg, not_an_option}, _}} = (catch KF(7, [], foo, [not_an_option])), - ?line {'EXIT', {{badarg,format}, _}} = + {'EXIT', {{badarg,format}, _}} = (catch KF(1, [], foo, [{format, binary}])), - ?line {'EXIT', {{badarg, order}, _}} = + {'EXIT', {{badarg, order}, _}} = (catch KF(1, [], foo, [{order, fun compare/2}])), - ?line {'EXIT', {{badarg, {flipp}}, _}} = + {'EXIT', {{badarg, {flipp}}, _}} = (catch KF(2, [{flipp}], foo,[])), - ?line {error,{file_error,AFlipp,enoent}} = + {error,{file_error,AFlipp,enoent}} = KF(2, [flipp | flopp], foo,[]), - ?line {'EXIT', {{badarg, {out, put}}, _}} = + {'EXIT', {{badarg, {out, put}}, _}} = (catch KF(1, [], {out,put}, [])), - ?line {'EXIT', {{badarg, kp}, _}} = (catch KF(kp, [], foo, [])), - ?line {'EXIT', {{badarg, kp}, _}} = (catch KF([1, kp], [], foo, [])), - ?line {'EXIT', {{badarg, kp}, _}} = (catch KF([1 | kp], [], foo, [])), + {'EXIT', {{badarg, kp}, _}} = (catch KF(kp, [], foo, [])), + {'EXIT', {{badarg, kp}, _}} = (catch KF([1, kp], [], foo, [])), + {'EXIT', {{badarg, kp}, _}} = (catch KF([1 | kp], [], foo, [])), ok. -term_sort(doc) -> - ["Sort terms on files."]; -term_sort(suite) -> - []; +%% Sort terms on files. term_sort(Config) when is_list(Config) -> - ?line sort(term, [{compressed,false}], Config), - ?line sort(term, [{order, fun compare/2}], Config), - ?line sort(term, [{order, ascending}, {compressed,true}], Config), - ?line sort(term, [{order, descending}], Config), + sort(term, [{compressed,false}], Config), + sort(term, [{order, fun compare/2}], Config), + sort(term, [{order, ascending}, {compressed,true}], Config), + sort(term, [{order, descending}], Config), ok. -term_keysort(doc) -> - ["Keysort terms on files."]; -term_keysort(suite) -> - []; +%% Keysort terms on files. term_keysort(Config) when is_list(Config) -> - ?line keysort(term, [{tmpdir, ""}], Config), - ?line keysort(term, [{order,descending}], Config), + keysort(term, [{tmpdir, ""}], Config), + keysort(term, [{order,descending}], Config), ok. -binary_term_sort(doc) -> - ["Sort binary terms on files."]; -binary_term_sort(suite) -> - []; +%% Sort binary terms on files. binary_term_sort(Config) when is_list(Config) -> PrivDir = ?privdir(Config), - ?line sort({2, binary_term}, [], Config), - ?line sort(binary_term, [{tmpdir, list_to_atom(PrivDir)}], Config), - ?line sort(binary_term, [{tmpdir,PrivDir}], Config), - ?line sort({3,binary_term}, [{order, fun compare/2}], Config), - ?line sort(binary_term, [{order, fun compare/2}], Config), - ?line sort(binary_term, [{order,descending}], Config), + sort({2, binary_term}, [], Config), + sort(binary_term, [{tmpdir, list_to_atom(PrivDir)}], Config), + sort(binary_term, [{tmpdir,PrivDir}], Config), + sort({3,binary_term}, [{order, fun compare/2}], Config), + sort(binary_term, [{order, fun compare/2}], Config), + sort(binary_term, [{order,descending}], Config), ok. -binary_term_keysort(doc) -> - ["Keysort binary terms on files."]; -binary_term_keysort(suite) -> - []; +%% Keysort binary terms on files. binary_term_keysort(Config) when is_list(Config) -> - ?line keysort({3, binary_term}, [], Config), - ?line keysort(binary_term, [], Config), - ?line keysort(binary_term, [{order,descending}], Config), + keysort({3, binary_term}, [], Config), + keysort(binary_term, [], Config), + keysort(binary_term, [{order,descending}], Config), ok. -binary_sort(doc) -> - ["Sort binaries on files."]; -binary_sort(suite) -> - []; +%% Sort binaries on files. binary_sort(Config) when is_list(Config) -> PrivDir = ?privdir(Config), - ?line sort({2, binary}, [], Config), - ?line sort(binary, [{tmpdir, list_to_atom(PrivDir)}], Config), - ?line sort(binary, [{tmpdir,PrivDir}], Config), - ?line sort({3,binary}, [{order, fun compare/2}], Config), - ?line sort(binary, [{order, fun compare/2}], Config), - ?line sort(binary, [{order,descending}], Config), + sort({2, binary}, [], Config), + sort(binary, [{tmpdir, list_to_atom(PrivDir)}], Config), + sort(binary, [{tmpdir,PrivDir}], Config), + sort({3,binary}, [{order, fun compare/2}], Config), + sort(binary, [{order, fun compare/2}], Config), + sort(binary, [{order,descending}], Config), ok. -term_merge(doc) -> - ["Merge terms on files."]; -term_merge(suite) -> - []; +%% Merge terms on files. term_merge(Config) when is_list(Config) -> - ?line merge(term, [{order, fun compare/2}], Config), - ?line merge(term, [{order, ascending}, {compressed,true}], Config), - ?line merge(term, [{order, descending}, {compressed,false}], Config), + merge(term, [{order, fun compare/2}], Config), + merge(term, [{order, ascending}, {compressed,true}], Config), + merge(term, [{order, descending}, {compressed,false}], Config), ok. -term_keymerge(doc) -> - ["Keymerge terms on files."]; -term_keymerge(suite) -> - []; +%% Keymerge terms on files. term_keymerge(Config) when is_list(Config) -> - ?line keymerge(term, [], Config), - ?line keymerge(term, [{order, descending}], Config), - ?line funmerge(term, [], Config), + keymerge(term, [], Config), + keymerge(term, [{order, descending}], Config), + funmerge(term, [], Config), ok. -binary_term_merge(doc) -> - ["Merge binary terms on files."]; -binary_term_merge(suite) -> - []; +%% Merge binary terms on files. binary_term_merge(Config) when is_list(Config) -> - ?line merge(binary_term, [], Config), - ?line merge({7, binary_term}, [], Config), - ?line merge({3, binary_term}, [{order, fun compare/2}], Config), + merge(binary_term, [], Config), + merge({7, binary_term}, [], Config), + merge({3, binary_term}, [{order, fun compare/2}], Config), ok. -binary_term_keymerge(doc) -> - ["Keymerge binary terms on files."]; -binary_term_keymerge(suite) -> - []; +%% Keymerge binary terms on files. binary_term_keymerge(Config) when is_list(Config) -> - ?line keymerge({3, binary_term}, [], Config), - ?line keymerge(binary_term, [], Config), - ?line funmerge({3, binary_term}, [], Config), - ?line funmerge(binary_term, [], Config), + keymerge({3, binary_term}, [], Config), + keymerge(binary_term, [], Config), + funmerge({3, binary_term}, [], Config), + funmerge(binary_term, [], Config), ok. -binary_merge(doc) -> - ["Merge binaries on files."]; -binary_merge(suite) -> - []; +%% Merge binaries on files. binary_merge(Config) when is_list(Config) -> - ?line merge(binary, [], Config), - ?line merge({7, binary}, [], Config), - ?line merge({3, binary}, [{order, fun compare/2}], Config), + merge(binary, [], Config), + merge({7, binary}, [], Config), + merge({3, binary}, [{order, fun compare/2}], Config), ok. -term_check(doc) -> - ["Check terms on files."]; -term_check(suite) -> - []; +%% Check terms on files. term_check(Config) when is_list(Config) -> - ?line check(term, Config), + check(term, Config), ok. -binary_term_check(doc) -> - ["Check binary terms on files."]; -binary_term_check(suite) -> - []; +%% Check binary terms on files. binary_term_check(Config) when is_list(Config) -> - ?line check(binary_term, Config), + check(binary_term, Config), ok. -term_keycheck(doc) -> - ["Keycheck terms on files."]; -term_keycheck(suite) -> - []; +%% Keycheck terms on files. term_keycheck(Config) when is_list(Config) -> - ?line keycheck(term, Config), + keycheck(term, Config), ok. -binary_term_keycheck(doc) -> - ["Keycheck binary terms on files."]; -binary_term_keycheck(suite) -> - []; +%% Keycheck binary terms on files. binary_term_keycheck(Config) when is_list(Config) -> - ?line keycheck(binary_term, Config), + keycheck(binary_term, Config), ok. -binary_check(doc) -> - ["Check binary terms on files."]; -binary_check(suite) -> - []; +%% Check binary terms on files. binary_check(Config) when is_list(Config) -> - ?line check(binary, Config), + check(binary, Config), ok. -inout(doc) -> - ["Funs as input or output."]; -inout(suite) -> - []; +%% Funs as input or output. inout(Config) when is_list(Config) -> BTF = {format, binary_term}, Foo = outfile("foo", Config), @@ -462,52 +407,52 @@ inout(Config) when is_list(Config) -> End = fun(read) -> end_of_input end, IF1 = fun(read) -> {[1,7,5], End} end, - ?line ok = file_sorter:sort(IF1, Foo, [{format, term}]), + ok = file_sorter:sort(IF1, Foo, [{format, term}]), %% 'close' is called, but the return value is caught and ignored. IF2 = fun(read) -> {[1,2,3], fun(close) -> throw(ignored) end} end, - ?line {error, bad_object} = file_sorter:sort(IF2, Foo, BTF), + {error, bad_object} = file_sorter:sort(IF2, Foo, BTF), IF3 = fun(no_match) -> foo end, - ?line {'EXIT', {function_clause, _}} = + {'EXIT', {function_clause, _}} = (catch file_sorter:sort(IF3, Foo)), IF4 = fun(read) -> throw(my_message) end, - ?line my_message = (catch file_sorter:sort(IF4, Foo)), + my_message = (catch file_sorter:sort(IF4, Foo)), IF5 = fun(read) -> {error, my_error} end, - ?line {error, my_error} = file_sorter:sort(IF5, Foo), + {error, my_error} = file_sorter:sort(IF5, Foo), %% Output is fun. - ?line {error, bad_object} = + {error, bad_object} = file_sorter:sort(IF2, fun(close) -> ignored end, BTF), Args = [{format, term}], - ?line {error, bad_object} = - file_sorter:keysort(1, IF2, fun(close) -> ignored end, Args), + {error, bad_object} = + file_sorter:keysort(1, IF2, fun(close) -> ignored end, Args), OF1 = fun(close) -> fine; (L) when is_list(L) -> fun(close) -> nice end end, - ?line nice = file_sorter:sort(IF1, OF1, Args), + nice = file_sorter:sort(IF1, OF1, Args), OF2 = fun(_) -> my_return end, - ?line my_return = file_sorter:sort(IF1, OF2, Args), + my_return = file_sorter:sort(IF1, OF2, Args), OF3 = fun(_) -> throw(my_message) end, - ?line my_message = (catch file_sorter:sort(IF1, OF3, Args)), + my_message = (catch file_sorter:sort(IF1, OF3, Args)), OF4 = fun(no_match) -> foo end, - ?line {'EXIT', {function_clause, _}} = + {'EXIT', {function_clause, _}} = (catch file_sorter:sort(IF1, OF4, Args)), - ?line P0 = pps(), - ?line Fs1 = to_files([[3,1,2,5,4], [8,3,10]], term, Config), - ?line error = file_sorter:sort(Fs1, fun(_) -> error end, Args), - ?line delete_files(Fs1), + P0 = pps(), + Fs1 = to_files([[3,1,2,5,4], [8,3,10]], term, Config), + error = file_sorter:sort(Fs1, fun(_) -> error end, Args), + delete_files(Fs1), - ?line true = P0 =:= pps(), + true = P0 =:= pps(), %% Passing a value from the input functions to the output functions. IFV1 = fun(read) -> {end_of_input, 17} end, OFV1 = fun({value, Value}) -> ofv(Value, []) end, - ?line {17, []} = file_sorter:sort(IFV1, OFV1, Args), + {17, []} = file_sorter:sort(IFV1, OFV1, Args), %% Output is not a fun. The value returned by input funs is ignored. %% OTP-5009. - ?line ok = file_sorter:sort(IFV1, Foo, [{format,term}]), - ?line [] = from_files(Foo, term), - ?line delete_files(Foo), + ok = file_sorter:sort(IFV1, Foo, [{format,term}]), + [] = from_files(Foo, term), + delete_files(Foo), ok. @@ -518,10 +463,7 @@ ofv(Value, A) -> ofv(Value, [L | A]) end. -many(doc) -> - ["Many temporary files."]; -many(suite) -> - []; +%% Many temporary files. many(Config) when is_list(Config) -> Foo = outfile("foo", Config), PrivDir = ?privdir(Config), @@ -530,171 +472,168 @@ many(Config) when is_list(Config) -> Args = [{format, term}], L1 = lists:map(fun(I) -> {one, two, three, I} end, lists:seq(1,1000)), L2 = lists:map(fun(I) -> {four, five, six, I} end, lists:seq(1,1000)), - ?line Fs2 = to_files([L1, L2], term, Config), - ?line ok = file_sorter:sort(Fs2, Foo, [{size,1000} | Args]), - ?line R = lists:sort(L1++L2), - ?line R = from_files(Foo, term), - ?line 2000 = length(R), - ?line ok = file_sorter:sort(Fs2, Foo, [{no_files,4},{size,1000} | Args]), - ?line R = from_files(Foo, term), - ?line ok = + Fs2 = to_files([L1, L2], term, Config), + ok = file_sorter:sort(Fs2, Foo, [{size,1000} | Args]), + R = lists:sort(L1++L2), + R = from_files(Foo, term), + 2000 = length(R), + ok = file_sorter:sort(Fs2, Foo, [{no_files,4},{size,1000} | Args]), + R = from_files(Foo, term), + ok = file_sorter:sort(Fs2, Foo, [{no_files,4},{size,1000},{order,descending} | Args]), - ?line true = lists:reverse(R) =:= from_files(Foo, term), - ?line ok = + true = lists:reverse(R) =:= from_files(Foo, term), + ok = file_sorter:sort(Fs2, Foo, [{no_files,4},{size,1000}, {order,fun compare/2} | Args]), - ?line R = from_files(Foo, term), - ?line ok = file_sorter:keysort(4, Fs2, Foo, - [{no_files,4},{size,1000} | Args]), - ?line RK = lists:keysort(4, L1++L2), - ?line RK = from_files(Foo, term), - ?line delete_files(Foo), - ?line ok = + R = from_files(Foo, term), + ok = file_sorter:keysort(4, Fs2, Foo, + [{no_files,4},{size,1000} | Args]), + RK = lists:keysort(4, L1++L2), + RK = from_files(Foo, term), + delete_files(Foo), + ok = file_sorter:keysort(4, Fs2, Foo, - [{no_files,4},{size,1000},{order,descending} | Args]), - ?line true = lists:reverse(RK) =:= from_files(Foo, term), - ?line delete_files(Foo), - ?line ok = file_sorter:keysort(4, Fs2, Foo, - [{size,500},{order,descending} | Args]), - ?line true = lists:reverse(RK) =:= from_files(Foo, term), - ?line delete_files(Foo), - ?line error = file_sorter:sort(Fs2, fun(_) -> error end, - [{tmpdir, PrivDir}, {no_files,3}, - {size,10000} | Args]), + [{no_files,4},{size,1000},{order,descending} | Args]), + true = lists:reverse(RK) =:= from_files(Foo, term), + delete_files(Foo), + ok = file_sorter:keysort(4, Fs2, Foo, + [{size,500},{order,descending} | Args]), + true = lists:reverse(RK) =:= from_files(Foo, term), + delete_files(Foo), + error = file_sorter:sort(Fs2, fun(_) -> error end, + [{tmpdir, PrivDir}, {no_files,3}, + {size,10000} | Args]), TmpDir = filename:join(PrivDir, "tmpdir"), file:del_dir(TmpDir), - ?line ok = file:make_dir(TmpDir), - ?line case os:type() of - {unix, _} -> - ?line ok = file:change_mode(TmpDir, 8#0000), - ?line {error, {file_error, _,_}} = - file_sorter:sort(Fs2, fun(_M) -> foo end, - [{no_files,3},{size,10000}, - {tmpdir,TmpDir} | Args]); - _ -> - true - end, - ?line ok = file:del_dir(TmpDir), + ok = file:make_dir(TmpDir), + case os:type() of + {unix, _} -> + ok = file:change_mode(TmpDir, 8#0000), + {error, {file_error, _,_}} = + file_sorter:sort(Fs2, fun(_M) -> foo end, + [{no_files,3},{size,10000}, + {tmpdir,TmpDir} | Args]); + _ -> + true + end, + ok = file:del_dir(TmpDir), delete_files(Fs2), - ?line true = P0 =:= pps(), + true = P0 =:= pps(), ok. -misc(doc) -> - ["Some other tests."]; -misc(suite) -> - []; +%% Some other tests. misc(Config) when is_list(Config) -> BTF = {format, binary_term}, Foo = outfile("foo", Config), FFoo = filename:absname(Foo), P0 = pps(), - ?line [File] = Fs1 = to_files([[1,3,2]], term, Config), - ?line ok = file:write_file(Foo,<<>>), - ?line case os:type() of - {unix, _} -> - ok = file:change_mode(Foo, 8#0000), - {error,{file_error,FFoo,eacces}} = - file_sorter:sort(Fs1, Foo, {format,term}); - _ -> - true - end, - ?line file:delete(Foo), - ?line NoBytes = 16, % RAM memory will never get this big, or? - ?line ALot = (1 bsl (NoBytes*8)) - 1, - ?line ok = file:write_file(File, <<ALot:NoBytes/unit:8,"foobar">>), + [File] = Fs1 = to_files([[1,3,2]], term, Config), + ok = file:write_file(Foo,<<>>), + case os:type() of + {unix, _} -> + ok = file:change_mode(Foo, 8#0000), + {error,{file_error,FFoo,eacces}} = + file_sorter:sort(Fs1, Foo, {format,term}); + _ -> + true + end, + file:delete(Foo), + NoBytes = 16, % RAM memory will never get this big, or? + ALot = (1 bsl (NoBytes*8)) - 1, + ok = file:write_file(File, <<ALot:NoBytes/unit:8,"foobar">>), FFile = filename:absname(File), - ?line {error, {bad_object,FFile}} = + {error, {bad_object,FFile}} = file_sorter:sort(Fs1, Foo, [BTF, {header, 20}]), - ?line ok = file:write_file(File, <<30:32,"foobar">>), - ?line {error, {premature_eof, FFile}} = file_sorter:sort(Fs1, Foo, BTF), - ?line ok = file:write_file(File, <<6:32,"foobar">>), - ?line {error, {bad_object,FFile}} = file_sorter:sort(Fs1, Foo, BTF), - ?line case os:type() of - {unix, _} -> - ok = file:change_mode(File, 8#0000), - {error, {file_error,FFile,eacces}} = - file_sorter:sort(Fs1, Foo), - {error, {file_error,FFile,eacces}} = - file_sorter:sort(Fs1, Foo, {format, binary_term}); - _ -> - true - end, - ?line delete_files(Fs1), - ?line true = P0 =:= pps(), + ok = file:write_file(File, <<30:32,"foobar">>), + {error, {premature_eof, FFile}} = file_sorter:sort(Fs1, Foo, BTF), + ok = file:write_file(File, <<6:32,"foobar">>), + {error, {bad_object,FFile}} = file_sorter:sort(Fs1, Foo, BTF), + case os:type() of + {unix, _} -> + ok = file:change_mode(File, 8#0000), + {error, {file_error,FFile,eacces}} = + file_sorter:sort(Fs1, Foo), + {error, {file_error,FFile,eacces}} = + file_sorter:sort(Fs1, Foo, {format, binary_term}); + _ -> + true + end, + delete_files(Fs1), + true = P0 =:= pps(), %% bigger than chunksize - ?line E1 = <<32000:32, 10:256000>>, - ?line E2 = <<32000:32, 5:256000>>, - ?line E3 = <<32000:32, 8:256000>>, - ?line ok = file:write_file(Foo, [E1, E2, E3]), - ?line ok = file_sorter:sort([Foo], Foo, [{format,binary},{size,10000}]), - ?line ok = file_sorter:sort([Foo], Foo, [{format,fun(X) -> X end}, - {size,10000}]), - ?line Es = list_to_binary([E2,E3,E1]), - ?line {ok, Es} = file:read_file(Foo), - ?line delete_files(Foo), - ?line true = P0 =:= pps(), + E1 = <<32000:32, 10:256000>>, + E2 = <<32000:32, 5:256000>>, + E3 = <<32000:32, 8:256000>>, + ok = file:write_file(Foo, [E1, E2, E3]), + ok = file_sorter:sort([Foo], Foo, [{format,binary},{size,10000}]), + ok = file_sorter:sort([Foo], Foo, [{format,fun(X) -> X end}, + {size,10000}]), + Es = list_to_binary([E2,E3,E1]), + {ok, Es} = file:read_file(Foo), + delete_files(Foo), + true = P0 =:= pps(), %% keysort more than one element L = [{c,1,a},{c,2,b},{c,3,c},{b,1,c},{b,2,b},{b,3,a},{a,1,a},{a,2,b}, {a,3,c}], - ?line Fs2 = to_files([L], binary_term, Config), - ?line ok = file_sorter:keysort([2,3], Fs2, Foo, {format, binary_term}), - ?line KS2_1 = from_files(Foo, binary_term), - ?line KS2_2 = lists:keysort(2,lists:keysort(3, L)), - ?line KS2_1 = KS2_2, - ?line ok = file_sorter:keysort([2,3], Fs2, Foo, - [{format, binary_term},{size,5}]), - ?line KS2_3 = from_files(Foo, binary_term), - ?line KS2_3 = KS2_2, - ?line ok = file_sorter:keysort([2,3,1], Fs2, Foo, {format, binary_term}), - ?line KS3_1 = from_files(Foo, binary_term), - ?line KS3_2 = lists:keysort(2, lists:keysort(3,lists:keysort(1, L))), - ?line KS3_1 = KS3_2, - ?line ok = file_sorter:keysort([2,3,1], Fs2, Foo, - [{format, binary_term},{size,5}]), - ?line KS3_3 = from_files(Foo, binary_term), - ?line KS3_3 = KS3_2, - ?line delete_files([Foo | Fs2]), - ?line true = P0 =:= pps(), + Fs2 = to_files([L], binary_term, Config), + ok = file_sorter:keysort([2,3], Fs2, Foo, {format, binary_term}), + KS2_1 = from_files(Foo, binary_term), + KS2_2 = lists:keysort(2,lists:keysort(3, L)), + KS2_1 = KS2_2, + ok = file_sorter:keysort([2,3], Fs2, Foo, + [{format, binary_term},{size,5}]), + KS2_3 = from_files(Foo, binary_term), + KS2_3 = KS2_2, + ok = file_sorter:keysort([2,3,1], Fs2, Foo, {format, binary_term}), + KS3_1 = from_files(Foo, binary_term), + KS3_2 = lists:keysort(2, lists:keysort(3,lists:keysort(1, L))), + KS3_1 = KS3_2, + ok = file_sorter:keysort([2,3,1], Fs2, Foo, + [{format, binary_term},{size,5}]), + KS3_3 = from_files(Foo, binary_term), + KS3_3 = KS3_2, + delete_files([Foo | Fs2]), + true = P0 =:= pps(), %% bigger than chunksize %% Assumes that CHUNKSIZE = 16384. Illustrates that the Last argument %% of merge_files/5 is necessary. - ?line EP1 = erlang:make_tuple(2728,foo), - ?line EP2 = lists:duplicate(2729,qqq), - ?line LL = [EP1, EP2, EP1, EP2, EP1, EP2], - ?line Fs3 = to_files([LL], binary, Config), - ?line ok = file_sorter:sort(Fs3, Foo, [{format,binary}, {unique,true}]), - ?line [EP1,EP2] = from_files(Foo, binary), - ?line delete_files(Foo), - ?line ok = file_sorter:sort(Fs3, Foo, - [{format,binary_term}, {unique,true}, - {size,30000}]), - ?line [EP1,EP2] = from_files(Foo, binary_term), - ?line delete_files([Foo | Fs3]), - - ?line true = P0 =:= pps(), - - ?line BE1 = <<20000:32, 17:160000>>, - ?line BE2 = <<20000:32, 1717:160000>>, - ?line ok = file:write_file(Foo, [BE1,BE2,BE1,BE2]), - ?line ok = file_sorter:sort([Foo], Foo, [{format,binary}, - {size,10000}, - {unique,true}]), - ?line BEs = list_to_binary([BE1, BE2]), - ?line {ok, BEs} = file:read_file(Foo), - ?line delete_files(Foo), - ?line true = P0 =:= pps(), - - ?line Fs4 = to_files([[7,4,1]], binary_term, Config), - ?line {error, {bad_term, _}} = file_sorter:sort(Fs4, Foo, {format, term}), - ?line delete_files([Foo | Fs4]), - ?line true = P0 =:= pps(), + EP1 = erlang:make_tuple(2728,foo), + EP2 = lists:duplicate(2729,qqq), + LL = [EP1, EP2, EP1, EP2, EP1, EP2], + Fs3 = to_files([LL], binary, Config), + ok = file_sorter:sort(Fs3, Foo, [{format,binary}, {unique,true}]), + [EP1,EP2] = from_files(Foo, binary), + delete_files(Foo), + ok = file_sorter:sort(Fs3, Foo, + [{format,binary_term}, {unique,true}, + {size,30000}]), + [EP1,EP2] = from_files(Foo, binary_term), + delete_files([Foo | Fs3]), + + true = P0 =:= pps(), + + BE1 = <<20000:32, 17:160000>>, + BE2 = <<20000:32, 1717:160000>>, + ok = file:write_file(Foo, [BE1,BE2,BE1,BE2]), + ok = file_sorter:sort([Foo], Foo, [{format,binary}, + {size,10000}, + {unique,true}]), + BEs = list_to_binary([BE1, BE2]), + {ok, BEs} = file:read_file(Foo), + delete_files(Foo), + true = P0 =:= pps(), + + Fs4 = to_files([[7,4,1]], binary_term, Config), + {error, {bad_term, _}} = file_sorter:sort(Fs4, Foo, {format, term}), + delete_files([Foo | Fs4]), + true = P0 =:= pps(), ok. @@ -708,71 +647,71 @@ sort(Fmt, XArgs, Config) -> Foo = outfile("foo", Config), %% Input is a fun. Output is a fun. - ?line [] = file_sorter:sort(input([], 2, Fmt), output([], Fmt), Args), - ?line L1 = [3,1,2,5,4], - ?line S1 = file_sorter:sort(input(L1, 2, Fmt), output([], Fmt), TmpArgs), - ?line S1 = rev(lists:sort(L1), TmpArgs), + [] = file_sorter:sort(input([], 2, Fmt), output([], Fmt), Args), + L1 = [3,1,2,5,4], + S1 = file_sorter:sort(input(L1, 2, Fmt), output([], Fmt), TmpArgs), + S1 = rev(lists:sort(L1), TmpArgs), %% Input is a file. Output is a fun. - ?line [] = file_sorter:sort([], output([], Fmt), Args), - ?line L2 = [3,1,2,5,4], - ?line Fs1 = to_files([L2], Fmt, Config), - ?line S2 = file_sorter:sort(Fs1, output([], Fmt), TmpArgs), - ?line S2 = rev(lists:sort(L2), TmpArgs), - ?line delete_files(Fs1), + [] = file_sorter:sort([], output([], Fmt), Args), + L2 = [3,1,2,5,4], + Fs1 = to_files([L2], Fmt, Config), + S2 = file_sorter:sort(Fs1, output([], Fmt), TmpArgs), + S2 = rev(lists:sort(L2), TmpArgs), + delete_files(Fs1), %% Input is a file. Output is a file - ?line ok = file_sorter:sort([], Foo, Args), - ?line [] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line ok = file_sorter:sort([], Foo, [{unique,true} | Args]), - ?line [] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line L3 = [3,1,2,5,4,6], - ?line Fs2 = to_files([L3], Fmt, Config), - ?line ok = file_sorter:sort(Fs2, Foo, Args), - ?line true = rev(lists:sort(L3), Args) =:= from_files(Foo, Fmt), - ?line delete_files([Foo | Fs2]), - ?line L4 = [1,3,4,1,2,5,4,5,6], - ?line Fs3 = to_files([L4], Fmt, Config), - ?line ok = file_sorter:sort(Fs3, Foo, Args++[{unique,true}, - {size,100000}]), - ?line true = rev(lists:usort(L4), Args) =:= from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line ok = file_sorter:sort(Fs3, Foo, Args++[{unique,true}]), - ?line true = rev(lists:usort(L4), Args) =:= from_files(Foo, Fmt), - ?line delete_files([Foo | Fs3]), + ok = file_sorter:sort([], Foo, Args), + [] = from_files(Foo, Fmt), + delete_files(Foo), + ok = file_sorter:sort([], Foo, [{unique,true} | Args]), + [] = from_files(Foo, Fmt), + delete_files(Foo), + L3 = [3,1,2,5,4,6], + Fs2 = to_files([L3], Fmt, Config), + ok = file_sorter:sort(Fs2, Foo, Args), + true = rev(lists:sort(L3), Args) =:= from_files(Foo, Fmt), + delete_files([Foo | Fs2]), + L4 = [1,3,4,1,2,5,4,5,6], + Fs3 = to_files([L4], Fmt, Config), + ok = file_sorter:sort(Fs3, Foo, Args++[{unique,true}, + {size,100000}]), + true = rev(lists:usort(L4), Args) =:= from_files(Foo, Fmt), + delete_files(Foo), + ok = file_sorter:sort(Fs3, Foo, Args++[{unique,true}]), + true = rev(lists:usort(L4), Args) =:= from_files(Foo, Fmt), + delete_files([Foo | Fs3]), %% Input is a fun. Output is a file. - ?line ok = file_sorter:sort(input([], 2, Fmt), Foo, Args), - ?line [] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line L5 = [3,1,2,5,4,7], - ?line ok = file_sorter:sort(input(L5, 2, Fmt), Foo, Args), - ?line true = rev(lists:sort(L5), Args) =:= from_files(Foo, Fmt), - ?line delete_files(Foo), + ok = file_sorter:sort(input([], 2, Fmt), Foo, Args), + [] = from_files(Foo, Fmt), + delete_files(Foo), + L5 = [3,1,2,5,4,7], + ok = file_sorter:sort(input(L5, 2, Fmt), Foo, Args), + true = rev(lists:sort(L5), Args) =:= from_files(Foo, Fmt), + delete_files(Foo), %% Removing duplicate keys. KFun = key_compare(2), L6 = [{5,e},{2,b},{3,c},{1,a},{4,d}] ++ [{2,c},{1,b},{4,a}], KUArgs = lists:keydelete(order, 1, Args) ++ - [{unique, true}, {order, KFun},{size,100000}], - ?line ok = file_sorter:sort(input(L6, 2, Fmt), Foo, KUArgs), - ?line true = rev(lists:ukeysort(2, L6), KUArgs) =:= from_files(Foo, Fmt), + [{unique, true}, {order, KFun},{size,100000}], + ok = file_sorter:sort(input(L6, 2, Fmt), Foo, KUArgs), + true = rev(lists:ukeysort(2, L6), KUArgs) =:= from_files(Foo, Fmt), KArgs = lists:keydelete(unique, 1, KUArgs), - ?line ok = file_sorter:sort(input(L6, 2, Fmt), Foo, KArgs), - ?line true = rev(lists:keysort(2, L6), KArgs) =:= from_files(Foo, Fmt), + ok = file_sorter:sort(input(L6, 2, Fmt), Foo, KArgs), + true = rev(lists:keysort(2, L6), KArgs) =:= from_files(Foo, Fmt), %% Removing duplicate keys. Again. KUArgs2 = lists:keydelete(order, 1, Args) ++ - [{unique, true}, {order, KFun},{size,5}], - ?line ok = file_sorter:sort(input(L6, 2, Fmt), Foo, KUArgs2), - ?line true = rev(lists:ukeysort(2, L6), KUArgs2) =:= from_files(Foo, Fmt), + [{unique, true}, {order, KFun},{size,5}], + ok = file_sorter:sort(input(L6, 2, Fmt), Foo, KUArgs2), + true = rev(lists:ukeysort(2, L6), KUArgs2) =:= from_files(Foo, Fmt), KArgs2 = lists:keydelete(unique, 1, KUArgs2), - ?line ok = file_sorter:sort(input(L6, 2, Fmt), Foo, KArgs2), - ?line true = rev(lists:keysort(2, L6), KArgs2) =:= from_files(Foo, Fmt), - ?line delete_files(Foo), - + ok = file_sorter:sort(input(L6, 2, Fmt), Foo, KArgs2), + true = rev(lists:keysort(2, L6), KArgs2) =:= from_files(Foo, Fmt), + delete_files(Foo), + ok. keysort(Fmt, XArgs, Config) -> @@ -781,58 +720,58 @@ keysort(Fmt, XArgs, Config) -> Foo = outfile("foo", Config), %% Input is files. Output is a file. - ?line ok = file_sorter:keysort(2, [], Foo, Args), - ?line [] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line ok = file_sorter:keysort(2, [], Foo, [{unique,true} | Args]), - ?line [] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line L0 = [{a,2},{a,1},{a,2},{a,2},{a,1},{a,2},{a,2},{a,3}], - ?line Fs0 = to_files([L0], Fmt, Config), - ?line S = rev(lists:ukeysort(1, L0), Args), - ?line ok = + ok = file_sorter:keysort(2, [], Foo, Args), + [] = from_files(Foo, Fmt), + delete_files(Foo), + ok = file_sorter:keysort(2, [], Foo, [{unique,true} | Args]), + [] = from_files(Foo, Fmt), + delete_files(Foo), + L0 = [{a,2},{a,1},{a,2},{a,2},{a,1},{a,2},{a,2},{a,3}], + Fs0 = to_files([L0], Fmt, Config), + S = rev(lists:ukeysort(1, L0), Args), + ok = file_sorter:keysort(1, Fs0, Foo, Args ++ [{unique,true}, {size,100000}]), - ?line S = from_files(Foo, Fmt), - ?line ok = + S = from_files(Foo, Fmt), + ok = file_sorter:keysort(1, Fs0, Foo, Args ++ [{unique,true}, {size,5}]), - ?line S = from_files(Foo, Fmt), - ?line ok = file_sorter:keysort(1, Fs0, Foo, Args ++ [{unique,true}]), - ?line S = from_files(Foo, Fmt), - ?line delete_files([Foo | Fs0]), - ?line L11 = [{a,1,x4},{b,2,x4},{c,3,x4}], - ?line L21 = [{a,1,x3},{b,2,x3},{c,3,x3}], - ?line L31 = [{a,1,x2},{b,2,x2},{c,3,x2}], - ?line L41 = [{a,1,x1},{b,2,x1},{c,3,x1}], - ?line All = [L11, L21, L31, L41], - ?line AllFlat = lists:append(All), - ?line Sorted = rev(lists:keysort(2, AllFlat), Args), - ?line Fs1 = to_files(All, Fmt, Config), - ?line ok = file_sorter:keysort(2, Fs1, Foo, Args), - ?line Sorted = from_files(Foo, Fmt), - ?line delete_files(Foo), + S = from_files(Foo, Fmt), + ok = file_sorter:keysort(1, Fs0, Foo, Args ++ [{unique,true}]), + S = from_files(Foo, Fmt), + delete_files([Foo | Fs0]), + L11 = [{a,1,x4},{b,2,x4},{c,3,x4}], + L21 = [{a,1,x3},{b,2,x3},{c,3,x3}], + L31 = [{a,1,x2},{b,2,x2},{c,3,x2}], + L41 = [{a,1,x1},{b,2,x1},{c,3,x1}], + All = [L11, L21, L31, L41], + AllFlat = lists:append(All), + Sorted = rev(lists:keysort(2, AllFlat), Args), + Fs1 = to_files(All, Fmt, Config), + ok = file_sorter:keysort(2, Fs1, Foo, Args), + Sorted = from_files(Foo, Fmt), + delete_files(Foo), %% Input is files. Output is a fun. - ?line [] = file_sorter:keysort(2, [], output([], Fmt), Args), - ?line KS1 = file_sorter:keysort(2, Fs1, output([], Fmt), TmpArgs), - ?line Sorted = KS1, - ?line delete_files(Fs1), + [] = file_sorter:keysort(2, [], output([], Fmt), Args), + KS1 = file_sorter:keysort(2, Fs1, output([], Fmt), TmpArgs), + Sorted = KS1, + delete_files(Fs1), %% Input is a fun. Output is a file. - ?line ok = file_sorter:keysort(2, input([], 2, Fmt), Foo, Args), - ?line [] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line ok = file_sorter:keysort(2, input(AllFlat, 4, Fmt), Foo, Args), - ?line Sorted = from_files(Foo, Fmt), - ?line delete_files(Foo), + ok = file_sorter:keysort(2, input([], 2, Fmt), Foo, Args), + [] = from_files(Foo, Fmt), + delete_files(Foo), + ok = file_sorter:keysort(2, input(AllFlat, 4, Fmt), Foo, Args), + Sorted = from_files(Foo, Fmt), + delete_files(Foo), %% Input is a fun. Output is a fun. - ?line [] = file_sorter:keysort(2, input([], 2, Fmt), output([], Fmt),Args), - ?line KS2 = + [] = file_sorter:keysort(2, input([], 2, Fmt), output([], Fmt),Args), + KS2 = file_sorter:keysort(2, input(AllFlat, 4, Fmt), output([], Fmt), TmpArgs), - ?line Sorted = KS2, + Sorted = KS2, ok. merge(Fmt, XArgs, Config) -> @@ -840,35 +779,35 @@ merge(Fmt, XArgs, Config) -> Foo = outfile("foo", Config), %% Input is a file. Output is a fun. - ?line [] = file_sorter:merge([], output([], Fmt), Args), - ?line L2 = [[1,3,5],[2,4,5]], - ?line Fs1 = to_files(L2, Fmt, Config), - ?line S2 = file_sorter:sort(Fs1, output([], Fmt), Args), - ?line S2 = rev(lists:sort(lists:append(L2)), Args), - ?line delete_files(Fs1), + [] = file_sorter:merge([], output([], Fmt), Args), + L2 = [[1,3,5],[2,4,5]], + Fs1 = to_files(L2, Fmt, Config), + S2 = file_sorter:sort(Fs1, output([], Fmt), Args), + S2 = rev(lists:sort(lists:append(L2)), Args), + delete_files(Fs1), %% Input is a file. Output is a file - ?line ok = file_sorter:merge([], Foo, Args), - ?line [] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line ok = file_sorter:merge([], Foo, [{unique,true} | Args]), - ?line [] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line L31 = [1,2,3], - ?line L32 = [2,3,4], - ?line L33 = [4,5,6], - ?line L3r = [L31, L32, L33], - ?line L3 = [rev(L31,Args), rev(L32,Args), rev(L33,Args)], - ?line Fs2 = to_files(L3, Fmt, Config), - ?line ok = file_sorter:merge(Fs2, Foo, Args), - ?line true = rev(lists:merge(L3r), Args) =:= from_files(Foo, Fmt), - ?line ok = file_sorter:merge(Fs2, Foo, Args++[{unique,true}, - {size,100000}]), - ?line true = rev(lists:umerge(L3r), Args) =:= from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line ok = file_sorter:merge(Fs2, Foo, Args++[{unique,true}]), - ?line true = rev(lists:umerge(L3r), Args) =:= from_files(Foo, Fmt), - ?line delete_files([Foo | Fs2]), + ok = file_sorter:merge([], Foo, Args), + [] = from_files(Foo, Fmt), + delete_files(Foo), + ok = file_sorter:merge([], Foo, [{unique,true} | Args]), + [] = from_files(Foo, Fmt), + delete_files(Foo), + L31 = [1,2,3], + L32 = [2,3,4], + L33 = [4,5,6], + L3r = [L31, L32, L33], + L3 = [rev(L31,Args), rev(L32,Args), rev(L33,Args)], + Fs2 = to_files(L3, Fmt, Config), + ok = file_sorter:merge(Fs2, Foo, Args), + true = rev(lists:merge(L3r), Args) =:= from_files(Foo, Fmt), + ok = file_sorter:merge(Fs2, Foo, Args++[{unique,true}, + {size,100000}]), + true = rev(lists:umerge(L3r), Args) =:= from_files(Foo, Fmt), + delete_files(Foo), + ok = file_sorter:merge(Fs2, Foo, Args++[{unique,true}]), + true = rev(lists:umerge(L3r), Args) =:= from_files(Foo, Fmt), + delete_files([Foo | Fs2]), ok. @@ -877,83 +816,83 @@ keymerge(Fmt, XArgs, Config) -> Foo = outfile("foo", Config), %% Input is files. Output is a file. - ?line ok = file_sorter:keymerge(2, [], Foo, Args), - ?line [] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line ok = file_sorter:keymerge(2, [], Foo, [{unique,true} | Args]), - ?line [] = from_files(Foo, Fmt), - ?line delete_files(Foo), - ?line L0 = [rev([{a,1},{a,2}], Args), rev([{a,2},{a,1},{a,3}], Args)], - ?line Fs0 = to_files(L0, Fmt, Config), - ?line delete_files(Foo), - ?line ok = file_sorter:keymerge(1, Fs0, Foo, Args ++ [{unique,false}]), - ?line S2 = rev([{a,1},{a,2},{a,2},{a,1},{a,3}], Args), - ?line S2 = from_files(Foo, Fmt), - ?line delete_files([Foo | Fs0]), - ?line L11 = [{a,1,x4},{b,2,x4},{c,3,x4}], - ?line L21 = [{a,1,x3},{b,2,x3},{c,3,x3}], - ?line L31 = [{a,1,x2},{b,2,x2},{c,3,x2}], - ?line L41 = [{a,1,x1},{b,2,x1},{c,3,x1}], - ?line All = + ok = file_sorter:keymerge(2, [], Foo, Args), + [] = from_files(Foo, Fmt), + delete_files(Foo), + ok = file_sorter:keymerge(2, [], Foo, [{unique,true} | Args]), + [] = from_files(Foo, Fmt), + delete_files(Foo), + L0 = [rev([{a,1},{a,2}], Args), rev([{a,2},{a,1},{a,3}], Args)], + Fs0 = to_files(L0, Fmt, Config), + delete_files(Foo), + ok = file_sorter:keymerge(1, Fs0, Foo, Args ++ [{unique,false}]), + S2 = rev([{a,1},{a,2},{a,2},{a,1},{a,3}], Args), + S2 = from_files(Foo, Fmt), + delete_files([Foo | Fs0]), + L11 = [{a,1,x4},{b,2,x4},{c,3,x4}], + L21 = [{a,1,x3},{b,2,x3},{c,3,x3}], + L31 = [{a,1,x2},{b,2,x2},{c,3,x2}], + L41 = [{a,1,x1},{b,2,x1},{c,3,x1}], + All = [rev(L11, Args), rev(L21, Args), rev(L31, Args), rev(L41, Args)], - ?line Merged1 = lists:keymerge(2, L11, L21), - ?line Merged2 = lists:keymerge(2, L31, L41), - ?line Merged = rev(lists:keymerge(2, Merged1, Merged2), Args), - ?line Fs1 = to_files(All, Fmt, Config), - ?line ok = file_sorter:keymerge(2, Fs1, Foo, Args), - ?line Merged = from_files(Foo, Fmt), + Merged1 = lists:keymerge(2, L11, L21), + Merged2 = lists:keymerge(2, L31, L41), + Merged = rev(lists:keymerge(2, Merged1, Merged2), Args), + Fs1 = to_files(All, Fmt, Config), + ok = file_sorter:keymerge(2, Fs1, Foo, Args), + Merged = from_files(Foo, Fmt), fun() -> - UArgs = [{unique,true} | Args], - ?line UMerged1 = lists:ukeymerge(2, L11, L21), - ?line UMerged2 = lists:ukeymerge(2, L31, L41), - ?line UMerged = rev(lists:ukeymerge(2, UMerged1, UMerged2), Args), - ?line ok = file_sorter:keymerge(2, Fs1, Foo, UArgs), - ?line UMerged = from_files(Foo, Fmt), - UArgs2 = make_args(Fmt, [{unique,true}, {size,50} | XArgs]), - ?line ok = file_sorter:keymerge(2, Fs1, Foo, UArgs2), - ?line UMerged = from_files(Foo, Fmt), - ?line List = rev([{a,1,x4},{b,2,x4},{c,3,x4}], Args), - ?line FsL = to_files([List], Fmt, Config), - ?line ok = file_sorter:keymerge(2, FsL, Foo, UArgs), - ?line List = from_files(Foo, Fmt), - ?line List1 = [{a,1,x4},{b,2,x4},{c,3,x4}], - ?line List2 = [{a,3,x4},{b,4,x4},{c,5,x4}], - ?line FsLL = to_files([rev(List1, Args), rev(List2, Args)], Fmt, Config), - ?line ok = file_sorter:keymerge(2, FsLL, Foo, UArgs), - ?line List1_2 = rev(lists:ukeymerge(2, List1, List2), Args), - ?line List1_2 = from_files(Foo, Fmt), - ?line delete_files(Foo) + UArgs = [{unique,true} | Args], + UMerged1 = lists:ukeymerge(2, L11, L21), + UMerged2 = lists:ukeymerge(2, L31, L41), + UMerged = rev(lists:ukeymerge(2, UMerged1, UMerged2), Args), + ok = file_sorter:keymerge(2, Fs1, Foo, UArgs), + UMerged = from_files(Foo, Fmt), + UArgs2 = make_args(Fmt, [{unique,true}, {size,50} | XArgs]), + ok = file_sorter:keymerge(2, Fs1, Foo, UArgs2), + UMerged = from_files(Foo, Fmt), + List = rev([{a,1,x4},{b,2,x4},{c,3,x4}], Args), + FsL = to_files([List], Fmt, Config), + ok = file_sorter:keymerge(2, FsL, Foo, UArgs), + List = from_files(Foo, Fmt), + List1 = [{a,1,x4},{b,2,x4},{c,3,x4}], + List2 = [{a,3,x4},{b,4,x4},{c,5,x4}], + FsLL = to_files([rev(List1, Args), rev(List2, Args)], Fmt, Config), + ok = file_sorter:keymerge(2, FsLL, Foo, UArgs), + List1_2 = rev(lists:ukeymerge(2, List1, List2), Args), + List1_2 = from_files(Foo, Fmt), + delete_files(Foo) end(), %% Input is files. Output is a fun. - ?line Fs3 = to_files(All, Fmt, Config), - ?line [] = file_sorter:keysort(2, [], output([], Fmt), Args), - ?line KS1 = file_sorter:keymerge(2, Fs3, output([], Fmt), Args), - ?line Merged = KS1, - ?line delete_files([Foo | Fs3]), - - ?line L2 = [[{a,1}],[{a,2}],[{a,3}],[{a,4}],[{a,5}],[{a,6}],[{a,7}]], - ?line Fs2 = to_files(L2, Fmt, Config), - ?line M = file_sorter:keymerge(1, Fs2, output([], Fmt), Args), - ?line M = rev(lists:append(L2), Args), - ?line delete_files(Fs2), - - ?line LL1 = [{d,4},{e,5},{f,6}], - ?line LL2 = [{a,1},{b,2},{c,3}], - ?line LL3 = [{j,10},{k,11},{l,12}], - ?line LL4 = [{g,7},{h,8},{i,9}], - ?line LL5 = [{p,16},{q,17},{r,18}], - ?line LL6 = [{m,13},{n,14},{o,15}], - ?line LLAll = [rev(LL1, Args),rev(LL2, Args),rev(LL3, Args), - rev(LL4, Args),rev(LL5, Args),rev(LL6, Args)], - ?line FsLL6 = to_files(LLAll, Fmt, Config), - ?line LL = rev(lists:sort(lists:append(LLAll)), Args), - ?line ok = file_sorter:keymerge(1, FsLL6, Foo, Args), - ?line LL = from_files(Foo, Fmt), - ?line ok = file_sorter:keymerge(1, FsLL6, Foo, [{unique,true} | Args]), - ?line LL = from_files(Foo, Fmt), - ?line delete_files([Foo | FsLL6]), + Fs3 = to_files(All, Fmt, Config), + [] = file_sorter:keysort(2, [], output([], Fmt), Args), + KS1 = file_sorter:keymerge(2, Fs3, output([], Fmt), Args), + Merged = KS1, + delete_files([Foo | Fs3]), + + L2 = [[{a,1}],[{a,2}],[{a,3}],[{a,4}],[{a,5}],[{a,6}],[{a,7}]], + Fs2 = to_files(L2, Fmt, Config), + M = file_sorter:keymerge(1, Fs2, output([], Fmt), Args), + M = rev(lists:append(L2), Args), + delete_files(Fs2), + + LL1 = [{d,4},{e,5},{f,6}], + LL2 = [{a,1},{b,2},{c,3}], + LL3 = [{j,10},{k,11},{l,12}], + LL4 = [{g,7},{h,8},{i,9}], + LL5 = [{p,16},{q,17},{r,18}], + LL6 = [{m,13},{n,14},{o,15}], + LLAll = [rev(LL1, Args),rev(LL2, Args),rev(LL3, Args), + rev(LL4, Args),rev(LL5, Args),rev(LL6, Args)], + FsLL6 = to_files(LLAll, Fmt, Config), + LL = rev(lists:sort(lists:append(LLAll)), Args), + ok = file_sorter:keymerge(1, FsLL6, Foo, Args), + LL = from_files(Foo, Fmt), + ok = file_sorter:keymerge(1, FsLL6, Foo, [{unique,true} | Args]), + LL = from_files(Foo, Fmt), + delete_files([Foo | FsLL6]), ok. @@ -963,84 +902,84 @@ funmerge(Fmt, XArgs, Config) -> UArgs = [{unique,true} | Args], Foo = outfile(foo, Config), - ?line EFs = to_files([[]], Fmt, Config), - ?line ok = file_sorter:merge(EFs, Foo, UArgs), - ?line [] = from_files(Foo, Fmt), + EFs = to_files([[]], Fmt, Config), + ok = file_sorter:merge(EFs, Foo, UArgs), + [] = from_files(Foo, Fmt), delete_files([Foo | EFs]), - ?line L11 = [{a,1,x4},{b,2,x4},{c,3,x4}], - ?line L21 = [{a,1,x3},{b,2,x3},{c,3,x3}], - ?line L31 = [{a,1,x2},{b,2,x2},{c,3,x2}], - ?line L41 = [{a,1,x1},{b,2,x1},{c,3,x1}], - ?line CAll = [L11, L21, L31, L41], - ?line CMerged1 = lists:merge(KComp, L11, L21), - ?line CMerged2 = lists:merge(KComp, L31, L41), - ?line CMerged = lists:merge(KComp, CMerged1, CMerged2), - ?line CFs1 = to_files(CAll, Fmt, Config), - ?line ok = file_sorter:merge(CFs1, Foo, Args), - ?line CMerged = from_files(Foo, Fmt), + L11 = [{a,1,x4},{b,2,x4},{c,3,x4}], + L21 = [{a,1,x3},{b,2,x3},{c,3,x3}], + L31 = [{a,1,x2},{b,2,x2},{c,3,x2}], + L41 = [{a,1,x1},{b,2,x1},{c,3,x1}], + CAll = [L11, L21, L31, L41], + CMerged1 = lists:merge(KComp, L11, L21), + CMerged2 = lists:merge(KComp, L31, L41), + CMerged = lists:merge(KComp, CMerged1, CMerged2), + CFs1 = to_files(CAll, Fmt, Config), + ok = file_sorter:merge(CFs1, Foo, Args), + CMerged = from_files(Foo, Fmt), Args4 = make_args(Fmt, [{size,50} | XArgs]), - ?line ok = file_sorter:merge(CFs1, Foo, [{order,KComp} | Args4]), - ?line CMerged = from_files(Foo, Fmt), - - ?line UMerged1 = lists:umerge(KComp, L11, L21), - ?line UMerged2 = lists:umerge(KComp, L31, L41), - ?line UMerged = lists:umerge(KComp, UMerged1, UMerged2), - ?line ok = file_sorter:merge(CFs1, Foo, [{order,KComp} | UArgs]), - ?line UMerged = from_files(Foo, Fmt), + ok = file_sorter:merge(CFs1, Foo, [{order,KComp} | Args4]), + CMerged = from_files(Foo, Fmt), + + UMerged1 = lists:umerge(KComp, L11, L21), + UMerged2 = lists:umerge(KComp, L31, L41), + UMerged = lists:umerge(KComp, UMerged1, UMerged2), + ok = file_sorter:merge(CFs1, Foo, [{order,KComp} | UArgs]), + UMerged = from_files(Foo, Fmt), UArgs2 = lists:keydelete(order, 1, make_args(Fmt, [{unique,true}, {size,50} | XArgs])), - ?line ok = file_sorter:merge(CFs1, Foo, [{order,KComp} | UArgs2]), - ?line UMerged = from_files(Foo, Fmt), - ?line delete_files(Foo), - - ?line List1 = [{a,1,x4},{b,2,x4},{c,3,x4}], - ?line List2 = [{a,3,x4},{b,4,x4},{c,5,x4}], - ?line List3 = [{a,5,x4},{b,6,x4},{c,7,x4}], - ?line FsLL = to_files([List1, List2, List3], Fmt, Config), - ?line ok = file_sorter:merge(FsLL, Foo, Args), - ?line List1_2 = lists:merge(KComp,lists:merge(KComp,List1,List2),List3), - ?line List1_2 = from_files(Foo, Fmt), - ?line ok = file_sorter:merge(FsLL, Foo, [{order,KComp} | UArgs]), - ?line UList1_2 = + ok = file_sorter:merge(CFs1, Foo, [{order,KComp} | UArgs2]), + UMerged = from_files(Foo, Fmt), + delete_files(Foo), + + List1 = [{a,1,x4},{b,2,x4},{c,3,x4}], + List2 = [{a,3,x4},{b,4,x4},{c,5,x4}], + List3 = [{a,5,x4},{b,6,x4},{c,7,x4}], + FsLL = to_files([List1, List2, List3], Fmt, Config), + ok = file_sorter:merge(FsLL, Foo, Args), + List1_2 = lists:merge(KComp,lists:merge(KComp,List1,List2),List3), + List1_2 = from_files(Foo, Fmt), + ok = file_sorter:merge(FsLL, Foo, [{order,KComp} | UArgs]), + UList1_2 = lists:umerge(KComp,lists:umerge(KComp, List1, List2),List3), - ?line UList1_2 = from_files(Foo, Fmt), - ?line delete_files([Foo | CFs1]), + UList1_2 = from_files(Foo, Fmt), + delete_files([Foo | CFs1]), fun() -> - ?line LL1 = [{d,4},{e,5},{f,6}], - ?line LL2 = [{a,1},{b,2},{c,3}], - ?line LL3 = [{j,10},{k,11},{l,12}], - ?line LL4 = [{g,7},{h,8},{i,9}], - ?line LL5 = [{p,16},{q,17},{r,18}], - ?line LL6 = [{m,13},{n,14},{o,15}], - ?line LLAll = [LL1,LL2,LL3,LL4,LL5,LL6], - ?line FsLL6 = to_files(LLAll, Fmt, Config), - ?line LL = lists:sort(lists:append(LLAll)), - ?line ok = file_sorter:merge(FsLL6, Foo, Args), - ?line LL = from_files(Foo, Fmt), - ?line ok = file_sorter:merge(FsLL6, Foo, UArgs), - ?line LL = from_files(Foo, Fmt), - ?line delete_files([Foo | FsLL6]) + LL1 = [{d,4},{e,5},{f,6}], + LL2 = [{a,1},{b,2},{c,3}], + LL3 = [{j,10},{k,11},{l,12}], + LL4 = [{g,7},{h,8},{i,9}], + LL5 = [{p,16},{q,17},{r,18}], + LL6 = [{m,13},{n,14},{o,15}], + LLAll = [LL1,LL2,LL3,LL4,LL5,LL6], + FsLL6 = to_files(LLAll, Fmt, Config), + LL = lists:sort(lists:append(LLAll)), + ok = file_sorter:merge(FsLL6, Foo, Args), + LL = from_files(Foo, Fmt), + ok = file_sorter:merge(FsLL6, Foo, UArgs), + LL = from_files(Foo, Fmt), + delete_files([Foo | FsLL6]) end(), fun() -> - ?line RLL1 = [{b,2},{h,8},{n,14}], - ?line RLL2 = [{a,1},{g,7},{m,13}], - ?line RLL3 = [{d,4},{j,10},{p,16}], - ?line RLL4 = [{c,3},{i,9},{o,15}], - ?line RLL5 = [{f,6},{l,12},{r,18}], - ?line RLL6 = [{e,5},{k,11},{q,17}], - ?line RLLAll = [RLL1,RLL2,RLL3,RLL4,RLL5,RLL6], - ?line RFsLL6 = to_files(RLLAll, Fmt, Config), - ?line RLL = lists:sort(lists:append(RLLAll)), - ?line ok = file_sorter:merge(RFsLL6, Foo, Args), - ?line RLL = from_files(Foo, Fmt), - ?line ok = file_sorter:merge(RFsLL6, Foo, UArgs), - ?line RLL = from_files(Foo, Fmt), - ?line delete_files([Foo | RFsLL6]) + RLL1 = [{b,2},{h,8},{n,14}], + RLL2 = [{a,1},{g,7},{m,13}], + RLL3 = [{d,4},{j,10},{p,16}], + RLL4 = [{c,3},{i,9},{o,15}], + RLL5 = [{f,6},{l,12},{r,18}], + RLL6 = [{e,5},{k,11},{q,17}], + RLLAll = [RLL1,RLL2,RLL3,RLL4,RLL5,RLL6], + RFsLL6 = to_files(RLLAll, Fmt, Config), + RLL = lists:sort(lists:append(RLLAll)), + ok = file_sorter:merge(RFsLL6, Foo, Args), + RLL = from_files(Foo, Fmt), + ok = file_sorter:merge(RFsLL6, Foo, UArgs), + RLL = from_files(Foo, Fmt), + delete_files([Foo | RFsLL6]) end(), ok. @@ -1054,57 +993,57 @@ check(Fmt, Config) -> L1 = [3,1,2,5,4], [F1_0] = Fs1 = to_files([L1], Fmt, Config), F1 = filename:absname(F1_0), - ?line {ok, [{F1,2,1}]} = file_sorter:check(Fs1, Args), - ?line {ok, [{F1,2,1}]} = file_sorter:check(Fs1, [{order,Fun} | Args]), - ?line {ok, [{F1,2,1}]} = file_sorter:check(Fs1, [{unique,true} | Args]), - ?line {ok, [{F1,2,1}]} = + {ok, [{F1,2,1}]} = file_sorter:check(Fs1, Args), + {ok, [{F1,2,1}]} = file_sorter:check(Fs1, [{order,Fun} | Args]), + {ok, [{F1,2,1}]} = file_sorter:check(Fs1, [{unique,true} | Args]), + {ok, [{F1,2,1}]} = file_sorter:check(Fs1, [{order,Fun},{unique,true} | Args]), - ?line {ok, [{F1,3,2}]} = + {ok, [{F1,3,2}]} = file_sorter:check(Fs1, [{order,descending} | Args]), - ?line {ok, [{F1,3,2}]} = + {ok, [{F1,3,2}]} = file_sorter:check(Fs1, [{unique,true},{order,descending} | Args]), - ?line delete_files(Fs1), - + delete_files(Fs1), + L2 = [[1,2,2,3,3,4,5,5],[5,5,4,3,3,2,2,1]], [F2_0,F3_0] = Fs2 = to_files(L2, Fmt, Config), F2 = filename:absname(F2_0), F3 = filename:absname(F3_0), - ?line {ok, [{F3,3,4}]} = file_sorter:check(Fs2, Args), - ?line {ok, [{F3,3,4}]} = file_sorter:check(Fs2, [{order,Fun} | Args]), - ?line {ok, [{F2,3,2},{F3,2,5}]} = + {ok, [{F3,3,4}]} = file_sorter:check(Fs2, Args), + {ok, [{F3,3,4}]} = file_sorter:check(Fs2, [{order,Fun} | Args]), + {ok, [{F2,3,2},{F3,2,5}]} = file_sorter:check(Fs2, [{unique, true} | Args]), - ?line {ok, [{F2,3,2},{F3,2,5}]} = + {ok, [{F2,3,2},{F3,2,5}]} = file_sorter:check(Fs2, [{order,Fun},{unique, true} | Args]), - ?line {ok, [{F2,2,2}]} = + {ok, [{F2,2,2}]} = file_sorter:check(Fs2, [{order,descending} | Args]), - ?line {ok, [{F2,2,2},{F3,2,5}]} = + {ok, [{F2,2,2},{F3,2,5}]} = file_sorter:check(Fs2, [{unique,true},{order,descending} | Args]), - ?line delete_files(Fs2), - + delete_files(Fs2), + L3 = [1,2,3,4], - ?line Fs3 = to_files([L3], Fmt, Config), - ?line {ok, []} = file_sorter:check(Fs3, [{unique,true} | Args]), - ?line {ok, []} = + Fs3 = to_files([L3], Fmt, Config), + {ok, []} = file_sorter:check(Fs3, [{unique,true} | Args]), + {ok, []} = file_sorter:check(Fs3, [{unique,true},{order,Fun} | Args]), - ?line delete_files(Fs3), + delete_files(Fs3), %% big objects - ?line T1 = erlang:make_tuple(10000,foo), - ?line T2 = erlang:make_tuple(10000,bar), - ?line L4 = [T1,T2], - ?line [FF_0] = Fs4 = to_files([L4], Fmt, Config), + T1 = erlang:make_tuple(10000,foo), + T2 = erlang:make_tuple(10000,bar), + L4 = [T1,T2], + [FF_0] = Fs4 = to_files([L4], Fmt, Config), FF = filename:absname(FF_0), - ?line {ok, [{FF,2,T2}]} = file_sorter:check(Fs4, [{unique,true} | Args]), - ?line delete_files(Fs4), + {ok, [{FF,2,T2}]} = file_sorter:check(Fs4, [{unique,true} | Args]), + delete_files(Fs4), CFun = key_compare(2), L10 = [[{1,a},{2,b},T10_1={1,b},{3,c}], [{1,b},T10_2={2,a}]], [F10_0,F11_0] = Fs10 = to_files(L10, Fmt, Config), F10_1 = filename:absname(F10_0), F11_1 = filename:absname(F11_0), - ?line {ok, [{F10_1,3,T10_1},{F11_1,2,T10_2}]} = + {ok, [{F10_1,3,T10_1},{F11_1,2,T10_2}]} = file_sorter:check(Fs10, [{unique,true},{order,CFun} | Args]), - ?line delete_files(Fs10), + delete_files(Fs10), ok. @@ -1112,31 +1051,31 @@ keycheck(Fmt, Config) -> Args0 = make_args(Fmt, [{size,5}]), Args = Args0 ++ [{tmpdir,?privdir(Config)}], - ?line L1 = [[{a,1},{b,2}], [{c,2},{b,1},{a,3}]], - ?line [F1_0,F2_0] = Fs1 = to_files(L1, Fmt, Config), + L1 = [[{a,1},{b,2}], [{c,2},{b,1},{a,3}]], + [F1_0,F2_0] = Fs1 = to_files(L1, Fmt, Config), F1 = filename:absname(F1_0), F2 = filename:absname(F2_0), - ?line {ok, [{F2,2,{b,1}}]} = file_sorter:keycheck(1, Fs1, Args), - ?line {ok, [{F2,2,{b,1}}]} = + {ok, [{F2,2,{b,1}}]} = file_sorter:keycheck(1, Fs1, Args), + {ok, [{F2,2,{b,1}}]} = file_sorter:keycheck(1, Fs1, [{unique,true} | Args]), - ?line {ok, [{F1,2,{b,2}}]} = + {ok, [{F1,2,{b,2}}]} = file_sorter:keycheck(1, Fs1, [{order,descending},{unique,true} | Args]), - ?line delete_files(Fs1), - + delete_files(Fs1), + L2 = [[{a,1},{a,2},{a,2},{b,2}], [{c,2},{b,1},{b,2},{b,2},{a,3}]], - ?line [F3_0,F4_0] = Fs2 = to_files(L2, Fmt, Config), + [F3_0,F4_0] = Fs2 = to_files(L2, Fmt, Config), F3 = filename:absname(F3_0), F4 = filename:absname(F4_0), - ?line {ok, [{F4,2,{b,1}}]} = file_sorter:keycheck(1, Fs2, Args), - ?line {ok, [{F3,2,{a,2}},{F4,2,{b,1}}]} = + {ok, [{F4,2,{b,1}}]} = file_sorter:keycheck(1, Fs2, Args), + {ok, [{F3,2,{a,2}},{F4,2,{b,1}}]} = file_sorter:keycheck(1, Fs2, [{unique,true} | Args]), - ?line {ok, [{F3,4,{b,2}}]} = + {ok, [{F3,4,{b,2}}]} = file_sorter:keycheck(1, Fs2, [{order,descending} | Args]), - ?line {ok, [{F3,2,{a,2}},{F4,3,{b,2}}]} = + {ok, [{F3,2,{a,2}},{F4,3,{b,2}}]} = file_sorter:keycheck(1, Fs2, [{order,descending},{unique,true} | Args]), - ?line delete_files(Fs2), - + delete_files(Fs2), + ok. rev(L, Args) -> @@ -1330,9 +1269,9 @@ c(Fd, Bin0, Size0, NoBytes, HL, L) -> eof when Size0 =:= 0 -> lists:reverse(L); eof -> - test_server:fail({error, premature_eof}); + ct:fail({error, premature_eof}); Error -> - test_server:fail(Error) + ct:fail(Error) end. c1(Fd, B, BinSize, HL, L) -> @@ -1347,7 +1286,7 @@ c1(Fd, B, BinSize, HL, L) -> <<BinTerm:Size/binary, R/binary>> = Bin, E = case catch binary_to_term(BinTerm) of {'EXIT', _} -> - test_server:fail({error, bad_object}); + ct:fail({error, bad_object}); Term -> Term end, diff --git a/lib/stdlib/test/filelib_SUITE.erl b/lib/stdlib/test/filelib_SUITE.erl index 5d5434c7b2..16616a3207 100644 --- a/lib/stdlib/test/filelib_SUITE.erl +++ b/lib/stdlib/test/filelib_SUITE.erl @@ -33,15 +33,14 @@ -include_lib("kernel/include/file.hrl"). init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?t:minutes(5)), - [{watchdog,Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,5}}]. all() -> [wildcard_one, wildcard_two, wildcard_errors, @@ -65,14 +64,14 @@ end_per_group(_GroupName, Config) -> wildcard_one(Config) when is_list(Config) -> - ?line {ok,OldCwd} = file:get_cwd(), - ?line Dir = filename:join(?config(priv_dir, Config), "wildcard_one"), - ?line ok = file:make_dir(Dir), + {ok,OldCwd} = file:get_cwd(), + Dir = filename:join(proplists:get_value(priv_dir, Config), "wildcard_one"), + ok = file:make_dir(Dir), do_wildcard_1(Dir, fun(Wc) -> filelib:wildcard(Wc, Dir, erl_prim_loader) end), - ?line file:set_cwd(Dir), + file:set_cwd(Dir), do_wildcard_1(Dir, fun(Wc) -> L = filelib:wildcard(Wc), @@ -81,30 +80,30 @@ wildcard_one(Config) when is_list(Config) -> L = filelib:wildcard(Wc, Dir), L = filelib:wildcard(Wc, Dir++"/.") end), - ?line file:set_cwd(OldCwd), - ?line ok = file:del_dir(Dir), + file:set_cwd(OldCwd), + ok = file:del_dir(Dir), ok. wildcard_two(Config) when is_list(Config) -> - ?line Dir = filename:join(?config(priv_dir, Config), "wildcard_two"), - ?line ok = file:make_dir(Dir), - ?line do_wildcard_1(Dir, fun(Wc) -> io:format("~p~n",[{Wc,Dir, X = filelib:wildcard(Wc, Dir)}]),X end), - ?line do_wildcard_1(Dir, fun(Wc) -> filelib:wildcard(Wc, Dir++"/") end), - ?line do_wildcard_1(Dir, fun(Wc) -> filelib:wildcard(Wc, Dir++"/.") end), + Dir = filename:join(proplists:get_value(priv_dir, Config), "wildcard_two"), + ok = file:make_dir(Dir), + do_wildcard_1(Dir, fun(Wc) -> io:format("~p~n",[{Wc,Dir, X = filelib:wildcard(Wc, Dir)}]),X end), + do_wildcard_1(Dir, fun(Wc) -> filelib:wildcard(Wc, Dir++"/") end), + do_wildcard_1(Dir, fun(Wc) -> filelib:wildcard(Wc, Dir++"/.") end), case os:type() of {win32,_} -> ok; _ -> - ?line do_wildcard_1(Dir, fun(Wc) -> filelib:wildcard(Wc, "//"++Dir) end) + do_wildcard_1(Dir, fun(Wc) -> filelib:wildcard(Wc, "//"++Dir) end) end, - ?line ok = file:del_dir(Dir), + ok = file:del_dir(Dir), ok. wildcard_errors(Config) when is_list(Config) -> - ?line wcc("{", missing_delimiter), - ?line wcc("{a", missing_delimiter), - ?line wcc("{a,", missing_delimiter), - ?line wcc("{a,b", missing_delimiter), + wcc("{", missing_delimiter), + wcc("{a", missing_delimiter), + wcc("{a,", missing_delimiter), + wcc("{a,b", missing_delimiter), ok. wcc(Wc, Error) -> @@ -131,70 +130,70 @@ subtract_dir("/"++Cs, []) -> Cs. do_wildcard_2(Dir, Wcf) -> %% Basic wildcards. All = ["abc","abcdef","glurf"], - ?line Files = mkfiles(lists:reverse(All), Dir), - ?line All = Wcf("*"), - ?line ["abc","abcdef"] = Wcf("a*"), - ?line ["abc","abcdef"] = Wcf("abc*"), - ?line ["abcdef"] = Wcf("abc???"), - ?line ["abcdef"] = Wcf("abcd*"), - ?line ["abcdef"] = Wcf("*def"), - ?line ["abcdef","glurf"] = Wcf("{*def,gl*}"), - ?line ["abc","abcdef"] = Wcf("a*{def,}"), - ?line ["abc","abcdef"] = Wcf("a*{,def}"), + Files = mkfiles(lists:reverse(All), Dir), + All = Wcf("*"), + ["abc","abcdef"] = Wcf("a*"), + ["abc","abcdef"] = Wcf("abc*"), + ["abcdef"] = Wcf("abc???"), + ["abcdef"] = Wcf("abcd*"), + ["abcdef"] = Wcf("*def"), + ["abcdef","glurf"] = Wcf("{*def,gl*}"), + ["abc","abcdef"] = Wcf("a*{def,}"), + ["abc","abcdef"] = Wcf("a*{,def}"), %% Constant wildcard. ["abcdef"] = Wcf("abcdef"), %% Negative tests. - ?line [] = Wcf("b*"), - ?line [] = Wcf("bufflig"), + [] = Wcf("b*"), + [] = Wcf("bufflig"), - ?line del(Files), + del(Files), do_wildcard_3(Dir, Wcf). - + do_wildcard_3(Dir, Wcf) -> %% Some character sets. All = ["a01","a02","a03","b00","c02","d19"], - ?line Files = mkfiles(lists:reverse(All), Dir), - ?line All = Wcf("[a-z]*"), - ?line All = Wcf("[a-d]*"), - ?line All = Wcf("[adbc]*"), - ?line All = Wcf("?[0-9][0-9]"), - ?line All = Wcf("?[0-1][0-39]"), - ?line All = Wcf("[abcdefgh][10][01239]"), - ?line ["a01","a02","a03","b00","c02"] = Wcf("[a-z]0[0-3]"), - ?line [] = Wcf("?[a-z][0-39]"), - ?line del(Files), + Files = mkfiles(lists:reverse(All), Dir), + All = Wcf("[a-z]*"), + All = Wcf("[a-d]*"), + All = Wcf("[adbc]*"), + All = Wcf("?[0-9][0-9]"), + All = Wcf("?[0-1][0-39]"), + All = Wcf("[abcdefgh][10][01239]"), + ["a01","a02","a03","b00","c02"] = Wcf("[a-z]0[0-3]"), + [] = Wcf("?[a-z][0-39]"), + del(Files), do_wildcard_4(Dir, Wcf). do_wildcard_4(Dir, Wcf) -> %% More character sets: tricky characters. All = ["a-","aA","aB","aC","a[","a]"], - ?line Files = mkfiles(lists:reverse(All), Dir), - ?line All = Wcf("a[][A-C-]"), + Files = mkfiles(lists:reverse(All), Dir), + All = Wcf("a[][A-C-]"), ["a-"] = Wcf("a[-]"), ["a["] = Wcf("a["), - ?line del(Files), + del(Files), do_wildcard_5(Dir, Wcf). do_wildcard_5(Dir, Wcf) -> Dirs = ["xa","blurf","yyy"], - ?line foreach(fun(D) -> ok = file:make_dir(filename:join(Dir, D)) end, Dirs), + foreach(fun(D) -> ok = file:make_dir(filename:join(Dir, D)) end, Dirs), All = ["blurf/nisse","xa/arne","xa/kalle","yyy/arne"], - ?line Files = mkfiles(lists:reverse(All), Dir), + Files = mkfiles(lists:reverse(All), Dir), %% Test. - ?line All = Wcf("*/*"), - ?line ["blurf/nisse","xa/arne","xa/kalle"] = Wcf("{blurf,xa}/*"), - ?line ["xa/arne","yyy/arne"] = Wcf("*/arne"), - ?line ["blurf/nisse"] = Wcf("*/nisse"), - ?line [] = Wcf("mountain/*"), - ?line [] = Wcf("xa/gurka"), + All = Wcf("*/*"), + ["blurf/nisse","xa/arne","xa/kalle"] = Wcf("{blurf,xa}/*"), + ["xa/arne","yyy/arne"] = Wcf("*/arne"), + ["blurf/nisse"] = Wcf("*/nisse"), + [] = Wcf("mountain/*"), + [] = Wcf("xa/gurka"), ["blurf/nisse"] = Wcf("blurf/nisse"), %% Cleanup - ?line del(Files), - ?line foreach(fun(D) -> ok = file:del_dir(filename:join(Dir, D)) end, Dirs), + del(Files), + foreach(fun(D) -> ok = file:del_dir(filename:join(Dir, D)) end, Dirs), do_wildcard_6(Dir, Wcf). do_wildcard_6(Dir, Wcf) -> @@ -271,45 +270,45 @@ do_wildcard_9(Dir, Wcf) -> fold_files(Config) when is_list(Config) -> - ?line Dir = filename:join(?config(priv_dir, Config), "fold_files"), - ?line ok = file:make_dir(Dir), - ?line Dirs = [filename:join(Dir, D) || D <- ["blurf","blurf/blarf"]], - ?line foreach(fun(D) -> ok = file:make_dir(D) end, Dirs), + Dir = filename:join(proplists:get_value(priv_dir, Config), "fold_files"), + ok = file:make_dir(Dir), + Dirs = [filename:join(Dir, D) || D <- ["blurf","blurf/blarf"]], + foreach(fun(D) -> ok = file:make_dir(D) end, Dirs), All = ["fb.txt","ko.txt", "blurf/nisse.text","blurf/blarf/aaa.txt","blurf/blarf/urfa.txt"], - ?line Files = mkfiles(lists:reverse(All), Dir), + Files = mkfiles(lists:reverse(All), Dir), %% Test. - ?line Files0 = filelib:fold_files(Dir, "^", false, - fun(H, T) -> [H|T] end, []), - ?line same_lists(["fb.txt","ko.txt"], Files0, Dir), + Files0 = filelib:fold_files(Dir, "^", false, + fun(H, T) -> [H|T] end, []), + same_lists(["fb.txt","ko.txt"], Files0, Dir), - ?line Files1 = filelib:fold_files(Dir, "^", true, - fun(H, T) -> [H|T] end, []), - ?line same_lists(All, Files1, Dir), + Files1 = filelib:fold_files(Dir, "^", true, + fun(H, T) -> [H|T] end, []), + same_lists(All, Files1, Dir), - ?line Files2 = filelib:fold_files(Dir, "[.]text$", true, - fun(H, T) -> [H|T] end, []), - ?line same_lists(["blurf/nisse.text"], Files2, Dir), + Files2 = filelib:fold_files(Dir, "[.]text$", true, + fun(H, T) -> [H|T] end, []), + same_lists(["blurf/nisse.text"], Files2, Dir), - ?line Files3 = filelib:fold_files(Dir, "^..[.]", true, - fun(H, T) -> [H|T] end, []), - ?line same_lists(["fb.txt","ko.txt"], Files3, Dir), + Files3 = filelib:fold_files(Dir, "^..[.]", true, + fun(H, T) -> [H|T] end, []), + same_lists(["fb.txt","ko.txt"], Files3, Dir), - ?line Files4 = filelib:fold_files(Dir, "^ko[.]txt$", true, - fun(H, T) -> [H|T] end, []), - ?line same_lists(["ko.txt"], Files4, Dir), - ?line Files4 = filelib:fold_files(Dir, "^ko[.]txt$", false, - fun(H, T) -> [H|T] end, []), + Files4 = filelib:fold_files(Dir, "^ko[.]txt$", true, + fun(H, T) -> [H|T] end, []), + same_lists(["ko.txt"], Files4, Dir), + Files4 = filelib:fold_files(Dir, "^ko[.]txt$", false, + fun(H, T) -> [H|T] end, []), - ?line [] = filelib:fold_files(Dir, "^$", true, - fun(H, T) -> [H|T] end, []), + [] = filelib:fold_files(Dir, "^$", true, + fun(H, T) -> [H|T] end, []), %% Cleanup - ?line del(Files), - ?line foreach(fun(D) -> ok = file:del_dir(D) end, lists:reverse(Dirs)), - ?line ok = file:del_dir(Dir). + del(Files), + foreach(fun(D) -> ok = file:del_dir(D) end, lists:reverse(Dirs)), + ok = file:del_dir(Dir). same_lists(Expected0, Actual0, BaseDir) -> Expected = [filename:absname(N, BaseDir) || N <- lists:sort(Expected0)], @@ -328,52 +327,49 @@ del([H|T]) -> del(T); del([]) -> ok. -otp_5960(suite) -> - []; -otp_5960(doc) -> - ["Test that filelib:ensure_dir/1 returns ok or {error,Reason}"]; +%% Test that filelib:ensure_dir/1 returns ok or {error,Reason}. otp_5960(Config) when is_list(Config) -> - ?line PrivDir = ?config(priv_dir, Config), - ?line Dir = filename:join(PrivDir, "otp_5960_dir"), - ?line Name1 = filename:join(Dir, name1), - ?line Name2 = filename:join(Dir, name2), - ?line ok = filelib:ensure_dir(Name1), % parent is created - ?line ok = filelib:ensure_dir(Name1), % repeating it should be OK - ?line ok = filelib:ensure_dir(Name2), % parent already exists - ?line ok = filelib:ensure_dir(Name2), % repeating it should be OK - ?line Name3 = filename:join(Name1, name3), - ?line {ok, FileInfo} = file:read_file_info(Dir), + PrivDir = proplists:get_value(priv_dir, Config), + Dir = filename:join(PrivDir, "otp_5960_dir"), + Name1 = filename:join(Dir, name1), + Name2 = filename:join(Dir, name2), + ok = filelib:ensure_dir(Name1), % parent is created + ok = filelib:ensure_dir(Name1), % repeating it should be OK + ok = filelib:ensure_dir(Name2), % parent already exists + ok = filelib:ensure_dir(Name2), % repeating it should be OK + Name3 = filename:join(Name1, name3), + {ok, FileInfo} = file:read_file_info(Dir), case os:type() of {win32,_} -> %% Not possibly to write protect directories on Windows %% (at least not using file:write_file_info/2). ok; _ -> - ?line Mode = FileInfo#file_info.mode, - ?line NoWriteMode = Mode - 8#00200 - 8#00020 - 8#00002, - ?line ok = file:write_file_info(Dir, #file_info{mode=NoWriteMode}), - ?line {error, _} = filelib:ensure_dir(Name3), - ?line ok = file:write_file_info(Dir, #file_info{mode=Mode}), + Mode = FileInfo#file_info.mode, + NoWriteMode = Mode - 8#00200 - 8#00020 - 8#00002, + ok = file:write_file_info(Dir, #file_info{mode=NoWriteMode}), + {error, _} = filelib:ensure_dir(Name3), + ok = file:write_file_info(Dir, #file_info{mode=Mode}), ok end. ensure_dir_eexist(Config) when is_list(Config) -> - ?line PrivDir = ?config(priv_dir, Config), - ?line Dir = filename:join(PrivDir, "ensure_dir_eexist"), - ?line Name = filename:join(Dir, "same_name_as_file_and_dir"), - ?line ok = filelib:ensure_dir(Name), - ?line ok = file:write_file(Name, <<"some string\n">>), + PrivDir = proplists:get_value(priv_dir, Config), + Dir = filename:join(PrivDir, "ensure_dir_eexist"), + Name = filename:join(Dir, "same_name_as_file_and_dir"), + ok = filelib:ensure_dir(Name), + ok = file:write_file(Name, <<"some string\n">>), %% There already is a file with the name of the directory %% we want to create. - ?line NeedFile = filename:join(Name, "file"), - ?line NeedFileB = filename:join(Name, <<"file">>), - ?line {error, eexist} = filelib:ensure_dir(NeedFile), - ?line {error, eexist} = filelib:ensure_dir(NeedFileB), + NeedFile = filename:join(Name, "file"), + NeedFileB = filename:join(Name, <<"file">>), + {error, eexist} = filelib:ensure_dir(NeedFile), + {error, eexist} = filelib:ensure_dir(NeedFileB), ok. ensure_dir_symlink(Config) when is_list(Config) -> - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), Dir = filename:join(PrivDir, "ensure_dir_symlink"), Name = filename:join(Dir, "same_name_as_file_and_dir"), ok = filelib:ensure_dir(Name), @@ -392,7 +388,7 @@ ensure_dir_symlink(Config) when is_list(Config) -> end. wildcard_symlink(Config) when is_list(Config) -> - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), Dir = filename:join(PrivDir, ?MODULE_STRING++"_wildcard_symlink"), SubDir = filename:join(Dir, "sub"), AFile = filename:join(SubDir, "a_file"), @@ -452,7 +448,7 @@ basenames(Dir, Files) -> end || F <- Files]. is_file_symlink(Config) -> - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), Dir = filename:join(PrivDir, ?MODULE_STRING++"_is_file_symlink"), SubDir = filename:join(Dir, "sub"), AFile = filename:join(SubDir, "a_file"), @@ -485,7 +481,7 @@ is_file_symlink(Config) -> end. file_props_symlink(Config) -> - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), Dir = filename:join(PrivDir, ?MODULE_STRING++"_file_props_symlink"), AFile = filename:join(Dir, "a_file"), Alias = filename:join(Dir, "symlink"), diff --git a/lib/stdlib/test/filename_SUITE.erl b/lib/stdlib/test/filename_SUITE.erl index 7f2e4771f3..3d6734b790 100644 --- a/lib/stdlib/test/filename_SUITE.erl +++ b/lib/stdlib/test/filename_SUITE.erl @@ -32,7 +32,9 @@ -include_lib("common_test/include/ct.hrl"). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [absname, absname_2, @@ -70,7 +72,7 @@ end_per_group(_GroupName, Config) -> absname(Config) when is_list(Config) -> case os:type() of {win32, _} -> - [Drive|_] = ?config(priv_dir, Config), + [Drive|_] = proplists:get_value(priv_dir, Config), Temp = filename:join([Drive|":/"], "temp"), case file:make_dir(Temp) of ok -> ok; @@ -130,7 +132,7 @@ absname(Config) when is_list(Config) -> absname_2(Config) when is_list(Config) -> case os:type() of {win32, _} -> - [Drive|_] = ?config(priv_dir, Config), + [Drive|_] = proplists:get_value(priv_dir, Config), [Drive|":/temp/foo"] = filename:absname(foo, [Drive|":/temp"]), [Drive|":/temp/foo"] = filename:absname("foo", [Drive|":/temp"]), [Drive|":/temp/../ebin"] = filename:absname("../ebin", @@ -181,7 +183,6 @@ absname_2(Config) when is_list(Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% basename_1(Config) when is_list(Config) -> - Dog = test_server:timetrap(test_server:seconds(10)), "." = filename:basename("."), "foo" = filename:basename("foo"), "foo" = filename:basename("/usr/foo"), @@ -202,11 +203,9 @@ basename_1(Config) when is_list(Config) -> "strange\\but\\true" = filename:basename("strange\\but\\true") end, - test_server:timetrap_cancel(Dog), ok. basename_2(Config) when is_list(Config) -> - Dog = test_server:timetrap(test_server:seconds(10)), "." = filename:basename(".", ".erl"), "foo" = filename:basename("foo.erl", ".erl"), "foo" = filename:basename('foo.erl', ".erl"), @@ -232,7 +231,6 @@ basename_2(Config) when is_list(Config) -> "strange\\but\\true" = filename:basename("strange\\but\\true", ".erl") end, - test_server:timetrap_cancel(Dog), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -431,7 +429,7 @@ find_src(Config) when is_list(Config) -> %% Make sure that find_src works for a slim BEAM file. OldPath = code:get_path(), try - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), code:add_patha(PrivDir), Src = "simple", SrcPath = filename:join(PrivDir, Src) ++ ".erl", @@ -454,7 +452,7 @@ find_src(Config) when is_list(Config) -> absname_bin(Config) when is_list(Config) -> case os:type() of {win32, _} -> - [Drive|_] = ?config(priv_dir, Config), + [Drive|_] = proplists:get_value(priv_dir, Config), Temp = filename:join([Drive|":/"], "temp"), case file:make_dir(Temp) of ok -> ok; @@ -506,7 +504,7 @@ absname_bin(Config) when is_list(Config) -> absname_bin_2(Config) when is_list(Config) -> case os:type() of {win32, _} -> - [Drive|_] = ?config(priv_dir, Config), + [Drive|_] = proplists:get_value(priv_dir, Config), <<Drive:8,":/temp/foo">> = filename:absname(<<"foo">>, <<Drive:8,":/temp">>), <<Drive:8,":/temp/../ebin">> = filename:absname(<<"../ebin">>, <<Drive:8,":/temp">>), @@ -553,7 +551,6 @@ absname_bin_2(Config) when is_list(Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% basename_bin_1(Config) when is_list(Config) -> - Dog = test_server:timetrap(test_server:seconds(10)), <<".">> = filename:basename(<<".">>), <<"foo">> = filename:basename(<<"foo">>), <<"foo">> = filename:basename(<<"/usr/foo">>), @@ -565,11 +562,9 @@ basename_bin_1(Config) when is_list(Config) -> _ -> <<"strange\\but\\true">> = filename:basename(<<"strange\\but\\true">>) end, - test_server:timetrap_cancel(Dog), ok. basename_bin_2(Config) when is_list(Config) -> - Dog = test_server:timetrap(test_server:seconds(10)), <<".">> = filename:basename(<<".">>, <<".erl">>), <<"foo">> = filename:basename(<<"foo.erl">>, <<".erl">>), <<"foo.erl">> = filename:basename(<<"/usr/foo.erl">>, <<".hrl">>), @@ -589,7 +584,6 @@ basename_bin_2(Config) when is_list(Config) -> <<"strange\\but\\true">> = filename:basename(<<"strange\\but\\true">>, <<".erl">>) end, - test_server:timetrap_cancel(Dog), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/lib/stdlib/test/fixtable_SUITE.erl b/lib/stdlib/test/fixtable_SUITE.erl index 66150e60c1..de100a11d6 100644 --- a/lib/stdlib/test/fixtable_SUITE.erl +++ b/lib/stdlib/test/fixtable_SUITE.erl @@ -33,7 +33,9 @@ %%% Internal exports -export([command_loop/0,start_commander/0]). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [multiple_fixes, multiple_processes, @@ -68,14 +70,11 @@ end_per_group(_GroupName, Config) -> -define(HELPER_NODE, (atom_to_list(?MODULE) ++ "_helper1")). init_per_testcase(_Func, Config) -> - PrivDir = ?config(priv_dir,Config), + PrivDir = proplists:get_value(priv_dir,Config), file:make_dir(PrivDir), - Dog=test_server:timetrap(test_server:seconds(60)), - [{watchdog, Dog}|Config]. + Config. end_per_testcase(_Func, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), lists:foreach(fun(X) -> (catch dets:close(X)), (catch file:delete(dets_filename(X,Config))) @@ -98,302 +97,280 @@ show(Term, Line) -> -endif. -fixbag(doc) -> - ["Check for bug OTP-5087, safe_fixtable for bags could give " - "incorrect lookups"]; -fixbag(suite) -> - []; +%% Check for bug OTP-5087; safe_fixtable for bags could give incorrect +%% lookups. fixbag(Config) when is_list(Config) -> - ?line T = ets:new(x,[bag]), - ?line ets:insert(T,{a,1}), - ?line ets:insert(T,{a,2}), - ?line ets:safe_fixtable(T,true), - ?line ets:match_delete(T,{a,2}), - ?line ets:insert(T,{a,3}), - ?line Res = ets:lookup(T,a), - ?line ets:safe_fixtable(T,false), - ?line Res = ets:lookup(T,a), + T = ets:new(x,[bag]), + ets:insert(T,{a,1}), + ets:insert(T,{a,2}), + ets:safe_fixtable(T,true), + ets:match_delete(T,{a,2}), + ets:insert(T,{a,3}), + Res = ets:lookup(T,a), + ets:safe_fixtable(T,false), + Res = ets:lookup(T,a), ok. -insert_same_key(doc) -> - ["Check correct behaviour if a key is deleted and reinserted during fixation."]; -insert_same_key(suite) -> - []; +%% Check correct behaviour if a key is deleted and reinserted during +%% fixation. insert_same_key(Config) when is_list(Config) -> - ?line {ok,Dets1} = dets:open_file(?DETS_TMP1, - [{file, dets_filename(?DETS_TMP1,Config)}]), - ?line Ets1 = ets:new(ets,[]), - ?line insert_same_key(Dets1,dets,Config), - ?line insert_same_key(Ets1,ets,Config), - ?line ets:insert(Ets1,{1,2}), - ?line 1 = ets:info(Ets1,size), - ?line dets:insert(Dets1,{1,2}), - ?line 1 = dets:info(Dets1,size), - ?line dets:close(Dets1), - ?line (catch file:delete(dets_filename(Dets1,Config))), - ?line ets:delete(Ets1), - ?line {ok,Dets2} = dets:open_file(?DETS_TMP1, - [{type,bag},{file, dets_filename(?DETS_TMP1,Config)}]), - ?line Ets2 = ets:new(ets,[bag]), - ?line insert_same_key(Dets2,dets,Config), - ?line insert_same_key(Ets2,ets,Config), - ?line ets:insert(Ets2,{1,2}), - ?line 2 = ets:info(Ets2,size), - ?line ets:insert(Ets2,{1,2}), - ?line 2 = ets:info(Ets2,size), - ?line dets:insert(Dets2,{1,2}), - ?line 2 = dets:info(Dets2,size), - ?line dets:insert(Dets2,{1,2}), - ?line 2 = dets:info(Dets2,size), - ?line dets:close(Dets2), - ?line (catch file:delete(dets_filename(Dets2,Config))), - ?line ets:delete(Ets2), - ?line {ok,Dets3} = dets:open_file(?DETS_TMP1, - [{type,duplicate_bag}, - {file, dets_filename(?DETS_TMP1,Config)}]), - ?line Ets3 = ets:new(ets,[duplicate_bag]), - ?line insert_same_key(Dets3,dets,Config), - ?line insert_same_key(Ets3,ets,Config), - ?line ets:insert(Ets3,{1,2}), - ?line 2 = ets:info(Ets3,size), - ?line ets:insert(Ets3,{1,2}), - ?line 3 = ets:info(Ets3,size), - ?line dets:insert(Dets3,{1,2}), - ?line 2 = dets:info(Dets3,size), - ?line dets:insert(Dets3,{1,2}), - ?line 3 = dets:info(Dets3,size), - ?line dets:close(Dets3), - ?line (catch file:delete(dets_filename(Dets3,Config))), - ?line ets:delete(Ets3), + {ok,Dets1} = dets:open_file(?DETS_TMP1, + [{file, dets_filename(?DETS_TMP1,Config)}]), + Ets1 = ets:new(ets,[]), + insert_same_key(Dets1,dets,Config), + insert_same_key(Ets1,ets,Config), + ets:insert(Ets1,{1,2}), + 1 = ets:info(Ets1,size), + dets:insert(Dets1,{1,2}), + 1 = dets:info(Dets1,size), + dets:close(Dets1), + (catch file:delete(dets_filename(Dets1,Config))), + ets:delete(Ets1), + {ok,Dets2} = dets:open_file(?DETS_TMP1, + [{type,bag},{file, dets_filename(?DETS_TMP1,Config)}]), + Ets2 = ets:new(ets,[bag]), + insert_same_key(Dets2,dets,Config), + insert_same_key(Ets2,ets,Config), + ets:insert(Ets2,{1,2}), + 2 = ets:info(Ets2,size), + ets:insert(Ets2,{1,2}), + 2 = ets:info(Ets2,size), + dets:insert(Dets2,{1,2}), + 2 = dets:info(Dets2,size), + dets:insert(Dets2,{1,2}), + 2 = dets:info(Dets2,size), + dets:close(Dets2), + (catch file:delete(dets_filename(Dets2,Config))), + ets:delete(Ets2), + {ok,Dets3} = dets:open_file(?DETS_TMP1, + [{type,duplicate_bag}, + {file, dets_filename(?DETS_TMP1,Config)}]), + Ets3 = ets:new(ets,[duplicate_bag]), + insert_same_key(Dets3,dets,Config), + insert_same_key(Ets3,ets,Config), + ets:insert(Ets3,{1,2}), + 2 = ets:info(Ets3,size), + ets:insert(Ets3,{1,2}), + 3 = ets:info(Ets3,size), + dets:insert(Dets3,{1,2}), + 2 = dets:info(Dets3,size), + dets:insert(Dets3,{1,2}), + 3 = dets:info(Dets3,size), + dets:close(Dets3), + (catch file:delete(dets_filename(Dets3,Config))), + ets:delete(Ets3), ok. insert_same_key(Tab,Mod,_Config) -> - ?line Mod:insert(Tab,{1,1}), - ?line Mod:insert(Tab,{1,2}), - ?line Mod:insert(Tab,{2,2}), - ?line Mod:insert(Tab,{2,2}), - ?line Mod:safe_fixtable(Tab,true), - ?line Mod:delete(Tab,1), - ?line Mod:insert(Tab,{1,1}), - ?line Expect = case Mod:info(Tab,type) of - bag -> - Mod:insert(Tab,{1,2}), - 2; - _ -> - 1 - end, - ?line Mod:delete(Tab,2), - ?line Mod:safe_fixtable(Tab,false), - ?line case Mod:info(Tab,size) of - Expect -> - ok; - _ -> - exit({size_field_wrong,{Mod,Mod:info(Tab)}}) - end. - - - - -owner_dies(doc) -> - ["Check correct behaviour if the table owner dies."]; -owner_dies(suite) -> - []; + Mod:insert(Tab,{1,1}), + Mod:insert(Tab,{1,2}), + Mod:insert(Tab,{2,2}), + Mod:insert(Tab,{2,2}), + Mod:safe_fixtable(Tab,true), + Mod:delete(Tab,1), + Mod:insert(Tab,{1,1}), + Expect = case Mod:info(Tab,type) of + bag -> + Mod:insert(Tab,{1,2}), + 2; + _ -> + 1 + end, + Mod:delete(Tab,2), + Mod:safe_fixtable(Tab,false), + case Mod:info(Tab,size) of + Expect -> + ok; + _ -> + exit({size_field_wrong,{Mod,Mod:info(Tab)}}) + end. + + + + +%% Check correct behaviour if the table owner dies. owner_dies(Config) when is_list(Config) -> - ?line P1 = start_commander(), - ?line Ets1 = command(P1,{ets,new,[ets,[]]}), - ?line command(P1,{ets,safe_fixtable,[Ets1,true]}), - ?line {_,[{P1,1}]} = ets:info(Ets1, safe_fixed), - ?line stop_commander(P1), - ?line undefined = ets:info(Ets1, safe_fixed), - ?line P2 = start_commander(), - ?line Ets2 = command(P2,{ets,new,[ets,[public]]}), - ?line command(P2,{ets,safe_fixtable,[Ets2,true]}), - ?line ets:safe_fixtable(Ets2,true), - ?line true = ets:info(Ets2, fixed), - ?line {_,[{_,1},{_,1}]} = ets:info(Ets2, safe_fixed), - ?line stop_commander(P2), - ?line undefined = ets:info(Ets2, safe_fixed), - ?line undefined = ets:info(Ets2, fixed), - ?line P3 = start_commander(), - ?line {ok,Dets} = ?LOG(command(P3, {dets, open_file, - [?DETS_TMP1, - [{file, - dets_filename(?DETS_TMP1, - Config)}]]})), - ?line command(P3, {dets, safe_fixtable, [Dets, true]}), - ?line {_,[{P3,1}]} = dets:info(Dets, safe_fixed), - ?line true = dets:info(Dets, fixed), - ?line stop_commander(P3), - ?line undefined = dets:info(Dets, safe_fixed), - ?line undefined = dets:info(Dets, fixed), - ?line P4 = start_commander(), - ?line {ok,Dets} = command(P4, {dets, open_file, + P1 = start_commander(), + Ets1 = command(P1,{ets,new,[ets,[]]}), + command(P1,{ets,safe_fixtable,[Ets1,true]}), + {_,[{P1,1}]} = ets:info(Ets1, safe_fixed), + stop_commander(P1), + undefined = ets:info(Ets1, safe_fixed), + P2 = start_commander(), + Ets2 = command(P2,{ets,new,[ets,[public]]}), + command(P2,{ets,safe_fixtable,[Ets2,true]}), + ets:safe_fixtable(Ets2,true), + true = ets:info(Ets2, fixed), + {_,[{_,1},{_,1}]} = ets:info(Ets2, safe_fixed), + stop_commander(P2), + undefined = ets:info(Ets2, safe_fixed), + undefined = ets:info(Ets2, fixed), + P3 = start_commander(), + {ok,Dets} = ?LOG(command(P3, {dets, open_file, + [?DETS_TMP1, + [{file, + dets_filename(?DETS_TMP1, + Config)}]]})), + command(P3, {dets, safe_fixtable, [Dets, true]}), + {_,[{P3,1}]} = dets:info(Dets, safe_fixed), + true = dets:info(Dets, fixed), + stop_commander(P3), + undefined = dets:info(Dets, safe_fixed), + undefined = dets:info(Dets, fixed), + P4 = start_commander(), + {ok,Dets} = command(P4, {dets, open_file, [?DETS_TMP1, [{file, dets_filename(?DETS_TMP1,Config)}]]}), - ?line {ok,Dets} = dets:open_file(?DETS_TMP1, + {ok,Dets} = dets:open_file(?DETS_TMP1, [{file, dets_filename(?DETS_TMP1,Config)}]), - ?line false = dets:info(Dets, safe_fixed), - ?line command(P4, {dets, safe_fixtable, [Dets, true]}), - ?line dets:safe_fixtable(Dets, true), - ?line {_,[{_,1},{_,1}]} = dets:info(Dets, safe_fixed), - ?line dets:safe_fixtable(Dets, true), - ?line stop_commander(P4), - ?line S = self(), - ?line {_,[{S,2}]} = dets:info(Dets, safe_fixed), - ?line true = dets:info(Dets, fixed), - ?line dets:close(Dets), - ?line undefined = dets:info(Dets, fixed), - ?line undefined = dets:info(Dets, safe_fixed), + false = dets:info(Dets, safe_fixed), + command(P4, {dets, safe_fixtable, [Dets, true]}), + dets:safe_fixtable(Dets, true), + {_,[{_,1},{_,1}]} = dets:info(Dets, safe_fixed), + dets:safe_fixtable(Dets, true), + stop_commander(P4), + S = self(), + {_,[{S,2}]} = dets:info(Dets, safe_fixed), + true = dets:info(Dets, fixed), + dets:close(Dets), + undefined = dets:info(Dets, fixed), + undefined = dets:info(Dets, safe_fixed), ok. - - -other_process_closes(doc) -> - ["When another process closes an dets table, different " - "things should happen depending on if it has opened it before."]; -other_process_closes(suite) -> - []; +%% When another process closes an dets table, different things should +%% happen depending on if it has opened it before. other_process_closes(Config) when is_list(Config) -> - ?line {ok,Dets} = dets:open_file(?DETS_TMP1, + {ok,Dets} = dets:open_file(?DETS_TMP1, [{file, dets_filename(tmp1,Config)}]), - ?line P2 = start_commander(), - ?line dets:safe_fixtable(Dets,true), - ?line S = self(), - ?line {_,[{S,1}]} = dets:info(Dets, safe_fixed), - ?line command(P2,{dets, safe_fixtable, [Dets, true]}), - ?line {_,[_,_]} = dets:info(Dets, safe_fixed), - ?line {error, not_owner} = command(P2,{dets, close, [Dets]}), - ?line {_,[_,_]} = dets:info(Dets, safe_fixed), - ?line command(P2,{dets, open_file,[?DETS_TMP1, + P2 = start_commander(), + dets:safe_fixtable(Dets,true), + S = self(), + {_,[{S,1}]} = dets:info(Dets, safe_fixed), + command(P2,{dets, safe_fixtable, [Dets, true]}), + {_,[_,_]} = dets:info(Dets, safe_fixed), + {error, not_owner} = command(P2,{dets, close, [Dets]}), + {_,[_,_]} = dets:info(Dets, safe_fixed), + command(P2,{dets, open_file,[?DETS_TMP1, [{file, dets_filename(?DETS_TMP1, Config)}]]}), - ?line {_,[_,_]} = dets:info(Dets, safe_fixed), - ?line command(P2,{dets, close, [Dets]}), - ?line stop_commander(P2), - ?line {_,[{S,1}]} = dets:info(Dets, safe_fixed), - ?line true = dets:info(Dets,fixed), - ?line dets:close(Dets), - ?line undefined = dets:info(Dets,fixed), - ?line undefined = dets:info(Dets, safe_fixed), + {_,[_,_]} = dets:info(Dets, safe_fixed), + command(P2,{dets, close, [Dets]}), + stop_commander(P2), + {_,[{S,1}]} = dets:info(Dets, safe_fixed), + true = dets:info(Dets,fixed), + dets:close(Dets), + undefined = dets:info(Dets,fixed), + undefined = dets:info(Dets, safe_fixed), ok. - -other_process_deletes(doc) -> - ["Check that fixtable structures are cleaned up if another process " - "deletes an ets table"]; -other_process_deletes(suite) -> - []; + +%% Check that fixtable structures are cleaned up if another process +%% deletes an ets table. other_process_deletes(Config) when is_list(Config) -> - ?line Ets = ets:new(ets,[public]), - ?line P = start_commander(), - ?line ets:safe_fixtable(Ets,true), - ?line ets:safe_fixtable(Ets,true), - ?line true = ets:info(Ets, fixed), - ?line {_,_} = ets:info(Ets, safe_fixed), - ?line command(P,{ets,delete,[Ets]}), - ?line stop_commander(P), - ?line undefined = ets:info(Ets, fixed), - ?line undefined = ets:info(Ets, safe_fixed), + Ets = ets:new(ets,[public]), + P = start_commander(), + ets:safe_fixtable(Ets,true), + ets:safe_fixtable(Ets,true), + true = ets:info(Ets, fixed), + {_,_} = ets:info(Ets, safe_fixed), + command(P,{ets,delete,[Ets]}), + stop_commander(P), + undefined = ets:info(Ets, fixed), + undefined = ets:info(Ets, safe_fixed), ok. -multiple_fixes(doc) -> - ["Check that multiple safe_fixtable keeps the reference counter."]; -multiple_fixes(suite) -> - []; +%% Check that multiple safe_fixtable keeps the reference counter. multiple_fixes(Config) when is_list(Config) -> - ?line {ok,Dets} = dets:open_file(?DETS_TMP1, + {ok,Dets} = dets:open_file(?DETS_TMP1, [{file, dets_filename(?DETS_TMP1,Config)}]), - ?line Ets = ets:new(ets,[]), - ?line multiple_fixes(Dets,dets), - ?line multiple_fixes(Ets,ets), - ?line dets:close(Dets), + Ets = ets:new(ets,[]), + multiple_fixes(Dets,dets), + multiple_fixes(Ets,ets), + dets:close(Dets), ok. multiple_fixes(Tab, Mod) -> - ?line false = Mod:info(Tab,fixed), - ?line false = Mod:info(Tab, safe_fixed), - ?line Mod:safe_fixtable(Tab, true), - ?line true = Mod:info(Tab,fixed), - ?line S = self(), - ?line {_,[{S,1}]} = Mod:info(Tab, safe_fixed), - ?line Mod:safe_fixtable(Tab, true), - ?line Mod:safe_fixtable(Tab, true), - ?line {_,[{S,3}]} = Mod:info(Tab, safe_fixed), - ?line true = Mod:info(Tab,fixed), - ?line Mod:safe_fixtable(Tab, false), - ?line {_,[{S,2}]} = Mod:info(Tab, safe_fixed), - ?line true = Mod:info(Tab,fixed), - ?line Mod:safe_fixtable(Tab, false), - ?line {_,[{S,1}]} = Mod:info(Tab, safe_fixed), - ?line true = Mod:info(Tab,fixed), - ?line Mod:safe_fixtable(Tab, false), - ?line false = Mod:info(Tab, safe_fixed), - ?line false = Mod:info(Tab,fixed). - -multiple_processes(doc) -> - ["Check that multiple safe_fixtable across processes are reference " - "counted OK"]; -multiple_processes(suite) -> - []; + false = Mod:info(Tab,fixed), + false = Mod:info(Tab, safe_fixed), + Mod:safe_fixtable(Tab, true), + true = Mod:info(Tab,fixed), + S = self(), + {_,[{S,1}]} = Mod:info(Tab, safe_fixed), + Mod:safe_fixtable(Tab, true), + Mod:safe_fixtable(Tab, true), + {_,[{S,3}]} = Mod:info(Tab, safe_fixed), + true = Mod:info(Tab,fixed), + Mod:safe_fixtable(Tab, false), + {_,[{S,2}]} = Mod:info(Tab, safe_fixed), + true = Mod:info(Tab,fixed), + Mod:safe_fixtable(Tab, false), + {_,[{S,1}]} = Mod:info(Tab, safe_fixed), + true = Mod:info(Tab,fixed), + Mod:safe_fixtable(Tab, false), + false = Mod:info(Tab, safe_fixed), + false = Mod:info(Tab,fixed). + +%% Check that multiple safe_fixtable across processes are reference +%% counted OK. multiple_processes(Config) when is_list(Config) -> - ?line {ok,Dets} = dets:open_file(?DETS_TMP1,[{file, + {ok,Dets} = dets:open_file(?DETS_TMP1,[{file, dets_filename(?DETS_TMP1, Config)}]), - ?line Ets = ets:new(ets,[public]), - ?line multiple_processes(Dets,dets), - ?line multiple_processes(Ets,ets), + Ets = ets:new(ets,[public]), + multiple_processes(Dets,dets), + multiple_processes(Ets,ets), ok. multiple_processes(Tab, Mod) -> - ?line io:format("Mod = ~p\n", [Mod]), - ?line P1 = start_commander(), - ?line P2 = start_commander(), - ?line false = Mod:info(Tab,fixed), - ?line false = Mod:info(Tab, safe_fixed), - ?line command(P1, {Mod, safe_fixtable, [Tab,true]}), - ?line true = Mod:info(Tab,fixed), - ?line {_,[{P1,1}]} = Mod:info(Tab, safe_fixed), - ?line command(P2, {Mod, safe_fixtable, [Tab,true]}), - ?line true = Mod:info(Tab,fixed), - ?line {_,L} = Mod:info(Tab,safe_fixed), - ?line true = (lists:sort(L) == lists:sort([{P1,1},{P2,1}])), - ?line command(P2, {Mod, safe_fixtable, [Tab,true]}), - ?line {_,L2} = Mod:info(Tab,safe_fixed), - ?line true = (lists:sort(L2) == lists:sort([{P1,1},{P2,2}])), - ?line command(P2, {Mod, safe_fixtable, [Tab,false]}), - ?line true = Mod:info(Tab,fixed), - ?line {_,L3} = Mod:info(Tab,safe_fixed), - ?line true = (lists:sort(L3) == lists:sort([{P1,1},{P2,1}])), - ?line command(P2, {Mod, safe_fixtable, [Tab,false]}), - ?line true = Mod:info(Tab,fixed), - ?line {_,[{P1,1}]} = Mod:info(Tab, safe_fixed), - ?line stop_commander(P1), - ?line receive after 1000 -> ok end, - ?line false = Mod:info(Tab,fixed), - ?line false = Mod:info(Tab, safe_fixed), - ?line command(P2, {Mod, safe_fixtable, [Tab,true]}), - ?line true = Mod:info(Tab,fixed), - ?line {_,[{P2,1}]} = Mod:info(Tab, safe_fixed), + io:format("Mod = ~p\n", [Mod]), + P1 = start_commander(), + P2 = start_commander(), + false = Mod:info(Tab,fixed), + false = Mod:info(Tab, safe_fixed), + command(P1, {Mod, safe_fixtable, [Tab,true]}), + true = Mod:info(Tab,fixed), + {_,[{P1,1}]} = Mod:info(Tab, safe_fixed), + command(P2, {Mod, safe_fixtable, [Tab,true]}), + true = Mod:info(Tab,fixed), + {_,L} = Mod:info(Tab,safe_fixed), + true = (lists:sort(L) == lists:sort([{P1,1},{P2,1}])), + command(P2, {Mod, safe_fixtable, [Tab,true]}), + {_,L2} = Mod:info(Tab,safe_fixed), + true = (lists:sort(L2) == lists:sort([{P1,1},{P2,2}])), + command(P2, {Mod, safe_fixtable, [Tab,false]}), + true = Mod:info(Tab,fixed), + {_,L3} = Mod:info(Tab,safe_fixed), + true = (lists:sort(L3) == lists:sort([{P1,1},{P2,1}])), + command(P2, {Mod, safe_fixtable, [Tab,false]}), + true = Mod:info(Tab,fixed), + {_,[{P1,1}]} = Mod:info(Tab, safe_fixed), + stop_commander(P1), + receive after 1000 -> ok end, + false = Mod:info(Tab,fixed), + false = Mod:info(Tab, safe_fixed), + command(P2, {Mod, safe_fixtable, [Tab,true]}), + true = Mod:info(Tab,fixed), + {_,[{P2,1}]} = Mod:info(Tab, safe_fixed), case Mod of dets -> - ?line dets:close(Tab); + dets:close(Tab); ets -> - ?line ets:delete(Tab) + ets:delete(Tab) end, - ?line stop_commander(P2), - ?line receive after 1000 -> ok end, - ?line undefined = Mod:info(Tab, safe_fixed), + stop_commander(P2), + receive after 1000 -> ok end, + undefined = Mod:info(Tab, safe_fixed), ok. - - + + %%% Helpers dets_filename(Base, Config) when is_atom(Base) -> dets_filename(atom_to_list(Base) ++ ".dat", Config); dets_filename(Basename, Config) -> - PrivDir = ?config(priv_dir,Config), + PrivDir = proplists:get_value(priv_dir,Config), filename:join(PrivDir, Basename). command_loop() -> diff --git a/lib/stdlib/test/format_SUITE.erl b/lib/stdlib/test/format_SUITE.erl index da28e085bb..b481d82ea6 100644 --- a/lib/stdlib/test/format_SUITE.erl +++ b/lib/stdlib/test/format_SUITE.erl @@ -27,18 +27,15 @@ -include_lib("common_test/include/ct.hrl"). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(1)). - init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), + Config. + +end_per_testcase(_Case, _Config) -> ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [hang_1]. @@ -59,11 +56,8 @@ end_per_group(_GroupName, Config) -> Config. -hang_1(doc) -> - ["Bad args can hang (OTP-2400)"]; -hang_1(suite) -> - []; +%% OTP-2400. Bad args can hang. hang_1(Config) when is_list(Config) -> - ?line _ = (catch io:format(a, "", [])), - ?line _ = (catch io:format({}, "", [])), + _ = (catch io:format(a, "", [])), + _ = (catch io:format({}, "", [])), ok. diff --git a/lib/stdlib/test/gen_event_SUITE.erl b/lib/stdlib/test/gen_event_SUITE.erl index e14f057720..4bad7801ff 100644 --- a/lib/stdlib/test/gen_event_SUITE.erl +++ b/lib/stdlib/test/gen_event_SUITE.erl @@ -59,75 +59,72 @@ end_per_group(_GroupName, Config) -> %% Start an event manager. %% -------------------------------------- -start(doc) -> []; -start(suite) -> []; start(Config) when is_list(Config) -> OldFl = process_flag(trap_exit, true), - ?line dummy_via:reset(), + dummy_via:reset(), - ?line {ok, Pid0} = gen_event:start(), %anonymous - ?line [] = gen_event:which_handlers(Pid0), - ?line ok = gen_event:stop(Pid0), + {ok, Pid0} = gen_event:start(), %anonymous + [] = gen_event:which_handlers(Pid0), + ok = gen_event:stop(Pid0), - ?line {ok, Pid1} = gen_event:start_link(), %anonymous - ?line [] = gen_event:which_handlers(Pid1), - ?line ok = gen_event:stop(Pid1), + {ok, Pid1} = gen_event:start_link(), %anonymous + [] = gen_event:which_handlers(Pid1), + ok = gen_event:stop(Pid1), - ?line {ok, Pid2} = gen_event:start({local, my_dummy_name}), - ?line [] = gen_event:which_handlers(my_dummy_name), - ?line [] = gen_event:which_handlers(Pid2), - ?line ok = gen_event:stop(my_dummy_name), + {ok, Pid2} = gen_event:start({local, my_dummy_name}), + [] = gen_event:which_handlers(my_dummy_name), + [] = gen_event:which_handlers(Pid2), + ok = gen_event:stop(my_dummy_name), - ?line {ok, Pid3} = gen_event:start_link({local, my_dummy_name}), - ?line [] = gen_event:which_handlers(my_dummy_name), - ?line [] = gen_event:which_handlers(Pid3), - ?line ok = gen_event:stop(my_dummy_name), + {ok, Pid3} = gen_event:start_link({local, my_dummy_name}), + [] = gen_event:which_handlers(my_dummy_name), + [] = gen_event:which_handlers(Pid3), + ok = gen_event:stop(my_dummy_name), - ?line {ok, Pid4} = gen_event:start_link({global, my_dummy_name}), - ?line [] = gen_event:which_handlers({global, my_dummy_name}), - ?line [] = gen_event:which_handlers(Pid4), - ?line ok = gen_event:stop({global, my_dummy_name}), + {ok, Pid4} = gen_event:start_link({global, my_dummy_name}), + [] = gen_event:which_handlers({global, my_dummy_name}), + [] = gen_event:which_handlers(Pid4), + ok = gen_event:stop({global, my_dummy_name}), - ?line {ok, Pid5} = gen_event:start_link({via, dummy_via, my_dummy_name}), - ?line [] = gen_event:which_handlers({via, dummy_via, my_dummy_name}), - ?line [] = gen_event:which_handlers(Pid5), - ?line ok = gen_event:stop({via, dummy_via, my_dummy_name}), + {ok, Pid5} = gen_event:start_link({via, dummy_via, my_dummy_name}), + [] = gen_event:which_handlers({via, dummy_via, my_dummy_name}), + [] = gen_event:which_handlers(Pid5), + ok = gen_event:stop({via, dummy_via, my_dummy_name}), - ?line {ok, _} = gen_event:start_link({local, my_dummy_name}), - ?line {error, {already_started, _}} = + {ok, _} = gen_event:start_link({local, my_dummy_name}), + {error, {already_started, _}} = gen_event:start_link({local, my_dummy_name}), - ?line {error, {already_started, _}} = + {error, {already_started, _}} = gen_event:start({local, my_dummy_name}), - ?line ok = gen_event:stop(my_dummy_name), + ok = gen_event:stop(my_dummy_name), - ?line {ok, Pid6} = gen_event:start_link({global, my_dummy_name}), - ?line {error, {already_started, _}} = + {ok, Pid6} = gen_event:start_link({global, my_dummy_name}), + {error, {already_started, _}} = gen_event:start_link({global, my_dummy_name}), - ?line {error, {already_started, _}} = + {error, {already_started, _}} = gen_event:start({global, my_dummy_name}), ok = gen_event:stop({global, my_dummy_name}, shutdown, 10000), receive {'EXIT', Pid6, shutdown} -> ok after 10000 -> - ?t:fail(exit_gen_event) + ct:fail(exit_gen_event) end, - ?line {ok, Pid7} = gen_event:start_link({via, dummy_via, my_dummy_name}), - ?line {error, {already_started, _}} = + {ok, Pid7} = gen_event:start_link({via, dummy_via, my_dummy_name}), + {error, {already_started, _}} = gen_event:start_link({via, dummy_via, my_dummy_name}), - ?line {error, {already_started, _}} = + {error, {already_started, _}} = gen_event:start({via, dummy_via, my_dummy_name}), exit(Pid7, shutdown), receive {'EXIT', Pid7, shutdown} -> ok after 10000 -> - ?t:fail(exit_gen_event) + ct:fail(exit_gen_event) end, - ?t:messages_get(), process_flag(trap_exit, OldFl), ok. @@ -184,7 +181,7 @@ hibernate(Config) when is_list(Config) -> {ok,Pid2} = gen_event:start({local, my_dummy_handler}), ok = gen_event:add_handler(my_dummy_handler, dummy_h, - [self(),hibernate]), + [self(),hibernate]), is_in_erlang_hibernate(Pid2), sys:suspend(my_dummy_handler), is_in_erlang_hibernate(Pid2), @@ -193,7 +190,7 @@ hibernate(Config) when is_list(Config) -> Pid2 ! wake, is_not_in_erlang_hibernate(Pid2), - + ok = gen_event:stop(my_dummy_handler), ok. @@ -204,7 +201,7 @@ is_in_erlang_hibernate(Pid) -> is_in_erlang_hibernate_1(0, Pid) -> io:format("~p\n", [erlang:process_info(Pid, current_function)]), - ?t:fail(not_in_erlang_hibernate_3); + ct:fail(not_in_erlang_hibernate_3); is_in_erlang_hibernate_1(N, Pid) -> {current_function,MFA} = erlang:process_info(Pid, current_function), case MFA of @@ -221,7 +218,7 @@ is_not_in_erlang_hibernate(Pid) -> is_not_in_erlang_hibernate_1(0, Pid) -> io:format("~p\n", [erlang:process_info(Pid, current_function)]), - ?t:fail(not_in_erlang_hibernate_3); + ct:fail(not_in_erlang_hibernate_3); is_not_in_erlang_hibernate_1(N, Pid) -> {current_function,MFA} = erlang:process_info(Pid, current_function), case MFA of @@ -233,720 +230,694 @@ is_not_in_erlang_hibernate_1(N, Pid) -> end. -add_handler(doc) -> []; -add_handler(suite) -> []; add_handler(Config) when is_list(Config) -> - ?line {ok,_} = gen_event:start({local, my_dummy_handler}), - ?line {error, my_error} = + {ok,_} = gen_event:start({local, my_dummy_handler}), + {error, my_error} = gen_event:add_handler(my_dummy_handler, dummy_h, make_error), - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line {error, my_error} = + {error, my_error} = gen_event:add_handler(my_dummy_handler, {dummy_h, self()}, make_error), - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,self()}, - [self()]), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,self()}, + [self()]), Self = self(), - ?line [{dummy_h, Self}, dummy_h] = + [{dummy_h, Self}, dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:stop(my_dummy_handler), + ok = gen_event:stop(my_dummy_handler), ok. -add_sup_handler(doc) -> []; -add_sup_handler(suite) -> []; add_sup_handler(Config) when is_list(Config) -> - ?line {ok,Pid} = gen_event:start({local, my_dummy_handler}), - ?line {error, my_error} = + {ok,Pid} = gen_event:start({local, my_dummy_handler}), + {error, my_error} = gen_event:add_sup_handler(my_dummy_handler, dummy_h, make_error), - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line exit(Pid, sup_died), - ?t:sleep(1000), - ?line [] = gen_event:which_handlers(my_dummy_handler), + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), + exit(Pid, sup_died), + ct:sleep(1000), + [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line {error, my_error} = + {error, my_error} = gen_event:add_handler(my_dummy_handler, {dummy_h, self()}, make_error), - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_sup_handler(my_dummy_handler, {dummy_h,self()}, - [self()]), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_sup_handler(my_dummy_handler, {dummy_h,self()}, + [self()]), Self = self(), - ?line [{dummy_h, Self}, dummy_h] = + [{dummy_h, Self}, dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:stop(my_dummy_handler), - - ?line receive - {gen_event_EXIT, dummy_h, shutdown} -> - ok - after 1000 -> - ?t:fail({no,{gen_event_EXIT, dummy_h, shutdown}}) - end, - - ?line receive - {gen_event_EXIT, {dummy_h,Self}, shutdown} -> - ok - after 1000 -> - ?t:fail({no,{gen_event_EXIT, {dummy_h,Self}, - shutdown}}) - end, + ok = gen_event:stop(my_dummy_handler), + + receive + {gen_event_EXIT, dummy_h, shutdown} -> + ok + after 1000 -> + ct:fail({no,{gen_event_EXIT, dummy_h, shutdown}}) + end, + + receive + {gen_event_EXIT, {dummy_h,Self}, shutdown} -> + ok + after 1000 -> + ct:fail({no,{gen_event_EXIT, {dummy_h,Self}, + shutdown}}) + end, ok. -delete_handler(doc) -> []; -delete_handler(suite) -> []; delete_handler(Config) when is_list(Config) -> - ?line {ok,_} = gen_event:start({local, my_dummy_handler}), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), - ?line {error, module_not_found} = + {ok,_} = gen_event:start({local, my_dummy_handler}), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + {error, module_not_found} = gen_event:delete_handler(my_dummy_handler, duuuuuuuuumy, []), - ?line return_hej = + return_hej = gen_event:delete_handler(my_dummy_handler, dummy_h, return_hej), - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), - ?line ok = + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + ok = gen_event:delete_handler(my_dummy_handler, dummy_h, []), - ?line [] = gen_event:which_handlers(my_dummy_handler), + [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,1}, [self()]), - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,2}, [self()]), - ?line {error, module_not_found} = + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,1}, [self()]), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,2}, [self()]), + {error, module_not_found} = gen_event:delete_handler(my_dummy_handler, {duuuuuuuuumy,1}, []), - ?line return_hej = + return_hej = gen_event:delete_handler(my_dummy_handler, {dummy_h,1}, return_hej), - ?line return_hej = + return_hej = gen_event:delete_handler(my_dummy_handler, {dummy_h,2}, return_hej), - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,2}, [self()]), - ?line ok = + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,2}, [self()]), + ok = gen_event:delete_handler(my_dummy_handler, {dummy_h,2}, []), - ?line [] = gen_event:which_handlers(my_dummy_handler), + [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:stop(my_dummy_handler), + ok = gen_event:stop(my_dummy_handler), ok. -swap_handler(doc) -> []; -swap_handler(suite) -> []; swap_handler(Config) when is_list(Config) -> - ?line {ok,_} = gen_event:start({local, my_dummy_handler}), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), - ?line {error, non_existing} = + {ok,_} = gen_event:start({local, my_dummy_handler}), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + {error, non_existing} = gen_event:swap_handler(my_dummy_handler, {faulty_h, swap}, {dummy1_h, []}), - ?line ok = + ok = gen_event:swap_handler(my_dummy_handler, {dummy_h, swap}, {dummy1_h, swap}), - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:delete_handler(my_dummy_handler, dummy1_h, []), + ok = gen_event:delete_handler(my_dummy_handler, dummy1_h, []), - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,3}, [self()]), - ?line {error, non_existing} = + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,3}, [self()]), + {error, non_existing} = gen_event:swap_handler(my_dummy_handler, {faulty_h, swap}, {dummy1_h, []}), - ?line ok = + ok = gen_event:swap_handler(my_dummy_handler, {{dummy_h,3}, swap}, {{dummy1_h,4}, swap}), - ?line [{dummy1_h,4}] = gen_event:which_handlers(my_dummy_handler), + [{dummy1_h,4}] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:delete_handler(my_dummy_handler, {dummy1_h,4}, []), + ok = gen_event:delete_handler(my_dummy_handler, {dummy1_h,4}, []), - ?line ok = gen_event:stop(my_dummy_handler), + ok = gen_event:stop(my_dummy_handler), ok. - -swap_sup_handler(doc) -> []; -swap_sup_handler(suite) -> []; + swap_sup_handler(Config) when is_list(Config) -> - ?line {ok,_} = gen_event:start({local, my_dummy_handler}), - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line {error, non_existing} = + {ok,_} = gen_event:start({local, my_dummy_handler}), + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + {error, non_existing} = gen_event:swap_handler(my_dummy_handler, {faulty_h, swap}, {dummy1_h, []}), - ?line ok = + ok = gen_event:swap_handler(my_dummy_handler, {dummy_h, swap}, {dummy1_h, swap}), - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - - ?line ok = gen_event:delete_handler(my_dummy_handler, dummy1_h, []), - ?line receive - {gen_event_EXIT, dummy1_h, normal} -> - ok - after 1000 -> - ?t:fail({no,{gen_event_EXIT, dummy1_h, normal}}) - end, - - ?line ok = gen_event:add_sup_handler(my_dummy_handler, {dummy_h,3}, - [self()]), - ?line {error, non_existing} = + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + + ok = gen_event:delete_handler(my_dummy_handler, dummy1_h, []), + receive + {gen_event_EXIT, dummy1_h, normal} -> + ok + after 1000 -> + ct:fail({no,{gen_event_EXIT, dummy1_h, normal}}) + end, + + ok = gen_event:add_sup_handler(my_dummy_handler, {dummy_h,3}, + [self()]), + {error, non_existing} = gen_event:swap_sup_handler(my_dummy_handler, {faulty_h, swap}, {dummy1_h, []}), - ?line ok = + ok = gen_event:swap_sup_handler(my_dummy_handler, {{dummy_h,3}, swap}, {{dummy1_h,4}, swap}), - ?line [{dummy1_h,4}] = gen_event:which_handlers(my_dummy_handler), + [{dummy1_h,4}] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:delete_handler(my_dummy_handler, {dummy1_h,4}, []), - ?line receive - {gen_event_EXIT, {dummy1_h,4}, normal} -> - ok - after 1000 -> - ?t:fail({no,{gen_event_EXIT, {dummy1_h,4}, normal}}) - end, + ok = gen_event:delete_handler(my_dummy_handler, {dummy1_h,4}, []), + receive + {gen_event_EXIT, {dummy1_h,4}, normal} -> + ok + after 1000 -> + ct:fail({no,{gen_event_EXIT, {dummy1_h,4}, normal}}) + end, - ?line ok = gen_event:stop(my_dummy_handler), + ok = gen_event:stop(my_dummy_handler), ok. - -notify(doc) -> []; -notify(suite) -> []; + notify(Config) when is_list(Config) -> - ?line {ok,_} = gen_event:start({local, my_dummy_handler}), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + {ok,_} = gen_event:start({local, my_dummy_handler}), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), Event = {event, self()}, - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:notify(my_dummy_handler, Event), - ?line receive - {dummy_h, Event} -> - ok - end, - ?line ok = gen_event:notify(my_dummy_handler, {swap_event,dummy1_h,swap}), - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:notify(my_dummy_handler, Event), - ?line receive - {dummy1_h, Event} -> - ok - end, - ?line ok = gen_event:notify(my_dummy_handler, delete_event), - ?line receive - {dummy1_h, removed} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), - - ?line ok = gen_event:notify(my_dummy_handler, error_event), - ?line receive - {dummy_h, returned_error} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:notify(my_dummy_handler, Event), + receive + {dummy_h, Event} -> + ok + end, + ok = gen_event:notify(my_dummy_handler, {swap_event,dummy1_h,swap}), + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:notify(my_dummy_handler, Event), + receive + {dummy1_h, Event} -> + ok + end, + ok = gen_event:notify(my_dummy_handler, delete_event), + receive + {dummy1_h, removed} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + + ok = gen_event:notify(my_dummy_handler, error_event), + receive + {dummy_h, returned_error} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), %% Handler with id, {Mod,Id} - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,5}, [self()]), - ?line [{dummy_h,5}] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:notify(my_dummy_handler, Event), - ?line receive - {dummy_h, Event} -> - ok - end, - ?line ok = gen_event:notify(my_dummy_handler, - {swap_event, {dummy1_h, 9}, swap}), - ?line [{dummy1_h,9}] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:notify(my_dummy_handler, Event), - ?line receive - {dummy1_h, Event} -> - ok - end, - ?line ok = gen_event:notify(my_dummy_handler, delete_event), - ?line receive - {dummy1_h, removed} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,a}, [self()]), - - ?line ok = gen_event:notify(my_dummy_handler, error_event), - ?line receive - {dummy_h, returned_error} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,5}, [self()]), + [{dummy_h,5}] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:notify(my_dummy_handler, Event), + receive + {dummy_h, Event} -> + ok + end, + ok = gen_event:notify(my_dummy_handler, + {swap_event, {dummy1_h, 9}, swap}), + [{dummy1_h,9}] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:notify(my_dummy_handler, Event), + receive + {dummy1_h, Event} -> + ok + end, + ok = gen_event:notify(my_dummy_handler, delete_event), + receive + {dummy1_h, removed} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,a}, [self()]), + + ok = gen_event:notify(my_dummy_handler, error_event), + receive + {dummy_h, returned_error} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), %% Supervised handler. - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:notify(my_dummy_handler, Event), - ?line receive - {dummy_h, Event} -> - ok - end, - - ?line ok = gen_event:notify(my_dummy_handler, do_crash), - ?line receive - {gen_event_EXIT, dummy_h, {'EXIT',_}} -> - ok - end, - - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line ok = gen_event:notify(my_dummy_handler, {swap_event,dummy1_h,swap}), - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - - ?line ok = gen_event:notify(my_dummy_handler, do_crash), - ?line receive - {gen_event_EXIT, dummy1_h, {'EXIT',_}} -> - ok - end, - - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line ok = gen_event:notify(my_dummy_handler, {swap_event,dummy1_h,swap}), - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - - ?line ok = gen_event:notify(my_dummy_handler, delete_event), - ?line receive - {dummy1_h, removed} -> - ok - end, - - ?line receive - {gen_event_EXIT, dummy1_h, normal} -> - ok - end, - - ?line [] = gen_event:which_handlers(my_dummy_handler), - - ?line ok = gen_event:stop(my_dummy_handler), + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:notify(my_dummy_handler, Event), + receive + {dummy_h, Event} -> + ok + end, + + ok = gen_event:notify(my_dummy_handler, do_crash), + receive + {gen_event_EXIT, dummy_h, {'EXIT',_}} -> + ok + end, + + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + ok = gen_event:notify(my_dummy_handler, {swap_event,dummy1_h,swap}), + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + + ok = gen_event:notify(my_dummy_handler, do_crash), + receive + {gen_event_EXIT, dummy1_h, {'EXIT',_}} -> + ok + end, + + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + ok = gen_event:notify(my_dummy_handler, {swap_event,dummy1_h,swap}), + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + + ok = gen_event:notify(my_dummy_handler, delete_event), + receive + {dummy1_h, removed} -> + ok + end, + + receive + {gen_event_EXIT, dummy1_h, normal} -> + ok + end, + + [] = gen_event:which_handlers(my_dummy_handler), + + ok = gen_event:stop(my_dummy_handler), ok. -sync_notify(doc) -> []; -sync_notify(suite) -> []; sync_notify(Config) when is_list(Config) -> - ?line {ok,_} = gen_event:start({local, my_dummy_handler}), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + {ok,_} = gen_event:start({local, my_dummy_handler}), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), Event = {event, self()}, - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:sync_notify(my_dummy_handler, Event), - ?line receive - {dummy_h, Event} -> - ok - end, - ?line ok = gen_event:sync_notify(my_dummy_handler, - {swap_event, dummy1_h, swap}), - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:sync_notify(my_dummy_handler, Event), - ?line receive - {dummy1_h, Event} -> - ok - end, - ?line ok = gen_event:sync_notify(my_dummy_handler, delete_event), - ?line receive - {dummy1_h, removed} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), - - ?line ok = gen_event:sync_notify(my_dummy_handler, error_event), - ?line receive - {dummy_h, returned_error} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:sync_notify(my_dummy_handler, Event), + receive + {dummy_h, Event} -> + ok + end, + ok = gen_event:sync_notify(my_dummy_handler, + {swap_event, dummy1_h, swap}), + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:sync_notify(my_dummy_handler, Event), + receive + {dummy1_h, Event} -> + ok + end, + ok = gen_event:sync_notify(my_dummy_handler, delete_event), + receive + {dummy1_h, removed} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + + ok = gen_event:sync_notify(my_dummy_handler, error_event), + receive + {dummy_h, returned_error} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), %% Handler with id, {Mod,Id} - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,5}, [self()]), - ?line [{dummy_h,5}] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:sync_notify(my_dummy_handler, Event), - ?line receive - {dummy_h, Event} -> - ok - end, - ?line ok = gen_event:sync_notify(my_dummy_handler, - {swap_event, {dummy1_h, 9}, swap}), - ?line [{dummy1_h,9}] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:sync_notify(my_dummy_handler, Event), - ?line receive - {dummy1_h, Event} -> - ok - end, - ?line ok = gen_event:sync_notify(my_dummy_handler, delete_event), - ?line receive - {dummy1_h, removed} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,a}, [self()]), - - ?line ok = gen_event:sync_notify(my_dummy_handler, error_event), - ?line receive - {dummy_h, returned_error} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,5}, [self()]), + [{dummy_h,5}] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:sync_notify(my_dummy_handler, Event), + receive + {dummy_h, Event} -> + ok + end, + ok = gen_event:sync_notify(my_dummy_handler, + {swap_event, {dummy1_h, 9}, swap}), + [{dummy1_h,9}] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:sync_notify(my_dummy_handler, Event), + receive + {dummy1_h, Event} -> + ok + end, + ok = gen_event:sync_notify(my_dummy_handler, delete_event), + receive + {dummy1_h, removed} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,a}, [self()]), + + ok = gen_event:sync_notify(my_dummy_handler, error_event), + receive + {dummy_h, returned_error} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), %% Supervised handler. - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:sync_notify(my_dummy_handler, Event), - ?line receive - {dummy_h, Event} -> - ok - end, - - ?line ok = gen_event:sync_notify(my_dummy_handler, do_crash), - ?line receive - {gen_event_EXIT, dummy_h, {'EXIT',_}} -> - ok - end, - - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line ok = gen_event:sync_notify(my_dummy_handler, - {swap_event,dummy1_h,swap}), - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - - ?line ok = gen_event:sync_notify(my_dummy_handler, do_crash), - ?line receive - {gen_event_EXIT, dummy1_h, {'EXIT',_}} -> - ok - end, - - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line ok = gen_event:sync_notify(my_dummy_handler, - {swap_event,dummy1_h,swap}), - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - - ?line ok = gen_event:sync_notify(my_dummy_handler, delete_event), - ?line receive - {dummy1_h, removed} -> - ok - end, - - ?line receive - {gen_event_EXIT, dummy1_h, normal} -> - ok - end, - - ?line [] = gen_event:which_handlers(my_dummy_handler), - - ?line ok = gen_event:stop(my_dummy_handler), + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:sync_notify(my_dummy_handler, Event), + receive + {dummy_h, Event} -> + ok + end, + + ok = gen_event:sync_notify(my_dummy_handler, do_crash), + receive + {gen_event_EXIT, dummy_h, {'EXIT',_}} -> + ok + end, + + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + ok = gen_event:sync_notify(my_dummy_handler, + {swap_event,dummy1_h,swap}), + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + + ok = gen_event:sync_notify(my_dummy_handler, do_crash), + receive + {gen_event_EXIT, dummy1_h, {'EXIT',_}} -> + ok + end, + + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + ok = gen_event:sync_notify(my_dummy_handler, + {swap_event,dummy1_h,swap}), + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + + ok = gen_event:sync_notify(my_dummy_handler, delete_event), + receive + {dummy1_h, removed} -> + ok + end, + + receive + {gen_event_EXIT, dummy1_h, normal} -> + ok + end, + + [] = gen_event:which_handlers(my_dummy_handler), + + ok = gen_event:stop(my_dummy_handler), ok. -call(doc) -> []; -call(suite) -> []; call(Config) when is_list(Config) -> - ?line {ok,_} = gen_event:start({local, my_dummy_handler}), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h, 1}, [self()]), - ?line [{dummy_h, 1}, dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line {'EXIT',_} = (catch gen_event:call(non_exist, dummy_h, hejsan)), - ?line {error, bad_module} = + {ok,_} = gen_event:start({local, my_dummy_handler}), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h, 1}, [self()]), + [{dummy_h, 1}, dummy_h] = gen_event:which_handlers(my_dummy_handler), + {'EXIT',_} = (catch gen_event:call(non_exist, dummy_h, hejsan)), + {error, bad_module} = gen_event:call(my_dummy_handler, bad_h, hejsan), - ?line {ok, hejhopp} = gen_event:call(my_dummy_handler, dummy_h, hejsan), - ?line {ok, hejhopp} = gen_event:call(my_dummy_handler, {dummy_h, 1}, - hejsan), - ?line {ok, hejhopp} = gen_event:call(my_dummy_handler, dummy_h, hejsan, - 10000), - ?line {'EXIT', {timeout, _}} = + {ok, hejhopp} = gen_event:call(my_dummy_handler, dummy_h, hejsan), + {ok, hejhopp} = gen_event:call(my_dummy_handler, {dummy_h, 1}, + hejsan), + {ok, hejhopp} = gen_event:call(my_dummy_handler, dummy_h, hejsan, + 10000), + {'EXIT', {timeout, _}} = (catch gen_event:call(my_dummy_handler, dummy_h, hejsan, 0)), flush(), - ?line ok = gen_event:delete_handler(my_dummy_handler, {dummy_h, 1}, []), - ?line {ok, swapped} = gen_event:call(my_dummy_handler, dummy_h, - {swap_call,dummy1_h,swap}), - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - ?line {error, bad_module} = + ok = gen_event:delete_handler(my_dummy_handler, {dummy_h, 1}, []), + {ok, swapped} = gen_event:call(my_dummy_handler, dummy_h, + {swap_call,dummy1_h,swap}), + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + {error, bad_module} = gen_event:call(my_dummy_handler, dummy_h, hejsan), - ?line ok = gen_event:call(my_dummy_handler, dummy1_h, delete_call), - ?line receive - {dummy1_h, removed} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), - - ?line {error, {return, faulty}} = + ok = gen_event:call(my_dummy_handler, dummy1_h, delete_call), + receive + {dummy1_h, removed} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + + {error, {return, faulty}} = gen_event:call(my_dummy_handler, dummy_h, error_call), - ?line receive - {dummy_h, returned_error} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), - - ?line {error, {'EXIT', _}} = + receive + {dummy_h, returned_error} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + + {error, {'EXIT', _}} = gen_event:call(my_dummy_handler, dummy_h, exit_call), - ?line [] = gen_event:which_handlers(my_dummy_handler), + [] = gen_event:which_handlers(my_dummy_handler), %% Handler with id, {Mod,Id} - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,1}, [self()]), - ?line [{dummy_h,1}] = gen_event:which_handlers(my_dummy_handler), - ?line {error, bad_module} = + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,1}, [self()]), + [{dummy_h,1}] = gen_event:which_handlers(my_dummy_handler), + {error, bad_module} = gen_event:call(my_dummy_handler, bad_h, hejsan), - ?line {ok, hejhopp} = gen_event:call(my_dummy_handler, {dummy_h,1}, - hejsan), - ?line {ok, swapped} = gen_event:call(my_dummy_handler, {dummy_h,1}, - {swap_call,{dummy1_h,2},swap}), - ?line [{dummy1_h,2}] = gen_event:which_handlers(my_dummy_handler), - ?line {error, bad_module} = + {ok, hejhopp} = gen_event:call(my_dummy_handler, {dummy_h,1}, + hejsan), + {ok, swapped} = gen_event:call(my_dummy_handler, {dummy_h,1}, + {swap_call,{dummy1_h,2},swap}), + [{dummy1_h,2}] = gen_event:which_handlers(my_dummy_handler), + {error, bad_module} = gen_event:call(my_dummy_handler, dummy_h, hejsan), - ?line ok = gen_event:call(my_dummy_handler, {dummy1_h,2}, delete_call), - ?line receive - {dummy1_h, removed} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,3}, [self()]), - - ?line {error, {return, faulty}} = + ok = gen_event:call(my_dummy_handler, {dummy1_h,2}, delete_call), + receive + {dummy1_h, removed} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,3}, [self()]), + + {error, {return, faulty}} = gen_event:call(my_dummy_handler, {dummy_h,3}, error_call), - ?line receive - {dummy_h, returned_error} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,4}, [self()]), - - ?line {error, {'EXIT', _}} = + receive + {dummy_h, returned_error} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,4}, [self()]), + + {error, {'EXIT', _}} = gen_event:call(my_dummy_handler, {dummy_h,4}, exit_call), - ?line [] = gen_event:which_handlers(my_dummy_handler), + [] = gen_event:which_handlers(my_dummy_handler), %% Supervised handler. - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line {error, bad_module} = + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), + {error, bad_module} = gen_event:call(my_dummy_handler, bad_h, hejsan), - ?line {ok, hejhopp} = gen_event:call(my_dummy_handler, dummy_h, hejsan), - ?line {ok, swapped} = gen_event:call(my_dummy_handler, dummy_h, - {swap_call,dummy1_h,swap}), - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - ?line {error, bad_module} = + {ok, hejhopp} = gen_event:call(my_dummy_handler, dummy_h, hejsan), + {ok, swapped} = gen_event:call(my_dummy_handler, dummy_h, + {swap_call,dummy1_h,swap}), + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + {error, bad_module} = gen_event:call(my_dummy_handler, dummy_h, hejsan), - ?line ok = gen_event:call(my_dummy_handler, dummy1_h, delete_call), - ?line receive - {dummy1_h, removed} -> - ok - end, + ok = gen_event:call(my_dummy_handler, dummy1_h, delete_call), + receive + {dummy1_h, removed} -> + ok + end, - ?line receive - {gen_event_EXIT, dummy1_h, normal} -> - ok - end, + receive + {gen_event_EXIT, dummy1_h, normal} -> + ok + end, - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line {error, {return, faulty}} = + {error, {return, faulty}} = gen_event:call(my_dummy_handler, dummy_h, error_call), - ?line receive - {dummy_h, returned_error} -> - ok - end, - - ?line receive - {gen_event_EXIT, dummy_h, {return,faulty}} -> - ok - after 1000 -> - ?t:fail({no, {gen_event_EXIT, dummy_h, {return,faulty}}}) - end, - - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - - ?line {error, {'EXIT', _}} = + receive + {dummy_h, returned_error} -> + ok + end, + + receive + {gen_event_EXIT, dummy_h, {return,faulty}} -> + ok + after 1000 -> + ct:fail({no, {gen_event_EXIT, dummy_h, {return,faulty}}}) + end, + + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + + {error, {'EXIT', _}} = gen_event:call(my_dummy_handler, dummy_h, exit_call), - ?line receive - {gen_event_EXIT, dummy_h, {'EXIT',_}} -> - ok - after 1000 -> - ?t:fail({no, {gen_event_EXIT, dummy_h, {'EXIT','_'}}}) - end, + receive + {gen_event_EXIT, dummy_h, {'EXIT',_}} -> + ok + after 1000 -> + ct:fail({no, {gen_event_EXIT, dummy_h, {'EXIT','_'}}}) + end, - ?line [] = gen_event:which_handlers(my_dummy_handler), + [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:stop(my_dummy_handler), + ok = gen_event:stop(my_dummy_handler), ok. flush() -> receive _ -> flush() after 0 -> ok end. -info(doc) -> []; -info(suite) -> []; info(Config) when is_list(Config) -> - ?line {ok,_} = gen_event:start({local, my_dummy_handler}), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + {ok,_} = gen_event:start({local, my_dummy_handler}), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), Info = {info, self()}, - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line my_dummy_handler ! Info, - ?line receive - {dummy_h, Info} -> - ok - end, - ?line my_dummy_handler ! {swap_info,dummy1_h,swap}, - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - ?line my_dummy_handler ! Info, - ?line receive - {dummy1_h, Info} -> - ok - end, - ?line my_dummy_handler ! delete_info, - ?line receive - {dummy1_h, removed} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), - - ?line my_dummy_handler ! error_info, - ?line receive - {dummy_h, returned_error} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), + my_dummy_handler ! Info, + receive + {dummy_h, Info} -> + ok + end, + my_dummy_handler ! {swap_info,dummy1_h,swap}, + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + my_dummy_handler ! Info, + receive + {dummy1_h, Info} -> + ok + end, + my_dummy_handler ! delete_info, + receive + {dummy1_h, removed} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, dummy_h, [self()]), + + my_dummy_handler ! error_info, + receive + {dummy_h, returned_error} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), %% Handler with id, {Mod,Id} - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,1}, [self()]), - ?line [{dummy_h,1}] = gen_event:which_handlers(my_dummy_handler), - ?line my_dummy_handler ! Info, - ?line receive - {dummy_h, Info} -> - ok - end, - ?line my_dummy_handler ! {swap_info,{dummy1_h,2},swap}, - ?line [{dummy1_h,2}] = gen_event:which_handlers(my_dummy_handler), - ?line my_dummy_handler ! Info, - ?line receive - {dummy1_h, Info} -> - ok - end, - ?line my_dummy_handler ! delete_info, - ?line receive - {dummy1_h, removed} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), - ?line ok = gen_event:add_handler(my_dummy_handler, {dummy_h,3}, [self()]), - - ?line my_dummy_handler ! error_info, - ?line receive - {dummy_h, returned_error} -> - ok - end, - ?line [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,1}, [self()]), + [{dummy_h,1}] = gen_event:which_handlers(my_dummy_handler), + my_dummy_handler ! Info, + receive + {dummy_h, Info} -> + ok + end, + my_dummy_handler ! {swap_info,{dummy1_h,2},swap}, + [{dummy1_h,2}] = gen_event:which_handlers(my_dummy_handler), + my_dummy_handler ! Info, + receive + {dummy1_h, Info} -> + ok + end, + my_dummy_handler ! delete_info, + receive + {dummy1_h, removed} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), + ok = gen_event:add_handler(my_dummy_handler, {dummy_h,3}, [self()]), + + my_dummy_handler ! error_info, + receive + {dummy_h, returned_error} -> + ok + end, + [] = gen_event:which_handlers(my_dummy_handler), %% Supervised handler - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line [dummy_h] = gen_event:which_handlers(my_dummy_handler), - ?line my_dummy_handler ! Info, - ?line receive - {dummy_h, Info} -> - ok - end, - ?line my_dummy_handler ! {swap_info,dummy1_h,swap}, - ?line [dummy1_h] = gen_event:which_handlers(my_dummy_handler), - ?line my_dummy_handler ! Info, - ?line receive - {dummy1_h, Info} -> - ok - end, - ?line my_dummy_handler ! delete_info, - ?line receive - {dummy1_h, removed} -> - ok - end, - - ?line receive - {gen_event_EXIT, dummy1_h, normal} -> - ok - after 1000 -> - ?t:fail({no, {gen_event_EXIT, dummy1_h, normal}}) - end, - - ?line [] = gen_event:which_handlers(my_dummy_handler), - - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - - ?line my_dummy_handler ! error_info, - ?line receive - {dummy_h, returned_error} -> - ok - end, - - ?line receive - {gen_event_EXIT, dummy_h, {return,faulty}} -> - ok - after 1000 -> - ?t:fail({no, {gen_event_EXIT, dummy_h, {return,faulty}}}) - end, - - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), - ?line my_dummy_handler ! do_crash, - - ?line receive - {gen_event_EXIT, dummy_h, {'EXIT',_}} -> - ok - after 1000 -> - ?t:fail({no, {gen_event_EXIT, dummy_h, {'EXIT','_'}}}) - end, - - ?line [] = gen_event:which_handlers(my_dummy_handler), - - ?line ok = gen_event:stop(my_dummy_handler), + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + [dummy_h] = gen_event:which_handlers(my_dummy_handler), + my_dummy_handler ! Info, + receive + {dummy_h, Info} -> + ok + end, + my_dummy_handler ! {swap_info,dummy1_h,swap}, + [dummy1_h] = gen_event:which_handlers(my_dummy_handler), + my_dummy_handler ! Info, + receive + {dummy1_h, Info} -> + ok + end, + my_dummy_handler ! delete_info, + receive + {dummy1_h, removed} -> + ok + end, + + receive + {gen_event_EXIT, dummy1_h, normal} -> + ok + after 1000 -> + ct:fail({no, {gen_event_EXIT, dummy1_h, normal}}) + end, + + [] = gen_event:which_handlers(my_dummy_handler), + + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + + my_dummy_handler ! error_info, + receive + {dummy_h, returned_error} -> + ok + end, + + receive + {gen_event_EXIT, dummy_h, {return,faulty}} -> + ok + after 1000 -> + ct:fail({no, {gen_event_EXIT, dummy_h, {return,faulty}}}) + end, + + ok = gen_event:add_sup_handler(my_dummy_handler, dummy_h, [self()]), + my_dummy_handler ! do_crash, + + receive + {gen_event_EXIT, dummy_h, {'EXIT',_}} -> + ok + after 1000 -> + ct:fail({no, {gen_event_EXIT, dummy_h, {'EXIT','_'}}}) + end, + + [] = gen_event:which_handlers(my_dummy_handler), + + ok = gen_event:stop(my_dummy_handler), ok. -call_format_status(suite) -> - []; -call_format_status(doc) -> - ["Test that sys:get_status/1,2 calls format_status/2"]; +%% Test that sys:get_status/1,2 calls format_status/2. call_format_status(Config) when is_list(Config) -> - ?line {ok, Pid} = gen_event:start({local, my_dummy_handler}), + {ok, Pid} = gen_event:start({local, my_dummy_handler}), %% State here intentionally differs from what we expect from format_status State = self(), FmtState = "dummy1_h handler state", - ?line ok = gen_event:add_handler(my_dummy_handler, dummy1_h, [State]), - ?line Status1 = sys:get_status(Pid), - ?line Status2 = sys:get_status(Pid, 5000), - ?line ok = gen_event:stop(Pid), - ?line {status, Pid, _, [_, _, Pid, [], Data1]} = Status1, - ?line HandlerInfo1 = proplists:get_value(items, Data1), - ?line {"Installed handlers", [{_,dummy1_h,_,FmtState,_}]} = HandlerInfo1, - ?line {status, Pid, _, [_, _, Pid, [], Data2]} = Status2, - ?line HandlerInfo2 = proplists:get_value(items, Data2), - ?line {"Installed handlers", [{_,dummy1_h,_,FmtState,_}]} = HandlerInfo2, + ok = gen_event:add_handler(my_dummy_handler, dummy1_h, [State]), + Status1 = sys:get_status(Pid), + Status2 = sys:get_status(Pid, 5000), + ok = gen_event:stop(Pid), + {status, Pid, _, [_, _, Pid, [], Data1]} = Status1, + HandlerInfo1 = proplists:get_value(items, Data1), + {"Installed handlers", [{_,dummy1_h,_,FmtState,_}]} = HandlerInfo1, + {status, Pid, _, [_, _, Pid, [], Data2]} = Status2, + HandlerInfo2 = proplists:get_value(items, Data2), + {"Installed handlers", [{_,dummy1_h,_,FmtState,_}]} = HandlerInfo2, ok. -call_format_status_anon(suite) -> - []; -call_format_status_anon(doc) -> - ["Test that sys:get_status/1,2 calls format_status/2 for anonymous gen_event processes"]; +%% Test that sys:get_status/1,2 calls format_status/2 for anonymous +%% gen_event processes. call_format_status_anon(Config) when is_list(Config) -> - ?line {ok, Pid} = gen_event:start(), + {ok, Pid} = gen_event:start(), %% The 'Name' of the gen_event process will be a pid() here, so %% the next line will crash if format_status can't string-ify pids. - ?line Status1 = sys:get_status(Pid), - ?line ok = gen_event:stop(Pid), + Status1 = sys:get_status(Pid), + ok = gen_event:stop(Pid), Header = "Status for event handler " ++ pid_to_list(Pid), - ?line {status, Pid, _, [_, _, Pid, [], Data1]} = Status1, - ?line Header = proplists:get_value(header, Data1), + {status, Pid, _, [_, _, Pid, [], Data1]} = Status1, + Header = proplists:get_value(header, Data1), ok. -error_format_status(suite) -> - []; -error_format_status(doc) -> - ["Test that a handler error calls format_status/2"]; +%% Test that a handler error calls format_status/2. error_format_status(Config) when is_list(Config) -> - ?line error_logger_forwarder:register(), + error_logger_forwarder:register(), OldFl = process_flag(trap_exit, true), State = self(), - ?line {ok, Pid} = gen_event:start({local, my_dummy_handler}), - ?line ok = gen_event:add_sup_handler(my_dummy_handler, dummy1_h, [State]), - ?line ok = gen_event:notify(my_dummy_handler, do_crash), - ?line receive - {gen_event_EXIT,dummy1_h,{'EXIT',_}} -> ok - after 5000 -> - ?t:fail(exit_gen_event) - end, + {ok, Pid} = gen_event:start({local, my_dummy_handler}), + ok = gen_event:add_sup_handler(my_dummy_handler, dummy1_h, [State]), + ok = gen_event:notify(my_dummy_handler, do_crash), + receive + {gen_event_EXIT,dummy1_h,{'EXIT',_}} -> ok + after 5000 -> + ct:fail(exit_gen_event) + end, FmtState = "dummy1_h handler state", receive {error,_GroupLeader, {Pid, @@ -955,18 +926,14 @@ error_format_status(Config) when is_list(Config) -> FmtState, _]}} -> ok; Other -> - ?line io:format("Unexpected: ~p", [Other]), - ?line ?t:fail() + io:format("Unexpected: ~p", [Other]), + ct:fail(failed) end, - ?t:messages_get(), - ?line ok = gen_event:stop(Pid), + ok = gen_event:stop(Pid), process_flag(trap_exit, OldFl), ok. -get_state(suite) -> - []; -get_state(doc) -> - ["Test that sys:get_state/1,2 return the gen_event state"]; +%% Test that sys:get_state/1,2 return the gen_event state. get_state(Config) when is_list(Config) -> {ok, Pid} = gen_event:start({local, my_dummy_handler}), State1 = self(), @@ -986,10 +953,7 @@ get_state(Config) when is_list(Config) -> ok = gen_event:stop(Pid), ok. -replace_state(suite) -> - []; -replace_state(doc) -> - ["Test that replace_state/2,3 replace the gen_event state"]; +%% Test that replace_state/2,3 replace the gen_event state. replace_state(Config) when is_list(Config) -> {ok, Pid} = gen_event:start({local, my_dummy_handler}), State1 = self(), diff --git a/lib/stdlib/test/gen_fsm_SUITE.erl b/lib/stdlib/test/gen_fsm_SUITE.erl index c238232ef0..f79a344c4e 100644 --- a/lib/stdlib/test/gen_fsm_SUITE.erl +++ b/lib/stdlib/test/gen_fsm_SUITE.erl @@ -44,10 +44,9 @@ -export([enter_loop/1]). %% Exports for apply --export([do_msg/1, do_sync_msg/1]). -export([enter_loop/2]). -% The gen_fsm behaviour +%% The gen_fsm behaviour -export([init/1, handle_event/3, handle_sync_event/4, terminate/3, handle_info/3, format_status/2]). -export([idle/2, idle/3, @@ -55,7 +54,7 @@ wfor_conf/2, wfor_conf/3, connected/2, connected/3]). -export([state0/3]). - + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -93,97 +92,95 @@ end_per_group(_GroupName, Config) -> start1(Config) when is_list(Config) -> %%OldFl = process_flag(trap_exit, true), - ?line {ok, Pid0} = gen_fsm:start_link(gen_fsm_SUITE, [], []), - ?line ok = do_func_test(Pid0), - ?line ok = do_sync_func_test(Pid0), + {ok, Pid0} = gen_fsm:start_link(gen_fsm_SUITE, [], []), + ok = do_func_test(Pid0), + ok = do_sync_func_test(Pid0), stop_it(Pid0), -%% ?line stopped = gen_fsm:sync_send_all_state_event(Pid0, stop), -%% ?line {'EXIT', {timeout,_}} = -%% (catch gen_fsm:sync_send_event(Pid0, hej)), + %% stopped = gen_fsm:sync_send_all_state_event(Pid0, stop), + %% {'EXIT', {timeout,_}} = + %% (catch gen_fsm:sync_send_event(Pid0, hej)), - ?line test_server:messages_get(), + [] = get_messages(), %%process_flag(trap_exit, OldFl), - ok. + ok. %% anonymous w. shutdown start2(Config) when is_list(Config) -> %% Dont link when shutdown - ?line {ok, Pid0} = gen_fsm:start(gen_fsm_SUITE, [], []), - ?line ok = do_func_test(Pid0), - ?line ok = do_sync_func_test(Pid0), - ?line shutdown_stopped = + {ok, Pid0} = gen_fsm:start(gen_fsm_SUITE, [], []), + ok = do_func_test(Pid0), + ok = do_sync_func_test(Pid0), + shutdown_stopped = gen_fsm:sync_send_all_state_event(Pid0, stop_shutdown), - ?line {'EXIT', {noproc,_}} = + {'EXIT', {noproc,_}} = (catch gen_fsm:sync_send_event(Pid0, hej)), - ?line test_server:messages_get(), + [] = get_messages(), ok. %% anonymous with timeout start3(Config) when is_list(Config) -> %%OldFl = process_flag(trap_exit, true), - ?line {ok, Pid0} = gen_fsm:start(gen_fsm_SUITE, [], [{timeout,5}]), - ?line ok = do_func_test(Pid0), - ?line ok = do_sync_func_test(Pid0), - ?line stop_it(Pid0), - - ?line {error, timeout} = gen_fsm:start(gen_fsm_SUITE, sleep, - [{timeout,5}]), + {ok, Pid0} = gen_fsm:start(gen_fsm_SUITE, [], [{timeout,5}]), + ok = do_func_test(Pid0), + ok = do_sync_func_test(Pid0), + stop_it(Pid0), - test_server:messages_get(), + {error, timeout} = gen_fsm:start(gen_fsm_SUITE, sleep, + [{timeout,5}]), + + [] = get_messages(), %%process_flag(trap_exit, OldFl), ok. %% anonymous with ignore -start4(suite) -> []; start4(Config) when is_list(Config) -> OldFl = process_flag(trap_exit, true), - ?line ignore = gen_fsm:start(gen_fsm_SUITE, ignore, []), + ignore = gen_fsm:start(gen_fsm_SUITE, ignore, []), - test_server:messages_get(), + [] = get_messages(), process_flag(trap_exit, OldFl), ok. %% anonymous with stop -start5(suite) -> []; start5(Config) when is_list(Config) -> OldFl = process_flag(trap_exit, true), - ?line {error, stopped} = gen_fsm:start(gen_fsm_SUITE, stop, []), + {error, stopped} = gen_fsm:start(gen_fsm_SUITE, stop, []), - test_server:messages_get(), + [] = get_messages(), process_flag(trap_exit, OldFl), ok. %% anonymous linked start6(Config) when is_list(Config) -> - ?line {ok, Pid} = gen_fsm:start_link(gen_fsm_SUITE, [], []), - ?line ok = do_func_test(Pid), - ?line ok = do_sync_func_test(Pid), - ?line stop_it(Pid), + {ok, Pid} = gen_fsm:start_link(gen_fsm_SUITE, [], []), + ok = do_func_test(Pid), + ok = do_sync_func_test(Pid), + stop_it(Pid), - test_server:messages_get(), + [] = get_messages(), ok. %% global register linked start7(Config) when is_list(Config) -> - ?line {ok, Pid} = + {ok, Pid} = gen_fsm:start_link({global, my_fsm}, gen_fsm_SUITE, [], []), - ?line {error, {already_started, Pid}} = + {error, {already_started, Pid}} = gen_fsm:start_link({global, my_fsm}, gen_fsm_SUITE, [], []), - ?line {error, {already_started, Pid}} = + {error, {already_started, Pid}} = gen_fsm:start({global, my_fsm}, gen_fsm_SUITE, [], []), - - ?line ok = do_func_test(Pid), - ?line ok = do_sync_func_test(Pid), - ?line ok = do_func_test({global, my_fsm}), - ?line ok = do_sync_func_test({global, my_fsm}), - ?line stop_it({global, my_fsm}), - - test_server:messages_get(), + + ok = do_func_test(Pid), + ok = do_sync_func_test(Pid), + ok = do_func_test({global, my_fsm}), + ok = do_sync_func_test({global, my_fsm}), + stop_it({global, my_fsm}), + + [] = get_messages(), ok. @@ -191,18 +188,18 @@ start7(Config) when is_list(Config) -> start8(Config) when is_list(Config) -> %%OldFl = process_flag(trap_exit, true), - ?line {ok, Pid} = + {ok, Pid} = gen_fsm:start({local, my_fsm}, gen_fsm_SUITE, [], []), - ?line {error, {already_started, Pid}} = + {error, {already_started, Pid}} = gen_fsm:start({local, my_fsm}, gen_fsm_SUITE, [], []), - ?line ok = do_func_test(Pid), - ?line ok = do_sync_func_test(Pid), - ?line ok = do_func_test(my_fsm), - ?line ok = do_sync_func_test(my_fsm), - ?line stop_it(Pid), - - test_server:messages_get(), + ok = do_func_test(Pid), + ok = do_sync_func_test(Pid), + ok = do_func_test(my_fsm), + ok = do_sync_func_test(my_fsm), + stop_it(Pid), + + [] = get_messages(), %%process_flag(trap_exit, OldFl), ok. @@ -210,80 +207,80 @@ start8(Config) when is_list(Config) -> start9(Config) when is_list(Config) -> %%OldFl = process_flag(trap_exit, true), - ?line {ok, Pid} = + {ok, Pid} = gen_fsm:start_link({local, my_fsm}, gen_fsm_SUITE, [], []), - ?line {error, {already_started, Pid}} = + {error, {already_started, Pid}} = gen_fsm:start({local, my_fsm}, gen_fsm_SUITE, [], []), - ?line ok = do_func_test(Pid), - ?line ok = do_sync_func_test(Pid), - ?line ok = do_func_test(my_fsm), - ?line ok = do_sync_func_test(my_fsm), - ?line stop_it(Pid), - - test_server:messages_get(), + ok = do_func_test(Pid), + ok = do_sync_func_test(Pid), + ok = do_func_test(my_fsm), + ok = do_sync_func_test(my_fsm), + stop_it(Pid), + + [] = get_messages(), %%process_flag(trap_exit, OldFl), ok. %% global register start10(Config) when is_list(Config) -> - ?line {ok, Pid} = + {ok, Pid} = gen_fsm:start({global, my_fsm}, gen_fsm_SUITE, [], []), - ?line {error, {already_started, Pid}} = + {error, {already_started, Pid}} = gen_fsm:start({global, my_fsm}, gen_fsm_SUITE, [], []), - ?line {error, {already_started, Pid}} = + {error, {already_started, Pid}} = gen_fsm:start_link({global, my_fsm}, gen_fsm_SUITE, [], []), - - ?line ok = do_func_test(Pid), - ?line ok = do_sync_func_test(Pid), - ?line ok = do_func_test({global, my_fsm}), - ?line ok = do_sync_func_test({global, my_fsm}), - ?line stop_it({global, my_fsm}), - - test_server:messages_get(), + + ok = do_func_test(Pid), + ok = do_sync_func_test(Pid), + ok = do_func_test({global, my_fsm}), + ok = do_sync_func_test({global, my_fsm}), + stop_it({global, my_fsm}), + + [] = get_messages(), ok. %% Stop registered processes start11(Config) when is_list(Config) -> - ?line {ok, Pid} = + {ok, Pid} = gen_fsm:start_link({local, my_fsm}, gen_fsm_SUITE, [], []), - ?line stop_it(Pid), + stop_it(Pid), - ?line {ok, _Pid1} = + {ok, _Pid1} = gen_fsm:start_link({local, my_fsm}, gen_fsm_SUITE, [], []), - ?line stop_it(my_fsm), - - ?line {ok, Pid2} = + stop_it(my_fsm), + + {ok, Pid2} = gen_fsm:start({global, my_fsm}, gen_fsm_SUITE, [], []), - ?line stop_it(Pid2), + stop_it(Pid2), receive after 1 -> true end, - ?line Result = + Result = gen_fsm:start({global, my_fsm}, gen_fsm_SUITE, [], []), io:format("Result = ~p~n",[Result]), - ?line {ok, _Pid3} = Result, - ?line stop_it({global, my_fsm}), + {ok, _Pid3} = Result, + stop_it({global, my_fsm}), - test_server:messages_get(), + [] = get_messages(), ok. %% Via register linked start12(Config) when is_list(Config) -> - ?line dummy_via:reset(), - ?line {ok, Pid} = + dummy_via:reset(), + {ok, Pid} = gen_fsm:start_link({via, dummy_via, my_fsm}, gen_fsm_SUITE, [], []), - ?line {error, {already_started, Pid}} = + {error, {already_started, Pid}} = gen_fsm:start_link({via, dummy_via, my_fsm}, gen_fsm_SUITE, [], []), - ?line {error, {already_started, Pid}} = + {error, {already_started, Pid}} = gen_fsm:start({via, dummy_via, my_fsm}, gen_fsm_SUITE, [], []), - ?line ok = do_func_test(Pid), - ?line ok = do_sync_func_test(Pid), - ?line ok = do_func_test({via, dummy_via, my_fsm}), - ?line ok = do_sync_func_test({via, dummy_via, my_fsm}), - ?line stop_it({via, dummy_via, my_fsm}), + ok = do_func_test(Pid), + ok = do_sync_func_test(Pid), + ok = do_func_test({via, dummy_via, my_fsm}), + ok = do_sync_func_test({via, dummy_via, my_fsm}), + stop_it({via, dummy_via, my_fsm}), - test_server:messages_get(), + [] = get_messages(), ok. @@ -339,7 +336,7 @@ stop6(_Config) -> stop7(_Config) -> dummy_via:reset(), {ok, Pid} = gen_fsm:start({via, dummy_via, to_stop}, - ?MODULE, [], []), + ?MODULE, [], []), ok = gen_fsm:stop({via, dummy_via, to_stop}), false = erlang:is_process_alive(Pid), {'EXIT',noproc} = (catch gen_fsm:stop({via, dummy_via, to_stop})), @@ -387,53 +384,51 @@ stop10(_Config) -> ok. %% Check that time outs in calls work -abnormal1(suite) -> []; abnormal1(Config) when is_list(Config) -> {ok, _Pid} = gen_fsm:start({local, my_fsm}, gen_fsm_SUITE, [], []), %% timeout call. delayed = gen_fsm:sync_send_event(my_fsm, {delayed_answer,1}, 100), {'EXIT',{timeout,_}} = - (catch gen_fsm:sync_send_event(my_fsm, {delayed_answer,10}, 1)), - test_server:messages_get(), + (catch gen_fsm:sync_send_event(my_fsm, {delayed_answer,10}, 1)), + [] = get_messages(), ok. %% Check that bad return values makes the fsm crash. Note that we must %% trap exit since we must link to get the real bad_return_ error -abnormal2(suite) -> []; abnormal2(Config) when is_list(Config) -> OldFl = process_flag(trap_exit, true), - ?line {ok, Pid} = + {ok, Pid} = gen_fsm:start_link(gen_fsm_SUITE, [], []), %% bad return value in the gen_fsm loop - ?line {'EXIT',{{bad_return_value, badreturn},_}} = + {'EXIT',{{bad_return_value, badreturn},_}} = (catch gen_fsm:sync_send_event(Pid, badreturn)), - - test_server:messages_get(), + + [{'EXIT',Pid,{bad_return_value,badreturn}}] = get_messages(), process_flag(trap_exit, OldFl), ok. shutdown(Config) when is_list(Config) -> - ?line error_logger_forwarder:register(), + error_logger_forwarder:register(), process_flag(trap_exit, true), - ?line {ok,Pid0} = gen_fsm:start_link(gen_fsm_SUITE, [], []), - ?line ok = do_func_test(Pid0), - ?line ok = do_sync_func_test(Pid0), - ?line {shutdown,reason} = + {ok,Pid0} = gen_fsm:start_link(gen_fsm_SUITE, [], []), + ok = do_func_test(Pid0), + ok = do_sync_func_test(Pid0), + {shutdown,reason} = gen_fsm:sync_send_all_state_event(Pid0, stop_shutdown_reason), receive {'EXIT',Pid0,{shutdown,reason}} -> ok end, process_flag(trap_exit, false), - ?line {'EXIT', {noproc,_}} = + {'EXIT', {noproc,_}} = (catch gen_fsm:sync_send_event(Pid0, hej)), receive Any -> - ?line io:format("Unexpected: ~p", [Any]), - ?line ?t:fail() + io:format("Unexpected: ~p", [Any]), + ct:fail(failed) after 500 -> ok end, @@ -443,70 +438,70 @@ shutdown(Config) when is_list(Config) -> sys1(Config) when is_list(Config) -> - ?line {ok, Pid} = + {ok, Pid} = gen_fsm:start(gen_fsm_SUITE, [], []), - ?line {status, Pid, {module,gen_fsm}, _} = sys:get_status(Pid), - ?line sys:suspend(Pid), - ?line {'EXIT', {timeout,_}} = + {status, Pid, {module,gen_fsm}, _} = sys:get_status(Pid), + sys:suspend(Pid), + {'EXIT', {timeout,_}} = (catch gen_fsm:sync_send_event(Pid, hej)), - ?line sys:resume(Pid), - ?line stop_it(Pid). + sys:resume(Pid), + stop_it(Pid). call_format_status(Config) when is_list(Config) -> - ?line {ok, Pid} = gen_fsm:start(gen_fsm_SUITE, [], []), - ?line Status = sys:get_status(Pid), - ?line {status, Pid, _Mod, [_PDict, running, _, _, Data]} = Status, - ?line [format_status_called | _] = lists:reverse(Data), - ?line stop_it(Pid), + {ok, Pid} = gen_fsm:start(gen_fsm_SUITE, [], []), + Status = sys:get_status(Pid), + {status, Pid, _Mod, [_PDict, running, _, _, Data]} = Status, + [format_status_called | _] = lists:reverse(Data), + stop_it(Pid), %% check that format_status can handle a name being an atom (pid is %% already checked by the previous test) - ?line {ok, Pid2} = gen_fsm:start({local, gfsm}, gen_fsm_SUITE, [], []), - ?line Status2 = sys:get_status(gfsm), - ?line {status, Pid2, _Mod, [_PDict2, running, _, _, Data2]} = Status2, - ?line [format_status_called | _] = lists:reverse(Data2), - ?line stop_it(Pid2), + {ok, Pid2} = gen_fsm:start({local, gfsm}, gen_fsm_SUITE, [], []), + Status2 = sys:get_status(gfsm), + {status, Pid2, _Mod, [_PDict2, running, _, _, Data2]} = Status2, + [format_status_called | _] = lists:reverse(Data2), + stop_it(Pid2), %% check that format_status can handle a name being a term other than a %% pid or atom GlobalName1 = {global, "CallFormatStatus"}, - ?line {ok, Pid3} = gen_fsm:start(GlobalName1, gen_fsm_SUITE, [], []), - ?line Status3 = sys:get_status(GlobalName1), - ?line {status, Pid3, _Mod, [_PDict3, running, _, _, Data3]} = Status3, - ?line [format_status_called | _] = lists:reverse(Data3), - ?line stop_it(Pid3), + {ok, Pid3} = gen_fsm:start(GlobalName1, gen_fsm_SUITE, [], []), + Status3 = sys:get_status(GlobalName1), + {status, Pid3, _Mod, [_PDict3, running, _, _, Data3]} = Status3, + [format_status_called | _] = lists:reverse(Data3), + stop_it(Pid3), GlobalName2 = {global, {name, "term"}}, - ?line {ok, Pid4} = gen_fsm:start(GlobalName2, gen_fsm_SUITE, [], []), - ?line Status4 = sys:get_status(GlobalName2), - ?line {status, Pid4, _Mod, [_PDict4, running, _, _, Data4]} = Status4, - ?line [format_status_called | _] = lists:reverse(Data4), - ?line stop_it(Pid4), + {ok, Pid4} = gen_fsm:start(GlobalName2, gen_fsm_SUITE, [], []), + Status4 = sys:get_status(GlobalName2), + {status, Pid4, _Mod, [_PDict4, running, _, _, Data4]} = Status4, + [format_status_called | _] = lists:reverse(Data4), + stop_it(Pid4), %% check that format_status can handle a name being a term other than a %% pid or atom - ?line dummy_via:reset(), + dummy_via:reset(), ViaName1 = {via, dummy_via, "CallFormatStatus"}, - ?line {ok, Pid5} = gen_fsm:start(ViaName1, gen_fsm_SUITE, [], []), - ?line Status5 = sys:get_status(ViaName1), - ?line {status, Pid5, _Mod, [_PDict5, running, _, _, Data5]} = Status5, - ?line [format_status_called | _] = lists:reverse(Data5), - ?line stop_it(Pid5), + {ok, Pid5} = gen_fsm:start(ViaName1, gen_fsm_SUITE, [], []), + Status5 = sys:get_status(ViaName1), + {status, Pid5, _Mod, [_PDict5, running, _, _, Data5]} = Status5, + [format_status_called | _] = lists:reverse(Data5), + stop_it(Pid5), ViaName2 = {via, dummy_via, {name, "term"}}, - ?line {ok, Pid6} = gen_fsm:start(ViaName2, gen_fsm_SUITE, [], []), - ?line Status6 = sys:get_status(ViaName2), - ?line {status, Pid6, _Mod, [_PDict6, running, _, _, Data6]} = Status6, - ?line [format_status_called | _] = lists:reverse(Data6), - ?line stop_it(Pid6). + {ok, Pid6} = gen_fsm:start(ViaName2, gen_fsm_SUITE, [], []), + Status6 = sys:get_status(ViaName2), + {status, Pid6, _Mod, [_PDict6, running, _, _, Data6]} = Status6, + [format_status_called | _] = lists:reverse(Data6), + stop_it(Pid6). error_format_status(Config) when is_list(Config) -> - ?line error_logger_forwarder:register(), + error_logger_forwarder:register(), OldFl = process_flag(trap_exit, true), StateData = "called format_status", - ?line {ok, Pid} = gen_fsm:start(gen_fsm_SUITE, {state_data, StateData}, []), + {ok, Pid} = gen_fsm:start(gen_fsm_SUITE, {state_data, StateData}, []), %% bad return value in the gen_fsm loop - ?line {'EXIT',{{bad_return_value, badreturn},_}} = + {'EXIT',{{bad_return_value, badreturn},_}} = (catch gen_fsm:sync_send_event(Pid, badreturn)), receive {error,_GroupLeader,{Pid, @@ -514,10 +509,9 @@ error_format_status(Config) when is_list(Config) -> [Pid,{_,_,badreturn},idle,{formatted,StateData},_]}} -> ok; Other -> - ?line io:format("Unexpected: ~p", [Other]), - ?line ?t:fail() + io:format("Unexpected: ~p", [Other]), + ct:fail(failed) end, - ?t:messages_get(), process_flag(trap_exit, OldFl), ok. @@ -534,12 +528,11 @@ terminate_crash_format(Config) when is_list(Config) -> ok; Other -> io:format("Unexpected: ~p", [Other]), - ?t:fail() + ct:fail(failed) after 5000 -> io:format("Timeout: expected error logger msg", []), - ?t:fail() + ct:fail(failed) end, - _ = ?t:messages_get(), process_flag(trap_exit, OldFl), ok. @@ -603,7 +596,9 @@ hibernate(Config) when is_list(Config) -> {ok, Pid0} = gen_fsm:start_link(?MODULE, hiber_now, []), is_in_erlang_hibernate(Pid0), stop_it(Pid0), - test_server:messages_get(), + receive + {'EXIT',Pid0,normal} -> ok + end, {ok, Pid} = gen_fsm:start_link(?MODULE, hiber, []), true = ({current_function,{erlang,hibernate,3}} =/= @@ -677,7 +672,11 @@ hibernate(Config) when is_list(Config) -> good_morning = gen_fsm:sync_send_all_state_event(Pid, wakeup_sync), is_not_in_erlang_hibernate(Pid), stop_it(Pid), - test_server:messages_get(), + receive + {'EXIT',Pid,normal} -> ok + end, + + [] = get_messages(), process_flag(trap_exit, OldFl), ok. @@ -687,7 +686,7 @@ is_in_erlang_hibernate(Pid) -> is_in_erlang_hibernate_1(0, Pid) -> io:format("~p\n", [erlang:process_info(Pid, current_function)]), - ?t:fail(not_in_erlang_hibernate_3); + ct:fail(not_in_erlang_hibernate_3); is_in_erlang_hibernate_1(N, Pid) -> {current_function,MFA} = erlang:process_info(Pid, current_function), case MFA of @@ -704,7 +703,7 @@ is_not_in_erlang_hibernate(Pid) -> is_not_in_erlang_hibernate_1(0, Pid) -> io:format("~p\n", [erlang:process_info(Pid, current_function)]), - ?t:fail(not_in_erlang_hibernate_3); + ct:fail(not_in_erlang_hibernate_3); is_not_in_erlang_hibernate_1(N, Pid) -> {current_function,MFA} = erlang:process_info(Pid, current_function), case MFA of @@ -715,108 +714,102 @@ is_not_in_erlang_hibernate_1(N, Pid) -> ok end. -%%sys1(suite) -> []; -%%sys1(_) -> - -enter_loop(suite) -> - []; -enter_loop(doc) -> - ["Test gen_fsm:enter_loop/4,5,6"]; +%% Test gen_fsm:enter_loop/4,5,6. enter_loop(Config) when is_list(Config) -> OldFlag = process_flag(trap_exit, true), - ?line dummy_via:reset(), + dummy_via:reset(), %% Locally registered process + {local, Name} - ?line {ok, Pid1a} = + {ok, Pid1a} = proc_lib:start_link(?MODULE, enter_loop, [local, local]), - ?line yes = gen_fsm:sync_send_event(Pid1a, 'alive?'), - ?line stopped = gen_fsm:sync_send_event(Pid1a, stop), + yes = gen_fsm:sync_send_event(Pid1a, 'alive?'), + stopped = gen_fsm:sync_send_event(Pid1a, stop), receive {'EXIT', Pid1a, normal} -> ok after 5000 -> - ?line test_server:fail(gen_fsm_did_not_die) + ct:fail(gen_fsm_did_not_die) end, %% Unregistered process + {local, Name} - ?line {ok, Pid1b} = + {ok, Pid1b} = proc_lib:start_link(?MODULE, enter_loop, [anon, local]), receive {'EXIT', Pid1b, process_not_registered} -> ok after 5000 -> - ?line test_server:fail(gen_fsm_did_not_die) + ct:fail(gen_fsm_did_not_die) end, %% Globally registered process + {global, Name} - ?line {ok, Pid2a} = + {ok, Pid2a} = proc_lib:start_link(?MODULE, enter_loop, [global, global]), - ?line yes = gen_fsm:sync_send_event(Pid2a, 'alive?'), - ?line stopped = gen_fsm:sync_send_event(Pid2a, stop), + yes = gen_fsm:sync_send_event(Pid2a, 'alive?'), + stopped = gen_fsm:sync_send_event(Pid2a, stop), receive {'EXIT', Pid2a, normal} -> ok after 5000 -> - ?line test_server:fail(gen_fsm_did_not_die) + ct:fail(gen_fsm_did_not_die) end, %% Unregistered process + {global, Name} - ?line {ok, Pid2b} = + {ok, Pid2b} = proc_lib:start_link(?MODULE, enter_loop, [anon, global]), receive {'EXIT', Pid2b, process_not_registered_globally} -> ok after 5000 -> - ?line test_server:fail(gen_fsm_did_not_die) + ct:fail(gen_fsm_did_not_die) end, %% Unregistered process + no name - ?line {ok, Pid3} = + {ok, Pid3} = proc_lib:start_link(?MODULE, enter_loop, [anon, anon]), - ?line yes = gen_fsm:sync_send_event(Pid3, 'alive?'), - ?line stopped = gen_fsm:sync_send_event(Pid3, stop), + yes = gen_fsm:sync_send_event(Pid3, 'alive?'), + stopped = gen_fsm:sync_send_event(Pid3, stop), receive {'EXIT', Pid3, normal} -> ok after 5000 -> - ?line test_server:fail(gen_fsm_did_not_die) + ct:fail(gen_fsm_did_not_die) end, %% Process not started using proc_lib - ?line Pid4 = + Pid4 = spawn_link(gen_fsm, enter_loop, [?MODULE, [], state0, []]), receive {'EXIT', Pid4, process_was_not_started_by_proc_lib} -> ok after 5000 -> - ?line test_server:fail(gen_fsm_did_not_die) + ct:fail(gen_fsm_did_not_die) end, %% Make sure I am the parent, ie that ordering a shutdown will %% result in the process terminating with Reason==shutdown - ?line {ok, Pid5} = + {ok, Pid5} = proc_lib:start_link(?MODULE, enter_loop, [anon, anon]), - ?line yes = gen_fsm:sync_send_event(Pid5, 'alive?'), - ?line exit(Pid5, shutdown), + yes = gen_fsm:sync_send_event(Pid5, 'alive?'), + exit(Pid5, shutdown), receive {'EXIT', Pid5, shutdown} -> ok after 5000 -> - ?line test_server:fail(gen_fsm_did_not_die) + ct:fail(gen_fsm_did_not_die) end, %% Make sure gen_fsm:enter_loop does not accept {local,Name} %% when it's another process than the calling one which is %% registered under that name register(armitage, self()), - ?line {ok, Pid6a} = + {ok, Pid6a} = proc_lib:start_link(?MODULE, enter_loop, [anon, local]), receive {'EXIT', Pid6a, process_not_registered} -> ok after 1000 -> - ?line test_server:fail(gen_fsm_started) + ct:fail(gen_fsm_started) end, unregister(armitage), @@ -824,25 +817,24 @@ enter_loop(Config) when is_list(Config) -> %% when it's another process than the calling one which is %% registered under that name global:register_name(armitage, self()), - ?line {ok, Pid6b} = + {ok, Pid6b} = proc_lib:start_link(?MODULE, enter_loop, [anon, global]), receive {'EXIT', Pid6b, process_not_registered_globally} -> ok after 1000 -> - ?line test_server:fail(gen_fsm_started) + ct:fail(gen_fsm_started) end, global:unregister_name(armitage), dummy_via:register_name(armitage, self()), - ?line {ok, Pid6c} = + {ok, Pid6c} = proc_lib:start_link(?MODULE, enter_loop, [anon, via]), receive {'EXIT', Pid6c, {process_not_registered_via, dummy_via}} -> ok after 1000 -> - ?line test_server:fail({gen_fsm_started, process_info(self(), - messages)}) + ct:fail({gen_fsm_started, process_info(self(), messages)}) end, dummy_via:unregister_name(armitage), @@ -883,8 +875,8 @@ wfor(Msg) -> stop_it(FSM) -> - ?line stopped = gen_fsm:sync_send_all_state_event(FSM, stop), - ?line {'EXIT',_} = (catch gen_fsm:sync_send_event(FSM, hej)), + stopped = gen_fsm:sync_send_all_state_event(FSM, stop), + {'EXIT',_} = (catch gen_fsm:sync_send_event(FSM, hej)), ok. @@ -895,7 +887,7 @@ do_func_test(FSM) -> ok = do_connect(FSM), ok = gen_fsm:send_all_state_event(FSM, {'alive?', self()}), wfor(yes), - test_server:do_times(3, ?MODULE, do_msg, [FSM]), + _ = [do_msg(FSM) || _ <- lists:seq(1, 3)], ok = gen_fsm:send_all_state_event(FSM, {'alive?', self()}), wfor(yes), ok = do_disconnect(FSM), @@ -933,7 +925,7 @@ do_sync_func_test(FSM) -> yes = gen_fsm:sync_send_all_state_event(FSM, 'alive?'), ok = do_sync_connect(FSM), yes = gen_fsm:sync_send_all_state_event(FSM, 'alive?'), - test_server:do_times(3, ?MODULE, do_sync_msg, [FSM]), + _ = [do_sync_msg(FSM) || _ <- lists:seq(1, 3)], yes = gen_fsm:sync_send_all_state_event(FSM, 'alive?'), ok = do_sync_disconnect(FSM), yes = gen_fsm:sync_send_all_state_event(FSM, 'alive?'), @@ -964,7 +956,7 @@ do_sync_disconnect(FSM) -> yes = gen_fsm:sync_send_event(FSM, disconnect), check_state(FSM, idle). - + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% @@ -979,7 +971,7 @@ init(stop) -> init(stop_shutdown) -> {stop, shutdown}; init(sleep) -> - test_server:sleep(1000), + ct:sleep(1000), {ok, idle, data}; init({timeout, T}) -> {ok, idle, state, T}; @@ -1012,7 +1004,7 @@ idle(_, Data) -> idle({connect, _Pid}, _From, Data) -> {reply, accept, wfor_conf, Data}; idle({delayed_answer, T}, _From, Data) -> - test_server:sleep(T), + ct:sleep(T), {reply, delayed, idle, Data}; idle(badreturn, _From, _Data) -> badreturn; @@ -1070,8 +1062,8 @@ hiber_idle('alive?', _From, Data) -> {reply, 'alive!', hiber_idle, Data}; hiber_idle(hibernate_sync, _From, Data) -> {reply, hibernating, hiber_wakeup, Data,hibernate}. -hiber_idle(timeout, hibernate_me) -> % Arrive here from - % handle_info(hibernate_later,...) +hiber_idle(timeout, hibernate_me) -> + %% Arrive here from handle_info(hibernate_later,...) {next_state, hiber_idle, [], hibernate}; hiber_idle(hibernate_async, Data) -> {next_state,hiber_wakeup, Data, hibernate}. @@ -1084,9 +1076,10 @@ hiber_wakeup(wakeup_async,Data) -> {next_state,hiber_idle,Data}; hiber_wakeup(snooze_async,Data) -> {next_state,hiber_wakeup,Data,hibernate}. - -handle_info(hibernate_now, _SName, _State) -> % Arrive here from by direct ! from testcase + +handle_info(hibernate_now, _SName, _State) -> + %% Arrive here from by direct ! from testcase {next_state, hiber_idle, [], hibernate}; handle_info(hibernate_later, _SName, _State) -> {next_state, hiber_idle, hibernate_me, 1000}; @@ -1134,3 +1127,9 @@ format_status(terminate, [_Pdict, StateData]) -> {formatted, StateData}; format_status(normal, [_Pdict, _StateData]) -> [format_status_called]. + +get_messages() -> + receive + Msg -> [Msg|get_messages()] + after 1 -> [] + end. diff --git a/lib/stdlib/test/gen_server_SUITE.erl b/lib/stdlib/test/gen_server_SUITE.erl index 634d868ad4..916fbc4e84 100644 --- a/lib/stdlib/test/gen_server_SUITE.erl +++ b/lib/stdlib/test/gen_server_SUITE.erl @@ -40,7 +40,7 @@ -export([stop1/1, stop2/1, stop3/1, stop4/1, stop5/1, stop6/1, stop7/1, stop8/1, stop9/1, stop10/1]). -% spawn export +%% spawn export -export([spec_init_local/2, spec_init_global/2, spec_init_via/2, spec_init_default_timeout/2, spec_init_global_default_timeout/2, spec_init_anonymous/1, @@ -48,11 +48,13 @@ spec_init_not_proc_lib/1, cast_fast_messup/0]). -% The gen_server behaviour +%% The gen_server behaviour -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, format_status/2]). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [start, {group,stop}, crash, call, cast, cast_fast, info, abcast, @@ -83,8 +85,6 @@ end_per_group(_GroupName, Config) -> Config. --define(default_timeout, ?t:minutes(1)). - init_per_testcase(Case, Config) when Case == call_remote1; Case == call_remote2; Case == call_remote3; @@ -92,11 +92,10 @@ init_per_testcase(Case, Config) when Case == call_remote1; Case == call_remote_n2; Case == call_remote_n3 -> {ok,N} = start_node(hubba), - ?line Dog = ?t:timetrap(?default_timeout), - [{node,N},{watchdog, Dog} | Config]; + [{node,N} | Config]; init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. + Config. + end_per_testcase(_Case, Config) -> case proplists:get_value(node, Config) of undefined -> @@ -104,8 +103,6 @@ end_per_testcase(_Case, Config) -> N -> test_server:stop_node(N) end, - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), ok. @@ -113,131 +110,133 @@ end_per_testcase(_Case, Config) -> %% Start and stop a gen_server. %% -------------------------------------- -start(suite) -> []; start(Config) when is_list(Config) -> OldFl = process_flag(trap_exit, true), %% anonymous - ?line {ok, Pid0} = gen_server:start(gen_server_SUITE, [], []), - ?line ok = gen_server:call(Pid0, started_p), - ?line ok = gen_server:call(Pid0, stop), - ?line busy_wait_for_process(Pid0,600), - ?line {'EXIT', {noproc,_}} = (catch gen_server:call(Pid0, started_p, 1)), + {ok, Pid0} = gen_server:start(gen_server_SUITE, [], []), + ok = gen_server:call(Pid0, started_p), + ok = gen_server:call(Pid0, stop), + busy_wait_for_process(Pid0,600), + {'EXIT', {noproc,_}} = (catch gen_server:call(Pid0, started_p, 1)), %% anonymous with timeout - ?line {ok, Pid00} = gen_server:start(gen_server_SUITE, [], - [{timeout,1000}]), - ?line ok = gen_server:call(Pid00, started_p), - ?line ok = gen_server:call(Pid00, stop), - ?line {error, timeout} = gen_server:start(gen_server_SUITE, sleep, - [{timeout,100}]), + {ok, Pid00} = gen_server:start(gen_server_SUITE, [], + [{timeout,1000}]), + ok = gen_server:call(Pid00, started_p), + ok = gen_server:call(Pid00, stop), + {error, timeout} = gen_server:start(gen_server_SUITE, sleep, + [{timeout,100}]), %% anonymous with ignore - ?line ignore = gen_server:start(gen_server_SUITE, ignore, []), + ignore = gen_server:start(gen_server_SUITE, ignore, []), %% anonymous with stop - ?line {error, stopped} = gen_server:start(gen_server_SUITE, stop, []), + {error, stopped} = gen_server:start(gen_server_SUITE, stop, []), %% anonymous linked - ?line {ok, Pid1} = + {ok, Pid1} = gen_server:start_link(gen_server_SUITE, [], []), - ?line ok = gen_server:call(Pid1, started_p), - ?line ok = gen_server:call(Pid1, stop), - ?line receive - {'EXIT', Pid1, stopped} -> - ok - after 5000 -> - test_server:fail(not_stopped) - end, + ok = gen_server:call(Pid1, started_p), + ok = gen_server:call(Pid1, stop), + receive + {'EXIT', Pid1, stopped} -> + ok + after 5000 -> + ct:fail(not_stopped) + end, %% local register - ?line {ok, Pid2} = + {ok, Pid2} = gen_server:start({local, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call(my_test_name, started_p), - ?line {error, {already_started, Pid2}} = + ok = gen_server:call(my_test_name, started_p), + {error, {already_started, Pid2}} = gen_server:start({local, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call(my_test_name, stop), + ok = gen_server:call(my_test_name, stop), - ?line busy_wait_for_process(Pid2,600), + busy_wait_for_process(Pid2,600), - ?line {'EXIT', {noproc,_}} = (catch gen_server:call(Pid2, started_p, 10)), + {'EXIT', {noproc,_}} = (catch gen_server:call(Pid2, started_p, 10)), %% local register linked - ?line {ok, Pid3} = + {ok, Pid3} = gen_server:start_link({local, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call(my_test_name, started_p), - ?line {error, {already_started, Pid3}} = + ok = gen_server:call(my_test_name, started_p), + {error, {already_started, Pid3}} = gen_server:start({local, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call(my_test_name, stop), - ?line receive - {'EXIT', Pid3, stopped} -> - ok - after 5000 -> - test_server:fail(not_stopped) - end, + ok = gen_server:call(my_test_name, stop), + receive + {'EXIT', Pid3, stopped} -> + ok + after 5000 -> + ct:fail(not_stopped) + end, %% global register - ?line {ok, Pid4} = + {ok, Pid4} = gen_server:start({global, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call({global, my_test_name}, started_p), - ?line {error, {already_started, Pid4}} = + ok = gen_server:call({global, my_test_name}, started_p), + {error, {already_started, Pid4}} = gen_server:start({global, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call({global, my_test_name}, stop), - test_server:sleep(1), - ?line {'EXIT', {noproc,_}} = (catch gen_server:call(Pid4, started_p, 10)), + ok = gen_server:call({global, my_test_name}, stop), + ct:sleep(1), + {'EXIT', {noproc,_}} = (catch gen_server:call(Pid4, started_p, 10)), %% global register linked - ?line {ok, Pid5} = + {ok, Pid5} = gen_server:start_link({global, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call({global, my_test_name}, started_p), - ?line {error, {already_started, Pid5}} = + ok = gen_server:call({global, my_test_name}, started_p), + {error, {already_started, Pid5}} = gen_server:start({global, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call({global, my_test_name}, stop), - ?line receive - {'EXIT', Pid5, stopped} -> - ok - after 5000 -> - test_server:fail(not_stopped) - end, + ok = gen_server:call({global, my_test_name}, stop), + receive + {'EXIT', Pid5, stopped} -> + ok + after 5000 -> + ct:fail(not_stopped) + end, %% via register - ?line dummy_via:reset(), - ?line {ok, Pid6} = + dummy_via:reset(), + {ok, Pid6} = gen_server:start({via, dummy_via, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call({via, dummy_via, my_test_name}, started_p), - ?line {error, {already_started, Pid6}} = + ok = gen_server:call({via, dummy_via, my_test_name}, started_p), + {error, {already_started, Pid6}} = gen_server:start({via, dummy_via, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call({via, dummy_via, my_test_name}, stop), - test_server:sleep(1), - ?line {'EXIT', {noproc,_}} = (catch gen_server:call(Pid6, started_p, 10)), + ok = gen_server:call({via, dummy_via, my_test_name}, stop), + ct:sleep(1), + {'EXIT', {noproc,_}} = (catch gen_server:call(Pid6, started_p, 10)), %% via register linked - ?line dummy_via:reset(), - ?line {ok, Pid7} = + dummy_via:reset(), + {ok, Pid7} = gen_server:start_link({via, dummy_via, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call({via, dummy_via, my_test_name}, started_p), - ?line {error, {already_started, Pid7}} = + ok = gen_server:call({via, dummy_via, my_test_name}, started_p), + {error, {already_started, Pid7}} = gen_server:start({via, dummy_via, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call({via, dummy_via, my_test_name}, stop), - ?line receive - {'EXIT', Pid7, stopped} -> - ok - after 5000 -> - test_server:fail(not_stopped) - end, - test_server:messages_get(), + ok = gen_server:call({via, dummy_via, my_test_name}, stop), + receive + {'EXIT', Pid7, stopped} -> + ok + after 5000 -> + ct:fail(not_stopped) + end, + receive + Msg -> ct:fail({unexpected,Msg}) + after 1 -> ok + end, process_flag(trap_exit, OldFl), ok. @@ -294,7 +293,7 @@ stop6(_Config) -> stop7(_Config) -> dummy_via:reset(), {ok, Pid} = gen_server:start({via, dummy_via, to_stop}, - ?MODULE, [], []), + ?MODULE, [], []), ok = gen_server:stop({via, dummy_via, to_stop}), false = erlang:is_process_alive(Pid), {'EXIT',noproc} = (catch gen_server:stop({via, dummy_via, to_stop})), @@ -342,31 +341,31 @@ stop10(_Config) -> ok. crash(Config) when is_list(Config) -> - ?line error_logger_forwarder:register(), + error_logger_forwarder:register(), process_flag(trap_exit, true), %% This crash should not generate a crash report. - ?line {ok,Pid0} = gen_server:start_link(?MODULE, [], []), - ?line {'EXIT',{{shutdown,reason},_}} = + {ok,Pid0} = gen_server:start_link(?MODULE, [], []), + {'EXIT',{{shutdown,reason},_}} = (catch gen_server:call(Pid0, shutdown_reason)), receive {'EXIT',Pid0,{shutdown,reason}} -> ok end, %% This crash should not generate a crash report. - ?line {ok,Pid1} = gen_server:start_link(?MODULE, {state,state1}, []), - ?line {'EXIT',{{shutdown,stop_reason},_}} = + {ok,Pid1} = gen_server:start_link(?MODULE, {state,state1}, []), + {'EXIT',{{shutdown,stop_reason},_}} = (catch gen_server:call(Pid1, stop_shutdown_reason)), receive {'EXIT',Pid1,{shutdown,stop_reason}} -> ok end, %% This crash should not generate a crash report. - ?line {ok,Pid2} = gen_server:start_link(?MODULE, [], []), - ?line {'EXIT',{shutdown,_}} = + {ok,Pid2} = gen_server:start_link(?MODULE, [], []), + {'EXIT',{shutdown,_}} = (catch gen_server:call(Pid2, exit_shutdown)), receive {'EXIT',Pid2,shutdown} -> ok end, %% This crash should not generate a crash report. - ?line {ok,Pid3} = gen_server:start_link(?MODULE, {state,state3}, []), - ?line {'EXIT',{shutdown,_}} = + {ok,Pid3} = gen_server:start_link(?MODULE, {state,state3}, []), + {'EXIT',{shutdown,_}} = (catch gen_server:call(Pid3, stop_shutdown)), receive {'EXIT',Pid3,shutdown} -> ok end, @@ -374,8 +373,8 @@ crash(Config) when is_list(Config) -> %% This crash should generate a crash report and a report %% from gen_server. - ?line {ok,Pid4} = gen_server:start(?MODULE, {state,state4}, []), - ?line {'EXIT',{crashed,_}} = (catch gen_server:call(Pid4, crash)), + {ok,Pid4} = gen_server:start(?MODULE, {state,state4}, []), + {'EXIT',{crashed,_}} = (catch gen_server:call(Pid4, crash)), receive {error,_GroupLeader4,{Pid4, "** Generic server"++_, @@ -384,22 +383,22 @@ crash(Config) when is_list(Config) -> |_Stacktrace]}]}} -> ok; Other4a -> - ?line io:format("Unexpected: ~p", [Other4a]), - ?line ?t:fail() + io:format("Unexpected: ~p", [Other4a]), + ct:fail(failed) end, receive {error_report,_,{Pid4,crash_report,[List4|_]}} -> {exit,crashed,_} = proplists:get_value(error_info, List4), Pid4 = proplists:get_value(pid, List4); Other4 -> - ?line io:format("Unexpected: ~p", [Other4]), - ?line ?t:fail() + io:format("Unexpected: ~p", [Other4]), + ct:fail(failed) end, receive Any -> - ?line io:format("Unexpected: ~p", [Any]), - ?line ?t:fail() + io:format("Unexpected: ~p", [Any]), + ct:fail(failed) after 500 -> ok end, @@ -412,32 +411,31 @@ crash(Config) when is_list(Config) -> %% handle_call. %% -------------------------------------- -call(suite) -> []; call(Config) when is_list(Config) -> OldFl = process_flag(trap_exit, true), - ?line {ok, _Pid} = + {ok, _Pid} = gen_server:start_link({local, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call(my_test_name, started_p), - ?line delayed = gen_server:call(my_test_name, {delayed_answer,1}), + ok = gen_server:call(my_test_name, started_p), + delayed = gen_server:call(my_test_name, {delayed_answer,1}), %% two requests within a specified time. - ?line ok = gen_server:call(my_test_name, {call_within, 1000}), - test_server:sleep(500), - ?line ok = gen_server:call(my_test_name, next_call), - ?line ok = gen_server:call(my_test_name, {call_within, 1000}), - test_server:sleep(1500), - ?line false = gen_server:call(my_test_name, next_call), - + ok = gen_server:call(my_test_name, {call_within, 1000}), + timer:sleep(500), + ok = gen_server:call(my_test_name, next_call), + ok = gen_server:call(my_test_name, {call_within, 1000}), + timer:sleep(1500), + false = gen_server:call(my_test_name, next_call), + %% timeout call. - ?line delayed = gen_server:call(my_test_name, {delayed_answer,1}, 30), - ?line {'EXIT',{timeout,_}} = + delayed = gen_server:call(my_test_name, {delayed_answer,1}, 30), + {'EXIT',{timeout,_}} = (catch gen_server:call(my_test_name, {delayed_answer,30}, 1)), %% bad return value in the gen_server loop from handle_call. - ?line {'EXIT',{{bad_return_value, badreturn},_}} = + {'EXIT',{{bad_return_value, badreturn},_}} = (catch gen_server:call(my_test_name, badreturn)), process_flag(trap_exit, OldFl), @@ -448,92 +446,86 @@ call(Config) when is_list(Config) -> %% -------------------------------------- start_node(Name) -> - ?line Pa = filename:dirname(code:which(?MODULE)), - ?line N = test_server:start_node(Name, slave, [{args, " -pa " ++ Pa}]), + Pa = filename:dirname(code:which(?MODULE)), + N = test_server:start_node(Name, slave, [{args, " -pa " ++ Pa}]), %% After starting a slave, it takes a little while until global knows %% about it, even if nodes() includes it, so we make sure that global %% knows about it before registering something on all nodes. global:sync(), N. -call_remote1(suite) -> []; call_remote1(Config) when is_list(Config) -> N = hubba, - ?line Node = proplists:get_value(node,Config), - ?line {ok, Pid} = rpc:call(Node, gen_server, start, - [{global, N}, ?MODULE, [], []]), - ?line ok = (catch gen_server:call({global, N}, started_p, infinity)), - ?line exit(Pid, boom), - ?line {'EXIT', {Reason, _}} = (catch gen_server:call({global, N}, - started_p, infinity)), - ?line true = (Reason == noproc) orelse (Reason == boom), + Node = proplists:get_value(node,Config), + {ok, Pid} = rpc:call(Node, gen_server, start, + [{global, N}, ?MODULE, [], []]), + ok = (catch gen_server:call({global, N}, started_p, infinity)), + exit(Pid, boom), + {'EXIT', {Reason, _}} = (catch gen_server:call({global, N}, + started_p, infinity)), + true = (Reason == noproc) orelse (Reason == boom), ok. -call_remote2(suite) -> []; call_remote2(Config) when is_list(Config) -> - ?line N = hubba, - ?line Node = proplists:get_value(node,Config), - - ?line {ok, Pid} = rpc:call(Node, gen_server, start, - [{global, N}, ?MODULE, [], []]), - ?line ok = (catch gen_server:call(Pid, started_p, infinity)), - ?line exit(Pid, boom), - ?line {'EXIT', {Reason, _}} = (catch gen_server:call(Pid, - started_p, infinity)), - ?line true = (Reason == noproc) orelse (Reason == boom), + N = hubba, + Node = proplists:get_value(node,Config), + + {ok, Pid} = rpc:call(Node, gen_server, start, + [{global, N}, ?MODULE, [], []]), + ok = (catch gen_server:call(Pid, started_p, infinity)), + exit(Pid, boom), + {'EXIT', {Reason, _}} = (catch gen_server:call(Pid, + started_p, infinity)), + true = (Reason == noproc) orelse (Reason == boom), ok. -call_remote3(suite) -> []; call_remote3(Config) when is_list(Config) -> - ?line Node = proplists:get_value(node,Config), - - ?line {ok, Pid} = rpc:call(Node, gen_server, start, - [{local, piller}, ?MODULE, [], []]), - ?line ok = (catch gen_server:call({piller, Node}, started_p, infinity)), - ?line exit(Pid, boom), - ?line {'EXIT', {Reason, _}} = (catch gen_server:call({piller, Node}, - started_p, infinity)), - ?line true = (Reason == noproc) orelse (Reason == boom), + Node = proplists:get_value(node,Config), + + {ok, Pid} = rpc:call(Node, gen_server, start, + [{local, piller}, ?MODULE, [], []]), + ok = (catch gen_server:call({piller, Node}, started_p, infinity)), + exit(Pid, boom), + {'EXIT', {Reason, _}} = (catch gen_server:call({piller, Node}, + started_p, infinity)), + true = (Reason == noproc) orelse (Reason == boom), ok. %% -------------------------------------- %% Test call to nonexisting node %% -------------------------------------- -call_remote_n1(suite) -> []; call_remote_n1(Config) when is_list(Config) -> - ?line N = hubba, - ?line Node = proplists:get_value(node,Config), - ?line {ok, _Pid} = rpc:call(Node, gen_server, start, - [{global, N}, ?MODULE, [], []]), - ?line _ = test_server:stop_node(Node), - ?line {'EXIT', {noproc, _}} = + N = hubba, + Node = proplists:get_value(node,Config), + {ok, _Pid} = rpc:call(Node, gen_server, start, + [{global, N}, ?MODULE, [], []]), + _ = test_server:stop_node(Node), + {'EXIT', {noproc, _}} = (catch gen_server:call({global, N}, started_p, infinity)), ok. -call_remote_n2(suite) -> []; call_remote_n2(Config) when is_list(Config) -> - ?line N = hubba, - ?line Node = proplists:get_value(node,Config), + N = hubba, + Node = proplists:get_value(node,Config), - ?line {ok, Pid} = rpc:call(Node, gen_server, start, - [{global, N}, ?MODULE, [], []]), - ?line _ = test_server:stop_node(Node), - ?line {'EXIT', {{nodedown, Node}, _}} = (catch gen_server:call(Pid, - started_p, infinity)), + {ok, Pid} = rpc:call(Node, gen_server, start, + [{global, N}, ?MODULE, [], []]), + _ = test_server:stop_node(Node), + {'EXIT', {{nodedown, Node}, _}} = (catch gen_server:call(Pid, + started_p, infinity)), ok. -call_remote_n3(suite) -> []; call_remote_n3(Config) when is_list(Config) -> - ?line Node = proplists:get_value(node,Config), + Node = proplists:get_value(node,Config), - ?line {ok, _Pid} = rpc:call(Node, gen_server, start, - [{local, piller}, ?MODULE, [], []]), - ?line _ = test_server:stop_node(Node), - ?line {'EXIT', {{nodedown, Node}, _}} = (catch gen_server:call({piller, Node}, - started_p, infinity)), + {ok, _Pid} = rpc:call(Node, gen_server, start, + [{local, piller}, ?MODULE, [], []]), + _ = test_server:stop_node(Node), + {'EXIT', {{nodedown, Node}, _}} = (catch gen_server:call({piller, Node}, + started_p, infinity)), ok. @@ -543,58 +535,56 @@ call_remote_n3(Config) when is_list(Config) -> %% handle_cast. %% -------------------------------------- -cast(suite) -> []; cast(Config) when is_list(Config) -> - ?line {ok, Pid} = + {ok, Pid} = gen_server:start({local, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call(my_test_name, started_p), - - ?line ok = gen_server:cast(my_test_name, {self(),handle_cast}), - ?line receive - {Pid, handled_cast} -> - ok - after 1000 -> - test_server:fail(handle_cast) - end, - - ?line ok = gen_server:cast(my_test_name, {self(),delayed_cast,1}), - ?line receive - {Pid, delayed} -> - ok - after 1000 -> - test_server:fail(delayed_cast) - end, - - ?line ok = gen_server:cast(my_test_name, {self(),stop}), - ?line receive - {Pid, stopped} -> - ok - after 1000 -> - test_server:fail(stop) - end, + ok = gen_server:call(my_test_name, started_p), + + ok = gen_server:cast(my_test_name, {self(),handle_cast}), + receive + {Pid, handled_cast} -> + ok + after 1000 -> + ct:fail(handle_cast) + end, + + ok = gen_server:cast(my_test_name, {self(),delayed_cast,1}), + receive + {Pid, delayed} -> + ok + after 1000 -> + ct:fail(delayed_cast) + end, + + ok = gen_server:cast(my_test_name, {self(),stop}), + receive + {Pid, stopped} -> + ok + after 1000 -> + ct:fail(stop) + end, ok. -cast_fast(suite) -> []; -cast_fast(doc) -> ["Test that cast really return immediately"]; +%% Test that cast really return immediately. cast_fast(Config) when is_list(Config) -> - ?line {ok,Node} = start_node(hubba), - ?line {_,"@"++Host} = lists:splitwith(fun ($@) -> false; (_) -> true end, - atom_to_list(Node)), - ?line FalseNode = list_to_atom("hopp@"++Host), - ?line true = rpc:cast(Node, ?MODULE, cast_fast_messup, []), -% ?line io:format("Nodes ~p~n", [rpc:call(N, ?MODULE, cast_fast_messup, [])]), - ?line test_server:sleep(1000), - ?line [Node] = nodes(), - ?line {Time,ok} = test_server:timecall(gen_server, cast, - [{hopp,FalseNode},hopp]), - ?line true = test_server:stop_node(Node), - ?line if Time > 1.0 -> % Default listen timeout is about 7.0 s - test_server:fail(hanging_cast); - true -> - ok - end. + {ok,Node} = start_node(hubba), + {_,"@"++Host} = lists:splitwith(fun ($@) -> false; (_) -> true end, + atom_to_list(Node)), + FalseNode = list_to_atom("hopp@"++Host), + true = rpc:cast(Node, ?MODULE, cast_fast_messup, []), + ct:sleep(1000), + [Node] = nodes(), + {Time,ok} = timer:tc(fun() -> + gen_server:cast({hopp,FalseNode}, hopp) + end), + true = test_server:stop_node(Node), + if Time > 1000000 -> % Default listen timeout is about 7.0 s + ct:fail(hanging_cast); + true -> + ok + end. cast_fast_messup() -> %% Register a false node: hopp@hostname @@ -609,37 +599,36 @@ cast_fast_messup() -> %% Test handle_info. %% -------------------------------------- -info(suite) -> []; info(Config) when is_list(Config) -> - ?line {ok, Pid} = + {ok, Pid} = gen_server:start({local, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call(my_test_name, started_p), - - ?line Pid ! {self(),handle_info}, - ?line receive - {Pid, handled_info} -> - ok - after 1000 -> - test_server:fail(handle_info) - end, - - ?line Pid ! {self(),delayed_info,1}, - ?line receive - {Pid, delayed_info} -> - ok - after 1000 -> - test_server:fail(delayed_info) - end, - - ?line Pid ! {self(),stop}, - ?line receive - {Pid, stopped_info} -> - ok - after 1000 -> - test_server:fail(stop_info) - end, + ok = gen_server:call(my_test_name, started_p), + + Pid ! {self(),handle_info}, + receive + {Pid, handled_info} -> + ok + after 1000 -> + ct:fail(handle_info) + end, + + Pid ! {self(),delayed_info,1}, + receive + {Pid, delayed_info} -> + ok + after 1000 -> + ct:fail(delayed_info) + end, + + Pid ! {self(),stop}, + receive + {Pid, stopped_info} -> + ok + after 1000 -> + ct:fail(stop_info) + end, ok. hibernate(Config) when is_list(Config) -> @@ -653,7 +642,7 @@ hibernate(Config) when is_list(Config) -> {'EXIT', Pid0, stopped} -> ok after 5000 -> - test_server:fail(gen_server_did_not_die) + ct:fail(gen_server_did_not_die) end, {ok, Pid} = @@ -720,7 +709,7 @@ hibernate(Config) when is_list(Config) -> {'EXIT', Pid, stopped} -> ok after 5000 -> - test_server:fail(gen_server_did_not_die) + ct:fail(gen_server_did_not_die) end, process_flag(trap_exit, OldFl), ok. @@ -731,7 +720,7 @@ is_in_erlang_hibernate(Pid) -> is_in_erlang_hibernate_1(0, Pid) -> io:format("~p\n", [erlang:process_info(Pid, current_function)]), - ?t:fail(not_in_erlang_hibernate_3); + ct:fail(not_in_erlang_hibernate_3); is_in_erlang_hibernate_1(N, Pid) -> {current_function,MFA} = erlang:process_info(Pid, current_function), case MFA of @@ -748,38 +737,37 @@ is_in_erlang_hibernate_1(N, Pid) -> %% handle_cast. %% -------------------------------------- -abcast(suite) -> []; abcast(Config) when is_list(Config) -> - ?line {ok, Pid} = + {ok, Pid} = gen_server:start({local, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call(my_test_name, started_p), - - ?line abcast = gen_server:abcast(my_test_name, {self(),handle_cast}), - ?line receive - {Pid, handled_cast} -> - ok - after 1000 -> - test_server:fail(abcast) - end, - - ?line abcast = gen_server:abcast([node()], my_test_name, - {self(),delayed_cast,1}), - ?line receive - {Pid, delayed} -> - ok - after 1000 -> - test_server:fail(delayed_abcast) - end, - - ?line abcast = gen_server:abcast(my_test_name, {self(),stop}), - ?line receive - {Pid, stopped} -> - ok - after 1000 -> - test_server:fail(abcast_stop) - end, + ok = gen_server:call(my_test_name, started_p), + + abcast = gen_server:abcast(my_test_name, {self(),handle_cast}), + receive + {Pid, handled_cast} -> + ok + after 1000 -> + ct:fail(abcast) + end, + + abcast = gen_server:abcast([node()], my_test_name, + {self(),delayed_cast,1}), + receive + {Pid, delayed} -> + ok + after 1000 -> + ct:fail(delayed_abcast) + end, + + abcast = gen_server:abcast(my_test_name, {self(),stop}), + receive + {Pid, stopped} -> + ok + after 1000 -> + ct:fail(abcast_stop) + end, ok. %% -------------------------------------- @@ -788,58 +776,56 @@ abcast(Config) when is_list(Config) -> %% handle_call. %% -------------------------------------- -multicall(suite) -> []; multicall(Config) when is_list(Config) -> OldFl = process_flag(trap_exit, true), - ?line {ok, Pid} = + {ok, Pid} = gen_server:start_link({local, my_test_name}, gen_server_SUITE, [], []), - ?line ok = gen_server:call(my_test_name, started_p), + ok = gen_server:call(my_test_name, started_p), Nodes = nodes(), Node = node(), - ?line {[{Node,delayed}],Nodes} = - gen_server:multi_call(my_test_name, {delayed_answer,1}), + {[{Node,delayed}],Nodes} = + gen_server:multi_call(my_test_name, {delayed_answer,1}), %% two requests within a specified time. - ?line {[{Node,ok}],[]} = - gen_server:multi_call([Node], my_test_name, {call_within, 1000}), - test_server:sleep(500), - ?line {[{Node,ok}],[]} = - gen_server:multi_call([Node], my_test_name, next_call), - ?line {[{Node,ok}],[]} = - gen_server:multi_call([Node], my_test_name, {call_within, 1000}), - test_server:sleep(1500), - ?line {[{Node,false}],[]} = - gen_server:multi_call([Node],my_test_name, next_call), + {[{Node,ok}],[]} = + gen_server:multi_call([Node], my_test_name, {call_within, 1000}), + timer:sleep(500), + {[{Node,ok}],[]} = + gen_server:multi_call([Node], my_test_name, next_call), + {[{Node,ok}],[]} = + gen_server:multi_call([Node], my_test_name, {call_within, 1000}), + timer:sleep(1500), + {[{Node,false}],[]} = + gen_server:multi_call([Node],my_test_name, next_call), %% Stop the server. - ?line {[{Node,ok}],[]} = - gen_server:multi_call([Node],my_test_name, stop), + {[{Node,ok}],[]} = + gen_server:multi_call([Node],my_test_name, stop), receive {'EXIT', Pid, stopped} -> ok after 1000 -> - test_server:fail(multicall_stop) + ct:fail(multicall_stop) end, - + process_flag(trap_exit, OldFl), ok. %% OTP-3587 -multicall_down(suite) -> []; multicall_down(Config) when is_list(Config) -> %% We need a named host which is inaccessible. - ?line Name = node@test01, + Name = node@test01, %% We use 'global' as a gen_server to call. - ?line {Good, Bad} = gen_server:multi_call([Name, node()], - global_name_server, - info, - 3000), + {Good, Bad} = gen_server:multi_call([Name, node()], + global_name_server, + info, + 3000), io:format("good = ~p, bad = ~p~n", [Good, Bad]), - ?line [Name] = Bad, + [Name] = Bad, ok. busy_wait_for_process(Pid,N) -> @@ -854,82 +840,79 @@ busy_wait_for_process(Pid,N) -> ok end. %%-------------------------------------------------------------- -spec_init(doc) -> - ["Test gen_server:enter_loop/[3,4,5]. Used when you want to write " - "your own special init-phase."]; -spec_init(suite) -> - []; +%% Test gen_server:enter_loop/[3,4,5]. Used when you want to write +%% your own special init-phase. spec_init(Config) when is_list(Config) -> - + OldFlag = process_flag(trap_exit, true), - ?line {ok, Pid0} = start_link(spec_init_local, [{ok, my_server}, []]), - ?line ok = gen_server:call(Pid0, started_p), - ?line ok = gen_server:call(Pid0, stop), + {ok, Pid0} = start_link(spec_init_local, [{ok, my_server}, []]), + ok = gen_server:call(Pid0, started_p), + ok = gen_server:call(Pid0, stop), receive {'EXIT', Pid0, stopped} -> ok after 5000 -> - test_server:fail(gen_server_did_not_die) + ct:fail(gen_server_did_not_die) end, - - ?line {ok, Pid01} = start_link(spec_init_local, [{not_ok, my_server}, []]), + + {ok, Pid01} = start_link(spec_init_local, [{not_ok, my_server}, []]), receive {'EXIT', Pid01, process_not_registered} -> ok after 5000 -> - test_server:fail(gen_server_did_not_die) + ct:fail(gen_server_did_not_die) end, - - ?line {ok, Pid1} = start_link(spec_init_global, [{ok, my_server}, []]), - ?line ok = gen_server:call(Pid1, started_p), - ?line ok = gen_server:call(Pid1, stop), + + {ok, Pid1} = start_link(spec_init_global, [{ok, my_server}, []]), + ok = gen_server:call(Pid1, started_p), + ok = gen_server:call(Pid1, stop), receive {'EXIT', Pid1, stopped} -> ok after 5000 -> - test_server:fail(gen_server_did_not_die) + ct:fail(gen_server_did_not_die) end, - - ?line {ok, Pid11} = + + {ok, Pid11} = start_link(spec_init_global, [{not_ok, my_server}, []]), receive {'EXIT', Pid11, process_not_registered_globally} -> ok after 5000 -> - test_server:fail(gen_server_did_not_die) + ct:fail(gen_server_did_not_die) end, - - ?line {ok, Pid2} = start_link(spec_init_anonymous, [[]]), - ?line ok = gen_server:call(Pid2, started_p), - ?line ok = gen_server:call(Pid2, stop), + + {ok, Pid2} = start_link(spec_init_anonymous, [[]]), + ok = gen_server:call(Pid2, started_p), + ok = gen_server:call(Pid2, stop), receive {'EXIT', Pid2, stopped} -> ok after 5000 -> - test_server:fail(gen_server_did_not_die) + ct:fail(gen_server_did_not_die) end, - - ?line {ok, Pid3} = start_link(spec_init_anonymous_default_timeout, [[]]), - ?line ok = gen_server:call(Pid3, started_p), - ?line ok = gen_server:call(Pid3, stop), + + {ok, Pid3} = start_link(spec_init_anonymous_default_timeout, [[]]), + ok = gen_server:call(Pid3, started_p), + ok = gen_server:call(Pid3, stop), receive {'EXIT', Pid3, stopped} -> ok after 5000 -> - test_server:fail(gen_server_did_not_die) + ct:fail(gen_server_did_not_die) end, - - ?line {ok, Pid4} = + + {ok, Pid4} = start_link(spec_init_default_timeout, [{ok, my_server}, []]), - ?line ok = gen_server:call(Pid4, started_p), - ?line ok = gen_server:call(Pid4, stop), + ok = gen_server:call(Pid4, started_p), + ok = gen_server:call(Pid4, stop), receive {'EXIT', Pid4, stopped} -> ok after 5000 -> - test_server:fail(gen_server_did_not_die) + ct:fail(gen_server_did_not_die) end, %% Before the OTP-10130 fix this failed because a timeout message @@ -939,83 +922,79 @@ spec_init(Config) when is_list(Config) -> start_link(spec_init_global_default_timeout, [{ok, hurra}, []]), timer:sleep(1000), ok = gen_server:call(_PidHurra, started_p), - - ?line Pid5 = + + Pid5 = erlang:spawn_link(?MODULE, spec_init_not_proc_lib, [[]]), receive {'EXIT', Pid5, process_was_not_started_by_proc_lib} -> ok after 5000 -> - test_server:fail(gen_server_did_not_die) + ct:fail(gen_server_did_not_die) end, process_flag(trap_exit, OldFlag), ok. %%-------------------------------------------------------------- -spec_init_local_registered_parent(doc) -> - ["Test that terminate is run when the parent is a locally registered " - "process OTP-4820"]; -spec_init_local_registered_parent(suite) -> []; +%% OTP-4820. Test that terminate is run when the parent is a locally +%% registered process. spec_init_local_registered_parent(Config) when is_list(Config) -> register(foobar, self()), process_flag(trap_exit, true), - - ?line {ok, Pid} = start_link(spec_init_local, [{ok, my_server}, []]), - - ?line ok = gen_server:cast(my_server, {self(),stop}), - ?line receive - {Pid, stopped} -> - ok - after 1000 -> - test_server:fail(stop) - end, + + {ok, Pid} = start_link(spec_init_local, [{ok, my_server}, []]), + + ok = gen_server:cast(my_server, {self(),stop}), + receive + {Pid, stopped} -> + ok + after 1000 -> + ct:fail(stop) + end, unregister(foobar), ok. + %%-------------------------------------------------------------- -spec_init_global_registered_parent(doc) -> - ["Test that terminate is run when the parent is a global registered " - "process OTP-4820"]; -spec_init_global_registered_parent(suite) -> []; +%% OTP-4820. Test that terminate is run when the parent is a global registered +%% process. spec_init_global_registered_parent(Config) when is_list(Config) -> global:register_name(foobar, self()), process_flag(trap_exit, true), - - ?line {ok, Pid} = start_link(spec_init_global, [{ok, my_server}, []]), - - ?line ok = gen_server:call(Pid, started_p), - ?line ok = gen_server:cast(Pid, {self(),stop}), - - ?line receive - {Pid, stopped} -> - ok - after 1000 -> - test_server:fail(stop) - end, + + {ok, Pid} = start_link(spec_init_global, [{ok, my_server}, []]), + + ok = gen_server:call(Pid, started_p), + ok = gen_server:cast(Pid, {self(),stop}), + + receive + {Pid, stopped} -> + ok + after 1000 -> + ct:fail(stop) + end, global:unregister_name(foobar), ok. + %%-------------------------------------------------------------- -otp_5854(suite) -> - []; -otp_5854(doc) -> - ["Test check for registered name in enter_loop/3,4,5"]; + +%% Test check for registered name in enter_loop/3,4,5. otp_5854(Config) when is_list(Config) -> OldFlag = process_flag(trap_exit, true), - ?line dummy_via:reset(), + dummy_via:reset(), %% Make sure gen_server:enter_loop does not accept {local,Name} %% when it's another process than the calling one which is %% registered under that name register(armitage, self()), - ?line {ok, Pid1} = + {ok, Pid1} = start_link(spec_init_local, [{not_ok, armitage}, []]), receive {'EXIT', Pid1, process_not_registered} -> ok after 1000 -> - ?line test_server:fail(gen_server_started) + ct:fail(gen_server_started) end, unregister(armitage), @@ -1023,25 +1002,25 @@ otp_5854(Config) when is_list(Config) -> %% when it's another process than the calling one which is %% registered under that name global:register_name(armitage, self()), - ?line {ok, Pid2} = + {ok, Pid2} = start_link(spec_init_global, [{not_ok, armitage}, []]), receive {'EXIT', Pid2, process_not_registered_globally} -> ok after 1000 -> - ?line test_server:fail(gen_server_started) + ct:fail(gen_server_started) end, global:unregister_name(armitage), %% (same for {via, Mod, Name}) dummy_via:register_name(armitage, self()), - ?line {ok, Pid3} = + {ok, Pid3} = start_link(spec_init_via, [{not_ok, armitage}, []]), receive {'EXIT', Pid3, {process_not_registered_via, dummy_via}} -> ok after 1000 -> - ?line test_server:fail(gen_server_started) + ct:fail(gen_server_started) end, dummy_via:unregister_name(armitage), @@ -1053,89 +1032,85 @@ otp_5854(Config) when is_list(Config) -> %% returns. otp_7669(Config) when is_list(Config) -> - ?line ?t:do_times(100, fun do_otp_7669_local_ignore/0), - ?line ?t:do_times(100, fun do_otp_7669_global_ignore/0), - ?line ?t:do_times(10, fun do_otp_7669_stop/0), + do_times(100, fun do_otp_7669_local_ignore/0), + do_times(100, fun do_otp_7669_global_ignore/0), + do_times(10, fun do_otp_7669_stop/0), ok. +do_times(0, _) -> + ok; +do_times(N, Fun) -> + Fun(), + do_times(N-1, Fun). + do_otp_7669_local_ignore() -> %% The name should never be registered after the return %% from gen_server:start/3. - ?line ignore = gen_server:start({local,?MODULE}, ?MODULE, ignore, []), - ?line undefined = whereis(?MODULE), - ?line ignore = gen_server:start({local,?MODULE}, ?MODULE, ignore, []), - ?line undefined = whereis(?MODULE), - ?line ignore = gen_server:start_link({local,?MODULE}, ?MODULE, ignore, []), - ?line undefined = whereis(?MODULE). + ignore = gen_server:start({local,?MODULE}, ?MODULE, ignore, []), + undefined = whereis(?MODULE), + ignore = gen_server:start({local,?MODULE}, ?MODULE, ignore, []), + undefined = whereis(?MODULE), + ignore = gen_server:start_link({local,?MODULE}, ?MODULE, ignore, []), + undefined = whereis(?MODULE). do_otp_7669_global_ignore() -> - ?line ignore = gen_server:start({global,?MODULE}, ?MODULE, ignore, []), - ?line undefined = global:whereis_name(?MODULE), - ?line ignore = gen_server:start_link({global,?MODULE}, ?MODULE, ignore, []), - ?line undefined = global:whereis_name(?MODULE). + ignore = gen_server:start({global,?MODULE}, ?MODULE, ignore, []), + undefined = global:whereis_name(?MODULE), + ignore = gen_server:start_link({global,?MODULE}, ?MODULE, ignore, []), + undefined = global:whereis_name(?MODULE). do_otp_7669_stop() -> %% The name should never be registered after the return %% from gen_server:start/3. - ?line {error,stopped} = gen_server:start({local,?MODULE}, - ?MODULE, stop, []), - ?line undefined = whereis(?MODULE), + {error,stopped} = gen_server:start({local,?MODULE}, + ?MODULE, stop, []), + undefined = whereis(?MODULE), - ?line {error,stopped} = gen_server:start({global,?MODULE}, - ?MODULE, stop, []), - ?line undefined = global:whereis_name(?MODULE). + {error,stopped} = gen_server:start({global,?MODULE}, + ?MODULE, stop, []), + undefined = global:whereis_name(?MODULE). -%% Verify that sys:get_status correctly calls our format_status/2 fun -%% -call_format_status(suite) -> - []; -call_format_status(doc) -> - ["Test that sys:get_status/1,2 calls format_status/2"]; +%% Verify that sys:get_status correctly calls our format_status/2 fun. call_format_status(Config) when is_list(Config) -> - ?line {ok, Pid} = gen_server:start_link({local, call_format_status}, - ?MODULE, [], []), - ?line Status1 = sys:get_status(call_format_status), - ?line {status, Pid, _Mod, [_PDict, running, _Parent, _, Data1]} = Status1, - ?line [format_status_called | _] = lists:reverse(Data1), - ?line Status2 = sys:get_status(call_format_status, 5000), - ?line {status, Pid, _Mod, [_PDict, running, _Parent, _, Data2]} = Status2, - ?line [format_status_called | _] = lists:reverse(Data2), + {ok, Pid} = gen_server:start_link({local, call_format_status}, + ?MODULE, [], []), + Status1 = sys:get_status(call_format_status), + {status, Pid, _Mod, [_PDict, running, _Parent, _, Data1]} = Status1, + [format_status_called | _] = lists:reverse(Data1), + Status2 = sys:get_status(call_format_status, 5000), + {status, Pid, _Mod, [_PDict, running, _Parent, _, Data2]} = Status2, + [format_status_called | _] = lists:reverse(Data2), %% check that format_status can handle a name being a pid (atom is %% already checked by the previous test) - ?line {ok, Pid3} = gen_server:start_link(gen_server_SUITE, [], []), - ?line Status3 = sys:get_status(Pid3), - ?line {status, Pid3, _Mod, [_PDict3, running, _Parent, _, Data3]} = Status3, - ?line [format_status_called | _] = lists:reverse(Data3), + {ok, Pid3} = gen_server:start_link(gen_server_SUITE, [], []), + Status3 = sys:get_status(Pid3), + {status, Pid3, _Mod, [_PDict3, running, _Parent, _, Data3]} = Status3, + [format_status_called | _] = lists:reverse(Data3), %% check that format_status can handle a name being a term other than a %% pid or atom GlobalName1 = {global, "CallFormatStatus"}, - ?line {ok, Pid4} = gen_server:start_link(GlobalName1, - gen_server_SUITE, [], []), - ?line Status4 = sys:get_status(Pid4), - ?line {status, Pid4, _Mod, [_PDict4, running, _Parent, _, Data4]} = Status4, - ?line [format_status_called | _] = lists:reverse(Data4), + {ok, Pid4} = gen_server:start_link(GlobalName1, + gen_server_SUITE, [], []), + Status4 = sys:get_status(Pid4), + {status, Pid4, _Mod, [_PDict4, running, _Parent, _, Data4]} = Status4, + [format_status_called | _] = lists:reverse(Data4), GlobalName2 = {global, {name, "term"}}, - ?line {ok, Pid5} = gen_server:start_link(GlobalName2, - gen_server_SUITE, [], []), - ?line Status5 = sys:get_status(GlobalName2), - ?line {status, Pid5, _Mod, [_PDict5, running, _Parent, _, Data5]} = Status5, - ?line [format_status_called | _] = lists:reverse(Data5), + {ok, Pid5} = gen_server:start_link(GlobalName2, + gen_server_SUITE, [], []), + Status5 = sys:get_status(GlobalName2), + {status, Pid5, _Mod, [_PDict5, running, _Parent, _, Data5]} = Status5, + [format_status_called | _] = lists:reverse(Data5), ok. -%% Verify that error termination correctly calls our format_status/2 fun -%% -error_format_status(suite) -> - []; -error_format_status(doc) -> - ["Test that an error termination calls format_status/2"]; +%% Verify that error termination correctly calls our format_status/2 fun. error_format_status(Config) when is_list(Config) -> - ?line error_logger_forwarder:register(), + error_logger_forwarder:register(), OldFl = process_flag(trap_exit, true), State = "called format_status", - ?line {ok, Pid} = gen_server:start_link(?MODULE, {state, State}, []), - ?line {'EXIT',{crashed,_}} = (catch gen_server:call(Pid, crash)), + {ok, Pid} = gen_server:start_link(?MODULE, {state, State}, []), + {'EXIT',{crashed,_}} = (catch gen_server:call(Pid, crash)), receive {'EXIT', Pid, crashed} -> ok @@ -1148,10 +1123,9 @@ error_format_status(Config) when is_list(Config) -> |_Stacktrace]}]}} -> ok; Other -> - ?line io:format("Unexpected: ~p", [Other]), - ?line ?t:fail() + io:format("Unexpected: ~p", [Other]), + ct:fail(failed) end, - ?t:messages_get(), process_flag(trap_exit, OldFl), ok. @@ -1169,29 +1143,23 @@ terminate_crash_format(Config) when is_list(Config) -> "** Generic server"++_, [Pid,stop, {formatted, State}, {{crash, terminate},[{?MODULE,terminate,2,_} - |_Stacktrace]}]}} -> + |_Stacktrace]}]}} -> ok; Other -> io:format("Unexpected: ~p", [Other]), - ?t:fail() + ct:fail(failed) after 5000 -> io:format("Timeout: expected error logger msg", []), - ?t:fail() + ct:fail(failed) end, - ?t:messages_get(), process_flag(trap_exit, OldFl), ok. %% Verify that sys:get_state correctly returns gen_server state -%% -get_state(suite) -> - []; -get_state(doc) -> - ["Test that sys:get_state/1,2 return the gen_server state"]; get_state(Config) when is_list(Config) -> State = self(), {ok, _Pid} = gen_server:start_link({local, get_state}, - ?MODULE, {state,State}, []), + ?MODULE, {state,State}, []), State = sys:get_state(get_state), State = sys:get_state(get_state, 5000), {ok, Pid} = gen_server:start_link(?MODULE, {state,State}, []), @@ -1203,15 +1171,10 @@ get_state(Config) when is_list(Config) -> ok. %% Verify that sys:replace_state correctly replaces gen_server state -%% -replace_state(suite) -> - []; -replace_state(doc) -> - ["Test that sys:replace_state/1,2 replace the gen_server state"]; replace_state(Config) when is_list(Config) -> State = self(), {ok, _Pid} = gen_server:start_link({local, replace_state}, - ?MODULE, {state,State}, []), + ?MODULE, {state,State}, []), State = sys:get_state(replace_state), NState1 = "replaced", Replace1 = fun(_) -> NState1 end, @@ -1250,16 +1213,16 @@ call_with_huge_message_queue(Config) when is_list(Config) -> "is not implemented"}; false -> do_call_with_huge_message_queue() - end. + end. do_call_with_huge_message_queue() -> - ?line Pid = spawn_link(fun echo_loop/0), + Pid = spawn_link(fun echo_loop/0), - ?line {Time,ok} = tc(fun() -> calls(10000, Pid) end), + {Time,ok} = tc(fun() -> calls(10000, Pid) end), - ?line [self() ! {msg,N} || N <- lists:seq(1, 500000)], + [self() ! {msg,N} || N <- lists:seq(1, 500000)], erlang:garbage_collect(), - ?line {NewTime,ok} = tc(fun() -> calls(10000, Pid) end), + {NewTime,ok} = tc(fun() -> calls(10000, Pid) end), io:format("Time for empty message queue: ~p", [Time]), io:format("Time for huge message queue: ~p", [NewTime]), @@ -1269,7 +1232,7 @@ do_call_with_huge_message_queue() -> ok; Q -> io:format("Q = ~p", [Q]), - ?line ?t:fail() + ct:fail(failed) end, ok. @@ -1381,7 +1344,7 @@ init(stop) -> init(hibernate) -> {ok,[],hibernate}; init(sleep) -> - test_server:sleep(1000), + ct:sleep(1000), {ok, []}; init({state,State}) -> {ok, State}. @@ -1435,11 +1398,11 @@ handle_info(timeout, {reply_to, From}) -> gen_server:reply(From, delayed), {noreply, []}; handle_info(timeout, hibernate_me) -> % Arrive here from - % handle_info(hibernate_later,...) + % handle_info(hibernate_later,...) {noreply, [], hibernate}; handle_info(hibernate_now, _State) -> % Arrive here from - % handle_cast({_,hibernate_later},...) - % and by direct ! from testcase + % handle_cast({_,hibernate_later},...) + % and by direct ! from testcase {noreply, [], hibernate}; handle_info(hibernate_later, _State) -> {noreply, hibernate_me, 1000}; diff --git a/lib/stdlib/test/id_transform_SUITE.erl b/lib/stdlib/test/id_transform_SUITE.erl index a0c3c9317a..aaa6a758d5 100644 --- a/lib/stdlib/test/id_transform_SUITE.erl +++ b/lib/stdlib/test/id_transform_SUITE.erl @@ -29,11 +29,12 @@ -export([check/2,check2/1,g/0,f/1,t/1,t1/1,t2/1,t3/1,t4/1, t5/1,apa/1,new_fun/0]). - % Serves as test... +%% Serves as test... -hej(hopp). -include_lib("common_test/include/ct.hrl"). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}]. all() -> [id_transform]. @@ -54,7 +55,7 @@ end_per_group(_GroupName, Config) -> Config. -id_transform(doc) -> "Test erl_id_trans."; +%% Test erl_id_trans. id_transform(Config) when is_list(Config) -> File = filename:join([code:lib_dir(stdlib),"examples", "erl_id_trans.erl"]), @@ -62,10 +63,8 @@ id_transform(Config) when is_list(Config) -> {module,erl_id_trans} = code:load_binary(erl_id_trans, File, Bin), case test_server:purify_is_running() of false -> - Dog = ct:timetrap(?t:hours(1)), - Res = run_in_test_suite(), - ?t:timetrap_cancel(Dog), - Res; + ct:timetrap({hours,1}), + run_in_test_suite(); true -> {skip,"Valgrind (too slow)"} end. @@ -139,9 +138,9 @@ do_trans_1(File, Tree0) -> {failed,{File,{transform,{unknown,Else}}}} end. -% From here on there's only fake code to serve as test cases -% for the id_transform. -% They need to be exported. +%% From here on there's only fake code to serve as test cases +%% for the id_transform. +%% They need to be exported. check(X,_Y) when X -> true; @@ -192,7 +191,7 @@ f(X) -> nok end. -% Stolen from erl_lint_SUITE.erl +%% Stolen from erl_lint_SUITE.erl -record(apa, {}). t(A) when atom(A) -> diff --git a/lib/stdlib/test/io_SUITE.erl b/lib/stdlib/test/io_SUITE.erl index 2d56f2d502..ddc55b1466 100644 --- a/lib/stdlib/test/io_SUITE.erl +++ b/lib/stdlib/test/io_SUITE.erl @@ -26,7 +26,7 @@ -export([error_1/1, float_g/1, otp_5403/1, otp_5813/1, otp_6230/1, otp_6282/1, otp_6354/1, otp_6495/1, otp_6517/1, otp_6502/1, - manpage/1, otp_6708/1, otp_7084/1, otp_7421/1, + manpage/1, otp_6708/1, otp_7084/0, otp_7084/1, otp_7421/1, io_lib_collect_line_3_wb/1, cr_whitespace_in_string/1, io_fread_newlines/1, otp_8989/1, io_lib_fread_literal/1, printable_range/1, bad_printable_range/1, @@ -37,7 +37,7 @@ -export([pretty/2]). -%-define(debug, true). +%%-define(debug, true). -ifdef(debug). -define(format(S, A), io:format(S, A)). @@ -48,22 +48,18 @@ -else. -include_lib("common_test/include/ct.hrl"). -define(format(S, A), ok). --define(privdir(Conf), ?config(priv_dir, Conf)). +-define(privdir(Conf), proplists:get_value(priv_dir, Conf)). -endif. - -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(1)). - init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. + Config. + end_per_testcase(_Case, _Config) -> - Dog = ?config(watchdog, _Config), - test_server:timetrap_cancel(Dog), ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [error_1, float_g, otp_5403, otp_5813, otp_6230, @@ -92,855 +88,588 @@ end_per_group(_GroupName, Config) -> Config. -error_1(doc) -> - ["Error cases for output"]; -error_1(suite) -> - []; +%% Error cases for output. error_1(Config) when is_list(Config) -> %% We don't do erroneous output on stdout - the test server %% seems to catch that somehow. - ?line PrivDir = ?privdir(Config), - ?line File = filename:join(PrivDir, "slask"), - ?line {ok, F1} = file:open(File, [write]), - ?line {'EXIT', _} = (catch io:format(muttru, "hej", [])), - ?line {'EXIT', _} = (catch io:format(F1, pelle, "hej")), - ?line {'EXIT', _} = (catch io:format(F1, 1, "hej")), - ?line {'EXIT', _} = (catch io:format(F1, "~p~", [kaka])), - ?line {'EXIT', _} = (catch io:format(F1, "~m~n", [kaka])), + PrivDir = ?privdir(Config), + File = filename:join(PrivDir, "slask"), + {ok, F1} = file:open(File, [write]), + {'EXIT', _} = (catch io:format(muttru, "hej", [])), + {'EXIT', _} = (catch io:format(F1, pelle, "hej")), + {'EXIT', _} = (catch io:format(F1, 1, "hej")), + {'EXIT', _} = (catch io:format(F1, "~p~", [kaka])), + {'EXIT', _} = (catch io:format(F1, "~m~n", [kaka])), %% This causes the file process to die, and it is linked to us, %% so we can't catch the error this easily. -% ?line {'EXIT', _} = (catch io:put_chars(F1, 666)), + %% {'EXIT', _} = (catch io:put_chars(F1, 666)), - ?line file:close(F1), - ?line {'EXIT', _} = (catch io:format(F1, "~p", ["hej"])), + file:close(F1), + {'EXIT', _} = (catch io:format(F1, "~p", ["hej"])), ok. float_g(Config) when is_list(Config) -> - ?line ["5.00000e-2", - "0.500000", - "5.00000", - "50.0000", - "500.000", - "5000.00", - "5.00000e+4", - "5.00000e+5"] = float_g_1("~g", 5.0, -2, 5), - - ?line ["-5.0000e-2", - "-0.50000", - "-5.0000", - "-50.000", - "-500.00", - "-5000.0", - "-5.0000e+4", - "-5.0000e+5"] = float_g_1("~.5g", -5.0, -2, 5), - - ?line ["5.000e-2", - "0.5000", - "5.000", - "50.00", - "500.0", - "5.000e+3", - "5.000e+4", - "5.000e+5"] = float_g_1("~.4g", 5.0, -2, 5), - - ?line ["-5.00e-2", - "-0.500", - "-5.00", - "-50.0", - "-5.00e+2", - "-5.00e+3", - "-5.00e+4", - "-5.00e+5"] = float_g_1("~.3g", -5.0, -2, 5), - - ?line ["5.0e-2", - "0.50", - "5.0", - "5.0e+1", - "5.0e+2", - "5.0e+3", - "5.0e+4", - "5.0e+5"] = float_g_1("~.2g", 5.0, -2, 5), - - ?line - case catch fmt("~.1g", [0.5]) of - "0.5" -> - ?line - ["5.0e-2", - "0.5", - "5.0e+0", - "5.0e+1", - "5.0e+2", - "5.0e+3", - "5.0e+4", - "5.0e+5"] = float_g_1("~.1g", 5.0, -2, 5); - {'EXIT',_} -> ok - end, - - ?line ["4.99999e-2", - "0.499999", - "4.99999", - "49.9999", - "499.999", - "4999.99", - "4.99999e+4", - "4.99999e+5"] = float_g_1("~g", 4.9999949999, -2, 5), - - ?line ["-5.00000e-2", - "-0.500000", - "-5.00000", - "-50.0000", - "-500.000", - "-5000.00", - "-5.00000e+4", - "-5.00000e+5"] = float_g_1("~g", -4.9999950001, -2, 5), + ["5.00000e-2", + "0.500000", + "5.00000", + "50.0000", + "500.000", + "5000.00", + "5.00000e+4", + "5.00000e+5"] = float_g_1("~g", 5.0, -2, 5), + + ["-5.0000e-2", + "-0.50000", + "-5.0000", + "-50.000", + "-500.00", + "-5000.0", + "-5.0000e+4", + "-5.0000e+5"] = float_g_1("~.5g", -5.0, -2, 5), + + ["5.000e-2", + "0.5000", + "5.000", + "50.00", + "500.0", + "5.000e+3", + "5.000e+4", + "5.000e+5"] = float_g_1("~.4g", 5.0, -2, 5), + + ["-5.00e-2", + "-0.500", + "-5.00", + "-50.0", + "-5.00e+2", + "-5.00e+3", + "-5.00e+4", + "-5.00e+5"] = float_g_1("~.3g", -5.0, -2, 5), + + ["5.0e-2", + "0.50", + "5.0", + "5.0e+1", + "5.0e+2", + "5.0e+3", + "5.0e+4", + "5.0e+5"] = float_g_1("~.2g", 5.0, -2, 5), + + case catch fmt("~.1g", [0.5]) of + "0.5" -> + ["5.0e-2", + "0.5", + "5.0e+0", + "5.0e+1", + "5.0e+2", + "5.0e+3", + "5.0e+4", + "5.0e+5"] = float_g_1("~.1g", 5.0, -2, 5); + {'EXIT',_} -> ok + end, + + ["4.99999e-2", + "0.499999", + "4.99999", + "49.9999", + "499.999", + "4999.99", + "4.99999e+4", + "4.99999e+5"] = float_g_1("~g", 4.9999949999, -2, 5), + + ["-5.00000e-2", + "-0.500000", + "-5.00000", + "-50.0000", + "-500.000", + "-5000.00", + "-5.00000e+4", + "-5.00000e+5"] = float_g_1("~g", -4.9999950001, -2, 5), ok. float_g_1(Fmt, V, Min, Max) -> [fmt(Fmt, [V*math:pow(10, E)]) || E <- lists:seq(Min, Max)]. -otp_5403(doc) -> - ["OTP-5403. ~s formats I/O lists and a single binary."]; -otp_5403(suite) -> - []; +%% OTP-5403. ~s formats I/O lists and a single binary. otp_5403(Config) when is_list(Config) -> - ?line "atom" = fmt("~s", [atom]), - ?line "binary" = fmt("~s", [<<"binary">>]), - ?line "atail" = fmt("~s", [["a" | <<"tail">>]]), - ?line "deepcharlist" = fmt("~s", [["deep",["char",["list"]]]]), - ?line "somebinaries" = fmt("~s", [[<<"some">>,[<<"binaries">>]]]), + "atom" = fmt("~s", [atom]), + "binary" = fmt("~s", [<<"binary">>]), + "atail" = fmt("~s", [["a" | <<"tail">>]]), + "deepcharlist" = fmt("~s", [["deep",["char",["list"]]]]), + "somebinaries" = fmt("~s", [[<<"some">>,[<<"binaries">>]]]), ok. -otp_5813(doc) -> - ["OTP-5813. read/3 is new."]; -otp_5813(suite) -> - []; +%% OTP-5813. read/3 is new. otp_5813(Config) when is_list(Config) -> - ?line PrivDir = ?privdir(Config), - ?line File = filename:join(PrivDir, "test"), + PrivDir = ?privdir(Config), + File = filename:join(PrivDir, "test"), - ?line ok = file:write_file(File, <<"a. ">>), - ?line {ok, Fd} = file:open(File, [read]), - ?line {ok, a, 1} = io:read(Fd, '', 1), - ?line {eof,1} = io:read(Fd, '', 1), + ok = file:write_file(File, <<"a. ">>), + {ok, Fd} = file:open(File, [read]), + {ok, a, 1} = io:read(Fd, '', 1), + {eof,1} = io:read(Fd, '', 1), ok = file:close(Fd), - ?line ok = file:write_file(File, <<"[}.">>), - ?line {ok, Fd2} = file:open(File, [read]), - ?line {error,{1,_,_},1} = io:read(Fd2, '', 1), - ?line ok = file:close(Fd), + ok = file:write_file(File, <<"[}.">>), + {ok, Fd2} = file:open(File, [read]), + {error,{1,_,_},1} = io:read(Fd2, '', 1), + ok = file:close(Fd), file:delete(File), ok. -otp_6230(doc) -> - ["OTP-6230. ~p and ~P with (huge) binaries."]; -otp_6230(suite) -> - []; +%% OTP-6230. ~p and ~P with (huge) binaries. otp_6230(Config) when is_list(Config) -> %% The problem is actually huge binaries, but the small tests here %% just run through most of the modified code. - ?line "<<>>" = fmt("~P", [<<"">>,-1]), - ?line "<<\"hej\">>" = fmt("~P", [<<"hej">>,-1]), - ?line "{hej,...}" = fmt("~P", [{hej,<<"hej">>},2]), - ?line "{hej,<<...>>}" = fmt("~P", [{hej,<<"hej">>},3]), - ?line "{hej,<<\"hejs\"...>>}" = fmt("~P", [{hej,<<"hejsan">>},4]), - ?line "{hej,<<\"hej\">>}" = fmt("~P", [{hej,<<"hej">>},6]), - ?line "<<...>>" = fmt("~P", [<<"hej">>,1]), - ?line "<<\"hejs\"...>>" = fmt("~P", [<<"hejsan">>,2]), - ?line "<<\"hej\">>" = fmt("~P", [<<"hej">>,4]), - ?line "{hej,<<127,...>>}" = + "<<>>" = fmt("~P", [<<"">>,-1]), + "<<\"hej\">>" = fmt("~P", [<<"hej">>,-1]), + "{hej,...}" = fmt("~P", [{hej,<<"hej">>},2]), + "{hej,<<...>>}" = fmt("~P", [{hej,<<"hej">>},3]), + "{hej,<<\"hejs\"...>>}" = fmt("~P", [{hej,<<"hejsan">>},4]), + "{hej,<<\"hej\">>}" = fmt("~P", [{hej,<<"hej">>},6]), + "<<...>>" = fmt("~P", [<<"hej">>,1]), + "<<\"hejs\"...>>" = fmt("~P", [<<"hejsan">>,2]), + "<<\"hej\">>" = fmt("~P", [<<"hej">>,4]), + "{hej,<<127,...>>}" = fmt("~P", [{hej,<<127:8,<<"hej">>/binary>>},4]), - ?line "{hej,<<127,104,101,...>>}" = + "{hej,<<127,104,101,...>>}" = fmt("~P", [{hej,<<127:8,<<"hej">>/binary>>},6]), B = list_to_binary(lists:duplicate(30000, $a)), - ?line "<<\"aaaa"++_ = fmt("~P", [B, 20000]), + "<<\"aaaa"++_ = fmt("~P", [B, 20000]), ok. -otp_6282(doc) -> - ["OTP-6282. ~p truncates strings (like binaries) depending on depth."]; -otp_6282(suite) -> - []; +%% OTP-6282. ~p truncates strings (like binaries) depending on depth. otp_6282(Config) when is_list(Config) -> - ?line "[]" = p("", 1, 20, 1), - ?line "[]" = p("", 1, 20, -1), - ?line "[...]" = p("a", 1, 20, 1), - ?line "\"a\"" = p("a", 1, 20, 2), - ?line "\"aa\"" = p("aa", 1, 20, 2), - ?line "\"aaa\"" = p("aaa", 1, 20, 2), - ?line "\"aaaa\"" = p("aaaa", 1, 20, 2), - % ?line "\"aaaa\"..." = p("aaaaaa", 1, 20, 2), - ?line "\"a\"" = p("a", 1, 20, -1), - % ?line "\"aa\"..." = p([$a,$a,1000], 1, 20, 2), - % ?line "\"aa\"..." = p([$a,$a,1000], 1, 20, 3), - ?line "[97,97,1000]" = p([$a,$a,1000], 1, 20, 4), + "[]" = p("", 1, 20, 1), + "[]" = p("", 1, 20, -1), + "[...]" = p("a", 1, 20, 1), + "\"a\"" = p("a", 1, 20, 2), + "\"aa\"" = p("aa", 1, 20, 2), + "\"aaa\"" = p("aaa", 1, 20, 2), + "\"aaaa\"" = p("aaaa", 1, 20, 2), + "\"a\"" = p("a", 1, 20, -1), + "[97,97,1000]" = p([$a,$a,1000], 1, 20, 4), S1 = lists:duplicate(200,$a), - ?line "[...]" = p(S1, 1, 20, 1), - % ?line "\"aaaaaaaaaaaaaaaa\"\n \"aaaaaaaaaaaaaaaa\"\n \"aaaa\"..." = - % ?line "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"..." = - % p(S1, 1, 20, 10), - ?line true = "\"" ++ S1 ++ "\"" =:= p(S1, 1, 205, -1), - ?line "[97,97,1000|...]" = p([$a,$a,1000,1000], 1, 20, 4), - - ?line "[[]]" = p([""], 1, 20, 2), - ?line "[[]]" = p([""], 1, 20, -1), - ?line "[[...]]" = p(["a"], 1, 20, 2), - ?line "[\"a\"]" = p(["a"], 1, 20, 3), - ?line "[\"aa\"]" = p(["aa"], 1, 20, 3), - ?line "[\"aaa\"]" = p(["aaa"], 1, 20, 3), - ?line "[\"a\"]" = p(["a"], 1, 20, -1), - % ?line "[\"aa\"...]" = p([[$a,$a,1000]], 1, 20, 3), - % ?line "[\"aa\"...]" = p([[$a,$a,1000]], 1, 20, 4), - ?line "[[97,97,1000]]" = p([[$a,$a,1000]], 1, 20, 5), - ?line "[[...]]" = p([S1], 1, 20, 2), - % ?line "[\"aaaaaaaaaaaaaa\"\n \"aaaaaaaaaaaaaa\"\n \"aaaaaaaa\"...]" = - % ?line "[\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"...]" = - % p([S1], 1, 20, 11), - ?line true = "[\"" ++ S1 ++ "\"]" =:= p([S1], 1, 210, -1), - ?line "[[97,97,1000|...]]" = p([[$a,$a,1000,1000]], 1, 20, 5), - - % ?line "[\"aaaa\"...]" = p(["aaaaa"], 1, 10, 3), - ?line "[\"aaaaa\"]" = p(["aaaaa"], 1, 10, 6), + "[...]" = p(S1, 1, 20, 1), + true = "\"" ++ S1 ++ "\"" =:= p(S1, 1, 205, -1), + "[97,97,1000|...]" = p([$a,$a,1000,1000], 1, 20, 4), + + "[[]]" = p([""], 1, 20, 2), + "[[]]" = p([""], 1, 20, -1), + "[[...]]" = p(["a"], 1, 20, 2), + "[\"a\"]" = p(["a"], 1, 20, 3), + "[\"aa\"]" = p(["aa"], 1, 20, 3), + "[\"aaa\"]" = p(["aaa"], 1, 20, 3), + "[\"a\"]" = p(["a"], 1, 20, -1), + "[[97,97,1000]]" = p([[$a,$a,1000]], 1, 20, 5), + "[[...]]" = p([S1], 1, 20, 2), + true = "[\"" ++ S1 ++ "\"]" =:= p([S1], 1, 210, -1), + "[[97,97,1000|...]]" = p([[$a,$a,1000,1000]], 1, 20, 5), + + "[\"aaaaa\"]" = p(["aaaaa"], 1, 10, 6), ok. -otp_6354(doc) -> - ["OTP-6354. io_lib_pretty rewritten."]; -otp_6354(suite) -> - []; +%% OTP-6354. io_lib_pretty rewritten. otp_6354(Config) when is_list(Config) -> %% A few tuples: - ?line "{}" = p({}, 1, 20, -1), - ?line "..." = p({}, 1, 20, 0), - ?line "{}" = p({}, 1, 20, 1), - ?line "{}" = p({}, 1, 20, 2), - ?line "{a}" = p({a}, 1, 20, -1), - ?line "..." = p({a}, 1, 20, 0), - ?line "{...}" = p({a}, 1, 20, 1), - ?line "{a}" = p({a}, 1, 20, 2), - ?line "{a,b}" = p({a,b}, 1, 20, -1), - ?line "..." = p({a,b}, 1, 20, 0), - ?line "{...}" = p({a,b}, 1, 20, 1), - ?line "{a,...}" = p({a,b}, 1, 20, 2), - ?line "{a,b}" = p({a,b}, 1, 20, 3), - ?line "{}" = p({}, 1, 1, -1), - ?line "..." = p({}, 1, 1, 0), - ?line "{}" = p({}, 1, 1, 1), - ?line "{}" = p({}, 1, 1, 2), - ?line "{a}" = p({a}, 1, 1, -1), - ?line "..." = p({a}, 1, 1, 0), - ?line "{...}" = p({a}, 1, 1, 1), - ?line "{a}" = p({a}, 1, 1, 2), - ?line "{a,\n b}" = p({a,b}, 1, 1, -1), - ?line "{1,\n b}" = p({1,b}, 1, 1, -1), - ?line "..." = p({a,b}, 1, 1, 0), - ?line "{...}" = p({a,b}, 1, 1, 1), - ?line "{a,...}" = p({a,b}, 1, 1, 2), - ?line "{a,\n b}" = p({a,b}, 1, 1, 3), - ?line "{{}}" = p({{}}, 1, 1, 2), - ?line "{[]}" = p({[]}, 1, 1, 2), - ?line bt(<<"{1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]}">>, - p({1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]}, -1)), - ?line bt(<<"{abcd,ddddd,\n ddddd}">>, - p({abcd,ddddd,ddddd}, 1,16, -1)), - ?line bt(<<"{1,2,a,b,\n {sfdsf,sdfdsfs},\n [sfsdf,sdfsdf]}">>, - p({1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]}, 1, 35, 100)), - % With other terms than atomic ones on the same line: -% ?line bt(<<"{1,2,a,b,{sfdsf,sdfdsfs},\n [sfsdf,sdfsdf]}">>, -% p({1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]}, 1, 35, 100)), - % With line breaks: -% ?line bt(<<"{1,\n" -% " 2,\n" -% " a,\n" -% " b,\n" -% " {sfdsf,sdfdsfs},\n" -% " [sfsdf,sdfsdf]}">>, -% p({1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]}, 1, 35, 100)), - ?line "{1,{1,{2,3}}}" = p({1,{1,{2,3}}}, 1, 80, 100), - - ?line bt(<<"{wwwww,{wwwww,{wwwww,{wwwww,{wwwww,lkjsldfj,klsdjfjklds,\n" - " sdkfjdsl,sdakfjdsklj,sdkljfsdj}}}}}">>, - p({wwwww,{wwwww,{wwwww,{wwwww,{wwwww,lkjsldfj,klsdjfjklds, - sdkfjdsl,sdakfjdsklj,sdkljfsdj}}}}}, -1)), - - % With no restriction on number of characters per line: -% ?line bt(<<"{wwwww,{wwwww,{wwwww,{wwwww,{wwwww,lkjsldfj,klsdjfjklds," -% "sdkfjdsl,sdakfjdsklj,\n" -% " sdkljfsdj}}}}}">>, -% p({wwwww,{wwwww,{wwwww,{wwwww,{wwwww,lkjsldfj,klsdjfjklds, -% sdkfjdsl,sdakfjdsklj,sdkljfsdj}}}}}, -1)), - - % With line breaks: -% ?line bt(<<"{wwwww,{wwwww,{wwwww,{wwwww,{wwwww,lkjsldfj,\n" -% " klsdjfjklds,\n" -% " sdkfjdsl,\n" -% " sdakfjdsklj,\n" -% " sdkljfsdj}}}}}">>, -% p({wwwww,{wwwww,{wwwww,{wwwww,{wwwww,lkjsldfj,klsdjfjklds, -% sdkfjdsl,sdakfjdsklj,sdkljfsdj}}}}}, -1)), - ?line bt(<<"{wwwww,\n" - " {wwwww,\n" - " {wwwww,\n" - " {wwwww,\n" - " {wwwww,\n" - " {lkjsldfj,\n" - " {klsdjfjklds,\n" - " {klajsljls,\n" - " #aaaaaaaaaaaaaaaaaaaaa" - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa{}}}}}}}}}">>, - p({wwwww,{wwwww,{wwwww,{wwwww,{wwwww,{lkjsldfj, - {klsdjfjklds,{klajsljls, - {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}}}}}}}}}, - -1)), - ?line "{{...},...}" = p({{a,b},{a,b,c},{d,e,f}},1,8,2), + "{}" = p({}, 1, 20, -1), + "..." = p({}, 1, 20, 0), + "{}" = p({}, 1, 20, 1), + "{}" = p({}, 1, 20, 2), + "{a}" = p({a}, 1, 20, -1), + "..." = p({a}, 1, 20, 0), + "{...}" = p({a}, 1, 20, 1), + "{a}" = p({a}, 1, 20, 2), + "{a,b}" = p({a,b}, 1, 20, -1), + "..." = p({a,b}, 1, 20, 0), + "{...}" = p({a,b}, 1, 20, 1), + "{a,...}" = p({a,b}, 1, 20, 2), + "{a,b}" = p({a,b}, 1, 20, 3), + "{}" = p({}, 1, 1, -1), + "..." = p({}, 1, 1, 0), + "{}" = p({}, 1, 1, 1), + "{}" = p({}, 1, 1, 2), + "{a}" = p({a}, 1, 1, -1), + "..." = p({a}, 1, 1, 0), + "{...}" = p({a}, 1, 1, 1), + "{a}" = p({a}, 1, 1, 2), + "{a,\n b}" = p({a,b}, 1, 1, -1), + "{1,\n b}" = p({1,b}, 1, 1, -1), + "..." = p({a,b}, 1, 1, 0), + "{...}" = p({a,b}, 1, 1, 1), + "{a,...}" = p({a,b}, 1, 1, 2), + "{a,\n b}" = p({a,b}, 1, 1, 3), + "{{}}" = p({{}}, 1, 1, 2), + "{[]}" = p({[]}, 1, 1, 2), + bt(<<"{1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]}">>, + p({1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]}, -1)), + bt(<<"{abcd,ddddd,\n ddddd}">>, + p({abcd,ddddd,ddddd}, 1,16, -1)), + bt(<<"{1,2,a,b,\n {sfdsf,sdfdsfs},\n [sfsdf,sdfsdf]}">>, + p({1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]}, 1, 35, 100)), + "{1,{1,{2,3}}}" = p({1,{1,{2,3}}}, 1, 80, 100), + + bt(<<"{wwwww,{wwwww,{wwwww,{wwwww,{wwwww,lkjsldfj,klsdjfjklds,\n" + " sdkfjdsl,sdakfjdsklj,sdkljfsdj}}}}}">>, + p({wwwww,{wwwww,{wwwww,{wwwww,{wwwww,lkjsldfj,klsdjfjklds, + sdkfjdsl,sdakfjdsklj,sdkljfsdj}}}}}, -1)), + + bt(<<"{wwwww,\n" + " {wwwww,\n" + " {wwwww,\n" + " {wwwww,\n" + " {wwwww,\n" + " {lkjsldfj,\n" + " {klsdjfjklds,\n" + " {klajsljls,\n" + " #aaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa{}}}}}}}}}">>, + p({wwwww,{wwwww,{wwwww,{wwwww,{wwwww,{lkjsldfj, + {klsdjfjklds,{klajsljls, + {aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}}}}}}}}}, + -1)), + "{{...},...}" = p({{a,b},{a,b,c},{d,e,f}},1,8,2), %% Closing brackets and parentheses count: - ?line "{{a,b,c},\n {{1,2,\n 3}}}" = p({{a,b,c},{{1,2,3}}},1,11,-1), - % With line breaks: -% ?line "{{a,b,c},\n {{1,\n 2,\n 3}}}" = p({{a,b,c},{{1,2,3}}},1,11,-1), - ?line "{{a,b,c},\n [1,2,\n 3]}" = p({{a,b,c},[1,2,3]},1,10,-1), - % With line breaks: -% ?line "{{a,b,c},\n [1,\n 2,\n 3]}" = p({{a,b,c},[1,2,3]},1,10,-1), - ?line "[{{a,b,c},\n {1,2,\n 3}}]" = p([{{a,b,c},{1,2,3}}],1,12,-1), - % With line breaks: -% ?line "[{{a,b,c},\n {1,\n 2,\n 3}}]" = p([{{a,b,c},{1,2,3}}],1,12,-1), + "{{a,b,c},\n {{1,2,\n 3}}}" = p({{a,b,c},{{1,2,3}}},1,11,-1), + %% With line breaks: + "{{a,b,c},\n [1,2,\n 3]}" = p({{a,b,c},[1,2,3]},1,10,-1), + %% With line breaks: + "[{{a,b,c},\n {1,2,\n 3}}]" = p([{{a,b,c},{1,2,3}}],1,12,-1), %% A few lists: - ?line "[]" = p([], 1, 20, -1), - ?line "..." = p([], 1, 20, 0), - ?line "[]" = p([], 1, 20, 1), - ?line "[]" = p([], 1, 20, 2), - ?line "[a]" = p([a], 1, 20, -1), - ?line "..." = p([a], 1, 20, 0), - ?line "[...]" = p([a], 1, 20, 1), - ?line "[a]" = p([a], 1, 20, 2), - ?line "[a,b]" = p([a,b], 1, 20, -1), - ?line "..." = p([a,b], 1, 20, 0), - ?line "[...]" = p([a,b], 1, 20, 1), - ?line "[a|...]" = p([a,b], 1, 20, 2), - ?line "[a,b]" = p([a,b], 1, 20, 3), - ?line "[a|b]" = p([a|b], 1, 20, -1), - ?line "..." = p([a|b], 1, 20, 0), - ?line "[...]" = p([a|b], 1, 20, 1), - ?line "[a|...]" = p([a|b], 1, 20, 2), - ?line "[a|b]" = p([a|b], 1, 20, 3), - ?line "[]" = p([], 1, 1, -1), - ?line "..." = p([], 1, 1, 0), - ?line "[]" = p([], 1, 1, 1), - ?line "[]" = p([], 1, 1, 2), - ?line "[a]" = p([a], 1, 1, -1), - ?line "..." = p([a], 1, 1, 0), - ?line "[...]" = p([a], 1, 1, 1), - ?line "[a]" = p([a], 1, 1, 2), - ?line "[a,\n b]" = p([a,b], 1, 1, -1), - ?line "..." = p([a,b], 1, 1, 0), - ?line "[...]" = p([a,b], 1, 1, 1), - ?line "[a|...]" = p([a,b], 1, 1, 2), - ?line "[a,\n b]" = p([a,b], 1, 1, 3), - ?line "[a|\n b]" = p([a|b], 1, 1, -1), - ?line "..." = p([a|b], 1, 1, 0), - ?line "[...]" = p([a|b], 1, 1, 1), - ?line "[a|...]" = p([a|b], 1, 1, 2), - ?line "[a|\n b]" = p([a|b], 1, 1, 3), - ?line "[{}]" = p([{}], 1, 1, 2), - ?line "[[]]" = p([[]], 1, 1, 2), - ?line bt(<<"[1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]]">>, - p([1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]], -1)), - ?line bt(<<"[1,2,a,b,\n {sfdsf,sdfdsfs},\n [sfsdf,sdfsdf]]">>, - p([1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]], 1, 35, 100)), - % With other terms than atomic ones on the same line: -% ?line bt(<<"[1,2,a,b,{sfdsf,sdfdsfs},\n [sfsdf,sdfsdf]]">>, -% p([1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]], 1, 35, 100)), - % With line breaks: -% ?line bt(<<"[1,\n" -% " 2,\n" -% " a,\n" -% " b,\n" -% " {sfdsf,sdfdsfs},\n" -% " [sfsdf,sdfsdf]]">>, -% p([1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]], 1, 35, 100)), + "[]" = p([], 1, 20, -1), + "..." = p([], 1, 20, 0), + "[]" = p([], 1, 20, 1), + "[]" = p([], 1, 20, 2), + "[a]" = p([a], 1, 20, -1), + "..." = p([a], 1, 20, 0), + "[...]" = p([a], 1, 20, 1), + "[a]" = p([a], 1, 20, 2), + "[a,b]" = p([a,b], 1, 20, -1), + "..." = p([a,b], 1, 20, 0), + "[...]" = p([a,b], 1, 20, 1), + "[a|...]" = p([a,b], 1, 20, 2), + "[a,b]" = p([a,b], 1, 20, 3), + "[a|b]" = p([a|b], 1, 20, -1), + "..." = p([a|b], 1, 20, 0), + "[...]" = p([a|b], 1, 20, 1), + "[a|...]" = p([a|b], 1, 20, 2), + "[a|b]" = p([a|b], 1, 20, 3), + "[]" = p([], 1, 1, -1), + "..." = p([], 1, 1, 0), + "[]" = p([], 1, 1, 1), + "[]" = p([], 1, 1, 2), + "[a]" = p([a], 1, 1, -1), + "..." = p([a], 1, 1, 0), + "[...]" = p([a], 1, 1, 1), + "[a]" = p([a], 1, 1, 2), + "[a,\n b]" = p([a,b], 1, 1, -1), + "..." = p([a,b], 1, 1, 0), + "[...]" = p([a,b], 1, 1, 1), + "[a|...]" = p([a,b], 1, 1, 2), + "[a,\n b]" = p([a,b], 1, 1, 3), + "[a|\n b]" = p([a|b], 1, 1, -1), + "..." = p([a|b], 1, 1, 0), + "[...]" = p([a|b], 1, 1, 1), + "[a|...]" = p([a|b], 1, 1, 2), + "[a|\n b]" = p([a|b], 1, 1, 3), + "[{}]" = p([{}], 1, 1, 2), + "[[]]" = p([[]], 1, 1, 2), + bt(<<"[1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]]">>, + p([1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]], -1)), + bt(<<"[1,2,a,b,\n {sfdsf,sdfdsfs},\n [sfsdf,sdfsdf]]">>, + p([1,2,a,b,{sfdsf,sdfdsfs},[sfsdf,sdfsdf]], 1, 35, 100)), %% Element #8 is not printable: - ?line "[49," ++ _ = p("1234567"++[3,4,5,6,7], 1, 100, 9), - % ?line "\"1234567\"..." = p("1234567"++[3,4,5,6,7], 1, 100, 8), + "[49," ++ _ = p("1234567"++[3,4,5,6,7], 1, 100, 9), + %% "\"1234567\"..." = p("1234567"++[3,4,5,6,7], 1, 100, 8), %% A few records: %% -record(a, {}). %% -record(a, {}). - ?line "..." = p({a}, 0), - ?line "{...}" = p({a}, 1), - ?line "#a{}" = p({a}, 2), - ?line "#a{}" = p({a}, -1), + "..." = p({a}, 0), + "{...}" = p({a}, 1), + "#a{}" = p({a}, 2), + "#a{}" = p({a}, -1), %% -record(b, {f}). - ?line "{...}" = p({b}, 1), - ?line "..." = p({b,c}, 0), - ?line "{...}" = p({b,c}, 1), - ?line "#b{...}" = p({b,c}, 2), - ?line "#b{f = c}" = p({b,c}, 3), - ?line "#b{f = c}" = p({b,c}, -1), - ?line "..." = p({b,{c,d}}, 0), - ?line "{...}" = p({b,{c,d}}, 1), - ?line "#b{...}" = p({b,{c,d}}, 2), - ?line "#b{f = {...}}" = p({b,{c,d}}, 3), - ?line "#b{f = {c,...}}" = p({b,{c,d}}, 4), - ?line "#b{f = {c,d}}" = p({b,{c,d}}, 5), - ?line "#b{f = {...}}" = p({b,{b,c}}, 3), - ?line "#b{f = #b{...}}" = p({b,{b,c}}, 4), - ?line "#b{f = #b{f = c}}" = p({b,{b,c}}, 5), + "{...}" = p({b}, 1), + "..." = p({b,c}, 0), + "{...}" = p({b,c}, 1), + "#b{...}" = p({b,c}, 2), + "#b{f = c}" = p({b,c}, 3), + "#b{f = c}" = p({b,c}, -1), + "..." = p({b,{c,d}}, 0), + "{...}" = p({b,{c,d}}, 1), + "#b{...}" = p({b,{c,d}}, 2), + "#b{f = {...}}" = p({b,{c,d}}, 3), + "#b{f = {c,...}}" = p({b,{c,d}}, 4), + "#b{f = {c,d}}" = p({b,{c,d}}, 5), + "#b{f = {...}}" = p({b,{b,c}}, 3), + "#b{f = #b{...}}" = p({b,{b,c}}, 4), + "#b{f = #b{f = c}}" = p({b,{b,c}}, 5), %% -record(c, {f1, f2}). - ?line "#c{f1 = d,f2 = e}" = p({c,d,e}, -1), - ?line "..." = p({c,d,e}, 0), - ?line "{...}" = p({c,d,e}, 1), - ?line "#c{...}" = p({c,d,e}, 2), - ?line "#c{f1 = d,...}" = p({c,d,e}, 3), - ?line "#c{f1 = d,f2 = e}" = p({c,d,e}, 4), + "#c{f1 = d,f2 = e}" = p({c,d,e}, -1), + "..." = p({c,d,e}, 0), + "{...}" = p({c,d,e}, 1), + "#c{...}" = p({c,d,e}, 2), + "#c{f1 = d,...}" = p({c,d,e}, 3), + "#c{f1 = d,f2 = e}" = p({c,d,e}, 4), %% -record(d, {a..., b..., c.., d...}). - ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2,\n" - " cccccccccccccccccccc = 3,dddddddddddddddddddd = 4,\n" - " eeeeeeeeeeeeeeeeeeee = 5}">>, - p({d,1,2,3,4,5}, -1)), - % With no restriction on number of characters per line: -% ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2," -% "cccccccccccccccccccc = 3,\n dddddddddddddddddddd = 4," -% "eeeeeeeeeeeeeeeeeeee = 5}">>, -% p({d,1,2,3,4,5}, -1)), - % With line breaks: -% ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,\n" -% " bbbbbbbbbbbbbbbbbbbb = 2,\n" -% " cccccccccccccccccccc = 3,\n" -% " dddddddddddddddddddd = 4,\n" -% " eeeeeeeeeeeeeeeeeeee = 5}">>, -% p({d,1,2,3,4,5}, -1)), - ?line "..." = p({d,1,2,3,4,5}, 0), - ?line "{...}" = p({d,1,2,3,4,5}, 1), - ?line "#d{...}" = p({d,1,2,3,4,5}, 2), - ?line "#d{aaaaaaaaaaaaaaaaaaaa = 1,...}" = p({d,1,2,3,4,5}, 3), - ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2,...}">>, - p({d,1,2,3,4,5}, 4)), - ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2,\n" - " cccccccccccccccccccc = 3,...}">>, - p({d,1,2,3,4,5}, 5)), % longer than 80 characters... - % With no restriction on number of characters per line: -% ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2," -% "cccccccccccccccccccc = 3,...}">>, -% p({d,1,2,3,4,5}, 5)), % longer than 80 characters... - % With line breaks: -% ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,\n" -% " bbbbbbbbbbbbbbbbbbbb = 2,\n" -% " cccccccccccccccccccc = 3,...}">>, -% p({d,1,2,3,4,5}, 5)), - ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2,\n" - " cccccccccccccccccccc = 3,dddddddddddddddddddd = 4,...}">>, - p({d,1,2,3,4,5}, 6)), - % With no restriction on number of characters per line: -% ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2," -% "cccccccccccccccccccc = 3,\n dddddddddddddddddddd = 4,...}">>, -% p({d,1,2,3,4,5}, 6)), - % With line breaks: -% ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,\n" -% " bbbbbbbbbbbbbbbbbbbb = 2,\n" -% " cccccccccccccccccccc = 3,\n" -% " dddddddddddddddddddd = 4,...}">>, -% p({d,1,2,3,4,5}, 6)), - ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2,\n" - " cccccccccccccccccccc = 3,dddddddddddddddddddd = 4,\n" - " eeeeeeeeeeeeeeeeeeee = 5}">>, - p({d,1,2,3,4,5}, 7)), - % With no restriction on number of characters per line: -% ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2," -% "cccccccccccccccccccc = 3,\n dddddddddddddddddddd = 4," -% "eeeeeeeeeeeeeeeeeeee = 5}">>, -% p({d,1,2,3,4,5}, 7)), - % With line breaks: -% ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,\n" -% " bbbbbbbbbbbbbbbbbbbb = 2,\n" -% " cccccccccccccccccccc = 3,\n" -% " dddddddddddddddddddd = 4,\n" -% " eeeeeeeeeeeeeeeeeeee = 5}">>, -% p({d,1,2,3,4,5}, 7)), - ?line bt(<<"#rrrrr{\n" - " f1 = 1,\n" - " f2 = #rrrrr{f1 = a,f2 = b,f3 = c},\n" - " f3 = \n" - " #rrrrr{\n" - " f1 = h,f2 = i,\n" - " f3 = \n" - " #rrrrr{\n" - " f1 = aa,\n" - " f2 = \n" - " #rrrrr{\n" - " f1 = #rrrrr{f1 = a,f2 = b,f3 = c},\n" - " f2 = 2,f3 = 3},\n" - " f3 = bb}}}">>, - p({rrrrr,1,{rrrrr,a,b,c},{rrrrr,h,i, - {rrrrr,aa,{rrrrr,{rrrrr,a,b,c}, - 2,3},bb}}}, - -1)), - % With other terms than atomic ones on the same line: -% ?line bt(<<"#rrrrr{\n" -% " f1 = 1,f2 = #rrrrr{f1 = a,f2 = b,f3 = c},\n" -% " f3 = \n" -% " #rrrrr{\n" -% " f1 = h,f2 = i,\n" -% " f3 = \n" -% " #rrrrr{\n" -% " f1 = aa,\n" -% " f2 = \n" -% " #rrrrr{\n" -% " f1 = #rrrrr{f1 = a,f2 = b," -% "f3 = c},f2 = 2,f3 = 3},\n" -% " f3 = bb}}}">>, -% p({rrrrr,1,{rrrrr,a,b,c},{rrrrr,h,i, -% {rrrrr,aa,{rrrrr,{rrrrr,a,b,c}, -% 2,3},bb}}}, -% -1)), - % With line breaks: -% ?line bt(<<"#rrrrr{\n" -% " f1 = 1,\n" -% " f2 = #rrrrr{f1 = a,f2 = b,f3 = c},\n" -% " f3 = \n" -% " #rrrrr{\n" -% " f1 = h,\n" -% " f2 = i,\n" -% " f3 = \n" -% " #rrrrr{\n" -% " f1 = aa,\n" -% " f2 = \n" -% " #rrrrr{\n" -% " f1 = #rrrrr{f1 = a,f2 = b," -% "f3 = c},\n" -% " f2 = 2,\n" -% " f3 = 3},\n" -% " f3 = bb}}}">>, -% p({rrrrr,1,{rrrrr,a,b,c},{rrrrr,h,i, -% {rrrrr,aa,{rrrrr,{rrrrr,a,b,c}, -% 2,3},bb}}}, -% -1)), - ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,\n" - " bbbbbbbbbbbbbbbbbbbb = \n" - " #d{aaaaaaaaaaaaaaaaaaaa = a,bbbbbbbbbbbbbbbbbbbb = b,\n" - " cccccccccccccccccccc = c,dddddddddddddddddddd = d,\n" - " eeeeeeeeeeeeeeeeeeee = e},\n" - " cccccccccccccccccccc = 3,\n" - " dddddddddddddddddddd = \n" - " #d{aaaaaaaaaaaaaaaaaaaa = h,bbbbbbbbbbbbbbbbbbbb = i,\n" - " cccccccccccccccccccc = \n" - " #d{aaaaaaaaaaaaaaaaaaaa = aa," - "bbbbbbbbbbbbbbbbbbbb = bb,\n" - " cccccccccccccccccccc = \n" - " #d{aaaaaaaaaaaaaaaaaaaa = 1," - "bbbbbbbbbbbbbbbbbbbb = 2,\n" - " cccccccccccccccccccc = 3," - "dddddddddddddddddddd = 4,\n" - " eeeeeeeeeeeeeeeeeeee = 5},\n" - " dddddddddddddddddddd = dd," - "eeeeeeeeeeeeeeeeeeee = ee},\n" - " dddddddddddddddddddd = k," - "eeeeeeeeeeeeeeeeeeee = l},\n" - " eeeeeeeeeeeeeeeeeeee = 5}">>, - p({d,1,{d,a,b,c,d,e},3,{d,h,i,{d,aa,bb,{d,1,2,3,4,5},dd,ee}, - k,l},5}, -1)), - % With line breaks: -% ?line bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,\n" -% " bbbbbbbbbbbbbbbbbbbb = \n" -% " #d{aaaaaaaaaaaaaaaaaaaa = a,\n" -% " bbbbbbbbbbbbbbbbbbbb = b,\n" -% " cccccccccccccccccccc = c,\n" -% " dddddddddddddddddddd = d,\n" -% " eeeeeeeeeeeeeeeeeeee = e},\n" -% " cccccccccccccccccccc = 3,\n" -% " dddddddddddddddddddd = \n" -% " #d{aaaaaaaaaaaaaaaaaaaa = h,\n" -% " bbbbbbbbbbbbbbbbbbbb = i,\n" -% " cccccccccccccccccccc = \n" -% " #d{aaaaaaaaaaaaaaaaaaaa = aa,\n" -% " bbbbbbbbbbbbbbbbbbbb = bb,\n" -% " cccccccccccccccccccc = \n" -% " #d{aaaaaaaaaaaaaaaaaaaa = 1,\n" -% " bbbbbbbbbbbbbbbbbbbb = 2,\n" -% " cccccccccccccccccccc = 3,\n" -% " dddddddddddddddddddd = 4,\n" -% " eeeeeeeeeeeeeeeeeeee = 5},\n" -% " dddddddddddddddddddd = dd,\n" -% " eeeeeeeeeeeeeeeeeeee = ee},\n" -% " dddddddddddddddddddd = k,\n" -% " eeeeeeeeeeeeeeeeeeee = l},\n" -% " eeeeeeeeeeeeeeeeeeee = 5}">>, -% p({d,1,{d,a,b,c,d,e},3,{d,h,i,{d,aa,bb,{d,1,2,3,4,5},dd,ee}, -% k,l},5}, -1)), + bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2,\n" + " cccccccccccccccccccc = 3,dddddddddddddddddddd = 4,\n" + " eeeeeeeeeeeeeeeeeeee = 5}">>, + p({d,1,2,3,4,5}, -1)), + "..." = p({d,1,2,3,4,5}, 0), + "{...}" = p({d,1,2,3,4,5}, 1), + "#d{...}" = p({d,1,2,3,4,5}, 2), + "#d{aaaaaaaaaaaaaaaaaaaa = 1,...}" = p({d,1,2,3,4,5}, 3), + bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2,...}">>, + p({d,1,2,3,4,5}, 4)), + bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2,\n" + " cccccccccccccccccccc = 3,...}">>, + p({d,1,2,3,4,5}, 5)), % longer than 80 characters... + bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2,\n" + " cccccccccccccccccccc = 3,dddddddddddddddddddd = 4,...}">>, + p({d,1,2,3,4,5}, 6)), + bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,bbbbbbbbbbbbbbbbbbbb = 2,\n" + " cccccccccccccccccccc = 3,dddddddddddddddddddd = 4,\n" + " eeeeeeeeeeeeeeeeeeee = 5}">>, + p({d,1,2,3,4,5}, 7)), + bt(<<"#rrrrr{\n" + " f1 = 1,\n" + " f2 = #rrrrr{f1 = a,f2 = b,f3 = c},\n" + " f3 = \n" + " #rrrrr{\n" + " f1 = h,f2 = i,\n" + " f3 = \n" + " #rrrrr{\n" + " f1 = aa,\n" + " f2 = \n" + " #rrrrr{\n" + " f1 = #rrrrr{f1 = a,f2 = b,f3 = c},\n" + " f2 = 2,f3 = 3},\n" + " f3 = bb}}}">>, + p({rrrrr,1,{rrrrr,a,b,c},{rrrrr,h,i, + {rrrrr,aa,{rrrrr,{rrrrr,a,b,c}, + 2,3},bb}}}, + -1)), + bt(<<"#d{aaaaaaaaaaaaaaaaaaaa = 1,\n" + " bbbbbbbbbbbbbbbbbbbb = \n" + " #d{aaaaaaaaaaaaaaaaaaaa = a,bbbbbbbbbbbbbbbbbbbb = b,\n" + " cccccccccccccccccccc = c,dddddddddddddddddddd = d,\n" + " eeeeeeeeeeeeeeeeeeee = e},\n" + " cccccccccccccccccccc = 3,\n" + " dddddddddddddddddddd = \n" + " #d{aaaaaaaaaaaaaaaaaaaa = h,bbbbbbbbbbbbbbbbbbbb = i,\n" + " cccccccccccccccccccc = \n" + " #d{aaaaaaaaaaaaaaaaaaaa = aa," + "bbbbbbbbbbbbbbbbbbbb = bb,\n" + " cccccccccccccccccccc = \n" + " #d{aaaaaaaaaaaaaaaaaaaa = 1," + "bbbbbbbbbbbbbbbbbbbb = 2,\n" + " cccccccccccccccccccc = 3," + "dddddddddddddddddddd = 4,\n" + " eeeeeeeeeeeeeeeeeeee = 5},\n" + " dddddddddddddddddddd = dd," + "eeeeeeeeeeeeeeeeeeee = ee},\n" + " dddddddddddddddddddd = k," + "eeeeeeeeeeeeeeeeeeee = l},\n" + " eeeeeeeeeeeeeeeeeeee = 5}">>, + p({d,1,{d,a,b,c,d,e},3,{d,h,i,{d,aa,bb,{d,1,2,3,4,5},dd,ee}, + k,l},5}, -1)), A = aaaaaaaaaaaaa, %% Print the record with dots at the end of the line (Ll = 80). - ?line "{aaaaaaa" ++ _ = - p({A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, - {A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, - {A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, - {A,{A,{ggg,{hhh,{ii,{jj,{kk,{ll,{mm,{nn,{oo,{d,1,2,3,4,5} - }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} - }}}}}}}}}}}}}}}}, 146), - ?line "{aaaaaaa" ++ _ = - p({A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, - {A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, - {A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, - {A,{A,{A,{A,{A,{ggg,{hhh,{ii,{jj,{kk,{ll,{mm,{nn,{oo,{a} - }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} - }}}}}}}}}}}}}}}}}}}, 152), - - ?line bt(<<"{aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {g,{h,{i,{j,{k,{l,{m,{n,{o,#" - "d{...}}}}}}}}}}}}}}}}">>, - p({A,{A,{A,{A,{A,{A, - {g,{h,{i,{j,{k,{l,{m,{n,{o,{d,1,2,3,4,5}}}}}}}}}}}}}}}}, 32)), - ?line bt(<<"{a,#b{f = {c,{d,{e,{f,...}}}}}}">>, - p({a,{b,{c,{d,{e,{f,g}}}}}}, 12)), - ?line bt(<<"{aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,#c{f1 = ddd," - "f2 = eee}}}}}}}}}}">>, - p({A,{A,{A,{A,{A,{A,{A,{A,{A,{c,ddd,eee}}}}}}}}}}, 100)), - ?line bt(<<"{aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,{aaaaaaaaaaaaa,{aaaaaaaaaaaaa,...}}}}">>, - p({A,{A,{A,{A,{b}}}}}, 8)), - % With no restriction on number of characters per line: -% ?line bt(<<"{aaaaaaaaaaaaa,{aaaaaaaaaaaaa,{aaaaaaaaaaaaa," -% "{aaaaaaaaaaaaa,...}}}}">>, -% p({A,{A,{A,{A,{b}}}}}, 8)), - ?line bt(<<"{aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,{aaaaaaaaaaaaa,{aaaaaaaaaaaaa,...}}}}}">>, - p({A,{A,{A,{A,{A,{b}}}}}}, 10)), - % With no restriction on number of characters per line: -% ?line bt(<<"{aaaaaaaaaaaaa,\n" -% " {aaaaaaaaaaaaa,{aaaaaaaaaaaaa,{aaaaaaaaaaaaa," -% "{aaaaaaaaaaaaa,...}}}}}">>, -% p({A,{A,{A,{A,{A,{b}}}}}}, 10)), - ?line bt(<<"{aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa," - "{aaaaaaaaaaaaa,#a{}}}}}}}}}}}">>, - p({A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{a}}}}}}}}}}}, 23)), - ?line bt(<<"{aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n", - " #rrrrr{\n" - " f1 = kljlkjlksfdgkljlsdkjf," - "f2 = kljkljsdaflkjlkjsdf,...}}}}">>, - p({A,{A,{A,{rrrrr, kljlkjlksfdgkljlsdkjf, - kljkljsdaflkjlkjsdf, - asdfkldsjfklkljsdklfds}}}}, 10)), - % With no restriction on number of characters per line: -% ?line bt(<<"{aaaaaaaaaaaaa,\n" -% " {aaaaaaaaaaaaa,\n" -% " {aaaaaaaaaaaaa,\n", -% " #rrrrr{f1 = kljlkjlksfdgkljlsdkjf,f2 = " -% "kljkljsdaflkjlkjsdf,...}}}}">>, -% p({A,{A,{A,{rrrrr, kljlkjlksfdgkljlsdkjf, -% kljkljsdaflkjlkjsdf, -% asdfkldsjfklkljsdklfds}}}}, 10)), - ?line bt(<<"{aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {aaaaaaaaaaaaa,\n" - " {g,{h,{i,{j,{k,{l,{m,{n," - "{o,#a{}}}}}}}}}}}}}}}}}">>, - p({A,{A,{A,{A,{A,{A,{A, - {g,{h,{i,{j,{k,{l,{m,{n,{o,{a}}}}}}}}}}}}}}}}}, 100)), - ?line bt(<<"#c{\n" - " f1 = \n" - " #c{\n" - " f1 = \n" - " #c{\n" - " f1 = \n" - " #c{\n" - " f1 = \n" - " #c{\n" - " f1 = \n" - " #c{\n" - " f1 = \n" - " #c{\n" - " f1 = \n" - " #c{\n" - " f1 = \n" - " #c{\n" - " f1 = #c{f1 = #c{f1 = #c{f1 = a," - "f2 = b},f2 = b},f2 = b},\n" - " f2 = b},\n" - " f2 = b},\n" - " f2 = b},\n" - " f2 = b},\n" - " f2 = b},\n" - " f2 = b},\n" - " f2 = b},\n" - " f2 = b},\n" - " f2 = b}">>, - p({c,{c,{c,{c,{c,{c,{c,{c,{c,{c,{c,{c,a,b},b},b},b},b},b}, - b},b},b},b},b},b}, -1)), - ?line bt(<<"#rrrrr{\n" - " f1 = \n" - " #rrrrr{\n" - " f1 = \n" - " #rrrrr{\n" - " f1 = \n" - " #rrrrr{\n" - " f1 = \n" - " {rrrrr,{rrrrr,a,#rrrrr{f1 = {rrrrr,1,2},f2 = a," - "f3 = b}},b},\n" - " f2 = {rrrrr,c,d},\n" - " f3 = {rrrrr,1,2}},\n" - " f2 = 1,f3 = 2},\n" - " f2 = 3,f3 = 4},\n" - " f2 = 5,f3 = 6}">>, - p({rrrrr,{rrrrr,{rrrrr,{rrrrr,{rrrrr,{rrrrr,a,{rrrrr, - {rrrrr,1,2},a,b}},b},{rrrrr,c,d},{rrrrr,1,2}}, - 1,2},3,4},5,6}, -1)), - % With other terms than atomic ones on the same line: -% ?line bt(<<"#rrrrr{\n" -% " f1 = \n" -% " #rrrrr{\n" -% " f1 = \n" -% " #rrrrr{\n" -% " f1 = \n" -% " #rrrrr{\n" -% " f1 = \n" -% " {rrrrr,{rrrrr,a,#rrrrr{f1 = {rrrrr,1,2},f2 = a," -% "f3 = b}},b},\n" -% " f2 = {rrrrr,c,d},f3 = {rrrrr,1,2}},\n" -% " f2 = 1,f3 = 2},\n" -% " f2 = 3,f3 = 4},\n" -% " f2 = 5,f3 = 6}">>, -% p({rrrrr,{rrrrr,{rrrrr,{rrrrr,{rrrrr,{rrrrr,a,{rrrrr, -% {rrrrr,1,2},a,b}},b},{rrrrr,c,d},{rrrrr,1,2}}, -% 1,2},3,4},5,6}, -1)), - % With no restriction on number of characters per line: -% ?line bt(<<"#rrrrr{\n" -% " f1 = \n" -% " #rrrrr{\n" -% " f1 = \n" -% " #rrrrr{\n" -% " f1 = \n" -% " #rrrrr{\n" -% " f1 = {rrrrr,{rrrrr,a,#rrrrr{f1 = {rrrrr,1,2},f2 = a," -% "f3 = b}},b},\n" -% " f2 = {rrrrr,c,d},f3 = {rrrrr,1,2}},\n" -% " f2 = 1,f3 = 2},\n" -% " f2 = 3,f3 = 4},\n" -% " f2 = 5,f3 = 6}">>, -% p({rrrrr,{rrrrr,{rrrrr,{rrrrr,{rrrrr,{rrrrr,a,{rrrrr, -% {rrrrr,1,2},a,b}},b},{rrrrr,c,d},{rrrrr,1,2}}, -% 1,2},3,4},5,6}, -1)), - % With line breaks: -% ?line bt(<<"#rrrrr{\n" -% " f1 = \n" -% " #rrrrr{\n" -% " f1 = \n" -% " #rrrrr{\n" -% " f1 = \n" -% " #rrrrr{\n" -% " f1 = {rrrrr,{rrrrr,a,#rrrrr{f1 = {rrrrr,1,2},f2 = a," -% "f3 = b}},b},\n" -% " f2 = {rrrrr,c,d},\n" -% " f3 = {rrrrr,1,2}},\n" -% " f2 = 1,\n" -% " f3 = 2},\n" -% " f2 = 3,\n" -% " f3 = 4},\n" -% " f2 = 5,\n" -% " f3 = 6}">>, -% p({rrrrr,{rrrrr,{rrrrr,{rrrrr,{rrrrr,{rrrrr,a,{rrrrr, -% {rrrrr,1,2},a,b}},b},{rrrrr,c,d},{rrrrr,1,2}}, -% 1,2},3,4},5,6}, -1)), - ?line "{aaa,\n {aaa," ++ _ = + "{aaaaaaa" ++ _ = + p({A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, + {A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, + {A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, + {A,{A,{ggg,{hhh,{ii,{jj,{kk,{ll,{mm,{nn,{oo,{d,1,2,3,4,5} + }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} + }}}}}}}}}}}}}}}}, 146), + "{aaaaaaa" ++ _ = + p({A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, + {A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, + {A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{A, + {A,{A,{A,{A,{A,{ggg,{hhh,{ii,{jj,{kk,{ll,{mm,{nn,{oo,{a} + }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} + }}}}}}}}}}}}}}}}}}}, 152), + + bt(<<"{aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {g,{h,{i,{j,{k,{l,{m,{n,{o,#" + "d{...}}}}}}}}}}}}}}}}">>, + p({A,{A,{A,{A,{A,{A, + {g,{h,{i,{j,{k,{l,{m,{n,{o,{d,1,2,3,4,5}}}}}}}}}}}}}}}}, 32)), + bt(<<"{a,#b{f = {c,{d,{e,{f,...}}}}}}">>, + p({a,{b,{c,{d,{e,{f,g}}}}}}, 12)), + bt(<<"{aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,#c{f1 = ddd," + "f2 = eee}}}}}}}}}}">>, + p({A,{A,{A,{A,{A,{A,{A,{A,{A,{c,ddd,eee}}}}}}}}}}, 100)), + bt(<<"{aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,{aaaaaaaaaaaaa,{aaaaaaaaaaaaa,...}}}}">>, + p({A,{A,{A,{A,{b}}}}}, 8)), + bt(<<"{aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,{aaaaaaaaaaaaa,{aaaaaaaaaaaaa,...}}}}}">>, + p({A,{A,{A,{A,{A,{b}}}}}}, 10)), + bt(<<"{aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa," + "{aaaaaaaaaaaaa,#a{}}}}}}}}}}}">>, + p({A,{A,{A,{A,{A,{A,{A,{A,{A,{A,{a}}}}}}}}}}}, 23)), + bt(<<"{aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n", + " #rrrrr{\n" + " f1 = kljlkjlksfdgkljlsdkjf," + "f2 = kljkljsdaflkjlkjsdf,...}}}}">>, + p({A,{A,{A,{rrrrr, kljlkjlksfdgkljlsdkjf, + kljkljsdaflkjlkjsdf, + asdfkldsjfklkljsdklfds}}}}, 10)), + bt(<<"{aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {aaaaaaaaaaaaa,\n" + " {g,{h,{i,{j,{k,{l,{m,{n," + "{o,#a{}}}}}}}}}}}}}}}}}">>, + p({A,{A,{A,{A,{A,{A,{A, + {g,{h,{i,{j,{k,{l,{m,{n,{o,{a}}}}}}}}}}}}}}}}}, 100)), + bt(<<"#c{\n" + " f1 = \n" + " #c{\n" + " f1 = \n" + " #c{\n" + " f1 = \n" + " #c{\n" + " f1 = \n" + " #c{\n" + " f1 = \n" + " #c{\n" + " f1 = \n" + " #c{\n" + " f1 = \n" + " #c{\n" + " f1 = \n" + " #c{\n" + " f1 = #c{f1 = #c{f1 = #c{f1 = a," + "f2 = b},f2 = b},f2 = b},\n" + " f2 = b},\n" + " f2 = b},\n" + " f2 = b},\n" + " f2 = b},\n" + " f2 = b},\n" + " f2 = b},\n" + " f2 = b},\n" + " f2 = b},\n" + " f2 = b}">>, + p({c,{c,{c,{c,{c,{c,{c,{c,{c,{c,{c,{c,a,b},b},b},b},b},b}, + b},b},b},b},b},b}, -1)), + bt(<<"#rrrrr{\n" + " f1 = \n" + " #rrrrr{\n" + " f1 = \n" + " #rrrrr{\n" + " f1 = \n" + " #rrrrr{\n" + " f1 = \n" + " {rrrrr,{rrrrr,a,#rrrrr{f1 = {rrrrr,1,2},f2 = a," + "f3 = b}},b},\n" + " f2 = {rrrrr,c,d},\n" + " f3 = {rrrrr,1,2}},\n" + " f2 = 1,f3 = 2},\n" + " f2 = 3,f3 = 4},\n" + " f2 = 5,f3 = 6}">>, + p({rrrrr,{rrrrr,{rrrrr,{rrrrr,{rrrrr,{rrrrr,a,{rrrrr, + {rrrrr,1,2},a,b}},b},{rrrrr,c,d},{rrrrr,1,2}}, + 1,2},3,4},5,6}, -1)), + "{aaa,\n {aaa," ++ _ = p({aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa, - {aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa, - {aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa, - {aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa, - {aaa,a}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}, + {aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa, + {aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa, + {aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa,{aaa, + {aaa,a}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}, 1, 80, -1), %% A few other cases... - ?line "{a,#Fun<" ++ _ = lists:flatten(io_lib_pretty:print({a,fun fmt/2})), - ?line "#Fun<" ++ _ = io_lib_pretty:print(fun() -> foo end), - % ?line "[<<\"foobar\">>|<<\"barf\"...>>]" = - % p([<<"foobar">>|<<"barfoo">>], 1, 30, 4), + "{a,#Fun<" ++ _ = lists:flatten(io_lib_pretty:print({a,fun fmt/2})), + "#Fun<" ++ _ = io_lib_pretty:print(fun() -> foo end), %% No support for negative columns any more: - ?line "[a,\n [b,\n c,\n d,\n [e,\n f]],\n c]" = - p([a,[b,c,d,[e,f]],c], -1, 2, 10), - ?line "[a,\n [b,\n c,\n d,\n [e,\n f]],\n c]" = - p([a,[b,c,d,[e,f]],c], 0, 2, 10), + "[a,\n [b,\n c,\n d,\n [e,\n f]],\n c]" = + p([a,[b,c,d,[e,f]],c], -1, 2, 10), + "[a,\n [b,\n c,\n d,\n [e,\n f]],\n c]" = + p([a,[b,c,d,[e,f]],c], 0, 2, 10), %% 20 bytes are tried first, then the rest. Try 21 bytes: L = lists:duplicate(20, $a), - % ?line bt(<<"<<\"aaaaaa\"\n \"aaaaaa\"\n \"aaaaaa\"\n \"aaa\">>">>, - ?line bt(<<"<<\"aaaaaaaaaaaaaaaaaaaaa\">>">>, - p(list_to_binary([$a | L]), 1, 10, -1)), - ?line "<<97," ++ _ = p(list_to_binary(L ++ [3]), 1, 10, -1), - % ?line "<<\"aaaa\"...>>" = p(list_to_binary(L ++ [3]), 1, 10, 2), - % ?line "<<\"aaaaaa\"\n \"aa\"...>>" = - % ?line "<<\"aaaaaaaa\"...>>" = - % p(list_to_binary(L ++ [3]), 1, 10, 3), - % ?line "<<\"aaaaaa\"\n \"aaaaaa\"\n \"aaaaaa\"\n \"aa\"...>>" = - % ?line "<<\"aaaaaaaaaaaaaaaaaaaa\"...>>" = - % p(list_to_binary(L ++ [3]), 1, 10, 21), - ?line "<<97," ++ _ = p(list_to_binary(L ++ [3]), 1, 10, 22), - - ?line "\"\\b\\t\\n\\v\\f\\r\\e\250\"" = - p([8,9,10,11,12,13,27,168], 1, 40, -1), - % ?line "\"\\b\\t\\n\"\n \"\\v\\f\\r\"\n \"\\e\250\"" = - ?line "\"\\b\\t\\n\\v\\f\\r\\e¨\"" = - p([8,9,10,11,12,13,27,168], 1, 10, -1), - ?line "\"\\b\\t\\n\\v\\f\\r\\e\250\"" = - p([8,9,10,11,12,13,27,168], 1, 40, 100), - % ?line "\"\\e\\t\\nab\"\n \"cd\"" = - ?line "\"\\e\\t\\nabcd\"" = - p("\e\t\nabcd", 1, 12, -1), + %% bt(<<"<<\"aaaaaa\"\n \"aaaaaa\"\n \"aaaaaa\"\n \"aaa\">>">>, + bt(<<"<<\"aaaaaaaaaaaaaaaaaaaaa\">>">>, + p(list_to_binary([$a | L]), 1, 10, -1)), + "<<97," ++ _ = p(list_to_binary(L ++ [3]), 1, 10, -1), + "<<97," ++ _ = p(list_to_binary(L ++ [3]), 1, 10, 22), + + "\"\\b\\t\\n\\v\\f\\r\\e\250\"" = + p([8,9,10,11,12,13,27,168], 1, 40, -1), + %% "\"\\b\\t\\n\"\n \"\\v\\f\\r\"\n \"\\e\250\"" = + "\"\\b\\t\\n\\v\\f\\r\\e¨\"" = + p([8,9,10,11,12,13,27,168], 1, 10, -1), + "\"\\b\\t\\n\\v\\f\\r\\e\250\"" = + p([8,9,10,11,12,13,27,168], 1, 40, 100), + %% "\"\\e\\t\\nab\"\n \"cd\"" = + "\"\\e\\t\\nabcd\"" = + p("\e\t\nabcd", 1, 12, -1), %% DEL (127) is special... - ?line "[127]" = p("\d", 1, 10, -1), - ?line "[127]" = p([127], 1, 10, 100), + "[127]" = p("\d", 1, 10, -1), + "[127]" = p([127], 1, 10, 100), - ?line "<<\"\\b\\t\\n\\v\\f\\r\\e\250\">>" = - p(<<8,9,10,11,12,13,27,168>>, 1, 40, -1), - ?line "<<\"\\b\\t\\n\\v\\f\\r\\e\250\">>" = - p(<<8,9,10,11,12,13,27,168>>, 1, 10, -1), - ?line "<<127>>" = p(<<127>>, 1, 10, 100), + "<<\"\\b\\t\\n\\v\\f\\r\\e\250\">>" = + p(<<8,9,10,11,12,13,27,168>>, 1, 40, -1), + "<<\"\\b\\t\\n\\v\\f\\r\\e\250\">>" = + p(<<8,9,10,11,12,13,27,168>>, 1, 10, -1), + "<<127>>" = p(<<127>>, 1, 10, 100), %% "Partial" string binaries: - ?line "<<\"he\"...>>" = p(list_to_binary("he"++[3]), 1, 80, 2), - ?line "<<\"he\"...>>" = p(list_to_binary("he"++[3]), 1, 80, 3), - ?line "<<104,101,3>>" = p(list_to_binary("he"++[3]), 1, 80, 4), - ?line "<<...>>" = p(list_to_binary([3] ++ "he"), 1, 80, 1), - ?line "<<3,...>>" = p(list_to_binary([3] ++ "he"), 1, 80, 2), - ?line "<<3,104,...>>" = p(list_to_binary([3] ++ "he"), 1, 80, 3), - - ?line "<<\"12345678901234567890\"...>>" = - p(list_to_binary("12345678901234567890"++[3]), 1, 80, 8), - ?line "<<\"12345678901234567890\"...>>" = - p(list_to_binary("12345678901234567890"++[3]), 1, 80, 21), - ?line "<<49," ++ _ = - p(list_to_binary("12345678901234567890"++[3]), 1, 80, 22), - - ?line "{sdfsdfj,\n 23" ++ _ = - p({sdfsdfj,23423423342.23432423}, 1, 17, -1), - - ?line bt(<<"kljkljlksdjjlf kljalkjlsdajafasjdfj [kjljklasdf,kjlljsfd,sdfsdkjfsd,kjjsdf,jl, + "<<\"he\"...>>" = p(list_to_binary("he"++[3]), 1, 80, 2), + "<<\"he\"...>>" = p(list_to_binary("he"++[3]), 1, 80, 3), + "<<104,101,3>>" = p(list_to_binary("he"++[3]), 1, 80, 4), + "<<...>>" = p(list_to_binary([3] ++ "he"), 1, 80, 1), + "<<3,...>>" = p(list_to_binary([3] ++ "he"), 1, 80, 2), + "<<3,104,...>>" = p(list_to_binary([3] ++ "he"), 1, 80, 3), + + "<<\"12345678901234567890\"...>>" = + p(list_to_binary("12345678901234567890"++[3]), 1, 80, 8), + "<<\"12345678901234567890\"...>>" = + p(list_to_binary("12345678901234567890"++[3]), 1, 80, 21), + "<<49," ++ _ = + p(list_to_binary("12345678901234567890"++[3]), 1, 80, 22), + + "{sdfsdfj,\n 23" ++ _ = + p({sdfsdfj,23423423342.23432423}, 1, 17, -1), + + bt(<<"kljkljlksdjjlf kljalkjlsdajafasjdfj [kjljklasdf,kjlljsfd,sdfsdkjfsd,kjjsdf,jl, lkjjlajsfd|jsdf]">>, fmt("~w ~w ~p", [kljkljlksdjjlf, @@ -949,45 +678,36 @@ otp_6354(Config) when is_list(Config) -> jsdf]])), %% Binaries are split as well: - ?line bt(<<"<<80,100,0,55,55,55,55,55,55,55,55,55,\n " + bt(<<"<<80,100,0,55,55,55,55,55,55,55,55,55,\n " "55,55,55,55,55,55,55,...>>">>, p(<<80,100,0,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55, 55,55,55,55,55,55,55,55,55,55,55,55>>,1,40,20)), - ?line bt(<<"<<80,100,0,55,55,55,55,55,55,55,55,55,\n " + bt(<<"<<80,100,0,55,55,55,55,55,55,55,55,55,\n " "55,55,55,55,55,55,55,55,55,55,55,55,\n 55,55,55,55,55,55>>">>, p(<<80,100,0,55,55,55,55,55,55,55,55,55,55,55,55,55,55,55, 55,55,55,55,55,55,55,55,55,55,55,55>>,1,40,-1)), - ?line "<<0,0,0,\n ...>>" = p(<<0,0,0,0,0>>, 1, 10, 4), + "<<0,0,0,\n ...>>" = p(<<0,0,0,0,0>>, 1, 10, 4), %% ~W now uses ",..." when printing tuples - ?line "[a,b|...]" = fmt("~W", [[a,b,c,d,e], 3]), - ?line "{a,b,...}" = fmt("~W", [{a,b,c,d,e}, 3]), + "[a,b|...]" = fmt("~W", [[a,b,c,d,e], 3]), + "{a,b,...}" = fmt("~W", [{a,b,c,d,e}, 3]), ok. -otp_6495(doc) -> - ["OTP-6495. io_lib_pretty bugfix."]; -otp_6495(suite) -> - []; +%% OTP-6495. io_lib_pretty bugfix. otp_6495(Config) when is_list(Config) -> - ?line bt(<<"[120,120,120,120,120,120,120,120,120,120,120,120,120,120," + bt(<<"[120,120,120,120,120,120,120,120,120,120,120,120,120,120," "120,120,120,120,120]<<1>>">>, fmt("~w~p", ["xxxxxxxxxxxxxxxxxxx", <<1>>])), ok. -otp_6517(doc) -> - ["OTP-6517. The Format argument of fwrite can be a binary."]; -otp_6517(suite) -> - []; +%% OTP-6517. The Format argument of fwrite can be a binary. otp_6517(Config) when is_list(Config) -> - ?line "string" = fmt(<<"~s">>, [<<"string">>]), + "string" = fmt(<<"~s">>, [<<"string">>]), ok. -otp_6502(doc) -> - ["OTP-6502. Bits."]; -otp_6502(suite) -> - []; +%% OTP-6502. Bits. otp_6502(Config) when is_list(Config) -> - ?line bt(<< + bt(<< "[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]" "<<0,0,8,\n" " " @@ -995,10 +715,7 @@ otp_6502(Config) when is_list(Config) -> fmt("~w~p", [lists:seq(0, 25), <<17:25>>])), ok. -otp_7421(doc) -> - ["OTP-7421. Soft limit of 60 chars removed when pretty printing."]; -otp_7421(suite) -> - []; +%% OTP-7421. Soft limit of 60 chars removed when pretty printing. otp_7421(Config) when is_list(Config) -> bt(<<"{aa,bb,\n" " c,dd,\n" @@ -1066,31 +783,28 @@ rfd(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 0) -> rfd(_, _) -> no. -manpage(doc) -> - ["The examples in io(3) and io_lib(3)."]; -manpage(suite) -> - []; +%% The examples in io(3) and io_lib(3). manpage(Config) when is_list(Config) -> %% The examples that write or print only, not the ones that read... - ?line bt(<<"Hello world!\n">>, + bt(<<"Hello world!\n">>, fmt("Hello world!~n", [])), - ?line bt(<<"| aaaaa|bbbbb |ccccc|\n">>, % bugfix + bt(<<"| aaaaa|bbbbb |ccccc|\n">>, % bugfix fmt("|~10.5c|~-10.5c|~5c|~n", [$a, $b, $c])), - ?line bt(<<"|**********|\n">>, + bt(<<"|**********|\n">>, fmt("|~10w|~n", [{hey, hey, hey}])), - ?line bt(<<"|{hey,hey,h|\n">>, + bt(<<"|{hey,hey,h|\n">>, fmt("|~10s|~n", [io_lib:write({hey, hey, hey})])), T = [{attributes,[[{id,age,1.50000},{mode,explicit}, {typename,"INTEGER"}], [{id,cho},{mode,explicit},{typename,'Cho'}]]}, {typename,'Person'},{tag,{'PRIVATE',3}},{mode,implicit}], - ?line bt(<<"[{attributes,[[{id,age,1.5},{mode,explicit},{typename," + bt(<<"[{attributes,[[{id,age,1.5},{mode,explicit},{typename," "[73,78,84,69,71,69,82]}],[{id,cho},{mode,explicit}," "{typename,'Cho'}]]},{typename,'Person'},{tag,{'PRIVATE',3}}," "{mode,implicit}]\n">>, fmt("~w~n", [T])), - ?line bt(<<"[{attributes,[[{id,age,1.5},\n" + bt(<<"[{attributes,[[{id,age,1.5},\n" " {mode,explicit},\n" " {typename,\"INTEGER\"}],\n" " [{id,cho},{mode,explicit},{typename,'Cho'}]]},\n" @@ -1098,7 +812,7 @@ manpage(Config) when is_list(Config) -> " {tag,{'PRIVATE',3}},\n" " {mode,implicit}]\n">>, fmt("~62p~n", [T])), - ?line bt(<<"Here T = [{attributes,[[{id,age,1.5},\n" + bt(<<"Here T = [{attributes,[[{id,age,1.5},\n" " {mode,explicit},\n" " {typename,\"INTEGER\"}],\n" " [{id,cho},\n" @@ -1108,67 +822,64 @@ manpage(Config) when is_list(Config) -> " {tag,{'PRIVATE',3}},\n" " {mode,implicit}]\n">>, fmt("Here T = ~62p~n", [T])), - ?line bt(<<"[{attributes,[[{id,age,1.5},{mode,explicit}," + bt(<<"[{attributes,[[{id,age,1.5},{mode,explicit}," "{typename,...}],[{id,cho},{mode,...},{...}]]}," "{typename,'Person'},{tag,{'PRIVATE',3}},{mode,implicit}]\n">>, fmt("~W~n", [T,9])), - ?line bt(<<"[{attributes,[[{id,age,1.5},{mode,explicit},{typename,...}]," + bt(<<"[{attributes,[[{id,age,1.5},{mode,explicit},{typename,...}]," "\n " "[{id,cho},{mode,...},{...}]]},\n {typename,'Person'},\n " "{tag,{'PRIVATE',3}},\n {mode,implicit}]\n">>, fmt("~62P~n", [T,9])), - ?line "1F\n" = fmt("~.16B~n", [31]), - ?line "-10011\n" = fmt("~.2B~n", [-19]), - ?line "5Z\n" = fmt("~.36B~n", [5*36+35]), - ?line "10#31\n" = fmt("~X~n", [31,"10#"]), - ?line "-0x1F\n" = fmt("~.16X~n", [-31,"0x"]), - ?line "10#31\n" = fmt("~.10#~n", [31]), - ?line "-16#1F\n" = fmt("~.16#~n", [-31]), - ?line "abc def 'abc def' {foo,1} A \n" = + "1F\n" = fmt("~.16B~n", [31]), + "-10011\n" = fmt("~.2B~n", [-19]), + "5Z\n" = fmt("~.36B~n", [5*36+35]), + "10#31\n" = fmt("~X~n", [31,"10#"]), + "-0x1F\n" = fmt("~.16X~n", [-31,"0x"]), + "10#31\n" = fmt("~.10#~n", [31]), + "-16#1F\n" = fmt("~.16#~n", [-31]), + "abc def 'abc def' {foo,1} A \n" = fmt("~s ~w ~i ~w ~c ~n", ['abc def', 'abc def', {foo, 1},{foo, 1}, 65]), - % fmt("~s", [65]), + %% fmt("~s", [65]), %% io_lib(3) - ?line bt(<<"{1,[2],[3],[...],...}">>, + bt(<<"{1,[2],[3],[...],...}">>, lists:flatten(io_lib:write({1,[2],[3],[4,5],6,7,8,9}, 5))), ok. -otp_6708(doc) -> - ["OTP-6708. Fewer newlines when pretty-printing."]; -otp_6708(suite) -> - []; +%% OTP-6708. Fewer newlines when pretty-printing. otp_6708(Config) when is_list(Config) -> - ?line bt(<<"[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,\n" + bt(<<"[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,\n" " 23,24,25,26,27,28,29|...]">>, p(lists:seq(1,1000), 30)), - ?line bt(<<"{lkjasklfjsdak,mlkasjdflksj,klasdjfklasd,jklasdfjkl,\n" + bt(<<"{lkjasklfjsdak,mlkasjdflksj,klasdjfklasd,jklasdfjkl,\n" " jklsdjfklsd,masdfjkkl}">>, p({lkjasklfjsdak,mlkasjdflksj,klasdjfklasd,jklasdfjkl, jklsdjfklsd, masdfjkkl}, -1)), - ?line bt(<<"#b{f = {lkjljalksdf,jklaskfjd,kljasdlf,kljasdf,kljsdlkf,\n" + bt(<<"#b{f = {lkjljalksdf,jklaskfjd,kljasdlf,kljasdf,kljsdlkf,\n" " kjdd}}">>, p({b, {lkjljalksdf,jklaskfjd,kljasdlf,kljasdf,kljsdlkf,kjdd}}, -1)), - ?line bt(<<"#b{f = {lkjljalksdf,jklaskfjd,kljasdlf,kljasdf,kljsdlkf,\n" + bt(<<"#b{f = {lkjljalksdf,jklaskfjd,kljasdlf,kljasdf,kljsdlkf,\n" " kdd}}">>, p({b, {lkjljalksdf,jklaskfjd,kljasdlf,kljasdf,kljsdlkf,kdd}}, -1)), - ?line bt(<<"#e{f = undefined,g = undefined,\n" + bt(<<"#e{f = undefined,g = undefined,\n" " h = #e{f = 11,g = 22,h = 333}}">>, p({e,undefined,undefined,{e,11,22,333}}, -1)), - ?line bt(<<"[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21|\n" + bt(<<"[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21|\n" " apa11]">>, p(lists:seq(1,21) ++ apa11, -1)), - ?line bt(<<"[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,\n" + bt(<<"[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,\n" " 23,\n" " {{abadalkjlasdjflksdajfksdklfsdjlkfdlskjflsdj" "flsdjfldsdsdddd}}]">>, p(lists:seq(1,23) ++ [{{abadalkjlasdjflksdajfksdklfsdjlkfdlskjflsdjflsdjfldsdsdddd}}], -1)), - ?line bt(<<"{lkjasdf,\n" + bt(<<"{lkjasdf,\n" " {kjkjsd,\n" " {kjsd,\n" " {kljsdf,\n" @@ -1180,7 +891,7 @@ otp_6708(Config) when is_list(Config) -> {dkjsdf,{kjlds, {kljsd,{kljs,{kljlkjsd}}}}}}}}}}, -1)), - ?line bt(<<"{lkjasdf,\n" + bt(<<"{lkjasdf,\n" " {kjkjsd,\n" " {kjsd,{kljsdf,{kjlsd,{dkjsdf,{kjlds," "{kljsd,{kljs}}}}}}}}}">>, @@ -1188,24 +899,24 @@ otp_6708(Config) when is_list(Config) -> {kljsdf,{kjlsd,{dkjsdf, {kjlds,{kljsd,{kljs}}}}}}}}}, -1)), - ?line bt(<<"<<1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,\n" + bt(<<"<<1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,\n" " 22,23>>">>, p(list_to_binary(lists:seq(1,23)), -1)), - ?line bt(<<"<<100,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,\n" + bt(<<"<<100,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,\n" " 27>>">>, p(list_to_binary([100|lists:seq(10,27)]), -1)), - ?line bt(<<"<<100,101,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,\n" + bt(<<"<<100,101,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,\n" " 26>>">>, p(list_to_binary([100,101|lists:seq(10,26)]), -1)), - ?line bt(<<"{{<<100,101,102,10,11,12,13,14,15,16,17,18,19,20,21,22,\n" + bt(<<"{{<<100,101,102,10,11,12,13,14,15,16,17,18,19,20,21,22,\n" " 23>>}}">>, p({{list_to_binary([100,101,102|lists:seq(10,23)])}}, -1)), - ?line bt(<<"[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22|\n" + bt(<<"[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22|\n" " ap]">>, p(lists:seq(1,22) ++ ap, -1)), - ?line bt(<<"[1,2,3,4,5,6,7,8,9,10,{},[],\n <<>>,11,12,13,14,15]">>, + bt(<<"[1,2,3,4,5,6,7,8,9,10,{},[],\n <<>>,11,12,13,14,15]">>, p(lists:seq(1,10) ++ [{},[],<<>>] ++ lists:seq(11,15),1,30,-1)), - ?line bt(<<"[ddd,ddd,\n" + bt(<<"[ddd,ddd,\n" " {1},\n" " [1,2],\n" " ddd,kdfd,\n" @@ -1215,7 +926,7 @@ otp_6708(Config) when is_list(Config) -> p([ddd,ddd,{1},[1,2],ddd,kdfd,[[1,2],a,b,c],<<"foo">>,<<"bar">>, 1,{2}],1,50,-1)), - ?line bt(<<"{dskljsadfkjsdlkjflksdjflksdjfklsdjklfjsdklfjlsdjfkl,jksd,\n" + bt(<<"{dskljsadfkjsdlkjflksdjflksdjfklsdjklfjsdklfjlsdjfkl,jksd,\n" " " "lkjsdf,kljsdf,kljsf,kljsdf,kljsdf,jkldf,jklsdf,kljsdf,\n" " " @@ -1226,7 +937,7 @@ otp_6708(Config) when is_list(Config) -> lkjsdf,kljsdf,kljsf,kljsdf,kljsdf,jkldf,jklsdf,kljsdf, kljsdf,jklsdf,lkjfd,lkjsdf,kljsdf,kljsdf,lkjsdf,kljsdf, lkjsdfsd,kljsdf,kjsfj}, 1, 110, -1)), - ?line bt(<<"{dskljsadfkjsdlkjflksdjflksdjfklsdjklfjsdklfjlsdjfkl," + bt(<<"{dskljsadfkjsdlkjflksdjflksdjfklsdjklfjsdklfjlsdjfkl," "#d{aaaaaaaaaaaaaaaaaaaa = 1,\n" " " "bbbbbbbbbbbbbbbbbbbb = 2,cccccccccccccccccccc = 3,\n" @@ -1239,15 +950,12 @@ otp_6708(Config) when is_list(Config) -> -define(ONE(N), ((1 bsl N) - 1)). -define(ALL_ONES, ((1 bsl 52) - 1)). -otp_7084(doc) -> - ["OTP-7084. Printing floating point numbers nicely."]; -otp_7084(suite) -> - []; + +otp_7084() -> + [{timetrap,{minutes,3}}]. + +%% OTP-7084. Printing floating point numbers nicely. otp_7084(Config) when is_list(Config) -> - OldDog=?config(watchdog, Config), - test_server:timetrap_cancel(OldDog), - Timeout = 180, - ?line Dog = test_server:timetrap({seconds,Timeout}), L = [{g_warm_up, fun g_warm_up/0}, {g_big_pos_float, fun g_big_pos_float/0}, {g_small_neg_float, fun g_small_neg_float/0}, @@ -1263,7 +971,6 @@ otp_7084(Config) when is_list(Config) -> catch throw:Reason -> Reason end, - ?line test_server:timetrap_cancel(Dog), R. g_warm_up() -> @@ -1295,7 +1002,7 @@ g_close_to_zero() -> g_denormalized() -> %% Denormalized floats (mantissa carry): -% D = 5, +%% D = 5, %% Faster: D = 1, [ft({{S,0,?ONE(N)},D,D}) || S <- [0,1], N <- lists:seq(0, 52)], @@ -1303,7 +1010,7 @@ g_denormalized() -> g_normalized() -> %% Normalized floats (exponent carry): -% D = 5, +%% D = 5, %% Faster: D = 1, [ft({{S,E,?ONE(52)},D,D}) || S <- [0,1], E <- lists:seq(0, 2045)], @@ -1322,8 +1029,7 @@ g_choice() -> g_misc() -> L_0_308 = lists:seq(0, 308), L_0_307 = lists:seq(0, 307), -% L_1_9 = lists:seq(1, 9), -% L_0_9 = lists:seq(0, 9), + %% Faster: L_1_9 = [1,5,9], L_0_9 = [0,1,5,9], @@ -1798,10 +1504,10 @@ pack(Sign, Exp, Frac) -> %% Whitebox test of io_lib:collect_line/3. io_lib_collect_line_3_wb(Config) when is_list(Config) -> - ?line do_collect_line(binary, "\n"), - ?line do_collect_line(binary, "\r\n"), - ?line do_collect_line(list, "\n"), - ?line do_collect_line(list, "\r\n"), + do_collect_line(binary, "\n"), + do_collect_line(binary, "\r\n"), + do_collect_line(list, "\n"), + do_collect_line(list, "\r\n"), ok. do_collect_line(Mode, Eol) -> @@ -1860,44 +1566,44 @@ do_collect_line_adjust_rest(Rest, [List|T]) when is_list(List) -> cr_whitespace_in_string(Config) when is_list(Config) -> - ?line {ok,["abc"],[]} = io_lib:fread("~s", "\rabc"). + {ok,["abc"],[]} = io_lib:fread("~s", "\rabc"). io_fread_newlines(Config) when is_list(Config) -> - ?line PrivDir = ?privdir(Config), - ?line Fname = filename:join(PrivDir, "io_fread_newlines.txt"), - ?line F0 = [[0,1,2,3,4,5,6,7,8,9]], - ?line F1 = [[0,1,2,3,4,5,6,7,8],[9]], - ?line F2 = [[0,1,2,3,4,5,6,7],[8,9]], - ?line F3 = [[0,1,2,3,4,5,6],[7,8,9]], - ?line F4 = [[0,1,2,3,4,5],[6,7,8,9]], - ?line F5 = [[0,1,2,3,4],[5,6,7,8,9]], - ?line F6 = [[0,1,2,3],[4,5,6,7],[8,9]], - ?line F7 = [[0,1,2],[3,4,5],[6,7,8],[9]], - ?line F8 = [[0,1],[2,3],[4,5],[6,7],[8,9]], - ?line F9 = [[0],[1],[2],[3],[4],[5],[6],[7],[8],[9]], - ?line Newlines = ["\n", "\r\n", "\r"], + PrivDir = ?privdir(Config), + Fname = filename:join(PrivDir, "io_fread_newlines.txt"), + F0 = [[0,1,2,3,4,5,6,7,8,9]], + F1 = [[0,1,2,3,4,5,6,7,8],[9]], + F2 = [[0,1,2,3,4,5,6,7],[8,9]], + F3 = [[0,1,2,3,4,5,6],[7,8,9]], + F4 = [[0,1,2,3,4,5],[6,7,8,9]], + F5 = [[0,1,2,3,4],[5,6,7,8,9]], + F6 = [[0,1,2,3],[4,5,6,7],[8,9]], + F7 = [[0,1,2],[3,4,5],[6,7,8],[9]], + F8 = [[0,1],[2,3],[4,5],[6,7],[8,9]], + F9 = [[0],[1],[2],[3],[4],[5],[6],[7],[8],[9]], + Newlines = ["\n", "\r\n", "\r"], try - ?line io_fread_newlines_1([F0,F1,F2,F3,F4,F5,F6,F7,F8,F9], + io_fread_newlines_1([F0,F1,F2,F3,F4,F5,F6,F7,F8,F9], Fname, Newlines) after file:delete(Fname) end. io_fread_newlines_1(Fs, Fname, [Newline|Newlines]) -> - ?line ok = io_fread_newlines_2(Fs, Fname, Newline), - ?line io_fread_newlines_1(Fs, Fname, Newlines); + ok = io_fread_newlines_2(Fs, Fname, Newline), + io_fread_newlines_1(Fs, Fname, Newlines); io_fread_newlines_1(_, _, []) -> ok. io_fread_newlines_2([F|Fs], Fname, Newline) -> - ?line N1 = write_newlines_file(Fname, F, Newline), - ?line {F2,N2} = read_newlines_file(Fname), - ?line io:format("~w ~p ~w~n~n", [N1,F,N2]), - ?line F2 = lists:flatten(F), + N1 = write_newlines_file(Fname, F, Newline), + {F2,N2} = read_newlines_file(Fname), + io:format("~w ~p ~w~n~n", [N1,F,N2]), + F2 = lists:flatten(F), %% Intermediate newlines are not counted - ?line N2 = N1 - (length(F) - 1)*length(Newline), - ?line io_fread_newlines_2(Fs, Fname, Newline); + N2 = N1 - (length(F) - 1)*length(Newline), + io_fread_newlines_2(Fs, Fname, Newline); io_fread_newlines_2([], _, _) -> ok. @@ -1939,111 +1645,108 @@ read_newlines(Fd, Acc, N0) -> -otp_8989(doc) -> - "OTP-8989 io:format for ~F.Ps ignores P in some cases"; +%% OTP-8989 io:format for ~F.Ps ignores P in some cases. otp_8989(Suite) when is_list(Suite) -> Hello = "Hello", - ?line " Hello" = fmt("~6.6s", [Hello]), - ?line " Hello" = fmt("~*.6s", [6,Hello]), - ?line " Hello" = fmt("~6.*s", [6,Hello]), - ?line " Hello" = fmt("~*.*s", [6,6,Hello]), + " Hello" = fmt("~6.6s", [Hello]), + " Hello" = fmt("~*.6s", [6,Hello]), + " Hello" = fmt("~6.*s", [6,Hello]), + " Hello" = fmt("~*.*s", [6,6,Hello]), %% - ?line " Hello" = fmt("~6.5s", [Hello]), - ?line " Hello" = fmt("~*.5s", [6,Hello]), - ?line " Hello" = fmt("~6.*s", [5,Hello]), - ?line " Hello" = fmt("~*.*s", [6,5,Hello]), + " Hello" = fmt("~6.5s", [Hello]), + " Hello" = fmt("~*.5s", [6,Hello]), + " Hello" = fmt("~6.*s", [5,Hello]), + " Hello" = fmt("~*.*s", [6,5,Hello]), %% - ?line " Hell" = fmt("~6.4s", [Hello]), - ?line " Hell" = fmt("~*.4s", [6,Hello]), - ?line " Hell" = fmt("~6.*s", [4,Hello]), - ?line " Hell" = fmt("~*.*s", [6,4,Hello]), + " Hell" = fmt("~6.4s", [Hello]), + " Hell" = fmt("~*.4s", [6,Hello]), + " Hell" = fmt("~6.*s", [4,Hello]), + " Hell" = fmt("~*.*s", [6,4,Hello]), %% - ?line "Hello" = fmt("~5.5s", [Hello]), - ?line "Hello" = fmt("~*.5s", [5,Hello]), - ?line "Hello" = fmt("~5.*s", [5,Hello]), - ?line "Hello" = fmt("~*.*s", [5,5,Hello]), + "Hello" = fmt("~5.5s", [Hello]), + "Hello" = fmt("~*.5s", [5,Hello]), + "Hello" = fmt("~5.*s", [5,Hello]), + "Hello" = fmt("~*.*s", [5,5,Hello]), %% - ?line " Hell" = fmt("~5.4s", [Hello]), - ?line " Hell" = fmt("~*.4s", [5,Hello]), - ?line " Hell" = fmt("~5.*s", [4,Hello]), - ?line " Hell" = fmt("~*.*s", [5,4,Hello]), + " Hell" = fmt("~5.4s", [Hello]), + " Hell" = fmt("~*.4s", [5,Hello]), + " Hell" = fmt("~5.*s", [4,Hello]), + " Hell" = fmt("~*.*s", [5,4,Hello]), %% - ?line "Hell" = fmt("~4.4s", [Hello]), - ?line "Hell" = fmt("~*.4s", [4,Hello]), - ?line "Hell" = fmt("~4.*s", [4,Hello]), - ?line "Hell" = fmt("~*.*s", [4,4,Hello]), + "Hell" = fmt("~4.4s", [Hello]), + "Hell" = fmt("~*.4s", [4,Hello]), + "Hell" = fmt("~4.*s", [4,Hello]), + "Hell" = fmt("~*.*s", [4,4,Hello]), %% - ?line " Hel" = fmt("~4.3s", [Hello]), - ?line " Hel" = fmt("~*.3s", [4,Hello]), - ?line " Hel" = fmt("~4.*s", [3,Hello]), - ?line " Hel" = fmt("~*.*s", [4,3,Hello]), + " Hel" = fmt("~4.3s", [Hello]), + " Hel" = fmt("~*.3s", [4,Hello]), + " Hel" = fmt("~4.*s", [3,Hello]), + " Hel" = fmt("~*.*s", [4,3,Hello]), %% %% - ?line "Hello " = fmt("~-6.6s", [Hello]), - ?line "Hello " = fmt("~*.6s", [-6,Hello]), - ?line "Hello " = fmt("~-6.*s", [6,Hello]), - ?line "Hello " = fmt("~*.*s", [-6,6,Hello]), + "Hello " = fmt("~-6.6s", [Hello]), + "Hello " = fmt("~*.6s", [-6,Hello]), + "Hello " = fmt("~-6.*s", [6,Hello]), + "Hello " = fmt("~*.*s", [-6,6,Hello]), %% - ?line "Hello " = fmt("~-6.5s", [Hello]), - ?line "Hello " = fmt("~*.5s", [-6,Hello]), - ?line "Hello " = fmt("~-6.*s", [5,Hello]), - ?line "Hello " = fmt("~*.*s", [-6,5,Hello]), + "Hello " = fmt("~-6.5s", [Hello]), + "Hello " = fmt("~*.5s", [-6,Hello]), + "Hello " = fmt("~-6.*s", [5,Hello]), + "Hello " = fmt("~*.*s", [-6,5,Hello]), %% - ?line "Hell " = fmt("~-6.4s", [Hello]), - ?line "Hell " = fmt("~*.4s", [-6,Hello]), - ?line "Hell " = fmt("~-6.*s", [4,Hello]), - ?line "Hell " = fmt("~*.*s", [-6,4,Hello]), + "Hell " = fmt("~-6.4s", [Hello]), + "Hell " = fmt("~*.4s", [-6,Hello]), + "Hell " = fmt("~-6.*s", [4,Hello]), + "Hell " = fmt("~*.*s", [-6,4,Hello]), %% - ?line "Hello" = fmt("~-5.5s", [Hello]), - ?line "Hello" = fmt("~*.5s", [-5,Hello]), - ?line "Hello" = fmt("~-5.*s", [5,Hello]), - ?line "Hello" = fmt("~*.*s", [-5,5,Hello]), + "Hello" = fmt("~-5.5s", [Hello]), + "Hello" = fmt("~*.5s", [-5,Hello]), + "Hello" = fmt("~-5.*s", [5,Hello]), + "Hello" = fmt("~*.*s", [-5,5,Hello]), %% - ?line "Hell " = fmt("~-5.4s", [Hello]), - ?line "Hell " = fmt("~*.4s", [-5,Hello]), - ?line "Hell " = fmt("~-5.*s", [4,Hello]), - ?line "Hell " = fmt("~*.*s", [-5,4,Hello]), + "Hell " = fmt("~-5.4s", [Hello]), + "Hell " = fmt("~*.4s", [-5,Hello]), + "Hell " = fmt("~-5.*s", [4,Hello]), + "Hell " = fmt("~*.*s", [-5,4,Hello]), %% - ?line "Hell" = fmt("~-4.4s", [Hello]), - ?line "Hell" = fmt("~*.4s", [-4,Hello]), - ?line "Hell" = fmt("~-4.*s", [4,Hello]), - ?line "Hell" = fmt("~*.*s", [-4,4,Hello]), + "Hell" = fmt("~-4.4s", [Hello]), + "Hell" = fmt("~*.4s", [-4,Hello]), + "Hell" = fmt("~-4.*s", [4,Hello]), + "Hell" = fmt("~*.*s", [-4,4,Hello]), %% - ?line "Hel " = fmt("~-4.3s", [Hello]), - ?line "Hel " = fmt("~*.3s", [-4,Hello]), - ?line "Hel " = fmt("~-4.*s", [3,Hello]), - ?line "Hel " = fmt("~*.*s", [-4,3,Hello]), + "Hel " = fmt("~-4.3s", [Hello]), + "Hel " = fmt("~*.3s", [-4,Hello]), + "Hel " = fmt("~-4.*s", [3,Hello]), + "Hel " = fmt("~*.*s", [-4,3,Hello]), ok. -io_lib_fread_literal(doc) -> - "OTP-9439 io_lib:fread bug for literate at end"; +%% OTP-9439 io_lib:fread bug for literate at end. io_lib_fread_literal(Suite) when is_list(Suite) -> - ?line {more,"~d",0,""} = io_lib:fread("~d", ""), - ?line {error,{fread,integer}} = io_lib:fread("~d", " "), - ?line {more,"~d",1,""} = io_lib:fread(" ~d", " "), - ?line {ok,[17],"X"} = io_lib:fread(" ~d", " 17X"), + {more,"~d",0,""} = io_lib:fread("~d", ""), + {error,{fread,integer}} = io_lib:fread("~d", " "), + {more,"~d",1,""} = io_lib:fread(" ~d", " "), + {ok,[17],"X"} = io_lib:fread(" ~d", " 17X"), %% - ?line {more,"d",0,""} = io_lib:fread("d", ""), - ?line {error,{fread,input}} = io_lib:fread("d", " "), - ?line {more,"d",1,""} = io_lib:fread(" d", " "), - ?line {ok,[],"X"} = io_lib:fread(" d", " dX"), + {more,"d",0,""} = io_lib:fread("d", ""), + {error,{fread,input}} = io_lib:fread("d", " "), + {more,"d",1,""} = io_lib:fread(" d", " "), + {ok,[],"X"} = io_lib:fread(" d", " dX"), %% - ?line {done,eof,_} = io_lib:fread([], eof, "~d"), - ?line {done,eof,_} = io_lib:fread([], eof, " ~d"), - ?line {more,C1} = io_lib:fread([], " \n", " ~d"), - ?line {done,{error,{fread,input}},_} = io_lib:fread(C1, eof, " ~d"), - ?line {done,{ok,[18]},""} = io_lib:fread(C1, "18\n", " ~d"), + {done,eof,_} = io_lib:fread([], eof, "~d"), + {done,eof,_} = io_lib:fread([], eof, " ~d"), + {more,C1} = io_lib:fread([], " \n", " ~d"), + {done,{error,{fread,input}},_} = io_lib:fread(C1, eof, " ~d"), + {done,{ok,[18]},""} = io_lib:fread(C1, "18\n", " ~d"), %% - ?line {done,eof,_} = io_lib:fread([], eof, "d"), - ?line {done,eof,_} = io_lib:fread([], eof, " d"), - ?line {more,C2} = io_lib:fread([], " \n", " d"), - ?line {done,{error,{fread,input}},_} = io_lib:fread(C2, eof, " d"), - ?line {done,{ok,[]},[]} = io_lib:fread(C2, "d\n", " d"), + {done,eof,_} = io_lib:fread([], eof, "d"), + {done,eof,_} = io_lib:fread([], eof, " d"), + {more,C2} = io_lib:fread([], " \n", " d"), + {done,{error,{fread,input}},_} = io_lib:fread(C2, eof, " d"), + {done,{ok,[]},[]} = io_lib:fread(C2, "d\n", " d"), ok. -printable_range(doc) -> - "Check that the printable range set by the user actually works"; +%% Check that the printable range set by the user actually works. printable_range(Suite) when is_list(Suite) -> Pa = filename:dirname(code:which(?MODULE)), {ok, UNode} = test_server:start_node(printable_range_unicode, slave, @@ -2145,19 +1848,17 @@ flush_from_port(P) -> ok end. -io_lib_print_binary_depth_one(doc) -> - "Test binaries printed with a depth of one behave correctly"; +%% Test binaries printed with a depth of one behave correctly. io_lib_print_binary_depth_one(Suite) when is_list(Suite) -> - ?line "<<>>" = fmt("~W", [<<>>, 1]), - ?line "<<>>" = fmt("~P", [<<>>, 1]), - ?line "<<...>>" = fmt("~W", [<<1>>, 1]), - ?line "<<...>>" = fmt("~P", [<<1>>, 1]), - ?line "<<...>>" = fmt("~W", [<<1:7>>, 1]), - ?line "<<...>>" = fmt("~P", [<<1:7>>, 1]), + "<<>>" = fmt("~W", [<<>>, 1]), + "<<>>" = fmt("~P", [<<>>, 1]), + "<<...>>" = fmt("~W", [<<1>>, 1]), + "<<...>>" = fmt("~P", [<<1>>, 1]), + "<<...>>" = fmt("~W", [<<1:7>>, 1]), + "<<...>>" = fmt("~P", [<<1:7>>, 1]), ok. -otp_10302(doc) -> - "OTP-10302. Unicode"; +%% OTP-10302. Unicode. otp_10302(Suite) when is_list(Suite) -> Pa = filename:dirname(code:which(?MODULE)), {ok, UNode} = test_server:start_node(printable_range_unicode, slave, @@ -2213,15 +1914,13 @@ pretty(Term, Opts) when is_list(Opts) -> is_latin1(S) -> S >= 0 andalso S =< 255. -otp_10836(doc) -> - "OTP-10836. ~ts extended to latin1"; +%% OTP-10836. ~ts extended to latin1. otp_10836(Suite) when is_list(Suite) -> S = io_lib:format("~ts", [[<<"äpple"/utf8>>, <<"äpple">>]]), "äppleäpple" = lists:flatten(S), ok. -otp_10755(doc) -> - "OTP-10755. The 'l' modifier"; +%% OTP-10755. The 'l' modifier otp_10755(Suite) when is_list(Suite) -> S = "string", "\"string\"" = fmt("~p", [S]), @@ -2300,7 +1999,7 @@ do_io_with_huge_message_queue(Config) -> ok; Q -> io:format("Q = ~p", [Q]), - ?t:fail() + ct:fail(failed) end, ok. @@ -2373,7 +2072,7 @@ re_fmt(Pattern, Format, Args) -> nomatch -> io:format("Pattern: ~s", [Pattern]), io:format("Result: ~s", [S]), - ?t:fail(); + ct:fail(failed); match -> ok end. diff --git a/lib/stdlib/test/io_proto_SUITE.erl b/lib/stdlib/test/io_proto_SUITE.erl index 97e6a90b76..ecd0d44db9 100644 --- a/lib/stdlib/test/io_proto_SUITE.erl +++ b/lib/stdlib/test/io_proto_SUITE.erl @@ -39,7 +39,7 @@ -export([uprompt/1]). -%-define(without_test_server, true). +%%-define(without_test_server, true). -ifdef(without_test_server). -define(line, put(line, ?LINE), ). @@ -48,7 +48,7 @@ -define(privdir(_), "./io_SUITE_priv"). -else. -include_lib("common_test/include/ct.hrl"). --define(privdir(Conf), ?config(priv_dir, Conf)). +-define(privdir(Conf), proplists:get_value(priv_dir, Conf)). -endif. %%-define(debug, true). @@ -57,30 +57,25 @@ -define(format(S, A), io:format(S, A)). -define(dbg(Data),io:format(standard_error, "DBG: ~p\r\n",[Data])). -define(RM_RF(Dir),begin io:format(standard_error, "Not Removed: ~p\r\n",[Dir]), - ok end). + ok end). -else. -define(format(S, A), ok). -define(dbg(Data),noop). -define(RM_RF(Dir),rm_rf(Dir)). -endif. - -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(20)). - init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), Term = os:getenv("TERM", "dumb"), os:putenv("TERM","vt100"), - [{watchdog, Dog}, {term, Term} | Config]. + [{term, Term} | Config]. end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - Term = ?config(term,Config), + Term = proplists:get_value(term,Config), os:putenv("TERM",Term), - test_server:timetrap_cancel(Dog), ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,20}}]. all() -> [setopts_getopts, unicode_options, unicode_options_gen, @@ -110,184 +105,175 @@ end_per_group(_GroupName, Config) -> q = [], nxt = eof, mode = list - }). + }). uprompt(_L) -> [1050,1072,1082,1074,1086,32,1077,32,85,110,105,99,111,100,101,32,63]. -unicode_prompt(suite) -> - []; -unicode_prompt(doc) -> - ["Test that an Unicode prompt does not crash the shell"]; +%% Test that an Unicode prompt does not crash the shell. unicode_prompt(Config) when is_list(Config) -> - ?line PA = filename:dirname(code:which(?MODULE)), + PA = filename:dirname(code:which(?MODULE)), case proplists:get_value(default_shell,Config) of old -> ok; new -> - ?line rtnode([{putline,""}, - {putline, "2."}, - {getline, "2"}, - {putline, "shell:prompt_func({io_proto_SUITE,uprompt})."}, - {getline, "default"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline, "\"hej\\n\""}, - {putline, "io:setopts([{binary,true}])."}, - {getline, "ok"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline, "<<\"hej\\n\">>"} - ],[],[],"-pa \""++ PA++"\"") + rtnode([{putline,""}, + {putline, "2."}, + {getline, "2"}, + {putline, "shell:prompt_func({io_proto_SUITE,uprompt})."}, + {getline, "default"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline, "\"hej\\n\""}, + {putline, "io:setopts([{binary,true}])."}, + {getline, "ok"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline, "<<\"hej\\n\">>"} + ],[],[],"-pa \""++ PA++"\"") end, %% And one with oldshell - ?line rtnode([{putline,""}, - {putline, "2."}, - {getline_re, ".*2$"}, - {putline, "shell:prompt_func({io_proto_SUITE,uprompt})."}, - {getline_re, ".*default"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline_re, ".*\"hej\\\\n\""}, - {putline, "io:setopts([{binary,true}])."}, - {getline_re, ".*ok"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline_re, ".*<<\"hej\\\\n\">>"} - ],[],[],"-oldshell -pa \""++PA++"\""), + rtnode([{putline,""}, + {putline, "2."}, + {getline_re, ".*2$"}, + {putline, "shell:prompt_func({io_proto_SUITE,uprompt})."}, + {getline_re, ".*default"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline_re, ".*\"hej\\\\n\""}, + {putline, "io:setopts([{binary,true}])."}, + {getline_re, ".*ok"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline_re, ".*<<\"hej\\\\n\">>"} + ],[],[],"-oldshell -pa \""++PA++"\""), ok. - -setopts_getopts(suite) -> - []; -setopts_getopts(doc) -> - ["Check io:setopts and io:getopts functions"]; + +%% Check io:setopts and io:getopts functions. setopts_getopts(Config) when is_list(Config) -> - ?line FileName = filename:join([?config(priv_dir,Config), - "io_proto_SUITE_setopts_getopts.dat"]), - ?line {ok,WFile} = file:open(FileName,[write]), - ?line Server = start_io_server_proxy(), - ?line [{binary, false}] = io:getopts(Server), - ?line [getopts] = proxy_getall(Server), - ?line [{binary,false},{encoding,latin1}] = lists:sort(io:getopts(WFile)), - ?line proxy_setnext(Server,"Hej"), - ?line "Hej" = io:get_line(Server,''), - ?line proxy_setnext(Server,"Hej"++[532]), - ?line [$H,$e,$j,532] = io:get_line(Server,''), - ?line ok = io:setopts(Server,[{binary,true}]), - ?line proxy_setnext(Server,"Hej"), - ?line <<"Hej">> = io:get_line(Server,''), - ?line proxy_setnext(Server,"Hej"++[532]), - ?line <<72,101,106,200,148>> = io:get_line(Server,''), - ?line [$H,$e,$j,532] = lists:flatten(io_lib:format("~ts",[<<72,101,106,200,148>>])), - ?line file:write(WFile,<<"HejA">>), - ?line file:write(WFile,unicode:characters_to_binary("Hej"++[532],unicode,unicode)), - ?line file:write(WFile,unicode:characters_to_binary("Hej"++[532],unicode,{utf16,big})), - ?line file:write(WFile,unicode:characters_to_binary("Hej"++[532],unicode,{utf16,little})), - ?line file:write(WFile,unicode:characters_to_binary("Hej"++[532],unicode,{utf32,big})), - ?line file:write(WFile,unicode:characters_to_binary("Hej"++[532],unicode,{utf32,little})), - ?line file:close(WFile), - ?line {ok,RFile} = file:open(FileName,[read]), - ?line [{binary,false},{encoding,latin1}] = lists:sort(io:getopts(RFile)), - ?line [$H,$e,$j,$A] = io:get_chars(RFile,'',4), - ?line io:setopts(RFile,[{encoding,unicode}]), - ?line [$H,$e,$j,532] = io:get_chars(RFile,'',4), - ?line [{binary,false},{encoding,unicode}] = lists:sort(io:getopts(RFile)), - ?line io:setopts(RFile,[{encoding,{utf16,big}}]), - ?line [$H,$e,$j,532] = io:get_chars(RFile,'',4), - ?line [{binary,false},{encoding,{utf16,big}}] = + FileName = filename:join([proplists:get_value(priv_dir,Config), + "io_proto_SUITE_setopts_getopts.dat"]), + {ok,WFile} = file:open(FileName,[write]), + Server = start_io_server_proxy(), + [{binary, false}] = io:getopts(Server), + [getopts] = proxy_getall(Server), + [{binary,false},{encoding,latin1}] = lists:sort(io:getopts(WFile)), + proxy_setnext(Server,"Hej"), + "Hej" = io:get_line(Server,''), + proxy_setnext(Server,"Hej"++[532]), + [$H,$e,$j,532] = io:get_line(Server,''), + ok = io:setopts(Server,[{binary,true}]), + proxy_setnext(Server,"Hej"), + <<"Hej">> = io:get_line(Server,''), + proxy_setnext(Server,"Hej"++[532]), + <<72,101,106,200,148>> = io:get_line(Server,''), + [$H,$e,$j,532] = lists:flatten(io_lib:format("~ts",[<<72,101,106,200,148>>])), + file:write(WFile,<<"HejA">>), + file:write(WFile,unicode:characters_to_binary("Hej"++[532],unicode,unicode)), + file:write(WFile,unicode:characters_to_binary("Hej"++[532],unicode,{utf16,big})), + file:write(WFile,unicode:characters_to_binary("Hej"++[532],unicode,{utf16,little})), + file:write(WFile,unicode:characters_to_binary("Hej"++[532],unicode,{utf32,big})), + file:write(WFile,unicode:characters_to_binary("Hej"++[532],unicode,{utf32,little})), + file:close(WFile), + {ok,RFile} = file:open(FileName,[read]), + [{binary,false},{encoding,latin1}] = lists:sort(io:getopts(RFile)), + [$H,$e,$j,$A] = io:get_chars(RFile,'',4), + io:setopts(RFile,[{encoding,unicode}]), + [$H,$e,$j,532] = io:get_chars(RFile,'',4), + [{binary,false},{encoding,unicode}] = lists:sort(io:getopts(RFile)), + io:setopts(RFile,[{encoding,{utf16,big}}]), + [$H,$e,$j,532] = io:get_chars(RFile,'',4), + [{binary,false},{encoding,{utf16,big}}] = lists:sort(io:getopts(RFile)), - ?line io:setopts(RFile,[{encoding,{utf16,little}}]), - ?line [$H,$e,$j,532] = io:get_chars(RFile,'',4), - ?line [{binary,false},{encoding,{utf16,little}}] = + io:setopts(RFile,[{encoding,{utf16,little}}]), + [$H,$e,$j,532] = io:get_chars(RFile,'',4), + [{binary,false},{encoding,{utf16,little}}] = lists:sort(io:getopts(RFile)), - ?line io:setopts(RFile,[{encoding,{utf32,big}}]), - ?line [$H,$e,$j,532] = io:get_chars(RFile,'',4), - ?line [{binary,false},{encoding,{utf32,big}}] = + io:setopts(RFile,[{encoding,{utf32,big}}]), + [$H,$e,$j,532] = io:get_chars(RFile,'',4), + [{binary,false},{encoding,{utf32,big}}] = lists:sort(io:getopts(RFile)), - ?line io:setopts(RFile,[{encoding,{utf32,little}}]), - ?line [$H,$e,$j,532] = io:get_chars(RFile,'',4), - ?line [{binary,false},{encoding,{utf32,little}}] = + io:setopts(RFile,[{encoding,{utf32,little}}]), + [$H,$e,$j,532] = io:get_chars(RFile,'',4), + [{binary,false},{encoding,{utf32,little}}] = lists:sort(io:getopts(RFile)), - ?line eof = io:get_line(RFile,''), - ?line file:position(RFile,0), - ?line io:setopts(RFile,[{binary,true},{encoding,latin1}]), - ?line <<$H,$e,$j,$A>> = io:get_chars(RFile,'',4), - ?line [{binary,true},{encoding,latin1}] = lists:sort(io:getopts(RFile)), - ?line io:setopts(RFile,[{encoding,unicode}]), - ?line <<$H,$e,$j,532/utf8>> = io:get_chars(RFile,'',4), - ?line [{binary,true},{encoding,unicode}] = lists:sort(io:getopts(RFile)), - ?line io:setopts(RFile,[{encoding,{utf16,big}}]), - ?line <<$H,$e,$j,532/utf8>> = io:get_chars(RFile,'',4), - ?line [{binary,true},{encoding,{utf16,big}}] = + eof = io:get_line(RFile,''), + file:position(RFile,0), + io:setopts(RFile,[{binary,true},{encoding,latin1}]), + <<$H,$e,$j,$A>> = io:get_chars(RFile,'',4), + [{binary,true},{encoding,latin1}] = lists:sort(io:getopts(RFile)), + io:setopts(RFile,[{encoding,unicode}]), + <<$H,$e,$j,532/utf8>> = io:get_chars(RFile,'',4), + [{binary,true},{encoding,unicode}] = lists:sort(io:getopts(RFile)), + io:setopts(RFile,[{encoding,{utf16,big}}]), + <<$H,$e,$j,532/utf8>> = io:get_chars(RFile,'',4), + [{binary,true},{encoding,{utf16,big}}] = lists:sort(io:getopts(RFile)), - ?line io:setopts(RFile,[{encoding,{utf16,little}}]), - ?line <<$H,$e,$j,532/utf8>> = io:get_chars(RFile,'',4), - ?line [{binary,true},{encoding,{utf16,little}}] = + io:setopts(RFile,[{encoding,{utf16,little}}]), + <<$H,$e,$j,532/utf8>> = io:get_chars(RFile,'',4), + [{binary,true},{encoding,{utf16,little}}] = lists:sort(io:getopts(RFile)), - ?line io:setopts(RFile,[{encoding,{utf32,big}}]), - ?line <<$H,$e,$j,532/utf8>> = io:get_chars(RFile,'',4), - ?line [{binary,true},{encoding,{utf32,big}}] = + io:setopts(RFile,[{encoding,{utf32,big}}]), + <<$H,$e,$j,532/utf8>> = io:get_chars(RFile,'',4), + [{binary,true},{encoding,{utf32,big}}] = lists:sort(io:getopts(RFile)), - ?line io:setopts(RFile,[{encoding,{utf32,little}}]), - ?line <<$H,$e,$j,532/utf8>> = io:get_chars(RFile,'',4), - ?line [{binary,true},{encoding,{utf32,little}}] = + io:setopts(RFile,[{encoding,{utf32,little}}]), + <<$H,$e,$j,532/utf8>> = io:get_chars(RFile,'',4), + [{binary,true},{encoding,{utf32,little}}] = lists:sort(io:getopts(RFile)), - ?line eof = io:get_line(RFile,''), - ?line file:close(RFile), + eof = io:get_line(RFile,''), + file:close(RFile), case proplists:get_value(default_shell,Config) of old -> ok; new -> %% So, lets test another node with new interactive shell - ?line rtnode([{putline,""}, - {putline, "2."}, - {getline, "2"}, - {putline, "lists:keyfind(binary,1,io:getopts())."}, - {getline, "{binary,false}"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline, "\"hej\\n\""}, - {putline, "io:setopts([{binary,true}])."}, - {getline, "ok"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline, "<<\"hej\\n\">>"} - ],[]) + rtnode([{putline,""}, + {putline, "2."}, + {getline, "2"}, + {putline, "lists:keyfind(binary,1,io:getopts())."}, + {getline, "{binary,false}"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline, "\"hej\\n\""}, + {putline, "io:setopts([{binary,true}])."}, + {getline, "ok"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline, "<<\"hej\\n\">>"} + ],[]) end, %% And one with oldshell - ?line rtnode([{putline,""}, - {putline, "2."}, - {getline_re, ".*2$"}, - {putline, "lists:keyfind(binary,1,io:getopts())."}, - {getline_re, ".*{binary,false}"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline_re, ".*\"hej\\\\n\""}, - {putline, "io:setopts([{binary,true}])."}, - {getline_re, ".*ok"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline_re, ".*<<\"hej\\\\n\">>"} - ],[],[],"-oldshell"), + rtnode([{putline,""}, + {putline, "2."}, + {getline_re, ".*2$"}, + {putline, "lists:keyfind(binary,1,io:getopts())."}, + {getline_re, ".*{binary,false}"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline_re, ".*\"hej\\\\n\""}, + {putline, "io:setopts([{binary,true}])."}, + {getline_re, ".*ok"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline_re, ".*<<\"hej\\\\n\">>"} + ],[],[],"-oldshell"), ok. get_lc_ctype() -> - case {os:type(),os:version()} of - {{unix,sunos},{5,N,_}} when N =< 8 -> - "iso_8859_1"; - _ -> - "ISO-8859-1" - end. - -unicode_options(suite) -> - []; -unicode_options(doc) -> - ["Tests various unicode options"]; + case {os:type(),os:version()} of + {{unix,sunos},{5,N,_}} when N =< 8 -> + "iso_8859_1"; + _ -> + "ISO-8859-1" + end. + +%% Test various unicode options. unicode_options(Config) when is_list(Config) -> - DataDir = ?config(data_dir,Config), - PrivDir = ?config(priv_dir,Config), + DataDir = proplists:get_value(data_dir,Config), + PrivDir = proplists:get_value(priv_dir,Config), %% A string in both russian and greek characters, which is present %% in all the internal test files (but in different formats of course)... TestData = [1090,1093,1077,32,1073,1080,1075,32, @@ -322,13 +308,10 @@ unicode_options(Config) when is_list(Config) -> "external_utf16_little_bom.dat", "external_utf16_big_bom.dat"], ReadBomFile = fun(File,Dir) -> - %io:format(standard_error,"~s\r\n",[filename:join([Dir,File])]), {ok,F} = file:open(filename:join([Dir,File]), [read,binary]), {ok,Bin} = file:read(F,4), {Type,Bytes} = unicode:bom_to_encoding(Bin), - %io:format(standard_error,"~p\r\n",[{Type,Bytes}]), - file:position(F,Bytes), io:setopts(F,[{encoding,Type}]), R = unicode:characters_to_list( @@ -346,26 +329,26 @@ unicode_options(Config) when is_list(Config) -> R end, ReadBomlessFileList = fun({Type,File},DataLen,Dir) -> - {ok,F} = file:open(filename:join([Dir,File]), - [read, - {encoding,Type}]), - R = io:get_chars(F,'',DataLen), - file:close(F), - R - end, + {ok,F} = file:open(filename:join([Dir,File]), + [read, + {encoding,Type}]), + R = io:get_chars(F,'',DataLen), + file:close(F), + R + end, ReadBomlessFileListLine = fun({Type,File},Dir) -> - {ok,F} = file:open(filename:join([Dir,File]), - [read, - {encoding,Type}]), - R = io:get_line(F,''), - file:close(F), - R - end, - ?line [TestData = ReadBomFile(F,DataDir) || F <- InternalBomFiles ], - ?line [ExternalTestData = ReadBomFile(F,DataDir) || F <- ExternalBomFiles ], - ?line [TestData = ReadBomlessFile(F,length(TestData),DataDir) || F <- AllNoBom ], - ?line [TestData = ReadBomlessFileList(F,length(TestData),DataDir) || F <- AllNoBom ], - ?line [TestData = ReadBomlessFileListLine(F,DataDir) || F <- AllNoBom ], + {ok,F} = file:open(filename:join([Dir,File]), + [read, + {encoding,Type}]), + R = io:get_line(F,''), + file:close(F), + R + end, + [TestData = ReadBomFile(F,DataDir) || F <- InternalBomFiles ], + [ExternalTestData = ReadBomFile(F,DataDir) || F <- ExternalBomFiles ], + [TestData = ReadBomlessFile(F,length(TestData),DataDir) || F <- AllNoBom ], + [TestData = ReadBomlessFileList(F,length(TestData),DataDir) || F <- AllNoBom ], + [TestData = ReadBomlessFileListLine(F,DataDir) || F <- AllNoBom ], BomDir = filename:join([PrivDir,"BOMDATA"]), BomlessDir = filename:join([PrivDir,"BOMLESSDATA"]), @@ -381,8 +364,8 @@ unicode_options(Config) when is_list(Config) -> file:close(F), ok end, - ?line [ ok = WriteBomFile(F,BomDir) || F <- AllNoBom ], - ?line [TestData = ReadBomFile(F,BomDir) || {_,F} <- AllNoBom ], + [ ok = WriteBomFile(F,BomDir) || F <- AllNoBom ], + [TestData = ReadBomFile(F,BomDir) || {_,F} <- AllNoBom ], WriteBomlessFile = fun({Enc,File},TData,Dir) -> {ok,F} = file:open( filename:join([Dir,File]), @@ -391,13 +374,13 @@ unicode_options(Config) when is_list(Config) -> file:close(F), ok end, - ?line [ ok = WriteBomlessFile(F,TestData,BomlessDir) || F <- AllNoBom ], - ?line [TestData = ReadBomlessFile(F,length(TestData),BomlessDir) || F <- AllNoBom ], - ?line [TestData = ReadBomlessFileList(F,length(TestData),BomlessDir) || F <- AllNoBom ], - ?line [TestData = ReadBomlessFileListLine(F,BomlessDir) || F <- AllNoBom ], - + [ ok = WriteBomlessFile(F,TestData,BomlessDir) || F <- AllNoBom ], + [TestData = ReadBomlessFile(F,length(TestData),BomlessDir) || F <- AllNoBom ], + [TestData = ReadBomlessFileList(F,length(TestData),BomlessDir) || F <- AllNoBom ], + [TestData = ReadBomlessFileListLine(F,BomlessDir) || F <- AllNoBom ], + CannotReadFile = fun({Enc,File},Dir) -> - %io:format(standard_error,"~s\r\n",[filename:join([Dir,File])]), + %%io:format(standard_error,"~s\r\n",[filename:join([Dir,File])]), {ok,F} = file:open( filename:join([Dir,File]), [read,binary,{encoding,Enc}]), @@ -414,14 +397,14 @@ unicode_options(Config) when is_list(Config) -> {error,terminated} = io:get_chars(F,'',10), ok end, - ?line [ ok = CannotReadFile(F,DataDir) || F <- AllNoBom ], - ?line [ ok = CannotReadFile(F,BomlessDir) || F <- AllNoBom ], - ?line [ ok = CannotReadFile(F,BomDir) || F <- AllNoBom ], + [ ok = CannotReadFile(F,DataDir) || F <- AllNoBom ], + [ ok = CannotReadFile(F,BomlessDir) || F <- AllNoBom ], + [ ok = CannotReadFile(F,BomDir) || F <- AllNoBom ], - ?line [ ok = WriteBomlessFile(F,TestData2,BomlessDir) || F <- AllNoBom ], - ?line [TestData2 = ReadBomlessFile(F,length(TestData2),BomlessDir) || F <- AllNoBom ], - ?line [TestData2 = ReadBomlessFileList(F,length(TestData2),BomlessDir) || F <- AllNoBom ], - ?line [TestData2 = ReadBomlessFileListLine(F,BomlessDir) || F <- AllNoBom ], + [ ok = WriteBomlessFile(F,TestData2,BomlessDir) || F <- AllNoBom ], + [TestData2 = ReadBomlessFile(F,length(TestData2),BomlessDir) || F <- AllNoBom ], + [TestData2 = ReadBomlessFileList(F,length(TestData2),BomlessDir) || F <- AllNoBom ], + [TestData2 = ReadBomlessFileListLine(F,BomlessDir) || F <- AllNoBom ], FailDir = filename:join([PrivDir,"FAIL"]), @@ -431,56 +414,56 @@ unicode_options(Config) when is_list(Config) -> {ok,F} = file:open( filename:join([Dir,File]), [write,binary]), - ?line {'EXIT', {no_translation,_}} = + {'EXIT', {no_translation,_}} = (catch io:put_chars(F,TestData)), - ?line {'EXIT', {terminated,_}} = (catch io:put_chars(F,TestData)), + {'EXIT', {terminated,_}} = (catch io:put_chars(F,TestData)), ok end, - ?line [ ok = CannotWriteFile(F,FailDir) || F <- AllNoBom ], + [ ok = CannotWriteFile(F,FailDir) || F <- AllNoBom ], case proplists:get_value(default_shell,Config) of old -> ok; new -> %% OK, time for the group_leaders... - ?line rtnode([{putline,""}, - {putline, "2."}, - {getline, "2"}, - {putline, "lists:keyfind(encoding,1,io:getopts())."}, - {getline, "{encoding,latin1}"}, - {putline, "io:format(\"~ts~n\",[[1024]])."}, - {getline, "\\x{400}"}, - {putline, "io:setopts([unicode])."}, - {getline, "ok"}, - {putline, "io:format(\"~ts~n\",[[1024]])."}, - {getline, - binary_to_list(unicode:characters_to_binary( - [1024],unicode,utf8))} - ],[],"LC_CTYPE=\""++get_lc_ctype()++"\"; " - "export LC_CTYPE; ") + rtnode([{putline,""}, + {putline, "2."}, + {getline, "2"}, + {putline, "lists:keyfind(encoding,1,io:getopts())."}, + {getline, "{encoding,latin1}"}, + {putline, "io:format(\"~ts~n\",[[1024]])."}, + {getline, "\\x{400}"}, + {putline, "io:setopts([unicode])."}, + {getline, "ok"}, + {putline, "io:format(\"~ts~n\",[[1024]])."}, + {getline, + binary_to_list(unicode:characters_to_binary( + [1024],unicode,utf8))} + ],[],"LC_CTYPE=\""++get_lc_ctype()++"\"; " + "export LC_CTYPE; ") end, - ?line rtnode([{putline,""}, - {putline, "2."}, - {getline_re, ".*2$"}, - {putline, "lists:keyfind(encoding,1,io:getopts())."}, - {getline_re, ".*{encoding,latin1}"}, - {putline, "io:format(\"~ts~n\",[[1024]])."}, - {getline_re, ".*\\\\x{400\\}"}, - {putline, "io:setopts([{encoding,unicode}])."}, - {getline_re, ".*ok"}, - {putline, "io:format(\"~ts~n\",[[1024]])."}, - {getline_re, - ".*"++binary_to_list(unicode:characters_to_binary( - [1024],unicode,utf8))} - ],[],"LC_CTYPE=\""++get_lc_ctype()++"\"; export LC_CTYPE; ", - " -oldshell "), + rtnode([{putline,""}, + {putline, "2."}, + {getline_re, ".*2$"}, + {putline, "lists:keyfind(encoding,1,io:getopts())."}, + {getline_re, ".*{encoding,latin1}"}, + {putline, "io:format(\"~ts~n\",[[1024]])."}, + {getline_re, ".*\\\\x{400\\}"}, + {putline, "io:setopts([{encoding,unicode}])."}, + {getline_re, ".*ok"}, + {putline, "io:format(\"~ts~n\",[[1024]])."}, + {getline_re, + ".*"++binary_to_list(unicode:characters_to_binary( + [1024],unicode,utf8))} + ],[],"LC_CTYPE=\""++get_lc_ctype()++"\"; export LC_CTYPE; ", + " -oldshell "), ok. - + %% Tests various unicode options on random generated files. unicode_options_gen(Config) when is_list(Config) -> random:seed(1240, 900586, 553728), - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), AllModes = [utf8,utf16,{utf16,big},{utf16,little}, utf32,{utf32,big},{utf32,little}], FSize = 9*1024, @@ -621,7 +604,7 @@ do_read_whole_file(Fname, Options, Fun) -> Res = do_read_whole_file_1(Fun, F), ok = file:close(F), unicode:characters_to_list(Res, unicode). - + do_read_whole_file_1(Fun, F) -> case Fun(F) of eof -> @@ -646,7 +629,7 @@ do_write_read_file(Fname, Options, Encoding, Writer) -> {ok,Bin} = file:read_file(Fname), ok = file:delete(Fname), Bin. - + enc2str(Atom) when is_atom(Atom) -> atom_to_list(Atom); enc2str({A1,A2}) when is_atom(A1), is_atom(A2) -> @@ -656,14 +639,14 @@ enc2str({A1,A2}) when is_atom(A1), is_atom(A2) -> random_unicode(0) -> []; random_unicode(N) -> - % Favour large unicode and make linebreaks + %% Favour large unicode and make linebreaks X = case random:uniform(20) of - A when A =< 1 -> $\n; - A0 when A0 =< 3 -> random:uniform(16#10FFFF); - A1 when A1 =< 6 -> random:uniform(16#10FFFF - 16#7F) + 16#7F; - A2 when A2 =< 12 -> random:uniform(16#10FFFF - 16#7FF) + 16#7FF; - _ -> random:uniform(16#10FFFF - 16#FFFF) + 16#FFFF - end, + A when A =< 1 -> $\n; + A0 when A0 =< 3 -> random:uniform(16#10FFFF); + A1 when A1 =< 6 -> random:uniform(16#10FFFF - 16#7F) + 16#7F; + A2 when A2 =< 12 -> random:uniform(16#10FFFF - 16#7FF) + 16#7FF; + _ -> random:uniform(16#10FFFF - 16#FFFF) + 16#FFFF + end, case X of Inv1 when Inv1 >= 16#D800, Inv1 =< 16#DFFF; Inv1 =:= 16#FFFE; @@ -672,15 +655,12 @@ random_unicode(N) -> _ -> [X | random_unicode(N-1)] end. - -binary_options(suite) -> - []; -binary_options(doc) -> - ["Tests variants with binary option"]; + +%% Test variants with binary option. binary_options(Config) when is_list(Config) -> - DataDir = ?config(data_dir,Config), - PrivDir = ?config(priv_dir,Config), + DataDir = proplists:get_value(data_dir,Config), + PrivDir = proplists:get_value(priv_dir,Config), TestData = unicode:characters_to_binary( [1090,1093,1077,32,1073,1080,1075,32, 1088,1077,1076,32,1092,1086,1100,32,1093, @@ -691,84 +671,79 @@ binary_options(Config) when is_list(Config) -> First10List = binary_to_list(First10), Second10List = binary_to_list(Second10), TestFile = filename:join([DataDir, "testdata_utf8.dat"]), - ?line {ok, F} = file:open(TestFile,[read]), - ?line {ok, First10List} = file:read(F,10), - ?line io:setopts(F,[binary]), - ?line {ok, Second10} = file:read(F,10), - ?line file:close(F), - ?line {ok, F2} = file:open(TestFile,[read,binary]), - ?line {ok, First10} = file:read(F2,10), - ?line io:setopts(F2,[list]), - ?line {ok, Second10List} = file:read(F2,10), - ?line file:position(F2,0), - %dbg:tracer(),dbg:p(F2,call),dbg:tpl(file_io_server,x), - ?line First10List = io:get_chars(F2,'',10), - ?line io:setopts(F2,[binary]), - ?line Second10 = unicode:characters_to_binary(io:get_chars(F2,'',10),unicode,latin1), - ?line file:close(F2), - ?line LineBreakFileName = filename:join([PrivDir, "testdata.dat"]), - ?line LineBreakTestData = <<TestData/binary,$\n>>, - ?line LineBreakTestDataList = binary_to_list(LineBreakTestData), - ?line file:write_file(LineBreakFileName,[LineBreakTestData,LineBreakTestData,LineBreakTestData,TestData]), - ?line {ok, F3} = file:open(LineBreakFileName,[read]), - ?line LineBreakTestDataList = io:get_line(F3,''), - ?line io:setopts(F3,[binary]), - ?line LineBreakTestData = unicode:characters_to_binary(io:get_line(F3,''),unicode,latin1), - ?line io:setopts(F3,[list]), - ?line LineBreakTestDataList = io:get_line(F3,''), - ?line io:setopts(F3,[binary]), - %ok = io:format(standard_error,"TestData = ~w~n",[TestData]), - ?line TestData = unicode:characters_to_binary(io:get_line(F3,''),unicode,latin1), - ?line eof = io:get_line(F3,''), - ?line file:close(F3), + {ok, F} = file:open(TestFile,[read]), + {ok, First10List} = file:read(F,10), + io:setopts(F,[binary]), + {ok, Second10} = file:read(F,10), + file:close(F), + {ok, F2} = file:open(TestFile,[read,binary]), + {ok, First10} = file:read(F2,10), + io:setopts(F2,[list]), + {ok, Second10List} = file:read(F2,10), + file:position(F2,0), + First10List = io:get_chars(F2,'',10), + io:setopts(F2,[binary]), + Second10 = unicode:characters_to_binary(io:get_chars(F2,'',10),unicode,latin1), + file:close(F2), + LineBreakFileName = filename:join([PrivDir, "testdata.dat"]), + LineBreakTestData = <<TestData/binary,$\n>>, + LineBreakTestDataList = binary_to_list(LineBreakTestData), + file:write_file(LineBreakFileName,[LineBreakTestData,LineBreakTestData,LineBreakTestData,TestData]), + {ok, F3} = file:open(LineBreakFileName,[read]), + LineBreakTestDataList = io:get_line(F3,''), + io:setopts(F3,[binary]), + LineBreakTestData = unicode:characters_to_binary(io:get_line(F3,''),unicode,latin1), + io:setopts(F3,[list]), + LineBreakTestDataList = io:get_line(F3,''), + io:setopts(F3,[binary]), + TestData = unicode:characters_to_binary(io:get_line(F3,''),unicode,latin1), + eof = io:get_line(F3,''), + file:close(F3), + %% OK, time for the group_leaders... - %% io:format(standard_error,"Hmmm:~w~n",["<<\""++binary_to_list(<<"\345\344\366"/utf8>>)++"\\n\">>"]), case proplists:get_value(default_shell,Config) of old -> ok; new -> - ?line rtnode([{putline, "2."}, - {getline, "2"}, - {putline, "lists:keyfind(binary,1,io:getopts())."}, - {getline, "{binary,false}"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline, "\"hej\\n\""}, - {putline, "io:setopts([{binary,true},unicode])."}, - {getline, "ok"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline, "<<\"hej\\n\">>"}, - {putline, "io:get_line('')."}, - {putline, binary_to_list(<<"\345\344\366"/utf8>>)}, - {getline, "<<\""++binary_to_list(<<"\345\344\366"/utf8>>)++"\\n\"/utf8>>"} - ],[]) + rtnode([{putline, "2."}, + {getline, "2"}, + {putline, "lists:keyfind(binary,1,io:getopts())."}, + {getline, "{binary,false}"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline, "\"hej\\n\""}, + {putline, "io:setopts([{binary,true},unicode])."}, + {getline, "ok"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline, "<<\"hej\\n\">>"}, + {putline, "io:get_line('')."}, + {putline, binary_to_list(<<"\345\344\366"/utf8>>)}, + {getline, "<<\""++binary_to_list(<<"\345\344\366"/utf8>>)++"\\n\"/utf8>>"} + ],[]) end, - %% And one with oldshell - ?line rtnode([{putline, "2."}, - {getline_re, ".*2$"}, - {putline, "lists:keyfind(binary,1,io:getopts())."}, - {getline_re, ".*{binary,false}"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline_re, ".*\"hej\\\\n\""}, - {putline, "io:setopts([{binary,true},unicode])."}, - {getline_re, ".*ok"}, - {putline, "io:get_line('')."}, - {putline, "hej"}, - {getline_re, ".*<<\"hej\\\\n\">>"}, - {putline, "io:get_line('')."}, - {putline, binary_to_list(<<"\345\344\366"/utf8>>)}, - {getline_re, ".*<<\""++binary_to_list(<<"\345\344\366"/utf8>>)++"\\\\n\"/utf8>>"} - ],[],[],"-oldshell"), + %% And one with oldshell + rtnode([{putline, "2."}, + {getline_re, ".*2$"}, + {putline, "lists:keyfind(binary,1,io:getopts())."}, + {getline_re, ".*{binary,false}"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline_re, ".*\"hej\\\\n\""}, + {putline, "io:setopts([{binary,true},unicode])."}, + {getline_re, ".*ok"}, + {putline, "io:get_line('')."}, + {putline, "hej"}, + {getline_re, ".*<<\"hej\\\\n\">>"}, + {putline, "io:get_line('')."}, + {putline, binary_to_list(<<"\345\344\366"/utf8>>)}, + {getline_re, ".*<<\""++binary_to_list(<<"\345\344\366"/utf8>>)++"\\\\n\"/utf8>>"} + ],[],[],"-oldshell"), ok. -bc_with_r12(suite) -> - []; -bc_with_r12(doc) -> - ["Test io protocol compatibility with R12 nodes"]; +%% Test io protocol compatibility with R12 nodes. bc_with_r12(Config) when is_list(Config) -> - case ?t:is_release_available("r12b") of + case test_server:is_release_available("r12b") of true -> bc_with_r12_1(Config); false -> {skip,"No R12B found"} end. @@ -776,135 +751,134 @@ bc_with_r12(Config) when is_list(Config) -> bc_with_r12_1(Config) -> PA = filename:dirname(code:which(?MODULE)), Name1 = io_proto_r12_1, - ?line N1 = list_to_atom(atom_to_list(Name1) ++ "@" ++ hostname()), - ?line ?t:start_node(Name1, peer, [{args, "-pz \""++PA++"\""},{erl,[{release,"r12b"}]}]), - DataDir = ?config(data_dir,Config), - %PrivDir = ?config(priv_dir,Config), + N1 = list_to_atom(atom_to_list(Name1) ++ "@" ++ hostname()), + test_server:start_node(Name1, peer, [{args, "-pz \""++PA++"\""}, + {erl,[{release,"r12b"}]}]), + DataDir = proplists:get_value(data_dir,Config), FileName1 = filename:join([DataDir,"testdata_latin1.dat"]), TestDataLine1 = [229,228,246], TestDataLine2 = [197,196,214], - ?line SPid1 = rpc:call(N1,erlang,spawn,[?MODULE,hold_the_line,[self(),FileName1,[read]]]), - ?line {ok,F1} = receive - {SPid1,Res1} -> - Res1 - after 5000 -> - exit(timeout) - end, - ?line TestDataLine1 = chomp(io:get_line(F1,'')), - ?line SPid1 ! die, + SPid1 = rpc:call(N1,erlang,spawn,[?MODULE,hold_the_line,[self(),FileName1,[read]]]), + {ok,F1} = receive + {SPid1,Res1} -> + Res1 + after 5000 -> + exit(timeout) + end, + TestDataLine1 = chomp(io:get_line(F1,'')), + SPid1 ! die, receive after 1000 -> ok end, - ?line SPid2 = rpc:call(N1,erlang,spawn,[?MODULE,hold_the_line,[self(),FileName1,[read,binary]]]), - ?line {ok,F2} = receive - {SPid2,Res2} -> - Res2 - after 5000 -> - exit(timeout) - end, + SPid2 = rpc:call(N1,erlang,spawn,[?MODULE,hold_the_line,[self(),FileName1,[read,binary]]]), + {ok,F2} = receive + {SPid2,Res2} -> + Res2 + after 5000 -> + exit(timeout) + end, TestDataLine1BinUtf = unicode:characters_to_binary(TestDataLine1), TestDataLine1BinLatin = list_to_binary(TestDataLine1), TestDataLine2BinUtf = unicode:characters_to_binary(TestDataLine2), TestDataLine2BinLatin = list_to_binary(TestDataLine2), - ?line TestDataLine1BinUtf = chomp(io:get_line(F2,'')), - ?line TestDataLine2BinUtf = chomp(io:get_line(F2,'')), - %io:format(standard_error,"Exec:~s\r\n",[rpc:call(N1,os,find_executable,["erl"])]), - %io:format(standard_error,"Io:~s\r\n",[rpc:call(N1,code,which,[io])]), - %io:format(standard_error,"File_io_server:~s\r\n",[rpc:call(N1,code,which,[file_io_server])]), - ?line file:position(F2,0), - ?line TestDataLine1BinLatin = chomp(rpc:call(N1,io,get_line,[F2,''])), - ?line TestDataLine2BinUtf = chomp(io:get_line(F2,'')), - ?line file:position(F2,0), - ?line TestDataLine1BinUtf = chomp(io:get_line(F2,'')), - ?line TestDataLine2BinLatin = chomp(rpc:call(N1,io,get_line,[F2,''])), - ?line eof = chomp(rpc:call(N1,io,get_line,[F2,''])), - ?line file:position(F2,0), - ?line TestDataLine1BinLatin = rpc:call(N1,io,get_chars,[F2,'',3]), + TestDataLine1BinUtf = chomp(io:get_line(F2,'')), + TestDataLine2BinUtf = chomp(io:get_line(F2,'')), + %%io:format(standard_error,"Exec:~s\r\n",[rpc:call(N1,os,find_executable,["erl"])]), + %%io:format(standard_error,"Io:~s\r\n",[rpc:call(N1,code,which,[io])]), + %%io:format(standard_error,"File_io_server:~s\r\n",[rpc:call(N1,code,which,[file_io_server])]), + file:position(F2,0), + TestDataLine1BinLatin = chomp(rpc:call(N1,io,get_line,[F2,''])), + TestDataLine2BinUtf = chomp(io:get_line(F2,'')), + file:position(F2,0), + TestDataLine1BinUtf = chomp(io:get_line(F2,'')), + TestDataLine2BinLatin = chomp(rpc:call(N1,io,get_line,[F2,''])), + eof = chomp(rpc:call(N1,io,get_line,[F2,''])), + file:position(F2,0), + TestDataLine1BinLatin = rpc:call(N1,io,get_chars,[F2,'',3]), io:get_chars(F2,'',1), - ?line TestDataLine2BinLatin = chomp(rpc:call(N1,io,get_line,[F2,''])), - ?line file:position(F2,0), - ?line {ok,[TestDataLine1]} = io:fread(F2,'',"~s"), - ?line {ok,[TestDataLine2]} = rpc:call(N1,io,fread,[F2,'',"~s"]), - - ?line DataLen1 = length(TestDataLine1), - ?line DataLen2 = length(TestDataLine2), - - ?line file:position(F2,0), - ?line {ok,TestDataLine1BinLatin} = file:read(F2,DataLen1), - ?line {ok,_} = file:read(F2,1), - ?line {ok,TestDataLine2BinLatin} = rpc:call(N1,file,read,[F2,DataLen2]), - ?line {ok,_} = file:read(F2,1), - ?line eof = rpc:call(N1,file,read,[F2,1]), + TestDataLine2BinLatin = chomp(rpc:call(N1,io,get_line,[F2,''])), + file:position(F2,0), + {ok,[TestDataLine1]} = io:fread(F2,'',"~s"), + {ok,[TestDataLine2]} = rpc:call(N1,io,fread,[F2,'',"~s"]), + + DataLen1 = length(TestDataLine1), + DataLen2 = length(TestDataLine2), + + file:position(F2,0), + {ok,TestDataLine1BinLatin} = file:read(F2,DataLen1), + {ok,_} = file:read(F2,1), + {ok,TestDataLine2BinLatin} = rpc:call(N1,file,read,[F2,DataLen2]), + {ok,_} = file:read(F2,1), + eof = rpc:call(N1,file,read,[F2,1]), %% As r12 has a bug when setting options with setopts, we need %% to reopen the file... - ?line SPid2 ! die, + SPid2 ! die, receive after 1000 -> ok end, - ?line SPid3 = rpc:call(N1,erlang,spawn,[?MODULE,hold_the_line,[self(),FileName1,[read]]]), - ?line {ok,F3} = receive - {SPid3,Res3} -> - Res3 - after 5000 -> - exit(timeout) - end, - - ?line file:position(F3,0), - ?line {ok,[TestDataLine1]} = io:fread(F3,'',"~s"), - ?line {ok,[TestDataLine2]} = rpc:call(N1,io,fread,[F3,'',"~s"]), - - - ?line file:position(F3,0), - ?line {ok,TestDataLine1} = file:read(F3,DataLen1), - ?line {ok,_} = file:read(F3,1), - ?line {ok,TestDataLine2} = rpc:call(N1,file,read,[F3,DataLen2]), - ?line {ok,_} = file:read(F3,1), - ?line eof = rpc:call(N1,file,read,[F3,1]), - + SPid3 = rpc:call(N1,erlang,spawn,[?MODULE,hold_the_line,[self(),FileName1,[read]]]), + {ok,F3} = receive + {SPid3,Res3} -> + Res3 + after 5000 -> + exit(timeout) + end, + + file:position(F3,0), + {ok,[TestDataLine1]} = io:fread(F3,'',"~s"), + {ok,[TestDataLine2]} = rpc:call(N1,io,fread,[F3,'',"~s"]), + + + file:position(F3,0), + {ok,TestDataLine1} = file:read(F3,DataLen1), + {ok,_} = file:read(F3,1), + {ok,TestDataLine2} = rpc:call(N1,file,read,[F3,DataLen2]), + {ok,_} = file:read(F3,1), + eof = rpc:call(N1,file,read,[F3,1]), + %% So, lets do it all again, but the other way around {ok,F4} = file:open(FileName1,[read]), - ?line TestDataLine1 = chomp(io:get_line(F4,'')), - ?line file:position(F4,0), - ?line io:setopts(F4,[binary]), - ?line TestDataLine1BinUtf = chomp(io:get_line(F4,'')), - ?line TestDataLine2BinUtf = chomp(io:get_line(F4,'')), - ?line file:position(F4,0), - ?line TestDataLine1BinUtf = chomp(io:get_line(F4,'')), - ?line TestDataLine2BinUtf = chomp(io:get_line(F4,'')), - ?line file:position(F4,0), - %dbg:tracer(),dbg:p(F4,[call,m]),dbg:tpl(file_io_server,x),dbg:tpl(io_lib,x), - ?line TestDataLine1BinUtf = chomp(io:get_line(F4,'')), - ?line TestDataLine2BinLatin = chomp(rpc:call(N1,io,get_line,[F4,''])), - ?line file:position(F4,0), - ?line TestDataLine1BinLatin = chomp(rpc:call(N1,io,get_line,[F4,''])), - ?line TestDataLine2BinUtf = chomp(io:get_line(F4,'')), - ?line eof = chomp(rpc:call(N1,io,get_line,[F4,''])), - ?line file:position(F4,0), - ?line TestDataLine1BinLatin = rpc:call(N1,io,get_chars,[F4,'',3]), + TestDataLine1 = chomp(io:get_line(F4,'')), + file:position(F4,0), + io:setopts(F4,[binary]), + TestDataLine1BinUtf = chomp(io:get_line(F4,'')), + TestDataLine2BinUtf = chomp(io:get_line(F4,'')), + file:position(F4,0), + TestDataLine1BinUtf = chomp(io:get_line(F4,'')), + TestDataLine2BinUtf = chomp(io:get_line(F4,'')), + file:position(F4,0), + TestDataLine1BinUtf = chomp(io:get_line(F4,'')), + TestDataLine2BinLatin = chomp(rpc:call(N1,io,get_line,[F4,''])), + file:position(F4,0), + TestDataLine1BinLatin = chomp(rpc:call(N1,io,get_line,[F4,''])), + TestDataLine2BinUtf = chomp(io:get_line(F4,'')), + eof = chomp(rpc:call(N1,io,get_line,[F4,''])), + file:position(F4,0), + TestDataLine1BinLatin = rpc:call(N1,io,get_chars,[F4,'',3]), io:get_chars(F4,'',1), - ?line TestDataLine2BinLatin = chomp(rpc:call(N1,io,get_line,[F4,''])), - ?line file:position(F4,0), - ?line {ok,[TestDataLine1]} = io:fread(F4,'',"~s"), - ?line {ok,[TestDataLine2]} = rpc:call(N1,io,fread,[F4,'',"~s"]), - ?line file:position(F4,0), - ?line {ok,TestDataLine1BinLatin} = file:read(F4,DataLen1), - ?line {ok,_} = file:read(F4,1), - ?line {ok,TestDataLine2BinLatin} = rpc:call(N1,file,read,[F4,DataLen2]), - ?line {ok,_} = file:read(F4,1), - ?line eof = rpc:call(N1,file,read,[F4,1]), - ?line io:setopts(F4,[list]), - - ?line file:position(F4,0), - ?line {ok,[TestDataLine1]} = io:fread(F4,'',"~s"), - ?line {ok,[TestDataLine2]} = rpc:call(N1,io,fread,[F4,'',"~s"]), - - - ?line file:position(F4,0), - ?line {ok,TestDataLine1} = file:read(F4,DataLen1), - ?line {ok,_} = file:read(F4,1), - ?line {ok,TestDataLine2} = rpc:call(N1,file,read,[F4,DataLen2]), - ?line {ok,_} = file:read(F4,1), - ?line eof = rpc:call(N1,file,read,[F4,1]), - + TestDataLine2BinLatin = chomp(rpc:call(N1,io,get_line,[F4,''])), + file:position(F4,0), + {ok,[TestDataLine1]} = io:fread(F4,'',"~s"), + {ok,[TestDataLine2]} = rpc:call(N1,io,fread,[F4,'',"~s"]), + file:position(F4,0), + {ok,TestDataLine1BinLatin} = file:read(F4,DataLen1), + {ok,_} = file:read(F4,1), + {ok,TestDataLine2BinLatin} = rpc:call(N1,file,read,[F4,DataLen2]), + {ok,_} = file:read(F4,1), + eof = rpc:call(N1,file,read,[F4,1]), + io:setopts(F4,[list]), + + file:position(F4,0), + {ok,[TestDataLine1]} = io:fread(F4,'',"~s"), + {ok,[TestDataLine2]} = rpc:call(N1,io,fread,[F4,'',"~s"]), + + + file:position(F4,0), + {ok,TestDataLine1} = file:read(F4,DataLen1), + {ok,_} = file:read(F4,1), + {ok,TestDataLine2} = rpc:call(N1,file,read,[F4,DataLen2]), + {ok,_} = file:read(F4,1), + eof = rpc:call(N1,file,read,[F4,1]), + file:close(F4), - ?t:stop_node(N1), + test_server:stop_node(N1), ok. hold_the_line(Parent,Filename,Options) -> @@ -913,14 +887,11 @@ hold_the_line(Parent,Filename,Options) -> die -> ok end. - -bc_with_r12_gl(suite) -> - []; -bc_with_r12_gl(doc) -> - ["Test io protocol compatibility with R12 nodes (terminals)"]; + +%% Test io protocol compatibility with R12 nodes (terminals). bc_with_r12_gl(Config) when is_list(Config) -> - case ?t:is_release_available("r12b") of + case test_server:is_release_available("r12b") of true -> case get_progs() of {error,Reason} -> @@ -932,12 +903,9 @@ bc_with_r12_gl(Config) when is_list(Config) -> {skip,"No R12B found"} end. -bc_with_r12_ogl(suite) -> - []; -bc_with_r12_ogl(doc) -> - ["Test io protocol compatibility with R12 nodes (oldshell)"]; +%% Test io protocol compatibility with R12 nodes (oldshell). bc_with_r12_ogl(Config) when is_list(Config) -> - case ?t:is_release_available("r12b") of + case test_server:is_release_available("r12b") of true -> case get_progs() of {error,Reason} -> @@ -952,8 +920,9 @@ bc_with_r12_ogl(Config) when is_list(Config) -> bc_with_r12_gl_1(_Config,Machine) -> PA = filename:dirname(code:which(?MODULE)), Name1 = io_proto_r12_gl_1, - ?line N1 = list_to_atom(atom_to_list(Name1) ++ "@" ++ hostname()), - ?line ?t:start_node(Name1, peer, [{args, "-pz \""++PA++"\""},{erl,[{release,"r12b"}]}]), + N1 = list_to_atom(atom_to_list(Name1) ++ "@" ++ hostname()), + test_server:start_node(Name1, peer, [{args, "-pz \""++PA++"\""}, + {erl,[{release,"r12b"}]}]), TestDataLine1 = [229,228,246], TestDataLine1BinUtf = unicode:characters_to_binary(TestDataLine1), TestDataLine1BinLatin = list_to_binary(TestDataLine1), @@ -963,141 +932,141 @@ bc_with_r12_gl_1(_Config,Machine) -> register(io_proto_suite,self()), AM1 = spawn(?MODULE,Machine, [MyNodeList, "io_proto_suite", N2List]), - - ?line GL = receive X when is_pid(X) -> X end, + + GL = receive X when is_pid(X) -> X end, %% get_line - ?line "Hej\n" = rpc:call(N1,io,get_line,[GL,"Prompt\n"]), - ?line io:setopts(GL,[binary]), - ?line io:format(GL,"Okej~n",[]), - ?line <<"Hej\n">> = rpc:call(N1,io,get_line,[GL,"Prompt\n"]), - ?line io:setopts(GL,[{encoding,latin1}]), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinLatin = chomp(rpc:call(N1,io,get_line,[GL,"Prompt\n"])), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinUtf = chomp(io:get_line(GL,"Prompt\n")), - ?line io:setopts(GL,[{encoding,unicode}]), - - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinLatin = chomp(rpc:call(N1,io,get_line,[GL,"Prompt\n"])), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinUtf = chomp(io:get_line(GL,"Prompt\n")), - ?line io:setopts(GL,[list]), - ?line io:format(GL,"Okej~n",[]), - + "Hej\n" = rpc:call(N1,io,get_line,[GL,"Prompt\n"]), + io:setopts(GL,[binary]), + io:format(GL,"Okej~n",[]), + <<"Hej\n">> = rpc:call(N1,io,get_line,[GL,"Prompt\n"]), + io:setopts(GL,[{encoding,latin1}]), + io:format(GL,"Okej~n",[]), + TestDataLine1BinLatin = chomp(rpc:call(N1,io,get_line,[GL,"Prompt\n"])), + io:format(GL,"Okej~n",[]), + TestDataLine1BinUtf = chomp(io:get_line(GL,"Prompt\n")), + io:setopts(GL,[{encoding,unicode}]), + + io:format(GL,"Okej~n",[]), + TestDataLine1BinLatin = chomp(rpc:call(N1,io,get_line,[GL,"Prompt\n"])), + io:format(GL,"Okej~n",[]), + TestDataLine1BinUtf = chomp(io:get_line(GL,"Prompt\n")), + io:setopts(GL,[list]), + io:format(GL,"Okej~n",[]), + %%get_chars - ?line "Hej" = rpc:call(N1,io,get_chars,[GL,"Prompt\n",3]), - ?line io:setopts(GL,[binary]), - ?line io:format(GL,"Okej~n",[]), - ?line <<"Hej">> = rpc:call(N1,io,get_chars,[GL,"Prompt\n",3]), - ?line io:setopts(GL,[{encoding,latin1}]), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinLatin = rpc:call(N1,io,get_chars,[GL,"Prompt\n",3]), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinUtf = io:get_chars(GL,"Prompt\n",3), - ?line io:setopts(GL,[{encoding,unicode}]), - - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinLatin = rpc:call(N1,io,get_chars,[GL,"Prompt\n",3]), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinUtf = io:get_chars(GL,"Prompt\n",3), - ?line io:setopts(GL,[list]), - ?line io:format(GL,"Okej~n",[]), + "Hej" = rpc:call(N1,io,get_chars,[GL,"Prompt\n",3]), + io:setopts(GL,[binary]), + io:format(GL,"Okej~n",[]), + <<"Hej">> = rpc:call(N1,io,get_chars,[GL,"Prompt\n",3]), + io:setopts(GL,[{encoding,latin1}]), + io:format(GL,"Okej~n",[]), + TestDataLine1BinLatin = rpc:call(N1,io,get_chars,[GL,"Prompt\n",3]), + io:format(GL,"Okej~n",[]), + TestDataLine1BinUtf = io:get_chars(GL,"Prompt\n",3), + io:setopts(GL,[{encoding,unicode}]), + + io:format(GL,"Okej~n",[]), + TestDataLine1BinLatin = rpc:call(N1,io,get_chars,[GL,"Prompt\n",3]), + io:format(GL,"Okej~n",[]), + TestDataLine1BinUtf = io:get_chars(GL,"Prompt\n",3), + io:setopts(GL,[list]), + io:format(GL,"Okej~n",[]), %%fread - ?line {ok,["Hej"]} = rpc:call(N1,io,fread,[GL,"Prompt\n","~s"]), - ?line io:setopts(GL,[binary]), - ?line io:format(GL,"Okej~n",[]), - ?line {ok,["Hej"]} = rpc:call(N1,io,fread,[GL,"Prompt\n","~s"]), - ?line io:setopts(GL,[{encoding,latin1}]), - ?line io:format(GL,"Okej~n",[]), - ?line {ok,[TestDataLine1]} = rpc:call(N1,io,fread,[GL,"Prompt\n","~s"]), - ?line io:format(GL,"Okej~n",[]), - ?line {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), - ?line io:setopts(GL,[{encoding,unicode}]), - ?line io:format(GL,"Okej~n",[]), - ?line {ok,[TestDataLine1]} = rpc:call(N1,io,fread,[GL,"Prompt\n","~s"]), - ?line io:format(GL,"Okej~n",[]), - ?line {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), - ?line io:setopts(GL,[list]), - ?line io:format(GL,"Okej~n",[]), - - - ?line receive - {AM1,done} -> - ok - after 5000 -> - exit(timeout) - end, - ?t:stop_node(N1), + {ok,["Hej"]} = rpc:call(N1,io,fread,[GL,"Prompt\n","~s"]), + io:setopts(GL,[binary]), + io:format(GL,"Okej~n",[]), + {ok,["Hej"]} = rpc:call(N1,io,fread,[GL,"Prompt\n","~s"]), + io:setopts(GL,[{encoding,latin1}]), + io:format(GL,"Okej~n",[]), + {ok,[TestDataLine1]} = rpc:call(N1,io,fread,[GL,"Prompt\n","~s"]), + io:format(GL,"Okej~n",[]), + {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), + io:setopts(GL,[{encoding,unicode}]), + io:format(GL,"Okej~n",[]), + {ok,[TestDataLine1]} = rpc:call(N1,io,fread,[GL,"Prompt\n","~s"]), + io:format(GL,"Okej~n",[]), + {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), + io:setopts(GL,[list]), + io:format(GL,"Okej~n",[]), + + + receive + {AM1,done} -> + ok + after 5000 -> + exit(timeout) + end, + test_server:stop_node(N1), ok. - + answering_machine1(OthNode,OthReg,Me) -> TestDataLine1 = [229,228,246], TestDataUtf = binary_to_list(unicode:characters_to_binary(TestDataLine1)), - ?line rtnode([{putline,""}, - {putline, "2."}, - {getline, "2"}, - {putline, "{"++OthReg++","++OthNode++"} ! group_leader()."}, - {getline, "<"}, - % get_line - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"}, - % get_chars - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"}, - % fread - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"} - - ],Me,"LC_CTYPE=\""++get_lc_ctype()++"\"; export LC_CTYPE; "), + rtnode([{putline,""}, + {putline, "2."}, + {getline, "2"}, + {putline, "{"++OthReg++","++OthNode++"} ! group_leader()."}, + {getline, "<"}, + %% get_line + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"}, + %% get_chars + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"}, + %% fread + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"} + + ],Me,"LC_CTYPE=\""++get_lc_ctype()++"\"; export LC_CTYPE; "), O = list_to_atom(OthReg), O ! {self(),done}, ok. @@ -1105,79 +1074,76 @@ answering_machine1(OthNode,OthReg,Me) -> answering_machine2(OthNode,OthReg,Me) -> TestDataLine1 = [229,228,246], TestDataUtf = binary_to_list(unicode:characters_to_binary(TestDataLine1)), - ?line rtnode([{putline,""}, - {putline, "2."}, - {getline, "2"}, - {putline, "{"++OthReg++","++OthNode++"} ! group_leader()."}, - {getline_re, ".*<[0-9].*"}, - % get_line - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"}, - % get_chars - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"}, - % fread - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, "Hej"}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataLine1}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"}, - {getline_re, ".*Prompt"}, - {putline, TestDataUtf}, - {getline_re, ".*Okej"} - - ],Me,"LC_CTYPE=\""++get_lc_ctype()++"\"; export LC_CTYPE; "," -oldshell "), + rtnode([{putline,""}, + {putline, "2."}, + {getline, "2"}, + {putline, "{"++OthReg++","++OthNode++"} ! group_leader()."}, + {getline_re, ".*<[0-9].*"}, + %% get_line + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"}, + %% get_chars + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"}, + %% fread + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, "Hej"}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataLine1}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"}, + {getline_re, ".*Prompt"}, + {putline, TestDataUtf}, + {getline_re, ".*Okej"} + + ],Me,"LC_CTYPE=\""++get_lc_ctype()++"\"; export LC_CTYPE; "," -oldshell "), O = list_to_atom(OthReg), O ! {self(),done}, ok. - -read_modes_ogl(suite) -> - []; -read_modes_ogl(doc) -> - ["Test various modes when reading from the group leade from another machine"]; + +%% Test various modes when reading from the group leade from another machine. read_modes_ogl(Config) when is_list(Config) -> case get_progs() of {error,Reason} -> @@ -1186,10 +1152,7 @@ read_modes_ogl(Config) when is_list(Config) -> read_modes_gl_1(Config,answering_machine2) end. -read_modes_gl(suite) -> - []; -read_modes_gl(doc) -> - ["Test various modes when reading from the group leade from another machine"]; +%% Test various modes when reading from the group leade from another machine. read_modes_gl(Config) when is_list(Config) -> case {get_progs(),proplists:get_value(default_shell,Config)} of {{error,Reason},_} -> @@ -1210,81 +1173,78 @@ read_modes_gl_1(_Config,Machine) -> register(io_proto_suite,self()), AM1 = spawn(?MODULE,Machine, [MyNodeList, "io_proto_suite", N2List]), - - ?line GL = receive X when is_pid(X) -> X end, + + GL = receive X when is_pid(X) -> X end, ?dbg({group_leader,X}), %% get_line - ?line receive after 500 -> ok end, % Dont clash with the new shell... - ?line "Hej\n" = io:get_line(GL,"Prompt\n"), - ?line io:setopts(GL,[binary]), - ?line io:format(GL,"Okej~n",[]), - ?line <<"Hej\n">> = io:get_line(GL,"Prompt\n"), - ?line io:setopts(GL,[{encoding,latin1}]), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinLatin = chomp(io:request(GL,{get_line,latin1,"Prompt\n"})), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinUtf = chomp(io:get_line(GL,"Prompt\n")), - ?line io:setopts(GL,[{encoding,unicode}]), - - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinLatin = chomp(io:request(GL,{get_line,latin1,"Prompt\n"})), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinUtf = chomp(io:get_line(GL,"Prompt\n")), - ?line io:setopts(GL,[list]), - ?line io:format(GL,"Okej~n",[]), - + receive after 500 -> ok end, % Dont clash with the new shell... + "Hej\n" = io:get_line(GL,"Prompt\n"), + io:setopts(GL,[binary]), + io:format(GL,"Okej~n",[]), + <<"Hej\n">> = io:get_line(GL,"Prompt\n"), + io:setopts(GL,[{encoding,latin1}]), + io:format(GL,"Okej~n",[]), + TestDataLine1BinLatin = chomp(io:request(GL,{get_line,latin1,"Prompt\n"})), + io:format(GL,"Okej~n",[]), + TestDataLine1BinUtf = chomp(io:get_line(GL,"Prompt\n")), + io:setopts(GL,[{encoding,unicode}]), + + io:format(GL,"Okej~n",[]), + TestDataLine1BinLatin = chomp(io:request(GL,{get_line,latin1,"Prompt\n"})), + io:format(GL,"Okej~n",[]), + TestDataLine1BinUtf = chomp(io:get_line(GL,"Prompt\n")), + io:setopts(GL,[list]), + io:format(GL,"Okej~n",[]), + %%get_chars - ?line "Hej" = io:get_chars(GL,"Prompt\n",3), - ?line io:setopts(GL,[binary]), - ?line io:format(GL,"Okej~n",[]), - ?line <<"Hej">> = io:get_chars(GL,"Prompt\n",3), - ?line io:setopts(GL,[{encoding,latin1}]), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinLatin = io:request(GL,{get_chars,latin1,"Prompt\n",3}), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinUtf = io:get_chars(GL,"Prompt\n",3), - ?line io:setopts(GL,[{encoding,unicode}]), - - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinLatin = io:request(GL,{get_chars,latin1,"Prompt\n",3}), - ?line io:format(GL,"Okej~n",[]), - ?line TestDataLine1BinUtf = io:get_chars(GL,"Prompt\n",3), - ?line io:setopts(GL,[list]), - ?line io:format(GL,"Okej~n",[]), + "Hej" = io:get_chars(GL,"Prompt\n",3), + io:setopts(GL,[binary]), + io:format(GL,"Okej~n",[]), + <<"Hej">> = io:get_chars(GL,"Prompt\n",3), + io:setopts(GL,[{encoding,latin1}]), + io:format(GL,"Okej~n",[]), + TestDataLine1BinLatin = io:request(GL,{get_chars,latin1,"Prompt\n",3}), + io:format(GL,"Okej~n",[]), + TestDataLine1BinUtf = io:get_chars(GL,"Prompt\n",3), + io:setopts(GL,[{encoding,unicode}]), + + io:format(GL,"Okej~n",[]), + TestDataLine1BinLatin = io:request(GL,{get_chars,latin1,"Prompt\n",3}), + io:format(GL,"Okej~n",[]), + TestDataLine1BinUtf = io:get_chars(GL,"Prompt\n",3), + io:setopts(GL,[list]), + io:format(GL,"Okej~n",[]), %%fread - ?line {ok,["Hej"]} = io:fread(GL,"Prompt\n","~s"), - ?line io:setopts(GL,[binary]), - ?line io:format(GL,"Okej~n",[]), - ?line {ok,["Hej"]} = io:fread(GL,"Prompt\n","~s"), - ?line io:setopts(GL,[{encoding,latin1}]), - ?line io:format(GL,"Okej~n",[]), - ?line {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), - ?line io:format(GL,"Okej~n",[]), - ?line {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), - ?line io:setopts(GL,[{encoding,unicode}]), - ?line io:format(GL,"Okej~n",[]), - ?line {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), - ?line io:format(GL,"Okej~n",[]), - ?line {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), - ?line io:setopts(GL,[list]), - ?line io:format(GL,"Okej~n",[]), - - - ?line receive - {AM1,done} -> - ok - after 5000 -> - exit(timeout) - end, + {ok,["Hej"]} = io:fread(GL,"Prompt\n","~s"), + io:setopts(GL,[binary]), + io:format(GL,"Okej~n",[]), + {ok,["Hej"]} = io:fread(GL,"Prompt\n","~s"), + io:setopts(GL,[{encoding,latin1}]), + io:format(GL,"Okej~n",[]), + {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), + io:format(GL,"Okej~n",[]), + {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), + io:setopts(GL,[{encoding,unicode}]), + io:format(GL,"Okej~n",[]), + {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), + io:format(GL,"Okej~n",[]), + {ok,[TestDataLine1]} = io:fread(GL,"Prompt\n","~s"), + io:setopts(GL,[list]), + io:format(GL,"Okej~n",[]), + + + receive + {AM1,done} -> + ok + after 5000 -> + exit(timeout) + end, ok. -broken_unicode(suite) -> - []; -broken_unicode(doc) -> - ["Test behaviour when reading broken Unicode files"]; +%% Test behaviour when reading broken Unicode files broken_unicode(Config) when is_list(Config) -> - Dir = ?config(priv_dir,Config), + Dir = proplists:get_value(priv_dir,Config), Latin1Name = filename:join([Dir,"latin1_data_file.dat"]), Utf8Name = filename:join([Dir,"utf8_data_file.dat"]), Latin1Data = iolist_to_binary(lists:duplicate(10,lists:seq(0,255)++[255,255,255])), @@ -1292,10 +1252,10 @@ broken_unicode(Config) when is_list(Config) -> lists:duplicate(10,lists:seq(0,255))), file:write_file(Latin1Name,Latin1Data), file:write_file(Utf8Name,Utf8Data), - ?line [ latin1 = heuristic_encoding_file2(Latin1Name,N,utf8) || N <- lists:seq(1,100)++[1024,2048,10000]], - ?line [ utf8 = heuristic_encoding_file2(Utf8Name,N,utf8) || N <- lists:seq(1,100)++[1024,2048,10000]], - ?line [ latin1 = heuristic_encoding_file2(Latin1Name,N,utf16) || N <- lists:seq(1,100)++[1024,2048,10000]], - ?line [ latin1 = heuristic_encoding_file2(Latin1Name,N,utf32) || N <- lists:seq(1,100)++[1024,2048,10000]], + [ latin1 = heuristic_encoding_file2(Latin1Name,N,utf8) || N <- lists:seq(1,100)++[1024,2048,10000]], + [ utf8 = heuristic_encoding_file2(Utf8Name,N,utf8) || N <- lists:seq(1,100)++[1024,2048,10000]], + [ latin1 = heuristic_encoding_file2(Latin1Name,N,utf16) || N <- lists:seq(1,100)++[1024,2048,10000]], + [ latin1 = heuristic_encoding_file2(Latin1Name,N,utf32) || N <- lists:seq(1,100)++[1024,2048,10000]], ok. @@ -1314,10 +1274,7 @@ loop_through_file2(F,Bin,Chunk,Enc) when is_binary(Bin) -> -eof_on_pipe(suite) -> - []; -eof_on_pipe(doc) -> - ["tests eof before newline on stdin when erlang is in pipe"]; +%% Test eof before newline on stdin when erlang is in pipe. eof_on_pipe(Config) when is_list(Config) -> case {get_progs(),os:type()} of {{error,Reason},_} -> @@ -1337,10 +1294,10 @@ eof_on_pipe(Config) when is_list(Config) -> end end, CommandLine1 = EchoLine ++ - "\""++Erl++"\" -noshell -eval " - "'io:format(\"~p\",[io:get_line(\"\")])," - "io:format(\"~p\",[io:get_line(\"\")])," - "io:format(\"~p\",[io:get_line(\"\")]).' -run init stop", + "\""++Erl++"\" -noshell -eval " + "'io:format(\"~p\",[io:get_line(\"\")])," + "io:format(\"~p\",[io:get_line(\"\")])," + "io:format(\"~p\",[io:get_line(\"\")]).' -run init stop", case os:cmd(CommandLine1) of "\"a\\n\"\"bu\"eof" -> ok; @@ -1348,10 +1305,10 @@ eof_on_pipe(Config) when is_list(Config) -> exit({unexpected1,Other1}) end, CommandLine2 = EchoLine ++ - "\""++Erl++"\" -noshell -eval " - "'io:setopts([binary]),io:format(\"~p\",[io:get_line(\"\")])," - "io:format(\"~p\",[io:get_line(\"\")])," - "io:format(\"~p\",[io:get_line(\"\")]).' -run init stop", + "\""++Erl++"\" -noshell -eval " + "'io:setopts([binary]),io:format(\"~p\",[io:get_line(\"\")])," + "io:format(\"~p\",[io:get_line(\"\")])," + "io:format(\"~p\",[io:get_line(\"\")]).' -run init stop", case os:cmd(CommandLine2) of "<<\"a\\n\">><<\"bu\">>eof" -> ok; @@ -1360,12 +1317,12 @@ eof_on_pipe(Config) when is_list(Config) -> end catch throw:skip -> - {skipped,"unsupported echo program"} + {skipped,"unsupported echo program"} end; {_,_} -> {skipped,"Only on linux"} end. - + %% %% Tool for running interactive shell (stolen from the kernel @@ -1435,16 +1392,16 @@ timeout(normal) -> -ifndef(debug). rm_rf(Dir) -> try - {ok,List} = file:list_dir(Dir), - Files = [filename:join([Dir,X]) || X <- List], - [case file:list_dir(Y) of - {error, enotdir} -> - ok = file:delete(Y); - _ -> - ok = rm_rf(Y) - end || Y <- Files], - ok = file:del_dir(Dir), - ok + {ok,List} = file:list_dir(Dir), + Files = [filename:join([Dir,X]) || X <- List], + [case file:list_dir(Y) of + {error, enotdir} -> + ok = file:delete(Y); + _ -> + ok = rm_rf(Y) + end || Y <- Files], + ok = file:del_dir(Dir), + ok catch _:Exception -> {error, {Exception,Dir}} end. @@ -1509,7 +1466,7 @@ get_and_put(CPid, [{putline_raw, Line}|T],N) -> Timeout = timeout(normal), receive {send_line, ok} -> - get_and_put(CPid, T,N+1) + get_and_put(CPid, T,N+1) after Timeout -> error_logger:error_msg("~p: putline_raw timeout (~p) sending " "\"~s\" (command number ~p)~n", @@ -1523,7 +1480,7 @@ get_and_put(CPid, [{putline, Line}|T],N) -> Timeout = timeout(normal), receive {send_line, ok} -> - get_and_put(CPid, [{getline, []}|T],N) + get_and_put(CPid, [{getline, []}|T],N) after Timeout -> error_logger:error_msg("~p: putline timeout (~p) sending " "\"~s\" (command number ~p)~n[~p]~n", @@ -1540,8 +1497,8 @@ wait_for_runerl_server(SPid) -> after Timeout -> {error, timeout} end. - - + + stop_runerl_node(CPid) -> Ref = erlang:monitor(process, CPid), @@ -1592,11 +1549,11 @@ create_tempdir(Dir,X) when X > $Z, X < $a -> create_tempdir(Dir,$a); create_tempdir(Dir,X) when X > $z -> Estr = lists:flatten( - io_lib:format("Unable to create ~s, reason eexist", - [Dir++[$z]])), + io_lib:format("Unable to create ~s, reason eexist", + [Dir++[$z]])), {error, Estr}; create_tempdir(Dir0, Ch) -> - % Expect fairly standard unix. + %% Expect fairly standard unix. Dir = Dir0++[Ch], case file:make_dir(Dir) of {error, eexist} -> @@ -1634,8 +1591,8 @@ start_runerl_node(RunErl,Erl,Tempdir,Nodename,Extra) -> []; _ -> " -sname "++(if is_atom(Nodename) -> atom_to_list(Nodename); - true -> Nodename - end)++ + true -> Nodename + end)++ " -setcookie "++atom_to_list(erlang:get_cookie()) end, XXArg = case Extra of @@ -1646,9 +1603,9 @@ start_runerl_node(RunErl,Erl,Tempdir,Nodename,Extra) -> end, spawn(fun() -> ?dbg("\""++RunErl++"\" "++Tempdir++"/ "++Tempdir++ - " \""++Erl++XArg++XXArg++"\""), + " \""++Erl++XArg++XXArg++"\""), os:cmd("\""++RunErl++"\" "++Tempdir++"/ "++Tempdir++ - " \""++Erl++XArg++XXArg++"\"") + " \""++Erl++XArg++XXArg++"\"") end). start_toerl_server(ToErl,Tempdir) -> @@ -1706,7 +1663,7 @@ toerl_loop(Port,Acc) -> _ -> toerl_loop(Port,[{Tag0,Data}|Acc]) end; - {Pid,{get_line,Timeout}} -> + {Pid,{get_line,Timeout}} -> case Acc of [] -> case get_data_within(Port,Timeout,[]) of @@ -1755,10 +1712,10 @@ toerl_loop(Port,Acc) -> Other -> {error, {unexpected, Other}} end. - + millistamp() -> erlang:monotonic_time(milli_seconds). - + get_data_within(Port, X, Acc) when X =< 0 -> ?dbg({get_data_within, X, Acc, ?LINE}), receive @@ -1877,8 +1834,8 @@ request({get_until, Encoding, Prompt, M, F, As}, State) -> {ok, convert(State#state.nxt, Encoding, State#state.mode), State#state{nxt = eof, q = [{get_until, Encoding, Prompt, M, F, As} | State#state.q]}}; request({get_chars, Encoding, Prompt, N}, State) -> {ok, convert(State#state.nxt, Encoding, State#state.mode), State#state{nxt = eof, - q = [{get_chars, Encoding, Prompt, N} | - State#state.q]}}; + q = [{get_chars, Encoding, Prompt, N} | + State#state.q]}}; request({get_line, Encoding, Prompt}, State) -> {ok, convert(State#state.nxt, Encoding, State#state.mode), State#state{nxt = eof, @@ -1910,7 +1867,7 @@ request(getopts, State) -> binary -> [{binary, true}] end, State#state{q=[getopts | State#state.q ]}}; request({requests, Reqs}, State) -> - multi_request(Reqs, {ok, ok, State}). + multi_request(Reqs, {ok, ok, State}). multi_request([R|Rs], {ok, _Res, State}) -> multi_request(Rs, request(R, State)); @@ -1941,7 +1898,7 @@ convert(Data, latin1, binary) -> _ -> {error, {cannot_convert, unicode, latin1}} end. - + hostname() -> from($@, atom_to_list(node())). diff --git a/lib/stdlib/test/lists_SUITE.erl b/lib/stdlib/test/lists_SUITE.erl index 257607f734..b21eb37ee3 100644 --- a/lib/stdlib/test/lists_SUITE.erl +++ b/lib/stdlib/test/lists_SUITE.erl @@ -24,24 +24,18 @@ -module(lists_SUITE). -include_lib("common_test/include/ct.hrl"). - -% Default timetrap timeout (set in init_per_testcase). -% This should be set relatively high (10-15 times the expected -% max testcasetime). --define(default_timeout, ?t:minutes(4)). - -% Test server specific exports +%% Test server specific exports -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2]). -export([init_per_testcase/2, end_per_testcase/2]). -% Test cases must be exported. +%% Test cases must be exported. -export([member/1, reverse/1, keymember/1, keysearch_keyfind/1, keystore/1, keytake/1, keyreplace/1, append_1/1, append_2/1, seq_loop/1, seq_2/1, seq_3/1, seq_2_e/1, seq_3_e/1, - + sublist_2/1, sublist_3/1, sublist_2_e/1, sublist_3_e/1, flatten_1/1, flatten_2/1, flatten_1_e/1, flatten_2_e/1, dropwhile/1, takewhile/1, @@ -78,7 +72,9 @@ %% %% all/1 %% -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,4}}]. all() -> [{group, append}, @@ -141,58 +137,48 @@ end_per_group(_GroupName, Config) -> init_per_testcase(_Case, Config) -> - ?line Dog=test_server:timetrap(?default_timeout), - [{watchdog, Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. -% -% Test cases starts here. -% +%% +%% Test cases starts here. +%% -append_1(doc) -> []; -append_1(suite) -> []; append_1(Config) when is_list(Config) -> - ?line "abcdef"=lists:append(["abc","def"]), - ?line [hej, du,[glade, [bagare]]]= + "abcdef"=lists:append(["abc","def"]), + [hej, du,[glade, [bagare]]]= lists:append([[hej], [du], [[glade, [bagare]]]]), - ?line [10, [elem]]=lists:append([[10], [[elem]]]), + [10, [elem]]=lists:append([[10], [[elem]]]), ok. -append_2(doc) -> []; -append_2(suite) -> []; append_2(Config) when is_list(Config) -> - ?line "abcdef"=lists:append("abc", "def"), - ?line [hej, du]=lists:append([hej], [du]), - ?line [10, [elem]]=lists:append([10], [[elem]]), + "abcdef"=lists:append("abc", "def"), + [hej, du]=lists:append([hej], [du]), + [10, [elem]]=lists:append([10], [[elem]]), ok. -reverse(suite) -> - []; -reverse(doc) -> - ["Tests the lists:reverse() implementation. The function is " - "`non-blocking', and only processes a fixed number of elements " - "at a time."]; +%% Tests the lists:reverse() implementation. The function is +%% `non-blocking', and only processes a fixed number of elements at a +%% time. reverse(Config) when is_list(Config) -> - ?line reverse_test(0), - ?line reverse_test(1), - ?line reverse_test(2), - ?line reverse_test(128), - ?line reverse_test(256), - ?line reverse_test(1000), - ?line reverse_test(1998), - ?line reverse_test(1999), - ?line reverse_test(2000), - ?line reverse_test(2001), - ?line reverse_test(3998), - ?line reverse_test(3999), - ?line reverse_test(4000), - ?line reverse_test(4001), - ?line reverse_test(60001), - ?line reverse_test(100007), + reverse_test(0), + reverse_test(1), + reverse_test(2), + reverse_test(128), + reverse_test(256), + reverse_test(1000), + reverse_test(1998), + reverse_test(1999), + reverse_test(2000), + reverse_test(2001), + reverse_test(3998), + reverse_test(3999), + reverse_test(4000), + reverse_test(4001), + reverse_test(60001), + reverse_test(100007), ok. reverse_test(0) -> @@ -210,27 +196,25 @@ reverse_test(Num) -> List0 = lists:reverse(List), ok. -member(doc) -> - ["Tests the lists:member() implementation." - "This test case depends on lists:reverse() to work, " - "wich is tested in a separate test case."]; +%% Test the lists:member() implementation. This test case depends on +%% lists:reverse() to work, wich is tested in a separate test case. member(Config) when is_list(Config) -> - ?line {'EXIT',{badarg,_}} = (catch lists:member(45, {a,b,c})), - ?line {'EXIT',{badarg,_}} = (catch lists:member(45, [0|non_list_tail])), - ?line false = lists:member(4233, []), - ?line member_test(1), - ?line member_test(100), - ?line member_test(256), - ?line member_test(1000), - ?line member_test(1998), - ?line member_test(1999), - ?line member_test(2000), - ?line member_test(2001), - ?line member_test(3998), - ?line member_test(3999), - ?line member_test(4000), - ?line member_test(4001), - ?line member_test(100008), + {'EXIT',{badarg,_}} = (catch lists:member(45, {a,b,c})), + {'EXIT',{badarg,_}} = (catch lists:member(45, [0|non_list_tail])), + false = lists:member(4233, []), + member_test(1), + member_test(100), + member_test(256), + member_test(1000), + member_test(1998), + member_test(1999), + member_test(2000), + member_test(2001), + member_test(3998), + member_test(3999), + member_test(4000), + member_test(4001), + member_test(100008), ok. member_test(Num) -> @@ -246,78 +230,78 @@ member_test(Num) -> false = lists:member({a,b,c}, List). keymember(Config) when is_list(Config) -> - ?line false = lists:keymember(anything_goes, 1, []), - ?line {'EXIT',{badarg,_}} = (catch lists:keymember(anything_goes, -1, [])), - ?line {'EXIT',{badarg,_}} = (catch lists:keymember(anything_goes, 0, [])), - ?line {'EXIT',{badarg,_}} = (catch lists:keymember(anything_goes, 1, {1,2,3})), + false = lists:keymember(anything_goes, 1, []), + {'EXIT',{badarg,_}} = (catch lists:keymember(anything_goes, -1, [])), + {'EXIT',{badarg,_}} = (catch lists:keymember(anything_goes, 0, [])), + {'EXIT',{badarg,_}} = (catch lists:keymember(anything_goes, 1, {1,2,3})), List = [{52.0,a},{-19,b,c},{37.5,d},an_atom,42.0,{39},{45,{x,y,z}}], - ?line false = lists:keymember(333, 5, List), - ?line false = lists:keymember(333, 999, List), - ?line false = lists:keymember(37, 1, List), - - ?line true = lists:keymember(52.0, 1, List), - ?line true = lists:keymember(52, 1, List), - ?line true = lists:keymember(-19, 1, List), - ?line true = lists:keymember(-19.0, 1, List), - ?line true = lists:keymember(37.5, 1, List), - ?line true = lists:keymember(39, 1, List), - ?line true = lists:keymember(39.0, 1, List), - ?line true = lists:keymember(45, 1, List), - ?line true = lists:keymember(45.0, 1, List), - - ?line true = lists:keymember(a, 2, List), - ?line true = lists:keymember(b, 2, List), - ?line true = lists:keymember(c, 3, List), - ?line true = lists:keymember(d, 2, List), - ?line true = lists:keymember({x,y,z}, 2, List), - - ?line Long0 = lists:seq(1, 100007), - ?line false = lists:keymember(kalle, 1, Long0), - ?line Long = lists:foldl(fun(E, A) -> [{1/E,E}|A] end, [], Long0), - ?line true = lists:keymember(1, 2, Long), - ?line true = lists:keymember(2, 2, Long), - ?line true = lists:keymember(1.0, 2, Long), - ?line true = lists:keymember(2.0, 2, Long), - ?line true = lists:keymember(100006, 2, Long), + false = lists:keymember(333, 5, List), + false = lists:keymember(333, 999, List), + false = lists:keymember(37, 1, List), + + true = lists:keymember(52.0, 1, List), + true = lists:keymember(52, 1, List), + true = lists:keymember(-19, 1, List), + true = lists:keymember(-19.0, 1, List), + true = lists:keymember(37.5, 1, List), + true = lists:keymember(39, 1, List), + true = lists:keymember(39.0, 1, List), + true = lists:keymember(45, 1, List), + true = lists:keymember(45.0, 1, List), + + true = lists:keymember(a, 2, List), + true = lists:keymember(b, 2, List), + true = lists:keymember(c, 3, List), + true = lists:keymember(d, 2, List), + true = lists:keymember({x,y,z}, 2, List), + + Long0 = lists:seq(1, 100007), + false = lists:keymember(kalle, 1, Long0), + Long = lists:foldl(fun(E, A) -> [{1/E,E}|A] end, [], Long0), + true = lists:keymember(1, 2, Long), + true = lists:keymember(2, 2, Long), + true = lists:keymember(1.0, 2, Long), + true = lists:keymember(2.0, 2, Long), + true = lists:keymember(100006, 2, Long), ok. keysearch_keyfind(Config) when is_list(Config) -> - ?line false = key_search_find(anything_goes, 1, []), - ?line {'EXIT',{badarg,_}} = (catch key_search_find(anything_goes, -1, [])), - ?line {'EXIT',{badarg,_}} = (catch key_search_find(anything_goes, 0, [])), - ?line {'EXIT',{badarg,_}} = (catch key_search_find(anything_goes, 1, {1,2,3})), + false = key_search_find(anything_goes, 1, []), + {'EXIT',{badarg,_}} = (catch key_search_find(anything_goes, -1, [])), + {'EXIT',{badarg,_}} = (catch key_search_find(anything_goes, 0, [])), + {'EXIT',{badarg,_}} = (catch key_search_find(anything_goes, 1, {1,2,3})), First = {x,42.0}, Second = {y,-77}, Third = {z,[a,b,c],{5.0}}, List = [First,Second,Third], - - ?line false = key_search_find(333, 1, []), - ?line false = key_search_find(333, 5, List), - ?line false = key_search_find(333, 999, List), - ?line false = key_search_find(37, 1, List), - - ?line {value,First} = key_search_find(42, 2, List), - ?line {value,First} = key_search_find(42.0, 2, List), - - ?line {value,Second} = key_search_find(-77, 2, List), - ?line {value,Second} = key_search_find(-77.0, 2, List), - - ?line {value,Third} = key_search_find(z, 1, List), - ?line {value,Third} = key_search_find([a,b,c], 2, List), - ?line {value,Third} = key_search_find({5}, 3, List), - ?line {value,Third} = key_search_find({5.0}, 3, List), - - ?line Long0 = lists:seq(1, 100007), - ?line false = key_search_find(kalle, 1, Long0), - ?line Long = lists:foldl(fun(E, A) -> [{1/E,float(E)}|A] end, [], Long0), - ?line {value,{_,1.0}} = key_search_find(1, 2, Long), - ?line {value,{_,1.0}} = key_search_find(1.0, 2, Long), - ?line {value,{_,2.0}} = key_search_find(2, 2, Long), - ?line {value,{_,2.0}} = key_search_find(2.0, 2, Long), - ?line {value,{_,33988.0}} = key_search_find(33988, 2, Long), - ?line {value,{_,33988.0}} = key_search_find(33988.0, 2, Long), + + false = key_search_find(333, 1, []), + false = key_search_find(333, 5, List), + false = key_search_find(333, 999, List), + false = key_search_find(37, 1, List), + + {value,First} = key_search_find(42, 2, List), + {value,First} = key_search_find(42.0, 2, List), + + {value,Second} = key_search_find(-77, 2, List), + {value,Second} = key_search_find(-77.0, 2, List), + + {value,Third} = key_search_find(z, 1, List), + {value,Third} = key_search_find([a,b,c], 2, List), + {value,Third} = key_search_find({5}, 3, List), + {value,Third} = key_search_find({5.0}, 3, List), + + Long0 = lists:seq(1, 100007), + false = key_search_find(kalle, 1, Long0), + Long = lists:foldl(fun(E, A) -> [{1/E,float(E)}|A] end, [], Long0), + {value,{_,1.0}} = key_search_find(1, 2, Long), + {value,{_,1.0}} = key_search_find(1.0, 2, Long), + {value,{_,2.0}} = key_search_find(2, 2, Long), + {value,{_,2.0}} = key_search_find(2.0, 2, Long), + {value,{_,33988.0}} = key_search_find(33988, 2, Long), + {value,{_,33988.0}} = key_search_find(33988.0, 2, Long), ok. %% Test both lists:keysearch/3 and lists:keyfind/3. The only @@ -333,29 +317,29 @@ key_search_find(Key, Pos, List) -> end. dropwhile(Config) when is_list(Config) -> - ?line F = fun(C) -> C =:= $@ end, + F = fun(C) -> C =:= $@ end, - ?line [] = lists:dropwhile(F, []), - ?line [a] = lists:dropwhile(F, [a]), - ?line [a,b] = lists:dropwhile(F, [a,b]), - ?line [a,b,c] = lists:dropwhile(F, [a,b,c]), + [] = lists:dropwhile(F, []), + [a] = lists:dropwhile(F, [a]), + [a,b] = lists:dropwhile(F, [a,b]), + [a,b,c] = lists:dropwhile(F, [a,b,c]), - ?line [] = lists:dropwhile(F, [$@]), - ?line [] = lists:dropwhile(F, [$@,$@]), - ?line [a,$@] = lists:dropwhile(F, [$@,a,$@]), + [] = lists:dropwhile(F, [$@]), + [] = lists:dropwhile(F, [$@,$@]), + [a,$@] = lists:dropwhile(F, [$@,a,$@]), - ?line [$k] = lists:dropwhile(F, [$@,$k]), - ?line [$k,$l] = lists:dropwhile(F, [$@,$@,$k,$l]), - ?line [a] = lists:dropwhile(F, [$@,$@,$@,a]), + [$k] = lists:dropwhile(F, [$@,$k]), + [$k,$l] = lists:dropwhile(F, [$@,$@,$k,$l]), + [a] = lists:dropwhile(F, [$@,$@,$@,a]), - ?line [a,$@,b] = lists:dropwhile(F, [$@,a,$@,b]), - ?line [a,$@,b] = lists:dropwhile(F, [$@,$@,a,$@,b]), - ?line [a,$@,b] = lists:dropwhile(F, [$@,$@,$@,a,$@,b]), + [a,$@,b] = lists:dropwhile(F, [$@,a,$@,b]), + [a,$@,b] = lists:dropwhile(F, [$@,$@,a,$@,b]), + [a,$@,b] = lists:dropwhile(F, [$@,$@,$@,a,$@,b]), Long = lists:seq(1, 1024), Shorter = lists:seq(800, 1024), - ?line Shorter = lists:dropwhile(fun(E) -> E < 800 end, Long), + Shorter = lists:dropwhile(fun(E) -> E < 800 end, Long), ok. @@ -386,41 +370,35 @@ takewhile(Config) when is_list(Config) -> ok. -keystore(doc) -> - ["OTP-XXX."]; -keystore(suite) -> []; keystore(Config) when is_list(Config) -> - ?line {'EXIT',_} = (catch lists:keystore(key, 0, [], {1})), - ?line {'EXIT',_} = (catch lists:keystore(key, 1, {}, {})), - ?line {'EXIT',_} = (catch lists:keystore(key, 1, {a,b}, {})), - ?line {'EXIT', _} = (catch lists:keystore(a, 2, [{1,a}], b)), + {'EXIT',_} = (catch lists:keystore(key, 0, [], {1})), + {'EXIT',_} = (catch lists:keystore(key, 1, {}, {})), + {'EXIT',_} = (catch lists:keystore(key, 1, {a,b}, {})), + {'EXIT', _} = (catch lists:keystore(a, 2, [{1,a}], b)), T = {k,17}, - ?line [T] = lists:keystore(a, 2, [], T), - ?line [{1,a},{2,b},{k,17}] = lists:keystore(c, 2, [{1,a},{2,b}],T), + [T] = lists:keystore(a, 2, [], T), + [{1,a},{2,b},{k,17}] = lists:keystore(c, 2, [{1,a},{2,b}],T), L = [{1,a},{2,b},{3,c}], - ?line [{k,17},{2,b},{3,c}] = lists:keystore(a, 2, L, T), - ?line [{1,a},{k,17},{3,c}] = lists:keystore(b, 2, L, T), - ?line [{1,a},{2,b},{k,17}] = lists:keystore(c, 2, L, T), - ?line [{2,b}] = lists:keystore(a, 2, [{1,a}], {2,b}), - ?line [{1,a}] = lists:keystore(foo, 1, [], {1,a}), + [{k,17},{2,b},{3,c}] = lists:keystore(a, 2, L, T), + [{1,a},{k,17},{3,c}] = lists:keystore(b, 2, L, T), + [{1,a},{2,b},{k,17}] = lists:keystore(c, 2, L, T), + [{2,b}] = lists:keystore(a, 2, [{1,a}], {2,b}), + [{1,a}] = lists:keystore(foo, 1, [], {1,a}), ok. -keytake(doc) -> - ["OTP-XXX."]; -keytake(suite) -> []; keytake(Config) when is_list(Config) -> - ?line {'EXIT',_} = (catch lists:keytake(key, 0, [])), - ?line {'EXIT',_} = (catch lists:keytake(key, 1, {})), - ?line {'EXIT',_} = (catch lists:keytake(key, 1, {a,b})), - ?line false = lists:keytake(key, 2, [{a}]), - ?line false = lists:keytake(key, 1, [a]), - ?line false = lists:keytake(k, 1, []), - ?line false = lists:keytake(k, 1, [{a},{b},{c}]), + {'EXIT',_} = (catch lists:keytake(key, 0, [])), + {'EXIT',_} = (catch lists:keytake(key, 1, {})), + {'EXIT',_} = (catch lists:keytake(key, 1, {a,b})), + false = lists:keytake(key, 2, [{a}]), + false = lists:keytake(key, 1, [a]), + false = lists:keytake(k, 1, []), + false = lists:keytake(k, 1, [{a},{b},{c}]), L = [{a,1},{b,2},{c,3}], - ?line {value,{a,1},[{b,2},{c,3}]} = lists:keytake(1, 2, L), - ?line {value,{b,2},[{a,1},{c,3}]} = lists:keytake(2, 2, L), - ?line {value,{c,3},[{a,1},{b,2}]} = lists:keytake(3, 2, L), - ?line false = lists:keytake(4, 2, L), + {value,{a,1},[{b,2},{c,3}]} = lists:keytake(1, 2, L), + {value,{b,2},[{a,1},{c,3}]} = lists:keytake(2, 2, L), + {value,{c,3},[{a,1},{b,2}]} = lists:keytake(3, 2, L), + false = lists:keytake(4, 2, L), ok. %% Test lists:keyreplace/4. @@ -434,153 +412,147 @@ keyreplace(Config) when is_list(Config) -> {'EXIT',_} = (catch lists:keyreplace(k, 0, [], {a,b})), ok. -merge(doc) -> ["merge functions"]; -merge(suite) -> []; merge(Config) when is_list(Config) -> %% merge list of lists - ?line [] = lists:merge([]), - ?line [] = lists:merge([[]]), - ?line [] = lists:merge([[],[]]), - ?line [] = lists:merge([[],[],[]]), - ?line [1] = lists:merge([[1]]), - ?line [1,1,2,2] = lists:merge([[1,2],[1,2]]), - ?line [1] = lists:merge([[1],[],[]]), - ?line [1] = lists:merge([[],[1],[]]), - ?line [1] = lists:merge([[],[],[1]]), - ?line [1,2] = lists:merge([[1],[2],[]]), - ?line [1,2] = lists:merge([[1],[],[2]]), - ?line [1,2] = lists:merge([[],[1],[2]]), - ?line [1,2,3,4,5,6] = lists:merge([[1,2],[],[5,6],[],[3,4],[]]), - ?line [1,2,3,4] = lists:merge([[4],[3],[2],[1]]), - ?line [1,2,3,4,5] = lists:merge([[1],[2],[3],[4],[5]]), - ?line [1,2,3,4,5,6] = lists:merge([[1],[2],[3],[4],[5],[6]]), - ?line [1,2,3,4,5,6,7,8,9] = + [] = lists:merge([]), + [] = lists:merge([[]]), + [] = lists:merge([[],[]]), + [] = lists:merge([[],[],[]]), + [1] = lists:merge([[1]]), + [1,1,2,2] = lists:merge([[1,2],[1,2]]), + [1] = lists:merge([[1],[],[]]), + [1] = lists:merge([[],[1],[]]), + [1] = lists:merge([[],[],[1]]), + [1,2] = lists:merge([[1],[2],[]]), + [1,2] = lists:merge([[1],[],[2]]), + [1,2] = lists:merge([[],[1],[2]]), + [1,2,3,4,5,6] = lists:merge([[1,2],[],[5,6],[],[3,4],[]]), + [1,2,3,4] = lists:merge([[4],[3],[2],[1]]), + [1,2,3,4,5] = lists:merge([[1],[2],[3],[4],[5]]), + [1,2,3,4,5,6] = lists:merge([[1],[2],[3],[4],[5],[6]]), + [1,2,3,4,5,6,7,8,9] = lists:merge([[1],[2],[3],[4],[5],[6],[7],[8],[9]]), Seq = lists:seq(1,100), - ?line true = Seq == lists:merge(lists:map(fun(E) -> [E] end, Seq)), + true = Seq == lists:merge(lists:map(fun(E) -> [E] end, Seq)), Two = [1,2], Six = [1,2,3,4,5,6], %% 2-way merge - ?line [] = lists:merge([], []), - ?line Two = lists:merge(Two, []), - ?line Two = lists:merge([], Two), - ?line Six = lists:merge([1,3,5], [2,4,6]), - ?line Six = lists:merge([2,4,6], [1,3,5]), - ?line Six = lists:merge([1,2,3], [4,5,6]), - ?line Six = lists:merge([4,5,6], [1,2,3]), - ?line Six = lists:merge([1,2,5],[3,4,6]), - ?line [1,2,3,5,7] = lists:merge([1,3,5,7], [2]), - ?line [1,2,3,4,5,7] = lists:merge([1,3,5,7], [2,4]), - ?line [1,2,3,4,5,6,7] = lists:merge([1,3,5,7], [2,4,6]), - ?line [1,2,3,5,7] = lists:merge([2], [1,3,5,7]), - ?line [1,2,3,4,5,7] = lists:merge([2,4], [1,3,5,7]), - ?line [1,2,3,4,5,6,7] = lists:merge([2,4,6], [1,3,5,7]), + [] = lists:merge([], []), + Two = lists:merge(Two, []), + Two = lists:merge([], Two), + Six = lists:merge([1,3,5], [2,4,6]), + Six = lists:merge([2,4,6], [1,3,5]), + Six = lists:merge([1,2,3], [4,5,6]), + Six = lists:merge([4,5,6], [1,2,3]), + Six = lists:merge([1,2,5],[3,4,6]), + [1,2,3,5,7] = lists:merge([1,3,5,7], [2]), + [1,2,3,4,5,7] = lists:merge([1,3,5,7], [2,4]), + [1,2,3,4,5,6,7] = lists:merge([1,3,5,7], [2,4,6]), + [1,2,3,5,7] = lists:merge([2], [1,3,5,7]), + [1,2,3,4,5,7] = lists:merge([2,4], [1,3,5,7]), + [1,2,3,4,5,6,7] = lists:merge([2,4,6], [1,3,5,7]), %% 3-way merge - ?line [] = lists:merge3([], [], []), - ?line Two = lists:merge3([], [], Two), - ?line Two = lists:merge3([], Two, []), - ?line Two = lists:merge3(Two, [], []), - ?line Six = lists:merge3([], [1,3,5], [2,4,6]), - ?line Six = lists:merge3([1,3,5], [], [2,4,6]), - ?line Six = lists:merge3([1,3,5], [2,4,6], []), - ?line Nine = lists:merge3([1,4,7],[2,5,8],[3,6,9]), - ?line Nine = lists:merge3([1,4,7],[3,6,9],[2,5,8]), - ?line Nine = lists:merge3([3,6,9],[1,4,7],[2,5,8]), - ?line Nine = lists:merge3([4,5,6],[1,2,3],[7,8,9]), - ?line Nine = lists:merge3([1,2,3],[4,5,6],[7,8,9]), - ?line Nine = lists:merge3([7,8,9],[4,5,6],[1,2,3]), - ?line Nine = lists:merge3([4,5,6],[7,8,9],[1,2,3]), - - ok. - -rmerge(doc) -> ["reverse merge functions"]; -rmerge(suite) -> []; + [] = lists:merge3([], [], []), + Two = lists:merge3([], [], Two), + Two = lists:merge3([], Two, []), + Two = lists:merge3(Two, [], []), + Six = lists:merge3([], [1,3,5], [2,4,6]), + Six = lists:merge3([1,3,5], [], [2,4,6]), + Six = lists:merge3([1,3,5], [2,4,6], []), + Nine = lists:merge3([1,4,7],[2,5,8],[3,6,9]), + Nine = lists:merge3([1,4,7],[3,6,9],[2,5,8]), + Nine = lists:merge3([3,6,9],[1,4,7],[2,5,8]), + Nine = lists:merge3([4,5,6],[1,2,3],[7,8,9]), + Nine = lists:merge3([1,2,3],[4,5,6],[7,8,9]), + Nine = lists:merge3([7,8,9],[4,5,6],[1,2,3]), + Nine = lists:merge3([4,5,6],[7,8,9],[1,2,3]), + + ok. + +%% reverse merge functions rmerge(Config) when is_list(Config) -> Two = [2,1], Six = [6,5,4,3,2,1], %% 2-way reversed merge - ?line [] = lists:rmerge([], []), - ?line Two = lists:rmerge(Two, []), - ?line Two = lists:rmerge([], Two), - ?line Six = lists:rmerge([5,3,1], [6,4,2]), - ?line Six = lists:rmerge([6,4,2], [5,3,1]), - ?line Six = lists:rmerge([3,2,1], [6,5,4]), - ?line Six = lists:rmerge([6,5,4], [3,2,1]), - ?line Six = lists:rmerge([4,3,2],[6,5,1]), - ?line [7,6,5,3,1] = lists:rmerge([7,5,3,1], [6]), - ?line [7,6,5,4,3,1] = lists:rmerge([7,5,3,1], [6,4]), - ?line [7,6,5,4,3,2,1] = lists:rmerge([7,5,3,1], [6,4,2]), - ?line [7,5,3,2,1] = lists:rmerge([2], [7,5,3,1]), - ?line [7,5,4,3,2,1] = lists:rmerge([4,2], [7,5,3,1]), - ?line [7,6,5,4,3,2,1] = lists:rmerge([6,4,2], [7,5,3,1]), + [] = lists:rmerge([], []), + Two = lists:rmerge(Two, []), + Two = lists:rmerge([], Two), + Six = lists:rmerge([5,3,1], [6,4,2]), + Six = lists:rmerge([6,4,2], [5,3,1]), + Six = lists:rmerge([3,2,1], [6,5,4]), + Six = lists:rmerge([6,5,4], [3,2,1]), + Six = lists:rmerge([4,3,2],[6,5,1]), + [7,6,5,3,1] = lists:rmerge([7,5,3,1], [6]), + [7,6,5,4,3,1] = lists:rmerge([7,5,3,1], [6,4]), + [7,6,5,4,3,2,1] = lists:rmerge([7,5,3,1], [6,4,2]), + [7,5,3,2,1] = lists:rmerge([2], [7,5,3,1]), + [7,5,4,3,2,1] = lists:rmerge([4,2], [7,5,3,1]), + [7,6,5,4,3,2,1] = lists:rmerge([6,4,2], [7,5,3,1]), Nine = [9,8,7,6,5,4,3,2,1], %% 3-way reversed merge - ?line [] = lists:rmerge3([], [], []), - ?line Two = lists:rmerge3([], [], Two), - ?line Two = lists:rmerge3([], Two, []), - ?line Two = lists:rmerge3(Two, [], []), - ?line Six = lists:rmerge3([], [5,3,1], [6,4,2]), - ?line Six = lists:rmerge3([5,3,1], [], [6,4,2]), - ?line Six = lists:rmerge3([5,3,1], [6,4,2], []), - ?line Nine = lists:rmerge3([7,4,1],[8,5,2],[9,6,3]), - ?line Nine = lists:rmerge3([7,4,1],[9,6,3],[8,5,2]), - ?line Nine = lists:rmerge3([9,6,3],[7,4,1],[8,5,2]), - ?line Nine = lists:rmerge3([6,5,4],[3,2,1],[9,8,7]), - ?line Nine = lists:rmerge3([3,2,1],[6,5,4],[9,8,7]), - ?line Nine = lists:rmerge3([9,8,7],[6,5,4],[3,2,1]), - ?line Nine = lists:rmerge3([6,5,4],[9,8,7],[3,2,1]), - - ok. - -sort_1(doc) -> ["sort/1"]; -sort_1(suite) -> []; + [] = lists:rmerge3([], [], []), + Two = lists:rmerge3([], [], Two), + Two = lists:rmerge3([], Two, []), + Two = lists:rmerge3(Two, [], []), + Six = lists:rmerge3([], [5,3,1], [6,4,2]), + Six = lists:rmerge3([5,3,1], [], [6,4,2]), + Six = lists:rmerge3([5,3,1], [6,4,2], []), + Nine = lists:rmerge3([7,4,1],[8,5,2],[9,6,3]), + Nine = lists:rmerge3([7,4,1],[9,6,3],[8,5,2]), + Nine = lists:rmerge3([9,6,3],[7,4,1],[8,5,2]), + Nine = lists:rmerge3([6,5,4],[3,2,1],[9,8,7]), + Nine = lists:rmerge3([3,2,1],[6,5,4],[9,8,7]), + Nine = lists:rmerge3([9,8,7],[6,5,4],[3,2,1]), + Nine = lists:rmerge3([6,5,4],[9,8,7],[3,2,1]), + + ok. + sort_1(Config) when is_list(Config) -> - ?line [] = lists:sort([]), - ?line [a] = lists:sort([a]), - ?line [a,a] = lists:sort([a,a]), - ?line [a,b] = lists:sort([a,b]), - ?line [a,b] = lists:sort([b,a]), - ?line [1,1] = lists:sort([1,1]), - ?line [1,1,2,3] = lists:sort([1,1,3,2]), - ?line [1,2,3,3] = lists:sort([3,3,1,2]), - ?line [1,1,1,1] = lists:sort([1,1,1,1]), - ?line [1,1,1,2,2,2,3,3,3] = lists:sort([3,3,3,2,2,2,1,1,1]), - ?line [1,1,1,2,2,2,3,3,3] = lists:sort([1,1,1,2,2,2,3,3,3]), - - ?line lists:foreach(fun check/1, perms([1,2,3])), - ?line lists:foreach(fun check/1, perms([1,2,3,4,5,6,7,8])), - ok. - -sort_rand(doc) -> ["sort/1 on big randomized lists"]; -sort_rand(suite) -> []; + [] = lists:sort([]), + [a] = lists:sort([a]), + [a,a] = lists:sort([a,a]), + [a,b] = lists:sort([a,b]), + [a,b] = lists:sort([b,a]), + [1,1] = lists:sort([1,1]), + [1,1,2,3] = lists:sort([1,1,3,2]), + [1,2,3,3] = lists:sort([3,3,1,2]), + [1,1,1,1] = lists:sort([1,1,1,1]), + [1,1,1,2,2,2,3,3,3] = lists:sort([3,3,3,2,2,2,1,1,1]), + [1,1,1,2,2,2,3,3,3] = lists:sort([1,1,1,2,2,2,3,3,3]), + + lists:foreach(fun check/1, perms([1,2,3])), + lists:foreach(fun check/1, perms([1,2,3,4,5,6,7,8])), + ok. + +%% sort/1 on big randomized lists sort_rand(Config) when is_list(Config) -> - ?line ok = check(biglist(10)), - ?line ok = check(biglist(100)), - ?line ok = check(biglist(1000)), - ?line ok = check(biglist(10000)), + ok = check(biglist(10)), + ok = check(biglist(100)), + ok = check(biglist(1000)), + ok = check(biglist(10000)), ok. %% sort/1 was really stable for a while - the order of equal elements %% was kept - but since the performance suffered a bit, this "feature" %% was removed. -sort_stable(doc) -> ["sort/1 should be stable for equal terms."]; -sort_stable(suite) -> []; + +%% sort/1 should be stable for equal terms. sort_stable(Config) when is_list(Config) -> - ?line ok = check_stability(bigfunlist(10)), - ?line ok = check_stability(bigfunlist(100)), - ?line ok = check_stability(bigfunlist(1000)), - ?line case erlang:system_info(modified_timing_level) of - undefined -> ok = check_stability(bigfunlist(10000)); - _ -> ok - end, + ok = check_stability(bigfunlist(10)), + ok = check_stability(bigfunlist(100)), + ok = check_stability(bigfunlist(1000)), + case erlang:system_info(modified_timing_level) of + undefined -> ok = check_stability(bigfunlist(10000)); + _ -> ok + end, ok. check([]) -> @@ -619,188 +591,180 @@ expl_pid([], L) -> L. -usort_1(suite) -> []; -usort_1(doc) -> [""]; usort_1(Conf) when is_list(Conf) -> - ?line [] = lists:usort([]), - ?line [1] = lists:usort([1]), - ?line [1] = lists:usort([1,1]), - ?line [1] = lists:usort([1,1,1,1,1]), - ?line [1,2] = lists:usort([1,2]), - ?line [1,2] = lists:usort([1,2,1]), - ?line [1,2] = lists:usort([1,2,2]), - ?line [1,2,3] = lists:usort([1,3,2]), - ?line [1,3] = lists:usort([3,1,3]), - ?line [0,1,3] = lists:usort([3,1,0]), - ?line [1,2,3] = lists:usort([3,1,2]), - ?line [1,2] = lists:usort([2,1,1]), - ?line [1,2] = lists:usort([2,1]), - ?line [0,3,4,8,9] = lists:usort([3,8,9,0,9,4]), - - ?line lists:foreach(fun ucheck/1, perms([1,2,3])), - ?line lists:foreach(fun ucheck/1, perms([1,2,3,4,5,6,2,1])), - - ok. - -umerge(suite) -> []; -umerge(doc) -> [""]; + [] = lists:usort([]), + [1] = lists:usort([1]), + [1] = lists:usort([1,1]), + [1] = lists:usort([1,1,1,1,1]), + [1,2] = lists:usort([1,2]), + [1,2] = lists:usort([1,2,1]), + [1,2] = lists:usort([1,2,2]), + [1,2,3] = lists:usort([1,3,2]), + [1,3] = lists:usort([3,1,3]), + [0,1,3] = lists:usort([3,1,0]), + [1,2,3] = lists:usort([3,1,2]), + [1,2] = lists:usort([2,1,1]), + [1,2] = lists:usort([2,1]), + [0,3,4,8,9] = lists:usort([3,8,9,0,9,4]), + + lists:foreach(fun ucheck/1, perms([1,2,3])), + lists:foreach(fun ucheck/1, perms([1,2,3,4,5,6,2,1])), + + ok. + umerge(Conf) when is_list(Conf) -> %% merge list of lists - ?line [] = lists:umerge([]), - ?line [] = lists:umerge([[]]), - ?line [] = lists:umerge([[],[]]), - ?line [] = lists:umerge([[],[],[]]), - ?line [1] = lists:umerge([[1]]), - ?line [1,2] = lists:umerge([[1,2],[1,2]]), - ?line [1] = lists:umerge([[1],[],[]]), - ?line [1] = lists:umerge([[],[1],[]]), - ?line [1] = lists:umerge([[],[],[1]]), - ?line [1,2] = lists:umerge([[1],[2],[]]), - ?line [1,2] = lists:umerge([[1],[],[2]]), - ?line [1,2] = lists:umerge([[],[1],[2]]), - ?line [1,2,3,4,5,6] = lists:umerge([[1,2],[],[5,6],[],[3,4],[]]), - ?line [1,2,3,4] = lists:umerge([[4],[3],[2],[1]]), - ?line [1,2,3,4,5] = lists:umerge([[1],[2],[3],[4],[5]]), - ?line [1,2,3,4,5,6] = lists:umerge([[1],[2],[3],[4],[5],[6]]), - ?line [1,2,3,4,5,6,7,8,9] = + [] = lists:umerge([]), + [] = lists:umerge([[]]), + [] = lists:umerge([[],[]]), + [] = lists:umerge([[],[],[]]), + [1] = lists:umerge([[1]]), + [1,2] = lists:umerge([[1,2],[1,2]]), + [1] = lists:umerge([[1],[],[]]), + [1] = lists:umerge([[],[1],[]]), + [1] = lists:umerge([[],[],[1]]), + [1,2] = lists:umerge([[1],[2],[]]), + [1,2] = lists:umerge([[1],[],[2]]), + [1,2] = lists:umerge([[],[1],[2]]), + [1,2,3,4,5,6] = lists:umerge([[1,2],[],[5,6],[],[3,4],[]]), + [1,2,3,4] = lists:umerge([[4],[3],[2],[1]]), + [1,2,3,4,5] = lists:umerge([[1],[2],[3],[4],[5]]), + [1,2,3,4,5,6] = lists:umerge([[1],[2],[3],[4],[5],[6]]), + [1,2,3,4,5,6,7,8,9] = lists:umerge([[1],[2],[3],[4],[5],[6],[7],[8],[9]]), - ?line [1,2,4,6,8] = lists:umerge([[1,2],[2,4,6,8]]), + [1,2,4,6,8] = lists:umerge([[1,2],[2,4,6,8]]), Seq = lists:seq(1,100), - ?line true = Seq == lists:umerge(lists:map(fun(E) -> [E] end, Seq)), + true = Seq == lists:umerge(lists:map(fun(E) -> [E] end, Seq)), Two = [1,2], Six = [1,2,3,4,5,6], %% 2-way unique merge - ?line [] = lists:umerge([], []), - ?line Two = lists:umerge(Two, []), - ?line Two = lists:umerge([], Two), - ?line Six = lists:umerge([1,3,5], [2,4,6]), - ?line Six = lists:umerge([2,4,6], [1,3,5]), - ?line Six = lists:umerge([1,2,3], [4,5,6]), - ?line Six = lists:umerge([4,5,6], [1,2,3]), - ?line Six = lists:umerge([1,2,5],[3,4,6]), - ?line [1,2,3,5,7] = lists:umerge([1,3,5,7], [2]), - ?line [1,2,3,4,5,7] = lists:umerge([1,3,5,7], [2,4]), - ?line [1,2,3,4,5,6,7] = lists:umerge([1,3,5,7], [2,4,6]), - ?line [1,2,3,5,7] = lists:umerge([2], [1,3,5,7]), - ?line [1,2,3,4,5,7] = lists:umerge([2,4], [1,3,5,7]), - ?line [1,2,3,4,5,6,7] = lists:umerge([2,4,6], [1,3,5,7]), - - ?line [1,2,3,5,7] = lists:umerge([1,2,3,5,7], [2]), - ?line [1,2,3,4,5,7] = lists:umerge([1,2,3,4,5,7], [2,4]), - ?line [1,2,3,4,5,6,7] = lists:umerge([1,2,3,4,5,6,7], [2,4,6]), - ?line [1,2,3,5,7] = lists:umerge([2], [1,2,3,5,7]), - ?line [1,2,3,4,5,7] = lists:umerge([2,4], [1,2,3,4,5,7]), - ?line [1,2,3,4,5,6,7] = lists:umerge([2,4,6], [1,2,3,4,5,6,7]), + [] = lists:umerge([], []), + Two = lists:umerge(Two, []), + Two = lists:umerge([], Two), + Six = lists:umerge([1,3,5], [2,4,6]), + Six = lists:umerge([2,4,6], [1,3,5]), + Six = lists:umerge([1,2,3], [4,5,6]), + Six = lists:umerge([4,5,6], [1,2,3]), + Six = lists:umerge([1,2,5],[3,4,6]), + [1,2,3,5,7] = lists:umerge([1,3,5,7], [2]), + [1,2,3,4,5,7] = lists:umerge([1,3,5,7], [2,4]), + [1,2,3,4,5,6,7] = lists:umerge([1,3,5,7], [2,4,6]), + [1,2,3,5,7] = lists:umerge([2], [1,3,5,7]), + [1,2,3,4,5,7] = lists:umerge([2,4], [1,3,5,7]), + [1,2,3,4,5,6,7] = lists:umerge([2,4,6], [1,3,5,7]), + + [1,2,3,5,7] = lists:umerge([1,2,3,5,7], [2]), + [1,2,3,4,5,7] = lists:umerge([1,2,3,4,5,7], [2,4]), + [1,2,3,4,5,6,7] = lists:umerge([1,2,3,4,5,6,7], [2,4,6]), + [1,2,3,5,7] = lists:umerge([2], [1,2,3,5,7]), + [1,2,3,4,5,7] = lists:umerge([2,4], [1,2,3,4,5,7]), + [1,2,3,4,5,6,7] = lists:umerge([2,4,6], [1,2,3,4,5,6,7]), %% 3-way unique merge - ?line [] = lists:umerge3([], [], []), - ?line Two = lists:umerge3([], [], Two), - ?line Two = lists:umerge3([], Two, []), - ?line Two = lists:umerge3(Two, [], []), - ?line Six = lists:umerge3([], [1,3,5], [2,4,6]), - ?line Six = lists:umerge3([1,3,5], [], [2,4,6]), - ?line Six = lists:umerge3([1,3,5], [2,4,6], []), - ?line Nine = lists:umerge3([1,4,7],[2,5,8],[3,6,9]), - ?line Nine = lists:umerge3([1,4,7],[3,6,9],[2,5,8]), - ?line Nine = lists:umerge3([3,6,9],[1,4,7],[2,5,8]), - ?line Nine = lists:umerge3([4,5,6],[1,2,3],[7,8,9]), - ?line Nine = lists:umerge3([1,2,3],[4,5,6],[7,8,9]), - ?line Nine = lists:umerge3([7,8,9],[4,5,6],[1,2,3]), - ?line Nine = lists:umerge3([4,5,6],[7,8,9],[1,2,3]), - - ?line [1,2,3] = lists:umerge3([1,2,3],[1,2,3],[1,2,3]), - ?line [1,2,3,4] = lists:umerge3([2,3,4],[1,2,3],[2,3,4]), - ?line [1,2,3] = lists:umerge3([1,2,3],[2,3],[1,2,3]), - ?line [1,2,3,4] = lists:umerge3([2,3,4],[3,4],[1,2,3]), - - ok. - -rumerge(suite) -> []; -rumerge(doc) -> [""]; + [] = lists:umerge3([], [], []), + Two = lists:umerge3([], [], Two), + Two = lists:umerge3([], Two, []), + Two = lists:umerge3(Two, [], []), + Six = lists:umerge3([], [1,3,5], [2,4,6]), + Six = lists:umerge3([1,3,5], [], [2,4,6]), + Six = lists:umerge3([1,3,5], [2,4,6], []), + Nine = lists:umerge3([1,4,7],[2,5,8],[3,6,9]), + Nine = lists:umerge3([1,4,7],[3,6,9],[2,5,8]), + Nine = lists:umerge3([3,6,9],[1,4,7],[2,5,8]), + Nine = lists:umerge3([4,5,6],[1,2,3],[7,8,9]), + Nine = lists:umerge3([1,2,3],[4,5,6],[7,8,9]), + Nine = lists:umerge3([7,8,9],[4,5,6],[1,2,3]), + Nine = lists:umerge3([4,5,6],[7,8,9],[1,2,3]), + + [1,2,3] = lists:umerge3([1,2,3],[1,2,3],[1,2,3]), + [1,2,3,4] = lists:umerge3([2,3,4],[1,2,3],[2,3,4]), + [1,2,3] = lists:umerge3([1,2,3],[2,3],[1,2,3]), + [1,2,3,4] = lists:umerge3([2,3,4],[3,4],[1,2,3]), + + ok. + rumerge(Conf) when is_list(Conf) -> Two = [2,1], Six = [6,5,4,3,2,1], %% 2-way reversed unique merge - ?line [] = lists:rumerge([], []), - ?line Two = lists:rumerge(Two, []), - ?line Two = lists:rumerge([], Two), - ?line Six = lists:rumerge([5,3,1], [6,4,2]), - ?line Six = lists:rumerge([6,4,2], [5,3,1]), - ?line Six = lists:rumerge([3,2,1], [6,5,4]), - ?line Six = lists:rumerge([6,5,4], [3,2,1]), - ?line Six = lists:rumerge([4,3,2],[6,5,1]), - ?line [7,6,5,3,1] = lists:rumerge([7,5,3,1], [6]), - ?line [7,6,5,4,3,1] = lists:rumerge([7,5,3,1], [6,4]), - ?line [7,6,5,4,3,2,1] = lists:rumerge([7,5,3,1], [6,4,2]), - ?line [7,5,3,2,1] = lists:rumerge([2], [7,5,3,1]), - ?line [7,5,4,3,2,1] = lists:rumerge([4,2], [7,5,3,1]), - ?line [7,6,5,4,3,2,1] = lists:rumerge([6,4,2], [7,5,3,1]), - - ?line [7,6,5,3,1] = lists:rumerge([7,6,5,3,1], [6]), - ?line [7,6,5,4,3,1] = lists:rumerge([7,6,5,4,3,1], [6,4]), - ?line [7,6,5,4,3,2,1] = lists:rumerge([7,6,5,4,3,2,1], [6,4,2]), - ?line [7,5,3,2,1] = lists:rumerge([2], [7,5,3,2,1]), - ?line [7,5,4,3,2,1] = lists:rumerge([4,2], [7,5,4,3,2,1]), - ?line [7,6,5,4,3,2,1] = lists:rumerge([6,4,2], [7,6,5,4,3,2,1]), + [] = lists:rumerge([], []), + Two = lists:rumerge(Two, []), + Two = lists:rumerge([], Two), + Six = lists:rumerge([5,3,1], [6,4,2]), + Six = lists:rumerge([6,4,2], [5,3,1]), + Six = lists:rumerge([3,2,1], [6,5,4]), + Six = lists:rumerge([6,5,4], [3,2,1]), + Six = lists:rumerge([4,3,2],[6,5,1]), + [7,6,5,3,1] = lists:rumerge([7,5,3,1], [6]), + [7,6,5,4,3,1] = lists:rumerge([7,5,3,1], [6,4]), + [7,6,5,4,3,2,1] = lists:rumerge([7,5,3,1], [6,4,2]), + [7,5,3,2,1] = lists:rumerge([2], [7,5,3,1]), + [7,5,4,3,2,1] = lists:rumerge([4,2], [7,5,3,1]), + [7,6,5,4,3,2,1] = lists:rumerge([6,4,2], [7,5,3,1]), + + [7,6,5,3,1] = lists:rumerge([7,6,5,3,1], [6]), + [7,6,5,4,3,1] = lists:rumerge([7,6,5,4,3,1], [6,4]), + [7,6,5,4,3,2,1] = lists:rumerge([7,6,5,4,3,2,1], [6,4,2]), + [7,5,3,2,1] = lists:rumerge([2], [7,5,3,2,1]), + [7,5,4,3,2,1] = lists:rumerge([4,2], [7,5,4,3,2,1]), + [7,6,5,4,3,2,1] = lists:rumerge([6,4,2], [7,6,5,4,3,2,1]), Nine = [9,8,7,6,5,4,3,2,1], %% 3-way reversed unique merge - ?line [] = lists:rumerge3([], [], []), - ?line Two = lists:rumerge3([], [], Two), - ?line Two = lists:rumerge3([], Two, []), - ?line Two = lists:rumerge3(Two, [], []), - ?line Six = lists:rumerge3([], [5,3,1], [6,4,2]), - ?line Six = lists:rumerge3([5,3,1], [], [6,4,2]), - ?line Six = lists:rumerge3([5,3,1], [6,4,2], []), - ?line Nine = lists:rumerge3([7,4,1],[8,5,2],[9,6,3]), - ?line Nine = lists:rumerge3([7,4,1],[9,6,3],[8,5,2]), - ?line Nine = lists:rumerge3([9,6,3],[7,4,1],[8,5,2]), - ?line Nine = lists:rumerge3([6,5,4],[3,2,1],[9,8,7]), - ?line Nine = lists:rumerge3([3,2,1],[6,5,4],[9,8,7]), - ?line Nine = lists:rumerge3([9,8,7],[6,5,4],[3,2,1]), - ?line Nine = lists:rumerge3([6,5,4],[9,8,7],[3,2,1]), - - ?line [3,2,1] = lists:rumerge3([3,2,1],[3,2,1],[3,2,1]), - ?line [4,3,2,1] = lists:rumerge3([4,3,2],[3,2,1],[3,2,1]), - ?line [5,4,3,2,1] = lists:rumerge3([4,3,2],[5,4,3,2],[5,4,3,2,1]), - ?line [6,5,4,3,2] = lists:rumerge3([4,3,2],[5,4,3,2],[6,5,4,3]), + [] = lists:rumerge3([], [], []), + Two = lists:rumerge3([], [], Two), + Two = lists:rumerge3([], Two, []), + Two = lists:rumerge3(Two, [], []), + Six = lists:rumerge3([], [5,3,1], [6,4,2]), + Six = lists:rumerge3([5,3,1], [], [6,4,2]), + Six = lists:rumerge3([5,3,1], [6,4,2], []), + Nine = lists:rumerge3([7,4,1],[8,5,2],[9,6,3]), + Nine = lists:rumerge3([7,4,1],[9,6,3],[8,5,2]), + Nine = lists:rumerge3([9,6,3],[7,4,1],[8,5,2]), + Nine = lists:rumerge3([6,5,4],[3,2,1],[9,8,7]), + Nine = lists:rumerge3([3,2,1],[6,5,4],[9,8,7]), + Nine = lists:rumerge3([9,8,7],[6,5,4],[3,2,1]), + Nine = lists:rumerge3([6,5,4],[9,8,7],[3,2,1]), + + [3,2,1] = lists:rumerge3([3,2,1],[3,2,1],[3,2,1]), + [4,3,2,1] = lists:rumerge3([4,3,2],[3,2,1],[3,2,1]), + [5,4,3,2,1] = lists:rumerge3([4,3,2],[5,4,3,2],[5,4,3,2,1]), + [6,5,4,3,2] = lists:rumerge3([4,3,2],[5,4,3,2],[6,5,4,3]), L1 = [c,d,e], L2 = [b,c,d], - ?line true = + true = lists:umerge(L1, L2) == lists:reverse(lists:rumerge(lists:reverse(L1), lists:reverse(L2))), ok. -usort_rand(doc) -> ["usort/1 on big randomized lists"]; -usort_rand(suite) -> []; +%% usort/1 on big randomized lists. usort_rand(Config) when is_list(Config) -> - ?line ok = ucheck(biglist(10)), - ?line ok = ucheck(biglist(100)), - ?line ok = ucheck(biglist(1000)), - ?line ok = ucheck(biglist(10000)), + ok = ucheck(biglist(10)), + ok = ucheck(biglist(100)), + ok = ucheck(biglist(1000)), + ok = ucheck(biglist(10000)), - ?line ok = ucheck(ubiglist(10)), - ?line ok = ucheck(ubiglist(100)), - ?line ok = ucheck(ubiglist(1000)), - ?line ok = ucheck(ubiglist(10000)), + ok = ucheck(ubiglist(10)), + ok = ucheck(ubiglist(100)), + ok = ucheck(ubiglist(1000)), + ok = ucheck(ubiglist(10000)), ok. -usort_stable(doc) -> ["usort/1 should keep the first duplicate."]; -usort_stable(suite) -> []; +%% usort/1 should keep the first duplicate. usort_stable(Config) when is_list(Config) -> - ?line ok = ucheck_stability(bigfunlist(3)), - ?line ok = ucheck_stability(bigfunlist(10)), - ?line ok = ucheck_stability(bigfunlist(100)), - ?line ok = ucheck_stability(bigfunlist(1000)), - ?line case erlang:system_info(modified_timing_level) of - undefined -> ok = ucheck_stability(bigfunlist(10000)); - _ -> ok - end, + ok = ucheck_stability(bigfunlist(3)), + ok = ucheck_stability(bigfunlist(10)), + ok = ucheck_stability(bigfunlist(100)), + ok = ucheck_stability(bigfunlist(1000)), + case erlang:system_info(modified_timing_level) of + undefined -> ok = ucheck_stability(bigfunlist(10000)); + _ -> ok + end, ok. ucheck([]) -> @@ -829,163 +793,155 @@ ucheck_stability(L) -> check_stab(L, U, S, "usort/1", "ukeysort/2"). -keymerge(doc) -> ["Key merge two lists."]; -keymerge(suite) -> []; +%% Key merge two lists. keymerge(Config) when is_list(Config) -> Two = [{1,a},{2,b}], Six = [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f}], %% 2-way keymerge - ?line [] = lists:keymerge(1, [], []), - ?line Two = lists:keymerge(1, Two, []), - ?line Two = lists:keymerge(1, [], Two), - ?line Six = lists:keymerge(1, [{1,a},{3,c},{5,e}], [{2,b},{4,d},{6,f}]), - ?line Six = lists:keymerge(1, [{2,b},{4,d},{6,f}], [{1,a},{3,c},{5,e}]), - ?line Six = lists:keymerge(1, [{1,a},{2,b},{3,c}], [{4,d},{5,e},{6,f}]), - ?line Six = lists:keymerge(1, [{4,d},{5,e},{6,f}], [{1,a},{2,b},{3,c}]), - ?line Six = lists:keymerge(1, [{1,a},{2,b},{5,e}],[{3,c},{4,d},{6,f}]), - ?line [{1,a},{2,b},{3,c},{5,e},{7,g}] = + [] = lists:keymerge(1, [], []), + Two = lists:keymerge(1, Two, []), + Two = lists:keymerge(1, [], Two), + Six = lists:keymerge(1, [{1,a},{3,c},{5,e}], [{2,b},{4,d},{6,f}]), + Six = lists:keymerge(1, [{2,b},{4,d},{6,f}], [{1,a},{3,c},{5,e}]), + Six = lists:keymerge(1, [{1,a},{2,b},{3,c}], [{4,d},{5,e},{6,f}]), + Six = lists:keymerge(1, [{4,d},{5,e},{6,f}], [{1,a},{2,b},{3,c}]), + Six = lists:keymerge(1, [{1,a},{2,b},{5,e}],[{3,c},{4,d},{6,f}]), + [{1,a},{2,b},{3,c},{5,e},{7,g}] = lists:keymerge(1, [{1,a},{3,c},{5,e},{7,g}], [{2,b}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = lists:keymerge(1, [{1,a},{3,c},{5,e},{7,g}], [{2,b},{4,d}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = lists:keymerge(1, [{1,a},{3,c},{5,e},{7,g}], [{2,b},{4,d},{6,f}]), - ?line [{1,a},{2,b},{3,c},{5,e},{7,g}] = + [{1,a},{2,b},{3,c},{5,e},{7,g}] = lists:keymerge(1, [{2,b}], [{1,a},{3,c},{5,e},{7,g}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = lists:keymerge(1, [{2,b},{4,d}], [{1,a},{3,c},{5,e},{7,g}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = lists:keymerge(1, [{2,b},{4,d},{6,f}], [{1,a},{3,c},{5,e},{7,g}]), - ?line [{b,2},{c,11},{c,12},{c,21},{c,22},{e,5}] = + [{b,2},{c,11},{c,12},{c,21},{c,22},{e,5}] = lists:keymerge(1,[{c,11},{c,12},{e,5}], [{b,2},{c,21},{c,22}]), ok. -rkeymerge(doc) -> ["Reverse key merge two lists."]; -rkeymerge(suite) -> []; +%% Reverse key merge two lists. rkeymerge(Config) when is_list(Config) -> Two = [{2,b},{1,a}], Six = [{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}], %% 2-way reversed keymerge - ?line [] = lists:rkeymerge(1, [], []), - ?line Two = lists:rkeymerge(1, Two, []), - ?line Two = lists:rkeymerge(1, [], Two), - ?line Six = lists:rkeymerge(1, [{5,e},{3,c},{1,a}], [{6,f},{4,d},{2,b}]), - ?line Six = lists:rkeymerge(1, [{6,f},{4,d},{2,b}], [{5,e},{3,c},{1,a}]), - ?line Six = lists:rkeymerge(1, [{3,c},{2,b},{1,a}], [{6,f},{5,e},{4,d}]), - ?line Six = lists:rkeymerge(1, [{6,f},{5,e},{4,d}], [{3,c},{2,b},{1,a}]), - ?line Six = lists:rkeymerge(1, [{4,d},{3,c},{2,b}],[{6,f},{5,e},{1,a}]), - ?line [{7,g},{6,f},{5,e},{3,c},{1,a}] = + [] = lists:rkeymerge(1, [], []), + Two = lists:rkeymerge(1, Two, []), + Two = lists:rkeymerge(1, [], Two), + Six = lists:rkeymerge(1, [{5,e},{3,c},{1,a}], [{6,f},{4,d},{2,b}]), + Six = lists:rkeymerge(1, [{6,f},{4,d},{2,b}], [{5,e},{3,c},{1,a}]), + Six = lists:rkeymerge(1, [{3,c},{2,b},{1,a}], [{6,f},{5,e},{4,d}]), + Six = lists:rkeymerge(1, [{6,f},{5,e},{4,d}], [{3,c},{2,b},{1,a}]), + Six = lists:rkeymerge(1, [{4,d},{3,c},{2,b}],[{6,f},{5,e},{1,a}]), + [{7,g},{6,f},{5,e},{3,c},{1,a}] = lists:rkeymerge(1, [{7,g},{5,e},{3,c},{1,a}], [{6,f}]), - ?line [{7,g},{6,f},{5,e},{4,d},{3,c},{1,a}] = + [{7,g},{6,f},{5,e},{4,d},{3,c},{1,a}] = lists:rkeymerge(1, [{7,g},{5,e},{3,c},{1,a}], [{6,f},{4,d}]), - ?line [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = + [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = lists:rkeymerge(1, [{7,g},{5,e},{3,c},{1,a}], [{6,f},{4,d},{2,b}]), - ?line [{7,g},{5,e},{3,c},{2,b},{1,a}] = + [{7,g},{5,e},{3,c},{2,b},{1,a}] = lists:rkeymerge(1, [{2,b}], [{7,g},{5,e},{3,c},{1,a}]), - ?line [{7,g},{5,e},{4,d},{3,c},{2,b},{1,a}] = + [{7,g},{5,e},{4,d},{3,c},{2,b},{1,a}] = lists:rkeymerge(1, [{4,d},{2,b}], [{7,g},{5,e},{3,c},{1,a}]), - ?line [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = + [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = lists:rkeymerge(1, [{6,f},{4,d},{2,b}], [{7,g},{5,e},{3,c},{1,a}]), L1 = [{c,11},{c,12},{e,5}], L2 = [{b,2},{c,21},{c,22}], - ?line true = + true = lists:keymerge(1, L1, L2) == lists:reverse(lists:rkeymerge(1,lists:reverse(L1), lists:reverse(L2))), ok. -keysort_1(doc) -> ["keysort"]; -keysort_1(suite) -> []; keysort_1(Config) when is_list(Config) -> - ?line ok = keysort_check(1, [], []), - ?line ok = keysort_check(1, [{a,b}], [{a,b}]), - ?line ok = keysort_check(1, [{a,b},{a,b}], [{a,b},{a,b}]), - ?line ok = keysort_check(1, [{a,b},{b,c}], [{a,b},{b,c}]), - ?line ok = keysort_check(1, [{b,c},{a,b}], [{a,b},{b,c}]), - ?line ok = keysort_check(1, - [{1,e},{3,f},{2,y},{0,z},{x,14}], - [{0,z},{1,e},{2,y},{3,f},{x,14}]), - ?line ok = keysort_check(1, - [{1,a},{1,a},{1,a},{1,a}], - [{1,a},{1,a},{1,a},{1,a}]), - - ?line [{b,1},{c,1}] = lists:keysort(1, [{c,1},{b,1}]), - ?line [{a,0},{b,2},{c,3},{d,4}] = - lists:keysort(1, [{d,4},{c,3},{b,2},{a,0}]), - ?line [{a,0},{b,1},{b,2},{c,1}] = - lists:keysort(1, [{c,1},{b,1},{b,2},{a,0}]), - ?line [{a,0},{b,1},{b,2},{c,1},{d,4}] = - lists:keysort(1, [{c,1},{b,1},{b,2},{a,0},{d,4}]), + ok = keysort_check(1, [], []), + ok = keysort_check(1, [{a,b}], [{a,b}]), + ok = keysort_check(1, [{a,b},{a,b}], [{a,b},{a,b}]), + ok = keysort_check(1, [{a,b},{b,c}], [{a,b},{b,c}]), + ok = keysort_check(1, [{b,c},{a,b}], [{a,b},{b,c}]), + ok = keysort_check(1, + [{1,e},{3,f},{2,y},{0,z},{x,14}], + [{0,z},{1,e},{2,y},{3,f},{x,14}]), + ok = keysort_check(1, + [{1,a},{1,a},{1,a},{1,a}], + [{1,a},{1,a},{1,a},{1,a}]), + + [{b,1},{c,1}] = lists:keysort(1, [{c,1},{b,1}]), + [{a,0},{b,2},{c,3},{d,4}] = + lists:keysort(1, [{d,4},{c,3},{b,2},{a,0}]), + [{a,0},{b,1},{b,2},{c,1}] = + lists:keysort(1, [{c,1},{b,1},{b,2},{a,0}]), + [{a,0},{b,1},{b,2},{c,1},{d,4}] = + lists:keysort(1, [{c,1},{b,1},{b,2},{a,0},{d,4}]), SFun = fun(L) -> fun(X) -> keysort_check(1, X, L) end end, L1 = [{1,a},{2,b},{3,c}], - ?line lists:foreach(SFun(L1), perms(L1)), + lists:foreach(SFun(L1), perms(L1)), L2 = [{1,a},{1,a},{2,b}], - ?line lists:foreach(SFun(L2), perms(L2)), + lists:foreach(SFun(L2), perms(L2)), L3 = [{1,a},{1,a},{1,a},{2,b}], - ?line lists:foreach(SFun(L3), perms(L3)), + lists:foreach(SFun(L3), perms(L3)), L4 = [{a,1},{a,1},{b,2},{b,2},{c,3},{d,4},{e,5},{f,6}], - ?line lists:foreach(SFun(L4), perms(L4)), + lists:foreach(SFun(L4), perms(L4)), ok. -keysort_stable(doc) -> ["keysort should be stable"]; -keysort_stable(suite) -> []; +%% keysort should be stable keysort_stable(Config) when is_list(Config) -> - ?line ok = keysort_check(1, [{1,b},{1,c}], [{1,b},{1,c}]), - ?line ok = keysort_check(1, [{1,c},{1,b}], [{1,c},{1,b}]), - ?line ok = keysort_check(1, - [{1,c},{1,b},{2,x},{3,p},{2,a}], - [{1,c},{1,b},{2,x},{2,a},{3,p}]), - ?line ok = keysort_check(1, - [{1,a},{1,b},{1,a},{1,a}], - [{1,a},{1,b},{1,a},{1,a}]), - ok. - -keysort_error(doc) -> ["keysort should exit when given bad arguments"]; -keysort_error(suite) -> []; + ok = keysort_check(1, [{1,b},{1,c}], [{1,b},{1,c}]), + ok = keysort_check(1, [{1,c},{1,b}], [{1,c},{1,b}]), + ok = keysort_check(1, + [{1,c},{1,b},{2,x},{3,p},{2,a}], + [{1,c},{1,b},{2,x},{2,a},{3,p}]), + ok = keysort_check(1, + [{1,a},{1,b},{1,a},{1,a}], + [{1,a},{1,b},{1,a},{1,a}]), + ok. + +%% keysort should exit when given bad arguments keysort_error(Config) when is_list(Config) -> - ?line {'EXIT', _} = (catch lists:keysort(0, [{1,b},{1,c}])), - ?line {'EXIT', _} = (catch lists:keysort(3, [{1,b},{1,c}])), - ?line {'EXIT', _} = (catch lists:keysort(1.5, [{1,b},{1,c}])), - ?line {'EXIT', _} = (catch lists:keysort(x, [{1,b},{1,c}])), - ?line {'EXIT', _} = (catch lists:keysort(x, [])), - ?line {'EXIT', _} = (catch lists:keysort(x, [{1,b}])), - ?line {'EXIT', _} = (catch lists:keysort(1, [a,b])), - ?line {'EXIT', _} = (catch lists:keysort(1, [{1,b} | {1,c}])), - ok. - -keysort_i(doc) -> ["keysort with other key than first element"]; -keysort_i(suite) -> []; + {'EXIT', _} = (catch lists:keysort(0, [{1,b},{1,c}])), + {'EXIT', _} = (catch lists:keysort(3, [{1,b},{1,c}])), + {'EXIT', _} = (catch lists:keysort(1.5, [{1,b},{1,c}])), + {'EXIT', _} = (catch lists:keysort(x, [{1,b},{1,c}])), + {'EXIT', _} = (catch lists:keysort(x, [])), + {'EXIT', _} = (catch lists:keysort(x, [{1,b}])), + {'EXIT', _} = (catch lists:keysort(1, [a,b])), + {'EXIT', _} = (catch lists:keysort(1, [{1,b} | {1,c}])), + ok. + +%% keysort with other key than first element keysort_i(Config) when is_list(Config) -> - ?line ok = keysort_check(2, [{a,2},{b,1},{c,3}], [{b,1},{a,2},{c,3}]), + ok = keysort_check(2, [{a,2},{b,1},{c,3}], [{b,1},{a,2},{c,3}]), ok. -keysort_rand(doc) -> ["keysort on big randomized lists"]; -keysort_rand(suite) -> []; +%% keysort on big randomized lists keysort_rand(Config) when is_list(Config) -> - ?line ok = keysort_check3(1, biglist(10)), - ?line ok = keysort_check3(1, biglist(100)), - ?line ok = keysort_check3(1, biglist(1000)), - ?line ok = keysort_check3(1, biglist(10000)), + ok = keysort_check3(1, biglist(10)), + ok = keysort_check3(1, biglist(100)), + ok = keysort_check3(1, biglist(1000)), + ok = keysort_check3(1, biglist(10000)), - ?line ok = keysort_check3(2, biglist(10)), - ?line ok = keysort_check3(2, biglist(100)), - ?line ok = keysort_check3(2, biglist(1000)), - ?line ok = keysort_check3(2, biglist(10000)), + ok = keysort_check3(2, biglist(10)), + ok = keysort_check3(2, biglist(100)), + ok = keysort_check3(2, biglist(1000)), + ok = keysort_check3(2, biglist(10000)), ok. %%% Keysort a list, check that the returned list is what we expected, %%% and that it is actually sorted. keysort_check(I, Input, Expected) -> - ?line Expected = lists:keysort(I, Input), + Expected = lists:keysort(I, Input), check_sorted(I, Input, Expected). keysort_check3(I, Input) -> @@ -1020,232 +976,223 @@ keycompare(I, J, A, B) when element(I, A) == element(I, B), ok. -ukeymerge(suite) -> []; -ukeymerge(doc) -> ["Merge two lists while removing duplicates."]; +%% Merge two lists while removing duplicates. ukeymerge(Conf) when is_list(Conf) -> Two = [{1,a},{2,b}], Six = [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f}], %% 2-way unique keymerge - ?line [] = lists:ukeymerge(1, [], []), - ?line Two = lists:ukeymerge(1, Two, []), - ?line Two = lists:ukeymerge(1, [], Two), - ?line [] = lists:ukeymerge(1, [], []), - ?line Two = lists:ukeymerge(1, Two, []), - ?line Two = lists:ukeymerge(1, [], Two), - ?line Six = lists:ukeymerge(1, [{1,a},{3,c},{5,e}], [{2,b},{4,d},{6,f}]), - ?line Six = lists:ukeymerge(1, [{2,b},{4,d},{6,f}], [{1,a},{3,c},{5,e}]), - ?line Six = lists:ukeymerge(1, [{1,a},{2,b},{3,c}], [{4,d},{5,e},{6,f}]), - ?line Six = lists:ukeymerge(1, [{4,d},{5,e},{6,f}], [{1,a},{2,b},{3,c}]), - ?line Six = lists:ukeymerge(1, [{1,a},{2,b},{5,e}],[{3,c},{4,d},{6,f}]), - ?line [{1,a},{2,b},{3,c},{5,e},{7,g}] = + [] = lists:ukeymerge(1, [], []), + Two = lists:ukeymerge(1, Two, []), + Two = lists:ukeymerge(1, [], Two), + [] = lists:ukeymerge(1, [], []), + Two = lists:ukeymerge(1, Two, []), + Two = lists:ukeymerge(1, [], Two), + Six = lists:ukeymerge(1, [{1,a},{3,c},{5,e}], [{2,b},{4,d},{6,f}]), + Six = lists:ukeymerge(1, [{2,b},{4,d},{6,f}], [{1,a},{3,c},{5,e}]), + Six = lists:ukeymerge(1, [{1,a},{2,b},{3,c}], [{4,d},{5,e},{6,f}]), + Six = lists:ukeymerge(1, [{4,d},{5,e},{6,f}], [{1,a},{2,b},{3,c}]), + Six = lists:ukeymerge(1, [{1,a},{2,b},{5,e}],[{3,c},{4,d},{6,f}]), + [{1,a},{2,b},{3,c},{5,e},{7,g}] = lists:ukeymerge(1, [{1,a},{3,c},{5,e},{7,g}], [{2,b}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = lists:ukeymerge(1, [{1,a},{3,c},{5,e},{7,g}], [{2,b},{4,d}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = lists:ukeymerge(1, [{1,a},{3,c},{5,e},{7,g}], [{2,b},{4,d},{6,f}]), - ?line [{1,a},{2,b},{3,c},{5,e},{7,g}] = + [{1,a},{2,b},{3,c},{5,e},{7,g}] = lists:ukeymerge(1, [{2,b}], [{1,a},{3,c},{5,e},{7,g}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = lists:ukeymerge(1, [{2,b},{4,d}], [{1,a},{3,c},{5,e},{7,g}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = lists:ukeymerge(1, [{2,b},{4,d},{6,f}], [{1,a},{3,c},{5,e},{7,g}]), - ?line [{1,a},{2,b},{3,c},{5,e},{7,g}] = + [{1,a},{2,b},{3,c},{5,e},{7,g}] = lists:ukeymerge(1, [{1,a},{2,b},{3,c},{5,e},{7,g}], [{2,b}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = lists:ukeymerge(1, [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}], [{2,b},{4,d}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = lists:ukeymerge(1, [{1,a},{3,c},{5,e},{6,f},{7,g}], [{2,b},{4,d},{6,f}]), - ?line [{1,a},{2,b},{3,c},{5,e},{7,g}] = + [{1,a},{2,b},{3,c},{5,e},{7,g}] = lists:ukeymerge(1, [{2,b}], [{1,a},{2,b},{3,c},{5,e},{7,g}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}] = lists:ukeymerge(1, [{2,b},{4,d}], [{1,a},{2,b},{3,c},{4,d},{5,e},{7,g}]), - ?line [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = + [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}] = lists:ukeymerge(1, [{2,b},{4,d},{6,f}], - [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}]), + [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{7,g}]), L1 = [{a,1},{a,3},{a,5},{a,7}], L2 = [{b,1},{b,3},{b,5},{b,7}], - ?line L1 = lists:ukeymerge(2, L1, L2), + L1 = lists:ukeymerge(2, L1, L2), ok. -rukeymerge(suite) -> []; -rukeymerge(doc) -> - ["Reverse merge two lists while removing duplicates."]; +%% Reverse merge two lists while removing duplicates. rukeymerge(Conf) when is_list(Conf) -> Two = [{2,b},{1,a}], Six = [{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}], %% 2-way reversed unique keymerge - ?line [] = lists:rukeymerge(1, [], []), - ?line Two = lists:rukeymerge(1, Two, []), - ?line Two = lists:rukeymerge(1, [], Two), - ?line Six = lists:rukeymerge(1, [{5,e},{3,c},{1,a}], [{6,f},{4,d},{2,b}]), - ?line Six = lists:rukeymerge(1, [{6,f},{4,d},{2,b}], [{5,e},{3,c},{1,a}]), - ?line Six = lists:rukeymerge(1, [{3,c},{2,b},{1,a}], [{6,f},{5,e},{4,d}]), - ?line Six = lists:rukeymerge(1, [{6,f},{5,e},{4,d}], [{3,c},{2,b},{1,a}]), - ?line Six = lists:rukeymerge(1, [{4,d},{3,c},{2,b}],[{6,f},{5,e},{1,a}]), - ?line [{7,g},{6,f},{5,e},{3,c},{1,a}] = + [] = lists:rukeymerge(1, [], []), + Two = lists:rukeymerge(1, Two, []), + Two = lists:rukeymerge(1, [], Two), + Six = lists:rukeymerge(1, [{5,e},{3,c},{1,a}], [{6,f},{4,d},{2,b}]), + Six = lists:rukeymerge(1, [{6,f},{4,d},{2,b}], [{5,e},{3,c},{1,a}]), + Six = lists:rukeymerge(1, [{3,c},{2,b},{1,a}], [{6,f},{5,e},{4,d}]), + Six = lists:rukeymerge(1, [{6,f},{5,e},{4,d}], [{3,c},{2,b},{1,a}]), + Six = lists:rukeymerge(1, [{4,d},{3,c},{2,b}],[{6,f},{5,e},{1,a}]), + [{7,g},{6,f},{5,e},{3,c},{1,a}] = lists:rukeymerge(1, [{7,g},{5,e},{3,c},{1,a}], [{6,f}]), - ?line [{7,g},{6,f},{5,e},{4,d},{3,c},{1,a}] = + [{7,g},{6,f},{5,e},{4,d},{3,c},{1,a}] = lists:rukeymerge(1, [{7,g},{5,e},{3,c},{1,a}], [{6,f},{4,d}]), - ?line [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = + [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = lists:rukeymerge(1, [{7,g},{5,e},{3,c},{1,a}], [{6,f},{4,d},{2,b}]), - ?line [{7,g},{5,e},{3,c},{2,b},{1,a}] = + [{7,g},{5,e},{3,c},{2,b},{1,a}] = lists:rukeymerge(1, [{2,b}], [{7,g},{5,e},{3,c},{1,a}]), - ?line [{7,g},{5,e},{4,d},{3,c},{2,b},{1,a}] = + [{7,g},{5,e},{4,d},{3,c},{2,b},{1,a}] = lists:rukeymerge(1, [{4,d},{2,b}], [{7,g},{5,e},{3,c},{1,a}]), - ?line [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = + [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = lists:rukeymerge(1, [{6,f},{4,d},{2,b}], [{7,g},{5,e},{3,c},{1,a}]), - ?line [{7,g},{6,f},{5,e},{3,c},{1,a}] = + [{7,g},{6,f},{5,e},{3,c},{1,a}] = lists:rukeymerge(1, [{7,g},{6,f},{5,e},{3,c},{1,a}], [{6,f}]), - ?line [{7,g},{6,f},{5,e},{4,d},{3,c},{1,a}] = + [{7,g},{6,f},{5,e},{4,d},{3,c},{1,a}] = lists:rukeymerge(1, [{7,g},{6,f},{5,e},{4,d},{3,c},{1,a}], [{6,f},{4,d}]), - ?line [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = + [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = lists:rukeymerge(1, [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}], - [{6,f},{4,d},{2,b}]), - ?line [{7,g},{5,e},{3,c},{2,b},{1,a}] = + [{6,f},{4,d},{2,b}]), + [{7,g},{5,e},{3,c},{2,b},{1,a}] = lists:rukeymerge(1, [{2,b}], [{7,g},{5,e},{3,c},{2,b},{1,a}]), - ?line [{7,g},{5,e},{4,d},{3,c},{2,b},{1,a}] = + [{7,g},{5,e},{4,d},{3,c},{2,b},{1,a}] = lists:rukeymerge(1, [{4,d},{2,b}], [{7,g},{5,e},{4,d},{3,c},{2,b},{1,a}]), - ?line [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = + [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}] = lists:rukeymerge(1, [{6,f},{4,d},{2,b}], - [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}]), + [{7,g},{6,f},{5,e},{4,d},{3,c},{2,b},{1,a}]), L1 = [{a,1},{a,3},{a,5},{a,7}], L2 = [{b,1},{b,3},{b,5},{b,7}], - ?line true = + true = lists:ukeymerge(2, L1, L2) == lists:reverse(lists:rukeymerge(2, lists:reverse(L1), lists:reverse(L2))), ok. -ukeysort_1(doc) -> ["ukeysort"]; -ukeysort_1(suite) -> []; ukeysort_1(Config) when is_list(Config) -> - ?line ok = ukeysort_check(1, [], []), - ?line ok = ukeysort_check(1, [{a,b}], [{a,b}]), - ?line ok = ukeysort_check(1, [{a,b},{a,b}], [{a,b}]), - ?line ok = ukeysort_check(1, [{a,b},{b,c}], [{a,b},{b,c}]), - ?line ok = ukeysort_check(1, [{b,c},{a,b}], [{a,b},{b,c}]), - ?line ok = ukeysort_check(1, - [{1,e},{3,f},{2,y},{0,z},{x,14}], - [{0,z},{1,e},{2,y},{3,f},{x,14}]), - ?line ok = ukeysort_check(1, [{1,a},{1,a},{1,a},{1,a}], [{1,a}]), + ok = ukeysort_check(1, [], []), + ok = ukeysort_check(1, [{a,b}], [{a,b}]), + ok = ukeysort_check(1, [{a,b},{a,b}], [{a,b}]), + ok = ukeysort_check(1, [{a,b},{b,c}], [{a,b},{b,c}]), + ok = ukeysort_check(1, [{b,c},{a,b}], [{a,b},{b,c}]), + ok = ukeysort_check(1, + [{1,e},{3,f},{2,y},{0,z},{x,14}], + [{0,z},{1,e},{2,y},{3,f},{x,14}]), + ok = ukeysort_check(1, [{1,a},{1,a},{1,a},{1,a}], [{1,a}]), L1 = [{1,a},{1,b},{1,a}], L1u = lists:ukeysort(1, L1), L2 = [{1,a},{1,b},{1,a}], L2u = lists:ukeysort(1, L2), - ?line ok = ukeysort_check(1, lists:keymerge(1, L1, L2), - lists:ukeymerge(1, L1u, L2u)), + ok = ukeysort_check(1, lists:keymerge(1, L1, L2), + lists:ukeymerge(1, L1u, L2u)), L3 = [{1,a},{1,b},{1,a},{2,a}], L3u = lists:ukeysort(1, L3), - ?line ok = ukeysort_check(1, lists:keymerge(1, L3, L2), - lists:ukeymerge(1, L3u, L2u)), + ok = ukeysort_check(1, lists:keymerge(1, L3, L2), + lists:ukeymerge(1, L3u, L2u)), L4 = [{1,b},{1,a}], L4u = lists:ukeysort(1, L4), - ?line ok = ukeysort_check(1, lists:keymerge(1, L1, L4), - lists:ukeymerge(1, L1u, L4u)), + ok = ukeysort_check(1, lists:keymerge(1, L1, L4), + lists:ukeymerge(1, L1u, L4u)), L5 = [{1,a},{1,b},{1,a},{2,a}], L5u = lists:ukeysort(1, L5), - ?line ok = ukeysort_check(1, lists:keymerge(1, [], L5), - lists:ukeymerge(1, [], L5u)), - ?line ok = ukeysort_check(1, lists:keymerge(1, L5, []), - lists:ukeymerge(1, L5u, [])), + ok = ukeysort_check(1, lists:keymerge(1, [], L5), + lists:ukeymerge(1, [], L5u)), + ok = ukeysort_check(1, lists:keymerge(1, L5, []), + lists:ukeymerge(1, L5u, [])), L6 = [{3,a}], L6u = lists:ukeysort(1, L6), - ?line ok = ukeysort_check(1, lists:keymerge(1, L5, L6), - lists:ukeymerge(1, L5u, L6u)), + ok = ukeysort_check(1, lists:keymerge(1, L5, L6), + lists:ukeymerge(1, L5u, L6u)), - ?line [{b,1},{c,1}] = lists:ukeysort(1, [{c,1},{c,1},{c,1},{c,1},{b,1}]), - ?line [{a,0},{b,2},{c,3},{d,4}] = - lists:ukeysort(1, [{d,4},{c,3},{b,2},{b,2},{a,0}]), - ?line [{a,0},{b,1},{c,1}] = - lists:ukeysort(1, [{c,1},{b,1},{b,1},{b,2},{b,2},{a,0}]), - ?line [{a,0},{b,1},{c,1},{d,4}] = - lists:ukeysort(1, [{c,1},{b,1},{b,2},{a,0},{a,0},{d,4},{d,4}]), + [{b,1},{c,1}] = lists:ukeysort(1, [{c,1},{c,1},{c,1},{c,1},{b,1}]), + [{a,0},{b,2},{c,3},{d,4}] = + lists:ukeysort(1, [{d,4},{c,3},{b,2},{b,2},{a,0}]), + [{a,0},{b,1},{c,1}] = + lists:ukeysort(1, [{c,1},{b,1},{b,1},{b,2},{b,2},{a,0}]), + [{a,0},{b,1},{c,1},{d,4}] = + lists:ukeysort(1, [{c,1},{b,1},{b,2},{a,0},{a,0},{d,4},{d,4}]), SFun = fun(L) -> fun(X) -> ukeysort_check(2, X, L) end end, PL = [{a,1},{b,2},{c,3},{d,4},{e,5},{f,6}], Ps = perms([{a,1},{b,2},{c,3},{d,4},{e,5},{f,6},{b,2},{a,1}]), - ?line lists:foreach(SFun(PL), Ps), + lists:foreach(SFun(PL), Ps), M1L = [{1,a},{1,a},{2,b}], M1s = [{1,a},{2,b}], - ?line lists:foreach(SFun(M1s), perms(M1L)), + lists:foreach(SFun(M1s), perms(M1L)), M2L = [{1,a},{2,b},{2,b}], M2s = [{1,a},{2,b}], - ?line lists:foreach(SFun(M2s), perms(M2L)), + lists:foreach(SFun(M2s), perms(M2L)), M3 = [{1,a},{2,b},{3,c}], - ?line lists:foreach(SFun(M3), perms(M3)), + lists:foreach(SFun(M3), perms(M3)), ok. -ukeysort_stable(doc) -> ["ukeysort should keep the first duplicate"]; -ukeysort_stable(suite) -> []; +%% ukeysort should keep the first duplicate. ukeysort_stable(Config) when is_list(Config) -> - ?line ok = ukeysort_check(1, [{1,b},{1,c}], [{1,b}]), - ?line ok = ukeysort_check(1, [{1,c},{1,b}], [{1,c}]), - ?line ok = ukeysort_check(1, - [{1,c},{1,b},{2,x},{3,p},{2,a}], - [{1,c},{2,x},{3,p}]), - - ?line ok = ukeysort_check(1, [{1,a},{1,b},{1,b}], [{1,a}]), - ?line ok = ukeysort_check(1, [{2,a},{1,b},{2,a}], [{1,b},{2,a}]), - - ?line ok = ukeysort_check_stability(bigfunlist(3)), - ?line ok = ukeysort_check_stability(bigfunlist(10)), - ?line ok = ukeysort_check_stability(bigfunlist(100)), - ?line ok = ukeysort_check_stability(bigfunlist(1000)), - ?line case erlang:system_info(modified_timing_level) of - undefined -> ok = ukeysort_check_stability(bigfunlist(10000)); - _ -> ok - end, - ok. - -ukeysort_error(doc) -> ["ukeysort should exit when given bad arguments"]; -ukeysort_error(suite) -> []; + ok = ukeysort_check(1, [{1,b},{1,c}], [{1,b}]), + ok = ukeysort_check(1, [{1,c},{1,b}], [{1,c}]), + ok = ukeysort_check(1, + [{1,c},{1,b},{2,x},{3,p},{2,a}], + [{1,c},{2,x},{3,p}]), + + ok = ukeysort_check(1, [{1,a},{1,b},{1,b}], [{1,a}]), + ok = ukeysort_check(1, [{2,a},{1,b},{2,a}], [{1,b},{2,a}]), + + ok = ukeysort_check_stability(bigfunlist(3)), + ok = ukeysort_check_stability(bigfunlist(10)), + ok = ukeysort_check_stability(bigfunlist(100)), + ok = ukeysort_check_stability(bigfunlist(1000)), + case erlang:system_info(modified_timing_level) of + undefined -> ok = ukeysort_check_stability(bigfunlist(10000)); + _ -> ok + end, + ok. + +%% ukeysort should exit when given bad arguments. ukeysort_error(Config) when is_list(Config) -> - ?line {'EXIT', _} = (catch lists:ukeysort(0, [{1,b},{1,c}])), - ?line {'EXIT', _} = (catch lists:ukeysort(3, [{1,b},{1,c}])), - ?line {'EXIT', _} = (catch lists:ukeysort(1.5, [{1,b},{1,c}])), - ?line {'EXIT', _} = (catch lists:ukeysort(x, [{1,b},{1,c}])), - ?line {'EXIT', _} = (catch lists:ukeysort(x, [])), - ?line {'EXIT', _} = (catch lists:ukeysort(x, [{1,b}])), - ?line {'EXIT', _} = (catch lists:ukeysort(1, [a,b])), - ?line {'EXIT', _} = (catch lists:ukeysort(1, [{1,b} | {1,c}])), - ok. - -ukeysort_i(doc) -> ["ukeysort with other key than first element"]; -ukeysort_i(suite) -> []; + {'EXIT', _} = (catch lists:ukeysort(0, [{1,b},{1,c}])), + {'EXIT', _} = (catch lists:ukeysort(3, [{1,b},{1,c}])), + {'EXIT', _} = (catch lists:ukeysort(1.5, [{1,b},{1,c}])), + {'EXIT', _} = (catch lists:ukeysort(x, [{1,b},{1,c}])), + {'EXIT', _} = (catch lists:ukeysort(x, [])), + {'EXIT', _} = (catch lists:ukeysort(x, [{1,b}])), + {'EXIT', _} = (catch lists:ukeysort(1, [a,b])), + {'EXIT', _} = (catch lists:ukeysort(1, [{1,b} | {1,c}])), + ok. + +%% ukeysort with other key than first element. ukeysort_i(Config) when is_list(Config) -> - ?line ok = ukeysort_check(2, [{a,2},{b,1},{c,3}], [{b,1},{a,2},{c,3}]), + ok = ukeysort_check(2, [{a,2},{b,1},{c,3}], [{b,1},{a,2},{c,3}]), ok. -ukeysort_rand(doc) -> ["ukeysort on big randomized lists"]; -ukeysort_rand(suite) -> []; +%% ukeysort on big randomized lists. ukeysort_rand(Config) when is_list(Config) -> - ?line ok = ukeysort_check3(2, biglist(10)), - ?line ok = ukeysort_check3(2, biglist(100)), - ?line ok = ukeysort_check3(2, biglist(1000)), - ?line ok = ukeysort_check3(2, biglist(10000)), + ok = ukeysort_check3(2, biglist(10)), + ok = ukeysort_check3(2, biglist(100)), + ok = ukeysort_check3(2, biglist(1000)), + ok = ukeysort_check3(2, biglist(10000)), - ?line ok = gen_ukeysort_check(1, ubiglist(10)), - ?line ok = gen_ukeysort_check(1, ubiglist(100)), - ?line ok = gen_ukeysort_check(1, ubiglist(1000)), - ?line ok = gen_ukeysort_check(1, ubiglist(10000)), + ok = gen_ukeysort_check(1, ubiglist(10)), + ok = gen_ukeysort_check(1, ubiglist(100)), + ok = gen_ukeysort_check(1, ubiglist(1000)), + ok = gen_ukeysort_check(1, ubiglist(10000)), ok. %% Check that ukeysort/2 is stable and correct relative keysort/2. @@ -1272,7 +1219,7 @@ ukeysort_check_stability(L) -> %%% Uniquely keysort a list, check that the returned list is what we %%% expected, and that it is actually sorted. ukeysort_check(I, Input, Expected) -> - ?line Expected = lists:ukeysort(I, Input), + Expected = lists:ukeysort(I, Input), ucheck_sorted(I, Input, Expected). ukeysort_check3(I, Input) -> @@ -1309,8 +1256,7 @@ ukeycompare(I, J, A, B) when A =/= B, -funmerge(doc) -> ["Merge two lists using a fun."]; -funmerge(suite) -> []; +%% Merge two lists using a fun. funmerge(Config) when is_list(Config) -> Two = [1,2], @@ -1318,29 +1264,28 @@ funmerge(Config) when is_list(Config) -> F = fun(X, Y) -> X =< Y end, %% 2-way merge - ?line [] = lists:merge(F, [], []), - ?line Two = lists:merge(F, Two, []), - ?line Two = lists:merge(F, [], Two), - ?line Six = lists:merge(F, [1,3,5], [2,4,6]), - ?line Six = lists:merge(F, [2,4,6], [1,3,5]), - ?line Six = lists:merge(F, [1,2,3], [4,5,6]), - ?line Six = lists:merge(F, [4,5,6], [1,2,3]), - ?line Six = lists:merge(F, [1,2,5],[3,4,6]), - ?line [1,2,3,5,7] = lists:merge(F, [1,3,5,7], [2]), - ?line [1,2,3,4,5,7] = lists:merge(F, [1,3,5,7], [2,4]), - ?line [1,2,3,4,5,6,7] = lists:merge(F, [1,3,5,7], [2,4,6]), - ?line [1,2,3,5,7] = lists:merge(F, [2], [1,3,5,7]), - ?line [1,2,3,4,5,7] = lists:merge(F, [2,4], [1,3,5,7]), - ?line [1,2,3,4,5,6,7] = lists:merge(F, [2,4,6], [1,3,5,7]), + [] = lists:merge(F, [], []), + Two = lists:merge(F, Two, []), + Two = lists:merge(F, [], Two), + Six = lists:merge(F, [1,3,5], [2,4,6]), + Six = lists:merge(F, [2,4,6], [1,3,5]), + Six = lists:merge(F, [1,2,3], [4,5,6]), + Six = lists:merge(F, [4,5,6], [1,2,3]), + Six = lists:merge(F, [1,2,5],[3,4,6]), + [1,2,3,5,7] = lists:merge(F, [1,3,5,7], [2]), + [1,2,3,4,5,7] = lists:merge(F, [1,3,5,7], [2,4]), + [1,2,3,4,5,6,7] = lists:merge(F, [1,3,5,7], [2,4,6]), + [1,2,3,5,7] = lists:merge(F, [2], [1,3,5,7]), + [1,2,3,4,5,7] = lists:merge(F, [2,4], [1,3,5,7]), + [1,2,3,4,5,6,7] = lists:merge(F, [2,4,6], [1,3,5,7]), F2 = fun(X,Y) -> element(1,X) =< element(1,Y) end, - ?line [{b,2},{c,11},{c,12},{c,21},{c,22},{e,5}] = + [{b,2},{c,11},{c,12},{c,21},{c,22},{e,5}] = lists:merge(F2,[{c,11},{c,12},{e,5}], [{b,2},{c,21},{c,22}]), ok. -rfunmerge(doc) -> ["Reverse merge two lists using a fun."]; -rfunmerge(suite) -> []; +%% Reverse merge two lists using a fun. rfunmerge(Config) when is_list(Config) -> Two = [2,1], @@ -1348,86 +1293,81 @@ rfunmerge(Config) when is_list(Config) -> F = fun(X, Y) -> X =< Y end, %% 2-way reversed merge - ?line [] = lists:rmerge(F, [], []), - ?line Two = lists:rmerge(F, Two, []), - ?line Two = lists:rmerge(F, [], Two), - ?line Six = lists:rmerge(F, [5,3,1], [6,4,2]), - ?line Six = lists:rmerge(F, [6,4,2], [5,3,1]), - ?line Six = lists:rmerge(F, [3,2,1], [6,5,4]), - ?line Six = lists:rmerge(F, [6,5,4], [3,2,1]), - ?line Six = lists:rmerge(F, [4,3,2],[6,5,1]), - ?line [7,6,5,3,1] = lists:rmerge(F, [7,5,3,1], [6]), - ?line [7,6,5,4,3,1] = lists:rmerge(F, [7,5,3,1], [6,4]), - ?line [7,6,5,4,3,2,1] = lists:rmerge(F, [7,5,3,1], [6,4,2]), - ?line [7,5,3,2,1] = lists:rmerge(F, [2], [7,5,3,1]), - ?line [7,5,4,3,2,1] = lists:rmerge(F, [4,2], [7,5,3,1]), - ?line [7,6,5,4,3,2,1] = lists:rmerge(F, [6,4,2], [7,5,3,1]), + [] = lists:rmerge(F, [], []), + Two = lists:rmerge(F, Two, []), + Two = lists:rmerge(F, [], Two), + Six = lists:rmerge(F, [5,3,1], [6,4,2]), + Six = lists:rmerge(F, [6,4,2], [5,3,1]), + Six = lists:rmerge(F, [3,2,1], [6,5,4]), + Six = lists:rmerge(F, [6,5,4], [3,2,1]), + Six = lists:rmerge(F, [4,3,2],[6,5,1]), + [7,6,5,3,1] = lists:rmerge(F, [7,5,3,1], [6]), + [7,6,5,4,3,1] = lists:rmerge(F, [7,5,3,1], [6,4]), + [7,6,5,4,3,2,1] = lists:rmerge(F, [7,5,3,1], [6,4,2]), + [7,5,3,2,1] = lists:rmerge(F, [2], [7,5,3,1]), + [7,5,4,3,2,1] = lists:rmerge(F, [4,2], [7,5,3,1]), + [7,6,5,4,3,2,1] = lists:rmerge(F, [6,4,2], [7,5,3,1]), F2 = fun(X,Y) -> element(1,X) =< element(1,Y) end, L1 = [{c,11},{c,12},{e,5}], L2 = [{b,2},{c,21},{c,22}], - ?line true = + true = lists:merge(F2, L1, L2) == lists:reverse(lists:rmerge(F2,lists:reverse(L1), lists:reverse(L2))), ok. -funsort_1(doc) -> ["sort/2"]; -funsort_1(suite) -> []; funsort_1(Config) when is_list(Config) -> - ?line ok = funsort_check(1, [], []), - ?line ok = funsort_check(1, [{a,b}], [{a,b}]), - ?line ok = funsort_check(1, [{a,b},{a,b}], [{a,b},{a,b}]), - ?line ok = funsort_check(1, [{a,b},{b,c}], [{a,b},{b,c}]), - ?line ok = funsort_check(1, [{b,c},{a,b}], [{a,b},{b,c}]), - ?line ok = funsort_check(1, - [{1,e},{3,f},{2,y},{0,z},{x,14}], - [{0,z},{1,e},{2,y},{3,f},{x,14}]), + ok = funsort_check(1, [], []), + ok = funsort_check(1, [{a,b}], [{a,b}]), + ok = funsort_check(1, [{a,b},{a,b}], [{a,b},{a,b}]), + ok = funsort_check(1, [{a,b},{b,c}], [{a,b},{b,c}]), + ok = funsort_check(1, [{b,c},{a,b}], [{a,b},{b,c}]), + ok = funsort_check(1, + [{1,e},{3,f},{2,y},{0,z},{x,14}], + [{0,z},{1,e},{2,y},{3,f},{x,14}]), F = funsort_fun(1), - ?line [{b,1},{c,1}] = lists:sort(F, [{c,1},{b,1}]), - ?line [{a,0},{b,2},{c,3},{d,4}] = - lists:sort(F, [{d,4},{c,3},{b,2},{a,0}]), - ?line [{a,0},{b,1},{b,2},{c,1}] = - lists:sort(F, [{c,1},{b,1},{b,2},{a,0}]), - ?line [{a,0},{b,1},{b,2},{c,1},{d,4}] = - lists:sort(F, [{c,1},{b,1},{b,2},{a,0},{d,4}]), + [{b,1},{c,1}] = lists:sort(F, [{c,1},{b,1}]), + [{a,0},{b,2},{c,3},{d,4}] = + lists:sort(F, [{d,4},{c,3},{b,2},{a,0}]), + [{a,0},{b,1},{b,2},{c,1}] = + lists:sort(F, [{c,1},{b,1},{b,2},{a,0}]), + [{a,0},{b,1},{b,2},{c,1},{d,4}] = + lists:sort(F, [{c,1},{b,1},{b,2},{a,0},{d,4}]), SFun = fun(L) -> fun(X) -> funsort_check(1, X, L) end end, L1 = [{1,a},{1,a},{2,b},{2,b},{3,c},{4,d},{5,e},{6,f}], - ?line lists:foreach(SFun(L1), perms(L1)), + lists:foreach(SFun(L1), perms(L1)), ok. -funsort_stable(doc) -> ["sort/2 should be stable"]; -funsort_stable(suite) -> []; +%% sort/2 should be stable. funsort_stable(Config) when is_list(Config) -> - ?line ok = funsort_check(1, [{1,b},{1,c}], [{1,b},{1,c}]), - ?line ok = funsort_check(1, [{1,c},{1,b}], [{1,c},{1,b}]), - ?line ok = funsort_check(1, - [{1,c},{1,b},{2,x},{3,p},{2,a}], - [{1,c},{1,b},{2,x},{2,a},{3,p}]), + ok = funsort_check(1, [{1,b},{1,c}], [{1,b},{1,c}]), + ok = funsort_check(1, [{1,c},{1,b}], [{1,c},{1,b}]), + ok = funsort_check(1, + [{1,c},{1,b},{2,x},{3,p},{2,a}], + [{1,c},{1,b},{2,x},{2,a},{3,p}]), ok. -funsort_error(doc) -> ["sort/2 should exit when given bad arguments"]; -funsort_error(suite) -> []; +%% sort/2 should exit when given bad arguments. funsort_error(Config) when is_list(Config) -> - ?line {'EXIT', _} = (catch lists:sort(1, [{1,b} , {1,c}])), - ?line {'EXIT', _} = (catch lists:sort(fun(X,Y) -> X =< Y end, - [{1,b} | {1,c}])), + {'EXIT', _} = (catch lists:sort(1, [{1,b} , {1,c}])), + {'EXIT', _} = (catch lists:sort(fun(X,Y) -> X =< Y end, + [{1,b} | {1,c}])), ok. -funsort_rand(doc) -> ["sort/2 on big randomized lists"]; -funsort_rand(suite) -> []; +%% sort/2 on big randomized lists. funsort_rand(Config) when is_list(Config) -> - ?line ok = funsort_check3(1, biglist(10)), - ?line ok = funsort_check3(1, biglist(100)), - ?line ok = funsort_check3(1, biglist(1000)), - ?line ok = funsort_check3(1, biglist(10000)), + ok = funsort_check3(1, biglist(10)), + ok = funsort_check3(1, biglist(100)), + ok = funsort_check3(1, biglist(1000)), + ok = funsort_check3(1, biglist(10000)), ok. -% Do a keysort +%% Do a keysort funsort(I, L) -> lists:sort(funsort_fun(I), L). @@ -1437,12 +1377,11 @@ funsort_check3(I, Input) -> %%% Keysort a list, check that the returned list is what we expected, %%% and that it is actually sorted. funsort_check(I, Input, Expected) -> - ?line Expected = funsort(I, Input), + Expected = funsort(I, Input), check_sorted(I, Input, Expected). -ufunmerge(suite) -> []; -ufunmerge(doc) -> ["Merge two lists while removing duplicates using a fun."]; +%% Merge two lists while removing duplicates using a fun. ufunmerge(Conf) when is_list(Conf) -> Two = [1,2], @@ -1450,175 +1389,168 @@ ufunmerge(Conf) when is_list(Conf) -> F = fun(X, Y) -> X =< Y end, %% 2-way unique merge - ?line [] = lists:umerge(F, [], []), - ?line Two = lists:umerge(F, Two, []), - ?line Two = lists:umerge(F, [], Two), - ?line Six = lists:umerge(F, [1,3,5], [2,4,6]), - ?line Six = lists:umerge(F, [2,4,6], [1,3,5]), - ?line Six = lists:umerge(F, [1,2,3], [4,5,6]), - ?line Six = lists:umerge(F, [4,5,6], [1,2,3]), - ?line Six = lists:umerge(F, [1,2,5],[3,4,6]), - ?line [1,2,3,5,7] = lists:umerge(F, [1,3,5,7], [2]), - ?line [1,2,3,4,5,7] = lists:umerge(F, [1,3,5,7], [2,4]), - ?line [1,2,3,4,5,6,7] = lists:umerge(F, [1,3,5,7], [2,4,6]), - ?line [1,2,3,5,7] = lists:umerge(F, [2], [1,3,5,7]), - ?line [1,2,3,4,5,7] = lists:umerge(F, [2,4], [1,3,5,7]), - ?line [1,2,3,4,5,6,7] = lists:umerge(F, [2,4,6], [1,3,5,7]), - - ?line [1,2,3,5,7] = lists:umerge(F, [1,2,3,5,7], [2]), - ?line [1,2,3,4,5,7] = lists:umerge(F, [1,2,3,4,5,7], [2,4]), - ?line [1,2,3,4,5,6,7] = lists:umerge(F, [1,3,5,6,7], [2,4,6]), - ?line [1,2,3,5,7] = lists:umerge(F, [2], [1,2,3,5,7]), - ?line [1,2,3,4,5,7] = lists:umerge(F, [2,4], [1,2,3,4,5,7]), - ?line [1,2,3,4,5,6,7] = lists:umerge(F, [2,4,6], [1,2,3,4,5,6,7]), + [] = lists:umerge(F, [], []), + Two = lists:umerge(F, Two, []), + Two = lists:umerge(F, [], Two), + Six = lists:umerge(F, [1,3,5], [2,4,6]), + Six = lists:umerge(F, [2,4,6], [1,3,5]), + Six = lists:umerge(F, [1,2,3], [4,5,6]), + Six = lists:umerge(F, [4,5,6], [1,2,3]), + Six = lists:umerge(F, [1,2,5],[3,4,6]), + [1,2,3,5,7] = lists:umerge(F, [1,3,5,7], [2]), + [1,2,3,4,5,7] = lists:umerge(F, [1,3,5,7], [2,4]), + [1,2,3,4,5,6,7] = lists:umerge(F, [1,3,5,7], [2,4,6]), + [1,2,3,5,7] = lists:umerge(F, [2], [1,3,5,7]), + [1,2,3,4,5,7] = lists:umerge(F, [2,4], [1,3,5,7]), + [1,2,3,4,5,6,7] = lists:umerge(F, [2,4,6], [1,3,5,7]), + + [1,2,3,5,7] = lists:umerge(F, [1,2,3,5,7], [2]), + [1,2,3,4,5,7] = lists:umerge(F, [1,2,3,4,5,7], [2,4]), + [1,2,3,4,5,6,7] = lists:umerge(F, [1,3,5,6,7], [2,4,6]), + [1,2,3,5,7] = lists:umerge(F, [2], [1,2,3,5,7]), + [1,2,3,4,5,7] = lists:umerge(F, [2,4], [1,2,3,4,5,7]), + [1,2,3,4,5,6,7] = lists:umerge(F, [2,4,6], [1,2,3,4,5,6,7]), L1 = [{a,1},{a,3},{a,5},{a,7}], L2 = [{b,1},{b,3},{b,5},{b,7}], F2 = fun(X,Y) -> element(2,X) =< element(2,Y) end, - ?line L1 = lists:umerge(F2, L1, L2), - ?line [{b,2},{e,5},{c,11},{c,12},{c,21},{c,22}] = + L1 = lists:umerge(F2, L1, L2), + [{b,2},{e,5},{c,11},{c,12},{c,21},{c,22}] = lists:umerge(F2, [{e,5},{c,11},{c,12}], [{b,2},{c,21},{c,22}]), ok. -rufunmerge(suite) -> []; -rufunmerge(doc) -> - ["Reverse merge two lists while removing duplicates using a fun."]; +%% Reverse merge two lists while removing duplicates using a fun. rufunmerge(Conf) when is_list(Conf) -> Two = [2,1], Six = [6,5,4,3,2,1], F = fun(X, Y) -> X =< Y end, %% 2-way reversed unique merge - ?line [] = lists:rumerge(F, [], []), - ?line Two = lists:rumerge(F, Two, []), - ?line Two = lists:rumerge(F, [], Two), - ?line Six = lists:rumerge(F, [5,3,1], [6,4,2]), - ?line Six = lists:rumerge(F, [6,4,2], [5,3,1]), - ?line Six = lists:rumerge(F, [3,2,1], [6,5,4]), - ?line Six = lists:rumerge(F, [6,5,4], [3,2,1]), - ?line Six = lists:rumerge(F, [4,3,2],[6,5,1]), - ?line [7,6,5,3,1] = lists:rumerge(F, [7,5,3,1], [6]), - ?line [7,6,5,4,3,1] = lists:rumerge(F, [7,5,3,1], [6,4]), - ?line [7,6,5,4,3,2,1] = lists:rumerge(F, [7,5,3,1], [6,4,2]), - ?line [7,5,3,2,1] = lists:rumerge(F, [2], [7,5,3,1]), - ?line [7,5,4,3,2,1] = lists:rumerge(F, [4,2], [7,5,3,1]), - ?line [7,6,5,4,3,2,1] = lists:rumerge(F, [6,4,2], [7,5,3,1]), - - ?line [7,6,5,3,1] = lists:rumerge(F, [7,6,5,3,1], [6]), - ?line [7,6,5,4,3,1] = lists:rumerge(F, [7,6,5,4,3,1], [6,4]), - ?line [7,6,5,4,3,2,1] = lists:rumerge(F, [7,6,5,4,3,2,1], [6,4,2]), - ?line [7,5,3,2,1] = lists:rumerge(F, [2], [7,5,3,2,1]), - ?line [7,5,4,3,2,1] = lists:rumerge(F, [4,2], [7,5,4,3,2,1]), - ?line [7,6,5,4,3,2,1] = lists:rumerge(F, [6,4,2], [7,6,5,4,3,2,1]), + [] = lists:rumerge(F, [], []), + Two = lists:rumerge(F, Two, []), + Two = lists:rumerge(F, [], Two), + Six = lists:rumerge(F, [5,3,1], [6,4,2]), + Six = lists:rumerge(F, [6,4,2], [5,3,1]), + Six = lists:rumerge(F, [3,2,1], [6,5,4]), + Six = lists:rumerge(F, [6,5,4], [3,2,1]), + Six = lists:rumerge(F, [4,3,2],[6,5,1]), + [7,6,5,3,1] = lists:rumerge(F, [7,5,3,1], [6]), + [7,6,5,4,3,1] = lists:rumerge(F, [7,5,3,1], [6,4]), + [7,6,5,4,3,2,1] = lists:rumerge(F, [7,5,3,1], [6,4,2]), + [7,5,3,2,1] = lists:rumerge(F, [2], [7,5,3,1]), + [7,5,4,3,2,1] = lists:rumerge(F, [4,2], [7,5,3,1]), + [7,6,5,4,3,2,1] = lists:rumerge(F, [6,4,2], [7,5,3,1]), + + [7,6,5,3,1] = lists:rumerge(F, [7,6,5,3,1], [6]), + [7,6,5,4,3,1] = lists:rumerge(F, [7,6,5,4,3,1], [6,4]), + [7,6,5,4,3,2,1] = lists:rumerge(F, [7,6,5,4,3,2,1], [6,4,2]), + [7,5,3,2,1] = lists:rumerge(F, [2], [7,5,3,2,1]), + [7,5,4,3,2,1] = lists:rumerge(F, [4,2], [7,5,4,3,2,1]), + [7,6,5,4,3,2,1] = lists:rumerge(F, [6,4,2], [7,6,5,4,3,2,1]), F2 = fun(X,Y) -> element(1,X) =< element(1,Y) end, L1 = [{1,a},{1,b},{1,a}], L2 = [{1,a},{1,b},{1,a}], - ?line true = lists:umerge(F2, L1, L2) == + true = lists:umerge(F2, L1, L2) == lists:reverse(lists:rumerge(F, lists:reverse(L2), lists:reverse(L1))), L3 = [{c,11},{c,12},{e,5}], L4 = [{b,2},{c,21},{c,22}], - ?line true = + true = lists:umerge(F2, L3, L4) == lists:reverse(lists:rumerge(F2,lists:reverse(L3), lists:reverse(L4))), ok. -ufunsort_1(doc) -> ["usort/2"]; -ufunsort_1(suite) -> []; ufunsort_1(Config) when is_list(Config) -> - ?line ok = ufunsort_check(1, [], []), - ?line ok = ufunsort_check(1, [{a,b}], [{a,b}]), - ?line ok = ufunsort_check(1, [{a,b},{a,b}], [{a,b}]), - ?line ok = ufunsort_check(1, [{a,b},{b,c}], [{a,b},{b,c}]), - ?line ok = ufunsort_check(1, [{b,c},{a,b}], [{a,b},{b,c}]), - ?line ok = ufunsort_check(1, - [{1,e},{3,f},{2,y},{0,z},{x,14}], - [{0,z},{1,e},{2,y},{3,f},{x,14}]), - ?line ok = ufunsort_check(1, - [{1,a},{2,b},{3,c},{2,b},{1,a},{2,b},{3,c}, - {2,b},{1,a}], - [{1,a},{2,b},{3,c}]), - ?line ok = ufunsort_check(1, - [{1,a},{1,a},{1,b},{1,b},{1,a},{2,a}], - [{1,a},{2,a}]), + ok = ufunsort_check(1, [], []), + ok = ufunsort_check(1, [{a,b}], [{a,b}]), + ok = ufunsort_check(1, [{a,b},{a,b}], [{a,b}]), + ok = ufunsort_check(1, [{a,b},{b,c}], [{a,b},{b,c}]), + ok = ufunsort_check(1, [{b,c},{a,b}], [{a,b},{b,c}]), + ok = ufunsort_check(1, + [{1,e},{3,f},{2,y},{0,z},{x,14}], + [{0,z},{1,e},{2,y},{3,f},{x,14}]), + ok = ufunsort_check(1, + [{1,a},{2,b},{3,c},{2,b},{1,a},{2,b},{3,c}, + {2,b},{1,a}], + [{1,a},{2,b},{3,c}]), + ok = ufunsort_check(1, + [{1,a},{1,a},{1,b},{1,b},{1,a},{2,a}], + [{1,a},{2,a}]), F = funsort_fun(1), L1 = [{1,a},{1,b},{1,a}], L2 = [{1,a},{1,b},{1,a}], - ?line ok = ufunsort_check(1, lists:keymerge(1, L1, L2), - lists:umerge(F, lists:usort(F, L1), - lists:usort(F, L2))), + ok = ufunsort_check(1, lists:keymerge(1, L1, L2), + lists:umerge(F, lists:usort(F, L1), + lists:usort(F, L2))), L3 = [{1,a},{1,b},{1,a},{2,a}], - ?line ok = ufunsort_check(1, lists:keymerge(1, L3, L2), - lists:umerge(F, lists:usort(F, L3), - lists:usort(F, L2))), + ok = ufunsort_check(1, lists:keymerge(1, L3, L2), + lists:umerge(F, lists:usort(F, L3), + lists:usort(F, L2))), L4 = [{1,b},{1,a}], - ?line ok = ufunsort_check(1, lists:keymerge(1, L1, L4), - lists:umerge(F, lists:usort(F, L1), - lists:usort(F, L4))), + ok = ufunsort_check(1, lists:keymerge(1, L1, L4), + lists:umerge(F, lists:usort(F, L1), + lists:usort(F, L4))), L5 = [{1,a},{1,b},{1,a},{2,a}], - ?line ok = ufunsort_check(1, lists:keymerge(1, L5, []), - lists:umerge(F, lists:usort(F, L5), [])), + ok = ufunsort_check(1, lists:keymerge(1, L5, []), + lists:umerge(F, lists:usort(F, L5), [])), L6 = [{3,a}], - ?line ok = ufunsort_check(1, lists:keymerge(1, L5, L6), - lists:umerge(F, lists:usort(F, L5), - lists:usort(F, L6))), - - ?line [{b,1},{c,1}] = lists:usort(F, [{c,1},{c,1},{b,1}]), - ?line [{a,0},{b,2},{c,3},{d,4}] = - lists:usort(F, [{d,4},{c,3},{b,2},{b,2},{a,0}]), - ?line [{a,0},{b,1},{c,1}] = - lists:usort(F, [{c,1},{b,1},{b,1},{b,2},{b,2},{a,0}]), - ?line [{a,0},{b,1},{c,1},{d,4}] = - lists:usort(F, [{c,1},{b,1},{b,2},{a,0},{a,0},{d,4},{d,4}]), + ok = ufunsort_check(1, lists:keymerge(1, L5, L6), + lists:umerge(F, lists:usort(F, L5), + lists:usort(F, L6))), + + [{b,1},{c,1}] = lists:usort(F, [{c,1},{c,1},{b,1}]), + [{a,0},{b,2},{c,3},{d,4}] = + lists:usort(F, [{d,4},{c,3},{b,2},{b,2},{a,0}]), + [{a,0},{b,1},{c,1}] = + lists:usort(F, [{c,1},{b,1},{b,1},{b,2},{b,2},{a,0}]), + [{a,0},{b,1},{c,1},{d,4}] = + lists:usort(F, [{c,1},{b,1},{b,2},{a,0},{a,0},{d,4},{d,4}]), SFun = fun(L) -> fun(X) -> ufunsort_check(1, X, L) end end, PL = [{1,a},{2,b},{3,c},{4,d},{5,e},{6,f}], Ps = perms([{1,a},{2,b},{3,c},{4,d},{5,e},{6,f},{2,b},{1,a}]), - ?line lists:foreach(SFun(PL), Ps), + lists:foreach(SFun(PL), Ps), ok. -ufunsort_stable(doc) -> ["usort/2 should be stable"]; -ufunsort_stable(suite) -> []; +%% usort/2 should be stable. ufunsort_stable(Config) when is_list(Config) -> - ?line ok = ufunsort_check(1, [{1,b},{1,c}], [{1,b}]), - ?line ok = ufunsort_check(1, [{1,c},{1,b}], [{1,c}]), - ?line ok = ufunsort_check(1, - [{1,c},{1,b},{2,x},{3,p},{2,a}], - [{1,c},{2,x},{3,p}]), - - ?line ok = ufunsort_check_stability(bigfunlist(10)), - ?line ok = ufunsort_check_stability(bigfunlist(100)), - ?line ok = ufunsort_check_stability(bigfunlist(1000)), - ?line case erlang:system_info(modified_timing_level) of - undefined -> ok = ufunsort_check_stability(bigfunlist(10000)); - _ -> ok - end, - ok. - -ufunsort_error(doc) -> ["usort/2 should exit when given bad arguments"]; -ufunsort_error(suite) -> []; + ok = ufunsort_check(1, [{1,b},{1,c}], [{1,b}]), + ok = ufunsort_check(1, [{1,c},{1,b}], [{1,c}]), + ok = ufunsort_check(1, + [{1,c},{1,b},{2,x},{3,p},{2,a}], + [{1,c},{2,x},{3,p}]), + + ok = ufunsort_check_stability(bigfunlist(10)), + ok = ufunsort_check_stability(bigfunlist(100)), + ok = ufunsort_check_stability(bigfunlist(1000)), + case erlang:system_info(modified_timing_level) of + undefined -> ok = ufunsort_check_stability(bigfunlist(10000)); + _ -> ok + end, + ok. + +%% usort/2 should exit when given bad arguments. ufunsort_error(Config) when is_list(Config) -> - ?line {'EXIT', _} = (catch lists:usort(1, [{1,b} , {1,c}])), - ?line {'EXIT', _} = (catch lists:usort(fun(X,Y) -> X =< Y end, - [{1,b} | {1,c}])), + {'EXIT', _} = (catch lists:usort(1, [{1,b} , {1,c}])), + {'EXIT', _} = (catch lists:usort(fun(X,Y) -> X =< Y end, + [{1,b} | {1,c}])), ok. -ufunsort_rand(doc) -> ["usort/2 on big randomized lists"]; -ufunsort_rand(suite) -> []; +%% usort/2 on big randomized lists. ufunsort_rand(Config) when is_list(Config) -> - ?line ok = ufunsort_check3(1, biglist(10)), - ?line ok = ufunsort_check3(1, biglist(100)), - ?line ok = ufunsort_check3(1, biglist(1000)), - ?line ok = ufunsort_check3(1, biglist(10000)), + ok = ufunsort_check3(1, biglist(10)), + ok = ufunsort_check3(1, biglist(100)), + ok = ufunsort_check3(1, biglist(1000)), + ok = ufunsort_check3(1, biglist(10000)), - ?line ok = gen_ufunsort_check(1, ubiglist(100)), - ?line ok = gen_ufunsort_check(1, ubiglist(1000)), - ?line ok = gen_ufunsort_check(1, ubiglist(10000)), + ok = gen_ufunsort_check(1, ubiglist(100)), + ok = gen_ufunsort_check(1, ubiglist(1000)), + ok = gen_ufunsort_check(1, ubiglist(10000)), ok. %% Check that usort/2 is stable and correct relative sort/2. @@ -1646,10 +1578,10 @@ ufunsort_check3(I, Input) -> %%% Keysort a list, check that the returned list is what we expected, %%% and that it is actually sorted. ufunsort_check(I, Input, Expected) -> - ?line Expected = ufunsort(I, Input), + Expected = ufunsort(I, Input), ucheck_sorted(I, Input, Expected). -% Do a keysort +%% Do a keysort ufunsort(I, L) -> lists:usort(funsort_fun(I), L). @@ -1701,7 +1633,7 @@ ubiglist(0, L) -> ubiglist(N, L) -> E = urandom_tuple(11, 6), ubiglist(N-1, [E|L]). - + urandom_tuple(N, I) -> R1 = randint(N), R2 = randint(I), @@ -1733,7 +1665,7 @@ bigfunlist(0, _P, L) -> bigfunlist(N, P, L) -> {E, NP} = random_funtuple(P, 11), bigfunlist(N-1, NP, [E | L]). - + random_funtuple(P, N) -> R = randint(N), F = make_fun(), @@ -1744,7 +1676,7 @@ random_funtuple(P, N) -> make_fun() -> Pid = spawn(?MODULE, make_fun, [self()]), receive {Pid, Fun} -> Fun end. - + make_fun(Pid) -> Pid ! {self(), fun make_fun/1}. @@ -1854,7 +1786,7 @@ sloop(N, S) -> end, sloop(N, NS) end. - + display_state(S) -> io:format("sort: ~p~n", [S#state.sort]), io:format("usort: ~p~n", [S#state.usort]), @@ -2123,85 +2055,67 @@ rkeymerge2_2(_I, T1, _E1, [], M, H1) -> %%%------------------------------------------------------------ -seq_loop(doc) -> - ["Test for infinite loop (OTP-2404)."]; -seq_loop(suite) -> - []; +%% Test for infinite loop (OTP-2404). seq_loop(Config) when is_list(Config) -> - ?line _ = (catch lists:seq(1, 5, -1)), + _ = (catch lists:seq(1, 5, -1)), ok. -seq_2(doc) -> - ["Non-error cases for seq/2"]; -seq_2(suite) -> - []; +%% Non-error cases for seq/2. seq_2(Config) when is_list(Config) -> - ?line [1,2,3] = lists:seq(1,3), - ?line [1] = lists:seq(1,1), - ?line Big = 748274827583793785928592859, - ?line Big1 = Big+1, - ?line Big2 = Big+2, - ?line [Big, Big1, Big2] = lists:seq(Big, Big+2), + [1,2,3] = lists:seq(1,3), + [1] = lists:seq(1,1), + Big = 748274827583793785928592859, + Big1 = Big+1, + Big2 = Big+2, + [Big, Big1, Big2] = lists:seq(Big, Big+2), ok. -seq_2_e(doc) -> - ["Error cases for seq/2"]; -seq_2_e(suite) -> - []; +%% Error cases for seq/2. seq_2_e(Config) when is_list(Config) -> - ?line seq_error([4, 2]), - ?line seq_error([1, a]), - ?line seq_error([1.0, 2.0]), + seq_error([4, 2]), + seq_error([1, a]), + seq_error([1.0, 2.0]), ok. seq_error(Args) -> {'EXIT', _} = (catch apply(lists, seq, Args)). -seq_3(doc) -> - ["Non-error cases for seq/3"]; -seq_3(suite) -> - []; +%% Non-error cases for seq/3. seq_3(Config) when is_list(Config) -> - ?line [1,2,3] = lists:seq(1,3,1), - ?line [1] = lists:seq(1,1,1), - ?line Big = 748274827583793785928592859, - ?line Big1 = Big+1, - ?line Big2 = Big+2, - ?line [Big, Big1, Big2] = lists:seq(Big, Big+2,1), + [1,2,3] = lists:seq(1,3,1), + [1] = lists:seq(1,1,1), + Big = 748274827583793785928592859, + Big1 = Big+1, + Big2 = Big+2, + [Big, Big1, Big2] = lists:seq(Big, Big+2,1), - ?line [3,2,1] = lists:seq(3,1,-1), - ?line [1] = lists:seq(1,1,-1), + [3,2,1] = lists:seq(3,1,-1), + [1] = lists:seq(1,1,-1), - ?line [3,1] = lists:seq(3,1,-2), - ?line [1] = lists:seq(1, 10, 10), - ?line [1, 4, 7, 10, 13, 16, 19] = lists:seq(1, 19, 3), - ?line [1, 4, 7, 10, 13, 16, 19] = lists:seq(1, 20, 3), - ?line [1, 4, 7, 10, 13, 16, 19] = lists:seq(1, 21, 3), + [3,1] = lists:seq(3,1,-2), + [1] = lists:seq(1, 10, 10), + [1, 4, 7, 10, 13, 16, 19] = lists:seq(1, 19, 3), + [1, 4, 7, 10, 13, 16, 19] = lists:seq(1, 20, 3), + [1, 4, 7, 10, 13, 16, 19] = lists:seq(1, 21, 3), - ?line [1] = lists:seq(1, 1, 0), %OTP-2613 + [1] = lists:seq(1, 1, 0), %OTP-2613 ok. -seq_3_e(doc) -> - ["Error cases for seq/3"]; -seq_3_e(suite) -> - []; +%% Error cases for seq/3. seq_3_e(Config) when is_list(Config) -> - ?line seq_error([4, 2, 1]), - ?line seq_error([3, 5, -1]), - ?line seq_error([1, a, 1]), - ?line seq_error([1.0, 2.0, 1]), + seq_error([4, 2, 1]), + seq_error([3, 5, -1]), + seq_error([1, a, 1]), + seq_error([1.0, 2.0, 1]), - ?line seq_error([1, 3, 1.0]), - ?line seq_error([1, 3, a]), - ?line seq_error([1, 3, 0]), + seq_error([1, 3, 1.0]), + seq_error([1, 3, a]), + seq_error([1, 3, 0]), - ?line seq_error([a, a, 0]), + seq_error([a, a, 0]), ok. -otp_7230(doc) -> - ["OTP-7230. seq/1,2 returns the empty list"]; -otp_7230(suite) -> - []; +%% OTP-7230. seq/1,2 returns the empty list. otp_7230(Config) when is_list(Config) -> From = -10, To = 10, @@ -2210,26 +2124,26 @@ otp_7230(Config) when is_list(Config) -> L = lists:seq(From, To), SL = lists:seq(StepFrom, StepTo), - ?line [] = - [{F, T, S} || - F <- L, T <- L, S <- SL, - not check_seq(F, T, S, catch lists:seq(F, T, S)) - orelse - S =:= 1 andalso not check_seq(F, T, S, catch lists:seq(F, T)) + [] = + [{F, T, S} || + F <- L, T <- L, S <- SL, + not check_seq(F, T, S, catch lists:seq(F, T, S)) + orelse + S =:= 1 andalso not check_seq(F, T, S, catch lists:seq(F, T)) ]. check_seq(From, To, 0, R) -> - From =:= To andalso R =:= [From] - orelse - From =/= To andalso is_tuple(R) andalso element(1, R) =:= 'EXIT'; + From =:= To andalso R =:= [From] + orelse + From =/= To andalso is_tuple(R) andalso element(1, R) =:= 'EXIT'; check_seq(From, To, Step, []) when Step =/= 0 -> - 0 =:= property(From, To, Step) - andalso - ( - Step > 0 andalso To < From andalso From-To =< Step - orelse - Step < 0 andalso To > From andalso To-From =< -Step - ); + 0 =:= property(From, To, Step) + andalso + ( + Step > 0 andalso To < From andalso From-To =< Step + orelse + Step < 0 andalso To > From andalso To-From =< -Step + ); check_seq(From, To, Step, R) when R =/= [], To < From, Step > 0 -> is_tuple(R) andalso element(1, R) =:= 'EXIT'; check_seq(From, To, Step, R) when R =/= [], To > From, Step < 0 -> @@ -2240,27 +2154,27 @@ check_seq(From, To, Step, L) when is_list(L), L =/= [], Step =/= 0 -> Min = lists:min(L), Max = lists:max(L), - [] =:= [E || E <- L, not is_integer(E)] - andalso - %% The difference between two consecutive elements is Step: - begin - LS = [First-Step]++L, - LR = L++[Last+Step], - [Step] =:= lists:usort([B-A || {A,B} <- lists:zip(LS, LR)]) - end - andalso - %% The first element of L is From: - From =:= First - andalso - %% No element outside the given interval: - Min >= lists:min([From, To]) - andalso - Max =< lists:max([From, To]) - andalso - %% All elements are present: - abs(To-Last) < abs(Step) - andalso - length(L) =:= property(From, To, Step); + [] =:= [E || E <- L, not is_integer(E)] + andalso + %% The difference between two consecutive elements is Step: + begin + LS = [First-Step]++L, + LR = L++[Last+Step], + [Step] =:= lists:usort([B-A || {A,B} <- lists:zip(LS, LR)]) + end + andalso + %% The first element of L is From: + From =:= First + andalso + %% No element outside the given interval: + Min >= lists:min([From, To]) + andalso + Max =< lists:max([From, To]) + andalso + %% All elements are present: + abs(To-Last) < abs(Step) + andalso + length(L) =:= property(From, To, Step); check_seq(_From, _To, _Step, _R) -> false. @@ -2270,25 +2184,22 @@ property(From, To, Step) -> %%%------------------------------------------------------------ --define(sublist_error2(X,Y), ?line {'EXIT', _} = (catch lists:sublist(X,Y))). --define(sublist_error3(X,Y,Z), ?line {'EXIT', _} = (catch lists:sublist(X,Y,Z))). +-define(sublist_error2(X,Y), {'EXIT', _} = (catch lists:sublist(X,Y))). +-define(sublist_error3(X,Y,Z), {'EXIT', _} = (catch lists:sublist(X,Y,Z))). -sublist_2(doc) -> ["sublist/2"]; -sublist_2(suite) -> []; sublist_2(Config) when is_list(Config) -> - ?line [] = lists:sublist([], 0), - ?line [] = lists:sublist([], 1), - ?line [] = lists:sublist([a], 0), - ?line [a] = lists:sublist([a], 1), - ?line [a] = lists:sublist([a], 2), - ?line [a] = lists:sublist([a|b], 1), + [] = lists:sublist([], 0), + [] = lists:sublist([], 1), + [] = lists:sublist([a], 0), + [a] = lists:sublist([a], 1), + [a] = lists:sublist([a], 2), + [a] = lists:sublist([a|b], 1), - ?line [a,b] = lists:sublist([a,b|c], 2), + [a,b] = lists:sublist([a,b|c], 2), ok. -sublist_2_e(doc) -> ["sublist/2 error cases"]; -sublist_2_e(suite) -> []; +%% sublist/2 error cases. sublist_2_e(Config) when is_list(Config) -> ?sublist_error2([], -1), ?sublist_error2(a, -1), @@ -2300,36 +2211,33 @@ sublist_2_e(Config) when is_list(Config) -> ?sublist_error2([], 1.5), ok. -sublist_3(doc) -> ["sublist/3"]; -sublist_3(suite) -> []; sublist_3(Config) when is_list(Config) -> - ?line [] = lists:sublist([], 1, 0), - ?line [] = lists:sublist([], 1, 1), - ?line [] = lists:sublist([a], 1, 0), - ?line [a] = lists:sublist([a], 1, 1), - ?line [a] = lists:sublist([a], 1, 2), - ?line [a] = lists:sublist([a|b], 1, 1), - - ?line [] = lists:sublist([], 1, 0), - ?line [] = lists:sublist([], 1, 1), - ?line [] = lists:sublist([a], 1, 0), - ?line [a] = lists:sublist([a], 1, 1), - ?line [a] = lists:sublist([a], 1, 2), - ?line [] = lists:sublist([a], 2, 1), - ?line [] = lists:sublist([a], 2, 2), - ?line [] = lists:sublist([a], 2, 79), - ?line [] = lists:sublist([a,b|c], 1, 0), - ?line [] = lists:sublist([a,b|c], 2, 0), - ?line [a] = lists:sublist([a,b|c], 1, 1), - ?line [b] = lists:sublist([a,b|c], 2, 1), - ?line [a,b] = lists:sublist([a,b|c], 1, 2), - - ?line [] = lists:sublist([a], 2, 0), - - ok. - -sublist_3_e(doc) -> ["sublist/3 error cases"]; -sublist_3_e(suite) -> []; + [] = lists:sublist([], 1, 0), + [] = lists:sublist([], 1, 1), + [] = lists:sublist([a], 1, 0), + [a] = lists:sublist([a], 1, 1), + [a] = lists:sublist([a], 1, 2), + [a] = lists:sublist([a|b], 1, 1), + + [] = lists:sublist([], 1, 0), + [] = lists:sublist([], 1, 1), + [] = lists:sublist([a], 1, 0), + [a] = lists:sublist([a], 1, 1), + [a] = lists:sublist([a], 1, 2), + [] = lists:sublist([a], 2, 1), + [] = lists:sublist([a], 2, 2), + [] = lists:sublist([a], 2, 79), + [] = lists:sublist([a,b|c], 1, 0), + [] = lists:sublist([a,b|c], 2, 0), + [a] = lists:sublist([a,b|c], 1, 1), + [b] = lists:sublist([a,b|c], 2, 1), + [a,b] = lists:sublist([a,b|c], 1, 2), + + [] = lists:sublist([a], 2, 0), + + ok. + +%% sublist/3 error cases sublist_3_e(Config) when is_list(Config) -> ?sublist_error3([], 1, -1), ?sublist_error3(a, 1, -1), @@ -2363,8 +2271,8 @@ sublist_3_e(Config) when is_list(Config) -> %%%------------------------------------------------------------ --define(flatten_error1(X), ?line {'EXIT', _} = (catch lists:flatten(X))). --define(flatten_error2(X,Y), ?line {'EXIT', _} = (catch lists:flatten(X,Y))). +-define(flatten_error1(X), {'EXIT', _} = (catch lists:flatten(X))). +-define(flatten_error2(X,Y), {'EXIT', _} = (catch lists:flatten(X,Y))). %% Test lists:flatten/1,2 and lists:flatlength/1. flatten_1(Config) when is_list(Config) -> @@ -2385,8 +2293,7 @@ lists_flatten(List) -> Len = length(Flat), Flat. -flatten_1_e(doc) -> ["flatten/1 error cases"]; -flatten_1_e(suite) -> []; +%% flatten/1 error cases flatten_1_e(Config) when is_list(Config) -> ?flatten_error1(a), ?flatten_error1([a|b]), @@ -2404,60 +2311,59 @@ flatten_2(Config) when is_list(Config) -> [a,b,c,[no,flatten]] = lists:flatten([[a,[b,c]]], [[no,flatten]]), ok. -flatten_2_e(doc) -> ["flatten/2 error cases"]; -flatten_2_e(suite) -> []; +%% flatten/2 error cases. flatten_2_e(Config) when is_list(Config) -> ok. %% Test lists:zip/2, lists:unzip/1. zip_unzip(Config) when is_list(Config) -> - ?line [] = lists:zip([], []), - ?line [{a,b}] = lists:zip([a], [b]), - ?line [{42.0,{kalle,nisse}},{a,b}] = lists:zip([42.0,a], [{kalle,nisse},b]), + [] = lists:zip([], []), + [{a,b}] = lists:zip([a], [b]), + [{42.0,{kalle,nisse}},{a,b}] = lists:zip([42.0,a], [{kalle,nisse},b]), %% Longer lists. - ?line SeqA = lists:seq(45, 200), - ?line SeqB = [A*A || A <- SeqA], - ?line AB = lists:zip(SeqA, SeqB), - ?line SeqA = [A || {A,_} <- AB], - ?line SeqB = [B || {_,B} <- AB], - ?line {SeqA,SeqB} = lists:unzip(AB), - + SeqA = lists:seq(45, 200), + SeqB = [A*A || A <- SeqA], + AB = lists:zip(SeqA, SeqB), + SeqA = [A || {A,_} <- AB], + SeqB = [B || {_,B} <- AB], + {SeqA,SeqB} = lists:unzip(AB), + %% Some more unzip/1. - ?line {[],[]} = lists:unzip([]), - ?line {[a],[b]} = lists:unzip([{a,b}]), - ?line {[a,c],[b,d]} = lists:unzip([{a,b},{c,d}]), + {[],[]} = lists:unzip([]), + {[a],[b]} = lists:unzip([{a,b}]), + {[a,c],[b,d]} = lists:unzip([{a,b},{c,d}]), %% Error cases. - ?line {'EXIT',{function_clause,_}} = (catch lists:zip([], [b])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zip([a], [])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zip([a], [b,c])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zip([a], [b,c])), + {'EXIT',{function_clause,_}} = (catch lists:zip([], [b])), + {'EXIT',{function_clause,_}} = (catch lists:zip([a], [])), + {'EXIT',{function_clause,_}} = (catch lists:zip([a], [b,c])), + {'EXIT',{function_clause,_}} = (catch lists:zip([a], [b,c])), ok. %% Test lists:zip3/3, lists:unzip3/1. zip_unzip3(Config) when is_list(Config) -> - ?line [] = lists:zip3([], [], []), - ?line [{a,b,c}] = lists:zip3([a], [b], [c]), + [] = lists:zip3([], [], []), + [{a,b,c}] = lists:zip3([a], [b], [c]), %% Longer lists. - ?line SeqA = lists:seq(45, 200), - ?line SeqB = [2*A || A <- SeqA], - ?line SeqC = [A*A || A <- SeqA], - ?line ABC = lists:zip3(SeqA, SeqB, SeqC), - ?line SeqA = [A || {A,_,_} <- ABC], - ?line SeqB = [B || {_,B,_} <- ABC], - ?line SeqC = [C || {_,_,C} <- ABC], - ?line {SeqA,SeqB,SeqC} = lists:unzip3(ABC), + SeqA = lists:seq(45, 200), + SeqB = [2*A || A <- SeqA], + SeqC = [A*A || A <- SeqA], + ABC = lists:zip3(SeqA, SeqB, SeqC), + SeqA = [A || {A,_,_} <- ABC], + SeqB = [B || {_,B,_} <- ABC], + SeqC = [C || {_,_,C} <- ABC], + {SeqA,SeqB,SeqC} = lists:unzip3(ABC), %% Some more unzip3/1. - ?line {[],[],[]} = lists:unzip3([]), - ?line {[a],[b],[c]} = lists:unzip3([{a,b,c}]), + {[],[],[]} = lists:unzip3([]), + {[a],[b],[c]} = lists:unzip3([{a,b,c}]), %% Error cases. - ?line {'EXIT',{function_clause,_}} = (catch lists:zip3([], [], [c])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zip3([], [b], [])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zip3([a], [], [])), + {'EXIT',{function_clause,_}} = (catch lists:zip3([], [], [c])), + {'EXIT',{function_clause,_}} = (catch lists:zip3([], [b], [])), + {'EXIT',{function_clause,_}} = (catch lists:zip3([a], [], [])), ok. @@ -2465,61 +2371,61 @@ zip_unzip3(Config) when is_list(Config) -> zipwith(Config) when is_list(Config) -> Zip = fun(A, B) -> [A|B] end, - ?line [] = lists:zipwith(Zip, [], []), - ?line [[a|b]] = lists:zipwith(Zip, [a], [b]), + [] = lists:zipwith(Zip, [], []), + [[a|b]] = lists:zipwith(Zip, [a], [b]), %% Longer lists. - ?line SeqA = lists:seq(77, 300), - ?line SeqB = [A*A || A <- SeqA], - ?line AB = lists:zipwith(Zip, SeqA, SeqB), - ?line SeqA = [A || [A|_] <- AB], - ?line SeqB = [B || [_|B] <- AB], - + SeqA = lists:seq(77, 300), + SeqB = [A*A || A <- SeqA], + AB = lists:zipwith(Zip, SeqA, SeqB), + SeqA = [A || [A|_] <- AB], + SeqB = [B || [_|B] <- AB], + %% Error cases. - ?line {'EXIT',{function_clause,_}} = (catch lists:zipwith(badfun, [], [])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zipwith(Zip, [], [b])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zipwith(Zip, [a], [])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zipwith(Zip, [a], [b,c])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zipwith(Zip, [a], [b,c])), + {'EXIT',{function_clause,_}} = (catch lists:zipwith(badfun, [], [])), + {'EXIT',{function_clause,_}} = (catch lists:zipwith(Zip, [], [b])), + {'EXIT',{function_clause,_}} = (catch lists:zipwith(Zip, [a], [])), + {'EXIT',{function_clause,_}} = (catch lists:zipwith(Zip, [a], [b,c])), + {'EXIT',{function_clause,_}} = (catch lists:zipwith(Zip, [a], [b,c])), ok. %% Test lists:zipwith3/4. zipwith3(Config) when is_list(Config) -> Zip = fun(A, B, C) -> [A,B,C] end, - ?line [] = lists:zipwith3(Zip, [], [], []), - ?line [[a,b,c]] = lists:zipwith3(Zip, [a], [b], [c]), + [] = lists:zipwith3(Zip, [], [], []), + [[a,b,c]] = lists:zipwith3(Zip, [a], [b], [c]), %% Longer lists. - ?line SeqA = lists:seq(45, 200), - ?line SeqB = [2*A || A <- SeqA], - ?line SeqC = [A*A || A <- SeqA], - ?line ABC = lists:zipwith3(Zip, SeqA, SeqB, SeqC), - ?line SeqA = [A || [A,_,_] <- ABC], - ?line SeqB = [B || [_,B,_] <- ABC], - ?line SeqC = [C || [_,_,C] <- ABC], + SeqA = lists:seq(45, 200), + SeqB = [2*A || A <- SeqA], + SeqC = [A*A || A <- SeqA], + ABC = lists:zipwith3(Zip, SeqA, SeqB, SeqC), + SeqA = [A || [A,_,_] <- ABC], + SeqB = [B || [_,B,_] <- ABC], + SeqC = [C || [_,_,C] <- ABC], %% Error cases. - ?line {'EXIT',{function_clause,_}} = (catch lists:zipwith3(badfun, [], [], [])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zipwith3(Zip, [], [], [c])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zipwith3(Zip, [], [b], [])), - ?line {'EXIT',{function_clause,_}} = (catch lists:zipwith3(Zip, [a], [], [])), + {'EXIT',{function_clause,_}} = (catch lists:zipwith3(badfun, [], [], [])), + {'EXIT',{function_clause,_}} = (catch lists:zipwith3(Zip, [], [], [c])), + {'EXIT',{function_clause,_}} = (catch lists:zipwith3(Zip, [], [b], [])), + {'EXIT',{function_clause,_}} = (catch lists:zipwith3(Zip, [a], [], [])), ok. %% Test lists:filter/2, lists:partition/2. filter_partition(Config) when is_list(Config) -> F = fun(I) -> I rem 2 =:= 0 end, - ?line filpart(F, [], []), - ?line filpart(F, [1], []), - ?line filpart(F, [1,3,17], []), - ?line filpart(F, [1,2,3,17], [2]), - ?line filpart(F, [6,8,1,2,3,17], [6,8,2]), - ?line filpart(F, [6,8,1,2,42,3,17], [6,8,2,42]), + filpart(F, [], []), + filpart(F, [1], []), + filpart(F, [1,3,17], []), + filpart(F, [1,2,3,17], [2]), + filpart(F, [6,8,1,2,3,17], [6,8,2]), + filpart(F, [6,8,1,2,42,3,17], [6,8,2,42]), %% Error cases. - ?line {'EXIT',{function_clause,_}} = (catch lists:filter(badfun, [])), - ?line {'EXIT',{function_clause,_}} = (catch lists:partition(badfun, [])), + {'EXIT',{function_clause,_}} = (catch lists:filter(badfun, [])), + {'EXIT',{function_clause,_}} = (catch lists:partition(badfun, [])), ok. filpart(F, All, Exp) -> @@ -2528,8 +2434,7 @@ filpart(F, All, Exp) -> {Exp,Other} = lists:partition(F, All). -otp_5939(doc) -> ["OTP-5939. Guard tests added."]; -otp_5939(suite) -> []; +%% OTP-5939. Guard tests added. otp_5939(Config) when is_list(Config) -> Fun1 = fun(A) -> A end, Fun2 = fun(A, B) -> {A,B} end, @@ -2538,163 +2443,161 @@ otp_5939(Config) when is_list(Config) -> Fold = fun(_E, A) -> A end, MapFold = fun(E, A) -> {E,A} end, - ?line {'EXIT', _} = (catch lists:usort( [asd], [qwe])), - - ?line {'EXIT', _} = (catch lists:zipwith(func, [], [])), - ?line [] = lists:zipwith(Fun2, [], []), - ?line {'EXIT', _} = (catch lists:zipwith3(func, [], [], [])), - ?line [] = lists:zipwith3(Fun3, [], [], []), - ?line {'EXIT', _} = (catch lists:keymap(func, 1, [])), - ?line {'EXIT', _} = (catch lists:keymap(Fun1, 0, [])), - ?line [] = lists:keymap(Fun1, 1, []), - ?line {'EXIT', _} = (catch lists:merge(func, [], [1])), - ?line {'EXIT', _} = (catch lists:merge(func, [1], [])), - ?line [] = lists:merge(Fun2, [], []), - ?line {'EXIT', _} = (catch lists:rmerge(func, [], [1])), - ?line {'EXIT', _} = (catch lists:rmerge(func, [1], [])), - ?line [] = lists:rmerge(Fun2, [], []), - ?line {'EXIT', _} = (catch lists:usort(func, [])), - ?line {'EXIT', _} = (catch lists:usort(func, [a])), - ?line {'EXIT', _} = (catch lists:usort(func, [a, b])), - ?line [] = lists:usort(Fun2, []), - ?line {'EXIT', _} = (catch lists:umerge(func, [], [1])), - ?line {'EXIT', _} = (catch lists:merge(func, [1], [])), - ?line [] = lists:umerge(Fun2, [], []), - ?line {'EXIT', _} = (catch lists:rumerge(func, [], [1])), - ?line {'EXIT', _} = (catch lists:rumerge(func, [1], [])), - ?line [] = lists:rumerge(Fun2, [], []), - ?line {'EXIT', _} = (catch lists:all(func, [])), - ?line true = lists:all(Pred, []), - ?line {'EXIT', _} = (catch lists:any(func, [])), - ?line false = lists:any(Pred, []), - ?line {'EXIT', _} = (catch lists:map(func, [])), - ?line [] = lists:map(Fun1, []), - ?line {'EXIT', _} = (catch lists:flatmap(func, [])), - ?line [] = lists:flatmap(Fun1, []), - ?line {'EXIT', _} = (catch lists:foldl(func, [], [])), - ?line [] = lists:foldl(Fold, [], []), - ?line {'EXIT', _} = (catch lists:foldr(func, [], [])), - ?line [] = lists:foldr(Fold, [], []), - ?line {'EXIT', _} = (catch lists:filter(func, [])), - ?line [] = lists:filter(Pred, []), - ?line {'EXIT', _} = (catch lists:partition(func, [])), - ?line {[],[]} = lists:partition(Pred, []), - ?line {'EXIT', _} = (catch lists:filtermap(func, [])), - ?line [] = lists:filtermap(Fun1, []), - ?line {'EXIT', _} = (catch lists:foreach(func, [])), - ?line ok = lists:foreach(Fun1, []), - ?line {'EXIT', _} = (catch lists:mapfoldl(func, [], [])), - ?line {[],[]} = lists:mapfoldl(MapFold, [], []), - ?line {'EXIT', _} = (catch lists:mapfoldr(func, [], [])), - ?line {[],[]} = lists:mapfoldr(MapFold, [], []), - ?line {'EXIT', _} = (catch lists:takewhile(func, [])), - ?line [] = lists:takewhile(Pred, []), - ?line {'EXIT', _} = (catch lists:dropwhile(func, [])), - ?line [] = lists:dropwhile(Pred, []), - ?line {'EXIT', _} = (catch lists:splitwith(func, [])), - ?line {[],[]} = lists:splitwith(Pred, []), - - ok. - -otp_6023(doc) -> ["OTP-6023. lists:keyreplace/4, a typecheck."]; -otp_6023(suite) -> []; + {'EXIT', _} = (catch lists:usort( [asd], [qwe])), + + {'EXIT', _} = (catch lists:zipwith(func, [], [])), + [] = lists:zipwith(Fun2, [], []), + {'EXIT', _} = (catch lists:zipwith3(func, [], [], [])), + [] = lists:zipwith3(Fun3, [], [], []), + {'EXIT', _} = (catch lists:keymap(func, 1, [])), + {'EXIT', _} = (catch lists:keymap(Fun1, 0, [])), + [] = lists:keymap(Fun1, 1, []), + {'EXIT', _} = (catch lists:merge(func, [], [1])), + {'EXIT', _} = (catch lists:merge(func, [1], [])), + [] = lists:merge(Fun2, [], []), + {'EXIT', _} = (catch lists:rmerge(func, [], [1])), + {'EXIT', _} = (catch lists:rmerge(func, [1], [])), + [] = lists:rmerge(Fun2, [], []), + {'EXIT', _} = (catch lists:usort(func, [])), + {'EXIT', _} = (catch lists:usort(func, [a])), + {'EXIT', _} = (catch lists:usort(func, [a, b])), + [] = lists:usort(Fun2, []), + {'EXIT', _} = (catch lists:umerge(func, [], [1])), + {'EXIT', _} = (catch lists:merge(func, [1], [])), + [] = lists:umerge(Fun2, [], []), + {'EXIT', _} = (catch lists:rumerge(func, [], [1])), + {'EXIT', _} = (catch lists:rumerge(func, [1], [])), + [] = lists:rumerge(Fun2, [], []), + {'EXIT', _} = (catch lists:all(func, [])), + true = lists:all(Pred, []), + {'EXIT', _} = (catch lists:any(func, [])), + false = lists:any(Pred, []), + {'EXIT', _} = (catch lists:map(func, [])), + [] = lists:map(Fun1, []), + {'EXIT', _} = (catch lists:flatmap(func, [])), + [] = lists:flatmap(Fun1, []), + {'EXIT', _} = (catch lists:foldl(func, [], [])), + [] = lists:foldl(Fold, [], []), + {'EXIT', _} = (catch lists:foldr(func, [], [])), + [] = lists:foldr(Fold, [], []), + {'EXIT', _} = (catch lists:filter(func, [])), + [] = lists:filter(Pred, []), + {'EXIT', _} = (catch lists:partition(func, [])), + {[],[]} = lists:partition(Pred, []), + {'EXIT', _} = (catch lists:filtermap(func, [])), + [] = lists:filtermap(Fun1, []), + {'EXIT', _} = (catch lists:foreach(func, [])), + ok = lists:foreach(Fun1, []), + {'EXIT', _} = (catch lists:mapfoldl(func, [], [])), + {[],[]} = lists:mapfoldl(MapFold, [], []), + {'EXIT', _} = (catch lists:mapfoldr(func, [], [])), + {[],[]} = lists:mapfoldr(MapFold, [], []), + {'EXIT', _} = (catch lists:takewhile(func, [])), + [] = lists:takewhile(Pred, []), + {'EXIT', _} = (catch lists:dropwhile(func, [])), + [] = lists:dropwhile(Pred, []), + {'EXIT', _} = (catch lists:splitwith(func, [])), + {[],[]} = lists:splitwith(Pred, []), + + ok. + +%% OTP-6023. lists:keyreplace/4, a typecheck. otp_6023(Config) when is_list(Config) -> - ?line {'EXIT', _} = (catch lists:keyreplace(a, 2, [{1,a}], b)), - ?line [{2,b}] = lists:keyreplace(a, 2, [{1,a}], {2,b}), + {'EXIT', _} = (catch lists:keyreplace(a, 2, [{1,a}], b)), + [{2,b}] = lists:keyreplace(a, 2, [{1,a}], {2,b}), ok. -otp_6606(doc) -> ["OTP-6606. sort and keysort bug"]; -otp_6606(suite) -> []; +%% OTP-6606. sort and keysort bug. otp_6606(Config) when is_list(Config) -> I = 1, F = float(1), L1 = [{F,I},{F,F},{I,I},{I,F}], - ?line L1 = lists:keysort(1, L1), - ?line L1 = lists:sort(L1), + L1 = lists:keysort(1, L1), + L1 = lists:sort(L1), L2 = [{I,I},{I,F},{F,I},{F,F}], - ?line L2 = lists:keysort(1, L2), - ?line L2 = lists:sort(L2), + L2 = lists:keysort(1, L2), + L2 = lists:sort(L2), ok. %% Test lists:suffix/2. suffix(Config) when is_list(Config) -> - ?line true = lists:suffix([], []), - ?line true = lists:suffix([], [a]), - ?line true = lists:suffix([], [a,b]), - ?line true = lists:suffix([], [a,b,c]), - ?line true = lists:suffix([a], lists:duplicate(200000, a)), - ?line true = lists:suffix(lists:seq(1, 1024), - lists:seq(2, 64000) ++ lists:seq(1, 1024)), - ?line true = lists:suffix(lists:duplicate(20000, a), - lists:duplicate(200000, a)), - ?line true = lists:suffix([2.0,3.0], [1.0,2.0,3.0]), + true = lists:suffix([], []), + true = lists:suffix([], [a]), + true = lists:suffix([], [a,b]), + true = lists:suffix([], [a,b,c]), + true = lists:suffix([a], lists:duplicate(200000, a)), + true = lists:suffix(lists:seq(1, 1024), + lists:seq(2, 64000) ++ lists:seq(1, 1024)), + true = lists:suffix(lists:duplicate(20000, a), + lists:duplicate(200000, a)), + true = lists:suffix([2.0,3.0], [1.0,2.0,3.0]), %% False cases. - ?line false = lists:suffix([a], []), - ?line false = lists:suffix([a,b,c], []), - ?line false = lists:suffix([a,b,c], [b,c]), - ?line false = lists:suffix([a,b,c], [a,b,c,a,b]), - ?line false = lists:suffix(lists:duplicate(199999, a)++[b], - lists:duplicate(200000, a)), - ?line false = lists:suffix([2.0,3.0], [1,2,3]), + false = lists:suffix([a], []), + false = lists:suffix([a,b,c], []), + false = lists:suffix([a,b,c], [b,c]), + false = lists:suffix([a,b,c], [a,b,c,a,b]), + false = lists:suffix(lists:duplicate(199999, a)++[b], + lists:duplicate(200000, a)), + false = lists:suffix([2.0,3.0], [1,2,3]), %% Error cases. - ?line {'EXIT',_} = (catch lists:suffix({a,b,c}, [])), - ?line {'EXIT',_} = (catch lists:suffix([], {a,b})), - ?line {'EXIT',_} = (catch lists:suffix([a|b], [])), - ?line {'EXIT',_} = (catch lists:suffix([a,b|c], [a|b])), - ?line {'EXIT',_} = (catch lists:suffix([a|b], [a,b|c])), - ?line {'EXIT',_} = (catch lists:suffix([a|b], [a|b])), - + {'EXIT',_} = (catch lists:suffix({a,b,c}, [])), + {'EXIT',_} = (catch lists:suffix([], {a,b})), + {'EXIT',_} = (catch lists:suffix([a|b], [])), + {'EXIT',_} = (catch lists:suffix([a,b|c], [a|b])), + {'EXIT',_} = (catch lists:suffix([a|b], [a,b|c])), + {'EXIT',_} = (catch lists:suffix([a|b], [a|b])), + ok. %% Test lists:subtract/2 and the '--' operator. subtract(Config) when is_list(Config) -> - ?line [] = sub([], []), - ?line [] = sub([], [a]), - ?line [] = sub([], lists:seq(1, 1024)), - ?line sub_non_matching([a], []), - ?line sub_non_matching([1,2], [make_ref()]), - ?line sub_non_matching(lists:seq(1, 1024), [make_ref(),make_ref()]), - + [] = sub([], []), + [] = sub([], [a]), + [] = sub([], lists:seq(1, 1024)), + sub_non_matching([a], []), + sub_non_matching([1,2], [make_ref()]), + sub_non_matching(lists:seq(1, 1024), [make_ref(),make_ref()]), + %% Matching subtracts. - ?line [] = sub([a], [a]), - ?line [a] = sub([a,b], [b]), - ?line [a] = sub([a,b], [b,c]), - ?line [a] = sub([a,b,c], [b,c]), - ?line [a] = sub([a,b,c], [b,c]), - ?line [d,a,a] = sub([a,b,c,d,a,a], [a,b,c]), - ?line [d,x,a] = sub([a,b,c,d,a,x,a], [a,b,c,a]), - ?line [1,2,3,4,5,6,7,8,9,9999,10000,20,21,22] = + [] = sub([a], [a]), + [a] = sub([a,b], [b]), + [a] = sub([a,b], [b,c]), + [a] = sub([a,b,c], [b,c]), + [a] = sub([a,b,c], [b,c]), + [d,a,a] = sub([a,b,c,d,a,a], [a,b,c]), + [d,x,a] = sub([a,b,c,d,a,x,a], [a,b,c,a]), + [1,2,3,4,5,6,7,8,9,9999,10000,20,21,22] = sub(lists:seq(1, 10000)++[20,21,22], lists:seq(10, 9998)), %% Floats/integers. - ?line [42.0,42.0] = sub([42.0,42,42.0], [42,42,42]), - ?line [1,2,3,4,43.0] = sub([1,2,3,4,5,42.0,43.0], [42.0,5]), + [42.0,42.0] = sub([42.0,42,42.0], [42,42,42]), + [1,2,3,4,43.0] = sub([1,2,3,4,5,42.0,43.0], [42.0,5]), %% Crashing subtracts. - ?line {'EXIT',_} = (catch sub([], [a|b])), - ?line {'EXIT',_} = (catch sub([a], [a|b])), - ?line {'EXIT',_} = (catch sub([a|b], [])), - ?line {'EXIT',_} = (catch sub([a|b], [])), - ?line {'EXIT',_} = (catch sub([a|b], [a])), + {'EXIT',_} = (catch sub([], [a|b])), + {'EXIT',_} = (catch sub([a], [a|b])), + {'EXIT',_} = (catch sub([a|b], [])), + {'EXIT',_} = (catch sub([a|b], [])), + {'EXIT',_} = (catch sub([a|b], [a])), ok. sub_non_matching(A, B) -> A = sub(A, B). - + sub(A, B) -> Res = A -- B, Res = lists:subtract(A, B). %% Test lists:droplast/1 droplast(Config) when is_list(Config) -> - ?line [] = lists:droplast([x]), - ?line [x] = lists:droplast([x, y]), - ?line {'EXIT', {function_clause, _}} = (catch lists:droplast([])), - ?line {'EXIT', {function_clause, _}} = (catch lists:droplast(x)), + [] = lists:droplast([x]), + [x] = lists:droplast([x, y]), + {'EXIT', {function_clause, _}} = (catch lists:droplast([])), + {'EXIT', {function_clause, _}} = (catch lists:droplast(x)), ok. diff --git a/lib/stdlib/test/log_mf_h_SUITE.erl b/lib/stdlib/test/log_mf_h_SUITE.erl index 70d03dd46f..9b543aa37c 100644 --- a/lib/stdlib/test/log_mf_h_SUITE.erl +++ b/lib/stdlib/test/log_mf_h_SUITE.erl @@ -53,17 +53,17 @@ end_per_group(_GroupName, Config) -> %%----------------------------------------------------------------- test(Config) when is_list(Config) -> - ?line {ok, Pid} = gen_event:start_link(), - ?line PrivDir = ?config(priv_dir, Config), + {ok, Pid} = gen_event:start_link(), + PrivDir = proplists:get_value(priv_dir, Config), Log1 = PrivDir ++ "/log1", - ?line ok = file:make_dir(Log1), + ok = file:make_dir(Log1), Args1 = log_mf_h:init(Log1, 500, 3), gen_event:add_handler(Pid, log_mf_h, Args1), generate(Pid, 200), {ok, Files} = file:list_dir(Log1), - ?line true = lists:member("1", Files), - ?line true = lists:member("index", Files), - ?line false = lists:member("2", Files), + true = lists:member("1", Files), + true = lists:member("index", Files), + false = lists:member("2", Files), generate(Pid, 2500), %% The documentation doesn't guarantee that syncing one request %% causes all previous ones to be finished too, but that seems to @@ -71,26 +71,26 @@ test(Config) when is_list(Config) -> %% look for them with 'list_dir'. gen_event:sync_notify(Pid, "end"), {ok, Files2} = file:list_dir(Log1), - ?line true = lists:member("1", Files2), - ?line true = lists:member("2", Files2), - ?line true = lists:member("3", Files2), - ?line false = lists:member("4", Files2), - ?line true = lists:member("index", Files2), - ?line {ok, #file_info{size=Size1,type=regular}} = file:read_file_info(Log1 ++ "/1"), - ?line if Size1 > 500 -> test_server:fail({too_big, Size1}); - true -> ok end, - ?line {ok, #file_info{size=Size2,type=regular}} = file:read_file_info(Log1 ++ "/2"), - ?line if Size2 > 500 -> test_server:fail({too_big, Size2}); - true -> ok end, - ?line {ok, #file_info{size=Size3,type=regular}} = file:read_file_info(Log1 ++ "/3"), - ?line if Size3 > 500 -> test_server:fail({too_big, Size3}); - true -> ok end, + true = lists:member("1", Files2), + true = lists:member("2", Files2), + true = lists:member("3", Files2), + false = lists:member("4", Files2), + true = lists:member("index", Files2), + {ok, #file_info{size=Size1,type=regular}} = file:read_file_info(Log1 ++ "/1"), + if Size1 > 500 -> ct:fail({too_big, Size1}); + true -> ok end, + {ok, #file_info{size=Size2,type=regular}} = file:read_file_info(Log1 ++ "/2"), + if Size2 > 500 -> ct:fail({too_big, Size2}); + true -> ok end, + {ok, #file_info{size=Size3,type=regular}} = file:read_file_info(Log1 ++ "/3"), + if Size3 > 500 -> ct:fail({too_big, Size3}); + true -> ok end, gen_event:delete_handler(Pid, log_mf_h, []), - ?line {ok, Index} = read_index_file(Log1), + {ok, Index} = read_index_file(Log1), gen_event:add_handler(Pid, log_mf_h, Args1), X = if Index == 3 -> 1; true -> Index + 1 end, - ?line {ok, X} = read_index_file(Log1). - + {ok, X} = read_index_file(Log1). + generate(Pid, Bytes) when Bytes > 32 -> gen_event:notify(Pid, make_list(32, [])), @@ -110,4 +110,3 @@ read_index_file(Dir) -> end; _ -> error end. - diff --git a/lib/stdlib/test/maps_SUITE.erl b/lib/stdlib/test/maps_SUITE.erl index f1f476433b..7f94b7bcb1 100644 --- a/lib/stdlib/test/maps_SUITE.erl +++ b/lib/stdlib/test/maps_SUITE.erl @@ -25,9 +25,7 @@ -include_lib("common_test/include/ct.hrl"). --define(default_timeout, ?t:minutes(1)). - -% Test server specific exports +%% Test server specific exports -export([all/0]). -export([suite/0]). -export([init_per_suite/1]). @@ -39,14 +37,15 @@ t_fold_3/1,t_map_2/1,t_size_1/1, t_with_2/1,t_without_2/1]). -%-define(badmap(V,F,Args), {'EXIT', {{badmap,V}, [{maps,F,Args,_}|_]}}). -%-define(badarg(F,Args), {'EXIT', {badarg, [{maps,F,Args,_}|_]}}). -% silly broken hipe +%%-define(badmap(V,F,Args), {'EXIT', {{badmap,V}, [{maps,F,Args,_}|_]}}). +%%-define(badarg(F,Args), {'EXIT', {badarg, [{maps,F,Args,_}|_]}}). +%% silly broken hipe -define(badmap(V,F,_Args), {'EXIT', {{badmap,V}, [{maps,F,_,_}|_]}}). -define(badarg(F,_Args), {'EXIT', {badarg, [{maps,F,_,_}|_]}}). suite() -> - [{ct_hooks, [ts_install_cth]}]. + [{ct_hooks, [ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [t_get_3,t_filter_2, @@ -60,12 +59,9 @@ end_per_suite(_Config) -> ok. init_per_testcase(_Case, Config) -> - Dog=test_server:timetrap(?default_timeout), - [{watchdog, Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. t_get_3(Config) when is_list(Config) -> diff --git a/lib/stdlib/test/ms_transform_SUITE.erl b/lib/stdlib/test/ms_transform_SUITE.erl index 6a9478d0d2..a8bd90de84 100644 --- a/lib/stdlib/test/ms_transform_SUITE.erl +++ b/lib/stdlib/test/ms_transform_SUITE.erl @@ -23,6 +23,7 @@ -include_lib("common_test/include/ct.hrl"). -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, + init_per_testcase/2, end_per_testcase/2, init_per_group/2,end_per_group/2]). -export([basic_ets/1]). -export([basic_dbg/1]). @@ -42,17 +43,16 @@ -export([warnings/1]). -export([no_warnings/1]). -export([eep37/1]). --export([init_per_testcase/2, end_per_testcase/2]). init_per_testcase(_Func, Config) -> - Dog=test_server:timetrap(test_server:seconds(360)), - [{watchdog, Dog}|Config]. + Config. -end_per_testcase(_Func, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog). +end_per_testcase(_Func, _Config) -> + ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,6}}]. all() -> [from_shell, basic_ets, basic_dbg, records, @@ -79,94 +79,89 @@ end_per_group(_GroupName, Config) -> %% This may be subject to change -define(WARN_NUMBER_SHADOW,50). -warnings(suite) -> - []; -warnings(doc) -> - ["Check that shadowed variables in fun head generate warning"]; + +%% Check that shadowed variables in fun head generate warning. warnings(Config) when is_list(Config) -> - ?line setup(Config), + setup(Config), Prog = <<"A=5, " - "ets:fun2ms(fun({A,B}) " - " when is_integer(A) and (A+5 > B) -> " - " A andalso B " - " end)">>, - ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'A'}}]}] = + "ets:fun2ms(fun({A,B}) " + " when is_integer(A) and (A+5 > B) -> " + " A andalso B " + " end)">>, + [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'A'}}]}] = compile_ww(Prog), Prog2 = <<"C = 5, ets:fun2ms(fun ({A,B} = - C) when is_integer(A) and (A+5 > B) -> + C) when is_integer(A) and (A+5 > B) -> {A andalso B,C} end)">>, [{_,[{3,ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] = - compile_ww(Prog2), - Rec3 = <<"-record(a,{a,b,c,d=foppa}).">>, - Prog3 = <<"A = 3, + compile_ww(Prog2), + Rec3 = <<"-record(a,{a,b,c,d=foppa}).">>, + Prog3 = <<"A = 3, C = 5, - ets:fun2ms(fun (C - = #a{a = A, b = B}) - when is_integer(A) and (A+5 > B) -> - {A andalso B,C} - end)">>, + ets:fun2ms(fun (C + = #a{a = A, b = B}) + when is_integer(A) and (A+5 > B) -> + {A andalso B,C} + end)">>, [{_,[{3,ms_transform,{?WARN_NUMBER_SHADOW,'C'}}, {4,ms_transform,{?WARN_NUMBER_SHADOW,'A'}}]}] = - compile_ww(Rec3,Prog3), - Rec4 = <<"-record(a,{a,b,c,d=foppa}).">>, - Prog4 = <<"A=3,C=5, " - "F = fun(B) -> B*3 end," - "erlang:display(F(A))," - "ets:fun2ms(fun(#a{a = A, b = B} = C) " - " when is_integer(A) and (A+5 > B) -> " - " {A andalso B,C} " - " end)">>, - ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'A'}}, - {_,ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] = - compile_ww(Rec4,Prog4), - Rec5 = <<"-record(a,{a,b,c,d=foppa}).">>, - Prog5 = <<"A=3,C=5, " - "F = fun(B) -> B*3 end," - "erlang:display(F(A))," - "B = ets:fun2ms(fun(#a{a = A, b = B} = C) " - " when is_integer(A) and (A+5 > B) -> " - " {A andalso B,C} " - " end)">>, - ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'A'}}, - {_,ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] = - compile_ww(Rec5,Prog5), - Prog6 = <<" X=bar, " - " A = case X of" - " foo ->" - " foo;" - " Y ->" - " ets:fun2ms(fun(Y) ->" % This is a warning - " 3*Y" - " end)" - " end," - " ets:fun2ms(fun(Y) ->" % Y out of "scope" here, so no warning - " {3*Y,A}" - " end)">>, - ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'Y'}}]}] = - compile_ww(Prog6), - Prog7 = <<" X=bar, " - " A = case X of" - " foo ->" - " Y = foo;" - " Y ->" - " bar" - " end," - " ets:fun2ms(fun(Y) ->" % Y exported from case and safe, so warn - " {3*Y,A}" - " end)">>, - ?line [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'Y'}}]}] = - compile_ww(Prog7), - ok. - -no_warnings(suite) -> - []; -no_warnings(doc) -> - ["Check that variables bound in other function clauses don't generate " - "warning"]; + compile_ww(Rec3,Prog3), + Rec4 = <<"-record(a,{a,b,c,d=foppa}).">>, + Prog4 = <<"A=3,C=5, " + "F = fun(B) -> B*3 end," + "erlang:display(F(A))," + "ets:fun2ms(fun(#a{a = A, b = B} = C) " + " when is_integer(A) and (A+5 > B) -> " + " {A andalso B,C} " + " end)">>, + [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'A'}}, + {_,ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] = + compile_ww(Rec4,Prog4), + Rec5 = <<"-record(a,{a,b,c,d=foppa}).">>, + Prog5 = <<"A=3,C=5, " + "F = fun(B) -> B*3 end," + "erlang:display(F(A))," + "B = ets:fun2ms(fun(#a{a = A, b = B} = C) " + " when is_integer(A) and (A+5 > B) -> " + " {A andalso B,C} " + " end)">>, + [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'A'}}, + {_,ms_transform,{?WARN_NUMBER_SHADOW,'C'}}]}] = + compile_ww(Rec5,Prog5), + Prog6 = <<" X=bar, " + " A = case X of" + " foo ->" + " foo;" + " Y ->" + " ets:fun2ms(fun(Y) ->" % This is a warning + " 3*Y" + " end)" + " end," + " ets:fun2ms(fun(Y) ->" % Y out of "scope" here, so no warning + " {3*Y,A}" + " end)">>, + [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'Y'}}]}] = + compile_ww(Prog6), + Prog7 = <<" X=bar, " + " A = case X of" + " foo ->" + " Y = foo;" + " Y ->" + " bar" + " end," + " ets:fun2ms(fun(Y) ->" % Y exported from case and safe, so warn + " {3*Y,A}" + " end)">>, + [{_,[{_,ms_transform,{?WARN_NUMBER_SHADOW,'Y'}}]}] = + compile_ww(Prog7), + ok. + +%% Check that variables bound in other function clauses don't generate +%% warning. no_warnings(Config) when is_list(Config) -> - ?line setup(Config), + setup(Config), Prog = <<"tmp(X) when X > 100 ->\n", " Y=X,\n" " Y;\n" @@ -174,188 +169,167 @@ no_warnings(Config) when is_list(Config) -> " ets:fun2ms(fun(Y) ->\n" " {X, 3*Y}\n" " end)">>, - ?line [] = compile_no_ww(Prog), + [] = compile_no_ww(Prog), Prog2 = <<"tmp(X) when X > 100 ->\n", - " Y=X,\n" - " Y;\n" - "tmp(X) when X < 200 ->\n" - " ok;\n" - "tmp(X) ->\n" - " ets:fun2ms(fun(Y) ->\n" - " {X, 3*Y}\n" - " end)">>, - ?line [] = compile_no_ww(Prog2), + " Y=X,\n" + " Y;\n" + "tmp(X) when X < 200 ->\n" + " ok;\n" + "tmp(X) ->\n" + " ets:fun2ms(fun(Y) ->\n" + " {X, 3*Y}\n" + " end)">>, + [] = compile_no_ww(Prog2), ok. -andalso_orelse(suite) -> - []; -andalso_orelse(doc) -> - ["Tests that andalso and orelse are allowed in guards."]; +%% Test that andalso and orelse are allowed in guards. andalso_orelse(Config) when is_list(Config) -> - ?line setup(Config), - ?line [{{'$1','$2'}, - [{'and',{is_integer,'$1'},{'>',{'+','$1',5},'$2'}}], - [{'andalso','$1','$2'}]}] = + setup(Config), + [{{'$1','$2'}, + [{'and',{is_integer,'$1'},{'>',{'+','$1',5},'$2'}}], + [{'andalso','$1','$2'}]}] = compile_and_run(<<"ets:fun2ms(fun({A,B}) " - " when is_integer(A) and (A+5 > B) -> " - " A andalso B " - " end)">>), - ?line [{{'$1','$2'}, - [{'or',{is_atom,'$1'},{'>',{'+','$1',5},'$2'}}], - [{'orelse','$1','$2'}]}] = + " when is_integer(A) and (A+5 > B) -> " + " A andalso B " + " end)">>), + [{{'$1','$2'}, + [{'or',{is_atom,'$1'},{'>',{'+','$1',5},'$2'}}], + [{'orelse','$1','$2'}]}] = compile_and_run(<<"ets:fun2ms(fun({A,B}) " - " when is_atom(A) or (A+5 > B) -> " - " A orelse B " - " end)">>), - ?line [{{'$1','$2'}, - [{'andalso',{is_integer,'$1'},{'>',{'+','$1',5},'$2'}}], - ['$1']}] = + " when is_atom(A) or (A+5 > B) -> " + " A orelse B " + " end)">>), + [{{'$1','$2'}, + [{'andalso',{is_integer,'$1'},{'>',{'+','$1',5},'$2'}}], + ['$1']}] = compile_and_run( - <<"ets:fun2ms(fun({A,B}) when is_integer(A) andalso (A+5 > B) ->" - " A " - " end)">>), - ?line [{{'$1','$2'}, - [{'orelse',{is_atom,'$1'},{'>',{'+','$1',5},'$2'}}], - ['$1']}] = + <<"ets:fun2ms(fun({A,B}) when is_integer(A) andalso (A+5 > B) ->" + " A " + " end)">>), + [{{'$1','$2'}, + [{'orelse',{is_atom,'$1'},{'>',{'+','$1',5},'$2'}}], + ['$1']}] = compile_and_run( - <<"ets:fun2ms(fun({A,B}) when is_atom(A) orelse (A+5 > B) -> " - " A " - " end)">>), + <<"ets:fun2ms(fun({A,B}) when is_atom(A) orelse (A+5 > B) -> " + " A " + " end)">>), ok. - - -bitsyntax(suite) -> - []; -bitsyntax(doc) -> - ["Tests that bitsyntax works and does not work where appropriate"]; + + +%% Test that bitsyntax works and does not work where appropriate. bitsyntax(Config) when is_list(Config) -> - ?line setup(Config), - ?line [{'_',[], - [<<0,27,0,27>>]}] = + setup(Config), + [{'_',[], + [<<0,27,0,27>>]}] = compile_and_run(<<"A = 27, " "ets:fun2ms(fun(_) -> <<A:16,27:16>> end)">>), - ?line [{{<<15,47>>, - '$1', - '$2'}, - [{'=:=','$1', - <<0,27>>}, - {'=:=','$2', - <<27,28,19>>}], - [<<188,0,13>>]}] = + [{{<<15,47>>, + '$1', + '$2'}, + [{'=:=','$1', + <<0,27>>}, + {'=:=','$2', + <<27,28,19>>}], + [<<188,0,13>>]}] = compile_and_run(<<"A = 27, " "ets:fun2ms(" " fun({<<15,47>>,B,C}) " " when B =:= <<A:16>>, C =:= <<27,28,19>> -> " " <<A:4,12:4,13:16>> " " end)">>), - ?line expect_failure( - <<>>, - <<"ets:fun2ms(fun({<<15,47>>,B,C}) " - " when B =:= <<16>>, C =:= <<27,28,19>> -> " - " <<B:4,12:4,13:16>> " - " end)">>), - ?line expect_failure( - <<>>, - <<"ets:fun2ms(fun({<<A:15,47>>,B,C}) " - " when B =:= <<16>>, C =:= <<27,28,19>> -> " - " <<B:4,12:4,13:16>> " - " end)">>), + expect_failure( + <<>>, + <<"ets:fun2ms(fun({<<15,47>>,B,C}) " + " when B =:= <<16>>, C =:= <<27,28,19>> -> " + " <<B:4,12:4,13:16>> " + " end)">>), + expect_failure( + <<>>, + <<"ets:fun2ms(fun({<<A:15,47>>,B,C}) " + " when B =:= <<16>>, C =:= <<27,28,19>> -> " + " <<B:4,12:4,13:16>> " + " end)">>), ok. -record_defaults(suite) -> - []; -record_defaults(doc) -> - ["Tests that record defaults works"]; +%% Test that record defaults works. record_defaults(Config) when is_list(Config) -> - ?line setup(Config), - ?line [{{<<27>>,{a,5,'$1',hej,hej}}, - [], - [{{a,hej,{'*','$1',2},flurp,flurp}}]}] = + setup(Config), + [{{<<27>>,{a,5,'$1',hej,hej}}, + [], + [{{a,hej,{'*','$1',2},flurp,flurp}}]}] = compile_and_run(<<"-record(a,{a,b,c,d=foppa}).">>, <<"ets:fun2ms(fun({<<27>>,#a{a=5, b=B,_=hej}}) -> " - "#a{a=hej,b=B*2,_=flurp} " - "end)">>), + "#a{a=hej,b=B*2,_=flurp} " + "end)">>), ok. -basic_ets(suite) -> - []; -basic_ets(doc) -> - ["Tests basic ets:fun2ms"]; +%% Test basic ets:fun2ms. basic_ets(Config) when is_list(Config) -> - ?line setup(Config), - ?line [{{a,b},[],[true]}] = compile_and_run( - <<"ets:fun2ms(fun({a,b}) -> true end)">>), - ?line [{{'$1',foo},[{is_list,'$1'}],[{{{hd,'$1'},'$_'}}]}, + setup(Config), + [{{a,b},[],[true]}] = compile_and_run( + <<"ets:fun2ms(fun({a,b}) -> true end)">>), + [{{'$1',foo},[{is_list,'$1'}],[{{{hd,'$1'},'$_'}}]}, {{'$1','$1'},[{is_tuple,'$1'}],[{{{element,1,'$1'},'$*'}}]}] = compile_and_run(<<"ets:fun2ms(fun({X,foo}) when is_list(X) -> ", - "{hd(X),object()};", - "({X,X}) when is_tuple(X) ->", - "{element(1,X),bindings()}", - "end)">>), - ?line [{{'$1','$2'},[],[{{'$2','$1'}}]}] = + "{hd(X),object()};", + "({X,X}) when is_tuple(X) ->", + "{element(1,X),bindings()}", + "end)">>), + [{{'$1','$2'},[],[{{'$2','$1'}}]}] = compile_and_run(<<"ets:fun2ms(fun({A,B}) -> {B,A} end)">>), - ?line [{{'$1','$2'},[],[['$2','$1']]}] = + [{{'$1','$2'},[],[['$2','$1']]}] = compile_and_run(<<"ets:fun2ms(fun({A,B}) -> [B,A] end)">>), ok. -basic_dbg(suite) -> - []; -basic_dbg(doc) -> - ["Tests basic ets:fun2ms"]; +%% Tests basic ets:fun2ms. basic_dbg(Config) when is_list(Config) -> - ?line setup(Config), - ?line [{[a,b],[],[{message,banan},{return_trace}]}] = + setup(Config), + [{[a,b],[],[{message,banan},{return_trace}]}] = compile_and_run(<<"dbg:fun2ms(fun([a,b]) -> message(banan), ", - "return_trace() end)">>), - ?line [{['$1','$2'],[],[{{'$2','$1'}}]}] = + "return_trace() end)">>), + [{['$1','$2'],[],[{{'$2','$1'}}]}] = compile_and_run(<<"dbg:fun2ms(fun([A,B]) -> {B,A} end)">>), - ?line [{['$1','$2'],[],[['$2','$1']]}] = + [{['$1','$2'],[],[['$2','$1']]}] = compile_and_run(<<"dbg:fun2ms(fun([A,B]) -> [B,A] end)">>), - ?line [{['$1','$2'],[],['$*']}] = + [{['$1','$2'],[],['$*']}] = compile_and_run(<<"dbg:fun2ms(fun([A,B]) -> bindings() end)">>), - ?line [{['$1','$2'],[],['$_']}] = + [{['$1','$2'],[],['$_']}] = compile_and_run(<<"dbg:fun2ms(fun([A,B]) -> object() end)">>), ok. -from_shell(suite) -> - []; -from_shell(doc) -> - ["Test calling of ets/dbg:fun2ms from the shell"]; +%% Test calling of ets/dbg:fun2ms from the shell. from_shell(Config) when is_list(Config) -> - ?line setup(Config), - ?line Fun = do_eval("fun({a,b}) -> true end"), - ?line [{{a,b},[],[true]}] = apply(ets,fun2ms,[Fun]), - ?line [{{a,b},[],[true]}] = do_eval("ets:fun2ms(fun({a,b}) -> true end)"), - ?line Fun2 = do_eval("fun([a,b]) -> message(banan), return_trace() end"), - ?line [{[a,b],[],[{message,banan},{return_trace}]}] + setup(Config), + Fun = do_eval("fun({a,b}) -> true end"), + [{{a,b},[],[true]}] = apply(ets,fun2ms,[Fun]), + [{{a,b},[],[true]}] = do_eval("ets:fun2ms(fun({a,b}) -> true end)"), + Fun2 = do_eval("fun([a,b]) -> message(banan), return_trace() end"), + [{[a,b],[],[{message,banan},{return_trace}]}] = apply(dbg,fun2ms,[Fun2]), - ?line [{[a,b],[],[{message,banan},{return_trace}]}] = + [{[a,b],[],[{message,banan},{return_trace}]}] = do_eval( "dbg:fun2ms(fun([a,b]) -> message(banan), return_trace() end)"), ok. -records(suite) -> - []; -records(doc) -> - ["Tests expansion of records in fun2ms"]; +%% Tests expansion of records in fun2ms. records(Config) when is_list(Config) -> - ?line setup(Config), - ?line RD = <<"-record(t, {" - "t1 = [] :: list()," - "t2 = foo :: atom()," - "t3," - "t4" - "}).">>, - ?line [{{t,'$1','$2',foo,'_'},[{is_list,'$1'}],[{{{hd,'$1'},'$_'}}]}, + setup(Config), + RD = <<"-record(t, {" + "t1 = [] :: list()," + "t2 = foo :: atom()," + "t3," + "t4" + "}).">>, + [{{t,'$1','$2',foo,'_'},[{is_list,'$1'}],[{{{hd,'$1'},'$_'}}]}, {{t,'_','_','_','_'},[{'==',{element,2,'$_'},nisse}],[{{'$*'}}]}] = compile_and_run(RD,<< - "ets:fun2ms(fun(#t{t1 = X, t2 = Y, t3 = foo}) when is_list(X) -> + "ets:fun2ms(fun(#t{t1 = X, t2 = Y, t3 = foo}) when is_list(X) -> {hd(X),object()}; - (#t{}) when (object())#t.t1 == nisse -> - {bindings()} - end)">>), - ?line [{{t,'$1','$2','_',foo}, + (#t{}) when (object())#t.t1 == nisse -> + {bindings()} + end)">>), + [{{t,'$1','$2','_',foo}, [{'==',{element,4,'$_'},7},{is_list,'$1'}], [{{{hd,'$1'},'$_'}}]}, {'$1',[{is_record,'$1',t,5}], @@ -373,7 +347,7 @@ records(Config) when is_list(Config) -> } end)" >>), - ?line [{[{t,'$1','$2',foo,'_'}],[{is_list,'$1'}],[{{{hd,'$1'},'$_'}}]}, + [{[{t,'$1','$2',foo,'_'}],[{is_list,'$1'}],[{{{hd,'$1'},'$_'}}]}, {[{t,'_','_','_','_'}],[{'==',{element,2,{hd,'$_'}},nisse}],[{{'$*'}}]}]= compile_and_run(RD,<< "dbg:fun2ms(fun([#t{t1 = X, t2 = Y, t3 = foo}]) when is_list(X) -> @@ -385,78 +359,66 @@ records(Config) when is_list(Config) -> ok. -record_index(suite) -> - []; -record_index(doc) -> - ["Tests expansion of records in fun2ms, part 2"]; +%% Test expansion of records in fun2ms, part 2. record_index(Config) when is_list(Config) -> - ?line setup(Config), - ?line RD = <<"-record(a,{a,b}).">>, - ?line [{{2},[],[true]}] = compile_and_run(RD, + setup(Config), + RD = <<"-record(a,{a,b}).">>, + [{{2},[],[true]}] = compile_and_run(RD, <<"ets:fun2ms(fun({#a.a}) -> true end)">>), - ?line [{{2},[],[2]}] = compile_and_run(RD, + [{{2},[],[2]}] = compile_and_run(RD, <<"ets:fun2ms(fun({#a.a}) -> #a.a end)">>), - ?line [{{2,'$1'},[{'>','$1',2}],[2]}] = compile_and_run(RD, + [{{2,'$1'},[{'>','$1',2}],[2]}] = compile_and_run(RD, <<"ets:fun2ms(fun({#a.a,A}) when A > #a.a -> #a.a end)">>), ok. -top_match(suite) -> - []; -top_match(doc) -> - ["Tests matching on top level in head to give alias for object()"]; +%% Tests matching on top level in head to give alias for object(). top_match(Config) when is_list(Config) -> - ?line setup(Config), - ?line RD = <<"-record(a,{a,b}).">>, - ?line [{{a,3,'_'},[],['$_']}] = + setup(Config), + RD = <<"-record(a,{a,b}).">>, + [{{a,3,'_'},[],['$_']}] = compile_and_run(RD, <<"ets:fun2ms(fun(A = #a{a=3}) -> A end)">>), - ?line [{{a,3,'_'},[],['$_']}] = + [{{a,3,'_'},[],['$_']}] = compile_and_run(RD, <<"ets:fun2ms(fun(#a{a=3} = A) -> A end)">>), - ?line [{[a,b],[],['$_']}] = + [{[a,b],[],['$_']}] = compile_and_run(RD, <<"dbg:fun2ms(fun(A = [a,b]) -> A end)">>), - ?line [{[a,b],[],['$_']}] = + [{[a,b],[],['$_']}] = compile_and_run(RD, <<"dbg:fun2ms(fun([a,b] = A) -> A end)">>), - ?line expect_failure(RD, + expect_failure(RD, <<"ets:fun2ms(fun({a,A = {_,b}}) -> A end)">>), - ?line expect_failure(RD, + expect_failure(RD, <<"dbg:fun2ms(fun([a,A = {_,b}]) -> A end)">>), - ?line expect_failure(RD, + expect_failure(RD, <<"ets:fun2ms(fun(A#a{a = 2}) -> A end)">>), ok. -multipass(suite) -> - []; -multipass(doc) -> - ["Tests that multi-defined fields in records give errors."]; +%% Tests that multi-defined fields in records give errors. multipass(Config) when is_list(Config) -> - ?line setup(Config), - ?line RD = <<"-record(a,{a,b}).">>, - ?line expect_failure(RD,<<"ets:fun2ms(fun(A) -> #a{a=2,a=3} end)">>), - ?line expect_failure(RD,<<"ets:fun2ms(fun(A) -> A#a{a=2,a=3} end)">>), - ?line expect_failure(RD,<<"ets:fun2ms(fun(A) when A =:= #a{a=2,a=3} ->", + setup(Config), + RD = <<"-record(a,{a,b}).">>, + expect_failure(RD,<<"ets:fun2ms(fun(A) -> #a{a=2,a=3} end)">>), + expect_failure(RD,<<"ets:fun2ms(fun(A) -> A#a{a=2,a=3} end)">>), + expect_failure(RD,<<"ets:fun2ms(fun(A) when A =:= #a{a=2,a=3} ->", " true end)">>), - ?line expect_failure(RD,<<"ets:fun2ms(fun({A,B})when A =:= B#a{a=2,a=3}->", + expect_failure(RD,<<"ets:fun2ms(fun({A,B})when A =:= B#a{a=2,a=3}->", "true end)">>), - ?line expect_failure(RD,<<"ets:fun2ms(fun(#a{a=3,a=3}) -> true end)">>), - ?line compile_and_run(RD,<<"ets:fun2ms(fun(A) -> #a{a=2,b=3} end)">>), - ?line compile_and_run(RD,<<"ets:fun2ms(fun(A) -> A#a{a=2,b=3} end)">>), - ?line compile_and_run(RD,<<"ets:fun2ms(fun(A) when A =:= #a{a=2,b=3} ->", + expect_failure(RD,<<"ets:fun2ms(fun(#a{a=3,a=3}) -> true end)">>), + compile_and_run(RD,<<"ets:fun2ms(fun(A) -> #a{a=2,b=3} end)">>), + compile_and_run(RD,<<"ets:fun2ms(fun(A) -> A#a{a=2,b=3} end)">>), + compile_and_run(RD,<<"ets:fun2ms(fun(A) when A =:= #a{a=2,b=3} ->", " true end)">>), - ?line compile_and_run(RD,<<"ets:fun2ms(fun({A,B})when A=:= B#a{a=2,b=3}->", + compile_and_run(RD,<<"ets:fun2ms(fun({A,B})when A=:= B#a{a=2,b=3}->", "true end)">>), - ?line compile_and_run(RD,<<"ets:fun2ms(fun(#a{a=3,b=3}) -> true end)">>), + compile_and_run(RD,<<"ets:fun2ms(fun(#a{a=3,b=3}) -> true end)">>), ok. -old_guards(suite) -> - []; -old_guards(doc) -> - ["Tests that old type tests in guards are translated"]; +%% Test that old type tests in guards are translated. old_guards(Config) when is_list(Config) -> - ?line setup(Config), + setup(Config), Tests = [ {atom,is_atom}, {float,is_float}, @@ -469,7 +431,7 @@ old_guards(Config) when is_list(Config) -> {tuple,is_tuple}, {binary,is_binary}, {function,is_function}], - ?line lists:foreach( + lists:foreach( fun({Old,New}) -> Bin = list_to_binary([<<"ets:fun2ms(fun(X) when ">>, atom_to_list(Old), @@ -482,15 +444,15 @@ old_guards(Config) when is_list(Config) -> end end, Tests), - ?line RD = <<"-record(a,{a,b}).">>, - ?line [{'$1',[{is_record,'$1',a,3}],[true]}] = + RD = <<"-record(a,{a,b}).">>, + [{'$1',[{is_record,'$1',a,3}],[true]}] = compile_and_run(RD, <<"ets:fun2ms(fun(X) when record(X,a) -> true end)">>), - ?line expect_failure + expect_failure (RD, <<"ets:fun2ms(fun(X) when integer(X) and constant(X) -> " "true end)">>), - ?line [{'$1',[{is_integer,'$1'}, + [{'$1',[{is_integer,'$1'}, {is_float,'$1'}, {is_atom,'$1'}, {is_list,'$1'}, @@ -511,13 +473,10 @@ old_guards(Config) when is_list(Config) -> >>), ok. -autoimported(suite) -> - []; -autoimported(doc) -> - ["Tests use of autoimported bif's used like erlang:'+'(A,B) in guards" - " and body."]; +%% Test use of autoimported BIFs used like erlang:'+'(A,B) in guards +%% and body. autoimported(Config) when is_list(Config) -> - ?line setup(Config), + setup(Config), Allowed = [ {abs,1}, {element,2}, @@ -530,7 +489,7 @@ autoimported(Config) when is_list(Config) -> {tl,1}, {trunc,1}, {self,0}, - %{float,1}, see float_1_function/1 + %%{float,1}, see float_1_function/1 {is_atom,1}, {is_float,1}, {is_integer,1}, @@ -547,8 +506,8 @@ autoimported(Config) when is_list(Config) -> {'or',2,infix}, {'xor',2,infix}, {'not',1}, - %{'andalso',2,infix}, - %{'orelse',2,infix}, + %%{'andalso',2,infix}, + %%{'orelse',2,infix}, {'+',1}, {'+',2,infix}, {'-',1}, @@ -571,8 +530,8 @@ autoimported(Config) when is_list(Config) -> {'=:=',2,infix}, {'/=',2,infix}, {'=/=',2,infix}], - ?line RD = <<"-record(a,{a,b}).">>, - ?line lists:foreach( + RD = <<"-record(a,{a,b}).">>, + lists:foreach( fun({A,0}) -> L = atom_to_list(A), Bin1 = list_to_binary( @@ -687,85 +646,76 @@ autoimported(Config) when is_list(Config) -> Allowed), ok. -semicolon(suite) -> - []; -semicolon(doc) -> - ["Tests semicolon in guards of match_specs."]; +%% Test semicolon in guards of match_specs. semicolon(Config) when is_list(Config) -> - ?line setup(Config), - ?line Res01 = compile_and_run + setup(Config), + Res01 = compile_and_run (<<"ets:fun2ms(fun(X) when is_integer(X); " "is_float(X) -> true end)">>), - ?line Res02 = compile_and_run + Res02 = compile_and_run (<<"ets:fun2ms(fun(X) when is_integer(X) -> true; " "(X) when is_float(X) -> true end)">>), - ?line Res01 = Res02, - ?line Res11 = compile_and_run + Res01 = Res02, + Res11 = compile_and_run (<<"ets:fun2ms(fun(X) when is_integer(X); " "is_float(X); atom(X) -> true end)">>), - ?line Res12 = compile_and_run + Res12 = compile_and_run (<<"ets:fun2ms(fun(X) when is_integer(X) -> true; " "(X) when is_float(X) -> true; " "(X) when is_atom(X) -> true end)">>), - ?line Res11 = Res12, + Res11 = Res12, ok. -float_1_function(suite) -> - []; -float_1_function(doc) -> - ["OTP-5297. The function float/1."]; +%% OTP-5297. The function float/1. float_1_function(Config) when is_list(Config) -> - ?line setup(Config), + setup(Config), RunMS = fun(L, MS) -> ets:match_spec_run(L, ets:match_spec_compile(MS)) end, - ?line MS1 = compile_and_run + MS1 = compile_and_run (<<"ets:fun2ms(fun(X) -> float(X) end)">>), - ?line [F1] = RunMS([3], MS1), - ?line true = is_float(F1) and (F1 == 3), + [F1] = RunMS([3], MS1), + true = is_float(F1) and (F1 == 3), - ?line MS1b = compile_and_run + MS1b = compile_and_run (<<"dbg:fun2ms(fun(X) -> float(X) end)">>), - ?line [F2] = RunMS([3], MS1b), - ?line true = is_float(F2) and (F2 == 3), + [F2] = RunMS([3], MS1b), + true = is_float(F2) and (F2 == 3), - ?line MS2 = compile_and_run + MS2 = compile_and_run (<<"ets:fun2ms(fun(X) when is_pid(X) or float(X) -> true end)">>), - ?line [] = RunMS([3.0], MS2), + [] = RunMS([3.0], MS2), - ?line MS3 = compile_and_run + MS3 = compile_and_run (<<"dbg:fun2ms(fun(X) when is_pid(X); float(X) -> true end)">>), - ?line [true] = RunMS([3.0], MS3), + [true] = RunMS([3.0], MS3), - ?line MS4 = compile_and_run + MS4 = compile_and_run (<<"ets:fun2ms(fun(X) when erlang:float(X) > 1 -> big;" " (_) -> small end)">>), - ?line [small,big] = RunMS([1.0, 3.0], MS4), + [small,big] = RunMS([1.0, 3.0], MS4), - ?line MS5 = compile_and_run + MS5 = compile_and_run (<<"ets:fun2ms(fun(X) when float(X) > 1 -> big;" " (_) -> small end)">>), - ?line [small,big] = RunMS([1.0, 3.0], MS5), + [small,big] = RunMS([1.0, 3.0], MS5), %% This is the test from autoimported/1. - ?line [{'$1',[{is_float,'$1'}],[{float,'$1'}]}] = + [{'$1',[{is_float,'$1'}],[{float,'$1'}]}] = compile_and_run (<<"ets:fun2ms(fun(X) when float(X) -> float(X) end)">>), - ?line [{'$1',[{float,'$1'}],[{float,'$1'}]}] = + [{'$1',[{float,'$1'}],[{float,'$1'}]}] = compile_and_run (<<"ets:fun2ms(fun(X) when erlang:'float'(X) -> " "erlang:'float'(X) end)">>), ok. -action_function(suite) -> - []; -action_function(doc) -> - ["Test all 'action functions'."]; +%% Test all 'action functions'. action_function(Config) when is_list(Config) -> - ?line setup(Config), - ?line [{['$1','$2'],[], + setup(Config), + [{['$1','$2'],[], [{set_seq_token,label,0}, {get_seq_token}, {message,'$1'}, @@ -778,7 +728,7 @@ action_function(Config) when is_list(Config) -> "message(X), " "return_trace(), " "exception_trace() end)">>), - ?line [{['$1','$2'],[], + [{['$1','$2'],[], [{process_dump}, {enable_trace,send}, {enable_trace,'$2',send}, @@ -791,7 +741,7 @@ action_function(Config) when is_list(Config) -> "enable_trace(Y, send), " "disable_trace(procs), " "disable_trace(Y, procs) end)">>), - ?line [{['$1','$2'], + [{['$1','$2'], [], [{display,'$1'}, {caller}, @@ -821,7 +771,7 @@ eep37(Config) when is_list(Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Helpers +%% Helpers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% setup(Config) -> @@ -832,14 +782,13 @@ temp_name() -> Conf = get(mts_config), C = get(mts_tf_counter), put(mts_tf_counter,C+1), - filename:join([?config(priv_dir,Conf), + filename:join([proplists:get_value(priv_dir,Conf), "tempfile"++integer_to_list(C)++".tmp"]). expect_failure(Recs,Code) -> case (catch compile_and_run(Recs,Code)) of {'EXIT',_Foo} -> - %erlang:display(_Foo), ok; Other -> exit({expected,failure,got,Other}) diff --git a/lib/stdlib/test/proc_lib_SUITE.erl b/lib/stdlib/test/proc_lib_SUITE.erl index a39a82b0df..ebce74545a 100644 --- a/lib/stdlib/test/proc_lib_SUITE.erl +++ b/lib/stdlib/test/proc_lib_SUITE.erl @@ -115,7 +115,7 @@ crash(Config) when is_list(Config) -> %% Spawn function with neighbour. Pid4 = proc_lib:spawn(?MODULE, sp2, []), - test_server:sleep(100), + ct:sleep(100), {?MODULE,sp2,[]} = proc_lib:initial_call(Pid4), {?MODULE,sp2,0} = proc_lib:translate_initial_call(Pid4), Pid4 ! die, @@ -152,9 +152,9 @@ analyse_crash(Pid, Expected0, ExpLinks) -> analyse_links(ExpLinks, Links); Unexpected -> io:format("~p\n", [Unexpected]), - test_server:fail(unexpected_message) + ct:fail(unexpected_message) after 5000 -> - test_server:fail(no_crash_report) + ct:fail(no_crash_report) end. analyse_links([H|Es], [{neighbour,N}|Links]) -> @@ -170,7 +170,7 @@ analyse_crash_1([{Key,Pattern}|T], Report) -> case lists:keyfind(Key, 1, Report) of false -> io:format("~p", [Report]), - test_server:fail({missing_key,Key}); + ct:fail({missing_key,Key}); {Key,Info} -> try match_info(Pattern, Info) @@ -179,7 +179,7 @@ analyse_crash_1([{Key,Pattern}|T], Report) -> io:format("key: ~p", [Key]), io:format("pattern: ~p", [Pattern]), io:format("actual: ~p", [Report]), - test_server:fail(no_match) + ct:fail(no_match) end, analyse_crash_1(T, Report) end; @@ -203,7 +203,7 @@ sync_start_nolink(Config) when is_list(Config) -> receive {sync_started, F} -> exit(F, kill), - test_server:fail(async_start) + ct:fail(async_start) after 1000 -> ok end, receive @@ -214,14 +214,14 @@ sync_start_nolink(Config) when is_list(Config) -> {sync_started, _} -> ok after 1000 -> exit(Pid2, kill), - test_server:fail(no_sync_start) + ct:fail(no_sync_start) end, ok. - + sync_start_link(Config) when is_list(Config) -> _Pid = spawn_link(?MODULE, sp3, [self()]), receive - {sync_started, _} -> test_server:fail(async_start) + {sync_started, _} -> ct:fail(async_start) after 1000 -> ok end, receive @@ -230,24 +230,24 @@ sync_start_link(Config) when is_list(Config) -> end, receive {sync_started, _} -> ok - after 1000 -> test_server:fail(no_sync_start) + after 1000 -> ct:fail(no_sync_start) end, ok. - + spawn_opt(Config) when is_list(Config) -> F = fun sp1/0, {name,Fname} = erlang:fun_info(F, name), FunMFArgs = {?MODULE,Fname,[]}, FunMFArity = {?MODULE,Fname,0}, - ?line Pid1 = proc_lib:spawn_opt(node(), F, [{priority,low}]), - ?line Pid = proc_lib:spawn_opt(F, [{priority,low}]), - ?line test_server:sleep(100), - ?line FunMFArgs = proc_lib:initial_call(Pid), - ?line FunMFArity = proc_lib:translate_initial_call(Pid), - ?line Pid ! die, - ?line FunMFArgs = proc_lib:initial_call(Pid1), - ?line FunMFArity = proc_lib:translate_initial_call(Pid1), - ?line Pid1 ! die, + Pid1 = proc_lib:spawn_opt(node(), F, [{priority,low}]), + Pid = proc_lib:spawn_opt(F, [{priority,low}]), + ct:sleep(100), + FunMFArgs = proc_lib:initial_call(Pid), + FunMFArity = proc_lib:translate_initial_call(Pid), + Pid ! die, + FunMFArgs = proc_lib:initial_call(Pid1), + FunMFArity = proc_lib:translate_initial_call(Pid1), + Pid1 ! die, ok. @@ -283,57 +283,57 @@ hibernate(Config) when is_list(Config) -> Ref = make_ref(), Self = self(), LoopData = {Ref,Self}, - ?line Pid = proc_lib:spawn_link(?MODULE, hib_loop, [LoopData]), + Pid = proc_lib:spawn_link(?MODULE, hib_loop, [LoopData]), %% Just check that the child process can process and answer messages. - ?line Pid ! {Self,loop_data}, + Pid ! {Self,loop_data}, receive {loop_data,LoopData} -> ok; Unexpected0 -> - ?line io:format("Unexpected: ~p\n", [Unexpected0]), - ?line ?t:fail() + io:format("Unexpected: ~p\n", [Unexpected0]), + ct:fail(failed) after 1000 -> - ?line io:format("Timeout"), - ?line ?t:fail() + io:format("Timeout"), + ct:fail(failed) end, %% Hibernate the process. - ?line Pid ! hibernate, + Pid ! hibernate, erlang:yield(), io:format("~p\n", [process_info(Pid, heap_size)]), %% Send a message to the process... - ?line Pid ! {Self,loop_data}, + Pid ! {Self,loop_data}, %% ... expect first a wake up message from the process... receive {awaken,LoopData} -> ok; Unexpected1 -> - ?line io:format("Unexpected: ~p\n", [Unexpected1]), - ?line ?t:fail() + io:format("Unexpected: ~p\n", [Unexpected1]), + ct:fail(failed) after 1000 -> - ?line io:format("Timeout"), - ?line ?t:fail() + io:format("Timeout"), + ct:fail(failed) end, %% ... followed by the answer to the actual request. receive {loop_data,LoopData} -> ok; Unexpected2 -> - ?line io:format("Unexpected: ~p\n", [Unexpected2]), - ?line ?t:fail() + io:format("Unexpected: ~p\n", [Unexpected2]), + ct:fail(failed) after 1000 -> - ?line io:format("Timeout"), - ?line ?t:fail() + io:format("Timeout"), + ct:fail(failed) end, %% Test that errors are handled correctly after wake up from hibernation... - ?line process_flag(trap_exit, true), - ?line error_logger:add_report_handler(?MODULE, self()), - ?line Pid ! crash, + process_flag(trap_exit, true), + error_logger:add_report_handler(?MODULE, self()), + Pid ! crash, %% We should receive two messages. Especially in the SMP emulator, %% we can't be sure of the message order, so sort the messages before @@ -341,10 +341,10 @@ hibernate(Config) when is_list(Config) -> Messages = lists:sort(hib_receive_messages(2)), io:format("~p", [Messages]), - ?line [{'EXIT',Pid,i_crashed},{crash_report,Pid,[Report,[]]}] = Messages, + [{'EXIT',Pid,i_crashed},{crash_report,Pid,[Report,[]]}] = Messages, %% Check that the initial_call has the expected format. - ?line {value,{initial_call,{?MODULE,hib_loop,[_]}}} = + {value,{initial_call,{?MODULE,hib_loop,[_]}}} = lists:keysearch(initial_call, 1, Report), error_logger:delete_report_handler(?MODULE), @@ -371,10 +371,7 @@ hib_receive_messages(N) -> Any -> [Any|hib_receive_messages(N-1)] end. -otp_6345(suite) -> - []; -otp_6345(doc) -> - ["'monitor' spawn_opt option"]; +%% 'monitor' spawn_opt option. otp_6345(Config) when is_list(Config) -> Opts = [link,monitor], {'EXIT', {badarg,[{proc_lib,check_for_monitor,_,_}|_Stack]}} = @@ -392,11 +389,8 @@ otp_6345_loop() -> otp_6345_loop() end. -%% OTP-9803 -init_dont_hang(suite) -> - []; -init_dont_hang(doc) -> - ["Check that proc_lib:start don't hang if spawned process crashes before proc_lib:init_ack/2"]; +%% OTP-9803. Check that proc_lib:start() doesn't hang if spawned process +%% crashes before proc_lib:init_ack/2. init_dont_hang(Config) when is_list(Config) -> %% Start should behave as start_link process_flag(trap_exit, true), @@ -489,7 +483,7 @@ stop(_Config) -> {'EXIT',noproc} = (catch proc_lib:stop({to_stop,Node})), true = test_server:stop_node(Node), - + %% Remote registered name, but non-existing node {'EXIT',{{nodedown,Node},_}} = (catch proc_lib:stop({to_stop,Node})), ok. @@ -522,7 +516,7 @@ t_format() -> if Tsz >= Usz -> - ?t:fail(); + ct:fail(failed); true -> ok end, @@ -549,7 +543,7 @@ t_format_looper() -> %%----------------------------------------------------------------- init(Tester) -> {ok, Tester}. - + handle_event({error_report, _GL, {Pid, crash_report, Report}}, Tester) -> io:format("~s\n", [proc_lib:format(Report)]), Tester ! {crash_report, Pid, Report}, diff --git a/lib/stdlib/test/qlc_SUITE.erl b/lib/stdlib/test/qlc_SUITE.erl index 6f94e740eb..75971bcf11 100644 --- a/lib/stdlib/test/qlc_SUITE.erl +++ b/lib/stdlib/test/qlc_SUITE.erl @@ -25,7 +25,7 @@ -define(QLC, qlc). -define(QLCs, "qlc"). -%-define(debug, true). +%%-define(debug, true). %% There are often many tests per testcase. Most tests are copied to a %% module, a file. The file is compiled and the test run. Should the @@ -44,9 +44,9 @@ -define(t, test_server). -else. -include_lib("common_test/include/ct.hrl"). --define(datadir, ?config(data_dir, Config)). --define(privdir, ?config(priv_dir, Config)). --define(testcase, ?config(?TESTCASE, Config)). +-define(datadir, proplists:get_value(data_dir, Config)). +-define(privdir, proplists:get_value(priv_dir, Config)). +-define(testcase, proplists:get_value(?TESTCASE, Config)). -endif. -include_lib("stdlib/include/ms_transform.hrl"). @@ -80,7 +80,7 @@ backward/1, forward/1, - eep37/1]). + eep37/1]). %% Internal exports. -export([bad_table_throw/1, bad_table_exit/1, default_table/1, bad_table/1, @@ -107,19 +107,15 @@ handle_event/2, handle_call/2, handle_info/2, terminate/2]). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(5)). - init_per_testcase(Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{?TESTCASE, Case}, {watchdog, Dog} | Config]. + [{?TESTCASE, Case} | Config]. end_per_testcase(_Case, _Config) -> - Dog = ?config(watchdog, _Config), - test_server:timetrap_cancel(Dog), ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,5}}]. all() -> [{group, parse_transform}, {group, evaluation}, @@ -159,35 +155,30 @@ init_per_group(_GroupName, Config) -> end_per_group(_GroupName, Config) -> Config. -badarg(doc) -> - "Badarg."; -badarg(suite) -> []; badarg(Config) when is_list(Config) -> Ts = - [{badarg, - <<"-import(qlc, [q/1, q/2]). + [{badarg, + <<"-import(qlc, [q/1, q/2]). q(_, _, _) -> ok. - badarg() -> - qlc:q(foo), - qlc:q(foo, cache_all), - qlc:q(foo, cache_all, extra), - q(bar), - q(bar, cache_all), - q(bar, cache_all, extra). - ">>, +badarg() -> + qlc:q(foo), + qlc:q(foo, cache_all), + qlc:q(foo, cache_all, extra), + q(bar), + q(bar, cache_all), + q(bar, cache_all, extra). +">>, [], - {errors,[{5,?QLC,not_a_query_list_comprehension}, - {6,?QLC,not_a_query_list_comprehension}, - {8,?QLC,not_a_query_list_comprehension}, - {9,?QLC,not_a_query_list_comprehension}], - []}}], - ?line [] = compile(Config, Ts), +{errors,[{5,?QLC,not_a_query_list_comprehension}, + {6,?QLC,not_a_query_list_comprehension}, + {8,?QLC,not_a_query_list_comprehension}, + {9,?QLC,not_a_query_list_comprehension}], + []}}], + [] = compile(Config, Ts), ok. -nested_qlc(doc) -> - "Nested qlc expressions."; -nested_qlc(suite) -> []; +%% Nested qlc expressions. nested_qlc(Config) when is_list(Config) -> %% Nested QLC expressions. X is bound before the first one; Z and X %% before the second one. @@ -227,12 +218,10 @@ nested_qlc(Config) when is_list(Config) -> [warn_unused_vars], {warnings,[{{6,39},erl_lint,{shadowed_var,'X',generate}}]}} ], - ?line [] = compile(Config, Ts), + [] = compile(Config, Ts), ok. -unused_var(doc) -> - "Unused variable with a name that should not be introduced."; -unused_var(suite) -> []; +%% Unused variable with a name that should not be introduced. unused_var(Config) when is_list(Config) -> Ts = [{unused_var, @@ -244,12 +233,10 @@ unused_var(Config) when is_list(Config) -> ">>, [warn_unused_vars], {warnings,[{{2,33},erl_lint,{unused_var,'Y1'}}]}}], - ?line [] = compile(Config, Ts), + [] = compile(Config, Ts), ok. -lc(doc) -> - "Ordinary LC expression."; -lc(suite) -> []; +%% Ordinary LC expression. lc(Config) when is_list(Config) -> Ts = [{lc, @@ -258,12 +245,10 @@ lc(Config) when is_list(Config) -> ">>, [], {warnings,[{{2,30},erl_lint,{shadowed_var,'X',generate}}]}}], - ?line [] = compile(Config, Ts), + [] = compile(Config, Ts), ok. -fun_clauses(doc) -> - "Fun with several clauses."; -fun_clauses(suite) -> []; +%% Fun with several clauses. fun_clauses(Config) when is_list(Config) -> Ts = [{fun_clauses, @@ -279,12 +264,10 @@ fun_clauses(Config) when is_list(Config) -> {{3,41},erl_lint,{shadowed_var,'X',generate}}, {{4,22},erl_lint,{shadowed_var,'X','fun'}}, {{4,41},erl_lint,{shadowed_var,'X',generate}}]}}], - ?line [] = compile(Config, Ts), + [] = compile(Config, Ts), ok. -filter_var(doc) -> - "Variable introduced in filter."; -filter_var(suite) -> []; +%% Variable introduced in filter. filter_var(Config) when is_list(Config) -> Ts = [{filter_var, @@ -309,13 +292,11 @@ filter_var(Config) when is_list(Config) -> ">>, [], {errors,[{{2,25},erl_lint,{unsafe_var,'V',{'case',{3,19}}}}],[]}}], - ?line [] = compile(Config, Ts), + [] = compile(Config, Ts), ok. -single(doc) -> - "Unused pattern variable."; -single(suite) -> []; +%% Unused pattern variable. single(Config) when is_list(Config) -> Ts = [{single, @@ -325,12 +306,10 @@ single(Config) when is_list(Config) -> ">>, [warn_unused_vars], {warnings,[{{2,30},erl_lint,{unused_var,'Y'}}]}}], - ?line [] = compile(Config, Ts), + [] = compile(Config, Ts), ok. -exported_var(doc) -> - "Exported variable in list expression (rhs of generator)."; -exported_var(suite) -> []; +%% Exported variable in list expression (rhs of generator). exported_var(Config) when is_list(Config) -> Ts = [{exported_var, @@ -347,12 +326,10 @@ exported_var(Config) when is_list(Config) -> [warn_export_vars], {warnings,[{{7,37},erl_lint,{exported_var,'Z',{'case',{3,36}}}}, {{7,44},erl_lint,{exported_var,'Z',{'case',{3,36}}}}]}}], - ?line [] = compile(Config, Ts), + [] = compile(Config, Ts), ok. -generator_vars(doc) -> - "Errors for generator variable used in list expression."; -generator_vars(suite) -> []; +%% Errors for generator variable used in list expression. generator_vars(Config) when is_list(Config) -> Ts = [{generator_vars, @@ -374,12 +351,10 @@ generator_vars(Config) when is_list(Config) -> {{9,33},?QLC,{used_generator_variable,'Z'}}, {{9,40},?QLC,{used_generator_variable,'Z'}}], []}}], - ?line [] = compile(Config, Ts), + [] = compile(Config, Ts), ok. -nomatch(doc) -> - "Unreachable clauses also found when compiling."; -nomatch(suite) -> []; +%% Unreachable clauses also found when compiling. nomatch(Config) when is_list(Config) -> Ts = [{unreachable1, @@ -451,13 +426,11 @@ nomatch(Config) when is_list(Config) -> {warnings,[{3,v3_core,nomatch}]}} ], - ?line [] = compile(Config, Ts), + [] = compile(Config, Ts), ok. -errors(doc) -> - "Errors within qlc expressions also found when compiling."; -errors(suite) -> []; +%% Errors within qlc expressions also found when compiling. errors(Config) when is_list(Config) -> Ts = [{errors1, @@ -466,12 +439,10 @@ errors(Config) when is_list(Config) -> ">>, [], {errors,[{{2,33},erl_lint,{unbound_var,'A'}}],[]}}], - ?line [] = compile(Config, Ts), + [] = compile(Config, Ts), ok. -pattern(doc) -> - "Patterns."; -pattern(suite) -> []; +%% Patterns. pattern(Config) when is_list(Config) -> Ts = [ <<"%% Records in patterns. No lookup. @@ -493,14 +464,12 @@ pattern(Config) when is_list(Config) -> end, [{<<\"hej\">>}])">> ], - ?line run(Config, <<"-record(a, {k,v}). + run(Config, <<"-record(a, {k,v}). -record(k, {t,v}).\n">>, Ts), ok. -eval(doc) -> - "eval/2"; -eval(suite) -> []; +%% eval/2 eval(Config) when is_list(Config) -> ScratchDir = filename:join([?privdir, "scratch","."]), @@ -616,12 +585,10 @@ eval(Config) when is_list(Config) -> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -cursor(doc) -> - "cursor/2"; -cursor(suite) -> []; +%% cursor/2 cursor(Config) when is_list(Config) -> ScratchDir = filename:join([?privdir, "scratch","."]), Ts = [<<"{'EXIT',{badarg,_}} = @@ -730,12 +697,10 @@ cursor(Config) when is_list(Config) -> ok = qlc:delete_cursor(C2)">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -fold(doc) -> - "fold/4"; -fold(suite) -> []; +%% fold/4 fold(Config) when is_list(Config) -> ScratchDir = filename:join([?privdir, "scratch","."]), Ts = [<<"Q = qlc:q([X || X <- [1,2,1,2,1]]), @@ -825,12 +790,10 @@ fold(Config) when is_list(Config) -> (catch qlc:fold(F, [], Q, [{unique_all,false}])) ">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -eval_unique(doc) -> - "Test the unique_all option of eval."; -eval_unique(suite) -> []; +%% Test the unique_all option of eval. eval_unique(Config) when is_list(Config) -> Ts = [<<"QLC1 = qlc:q([X || X <- qlc:append([[1,1,2], [1,2,3,2,3]])]), [1,2,3] = qlc:eval(QLC1, {unique_all,true}), @@ -922,12 +885,10 @@ eval_unique(Config) when is_list(Config) -> {sort,{sort,{list,_},[{unique,true}]},[]} = i(Q)">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -eval_cache(doc) -> - "Test the cache_all and unique_all options of eval."; -eval_cache(suite) -> []; +%% Test the cache_all and unique_all options of eval. eval_cache(Config) when is_list(Config) -> Ts = [ <<"E = ets:new(apa, [ordered_set]), @@ -1056,12 +1017,10 @@ eval_cache(Config) when is_list(Config) -> [1] = qlc:e(H, unique_all)">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -append(doc) -> - "Test the append function."; -append(suite) -> []; +%% Test the append function. append(Config) when is_list(Config) -> Ts = [<<"C = qlc:cursor(qlc:q([X || X <- [0,1,2,3], begin 10/X > 0.0 end])), R = (catch qlc:next_answers(C)), @@ -1121,12 +1080,12 @@ append(Config) when is_list(Config) -> foo() -> bar">>, %% Used to work up to R11B. - % <<"apa = qlc:e(qlc:q([X || X <- qlc:append([[1,2,3], ugly()])])), - % ok. - % - % ugly() -> - % [a | apa]. - % foo() -> bar">>, + %% <<"apa = qlc:e(qlc:q([X || X <- qlc:append([[1,2,3], ugly()])])), + %% ok. + %% + %% ugly() -> + %% [a | apa]. + %% foo() -> bar">>, %% Maybe this one should fail. @@ -1179,99 +1138,93 @@ append(Config) when is_list(Config) -> [a,b,1,2,1,2] = qlc:e(Q)">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -evaluator(doc) -> - "Simple call from evaluator."; -evaluator(suite) -> []; +%% Simple call from evaluator. evaluator(Config) when is_list(Config) -> - ?line true = is_alive(), + true = is_alive(), evaluator_2(Config, []), - ?line {ok, Node} = start_node(qlc_SUITE_evaluator), - ?line ok = rpc:call(Node, ?MODULE, evaluator_2, [Config, [compiler]]), - ?line ?t:stop_node(Node), + {ok, Node} = start_node(qlc_SUITE_evaluator), + ok = rpc:call(Node, ?MODULE, evaluator_2, [Config, [compiler]]), + test_server:stop_node(Node), ok. evaluator_2(Config, Apps) -> - ?line lists:foreach(fun(App) -> true = code:del_path(App) end, Apps), + lists:foreach(fun(App) -> true = code:del_path(App) end, Apps), FileName = filename:join(?privdir, "eval"), - ?line ok = file:write_file(FileName, + ok = file:write_file(FileName, <<"H = qlc:q([X || X <- L]), [1,2,3] = qlc:e(H).">>), - ?line Bs = erl_eval:add_binding('L', [1,2,3], erl_eval:new_bindings()), - ?line ok = file:eval(FileName, Bs), + Bs = erl_eval:add_binding('L', [1,2,3], erl_eval:new_bindings()), + ok = file:eval(FileName, Bs), %% The error message is "handled" a bit too much... %% (no trace of erl_lint left) - ?line ok = file:write_file(FileName, + ok = file:write_file(FileName, <<"H = qlc:q([X || X <- L]), qlc:e(H).">>), - ?line {error,_} = file:eval(FileName), + {error,_} = file:eval(FileName), %% Ugly error message; badarg is caught by file.erl. - ?line ok = file:write_file(FileName, + ok = file:write_file(FileName, <<"H = qlc:q([Z || {X,Y} <- [{a,2}], Z <- [Y]]), qlc:e(H).">>), - ?line {error,_} = file:eval(FileName), + {error,_} = file:eval(FileName), _ = file:delete(FileName), ok. start_node(Name) -> - ?line PA = filename:dirname(code:which(?MODULE)), - ?t:start_node(Name, slave, [{args, "-pa " ++ PA}]). + PA = filename:dirname(code:which(?MODULE)), + test_server:start_node(Name, slave, [{args, "-pa " ++ PA}]). -string_to_handle(doc) -> - "string_to_handle/1,2."; -string_to_handle(suite) -> []; +%% string_to_handle/1,2. string_to_handle(Config) when is_list(Config) -> - ?line {'EXIT',{badarg,_}} = (catch qlc:string_to_handle(14)), - ?line {'EXIT',{badarg,_}} = + {'EXIT',{badarg,_}} = (catch qlc:string_to_handle(14)), + {'EXIT',{badarg,_}} = (catch qlc:string_to_handle("[X || X <- [a].", unique_all)), - ?line R1 = {error, _, {_,erl_scan,_}} = qlc:string_to_handle("'"), - ?line "1: unterminated " ++ _ = lists:flatten(qlc:format_error(R1)), - ?line {error, _, {_,erl_parse,_}} = qlc:string_to_handle("foo"), - ?line {'EXIT',{badarg,_}} = (catch qlc:string_to_handle("foo, bar.")), - ?line R3 = {error, _, {_,?QLC,not_a_query_list_comprehension}} = + R1 = {error, _, {_,erl_scan,_}} = qlc:string_to_handle("'"), + "1: unterminated " ++ _ = lists:flatten(qlc:format_error(R1)), + {error, _, {_,erl_parse,_}} = qlc:string_to_handle("foo"), + {'EXIT',{badarg,_}} = (catch qlc:string_to_handle("foo, bar.")), + R3 = {error, _, {_,?QLC,not_a_query_list_comprehension}} = qlc:string_to_handle("bad."), - ?line "1: argument is not" ++ _ = lists:flatten(qlc:format_error(R3)), - ?line R4 = {error, _, {_,?QLC,{used_generator_variable,'Y'}}} = + "1: argument is not" ++ _ = lists:flatten(qlc:format_error(R3)), + R4 = {error, _, {_,?QLC,{used_generator_variable,'Y'}}} = qlc:string_to_handle("[X || begin Y = [1,2], true end, X <- Y]."), - ?line "1: generated variable 'Y'" ++ _ = + "1: generated variable 'Y'" ++ _ = lists:flatten(qlc:format_error(R4)), - ?line {error, _, {_,erl_lint,_}} = qlc:string_to_handle("[X || X <- A]."), - ?line H1 = qlc:string_to_handle("[X || X <- [1,2]]."), - ?line [1,2] = qlc:e(H1), - ?line H2 = qlc:string_to_handle("[X || X <- qlc:append([a,b]," + {error, _, {_,erl_lint,_}} = qlc:string_to_handle("[X || X <- A]."), + H1 = qlc:string_to_handle("[X || X <- [1,2]]."), + [1,2] = qlc:e(H1), + H2 = qlc:string_to_handle("[X || X <- qlc:append([a,b]," "qlc:e(qlc:q([X || X <- [c,d,e]])))]."), - ?line [a,b,c,d,e] = qlc:e(H2), + [a,b,c,d,e] = qlc:e(H2), %% The generated fun has many arguments (erl_eval has a maximum of 20). - ?line H3 = qlc:string_to_handle( + H3 = qlc:string_to_handle( "[{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W} ||" " {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W} <- []]."), - ?line [] = qlc:e(H3), - ?line Bs1 = erl_eval:add_binding('L', [1,2,3], erl_eval:new_bindings()), - ?line H4 = qlc:string_to_handle("[X || X <- L].", [], Bs1), - ?line [1,2,3] = qlc:e(H4), - ?line H5 = qlc:string_to_handle("[X || X <- [1,2,1,2]].", [unique, cache]), - ?line [1,2] = qlc:e(H5), - - ?line Ets = ets:new(test, []), - ?line true = ets:insert(Ets, [{1}]), - ?line Bs2 = erl_eval:add_binding('E', Ets, erl_eval:new_bindings()), - ?line Q = "[X || {X} <- ets:table(E)].", - ?line [1] = qlc:e(qlc:string_to_handle(Q, [], Bs2)), - ?line [1] = qlc:e(qlc:string_to_handle(Q, {max_lookup,1000}, Bs2)), - ?line [1] = qlc:e(qlc:string_to_handle(Q, {max_lookup,infinity}, Bs2)), - ?line {'EXIT',{badarg,_}} = + [] = qlc:e(H3), + Bs1 = erl_eval:add_binding('L', [1,2,3], erl_eval:new_bindings()), + H4 = qlc:string_to_handle("[X || X <- L].", [], Bs1), + [1,2,3] = qlc:e(H4), + H5 = qlc:string_to_handle("[X || X <- [1,2,1,2]].", [unique, cache]), + [1,2] = qlc:e(H5), + + Ets = ets:new(test, []), + true = ets:insert(Ets, [{1}]), + Bs2 = erl_eval:add_binding('E', Ets, erl_eval:new_bindings()), + Q = "[X || {X} <- ets:table(E)].", + [1] = qlc:e(qlc:string_to_handle(Q, [], Bs2)), + [1] = qlc:e(qlc:string_to_handle(Q, {max_lookup,1000}, Bs2)), + [1] = qlc:e(qlc:string_to_handle(Q, {max_lookup,infinity}, Bs2)), + {'EXIT',{badarg,_}} = (catch qlc:string_to_handle(Q, {max_lookup,-1}, Bs2)), - ?line {'EXIT', {no_lookup_to_carry_out, _}} = + {'EXIT', {no_lookup_to_carry_out, _}} = (catch qlc:e(qlc:string_to_handle(Q, {lookup,true}, Bs2))), - ?line ets:delete(Ets), + ets:delete(Ets), ok. -table(doc) -> - "table"; -table(suite) -> []; +%% table table(Config) when is_list(Config) -> dets:start(), Ts = [ @@ -1353,11 +1306,11 @@ table(Config) when is_list(Config) -> ets:delete(E)">>, %% The info tag num_of_objects is currently not used. -% <<"E = ets:new(test, [ordered_set]), -% true = ets:insert(E, [{1,a},{2,b},{3,c}]), -% H = qlc:q([X || X <- qlc_SUITE:bad_table_info_fun_n_objects(E)]), -% {'EXIT', finito} = (catch {any_term,qlc:e(H)}), -% ets:delete(E)">>, +%% <<"E = ets:new(test, [ordered_set]), +%% true = ets:insert(E, [{1,a},{2,b},{3,c}]), +%% H = qlc:q([X || X <- qlc_SUITE:bad_table_info_fun_n_objects(E)]), +%% {'EXIT', finito} = (catch {any_term,qlc:e(H)}), +%% ets:delete(E)">>, <<"E = ets:new(test, [ordered_set]), true = ets:insert(E, [{1,a},{2,b},{3,c}]), @@ -1473,7 +1426,7 @@ table(Config) when is_list(Config) -> [1,2] = lookup_keys(Q) end, [{1,1},{2,2}])">> ], - ?line run(Config, Ts), + run(Config, Ts), Ts2 = [ %% [T || P <- Table, F] turned into a match spec. Records needed. @@ -1484,13 +1437,11 @@ table(Config) when is_list(Config) -> [{a,1,2},{a,3,4}] = lists:sort(qlc:eval(QH)), ets:delete(E)">> ], - ?line run(Config, <<"-record(a, {b,c}).\n">>, Ts2), + run(Config, <<"-record(a, {b,c}).\n">>, Ts2), ok. -process_dies(doc) -> - "Caller or cursor process dies."; -process_dies(suite) -> []; +%% Caller or cursor process dies. process_dies(Config) when is_list(Config) -> Ts = [ <<"E = ets:new(test, []), @@ -1629,12 +1580,10 @@ process_dies(Config) when is_list(Config) -> true = ets:delete(E), ok">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -sort(doc) -> - "The sort option."; -sort(suite) -> []; +%% The sort option. sort(Config) when is_list(Config) -> Ts = [ <<"H = qlc:q([X || X <- qlc:sort([1,2,3,2], {unique,true})]), @@ -1741,12 +1690,10 @@ sort(Config) when is_list(Config) -> end ], - ?line run(Config, Ts), + run(Config, Ts), ok. -keysort(doc) -> - "The sort option."; -keysort(suite) -> []; +%% The sort option. keysort(Config) when is_list(Config) -> Ts = [ @@ -1865,13 +1812,11 @@ keysort(Config) when is_list(Config) -> 100003 = length(R)">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -filesort(doc) -> - "keysort/1,2, using a file."; -filesort(suite) -> []; +%% keysort/1,2, using a file. filesort(Config) when is_list(Config) -> Ts = [ <<"Q = qlc:q([X || X <- [{3},{1},{2}]]), @@ -1879,13 +1824,11 @@ filesort(Config) when is_list(Config) -> Q2 = qlc:q([{X,Y} || Y <- [1,2], X <- qlc:keysort([1],Q,Opts)]), [{{1},1},{{2},1},{{3},1},{{1},2},{{2},2},{{3},2}] = qlc:e(Q2)">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -cache(doc) -> - "The cache option."; -cache(suite) -> []; +%% The cache option. cache(Config) when is_list(Config) -> Ts = [ <<"{'EXIT', {badarg, _}} = (catch qlc:q([X || X <- [1,2]], badarg))">>, @@ -2043,12 +1986,10 @@ cache(Config) when is_list(Config) -> []} = i(H, cache_all)">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -cache_list(doc) -> - "OTP-6038. The {cache,list} option."; -cache_list(suite) -> []; +%% OTP-6038. The {cache,list} option. cache_list(Config) when is_list(Config) -> Ts = [ begin @@ -2334,12 +2275,10 @@ cache_list(Config) when is_list(Config) -> {'EXIT', {badarg, _}} = (catch qlc:e(Q, {max_list_size, foo}))">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -filter(doc) -> - "Filters and match specs."; -filter(suite) -> []; +%% Filters and match specs. filter(Config) when is_list(Config) -> Ts = [ <<"L = [1,2,3,4,5], @@ -2461,12 +2400,10 @@ filter(Config) when is_list(Config) -> [{2,b},{2,c},{3,b},{3,c}] = qlc:e(H)">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -info(doc) -> - "info/2."; -info(suite) -> []; +%% info/2. info(Config) when is_list(Config) -> Ts = [ <<"{list, [1,2]} = i(qlc:q([X || X <- [1,2]])), @@ -2686,12 +2623,10 @@ info(Config) when is_list(Config) -> [{4},{5},{6}] = qlc:e(F(3))">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -nested_info(doc) -> - "Nested QLC expressions. QLC expressions in filter and template."; -nested_info(suite) -> []; +%% Nested QLC expressions. QLC expressions in filter and template. nested_info(Config) when is_list(Config) -> Ts = [ <<"L = [{1,a},{2,b},{3,c}], @@ -2792,13 +2727,11 @@ nested_info(Config) when is_list(Config) -> [{1,1},{1,1},{1,2},{1,2},{2,1},{2,1},{2,2},{2,2}] = qlc:e(Q)">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -lookup1(doc) -> - "Lookup keys. Mostly test of patterns."; -lookup1(suite) -> []; +%% Lookup keys. Mostly test of patterns. lookup1(Config) when is_list(Config) -> Ts = [ <<"etsc(fun(E) -> @@ -3003,12 +2936,10 @@ lookup1(Config) when is_list(Config) -> []} ], - ?line run(Config, Ts), + run(Config, Ts), ok. -lookup2(doc) -> - "Lookup keys. Mostly test of filters."; -lookup2(suite) -> []; +%% Lookup keys. Mostly test of filters. lookup2(Config) when is_list(Config) -> Ts = [ <<"%% Only guards are inspected. No lookup. @@ -3708,9 +3639,7 @@ lookup2(Config) when is_list(Config) -> ok. -lookup_rec(doc) -> - "Lookup keys. With records."; -lookup_rec(suite) -> []; +%% Lookup keys. With records. lookup_rec(Config) when is_list(Config) -> Ts = [ <<"etsc(fun(E) -> @@ -3778,12 +3707,10 @@ lookup_rec(Config) when is_list(Config) -> [_] = lookup_keys(Q) end, [{keypos,2}], [#r{a=foo}])">> ], - ?line run(Config, <<"-record(r, {a}).\n">>, Ts), + run(Config, <<"-record(r, {a}).\n">>, Ts), ok. -indices(doc) -> - "Using indices for lookup."; -indices(suite) -> []; +%% Using indices for lookup. indices(Config) when is_list(Config) -> Ts = [ <<"L = [{1,a},{2,b},{3,c}], @@ -3845,12 +3772,10 @@ indices(Config) when is_list(Config) -> [{c,3,z,w}] = qlc:eval(QH)">> ], - ?line run(Config, <<"-record(r, {a}).\n">>, Ts), + run(Config, <<"-record(r, {a}).\n">>, Ts), ok. -pre_fun(doc) -> - "Test the table/2 callback functions parent_fun and stop_fun."; -pre_fun(suite) -> []; +%% Test the table/2 callback functions parent_fun and stop_fun. pre_fun(Config) when is_list(Config) -> Ts = [ <<"PF = process_flag(trap_exit, true), @@ -3926,12 +3851,10 @@ pre_fun(Config) when is_list(Config) -> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -skip_filters(doc) -> - "Lookup keys. With records."; -skip_filters(suite) -> []; +%% Lookup keys. With records. skip_filters(Config) when is_list(Config) -> %% Skipped filters TsS = [ @@ -4051,7 +3974,7 @@ skip_filters(Config) when is_list(Config) -> end, [{0},{1},{2},{3},{4}])">> ], - ?line run(Config, TsS), + run(Config, TsS), Ts = [ <<"etsc(fun(E) -> @@ -4329,14 +4252,12 @@ skip_filters(Config) when is_list(Config) -> end, [{1},{2},{3}])">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -ets(doc) -> - "ets:table/1,2."; -ets(suite) -> []; +%% ets:table/1,2. ets(Config) when is_list(Config) -> Ts = [ <<"E = ets:new(t, [ordered_set]), @@ -4377,12 +4298,10 @@ ets(Config) when is_list(Config) -> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -dets(doc) -> - "dets:table/1,2."; -dets(suite) -> []; +%% dets:table/1,2. dets(Config) when is_list(Config) -> dets:start(), T = t, @@ -4475,14 +4394,12 @@ dets(Config) when is_list(Config) -> ], - ?line run(Config, Ts), + run(Config, Ts), _ = file:delete(Fname), ok. -join_option(doc) -> - "The 'join' option (any, lookup, merge, nested_loop). Also cache/unique."; -join_option(suite) -> []; +%% The 'join' option (any, lookup, merge, nested_loop). Also cache/unique. join_option(Config) when is_list(Config) -> Ts = [ <<"Q1 = qlc:q([X || X <- [1,2,3]],{join,merge}), @@ -4607,7 +4524,7 @@ join_option(Config) when is_list(Config) -> ets:delete(E1)">> ], - ?line run(Config, Ts), + run(Config, Ts), %% The 'cache' and 'unique' options of qlc/2 affects join. CUTs = [ @@ -4655,13 +4572,11 @@ join_option(Config) when is_list(Config) -> _],[{unique,true}]} = i(Q, Options), [{1,1,1},{2,2,1},{1,1,2},{2,2,2}] = qlc:e(Q, Options)">> ], - ?line run(Config, CUTs), + run(Config, CUTs), ok. -join_filter(doc) -> - "Various aspects of filters and join."; -join_filter(suite) -> []; +%% Various aspects of filters and join. join_filter(Config) when is_list(Config) -> Ts = [ <<"E1 = create_ets(1, 10), @@ -4698,12 +4613,10 @@ join_filter(Config) when is_list(Config) -> end, [{a},{b},{c}])">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -join_lookup(doc) -> - "Lookup join."; -join_lookup(suite) -> []; +%% Lookup join. join_lookup(Config) when is_list(Config) -> Ts = [ <<"E1 = create_ets(1, 10), @@ -4793,12 +4706,10 @@ join_lookup(Config) when is_list(Config) -> ets:delete(E)">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -join_merge(doc) -> - "Merge join."; -join_merge(suite) -> []; +%% Merge join. join_merge(Config) when is_list(Config) -> Ts = [ <<"Q = qlc:q([{X,Y} || {X} <- [], {Y} <- [{1}], X =:= Y], @@ -5070,7 +4981,7 @@ join_merge(Config) when is_list(Config) -> [{2,a}] = qlc:e(Q)">> ], - ?line run(Config, Ts), + run(Config, Ts), %% Small examples. Returning an error term. ETs = [ @@ -5249,7 +5160,7 @@ join_merge(Config) when is_list(Config) -> err = qlc:e(Q)">> ], - ?line run(Config, ETs), + run(Config, ETs), %% Mostly examples where temporary files are needed while merging. FTs = [ @@ -5408,13 +5319,11 @@ join_merge(Config) when is_list(Config) -> ], - ?line run(Config, FTs), + run(Config, FTs), ok. -join_sort(doc) -> - "Merge join optimizations (avoid unnecessary sorting)."; -join_sort(suite) -> []; +%% Merge join optimizations (avoid unnecessary sorting). join_sort(Config) when is_list(Config) -> Ts = [ <<"H1_1 = qlc:keysort(1, [{1,2,3},{4,5,6}]), @@ -5694,12 +5603,10 @@ join_sort(Config) when is_list(Config) -> end, [{1,2},{3,4}])">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -join_complex(doc) -> - "Join of more than two columns."; -join_complex(suite) -> []; +%% Join of more than two columns. join_complex(Config) when is_list(Config) -> Ts = [{three, <<"three() -> @@ -5727,7 +5634,7 @@ join_complex(Config) when is_list(Config) -> {warnings,[{2,qlc,too_many_joins}]}} ], - ?line compile(Config, Ts), + compile(Config, Ts), Ts2 = [{three, <<"three() -> @@ -5756,14 +5663,12 @@ join_complex(Config) when is_list(Config) -> {[],["cannot handle more than one join efficiently"]}} ], - ?line compile_format(Config, Ts2), + compile_format(Config, Ts2), ok. -otp_5644(doc) -> - "OTP-5644. Handle the new language element M:F/A."; -otp_5644(suite) -> []; +%% OTP-5644. Handle the new language element M:F/A. otp_5644(Config) when is_list(Config) -> Ts = [ <<"Q = qlc:q([fun modul:mfa/0 || _ <- [1,2], @@ -5771,12 +5676,10 @@ otp_5644(Config) when is_list(Config) -> [_,_] = qlc:eval(Q)">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. -otp_5195(doc) -> - "OTP-5195. Allow traverse functions returning terms."; -otp_5195(suite) -> []; +%% OTP-5195. Allow traverse functions returning terms. otp_5195(Config) when is_list(Config) -> %% Several minor improvements have been implemented in OTP-5195. %% The test cases are spread all over... except these. @@ -5854,7 +5757,7 @@ otp_5195(Config) when is_list(Config) -> ], - ?line run(Config, Ts), + run(Config, Ts), Ts2 = [<<"Q = qlc:q([{X,Y} || {X} <- [{1},{2},{3}], begin @@ -5863,13 +5766,11 @@ otp_5195(Config) when is_list(Config) -> end, X =:= Y]), [{3,3}] = qlc:e(Q)">>], - ?line run(Config, Ts2), + run(Config, Ts2), ok. -otp_6038_bug(doc) -> - "OTP-6038. Bug fixes: unique and keysort; cache."; -otp_6038_bug(suite) -> []; +%% OTP-6038. Bug fixes: unique and keysort; cache. otp_6038_bug(Config) when is_list(Config) -> %% The 'unique' option can no longer be merged with the keysort options. %% This used to return [{1,a},{1,c},{2,b},{2,d}], but since @@ -5879,7 +5780,7 @@ otp_6038_bug(Config) when is_list(Config) -> H2 = qlc:keysort(1, H1, [{unique,true}]), [{1,a},{2,b}] = qlc:e(H2)">>], - ?line run(Config, Ts), + run(Config, Ts), %% Sometimes the cache options did not empty the correct tables. CTs = [ @@ -5908,13 +5809,11 @@ otp_6038_bug(Config) when is_list(Config) -> L = [{X,Y} || X <- [1,2], Y <- L4], true = R =:= L">> ], - ?line run(Config, CTs), + run(Config, CTs), ok. -otp_6359(doc) -> - "OTP-6359. dets:select() never returns the empty list."; -otp_6359(suite) -> []; +%% OTP-6359. dets:select() never returns the empty list. otp_6359(Config) when is_list(Config) -> dets:start(), T = luna, @@ -5933,12 +5832,10 @@ otp_6359(Config) when is_list(Config) -> ok">>] ], - ?line run(Config, Ts), + run(Config, Ts), ok. -otp_6562(doc) -> - "OTP-6562. compressed = false (should be []) when sorting before join."; -otp_6562(suite) -> []; +%% OTP-6562. compressed = false (should be []) when sorting before join. otp_6562(Config) when is_list(Config) -> Bug = [ %% This example uses a file to sort E2 on the second column. It is @@ -5957,7 +5854,7 @@ otp_6562(Config) when is_list(Config) -> ets:delete(E1), ets:delete(E2)">> ], - ?line run(Config, Bug), + run(Config, Bug), Bits = [ {otp_6562_1, @@ -5969,18 +5866,16 @@ otp_6562(Config) when is_list(Config) -> {errors,[{2,qlc,binary_generator}], []}} ], - ?line [] = compile(Config, Bits), + [] = compile(Config, Bits), - ?line R1 = {error,qlc,{1,qlc,binary_generator}} + R1 = {error,qlc,{1,qlc,binary_generator}} = qlc:string_to_handle("[X || <<X:8>> <= <<\"hej\">>]."), - ?line "1: cannot handle binary generators\n" = + "1: cannot handle binary generators\n" = lists:flatten(qlc:format_error(R1)), ok. -otp_6590(doc) -> - "OTP-6590. Bug fix (join info)."; -otp_6590(suite) -> []; +%% OTP-6590. Bug fix (join info). otp_6590(Config) when is_list(Config) -> Ts = [<<"fun(Tab1Value) -> Q = qlc:q([T1#tab1.id || T1 <- [#tab1{id = id1, @@ -5992,13 +5887,11 @@ otp_6590(Config) when is_list(Config) -> [id1] = qlc:e(Q) end(v)">>], - ?line run(Config, <<"-record(tab1, {id, tab2_id, value}). + run(Config, <<"-record(tab1, {id, tab2_id, value}). -record(tab2, {id, value}).\n">>, Ts), ok. -otp_6673(doc) -> - "OTP-6673. Optimizations and fixes."; -otp_6673(suite) -> []; +%% OTP-6673. Optimizations and fixes. otp_6673(Config) when is_list(Config) -> Ts_PT = [<<"etsc(fun(E1) -> @@ -6054,7 +5947,7 @@ otp_6673(Config) when is_list(Config) -> end, [{1,x},{2,y},{3,z}])">>], - ?line run(Config, Ts_PT), + run(Config, Ts_PT), MS = ets:fun2ms(fun({X,_Y}=T) when X > 1 -> T end), Ts_RT = [ @@ -6091,13 +5984,11 @@ otp_6673(Config) when is_list(Config) -> end, [{x,1},{y,2},{z,3}])">> ], - ?line run(Config, Ts_RT), + run(Config, Ts_RT), ok. -otp_6964(doc) -> - "OTP-6964. New option 'tmpdir_usage'."; -otp_6964(suite) -> []; +%% OTP-6964. New option 'tmpdir_usage'. otp_6964(Config) when is_list(Config) -> T1 = [ <<"Q1 = qlc:q([{X} || X <- [1,2]]), @@ -6131,7 +6022,7 @@ otp_6964(Config) when is_list(Config) -> _ = erlang:system_flag(backtrace_depth, D) end, qlc_SUITE:uninstall_error_logger()">>], - ?line run(Config, T1), + run(Config, T1), T2 = [ <<"%% File sorter. @@ -6164,7 +6055,7 @@ otp_6964(Config) when is_list(Config) -> {info, caching} = qlc_SUITE:read_error_logger(), qlc_SUITE:uninstall_error_logger()">>], - ?line run(Config, T2), + run(Config, T2), T3 = [ <<"%% sort/keysort @@ -6194,7 +6085,7 @@ otp_6964(Config) when is_list(Config) -> qlc_SUITE:uninstall_error_logger(), ets:delete(E1), ets:delete(E2)">>], - ?line run(Config, T3), + run(Config, T3), T4 = [ <<"%% cache list @@ -6225,18 +6116,16 @@ otp_6964(Config) when is_list(Config) -> lists:flatten(qlc:format_error(ErrReply)) end, [{keypos,1}], [{I,a,lists:duplicate(100000,1)} || I <- lists:seq(1, 10)])">>], - ?line run(Config, T4), + run(Config, T4), ok. -otp_7238(doc) -> - "OTP-7238. info-option 'depth', &c."; -otp_7238(suite) -> []; +%% OTP-7238. info-option 'depth', &c. otp_7238(Config) when is_list(Config) -> dets:start(), T = otp_7238, Fname = filename(T, Config), - ?line ok = compile_gb_table(Config), + ok = compile_gb_table(Config), %% A few more warnings. T1 = [ @@ -6365,7 +6254,7 @@ otp_7238(Config) when is_list(Config) -> [], {warnings,[{2,sys_core_fold,no_clause_match}]}} ], - ?line [] = compile(Config, T1), + [] = compile(Config, T1), %% 'depth' is a new option used by info() T2 = [ @@ -6591,7 +6480,7 @@ otp_7238(Config) when is_list(Config) -> qlc:info(Q, [{format,abstract_code},{depth, 2}])">> ], - ?line run(Config, T2), + run(Config, T2), T3 = [ %% {nomatch_6, @@ -6607,7 +6496,7 @@ otp_7238(Config) when is_list(Config) -> %% [], %% {[],["pattern cannot possibly match"]}} ], - ?line compile_format(Config, T3), + compile_format(Config, T3), %% *Very* simple test - just check that it doesn't crash. Type = [{cres, @@ -6615,13 +6504,11 @@ otp_7238(Config) when is_list(Config) -> {'EXIT',{{badfun,_},_}} = (catch qlc:e(Q))">>, [type_checker], []}], - ?line run(Config, Type), + run(Config, Type), ok. -otp_7114(doc) -> - "OTP-7114. Match spec, table and duplicated objects.."; -otp_7114(suite) -> []; +%% OTP-7114. Match spec, table and duplicated objects... otp_7114(Config) when is_list(Config) -> Ts = [<<"T = ets:new(t, [bag]), [ets:insert(T, {t, I, I div 2}) || I <- lists:seq(1,10)], @@ -6632,11 +6519,9 @@ otp_7114(Config) when is_list(Config) -> [0,1,2,3,4,5] = qlc:e(qlc:sort(qlc:e(Q1)), unique_all), ets:delete(T), ok">>], - ?line run(Config, Ts). + run(Config, Ts). -otp_7232(doc) -> - "OTP-7232. qlc:info() bug (pids, ports, refs, funs)."; -otp_7232(suite) -> []; +%% OTP-7232. qlc:info() bug (pids, ports, refs, funs). otp_7232(Config) when is_list(Config) -> Ts = [<<"L = [fun math:sqrt/1, list_to_pid(\"<0.4.1>\"), erlang:make_ref()], @@ -6664,11 +6549,9 @@ otp_7232(Config) when is_list(Config) -> \"[<<8,1:1>>]\" = qlc:info(Q)">> ], - ?line run(Config, Ts). + run(Config, Ts). -otp_7552(doc) -> - "OTP-7552. Merge join bug."; -otp_7552(suite) -> []; +%% OTP-7552. Merge join bug. otp_7552(Config) when is_list(Config) -> %% The poor performance cannot be observed unless the %% (redundant) join filter is skipped. @@ -6691,11 +6574,9 @@ otp_7552(Config) when is_list(Config) -> Qn = F(nested_loop), true = lists:sort(qlc:e(Qm, {max_list_size,20})) =:= lists:sort(qlc:e(Qn))">>], - ?line run(Config, Ts). + run(Config, Ts). -otp_7714(doc) -> - "OTP-7714. Merge join bug."; -otp_7714(suite) -> []; +%% OTP-7714. Merge join bug. otp_7714(Config) when is_list(Config) -> %% The original example uses Mnesia. This one does not. Ts = [<<"E1 = ets:new(set,[]), @@ -6710,11 +6591,9 @@ otp_7714(Config) when is_list(Config) -> [{a,1},{a,2},{a,3}] = lists:sort(qlc:e(Q)), ets:delete(E1), ets:delete(E2)">>], - ?line run(Config, Ts). + run(Config, Ts). -otp_11758(doc) -> - "OTP-11758. Bug."; -otp_11758(suite) -> []; +%% OTP-11758. Bug. otp_11758(Config) when is_list(Config) -> Ts = [<<"T = ets:new(r, [{keypos, 2}]), L = [{rrr, xxx, aaa}, {rrr, yyy, bbb}], @@ -6725,12 +6604,10 @@ otp_11758(Config) when is_list(Config) -> ets:delete(T)">>], run(Config, Ts). -otp_6674(doc) -> - "OTP-6674. match/comparison."; -otp_6674(suite) -> []; +%% OTP-6674. match/comparison. otp_6674(Config) when is_list(Config) -> - ?line ok = compile_gb_table(Config), + ok = compile_gb_table(Config), Ts = [%% lookup join <<"E = ets:new(join, [ordered_set]), @@ -7153,11 +7030,9 @@ otp_6674(Config) when is_list(Config) -> ], - ?line run(Config, Ts). + run(Config, Ts). -otp_12946(doc) -> - ["Syntax error."]; -otp_12946(suite) -> []; +%% Syntax error. otp_12946(Config) when is_list(Config) -> Text = <<"-export([init/0]). @@ -7167,12 +7042,10 @@ otp_12946(Config) when is_list(Config) -> {errors,[{4,erl_parse,_}],[]} = compile_file(Config, Text, []), ok. -manpage(doc) -> - "Examples from qlc(3)."; -manpage(suite) -> []; +%% Examples from qlc(3). manpage(Config) when is_list(Config) -> - ?line ok = compile_gb_table(Config), + ok = compile_gb_table(Config), Ts = [ <<"QH = qlc:q([{X,Y} || X <- [a,b], Y <- [1,2]]), @@ -7327,7 +7200,7 @@ manpage(Config) when is_list(Config) -> ets:match_spec_compile([{{{'$1','$2'},'_'},[],['$1']}]))\", L = qlc:info(QH)">> ], - ?line run(Config, Ts), + run(Config, Ts), L = [1,2,3], Bs = erl_eval:add_binding('L', L, erl_eval:new_bindings()), @@ -7345,7 +7218,7 @@ manpage(Config) when is_list(Config) -> true = qlc:info(QH1) =:= qlc:info(QH2), true = ets:delete(Tab)">>]], - ?line run(Config, ETs), + run(Config, ETs), %% dets(3) DTs = [ @@ -7358,16 +7231,16 @@ manpage(Config) when is_list(Config) -> true = qlc:info(QH1) =:= qlc:info(QH2), ok = dets:close(T)">>]], - ?line run(Config, DTs), + run(Config, DTs), ok. compile_gb_table(Config) -> GB_table_file = filename("gb_table.erl", Config), - ?line ok = file:write_file(GB_table_file, gb_table()), - ?line {ok, gb_table} = compile:file(GB_table_file, [{outdir,?privdir}]), - ?line code:purge(gb_table), - ?line {module, gb_table} = + ok = file:write_file(GB_table_file, gb_table()), + {ok, gb_table} = compile:file(GB_table_file, [{outdir,?privdir}]), + code:purge(gb_table), + {module, gb_table} = code:load_abs(filename:rootname(GB_table_file)), ok. @@ -7433,9 +7306,7 @@ gb_iter(I0, N, EFun) -> ">>. -backward(doc) -> - "OTP-6674. Join info and extra constants."; -backward(suite) -> []; +%% OTP-6674. Join info and extra constants. backward(Config) when is_list(Config) -> try_old_join_info(Config), ok. @@ -7470,9 +7341,6 @@ try_old_join_info(Config) -> qlc:info(H2, {format,debug}), [{1,1},{2,2}] = qlc:e(H2). -forward(doc) -> - ""; -forward(suite) -> []; forward(Config) when is_list(Config) -> Ts = [ %% LC_fun() returns something unknown. @@ -7481,12 +7349,12 @@ forward(Config) when is_list(Config) -> {'EXIT', {{unsupported_qlc_handle,_},_}} = (catch qlc:e(FakeH))">>, %% 'f1' should be used for new stuff that does not interfer with old behavior -% %% The unused element 'f1' of #qlc_table seems to be used. -% <<"DF = fun() -> foo end, -% FakeH = {qlc_handle,{qlc_table,DF, -% true,DF,DF,DF,DF,DF, -% undefined,not_undefined,undefined,no_match_spec}}, -% {'EXIT', {{unsupported_qlc_handle,_},_}} = (catch qlc:e(FakeH))">>, +%% %% The unused element 'f1' of #qlc_table seems to be used. +%% <<"DF = fun() -> foo end, +%% FakeH = {qlc_handle,{qlc_table,DF, +%% true,DF,DF,DF,DF,DF, +%% undefined,not_undefined,undefined,no_match_spec}}, +%% {'EXIT', {{unsupported_qlc_handle,_},_}} = (catch qlc:e(FakeH))">>, %% #qlc_opt has changed. <<"H = qlc:q([X || X <- []]), @@ -7495,7 +7363,7 @@ forward(Config) when is_list(Config) -> {'EXIT', {{unsupported_qlc_handle,_},_}} = (catch qlc:e(FakeH))">> ], - ?line run(Config, Ts), + run(Config, Ts), ok. eep37(Config) when is_list(Config) -> @@ -7955,7 +7823,7 @@ run_test(Config, Extra, {cres, Body, Opts, ExpectedCompileReturn}) -> R = case catch Mod:function() of {'EXIT', _Reason} = Error -> - ?t:format("failed, got ~p~n", [Error]), + io:format("failed, got ~p~n", [Error]), fail(SourceFile); Reply -> Reply @@ -7966,7 +7834,7 @@ run_test(Config, Extra, {cres, Body, Opts, ExpectedCompileReturn}) -> {file, cover_compiled} -> ok; {file, _} -> - ?t:format("qlc_pt was loaded in runtime~n", []), + io:format("qlc_pt was loaded in runtime~n", []), fail(SourceFile); false -> ok @@ -8167,16 +8035,15 @@ warnings(File, Ws) -> end. expected(Test, Expected, Got, File) -> - ?t:format("~nTest ~p failed. ", [Test]), + io:format("~nTest ~p failed. ", [Test]), expected(Expected, Got, File). expected(Expected, Got, File) -> - ?t:format("Expected~n ~p~n, but got~n ~p~n", [Expected, Got]), + io:format("Expected~n ~p~n, but got~n ~p~n", [Expected, Got]), fail(File). fail(Source) -> - io:format("failed~n"), - ?t:fail({failed,testcase,on,Source}). + ct:fail({failed,testcase,on,Source}). %% Copied from global_SUITE.erl. @@ -8197,8 +8064,8 @@ read_error_logger() -> {error, Pid, Tuple} -> {error, Pid, Tuple} after 1000 -> - ?line io:format("No reply after 1 s\n", []), - ?line ?t:fail() + io:format("No reply after 1 s\n", []), + ct:fail(failed) end. %%----------------------------------------------------------------- diff --git a/lib/stdlib/test/queue_SUITE.erl b/lib/stdlib/test/queue_SUITE.erl index 77fe6adb7c..cd3f8e6e2f 100644 --- a/lib/stdlib/test/queue_SUITE.erl +++ b/lib/stdlib/test/queue_SUITE.erl @@ -19,26 +19,23 @@ %% -module(queue_SUITE). -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, + init_per_testcase/2, end_per_testcase/2, init_per_group/2,end_per_group/2]). -export([do/1, to_list/1, io_test/1, op_test/1, error/1, oops/1]). --export([init_per_testcase/2, end_per_testcase/2]). -include_lib("common_test/include/ct.hrl"). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(1)). - init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), + Config. + +end_per_testcase(_Case, _Config) -> ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [do, to_list, io_test, op_test, error, oops]. @@ -59,47 +56,40 @@ end_per_group(_GroupName, Config) -> Config. -do(doc) -> - [""]; -do(suite) -> - []; do(Config) when is_list(Config) -> - ?line L = [{in, 1}, - {in, 2}, - {out, {value, 1}}, - {in, 3}, - {out, {value, 2}}, - {out, {value, 3}}, - {out, empty} - ], - - ?line E = queue:new(), - ?line [] = queue:to_list(E), - ?line Q = do_queue(E, L), - ?line true = queue:is_empty(Q), - ?line 0 = queue:len(Q), + L = [{in, 1}, + {in, 2}, + {out, {value, 1}}, + {in, 3}, + {out, {value, 2}}, + {out, {value, 3}}, + {out, empty} + ], + + E = queue:new(), + [] = queue:to_list(E), + Q = do_queue(E, L), + true = queue:is_empty(Q), + 0 = queue:len(Q), ok. -to_list(doc) -> - ["OTP-2701"]; -to_list(suite) -> - []; +%% OTP-2701 to_list(Config) when is_list(Config) -> - ?line E = queue:new(), - ?line Q = do_queue(E, [{in, 1}, - {in, 2}, - {in, 3}, - {out, {value, 1}}, - {in, 4}, - {in, 5}]), - ?line true = queue:is_queue(Q), - ?line 4 = queue:len(Q), - ?line case queue:to_list(Q) of - [2,3,4,5] -> - ok; - Other1 -> - test_server:fail(Other1) - end, + E = queue:new(), + Q = do_queue(E, [{in, 1}, + {in, 2}, + {in, 3}, + {out, {value, 1}}, + {in, 4}, + {in, 5}]), + true = queue:is_queue(Q), + 4 = queue:len(Q), + case queue:to_list(Q) of + [2,3,4,5] -> + ok; + Other1 -> + ct:fail(Other1) + end, ok. do_queue(Q, []) -> @@ -114,93 +104,86 @@ do_queue_1({out, E}, Q) -> {E, Q1} -> Q1; Other -> - test_server:fail({"out failed", E, Q, Other}) + ct:fail({"out failed", E, Q, Other}) end. -io_test(doc) -> - "Test input and output"; -io_test(suite) -> - []; +%% Test input and output. io_test(Config) when is_list(Config) -> E = queue:new(), do_io_test(E), ok. do_io_test(E) -> - ?line [4,3,5] = + [4,3,5] = io([snoc,snoc,head,head,head,cons,cons,snoc], E, 1), - ?line [5,3,4] = + [5,3,4] = io([cons,cons,daeh,daeh,daeh,snoc,snoc,cons], E, 1), - ?line [4,3,5] = + [4,3,5] = io([in,in,out,out,out,in_r,in_r,in], E, 1), - ?line [5,3,4] = + [5,3,4] = io([in_r,in_r,out_r,out_r,out_r,in,in,in_r], E, 1), %% - ?line [] = + [] = io([snoc,snoc,head,snoc,snoc,head,head,snoc,head,head], E, 1), - ?line [] = + [] = io([cons,cons,daeh,cons,cons,daeh,daeh,cons,daeh,daeh], E, 1), - ?line [] = + [] = io([in,in,out,in,in,out,out,in,out,out], E, 1), - ?line [] = + [] = io([in_r,in_r,out_r,in_r,in_r,out_r,out_r,in_r,out_r,out_r], E, 1), %% - ?line [5,6] = + [5,6] = io([snoc,snoc,snoc,head,head,snoc,snoc,snoc,head,head], E, 1), - ?line [6,5] = + [6,5] = io([cons,cons,cons,daeh,daeh,cons,cons,cons,daeh,daeh], E, 1), - ?line [5,6] = + [5,6] = io([in,in,in,out,out,in,in,in,out,out], E, 1), - ?line [6,5] = + [6,5] = io([in_r,in_r,in_r,out_r,out_r,in_r,in_r,in_r,out_r,out_r], E, 1), %% - ?line [5] = + [5] = io([snoc,head,head,snoc,head,snoc,head,snoc,head,snoc], E, 1), - ?line [5] = + [5] = io([cons,daeh,daeh,cons,daeh,cons,daeh,cons,daeh,cons], E, 1), - ?line [5] = + [5] = io([in,out,out,in,out,in,out,in,out,in], E, 1), - ?line [5] = + [5] = io([in_r,out_r,out_r,in_r,out_r,in_r,out_r,in_r,out_r,in_r], E, 1), %% - ?line [] = + [] = io([snoc,head,snoc,snoc,head,head,snoc,snoc,snoc,head,head,head], E, 1), - ?line [] = + [] = io([cons,daeh,cons,cons,daeh,daeh,cons,cons,cons,daeh,daeh,daeh], - E, 1), - ?line [] = + E, 1), + [] = io([in,out,in,in,out,out,in,in,in,out,out,out], E, 1), - ?line [] = + [] = io([in_r,out_r,in_r,in_r,out_r,out_r,in_r,in_r,in_r,out_r,out_r,out_r], - E, 1), + E, 1), %% - ?line [3] = io([cons,cons,cons,snoc,daeh,daeh,daeh], E, 1), - ?line [3] = io([snoc,snoc,snoc,cons,head,head,head], E, 1), - ?line [3] = io([in,in,in,in_r,out,out,out], E, 1), - ?line [3] = io([in_r,in_r,in_r,in,out_r,out_r,out_r], E, 1), + [3] = io([cons,cons,cons,snoc,daeh,daeh,daeh], E, 1), + [3] = io([snoc,snoc,snoc,cons,head,head,head], E, 1), + [3] = io([in,in,in,in_r,out,out,out], E, 1), + [3] = io([in_r,in_r,in_r,in,out_r,out_r,out_r], E, 1), %% - ?line Q2 = queue:join(queue:cons(1, E),queue:cons(2, E)), - ?line Q1 = queue:reverse(Q2), - ?line [1] = io([head], Q1, 3), - ?line [1] = io([out], Q1, 3), - ?line [1] = io([daeh], Q2, 3), - ?line [1] = io([out_r], Q2, 3), -% ?line [2] = io([cons,cons,snoc,daeh,daeh], [], 1), -% ?line [2] = io([snoc,snoc,cons,head,head], [], 1), -% ?line [2] = io([in,in,in_r,out,out], [], 1), -% ?line [2] = io([in_r,in_r,in,out_r,out_r], [], 1), + Q2 = queue:join(queue:cons(1, E),queue:cons(2, E)), + Q1 = queue:reverse(Q2), + [1] = io([head], Q1, 3), + [1] = io([out], Q1, 3), + [1] = io([daeh], Q2, 3), + [1] = io([out_r], Q2, 3), %% - ?line [2] = + [2] = io([in,peek,peek_r,drop,in_r,peek,peek_r,in,peek,peek_r,drop_r], E, 1), %% Malformed queues UGLY-GUTS-ALL-OVER-THE-PLACE - ?line [2,1] = io([peek], {[1,2],[]}, 1), - ?line [1,2] = io([peek_r], {[],[1,2]}, 1), + [2,1] = io([peek], {[1,2],[]}, 1), + [1,2] = io([peek_r], {[],[1,2]}, 1), %% ok. @@ -269,7 +252,7 @@ io([peek_r | Tail], Q, Q0, X) -> io([drop | Tail], Q, [], X) -> try queue:drop(Q) of V -> - test_server:fail({?MODULE,?LINE,V}) + ct:fail({?MODULE,?LINE,V}) catch error:empty -> io(Tail, Q, [], X) @@ -280,7 +263,7 @@ io([drop | Tail], Q, [_ | T], X) -> io([drop_r | Tail], Q, [], X) -> try queue:drop_r(Q) of V -> - test_server:fail({?MODULE,?LINE,V}) + ct:fail({?MODULE,?LINE,V}) catch error:empty -> io(Tail, Q, [], X) @@ -298,108 +281,102 @@ io([], Q, QQ, _X) -> QQ. -op_test(doc) -> - "Test operations on whole queues"; -op_test(suite) -> - []; +%% Test operations on whole queues. op_test(Config) when is_list(Config) -> do_op_test(fun id/1), ok. do_op_test(F) -> - ?line Len = 50, - ?line Len2 = 2*Len, - ?line L1 = lists:seq(1, Len), - ?line L1r = lists:reverse(L1), - ?line L2 = lists:seq(Len+1, Len2), - ?line L2r = lists:reverse(L2), - ?line L3 = L1++L2, - ?line L3r = L2r++L1r, - ?line Q0 = F(queue:new()), - ?line [] = queue:to_list(Q0), - ?line Q0 = F(queue:from_list([])), - ?line Q1 = F(queue:from_list(L1)), - ?line Q2 = F(queue:from_list(L2)), - ?line Q3 = F(queue:from_list(L3)), - ?line Len = queue:len(Q1), - ?line Len = queue:len(Q2), - ?line Len2 = queue:len(Q3), - ?line L1 = queue:to_list(Q1), - ?line L2 = queue:to_list(Q2), - ?line L3 = queue:to_list(Q3), - ?line Q3b = queue:join(Q0, queue:join(queue:join(Q1, Q2), Q0)), - ?line L3 = queue:to_list(Q3b), - ?line {Q0, Q3New1} = queue:split(0, Q3), - ?line L3 = queue:to_list(Q3New1), - ?line {Q3New2, Q0} = queue:split(Len2, Q3), - ?line L3 = queue:to_list(Q3New2), - ?line {Q1a, Q2a} = queue:split(Len, Q3), - ?line L1 = queue:to_list(Q1a), - ?line L2 = queue:to_list(Q2a), - ?line {Q3c, Q3d} = queue:split(2, Q3), - ?line L3 = queue:to_list(Q3c) ++ queue:to_list(Q3d), - ?line {Q1b, Q2b} = queue:split(Len, Q3b), - ?line L1 = queue:to_list(Q1b), - ?line L2 = queue:to_list(Q2b), - ?line Len = queue:len(Q1b), - ?line Len = queue:len(Q2b), - ?line Len2 = queue:len(Q3b), - ?line Q1r = queue:reverse(Q1), - ?line Q2r = queue:reverse(Q2), - ?line Q1ar = queue:reverse(Q1a), - ?line Q2ar = queue:reverse(Q2a), - ?line Q1br = queue:reverse(Q1b), - ?line Q2br = queue:reverse(Q2b), - ?line Q3br = queue:reverse(Q3b), - ?line L1r = queue:to_list(Q1r), - ?line L1r = queue:to_list(Q1ar), - ?line L1r = queue:to_list(Q1br), - ?line L2r = queue:to_list(Q2r), - ?line L2r = queue:to_list(Q2ar), - ?line L2r = queue:to_list(Q2br), - ?line L3r = queue:to_list(Q3br), - ?line Len = queue:len(Q1br), - ?line Len = queue:len(Q2br), - ?line Len2 = queue:len(Q3br), - ?line false = queue:member([], Q0), - ?line false = queue:member(0, Q0), - ?line false = queue:member(0, Q1), - ?line false = queue:member([], Q1), - ?line true = queue:member(1, Q1), - ?line false = queue:member(1.0, Q1), - ?line true = queue:member(Len, Q1), + Len = 50, + Len2 = 2*Len, + L1 = lists:seq(1, Len), + L1r = lists:reverse(L1), + L2 = lists:seq(Len+1, Len2), + L2r = lists:reverse(L2), + L3 = L1++L2, + L3r = L2r++L1r, + Q0 = F(queue:new()), + [] = queue:to_list(Q0), + Q0 = F(queue:from_list([])), + Q1 = F(queue:from_list(L1)), + Q2 = F(queue:from_list(L2)), + Q3 = F(queue:from_list(L3)), + Len = queue:len(Q1), + Len = queue:len(Q2), + Len2 = queue:len(Q3), + L1 = queue:to_list(Q1), + L2 = queue:to_list(Q2), + L3 = queue:to_list(Q3), + Q3b = queue:join(Q0, queue:join(queue:join(Q1, Q2), Q0)), + L3 = queue:to_list(Q3b), + {Q0, Q3New1} = queue:split(0, Q3), + L3 = queue:to_list(Q3New1), + {Q3New2, Q0} = queue:split(Len2, Q3), + L3 = queue:to_list(Q3New2), + {Q1a, Q2a} = queue:split(Len, Q3), + L1 = queue:to_list(Q1a), + L2 = queue:to_list(Q2a), + {Q3c, Q3d} = queue:split(2, Q3), + L3 = queue:to_list(Q3c) ++ queue:to_list(Q3d), + {Q1b, Q2b} = queue:split(Len, Q3b), + L1 = queue:to_list(Q1b), + L2 = queue:to_list(Q2b), + Len = queue:len(Q1b), + Len = queue:len(Q2b), + Len2 = queue:len(Q3b), + Q1r = queue:reverse(Q1), + Q2r = queue:reverse(Q2), + Q1ar = queue:reverse(Q1a), + Q2ar = queue:reverse(Q2a), + Q1br = queue:reverse(Q1b), + Q2br = queue:reverse(Q2b), + Q3br = queue:reverse(Q3b), + L1r = queue:to_list(Q1r), + L1r = queue:to_list(Q1ar), + L1r = queue:to_list(Q1br), + L2r = queue:to_list(Q2r), + L2r = queue:to_list(Q2ar), + L2r = queue:to_list(Q2br), + L3r = queue:to_list(Q3br), + Len = queue:len(Q1br), + Len = queue:len(Q2br), + Len2 = queue:len(Q3br), + false = queue:member([], Q0), + false = queue:member(0, Q0), + false = queue:member(0, Q1), + false = queue:member([], Q1), + true = queue:member(1, Q1), + false = queue:member(1.0, Q1), + true = queue:member(Len, Q1), %% %% Additional coverage. - ?line {MyL1r,MyL2r} = lists:split(Len-2, L1r), - ?line MyQ0r = queue:reverse(F(queue:from_list(L1))), - ?line {MyQ1r,MyQ2r} = queue:split(Len-2, MyQ0r), - ?line MyL1r = queue:to_list(MyQ1r), - ?line MyL2r = queue:to_list(MyQ2r), - ?line MyQ3r = queue:filter( - fun (X) when X rem 4 >= 2 -> false; - (X) when X rem 8 == 0 -> [float(X),{X}]; - (X) when X rem 2 >= 1 -> [{X}]; - (_) -> true - end, MyQ1r), - ?line MyL3r = lists:flatten( - [if X rem 8 == 0 -> [float(X),{X}]; - X rem 2 >= 1 -> {X}; - true -> X - end || X <- MyL1r, - X rem 4 < 2]), - ?line MyL3r = queue:to_list(MyQ3r), - ?line MyQ4 = F(queue:from_list([11,22,33,44])), - ?line [11,22] = queue:to_list(queue:filter(fun(X) when X < 27 -> true; - (_) -> [] end, MyQ4)), - ?line [33,44] = queue:to_list(queue:filter(fun(X) when X < 27 -> false; - (X) -> [X] end, MyQ4)), + {MyL1r,MyL2r} = lists:split(Len-2, L1r), + MyQ0r = queue:reverse(F(queue:from_list(L1))), + {MyQ1r,MyQ2r} = queue:split(Len-2, MyQ0r), + MyL1r = queue:to_list(MyQ1r), + MyL2r = queue:to_list(MyQ2r), + MyQ3r = queue:filter( + fun (X) when X rem 4 >= 2 -> false; + (X) when X rem 8 == 0 -> [float(X),{X}]; + (X) when X rem 2 >= 1 -> [{X}]; + (_) -> true + end, MyQ1r), + MyL3r = lists:flatten( + [if X rem 8 == 0 -> [float(X),{X}]; + X rem 2 >= 1 -> {X}; + true -> X + end || X <- MyL1r, + X rem 4 < 2]), + MyL3r = queue:to_list(MyQ3r), + MyQ4 = F(queue:from_list([11,22,33,44])), + [11,22] = queue:to_list(queue:filter(fun(X) when X < 27 -> true; + (_) -> [] end, MyQ4)), + [33,44] = queue:to_list(queue:filter(fun(X) when X < 27 -> false; + (X) -> [X] end, MyQ4)), %% ok. -error(doc) -> - "Test queue errors"; -error(suite) -> - []; +%% Test queue errors. error(Config) when is_list(Config) -> do_error(fun id/1, illegal_queue), do_error(fun id/1, {[],illegal_queue}), @@ -417,65 +394,62 @@ trycatch(M, F, Args) -> end. do_error(F, IQ) -> - ?line io:format("Illegal Queue: ~p~n", [IQ]), + io:format("Illegal Queue: ~p~n", [IQ]), %% - ?line {error,badarg} = trycatch(in, [1, IQ]), - ?line {error,badarg} = trycatch(out, [IQ]), - ?line {error,badarg} = trycatch(in_r ,[1, IQ]), - ?line {error,badarg} = trycatch(out_r ,[IQ]), - ?line {error,badarg} = trycatch(to_list ,[IQ]), + {error,badarg} = trycatch(in, [1, IQ]), + {error,badarg} = trycatch(out, [IQ]), + {error,badarg} = trycatch(in_r ,[1, IQ]), + {error,badarg} = trycatch(out_r ,[IQ]), + {error,badarg} = trycatch(to_list ,[IQ]), %% - ?line {error,badarg} = trycatch(from_list, [no_list]), - ?line {error,badarg} = trycatch(is_empty, [IQ]), - ?line {error,badarg} = trycatch(len, [IQ]), + {error,badarg} = trycatch(from_list, [no_list]), + {error,badarg} = trycatch(is_empty, [IQ]), + {error,badarg} = trycatch(len, [IQ]), %% - ?line {error,badarg} = trycatch(cons, [1, IQ]), - ?line {error,badarg} = trycatch(head, [IQ]), - ?line {error,badarg} = trycatch(tail, [IQ]), + {error,badarg} = trycatch(cons, [1, IQ]), + {error,badarg} = trycatch(head, [IQ]), + {error,badarg} = trycatch(tail, [IQ]), %% - ?line {error,badarg} = trycatch(snoc, [IQ, 1]), - ?line {error,badarg} = trycatch(last, [IQ]), - ?line {error,badarg} = trycatch(daeh, [IQ]), - ?line {error,badarg} = trycatch(liat, [IQ]), - ?line {error,badarg} = trycatch(lait, [IQ]), - ?line {error,badarg} = trycatch(init, [IQ]), + {error,badarg} = trycatch(snoc, [IQ, 1]), + {error,badarg} = trycatch(last, [IQ]), + {error,badarg} = trycatch(daeh, [IQ]), + {error,badarg} = trycatch(liat, [IQ]), + {error,badarg} = trycatch(lait, [IQ]), + {error,badarg} = trycatch(init, [IQ]), %% - ?line {error,badarg} = trycatch(reverse, [IQ]), - ?line {error,badarg} = trycatch(join, [F(queue:new()), IQ]), - ?line {error,badarg} = trycatch(join, [IQ, F(queue:new())]), - ?line {error,badarg} = trycatch(split, [17, IQ]), - ?line {error,badarg} = trycatch(head, [IQ]), + {error,badarg} = trycatch(reverse, [IQ]), + {error,badarg} = trycatch(join, [F(queue:new()), IQ]), + {error,badarg} = trycatch(join, [IQ, F(queue:new())]), + {error,badarg} = trycatch(split, [17, IQ]), + {error,badarg} = trycatch(head, [IQ]), %% - ?line Q0 = F(queue:new()), - ?line {error,badarg} = trycatch(split, [1, Q0]), - ?line {error,badarg} = trycatch(split, [2, queue:snoc(Q0, 1)]), + Q0 = F(queue:new()), + {error,badarg} = trycatch(split, [1, Q0]), + {error,badarg} = trycatch(split, [2, queue:snoc(Q0, 1)]), %% - ?line {value,false} = trycatch(is_queue, [IQ]), - ?line {error,badarg} = trycatch(get, [IQ]), - ?line {error,badarg} = trycatch(peek, [IQ]), - ?line {error,badarg} = trycatch(peek_r, [IQ]), - ?line {error,badarg} = trycatch(filter, [fun id/1, IQ]), - ?line {error,badarg} = trycatch(filter, [no_fun, Q0]), + {value,false} = trycatch(is_queue, [IQ]), + {error,badarg} = trycatch(get, [IQ]), + {error,badarg} = trycatch(peek, [IQ]), + {error,badarg} = trycatch(peek_r, [IQ]), + {error,badarg} = trycatch(filter, [fun id/1, IQ]), + {error,badarg} = trycatch(filter, [no_fun, Q0]), %% - ?line {error,badarg} = trycatch(member, [1, IQ]), + {error,badarg} = trycatch(member, [1, IQ]), ok. id(X) -> X. -oops(doc) -> - "Test queue errors"; -oops(suite) -> - []; +%% Test queue errors. oops(Config) when is_list(Config) -> - ?line N = 3142, - ?line Optab = optab(), - ?line Seed0 = rand:seed(exsplus, {1,2,4}), - ?line {Is,Seed} = random_list(N, tuple_size(Optab), Seed0, []), - ?line io:format("~p ", [Is]), - ?line QA = queue:new(), - ?line QB = {[]}, - ?line emul([QA], [QB], Seed, [element(I, Optab) || I <- Is]). + N = 3142, + Optab = optab(), + Seed0 = rand:seed(exsplus, {1,2,4}), + {Is,Seed} = random_list(N, tuple_size(Optab), Seed0, []), + io:format("~p ", [Is]), + QA = queue:new(), + QB = {[]}, + emul([QA], [QB], Seed, [element(I, Optab) || I <- Is]). optab() -> {{new,[], q, fun () -> {[]} end}, diff --git a/lib/stdlib/test/rand_SUITE.erl b/lib/stdlib/test/rand_SUITE.erl index ab260da950..6830101e96 100644 --- a/lib/stdlib/test/rand_SUITE.erl +++ b/lib/stdlib/test/rand_SUITE.erl @@ -35,19 +35,17 @@ -include_lib("common_test/include/ct.hrl"). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(3)). -define(LOOP, 1000000). init_per_testcase(_Case, Config) -> - Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), + Config. + +end_per_testcase(_Case, _Config) -> ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,3}}]. all() -> [seed, interval_int, interval_float, @@ -85,16 +83,13 @@ algs() -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -seed(doc) -> - ["Test that seed and seed_s and export_seed/0 is working."]; -seed(suite) -> - []; +%% Test that seed and seed_s and export_seed/0 is working. seed(Config) when is_list(Config) -> Algs = algs(), Test = fun(Alg) -> try seed_1(Alg) catch _:Reason -> - test_server:fail({Alg, Reason, erlang:get_stacktrace()}) + ct:fail({Alg, Reason, erlang:get_stacktrace()}) end end, [Test(Alg) || Alg <- Algs], @@ -139,10 +134,7 @@ seed_1(Alg) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -api_eq(doc) -> - ["Check that both api's are consistent with each other."]; -api_eq(suite) -> - []; +%% Check that both APIs are consistent with each other. api_eq(_Config) -> Algs = algs(), Small = fun(Alg) -> @@ -188,10 +180,7 @@ api_eq_1(S00) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -interval_int(doc) -> - ["Check that uniform/1 returns values within the proper interval."]; -interval_int(suite) -> - []; +%% Check that uniform/1 returns values within the proper interval. interval_int(Config) when is_list(Config) -> Algs = algs(), Small = fun(Alg) -> @@ -225,10 +214,7 @@ interval_int_1(N, Top, Max) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -interval_float(doc) -> - ["Check that uniform/0 returns values within the proper interval."]; -interval_float(suite) -> - []; +%% Check that uniform/0 returns values within the proper interval. interval_float(Config) when is_list(Config) -> Algs = algs(), Test = fun(Alg) -> @@ -252,8 +238,7 @@ interval_float_1(N) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -reference(doc) -> ["Check if exs64 algorithm generates the proper sequence."]; -reference(suite) -> []; +%% Check if exs64 algorithm generates the proper sequence. reference(Config) when is_list(Config) -> [reference_1(Alg) || Alg <- algs()], ok. @@ -267,7 +252,6 @@ reference_1(Alg) -> io:format("Failed: ~p~n",[Alg]), io:format("Length ~p ~p~n",[length(Refval), length(Testval)]), io:format("Head ~p ~p~n",[hd(Refval), hd(Testval)]), - %% test_server:fail({Alg, Refval -- Testval}), ok end. @@ -330,9 +314,9 @@ basic_uniform_1(0, {#{type:=Alg}, _}, Sum, A) -> %% Verify that the basic statistics are ok %% be gentle we don't want to see to many failing tests - abs(0.5 - AverN) < 0.005 orelse test_server:fail({average, Alg, AverN}), - abs(?LOOP div 100 - Min) < 1000 orelse test_server:fail({min, Alg, Min}), - abs(?LOOP div 100 - Max) < 1000 orelse test_server:fail({max, Alg, Max}), + abs(0.5 - AverN) < 0.005 orelse ct:fail({average, Alg, AverN}), + abs(?LOOP div 100 - Min) < 1000 orelse ct:fail({min, Alg, Min}), + abs(?LOOP div 100 - Max) < 1000 orelse ct:fail({max, Alg, Max}), ok. basic_uniform_2(N, S0, Sum, A0) when N > 0 -> @@ -349,9 +333,9 @@ basic_uniform_2(0, {#{type:=Alg}, _}, Sum, A) -> %% Verify that the basic statistics are ok %% be gentle we don't want to see to many failing tests - abs(50.5 - AverN) < 0.5 orelse test_server:fail({average, Alg, AverN}), - abs(?LOOP div 100 - Min) < 1000 orelse test_server:fail({min, Alg, Min}), - abs(?LOOP div 100 - Max) < 1000 orelse test_server:fail({max, Alg, Max}), + abs(50.5 - AverN) < 0.5 orelse ct:fail({average, Alg, AverN}), + abs(?LOOP div 100 - Min) < 1000 orelse ct:fail({min, Alg, Min}), + abs(?LOOP div 100 - Max) < 1000 orelse ct:fail({max, Alg, Max}), ok. basic_normal_1(N, S0, Sum, Sq) when N > 0 -> @@ -363,14 +347,13 @@ basic_normal_1(0, {#{type:=Alg}, _}, Sum, SumSq) -> io:format("~.10w: Average: ~7.4f StdDev ~6.4f~n", [Alg, Mean, StdDev]), %% Verify that the basic statistics are ok %% be gentle we don't want to see to many failing tests - abs(Mean) < 0.005 orelse test_server:fail({average, Alg, Mean}), - abs(StdDev - 1.0) < 0.005 orelse test_server:fail({stddev, Alg, StdDev}), + abs(Mean) < 0.005 orelse ct:fail({average, Alg, Mean}), + abs(StdDev - 1.0) < 0.005 orelse ct:fail({stddev, Alg, StdDev}), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -plugin(doc) -> ["Test that the user can write algorithms"]; -plugin(suite) -> []; +%% Test that the user can write algorithms. plugin(Config) when is_list(Config) -> _ = lists:foldl(fun(_, S0) -> {V1, S1} = rand:uniform_s(10000, S0), diff --git a/lib/stdlib/test/random_SUITE.erl b/lib/stdlib/test/random_SUITE.erl index 701a3e3f33..34b350e132 100644 --- a/lib/stdlib/test/random_SUITE.erl +++ b/lib/stdlib/test/random_SUITE.erl @@ -19,26 +19,23 @@ -module(random_SUITE). -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, + init_per_testcase/2, end_per_testcase/2, init_per_group/2,end_per_group/2]). -export([interval_1/1, seed0/1, seed/1]). --export([init_per_testcase/2, end_per_testcase/2]). -include_lib("common_test/include/ct.hrl"). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(1)). - init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - [{watchdog, Dog} | Config]. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), + Config. + +end_per_testcase(_Case, _Config) -> ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [interval_1, seed0, seed]. @@ -59,59 +56,50 @@ end_per_group(_GroupName, Config) -> Config. -seed0(doc) -> - ["Test that seed is set implicitly, and always the same."]; -seed0(suite) -> - []; +%% Test that seed is set implicitly, and always the same. seed0(Config) when is_list(Config) -> - ?line Self = self(), - ?line _ = spawn(fun() -> Self ! random:uniform() end), - ?line F1 = receive - Fa -> Fa - end, - ?line _ = spawn(fun() -> random:seed(), - Self ! random:uniform() end), - ?line F2 = receive - Fb -> Fb - end, - ?line F1 = F2, + Self = self(), + _ = spawn(fun() -> Self ! random:uniform() end), + F1 = receive + Fa -> Fa + end, + _ = spawn(fun() -> random:seed(), + Self ! random:uniform() end), + F2 = receive + Fb -> Fb + end, + F1 = F2, ok. -seed(doc) -> - ["Test that seed/1 and seed/3 is equivalent."]; -seed(suite) -> - []; +%% Test that seed/1 and seed/3 are equivalent. seed(Config) when is_list(Config) -> - ?line Self = self(), + Self = self(), Seed = {S1, S2, S3} = erlang:timestamp(), - ?line _ = spawn(fun() -> - random:seed(S1,S2,S3), - Rands = lists:foldl(fun - (_, Out) -> [random:uniform(10000)|Out] - end, [], lists:seq(1,100)), - Self ! {seed_test, Rands} - end), - ?line Rands1 = receive {seed_test, R1s} -> R1s end, - ?line _ = spawn(fun() -> - random:seed(Seed), - Rands = lists:foldl(fun - (_, Out) -> [random:uniform(10000)|Out] - end, [], lists:seq(1,100)), - Self ! {seed_test, Rands} - end), - ?line Rands2 = receive {seed_test, R2s} -> R2s end, - ?line Rands1 = Rands2, + _ = spawn(fun() -> + random:seed(S1,S2,S3), + Rands = lists:foldl(fun + (_, Out) -> [random:uniform(10000)|Out] + end, [], lists:seq(1,100)), + Self ! {seed_test, Rands} + end), + Rands1 = receive {seed_test, R1s} -> R1s end, + _ = spawn(fun() -> + random:seed(Seed), + Rands = lists:foldl(fun + (_, Out) -> [random:uniform(10000)|Out] + end, [], lists:seq(1,100)), + Self ! {seed_test, Rands} + end), + Rands2 = receive {seed_test, R2s} -> R2s end, + Rands1 = Rands2, ok. -interval_1(doc) -> - ["Check that uniform/1 returns values within the proper interval."]; -interval_1(suite) -> - []; +%% Check that uniform/1 returns values within the proper interval. interval_1(Config) when is_list(Config) -> - ?line Top = 7, - ?line N = 10, - ?line check_interval(N, Top), + Top = 7, + N = 10, + check_interval(N, Top), ok. check_interval(0, _) -> ok; @@ -119,9 +107,9 @@ check_interval(N, Top) -> X = random:uniform(Top), if X < 1 -> - test_server:fail(too_small); + ct:fail(too_small); X > Top -> - test_server:fail(too_large); + ct:fail(too_large); true -> ok end, diff --git a/lib/stdlib/test/re_SUITE.erl b/lib/stdlib/test/re_SUITE.erl index bd495ce587..a937e7b1cf 100644 --- a/lib/stdlib/test/re_SUITE.erl +++ b/lib/stdlib/test/re_SUITE.erl @@ -33,7 +33,9 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("kernel/include/file.hrl"). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,3}}]. all() -> [pcre, compile_options, run_options, combined_options, @@ -61,264 +63,247 @@ end_per_group(_GroupName, Config) -> Config. -pcre(doc) -> - ["Run all applicable tests from the PCRE testsuites."]; +%% Run all applicable tests from the PCRE testsuites. pcre(Config) when is_list(Config) -> - Dog = ?t:timetrap(?t:minutes(3)), - RootDir = ?config(data_dir, Config), + RootDir = proplists:get_value(data_dir, Config), Res = run_pcre_tests:test(RootDir), 0 = lists:sum([ X || {X,_,_} <- Res ]), - ?t:timetrap_cancel(Dog), {comment,Res}. -compile_options(doc) -> - ["Test all documented compile options"]; +%% Test all documented compile options. compile_options(Config) when is_list(Config) -> - ?line ok = ctest("ABDabcdABCD","abcd",[],true,{match,[{3,4}]}), - ?line ok = ctest("ABDabcdABCD","abcd",[anchored],true,nomatch), - ?line ok = ctest("ABDabcdABCD",".*abcd",[anchored],true,{match,[{0,7}]}), - ?line ok = ctest("ABCabcdABC","ABCD",[],true,nomatch), - ?line ok = ctest("ABCabcdABC","ABCD",[caseless],true,{match,[{3,4}]}), - ?line ok = ctest("abcdABC\n","ABC$",[],true,{match,[{4,3}]}), - ?line ok = ctest("abcdABC\n","ABC$",[dollar_endonly],true,nomatch), - ?line ok = ctest("abcdABC\n","ABC.",[],true,nomatch), - ?line ok = ctest("abcdABC\n","ABC.",[dotall],true,{match,[{4,4}]}), - ?line ok = ctest("abcdABCD","ABC .",[],true,nomatch), - ?line ok = ctest("abcdABCD","ABC .",[extended],true,{match,[{4,4}]}), - ?line ok = ctest("abcd\nABCD","ABC",[],true,{match,[{5,3}]}), - ?line ok = ctest("abcd\nABCD","ABC",[firstline],true,nomatch), - ?line ok = ctest("abcd\nABCD","^ABC",[],true,nomatch), - ?line ok = ctest("abcd\nABCD","^ABC",[multiline],true,{match,[{5,3}]}), - ?line ok = ctest("abcdABCD","(ABC)",[],true,{match,[{4,3},{4,3}]}), - ?line ok = ctest("abcdABCD","(ABC)",[no_auto_capture],true,{match,[{4,3}]}), - ?line ok = ctest(notused,"(?<FOO>ABC)|(?<FOO>DEF)",[],false,notused), - ?line ok = ctest("abcdABCD","(?<FOO>ABC)|(?<FOO>DEF)",[dupnames],true,{match,[{4,3},{4,3}]}), - ?line ok = ctest("abcdABCDabcABCD","abcd.*D",[],true,{match,[{0,15}]}), - ?line ok = ctest("abcdABCDabcABCD","abcd.*D",[ungreedy],true,{match,[{0,8}]}), - ?line ok = ctest("abcdABCabcABC\nD","abcd.*D",[],true,nomatch), - ?line ok = ctest("abcdABCabcABC\nD","abcd.*D",[{newline,cr}],true,{match,[{0,15}]}), - ?line ok = ctest("abcdABCabcABC\rD","abcd.*D",[],true,{match,[{0,15}]}), - ?line ok = ctest("abcdABCabcABC\rD","abcd.*D",[{newline,lf}],true,{match,[{0,15}]}), - ?line ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,lf}],true,nomatch), - ?line ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,cr}],true,nomatch), - ?line ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,crlf}],true,{match,[{7,4}]}), - - ?line ok = ctest("abcdABCabcd\r","abcd$",[{newline,crlf}],true,nomatch), - ?line ok = ctest("abcdABCabcd\n","abcd$",[{newline,crlf}],true,nomatch), - ?line ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), - - ?line ok = ctest("abcdABCabcd\r","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), - ?line ok = ctest("abcdABCabcd\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + ok = ctest("ABDabcdABCD","abcd",[],true,{match,[{3,4}]}), + ok = ctest("ABDabcdABCD","abcd",[anchored],true,nomatch), + ok = ctest("ABDabcdABCD",".*abcd",[anchored],true,{match,[{0,7}]}), + ok = ctest("ABCabcdABC","ABCD",[],true,nomatch), + ok = ctest("ABCabcdABC","ABCD",[caseless],true,{match,[{3,4}]}), + ok = ctest("abcdABC\n","ABC$",[],true,{match,[{4,3}]}), + ok = ctest("abcdABC\n","ABC$",[dollar_endonly],true,nomatch), + ok = ctest("abcdABC\n","ABC.",[],true,nomatch), + ok = ctest("abcdABC\n","ABC.",[dotall],true,{match,[{4,4}]}), + ok = ctest("abcdABCD","ABC .",[],true,nomatch), + ok = ctest("abcdABCD","ABC .",[extended],true,{match,[{4,4}]}), + ok = ctest("abcd\nABCD","ABC",[],true,{match,[{5,3}]}), + ok = ctest("abcd\nABCD","ABC",[firstline],true,nomatch), + ok = ctest("abcd\nABCD","^ABC",[],true,nomatch), + ok = ctest("abcd\nABCD","^ABC",[multiline],true,{match,[{5,3}]}), + ok = ctest("abcdABCD","(ABC)",[],true,{match,[{4,3},{4,3}]}), + ok = ctest("abcdABCD","(ABC)",[no_auto_capture],true,{match,[{4,3}]}), + ok = ctest(notused,"(?<FOO>ABC)|(?<FOO>DEF)",[],false,notused), + ok = ctest("abcdABCD","(?<FOO>ABC)|(?<FOO>DEF)",[dupnames],true,{match,[{4,3},{4,3}]}), + ok = ctest("abcdABCDabcABCD","abcd.*D",[],true,{match,[{0,15}]}), + ok = ctest("abcdABCDabcABCD","abcd.*D",[ungreedy],true,{match,[{0,8}]}), + ok = ctest("abcdABCabcABC\nD","abcd.*D",[],true,nomatch), + ok = ctest("abcdABCabcABC\nD","abcd.*D",[{newline,cr}],true,{match,[{0,15}]}), + ok = ctest("abcdABCabcABC\rD","abcd.*D",[],true,{match,[{0,15}]}), + ok = ctest("abcdABCabcABC\rD","abcd.*D",[{newline,lf}],true,{match,[{0,15}]}), + ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,lf}],true,nomatch), + ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,cr}],true,nomatch), + ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,crlf}],true,{match,[{7,4}]}), + + ok = ctest("abcdABCabcd\r","abcd$",[{newline,crlf}],true,nomatch), + ok = ctest("abcdABCabcd\n","abcd$",[{newline,crlf}],true,nomatch), + ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + + ok = ctest("abcdABCabcd\r","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + ok = ctest("abcdABCabcd\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), ok. -run_options(doc) -> - ["Test all documented run specific options"]; +%% Test all documented run specific options. run_options(Config) when is_list(Config) -> - ?line rtest("ABCabcdABC","abc",[],[],true), - ?line rtest("ABCabcdABC","abc",[anchored],[],false), - % Anchored in run overrides unanchored in compilation - ?line rtest("ABCabcdABC","abc",[],[anchored],false), - - ?line rtest("","a?b?",[],[],true), - ?line rtest("","a?b?",[],[notempty],false), - - ?line rtest("abc","^a",[],[],true), - ?line rtest("abc","^a",[],[notbol],false), - ?line rtest("ab\nc","^a",[multiline],[],true), - ?line rtest("ab\nc","^a",[multiline],[notbol],false), - ?line rtest("ab\nc","^c",[multiline],[notbol],true), - - ?line rtest("abc","c$",[],[],true), - ?line rtest("abc","c$",[],[noteol],false), - - ?line rtest("ab\nc","b$",[multiline],[],true), - ?line rtest("ab\nc","c$",[multiline],[],true), - ?line rtest("ab\nc","b$",[multiline],[noteol],true), - ?line rtest("ab\nc","c$",[multiline],[noteol],false), - - ?line rtest("abc","ab",[],[{offset,0}],true), - ?line rtest("abc","ab",[],[{offset,1}],false), - - ?line rtest("abcdABCabcABC\nD","abcd.*D",[],[],false), - ?line rtest("abcdABCabcABC\nD","abcd.*D",[],[{newline,cr}],true), - ?line rtest("abcdABCabcABC\rD","abcd.*D",[],[],true), - ?line rtest("abcdABCabcABC\rD","abcd.*D",[{newline,cr}],[{newline,lf}],true), - ?line rtest("abcdABCabcd\r\n","abcd$",[],[{newline,lf}],false), - ?line rtest("abcdABCabcd\r\n","abcd$",[],[{newline,cr}],false), - ?line rtest("abcdABCabcd\r\n","abcd$",[],[{newline,crlf}],true), - - ?line rtest("abcdABCabcd\r","abcd$",[],[{newline,crlf}],false), - ?line rtest("abcdABCabcd\n","abcd$",[],[{newline,crlf}],false), - ?line rtest("abcdABCabcd\r\n","abcd$",[],[{newline,anycrlf}],true), - - ?line rtest("abcdABCabcd\r","abcd$",[],[{newline,anycrlf}],true), - ?line rtest("abcdABCabcd\n","abcd$",[],[{newline,anycrlf}],true), - - ?line {ok,MP} = re:compile(".*(abcd).*"), - ?line {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[]), - ?line {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all}]), - ?line {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all,index}]), - ?line {match,["ABCabcdABC","abcd"]} = re:run("ABCabcdABC",MP,[{capture,all,list}]), - ?line {match,[<<"ABCabcdABC">>,<<"abcd">>]} = re:run("ABCabcdABC",MP,[{capture,all,binary}]), - ?line {match,[{0,10}]} = re:run("ABCabcdABC",MP,[{capture,first}]), - ?line {match,[{0,10}]} = re:run("ABCabcdABC",MP,[{capture,first,index}]), ?line {match,["ABCabcdABC"]} = re:run("ABCabcdABC",MP,[{capture,first,list}]), - ?line {match,[<<"ABCabcdABC">>]} = re:run("ABCabcdABC",MP,[{capture,first,binary}]), - - ?line {match,[{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all_but_first}]), - ?line {match,[{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,index}]), - ?line {match,["abcd"]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,list}]), - ?line {match,[<<"abcd">>]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,binary}]), - - ?line match = re:run("ABCabcdABC",MP,[{capture,none}]), - ?line match = re:run("ABCabcdABC",MP,[{capture,none,index}]), - ?line match = re:run("ABCabcdABC",MP,[{capture,none,list}]), - ?line match = re:run("ABCabcdABC",MP,[{capture,none,binary}]), - - ?line {ok,MP2} = re:compile(".*(?<FOO>abcd).*"), - ?line {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,[1]}]), - ?line {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,['FOO']}]), - ?line {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"]}]), - ?line {match,["abcd"]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"],list}]), - ?line {match,[<<"abcd">>]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"],binary}]), - - ?line {match,[{-1,0}]} = re:run("ABCabcdABC",MP2,[{capture,[200]}]), - ?line {match,[{-1,0}]} = re:run("ABCabcdABC",MP2,[{capture,['BAR']}]), - ?line {match,[""]} = re:run("ABCabcdABC",MP2,[{capture,[200],list}]), - ?line {match,[""]} = re:run("ABCabcdABC",MP2,[{capture,['BAR'],list}]), - ?line {match,[<<>>]} = re:run("ABCabcdABC",MP2,[{capture,[200],binary}]), - ?line {match,[<<>>]} = re:run("ABCabcdABC",MP2,[{capture,['BAR'],binary}]), - - ?line {ok, MP3} = re:compile(".*((?<FOO>abdd)|a(..d)).*"), - ?line {match,[{0,10},{3,4},{-1,0},{4,3}]} = re:run("ABCabcdABC",MP3,[]), - ?line {match,[{0,10},{3,4},{-1,0},{4,3}]} = re:run("ABCabcdABC",MP3,[{capture,all,index}]), - ?line {match,[<<"ABCabcdABC">>,<<"abcd">>,<<>>,<<"bcd">>]} = re:run("ABCabcdABC",MP3,[{capture,all,binary}]), - ?line {match,["ABCabcdABC","abcd",[],"bcd"]} = re:run("ABCabcdABC",MP3,[{capture,all,list}]), + rtest("ABCabcdABC","abc",[],[],true), + rtest("ABCabcdABC","abc",[anchored],[],false), + %% Anchored in run overrides unanchored in compilation + rtest("ABCabcdABC","abc",[],[anchored],false), + + rtest("","a?b?",[],[],true), + rtest("","a?b?",[],[notempty],false), + + rtest("abc","^a",[],[],true), + rtest("abc","^a",[],[notbol],false), + rtest("ab\nc","^a",[multiline],[],true), + rtest("ab\nc","^a",[multiline],[notbol],false), + rtest("ab\nc","^c",[multiline],[notbol],true), + + rtest("abc","c$",[],[],true), + rtest("abc","c$",[],[noteol],false), + + rtest("ab\nc","b$",[multiline],[],true), + rtest("ab\nc","c$",[multiline],[],true), + rtest("ab\nc","b$",[multiline],[noteol],true), + rtest("ab\nc","c$",[multiline],[noteol],false), + + rtest("abc","ab",[],[{offset,0}],true), + rtest("abc","ab",[],[{offset,1}],false), + + rtest("abcdABCabcABC\nD","abcd.*D",[],[],false), + rtest("abcdABCabcABC\nD","abcd.*D",[],[{newline,cr}],true), + rtest("abcdABCabcABC\rD","abcd.*D",[],[],true), + rtest("abcdABCabcABC\rD","abcd.*D",[{newline,cr}],[{newline,lf}],true), + rtest("abcdABCabcd\r\n","abcd$",[],[{newline,lf}],false), + rtest("abcdABCabcd\r\n","abcd$",[],[{newline,cr}],false), + rtest("abcdABCabcd\r\n","abcd$",[],[{newline,crlf}],true), + + rtest("abcdABCabcd\r","abcd$",[],[{newline,crlf}],false), + rtest("abcdABCabcd\n","abcd$",[],[{newline,crlf}],false), + rtest("abcdABCabcd\r\n","abcd$",[],[{newline,anycrlf}],true), + + rtest("abcdABCabcd\r","abcd$",[],[{newline,anycrlf}],true), + rtest("abcdABCabcd\n","abcd$",[],[{newline,anycrlf}],true), + + {ok,MP} = re:compile(".*(abcd).*"), + {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[]), + {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all}]), + {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all,index}]), + {match,["ABCabcdABC","abcd"]} = re:run("ABCabcdABC",MP,[{capture,all,list}]), + {match,[<<"ABCabcdABC">>,<<"abcd">>]} = re:run("ABCabcdABC",MP,[{capture,all,binary}]), + {match,[{0,10}]} = re:run("ABCabcdABC",MP,[{capture,first}]), + {match,[{0,10}]} = re:run("ABCabcdABC",MP,[{capture,first,index}]), ?line {match,["ABCabcdABC"]} = re:run("ABCabcdABC",MP,[{capture,first,list}]), + {match,[<<"ABCabcdABC">>]} = re:run("ABCabcdABC",MP,[{capture,first,binary}]), + + {match,[{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all_but_first}]), + {match,[{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,index}]), + {match,["abcd"]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,list}]), + {match,[<<"abcd">>]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,binary}]), + + match = re:run("ABCabcdABC",MP,[{capture,none}]), + match = re:run("ABCabcdABC",MP,[{capture,none,index}]), + match = re:run("ABCabcdABC",MP,[{capture,none,list}]), + match = re:run("ABCabcdABC",MP,[{capture,none,binary}]), + + {ok,MP2} = re:compile(".*(?<FOO>abcd).*"), + {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,[1]}]), + {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,['FOO']}]), + {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"]}]), + {match,["abcd"]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"],list}]), + {match,[<<"abcd">>]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"],binary}]), + + {match,[{-1,0}]} = re:run("ABCabcdABC",MP2,[{capture,[200]}]), + {match,[{-1,0}]} = re:run("ABCabcdABC",MP2,[{capture,['BAR']}]), + {match,[""]} = re:run("ABCabcdABC",MP2,[{capture,[200],list}]), + {match,[""]} = re:run("ABCabcdABC",MP2,[{capture,['BAR'],list}]), + {match,[<<>>]} = re:run("ABCabcdABC",MP2,[{capture,[200],binary}]), + {match,[<<>>]} = re:run("ABCabcdABC",MP2,[{capture,['BAR'],binary}]), + + {ok, MP3} = re:compile(".*((?<FOO>abdd)|a(..d)).*"), + {match,[{0,10},{3,4},{-1,0},{4,3}]} = re:run("ABCabcdABC",MP3,[]), + {match,[{0,10},{3,4},{-1,0},{4,3}]} = re:run("ABCabcdABC",MP3,[{capture,all,index}]), + {match,[<<"ABCabcdABC">>,<<"abcd">>,<<>>,<<"bcd">>]} = re:run("ABCabcdABC",MP3,[{capture,all,binary}]), + {match,["ABCabcdABC","abcd",[],"bcd"]} = re:run("ABCabcdABC",MP3,[{capture,all,list}]), ok. - - -combined_options(doc) -> - ["Test compile options given directly to run"]; + + +%% Test compile options given directly to run. combined_options(Config) when is_list(Config) -> - ?line ok = crtest("ABDabcdABCD","abcd",[],true,{match,[{3,4}]}), - ?line ok = crtest("ABDabcdABCD","abcd",[anchored],true,nomatch), - ?line ok = crtest("ABDabcdABCD",".*abcd",[anchored],true,{match,[{0,7}]}), - ?line ok = crtest("ABCabcdABC","ABCD",[],true,nomatch), - ?line ok = crtest("ABCabcdABC","ABCD",[caseless],true,{match,[{3,4}]}), - ?line ok = crtest("abcdABC\n","ABC$",[],true,{match,[{4,3}]}), - ?line ok = crtest("abcdABC\n","ABC$",[dollar_endonly],true,nomatch), - ?line ok = crtest("abcdABC\n","ABC.",[],true,nomatch), - ?line ok = crtest("abcdABC\n","ABC.",[dotall],true,{match,[{4,4}]}), - ?line ok = crtest("abcdABCD","ABC .",[],true,nomatch), - ?line ok = crtest("abcdABCD","ABC .",[extended],true,{match,[{4,4}]}), - ?line ok = crtest("abcd\nABCD","ABC",[],true,{match,[{5,3}]}), - ?line ok = crtest("abcd\nABCD","ABC",[firstline],true,nomatch), - ?line ok = crtest("abcd\nABCD","^ABC",[],true,nomatch), - ?line ok = crtest("abcd\nABCD","^ABC",[multiline],true,{match,[{5,3}]}), - ?line ok = crtest("abcdABCD","(ABC)",[],true,{match,[{4,3},{4,3}]}), - ?line ok = crtest("abcdABCD","(ABC)",[no_auto_capture],true,{match,[{4,3}]}), - ?line ok = crtest(notused,"(?<FOO>ABC)|(?<FOO>DEF)",[],false,notused), - ?line ok = crtest("abcdABCD","(?<FOO>ABC)|(?<FOO>DEF)",[dupnames],true,{match,[{4,3},{4,3}]}), - ?line ok = crtest("abcdABCDabcABCD","abcd.*D",[],true,{match,[{0,15}]}), - ?line ok = crtest("abcdABCDabcABCD","abcd.*D",[ungreedy],true,{match,[{0,8}]}), - ?line ok = ctest("abcdABCabcABC\nD","abcd.*D",[],true,nomatch), - ?line ok = crtest("abcdABCabcABC\nD","abcd.*D",[{newline,cr}],true,{match,[{0,15}]}), - ?line ok = crtest("abcdABCabcABC\rD","abcd.*D",[],true,{match,[{0,15}]}), - ?line ok = crtest("abcdABCabcABC\rD","abcd.*D",[{newline,lf}],true,{match,[{0,15}]}), - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,lf}],true,nomatch), - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,cr}],true,nomatch), - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,crlf}],true,{match,[{7,4}]}), - - ?line ok = crtest("abcdABCabcd\r","abcd$",[{newline,crlf}],true,nomatch), - ?line ok = crtest("abcdABCabcd\n","abcd$",[{newline,crlf}],true,nomatch), - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), - - ?line ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), - ?line ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), - - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), - - ?line ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), - - ?line ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), - - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), - - ?line ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), - ?line ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), - - % Check that unique run-options fail in compile only case: - ?line {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},{capture,all,binary}])), - ?line {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},{offset,3}])), - ?line {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},notempty])), - ?line {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},notbol])), - ?line {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},noteol])), - - - ?line {match,_} = re:run("abcdABCabcd\r\n","abcd$",[{newline,crlf}]), - ?line nomatch = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf}]), - ?line {match,_} = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf},multiline]), - ?line nomatch = re:run("abcdABCabcd\r\nefgh","efgh$",[{newline,crlf},multiline,noteol]), - ?line {match,_} = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf},multiline,noteol]), - ?line {match,_} = re:run("abcdABCabcd\r\nefgh","^abcd",[{newline,crlf},multiline,noteol]), - ?line nomatch = re:run("abcdABCabcd\r\nefgh","^abcd",[{newline,crlf},multiline,notbol]), - ?line {match,_} = re:run("abcdABCabcd\r\nefgh","^efgh",[{newline,crlf},multiline,notbol]), - ?line {match,_} = re:run("ABC\nD","[a-z]*",[{newline,crlf}]), - ?line nomatch = re:run("ABC\nD","[a-z]*",[{newline,crlf},notempty]), + ok = crtest("ABDabcdABCD","abcd",[],true,{match,[{3,4}]}), + ok = crtest("ABDabcdABCD","abcd",[anchored],true,nomatch), + ok = crtest("ABDabcdABCD",".*abcd",[anchored],true,{match,[{0,7}]}), + ok = crtest("ABCabcdABC","ABCD",[],true,nomatch), + ok = crtest("ABCabcdABC","ABCD",[caseless],true,{match,[{3,4}]}), + ok = crtest("abcdABC\n","ABC$",[],true,{match,[{4,3}]}), + ok = crtest("abcdABC\n","ABC$",[dollar_endonly],true,nomatch), + ok = crtest("abcdABC\n","ABC.",[],true,nomatch), + ok = crtest("abcdABC\n","ABC.",[dotall],true,{match,[{4,4}]}), + ok = crtest("abcdABCD","ABC .",[],true,nomatch), + ok = crtest("abcdABCD","ABC .",[extended],true,{match,[{4,4}]}), + ok = crtest("abcd\nABCD","ABC",[],true,{match,[{5,3}]}), + ok = crtest("abcd\nABCD","ABC",[firstline],true,nomatch), + ok = crtest("abcd\nABCD","^ABC",[],true,nomatch), + ok = crtest("abcd\nABCD","^ABC",[multiline],true,{match,[{5,3}]}), + ok = crtest("abcdABCD","(ABC)",[],true,{match,[{4,3},{4,3}]}), + ok = crtest("abcdABCD","(ABC)",[no_auto_capture],true,{match,[{4,3}]}), + ok = crtest(notused,"(?<FOO>ABC)|(?<FOO>DEF)",[],false,notused), + ok = crtest("abcdABCD","(?<FOO>ABC)|(?<FOO>DEF)",[dupnames],true,{match,[{4,3},{4,3}]}), + ok = crtest("abcdABCDabcABCD","abcd.*D",[],true,{match,[{0,15}]}), + ok = crtest("abcdABCDabcABCD","abcd.*D",[ungreedy],true,{match,[{0,8}]}), + ok = ctest("abcdABCabcABC\nD","abcd.*D",[],true,nomatch), + ok = crtest("abcdABCabcABC\nD","abcd.*D",[{newline,cr}],true,{match,[{0,15}]}), + ok = crtest("abcdABCabcABC\rD","abcd.*D",[],true,{match,[{0,15}]}), + ok = crtest("abcdABCabcABC\rD","abcd.*D",[{newline,lf}],true,{match,[{0,15}]}), + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,lf}],true,nomatch), + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,cr}],true,nomatch), + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,crlf}],true,{match,[{7,4}]}), + + ok = crtest("abcdABCabcd\r","abcd$",[{newline,crlf}],true,nomatch), + ok = crtest("abcdABCabcd\n","abcd$",[{newline,crlf}],true,nomatch), + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + + ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), + + ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), + + ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), + + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), + + ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), + ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), + + %% Check that unique run-options fail in compile only case: + {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},{capture,all,binary}])), + {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},{offset,3}])), + {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},notempty])), + {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},notbol])), + {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},noteol])), + + + {match,_} = re:run("abcdABCabcd\r\n","abcd$",[{newline,crlf}]), + nomatch = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf}]), + {match,_} = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf},multiline]), + nomatch = re:run("abcdABCabcd\r\nefgh","efgh$",[{newline,crlf},multiline,noteol]), + {match,_} = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf},multiline,noteol]), + {match,_} = re:run("abcdABCabcd\r\nefgh","^abcd",[{newline,crlf},multiline,noteol]), + nomatch = re:run("abcdABCabcd\r\nefgh","^abcd",[{newline,crlf},multiline,notbol]), + {match,_} = re:run("abcdABCabcd\r\nefgh","^efgh",[{newline,crlf},multiline,notbol]), + {match,_} = re:run("ABC\nD","[a-z]*",[{newline,crlf}]), + nomatch = re:run("ABC\nD","[a-z]*",[{newline,crlf},notempty]), ok. -replace_autogen(doc) -> - ["Test replace with autogenerated erlang module"]; +%% Test replace with autogenerated erlang module. replace_autogen(Config) when is_list(Config) -> - Dog = ?t:timetrap(?t:minutes(3)), re_testoutput1_replacement_test:run(), - ?t:timetrap_cancel(Dog), ok. -global_capture(doc) -> - ["Tests capture options together with global searching"]; +%% Test capture options together with global searching. global_capture(Config) when is_list(Config) -> - Dog = ?t:timetrap(?t:minutes(3)), - ?line {match,[{3,4}]} = re:run("ABCabcdABC",".*(?<FOO>abcd).*",[{capture,[1]}]), - ?line {match,[{10,4}]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[{capture,[1]}]), - ?line {match,[[{10,4}]]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[global,{capture,[1]}]), - ?line {match,[{3,4}]} = re:run("ABCabcdABC",".*(?<FOO>abcd).*",[{capture,['FOO']}]), - ?line {match,[{10,4}]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[{capture,['FOO']}]), - ?line {match,[[{10,4}]]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[global,{capture,['FOO']}]), - ?line {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global]), - ?line {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all}]), - ?line {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all,index}]), - ?line {match,[[{3,4}],[{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,first}]), - ?line {match,[[{3,4}],[{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all_but_first}]), - ?line {match,[[<<"bcd">>],[<<"bcd">>]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all_but_first,binary}]), - ?line {match,[["bcd"],["bcd"]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all_but_first,list}]), - ?line {match,[["abcd","bcd"],["abcd","bcd"]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,list}]), - ?line {match,[[<<"abcd">>,<<"bcd">>],[<<"abcd">>,<<"bcd">>]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,binary}]), - ?line {match,[[{3,4},{4,3}],[{10,4},{11,3}]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,index}]), - ?line match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,index}]), - ?line match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,binary}]), - ?line match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,list}]), - ?line {match,[[<<195,133,98,99,100>>,<<"bcd">>],[<<"abcd">>,<<"bcd">>]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,binary},unicode]), - ?line {match,[["Åbcd","bcd"],["abcd","bcd"]]} = re:run(<<"ABC",8#303,8#205,"bcdABCabcdA">>,".(?<FOO>bcd)",[global,{capture,all,list},unicode]), - ?line {match,[["Åbcd","bcd"],["abcd","bcd"]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,list},unicode]), - ?line {match,[[{3,5},{5,3}],[{11,4},{12,3}]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,index},unicode]), - ?t:timetrap_cancel(Dog), + {match,[{3,4}]} = re:run("ABCabcdABC",".*(?<FOO>abcd).*",[{capture,[1]}]), + {match,[{10,4}]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[{capture,[1]}]), + {match,[[{10,4}]]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[global,{capture,[1]}]), + {match,[{3,4}]} = re:run("ABCabcdABC",".*(?<FOO>abcd).*",[{capture,['FOO']}]), + {match,[{10,4}]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[{capture,['FOO']}]), + {match,[[{10,4}]]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[global,{capture,['FOO']}]), + {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global]), + {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all}]), + {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all,index}]), + {match,[[{3,4}],[{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,first}]), + {match,[[{3,4}],[{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all_but_first}]), + {match,[[<<"bcd">>],[<<"bcd">>]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all_but_first,binary}]), + {match,[["bcd"],["bcd"]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all_but_first,list}]), + {match,[["abcd","bcd"],["abcd","bcd"]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,list}]), + {match,[[<<"abcd">>,<<"bcd">>],[<<"abcd">>,<<"bcd">>]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,binary}]), + {match,[[{3,4},{4,3}],[{10,4},{11,3}]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,index}]), + match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,index}]), + match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,binary}]), + match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,list}]), + {match,[[<<195,133,98,99,100>>,<<"bcd">>],[<<"abcd">>,<<"bcd">>]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,binary},unicode]), + {match,[["Åbcd","bcd"],["abcd","bcd"]]} = re:run(<<"ABC",8#303,8#205,"bcdABCabcdA">>,".(?<FOO>bcd)",[global,{capture,all,list},unicode]), + {match,[["Åbcd","bcd"],["abcd","bcd"]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,list},unicode]), + {match,[[{3,5},{5,3}],[{11,4},{12,3}]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,index},unicode]), ok. -replace_input_types(doc) -> - ["Tests replace with different input types"]; +%% Test replace with different input types. replace_input_types(Config) when is_list(Config) -> - Dog = ?t:timetrap(?t:minutes(3)), - ?line <<"abcd">> = re:replace("abcd","Z","X",[{return,binary},unicode]), - ?line <<"abcd">> = re:replace("abcd","\x{400}","X",[{return,binary},unicode]), - ?line <<"a",208,128,"cd">> = re:replace(<<"abcd">>,"b","\x{400}",[{return,binary},unicode]), - ?t:timetrap_cancel(Dog), + <<"abcd">> = re:replace("abcd","Z","X",[{return,binary},unicode]), + <<"abcd">> = re:replace("abcd","\x{400}","X",[{return,binary},unicode]), + <<"a",208,128,"cd">> = re:replace(<<"abcd">>,"b","\x{400}",[{return,binary},unicode]), ok. -replace_return(doc) -> - ["Tests return options of replace together with global searching"]; +%% Test return options of replace together with global searching. replace_return(Config) when is_list(Config) -> - Dog = ?t:timetrap(?t:minutes(3)), {'EXIT',{badarg,_}} = (catch re:replace("na","(a","")), ok = replacetest(<<"nisse">>,"i","a",[{return,binary}],<<"nasse">>), ok = replacetest("ABC\305abcdABCabcdA","a(?<FOO>bcd)","X",[global,{return,binary}],<<"ABCÅXABCXA">>), @@ -339,7 +324,6 @@ replace_return(Config) when is_list(Config) -> ok = replacetest("a\x{400}bcd","d","X",[global,{return,binary},unicode],<<"a",208,128,"bcX">>), ok = replacetest("a\x{400}bcd","Z","X",[global,{return,list},unicode],"a\x{400}bcd"), ok = replacetest("a\x{400}bcd","Z","X",[global,{return,binary},unicode],<<"a",208,128,"bcd">>), - ?t:timetrap_cancel(Dog), ok. rtest(Subj, RE, Copt, Ropt, true) -> @@ -412,18 +396,13 @@ copt(ungreedy) -> true; copt(unicode) -> true; copt(_) -> false. -split_autogen(doc) -> - ["Test split with autogenerated erlang module"]; +%% Test split with autogenerated erlang module. split_autogen(Config) when is_list(Config) -> - Dog = ?t:timetrap(?t:minutes(3)), re_testoutput1_split_test:run(), - ?t:timetrap_cancel(Dog), ok. -split_options(doc) -> - ["Test special options to split."]; +%% Test special options to split. split_options(Config) when is_list(Config) -> - Dog = ?t:timetrap(?t:minutes(1)), ok = splittest("a b c ","( )",[group,trim],[[<<"a">>,<<" ">>],[<<"b">>,<<" ">>],[<<"c">>,<<" ">>]]), ok = splittest("a b c ","( )",[group,{parts,0}],[[<<"a">>,<<" ">>],[<<"b">>,<<" ">>],[<<"c">>,<<" ">>]]), ok = splittest("a b c ","( )",[{parts,infinity},group],[[<<"a">>,<<" ">>],[<<"b">>,<<" ">>],[<<"c">>,<<" ">>],[<<>>]]), @@ -439,27 +418,23 @@ split_options(Config) when is_list(Config) -> {'EXIT',{badarg,_}} = (catch re:split("a b c d","( +)",[{parts,banan}])), {'EXIT',{badarg,_}} = (catch re:split("a b c d","( +)",[{capture,all}])), {'EXIT',{badarg,_}} = (catch re:split("a b c d","( +)",[{capture,[],binary}])), - % Parts 0 is equal to no parts specification (implicit strip) + %% Parts 0 is equal to no parts specification (implicit strip) ok = splittest("a b c d","( *)",[{parts,0},{return,list}],["a"," ","b"," ","c"," ","d"]), - ?t:timetrap_cancel(Dog), ok. - + join([]) -> []; join([A]) -> [A]; join([H|T]) -> [H,<<":">>|join(T)]. -split_specials(doc) -> - ["Some special cases of split that are easy to get wrong."]; +%% Some special cases of split that are easy to get wrong. split_specials(Config) when is_list(Config) -> %% More or less just to remember these icky cases - Dog = ?t:timetrap(?t:minutes(1)), - ?line <<"::abd:f">> = + <<"::abd:f">> = iolist_to_binary(join(re:split("abdf","^(?!(ab)de|x)(abd)(f)",[trim]))), - ?line <<":abc2xyzabc3">> = + <<":abc2xyzabc3">> = iolist_to_binary(join(re:split("abc1abc2xyzabc3","\\Aabc.",[trim]))), - ?t:timetrap_cancel(Dog), ok. - + %% Test that errors are handled correctly by the erlang code. error_handling(_Config) -> @@ -470,26 +445,26 @@ error_handling(_Config) -> false -> error_handling() end. - + error_handling() -> - % This test checks the exception tuples manufactured in the erlang - % code to hide the trapping from the user at least when it comes to errors - Dog = ?t:timetrap(?t:minutes(1)), - % The malformed precomiled RE is detected after - % the trap to re:grun from grun, in the grun function clause - % that handles precompiled expressions + %% This test checks the exception tuples manufactured in the erlang + %% code to hide the trapping from the user at least when it comes to errors + + %% The malformed precomiled RE is detected after + %% the trap to re:grun from grun, in the grun function clause + %% that handles precompiled expressions {'EXIT',{badarg,[{re,run,["apa",{1,2,3,4},[global]],_}, {?MODULE,error_handling,0,_} | _]}} = (catch re:run("apa",{1,2,3,4},[global])), - % An invalid capture list will also cause a badarg late, - % but with a non pre compiled RE, the exception should be thrown by the - % grun function clause that handles RE's compiled implicitly by - % the run/3 BIF before trapping. + %% An invalid capture list will also cause a badarg late, + %% but with a non pre compiled RE, the exception should be thrown by the + %% grun function clause that handles RE's compiled implicitly by + %% the run/3 BIF before trapping. {'EXIT',{badarg,[{re,run,["apa","p",[{capture,[1,{a}]},global]],_}, {?MODULE,error_handling,0,_} | _]}} = (catch re:run("apa","p",[{capture,[1,{a}]},global])), - % And so the case of a precompiled expression together with - % a compile-option (binary and list subject): + %% And so the case of a precompiled expression together with + %% a compile-option (binary and list subject): {ok,RE} = re:compile("(p)"), {match,[[{1,1},{1,1}]]} = re:run(<<"apa">>,RE,[global]), {match,[[{1,1},{1,1}]]} = re:run("apa",RE,[global]), @@ -509,7 +484,7 @@ error_handling() -> {error, {compile, {_,_}}} = re:run("apa","(p",[report_errors]), {'EXIT',{badarg,_}} = (catch re:run("apa","(p",[global])), {error, {compile, {_,_}}} = re:run("apa","(p",[report_errors,global]), - % Badly formed options + %% Badly formed options {'EXIT',{badarg,_}} = (catch re:run(<<"apa">>,RE,["global"])), {'EXIT',{badarg,_}} = (catch re:run(<<"apa">>,RE,[{offset,-1}])), {'EXIT',{badarg,_}} = (catch re:run(<<"apa">>,RE,[{offset,ett}])), @@ -536,7 +511,7 @@ error_handling() -> {'EXIT',{badarg,_}} = (catch re:run(<<"apa",2:2>>,<<"(p)">>,[{capture,[0,1],binary}])), <<_:4,Temp:3/binary,_:4>> = <<38,23,6,18>>, {match,[{1,1},{1,1}]} = re:run(Temp,<<"(p)">>,[]), % Unaligned works - % The replace errors: + %% The replace errors: {'EXIT',{badarg,[{re,replace,["apa",{1,2,3,4},"X",[]],_}, {?MODULE,error_handling,0,_} | _]}} = (catch re:replace("apa",{1,2,3,4},"X",[])), @@ -572,13 +547,13 @@ error_handling() -> (catch iolist_to_binary(re:replace("apa","p","X", [{return,banana}]))), {'EXIT',{badarg,_}} = (catch re:replace("apa","(p","X",[])), - % Badarg, not compile error. + %% Badarg, not compile error. {'EXIT',{badarg,[{re,replace, ["apa","(p","X",[{return,banana}]],_}, {?MODULE,error_handling,0,_} | _]}} = (catch iolist_to_binary(re:replace("apa","(p","X", [{return,banana}]))), - % And the split errors: + %% And the split errors: [<<"a">>,<<"a">>] = (catch re:split("apa","p",[])), [<<"a">>,<<"p">>,<<"a">>] = (catch re:split("apa",RE,[])), {'EXIT',{badarg,[{re,split,["apa","p",[report_errors]],_}, @@ -618,34 +593,31 @@ error_handling() -> {?MODULE,error_handling,0,_} | _]}} = (catch re:split("apa",RE,[banana])), {'EXIT',{badarg,_}} = (catch re:split("apa","(p")), - %Exception on bad argument, not compilation error + %%Exception on bad argument, not compilation error {'EXIT',{badarg,[{re,split, ["apa", "(p", [banana]],_}, {?MODULE,error_handling,0,_} | _]}} = (catch re:split("apa","(p",[banana])), - ?t:timetrap_cancel(Dog), ok. - -pcre_cve_2008_2371(doc) -> - "Fix as in http://vcs.pcre.org/viewvc?revision=360&view=revision"; + +%% Fix as in http://vcs.pcre.org/viewvc?revision=360&view=revision pcre_cve_2008_2371(Config) when is_list(Config) -> %% Make sure it doesn't crash the emulator. re:compile(<<"(?i)[\xc3\xa9\xc3\xbd]|[\xc3\xa9\xc3\xbdA]">>, [unicode]), ok. -pcre_compile_workspace_overflow(doc) -> - "Patch from http://vcs.pcre.org/viewvc/code/trunk/pcre_compile.c?r1=504&r2=505&view=patch"; +%% Patch from +%% http://vcs.pcre.org/viewvc/code/trunk/pcre_compile.c?r1=504&r2=505&view=patch pcre_compile_workspace_overflow(Config) when is_list(Config) -> N = 819, - ?line {error,{"internal error: overran compiling workspace",799}} = + {error,{"internal error: overran compiling workspace",799}} = re:compile([lists:duplicate(N, $(), lists:duplicate(N, $))]), ok. -re_infinite_loop(doc) -> - "Make sure matches that really loop infinitely actually fail"; + +%% Make sure matches that really loop infinitely actually fail. re_infinite_loop(Config) when is_list(Config) -> - Dog = ?t:timetrap(?t:minutes(1)), Str = "http:/www.flickr.com/slideShow/index.gne?group_id=&user_id=69845378@N0", EMail_regex = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+" @@ -657,20 +629,17 @@ re_infinite_loop(Config) when is_list(Config) -> nomatch = re:run(Str, EMail_regex, [global]), {error,match_limit} = re:run(Str, EMail_regex,[report_errors]), {error,match_limit} = re:run(Str, EMail_regex,[report_errors,global]), - ?t:timetrap_cancel(Dog), ok. -re_backwards_accented(doc) -> - "Check for nasty bug where accented graphemes can make PCRE back past " - "beginning of subject"; + +%% Check for nasty bug where accented graphemes can make PCRE back +%% past beginning of subject. re_backwards_accented(Config) when is_list(Config) -> - Dog = ?t:timetrap(?t:minutes(1)), - ?line match = re:run(<<65,204,128,65,204,128,97,98,99>>, - <<"\\X?abc">>, - [unicode,{capture,none}]), - ?t:timetrap_cancel(Dog), + match = re:run(<<65,204,128,65,204,128,97,98,99>>, + <<"\\X?abc">>, + [unicode,{capture,none}]), ok. -opt_dupnames(doc) -> - "Check correct handling of dupnames option to re"; + +%% Check correct handling of dupnames option to re. opt_dupnames(Config) when is_list(Config) -> Days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"], _ = [ begin @@ -704,9 +673,9 @@ opt_dupnames(Config) when is_list(Config) -> "(?<DN>Sat)(?:urday)?", [dupnames, {capture, ['Skrap','DN','Skrap2'],index}]), {match,[{-1,0},{0,3},{-1,0}]} = re:run("Wednesday","(?<Skrap>.)(?<DN>Mon|Fri|Sun)(?:day)?(?<Skrap2>.)|" - "(?<DN>Tue)(?:sday)?|(?<DN>Wed)nesday|(?<DN>Thu)(?:rsday)?|" - "(?<DN>Sat)(?:urday)?", - [dupnames, {capture, ['Skrap','DN','Skrap2'],index}]), + "(?<DN>Tue)(?:sday)?|(?<DN>Wed)nesday|(?<DN>Thu)(?:rsday)?|" + "(?<DN>Sat)(?:urday)?", + [dupnames, {capture, ['Skrap','DN','Skrap2'],index}]), nomatch = re:run("Wednsday","(?<Skrap>.)(?<DN>Mon|Fri|Sun)(?:day)?(?<Skrap2>.)|" "(?<DN>Tue)(?:sday)?|(?<DN>Wed)nesday|(?<DN>Thu)(?:rsday)?|" "(?<DN>Sat)(?:urday)?", @@ -758,8 +727,7 @@ opt_dupnames(Config) when is_list(Config) -> "h","a","n","T","e","then"],binary}]), ok. -opt_all_names(doc) -> - "Test capturing of all_names"; +%% Test capturing of all_names. opt_all_names(Config) when is_list(Config) -> Days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"], {match,[{1,3},{0,1},{7,1}]} = re:run("SMondayX","(?<Skrap>.)(?<DN>Mon|Fri|Sun)(?:day)?(?<Skrap2>.)|" @@ -767,10 +735,10 @@ opt_all_names(Config) when is_list(Config) -> "(?<DN>Sat)(?:urday)?", [dupnames, {capture, all_names,index}]), {match,[{0,3},{-1,0},{-1,0}]} = re:run("Wednesday","(?<Skrap>.)(?<DN>Mon|Fri|Sun)(?:day)?(?<Skrap2>.)|" - "(?<DN>Tue)(?:sday)?|(?<DN>Wed)nesday|(?<DN>Thu)(?:rsday)?|" - "(?<DN>Sat)(?:urday)?", - [dupnames, {capture, all_names,index}]), - + "(?<DN>Tue)(?:sday)?|(?<DN>Wed)nesday|(?<DN>Thu)(?:rsday)?|" + "(?<DN>Sat)(?:urday)?", + [dupnames, {capture, all_names,index}]), + _ = [ begin {match,[{0,3}]} = re:run(Day, @@ -809,7 +777,7 @@ opt_all_names(Config) when is_list(Config) -> {match,[[<<>>,<<>>,<<"C">>], [<<>>,<<>>,<<"C">>], [<<>>,<<>>,<<"C">>]]} = re:run("CCC","(?<A>A)|(?<B>B)|(?<C>C)", - [global,{capture, all_names, binary}]), + [global,{capture, all_names, binary}]), {match,[[<<"C">>,<<>>], [<<>>,<<"B">>], [<<"C">>,<<>>]]} = re:run("CBC","(?<A>A)|(?<B>B)|(?<A>C)", @@ -831,8 +799,7 @@ opt_all_names(Config) when is_list(Config) -> [dupnames,{capture,all_names,binary}]), ok. -inspect(doc) -> - "Test the minimal inspect function"; +%% Test the minimal inspect function. inspect(Config) when is_list(Config)-> {ok,MP} = re:compile("(?<A>A)|(?<B>B)|(?<C>C)."), {namelist,[<<"A">>,<<"B">>,<<"C">>]} = re:inspect(MP,namelist), @@ -845,15 +812,13 @@ inspect(Config) when is_list(Config)-> {'EXIT',{badarg,_}} = (catch re:inspect({re_pattern,3,0,0,<<"kalle",2:2>>},namelist)), ok. -opt_no_start_optimize(doc) -> - "Test that the no_start_optimize compilation flag works"; +%% Test that the no_start_optimize compilation flag works. opt_no_start_optimize(Config) when is_list(Config) -> {match, [{3,3}]} = re:run("DEFABC","(*COMMIT)ABC",[]), % Start optimization makes this result wrong! nomatch = re:run("DEFABC","(*COMMIT)ABC",[no_start_optimize]), % This is the correct result... ok. -opt_never_utf(doc) -> - "Check that the never_utf option works"; +%% Check that the never_utf option works. opt_never_utf(Config) when is_list(Config) -> {match,[{0,3}]} = re:run("ABC","ABC",[never_utf]), {match,[{0,3}]} = re:run("ABC","(*UTF)ABC",[]), @@ -867,29 +832,29 @@ opt_never_utf(Config) when is_list(Config) -> {error,_} = (catch re:compile("(*UTF)ABC",[never_utf])), {error,_} = (catch re:compile("(*UTF8)ABC",[never_utf])), ok. -opt_ucp(doc) -> - "Check that the ucp option is passed to PCRE"; + +%% Check that the ucp option is passed to PCRE. opt_ucp(Config) when is_list(Config) -> {match,[{0,1}]} = re:run([$a],"\\w",[unicode]), {match,[{0,2}]} = re:run([229],"\\w",[unicode]), % Latin1 works without UCP, as we have a default - % Latin1 table + %% Latin1 table nomatch = re:run([1024],"\\w",[unicode]), % Latin1 word characters only, 1024 is not latin1 {match,[{0,2}]} = re:run([1024],"\\w",[unicode,ucp]), % Any Unicode word character works with 'ucp' ok. -match_limit(doc) -> - "Check that the match_limit and match_limit_recursion options work"; + +%% Check that the match_limit and match_limit_recursion options work. match_limit(Config) when is_list(Config) -> nomatch = re:run("aaaaaaaaaaaaaz","(a+)*zz",[]), nomatch = re:run("aaaaaaaaaaaaaz","(a+)*zz",[{match_limit,3000}]), nomatch = re:run("aaaaaaaaaaaaaz","(a+)*zz",[{match_limit_recursion,10}]), nomatch = re:run("aaaaaaaaaaaaaz","(a+)*zz",[report_errors]), {error,match_limit} = re:run("aaaaaaaaaaaaaz","(a+)*zz",[{match_limit,3000}, - report_errors]), + report_errors]), {error,match_limit_recursion} = re:run("aaaaaaaaaaaaaz","(a+)*zz",[{match_limit_recursion,10}, report_errors]), {error,match_limit} = re:run("aaaaaaaaaaaaaz","(a+)*zz",[{match_limit,3000}, - report_errors,global]), + report_errors,global]), {error,match_limit_recursion} = re:run("aaaaaaaaaaaaaz","(a+)*zz",[{match_limit_recursion,10}, report_errors,global]), @@ -902,9 +867,9 @@ match_limit(Config) when is_list(Config) -> "aaaaaaaaaaaaaz" = re:replace("aaaaaaaaaaaaaz","(a+)*zz","!", [{match_limit,3000},{return,list}]), {'EXIT', {badarg,_}} = (catch re:replace("aaaaaaaaaaaaaz","(a+)*zz","!", - [{match_limit_recursion,-1},{return,list}])), + [{match_limit_recursion,-1},{return,list}])), {'EXIT', {badarg,_}} = (catch re:replace("aaaaaaaaaaaaaz","(a+)*zz","!", - [{match_limit,-1},{return,list}])), + [{match_limit,-1},{return,list}])), {'EXIT', {badarg,_}} = (catch re:run("aaaaaaaaaaaaaz","(a+)*zz", [{match_limit_recursion,-1}, report_errors,global])), @@ -912,9 +877,8 @@ match_limit(Config) when is_list(Config) -> [{match_limit,-1}, report_errors,global])), ok. -sub_binaries(doc) -> - "test that we get sub-binaries if subject is a binary and we " - "capture binaries"; +%% Test that we get sub-binaries if subject is a binary and we capture +%% binaries. sub_binaries(Config) when is_list(Config) -> Bin = list_to_binary(lists:seq(1,255)), {match,[B,C]}=re:run(Bin,"(a)",[{capture,all,binary}]), diff --git a/lib/stdlib/test/run_pcre_tests.erl b/lib/stdlib/test/run_pcre_tests.erl index b7d1df39b8..8b0373d062 100644 --- a/lib/stdlib/test/run_pcre_tests.erl +++ b/lib/stdlib/test/run_pcre_tests.erl @@ -69,8 +69,6 @@ pick_exec_options([]) -> test([],_,_,_) -> 0; test([{RE0,Line,Options0,Tests}|T],PreCompile,XMode,REAsList) -> - %io:format("."), - %case RE of <<>> -> io:format("Empty re:~w~n",[Line]); _ -> ok end, Unicode = lists:member(unicode,Options0), RE = case REAsList of true -> @@ -90,7 +88,6 @@ test([{RE0,Line,Options0,Tests}|T],PreCompile,XMode,REAsList) -> end, case Cres of {ok,P} -> - %erlang:display({testrun,RE,P,Tests,ExecOptions,Xopt,XMode}), case (catch testrun(RE,P,Tests,ExecOptions,Xopt,XMode)) of N when is_integer(N) -> N + test(T,PreCompile,XMode,REAsList); @@ -125,16 +122,10 @@ test([{RE0,Line,Options0,Tests}|T],PreCompile,XMode,REAsList) -> loopexec(_,_,X,Y,_,_) when X > Y -> {match,[]}; loopexec(P,Chal,X,Y,Unicode,Xopt) -> - %io:format("~p~n",[X]), case re:run(Chal,P,[{offset,X}]++Xopt) of nomatch -> - %io:format(" re:exec(~p,~p,[{offset,~p}]) -> ~p~n", - % [P,Chal,X,no]), {match,[]}; - %loopexec(P,Chal,X+1,Y); {match,[{A,B}|More]} -> - %io:format(" re:exec(~p,~p,[{offset,~p}]) -> ~p~n", - % [P,Chal,X,{match,[{A,B}|More]}]), {match,Rest} = case B>0 of true -> @@ -169,7 +160,6 @@ forward(Chal,A,N,true) -> _ -> 1 end, - %io:format("Forward ~p~n",[Forw]), forward(Chal,A+Forw,N-1,true). contains_eightbit(<<>>) -> @@ -334,8 +324,6 @@ testrun(RE,P,[{Chal,Line,ExecOpt,Responses}|T],EO,Xopt0,XMode) -> nomatch -> nomatch; {match, Reslist} -> - %io:format("re:run(~w,~w,~w) -> ~w~n",[Chal,P,ExecOpt++Xopt++ - % [{capture,all,list}],Reslist]), UFix = lists:member(unicode,EO), {match,bfix([if UFix =:= true -> list_to_utf8(L); @@ -425,7 +413,6 @@ pickline(Start,Stop,Bin) when Stop >= size(Bin) -> {Res,Stop}; pickline(Start,Stop,Bin) -> - %erlang:display({Start,Stop,size(Bin)}), <<_:Stop/binary,Ch,_/binary>> = Bin, case Ch of $\n -> @@ -465,15 +452,13 @@ stru([{_,<<>>}|T]) -> stru(T); stru([{Line,<<Ch,Re0/binary>>}|T0]) -> {T,Re} = find_rest_re(Ch,[{Line,Re0}|T0]), - %io:format("DBG: ~p~n",[Re]), {NewRe,<< Ch, Options/binary >>} = end_of_re(Ch,Re), case interpret_options_x(backstrip(frontstrip(Options)),NewRe) of {Olist,<<>>} -> U = lists:member(unicode,Olist), case T of [{_,<<$-,_/binary>>}|Con] -> - %Debug output, we skip those - %io:format("Skipping debug (~w)~n",[Line]), + %%Debug output, we skip those TmpT = skip_debug(Con), {NewT,Matches} = stru2(TmpT,U), [{NewRe,Line,Olist,Matches}|stru(NewT)]; @@ -482,12 +467,10 @@ stru([{Line,<<Ch,Re0/binary>>}|T0]) -> {NewT,Matches} = stru2(NewT0,U), [{NewRe,Line,Olist,Matches}|stru(NewT)]; [{_,<<Bla,_/binary>>}|_] when Bla =/= $ -> - %io:format("Skipping blabla (~w)~n",[Line]), NewT = skip_until_empty(T), stru(NewT); _ -> {NewT,Matches} = stru2(T,U), - %erlang:display({NewRe,Line,Olist,Matches}), Matches1 = case U of true -> Matches ++ @@ -496,7 +479,6 @@ stru([{Line,<<Ch,Re0/binary>>}|T0]) -> false -> Matches end, - %erlang:display({NewRe,Line,Olist,Matches1}), [{NewRe,Line,Olist,Matches1}|stru(NewT)] end; {_,Rest} -> @@ -605,7 +587,7 @@ backslash_end(<<_,R/binary>>) -> backslash_end(R). stru2([{Line,<<$ ,Rest/binary>>} | T],U) -> - % A challenge + %% A challenge case (catch responses(T,U)) of {NewT,Rlist} -> {NewNewT,StrList} = stru2(NewT,U), @@ -765,17 +747,17 @@ pick_offset(Rest) -> escape(<<>>,_) -> {[],<<>>}; escape(<<$\\, Ch, Rest/binary>>,U) when Ch >= $A, Ch =< $Z; Ch =:= $? -> - %Options in the string... + %%Options in the string... NewOpts = eopt(Ch), {MoreOpts,Tail} = escape(Rest,U), {NewOpts ++ MoreOpts,Tail}; escape(<<$\\, $>, Rest/binary>>,U) -> - %Offset Options in the string... + %%Offset Options in the string... {NewOpt,NewRest} = pick_offset(Rest), {MoreOpts,Tail} = escape(NewRest,U), {[NewOpt|MoreOpts],Tail}; escape(<<$\\, $<, Rest/binary>>,U) -> - %CR Options in the string... + %%CR Options in the string... {NewOpt,NewRest} = pinch_cr(Rest), {MoreOpts,Tail} = escape(NewRest,U), {[NewOpt|MoreOpts],Tail}; @@ -789,7 +771,6 @@ escape(<<$\\, Ch, Rest/binary>>,U) -> {<<$\\>>,<<Ch,Rest/binary>>} end; CCC -> - %erlang:display({escape,CCC}), {<<CCC>>,Rest} end, {MoreOpts,Tail} = escape(NR,U), @@ -877,7 +858,6 @@ multi_esc(<<$x,${,N,O,$},Rest/binary>>,Unicode) ((N >= $a) and (N =< $f))) and (((O >= $0) and (O =< $9)) or ((O >= $A) and (O =< $F)) or ((O >= $a) and (O =< $f)))) -> - %io:format("~p(~p)~n",[<<$x,${,N,O,$}>>,get(unicode)]), Cha = (trx(N) bsl 4) bor trx(O), case Unicode of false -> @@ -974,8 +954,8 @@ single_esc($\\) -> $\\; single_esc($a) -> 7; -%single_esc(Ch) when Ch >= $A, Ch =< $Z -> % eh? -% Ch; +%%single_esc(Ch) when Ch >= $A, Ch =< $Z -> % eh? +%% Ch; single_esc(_) -> no. @@ -1003,8 +983,6 @@ gen_split_test(OneFile) -> io:format(F,"-module(~s).~n",[ErlModule]), io:format(F,"-compile(export_all).~n",[]), io:format(F,"-compile(no_native).~n",[]), - %io:format(F,"-include(\"test_server.hrl\").~n",[]), - %io:format(F,"-define(line,erlang:display(?LINE),).~n",[]), io:format(F,"%% This file is generated by running ~w:gen_split_test(~p)~n", [?MODULE,OneFile]), io:format(F,"join([]) -> [];~n",[]), @@ -1095,7 +1073,6 @@ gen_repl_test(OneFile) -> io:format(F,"-module(~s).~n",[ErlModule]), io:format(F,"-compile(export_all).~n",[]), io:format(F,"-compile(no_native).~n",[]), - %io:format(F,"-include(\"test_server.hrl\").~n",[]), io:format(F,"%% This file is generated by running ~w:gen_repl_test(~p)~n", [?MODULE,OneFile]), io:format(F,"run() ->~n",[]), diff --git a/lib/stdlib/test/select_SUITE.erl b/lib/stdlib/test/select_SUITE.erl index f92971583a..b7e86377c4 100644 --- a/lib/stdlib/test/select_SUITE.erl +++ b/lib/stdlib/test/select_SUITE.erl @@ -27,21 +27,21 @@ %% Define to run outside of test server %% %%-define(STANDALONE,1). - + %% %% Define for debug output %% %%-define(debug,1). - + -ifdef(STANDALONE). -define(config(A,B),config(A,B)). -export([config/2]). --define(fmt(A,B),io:format(A,B)). -else. -include_lib("common_test/include/ct.hrl"). --define(fmt(A,B),test_server:format(A,B)). -endif. - + +-define(fmt(A,B), io:format(A, B)). + -ifdef(debug). -ifdef(STANDALONE). -define(line, erlang:display({?MODULE,?LINE}), ). @@ -53,7 +53,7 @@ -endif. -define(dbgformat(A,B),noop). -endif. - + -ifdef(STANDALONE). config(priv_dir,_) -> ".". @@ -64,16 +64,15 @@ config(priv_dir,_) -> init_per_testcase/2, end_per_testcase/2, return_values/1]). -init_per_testcase(_Case, Config) when is_list(Config) -> - ?line Dog=test_server:timetrap(test_server:seconds(1200)), - [{watchdog, Dog}|Config]. +init_per_testcase(_Case, Config) -> + Config. -end_per_testcase(_Case, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,20}}]. all() -> [return_values, select_test]. @@ -94,17 +93,11 @@ end_per_group(_GroupName, Config) -> Config. -select_test(suite) -> - []; -select_test(doc) -> - ["Tests select in numerous ways"]; +%% Test select in numerous ways. select_test(Config) when is_list(Config) -> do_test(Config). -return_values(suite) -> - []; -return_values(doc) -> - ["Tests return values in specific situations for select/3 and select/1"]; +%% Test return values in specific situations for select/3 and select/1. return_values(Config) when is_list(Config) -> do_return_values(). @@ -117,7 +110,7 @@ table_factor({ets,_}) -> 100. gen_dets_filename(Config,N) -> - filename:join(?config(priv_dir,Config), + filename:join(proplists:get_value(priv_dir,Config), "testdets_" ++ integer_to_list(N) ++ ".dets"). create_tables(Config) -> @@ -128,15 +121,15 @@ create_tables(Config) -> F1 = gen_dets_filename(Config,1), (catch file:delete(F1)), {ok,DetsPlain} = dets:open_file(testdets_1, - [{file, F1}]), + [{file, F1}]), F3 = gen_dets_filename(Config,3), (catch file:delete(F3)), {ok,DetsBag} = dets:open_file(testdets_3, - [{file, F3},{type, bag}]), + [{file, F3},{type, bag}]), F4 = gen_dets_filename(Config,4), (catch file:delete(F4)), {ok,DetsDBag} = dets:open_file(testdets_4, - [{file, F4},{type, duplicate_bag}]), + [{file, F4},{type, duplicate_bag}]), [{ets,Hash}, {ets,Tree}, {ets,Bag}, {ets,DBag}, {dets, DetsPlain}, {dets, DetsBag}, {dets, DetsDBag}]. @@ -189,7 +182,7 @@ build_tables(Config,Type) -> L = create_tables(Config), ?dbgformat("Tables: ~p~n",[L]), lists:foreach(fun(TD) -> - fill_table(TD,table_size(TD),Type) + fill_table(TD,table_size(TD),Type) end, L), L. @@ -202,10 +195,10 @@ destroy_tables([{ets,Tab}|T]) -> destroy_tables([{dets,Tab}|T]) -> dets:close(Tab), destroy_tables(T). - + init_random(Config) -> - WriteDir = ReadDir = ?config(priv_dir,Config), + WriteDir = ReadDir = proplists:get_value(priv_dir,Config), (catch file:make_dir(WriteDir)), Seed = case file:consult(filename:join([ReadDir, "preset_random_seed2.txt"])) of @@ -229,7 +222,7 @@ create_pb_key(N,list) -> X = rand:uniform(N), case rand:uniform(4) of 3 -> {[X, X+1, '_'], fun([Z,Z1,P1]) -> - [Z,Z1,P1] =:= [X,X+1,P1] end}; + [Z,Z1,P1] =:= [X,X+1,P1] end}; 2 -> {[X, '_', '_'], fun([Z,P1,P2]) -> [Z,P1,P2] =:= [X,P1,P2] end}; 1 -> {[X, X+1, '$1'], fun([Z,Z1,P1]) -> [Z,Z1,P1] =:= [X,X+1,P1] end}; @@ -309,7 +302,7 @@ cmp_ms_to_fun({Mod,Tab}, MS, Fun1, Fun2, ChunkSize) -> false -> ?fmt("Match_spec result differs from fun result:~n",[]), ?fmt("Parameters: ~p,~p,~p,~p~n", - [{Mod,Tab}, MS, Fun1, Fun2]), + [{Mod,Tab}, MS, Fun1, Fun2]), ?fmt("Match_spec Result: ~p~n", [MSRes]), ?fmt("Fun Result: ~p~n", [FunRes]), Info = (catch Mod:info(Tab)), @@ -351,18 +344,18 @@ do_test(Config) -> ?fmt("multi_key done for type ~w~n",[Type]), multi_mixed_key(Tabs,Type), ?fmt("multi_mixed_key done for type ~w~n", - [Type]), + [Type]), destroy_tables(Tabs) end, [tuple, list, complex]), ok. - + basic_key(Tabs,Type) -> Fun = fun() -> lists:map(fun(Tab) -> - ?line Key = + Key = create_random_key(num_els(Tab),Type), - ?line MS = + MS = [{{Key,'_','_','_','_'},[],['$_']}], MF = fun({Key0,A,B,F,Bi},Acc) -> case Key =:= Key0 of @@ -373,18 +366,18 @@ basic_key(Tabs,Type) -> Acc end end, - ?line cmp_ms_to_fun(Tab,MS,MF,[]) + cmp_ms_to_fun(Tab,MS,MF,[]) end, Tabs) end, - ?line do_n(50,Fun), + do_n(50,Fun), ok. - + basic_pb_key(Tabs,Type) -> InnerFun = fun(Tab) -> - ?line {Key,KeyFun} = + {Key,KeyFun} = create_pb_key(num_els(Tab),Type), - ?line MS = [{{Key,'_','_','_','_'},[],['$_']}], + MS = [{{Key,'_','_','_','_'},[],['$_']}], MF = fun({Key0,A,B,F,Bi},Acc) -> case KeyFun(Key0) of true -> @@ -394,27 +387,27 @@ basic_pb_key(Tabs,Type) -> Acc end end, - ?line cmp_ms_to_fun(Tab,MS,MF,[]) + cmp_ms_to_fun(Tab,MS,MF,[]) end, - ?line {Etses, Detses} = split_by_type(Tabs), - - ?line FunEts = fun() -> - ?line lists:foreach(InnerFun, - Etses) - end, - ?line FunDets = fun() -> - ?line lists:foreach(InnerFun, - Detses) - end, - ?line do_n(table_factor(hd(Etses)) div 2,FunEts), - ?line do_n(10,FunDets), + {Etses, Detses} = split_by_type(Tabs), + + FunEts = fun() -> + lists:foreach(InnerFun, + Etses) + end, + FunDets = fun() -> + lists:foreach(InnerFun, + Detses) + end, + do_n(table_factor(hd(Etses)) div 2,FunEts), + do_n(10,FunDets), ok. - + double_pb_key(Tabs,Type) -> InnerFun = fun(Tab) -> - ?line {KeyA,KeyFunA} = + {KeyA,KeyFunA} = create_pb_key(num_els(Tab),Type), - ?line {KeyB,KeyFunB} = + {KeyB,KeyFunB} = create_pb_key(num_els(Tab),Type), MS = [{{KeyA,'_','_','_','_'},[],['$_']}, {{KeyB,'_','_','_','_'},[],['$_']}], @@ -448,51 +441,51 @@ double_pb_key(Tabs,Type) -> end end end, - ?line cmp_ms_to_fun(Tab,MS,MF,[]) + cmp_ms_to_fun(Tab,MS,MF,[]) end, - ?line {Etses, Detses} = split_by_type(Tabs), - - ?line FunEts = fun() -> - ?line lists:foreach(InnerFun, - Etses) - end, - ?line FunDets = fun() -> - ?line lists:foreach(InnerFun, - Detses) - end, - ?line do_n(table_factor(hd(Etses)) div 2,FunEts), - ?line do_n(10,FunDets), + {Etses, Detses} = split_by_type(Tabs), + + FunEts = fun() -> + lists:foreach(InnerFun, + Etses) + end, + FunDets = fun() -> + lists:foreach(InnerFun, + Detses) + end, + do_n(table_factor(hd(Etses)) div 2,FunEts), + do_n(10,FunDets), ok. - - + + multi_key(Tabs,Type) -> Fun = fun() -> lists:map(fun(Tab) -> - ?line KeyA = + KeyA = create_random_key(num_els(Tab),Type), - ?line KeyB = + KeyB = create_random_key(num_els(Tab),Type), - ?line KeyC = + KeyC = create_random_key(num_els(Tab),Type), - ?line KeyD = + KeyD = create_random_key(num_els(Tab),Type), - ?line KeyE = + KeyE = create_random_key(num_els(Tab),Type), - ?line KeyF = + KeyF = create_random_key(num_els(Tab),Type), - ?line KeyG = + KeyG = create_random_key(num_els(Tab),Type), - ?line KeyH = + KeyH = create_random_key(num_els(Tab),Type), - ?line KeyI = + KeyI = create_random_key(num_els(Tab),Type), - ?line KeyJ = + KeyJ = create_random_key(num_els(Tab),Type), - ?line KeyK = + KeyK = create_random_key(num_els(Tab),Type), - ?line KeyL = + KeyL = create_random_key(num_els(Tab),Type), - + MS = [{{KeyA,'$1','_','$2','_'},[], [{{'$1','$2'}}]}, {{KeyB,'$1','_','$2','_'},[], @@ -519,7 +512,7 @@ multi_key(Tabs,Type) -> [{{'$1','$2'}}]} ], ?dbgformat("Tab: ~p, MS: ~p~n", - [Tab,MS]), + [Tab,MS]), MF = fun({Key0,A,_B,F,_Bi},Acc) -> case Key0 of KeyA -> @@ -562,40 +555,40 @@ multi_key(Tabs,Type) -> Acc end end, - ?line cmp_ms_to_fun(Tab,MS,MF,[]) + cmp_ms_to_fun(Tab,MS,MF,[]) end, Tabs) end, - ?line do_n(33,Fun), + do_n(33,Fun), ok. - + multi_mixed_key(Tabs,Type) -> InnerFun = fun(Tab) -> - ?line KeyA = + KeyA = create_random_key(num_els(Tab),Type), - ?line KeyB = + KeyB = create_random_key(num_els(Tab),Type), - ?line KeyC = + KeyC = create_random_key(num_els(Tab),Type), - ?line KeyD = + KeyD = create_random_key(num_els(Tab),Type), - ?line {KeyE, FunE} = + {KeyE, FunE} = create_pb_key(num_els(Tab),Type), - ?line KeyF = + KeyF = create_random_key(num_els(Tab),Type), - ?line {KeyG, FunG} = + {KeyG, FunG} = create_pb_key(num_els(Tab),Type), - ?line KeyH = + KeyH = create_random_key(num_els(Tab),Type), - ?line KeyI = + KeyI = create_random_key(num_els(Tab),Type), - ?line {KeyJ, FunJ} = + {KeyJ, FunJ} = create_pb_key(num_els(Tab),Type), - ?line KeyK = + KeyK = create_random_key(num_els(Tab),Type), - ?line KeyL = + KeyL = create_random_key(num_els(Tab),Type), - + MS = [{{KeyA,'$1','_','$2','_'},[], [{{'$1','$2'}}]}, {{KeyB,'$1','_','$2','_'},[], @@ -664,34 +657,34 @@ multi_mixed_key(Tabs,Type) -> end end end, - ?line cmp_ms_to_fun(Tab,MS,MF,[]), - ?line case Tab of - {ets,_} -> - ?line cmp_ms_to_fun(Tab,MS,MF,[],1), - ?line cmp_ms_to_fun(Tab,MS,MF,[],10), - ?line cmp_ms_to_fun(Tab,MS,MF,[],1000000), - ?line cmp_ms_to_fun(Tab,MS,MF,[],-1), - ?line cmp_ms_to_fun(Tab,MS,MF,[],-10), - ?line cmp_ms_to_fun(Tab,MS,MF,[],-1000000); - _ -> - ok - end + cmp_ms_to_fun(Tab,MS,MF,[]), + case Tab of + {ets,_} -> + cmp_ms_to_fun(Tab,MS,MF,[],1), + cmp_ms_to_fun(Tab,MS,MF,[],10), + cmp_ms_to_fun(Tab,MS,MF,[],1000000), + cmp_ms_to_fun(Tab,MS,MF,[],-1), + cmp_ms_to_fun(Tab,MS,MF,[],-10), + cmp_ms_to_fun(Tab,MS,MF,[],-1000000); + _ -> + ok + end end, - ?line {Etses, Detses} = split_by_type(Tabs), - - ?line FunEts = fun() -> - ?line lists:foreach(InnerFun, - Etses) - end, - ?line FunDets = fun() -> - ?line lists:foreach(InnerFun, - Detses) - end, - ?line do_n(table_factor(hd(Etses)) div 2,FunEts), - ?line do_n(table_factor(hd(Detses)) div 2,FunDets), + {Etses, Detses} = split_by_type(Tabs), + + FunEts = fun() -> + lists:foreach(InnerFun, + Etses) + end, + FunDets = fun() -> + lists:foreach(InnerFun, + Detses) + end, + do_n(table_factor(hd(Etses)) div 2,FunEts), + do_n(table_factor(hd(Detses)) div 2,FunDets), ok. - - + + split_by_type(List) -> split_by_type(List,[],[]). split_by_type([],AccEts,AccDets) -> @@ -702,121 +695,119 @@ split_by_type([{ets,Tab}|T],AccEts,AccDets) -> split_by_type(T,[{ets,Tab}|AccEts],AccDets). whitebox() -> - ?line ets:new(xxx,[named_table, ordered_set]), - ?line ets:new(yyy,[named_table]), - ?line E = fun(0,_)->ok; - (N,F) -> - ?line ets:insert(xxx,{N,N rem 10}), - ?line ets:insert(yyy,{N,N rem 10}), - F(N-1,F) - end, - ?line E(10000,E), - - ?line G = fun(F,C,A) -> - ?line case ets:select(C) of - {L,C2} -> - ?line F(F,C2,A+length(L)); - '$end_of_table' -> - ?line A - end - end, - ?line H=fun({L,C}) -> - ?line G(G,C,length(L)) - end, - - ?line 1 = H(ets:select(xxx,[{{'$1','$2'},[{'<','$1',2}],['$_']}],7)), - ?line 10000 = H(ets:select(xxx,[{{'$1','$2'},[],['$_']}],1)), - ?line 1 = H(ets:select(yyy,[{{'$1','$2'},[{'<','$1',2}],['$_']}],7)), - ?line 10000 = H(ets:select(yyy,[{{'$1','$2'},[],['$_']}],1)), - - ?line {[{5,5}],_} = ets:select(xxx,[{{5,'$2'},[],['$_']}],1), - ?line {[{5,5}],_} = ets:select(yyy,[{{5,'$2'},[],['$_']}],1), - - ?line I = fun(_,0) -> - ok; - (I,N) -> - ?line 10000 = - H(ets:select(xxx,[{{'$1','$2'},[],['$_']}],N)), - I(I,N-1) - end, - ?line I(I,2000), - ?line J = fun(F,C,A) -> - ?line case ets:select(C) of - {L,C2} -> - ?line F(F,C2,lists:reverse(L)++A); - '$end_of_table' -> - ?line lists:reverse(A) - end - end, - ?line K = fun({L,C}) -> - ?line J(J,C,lists:reverse(L)) - end, - ?line M = fun(_, _, 0) -> - ok; - (F, What, N) -> - ?line What = - K(ets:select(xxx,[{{'$1','$2'},[],['$_']}],N)), - F(F, What, N-1) - end, - ?line N = fun(HM) -> - ?line What = ets:select(xxx,[{{'$1','$2'},[],['$_']}]), - ?line What = lists:sort(What), - M(M, What, HM) - end, - ?line N(2000), - ?line ets:delete(xxx), - ?line ets:delete(yyy). + ets:new(xxx,[named_table, ordered_set]), + ets:new(yyy,[named_table]), + E = fun(0,_)->ok; + (N,F) -> + ets:insert(xxx,{N,N rem 10}), + ets:insert(yyy,{N,N rem 10}), + F(N-1,F) + end, + E(10000,E), + + G = fun(F,C,A) -> + case ets:select(C) of + {L,C2} -> + F(F,C2,A+length(L)); + '$end_of_table' -> + A + end + end, + H=fun({L,C}) -> + G(G,C,length(L)) + end, + + 1 = H(ets:select(xxx,[{{'$1','$2'},[{'<','$1',2}],['$_']}],7)), + 10000 = H(ets:select(xxx,[{{'$1','$2'},[],['$_']}],1)), + 1 = H(ets:select(yyy,[{{'$1','$2'},[{'<','$1',2}],['$_']}],7)), + 10000 = H(ets:select(yyy,[{{'$1','$2'},[],['$_']}],1)), + + {[{5,5}],_} = ets:select(xxx,[{{5,'$2'},[],['$_']}],1), + {[{5,5}],_} = ets:select(yyy,[{{5,'$2'},[],['$_']}],1), + + I = fun(_,0) -> + ok; + (I,N) -> + 10000 = + H(ets:select(xxx,[{{'$1','$2'},[],['$_']}],N)), + I(I,N-1) + end, + I(I,2000), + J = fun(F,C,A) -> + case ets:select(C) of + {L,C2} -> + F(F,C2,lists:reverse(L)++A); + '$end_of_table' -> + lists:reverse(A) + end + end, + K = fun({L,C}) -> + J(J,C,lists:reverse(L)) + end, + M = fun(_, _, 0) -> + ok; + (F, What, N) -> + What = + K(ets:select(xxx,[{{'$1','$2'},[],['$_']}],N)), + F(F, What, N-1) + end, + N = fun(HM) -> + What = ets:select(xxx,[{{'$1','$2'},[],['$_']}]), + What = lists:sort(What), + M(M, What, HM) + end, + N(2000), + ets:delete(xxx), + ets:delete(yyy). do_return_values() -> - ?line T = ets:new(xxx,[ordered_set]), - ?line U = ets:new(xxx,[]), - ?line '$end_of_table' = ets:select(T,[{'_',[],['$_']}],1), - ?line '$end_of_table' = ets:select(U,[{'_',[],['$_']}],1), - ?line ets:insert(T,{ett,1}), - ?line ets:insert(U,{ett,1}), - ?line {[{ett,1}],C1} = ets:select(T,[{'_',[],['$_']}],1), - ?line '$end_of_table' = ets:select(C1), - ?line {[{ett,1}],C2} = ets:select(U,[{'_',[],['$_']}],1), - ?line '$end_of_table' = ets:select(C2), - ?line {[{ett,1}],C3} = ets:select(T,[{'_',[],['$_']}],2), - ?line '$end_of_table' = ets:select(C3), - ?line {[{ett,1}],C4} = ets:select(U,[{'_',[],['$_']}],2), - ?line '$end_of_table' = ets:select(C4), - ?line E = fun(0,_)->ok; - (N,F) -> - ?line ets:insert(T,{N,N rem 10}), - ?line ets:insert(U,{N,N rem 10}), - F(N-1,F) - end, - ?line E(10000,E), - ?line '$end_of_table' = ets:select(T,[{{hej, hopp},[],['$_']}],1), - ?line '$end_of_table' = ets:select(U,[{{hej,hopp},[],['$_']}],1), - ?line {[{ett,1}],CC1} = ets:select(T,[{{'$1','_'},[{is_atom, '$1'}], - ['$_']}],1), - ?line '$end_of_table' = ets:select(CC1), - ?line {[{ett,1}],CC2} = ets:select(U,[{{'$1','_'},[{is_atom, '$1'}], - ['$_']}],1), - ?line '$end_of_table' = ets:select(CC2), - ?line {[{ett,1}],CC3} = ets:select(T,[{{'$1','_'},[{is_atom, '$1'}], - ['$_']}],2), - ?line '$end_of_table' = ets:select(CC3), - ?line {[{ett,1}],CC4} = ets:select(U,[{{'$1','_'},[{is_atom, '$1'}], - ['$_']}],2), - ?line '$end_of_table' = ets:select(CC4), - ?line ets:delete(T), - ?line ets:delete(U), - ?line V = ets:new(xxx,[{keypos, 4}]), - ?line X = ets:new(xxx,[ordered_set, {keypos, 4}]), - ?line ets:insert(V,{1,1,1,ett}), - ?line ets:insert(X,{1,1,1,ett}), - ?line '$end_of_table' = ets:select(V,[{{1,1,1},[],['$_']}],1), - ?line '$end_of_table' = ets:select(X,[{{1,1,1},[],['$_']}],1), - ?line ets:delete(V), - ?line ets:delete(X), + T = ets:new(xxx,[ordered_set]), + U = ets:new(xxx,[]), + '$end_of_table' = ets:select(T,[{'_',[],['$_']}],1), + '$end_of_table' = ets:select(U,[{'_',[],['$_']}],1), + ets:insert(T,{ett,1}), + ets:insert(U,{ett,1}), + {[{ett,1}],C1} = ets:select(T,[{'_',[],['$_']}],1), + '$end_of_table' = ets:select(C1), + {[{ett,1}],C2} = ets:select(U,[{'_',[],['$_']}],1), + '$end_of_table' = ets:select(C2), + {[{ett,1}],C3} = ets:select(T,[{'_',[],['$_']}],2), + '$end_of_table' = ets:select(C3), + {[{ett,1}],C4} = ets:select(U,[{'_',[],['$_']}],2), + '$end_of_table' = ets:select(C4), + E = fun(0,_)->ok; + (N,F) -> + ets:insert(T,{N,N rem 10}), + ets:insert(U,{N,N rem 10}), + F(N-1,F) + end, + E(10000,E), + '$end_of_table' = ets:select(T,[{{hej, hopp},[],['$_']}],1), + '$end_of_table' = ets:select(U,[{{hej,hopp},[],['$_']}],1), + {[{ett,1}],CC1} = ets:select(T,[{{'$1','_'},[{is_atom, '$1'}], + ['$_']}],1), + '$end_of_table' = ets:select(CC1), + {[{ett,1}],CC2} = ets:select(U,[{{'$1','_'},[{is_atom, '$1'}], + ['$_']}],1), + '$end_of_table' = ets:select(CC2), + {[{ett,1}],CC3} = ets:select(T,[{{'$1','_'},[{is_atom, '$1'}], + ['$_']}],2), + '$end_of_table' = ets:select(CC3), + {[{ett,1}],CC4} = ets:select(U,[{{'$1','_'},[{is_atom, '$1'}], + ['$_']}],2), + '$end_of_table' = ets:select(CC4), + ets:delete(T), + ets:delete(U), + V = ets:new(xxx,[{keypos, 4}]), + X = ets:new(xxx,[ordered_set, {keypos, 4}]), + ets:insert(V,{1,1,1,ett}), + ets:insert(X,{1,1,1,ett}), + '$end_of_table' = ets:select(V,[{{1,1,1},[],['$_']}],1), + '$end_of_table' = ets:select(X,[{{1,1,1},[],['$_']}],1), + ets:delete(V), + ets:delete(X), ok. - - diff --git a/lib/stdlib/test/sets_SUITE.erl b/lib/stdlib/test/sets_SUITE.erl index 06da696700..b866cb62e0 100644 --- a/lib/stdlib/test/sets_SUITE.erl +++ b/lib/stdlib/test/sets_SUITE.erl @@ -36,15 +36,14 @@ -import(lists, [foldl/3,reverse/1]). init_per_testcase(_Case, Config) -> - Dog = ?t:timetrap(?t:minutes(5)), - [{watchdog,Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,5}}]. all() -> [create, add_element, del_element, subtract, diff --git a/lib/stdlib/test/shell_SUITE.erl b/lib/stdlib/test/shell_SUITE.erl index 747b76abb6..af735218b9 100644 --- a/lib/stdlib/test/shell_SUITE.erl +++ b/lib/stdlib/test/shell_SUITE.erl @@ -54,26 +54,23 @@ config(priv_dir,_) -> -else. -include_lib("common_test/include/ct.hrl"). -export([init_per_testcase/2, end_per_testcase/2]). -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(10)). init_per_testcase(_Case, Config) -> - ?line Dog = ?t:timetrap(?default_timeout), - ?line OrigPath = code:get_path(), - ?line code:add_patha(?config(priv_dir,Config)), - [{orig_path,OrigPath}, {watchdog, Dog} | Config]. + OrigPath = code:get_path(), + code:add_patha(proplists:get_value(priv_dir,Config)), + [{orig_path,OrigPath} | Config]. end_per_testcase(_Case, Config) -> - ?line Dog = ?config(watchdog, Config), - ?line test_server:timetrap_cancel(Dog), - ?line OrigPath = ?config(orig_path,Config), - ?line code:set_path(OrigPath), - ?line application:unset_env(stdlib, restricted_shell), - ?line (catch code:purge(user_default)), - ?line (catch code:delete(user_default)), + OrigPath = proplists:get_value(orig_path,Config), + code:set_path(OrigPath), + application:unset_env(stdlib, restricted_shell), + (catch code:purge(user_default)), + (catch code:delete(user_default)), ok. -endif. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,10}}]. all() -> [forget, records, known_bugs, otp_5226, otp_5327, @@ -112,101 +109,95 @@ end_per_group(_GroupName, Config) -> -record(state, {bin, reply, leader, unic = latin1}). -start_restricted_from_shell(doc) -> - ["Test that a restricted shell can be started from the normal shell"]; -start_restricted_from_shell(suite) -> - []; +%% Test that a restricted shell can be started from the normal shell. start_restricted_from_shell(Config) when is_list(Config) -> - ?line [{error,nofile}] = scan(<<"begin shell:start_restricted(" - "nonexisting_module) end.">>), - ?line Test = filename:join(?config(priv_dir, Config), - "test_restricted.erl"), + [{error,nofile}] = scan(<<"begin shell:start_restricted(" + "nonexisting_module) end.">>), + Test = filename:join(proplists:get_value(priv_dir, Config), + "test_restricted.erl"), Contents = <<"-module(test_restricted). -export([local_allowed/3, non_local_allowed/3]). - local_allowed(m,[],State) -> - {true,State}; - local_allowed(ugly,[],_State) -> - non_conforming_reply; - local_allowed(_,_,State) -> - {false,State}. - - non_local_allowed({shell,stop_restricted},[],State) -> - {true,State}; - non_local_allowed({erlang,'+'},[_],State) -> - {true,State}; - non_local_allowed({erlang,'-'},[_,_],_State) -> - non_conforming_reply; - non_local_allowed({h, d}, [Arg], S) -> - {{redirect, {erlang,hd}, [Arg]}, S}; - non_local_allowed(_,_,State) -> - {false,State}. - ">>, - ?line ok = compile_file(Config, Test, Contents, []), - ?line "exception exit: restricted shell starts now" = - comm_err(<<"begin shell:start_restricted(" - "test_restricted) end.">>), - ?line {ok, test_restricted} = - application:get_env(stdlib, restricted_shell), - ?line "Module" ++ _ = t({<<"begin m() end.">>, utf8}), - ?line "exception exit: restricted shell does not allow c(foo)" = - comm_err(<<"begin c(foo) end.">>), - ?line "exception exit: restricted shell does not allow init:stop()" = - comm_err(<<"begin init:stop() end.">>), - ?line "exception exit: restricted shell does not allow init:stop()" = - comm_err(<<"begin F = fun() -> init:stop() end, F() end.">>), - ?line "exception error: an error occurred when evaluating an arithmetic expression" = - comm_err(<<"begin +a end.">>), - ?line "exception exit: restricted shell does not allow a + b" = - comm_err(<<"begin a+b end.">>), - ?line "exception exit: restricted shell does not allow - b" = - comm_err(<<"begin -b end.">>), - ?line "exception exit: restricted shell does not allow 1 + 2" = - comm_err(<<"begin if atom(1 + 2> 0) -> 1; true -> 2 end end.">>), - ?line "exception exit: restricted shell does not allow 1 + 2" = - comm_err(<<"begin if is_atom(1 + 2> 0) -> 1; true -> 2 end end.">>), - ?line "exception exit: restricted shell does not allow - 2" = - comm_err(<<"begin if - 2 -> 1; true -> 2 end end.">>), - ?line "exception exit: restricted shell does not allow - 2" = - comm_err(<<"begin if (- 2 > 0) andalso true -> 1; true -> 2 end end.">>), - ?line "exception exit: restricted shell does not allow - 2" = - comm_err(<<"begin if (- 2 > 0) orelse true -> 1; true -> 2 end end.">>), - ?line "exception exit: restricted shell does not allow 1 + 2" = - comm_err(<<"begin if 1 + 2 > 0 -> 1; true -> 2 end end.">>), - ?line "exception exit: restricted shell does not allow 1 + 2" = - comm_err(<<"begin if erlang:is_atom(1 + 2> 0) -> 1; true -> 2 end end.">>), - ?line "exception exit: restricted shell does not allow is_integer(1)" = - comm_err(<<"begin if is_integer(1) -> 1; true -> 2 end end.">>), - ?line "exception exit: restricted shell does not allow is_integer(1)" = - comm_err(<<"begin if integer(1) -> 1; true -> 2 end end.">>), - ?line "exception exit: " - "restricted shell module returned bad value non_conforming_reply" = - comm_err(<<"ugly().">>), - ?line [one] = scan(<<"h:d([one,two]).">>), - ?line "exception exit: " - "restricted shell module returned bad value non_conforming_reply" = - comm_err(<<"1 - 2.">>), - ?line "exception exit: restricted shell stopped"= - comm_err(<<"begin shell:stop_restricted() end.">>), - ?line undefined = - application:get_env(stdlib, restricted_shell), - ok. - -start_restricted_on_command_line(doc) -> - ["Check restricted shell when started from the command line"]; -start_restricted_on_command_line(suite) -> - []; +local_allowed(m,[],State) -> + {true,State}; +local_allowed(ugly,[],_State) -> + non_conforming_reply; +local_allowed(_,_,State) -> + {false,State}. + +non_local_allowed({shell,stop_restricted},[],State) -> + {true,State}; +non_local_allowed({erlang,'+'},[_],State) -> + {true,State}; +non_local_allowed({erlang,'-'},[_,_],_State) -> + non_conforming_reply; +non_local_allowed({h, d}, [Arg], S) -> + {{redirect, {erlang,hd}, [Arg]}, S}; +non_local_allowed(_,_,State) -> + {false,State}. +">>, + ok = compile_file(Config, Test, Contents, []), +"exception exit: restricted shell starts now" = +comm_err(<<"begin shell:start_restricted(" + "test_restricted) end.">>), +{ok, test_restricted} = +application:get_env(stdlib, restricted_shell), +"Module" ++ _ = t({<<"begin m() end.">>, utf8}), +"exception exit: restricted shell does not allow c(foo)" = +comm_err(<<"begin c(foo) end.">>), +"exception exit: restricted shell does not allow init:stop()" = +comm_err(<<"begin init:stop() end.">>), +"exception exit: restricted shell does not allow init:stop()" = +comm_err(<<"begin F = fun() -> init:stop() end, F() end.">>), +"exception error: an error occurred when evaluating an arithmetic expression" = +comm_err(<<"begin +a end.">>), +"exception exit: restricted shell does not allow a + b" = +comm_err(<<"begin a+b end.">>), +"exception exit: restricted shell does not allow - b" = +comm_err(<<"begin -b end.">>), +"exception exit: restricted shell does not allow 1 + 2" = +comm_err(<<"begin if atom(1 + 2> 0) -> 1; true -> 2 end end.">>), +"exception exit: restricted shell does not allow 1 + 2" = +comm_err(<<"begin if is_atom(1 + 2> 0) -> 1; true -> 2 end end.">>), +"exception exit: restricted shell does not allow - 2" = +comm_err(<<"begin if - 2 -> 1; true -> 2 end end.">>), +"exception exit: restricted shell does not allow - 2" = +comm_err(<<"begin if (- 2 > 0) andalso true -> 1; true -> 2 end end.">>), +"exception exit: restricted shell does not allow - 2" = +comm_err(<<"begin if (- 2 > 0) orelse true -> 1; true -> 2 end end.">>), +"exception exit: restricted shell does not allow 1 + 2" = +comm_err(<<"begin if 1 + 2 > 0 -> 1; true -> 2 end end.">>), +"exception exit: restricted shell does not allow 1 + 2" = +comm_err(<<"begin if erlang:is_atom(1 + 2> 0) -> 1; true -> 2 end end.">>), +"exception exit: restricted shell does not allow is_integer(1)" = +comm_err(<<"begin if is_integer(1) -> 1; true -> 2 end end.">>), +"exception exit: restricted shell does not allow is_integer(1)" = +comm_err(<<"begin if integer(1) -> 1; true -> 2 end end.">>), +"exception exit: " +"restricted shell module returned bad value non_conforming_reply" = +comm_err(<<"ugly().">>), +[one] = scan(<<"h:d([one,two]).">>), +"exception exit: " +"restricted shell module returned bad value non_conforming_reply" = +comm_err(<<"1 - 2.">>), +"exception exit: restricted shell stopped"= +comm_err(<<"begin shell:stop_restricted() end.">>), +undefined = +application:get_env(stdlib, restricted_shell), +ok. + +%% Check restricted shell when started from the command line. start_restricted_on_command_line(Config) when is_list(Config) -> - ?line {ok,Node} = start_node(shell_suite_helper_1, - "-pa "++?config(priv_dir,Config)++ - " -stdlib restricted_shell foo"), - ?line "Warning! Restricted shell module foo not found: nofile"++_ = + {ok,Node} = start_node(shell_suite_helper_1, + "-pa "++proplists:get_value(priv_dir,Config)++ + " -stdlib restricted_shell foo"), + "Warning! Restricted shell module foo not found: nofile"++_ = t({Node, <<"begin m() end.">>}), - ?line "exception exit: restricted shell does not allow m()" = + "exception exit: restricted shell does not allow m()" = comm_err({Node, <<"begin m() end.">>}), - ?line [ok] = + [ok] = (catch scan({Node, <<"begin q() end.">>})), - ?line test_server:stop_node(Node), - ?line Test = filename:join(?config(priv_dir, Config), + test_server:stop_node(Node), + Test = filename:join(proplists:get_value(priv_dir, Config), "test_restricted2.erl"), Contents = <<"-module(test_restricted2). -export([local_allowed/3, non_local_allowed/3]). @@ -222,36 +213,34 @@ start_restricted_on_command_line(Config) when is_list(Config) -> non_local_allowed(_,_,State) -> {false,State}. ">>, - ?line ok = compile_file(Config, Test, Contents, []), - ?line {ok,Node2} = start_node(shell_suite_helper_2, - "-pa "++?config(priv_dir,Config)++ + ok = compile_file(Config, Test, Contents, []), + {ok,Node2} = start_node(shell_suite_helper_2, + "-pa "++proplists:get_value(priv_dir,Config)++ " -stdlib restricted_shell test_restricted2"), - ?line "Module" ++ _ = t({Node2,<<"begin m() end.">>, utf8}), - ?line "exception exit: restricted shell does not allow c(foo)" = + "Module" ++ _ = t({Node2,<<"begin m() end.">>, utf8}), + "exception exit: restricted shell does not allow c(foo)" = comm_err({Node2,<<"begin c(foo) end.">>}), - ?line "exception exit: restricted shell does not allow init:stop()" = + "exception exit: restricted shell does not allow init:stop()" = comm_err({Node2,<<"begin init:stop() end.">>}), - ?line "exception exit: restricted shell does not allow init:stop()" = + "exception exit: restricted shell does not allow init:stop()" = comm_err({Node2,<<"begin F = fun() -> init:stop() end, F() end.">>}), - ?line [Node2] = + [Node2] = scan({Node2, <<"begin erlang:node() end.">>}), - ?line [Node2] = + [Node2] = scan({Node2, <<"begin node() end.">>}), - ?line "exception exit: restricted shell stopped"= + "exception exit: restricted shell stopped"= comm_err({Node2,<<"begin shell:stop_restricted() end.">>}), - ?line [ok] = + [ok] = scan({Node2, <<"begin q() end.">>}), - ?line test_server:stop_node(Node2), + test_server:stop_node(Node2), ok. -restricted_local(suite) -> - []; -restricted_local(doc) -> - ["Tests calling local shell functions with spectacular arguments in restricted shell"]; +%% Tests calling local shell functions with spectacular arguments in +%% restricted shell. restricted_local(Config) when is_list(Config) -> - ?line [{error,nofile}] = scan(<<"begin shell:start_restricted(" + [{error,nofile}] = scan(<<"begin shell:start_restricted(" "nonexisting_module) end.">>), - ?line Test = filename:join(?config(priv_dir, Config), + Test = filename:join(proplists:get_value(priv_dir, Config), "test_restricted_local.erl"), Contents = <<"-module(test_restricted_local). -export([local_allowed/3, non_local_allowed/3]). @@ -271,8 +260,8 @@ restricted_local(Config) when is_list(Config) -> non_local_allowed(_,_,State) -> {false,State}. ">>, - ?line ok = compile_file(Config, Test, Contents, []), - ?line Test2 = filename:join(?config(priv_dir, Config), + ok = compile_file(Config, Test, Contents, []), + Test2 = filename:join(proplists:get_value(priv_dir, Config), "user_default.erl"), Contents2 = <<"-module(user_default). -export([funkis/1,apple/1]). @@ -283,115 +272,109 @@ restricted_local(Config) when is_list(Config) -> apple(_) -> apple. ">>, - ?line ok = compile_file(Config, Test2, Contents2, []), - ?line "exception exit: restricted shell starts now" = + ok = compile_file(Config, Test2, Contents2, []), + "exception exit: restricted shell starts now" = comm_err(<<"begin shell:start_restricted(" "test_restricted_local) end.">>), - ?line {ok, test_restricted_local} = + {ok, test_restricted_local} = application:get_env(stdlib, restricted_shell), - ?line "exception exit: restricted shell does not allow foo(" ++ _ = + "exception exit: restricted shell does not allow foo(" ++ _ = comm_err(<<"begin F=fun() -> hello end, foo(F) end.">>), - ?line "exception error: undefined shell command banan/1" = + "exception error: undefined shell command banan/1" = comm_err(<<"begin F=fun() -> hello end, banan(F) end.">>), - ?line "{error,"++_ = t(<<"begin F=fun() -> hello end, c(F) end.">>), - ?line "exception exit: restricted shell does not allow l(" ++ _ = + "{error,"++_ = t(<<"begin F=fun() -> hello end, c(F) end.">>), + "exception exit: restricted shell does not allow l(" ++ _ = comm_err(<<"begin F=fun() -> hello end, l(F) end.">>), - ?line "exception error: variable 'F' is unbound" = + "exception error: variable 'F' is unbound" = comm_err(<<"begin F=fun() -> hello end, f(F), F end.">>), - ?line [funkis] = + [funkis] = scan(<<"begin F=fun() -> hello end, funkis(F) end.">>), - ?line "exception exit: restricted shell does not allow apple(" ++ _ = + "exception exit: restricted shell does not allow apple(" ++ _ = comm_err(<<"begin F=fun() -> hello end, apple(F) end.">>), - ?line "exception exit: restricted shell stopped"= + "exception exit: restricted shell stopped"= comm_err(<<"begin shell:stop_restricted() end.">>), - ?line undefined = + undefined = application:get_env(stdlib, restricted_shell), - ?line (catch code:purge(user_default)), - ?line true = (catch code:delete(user_default)), + (catch code:purge(user_default)), + true = (catch code:delete(user_default)), ok. -forget(doc) -> - ["f/0 and f/1"]; -forget(suite) -> - []; +%% f/0 and f/1. forget(Config) when is_list(Config) -> %% f/0 - ?line [ok] = scan(<<"begin f() end.">>), - ?line "1: variable 'A' is unbound" = + [ok] = scan(<<"begin f() end.">>), + "1: variable 'A' is unbound" = comm_err(<<"A = 3, f(), A.">>), - ?line [ok] = scan(<<"A = 3, A = f(), A.">>), + [ok] = scan(<<"A = 3, A = f(), A.">>), %% f/1 - ?line [ok] = scan(<<"begin f(A) end.">>), - ?line "1: variable 'A' is unbound" = + [ok] = scan(<<"begin f(A) end.">>), + "1: variable 'A' is unbound" = comm_err(<<"A = 3, f(A), A.">>), - ?line [ok] = scan(<<"A = 3, A = f(A), A.">>), - ?line "exception error: no function clause matching call to f/1" = + [ok] = scan(<<"A = 3, A = f(A), A.">>), + "exception error: no function clause matching call to f/1" = comm_err(<<"f(a).">>), ok. -records(doc) -> - ["Test of the record support. OTP-5063."]; -records(suite) -> - []; +%% Test of the record support. OTP-5063. records(Config) when is_list(Config) -> %% rd/2 - ?line [{attribute,_,record,{bar,_}},ok] = + [{attribute,_,record,{bar,_}},ok] = scan(<<"rd(foo,{bar}), rd(bar,{foo = (#foo{})#foo.bar}), rl(bar).">>), - ?line "variable 'R' is unbound" = % used to work (before OTP-5878, R11B) + "variable 'R' is unbound" = % used to work (before OTP-5878, R11B) exit_string(<<"rd(foo,{bar}), R = #foo{}, rd(bar,{foo = R#foo.bar}).">>), - ?line "exception error: no function clause matching call to rd/2" = + "exception error: no function clause matching call to rd/2" = comm_err(<<"rd({foo},{bar}).">>), - ?line "bad record declaration" = exit_string(<<"A = bar, rd(foo,A).">>), - ?line [foo] = scan(<<"begin rd(foo,{bar}) end.">>), - ?line "1: record foo undefined" = + "bad record declaration" = exit_string(<<"A = bar, rd(foo,A).">>), + [foo] = scan(<<"begin rd(foo,{bar}) end.">>), + "1: record foo undefined" = comm_err(<<"begin rd(foo,{bar}), #foo{} end.">>), - ?line ['f o o'] = scan(<<"rd('f o o', {bar}).">>), - ?line [foo] = scan(<<"rd(foo,{bar}), rd(foo,{foo = #foo{}}).">>), + ['f o o'] = scan(<<"rd('f o o', {bar}).">>), + [foo] = scan(<<"rd(foo,{bar}), rd(foo,{foo = #foo{}}).">>), %% rf/0,1 - ?line [_, {attribute,_,record,{foo,_}},ok] = + [_, {attribute,_,record,{foo,_}},ok] = scan(<<"rf('_'). rd(foo,{bar}),rl().">>), - ?line "1: record foo undefined" = + "1: record foo undefined" = comm_err(<<"rd(foo,{bar}), #foo{}, rf(foo), #foo{}.">>), - ?line [ok,{foo,undefined}] = + [ok,{foo,undefined}] = scan(<<"rd(foo,{bar}), A = #foo{}, rf(foo). A.">>), - ?line [_] = scan(<<"begin rf() end.">>), - ?line [ok] = scan(<<"begin rf(foo) end.">>), + [_] = scan(<<"begin rf() end.">>), + [ok] = scan(<<"begin rf(foo) end.">>), %% rp/1 - ?line "#foo{bar = undefined}.\nok.\n" = + "#foo{bar = undefined}.\nok.\n" = t(<<"rd(foo,{bar}), rp(#foo{}).">>), - ?line [{foo,3,4,3},ok] = scan(<<"rd(foo,{a = 3, b}), rp({foo,3,4,3}).">>), - ?line "#foo{a = 12}.\nok.\n" = t(<<"rd(foo,{a = 3}), rp({foo,12}).">>), - ?line [{[{foo}],12},ok] = scan(<<"rd(foo,{a = 3}), rp({[{foo}],12}).">>), + [{foo,3,4,3},ok] = scan(<<"rd(foo,{a = 3, b}), rp({foo,3,4,3}).">>), + "#foo{a = 12}.\nok.\n" = t(<<"rd(foo,{a = 3}), rp({foo,12}).">>), + [{[{foo}],12},ok] = scan(<<"rd(foo,{a = 3}), rp({[{foo}],12}).">>), %% rr/1,2,3 MS = ?MODULE_STRING, RR1 = "rr(" ++ MS ++ "). #state{}.", - ?line "[state]\n" + "[state]\n" "#state{bin = undefined,reply = undefined,leader = undefined,\n" " unic = latin1}.\n" = t(RR1), RR2 = "rr(" ++ MS ++ ",[state]). #state{}.", - ?line "[state]\n" + "[state]\n" "#state{bin = undefined,reply = undefined,leader = undefined,\n" " unic = latin1}.\n" = t(RR2), RR3 = "rr(" ++ MS ++ ",'_'). #state{}.", - ?line "[state]\n" + "[state]\n" "#state{bin = undefined,reply = undefined,leader = undefined,\n" " unic = latin1}.\n" = t(RR3), RR4 = "rr(" ++ MS ++ ", '_', {d,test1}).", - ?line [[state]] = scan(RR4), + [[state]] = scan(RR4), - Test = filename:join(?config(priv_dir, Config), "test.erl"), + Test = filename:join(proplists:get_value(priv_dir, Config), "test.erl"), Contents = <<"-module(test). -record(state, {bin :: binary(), reply = no, @@ -404,7 +387,7 @@ records(Config) when is_list(Config) -> -ifdef(test2). -record(test2, {g}). -endif.">>, - ?line ok = file:write_file(Test, Contents), + ok = file:write_file(Test, Contents), RR5 = "rr(\"" ++ Test ++ "\", '_', {d,test1}), rl([test1,test2]).", A1 = erl_anno:new(1), @@ -415,164 +398,155 @@ records(Config) when is_list(Config) -> "\", '_', [{d,test1},{d,test2,17}]), rl([test1,test2]).", [{attribute,A1,record,{test1,_}},{attribute,A1,record,{test2,_}},ok] = scan(RR7), - ?line PreReply = scan(<<"rr(prim_file).">>), % preloaded... - ?line true = is_list(PreReply), - ?line Dir = filename:join(?config(priv_dir, Config), "*.erl"), - ?line RR8 = "rp(rr(\"" ++ Dir ++ "\")).", - ?line [_,ok] = scan(RR8), + PreReply = scan(<<"rr(prim_file).">>), % preloaded... + true = is_list(PreReply), + Dir = filename:join(proplists:get_value(priv_dir, Config), "*.erl"), + RR8 = "rp(rr(\"" ++ Dir ++ "\")).", + [_,ok] = scan(RR8), file:delete(Test), RR1000 = "begin rr(" ++ MS ++ ") end.", - ?line [_] = scan(RR1000), + [_] = scan(RR1000), RR1001 = "begin rr(" ++ MS ++ ", state) end.", - ?line [_] = scan(RR1001), + [_] = scan(RR1001), RR1002 = "begin rr(" ++ MS ++ ", state,{i,'.'}) end.", - ?line [_] = scan(RR1002), + [_] = scan(RR1002), - ?line [{error,nofile}] = scan(<<"rr(not_a_module).">>), - ?line [{error,invalid_filename}] = scan(<<"rr({foo}).">>), - ?line [[]] = scan(<<"rr(\"not_a_file\").">>), + [{error,nofile}] = scan(<<"rr(not_a_module).">>), + [{error,invalid_filename}] = scan(<<"rr({foo}).">>), + [[]] = scan(<<"rr(\"not_a_file\").">>), %% using records - ?line [2] = scan(<<"rd(foo,{bar}), record_info(size, foo).">>), - ?line [true] = scan(<<"rd(foo,{bar}), is_record(#foo{}, foo).">>), - ?line [true] = scan(<<"rd(foo,{bar}), erlang:is_record(#foo{}, foo).">>), - ?line [true] = scan(<<"rd(foo,{bar}), + [2] = scan(<<"rd(foo,{bar}), record_info(size, foo).">>), + [true] = scan(<<"rd(foo,{bar}), is_record(#foo{}, foo).">>), + [true] = scan(<<"rd(foo,{bar}), erlang:is_record(#foo{}, foo).">>), + [true] = scan(<<"rd(foo,{bar}), fun() when record(#foo{},foo) -> true end().">>), - ?line [2] = scan(<<"rd(foo,{bar}), #foo.bar.">>), - ?line "#foo{bar = 17}.\n" = + [2] = scan(<<"rd(foo,{bar}), #foo.bar.">>), + "#foo{bar = 17}.\n" = t(<<"rd(foo,{bar}), A = #foo{}, A#foo{bar = 17}.">>), %% test of is_record/2 in lc - ?line "[#foo{bar = 3}].\n" = + "[#foo{bar = 3}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "is_record(X, foo)].">>), - ?line "[x,[],{a,b}].\n" = + "[x,[],{a,b}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "not is_record(X, foo)].">>), - ?line "[#foo{bar = 3}].\n" = + "[#foo{bar = 3}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "begin is_record(X, foo) end].">>), - ?line "[x,[],{a,b}].\n" = + "[x,[],{a,b}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "begin not is_record(X, foo) end].">>), - ?line "[#foo{bar = 3},x,[],{a,b}].\n" = + "[#foo{bar = 3},x,[],{a,b}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "is_record(X, foo) or not is_binary(X)].">>), - ?line "[#foo{bar = 3},x,[],{a,b}].\n" = + "[#foo{bar = 3},x,[],{a,b}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "not is_record(X, foo) or not is_binary(X)].">>), - ?line "[#foo{bar = 3}].\n" = + "[#foo{bar = 3}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "is_record(X, foo) or is_reference(X)].">>), - ?line "[x,[],{a,b}].\n" = + "[x,[],{a,b}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "not is_record(X, foo) or is_reference(X)].">>), - ?line "[#foo{bar = 3},x,[],{a,b}].\n" = + "[#foo{bar = 3},x,[],{a,b}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "begin is_record(X, foo) or not is_binary(X) end].">>), - ?line "[#foo{bar = 3},x,[],{a,b}].\n" = + "[#foo{bar = 3},x,[],{a,b}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "begin not is_record(X, foo) or not is_binary(X) end].">>), - ?line "[#foo{bar = 3}].\n" = + "[#foo{bar = 3}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "begin is_record(X, foo) or is_reference(X) end].">>), - ?line "[x,[],{a,b}].\n" = + "[x,[],{a,b}].\n" = t(<<"rd(foo,{bar}), [X || X <- [#foo{bar=3},x,[],{a,b}]," "begin not is_record(X, foo) or is_reference(X) end].">>), - ?line [ok] = + [ok] = scan(<<"rd(a,{}), is_record({a},a) andalso true, b().">>), %% nested record defs - ?line "#b{a = #a{}}.\n" = t(<<"rd(a,{}), rd(b, {a = #a{}}), #b{}.">>), + "#b{a = #a{}}.\n" = t(<<"rd(a,{}), rd(b, {a = #a{}}), #b{}.">>), - ?line [ok,ok,ok] = scan(<<"rf('_'), rp(rp(rl(rf(rf(rf(rl())))))).">>), + [ok,ok,ok] = scan(<<"rf('_'), rp(rp(rl(rf(rf(rf(rl())))))).">>), ok. -known_bugs(doc) -> - ["Known bugs."]; -known_bugs(suite) -> - []; +%% Known bugs. known_bugs(Config) when is_list(Config) -> %% erl_eval:merge_bindings/2 cannot handle _removal_ of bindings. - ?line [3] = scan(<<"A = 3, length(begin f(A), [3] end), A.">>), + [3] = scan(<<"A = 3, length(begin f(A), [3] end), A.">>), ok. -otp_5226(doc) -> - ["OTP-5226. Wildcards accepted when reading BEAM files using rr/1,2,3."]; -otp_5226(suite) -> - []; +%% OTP-5226. Wildcards accepted when reading BEAM files using rr/1,2,3. otp_5226(Config) when is_list(Config) -> Test1 = <<"-module(test1). -record('_test1', {a,b}).">>, Test2 = <<"-module(test2). -record('_test2', {c,d}).">>, - ?line File1 = filename("test1.erl", Config), - ?line File2 = filename("test2.erl", Config), - ?line Beam = filename("*.beam", Config), - ?line ok = compile_file(Config, File1, Test1, [no_debug_info]), - ?line ok = compile_file(Config, File2, Test2, [no_debug_info]), - RR = "rr(\"" ++ Beam ++ "\").", - ?line [Recs] = scan(RR), - ?line true = lists:member('_test1', Recs), - ?line true = lists:member('_test2', Recs), - file:delete(filename("test1.beam", Config)), - file:delete(filename("test2.beam", Config)), - file:delete(File1), - file:delete(File2), - ok. - -otp_5327(doc) -> - ["OTP-5226. Test of eval_bits, mostly."]; -otp_5327(suite) -> - []; + File1 = filename("test1.erl", Config), + File2 = filename("test2.erl", Config), + Beam = filename("*.beam", Config), + ok = compile_file(Config, File1, Test1, [no_debug_info]), + ok = compile_file(Config, File2, Test2, [no_debug_info]), + RR = "rr(\"" ++ Beam ++ "\").", + [Recs] = scan(RR), + true = lists:member('_test1', Recs), + true = lists:member('_test2', Recs), + file:delete(filename("test1.beam", Config)), + file:delete(filename("test2.beam", Config)), + file:delete(File1), + file:delete(File2), + ok. + +%% OTP-5226. Test of eval_bits, mostly. otp_5327(Config) when is_list(Config) -> - ?line "exception error: bad argument" = + "exception error: bad argument" = comm_err(<<"<<\"hej\":default>>.">>), - ?line <<"abc">> = + <<"abc">> = erl_parse:normalise({bin,1,[{bin_element,1,{string,1,"abc"}, - default,default}]}), - ?line [<<"abc">>] = scan(<<"<<(<<\"abc\">>):3/binary>>.">>), - ?line [<<"abc">>] = scan(<<"<<(<<\"abc\">>)/binary>>.">>), - ?line "exception error: bad argument" = + default,default}]}), + [<<"abc">>] = scan(<<"<<(<<\"abc\">>):3/binary>>.">>), + [<<"abc">>] = scan(<<"<<(<<\"abc\">>)/binary>>.">>), + "exception error: bad argument" = comm_err(<<"<<(<<\"abc\">>):4/binary>>.">>), - ?line true = byte_size(hd(scan("<<3.14:64/float>>."))) =:= 8, - ?line true = byte_size(hd(scan("<<3.14:32/float>>."))) =:= 4, - ?line "exception error: bad argument" = + true = byte_size(hd(scan("<<3.14:64/float>>."))) =:= 8, + true = byte_size(hd(scan("<<3.14:32/float>>."))) =:= 4, + "exception error: bad argument" = comm_err(<<"<<3.14:128/float>>.">>), - ?line "exception error: bad argument" = + "exception error: bad argument" = comm_err(<<"<<10:default>>.">>), - ?line [<<98,1:1>>] = scan(<<"<<3:3,5:6>>.">>), - ?line {'EXIT',{badarg,_}} = + [<<98,1:1>>] = scan(<<"<<3:3,5:6>>.">>), + {'EXIT',{badarg,_}} = (catch erl_parse:normalise({bin,1,[{bin_element,1,{integer,1,17}, {atom,1,all}, default}]})), - ?line [<<-20/signed>>] = scan(<<"<<-20/signed>> = <<-20>>.">>), - ?line [<<-300:16/signed>>] = - scan(<<"<<-300:16/signed>> = <<-300:16>>.">>), - ?line [<<-1000:24/signed>>] = - scan(<<"<<-1000:24/signed>> = <<-1000:24>>.">>), - ?line [<<-(1 bsl 29):32/signed>>] = + [<<-20/signed>>] = scan(<<"<<-20/signed>> = <<-20>>.">>), + [<<-300:16/signed>>] = + scan(<<"<<-300:16/signed>> = <<-300:16>>.">>), + [<<-1000:24/signed>>] = + scan(<<"<<-1000:24/signed>> = <<-1000:24>>.">>), + [<<-(1 bsl 29):32/signed>>] = scan(<<"<<-(1 bsl 29):32/signed>> = <<-(1 bsl 29):32>>.">>), - ?line "exception error: no match of right hand side value <<0,0,0>>" = + "exception error: no match of right hand side value <<0,0,0>>" = comm_err(<<"<<B:3/unit:7-binary,_/binary>> = <<0:24>>.">>), - ?line true = [<<103133:64/float>>] =:= + true = [<<103133:64/float>>] =:= scan(<<"<<103133:64/float>> = <<103133:64/float>>.">>), - ?line true = [<<103133.0:64/float>>] =:= + true = [<<103133.0:64/float>>] =:= scan(<<"<<103133.0:64/float>> = <<103133:64/float>>.">>), - ?line true = [<<103133:64/float>>] =:= scan(<<"<<103133:64/float>>.">>), + true = [<<103133:64/float>>] =:= scan(<<"<<103133:64/float>>.">>), Int = 17, - ?line true = [<<Int:64/float>>] =:= scan(<<"Int = 17, <<Int:64/float>>.">>), - ?line "exception error: no match of right hand side value" ++ _ = + true = [<<Int:64/float>>] =:= scan(<<"Int = 17, <<Int:64/float>>.">>), + "exception error: no match of right hand side value" ++ _ = comm_err(<<"<<103133:64/binary>> = <<103133:64/float>>.">>), - ?line "exception error: interpreted function with arity 1 called with two arguments" = + "exception error: interpreted function with arity 1 called with two arguments" = comm_err(<<"(fun(X) -> X end)(a,b).">>), - ?line {'EXIT', {{illegal_pattern,_}, _}} = + {'EXIT', {{illegal_pattern,_}, _}} = (catch evaluate("<<A:a>> = <<17:32>>.", [])), C = <<" <<A:4,B:4,C:4,D:4,E:4,F:4>> = <<\"hej\">>, @@ -581,60 +555,54 @@ otp_5327(Config) when is_list(Config) -> _ -> 2 end. ">>, - ?line 1 = evaluate(C, []), + 1 = evaluate(C, []), %% unbound_var would be nicer... - ?line {'EXIT',{{illegal_pattern,_},_}} = + {'EXIT',{{illegal_pattern,_},_}} = (catch evaluate(<<"<<A:B>> = <<17:32>>.">>, [])), %% undefined_bittype is turned into badmatch: - ?line {'EXIT',{{badmatch,<<17:32>>},_}} = + {'EXIT',{{badmatch,<<17:32>>},_}} = (catch evaluate(<<"<<A/apa>> = <<17:32>>.">>, [])), - ?line {'EXIT',_} = + {'EXIT',_} = (catch evaluate(<<"<<17/binary-unit:8-unit:16>>.">>, [])), - ?line {'EXIT',_} = + {'EXIT',_} = (catch evaluate(<<"<<17:32/unsigned-signed>> = <<17:32>>.">>, [])), - ?line {'EXIT',_} = + {'EXIT',_} = (catch evaluate(<<"<<17:32/unsigned-signed>>.">>, [])), - ?line <<17:32>> = evaluate(<<"<<17:32/signed-signed>>.">>, []), - ?line {'EXIT',_} = + <<17:32>> = evaluate(<<"<<17:32/signed-signed>>.">>, []), + {'EXIT',_} = (catch evaluate(<<"<<32/unit:8>>.">>, [])), ok. -otp_5435(doc) -> - ["OTP-5435. sys_pre_expand not in the path."]; -otp_5435(suite) -> - []; +%% OTP-5435. sys_pre_expand not in the path. otp_5435(Config) when is_list(Config) -> - ?line true = <<103133:64/float>> =:= + true = <<103133:64/float>> =:= evaluate(<<"<<103133:64/float>> = <<103133:64/float>>.">>, []), - ?line true = <<103133.0:64/float>> =:= + true = <<103133.0:64/float>> =:= evaluate(<<"<<103133.0:64/float>> = <<103133:64/float>>.">>, []), - ?line true = is_alive(), - ?line {ok, Node} = start_node(shell_SUITE_otp_5435), - ?line ok = rpc:call(Node, ?MODULE, otp_5435_2, []), - ?line ?t:stop_node(Node), + true = is_alive(), + {ok, Node} = start_node(shell_SUITE_otp_5435), + ok = rpc:call(Node, ?MODULE, otp_5435_2, []), + test_server:stop_node(Node), ok. - + start_node(Name) -> - ?line PA = filename:dirname(code:which(?MODULE)), - ?t:start_node(Name, slave, [{args, "-pa " ++ PA}]). + PA = filename:dirname(code:which(?MODULE)), + test_server:start_node(Name, slave, [{args, "-pa " ++ PA}]). otp_5435_2() -> - ?line true = code:del_path(compiler), + true = code:del_path(compiler), %% sys_pre_expand can no longer be found %% OTP-5876. But erl_expand_records can! - ?line [{attribute,_,record,{bar,_}},ok] = + [{attribute,_,record,{bar,_}},ok] = scan(<<"rd(foo,{bar}), rd(bar,{foo = (#foo{})#foo.bar}), - rl(bar).">>), + rl(bar).">>), ok. -otp_5195(doc) -> - ["OTP-5195. QLC, mostly."]; -otp_5195(suite) -> - []; +%% OTP-5195. QLC, mostly. otp_5195(Config) when is_list(Config) -> %% QLC. It was easier to put these cases here than in qlc_SUITE. - ?line "[#a{b = undefined}].\n" = + "[#a{b = undefined}].\n" = t(<<"rd(a,{b}), qlc:e(qlc:q([X || X <- [#a{}],is_record(X, a)])).">>), %% An experimental shell used to translate error tuples: @@ -642,570 +610,556 @@ otp_5195(Config) when is_list(Config) -> %% "list expression\".\n" = %% t(<<"qlc:q([X || X <- [{a}], Y <- [X]]).">>), %% Same as last one (if the shell does not translate error tuples): - ?line [{error,qlc,{1,qlc,{used_generator_variable,'X'}}}] = + [{error,qlc,{1,qlc,{used_generator_variable,'X'}}}] = scan(<<"qlc:q([X || X <- [{a}], Y <- [X]]).">>), - ?line {error,qlc,{1,qlc,{used_generator_variable,'X'}}} = + {error,qlc,{1,qlc,{used_generator_variable,'X'}}} = evaluate(<<"qlc:q([X || X <- [{a}], Y <- [X]]).">>, []), Ugly = <<"qlc:e(qlc:q([X || X <- qlc:append([[1,2,3],ugly()])])).">>, - ?line "undefined shell command ugly/0" = error_string(Ugly), - ?line {'EXIT',{undef,_}} = (catch evaluate(Ugly, [])), + "undefined shell command ugly/0" = error_string(Ugly), + {'EXIT',{undef,_}} = (catch evaluate(Ugly, [])), V_1 = <<"qlc:e(qlc:q([X || X <- qlc:append([[1,2,3],v(-1)])])).">>, - ?line "- 1: command not found" = comm_err(V_1), - ?line {'EXIT', {undef,_}} = (catch evaluate(V_1, [])), + "- 1: command not found" = comm_err(V_1), + {'EXIT', {undef,_}} = (catch evaluate(V_1, [])), - ?line "1\n2\n3\n3.\n" = + "1\n2\n3\n3.\n" = t(<<"1. 2. 3. 3 = fun(A) when A =:= 2 -> v(3) end(v(2)).">>), - ?line List4 = t(<<"[a,list]. A = [1,2]. " - "qlc:q([X || X <- qlc:append(A, v(1))]). " - "[1,2,a,list] = qlc:e(v(-1)).">>), - ?line "[1,2,a,list].\n" = string:substr(List4, string:len(List4)-13), + List4 = t(<<"[a,list]. A = [1,2]. " + "qlc:q([X || X <- qlc:append(A, v(1))]). " + "[1,2,a,list] = qlc:e(v(-1)).">>), + "[1,2,a,list].\n" = string:substr(List4, string:len(List4)-13), ok. -otp_5915(doc) -> - ["OTP-5915. Strict record tests in guards."]; -otp_5915(suite) -> - []; +%% OTP-5915. Strict record tests in guards. otp_5915(Config) when is_list(Config) -> C = <<" rd(r, {a = 4,b}), - rd(r1, {a,b}), - rd(r2, {a = #r1{},b,c=length([1,2,3])}), - rd(r3, {a = fun(_) -> #r1{} end(1), b}), - - foo = fun(A) when A#r1.a > A#r1.b -> foo end(#r1{b = 2}), - 0 = fun(A) when A#r2.a -> 0 end(#r2{a = true}), - 1 = fun(A) when (#r1{a = A})#r1.a > 2 -> 1 end(3), - 2 = fun(N) when ((#r2{a = #r{a = 4}, b = length([a,b,c])})#r2.a)#r.a > N -> - 2 end(2), - 3 = fun(A) when (A#r2.a)#r1.a =:= 3 -> 3 end(#r2{a = #r1{a = 3}}), - ok = fun() -> - F = fun(A) when record(A#r.a, r1) -> 4; - (A) when record(A#r1.a, r1) -> 5 - end, - 5 = F(#r1{a = #r1{}}), - 4 = F(#r{a = #r1{}}), - ok - end(), - 3 = fun(A) when record(A#r1.a, r), - (A#r1.a)#r.a > 3 -> 3 - end(#r1{a = #r{a = 4}}), - 7 = fun(A) when record(A#r3.a, r1) -> 7 end(#r3{}), - [#r1{a = 2,b = 1}] = - fun() -> - [A || A <- [#r1{a = 1, b = 3}, - #r2{a = 2,b = 1}, - #r1{a = 2, b = 1}], - A#r1.a > - A#r1.b] - end(), - {[_],b} = - fun(L) -> + rd(r1, {a,b}), + rd(r2, {a = #r1{},b,c=length([1,2,3])}), + rd(r3, {a = fun(_) -> #r1{} end(1), b}), + + foo = fun(A) when A#r1.a > A#r1.b -> foo end(#r1{b = 2}), + 0 = fun(A) when A#r2.a -> 0 end(#r2{a = true}), + 1 = fun(A) when (#r1{a = A})#r1.a > 2 -> 1 end(3), + 2 = fun(N) when ((#r2{a = #r{a = 4}, b = length([a,b,c])})#r2.a)#r.a > N -> + 2 end(2), + 3 = fun(A) when (A#r2.a)#r1.a =:= 3 -> 3 end(#r2{a = #r1{a = 3}}), + ok = fun() -> + F = fun(A) when record(A#r.a, r1) -> 4; + (A) when record(A#r1.a, r1) -> 5 + end, + 5 = F(#r1{a = #r1{}}), + 4 = F(#r{a = #r1{}}), + ok + end(), + 3 = fun(A) when record(A#r1.a, r), + (A#r1.a)#r.a > 3 -> 3 + end(#r1{a = #r{a = 4}}), + 7 = fun(A) when record(A#r3.a, r1) -> 7 end(#r3{}), + [#r1{a = 2,b = 1}] = + fun() -> + [A || A <- [#r1{a = 1, b = 3}, + #r2{a = 2,b = 1}, + #r1{a = 2, b = 1}], + A#r1.a > + A#r1.b] + end(), + {[_],b} = + fun(L) -> %% A is checked only once: - R1 = [{A,B} || A <- L, A#r1.a, B <- L, A#r1.b], - A = #r2{a = true}, + R1 = [{A,B} || A <- L, A#r1.a, B <- L, A#r1.b], + A = #r2{a = true}, %% A is checked again: - B = if A#r1.a -> a; true -> b end, - {R1,B} - end([#r1{a = true, b = true}]), - - p = fun(A) when (A#r1.a =:= 2) or (A#r2.a =:= 1) -> o; - (_) -> p - end(#r1{a = 2}), - - o = fun(A) when (A#r1.a =:= 2) orelse (A#r2.a =:= 1) -> o; - (_) -> p - end(#r1{a = 2}), - - 3 = fun(A) when A#r1.a > 3, - record(A, r1) -> 3 - end(#r1{a = 5}), - - ok = fun() -> - F = fun(A) when (A#r2.a =:= 1) orelse (A#r2.a) -> 2; - (A) when (A#r1.a =:= 1) orelse (A#r1.a) -> 1; - (A) when (A#r2.a =:= 2) andalso (A#r2.b) -> 3 - end, - 1 = F(#r1{a = 1}), - 2 = F(#r2{a = true}), - 3 = F(#r2{a = 2, b = true}), - ok - end(), - - b = fun(A) when false or not (A#r.a =:= 1) -> a; - (_) -> b - end(#r1{a = 1}), - b = fun(A) when not (A#r.a =:= 1) or false -> a; - (_) -> b - end(#r1{a = 1}), - - ok = fun() -> - F = fun(A) when not (A#r.a =:= 1) -> yes; - (_) -> no - end, - no = F(#r1{a = 2}), - yes = F(#r{a = 2}), - no = F(#r{a = 1}), - ok - end(), - - a = fun(A) when record(A, r), - A#r.a =:= 1, - A#r.b =:= 2 ->a - end(#r{a = 1, b = 2}), - a = fun(A) when erlang:is_record(A, r), - A#r.a =:= 1, - A#r.b =:= 2 -> a - end(#r{a = 1, b = 2}), - a = fun(A) when is_record(A, r), - A#r.a =:= 1, - A#r.b =:= 2 -> a - end(#r{a = 1, b = 2}), - - nop = fun(A) when (is_record(A, r1) and (A#r1.a > 3)) or (A#r2.a < 1) -> - japp; - (_) -> - nop - end(#r2{a = 0}), - nop = fun(A) when (A#r1.a > 3) or (A#r2.a < 1) -> japp; - (_) -> - nop - end(#r2{a = 0}), - - ok = fun() -> - F = fun(A) when (A#r1.a =:= 2) or (A#r2.a =:= 1) -> o; - (_) -> p - end, - p = F(#r2{a = 1}), - p = F(#r1{a = 2}), - ok - end(), - - ok = fun() -> - F = fun(A) when fail, A#r1.a; A#r1.a -> ab; - (_) -> bu - end, - ab = F(#r1{a = true}), - bu = F(#r2{a = true}), - ok - end(), - - both = fun(A) when A#r.a, A#r.b -> both - end(#r{a = true, b = true}), - - ok = fun() -> - F = fun(A, B) when ((A#r1.a) orelse (B#r2.a)) - or (B#r2.b) or (A#r1.b) -> true; - (_, _) -> false - end, - true = F(#r1{a = false, b = false}, #r2{a = false, b = true}), - false = F(#r1{a = true, b = true}, #r1{a = false, b = true}), - ok - end(), - - ok.">>, + B = if A#r1.a -> a; true -> b end, + {R1,B} + end([#r1{a = true, b = true}]), + + p = fun(A) when (A#r1.a =:= 2) or (A#r2.a =:= 1) -> o; + (_) -> p + end(#r1{a = 2}), + + o = fun(A) when (A#r1.a =:= 2) orelse (A#r2.a =:= 1) -> o; + (_) -> p + end(#r1{a = 2}), + + 3 = fun(A) when A#r1.a > 3, + record(A, r1) -> 3 + end(#r1{a = 5}), + + ok = fun() -> + F = fun(A) when (A#r2.a =:= 1) orelse (A#r2.a) -> 2; + (A) when (A#r1.a =:= 1) orelse (A#r1.a) -> 1; + (A) when (A#r2.a =:= 2) andalso (A#r2.b) -> 3 + end, + 1 = F(#r1{a = 1}), + 2 = F(#r2{a = true}), + 3 = F(#r2{a = 2, b = true}), + ok + end(), + + b = fun(A) when false or not (A#r.a =:= 1) -> a; + (_) -> b + end(#r1{a = 1}), + b = fun(A) when not (A#r.a =:= 1) or false -> a; + (_) -> b + end(#r1{a = 1}), + + ok = fun() -> + F = fun(A) when not (A#r.a =:= 1) -> yes; + (_) -> no + end, + no = F(#r1{a = 2}), + yes = F(#r{a = 2}), + no = F(#r{a = 1}), + ok + end(), + + a = fun(A) when record(A, r), + A#r.a =:= 1, + A#r.b =:= 2 ->a + end(#r{a = 1, b = 2}), + a = fun(A) when erlang:is_record(A, r), + A#r.a =:= 1, + A#r.b =:= 2 -> a + end(#r{a = 1, b = 2}), + a = fun(A) when is_record(A, r), + A#r.a =:= 1, + A#r.b =:= 2 -> a + end(#r{a = 1, b = 2}), + + nop = fun(A) when (is_record(A, r1) and (A#r1.a > 3)) or (A#r2.a < 1) -> + japp; + (_) -> + nop + end(#r2{a = 0}), + nop = fun(A) when (A#r1.a > 3) or (A#r2.a < 1) -> japp; + (_) -> + nop + end(#r2{a = 0}), + + ok = fun() -> + F = fun(A) when (A#r1.a =:= 2) or (A#r2.a =:= 1) -> o; + (_) -> p + end, + p = F(#r2{a = 1}), + p = F(#r1{a = 2}), + ok + end(), + + ok = fun() -> + F = fun(A) when fail, A#r1.a; A#r1.a -> ab; + (_) -> bu + end, + ab = F(#r1{a = true}), + bu = F(#r2{a = true}), + ok + end(), + + both = fun(A) when A#r.a, A#r.b -> both + end(#r{a = true, b = true}), + + ok = fun() -> + F = fun(A, B) when ((A#r1.a) orelse (B#r2.a)) + or (B#r2.b) or (A#r1.b) -> true; + (_, _) -> false + end, + true = F(#r1{a = false, b = false}, #r2{a = false, b = true}), + false = F(#r1{a = true, b = true}, #r1{a = false, b = true}), + ok + end(), + + ok.">>, [ok] = scan(C), - ok. + ok. -otp_5916(doc) -> - ["OTP-5916. erlang:is_record/3 allowed in guards."]; -otp_5916(suite) -> - []; +%% OTP-5916. erlang:is_record/3 allowed in guards. otp_5916(Config) when is_list(Config) -> C = <<" rd(r1, {a,b}), - rd(r2, {a,b}), + rd(r2, {a,b}), - true = if erlang:is_record(#r1{},r1,3) -> true; true -> false end, - false = if erlang:is_record(#r2{},r1,3) -> true; true -> false end, + true = if erlang:is_record(#r1{},r1,3) -> true; true -> false end, + false = if erlang:is_record(#r2{},r1,3) -> true; true -> false end, - true = if is_record(#r1{},r1,3) -> true; true -> false end, - false = if is_record(#r2{},r1,3) -> true; true -> false end, + true = if is_record(#r1{},r1,3) -> true; true -> false end, + false = if is_record(#r2{},r1,3) -> true; true -> false end, - ok.">>, + ok.">>, [ok] = scan(C), - ok. + ok. -bs_match_misc_SUITE(doc) -> - ["OTP-5327. Adopted from parts of emulator/test/bs_match_misc_SUITE.erl."]; -bs_match_misc_SUITE(suite) -> - []; +%% OTP-5327. Adopted from parts of emulator/test/bs_match_misc_SUITE.erl. bs_match_misc_SUITE(Config) when is_list(Config) -> C = <<" F1 = fun() -> 3.1415 end, - FOne = fun() -> 1.0 end, - - Fcmp = fun(F1, F2) when (F1 - F2) / F2 < 0.0000001 -> ok end, - - MakeSubBin = fun(Bin0) -> - Sz = size(Bin0), - Bin1 = <<37,Bin0/binary,38,39>>, - <<_:8,Bin:Sz/binary,_:8,_:8>> = Bin1, - Bin - end, - - MatchFloat = - fun(Bin0, Fsz, I) -> - Bin = MakeSubBin(Bin0), - Bsz = size(Bin) * 8, - Tsz = Bsz - Fsz - I, - <<_:I,F:Fsz/float,_:Tsz>> = Bin, - F - end, - - TFloat = fun() -> - F = F1(), - G = FOne(), - - G = MatchFloat(<<63,128,0,0>>, 32, 0), - G = MatchFloat(<<63,240,0,0,0,0,0,0>>, 64, 0), - - Fcmp(F, MatchFloat(<<F:32/float>>, 32, 0)), - Fcmp(F, MatchFloat(<<F:64/float>>, 64, 0)), - Fcmp(F, MatchFloat(<<1:1,F:32/float,127:7>>, 32, 1)), - Fcmp(F, MatchFloat(<<1:1,F:64/float,127:7>>, 64, 1)), - Fcmp(F, MatchFloat(<<1:13,F:32/float,127:3>>, 32, 13)), - Fcmp(F, MatchFloat(<<1:13,F:64/float,127:3>>, 64, 13)) - end, - TFloat(), - - F2 = fun() -> 2.7133 end, - - MatchFloatLittle = fun(Bin0, Fsz, I) -> - Bin = MakeSubBin(Bin0), - Bsz = size(Bin) * 8, - Tsz = Bsz - Fsz - I, - <<_:I,F:Fsz/float-little,_:Tsz>> = Bin, - F - end, - - LittleFloat = fun() -> - F = F2(), - G = FOne(), - - G = MatchFloatLittle(<<0,0,0,0,0,0,240,63>>, 64, 0), - G = MatchFloatLittle(<<0,0,128,63>>, 32, 0), - - Fcmp(F, MatchFloatLittle(<<F:32/float-little>>, 32, 0)), - Fcmp(F, MatchFloatLittle(<<F:64/float-little>>, 64, 0)), - Fcmp(F, MatchFloatLittle(<<1:1,F:32/float-little,127:7>>, 32, 1)), - Fcmp(F, MatchFloatLittle(<<1:1,F:64/float-little,127:7>>, 64, 1)), - Fcmp(F, MatchFloatLittle(<<1:13,F:32/float-little,127:3>>, 32, 13)), - Fcmp(F, MatchFloatLittle(<<1:13,F:64/float-little,127:3>>, 64, 13)) - end, - LittleFloat(), - - Sean1 = fun(<<B/binary>>) when size(B) < 4 -> small; - (<<1, _B/binary>>) -> large - end, - - Sean = fun() -> - small = Sean1(<<>>), - small = Sean1(<<1>>), - small = Sean1(<<1,2>>), - small = Sean1(<<1,2,3>>), - large = Sean1(<<1,2,3,4>>), - - small = Sean1(<<4>>), - small = Sean1(<<4,5>>), - small = Sean1(<<4,5,6>>), - {'EXIT',{function_clause,_}} = (catch Sean1(<<4,5,6,7>>)) - end, - Sean(), - - NativeBig = fun() -> - <<37.33:64/native-float>> = <<37.33:64/big-float>>, - <<3974:16/native-integer>> = <<3974:16/big-integer>> - end, - - NativeLittle = fun() -> - <<37869.32343:64/native-float>> = <<37869.32343:64/little-float>>, - <<7974:16/native-integer>> = <<7974:16/little-integer>> - end, - - Native = fun() -> - <<3.14:64/native-float>> = <<3.14:64/native-float>>, - <<333:16/native>> = <<333:16/native>>, - <<38658345:32/native>> = <<38658345:32/native>>, - case <<1:16/native>> of - <<0,1>> -> NativeBig(); - <<1,0>> -> NativeLittle() - end - end, - Native(), - - Split = fun(<<N:16,B:N/binary,T/binary>>) -> {B,T} end, - - Split2 = fun(N, <<N:16,B:N/binary,T/binary>>) -> {B,T} end, - - Split_2 = fun(<<N0:8,N:N0,B:N/binary,T/binary>>) -> {B,T} end, - - Skip = fun(<<N:8,_:N/binary,T/binary>>) -> T end, - - SizeVar = fun() -> - {<<45>>,<<>>} = Split(<<1:16,45>>), - {<<45>>,<<46,47>>} = Split(<<1:16,45,46,47>>), - {<<45,46>>,<<47>>} = Split(<<2:16,45,46,47>>), - - {<<45,46,47>>,<<48>>} = Split_2(<<16:8,3:16,45,46,47,48>>), - - {<<45,46>>,<<47>>} = Split2(2, <<2:16,45,46,47>>), - {'EXIT',{function_clause,_}} = - (catch Split2(42, <<2:16,45,46,47>>)), - - <<\"cdef\">> = Skip(<<2:8,\"abcdef\">>) + FOne = fun() -> 1.0 end, + + Fcmp = fun(F1, F2) when (F1 - F2) / F2 < 0.0000001 -> ok end, + + MakeSubBin = fun(Bin0) -> + Sz = size(Bin0), + Bin1 = <<37,Bin0/binary,38,39>>, + <<_:8,Bin:Sz/binary,_:8,_:8>> = Bin1, + Bin + end, + + MatchFloat = + fun(Bin0, Fsz, I) -> + Bin = MakeSubBin(Bin0), + Bsz = size(Bin) * 8, + Tsz = Bsz - Fsz - I, + <<_:I,F:Fsz/float,_:Tsz>> = Bin, + F + end, + + TFloat = fun() -> + F = F1(), + G = FOne(), + + G = MatchFloat(<<63,128,0,0>>, 32, 0), + G = MatchFloat(<<63,240,0,0,0,0,0,0>>, 64, 0), + + Fcmp(F, MatchFloat(<<F:32/float>>, 32, 0)), + Fcmp(F, MatchFloat(<<F:64/float>>, 64, 0)), + Fcmp(F, MatchFloat(<<1:1,F:32/float,127:7>>, 32, 1)), + Fcmp(F, MatchFloat(<<1:1,F:64/float,127:7>>, 64, 1)), + Fcmp(F, MatchFloat(<<1:13,F:32/float,127:3>>, 32, 13)), + Fcmp(F, MatchFloat(<<1:13,F:64/float,127:3>>, 64, 13)) + end, + TFloat(), + + F2 = fun() -> 2.7133 end, + + MatchFloatLittle = fun(Bin0, Fsz, I) -> + Bin = MakeSubBin(Bin0), + Bsz = size(Bin) * 8, + Tsz = Bsz - Fsz - I, + <<_:I,F:Fsz/float-little,_:Tsz>> = Bin, + F + end, + + LittleFloat = fun() -> + F = F2(), + G = FOne(), + + G = MatchFloatLittle(<<0,0,0,0,0,0,240,63>>, 64, 0), + G = MatchFloatLittle(<<0,0,128,63>>, 32, 0), + + Fcmp(F, MatchFloatLittle(<<F:32/float-little>>, 32, 0)), + Fcmp(F, MatchFloatLittle(<<F:64/float-little>>, 64, 0)), + Fcmp(F, MatchFloatLittle(<<1:1,F:32/float-little,127:7>>, 32, 1)), + Fcmp(F, MatchFloatLittle(<<1:1,F:64/float-little,127:7>>, 64, 1)), + Fcmp(F, MatchFloatLittle(<<1:13,F:32/float-little,127:3>>, 32, 13)), + Fcmp(F, MatchFloatLittle(<<1:13,F:64/float-little,127:3>>, 64, 13)) + end, + LittleFloat(), + + Sean1 = fun(<<B/binary>>) when size(B) < 4 -> small; + (<<1, _B/binary>>) -> large + end, + + Sean = fun() -> + small = Sean1(<<>>), + small = Sean1(<<1>>), + small = Sean1(<<1,2>>), + small = Sean1(<<1,2,3>>), + large = Sean1(<<1,2,3,4>>), + + small = Sean1(<<4>>), + small = Sean1(<<4,5>>), + small = Sean1(<<4,5,6>>), + {'EXIT',{function_clause,_}} = (catch Sean1(<<4,5,6,7>>)) + end, + Sean(), + + NativeBig = fun() -> + <<37.33:64/native-float>> = <<37.33:64/big-float>>, + <<3974:16/native-integer>> = <<3974:16/big-integer>> + end, + + NativeLittle = fun() -> + <<37869.32343:64/native-float>> = <<37869.32343:64/little-float>>, + <<7974:16/native-integer>> = <<7974:16/little-integer>> + end, + + Native = fun() -> + <<3.14:64/native-float>> = <<3.14:64/native-float>>, + <<333:16/native>> = <<333:16/native>>, + <<38658345:32/native>> = <<38658345:32/native>>, + case <<1:16/native>> of + <<0,1>> -> NativeBig(); + <<1,0>> -> NativeLittle() + end + end, + Native(), + + Split = fun(<<N:16,B:N/binary,T/binary>>) -> {B,T} end, + + Split2 = fun(N, <<N:16,B:N/binary,T/binary>>) -> {B,T} end, + + Split_2 = fun(<<N0:8,N:N0,B:N/binary,T/binary>>) -> {B,T} end, + + Skip = fun(<<N:8,_:N/binary,T/binary>>) -> T end, + + SizeVar = fun() -> + {<<45>>,<<>>} = Split(<<1:16,45>>), + {<<45>>,<<46,47>>} = Split(<<1:16,45,46,47>>), + {<<45,46>>,<<47>>} = Split(<<2:16,45,46,47>>), + + {<<45,46,47>>,<<48>>} = Split_2(<<16:8,3:16,45,46,47,48>>), + + {<<45,46>>,<<47>>} = Split2(2, <<2:16,45,46,47>>), + {'EXIT',{function_clause,_}} = + (catch Split2(42, <<2:16,45,46,47>>)), + + <<\"cdef\">> = Skip(<<2:8,\"abcdef\">>) end, - SizeVar(), - - Wcheck = fun(<<A>>) when A==3-> ok1; - (<<_,_:2/binary>>) -> ok2; - (<<_>>) -> ok3; - (Other) -> {error,Other} - end, - - Wiger = fun() -> - ok1 = Wcheck(<<3>>), - ok2 = Wcheck(<<1,2,3>>), - ok3 = Wcheck(<<4>>), - {error,<<1,2,3,4>>} = Wcheck(<<1,2,3,4>>), - {error,<<>>} = Wcheck(<<>>) - end, - Wiger(), - - ok. - ">>, + SizeVar(), + + Wcheck = fun(<<A>>) when A==3-> ok1; + (<<_,_:2/binary>>) -> ok2; + (<<_>>) -> ok3; + (Other) -> {error,Other} + end, + + Wiger = fun() -> + ok1 = Wcheck(<<3>>), + ok2 = Wcheck(<<1,2,3>>), + ok3 = Wcheck(<<4>>), + {error,<<1,2,3,4>>} = Wcheck(<<1,2,3,4>>), + {error,<<>>} = Wcheck(<<>>) + end, + Wiger(), + + ok. +">>, [ok] = scan(C), - ok = evaluate(C, []). +ok = evaluate(C, []). %% This one is not run during night builds since it takes several minutes. -bs_match_int_SUITE(doc) -> - ["OTP-5327. Adopted from emulator/test/bs_match_int_SUITE.erl."]; -bs_match_int_SUITE(suite) -> - []; + +%% OTP-5327. Adopted from emulator/test/bs_match_int_SUITE.erl. bs_match_int_SUITE(Config) when is_list(Config) -> C = <<" FunClause = fun({'EXIT',{function_clause,_}}) -> ok end, - Mkbin = fun(L) when list(L) -> list_to_binary(L) end, - - GetInt1 = fun(<<I:0>>) -> I; - (<<I:8>>) -> I; - (<<I:16>>) -> I; - (<<I:24>>) -> I; - (<<I:32>>) -> I - end, - - GetInt2 = fun(Bin0, I, F) when size(Bin0) < 4 -> - Bin = <<0,Bin0/binary>>, - I = GetInt1(Bin), - F(Bin, I, F); - (_, I, _F) -> I - end, - - GetInt = fun(Bin) -> - I = GetInt1(Bin), - GetInt2(Bin, I, GetInt2) - end, - - - Cmp128 = fun(<<I:128>>, I) -> equal; - (_, _) -> not_equal - end, - - Uint2 = fun([H|T], Acc, F) -> F(T, Acc bsl 8 bor H, F); - ([], Acc, _F) -> Acc - end, - - Uint = fun(L) -> Uint2(L, 0, Uint2) end, - - Integer = fun() -> - 0 = GetInt(Mkbin([])), - 0 = GetInt(Mkbin([0])), - 42 = GetInt(Mkbin([42])), - 255 = GetInt(Mkbin([255])), - 256 = GetInt(Mkbin([1,0])), - 257 = GetInt(Mkbin([1,1])), - 258 = GetInt(Mkbin([1,2])), - 258 = GetInt(Mkbin([1,2])), - 65534 = GetInt(Mkbin([255,254])), - 16776455 = GetInt(Mkbin([255,253,7])), - 4245492555 = GetInt(Mkbin([253,13,19,75])), - 4294967294 = GetInt(Mkbin([255,255,255,254])), - 4294967295 = GetInt(Mkbin([255,255,255,255])), - Eight = [200,1,19,128,222,42,97,111], - Cmp128(Eight, Uint(Eight)), - FunClause(catch GetInt(Mkbin(lists:seq(1,5)))) - end, - Integer(), - - Sint = fun(Bin) -> - case Bin of - <<I:8/signed>> -> I; - <<I:8/signed,_:3,_:5>> -> I; - Other -> {no_match,Other} - end - end, - - SignedInteger = fun() -> - {no_match,_} = Sint(Mkbin([])), - {no_match,_} = Sint(Mkbin([1,2,3])), - 127 = Sint(Mkbin([127])), - -1 = Sint(Mkbin([255])), - -128 = Sint(Mkbin([128])), - 42 = Sint(Mkbin([42,255])), - 127 = Sint(Mkbin([127,255])) - end, - SignedInteger(), - - Dynamic5 = fun(Bin, S1, S2, A, B) -> - case Bin of - <<A:S1,B:S2>> -> - % io:format(\"~p ~p ~p ~p~n\", [S1,S2,A,B]), - ok; - _Other -> erlang:error(badmatch, [Bin,S1,S2,A,B]) - end - end, - - Dynamic2 = fun(Bin, S1, F) when S1 >= 0 -> - S2 = size(Bin) * 8 - S1, - Dynamic5(Bin, S1, S2, (1 bsl S1) - 1, (1 bsl S2) - 1), - F(Bin, S1-1, F); - (_, _, _) -> ok - end, - - Dynamic = fun(Bin, S1) -> - Dynamic2(Bin, S1, Dynamic2) - end, - - Dynamic(Mkbin([255]), 8), - Dynamic(Mkbin([255,255]), 16), - Dynamic(Mkbin([255,255,255]), 24), - Dynamic(Mkbin([255,255,255,255]), 32), - - BigToLittle4 = - fun([B0,B1,B2,B3,B4,B5,B6,B7|T], N, Acc, F) when N >= 8 -> - F(T, N-8, [B0,B1,B2,B3,B4,B5,B6,B7|Acc], F); - (List, N, Acc, _F) -> lists:sublist(List, 1, N) ++ Acc - end, - - BigToLittle = - fun(List, N) -> BigToLittle4(List, N, [], BigToLittle4) end, - - ReversedSublist = - fun(_List, 0, Acc, _F) -> Acc; - ([H|T], N, Acc, F) -> F(T, N-1, [H|Acc], F) - end, - - TwoComplementAndReverse = - fun([H|T], Carry, Acc, F) -> - Sum = 1-H+Carry, - F(T, Sum div 2, [Sum rem 2|Acc], F); - ([], Carry, Acc, _F) -> [Carry|Acc] - end, - - MakeInt = fun(_List, 0, Acc, _F) -> Acc; - ([H|T], N, Acc, F) -> F(T, N-1, Acc bsl 1 bor H, F) - end, - - MakeSignedInt = - fun(_List, 0) -> 0; - ([0|_]=List, N) -> MakeInt(List, N, 0, MakeInt); - ([1|_]=List0, N) -> - List1 = ReversedSublist(List0, N, [], ReversedSublist), - List2 = TwoComplementAndReverse(List1, 1, [], - TwoComplementAndReverse), - -MakeInt(List2, length(List2), 0, MakeInt) - end, - - BitsToList = - fun([H|T], 0, F) -> F(T, 16#80, F); - ([H|_]=List, Mask, F) -> - [case H band Mask of + Mkbin = fun(L) when list(L) -> list_to_binary(L) end, + + GetInt1 = fun(<<I:0>>) -> I; + (<<I:8>>) -> I; + (<<I:16>>) -> I; + (<<I:24>>) -> I; + (<<I:32>>) -> I + end, + + GetInt2 = fun(Bin0, I, F) when size(Bin0) < 4 -> + Bin = <<0,Bin0/binary>>, + I = GetInt1(Bin), + F(Bin, I, F); + (_, I, _F) -> I + end, + + GetInt = fun(Bin) -> + I = GetInt1(Bin), + GetInt2(Bin, I, GetInt2) + end, + + + Cmp128 = fun(<<I:128>>, I) -> equal; + (_, _) -> not_equal + end, + + Uint2 = fun([H|T], Acc, F) -> F(T, Acc bsl 8 bor H, F); + ([], Acc, _F) -> Acc + end, + + Uint = fun(L) -> Uint2(L, 0, Uint2) end, + + Integer = fun() -> + 0 = GetInt(Mkbin([])), + 0 = GetInt(Mkbin([0])), + 42 = GetInt(Mkbin([42])), + 255 = GetInt(Mkbin([255])), + 256 = GetInt(Mkbin([1,0])), + 257 = GetInt(Mkbin([1,1])), + 258 = GetInt(Mkbin([1,2])), + 258 = GetInt(Mkbin([1,2])), + 65534 = GetInt(Mkbin([255,254])), + 16776455 = GetInt(Mkbin([255,253,7])), + 4245492555 = GetInt(Mkbin([253,13,19,75])), + 4294967294 = GetInt(Mkbin([255,255,255,254])), + 4294967295 = GetInt(Mkbin([255,255,255,255])), + Eight = [200,1,19,128,222,42,97,111], + Cmp128(Eight, Uint(Eight)), + FunClause(catch GetInt(Mkbin(lists:seq(1,5)))) + end, + Integer(), + + Sint = fun(Bin) -> + case Bin of + <<I:8/signed>> -> I; + <<I:8/signed,_:3,_:5>> -> I; + Other -> {no_match,Other} + end + end, + + SignedInteger = fun() -> + {no_match,_} = Sint(Mkbin([])), + {no_match,_} = Sint(Mkbin([1,2,3])), + 127 = Sint(Mkbin([127])), + -1 = Sint(Mkbin([255])), + -128 = Sint(Mkbin([128])), + 42 = Sint(Mkbin([42,255])), + 127 = Sint(Mkbin([127,255])) + end, + SignedInteger(), + + Dynamic5 = fun(Bin, S1, S2, A, B) -> + case Bin of + <<A:S1,B:S2>> -> + %% io:format(\"~p ~p ~p ~p~n\", [S1,S2,A,B]), + ok; + _Other -> erlang:error(badmatch, [Bin,S1,S2,A,B]) + end + end, + + Dynamic2 = fun(Bin, S1, F) when S1 >= 0 -> + S2 = size(Bin) * 8 - S1, + Dynamic5(Bin, S1, S2, (1 bsl S1) - 1, (1 bsl S2) - 1), + F(Bin, S1-1, F); + (_, _, _) -> ok + end, + + Dynamic = fun(Bin, S1) -> + Dynamic2(Bin, S1, Dynamic2) + end, + + Dynamic(Mkbin([255]), 8), + Dynamic(Mkbin([255,255]), 16), + Dynamic(Mkbin([255,255,255]), 24), + Dynamic(Mkbin([255,255,255,255]), 32), + + BigToLittle4 = + fun([B0,B1,B2,B3,B4,B5,B6,B7|T], N, Acc, F) when N >= 8 -> + F(T, N-8, [B0,B1,B2,B3,B4,B5,B6,B7|Acc], F); + (List, N, Acc, _F) -> lists:sublist(List, 1, N) ++ Acc + end, + + BigToLittle = + fun(List, N) -> BigToLittle4(List, N, [], BigToLittle4) end, + + ReversedSublist = + fun(_List, 0, Acc, _F) -> Acc; + ([H|T], N, Acc, F) -> F(T, N-1, [H|Acc], F) + end, + + TwoComplementAndReverse = + fun([H|T], Carry, Acc, F) -> + Sum = 1-H+Carry, + F(T, Sum div 2, [Sum rem 2|Acc], F); + ([], Carry, Acc, _F) -> [Carry|Acc] + end, + + MakeInt = fun(_List, 0, Acc, _F) -> Acc; + ([H|T], N, Acc, F) -> F(T, N-1, Acc bsl 1 bor H, F) + end, + + MakeSignedInt = + fun(_List, 0) -> 0; + ([0|_]=List, N) -> MakeInt(List, N, 0, MakeInt); + ([1|_]=List0, N) -> + List1 = ReversedSublist(List0, N, [], ReversedSublist), + List2 = TwoComplementAndReverse(List1, 1, [], + TwoComplementAndReverse), + -MakeInt(List2, length(List2), 0, MakeInt) + end, + + BitsToList = + fun([H|T], 0, F) -> F(T, 16#80, F); + ([H|_]=List, Mask, F) -> + [case H band Mask of 0 -> 0; _ -> 1 - end | F(List, Mask bsr 1, F)]; - ([], _, _F) -> [] - end, - - MoreDynamic3 = - fun(Action, Bin, List, Bef, Aft, F) when Bef =< Aft -> - Action(Bin, List, Bef, Aft-Bef), - F(Action, Bin, List, Bef, Aft-1, F); - (_, _, _, _, _, _) -> ok - end, - - MoreDynamic2 = - fun(Action, Bin, [_|T]=List, Bef, F) -> - MoreDynamic3(Action, Bin, List, Bef, size(Bin)*8, - MoreDynamic3), - F(Action, Bin, T, Bef+1, F); - (_, _, [], _, _F) -> ok - end, - - MoreDynamic1 = - fun(Action, Bin) -> - BitList = BitsToList(binary_to_list(Bin),16#80,BitsToList), - MoreDynamic2(Action, Bin, BitList, 0, MoreDynamic2) - end, - - MoreDynamic = fun() -> - % Unsigned big-endian numbers. - Unsigned = fun(Bin, List, SkipBef, N) -> - SkipAft = 8*size(Bin) - N - SkipBef, - <<_:SkipBef,Int:N,_:SkipAft>> = Bin, - Int = MakeInt(List, N, 0, MakeInt) - end, - MoreDynamic1(Unsigned, erlang:md5(Mkbin([42]))), + end | F(List, Mask bsr 1, F)]; + ([], _, _F) -> [] + end, + + MoreDynamic3 = + fun(Action, Bin, List, Bef, Aft, F) when Bef =< Aft -> + Action(Bin, List, Bef, Aft-Bef), + F(Action, Bin, List, Bef, Aft-1, F); + (_, _, _, _, _, _) -> ok + end, + + MoreDynamic2 = + fun(Action, Bin, [_|T]=List, Bef, F) -> + MoreDynamic3(Action, Bin, List, Bef, size(Bin)*8, + MoreDynamic3), + F(Action, Bin, T, Bef+1, F); + (_, _, [], _, _F) -> ok + end, + + MoreDynamic1 = + fun(Action, Bin) -> + BitList = BitsToList(binary_to_list(Bin),16#80,BitsToList), + MoreDynamic2(Action, Bin, BitList, 0, MoreDynamic2) + end, + + MoreDynamic = fun() -> + %% Unsigned big-endian numbers. + Unsigned = fun(Bin, List, SkipBef, N) -> + SkipAft = 8*size(Bin) - N - SkipBef, + <<_:SkipBef,Int:N,_:SkipAft>> = Bin, + Int = MakeInt(List, N, 0, MakeInt) + end, + MoreDynamic1(Unsigned, erlang:md5(Mkbin([42]))), %% Signed big-endian numbers. - Signed = fun(Bin, List, SkipBef, N) -> - SkipAft = 8*size(Bin) - N - SkipBef, - <<_:SkipBef,Int:N/signed,_:SkipAft>> = Bin, - case MakeSignedInt(List, N) of - Int -> ok; - Other -> - io:format(\"Bin = ~p,\", [Bin]), + Signed = fun(Bin, List, SkipBef, N) -> + SkipAft = 8*size(Bin) - N - SkipBef, + <<_:SkipBef,Int:N/signed,_:SkipAft>> = Bin, + case MakeSignedInt(List, N) of + Int -> ok; + Other -> + io:format(\"Bin = ~p,\", [Bin]), io:format(\"SkipBef = ~p, N = ~p\", [SkipBef,N]), - io:format(\"Expected ~p, got ~p\", + io:format(\"Expected ~p, got ~p\", [Int,Other]) - end - end, - MoreDynamic1(Signed, erlang:md5(Mkbin([43]))), + end + end, + MoreDynamic1(Signed, erlang:md5(Mkbin([43]))), %% Unsigned little-endian numbers. - UnsLittle = fun(Bin, List, SkipBef, N) -> - SkipAft = 8*size(Bin) - N - SkipBef, - <<_:SkipBef,Int:N/little,_:SkipAft>> = Bin, - Int = MakeInt(BigToLittle(List, N), N, 0, - MakeInt) - end, - MoreDynamic1(UnsLittle, erlang:md5(Mkbin([44]))), + UnsLittle = fun(Bin, List, SkipBef, N) -> + SkipAft = 8*size(Bin) - N - SkipBef, + <<_:SkipBef,Int:N/little,_:SkipAft>> = Bin, + Int = MakeInt(BigToLittle(List, N), N, 0, + MakeInt) + end, + MoreDynamic1(UnsLittle, erlang:md5(Mkbin([44]))), %% Signed little-endian numbers. - SignLittle = fun(Bin, List, SkipBef, N) -> - SkipAft = 8*size(Bin) - N - SkipBef, - <<_:SkipBef,Int:N/signed-little,_:SkipAft>> = Bin, - Little = BigToLittle(List, N), - Int = MakeSignedInt(Little, N) - end, - MoreDynamic1(SignLittle, erlang:md5(Mkbin([45]))) - end, - MoreDynamic(), - - ok. - ">>, + SignLittle = fun(Bin, List, SkipBef, N) -> + SkipAft = 8*size(Bin) - N - SkipBef, + <<_:SkipBef,Int:N/signed-little,_:SkipAft>> = Bin, + Little = BigToLittle(List, N), + Int = MakeSignedInt(Little, N) + end, + MoreDynamic1(SignLittle, erlang:md5(Mkbin([45]))) + end, + MoreDynamic(), + + ok. +">>, [ok] = scan(C), - ok = evaluate(C, []). +ok = evaluate(C, []). -bs_match_tail_SUITE(doc) -> - ["OTP-5327. Adopted from emulator/test/bs_match_tail_SUITE.erl."]; -bs_match_tail_SUITE(suite) -> - []; +%% OTP-5327. Adopted from emulator/test/bs_match_tail_SUITE.erl. bs_match_tail_SUITE(Config) when is_list(Config) -> C = <<" GetTailUsed = fun(<<A:1,T/binary>>) -> {A,T} end, @@ -1213,13 +1167,13 @@ bs_match_tail_SUITE(Config) when is_list(Config) -> GetTailUnused = fun(<<A:15,_/binary>>) -> A end, GetDynTailUsed = fun(Bin, Sz) -> - <<A:Sz,T/binary>> = Bin, - {A,T} + <<A:Sz,T/binary>> = Bin, + {A,T} end, GetDynTailUnused = fun(Bin, Sz) -> - <<A:Sz,_/binary>> = Bin, - A + <<A:Sz,_/binary>> = Bin, + A end, Mkbin = fun(L) when list(L) -> list_to_binary(L) end, @@ -1229,12 +1183,12 @@ bs_match_tail_SUITE(Config) when is_list(Config) -> TestZeroTail2 = fun(<<_A:4,_B:4>>) -> ok end, ZeroTail = fun() -> - 7 = (catch TestZeroTail(Mkbin([7]))), - {'EXIT',{function_clause,_}} = - (catch TestZeroTail(Mkbin([1,2]))), - {'EXIT',{function_clause,_}} = - (catch TestZeroTail2(Mkbin([1,2,3]))) - end, + 7 = (catch TestZeroTail(Mkbin([7]))), + {'EXIT',{function_clause,_}} = + (catch TestZeroTail(Mkbin([1,2]))), + {'EXIT',{function_clause,_}} = + (catch TestZeroTail2(Mkbin([1,2,3]))) + end, ZeroTail(), AlGetTailUsed = fun(<<A:16,T/binary>>) -> {A,T} end, @@ -1242,45 +1196,42 @@ bs_match_tail_SUITE(Config) when is_list(Config) -> AlGetTailUnused = fun(<<A:16,_/binary>>) -> A end, Aligned = fun() -> - Tail1 = Mkbin([]), - {258,Tail1} = AlGetTailUsed(Mkbin([1,2])), - Tail2 = Mkbin(lists:seq(1, 127)), - {35091,Tail2} = AlGetTailUsed(Mkbin([137,19|Tail2])), - - 64896 = AlGetTailUnused(Mkbin([253,128])), - 64895 = AlGetTailUnused(Mkbin([253,127|lists:seq(42, 255)])), - - Tail3 = Mkbin(lists:seq(0, 19)), - {0,Tail1} = GetDynTailUsed(Tail1, 0), - {0,Tail3} = GetDynTailUsed(Mkbin([Tail3]), 0), - {73,Tail3} = GetDynTailUsed(Mkbin([73|Tail3]), 8), - - 0 = GetDynTailUnused(Mkbin([]), 0), - 233 = GetDynTailUnused(Mkbin([233]), 8), - 23 = GetDynTailUnused(Mkbin([23,22,2]), 8) - end, + Tail1 = Mkbin([]), + {258,Tail1} = AlGetTailUsed(Mkbin([1,2])), + Tail2 = Mkbin(lists:seq(1, 127)), + {35091,Tail2} = AlGetTailUsed(Mkbin([137,19|Tail2])), + + 64896 = AlGetTailUnused(Mkbin([253,128])), + 64895 = AlGetTailUnused(Mkbin([253,127|lists:seq(42, 255)])), + + Tail3 = Mkbin(lists:seq(0, 19)), + {0,Tail1} = GetDynTailUsed(Tail1, 0), + {0,Tail3} = GetDynTailUsed(Mkbin([Tail3]), 0), + {73,Tail3} = GetDynTailUsed(Mkbin([73|Tail3]), 8), + + 0 = GetDynTailUnused(Mkbin([]), 0), + 233 = GetDynTailUnused(Mkbin([233]), 8), + 23 = GetDynTailUnused(Mkbin([23,22,2]), 8) + end, Aligned(), - + UnAligned = fun() -> - {'EXIT',{function_clause,_}} = - (catch GetTailUsed(Mkbin([42]))), - {'EXIT',{{badmatch,_},_}} = - (catch GetDynTailUsed(Mkbin([137]), 3)), - {'EXIT',{function_clause,_}} = - (catch GetTailUnused(Mkbin([42,33]))), - {'EXIT',{{badmatch,_},_}} = - (catch GetDynTailUnused(Mkbin([44]), 7)) - end, + {'EXIT',{function_clause,_}} = + (catch GetTailUsed(Mkbin([42]))), + {'EXIT',{{badmatch,_},_}} = + (catch GetDynTailUsed(Mkbin([137]), 3)), + {'EXIT',{function_clause,_}} = + (catch GetTailUnused(Mkbin([42,33]))), + {'EXIT',{{badmatch,_},_}} = + (catch GetDynTailUnused(Mkbin([44]), 7)) + end, UnAligned(), ok. - ">>, +">>, [ok] = scan(C), - ok = evaluate(C, []). +ok = evaluate(C, []). -bs_match_bin_SUITE(doc) -> - ["OTP-5327. Adopted from emulator/test/bs_match_bin_SUITE.erl."]; -bs_match_bin_SUITE(suite) -> - []; +%% OTP-5327. Adopted from emulator/test/bs_match_bin_SUITE.erl. bs_match_bin_SUITE(Config) when is_list(Config) -> ByteSplitBinary = <<"ByteSplit = @@ -1290,252 +1241,249 @@ bs_match_bin_SUITE(Config) when is_list(Config) -> <<B1:Sz1/binary,B2:Sz2/binary>> = B, B1 = list_to_binary(lists:sublist(L, 1, Pos)), B2 = list_to_binary(lists:nthtail(Pos, L)), - Fun(L, B, Pos-1, Fun); - (L, B, _, _Fun) -> ok - end, - Mkbin = fun(L) when list(L) -> list_to_binary(L) end, - L = lists:seq(0, 57), - B = Mkbin(L), - ByteSplit(L, B, size(B), ByteSplit), - Id = fun(I) -> I end, - MakeUnalignedSubBinary = - fun(Bin0) -> - Bin1 = <<0:3,Bin0/binary,31:5>>, - Sz = size(Bin0), - <<0:3,Bin:Sz/binary,31:5>> = Id(Bin1), - Bin + Fun(L, B, Pos-1, Fun); + (L, B, _, _Fun) -> ok end, - Unaligned = MakeUnalignedSubBinary(B), - ByteSplit(L, Unaligned, size(Unaligned), ByteSplit), - ok. - ">>, + Mkbin = fun(L) when list(L) -> list_to_binary(L) end, + L = lists:seq(0, 57), + B = Mkbin(L), + ByteSplit(L, B, size(B), ByteSplit), + Id = fun(I) -> I end, + MakeUnalignedSubBinary = + fun(Bin0) -> + Bin1 = <<0:3,Bin0/binary,31:5>>, + Sz = size(Bin0), + <<0:3,Bin:Sz/binary,31:5>> = Id(Bin1), + Bin + end, + Unaligned = MakeUnalignedSubBinary(B), + ByteSplit(L, Unaligned, size(Unaligned), ByteSplit), + ok. +">>, [ok] = scan(ByteSplitBinary), - ok = evaluate(ByteSplitBinary, []), - BitSplitBinary = - <<"Mkbin = fun(L) when list(L) -> list_to_binary(L) end, +ok = evaluate(ByteSplitBinary, []), +BitSplitBinary = +<<"Mkbin = fun(L) when list(L) -> list_to_binary(L) end, MakeInt = - fun(List, 0, Acc, _F) -> Acc; - ([H|T], N, Acc, F) -> F(T, N-1, Acc bsl 1 bor H, F) - end, - - MakeBinFromList = - fun(List, 0, _F) -> Mkbin([]); - (List, N, F) -> - list_to_binary([MakeInt(List, 8, 0, MakeInt), - F(lists:nthtail(8, List), N-8, F)]) - end, - - BitSplitBinary3 = - fun(Action, Bin, List, Bef, Aft, F) when Bef =< Aft -> - Action(Bin, List, Bef, (Aft-Bef) div 8 * 8), - F(Action, Bin, List, Bef, Aft-8, F); - (_, _, _, _, _, _) -> ok - end, - - BitSplitBinary2 = - fun(Action, Bin, [_|T]=List, Bef, F) -> - BitSplitBinary3(Action, Bin, List, Bef, size(Bin)*8, - BitSplitBinary3), - F(Action, Bin, T, Bef+1, F); - (Action, Bin, [], Bef, F) -> ok - end, - - BitsToList = - fun([H|T], 0, F) -> F(T, 16#80, F); - ([H|_]=List, Mask, F) -> - [case H band Mask of - 0 -> 0; - _ -> 1 - end | F(List, Mask bsr 1, F)]; - ([], _, _F) -> [] - end, - - BitSplitBinary1 = - fun(Action, Bin) -> - BitList = BitsToList(binary_to_list(Bin), 16#80, - BitsToList), - BitSplitBinary2(Action, Bin, BitList, 0, BitSplitBinary2) - end, - - Fun = fun(Bin, List, SkipBef, N) -> - SkipAft = 8*size(Bin) - N - SkipBef, - <<I1:SkipBef,OutBin:N/binary-unit:1,I2:SkipAft>> = Bin, - OutBin = MakeBinFromList(List, N, MakeBinFromList) - end, - - BitSplitBinary1(Fun, erlang:md5(<<1,2,3>>)), - Id = fun(I) -> I end, - MakeUnalignedSubBinary = - fun(Bin0) -> - Bin1 = <<0:3,Bin0/binary,31:5>>, - Sz = size(Bin0), - <<0:3,Bin:Sz/binary,31:5>> = Id(Bin1), - Bin - end, - BitSplitBinary1(Fun, MakeUnalignedSubBinary(erlang:md5(<<1,2,3>>))), - ok. - ">>, + fun(List, 0, Acc, _F) -> Acc; + ([H|T], N, Acc, F) -> F(T, N-1, Acc bsl 1 bor H, F) + end, + + MakeBinFromList = + fun(List, 0, _F) -> Mkbin([]); + (List, N, F) -> + list_to_binary([MakeInt(List, 8, 0, MakeInt), + F(lists:nthtail(8, List), N-8, F)]) + end, + + BitSplitBinary3 = + fun(Action, Bin, List, Bef, Aft, F) when Bef =< Aft -> + Action(Bin, List, Bef, (Aft-Bef) div 8 * 8), + F(Action, Bin, List, Bef, Aft-8, F); + (_, _, _, _, _, _) -> ok + end, + + BitSplitBinary2 = + fun(Action, Bin, [_|T]=List, Bef, F) -> + BitSplitBinary3(Action, Bin, List, Bef, size(Bin)*8, + BitSplitBinary3), + F(Action, Bin, T, Bef+1, F); + (Action, Bin, [], Bef, F) -> ok + end, + + BitsToList = + fun([H|T], 0, F) -> F(T, 16#80, F); + ([H|_]=List, Mask, F) -> + [case H band Mask of + 0 -> 0; + _ -> 1 + end | F(List, Mask bsr 1, F)]; + ([], _, _F) -> [] + end, + + BitSplitBinary1 = + fun(Action, Bin) -> + BitList = BitsToList(binary_to_list(Bin), 16#80, + BitsToList), + BitSplitBinary2(Action, Bin, BitList, 0, BitSplitBinary2) + end, + + Fun = fun(Bin, List, SkipBef, N) -> + SkipAft = 8*size(Bin) - N - SkipBef, + <<I1:SkipBef,OutBin:N/binary-unit:1,I2:SkipAft>> = Bin, + OutBin = MakeBinFromList(List, N, MakeBinFromList) + end, + + BitSplitBinary1(Fun, erlang:md5(<<1,2,3>>)), + Id = fun(I) -> I end, + MakeUnalignedSubBinary = + fun(Bin0) -> + Bin1 = <<0:3,Bin0/binary,31:5>>, + Sz = size(Bin0), + <<0:3,Bin:Sz/binary,31:5>> = Id(Bin1), + Bin + end, + BitSplitBinary1(Fun, MakeUnalignedSubBinary(erlang:md5(<<1,2,3>>))), + ok. +">>, [ok] = scan(BitSplitBinary), - ok = evaluate(BitSplitBinary, []). +ok = evaluate(BitSplitBinary, []). -define(FAIL(Expr), "{'EXIT',{badarg,_}} = (catch " ??Expr ")"). -define(COF(Int0), "(fun(Int) -> true = <<Int:32/float>> =:= <<(float(Int)):32/float>>, - true = <<Int:64/float>> =:= <<(float(Int)):64/float>> - end)(Nonliteral(" ??Int0 ")), - true = <<" ??Int0 ":32/float>> =:= <<(float("??Int0")):32/float>>, - true = <<" ??Int0 ":64/float>> =:= <<(float("??Int0")):64/float>>"). + true = <<Int:64/float>> =:= <<(float(Int)):64/float>> + end)(Nonliteral(" ??Int0 ")), +true = <<" ??Int0 ":32/float>> =:= <<(float("??Int0")):32/float>>, +true = <<" ??Int0 ":64/float>> =:= <<(float("??Int0")):64/float>>"). -define(COF64(Int0), "(fun(Int) -> true = <<Int:64/float>> =:= <<(float(Int)):64/float>> - end)(Nonliteral(" ??Int0 ")), - true = <<" ??Int0 ":64/float>> =:= <<(float("??Int0")):64/float>>"). + end)(Nonliteral(" ??Int0 ")), +true = <<" ??Int0 ":64/float>> =:= <<(float("??Int0")):64/float>>"). -bs_construct_SUITE(doc) -> - ["OTP-5327. Adopted from parts of emulator/test/bs_construct_SUITE.erl."]; -bs_construct_SUITE(suite) -> - []; +%% OTP-5327. Adopted from parts of emulator/test/bs_construct_SUITE.erl. bs_construct_SUITE(Config) when is_list(Config) -> C1 = <<" Testf_1 = fun(W, B) -> " ?FAIL(<<42:W>>) "," - ?FAIL(<<3.14:W/float>>) "," - ?FAIL(<<B:W/binary>>) " + ?FAIL(<<3.14:W/float>>) "," + ?FAIL(<<B:W/binary>>) " end, - TestF = fun() -> " + TestF = fun() -> " ?FAIL(<<3.14>>) "," - ?FAIL(<<<<1,2>>>>) "," + ?FAIL(<<<<1,2>>>>) "," - ?FAIL(<<2.71/binary>>) "," - ?FAIL(<<24334/binary>>) "," - ?FAIL(<<24334344294788947129487129487219847/binary>>) "," + ?FAIL(<<2.71/binary>>) "," + ?FAIL(<<24334/binary>>) "," + ?FAIL(<<24334344294788947129487129487219847/binary>>) "," - ?FAIL(<<<<1,2,3>>/float>>) ", + ?FAIL(<<<<1,2,3>>/float>>) ", %% Negative field widths. Testf_1(-8, <<1,2,3,4,5>>)," ?FAIL(<<42:(-16)>>) "," - ?FAIL(<<3.14:(-8)/float>>) "," - ?FAIL(<<<<23,56,0,2>>:(-16)/binary>>) "," - ?FAIL(<<<<23,56,0,2>>:(2.5)/binary>>) "," - ?FAIL(<<<<23,56,0,2>>:(anka)>>) " + ?FAIL(<<3.14:(-8)/float>>) "," + ?FAIL(<<<<23,56,0,2>>:(-16)/binary>>) "," + ?FAIL(<<<<23,56,0,2>>:(2.5)/binary>>) "," + ?FAIL(<<<<23,56,0,2>>:(anka)>>) " end, - TestF(), + TestF(), - NotUsed1 = fun(I, BinString) -> <<I:32,BinString/binary>>, ok end, + NotUsed1 = fun(I, BinString) -> <<I:32,BinString/binary>>, ok end, - NotUsed2 = fun(I, Sz) -> <<I:Sz>>, ok end, + NotUsed2 = fun(I, Sz) -> <<I:Sz>>, ok end, - NotUsed3 = fun(I) -><<I:(-8)>>, ok end, + NotUsed3 = fun(I) -><<I:(-8)>>, ok end, - NotUsed = fun() -> - ok = NotUsed1(3, <<\"dum\">>), + NotUsed = fun() -> + ok = NotUsed1(3, <<\"dum\">>), {'EXIT',{badarg,_}} = (catch NotUsed1(3, \"dum\")), " - ?FAIL(NotUsed2(444, -2)) "," - ?FAIL(NotUsed2(444, anka)) "," - ?FAIL(NotUsed3(444)) " + ?FAIL(NotUsed2(444, -2)) "," + ?FAIL(NotUsed2(444, anka)) "," + ?FAIL(NotUsed3(444)) " end, - NotUsed(), - - InGuard3 = fun(Bin, A, B) when <<A:13,B:3>> == Bin -> 1; - (Bin, A, B) when <<A:16,B/binary>> == Bin -> 2; - (Bin, A, B) when <<A:14,B/float,3:2>> == Bin -> 3; - (Bin, A, B) when {a,b,<<A:14,B/float,3:2>>} == Bin -> - cant_happen; - (_, _, _) -> nope - end, - - InGuard = fun() -> - 1 = InGuard3(<<16#74ad:16>>, 16#e95, 5), - 2 = InGuard3(<<16#3A,16#F7,\"hello\">>, 16#3AF7, <<\"hello\">>), + NotUsed(), + + InGuard3 = fun(Bin, A, B) when <<A:13,B:3>> == Bin -> 1; + (Bin, A, B) when <<A:16,B/binary>> == Bin -> 2; + (Bin, A, B) when <<A:14,B/float,3:2>> == Bin -> 3; + (Bin, A, B) when {a,b,<<A:14,B/float,3:2>>} == Bin -> + cant_happen; + (_, _, _) -> nope + end, + + InGuard = fun() -> + 1 = InGuard3(<<16#74ad:16>>, 16#e95, 5), + 2 = InGuard3(<<16#3A,16#F7,\"hello\">>, 16#3AF7, <<\"hello\">>), 3 = InGuard3(<<16#FBCD:14,3.1415/float,3:2>>, 16#FBCD, 3.1415), - nope = InGuard3(<<1>>, 42, b), - nope = InGuard3(<<1>>, a, b), - nope = InGuard3(<<1,2>>, 1, 1), - nope = InGuard3(<<4,5>>, 1, 2.71), - nope = InGuard3(<<4,5>>, 1, <<12,13>>) - end, - InGuard(), + nope = InGuard3(<<1>>, 42, b), + nope = InGuard3(<<1>>, a, b), + nope = InGuard3(<<1,2>>, 1, 1), + nope = InGuard3(<<4,5>>, 1, 2.71), + nope = InGuard3(<<4,5>>, 1, <<12,13>>) + end, + InGuard(), - Nonliteral = fun(X) -> X end, + Nonliteral = fun(X) -> X end, - CoerceToFloat = fun() -> " + CoerceToFloat = fun() -> " ?COF(0) "," - ?COF(-1) "," - ?COF(1) "," - ?COF(42) "," - ?COF(255) "," - ?COF(-255) "," - ?COF64(298748888888888888888888888883478264866528467367364766666666666666663) "," - ?COF64(-367546729879999999999947826486652846736736476555566666663) " + ?COF(-1) "," + ?COF(1) "," + ?COF(42) "," + ?COF(255) "," + ?COF(-255) "," + ?COF64(298748888888888888888888888883478264866528467367364766666666666666663) "," + ?COF64(-367546729879999999999947826486652846736736476555566666663) " end, - CoerceToFloat(), - ok. - ">>, + CoerceToFloat(), + ok. +">>, [ok] = scan(C1), - ok = evaluate(C1, []), +ok = evaluate(C1, []), - %% There is another one, lib/compiler/test/bs_construct_SUITE.erl... - C2 = <<" +%% There is another one, lib/compiler/test/bs_construct_SUITE.erl... +C2 = <<" I = fun(X) -> X end, Fail = fun() -> - I_minus_777 = I(-777), - I_minus_2047 = I(-2047), + I_minus_777 = I(-777), + I_minus_2047 = I(-2047), %% One negative field size, but the sum of field sizes will be 1 byte. %% Make sure that we reject that properly. - {'EXIT',{badarg,_}} = (catch <<I_minus_777:2048/unit:8, - 57:I_minus_2047/unit:8>>), + {'EXIT',{badarg,_}} = (catch <<I_minus_777:2048/unit:8, + 57:I_minus_2047/unit:8>>), %% Same thing, but use literals. - {'EXIT',{badarg,_}} = (catch <<I_minus_777:2048/unit:8, - 57:(-2047)/unit:8>>), + {'EXIT',{badarg,_}} = (catch <<I_minus_777:2048/unit:8, + 57:(-2047)/unit:8>>), %% Bad alignment. - I_one = I(1), - <<1:1>> = <<2375:I_one>>, - <<3:2>> = <<45:1,2375:I_one>>, - <<14:4>> = <<45:1,2375:I_one,918:2>>, - <<118:7>> = <<45:1,2375:I_one,918:5>>, + I_one = I(1), + <<1:1>> = <<2375:I_one>>, + <<3:2>> = <<45:1,2375:I_one>>, + <<14:4>> = <<45:1,2375:I_one,918:2>>, + <<118:7>> = <<45:1,2375:I_one,918:5>>, %% Not numbers. - {'EXIT',{badarg,_}} = (catch <<45:(I(not_a_number))>>), - {'EXIT',{badarg,_}} = (catch <<13:8,45:(I(not_a_number))>>), + {'EXIT',{badarg,_}} = (catch <<45:(I(not_a_number))>>), + {'EXIT',{badarg,_}} = (catch <<13:8,45:(I(not_a_number))>>), %% Unaligned sizes. - BadSz = I(7), - <<2:4>> = <<34:4>>, - <<34:7>> = <<34:BadSz>>, + BadSz = I(7), + <<2:4>> = <<34:4>>, + <<34:7>> = <<34:BadSz>>, - [] = [X || {X} <- [], X == <<3:BadSz>>], - [] = [X || {X} <- [], X == <<3:4>>] - end, + [] = [X || {X} <- [], X == <<3:BadSz>>], + [] = [X || {X} <- [], X == <<3:4>>] + end, Fail(), FloatBin1 = fun(F) -> - {<<1,2,3>>,F+3.0} - end, + {<<1,2,3>>,F+3.0} + end, FloatBin = fun() -> %% Some more coverage. - {<<1,2,3>>,7.0} = FloatBin1(4) - end, + {<<1,2,3>>,7.0} = FloatBin1(4) + end, FloatBin(), ok. - ">>, +">>, [ok] = scan(C2), - ok = evaluate(C2, []). +ok = evaluate(C2, []). evaluate(B, Vars) when is_binary(B) -> evaluate(binary_to_list(B), Vars); @@ -1549,60 +1497,55 @@ evaluate(Str, Vars) -> end. -refman_bit_syntax(doc) -> - ["Bit syntax examples from the Reference Manual. OTP-5237."]; -refman_bit_syntax(suite) -> - []; +%% Bit syntax examples from the Reference Manual. OTP-5237. refman_bit_syntax(Config) when is_list(Config) -> %% Reference Manual "Bit Syntax Expressions" - ?line Bin1 = <<1,17,42>>, - ?line true = [1,17,42] =:= binary_to_list(Bin1), - ?line Bin2 = <<"abc">>, - ?line true = "abc" =:= binary_to_list(Bin2), - ?line Bin3 = <<1,17,42:16>>, - ?line true = [1,17,0,42] =:= binary_to_list(Bin3), - ?line <<_A,_B,C:16>> = <<1,17,42:16>>, - ?line true = C =:= 42, - ?line <<D:16,_E,F>> = <<1,17,42:16>>, - ?line true = D =:= 273, - ?line true = F =:= 42, + Bin1 = <<1,17,42>>, + true = [1,17,42] =:= binary_to_list(Bin1), + Bin2 = <<"abc">>, + true = "abc" =:= binary_to_list(Bin2), + Bin3 = <<1,17,42:16>>, + true = [1,17,0,42] =:= binary_to_list(Bin3), + <<_A,_B,C:16>> = <<1,17,42:16>>, + true = C =:= 42, + <<D:16,_E,F>> = <<1,17,42:16>>, + true = D =:= 273, + true = F =:= 42, <<_G,H/binary>> = <<1,17,42:16>>, - ?line true = H =:= <<17,0,42>>, + true = H =:= <<17,0,42>>, - ?line [ok] = + [ok] = scan(<<"Bin1 = <<1,17,42>>, true = [1,17,42] =:= binary_to_list(Bin1), - Bin2 = <<\"abc\">>, + Bin2 = <<\"abc\">>, true = \"abc\" =:= binary_to_list(Bin2), Bin3 = <<1,17,42:16>>, - true = - [1,17,0,42] =:= binary_to_list(Bin3), - <<A,B,C:16>> = <<1,17,42:16>>, - true = C =:= 42, - <<D:16,E,F>> = <<1,17,42:16>>, - true = D =:= 273, - true = F =:= 42, - <<G,H/binary>> = <<1,17,42:16>>, - true = H =:= <<17,0,42>>, - ok.">>), + true = + [1,17,0,42] =:= binary_to_list(Bin3), + <<A,B,C:16>> = <<1,17,42:16>>, + true = C =:= 42, + <<D:16,E,F>> = <<1,17,42:16>>, + true = D =:= 273, + true = F =:= 42, + <<G,H/binary>> = <<1,17,42:16>>, + true = H =:= <<17,0,42>>, + ok.">>), %% Binary comprehensions. - ?line <<2,4,6>> = << << (X*2) >> || <<X>> <= << 1,2,3 >> >>, - ok. + <<2,4,6>> = << << (X*2) >> || <<X>> <= << 1,2,3 >> >>, + ok. -define(IP_VERSION, 4). -define(IP_MIN_HDR_LEN, 5). -progex_bit_syntax(doc) -> - ["Bit syntax examples from Programming Examples. OTP-5237."]; -progex_bit_syntax(suite) -> - []; + +%% Bit syntax examples from Programming Examples. OTP-5237. progex_bit_syntax(Config) when is_list(Config) -> Bin11 = <<1, 17, 42>>, true = [1, 17, 42] =:= binary_to_list(Bin11), Bin12 = <<"abc">>, true = [97, 98, 99] =:= binary_to_list(Bin12), - + A = 1, B = 17, C = 42, Bin2 = <<A, B, C:16>>, true = [1, 17, 00, 42] =:= binary_to_list(Bin2), @@ -1615,10 +1558,10 @@ progex_bit_syntax(Config) when is_list(Config) -> DgramSize = byte_size(Dgram), case Dgram of <<?IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16, - ID:16, Flgs:3, FragOff:13, - TTL:8, Proto:8, HdrChkSum:16, - SrcIP:32, DestIP:32, - RestDgram/binary>> when HLen>=5, 4*HLen=<DgramSize -> + ID:16, Flgs:3, FragOff:13, + TTL:8, Proto:8, HdrChkSum:16, + SrcIP:32, DestIP:32, + RestDgram/binary>> when HLen>=5, 4*HLen=<DgramSize -> OptsLen = 4*(HLen - ?IP_MIN_HDR_LEN), <<Opts:OptsLen/binary,Data/binary>> = RestDgram, {SrvcType, TotLen, Flgs, FragOff, ID, HdrChkSum, @@ -1655,57 +1598,57 @@ progex_bit_syntax(Config) when is_list(Config) -> B2 = triples_to_bin2(BL), true = Lst =:= binary_to_list(B2), - ?line [ok] = scan( - <<"Bin11 = <<1, 17, 42>>, + [ok] = scan( + <<"Bin11 = <<1, 17, 42>>, true = [1, 17, 42] =:= binary_to_list(Bin11), - Bin12 = <<\"abc\">>, + Bin12 = <<\"abc\">>, true = [97, 98, 99] =:= binary_to_list(Bin12), - A = 1, B = 17, C = 42, - Bin2 = <<A, B, C:16>>, - true = [1, 17, 00, 42] =:= binary_to_list(Bin2), - <<D:16, E, F/binary>> = Bin2, - true = D =:= 273, - true = E =:= 00, - true = [42] =:= binary_to_list(F), - - Fun4 = fun(Dgram) -> - DgramSize = byte_size(Dgram), - case Dgram of - <<4:4, HLen:4, SrvcType:8, TotLen:16, - ID:16, Flgs:3, FragOff:13, - TTL:8, Proto:8, HdrChkSum:16, - SrcIP:32, DestIP:32, - RestDgram/binary>> when HLen>=5, - 4*HLen=<DgramSize -> - OptsLen = 4*(HLen - 5), - <<Opts:OptsLen/binary,Data/binary>> = RestDgram, - {SrvcType, TotLen, Flgs, FragOff, ID, HdrChkSum, - Proto, TTL, SrcIP, DestIP, Data, Opts}; - _ -> - not_ok - end - end, - true = Fun4(<<>>) =:= not_ok, - true = is_tuple(Fun4(list_to_binary - ([<<4:4,5:4>>,list_to_binary(lists:seq(1,255))]))), - - X = 23432324, Y = 24324234, - <<10:7>> = <<X:1, Y:6>>, - Z = 234324324, - XYZ = <<X:1, Y:6, Z:1>>, - true = [20] =:= binary_to_list(XYZ), - Hello1 = <<\"hello\">>, + A = 1, B = 17, C = 42, + Bin2 = <<A, B, C:16>>, + true = [1, 17, 00, 42] =:= binary_to_list(Bin2), + <<D:16, E, F/binary>> = Bin2, + true = D =:= 273, + true = E =:= 00, + true = [42] =:= binary_to_list(F), + + Fun4 = fun(Dgram) -> + DgramSize = byte_size(Dgram), + case Dgram of + <<4:4, HLen:4, SrvcType:8, TotLen:16, + ID:16, Flgs:3, FragOff:13, + TTL:8, Proto:8, HdrChkSum:16, + SrcIP:32, DestIP:32, + RestDgram/binary>> when HLen>=5, + 4*HLen=<DgramSize -> + OptsLen = 4*(HLen - 5), + <<Opts:OptsLen/binary,Data/binary>> = RestDgram, + {SrvcType, TotLen, Flgs, FragOff, ID, HdrChkSum, + Proto, TTL, SrcIP, DestIP, Data, Opts}; + _ -> + not_ok + end + end, + true = Fun4(<<>>) =:= not_ok, + true = is_tuple(Fun4(list_to_binary + ([<<4:4,5:4>>,list_to_binary(lists:seq(1,255))]))), + + X = 23432324, Y = 24324234, + <<10:7>> = <<X:1, Y:6>>, + Z = 234324324, + XYZ = <<X:1, Y:6, Z:1>>, + true = [20] =:= binary_to_list(XYZ), + Hello1 = <<\"hello\">>, Hello2 = <<$h,$e,$l,$l,$o>>, - true = \"hello\" =:= binary_to_list(Hello1), + true = \"hello\" =:= binary_to_list(Hello1), true = \"hello\" =:= binary_to_list(Hello2), FunM1 = fun(<<X1:7/binary, Y1:1/binary>>) -> {X1,Y1} end, - true = {<<\"1234567\">>,<<\"8\">>} =:= FunM1(<<\"12345678\">>), + true = {<<\"1234567\">>,<<\"8\">>} =:= FunM1(<<\"12345678\">>), FunM2 = fun(<<_X1:7/binary-unit:7, _Y1:1/binary-unit:1>>) -> ok; (_) -> not_ok end, - true = not_ok =:= FunM2(<<\"1\">>), + true = not_ok =:= FunM2(<<\"1\">>), ok.">>), ok. @@ -1726,590 +1669,577 @@ triples_to_bin2([{X,Y,Z} | T], Acc) -> triples_to_bin2([], Acc) -> list_to_binary(lists:reverse(Acc)). -progex_records(doc) -> - ["Record examples from Programming Examples. OTP-5237."]; -progex_records(suite) -> - []; +%% Record examples from Programming Examples. OTP-5237. progex_records(Config) when is_list(Config) -> Test1 = - <<"-module(recs). + <<"-module(recs). -record(person, {name = \"\", phone = [], address}). -record(name, {first = \"Robert\", last = \"Ericsson\"}). -record(person2, {name = #name{}, phone}). - -export([t/0]). +-export([t/0]). - t() -> - _P1 = #person{phone=[0,8,2,3,4,3,1,2], name=\"Robert\"}, +t() -> + _P1 = #person{phone=[0,8,2,3,4,3,1,2], name=\"Robert\"}, \"Robert\" = _P1#person.name, [0,8,2,3,4,3,1,2] = _P1#person.phone, - undefined = _P1#person.address, + undefined = _P1#person.address, - _P2 = #person{name = \"Jakob\", _ = '_'}, + _P2 = #person{name = \"Jakob\", _ = '_'}, \"Jakob\" = _P2#person.name, '_' = _P2#person.phone, - '_' = _P2#person.address, - - P = #person{name = \"Joe\", phone = [0,8,2,3,4,3,1,2]}, + '_' = _P2#person.address, + + P = #person{name = \"Joe\", phone = [0,8,2,3,4,3,1,2]}, \"Joe\" = P#person.name, [0,8,2,3,4,3,1,2] = P#person.phone, - undefined = P#person.address, + undefined = P#person.address, - P1 = #person{name=\"Joe\", phone=[1,2,3], address=\"A street\"}, + P1 = #person{name=\"Joe\", phone=[1,2,3], address=\"A street\"}, P2 = P1#person{name=\"Robert\"}, \"Robert\" = P2#person.name, [1,2,3] = P2#person.phone, - \"A street\" = P2#person.address, + \"A street\" = P2#person.address, a_person = foo(P1), - {found, [1,2,3]} = - find_phone([#person{name = a}, - #person{name = b, phone = [3,2,1]}, - #person{name = c, phone = [1,2,3]}], - c), + {found, [1,2,3]} = + find_phone([#person{name = a}, + #person{name = b, phone = [3,2,1]}, + #person{name = c, phone = [1,2,3]}], + c), - P3 = #person{name=\"Joe\", phone=[0,0,7], address=\"A street\"}, + P3 = #person{name=\"Joe\", phone=[0,0,7], address=\"A street\"}, #person{name = Name} = P3, - \"Joe\" = Name, + \"Joe\" = Name, \"Robert\" = demo(), ok. - foo(P) when is_record(P, person) -> a_person; - foo(_) -> not_a_person. +foo(P) when is_record(P, person) -> a_person; +foo(_) -> not_a_person. - find_phone([#person{name=Name, phone=Phone} | _], Name) -> - {found, Phone}; - find_phone([_| T], Name) -> - find_phone(T, Name); - find_phone([], _Name) -> - not_found. +find_phone([#person{name=Name, phone=Phone} | _], Name) -> + {found, Phone}; +find_phone([_| T], Name) -> + find_phone(T, Name); +find_phone([], _Name) -> + not_found. - demo() -> - P = #person2{name= #name{first=\"Robert\",last=\"Virding\"}, +demo() -> + P = #person2{name= #name{first=\"Robert\",last=\"Virding\"}, phone=123}, - _First = (P#person2.name)#name.first. - ">>, - ?line ok = run_file(Config, recs, Test1), + _First = (P#person2.name)#name.first. +">>, + ok = run_file(Config, recs, Test1), - Test1_shell = - <<"rd(person, {name = \"\", phone = [], address}), +Test1_shell = +<<"rd(person, {name = \"\", phone = [], address}), rd(name, {first = \"Robert\", last = \"Ericsson\"}), rd(person2, {name = #name{}, phone}), - _P1 = #person{phone=[0,8,2,3,4,3,1,2], name=\"Robert\"}, + _P1 = #person{phone=[0,8,2,3,4,3,1,2], name=\"Robert\"}, \"Robert\" = _P1#person.name, [0,8,2,3,4,3,1,2] = _P1#person.phone, - undefined = _P1#person.address, + undefined = _P1#person.address, - _P2 = #person{name = \"Jakob\", _ = '_'}, + _P2 = #person{name = \"Jakob\", _ = '_'}, \"Jakob\" = _P2#person.name, '_' = _P2#person.phone, - '_' = _P2#person.address, + '_' = _P2#person.address, - P = #person{name = \"Joe\", phone = [0,8,2,3,4,3,1,2]}, + P = #person{name = \"Joe\", phone = [0,8,2,3,4,3,1,2]}, \"Joe\" = P#person.name, [0,8,2,3,4,3,1,2] = P#person.phone, - undefined = P#person.address, + undefined = P#person.address, - P1 = #person{name=\"Joe\", phone=[1,2,3], address=\"A street\"}, + P1 = #person{name=\"Joe\", phone=[1,2,3], address=\"A street\"}, P2 = P1#person{name=\"Robert\"}, \"Robert\" = P2#person.name, [1,2,3] = P2#person.phone, - \"A street\" = P2#person.address, + \"A street\" = P2#person.address, Foo = fun(P) when is_record(P, person) -> a_person; (_) -> not_a_person end, - a_person = Foo(P1), - - Find = fun([#person{name=Name, phone=Phone} | _], Name, Fn) -> - {found, Phone}; - ([_| T], Name, Fn) -> - Fn(T, Name, Fn); - ([], _Name, _Fn) -> - not_found - end, - - {found, [1,2,3]} = Find([#person{name = a}, - #person{name = b, phone = [3,2,1]}, - #person{name = c, phone = [1,2,3]}], - c, - Find), - - P3 = #person{name=\"Joe\", phone=[0,0,7], address=\"A street\"}, + a_person = Foo(P1), + + Find = fun([#person{name=Name, phone=Phone} | _], Name, Fn) -> + {found, Phone}; + ([_| T], Name, Fn) -> + Fn(T, Name, Fn); + ([], _Name, _Fn) -> + not_found + end, + + {found, [1,2,3]} = Find([#person{name = a}, + #person{name = b, phone = [3,2,1]}, + #person{name = c, phone = [1,2,3]}], + c, + Find), + + P3 = #person{name=\"Joe\", phone=[0,0,7], address=\"A street\"}, #person{name = Name} = P3, - \"Joe\" = Name, + \"Joe\" = Name, Demo = fun() -> - P17 = #person2{name= #name{first=\"Robert\",last=\"Virding\"}, + P17 = #person2{name= #name{first=\"Robert\",last=\"Virding\"}, phone=123}, - _First = (P17#person2.name)#name.first - end, + _First = (P17#person2.name)#name.first + end, - \"Robert\" = Demo(), + \"Robert\" = Demo(), ok. - ">>, - ?line [ok] = scan(Test1_shell), +">>, + [ok] = scan(Test1_shell), - Test2 = - <<"-module(recs). +Test2 = +<<"-module(recs). -record(person, {name, age, phone = [], dict = []}). - -compile(export_all). +-compile(export_all). - t() -> ok. +t() -> ok. - make_hacker_without_phone(Name, Age) -> - #person{name = Name, age = Age, - dict = [{computer_knowledge, excellent}, - {drinks, coke}]}. - print(#person{name = Name, age = Age, - phone = Phone, dict = Dict}) -> - io:format(\"Name: ~s, Age: ~w, Phone: ~w ~n\" +make_hacker_without_phone(Name, Age) -> + #person{name = Name, age = Age, + dict = [{computer_knowledge, excellent}, + {drinks, coke}]}. +print(#person{name = Name, age = Age, + phone = Phone, dict = Dict}) -> + io:format(\"Name: ~s, Age: ~w, Phone: ~w ~n\" \"Dictionary: ~w.~n\", [Name, Age, Phone, Dict]). birthday(P) when record(P, person) -> - P#person{age = P#person.age + 1}. + P#person{age = P#person.age + 1}. - register_two_hackers() -> - Hacker1 = make_hacker_without_phone(\"Joe\", 29), +register_two_hackers() -> + Hacker1 = make_hacker_without_phone(\"Joe\", 29), OldHacker = birthday(Hacker1), - % The central_register_server should have - % an interface function for this. - central_register_server ! {register_person, Hacker1}, - central_register_server ! {register_person, - OldHacker#person{name = \"Robert\", + %% The central_register_server should have + %% an interface function for this. + central_register_server ! {register_person, Hacker1}, + central_register_server ! {register_person, + OldHacker#person{name = \"Robert\", phone = [0,8,3,2,4,5,3,1]}}. - ">>, - ?line ok = run_file(Config, recs, Test2), - ok. +">>, + ok = run_file(Config, recs, Test2), +ok. -progex_lc(doc) -> - ["List comprehension examples from Programming Examples. OTP-5237."]; -progex_lc(suite) -> - []; +%% List comprehension examples from Programming Examples. OTP-5237. progex_lc(Config) when is_list(Config) -> Test1 = - <<"-module(lc). + <<"-module(lc). -export([t/0]). - t() -> - [a,4,b,5,6] = [X || X <- [1,2,a,3,4,b,5,6], X > 3], - [4,5,6] = [X || X <- [1,2,a,3,4,b,5,6], integer(X), X > 3], - [{1,a},{1,b},{2,a},{2,b},{3,a},{3,b}] = - [{X, Y} || X <- [1,2,3], Y <- [a,b]], - - [1,2,3,4,5,6,7,8] = sort([4,5,1,8,3,6,7,2]), - [[b,u,g],[b,g,u],[u,b,g],[u,g,b],[g,b,u],[g,u,b]] = - perms([b,u,g]), - [] = pyth(11), - [{3,4,5},{4,3,5}] = pyth(12), - [{3,4,5},{4,3,5},{5,12,13},{6,8,10},{8,6,10},{8,15,17}, - {9,12,15},{12,5,13},{12,9,15},{12,16,20},{15,8,17}, - {16,12,20}] = pyth(50), - [] = pyth1(11), - [{3,4,5},{4,3,5}] = pyth1(12), - [{3,4,5},{4,3,5},{5,12,13},{6,8,10},{8,6,10},{8,15,17}, - {9,12,15},{12,5,13},{12,9,15},{12,16,20},{15,8,17}, - {16,12,20}] = pyth1(50), - [1,2,3,4,5] = append([[1,2,3],[4,5]]), - [2,3,4] = map(fun(X) -> X + 1 end, [1,2,3]), - [2,4] = filter(fun(X) -> X > 1 end, [0,2,4]), - [1,2,3,7] = select(b,[{a,1},{b,2},{c,3},{b,7}]), - [2,7] = select2(b,[{a,1},{b,2},{c,3},{b,7}]), - ok. - - sort([Pivot|T]) -> - sort([ X || X <- T, X < Pivot]) ++ - [Pivot] ++ - sort([ X || X <- T, X >= Pivot]); - sort([]) -> []. - - perms([]) -> [[]]; - perms(L) -> [[H|T] || H <- L, T <- perms(L--[H])]. - - pyth(N) -> - [ {A,B,C} || - A <- lists:seq(1,N), - B <- lists:seq(1,N), - C <- lists:seq(1,N), - A+B+C =< N, - A*A+B*B == C*C - ]. - - pyth1(N) -> - [{A,B,C} || - A <- lists:seq(1,N), - B <- lists:seq(1,N-A+1), - C <- lists:seq(1,N-A-B+2), - A+B+C =< N, - A*A+B*B == C*C ]. - - append(L) -> [X || L1 <- L, X <- L1]. - map(Fun, L) -> [Fun(X) || X <- L]. - filter(Pred, L) -> [X || X <- L, Pred(X)]. - - select(X, L) -> [Y || {X, Y} <- L]. - select2(X, L) -> [Y || {X1, Y} <- L, X == X1]. - ">>, - ?line ok = run_file(Config, lc, Test1), - - Test1_shell = - <<"[a,4,b,5,6] = [X || X <- [1,2,a,3,4,b,5,6], X > 3], - [4,5,6] = [X || X <- [1,2,a,3,4,b,5,6], integer(X), X > 3], - [{1,a},{1,b},{2,a},{2,b},{3,a},{3,b}] = - [{X, Y} || X <- [1,2,3], Y <- [a,b]], - - Sort = fun([Pivot|T], Fn) -> - Fn([ X || X <- T, X < Pivot], Fn) ++ - [Pivot] ++ - Fn([ X || X <- T, X >= Pivot], Fn); - ([], _Fn) -> [] - end, - - [1,2,3,4,5,6,7,8] = Sort([4,5,1,8,3,6,7,2], Sort), - Perms = fun([], _Fn) -> [[]]; - (L, Fn) -> [[H|T] || H <- L, T <- Fn(L--[H], Fn)] - end, - [[b,u,g],[b,g,u],[u,b,g],[u,g,b],[g,b,u],[g,u,b]] = - Perms([b,u,g], Perms), - - Pyth = fun(N) -> - [ {A,B,C} || - A <- lists:seq(1,N), - B <- lists:seq(1,N), - C <- lists:seq(1,N), - A+B+C =< N, - A*A+B*B == C*C - ] - end, - - [] = Pyth(11), - [{3,4,5},{4,3,5}] = Pyth(12), - %[{3,4,5},{4,3,5},{5,12,13},{6,8,10},{8,6,10},{8,15,17}, - % {9,12,15},{12,5,13},{12,9,15},{12,16,20},{15,8,17}, - % {16,12,20}] = Pyth(50), - - Pyth1 = fun(N) -> - [{A,B,C} || - A <- lists:seq(1,N), - B <- lists:seq(1,N-A+1), - C <- lists:seq(1,N-A-B+2), - A+B+C =< N, - A*A+B*B == C*C ] - end, - - [] = Pyth1(11), - [{3,4,5},{4,3,5}] = Pyth1(12), - [{3,4,5},{4,3,5},{5,12,13},{6,8,10},{8,6,10},{8,15,17}, - {9,12,15},{12,5,13},{12,9,15},{12,16,20},{15,8,17}, - {16,12,20}] = Pyth1(50), - - Append = fun(L) -> [X || L1 <- L, X <- L1] end, - [1,2,3,4,5] = Append([[1,2,3],[4,5]]), - Map = fun(Fun, L) -> [Fun(X) || X <- L] end, - [2,3,4] = Map(fun(X) -> X + 1 end, [1,2,3]), - Filter = fun(Pred, L) -> [X || X <- L, Pred(X)] end, - [2,4] = Filter(fun(X) -> X > 1 end, [0,2,4]), - - Select = fun(X, L) -> [Y || {X, Y} <- L] end, - [1,2,3,7] = Select(b,[{a,1},{b,2},{c,3},{b,7}]), - Select2 = fun(X, L) -> [Y || {X1, Y} <- L, X == X1] end, - [2,7] = Select2(b,[{a,1},{b,2},{c,3},{b,7}]), - ok. - ">>, - ?line [ok] = scan(Test1_shell), +t() -> + [a,4,b,5,6] = [X || X <- [1,2,a,3,4,b,5,6], X > 3], + [4,5,6] = [X || X <- [1,2,a,3,4,b,5,6], integer(X), X > 3], + [{1,a},{1,b},{2,a},{2,b},{3,a},{3,b}] = + [{X, Y} || X <- [1,2,3], Y <- [a,b]], + + [1,2,3,4,5,6,7,8] = sort([4,5,1,8,3,6,7,2]), + [[b,u,g],[b,g,u],[u,b,g],[u,g,b],[g,b,u],[g,u,b]] = + perms([b,u,g]), + [] = pyth(11), + [{3,4,5},{4,3,5}] = pyth(12), + [{3,4,5},{4,3,5},{5,12,13},{6,8,10},{8,6,10},{8,15,17}, + {9,12,15},{12,5,13},{12,9,15},{12,16,20},{15,8,17}, + {16,12,20}] = pyth(50), + [] = pyth1(11), + [{3,4,5},{4,3,5}] = pyth1(12), + [{3,4,5},{4,3,5},{5,12,13},{6,8,10},{8,6,10},{8,15,17}, + {9,12,15},{12,5,13},{12,9,15},{12,16,20},{15,8,17}, + {16,12,20}] = pyth1(50), + [1,2,3,4,5] = append([[1,2,3],[4,5]]), + [2,3,4] = map(fun(X) -> X + 1 end, [1,2,3]), + [2,4] = filter(fun(X) -> X > 1 end, [0,2,4]), + [1,2,3,7] = select(b,[{a,1},{b,2},{c,3},{b,7}]), + [2,7] = select2(b,[{a,1},{b,2},{c,3},{b,7}]), ok. -progex_funs(doc) -> - ["Funs examples from Programming Examples. OTP-5237."]; -progex_funs(suite) -> - []; +sort([Pivot|T]) -> + sort([ X || X <- T, X < Pivot]) ++ + [Pivot] ++ + sort([ X || X <- T, X >= Pivot]); +sort([]) -> []. + +perms([]) -> [[]]; +perms(L) -> [[H|T] || H <- L, T <- perms(L--[H])]. + +pyth(N) -> + [ {A,B,C} || + A <- lists:seq(1,N), + B <- lists:seq(1,N), + C <- lists:seq(1,N), + A+B+C =< N, + A*A+B*B == C*C + ]. + +pyth1(N) -> + [{A,B,C} || + A <- lists:seq(1,N), + B <- lists:seq(1,N-A+1), + C <- lists:seq(1,N-A-B+2), + A+B+C =< N, + A*A+B*B == C*C ]. + +append(L) -> [X || L1 <- L, X <- L1]. +map(Fun, L) -> [Fun(X) || X <- L]. +filter(Pred, L) -> [X || X <- L, Pred(X)]. + +select(X, L) -> [Y || {X, Y} <- L]. +select2(X, L) -> [Y || {X1, Y} <- L, X == X1]. +">>, + ok = run_file(Config, lc, Test1), + +Test1_shell = +<<"[a,4,b,5,6] = [X || X <- [1,2,a,3,4,b,5,6], X > 3], + [4,5,6] = [X || X <- [1,2,a,3,4,b,5,6], integer(X), X > 3], + [{1,a},{1,b},{2,a},{2,b},{3,a},{3,b}] = + [{X, Y} || X <- [1,2,3], Y <- [a,b]], + + Sort = fun([Pivot|T], Fn) -> + Fn([ X || X <- T, X < Pivot], Fn) ++ + [Pivot] ++ + Fn([ X || X <- T, X >= Pivot], Fn); + ([], _Fn) -> [] + end, + + [1,2,3,4,5,6,7,8] = Sort([4,5,1,8,3,6,7,2], Sort), + Perms = fun([], _Fn) -> [[]]; + (L, Fn) -> [[H|T] || H <- L, T <- Fn(L--[H], Fn)] + end, + [[b,u,g],[b,g,u],[u,b,g],[u,g,b],[g,b,u],[g,u,b]] = + Perms([b,u,g], Perms), + + Pyth = fun(N) -> + [ {A,B,C} || + A <- lists:seq(1,N), + B <- lists:seq(1,N), + C <- lists:seq(1,N), + A+B+C =< N, + A*A+B*B == C*C + ] + end, + + [] = Pyth(11), + [{3,4,5},{4,3,5}] = Pyth(12), +%%[{3,4,5},{4,3,5},{5,12,13},{6,8,10},{8,6,10},{8,15,17}, +%% {9,12,15},{12,5,13},{12,9,15},{12,16,20},{15,8,17}, +%% {16,12,20}] = Pyth(50), + + Pyth1 = fun(N) -> + [{A,B,C} || + A <- lists:seq(1,N), + B <- lists:seq(1,N-A+1), + C <- lists:seq(1,N-A-B+2), + A+B+C =< N, + A*A+B*B == C*C ] + end, + + [] = Pyth1(11), + [{3,4,5},{4,3,5}] = Pyth1(12), + [{3,4,5},{4,3,5},{5,12,13},{6,8,10},{8,6,10},{8,15,17}, + {9,12,15},{12,5,13},{12,9,15},{12,16,20},{15,8,17}, + {16,12,20}] = Pyth1(50), + + Append = fun(L) -> [X || L1 <- L, X <- L1] end, + [1,2,3,4,5] = Append([[1,2,3],[4,5]]), + Map = fun(Fun, L) -> [Fun(X) || X <- L] end, + [2,3,4] = Map(fun(X) -> X + 1 end, [1,2,3]), + Filter = fun(Pred, L) -> [X || X <- L, Pred(X)] end, + [2,4] = Filter(fun(X) -> X > 1 end, [0,2,4]), + + Select = fun(X, L) -> [Y || {X, Y} <- L] end, + [1,2,3,7] = Select(b,[{a,1},{b,2},{c,3},{b,7}]), + Select2 = fun(X, L) -> [Y || {X1, Y} <- L, X == X1] end, + [2,7] = Select2(b,[{a,1},{b,2},{c,3},{b,7}]), + ok. +">>, + [ok] = scan(Test1_shell), +ok. + +%% Funs examples from Programming Examples. OTP-5237. progex_funs(Config) when is_list(Config) -> Test1 = - <<"-module(funs). + <<"-module(funs). -compile(export_all). - double([H|T]) -> [2*H|double(T)]; - double([]) -> []. +double([H|T]) -> [2*H|double(T)]; +double([]) -> []. - add_one([H|T]) -> [H+1|add_one(T)]; - add_one([]) -> []. +add_one([H|T]) -> [H+1|add_one(T)]; +add_one([]) -> []. - map(F, [H|T]) -> [F(H)|map(F, T)]; - map(F, []) -> []. +map(F, [H|T]) -> [F(H)|map(F, T)]; +map(F, []) -> []. - double2(L) -> map(fun(X) -> 2*X end, L). - add_one2(L) -> map(fun(X) -> 1 + X end, L). +double2(L) -> map(fun(X) -> 2*X end, L). +add_one2(L) -> map(fun(X) -> 1 + X end, L). - print_list(Stream, [H|T]) -> - io:format(Stream, \"~p~n\", [H]), +print_list(Stream, [H|T]) -> + io:format(Stream, \"~p~n\", [H]), print_list(Stream, T); - print_list(Stream, []) -> - true. - - broadcast(Msg, [Pid|Pids]) -> - Pid ! Msg, - broadcast(Msg, Pids); - broadcast(_, []) -> - true. - - foreach(F, [H|T]) -> - F(H), - foreach(F, T); - foreach(F, []) -> - ok. + print_list(Stream, []) -> + true. + +broadcast(Msg, [Pid|Pids]) -> + Pid ! Msg, + broadcast(Msg, Pids); +broadcast(_, []) -> + true. + +foreach(F, [H|T]) -> + F(H), + foreach(F, T); +foreach(F, []) -> + ok. - print_list2(S, L) -> - foreach(fun(H) -> io:format(S, \"~p~n\",[H]) end, L). +print_list2(S, L) -> + foreach(fun(H) -> io:format(S, \"~p~n\",[H]) end, L). broadcast2(M, L) -> foreach(fun(Pid) -> Pid ! M end, L). - t1() -> map(fun(X) -> 2 * X end, [1,2,3,4,5]). +t1() -> map(fun(X) -> 2 * X end, [1,2,3,4,5]). - t2() -> map(fun double/1, [1,2,3,4,5]). +t2() -> map(fun double/1, [1,2,3,4,5]). - t3() -> map({?MODULE, double3}, [1,2,3,4,5]). +t3() -> map({?MODULE, double3}, [1,2,3,4,5]). - double3(X) -> X * 2. +double3(X) -> X * 2. - f(F, Args) when function(F) -> - apply(F, Args); - f(N, _) when integer(N) -> - N. +f(F, Args) when function(F) -> + apply(F, Args); +f(N, _) when integer(N) -> + N. - print_list3(File, List) -> - {ok, Stream} = file:open(File, write), - foreach(fun(X) -> io:format(Stream,\"~p~n\",[X]) end, List), +print_list3(File, List) -> + {ok, Stream} = file:open(File, write), + foreach(fun(X) -> io:format(Stream,\"~p~n\",[X]) end, List), file:close(Stream). - print_list4(File, List) -> - {ok, Stream} = file:open(File, write), - foreach(fun(File) -> - io:format(Stream,\"~p~n\",[File]) +print_list4(File, List) -> + {ok, Stream} = file:open(File, write), + foreach(fun(File) -> + io:format(Stream,\"~p~n\",[File]) end, List), - file:close(Stream). + file:close(Stream). + +any(Pred, [H|T]) -> + case Pred(H) of + true -> true; + false -> any(Pred, T) + end; +any(Pred, []) -> + false. - any(Pred, [H|T]) -> - case Pred(H) of - true -> true; - false -> any(Pred, T) - end; - any(Pred, []) -> - false. - - all(Pred, [H|T]) -> - case Pred(H) of - true -> all(Pred, T); - false -> false - end; - all(Pred, []) -> - true. - - foldl(F, Accu, [Hd|Tail]) -> - foldl(F, F(Hd, Accu), Tail); - foldl(F, Accu, []) -> Accu. - - mapfoldl(F, Accu0, [Hd|Tail]) -> - {R,Accu1} = F(Hd, Accu0), - {Rs,Accu2} = mapfoldl(F, Accu1, Tail), - {[R|Rs], Accu2}; - mapfoldl(F, Accu, []) -> {[], Accu}. - - filter(F, [H|T]) -> - case F(H) of - true -> [H|filter(F, T)]; - false -> filter(F, T) - end; - filter(F, []) -> []. - - diff(L1, L2) -> - filter(fun(X) -> not lists:member(X, L2) end, L1). - - intersection(L1,L2) -> filter(fun(X) -> lists:member(X,L1) end, L2). - - takewhile(Pred, [H|T]) -> - case Pred(H) of - true -> [H|takewhile(Pred, T)]; - false -> [] - end; - takewhile(Pred, []) -> - []. - - dropwhile(Pred, [H|T]) -> - case Pred(H) of - true -> dropwhile(Pred, T); - false -> [H|T] - end; - dropwhile(Pred, []) -> - []. - - splitlist(Pred, L) -> - splitlist(Pred, L, []). - - splitlist(Pred, [H|T], L) -> - case Pred(H) of - true -> splitlist(Pred, T, [H|L]); - false -> {lists:reverse(L), [H|T]} - end; - splitlist(Pred, [], L) -> - {lists:reverse(L), []}. - - first(Pred, [H|T]) -> - case Pred(H) of - true -> - {true, H}; - false -> - first(Pred, T) - end; - first(Pred, []) -> - false. - - ints_from(N) -> - fun() -> - [N|ints_from(N+1)] - end. - - pconst(X) -> - fun (T) -> - case T of - [X|T1] -> {ok, {const, X}, T1}; - _ -> fail - end - end. - - pand(P1, P2) -> - fun (T) -> - case P1(T) of - {ok, R1, T1} -> - case P2(T1) of - {ok, R2, T2} -> - {ok, {'and', R1, R2}}; - fail -> - fail - end; - fail -> - fail - end - end. - - por(P1, P2) -> - fun (T) -> - case P1(T) of - {ok, R, T1} -> - {ok, {'or',1,R}, T1}; - fail -> - case P2(T) of - {ok, R1, T1} -> - {ok, {'or',2,R1}, T1}; - fail -> - fail - end - end - end. - - grammar() -> - pand( - por(pconst(a), pconst(b)), - por(pconst(c), pconst(d))). - - parse(List) -> - (grammar())(List). - - - t() -> - [2,4,6,8] = double([1,2,3,4]), - [2,3,4,5] = add_one([1,2,3,4]), - [2,4,6,8] = double2([1,2,3,4]), - [2,3,4,5] = add_one2([1,2,3,4]), - XX = ints_from(1), - [1 | _] = XX(), - 1 = hd(XX()), - Y = tl(XX()), - 2 = hd(Y()), - - P1 = pconst(a), - {ok,{const,a},[b,c]} = P1([a,b,c]), - fail = P1([x,y,z]), - - {ok,{'and',{'or',1,{const,a}},{'or',1,{const,c}}}} = - parse([a,c]), - {ok,{'and',{'or',1,{const,a}},{'or',2,{const,d}}}} = - parse([a,d]), - {ok,{'and',{'or',2,{const,b}},{'or',1,{const,c}}}} = - parse([b,c]), - {ok,{'and',{'or',2,{const,b}},{'or',2,{const,d}}}} = - parse([b,d]), - fail = parse([a,b]), - ok. - ">>, - ?line ok = run_file(Config, funs, Test1), - - Test2_shell = - <<"Double = fun(X) -> 2 * X end, +all(Pred, [H|T]) -> + case Pred(H) of + true -> all(Pred, T); + false -> false + end; +all(Pred, []) -> + true. + +foldl(F, Accu, [Hd|Tail]) -> + foldl(F, F(Hd, Accu), Tail); +foldl(F, Accu, []) -> Accu. + +mapfoldl(F, Accu0, [Hd|Tail]) -> + {R,Accu1} = F(Hd, Accu0), + {Rs,Accu2} = mapfoldl(F, Accu1, Tail), + {[R|Rs], Accu2}; +mapfoldl(F, Accu, []) -> {[], Accu}. + +filter(F, [H|T]) -> + case F(H) of + true -> [H|filter(F, T)]; + false -> filter(F, T) + end; +filter(F, []) -> []. + +diff(L1, L2) -> + filter(fun(X) -> not lists:member(X, L2) end, L1). + +intersection(L1,L2) -> filter(fun(X) -> lists:member(X,L1) end, L2). + +takewhile(Pred, [H|T]) -> + case Pred(H) of + true -> [H|takewhile(Pred, T)]; + false -> [] + end; +takewhile(Pred, []) -> + []. + +dropwhile(Pred, [H|T]) -> + case Pred(H) of + true -> dropwhile(Pred, T); + false -> [H|T] + end; +dropwhile(Pred, []) -> + []. + +splitlist(Pred, L) -> + splitlist(Pred, L, []). + +splitlist(Pred, [H|T], L) -> + case Pred(H) of + true -> splitlist(Pred, T, [H|L]); + false -> {lists:reverse(L), [H|T]} + end; +splitlist(Pred, [], L) -> + {lists:reverse(L), []}. + +first(Pred, [H|T]) -> + case Pred(H) of + true -> + {true, H}; + false -> + first(Pred, T) + end; +first(Pred, []) -> + false. + +ints_from(N) -> + fun() -> + [N|ints_from(N+1)] + end. + +pconst(X) -> + fun (T) -> + case T of + [X|T1] -> {ok, {const, X}, T1}; + _ -> fail + end + end. + +pand(P1, P2) -> + fun (T) -> + case P1(T) of + {ok, R1, T1} -> + case P2(T1) of + {ok, R2, T2} -> + {ok, {'and', R1, R2}}; + fail -> + fail + end; + fail -> + fail + end + end. + +por(P1, P2) -> + fun (T) -> + case P1(T) of + {ok, R, T1} -> + {ok, {'or',1,R}, T1}; + fail -> + case P2(T) of + {ok, R1, T1} -> + {ok, {'or',2,R1}, T1}; + fail -> + fail + end + end + end. + +grammar() -> + pand( + por(pconst(a), pconst(b)), + por(pconst(c), pconst(d))). + +parse(List) -> + (grammar())(List). + + +t() -> + [2,4,6,8] = double([1,2,3,4]), + [2,3,4,5] = add_one([1,2,3,4]), + [2,4,6,8] = double2([1,2,3,4]), + [2,3,4,5] = add_one2([1,2,3,4]), + XX = ints_from(1), + [1 | _] = XX(), + 1 = hd(XX()), + Y = tl(XX()), + 2 = hd(Y()), + + P1 = pconst(a), + {ok,{const,a},[b,c]} = P1([a,b,c]), + fail = P1([x,y,z]), + + {ok,{'and',{'or',1,{const,a}},{'or',1,{const,c}}}} = + parse([a,c]), + {ok,{'and',{'or',1,{const,a}},{'or',2,{const,d}}}} = + parse([a,d]), + {ok,{'and',{'or',2,{const,b}},{'or',1,{const,c}}}} = + parse([b,c]), + {ok,{'and',{'or',2,{const,b}},{'or',2,{const,d}}}} = + parse([b,d]), + fail = parse([a,b]), + ok. +">>, + ok = run_file(Config, funs, Test1), + +Test2_shell = +<<"Double = fun(X) -> 2 * X end, [2,4,6,8,10] = lists:map(Double, [1,2,3,4,5]), - - Big = fun(X) -> if X > 10 -> true; true -> false end end, - false = lists:any(Big, [1,2,3,4]), - true = lists:any(Big, [1,2,3,12,5]), - false = lists:all(Big, [1,2,3,4,12,6]), - true = lists:all(Big, [12,13,14,15]), - L = [\"I\",\"like\",\"Erlang\"], + + Big = fun(X) -> if X > 10 -> true; true -> false end end, + false = lists:any(Big, [1,2,3,4]), + true = lists:any(Big, [1,2,3,12,5]), + false = lists:all(Big, [1,2,3,4,12,6]), + true = lists:all(Big, [12,13,14,15]), + L = [\"I\",\"like\",\"Erlang\"], 11 = lists:foldl(fun(X, Sum) -> length(X) + Sum end, 0, L), - Upcase = fun(X) when $a =< X, X =< $z -> X + $A - $a; - (X) -> X - end, - Upcase_word = fun(X) -> lists:map(Upcase, X) end, - \"ERLANG\" = Upcase_word(\"Erlang\"), + Upcase = fun(X) when $a =< X, X =< $z -> X + $A - $a; + (X) -> X + end, + Upcase_word = fun(X) -> lists:map(Upcase, X) end, + \"ERLANG\" = Upcase_word(\"Erlang\"), [\"I\",\"LIKE\",\"ERLANG\"] = lists:map(Upcase_word, L), {[\"I\",\"LIKE\",\"ERLANG\"],11} = lists:mapfoldl(fun(Word, Sum) -> - {Upcase_word(Word), Sum + length(Word)} + {Upcase_word(Word), Sum + length(Word)} end, 0, L), - [500,12,45] = lists:filter(Big, [500,12,2,45,6,7]), - [200,500,45] = lists:takewhile(Big, [200,500,45,5,3,45,6]), - [5,3,45,6] = lists:dropwhile(Big, [200,500,45,5,3,45,6]), - {[200,500,45],[5,3,45,6]} = - lists:splitwith(Big, [200,500,45,5,3,45,6]), + [500,12,45] = lists:filter(Big, [500,12,2,45,6,7]), + [200,500,45] = lists:takewhile(Big, [200,500,45,5,3,45,6]), + [5,3,45,6] = lists:dropwhile(Big, [200,500,45,5,3,45,6]), + {[200,500,45],[5,3,45,6]} = + lists:splitwith(Big, [200,500,45,5,3,45,6]), %% {true,45} = lists:first(Big, [1,2,45,6,123]), %% false = lists:first(Big, [1,2,4,5]), - - Adder = fun(X) -> fun(Y) -> X + Y end end, - Add6 = Adder(6), - 16 = Add6(10), - ok. - ">>, - ?line [ok] = scan(Test2_shell), - ok. + + Adder = fun(X) -> fun(Y) -> X + Y end end, + Add6 = Adder(6), + 16 = Add6(10), + ok. +">>, + [ok] = scan(Test2_shell), +ok. -otp_5990(doc) -> - "OTP-5990. {erlang,is_record}."; -otp_5990(suite) -> []; +%% OTP-5990. {erlang,is_record}. otp_5990(Config) when is_list(Config) -> - ?line [true] = + [true] = scan(<<"rd('OrdSet', {orddata = {},ordtype = type}), " "S = #'OrdSet'{ordtype = {}}, " "if tuple(S#'OrdSet'.ordtype) -> true; true -> false end.">>), ok. -otp_6166(doc) -> - "OTP-6166. Order of record definitions."; -otp_6166(suite) -> []; +%% OTP-6166. Order of record definitions. otp_6166(Config) when is_list(Config) -> - Test1 = filename:join(?config(priv_dir, Config), "test1.hrl"), + Test1 = filename:join(proplists:get_value(priv_dir, Config), "test1.hrl"), Contents1 = <<"-module(test1). -record(r5, {f}). -record(r3, {f = #r5{}}). " "-record(r1, {f = #r3{}}). -record(r4, {f = #r1{}}). " - "-record(r2, {f = #r4{}}).">>, - ?line ok = file:write_file(Test1, Contents1), +"-record(r2, {f = #r4{}}).">>, + ok = file:write_file(Test1, Contents1), - Test2 = filename:join(?config(priv_dir, Config), "test2.hrl"), + Test2 = filename:join(proplists:get_value(priv_dir, Config), "test2.hrl"), Contents2 = <<"-module(test2). -record(r5, {f}). -record(r3, {f = #r5{}}). " "-record(r1, {f = #r3{}}). -record(r4, {f = #r1{}}). " "-record(r2, {f = #r4{}}). -record(r6, {f = #r5{}}). % r6 > r0 -record(r0, {f = #r5{}, g = #r5{}}). % r0 < r5">>, - ?line ok = file:write_file(Test2, Contents2), + ok = file:write_file(Test2, Contents2), RR12 = "[r1,r2,r3,r4,r5] = rr(\"" ++ Test1 ++ "\"), [r0,r1,r2,r3,r4,r5,r6] = rr(\"" ++ Test2 ++ "\"), @@ -2317,74 +2247,72 @@ otp_6166(Config) when is_list(Config) -> true = is_record(R0, r0), true = is_record(R6, r6), ok. ", - ?line [ok] = scan(RR12), + [ok] = scan(RR12), file:delete(Test1), file:delete(Test2), ok. -otp_6554(doc) -> - "OTP-6554. Formatted exits and error messages."; -otp_6554(suite) -> []; +%% OTP-6554. Formatted exits and error messages. otp_6554(Config) when is_list(Config) -> %% Should check the stacktrace as well... - ?line "exception error: bad argument" = + "exception error: bad argument" = comm_err(<<"math:sqrt(a).">>), - ?line "exception error: bad argument" = + "exception error: bad argument" = comm_err(<<"fun(X, Y) -> X ++ Y end(a, b).">>), - ?line "exception error: bad argument" = + "exception error: bad argument" = comm_err(<<"math:sqrt(lists:seq(1,40)).">>), - ?line "exception error: bad argument" = + "exception error: bad argument" = comm_err(<<"math:sqrt(lists:seq(1,10)).">>), - ?line "exception error: bad argument" = + "exception error: bad argument" = comm_err(<<"a ++ b.">>), - ?line "exception error: bad argument" = + "exception error: bad argument" = comm_err(<<"I = {file_info,undefined,undefined,undefined,undefined, undefined,undefined,undefined,undefined,undefined, undefined,undefined,undefined,undefined}, aa ++ I.">>), - ?line "exception error: bad argument" = + "exception error: bad argument" = comm_err(<<"I = {file_info,undefined,undefined,undefined,undefined, undefined,undefined,undefined,undefined,undefined, undefined,undefined,undefined,undefined}, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ++ I.">>), - ?line "exception error: bad argument" = + "exception error: bad argument" = comm_err(<<"I = {file_info,undefined,undefined,undefined,undefined, undefined,undefined,undefined,undefined,undefined, undefined,undefined,undefined,undefined}, I ++ I.">>), - ?line "exception error: bad argument" = + "exception error: bad argument" = comm_err(<<"fun(X) -> not X end(a).">>), - ?line "exception error: bad argument: a" = + "exception error: bad argument: a" = comm_err(<<"fun(A, B) -> A orelse B end(a, b).">>), - ?line "exception error: an error occurred when evaluating an arithmetic expression" = + "exception error: an error occurred when evaluating an arithmetic expression" = comm_err(<<"math:sqrt(2)/round(math:sqrt(0)).">>), - ?line "exception error: interpreted function with arity 1 called with no arguments" = + "exception error: interpreted function with arity 1 called with no arguments" = comm_err(<<"fun(V) -> V end().">>), - ?line "exception error: interpreted function with arity 1 called with two arguments" = + "exception error: interpreted function with arity 1 called with two arguments" = comm_err(<<"fun(V) -> V end(1,2).">>), - ?line "exception error: interpreted function with arity 0 called with one argument" = + "exception error: interpreted function with arity 0 called with one argument" = comm_err(<<"fun() -> v end(1).">>), - ?line "exception error: interpreted function with arity 0 called with 4 arguments" = + "exception error: interpreted function with arity 0 called with 4 arguments" = comm_err(<<"fun() -> v end(1,2,3,4).">>), - ?line "exception error: math:sqrt/1 called with two arguments" = + "exception error: math:sqrt/1 called with two arguments" = comm_err(<<"fun math:sqrt/1(1,2).">>), - ?line "exception error: bad function 1." ++ _ = + "exception error: bad function 1." ++ _ = comm_err(<<"(math:sqrt(2))().">>), - ?line "exception error: bad function [1," ++ _ = + "exception error: bad function [1," ++ _ = comm_err(<<"(lists:seq(1, 100))().">>), - ?line "exception error: no match of right hand side value 1" ++ _ = + "exception error: no match of right hand side value 1" ++ _ = comm_err(<<"a = math:sqrt(2).">>), - ?line "exception error: no match of right hand side value" ++ _ = + "exception error: no match of right hand side value" ++ _ = comm_err(<<"I = {file_info,undefined,undefined,undefined,undefined, undefined,undefined,undefined,undefined,undefined, undefined,undefined,undefined,undefined}, a = I.">>), - ?line "exception error: no case clause matching 1" ++ _ = + "exception error: no case clause matching 1" ++ _ = comm_err(<<"case math:sqrt(2) of a -> ok end.">>), - ?line "exception error: no case clause matching [1," ++ _ = + "exception error: no case clause matching [1," ++ _ = comm_err(<<"V = lists:seq(1, 20), case V of a -> ok end.">>), - ?line "exception error: no function clause matching" = + "exception error: no function clause matching" = comm_err(<<"fun(P) when is_pid(P) -> true end(a).">>), case test_server:is_native(erl_eval) of true -> @@ -2406,68 +2334,68 @@ otp_6554(Config) when is_list(Config) -> "lists:reverse(34) (lists.erl, line " ++ _ = comm_err(<<"lists:reverse(34).">>) end, - ?line "exception error: function_clause" = + "exception error: function_clause" = comm_err(<<"erlang:error(function_clause, 4).">>), - ?line "exception error: no function clause matching" ++ _ = + "exception error: no function clause matching" ++ _ = comm_err(<<"fun(a, b, c, d) -> foo end" " (lists:seq(1,17)," " lists:seq(1, 18)," " lists:seq(1, 40)," " lists:seq(1, 5)).">>), - ?line "exception error: no function clause matching" = + "exception error: no function clause matching" = comm_err(<<"fun(P, q) when is_pid(P) -> true end(a, b).">>), - ?line "exception error: no true branch found when evaluating an if expression" = + "exception error: no true branch found when evaluating an if expression" = comm_err(<<"if length([a,b]) > 17 -> a end.">>), - ?line "exception error: no such process or port" = + "exception error: no such process or port" = comm_err(<<"Pid = spawn(fun() -> a end)," "timer:sleep(1)," "link(Pid).">>), - ?line "exception error: a system limit has been reached" = + "exception error: a system limit has been reached" = comm_err(<<"list_to_atom(lists:duplicate(300,$a)).">>), - ?line "exception error: bad receive timeout value" = + "exception error: bad receive timeout value" = comm_err(<<"receive after a -> foo end.">>), - ?line "exception error: no try clause matching 1" ++ _ = + "exception error: no try clause matching 1" ++ _ = comm_err(<<"try math:sqrt(2) of bar -> yes after 3 end.">>), - ?line "exception error: no try clause matching [1" ++ _ = + "exception error: no try clause matching [1" ++ _ = comm_err(<<"V = lists:seq(1, 20)," "try V of bar -> yes after 3 end.">>), - ?line "exception error: undefined function math:sqrt/2" = + "exception error: undefined function math:sqrt/2" = comm_err(<<"math:sqrt(2, 2).">>), - ?line "exception error: limit of number of arguments to interpreted function " + "exception error: limit of number of arguments to interpreted function " "exceeded" = comm_err(<<"fun(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U) ->" " a end().">>), - ?line "exception error: bad filter a" = + "exception error: bad filter a" = comm_err(<<"[b || begin a end].">>), - ?line "exception error: bad generator a" = + "exception error: bad generator a" = comm_err(<<"[X || X <- a].">>), - ?line "exception throw: undef" = comm_err(<<"throw(undef).">>), - ?line "exception exit: undef" = comm_err(<<"exit(undef).">>), + "exception throw: undef" = comm_err(<<"throw(undef).">>), + "exception exit: undef" = comm_err(<<"exit(undef).">>), - ?line "exception exit: foo" = + "exception exit: foo" = comm_err(<<"catch spawn_link(fun() ->" " timer:sleep(300), exit(foo) " " end)," "timer:sleep(500).">>), - ?line [ok] = scan( + [ok] = scan( <<"begin process_flag(trap_exit, true)," " Pid = spawn_link(fun() ->" " timer:sleep(300), exit(foo) " " end)," " timer:sleep(500)," " receive {'EXIT', Pid, foo} -> ok end end.">>), - ?line "exception exit: badarith" = + "exception exit: badarith" = comm_err(<<"catch spawn_link(fun() ->" " timer:sleep(300), 1/0 " " end)," "timer:sleep(500).">>), - ?line "exception exit: {nocatch,foo}" = + "exception exit: {nocatch,foo}" = comm_err(<<"catch spawn_link(fun() ->" " timer:sleep(300), throw(foo) " " end)," "timer:sleep(500).">>), - ?line [ok] = scan( + [ok] = scan( <<"begin process_flag(trap_exit, true)," " Pid = spawn_link(fun() ->" " timer:sleep(300), throw(foo) " @@ -2476,37 +2404,37 @@ otp_6554(Config) when is_list(Config) -> " receive {'EXIT', Pid, {{nocatch,foo},_}} -> ok end " "end.">>), - ?line "exception error: an error occurred when evaluating an arithmetic expression" = + "exception error: an error occurred when evaluating an arithmetic expression" = comm_err(<<"begin catch_exception(true), 1/0 end.">>), - ?line "exception error: an error occurred when evaluating an arithmetic expression" = + "exception error: an error occurred when evaluating an arithmetic expression" = comm_err(<<"begin catch_exception(false), 1/0 end.">>), - ?line "exception error: no function clause matching call to catch_exception/1" = + "exception error: no function clause matching call to catch_exception/1" = comm_err(<<"catch_exception(1).">>), %% A bug was corrected (expansion of 'try'): - ?line "2: command not found" = + "2: command not found" = comm_err(<<"try 1 of 1 -> v(2) after 3 end.">>), %% Cover a few lines: - ?line "3: command not found" = + "3: command not found" = comm_err(<<"receive foo -> foo after 0 -> v(3) end.">>), - ?line "3: command not found" = + "3: command not found" = comm_err(<<"receive foo -> foo after 0 -> e(3) end.">>), - ?line "1 / 0: command not found" = comm_err(<<"v(1/0).">>), - ?line "1\n1.\n" = t(<<"1. e(1).">>), - ?line [ok] = scan(<<"h().">>), - ?line "exception exit: normal" = comm_err(<<"exit(normal).">>), - ?line [foo] = scan(<<"begin history(0), foo end.">>), - ?line application:unset_env(stdlib, shell_history_length), - ?line [true] = scan(<<"begin <<10:(1024*1024*10)>>," + "1 / 0: command not found" = comm_err(<<"v(1/0).">>), + "1\n1.\n" = t(<<"1. e(1).">>), + [ok] = scan(<<"h().">>), + "exception exit: normal" = comm_err(<<"exit(normal).">>), + [foo] = scan(<<"begin history(0), foo end.">>), + application:unset_env(stdlib, shell_history_length), + [true] = scan(<<"begin <<10:(1024*1024*10)>>," "<<10:(1024*1024*10)>>, garbage_collect() end.">>), - ?line "1: syntax error before: '.'" = comm_err("1-."), - %% ?line comm_err(<<"exit().">>), % would hang - ?line "exception error: no function clause matching call to history/1" = + "1: syntax error before: '.'" = comm_err("1-."), + %% comm_err(<<"exit().">>), % would hang + "exception error: no function clause matching call to history/1" = comm_err(<<"history(foo).">>), - ?line "exception error: no function clause matching call to results/1" = + "exception error: no function clause matching call to results/1" = comm_err(<<"results(foo).">>), - ?line Test = filename:join(?config(priv_dir, Config), + Test = filename:join(proplists:get_value(priv_dir, Config), "otp_6554.erl"), Contents = <<"-module(otp_6554). -export([local_allowed/3, non_local_allowed/3]). @@ -2516,31 +2444,31 @@ otp_6554(Config) when is_list(Config) -> non_local_allowed(_,_,State) -> {true,State}. ">>, - ?line ok = compile_file(Config, Test, Contents, []), - ?line "exception exit: restricted shell starts now" = + ok = compile_file(Config, Test, Contents, []), + "exception exit: restricted shell starts now" = comm_err(<<"begin shell:start_restricted(otp_6554) end.">>), - ?line "-record(r,{}).\n1.\nok.\n" = + "-record(r,{}).\n1.\nok.\n" = t(<<"f(), f(B), h(), b(), history(20), results(20)," "rd(r, {}), rl(r), rf('_'), rl(), rf()," "rp(1), _ = rr({foo}), _ = rr({foo}, [])," "rr({foo}, [], []), ok.">>), - ?line "false.\n" = t(<<"catch_exception(true).">>), - ?line "exception exit: restricted shell stopped"= + "false.\n" = t(<<"catch_exception(true).">>), + "exception exit: restricted shell stopped"= comm_err(<<"begin shell:stop_restricted() end.">>), - ?line "true.\n" = t(<<"catch_exception(false).">>), + "true.\n" = t(<<"catch_exception(false).">>), - ?line "20\n1\n1\n1: results(2)\n2: 1\n-> 1\n3: v(2)\n-> 1.\nok.\n" = + "20\n1\n1\n1: results(2)\n2: 1\n-> 1\n3: v(2)\n-> 1.\nok.\n" = t(<<"results(2). 1. v(2). h().">>), - ?line application:unset_env(stdlib, shell_saved_results), - ?line "1\nfoo\n17\nB = foo\nC = 17\nF = fun() ->\n foo" + application:unset_env(stdlib, shell_saved_results), + "1\nfoo\n17\nB = foo\nC = 17\nF = fun() ->\n foo" "\n end.\nok.\n" = t(<<"begin F = fun() -> foo end, 1 end. B = F(). C = 17. b().">>), - ?line "3: command not found" = comm_err(<<"#{v(3) => v}.">>), - ?line "3: command not found" = comm_err(<<"#{k => v(3)}.">>), - ?line "3: command not found" = comm_err(<<"#{v(3) := v}.">>), - ?line "3: command not found" = comm_err(<<"#{k := v(3)}.">>), - ?line "3: command not found" = comm_err(<<"(v(3))#{}.">>), + "3: command not found" = comm_err(<<"#{v(3) => v}.">>), + "3: command not found" = comm_err(<<"#{k => v(3)}.">>), + "3: command not found" = comm_err(<<"#{v(3) := v}.">>), + "3: command not found" = comm_err(<<"#{k := v(3)}.">>), + "3: command not found" = comm_err(<<"(v(3))#{}.">>), %% Tests I'd like to do: (you should try them manually) %% "catch spawn_link(fun() -> timer:sleep(1000), exit(foo) end)." %% "** exception error: foo" should be output after 1 second @@ -2552,12 +2480,10 @@ otp_6554(Config) when is_list(Config) -> ok. -otp_7184(doc) -> - "OTP-7184. Propagate exit signals from dying evaluator process."; -otp_7184(suite) -> []; +%% OTP-7184. Propagate exit signals from dying evaluator process. otp_7184(Config) when is_list(Config) -> register(otp_7184, self()), - ?line catch + catch t(<<"P = self(), spawn_link(fun() -> process_flag(trap_exit,true), P ! up, @@ -2569,7 +2495,7 @@ otp_7184(Config) when is_list(Config) -> erlang:raise(throw, thrown, []).">>), receive {otp_7184,{'EXIT',_,{{nocatch,thrown},[]}}} -> ok end, - ?line catch + catch t(<<"P = self(), spawn_link(fun() -> process_flag(trap_exit,true), P ! up, @@ -2581,7 +2507,7 @@ otp_7184(Config) when is_list(Config) -> erlang:raise(exit, fini, []).">>), receive {otp_7184,{'EXIT',_,{fini,[]}}} -> ok end, - ?line catch + catch t(<<"P = self(), spawn_link(fun() -> process_flag(trap_exit,true), P ! up, @@ -2596,18 +2522,16 @@ otp_7184(Config) when is_list(Config) -> unregister(otp_7184), %% v/1, a few missed cases - ?line "17\n<<0,0,0,64>>.\nok.\n" = + "17\n<<0,0,0,64>>.\nok.\n" = t(<<"17. " "<<64:32>>. " "<<64>> = << << X >> || << X >> <= v(2), X > v(1) >>, ok.">>), - ?line "17\n<<0,17>>.\n" =t(<<"17. <<(v(1)):16>>.">>), + "17\n<<0,17>>.\n" =t(<<"17. <<(v(1)):16>>.">>), ok. -otp_7232(doc) -> - "OTP-7232. qlc:info() bug."; -otp_7232(suite) -> []; +%% OTP-7232. qlc:info() bug. otp_7232(Config) when is_list(Config) -> Info = <<"qlc:info(qlc:sort(qlc:q([X || X <- [55296,56296]]), " "{order, fun(A,B)-> A>B end})).">>, @@ -2618,24 +2542,22 @@ otp_7232(Config) when is_list(Config) -> " end}])" = evaluate(Info, []), ok. -otp_8393(doc) -> - "OTP-8393. Prompt string."; -otp_8393(suite) -> []; +%% OTP-8393. Prompt string. otp_8393(Config) when is_list(Config) -> - ?line _ = shell:prompt_func(default), - ?line "Bad prompt function: '> '" = + _ = shell:prompt_func(default), + "Bad prompt function: '> '" = prompt_err(<<"shell:prompt_func('> ').">>), - ?line _ = shell:prompt_func(default), - ?line "exception error: an error occurred when evaluating an arithmetic expression"++_ = + _ = shell:prompt_func(default), + "exception error: an error occurred when evaluating an arithmetic expression"++_ = prompt_err(<<"shell:prompt_func({shell_SUITE,prompt4}).">>), - ?line _ = shell:prompt_func(default), - ?line "default.\n" = + _ = shell:prompt_func(default), + "default.\n" = t(<<"shell:prompt_func({shell_SUITE,prompt2}).">>), - ?line _ = shell:prompt_func(default), - ?line "default\nl.\n" = + _ = shell:prompt_func(default), + "default\nl.\n" = t(<<"shell:prompt_func({shell_SUITE,prompt3}). l.">>), %% @@ -2644,8 +2566,8 @@ otp_8393(Config) when is_list(Config) -> %% That is instead tested in the io_proto_SUITE, which has %% the right infrastructure in place for such tests. /PaN %% - ?line _ = shell:prompt_func(default), - ?line "default\nl.\n" = + _ = shell:prompt_func(default), + "default\nl.\n" = t(<<"shell:prompt_func({shell_SUITE,prompt5}). l.">>), %% Restricted shell. @@ -2663,30 +2585,30 @@ otp_8393(Config) when is_list(Config) -> non_local_allowed(_,_,State) -> {false,State}. ">>, - ?line Test = filename:join(?config(priv_dir, Config), + Test = filename:join(proplists:get_value(priv_dir, Config), "test_restricted_shell.erl"), - ?line ok = compile_file(Config, Test, Contents, []), - ?line _ = shell:prompt_func(default), - ?line "exception exit: restricted shell starts now" = + ok = compile_file(Config, Test, Contents, []), + _ = shell:prompt_func(default), + "exception exit: restricted shell starts now" = comm_err(<<"begin shell:start_restricted(" "test_restricted_shell) end.">>), - ?line "default.\n"++_ = + "default.\n"++_ = t(<<"shell:prompt_func({shell_SUITE,prompt1}).">>), - ?line "exception exit: restricted shell does not allow apple(" ++ _ = + "exception exit: restricted shell does not allow apple(" ++ _ = comm_err(<<"apple(1).">>), - ?line "{shell_SUITE,prompt1}.\n" = + "{shell_SUITE,prompt1}.\n" = t(<<"shell:prompt_func(default).">>), - ?line "exception exit: restricted shell stopped"= + "exception exit: restricted shell stopped"= comm_err(<<"begin shell:stop_restricted() end.">>), - ?line undefined = + undefined = application:get_env(stdlib, restricted_shell), - ?line NR = shell:results(20), - ?line "default\n20.\n" = + NR = shell:results(20), + "default\n20.\n" = t(<<"shell:prompt_func({shell_SUITE,prompt3}). results(0).">>), - ?line _ = shell:prompt_func(default), - ?line 0 = shell:results(NR), + _ = shell:prompt_func(default), + 0 = shell:results(NR), ok. prompt1(_L) -> @@ -2747,12 +2669,10 @@ prompt_err(B) -> S = string:strip(S2, both, $"), string:strip(S, right, $.). -otp_10302(doc) -> - "OTP-10302. Unicode."; -otp_10302(suite) -> []; +%% OTP-10302. Unicode. otp_10302(Config) when is_list(Config) -> {ok,Node} = start_node(shell_suite_helper_2, - "-pa "++?config(priv_dir,Config)++ + "-pa "++proplists:get_value(priv_dir,Config)++ " +pc unicode"), Test1 = <<"begin @@ -3097,9 +3017,9 @@ run_file(Config, Module, Test) -> ok. compile_file(Config, File, Test, Opts0) -> - ?line Opts = [export_all,return,{outdir,?config(priv_dir, Config)}|Opts0], - ?line ok = file:write_file(File, Test), - ?line case compile:file(File, Opts) of + Opts = [export_all,return,{outdir,proplists:get_value(priv_dir, Config)}|Opts0], + ok = file:write_file(File, Test), + case compile:file(File, Opts) of {ok, _M, _Ws} -> ok; _ -> error end. @@ -3107,10 +3027,10 @@ compile_file(Config, File, Test, Opts0) -> filename(Name, Config) when is_atom(Name) -> filename(atom_to_list(Name), Config); filename(Name, Config) -> - filename:join(?config(priv_dir, Config), Name). + filename:join(proplists:get_value(priv_dir, Config), Name). start_node(Name, Xargs) -> - ?line N = test_server:start_node(Name, slave, [{args, " " ++ Xargs}]), + N = test_server:start_node(Name, slave, [{args, " " ++ Xargs}]), global:sync(), N. diff --git a/lib/stdlib/test/slave_SUITE.erl b/lib/stdlib/test/slave_SUITE.erl index f01bf77550..dc14e4735a 100644 --- a/lib/stdlib/test/slave_SUITE.erl +++ b/lib/stdlib/test/slave_SUITE.erl @@ -29,7 +29,9 @@ -export([fun_init/1, test_errors/1]). -export([timeout_test/1, auth_test/1, rsh_test/1, start_a_slave/3]). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [t_start_link, start_link_nodedown, t_start, errors]. @@ -50,30 +52,27 @@ end_per_group(_GroupName, Config) -> Config. -t_start_link(suite) -> []; t_start_link(Config) when is_list(Config) -> - ?line Dog = test_server:timetrap(test_server:seconds(20)), - %% Define useful variables. - ?line Host = host(), - ?line Slave1 = node_name(Host, slave1), - ?line Slave2 = node_name(Host, slave2), + Host = host(), + Slave1 = node_name(Host, slave1), + Slave2 = node_name(Host, slave2), %% Test slave:start_link() with one, two, and three arguments. - ?line ThisNode = node(), - ?line {error, {already_running, ThisNode}} = slave:start_link(Host), - ?line {ok, Slave1} = slave:start_link(Host, slave1), - ?line {ok, Slave2} = slave:start_link(Host, slave2, "-my_option 42"), - ?line {ok, [["42"]]} = rpc:call(Slave2, init, get_argument, [my_option]), + ThisNode = node(), + {error, {already_running, ThisNode}} = slave:start_link(Host), + {ok, Slave1} = slave:start_link(Host, slave1), + {ok, Slave2} = slave:start_link(Host, slave2, "-my_option 42"), + {ok, [["42"]]} = rpc:call(Slave2, init, get_argument, [my_option]), %% Kill the two slave nodes and verify that they are dead. - ?line rpc:cast(Slave1, erlang, halt, []), - ?line rpc:cast(Slave2, erlang, halt, []), - ?line is_dead(Slave1), - ?line is_dead(Slave2), + rpc:cast(Slave1, erlang, halt, []), + rpc:cast(Slave2, erlang, halt, []), + is_dead(Slave1), + is_dead(Slave2), %% Start two slave nodes from another process and verify that %% the slaves die when that process terminates. @@ -85,41 +84,36 @@ t_start_link(Config) when is_list(Config) -> Parent ! slaves_started, receive never -> ok end end), - ?line receive slaves_started -> ok end, - ?line process_flag(trap_exit, true), - ?line wait_alive(Slave1), - ?line wait_alive(Slave2), - ?line exit(Pid, kill), - ?line receive {'EXIT', Pid, killed} -> ok end, - ?line test_server:sleep(250), - ?line is_dead(Slave1), - ?line is_dead(Slave2), - - ?line test_server:timetrap_cancel(Dog), + receive slaves_started -> ok end, + process_flag(trap_exit, true), + wait_alive(Slave1), + wait_alive(Slave2), + exit(Pid, kill), + receive {'EXIT', Pid, killed} -> ok end, + ct:sleep(250), + is_dead(Slave1), + is_dead(Slave2), + ok. %% Test that slave:start_link() works when the master exits. -start_link_nodedown(suite) -> []; start_link_nodedown(Config) when is_list(Config) -> - ?line Dog = test_server:timetrap(test_server:seconds(20)), - %% Define useful variables. - ?line Host = host(), - ?line Master = node_name(Host, my_master), - ?line Slave = node_name(Host, my_slave), + Host = host(), + Master = node_name(Host, my_master), + Slave = node_name(Host, my_slave), + + Pa = "-pa " ++ filename:dirname(code:which(?MODULE)), + {ok, Master} = slave:start_link(Host, my_master, Pa), + spawn(Master, ?MODULE, start_a_slave, [self(), Host, my_slave]), + {reply, {ok, _Node}} = receive Any -> Any end, - ?line Pa = "-pa " ++ filename:dirname(code:which(?MODULE)), - ?line {ok, Master} = slave:start_link(Host, my_master, Pa), - ?line spawn(Master, ?MODULE, start_a_slave, [self(), Host, my_slave]), - ?line {reply, {ok, _Node}} = receive Any -> Any end, - - ?line rpc:call(Master, erlang, halt, []), - ?line receive after 200 -> ok end, - ?line pang = net_adm:ping(Slave), + rpc:call(Master, erlang, halt, []), + receive after 200 -> ok end, + pang = net_adm:ping(Slave), - ?line test_server:timetrap_cancel(Dog), ok. start_a_slave(ReplyTo, Host, Name) -> @@ -128,82 +122,74 @@ start_a_slave(ReplyTo, Host, Name) -> %% Test slave:start(). -t_start(suite) -> []; t_start(Config) when is_list(Config) -> - ?line Dog = test_server:timetrap(test_server:seconds(20)), - %% Define useful variables. - ?line Host = host(), - ?line Slave1 = node_name(Host, slave1), - ?line Slave2 = node_name(Host, slave2), + Host = host(), + Slave1 = node_name(Host, slave1), + Slave2 = node_name(Host, slave2), %% By running all tests from this master node which is linked %% to this test case, we ensure that all slaves are killed %% if this test case fails. (If they are not, and therefore further %% test cases fail, there is a bug in slave.) - ?line {ok, Master} = slave:start_link(Host, master), - + {ok, Master} = slave:start_link(Host, master), + %% Test slave:start() with one, two, and three arguments. - ?line ThisNode = node(), - ?line {error, {already_running, ThisNode}} = slave:start(Host), - ?line {ok, Slave1} = rpc:call(Master, slave, start, [Host, slave1]), - ?line {ok, Slave2} = rpc:call(Master, slave, start, - [Host, slave2, "-my_option 42"]), - ?line {ok, [["42"]]} = rpc:call(Slave2, init, get_argument, [my_option]), + ThisNode = node(), + {error, {already_running, ThisNode}} = slave:start(Host), + {ok, Slave1} = rpc:call(Master, slave, start, [Host, slave1]), + {ok, Slave2} = rpc:call(Master, slave, start, + [Host, slave2, "-my_option 42"]), + {ok, [["42"]]} = rpc:call(Slave2, init, get_argument, [my_option]), %% Test that a slave terminates when its master node terminates. - ?line ok = slave:stop(Slave2), - ?line is_dead(Slave2), - ?line {ok, Slave2} = rpc:call(Slave1, slave, start, [Host, slave2]), - ?line is_alive(Slave2), - ?line rpc:call(Slave1, erlang, halt, []), % Kill master. + ok = slave:stop(Slave2), + is_dead(Slave2), + {ok, Slave2} = rpc:call(Slave1, slave, start, [Host, slave2]), + is_alive(Slave2), + rpc:call(Slave1, erlang, halt, []), % Kill master. receive after 1000 -> ok end, % Make sure slaves have noticed % their dead master. - ?line is_dead(Slave1), - ?line is_dead(Slave2), % Slave should be dead, too. + is_dead(Slave1), + is_dead(Slave2), % Slave should be dead, too. %% Kill all slaves and verify that they are dead. - ?line ok = slave:stop(Slave1), - ?line ok = slave:stop(Slave2), - ?line is_dead(Slave1), - ?line is_dead(Slave2), + ok = slave:stop(Slave1), + ok = slave:stop(Slave2), + is_dead(Slave1), + is_dead(Slave2), - ?line test_server:timetrap_cancel(Dog), ok. %% Test the various error conditions in parallell (since the timeout %% in slave is 32 seconds). -errors(suite) -> []; errors(Config) when is_list(Config) -> - ?line Dog = test_server:timetrap(test_server:seconds(50)), - - ?line process_flag(trap_exit, true), - ?line Pa = filename:dirname(code:which(?MODULE)), - ?line {ok, Master} = slave_start_link(host(), master, - "-rsh no_rsh_program -pa "++Pa++ - " -env ERL_CRASH_DUMP erl_crash_dump.master"), - ?line Pids = rpc:call(Master, ?MODULE, test_errors, [self()]), - ?line wait_for_result(Pids), + process_flag(trap_exit, true), + Pa = filename:dirname(code:which(?MODULE)), + {ok, Master} = slave_start_link(host(), master, + "-rsh no_rsh_program -pa "++Pa++ + " -env ERL_CRASH_DUMP erl_crash_dump.master"), + Pids = rpc:call(Master, ?MODULE, test_errors, [self()]), + wait_for_result(Pids), - ?line test_server:timetrap_cancel(Dog), ok. wait_for_result([]) -> ok; wait_for_result(Pids) -> - ?line receive - {'EXIT', Pid, normal} -> - io:format("Process ~p terminated", [Pid]), - wait_for_result(lists:delete(Pid, Pids)); - {'EXIT', _, Reason} -> - exit(Reason) - end. + receive + {'EXIT', Pid, normal} -> + io:format("Process ~p terminated", [Pid]), + wait_for_result(lists:delete(Pid, Pids)); + {'EXIT', _, Reason} -> + exit(Reason) + end. show_process_info(Pid) -> io:format("~p: ~p", [Pid, catch process_info(Pid, initial_call)]). @@ -211,25 +197,25 @@ show_process_info(Pid) -> test_errors(ResultTo) -> %% Sigh! We use ordinary spawn instead of fun_spawn/1 to be able %% identify the processes by their initial call. - ?line P1 = spawn(?MODULE, timeout_test, [ResultTo]), - ?line P2 = spawn(?MODULE, auth_test, [ResultTo]), - ?line P3 = spawn(?MODULE, rsh_test, [ResultTo]), + P1 = spawn(?MODULE, timeout_test, [ResultTo]), + P2 = spawn(?MODULE, auth_test, [ResultTo]), + P3 = spawn(?MODULE, rsh_test, [ResultTo]), Pids =[P1, P2, P3], - ?line lists:foreach(fun show_process_info/1, Pids), + lists:foreach(fun show_process_info/1, Pids), Pids. timeout_test(ResultTo) -> link(ResultTo), - ?line {error, timeout} = slave:start(host(), slave1, "-boot no_boot_script"). + {error, timeout} = slave:start(host(), slave1, "-boot no_boot_script"). auth_test(ResultTo) -> link(ResultTo), - ?line {error, timeout} = slave:start(host(), slave2, - "-setcookie definitely_not_a_cookie"). + {error, timeout} = slave:start(host(), slave2, + "-setcookie definitely_not_a_cookie"). rsh_test(ResultTo) -> link(ResultTo), - ?line {error, no_rsh} = slave:start(super, slave3). + {error, no_rsh} = slave:start(super, slave3). %%% Utilities. @@ -239,7 +225,7 @@ wait_alive(Node) -> wait_alive_1(10, Node). wait_alive_1(0, Node) -> - ?t:fail({still_not_alive,Node}); + ct:fail({still_not_alive,Node}); wait_alive_1(N, Node) -> case rpc:call(Node, init, get_status, []) of {started,_} -> diff --git a/lib/stdlib/test/sofs_SUITE.erl b/lib/stdlib/test/sofs_SUITE.erl index 9eed2893d4..2277b2d6fb 100644 --- a/lib/stdlib/test/sofs_SUITE.erl +++ b/lib/stdlib/test/sofs_SUITE.erl @@ -19,7 +19,7 @@ %% -module(sofs_SUITE). -%-define(debug, true). +%%-define(debug, true). -ifdef(debug). -define(format(S, A), io:format(S, A)). @@ -35,28 +35,28 @@ init_per_group/2,end_per_group/2]). -export([ from_term_1/1, set_1/1, from_sets_1/1, relation_1/1, - a_function_1/1, family_1/1, projection/1, - relation_to_family_1/1, domain_1/1, range_1/1, image/1, - inverse_image/1, inverse_1/1, converse_1/1, no_elements_1/1, - substitution/1, restriction/1, drestriction/1, - strict_relation_1/1, extension/1, weak_relation_1/1, - to_sets_1/1, specification/1, union_1/1, intersection_1/1, - difference/1, symdiff/1, symmetric_partition/1, - is_sofs_set_1/1, is_set_1/1, is_equal/1, is_subset/1, - is_a_function_1/1, is_disjoint/1, join/1, canonical/1, - composite_1/1, relative_product_1/1, relative_product_2/1, - product_1/1, partition_1/1, partition_3/1, - multiple_relative_product/1, digraph/1, constant_function/1, - misc/1]). + a_function_1/1, family_1/1, projection/1, + relation_to_family_1/1, domain_1/1, range_1/1, image/1, + inverse_image/1, inverse_1/1, converse_1/1, no_elements_1/1, + substitution/1, restriction/1, drestriction/1, + strict_relation_1/1, extension/1, weak_relation_1/1, + to_sets_1/1, specification/1, union_1/1, intersection_1/1, + difference/1, symdiff/1, symmetric_partition/1, + is_sofs_set_1/1, is_set_1/1, is_equal/1, is_subset/1, + is_a_function_1/1, is_disjoint/1, join/1, canonical/1, + composite_1/1, relative_product_1/1, relative_product_2/1, + product_1/1, partition_1/1, partition_3/1, + multiple_relative_product/1, digraph/1, constant_function/1, + misc/1]). -export([ family_specification/1, - family_domain_1/1, family_range_1/1, - family_to_relation_1/1, - union_of_family_1/1, intersection_of_family_1/1, - family_projection/1, family_difference/1, - family_intersection_1/1, family_union_1/1, - family_intersection_2/1, family_union_2/1, - partition_family/1]). + family_domain_1/1, family_range_1/1, + family_to_relation_1/1, + union_of_family_1/1, intersection_of_family_1/1, + family_projection/1, family_difference/1, + family_intersection_1/1, family_union_1/1, + family_intersection_2/1, family_union_2/1, + partition_family/1]). -import(sofs, [a_function/1, a_function/2, constant_function/2, @@ -87,7 +87,9 @@ -compile({inline,[{eval,2}]}). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,2}}]. all() -> [{group, sofs}, {group, sofs_family}]. @@ -129,401 +131,384 @@ end_per_group(_GroupName, Config) -> init_per_testcase(_Case, Config) -> - Dog=?t:timetrap(?t:minutes(2)), - [{watchdog, Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), +end_per_testcase(_Case, _Config) -> ok. %% [{2,b},{1,a,b}] == lists:sort([{2,b},{1,a,b}]) %% [{1,a,b},{2,b}] == lists:keysort(1,[{2,b},{1,a,b}]) -from_term_1(suite) -> []; -from_term_1(doc) -> [""]; from_term_1(Conf) when is_list(Conf) -> %% would go wrong: projection(1,from_term([{2,b},{1,a,b}])), - ?line {'EXIT', {badarg, _}} = (catch from_term([], {atom,'_',atom})), - ?line {'EXIT', {badarg, _}} = (catch from_term([], [])), - ?line {'EXIT', {badarg, _}} = (catch from_term([], [atom,atom])), - - ?line [] = to_external(from_term([])), - ?line eval(from_term([]), empty_set()), - ?line [] = to_external(from_term([], ['_'])), - ?line eval(from_term([], ['_']), empty_set()), - ?line [[]] = to_external(from_term([[]])), - ?line [[['_']]] = type(from_term([[],[[]]])), - ?line [[],[[]]] = to_external(from_term([[],[[]]])), - ?line [[['_']]] = type(from_term([[],[[]]])), - ?line eval(from_term([a],['_']), set([a])), - ?line [[],[a]] = to_external(from_term([[],[a]])), - ?line [[],[{a}]] = to_external(from_term([[{a}],[]])), - ?line [{[],[{a,b,[d]}]},{[{a,b}],[]}] = + {'EXIT', {badarg, _}} = (catch from_term([], {atom,'_',atom})), + {'EXIT', {badarg, _}} = (catch from_term([], [])), + {'EXIT', {badarg, _}} = (catch from_term([], [atom,atom])), + + [] = to_external(from_term([])), + eval(from_term([]), empty_set()), + [] = to_external(from_term([], ['_'])), + eval(from_term([], ['_']), empty_set()), + [[]] = to_external(from_term([[]])), + [[['_']]] = type(from_term([[],[[]]])), + [[],[[]]] = to_external(from_term([[],[[]]])), + [[['_']]] = type(from_term([[],[[]]])), + eval(from_term([a],['_']), set([a])), + [[],[a]] = to_external(from_term([[],[a]])), + [[],[{a}]] = to_external(from_term([[{a}],[]])), + [{[],[{a,b,[d]}]},{[{a,b}],[]}] = to_external(from_term([{[],[{a,b,[d]}]},{[{a,b}],[]}])), - ?line [{[a,b],[c,d]}] = to_external(from_term([{[a,b],[c,d]}])), - ?line [{{a,b},[a,b],{{a},{b}}}] = + [{[a,b],[c,d]}] = to_external(from_term([{[a,b],[c,d]}])), + [{{a,b},[a,b],{{a},{b}}}] = to_external(from_term([{{a,b},[a,b],{{a},{b}}}])), - ?line [{{a,{[a,b]},a}},{{z,{[y,z]},z}}] = + [{{a,{[a,b]},a}},{{z,{[y,z]},z}}] = to_external(from_term([{{a,{[a,b,a]},a}},{{z,{[y,y,z]},z}}])), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch from_term([{m1,[{m1,f1,1},{m1,f2,2}]},{m2,[]},{m3,[a]}])), - ?line MS1 = [{m1,[{m1,f1,1},{m1,f2,2}]},{m2,[]},{m3,[{m3,f3,3}]}], - ?line eval(to_external(from_term(MS1)), MS1), - - ?line eval(to_external(from_term(a)), a), - ?line eval(to_external(from_term({a})), {a}), - - ?line eval(to_external(from_term([[a],[{b,c}]],[[atomic]])), - [[a],[{b,c}]]), - ?line eval(type(from_term([[a],[{b,c}]],[[atomic]])), - [[atomic]]), - - ?line {'EXIT', {badarg, _}} = (catch from_term([[],[],a])), - ?line {'EXIT', {badarg, _}} = (catch from_term([{[a,b],[c,{d}]}])), - ?line {'EXIT', {badarg, _}} = (catch from_term([[],[a],[{a}]])), - ?line {'EXIT', {badarg, _}} = (catch from_term([a,{a,b}])), - ?line {'EXIT', {badarg, _}} = (catch from_term([[a],[{b,c}]],[['_']])), - ?line {'EXIT', {badarg, _}} = (catch from_term([a | {a,b}])), - ?line {'EXIT', {badarg, _}} = + MS1 = [{m1,[{m1,f1,1},{m1,f2,2}]},{m2,[]},{m3,[{m3,f3,3}]}], + eval(to_external(from_term(MS1)), MS1), + + eval(to_external(from_term(a)), a), + eval(to_external(from_term({a})), {a}), + + eval(to_external(from_term([[a],[{b,c}]],[[atomic]])), + [[a],[{b,c}]]), + eval(type(from_term([[a],[{b,c}]],[[atomic]])), + [[atomic]]), + + {'EXIT', {badarg, _}} = (catch from_term([[],[],a])), + {'EXIT', {badarg, _}} = (catch from_term([{[a,b],[c,{d}]}])), + {'EXIT', {badarg, _}} = (catch from_term([[],[a],[{a}]])), + {'EXIT', {badarg, _}} = (catch from_term([a,{a,b}])), + {'EXIT', {badarg, _}} = (catch from_term([[a],[{b,c}]],[['_']])), + {'EXIT', {badarg, _}} = (catch from_term([a | {a,b}])), + {'EXIT', {badarg, _}} = (catch from_term([{{a},b,c},{d,e,f}],[{{atom},atom,atom}])), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch from_term([{a,{b,c}} | tail], [{atom,{atom,atom}}])), - ?line {'EXIT', {badarg, _}} = (catch from_term({})), - ?line {'EXIT', {badarg, _}} = (catch from_term([{}])), + {'EXIT', {badarg, _}} = (catch from_term({})), + {'EXIT', {badarg, _}} = (catch from_term([{}])), - ?line [{foo,bar},[b,a]] = + [{foo,bar},[b,a]] = to_external(from_term([[b,a],{foo,bar},[b,a]], [atom])), - ?line [{[atom],{atom,atom}}] = + [{[atom],{atom,atom}}] = type(from_term([{[], {a,b}},{[a,b],{e,f}}])), - ?line [{[atom],{atom,atom}}] = + [{[atom],{atom,atom}}] = type(from_term([{[], {a,b}},{[a,b],{e,f}}], [{[atom],{atom,atom}}])), - ?line [[atom]] = type(from_term([[a],[{b,c}]],[[atom]])), + [[atom]] = type(from_term([[a],[{b,c}]],[[atom]])), - ?line {atom, atom} = type(from_term({a,b}, {atom, atom})), - ?line atom = type(from_term(a, atom)), - ?line {'EXIT', {badarg, _}} = (catch from_term({a,b},{atom})), - ?line [{{a},b,c},{{d},e,f}] = + {atom, atom} = type(from_term({a,b}, {atom, atom})), + atom = type(from_term(a, atom)), + {'EXIT', {badarg, _}} = (catch from_term({a,b},{atom})), + [{{a},b,c},{{d},e,f}] = to_external(from_term([{{a},b,c},{{a},b,c},{{d},e,f}], [{{atom},atom,atom}])), %% from_external too... - ?line e = to_external(from_external(e, atom)), - ?line {e} = to_external(from_external({e}, {atom})), - ?line [e] = to_external(from_external([e], [atom])), + e = to_external(from_external(e, atom)), + {e} = to_external(from_external({e}, {atom})), + [e] = to_external(from_external([e], [atom])), %% and is_type... - ?line true = is_type(['_']), - ?line false = is_type('_'), - ?line true = is_type([['_']]), - ?line false = is_type({atom,[],atom}), - ?line false = is_type({atom,'_',atom}), - ?line true = is_type({atom,atomic,atom}), - ?line true = is_type({atom,atom}), - ?line true = is_type(atom), - ?line true = is_type([atom]), - ?line true = is_type(type), + true = is_type(['_']), + false = is_type('_'), + true = is_type([['_']]), + false = is_type({atom,[],atom}), + false = is_type({atom,'_',atom}), + true = is_type({atom,atomic,atom}), + true = is_type({atom,atom}), + true = is_type(atom), + true = is_type([atom]), + true = is_type(type), ok. -set_1(suite) -> []; -set_1(doc) -> [""]; set_1(Conf) when is_list(Conf) -> %% set/1 - ?line {'EXIT', {badarg, _}} = (catch set(a)), - ?line {'EXIT', {badarg, _}} = (catch set({a})), - ?line eval(set([]), from_term([],[atom])), - ?line eval(set([a,b,c]), from_term([a,b,c])), - ?line eval(set([a,b,a,a,b]), from_term([a,b])), - ?line eval(set([a,b,c,a,d,d,c,1]), from_term([1,a,b,c,d])), - ?line eval(set([a,b,d,a,c]), from_term([a,b,c,d])), - ?line eval(set([f,e,d,c,d]), from_term([c,d,e,f])), - ?line eval(set([h,f,d,g,g,d,c]), from_term([c,d,f,g,h])), - ?line eval(set([h,e,d,k,l]), from_term([d,e,h,k,l])), - ?line eval(set([h,e,c,k,d]), from_term([c,d,e,h,k])), + {'EXIT', {badarg, _}} = (catch set(a)), + {'EXIT', {badarg, _}} = (catch set({a})), + eval(set([]), from_term([],[atom])), + eval(set([a,b,c]), from_term([a,b,c])), + eval(set([a,b,a,a,b]), from_term([a,b])), + eval(set([a,b,c,a,d,d,c,1]), from_term([1,a,b,c,d])), + eval(set([a,b,d,a,c]), from_term([a,b,c,d])), + eval(set([f,e,d,c,d]), from_term([c,d,e,f])), + eval(set([h,f,d,g,g,d,c]), from_term([c,d,f,g,h])), + eval(set([h,e,d,k,l]), from_term([d,e,h,k,l])), + eval(set([h,e,c,k,d]), from_term([c,d,e,h,k])), %% set/2 - ?line {'EXIT', {badarg, _}} = (catch set(a, [a])), - ?line {'EXIT', {badarg, _}} = (catch set({a}, [a])), - ?line {'EXIT', {badarg, _}} = (catch set([a], {a})), - ?line {'EXIT', {badarg, _}} = (catch set([a], a)), - ?line {'EXIT', {badarg, _}} = (catch set([a], [a,b])), - ?line {'EXIT', {badarg, _}} = (catch set([a | b],[foo])), - ?line {'EXIT', {badarg, _}} = (catch set([a | b],['_'])), - ?line {'EXIT', {badarg, _}} = (catch set([a | b],[[atom]])), - ?line {'EXIT', {badarg, _}} = (catch set([{}],[{}])), - ?line eval(set([a],['_']), from_term([a],['_'])), - ?line eval(set([], ['_']), empty_set()), - ?line eval(set([a,b,a,b],[foo]), from_term([a,b],[foo])), + {'EXIT', {badarg, _}} = (catch set(a, [a])), + {'EXIT', {badarg, _}} = (catch set({a}, [a])), + {'EXIT', {badarg, _}} = (catch set([a], {a})), + {'EXIT', {badarg, _}} = (catch set([a], a)), + {'EXIT', {badarg, _}} = (catch set([a], [a,b])), + {'EXIT', {badarg, _}} = (catch set([a | b],[foo])), + {'EXIT', {badarg, _}} = (catch set([a | b],['_'])), + {'EXIT', {badarg, _}} = (catch set([a | b],[[atom]])), + {'EXIT', {badarg, _}} = (catch set([{}],[{}])), + eval(set([a],['_']), from_term([a],['_'])), + eval(set([], ['_']), empty_set()), + eval(set([a,b,a,b],[foo]), from_term([a,b],[foo])), ok. -from_sets_1(suite) -> []; -from_sets_1(doc) -> [""]; from_sets_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), + E = empty_set(), %% unordered - ?line eval(from_sets([]), E), - ?line {'EXIT', {type_mismatch, _}} = + eval(from_sets([]), E), + {'EXIT', {type_mismatch, _}} = (catch from_sets([from_term([{a,b}]), E, from_term([{a,b,c}])])), - ?line eval(from_sets([from_term([{a,b}]), E]), - from_term([[],[{a,b}]])), + eval(from_sets([from_term([{a,b}]), E]), + from_term([[],[{a,b}]])), - ?line eval(from_sets([from_term({a,b},{atom,atom}), - from_term({b,c},{atom,atom})]), - relation([{a,b}, {b,c}])), - ?line {'EXIT', {type_mismatch, _}} = + eval(from_sets([from_term({a,b},{atom,atom}), + from_term({b,c},{atom,atom})]), + relation([{a,b}, {b,c}])), + {'EXIT', {type_mismatch, _}} = (catch from_sets([from_term({a,b},{atom,atom}), from_term({a,b,c},{atom,atom,atom})])), - ?line {'EXIT', {badarg, _}} = (catch from_sets(foo)), - ?line eval(from_sets([E]), from_term([[]])), - ?line eval(from_sets([E,E]), from_term([[]])), - ?line eval(from_sets([E,set([a])]), from_term([[],[a]])), - ?line {'EXIT', {badarg, _}} = (catch from_sets([E,{a}])), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {badarg, _}} = (catch from_sets(foo)), + eval(from_sets([E]), from_term([[]])), + eval(from_sets([E,E]), from_term([[]])), + eval(from_sets([E,set([a])]), from_term([[],[a]])), + {'EXIT', {badarg, _}} = (catch from_sets([E,{a}])), + {'EXIT', {type_mismatch, _}} = (catch from_sets([E,from_term({a}),E])), - ?line {'EXIT', {type_mismatch, _}} = (catch from_sets([from_term({a}),E])), + {'EXIT', {type_mismatch, _}} = (catch from_sets([from_term({a}),E])), %% ordered - ?line O = {from_term(a,atom), from_term({b}, {atom}), set([c,d])}, - ?line eval(from_sets(O), from_term({a,{b},[c,d]}, {atom,{atom},[atom]})), - ?line {'EXIT', {badarg, _}} = (catch from_sets([a,b])), - ?line {'EXIT', {badarg, _}} = (catch from_sets({a,b})), - ?line eval(from_sets({from_term({a}),E}), from_term({{a},[]})), + O = {from_term(a,atom), from_term({b}, {atom}), set([c,d])}, + eval(from_sets(O), from_term({a,{b},[c,d]}, {atom,{atom},[atom]})), + {'EXIT', {badarg, _}} = (catch from_sets([a,b])), + {'EXIT', {badarg, _}} = (catch from_sets({a,b})), + eval(from_sets({from_term({a}),E}), from_term({{a},[]})), ok. -relation_1(suite) -> []; -relation_1(doc) -> [""]; relation_1(Conf) when is_list(Conf) -> %% relation/1 - ?line eval(relation([]), from_term([], [{atom,atom}])), - ?line eval(from_term([{a}]), relation([{a}])), - ?line {'EXIT', {badarg, _}} = (catch relation(a)), - ?line {'EXIT', {badarg, _}} = (catch relation([{a} | a])), - ?line {'EXIT', {badarg, _}} = (catch relation([{}])), - ?line {'EXIT', {badarg, _}} = (catch relation([],0)), - ?line {'EXIT', {badarg, _}} = (catch relation([{a}],a)), + eval(relation([]), from_term([], [{atom,atom}])), + eval(from_term([{a}]), relation([{a}])), + {'EXIT', {badarg, _}} = (catch relation(a)), + {'EXIT', {badarg, _}} = (catch relation([{a} | a])), + {'EXIT', {badarg, _}} = (catch relation([{}])), + {'EXIT', {badarg, _}} = (catch relation([],0)), + {'EXIT', {badarg, _}} = (catch relation([{a}],a)), %% relation/2 - ?line eval(relation([{a},{b}], 1), from_term([{a},{b}])), - ?line eval(relation([{1,a},{2,b},{1,a}], [{x,y}]), - from_term([{1,a},{2,b}], [{x,y}])), - ?line eval(relation([{[1,2],a},{[2,1],b},{[2,1],a}], [{[x],y}]), - from_term([{[1,2],a},{[1,2],b}], [{[x],y}])), - ?line {'EXIT', {badarg, _}} = (catch relation([{1,a},{2,b}], [{[x],y}])), - ?line {'EXIT', {badarg, _}} = (catch relation([{1,a},{1,a,b}], [{x,y}])), - ?line {'EXIT', {badarg, _}} = (catch relation([{a}], 2)), - ?line {'EXIT', {badarg, _}} = (catch relation([{a},{b},{c,d}], 1)), - ?line eval(relation([{{a},[{foo,bar}]}], ['_']), - from_term([{{a},[{foo,bar}]}], ['_'])), - ?line eval(relation([], ['_']), from_term([], ['_'])), - ?line {'EXIT', {badarg, _}} = (catch relation([[a]],['_'])), - ?line eval(relation([{[a,b,a]}], [{[atom]}]), from_term([{[a,b,a]}])), - ?line eval(relation([{[a,b,a],[[d,e,d]]}], [{[atom],[[atom]]}]), - from_term([{[a,b,a],[[d,e,d]]}])), - ?line eval(relation([{[a,b,a],[[d,e,d]]}], [{atom,[[atom]]}]), - from_term([{[a,b,a],[[d,e,d]]}], [{atom,[[atom]]}])), + eval(relation([{a},{b}], 1), from_term([{a},{b}])), + eval(relation([{1,a},{2,b},{1,a}], [{x,y}]), + from_term([{1,a},{2,b}], [{x,y}])), + eval(relation([{[1,2],a},{[2,1],b},{[2,1],a}], [{[x],y}]), + from_term([{[1,2],a},{[1,2],b}], [{[x],y}])), + {'EXIT', {badarg, _}} = (catch relation([{1,a},{2,b}], [{[x],y}])), + {'EXIT', {badarg, _}} = (catch relation([{1,a},{1,a,b}], [{x,y}])), + {'EXIT', {badarg, _}} = (catch relation([{a}], 2)), + {'EXIT', {badarg, _}} = (catch relation([{a},{b},{c,d}], 1)), + eval(relation([{{a},[{foo,bar}]}], ['_']), + from_term([{{a},[{foo,bar}]}], ['_'])), + eval(relation([], ['_']), from_term([], ['_'])), + {'EXIT', {badarg, _}} = (catch relation([[a]],['_'])), + eval(relation([{[a,b,a]}], [{[atom]}]), from_term([{[a,b,a]}])), + eval(relation([{[a,b,a],[[d,e,d]]}], [{[atom],[[atom]]}]), + from_term([{[a,b,a],[[d,e,d]]}])), + eval(relation([{[a,b,a],[[d,e,d]]}], [{atom,[[atom]]}]), + from_term([{[a,b,a],[[d,e,d]]}], [{atom,[[atom]]}])), ok. -a_function_1(suite) -> []; -a_function_1(doc) -> [""]; a_function_1(Conf) when is_list(Conf) -> %% a_function/1 - ?line eval(a_function([]), from_term([], [{atom,atom}])), - ?line eval(a_function([{a,b},{a,b},{b,c}]), from_term([{a,b},{b,c}])), - ?line {'EXIT', {badarg, _}} = (catch a_function([{a}])), - ?line {'EXIT', {badarg, _}} = (catch a_function([{a},{b},{c,d}])), - ?line {'EXIT', {badarg, _}} = (catch a_function(a)), - ?line {'EXIT', {badarg, _}} = (catch a_function([{a,b} | a])), - ?line {'EXIT', {bad_function, _}} = + eval(a_function([]), from_term([], [{atom,atom}])), + eval(a_function([{a,b},{a,b},{b,c}]), from_term([{a,b},{b,c}])), + {'EXIT', {badarg, _}} = (catch a_function([{a}])), + {'EXIT', {badarg, _}} = (catch a_function([{a},{b},{c,d}])), + {'EXIT', {badarg, _}} = (catch a_function(a)), + {'EXIT', {badarg, _}} = (catch a_function([{a,b} | a])), + {'EXIT', {bad_function, _}} = (catch a_function([{a,b},{b,c},{a,c}])), F = 0.0, I = round(F), if F == I -> % term ordering - ?line {'EXIT', {bad_function, _}} = + {'EXIT', {bad_function, _}} = (catch a_function([{I,a},{F,b}])), - ?line {'EXIT', {bad_function, _}} = - (catch a_function([{[I],a},{[F],b}],[{[a],b}])); + {'EXIT', {bad_function, _}} = + (catch a_function([{[I],a},{[F],b}],[{[a],b}])); true -> - ?line 2 = no_elements(a_function([{I,a},{F,b}])), - ?line 2 = no_elements(a_function([{[I],a},{[F],b}],[{[a],b}])) + 2 = no_elements(a_function([{I,a},{F,b}])), + 2 = no_elements(a_function([{[I],a},{[F],b}],[{[a],b}])) end, %% a_function/2 FT = [{atom,atom}], - ?line eval(a_function([], FT), from_term([], FT)), - ?line eval(a_function([{a,b},{b,c},{b,c}], FT), - from_term([{a,b},{b,c}], FT)), - ?line {'EXIT', {badarg, _}} = (catch a_function([{a,b}], [{a}])), - ?line {'EXIT', {badarg, _}} = (catch a_function([{a,b}], [{a,[b,c]}])), - ?line {'EXIT', {badarg, _}} = (catch a_function([{a}], FT)), - ?line {'EXIT', {badarg, _}} = (catch a_function([{a},{b},{c,d}], FT)), - ?line {'EXIT', {badarg, _}} = (catch a_function(a, FT)), - ?line {'EXIT', {badarg, _}} = (catch a_function([{a,b} | a], FT)), - ?line eval(a_function([{{a},[{foo,bar}]}], ['_']), - from_term([{{a},[{foo,bar}]}], ['_'])), - ?line eval(a_function([], ['_']), from_term([], ['_'])), - ?line {'EXIT', {badarg, _}} = (catch a_function([[a]],['_'])), - ?line {'EXIT', {bad_function, _}} = + eval(a_function([], FT), from_term([], FT)), + eval(a_function([{a,b},{b,c},{b,c}], FT), + from_term([{a,b},{b,c}], FT)), + {'EXIT', {badarg, _}} = (catch a_function([{a,b}], [{a}])), + {'EXIT', {badarg, _}} = (catch a_function([{a,b}], [{a,[b,c]}])), + {'EXIT', {badarg, _}} = (catch a_function([{a}], FT)), + {'EXIT', {badarg, _}} = (catch a_function([{a},{b},{c,d}], FT)), + {'EXIT', {badarg, _}} = (catch a_function(a, FT)), + {'EXIT', {badarg, _}} = (catch a_function([{a,b} | a], FT)), + eval(a_function([{{a},[{foo,bar}]}], ['_']), + from_term([{{a},[{foo,bar}]}], ['_'])), + eval(a_function([], ['_']), from_term([], ['_'])), + {'EXIT', {badarg, _}} = (catch a_function([[a]],['_'])), + {'EXIT', {bad_function, _}} = (catch a_function([{a,b},{b,c},{a,c}], FT)), - ?line eval(a_function([{a,[a]},{a,[a,a]}], [{atom,[atom]}]), - from_term([{a,[a]}])), - ?line eval(a_function([{[b,a],c},{[a,b],c}], [{[atom],atom}]), - from_term([{[a,b],c}])), + eval(a_function([{a,[a]},{a,[a,a]}], [{atom,[atom]}]), + from_term([{a,[a]}])), + eval(a_function([{[b,a],c},{[a,b],c}], [{[atom],atom}]), + from_term([{[a,b],c}])), ok. -family_1(suite) -> []; -family_1(doc) -> [""]; family_1(Conf) when is_list(Conf) -> %% family/1 - ?line eval(family([]), from_term([],[{atom,[atom]}])), - ?line {'EXIT', {badarg, _}} = (catch family(a)), - ?line {'EXIT', {badarg, _}} = (catch family([a])), - ?line {'EXIT', {badarg, _}} = (catch family([{a,b}])), - ?line {'EXIT', {badarg, _}} = (catch family([{a,[]} | a])), - ?line {'EXIT', {badarg, _}} = (catch family([{a,[a|b]}])), - ?line {'EXIT', {bad_function, _}} = + eval(family([]), from_term([],[{atom,[atom]}])), + {'EXIT', {badarg, _}} = (catch family(a)), + {'EXIT', {badarg, _}} = (catch family([a])), + {'EXIT', {badarg, _}} = (catch family([{a,b}])), + {'EXIT', {badarg, _}} = (catch family([{a,[]} | a])), + {'EXIT', {badarg, _}} = (catch family([{a,[a|b]}])), + {'EXIT', {bad_function, _}} = (catch family([{a,[a]},{a,[]}])), - ?line {'EXIT', {bad_function, _}} = + {'EXIT', {bad_function, _}} = (catch family([{a,[]},{b,[]},{a,[a]}])), F = 0.0, I = round(F), if F == I -> % term ordering - ?line {'EXIT', {bad_function, _}} = + {'EXIT', {bad_function, _}} = (catch family([{I,[a]},{F,[b]}])), - ?line true = (1 =:= no_elements(family([{a,[I]},{a,[F]}]))); + true = (1 =:= no_elements(family([{a,[I]},{a,[F]}]))); true -> - ?line {'EXIT', {bad_function, _}} = + {'EXIT', {bad_function, _}} = (catch family([{a,[I]},{a,[F]}])) end, - ?line eval(family([{a,[]},{b,[b]},{a,[]}]), from_term([{a,[]},{b,[b]}])), - ?line eval(to_external(family([{b,[{hej,san},tjo]},{a,[]}])), - [{a,[]},{b,[tjo,{hej,san}]}]), - ?line eval(family([{a,[a]},{a,[a,a]}]), family([{a,[a]}])), + eval(family([{a,[]},{b,[b]},{a,[]}]), from_term([{a,[]},{b,[b]}])), + eval(to_external(family([{b,[{hej,san},tjo]},{a,[]}])), + [{a,[]},{b,[tjo,{hej,san}]}]), + eval(family([{a,[a]},{a,[a,a]}]), family([{a,[a]}])), %% family/2 FT = [{a,[a]}], - ?line eval(family([], FT), from_term([],FT)), - ?line {'EXIT', {badarg, _}} = (catch family(a,FT)), - ?line {'EXIT', {badarg, _}} = (catch family([a],FT)), - ?line {'EXIT', {badarg, _}} = (catch family([{a,b}],FT)), - ?line {'EXIT', {badarg, _}} = (catch family([{a,[]} | a],FT)), - ?line {'EXIT', {badarg, _}} = (catch family([{a,[a|b]}], FT)), - ?line {'EXIT', {bad_function, _}} = + eval(family([], FT), from_term([],FT)), + {'EXIT', {badarg, _}} = (catch family(a,FT)), + {'EXIT', {badarg, _}} = (catch family([a],FT)), + {'EXIT', {badarg, _}} = (catch family([{a,b}],FT)), + {'EXIT', {badarg, _}} = (catch family([{a,[]} | a],FT)), + {'EXIT', {badarg, _}} = (catch family([{a,[a|b]}], FT)), + {'EXIT', {bad_function, _}} = (catch family([{a,[a]},{a,[]}], FT)), - ?line {'EXIT', {bad_function, _}} = + {'EXIT', {bad_function, _}} = (catch family([{a,[]},{b,[]},{a,[a]}], FT)), - ?line eval(family([{a,[]},{b,[b,b]},{a,[]}], FT), - from_term([{a,[]},{b,[b]}], FT)), - ?line eval(to_external(family([{b,[{hej,san},tjo]},{a,[]}], FT)), - [{a,[]},{b,[tjo,{hej,san}]}]), - - ?line eval(family([{{a},[{foo,bar}]}], ['_']), - from_term([{{a},[{foo,bar}]}], ['_'])), - ?line eval(family([], ['_']), from_term([], ['_'])), - ?line {'EXIT', {badarg, _}} = (catch family([[a]],['_'])), - ?line {'EXIT', {badarg, _}} = (catch family([{a,b}],['_'])), - ?line {'EXIT', {badarg, _}} = + eval(family([{a,[]},{b,[b,b]},{a,[]}], FT), + from_term([{a,[]},{b,[b]}], FT)), + eval(to_external(family([{b,[{hej,san},tjo]},{a,[]}], FT)), + [{a,[]},{b,[tjo,{hej,san}]}]), + + eval(family([{{a},[{foo,bar}]}], ['_']), + from_term([{{a},[{foo,bar}]}], ['_'])), + eval(family([], ['_']), from_term([], ['_'])), + {'EXIT', {badarg, _}} = (catch family([[a]],['_'])), + {'EXIT', {badarg, _}} = (catch family([{a,b}],['_'])), + {'EXIT', {badarg, _}} = (catch family([{a,[foo]}], [{atom,atom}])), - ?line eval(family([{{a},[{foo,bar}]}], [{{dt},[{r1,t2}]}]), - from_term([{{a},[{foo,bar}]}], [{{dt},[{r1,t2}]}])), - ?line eval(family([{a,[a]},{a,[a,a]}],[{atom,[atom]}]), - family([{a,[a]}])), - ?line eval(family([{[a,b],[a]},{[b,a],[a,a]}],[{[atom],[atom]}]), - from_term([{[a,b],[a]},{[b,a],[a,a]}])), + eval(family([{{a},[{foo,bar}]}], [{{dt},[{r1,t2}]}]), + from_term([{{a},[{foo,bar}]}], [{{dt},[{r1,t2}]}])), + eval(family([{a,[a]},{a,[a,a]}],[{atom,[atom]}]), + family([{a,[a]}])), + eval(family([{[a,b],[a]},{[b,a],[a,a]}],[{[atom],[atom]}]), + from_term([{[a,b],[a]},{[b,a],[a,a]}])), ok. -projection(suite) -> []; -projection(doc) -> [""]; projection(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), + E = empty_set(), + ER = relation([]), %% set of ordered sets - ?line S1 = relation([{a,1},{b,2},{b,22},{c,0}]), - ?line S2 = relation([{a,1},{a,2},{a,3},{b,4},{b,5},{b,6}]), - - ?line eval(projection(1, E), E), - ?line eval(projection(1, ER), set([])), - ?line eval(projection(1, relation([{a,1}])), set([a])), - ?line eval(projection(1, S1), set([a,b,c])), - ?line eval(projection(1, S2), set([a,b])), - ?line eval(projection(2, S1), set([0,1,2,22])), - ?line eval(projection(2, relation([{1,a},{2,a},{3,b}])), set([a,b])), - ?line eval(projection(1, relation([{a},{b},{c}])), set([a,b,c])), + S1 = relation([{a,1},{b,2},{b,22},{c,0}]), + S2 = relation([{a,1},{a,2},{a,3},{b,4},{b,5},{b,6}]), + + eval(projection(1, E), E), + eval(projection(1, ER), set([])), + eval(projection(1, relation([{a,1}])), set([a])), + eval(projection(1, S1), set([a,b,c])), + eval(projection(1, S2), set([a,b])), + eval(projection(2, S1), set([0,1,2,22])), + eval(projection(2, relation([{1,a},{2,a},{3,b}])), set([a,b])), + eval(projection(1, relation([{a},{b},{c}])), set([a,b,c])), Fun1 = {external, fun({A,B,C}) -> {A,{B,C}} end}, - ?line eval(projection(Fun1, E), E), + eval(projection(Fun1, E), E), %% No check here: - ?line eval(projection(3, projection(Fun1, empty_set())), E), - ?line E2 = relation([], 3), - ?line eval(projection(Fun1, E2), from_term([], [{atom,{atom,atom}}])), + eval(projection(3, projection(Fun1, empty_set())), E), + E2 = relation([], 3), + eval(projection(Fun1, E2), from_term([], [{atom,{atom,atom}}])), Fun2 = {external, fun({A,_B}) -> {A} end}, - ?line eval(projection(Fun2, ER), from_term([], [{atom}])), - ?line eval(projection(Fun2, relation([{a,1}])), relation([{a}])), - ?line eval(projection(Fun2, relation([{a,1},{b,3},{a,2}])), - relation([{a},{b}])), + eval(projection(Fun2, ER), from_term([], [{atom}])), + eval(projection(Fun2, relation([{a,1}])), relation([{a}])), + eval(projection(Fun2, relation([{a,1},{b,3},{a,2}])), + relation([{a},{b}])), Fun3 = {external, fun({A,_B,C}) -> {C,{A},C} end}, - ?line eval(projection(Fun3, relation([{a,1,x},{b,3,y},{a,2,z}])), - from_term([{x,{a},x},{y,{b},y},{z,{a},z}])), + eval(projection(Fun3, relation([{a,1,x},{b,3,y},{a,2,z}])), + from_term([{x,{a},x},{y,{b},y},{z,{a},z}])), Fun4 = {external, fun(A={B,_C,_D}) -> {B, A} end}, - ?line eval(projection(Fun4, relation([{a,1,x},{b,3,y},{a,2,z}])), - from_term([{a,{a,1,x}},{b,{b,3,y}},{a,{a,2,z}}])), + eval(projection(Fun4, relation([{a,1,x},{b,3,y},{a,2,z}])), + from_term([{a,{a,1,x}},{b,{b,3,y}},{a,{a,2,z}}])), - ?line eval(projection({external, fun({A,B,_C,D}) -> {A,B,A,D} end}, - relation([{1,1,1,2}, {1,1,3,1}])), - relation([{1,1,1,1}, {1,1,1,2}])), + eval(projection({external, fun({A,B,_C,D}) -> {A,B,A,D} end}, + relation([{1,1,1,2}, {1,1,3,1}])), + relation([{1,1,1,1}, {1,1,1,2}])), - ?line {'EXIT', {badarg, _}} = (catch projection(1, set([]))), - ?line {'EXIT', {function_clause, _}} = + {'EXIT', {badarg, _}} = (catch projection(1, set([]))), + {'EXIT', {function_clause, _}} = (catch projection({external, fun({A}) -> A end}, S1)), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch projection({external, fun({A,_}) -> {A,0} end}, from_term([{1,a}]))), %% {} is not an ordered set - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch projection({external, fun(_) -> {} end}, ER)), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch projection({external, fun(_) -> {{}} end}, ER)), - ?line eval(projection({external, fun({T,_}) -> T end}, - relation([{{},a},{{},b}])), - set([{}])), - ?line eval(projection({external, fun({T}) -> T end}, relation([{{}}])), - set([{}])), - - ?line eval(projection({external, fun(A) -> {A} end}, - relation([{1,a},{2,b}])), - from_term([{{1,a}},{{2,b}}])), - ?line eval(projection({external, fun({A,B}) -> {B,A} end}, - relation([{1,a},{2,b}])), - relation([{a,1},{b,2}])), - ?line eval(projection({external, fun(X=Y=A) -> {X,Y,A} end}, set([a,b,c])), - relation([{a,a,a},{b,b,b},{c,c,c}])), - - ?line eval(projection({external, fun({A,{_},B}) -> {A,B} end}, - from_term([{a,{a},b},{a,{b},c}])), - relation([{a,b},{a,c}])), - ?line eval(projection({external, fun({A,_,B}) -> {A,B} end}, - relation([{a,{},b},{a,{},c}])), - relation([{a,b},{a,c}])), + eval(projection({external, fun({T,_}) -> T end}, + relation([{{},a},{{},b}])), + set([{}])), + eval(projection({external, fun({T}) -> T end}, relation([{{}}])), + set([{}])), + + eval(projection({external, fun(A) -> {A} end}, + relation([{1,a},{2,b}])), + from_term([{{1,a}},{{2,b}}])), + eval(projection({external, fun({A,B}) -> {B,A} end}, + relation([{1,a},{2,b}])), + relation([{a,1},{b,2}])), + eval(projection({external, fun(X=Y=A) -> {X,Y,A} end}, set([a,b,c])), + relation([{a,a,a},{b,b,b},{c,c,c}])), + + eval(projection({external, fun({A,{_},B}) -> {A,B} end}, + from_term([{a,{a},b},{a,{b},c}])), + relation([{a,b},{a,c}])), + eval(projection({external, fun({A,_,B}) -> {A,B} end}, + relation([{a,{},b},{a,{},c}])), + relation([{a,b},{a,c}])), Fun5 = fun(S) -> from_term({to_external(S),0}, {type(S),atom}) end, - ?line eval(projection(Fun5, E), E), - ?line eval(projection(Fun5, set([a,b])), from_term([{a,0},{b,0}])), - ?line eval(projection(Fun5, relation([{a,1},{b,2}])), - from_term([{{a,1},0},{{b,2},0}])), - ?line eval(projection(Fun5, from_term([[a],[b]])), - from_term([{[a],0},{[b],0}])), + eval(projection(Fun5, E), E), + eval(projection(Fun5, set([a,b])), from_term([{a,0},{b,0}])), + eval(projection(Fun5, relation([{a,1},{b,2}])), + from_term([{{a,1},0},{{b,2},0}])), + eval(projection(Fun5, from_term([[a],[b]])), + from_term([{[a],0},{[b],0}])), F = 0.0, I = round(F), - ?line FR = relation([{I},{F}]), + FR = relation([{I},{F}]), if F == I -> % term ordering true = (no_elements(projection(1, FR)) =:= 1); @@ -532,382 +517,374 @@ projection(Conf) when is_list(Conf) -> end, %% set of sets - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch projection({external, fun(X) -> X end}, from_term([], [[atom]]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch projection({external, fun(X) -> X end}, from_term([[a]]))), - ?line eval(projection(fun sofs:union/1, - from_term([[[1,2],[2,3]], [[a,b],[b,c]]])), - from_term([[1,2,3], [a,b,c]])), - ?line eval(projection(fun(_) -> from_term([a]) end, - from_term([[b]], [[a]])), - from_term([[a]])), - ?line eval(projection(fun(_) -> from_term([a]) end, - from_term([[1,2],[3,4]])), - from_term([[a]])), + eval(projection(fun sofs:union/1, + from_term([[[1,2],[2,3]], [[a,b],[b,c]]])), + from_term([[1,2,3], [a,b,c]])), + eval(projection(fun(_) -> from_term([a]) end, + from_term([[b]], [[a]])), + from_term([[a]])), + eval(projection(fun(_) -> from_term([a]) end, + from_term([[1,2],[3,4]])), + from_term([[a]])), Fun10 = fun(S) -> - %% Cheating a lot... - case to_external(S) of - [1] -> from_term({1,1}); - _ -> S - end - end, - ?line eval(projection(Fun10, from_term([[1]])), from_term([{1,1}])), - ?line eval(projection(fun(_) -> from_term({a}) end, from_term([[a]])), - from_term([{a}])), - ?line {'EXIT', {badarg, _}} = + %% Cheating a lot... + case to_external(S) of + [1] -> from_term({1,1}); + _ -> S + end + end, + eval(projection(Fun10, from_term([[1]])), from_term([{1,1}])), + eval(projection(fun(_) -> from_term({a}) end, from_term([[a]])), + from_term([{a}])), + {'EXIT', {badarg, _}} = (catch projection(fun(_) -> {a} end, from_term([[a]]))), ok. -substitution(suite) -> []; -substitution(doc) -> [""]; substitution(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), + E = empty_set(), + ER = relation([]), %% set of ordered sets - ?line S1 = relation([{a,1},{b,2},{b,22},{c,0}]), - ?line S2 = relation([{a,1},{a,2},{a,3},{b,4},{b,5},{b,6}]), + S1 = relation([{a,1},{b,2},{b,22},{c,0}]), + S2 = relation([{a,1},{a,2},{a,3},{b,4},{b,5},{b,6}]), - ?line eval(substitution(1, E), E), + eval(substitution(1, E), E), %% No check here: Fun0 = {external, fun({A,B,C}) -> {A,{B,C}} end}, - ?line eval(substitution(3, substitution(Fun0, empty_set())), E), - ?line eval(substitution(1, ER), from_term([],[{{atom,atom},atom}])), - ?line eval(substitution(1, relation([{a,1}])), from_term([{{a,1},a}])), - ?line eval(substitution(1, S1), - from_term([{{a,1},a},{{b,2},b},{{b,22},b},{{c,0},c}])), - ?line eval(substitution(1, S2), - from_term([{{a,1},a},{{a,2},a},{{a,3},a},{{b,4},b}, - {{b,5},b},{{b,6},b}])), - ?line eval(substitution(2, S1), - from_term([{{a,1},1},{{b,2},2},{{b,22},22},{{c,0},0}])), - + eval(substitution(3, substitution(Fun0, empty_set())), E), + eval(substitution(1, ER), from_term([],[{{atom,atom},atom}])), + eval(substitution(1, relation([{a,1}])), from_term([{{a,1},a}])), + eval(substitution(1, S1), + from_term([{{a,1},a},{{b,2},b},{{b,22},b},{{c,0},c}])), + eval(substitution(1, S2), + from_term([{{a,1},a},{{a,2},a},{{a,3},a},{{b,4},b}, + {{b,5},b},{{b,6},b}])), + eval(substitution(2, S1), + from_term([{{a,1},1},{{b,2},2},{{b,22},22},{{c,0},0}])), + Fun1 = fun({A,_B}) -> {A} end, XFun1 = {external, Fun1}, - ?line eval(substitution(XFun1, E), E), - ?line eval(substitution(Fun1, E), E), - ?line eval(substitution(XFun1, ER), from_term([], [{{atom,atom},{atom}}])), - ?line eval(substitution(XFun1, relation([{a,1}])), - from_term([{{a,1},{a}}])), - ?line eval(substitution(XFun1, relation([{a,1},{b,3},{a,2}])), - from_term([{{a,1},{a}},{{a,2},{a}},{{b,3},{b}}])), - ?line eval(substitution({external, fun({A,_B,C}) -> {C,A,C} end}, - relation([{a,1,x},{b,3,y},{a,2,z}])), - from_term([{{a,1,x},{x,a,x}},{{a,2,z},{z,a,z}}, - {{b,3,y},{y,b,y}}])), + eval(substitution(XFun1, E), E), + eval(substitution(Fun1, E), E), + eval(substitution(XFun1, ER), from_term([], [{{atom,atom},{atom}}])), + eval(substitution(XFun1, relation([{a,1}])), + from_term([{{a,1},{a}}])), + eval(substitution(XFun1, relation([{a,1},{b,3},{a,2}])), + from_term([{{a,1},{a}},{{a,2},{a}},{{b,3},{b}}])), + eval(substitution({external, fun({A,_B,C}) -> {C,A,C} end}, + relation([{a,1,x},{b,3,y},{a,2,z}])), + from_term([{{a,1,x},{x,a,x}},{{a,2,z},{z,a,z}}, + {{b,3,y},{y,b,y}}])), Fun2 = fun(S) -> {A,_B} = to_external(S), from_term({A}) end, - ?line eval(substitution(Fun2, ER), E), - ?line eval(substitution(Fun2, relation([{a,1}])), - from_term([{{a,1},{a}}])), + eval(substitution(Fun2, ER), E), + eval(substitution(Fun2, relation([{a,1}])), + from_term([{{a,1},{a}}])), Fun3 = fun(S) -> from_term({to_external(S),0}, {type(S),atom}) end, - ?line eval(substitution(Fun3, E), E), - ?line eval(substitution(Fun3, set([a,b])), - from_term([{a,{a,0}},{b,{b,0}}])), - ?line eval(substitution(Fun3, relation([{a,1},{b,2}])), - from_term([{{a,1},{{a,1},0}},{{b,2},{{b,2},0}}])), - ?line eval(substitution(Fun3, from_term([[a],[b]])), - from_term([{[a],{[a],0}},{[b],{[b],0}}])), - - ?line eval(substitution(fun(_) -> E end, from_term([[a],[b]])), - from_term([{[a],[]},{[b],[]}])), - - ?line {'EXIT', {badarg, _}} = (catch substitution(1, set([]))), - ?line eval(substitution(1, ER), from_term([], [{{atom,atom},atom}])), - ?line {'EXIT', {function_clause, _}} = + eval(substitution(Fun3, E), E), + eval(substitution(Fun3, set([a,b])), + from_term([{a,{a,0}},{b,{b,0}}])), + eval(substitution(Fun3, relation([{a,1},{b,2}])), + from_term([{{a,1},{{a,1},0}},{{b,2},{{b,2},0}}])), + eval(substitution(Fun3, from_term([[a],[b]])), + from_term([{[a],{[a],0}},{[b],{[b],0}}])), + + eval(substitution(fun(_) -> E end, from_term([[a],[b]])), + from_term([{[a],[]},{[b],[]}])), + + {'EXIT', {badarg, _}} = (catch substitution(1, set([]))), + eval(substitution(1, ER), from_term([], [{{atom,atom},atom}])), + {'EXIT', {function_clause, _}} = (catch substitution({external, fun({A,_}) -> A end}, set([]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch substitution({external, fun({A,_}) -> {A,0} end}, from_term([{1,a}]))), %% set of sets - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch substitution({external, fun(X) -> X end}, from_term([], [[atom]]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch substitution({external, fun(X) -> X end}, from_term([[a]]))), - ?line eval(substitution(fun(X) -> X end, from_term([], [[atom]])), E), - ?line eval(substitution(fun sofs:union/1, - from_term([[[1,2],[2,3]], [[a,b],[b,c]]])), - from_term([{[[1,2],[2,3]],[1,2,3]}, {[[a,b],[b,c]],[a,b,c]}])), - ?line eval(substitution(fun(_) -> from_term([a]) end, - from_term([[b]], [[a]])), - from_term([{[b],[a]}], [{[a],[atom]}])), - ?line eval(substitution(fun(_) -> from_term([a]) end, - from_term([[1,2],[3,4]])), - from_term([{[1,2],[a]},{[3,4],[a]}])), + eval(substitution(fun(X) -> X end, from_term([], [[atom]])), E), + eval(substitution(fun sofs:union/1, + from_term([[[1,2],[2,3]], [[a,b],[b,c]]])), + from_term([{[[1,2],[2,3]],[1,2,3]}, {[[a,b],[b,c]],[a,b,c]}])), + eval(substitution(fun(_) -> from_term([a]) end, + from_term([[b]], [[a]])), + from_term([{[b],[a]}], [{[a],[atom]}])), + eval(substitution(fun(_) -> from_term([a]) end, + from_term([[1,2],[3,4]])), + from_term([{[1,2],[a]},{[3,4],[a]}])), Fun10 = fun(S) -> - %% Cheating a lot... - case to_external(S) of - [1] -> from_term({1,1}); - _ -> S - end - end, - ?line eval(substitution(Fun10, from_term([[1]])), - from_term([{[1],{1,1}}])), - ?line {'EXIT', {type_mismatch, _}} = + %% Cheating a lot... + case to_external(S) of + [1] -> from_term({1,1}); + _ -> S + end + end, + eval(substitution(Fun10, from_term([[1]])), + from_term([{[1],{1,1}}])), + {'EXIT', {type_mismatch, _}} = (catch substitution(Fun10, from_term([[1],[2]]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch substitution(Fun10, from_term([[1],[0]]))), - ?line eval(substitution(fun(_) -> from_term({a}) end, from_term([[a]])), - from_term([{[a],{a}}])), - ?line {'EXIT', {badarg, _}} = + eval(substitution(fun(_) -> from_term({a}) end, from_term([[a]])), + from_term([{[a],{a}}])), + {'EXIT', {badarg, _}} = (catch substitution(fun(_) -> {a} end, from_term([[a]]))), ok. -restriction(suite) -> []; -restriction(doc) -> [""]; restriction(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([], 2), + E = empty_set(), + ER = relation([], 2), %% set of ordered sets - ?line S1 = relation([{a,1},{b,2},{b,22},{c,0}]), - ?line eval(restriction(S1, set([a,b])), - relation([{a,1},{b,2},{b,22}])), - ?line eval(restriction(2, S1, set([1,2])), - relation([{a,1},{b,2}])), - ?line eval(restriction(S1, set([a,b,c])), S1), - ?line eval(restriction(1, S1, set([0,1,d,e])), ER), - ?line eval(restriction(1, S1, E), ER), - ?line eval(restriction({external, fun({_A,B,C}) -> {B,C} end}, - relation([{a,aa,1},{b,bb,2},{c,cc,3}]), - relation([{bb,2},{cc,3}])), - relation([{b,bb,2},{c,cc,3}])), + S1 = relation([{a,1},{b,2},{b,22},{c,0}]), + eval(restriction(S1, set([a,b])), + relation([{a,1},{b,2},{b,22}])), + eval(restriction(2, S1, set([1,2])), + relation([{a,1},{b,2}])), + eval(restriction(S1, set([a,b,c])), S1), + eval(restriction(1, S1, set([0,1,d,e])), ER), + eval(restriction(1, S1, E), ER), + eval(restriction({external, fun({_A,B,C}) -> {B,C} end}, + relation([{a,aa,1},{b,bb,2},{c,cc,3}]), + relation([{bb,2},{cc,3}])), + relation([{b,bb,2},{c,cc,3}])), R1 = relation([],[{a,b}]), - ?line eval(restriction(2, R1,sofs:set([],[b])), R1), + eval(restriction(2, R1,sofs:set([],[b])), R1), Id = fun(X) -> X end, XId = {external, Id}, - ?line eval(restriction(XId, relation([{a,b}]), E), ER), - ?line eval(restriction(XId, E, relation([{b,d}])), E), + eval(restriction(XId, relation([{a,b}]), E), ER), + eval(restriction(XId, E, relation([{b,d}])), E), Fun1 = fun(S) -> {_A,B,C} = to_external(S), from_term({B,C}) end, - ?line eval(restriction(Fun1, - relation([{a,aa,1},{b,bb,2},{c,cc,3}]), - relation([{bb,2},{cc,3}])), - relation([{b,bb,2},{c,cc,3}])), - ?line eval(restriction({external, fun({_,{A},B}) -> {A,B} end}, - from_term([{a,{aa},1},{b,{bb},2},{c,{cc},3}]), - from_term([{bb,2},{cc,3}])), - from_term([{b,{bb},2},{c,{cc},3}])), + eval(restriction(Fun1, + relation([{a,aa,1},{b,bb,2},{c,cc,3}]), + relation([{bb,2},{cc,3}])), + relation([{b,bb,2},{c,cc,3}])), + eval(restriction({external, fun({_,{A},B}) -> {A,B} end}, + from_term([{a,{aa},1},{b,{bb},2},{c,{cc},3}]), + from_term([{bb,2},{cc,3}])), + from_term([{b,{bb},2},{c,{cc},3}])), S5 = relation([{1,a},{2,b},{3,c}]), - ?line eval(restriction(2, S5, set([b,c])), relation([{2,b},{3,c}])), + eval(restriction(2, S5, set([b,c])), relation([{2,b},{3,c}])), S4 = relation([{a,1},{b,2},{b,27},{c,0}]), - ?line eval(restriction(2, S4, E), ER), + eval(restriction(2, S4, E), ER), S6 = relation([{1,a},{2,c},{3,b}]), - ?line eval(restriction(2, S6, set([d,e])), ER), - ?line eval(restriction(2, - relation([{1,d},{2,c},{3,b},{4,a},{5,e}]), - set([c])), - relation([{2,c}])), - ?line eval(restriction(XId, - relation([{1,a},{3,b},{4,c},{4,d}]), - relation([{2,a},{2,c},{4,c}])), - relation([{4,c}])), - ?line eval(restriction(2, relation([{a,b}]), E), ER), - ?line eval(restriction(2, E, relation([{b,d}])), E), - ?line eval(restriction(2, relation([{b,d}]), E), ER), - ?line eval(restriction(XId, E, set([a])), E), - ?line eval(restriction(1, S1, E), ER), - ?line {'EXIT', {badarg, _}} = + eval(restriction(2, S6, set([d,e])), ER), + eval(restriction(2, + relation([{1,d},{2,c},{3,b},{4,a},{5,e}]), + set([c])), + relation([{2,c}])), + eval(restriction(XId, + relation([{1,a},{3,b},{4,c},{4,d}]), + relation([{2,a},{2,c},{4,c}])), + relation([{4,c}])), + eval(restriction(2, relation([{a,b}]), E), ER), + eval(restriction(2, E, relation([{b,d}])), E), + eval(restriction(2, relation([{b,d}]), E), ER), + eval(restriction(XId, E, set([a])), E), + eval(restriction(1, S1, E), ER), + {'EXIT', {badarg, _}} = (catch restriction(3, relation([{a,b}]), E)), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch restriction(3, relation([{a,b}]), relation([{b,d}]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch restriction(3, relation([{a,b}]), set([{b,d}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch restriction(2, relation([{a,b}]), relation([{b,d}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch restriction({external, fun({A,_B}) -> A end}, relation([{a,b}]), relation([{b,d}]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch restriction({external, fun({A,_}) -> {A,0} end}, from_term([{1,a}]), from_term([{1,0}]))), - ?line eval(restriction(2, relation([{a,d},{b,e},{c,b},{d,c}]), set([b,d])), - relation([{a,d},{c,b}])), - ?line {'EXIT', {function_clause, _}} = + eval(restriction(2, relation([{a,d},{b,e},{c,b},{d,c}]), set([b,d])), + relation([{a,d},{c,b}])), + {'EXIT', {function_clause, _}} = (catch restriction({external, fun({A,_B}) -> A end}, set([]), E)), Fun3 = fun(S) -> from_term({to_external(S),0}, {type(S),atom}) end, - ?line eval(restriction(Fun3, set([1,2]), from_term([{1,0}])), - from_term([1])), + eval(restriction(Fun3, set([1,2]), from_term([{1,0}])), + from_term([1])), %% set of sets - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch restriction({external, fun(X) -> X end}, from_term([], [[atom]]), set([a]))), S2 = from_term([], [[atom]]), - ?line eval(restriction(Id, S2, E), E), + eval(restriction(Id, S2, E), E), S3 = from_term([[a],[b]], [[atom]]), - ?line eval(restriction(Id, S3, E), E), - ?line eval(restriction(Id, from_term([], [[atom]]), set([a])), - from_term([], [[atom]])), - ?line eval(restriction(fun sofs:union/1, - from_term([[[a],[b]], [[b],[c]], - [[], [a,b]], [[1],[2]]]), - from_term([[a,b],[1,2,3],[b,c]])), - from_term([[[],[a,b]], [[a],[b]],[[b],[c]]])), - ?line eval(restriction(fun(_) -> from_term([a]) end, - from_term([], [[atom]]), - from_term([], [[a]])), - from_term([], [[atom]])), - ?line {'EXIT', {type_mismatch, _}} = + eval(restriction(Id, S3, E), E), + eval(restriction(Id, from_term([], [[atom]]), set([a])), + from_term([], [[atom]])), + eval(restriction(fun sofs:union/1, + from_term([[[a],[b]], [[b],[c]], + [[], [a,b]], [[1],[2]]]), + from_term([[a,b],[1,2,3],[b,c]])), + from_term([[[],[a,b]], [[a],[b]],[[b],[c]]])), + eval(restriction(fun(_) -> from_term([a]) end, + from_term([], [[atom]]), + from_term([], [[a]])), + from_term([], [[atom]])), + {'EXIT', {type_mismatch, _}} = (catch restriction(fun(_) -> from_term([a]) end, from_term([[1,2],[3,4]]), from_term([], [atom]))), Fun10 = fun(S) -> - %% Cheating a lot... - case to_external(S) of - [1] -> from_term({1,1}); - _ -> S - end - end, - ?line {'EXIT', {type_mismatch, _}} = + %% Cheating a lot... + case to_external(S) of + [1] -> from_term({1,1}); + _ -> S + end + end, + {'EXIT', {type_mismatch, _}} = (catch restriction(Fun10, from_term([[1]]), from_term([], [[atom]]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch restriction(fun(_) -> from_term({a}) end, from_term([[a]]), from_term([], [atom]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch restriction(fun(_) -> {a} end, from_term([[a]]), from_term([], [atom]))), ok. -drestriction(suite) -> []; -drestriction(doc) -> [""]; drestriction(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([], 2), + E = empty_set(), + ER = relation([], 2), %% set of ordered sets - ?line S1 = relation([{a,1},{b,2},{b,22},{c,0}]), - ?line eval(drestriction(S1, set([a,b])), relation([{c,0}])), - ?line eval(drestriction(2, S1, set([1,2])), - relation([{b,22},{c,0}])), - ?line eval(drestriction(S1, set([a,b,c])), ER), - ?line eval(drestriction(2, ER, set([a,b])), ER), - ?line eval(drestriction(1, S1, set([0,1,d,e])), S1), - ?line eval(drestriction(1, S1, E), S1), - ?line eval(drestriction({external, fun({_A,B,C}) -> {B,C} end}, - relation([{a,aa,1},{b,bb,2},{c,cc,3}]), - relation([{bb,2},{cc,3}])), - relation([{a,aa,1}])), + S1 = relation([{a,1},{b,2},{b,22},{c,0}]), + eval(drestriction(S1, set([a,b])), relation([{c,0}])), + eval(drestriction(2, S1, set([1,2])), + relation([{b,22},{c,0}])), + eval(drestriction(S1, set([a,b,c])), ER), + eval(drestriction(2, ER, set([a,b])), ER), + eval(drestriction(1, S1, set([0,1,d,e])), S1), + eval(drestriction(1, S1, E), S1), + eval(drestriction({external, fun({_A,B,C}) -> {B,C} end}, + relation([{a,aa,1},{b,bb,2},{c,cc,3}]), + relation([{bb,2},{cc,3}])), + relation([{a,aa,1}])), Id = fun(X) -> X end, XId = {external, Id}, - ?line eval(drestriction(XId, relation([{a,b}]), E), relation([{a,b}])), - ?line eval(drestriction(XId, E, relation([{b,d}])), E), + eval(drestriction(XId, relation([{a,b}]), E), relation([{a,b}])), + eval(drestriction(XId, E, relation([{b,d}])), E), Fun1 = fun(S) -> {_A,B,C} = to_external(S), from_term({B,C}) end, - ?line eval(drestriction(Fun1, - relation([{a,aa,1},{b,bb,2},{c,cc,3}]), - relation([{bb,2},{cc,3}])), - relation([{a,aa,1}])), - ?line eval(drestriction({external, fun({_,{A},B}) -> {A,B} end}, - from_term([{a,{aa},1},{b,{bb},2},{c,{cc},3}]), - from_term([{bb,2},{cc,3}])), - from_term([{a,{aa},1}])), + eval(drestriction(Fun1, + relation([{a,aa,1},{b,bb,2},{c,cc,3}]), + relation([{bb,2},{cc,3}])), + relation([{a,aa,1}])), + eval(drestriction({external, fun({_,{A},B}) -> {A,B} end}, + from_term([{a,{aa},1},{b,{bb},2},{c,{cc},3}]), + from_term([{bb,2},{cc,3}])), + from_term([{a,{aa},1}])), S5 = relation([{1,a},{2,b},{3,c}]), - ?line eval(drestriction(2, S5, set([b,c])), relation([{1,a}])), + eval(drestriction(2, S5, set([b,c])), relation([{1,a}])), S4 = relation([{a,1},{b,2},{b,27},{c,0}]), - ?line eval(drestriction(2, S4, set([])), S4), + eval(drestriction(2, S4, set([])), S4), S6 = relation([{1,a},{2,c},{3,b}]), - ?line eval(drestriction(2, S6, set([d,e])), S6), - ?line eval(drestriction(2, - relation([{1,d},{2,c},{3,b},{4,a},{5,e}]), - set([c])), - relation([{1,d},{3,b},{4,a},{5,e}])), - ?line eval(drestriction(XId, - relation([{1,a},{3,b},{4,c},{4,d}]), - relation([{2,a},{2,c},{4,c}])), - relation([{1,a},{3,b},{4,d}])), - ?line eval(drestriction(2, relation([{a,b}]), E), relation([{a,b}])), - ?line eval(drestriction(2, E, relation([{b,d}])), E), - ?line eval(drestriction(2, relation([{b,d}]), E), relation([{b,d}])), - ?line eval(drestriction(XId, E, set([a])), E), - ?line eval(drestriction(1, S1, E), S1), - ?line {'EXIT', {badarg, _}} = + eval(drestriction(2, S6, set([d,e])), S6), + eval(drestriction(2, + relation([{1,d},{2,c},{3,b},{4,a},{5,e}]), + set([c])), + relation([{1,d},{3,b},{4,a},{5,e}])), + eval(drestriction(XId, + relation([{1,a},{3,b},{4,c},{4,d}]), + relation([{2,a},{2,c},{4,c}])), + relation([{1,a},{3,b},{4,d}])), + eval(drestriction(2, relation([{a,b}]), E), relation([{a,b}])), + eval(drestriction(2, E, relation([{b,d}])), E), + eval(drestriction(2, relation([{b,d}]), E), relation([{b,d}])), + eval(drestriction(XId, E, set([a])), E), + eval(drestriction(1, S1, E), S1), + {'EXIT', {badarg, _}} = (catch drestriction(3, relation([{a,b}]), E)), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch drestriction(3, relation([{a,b}]), relation([{b,d}]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch drestriction(3, relation([{a,b}]), set([{b,d}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch drestriction(2, relation([{a,b}]), relation([{b,d}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch drestriction({external, fun({A,_B}) -> A end}, relation([{a,b}]), relation([{b,d}]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch drestriction({external, fun({A,_}) -> {A,0} end}, from_term([{1,a}]), from_term([{1,0}]))), - ?line eval(drestriction(2, relation([{a,d},{b,e},{c,b},{d,c}]), set([b,d])), - relation([{b,e},{d,c}])), - ?line {'EXIT', {function_clause, _}} = + eval(drestriction(2, relation([{a,d},{b,e},{c,b},{d,c}]), set([b,d])), + relation([{b,e},{d,c}])), + {'EXIT', {function_clause, _}} = (catch drestriction({external, fun({A,_B}) -> A end}, set([]), E)), Fun3 = fun(S) -> from_term({to_external(S),0}, {type(S),atom}) end, - ?line eval(drestriction(Fun3, set([1,2]), from_term([{1,0}])), - from_term([2])), + eval(drestriction(Fun3, set([1,2]), from_term([{1,0}])), + from_term([2])), %% set of sets - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch drestriction({external, fun(X) -> X end}, from_term([], [[atom]]), set([a]))), S2 = from_term([], [[atom]]), - ?line eval(drestriction(Id, S2, E), S2), + eval(drestriction(Id, S2, E), S2), S3 = from_term([[a],[b]], [[atom]]), - ?line eval(drestriction(Id, S3, E), S3), - ?line eval(drestriction(Id, from_term([], [[atom]]), set([a])), - from_term([], [[atom]])), - ?line eval(drestriction(fun sofs:union/1, - from_term([[[a],[b]], [[b],[c]], - [[], [a,b]], [[1],[2]]]), - from_term([[a,b],[1,2,3],[b,c]])), - from_term([[[1],[2]]])), - ?line eval(drestriction(fun(_) -> from_term([a]) end, - from_term([], [[atom]]), - from_term([], [[a]])), - from_term([], [[atom]])), - ?line {'EXIT', {type_mismatch, _}} = + eval(drestriction(Id, S3, E), S3), + eval(drestriction(Id, from_term([], [[atom]]), set([a])), + from_term([], [[atom]])), + eval(drestriction(fun sofs:union/1, + from_term([[[a],[b]], [[b],[c]], + [[], [a,b]], [[1],[2]]]), + from_term([[a,b],[1,2,3],[b,c]])), + from_term([[[1],[2]]])), + eval(drestriction(fun(_) -> from_term([a]) end, + from_term([], [[atom]]), + from_term([], [[a]])), + from_term([], [[atom]])), + {'EXIT', {type_mismatch, _}} = (catch drestriction(fun(_) -> from_term([a]) end, from_term([[1,2],[3,4]]), from_term([], [atom]))), Fun10 = fun(S) -> - %% Cheating a lot... - case to_external(S) of - [1] -> from_term({1,1}); - _ -> S - end - end, - ?line {'EXIT', {type_mismatch, _}} = + %% Cheating a lot... + case to_external(S) of + [1] -> from_term({1,1}); + _ -> S + end + end, + {'EXIT', {type_mismatch, _}} = (catch drestriction(Fun10, from_term([[1]]), from_term([], [[atom]]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch drestriction(fun(_) -> from_term({a}) end, from_term([[a]]), from_term([], [atom]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch drestriction(fun(_) -> {a} end, from_term([[a]]), from_term([], [atom]))), ok. -strict_relation_1(suite) -> []; -strict_relation_1(doc) -> [""]; strict_relation_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([], 2), - ?line eval(strict_relation(E), E), - ?line eval(strict_relation(ER), ER), - ?line eval(strict_relation(relation([{1,a},{a,a},{2,b}])), - relation([{1,a},{2,b}])), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + ER = relation([], 2), + eval(strict_relation(E), E), + eval(strict_relation(ER), ER), + eval(strict_relation(relation([{1,a},{a,a},{2,b}])), + relation([{1,a},{2,b}])), + {'EXIT', {badarg, _}} = (catch strict_relation(relation([{1,2,3}]))), F = 0.0, I = round(F), - ?line FR = relation([{F,I}]), + FR = relation([{F,I}]), if F == I -> % term ordering eval(strict_relation(FR), ER); @@ -916,362 +893,334 @@ strict_relation_1(Conf) when is_list(Conf) -> end, ok. -extension(suite) -> []; -extension(doc) -> [""]; extension(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([], 2), - ?line EF = family([]), - ?line C1 = from_term(3), - ?line C2 = from_term([3]), - ?line {'EXIT', {function_clause, _}} = (catch extension(foo, E, C1)), - ?line {'EXIT', {function_clause, _}} = (catch extension(ER, foo, C1)), - ?line {'EXIT', {{case_clause, _},_}} = (catch extension(ER, E, foo)), - ?line {'EXIT', {type_mismatch, _}} = (catch extension(ER, E, E)), - ?line {'EXIT', {badarg, _}} = (catch extension(C2, E, E)), - ?line eval(E, extension(E, E, E)), - ?line eval(EF, extension(EF, E, E)), - ?line eval(family([{3,[]}]), extension(EF, set([3]), E)), - ?line eval(ER, extension(ER, E, C1)), - ?line eval(E, extension(E, ER, E)), - ?line eval(from_term([],[{{atom,atom},type(ER)}]), extension(E, ER, ER)), - - ?line R1 = relation([{c,7},{c,9},{c,11},{d,17},{f,20}]), - ?line S1 = set([a,c,d,e]), - ?line eval(extension(R1, S1, C1), lextension(R1, S1, C1)), - - ?line S2 = set([1,2,3]), - ?line eval(extension(ER, S2, C1), lextension(ER, S2, C1)), - - ?line R3 = relation([{4,a},{8,b}]), - ?line S3 = set([1,2,3,4,5,6,7,8,9,10,11]), - ?line eval(extension(R3, S3, C1), lextension(R3, S3, C1)), - - ?line R4 = relation([{2,b},{4,d},{6,f}]), - ?line S4 = set([1,3,5,7]), - ?line eval(extension(R4, S4, C1), lextension(R4, S4, C1)), - - ?line F1 = family([{a,[1]},{c,[2]}]), - ?line S5 = set([a,b,c,d]), - ?line eval(extension(F1, S5, C2), lextension(F1, S5, C2)), + E = empty_set(), + ER = relation([], 2), + EF = family([]), + C1 = from_term(3), + C2 = from_term([3]), + {'EXIT', {function_clause, _}} = (catch extension(foo, E, C1)), + {'EXIT', {function_clause, _}} = (catch extension(ER, foo, C1)), + {'EXIT', {{case_clause, _},_}} = (catch extension(ER, E, foo)), + {'EXIT', {type_mismatch, _}} = (catch extension(ER, E, E)), + {'EXIT', {badarg, _}} = (catch extension(C2, E, E)), + eval(E, extension(E, E, E)), + eval(EF, extension(EF, E, E)), + eval(family([{3,[]}]), extension(EF, set([3]), E)), + eval(ER, extension(ER, E, C1)), + eval(E, extension(E, ER, E)), + eval(from_term([],[{{atom,atom},type(ER)}]), extension(E, ER, ER)), + + R1 = relation([{c,7},{c,9},{c,11},{d,17},{f,20}]), + S1 = set([a,c,d,e]), + eval(extension(R1, S1, C1), lextension(R1, S1, C1)), + + S2 = set([1,2,3]), + eval(extension(ER, S2, C1), lextension(ER, S2, C1)), + + R3 = relation([{4,a},{8,b}]), + S3 = set([1,2,3,4,5,6,7,8,9,10,11]), + eval(extension(R3, S3, C1), lextension(R3, S3, C1)), + + R4 = relation([{2,b},{4,d},{6,f}]), + S4 = set([1,3,5,7]), + eval(extension(R4, S4, C1), lextension(R4, S4, C1)), + + F1 = family([{a,[1]},{c,[2]}]), + S5 = set([a,b,c,d]), + eval(extension(F1, S5, C2), lextension(F1, S5, C2)), ok. lextension(R, S, C) -> union(R, drestriction(1, constant_function(S, C), domain(R))). -weak_relation_1(suite) -> []; -weak_relation_1(doc) -> [""]; weak_relation_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([], 2), - ?line eval(weak_relation(E), E), - ?line eval(weak_relation(ER), ER), - ?line eval(weak_relation(relation([{a,1},{a,2},{b,2},{c,c}])), - relation([{1,1},{2,2},{a,1},{a,2},{a,a},{b,2},{b,b},{c,c}])), - ?line eval(weak_relation(relation([{a,1},{a,a},{a,b}])), - relation([{1,1},{a,1},{a,a},{a,b},{b,b}])), - ?line eval(weak_relation(relation([{a,1},{a,b},{7,w}])), - relation([{1,1},{7,7},{7,w},{a,1},{a,a},{a,b},{b,b},{w,w}])), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + ER = relation([], 2), + eval(weak_relation(E), E), + eval(weak_relation(ER), ER), + eval(weak_relation(relation([{a,1},{a,2},{b,2},{c,c}])), + relation([{1,1},{2,2},{a,1},{a,2},{a,a},{b,2},{b,b},{c,c}])), + eval(weak_relation(relation([{a,1},{a,a},{a,b}])), + relation([{1,1},{a,1},{a,a},{a,b},{b,b}])), + eval(weak_relation(relation([{a,1},{a,b},{7,w}])), + relation([{1,1},{7,7},{7,w},{a,1},{a,a},{a,b},{b,b},{w,w}])), + {'EXIT', {badarg, _}} = (catch weak_relation(from_term([{{a},a}]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch weak_relation(from_term([{a,a}],[{d,r}]))), - ?line {'EXIT', {badarg, _}} = (catch weak_relation(relation([{1,2,3}]))), + {'EXIT', {badarg, _}} = (catch weak_relation(relation([{1,2,3}]))), F = 0.0, I = round(F), if F == I -> % term ordering - ?line FR1 = relation([{F,I}]), + FR1 = relation([{F,I}]), eval(weak_relation(FR1), FR1), - ?line FR2 = relation([{F,2},{I,1}]), + FR2 = relation([{F,2},{I,1}]), true = no_elements(weak_relation(FR2)) =:= 5, - ?line FR3 = relation([{1,0},{1.0,1}]), + FR3 = relation([{1,0},{1.0,1}]), true = no_elements(weak_relation(FR3)) =:= 3; true -> ok end, ok. -to_sets_1(suite) -> []; -to_sets_1(doc) -> [""]; to_sets_1(Conf) when is_list(Conf) -> - ?line {'EXIT', {badarg, _}} = (catch to_sets(from_term(a))), - ?line {'EXIT', {function_clause, _}} = (catch to_sets(a)), + {'EXIT', {badarg, _}} = (catch to_sets(from_term(a))), + {'EXIT', {function_clause, _}} = (catch to_sets(a)), %% unordered - ?line [] = to_sets(empty_set()), - ?line eval(to_sets(from_term([a])), [from_term(a)]), - ?line eval(to_sets(from_term([[]],[[atom]])), [set([])]), + [] = to_sets(empty_set()), + eval(to_sets(from_term([a])), [from_term(a)]), + eval(to_sets(from_term([[]],[[atom]])), [set([])]), - ?line L = [from_term([a,b]),from_term([c,d])], - ?line eval(to_sets(from_sets(L)), L), + L = [from_term([a,b]),from_term([c,d])], + eval(to_sets(from_sets(L)), L), - ?line eval(to_sets(relation([{a,1},{b,2}])), - [from_term({a,1},{atom,atom}), from_term({b,2},{atom,atom})]), + eval(to_sets(relation([{a,1},{b,2}])), + [from_term({a,1},{atom,atom}), from_term({b,2},{atom,atom})]), %% ordered - ?line O = {from_term(a,atom), from_term({b}, {atom}), set([c,d])}, - ?line eval(to_sets(from_sets(O)), O), + O = {from_term(a,atom), from_term({b}, {atom}), set([c,d])}, + eval(to_sets(from_sets(O)), O), ok. -specification(suite) -> []; -specification(doc) -> [""]; specification(Conf) when is_list(Conf) -> Fun = {external, fun(I) when is_integer(I) -> true; (_) -> false end}, - ?line [1,2,3] = to_external(specification(Fun, set([a,1,b,2,c,3]))), + [1,2,3] = to_external(specification(Fun, set([a,1,b,2,c,3]))), Fun2 = fun(S) -> is_subset(S, set([1,3,5,7,9])) end, S2 = from_term([[1],[2],[3],[4],[5],[6],[7]]), - ?line eval(specification(Fun2, S2), from_term([[1],[3],[5],[7]])), + eval(specification(Fun2, S2), from_term([[1],[3],[5],[7]])), Fun2x = fun([1]) -> true; ([3]) -> true; (_) -> false end, - ?line eval(specification({external,Fun2x}, S2), from_term([[1],[3]])), + eval(specification({external,Fun2x}, S2), from_term([[1],[3]])), Fun3 = fun(_) -> neither_true_nor_false end, - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch specification(Fun3, set([a]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch specification({external, Fun3}, set([a]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch specification(Fun3, from_term([[a]]))), - ?line {'EXIT', {function_clause, _}} = + {'EXIT', {function_clause, _}} = (catch specification(Fun, a)), ok. -union_1(suite) -> []; -union_1(doc) -> [""]; union_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([], 2), - ?line {'EXIT', {badarg, _}} = (catch union(ER)), - ?line {'EXIT', {type_mismatch, _}} = + E = empty_set(), + ER = relation([], 2), + {'EXIT', {badarg, _}} = (catch union(ER)), + {'EXIT', {type_mismatch, _}} = (catch union(relation([{a,b}]), relation([{a,b,c}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch union(from_term([{a,b}]), from_term([{c,[x]}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch union(from_term([{a,b}]), from_term([{c,d}], [{d,r}]))), - ?line {'EXIT', {badarg, _}} = (catch union(set([a,b,c]))), - ?line eval(union(E), E), - ?line eval(union(from_term([[]],[[atom]])), set([])), - ?line eval(union(from_term([[{a,b},{b,c}],[{b,c}]])), - relation([{a,b},{b,c}])), - ?line eval(union(from_term([[1,2,3],[2,3,4],[3,4,5]])), - set([1,2,3,4,5])), - - ?line eval(union(from_term([{[a],[],c}]), from_term([{[],[],q}])), - from_term([{[a],[],c},{[],[],q}])), - - ?line eval(union(E, E), E), - ?line eval(union(set([a,b]), E), set([a,b])), - ?line eval(union(E, set([a,b])), set([a,b])), - - ?line eval(union(from_term([[a,b]])), from_term([a,b])), + {'EXIT', {badarg, _}} = (catch union(set([a,b,c]))), + eval(union(E), E), + eval(union(from_term([[]],[[atom]])), set([])), + eval(union(from_term([[{a,b},{b,c}],[{b,c}]])), + relation([{a,b},{b,c}])), + eval(union(from_term([[1,2,3],[2,3,4],[3,4,5]])), + set([1,2,3,4,5])), + + eval(union(from_term([{[a],[],c}]), from_term([{[],[],q}])), + from_term([{[a],[],c},{[],[],q}])), + + eval(union(E, E), E), + eval(union(set([a,b]), E), set([a,b])), + eval(union(E, set([a,b])), set([a,b])), + + eval(union(from_term([[a,b]])), from_term([a,b])), ok. -intersection_1(suite) -> []; -intersection_1(doc) -> [""]; intersection_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line {'EXIT', {badarg, _}} = (catch intersection(from_term([a,b]))), - ?line {'EXIT', {badarg, _}} = (catch intersection(E)), - ?line {'EXIT', {type_mismatch, _}} = + E = empty_set(), + {'EXIT', {badarg, _}} = (catch intersection(from_term([a,b]))), + {'EXIT', {badarg, _}} = (catch intersection(E)), + {'EXIT', {type_mismatch, _}} = (catch intersection(relation([{a,b}]), relation([{a,b,c}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch intersection(relation([{a,b}]), from_term([{a,b}],[{d,r}]))), - ?line eval(intersection(from_term([[a,b,c],[d,e,f],[g,h,i]])), set([])), - - ?line eval(intersection(E, E), E), - ?line eval(intersection(set([a,b,c]),set([0,b,q])), - set([b])), - ?line eval(intersection(set([0,b,q]),set([a,b,c])), - set([b])), - ?line eval(intersection(set([a,b,c]),set([a,b,c])), - set([a,b,c])), - ?line eval(intersection(set([a,b,d]),set([c,d])), - set([d])), + eval(intersection(from_term([[a,b,c],[d,e,f],[g,h,i]])), set([])), + + eval(intersection(E, E), E), + eval(intersection(set([a,b,c]),set([0,b,q])), + set([b])), + eval(intersection(set([0,b,q]),set([a,b,c])), + set([b])), + eval(intersection(set([a,b,c]),set([a,b,c])), + set([a,b,c])), + eval(intersection(set([a,b,d]),set([c,d])), + set([d])), ok. -difference(suite) -> []; -difference(doc) -> [""]; difference(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line {'EXIT', {type_mismatch, _}} = + E = empty_set(), + {'EXIT', {type_mismatch, _}} = (catch difference(relation([{a,b}]), relation([{a,b,c}]))), - ?line eval(difference(E, E), E), - ?line {'EXIT', {type_mismatch, _}} = + eval(difference(E, E), E), + {'EXIT', {type_mismatch, _}} = (catch difference(relation([{a,b}]), from_term([{a,c}],[{d,r}]))), - ?line eval(difference(set([a,b,c,d,f]), set([a,d,e,g])), - set([b,c,f])), - ?line eval(difference(set([a,b,c]), set([d,e,f])), - set([a,b,c])), - ?line eval(difference(set([a,b,c]), set([a,b,c,d,e,f])), - set([])), - ?line eval(difference(set([e,f,g]), set([a,b,c,e])), - set([f,g])), - ?line eval(difference(set([a,b,d,e,f]), set([c])), - set([a,b,d,e,f])), + eval(difference(set([a,b,c,d,f]), set([a,d,e,g])), + set([b,c,f])), + eval(difference(set([a,b,c]), set([d,e,f])), + set([a,b,c])), + eval(difference(set([a,b,c]), set([a,b,c,d,e,f])), + set([])), + eval(difference(set([e,f,g]), set([a,b,c,e])), + set([f,g])), + eval(difference(set([a,b,d,e,f]), set([c])), + set([a,b,d,e,f])), ok. -symdiff(suite) -> []; -symdiff(doc) -> [""]; symdiff(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line {'EXIT', {type_mismatch, _}} = + E = empty_set(), + {'EXIT', {type_mismatch, _}} = (catch symdiff(relation([{a,b}]), relation([{a,b,c}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch symdiff(relation([{a,b}]), from_term([{a,b}], [{d,r}]))), - ?line eval(symdiff(E, E), E), - ?line eval(symdiff(set([a,b,c,d,e,f]), set([0,1,a,c])), - union(set([b,d,e,f]), set([0,1]))), - ?line eval(symdiff(set([a,b,c]), set([q,v,w,x,y])), - union(set([a,b,c]), set([q,v,w,x,y]))), - ?line eval(symdiff(set([a,b,c,d,e,f]), set([a,b,c])), - set([d,e,f])), - ?line eval(symdiff(set([c,e,g,h,i]), set([b,d,f])), - union(set([c,e,g,h,i]), set([b,d,f]))), - ?line eval(symdiff(set([c,d,g,h,k,l]), - set([a,b,e,f,i,j,m,n])), - union(set([c,d,g,h,k,l]), set([a,b,e,f,i,j,m,n]))), - ?line eval(symdiff(set([c,d,g,h,k,l]), - set([d,e,h,i,l,m,n,o,p])), - union(set([c,g,k]), set([e,i,m,n,o,p]))), + eval(symdiff(E, E), E), + eval(symdiff(set([a,b,c,d,e,f]), set([0,1,a,c])), + union(set([b,d,e,f]), set([0,1]))), + eval(symdiff(set([a,b,c]), set([q,v,w,x,y])), + union(set([a,b,c]), set([q,v,w,x,y]))), + eval(symdiff(set([a,b,c,d,e,f]), set([a,b,c])), + set([d,e,f])), + eval(symdiff(set([c,e,g,h,i]), set([b,d,f])), + union(set([c,e,g,h,i]), set([b,d,f]))), + eval(symdiff(set([c,d,g,h,k,l]), + set([a,b,e,f,i,j,m,n])), + union(set([c,d,g,h,k,l]), set([a,b,e,f,i,j,m,n]))), + eval(symdiff(set([c,d,g,h,k,l]), + set([d,e,h,i,l,m,n,o,p])), + union(set([c,g,k]), set([e,i,m,n,o,p]))), ok. -symmetric_partition(suite) -> []; -symmetric_partition(doc) -> [""]; symmetric_partition(Conf) when is_list(Conf) -> - ?line E = set([]), - ?line S1 = set([1,2,3,4]), - ?line S2 = set([3,4,5,6]), - ?line S3 = set([3,4]), - ?line S4 = set([1,2,3,4,5,6]), - ?line T1 = set([1,2]), - ?line T2 = set([3,4]), - ?line T3 = set([5,6]), - ?line T4 = set([1,2,5,6]), - ?line {'EXIT', {type_mismatch, _}} = + E = set([]), + S1 = set([1,2,3,4]), + S2 = set([3,4,5,6]), + S3 = set([3,4]), + S4 = set([1,2,3,4,5,6]), + T1 = set([1,2]), + T2 = set([3,4]), + T3 = set([5,6]), + T4 = set([1,2,5,6]), + {'EXIT', {type_mismatch, _}} = (catch symmetric_partition(relation([{a,b}]), relation([{a,b,c}]))), - ?line {E, E, E} = symmetric_partition(E, E), - ?line {'EXIT', {type_mismatch, _}} = + {E, E, E} = symmetric_partition(E, E), + {'EXIT', {type_mismatch, _}} = (catch symmetric_partition(relation([{a,b}]), from_term([{a,c}],[{d,r}]))), - ?line {E, E, S1} = symmetric_partition(E, S1), - ?line {S1, E, E} = symmetric_partition(S1, E), - ?line {T1, T2, T3} = symmetric_partition(S1, S2), - ?line {T3, T2, T1} = symmetric_partition(S2, S1), - ?line {E, T2, T4} = symmetric_partition(S3, S4), - ?line {T4, T2, E} = symmetric_partition(S4, S3), - - ?line S5 = set([1,3,5]), - ?line S6 = set([2,4,6,7,8]), - ?line {S5, E, S6} = symmetric_partition(S5, S6), - ?line {S6, E, S5} = symmetric_partition(S6, S5), - ?line EE = empty_set(), - ?line {EE, EE, EE} = symmetric_partition(EE, EE), + {E, E, S1} = symmetric_partition(E, S1), + {S1, E, E} = symmetric_partition(S1, E), + {T1, T2, T3} = symmetric_partition(S1, S2), + {T3, T2, T1} = symmetric_partition(S2, S1), + {E, T2, T4} = symmetric_partition(S3, S4), + {T4, T2, E} = symmetric_partition(S4, S3), + + S5 = set([1,3,5]), + S6 = set([2,4,6,7,8]), + {S5, E, S6} = symmetric_partition(S5, S6), + {S6, E, S5} = symmetric_partition(S6, S5), + EE = empty_set(), + {EE, EE, EE} = symmetric_partition(EE, EE), ok. -is_sofs_set_1(suite) -> []; -is_sofs_set_1(doc) -> [""]; is_sofs_set_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line true = is_sofs_set(E), - ?line true = is_sofs_set(from_term([a])), - ?line true = is_sofs_set(from_term({a})), - ?line true = is_sofs_set(from_term(a)), - ?line false = is_sofs_set(a), + E = empty_set(), + true = is_sofs_set(E), + true = is_sofs_set(from_term([a])), + true = is_sofs_set(from_term({a})), + true = is_sofs_set(from_term(a)), + false = is_sofs_set(a), ok. -is_set_1(suite) -> []; -is_set_1(doc) -> [""]; is_set_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line true = is_set(E), - ?line true = is_set(from_term([a])), - ?line false = is_set(from_term({a})), - ?line false = is_set(from_term(a)), - ?line {'EXIT', _} = (catch is_set(a)), - - ?line true = is_empty_set(E), - ?line false = is_empty_set(from_term([a])), - ?line false = is_empty_set(from_term({a})), - ?line false = is_empty_set(from_term(a)), - ?line {'EXIT', _} = (catch is_empty_set(a)), + E = empty_set(), + true = is_set(E), + true = is_set(from_term([a])), + false = is_set(from_term({a})), + false = is_set(from_term(a)), + {'EXIT', _} = (catch is_set(a)), + + true = is_empty_set(E), + false = is_empty_set(from_term([a])), + false = is_empty_set(from_term({a})), + false = is_empty_set(from_term(a)), + {'EXIT', _} = (catch is_empty_set(a)), ok. -is_equal(suite) -> []; -is_equal(doc) -> [""]; is_equal(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line true = is_equal(E, E), - ?line false = is_equal(from_term([a]), E), - ?line {'EXIT', {type_mismatch, _}} = + E = empty_set(), + true = is_equal(E, E), + false = is_equal(from_term([a]), E), + {'EXIT', {type_mismatch, _}} = (catch is_equal(intersection(set([a]), set([b])), intersection(from_term([{a}]), from_term([{b}])))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch is_equal(from_term([],[{[atom],atom,[atom]}]), from_term([],[{[atom],{atom},[atom]}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch is_equal(set([a]), from_term([a],[type]))), - ?line E2 = from_sets({from_term(a,atom)}), - ?line true = is_equal(E2, E2), - ?line true = is_equal(from_term({a}, {atom}), E2), - ?line false = is_equal(from_term([{[a],[],c}]), - from_term([{[],[],q}])), + E2 = from_sets({from_term(a,atom)}), + true = is_equal(E2, E2), + true = is_equal(from_term({a}, {atom}), E2), + false = is_equal(from_term([{[a],[],c}]), + from_term([{[],[],q}])), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch is_equal(E, E2)), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch is_equal(E2, E)), - ?line true = is_equal(from_term({[],a,[]},{[atom],atom,[atom]}), - from_term({[],a,[]},{[atom],atom,[atom]})), - ?line {'EXIT', {type_mismatch, _}} = + true = is_equal(from_term({[],a,[]},{[atom],atom,[atom]}), + from_term({[],a,[]},{[atom],atom,[atom]})), + {'EXIT', {type_mismatch, _}} = (catch is_equal(from_term({[],a,[]},{[atom],atom,[atom]}), from_term({[],{a},[]},{[atom],{atom},[atom]}))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch is_equal(from_term({a}), from_term({a},{type}))), ok. -is_subset(suite) -> []; -is_subset(doc) -> [""]; is_subset(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line true = is_subset(E, E), - ?line true = is_subset(set([a,c,e]), set([a,b,c,d,e])), - ?line false = is_subset(set([a,b]), E), - ?line false = is_subset(set([d,e,f]), set([b,c,d,e])), - ?line false = is_subset(set([a,b,c]), set([b,c])), - ?line false = is_subset(set([b,c]), set([a,c])), - ?line false = is_subset(set([d,e]), set([a,b])), - ?line {'EXIT', {type_mismatch, _}} = + E = empty_set(), + true = is_subset(E, E), + true = is_subset(set([a,c,e]), set([a,b,c,d,e])), + false = is_subset(set([a,b]), E), + false = is_subset(set([d,e,f]), set([b,c,d,e])), + false = is_subset(set([a,b,c]), set([b,c])), + false = is_subset(set([b,c]), set([a,c])), + false = is_subset(set([d,e]), set([a,b])), + {'EXIT', {type_mismatch, _}} = (catch is_subset(intersection(set([a]), set([b])), intersection(from_term([{a}]), from_term([{b}])))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch is_subset(set([a]), from_term([a,b], [at]))), ok. -is_a_function_1(suite) -> []; -is_a_function_1(doc) -> [""]; is_a_function_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([], 2), - ?line {'EXIT', {badarg, _}} = (catch is_a_function(set([a,b]))), - ?line true = is_a_function(E), - ?line true = is_a_function(ER), - ?line true = is_a_function(relation([])), - ?line true = is_a_function(relation([],2)), - ?line true = is_a_function(relation([{a,b},{b,c}])), - ?line false = is_a_function(relation([{a,b},{b,c},{b,d},{e,f}])), - ?line IS = relation([{{a,b},c},{{a,b},d}]), - ?line false = is_a_function(IS), + E = empty_set(), + ER = relation([], 2), + {'EXIT', {badarg, _}} = (catch is_a_function(set([a,b]))), + true = is_a_function(E), + true = is_a_function(ER), + true = is_a_function(relation([])), + true = is_a_function(relation([],2)), + true = is_a_function(relation([{a,b},{b,c}])), + false = is_a_function(relation([{a,b},{b,c},{b,d},{e,f}])), + IS = relation([{{a,b},c},{{a,b},d}]), + false = is_a_function(IS), F = 0.0, I = round(F), - ?line FR = relation([{I,F},{F,1}]), + FR = relation([{I,F},{F,1}]), if F == I -> % term ordering false = is_a_function(FR); @@ -1280,343 +1229,315 @@ is_a_function_1(Conf) when is_list(Conf) -> end, ok. -is_disjoint(suite) -> []; -is_disjoint(doc) -> [""]; is_disjoint(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line {'EXIT', {type_mismatch, _}} = + E = empty_set(), + {'EXIT', {type_mismatch, _}} = (catch is_disjoint(relation([{a,1}]), set([a,b]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch is_disjoint(set([a]), from_term([a],[mota]))), - ?line true = is_disjoint(E, E), - ?line false = is_disjoint(set([a,b,c]),set([b,c,d])), - ?line false = is_disjoint(set([b,c,d]),set([a,b,c])), - ?line true = is_disjoint(set([a,c,e]),set([b,d,f])), + true = is_disjoint(E, E), + false = is_disjoint(set([a,b,c]),set([b,c,d])), + false = is_disjoint(set([b,c,d]),set([a,b,c])), + true = is_disjoint(set([a,c,e]),set([b,d,f])), ok. -join(suite) -> []; -join(doc) -> [""]; join(Conf) when is_list(Conf) -> - ?line E = empty_set(), - - ?line {'EXIT', {badarg, _}} = (catch join(relation([{a,1}]), 3, E, 5)), - ?line {'EXIT', {badarg, _}} = (catch join(E, 1, relation([{a,1}]), 3)), - ?line {'EXIT', {badarg, _}} = (catch join(E, 1, from_term([a]), 1)), - - ?line eval(join(E, 1, E, 2), E), - ?line eval(join(E, 1, from_term([{{a},b}]), 2), E), - ?line eval(join(from_term([{{a},b}]), 2, E, 1), E), - ?line eval(join(from_term([{{a},b,e}]), 2, from_term([{c,{d}}]), 1), - from_term([], [{{atom},atom,atom,{atom}}])), - ?line eval(join(relation([{a}]), 1, relation([{1,a},{2,a}]), 2), - relation([{a,1},{a,2}])), - ?line eval(join(relation([{a,b,c},{b,c,d}]), 2, - relation([{1,b},{2,a},{3,c}]), 2), - relation([{a,b,c,1},{b,c,d,3}])), - ?line eval(join(relation([{1,a,aa},{1,b,bb},{1,c,cc},{2,a,aa},{2,b,bb}]), - 1, - relation([{1,c,cc},{1,d,dd},{1,e,ee},{2,c,cc},{2,d,dd}]), - 1), - relation([{1,a,aa,c,cc},{1,a,aa,d,dd},{1,a,aa,e,ee},{1,b,bb,c,cc}, - {1,b,bb,d,dd},{1,b,bb,e,ee},{1,c,cc,c,cc},{1,c,cc,d,dd}, - {1,c,cc,e,ee},{2,a,aa,c,cc},{2,a,aa,d,dd},{2,b,bb,c,cc}, - {2,b,bb,d,dd}])), + E = empty_set(), + + {'EXIT', {badarg, _}} = (catch join(relation([{a,1}]), 3, E, 5)), + {'EXIT', {badarg, _}} = (catch join(E, 1, relation([{a,1}]), 3)), + {'EXIT', {badarg, _}} = (catch join(E, 1, from_term([a]), 1)), + + eval(join(E, 1, E, 2), E), + eval(join(E, 1, from_term([{{a},b}]), 2), E), + eval(join(from_term([{{a},b}]), 2, E, 1), E), + eval(join(from_term([{{a},b,e}]), 2, from_term([{c,{d}}]), 1), + from_term([], [{{atom},atom,atom,{atom}}])), + eval(join(relation([{a}]), 1, relation([{1,a},{2,a}]), 2), + relation([{a,1},{a,2}])), + eval(join(relation([{a,b,c},{b,c,d}]), 2, + relation([{1,b},{2,a},{3,c}]), 2), + relation([{a,b,c,1},{b,c,d,3}])), + eval(join(relation([{1,a,aa},{1,b,bb},{1,c,cc},{2,a,aa},{2,b,bb}]), + 1, + relation([{1,c,cc},{1,d,dd},{1,e,ee},{2,c,cc},{2,d,dd}]), + 1), + relation([{1,a,aa,c,cc},{1,a,aa,d,dd},{1,a,aa,e,ee},{1,b,bb,c,cc}, + {1,b,bb,d,dd},{1,b,bb,e,ee},{1,c,cc,c,cc},{1,c,cc,d,dd}, + {1,c,cc,e,ee},{2,a,aa,c,cc},{2,a,aa,d,dd},{2,b,bb,c,cc}, + {2,b,bb,d,dd}])), R1 = relation([{a,b},{b,c}]), R2 = relation([{b,1},{a,2},{c,3},{c,4}]), - ?line eval(join(R1, 1, R2, 1), from_term([{a,b,2},{b,c,1}])), - ?line eval(join(R1, 2, R2, 1), from_term([{a,b,1},{b,c,3},{b,c,4}])), - ?line eval(join(R1, 1, converse(R2), 2), - from_term([{a,b,2},{b,c,1}])), - ?line eval(join(R1, 2, converse(R2), 2), - from_term([{a,b,1},{b,c,3},{b,c,4}])), + eval(join(R1, 1, R2, 1), from_term([{a,b,2},{b,c,1}])), + eval(join(R1, 2, R2, 1), from_term([{a,b,1},{b,c,3},{b,c,4}])), + eval(join(R1, 1, converse(R2), 2), + from_term([{a,b,2},{b,c,1}])), + eval(join(R1, 2, converse(R2), 2), + from_term([{a,b,1},{b,c,3},{b,c,4}])), ok. -canonical(suite) -> []; -canonical(doc) -> [""]; canonical(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + {'EXIT', {badarg, _}} = (catch canonical_relation(set([a,b]))), - ?line eval(canonical_relation(E), E), - ?line eval(canonical_relation(from_term([[]])), E), - ?line eval(canonical_relation(from_term([[a,b,c]])), - from_term([{a,[a,b,c]},{b,[a,b,c]},{c,[a,b,c]}])), + eval(canonical_relation(E), E), + eval(canonical_relation(from_term([[]])), E), + eval(canonical_relation(from_term([[a,b,c]])), + from_term([{a,[a,b,c]},{b,[a,b,c]},{c,[a,b,c]}])), ok. -relation_to_family_1(suite) -> []; -relation_to_family_1(doc) -> [""]; relation_to_family_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line EF = family([]), - ?line eval(relation_to_family(E), E), - ?line eval(relation_to_family(relation([])), EF), - ?line eval(relation_to_family(relation([], 2)), EF), - ?line R = relation([{b,1},{c,7},{c,9},{c,11}]), - ?line F = family([{b,[1]},{c,[7,9,11]}]), - ?line eval(relation_to_family(R), F), - ?line eval(sofs:rel2fam(R), F), - ?line {'EXIT', {badarg, _}} = (catch relation_to_family(set([a]))), + E = empty_set(), + EF = family([]), + eval(relation_to_family(E), E), + eval(relation_to_family(relation([])), EF), + eval(relation_to_family(relation([], 2)), EF), + R = relation([{b,1},{c,7},{c,9},{c,11}]), + F = family([{b,[1]},{c,[7,9,11]}]), + eval(relation_to_family(R), F), + eval(sofs:rel2fam(R), F), + {'EXIT', {badarg, _}} = (catch relation_to_family(set([a]))), ok. -domain_1(suite) -> []; -domain_1(doc) -> [""]; domain_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), - ?line {'EXIT', {badarg, _}} = (catch domain(relation([],3))), - ?line eval(domain(E), E), - ?line eval(domain(ER), set([])), - ?line eval(domain(relation([{1,a},{1,b},{2,a},{2,b}])), set([1,2])), - ?line eval(domain(relation([{a,1},{b,2},{c,3}])), set([a,b,c])), - ?line eval(field(relation([{a,1},{b,2},{c,3}])), - set([a,b,c,1,2,3])), + E = empty_set(), + ER = relation([]), + {'EXIT', {badarg, _}} = (catch domain(relation([],3))), + eval(domain(E), E), + eval(domain(ER), set([])), + eval(domain(relation([{1,a},{1,b},{2,a},{2,b}])), set([1,2])), + eval(domain(relation([{a,1},{b,2},{c,3}])), set([a,b,c])), + eval(field(relation([{a,1},{b,2},{c,3}])), + set([a,b,c,1,2,3])), F = 0.0, I = round(F), - ?line FR = relation([{I,a},{F,b}]), + FR = relation([{I,a},{F,b}]), if F == I -> % term ordering - ?line true = (1 =:= no_elements(domain(FR))); + true = (1 =:= no_elements(domain(FR))); true -> - ?line true = (2 =:= no_elements(domain(FR))) + true = (2 =:= no_elements(domain(FR))) end, ok. -range_1(suite) -> []; -range_1(doc) -> [""]; range_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), - ?line {'EXIT', {badarg, _}} = (catch range(relation([],3))), - ?line eval(range(E), E), - ?line eval(range(ER), set([])), - ?line eval(range(relation([{1,a},{1,b},{2,a},{2,b}])), set([a,b])), - ?line eval(range(relation([{a,1},{b,2},{c,3}])), set([1,2,3])), + E = empty_set(), + ER = relation([]), + {'EXIT', {badarg, _}} = (catch range(relation([],3))), + eval(range(E), E), + eval(range(ER), set([])), + eval(range(relation([{1,a},{1,b},{2,a},{2,b}])), set([a,b])), + eval(range(relation([{a,1},{b,2},{c,3}])), set([1,2,3])), ok. - -inverse_1(suite) -> []; -inverse_1(doc) -> [""]; + inverse_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), - ?line {'EXIT', {badarg, _}} = (catch inverse(relation([],3))), - ?line {'EXIT', {bad_function, _}} = + E = empty_set(), + ER = relation([]), + {'EXIT', {badarg, _}} = (catch inverse(relation([],3))), + {'EXIT', {bad_function, _}} = (catch inverse(relation([{1,a},{1,b}]))), - ?line {'EXIT', {bad_function, _}} = + {'EXIT', {bad_function, _}} = (catch inverse(relation([{1,a},{2,a}]))), - ?line eval(inverse(E), E), - ?line eval(inverse(ER), ER), - ?line eval(inverse(relation([{a,1},{b,2},{c,3}])), - relation([{1,a},{2,b},{3,c}])), + eval(inverse(E), E), + eval(inverse(ER), ER), + eval(inverse(relation([{a,1},{b,2},{c,3}])), + relation([{1,a},{2,b},{3,c}])), F = 0.0, I = round(F), - ?line FR = relation([{I,a},{F,b}]), + FR = relation([{I,a},{F,b}]), if F == I -> % term ordering - ?line {'EXIT', {bad_function, _}} = (catch inverse(FR)); + {'EXIT', {bad_function, _}} = (catch inverse(FR)); true -> - ?line eval(inverse(FR), relation([{a,I},{b,F}])) + eval(inverse(FR), relation([{a,I},{b,F}])) end, ok. - -converse_1(suite) -> []; -converse_1(doc) -> [""]; + converse_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), - ?line {'EXIT', {badarg, _}} = (catch converse(relation([],3))), - ?line eval(converse(ER), ER), - ?line eval(converse(E), E), - ?line eval(converse(relation([{a,1},{b,2},{c,3}])), - relation([{1,a},{2,b},{3,c}])), - ?line eval(converse(relation([{1,a},{1,b}])), - relation([{a,1},{b,1}])), - ?line eval(converse(relation([{1,a},{2,a}])), - relation([{a,1},{a,2}])), + E = empty_set(), + ER = relation([]), + {'EXIT', {badarg, _}} = (catch converse(relation([],3))), + eval(converse(ER), ER), + eval(converse(E), E), + eval(converse(relation([{a,1},{b,2},{c,3}])), + relation([{1,a},{2,b},{3,c}])), + eval(converse(relation([{1,a},{1,b}])), + relation([{a,1},{b,1}])), + eval(converse(relation([{1,a},{2,a}])), + relation([{a,1},{a,2}])), ok. - -no_elements_1(suite) -> []; -no_elements_1(doc) -> [""]; + no_elements_1(Conf) when is_list(Conf) -> - ?line 0 = no_elements(empty_set()), - ?line 0 = no_elements(set([])), - ?line 1 = no_elements(from_term([a])), - ?line 10 = no_elements(from_term(lists:seq(1,10))), - ?line 3 = no_elements(from_term({a,b,c},{atom,atom,atom})), - ?line {'EXIT', {badarg, _}} = (catch no_elements(from_term(a))), - ?line {'EXIT', {function_clause, _}} = (catch no_elements(a)), + 0 = no_elements(empty_set()), + 0 = no_elements(set([])), + 1 = no_elements(from_term([a])), + 10 = no_elements(from_term(lists:seq(1,10))), + 3 = no_elements(from_term({a,b,c},{atom,atom,atom})), + {'EXIT', {badarg, _}} = (catch no_elements(from_term(a))), + {'EXIT', {function_clause, _}} = (catch no_elements(a)), ok. -image(suite) -> []; -image(doc) -> [""]; image(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), - ?line eval(image(E, E), E), - ?line eval(image(ER, E), set([])), - ?line eval(image(relation([{a,1},{b,2},{c,3},{f,6}]), set([a,b,c,d,f])), - set([1,2,3,6])), - ?line eval(image(relation([{a,1},{b,2},{c,3},{d,4},{r,17}]), - set([b,c,q,r])), - set([2,3,17])), - ?line eval(image(from_term([{[a],{1}},{[b],{2}}]), from_term([[a]])), - from_term([{1}])), - ?line eval(image(relation([{1,a},{2,a},{3,a},{4,b},{2,b}]), set([1,2,4])), - set([a,b])), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + ER = relation([]), + eval(image(E, E), E), + eval(image(ER, E), set([])), + eval(image(relation([{a,1},{b,2},{c,3},{f,6}]), set([a,b,c,d,f])), + set([1,2,3,6])), + eval(image(relation([{a,1},{b,2},{c,3},{d,4},{r,17}]), + set([b,c,q,r])), + set([2,3,17])), + eval(image(from_term([{[a],{1}},{[b],{2}}]), from_term([[a]])), + from_term([{1}])), + eval(image(relation([{1,a},{2,a},{3,a},{4,b},{2,b}]), set([1,2,4])), + set([a,b])), + {'EXIT', {badarg, _}} = (catch image(from_term([a,b]), E)), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch image(from_term([{[a],1}]), set([[a]]))), ok. -inverse_image(suite) -> []; -inverse_image(doc) -> [""]; inverse_image(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), - ?line eval(inverse_image(E, E), E), - ?line eval(inverse_image(ER, E), set([])), - ?line eval(inverse_image(converse(relation([{a,1},{b,2},{c,3},{f,6}])), - set([a,b,c,d,f])), - set([1,2,3,6])), - ?line eval(inverse_image(converse(relation([{a,1},{b,2},{c,3}, - {d,4},{r,17}])), - set([b,c,q,r])), - set([2,3,17])), - ?line eval(inverse_image(converse(from_term([{[a],{1}},{[b],{2}}])), - from_term([[a]])), - from_term([{1}])), - ?line eval(inverse_image(converse(relation([{1,a},{2,a}, - {3,a},{4,b},{2,b}])), - set([1,2,4])), - set([a,b])), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + ER = relation([]), + eval(inverse_image(E, E), E), + eval(inverse_image(ER, E), set([])), + eval(inverse_image(converse(relation([{a,1},{b,2},{c,3},{f,6}])), + set([a,b,c,d,f])), + set([1,2,3,6])), + eval(inverse_image(converse(relation([{a,1},{b,2},{c,3}, + {d,4},{r,17}])), + set([b,c,q,r])), + set([2,3,17])), + eval(inverse_image(converse(from_term([{[a],{1}},{[b],{2}}])), + from_term([[a]])), + from_term([{1}])), + eval(inverse_image(converse(relation([{1,a},{2,a}, + {3,a},{4,b},{2,b}])), + set([1,2,4])), + set([a,b])), + {'EXIT', {badarg, _}} = (catch inverse_image(from_term([a,b]), E)), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch inverse_image(converse(from_term([{[a],1}])), set([[a]]))), ok. -composite_1(suite) -> []; -composite_1(doc) -> [""]; composite_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line EF = a_function([]), - ?line eval(composite(E, E), E), - ?line eval(composite(E, a_function([{a,b}])), E), - ?line eval(composite(relation([{a,b}]), E), E), - ?line {'EXIT', {bad_function, _}} = + E = empty_set(), + EF = a_function([]), + eval(composite(E, E), E), + eval(composite(E, a_function([{a,b}])), E), + eval(composite(relation([{a,b}]), E), E), + {'EXIT', {bad_function, _}} = (catch composite(EF, relation([{a,b},{a,c}]))), - ?line {'EXIT', {bad_function, _}} = + {'EXIT', {bad_function, _}} = (catch composite(a_function([{b,a}]), EF)), - ?line {'EXIT', {bad_function, _}} = + {'EXIT', {bad_function, _}} = (catch composite(relation([{1,a},{2,b},{2,a}]), a_function([{a,1},{b,3}]))), - ?line {'EXIT', {bad_function, _}} = - (catch composite(a_function([{1,a},{2,b}]), a_function([{b,3}]))), - ?line eval(composite(EF, EF), EF), - ?line eval(composite(a_function([{b,a}]), from_term([{a,{b,c}}])), - from_term([{b,{b,c}}])), - ?line eval(composite(a_function([{q,1},{z,2}]), - a_function([{1,a},{2,a}])), - a_function([{q,a},{z,a}])), - ?line eval(composite(a_function([{a,0},{b,0},{c,1},{d,1},{e,2},{f,3}]), - a_function([{0,p},{1,q},{2,r},{3,w},{4,aa}])), - a_function([{c,q},{d,q},{f,w},{e,r},{a,p},{b,p}])), - ?line eval(composite(a_function([{1,c}]), - a_function([{a,1},{b,3},{c,4}])), - a_function([{1,4}])), - ?line {'EXIT', {bad_function, _}} = + {'EXIT', {bad_function, _}} = + (catch composite(a_function([{1,a},{2,b}]), a_function([{b,3}]))), + eval(composite(EF, EF), EF), + eval(composite(a_function([{b,a}]), from_term([{a,{b,c}}])), + from_term([{b,{b,c}}])), + eval(composite(a_function([{q,1},{z,2}]), + a_function([{1,a},{2,a}])), + a_function([{q,a},{z,a}])), + eval(composite(a_function([{a,0},{b,0},{c,1},{d,1},{e,2},{f,3}]), + a_function([{0,p},{1,q},{2,r},{3,w},{4,aa}])), + a_function([{c,q},{d,q},{f,w},{e,r},{a,p},{b,p}])), + eval(composite(a_function([{1,c}]), + a_function([{a,1},{b,3},{c,4}])), + a_function([{1,4}])), + {'EXIT', {bad_function, _}} = (catch composite(a_function([{1,a},{2,b}]), a_function([{a,1},{c,3}]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch composite(from_term([a,b]), E)), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch composite(E, from_term([a,b]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch composite(from_term([{a,b}]), from_term([{{a},b}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch composite(from_term([{a,b}]), from_term([{b,c}], [{d,r}]))), F = 0.0, I = round(F), - ?line FR1 = relation([{1,c}]), - ?line FR2 = relation([{I,1},{F,3},{c,4}]), + FR1 = relation([{1,c}]), + FR2 = relation([{I,1},{F,3},{c,4}]), if F == I -> % term ordering - ?line {'EXIT', {bad_function, _}} = (catch composite(FR1, FR2)); + {'EXIT', {bad_function, _}} = (catch composite(FR1, FR2)); true -> - ?line eval(composite(FR1, FR2), a_function([{1,4}])) + eval(composite(FR1, FR2), a_function([{1,4}])) end, ok. -relative_product_1(suite) -> []; -relative_product_1(doc) -> [""]; relative_product_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), - ?line eval(relative_product1(E, E), E), - ?line eval(relative_product1(E, relation([{a,b}])), E), - ?line eval(relative_product1(relation([{a,b}]), E), E), - ?line eval(relative_product1(relation([{a,b}]), from_term([{a,{b,c}}])), - from_term([{b,{b,c}}])), - ?line eval(relative_product1(relation([{1,z},{1,q},{2,z}]), - relation([{1,a},{1,b},{2,a}])), - relation([{q,a},{q,b},{z,a},{z,b}])), - ?line eval(relative_product1(relation([{0,a},{0,b},{1,c}, - {1,d},{2,e},{3,f}]), - relation([{1,q},{3,w}])), - relation([{c,q},{d,q},{f,w}])), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + ER = relation([]), + eval(relative_product1(E, E), E), + eval(relative_product1(E, relation([{a,b}])), E), + eval(relative_product1(relation([{a,b}]), E), E), + eval(relative_product1(relation([{a,b}]), from_term([{a,{b,c}}])), + from_term([{b,{b,c}}])), + eval(relative_product1(relation([{1,z},{1,q},{2,z}]), + relation([{1,a},{1,b},{2,a}])), + relation([{q,a},{q,b},{z,a},{z,b}])), + eval(relative_product1(relation([{0,a},{0,b},{1,c}, + {1,d},{2,e},{3,f}]), + relation([{1,q},{3,w}])), + relation([{c,q},{d,q},{f,w}])), + {'EXIT', {badarg, _}} = (catch relative_product1(from_term([a,b]), ER)), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch relative_product1(ER, from_term([a,b]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch relative_product1(from_term([{a,b}]), from_term([{{a},b}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch relative_product1(from_term([{a,b}]), from_term([{b,c}], [{d,r}]))), ok. -relative_product_2(suite) -> []; -relative_product_2(doc) -> [""]; relative_product_2(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), + E = empty_set(), + ER = relation([]), - ?line {'EXIT', {badarg, _}} = (catch relative_product({from_term([a,b])})), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {badarg, _}} = (catch relative_product({from_term([a,b])})), + {'EXIT', {type_mismatch, _}} = (catch relative_product({from_term([{a,b}]), from_term([{{a},b}])})), - ?line {'EXIT', {badarg, _}} = (catch relative_product({})), - ?line true = is_equal(relative_product({ER}), - from_term([], [{atom,{atom}}])), - ?line eval(relative_product({relation([{a,b},{c,a}]), - relation([{a,1},{a,2}]), - relation([{a,aa},{c,1}])}), - from_term([{a,{b,1,aa}},{a,{b,2,aa}}])), - ?line eval(relative_product({relation([{a,b}])}, E), E), - ?line eval(relative_product({E}, relation([{a,b}])), E), - ?line eval(relative_product({E,from_term([], [{{atom,atom,atom},atom}])}), - E), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch relative_product({})), + true = is_equal(relative_product({ER}), + from_term([], [{atom,{atom}}])), + eval(relative_product({relation([{a,b},{c,a}]), + relation([{a,1},{a,2}]), + relation([{a,aa},{c,1}])}), + from_term([{a,{b,1,aa}},{a,{b,2,aa}}])), + eval(relative_product({relation([{a,b}])}, E), E), + eval(relative_product({E}, relation([{a,b}])), E), + eval(relative_product({E,from_term([], [{{atom,atom,atom},atom}])}), + E), + {'EXIT', {badarg, _}} = (catch relative_product({from_term([a,b])}, E)), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch relative_product({relation([])}, set([]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch relative_product({from_term([{a,b}]), from_term([{{a},b}])}, ER)), - ?line {'EXIT', {badarg, _}} = (catch relative_product({}, ER)), - ?line relprod2({relation([{a,b}])}, from_term([],[{{atom},atom}]), ER), - ?line relprod2({relation([{a,b}]),relation([{a,1}])}, - from_term([{{b,1},{tjo,hej,sa}}]), - from_term([{a,{tjo,hej,sa}}])), - ?line relprod2({relation([{a,b}]), ER}, from_term([{{a,b},b}]), ER), - ?line relprod2({relation([{a,b},{c,a}]), - relation([{a,1},{a,2}])}, - from_term([{{b,1},b1},{{b,2},b2}]), - relation([{a,b1},{a,b2}])), - ?line eval(relative_product({relation([{a,b}]), ER}), - from_term([],[{atom,{atom,atom}}])), - ?line eval(relative_product({from_term([{{a,[a,b]},[a]}]), - from_term([{{a,[a,b]},[[a,b]]}])}), - from_term([{{a,[a,b]},{[a],[[a,b]]}}])), + {'EXIT', {badarg, _}} = (catch relative_product({}, ER)), + relprod2({relation([{a,b}])}, from_term([],[{{atom},atom}]), ER), + relprod2({relation([{a,b}]),relation([{a,1}])}, + from_term([{{b,1},{tjo,hej,sa}}]), + from_term([{a,{tjo,hej,sa}}])), + relprod2({relation([{a,b}]), ER}, from_term([{{a,b},b}]), ER), + relprod2({relation([{a,b},{c,a}]), + relation([{a,1},{a,2}])}, + from_term([{{b,1},b1},{{b,2},b2}]), + relation([{a,b1},{a,b2}])), + eval(relative_product({relation([{a,b}]), ER}), + from_term([],[{atom,{atom,atom}}])), + eval(relative_product({from_term([{{a,[a,b]},[a]}]), + from_term([{{a,[a,b]},[[a,b]]}])}), + from_term([{{a,[a,b]},{[a],[[a,b]]}}])), ok. relprod2(A1T, A2, R) -> @@ -1624,219 +1545,213 @@ relprod2(A1T, A2, R) -> eval(relative_product(A1T, A2), R), eval(relative_product(tuple_to_list(A1T), A2), R). -product_1(suite) -> []; -product_1(doc) -> [""]; product_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line eval(product(E, E), E), - ?line eval(product(relation([]), E), E), - ?line eval(product(E, relation([])), E), - ?line eval(product(relation([{a,b}]),relation([{c,d}])), - from_term([{{a,b},{c,d}}],[{{atom,atom},{atom,atom}}])), - - ?line eval(product({E, set([a,b,c])}), E), - ?line eval(product({set([a,b,c]), E}), E), - ?line eval(product({set([a,b,c]), E, E}), E), - ?line eval(product({E,E}), E), - ?line eval(product({set([a,b]),set([1,2])}), - relation([{a,1},{a,2},{b,1},{b,2}])), - ?line eval(product({from_term([a,b]), from_term([{a,b},{c,d}]), - from_term([1])}), - from_term([{a,{a,b},1},{a,{c,d},1},{b,{a,b},1},{b,{c,d},1}])), - ?line {'EXIT', {badarg, _}} = (catch product({})), - ?line {'EXIT', {badarg, _}} = (catch product({foo})), - ?line eval(product({E}), E), - ?line eval(product({E, E}), E), - ?line eval(product(set([a,b]), set([1,2])), - relation([{a,1},{a,2},{b,1},{b,2}])), - ?line eval(product({relation([]), E}), E), + E = empty_set(), + eval(product(E, E), E), + eval(product(relation([]), E), E), + eval(product(E, relation([])), E), + eval(product(relation([{a,b}]),relation([{c,d}])), + from_term([{{a,b},{c,d}}],[{{atom,atom},{atom,atom}}])), + + eval(product({E, set([a,b,c])}), E), + eval(product({set([a,b,c]), E}), E), + eval(product({set([a,b,c]), E, E}), E), + eval(product({E,E}), E), + eval(product({set([a,b]),set([1,2])}), + relation([{a,1},{a,2},{b,1},{b,2}])), + eval(product({from_term([a,b]), from_term([{a,b},{c,d}]), + from_term([1])}), + from_term([{a,{a,b},1},{a,{c,d},1},{b,{a,b},1},{b,{c,d},1}])), + {'EXIT', {badarg, _}} = (catch product({})), + {'EXIT', {badarg, _}} = (catch product({foo})), + eval(product({E}), E), + eval(product({E, E}), E), + eval(product(set([a,b]), set([1,2])), + relation([{a,1},{a,2},{b,1},{b,2}])), + eval(product({relation([]), E}), E), ok. -partition_1(suite) -> []; -partition_1(doc) -> [""]; partition_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), - ?line Id = fun(A) -> A end, - ?line S1 = relation([{a,1},{b,2},{b,22},{c,0}]), - ?line eval(partition(1, E), E), - ?line eval(partition(2, E), E), - ?line eval(partition(1, ER), from_term([], [type(ER)])), - ?line eval(partition(2, ER), from_term([], [type(ER)])), - ?line eval(partition(1, relation([{1,a},{1,b},{2,c},{2,d}])), - from_term([[{1,a},{1,b}],[{2,c},{2,d}]])), - ?line eval(partition(2, relation([{1,a},{1,b},{2,a},{2,b},{3,c}])), - from_term([[{1,a},{2,a}],[{1,b},{2,b}],[{3,c}]])), - ?line eval(partition(2, relation([{1,a}])), from_term([[{1,a}]])), - ?line eval(partition(2, relation([{1,a},{2,b}])), - from_term([[{1,a}],[{2,b}]])), - ?line eval(partition(2, relation([{1,a},{2,a},{3,a}])), - from_term([[{1,a},{2,a},{3,a}]])), - ?line eval(partition(2, relation([{1,b},{2,a}])), % OTP-4516 - from_term([[{1,b}],[{2,a}]])), - ?line eval(union(partition(Id, S1)), S1), - ?line eval(partition({external, fun({A,{B,_}}) -> {A,B} end}, - from_term([{a,{b,c}},{b,{c,d}},{a,{b,f}}])), - from_term([[{a,{b,c}},{a,{b,f}}],[{b,{c,d}}]])), + E = empty_set(), + ER = relation([]), + Id = fun(A) -> A end, + S1 = relation([{a,1},{b,2},{b,22},{c,0}]), + eval(partition(1, E), E), + eval(partition(2, E), E), + eval(partition(1, ER), from_term([], [type(ER)])), + eval(partition(2, ER), from_term([], [type(ER)])), + eval(partition(1, relation([{1,a},{1,b},{2,c},{2,d}])), + from_term([[{1,a},{1,b}],[{2,c},{2,d}]])), + eval(partition(2, relation([{1,a},{1,b},{2,a},{2,b},{3,c}])), + from_term([[{1,a},{2,a}],[{1,b},{2,b}],[{3,c}]])), + eval(partition(2, relation([{1,a}])), from_term([[{1,a}]])), + eval(partition(2, relation([{1,a},{2,b}])), + from_term([[{1,a}],[{2,b}]])), + eval(partition(2, relation([{1,a},{2,a},{3,a}])), + from_term([[{1,a},{2,a},{3,a}]])), + eval(partition(2, relation([{1,b},{2,a}])), % OTP-4516 + from_term([[{1,b}],[{2,a}]])), + eval(union(partition(Id, S1)), S1), + eval(partition({external, fun({A,{B,_}}) -> {A,B} end}, + from_term([{a,{b,c}},{b,{c,d}},{a,{b,f}}])), + from_term([[{a,{b,c}},{a,{b,f}}],[{b,{c,d}}]])), F = 0.0, I = round(F), - ?line FR = relation([{I,a},{F,b}]), + FR = relation([{I,a},{F,b}]), if F == I -> % term ordering - ?line eval(partition(1, FR), from_term([[{I,a},{F,b}]])); + eval(partition(1, FR), from_term([[{I,a},{F,b}]])); true -> - ?line eval(partition(1, FR), from_term([[{I,a}],[{F,b}]])) + eval(partition(1, FR), from_term([[{I,a}],[{F,b}]])) end, - ?line {'EXIT', {badarg, _}} = (catch partition(2, set([a]))), - ?line {'EXIT', {badarg, _}} = (catch partition(1, set([a]))), - ?line eval(partition(Id, set([a])), from_term([[a]])), - - ?line eval(partition(E), E), - ?line P1 = from_term([[a,b,c],[d,e,f],[g,h]]), - ?line P2 = from_term([[a,d],[b,c,e,f,q,v]]), - ?line eval(partition(union(P1, P2)), - from_term([[a],[b,c],[d],[e,f],[g,h],[q,v]])), - ?line {'EXIT', {badarg, _}} = (catch partition(from_term([a]))), + {'EXIT', {badarg, _}} = (catch partition(2, set([a]))), + {'EXIT', {badarg, _}} = (catch partition(1, set([a]))), + eval(partition(Id, set([a])), from_term([[a]])), + + eval(partition(E), E), + P1 = from_term([[a,b,c],[d,e,f],[g,h]]), + P2 = from_term([[a,d],[b,c,e,f,q,v]]), + eval(partition(union(P1, P2)), + from_term([[a],[b,c],[d],[e,f],[g,h],[q,v]])), + {'EXIT', {badarg, _}} = (catch partition(from_term([a]))), ok. -partition_3(suite) -> []; -partition_3(doc) -> [""]; partition_3(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), + E = empty_set(), + ER = relation([]), %% set of ordered sets - ?line S1 = relation([{a,1},{b,2},{b,22},{c,0}]), - ?line eval(partition(1, S1, set([0,1,d,e])), - lpartition(1, S1, set([0,1,d,e]))), - ?line eval(partition(1, S1, E), lpartition(1, S1, E)), - ?line eval(partition(2, ER, set([a,b])), lpartition(2, ER, set([a,b]))), + S1 = relation([{a,1},{b,2},{b,22},{c,0}]), + eval(partition(1, S1, set([0,1,d,e])), + lpartition(1, S1, set([0,1,d,e]))), + eval(partition(1, S1, E), lpartition(1, S1, E)), + eval(partition(2, ER, set([a,b])), lpartition(2, ER, set([a,b]))), XFun1 = {external, fun({_A,B,C}) -> {B,C} end}, R1a = relation([{a,aa,1},{b,bb,2},{c,cc,3}]), R1b = relation([{bb,2},{cc,3}]), - ?line eval(partition(XFun1, R1a, R1b), lpartition(XFun1, R1a, R1b)), + eval(partition(XFun1, R1a, R1b), lpartition(XFun1, R1a, R1b)), Id = fun(X) -> X end, XId = {external, Id}, R2 = relation([{a,b}]), - ?line eval(partition(XId, R2, E), lpartition(XId, R2, E)), + eval(partition(XId, R2, E), lpartition(XId, R2, E)), R3 = relation([{b,d}]), - ?line eval(partition(XId, E, R3), lpartition(XId, E, R3)), + eval(partition(XId, E, R3), lpartition(XId, E, R3)), Fun1 = fun(S) -> {_A,B,C} = to_external(S), from_term({B,C}) end, R4a = relation([{a,aa,1},{b,bb,2},{c,cc,3}]), R4b = relation([{bb,2},{cc,3}]), - ?line eval(partition(Fun1,R4a,R4b), lpartition(Fun1,R4a,R4b)), + eval(partition(Fun1,R4a,R4b), lpartition(Fun1,R4a,R4b)), XFun2 = {external, fun({_,{A},B}) -> {A,B} end}, R5a = from_term([{a,{aa},1},{b,{bb},2},{c,{cc},3}]), R5b = from_term([{bb,2},{cc,3}]), - ?line eval(partition(XFun2,R5a, R5b), lpartition(XFun2,R5a, R5b)), + eval(partition(XFun2,R5a, R5b), lpartition(XFun2,R5a, R5b)), R6 = relation([{a,b}]), - ?line eval(partition(2, R6, E), lpartition(2, R6, E)), + eval(partition(2, R6, E), lpartition(2, R6, E)), R7 = relation([{b,d}]), - ?line eval(partition(2, E, R7), lpartition(2, E, R7)), + eval(partition(2, E, R7), lpartition(2, E, R7)), S2 = set([a]), - ?line eval(partition(XId, E, S2), lpartition(XId, E, S2)), - ?line eval(partition(XId, S1, E), lpartition(XId, S1, E)), - ?line {'EXIT', {badarg, _}} = + eval(partition(XId, E, S2), lpartition(XId, E, S2)), + eval(partition(XId, S1, E), lpartition(XId, S1, E)), + {'EXIT', {badarg, _}} = (catch partition(3, relation([{a,b}]), E)), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch partition(3, relation([{a,b}]), relation([{b,d}]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch partition(3, relation([{a,b}]), set([{b,d}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch partition(2, relation([{a,b}]), relation([{b,d}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch partition({external, fun({A,_B}) -> A end}, relation([{a,b}]), relation([{b,d}]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch partition({external, fun({A,_}) -> {A,0} end}, from_term([{1,a}]), from_term([{1,0}]))), S18a = relation([{1,e},{2,b},{3,c},{4,b},{5,a},{6,0}]), S18b = set([b,d,f]), - ?line eval(partition({external,fun({_,X}) -> X end}, S18a, S18b), - lpartition({external,fun({_,X}) -> X end}, S18a, S18b)), + eval(partition({external,fun({_,X}) -> X end}, S18a, S18b), + lpartition({external,fun({_,X}) -> X end}, S18a, S18b)), S19a = sofs:relation([{3,a},{8,b}]), S19b = set([2,6,7]), - ?line eval(partition({external,fun({X,_}) -> X end}, S19a, S19b), - lpartition({external,fun({X,_}) -> X end}, S19a, S19b)), + eval(partition({external,fun({X,_}) -> X end}, S19a, S19b), + lpartition({external,fun({X,_}) -> X end}, S19a, S19b)), R8a = relation([{a,d},{b,e},{c,b},{d,c}]), S8 = set([b,d]), - ?line eval(partition(2, R8a, S8), lpartition(2, R8a, S8)), + eval(partition(2, R8a, S8), lpartition(2, R8a, S8)), S16a = relation([{1,e},{2,b},{3,c},{4,b},{5,a},{6,0}]), S16b = set([b,c,d]), - ?line eval(partition(2, S16a, S16b), lpartition(2, S16a, S16b)), + eval(partition(2, S16a, S16b), lpartition(2, S16a, S16b)), S17a = relation([{e,1},{b,2},{c,3},{b,4},{a,5},{0,6}]), S17b = set([b,c,d]), - ?line eval(partition(1, S17a, S17b), lpartition(1, S17a, S17b)), + eval(partition(1, S17a, S17b), lpartition(1, S17a, S17b)), - ?line {'EXIT', {function_clause, _}} = + {'EXIT', {function_clause, _}} = (catch partition({external, fun({A,_B}) -> A end}, set([]), E)), Fun3 = fun(S) -> from_term({to_external(S),0}, {type(S),atom}) end, S9a = set([1,2]), S9b = from_term([{1,0}]), - ?line eval(partition(Fun3, S9a, S9b), lpartition(Fun3, S9a, S9b)), + eval(partition(Fun3, S9a, S9b), lpartition(Fun3, S9a, S9b)), S14a = relation([{1,a},{2,b},{3,c},{0,0}]), S14b = set([b,c]), - ?line eval(partition(2, S14a, S14b), lpartition(2, S14a, S14b)), + eval(partition(2, S14a, S14b), lpartition(2, S14a, S14b)), S15a = relation([{a,1},{b,2},{c,3},{0,0}]), S15b = set([b,c]), - ?line eval(partition(1, S15a, S15b), lpartition(1, S15a, S15b)), + eval(partition(1, S15a, S15b), lpartition(1, S15a, S15b)), %% set of sets - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch partition({external, fun(X) -> X end}, from_term([], [[atom]]), set([a]))), S10 = from_term([], [[atom]]), - ?line eval(partition(Id, S10, E), lpartition(Id, S10, E)), + eval(partition(Id, S10, E), lpartition(Id, S10, E)), S10e = from_term([[a],[b]], [[atom]]), - ?line eval(partition(Id, S10e, E), lpartition(Id, S10e, E)), + eval(partition(Id, S10e, E), lpartition(Id, S10e, E)), S11a = from_term([], [[atom]]), S11b = set([a]), - ?line eval(partition(Id, S11a, S11b), lpartition(Id, S11a, S11b)), + eval(partition(Id, S11a, S11b), lpartition(Id, S11a, S11b)), S12a = from_term([[[a],[b]], [[b],[c]], [[], [a,b]], [[1],[2]]]), S12b = from_term([[a,b],[1,2,3],[b,c]]), - ?line eval(partition(fun sofs:union/1, S12a, S12b), - lpartition(fun sofs:union/1, S12a, S12b)), + eval(partition(fun sofs:union/1, S12a, S12b), + lpartition(fun sofs:union/1, S12a, S12b)), Fun13 = fun(_) -> from_term([a]) end, S13a = from_term([], [[atom]]), S13b = from_term([], [[a]]), - ?line eval(partition(Fun13, S13a, S13b), lpartition(Fun13, S13a, S13b)), + eval(partition(Fun13, S13a, S13b), lpartition(Fun13, S13a, S13b)), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch partition(fun(_) -> from_term([a]) end, from_term([[1,2],[3,4]]), from_term([], [atom]))), Fun10 = fun(S) -> - %% Cheating a lot... - case to_external(S) of - [1] -> from_term({1,1}); - _ -> S - end - end, - ?line {'EXIT', {type_mismatch, _}} = + %% Cheating a lot... + case to_external(S) of + [1] -> from_term({1,1}); + _ -> S + end + end, + {'EXIT', {type_mismatch, _}} = (catch partition(Fun10, from_term([[1]]), from_term([], [[atom]]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch partition(fun(_) -> from_term({a}) end, from_term([[a]]), from_term([], [atom]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch partition(fun(_) -> {a} end, from_term([[a]]), from_term([], [atom]))), @@ -1845,84 +1760,80 @@ partition_3(Conf) when is_list(Conf) -> lpartition(F, S1, S2) -> {restriction(F, S1, S2), drestriction(F, S1, S2)}. -multiple_relative_product(suite) -> []; -multiple_relative_product(doc) -> [""]; multiple_relative_product(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), - ?line T = relation([{a,1},{a,11},{b,2},{c,3},{c,33},{d,4}]), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + ER = relation([]), + T = relation([{a,1},{a,11},{b,2},{c,3},{c,33},{d,4}]), + {'EXIT', {badarg, _}} = (catch multiple_relative_product({}, ER)), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch multiple_relative_product({}, relation([{a,b}]))), - ?line eval(multiple_relative_product({E,T,T}, relation([], 3)), E), - ?line eval(multiple_relative_product({T,T,T}, E), E), - ?line eval(multiple_relative_product({T,T,T}, relation([],3)), - from_term([],[{{atom,atom,atom},{atom,atom,atom}}])), - ?line eval(multiple_relative_product({T,T,T}, + eval(multiple_relative_product({E,T,T}, relation([], 3)), E), + eval(multiple_relative_product({T,T,T}, E), E), + eval(multiple_relative_product({T,T,T}, relation([],3)), + from_term([],[{{atom,atom,atom},{atom,atom,atom}}])), + eval(multiple_relative_product({T,T,T}, relation([{a,b,c},{c,d,a}])), - from_term([{{a,b,c},{1,2,3}}, {{a,b,c},{1,2,33}}, - {{a,b,c},{11,2,3}}, {{a,b,c},{11,2,33}}, - {{c,d,a},{3,4,1}}, {{c,d,a},{3,4,11}}, - {{c,d,a},{33,4,1}}, {{c,d,a},{33,4,11}}])), - ?line {'EXIT', {type_mismatch, _}} = + from_term([{{a,b,c},{1,2,3}}, {{a,b,c},{1,2,33}}, + {{a,b,c},{11,2,3}}, {{a,b,c},{11,2,33}}, + {{c,d,a},{3,4,1}}, {{c,d,a},{3,4,11}}, + {{c,d,a},{33,4,1}}, {{c,d,a},{33,4,11}}])), + {'EXIT', {type_mismatch, _}} = (catch multiple_relative_product({T}, from_term([{{a}}]))), ok. -digraph(suite) -> []; -digraph(doc) -> [""]; digraph(Conf) when is_list(Conf) -> - ?line T0 = ets:all(), - ?line E = empty_set(), - ?line R = relation([{a,b},{b,c},{c,d},{d,a}]), - ?line F = relation_to_family(R), + T0 = ets:all(), + E = empty_set(), + R = relation([{a,b},{b,c},{c,d},{d,a}]), + F = relation_to_family(R), Type = type(F), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch family_to_digraph(set([a]))), digraph_fail(badarg, catch family_to_digraph(set([a]), [foo])), digraph_fail(badarg, catch family_to_digraph(F, [foo])), digraph_fail(cyclic, catch family_to_digraph(family([{a,[a]}]),[acyclic])), - ?line G1 = family_to_digraph(E), - ?line {'EXIT', {badarg, _}} = (catch digraph_to_family(G1, foo)), - ?line {'EXIT', {badarg, _}} = (catch digraph_to_family(G1, atom)), - ?line true = [] == to_external(digraph_to_family(G1)), - ?line true = [] == to_external(digraph_to_family(G1, Type)), - ?line true = digraph:delete(G1), - - ?line G1a = family_to_digraph(E, [protected]), - ?line true = [] == to_external(digraph_to_family(G1a)), - ?line true = [] == to_external(digraph_to_family(G1a, Type)), - ?line true = digraph:delete(G1a), - - ?line G2 = family_to_digraph(F), - ?line true = F == digraph_to_family(G2), - ?line true = F == digraph_to_family(G2, type(F)), - ?line true = digraph:delete(G2), - - ?line R2 = from_term([{{a},b},{{c},d}]), - ?line F2 = relation_to_family(R2), - ?line Type2 = type(F2), - ?line G3 = family_to_digraph(F2, [protected]), - ?line true = is_subset(F2, digraph_to_family(G3, Type2)), - ?line true = digraph:delete(G3), + G1 = family_to_digraph(E), + {'EXIT', {badarg, _}} = (catch digraph_to_family(G1, foo)), + {'EXIT', {badarg, _}} = (catch digraph_to_family(G1, atom)), + true = [] == to_external(digraph_to_family(G1)), + true = [] == to_external(digraph_to_family(G1, Type)), + true = digraph:delete(G1), + + G1a = family_to_digraph(E, [protected]), + true = [] == to_external(digraph_to_family(G1a)), + true = [] == to_external(digraph_to_family(G1a, Type)), + true = digraph:delete(G1a), + + G2 = family_to_digraph(F), + true = F == digraph_to_family(G2), + true = F == digraph_to_family(G2, type(F)), + true = digraph:delete(G2), + + R2 = from_term([{{a},b},{{c},d}]), + F2 = relation_to_family(R2), + Type2 = type(F2), + G3 = family_to_digraph(F2, [protected]), + true = is_subset(F2, digraph_to_family(G3, Type2)), + true = digraph:delete(G3), Fl = 0.0, I = round(Fl), if Fl == I -> % term ordering - ?line G4 = digraph:new(), + G4 = digraph:new(), digraph:add_vertex(G4, Fl), digraph:add_vertex(G4, I), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch digraph_to_family(G4, Type)), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch digraph_to_family(G4)), - ?line true = digraph:delete(G4); + true = digraph:delete(G4); true -> ok end, - - ?line true = T0 == ets:all(), + + true = T0 == ets:all(), ok. digraph_fail(ExitReason, Fail) -> @@ -1932,32 +1843,28 @@ digraph_fail(ExitReason, Fail) -> {true,2} -> ok end. -constant_function(suite) -> []; -constant_function(doc) -> [""]; constant_function(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line C = from_term(3), - ?line eval(constant_function(E, C), E), - ?line eval(constant_function(set([a,b]), E), from_term([{a,[]},{b,[]}])), - ?line eval(constant_function(set([a,b]), C), from_term([{a,3},{b,3}])), - ?line {'EXIT', {badarg, _}} = (catch constant_function(C, C)), - ?line {'EXIT', {badarg, _}} = (catch constant_function(set([]), foo)), + E = empty_set(), + C = from_term(3), + eval(constant_function(E, C), E), + eval(constant_function(set([a,b]), E), from_term([{a,[]},{b,[]}])), + eval(constant_function(set([a,b]), C), from_term([{a,3},{b,3}])), + {'EXIT', {badarg, _}} = (catch constant_function(C, C)), + {'EXIT', {badarg, _}} = (catch constant_function(set([]), foo)), ok. -misc(suite) -> []; -misc(doc) -> [""]; misc(Conf) when is_list(Conf) -> - % find "relational" part of relation: - ?line S = relation([{a,b},{b,c},{b,d},{c,d}]), + %% find "relational" part of relation: + S = relation([{a,b},{b,c},{b,d},{c,d}]), Id = fun(A) -> A end, - ?line RR = relational_restriction(S), - ?line eval(union(difference(partition(Id,S), partition(1,S))), RR), - ?line eval(union(difference(partition(1,S), partition(Id,S))), RR), - - % the "functional" part: - ?line eval(union(intersection(partition(1,S), partition(Id,S))), - difference(S, RR)), - ?line {'EXIT', {undef, _}} = + RR = relational_restriction(S), + eval(union(difference(partition(Id,S), partition(1,S))), RR), + eval(union(difference(partition(1,S), partition(Id,S))), RR), + + %% the "functional" part: + eval(union(intersection(partition(1,S), partition(Id,S))), + difference(S, RR)), + {'EXIT', {undef, _}} = (catch projection(fun external:foo/1, set([a,b,c]))), ok. @@ -1966,157 +1873,143 @@ relational_restriction(R) -> family_to_relation(family_specification(Fun, relation_to_family(R))). -family_specification(suite) -> []; -family_specification(doc) -> [""]; family_specification(Conf) when is_list(Conf) -> E = empty_set(), %% internal - ?line eval(family_specification(fun sofs:is_set/1, E), E), - ?line {'EXIT', {badarg, _}} = - (catch family_specification(fun sofs:is_set/1, set([]))), - ?line F1 = from_term([{1,[1]}]), - ?line eval(family_specification(fun sofs:is_set/1, F1), F1), + eval(family_specification(fun sofs:is_set/1, E), E), + {'EXIT', {badarg, _}} = + (catch family_specification(fun sofs:is_set/1, set([]))), + F1 = from_term([{1,[1]}]), + eval(family_specification(fun sofs:is_set/1, F1), F1), Fun = fun(S) -> is_subset(S, set([0,1,2,3,4])) end, - ?line F2 = family([{a,[1,2]},{b,[3,4,5]}]), - ?line eval(family_specification(Fun, F2), family([{a,[1,2]}])), - ?line F3 = from_term([{a,[]},{b,[]}]), - ?line eval(family_specification(fun sofs:is_set/1, F3), F3), + F2 = family([{a,[1,2]},{b,[3,4,5]}]), + eval(family_specification(Fun, F2), family([{a,[1,2]}])), + F3 = from_term([{a,[]},{b,[]}]), + eval(family_specification(fun sofs:is_set/1, F3), F3), Fun2 = fun(_) -> throw(fippla) end, - ?line fippla = (catch family_specification(Fun2, family([{a,[1]}]))), + fippla = (catch family_specification(Fun2, family([{a,[1]}]))), Fun3 = fun(_) -> neither_true_nor_false end, - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch family_specification(Fun3, F3)), %% external IsList = {external, fun(L) when is_list(L) -> true; (_) -> false end}, - ?line eval(family_specification(IsList, E), E), - ?line eval(family_specification(IsList, F1), F1), + eval(family_specification(IsList, E), E), + eval(family_specification(IsList, F1), F1), MF = {external, fun(L) -> lists:member(3, L) end}, - ?line eval(family_specification(MF, F2), family([{b,[3,4,5]}])), - ?line fippla = (catch family_specification(Fun2, family([{a,[1]}]))), - ?line {'EXIT', {badarg, _}} = + eval(family_specification(MF, F2), family([{b,[3,4,5]}])), + fippla = (catch family_specification(Fun2, family([{a,[1]}]))), + {'EXIT', {badarg, _}} = (catch family_specification({external, Fun3}, F3)), ok. -family_domain_1(suite) -> []; -family_domain_1(doc) -> [""]; family_domain_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = from_term([{a,[]},{b,[]}],[{atom,[{atom,atom}]}]), - ?line EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), - ?line eval(family_domain(E), E), - ?line eval(family_domain(ER), EF), - ?line FR = from_term([{a,[{1,a},{2,b},{3,c}]},{b,[]},{c,[{4,d},{5,e}]}]), - ?line eval(family_domain(FR), from_term([{a,[1,2,3]},{b,[]},{c,[4,5]}])), - ?line eval(family_field(E), E), - ?line eval(family_field(FR), - from_term([{a,[a,b,c,1,2,3]},{b,[]},{c,[d,e,4,5]}])), - ?line eval(family_domain(from_term([{{a},[{{1,[]},c}]}])), - from_term([{{a},[{1,[]}]}])), - ?line eval(family_domain(from_term([{{a},[{{1,[a]},c}]}])), - from_term([{{a},[{1,[a]}]}])), - ?line eval(family_domain(from_term([{{a},[]}])), - from_term([{{a},[]}])), - ?line eval(family_domain(from_term([], type(FR))), - from_term([], [{atom,[atom]}])), - ?line {'EXIT', {badarg, _}} = (catch family_domain(set([a]))), - ?line {'EXIT', {badarg, _}} = (catch family_field(set([a]))), - ?line {'EXIT', {badarg, _}} = (catch family_domain(set([{a,[b]}]))), + E = empty_set(), + ER = from_term([{a,[]},{b,[]}],[{atom,[{atom,atom}]}]), + EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), + eval(family_domain(E), E), + eval(family_domain(ER), EF), + FR = from_term([{a,[{1,a},{2,b},{3,c}]},{b,[]},{c,[{4,d},{5,e}]}]), + eval(family_domain(FR), from_term([{a,[1,2,3]},{b,[]},{c,[4,5]}])), + eval(family_field(E), E), + eval(family_field(FR), + from_term([{a,[a,b,c,1,2,3]},{b,[]},{c,[d,e,4,5]}])), + eval(family_domain(from_term([{{a},[{{1,[]},c}]}])), + from_term([{{a},[{1,[]}]}])), + eval(family_domain(from_term([{{a},[{{1,[a]},c}]}])), + from_term([{{a},[{1,[a]}]}])), + eval(family_domain(from_term([{{a},[]}])), + from_term([{{a},[]}])), + eval(family_domain(from_term([], type(FR))), + from_term([], [{atom,[atom]}])), + {'EXIT', {badarg, _}} = (catch family_domain(set([a]))), + {'EXIT', {badarg, _}} = (catch family_field(set([a]))), + {'EXIT', {badarg, _}} = (catch family_domain(set([{a,[b]}]))), ok. -family_range_1(suite) -> []; -family_range_1(doc) -> [""]; family_range_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = from_term([{a,[]},{b,[]}],[{atom,[{atom,atom}]}]), - ?line EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), - ?line eval(family_range(E), E), - ?line eval(family_range(ER), EF), - ?line FR = from_term([{a,[{1,a},{2,b},{3,c}]},{b,[]},{c,[{4,d},{5,e}]}]), - ?line eval(family_range(FR), from_term([{a,[a,b,c]},{b,[]},{c,[d,e]}])), - ?line eval(family_range(from_term([{{a},[{c,{1,[a]}}]}])), - from_term([{{a},[{1,[a]}]}])), - ?line eval(family_range(from_term([{{a},[{c,{1,[]}}]}])), - from_term([{{a},[{1,[]}]}])), - ?line eval(family_range(from_term([{{a},[]}])), - from_term([{{a},[]}])), - ?line eval(family_range(from_term([], type(FR))), - from_term([], [{atom,[atom]}])), - ?line {'EXIT', {badarg, _}} = (catch family_range(set([a]))), - ?line {'EXIT', {badarg, _}} = (catch family_range(set([{a,[b]}]))), + E = empty_set(), + ER = from_term([{a,[]},{b,[]}],[{atom,[{atom,atom}]}]), + EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), + eval(family_range(E), E), + eval(family_range(ER), EF), + FR = from_term([{a,[{1,a},{2,b},{3,c}]},{b,[]},{c,[{4,d},{5,e}]}]), + eval(family_range(FR), from_term([{a,[a,b,c]},{b,[]},{c,[d,e]}])), + eval(family_range(from_term([{{a},[{c,{1,[a]}}]}])), + from_term([{{a},[{1,[a]}]}])), + eval(family_range(from_term([{{a},[{c,{1,[]}}]}])), + from_term([{{a},[{1,[]}]}])), + eval(family_range(from_term([{{a},[]}])), + from_term([{{a},[]}])), + eval(family_range(from_term([], type(FR))), + from_term([], [{atom,[atom]}])), + {'EXIT', {badarg, _}} = (catch family_range(set([a]))), + {'EXIT', {badarg, _}} = (catch family_range(set([{a,[b]}]))), ok. -family_to_relation_1(suite) -> []; -family_to_relation_1(doc) -> [""]; family_to_relation_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line ER = relation([]), - ?line EF = family([]), - ?line eval(family_to_relation(E), E), - ?line eval(family_to_relation(EF), ER), - ?line eval(sofs:fam2rel(EF), ER), - ?line F = family([{a,[]},{b,[1]},{c,[7,9,11]}]), - ?line eval(family_to_relation(F), relation([{b,1},{c,7},{c,9},{c,11}])), - ?line {'EXIT', {badarg, _}} = (catch family_to_relation(set([a]))), + E = empty_set(), + ER = relation([]), + EF = family([]), + eval(family_to_relation(E), E), + eval(family_to_relation(EF), ER), + eval(sofs:fam2rel(EF), ER), + F = family([{a,[]},{b,[1]},{c,[7,9,11]}]), + eval(family_to_relation(F), relation([{b,1},{c,7},{c,9},{c,11}])), + {'EXIT', {badarg, _}} = (catch family_to_relation(set([a]))), ok. -union_of_family_1(suite) -> []; -union_of_family_1(doc) -> [""]; union_of_family_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), - ?line eval(union_of_family(E), E), - ?line eval(union_of_family(EF), set([])), - ?line eval(union_of_family(family([])), set([])), - ?line FR = from_term([{a,[1,2,3]},{b,[]},{c,[4,5]}]), - ?line eval(union_of_family(FR), set([1,2,3,4,5])), - ?line eval(union_of_family(sofs:family([{a,[1,2]},{b,[1,2]}])), - set([1,2])), - ?line {'EXIT', {badarg, _}} = (catch union_of_family(set([a]))), + E = empty_set(), + EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), + eval(union_of_family(E), E), + eval(union_of_family(EF), set([])), + eval(union_of_family(family([])), set([])), + FR = from_term([{a,[1,2,3]},{b,[]},{c,[4,5]}]), + eval(union_of_family(FR), set([1,2,3,4,5])), + eval(union_of_family(sofs:family([{a,[1,2]},{b,[1,2]}])), + set([1,2])), + {'EXIT', {badarg, _}} = (catch union_of_family(set([a]))), ok. -intersection_of_family_1(suite) -> []; -intersection_of_family_1(doc) -> [""]; intersection_of_family_1(Conf) when is_list(Conf) -> - ?line EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), - ?line eval(intersection_of_family(EF), set([])), - ?line FR = from_term([{a,[1,2,3]},{b,[2,3]},{c,[3,4,5]}]), - ?line eval(intersection_of_family(FR), set([3])), - ?line {'EXIT', {badarg, _}} = + EF = from_term([{a,[]},{b,[]}],[{atom,[atom]}]), + eval(intersection_of_family(EF), set([])), + FR = from_term([{a,[1,2,3]},{b,[2,3]},{c,[3,4,5]}]), + eval(intersection_of_family(FR), set([3])), + {'EXIT', {badarg, _}} = (catch intersection_of_family(family([]))), - ?line EE = from_term([], [[atom]]), - ?line {'EXIT', {badarg, _}} = (catch intersection_of_family(EE)), - ?line {'EXIT', {badarg, _}} = (catch intersection_of_family(set([a]))), + EE = from_term([], [[atom]]), + {'EXIT', {badarg, _}} = (catch intersection_of_family(EE)), + {'EXIT', {badarg, _}} = (catch intersection_of_family(set([a]))), ok. -family_projection(suite) -> []; -family_projection(doc) -> [""]; family_projection(Conf) when is_list(Conf) -> SSType = [{atom,[[atom]]}], SRType = [{atom,[{atom,atom}]}], - ?line E = empty_set(), - - ?line eval(family_projection(fun(X) -> X end, family([])), E), - ?line L1 = [{a,[]}], - ?line eval(family_projection(fun sofs:union/1, E), E), - ?line eval(family_projection(fun sofs:union/1, from_term(L1, SSType)), - family(L1)), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + + eval(family_projection(fun(X) -> X end, family([])), E), + L1 = [{a,[]}], + eval(family_projection(fun sofs:union/1, E), E), + eval(family_projection(fun sofs:union/1, from_term(L1, SSType)), + family(L1)), + {'EXIT', {badarg, _}} = (catch family_projection(fun sofs:union/1, set([]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch family_projection(fun sofs:union/1, from_term([{1,[1]}]))), - ?line F2 = from_term([{a,[[1],[2]]},{b,[[3,4],[5]]}], SSType), - ?line eval(family_projection(fun sofs:union/1, F2), - family_union(F2)), + F2 = from_term([{a,[[1],[2]]},{b,[[3,4],[5]]}], SSType), + eval(family_projection(fun sofs:union/1, F2), + family_union(F2)), - ?line F3 = from_term([{1,[{a,b},{b,c},{c,d}]},{3,[]},{5,[{3,5}]}], - SRType), - ?line eval(family_projection(fun sofs:domain/1, F3), family_domain(F3)), - ?line eval(family_projection(fun sofs:range/1, F3), family_range(F3)), + F3 = from_term([{1,[{a,b},{b,c},{c,d}]},{3,[]},{5,[{3,5}]}], + SRType), + eval(family_projection(fun sofs:domain/1, F3), family_domain(F3)), + eval(family_projection(fun sofs:range/1, F3), family_range(F3)), - ?line eval(family_projection(fun(_) -> E end, family([{a,[b,c]}])), - from_term([{a,[]}])), + eval(family_projection(fun(_) -> E end, family([{a,[b,c]}])), + from_term([{a,[]}])), Fun1 = fun(S) -> case to_external(S) of @@ -2124,264 +2017,252 @@ family_projection(Conf) when is_list(Conf) -> _ -> S end end, - ?line eval(family_projection(Fun1, family([{a,[1]}])), - from_term([{a,{1,1}}])), + eval(family_projection(Fun1, family([{a,[1]}])), + from_term([{a,{1,1}}])), Fun2 = fun(_) -> throw(fippla) end, - ?line fippla = + fippla = (catch family_projection(Fun2, family([{a,[1]}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch family_projection(Fun1, from_term([{1,[1]},{2,[2]}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch family_projection(Fun1, from_term([{1,[1]},{0,[0]}]))), - ?line eval(family_projection(fun(_) -> E end, from_term([{a,[]}])), - from_term([{a,[]}])), + eval(family_projection(fun(_) -> E end, from_term([{a,[]}])), + from_term([{a,[]}])), F4 = from_term([{a,[{1,2,3}]},{b,[{4,5,6}]},{c,[]},{m3,[]}]), Z = from_term(0), - ?line eval(family_projection(fun(S) -> local_adjoin(S, Z) end, F4), - from_term([{a,[{{1,2,3},0}]},{b,[{{4,5,6},0}]},{c,[]},{m3,[]}])), - ?line {'EXIT', {badarg, _}} = + eval(family_projection(fun(S) -> local_adjoin(S, Z) end, F4), + from_term([{a,[{{1,2,3},0}]},{b,[{{4,5,6},0}]},{c,[]},{m3,[]}])), + {'EXIT', {badarg, _}} = (catch family_projection({external, fun(X) -> X end}, from_term([{1,[1]}]))), %% ordered set element - ?line eval(family_projection(fun(_) -> from_term(a, atom) end, - from_term([{1,[a]}])), - from_term([{1,a}])), + eval(family_projection(fun(_) -> from_term(a, atom) end, + from_term([{1,[a]}])), + from_term([{1,a}])), ok. -family_difference(suite) -> []; -family_difference(doc) -> [""]; family_difference(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line EF = family([]), - ?line F9 = from_term([{b,[b,c]}]), - ?line F10 = from_term([{a,[b,c]}]), - ?line eval(family_difference(E, E), E), - ?line eval(family_difference(E, F10), from_term([], type(F10))), - ?line eval(family_difference(F10, E), F10), - ?line eval(family_difference(F9, F10), F9), - ?line eval(family_difference(F10, F10), family([{a,[]}])), - ?line F20 = from_term([{a,[1,2,3]},{b,[1,2,3]},{c,[1,2,3]}]), - ?line F21 = from_term([{b,[1,2,3]},{c,[1,2,3]}]), - ?line eval(family_difference(F20, from_term([{a,[2]}])), - from_term([{a,[1,3]},{b,[1,2,3]},{c,[1,2,3]}])), - ?line eval(family_difference(F20, from_term([{0,[2]},{q,[1,2]}])), F20), - ?line eval(family_difference(F20, F21), - from_term([{a,[1,2,3]},{b,[]},{c,[]}])), - - ?line eval(family_difference(from_term([{e,[f,g]}]), family([])), - from_term([{e,[f,g]}])), - ?line eval(family_difference(from_term([{e,[f,g]}]), EF), - from_term([{e,[f,g]}])), - ?line eval(family_difference(from_term([{a,[a,b,c,d]},{c,[b,c]}]), - from_term([{a,[b,c]},{b,[d]},{d,[e,f]}])), - from_term([{a,[a,d]},{c,[b,c]}])), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + EF = family([]), + F9 = from_term([{b,[b,c]}]), + F10 = from_term([{a,[b,c]}]), + eval(family_difference(E, E), E), + eval(family_difference(E, F10), from_term([], type(F10))), + eval(family_difference(F10, E), F10), + eval(family_difference(F9, F10), F9), + eval(family_difference(F10, F10), family([{a,[]}])), + F20 = from_term([{a,[1,2,3]},{b,[1,2,3]},{c,[1,2,3]}]), + F21 = from_term([{b,[1,2,3]},{c,[1,2,3]}]), + eval(family_difference(F20, from_term([{a,[2]}])), + from_term([{a,[1,3]},{b,[1,2,3]},{c,[1,2,3]}])), + eval(family_difference(F20, from_term([{0,[2]},{q,[1,2]}])), F20), + eval(family_difference(F20, F21), + from_term([{a,[1,2,3]},{b,[]},{c,[]}])), + + eval(family_difference(from_term([{e,[f,g]}]), family([])), + from_term([{e,[f,g]}])), + eval(family_difference(from_term([{e,[f,g]}]), EF), + from_term([{e,[f,g]}])), + eval(family_difference(from_term([{a,[a,b,c,d]},{c,[b,c]}]), + from_term([{a,[b,c]},{b,[d]},{d,[e,f]}])), + from_term([{a,[a,d]},{c,[b,c]}])), + {'EXIT', {badarg, _}} = (catch family_difference(set([]), set([]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch family_difference(from_term([{a,[b,c]}]), from_term([{e,[{f}]}]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch family_difference(from_term([{a,[b]}]), from_term([{c,[d]}], [{i,[s]}]))), ok. -family_intersection_1(suite) -> []; -family_intersection_1(doc) -> [""]; family_intersection_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line EF = family([]), - ?line ES = from_term([], [{atom,[[atom]]}]), - ?line eval(family_intersection(E), E), - ?line {'EXIT', {badarg, _}} = (catch family_intersection(EF)), - ?line eval(family_intersection(ES), EF), - ?line {'EXIT', {badarg, _}} = (catch family_intersection(set([]))), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + EF = family([]), + ES = from_term([], [{atom,[[atom]]}]), + eval(family_intersection(E), E), + {'EXIT', {badarg, _}} = (catch family_intersection(EF)), + eval(family_intersection(ES), EF), + {'EXIT', {badarg, _}} = (catch family_intersection(set([]))), + {'EXIT', {badarg, _}} = (catch family_intersection(from_term([{a,[1,2]}]))), - ?line F1 = from_term([{a,[[1],[2],[2,3]]},{b,[]},{c,[[4]]}]), - ?line {'EXIT', {badarg, _}} = (catch family_intersection(F1)), - ?line F2 = from_term([{b,[[1],[2],[2,3]]},{a,[]},{c,[[4]]}]), - ?line {'EXIT', {badarg, _}} = (catch family_intersection(F2)), - ?line F3 = from_term([{a,[[1,2,3],[2],[2,3]]},{c,[[4,5,6],[5,6,7]]}]), - ?line eval(family_intersection(F3), family([{a,[2]},{c,[5,6]}])), + F1 = from_term([{a,[[1],[2],[2,3]]},{b,[]},{c,[[4]]}]), + {'EXIT', {badarg, _}} = (catch family_intersection(F1)), + F2 = from_term([{b,[[1],[2],[2,3]]},{a,[]},{c,[[4]]}]), + {'EXIT', {badarg, _}} = (catch family_intersection(F2)), + F3 = from_term([{a,[[1,2,3],[2],[2,3]]},{c,[[4,5,6],[5,6,7]]}]), + eval(family_intersection(F3), family([{a,[2]},{c,[5,6]}])), ok. -family_intersection_2(suite) -> []; -family_intersection_2(doc) -> [""]; family_intersection_2(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line EF = family([]), - ?line F1 = from_term([{a,[1,2]},{b,[4,5]},{c,[7,8]},{d,[10,11]}]), - ?line F2 = from_term([{c,[6,7]},{d,[9,10,11]},{q,[1]}]), - ?line F3 = from_term([{a,[1,2]},{b,[4,5]},{c,[6,7,8]},{d,[9,10,11]}, - {q,[1]}]), - - ?line eval(family_intersection(E, E), E), - ?line eval(family_intersection(EF, EF), EF), - ?line eval(family_intersection(F1, F2), - from_term([{c,[7]},{d,[10,11]}])), - ?line eval(family_intersection(F1, F3), F1), - ?line eval(family_intersection(F2, F3), F2), - - ?line eval(family_intersection(EF, from_term([{e,[f,g]}])), EF), - ?line eval(family_intersection(E, from_term([{e,[f,g]}])), EF), - ?line eval(family_intersection(from_term([{e,[f,g]}]), EF), EF), - ?line eval(family_intersection(from_term([{e,[f,g]}]), E), EF), - ?line {'EXIT', {type_mismatch, _}} = + E = empty_set(), + EF = family([]), + F1 = from_term([{a,[1,2]},{b,[4,5]},{c,[7,8]},{d,[10,11]}]), + F2 = from_term([{c,[6,7]},{d,[9,10,11]},{q,[1]}]), + F3 = from_term([{a,[1,2]},{b,[4,5]},{c,[6,7,8]},{d,[9,10,11]}, + {q,[1]}]), + + eval(family_intersection(E, E), E), + eval(family_intersection(EF, EF), EF), + eval(family_intersection(F1, F2), + from_term([{c,[7]},{d,[10,11]}])), + eval(family_intersection(F1, F3), F1), + eval(family_intersection(F2, F3), F2), + + eval(family_intersection(EF, from_term([{e,[f,g]}])), EF), + eval(family_intersection(E, from_term([{e,[f,g]}])), EF), + eval(family_intersection(from_term([{e,[f,g]}]), EF), EF), + eval(family_intersection(from_term([{e,[f,g]}]), E), EF), + {'EXIT', {type_mismatch, _}} = (catch family_intersection(from_term([{a,[b,c]}]), from_term([{e,[{f}]}]))), - ?line F11 = family([{a,[1,2,3]},{b,[0,2,4]},{c,[0,3,6,9]}]), - ?line eval(union_of_family(F11), set([0,1,2,3,4,6,9])), - ?line F12 = from_term([{a,[1,2,3,4]},{b,[0,2,4]},{c,[2,3,4,5]}]), - ?line eval(intersection_of_family(F12), set([2,4])), + F11 = family([{a,[1,2,3]},{b,[0,2,4]},{c,[0,3,6,9]}]), + eval(union_of_family(F11), set([0,1,2,3,4,6,9])), + F12 = from_term([{a,[1,2,3,4]},{b,[0,2,4]},{c,[2,3,4,5]}]), + eval(intersection_of_family(F12), set([2,4])), ok. -family_union_1(suite) -> []; -family_union_1(doc) -> [""]; family_union_1(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line EF = family([]), - ?line ES = from_term([], [{atom,[[atom]]}]), - ?line eval(family_union(E), E), - ?line eval(family_union(ES), EF), - ?line {'EXIT', {badarg, _}} = (catch family_union(set([]))), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + EF = family([]), + ES = from_term([], [{atom,[[atom]]}]), + eval(family_union(E), E), + eval(family_union(ES), EF), + {'EXIT', {badarg, _}} = (catch family_union(set([]))), + {'EXIT', {badarg, _}} = (catch family_union(from_term([{a,[1,2]}]))), - ?line eval(family_union(from_term([{a,[[1],[2],[2,3]]},{b,[]},{c,[[4]]}])), - family([{a,[1,2,3]},{b,[]},{c,[4]}])), + eval(family_union(from_term([{a,[[1],[2],[2,3]]},{b,[]},{c,[[4]]}])), + family([{a,[1,2,3]},{b,[]},{c,[4]}])), ok. -family_union_2(suite) -> []; -family_union_2(doc) -> [""]; family_union_2(Conf) when is_list(Conf) -> - ?line E = empty_set(), - ?line EF = family([]), - ?line F1 = from_term([{a,[1,2]},{b,[4,5]},{c,[7,8]},{d,[10,11]}]), - ?line F2 = from_term([{c,[6,7]},{d,[9,10,11]},{q,[1]}]), - ?line F3 = from_term([{a,[1,2]},{b,[4,5]},{c,[6,7,8]},{d,[9,10,11]}, - {q,[1]}]), - - ?line eval(family_union(E, E), E), - ?line eval(family_union(F1, E), F1), - ?line eval(family_union(E, F2), F2), - ?line eval(family_union(F1, F2), F3), - ?line eval(family_union(F2, F1), F3), - - ?line eval(family_union(E, from_term([{e,[f,g]}])), - from_term([{e,[f,g]}])), - ?line eval(family_union(EF, from_term([{e,[f,g]}])), - from_term([{e,[f,g]}])), - ?line eval(family_union(from_term([{e,[f,g]}]), E), - from_term([{e,[f,g]}])), - ?line {'EXIT', {badarg, _}} = + E = empty_set(), + EF = family([]), + F1 = from_term([{a,[1,2]},{b,[4,5]},{c,[7,8]},{d,[10,11]}]), + F2 = from_term([{c,[6,7]},{d,[9,10,11]},{q,[1]}]), + F3 = from_term([{a,[1,2]},{b,[4,5]},{c,[6,7,8]},{d,[9,10,11]}, + {q,[1]}]), + + eval(family_union(E, E), E), + eval(family_union(F1, E), F1), + eval(family_union(E, F2), F2), + eval(family_union(F1, F2), F3), + eval(family_union(F2, F1), F3), + + eval(family_union(E, from_term([{e,[f,g]}])), + from_term([{e,[f,g]}])), + eval(family_union(EF, from_term([{e,[f,g]}])), + from_term([{e,[f,g]}])), + eval(family_union(from_term([{e,[f,g]}]), E), + from_term([{e,[f,g]}])), + {'EXIT', {badarg, _}} = (catch family_union(set([]),set([]))), - ?line {'EXIT', {type_mismatch, _}} = + {'EXIT', {type_mismatch, _}} = (catch family_union(from_term([{a,[b,c]}]), from_term([{e,[{f}]}]))), ok. -partition_family(suite) -> []; -partition_family(doc) -> [""]; partition_family(Conf) when is_list(Conf) -> - ?line E = empty_set(), + E = empty_set(), %% set of ordered sets - ?line ER = relation([]), - ?line EF = from_term([], [{atom,[{atom,atom}]}]), - - ?line eval(partition_family(1, E), E), - ?line eval(partition_family(2, E), E), - ?line eval(partition_family(fun sofs:union/1, E), E), - ?line eval(partition_family(1, ER), EF), - ?line eval(partition_family(2, ER), EF), - ?line {'EXIT', {badarg, _}} = (catch partition_family(1, set([]))), - ?line {'EXIT', {badarg, _}} = (catch partition_family(2, set([]))), - ?line {'EXIT', {function_clause, _}} = + ER = relation([]), + EF = from_term([], [{atom,[{atom,atom}]}]), + + eval(partition_family(1, E), E), + eval(partition_family(2, E), E), + eval(partition_family(fun sofs:union/1, E), E), + eval(partition_family(1, ER), EF), + eval(partition_family(2, ER), EF), + {'EXIT', {badarg, _}} = (catch partition_family(1, set([]))), + {'EXIT', {badarg, _}} = (catch partition_family(2, set([]))), + {'EXIT', {function_clause, _}} = (catch partition_family(fun({_A,B}) -> {B} end, from_term([{1}]))), - ?line eval(partition_family(1, relation([{1,a},{1,b},{2,c},{2,d}])), - from_term([{1,[{1,a},{1,b}]},{2,[{2,c},{2,d}]}])), - ?line eval(partition_family(1, relation([{1,a},{2,b}])), - from_term([{1,[{1,a}]},{2,[{2,b}]}])), - ?line eval(partition_family(2, relation([{1,a},{1,b},{2,a},{2,b},{3,c}])), - from_term([{a,[{1,a},{2,a}]},{b,[{1,b},{2,b}]},{c,[{3,c}]}])), - ?line eval(partition_family(2, relation([{1,a}])), - from_term([{a,[{1,a}]}])), - ?line eval(partition_family(2, relation([{1,a},{2,a},{3,a}])), - from_term([{a,[{1,a},{2,a},{3,a}]}])), - ?line eval(partition_family(2, relation([{1,a},{2,b}])), - from_term([{a,[{1,a}]},{b,[{2,b}]}])), - ?line F13 = from_term([{a,b,c},{a,b,d},{b,b,c},{a,c,c},{a,c,d},{b,c,c}]), - ?line eval(partition_family(2, F13), - from_term([{b,[{a,b,c},{a,b,d},{b,b,c}]}, - {c,[{a,c,c},{a,c,d},{b,c,c}]}])), + eval(partition_family(1, relation([{1,a},{1,b},{2,c},{2,d}])), + from_term([{1,[{1,a},{1,b}]},{2,[{2,c},{2,d}]}])), + eval(partition_family(1, relation([{1,a},{2,b}])), + from_term([{1,[{1,a}]},{2,[{2,b}]}])), + eval(partition_family(2, relation([{1,a},{1,b},{2,a},{2,b},{3,c}])), + from_term([{a,[{1,a},{2,a}]},{b,[{1,b},{2,b}]},{c,[{3,c}]}])), + eval(partition_family(2, relation([{1,a}])), + from_term([{a,[{1,a}]}])), + eval(partition_family(2, relation([{1,a},{2,a},{3,a}])), + from_term([{a,[{1,a},{2,a},{3,a}]}])), + eval(partition_family(2, relation([{1,a},{2,b}])), + from_term([{a,[{1,a}]},{b,[{2,b}]}])), + F13 = from_term([{a,b,c},{a,b,d},{b,b,c},{a,c,c},{a,c,d},{b,c,c}]), + eval(partition_family(2, F13), + from_term([{b,[{a,b,c},{a,b,d},{b,b,c}]}, + {c,[{a,c,c},{a,c,d},{b,c,c}]}])), Fun1 = {external, fun({A,_B}) -> {A} end}, - ?line eval(partition_family(Fun1, relation([{a,1},{a,2},{b,3}])), - from_term([{{a},[{a,1},{a,2}]},{{b},[{b,3}]}])), + eval(partition_family(Fun1, relation([{a,1},{a,2},{b,3}])), + from_term([{{a},[{a,1},{a,2}]},{{b},[{b,3}]}])), Fun2 = fun(S) -> {A,_B} = to_external(S), from_term({A}) end, - ?line eval(partition_family(Fun2, relation([{a,1},{a,2},{b,3}])), - from_term([{{a},[{a,1},{a,2}]},{{b},[{b,3}]}])), + eval(partition_family(Fun2, relation([{a,1},{a,2},{b,3}])), + from_term([{{a},[{a,1},{a,2}]},{{b},[{b,3}]}])), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch partition_family({external, fun({A,_}) -> {A,0} end}, from_term([{1,a}]))), - ?line [{{atom,atom},[{atom,atom,atom,atom}]}] = + [{{atom,atom},[{atom,atom,atom,atom}]}] = type(partition_family({external, fun({A,_B,C,_D}) -> {C,A} end}, relation([],4))), Fun3 = fun(S) -> from_term({to_external(S),0}, {type(S),atom}) end, - ?line eval(partition_family(Fun3, E), E), - ?line eval(partition_family(Fun3, set([a,b])), - from_term([{{a,0},[a]}, {{b,0},[b]}])), - ?line eval(partition_family(Fun3, relation([{a,1},{b,2}])), - from_term([{{{a,1},0},[{a,1}]},{{{b,2},0},[{b,2}]}])), - ?line eval(partition_family(Fun3, from_term([[a],[b]])), - from_term([{{[a],0},[[a]]}, {{[b],0},[[b]]}])), - ?line partition_family({external, fun(X) -> X end}, E), + eval(partition_family(Fun3, E), E), + eval(partition_family(Fun3, set([a,b])), + from_term([{{a,0},[a]}, {{b,0},[b]}])), + eval(partition_family(Fun3, relation([{a,1},{b,2}])), + from_term([{{{a,1},0},[{a,1}]},{{{b,2},0},[{b,2}]}])), + eval(partition_family(Fun3, from_term([[a],[b]])), + from_term([{{[a],0},[[a]]}, {{[b],0},[[b]]}])), + partition_family({external, fun(X) -> X end}, E), F = 0.0, I = round(F), - ?line FR = relation([{I,a},{F,b}]), + FR = relation([{I,a},{F,b}]), if F == I -> % term ordering - ?line true = (1 =:= no_elements(partition_family(1, FR))); + true = (1 =:= no_elements(partition_family(1, FR))); true -> - ?line eval(partition_family(1, FR), - from_term([{I,[{I,a}]},{F,[{F,b}]}])) + eval(partition_family(1, FR), + from_term([{I,[{I,a}]},{F,[{F,b}]}])) end, %% set of sets - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch partition_family({external, fun(X) -> X end}, from_term([], [[atom]]))), - ?line {'EXIT', {badarg, _}} = + {'EXIT', {badarg, _}} = (catch partition_family({external, fun(X) -> X end}, from_term([[a]]))), - ?line eval(partition_family(fun sofs:union/1, - from_term([[[1],[1,2]], [[1,2]]])), - from_term([{[1,2], [[[1],[1,2]],[[1,2]]]}])), - ?line eval(partition_family(fun(X) -> X end, - from_term([[1],[1,2],[1,2,3]])), - from_term([{[1],[[1]]},{[1,2],[[1,2]]},{[1,2,3],[[1,2,3]]}])), - - ?line eval(partition_family(fun(_) -> from_term([a]) end, - from_term([], [[atom]])), - E), + eval(partition_family(fun sofs:union/1, + from_term([[[1],[1,2]], [[1,2]]])), + from_term([{[1,2], [[[1],[1,2]],[[1,2]]]}])), + eval(partition_family(fun(X) -> X end, + from_term([[1],[1,2],[1,2,3]])), + from_term([{[1],[[1]]},{[1,2],[[1,2]]},{[1,2,3],[[1,2,3]]}])), + + eval(partition_family(fun(_) -> from_term([a]) end, + from_term([], [[atom]])), + E), Fun10 = fun(S) -> - %% Cheating a lot... - case to_external(S) of - [1] -> from_term({1,1}); - _ -> S - end - end, + %% Cheating a lot... + case to_external(S) of + [1] -> from_term({1,1}); + _ -> S + end + end, - ?line eval(partition_family(Fun10, from_term([[1]])), - from_term([{{1,1},[[1]]}])), - ?line eval(partition_family(fun(_) -> from_term({a}) end, - from_term([[a]])), - from_term([{{a},[[a]]}])), - ?line {'EXIT', {badarg, _}} = - (catch partition_family(fun(_) -> {a} end, from_term([[a]]))), + eval(partition_family(Fun10, from_term([[1]])), + from_term([{{1,1},[[1]]}])), + eval(partition_family(fun(_) -> from_term({a}) end, + from_term([[a]])), + from_term([{{a},[[a]]}])), + {'EXIT', {badarg, _}} = + (catch partition_family(fun(_) -> {a} end, from_term([[a]]))), ok. %% Not meant to be efficient... diff --git a/lib/stdlib/test/stdlib_SUITE.erl b/lib/stdlib/test/stdlib_SUITE.erl index 687e2fb6e8..f7064c4169 100644 --- a/lib/stdlib/test/stdlib_SUITE.erl +++ b/lib/stdlib/test/stdlib_SUITE.erl @@ -31,10 +31,7 @@ suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> - [app_test, appup_test, assert_test, {group,upgrade}]. - -groups() -> - [{upgrade,[minor_upgrade,major_upgrade]}]. + [app_test, appup_test, assert_test]. init_per_suite(Config) -> Config. @@ -42,13 +39,9 @@ init_per_suite(Config) -> end_per_suite(_Config) -> ok. -init_per_group(upgrade, Config) -> - ct_release_test:init(Config); init_per_group(_GroupName, Config) -> Config. -end_per_group(upgrade, Config) -> - ct_release_test:cleanup(Config); end_per_group(_GroupName, Config) -> Config. @@ -58,15 +51,12 @@ init_per_testcase(_Case, Config) -> end_per_testcase(_Case, _Config) -> ok. -% -% Test cases starts here. -% -app_test(suite) -> - []; -app_test(doc) -> - ["Application consistency test."]; +%% +%% Test cases starts here. +%% +%% Application consistency test. app_test(Config) when is_list(Config) -> - ?t:app_test(stdlib), + test_server:app_test(stdlib), ok. %% Test that appup allows upgrade from/downgrade to a maximum of one @@ -165,35 +155,10 @@ check_appup([],_,_) -> ok. -minor_upgrade(Config) -> - ct_release_test:upgrade(stdlib,minor,{?MODULE,[]},Config). - -major_upgrade(Config) -> - ct_release_test:upgrade(stdlib,major,{?MODULE,[]},Config). - -%% Version numbers are checked by ct_release_test, so there is nothing -%% more to check here... -upgrade_init(CtData,State) -> - {ok,{FromVsn,ToVsn}} = ct_release_test:get_app_vsns(CtData,stdlib), - case ct_release_test:get_appup(CtData,stdlib) of - {ok,{FromVsn,ToVsn,[restart_new_emulator],[restart_new_emulator]}} -> - io:format("Upgrade/downgrade ~p <--> ~p",[FromVsn,ToVsn]); - {error,{vsn_not_found,_}} when FromVsn==ToVsn -> - io:format("No upgrade test for stdlib, same version") - end, - State. -upgrade_upgraded(_CtData,State) -> - State. -upgrade_downgraded(_CtData,State) -> - State. - - -include_lib("stdlib/include/assert.hrl"). -include_lib("stdlib/include/assert.hrl"). % test repeated inclusion -assert_test(suite) -> - []; -assert_test(doc) -> - ["Assert macros test."]; + +%% Assert macros test. assert_test(_Config) -> ok = ?assert(true), {'EXIT',{{assert, _},_}} = (catch ?assert(false)), diff --git a/lib/stdlib/test/string_SUITE.erl b/lib/stdlib/test/string_SUITE.erl index 6ac3950f44..b5d221732e 100644 --- a/lib/stdlib/test/string_SUITE.erl +++ b/lib/stdlib/test/string_SUITE.erl @@ -23,26 +23,22 @@ -module(string_SUITE). -include_lib("common_test/include/ct.hrl"). - -% Default timetrap timeout (set in init_per_testcase). --define(default_timeout, ?t:minutes(1)). - -% Test server specific exports +%% Test server specific exports -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2]). -export([init_per_testcase/2, end_per_testcase/2]). -% Test cases must be exported. +%% Test cases must be exported. -export([len/1,equal/1,concat/1,chr_rchr/1,str_rstr/1]). -export([span_cspan/1,substr/1,tokens/1,chars/1]). -export([copies/1,words/1,strip/1,sub_word/1,left_right/1]). -export([sub_string/1,centre/1, join/1]). -export([to_integer/1,to_float/1]). -export([to_upper_to_lower/1]). -%% -%% all/1 -%% -suite() -> [{ct_hooks,[ts_install_cth]}]. + +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [len, equal, concat, chr_rchr, str_rstr, span_cspan, @@ -67,155 +63,125 @@ end_per_group(_GroupName, Config) -> init_per_testcase(_Case, Config) -> - ?line Dog=test_server:timetrap(?default_timeout), - [{watchdog, Dog}|Config]. -end_per_testcase(_Case, Config) -> - Dog=?config(watchdog, Config), - test_server:timetrap_cancel(Dog), + Config. + +end_per_testcase(_Case, _Config) -> ok. -% -% Test cases starts here. -% +%% +%% Test cases starts here. +%% -len(suite) -> - []; -len(doc) -> - []; len(Config) when is_list(Config) -> - ?line 0 = string:len(""), - ?line L = tuple_size(list_to_tuple(atom_to_list(?MODULE))), - ?line L = string:len(atom_to_list(?MODULE)), + 0 = string:len(""), + L = tuple_size(list_to_tuple(atom_to_list(?MODULE))), + L = string:len(atom_to_list(?MODULE)), %% invalid arg type - ?line {'EXIT',_} = (catch string:len({})), + {'EXIT',_} = (catch string:len({})), ok. -equal(suite) -> - []; -equal(doc) -> - []; equal(Config) when is_list(Config) -> - ?line true = string:equal("", ""), - ?line false = string:equal("", " "), - ?line true = string:equal("laban", "laban"), - ?line false = string:equal("skvimp", "skvump"), + true = string:equal("", ""), + false = string:equal("", " "), + true = string:equal("laban", "laban"), + false = string:equal("skvimp", "skvump"), %% invalid arg type - ?line true = string:equal(2, 2), % not good, should crash + true = string:equal(2, 2), % not good, should crash ok. -concat(suite) -> - []; -concat(doc) -> - []; concat(Config) when is_list(Config) -> - ?line "erlang rules" = string:concat("erlang ", "rules"), - ?line "" = string:concat("", ""), - ?line "x" = string:concat("x", ""), - ?line "y" = string:concat("", "y"), + "erlang rules" = string:concat("erlang ", "rules"), + "" = string:concat("", ""), + "x" = string:concat("x", ""), + "y" = string:concat("", "y"), %% invalid arg type - ?line {'EXIT',_} = (catch string:concat(hello, please)), + {'EXIT',_} = (catch string:concat(hello, please)), ok. -chr_rchr(suite) -> - []; -chr_rchr(doc) -> - []; chr_rchr(Config) when is_list(Config) -> {_,_,X} = erlang:timestamp(), - ?line 0 = string:chr("", (X rem (255-32)) + 32), - ?line 0 = string:rchr("", (X rem (255-32)) + 32), - ?line 1 = string:chr("x", $x), - ?line 1 = string:rchr("x", $x), - ?line 1 = string:chr("xx", $x), - ?line 2 = string:rchr("xx", $x), - ?line 3 = string:chr("xyzyx", $z), - ?line 3 = string:rchr("xyzyx", $z), + 0 = string:chr("", (X rem (255-32)) + 32), + 0 = string:rchr("", (X rem (255-32)) + 32), + 1 = string:chr("x", $x), + 1 = string:rchr("x", $x), + 1 = string:chr("xx", $x), + 2 = string:rchr("xx", $x), + 3 = string:chr("xyzyx", $z), + 3 = string:rchr("xyzyx", $z), %% invalid arg type - ?line {'EXIT',_} = (catch string:chr(hello, $h)), + {'EXIT',_} = (catch string:chr(hello, $h)), %% invalid arg type - ?line {'EXIT',_} = (catch string:chr("hello", h)), + {'EXIT',_} = (catch string:chr("hello", h)), %% invalid arg type - ?line {'EXIT',_} = (catch string:rchr(hello, $h)), + {'EXIT',_} = (catch string:rchr(hello, $h)), %% invalid arg type - ?line {'EXIT',_} = (catch string:rchr("hello", h)), + {'EXIT',_} = (catch string:rchr("hello", h)), ok. -str_rstr(suite) -> - []; -str_rstr(doc) -> - []; str_rstr(Config) when is_list(Config) -> {_,_,X} = erlang:timestamp(), - ?line 0 = string:str("", [(X rem (255-32)) + 32]), - ?line 0 = string:rstr("", [(X rem (255-32)) + 32]), - ?line 1 = string:str("x", "x"), - ?line 1 = string:rstr("x", "x"), - ?line 0 = string:str("hello", ""), - ?line 0 = string:rstr("hello", ""), - ?line 1 = string:str("xxxx", "xx"), - ?line 3 = string:rstr("xxxx", "xx"), - ?line 3 = string:str("xy z yx", " z"), - ?line 3 = string:rstr("xy z yx", " z"), + 0 = string:str("", [(X rem (255-32)) + 32]), + 0 = string:rstr("", [(X rem (255-32)) + 32]), + 1 = string:str("x", "x"), + 1 = string:rstr("x", "x"), + 0 = string:str("hello", ""), + 0 = string:rstr("hello", ""), + 1 = string:str("xxxx", "xx"), + 3 = string:rstr("xxxx", "xx"), + 3 = string:str("xy z yx", " z"), + 3 = string:rstr("xy z yx", " z"), %% invalid arg type - ?line {'EXIT',_} = (catch string:str(hello, "he")), + {'EXIT',_} = (catch string:str(hello, "he")), %% invalid arg type - ?line {'EXIT',_} = (catch string:str("hello", he)), + {'EXIT',_} = (catch string:str("hello", he)), %% invalid arg type - ?line {'EXIT',_} = (catch string:rstr(hello, "he")), + {'EXIT',_} = (catch string:rstr(hello, "he")), %% invalid arg type - ?line {'EXIT',_} = (catch string:rstr("hello", he)), + {'EXIT',_} = (catch string:rstr("hello", he)), ok. -span_cspan(suite) -> - []; -span_cspan(doc) -> - []; span_cspan(Config) when is_list(Config) -> - ?line 0 = string:span("", "1"), - ?line 0 = string:span("1", ""), - ?line 0 = string:cspan("", "1"), - ?line 1 = string:cspan("1", ""), - ?line 1 = string:span("1 ", "1"), - ?line 5 = string:span(" 1 ", "12 "), - ?line 6 = string:span("1231234", "123"), - ?line 0 = string:cspan("1 ", "1"), - ?line 1 = string:cspan("3 ", "12 "), - ?line 6 = string:cspan("1231234", "4"), + 0 = string:span("", "1"), + 0 = string:span("1", ""), + 0 = string:cspan("", "1"), + 1 = string:cspan("1", ""), + 1 = string:span("1 ", "1"), + 5 = string:span(" 1 ", "12 "), + 6 = string:span("1231234", "123"), + 0 = string:cspan("1 ", "1"), + 1 = string:cspan("3 ", "12 "), + 6 = string:cspan("1231234", "4"), %% invalid arg type - ?line {'EXIT',_} = (catch string:span(1234, "1")), + {'EXIT',_} = (catch string:span(1234, "1")), %% invalid arg type - ?line {'EXIT',_} = (catch string:span(1234, "1")), + {'EXIT',_} = (catch string:span(1234, "1")), %% invalid arg type - ?line {'EXIT',_} = (catch string:cspan("1234", 1)), + {'EXIT',_} = (catch string:cspan("1234", 1)), %% invalid arg type - ?line {'EXIT',_} = (catch string:cspan("1234", 4)), + {'EXIT',_} = (catch string:cspan("1234", 4)), ok. -substr(suite) -> - []; -substr(doc) -> - []; substr(Config) when is_list(Config) -> - ?line {'EXIT',_} = (catch string:substr("", 0)), - ?line [] = string:substr("", 1), - ?line {'EXIT',_} = (catch string:substr("", 2)), - ?line [] = string:substr("1", 2), - ?line {'EXIT',_} = (catch string:substr("", 0, 1)), - ?line [] = string:substr("", 1, 1), - ?line [] = string:substr("", 1, 2), - ?line {'EXIT',_} = (catch string:substr("", 2, 2)), - ?line "1234" = string:substr("1234", 1), - ?line "1234" = string:substr("1234", 1, 4), - ?line "1234" = string:substr("1234", 1, 5), - ?line "23" = string:substr("1234", 2, 2), - ?line "4" = string:substr("1234", 4), - ?line "" = string:substr("1234", 4, 0), - ?line "4" = string:substr("1234", 4, 1), - %% invalid arg type - ?line {'EXIT',_} = (catch string:substr(1234, 1)), - %% invalid arg type - ?line {'EXIT',_} = (catch string:substr("1234", "1")), + {'EXIT',_} = (catch string:substr("", 0)), + [] = string:substr("", 1), + {'EXIT',_} = (catch string:substr("", 2)), + [] = string:substr("1", 2), + {'EXIT',_} = (catch string:substr("", 0, 1)), + [] = string:substr("", 1, 1), + [] = string:substr("", 1, 2), + {'EXIT',_} = (catch string:substr("", 2, 2)), + "1234" = string:substr("1234", 1), + "1234" = string:substr("1234", 1, 4), + "1234" = string:substr("1234", 1, 5), + "23" = string:substr("1234", 2, 2), + "4" = string:substr("1234", 4), + "" = string:substr("1234", 4, 0), + "4" = string:substr("1234", 4, 1), + %% invalid arg type + {'EXIT',_} = (catch string:substr(1234, 1)), + %% invalid arg type + {'EXIT',_} = (catch string:substr("1234", "1")), ok. tokens(Config) when is_list(Config) -> @@ -252,261 +218,217 @@ replace_sep(C, Seps, New) -> false -> C end. -chars(suite) -> - []; -chars(doc) -> - []; chars(Config) when is_list(Config) -> - ?line [] = string:chars($., 0), - ?line [] = string:chars($., 0, []), - ?line 10 = length(string:chars(32, 10, [])), - ?line "aaargh" = string:chars($a, 3, "rgh"), + [] = string:chars($., 0), + [] = string:chars($., 0, []), + 10 = length(string:chars(32, 10, [])), + "aaargh" = string:chars($a, 3, "rgh"), %% invalid arg type - ?line {'EXIT',_} = (catch string:chars($x, [])), + {'EXIT',_} = (catch string:chars($x, [])), ok. -copies(suite) -> - []; -copies(doc) -> - []; copies(Config) when is_list(Config) -> - ?line "" = string:copies("", 10), - ?line "" = string:copies(".", 0), - ?line "." = string:copies(".", 1), - ?line 30 = length(string:copies("123", 10)), + "" = string:copies("", 10), + "" = string:copies(".", 0), + "." = string:copies(".", 1), + 30 = length(string:copies("123", 10)), %% invalid arg type - ?line {'EXIT',_} = (catch string:copies("hej", -1)), - ?line {'EXIT',_} = (catch string:copies("hej", 2.0)), + {'EXIT',_} = (catch string:copies("hej", -1)), + {'EXIT',_} = (catch string:copies("hej", 2.0)), ok. -words(suite) -> - []; -words(doc) -> - []; words(Config) when is_list(Config) -> - ?line 1 = string:words(""), - ?line 1 = string:words("", $,), - ?line 1 = string:words("hello"), - ?line 1 = string:words("hello", $,), - ?line 1 = string:words("...", $.), - ?line 2 = string:words("2.35", $.), - ?line 100 = string:words(string:copies(". ", 100)), + 1 = string:words(""), + 1 = string:words("", $,), + 1 = string:words("hello"), + 1 = string:words("hello", $,), + 1 = string:words("...", $.), + 2 = string:words("2.35", $.), + 100 = string:words(string:copies(". ", 100)), %% invalid arg type - ?line {'EXIT',_} = (catch string:chars(hej, 1)), + {'EXIT',_} = (catch string:chars(hej, 1)), %% invalid arg type - ?line {'EXIT',_} = (catch string:chars("hej", 1, " ")), + {'EXIT',_} = (catch string:chars("hej", 1, " ")), ok. -strip(suite) -> - []; -strip(doc) -> - []; strip(Config) when is_list(Config) -> - ?line "" = string:strip(""), - ?line "" = string:strip("", both), - ?line "" = string:strip("", both, $.), - ?line "hej" = string:strip(" hej "), - ?line "hej " = string:strip(" hej ", left), - ?line " hej" = string:strip(" hej ", right), - ?line " hej " = string:strip(" hej ", right, $.), - ?line "hej hopp" = string:strip(" hej hopp ", both), + "" = string:strip(""), + "" = string:strip("", both), + "" = string:strip("", both, $.), + "hej" = string:strip(" hej "), + "hej " = string:strip(" hej ", left), + " hej" = string:strip(" hej ", right), + " hej " = string:strip(" hej ", right, $.), + "hej hopp" = string:strip(" hej hopp ", both), %% invalid arg type - ?line {'EXIT',_} = (catch string:strip(hej)), + {'EXIT',_} = (catch string:strip(hej)), %% invalid arg type - ?line {'EXIT',_} = (catch string:strip(" hej", up)), + {'EXIT',_} = (catch string:strip(" hej", up)), %% invalid arg type - ?line {'EXIT',_} = (catch string:strip(" hej", left, " ")), % not good + {'EXIT',_} = (catch string:strip(" hej", left, " ")), % not good ok. -sub_word(suite) -> - []; -sub_word(doc) -> - []; sub_word(Config) when is_list(Config) -> - ?line "" = string:sub_word("", 1), - ?line "" = string:sub_word("", 1, $,), - ?line {'EXIT',_} = (catch string:sub_word("1 2 3", 0)), - ?line "" = string:sub_word("1 2 3", 4), - ?line "llo th" = string:sub_word("but hello there", 2, $e), + "" = string:sub_word("", 1), + "" = string:sub_word("", 1, $,), + {'EXIT',_} = (catch string:sub_word("1 2 3", 0)), + "" = string:sub_word("1 2 3", 4), + "llo th" = string:sub_word("but hello there", 2, $e), %% invalid arg type - ?line {'EXIT',_} = (catch string:sub_word('hello there', 1)), + {'EXIT',_} = (catch string:sub_word('hello there', 1)), %% invalid arg type - ?line {'EXIT',_} = (catch string:sub_word("hello there", 1, "e")), + {'EXIT',_} = (catch string:sub_word("hello there", 1, "e")), ok. -left_right(suite) -> - []; -left_right(doc) -> - []; left_right(Config) when is_list(Config) -> - ?line "" = string:left("", 0), - ?line "" = string:left("hej", 0), - ?line "" = string:left("hej", 0, $.), - ?line "" = string:right("", 0), - ?line "" = string:right("hej", 0), - ?line "" = string:right("hej", 0, $.), - ?line "123 " = string:left("123 ", 5), - ?line " 123" = string:right(" 123", 5), - ?line "123!!" = string:left("123!", 5, $!), - ?line "==123" = string:right("=123", 5, $=), - ?line "1" = string:left("123", 1, $.), - ?line "3" = string:right("123", 1, $.), - %% invalid arg type - ?line {'EXIT',_} = (catch string:left(hello, 5)), - %% invalid arg type - ?line {'EXIT',_} = (catch string:right(hello, 5)), - %% invalid arg type - ?line {'EXIT',_} = (catch string:left("hello", 5, ".")), - %% invalid arg type - ?line {'EXIT',_} = (catch string:right("hello", 5, ".")), + "" = string:left("", 0), + "" = string:left("hej", 0), + "" = string:left("hej", 0, $.), + "" = string:right("", 0), + "" = string:right("hej", 0), + "" = string:right("hej", 0, $.), + "123 " = string:left("123 ", 5), + " 123" = string:right(" 123", 5), + "123!!" = string:left("123!", 5, $!), + "==123" = string:right("=123", 5, $=), + "1" = string:left("123", 1, $.), + "3" = string:right("123", 1, $.), + %% invalid arg type + {'EXIT',_} = (catch string:left(hello, 5)), + %% invalid arg type + {'EXIT',_} = (catch string:right(hello, 5)), + %% invalid arg type + {'EXIT',_} = (catch string:left("hello", 5, ".")), + %% invalid arg type + {'EXIT',_} = (catch string:right("hello", 5, ".")), ok. -sub_string(suite) -> - []; -sub_string(doc) -> - []; sub_string(Config) when is_list(Config) -> - ?line {'EXIT',_} = (catch string:sub_string("", 0)), - ?line [] = string:sub_string("", 1), - ?line {'EXIT',_} = (catch string:sub_string("", 2)), - ?line [] = string:sub_string("1", 2), - ?line {'EXIT',_} = (catch string:sub_string("", 0, 1)), - ?line [] = string:sub_string("", 1, 1), - ?line [] = string:sub_string("", 1, 2), - ?line {'EXIT',_} = (catch string:sub_string("", 2, 2)), - ?line "1234" = string:sub_string("1234", 1), - ?line "1234" = string:sub_string("1234", 1, 4), - ?line "1234" = string:sub_string("1234", 1, 5), - ?line "23" = string:sub_string("1234", 2, 3), - ?line "4" = string:sub_string("1234", 4), - ?line "4" = string:sub_string("1234", 4, 4), - ?line "4" = string:sub_string("1234", 4, 5), - %% invalid arg type - ?line {'EXIT',_} = (catch string:sub_string(1234, 1)), - %% invalid arg type - ?line {'EXIT',_} = (catch string:sub_string("1234", "1")), + {'EXIT',_} = (catch string:sub_string("", 0)), + [] = string:sub_string("", 1), + {'EXIT',_} = (catch string:sub_string("", 2)), + [] = string:sub_string("1", 2), + {'EXIT',_} = (catch string:sub_string("", 0, 1)), + [] = string:sub_string("", 1, 1), + [] = string:sub_string("", 1, 2), + {'EXIT',_} = (catch string:sub_string("", 2, 2)), + "1234" = string:sub_string("1234", 1), + "1234" = string:sub_string("1234", 1, 4), + "1234" = string:sub_string("1234", 1, 5), + "23" = string:sub_string("1234", 2, 3), + "4" = string:sub_string("1234", 4), + "4" = string:sub_string("1234", 4, 4), + "4" = string:sub_string("1234", 4, 5), + %% invalid arg type + {'EXIT',_} = (catch string:sub_string(1234, 1)), + %% invalid arg type + {'EXIT',_} = (catch string:sub_string("1234", "1")), ok. -centre(suite) -> - []; -centre(doc) -> - []; centre(Config) when is_list(Config) -> - ?line "" = string:centre("", 0), - ?line "" = string:centre("1", 0), - ?line "" = string:centre("", 0, $-), - ?line "" = string:centre("1", 0, $-), - ?line "gd" = string:centre("agda", 2), - ?line "agda " = string:centre("agda", 5), - ?line " agda " = string:centre("agda", 6), - ?line "agda." = string:centre("agda", 5, $.), - ?line "--agda--" = string:centre("agda", 8, $-), - ?line "agda" = string:centre("agda", 4), - %% invalid arg type - ?line {'EXIT',_} = (catch string:centre(hello, 10)), + "" = string:centre("", 0), + "" = string:centre("1", 0), + "" = string:centre("", 0, $-), + "" = string:centre("1", 0, $-), + "gd" = string:centre("agda", 2), + "agda " = string:centre("agda", 5), + " agda " = string:centre("agda", 6), + "agda." = string:centre("agda", 5, $.), + "--agda--" = string:centre("agda", 8, $-), + "agda" = string:centre("agda", 4), + %% invalid arg type + {'EXIT',_} = (catch string:centre(hello, 10)), ok. -to_integer(suite) -> - []; -to_integer(doc) -> - []; to_integer(Config) when is_list(Config) -> - ?line {1,""} = test_to_integer("1"), - ?line {1,""} = test_to_integer("+1"), - ?line {-1,""} = test_to_integer("-1"), - ?line {1,"="} = test_to_integer("1="), - ?line {7,"F"} = test_to_integer("7F"), - ?line {709,""} = test_to_integer("709"), - ?line {709,"*2"} = test_to_integer("709*2"), - ?line {0,"xAB"} = test_to_integer("0xAB"), - ?line {16,"#FF"} = test_to_integer("16#FF"), - ?line {error,no_integer} = test_to_integer(""), - ?line {error,no_integer} = test_to_integer("!1"), - ?line {error,no_integer} = test_to_integer("F1"), - ?line {error,not_a_list} = test_to_integer('23'), - ?line {3,[[]]} = test_to_integer([$3,[]]), - ?line {3,[hello]} = test_to_integer([$3,hello]), + {1,""} = test_to_integer("1"), + {1,""} = test_to_integer("+1"), + {-1,""} = test_to_integer("-1"), + {1,"="} = test_to_integer("1="), + {7,"F"} = test_to_integer("7F"), + {709,""} = test_to_integer("709"), + {709,"*2"} = test_to_integer("709*2"), + {0,"xAB"} = test_to_integer("0xAB"), + {16,"#FF"} = test_to_integer("16#FF"), + {error,no_integer} = test_to_integer(""), + {error,no_integer} = test_to_integer("!1"), + {error,no_integer} = test_to_integer("F1"), + {error,not_a_list} = test_to_integer('23'), + {3,[[]]} = test_to_integer([$3,[]]), + {3,[hello]} = test_to_integer([$3,hello]), ok. test_to_integer(Str) -> io:format("Checking ~p~n", [Str]), case string:to_integer(Str) of {error,_Reason} = Bad -> - ?line {'EXIT',_} = (catch list_to_integer(Str)), + {'EXIT',_} = (catch list_to_integer(Str)), Bad; {F,_Rest} = Res -> - ?line _ = integer_to_list(F), + _ = integer_to_list(F), Res end. -to_float(suite) -> - []; -to_float(doc) -> - []; to_float(Config) when is_list(Config) -> - ?line {1.2,""} = test_to_float("1.2"), - ?line {1.2,""} = test_to_float("1,2"), - ?line {120.0,""} = test_to_float("1.2e2"), - ?line {120.0,""} = test_to_float("+1,2e2"), - ?line {-120.0,""} = test_to_float("-1.2e2"), - ?line {-120.0,""} = test_to_float("-1,2e+2"), - ?line {-1.2e-2,""} = test_to_float("-1.2e-2"), - ?line {1.2,"="} = test_to_float("1.2="), - ?line {7.9,"e"} = test_to_float("7.9e"), - ?line {7.9,"ee"} = test_to_float("7.9ee"), - ?line {7.9,"e+"} = test_to_float("7.9e+"), - ?line {7.9,"e-"} = test_to_float("7.9e-"), - ?line {7.9,"e++"} = test_to_float("7.9e++"), - ?line {7.9,"e--"} = test_to_float("7.9e--"), - ?line {7.9,"e+e"} = test_to_float("7.9e+e"), - ?line {7.9,"e-e"} = test_to_float("7.9e-e"), - ?line {7.9,"e+."} = test_to_float("7.9e+."), - ?line {7.9,"e-."} = test_to_float("7.9e-."), - ?line {7.9,"e+,"} = test_to_float("7.9e+,"), - ?line {7.9,"e-,"} = test_to_float("7.9e-,"), - ?line {error,no_float} = test_to_float(""), - ?line {error,no_float} = test_to_float("e1,0"), - ?line {error,no_float} = test_to_float("1;0"), - ?line {error,no_float} = test_to_float("1"), - ?line {error,no_float} = test_to_float("1e"), - ?line {error,no_float} = test_to_float("2."), - ?line {error,not_a_list} = test_to_float('2.3'), - ?line {2.3,[[]]} = test_to_float([$2,$.,$3,[]]), - ?line {2.3,[hello]} = test_to_float([$2,$.,$3,hello]), + {1.2,""} = test_to_float("1.2"), + {1.2,""} = test_to_float("1,2"), + {120.0,""} = test_to_float("1.2e2"), + {120.0,""} = test_to_float("+1,2e2"), + {-120.0,""} = test_to_float("-1.2e2"), + {-120.0,""} = test_to_float("-1,2e+2"), + {-1.2e-2,""} = test_to_float("-1.2e-2"), + {1.2,"="} = test_to_float("1.2="), + {7.9,"e"} = test_to_float("7.9e"), + {7.9,"ee"} = test_to_float("7.9ee"), + {7.9,"e+"} = test_to_float("7.9e+"), + {7.9,"e-"} = test_to_float("7.9e-"), + {7.9,"e++"} = test_to_float("7.9e++"), + {7.9,"e--"} = test_to_float("7.9e--"), + {7.9,"e+e"} = test_to_float("7.9e+e"), + {7.9,"e-e"} = test_to_float("7.9e-e"), + {7.9,"e+."} = test_to_float("7.9e+."), + {7.9,"e-."} = test_to_float("7.9e-."), + {7.9,"e+,"} = test_to_float("7.9e+,"), + {7.9,"e-,"} = test_to_float("7.9e-,"), + {error,no_float} = test_to_float(""), + {error,no_float} = test_to_float("e1,0"), + {error,no_float} = test_to_float("1;0"), + {error,no_float} = test_to_float("1"), + {error,no_float} = test_to_float("1e"), + {error,no_float} = test_to_float("2."), + {error,not_a_list} = test_to_float('2.3'), + {2.3,[[]]} = test_to_float([$2,$.,$3,[]]), + {2.3,[hello]} = test_to_float([$2,$.,$3,hello]), ok. test_to_float(Str) -> io:format("Checking ~p~n", [Str]), case string:to_float(Str) of {error,_Reason} = Bad -> - ?line {'EXIT',_} = (catch list_to_float(Str)), + {'EXIT',_} = (catch list_to_float(Str)), Bad; {F,_Rest} = Res -> - ?line _ = float_to_list(F), + _ = float_to_list(F), Res end. - -to_upper_to_lower(suite) -> - []; -to_upper_to_lower(doc) -> - []; + to_upper_to_lower(Config) when is_list(Config) -> - ?line "1234ABCDEFÅÄÖ=" = string:to_upper("1234abcdefåäö="), - ?line "éèíúùòóåäöabc()" = string:to_lower("ÉÈÍÚÙÒÓÅÄÖabc()"), - ?line All = lists:seq(0, 255), + "1234ABCDEFÅÄÖ=" = string:to_upper("1234abcdefåäö="), + "éèíúùòóåäöabc()" = string:to_lower("ÉÈÍÚÙÒÓÅÄÖabc()"), + All = lists:seq(0, 255), - ?line UC = string:to_upper(All), - ?line 256 = length(UC), - ?line all_upper_latin1(UC, 0), + UC = string:to_upper(All), + 256 = length(UC), + all_upper_latin1(UC, 0), - ?line LC = string:to_lower(All), - ?line all_lower_latin1(LC, 0), + LC = string:to_lower(All), + all_lower_latin1(LC, 0), - ?line LC = string:to_lower(string:to_upper(LC)), - ?line LC = string:to_lower(string:to_upper(UC)), - ?line UC = string:to_upper(string:to_lower(LC)), - ?line UC = string:to_upper(string:to_lower(UC)), + LC = string:to_lower(string:to_upper(LC)), + LC = string:to_lower(string:to_upper(UC)), + UC = string:to_upper(string:to_lower(LC)), + UC = string:to_upper(string:to_lower(UC)), ok. all_upper_latin1([C|T], C) when 0 =< C, C < $a; @@ -533,15 +455,11 @@ all_lower_latin1([H|T], C) when $A =< C, C =< $Z; all_lower_latin1(T, C+1); all_lower_latin1([], 256) -> ok. -join(suite) -> - []; -join(doc) -> - []; join(Config) when is_list(Config) -> - ?line "erlang rules" = string:join(["erlang", "rules"], " "), - ?line "a,-,b,-,c" = string:join(["a", "b", "c"], ",-,"), - ?line "1234" = string:join(["1", "2", "3", "4"], ""), - ?line [] = string:join([], ""), % OTP-7231 + "erlang rules" = string:join(["erlang", "rules"], " "), + "a,-,b,-,c" = string:join(["a", "b", "c"], ",-,"), + "1234" = string:join(["1", "2", "3", "4"], ""), + [] = string:join([], ""), % OTP-7231 %% invalid arg type - ?line {'EXIT',_} = (catch string:join([apa], "")), + {'EXIT',_} = (catch string:join([apa], "")), ok. diff --git a/lib/stdlib/test/supervisor_SUITE.erl b/lib/stdlib/test/supervisor_SUITE.erl index 903ca76575..9de5a57e7f 100644 --- a/lib/stdlib/test/supervisor_SUITE.erl +++ b/lib/stdlib/test/supervisor_SUITE.erl @@ -22,7 +22,6 @@ -module(supervisor_SUITE). -include_lib("common_test/include/ct.hrl"). --define(TIMEOUT, ?t:minutes(1)). %% Testserver specific export -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, @@ -78,7 +77,8 @@ %%------------------------------------------------------------------------- suite() -> - [{ct_hooks,[ts_install_cth]}]. + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [{group, sup_start}, {group, sup_start_map}, {group, sup_stop}, child_adm, @@ -144,11 +144,9 @@ end_per_group(_GroupName, Config) -> Config. init_per_testcase(_Case, Config) -> - Dog = ?t:timetrap(?TIMEOUT), - [{watchdog,Dog}|Config]. + Config. -end_per_testcase(_Case, Config) -> - ?t:timetrap_cancel(?config(watchdog,Config)), +end_per_testcase(_Case, _Config) -> ok. start_link(InitResult) -> @@ -704,7 +702,7 @@ permanent_normal(Config) when is_list(Config) -> true -> ok; false -> - test_server:fail({permanent_child_not_restarted, Child1}) + ct:fail({permanent_child_not_restarted, Child1}) end, [1,1,0,1] = get_child_counts(sup_test). @@ -753,7 +751,7 @@ permanent_shutdown(Config) when is_list(Config) -> true -> ok; false -> - test_server:fail({permanent_child_not_restarted, Child1}) + ct:fail({permanent_child_not_restarted, Child1}) end, [1,1,0,1] = get_child_counts(sup_test), @@ -764,7 +762,7 @@ permanent_shutdown(Config) when is_list(Config) -> true -> ok; false -> - test_server:fail({permanent_child_not_restarted, Child1}) + ct:fail({permanent_child_not_restarted, Child1}) end, [1,1,0,1] = get_child_counts(sup_test). @@ -817,7 +815,7 @@ temporary_shutdown(Config) when is_list(Config) -> faulty_application_shutdown(Config) when is_list(Config) -> %% Set some paths - AppDir = filename:join(?config(data_dir, Config), "app_faulty"), + AppDir = filename:join(proplists:get_value(data_dir, Config), "app_faulty"), EbinDir = filename:join(AppDir, "ebin"), %% Start faulty app @@ -860,7 +858,7 @@ permanent_abnormal(Config) when is_list(Config) -> true -> ok; false -> - test_server:fail({permanent_child_not_restarted, Child1}) + ct:fail({permanent_child_not_restarted, Child1}) end, [1,1,0,1] = get_child_counts(sup_test). @@ -879,7 +877,7 @@ transient_abnormal(Config) when is_list(Config) -> true -> ok; false -> - test_server:fail({transient_child_not_restarted, Child1}) + ct:fail({transient_child_not_restarted, Child1}) end, [1,1,0,1] = get_child_counts(sup_test). @@ -975,9 +973,9 @@ one_for_one(Config) when is_list(Config) -> if length(Children) == 2 -> case lists:keysearch(CPid2, 2, Children) of {value, _} -> ok; - _ -> test_server:fail(bad_child) + _ -> ct:fail(bad_child) end; - true -> test_server:fail({bad_child_list, Children}) + true -> ct:fail({bad_child_list, Children}) end, [2,2,0,2] = get_child_counts(sup_test), @@ -1028,7 +1026,7 @@ one_for_all(Config) when is_list(Config) -> Children = supervisor:which_children(sup_test), if length(Children) == 2 -> ok; true -> - test_server:fail({bad_child_list, Children}) + ct:fail({bad_child_list, Children}) end, %% Test that no old children is still alive @@ -1103,7 +1101,7 @@ one_for_all_other_child_fails_restart(Config) when is_list(Config) -> {_childName, _Pid} -> exit(SupPid, kill), check_exit([StarterPid, SupPid]), - test_server:fail({restarting_child_not_terminated, Child1Pid2}) + ct:fail({restarting_child_not_terminated, Child1Pid2}) end, %% Let the restart complete. Child1Pid3 = receive {child1, Pid5} -> Pid5 end, @@ -1130,9 +1128,9 @@ simple_one_for_one(Config) when is_list(Config) -> if length(Children) == 2 -> case lists:keysearch(CPid2, 2, Children) of {value, _} -> ok; - _ -> test_server:fail(bad_child) + _ -> ct:fail(bad_child) end; - true -> test_server:fail({bad_child_list, Children}) + true -> ct:fail({bad_child_list, Children}) end, [1,2,0,2] = get_child_counts(sup_test), @@ -1166,9 +1164,9 @@ simple_one_for_one_shutdown(Config) when is_list(Config) -> if T < 1000*ShutdownTime -> %% Because supervisor's children wait before exiting, it can't %% terminate quickly - test_server:fail({shutdown_too_short, T}); + ct:fail({shutdown_too_short, T}); T >= 1000*5*ShutdownTime -> - test_server:fail({shutdown_too_long, T}); + ct:fail({shutdown_too_long, T}); true -> check_exit([SupPid]) end. @@ -1190,9 +1188,9 @@ simple_one_for_one_extra(Config) when is_list(Config) -> if length(Children) == 2 -> case lists:keysearch(CPid2, 2, Children) of {value, _} -> ok; - _ -> test_server:fail(bad_child) + _ -> ct:fail(bad_child) end; - true -> test_server:fail({bad_child_list, Children}) + true -> ct:fail({bad_child_list, Children}) end, [1,2,0,2] = get_child_counts(sup_test), terminate(SupPid, CPid2, child2, abnormal), @@ -1244,7 +1242,7 @@ rest_for_one(Config) when is_list(Config) -> if length(Children) == 3 -> ok; true -> - test_server:fail({bad_child_list, Children}) + ct:fail({bad_child_list, Children}) end, [3,3,0,3] = get_child_counts(sup_test), @@ -1320,7 +1318,7 @@ rest_for_one_other_child_fails_restart(Config) when is_list(Config) -> {child1, _Child1Pid3} -> exit(SupPid, kill), check_exit([StarterPid, SupPid]), - test_server:fail({restarting_started_child, Child1Pid2}) + ct:fail({restarting_started_child, Child1Pid2}) end, StarterPid ! {stop, Self}, check_exit([StarterPid, SupPid]). @@ -1350,7 +1348,7 @@ child_unlink(Config) when is_list(Config) -> ok; _ -> exit(Pid, kill), - test_server:fail(supervisor_hangs) + ct:fail(supervisor_hangs) end. %%------------------------------------------------------------------------- %% Test a basic supervison tree. @@ -1486,18 +1484,18 @@ count_restarting_children(Config) when is_list(Config) -> supervisor_deadlock:restart_child(Ch1_1), supervisor_deadlock:restart_child(Ch1_2), supervisor_deadlock:restart_child(Ch1_3), - test_server:sleep(400), + ct:sleep(400), [1,3,0,3] = get_child_counts(SupPid), [Ch2_1, Ch2_2, Ch2_3] = [C || {_,C,_,_} <- supervisor:which_children(SupPid)], ets:insert(supervisor_deadlock,{fail_start,true}), supervisor_deadlock:restart_child(Ch2_1), supervisor_deadlock:restart_child(Ch2_2), - test_server:sleep(4000), % allow restart to happen before proceeding + ct:sleep(4000), % allow restart to happen before proceeding [1,1,0,3] = get_child_counts(SupPid), ets:insert(supervisor_deadlock,{fail_start,false}), - test_server:sleep(4000), % allow restart to happen before proceeding + ct:sleep(4000), % allow restart to happen before proceeding [1,3,0,3] = get_child_counts(SupPid), ok = supervisor:terminate_child(SupPid, Ch2_3), @@ -1689,7 +1687,7 @@ simple_one_for_one_scale_many_temporary_children(_Config) -> %% The scaling shoul be linear (i.e.10, really), but we %% give some extra here to avoid failing the test %% unecessarily. - ?t:fail({bad_scaling,Scaling}); + ct:fail({bad_scaling,Scaling}); true -> ok end; @@ -2118,14 +2116,14 @@ in_child_list([Pid | Rest], Pids) -> true -> in_child_list(Rest, Pids); false -> - test_server:fail(child_should_be_alive) + ct:fail(child_should_be_alive) end. not_in_child_list([], _) -> true; not_in_child_list([Pid | Rest], Pids) -> case is_in_child_list(Pid, Pids) of true -> - test_server:fail(child_should_not_be_alive); + ct:fail(child_should_not_be_alive); false -> not_in_child_list(Rest, Pids) end. @@ -2146,7 +2144,7 @@ check_exit_reason(Reason) -> {'EXIT', _, Reason} -> ok; {'EXIT', _, Else} -> - test_server:fail({bad_exit_reason, Else}) + ct:fail({bad_exit_reason, Else}) end. check_exit_reason(Pid, Reason) -> @@ -2154,5 +2152,5 @@ check_exit_reason(Pid, Reason) -> {'EXIT', Pid, Reason} -> ok; {'EXIT', Pid, Else} -> - test_server:fail({bad_exit_reason, Else}) + ct:fail({bad_exit_reason, Else}) end. diff --git a/lib/stdlib/test/supervisor_bridge_SUITE.erl b/lib/stdlib/test/supervisor_bridge_SUITE.erl index 94e719bea1..029cb3fd7f 100644 --- a/lib/stdlib/test/supervisor_bridge_SUITE.erl +++ b/lib/stdlib/test/supervisor_bridge_SUITE.erl @@ -30,7 +30,9 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,1}}]. all() -> [starting, mini_terminate, mini_die, badstart, simple_global_supervisor]. @@ -53,33 +55,30 @@ end_per_group(_GroupName, Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -starting(suite) -> []; starting(Config) when is_list(Config) -> process_flag(trap_exit,true), - ?line ignore = start(1), - ?line {error,testing} = start(2), + ignore = start(1), + {error,testing} = start(2), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -mini_terminate(suite) -> []; mini_terminate(Config) when is_list(Config) -> miniappl(1), ok. -mini_die(suite) -> []; mini_die(Config) when is_list(Config) -> miniappl(2), ok. miniappl(N) -> process_flag(trap_exit,true), - ?line {ok,Server} = start(3), - ?line Client = spawn_link(?MODULE,client,[N]), - ?line Handle = test_server:timetrap(2000), - ?line miniappl_loop(Client,Server), - ?line test_server:timetrap_cancel(Handle). + {ok,Server} = start(3), + Client = spawn_link(?MODULE,client,[N]), + ct:timetrap({seconds,2}), + miniappl_loop(Client, Server). + miniappl_loop([],[]) -> ok; @@ -87,19 +86,19 @@ miniappl_loop(Client,Server) -> io:format("Client ~p, Server ~p\n",[Client,Server]), receive {'EXIT',Client,_} -> - ?line miniappl_loop([],Server); + miniappl_loop([],Server); {'EXIT',Server,killed} -> %% terminate - ?line miniappl_loop(Client,[]); + miniappl_loop(Client,[]); {'EXIT',Server,died} -> %% die - ?line miniappl_loop(Client,[]); + miniappl_loop(Client,[]); {dying,_Reason} -> - ?line miniappl_loop(Client, Server); + miniappl_loop(Client, Server); Other -> - ?line exit({failed,Other}) + exit({failed,Other}) end. %%%%%%%%%%%%%%%%%%%% -% Client +%% Client client(N) -> io:format("Client starting...\n"), @@ -112,7 +111,7 @@ client(N) -> exit(fine). %%%%%%%%%%%%%%%%%%%% -% Non compliant server +%% Non compliant server start(N) -> supervisor_bridge:start_link({local,?bridge_name},?MODULE,N). @@ -170,45 +169,44 @@ terminate(_Reason, _State) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -badstart(suite) -> []; -badstart(doc) -> "Test various bad ways of starting a supervisor bridge."; +%% Test various bad ways of starting a supervisor bridge. badstart(Config) when is_list(Config) -> - ?line Dog = test_server:timetrap(test_server:minutes(1)), - %% Various bad arguments. - ?line {'EXIT',_} = + {'EXIT',_} = (catch supervisor_bridge:start_link({xxx,?bridge_name},?MODULE,1)), - ?line {'EXIT',_} = + {'EXIT',_} = (catch supervisor_bridge:start_link({local,"foo"},?MODULE,1)), - ?line {'EXIT',_} = + {'EXIT',_} = (catch supervisor_bridge:start_link(?bridge_name,?MODULE,1)), - ?line [] = test_server:messages_get(), % No messages waiting + receive + Msg -> + ct:fail({unexpected,Msg}) + after 1 -> + ok + end, %% Already started. - ?line process_flag(trap_exit, true), - ?line {ok,Pid} = + process_flag(trap_exit, true), + {ok,Pid} = supervisor_bridge:start_link({local,?bridge_name},?MODULE,3), - ?line {error,{already_started,Pid}} = + {error,{already_started,Pid}} = supervisor_bridge:start_link({local,?bridge_name},?MODULE,3), - ?line public_kill(), + public_kill(), %% We used to wait 1 ms before retrieving the message queue, %% but that might not always be enough if the machine is overloaded. - ?line receive - {'EXIT', Pid, killed} -> ok - end, - ?line test_server:timetrap_cancel(Dog), + receive + {'EXIT', Pid, killed} -> ok + end, ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% OTP-9212. Restart of global supervisor. -simple_global_supervisor(suite) -> []; -simple_global_supervisor(doc) -> "Globally registered supervisor."; +%% Globally registered supervisor. simple_global_supervisor(Config) when is_list(Config) -> - ?line Dog = test_server:timetrap({seconds,10}), Child = {child, {?MODULE,server9212,[]}, permanent, 2000, worker, []}, InitResult = {ok, {{one_for_all,3,60}, [Child]}}, @@ -216,16 +214,15 @@ simple_global_supervisor(Config) when is_list(Config) -> supervisor:start_link({local,bridge9212}, ?MODULE, {4,InitResult}), BN_1 = global:whereis_name(?bridge_name), - ?line exit(BN_1, kill), + exit(BN_1, kill), timer:sleep(200), BN_2 = global:whereis_name(?bridge_name), - ?line true = is_pid(BN_2), - ?line true = BN_1 =/= BN_2, + true = is_pid(BN_2), + true = BN_1 =/= BN_2, - ?line process_flag(trap_exit, true), + process_flag(trap_exit, true), exit(Sup, kill), - ?line receive {'EXIT', Sup, killed} -> ok end, - ?line test_server:timetrap_cancel(Dog), + receive {'EXIT', Sup, killed} -> ok end, ok. server9212() -> diff --git a/lib/stdlib/test/sys_SUITE.erl b/lib/stdlib/test/sys_SUITE.erl index 102a147fcd..39bc835824 100644 --- a/lib/stdlib/test/sys_SUITE.erl +++ b/lib/stdlib/test/sys_SUITE.erl @@ -53,7 +53,6 @@ end_per_group(_GroupName, Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -log(suite) -> []; log(Config) when is_list(Config) -> {ok,_Server} = start(), ok = sys:log(?server,true), @@ -63,9 +62,8 @@ log(Config) when is_list(Config) -> stop(), ok. -log_to_file(suite) -> []; log_to_file(Config) when is_list(Config) -> - TempName = test_server:temp_name(?config(priv_dir,Config) ++ "sys."), + TempName = test_server:temp_name(proplists:get_value(priv_dir,Config) ++ "sys."), {ok,_Server} = start(), ok = sys:log_to_file(?server,TempName), {ok,-44} = public_call(44), @@ -74,20 +72,19 @@ log_to_file(Config) when is_list(Config) -> Msg1 = io:get_line(Fd,''), Msg2 = io:get_line(Fd,''), file:close(Fd), - lists:prefix("*DBG* sys_SUITE_server got call {req,44} from ",Msg1), - lists:prefix("*DBG* sys_SUITE_server sent {ok,-44} to ",Msg2), + "*DBG* sys_SUITE_server got call {req,44} from " ++ _ = Msg1, + "*DBG* sys_SUITE_server sent {ok,-44} to " ++ _ = Msg2, stop(), ok. -stats(suite) -> []; stats(Config) when is_list(Config) -> Self = self(), {ok,_Server} = start(), ok = sys:statistics(?server,true), {ok,-44} = public_call(44), {ok,Stats} = sys:statistics(?server,get), - lists:member({messages_in,1},Stats), - lists:member({messages_out,1},Stats), + true = lists:member({messages_in,1}, Stats), + true = lists:member({messages_out,0}, Stats), ok = sys:statistics(?server,false), {status,_Pid,{module,_Mod},[_PDict,running,Self,_,_]} = sys:get_status(?server), @@ -95,43 +92,40 @@ stats(Config) when is_list(Config) -> stop(), ok. -trace(suite) -> []; trace(Config) when is_list(Config) -> {ok,_Server} = start(), - test_server:sleep(2000), - test_server:capture_start(), + ct:sleep(2000), + ct:capture_start(), sys:trace(?server,true), {ok,-44} = public_call(44), %% ho, hum, allow for the io to reach us.. - test_server:sleep(1000), - test_server:capture_stop(), - [Msg1,Msg2] = test_server:capture_get(), - lists:prefix("*DBG* sys_SUITE_server got call {req,44} from ",Msg1), - lists:prefix("*DBG* sys_SUITE_server sent {ok,-44} to ",Msg2), + ct:sleep(1000), + ct:capture_stop(), + [Msg1,Msg2] = ct:capture_get(), + "*DBG* sys_SUITE_server got call {req,44} from " ++ _ = Msg1, + "*DBG* sys_SUITE_server sent {ok,-44} to " ++ _ = Msg2, stop(), ok. -suspend(suite) -> []; suspend(Config) when is_list(Config) -> - ?line {ok,_Server} = start(), - ?line sys:suspend(?server,1000), - ?line {'EXIT',_} = (catch public_call(48)), - ?line {status,_,_,[_,suspended,_,_,_]} = sys:get_status(?server), - ?line sys:suspend(?server,1000), %% doing it twice is no error - ?line {'EXIT',_} = (catch public_call(48)), - ?line sys:resume(?server), - ?line {status,_,_,[_,running,_,_,_]} = sys:get_status(?server), - ?line {ok,-48} = (catch public_call(48)), - ?line sys:resume(?server), %% doing it twice is no error - ?line {ok,-48} = (catch public_call(48)), - ?line stop(), + {ok,_Server} = start(), + sys:suspend(?server,1000), + {'EXIT',_} = (catch public_call(48)), + {status,_,_,[_,suspended,_,_,_]} = sys:get_status(?server), + sys:suspend(?server,1000), %% doing it twice is no error + {'EXIT',_} = (catch public_call(48)), + sys:resume(?server), + {status,_,_,[_,running,_,_,_]} = sys:get_status(?server), + {ok,-48} = (catch public_call(48)), + sys:resume(?server), %% doing it twice is no error + {ok,-48} = (catch public_call(48)), + stop(), ok. -install(suite) -> []; install(Config) when is_list(Config) -> - ?line {ok,_Server} = start(), - ?line Master = self(), - ?line SpyFun = + {ok,_Server} = start(), + Master = self(), + SpyFun = fun(func_state,Event,ProcState) -> case Event of {in,{'$gen_call',_From,{req,Arg}}} -> @@ -141,22 +135,26 @@ install(Config) when is_list(Config) -> io:format("Trigged other=~p\n",[Other]) end end, - ?line sys:install(?server,{SpyFun,func_state}), - ?line {ok,-1} = (catch public_call(1)), - ?line sys:no_debug(?server), - ?line {ok,-2} = (catch public_call(2)), - ?line sys:install(?server,{SpyFun,func_state}), - ?line sys:install(?server,{SpyFun,func_state}), - ?line {ok,-3} = (catch public_call(3)), - ?line sys:remove(?server,SpyFun), - ?line {ok,-4} = (catch public_call(4)), - ?line Msgs = test_server:messages_get(), - ?line [{spy_got,{request,1},sys_SUITE_server}, - {spy_got,{request,3},sys_SUITE_server}] = Msgs, - ?line stop(), + sys:install(?server,{SpyFun,func_state}), + {ok,-1} = (catch public_call(1)), + sys:no_debug(?server), + {ok,-2} = (catch public_call(2)), + sys:install(?server,{SpyFun,func_state}), + sys:install(?server,{SpyFun,func_state}), + {ok,-3} = (catch public_call(3)), + sys:remove(?server,SpyFun), + {ok,-4} = (catch public_call(4)), + [{spy_got,{request,1},sys_SUITE_server}, + {spy_got,{request,3},sys_SUITE_server}] = get_messages(), + stop(), ok. -special_process(suite) -> []; +get_messages() -> + receive + Msg -> [Msg|get_messages()] + after 1 -> [] + end. + special_process(Config) when is_list(Config) -> ok = spec_proc(sys_sp1), ok = spec_proc(sys_sp2). diff --git a/lib/stdlib/test/tar_SUITE.erl b/lib/stdlib/test/tar_SUITE.erl index a22eaa1d3a..7f20851445 100644 --- a/lib/stdlib/test/tar_SUITE.erl +++ b/lib/stdlib/test/tar_SUITE.erl @@ -53,10 +53,9 @@ end_per_group(_GroupName, Config) -> Config. -borderline(doc) -> - ["Test creating, listing and extracting one file from an archive", - "multiple times with different file sizes. ", - "Also check that the file attributes of the extracted file has survived."]; +%% Test creating, listing and extracting one file from an archive, +%% multiple times with different file sizes. Also check that the file +%% attributes of the extracted file has survived. borderline(Config) when is_list(Config) -> %% Note: We cannot use absolute paths, because the pathnames will be @@ -64,47 +63,47 @@ borderline(Config) when is_list(Config) -> %% Therefore, strip off the current working directory from the front %% of the private directory path. - ?line {ok, Cwd} = file:get_cwd(), - ?line RootDir = ?config(priv_dir, Config), - ?line TempDir = remove_prefix(Cwd++"/", filename:join(RootDir, "borderline")), - ?line ok = file:make_dir(TempDir), + {ok, Cwd} = file:get_cwd(), + RootDir = proplists:get_value(priv_dir, Config), + TempDir = remove_prefix(Cwd++"/", filename:join(RootDir, "borderline")), + ok = file:make_dir(TempDir), - ?line Record = 512, - ?line Block = 20 * Record, + Record = 512, + Block = 20 * Record, - ?line lists:foreach(fun(Size) -> borderline_test(Size, TempDir) end, - [0, 1, 10, 13, 127, 333, Record-1, Record, Record+1, - Block-2*Record-1, Block-2*Record, Block-2*Record+1, - Block-Record-1, Block-Record, Block-Record+1, - Block-1, Block, Block+1, - Block+Record-1, Block+Record, Block+Record+1]), + lists:foreach(fun(Size) -> borderline_test(Size, TempDir) end, + [0, 1, 10, 13, 127, 333, Record-1, Record, Record+1, + Block-2*Record-1, Block-2*Record, Block-2*Record+1, + Block-Record-1, Block-Record, Block-Record+1, + Block-1, Block, Block+1, + Block+Record-1, Block+Record, Block+Record+1]), %% Clean up. - ?line delete_files([TempDir]), + delete_files([TempDir]), ok. borderline_test(Size, TempDir) -> - ?line Archive = filename:join(TempDir, "ar_"++integer_to_list(Size)++".tar"), - ?line Name = filename:join(TempDir, "file_"++integer_to_list(Size)), - ?line io:format("Testing size ~p", [Size]), + Archive = filename:join(TempDir, "ar_"++integer_to_list(Size)++".tar"), + Name = filename:join(TempDir, "file_"++integer_to_list(Size)), + io:format("Testing size ~p", [Size]), %% Create a file and archive it. X0 = erlang:monotonic_time(), - ?line file:write_file(Name, random_byte_list(X0, Size)), - ?line ok = erl_tar:create(Archive, [Name]), - ?line ok = file:delete(Name), + file:write_file(Name, random_byte_list(X0, Size)), + ok = erl_tar:create(Archive, [Name]), + ok = file:delete(Name), %% Verify listing and extracting. - ?line {ok, [Name]} = erl_tar:table(Archive), - ?line ok = erl_tar:extract(Archive, [verbose]), + {ok, [Name]} = erl_tar:table(Archive), + ok = erl_tar:extract(Archive, [verbose]), %% Verify contents of extracted file. - ?line {ok, Bin} = file:read_file(Name), - ?line true = match_byte_list(X0, binary_to_list(Bin)), + {ok, Bin} = file:read_file(Name), + true = match_byte_list(X0, binary_to_list(Bin)), %% Verify that Unix tar can read it. - ?line tar_tf(Archive, Name), + tar_tf(Archive, Name), ok. @@ -117,20 +116,20 @@ tar_tf(Archive, Name) -> end. tar_tf1(Archive, Name) -> - ?line Expect = Name ++ "\n", - ?line cmd_expect("tar tf " ++ Archive, Expect). + Expect = Name ++ "\n", + cmd_expect("tar tf " ++ Archive, Expect). %% We can't use os:cmd/1, because Unix 'tar tf Name' on Solaris never %% terminates when given an archive of a size it doesn't like. cmd_expect(Cmd, Expect) -> - ?line Port = open_port({spawn, make_cmd(Cmd)}, [stream, in, eof]), - ?line get_data(Port, Expect). + Port = open_port({spawn, make_cmd(Cmd)}, [stream, in, eof]), + get_data(Port, Expect). get_data(Port, Expect) -> receive {Port, {data, Bytes}} -> - ?line get_data(Port, match_output(Bytes, Expect, Port)); + get_data(Port, match_output(Bytes, Expect, Port)); {Port, eof} -> Port ! {self(), close}, receive @@ -143,26 +142,26 @@ get_data(Port, Expect) -> after 1 -> % force context switch ok end, - ?line match_output(eof, Expect, Port) + match_output(eof, Expect, Port) end. match_output([C|Output], [C|Expect], Port) -> - ?line match_output(Output, Expect, Port); + match_output(Output, Expect, Port); match_output([_|_], [_|_], Port) -> - ?line kill_port_and_fail(Port, badmatch); + kill_port_and_fail(Port, badmatch); match_output([X|Output], [], Port) -> - ?line kill_port_and_fail(Port, {too_much_data, [X|Output]}); + kill_port_and_fail(Port, {too_much_data, [X|Output]}); match_output([], Expect, _Port) -> Expect; match_output(eof, [], _Port) -> []; match_output(eof, _Expect, Port) -> - ?line kill_port_and_fail(Port, unexpected_end_of_input). + kill_port_and_fail(Port, unexpected_end_of_input). kill_port_and_fail(Port, Reason) -> unlink(Port), exit(Port, die), - test_server:fail(Reason). + ct:fail(Reason). make_cmd(Cmd) -> case os:type() of @@ -198,58 +197,56 @@ random_byte_list(_X, 0, Result) -> next_random(X) -> (X*17059465+1) band 16#fffffffff. -atomic(doc) -> - ["Test the 'atomic' operations: create/extract/table, on compressed " - "and uncompressed archives." - "Also test the 'cooked' option."]; -atomic(suite) -> []; +%% Test the 'atomic' operations: create/extract/table, on compressed +%% and uncompressed archives. +%% Also test the 'cooked' option. atomic(Config) when is_list(Config) -> - ?line ok = file:set_cwd(?config(priv_dir, Config)), - ?line DataFiles = data_files(), - ?line Names = [Name || {Name,_,_} <- DataFiles], + ok = file:set_cwd(proplists:get_value(priv_dir, Config)), + DataFiles = data_files(), + Names = [Name || {Name,_,_} <- DataFiles], io:format("Names: ~p", [Names]), %% Create an uncompressed archive. The compressed flag should still be %% allowed when listing contents or extracting. - ?line Tar1 = "uncompressed.tar", - ?line erl_tar:create(Tar1, Names, []), - ?line {ok, Names} = erl_tar:table(Tar1, []), - ?line {ok, Names} = erl_tar:table(Tar1, [compressed]), - ?line {ok, Names} = erl_tar:table(Tar1, [cooked]), - ?line {ok, Names} = erl_tar:table(Tar1, [compressed,cooked]), - + Tar1 = "uncompressed.tar", + erl_tar:create(Tar1, Names, []), + {ok, Names} = erl_tar:table(Tar1, []), + {ok, Names} = erl_tar:table(Tar1, [compressed]), + {ok, Names} = erl_tar:table(Tar1, [cooked]), + {ok, Names} = erl_tar:table(Tar1, [compressed,cooked]), + %% Create a compressed archive. - ?line Tar2 = "compressed.tar", - ?line erl_tar:create(Tar2, Names, [compressed]), - ?line {ok, Names} = erl_tar:table(Tar2, [compressed]), - ?line {error, Reason} = erl_tar:table(Tar2, []), - ?line {ok, Names} = erl_tar:table(Tar2, [compressed,cooked]), - ?line {error, Reason} = erl_tar:table(Tar2, [cooked]), - ?line ok = io:format("No compressed option: ~p, ~s", - [Reason, erl_tar:format_error(Reason)]), + Tar2 = "compressed.tar", + erl_tar:create(Tar2, Names, [compressed]), + {ok, Names} = erl_tar:table(Tar2, [compressed]), + {error, Reason} = erl_tar:table(Tar2, []), + {ok, Names} = erl_tar:table(Tar2, [compressed,cooked]), + {error, Reason} = erl_tar:table(Tar2, [cooked]), + ok = io:format("No compressed option: ~p, ~s", + [Reason, erl_tar:format_error(Reason)]), %% Same test again, but this time created with 'cooked' - ?line Tar3 = "uncompressed_cooked.tar", - ?line erl_tar:create(Tar3, Names, [cooked]), - ?line {ok, Names} = erl_tar:table(Tar3, []), - ?line {ok, Names} = erl_tar:table(Tar3, [compressed]), - ?line {ok, Names} = erl_tar:table(Tar3, [cooked]), - ?line {ok, Names} = erl_tar:table(Tar3, [compressed,cooked]), - - ?line Tar4 = "compressed_cooked.tar", - ?line erl_tar:create(Tar4, Names, [compressed,cooked]), - ?line {ok, Names} = erl_tar:table(Tar4, [compressed]), - ?line {error, Reason} = erl_tar:table(Tar4, []), - ?line {ok, Names} = erl_tar:table(Tar4, [compressed,cooked]), - ?line {error, Reason} = erl_tar:table(Tar4, [cooked]), - ?line ok = io:format("No compressed option: ~p, ~s", - [Reason, erl_tar:format_error(Reason)]), + Tar3 = "uncompressed_cooked.tar", + erl_tar:create(Tar3, Names, [cooked]), + {ok, Names} = erl_tar:table(Tar3, []), + {ok, Names} = erl_tar:table(Tar3, [compressed]), + {ok, Names} = erl_tar:table(Tar3, [cooked]), + {ok, Names} = erl_tar:table(Tar3, [compressed,cooked]), + + Tar4 = "compressed_cooked.tar", + erl_tar:create(Tar4, Names, [compressed,cooked]), + {ok, Names} = erl_tar:table(Tar4, [compressed]), + {error, Reason} = erl_tar:table(Tar4, []), + {ok, Names} = erl_tar:table(Tar4, [compressed,cooked]), + {error, Reason} = erl_tar:table(Tar4, [cooked]), + ok = io:format("No compressed option: ~p, ~s", + [Reason, erl_tar:format_error(Reason)]), %% Clean up. - ?line delete_files([Tar1,Tar2,Tar3,Tar4|Names]), + delete_files([Tar1,Tar2,Tar3,Tar4|Names]), ok. @@ -279,50 +276,48 @@ create_files([{Name, Size, First}|Rest]) -> create_files([]) -> ok. -long_names(doc) -> - ["Test to extract an Unix tar file containing filenames longer than 100 ", - "characters and empty directories."]; +%% Test to extract an Unix tar file containing filenames longer than +%% 100 characters and empty directories. long_names(Config) when is_list(Config) -> - ?line DataDir = ?config(data_dir, Config), - ?line Long = filename:join(DataDir, "long_names.tar"), + DataDir = proplists:get_value(data_dir, Config), + Long = filename:join(DataDir, "long_names.tar"), run_in_short_tempdir(Config, fun() -> do_long_names(Long) end). do_long_names(Long) -> %% Try table/2 and extract/2. - ?line case erl_tar:table(Long, [verbose]) of - {ok,List} when is_list(List) -> - ?line io:format("~p\n", [List]) - end, + case erl_tar:table(Long, [verbose]) of + {ok,List} when is_list(List) -> + io:format("~p\n", [List]) + end, - ?line {ok,Cwd} = file:get_cwd(), - ?line ok = erl_tar:extract(Long), - ?line Base = filename:join([Cwd, "original_software", "written_by", - "a_bunch_of_hackers", - "spending_all_their_nights", - "still", "not_long_enough", - "but_soon_it_will_be"]), + {ok,Cwd} = file:get_cwd(), + ok = erl_tar:extract(Long), + Base = filename:join([Cwd, "original_software", "written_by", + "a_bunch_of_hackers", + "spending_all_their_nights", + "still", "not_long_enough", + "but_soon_it_will_be"]), %% Verify that the empty directory was created. - ?line EmptyDir = filename:join(Base, "empty_directory"), - ?line {ok, #file_info{type=directory}} = file:read_file_info(EmptyDir), + EmptyDir = filename:join(Base, "empty_directory"), + {ok, #file_info{type=directory}} = file:read_file_info(EmptyDir), %% Verify that the files were created. - ?line {ok,First} = file:read_file(filename:join(Base, "first_file")), - ?line {ok,Second} = file:read_file(filename:join(Base, "second_file")), - ?line "Here"++_ = binary_to_list(First), - ?line "And"++_ = binary_to_list(Second), + {ok,First} = file:read_file(filename:join(Base, "first_file")), + {ok,Second} = file:read_file(filename:join(Base, "second_file")), + "Here"++_ = binary_to_list(First), + "And"++_ = binary_to_list(Second), ok. -create_long_names(doc) -> - ["Creates a tar file from a deep directory structure (filenames are ", - "longer than 100 characters)."]; +%% Creates a tar file from a deep directory structure (filenames are +%% longer than 100 characters). create_long_names(Config) when is_list(Config) -> run_in_short_tempdir(Config, fun create_long_names/0). - + create_long_names() -> - ?line {ok,Dir} = file:get_cwd(), + {ok,Dir} = file:get_cwd(), Dirs = ["aslfjkshjkhliuf", "asdhjfehnbfsky", "sahajfskdfhsz", @@ -330,49 +325,48 @@ create_long_names() -> "f7nafhjgffagkhsfkhsjk", "dfjasldkfjsdkfjashbv"], - ?line DeepDir = make_dirs(Dirs, []), - ?line AFile = filename:join(DeepDir, "a_file"), - ?line Hello = "hello, world\n", - ?line ok = file:write_file(AFile, Hello), - ?line TarName = filename:join(Dir, "my_tar_with_long_names.tar"), - ?line ok = erl_tar:create(TarName, [AFile]), + DeepDir = make_dirs(Dirs, []), + AFile = filename:join(DeepDir, "a_file"), + Hello = "hello, world\n", + ok = file:write_file(AFile, Hello), + TarName = filename:join(Dir, "my_tar_with_long_names.tar"), + ok = erl_tar:create(TarName, [AFile]), %% Print contents. - ?line ok = erl_tar:tt(TarName), + ok = erl_tar:tt(TarName), %% Extract and verify. - ?line ExtractDir = "extract_dir", - ?line ok = file:make_dir(ExtractDir), - ?line ok = erl_tar:extract(TarName, [{cwd,ExtractDir}]), - ?line {ok, Bin} = file:read_file(filename:join(ExtractDir, AFile)), - ?line Hello = binary_to_list(Bin), + ExtractDir = "extract_dir", + ok = file:make_dir(ExtractDir), + ok = erl_tar:extract(TarName, [{cwd,ExtractDir}]), + {ok, Bin} = file:read_file(filename:join(ExtractDir, AFile)), + Hello = binary_to_list(Bin), ok. make_dirs([Dir|Rest], []) -> - ?line ok = file:make_dir(Dir), - ?line make_dirs(Rest, Dir); + ok = file:make_dir(Dir), + make_dirs(Rest, Dir); make_dirs([Dir|Rest], Parent) -> - ?line Name = filename:join(Parent, Dir), - ?line ok = file:make_dir(Name), - ?line make_dirs(Rest, Name); + Name = filename:join(Parent, Dir), + ok = file:make_dir(Name), + make_dirs(Rest, Name); make_dirs([], Dir) -> Dir. -bad_tar(doc) -> - ["Try erl_tar:table/2 and erl_tar:extract/2 on some corrupted tar files."]; +%% Try erl_tar:table/2 and erl_tar:extract/2 on some corrupted tar files. bad_tar(Config) when is_list(Config) -> - ?line try_bad("bad_checksum", bad_header, Config), - ?line try_bad("bad_octal", bad_header, Config), - ?line try_bad("bad_too_short", eof, Config), - ?line try_bad("bad_even_shorter", eof, Config), + try_bad("bad_checksum", bad_header, Config), + try_bad("bad_octal", bad_header, Config), + try_bad("bad_too_short", eof, Config), + try_bad("bad_even_shorter", eof, Config), ok. try_bad(Name0, Reason, Config) -> - %% Intentionally no ?line macros here. + %% Intentionally no macros here. - DataDir = ?config(data_dir, Config), - PrivDir = ?config(priv_dir, Config), + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), Name = Name0 ++ ".tar", io:format("~nTrying ~s", [Name]), Full = filename:join(DataDir, Name), @@ -383,38 +377,37 @@ try_bad(Name0, Reason, Config) -> io:format("Result: ~p", [Expected]), case catch erl_tar:format_error(Reason) of {'EXIT', CrashReason} -> - test_server:fail({format_error, crashed, CrashReason}); + ct:fail({format_error, crashed, CrashReason}); String when is_list(String) -> io:format("format_error(~p) -> ~s", [Reason, String]); Other -> - test_server:fail({format_error, returned, Other}) + ct:fail({format_error, returned, Other}) end; {Other1, Other2} -> io:format("table/2 returned ~p", [Other1]), io:format("extract/2 returned ~p", [Other2]), - test_server:fail({bad_return_value, Other1, Other2}) + ct:fail({bad_return_value, Other1, Other2}) end. -errors(doc) -> - ["Tests that some common errors return correct error codes ", - "and that format_error/1 handles them correctly."]; +%% Tests that some common errors return correct error codes +%% and that format_error/1 handles them correctly. errors(Config) when is_list(Config) -> - ?line PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), %% Give the tar file the same name as a directory. - ?line BadTar = filename:join(PrivDir, "bad_tarfile.tar"), - ?line ok = file:make_dir(BadTar), - ?line try_error(erl_tar, create, [BadTar, []], {BadTar, eisdir}), + BadTar = filename:join(PrivDir, "bad_tarfile.tar"), + ok = file:make_dir(BadTar), + try_error(erl_tar, create, [BadTar, []], {BadTar, eisdir}), %% Try including non-existent files in the tar file. - ?line NonExistent = "non_existent_file", - ?line GoodTar = filename:join(PrivDir, "a_good_tarfile.tar"), - ?line try_error(erl_tar, create, [GoodTar, [NonExistent]], - {NonExistent, enoent}), + NonExistent = "non_existent_file", + GoodTar = filename:join(PrivDir, "a_good_tarfile.tar"), + try_error(erl_tar, create, [GoodTar, [NonExistent]], + {NonExistent, enoent}), %% Clean up. - ?line delete_files([GoodTar,BadTar]), - + delete_files([GoodTar,BadTar]), + ok. try_error(M, F, A, Error) -> @@ -423,18 +416,18 @@ try_error(M, F, A, Error) -> {'EXIT', Reason} -> exit(Reason); ok -> - test_server:fail(unexpected_success); + ct:fail(unexpected_success); {error, Error} -> case catch erl_tar:format_error(Error) of {'EXIT', FReason} -> - test_server:fail({format_error, crashed, FReason}); + ct:fail({format_error, crashed, FReason}); String when is_list(String) -> io:format("format_error(~p) -> ~s", [Error, String]); Other -> - test_server:fail({format_error, returned, Other}) + ct:fail({format_error, returned, Other}) end; Other -> - test_server:fail({expected, {error, Error}, actual, Other}) + ct:fail({expected, {error, Error}, actual, Other}) end. %% remove_prefix(Prefix, List) -> ListWithoutPrefix. @@ -444,107 +437,104 @@ remove_prefix([C|Rest1], [C|Rest2]) -> remove_prefix(_, Result) -> Result. -extract_from_binary(doc) -> - "Test extracting a tar archive from a binary."; +%% Test extracting a tar archive from a binary. extract_from_binary(Config) when is_list(Config) -> - ?line DataDir = ?config(data_dir, Config), - ?line PrivDir = ?config(priv_dir, Config), - ?line Long = filename:join(DataDir, "no_fancy_stuff.tar"), - ?line ExtractDir = filename:join(PrivDir, "extract_from_binary"), - ?line ok = file:make_dir(ExtractDir), - + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), + Long = filename:join(DataDir, "no_fancy_stuff.tar"), + ExtractDir = filename:join(PrivDir, "extract_from_binary"), + ok = file:make_dir(ExtractDir), + %% Read a tar file into a binary and extract from the binary. - ?line {ok, Bin} = file:read_file(Long), - ?line ok = erl_tar:extract({binary, Bin}, [{cwd,ExtractDir}]), + {ok, Bin} = file:read_file(Long), + ok = erl_tar:extract({binary, Bin}, [{cwd,ExtractDir}]), %% Verify. Dir = filename:join(ExtractDir, "no_fancy_stuff"), - ?line true = filelib:is_dir(Dir), - ?line true = filelib:is_file(filename:join(Dir, "a_dir_list")), - ?line true = filelib:is_file(filename:join(Dir, "EPLICENCE")), + true = filelib:is_dir(Dir), + true = filelib:is_file(filename:join(Dir, "a_dir_list")), + true = filelib:is_file(filename:join(Dir, "EPLICENCE")), %% Clean up. - ?line delete_files([ExtractDir]), + delete_files([ExtractDir]), ok. extract_from_binary_compressed(Config) when is_list(Config) -> %% Test extracting a compressed tar archive from a binary. - ?line DataDir = ?config(data_dir, Config), - ?line PrivDir = ?config(priv_dir, Config), - ?line Name = filename:join(DataDir, "cooked_tar_problem.tar.gz"), - ?line ExtractDir = filename:join(PrivDir, "extract_from_binary_compressed"), - ?line ok = file:make_dir(ExtractDir), - ?line {ok,Bin} = file:read_file(Name), + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), + Name = filename:join(DataDir, "cooked_tar_problem.tar.gz"), + ExtractDir = filename:join(PrivDir, "extract_from_binary_compressed"), + ok = file:make_dir(ExtractDir), + {ok,Bin} = file:read_file(Name), %% Try taking contents. - ?line {ok,Files} = erl_tar:table({binary,Bin}, [compressed]), - ?line io:format("~p\n", [Files]), - ?line 19 = length(Files), - + {ok,Files} = erl_tar:table({binary,Bin}, [compressed]), + io:format("~p\n", [Files]), + 19 = length(Files), + %% Trying extracting from a binary. - ?line ok = erl_tar:extract({binary,Bin}, [compressed,{cwd,ExtractDir}]), - ?line {ok,List} = file:list_dir(filename:join(ExtractDir, "ddll_SUITE_data")), - ?line io:format("~p\n", [List]), - ?line 19 = length(List), + ok = erl_tar:extract({binary,Bin}, [compressed,{cwd,ExtractDir}]), + {ok,List} = file:list_dir(filename:join(ExtractDir, "ddll_SUITE_data")), + io:format("~p\n", [List]), + 19 = length(List), %% Clean up while at the same time testing that all file %% were extracted as expected. lists:foreach(fun(N) -> File = filename:join(ExtractDir, N), io:format("Deleting: ~p\n", [File]), - ?line ok = file:delete(File) + ok = file:delete(File) end, Files), %% Clean up the rest. - ?line delete_files([ExtractDir]), + delete_files([ExtractDir]), ok. -extract_from_open_file(doc) -> - "Test extracting a tar archive from an open file."; +%% Test extracting a tar archive from an open file. extract_from_open_file(Config) when is_list(Config) -> - ?line DataDir = ?config(data_dir, Config), - ?line PrivDir = ?config(priv_dir, Config), - ?line Long = filename:join(DataDir, "no_fancy_stuff.tar"), - ?line ExtractDir = filename:join(PrivDir, "extract_from_open_file"), - ?line ok = file:make_dir(ExtractDir), + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), + Long = filename:join(DataDir, "no_fancy_stuff.tar"), + ExtractDir = filename:join(PrivDir, "extract_from_open_file"), + ok = file:make_dir(ExtractDir), - ?line {ok, File} = file:open(Long, [read]), - ?line ok = erl_tar:extract({file, File}, [{cwd,ExtractDir}]), + {ok, File} = file:open(Long, [read]), + ok = erl_tar:extract({file, File}, [{cwd,ExtractDir}]), %% Verify. Dir = filename:join(ExtractDir, "no_fancy_stuff"), - ?line true = filelib:is_dir(Dir), - ?line true = filelib:is_file(filename:join(Dir, "a_dir_list")), - ?line true = filelib:is_file(filename:join(Dir, "EPLICENCE")), + true = filelib:is_dir(Dir), + true = filelib:is_file(filename:join(Dir, "a_dir_list")), + true = filelib:is_file(filename:join(Dir, "EPLICENCE")), %% Close open file. - ?line ok = file:close(File), + ok = file:close(File), %% Clean up. - ?line delete_files([ExtractDir]), + delete_files([ExtractDir]), ok. -symlinks(doc) -> - "Test that archives containing symlinks can be created and extracted."; +%% Test that archives containing symlinks can be created and extracted. symlinks(Config) when is_list(Config) -> - ?line PrivDir = ?config(priv_dir, Config), - ?line Dir = filename:join(PrivDir, "symlinks"), - ?line ok = file:make_dir(Dir), - ?line ABadSymlink = filename:join(Dir, "bad_symlink"), - ?line PointsTo = "/a/definitely/non_existing/path", - ?line Res = case make_symlink("/a/definitely/non_existing/path", ABadSymlink) of - {error, enotsup} -> - {skip, "Symbolic links not supported on this platform"}; - ok -> - symlinks(Dir, "bad_symlink", PointsTo), - long_symlink(Dir) - end, + PrivDir = proplists:get_value(priv_dir, Config), + Dir = filename:join(PrivDir, "symlinks"), + ok = file:make_dir(Dir), + ABadSymlink = filename:join(Dir, "bad_symlink"), + PointsTo = "/a/definitely/non_existing/path", + Res = case make_symlink("/a/definitely/non_existing/path", ABadSymlink) of + {error, enotsup} -> + {skip, "Symbolic links not supported on this platform"}; + ok -> + symlinks(Dir, "bad_symlink", PointsTo), + long_symlink(Dir) + end, %% Clean up. - ?line delete_files([Dir]), + delete_files([Dir]), Res. make_symlink(Path, Link) -> @@ -569,103 +559,103 @@ make_symlink(Path, Link) -> _ -> file:make_symlink(Path, Link) end. - + symlinks(Dir, BadSymlink, PointsTo) -> - ?line Tar = filename:join(Dir, "symlink.tar"), - ?line DerefTar = filename:join(Dir, "dereference.tar"), + Tar = filename:join(Dir, "symlink.tar"), + DerefTar = filename:join(Dir, "dereference.tar"), %% Create the archive. - ?line ok = file:set_cwd(Dir), - ?line GoodSymlink = "good_symlink", - ?line AFile = "a_good_file", - ?line ALine = "A line of text for a file.", - ?line ok = file:write_file(AFile, ALine), - ?line ok = file:make_symlink(AFile, GoodSymlink), - ?line ok = erl_tar:create(Tar, [BadSymlink, GoodSymlink, AFile], [verbose]), + ok = file:set_cwd(Dir), + GoodSymlink = "good_symlink", + AFile = "a_good_file", + ALine = "A line of text for a file.", + ok = file:write_file(AFile, ALine), + ok = file:make_symlink(AFile, GoodSymlink), + ok = erl_tar:create(Tar, [BadSymlink, GoodSymlink, AFile], [verbose]), %% List contents of tar file. - ?line ok = erl_tar:tt(Tar), + ok = erl_tar:tt(Tar), %% Also create another archive with the dereference flag. - ?line ok = erl_tar:create(DerefTar, [AFile, GoodSymlink], [dereference, verbose]), + ok = erl_tar:create(DerefTar, [AFile, GoodSymlink], [dereference, verbose]), %% Extract files to a new directory. - ?line NewDir = filename:join(Dir, "extracted"), - ?line ok = file:make_dir(NewDir), - ?line ok = erl_tar:extract(Tar, [{cwd, NewDir}, verbose]), + NewDir = filename:join(Dir, "extracted"), + ok = file:make_dir(NewDir), + ok = erl_tar:extract(Tar, [{cwd, NewDir}, verbose]), %% Verify that the files are there. - ?line ok = file:set_cwd(NewDir), - ?line {ok, #file_info{type=symlink}} = file:read_link_info(BadSymlink), - ?line {ok, PointsTo} = file:read_link(BadSymlink), - ?line {ok, #file_info{type=symlink}} = file:read_link_info(GoodSymlink), - ?line {ok, AFile} = file:read_link(GoodSymlink), - ?line Expected = list_to_binary(ALine), - ?line {ok, Expected} = file:read_file(GoodSymlink), + ok = file:set_cwd(NewDir), + {ok, #file_info{type=symlink}} = file:read_link_info(BadSymlink), + {ok, PointsTo} = file:read_link(BadSymlink), + {ok, #file_info{type=symlink}} = file:read_link_info(GoodSymlink), + {ok, AFile} = file:read_link(GoodSymlink), + Expected = list_to_binary(ALine), + {ok, Expected} = file:read_file(GoodSymlink), %% Extract the "dereferenced archive" to a new directory. - ?line NewDirDeref = filename:join(Dir, "extracted_deref"), - ?line ok = file:make_dir(NewDirDeref), - ?line ok = erl_tar:extract(DerefTar, [{cwd, NewDirDeref}, verbose]), + NewDirDeref = filename:join(Dir, "extracted_deref"), + ok = file:make_dir(NewDirDeref), + ok = erl_tar:extract(DerefTar, [{cwd, NewDirDeref}, verbose]), %% Verify that the files are there. - ?line ok = file:set_cwd(NewDirDeref), - ?line {ok, #file_info{type=regular}} = file:read_link_info(GoodSymlink), - ?line {ok, #file_info{type=regular}} = file:read_link_info(AFile), - ?line {ok, Expected} = file:read_file(GoodSymlink), - ?line {ok, Expected} = file:read_file(AFile), + ok = file:set_cwd(NewDirDeref), + {ok, #file_info{type=regular}} = file:read_link_info(GoodSymlink), + {ok, #file_info{type=regular}} = file:read_link_info(AFile), + {ok, Expected} = file:read_file(GoodSymlink), + {ok, Expected} = file:read_file(AFile), ok. long_symlink(Dir) -> - ?line Tar = filename:join(Dir, "long_symlink.tar"), - ?line ok = file:set_cwd(Dir), - - ?line AFile = "long_symlink", - ?line FarTooLong = "/tmp/aarrghh/this/path/is/far/longer/than/one/hundred/characters/which/is/the/maximum/number/of/characters/allowed", - ?line ok = file:make_symlink(FarTooLong, AFile), - ?line {error,Error} = erl_tar:create(Tar, [AFile], [verbose]), - ?line io:format("Error: ~s\n", [erl_tar:format_error(Error)]), - ?line {FarTooLong,symbolic_link_too_long} = Error, + Tar = filename:join(Dir, "long_symlink.tar"), + ok = file:set_cwd(Dir), + + AFile = "long_symlink", + FarTooLong = "/tmp/aarrghh/this/path/is/far/longer/than/one/hundred/characters/which/is/the/maximum/number/of/characters/allowed", + ok = file:make_symlink(FarTooLong, AFile), + {error,Error} = erl_tar:create(Tar, [AFile], [verbose]), + io:format("Error: ~s\n", [erl_tar:format_error(Error)]), + {FarTooLong,symbolic_link_too_long} = Error, ok. open_add_close(Config) when is_list(Config) -> - ?line PrivDir = ?config(priv_dir, Config), - ?line ok = file:set_cwd(PrivDir), - ?line Dir = filename:join(PrivDir, "open_add_close"), - ?line ok = file:make_dir(Dir), - - ?line [{FileOne,_,_},{FileTwo,_,_},{FileThree,_,_}] = oac_files(), - ?line ADir = "empty_dir", - ?line AnotherDir = "another_dir", - ?line SomeContent = filename:join(AnotherDir, "some_content"), - ?line ok = file:make_dir(ADir), - ?line ok = file:make_dir(AnotherDir), - ?line ok = file:make_dir(SomeContent), - - ?line TarOne = filename:join(Dir, "archive1.tar"), - ?line {ok,AD} = erl_tar:open(TarOne, [write]), - ?line ok = erl_tar:add(AD, FileOne, []), - ?line ok = erl_tar:add(AD, FileTwo, "second file", []), - ?line ok = erl_tar:add(AD, FileThree, [verbose]), - ?line ok = erl_tar:add(AD, FileThree, "chunked", [{chunks,11411},verbose]), - ?line ok = erl_tar:add(AD, ADir, [verbose]), - ?line ok = erl_tar:add(AD, AnotherDir, [verbose]), - ?line ok = erl_tar:close(AD), - - ?line ok = erl_tar:t(TarOne), - ?line ok = erl_tar:tt(TarOne), - - ?line {ok,[FileOne,"second file",FileThree,"chunked",ADir,SomeContent]} = erl_tar:table(TarOne), - - ?line delete_files(["oac_file","oac_small","oac_big",Dir,AnotherDir,ADir]), + PrivDir = proplists:get_value(priv_dir, Config), + ok = file:set_cwd(PrivDir), + Dir = filename:join(PrivDir, "open_add_close"), + ok = file:make_dir(Dir), + + [{FileOne,_,_},{FileTwo,_,_},{FileThree,_,_}] = oac_files(), + ADir = "empty_dir", + AnotherDir = "another_dir", + SomeContent = filename:join(AnotherDir, "some_content"), + ok = file:make_dir(ADir), + ok = file:make_dir(AnotherDir), + ok = file:make_dir(SomeContent), + + TarOne = filename:join(Dir, "archive1.tar"), + {ok,AD} = erl_tar:open(TarOne, [write]), + ok = erl_tar:add(AD, FileOne, []), + ok = erl_tar:add(AD, FileTwo, "second file", []), + ok = erl_tar:add(AD, FileThree, [verbose]), + ok = erl_tar:add(AD, FileThree, "chunked", [{chunks,11411},verbose]), + ok = erl_tar:add(AD, ADir, [verbose]), + ok = erl_tar:add(AD, AnotherDir, [verbose]), + ok = erl_tar:close(AD), + + ok = erl_tar:t(TarOne), + ok = erl_tar:tt(TarOne), + + {ok,[FileOne,"second file",FileThree,"chunked",ADir,SomeContent]} = erl_tar:table(TarOne), + + delete_files(["oac_file","oac_small","oac_big",Dir,AnotherDir,ADir]), ok. @@ -678,60 +668,59 @@ oac_files() -> cooked_compressed(Config) when is_list(Config) -> %% Test that a compressed archive can be read in cooked mode. - ?line DataDir = ?config(data_dir, Config), - ?line PrivDir = ?config(priv_dir, Config), - ?line Name = filename:join(DataDir, "cooked_tar_problem.tar.gz"), + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), + Name = filename:join(DataDir, "cooked_tar_problem.tar.gz"), %% Try table/2 and extract/2. - ?line {ok,List} = erl_tar:table(Name, [cooked,compressed]), - ?line io:format("~p\n", [List]), - ?line 19 = length(List), - ?line ok = erl_tar:extract(Name, [cooked,compressed,{cwd,PrivDir}]), + {ok,List} = erl_tar:table(Name, [cooked,compressed]), + io:format("~p\n", [List]), + 19 = length(List), + ok = erl_tar:extract(Name, [cooked,compressed,{cwd,PrivDir}]), %% Clean up while at the same time testing that all file %% were extracted as expected. lists:foreach(fun(N) -> File = filename:join(PrivDir, N), io:format("Deleting: ~p\n", [File]), - ?line ok = file:delete(File) + ok = file:delete(File) end, List), %% Clean up. - ?line delete_files([filename:join(PrivDir, "ddll_SUITE_data")]), + delete_files([filename:join(PrivDir, "ddll_SUITE_data")]), ok. -memory(doc) -> - ["Test that an archive can be created directly from binaries and " - "that an archive can be extracted into binaries."]; +%% Test that an archive can be created directly from binaries and +%% that an archive can be extracted into binaries. memory(Config) when is_list(Config) -> - ?line DataDir = ?config(data_dir, Config), - - ?line FileBins = [{"bar/fum", <<"BARFUM">>},{"foo", <<"FOO">>}], - ?line Name1 = filename:join(DataDir, "memory.tar"), - ?line ok = erl_tar:create(Name1, FileBins, [write,verbose]), - ?line {ok,Extracted1} = erl_tar:extract(Name1, [memory,verbose]), - ?line FileBins1 = lists:sort(Extracted1), - - ?line io:format("FileBins: ~p\n", [FileBins]), - ?line io:format("FileBins1: ~p\n", [FileBins1]), - ?line FileBins = FileBins1, - - ?line Name2 = filename:join(DataDir, "memory2.tar"), - ?line {ok,Fd} = erl_tar:open(Name2, [write]), - ?line [ok,ok] = [erl_tar:add(Fd, B, N, [write,verbose]) || {N,B} <- FileBins], - ?line ok = erl_tar:close(Fd), - ?line {ok,Extracted2} = erl_tar:extract(Name2, [memory,verbose]), - ?line FileBins2 = lists:sort(Extracted2), - ?line io:format("FileBins2: ~p\n", [FileBins2]), - ?line FileBins = FileBins2, + DataDir = proplists:get_value(data_dir, Config), + + FileBins = [{"bar/fum", <<"BARFUM">>},{"foo", <<"FOO">>}], + Name1 = filename:join(DataDir, "memory.tar"), + ok = erl_tar:create(Name1, FileBins, [write,verbose]), + {ok,Extracted1} = erl_tar:extract(Name1, [memory,verbose]), + FileBins1 = lists:sort(Extracted1), + + io:format("FileBins: ~p\n", [FileBins]), + io:format("FileBins1: ~p\n", [FileBins1]), + FileBins = FileBins1, + + Name2 = filename:join(DataDir, "memory2.tar"), + {ok,Fd} = erl_tar:open(Name2, [write]), + [ok,ok] = [erl_tar:add(Fd, B, N, [write,verbose]) || {N,B} <- FileBins], + ok = erl_tar:close(Fd), + {ok,Extracted2} = erl_tar:extract(Name2, [memory,verbose]), + FileBins2 = lists:sort(Extracted2), + io:format("FileBins2: ~p\n", [FileBins2]), + FileBins = FileBins2, %% Clean up. - ?line ok = delete_files([Name1,Name2]), + ok = delete_files([Name1,Name2]), ok. %% Test filenames with characters outside the US ASCII range. unicode(Config) when is_list(Config) -> - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), do_unicode(PrivDir), case has_transparent_naming() of true -> @@ -811,7 +800,7 @@ delete_files([Item|Rest]) -> %% 260 characters. run_in_short_tempdir(Config, Fun) -> {ok,Cwd} = file:get_cwd(), - PrivDir0 = ?config(priv_dir, Config), + PrivDir0 = proplists:get_value(priv_dir, Config), %% Normalize name to make sure that there is no slash at the end. PrivDir = filename:absname(PrivDir0), @@ -850,7 +839,7 @@ start_node(Name, Args) -> ct:log("Trying to start ~w@~s~n", [Name,Host]), case test_server:start_node(Name, peer, [{args,Args}]) of {error,Reason} -> - test_server:fail(Reason); + ct:fail(Reason); {ok,Node} -> ct:log("Node ~p started~n", [Node]), Node diff --git a/lib/stdlib/test/timer_SUITE.erl b/lib/stdlib/test/timer_SUITE.erl index e4d656c9bf..d4bbd39d50 100644 --- a/lib/stdlib/test/timer_SUITE.erl +++ b/lib/stdlib/test/timer_SUITE.erl @@ -41,7 +41,9 @@ %% reasonable on different machines; therefore the test can sometimes %% fail, even though the timer module is ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,20}}]. all() -> [do_big_test]. @@ -65,15 +67,13 @@ end_per_group(_GroupName, Config) -> %% ------------------------------------------------------- %% do_big_test(TConfig) when is_list(TConfig) -> - Dog = ?t:timetrap(?t:minutes(20)), Save = process_flag(trap_exit, true), Result = big_test(200), process_flag(trap_exit, Save), - ?t:timetrap_cancel(Dog), report_result(Result). report_result(ok) -> ok; -report_result(Error) -> ?line test_server:fail(Error). +report_result(Error) -> ct:fail(Error). %% ------------------------------------------------------- %% @@ -98,7 +98,7 @@ big_test(N) -> Result = analyze_report(Report), %%io:format("big_test is done: ~w~n", [Result]), Result. - + big_loop(_C, 0, []) -> %%io:format("All processes are done!~n", []), ok; @@ -109,8 +109,8 @@ big_loop(C, 0, Pids) -> {'EXIT', Pid, done} -> big_loop(C, 0, lists:delete(Pid, Pids)); {'EXIT', Pid, Error} -> - ?line ok = io:format("XXX Pid ~w died with reason ~p~n", - [Pid, Error]), + ok = io:format("XXX Pid ~w died with reason ~p~n", + [Pid, Error]), big_loop(C, 0, lists:delete(Pid, Pids)) end; big_loop(C, N, Pids) -> @@ -119,14 +119,14 @@ big_loop(C, N, Pids) -> {'EXIT', Pid, done} -> big_loop(C, N, lists:delete(Pid, Pids)); {'EXIT', Pid, Error} -> - ?line ok =io:format("XXX Internal error: Pid ~w died, reason ~p~n", - [Pid, Error]), + ok =io:format("XXX Internal error: Pid ~w died, reason ~p~n", + [Pid, Error]), big_loop(C, N, lists:delete(Pid, Pids)) after 0 -> %% maybe start an interval timer test Pids1 = maybe_start_i_test(Pids, C, rand:uniform(4)), - + %% start 1-4 "after" tests Pids2 = start_after_test(Pids1, C, rand:uniform(4)), %%Pids2=Pids1, @@ -136,7 +136,7 @@ big_loop(C, N, Pids) -> %% spawn zero, one or two nrev to get some load ;-/ Pids3 = start_nrev(Pids2, rand:uniform(100)), - + big_loop(C, N-1, Pids3) end. @@ -149,7 +149,7 @@ start_nrev(Pids, _N) -> NrevPid1 = spawn_link(timer_SUITE, do_nrev, [rand:uniform(1000)*10]), NrevPid2 = spawn_link(timer_SUITE, do_nrev, [1]), [NrevPid1,NrevPid2|Pids]. - + start_after_test(Pids, C, 1) -> TO1 = rand:uniform(100)*47, @@ -177,8 +177,8 @@ a_t(C, TimeOut) -> watchdog -> Stop = system_time(), report(C, Start,Stop,TimeOut), - ?line ok = io:format("Internal watchdog timeout (a), not good!!~n", - []), + ok = io:format("Internal watchdog timeout (a), not good!!~n", + []), exit(done) end. @@ -208,8 +208,8 @@ i_wait(Start, Prev, Times, TimeOut, Times, Ref, C) -> Now = system_time(), report_interval(C, {final,Times}, Start, Prev, Now, TimeOut), timer:cancel(Ref), - ?line ok = io:format("Internal watchdog timeout (i), not good!!~n", - []), + ok = io:format("Internal watchdog timeout (i), not good!!~n", + []), exit(done) end; i_wait(Start, Prev, Count, TimeOut, Times, Ref, C) -> @@ -221,8 +221,8 @@ i_wait(Start, Prev, Count, TimeOut, Times, Ref, C) -> watchdog -> Now = system_time(), report_interval(C, {final,Count}, Start, Prev, Now, TimeOut), - ?line ok = io:format("Internal watchdog timeout (j), not good!!~n", - []), + ok = io:format("Internal watchdog timeout (j), not good!!~n", + []), exit(done) end. @@ -289,13 +289,6 @@ update(New, Stat) when New < Stat#stat.min -> update(New, Stat) -> Stat#stat{n=Stat#stat.n + 1, avg=(New+Stat#stat.avg) div 2}. -%update(New, {N,Max,Min,Avg}) when New>Max -> -% {N+1,New,Min,(New+Avg) div 2}; -%update(New, {N,Max,Min,Avg}) when New<Min -> -% {N+1,Max,New,(New+Avg) div 2}; -%update(New, {N,Max,Min,Avg}) -> -% {N+1,Max,Min,(New+Avg) div 2}. - print_report({E,LateS,EarlyS,I}) -> Early = EarlyS#stat.n, Late = LateS#stat.n, Total = E + Early + Late, @@ -379,10 +372,10 @@ nrev([]) -> []; nrev([H|T]) -> append(nrev(T), [H]). - + append([H|T],Z) -> - [H|append(T,Z)]; + [H|append(T,Z)]; append([],X) -> - X. + X. %% ------------------------------------------------------- %% diff --git a/lib/stdlib/test/timer_simple_SUITE.erl b/lib/stdlib/test/timer_simple_SUITE.erl index 42b96c4b1c..64fce2a4b2 100644 --- a/lib/stdlib/test/timer_simple_SUITE.erl +++ b/lib/stdlib/test/timer_simple_SUITE.erl @@ -56,7 +56,9 @@ -define(MAXREF, (1 bsl 18)). -define(REFMARG, 30). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,10}}]. all() -> [apply_after, send_after1, send_after2, send_after3, @@ -87,222 +89,198 @@ init_per_testcase(_, Config) when is_list(Config) -> %% Testing timer interface!! -apply_after(doc) -> "Test of apply_after, with sending of message."; -apply_after(suite) -> []; +%% Test of apply_after, with sending of message. apply_after(Config) when is_list(Config) -> - ?line timer:apply_after(500, ?MODULE, send, [self(), ok_apply]), - ?line ok = get_mess(1000, ok_apply). + timer:apply_after(500, ?MODULE, send, [self(), ok_apply]), + ok = get_mess(1000, ok_apply). -send_after1(doc) -> "Test of send_after with time = 0."; -send_after1(suite) -> []; +%% Test of send_after with time = 0. send_after1(Config) when is_list(Config) -> - ?line timer:send_after(0, ok_send1), - ?line ok = get_mess(1000, ok_send1). + timer:send_after(0, ok_send1), + ok = get_mess(1000, ok_send1). -send_after2(doc) -> "Test of send_after with time = 500."; -send_after2(suite) -> []; +%% Test of send_after with time = 500. send_after2(Config) when is_list(Config) -> - ?line timer:send_after(500, self(), ok_send2), - ?line ok = get_mess(2000, ok_send2). + timer:send_after(500, self(), ok_send2), + ok = get_mess(2000, ok_send2). -send_after3(doc) -> "Test of send_after with time = 500, with receiver " - "a registered process. [OTP-2735]"; -send_after3(suite) -> []; +%% Test of send_after with time = 500, with receiver a registered +%% process. [OTP-2735] send_after3(Config) when is_list(Config) -> - ?line Name = list_to_atom(pid_to_list(self())), - ?line register(Name, self()), - ?line timer:send_after(500, Name, ok_send3), - ?line ok = get_mess(2000, ok_send3), - ?line unregister(Name). - -exit_after1(doc) -> "Test of exit_after with time = 1000."; -exit_after1(suite) -> []; + Name = list_to_atom(pid_to_list(self())), + register(Name, self()), + timer:send_after(500, Name, ok_send3), + ok = get_mess(2000, ok_send3), + unregister(Name). + +%% Test of exit_after with time = 1000. exit_after1(Config) when is_list(Config) -> - ?line process_flag(trap_exit, true), - ?line Pid = spawn_link(?MODULE, forever, []), - ?line timer:exit_after(1000, Pid, exit_test1), - ?line ok = get_mess(5000, {'EXIT', Pid, exit_test1}). - -exit_after2(doc) -> "Test of exit_after with time = 1000. The process to " - "exit is the name of a registered process. " - "[OTP-2735]"; -exit_after2(suite) -> []; + process_flag(trap_exit, true), + Pid = spawn_link(?MODULE, forever, []), + timer:exit_after(1000, Pid, exit_test1), + ok = get_mess(5000, {'EXIT', Pid, exit_test1}). + +%% Test of exit_after with time = 1000. The process to exit is the +%% name of a registered process. [OTP-2735] exit_after2(Config) when is_list(Config) -> - ?line process_flag(trap_exit, true), - ?line Pid = spawn_link(?MODULE, forever, []), - ?line Name = list_to_atom(pid_to_list(Pid)), - ?line register(Name, Pid), - ?line timer:exit_after(1000, Name, exit_test2), - ?line ok = get_mess(2000, {'EXIT', Pid, exit_test2}). - -kill_after1(doc) -> "Test of kill_after with time = 1000."; -kill_after1(suite) -> []; + process_flag(trap_exit, true), + Pid = spawn_link(?MODULE, forever, []), + Name = list_to_atom(pid_to_list(Pid)), + register(Name, Pid), + timer:exit_after(1000, Name, exit_test2), + ok = get_mess(2000, {'EXIT', Pid, exit_test2}). + +%% Test of kill_after with time = 1000. kill_after1(Config) when is_list(Config) -> - ?line process_flag(trap_exit, true), - ?line Pid = spawn_link(?MODULE, forever, []), - ?line timer:kill_after(1000, Pid), - ?line ok = get_mess(2000, {'EXIT', Pid, killed}). - -kill_after2(doc) -> "Test of kill_after with time = 1000. The process to " - "exit is the name of a registered process. " - "[OTP-2735]"; -kill_after2(suite) -> []; + process_flag(trap_exit, true), + Pid = spawn_link(?MODULE, forever, []), + timer:kill_after(1000, Pid), + ok = get_mess(2000, {'EXIT', Pid, killed}). + +%% Test of kill_after with time = 1000. The process to exit is the +%% name of a registered process. [OTP-2735] kill_after2(Config) when is_list(Config) -> - ?line process_flag(trap_exit, true), - ?line Pid = spawn_link(?MODULE, forever, []), - ?line Name = list_to_atom(pid_to_list(Pid)), - ?line register(Name, Pid), - ?line timer:kill_after(1000, Name), - ?line ok = get_mess(2000, {'EXIT', Pid, killed}). - -apply_interval(doc) -> "Test of apply_interval by sending messages. Receive " - "3 messages, cancel the timer, and check that we do " - "not get any more messages."; -apply_interval(suite) -> []; + process_flag(trap_exit, true), + Pid = spawn_link(?MODULE, forever, []), + Name = list_to_atom(pid_to_list(Pid)), + register(Name, Pid), + timer:kill_after(1000, Name), + ok = get_mess(2000, {'EXIT', Pid, killed}). + +%% Test of apply_interval by sending messages. Receive +%% 3 messages, cancel the timer, and check that we do +%% not get any more messages. apply_interval(Config) when is_list(Config) -> - ?line {ok, Ref} = timer:apply_interval(1000, ?MODULE, send, + {ok, Ref} = timer:apply_interval(1000, ?MODULE, send, [self(), apply_int]), - ?line ok = get_mess(1500, apply_int, 3), - ?line timer:cancel(Ref), - ?line nor = get_mess(1000, apply_int). - -send_interval1(doc) -> "Test of send_interval/2. Receive 5 messages, cancel " - "the timer, and check that we do not get any more " - "messages."; -send_interval1(suite) -> []; + ok = get_mess(1500, apply_int, 3), + timer:cancel(Ref), + nor = get_mess(1000, apply_int). + +%% Test of send_interval/2. Receive 5 messages, cancel the timer, and +%% check that we do not get any more messages. send_interval1(Config) when is_list(Config) -> {ok, Ref} = timer:send_interval(1000, send_int), - ?line ok = get_mess(1500, send_int, 5), + ok = get_mess(1500, send_int, 5), timer:cancel(Ref), - ?line nor = get_mess(1000, send_int). % We should receive only five + nor = get_mess(1000, send_int). % We should receive only five -send_interval2(doc) -> "Test of send_interval/3. Receive 2 messages, cancel " - "the timer, and check that we do not get any more " - "messages."; -send_interval2(suite) -> []; +%% Test of send_interval/3. Receive 2 messages, cancel the timer, and +%% check that we do not get any more messages. send_interval2(Config) when is_list(Config) -> {ok, Ref} = timer:send_interval(1000, self(), send_int2), - ?line ok = get_mess(1500, send_int2, 2), + ok = get_mess(1500, send_int2, 2), timer:cancel(Ref), - ?line nor = get_mess(1000, send_int2). % We should receive only two + nor = get_mess(1000, send_int2). % We should receive only two -send_interval3(doc) -> "Test of send_interval/3. Receive 2 messages, cancel " - "the timer, and check that we do not get any more " - "messages. The receiver is the name of a registered " - "process. [OTP-2735]"; -send_interval3(suite) -> []; +%% Test of send_interval/3. Receive 2 messages, cancel the timer, and +%% check that we do not get any more messages. The receiver is the +%% name of a registered process. [OTP-2735] send_interval3(Config) when is_list(Config) -> - ?line process_flag(trap_exit, true), - ?line Name = list_to_atom(pid_to_list(self())), - ?line register(Name, self()), - ?line {ok, Ref} = timer:send_interval(1000, Name, send_int3), - ?line ok = get_mess(1500, send_int3, 2), + process_flag(trap_exit, true), + Name = list_to_atom(pid_to_list(self())), + register(Name, self()), + {ok, Ref} = timer:send_interval(1000, Name, send_int3), + ok = get_mess(1500, send_int3, 2), timer:cancel(Ref), - ?line nor = get_mess(1000, send_int3), % We should receive only two - ?line unregister(Name). + nor = get_mess(1000, send_int3), % We should receive only two + unregister(Name). -send_interval4(doc) -> "Test that send interval stops sending msg when the " - "receiving process terminates."; -send_interval4(suite) -> []; +%% Test that send interval stops sending msg when the receiving +%% process terminates. send_interval4(Config) when is_list(Config) -> - ?line timer:send_interval(500, one_time_only), + timer:send_interval(500, one_time_only), receive one_time_only -> ok end, - ?line timer_server ! {'EXIT', self(), normal}, % Should remove the timer - ?line timer:send_after(600, send_intv_ok), - ?line send_intv_ok = receive - Msg -> Msg - end. - -cancel1(doc) -> "Test that we can cancel a timer."; -cancel1(suite) -> []; + timer_server ! {'EXIT', self(), normal}, % Should remove the timer + timer:send_after(600, send_intv_ok), + send_intv_ok = receive + Msg -> Msg + end. + +%% Test that we can cancel a timer. cancel1(Config) when is_list(Config) -> - ?line {ok, Ref} = timer:send_after(1000, this_should_be_canceled), - ?line timer:cancel(Ref), - ?line nor = get_mess(2000, this_should_be_canceled). % We should rec 0 msgs + {ok, Ref} = timer:send_after(1000, this_should_be_canceled), + timer:cancel(Ref), + nor = get_mess(2000, this_should_be_canceled). % We should rec 0 msgs -cancel2(doc) -> "Test cancel/1 with bad argument."; -cancel2(suite) -> []; +%% Test cancel/1 with bad argument. cancel2(Config) when is_list(Config) -> - ?line {error, badarg} = timer:cancel(no_reference). + {error, badarg} = timer:cancel(no_reference). -tc(doc) -> "Test sleep/1 and tc/3."; -tc(suite) -> []; +%% Test sleep/1 and tc/3. tc(Config) when is_list(Config) -> %% This should test both sleep and tc/3 - ?line {Res1, ok} = timer:tc(timer, sleep, [500]), - ?line ok = if + {Res1, ok} = timer:tc(timer, sleep, [500]), + ok = if Res1 < 500*1000 -> {too_early, Res1}; % Too early Res1 > 800*1000 -> {too_late, Res1}; % Too much time true -> ok end, %% tc/2 - ?line {Res2, ok} = timer:tc(fun(T) -> timer:sleep(T) end, [500]), - ?line ok = if + {Res2, ok} = timer:tc(fun(T) -> timer:sleep(T) end, [500]), + ok = if Res2 < 500*1000 -> {too_early, Res2}; % Too early Res2 > 800*1000 -> {too_late, Res2}; % Too much time true -> ok end, - + %% tc/1 - ?line {Res3, ok} = timer:tc(fun() -> timer:sleep(500) end), - ?line ok = if + {Res3, ok} = timer:tc(fun() -> timer:sleep(500) end), + ok = if Res3 < 500*1000 -> {too_early, Res3}; % Too early Res3 > 800*1000 -> {too_late, Res3}; % Too much time true -> ok end, %% Check that timer:tc don't catch errors - ?line ok = try timer:tc(erlang, exit, [foo]) - catch exit:foo -> ok - end, - - ?line ok = try timer:tc(fun(Reason) -> 1 = Reason end, [foo]) - catch error:{badmatch,_} -> ok - end, - - ?line ok = try timer:tc(fun() -> throw(foo) end) - catch foo -> ok - end, - + ok = try timer:tc(erlang, exit, [foo]) + catch exit:foo -> ok + end, + + ok = try timer:tc(fun(Reason) -> 1 = Reason end, [foo]) + catch error:{badmatch,_} -> ok + end, + + ok = try timer:tc(fun() -> throw(foo) end) + catch foo -> ok + end, + %% Check that return values are propageted Self = self(), - ?line {_, Self} = timer:tc(erlang, self, []), - ?line {_, Self} = timer:tc(fun(P) -> P end, [self()]), - ?line {_, Self} = timer:tc(fun() -> self() end), - - ?line Sec = timer:seconds(4), - ?line Min = timer:minutes(4), - ?line Hour = timer:hours(4), - ?line MyRes = 4*1000 + 4*60*1000 + 4*60*60*1000, - ?line if MyRes == Sec + Min + Hour -> ok end, - ?line TimerRes = timer:hms(4,4,4), - ?line if MyRes == TimerRes -> ok end, + {_, Self} = timer:tc(erlang, self, []), + {_, Self} = timer:tc(fun(P) -> P end, [self()]), + {_, Self} = timer:tc(fun() -> self() end), + + Sec = timer:seconds(4), + Min = timer:minutes(4), + Hour = timer:hours(4), + MyRes = 4*1000 + 4*60*1000 + 4*60*60*1000, + if MyRes == Sec + Min + Hour -> ok end, + TimerRes = timer:hms(4,4,4), + if MyRes == TimerRes -> ok end, ok. -unique_refs(doc) -> - "Tests that cancellations of one-shot timers do not accidentally " - "cancel interval timers [OTP-2771]."; -unique_refs(suite) -> - []; +%% Test that cancellations of one-shot timers do not accidentally +%% cancel interval timers. [OTP-2771]. unique_refs(Config) when is_list(Config) -> - ?line ITimers = repeat_send_interval(10), % 10 interval timers - ?line eat_refs(?MAXREF - ?REFMARG), - ?line set_and_cancel_one_shots(?REFMARG), - ?line NumLeft = num_timers(), - ?line io:format("~w timers left, should be 10\n", [NumLeft]), - ?line cancel(ITimers), - ?line receive_nisse(), - ?line 10 = NumLeft. + ITimers = repeat_send_interval(10), % 10 interval timers + eat_refs(?MAXREF - ?REFMARG), + set_and_cancel_one_shots(?REFMARG), + NumLeft = num_timers(), + io:format("~w timers left, should be 10\n", [NumLeft]), + cancel(ITimers), + receive_nisse(), + 10 = NumLeft. repeat_send_interval(0) -> []; repeat_send_interval(M) -> - ?line {ok, Ref} = timer:send_interval(6000,self(), nisse), - ?line [Ref| repeat_send_interval(M - 1)]. + {ok, Ref} = timer:send_interval(6000,self(), nisse), + [Ref| repeat_send_interval(M - 1)]. eat_refs(0) -> 0; @@ -320,8 +298,8 @@ set_and_cancel_one_shots(N) -> set_and_cancel_one_shots(N-1). cancel([T| Ts]) -> - ?line timer:cancel(T), - ?line cancel(Ts); + timer:cancel(T), + cancel(Ts); cancel([]) -> ok. @@ -344,7 +322,7 @@ get_mess(Time, Mess, N) -> receive Mess -> get_mess(Time, Mess, N-1) after Time - -> nor % Not Received + -> nor % Not Received end. forever() -> @@ -352,16 +330,13 @@ forever() -> forever(). -% -% Testing for performance (on different implementations) of timers -% +%% +%% Testing for performance (on different implementations) of timers +%% + -timer_perf(suite) -> []; timer_perf(Config) when is_list(Config) -> - Dog = ?t:timetrap(?t:minutes(10)), - Res = performance(timer), - ?t:timetrap_cancel(Dog), - Res. + performance(timer). performance(Mod) -> process_flag(trap_exit, true), @@ -374,7 +349,7 @@ performance(Mod) -> big_test(M) -> Load_Pids = start_nrev(20, M), % Increase if more load wanted :) - + LPids = spawn_timers(5, M, 10000, 5), apply(M, sleep, [4000]), @@ -384,7 +359,7 @@ big_test(M) -> SPids = spawn_timers(15, M, 100, 3), Res = wait(SPids ++ MPids ++ LPids, [], 0, M), - + lists:foreach(fun(Pid) -> exit(Pid, kill) end, Load_Pids), Res. @@ -395,12 +370,12 @@ wait(Pids, ResList, N, M) -> {Pid, ok, Res, T} -> wait(lists:delete(Pid, Pids), [{T, Res} | ResList], N, M); {Pid, Error}-> - ?line test_server:fail(Error), + ct:fail(Error), wait(lists:delete(Pid, Pids), ResList, N+1, M); {'EXIT', Pid, normal} -> wait(lists:delete(Pid, Pids), ResList, N, M); {'EXIT', Pid, Reason} -> - ?line test_server:fail({Pid,Reason}) + ct:fail({Pid,Reason}) end. spawn_timers(0, _, _, _) -> @@ -440,7 +415,6 @@ timer_irec(Start, T, {N, Max}, Res, {Pid, Mod, Ref}) -> done -> Now = system_time(), Elapsed = (Now - (Start + (N*T*1000))) div 1000, -% io:format("~w Now ~w Started ~w Elap ~w~n", [T,Now,Start,Elapsed]), timer_irec(Start, T, {N+1, Max}, [Elapsed | Res], @@ -476,11 +450,11 @@ nrev([]) -> []; nrev([H|T]) -> append(nrev(T), [H]). - + append([H|T],Z) -> - [H|append(T,Z)]; + [H|append(T,Z)]; append([],X) -> - X. + X. system_time() -> erlang:monotonic_time(micro_seconds). @@ -488,7 +462,6 @@ system_time() -> %% ------------------------------------------------------- %% report_result({Res, 0}) -> -% io:format("DEBUG0 all ~p ~n", [Res]), {A_List, I_List} = split_list(Res, [], []), A_val = calc_a_val(A_List), I_val = calc_i_val(I_List), @@ -497,7 +470,7 @@ report_result({Res, 0}) -> report_result({Head, N}) -> io:format("Test Failed: Number of internal tmo ~w~n", [N]), - ?line test_server:fail({Head, N}). + ct:fail({Head, N}). split_list([], AL, IL) -> {AL, IL}; @@ -547,11 +520,11 @@ get_ivals(List) -> LTot = lists:map(fun(X) -> element(2, X) end, List), LMin = lists:map(fun(X) -> element(4, X) end, List), LMax = lists:map(fun(X) -> element(5, X) end, List), - + MaxTot = lists:max(LTot), MinTot = lists:min(LTot), AverTot = lists:sum(LTot) div Len, - + IterMax = lists:max(LMax), IterMin = lists:min(LMin), IterAver= AverTot div Num, diff --git a/lib/stdlib/test/unicode_SUITE.erl b/lib/stdlib/test/unicode_SUITE.erl index f45e00928e..d2ee5d19a4 100644 --- a/lib/stdlib/test/unicode_SUITE.erl +++ b/lib/stdlib/test/unicode_SUITE.erl @@ -37,16 +37,16 @@ ex_binaries_errors_utf16_big/1, ex_binaries_errors_utf32_little/1, ex_binaries_errors_utf32_big/1]). - -init_per_testcase(Case, Config) when is_atom(Case), is_list(Config) -> - Dog=?t:timetrap(?t:minutes(20)), - [{watchdog, Dog}|Config]. -end_per_testcase(_Case, Config) -> - Dog = ?config(watchdog, Config), - ?t:timetrap_cancel(Dog). +init_per_testcase(_Case, Config) -> + Config. + +end_per_testcase(_Case, _Config) -> + ok. -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{minutes,20}}]. all() -> [utf8_illegal_sequences_bif, @@ -80,7 +80,7 @@ binaries_errors_limit(Config) when is_list(Config) -> ex_binaries_errors_utf8(Config), setlimit(default), ok. - + ex_binaries_errors_utf8(Config) when is_list(Config) -> %% Original smoke test, we should not forget the original offset... <<_:8,_:8,RR2/binary>> = <<$a,$b,164,165,$c>>, @@ -151,10 +151,10 @@ utf16_inner_loop([_|List], BrokenPart, BrokenSz, PartlyBroken, PBSz, Endian) -> utf16_inner_loop(List, BrokenPart, BrokenSz, PartlyBroken, PBSz, Endian); utf16_inner_loop([], _, _, _, _, _) -> ok. - + ex_binaries_errors_utf32_big(Config) when is_list(Config) -> ex_binaries_errors_utf32(big). - + ex_binaries_errors_utf32_little(Config) when is_list(Config) -> ex_binaries_errors_utf32(little). @@ -180,7 +180,7 @@ ex_binaries_errors_utf32(Endian) -> PartlyBroken, PBSz, Endian) end || N <- lists:seq(1, 16, 3) ], ok. - + utf32_inner_loop([_|List], BrokenPart, BrokenSz, PartlyBroken, PBSz, Endian) -> Sz = length(List)*4 + BrokenSz, Chomped = binary:part(PartlyBroken, PBSz - Sz, Sz), @@ -199,115 +199,115 @@ exceptions(Config) when is_list(Config) -> ex_exceptions(Config). ex_exceptions(Config) when is_list(Config) -> - ?line L = lists:seq(0,255), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L++255,unicode)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary({1,2,3},unicode)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1,unicode)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1.0,unicode)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary('1',unicode)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,apa],unicode)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,4.0],unicode)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L++255,latin1)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary({1,2,3},latin1)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1,latin1)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1.0,latin1)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary('1',latin1)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,apa],latin1)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,4.0],latin1)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,gnarfl)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,L)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,{latin1})), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,[latin1])), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,1)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,1.0)), + L = lists:seq(0,255), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L++255,unicode)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary({1,2,3},unicode)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1,unicode)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1.0,unicode)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary('1',unicode)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,apa],unicode)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,4.0],unicode)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L++255,latin1)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary({1,2,3},latin1)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1,latin1)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1.0,latin1)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary('1',latin1)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,apa],latin1)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,4.0],latin1)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,gnarfl)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,L)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,{latin1})), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,[latin1])), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,1)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,1.0)), Encodings = [unicode, utf8,utf16,utf32,{utf16,big}, {utf16,little},{utf32,big},{utf32,little}], [ begin - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L++255,unicode,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary({1,2,3},unicode,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1,unicode,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1.0,unicode,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary('1',unicode,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,apa],unicode, - Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,4.0],unicode, - Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L++255,latin1,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary({1,2,3},latin1,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1,latin1,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1.0,latin1,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary('1',latin1,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,apa],latin1, - Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,4.0],latin1, - Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,gnarfl,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,L,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,{latin1},Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,[latin1],Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,1,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,1.0,Enc)) + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L++255,unicode,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary({1,2,3},unicode,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1,unicode,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1.0,unicode,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary('1',unicode,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,apa],unicode, + Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,4.0],unicode, + Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L++255,latin1,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary({1,2,3},latin1,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1,latin1,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(1.0,latin1,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary('1',latin1,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,apa],latin1, + Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary([1,2,3,4.0],latin1, + Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,gnarfl,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,L,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,{latin1},Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,[latin1],Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,1,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_binary(L,1.0,Enc)) end || Enc <- Encodings ], Encodings2 = [latin1, unicode, utf8,utf16,utf32,{utf16,big}, - {utf16,little},{utf32,big},{utf32,little}], + {utf16,little},{utf32,big},{utf32,little}], [ begin - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L++255,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list({1,2,3},Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(1,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(1.0,Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list('1',Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list([1,2,3,apa],Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list([1,2,3,4.0],Enc)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,{Enc})), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,[Enc])) + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L++255,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list({1,2,3},Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(1,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(1.0,Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list('1',Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list([1,2,3,apa],Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list([1,2,3,4.0],Enc)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,{Enc})), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,[Enc])) end || Enc <- Encodings2 ], - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,gnarfl)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,L)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,1)), - ?line {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,1.0)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,gnarfl)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,L)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,1)), + {'EXIT',{badarg,_}} = (catch unicode:characters_to_list(L,1.0)), [ begin - ?line Bx = unicode:characters_to_binary(L,latin1, Enc), - ?line L = unicode:characters_to_list(Bx,Enc) + Bx = unicode:characters_to_binary(L,latin1, Enc), + L = unicode:characters_to_list(Bx,Enc) end || Enc <- Encodings ], - ?line B = unicode:characters_to_binary(L,latin1), - ?line L = unicode:characters_to_list(B,unicode), - ?line L = unicode:characters_to_list(list_to_binary(L),latin1), - ?line More = <<B/binary,0,1,2>>, - ?line B2 = list_to_binary([254,255]), - ?line B3 = list_to_binary([0,1,2,254,255]), - ?line {error,B,Rest1} = unicode:characters_to_binary([L,B2],unicode), - ?line B2 = iolist_to_binary(Rest1), - ?line {error,More,Rest2} = unicode:characters_to_binary([L,B3],unicode), - [ begin ?line {error,_,_} = unicode:characters_to_binary([L,B2],unicode,Enc) end + B = unicode:characters_to_binary(L,latin1), + L = unicode:characters_to_list(B,unicode), + L = unicode:characters_to_list(list_to_binary(L),latin1), + More = <<B/binary,0,1,2>>, + B2 = list_to_binary([254,255]), + B3 = list_to_binary([0,1,2,254,255]), + {error,B,Rest1} = unicode:characters_to_binary([L,B2],unicode), + B2 = iolist_to_binary(Rest1), + {error,More,Rest2} = unicode:characters_to_binary([L,B3],unicode), + [ begin {error,_,_} = unicode:characters_to_binary([L,B2],unicode,Enc) end || Enc <- Encodings ], - ?line Valid0 = unicode:characters_to_binary([L,254,255],unicode), - ?line Valid1 = unicode:characters_to_binary([L,254,255],latin1), - ?line Valid2 = unicode:characters_to_binary([L,254,255,256,257],unicode), - ?line Valid3 = unicode:characters_to_binary([L,B2],latin1), - ?line true = is_binary(Valid0), - ?line true = is_binary(Valid1), - ?line true = is_binary(Valid2), - ?line true = is_binary(Valid3), - ?line Valid4 = unicode:characters_to_binary([L,B3],latin1), - ?line true = is_binary(Valid4), - ?line B2 = iolist_to_binary(Rest2), - ?line true = (L ++ [254,255] =:= unicode:characters_to_list(Valid0,unicode)), - ?line true = (L ++ [254,255,256,257] =:= unicode:characters_to_list(Valid2,unicode)), + Valid0 = unicode:characters_to_binary([L,254,255],unicode), + Valid1 = unicode:characters_to_binary([L,254,255],latin1), + Valid2 = unicode:characters_to_binary([L,254,255,256,257],unicode), + Valid3 = unicode:characters_to_binary([L,B2],latin1), + true = is_binary(Valid0), + true = is_binary(Valid1), + true = is_binary(Valid2), + true = is_binary(Valid3), + Valid4 = unicode:characters_to_binary([L,B3],latin1), + true = is_binary(Valid4), + B2 = iolist_to_binary(Rest2), + true = (L ++ [254,255] =:= unicode:characters_to_list(Valid0,unicode)), + true = (L ++ [254,255,256,257] =:= unicode:characters_to_list(Valid2,unicode)), lists:foreach(fun(Enco) -> - ?line Valid0x = unicode:characters_to_binary([L,254,255],unicode,Enco), - ?line Valid1x = unicode:characters_to_binary([L,254,255],latin1,Enco), - ?line Valid2x = unicode:characters_to_binary([L,254,255,256,257],unicode,Enco), - ?line Valid3x = unicode:characters_to_binary([L,B2],latin1,Enco), - ?line true = is_binary(Valid0x), - ?line true = is_binary(Valid1x), - ?line true = is_binary(Valid2x), - ?line true = is_binary(Valid3x) + Valid0x = unicode:characters_to_binary([L,254,255],unicode,Enco), + Valid1x = unicode:characters_to_binary([L,254,255],latin1,Enco), + Valid2x = unicode:characters_to_binary([L,254,255,256,257],unicode,Enco), + Valid3x = unicode:characters_to_binary([L,B2],latin1,Enco), + true = is_binary(Valid0x), + true = is_binary(Valid1x), + true = is_binary(Valid2x), + true = is_binary(Valid3x) end, Encodings), ok. - + latin1(Config) when is_list(Config) -> setlimit(10), @@ -316,132 +316,132 @@ latin1(Config) when is_list(Config) -> ex_latin1(Config). ex_latin1(Config) when is_list(Config) -> - ?line All = lists:seq(0,255), - ?line AllBin = list_to_binary(All), - ?line AllUtf8 = unicode:characters_to_binary(All,latin1), - ?line AllUtf8 = unicode:characters_to_binary(AllBin,latin1), - ?line AllUtf8 = unicode:characters_to_binary([AllBin],latin1), - ?line AllUtf8 = unicode:characters_to_binary(make_unaligned(AllBin),latin1), - ?line AllUtf8 = unicode:characters_to_binary([make_unaligned(AllBin)],latin1), - ?line AllUtf8 = list_to_utf8_bsyntax([AllBin],latin1), - ?line AllUtf8 = list_to_utf8_bsyntax([make_unaligned(AllBin)],latin1), - ?line AllUtf8 = unicode_mixed_to_utf8_1(All), - - ?line AllUtf16_Big = unicode:characters_to_binary(All,latin1,utf16), - ?line AllUtf16_Big = unicode:characters_to_binary(AllBin,latin1,utf16), - ?line AllUtf16_Big = unicode:characters_to_binary([AllBin],latin1,utf16), - ?line AllUtf16_Big = unicode:characters_to_binary(make_unaligned(AllBin),latin1,utf16), - ?line AllUtf16_Big = unicode:characters_to_binary([make_unaligned(AllBin)],latin1,utf16), - ?line AllUtf16_Big = list_to_utf16_big_bsyntax([AllBin],latin1), - ?line AllUtf16_Big = list_to_utf16_big_bsyntax([make_unaligned(AllBin)],latin1), - - ?line AllUtf16_Little = unicode:characters_to_binary(All,latin1,{utf16,little}), - ?line AllUtf16_Little = unicode:characters_to_binary(AllBin,latin1,{utf16,little}), - ?line AllUtf16_Little = unicode:characters_to_binary([AllBin],latin1,{utf16,little}), - ?line AllUtf16_Little = unicode:characters_to_binary(make_unaligned(AllBin),latin1, - {utf16,little}), - ?line AllUtf16_Little = unicode:characters_to_binary([make_unaligned(AllBin)],latin1, - {utf16,little}), - ?line AllUtf16_Little = list_to_utf16_little_bsyntax([AllBin],latin1), - ?line AllUtf16_Little = list_to_utf16_little_bsyntax([make_unaligned(AllBin)],latin1), - - ?line AllUtf32_Big = unicode:characters_to_binary(All,latin1,utf32), - ?line AllUtf32_Big = unicode:characters_to_binary(AllBin,latin1,utf32), - ?line AllUtf32_Big = unicode:characters_to_binary([AllBin],latin1,utf32), - ?line AllUtf32_Big = unicode:characters_to_binary(make_unaligned(AllBin),latin1,utf32), - ?line AllUtf32_Big = unicode:characters_to_binary([make_unaligned(AllBin)],latin1,utf32), - ?line AllUtf32_Big = list_to_utf32_big_bsyntax([AllBin],latin1), - ?line AllUtf32_Big = list_to_utf32_big_bsyntax([make_unaligned(AllBin)],latin1), - - ?line AllUtf32_Little = unicode:characters_to_binary(All,latin1,{utf32,little}), - ?line AllUtf32_Little = unicode:characters_to_binary(AllBin,latin1,{utf32,little}), - ?line AllUtf32_Little = unicode:characters_to_binary([AllBin],latin1,{utf32,little}), - ?line AllUtf32_Little = unicode:characters_to_binary(make_unaligned(AllBin),latin1, - {utf32,little}), - ?line AllUtf32_Little = unicode:characters_to_binary([make_unaligned(AllBin)],latin1, - {utf32,little}), - ?line AllUtf32_Little = list_to_utf32_little_bsyntax([AllBin],latin1), - ?line AllUtf32_Little = list_to_utf32_little_bsyntax([make_unaligned(AllBin)],latin1), - - ?line DoubleUtf8 = <<AllUtf8/binary,AllUtf8/binary>>, - ?line DoubleUtf8 = unicode:characters_to_binary([All,AllBin],latin1), - ?line DoubleUtf8 = + All = lists:seq(0,255), + AllBin = list_to_binary(All), + AllUtf8 = unicode:characters_to_binary(All,latin1), + AllUtf8 = unicode:characters_to_binary(AllBin,latin1), + AllUtf8 = unicode:characters_to_binary([AllBin],latin1), + AllUtf8 = unicode:characters_to_binary(make_unaligned(AllBin),latin1), + AllUtf8 = unicode:characters_to_binary([make_unaligned(AllBin)],latin1), + AllUtf8 = list_to_utf8_bsyntax([AllBin],latin1), + AllUtf8 = list_to_utf8_bsyntax([make_unaligned(AllBin)],latin1), + AllUtf8 = unicode_mixed_to_utf8_1(All), + + AllUtf16_Big = unicode:characters_to_binary(All,latin1,utf16), + AllUtf16_Big = unicode:characters_to_binary(AllBin,latin1,utf16), + AllUtf16_Big = unicode:characters_to_binary([AllBin],latin1,utf16), + AllUtf16_Big = unicode:characters_to_binary(make_unaligned(AllBin),latin1,utf16), + AllUtf16_Big = unicode:characters_to_binary([make_unaligned(AllBin)],latin1,utf16), + AllUtf16_Big = list_to_utf16_big_bsyntax([AllBin],latin1), + AllUtf16_Big = list_to_utf16_big_bsyntax([make_unaligned(AllBin)],latin1), + + AllUtf16_Little = unicode:characters_to_binary(All,latin1,{utf16,little}), + AllUtf16_Little = unicode:characters_to_binary(AllBin,latin1,{utf16,little}), + AllUtf16_Little = unicode:characters_to_binary([AllBin],latin1,{utf16,little}), + AllUtf16_Little = unicode:characters_to_binary(make_unaligned(AllBin),latin1, + {utf16,little}), + AllUtf16_Little = unicode:characters_to_binary([make_unaligned(AllBin)],latin1, + {utf16,little}), + AllUtf16_Little = list_to_utf16_little_bsyntax([AllBin],latin1), + AllUtf16_Little = list_to_utf16_little_bsyntax([make_unaligned(AllBin)],latin1), + + AllUtf32_Big = unicode:characters_to_binary(All,latin1,utf32), + AllUtf32_Big = unicode:characters_to_binary(AllBin,latin1,utf32), + AllUtf32_Big = unicode:characters_to_binary([AllBin],latin1,utf32), + AllUtf32_Big = unicode:characters_to_binary(make_unaligned(AllBin),latin1,utf32), + AllUtf32_Big = unicode:characters_to_binary([make_unaligned(AllBin)],latin1,utf32), + AllUtf32_Big = list_to_utf32_big_bsyntax([AllBin],latin1), + AllUtf32_Big = list_to_utf32_big_bsyntax([make_unaligned(AllBin)],latin1), + + AllUtf32_Little = unicode:characters_to_binary(All,latin1,{utf32,little}), + AllUtf32_Little = unicode:characters_to_binary(AllBin,latin1,{utf32,little}), + AllUtf32_Little = unicode:characters_to_binary([AllBin],latin1,{utf32,little}), + AllUtf32_Little = unicode:characters_to_binary(make_unaligned(AllBin),latin1, + {utf32,little}), + AllUtf32_Little = unicode:characters_to_binary([make_unaligned(AllBin)],latin1, + {utf32,little}), + AllUtf32_Little = list_to_utf32_little_bsyntax([AllBin],latin1), + AllUtf32_Little = list_to_utf32_little_bsyntax([make_unaligned(AllBin)],latin1), + + DoubleUtf8 = <<AllUtf8/binary,AllUtf8/binary>>, + DoubleUtf8 = unicode:characters_to_binary([All,AllBin],latin1), + DoubleUtf8 = unicode:characters_to_binary([All,make_unaligned(AllBin)],latin1), - ?line DoubleUtf8 = unicode:characters_to_binary([All|AllBin],latin1), - ?line DoubleUtf8 = + DoubleUtf8 = unicode:characters_to_binary([All|AllBin],latin1), + DoubleUtf8 = unicode:characters_to_binary([All|make_unaligned(AllBin)],latin1), - ?line DoubleUtf8 = unicode:characters_to_binary([AllBin,All],latin1), - ?line DoubleUtf8 = unicode:characters_to_binary([AllBin|All],latin1), - ?line DoubleUtf8 = list_to_utf8_bsyntax([AllBin|All],latin1), + DoubleUtf8 = unicode:characters_to_binary([AllBin,All],latin1), + DoubleUtf8 = unicode:characters_to_binary([AllBin|All],latin1), + DoubleUtf8 = list_to_utf8_bsyntax([AllBin|All],latin1), - ?line DoubleUtf16 = <<AllUtf16_Big/binary,AllUtf16_Big/binary>>, - ?line DoubleUtf16 = unicode:characters_to_binary([All,AllBin],latin1,{utf16,big}), - ?line DoubleUtf16 = + DoubleUtf16 = <<AllUtf16_Big/binary,AllUtf16_Big/binary>>, + DoubleUtf16 = unicode:characters_to_binary([All,AllBin],latin1,{utf16,big}), + DoubleUtf16 = unicode:characters_to_binary([All,make_unaligned(AllBin)],latin1,{utf16,big}), - ?line DoubleUtf16 = unicode:characters_to_binary([All|AllBin],latin1,{utf16,big}), - ?line DoubleUtf16 = + DoubleUtf16 = unicode:characters_to_binary([All|AllBin],latin1,{utf16,big}), + DoubleUtf16 = unicode:characters_to_binary([All|make_unaligned(AllBin)],latin1,{utf16,big}), - ?line DoubleUtf16 = unicode:characters_to_binary([AllBin,All],latin1,{utf16,big}), - ?line DoubleUtf16 = unicode:characters_to_binary([AllBin|All],latin1,{utf16,big}), - ?line DoubleUtf16 = list_to_utf16_big_bsyntax([AllBin|All],latin1), - - ?line All = unicode:characters_to_list(AllUtf8,unicode), - ?line All = unicode:characters_to_list(make_unaligned(AllUtf8),unicode), - ?line All = utf8_to_list_bsyntax(AllUtf8), - ?line AllAll = All ++ All, - ?line AllAll = unicode:characters_to_list(DoubleUtf8,unicode), - ?line AllAll = unicode:characters_to_list(make_unaligned(DoubleUtf8),unicode), - ?line AllAll = utf8_to_list_bsyntax(DoubleUtf8), - ?line {error,AllUtf8,Rest1} = unicode:characters_to_binary(All++[16#FFF],latin1), - ?line [16#FFF] = lists:flatten(Rest1), - ?line {error,DoubleUtf8,Rest2} = + DoubleUtf16 = unicode:characters_to_binary([AllBin,All],latin1,{utf16,big}), + DoubleUtf16 = unicode:characters_to_binary([AllBin|All],latin1,{utf16,big}), + DoubleUtf16 = list_to_utf16_big_bsyntax([AllBin|All],latin1), + + All = unicode:characters_to_list(AllUtf8,unicode), + All = unicode:characters_to_list(make_unaligned(AllUtf8),unicode), + All = utf8_to_list_bsyntax(AllUtf8), + AllAll = All ++ All, + AllAll = unicode:characters_to_list(DoubleUtf8,unicode), + AllAll = unicode:characters_to_list(make_unaligned(DoubleUtf8),unicode), + AllAll = utf8_to_list_bsyntax(DoubleUtf8), + {error,AllUtf8,Rest1} = unicode:characters_to_binary(All++[16#FFF],latin1), + [16#FFF] = lists:flatten(Rest1), + {error,DoubleUtf8,Rest2} = unicode:characters_to_binary([All,AllBin,16#FFF],latin1), - ?line {error,DoubleUtf16,Rest2x} = + {error,DoubleUtf16,Rest2x} = unicode:characters_to_binary([All,AllBin,16#FFF],latin1,utf16), - ?line [16#FFF] = lists:flatten(Rest2), - ?line [16#FFF] = lists:flatten(Rest2x), - ?line {error,AllUtf8,Rest3} = + [16#FFF] = lists:flatten(Rest2), + [16#FFF] = lists:flatten(Rest2x), + {error,AllUtf8,Rest3} = unicode:characters_to_binary([All,16#FFF,AllBin,16#FFF], - latin1), - ?line {error,AllUtf8,Rest3} = + latin1), + {error,AllUtf8,Rest3} = unicode:characters_to_binary([All,16#FFF,make_unaligned(AllBin),16#FFF], - latin1), - ?line {error,AllUtf16_Big,Rest3x} = + latin1), + {error,AllUtf16_Big,Rest3x} = unicode:characters_to_binary([All,16#FFF,AllBin,16#FFF], - latin1,{utf16,big}), - ?line {error,AllUtf16_Big,Rest3x} = + latin1,{utf16,big}), + {error,AllUtf16_Big,Rest3x} = unicode:characters_to_binary([All,16#FFF,make_unaligned(AllBin),16#FFF], - latin1,{utf16,big}), - ?line [16#FFF,AllBin,16#FFF] = lists:flatten(Rest3), - ?line [16#FFF,AllBin,16#FFF] = lists:flatten(Rest3x), - ?line DoubleSize = byte_size(DoubleUtf8), - ?line AllBut1 = DoubleSize - 1, - ?line AllBut2 = DoubleSize - 2, - ?line <<MissingLastByte:AllBut1/binary,_>> = DoubleUtf8, - ?line <<_:AllBut2/binary,MissingStart:1/binary,_>> = DoubleUtf8, - ?line {ChompedList,_} = lists:split(length(AllAll) - 1,AllAll), - ?line {incomplete,ChompedList,MissingStart} = + latin1,{utf16,big}), + [16#FFF,AllBin,16#FFF] = lists:flatten(Rest3), + [16#FFF,AllBin,16#FFF] = lists:flatten(Rest3x), + DoubleSize = byte_size(DoubleUtf8), + AllBut1 = DoubleSize - 1, + AllBut2 = DoubleSize - 2, + <<MissingLastByte:AllBut1/binary,_>> = DoubleUtf8, + <<_:AllBut2/binary,MissingStart:1/binary,_>> = DoubleUtf8, + {ChompedList,_} = lists:split(length(AllAll) - 1,AllAll), + {incomplete,ChompedList,MissingStart} = unicode:characters_to_list(MissingLastByte,unicode), - ?line {incomplete,ChompedList,MissingStart} = + {incomplete,ChompedList,MissingStart} = unicode:characters_to_list(make_unaligned(MissingLastByte),unicode), - ?line DoubleSize16 = byte_size(DoubleUtf16), - ?line DoubleUtf16_2 = list_to_binary([DoubleUtf16,<<16#FFFFF/utf16-big>>]), - ?line DoubleSize16_2 = byte_size(DoubleUtf16_2), - ?line AllBut1_16 = DoubleSize16 - 1, - ?line AllBut2_16_2 = DoubleSize16_2 - 2, - ?line <<MissingLastBytes16:AllBut2_16_2/binary,_,_>> = DoubleUtf16_2, - ?line <<MissingLastByte16:AllBut1_16/binary,_>> = DoubleUtf16, - ?line {incomplete,AllAll,_} = + DoubleSize16 = byte_size(DoubleUtf16), + DoubleUtf16_2 = list_to_binary([DoubleUtf16,<<16#FFFFF/utf16-big>>]), + DoubleSize16_2 = byte_size(DoubleUtf16_2), + AllBut1_16 = DoubleSize16 - 1, + AllBut2_16_2 = DoubleSize16_2 - 2, + <<MissingLastBytes16:AllBut2_16_2/binary,_,_>> = DoubleUtf16_2, + <<MissingLastByte16:AllBut1_16/binary,_>> = DoubleUtf16, + {incomplete,AllAll,_} = unicode:characters_to_list(MissingLastBytes16,utf16), - ?line {incomplete,AllAll,_} = + {incomplete,AllAll,_} = unicode:characters_to_list(make_unaligned(MissingLastBytes16),utf16), - ?line {incomplete,ChompedList,_} = + {incomplete,ChompedList,_} = unicode:characters_to_list(MissingLastByte16,utf16), - ?line {incomplete,ChompedList,_} = + {incomplete,ChompedList,_} = unicode:characters_to_list(make_unaligned(MissingLastByte16),utf16), ok. - + roundtrips(Config) when is_list(Config) -> setlimit(10), ex_roundtrips(Config), @@ -449,23 +449,21 @@ roundtrips(Config) when is_list(Config) -> ex_roundtrips(Config). ex_roundtrips(Config) when is_list(Config) -> - ?line L1 = ranges(0, 16#D800 - 1, - erlang:system_info(context_reductions) * 11), - ?line L2 = ranges(16#DFFF + 1, 16#10000 - 1, - erlang:system_info(context_reductions) * 11), - %?line L3 = ranges(16#FFFF + 1, 16#10FFFF, - % erlang:system_info(context_reductions) * 11), - ?line L3 = ranges(16#FFFFF, 16#10FFFF, - erlang:system_info(context_reductions) * 11), - ?line L = L1 ++ L2 ++ L3, - ?line LLen = length(L), - ?line Parts = erlang:system_info(schedulers), - ?line Lists = splitup(L,LLen,Parts), - ?line PidRefs = [spawn_monitor(fun() -> - do_roundtrips(MyPart) - end) || MyPart <- Lists], - ?line [receive {'DOWN',Ref,process,Pid,Reason} -> normal=Reason end || - {Pid,Ref} <- PidRefs], + L1 = ranges(0, 16#D800 - 1, + erlang:system_info(context_reductions) * 11), + L2 = ranges(16#DFFF + 1, 16#10000 - 1, + erlang:system_info(context_reductions) * 11), + L3 = ranges(16#FFFFF, 16#10FFFF, + erlang:system_info(context_reductions) * 11), + L = L1 ++ L2 ++ L3, + LLen = length(L), + Parts = erlang:system_info(schedulers), + Lists = splitup(L,LLen,Parts), + PidRefs = [spawn_monitor(fun() -> + do_roundtrips(MyPart) + end) || MyPart <- Lists], + [receive {'DOWN',Ref,process,Pid,Reason} -> normal=Reason end || + {Pid,Ref} <- PidRefs], ok. do_roundtrips([]) -> @@ -529,10 +527,10 @@ ex_random_lists(Config) when is_list(Config) -> PlainFlatten4 = fun(L) -> iolist_to_binary([int_to_utf8(X) || X <- unicode:characters_to_list(flatb(L),latin1)]) end, - ?line random_iolist:run(150, PlainFlatten1, PlainFlatten3), - ?line random_iolist:run(150, PlainFlatten2, PlainFlatten3), - ?line random_iolist:run(150, PlainFlatten1, PlainFlatten2), - ?line random_iolist:run(150, PlainFlatten1, PlainFlatten4), + random_iolist:run(150, PlainFlatten1, PlainFlatten3), + random_iolist:run(150, PlainFlatten2, PlainFlatten3), + random_iolist:run(150, PlainFlatten1, PlainFlatten2), + random_iolist:run(150, PlainFlatten1, PlainFlatten4), SelfMade = fun(L) -> iolist_to_binary(lists:map(fun(X) -> int_to_utf8(X) @@ -548,52 +546,52 @@ ex_random_lists(Config) when is_list(Config) -> Other end end, - ?line random_iolist:run(150, PlainFlatten1, SelfMade), - ?line random_iolist:run(150, PlainFlatten2, SelfMadeA), + random_iolist:run(150, PlainFlatten1, SelfMade), + random_iolist:run(150, PlainFlatten2, SelfMadeA), RoundTrip11 = fun(L) -> - unicode:characters_to_list(unicode:characters_to_binary(L,latin1),unicode) - end, + unicode:characters_to_list(unicode:characters_to_binary(L,latin1),unicode) + end, RoundTrip21 = fun(L) -> - utf8_to_list_bsyntax(unicode:characters_to_binary(L,latin1)) - end, + utf8_to_list_bsyntax(unicode:characters_to_binary(L,latin1)) + end, RoundTrip31 = fun(L) -> - unicode:characters_to_list(list_to_utf8_bsyntax(L,latin1),unicode) - end, + unicode:characters_to_list(list_to_utf8_bsyntax(L,latin1),unicode) + end, RoundTrip41 = fun(L) -> - utf8_to_list_bsyntax(list_to_utf8_bsyntax(L,latin1)) - end, + utf8_to_list_bsyntax(list_to_utf8_bsyntax(L,latin1)) + end, RoundTrip51 = fun(L) -> - unicode:characters_to_list(L,latin1) - end, - ?line random_iolist:run(150, RoundTrip11,RoundTrip21), - ?line random_iolist:run(150, RoundTrip21,RoundTrip31), - ?line random_iolist:run(150, RoundTrip31,RoundTrip41), - ?line random_iolist:run(150, RoundTrip11,RoundTrip41), - ?line random_iolist:run(150, RoundTrip21,RoundTrip41), - ?line random_iolist:run(150, RoundTrip11,RoundTrip31), - ?line random_iolist:run(150, RoundTrip11,RoundTrip51), + unicode:characters_to_list(L,latin1) + end, + random_iolist:run(150, RoundTrip11,RoundTrip21), + random_iolist:run(150, RoundTrip21,RoundTrip31), + random_iolist:run(150, RoundTrip31,RoundTrip41), + random_iolist:run(150, RoundTrip11,RoundTrip41), + random_iolist:run(150, RoundTrip21,RoundTrip41), + random_iolist:run(150, RoundTrip11,RoundTrip31), + random_iolist:run(150, RoundTrip11,RoundTrip51), UniFlatten1 = fun(L) -> unicode:characters_to_binary(flat(L),unicode) end, UniFlatten2 = fun(L) -> - unicode:characters_to_binary(L,unicode) + unicode:characters_to_binary(L,unicode) end, UniFlatten3 = fun(L) -> - unicode:characters_to_binary(flatx(L),unicode) + unicode:characters_to_binary(flatx(L),unicode) end, UniFlatten4 = fun(L) -> - unicode:characters_to_binary(unicode:characters_to_list(L,unicode),unicode) + unicode:characters_to_binary(unicode:characters_to_list(L,unicode),unicode) end, - ?line random_unicode_list:run(150, UniFlatten1,UniFlatten2), - ?line random_unicode_list:run(150, UniFlatten1,UniFlatten3), - ?line random_unicode_list:run(150, UniFlatten2,UniFlatten4), - ?line random_unicode_list:run(150, UniFlatten2,UniFlatten3), + random_unicode_list:run(150, UniFlatten1,UniFlatten2), + random_unicode_list:run(150, UniFlatten1,UniFlatten3), + random_unicode_list:run(150, UniFlatten2,UniFlatten4), + random_unicode_list:run(150, UniFlatten2,UniFlatten3), - ?line Encodings = [utf8,{utf16,big}, - {utf16,little},{utf32,big},{utf32,little}], + Encodings = [utf8,{utf16,big}, + {utf16,little},{utf32,big},{utf32,little}], lists:foreach(fun(OutEnc1) -> lists:foreach(fun(InEnc1) -> Uni16BigFlatten1 = fun(L) -> @@ -608,11 +606,10 @@ ex_random_lists(Config) when is_list(Config) -> Uni16BigFlatten4 = fun(L) -> unicode:characters_to_binary(unicode:characters_to_list(L,InEnc1),InEnc1,OutEnc1) end, - %erlang:display({InEnc1,OutEnc1}), - ?line random_unicode_list:run(150, Uni16BigFlatten1,Uni16BigFlatten2,InEnc1), - ?line random_unicode_list:run(150, Uni16BigFlatten1,Uni16BigFlatten3,InEnc1), - ?line random_unicode_list:run(150, Uni16BigFlatten2,Uni16BigFlatten4,InEnc1), - ?line random_unicode_list:run(150, Uni16BigFlatten2,Uni16BigFlatten3,InEnc1) + random_unicode_list:run(150, Uni16BigFlatten1,Uni16BigFlatten2,InEnc1), + random_unicode_list:run(150, Uni16BigFlatten1,Uni16BigFlatten3,InEnc1), + random_unicode_list:run(150, Uni16BigFlatten2,Uni16BigFlatten4,InEnc1), + random_unicode_list:run(150, Uni16BigFlatten2,Uni16BigFlatten3,InEnc1) end, Encodings) end, Encodings), SelfMade1 = fun(L) -> @@ -624,10 +621,10 @@ ex_random_lists(Config) when is_list(Config) -> SelfMade3 = fun(L) -> list_to_utf8_bsyntax(L,unicode) end, - ?line random_unicode_list:run(150, SelfMade1,SelfMade2), - ?line random_unicode_list:run(150, UniFlatten2, SelfMade1), - ?line random_unicode_list:run(150, UniFlatten2, SelfMade2), - ?line random_unicode_list:run(150, UniFlatten2, SelfMade3), + random_unicode_list:run(150, SelfMade1,SelfMade2), + random_unicode_list:run(150, UniFlatten2, SelfMade1), + random_unicode_list:run(150, UniFlatten2, SelfMade2), + random_unicode_list:run(150, UniFlatten2, SelfMade3), RoundTrip1 = fun(L) -> unicode:characters_to_list(unicode:characters_to_binary(L,unicode),unicode) end, @@ -640,12 +637,12 @@ ex_random_lists(Config) when is_list(Config) -> RoundTrip4 = fun(L) -> utf8_to_list_bsyntax(list_to_utf8_bsyntax(L,unicode)) end, - ?line random_unicode_list:run(150, RoundTrip1,RoundTrip2), - ?line random_unicode_list:run(150, RoundTrip2,RoundTrip3), - ?line random_unicode_list:run(150, RoundTrip3,RoundTrip4), - ?line random_unicode_list:run(150, RoundTrip1,RoundTrip4), - ?line random_unicode_list:run(150, RoundTrip2,RoundTrip4), - ?line random_unicode_list:run(150, RoundTrip1,RoundTrip3), + random_unicode_list:run(150, RoundTrip1,RoundTrip2), + random_unicode_list:run(150, RoundTrip2,RoundTrip3), + random_unicode_list:run(150, RoundTrip3,RoundTrip4), + random_unicode_list:run(150, RoundTrip1,RoundTrip4), + random_unicode_list:run(150, RoundTrip2,RoundTrip4), + random_unicode_list:run(150, RoundTrip1,RoundTrip3), lists:foreach(fun(OutEnc2) -> lists:foreach(fun(InEnc2) -> RoundTripUtf16_Big_1 = fun(L) -> @@ -660,12 +657,12 @@ ex_random_lists(Config) when is_list(Config) -> RoundTripUtf16_Big_4 = fun(L) -> x_to_list_bsyntax(InEnc2,list_to_x_bsyntax(InEnc2,L,InEnc2)) end, - ?line random_unicode_list:run(150, RoundTripUtf16_Big_1,RoundTripUtf16_Big_2,InEnc2), - ?line random_unicode_list:run(150, RoundTripUtf16_Big_2,RoundTripUtf16_Big_3,InEnc2), - ?line random_unicode_list:run(150, RoundTripUtf16_Big_3,RoundTripUtf16_Big_4,InEnc2), - ?line random_unicode_list:run(150, RoundTripUtf16_Big_1,RoundTripUtf16_Big_4,InEnc2), - ?line random_unicode_list:run(150, RoundTripUtf16_Big_2,RoundTripUtf16_Big_4,InEnc2), - ?line random_unicode_list:run(150, RoundTripUtf16_Big_1,RoundTripUtf16_Big_3,InEnc2) + random_unicode_list:run(150, RoundTripUtf16_Big_1,RoundTripUtf16_Big_2,InEnc2), + random_unicode_list:run(150, RoundTripUtf16_Big_2,RoundTripUtf16_Big_3,InEnc2), + random_unicode_list:run(150, RoundTripUtf16_Big_3,RoundTripUtf16_Big_4,InEnc2), + random_unicode_list:run(150, RoundTripUtf16_Big_1,RoundTripUtf16_Big_4,InEnc2), + random_unicode_list:run(150, RoundTripUtf16_Big_2,RoundTripUtf16_Big_4,InEnc2), + random_unicode_list:run(150, RoundTripUtf16_Big_1,RoundTripUtf16_Big_3,InEnc2) end, Encodings) end, Encodings), ToList1 = fun(L) -> @@ -680,12 +677,12 @@ ex_random_lists(Config) when is_list(Config) -> ToList4 = fun(L) -> utf8_to_list(unicode_mixed_to_utf8_2(L)) end, - ?line random_unicode_list:run(150, ToList1,ToList2), - ?line random_unicode_list:run(150, ToList2,ToList3), - ?line random_unicode_list:run(150, ToList3,ToList4), - ?line random_unicode_list:run(150, ToList1,ToList4), - ?line random_unicode_list:run(150, ToList2,ToList4), - ?line random_unicode_list:run(150, ToList1,ToList3), + random_unicode_list:run(150, ToList1,ToList2), + random_unicode_list:run(150, ToList2,ToList3), + random_unicode_list:run(150, ToList3,ToList4), + random_unicode_list:run(150, ToList1,ToList4), + random_unicode_list:run(150, ToList2,ToList4), + random_unicode_list:run(150, ToList1,ToList3), ok. @@ -696,13 +693,13 @@ utf16_illegal_sequences_bif(Config) when is_list(Config) -> ex_utf16_illegal_sequences_bif(Config). ex_utf16_illegal_sequences_bif(Config) when is_list(Config) -> - ?line utf16_fail_range_bif_simple(16#10FFFF+1, 16#10FFFF+512), %Too large. - ?line utf16_fail_range_bif(16#D800, 16#DFFF), %Reserved for UTF-16. + utf16_fail_range_bif_simple(16#10FFFF+1, 16#10FFFF+512), %Too large. + utf16_fail_range_bif(16#D800, 16#DFFF), %Reserved for UTF-16. + + lonely_hi_surrogate_bif(16#D800, 16#DBFF,incomplete), + lonely_hi_surrogate_bif(16#DC00, 16#DFFF,error), + leading_lo_surrogate_bif(16#DC00, 16#DFFF), - ?line lonely_hi_surrogate_bif(16#D800, 16#DBFF,incomplete), - ?line lonely_hi_surrogate_bif(16#DC00, 16#DFFF,error), - ?line leading_lo_surrogate_bif(16#DC00, 16#DFFF), - ok. utf16_fail_range_bif(Char, End) when Char =< End -> @@ -770,20 +767,20 @@ utf8_illegal_sequences_bif(Config) when is_list(Config) -> ex_utf8_illegal_sequences_bif(Config). ex_utf8_illegal_sequences_bif(Config) when is_list(Config) -> - ?line fail_range_bif(16#10FFFF+1, 16#10FFFF+512), %Too large. - ?line fail_range_bif(16#D800, 16#DFFF), %Reserved for UTF-16. + fail_range_bif(16#10FFFF+1, 16#10FFFF+512), %Too large. + fail_range_bif(16#D800, 16#DFFF), %Reserved for UTF-16. %% Illegal first character. - ?line [fail_bif(<<I,16#8F,16#8F,16#8F>>,unicode) || I <- lists:seq(16#80, 16#BF)], + [fail_bif(<<I,16#8F,16#8F,16#8F>>,unicode) || I <- lists:seq(16#80, 16#BF)], %% Short sequences. - ?line short_sequences_bif(16#80, 16#10FFFF), + short_sequences_bif(16#80, 16#10FFFF), %% Overlong sequences. (Using more bytes than necessary %% is not allowed.) - ?line overlong_bif(0, 127, 2), - ?line overlong_bif(128, 16#7FF, 3), - ?line overlong_bif(16#800, 16#FFFF, 4), + overlong_bif(0, 127, 2), + overlong_bif(128, 16#7FF, 3), + overlong_bif(16#800, 16#FFFF, 4), ok. fail_range_bif(Char, End) when Char =< End -> @@ -797,7 +794,6 @@ fail_range_bif(_, _) -> ok. short_sequences_bif(Char, End) -> Step = (End - Char) div erlang:system_info(schedulers) + 1, -% Step = (End - Char) + 1, PidRefs = short_sequences_bif_1(Char, Step, End), [receive {'DOWN',Ref,process,Pid,Reason} -> normal=Reason end || {Pid,Ref} <- PidRefs], @@ -918,8 +914,8 @@ only_fail_bif_1(Bin,Coding) -> Other -> exit({faulty_encoding_accepted,[Bin],Coding,Other}) end. - - + + fail_bif(Bin,Coding) -> @@ -1021,9 +1017,9 @@ unicode_mixed_to_utf8_2(L) -> int_to_utf8(E) end || E <- Flist ], iolist_to_binary([ExpList]). - - - + + + utf8_to_list_bsyntax(<<>>) -> []; @@ -1042,8 +1038,8 @@ list_to_utf8_bsyntax(List,latin1) -> FList = flatb(List), list_to_binary([ <<E/utf8>> || E <- FList ]). - - + + %% @@ -1066,7 +1062,7 @@ int_to_utf16_little(U) when U >= 16#10000, U =< 16#10FFFF -> LO = (16#DC00 bor (UPrim band 16#3FF)), <<HI:16/little,LO:16/little>>. - + %% This function intentionally allows construction of %% UTF-8 sequence in illegal ranges. int_to_utf8(I) when I =< 16#7F -> @@ -1093,7 +1089,7 @@ int_to_utf8(I) when I =< 16#3FFFFFF -> B2 = (I bsr 18), B1 = (I bsr 24), <<1:1,1:1,1:1,1:1,1:1,0:1,B1:2,1:1,0:1,B2:6,1:1,0:1,B3:6,1:1,0:1,B4:6, - 1:1,0:1,B5:6>>. + 1:1,0:1,B5:6>>. utf16_big_to_list_bsyntax(<<>>) -> []; @@ -1131,7 +1127,7 @@ list_to_utf16_little_bsyntax(List,latin1) -> list_to_binary([ <<E/utf16-little>> || E <- FList ]). - + utf32_big_to_list_bsyntax(<<>>) -> []; utf32_big_to_list_bsyntax(<<C/utf32-big,R/binary>>) -> @@ -1162,12 +1158,12 @@ list_to_utf32_little_bsyntax(List,{utf32,little}) -> E; true -> <<E/utf32-little>> - end || E <- FList ]); + end || E <- FList ]); list_to_utf32_little_bsyntax(List,latin1) -> FList = flatb(List), list_to_binary([ <<E/utf32-little>> || E <- FList ]). - + %% int_to_utf8(I, NumberOfBytes) -> Binary. %% This function can be used to construct overlong sequences. @@ -1211,7 +1207,7 @@ utf8_to_int(<<1:1,1:1,0:1,B1:5,1:1,0:1,B2:6>>) -> utf8_to_int(<<1:1,1:1,1:1,0:1,B1:4,1:1,0:1,B2:6,1:1,0:1,B3:6>>) -> (B1 bsl 12) bor (B2 bsl 6) bor B3; utf8_to_int(<<1:1,1:1,1:1,1:1,0:1,B1:3,1:1,0:1, - B2:6,1:1,0:1,B3:6,1:1,0:1,B4:6>>) -> + B2:6,1:1,0:1,B3:6,1:1,0:1,B4:6>>) -> Res = (B1 bsl 18) bor (B2 bsl 12) bor (B3 bsl 6) bor B4, case Res of X when X > 16#10FFFF -> @@ -1295,10 +1291,9 @@ list_to_x_bsyntax({utf32,big},L,Enc) -> list_to_utf32_big_bsyntax(L,Enc); list_to_x_bsyntax({utf32,little},L,Enc) -> list_to_utf32_little_bsyntax(L,Enc). - + make_unaligned(Bin0) when is_binary(Bin0) -> -% put(c_count,get(c_count)+1), Bin1 = <<0:3,Bin0/binary,31:5>>, Sz = byte_size(Bin0), <<0:3,Bin:Sz/binary,31:5>> = id(Bin1), @@ -1310,80 +1305,3 @@ setlimit(X) -> erts_debug:set_internal_state(available_internal_state,true), io:format("Setting loop limit, old: ~p, now set to ~p~n", [erts_debug:set_internal_state(unicode_loop_limit,X),X]). - - -%% -%% Tracing utility -%% - -%% tr_dump() -> -%% erlang:display(lists:sort(ets:tab2list(values))). - -%% tr_off(Pid) -> -%% receive after 10000 -> ok end, -%% tr_dump(), -%% Ref = erlang:monitor(process,Pid), -%% exit(Pid,kill), -%% receive -%% {'DOWN',Ref,_,_,_} -> ok -%% end, -%% ok. - -%% tr_on() -> -%% catch ets:delete(values), -%% ets:new(values,[named_table,public]), -%% ets:insert(values,{traps,0}), -%% catch ets:delete(state), -%% ets:new(state,[named_table,public]), -%% Pid = spawn(?MODULE,trace_recv,[values,state]), -%% erlang:trace(new,true,[garbage_collection,{tracer,Pid},timestamp,call]), -%% erlang:trace_pattern({erlang,list_to_utf8,2},[{'_',[],[{return_trace}]}],[global]), -%% Pid. - -%% ts_to_int({Mega,Sec,Micro}) -> -%% ((Mega * 1000000) + Sec) * 1000000 + Micro. - -%% trace_recv(Values,State) -> -%% receive -%% {trace_ts,Pid,call,_,TS} -> -%% case ets:lookup(State,{call,Pid}) of -%% [{{call,Pid},_}] -> -%% ets:update_counter(values,traps,1); -%% _ -> -%% ok -%% end, -%% ets:insert(State,{{call,Pid},ts_to_int(TS)}); -%% {trace_ts,Pid,return_from,_,_,TS} -> -%% case ets:lookup(State,{call,Pid}) of -%% [{{call,Pid},TS2}] -> -%% ets:delete(State,{call,Pid}), -%% Elapsed = ts_to_int(TS) - TS2, -%% case ets:lookup(Values,Pid) of -%% [{Pid,GCNum,CallNum,GCTime,CallTime}] -> -%% ets:insert(Values,{Pid,GCNum,CallNum+1,GCTime,CallTime+Elapsed}); -%% [] -> -%% ets:insert(Values,{Pid,0,1,0,Elapsed}) -%% end; -%% _Other -> -%% erlang:display({what2,Pid}) -%% end; -%% {trace_ts,Pid,gc_start,_,TS} -> -%% ets:insert(State,{{gc,Pid},ts_to_int(TS)}); -%% {trace_ts,Pid,gc_end,_,TS} -> -%% case ets:lookup(State,{gc,Pid}) of -%% [{{gc,Pid},TS2}] -> -%% ets:delete(State,{gc,Pid}), -%% Elapsed = ts_to_int(TS) - TS2, -%% case ets:lookup(Values,Pid) of -%% [{Pid,Num,CNum,Time,CTime}] -> -%% ets:insert(Values,{Pid,Num+1,CNum,Time+Elapsed,CTime}); -%% [] -> -%% ets:insert(Values,{Pid,1,0,Elapsed,0}) -%% end; -%% _Other -> -%% erlang:display({what,Pid}) -%% end; -%% X -> -%% erlang:display({trace_recv,X}) -%% end, -%% trace_recv(Values,State). diff --git a/lib/stdlib/test/win32reg_SUITE.erl b/lib/stdlib/test/win32reg_SUITE.erl index 88614c639d..62619dff47 100644 --- a/lib/stdlib/test/win32reg_SUITE.erl +++ b/lib/stdlib/test/win32reg_SUITE.erl @@ -24,7 +24,9 @@ -include_lib("common_test/include/ct.hrl"). -suite() -> [{ct_hooks,[ts_install_cth]}]. +suite() -> + [{ct_hooks,[ts_install_cth]}, + {timetrap,{seconds,10}}]. all() -> [long, evil_write]. @@ -49,11 +51,8 @@ init_per_suite(Config) when is_list(Config) -> end_per_suite(Config) when is_list(Config) -> Config. - -long(doc) -> "Test long keys and entries (OTP-3446)."; +%% Test long keys and entries (OTP-3446). long(Config) when is_list(Config) -> - Dog = test_server:timetrap(test_server:seconds(10)), - LongKey = "software\\" ++ lists:flatten(lists:duplicate(10, "..\\software\\")) ++ "Ericsson\\Erlang", @@ -76,12 +75,9 @@ long(Config) when is_list(Config) -> %% Done. ok = win32reg:close(Reg), - test_server:timetrap_cancel(Dog), ok. evil_write(Config) when is_list(Config) -> - Dog = test_server:timetrap(test_server:seconds(10)), - Key = "Software\\Ericsson\\Erlang", {ok,Reg} = win32reg:open([read,write]), ok = win32reg:change_key(Reg, "\\hkcu"), @@ -95,13 +91,12 @@ evil_write(Config) when is_list(Config) -> %% Done. ok = win32reg:close(Reg), - test_server:timetrap_cancel(Dog), ok. evil_write_1(Reg, [_|[_|_]=Key]=Key0) -> - ?line io:format("Key = ~p\n", [Key0]), - ?line ok = win32reg:set_value(Reg, Key0, "A good value for me"), - ?line {ok,_Val} = win32reg:value(Reg, Key0), - ?line ok = win32reg:delete_value(Reg, Key0), + io:format("Key = ~p\n", [Key0]), + ok = win32reg:set_value(Reg, Key0, "A good value for me"), + {ok,_Val} = win32reg:value(Reg, Key0), + ok = win32reg:delete_value(Reg, Key0), evil_write_1(Reg, Key); evil_write_1(_, [_]) -> ok. diff --git a/lib/stdlib/test/y2k_SUITE.erl b/lib/stdlib/test/y2k_SUITE.erl index d80dd10631..7828eb26ed 100644 --- a/lib/stdlib/test/y2k_SUITE.erl +++ b/lib/stdlib/test/y2k_SUITE.erl @@ -55,104 +55,80 @@ end_per_group(_GroupName, Config) -> Config. -date_1999_01_01(doc) -> - "#1 : 1999-01-01: test roll-over from 1998-12-31 to 1999-01-01."; -date_1999_01_01(suite) -> - []; +%% #1 : 1999-01-01: test roll-over from 1998-12-31 to 1999-01-01. date_1999_01_01(Config) when is_list(Config) -> - ?line Date = {1998, 12, 31}, NextDate = {1999, 1, 1}, - ?line match(next_date(Date), NextDate), + Date = {1998, 12, 31}, NextDate = {1999, 1, 1}, + match(next_date(Date), NextDate), TZD = tzd(Date), if TZD > 0 -> - ?line Time = {24 - TZD, 0, 0}, - ?line {NDate, _NTime} = + Time = {24 - TZD, 0, 0}, + {NDate, _NTime} = erlang:localtime_to_universaltime({Date, Time}), - ?line match(NDate, NextDate); + match(NDate, NextDate); TZD < 0 -> - ?line Time = {24 + TZD, 0, 0}, - ?line {NDate, _NTime} = + Time = {24 + TZD, 0, 0}, + {NDate, _NTime} = erlang:universaltime_to_localtime({Date, Time}), - ?line match(NDate, NextDate); + match(NDate, NextDate); true -> ok end. - -date_1999_02_28(doc) -> - "#2 : 1999-02-28: test roll-over from 1999-02-28 to 1999-03-01."; -date_1999_02_28(suite) -> - []; + +%% #2 : 1999-02-28: test roll-over from 1999-02-28 to 1999-03-01. date_1999_02_28(Config) when is_list(Config) -> - ?line Date = {1999, 2, 28}, NextDate = {1999, 3, 1}, - ?line match(next_date(Date), NextDate), - ?line match(tz_next_date(Date), NextDate). - -date_1999_09_09(doc) -> - "#3 : 1999-09-09: test roll-over from 1999-09-08 to 1999-09-09."; -date_1999_09_09(suite) -> - []; + Date = {1999, 2, 28}, NextDate = {1999, 3, 1}, + match(next_date(Date), NextDate), + match(tz_next_date(Date), NextDate). + +%% #3 : 1999-09-09: test roll-over from 1999-09-08 to 1999-09-09. date_1999_09_09(Config) when is_list(Config) -> - ?line Date = {1999, 9, 8}, NextDate = {1999, 9, 9}, - ?line match(next_date(Date), NextDate), - ?line match(tz_next_date(Date), NextDate). - -date_2000_01_01(doc) -> - "#4 : 2000-01-01: test roll-over from 1999-12-31 to 2000-01-01 to " - "2000-01-02."; -date_2000_01_01(suite) -> - []; + Date = {1999, 9, 8}, NextDate = {1999, 9, 9}, + match(next_date(Date), NextDate), + match(tz_next_date(Date), NextDate). + +%% #4 : 2000-01-01: test roll-over from 1999-12-31 to 2000-01-01 to +%% 2000-01-02.; date_2000_01_01(Config) when is_list(Config) -> - ?line Date = {1999, 12, 31}, NextDate = {2000, 1, 1}, - ?line match(next_date(Date), NextDate), - ?line match(tz_next_date(Date), NextDate), - ?line NextDate1 = {2000, 1, 2}, - ?line match(next_date(NextDate), NextDate1), - ?line match(tz_next_date(NextDate), NextDate1). - -date_2000_02_29(doc) -> - "#5 : 2000-02-29: test roll-over from 2000-02-28 to 2000-02-29 to " - "2000-03-01."; -date_2000_02_29(suite) -> - []; + Date = {1999, 12, 31}, NextDate = {2000, 1, 1}, + match(next_date(Date), NextDate), + match(tz_next_date(Date), NextDate), + NextDate1 = {2000, 1, 2}, + match(next_date(NextDate), NextDate1), + match(tz_next_date(NextDate), NextDate1). + +%% #5 : 2000-02-29: test roll-over from 2000-02-28 to 2000-02-29 to +%% 2000-03-01. date_2000_02_29(Config) when is_list(Config) -> - ?line Date = {2000, 2, 28}, NextDate = {2000, 2, 29}, - ?line match(next_date(Date), NextDate), - ?line match(tz_next_date(Date), NextDate), - ?line NextDate1 = {2000, 3, 1}, - ?line match(next_date(NextDate), NextDate1), - ?line match(tz_next_date(NextDate), NextDate1). - -date_2001_01_01(doc) -> - "#6 : 2001-01-01: test roll-over from 2000-12-31 to 2001-01-01."; -date_2001_01_01(suite) -> - []; + Date = {2000, 2, 28}, NextDate = {2000, 2, 29}, + match(next_date(Date), NextDate), + match(tz_next_date(Date), NextDate), + NextDate1 = {2000, 3, 1}, + match(next_date(NextDate), NextDate1), + match(tz_next_date(NextDate), NextDate1). + +%% #6 : 2001-01-01: test roll-over from 2000-12-31 to 2001-01-01. date_2001_01_01(Config) when is_list(Config) -> - ?line Date = {2000, 12, 31}, NextDate = {2001, 1, 1}, - ?line match(next_date(Date), NextDate), - ?line match(tz_next_date(Date), NextDate). - -date_2001_02_29(doc) -> - "#7 : 2001-02-29: test roll-over from 2001-02-28 to 2001-03-01."; -date_2001_02_29(suite) -> - []; + Date = {2000, 12, 31}, NextDate = {2001, 1, 1}, + match(next_date(Date), NextDate), + match(tz_next_date(Date), NextDate). + +%% #7 : 2001-02-29: test roll-over from 2001-02-28 to 2001-03-01. date_2001_02_29(Config) when is_list(Config) -> - ?line Date = {2001, 2, 28}, NextDate = {2001, 3, 1}, - ?line match(next_date(Date), NextDate), - ?line match(tz_next_date(Date), NextDate). - -date_2004_02_29(doc) -> - "#8 : 2004-02-29: test roll-over from 2004-02-28 to 2004-02-29 to " - "2004-03-01."; -date_2004_02_29(suite) -> - []; + Date = {2001, 2, 28}, NextDate = {2001, 3, 1}, + match(next_date(Date), NextDate), + match(tz_next_date(Date), NextDate). + +%% #8 : 2004-02-29: test roll-over from 2004-02-28 to 2004-02-29 to +%% 2004-03-01. date_2004_02_29(Config) when is_list(Config) -> - ?line Date = {2004, 2, 28}, NextDate = {2004, 2, 29}, - ?line match(next_date(Date), NextDate), - ?line match(tz_next_date(Date), NextDate), - ?line NextDate1 = {2004, 3, 1}, - ?line match(next_date(NextDate), NextDate1), - ?line match(tz_next_date(NextDate), NextDate1). - + Date = {2004, 2, 28}, NextDate = {2004, 2, 29}, + match(next_date(Date), NextDate), + match(tz_next_date(Date), NextDate), + NextDate1 = {2004, 3, 1}, + match(next_date(NextDate), NextDate1), + match(tz_next_date(NextDate), NextDate1). + %% %% Local functions %% @@ -162,7 +138,7 @@ next_date(Date) -> %% timezonediff %% tzd(Date) -> - ?line {_LDate, {LH, _LM, _LS}} = + {_LDate, {LH, _LM, _LS}} = erlang:universaltime_to_localtime({Date, {12, 0, 0}}), 12 - LH. @@ -170,15 +146,15 @@ tz_next_date(Date) -> TZD = tzd(Date), if TZD > 0 -> - ?line Time = {24 - TZD, 0, 0}, - ?line {NDate, _NTime} = + Time = {24 - TZD, 0, 0}, + {NDate, _NTime} = erlang:localtime_to_universaltime({Date, Time}), - ?line NDate; + NDate; TZD < 0 -> - ?line Time = {24 + TZD, 0, 0}, - ?line {NDate, _NTime} = + Time = {24 + TZD, 0, 0}, + {NDate, _NTime} = erlang:universaltime_to_localtime({Date, Time}), - ?line NDate; + NDate; true -> Date end. @@ -189,6 +165,3 @@ tz_next_date(Date) -> match(X, X) -> ok. - - - diff --git a/lib/stdlib/test/zip_SUITE.erl b/lib/stdlib/test/zip_SUITE.erl index 135bfd5867..57ad869f24 100644 --- a/lib/stdlib/test/zip_SUITE.erl +++ b/lib/stdlib/test/zip_SUITE.erl @@ -56,12 +56,11 @@ end_per_group(_GroupName, Config) -> Config. -borderline(doc) -> - ["Test creating, listing and extracting one file from an archive " - "multiple times with different file sizes. Also check that the " - "modification date of the extracted file has survived."]; +%% Test creating, listing and extracting one file from an archive +%% multiple times with different file sizes. Also check that the +%% modification date of the extracted file has survived. borderline(Config) when is_list(Config) -> - RootDir = ?config(priv_dir, Config), + RootDir = proplists:get_value(priv_dir, Config), TempDir = filename:join(RootDir, "borderline"), ok = file:make_dir(TempDir), @@ -178,7 +177,7 @@ match_output(eof, Expect, Port) -> kill_port_and_fail(Port, Reason) -> unlink(Port), exit(Port, die), - test_server:fail(Reason). + ct:fail(Reason). make_cmd(Cmd) -> Cmd. @@ -215,12 +214,10 @@ random_byte_list(_X, 0, Result) -> next_random(X) -> (X*17059465+1) band 16#fffffffff. -atomic(doc) -> - ["Test the 'atomic' operations: zip/unzip/list_dir, on archives." - "Also test the 'cooked' option."]; -atomic(suite) -> []; +%% Test the 'atomic' operations: zip/unzip/list_dir, on archives. +%% Also test the 'cooked' option. atomic(Config) when is_list(Config) -> - ok = file:set_cwd(?config(priv_dir, Config)), + ok = file:set_cwd(proplists:get_value(priv_dir, Config)), DataFiles = data_files(), Names = [Name || {Name,_,_} <- DataFiles], io:format("Names: ~p", [Names]), @@ -243,12 +240,10 @@ atomic(Config) when is_list(Config) -> ok. -openzip_api(doc) -> - ["Test the openzip_open/2, openzip_get/1, openzip_get/2, openzip_close/1 " - "and openzip_list_dir/1 functions."]; -openzip_api(suite) -> []; +%% Test the openzip_open/2, openzip_get/1, openzip_get/2, openzip_close/1 +%% and openzip_list_dir/1 functions. openzip_api(Config) when is_list(Config) -> - ok = file:set_cwd(?config(priv_dir, Config)), + ok = file:set_cwd(proplists:get_value(priv_dir, Config)), DataFiles = data_files(), Names = [Name || {Name, _, _} <- DataFiles], io:format("Names: ~p", [Names]), @@ -282,12 +277,10 @@ openzip_api(Config) when is_list(Config) -> ok. -zip_api(doc) -> - ["Test the zip_open/2, zip_get/1, zip_get/2, zip_close/1 " - "and zip_list_dir/1 functions."]; -zip_api(suite) -> []; +%% Test the zip_open/2, zip_get/1, zip_get/2, zip_close/1, +%% and zip_list_dir/1 functions. zip_api(Config) when is_list(Config) -> - ok = file:set_cwd(?config(priv_dir, Config)), + ok = file:set_cwd(proplists:get_value(priv_dir, Config)), DataFiles = data_files(), Names = [Name || {Name, _, _} <- DataFiles], io:format("Names: ~p", [Names]), @@ -318,13 +311,11 @@ zip_api(Config) when is_list(Config) -> %% Clean up. delete_files([Names]), - ok. + ok. -open_leak(doc) -> - ["Test that zip doesn't leak processes and ports where the " - "controlling process dies without closing an zip opened with " - "zip:zip_open/1."]; -open_leak(suite) -> []; +%% Test that zip doesn't leak processes and ports where the +%% controlling process dies without closing an zip opened with +%% zip:zip_open/1. open_leak(Config) when is_list(Config) -> %% Create a zip archive Zip = "zip.zip", @@ -358,13 +349,10 @@ spawned_zip_dead(ZipSrv) -> false end. -unzip_options(doc) -> - ["Test options for unzip, only cwd and file_list currently"]; -unzip_options(suite) -> - []; +%% Test options for unzip, only cwd and file_list currently. unzip_options(Config) when is_list(Config) -> - DataDir = ?config(data_dir, Config), - PrivDir = ?config(priv_dir, Config), + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), Long = filename:join(DataDir, "abc.zip"), %% create a temp directory @@ -374,28 +362,25 @@ unzip_options(Config) when is_list(Config) -> FList = ["quotes/rain.txt","wikipedia.txt"], %% Unzip a zip file in Subdir - ?line {ok, RetList} = zip:unzip(Long, [{cwd, Subdir}, - {file_list, FList}]), + {ok, RetList} = zip:unzip(Long, [{cwd, Subdir}, + {file_list, FList}]), %% Verify. - ?line true = (length(FList) =:= length(RetList)), - ?line lists:foreach(fun(F)-> {ok,B} = file:read_file(filename:join(DataDir, F)), - {ok,B} = file:read_file(filename:join(Subdir, F)) end, - FList), - ?line lists:foreach(fun(F)-> ok = file:delete(F) end, - RetList), + true = (length(FList) =:= length(RetList)), + lists:foreach(fun(F)-> {ok,B} = file:read_file(filename:join(DataDir, F)), + {ok,B} = file:read_file(filename:join(Subdir, F)) end, + FList), + lists:foreach(fun(F)-> ok = file:delete(F) end, + RetList), %% Clean up and verify no more files. - ?line 0 = delete_files([Subdir]), + 0 = delete_files([Subdir]), ok. -unzip_jar(doc) -> - ["Test unzip a jar file (OTP-7382)"]; -unzip_jar(suite) -> - []; +%% Test unzip a jar file (OTP-7382). unzip_jar(Config) when is_list(Config) -> - DataDir = ?config(data_dir, Config), - PrivDir = ?config(priv_dir, Config), + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), JarFile = filename:join(DataDir, "test.jar"), %% create a temp directory @@ -408,28 +393,25 @@ unzip_jar(Config) when is_list(Config) -> {ok, RetList} = zip:unzip(JarFile), %% Verify. - ?line lists:foreach(fun(F)-> {ok,B} = file:read_file(filename:join(DataDir, F)), - {ok,B} = file:read_file(filename:join(Subdir, F)) end, - FList), - ?line lists:foreach(fun(F)-> ok = file:delete(F) end, - RetList), + lists:foreach(fun(F)-> {ok,B} = file:read_file(filename:join(DataDir, F)), + {ok,B} = file:read_file(filename:join(Subdir, F)) end, + FList), + lists:foreach(fun(F)-> ok = file:delete(F) end, + RetList), %% Clean up and verify no more files. - ?line 0 = delete_files([Subdir]), + 0 = delete_files([Subdir]), ok. -zip_options(doc) -> - ["Test the options for unzip, only cwd currently"]; -zip_options(suite) -> - []; +%% Test the options for unzip, only cwd currently. zip_options(Config) when is_list(Config) -> - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), ok = file:set_cwd(PrivDir), DataFiles = data_files(), Names = [Name || {Name, _, _} <- DataFiles], %% Make sure cwd is not where we get the files - ok = file:set_cwd(?config(data_dir, Config)), + ok = file:set_cwd(proplists:get_value(data_dir, Config)), %% Create a zip archive {ok, {_,Zip}} = @@ -459,10 +441,7 @@ zip_options(Config) when is_list(Config) -> ok. -list_dir_options(doc) -> - ["Test the options for list_dir... one day"]; -list_dir_options(suite) -> - []; +%% Test the options for list_dir... one day. list_dir_options(Config) when is_list(Config) -> ok. @@ -514,10 +493,9 @@ create_files([]) -> %% make_dirs([], Dir) -> %% Dir. -bad_zip(doc) -> - ["Try zip:unzip/1 on some corrupted zip files."]; +%% Try zip:unzip/1 on some corrupted zip files. bad_zip(Config) when is_list(Config) -> - ok = file:set_cwd(?config(priv_dir, Config)), + ok = file:set_cwd(proplists:get_value(priv_dir, Config)), try_bad("bad_crc", {bad_crc, "abc.txt"}, Config), try_bad("bad_central_directory", bad_central_directory, Config), try_bad("bad_file_header", bad_file_header, Config), @@ -537,7 +515,7 @@ try_bad(N, R, Config) -> try_bad(Name0, Reason, What, Config) -> %% Intentionally no macros here. - DataDir = ?config(data_dir, Config), + DataDir = proplists:get_value(data_dir, Config), Name = Name0 ++ ".zip", io:format("~nTrying ~s", [Name]), Full = filename:join(DataDir, Name), @@ -547,14 +525,13 @@ try_bad(Name0, Reason, What, Config) -> io:format("Result: ~p\n", [Expected]); Other -> io:format("unzip/2 returned ~p (expected ~p)\n", [Other, Expected]), - test_server:fail({bad_return_value, Other}) + ct:fail({bad_return_value, Other}) end. -unzip_to_binary(doc) -> - ["Test extracting to binary with memory option."]; +%% Test extracting to binary with memory option. unzip_to_binary(Config) when is_list(Config) -> - DataDir = ?config(data_dir, Config), - PrivDir = ?config(priv_dir, Config), + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), WorkDir = filename:join(PrivDir, "unzip_to_binary"), _ = file:make_dir(WorkDir), @@ -573,11 +550,10 @@ unzip_to_binary(Config) when is_list(Config) -> ok. -zip_to_binary(doc) -> - ["Test compressing to binary with memory option."]; +%% Test compressing to binary with memory option. zip_to_binary(Config) when is_list(Config) -> - DataDir = ?config(data_dir, Config), - PrivDir = ?config(priv_dir, Config), + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), WorkDir = filename:join(PrivDir, "zip_to_binary"), _ = file:make_dir(WorkDir), @@ -606,8 +582,7 @@ zip_to_binary(Config) when is_list(Config) -> ok. -aliases(doc) -> - ["Test using the aliases, extract/2, table/2 and create/3"]; +%% Test using the aliases, extract/2, table/2 and create/3. aliases(Config) when is_list(Config) -> {_, _, X0} = erlang:timestamp(), Size = 100, @@ -628,11 +603,10 @@ aliases(Config) when is_list(Config) -> -unzip_from_binary(doc) -> - ["Test extracting a zip archive from a binary."]; +%% Test extracting a zip archive from a binary. unzip_from_binary(Config) when is_list(Config) -> - DataDir = ?config(data_dir, Config), - PrivDir = ?config(priv_dir, Config), + DataDir = proplists:get_value(data_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), ExtractDir = filename:join(PrivDir, "extract_from_binary"), ok = file:make_dir(ExtractDir), Archive = filename:join(ExtractDir, "abc.zip"), @@ -698,11 +672,9 @@ do_delete_files([Item|Rest], Cnt) -> end, do_delete_files(Rest, Cnt + DelCnt). -compress_control(doc) -> - ["Test control of which files that should be compressed"]; -compress_control(suite) -> []; +%% Test control of which files that should be compressed. compress_control(Config) when is_list(Config) -> - ok = file:set_cwd(?config(priv_dir, Config)), + ok = file:set_cwd(proplists:get_value(priv_dir, Config)), Dir = "compress_control", Files = [ {Dir, dir, $d}, @@ -833,32 +805,32 @@ extensions([], Old) -> Old. foldl(Config) -> - PrivDir = ?config(priv_dir, Config), + PrivDir = proplists:get_value(priv_dir, Config), File = filename:join([PrivDir, "foldl.zip"]), FooBin = <<"FOO">>, BarBin = <<"BAR">>, Files = [{"foo", FooBin}, {"bar", BarBin}], - ?line {ok, {File, Bin}} = zip:create(File, Files, [memory]), + {ok, {File, Bin}} = zip:create(File, Files, [memory]), ZipFun = fun(N, I, B, Acc) -> [{N, B(), I()} | Acc] end, - ?line {ok, FileSpec} = zip:foldl(ZipFun, [], {File, Bin}), - ?line [{"bar", BarBin, #file_info{}}, {"foo", FooBin, #file_info{}}] = FileSpec, - ?line {ok, {File, Bin}} = zip:create(File, lists:reverse(FileSpec), [memory]), - ?line {foo_bin, FooBin} = + {ok, FileSpec} = zip:foldl(ZipFun, [], {File, Bin}), + [{"bar", BarBin, #file_info{}}, {"foo", FooBin, #file_info{}}] = FileSpec, + {ok, {File, Bin}} = zip:create(File, lists:reverse(FileSpec), [memory]), + {foo_bin, FooBin} = try zip:foldl(fun("foo", _, B, _) -> throw(B()); (_, _, _, Acc) -> Acc end, [], {File, Bin}) catch throw:FooBin -> {foo_bin, FooBin} end, - ?line ok = file:write_file(File, Bin), - ?line {ok, FileSpec} = zip:foldl(ZipFun, [], File), + ok = file:write_file(File, Bin), + {ok, FileSpec} = zip:foldl(ZipFun, [], File), - ?line {error, einval} = zip:foldl(fun() -> ok end, [], File), - ?line {error, einval} = zip:foldl(ZipFun, [], 42), - ?line {error, einval} = zip:foldl(ZipFun, [], {File, 42}), + {error, einval} = zip:foldl(fun() -> ok end, [], File), + {error, einval} = zip:foldl(ZipFun, [], 42), + {error, einval} = zip:foldl(ZipFun, [], {File, 42}), - ?line ok = file:delete(File), - ?line {error, enoent} = zip:foldl(ZipFun, [], File), + ok = file:delete(File), + {error, enoent} = zip:foldl(ZipFun, [], File), ok. |