LSL-PyOptimizer/unit_tests
Sei Lisa e3c1634724 Fix regression introduced with the latest changes to loadlib
In Python 2, function type names from buiiltins.txt were entered into the tables as Unicode, causing the output module to promote strings to Unicode, and causing trouble further down the line.

Entering them as str fixes the issue.

Thanks a lot to @PeterStindberg for reporting the issue and providing a script that reproduces it.

Fixes #21
2023-01-09 11:03:41 +01:00
..
coverage.suite Fix missing comma that prevented --libdata from working 2022-12-20 21:49:32 +01:00
expr.suite Fix warning about possible future breakage 2022-12-12 16:32:14 +01:00
lso.suite Add -y to test entries without an .err file; improve consistency 2020-11-08 19:07:07 +01:00
preproc.suite Fix --postarg and add option --preproc-show-cmdline + unit test 2022-06-17 16:13:22 +02:00
regression.suite Fix regression introduced with the latest changes to loadlib 2023-01-09 11:03:41 +01:00
__init__.py Forgot unit_tests/__init__.py necessary to run the JSON test 2019-01-11 17:34:10 +01:00
builtins-coverage-1.txt Add the new test suite. 2019-01-04 20:27:36 +01:00
builtins-coverage-2.txt Add the new test suite. 2019-01-04 20:27:36 +01:00
builtins-coverage-4.txt Add the new test suite. 2019-01-04 20:27:36 +01:00
builtins-coverage-5.txt Add the new test suite. 2019-01-04 20:27:36 +01:00
cat.py Add the new test suite. 2019-01-04 20:27:36 +01:00
false.py Add the new test suite. 2019-01-04 20:27:36 +01:00
fndata-coverage-3.txt Add the new test suite. 2019-01-04 20:27:36 +01:00
fndata-coverage-4.txt Add the new test suite. 2019-01-04 20:27:36 +01:00
fndata-coverage-5.txt Add the new test suite. 2019-01-04 20:27:36 +01:00
json.err All tests pass now 2020-11-10 02:14:15 +01:00
json.out Add the new test suite. 2019-01-04 20:27:36 +01:00
json.py All tests pass now 2020-11-10 02:14:15 +01:00
output-list.lsl Remove indents from list generator 2021-05-08 18:45:15 +02:00
README.txt Make .fail files replace the docstring in order to be visible 2019-01-04 22:29:15 +01:00
seftable-coverage.txt Add the new test suite. 2019-01-04 20:27:36 +01:00

Unit testing suites. These tests are run via run-tests.py.

The testing is performed using the standard Python module 'unittest'. This module accepts some command-line options; we don't add any ourselves. Use 'python run-tests.py -h' for help, or look here for details: https://docs.python.org/2/library/unittest.html#command-line-interface

There are 5 directories defined in the code that contain tests, all of which end in .suite: regression.suite, expr.suite, lso.suite, coverage.suite, preproc.suite.

The files that all 5 contain are the tests themselves. The run-tests.py program reads all .run and .lsl files in each directory and takes them as tests to run.

A test is a series of files all with the same name and with different extensions. Running the test means running the optimizer with the parameters in the .run file (if present), giving it the .lsl file (if present) as input. The output to stdout is compared to the .out file and the output to stderr is compared to the .err file. The test passes if both match and no exception is raised; otherwise it fails.

These are the extensions that the test suite recognizes in more detail:

  .lsl: Source file to test. If the first line starts with '// ', then the text in the rest of the line will be set as the docstring for the corresponding test function (visible when requesting verbose coverage).
  .run: Command line parameters for the test. Default is: 'main.py -', except in expr.suite which defaults to 'main.py -O clear,optimize,constfold,addstrings,expr -'. The syntax for the parameters is that of the Bourne shell, but '$' expansion is not supported. The 'main.py' part is the value that argv[0] will receive, but is unused otherwise.
  .out: Expected stdout resulting from the test. If the first line is REGEX then the rest of the file will be taken as a regular expression to match against, as opposed to matching the whole file contents.
  .err: Expected stderr resulting from the test. It also allows regular expression.
  .skp: If present, the test will be skipped (not run). The contents of this file are taken as the reason for the expected failure.
  .fail: If present, the test will be run, and counted as an expected failure. If a .fail file is present and the test passes, that will be counted as an unexpected success, and the program will not report success at the end. The contents will go to the docstring for the test if not empty, replacing the one taken from the .lsl file.

A test is considered such when either the .lsl or the .run file are present. The default stdin for the program is the .lsl file.

As for the meaning of each subdirectory:

- regression.suite contains normal regression tests.
- expr.suite contains regression tests that apply to expressions.
- lso.suite contains LSO mode tests. Note that LSO support is incomplete.
- coverage.suite contains tests that force certain code paths to execute, in order to maximize the exercised code coverage, even if some tests are trivial and unlikely to cause a regression.
- preproc.suite is for preprocessor-related tests.

As for the files in this directory:

- cat.py just copies standard input to standard output. Used as a preprocessor for some preprocessor tests.
- false.py just terminates with exit code 1.
- output-list.lsl is a utility script that dumps an arbitrary list to local chat, in a format very similar to the one that the expression suite outputs (it may require manual removal of timestamps). Float precision may differ.