oKsphinx.addnodesdocument)}( rawsourcechildren]docutils.nodessection)}(hhh](h title)}(hAutotesting Transcrypt codeh]h TextAutotesting Transcrypt code}(hhparenthhhsourceNlineNuba attributes}(ids]classes]names]dupnames]backrefs]utagnamehhh hhh_/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/docs/sphinx/autotesting_transcrypt.rsthKubh )}(hhh](h)}(hWhy it's neededh]hWhy it’s needed}(hh1hh/hhhNhNubah}(h ]h"]h$]h&]h(]uh*hhh,hhhh+hKubh paragraph)}(hdA powerful autotest facility was added to Transcrypt right from the start for the following reasons:h]hdA powerful autotest facility was added to Transcrypt right from the start for the following reasons:}(hhAhh?hhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhh,hhubh enumerated_list)}(hhh](h list_item)}(hX_Any programming language compiler has to be reliable, since a large investment in code may come to depend upon it. Languages and libraries should be able to evolve without regression bugs being introduced. In a rich language many constructs are possible which all should be tested with each new release. This can only be done if testing is automated. h]h>)}(hX^Any programming language compiler has to be reliable, since a large investment in code may come to depend upon it. Languages and libraries should be able to evolve without regression bugs being introduced. In a rich language many constructs are possible which all should be tested with each new release. This can only be done if testing is automated.h]hX^Any programming language compiler has to be reliable, since a large investment in code may come to depend upon it. Languages and libraries should be able to evolve without regression bugs being introduced. In a rich language many constructs are possible which all should be tested with each new release. This can only be done if testing is automated.}(hhZhhXubah}(h ]h"]h$]h&]h(]uh*h=hh+hK hhTubah}(h ]h"]h$]h&]h(]uh*hRhhOhhhh+hNubhS)}(hXSince Transcrypt compiles not all of Python but a fairly extensive subset, it has to be rigorously clear what can be compiled and what not. The sourcecode of a set of automated tests can be an effective means of laying down what is possible in the language. Whereas code examples and documents may lag back or deviate from reality, test code has to cover the essential features of the language and is, by nature, constantly exercised to match the latest status of the language. h]h>)}(hXSince Transcrypt compiles not all of Python but a fairly extensive subset, it has to be rigorously clear what can be compiled and what not. The sourcecode of a set of automated tests can be an effective means of laying down what is possible in the language. Whereas code examples and documents may lag back or deviate from reality, test code has to cover the essential features of the language and is, by nature, constantly exercised to match the latest status of the language.h]hXSince Transcrypt compiles not all of Python but a fairly extensive subset, it has to be rigorously clear what can be compiled and what not. The sourcecode of a set of automated tests can be an effective means of laying down what is possible in the language. Whereas code examples and documents may lag back or deviate from reality, test code has to cover the essential features of the language and is, by nature, constantly exercised to match the latest status of the language.}(hhrhhpubah}(h ]h"]h$]h&]h(]uh*h=hh+hK hhlubah}(h ]h"]h$]h&]h(]uh*hRhhOhhhh+hNubeh}(h ]h"]h$]h&]h(]enumtypearabicprefixhsuffix.uh*hMhh,hhhh+hK ubeh}(h ]why-it-s-neededah"]h$]why it's neededah&]h(]uh*h hh hhhh+hKubh )}(hhh](h)}(h How it worksh]h How it works}(hhhhhhhNhNubah}(h ]h"]h$]h&]h(]uh*hhhhhhh+hKubh>)}(hWhen code is being tested, a reference is needed of what is considered to be correct. With Transcrypt that reference is CPython. Autotesting Transcrypt code is simple and boils down to the following.h]hWhen code is being tested, a reference is needed of what is considered to be correct. With Transcrypt that reference is CPython. Autotesting Transcrypt code is simple and boils down to the following.}(hhhhhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhhhhubhN)}(hhh](hS)}(hX$Along with developing production code, a growing set of *testlets* is developed. A testlet is a small module testing a certain feature or group of features. It repeatedly calls method *org.transcrypt.autotester.AutoTester.check (self, \*args)* to build a well defined sequence of output data.h]h>)}(hhh](h8Along with developing production code, a growing set of }(h8Along with developing production code, a growing set of hhubh emphasis)}(h *testlets*h]htestlets}(hhhhubah}(h ]h"]h$]h&]h(]uh*hhhubhv is developed. A testlet is a small module testing a certain feature or group of features. It repeatedly calls method }(hv is developed. A testlet is a small module testing a certain feature or group of features. It repeatedly calls method hhubh)}(h;*org.transcrypt.autotester.AutoTester.check (self, \*args)*h]h9org.transcrypt.autotester.AutoTester.check (self, *args)}(hhhhubah}(h ]h"]h$]h&]h(]uh*hhhubh1 to build a well defined sequence of output data.}(h1 to build a well defined sequence of output data.hhubeh}(h ]h"]h$]h&]h(]uh*h=hh+hKhhubah}(h ]h"]h$]h&]h(]uh*hRhhhhhh+hNubhS)}(hKA series of testlets are imported into an application called an *autotest*.h]h>)}(hhh](h@A series of testlets are imported into an application called an }(h@A series of testlets are imported into an application called an hhubh)}(h *autotest*h]hautotest}(hhhjubah}(h ]h"]h$]h&]h(]uh*hhhubh.}(hhhhubeh}(h ]h"]h$]h&]h(]uh*h=hh+hKhhubah}(h ]h"]h$]h&]h(]uh*hRhhhhhh+hNubhS)}(hThe autotest is first run from the command line: *python transcrypt -r autotest*. This will generate file *autotest.html* in the working directory, containing the *reference data sequence* produced by CPython, in an HTML DIV.h]h>)}(hj%h](h1The autotest is first run from the command line: }(h1The autotest is first run from the command line: hj'ubh)}(h*python transcrypt -r autotest*h]hpython transcrypt -r autotest}(hhhj/ubah}(h ]h"]h$]h&]h(]uh*hhj'ubh. This will generate file }(h. This will generate file hj'ubh)}(h*autotest.html*h]h autotest.html}(hhhjBubah}(h ]h"]h$]h&]h(]uh*hhj'ubh* in the working directory, containing the }(h* in the working directory, containing the hj'ubh)}(h*reference data sequence*h]hreference data sequence}(hhhjUubah}(h ]h"]h$]h&]h(]uh*hhj'ubh% produced by CPython, in an HTML DIV.}(h% produced by CPython, in an HTML DIV.hj'ubeh}(h ]h"]h$]h&]h(]uh*h=hh+hKhj#ubah}(h ]h"]h$]h&]h(]uh*hRhhhhhh+hNubhS)}(hXCAfter that, the autotest is compiled to JavaScript: *python transcrypt -b autotest*. This will generate file *autotest.js* in the corresponding target directory. Note that you may need extra command line switches to activate options needed for your testcode, e.g. -c if you use complex numbers or -da if you use assertions.h]h>)}(hjvh](h4After that, the autotest is compiled to JavaScript: }(h4After that, the autotest is compiled to JavaScript: hjxubh)}(h*python transcrypt -b autotest*h]hpython transcrypt -b autotest}(hhhjubah}(h ]h"]h$]h&]h(]uh*hhjxubh. This will generate file }(h. This will generate file hjxubh)}(h *autotest.js*h]h autotest.js}(hhhjubah}(h ]h"]h$]h&]h(]uh*hhjxubh in the corresponding target directory. Note that you may need extra command line switches to activate options needed for your testcode, e.g. -c if you use complex numbers or -da if you use assertions.}(h in the corresponding target directory. Note that you may need extra command line switches to activate options needed for your testcode, e.g. -c if you use complex numbers or -da if you use assertions.hjxubeh}(h ]h"]h$]h&]h(]uh*h=hh+hKhjtubah}(h ]h"]h$]h&]h(]uh*hRhhhhhh+hNubhS)}(hClick on *autotest.html* to load the autotest into the browser and run *autotest.js*. This will generate the *test data sequence*, now using the Transcrypt runtime.h]h>)}(hjh](h Click on }(h Click on hjubh)}(h*autotest.html*h]h autotest.html}(hhhjubah}(h ]h"]h$]h&]h(]uh*hhjubh/ to load the autotest into the browser and run }(h/ to load the autotest into the browser and run hjubh)}(h *autotest.js*h]h autotest.js}(hhhjubah}(h ]h"]h$]h&]h(]uh*hhjubh. This will generate the }(h. This will generate the hjubh)}(h*test data sequence*h]htest data sequence}(hhhjubah}(h ]h"]h$]h&]h(]uh*hhjubh#, now using the Transcrypt runtime.}(h#, now using the Transcrypt runtime.hjubeh}(h ]h"]h$]h&]h(]uh*h=hh+hKhjubah}(h ]h"]h$]h&]h(]uh*hRhhhhhh+hNubhS)}(hAfter this, the test data sequence is automatically compared to the reference data sequence that was part of the html, and an error report is shown in the browser. h]h>)}(hAfter this, the test data sequence is automatically compared to the reference data sequence that was part of the html, and an error report is shown in the browser.h]hAfter this, the test data sequence is automatically compared to the reference data sequence that was part of the html, and an error report is shown in the browser.}(hj hjubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhjubah}(h ]h"]h$]h&]h(]uh*hRhhhhhh+hNubeh}(h ]h"]h$]h&]h(]hhhhhhuh*hMhhhhhh+hKubh>)}(h`An example of two testlets combined into the 'hello' autotest, that is part of the distribution:h]hdAn example of two testlets combined into the ‘hello’ autotest, that is part of the distribution:}(hj#hj!hhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhhhhubh table)}(hhh]h tgroup)}(hhh](h colspec)}(hhh]h}(h ]h"]h$]h&]h(]colwidthKLuh*j9hj6ubj:)}(hhh]h}(h ]h"]h$]h&]h(]colwidthKLuh*j9hj6ubj:)}(hhh]h}(h ]h"]h$]h&]h(]colwidthKLuh*j9hj6ubh tbody)}(hhh]h row)}(hhh](h entry)}(hhh]h container)}(hhh](h caption)}(h autotest.pyh]h autotest.py}(hjqhjoubah}(h ]h"]h$]h&]h(]uh*jmhh+hKhjjubh literal_block)}(himport org.transcrypt.autotester import testlet0 import testlet1 autoTester = org.transcrypt.autotester.AutoTester () autoTester.run (testlet0, 'testlet0') autoTester.run (testlet1, 'testlet1') autoTester.done () h]himport org.transcrypt.autotester import testlet0 import testlet1 autoTester = org.transcrypt.autotester.AutoTester () autoTester.run (testlet0, 'testlet0') autoTester.run (testlet1, 'testlet1') autoTester.done () }(hhhjubah}(h ]h"]h$]h&]h(]sourcef/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/hello/autotest.py xml:spacepreserveforcehighlight_args} linenostartKsuh*j}hh+hKhjjubeh}(h ]id1ah"]literal-block-wrapperah$]h&]h(] literal_blockuh*jhhjeubah}(h ]h"]h$]h&]h(]uh*jchj`ubjd)}(hhh]ji)}(hhh](jn)}(h testlet0.pyh]h testlet0.py}(hjhjubah}(h ]h"]h$]h&]h(]uh*jmhh+hKhjubj~)}(hTdef run (autoTester): autoTester.check ('hello') autoTester.check ('world') h]hTdef run (autoTester): autoTester.check ('hello') autoTester.check ('world') }(hhhjubah}(h ]h"]h$]h&]h(]sourcef/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/hello/testlet0.pyjjjj}jKsuh*j}hh+hKhjubeh}(h ]id2ah"]jah$]h&]h(] literal_blockuh*jhhjubah}(h ]h"]h$]h&]h(]uh*jchj`ubjd)}(hhh]ji)}(hhh](jn)}(h testlet1.pyh]h testlet1.py}(hjhjubah}(h ]h"]h$]h&]h(]uh*jmhh+hKhjubj~)}(hUdef run (autoTester): autoTester.check ('goodbye') autoTester.check ('moon') h]hUdef run (autoTester): autoTester.check ('goodbye') autoTester.check ('moon') }(hhhjubah}(h ]h"]h$]h&]h(]sourcef/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/development/automated_tests/hello/testlet1.pyjjjj}jKsuh*j}hh+hKhjubeh}(h ]id3ah"]jah$]h&]h(] literal_blockuh*jhhjubah}(h ]h"]h$]h&]h(]uh*jchj`ubeh}(h ]h"]h$]h&]h(]uh*j^hj[ubah}(h ]h"]h$]h&]h(]uh*jYhj6ubeh}(h ]h"]h$]h&]h(]colsKuh*j4hj1ubah}(h ]h"]h$]h&]h(]uh*j/hhhhhNhNubh>)}(hSteps to run the tests:h]hSteps to run the tests:}(hj%hj#hhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK!hhhhubj~)}(h-transcrypt -r autotest transcrypt -b autotesth]h-transcrypt -r autotest transcrypt -b autotest}(hhhj1ubah}(h ]h"]h$]h&]h(]jjjlanguageshellj}uh*j}hh+hK#hhhhubh>)}(hXAt this point, if you start a webserver and load *autotest.html* in your browser from localhost, you will see that all tests passed. In order to trigger an error, open *testlet1.py*, search for *goodbye* and replace it with *badbye*. After that, recompile with:h](h1At this point, if you start a webserver and load }(h1At this point, if you start a webserver and load hjBhhhNhNubh)}(h*autotest.html*h]h autotest.html}(hhhjKubah}(h ]h"]h$]h&]h(]uh*hhjBubhh in your browser from localhost, you will see that all tests passed. In order to trigger an error, open }(hh in your browser from localhost, you will see that all tests passed. In order to trigger an error, open hjBhhhNhNubh)}(h *testlet1.py*h]h testlet1.py}(hhhj^ubah}(h ]h"]h$]h&]h(]uh*hhjBubh , search for }(h , search for hjBhhhNhNubh)}(h *goodbye*h]hgoodbye}(hhhjqubah}(h ]h"]h$]h&]h(]uh*hhjBubh and replace it with }(h and replace it with hjBhhhNhNubh)}(h*badbye*h]hbadbye}(hhhjubah}(h ]h"]h$]h&]h(]uh*hhjBubh. After that, recompile with:}(h. After that, recompile with:hjBhhhNhNubeh}(h ]h"]h$]h&]h(]uh*h=hh+hK(hhhhubj~)}(htranscrypt -b autotesth]htranscrypt -b autotest}(hhhjubah}(h ]h"]h$]h&]h(]jjjj?shellj}uh*j}hh+hK*hhhhubh>)}(h>Once again open *autotest.html* in your browser, it will show:h](hOnce again open }(hOnce again open hjhhhNhNubh)}(h*autotest.html*h]h autotest.html}(hhhjubah}(h ]h"]h$]h&]h(]uh*hhjubh in your browser, it will show:}(h in your browser, it will show:hjhhhNhNubeh}(h ]h"]h$]h&]h(]uh*h=hh+hK.hhhhubh figure)}(hhh]h image)}(hV.. figure:: ../images/autotest_hello.png :alt: Output of 'hello autotest' h]h}(h ]h"]h$]h&]h(]altOutput of 'hello autotest'uri../images/autotest_hello.png candidates}*jsuh*jhjhh+hNubah}(h ]h"]h$]h&]h(]uh*jhhhhhh+hNubh>)}(hSome testlets may require additional switches. The main *transcrypt* autotest e.g. requires and extra *-c -da*, since it uses both complex numbers and debugging assertions.h](h8Some testlets may require additional switches. The main }(h8Some testlets may require additional switches. The main hjhhhNhNubh)}(h *transcrypt*h]h transcrypt}(hhhjubah}(h ]h"]h$]h&]h(]uh*hhjubh" autotest e.g. requires and extra }(h" autotest e.g. requires and extra hjhhhNhNubh)}(h*-c -da*h]h-c -da}(hhhj ubah}(h ]h"]h$]h&]h(]uh*hhjubh>, since it uses both complex numbers and debugging assertions.}(h>, since it uses both complex numbers and debugging assertions.hjhhhNhNubeh}(h ]h"]h$]h&]h(]uh*h=hh+hK3hhhhubeh}(h ] how-it-worksah"]h$] how it worksah&]h(]uh*h hh hhhh+hKubeh}(h ]autotesting-transcrypt-codeah"]h$]autotesting transcrypt codeah&]h(]uh*h hhhhhh+hKubah}(h ]h"]h$]h&]h(]sourceh+uh*hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksjcfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjTerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh+ _destinationN _config_files]pep_referencesN pep_base_url https://www.python.org/dev/peps/pep_file_url_templatepep-%04drfc_referencesN rfc_base_urlhttps://tools.ietf.org/html/ tab_widthKtrim_footnote_reference_spacefile_insertion_enabled raw_enabledKsyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xformembed_stylesheetcloak_email_addressesenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(j/j,hhj'j$u nametypes}(j/NhNj'Nuh }(j,h hh,j$hjjjjjjju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}jbKsRparse_messages]transform_messages] transformerN decorationNhhub.