aboutsummaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)AuthorFilesLines
2021-01-30lsearch, lsort: support for -stride and -indexSteve Bennett2-10/+151
Add -stride support to both lsearch and lsort Add -index support to lsearch Improve -index for lsort to support multiple indices Also harmonise some error messages with Tcl 8.7 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-01-23history: Add support for history keepSteve Bennett1-1/+1
Fixes #191 Signed-off-by: Steve Bennett <steveb@workware.net.au> Reported-by: D. Bohdan <dbohdan@dbohdan.com>
2021-01-09Add the [xtrace] commandSteve Bennett1-0/+62
Allows a debugger or tracing facility to be implemented Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-01-03bootstrap jimsh: pass all testsSteve Bennett7-72/+103
In order to test bootstrap jimsh, it is very helpful if it can pass all the unit tests. - Set tcl_platform(bootstrap) to 1 for bootstrap jimsh or 0 otherwise - Use getref to determine in we have references, not ref since we implement a poor-man's ref for bootstrap jimsh - bootstrap jimsh package doesn't return a "Can't load package" message if loading the package fails - exec tests using [open |command] need pipe - bootstrap jimsh can't set file times with [file mtime] Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-01-03core: fix parsing of booleansSteve Bennett1-0/+5
When boolean parsing was combined in commit 982ec4f524bc81a240cb729cf09bd3c677aea485 it broken parsing of boolean values in expressions that weren't standalone. e.g. expr {true} was fine, but expr {true ? 4 : 5} was not. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-12-26loop: Allow start value to be omittedSteve Bennett1-0/+8
It is convenient to be able to do just: loop i 5 { body } Where the start value is 0. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-12-26core: commands that take an index now use integer expressionsSteve Bennett9-27/+160
This means that instead of just [list index 2+1], we can now do [list index end-$n*2+1] This applies to: lindex, linsert, lreplace, lset, lrange, lsort, regexp, regsub string index,first,last,range Also add tests for both direct integer expressions and indexes. Still needs doc update. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-12-26core: support integer expressions in various commandsSteve Bennett5-38/+36
For convenience, many commands now accept integer expressions rather than only simple integers. These are: loop, range, incr, string repeat, lrepeat, pack, unpack, rand This simplifies many cases where previously expr {} or $() was required. e.g. foreach i [range 4+1 2*$b] { ... } string repeat 2**$n a Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-12-11list, string: support any number of +/-n for indexSteve Bennett1-0/+28
It is especially convenient to add -1 for something like: lindex $list end-$BACK-1 or: string range $str $p $p+$len-1 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-11-16expr: TIP 582 - comments in expressionsSteve Bennett2-3/+26
Add support for comments in expressions Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-11-14core: parser: fix for script with missing end quoteSteve Bennett1-0/+16
Ensure that 'info complete' returns 0 for a script is missing the end quote such as "abc$def Fixes #181 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-11-14tests: ssl: use flush, not closeSteve Bennett1-3/+3
Using 'close w' with an ssl socket doesn't really work because this is done only on the underlying socket. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-11-14tests: aio tty: skip tests if stdout is not a ttySteve Bennett1-1/+1
Fixes: #182 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-11-09aio: socket: Fix tests connecting to 0.0.0.0Steve Bennett2-10/+25
It is not portable to connect to 0.0.0.0, expecting this to the same as connecting to localhost/127.0.0.1, and the same for IPv6. So explicitly connect to 127.0.0.1 or [::1] Fixes #180 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-11-08build: Fix build and tests for out-of-tree buildSteve Bennett7-28/+23
Loadable modules and tests Fixes #179 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-11-01scan.test: Be more lenient in floating point formatSteve Bennett1-4/+4
Some systems produce 5e-05 while some produce 5e-5. Both are acceptable. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-10-31core: change "newVal" to "value" in [lset] usageD. Bohdan1-1/+1
2020-10-31core: put space before "..." in "wrong # args" msgD. Bohdan2-0/+14
Resolves #173.
2020-09-27core: make unary "!" work with non-int booleansD. Bohdan1-0/+8
2020-09-23dict: add support for getwithdefault/getdefSteve Bennett1-0/+107
TIP 342 (https://core.tcl-lang.org/tips/doc/trunk/tip/342.md) Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-09-23core: implement string comparison operatorsD. Bohdan1-0/+22
TIP 461
2020-09-23core: implement 0d radix prefix for decimalD. Bohdan1-0/+7
TIP 472
2020-07-12string last: fix segfault with invalid indexSteve Bennett1-0/+3
[string last foo bar -1] gave segfault due to missing check for invalid index. Fixes #161 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-06-25core: dicts (and arrays) now preserve insertion orderSteve Bennett4-3/+41
Although the documentation has always stated that, like Tcl, insertion order of dictionaries was preserved, this has never been the case. Instead, dictionaries were implemented as simple hash tables that did not preserve order. Now, a new implementation of dictionaries preserves insertion order and has a number of other benefits. Instead of hashing keys and storing keys and values in the hash table, the keys and values are not stored in a separate table, exactly as lists are stored, with alternating key, value pairs. Iterating over the dictionary is exactly like iterating over a list, where the order is consistent. The hash table uses closed hashing rather than open hashing to avoid allocatation of hash entry structures. Instead a fixed (but expandable) hash table maps the key hash to the offset in the key/value table. This use of offsets means that if the key/value table grows, the offsets remain valid. Likewise, if the hash table needs to grow, the key, value table remains unchanged. In addition to the offset (which indexes to the value, and 0 means the hash table entry is unused), the original hash is stored in the hash table. This reduces the need for object comparisons on hash entry collisions. The collision resolution algorithm is the same as that used by Python: peturb >>= 5; idx = (5 * idx + 1 + peturb) & dict->sizemask; In order to reduce collisions, the hash table is expanded once it reaches half full. This is more conservative that Python where the table is expanded when it is two thirds full. Note that if a hash collision occurs and then the original entry that cased the hash collision is removed, we still need to continue iterating when searching for the new key. Don't stop at the now-empty slot. So these entries are marked with offset=-1 to indicate that they need to be skipped. In addition, the new faster hashing algorithm from Tcl 8.7 is used. This the hash for integers to be calculated efficiently without requiring them to be converted to string form first. This implementation is modelled largely on the Python dict implementation. Overall the performance should be an improvement over the current implementation, whilst preserving order. Dictionary creating and insertion should be faster as hash entries do not need to be allocated and resizing should be slightly faster. Entry lookup should be about the same, except may be faster for pure integer keys. Below are some indicative benchmarks. OLD NEW dict-create-1.1 Create empty dict 97.2ns . dict-create-1.2 Create small dict 440ns -27% dict-create-1.3 Create medium dict 1.54us -57% dict-create-1.4 Create large dict (int keys) 130us -80% dict-create-1.5 Create large dict (string keys) 143us -75% dict-set-1.1 Replace existing item 258ns -34% dict-set-1.2 Replace nonexistent item 365ns -49% dict-exists-1.1 Find existing item 55.7ns -5% dict-exists-1.2 Find nonexistent item 55.0ns -5% Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-06-13core: info commands failed to match under some conditionsSteve Bennett1-0/+7
Now that proc names are stored as-is in the commands table, info commands needs to take into account matching both foo::test and ::foo::test against the pattern ::foo::* Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-06-05tests: allow more time for some testsSteve Bennett3-18/+18
If running in a VM with very variable time Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-06-05tests: Fix some tests when certain features are disabledSteve Bennett3-7/+13
namespace, ssl Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-06-05core: command (proc) names may now contained embedded nullsSteve Bennett2-0/+6
The hash table used to store commands now uses Jim_Obj keys rather than allocated char *, so embedded nulls are supported. This means that some API function such as Jim_RenameCommand() now take Jim_Obj * rather than const char *, however Jim_CreateCommand() is retained with const char * for convenience and the new Jim_CreateCommandObj() is added. This is generally a performance win as the existing Jim_Obj can be used as the key. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-06-05core: string match and other glob matching support embedded nullsSteve Bennett2-2/+21
string match, switch -glob, info commands, etc. all now support patterns and strings with embedded nulls. Fixes #143 Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-06-05core: variable names may now contain embedded nullsSteve Bennett5-17/+17
Hash tables used to store variables are now use Jim_Obj keys rather than allocated char *, so embedded nulls are supported. This is generally a performance win as the existing Jim_Obj can be used as the key. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-28test(aio,socket,tty): match musl error messagesD. Bohdan3-5/+5
2020-05-07tests: interactive.tests requires socket pty supportSteve Bennett1-0/+1
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-07tests: Add interactive mode testsSteve Bennett2-0/+368
Using a custom "expect-like" module to allow testing Jim in interactive mode. This also exercises the 'socket pty' support. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-07lsearch, switch: fix -regexp case with option-like patternSteve Bennett2-0/+17
If the pattern begins with -, the internal invocation of regexp will treat the pattern as an option. Fix this by adding -- to the internal invocation of regexp. Fixes #154 Reported-by: Barry Arthur <barry.arthur@gmail.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-06tests: socket.test check for ipv6 supportSteve Bennett1-4/+18
Skip ipv6 tests if not supported Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-06tests: jimsh.tests additional testsSteve Bennett1-0/+16
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-06tests: ssl.test: Enable SNI and test verifySteve Bennett1-4/+8
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-06aio: Fix eventloop and eof for ssl connectionsSteve Bennett2-9/+9
We can't use feof() and 'buffering none' on ssl connections. Instead we have to get eof from the ssl layer, and provide special handling for buffering in the eventloop. For eof, add ssl_eof() and detect SSL_read() results that indicate eof to set AIO_EOF in flags. For buffering, add 'read -pending' that will read, and then immediately read any buffered data so that the 'readable' event will trigger next time. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-06tests: add ssl.testSteve Bennett3-0/+168
Note that there is currently a problem with ssl and readable events Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-06tests: add socket.testsSteve Bennett1-0/+367
Basic testing of each of the socket types Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-06tests/runall.tcl: support tests that forkSteve Bennett1-0/+7
Because we use catch -exit { ... }, if a test uses os.fork we will return in both the parent in the child. To fix this, require the child to use exit 99, and detect this case and exit from the child in this case. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-06exit: Set the exit code as the interp resultSteve Bennett2-3/+3
If exit is caught with catch -exit, it is currently not possible to retrieve the exit value. If an exit code is provided, set it as the interp result. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04tests: Fixes to recent tests for windowsSteve Bennett5-18/+27
Mostly just avoiding running certain tests, but also: - rename() won't overwrite an existing file on Windows - ensure that eof returns 0 or 1 - in aio.test, create and read the file in binary mode Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04jim.c: Fix UpdateStringOfIndex()Steve Bennett1-0/+8
In case the index is invalid, the string should contain -MAX_INT Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04scan: Fix a utf-8 bug for string lengthSteve Bennett1-0/+7
The string length was being checked in chars instead of bytes Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04regsub: Fix regsub -all with \ASteve Bennett1-5/+5
regsub -all matches \A against the start of each match, but correctly handle a pattern like ^ which does not advance the match Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04regexp: Improved error messageSteve Bennett1-5/+4
Detect and produce an error for missing closing bracket ] Consider a trailing backslash as an invalid escape Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04signal check: fix error returnSteve Bennett1-4/+2
If the signal is invalid, indicate that Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04unpack: consistent error messagesSteve Bennett1-7/+5
between pack and unpack Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-05-04file readlink: change error message to match TclSteve Bennett1-1/+1
Signed-off-by: Steve Bennett <steveb@workware.net.au>