From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id BD56E6EC7F; Tue, 20 Jul 2021 19:28:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BD56E6EC7F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626798482; bh=qTkok3GAy4H3yj74YfoMmKn2wNyGBDfP1unnIqlMO0g=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=WwGFLhy1576nt66kRmKbDpf/si4Zw+VoniuukLwPsOu35ffEG4s/BRqWEQfZSr4qO Ahbn+AScFDENr1jqa6vJu0EMbu4Z9iWqSiPP6aYbp0+etAEq8idWPOekzbG5zi7bJo 3h5bB2NIr/dGzEDQZXCs9qmSJ+PCHxhUfkqqFq/o= Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D009B6EC55 for ; Tue, 20 Jul 2021 19:27:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D009B6EC55 Received: by mail-lj1-f172.google.com with SMTP id d17so11706029ljq.12 for ; Tue, 20 Jul 2021 09:27:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mOTC4gK6GYRqRBKeOoMGxz581PB/gHPoKVuUylVGlJY=; b=uEGTMwFjYsJnfGrUMzhuTtjVKUMVyLIq6KRwI/32YLOQa2eeMxX+P6B6TvYx3qL67q Tde37MyQnOWTh5pKn3h3w5Dy7t90NJC1rceFyLyp8PlHZpkrHCrzQLhtoN4TQocg+hM+ N1UmPjmXB8YpeWNG8S2xO2IQukZMkTbaaYYEwFnMN5OTGjri40Z1bsTkpXlNtswvgVst MoOdmZEXG36o+ZRE+WqHONqzx4k6mGp3n2//xiOzv8XY5MDatiwC3hewnppiYdaqFGDw RmQvqwGYUDa3KU7hpWI+l9UlDCuRYVdFZ79+Gi6/GcdvLlHs7d/i0Gi7spY9mstb5+vd N7fQ== X-Gm-Message-State: AOAM530DgfW6mtFCiQW4njfzPDmMvWdLGejq2NW7B8EHIHYscYnLYYgn Gx6+4fa23pIpwF+bie8s55gWra+Qy728MA== X-Google-Smtp-Source: ABdhPJyag+d+VjQjGVRAfdSQwU+AsIM0JBoOHBYgAgRq6Kd1aEvnMMD2Ri8qZz8k6NBGkMDZq0QmBA== X-Received: by 2002:a05:651c:88d:: with SMTP id d13mr24698590ljq.505.1626798465226; Tue, 20 Jul 2021 09:27:45 -0700 (PDT) Received: from localhost.localdomain ([2a00:1fa0:44c8:ff00:875c:6e54:99e0:fb4a]) by smtp.gmail.com with ESMTPSA id d8sm1562660lfi.129.2021.07.20.09.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 09:27:44 -0700 (PDT) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Tue, 20 Jul 2021 19:26:49 +0300 Message-Id: <3fc0b9e1c18be73ceabe85e41818b0a4ee3e2102.1626797225.git.m.kokryashkin@tarantool.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 01/10] test: port lua-Harness to Test.Assertion X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Maxim Kokryashkin via Tarantool-patches Reply-To: Maxim Kokryashkin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Backports conversion to Test.Assertion patch[1] from lua-Harness suite As a result out of this change out-of-source testing is broken, but the previous assertion using package.path as a second argument worked fine. Because of that, this commit includes fix, that was made by this patch[2] in mainline lua-Harness. [1]: https://framagit.org/fperrad/lua-Harness/-/commit/074fefa51da1276078f735fa8fb568963fe541f1 [2]: https://framagit.org/fperrad/lua-Harness/-/commit/c4451fe06fcdc0d83a72dfa56eaae3ed26151c04 Part of tarantool/tarantool#5970 Part of tarantool/tarantool#4473 --- Additional comments on issue with out-of-source testing: https://github.com/tarantool/tarantool/issues/5970#issuecomment-880158605 test/lua-Harness-tests/090-tap.t | 8 +- test/lua-Harness-tests/091-profile.t | 10 +- test/lua-Harness-tests/101-boolean.t | 126 +-- test/lua-Harness-tests/102-function.t | 218 ++--- test/lua-Harness-tests/103-nil.t | 126 +-- test/lua-Harness-tests/104-number.t | 270 +++---- test/lua-Harness-tests/105-string.t | 308 ++++---- test/lua-Harness-tests/106-table.t | 132 ++-- test/lua-Harness-tests/107-thread.t | 128 +-- test/lua-Harness-tests/108-userdata.t | 124 +-- test/lua-Harness-tests/200-examples.t | 12 +- test/lua-Harness-tests/201-assign.t | 82 +- test/lua-Harness-tests/202-expr.t | 138 ++-- test/lua-Harness-tests/203-lexico.t | 66 +- test/lua-Harness-tests/204-grammar.t | 76 +- test/lua-Harness-tests/211-scope.t | 24 +- test/lua-Harness-tests/212-function.t | 138 ++-- test/lua-Harness-tests/213-closure.t | 32 +- test/lua-Harness-tests/214-coroutine.t | 96 +-- test/lua-Harness-tests/221-table.t | 54 +- test/lua-Harness-tests/222-constructor.t | 34 +- test/lua-Harness-tests/223-iterator.t | 18 +- test/lua-Harness-tests/231-metatable.t | 232 +++--- test/lua-Harness-tests/232-object.t | 38 +- .../241-standalone.t.disabled | 116 +-- test/lua-Harness-tests/242-luac.t | 80 +- test/lua-Harness-tests/301-basic.t | 748 +++++++++--------- test/lua-Harness-tests/303-package.t | 119 +-- test/lua-Harness-tests/304-string.t | 648 +++++++-------- test/lua-Harness-tests/305-utf8.t | 4 +- test/lua-Harness-tests/306-table.t | 186 ++--- test/lua-Harness-tests/307-math.t | 266 +++---- test/lua-Harness-tests/308-io.t | 248 +++--- test/lua-Harness-tests/309-os.t | 158 ++-- test/lua-Harness-tests/310-debug.t | 226 +++--- test/lua-Harness-tests/311-bit32.t | 70 +- test/lua-Harness-tests/314-regex.t | 8 +- test/lua-Harness-tests/320-stdin.t | 26 +- test/lua-Harness-tests/401-bitop.t | 60 +- test/lua-Harness-tests/402-ffi.t | 78 +- test/lua-Harness-tests/403-jit.t | 96 +-- test/lua-Harness-tests/404-ext.t | 162 ++-- test/lua-Harness-tests/411-luajit.t.disabled | 166 ++-- test/lua-Harness-tests/lexico52/lexico.t | 22 +- test/lua-Harness-tests/lexico53/boolean.t | 44 +- test/lua-Harness-tests/lexico53/function.t | 72 +- test/lua-Harness-tests/lexico53/lexico.t | 14 +- test/lua-Harness-tests/lexico53/nil.t | 44 +- test/lua-Harness-tests/lexico53/number.t | 224 +++--- test/lua-Harness-tests/lexico53/string.t | 196 ++--- test/lua-Harness-tests/lexico53/table.t | 44 +- test/lua-Harness-tests/lexico53/thread.t | 44 +- test/lua-Harness-tests/lexico53/userdata.t | 44 +- test/lua-Harness-tests/lexico53/utf8.t | 240 +++--- test/lua-Harness-tests/lexico54/lexico.t | 8 +- test/lua-Harness-tests/lexico54/metatable.t | 14 +- test/lua-Harness-tests/lexico54/utf8.t | 34 +- test/lua-Harness-tests/lexicojit/basic.t | 14 +- test/lua-Harness-tests/lexicojit/ext.t | 26 +- test/lua-Harness-tests/lexicojit/lexico.t | 30 +- test/lua-Harness-tests/tap.lua | 96 ++- 61 files changed, 3599 insertions(+), 3566 deletions(-) diff --git a/test/lua-Harness-tests/090-tap.t b/test/lua-Harness-tests/090-tap.t index 92f04d8e..47a9b613 100755 --- a/test/lua-Harness-tests/090-tap.t +++ b/test/lua-Harness-tests/090-tap.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2018, Perrad Francois +-- Copyright (C) 2018-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -25,9 +25,9 @@ require'tap' plan(3) -ok( true, 'ok' ) -is( 42, 42, '42 == 42' ) -pass( 'pass' ) +truthy( true, 'truthy' ) +equals( 42, 42, '42 == 42' ) +passes( 'pass' ) -- Local Variables: -- mode: lua diff --git a/test/lua-Harness-tests/091-profile.t b/test/lua-Harness-tests/091-profile.t index db474384..53220569 100755 --- a/test/lua-Harness-tests/091-profile.t +++ b/test/lua-Harness-tests/091-profile.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2018, Perrad Francois +-- Copyright (C) 2018-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -26,14 +26,14 @@ require'tap' plan'no_plan' -type_ok(_VERSION, 'string', "variable _VERSION") -like(_VERSION, '^Lua 5%.%d$') +is_string(_VERSION, "variable _VERSION") +matches(_VERSION, '^Lua 5%.%d$') if jit then - type_ok(jit.version_num, 'number', "variable jit.version_num") + is_number(jit.version_num, "variable jit.version_num") end -local profile = require_ok'profile' +require_ok'profile' done_testing() diff --git a/test/lua-Harness-tests/101-boolean.t b/test/lua-Harness-tests/101-boolean.t index c26b276e..95a3c0bd 100755 --- a/test/lua-Harness-tests/101-boolean.t +++ b/test/lua-Harness-tests/101-boolean.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -27,91 +27,91 @@ local has_op53 = _VERSION >= 'Lua 5.3' plan'no_plan' -error_like(function () return -true end, - "^[^:]+:%d+: attempt to perform arithmetic on a %w+ value", - "-true") +error_matches(function () return -true end, + "^[^:]+:%d+: attempt to perform arithmetic on a %w+ value", + "-true") -error_like(function () return #true end, - "^[^:]+:%d+: attempt to get length of a boolean value", - "#true") +error_matches(function () return #true end, + "^[^:]+:%d+: attempt to get length of a boolean value", + "#true") -is(not false, true, "not false") +equals(not false, true, "not false") -error_like(function () return true + 10 end, - "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", - "true + 10") +error_matches(function () return true + 10 end, + "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", + "true + 10") -error_like(function () return true - 2 end, - "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", - "true - 2") +error_matches(function () return true - 2 end, + "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", + "true - 2") -error_like(function () return true * 3.14 end, - "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", - "true * 3.14") +error_matches(function () return true * 3.14 end, + "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", + "true * 3.14") -error_like(function () return true / -7 end, - "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", - "true / -7") +error_matches(function () return true / -7 end, + "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", + "true / -7") -error_like(function () return true % 4 end, - "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", - "true % 4") +error_matches(function () return true % 4 end, + "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", + "true % 4") -error_like(function () return true ^ 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", - "true ^ 3") +error_matches(function () return true ^ 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", + "true ^ 3") -error_like(function () return true .. 'end' end, - "^[^:]+:%d+: attempt to concatenate a boolean value", - "true .. 'end'") +error_matches(function () return true .. 'end' end, + "^[^:]+:%d+: attempt to concatenate a boolean value", + "true .. 'end'") -is(true == true, true, "true == true") +equals(true == true, true, "true == true") -is(true ~= false, true, "true ~= false") +equals(true ~= false, true, "true ~= false") -is(true == 1, false, "true == 1") +equals(true == 1, false, "true == 1") -is(true ~= 1, true, "true ~= 1") +equals(true ~= 1, true, "true ~= 1") -error_like(function () return true < false end, - "^[^:]+:%d+: attempt to compare two boolean values", - "true < false") +error_matches(function () return true < false end, + "^[^:]+:%d+: attempt to compare two boolean values", + "true < false") -error_like(function () return true <= false end, - "^[^:]+:%d+: attempt to compare two boolean values", - "true <= false") +error_matches(function () return true <= false end, + "^[^:]+:%d+: attempt to compare two boolean values", + "true <= false") -error_like(function () return true > false end, - "^[^:]+:%d+: attempt to compare two boolean values", - "true > false") +error_matches(function () return true > false end, + "^[^:]+:%d+: attempt to compare two boolean values", + "true > false") -error_like(function () return true >= false end, - "^[^:]+:%d+: attempt to compare two boolean values", - "true >= false") +error_matches(function () return true >= false end, + "^[^:]+:%d+: attempt to compare two boolean values", + "true >= false") -error_like(function () return true < 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "true < 0") +error_matches(function () return true < 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "true < 0") -error_like(function () return true <= 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "true <= 0") +error_matches(function () return true <= 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "true <= 0") -error_like(function () return true > 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "true > 0") +error_matches(function () return true > 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "true > 0") -error_like(function () return true >= 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "true >= 0") +error_matches(function () return true >= 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "true >= 0") -error_like(function () local a = true; local b = a[1]; end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () local a = true; local b = a[1]; end, + "^[^:]+:%d+: attempt to index", + "index") -error_like(function () local a = true; a[1] = 1; end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () local a = true; a[1] = 1; end, + "^[^:]+:%d+: attempt to index", + "index") if has_op53 then make_specific_checks'lexico53/boolean.t' diff --git a/test/lua-Harness-tests/102-function.t b/test/lua-Harness-tests/102-function.t index c49afc5e..26ced043 100755 --- a/test/lua-Harness-tests/102-function.t +++ b/test/lua-Harness-tests/102-function.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -29,168 +29,168 @@ plan'no_plan' local f = function () return 1 end -error_like(function () return -f end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "-f") +error_matches(function () return -f end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "-f") -error_like(function () f = print; return -f end, - "^[^:]+:%d+: attempt to perform arithmetic on") +error_matches(function () f = print; return -f end, + "^[^:]+:%d+: attempt to perform arithmetic on") -error_like(function () return #f end, - "^[^:]+:%d+: attempt to get length of", - "#f") +error_matches(function () return #f end, + "^[^:]+:%d+: attempt to get length of", + "#f") -error_like(function () f = print; return #f end, - "^[^:]+:%d+: attempt to get length of") +error_matches(function () f = print; return #f end, + "^[^:]+:%d+: attempt to get length of") -is(not f, false, "not f") +equals(not f, false, "not f") -is(not print, false) +equals(not print, false) -error_like(function () return f + 10 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "f + 10") +error_matches(function () return f + 10 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "f + 10") -error_like(function () f = print; return f + 10 end, - "^[^:]+:%d+: attempt to perform arithmetic on") +error_matches(function () f = print; return f + 10 end, + "^[^:]+:%d+: attempt to perform arithmetic on") -error_like(function () return f - 2 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "f - 2") +error_matches(function () return f - 2 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "f - 2") -error_like(function () f = print; return f - 2 end, - "^[^:]+:%d+: attempt to perform arithmetic on") +error_matches(function () f = print; return f - 2 end, + "^[^:]+:%d+: attempt to perform arithmetic on") -error_like(function () return f * 3.14 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "f * 3.14") +error_matches(function () return f * 3.14 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "f * 3.14") -error_like(function () f = print; return f * 3.14 end, - "^[^:]+:%d+: attempt to perform arithmetic on") +error_matches(function () f = print; return f * 3.14 end, + "^[^:]+:%d+: attempt to perform arithmetic on") -error_like(function () return f / -7 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "f / -7") +error_matches(function () return f / -7 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "f / -7") -error_like(function () f = print; return f / -7 end, - "^[^:]+:%d+: attempt to perform arithmetic on") +error_matches(function () f = print; return f / -7 end, + "^[^:]+:%d+: attempt to perform arithmetic on") -error_like(function () return f % 4 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "f % 4") +error_matches(function () return f % 4 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "f % 4") -error_like(function () f = print; return f % 4 end, - "^[^:]+:%d+: attempt to perform arithmetic on") +error_matches(function () f = print; return f % 4 end, + "^[^:]+:%d+: attempt to perform arithmetic on") -error_like(function () return f ^ 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "f ^ 3") +error_matches(function () return f ^ 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "f ^ 3") -error_like(function () f = print; return f ^ 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on") +error_matches(function () f = print; return f ^ 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on") -error_like(function () return f .. 'end' end, - "^[^:]+:%d+: attempt to concatenate", - "f .. 'end'") +error_matches(function () return f .. 'end' end, + "^[^:]+:%d+: attempt to concatenate", + "f .. 'end'") -error_like(function () f = print; return f .. 'end' end, - "^[^:]+:%d+: attempt to concatenate") +error_matches(function () f = print; return f .. 'end' end, + "^[^:]+:%d+: attempt to concatenate") local g = f -is(f == g, true, "f == f") +equals(f == g, true, "f == f") g = print -is(g == print, true) +equals(g == print, true) g = function () return 2 end -is(f ~= g, true, "f ~= g") +equals(f ~= g, true, "f ~= g") local h = type -is(f ~= h, true) +equals(f ~= h, true) -is(print ~= g, true) -is(print ~= h, true) +equals(print ~= g, true) +equals(print ~= h, true) -is(f == 1, false, "f == 1") +equals(f == 1, false, "f == 1") -is(print == 1, false) +equals(print == 1, false) -is(f ~= 1, true, "f ~= 1") +equals(f ~= 1, true, "f ~= 1") -is(print ~= 1, true) +equals(print ~= 1, true) -error_like(function () return f < g end, - "^[^:]+:%d+: attempt to compare two function values", - "f < g") +error_matches(function () return f < g end, + "^[^:]+:%d+: attempt to compare two function values", + "f < g") -error_like(function () f = print; g = type; return f < g end, - "^[^:]+:%d+: attempt to compare two function values") +error_matches(function () f = print; g = type; return f < g end, + "^[^:]+:%d+: attempt to compare two function values") -error_like(function () return f <= g end, - "^[^:]+:%d+: attempt to compare two function values", - "f <= g") +error_matches(function () return f <= g end, + "^[^:]+:%d+: attempt to compare two function values", + "f <= g") -error_like(function () f = print; g = type; return f <= g end, - "^[^:]+:%d+: attempt to compare two function values") +error_matches(function () f = print; g = type; return f <= g end, + "^[^:]+:%d+: attempt to compare two function values") -error_like(function () return f > g end, - "^[^:]+:%d+: attempt to compare two function values", - "f > g") +error_matches(function () return f > g end, + "^[^:]+:%d+: attempt to compare two function values", + "f > g") -error_like(function () f = print; g = type; return f > g end, - "^[^:]+:%d+: attempt to compare two function values") +error_matches(function () f = print; g = type; return f > g end, + "^[^:]+:%d+: attempt to compare two function values") -error_like(function () return f >= g end, - "^[^:]+:%d+: attempt to compare two function values", - "f >= g") +error_matches(function () return f >= g end, + "^[^:]+:%d+: attempt to compare two function values", + "f >= g") -error_like(function () f = print; g = type; return f >= g end, - "^[^:]+:%d+: attempt to compare two function values") +error_matches(function () f = print; g = type; return f >= g end, + "^[^:]+:%d+: attempt to compare two function values") -error_like(function () return f < 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "f < 0") +error_matches(function () return f < 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "f < 0") -error_like(function () f = print; return f < 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+") +error_matches(function () f = print; return f < 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+") -error_like(function () return f <= 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "f <= 0") +error_matches(function () return f <= 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "f <= 0") -error_like(function () f = print; return f <= 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+") +error_matches(function () f = print; return f <= 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+") -error_like(function () return f > 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "f > 0") +error_matches(function () return f > 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "f > 0") -error_like(function () f = print; return f > 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+") +error_matches(function () f = print; return f > 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+") -error_like(function () return f > 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "f >= 0") +error_matches(function () return f > 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "f >= 0") -error_like(function () f = print; return f >= 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+") +error_matches(function () f = print; return f >= 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+") -error_like(function () local a = f; local b = a[1]; end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () local a = f; local b = a[1]; end, + "^[^:]+:%d+: attempt to index", + "index") -error_like(function () local a = print; local b = a[1]; end, - "^[^:]+:%d+: attempt to index") +error_matches(function () local a = print; local b = a[1]; end, + "^[^:]+:%d+: attempt to index") -error_like(function () local a = f; a[1] = 1; end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () local a = f; a[1] = 1; end, + "^[^:]+:%d+: attempt to index", + "index") -error_like(function () local a = print; a[1] = 1; end, - "^[^:]+:%d+: attempt to index") +error_matches(function () local a = print; a[1] = 1; end, + "^[^:]+:%d+: attempt to index") local t = {} t[print] = true -ok(t[print]) +truthy(t[print]) if has_op53 then make_specific_checks'lexico53/function.t' diff --git a/test/lua-Harness-tests/103-nil.t b/test/lua-Harness-tests/103-nil.t index 87a1c3b1..90a3b4f3 100755 --- a/test/lua-Harness-tests/103-nil.t +++ b/test/lua-Harness-tests/103-nil.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -27,91 +27,91 @@ local has_op53 = _VERSION >= 'Lua 5.3' plan'no_plan' -error_like(function () return -nil end, - "^[^:]+:%d+: attempt to perform arithmetic on a nil value", - "-nil") +error_matches(function () return -nil end, + "^[^:]+:%d+: attempt to perform arithmetic on a nil value", + "-nil") -error_like(function () return #nil end, - "^[^:]+:%d+: attempt to get length of a nil value", - "#nil") +error_matches(function () return #nil end, + "^[^:]+:%d+: attempt to get length of a nil value", + "#nil") -is(not nil, true, "not nil") +equals(not nil, true, "not nil") -error_like(function () return nil + 10 end, - "^[^:]+:%d+: attempt to perform arithmetic on a nil value", - "nil + 10") +error_matches(function () return nil + 10 end, + "^[^:]+:%d+: attempt to perform arithmetic on a nil value", + "nil + 10") -error_like(function () return nil - 2 end, - "^[^:]+:%d+: attempt to perform arithmetic on a nil value", - "nil - 2") +error_matches(function () return nil - 2 end, + "^[^:]+:%d+: attempt to perform arithmetic on a nil value", + "nil - 2") -error_like(function () return nil * 3.14 end, - "^[^:]+:%d+: attempt to perform arithmetic on a nil value", - "nil * 3.14") +error_matches(function () return nil * 3.14 end, + "^[^:]+:%d+: attempt to perform arithmetic on a nil value", + "nil * 3.14") -error_like(function () return nil / -7 end, - "^[^:]+:%d+: attempt to perform arithmetic on a nil value", - "nil / -7") +error_matches(function () return nil / -7 end, + "^[^:]+:%d+: attempt to perform arithmetic on a nil value", + "nil / -7") -error_like(function () return nil % 4 end, - "^[^:]+:%d+: attempt to perform arithmetic on a nil value", - "nil % 4") +error_matches(function () return nil % 4 end, + "^[^:]+:%d+: attempt to perform arithmetic on a nil value", + "nil % 4") -error_like(function () return nil ^ 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on a nil value", - "nil ^ 3") +error_matches(function () return nil ^ 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on a nil value", + "nil ^ 3") -error_like(function () return nil .. 'end' end, - "^[^:]+:%d+: attempt to concatenate a nil value", - "nil .. 'end'") +error_matches(function () return nil .. 'end' end, + "^[^:]+:%d+: attempt to concatenate a nil value", + "nil .. 'end'") -is(nil == nil, true, "nil == nil") +equals(nil == nil, true, "nil == nil") -is(nil ~= nil, false, "nil ~= nil") +equals(nil ~= nil, false, "nil ~= nil") -is(nil == 1, false, "nil == 1") +equals(nil == 1, false, "nil == 1") -is(nil ~= 1, true, "nil ~= 1") +equals(nil ~= 1, true, "nil ~= 1") -error_like(function () return nil < nil end, - "^[^:]+:%d+: attempt to compare two nil values", - "nil < nil") +error_matches(function () return nil < nil end, + "^[^:]+:%d+: attempt to compare two nil values", + "nil < nil") -error_like(function () return nil <= nil end, - "^[^:]+:%d+: attempt to compare two nil values", - "nil <= nil") +error_matches(function () return nil <= nil end, + "^[^:]+:%d+: attempt to compare two nil values", + "nil <= nil") -error_like(function () return nil > nil end, - "^[^:]+:%d+: attempt to compare two nil values", - "nil > nil") +error_matches(function () return nil > nil end, + "^[^:]+:%d+: attempt to compare two nil values", + "nil > nil") -error_like(function () return nil > nil end, - "^[^:]+:%d+: attempt to compare two nil values", - "nil >= nil") +error_matches(function () return nil > nil end, + "^[^:]+:%d+: attempt to compare two nil values", + "nil >= nil") -error_like(function () return nil < 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "nil < 0") +error_matches(function () return nil < 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "nil < 0") -error_like(function () return nil <= 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "nil <= 0") +error_matches(function () return nil <= 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "nil <= 0") -error_like(function () return nil > 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "nil > 0") +error_matches(function () return nil > 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "nil > 0") -error_like(function () return nil >= 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "nil >= 0") +error_matches(function () return nil >= 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "nil >= 0") -error_like(function () local a = nil; local b = a[1]; end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () local a = nil; local b = a[1]; end, + "^[^:]+:%d+: attempt to index", + "index") -error_like(function () local a = nil; a[1] = 1; end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () local a = nil; a[1] = 1; end, + "^[^:]+:%d+: attempt to index", + "index") if has_op53 then make_specific_checks'lexico53/nil.t' diff --git a/test/lua-Harness-tests/104-number.t b/test/lua-Harness-tests/104-number.t index f5b81e3d..a41c5951 100755 --- a/test/lua-Harness-tests/104-number.t +++ b/test/lua-Harness-tests/104-number.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2019, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -28,209 +28,209 @@ local has_op53 = _VERSION >= 'Lua 5.3' plan'no_plan' -is(-1, -(1), "-1") +equals(-1, -(1), "-1") -is(not 1, false, "not 1") +equals(not 1, false, "not 1") -is(10 + 2, 12, "10 + 2") +equals(10 + 2, 12, "10 + 2") -is(2 - 10.5, -8.5, "2 - 10.5") +equals(2 - 10.5, -8.5, "2 - 10.5") -is(2 * 3, 6, "2 * 3") +equals(2 * 3, 6, "2 * 3") -is(3.14 * 1, 3.14, "3.14 * 1") +equals(3.14 * 1, 3.14, "3.14 * 1") -is(-7 / 0.5, -14, "-7 / 0.5") +equals(-7 / 0.5, -14, "-7 / 0.5") -type_ok(1.0 / 0.0, 'number', "1.0 / 0.0") +is_number(1.0 / 0.0, "1.0 / 0.0") -is(-25 % 3, 2, "-25 % 3") +equals(-25 % 3, 2, "-25 % 3") if _VERSION >= 'Lua 5.3' then - error_like(function () return 1 % 0 end, - "^[^:]+:%d+: attempt to perform 'n%%0'", - "1 % 0") + error_matches(function () return 1 % 0 end, + "^[^:]+:%d+: attempt to perform 'n%%0'", + "1 % 0") else - type_ok(1 % 0, 'number', "1 % 0") + is_number(1 % 0, "1 % 0") end -error_like(function () return 10 + true end, - "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", - "10 + true") +error_matches(function () return 10 + true end, + "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", + "10 + true") -error_like(function () return 2 - nil end, - "^[^:]+:%d+: attempt to perform arithmetic on a nil value", - "2 - nil") +error_matches(function () return 2 - nil end, + "^[^:]+:%d+: attempt to perform arithmetic on a nil value", + "2 - nil") -error_like(function () return 2 * {} end, - "^[^:]+:%d+: attempt to perform arithmetic on a table value", - "2 * {}") +error_matches(function () return 2 * {} end, + "^[^:]+:%d+: attempt to perform arithmetic on a table value", + "2 * {}") -error_like(function () return 3.14 * false end, - "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", - "3.14 * false") +error_matches(function () return 3.14 * false end, + "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", + "3.14 * false") -error_like(function () return -7 / {} end, - "^[^:]+:%d+: attempt to perform arithmetic on a table value", - "-7 / {}") +error_matches(function () return -7 / {} end, + "^[^:]+:%d+: attempt to perform arithmetic on a table value", + "-7 / {}") -error_like(function () return 3 ^ true end, - "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", - "3 ^ true") +error_matches(function () return 3 ^ true end, + "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", + "3 ^ true") -error_like(function () return -25 % false end, - "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", - "-25 % false") +error_matches(function () return -25 % false end, + "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", + "-25 % false") -error_like(function () return 10 + 'text' end, - "^[^:]+:%d+: attempt to", - "10 + 'text'") +error_matches(function () return 10 + 'text' end, + "^[^:]+:%d+: attempt to", + "10 + 'text'") -error_like(function () return 2 - 'text' end, - "^[^:]+:%d+: attempt to", - "2 - 'text'") +error_matches(function () return 2 - 'text' end, + "^[^:]+:%d+: attempt to", + "2 - 'text'") -error_like(function () return 2 * 'text' end, - "^[^:]+:%d+: attempt to", - "2 * 'text'") +error_matches(function () return 2 * 'text' end, + "^[^:]+:%d+: attempt to", + "2 * 'text'") -error_like(function () return 3.14 * 'text' end, - "^[^:]+:%d+: attempt to", - "3.14 * 'text'") +error_matches(function () return 3.14 * 'text' end, + "^[^:]+:%d+: attempt to", + "3.14 * 'text'") -error_like(function () return -7 / 'text' end, - "^[^:]+:%d+: attempt to", - "-7 / 'text'") +error_matches(function () return -7 / 'text' end, + "^[^:]+:%d+: attempt to", + "-7 / 'text'") -error_like(function () return 25 % 'text' end, - "^[^:]+:%d+: attempt to", - "25 % 'text'") +error_matches(function () return 25 % 'text' end, + "^[^:]+:%d+: attempt to", + "25 % 'text'") -error_like(function () return 3 ^ 'text' end, - "^[^:]+:%d+: attempt to", - "3 ^ 'text'") +error_matches(function () return 3 ^ 'text' end, + "^[^:]+:%d+: attempt to", + "3 ^ 'text'") if profile.nocvts2n then - error_like(function () return 10 + '2' end, - "^[^:]+:%d+: attempt to", - "10 + '2'") + error_matches(function () return 10 + '2' end, + "^[^:]+:%d+: attempt to", + "10 + '2'") - error_like(function () return 2 - '10.5' end, - "^[^:]+:%d+: attempt to", - "2 - '10.5'") + error_matches(function () return 2 - '10.5' end, + "^[^:]+:%d+: attempt to", + "2 - '10.5'") - error_like(function () return 2 * '3' end, - "^[^:]+:%d+: attempt to", - "2 * '3'") + error_matches(function () return 2 * '3' end, + "^[^:]+:%d+: attempt to", + "2 * '3'") - error_like(function () return 3.14 * '1' end, - "^[^:]+:%d+: attempt to", - "3.14 * '1'") + error_matches(function () return 3.14 * '1' end, + "^[^:]+:%d+: attempt to", + "3.14 * '1'") - error_like(function () return -7 / '0.5' end, - "^[^:]+:%d+: attempt to", - "-7 / '0.5'") + error_matches(function () return -7 / '0.5' end, + "^[^:]+:%d+: attempt to", + "-7 / '0.5'") - error_like(function () return -25 % '3' end, - "^[^:]+:%d+: attempt to", - "-25 % '3'") + error_matches(function () return -25 % '3' end, + "^[^:]+:%d+: attempt to", + "-25 % '3'") - error_like(function () return 3 ^ '3' end, - "^[^:]+:%d+: attempt to", - "3 ^ '3'") + error_matches(function () return 3 ^ '3' end, + "^[^:]+:%d+: attempt to", + "3 ^ '3'") else - is(10 + '2', 12, "10 + '2'") + equals(10 + '2', 12, "10 + '2'") - is(2 - '10.5', -8.5, "2 - '10.5'") + equals(2 - '10.5', -8.5, "2 - '10.5'") - is(2 * '3', 6, "2 * '3'") + equals(2 * '3', 6, "2 * '3'") - is(3.14 * '1', 3.14, "3.14 * '1'") + equals(3.14 * '1', 3.14, "3.14 * '1'") - is(-7 / '0.5', -14, "-7 / '0.5'") + equals(-7 / '0.5', -14, "-7 / '0.5'") - is(-25 % '3', 2, "-25 % '3'") + equals(-25 % '3', 2, "-25 % '3'") - is(3 ^ '3', 27, "3 ^ '3'") + equals(3 ^ '3', 27, "3 ^ '3'") end if profile.nocvtn2s then - error_like(function () return 1 .. 'end' end, - "^[^:]+:%d+: attempt to concatenate a number value", - "1 .. 'end'") + error_matches(function () return 1 .. 'end' end, + "^[^:]+:%d+: attempt to concatenate a number value", + "1 .. 'end'") - error_like(function () return 1 .. 2 end, - "^[^:]+:%d+: attempt to concatenate a number value", - "1 .. 2") + error_matches(function () return 1 .. 2 end, + "^[^:]+:%d+: attempt to concatenate a number value", + "1 .. 2") else - is(1 .. 'end', '1end', "1 .. 'end'") + equals(1 .. 'end', '1end', "1 .. 'end'") - is(1 .. 2, '12', "1 .. 2") + equals(1 .. 2, '12', "1 .. 2") end -error_like(function () return 1 .. true end, - "^[^:]+:%d+: attempt to concatenate a %w+ value", - "1 .. true") +error_matches(function () return 1 .. true end, + "^[^:]+:%d+: attempt to concatenate a %w+ value", + "1 .. true") -is(1.0 == 1, true, "1.0 == 1") +equals(1.0 == 1, true, "1.0 == 1") -is(1 ~= 2, true, "1 ~= 2") +equals(1 ~= 2, true, "1 ~= 2") -is(1 == true, false, "1 == true") +equals(1 == true, false, "1 == true") -is(1 ~= nil, true, "1 ~= nil") +equals(1 ~= nil, true, "1 ~= nil") -is(1 == '1', false, "1 == '1'") +equals(1 == '1', false, "1 == '1'") -is(1 ~= '1', true, "1 ~= '1'") +equals(1 ~= '1', true, "1 ~= '1'") -is(1 < 0, false, "1 < 0") +equals(1 < 0, false, "1 < 0") -is(1 <= 0, false, "1 <= 0") +equals(1 <= 0, false, "1 <= 0") -is(1 > 0, true, "1 > 0") +equals(1 > 0, true, "1 > 0") -is(1 >= 0, true, "1 >= 0") +equals(1 >= 0, true, "1 >= 0") -error_like(function () return 1 < false end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "1 < false") +error_matches(function () return 1 < false end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "1 < false") -error_like(function () return 1 <= nil end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "1 <= nil") +error_matches(function () return 1 <= nil end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "1 <= nil") -error_like(function () return 1 > true end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "1 > true") +error_matches(function () return 1 > true end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "1 > true") -error_like(function () return 1 >= {} end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "1 >= {}") +error_matches(function () return 1 >= {} end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "1 >= {}") -error_like(function () return 1 < '0' end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "1 < '0'") +error_matches(function () return 1 < '0' end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "1 < '0'") -error_like(function () return 1 <= '0' end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "1 <= '0'") +error_matches(function () return 1 <= '0' end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "1 <= '0'") -error_like(function () return 1 > '0' end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "1 > '0'") +error_matches(function () return 1 > '0' end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "1 > '0'") -error_like(function () return 1 >= '0' end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "1 >= '0'") +error_matches(function () return 1 >= '0' end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "1 >= '0'") -error_like(function () local a= 3.14; local b = a[1]; end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () local a= 3.14; local b = a[1]; end, + "^[^:]+:%d+: attempt to index", + "index") -error_like(function () local a = 3.14; a[1] = 1; end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () local a = 3.14; a[1] = 1; end, + "^[^:]+:%d+: attempt to index", + "index") if has_op53 then make_specific_checks'lexico53/number.t' diff --git a/test/lua-Harness-tests/105-string.t b/test/lua-Harness-tests/105-string.t index 184deaba..af8c90b7 100755 --- a/test/lua-Harness-tests/105-string.t +++ b/test/lua-Harness-tests/105-string.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2019, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -29,239 +29,239 @@ local has_op53 = _VERSION >= 'Lua 5.3' plan'no_plan' if profile.nocvts2n then - error_like(function () return - '1' end, - "^[^:]+:%d+: attempt to", - "-'1'") + error_matches(function () return - '1' end, + "^[^:]+:%d+: attempt to", + "-'1'") else - is(- '1', -1, "-'1'") + equals(- '1', -1, "-'1'") end -error_like(function () return - 'text' end, - "^[^:]+:%d+: attempt to", - "-'text'") +error_matches(function () return - 'text' end, + "^[^:]+:%d+: attempt to", + "-'text'") -is(# 'text', 4, "#'text'") +equals(# 'text', 4, "#'text'") -is(not 'text', false, "not 'text'") +equals(not 'text', false, "not 'text'") if profile.nocvts2n then - error_like(function () return '10' + 2 end, - "^[^:]+:%d+: attempt to", - "'10' + 2") + error_matches(function () return '10' + 2 end, + "^[^:]+:%d+: attempt to", + "'10' + 2") - error_like(function () return '2' - 10.5 end, - "^[^:]+:%d+: attempt to", - "'2' - 10.5") + error_matches(function () return '2' - 10.5 end, + "^[^:]+:%d+: attempt to", + "'2' - 10.5") - error_like(function () return '2' * 3 end, - "^[^:]+:%d+: attempt to", - "'2' * 3") + error_matches(function () return '2' * 3 end, + "^[^:]+:%d+: attempt to", + "'2' * 3") - error_like(function () return '3.14' * 1 end, - "^[^:]+:%d+: attempt to", - "'3.14' * 1") + error_matches(function () return '3.14' * 1 end, + "^[^:]+:%d+: attempt to", + "'3.14' * 1") - error_like(function () return '-7' / 0.5 end, - "^[^:]+:%d+: attempt to", - "'-7' / 0.5") + error_matches(function () return '-7' / 0.5 end, + "^[^:]+:%d+: attempt to", + "'-7' / 0.5") - error_like(function () return '-25' % 3 end, - "^[^:]+:%d+: attempt to", - "'-25' % 3") + error_matches(function () return '-25' % 3 end, + "^[^:]+:%d+: attempt to", + "'-25' % 3") - error_like(function () return '3' ^ 3 end, - "^[^:]+:%d+: attempt to", - "'3' ^ 3") + error_matches(function () return '3' ^ 3 end, + "^[^:]+:%d+: attempt to", + "'3' ^ 3") else - is('10' + 2, 12, "'10' + 2") + equals('10' + 2, 12, "'10' + 2") - is('2' - 10.5, -8.5, "'2' - 10.5") + equals('2' - 10.5, -8.5, "'2' - 10.5") - is('2' * 3, 6, "'2' * 3") + equals('2' * 3, 6, "'2' * 3") - is('3.14' * 1, 3.14, "'3.14' * 1") + equals('3.14' * 1, 3.14, "'3.14' * 1") - is('-7' / 0.5, -14, "'-7' / 0.5") + equals('-7' / 0.5, -14, "'-7' / 0.5") - is('-25' % 3, 2, "'-25' % 3") + equals('-25' % 3, 2, "'-25' % 3") - is('3' ^ 3, 27, "'3' ^ 3") + equals('3' ^ 3, 27, "'3' ^ 3") end -error_like(function () return '10' + true end, - "^[^:]+:%d+: attempt to", - "'10' + true") +error_matches(function () return '10' + true end, + "^[^:]+:%d+: attempt to", + "'10' + true") -error_like(function () return '2' - nil end, - "^[^:]+:%d+: attempt to", - "'2' - nil") +error_matches(function () return '2' - nil end, + "^[^:]+:%d+: attempt to", + "'2' - nil") -error_like(function () return '2' * {} end, - "^[^:]+:%d+: attempt to", - "'2' * {}") +error_matches(function () return '2' * {} end, + "^[^:]+:%d+: attempt to", + "'2' * {}") -error_like(function () return '3.14' * false end, - "^[^:]+:%d+: attempt to", - "'3.14' * false") +error_matches(function () return '3.14' * false end, + "^[^:]+:%d+: attempt to", + "'3.14' * false") -error_like(function () return '-7' / {} end, - "^[^:]+:%d+: attempt to", - "'-7' / {}") +error_matches(function () return '-7' / {} end, + "^[^:]+:%d+: attempt to", + "'-7' / {}") -error_like(function () return '-25' % false end, - "^[^:]+:%d+: attempt to", - "'-25' % false") +error_matches(function () return '-25' % false end, + "^[^:]+:%d+: attempt to", + "'-25' % false") -error_like(function () return '3' ^ true end, - "^[^:]+:%d+: attempt to", - "'3' ^ true") +error_matches(function () return '3' ^ true end, + "^[^:]+:%d+: attempt to", + "'3' ^ true") -error_like(function () return '10' + 'text' end, - "^[^:]+:%d+: attempt to", - "'10' + 'text'") +error_matches(function () return '10' + 'text' end, + "^[^:]+:%d+: attempt to", + "'10' + 'text'") -error_like(function () return '2' - 'text' end, - "^[^:]+:%d+: attempt to", - "'2' - 'text'") +error_matches(function () return '2' - 'text' end, + "^[^:]+:%d+: attempt to", + "'2' - 'text'") -error_like(function () return '3.14' * 'text' end, - "^[^:]+:%d+: attempt to", - "'3.14' * 'text'") +error_matches(function () return '3.14' * 'text' end, + "^[^:]+:%d+: attempt to", + "'3.14' * 'text'") -error_like(function () return '-7' / 'text' end, - "^[^:]+:%d+: attempt to", - "'-7' / 'text'") +error_matches(function () return '-7' / 'text' end, + "^[^:]+:%d+: attempt to", + "'-7' / 'text'") -error_like(function () return '-25' % 'text' end, - "^[^:]+:%d+: attempt to", - "'-25' % 'text'") +error_matches(function () return '-25' % 'text' end, + "^[^:]+:%d+: attempt to", + "'-25' % 'text'") -error_like(function () return '3' ^ 'text' end, - "^[^:]+:%d+: attempt to", - "'3' ^ 'text'") +error_matches(function () return '3' ^ 'text' end, + "^[^:]+:%d+: attempt to", + "'3' ^ 'text'") if profile.nocvts2n then - error_like(function () return '10' + '2' end, - "^[^:]+:%d+: attempt to", - "'10' + '2'") + error_matches(function () return '10' + '2' end, + "^[^:]+:%d+: attempt to", + "'10' + '2'") - error_like(function () return '2' - '10.5' end, - "^[^:]+:%d+: attempt to", - "'2' - '10.5'") + error_matches(function () return '2' - '10.5' end, + "^[^:]+:%d+: attempt to", + "'2' - '10.5'") - error_like(function () return '2' * '3' end, - "^[^:]+:%d+: attempt to", - "'2' * '3'") + error_matches(function () return '2' * '3' end, + "^[^:]+:%d+: attempt to", + "'2' * '3'") - error_like(function () return '3.14' * '1' end, - "^[^:]+:%d+: attempt to", - "'3.14' * '1'") + error_matches(function () return '3.14' * '1' end, + "^[^:]+:%d+: attempt to", + "'3.14' * '1'") - error_like(function () return '-7' / '0.5' end, - "^[^:]+:%d+: attempt to", - "'-7' / '0.5'") + error_matches(function () return '-7' / '0.5' end, + "^[^:]+:%d+: attempt to", + "'-7' / '0.5'") - error_like(function () return '-25' % '3' end, - "^[^:]+:%d+: attempt to", - "'-25' % '3'") + error_matches(function () return '-25' % '3' end, + "^[^:]+:%d+: attempt to", + "'-25' % '3'") - error_like(function () return '3' ^ '3' end, - "^[^:]+:%d+: attempt to", - "'3' ^ '3'") + error_matches(function () return '3' ^ '3' end, + "^[^:]+:%d+: attempt to", + "'3' ^ '3'") else - is('10' + '2', 12, "'10' + '2'") + equals('10' + '2', 12, "'10' + '2'") - is('2' - '10.5', -8.5, "'2' - '10.5'") + equals('2' - '10.5', -8.5, "'2' - '10.5'") - is('2' * '3', 6, "'2' * '3'") + equals('2' * '3', 6, "'2' * '3'") - is('3.14' * '1', 3.14, "'3.14' * '1'") + equals('3.14' * '1', 3.14, "'3.14' * '1'") - is('-7' / '0.5', -14, "'-7' / '0.5'") + equals('-7' / '0.5', -14, "'-7' / '0.5'") - is('-25' % '3', 2, "'-25' % '3'") + equals('-25' % '3', 2, "'-25' % '3'") - is('3' ^ '3', 27, "'3' ^ '3'") + equals('3' ^ '3', 27, "'3' ^ '3'") end -is('1' .. 'end', '1end', "'1' .. 'end'") +equals('1' .. 'end', '1end', "'1' .. 'end'") if profile.nocvtn2s then - error_like(function () return '1' .. 2 end, - "^[^:]+:%d+: attempt to concatenate a number value", - "'1' .. 2") + error_matches(function () return '1' .. 2 end, + "^[^:]+:%d+: attempt to concatenate a number value", + "'1' .. 2") else - is('1' .. 2, '12', "'1' .. 2") + equals('1' .. 2, '12', "'1' .. 2") end -error_like(function () return '1' .. true end, - "^[^:]+:%d+: attempt to concatenate a boolean value", - "'1' .. true") +error_matches(function () return '1' .. true end, + "^[^:]+:%d+: attempt to concatenate a boolean value", + "'1' .. true") -is('foo\0bar' <= 'foo\0baz', true, "'foo\\0bar' <= 'foo\\0baz'") +equals('foo\0bar' <= 'foo\0baz', true, "'foo\\0bar' <= 'foo\\0baz'") -is('foo\0bar' ~= 'foo', true, "'foo\\0bar' ~= 'foo'") +equals('foo\0bar' ~= 'foo', true, "'foo\\0bar' ~= 'foo'") -is('foo\0bar' >= 'foo', true, "'foo\\0bar' >= 'foo'") +equals('foo\0bar' >= 'foo', true, "'foo\\0bar' >= 'foo'") -is('1.0' == '1', false, "'1.0' == '1'") +equals('1.0' == '1', false, "'1.0' == '1'") -is('1' ~= '2', true, "'1' ~= '2'") +equals('1' ~= '2', true, "'1' ~= '2'") -is('1' == true, false, "'1' == true") +equals('1' == true, false, "'1' == true") -is('1' ~= nil, true, "'1' ~= nil") +equals('1' ~= nil, true, "'1' ~= nil") -is('1' == 1, false, "'1' == 1") +equals('1' == 1, false, "'1' == 1") -is('1' ~= 1, true, "'1' ~= 1") +equals('1' ~= 1, true, "'1' ~= 1") -is('1' < '0', false, "'1' < '0'") +equals('1' < '0', false, "'1' < '0'") -is('1' <= '0', false, "'1' <= '0'") +equals('1' <= '0', false, "'1' <= '0'") -is('1' > '0', true, "'1' > '0'") +equals('1' > '0', true, "'1' > '0'") -is('1' >= '0', true, "'1' >= '0'") +equals('1' >= '0', true, "'1' >= '0'") -error_like(function () return '1' < false end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "'1' < false") +error_matches(function () return '1' < false end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "'1' < false") -error_like(function () return '1' <= nil end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "'1' <= nil") +error_matches(function () return '1' <= nil end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "'1' <= nil") -error_like(function () return '1' > true end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "'1' > true") +error_matches(function () return '1' > true end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "'1' > true") -error_like(function () return '1' >= {} end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "'1' >= {}") +error_matches(function () return '1' >= {} end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "'1' >= {}") -error_like(function () return '1' < 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "'1' < 0") +error_matches(function () return '1' < 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "'1' < 0") -error_like(function () return '1' <= 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "'1' <= 0") +error_matches(function () return '1' <= 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "'1' <= 0") -error_like(function () return '1' > 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "'1' > 0") +error_matches(function () return '1' > 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "'1' > 0") -error_like(function () return '1' > 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "'1' >== 0") +error_matches(function () return '1' > 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "'1' >== 0") local a = 'text' -is(a[1], nil, "index") +equals(a[1], nil, "index") -error_like(function () a = 'text'; a[1] = 1; end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () a = 'text'; a[1] = 1; end, + "^[^:]+:%d+: attempt to index", + "index") if has_op53 then make_specific_checks'lexico53/string.t' diff --git a/test/lua-Harness-tests/106-table.t b/test/lua-Harness-tests/106-table.t index 667b9c8d..03d45085 100755 --- a/test/lua-Harness-tests/106-table.t +++ b/test/lua-Harness-tests/106-table.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -27,99 +27,99 @@ local has_op53 = _VERSION >= 'Lua 5.3' plan'no_plan' -error_like(function () return -{} end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "-{}") +error_matches(function () return -{} end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "-{}") -is(# {}, 0, "#{}") -is(# {4,5,6}, 3) +equals(# {}, 0, "#{}") +equals(# {4,5,6}, 3) -is(not {}, false, "not {}") +equals(not {}, false, "not {}") -error_like(function () return {} + 10 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "{} + 10") +error_matches(function () return {} + 10 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "{} + 10") -error_like(function () return {} - 2 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "{} - 2") +error_matches(function () return {} - 2 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "{} - 2") -error_like(function () return {} * 3.14 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "{} * 3.14") +error_matches(function () return {} * 3.14 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "{} * 3.14") -error_like(function () return {} / 7 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "{} / 7") +error_matches(function () return {} / 7 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "{} / 7") -error_like(function () return {} % 4 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "{} % 4") +error_matches(function () return {} % 4 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "{} % 4") -error_like(function () return {} ^ 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "{} ^ 3") +error_matches(function () return {} ^ 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "{} ^ 3") -error_like(function () return {} .. 'end' end, - "^[^:]+:%d+: attempt to concatenate", - "{} .. 'end'") +error_matches(function () return {} .. 'end' end, + "^[^:]+:%d+: attempt to concatenate", + "{} .. 'end'") -is({} == {}, false, "{} == {}") +equals({} == {}, false, "{} == {}") local t1 = {} local t2 = {} -is(t1 == t1, true, "t1 == t1") -is(t1 == t2, false, "t1 == t2") -is(t1 ~= t2, true, "t1 ~= t2") +equals(t1 == t1, true, "t1 == t1") +equals(t1 == t2, false, "t1 == t2") +equals(t1 ~= t2, true, "t1 ~= t2") -is({} == 1, false, "{} == 1") +equals({} == 1, false, "{} == 1") -is({} ~= 1, true, "{} ~= 1") +equals({} ~= 1, true, "{} ~= 1") -error_like(function () return t1 < t2 end, - "^[^:]+:%d+: attempt to compare two table values", - "t1 < t2") +error_matches(function () return t1 < t2 end, + "^[^:]+:%d+: attempt to compare two table values", + "t1 < t2") -error_like(function () return t1 <= t2 end, - "^[^:]+:%d+: attempt to compare two table values", - "t1 <= t2") +error_matches(function () return t1 <= t2 end, + "^[^:]+:%d+: attempt to compare two table values", + "t1 <= t2") -error_like(function () return t1 > t2 end, - "^[^:]+:%d+: attempt to compare two table values", - "t1 > t2") +error_matches(function () return t1 > t2 end, + "^[^:]+:%d+: attempt to compare two table values", + "t1 > t2") -error_like(function () return t1 >= t2 end, - "^[^:]+:%d+: attempt to compare two table values", - "t1 >= t2") +error_matches(function () return t1 >= t2 end, + "^[^:]+:%d+: attempt to compare two table values", + "t1 >= t2") -error_like(function () return {} < 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "{} < 0") +error_matches(function () return {} < 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "{} < 0") -error_like(function () return {} <= 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "{} <= 0") +error_matches(function () return {} <= 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "{} <= 0") -error_like(function () return {} > 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "{} > 0") +error_matches(function () return {} > 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "{} > 0") -error_like(function () return {} >= 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "{} >= 0") +error_matches(function () return {} >= 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "{} >= 0") local t = {} -is( t[1], nil, "index" ) +equals( t[1], nil, "index" ) t[1] = 42 -is( t[1], 42, "index" ) +equals( t[1], 42, "index" ) -error_like(function () t = {}; t[nil] = 42 end, - "^[^:]+:%d+: table index is nil", - "table index is nil") +error_matches(function () t = {}; t[nil] = 42 end, + "^[^:]+:%d+: table index is nil", + "table index is nil") -error_like(function () t = {}; t[0/0] = 42 end, - "^[^:]+:%d+: table index is NaN", - "table index is NaN") +error_matches(function () t = {}; t[0/0] = 42 end, + "^[^:]+:%d+: table index is NaN", + "table index is NaN") if has_op53 then make_specific_checks'lexico53/table.t' diff --git a/test/lua-Harness-tests/107-thread.t b/test/lua-Harness-tests/107-thread.t index 5c5bf22f..36003bab 100755 --- a/test/lua-Harness-tests/107-thread.t +++ b/test/lua-Harness-tests/107-thread.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -29,97 +29,97 @@ plan'no_plan' local co = coroutine.create(function () return 1 end) -error_like(function () return -co end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "-co") +error_matches(function () return -co end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "-co") -error_like(function () return #co end, - "^[^:]+:%d+: attempt to get length of", - "#co") +error_matches(function () return #co end, + "^[^:]+:%d+: attempt to get length of", + "#co") -is(not co, false, "not co") +equals(not co, false, "not co") -error_like(function () return co + 10 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "co + 10") +error_matches(function () return co + 10 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "co + 10") -error_like(function () return co - 2 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "co - 2") +error_matches(function () return co - 2 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "co - 2") -error_like(function () return co * 3.14 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "co * 3.14") +error_matches(function () return co * 3.14 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "co * 3.14") -error_like(function () return co / 7 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "co / 7") +error_matches(function () return co / 7 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "co / 7") -error_like(function () return co % 4 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "co % 4") +error_matches(function () return co % 4 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "co % 4") -error_like(function () return co ^ 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "co ^ 3") +error_matches(function () return co ^ 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "co ^ 3") -error_like(function () return co .. 'end' end, - "^[^:]+:%d+: attempt to concatenate", - "co .. 'end'") +error_matches(function () return co .. 'end' end, + "^[^:]+:%d+: attempt to concatenate", + "co .. 'end'") -is(co == co, true, "co == co") +equals(co == co, true, "co == co") local co1 = coroutine.create(function () return 1 end) local co2 = coroutine.create(function () return 2 end) -is(co1 ~= co2, true, "co1 ~= co2") +equals(co1 ~= co2, true, "co1 ~= co2") -is(co == 1, false, "co == 1") +equals(co == 1, false, "co == 1") -is(co ~= 1, true, "co ~= 1") +equals(co ~= 1, true, "co ~= 1") -error_like(function () return co1 < co2 end, - "^[^:]+:%d+: attempt to compare two thread values", - "co1 < co2") +error_matches(function () return co1 < co2 end, + "^[^:]+:%d+: attempt to compare two thread values", + "co1 < co2") -error_like(function () return co1 <= co2 end, - "^[^:]+:%d+: attempt to compare two thread values", - "co1 <= co2") +error_matches(function () return co1 <= co2 end, + "^[^:]+:%d+: attempt to compare two thread values", + "co1 <= co2") -error_like(function () return co1 > co2 end, - "^[^:]+:%d+: attempt to compare two thread values", - "co1 > co2") +error_matches(function () return co1 > co2 end, + "^[^:]+:%d+: attempt to compare two thread values", + "co1 > co2") -error_like(function () return co1 >= co2 end, - "^[^:]+:%d+: attempt to compare two thread values", - "co1 >= co2") +error_matches(function () return co1 >= co2 end, + "^[^:]+:%d+: attempt to compare two thread values", + "co1 >= co2") -error_like(function () return co < 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "co < 0") +error_matches(function () return co < 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "co < 0") -error_like(function () return co <= 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "co <= 0") +error_matches(function () return co <= 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "co <= 0") -error_like(function () return co > 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "co > 0") +error_matches(function () return co > 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "co > 0") -error_like(function () return co > 0 end, - "^[^:]+:%d+: attempt to compare %w+ with %w+", - "co >= 0") +error_matches(function () return co > 0 end, + "^[^:]+:%d+: attempt to compare %w+ with %w+", + "co >= 0") -error_like(function () local a = co[1] end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () local a = co[1] end, + "^[^:]+:%d+: attempt to index", + "index") -error_like(function () co[1] = 1 end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () co[1] = 1 end, + "^[^:]+:%d+: attempt to index", + "index") local t = {} t[co] = true -ok(t[co]) +truthy(t[co]) if has_op53 then make_specific_checks'lexico53/thread.t' diff --git a/test/lua-Harness-tests/108-userdata.t b/test/lua-Harness-tests/108-userdata.t index 48a5f60f..41b820d3 100755 --- a/test/lua-Harness-tests/108-userdata.t +++ b/test/lua-Harness-tests/108-userdata.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -29,94 +29,94 @@ plan'no_plan' local u = io.stdin -error_like(function () return -u end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "-u") +error_matches(function () return -u end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "-u") -error_like(function () return #u end, - "^[^:]+:%d+: attempt to get length of", - "#u") +error_matches(function () return #u end, + "^[^:]+:%d+: attempt to get length of", + "#u") -is(not u, false, "not u") +equals(not u, false, "not u") -error_like(function () return u + 10 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "u + 10") +error_matches(function () return u + 10 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "u + 10") -error_like(function () return u - 2 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "u - 2") +error_matches(function () return u - 2 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "u - 2") -error_like(function () return u * 3.14 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "u * 3.14") +error_matches(function () return u * 3.14 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "u * 3.14") -error_like(function () return u / 7 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "u / 7") +error_matches(function () return u / 7 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "u / 7") -error_like(function () return u % 4 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "u % 4") +error_matches(function () return u % 4 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "u % 4") -error_like(function () return u ^ 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "u ^ 3") +error_matches(function () return u ^ 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "u ^ 3") -error_like(function () return u .. 'end' end, - "^[^:]+:%d+: attempt to concatenate", - "u .. 'end'") +error_matches(function () return u .. 'end' end, + "^[^:]+:%d+: attempt to concatenate", + "u .. 'end'") -is(u == u, true, "u == u") +equals(u == u, true, "u == u") local v = io.stdout -is(u ~= v, true, "u ~= v") +equals(u ~= v, true, "u ~= v") -is(u == 1, false, "u == 1") +equals(u == 1, false, "u == 1") -is(u ~= 1, true, "u ~= 1") +equals(u ~= 1, true, "u ~= 1") -error_like(function () return u < v end, - "^[^:]+:%d+: attempt to compare two", - "u < v") +error_matches(function () return u < v end, + "^[^:]+:%d+: attempt to compare two", + "u < v") -error_like(function () return u <= v end, - "^[^:]+:%d+: attempt to compare two", - "u <= v") +error_matches(function () return u <= v end, + "^[^:]+:%d+: attempt to compare two", + "u <= v") -error_like(function () return u > v end, - "^[^:]+:%d+: attempt to compare two", - "u > v") +error_matches(function () return u > v end, + "^[^:]+:%d+: attempt to compare two", + "u > v") -error_like(function () return u >= v end, - "^[^:]+:%d+: attempt to compare two", - "u >= v") +error_matches(function () return u >= v end, + "^[^:]+:%d+: attempt to compare two", + "u >= v") -error_like(function () return u < 0 end, - "^[^:]+:%d+: attempt to compare", - "u < 0") +error_matches(function () return u < 0 end, + "^[^:]+:%d+: attempt to compare", + "u < 0") -error_like(function () return u <= 0 end, - "^[^:]+:%d+: attempt to compare", - "u <= 0") +error_matches(function () return u <= 0 end, + "^[^:]+:%d+: attempt to compare", + "u <= 0") -error_like(function () return u > 0 end, - "^[^:]+:%d+: attempt to compare", - "u > 0") +error_matches(function () return u > 0 end, + "^[^:]+:%d+: attempt to compare", + "u > 0") -error_like(function () return u > 0 end, - "^[^:]+:%d+: attempt to compare", - "u >= 0") +error_matches(function () return u > 0 end, + "^[^:]+:%d+: attempt to compare", + "u >= 0") -is(u[1], nil, "index") +equals(u[1], nil, "index") -error_like(function () u[1] = 1 end, - "^[^:]+:%d+: attempt to index", - "index") +error_matches(function () u[1] = 1 end, + "^[^:]+:%d+: attempt to index", + "index") local t = {} t[u] = true -ok(t[u]) +truthy(t[u]) if has_op53 then make_specific_checks'lexico53/userdata.t' diff --git a/test/lua-Harness-tests/200-examples.t b/test/lua-Harness-tests/200-examples.t index 362aae3a..708ee3bd 100755 --- a/test/lua-Harness-tests/200-examples.t +++ b/test/lua-Harness-tests/200-examples.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -35,7 +35,7 @@ function factorial (n) return n * factorial(n-1) end end -is(factorial(7), 5040, "factorial (recursive)") +equals(factorial(7), 5040, "factorial (recursive)") local function local_factorial (n) if n == 0 then @@ -44,7 +44,7 @@ local function local_factorial (n) return n * local_factorial(n-1) end end -is(local_factorial(7), 5040, "factorial (recursive)") +equals(local_factorial(7), 5040, "factorial (recursive)") local function loop_factorial (n) local a = 1 @@ -53,7 +53,7 @@ local function loop_factorial (n) end return a end -is(loop_factorial(7), 5040, "factorial (loop)") +equals(loop_factorial(7), 5040, "factorial (loop)") local function iter_factorial (n) local function iter (product, counter) @@ -65,7 +65,7 @@ local function iter_factorial (n) end return iter(1, 1) end -is(iter_factorial(7), 5040, "factorial (iter)") +equals(iter_factorial(7), 5040, "factorial (iter)") --[[ @@ -86,7 +86,7 @@ local function A (k, x1, x2, x3, x4, x5) end end -is(A(10, +equals(A(10, function () return 1 end, function () return -1 end, function () return -1 end, diff --git a/test/lua-Harness-tests/201-assign.t b/test/lua-Harness-tests/201-assign.t index 7d023d8e..3e978091 100755 --- a/test/lua-Harness-tests/201-assign.t +++ b/test/lua-Harness-tests/201-assign.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -34,19 +34,19 @@ local has_env = _VERSION >= 'Lua 5.2' plan'no_plan' do - is(b, nil, "global variable") + equals(b, nil, "global variable") b = 10 - is(b, 10) + equals(b, 10) if has_env then - is(_ENV.b, 10, "_ENV") - is(_G, _ENV, "_G") - error_like([[ _ENV = nil; b = 20 ]], - "attempt to ") + equals(_ENV.b, 10, "_ENV") + equals(_G, _ENV, "_G") + error_matches([[ _ENV = nil; b = 20 ]], + "attempt to ") else - is(_ENV, nil, "no _ENV"); + equals(_ENV, nil, "no _ENV"); end b = nil - is(b, nil) + equals(b, nil) end do @@ -55,39 +55,39 @@ do i, a[i] = i+1, 20 -- this behavior is undefined -- see http://lua-users.org/lists/lua-l/2006-06/msg00378.html - is(i, 4, "check eval") - is(a[3], 20) + equals(i, 4, "check eval") + equals(a[3], 20) end do local x = 1. local y = 2. x, y = y, x -- swap - is(x, 2, "check swap") - is(y, 1) + equals(x, 2, "check swap") + equals(y, 1) end do local a, b, c = 0, 1 - is(a, 0, "check padding") - is(b, 1) - is(c, nil) + equals(a, 0, "check padding") + equals(b, 1) + equals(c, nil) a, b = a+1, b+1, a+b - is(a, 1) - is(b, 2) + equals(a, 1) + equals(b, 2) a, b, c = 0 - is(a, 0) - is(b, nil) - is(c, nil) + equals(a, 0) + equals(b, nil) + equals(c, nil) end do local function f() return 1, 2 end local a, b, c, d = f() - is(a, 1, "adjust with function") - is(b, 2) - is(c, nil) - is(d, nil) + equals(a, 1, "adjust with function") + equals(b, 2) + equals(c, nil) + equals(d, nil) end do @@ -95,37 +95,37 @@ do local a = 2 local b, c a, b, c = f(), 3 - is(a, nil, "padding with function") - is(b, 3) - is(c, nil) + equals(a, nil, "padding with function") + equals(b, 3) + equals(c, nil) end do local my_i = 1 - is(my_i, 1, "local variable") + equals(my_i, 1, "local variable") local my_i = 2 - is(my_i, 2) + equals(my_i, 2) end do local i = 1 local j = i - is(i, 1, "local variable") - is(j, 1) + equals(i, 1, "local variable") + equals(j, 1) j = 2 - is(i, 1) - is(j, 2) + equals(i, 1) + equals(j, 2) end do local function f(x) return 2*x end - is(f(2), 4, "param & result of function") + equals(f(2), 4, "param & result of function") local a = 2 a = f(a) - is(a, 4) + equals(a, 4) local b = 2 b = f(b) - is(b, 4) + equals(b, 4) end do @@ -134,10 +134,10 @@ do local n3 = 3 local n4 = 4 n1,n2,n3,n4 = n4,n3,n2,n1 - is(n1, 4, "assignment list swap values") - is(n2, 3) - is(n3, 2) - is(n4, 1) + equals(n1, 4, "assignment list swap values") + equals(n2, 3) + equals(n3, 2) + equals(n4, 1) end done_testing() diff --git a/test/lua-Harness-tests/202-expr.t b/test/lua-Harness-tests/202-expr.t index 25767507..f86276af 100755 --- a/test/lua-Harness-tests/202-expr.t +++ b/test/lua-Harness-tests/202-expr.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -36,115 +36,115 @@ local nocvts2n = profile.nocvts2n plan'no_plan' local x = math.pi -is(tostring(x - x%0.0001), tostring(3.1415), "modulo") +equals(tostring(x - x%0.0001), tostring(3.1415), "modulo") local a = {}; a.x = 1; a.y = 0; local b = {}; b.x = 1; b.y = 0; local c = a -is(a == c, true, "relational op (by reference)") -is(a ~= b, true) - -is('0' == 0, false, "relational op") -is(2 < 15, true) -is('2' < '15', false) - -error_like(function () return 2 < '15' end, - "compare", - "relational op") - -error_like(function () return '2' < 15 end, - "compare", - "relational op") - -is(4 and 5, 5, "logical op") -is(nil and 13, nil) -is(false and 13, false) -is(4 or 5, 4) -is(false or 5, 5) -is(false or 'text', 'text') - -is(10 or 20, 10, "logical op") -is(10 or error(), 10) -is(nil or 'a', 'a') -is(nil and 10, nil) -is(false and error(), false) -is(false and nil, false) -is(false or nil, nil) -is(10 and 20, 20) - -is(not nil, true, "logical not") -is(not false, true) -is(not 0, false) -is(not not nil, false) -is(not 'text', false) +equals(a == c, true, "relational op (by reference)") +equals(a ~= b, true) + +equals('0' == 0, false, "relational op") +equals(2 < 15, true) +equals('2' < '15', false) + +error_matches(function () return 2 < '15' end, + "compare", + "relational op") + +error_matches(function () return '2' < 15 end, + "compare", + "relational op") + +equals(4 and 5, 5, "logical op") +equals(nil and 13, nil) +equals(false and 13, false) +equals(4 or 5, 4) +equals(false or 5, 5) +equals(false or 'text', 'text') + +equals(10 or 20, 10, "logical op") +equals(10 or error(), 10) +equals(nil or 'a', 'a') +equals(nil and 10, nil) +equals(false and error(), false) +equals(false and nil, false) +equals(false or nil, nil) +equals(10 and 20, 20) + +equals(not nil, true, "logical not") +equals(not false, true) +equals(not 0, false) +equals(not not nil, false) +equals(not 'text', false) a = {} -is(not a, false) -is(not (a == a), false) -is(not (a ~= a), true) +equals(not a, false) +equals(not (a == a), false) +equals(not (a ~= a), true) -is("Hello " .. "World", "Hello World", "concatenation") +equals("Hello " .. "World", "Hello World", "concatenation") if not nocvtn2s then - is(0 .. 1, '01') + equals(0 .. 1, '01') end a = "Hello" -is(a .. " World", "Hello World") -is(a, "Hello") +equals(a .. " World", "Hello World") +equals(a, "Hello") if not nocvts2n then - is('10' + 1, 11, "coercion") - is('-5.3' * '2', -10.6) + equals('10' + 1, 11, "coercion") + equals('-5.3' * '2', -10.6) end -is(tostring(10), '10') +equals(tostring(10), '10') if not nocvtn2s then - is(10 .. 20, '1020') - is(10 .. '', '10') + equals(10 .. 20, '1020') + equals(10 .. '', '10') end -error_like(function () return 'hello' + 1 end, - ((not nocvts2n and _VERSION >= 'Lua 5.4') or ravi) and "attempt to add" or "perform arithmetic", - "no coercion") +error_matches(function () return 'hello' + 1 end, + ((not nocvts2n and _VERSION >= 'Lua 5.4') or ravi) and "attempt to add" or "perform arithmetic", + "no coercion") -error_like(function () +error_matches(function () local function first() return end local function limit() return 2 end local function step() return 1 end for i = first(), limit(), step() do print(i) end - end, - "^[^:]+:%d+:.- 'for' initial value", - "for tonumber") + end, + "^[^:]+:%d+:.- 'for' initial value", + "for tonumber") -error_like(function () +error_matches(function () local function first() return 1 end local function limit() return end local function step() return 2 end for i = first(), limit(), step() do print(i) end - end, - "^[^:]+:%d+:.- 'for' limit", - "for tonumber") + end, + "^[^:]+:%d+:.- 'for' limit", + "for tonumber") -error_like(function () +error_matches(function () local function first() return 1 end local function limit() return 2 end local function step() return end for i = first(), limit(), step() do print(i) end - end, - "^[^:]+:%d+:.- 'for' step", - "for tonumber") + end, + "^[^:]+:%d+:.- 'for' step", + "for tonumber") if _VERSION >= 'Lua 5.4' then - error_like(function () + error_matches(function () for i = 1, 10, 0 do print(i) end - end, - "^[^:]+:%d+: 'for' step is zero", - "for step zero") + end, + "^[^:]+:%d+: 'for' step is zero", + "for step zero") end done_testing() diff --git a/test/lua-Harness-tests/203-lexico.t b/test/lua-Harness-tests/203-lexico.t index 7f554820..6143615c 100755 --- a/test/lua-Harness-tests/203-lexico.t +++ b/test/lua-Harness-tests/203-lexico.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2010-2020, Perrad Francois +-- Copyright (C) 2010-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -37,71 +37,71 @@ local luajit21 = jit and (jit.version_num >= 20100 or jit.version:match'^RaptorJ plan'no_plan' -is("\65", "A") -is("\065", "A") +equals("\65", "A") +equals("\065", "A") -is(string.byte("\a"), 7) -is(string.byte("\b"), 8) -is(string.byte("\f"), 12) -is(string.byte("\n"), 10) -is(string.byte("\r"), 13) -is(string.byte("\t"), 9) -is(string.byte("\v"), 11) -is(string.byte("\\"), 92) +equals(string.byte("\a"), 7) +equals(string.byte("\b"), 8) +equals(string.byte("\f"), 12) +equals(string.byte("\n"), 10) +equals(string.byte("\r"), 13) +equals(string.byte("\t"), 9) +equals(string.byte("\v"), 11) +equals(string.byte("\\"), 92) -is(string.len("A\0B"), 3) +equals(string.len("A\0B"), 3) do local f, msg = loadstring [[a = "A\300"]] if _VERSION == 'Lua 5.1' then - like(msg, "^[^:]+:%d+: .- near") + matches(msg, "^[^:]+:%d+: .- near") else - like(msg, "^[^:]+:%d+: .- escape .- near") + matches(msg, "^[^:]+:%d+: .- escape .- near") end f, msg = loadstring [[a = " unfinished string ]] - like(msg, "^[^:]+:%d+: unfinished string near") + matches(msg, "^[^:]+:%d+: unfinished string near") f, msg = loadstring [[a = " unfinished string ]] - like(msg, "^[^:]+:%d+: unfinished string near") + matches(msg, "^[^:]+:%d+: unfinished string near") f, msg = loadstring [[a = " unfinished string \ ]] - like(msg, "^[^:]+:%d+: unfinished string near") + matches(msg, "^[^:]+:%d+: unfinished string near") f, msg = loadstring [[a = " unfinished string \]] - like(msg, "^[^:]+:%d+: unfinished string near") + matches(msg, "^[^:]+:%d+: unfinished string near") f, msg = loadstring "a = [[ unfinished long string " - like(msg, "^[^:]+:%d+: unfinished long string .-near") + matches(msg, "^[^:]+:%d+: unfinished long string .-near") f, msg = loadstring "a = [== invalid long string delimiter " - like(msg, "^[^:]+:%d+: invalid long string delimiter near") + matches(msg, "^[^:]+:%d+: invalid long string delimiter near") end do local a = 'alo\n123"' - is('alo\n123"', a) - is("alo\n123\"", a) - is('\97lo\10\04923"', a) - is([[alo + equals('alo\n123"', a) + equals("alo\n123\"", a) + equals('\97lo\10\04923"', a) + equals([[alo 123"]], a) - is([==[ + equals([==[ alo 123"]==], a) end -is(3.0, 3) -is(314.16e-2, 3.1416) -is(0.31416E1, 3.1416) -is(.3, 0.3) -is(0xff, 255) -is(0x56, 86) +equals(3.0, 3) +equals(314.16e-2, 3.1416) +equals(0.31416E1, 3.1416) +equals(.3, 0.3) +equals(0xff, 255) +equals(0x56, 86) do local f, msg = loadstring [[a = 12e34e56]] - like(msg, "^[^:]+:%d+: malformed number near") + matches(msg, "^[^:]+:%d+: malformed number near") end --[===[ @@ -114,7 +114,7 @@ end do local f, msg = loadstring " --[[ unfinished long comment " - like(msg, "^[^:]+:%d+: unfinished long comment .-near") + matches(msg, "^[^:]+:%d+: unfinished long comment .-near") end if _VERSION >= 'Lua 5.2' or jit then diff --git a/test/lua-Harness-tests/204-grammar.t b/test/lua-Harness-tests/204-grammar.t index d9ae3a6f..c34fd28c 100755 --- a/test/lua-Harness-tests/204-grammar.t +++ b/test/lua-Harness-tests/204-grammar.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2010-2020, Perrad Francois +-- Copyright (C) 2010-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -39,19 +39,19 @@ plan'no_plan' do --[[ empty statement ]] local f, msg = loadstring [[; a = 1]] if _VERSION == 'Lua 5.1' and not profile.luajit_compat52 then - like(msg, "^[^:]+:%d+: unexpected symbol near ';'", "empty statement") + matches(msg, "^[^:]+:%d+: unexpected symbol near ';'", "empty statement") else - type_ok(f, 'function', "empty statement") + is_function(f, "empty statement") end f = loadstring [[a = 1; a = 2]] - type_ok(f, 'function') + is_function(f) f, msg = loadstring [[a = 1;;; a = 2]] if _VERSION == 'Lua 5.1' and not profile.luajit_compat52 then - like(msg, "^[^:]+:%d+: unexpected symbol near ';'") + matches(msg, "^[^:]+:%d+: unexpected symbol near ';'") else - type_ok(f, 'function') + is_function(f) end end @@ -67,11 +67,11 @@ function f() end ]] if _VERSION == 'Lua 5.1' then - like(msg, "^[^:]+:%d+: no loop to break", "orphan break") + matches(msg, "^[^:]+:%d+: no loop to break", "orphan break") elseif _VERSION <= 'Lua 5.3' then - like(msg, "^[^:]+:%d+: at line 5 not inside a loop", "orphan break") + matches(msg, "^[^:]+:%d+: at line 5 not inside a loop", "orphan break") else - like(msg, "^[^:]+:%d+: break outside loop at line 5", "orphan break") + matches(msg, "^[^:]+:%d+: break outside loop at line 5", "orphan break") end end @@ -88,9 +88,9 @@ function f() end ]] if _VERSION == 'Lua 5.1' and not profile.luajit_compat52 then - like(msg, "^[^:]+:%d+: 'end' expected %(to close 'while' at line 3%) near 'print'", "break anywhere") + matches(msg, "^[^:]+:%d+: 'end' expected %(to close 'while' at line 3%) near 'print'", "break anywhere") else - type_ok(f, 'function', "break anywhere") + is_function(f, "break anywhere") end f, msg = loadstring [[ @@ -107,9 +107,9 @@ function f() end ]] if _VERSION == 'Lua 5.1' and not profile.luajit_compat52 then - like(msg, "^[^:]+:%d+: 'end' expected %(to close 'if' at line 5%) near 'print'", "break anywhere") + matches(msg, "^[^:]+:%d+: 'end' expected %(to close 'if' at line 5%) near 'print'", "break anywhere") else - type_ok(f, 'function', "break anywhere") + is_function(f, "break anywhere") end end @@ -120,9 +120,9 @@ if has_goto then goto unknown ]] if jit then - like(msg, ":%d+: undefined label 'unknown'", "unknown goto") + matches(msg, ":%d+: undefined label 'unknown'", "unknown goto") else - like(msg, ":%d+: no visible label 'unknown' for at line %d+", "unknown goto") + matches(msg, ":%d+: no visible label 'unknown' for at line %d+", "unknown goto") end f, msg = loadstring [[ @@ -131,9 +131,9 @@ if has_goto then ::label:: ]] if jit then - like(msg, ":%d+: duplicate label 'label'", "duplicate label") + matches(msg, ":%d+: duplicate label 'label'", "duplicate label") else - like(msg, ":%d+: label 'label' already defined on line %d+", "duplicate label") + matches(msg, ":%d+: label 'label' already defined on line %d+", "duplicate label") end f, msg = loadstring [[ @@ -144,9 +144,9 @@ if has_goto then goto e ]] if jit then - like(msg, ":%d+: jumps into the scope of local 'x'", "bad goto") + matches(msg, ":%d+: jumps into the scope of local 'x'", "bad goto") else - like(msg, ":%d+: at line %d+ jumps into the scope of local 'x'", "bad goto") + matches(msg, ":%d+: at line %d+ jumps into the scope of local 'x'", "bad goto") end f= loadstring [[ @@ -160,67 +160,67 @@ do ::s3:: end ]] - type_ok(f, 'function', "goto") + is_function(f, "goto") else diag("no goto") end do --[[ syntax error ]] local f, msg = loadstring [[a = { 1, 2, 3)]] - like(msg, ":%d+: '}' expected near '%)'", "constructor { }") + matches(msg, ":%d+: '}' expected near '%)'", "constructor { }") f, msg = loadstring [[a = (1 + 2}]] - like(msg, ":%d+: '%)' expected near '}'", "expr ( )") + matches(msg, ":%d+: '%)' expected near '}'", "expr ( )") f, msg = loadstring [[a = f(1, 2}]] - like(msg, ":%d+: '%)' expected near '}'", "expr ( )") + matches(msg, ":%d+: '%)' expected near '}'", "expr ( )") f, msg = loadstring [[function f () return 1]] - like(msg, ":%d+: 'end' expected near '?'?", "function end") + matches(msg, ":%d+: 'end' expected near '?'?", "function end") f, msg = loadstring [[do local a = f()]] - like(msg, ":%d+: 'end' expected near '?'?", "do end") + matches(msg, ":%d+: 'end' expected near '?'?", "do end") f, msg = loadstring [[for i = 1, 2 do print(i)]] - like(msg, ":%d+: 'end' expected near '?'?", "for end") + matches(msg, ":%d+: 'end' expected near '?'?", "for end") f, msg = loadstring [[if true then f()]] - like(msg, ":%d+: 'end' expected near '?'?", "if end") + matches(msg, ":%d+: 'end' expected near '?'?", "if end") f, msg = loadstring [[while true do f()]] - like(msg, ":%d+: 'end' expected near '?'?", "while end") + matches(msg, ":%d+: 'end' expected near '?'?", "while end") f, msg = loadstring [[repeat f()]] - like(msg, ":%d+: 'until' expected near '?'?", "repeat until") + matches(msg, ":%d+: 'until' expected near '?'?", "repeat until") f, msg = loadstring [[function f (a, 2) return a * 2 end]] - like(msg, ":%d+: or '...' expected near '2'", "function parameter list") + matches(msg, ":%d+: or '...' expected near '2'", "function parameter list") f, msg = loadstring [[a = o:m[1, 2)]] - like(msg, ":%d+: function arguments expected near '%['", "function argument list") + matches(msg, ":%d+: function arguments expected near '%['", "function argument list") f, msg = loadstring [[for i do print(i) end]] - like(msg, ":%d+: '=' or 'in' expected near 'do'", "for init") + matches(msg, ":%d+: '=' or 'in' expected near 'do'", "for init") f, msg = loadstring [[for i = 1, 2 print(i) end]] - like(msg, ":%d+: 'do' expected near 'print'", "for do") + matches(msg, ":%d+: 'do' expected near 'print'", "for do") f, msg = loadstring [[if true f() end]] - like(msg, ":%d+: 'then' expected near 'f'", "if then") + matches(msg, ":%d+: 'then' expected near 'f'", "if then") f, msg = loadstring [[while true f() end]] - like(msg, ":%d+: 'do' expected near 'f", "while do") + matches(msg, ":%d+: 'do' expected near 'f", "while do") end if has_attr then local f, msg = load [[local foo < bar > = 'bar']] - like(msg, "^[^:]+:%d+: unknown attribute 'bar'") + matches(msg, "^[^:]+:%d+: unknown attribute 'bar'") f, msg = load [[local foo = 'bar'; foo = 'baz']] - like(msg, "^[^:]+:%d+: attempt to assign to const variable 'foo'") + matches(msg, "^[^:]+:%d+: attempt to assign to const variable 'foo'") f, msg = load [[local foo = 'bar'; foo = 'baz']] - like(msg, "^[^:]+:%d+: attempt to assign to const variable 'foo'") + matches(msg, "^[^:]+:%d+: attempt to assign to const variable 'foo'") end done_testing() diff --git a/test/lua-Harness-tests/211-scope.t b/test/lua-Harness-tests/211-scope.t index 64eed521..2c449ab5 100755 --- a/test/lua-Harness-tests/211-scope.t +++ b/test/lua-Harness-tests/211-scope.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -38,15 +38,15 @@ plan(10) x = 10 do local x = x - is(x, 10, "scope") + equals(x, 10, "scope") x = x + 1 do local x = x + 1 - is(x, 12) + equals(x, 12) end - is(x, 11) + equals(x, 11) end -is(x, 10) +equals(x, 10) --[[ scope ]] x = 10 @@ -61,22 +61,22 @@ end if i > 20 then local x x = 20 - nok("scope") + fails("scope") else - is(x, 10, "scope") + equals(x, 10, "scope") end -is(x, 10) +equals(x, 10) --[[ scope ]] local a, b = 1, 10 if a < b then - is(a, 1, "scope") + equals(a, 1, "scope") local a - is(a, nil) + equals(a, nil) end -is(a, 1) -is(b, 10) +equals(a, 1) +equals(b, 10) -- Local Variables: -- mode: lua diff --git a/test/lua-Harness-tests/212-function.t b/test/lua-Harness-tests/212-function.t index 28510537..8325e79b 100755 --- a/test/lua-Harness-tests/212-function.t +++ b/test/lua-Harness-tests/212-function.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -45,15 +45,15 @@ do --[[ add ]] end local t = { 10, 20, 30, 40 } - is(add(t), 100, "add") + equals(add(t), 100, "add") end do --[[ f ]] local function f(a, b) return a or b end - is(f(3), 3, "f") - is(f(3, 4), 3) - is(f(3, 4, 5), 3) + equals(f(3), 3, "f") + equals(f(3, 4), 3) + equals(f(3, 4, 5), 3) end do --[[ incCount ]] @@ -64,13 +64,13 @@ do --[[ incCount ]] count = count + n end - is(count, 0, "inCount") + equals(count, 0, "inCount") incCount() - is(count, 1) + equals(count, 1) incCount(2) - is(count, 3) + equals(count, 3) incCount(1) - is(count, 4) + equals(count, 4) end do --[[ maximum ]] @@ -87,8 +87,8 @@ do --[[ maximum ]] end local m, mi = maximum({8,10,23,12,5}) - is(m, 23, "maximum") - is(mi, 3) + equals(m, 23, "maximum") + equals(mi, 3) end do --[[ call by value ]] @@ -98,13 +98,13 @@ do --[[ call by value ]] end local a = 12 - is(a, 12, "call by value") + equals(a, 12, "call by value") local b = f(a) - is(b, 11) - is(a, 12) + equals(b, 11) + equals(a, 12) local c = f(12) - is(c, 11) - is(a, 12) + equals(c, 11) + equals(a, 12) end do --[[ call by ref ]] @@ -114,38 +114,38 @@ do --[[ call by ref ]] end local a = { 'a', 'b', 'c' } - is(table.concat(a, ','), 'a,b,c', "call by ref") + equals(table.concat(a, ','), 'a,b,c', "call by ref") local b = f(a) - is(table.concat(b, ','), 'a,b,c,end') - is(table.concat(a, ','), 'a,b,c,end') + equals(table.concat(b, ','), 'a,b,c,end') + equals(table.concat(a, ','), 'a,b,c,end') end do --[[ var args ]] local function g1(a, b, ...) local arg = {...} - is(a, 3, "vararg") - is(b, nil) - is(#arg, 0) - is(arg[1], nil) + equals(a, 3, "vararg") + equals(b, nil) + equals(#arg, 0) + equals(arg[1], nil) end g1(3) local function g2(a, b, ...) local arg = {...} - is(a, 3) - is(b, 4) - is(#arg, 0) - is(arg[1], nil) + equals(a, 3) + equals(b, 4) + equals(#arg, 0) + equals(arg[1], nil) end g2(3, 4) local function g3(a, b, ...) local arg = {...} - is(a, 3) - is(b, 4) - is(#arg, 2) - is(arg[1], 5) - is(arg[2], 8) + equals(a, 3) + equals(b, 4) + equals(#arg, 2) + equals(arg[1], 5) + equals(arg[2], 8) end g3(3, 4, 5, 8) end @@ -153,48 +153,48 @@ end do --[[ var args ]] local function g1(a, b, ...) local c, d, e = ... - is(a, 3, "var args") - is(b, nil) - is(c, nil) - is(d, nil) - is(e, nil) + equals(a, 3, "var args") + equals(b, nil) + equals(c, nil) + equals(d, nil) + equals(e, nil) end g1(3) local function g2(a, b, ...) local c, d, e = ... - is(a, 3) - is(b, 4) - is(c, nil) - is(d, nil) - is(e, nil) + equals(a, 3) + equals(b, 4) + equals(c, nil) + equals(d, nil) + equals(e, nil) end g2(3, 4) local function g3(a, b, ...) local c, d, e = ... - is(a, 3) - is(b, 4) - is(c, 5) - is(d, 8) - is(e, nil) + equals(a, 3) + equals(b, 4) + equals(c, 5) + equals(d, 8) + equals(e, nil) end g3(3, 4, 5, 8) end do --[[ var args ]] local function g1(a, b, ...) - is(#{a, b, ...}, 1, "varargs") + equals(#{a, b, ...}, 1, "varargs") end g1(3) local function g2(a, b, ...) - is(#{a, b, ...}, 2) + equals(#{a, b, ...}, 2) end g2(3, 4) local function g3(a, b, ...) - is(#{a, b, ...}, 4) + equals(#{a, b, ...}, 4) end g3(3, 4, 5, 8) end @@ -206,20 +206,20 @@ do --[[ var args ]] local function k() return 'c', (f()) end local x, y = f() - is(x, 1, "var args") - is(y, 2) + equals(x, 1, "var args") + equals(y, 2) local z x, y, z = g() - is(x, 'a') - is(y, 1) - is(z, 2) + equals(x, 'a') + equals(y, 1) + equals(z, 2) x, y = h() - is(x, 1) - is(y, 'b') + equals(x, 1) + equals(y, 'b') x, y, z = k() - is(x, 'c') - is(y, 1) - is(z, nil) + equals(x, 'c') + equals(y, 1) + equals(z, nil) end do --[[ invalid var args ]] @@ -228,7 +228,7 @@ function f () print(...) end ]] - like(msg, "^[^:]+:%d+: cannot use '...' outside a vararg function", "invalid var args") + matches(msg, "^[^:]+:%d+: cannot use '...' outside a vararg function", "invalid var args") end do --[[ tail call ]] @@ -241,8 +241,8 @@ do --[[ tail call ]] return 'end', 0 end - eq_array({foo(3)}, {'end', 0}, "tail call") - eq_array(output, {3, 2, 1, 0}) + array_equals({foo(3)}, {'end', 0}, "tail call") + array_equals(output, {3, 2, 1, 0}) end do --[[ no tail call ]] @@ -255,8 +255,8 @@ do --[[ no tail call ]] return 'end', 0 end - is(foo(3), 'end', "no tail call") - eq_array(output, {3, 2, 1, 0}) + equals(foo(3), 'end', "no tail call") + array_equals(output, {3, 2, 1, 0}) end do --[[ no tail call ]] @@ -268,16 +268,16 @@ do --[[ no tail call ]] end end - is(foo(3), nil, "no tail call") - eq_array(output, {3, 2, 1, 0}) + equals(foo(3), nil, "no tail call") + array_equals(output, {3, 2, 1, 0}) end do --[[ sub name ]] local function f () return 1 end - is(f(), 1, "sub name") + equals(f(), 1, "sub name") function f () return 2 end - is(f(), 2) + equals(f(), 2) end -- Local Variables: diff --git a/test/lua-Harness-tests/213-closure.t b/test/lua-Harness-tests/213-closure.t index fc3bd29c..925a0b84 100755 --- a/test/lua-Harness-tests/213-closure.t +++ b/test/lua-Harness-tests/213-closure.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -36,8 +36,8 @@ do --[[ inc ]] return counter end - is(inc(1), 1, "inc") - is(inc(2), 3) + equals(inc(1), 1, "inc") + equals(inc(2), 3) end do --[[ newCounter ]] @@ -50,13 +50,13 @@ do --[[ newCounter ]] end local c1 = newCounter() - is(c1(), 1, "newCounter") - is(c1(), 2) + equals(c1(), 1, "newCounter") + equals(c1(), 2) local c2 = newCounter() - is(c2(), 1) - is(c1(), 3) - is(c2(), 2) + equals(c2(), 1) + equals(c1(), 3) + equals(c2(), 2) end do --[[ @@ -71,9 +71,9 @@ of them share the same x. a[i] = function () y=y+1; return x+y end end - is(a[1](), 21, "ten closures") - is(a[1](), 22) - is(a[2](), 21) + equals(a[1](), 21, "ten closures") + equals(a[1](), 22) + equals(a[2](), 21) end do --[[ add ]] @@ -82,12 +82,12 @@ do --[[ add ]] end local f = add(2) - type_ok(f, 'function', "add") - is(f(10), 12) + is_function(f, "add") + equals(f(10), 12) local g = add(5) - is(g(1), 6) - is(g(10), 15) - is(f(1), 3) + equals(g(1), 6) + equals(g(10), 15) + equals(f(1), 3) end -- Local Variables: diff --git a/test/lua-Harness-tests/214-coroutine.t b/test/lua-Harness-tests/214-coroutine.t index 92929e1b..3101f840 100755 --- a/test/lua-Harness-tests/214-coroutine.t +++ b/test/lua-Harness-tests/214-coroutine.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -58,11 +58,11 @@ do return b, 'end' end) - eq_array({coroutine.resume(co, 1, 10)}, {true, 4}, "foo1") - eq_array({coroutine.resume(co, 'r')}, {true, 11, -9}) - eq_array({coroutine.resume(co, "x", "y")}, {true, 10, 'end'}) - eq_array({coroutine.resume(co, "x", "y")}, {false, "cannot resume dead coroutine"}) - eq_array(output, { + array_equals({coroutine.resume(co, 1, 10)}, {true, 4}, "foo1") + array_equals({coroutine.resume(co, 'r')}, {true, 11, -9}) + array_equals({coroutine.resume(co, "x", "y")}, {true, 10, 'end'}) + array_equals({coroutine.resume(co, "x", "y")}, {false, "cannot resume dead coroutine"}) + array_equals(output, { 'co-body 1 10', 'foo 2', 'co-body r', @@ -75,21 +75,21 @@ do local co = coroutine.create(function () output = 'hi' end) - like(co, '^thread: 0?[Xx]?%x+$', "basics") + matches(co, '^thread: 0?[Xx]?%x+$', "basics") - is(coroutine.status(co), 'suspended') + equals(coroutine.status(co), 'suspended') coroutine.resume(co) - is(output, 'hi') - is(coroutine.status(co), 'dead') + equals(output, 'hi') + equals(coroutine.status(co), 'dead') - error_like(function () coroutine.create(true) end, - "^[^:]+:%d+: bad argument #1 to 'create' %(.- expected") + error_matches(function () coroutine.create(true) end, + "^[^:]+:%d+: bad argument #1 to 'create' %(.- expected") - error_like(function () coroutine.resume(true) end, - "^[^:]+:%d+: bad argument #1 to 'resume' %(.- expected") + error_matches(function () coroutine.resume(true) end, + "^[^:]+:%d+: bad argument #1 to 'resume' %(.- expected") - error_like(function () coroutine.status(true) end, - "^[^:]+:%d+: bad argument #1 to 'status' %(.- expected") + error_matches(function () coroutine.status(true) end, + "^[^:]+:%d+: bad argument #1 to 'status' %(.- expected") end do @@ -104,13 +104,13 @@ do coroutine.resume(co) if has_running52 then local thr, ismain = coroutine.running() - type_ok(thr, 'thread', "running") - is(ismain, true, "running") + is_thread(thr, "running") + is_true(ismain, "running") else local thr = coroutine.running() - is(thr, nil, "main thread") + is_nil(thr, "main thread") end - is(coroutine.status(co), 'suspended', "basics") + equals(coroutine.status(co), 'suspended', "basics") coroutine.resume(co) coroutine.resume(co) coroutine.resume(co) @@ -121,8 +121,8 @@ do coroutine.resume(co) coroutine.resume(co) coroutine.resume(co) - eq_array({coroutine.resume(co)}, {false, 'cannot resume dead coroutine'}) - eq_array(output, {1,2,3,4,5,6,7,8,9,10}) + array_equals({coroutine.resume(co)}, {false, 'cannot resume dead coroutine'}) + array_equals(output, {1,2,3,4,5,6,7,8,9,10}) end do @@ -130,7 +130,7 @@ do coroutine.yield(a + b, a - b) end) - eq_array({coroutine.resume(co, 20, 10)}, {true, 30, 10}, "basics") + array_equals({coroutine.resume(co, 20, 10)}, {true, 30, 10}, "basics") end do @@ -138,7 +138,7 @@ do return 6, 7 end) - eq_array({coroutine.resume(co)}, {true, 6, 7}, "basics") + array_equals({coroutine.resume(co)}, {true, 6, 7}, "basics") end if has_coroutine52 then @@ -147,8 +147,8 @@ if has_coroutine52 then return coroutine.yield(...) end, ...) end) - eq_array({co("Hello")}, {"Hello"}) - eq_array({co("World")}, {true, "World"}) + array_equals({co("Hello")}, {"Hello"}) + array_equals({co("World")}, {true, "World"}) end if has_coroutine52 then @@ -160,8 +160,8 @@ if has_coroutine52 then return coroutine.yield(...) end, backtrace, ...) end) - eq_array({co("Hello")}, {"Hello"}) - eq_array({co("World")}, {true, "World"}) + array_equals({co("Hello")}, {"Hello"}) + array_equals({co("World")}, {true, "World"}) end if has_coroutine52 then @@ -180,19 +180,19 @@ if has_coroutine52 then co() co(true) co(false) - eq_array(output, {true, false}) + array_equals(output, {true, false}) end if has_coroutine52 then local co = coroutine.wrap(print) - type_ok(co, 'function') + is_function(co) - error_like(function () coroutine.wrap(true) end, - "^[^:]+:%d+: bad argument #1 to 'wrap' %(function expected, got boolean%)") + error_matches(function () coroutine.wrap(true) end, + "^[^:]+:%d+: bad argument #1 to 'wrap' %(function expected, got boolean%)") co = coroutine.wrap(function () error"in coro" end) - error_like(function () co() end, - "^[^:]+:%d+: [^:]+:%d+: in coro$") + error_matches(function () co() end, + "^[^:]+:%d+: [^:]+:%d+: in coro$") end do @@ -200,18 +200,18 @@ do error "in coro" end) local r, msg = coroutine.resume(co) - is(r, false) - like(msg, "^[^:]+:%d+: in coro$") + is_false(r) + matches(msg, "^[^:]+:%d+: in coro$") end do - error_like(function () coroutine.yield() end, - "attempt to yield") + error_matches(function () coroutine.yield() end, + "attempt to yield") if has_isyieldable then - is(coroutine.isyieldable(), false, "isyieldable") + is_false(coroutine.isyieldable(), "isyieldable") else - is(coroutine.isyieldable, nil, "no coroutine.isyieldable") + is_nil(coroutine.isyieldable, "no coroutine.isyieldable") end end @@ -221,17 +221,17 @@ if has_close then local co = coroutine.create(function () output = 'hi' end) - is(coroutine.close(co), true, "close") - is(coroutine.status(co), 'dead') - is(coroutine.close(co), true, "close again") + is_true(coroutine.close(co), "close") + equals(coroutine.status(co), 'dead') + is_true(coroutine.close(co), "close again") - error_like(function () coroutine.close(coroutine.running()) end, - "^[^:]+:%d+: cannot close a running coroutine") + error_matches(function () coroutine.close(coroutine.running()) end, + "^[^:]+:%d+: cannot close a running coroutine") - error_like(function () coroutine.close(42) end, - "^[^:]+:%d+: bad argument #1 to 'close' %(thread expected, got number%)") + error_matches(function () coroutine.close(42) end, + "^[^:]+:%d+: bad argument #1 to 'close' %(thread expected, got number%)") else - is(coroutine.close, nil, "no coroutine.close") + is_nil(coroutine.close, "no coroutine.close") end done_testing() diff --git a/test/lua-Harness-tests/221-table.t b/test/lua-Harness-tests/221-table.t index c064a339..1b4e6ff6 100755 --- a/test/lua-Harness-tests/221-table.t +++ b/test/lua-Harness-tests/221-table.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -33,20 +33,20 @@ do local k = 'x' a[k] = 10 a[20] = 'great' - is(a['x'], 10) + equals(a['x'], 10) k = 20 - is(a[k], 'great') + equals(a[k], 'great') a['x'] = a ['x'] + 1 - is(a['x'], 11) + equals(a['x'], 11) end do local a = {} a['x'] = 10 local b = a - is(b['x'], 10) + equals(b['x'], 10) b['x'] = 20 - is(a['x'], 20) + equals(a['x'], 20) a = nil b = nil end @@ -54,19 +54,19 @@ end do local a = {} for i=1,1000 do a[i] = i*2 end - is(a[9], 18) + equals(a[9], 18) a['x'] = 10 - is(a['x'], 10) - is(a['y'], nil) + equals(a['x'], 10) + equals(a['y'], nil) end do local a = {} local x = 'y' a[x] = 10 - is(a[x], 10) - is(a.x, nil) - is(a.y, 10) + equals(a[x], 10) + equals(a.x, nil) + equals(a.y, 10) end do @@ -75,41 +75,41 @@ do a[i] = "one value" a[j] = "another value" a[k] = "yet another value" - is(a[j], "another value") - is(a[k], "yet another value") - is(a[tonumber(j)], "one value") - is(a[tonumber(k)], "one value") + equals(a[j], "another value") + equals(a[k], "yet another value") + equals(a[tonumber(j)], "one value") + equals(a[tonumber(k)], "one value") end do local t = { {'a','b','c'}, 10 } - is(t[2], 10) - is(t[1][3], 'c') + equals(t[2], 10) + equals(t[1][3], 'c') t[1][1] = 'A' - is(table.concat(t[1],','), 'A,b,c') + equals(table.concat(t[1],','), 'A,b,c') end do local tt = { {'a','b','c'}, 10 } - is(tt[2], 10) - is(tt[1][3], 'c') + equals(tt[2], 10) + equals(tt[1][3], 'c') tt[1][1] = 'A' - is(table.concat(tt[1],','), 'A,b,c') + equals(table.concat(tt[1],','), 'A,b,c') end do local a = {} - error_like(function () a() end, - "^[^:]+:%d+: .- call") + error_matches(function () a() end, + "^[^:]+:%d+: .- call") end do local tt = { {'a','b','c'}, 10 } - is((tt)[2], 10) - is((tt[1])[3], 'c'); + equals((tt)[2], 10) + equals((tt[1])[3], 'c'); (tt)[1][2] = 'B' (tt[1])[3] = 'C' - is(table.concat(tt[1],','), 'a,B,C') + equals(table.concat(tt[1],','), 'a,B,C') end -- Local Variables: diff --git a/test/lua-Harness-tests/222-constructor.t b/test/lua-Harness-tests/222-constructor.t index a01be2ec..ce89b9aa 100755 --- a/test/lua-Harness-tests/222-constructor.t +++ b/test/lua-Harness-tests/222-constructor.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -37,8 +37,8 @@ plan(16) do --[[ list-style init ]] local days = {'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'} - is(days[4], 'Wednesday', "list-style init") - is(#days, 7) + equals(days[4], 'Wednesday', "list-style init") + equals(#days, 7) end do @@ -52,7 +52,7 @@ do 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 } - is(#large, 100) + equals(#large, 100) large = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, @@ -63,13 +63,13 @@ do 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 } - is(#large, 200) + equals(#large, 200) end do --[[ record-style init ]] local a = {x=0, y=0} - is(a.x, 0, "record-style init") - is(a.y, 0) + equals(a.x, 0, "record-style init") + equals(a.y, 0) end do @@ -77,9 +77,9 @@ do local x = {0, 1, 2} w[1] = "another field" x.f = w - is(w['x'], 0, "ctor") - is(w[1], "another field") - is(x.f[1], "another field") + equals(w['x'], 0, "ctor") + equals(w[1], "another field") + equals(x.f[1], "another field") w.x = nil end @@ -90,7 +90,7 @@ do --[[ mix record-style and list-style init ]] {x=-10, y=1}, {x=0, y=1} } - is(polyline[2].x, -10, "mix record-style and list-style init") + equals(polyline[2].x, -10, "mix record-style and list-style init") end do @@ -98,17 +98,17 @@ do ['*'] = 'mul', ['/'] = 'div'} local i = 20; local s = '-' local a = {[i+0] = s, [i+1] = s..s, [i+2] = s..s..s} - is(opnames[s], 'sub', "ctor") - is(a[22], '---') + equals(opnames[s], 'sub', "ctor") + equals(a[22], '---') end do local function f() return 10, 20 end - eq_array({f()}, {10, 20}, "ctor") - eq_array({'a', f()}, {'a', 10, 20}) - eq_array({f(), 'b'}, {10, 'b'}) - eq_array({'c', (f())}, {'c', 10}) + array_equals({f()}, {10, 20}, "ctor") + array_equals({'a', f()}, {'a', 10, 20}) + array_equals({f(), 'b'}, {10, 'b'}) + array_equals({'c', (f())}, {'c', 10}) end -- Local Variables: diff --git a/test/lua-Harness-tests/223-iterator.t b/test/lua-Harness-tests/223-iterator.t index 777ad73d..a95fd1fe 100755 --- a/test/lua-Harness-tests/223-iterator.t +++ b/test/lua-Harness-tests/223-iterator.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -48,7 +48,7 @@ do --[[ list_iter ]] for element in list_iter(t) do output[#output+1] = element end - eq_array(output, t, "list_iter") + array_equals(output, t, "list_iter") end do --[[ values ]] @@ -65,7 +65,7 @@ do --[[ values ]] for element in values(t) do output[#output+1] = element end - eq_array(output, t, "values") + array_equals(output, t, "values") end do --[[ emul ipairs ]] @@ -87,7 +87,7 @@ do --[[ emul ipairs ]] output[#output+1] = i output[#output+1] = v end - eq_array(output, {1, 'one', 2, 'two', 3, 'three'}, "emul ipairs") + array_equals(output, {1, 'one', 2, 'two', 3, 'three'}, "emul ipairs") end do --[[ emul pairs ]] @@ -101,7 +101,7 @@ do --[[ emul pairs ]] output[#output+1] = k output[#output+1] = v end - eq_array(output, {1, 'one', 2, 'two', 3, 'three'}, "emul ipairs") + array_equals(output, {1, 'one', 2, 'two', 3, 'three'}, "emul ipairs") end do --[[ with next ]] @@ -111,7 +111,7 @@ do --[[ with next ]] output[#output+1] = k output[#output+1] = v end - eq_array(output, {1, 'one', 2, 'two', 3, 'three'}, "with next") + array_equals(output, {1, 'one', 2, 'two', 3, 'three'}, "with next") end do --[[ permutations ]] @@ -143,7 +143,7 @@ do --[[ permutations ]] for p in permutations{'a', 'b', 'c'} do output[#output+1] = table.concat(p, ' ') end - eq_array(output, {'b c a','c b a','c a b','a c b','b a c','a b c'}, "permutations") + array_equals(output, {'b c a','c b a','c a b','a c b','b a c','a b c'}, "permutations") end do --[[ permutations with wrap ]] @@ -171,7 +171,7 @@ do --[[ permutations with wrap ]] for p in permutations{'a', 'b', 'c'} do output[#output+1] = table.concat(p, ' ') end - eq_array(output, {'b c a','c b a','c a b','a c b','b a c','a b c'}, "permutations with wrap") + array_equals(output, {'b c a','c b a','c a b','a c b','b a c','a b c'}, "permutations with wrap") end do --[[ fibo ]] @@ -192,7 +192,7 @@ do --[[ fibo ]] output[#output+1] = n if n > 30 then break end end - eq_array(output, {0, 1, 1, 2, 3, 5, 8, 13, 21, 34}, "fibo") + array_equals(output, {0, 1, 1, 2, 3, 5, 8, 13, 21, 34}, "fibo") end -- Local Variables: diff --git a/test/lua-Harness-tests/231-metatable.t b/test/lua-Harness-tests/231-metatable.t index 97ac5420..8d181d0e 100755 --- a/test/lua-Harness-tests/231-metatable.t +++ b/test/lua-Harness-tests/231-metatable.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -44,34 +44,34 @@ plan'no_plan' do local t = {} - is(getmetatable(t), nil, "metatable") + equals(getmetatable(t), nil, "metatable") local t1 = {} - is(setmetatable(t, t1), t) - is(getmetatable(t), t1) - is(setmetatable(t, nil), t) - error_like(function () setmetatable(t, true) end, - "^[^:]+:%d+: bad argument #2 to 'setmetatable' %(nil or table expected") + equals(setmetatable(t, t1), t) + equals(getmetatable(t), t1) + equals(setmetatable(t, nil), t) + error_matches(function () setmetatable(t, true) end, + "^[^:]+:%d+: bad argument #2 to 'setmetatable' %(nil or table expected") local mt = {} mt.__metatable = "not your business" setmetatable(t, mt) - is(getmetatable(t), "not your business", "protected metatable") - error_like(function () setmetatable(t, {}) end, - "^[^:]+:%d+: cannot change a protected metatable") + equals(getmetatable(t), "not your business", "protected metatable") + error_matches(function () setmetatable(t, {}) end, + "^[^:]+:%d+: cannot change a protected metatable") - is(getmetatable('').__index, string, "metatable for string") + equals(getmetatable('').__index, string, "metatable for string") - is(getmetatable(nil), nil, "metatable for nil") - is(getmetatable(false), nil, "metatable for boolean") - is(getmetatable(2), nil, "metatable for number") - is(getmetatable(print), nil, "metatable for function") + equals(getmetatable(nil), nil, "metatable for nil") + equals(getmetatable(false), nil, "metatable for boolean") + equals(getmetatable(2), nil, "metatable for number") + equals(getmetatable(print), nil, "metatable for function") end do local t = {} local mt = { __tostring=function () return '__TABLE__' end } setmetatable(t, mt) - is(tostring(t), '__TABLE__', "__tostring") + equals(tostring(t), '__TABLE__', "__tostring") end do @@ -81,26 +81,26 @@ do function mt.__tostring () a = "return nothing" end setmetatable(t, mt) if has_metamethod_tostring53 then - error_like(function () tostring(t) end, - "^[^:]+:%d+: '__tostring' must return a string") - is(a, "return nothing") + error_matches(function () tostring(t) end, + "^[^:]+:%d+: '__tostring' must return a string") + equals(a, "return nothing") if has_metamethod_tostring54 then - error_like(function () print(t) end, - "^[^:]+:%d+: '__tostring' must return a string") + error_matches(function () print(t) end, + "^[^:]+:%d+: '__tostring' must return a string") else - error_is(function () print(t) end, - "'__tostring' must return a string") + error_equals(function () print(t) end, + "'__tostring' must return a string") end else - is(tostring(t), nil, "__tostring no-output") - is(a, "return nothing") - error_like(function () print(t) end, - "^[^:]+:%d+: 'tostring' must return a string to 'print'") + equals(tostring(t), nil, "__tostring no-output") + equals(a, "return nothing") + error_matches(function () print(t) end, + "^[^:]+:%d+: 'tostring' must return a string to 'print'") end mt.__tostring = function () return '__FIRST__', 2 end setmetatable(t, mt) - is(tostring(t), '__FIRST__', "__tostring too-many-output") + equals(tostring(t), '__FIRST__', "__tostring too-many-output") end do @@ -108,9 +108,9 @@ do t.mt = {} setmetatable(t, t.mt) t.mt.__tostring = "not a function" - error_like(function () tostring(t) end, - "attempt to call", - "__tostring invalid") + error_matches(function () tostring(t) end, + "attempt to call", + "__tostring invalid") end do @@ -118,9 +118,9 @@ do local mt = { __len=function () return 42 end } setmetatable(t, mt) if has_metamethod52 then - is(#t, 42, "__len") + equals(#t, 42, "__len") else - is(#t, 0, "__len 5.1") + equals(#t, 0, "__len 5.1") end end @@ -131,9 +131,9 @@ if has_metamethod52 then if jit then todo("not with LuaJIT") end - error_like(function () print(table.concat(t)) end, - "object length is not a.-er", - "__len invalid") + error_matches(function () print(table.concat(t)) end, + "object length is not a.-er", + "__len invalid") end do @@ -145,7 +145,7 @@ do end, } setmetatable(t, mt) - is(t .. t .. t ..'end' .. '.', "t|t|t|end.", "__concat") + equals(t .. t .. t ..'end' .. '.', "t|t|t|end.", "__concat") end do --[[ Cplx ]] @@ -183,11 +183,11 @@ do --[[ Cplx ]] local c1 = Cplx.new(1, 3) local c2 = Cplx.new(2, -1) - is(tostring(c1 + c2), '(3,2)', "cplx __add") - is(tostring(c1 + 3), '(4,3)') - is(tostring(-2 + c1), '(-1,3)') - is(tostring(c1 + '3'), '(4,3)') - is(tostring('-2' + c1), '(-1,3)') + equals(tostring(c1 + c2), '(3,2)', "cplx __add") + equals(tostring(c1 + 3), '(4,3)') + equals(tostring(-2 + c1), '(-1,3)') + equals(tostring(c1 + '3'), '(4,3)') + equals(tostring('-2' + c1), '(-1,3)') function Cplx.mt.__sub (a, b) if type(a) ~= 'table' then @@ -200,11 +200,11 @@ do --[[ Cplx ]] return r end - is(tostring(c1 - c2), '(-1,4)', "cplx __sub") - is(tostring(c1 - 3), '(-2,3)') - is(tostring(-2 - c1), '(-3,-3)') - is(tostring(c1 - '3'), '(-2,3)') - is(tostring('-2' - c1), '(-3,-3)') + equals(tostring(c1 - c2), '(-1,4)', "cplx __sub") + equals(tostring(c1 - 3), '(-2,3)') + equals(tostring(-2 - c1), '(-3,-3)') + equals(tostring(c1 - '3'), '(-2,3)') + equals(tostring('-2' - c1), '(-3,-3)') function Cplx.mt.__mul (a, b) if type(a) ~= 'table' then @@ -218,11 +218,11 @@ do --[[ Cplx ]] return r end - is(tostring(c1 * c2), '(5,5)', "cplx __mul") - is(tostring(c1 * 3), '(3,9)') - is(tostring(-2 * c1), '(-2,-6)') - is(tostring(c1 * '3'), '(3,9)') - is(tostring('-2' * c1), '(-2,-6)') + equals(tostring(c1 * c2), '(5,5)', "cplx __mul") + equals(tostring(c1 * 3), '(3,9)') + equals(tostring(-2 * c1), '(-2,-6)') + equals(tostring(c1 * '3'), '(3,9)') + equals(tostring('-2' * c1), '(-2,-6)') function Cplx.mt.__div (a, b) if type(a) ~= 'table' then @@ -241,11 +241,11 @@ do --[[ Cplx ]] c1 = Cplx.new(2, 6) c2 = Cplx.new(2, 0) - is(tostring(c1 / c2), '(1,3)', "cplx __div") - is(tostring(c1 / 2), '(1,3)') - is(tostring(-4 / c2), '(-2,0)') - is(tostring(c1 / '2'), '(1,3)') - is(tostring('-4' / c2), '(-2,0)') + equals(tostring(c1 / c2), '(1,3)', "cplx __div") + equals(tostring(c1 / 2), '(1,3)') + equals(tostring(-4 / c2), '(-2,0)') + equals(tostring(c1 / '2'), '(1,3)') + equals(tostring('-4' / c2), '(-2,0)') function Cplx.mt.__unm (a) if type(a) ~= 'table' then @@ -256,7 +256,7 @@ do --[[ Cplx ]] end c1 = Cplx.new(1, 3) - is(tostring(- c1), '(-1,-3)', "cplx __unm") + equals(tostring(- c1), '(-1,-3)', "cplx __unm") function Cplx.mt.__len (a) return math.sqrt(a.re*a.re + a.im*a.im) @@ -264,9 +264,9 @@ do --[[ Cplx ]] c1 = Cplx.new(3, 4) if has_metamethod52 then - is( #c1, 5, "cplx __len") + equals( #c1, 5, "cplx __len") else - is( #c1, 0, "__len 5.1") + equals( #c1, 0, "__len 5.1") end function Cplx.mt.__eq (a, b) @@ -283,10 +283,10 @@ do --[[ Cplx ]] c2 = Cplx.new(1, 3) local c3 = Cplx.new(2, 0) - is(c1 ~= c2, true, "cplx __eq") - is(c1 == c3, true) - is(c1 == 2, false) - is(Cplx.mt.__eq(c1, 2), true) + equals(c1 ~= c2, true, "cplx __eq") + equals(c1 == c3, true) + equals(c1 == 2, false) + equals(Cplx.mt.__eq(c1, 2), true) function Cplx.mt.__lt (a, b) if type(a) ~= 'table' then @@ -300,14 +300,14 @@ do --[[ Cplx ]] return ra < rb end - is(c1 < c2, true, "cplx __lt") - is(c1 < c3, false) + equals(c1 < c2, true, "cplx __lt") + equals(c1 < c3, false) if has_metamethod_le_emulated then - is(c1 <= c3, true) + equals(c1 <= c3, true) end if has_metamethod52 then - is(c1 < 1, false) - is(c1 < 4, true) + equals(c1 < 1, false) + equals(c1 < 4, true) end function Cplx.mt.__le (a, b) @@ -322,9 +322,9 @@ do --[[ Cplx ]] return ra <= rb end - is(c1 < c2, true, "cplx __lt __le") - is(c1 < c3, false) - is(c1 <= c3, true) + equals(c1 < c2, true, "cplx __lt __le") + equals(c1 < c3, false) + equals(c1 <= c3, true) local a = nil function Cplx.mt.__call (obj) @@ -334,20 +334,20 @@ do --[[ Cplx ]] c1 = Cplx.new(2, 0) local r = c1() - is(r, true, "cplx __call (without args)") - is(a, "Cplx.__call (2,0)") + equals(r, true, "cplx __call (without args)") + equals(a, "Cplx.__call (2,0)") function Cplx.mt.__call (obj, ...) a = "Cplx.__call " .. tostring(obj) .. ", " .. table.concat({...}, ", ") return true end - is(c1(), true, "cplx __call (with args)") - is(a, "Cplx.__call (2,0), ") - is(c1('a'), true) - is(a, "Cplx.__call (2,0), a") - is(c1('a', 'b', 'c'), true) - is(a, "Cplx.__call (2,0), a, b, c") + equals(c1(), true, "cplx __call (with args)") + equals(a, "Cplx.__call (2,0), ") + equals(c1('a'), true) + equals(a, "Cplx.__call (2,0), a") + equals(c1('a', 'b', 'c'), true) + equals(a, "Cplx.__call (2,0), a, b, c") end --[[ delegate ]] @@ -371,7 +371,7 @@ if has_metamethod_pairs then r[#r+1] = k end table.sort(r) - is( table.concat(r, ','), 'a,b,c', "__pairs" ) + equals( table.concat(r, ','), 'a,b,c', "__pairs" ) end if has_metamethod_ipairs then local t = { @@ -388,7 +388,7 @@ if has_metamethod_ipairs then for i, v in ipairs(t) do r = r .. v end - is( r, 'abc', "__ipairs" ) + equals( r, 'abc', "__ipairs" ) end do --[[ Window ]] @@ -409,17 +409,17 @@ do --[[ Window ]] end local w = Window.new{x=10, y=20} - is(w.x, 10, "table-access") - is(w.width, 100) - is(rawget(w, 'x'), 10) - is(rawget(w, 'width'), nil) + equals(w.x, 10, "table-access") + equals(w.width, 100) + equals(rawget(w, 'x'), 10) + equals(rawget(w, 'width'), nil) Window.mt.__index = Window.prototype -- just a table w = Window.new{x=10, y=20} - is(w.x, 10, "table-access") - is(w.width, 100) - is(rawget(w, 'x'), 10) - is(rawget(w, 'width'), nil) + equals(w.x, 10, "table-access") + equals(w.width, 100) + equals(rawget(w, 'x'), 10) + equals(rawget(w, 'width'), nil) end do --[[ tables with default values ]] @@ -429,11 +429,11 @@ do --[[ tables with default values ]] end local tab = {x=10, y=20} - is(tab.x, 10, "tables with default values") - is(tab.z, nil) + equals(tab.x, 10, "tables with default values") + equals(tab.z, nil) setDefault_1(tab, 0) - is(tab.x, 10) - is(tab.z, 0) + equals(tab.x, 10) + equals(tab.z, 0) end do --[[ tables with default values ]] @@ -444,11 +444,11 @@ do --[[ tables with default values ]] end local tab = {x=10, y=20} - is(tab.x, 10, "tables with default values") - is(tab.z, nil) + equals(tab.x, 10, "tables with default values") + equals(tab.z, nil) setDefault_2(tab, 0) - is(tab.x, 10) - is(tab.z, 0) + equals(tab.x, 10) + equals(tab.z, 0) end do --[[ tables with default values ]] @@ -460,11 +460,11 @@ do --[[ tables with default values ]] end local tab = {x=10, y=20} - is(tab.x, 10, "tables with default values") - is(tab.z, nil) + equals(tab.x, 10, "tables with default values") + equals(tab.z, nil) setDefault_3(tab, 0) - is(tab.x, 10) - is(tab.z, 0) + equals(tab.x, 10) + equals(tab.z, 0) end do --[[ private access ]] @@ -492,9 +492,9 @@ do --[[ private access ]] setmetatable(t, mt) t[2] = 'hello' - is(t[2], 'hello', "tracking table accesses") - is(w, "*update of element 2 to hello") - is(r, "*access to element 2") + equals(t[2], 'hello', "tracking table accesses") + equals(w, "*update of element 2 to hello") + equals(r, "*access to element 2") end do --[[ private access ]] @@ -527,9 +527,9 @@ do --[[ private access ]] t = track(t) t[2] = 'hello' - is(t[2], 'hello', "tracking table accesses") - is(w, "*update of element 2 to hello") - is(r, "*access to element 2") + equals(t[2], 'hello', "tracking table accesses") + equals(w, "*update of element 2 to hello") + equals(r, "*access to element 2") end do --[[ read-only table ]] @@ -548,10 +548,10 @@ do --[[ read-only table ]] local days = readOnly{'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thurday', 'Friday', 'Saturday'} - is(days[1], 'Sunday', "read-only tables") + equals(days[1], 'Sunday', "read-only tables") - error_like(function () days[2] = 'Noday' end, - "^[^:]+:%d+: attempt to update a read%-only table") + error_matches(function () days[2] = 'Noday' end, + "^[^:]+:%d+: attempt to update a read%-only table") end do --[[ declare global ]] @@ -568,13 +568,13 @@ do --[[ declare global ]] end, }) - error_like(function () new_a = 1 end, - "^[^:]+:%d+: attempt to write to undeclared variable new_a", - "declaring global variables") + error_matches(function () new_a = 1 end, + "^[^:]+:%d+: attempt to write to undeclared variable new_a", + "declaring global variables") declare 'new_a' new_a = 1 - is(new_a, 1) + equals(new_a, 1) end do @@ -585,7 +585,7 @@ do } local t = setmetatable({}, mt) t[1] = 42 - is(newindex[1], 42, "__newindex") + equals(newindex[1], 42, "__newindex") end if has_anno_toclose then diff --git a/test/lua-Harness-tests/232-object.t b/test/lua-Harness-tests/232-object.t index 0d875729..583e37a6 100755 --- a/test/lua-Harness-tests/232-object.t +++ b/test/lua-Harness-tests/232-object.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -37,11 +37,11 @@ do --[[ object ]] local a1 = Account; Account = nil a1.withdraw(a1, 100.00) - is(a1.balance, -100, "object") + equals(a1.balance, -100, "object") local a2 = {balance = 0, withdraw = a1.withdraw} a2.withdraw(a2, 260.00) - is(a2.balance, -260) + equals(a2.balance, -260) end do --[[ object ]] @@ -53,7 +53,7 @@ do --[[ object ]] local a = Account a:withdraw(100.00) - is(a.balance, -100, "object") + equals(a.balance, -100, "object") Account = { balance = 0, withdraw = function (self, v) @@ -65,9 +65,9 @@ do --[[ object ]] end Account.deposit(Account, 200.00) - is(Account.balance, 200, "object") + equals(Account.balance, 200, "object") Account:withdraw(100.00) - is(Account.balance, 100) + equals(Account.balance, 100) end do --[[ class ]] @@ -90,12 +90,12 @@ do --[[ class ]] local a = Account:new{balance = 0} a:deposit(100.00) - is(a.balance, 100, "classe") + equals(a.balance, 100, "classe") local b = Account:new() - is(b.balance, 0) + equals(b.balance, 0) b:deposit(200.00) - is(b.balance, 200) + equals(b.balance, 200) end do --[[ inheritance ]] @@ -121,7 +121,7 @@ do --[[ inheritance ]] end local a = Account:new() - is(a.balance, 0, "inheritance") + equals(a.balance, 0, "inheritance") -- r, msg = pcall(Account.withdraw, a, 100) -- print(msg) @@ -143,10 +143,10 @@ do --[[ inheritance ]] local s = SpecialAccount:new{limit=1000.00} s:deposit(100.00) - is(s.balance, 100) + equals(s.balance, 100) s:withdraw(200.00) - is(s.balance, -100) + equals(s.balance, -100) end do --[[ multiple inheritance ]] @@ -201,9 +201,9 @@ do --[[ multiple inheritance ]] local NamedAccount = createClass(Account, Named) local account = NamedAccount:new{name = "Paul"} - is(account:getname(), 'Paul', "multiple inheritance") + equals(account:getname(), 'Paul', "multiple inheritance") account:deposit(100.00) - is(account.balance, 100) + equals(account.balance, 100) end do --[[ multiple inheritance (patched) ]] @@ -259,9 +259,9 @@ do --[[ multiple inheritance (patched) ]] local NamedAccount = createClass(Account, Named) local account = NamedAccount:new{name = "Paul"} - is(account:getname(), 'Paul', "multiple inheritance (patched)") + equals(account:getname(), 'Paul', "multiple inheritance (patched)") account:deposit(100.00) - is(account.balance, 100) + equals(account.balance, 100) end do --[[ privacy ]] @@ -287,7 +287,7 @@ do --[[ privacy ]] local acc1 = newAccount(100.00) acc1.withdraw(40.00) - is(acc1.getBalance(), 60, "privacy") + equals(acc1.getBalance(), 60, "privacy") end do --[[ single-method approach ]] @@ -301,9 +301,9 @@ do --[[ single-method approach ]] end local d = newObject(0) - is(d('get'), 0, "single-method approach") + equals(d('get'), 0, "single-method approach") d('set', 10) - is(d('get'), 10) + equals(d('get'), 10) end -- Local Variables: diff --git a/test/lua-Harness-tests/241-standalone.t.disabled b/test/lua-Harness-tests/241-standalone.t.disabled index c5237eed..deb5421d 100755 --- a/test/lua-Harness-tests/241-standalone.t.disabled +++ b/test/lua-Harness-tests/241-standalone.t.disabled @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -59,17 +59,17 @@ f:close() local cmd = lua .. " hello-241.lua" f = io.popen(cmd) -is(f:read'*l', 'Hello World', "file") +equals(f:read'*l', 'Hello World', "file") f:close() cmd = lua .. " -- hello-241.lua" f = io.popen(cmd) -is(f:read'*l', 'Hello World', "-- file") +equals(f:read'*l', 'Hello World', "-- file") f:close() cmd = lua .. " no_file-241.lua 2>&1" f = io.popen(cmd) -like(f:read'*l', "^[^:]+: cannot open no_file%-241%.lua", "no file") +matches(f:read'*l', "^[^:]+: cannot open no_file%-241%.lua", "no file") f:close() if has_bytecode then @@ -80,7 +80,7 @@ if has_bytecode then end cmd = lua .. " hello-241.luac" f = io.popen(cmd) - is(f:read'*l', 'Hello World', "bytecode") + equals(f:read'*l', 'Hello World', "bytecode") f:close() os.remove('hello-241.luac') -- clean up @@ -88,8 +88,8 @@ if has_bytecode then os.execute(luac .. " -s -o hello-hello-241.luac hello-241.lua hello-241.lua") cmd = lua .. " hello-hello-241.luac" f = io.popen(cmd) - is(f:read'*l', 'Hello World', "combine 1") - is(f:read'*l', 'Hello World', "combine 2") + equals(f:read'*l', 'Hello World', "combine 1") + equals(f:read'*l', 'Hello World', "combine 2") f:close() os.remove('hello-hello-241.luac') -- clean up end @@ -97,116 +97,116 @@ end cmd = lua .. " < hello-241.lua" f = io.popen(cmd) -is(f:read'*l', 'Hello World', "redirect") +equals(f:read'*l', 'Hello World', "redirect") f:close() cmd = lua .. " - < hello-241.lua" f = io.popen(cmd) -is(f:read'*l', 'Hello World', "redirect") +equals(f:read'*l', 'Hello World', "redirect") f:close() cmd = lua .. " -i hello-241.lua < hello-241.lua 2>&1" f = io.popen(cmd) -like(f:read'*l', banner, "-i") +matches(f:read'*l', banner, "-i") if ujit then - like(f:read'*l', '^JIT:') + matches(f:read'*l', '^JIT:') end if ravi then - like(f:read'*l', '^Copyright %(C%)') - like(f:read'*l', '^Portions Copyright %(C%)') - like(f:read'*l', '^Options') + matches(f:read'*l', '^Copyright %(C%)') + matches(f:read'*l', '^Portions Copyright %(C%)') + matches(f:read'*l', '^Options') end -is(f:read'*l', 'Hello World') +equals(f:read'*l', 'Hello World') f:close() cmd = lua .. [[ -e"a=1" -e "print(a)"]] f = io.popen(cmd) -is(f:read'*l', '1', "-e") +equals(f:read'*l', '1', "-e") f:close() cmd = lua .. [[ -e "error('msg')" 2>&1]] f = io.popen(cmd) -is(f:read'*l', lua .. [[: (command line):1: msg]], "error") -is(f:read'*l', "stack traceback:", "backtrace") +equals(f:read'*l', lua .. [[: (command line):1: msg]], "error") +equals(f:read'*l', "stack traceback:", "backtrace") f:close() cmd = lua .. [[ -e "error(setmetatable({}, {__tostring=function() return 'MSG' end}))" 2>&1]] f = io.popen(cmd) if has_error52 or jit then - is(f:read'*l', lua .. [[: MSG]], "error with object") + equals(f:read'*l', lua .. [[: MSG]], "error with object") else - is(f:read'*l', lua .. [[: (error object is not a string)]], "error with object") + equals(f:read'*l', lua .. [[: (error object is not a string)]], "error with object") end if jit then - is(f:read'*l', "stack traceback:", "backtrace") + equals(f:read'*l', "stack traceback:", "backtrace") else - is(f:read'*l', nil, "not backtrace") + equals(f:read'*l', nil, "not backtrace") end f:close() cmd = lua .. [[ -e "error{}" 2>&1]] f = io.popen(cmd) if has_error53 then - is(f:read'l', lua .. [[: (error object is a table value)]], "error") - is(f:read'l', "stack traceback:", "backtrace") + equals(f:read'l', lua .. [[: (error object is a table value)]], "error") + equals(f:read'l', "stack traceback:", "backtrace") elseif has_error52 then - is(f:read'*l', lua .. [[: (no error message)]], "error") - is(f:read'*l', nil, "not backtrace") + equals(f:read'*l', lua .. [[: (no error message)]], "error") + equals(f:read'*l', nil, "not backtrace") else - is(f:read'*l', lua .. [[: (error object is not a string)]], "error") - is(f:read'*l', nil, "not backtrace") + equals(f:read'*l', lua .. [[: (error object is not a string)]], "error") + equals(f:read'*l', nil, "not backtrace") end f:close() cmd = lua .. [[ -e"a=1" -e "print(a)" hello-241.lua]] f = io.popen(cmd) -is(f:read'*l', '1', "-e & script") -is(f:read'*l', 'Hello World') +equals(f:read'*l', '1', "-e & script") +equals(f:read'*l', 'Hello World') f:close() cmd = lua .. [[ -e"a=1" -i < hello-241.lua 2>&1]] f = io.popen(cmd) -like(f:read'*l', banner, "-e & -i") +matches(f:read'*l', banner, "-e & -i") f:close() cmd = lua .. [[ -e "?syntax error?" 2>&1]] f = io.popen(cmd) -like(f:read'*l', "^.-%d: unexpected symbol near '%?'", "-e bad") +matches(f:read'*l', "^.-%d: unexpected symbol near '%?'", "-e bad") f:close() cmd = lua .. [[ -e 2>&1]] f = io.popen(cmd) if _VERSION ~= 'Lua 5.1' then - like(f:read'*l', "^[^:]+: '%-e' needs argument", "no file") + matches(f:read'*l', "^[^:]+: '%-e' needs argument", "-e w/o arg") end -like(f:read'*l', "^usage: ", "no file") +matches(f:read'*l', "^usage: ") f:close() cmd = lua .. [[ -v 2>&1]] f = io.popen(cmd) -like(f:read'*l', banner, "-v") +matches(f:read'*l', banner, "-v") f:close() cmd = lua .. [[ -v hello-241.lua 2>&1]] f = io.popen(cmd) -like(f:read'*l', banner, "-v & script") +matches(f:read'*l', banner, "-v & script") if ravi then - like(f:read'*l', '^Copyright %(C%)') - like(f:read'*l', '^Portions Copyright %(C%)') - like(f:read'*l', '^Options') + matches(f:read'*l', '^Copyright %(C%)') + matches(f:read'*l', '^Portions Copyright %(C%)') + matches(f:read'*l', '^Options') end -is(f:read'*l', 'Hello World') +equals(f:read'*l', 'Hello World') f:close() cmd = lua .. [[ -v -- 2>&1]] f = io.popen(cmd) -like(f:read'*l', banner, "-v --") +matches(f:read'*l', banner, "-v --") f:close() if has_opt_E then cmd = lua .. [[ -E hello-241.lua 2>&1]] f = io.popen(cmd) - is(f:read'*l', 'Hello World', "-E") + equals(f:read'*l', 'Hello World', "-E") f:close() else diag("no -E") @@ -215,44 +215,52 @@ end cmd = lua .. [[ -u 2>&1]] f = io.popen(cmd) if _VERSION ~= 'Lua 5.1' then - like(f:read'*l', "^[^:]+: unrecognized option '%-u'", "unknown option") + matches(f:read'*l', "^[^:]+: unrecognized option '%-u'", "unknown option") end -like(f:read'*l', "^usage: ", "no file") +matches(f:read'*l', "^usage: ") f:close() cmd = lua .. [[ --u 2>&1]] f = io.popen(cmd) if _VERSION ~= 'Lua 5.1' then - like(f:read'*l', "^[^:]+: unrecognized option '%-%-u'", "unknown option") + matches(f:read'*l', "^[^:]+: unrecognized option '%-%-u'", "unknown option") end -like(f:read'*l', "^usage: ", "no file") +matches(f:read'*l', "^usage: ") f:close() -cmd = lua .. [[ -ltap -e "print(type(ok))"]] +f = io.open('foo.lua', 'w') +f:write([[ +function FOO () end +]]) +f:close() + +cmd = lua .. [[ -lfoo -e "print(type(FOO))"]] f = io.popen(cmd) -is(f:read'*l', 'function', "-ltap") +equals(f:read'*l', 'function', "-lfoo") f:close() -cmd = lua .. [[ -l tap -e "print(type(ok))"]] +cmd = lua .. [[ -l foo -e "print(type(FOO))"]] f = io.popen(cmd) -is(f:read'*l', 'function', "-l tap") +equals(f:read'*l', 'function', "-l foo") f:close() +os.remove('foo.lua') -- clean up + cmd = lua .. [[ -l lpeg -e "print(1)" 2>&1]] f = io.popen(cmd) -isnt(f:read'*l', nil, "-l lpeg") +not_equals(f:read'*l', nil, "-l lpeg") f:close() cmd = lua .. [[ -l no_lib hello-241.lua 2>&1]] f = io.popen(cmd) -like(f:read'*l', "^[^:]+: module 'no_lib' not found:", "-l no lib") +matches(f:read'*l', "^[^:]+: module 'no_lib' not found:", "-l no lib") f:close() if has_opt_W then cmd = lua .. [[ -W -e "warn'foo'" 2>&1]] f = io.popen(cmd) - is(f:read'*l', 'Lua warning: foo', "-W") - is(f:read'*l', nil) + equals(f:read'*l', 'Lua warning: foo', "-W") + equals(f:read'*l', nil) f:close() else diag("no -W") diff --git a/test/lua-Harness-tests/242-luac.t b/test/lua-Harness-tests/242-luac.t index a95a334a..9efabd01 100755 --- a/test/lua-Harness-tests/242-luac.t +++ b/test/lua-Harness-tests/242-luac.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2010-2020, Perrad Francois +-- Copyright (C) 2010-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -79,67 +79,67 @@ end do -- luac -v local cmd = luac .. [[ -v 2>&1]] local f = io.popen(cmd) - like(f:read'*l', '^Lua', "-v") + matches(f:read'*l', '^Lua', "-v") f:close() end do -- luac -v -- local cmd = luac .. [[ -v -- 2>&1]] local f = io.popen(cmd) - like(f:read'*l', '^Lua', "-v --") + matches(f:read'*l', '^Lua', "-v --") f:close() end do -- luac -u local cmd = luac .. [[ -u 2>&1]] local f = io.popen(cmd) - like(f:read'*l', "^[^:]+: unrecognized option '%-u'", "unknown option") - like(f:read'*l', "^usage:") + matches(f:read'*l', "^[^:]+: unrecognized option '%-u'", "unknown option") + matches(f:read'*l', "^usage:") f:close() end do -- luac --u local cmd = luac .. [[ --u 2>&1]] local f = io.popen(cmd) - like(f:read'*l', "^[^:]+: unrecognized option '%-%-u'", "unknown option") - like(f:read'*l', "^usage:") + matches(f:read'*l', "^[^:]+: unrecognized option '%-%-u'", "unknown option") + matches(f:read'*l', "^usage:") f:close() end do -- luac -p hello-242.lua local cmd = luac .. [[ -p hello-242.lua 2>&1]] local f = io.popen(cmd) - is(f:read'*l', nil) + equals(f:read'*l', nil) f:close() end do -- luac -p - < hello-242.lua local cmd = luac .. [[ -p - < hello-242.lua 2>&1]] local f = io.popen(cmd) - is(f:read'*l', nil) + equals(f:read'*l', nil) f:close() end do -- luac -p no_file-242.lua local cmd = luac .. [[ -p no_file-242.lua 2>&1]] local f = io.popen(cmd) - like(f:read'*l', "^[^:]+: cannot open no_file%-242%.lua", "no file") + matches(f:read'*l', "^[^:]+: cannot open no_file%-242%.lua", "no file") f:close() end do -- luac -o local cmd = luac .. [[ -o 2>&1]] local f = io.popen(cmd) - like(f:read'*l', "^[^:]+: '%-o' needs argument", "-o needs argument") + matches(f:read'*l', "^[^:]+: '%-o' needs argument", "-o needs argument") f:close() end do -- luac -v -l -l hello-242.lua local cmd = luac .. [[ -v -l -l hello-242.lua]] local f = io.popen(cmd) - like(f:read'*l', '^Lua', "-v -l -l") - is(f:read'*l', '') - like(f:read'*l', "^main") + matches(f:read'*l', '^Lua', "-v -l -l") + equals(f:read'*l', '') + matches(f:read'*l', "^main") f:close() end @@ -148,24 +148,24 @@ os.remove('hello-242.lua') -- clean up do -- luac -l luac.out local cmd = luac .. [[ -l luac.out]] local f = io.popen(cmd) - is(f:read'*l', '', "-l luac.out") - like(f:read'*l', "^main") + equals(f:read'*l', '', "-l luac.out") + matches(f:read'*l', "^main") f:close() end do -- luac -l local cmd = luac .. [[ -l]] local f = io.popen(cmd) - is(f:read'*l', '', "-l") - like(f:read'*l', "^main") + equals(f:read'*l', '', "-l") + matches(f:read'*l', "^main") f:close() end do -- luac -l - < luac.out local cmd = luac .. [[ -l - < luac.out]] local f = io.popen(cmd) - is(f:read'*l', '', "-l -") - like(f:read'*l', "^main") + equals(f:read'*l', '', "-l -") + matches(f:read'*l', "^main") f:close() end @@ -176,9 +176,9 @@ if _VERSION ~= 'Lua 5.1' then local cmd = luac .. [[ luac.out 2>&1]] f = io.popen(cmd) if _VERSION <= 'Lua 5.3' then - like(f:read'*l', "truncated precompiled chunk") + matches(f:read'*l', "truncated precompiled chunk") else - like(f:read'*l', "bad binary format %(truncated chunk%)") + matches(f:read'*l', "bad binary format %(truncated chunk%)") end f:close() end @@ -190,9 +190,9 @@ if _VERSION ~= 'Lua 5.1' then -- bad signature local cmd = luac .. [[ luac.out 2>&1]] f = io.popen(cmd) if _VERSION <= 'Lua 5.3' then - like(f:read'*l', "not a precompiled chunk", "bad signature") + matches(f:read'*l', "not a precompiled chunk", "bad signature") else - like(f:read'*l', "bad binary format %(not a binary chunk%)", "bad signature") + matches(f:read'*l', "bad binary format %(not a binary chunk%)", "bad signature") end f:close() end @@ -204,9 +204,9 @@ if _VERSION ~= 'Lua 5.1' then -- bad version local cmd = luac .. [[ luac.out 2>&1]] f = io.popen(cmd) if _VERSION <= 'Lua 5.3' then - like(f:read'*l', "version mismatch in precompiled chunk", "bad version") + matches(f:read'*l', "version mismatch in precompiled chunk", "bad version") else - like(f:read'*l', "bad binary format %(version mismatch%)", "bad version") + matches(f:read'*l', "bad binary format %(version mismatch%)", "bad version") end f:close() end @@ -218,11 +218,11 @@ if _VERSION ~= 'Lua 5.1' then -- bad format local cmd = luac .. [[ luac.out 2>&1]] f = io.popen(cmd) if _VERSION == 'Lua 5.2' then - like(f:read'*l', "version mismatch in precompiled chunk", "bad format") + matches(f:read'*l', "version mismatch in precompiled chunk", "bad format") elseif _VERSION == 'Lua 5.3' then - like(f:read'*l', "format mismatch in precompiled chunk", "bad format") + matches(f:read'*l', "format mismatch in precompiled chunk", "bad format") else - like(f:read'*l', "bad binary format %(format mismatch%)", "bad format") + matches(f:read'*l', "bad binary format %(format mismatch%)", "bad format") end f:close() end @@ -233,7 +233,7 @@ if _VERSION == 'Lua 5.2' then -- bad sizes f:close() local cmd = luac .. [[ luac.out 2>&1]] f = io.popen(cmd) - like(f:read'*l', "incompatible precompiled chunk", "incompatible 5.2") + matches(f:read'*l', "incompatible precompiled chunk", "incompatible 5.2") f:close() end @@ -244,7 +244,7 @@ if _VERSION == 'Lua 5.2' then -- bad data / tail f:close() local cmd = luac .. [[ luac.out 2>&1]] f = io.popen(cmd) - like(f:read'*l', "corrupted precompiled chunk", "corrupted 5.2") + matches(f:read'*l', "corrupted precompiled chunk", "corrupted 5.2") f:close() end @@ -254,7 +254,7 @@ if _VERSION == 'Lua 5.3' then -- bad data f:close() local cmd = luac .. [[ luac.out 2>&1]] f = io.popen(cmd) - like(f:read'*l', "corrupted precompiled chunk", "corrupted") + matches(f:read'*l', "corrupted precompiled chunk", "corrupted") f:close() end @@ -264,7 +264,7 @@ if _VERSION == 'Lua 5.3' then -- bad sizes f:close() local cmd = luac .. [[ luac.out 2>&1]] f = io.popen(cmd) - like(f:read'*l', "int size mismatch in precompiled chunk", "bad sizes") + matches(f:read'*l', "int size mismatch in precompiled chunk", "bad sizes") f:close() end @@ -274,7 +274,7 @@ if _VERSION == 'Lua 5.3' then -- bad endianess f:close() local cmd = luac .. [[ luac.out 2>&1]] f = io.popen(cmd) - like(f:read'*l', "endianness mismatch in precompiled chunk", "bad endian") + matches(f:read'*l', "endianness mismatch in precompiled chunk", "bad endian") f:close() end @@ -285,7 +285,7 @@ if _VERSION == 'Lua 5.3' then -- bad float format f:close() local cmd = luac .. [[ luac.out 2>&1]] f = io.popen(cmd) - like(f:read'*l', "float format mismatch in precompiled chunk") + matches(f:read'*l', "float format mismatch in precompiled chunk") f:close() end @@ -312,19 +312,19 @@ s = nil local cmd = luac .. [[ -o cover-242.out cover-242.lua 2>&1]] f = io.popen(cmd) - is(f:read'*l', nil, "-o cover-242.out cover-242.lua") + equals(f:read'*l', nil, "-o cover-242.out cover-242.lua") f:close() cmd = luac .. [[ -l cover-242.out]] f = io.popen(cmd) - is(f:read'*l', '', "-l cover-242.out") - like(f:read'*l', "^main") + equals(f:read'*l', '', "-l cover-242.out") + matches(f:read'*l', "^main") f:close() cmd = luac .. [[ -l -l cover-242.out]] f = io.popen(cmd) - is(f:read'*l', '', "-l -l cover-242.out") - like(f:read'*l', "^main") + equals(f:read'*l', '', "-l -l cover-242.out") + matches(f:read'*l', "^main") f:close() end diff --git a/test/lua-Harness-tests/301-basic.t b/test/lua-Harness-tests/301-basic.t index a4bb09ff..415cc497 100755 --- a/test/lua-Harness-tests/301-basic.t +++ b/test/lua-Harness-tests/301-basic.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -54,32 +54,32 @@ plan'no_plan' do -- assert local v, msg = assert('text', "assert string") - is(v, 'text', "function assert") - is(msg, "assert string") + equals(v, 'text', "function assert") + equals(msg, "assert string") v, msg = assert({}, "assert table") - is(msg, "assert table") + equals(msg, "assert table") - error_like(function () assert(false, "ASSERTION TEST") end, - "^[^:]+:%d+: ASSERTION TEST", - "function assert(false, msg)") + error_matches(function () assert(false, "ASSERTION TEST") end, + "^[^:]+:%d+: ASSERTION TEST", + "function assert(false, msg)") - error_like(function () assert(false) end, - "^[^:]+:%d+: assertion failed!", - "function assert(false)") + error_matches(function () assert(false) end, + "^[^:]+:%d+: assertion failed!", + "function assert(false)") if has_error53 then v, msg = pcall(function() assert(false, 42) end) - is(msg, 42, "function assert(false, 42)") + equals(msg, 42, "function assert(false, 42)") else - error_like(function () assert(false, 42) end, - "^[^:]+:%d+: 42", - "function assert(false, 42)") + error_matches(function () assert(false, 42) end, + "^[^:]+:%d+: 42", + "function assert(false, 42)") end if has_error53 then local obj = {} v, msg = pcall(function() assert(false, obj) end) - is(msg, obj, "function assert(false, {})") + equals(msg, obj, "function assert(false, {})") else diag("no assert with table") end @@ -87,71 +87,71 @@ end -- collectgarbage if jit then - is(collectgarbage('stop'), 0, "function collectgarbage 'stop/restart/collect'") - is(collectgarbage('step'), false) - is(collectgarbage('restart'), 0) - is(collectgarbage('step'), false) - is(collectgarbage('collect'), 0) - is(collectgarbage('setpause', 10), 200) - is(collectgarbage('setstepmul', 200), 200) - is(collectgarbage(), 0) + equals(collectgarbage('stop'), 0, "function collectgarbage 'stop/restart/collect'") + equals(collectgarbage('step'), false) + equals(collectgarbage('restart'), 0) + equals(collectgarbage('step'), false) + equals(collectgarbage('collect'), 0) + equals(collectgarbage('setpause', 10), 200) + equals(collectgarbage('setstepmul', 200), 200) + equals(collectgarbage(), 0) elseif _VERSION == 'Lua 5.1' then - is(collectgarbage('stop'), 0, "function collectgarbage 'stop/restart/collect'") - is(collectgarbage('restart'), 0) - is(collectgarbage('step'), false) - is(collectgarbage('collect'), 0) - is(collectgarbage(), 0) + equals(collectgarbage('stop'), 0, "function collectgarbage 'stop/restart/collect'") + equals(collectgarbage('restart'), 0) + equals(collectgarbage('step'), false) + equals(collectgarbage('collect'), 0) + equals(collectgarbage(), 0) elseif _VERSION == 'Lua 5.2' then - is(collectgarbage('stop'), 0, "function collectgarbage 'stop/restart/collect'") - is(collectgarbage('isrunning'), false) - is(collectgarbage('step'), false) - is(collectgarbage('restart'), 0) - is(collectgarbage('isrunning'), true) - is(collectgarbage('step'), false) - is(collectgarbage('collect'), 0) - is(collectgarbage('setpause', 10), 200) - is(collectgarbage('setstepmul', 200), 200) - is(collectgarbage(), 0) - is(collectgarbage('generational'), 0) - is(collectgarbage('step'), false) - is(collectgarbage('incremental'), 0) - is(collectgarbage('setmajorinc'), 200) + equals(collectgarbage('stop'), 0, "function collectgarbage 'stop/restart/collect'") + equals(collectgarbage('isrunning'), false) + equals(collectgarbage('step'), false) + equals(collectgarbage('restart'), 0) + equals(collectgarbage('isrunning'), true) + equals(collectgarbage('step'), false) + equals(collectgarbage('collect'), 0) + equals(collectgarbage('setpause', 10), 200) + equals(collectgarbage('setstepmul', 200), 200) + equals(collectgarbage(), 0) + equals(collectgarbage('generational'), 0) + equals(collectgarbage('step'), false) + equals(collectgarbage('incremental'), 0) + equals(collectgarbage('setmajorinc'), 200) elseif _VERSION == 'Lua 5.3' then - is(collectgarbage('stop'), 0, "function collectgarbage 'stop/restart/collect'") - is(collectgarbage('isrunning'), false) - --is(collectgarbage('step'), false) - type_ok(collectgarbage('step'), 'boolean') - is(collectgarbage('restart'), 0) - is(collectgarbage('isrunning'), true) - is(collectgarbage('step'), false) - is(collectgarbage('collect'), 0) - is(collectgarbage('setpause', 10), 200) - is(collectgarbage('setstepmul', 200), 200) - is(collectgarbage(), 0) - is(collectgarbage('step'), false) + equals(collectgarbage('stop'), 0, "function collectgarbage 'stop/restart/collect'") + equals(collectgarbage('isrunning'), false) + --equals(collectgarbage('step'), false) + is_boolean(collectgarbage('step')) + equals(collectgarbage('restart'), 0) + equals(collectgarbage('isrunning'), true) + equals(collectgarbage('step'), false) + equals(collectgarbage('collect'), 0) + equals(collectgarbage('setpause', 10), 200) + equals(collectgarbage('setstepmul', 200), 200) + equals(collectgarbage(), 0) + equals(collectgarbage('step'), false) elseif _VERSION == 'Lua 5.4' then - is(collectgarbage('stop'), 0, "function collectgarbage 'stop/restart/collect'") - is(collectgarbage('isrunning'), false) - is(collectgarbage('generational'), 'generational') - is(collectgarbage('incremental'), 'generational') - is(collectgarbage('incremental'), 'incremental') - is(collectgarbage('generational'), 'incremental') - is(collectgarbage('step'), false) - is(collectgarbage('restart'), 0) - is(collectgarbage('isrunning'), true) - is(collectgarbage('step'), false) - is(collectgarbage('collect'), 0) - is(collectgarbage('setpause', 10), 200) - is(collectgarbage('setstepmul', 200), 100) - is(collectgarbage(), 0) - is(collectgarbage('step'), false) -end - -type_ok(collectgarbage('count'), 'number', "function collectgarbage 'count'") - -error_like(function () collectgarbage('unknown') end, - "^[^:]+:%d+: bad argument #1 to 'collectgarbage' %(invalid option 'unknown'%)", - "function collectgarbage (invalid)") + equals(collectgarbage('stop'), 0, "function collectgarbage 'stop/restart/collect'") + equals(collectgarbage('isrunning'), false) + equals(collectgarbage('generational'), 'generational') + equals(collectgarbage('incremental'), 'generational') + equals(collectgarbage('incremental'), 'incremental') + equals(collectgarbage('generational'), 'incremental') + equals(collectgarbage('step'), false) + equals(collectgarbage('restart'), 0) + equals(collectgarbage('isrunning'), true) + equals(collectgarbage('step'), false) + equals(collectgarbage('collect'), 0) + equals(collectgarbage('setpause', 10), 200) + equals(collectgarbage('setstepmul', 200), 100) + equals(collectgarbage(), 0) + equals(collectgarbage('step'), false) +end + +is_number(collectgarbage('count'), "function collectgarbage 'count'") + +error_matches(function () collectgarbage('unknown') end, + "^[^:]+:%d+: bad argument #1 to 'collectgarbage' %(invalid option 'unknown'%)", + "function collectgarbage (invalid)") do -- dofile local f = io.open('lib-301.lua', 'w') @@ -167,91 +167,91 @@ end f:close() dofile('lib-301.lua') local n = norm(3.4, 1.0) - like(twice(n), '^7%.088', "function dofile") + matches(twice(n), '^7%.088', "function dofile") os.remove('lib-301.lua') -- clean up - error_like(function () dofile('no_file-301.lua') end, - "cannot open no_file%-301%.lua: No such file or directory", - "function dofile (no file)") + error_matches(function () dofile('no_file-301.lua') end, + "cannot open no_file%-301%.lua: No such file or directory", + "function dofile (no file)") f = io.open('foo-301.lua', 'w') f:write[[?syntax error?]] f:close() - error_like(function () dofile('foo-301.lua') end, - "^foo%-301%.lua:%d+:", - "function dofile (syntax error)") + error_matches(function () dofile('foo-301.lua') end, + "^foo%-301%.lua:%d+:", + "function dofile (syntax error)") os.remove('foo-301.lua') -- clean up end do -- error - error_like(function () error("ERROR TEST") end, - "^[^:]+:%d+: ERROR TEST", - "function error(msg)") + error_matches(function () error("ERROR TEST") end, + "^[^:]+:%d+: ERROR TEST", + "function error(msg)") - error_is(function () error("ERROR TEST", 0) end, - "ERROR TEST", - "function error(msg, 0)") + error_equals(function () error("ERROR TEST", 0) end, + "ERROR TEST", + "function error(msg, 0)") if has_error53 then local v, msg = pcall(function() error(42) end) - is(msg, 42, "function error(42)") + equals(msg, 42, "function error(42)") else - error_like(function () error(42) end, - "^[^:]+:%d+: 42", - "function error(42)") + error_matches(function () error(42) end, + "^[^:]+:%d+: 42", + "function error(42)") end local obj = {} local v, msg = pcall(function() error(obj) end) - is(msg, obj, "function error({})") + equals(msg, obj, "function error({})") v, msg = pcall(function() error() end) - is(msg, nil, "function error()") + equals(msg, nil, "function error()") end -- gcinfo if has_gcinfo then - type_ok(gcinfo(), 'number', "function gcinfo") + is_number(gcinfo(), "function gcinfo") else - is(gcinfo, nil, "no gcinfo (removed)") + is_nil(gcinfo, "no gcinfo (removed)") end -- getfenv if has_getfenv then - type_ok(getfenv(0), 'table', "function getfenv") - is(getfenv(0), _G) - is(getfenv(1), _G) - is(getfenv(), _G) + is_table(getfenv(0), "function getfenv") + equals(getfenv(0), _G) + equals(getfenv(1), _G) + equals(getfenv(), _G) local function f () end - type_ok(getfenv(f), 'table') - is(getfenv(f), _G) - type_ok(getfenv(print), 'table') - is(getfenv(print), _G) - - error_like(function () getfenv(-3) end, - "^[^:]+:%d+: bad argument #1 to 'getfenv' %(.-level.-%)", - "function getfenv (negative)") - - error_like(function () getfenv(12) end, - "^[^:]+:%d+: bad argument #1 to 'getfenv' %(invalid level%)", - "function getfenv (too depth)") + is_table(getfenv(f)) + equals(getfenv(f), _G) + is_table(getfenv(print)) + equals(getfenv(print), _G) + + error_matches(function () getfenv(-3) end, + "^[^:]+:%d+: bad argument #1 to 'getfenv' %(.-level.-%)", + "function getfenv (negative)") + + error_matches(function () getfenv(12) end, + "^[^:]+:%d+: bad argument #1 to 'getfenv' %(invalid level%)", + "function getfenv (too depth)") else - is(getfenv, nil, "no getfenv") + is_nil(getfenv, "no getfenv") end do -- getmetatable - is(getmetatable(true), nil, "boolean has no metatable by default") - is(getmetatable(getmetatable), nil, "function has no metatable by default") - is(getmetatable(nil), nil, "nil has no metatable by default") - is(getmetatable(3.14), nil, "number has no metatable by default") - is(getmetatable({}), nil, "table has no metatable by default") + equals(getmetatable(true), nil, "boolean has no metatable by default") + equals(getmetatable(getmetatable), nil, "function has no metatable by default") + equals(getmetatable(nil), nil, "nil has no metatable by default") + equals(getmetatable(3.14), nil, "number has no metatable by default") + equals(getmetatable({}), nil, "table has no metatable by default") local co = coroutine.create(function () return 1 end) - is(getmetatable(co), nil, "thread has no metatable by default") + equals(getmetatable(co), nil, "thread has no metatable by default") - type_ok(getmetatable('ABC'), 'table', "string has a metatable") - is(getmetatable('ABC'), getmetatable('abc'), "string has a shared metatable") + is_table(getmetatable('ABC'), "string has a metatable") + equals(getmetatable('ABC'), getmetatable('abc'), "string has a shared metatable") end do -- ipairs @@ -267,21 +267,21 @@ do -- ipairs }) end local f, v, s = ipairs(a) - type_ok(f, 'function', "function ipairs") - type_ok(v, 'table') - is(s, 0) + is_function(f, "function ipairs") + is_table(v) + equals(s, 0) s, v = f(a, s) - is(s, 1) - is(v, 'a') + equals(s, 1) + equals(v, 'a') s, v = f(a, s) - is(s, 2) - is(v, 'b') + equals(s, 2) + equals(v, 'b') s, v = f(a, s) - is(s, 3) - is(v, 'c') + equals(s, 3) + equals(v, 'c') s, v = f(a, s) - is(s, nil) - is(v, nil) + equals(s, nil) + equals(v, nil) end do -- load @@ -299,10 +299,10 @@ end if msg then diag(msg) end - type_ok(f, 'function', "function load(reader)") - is(bar, nil) + is_function(f, "function load(reader)") + equals(bar, nil) f() - is(bar('ok'), 'ok') + equals(bar('ok'), 'ok') bar = nil t = { [[ @@ -319,25 +319,25 @@ end if msg then diag(msg) end - type_ok(f, 'function', "function load(pathological reader)") + is_function(f, "function load(pathological reader)") f() if _VERSION == 'Lua 5.1' and not jit then todo("not with 5.1") end - is(baz, nil) + equals(baz, nil) t = { [[?syntax error?]] } i = 0 f, msg = load(reader, "errorchunk") - is(f, nil, "function load(syntax error)") - like(msg, "^%[string \"errorchunk\"%]:%d+:") + is_nil(f, "function load(syntax error)") + matches(msg, "^%[string \"errorchunk\"%]:%d+:") f = load(function () return nil end) - type_ok(f, 'function', "when reader returns nothing") + is_function(f, "when reader returns nothing") f, msg = load(function () return {} end) - is(f, nil, "reader function must return a string") - like(msg, "reader function must return a string") + is_nil(f, "reader function must return a string") + matches(msg, "reader function must return a string") if has_load52 then f = load([[ @@ -345,9 +345,9 @@ function bar (x) return x end ]]) - is(bar, nil, "function load(str)") + equals(bar, nil, "function load(str)") f() - is(bar('ok'), 'ok') + equals(bar('ok'), 'ok') bar = nil local env = {} @@ -356,21 +356,21 @@ function bar (x) return x end ]], "from string", 't', env) - is(env.bar, nil, "function load(str)") + equals(env.bar, nil, "function load(str)") f() - is(env.bar('ok'), 'ok') + equals(env.bar('ok'), 'ok') f, msg = load([[?syntax error?]], "errorchunk") - is(f, nil, "function load(syntax error)") - like(msg, "^%[string \"errorchunk\"%]:%d+:") + is_nil(f, "function load(syntax error)") + matches(msg, "^%[string \"errorchunk\"%]:%d+:") f, msg = load([[print 'ok']], "chunk txt", 'b') - like(msg, "attempt to load") - is(f, nil, "mode") + matches(msg, "attempt to load") + is_nil(f, "mode") f, msg = load("\x1bLua", "chunk bin", 't') - like(msg, "attempt to load") - is(f, nil, "mode") + matches(msg, "attempt to load") + is_nil(f, "mode") else diag("no load with string") end @@ -388,21 +388,21 @@ end ]] f:close() f = loadfile('foo-301.lua') - is(foo, nil, "function loadfile") + equals(foo, nil, "function loadfile") f() - is(foo('ok'), 'ok') + equals(foo('ok'), 'ok') if has_loadfile52 then local msg f, msg = loadfile('foo-301.lua', 'b') - like(msg, "attempt to load") - is(f, nil, "mode") + matches(msg, "attempt to load") + is_nil(f, "mode") local env = {} f = loadfile('foo-301.lua', 't', env) - is(env.foo, nil, "function loadfile") + equals(env.foo, nil, "function loadfile") f() - is(env.foo('ok'), 'ok') + equals(env.foo('ok'), 'ok') else diag("no loadfile with mode & env") end @@ -411,15 +411,15 @@ end local msg f, msg = loadfile('no_file-301.lua') - is(f, nil, "function loadfile (no file)") - is(msg, "cannot open no_file-301.lua: No such file or directory") + is_nil(f, "function loadfile (no file)") + equals(msg, "cannot open no_file-301.lua: No such file or directory") f = io.open('foo-301.lua', 'w') f:write[[?syntax error?]] f:close() f, msg = loadfile('foo-301.lua') - is(f, nil, "function loadfile (syntax error)") - like(msg, '^foo%-301%.lua:%d+:') + is_nil(f, "function loadfile (syntax error)") + matches(msg, '^foo%-301%.lua:%d+:') os.remove('foo-301.lua') -- clean up end @@ -428,187 +428,187 @@ if has_loadstring then local f = loadstring([[i = i + 1]]) i = 0 f() - is(i, 1, "function loadstring") + equals(i, 1, "function loadstring") f() - is(i, 2) + equals(i, 2) i = 32 local i = 0 f = loadstring([[i = i + 1; return i]]) local g = function () i = i + 1; return i end - is(f(), 33, "function loadstring") - is(g(), 1) + equals(f(), 33, "function loadstring") + equals(g(), 1) local msg f, msg = loadstring([[?syntax error?]]) - is(f, nil, "function loadstring (syntax error)") - like(msg, '^%[string "%?syntax error%?"%]:%d+:') + is_nil(f, "function loadstring (syntax error)") + matches(msg, '^%[string "%?syntax error%?"%]:%d+:') elseif has_alias_loadstring then - is(loadstring, load, "alias loadstring") + equals(loadstring, load, "alias loadstring") else - is(loadstring, nil, "no loadstring") + is_nil(loadstring, "no loadstring") end -- newproxy if has_newproxy then local proxy = newproxy(false) - type_ok(proxy, 'userdata', "function newproxy(false)") - is(getmetatable(proxy), nil, "without metatable") + is_userdata(proxy, "function newproxy(false)") + is_nil(getmetatable(proxy), "without metatable") proxy = newproxy(true) - type_ok(proxy, 'userdata', "function newproxy(true)") - type_ok(getmetatable(proxy), 'table', "with metatable") + is_userdata(proxy, "function newproxy(true)") + is_table(getmetatable(proxy), "with metatable") local proxy2 = newproxy(proxy) - type_ok(proxy, 'userdata', "function newproxy(proxy)") - is(getmetatable(proxy2), getmetatable(proxy)) + is_userdata(proxy, "function newproxy(proxy)") + equals(getmetatable(proxy2), getmetatable(proxy)) - error_like(function () newproxy({}) end, - "^[^:]+:%d+: bad argument #1 to 'newproxy' %(boolean or proxy expected%)", - "function newproxy({})") + error_matches(function () newproxy({}) end, + "^[^:]+:%d+: bad argument #1 to 'newproxy' %(boolean or proxy expected%)", + "function newproxy({})") else - is(newproxy, nil, "no newproxy") + is_nil(newproxy, "no newproxy") end do -- next local t = {'a','b','c'} local a = next(t, nil) - is(a, 1, "function next (array)") + equals(a, 1, "function next (array)") a = next(t, 1) - is(a, 2) + equals(a, 2) a = next(t, 2) - is(a, 3) + equals(a, 3) a = next(t, 3) - is(a, nil) + equals(a, nil) - error_like(function () a = next() end, - "^[^:]+:%d+: bad argument #1 to 'next' %(table expected, got no value%)", - "function next (no arg)") + error_matches(function () a = next() end, + "^[^:]+:%d+: bad argument #1 to 'next' %(table expected, got no value%)", + "function next (no arg)") - error_like(function () a = next(t, 6) end, - "invalid key to 'next'", - "function next (invalid key)") + error_matches(function () a = next(t, 6) end, + "invalid key to 'next'", + "function next (invalid key)") t = {'a','b','c'} a = next(t, 2) - is(a, 3, "function next (unorderer)") + equals(a, 3, "function next (unorderer)") a = next(t, 1) - is(a, 2) + equals(a, 2) a = next(t, 3) - is(a, nil) + equals(a, nil) t = {} a = next(t, nil) - is(a, nil, "function next (empty table)") + equals(a, nil, "function next (empty table)") end do -- pairs local a = {'a','b','c'} local f, v, s = pairs(a) - type_ok(f, 'function', "function pairs") - type_ok(v, 'table') - is(s, nil) + is_function(f, "function pairs") + is_table(v) + equals(s, nil) s = f(v, s) - is(s, 1) + equals(s, 1) s = f(v, s) - is(s, 2) + equals(s, 2) s = f(v, s) - is(s, 3) + equals(s, 3) s = f(v, s) - is(s, nil) + equals(s, nil) end do -- pcall local status, result = pcall(assert, 1) - is(status, true, "function pcall") - is(result, 1) + is_true(status, "function pcall") + equals(result, 1) status, result = pcall(assert, false, 'catched') - is(status, false) - is(result, 'catched') + is_false(status) + equals(result, 'catched') status = pcall(assert) - is(status, false) + is_false(status) end do -- rawequal local t = {} local a = t - is(rawequal(nil, nil), true, "function rawequal -> true") - is(rawequal(false, false), true) - is(rawequal(3, 3), true) - is(rawequal('text', 'text'), true) - is(rawequal(t, a), true) - is(rawequal(print, print), true) - - is(rawequal(nil, 2), false, "function rawequal -> false") - is(rawequal(false, true), false) - is(rawequal(false, 2), false) - is(rawequal(3, 2), false) - is(rawequal(3, '2'), false) - is(rawequal('text', '2'), false) - is(rawequal('text', 2), false) - is(rawequal(t, {}), false) - is(rawequal(t, 2), false) - is(rawequal(print, type), false) - is(rawequal(print, 2), false) + is_true(rawequal(nil, nil), "function rawequal -> true") + is_true(rawequal(false, false)) + is_true(rawequal(3, 3)) + is_true(rawequal('text', 'text')) + is_true(rawequal(t, a)) + is_true(rawequal(print, print)) + + is_false(rawequal(nil, 2), "function rawequal -> false") + is_false(rawequal(false, true)) + is_false(rawequal(false, 2)) + is_false(rawequal(3, 2)) + is_false(rawequal(3, '2')) + is_false(rawequal('text', '2')) + is_false(rawequal('text', 2)) + is_false(rawequal(t, {})) + is_false(rawequal(t, 2)) + is_false(rawequal(print, type)) + is_false(rawequal(print, 2)) end -- rawlen if has_rawlen then - is(rawlen("text"), 4, "function rawlen (string)") - is(rawlen({ 'a', 'b', 'c'}), 3, "function rawlen (table)") - error_like(function () local a = rawlen(true) end, - "^[^:]+:%d+: bad argument #1 to 'rawlen' %(table ", - "function rawlen (bad arg)") + equals(rawlen("text"), 4, "function rawlen (string)") + equals(rawlen({ 'a', 'b', 'c'}), 3, "function rawlen (table)") + error_matches(function () local a = rawlen(true) end, + "^[^:]+:%d+: bad argument #1 to 'rawlen' %(table ", + "function rawlen (bad arg)") else - is(rawlen, nil, "no rawlen") + is_nil(rawlen, "no rawlen") end do -- rawget local t = {a = 'letter a', b = 'letter b'} - is(rawget(t, 'a'), 'letter a', "function rawget") + equals(rawget(t, 'a'), 'letter a', "function rawget") end do -- rawset local t = {} - is(rawset(t, 'a', 'letter a'), t, "function rawset") - is(t.a, 'letter a') + equals(rawset(t, 'a', 'letter a'), t, "function rawset") + equals(t.a, 'letter a') - error_like(function () t = {}; rawset(t, nil, 42) end, - "^table index is nil", - "function rawset (table index is nil)") + error_matches(function () t = {}; rawset(t, nil, 42) end, + "^table index is nil", + "function rawset (table index is nil)") end do -- select - is(select('#'), 0, "function select") - is(select('#','a','b','c'), 3) - eq_array({select(1,'a','b','c')}, {'a','b','c'}) - eq_array({select(3,'a','b','c')}, {'c'}) - eq_array({select(5,'a','b','c')}, {}) - eq_array({select(-1,'a','b','c')}, {'c'}) - eq_array({select(-2,'a','b','c')}, {'b', 'c'}) - eq_array({select(-3,'a','b','c')}, {'a', 'b', 'c'}) + equals(select('#'), 0, "function select") + equals(select('#','a','b','c'), 3) + array_equals({select(1,'a','b','c')}, {'a','b','c'}) + array_equals({select(3,'a','b','c')}, {'c'}) + array_equals({select(5,'a','b','c')}, {}) + array_equals({select(-1,'a','b','c')}, {'c'}) + array_equals({select(-2,'a','b','c')}, {'b', 'c'}) + array_equals({select(-3,'a','b','c')}, {'a', 'b', 'c'}) - error_like(function () select(0,'a','b','c') end, - "^[^:]+:%d+: bad argument #1 to 'select' %(index out of range%)", - "function select (out of range)") + error_matches(function () select(0,'a','b','c') end, + "^[^:]+:%d+: bad argument #1 to 'select' %(index out of range%)", + "function select (out of range)") - error_like(function () select(-4,'a','b','c') end, - "^[^:]+:%d+: bad argument #1 to 'select' %(index out of range%)", - "function select (out of range)") + error_matches(function () select(-4,'a','b','c') end, + "^[^:]+:%d+: bad argument #1 to 'select' %(index out of range%)", + "function select (out of range)") end -- setfenv if has_getfenv then local t = {} local function f () end - is(setfenv(f, t), f, "function setfenv") - type_ok(getfenv(f), 'table') - is(getfenv(f), t) + equals(setfenv(f, t), f, "function setfenv") + is_table(getfenv(f)) + equals(getfenv(f), t) save = getfenv(1) a = 1 setfenv(1, {g = _G}) - g.is(a, nil, "function setfenv") - g.is(g.a, 1) + g.equals(a, nil, "function setfenv") + g.equals(g.a, 1) g.setfenv(1, g.save) -- restore save = getfenv(1) @@ -616,12 +616,12 @@ if has_getfenv then local newgt = {} -- create new environment setmetatable(newgt, {__index = _G}) setfenv(1, newgt) -- set it - is(a, 1, "function setfenv") + equals(a, 1, "function setfenv") a = 10 - is(a, 10) - is(_G.a, 1) + equals(a, 10) + equals(_G.a, 1) _G.a = 20 - is(_G.a, 20) + equals(_G.a, 20) setfenv(1, save) -- restore save = getfenv(1) @@ -633,165 +633,165 @@ if has_getfenv then a = 3 local f1 = factory() local f2 = factory() - is(f1(), 3, "function setfenv") - is(f2(), 3) + equals(f1(), 3, "function setfenv") + equals(f2(), 3) setfenv(f1, {a = 10}) - is(f1(), 10) - is(f2(), 3) + equals(f1(), 10) + equals(f2(), 3) setfenv(1, save) -- restore - is(setfenv(0, _G), nil, "function setfenv(0)") + equals(setfenv(0, _G), nil, "function setfenv(0)") - error_like(function () setfenv(-3, {}) end, - "^[^:]+:%d+: bad argument #1 to 'setfenv' %(.-level.-%)", - "function setfenv (negative)") + error_matches(function () setfenv(-3, {}) end, + "^[^:]+:%d+: bad argument #1 to 'setfenv' %(.-level.-%)", + "function setfenv (negative)") - error_like(function () setfenv(12, {}) end, - "^[^:]+:%d+: bad argument #1 to 'setfenv' %(invalid level%)", - "function setfenv (too depth)") + error_matches(function () setfenv(12, {}) end, + "^[^:]+:%d+: bad argument #1 to 'setfenv' %(invalid level%)", + "function setfenv (too depth)") t = {} - error_like(function () setfenv(t, {}) end, - "^[^:]+:%d+: bad argument #1 to 'setfenv' %(number expected, got table%)", - "function setfenv (bad arg)") + error_matches(function () setfenv(t, {}) end, + "^[^:]+:%d+: bad argument #1 to 'setfenv' %(number expected, got table%)", + "function setfenv (bad arg)") - error_like(function () setfenv(print, {}) end, - "^[^:]+:%d+: 'setfenv' cannot change environment of given object", - "function setfenv (forbidden)") + error_matches(function () setfenv(print, {}) end, + "^[^:]+:%d+: 'setfenv' cannot change environment of given object", + "function setfenv (forbidden)") else - is(setfenv, nil, "no setfenv") + is_nil(setfenv, "no setfenv") end do -- setmetatable local mt = {} local t = {} - is(t, setmetatable(t, mt), "setmetatable") - is(getmetatable(t), mt) - is(t, setmetatable(t, nil)) - is(getmetatable(t), nil) + equals(t, setmetatable(t, mt), "setmetatable") + equals(getmetatable(t), mt) + equals(t, setmetatable(t, nil)) + equals(getmetatable(t), nil) - error_like(function () setmetatable(t, true) end, - "^[^:]+:%d+: bad argument #2 to 'setmetatable' %(nil or table expected", - "function setmetatable (bad arg)") - error_like(function () setmetatable(true, mt) end, - "^[^:]+:%d+: bad argument #1 to 'setmetatable' %(table expected, got boolean%)", - "function setmetatable (bad arg)") + error_matches(function () setmetatable(t, true) end, + "^[^:]+:%d+: bad argument #2 to 'setmetatable' %(nil or table expected", + "function setmetatable (bad arg)") + error_matches(function () setmetatable(true, mt) end, + "^[^:]+:%d+: bad argument #1 to 'setmetatable' %(table expected, got boolean%)", + "function setmetatable (bad arg)") end do -- type - is(type("Hello world"), 'string', "function type") - is(type(10.4*3), 'number') - is(type(print), 'function') - is(type(type), 'function') - is(type(true), 'boolean') - is(type(nil), 'nil') - is(type(io.stdin), 'userdata') - is(type(type(X)), 'string') + equals(type("Hello world"), 'string', "function type") + equals(type(10.4*3), 'number') + equals(type(print), 'function') + equals(type(type), 'function') + equals(type(true), 'boolean') + equals(type(nil), 'nil') + equals(type(io.stdin), 'userdata') + equals(type(type(X)), 'string') local a = nil - is(type(a), 'nil', "function type") + equals(type(a), 'nil', "function type") a = 10 - is(type(a), 'number') + equals(type(a), 'number') a = "a string!!" - is(type(a), 'string') + equals(type(a), 'string') a = print - is(type(a), 'function') - is(type(function () end), 'function') + equals(type(a), 'function') + equals(type(function () end), 'function') - error_like(function () type() end, - "^[^:]+:%d+: bad argument #1 to 'type' %(value expected%)", - "function type (no arg)") + error_matches(function () type() end, + "^[^:]+:%d+: bad argument #1 to 'type' %(value expected%)", + "function type (no arg)") end do -- tonumber - is(tonumber('text12'), nil, "function tonumber") - is(tonumber('12text'), nil) - is(tonumber(3.14), 3.14) - is(tonumber('3.14'), 3.14) - is(tonumber(' 3.14 '), 3.14) - is(tonumber(tostring(111), 2), 7) - is(tonumber('111', 2), 7) - is(tonumber(' 111 ', 2), 7) + equals(tonumber('text12'), nil, "function tonumber") + equals(tonumber('12text'), nil) + equals(tonumber(3.14), 3.14) + equals(tonumber('3.14'), 3.14) + equals(tonumber(' 3.14 '), 3.14) + equals(tonumber(tostring(111), 2), 7) + equals(tonumber('111', 2), 7) + equals(tonumber(' 111 ', 2), 7) local a = {} - is(tonumber(a), nil) + equals(tonumber(a), nil) - error_like(function () tonumber() end, - "^[^:]+:%d+: bad argument #1 to 'tonumber' %(value expected%)", - "function tonumber (no arg)") + error_matches(function () tonumber() end, + "^[^:]+:%d+: bad argument #1 to 'tonumber' %(value expected%)", + "function tonumber (no arg)") - error_like(function () tonumber('111', 200) end, - "^[^:]+:%d+: bad argument #2 to 'tonumber' %(base out of range%)", - "function tonumber (bad base)") + error_matches(function () tonumber('111', 200) end, + "^[^:]+:%d+: bad argument #2 to 'tonumber' %(base out of range%)", + "function tonumber (bad base)") end do -- tostring - is(tostring('text'), 'text', "function tostring") - is(tostring(3.14), '3.14') - is(tostring(nil), 'nil') - is(tostring(true), 'true') - is(tostring(false), 'false') - like(tostring({}), '^table: 0?[Xx]?%x+$') - like(tostring(print), '^function: 0?[Xx]?[builtin]*#?%x+$') + equals(tostring('text'), 'text', "function tostring") + equals(tostring(3.14), '3.14') + equals(tostring(nil), 'nil') + equals(tostring(true), 'true') + equals(tostring(false), 'false') + matches(tostring({}), '^table: 0?[Xx]?%x+$') + matches(tostring(print), '^function: 0?[Xx]?[builtin]*#?%x+$') - error_like(function () tostring() end, - "^[^:]+:%d+: bad argument #1 to 'tostring' %(value expected%)", - "function tostring (no arg)") + error_matches(function () tostring() end, + "^[^:]+:%d+: bad argument #1 to 'tostring' %(value expected%)", + "function tostring (no arg)") end -- unpack if has_unpack then - eq_array({unpack({})}, {}, "function unpack") - eq_array({unpack({'a'})}, {'a'}) - eq_array({unpack({'a','b','c'})}, {'a','b','c'}) - eq_array({(unpack({'a','b','c'}))}, {'a'}) - eq_array({unpack({'a','b','c','d','e'},2,4)}, {'b','c','d'}) - eq_array({unpack({'a','b','c'},2,4)}, {'b','c'}) + array_equals({unpack({})}, {}, "function unpack") + array_equals({unpack({'a'})}, {'a'}) + array_equals({unpack({'a','b','c'})}, {'a','b','c'}) + array_equals({(unpack({'a','b','c'}))}, {'a'}) + array_equals({unpack({'a','b','c','d','e'},2,4)}, {'b','c','d'}) + array_equals({unpack({'a','b','c'},2,4)}, {'b','c'}) elseif has_alias_unpack then - is(unpack, table.unpack, "alias unpack") + equals(unpack, table.unpack, "alias unpack") else - is(unpack, nil, "no unpack") + is_nil(unpack, "no unpack") end -- warn if has_warn then - is(warn('foo'), nil, "function warn") + equals(warn('foo'), nil, "function warn") local r, f = pcall(io.popen, lua .. [[ -W -e "warn'foo'" 2>&1]]) if r then - is(f:read'*l', 'Lua warning: foo', "warn called with popen") - is(f:read'*l', nil) - is(f:close(), true) + equals(f:read'*l', 'Lua warning: foo', "warn called with popen") + equals(f:read'*l', nil) + equals(f:close(), true) else diag("io.popen not supported") end r, f = pcall(io.popen, lua .. [[ -e "warn'@on'; warn'foo'" 2>&1]]) if r then - is(f:read'*l', 'Lua warning: foo', "warn called with popen") - is(f:read'*l', nil) - is(f:close(), true) + equals(f:read'*l', 'Lua warning: foo', "warn called with popen") + equals(f:read'*l', nil) + equals(f:close(), true) else diag("io.popen not supported") end r, f = pcall(io.popen, lua .. [[ -e "warn'@on'; warn('foo', 'bar')" 2>&1]]) if r then - is(f:read'*l', 'Lua warning: foobar', "warn called with popen") - is(f:read'*l', nil) - is(f:close(), true) + equals(f:read'*l', 'Lua warning: foobar', "warn called with popen") + equals(f:read'*l', nil) + equals(f:close(), true) else diag("io.popen not supported") end - error_like(function () warn('foo', warn) end, - "^[^:]+:%d+: bad argument #2 to 'warn' %(string expected, got function%)", - "function warn (no arg)") + error_matches(function () warn('foo', warn) end, + "^[^:]+:%d+: bad argument #2 to 'warn' %(string expected, got function%)", + "function warn (no arg)") - error_like(function () warn() end, - "^[^:]+:%d+: bad argument #1 to 'warn' %(string expected, got no value%)", - "function warn (no arg)") + error_matches(function () warn() end, + "^[^:]+:%d+: bad argument #1 to 'warn' %(string expected, got no value%)", + "function warn (no arg)") else - is(warn, nil, "no warn") + is_nil(warn, "no warn") end do -- xpcall @@ -804,41 +804,41 @@ do -- xpcall end local status, result = xpcall(function () return assert(1) end, err) - is(status, true, "function xpcall") - is(result, 1) + is_true(status, "function xpcall") + equals(result, 1) status, result = xpcall(function () return assert(false, 'catched') end, err) - is(status, false) + is_false(status) if jit then - is(result, 'catched') + equals(result, 'catched') else - like(result, ':%d+: catched') + matches(result, ':%d+: catched') end status, result = xpcall(function () return assert(false, 'catched') end, backtrace) - is(status, false) - is(result, 'not a back trace') + is_false(status) + equals(result, 'not a back trace') if has_xpcall52 then status, result = xpcall(assert, err, 1) - is(status, true, "function xpcall with args") - is(result, 1) + is_true(status, "function xpcall with args") + equals(result, 1) status, result = xpcall(assert, err, false, 'catched') - is(status, false) - is(result, 'catched') + is_false(status) + equals(result, 'catched') status, result = xpcall(assert, backtrace, false, 'catched') - is(status, false) - is(result, 'not a back trace') + is_false(status) + equals(result, 'not a back trace') end - error_like(function () xpcall(assert) end, - "bad argument #2 to 'xpcall' %(.-", - "function xpcall") + error_matches(function () xpcall(assert) end, + "bad argument #2 to 'xpcall' %(.-", + "function xpcall") if has_xpcall53 then - error_like(function () xpcall(assert, 1) end, - "bad argument #2 to 'xpcall' %(function expected, got number%)", - "function xpcall") + error_matches(function () xpcall(assert, 1) end, + "bad argument #2 to 'xpcall' %(function expected, got number%)", + "function xpcall") else - is(xpcall(assert, nil), false, "function xpcall") + is_false(xpcall(assert, nil), "function xpcall") end end diff --git a/test/lua-Harness-tests/303-package.t b/test/lua-Harness-tests/303-package.t index 7e5216d8..1a1d7e05 100755 --- a/test/lua-Harness-tests/303-package.t +++ b/test/lua-Harness-tests/303-package.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -45,45 +45,45 @@ local has_require54 = _VERSION >= 'Lua 5.4' plan'no_plan' -type_ok(package.config, 'string') +is_string(package.config) -type_ok(package.cpath, 'string') +is_string(package.cpath) -type_ok(package.path, 'string') +is_string(package.path) if has_loaders then - type_ok(package.loaders, 'table', "table package.loaders") + is_table(package.loaders, "table package.loaders") elseif has_alias_loaders then - is(package.loaders, package.searchers, "alias package.loaders") + equals(package.loaders, package.searchers, "alias package.loaders") else - is(package.loaders, nil, "no package.loaders") + is_nil(package.loaders, "no package.loaders") end if has_searchers then - type_ok(package.searchers, 'table', "table package.searchers") + is_table(package.searchers, "table package.searchers") elseif has_alias_searchers then - is(package.searchers, package.loaders, "alias package.searchers") + equals(package.searchers, package.loaders, "alias package.searchers") else - is(package.searchers, nil, "no package.searchers") + is_nil(package.searchers, "no package.searchers") end do -- loaded - ok(package.loaded._G, "table package.loaded") - ok(package.loaded.coroutine) - ok(package.loaded.io) - ok(package.loaded.math) - ok(package.loaded.os) - ok(package.loaded.package) - ok(package.loaded.string) - ok(package.loaded.table) + truthy(package.loaded._G, "table package.loaded") + truthy(package.loaded.coroutine) + truthy(package.loaded.io) + truthy(package.loaded.math) + truthy(package.loaded.os) + truthy(package.loaded.package) + truthy(package.loaded.string) + truthy(package.loaded.table) local m = require'os' - is(m, package.loaded['os']) + equals(m, package.loaded['os']) end do -- preload - type_ok(package.preload, 'table', "table package.preload") - is(# package.preload, 0) + is_table(package.preload, "table package.preload") + equals(# package.preload, 0) local foo = {} foo.bar = 1234 @@ -93,35 +93,35 @@ do -- preload package.preload.foo = foo_loader local m = require 'foo' assert(m == foo) - is(m.bar, 1234, "function require & package.preload") + equals(m.bar, 1234, "function require & package.preload") end do -- loadlib local path_lpeg = package.searchpath and package.searchpath('lpeg', package.cpath) local f, msg = package.loadlib('libbar', 'baz') - is(f, nil, "loadlib") - type_ok(msg, 'string') + is_nil(f, "loadlib") + is_string(msg) if path_lpeg then f, msg = package.loadlib(path_lpeg, 'baz') - is(f, nil, "loadlib") - like(msg, 'undefined symbol') + is_nil(f, "loadlib") + matches(msg, 'undefined symbol') f = package.loadlib(path_lpeg, 'luaopen_lpeg') - type_ok(f, 'function', "loadlib ok") + is_function(f, "loadlib ok") else skip("no lpeg path") end if has_loadlib52 then f, msg = package.loadlib('libbar', '*') - is(f, nil, "loadlib '*'") - type_ok(msg, 'string') + is_nil(f, "loadlib '*'") + is_string(msg) if path_lpeg then f = package.loadlib(path_lpeg, '*') - is(f, true, "loadlib '*'") + is_true(f, "loadlib '*'") else skip("no lpeg path") end @@ -131,11 +131,12 @@ end -- searchpath if has_searcherpath then local p = package.searchpath('tap', package.path) - type_ok(p, 'string', "searchpath") + is_string(p, "searchpath") + matches(p, "tap.lua$", "searchpath") p = package.searchpath('tap', 'bad path') - is(p, nil) + is_nil(p) else - is(package.searchpath, nil, "no package.searchpath") + is_nil(package.searchpath, "no package.searchpath") end do -- require @@ -175,31 +176,31 @@ return complex f:close() if has_require54 then local m1, path1 = require 'complex' - is(m1, complex, "function require") - is(path1, './complex.lua') + equals(m1, complex, "function require") + equals(path1, './complex.lua') local m2, path2 = require 'complex' - is(m1, m2) - is(path2, nil) + equals(m1, m2) + equals(path2, nil) else local m1 = require 'complex' - is(m1, complex, "function require") + equals(m1, complex, "function require") local m2 = require 'complex' - is(m1, m2) + equals(m1, m2) end - is(complex.i.r, 0) - is(complex.i.i, 1) + equals(complex.i.r, 0) + equals(complex.i.i, 1) os.remove('complex.lua') -- clean up - error_like(function () require('no_module') end, - "^[^:]+:%d+: module 'no_module' not found:", - "function require (no module)") + error_matches(function () require('no_module') end, + "^[^:]+:%d+: module 'no_module' not found:", + "function require (no module)") f = io.open('syntax.lua', 'w') f:write [[?syntax error?]] f:close() - error_like(function () require('syntax') end, - "^error loading module 'syntax' from file '%.[/\\]syntax%.lua':", - "function require (syntax error)") + error_matches(function () require('syntax') end, + "^error loading module 'syntax' from file '%.[/\\]syntax%.lua':", + "function require (syntax error)") os.remove('syntax.lua') -- clean up f = io.open('bar.lua', 'w') @@ -210,7 +211,7 @@ return complex f:close() a = nil require 'bar' - is(a, 'bar', "function require (arg)") + equals(a, 'bar', "function require (arg)") os.remove('bar.lua') -- clean up f = io.open('cplx.lua', 'w') @@ -253,8 +254,8 @@ return cplx ]] f:close() require 'cplx' - is(cplx.i.r, 0, "function require & module") - is(cplx.i.i, 1) + equals(cplx.i.r, 0, "function require & module") + equals(cplx.i.i, 1) os.remove('cplx.lua') -- clean up end @@ -263,21 +264,21 @@ local done_testing = done_testing if has_module then m = {} package.seeall(m) - m.pass("function package.seeall") + m.passes("function package.seeall") - is(mod, nil, "function module & seeall") + is_nil(mod, "function module & seeall") module('mod', package.seeall) - type_ok(mod, 'table') - is(mod, package.loaded.mod) + is_table(mod) + equals(mod, package.loaded.mod) - is(modz, nil, "function module") + is_nil(modz, "function module") local _G = _G module('modz') - _G.type_ok(_G.modz, 'table') - _G.is(_G.modz, _G.package.loaded.modz) + _G.is_table(_G.modz) + _G.equals(_G.modz, _G.package.loaded.modz) else - is(package.seeall, nil, "package.seeall (removed)") - is(module, nil, "module (removed)") + is_nil(package.seeall, "package.seeall (removed)") + is_nil(module, "module (removed)") end done_testing() diff --git a/test/lua-Harness-tests/304-string.t b/test/lua-Harness-tests/304-string.t index 991600a7..7011a88e 100755 --- a/test/lua-Harness-tests/304-string.t +++ b/test/lua-Harness-tests/304-string.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -49,79 +49,79 @@ plan'no_plan' do -- metatable local mt = getmetatable('ABC') - type_ok(mt, 'table', "metatable") - type_ok(mt.__index, 'table') + is_table(mt, "metatable") + is_table(mt.__index) if not profile.nocvts2n and _VERSION >= 'Lua 5.4' then - type_ok(mt.__add, 'function') - type_ok(mt.__div, 'function') - type_ok(mt.__idiv, 'function') - type_ok(mt.__mul, 'function') - type_ok(mt.__mod, 'function') - type_ok(mt.__pow, 'function') - type_ok(mt.__sub, 'function') - type_ok(mt.__unm, 'function') + is_function(mt.__add) + is_function(mt.__div) + is_function(mt.__idiv) + is_function(mt.__mul) + is_function(mt.__mod) + is_function(mt.__pow) + is_function(mt.__sub) + is_function(mt.__unm) else - is(mt.__add, nil) - is(mt.__div, nil) - is(mt.__idiv, nil) - is(mt.__mul, nil) - is(mt.__mod, nil) - is(mt.__pow, nil) - is(mt.__sub, nil) - is(mt.__unm, nil) + is_nil(mt.__add) + is_nil(mt.__div) + is_nil(mt.__idiv) + is_nil(mt.__mul) + is_nil(mt.__mod) + is_nil(mt.__pow) + is_nil(mt.__sub) + is_nil(mt.__unm) end - is(mt.__index.byte, string.byte) - is(mt.__index.char, string.char) - is(mt.__index.dump, string.dump) - is(mt.__index.find, string.find) - is(mt.__index.format, string.format) - is(mt.__index.gmatch, string.gmatch) - is(mt.__index.gsub, string.gsub) - is(mt.__index.len, string.len) - is(mt.__index.lower, string.lower) - is(mt.__index.match, string.match) - is(mt.__index.rep, string.rep) - is(mt.__index.reverse, string.reverse) - is(mt.__index.sub, string.sub) - is(mt.__index.upper, string.upper) + equals(mt.__index.byte, string.byte) + equals(mt.__index.char, string.char) + equals(mt.__index.dump, string.dump) + equals(mt.__index.find, string.find) + equals(mt.__index.format, string.format) + equals(mt.__index.gmatch, string.gmatch) + equals(mt.__index.gsub, string.gsub) + equals(mt.__index.len, string.len) + equals(mt.__index.lower, string.lower) + equals(mt.__index.match, string.match) + equals(mt.__index.rep, string.rep) + equals(mt.__index.reverse, string.reverse) + equals(mt.__index.sub, string.sub) + equals(mt.__index.upper, string.upper) if has_pack then - is(mt.__index.pack, string.pack) - is(mt.__index.packsize, string.packsize) - is(mt.__index.unpack, string.unpack) + equals(mt.__index.pack, string.pack) + equals(mt.__index.packsize, string.packsize) + equals(mt.__index.unpack, string.unpack) else - is(mt.__index.pack, nil) - is(mt.__index.packsize, nil) - is(mt.__index.unpack, nil) + is_nil(mt.__index.pack) + is_nil(mt.__index.packsize) + is_nil(mt.__index.unpack) end end do -- byte - is(string.byte('ABC'), 65, "function byte") - is(string.byte('ABC', 2), 66) - is(string.byte('ABC', -1), 67) - is(string.byte('ABC', 4), nil) - is(string.byte('ABC', 0), nil) - eq_array({string.byte('ABC', 1, 3)}, {65, 66, 67}) - eq_array({string.byte('ABC', 1, 4)}, {65, 66, 67}) + equals(string.byte('ABC'), 65, "function byte") + equals(string.byte('ABC', 2), 66) + equals(string.byte('ABC', -1), 67) + equals(string.byte('ABC', 4), nil) + equals(string.byte('ABC', 0), nil) + array_equals({string.byte('ABC', 1, 3)}, {65, 66, 67}) + array_equals({string.byte('ABC', 1, 4)}, {65, 66, 67}) local s = "ABC" - is(s:byte(2), 66, "method s:byte") + equals(s:byte(2), 66, "method s:byte") end do -- char - is(string.char(65, 66, 67), 'ABC', "function char") - is(string.char(), '') + equals(string.char(65, 66, 67), 'ABC', "function char") + equals(string.char(), '') - error_like(function () string.char(0, 'bad') end, - "^[^:]+:%d+: bad argument #2 to 'char' %(number expected, got string%)", - "function char (bad arg)") + error_matches(function () string.char(0, 'bad') end, + "^[^:]+:%d+: bad argument #2 to 'char' %(number expected, got string%)", + "function char (bad arg)") - error_like(function () string.char(0, 9999) end, - "^[^:]+:%d+: bad argument #2 to 'char' %(.-value.-%)", - "function char (invalid)") + error_matches(function () string.char(0, 9999) end, + "^[^:]+:%d+: bad argument #2 to 'char' %(.-value.-%)", + "function char (invalid)") end do -- dump @@ -139,176 +139,176 @@ do -- dump end local d = string.dump(add) - type_ok(d, 'string', "function dump") + is_string(d, "function dump") local f = loadstring(d) - type_ok(f, 'function') - is(f(1, 2), 3) + is_function(f) + equals(f(1, 2), 3) if signature then local sig = d:sub(1, #signature) - is(sig, signature) + equals(sig, signature) end if has_dump53 then local d2 = string.dump(add, true) - type_ok(d2, 'string', "function dump with strip") + is_string(d2, "function dump with strip") f = loadstring(d2) - type_ok(f, 'function') - is(f(1, 2), 3) - isnt(d2:len(), d:len()) + is_function(f) + equals(f(1, 2), 3) + not_equals(d2:len(), d:len()) if signature then local sig = d2:sub(1, #signature) - is(sig, signature) + equals(sig, signature) end end - error_like(function () string.dump(print) end, - "^[^:]+:%d+: unable to dump given function", - "function dump (C function)") + error_matches(function () string.dump(print) end, + "^[^:]+:%d+: unable to dump given function", + "function dump (C function)") end do -- find local s = "hello world" - eq_array({string.find(s, "hello")}, {1, 5}, "function find (mode plain)") - eq_array({string.find(s, "hello", 1, true)}, {1, 5}) - eq_array({string.find(s, "hello", 1)}, {1, 5}) - is(string.sub(s, 1, 5), "hello") - eq_array({string.find(s, "world")}, {7, 11}) - eq_array({string.find(s, "l")}, {3, 3}) - is(string.find(s, "lll"), nil) - is(string.find(s, "hello", 2, true), nil) - eq_array({string.find(s, "world", 2, true)}, {7, 11}) - is(string.find(s, "hello", 20), nil) + array_equals({string.find(s, "hello")}, {1, 5}, "function find (mode plain)") + array_equals({string.find(s, "hello", 1, true)}, {1, 5}) + array_equals({string.find(s, "hello", 1)}, {1, 5}) + equals(string.sub(s, 1, 5), "hello") + array_equals({string.find(s, "world")}, {7, 11}) + array_equals({string.find(s, "l")}, {3, 3}) + equals(string.find(s, "lll"), nil) + equals(string.find(s, "hello", 2, true), nil) + array_equals({string.find(s, "world", 2, true)}, {7, 11}) + equals(string.find(s, "hello", 20), nil) s = "hello world" - eq_array({string.find(s, "^h.ll.")}, {1, 5}, "function find (with regex & captures)") - eq_array({string.find(s, "w.rld", 2)}, {7, 11}) - is(string.find(s, "W.rld"), nil) - eq_array({string.find(s, "^(h.ll.)")}, {1, 5, 'hello'}) - eq_array({string.find(s, "^(h.)l(l.)")}, {1, 5, 'he', 'lo'}) + array_equals({string.find(s, "^h.ll.")}, {1, 5}, "function find (with regex & captures)") + array_equals({string.find(s, "w.rld", 2)}, {7, 11}) + equals(string.find(s, "W.rld"), nil) + array_equals({string.find(s, "^(h.ll.)")}, {1, 5, 'hello'}) + array_equals({string.find(s, "^(h.)l(l.)")}, {1, 5, 'he', 'lo'}) s = "Deadline is 30/05/1999, firm" local date = "%d%d/%d%d/%d%d%d%d" - is(string.sub(s, string.find(s, date)), "30/05/1999") + equals(string.sub(s, string.find(s, date)), "30/05/1999") date = "%f[%S]%d%d/%d%d/%d%d%d%d" - is(string.sub(s, string.find(s, date)), "30/05/1999") + equals(string.sub(s, string.find(s, date)), "30/05/1999") - error_like(function () string.find(s, '%f') end, - "^[^:]+:%d+: missing '%[' after '%%f' in pattern", - "function find (invalid frontier)") + error_matches(function () string.find(s, '%f') end, + "^[^:]+:%d+: missing '%[' after '%%f' in pattern", + "function find (invalid frontier)") end do -- format - is(string.format("pi = %.4f", math.pi), 'pi = 3.1416', "function format") + equals(string.format("pi = %.4f", math.pi), 'pi = 3.1416', "function format") local d = 5; local m = 11; local y = 1990 - is(string.format("%02d/%02d/%04d", d, m, y), "05/11/1990") - is(string.format("%X %x", 126, 126), "7E 7e") + equals(string.format("%02d/%02d/%04d", d, m, y), "05/11/1990") + equals(string.format("%X %x", 126, 126), "7E 7e") local tag, title = "h1", "a title" - is(string.format("<%s>%s", tag, title, tag), "

a title

") + equals(string.format("<%s>%s", tag, title, tag), "

a title

") - is(string.format('%q', 'a string with "quotes" and \n new line'), [["a string with \"quotes\" and \ + equals(string.format('%q', 'a string with "quotes" and \n new line'), [["a string with \"quotes\" and \ new line"]], "function format %q") if has_format_q52 then - is(string.format('%q', 'a string with \0 and \r.'), [["a string with \0 and \13."]], "function format %q") - is(string.format('%q', 'a string with \b and \b2'), [["a string with \8 and \0082"]], "function format %q") + equals(string.format('%q', 'a string with \0 and \r.'), [["a string with \0 and \13."]], "function format %q") + equals(string.format('%q', 'a string with \b and \b2'), [["a string with \8 and \0082"]], "function format %q") else - is(string.format('%q', 'a string with \0 and \r.'), [["a string with \000 and \r."]], "function format %q") - is(string.format('%q', 'a string with \b and \b2'), '"a string with \b and \b2"', "function format %q") + equals(string.format('%q', 'a string with \0 and \r.'), [["a string with \000 and \r."]], "function format %q") + equals(string.format('%q', 'a string with \b and \b2'), '"a string with \b and \b2"', "function format %q") end if has_format_q53 then - is(string.format('%q', 1.5), '0x1.8p+0', "function format %q") - is(string.format('%q', 7), '7', "function format %q") + equals(string.format('%q', 1.5), '0x1.8p+0', "function format %q") + equals(string.format('%q', 7), '7', "function format %q") else - is(string.format('%q', 1.5), [["1.5"]], "function format %q") - is(string.format('%q', 7), [["7"]], "function format %q") + equals(string.format('%q', 1.5), [["1.5"]], "function format %q") + equals(string.format('%q', 7), [["7"]], "function format %q") end if has_format_q53 then - is(string.format('%q', nil), 'nil', "function format ('%q', nil)") + equals(string.format('%q', nil), 'nil', "function format ('%q', nil)") elseif luajit21 then - is(string.format('%q', nil), [["nil"]], "function format ('%q', nil)") + equals(string.format('%q', nil), [["nil"]], "function format ('%q', nil)") else - error_like(function () string.format("%q", nil) end, - "^[^:]+:%d+: bad argument #2 to 'format' %(", - "function format ('%q', nil)") + error_matches(function () string.format("%q", nil) end, + "^[^:]+:%d+: bad argument #2 to 'format' %(", + "function format ('%q', nil)") end if has_format_q54 then - is(string.format('%q', 0/0), '(0/0)', "function format ('%q', NaN)") - is(string.format('%q', 1/0), '1e9999', "function format ('%q', +Inf)") - is(string.format('%q', -1/0), '-1e9999', "function format ('%q', -Inf)") + equals(string.format('%q', 0/0), '(0/0)', "function format ('%q', NaN)") + equals(string.format('%q', 1/0), '1e9999', "function format ('%q', +Inf)") + equals(string.format('%q', -1/0), '-1e9999', "function format ('%q', -Inf)") - error_like(function () string.format("%-q", 0) end, - "^[^:]+:%d+: specifier '%%q' cannot have modifiers", - "function format '%-q'") + error_matches(function () string.format("%-q", 0) end, + "^[^:]+:%d+: specifier '%%q' cannot have modifiers", + "function format '%-q'") end if luajit21 then - like(string.format('%q', {}), [[^"table: ]], "function format ('%q', {})") + matches(string.format('%q', {}), [[^"table: ]], "function format ('%q', {})") else - error_like(function () string.format("%q", {}) end, - "^[^:]+:%d+: bad argument #2 to 'format' %(", - "function format ('%q', {})") + error_matches(function () string.format("%q", {}) end, + "^[^:]+:%d+: bad argument #2 to 'format' %(", + "function format ('%q', {})") end if has_format_a then - is(string.format('%a', 1.5), '0x1.8p+0', "function format %a") + equals(string.format('%a', 1.5), '0x1.8p+0', "function format %a") end if has_format_p then - is(string.format('table: %p', string), tostring(string), "function format %p") + equals(string.format('table: %p', string), tostring(string), "function format %p") end - is(string.format("%5s", 'foo'), ' foo', "function format (%5s)") + equals(string.format("%5s", 'foo'), ' foo', "function format (%5s)") if _VERSION >= 'Lua 5.3' then - error_like(function () string.format("%5s", "foo\0bar") end, - "^[^:]+:%d+: bad argument #2 to 'format' %(string contains zeros%)", - "function format format (%5s with \\0)") + error_matches(function () string.format("%5s", "foo\0bar") end, + "^[^:]+:%d+: bad argument #2 to 'format' %(string contains zeros%)", + "function format format (%5s with \\0)") end - is(string.format("%s %s", 1, 2, 3), '1 2', "function format (too many arg)") + equals(string.format("%s %s", 1, 2, 3), '1 2', "function format (too many arg)") - is(string.format("%% %c %%", 65), '% A %', "function format (%%)") + equals(string.format("%% %c %%", 65), '% A %', "function format (%%)") local r = string.rep("ab", 100) - is(string.format("%s %d", r, r:len()), r .. " 200") + equals(string.format("%s %d", r, r:len()), r .. " 200") - error_like(function () string.format("%s %s", 1) end, - "^[^:]+:%d+: bad argument #3 to 'format' %(.-no value%)", - "function format (too few arg)") + error_matches(function () string.format("%s %s", 1) end, + "^[^:]+:%d+: bad argument #3 to 'format' %(.-no value%)", + "function format (too few arg)") - error_like(function () string.format('%d', 'toto') end, - "^[^:]+:%d+: bad argument #2 to 'format' %(number expected, got string%)", - "function format (bad arg)") + error_matches(function () string.format('%d', 'toto') end, + "^[^:]+:%d+: bad argument #2 to 'format' %(number expected, got string%)", + "function format (bad arg)") - error_like(function () string.format('%k', 'toto') end, - "^[^:]+:%d+: invalid .- '%%k' to 'format'", - "function format (invalid conversion)") + error_matches(function () string.format('%k', 'toto') end, + "^[^:]+:%d+: invalid .- '%%k' to 'format'", + "function format (invalid conversion)") if luajit21 then - error_like(function () string.format('%111s', 'toto') end, - "^[^:]+:%d+: invalid option '%%111' to 'format'", - "function format (invalid format)") + error_matches(function () string.format('%111s', 'toto') end, + "^[^:]+:%d+: invalid option '%%111' to 'format'", + "function format (invalid format)") else - error_like(function () string.format('%111s', 'toto') end, - "^[^:]+:%d+: invalid format %(width or precision too long%)", - "function format (invalid format)") + error_matches(function () string.format('%111s', 'toto') end, + "^[^:]+:%d+: invalid format %(width or precision too long%)", + "function format (invalid format)") - error_like(function () string.format('%------s', 'toto') end, - "^[^:]+:%d+: invalid format %(repeated flags%)", - "function format (invalid format)") + error_matches(function () string.format('%------s', 'toto') end, + "^[^:]+:%d+: invalid format %(repeated flags%)", + "function format (invalid format)") end - error_like(function () string.format('pi = %.123f', math.pi) end, - "^[^:]+:%d+: invalid ", - "function format (invalid format)") + error_matches(function () string.format('pi = %.123f', math.pi) end, + "^[^:]+:%d+: invalid ", + "function format (invalid format)") - error_like(function () string.format('% 123s', 'toto') end, - "^[^:]+:%d+: invalid ", - "function format (invalid format)") + error_matches(function () string.format('% 123s', 'toto') end, + "^[^:]+:%d+: invalid ", + "function format (invalid format)") end do -- gmatch @@ -317,99 +317,99 @@ do -- gmatch for c in string.gmatch(s, '..') do table.insert(output, c) end - eq_array(output, {'he', 'll'}, "function gmatch") + array_equals(output, {'he', 'll'}, "function gmatch") if has_gmatch54 then output = {} for c in string.gmatch(s, '..', 2) do table.insert(output, c) end - eq_array(output, {'el', 'lo'}) + array_equals(output, {'el', 'lo'}) end output = {} for c1, c2 in string.gmatch(s, '(.)(.)') do table.insert(output, c1) table.insert(output, c2) end - eq_array(output, {'h', 'e', 'l', 'l'}) + array_equals(output, {'h', 'e', 'l', 'l'}) s = "hello world from Lua" output = {} for w in string.gmatch(s, '%a+') do table.insert(output, w) end - eq_array(output, {'hello', 'world', 'from', 'Lua'}) + array_equals(output, {'hello', 'world', 'from', 'Lua'}) s = "from=world, to=Lua" output = {} for k, v in string.gmatch(s, '(%w+)=(%w+)') do table.insert(output, k) table.insert(output, v) end - eq_array(output, {'from', 'world', 'to', 'Lua'}) + array_equals(output, {'from', 'world', 'to', 'Lua'}) end do -- gsub - is(string.gsub("hello world", "(%w+)", "%1 %1"), "hello hello world world", "function gsub") - is(string.gsub("hello world", "%w+", "%0 %0", 1), "hello hello world") - is(string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1"), "world hello Lua from") + equals(string.gsub("hello world", "(%w+)", "%1 %1"), "hello hello world world", "function gsub") + equals(string.gsub("hello world", "%w+", "%0 %0", 1), "hello hello world") + equals(string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1"), "world hello Lua from") if _VERSION == 'Lua 5.1' then todo("not with 5.1") end - error_like(function () string.gsub("hello world", "%w+", "%e") end, - "^[^:]+:%d+: invalid use of '%%' in replacement string", - "function gsub (invalid replacement string)") - is(string.gsub("home = $HOME, user = $USER", "%$(%w+)", string.reverse), "home = EMOH, user = RESU") - is(string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s) return tostring(loadstring(s)()) end), "4+5 = 9") + error_matches(function () string.gsub("hello world", "%w+", "%e") end, + "^[^:]+:%d+: invalid use of '%%' in replacement string", + "function gsub (invalid replacement string)") + equals(string.gsub("home = $HOME, user = $USER", "%$(%w+)", string.reverse), "home = EMOH, user = RESU") + equals(string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s) return tostring(loadstring(s)()) end), "4+5 = 9") local t = {name='lua', version='5.1'} - is(string.gsub("$name-$version.tar.gz", "%$(%w+)", t), "lua-5.1.tar.gz") + equals(string.gsub("$name-$version.tar.gz", "%$(%w+)", t), "lua-5.1.tar.gz") - is(string.gsub("Lua is cute", 'cute', 'great'), "Lua is great") - is(string.gsub("all lii", 'l', 'x'), "axx xii") - is(string.gsub("Lua is great", '^Sol', 'Sun'), "Lua is great") - is(string.gsub("all lii", 'l', 'x', 1), "axl lii") - is(string.gsub("all lii", 'l', 'x', 2), "axx lii") - is(select(2, string.gsub("string with 3 spaces", ' ', ' ')), 3) + equals(string.gsub("Lua is cute", 'cute', 'great'), "Lua is great") + equals(string.gsub("all lii", 'l', 'x'), "axx xii") + equals(string.gsub("Lua is great", '^Sol', 'Sun'), "Lua is great") + equals(string.gsub("all lii", 'l', 'x', 1), "axl lii") + equals(string.gsub("all lii", 'l', 'x', 2), "axx lii") + equals(select(2, string.gsub("string with 3 spaces", ' ', ' ')), 3) - eq_array({string.gsub("hello, up-down!", '%A', '.')}, {"hello..up.down.", 4}) - eq_array({string.gsub("hello, up-down!", '%A', '%%')}, {"hello%%up%down%", 4}) + array_equals({string.gsub("hello, up-down!", '%A', '.')}, {"hello..up.down.", 4}) + array_equals({string.gsub("hello, up-down!", '%A', '%%')}, {"hello%%up%down%", 4}) local text = "hello world" local nvow = select(2, string.gsub(text, '[AEIOUaeiou]', '')) - is(nvow, 3) - eq_array({string.gsub("one, and two; and three", '%a+', 'word')}, {"word, word word; word word", 5}) + equals(nvow, 3) + array_equals({string.gsub("one, and two; and three", '%a+', 'word')}, {"word, word word; word word", 5}) local test = "int x; /* x */ int y; /* y */" - eq_array({string.gsub(test, "/%*.*%*/", '')}, {"int x; ", 1}) - eq_array({string.gsub(test, "/%*.-%*/", '')}, {"int x; int y; ", 2}) + array_equals({string.gsub(test, "/%*.*%*/", '')}, {"int x; ", 1}) + array_equals({string.gsub(test, "/%*.-%*/", '')}, {"int x; int y; ", 2}) local s = "a (enclosed (in) parentheses) line" - eq_array({string.gsub(s, '%b()', '')}, {"a line", 1}) + array_equals({string.gsub(s, '%b()', '')}, {"a line", 1}) - error_like(function () string.gsub(s, '%b(', '') end, - "^[^:]+:%d+: .- pattern", - "function gsub (malformed pattern)") + error_matches(function () string.gsub(s, '%b(', '') end, + "^[^:]+:%d+: .- pattern", + "function gsub (malformed pattern)") - eq_array({string.gsub("hello Lua!", "%a", "%0-%0")}, {"h-he-el-ll-lo-o L-Lu-ua-a!", 8}) - eq_array({string.gsub("hello Lua", "(.)(.)", "%2%1")}, {"ehll ouLa", 4}) + array_equals({string.gsub("hello Lua!", "%a", "%0-%0")}, {"h-he-el-ll-lo-o L-Lu-ua-a!", 8}) + array_equals({string.gsub("hello Lua", "(.)(.)", "%2%1")}, {"ehll ouLa", 4}) local function expand (str) return (string.gsub(str, '$(%w+)', _G)) end name = 'Lua'; status= 'great' - is(expand("$name is $status, isn't it?"), "Lua is great, isn't it?") - is(expand("$othername is $status, isn't it?"), "$othername is great, isn't it?") + equals(expand("$name is $status, isn't it?"), "Lua is great, isn't it?") + equals(expand("$othername is $status, isn't it?"), "$othername is great, isn't it?") function expand (str) return (string.gsub(str, '$(%w+)', function (n) return tostring(_G[n]), 1 end)) end - like(expand("print = $print; a = $a"), "^print = function: [0]?[Xx]?[builtin]*#?%x+; a = nil") + matches(expand("print = $print; a = $a"), "^print = function: [0]?[Xx]?[builtin]*#?%x+; a = nil") - error_like(function () string.gsub("hello world", '(%w+)', '%2 %2') end, - "^[^:]+:%d+: invalid capture index", - "function gsub (invalid index)") + error_matches(function () string.gsub("hello world", '(%w+)', '%2 %2') end, + "^[^:]+:%d+: invalid capture index", + "function gsub (invalid index)") - error_like(function () string.gsub("hello world", '(%w+)', true) end, - "^[^:]+:%d+: bad argument #3 to 'gsub' %(string/function/table expected", - "function gsub (bad type)") + error_matches(function () string.gsub("hello world", '(%w+)', true) end, + "^[^:]+:%d+: bad argument #3 to 'gsub' %(string/function/table expected", + "function gsub (bad type)") - error_like(function () + error_matches(function () function expand (str) return (string.gsub(str, '$(%w+)', _G)) end @@ -423,204 +423,204 @@ do -- gsub local function trim (str) return (str:gsub('^%s*(.-)%s*$', '%1')) end - is(trim('foo'), 'foo', "gsub trim") - is(trim(' foo bar '), 'foo bar') + equals(trim('foo'), 'foo', "gsub trim") + equals(trim(' foo bar '), 'foo bar') end do -- len - is(string.len(''), 0, "function len") - is(string.len('test'), 4) - is(string.len("a\000b\000c"), 5) - is(string.len('"'), 1) + equals(string.len(''), 0, "function len") + equals(string.len('test'), 4) + equals(string.len("a\000b\000c"), 5) + equals(string.len('"'), 1) end do -- lower - is(string.lower('Test'), 'test', "function lower") - is(string.lower('TeSt'), 'test') + equals(string.lower('Test'), 'test', "function lower") + equals(string.lower('TeSt'), 'test') end do -- match local s = "hello world" - is(string.match(s, '^hello'), 'hello', "function match") - is(string.match(s, 'world', 2), 'world') - is(string.match(s, 'World'), nil) - eq_array({string.match(s, '^(h.ll.)')}, {'hello'}) - eq_array({string.match(s, '^(h.)l(l.)')}, {'he', 'lo'}) + equals(string.match(s, '^hello'), 'hello', "function match") + equals(string.match(s, 'world', 2), 'world') + equals(string.match(s, 'World'), nil) + array_equals({string.match(s, '^(h.ll.)')}, {'hello'}) + array_equals({string.match(s, '^(h.)l(l.)')}, {'he', 'lo'}) local date = "Today is 17/7/1990" - is(string.match(date, '%d+/%d+/%d+'), '17/7/1990') - eq_array({string.match(date, '(%d+)/(%d+)/(%d+)')}, {'17', '7', '1990'}) - is(string.match("The number 1298 is even", '%d+'), '1298') + equals(string.match(date, '%d+/%d+/%d+'), '17/7/1990') + array_equals({string.match(date, '(%d+)/(%d+)/(%d+)')}, {'17', '7', '1990'}) + equals(string.match("The number 1298 is even", '%d+'), '1298') local pair = "name = Anna" - eq_array({string.match(pair, '(%a+)%s*=%s*(%a+)')}, {'name', 'Anna'}) + array_equals({string.match(pair, '(%a+)%s*=%s*(%a+)')}, {'name', 'Anna'}) s = [[then he said: "it's all right"!]] - eq_array({string.match(s, "([\"'])(.-)%1")}, {'"', "it's all right"}, "function match (back ref)") + array_equals({string.match(s, "([\"'])(.-)%1")}, {'"', "it's all right"}, "function match (back ref)") local p = "%[(=*)%[(.-)%]%1%]" s = "a = [=[[[ something ]] ]==]x]=]; print(a)" - eq_array({string.match(s, p)}, {'=', '[[ something ]] ]==]x'}) + array_equals({string.match(s, p)}, {'=', '[[ something ]] ]==]x'}) if has_class_g then - is(string.match(s, "%g"), "a", "match graphic char") + equals(string.match(s, "%g"), "a", "match graphic char") end - error_like(function () string.match("hello world", "%1") end, - "^[^:]+:%d+: invalid capture index", - "function match invalid capture") + error_matches(function () string.match("hello world", "%1") end, + "^[^:]+:%d+: invalid capture index", + "function match invalid capture") - error_like(function () string.match("hello world", "%w)") end, - "^[^:]+:%d+: invalid pattern capture", - "function match invalid capture") + error_matches(function () string.match("hello world", "%w)") end, + "^[^:]+:%d+: invalid pattern capture", + "function match invalid capture") end -- pack if has_pack then - is(string.pack('b', 0x31), '\x31', "function pack") - is(string.pack('>b', 0x31), '\x31') - is(string.pack('=b', 0x31), '\x31') - is(string.pack('B', 0x91), '\x91') - is(string.pack('=B', 0x91), '\x91') - is(string.pack('h', 1):reverse()), 1) - is(string.byte(string.pack('H', 1):reverse()), 1) - is(string.byte(string.pack('l', 1):reverse()), 1) - is(string.byte(string.pack('L', 1):reverse()), 1) - is(string.byte(string.pack('j', 1):reverse()), 1) - is(string.byte(string.pack('J', 1):reverse()), 1) - is(string.byte(string.pack('T', 1):reverse()), 1) - is(string.byte(string.pack('i', 1):reverse()), 1) - is(string.byte(string.pack('I', 1):reverse()), 1) - is(string.pack('i1', 0):len(), 1) - is(string.pack('i2', 0):len(), 2) - is(string.pack('i4', 0):len(), 4) - is(string.pack('i8', 0):len(), 8) - is(string.pack('i16', 0):len(), 16) - error_like(function () string.pack('i20', 0) end, - "^[^:]+:%d+: integral size %(20%) out of limits %[1,16%]", - "function pack out limit") - - is(string.pack('!2 i1 i4', 0, 0):len(), 6) - is(string.pack('i1 Xb i1', 0, 0):len(), 2) - is(string.pack('i1 x x i1', 0, 0):len(), 4) - - is(string.pack('c3', 'foo'), 'foo') - is(string.pack('z', 'foo'), 'foo\0') - is(string.pack('c4', 'foo'), 'foo\0') -- padding - - error_like(function () string.pack('w', 0) end, - "^[^:]+:%d+: invalid format option 'w'", - "function pack invalid format") - - error_like(function () string.pack('i1 Xz i1', 0, 0) end, - "^[^:]+:%d+: bad argument #1 to 'pack' %(invalid next option for option 'X'%)", - "function pack invalid next") - - error_like(function () string.pack('i', 'foo') end, - "^[^:]+:%d+: bad argument #2 to 'pack' %(number expected, got string%)", - "function pack bad arg") + equals(string.pack('b', 0x31), '\x31', "function pack") + equals(string.pack('>b', 0x31), '\x31') + equals(string.pack('=b', 0x31), '\x31') + equals(string.pack('B', 0x91), '\x91') + equals(string.pack('=B', 0x91), '\x91') + equals(string.pack('h', 1):reverse()), 1) + equals(string.byte(string.pack('H', 1):reverse()), 1) + equals(string.byte(string.pack('l', 1):reverse()), 1) + equals(string.byte(string.pack('L', 1):reverse()), 1) + equals(string.byte(string.pack('j', 1):reverse()), 1) + equals(string.byte(string.pack('J', 1):reverse()), 1) + equals(string.byte(string.pack('T', 1):reverse()), 1) + equals(string.byte(string.pack('i', 1):reverse()), 1) + equals(string.byte(string.pack('I', 1):reverse()), 1) + equals(string.pack('i1', 0):len(), 1) + equals(string.pack('i2', 0):len(), 2) + equals(string.pack('i4', 0):len(), 4) + equals(string.pack('i8', 0):len(), 8) + equals(string.pack('i16', 0):len(), 16) + error_matches(function () string.pack('i20', 0) end, + "^[^:]+:%d+: integral size %(20%) out of limits %[1,16%]", + "function pack out limit") + + equals(string.pack('!2 i1 i4', 0, 0):len(), 6) + equals(string.pack('i1 Xb i1', 0, 0):len(), 2) + equals(string.pack('i1 x x i1', 0, 0):len(), 4) + + equals(string.pack('c3', 'foo'), 'foo') + equals(string.pack('z', 'foo'), 'foo\0') + equals(string.pack('c4', 'foo'), 'foo\0') -- padding + + error_matches(function () string.pack('w', 0) end, + "^[^:]+:%d+: invalid format option 'w'", + "function pack invalid format") + + error_matches(function () string.pack('i1 Xz i1', 0, 0) end, + "^[^:]+:%d+: bad argument #1 to 'pack' %(invalid next option for option 'X'%)", + "function pack invalid next") + + error_matches(function () string.pack('i', 'foo') end, + "^[^:]+:%d+: bad argument #2 to 'pack' %(number expected, got string%)", + "function pack bad arg") else - is(string.pack, nil, "no string.pack"); + is_nil(string.pack, "no string.pack"); end -- packsize if has_pack then - is(string.packsize('b'), 1, "function packsize") + equals(string.packsize('b'), 1, "function packsize") - is(string.packsize(''), 0, "function packsize empty") + equals(string.packsize(''), 0, "function packsize empty") - error_like(function () string.packsize('z') end, - "^[^:]+:%d+: bad argument #1 to 'packsize' %(variable%-length format%)", - "function packsize bad arg") + error_matches(function () string.packsize('z') end, + "^[^:]+:%d+: bad argument #1 to 'packsize' %(variable%-length format%)", + "function packsize bad arg") else - is(string.packsize, nil, "no string.packsize"); + is_nil(string.packsize, "no string.packsize"); end do -- rep - is(string.rep('ab', 3), 'ababab', "function rep") - is(string.rep('ab', 0), '') - is(string.rep('ab', -1), '') - is(string.rep('', 5), '') + equals(string.rep('ab', 3), 'ababab', "function rep") + equals(string.rep('ab', 0), '') + equals(string.rep('ab', -1), '') + equals(string.rep('', 5), '') if has_rep52 then - is(string.rep('ab', 3, ','), 'ab,ab,ab', "with sep") + equals(string.rep('ab', 3, ','), 'ab,ab,ab', "with sep") local n = 1e6 - is(string.rep('a', n), string.rep('', n + 1, 'a')) + equals(string.rep('a', n), string.rep('', n + 1, 'a')) else diag("no rep with separator") end if _VERSION >= 'Lua 5.3' then - error_like(function () string.rep('foo', 1e9) end, - "^[^:]+:%d+: resulting string too large", - "too large") + error_matches(function () string.rep('foo', 1e9) end, + "^[^:]+:%d+: resulting string too large", + "too large") elseif luajit21 then - error_is(function () string.rep('foo', 1e9) end, - "not enough memory", - "too large") + error_equals(function () string.rep('foo', 1e9) end, + "not enough memory", + "too large") end if _VERSION >= 'Lua 5.4' or jit then - is(string.rep('', 1e8), '', "rep ''") + equals(string.rep('', 1e8), '', "rep ''") else diag('too slow') end end do -- reverse - is(string.reverse('abcde'), 'edcba', "function reverse") - is(string.reverse('abcd'), 'dcba') - is(string.reverse(''), '') + equals(string.reverse('abcde'), 'edcba', "function reverse") + equals(string.reverse('abcd'), 'dcba') + equals(string.reverse(''), '') end do -- sub - is(string.sub('abcde', 1, 2), 'ab', "function sub") - is(string.sub('abcde', 3, 4), 'cd') - is(string.sub('abcde', -2), 'de') - is(string.sub('abcde', 3, 2), '') + equals(string.sub('abcde', 1, 2), 'ab', "function sub") + equals(string.sub('abcde', 3, 4), 'cd') + equals(string.sub('abcde', -2), 'de') + equals(string.sub('abcde', 3, 2), '') end do -- upper - is(string.upper('Test'), 'TEST', "function upper") - is(string.upper('TeSt'), 'TEST') - is(string.upper(string.rep('Test', 10000)), string.rep('TEST', 10000)) + equals(string.upper('Test'), 'TEST', "function upper") + equals(string.upper('TeSt'), 'TEST') + equals(string.upper(string.rep('Test', 10000)), string.rep('TEST', 10000)) end -- unpack if has_pack then - is(string.unpack('h', 1):reverse()), 1, "function unpack") - is(string.unpack('H', 1):reverse()), 1) - is(string.unpack('l', 1):reverse()), 1) - is(string.unpack('L', 1):reverse()), 1) - is(string.unpack('j', 1):reverse()), 1) - is(string.unpack('J', 1):reverse()), 1) - is(string.unpack('T', 1):reverse()), 1) - is(string.unpack('i', 1):reverse()), 1) - is(string.unpack('I', 1):reverse()), 1) - is(string.unpack('f', 1.0):reverse()), 1.0) - is(string.unpack('d', 1.0):reverse()), 1.0) - is(string.unpack('n', 1.0):reverse()), 1.0) - - is(string.unpack('c3', string.pack('c3', 'foo')), 'foo') - is(string.unpack('z', string.pack('z', 'foo')), 'foo') - is(string.unpack('s', string.pack('s', 'foo')), 'foo') - - error_like(function () string.unpack('c4', 'foo') end, - "^[^:]+:%d+: bad argument #2 to 'unpack' %(data string too short%)", - "function unpack data too short") - - error_like(function () string.unpack('c', 'foo') end, - "^[^:]+:%d+: missing size for format option 'c'", - "function unpack missing size") + equals(string.unpack('h', 1):reverse()), 1, "function unpack") + equals(string.unpack('H', 1):reverse()), 1) + equals(string.unpack('l', 1):reverse()), 1) + equals(string.unpack('L', 1):reverse()), 1) + equals(string.unpack('j', 1):reverse()), 1) + equals(string.unpack('J', 1):reverse()), 1) + equals(string.unpack('T', 1):reverse()), 1) + equals(string.unpack('i', 1):reverse()), 1) + equals(string.unpack('I', 1):reverse()), 1) + equals(string.unpack('f', 1.0):reverse()), 1.0) + equals(string.unpack('d', 1.0):reverse()), 1.0) + equals(string.unpack('n', 1.0):reverse()), 1.0) + + equals(string.unpack('c3', string.pack('c3', 'foo')), 'foo') + equals(string.unpack('z', string.pack('z', 'foo')), 'foo') + equals(string.unpack('s', string.pack('s', 'foo')), 'foo') + + error_matches(function () string.unpack('c4', 'foo') end, + "^[^:]+:%d+: bad argument #2 to 'unpack' %(data string too short%)", + "function unpack data too short") + + error_matches(function () string.unpack('c', 'foo') end, + "^[^:]+:%d+: missing size for format option 'c'", + "function unpack missing size") else - is(string.unpack, nil, "no string.unpack"); + is_nil(string.unpack, "no string.unpack"); end done_testing() diff --git a/test/lua-Harness-tests/305-utf8.t b/test/lua-Harness-tests/305-utf8.t index 6c125388..be0ace6e 100755 --- a/test/lua-Harness-tests/305-utf8.t +++ b/test/lua-Harness-tests/305-utf8.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2014-2020, Perrad Francois +-- Copyright (C) 2014-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -37,7 +37,7 @@ local has_utf8 = _VERSION >= 'Lua 5.3' or (jit and jit.version:match'moonjit') o if not utf8 then plan(1) - nok(has_utf8, "no has_utf8") + falsy(has_utf8, "no has_utf8") else plan'no_plan' make_specific_checks'lexico53/utf8.t' diff --git a/test/lua-Harness-tests/306-table.t b/test/lua-Harness-tests/306-table.t index 98366556..c57947f6 100755 --- a/test/lua-Harness-tests/306-table.t +++ b/test/lua-Harness-tests/306-table.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -48,62 +48,62 @@ plan'no_plan' do -- concat local t = {'a','b','c','d','e'} - is(table.concat(t), 'abcde', "function concat") - is(table.concat(t, ','), 'a,b,c,d,e') - is(table.concat(t, ',',2), 'b,c,d,e') - is(table.concat(t, ',', 2, 4), 'b,c,d') - is(table.concat(t, ',', 4, 2), '') + equals(table.concat(t), 'abcde', "function concat") + equals(table.concat(t, ','), 'a,b,c,d,e') + equals(table.concat(t, ',',2), 'b,c,d,e') + equals(table.concat(t, ',', 2, 4), 'b,c,d') + equals(table.concat(t, ',', 4, 2), '') t = {'a','b',3,'d','e'} if nocvtn2s then - error_like(function () table.concat(t,',') end, - "^[^:]+:%d+: invalid value %(number%) at index 3 in table for 'concat'", - "function concat (number no conv)") + error_matches(function () table.concat(t,',') end, + "^[^:]+:%d+: invalid value %(number%) at index 3 in table for 'concat'", + "function concat (number no conv)") else - is(table.concat(t,','), 'a,b,3,d,e', "function concat (number)") + equals(table.concat(t,','), 'a,b,3,d,e', "function concat (number)") end t = {'a','b','c','d','e'} - error_like(function () table.concat(t, ',', 2, 7) end, - "^[^:]+:%d+: invalid value %(nil%) at index 6 in table for 'concat'", - "function concat (out of range)") + error_matches(function () table.concat(t, ',', 2, 7) end, + "^[^:]+:%d+: invalid value %(nil%) at index 6 in table for 'concat'", + "function concat (out of range)") t = {'a','b',true,'d','e'} - error_like(function () table.concat(t, ',') end, - "^[^:]+:%d+: invalid value %(boolean%) at index 3 in table for 'concat'", - "function concat (non-string)") + error_matches(function () table.concat(t, ',') end, + "^[^:]+:%d+: invalid value %(boolean%) at index 3 in table for 'concat'", + "function concat (non-string)") end do -- insert local a = {'10', '20', '30'} table.insert(a, 1, '15') - is(table.concat(a,','), '15,10,20,30', "function insert") + equals(table.concat(a,','), '15,10,20,30', "function insert") local t = {} table.insert(t, 'a') - is(table.concat(t, ','), 'a') + equals(table.concat(t, ','), 'a') table.insert(t, 'b') - is(table.concat(t, ','), 'a,b') + equals(table.concat(t, ','), 'a,b') table.insert(t, 1, 'c') - is(table.concat(t, ','), 'c,a,b') + equals(table.concat(t, ','), 'c,a,b') table.insert(t, 2, 'd') - is(table.concat(t, ','), 'c,d,a,b') + equals(table.concat(t, ','), 'c,d,a,b') table.insert(t, 5, 'e') - is(table.concat(t, ','), 'c,d,a,b,e') + equals(table.concat(t, ','), 'c,d,a,b,e') if _VERSION == 'Lua 5.1' then todo("not with 5.1", 2) end - error_like(function () table.insert(t, 7, 'f') end, - "^[^:]+:%d+: bad argument #2 to 'insert' %(position out of bounds%)", - "function insert (out of bounds)") + error_matches(function () table.insert(t, 7, 'f') end, + "^[^:]+:%d+: bad argument #2 to 'insert' %(position out of bounds%)", + "function insert (out of bounds)") - error_like(function () table.insert(t, -9, 'f') end, - "^[^:]+:%d+: bad argument #2 to 'insert' %(position out of bounds%)", - "function insert (out of bounds)") + error_matches(function () table.insert(t, -9, 'f') end, + "^[^:]+:%d+: bad argument #2 to 'insert' %(position out of bounds%)", + "function insert (out of bounds)") - error_like(function () table.insert(t, 2, 'g', 'h') end, - "^[^:]+:%d+: wrong number of arguments to 'insert'", - "function insert (too many arg)") + error_matches(function () table.insert(t, 2, 'g', 'h') end, + "^[^:]+:%d+: wrong number of arguments to 'insert'", + "function insert (too many arg)") end -- foreach 5.0 @@ -111,7 +111,7 @@ if has_foreach then local t = {a=10, b=100} local output = {} table.foreach(t, function (k, v) output[k] = v end) - eq_array(output, t, "function foreach (hash)") + array_equals(output, t, "function foreach (hash)") t = {'a','b','c'} output = {} @@ -119,9 +119,9 @@ if has_foreach then table.insert(output, k) table.insert(output, v) end) - eq_array(output, {1, 'a', 2, 'b', 3, 'c'}, "function foreach (array)") + array_equals(output, {1, 'a', 2, 'b', 3, 'c'}, "function foreach (array)") else - is(table.foreach, nil, "no table.foreach"); + is_nil(table.foreach, "no table.foreach"); end -- foreachi 5.0 @@ -132,33 +132,33 @@ if has_foreachi then table.insert(output, i) table.insert(output, v) end) - eq_array(output, {1, 'a', 2, 'b', 3, 'c'}, "function foreachi") + array_equals(output, {1, 'a', 2, 'b', 3, 'c'}, "function foreachi") else - is(table.foreachi, nil, "no table.foreachi"); + is_nil(table.foreachi, "no table.foreachi"); end if has_getn then - is(table.getn{10,2,4}, 3, "function getn") - is(table.getn{10,2,nil}, 2) + equals(table.getn{10,2,4}, 3, "function getn") + equals(table.getn{10,2,nil}, 2) else - is(table.getn, nil, "no table.getn"); + is_nil(table.getn, "no table.getn"); end -- maxn if has_maxn then local t = {} - is(table.maxn(t), 0, "function maxn") + equals(table.maxn(t), 0, "function maxn") t[1] = 'a' t[2] = 'b' - is(table.maxn(t), 2) + equals(table.maxn(t), 2) t[6] = 'g' - is(table.maxn(t), 6) + equals(table.maxn(t), 6) local a = {} a[10000] = 1 - is(table.maxn(a), 10000) + equals(table.maxn(a), 10000) else - is(table.maxn, nil, "no table.maxn"); + is_nil(table.maxn, "no table.maxn"); end -- move @@ -166,78 +166,78 @@ if has_move then local a = {'a', 'b', 'c'} local t = { 1, 2, 3, 4} table.move(a, 1, 3, 1, t) - eq_array(t, {'a', 'b', 'c', 4}, "function move") + array_equals(t, {'a', 'b', 'c', 4}, "function move") table.move(a, 1, 3, 3, t) - eq_array(t, {'a', 'b', 'a', 'b', 'c'}) + array_equals(t, {'a', 'b', 'a', 'b', 'c'}) table.move(a, 1, 3, 1) - eq_array(a, {'a', 'b', 'c'}) + array_equals(a, {'a', 'b', 'c'}) table.move(a, 1, 3, 3) - eq_array(a, {'a', 'b', 'a', 'b', 'c'}) + array_equals(a, {'a', 'b', 'a', 'b', 'c'}) - error_like(function () table.move(a, 1, 2, 1, 2) end, - "^[^:]+:%d+: bad argument #5 to 'move' %(table expected", - "function move (bad arg)") + error_matches(function () table.move(a, 1, 2, 1, 2) end, + "^[^:]+:%d+: bad argument #5 to 'move' %(table expected", + "function move (bad arg)") - error_like(function () table.move(a, 1, 2) end, - "^[^:]+:%d+: bad argument #4 to 'move' %(number expected, got .-%)", - "function move (bad arg)") + error_matches(function () table.move(a, 1, 2) end, + "^[^:]+:%d+: bad argument #4 to 'move' %(number expected, got .-%)", + "function move (bad arg)") - error_like(function () table.move(a, 1) end, - "^[^:]+:%d+: bad argument #3 to 'move' %(number expected, got .-%)", - "function move (bad arg)") + error_matches(function () table.move(a, 1) end, + "^[^:]+:%d+: bad argument #3 to 'move' %(number expected, got .-%)", + "function move (bad arg)") else - is(table.move, nil, "no table.move"); + is_nil(table.move, "no table.move"); end -- pack if has_pack then local t = table.pack("abc", "def", "ghi") - eq_array(t, { + array_equals(t, { "abc", "def", "ghi" }, "function pack") - is(t.n, 3) + equals(t.n, 3) t = table.pack() - eq_array(t, {}, "function pack (no element)") - is(t.n, 0) + array_equals(t, {}, "function pack (no element)") + equals(t.n, 0) else - is(table.pack, nil, "no table.pack"); + is_nil(table.pack, "no table.pack"); end do -- remove local t = {} local a = table.remove(t) - is(a, nil, "function remove") + equals(a, nil, "function remove") t = {'a','b','c','d','e'} a = table.remove(t) - is(a, 'e') - is(table.concat(t, ','), 'a,b,c,d') + equals(a, 'e') + equals(table.concat(t, ','), 'a,b,c,d') a = table.remove(t,3) - is(a, 'c') - is(table.concat(t, ','), 'a,b,d') + equals(a, 'c') + equals(table.concat(t, ','), 'a,b,d') a = table.remove(t,1) - is(a, 'a') - is(table.concat(t, ','), 'b,d') + equals(a, 'a') + equals(table.concat(t, ','), 'b,d') if _VERSION == 'Lua 5.1' then todo("not with 5.1", 1) end - error_like(function () table.remove(t,7) end, - "^[^:]+:%d+: bad argument #1 to 'remove' %(position out of bounds%)", - "function remove (out of bounds)") + error_matches(function () table.remove(t,7) end, + "^[^:]+:%d+: bad argument #1 to 'remove' %(position out of bounds%)", + "function remove (out of bounds)") end -- setn obsolete if has_setn_obsolete then local a = {} - error_like(function () table.setn(a, 10000) end, - "^[^:]+:%d+: 'setn' is obsolete", - "function setn") + error_matches(function () table.setn(a, 10000) end, + "^[^:]+:%d+: 'setn' is obsolete", + "function setn") else - is(table.setn, nil, "no table.setn"); + is_nil(table.setn, "no table.setn"); end do -- sort @@ -255,7 +255,7 @@ do -- sort for _, n in ipairs(a) do table.insert(output, n) end - eq_array(output, {'luaH_get', 'luaH_present', 'luaH_set'}, "function sort") + array_equals(output, {'luaH_get', 'luaH_present', 'luaH_set'}, "function sort") end do @@ -275,14 +275,14 @@ do -- sort table.insert(output, name) table.insert(output, line) end - eq_array(output, {'luaH_get', 24, 'luaH_present', 48, 'luaH_set', 10}, "function sort") + array_equals(output, {'luaH_get', 24, 'luaH_present', 48, 'luaH_set', 10}, "function sort") output = {} for name, line in pairsByKeys(lines, function (a, b) return a < b end) do table.insert(output, name) table.insert(output, line) end - eq_array(output, {'luaH_get', 24, 'luaH_present', 48, 'luaH_set', 10}, "function sort") + array_equals(output, {'luaH_get', 24, 'luaH_present', 48, 'luaH_set', 10}, "function sort") end do @@ -326,7 +326,7 @@ do -- sort table.insert(output, n) end - eq_array(output, { + array_equals(output, { 'a', 1, 'a b', 2, 'a b c', 6, @@ -340,26 +340,26 @@ do -- sort if _VERSION == 'Lua 5.1' and not jit then todo("not with 5.1") end - error_like(function () + error_matches(function () local t = { 1 } table.sort( { t, t, t, t, }, function (a, b) return a[1] == b[1] end ) - end, - "^[^:]+:%d+: invalid order function for sorting", - "function sort (bad func)") + end, + "^[^:]+:%d+: invalid order function for sorting", + "function sort (bad func)") end -- unpack if has_unpack then - eq_array({table.unpack({})}, {}, "function unpack") - eq_array({table.unpack({'a'})}, {'a'}) - eq_array({table.unpack({'a','b','c'})}, {'a','b','c'}) - eq_array({(table.unpack({'a','b','c'}))}, {'a'}) - eq_array({table.unpack({'a','b','c','d','e'},2,4)}, {'b','c','d'}) - eq_array({table.unpack({'a','b','c'},2,4)}, {'b','c'}) + array_equals({table.unpack({})}, {}, "function unpack") + array_equals({table.unpack({'a'})}, {'a'}) + array_equals({table.unpack({'a','b','c'})}, {'a','b','c'}) + array_equals({(table.unpack({'a','b','c'}))}, {'a'}) + array_equals({table.unpack({'a','b','c','d','e'},2,4)}, {'b','c','d'}) + array_equals({table.unpack({'a','b','c'},2,4)}, {'b','c'}) elseif has_alias_unpack then - is(table.unpack, unpack, "alias table.unpack"); + equals(table.unpack, unpack, "alias table.unpack"); else - is(table.unpack, nil, "no table.unpack"); + is_nil(table.unpack, "no table.unpack"); end done_testing() diff --git a/test/lua-Harness-tests/307-math.t b/test/lua-Harness-tests/307-math.t index 8b51ed16..b50e449f 100755 --- a/test/lua-Harness-tests/307-math.t +++ b/test/lua-Harness-tests/307-math.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -43,91 +43,91 @@ local nocvts2n = profile.nocvts2n or jit plan'no_plan' do -- abs - is(math.abs(-12.34), 12.34, "function abs (float)") - is(math.abs(12.34), 12.34) + equals(math.abs(-12.34), 12.34, "function abs (float)") + equals(math.abs(12.34), 12.34) if math.type then - is(math.type(math.abs(-12.34)), 'float') + equals(math.type(math.abs(-12.34)), 'float') end - is(math.abs(-12), 12, "function abs (integer)") - is(math.abs(12), 12) + equals(math.abs(-12), 12, "function abs (integer)") + equals(math.abs(12), 12) if math.type then - is(math.type(math.abs(-12)), 'integer') + equals(math.type(math.abs(-12)), 'integer') end end do -- acos - like(math.acos(0.5), '^1%.047', "function acos") + matches(math.acos(0.5), '^1%.047', "function acos") end do -- asin - like(math.asin(0.5), '^0%.523', "function asin") + matches(math.asin(0.5), '^0%.523', "function asin") end do -- atan - like(math.atan(0.5), '^0%.463', "function atan") + matches(math.atan(0.5), '^0%.463', "function atan") end -- atan2 if has_mathx then - like(math.atan2(1.0, 2.0), '^0%.463', "function atan2") + matches(math.atan2(1.0, 2.0), '^0%.463', "function atan2") else - is(math.atan2, nil, "function atan2 (removed)") + is_nil(math.atan2, "function atan2 (removed)") end do -- ceil - is(math.ceil(12.34), 13, "function ceil") - is(math.ceil(-12.34), -12) - is(math.ceil(-12), -12) + equals(math.ceil(12.34), 13, "function ceil") + equals(math.ceil(-12.34), -12) + equals(math.ceil(-12), -12) if math.type then - is(math.type(math.ceil(-12.34)), 'integer') + equals(math.type(math.ceil(-12.34)), 'integer') end end do -- cos - like(math.cos(1.0), '^0%.540', "function cos") + matches(math.cos(1.0), '^0%.540', "function cos") end -- cosh if has_mathx then - like(math.cosh(1.0), '^1%.543', "function cosh") + matches(math.cosh(1.0), '^1%.543', "function cosh") else - is(math.cosh, nil, "function cosh (removed)") + is_nil(math.cosh, "function cosh (removed)") end do -- deg - is(math.deg(math.pi), 180, "function deg") + equals(math.deg(math.pi), 180, "function deg") end do -- exp - like(math.exp(1.0), '^2%.718', "function exp") + matches(math.exp(1.0), '^2%.718', "function exp") end do -- floor - is(math.floor(12.34), 12, "function floor") - is(math.floor(-12.34), -13) - is(math.floor(-12), -12) + equals(math.floor(12.34), 12, "function floor") + equals(math.floor(-12.34), -13) + equals(math.floor(-12), -12) if math.type then - is(math.type(math.floor(-12.34)), 'integer') + equals(math.type(math.floor(-12.34)), 'integer') end end do -- fmod - like(math.fmod(7.0001, 0.3), '^0%.100', "function fmod (float)") - like(math.fmod(-7.0001, 0.3), '^-0%.100') - like(math.fmod(-7.0001, -0.3), '^-0%.100') + matches(math.fmod(7.0001, 0.3), '^0%.100', "function fmod (float)") + matches(math.fmod(-7.0001, 0.3), '^-0%.100') + matches(math.fmod(-7.0001, -0.3), '^-0%.100') if math.type then - is(math.type(math.fmod(7.0, 0.3)), 'float') + equals(math.type(math.fmod(7.0, 0.3)), 'float') end - is(math.fmod(7, 3), 1, "function fmod (integer)") - is(math.fmod(-7, 3), -1) - is(math.fmod(-7, -1), 0) + equals(math.fmod(7, 3), 1, "function fmod (integer)") + equals(math.fmod(-7, 3), -1) + equals(math.fmod(-7, -1), 0) if math.type then - is(math.type(math.fmod(7, 3)), 'integer') + equals(math.type(math.fmod(7, 3)), 'integer') end if _VERSION >= 'Lua 5.3' then - error_like(function () math.fmod(7, 0) end, - "^[^:]+:%d+: bad argument #2 to 'fmod' %(zero%)", - "function fmod 0") + error_matches(function () math.fmod(7, 0) end, + "^[^:]+:%d+: bad argument #2 to 'fmod' %(zero%)", + "function fmod 0") else diag"fmod by zero -> nan" end @@ -135,151 +135,151 @@ end -- frexp if has_mathx then - eq_array({math.frexp(1.5)}, {0.75, 1}, "function frexp") + array_equals({math.frexp(1.5)}, {0.75, 1}, "function frexp") else - is(math.frexp, nil, "function frexp (removed)") + is_nil(math.frexp, "function frexp (removed)") end do -- huge - type_ok(math.huge, 'number', "variable huge") + is_number(math.huge, "variable huge") if math.type then - is(math.type(math.huge), 'float') + equals(math.type(math.huge), 'float') end end -- ldexp if has_mathx then - is(math.ldexp(1.2, 3), 9.6, "function ldexp") + equals(math.ldexp(1.2, 3), 9.6, "function ldexp") else - is(math.ldexp, nil, "function ldexp (removed)") + is_nil(math.ldexp, "function ldexp (removed)") end do -- log - like(math.log(47), '^3%.85', "function log") + matches(math.log(47), '^3%.85', "function log") if has_log_with_base then - like(math.log(47, math.exp(1)), '^3%.85', "function log (base e)") - like(math.log(47, 2), '^5%.554', "function log (base 2)") - like(math.log(47, 10), '^1%.672', "function log (base 10)") + matches(math.log(47, math.exp(1)), '^3%.85', "function log (base e)") + matches(math.log(47, 2), '^5%.554', "function log (base 2)") + matches(math.log(47, 10), '^1%.672', "function log (base 10)") end end -- log10 if has_log10 then - like(math.log10(47.0), '^1%.672', "function log10") + matches(math.log10(47.0), '^1%.672', "function log10") else - is(math.log10, nil, "function log10 (removed)") + is_nil(math.log10, "function log10 (removed)") end do --max - is(math.max(1), 1, "function max") - is(math.max(1, 2), 2) - is(math.max(1, 2, 3, -4), 3) + equals(math.max(1), 1, "function max") + equals(math.max(1, 2), 2) + equals(math.max(1, 2, 3, -4), 3) - error_like(function () math.max() end, - "^[^:]+:%d+: bad argument #1 to 'max' %(.- expected", - "function max 0") + error_matches(function () math.max() end, + "^[^:]+:%d+: bad argument #1 to 'max' %(.- expected", + "function max 0") end -- maxinteger if has_integer then - type_ok(math.maxinteger, 'number', "variable maxinteger") + is_number(math.maxinteger, "variable maxinteger") if math.type then - is(math.type(math.maxinteger), 'integer') + equals(math.type(math.maxinteger), 'integer') end else - is(math.maxinteger, nil, "no maxinteger") + is_nil(math.maxinteger, "no maxinteger") end do --min - is(math.min(1), 1, "function min") - is(math.min(1, 2), 1) - is(math.min(1, 2, 3, -4), -4) + equals(math.min(1), 1, "function min") + equals(math.min(1, 2), 1) + equals(math.min(1, 2, 3, -4), -4) - error_like(function () math.min() end, - "^[^:]+:%d+: bad argument #1 to 'min' %(.- expected", - "function min 0") + error_matches(function () math.min() end, + "^[^:]+:%d+: bad argument #1 to 'min' %(.- expected", + "function min 0") end -- mininteger if has_integer then - type_ok(math.mininteger, 'number', "variable mininteger") + is_number(math.mininteger, "variable mininteger") if math.type then - is(math.type(math.mininteger), 'integer') + equals(math.type(math.mininteger), 'integer') end else - is(math.mininteger, nil, "no mininteger") + is_nil(math.mininteger, "no mininteger") end -- mod (compat50) if has_mod then - is(math.mod, math.fmod, "function mod (alias fmod)") + equals(math.mod, math.fmod, "function mod (alias fmod)") else - is(math.mod, nil, "function mod (alias removed)") + is_nil(math.mod, "function mod (alias removed)") end do -- modf - eq_array({math.modf(2.25)}, {2, 0.25}, "function modf") - eq_array({math.modf(2)}, {2, 0.0}) + array_equals({math.modf(2.25)}, {2, 0.25}, "function modf") + array_equals({math.modf(2)}, {2, 0.0}) end do -- pi - like(tostring(math.pi), '^3%.14', "variable pi") + matches(tostring(math.pi), '^3%.14', "variable pi") end -- pow if has_mathx then - is(math.pow(-2, 3), -8, "function pow") + equals(math.pow(-2, 3), -8, "function pow") else - is(math.pow, nil, "function pow (removed)") + is_nil(math.pow, "function pow (removed)") end do -- rad - like(math.rad(180), '^3%.14', "function rad") + matches(math.rad(180), '^3%.14', "function rad") end do -- random - like(math.random(), '^0%.%d+', "function random no arg") + matches(math.random(), '^0%.%d+', "function random no arg") if math.type then - is(math.type(math.random()), 'float') + equals(math.type(math.random()), 'float') end - like(math.random(9), '^%d$', "function random 1 arg") + matches(math.random(9), '^%d$', "function random 1 arg") if math.type then - is(math.type(math.random(9)), 'integer') + equals(math.type(math.random(9)), 'integer') end - like(math.random(10, 19), '^1%d$', "function random 2 arg") + matches(math.random(10, 19), '^1%d$', "function random 2 arg") if math.type then - is(math.type(math.random(10, 19)), 'integer') + equals(math.type(math.random(10, 19)), 'integer') end - like(math.random(-19, -10), '^-1%d$', "function random 2 arg") + matches(math.random(-19, -10), '^-1%d$', "function random 2 arg") if _VERSION >= 'Lua 5.4' then - like(math.random(0), '^%-?%d+$', "function random 0") + matches(math.random(0), '^%-?%d+$', "function random 0") else if jit then todo("LuaJIT intentional. Don't check empty interval.") end - error_like(function () math.random(0) end, - "^[^:]+:%d+: bad argument #1 to 'random' %(interval is empty%)", - "function random empty interval") + error_matches(function () math.random(0) end, + "^[^:]+:%d+: bad argument #1 to 'random' %(interval is empty%)", + "function random empty interval") end if jit then todo("LuaJIT intentional. Don't check empty interval.", 2) end - error_like(function () math.random(-9) end, - "^[^:]+:%d+: bad argument #%d to 'random' %(interval is empty%)", - "function random empty interval") + error_matches(function () math.random(-9) end, + "^[^:]+:%d+: bad argument #%d to 'random' %(interval is empty%)", + "function random empty interval") - error_like(function () math.random(19, 10) end, - "^[^:]+:%d+: bad argument #%d to 'random' %(interval is empty%)", - "function random empty interval") + error_matches(function () math.random(19, 10) end, + "^[^:]+:%d+: bad argument #%d to 'random' %(interval is empty%)", + "function random empty interval") if jit then todo("LuaJIT intentional. Don't care about extra arguments.") end - error_like(function () math.random(1, 2, 3) end, - "^[^:]+:%d+: wrong number of arguments", - "function random too many arg") + error_matches(function () math.random(1, 2, 3) end, + "^[^:]+:%d+: wrong number of arguments", + "function random too many arg") end do -- randomseed @@ -287,82 +287,82 @@ do -- randomseed local a = math.random() math.randomseed(42) local b = math.random() - is(a, b, "function randomseed") + equals(a, b, "function randomseed") end do -- sin - like(math.sin(1.0), '^0%.841', "function sin") + matches(math.sin(1.0), '^0%.841', "function sin") end -- sinh if has_mathx then - like(math.sinh(1), '^1%.175', "function sinh") + matches(math.sinh(1), '^1%.175', "function sinh") else - is(math.sinh, nil, "function sinh (removed)") + is_nil(math.sinh, "function sinh (removed)") end do -- sqrt - like(math.sqrt(2), '^1%.414', "function sqrt") + matches(math.sqrt(2), '^1%.414', "function sqrt") end do -- tan - like(math.tan(1.0), '^1%.557', "function tan") + matches(math.tan(1.0), '^1%.557', "function tan") end -- tanh if has_mathx then - like(math.tanh(1), '^0%.761', "function tanh") + matches(math.tanh(1), '^0%.761', "function tanh") else - is(math.tanh, nil, "function tanh (removed)") + is_nil(math.tanh, "function tanh (removed)") end -- tointeger if has_integer then - is(math.tointeger(-12), -12, "function tointeger (number)") - is(math.tointeger(-12.0), -12) - is(math.tointeger(-12.34), nil) + equals(math.tointeger(-12), -12, "function tointeger (number)") + equals(math.tointeger(-12.0), -12) + equals(math.tointeger(-12.34), nil) if nocvts2n then - is(math.tointeger('-12'), nil, "function tointeger (string)") - is(math.tointeger('-12.0'), nil) + equals(math.tointeger('-12'), nil, "function tointeger (string)") + equals(math.tointeger('-12.0'), nil) else - is(math.tointeger('-12'), -12, "function tointeger (string)") - is(math.tointeger('-12.0'), -12) + equals(math.tointeger('-12'), -12, "function tointeger (string)") + equals(math.tointeger('-12.0'), -12) end - is(math.tointeger('-12.34'), nil) - is(math.tointeger('bad'), nil) - is(math.tointeger(true), nil, "function tointeger (boolean)") - is(math.tointeger({}), nil, "function tointeger (table)") + equals(math.tointeger('-12.34'), nil) + equals(math.tointeger('bad'), nil) + equals(math.tointeger(true), nil, "function tointeger (boolean)") + equals(math.tointeger({}), nil, "function tointeger (table)") else - is(math.tointeger, nil, "no math.tointeger") + is_nil(math.tointeger, "no math.tointeger") end -- type if has_integer then - is(math.type(3), 'integer', "function type") - is(math.type(3.14), 'float') - is(math.type('3.14'), nil) + equals(math.type(3), 'integer', "function type") + equals(math.type(3.14), 'float') + equals(math.type('3.14'), nil) else - is(math.type, nil, "no math.type") + is_nil(math.type, "no math.type") end -- ult if has_integer then - is(math.ult(2, 3), true, "function ult") - is(math.ult(2, 2), false) - is(math.ult(2, 1), false) - - error_like(function () math.ult(3.14) end, - "^%S+ bad argument #1 to 'ult' %(number has no integer representation%)", - "function ult (float)") - error_like(function () math.ult(2, 3.14) end, - "^%S+ bad argument #2 to 'ult' %(number has no integer representation%)") - error_like(function () math.ult(true) end, - "^[^:]+:%d+: bad argument #1 to 'ult' %(number expected, got boolean%)", - "function ult (boolean)") - error_like(function () math.ult(2, true) end, - "^[^:]+:%d+: bad argument #2 to 'ult' %(number expected, got boolean%)") + equals(math.ult(2, 3), true, "function ult") + equals(math.ult(2, 2), false) + equals(math.ult(2, 1), false) + + error_matches(function () math.ult(3.14) end, + "^%S+ bad argument #1 to 'ult' %(number has no integer representation%)", + "function ult (float)") + error_matches(function () math.ult(2, 3.14) end, + "^%S+ bad argument #2 to 'ult' %(number has no integer representation%)") + error_matches(function () math.ult(true) end, + "^[^:]+:%d+: bad argument #1 to 'ult' %(number expected, got boolean%)", + "function ult (boolean)") + error_matches(function () math.ult(2, true) end, + "^[^:]+:%d+: bad argument #2 to 'ult' %(number expected, got boolean%)") else - is(math.ult, nil, "no math.ult") + is_nil(math.ult, "no math.ult") end done_testing() diff --git a/test/lua-Harness-tests/308-io.t b/test/lua-Harness-tests/308-io.t index 35d39c02..c126adf2 100755 --- a/test/lua-Harness-tests/308-io.t +++ b/test/lua-Harness-tests/308-io.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -45,142 +45,142 @@ local lua = get_lua_binary_name() plan'no_plan' do -- stdin - like(io.stdin, '^file %(0?[Xx]?%x+%)$', "variable stdin") + matches(io.stdin, '^file %(0?[Xx]?%x+%)$', "variable stdin") end do -- stdout - like(io.stdout, '^file %(0?[Xx]?%x+%)$', "variable stdout") + matches(io.stdout, '^file %(0?[Xx]?%x+%)$', "variable stdout") end do -- stderr - like(io.stderr, '^file %(0?[Xx]?%x+%)$', "variable stderr") + matches(io.stderr, '^file %(0?[Xx]?%x+%)$', "variable stderr") end do -- metatable local f = io.tmpfile() local mt = getmetatable(f) - type_ok(mt, 'table', "metatable") + is_table(mt, "metatable") - type_ok(mt.__gc, 'function') - type_ok(mt.__tostring, 'function') - type_ok(mt.__index, 'table') + is_function(mt.__gc) + is_function(mt.__tostring) + is_table(mt.__index) if has_meta53 then - is(mt.__name, 'FILE*') + equals(mt.__name, 'FILE*') else - is(mt.__name, nil) + is_nil(mt.__name) end if has_meta54 then - type_ok(mt.__close, 'function') - type_ok(mt.__index, 'table') - is(mt.close, nil) - is(mt.flush, nil) - is(mt.lines, nil) - is(mt.read, nil) - is(mt.seek, nil) - is(mt.setvbuf, nil) - is(mt.write, nil) + is_function(mt.__close) + is_table(mt.__index) + is_nil(mt.close) + is_nil(mt.flush) + is_nil(mt.lines) + is_nil(mt.read) + is_nil(mt.seek) + is_nil(mt.setvbuf) + is_nil(mt.write) else - is(mt.__close, nil) - is(mt.__index, mt) - type_ok(mt.close, 'function') - type_ok(mt.flush, 'function') - type_ok(mt.lines, 'function') - type_ok(mt.read, 'function') - type_ok(mt.seek, 'function') - type_ok(mt.setvbuf, 'function') - type_ok(mt.write, 'function') + is_nil(mt.__close) + equals(mt.__index, mt) + is_function(mt.close) + is_function(mt.flush) + is_function(mt.lines) + is_function(mt.read) + is_function(mt.seek) + is_function(mt.setvbuf) + is_function(mt.write) end - type_ok(mt.__index.close, 'function') - type_ok(mt.__index.flush, 'function') - type_ok(mt.__index.lines, 'function') - type_ok(mt.__index.read, 'function') - type_ok(mt.__index.seek, 'function') - type_ok(mt.__index.setvbuf, 'function') - type_ok(mt.__index.write, 'function') + is_function(mt.__index.close) + is_function(mt.__index.flush) + is_function(mt.__index.lines) + is_function(mt.__index.read) + is_function(mt.__index.seek) + is_function(mt.__index.setvbuf) + is_function(mt.__index.write) end do -- close local r, msg = io.close(io.stderr) - is(r, nil, "close (std)") - is(msg, "cannot close standard file") + is_nil(r, "close (std)") + equals(msg, "cannot close standard file") end do -- flush - is(io.flush(), true, "function flush") + is_true(io.flush(), "function flush") end do -- open os.remove('file-308.no') local f, msg = io.open("file-308.no") - is(f, nil, "function open") - is(msg, "file-308.no: No such file or directory") + is_nil(f, "function open") + equals(msg, "file-308.no: No such file or directory") os.remove('file-308.txt') f = io.open('file-308.txt', 'w') f:write("file with text\n") f:close() f = io.open('file-308.txt') - like(f, '^file %(0?[Xx]?%x+%)$', "function open") + matches(f, '^file %(0?[Xx]?%x+%)$', "function open") - is(io.close(f), true, "function close") + is_true(io.close(f), "function close") - error_like(function () io.close(f) end, - "^[^:]+:%d+: attempt to use a closed file", - "function close (closed)") + error_matches(function () io.close(f) end, + "^[^:]+:%d+: attempt to use a closed file", + "function close (closed)") if _VERSION == 'Lua 5.1' then todo("not with 5.1") end - error_like(function () io.open('file-308.txt', 'baz') end, - "^[^:]+:%d+: bad argument #2 to 'open' %(invalid mode%)", - "function open (bad mode)") + error_matches(function () io.open('file-308.txt', 'baz') end, + "^[^:]+:%d+: bad argument #2 to 'open' %(invalid mode%)", + "function open (bad mode)") end do -- type - is(io.type("not a file"), nil, "function type") + equals(io.type("not a file"), nil, "function type") local f = io.open('file-308.txt') - is(io.type(f), 'file') - like(tostring(f), '^file %(0?[Xx]?%x+%)$') + equals(io.type(f), 'file') + matches(tostring(f), '^file %(0?[Xx]?%x+%)$') io.close(f) - is(io.type(f), 'closed file') - is(tostring(f), 'file (closed)') + equals(io.type(f), 'closed file') + equals(tostring(f), 'file (closed)') end do -- input - is(io.stdin, io.input(), "function input") - is(io.stdin, io.input(nil)) + equals(io.stdin, io.input(), "function input") + equals(io.stdin, io.input(nil)) local f = io.stdin - like(io.input('file-308.txt'), '^file %(0?[Xx]?%x+%)$') - is(f, io.input(f)) + matches(io.input('file-308.txt'), '^file %(0?[Xx]?%x+%)$') + equals(f, io.input(f)) end do -- output - is(io.output(), io.stdout, "function output") - is(io.output(nil), io.stdout) + equals(io.output(), io.stdout, "function output") + equals(io.output(nil), io.stdout) local f = io.stdout - like(io.output('output.new'), '^file %(0?[Xx]?%x+%)$') - is(f, io.output(f)) + matches(io.output('output.new'), '^file %(0?[Xx]?%x+%)$') + equals(f, io.output(f)) os.remove('output.new') end do -- popen local r, f = pcall(io.popen, lua .. [[ -e "print 'standard output'"]]) if r then - is(io.type(f), 'file', "popen (read)") - is(f:read(), "standard output") - is(io.close(f), true) + equals(io.type(f), 'file', "popen (read)") + equals(f:read(), "standard output") + is_true(io.close(f)) else diag("io.popen not supported") end r, f = pcall(io.popen, lua .. [[ -e "for line in io.lines() do print((line:gsub('e', 'a'))) end"]], 'w') if r then - is(io.type(f), 'file', "popen (write)") + equals(io.type(f), 'file', "popen (write)") f:write("# hello\n") -- not tested : hallo - is(io.close(f), true) + is_true(io.close(f)) else diag("io.popen not supported") end @@ -188,17 +188,17 @@ end do -- lines for line in io.lines('file-308.txt') do - is(line, "file with text", "function lines(filename)") + equals(line, "file with text", "function lines(filename)") end - error_like(function () io.lines('file-308.no') end, - "No such file or directory", - "function lines(no filename)") + error_matches(function () io.lines('file-308.no') end, + "No such file or directory", + "function lines(no filename)") end do -- tmpfile local f = io.tmpfile() - is(io.type(f), 'file', "function tmpfile") + equals(io.type(f), 'file', "function tmpfile") f:write("some text") f:close() end @@ -210,57 +210,57 @@ end do -- :close local r, msg = io.stderr:close() - is(r, nil, "method close (std)") - is(msg, "cannot close standard file") + is_nil(r, "method close (std)") + equals(msg, "cannot close standard file") local f = io.open('file-308.txt') - is(f:close(), true, "method close") + is_true(f:close(), "method close") end do -- :flush - is(io.stderr:flush(), true, "method flush") + equals(io.stderr:flush(), true, "method flush") local f = io.open('file-308.txt') f:close() - error_like(function () f:flush() end, - "^[^:]+:%d+: attempt to use a closed file", - "method flush (closed)") + error_matches(function () f:flush() end, + "^[^:]+:%d+: attempt to use a closed file", + "method flush (closed)") end do -- :read & :write local f = io.open('file-308.txt') f:close() - error_like(function () f:read() end, - "^[^:]+:%d+: attempt to use a closed file", - "method read (closed)") + error_matches(function () f:read() end, + "^[^:]+:%d+: attempt to use a closed file", + "method read (closed)") f = io.open('file-308.txt') local s = f:read() - is(s:len(), 14, "method read") - is(s, "file with text") + equals(s:len(), 14, "method read") + equals(s, "file with text") s = f:read() - is(s, nil) + equals(s, nil) f:close() f = io.open('file-308.txt') - error_like(function () f:read('*z') end, - "^[^:]+:%d+: bad argument #1 to 'read' %(invalid %w+%)", - "method read (invalid)") + error_matches(function () f:read('*z') end, + "^[^:]+:%d+: bad argument #1 to 'read' %(invalid %w+%)", + "method read (invalid)") f:close() f = io.open('file-308.txt') local s1, s2 = f:read('*l', '*l') - is(s1:len(), 14, "method read *l") - is(s1, "file with text") - is(s2, nil) + equals(s1:len(), 14, "method read *l") + equals(s1, "file with text") + equals(s2, nil) f:close() if has_read52 then f = io.open('file-308.txt') s1, s2 = f:read('*L', '*L') - is(s1:len(), 15, "method read *L") - is(s1, "file with text\n") - is(s2, nil) + equals(s1:len(), 15, "method read *L") + equals(s1, "file with text\n") + equals(s2, nil) f:close() else diag("no read *L") @@ -268,8 +268,8 @@ do -- :read & :write f = io.open('file-308.txt') local n1, n2 = f:read('*n', '*n') - is(n1, nil, "method read *n") - is(n2, nil) + equals(n1, nil, "method read *n") + equals(n2, nil) f:close() f = io.open('file-308.num', 'w') @@ -280,13 +280,13 @@ do -- :read & :write f = io.open('file-308.num') n1, n2 = f:read('*n', '*n') - is(n1, 1, "method read *n") - is(n2, 255, "method read *n") + equals(n1, 1, "method read *n") + equals(n2, 255, "method read *n") local n = f:read('*n') if _VERSION < 'Lua 5.3' then - type_ok(n, 'number') + is_number(n) else - is(n, nil, "method read *n too long") + is_nil(n, "method read *n too long") end f:close() @@ -294,39 +294,39 @@ do -- :read & :write f = io.open('file-308.txt') s = f:read('*a') - is(s:len(), 15, "method read *a") - is(s, "file with text\n") + equals(s:len(), 15, "method read *a") + equals(s, "file with text\n") f:close() if has_read53 then f = io.open('file-308.txt') s = f:read('a') - is(s:len(), 15, "method read a") - is(s, "file with text\n") + equals(s:len(), 15, "method read a") + equals(s, "file with text\n") f:close() else diag("* mandatory") end f = io.open('file-308.txt') - is(f:read(0), '', "method read number") - eq_array({f:read(5, 5, 15)}, {'file ', 'with ', "text\n"}) + equals(f:read(0), '', "method read number") + array_equals({f:read(5, 5, 15)}, {'file ', 'with ', "text\n"}) f:close() end do -- :lines local f = io.open('file-308.txt') for line in f:lines() do - is(line, "file with text", "method lines") + equals(line, "file with text", "method lines") end - is(io.type(f), 'file') + equals(io.type(f), 'file') f:close() - is(io.type(f), 'closed file') + equals(io.type(f), 'closed file') if has_lines52 then f = io.open('file-308.txt') for two_char in f:lines(2) do - is(two_char, "fi", "method lines (with read option)") + equals(two_char, "fi", "method lines (with read option)") break end f:close() @@ -339,31 +339,31 @@ do -- :seek local f = io.open('file-308.txt') f:close() - error_like(function () f:seek('end', 0) end, - "^[^:]+:%d+: attempt to use a closed file", - "method seek (closed)") + error_matches(function () f:seek('end', 0) end, + "^[^:]+:%d+: attempt to use a closed file", + "method seek (closed)") f = io.open('file-308.txt') - error_like(function () f:seek('bad', 0) end, - "^[^:]+:%d+: bad argument #1 to 'seek' %(invalid option 'bad'%)", - "method seek (invalid)") + error_matches(function () f:seek('bad', 0) end, + "^[^:]+:%d+: bad argument #1 to 'seek' %(invalid option 'bad'%)", + "method seek (invalid)") f = io.open('file-308.bin', 'w') f:write('ABCDE') f:close() f = io.open('file-308.bin') - is(f:seek('end', 0), 5, "method seek") + equals(f:seek('end', 0), 5, "method seek") f:close() os.remove('file-308.bin') --clean up end do -- :setvbuf local f = io.open('file-308.txt') - is(f:setvbuf('no'), true, "method setvbuf 'no'") + equals(f:setvbuf('no'), true, "method setvbuf 'no'") - is(f:setvbuf('full', 4096), true, "method setvbuf 'full'") + equals(f:setvbuf('full', 4096), true, "method setvbuf 'full'") - is(f:setvbuf('line', 132), true, "method setvbuf 'line'") + equals(f:setvbuf('line', 132), true, "method setvbuf 'line'") f:close() end @@ -372,15 +372,15 @@ os.remove('file-308.txt') -- clean up do -- :write local f = io.open('file-308.out', 'w') f:close() - error_like(function () f:write('end') end, - "^[^:]+:%d+: attempt to use a closed file", - "method write (closed)") + error_matches(function () f:write('end') end, + "^[^:]+:%d+: attempt to use a closed file", + "method write (closed)") f = io.open('file-308.out', 'w') if has_write51 then - is(f:write('end'), true, "method write") + equals(f:write('end'), true, "method write") else - is(f:write('end'), f, "method write") + equals(f:write('end'), f, "method write") end f:close() diff --git a/test/lua-Harness-tests/309-os.t b/test/lua-Harness-tests/309-os.t index a787b147..ff033bbf 100755 --- a/test/lua-Harness-tests/309-os.t +++ b/test/lua-Harness-tests/309-os.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -40,91 +40,91 @@ plan'no_plan' do -- clock local clk = os.clock() - type_ok(clk, 'number', "function clock") - ok(clk <= os.clock()) + is_number(clk, "function clock") + truthy(clk <= os.clock()) end do -- date local d = os.date('!*t', 0) - is(d.year, 1970, "function date") - is(d.month, 1) - is(d.day, 1) - is(d.hour, 0) - is(d.min, 0) - is(d.sec, 0) - is(d.wday, 5) - is(d.yday, 1) - is(d.isdst, false) + equals(d.year, 1970, "function date") + equals(d.month, 1) + equals(d.day, 1) + equals(d.hour, 0) + equals(d.min, 0) + equals(d.sec, 0) + equals(d.wday, 5) + equals(d.yday, 1) + equals(d.isdst, false) - is(os.date('!%d/%m/%y %H:%M:%S', 0), '01/01/70 00:00:00', "function date") + equals(os.date('!%d/%m/%y %H:%M:%S', 0), '01/01/70 00:00:00', "function date") - like(os.date('%H:%M:%S'), '^%d%d:%d%d:%d%d', "function date") + matches(os.date('%H:%M:%S'), '^%d%d:%d%d:%d%d', "function date") if (_VERSION == 'Lua 5.1' and not jit) or luajit20 then todo("not with 5.1") end - is(os.date('%Oy', 0), '70') + equals(os.date('%Oy', 0), '70') if _VERSION == 'Lua 5.1' then todo("not with 5.1") end - error_like(function () os.date('%Ja', 0) end, - "^[^:]+:%d+: bad argument #1 to 'date' %(invalid conversion specifier '%%Ja'%)", - "function date (invalid)") + error_matches(function () os.date('%Ja', 0) end, + "^[^:]+:%d+: bad argument #1 to 'date' %(invalid conversion specifier '%%Ja'%)", + "function date (invalid)") end do -- difftime - is(os.difftime(1234, 1200), 34, "function difftime") + equals(os.difftime(1234, 1200), 34, "function difftime") end do -- execute if has_execute51 then local res = os.execute() - is(res, 1, "function execute -> shell is available") + equals(res, 1, "function execute -> shell is available") - ok(os.execute('__IMPROBABLE__') > 0, "function execute __IMPROBABLE__") + truthy(os.execute('__IMPROBABLE__') > 0, "function execute __IMPROBABLE__") local cmd = lua .. [[ -e "print '# hello from external Lua'"]] - is(os.execute(cmd), 0, "function execute") + equals(os.execute(cmd), 0, "function execute") else local res = os.execute() - is(res, true, "function execute -> shell is available") + is_true(res, "function execute -> shell is available") local r, s, n = os.execute('__IMPROBABLE__') - is(r, nil, "function execute __IMPROBABLE__") - is(s, 'exit') - type_ok(n, 'number') + is_nil(r, "function execute __IMPROBABLE__") + equals(s, 'exit') + is_number(n) local cmd = lua .. [[ -e "print '# hello from external Lua'"]] r, s, n = os.execute(cmd) - is(r, true, "function execute") - is(s, 'exit') - is(n, 0) + is_true(r, "function execute") + equals(s, 'exit') + equals(n, 0) end end do -- exit called with execute if has_execute51 then local cmd = lua .. [[ -e "print '# hello from external Lua'; os.exit(2)"]] - ok(os.execute(cmd) > 0, "function exit called with execute") + truthy(os.execute(cmd) > 0, "function exit called with execute") else local cmd = lua .. [[ -e "print '# hello from external Lua'; os.exit(2)"]] local r, s, n = os.execute(cmd) - is(r, nil, "function exit called with execute") - is(s, 'exit') - is(n, 2, "exit value") + is_nil(r, "function exit called with execute") + equals(s, 'exit') + equals(n, 2, "exit value") cmd = lua .. [[ -e "print '# hello from external Lua'; os.exit(false)"]] r, s, n = os.execute(cmd) - is(r, nil, "function exit called with execute") - is(s, 'exit') - is(n, 1, "exit value") + is_nil(r, "function exit called with execute") + equals(s, 'exit') + equals(n, 1, "exit value") cmd = lua .. [[ -e "print '# hello from external Lua'; os.exit(true, true)"]] r, s, n = os.execute(cmd) - is(r, true, "exit called with execute") - is(s, 'exit') - is(n, 0, "exit value") + is_true(r, "exit called with execute") + equals(s, 'exit') + equals(n, 0, "exit value") end end @@ -132,16 +132,16 @@ do -- exit called with popen local cmd = lua .. [[ -e "print 'reached'; os.exit(); print 'not reached';"]] local res, f = pcall(io.popen, cmd) if res then - is(f:read'*l', 'reached', "exit called with popen") - is(f:read'*l', nil) + equals(f:read'*l', 'reached', "exit called with popen") + equals(f:read'*l', nil) if has_execute51 then local code = f:close() - is(code, true, "exit code") + is_true(code, "exit code") else local r, s, n = f:close() - is(r, true) - is(s, 'exit', "exit code") - is(n, 0, "exit value") + is_true(r) + equals(s, 'exit', "exit code") + equals(n, 0, "exit value") end else diag("io.popen not supported") @@ -150,16 +150,16 @@ do -- exit called with popen cmd = lua .. [[ -e "print 'reached'; os.exit(3); print 'not reached';"]] res, f = pcall(io.popen, cmd) if res then - is(f:read'*l', 'reached', "exit called with popen") - is(f:read'*l', nil) + equals(f:read'*l', 'reached', "exit called with popen") + equals(f:read'*l', nil) if has_execute51 then local code = f:close() - is(code, true, "exit code") + is_true(code, "exit code") else local r, s, n = f:close() - is(r, nil) - is(s, 'exit', "exit code") - is(n, 3, "exit value") + is_nil(r) + equals(s, 'exit', "exit code") + equals(n, 3, "exit value") end else diag("io.popen not supported") @@ -167,10 +167,10 @@ do -- exit called with popen end do -- getenv - is(os.getenv('__IMPROBABLE__'), nil, "function getenv") + equals(os.getenv('__IMPROBABLE__'), nil, "function getenv") local user = os.getenv('LOGNAME') or os.getenv('USERNAME') - type_ok(user, 'string', "function getenv") + is_string(user, "function getenv") end do -- remove @@ -178,12 +178,12 @@ do -- remove f:write("file to remove") f:close() local r = os.remove("file-309.rm") - is(r, true, "function remove") + is_true(r, "function remove") local msg r, msg = os.remove('file-309.rm') - is(r, nil, "function remove") - like(msg, '^file%-309%.rm: No such file or directory') + is_nil(r, "function remove") + matches(msg, '^file%-309%.rm: No such file or directory') end do -- rename @@ -192,25 +192,25 @@ do -- rename f:close() os.remove('file-309.new') local r = os.rename('file-309.old', 'file-309.new') - is(r, true, "function rename") + is_true(r, "function rename") os.remove('file-309.new') -- clean up local msg r, msg = os.rename('file-309.old', 'file-309.new') - is(r, nil, "function rename") - like(msg, 'No such file or directory') + is_nil(r, "function rename") + matches(msg, 'No such file or directory') end do -- setlocale - is(os.setlocale('C', 'all'), 'C', "function setlocale") - is(os.setlocale(), 'C') - is(os.setlocale('unk_loc', 'all'), nil, "function setlocale (unknown locale)") + equals(os.setlocale('C', 'all'), 'C', "function setlocale") + equals(os.setlocale(), 'C') + equals(os.setlocale('unk_loc', 'all'), nil, "function setlocale (unknown locale)") end do -- time - like(os.time(), '^%d+%.?%d*$', "function time") - like(os.time(nil), '^%d+%.?%d*$', "function time") - like(os.time({ + matches(os.time(), '^%d+%.?%d*$', "function time") + matches(os.time(nil), '^%d+%.?%d*$', "function time") + matches(os.time({ sec = 0, min = 0, hour = 0, @@ -220,20 +220,20 @@ do -- time isdst = false, }), '^946%d+$', "function time") - error_like(function () os.time{} end, - "^[^:]+:%d+: field '%w+' missing in date table", - "function time (missing field)") + error_matches(function () os.time{} end, + "^[^:]+:%d+: field '%w+' missing in date table", + "function time (missing field)") - error_like(function () os.time({ day = 'bad', year = 'bad' }) end, - "^[^:]+:%d+: field '%w+'", - "function time (bad field)") + error_matches(function () os.time({ day = 'bad', year = 'bad' }) end, + "^[^:]+:%d+: field '%w+'", + "function time (bad field)") if _VERSION < 'Lua 5.3' then todo("only with integer") end - error_like(function () os.time({ day = 1.5, year = 1.5 }) end, - "^[^:]+:%d+: field '%w+' is not an integer", - "function time (not integer)") + error_matches(function () os.time({ day = 1.5, year = 1.5 }) end, + "^[^:]+:%d+: field '%w+' is not an integer", + "function time (not integer)") if string.packsize and string.packsize('l') == 8 then skip('64bit platforms') @@ -241,7 +241,7 @@ do -- time if _VERSION < 'Lua 5.3' then todo"only with 5.3" end - error_like(function () os.time({ + error_matches(function () os.time({ sec = 0, min = 0, hour = 0, @@ -250,15 +250,15 @@ do -- time year = 1000, isdst = false, }) end, - "^[^:]+:%d+: time result cannot be represented in this installation", - "function time (invalid)") + "^[^:]+:%d+: time result cannot be represented in this installation", + "function time (invalid)") end end do -- tmpname local fname = os.tmpname() - type_ok(fname, 'string', "function tmpname") - ok(fname ~= os.tmpname()) + is_string(fname, "function tmpname") + truthy(fname ~= os.tmpname()) end done_testing() diff --git a/test/lua-Harness-tests/310-debug.t b/test/lua-Harness-tests/310-debug.t index f78af03f..4ec970fb 100755 --- a/test/lua-Harness-tests/310-debug.t +++ b/test/lua-Harness-tests/310-debug.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2020, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -52,57 +52,57 @@ plan'no_plan' -- getfenv if has_getfenv then - is(debug.getfenv(3.14), nil, "function getfenv") + equals(debug.getfenv(3.14), nil, "function getfenv") local function f () end - type_ok(debug.getfenv(f), 'table') - is(debug.getfenv(f), _G) - type_ok(debug.getfenv(print), 'table') - is(debug.getfenv(print), _G) + is_table(debug.getfenv(f)) + equals(debug.getfenv(f), _G) + is_table(debug.getfenv(print)) + equals(debug.getfenv(print), _G) local a = coroutine.create(function () return 1 end) - type_ok(debug.getfenv(a), 'table', "function getfenv (thread)") - is(debug.getfenv(a), _G) + is_table(debug.getfenv(a), "function getfenv (thread)") + equals(debug.getfenv(a), _G) else - is(debug.getfenv, nil, "no debug.getfenv (removed)") + is_nil(debug.getfenv, "no debug.getfenv (removed)") end do -- getinfo - local info = debug.getinfo(is) - type_ok(info, 'table', "function getinfo (function)") - is(info.func, is, " .func") + local info = debug.getinfo(equals) + is_table(info, "function getinfo (function)") + equals(info.func, equals, " .func") - info = debug.getinfo(is, 'L') - type_ok(info, 'table', "function getinfo (function, opt)") - type_ok(info.activelines, 'table') + info = debug.getinfo(equals, 'L') + is_table(info, "function getinfo (function, opt)") + is_table(info.activelines) info = debug.getinfo(1) - type_ok(info, 'table', "function getinfo (level)") - like(info.func, "^function: [0]?[Xx]?%x+", " .func") + is_table(info, "function getinfo (level)") + matches(info.func, "^function: [0]?[Xx]?%x+", " .func") - is(debug.getinfo(12), nil, "function getinfo (too depth)") + equals(debug.getinfo(12), nil, "function getinfo (too depth)") - error_like(function () debug.getinfo('bad') end, - "bad argument #1 to 'getinfo' %(.- expected", - "function getinfo (bad arg)") + error_matches(function () debug.getinfo('bad') end, + "bad argument #1 to 'getinfo' %(.- expected", + "function getinfo (bad arg)") - error_like(function () debug.getinfo(is, 'X') end, - "bad argument #2 to 'getinfo' %(invalid option%)", - "function getinfo (bad opt)") + error_matches(function () debug.getinfo(equals, 'X') end, + "bad argument #2 to 'getinfo' %(invalid option%)", + "function getinfo (bad opt)") end do -- getlocal local name, value = debug.getlocal(0, 1) - type_ok(name, 'string', "function getlocal (level)") - is(value, 0) + is_string(name, "function getlocal (level)") + equals(value, 0) - error_like(function () debug.getlocal(42, 1) end, - "bad argument #1 to 'getlocal' %(level out of range%)", - "function getlocal (out of range)") + error_matches(function () debug.getlocal(42, 1) end, + "bad argument #1 to 'getlocal' %(level out of range%)", + "function getlocal (out of range)") if has_getlocal52 then - name, value = debug.getlocal(like, 1) - type_ok(name, 'string', "function getlocal (func)") - is(value, nil) + name, value = debug.getlocal(matches, 1) + is_string(name, "function getlocal (func)") + equals(value, nil) else diag("no getlocal with function") end @@ -110,31 +110,31 @@ end do -- getmetatable local t = {} - is(debug.getmetatable(t), nil, "function getmetatable") + equals(debug.getmetatable(t), nil, "function getmetatable") local t1 = {} debug.setmetatable(t, t1) - is(debug.getmetatable(t), t1) + equals(debug.getmetatable(t), t1) local a = true - is(debug.getmetatable(a), nil) + equals(debug.getmetatable(a), nil) debug.setmetatable(a, t1) - is(debug.getmetatable(t), t1) + equals(debug.getmetatable(t), t1) a = 3.14 - is(debug.getmetatable(a), nil) + equals(debug.getmetatable(a), nil) debug.setmetatable(a, t1) - is(debug.getmetatable(t), t1) + equals(debug.getmetatable(t), t1) end do -- getregistry local reg = debug.getregistry() - type_ok(reg, 'table', "function getregistry") - type_ok(reg._LOADED, 'table') + is_table(reg, "function getregistry") + is_table(reg._LOADED) end do -- getupvalue local name = debug.getupvalue(plan, 1) - type_ok(name, 'string', "function getupvalue") + is_string(name, "function getupvalue") end do -- gethook @@ -142,156 +142,156 @@ do -- gethook local hook, mask, count if has_gethook54 then hook = debug.gethook() - is(hook, nil, "function gethook") + equals(hook, nil, "function gethook") else hook, mask, count = debug.gethook() - is(hook, nil, "function gethook") - is(mask, '') - is(count, 0) + equals(hook, nil, "function gethook") + equals(mask, '') + equals(count, 0) end local function f () end debug.sethook(f, 'c', 42) hook , mask, count = debug.gethook() - is(hook, f, "function gethook") - is(mask, 'c') - is(count, 42) + equals(hook, f, "function gethook") + equals(mask, 'c') + equals(count, 42) local co = coroutine.create(function () print "thread" end) hook = debug.gethook(co) if jit then - type_ok(hook, 'function', "function gethook(thread)") + is_function(hook, "function gethook(thread)") else - is(hook, nil, "function gethook(thread)") + is_nil(hook, "function gethook(thread)") end end do -- setlocal local name = debug.setlocal(0, 1, 0) - type_ok(name, 'string', "function setlocal (level)") + is_string(name, "function setlocal (level)") name = debug.setlocal(0, 42, 0) - is(name, nil, "function setlocal (level)") + equals(name, nil, "function setlocal (level)") - error_like(function () debug.setlocal(42, 1, true) end, - "bad argument #1 to 'setlocal' %(level out of range%)", - "function setlocal (out of range)") + error_matches(function () debug.setlocal(42, 1, true) end, + "bad argument #1 to 'setlocal' %(level out of range%)", + "function setlocal (out of range)") end -- setcstacklimit if has_setcstacklimit then - type_ok(debug.setcstacklimit(200), 'number', "function setcstacklimit") - is(debug.setcstacklimit(1000), 200) + is_number(debug.setcstacklimit(200), "function setcstacklimit") + equals(debug.setcstacklimit(1000), 200) - error_like(function () debug.setcstacklimit('bad') end, - "^[^:]+:%d+: bad argument #1 to 'setcstacklimit' %(number expected, got string%)", - "function setcstacklimit (bad arg)") + error_matches(function () debug.setcstacklimit('bad') end, + "^[^:]+:%d+: bad argument #1 to 'setcstacklimit' %(number expected, got string%)", + "function setcstacklimit (bad arg)") else - is(debug.setcstacklimit, nil, "no debug.setcstacklimit") + is_nil(debug.setcstacklimit, "no debug.setcstacklimit") end -- setfenv if has_getfenv then local t = {} local function f () end - is(debug.setfenv(f, t), f, "function setfenv") - type_ok(debug.getfenv(f), 'table') - is(debug.getfenv(f), t) - is(debug.setfenv(print, t), print) - type_ok(debug.getfenv(print), 'table') - is(debug.getfenv(print), t) + equals(debug.setfenv(f, t), f, "function setfenv") + is_table(debug.getfenv(f)) + equals(debug.getfenv(f), t) + equals(debug.setfenv(print, t), print) + is_table(debug.getfenv(print)) + equals(debug.getfenv(print), t) t = {} local a = coroutine.create(function () return 1 end) - is(debug.setfenv(a, t), a, "function setfenv (thread)") - type_ok(debug.getfenv(a), 'table') - is(debug.getfenv(a), t) + equals(debug.setfenv(a, t), a, "function setfenv (thread)") + is_table(debug.getfenv(a)) + equals(debug.getfenv(a), t) - error_like(function () t = {}; debug.setfenv(t, t) end, - "^[^:]+:%d+: 'setfenv' cannot change environment of given object", - "function setfenv (forbidden)") + error_matches(function () t = {}; debug.setfenv(t, t) end, + "^[^:]+:%d+: 'setfenv' cannot change environment of given object", + "function setfenv (forbidden)") else - is(debug.setfenv, nil, "no debug.setfenv (removed)") + is_nil(debug.setfenv, "no debug.setfenv (removed)") end do -- setmetatable local t = {} local t1 = {} if has_setmetatable52 then - is(debug.setmetatable(t, t1), t, "function setmetatable") + equals(debug.setmetatable(t, t1), t, "function setmetatable") else - is(debug.setmetatable(t, t1), true, "function setmetatable") + equals(debug.setmetatable(t, t1), true, "function setmetatable") end - is(getmetatable(t), t1) + equals(getmetatable(t), t1) - error_like(function () debug.setmetatable(t, true) end, - "^[^:]+:%d+: bad argument #2 to 'setmetatable' %(nil or table expected") + error_matches(function () debug.setmetatable(t, true) end, + "^[^:]+:%d+: bad argument #2 to 'setmetatable' %(nil or table expected") end do -- setupvalue local r, tb = pcall(require, 'Test.Builder') local value = r and tb:new() or {} local name = debug.setupvalue(plan, 1, value) - type_ok(name, 'string', "function setupvalue") + is_string(name, "function setupvalue") name = debug.setupvalue(plan, 42, true) - is(name, nil) + is_nil(name) end -- getuservalue / setuservalue if has_getuservalue54 then local u = io.tmpfile() -- lua_newuserdatauv(L, sizeof(LStream), 0); - is(debug.getuservalue(u, 0), nil, "function getuservalue") - is(debug.getuservalue(true), nil) + equals(debug.getuservalue(u, 0), nil, "function getuservalue") + equals(debug.getuservalue(true), nil) - error_like(function () debug.getuservalue(u, 'foo') end, - "^[^:]+:%d+: bad argument #2 to 'getuservalue' %(number expected, got string%)") + error_matches(function () debug.getuservalue(u, 'foo') end, + "^[^:]+:%d+: bad argument #2 to 'getuservalue' %(number expected, got string%)") local data = {} - is(debug.setuservalue(u, data, 42), nil, "function setuservalue") + equals(debug.setuservalue(u, data, 42), nil, "function setuservalue") - error_like(function () debug.setuservalue({}, data) end, - "^[^:]+:%d+: bad argument #1 to 'setuservalue' %(userdata expected, got table%)") + error_matches(function () debug.setuservalue({}, data) end, + "^[^:]+:%d+: bad argument #1 to 'setuservalue' %(userdata expected, got table%)") - error_like(function () debug.setuservalue(u, data, 'foo') end, - "^[^:]+:%d+: bad argument #3 to 'setuservalue' %(number expected, got string%)") + error_matches(function () debug.setuservalue(u, data, 'foo') end, + "^[^:]+:%d+: bad argument #3 to 'setuservalue' %(number expected, got string%)") elseif has_getuservalue then local u = io.tmpfile() local old = debug.getuservalue(u) if jit then - type_ok(old, 'table', "function getuservalue") + is_table(old, "function getuservalue") else - is(old, nil, "function getuservalue") + is_nil(old, "function getuservalue") end - is(debug.getuservalue(true), nil) + equals(debug.getuservalue(true), nil) local data = {} local r = debug.setuservalue(u, data) - is(r, u, "function setuservalue") - is(debug.getuservalue(u), data) + equals(r, u, "function setuservalue") + equals(debug.getuservalue(u), data) r = debug.setuservalue(u, old) - is(debug.getuservalue(u), old) + equals(debug.getuservalue(u), old) - error_like(function () debug.setuservalue({}, data) end, - "^[^:]+:%d+: bad argument #1 to 'setuservalue' %(userdata expected, got table%)") + error_matches(function () debug.setuservalue({}, data) end, + "^[^:]+:%d+: bad argument #1 to 'setuservalue' %(userdata expected, got table%)") else - is(debug.getuservalue, nil, "no getuservalue") - is(debug.setuservalue, nil, "no setuservalue") + is_nil(debug.getuservalue, "no getuservalue") + is_nil(debug.setuservalue, "no setuservalue") end do -- traceback - like(debug.traceback(), "^stack traceback:\n", "function traceback") + matches(debug.traceback(), "^stack traceback:\n", "function traceback") - like(debug.traceback("message\n"), "^message\n\nstack traceback:\n", "function traceback with message") + matches(debug.traceback("message\n"), "^message\n\nstack traceback:\n", "function traceback with message") - like(debug.traceback(false), "false", "function traceback") + matches(debug.traceback(false), "false", "function traceback") end -- upvalueid if has_upvalueid then local id = debug.upvalueid(plan, 1) - type_ok(id, 'userdata', "function upvalueid") + is_userdata(id, "function upvalueid") else - is(debug.upvalueid, nil, "no upvalueid") + is_nil(debug.upvalueid, "no upvalueid") end -- upvaluejoin @@ -299,17 +299,17 @@ if has_upvaluejoin and jit then diag("jit upvaluejoin") -- TODO elseif has_upvaluejoin then - debug.upvaluejoin(pass, 1, fail, 1) + debug.upvaluejoin(passes, 1, fails, 1) - error_like(function () debug.upvaluejoin(true, 1, nil, 1) end, - "bad argument #1 to 'upvaluejoin' %(function expected, got boolean%)", - "function upvaluejoin (bad arg)") + error_matches(function () debug.upvaluejoin(true, 1, nil, 1) end, + "bad argument #1 to 'upvaluejoin' %(function expected, got boolean%)", + "function upvaluejoin (bad arg)") - error_like(function () debug.upvaluejoin(pass, 1, true, 1) end, - "bad argument #3 to 'upvaluejoin' %(function expected, got boolean%)", - "function upvaluejoin (bad arg)") + error_matches(function () debug.upvaluejoin(passes, 1, true, 1) end, + "bad argument #3 to 'upvaluejoin' %(function expected, got boolean%)", + "function upvaluejoin (bad arg)") else - is(debug.upvaluejoin, nil, "no upvaluejoin") + is_nil(debug.upvaluejoin, "no upvaluejoin") end done_testing() diff --git a/test/lua-Harness-tests/311-bit32.t b/test/lua-Harness-tests/311-bit32.t index 7023906e..b8ccb7ea 100755 --- a/test/lua-Harness-tests/311-bit32.t +++ b/test/lua-Harness-tests/311-bit32.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2010-2018, Perrad Francois +-- Copyright (C) 2010-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -35,88 +35,88 @@ local has_bit32 = _VERSION == 'Lua 5.2' or profile.compat52 or profile.has_bit32 if not bit32 then plan(1) - nok(has_bit32, "no has_bit32") + falsy(has_bit32, "no has_bit32") os.exit(0) end plan(20) do -- arshift - is(bit32.arshift(0x06, 1), 0x03, "function arshift") - is(bit32.arshift(-3, 1), bit32.arshift(-6, 2), "function arshift") + equals(bit32.arshift(0x06, 1), 0x03, "function arshift") + equals(bit32.arshift(-3, 1), bit32.arshift(-6, 2), "function arshift") end do -- band - is(bit32.band(0x01, 0x03, 0x07), 0x01, "function band") + equals(bit32.band(0x01, 0x03, 0x07), 0x01, "function band") end do -- bnot if string.pack and #string.pack('n', 0) == 4 then - is(bit32.bnot(0x03), (-1 - 0x03), "function bnot") + equals(bit32.bnot(0x03), (-1 - 0x03), "function bnot") else - is(bit32.bnot(0x03), (-1 - 0x03) % 2^32, "function bnot") + equals(bit32.bnot(0x03), (-1 - 0x03) % 2^32, "function bnot") end end do -- bor - is(bit32.bor(0x01, 0x03, 0x07), 0x07, "function bor") + equals(bit32.bor(0x01, 0x03, 0x07), 0x07, "function bor") end do -- btest - is(bit32.btest(0x01), true, "function btest") - is(bit32.btest(0x00), false, "function btest") + equals(bit32.btest(0x01), true, "function btest") + equals(bit32.btest(0x00), false, "function btest") end do -- bxor - is(bit32.bxor(0x01, 0x03, 0x07), 0x05, "function bxor") + equals(bit32.bxor(0x01, 0x03, 0x07), 0x05, "function bxor") end do -- extract - is(bit32.extract(0xFFFF, 3, 3), 0x07, "function extract") + equals(bit32.extract(0xFFFF, 3, 3), 0x07, "function extract") - error_like(function () bit32.extract(0xFFFF, 99) end, - "^[^:]+:%d+: trying to access non%-existent bits", - "function extract (non-existent bits)") + error_matches(function () bit32.extract(0xFFFF, 99) end, + "^[^:]+:%d+: trying to access non%-existent bits", + "function extract (non-existent bits)") - error_like(function () bit32.extract(0xFFFF, -3) end, - "^[^:]+:%d+: bad argument #2 to 'extract' %(field cannot be negative%)", - "function extract (negatif field)") + error_matches(function () bit32.extract(0xFFFF, -3) end, + "^[^:]+:%d+: bad argument #2 to 'extract' %(field cannot be negative%)", + "function extract (negatif field)") - error_like(function () bit32.extract(0xFFFF, 3, -3) end, - "^[^:]+:%d+: bad argument #3 to 'extract' %(width must be positive%)", - "function extract (negative width)") + error_matches(function () bit32.extract(0xFFFF, 3, -3) end, + "^[^:]+:%d+: bad argument #3 to 'extract' %(width must be positive%)", + "function extract (negative width)") end do -- replace - is(bit32.replace(0x0000, 0xFFFF, 3, 3), 0x38, "function replace") + equals(bit32.replace(0x0000, 0xFFFF, 3, 3), 0x38, "function replace") - error_like(function () bit32.replace(0x0000, 0xFFFF, 99) end, - "^[^:]+:%d+: trying to access non%-existent bits", - "function replace (non-existent bits)") + error_matches(function () bit32.replace(0x0000, 0xFFFF, 99) end, + "^[^:]+:%d+: trying to access non%-existent bits", + "function replace (non-existent bits)") - error_like(function () bit32.replace(0x0000, 0xFFFF, -3) end, - "^[^:]+:%d+: bad argument #3 to 'replace' %(field cannot be negative%)", - "function replace (negatif field)") + error_matches(function () bit32.replace(0x0000, 0xFFFF, -3) end, + "^[^:]+:%d+: bad argument #3 to 'replace' %(field cannot be negative%)", + "function replace (negatif field)") - error_like(function () bit32.replace(0x0000, 0xFFFF, 3, -3) end, - "^[^:]+:%d+: bad argument #4 to 'replace' %(width must be positive%)", - "function replace (negative width)") + error_matches(function () bit32.replace(0x0000, 0xFFFF, 3, -3) end, + "^[^:]+:%d+: bad argument #4 to 'replace' %(width must be positive%)", + "function replace (negative width)") end do -- lrotate - is(bit32.lrotate(0x03, 2), 0x0C, "function lrotate") + equals(bit32.lrotate(0x03, 2), 0x0C, "function lrotate") end do -- lshift - is(bit32.lshift(0x03, 2), 0x0C, "function lshift") + equals(bit32.lshift(0x03, 2), 0x0C, "function lshift") end do -- rrotate - is(bit32.rrotate(0x06, 1), 0x03, "function rrotate") + equals(bit32.rrotate(0x06, 1), 0x03, "function rrotate") end do -- rshift - is(bit32.rshift(0x06, 1), 0x03, "function rshift") + equals(bit32.rshift(0x06, 1), 0x03, "function rshift") end -- Local Variables: diff --git a/test/lua-Harness-tests/314-regex.t b/test/lua-Harness-tests/314-regex.t index 58cdb66e..56883bd4 100755 --- a/test/lua-Harness-tests/314-regex.t +++ b/test/lua-Harness-tests/314-regex.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -198,14 +198,14 @@ for _, filename in ipairs(test_files) do end if result:sub(1, 1) == '/' then pattern = result:sub(2, result:len() - 1) - error_like(compiled, pattern, desc) + error_matches(compiled, pattern, desc) else local r, out r, msg = pcall(function () out = compiled() end) if r then - is(out, result, desc) + equals(out, result, desc) else - fail(desc) + fails(desc) diag(msg) end end diff --git a/test/lua-Harness-tests/320-stdin.t b/test/lua-Harness-tests/320-stdin.t index 4828285d..09f92c1b 100755 --- a/test/lua-Harness-tests/320-stdin.t +++ b/test/lua-Harness-tests/320-stdin.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -49,7 +49,7 @@ end local cmd = lua .. [[ -e "dofile(); n = norm(3.4, 1.0); print(twice(n))" < lib-320.lua]] f = io.popen(cmd) - like(f:read'*l', '^7%.088', "function dofile (stdin)") + matches(f:read'*l', '^7%.088', "function dofile (stdin)") f:close() os.remove('lib-320.lua') -- clean up @@ -66,8 +66,8 @@ end local cmd = lua .. [[ -e "f = loadfile(); print(foo); f(); print(foo('ok'))" < foo-320.lua]] f = io.popen(cmd) - is(f:read'*l', 'nil', "function loadfile (stdin)") - is(f:read'*l', 'ok') + equals(f:read'*l', 'nil', "function loadfile (stdin)") + equals(f:read'*l', 'ok') f:close() os.remove('foo-320.lua') -- clean up @@ -80,15 +80,15 @@ do local cmd = lua .. [[ -e "print(io.read'*l'); print(io.read'*l'); print(io.type(io.stdin))" < file-320.txt]] f = io.popen(cmd) - is(f:read'*l', 'file with text', "function io.read *l") - is(f:read'*l', 'nil') - is(f:read'*l', 'file') + equals(f:read'*l', 'file with text', "function io.read *l") + equals(f:read'*l', 'nil') + equals(f:read'*l', 'file') f:close() cmd = lua .. [[ -e "for line in io.lines() do print(line) end" < file-320.txt]] f = io.popen(cmd) - is(f:read'*l', 'file with text', "function io.lines") - is(f:read'*l', nil) + equals(f:read'*l', 'file with text', "function io.lines") + equals(f:read'*l', nil) f:close() os.remove('file-320.txt') -- clean up @@ -102,8 +102,8 @@ do local cmd = lua .. [[ -e "while true do local n1, n2, n3 = io.read('*number', '*number', '*number'); if not n1 then break end; print(math.max(n1, n2, n3)) end" < number-320.txt]] f = io.popen(cmd) - like(f:read'*l', '15000%.?', "function io:read *number") - is(f:read'*l', '1000001') + matches(f:read'*l', '15000%.?', "function io:read *number") + equals(f:read'*l', '1000001') f:close() os.remove('number-320.txt') -- clean up @@ -118,8 +118,8 @@ do local cmd = lua .. [[ -e "debug.debug()" < dbg-320.txt]] f = io.popen(cmd) - is(f:read'*l', 'ok', "function debug.debug") - is(f:read'*l', nil) + equals(f:read'*l', 'ok', "function debug.debug") + equals(f:read'*l', nil) f:close() os.remove('dbg-320.txt') -- clean up diff --git a/test/lua-Harness-tests/401-bitop.t b/test/lua-Harness-tests/401-bitop.t index f95aebf3..e454420e 100755 --- a/test/lua-Harness-tests/401-bitop.t +++ b/test/lua-Harness-tests/401-bitop.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2018, Perrad Francois +-- Copyright (C) 2018-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -32,70 +32,70 @@ end plan(29) -is(package.loaded.bit, _G.bit, "package.loaded") -is(require'bit', bit, "require") +equals(package.loaded.bit, _G.bit, "package.loaded") +equals(require'bit', bit, "require") do -- arshift - is(bit.arshift(256, 8), 1, "function arshift") - is(bit.arshift(-256, 8), -1) + equals(bit.arshift(256, 8), 1, "function arshift") + equals(bit.arshift(-256, 8), -1) end do -- band - is(bit.band(0x12345678, 0xff), 0x00000078, "function band") + equals(bit.band(0x12345678, 0xff), 0x00000078, "function band") end do -- bnot - is(bit.bnot(0), -1, "function bnot") - is(bit.bnot(-1), 0) - is(bit.bnot(0xffffffff), 0) + equals(bit.bnot(0), -1, "function bnot") + equals(bit.bnot(-1), 0) + equals(bit.bnot(0xffffffff), 0) end do -- bor - is(bit.bor(1, 2, 4, 8), 15, "function bor") + equals(bit.bor(1, 2, 4, 8), 15, "function bor") end do -- bswap - is(bit.bswap(0x12345678), 0x78563412, "function bswap") - is(bit.bswap(0x78563412), 0x12345678) + equals(bit.bswap(0x12345678), 0x78563412, "function bswap") + equals(bit.bswap(0x78563412), 0x12345678) end do -- bxor - is(bit.bxor(0xa5a5f0f0, 0xaa55ff00), 0x0ff00ff0, "function bxor") + equals(bit.bxor(0xa5a5f0f0, 0xaa55ff00), 0x0ff00ff0, "function bxor") end do -- lshift - is(bit.lshift(1, 0), 1, "function lshift") - is(bit.lshift(1, 8), 256) - is(bit.lshift(1, 40), 256) - is(bit.lshift(0x87654321, 12), 0x54321000) + equals(bit.lshift(1, 0), 1, "function lshift") + equals(bit.lshift(1, 8), 256) + equals(bit.lshift(1, 40), 256) + equals(bit.lshift(0x87654321, 12), 0x54321000) end do -- rol - is(bit.rol(0x12345678, 12), 0x45678123, "function rol") + equals(bit.rol(0x12345678, 12), 0x45678123, "function rol") end do -- ror - is(bit.ror(0x12345678, 12), 0x67812345, "function ror") + equals(bit.ror(0x12345678, 12), 0x67812345, "function ror") end do -- rshift - is(bit.rshift(256, 8), 1, "function rshift") - is(bit.rshift(-256, 8), 16777215) - is(bit.rshift(0x87654321, 12), 0x00087654) + equals(bit.rshift(256, 8), 1, "function rshift") + equals(bit.rshift(-256, 8), 16777215) + equals(bit.rshift(0x87654321, 12), 0x00087654) end do -- tobit - is(bit.tobit(0xffffffff + 1), 0, "function tobit") - is(bit.tobit(2^40 + 1234), 1234) + equals(bit.tobit(0xffffffff + 1), 0, "function tobit") + equals(bit.tobit(2^40 + 1234), 1234) end do -- tohex - is(bit.tohex(1), '00000001', "function tohex") - is(bit.tohex(-1), 'ffffffff') - is(bit.tohex(0xffffffff), 'ffffffff') - is(bit.tohex(-1, -8), 'FFFFFFFF') - is(bit.tohex(0x21, 4), '0021') - is(bit.tohex(0x87654321, 4), '4321') + equals(bit.tohex(1), '00000001', "function tohex") + equals(bit.tohex(-1), 'ffffffff') + equals(bit.tohex(0xffffffff), 'ffffffff') + equals(bit.tohex(-1, -8), 'FFFFFFFF') + equals(bit.tohex(0x21, 4), '0021') + equals(bit.tohex(0x87654321, 4), '4321') end -- Local Variables: diff --git a/test/lua-Harness-tests/402-ffi.t b/test/lua-Harness-tests/402-ffi.t index a2e32a54..73507a61 100755 --- a/test/lua-Harness-tests/402-ffi.t +++ b/test/lua-Harness-tests/402-ffi.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2018, Perrad Francois +-- Copyright (C) 2018-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -32,106 +32,106 @@ end if not pcall(require, 'ffi') then plan(2) - is(_G.ffi, nil, "no FFI") - is(package.loaded.ffi, nil) + is_nil(_G.ffi, "no FFI") + is_nil(package.loaded.ffi) os.exit(0) end plan(33) -is(_G.ffi, nil, "ffi not loaded by default") +is_nil(_G.ffi, "ffi not loaded by default") ffi = require'ffi' -is(package.loaded.ffi, ffi, "package.loaded") -is(require'ffi', ffi, "require") +equals(package.loaded.ffi, ffi, "package.loaded") +equals(require'ffi', ffi, "require") do -- C - type_ok(ffi.C, 'userdata', 'C') + is_userdata(ffi.C, 'C') end do -- abi - type_ok(ffi.abi('32bit'), 'boolean', "abi") - type_ok(ffi.abi('64bit'), 'boolean') - type_ok(ffi.abi('le'), 'boolean') - type_ok(ffi.abi('be'), 'boolean') - type_ok(ffi.abi('fpu'), 'boolean') - type_ok(ffi.abi('softfp'), 'boolean') - type_ok(ffi.abi('hardfp'), 'boolean') - type_ok(ffi.abi('eabi'), 'boolean') - type_ok(ffi.abi('win'), 'boolean') - is(ffi.abi('bad'), false) - is(ffi.abi(0), false) - - error_like(function () ffi.abi(true) end, - "^[^:]+:%d+: bad argument #1 to 'abi' %(string expected, got boolean%)", - "function unpack missing size") + is_boolean(ffi.abi('32bit'), "abi") + is_boolean(ffi.abi('64bit')) + is_boolean(ffi.abi('le')) + is_boolean(ffi.abi('be')) + is_boolean(ffi.abi('fpu')) + is_boolean(ffi.abi('softfp')) + is_boolean(ffi.abi('hardfp')) + is_boolean(ffi.abi('eabi')) + is_boolean(ffi.abi('win')) + is_false(ffi.abi('bad')) + is_false(ffi.abi(0)) + + error_matches(function () ffi.abi(true) end, + "^[^:]+:%d+: bad argument #1 to 'abi' %(string expected, got boolean%)", + "function unpack missing size") end do -- alignof - type_ok(ffi.alignof, 'function', "alignof") + is_function(ffi.alignof, "alignof") end do -- arch - is(ffi.arch, jit.arch, "alias arch") + equals(ffi.arch, jit.arch, "alias arch") end do -- cast - type_ok(ffi.cast, 'function', "cast") + is_function(ffi.cast, "cast") end do -- cdef - type_ok(ffi.cdef, 'function', "cdef") + is_function(ffi.cdef, "cdef") end do -- copy - type_ok(ffi.copy, 'function', "copy") + is_function(ffi.copy, "copy") end do -- errno - type_ok(ffi.errno, 'function', "errno") + is_function(ffi.errno, "errno") end do -- fill - type_ok(ffi.fill, 'function', "fill") + is_function(ffi.fill, "fill") end do -- gc - type_ok(ffi.gc, 'function', "gc") + is_function(ffi.gc, "gc") end do -- istype - type_ok(ffi.istype, 'function', "istype") + is_function(ffi.istype, "istype") end do -- load - type_ok(ffi.load, 'function', "load") + is_function(ffi.load, "load") end do -- metatype - type_ok(ffi.metatype, 'function', "metatype") + is_function(ffi.metatype, "metatype") end do -- new - type_ok(ffi.new, 'function', "new") + is_function(ffi.new, "new") end do -- offsetof - type_ok(ffi.offsetof, 'function', "offsetof") + is_function(ffi.offsetof, "offsetof") end do -- os - is(ffi.os, jit.os, "alias os") + equals(ffi.os, jit.os, "alias os") end do -- sizeof - type_ok(ffi.sizeof, 'function', "sizeof") + is_function(ffi.sizeof, "sizeof") end do -- string - type_ok(ffi.string, 'function', "string") + is_function(ffi.string, "string") end do -- typeof - type_ok(ffi.typeof, 'function', "typeof") + is_function(ffi.typeof, "typeof") end -- Local Variables: diff --git a/test/lua-Harness-tests/403-jit.t b/test/lua-Harness-tests/403-jit.t index 0073c90d..306a7c44 100755 --- a/test/lua-Harness-tests/403-jit.t +++ b/test/lua-Harness-tests/403-jit.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2018-2020, Perrad Francois +-- Copyright (C) 2018-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -39,118 +39,118 @@ local has_jit_util = not ujit and not jit.version:match'RaptorJIT' plan'no_plan' -is(package.loaded.jit, _G.jit, "package.loaded") -is(require'jit', jit, "require") +equals(package.loaded.jit, _G.jit, "package.loaded") +equals(require'jit', jit, "require") do -- arch - type_ok(jit.arch, 'string', "arch") + is_string(jit.arch, "arch") end do -- flush - type_ok(jit.flush, 'function', "flush") + is_function(jit.flush, 'function', "flush") end do -- off jit.off() - is(jit.status(), false, "off") + is_false(jit.status(), "off") end -- on if compiled_with_jit then jit.on() - is(jit.status(), true, "on") + is_true(jit.status(), "on") else - error_like(function () jit.on() end, - "^[^:]+:%d+: JIT compiler permanently disabled by build option", - "no jit.on") + error_matches(function () jit.on() end, + "^[^:]+:%d+: JIT compiler permanently disabled by build option", + "no jit.on") end -- opt if has_jit_opt then - type_ok(jit.opt, 'table', "opt.*") - type_ok(jit.opt.start, 'function', "opt.start") + is_table(jit.opt, "opt.*") + is_function(jit.opt.start, 'function', "opt.start") else - is(jit.opt, nil, "no jit.opt") + is_nil(jit.opt, "no jit.opt") end do -- os - type_ok(jit.os, 'string', "os") + is_string(jit.os, "os") end -- prngstate if profile.openresty then - type_ok(jit.prngstate(), 'table', "prngstate") + is_table(jit.prngstate(), "prngstate") local s1 = { 1, 2, 3, 4, 5, 6, 7, 8} - type_ok(jit.prngstate(s1), 'table') + is_table(jit.prngstate(s1)) local s2 = { 8, 7, 6, 5, 4, 3, 2, 1} - eq_array(jit.prngstate(s2), s1) - eq_array(jit.prngstate(), s2) + array_equals(jit.prngstate(s2), s1) + array_equals(jit.prngstate(), s2) - type_ok(jit.prngstate(32), 'table', "backward compat") - eq_array(jit.prngstate(5617), { 32, 0, 0, 0, 0, 0, 0, 0 }) - eq_array(jit.prngstate(), { 5617, 0, 0, 0, 0, 0, 0, 0 }) + is_table(jit.prngstate(32), 'table', "backward compat") + array_equals(jit.prngstate(5617), { 32, 0, 0, 0, 0, 0, 0, 0 }) + array_equals(jit.prngstate(), { 5617, 0, 0, 0, 0, 0, 0, 0 }) - error_like(function () jit.prngstate(-1) end, - "^[^:]+:%d+: bad argument #1 to 'prngstate' %(PRNG state must be an array with up to 8 integers or an integer%)") + error_matches(function () jit.prngstate(-1) end, + "^[^:]+:%d+: bad argument #1 to 'prngstate' %(PRNG state must be an array with up to 8 integers or an integer%)") - error_like(function () jit.prngstate(false) end, - "^[^:]+:%d+: bad argument #1 to 'prngstate' %(table expected, got boolean%)") + error_matches(function () jit.prngstate(false) end, + "^[^:]+:%d+: bad argument #1 to 'prngstate' %(table expected, got boolean%)") elseif jit.version:match'moonjit' then - is(jit.prngstate(), 0, "prngstate") + equals(jit.prngstate(), 0, "prngstate") else - is(jit.prngstate, nil, "no jit.prngstate"); + is_nil(jit.prngstate, "no jit.prngstate"); end -- security if has_jit_security then - type_ok(jit.security, 'function', "security") - type_ok(jit.security('prng'), 'number', "prng") - type_ok(jit.security('strhash'), 'number', "strhash") - type_ok(jit.security('strid'), 'number', "stdid") - type_ok(jit.security('mcode'), 'number', "mcode") - - error_like(function () jit.security('foo') end, - "^[^:]+:%d+: bad argument #1 to 'security' %(invalid option 'foo'%)") + is_function(jit.security, "security") + is_number(jit.security('prng'), "prng") + is_number(jit.security('strhash'), "strhash") + is_number(jit.security('strid'), "stdid") + is_number(jit.security('mcode'), "mcode") + + error_matches(function () jit.security('foo') end, + "^[^:]+:%d+: bad argument #1 to 'security' %(invalid option 'foo'%)") else - is(jit.security, nil, "no jit.security") + is_nil(jit.security, "no jit.security") end do -- status local status = { jit.status() } - type_ok(status[1], 'boolean', "status") + is_boolean(status[1], "status") if compiled_with_jit then for i = 2, #status do - type_ok(status[i], 'string', status[i]) + is_string(status[i], status[i]) end else - is(#status, 1) + equals(#status, 1) end end -- util if has_jit_util then local jutil = require'jit.util' - type_ok(jutil, 'table', "util") - is(package.loaded['jit.util'], jutil) + is_table(jutil, "util") + equals(package.loaded['jit.util'], jutil) if luajit20 then - is(jit.util, jutil, "util inside jit") + equals(jit.util, jutil, "util inside jit") else - is(jit.util, nil, "no util inside jit") + is_nil(jit.util, "no util inside jit") end else local r = pcall(require, 'jit.util') - is(r, false, "no jit.util") + is_false(r, "no jit.util") end do -- version - type_ok(jit.version, 'string', "version") - like(jit.version, '^%w+ %d%.%d%.%d') + is_string(jit.version, "version") + matches(jit.version, '^%w+ %d%.%d%.%d') end do -- version_num - type_ok(jit.version_num, 'number', "version_num") - like(string.format("%06d", jit.version_num), '^0[12]0[012]%d%d$') + is_number(jit.version_num, "version_num") + matches(string.format("%06d", jit.version_num), '^0[12]0[012]%d%d$') end done_testing() diff --git a/test/lua-Harness-tests/404-ext.t b/test/lua-Harness-tests/404-ext.t index a799c750..afe1d5b5 100755 --- a/test/lua-Harness-tests/404-ext.t +++ b/test/lua-Harness-tests/404-ext.t @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2019-2020, Perrad Francois +-- Copyright (C) 2019-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -36,124 +36,124 @@ plan'no_plan' do -- table.new local r, new = pcall(require, 'table.new') - is(r, true, 'table.new') - type_ok(new, 'function') - is(package.loaded['table.new'], new) + is_true(r, 'table.new') + is_function(new) + equals(package.loaded['table.new'], new) - type_ok(new(100, 0), 'table') - type_ok(new(0, 100), 'table') - type_ok(new(200, 200), 'table') + is_table(new(100, 0)) + is_table(new(0, 100)) + is_table(new(200, 200)) - error_like(function () new(42) end, - "^[^:]+:%d+: bad argument #2 to 'new' %(number expected, got no value%)") + error_matches(function () new(42) end, + "^[^:]+:%d+: bad argument #2 to 'new' %(number expected, got no value%)") end do -- table.clear local r, clear = pcall(require, 'table.clear') - is(r, true, 'table.clear') - type_ok(clear, 'function') - is(package.loaded['table.clear'], clear) + is_true(r, 'table.clear') + is_function(clear) + equals(package.loaded['table.clear'], clear) local t = { 'foo', bar = 42 } - is(t[1], 'foo') - is(t.bar, 42) + equals(t[1], 'foo') + equals(t.bar, 42) clear(t) - is(t[1], nil) - is(t.bar, nil) + is_nil(t[1]) + is_nil(t.bar) - error_like(function () clear(42) end, - "^[^:]+:%d+: bad argument #1 to 'clear' %(table expected, got number%)") + error_matches(function () clear(42) end, + "^[^:]+:%d+: bad argument #1 to 'clear' %(table expected, got number%)") end -- table.clone if profile.openresty then local r, clone = pcall(require, 'table.clone') - is(r, true, 'table.clone') - type_ok(clone, 'function') - is(package.loaded['table.clone'], clone) + is_true(r, 'table.clone') + is_function(clone) + equals(package.loaded['table.clone'], clone) local mt = {} local t = setmetatable({ 'foo', bar = 42 }, mt) - is(t[1], 'foo') - is(t.bar, 42) + equals(t[1], 'foo') + equals(t.bar, 42) local t2 = clone(t) - type_ok(t2, 'table') - isnt(t2, t) - is(getmetatable(t2), nil) - is(t2[1], 'foo') - is(t2.bar, 42) - - error_like(function () clone(42) end, - "^[^:]+:%d+: bad argument #1 to 'clone' %(table expected, got number%)") + is_table(t2) + not_equals(t2, t) + is_nil(getmetatable(t2)) + equals(t2[1], 'foo') + equals(t2.bar, 42) + + error_matches(function () clone(42) end, + "^[^:]+:%d+: bad argument #1 to 'clone' %(table expected, got number%)") else - is(pcall(require, 'table.clone'), false, 'no table.clone') + is_false(pcall(require, 'table.clone'), 'no table.clone') end -- table.isarray if profile.openresty then local r, isarray = pcall(require, 'table.isarray') - is(r, true, 'table.isarray') - type_ok(isarray, 'function') - is(package.loaded['table.isarray'], isarray) - - is(isarray({ [3] = 3, [5.3] = 4 }), false) - is(isarray({ [3] = 'a', [5] = true }), true) - is(isarray({ 'a', nil, true, 3.14 }), true) - is(isarray({}), true) - is(isarray({ ['1'] = 3, ['2'] = 4 }), false) - is(isarray({ ['dog'] = 3, ['cat'] = 4 }), false) - is(isarray({ 'dog', 'cat', true, ['bird'] = 3 }), false) - - error_like(function () isarray(42) end, - "^[^:]+:%d+: bad argument #1 to 'isarray' %(table expected, got number%)") + is_true(r, 'table.isarray') + is_function(isarray) + equals(package.loaded['table.isarray'], isarray) + + is_false(isarray({ [3] = 3, [5.3] = 4 })) + is_true(isarray({ [3] = 'a', [5] = true })) + is_true(isarray({ 'a', nil, true, 3.14 })) + is_true(isarray({})) + is_false(isarray({ ['1'] = 3, ['2'] = 4 })) + is_false(isarray({ ['dog'] = 3, ['cat'] = 4 })) + is_false(isarray({ 'dog', 'cat', true, ['bird'] = 3 })) + + error_matches(function () isarray(42) end, + "^[^:]+:%d+: bad argument #1 to 'isarray' %(table expected, got number%)") else - is(pcall(require, 'table.isarray'), false, 'no table.isarray') + is_false(pcall(require, 'table.isarray'), 'no table.isarray') end -- table.isempty if profile.openresty then local r, isempty = pcall(require, 'table.isempty') - is(r, true, 'table.isempty') - type_ok(isempty, 'function') - is(package.loaded['table.isempty'], isempty) - - is(isempty({}), true) - is(isempty({ nil }), true) - is(isempty({ dogs = nil }), true) - is(isempty({ 3.1 }), false) - is(isempty({ 'a', 'b' }), false) - is(isempty({ nil, false }), false) - is(isempty({ dogs = 3 }), false) - is(isempty({ dogs = 3, cats = 4 }), false) - is(isempty({ dogs = 3, 5 }), false) - - error_like(function () isempty(42) end, - "^[^:]+:%d+: bad argument #1 to 'isempty' %(table expected, got number%)") + is_true(r, 'table.isempty') + is_function(isempty) + equals(package.loaded['table.isempty'], isempty) + + is_true(isempty({})) + is_true(isempty({ nil })) + is_true(isempty({ dogs = nil })) + is_false(isempty({ 3.1 })) + is_false(isempty({ 'a', 'b' })) + is_false(isempty({ nil, false })) + is_false(isempty({ dogs = 3 })) + is_false(isempty({ dogs = 3, cats = 4 })) + is_false(isempty({ dogs = 3, 5 })) + + error_matches(function () isempty(42) end, + "^[^:]+:%d+: bad argument #1 to 'isempty' %(table expected, got number%)") else - is(pcall(require, 'table.isempty'), false, 'no table.isempty') + is_false(pcall(require, 'table.isempty'), 'no table.isempty') end -- table.nkeys if profile.openresty then local r, nkeys = pcall(require, 'table.nkeys') - is(r, true, 'table.nkeys') - type_ok(nkeys, 'function') - is(package.loaded['table.nkeys'], nkeys) - - is(nkeys({}), 0) - is(nkeys({ cats = 4 }), 1) - is(nkeys({ dogs = 3, cats = 4 }), 2) - is(nkeys({ dogs = nil, cats = 4 }), 1) - is(nkeys({ 'cats' }), 1) - is(nkeys({ 'dogs', 3, 'cats', 4 }), 4) - is(nkeys({ 'dogs', nil, 'cats', 4 }), 3) - is(nkeys({ cats = 4, 5, 6 }), 3) - is(nkeys({ nil, 'foo', dogs = 3, cats = 4 }), 3) - - error_like(function () nkeys(42) end, - "^[^:]+:%d+: bad argument #1 to 'nkeys' %(table expected, got number%)") + is_true(r, 'table.nkeys') + is_function(nkeys) + equals(package.loaded['table.nkeys'], nkeys) + + equals(nkeys({}), 0) + equals(nkeys({ cats = 4 }), 1) + equals(nkeys({ dogs = 3, cats = 4 }), 2) + equals(nkeys({ dogs = nil, cats = 4 }), 1) + equals(nkeys({ 'cats' }), 1) + equals(nkeys({ 'dogs', 3, 'cats', 4 }), 4) + equals(nkeys({ 'dogs', nil, 'cats', 4 }), 3) + equals(nkeys({ cats = 4, 5, 6 }), 3) + equals(nkeys({ nil, 'foo', dogs = 3, cats = 4 }), 3) + + error_matches(function () nkeys(42) end, + "^[^:]+:%d+: bad argument #1 to 'nkeys' %(table expected, got number%)") else - is(pcall(require, 'table.nkeys'), false, 'no table.nkeys') + is_false(pcall(require, 'table.nkeys'), 'no table.nkeys') end -- thread.exdata diff --git a/test/lua-Harness-tests/411-luajit.t.disabled b/test/lua-Harness-tests/411-luajit.t.disabled index feb752eb..ad7e279e 100755 --- a/test/lua-Harness-tests/411-luajit.t.disabled +++ b/test/lua-Harness-tests/411-luajit.t.disabled @@ -2,7 +2,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2018-2020, Perrad Francois +-- Copyright (C) 2018-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -44,162 +44,162 @@ local has_openresty_listing = profile.openresty or jit.version:match'moonjit' plan'no_plan' diag(lua) -local f = io.open('hello-404.lua', 'w') +local f = io.open('hello-411.lua', 'w') f:write([[ print 'Hello World' ]]) f:close() -os.execute(lua .. " -b hello-404.lua hello-404.out") -local cmd = lua .. " hello-404.out" +os.execute(lua .. " -b hello-411.lua hello-411.out") +local cmd = lua .. " hello-411.out" f = io.popen(cmd) -is(f:read'*l', 'Hello World', "-b") +equals(f:read'*l', 'Hello World', "-b") f:close() -os.execute(lua .. " -bg hello-404.lua hello-404.out") -cmd = lua .. " hello-404.out" +os.execute(lua .. " -bg hello-411.lua hello-411.out") +cmd = lua .. " hello-411.out" f = io.popen(cmd) -is(f:read'*l', 'Hello World', "-bg") +equals(f:read'*l', 'Hello World', "-bg") f:close() -os.execute(lua .. " -be 'print[[Hello World]]' hello-404.out") -cmd = lua .. " hello-404.out" +os.execute(lua .. " -be 'print[[Hello World]]' hello-411.out") +cmd = lua .. " hello-411.out" f = io.popen(cmd) -is(f:read'*l', 'Hello World', "-be") +equals(f:read'*l', 'Hello World', "-be") f:close() -os.remove('hello-404.out') -- clean up +os.remove('hello-411.out') -- clean up if has_jutil then - cmd = lua .. " -bl hello-404.lua" + cmd = lua .. " -bl hello-411.lua" f = io.popen(cmd) - like(f:read'*l', '^%-%- BYTECODE %-%- hello%-404%.lua', "-bl hello.lua") + matches(f:read'*l', '^%-%- BYTECODE %-%- hello%-411%.lua', "-bl hello.lua") if has_openresty_listing then - like(f:read'*l', '^KGC 0') - like(f:read'*l', '^KGC 1') + matches(f:read'*l', '^KGC 0') + matches(f:read'*l', '^KGC 1') end - like(f:read'*l', '^0001 %u[%u%d]+%s+') - like(f:read'*l', '^0002 %u[%u%d]+%s+') - like(f:read'*l', '^0003 %u[%u%d]+%s+') + matches(f:read'*l', '^0001 %u[%u%d]+%s+') + matches(f:read'*l', '^0002 %u[%u%d]+%s+') + matches(f:read'*l', '^0003 %u[%u%d]+%s+') f:close() - os.execute(lua .. " -bl hello-404.lua hello-404.txt") - f = io.open('hello-404.txt', 'r') - like(f:read'*l', '^%-%- BYTECODE %-%- hello%-404%.lua', "-bl hello.lua hello.txt") + os.execute(lua .. " -bl hello-411.lua hello-411.txt") + f = io.open('hello-411.txt', 'r') + matches(f:read'*l', '^%-%- BYTECODE %-%- hello%-411%.lua', "-bl hello.lua hello.txt") if has_openresty_listing then - like(f:read'*l', '^KGC 0') - like(f:read'*l', '^KGC 1') + matches(f:read'*l', '^KGC 0') + matches(f:read'*l', '^KGC 1') end - like(f:read'*l', '^0001 %u[%u%d]+%s+') - like(f:read'*l', '^0002 %u[%u%d]+%s+') - like(f:read'*l', '^0003 %u[%u%d]+%s+') + matches(f:read'*l', '^0001 %u[%u%d]+%s+') + matches(f:read'*l', '^0002 %u[%u%d]+%s+') + matches(f:read'*l', '^0003 %u[%u%d]+%s+') f:close() end if has_openresty_listing then - cmd = lua .. " -bL hello-404.lua" + cmd = lua .. " -bL hello-411.lua" f = io.popen(cmd) - like(f:read'*l', '^%-%- BYTECODE %-%- hello%-404%.lua', "-bL hello.lua") - like(f:read'*l', '^KGC 0') - like(f:read'*l', '^KGC 1') - like(f:read'*l', '^0001 %[1%] %u[%u%d]+%s+') - like(f:read'*l', '^0002 %[1%] %u[%u%d]+%s+') - like(f:read'*l', '^0003 %[1%] %u[%u%d]+%s+') + matches(f:read'*l', '^%-%- BYTECODE %-%- hello%-411%.lua', "-bL hello.lua") + matches(f:read'*l', '^KGC 0') + matches(f:read'*l', '^KGC 1') + matches(f:read'*l', '^0001 %[1%] %u[%u%d]+%s+') + matches(f:read'*l', '^0002 %[1%] %u[%u%d]+%s+') + matches(f:read'*l', '^0003 %[1%] %u[%u%d]+%s+') f:close() - os.execute(lua .. " -bL hello-404.lua hello-404.txt") - f = io.open('hello-404.txt', 'r') - like(f:read'*l', '^%-%- BYTECODE %-%- hello%-404%.lua', "-bL hello.lua hello.txt") - like(f:read'*l', '^KGC 0') - like(f:read'*l', '^KGC 1') - like(f:read'*l', '^0001 %[1%] %u[%u%d]+%s+') - like(f:read'*l', '^0002 %[1%] %u[%u%d]+%s+') - like(f:read'*l', '^0003 %[1%] %u[%u%d]+%s+') + os.execute(lua .. " -bL hello-411.lua hello-411.txt") + f = io.open('hello-411.txt', 'r') + matches(f:read'*l', '^%-%- BYTECODE %-%- hello%-411%.lua', "-bL hello.lua hello.txt") + matches(f:read'*l', '^KGC 0') + matches(f:read'*l', '^KGC 1') + matches(f:read'*l', '^0001 %[1%] %u[%u%d]+%s+') + matches(f:read'*l', '^0002 %[1%] %u[%u%d]+%s+') + matches(f:read'*l', '^0003 %[1%] %u[%u%d]+%s+') f:close() end -os.remove('hello-404.txt') -- clean up - -os.execute(lua .. " -b hello-404.lua hello-404.c") -f = io.open('hello-404.c', 'r') -like(f:read'*l', '^#ifdef __?cplusplus$', "-b hello.lua hello.c") -like(f:read'*l', '^extern "C"$') -like(f:read'*l', '^#endif$') -like(f:read'*l', '^#ifdef _WIN32$') -like(f:read'*l', '^__declspec%(dllexport%)$') -like(f:read'*l', '^#endif$') -like(f:read'*l', '^const.- char luaJIT_BC_hello_404%[%] = {$') -like(f:read'*l', '^%d+,%d+,%d+,') +os.remove('hello-411.txt') -- clean up + +os.execute(lua .. " -b hello-411.lua hello-411.c") +f = io.open('hello-411.c', 'r') +matches(f:read'*l', '^#ifdef __?cplusplus$', "-b hello.lua hello.c") +matches(f:read'*l', '^extern "C"$') +matches(f:read'*l', '^#endif$') +matches(f:read'*l', '^#ifdef _WIN32$') +matches(f:read'*l', '^__declspec%(dllexport%)$') +matches(f:read'*l', '^#endif$') +matches(f:read'*l', '^const.- char luaJIT_BC_hello_411%[%] = {$') +matches(f:read'*l', '^%d+,%d+,%d+,') f:close() -os.remove('hello-404.c') -- clean up +os.remove('hello-411.c') -- clean up -os.execute(lua .. " -b hello-404.lua hello-404.h") -f = io.open('hello-404.h', 'r') -like(f:read'*l', '^#define luaJIT_BC_hello_404_SIZE %d+$', "-b hello.lua hello.h") -like(f:read'*l', '^static const.- char luaJIT_BC_hello_404%[%] = {$') -like(f:read'*l', '^%d+,%d+,%d+,') +os.execute(lua .. " -b hello-411.lua hello-411.h") +f = io.open('hello-411.h', 'r') +matches(f:read'*l', '^#define luaJIT_BC_hello_411_SIZE %d+$', "-b hello.lua hello.h") +matches(f:read'*l', '^static const.- char luaJIT_BC_hello_411%[%] = {$') +matches(f:read'*l', '^%d+,%d+,%d+,') f:close() -os.remove('hello-404.h') -- clean up +os.remove('hello-411.h') -- clean up -cmd = lua .. " -j flush hello-404.lua" +cmd = lua .. " -j flush hello-411.lua" f = io.popen(cmd) -is(f:read'*l', 'Hello World', "-j flush") +equals(f:read'*l', 'Hello World', "-j flush") f:close() -cmd = lua .. " -joff hello-404.lua" +cmd = lua .. " -joff hello-411.lua" f = io.popen(cmd) -is(f:read'*l', 'Hello World', "-joff") +equals(f:read'*l', 'Hello World', "-joff") f:close() -cmd = lua .. " -jon hello-404.lua 2>&1" +cmd = lua .. " -jon hello-411.lua 2>&1" f = io.popen(cmd) if compiled_with_jit then - is(f:read'*l', 'Hello World', "-jon") + equals(f:read'*l', 'Hello World', "-jon") else - like(f:read'*l', "^[^:]+: JIT compiler permanently disabled by build option", "no jit") + matches(f:read'*l', "^[^:]+: JIT compiler permanently disabled by build option", "no jit") end f:close() -cmd = lua .. " -j bad hello-404.lua 2>&1" +cmd = lua .. " -j bad hello-411.lua 2>&1" f = io.popen(cmd) -like(f:read'*l', "^[^:]+: unknown luaJIT command or jit%.%* modules not installed", "-j bad") +matches(f:read'*l', "^[^:]+: unknown luaJIT command or jit%.%* modules not installed", "-j bad") f:close() if compiled_with_jit then - cmd = lua .. " -O hello-404.lua" + cmd = lua .. " -O hello-411.lua" f = io.popen(cmd) - is(f:read'*l', 'Hello World', "-O") + equals(f:read'*l', 'Hello World', "-O") f:close() - cmd = lua .. " -O3 hello-404.lua" + cmd = lua .. " -O3 hello-411.lua" f = io.popen(cmd) - is(f:read'*l', 'Hello World', "-O3") + equals(f:read'*l', 'Hello World', "-O3") f:close() - cmd = lua .. " -Ocse -O-dce -Ohotloop=10 hello-404.lua" + cmd = lua .. " -Ocse -O-dce -Ohotloop=10 hello-411.lua" f = io.popen(cmd) - is(f:read'*l', 'Hello World', "-Ocse -O-dce -Ohotloop=10") + equals(f:read'*l', 'Hello World', "-Ocse -O-dce -Ohotloop=10") f:close() - cmd = lua .. " -O+cse,-dce,hotloop=10 hello-404.lua" + cmd = lua .. " -O+cse,-dce,hotloop=10 hello-411.lua" f = io.popen(cmd) - is(f:read'*l', 'Hello World', "-O+cse,-dce,hotloop=10") + equals(f:read'*l', 'Hello World', "-O+cse,-dce,hotloop=10") f:close() - cmd = lua .. " -O+bad hello-404.lua 2>&1" + cmd = lua .. " -O+bad hello-411.lua 2>&1" f = io.popen(cmd) - like(f:read'*l', "^[^:]+: unknown or malformed optimization flag '%+bad'", "-O+bad") + matches(f:read'*l', "^[^:]+: unknown or malformed optimization flag '%+bad'", "-O+bad") f:close() else - cmd = lua .. " -O0 hello-404.lua 2>&1" + cmd = lua .. " -O0 hello-411.lua 2>&1" f = io.popen(cmd) - like(f:read'*l', "^[^:]+: attempt to index a nil value") + matches(f:read'*l', "^[^:]+: attempt to index a nil value") f:close() end -os.remove('hello-404.lua') -- clean up +os.remove('hello-411.lua') -- clean up done_testing() diff --git a/test/lua-Harness-tests/lexico52/lexico.t b/test/lua-Harness-tests/lexico52/lexico.t index ff6bb99e..df6610ed 100644 --- a/test/lua-Harness-tests/lexico52/lexico.t +++ b/test/lua-Harness-tests/lexico52/lexico.t @@ -1,40 +1,40 @@ -- -- lua-Harness : -- --- Copyright (C) 2012-2018, Perrad Francois +-- Copyright (C) 2012-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. -- -is("\x41", "A") -is("\x3d", "=") -is("\x3D", "=") +equals("\x41", "A") +equals("\x3d", "=") +equals("\x3D", "=") do local f, msg = load [[a = "A\xyz"]] - like(msg, "^[^:]+:%d+: .- near") + matches(msg, "^[^:]+:%d+: .- near") f, msg = load [[a = "A\Z"]] - like(msg, "^[^:]+:%d+: .- escape .- near") + matches(msg, "^[^:]+:%d+: .- escape .- near") end do local a = 'alo\n123"' - is("alo\n\z + equals("alo\n\z 123\"", a) local f, msg = load [[a = " escape \z unauthorized new line" ]] - like(msg, "^[^:]+:%d+: unfinished string near") + matches(msg, "^[^:]+:%d+: unfinished string near") end -is(0x0.1E, 0x1E / 0x100) -- 0.1171875 -is(0xA23p-4, 0xA23 / (2^4)) -- 162.1875 +equals(0x0.1E, 0x1E / 0x100) -- 0.1171875 +equals(0xA23p-4, 0xA23 / (2^4)) -- 162.1875 if string.pack and #string.pack('n', 0) == 4 then diag('Small Lua') else - is(0X1.921FB54442D18P+1, (1 + 0x921FB54442D18/0x10000000000000) * 2) + equals(0X1.921FB54442D18P+1, (1 + 0x921FB54442D18/0x10000000000000) * 2) end -- Local Variables: diff --git a/test/lua-Harness-tests/lexico53/boolean.t b/test/lua-Harness-tests/lexico53/boolean.t index 693ac767..09dc96d4 100644 --- a/test/lua-Harness-tests/lexico53/boolean.t +++ b/test/lua-Harness-tests/lexico53/boolean.t @@ -1,39 +1,39 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. -- -error_like(function () return ~true end, - "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", - "~true") +error_matches(function () return ~true end, + "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", + "~true") -error_like(function () return true // 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", - "true // 3") +error_matches(function () return true // 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on a boolean value", + "true // 3") -error_like(function () return true & 7 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", - "true & 7") +error_matches(function () return true & 7 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", + "true & 7") -error_like(function () return true | 1 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", - "true | 1") +error_matches(function () return true | 1 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", + "true | 1") -error_like(function () return true ~ 4 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", - "true ~ 4") +error_matches(function () return true ~ 4 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", + "true ~ 4") -error_like(function () return true >> 5 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", - "true >> 5") +error_matches(function () return true >> 5 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", + "true >> 5") -error_like(function () return true << 2 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", - "true << 2") +error_matches(function () return true << 2 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", + "true << 2") -- Local Variables: -- mode: lua diff --git a/test/lua-Harness-tests/lexico53/function.t b/test/lua-Harness-tests/lexico53/function.t index 2471be6e..ab48c118 100644 --- a/test/lua-Harness-tests/lexico53/function.t +++ b/test/lua-Harness-tests/lexico53/function.t @@ -1,7 +1,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2019, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -9,54 +9,54 @@ local f = function () return 1 end -error_like(function () return ~f end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "~f") +error_matches(function () return ~f end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "~f") -error_like(function () f = print; return ~f end, - "^[^:]+:%d+: attempt to perform bitwise operation on") +error_matches(function () f = print; return ~f end, + "^[^:]+:%d+: attempt to perform bitwise operation on") -error_like(function () return f // 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "f // 3") +error_matches(function () return f // 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "f // 3") -error_like(function () f = print; return f // 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on") +error_matches(function () f = print; return f // 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on") -error_like(function () return f & 7 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "f & 7") +error_matches(function () return f & 7 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "f & 7") -error_like(function () f = print; return f & 7 end, - "^[^:]+:%d+: attempt to perform bitwise operation on") +error_matches(function () f = print; return f & 7 end, + "^[^:]+:%d+: attempt to perform bitwise operation on") -error_like(function () return f | 1 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "f | 1") +error_matches(function () return f | 1 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "f | 1") -error_like(function () f = print; return f | 1 end, - "^[^:]+:%d+: attempt to perform bitwise operation on") +error_matches(function () f = print; return f | 1 end, + "^[^:]+:%d+: attempt to perform bitwise operation on") -error_like(function () return f ~ 4 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "f ~ 4") +error_matches(function () return f ~ 4 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "f ~ 4") -error_like(function () f = print; return f ~ 4 end, - "^[^:]+:%d+: attempt to perform bitwise operation on") +error_matches(function () f = print; return f ~ 4 end, + "^[^:]+:%d+: attempt to perform bitwise operation on") -error_like(function () return f >> 5 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "f >> 5") +error_matches(function () return f >> 5 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "f >> 5") -error_like(function () f = print; return f >> 5 end, - "^[^:]+:%d+: attempt to perform bitwise operation on") +error_matches(function () f = print; return f >> 5 end, + "^[^:]+:%d+: attempt to perform bitwise operation on") -error_like(function () return f << 2 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "f << 2") +error_matches(function () return f << 2 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "f << 2") -error_like(function () f = print; return f << 2 end, - "^[^:]+:%d+: attempt to perform bitwise operation on") +error_matches(function () f = print; return f << 2 end, + "^[^:]+:%d+: attempt to perform bitwise operation on") -- Local Variables: -- mode: lua diff --git a/test/lua-Harness-tests/lexico53/lexico.t b/test/lua-Harness-tests/lexico53/lexico.t index 41b0d897..03be2f96 100644 --- a/test/lua-Harness-tests/lexico53/lexico.t +++ b/test/lua-Harness-tests/lexico53/lexico.t @@ -1,25 +1,25 @@ -- -- lua-Harness : -- --- Copyright (C) 2015-2018, Perrad Francois +-- Copyright (C) 2015-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. -- -is("\u{41}", "A") -is("\u{20AC}", "\xE2\x82\xAC") -is("\u{20ac}", "\xe2\x82\xac") +equals("\u{41}", "A") +equals("\u{20AC}", "\xE2\x82\xAC") +equals("\u{20ac}", "\xe2\x82\xac") do local f, msg = load [[a = "A\u{yz}"]] - like(msg, "^[^:]+:%d+: .- near") + matches(msg, "^[^:]+:%d+: .- near") f, msg = load [[a = "A\u{41"]] - like(msg, "^[^:]+:%d+: .- near") + matches(msg, "^[^:]+:%d+: .- near") f, msg = load [[a = "A\u{FFFFFFFFFF}"]] - like(msg, "^[^:]+:%d+: .- near") + matches(msg, "^[^:]+:%d+: .- near") end -- Local Variables: diff --git a/test/lua-Harness-tests/lexico53/nil.t b/test/lua-Harness-tests/lexico53/nil.t index a6438e20..e665cce4 100644 --- a/test/lua-Harness-tests/lexico53/nil.t +++ b/test/lua-Harness-tests/lexico53/nil.t @@ -1,39 +1,39 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. -- -error_like(function () return ~nil end, - "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", - "~nil") +error_matches(function () return ~nil end, + "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", + "~nil") -error_like(function () return nil // 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on a nil value", - "nil // 3") +error_matches(function () return nil // 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on a nil value", + "nil // 3") -error_like(function () return nil & 7 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", - "nil & 7") +error_matches(function () return nil & 7 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", + "nil & 7") -error_like(function () return nil | 1 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", - "nil | 1") +error_matches(function () return nil | 1 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", + "nil | 1") -error_like(function () return nil ~ 4 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", - "nil ~ 4") +error_matches(function () return nil ~ 4 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", + "nil ~ 4") -error_like(function () return nil >> 5 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", - "nil >> 5") +error_matches(function () return nil >> 5 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", + "nil >> 5") -error_like(function () return nil << 2 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", - "nil << 2") +error_matches(function () return nil << 2 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a nil value", + "nil << 2") -- Local Variables: -- mode: lua diff --git a/test/lua-Harness-tests/lexico53/number.t b/test/lua-Harness-tests/lexico53/number.t index d205da3b..b0e1acb2 100644 --- a/test/lua-Harness-tests/lexico53/number.t +++ b/test/lua-Harness-tests/lexico53/number.t @@ -1,7 +1,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2019, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -9,169 +9,169 @@ local profile = require'profile' -is(~4, -5, "~4") +equals(~4, -5, "~4") -error_like(function () return ~3.14 end, - "^[^:]+:%d+: number has no integer representation", - "~3.14") +error_matches(function () return ~3.14 end, + "^[^:]+:%d+: number has no integer representation", + "~3.14") -is(25.5 // 3.5, 7.0, "25.5 // 3.5") +equals(25.5 // 3.5, 7.0, "25.5 // 3.5") -is(25 // 3, 8, "25 // 3") +equals(25 // 3, 8, "25 // 3") -is(25 // -3, -9, "25 // -3") +equals(25 // -3, -9, "25 // -3") -is(1 // -1, -1, "1 // -1") +equals(1 // -1, -1, "1 // -1") -type_ok(1.0 // 0, 'number', "1.0 // 0") +is_number(1.0 // 0, "1.0 // 0") -error_like(function () return 1 // 0 end, - "^[^:]+:%d+: attempt to divide by zero", - "1 // 0") +error_matches(function () return 1 // 0 end, + "^[^:]+:%d+: attempt to divide by zero", + "1 // 0") -is(3 & 7, 3, "3 & 7") +equals(3 & 7, 3, "3 & 7") -is(4 | 1, 5, "4 | 1") +equals(4 | 1, 5, "4 | 1") -is(7 ~ 1, 6, "7 ~ 1") +equals(7 ~ 1, 6, "7 ~ 1") -is(100 >> 5, 3, "100 >> 5") +equals(100 >> 5, 3, "100 >> 5") -is(3 << 2, 12, "3 << 2") +equals(3 << 2, 12, "3 << 2") -error_like(function () return 25 // {} end, - "^[^:]+:%d+: attempt to perform arithmetic on a table value", - "25 // {}") +error_matches(function () return 25 // {} end, + "^[^:]+:%d+: attempt to perform arithmetic on a table value", + "25 // {}") -error_like(function () return 3 & true end, - "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", - "3 & true") +error_matches(function () return 3 & true end, + "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", + "3 & true") -error_like(function () return 4 | true end, - "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", - "4 | true") +error_matches(function () return 4 | true end, + "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", + "4 | true") -error_like(function () return 7 ~ true end, - "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", - "7 ~ true") +error_matches(function () return 7 ~ true end, + "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", + "7 ~ true") -error_like(function () return 100 >> true end, - "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", - "100 >> true") +error_matches(function () return 100 >> true end, + "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", + "100 >> true") -error_like(function () return 3 << true end, - "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", - "3 << true") +error_matches(function () return 3 << true end, + "^[^:]+:%d+: attempt to perform bitwise operation on a boolean value", + "3 << true") -error_like(function () return 25 // 'text' end, - "^[^:]+:%d+: attempt to", - "25 // 'text'") +error_matches(function () return 25 // 'text' end, + "^[^:]+:%d+: attempt to", + "25 // 'text'") -error_like(function () return 3 & 'text' end, - "^[^:]+:%d+: attempt to", - "3 & 'text'") +error_matches(function () return 3 & 'text' end, + "^[^:]+:%d+: attempt to", + "3 & 'text'") -error_like(function () return 4 | 'text' end, - "^[^:]+:%d+: attempt to", - "4 | 'text'") +error_matches(function () return 4 | 'text' end, + "^[^:]+:%d+: attempt to", + "4 | 'text'") -error_like(function () return 7 ~ 'text' end, - "^[^:]+:%d+: attempt to", - "7 ~ 'text'") +error_matches(function () return 7 ~ 'text' end, + "^[^:]+:%d+: attempt to", + "7 ~ 'text'") -error_like(function () return 100 >> 'text' end, - "^[^:]+:%d+: attempt to", - "100 >> 'text'") +error_matches(function () return 100 >> 'text' end, + "^[^:]+:%d+: attempt to", + "100 >> 'text'") -error_like(function () return 3 << 'text' end, - "^[^:]+:%d+: attempt to", - "3 << 'text'") +error_matches(function () return 3 << 'text' end, + "^[^:]+:%d+: attempt to", + "3 << 'text'") if profile.nocvts2n then - error_like(function () return 25.5 // '3.5' end, - "^[^:]+:%d+: attempt to", - "25.5 // '3.5'") + error_matches(function () return 25.5 // '3.5' end, + "^[^:]+:%d+: attempt to", + "25.5 // '3.5'") - error_like(function () return 25 // '3' end, - "^[^:]+:%d+: attempt to", - "25 // '3'") + error_matches(function () return 25 // '3' end, + "^[^:]+:%d+: attempt to", + "25 // '3'") else - is(25.5 // '3.5', 7.0, "25.5 // '3.5'") + equals(25.5 // '3.5', 7.0, "25.5 // '3.5'") - is(25 // '3', 8, "25 // '3'") + equals(25 // '3', 8, "25 // '3'") end if profile.nocvts2n or _VERSION >= 'Lua 5.4' then - error_like(function () return 3 & '7' end, - "^[^:]+:%d+: attempt to", - "3 & '7'") + error_matches(function () return 3 & '7' end, + "^[^:]+:%d+: attempt to", + "3 & '7'") - error_like(function () return 4 | '1' end, - "^[^:]+:%d+: attempt to", - "4 | '1'") + error_matches(function () return 4 | '1' end, + "^[^:]+:%d+: attempt to", + "4 | '1'") - error_like(function () return 7 ~ '1' end, - "^[^:]+:%d+: attempt to", - "7 ~ '1'") + error_matches(function () return 7 ~ '1' end, + "^[^:]+:%d+: attempt to", + "7 ~ '1'") - error_like(function () return 100 >> '5' end, - "^[^:]+:%d+: attempt to", - "100 >> '5'") + error_matches(function () return 100 >> '5' end, + "^[^:]+:%d+: attempt to", + "100 >> '5'") - error_like(function () return 3 << '2' end, - "^[^:]+:%d+: attempt to", - "3 << '2'") + error_matches(function () return 3 << '2' end, + "^[^:]+:%d+: attempt to", + "3 << '2'") else - is(3 & '7', 3, "3 & '7'") + equals(3 & '7', 3, "3 & '7'") - is(4 | '1', 5, "4 | '1'") + equals(4 | '1', 5, "4 | '1'") - is(7 ~ '1', 6, "7 ~ '1'") + equals(7 ~ '1', 6, "7 ~ '1'") - is(100 >> '5', 3, "100 >> '5'") + equals(100 >> '5', 3, "100 >> '5'") - is(3 << '2', 12, "3 << '2'") + equals(3 << '2', 12, "3 << '2'") end -error_like(function () return 3.5 & 7 end, - "^[^:]+:%d+: number has no integer representation", - "3.5 & 7") +error_matches(function () return 3.5 & 7 end, + "^[^:]+:%d+: number has no integer representation", + "3.5 & 7") -error_like(function () return 3 & 7.5 end, - "^[^:]+:%d+: number has no integer representation", - "3 & 7.5") +error_matches(function () return 3 & 7.5 end, + "^[^:]+:%d+: number has no integer representation", + "3 & 7.5") -error_like(function () return 4.5 | 1 end, - "^[^:]+:%d+: number has no integer representation", - "4.5 | 1") +error_matches(function () return 4.5 | 1 end, + "^[^:]+:%d+: number has no integer representation", + "4.5 | 1") -error_like(function () return 4 | 1.5 end, - "^[^:]+:%d+: number has no integer representation", - "4 | 1.5") +error_matches(function () return 4 | 1.5 end, + "^[^:]+:%d+: number has no integer representation", + "4 | 1.5") -error_like(function () return 7.5 ~ 1 end, - "^[^:]+:%d+: number has no integer representation", - "7.5 ~ 1") +error_matches(function () return 7.5 ~ 1 end, + "^[^:]+:%d+: number has no integer representation", + "7.5 ~ 1") -error_like(function () return 7 ~ 1.5 end, - "^[^:]+:%d+: number has no integer representation", - "7 ~ 1.5") +error_matches(function () return 7 ~ 1.5 end, + "^[^:]+:%d+: number has no integer representation", + "7 ~ 1.5") -error_like(function () return 100.5 >> 5 end, - "^[^:]+:%d+: number has no integer representation", - "100.5 >> 5") +error_matches(function () return 100.5 >> 5 end, + "^[^:]+:%d+: number has no integer representation", + "100.5 >> 5") -error_like(function () return 100 >> 5.5 end, - "^[^:]+:%d+: number has no integer representation", - "100 >> 5.5") +error_matches(function () return 100 >> 5.5 end, + "^[^:]+:%d+: number has no integer representation", + "100 >> 5.5") -error_like(function () return 3.5 << 2 end, - "^[^:]+:%d+: number has no integer representation", - "3.5 << 2") +error_matches(function () return 3.5 << 2 end, + "^[^:]+:%d+: number has no integer representation", + "3.5 << 2") -error_like(function () return 3 << 2.5 end, - "^[^:]+:%d+: number has no integer representation", - "3 << 2.5") +error_matches(function () return 3 << 2.5 end, + "^[^:]+:%d+: number has no integer representation", + "3 << 2.5") -- Local Variables: -- mode: lua diff --git a/test/lua-Harness-tests/lexico53/string.t b/test/lua-Harness-tests/lexico53/string.t index eb74064b..de0140c7 100644 --- a/test/lua-Harness-tests/lexico53/string.t +++ b/test/lua-Harness-tests/lexico53/string.t @@ -1,7 +1,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2019, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -10,155 +10,155 @@ local profile = require'profile' if profile.nocvts2n or _VERSION >= 'Lua 5.4' then - error_like(function () return ~'4' end, + error_matches(function () return ~'4' end, "^[^:]+:%d+: attempt to", "~'4'") else - is(~'4', -5, "~'4'") + equals(~'4', -5, "~'4'") end -error_like(function () return ~'text' end, - "^[^:]+:%d+: attempt to", - "~'text'") +error_matches(function () return ~'text' end, + "^[^:]+:%d+: attempt to", + "~'text'") if profile.nocvts2n then - error_like(function () return '25.5' // 3.5 end, - "^[^:]+:%d+: attempt to", - "'25.5' // 3.5") + error_matches(function () return '25.5' // 3.5 end, + "^[^:]+:%d+: attempt to", + "'25.5' // 3.5") - error_like(function () return '25' // 3 end, - "^[^:]+:%d+: attempt to", - "'25' // 3") + error_matches(function () return '25' // 3 end, + "^[^:]+:%d+: attempt to", + "'25' // 3") else - is('25.5' // 3.5, 7.0, "'25.5' // 3.5") + equals('25.5' // 3.5, 7.0, "'25.5' // 3.5") - is('25' // 3, 8, "'25' // 3") + equals('25' // 3, 8, "'25' // 3") end if profile.nocvts2n or _VERSION >= 'Lua 5.4' then - error_like(function () return '3' & 7 end, - "^[^:]+:%d+: attempt to", - "'3' & 7") + error_matches(function () return '3' & 7 end, + "^[^:]+:%d+: attempt to", + "'3' & 7") - error_like(function () return '4' | 1 end, - "^[^:]+:%d+: attempt to", - "'4' | 1") + error_matches(function () return '4' | 1 end, + "^[^:]+:%d+: attempt to", + "'4' | 1") - error_like(function () return '7' ~ 1 end, - "^[^:]+:%d+: attempt to", - "'7' ~ 1") + error_matches(function () return '7' ~ 1 end, + "^[^:]+:%d+: attempt to", + "'7' ~ 1") - error_like(function () return '100' >> 5 end, - "^[^:]+:%d+: attempt to", - "'100' >> 5") + error_matches(function () return '100' >> 5 end, + "^[^:]+:%d+: attempt to", + "'100' >> 5") - error_like(function () return '3' << 2 end, - "^[^:]+:%d+: attempt to", - "'3' << 2") + error_matches(function () return '3' << 2 end, + "^[^:]+:%d+: attempt to", + "'3' << 2") else - is('3' & 7, 3, "'3' & 7") + equals('3' & 7, 3, "'3' & 7") - is('4' | 1, 5, "'4' | 1") + equals('4' | 1, 5, "'4' | 1") - is('7' ~ 1, 6, "'7' ~ 1") + equals('7' ~ 1, 6, "'7' ~ 1") - is('100' >> 5, 3, "'100' >> 5") + equals('100' >> 5, 3, "'100' >> 5") - is('3' << 2, 12, "'3' << 2") + equals('3' << 2, 12, "'3' << 2") end -error_like(function () return '25' // {} end, - "^[^:]+:%d+: attempt to", - "'25' // {}") +error_matches(function () return '25' // {} end, + "^[^:]+:%d+: attempt to", + "'25' // {}") -error_like(function () return '3' & true end, - "^[^:]+:%d+: attempt to", - "'3' & true") +error_matches(function () return '3' & true end, + "^[^:]+:%d+: attempt to", + "'3' & true") -error_like(function () return '4' | true end, - "^[^:]+:%d+: attempt to", - "'4' | true") +error_matches(function () return '4' | true end, + "^[^:]+:%d+: attempt to", + "'4' | true") -error_like(function () return '7' ~ true end, - "^[^:]+:%d+: attempt to", - "'7' ~ true") +error_matches(function () return '7' ~ true end, + "^[^:]+:%d+: attempt to", + "'7' ~ true") -error_like(function () return '100' >> true end, - "^[^:]+:%d+: attempt to", - "'100' >> true") +error_matches(function () return '100' >> true end, + "^[^:]+:%d+: attempt to", + "'100' >> true") -error_like(function () return '3' << true end, - "^[^:]+:%d+: attempt to", - "'3' << true") +error_matches(function () return '3' << true end, + "^[^:]+:%d+: attempt to", + "'3' << true") -error_like(function () return '25' // 'text' end, - "^[^:]+:%d+: attempt to", - "'25' // 'text'") +error_matches(function () return '25' // 'text' end, + "^[^:]+:%d+: attempt to", + "'25' // 'text'") -error_like(function () return '3' & 'text' end, - "^[^:]+:%d+: attempt to", - "'3' & 'text'") +error_matches(function () return '3' & 'text' end, + "^[^:]+:%d+: attempt to", + "'3' & 'text'") -error_like(function () return '4' | 'text' end, - "^[^:]+:%d+: attempt to", - "'4' | 'text'") +error_matches(function () return '4' | 'text' end, + "^[^:]+:%d+: attempt to", + "'4' | 'text'") -error_like(function () return '7' ~ 'text' end, - "^[^:]+:%d+: attempt to", - "'7' ~ 'text'") +error_matches(function () return '7' ~ 'text' end, + "^[^:]+:%d+: attempt to", + "'7' ~ 'text'") -error_like(function () return '100' >> 'text' end, - "^[^:]+:%d+: attempt to", - "'100' >> 'text'") +error_matches(function () return '100' >> 'text' end, + "^[^:]+:%d+: attempt to", + "'100' >> 'text'") -error_like(function () return '3' << 'text' end, - "^[^:]+:%d+: attempt to", - "'3' << 'text'") +error_matches(function () return '3' << 'text' end, + "^[^:]+:%d+: attempt to", + "'3' << 'text'") if profile.nocvts2n then - error_like(function () return '25.5' // '3.5' end, - "^[^:]+:%d+: attempt to", - "'25.5' // '3.5'") + error_matches(function () return '25.5' // '3.5' end, + "^[^:]+:%d+: attempt to", + "'25.5' // '3.5'") - error_like(function () return '25' // '3' end, - "^[^:]+:%d+: attempt to", - "'25' // '3'") + error_matches(function () return '25' // '3' end, + "^[^:]+:%d+: attempt to", + "'25' // '3'") else - is('25.5' // '3.5', 7.0, "'25.5' // '3.5'") + equals('25.5' // '3.5', 7.0, "'25.5' // '3.5'") - is('25' // '3', 8, "'25' // '3'") + equals('25' // '3', 8, "'25' // '3'") end if profile.nocvts2n or _VERSION >= 'Lua 5.4' then - error_like(function () return '3' & '7' end, - "^[^:]+:%d+: attempt to", - "'3' & '7'") + error_matches(function () return '3' & '7' end, + "^[^:]+:%d+: attempt to", + "'3' & '7'") - error_like(function () return '4' | '1' end, - "^[^:]+:%d+: attempt to", - "'4' | '1'") + error_matches(function () return '4' | '1' end, + "^[^:]+:%d+: attempt to", + "'4' | '1'") - error_like(function () return '7' ~ '1' end, - "^[^:]+:%d+: attempt to", - "'7' ~ '1'") + error_matches(function () return '7' ~ '1' end, + "^[^:]+:%d+: attempt to", + "'7' ~ '1'") - error_like(function () return '100' >> '5' end, - "^[^:]+:%d+: attempt to", - "'100' >> '5'") + error_matches(function () return '100' >> '5' end, + "^[^:]+:%d+: attempt to", + "'100' >> '5'") - error_like(function () return '3' << '2' end, - "^[^:]+:%d+: attempt to", - "'3' << '2'") + error_matches(function () return '3' << '2' end, + "^[^:]+:%d+: attempt to", + "'3' << '2'") else - is('3' & '7', 3, "'3' & '7'") + equals('3' & '7', 3, "'3' & '7'") - is('4' | '1', 5, "'4' | '1'") + equals('4' | '1', 5, "'4' | '1'") - is('7' ~ '1', 6, "'7' ~ '1'") + equals('7' ~ '1', 6, "'7' ~ '1'") - is('100' >> '5', 3, "'100' >> '5'") + equals('100' >> '5', 3, "'100' >> '5'") - is('3' << '2', 12, "'3' << 2") + equals('3' << '2', 12, "'3' << 2") end -- Local Variables: diff --git a/test/lua-Harness-tests/lexico53/table.t b/test/lua-Harness-tests/lexico53/table.t index 007232d5..f5a5d82c 100644 --- a/test/lua-Harness-tests/lexico53/table.t +++ b/test/lua-Harness-tests/lexico53/table.t @@ -1,39 +1,39 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2018, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. -- -error_like(function () return ~{} end, - "^[^:]+:%d+: attempt to perform bitwise operation on a table value", - "~{}") +error_matches(function () return ~{} end, + "^[^:]+:%d+: attempt to perform bitwise operation on a table value", + "~{}") -error_like(function () return {} // 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "{} // 3") +error_matches(function () return {} // 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "{} // 3") -error_like(function () return {} & 7 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a table value", - "{} & 7") +error_matches(function () return {} & 7 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a table value", + "{} & 7") -error_like(function () return {} | 1 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a table value", - "{} | 1") +error_matches(function () return {} | 1 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a table value", + "{} | 1") -error_like(function () return {} ~ 4 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a table value", - "{} ~ 4") +error_matches(function () return {} ~ 4 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a table value", + "{} ~ 4") -error_like(function () return {} >> 5 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a table value", - "{} >> 5") +error_matches(function () return {} >> 5 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a table value", + "{} >> 5") -error_like(function () return {} << 2 end, - "^[^:]+:%d+: attempt to perform bitwise operation on a table value", - "{} << 2") +error_matches(function () return {} << 2 end, + "^[^:]+:%d+: attempt to perform bitwise operation on a table value", + "{} << 2") -- Local Variables: -- mode: lua diff --git a/test/lua-Harness-tests/lexico53/thread.t b/test/lua-Harness-tests/lexico53/thread.t index ef9e57b3..c49de20a 100644 --- a/test/lua-Harness-tests/lexico53/thread.t +++ b/test/lua-Harness-tests/lexico53/thread.t @@ -1,7 +1,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2019, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -9,33 +9,33 @@ local co = coroutine.create(function () return 1 end) -error_like(function () return ~co end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "~co") +error_matches(function () return ~co end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "~co") -error_like(function () return co // 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "co // 3") +error_matches(function () return co // 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "co // 3") -error_like(function () return co & 7 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "co & 7") +error_matches(function () return co & 7 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "co & 7") -error_like(function () return co | 1 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "co | 1") +error_matches(function () return co | 1 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "co | 1") -error_like(function () return co ~ 4 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "co ~ 4") +error_matches(function () return co ~ 4 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "co ~ 4") -error_like(function () return co >> 5 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "co >> 5") +error_matches(function () return co >> 5 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "co >> 5") -error_like(function () return co << 2 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "co << 2") +error_matches(function () return co << 2 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "co << 2") -- Local Variables: -- mode: lua diff --git a/test/lua-Harness-tests/lexico53/userdata.t b/test/lua-Harness-tests/lexico53/userdata.t index 06b96f91..f01febf6 100644 --- a/test/lua-Harness-tests/lexico53/userdata.t +++ b/test/lua-Harness-tests/lexico53/userdata.t @@ -1,7 +1,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2009-2019, Perrad Francois +-- Copyright (C) 2009-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -9,33 +9,33 @@ local u = io.stdin -error_like(function () return ~u end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "~u") +error_matches(function () return ~u end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "~u") -error_like(function () return u // 3 end, - "^[^:]+:%d+: attempt to perform arithmetic on", - "u // 3") +error_matches(function () return u // 3 end, + "^[^:]+:%d+: attempt to perform arithmetic on", + "u // 3") -error_like(function () return u & 7 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "u & 7") +error_matches(function () return u & 7 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "u & 7") -error_like(function () return u | 1 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "u | 1") +error_matches(function () return u | 1 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "u | 1") -error_like(function () return u ~ 4 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "u ~ 4") +error_matches(function () return u ~ 4 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "u ~ 4") -error_like(function () return u >> 5 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "u >> 5") +error_matches(function () return u >> 5 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "u >> 5") -error_like(function () return u << 2 end, - "^[^:]+:%d+: attempt to perform bitwise operation on", - "u << 2") +error_matches(function () return u << 2 end, + "^[^:]+:%d+: attempt to perform bitwise operation on", + "u << 2") -- Local Variables: -- mode: lua diff --git a/test/lua-Harness-tests/lexico53/utf8.t b/test/lua-Harness-tests/lexico53/utf8.t index 87d3f6dd..1458fe86 100644 --- a/test/lua-Harness-tests/lexico53/utf8.t +++ b/test/lua-Harness-tests/lexico53/utf8.t @@ -1,7 +1,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2014-2020, Perrad Francois +-- Copyright (C) 2014-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -11,44 +11,44 @@ local has_char54 = _VERSION >= 'Lua 5.4' local has_charpattern54 = _VERSION >= 'Lua 5.4' do -- char - is(utf8.char(65, 66, 67), 'ABC', "function char") - is(utf8.char(0x20AC), '\u{20AC}') - is(utf8.char(), '') - - is(utf8.char(0):len(), 1) - is(utf8.char(0x7F):len(), 1) - is(utf8.char(0x80):len(), 2) - is(utf8.char(0x7FF):len(), 2) - is(utf8.char(0x800):len(), 3) - is(utf8.char(0xFFFF):len(), 3) - is(utf8.char(0x10000):len(), 4) - is(utf8.char(0x10FFFF):len(), 4) + equals(utf8.char(65, 66, 67), 'ABC', "function char") + equals(utf8.char(0x20AC), '\u{20AC}') + equals(utf8.char(), '') + + equals(utf8.char(0):len(), 1) + equals(utf8.char(0x7F):len(), 1) + equals(utf8.char(0x80):len(), 2) + equals(utf8.char(0x7FF):len(), 2) + equals(utf8.char(0x800):len(), 3) + equals(utf8.char(0xFFFF):len(), 3) + equals(utf8.char(0x10000):len(), 4) + equals(utf8.char(0x10FFFF):len(), 4) if has_char54 then - is(utf8.char(0x1FFFFF):len(), 4) - is(utf8.char(0x200000):len(), 5) - is(utf8.char(0x3FFFFFF):len(), 5) - is(utf8.char(0x4000000):len(), 6) - is(utf8.char(0x7FFFFFFF):len(), 6) + equals(utf8.char(0x1FFFFF):len(), 4) + equals(utf8.char(0x200000):len(), 5) + equals(utf8.char(0x3FFFFFF):len(), 5) + equals(utf8.char(0x4000000):len(), 6) + equals(utf8.char(0x7FFFFFFF):len(), 6) else - error_like(function () utf8.char(0x110000) end, - "^[^:]+:%d+: bad argument #1 to 'char' %(value out of ", - "function char (out of range)") + error_matches(function () utf8.char(0x110000) end, + "^[^:]+:%d+: bad argument #1 to 'char' %(value out of ", + "function char (out of range)") end - error_like(function () utf8.char(0, -1) end, - "^[^:]+:%d+: bad argument #2 to 'char' %(value out of ", - "function char (out of range)") + error_matches(function () utf8.char(0, -1) end, + "^[^:]+:%d+: bad argument #2 to 'char' %(value out of ", + "function char (out of range)") - error_like(function () utf8.char(0, 'bad') end, - "^[^:]+:%d+: bad argument #2 to 'char' %(number expected, got string%)", - "function char (bad)") + error_matches(function () utf8.char(0, 'bad') end, + "^[^:]+:%d+: bad argument #2 to 'char' %(number expected, got string%)", + "function char (bad)") end do -- charpattern if has_charpattern54 then - is(utf8.charpattern, "[\0-\x7F\xC2-\xFD][\x80-\xBF]*", "charpattern") + equals(utf8.charpattern, "[\0-\x7F\xC2-\xFD][\x80-\xBF]*", "charpattern") else - is(utf8.charpattern, "[\0-\x7F\xC2-\xF4][\x80-\xBF]*", "charpattern") + equals(utf8.charpattern, "[\0-\x7F\xC2-\xF4][\x80-\xBF]*", "charpattern") end end @@ -59,116 +59,116 @@ do -- codes ap[#ap+1] = p ac[#ac+1] = c end - eq_array(ap, {1, 2, 5}, "function codes") - eq_array(ac, {0x41, 0x20AC, 0x33}) + array_equals(ap, {1, 2, 5}, "function codes") + array_equals(ac, {0x41, 0x20AC, 0x33}) local empty = true for p, c in utf8.codes('') do empty = false end - ok(empty, "codes (empty)") + truthy(empty, "codes (empty)") - error_like(function () utf8.codes() end, - "^[^:]+:%d+: bad argument #1 to 'codes' %(string expected, got no value%)", - "function codes ()") + error_matches(function () utf8.codes() end, + "^[^:]+:%d+: bad argument #1 to 'codes' %(string expected, got no value%)", + "function codes ()") - error_like(function () utf8.codes(true) end, - "^[^:]+:%d+: bad argument #1 to 'codes' %(string expected, got boolean%)", - "function codes (true)") + error_matches(function () utf8.codes(true) end, + "^[^:]+:%d+: bad argument #1 to 'codes' %(string expected, got boolean%)", + "function codes (true)") - error_like(function () for p, c in utf8.codes('invalid\xFF') do end end, - "^[^:]+:%d+: invalid UTF%-8 code", - "function codes (invalid)") + error_matches(function () for p, c in utf8.codes('invalid\xFF') do end end, + "^[^:]+:%d+: invalid UTF%-8 code", + "function codes (invalid)") end do -- codepoints - is(utf8.codepoint("A\u{20AC}3"), 0x41, "function codepoint") - is(utf8.codepoint("A\u{20AC}3", 2), 0x20AC) - is(utf8.codepoint("A\u{20AC}3", -1), 0x33) - is(utf8.codepoint("A\u{20AC}3", 5), 0x33) - eq_array({utf8.codepoint("A\u{20AC}3", 1, 5)}, {0x41, 0x20AC, 0x33}) - eq_array({utf8.codepoint("A\u{20AC}3", 1, 4)}, {0x41, 0x20AC}) - - error_like(function () utf8.codepoint("A\u{20AC}3", 6) end, - "^[^:]+:%d+: bad argument #3 to 'codepoint' %(out of ", - "function codepoint (out of range)") - - error_like(function () utf8.codepoint("A\u{20AC}3", 8) end, - "^[^:]+:%d+: bad argument #3 to 'codepoint' %(out of ", - "function codepoint (out of range)") - - error_like(function () utf8.codepoint("invalid\xFF", 8) end, - "^[^:]+:%d+: invalid UTF%-8 code", - "function codepoint (invalid)") + equals(utf8.codepoint("A\u{20AC}3"), 0x41, "function codepoint") + equals(utf8.codepoint("A\u{20AC}3", 2), 0x20AC) + equals(utf8.codepoint("A\u{20AC}3", -1), 0x33) + equals(utf8.codepoint("A\u{20AC}3", 5), 0x33) + array_equals({utf8.codepoint("A\u{20AC}3", 1, 5)}, {0x41, 0x20AC, 0x33}) + array_equals({utf8.codepoint("A\u{20AC}3", 1, 4)}, {0x41, 0x20AC}) + + error_matches(function () utf8.codepoint("A\u{20AC}3", 6) end, + "^[^:]+:%d+: bad argument #3 to 'codepoint' %(out of ", + "function codepoint (out of range)") + + error_matches(function () utf8.codepoint("A\u{20AC}3", 8) end, + "^[^:]+:%d+: bad argument #3 to 'codepoint' %(out of ", + "function codepoint (out of range)") + + error_matches(function () utf8.codepoint("invalid\xFF", 8) end, + "^[^:]+:%d+: invalid UTF%-8 code", + "function codepoint (invalid)") end do -- len - is(utf8.len('A'), 1, "function len") - is(utf8.len(''), 0) - is(utf8.len("\u{41}\u{42}\u{43}"), 3) - is(utf8.len("A\u{20AC}3"), 3) - - is(utf8.len('A', 1), 1) - is(utf8.len('A', 2), 0) - is(utf8.len('ABC', 1, 1), 1) - is(utf8.len('ABC', 2, 2), 1) - is(utf8.len('ABC', -1), 1) - is(utf8.len('ABC', -2), 2) - - error_like(function () utf8.len('A', 3) end, - "^[^:]+:%d+: bad argument #2 to 'len' %(initial position out of ", - "function len (out of range)") + equals(utf8.len('A'), 1, "function len") + equals(utf8.len(''), 0) + equals(utf8.len("\u{41}\u{42}\u{43}"), 3) + equals(utf8.len("A\u{20AC}3"), 3) + + equals(utf8.len('A', 1), 1) + equals(utf8.len('A', 2), 0) + equals(utf8.len('ABC', 1, 1), 1) + equals(utf8.len('ABC', 2, 2), 1) + equals(utf8.len('ABC', -1), 1) + equals(utf8.len('ABC', -2), 2) + + error_matches(function () utf8.len('A', 3) end, + "^[^:]+:%d+: bad argument #2 to 'len' %(initial position out of ", + "function len (out of range)") local len, pos = utf8.len('invalid\xFF') - is(len, nil, "function len (invalid)") - is(pos, 8) + equals(len, nil, "function len (invalid)") + equals(pos, 8) end do -- offset - is(utf8.offset("A\u{20AC}3", 1), 1, "function offset") - is(utf8.offset("A\u{20AC}3", 2), 2) - is(utf8.offset("A\u{20AC}3", 3), 5) - is(utf8.offset("A\u{20AC}3", 4), 6) - is(utf8.offset("A\u{20AC}3", 5), nil) - is(utf8.offset("A\u{20AC}3", 6), nil) - is(utf8.offset("A\u{20AC}3", -1), 5) - is(utf8.offset("A\u{20AC}3", 1, 2), 2) - is(utf8.offset("A\u{20AC}3", 2, 2), 5) - is(utf8.offset("A\u{20AC}3", 3, 2), 6) - is(utf8.offset("A\u{20AC}3", 4, 2), nil) - is(utf8.offset("A\u{20AC}3", -1, 2), 1) - is(utf8.offset("A\u{20AC}3", -2, 2), nil) - is(utf8.offset("A\u{20AC}3", 1, 5), 5) - is(utf8.offset("A\u{20AC}3", 2, 5), 6) - is(utf8.offset("A\u{20AC}3", 3, 5), nil) - is(utf8.offset("A\u{20AC}3", -1, 5), 2) - is(utf8.offset("A\u{20AC}3", -2, 5), 1) - is(utf8.offset("A\u{20AC}3", -3, 5), nil) - is(utf8.offset("A\u{20AC}3", 1, 6), 6) - is(utf8.offset("A\u{20AC}3", 2, 6), nil) - is(utf8.offset("A\u{20AC}3", 1, -1), 5) - is(utf8.offset("A\u{20AC}3", -1, -1), 2) - is(utf8.offset("A\u{20AC}3", -2, -1), 1) - is(utf8.offset("A\u{20AC}3", -3, -1), nil) - is(utf8.offset("A\u{20AC}3", 1, -4), 2) - is(utf8.offset("A\u{20AC}3", 2, -4), 5) - is(utf8.offset("A\u{20AC}3", -1, -4), 1) - is(utf8.offset("A\u{20AC}3", -2, -4), nil) - - is(utf8.offset("A\u{20AC}3", 0, 1), 1) - is(utf8.offset("A\u{20AC}3", 0, 2), 2) - is(utf8.offset("A\u{20AC}3", 0, 3), 2) - is(utf8.offset("A\u{20AC}3", 0, 4), 2) - is(utf8.offset("A\u{20AC}3", 0, 5), 5) - is(utf8.offset("A\u{20AC}3", 0, 6), 6) - - error_like(function () utf8.offset("A\u{20AC}3", 1, 7) end, - "^[^:]+:%d+: bad argument #3 to 'offset' %(position out of ", - "function offset (out of range)") - - error_like(function () utf8.offset("\x80", 1) end, - "^[^:]+:%d+: initial position is a continuation byte", - "function offset (continuation byte)") + equals(utf8.offset("A\u{20AC}3", 1), 1, "function offset") + equals(utf8.offset("A\u{20AC}3", 2), 2) + equals(utf8.offset("A\u{20AC}3", 3), 5) + equals(utf8.offset("A\u{20AC}3", 4), 6) + equals(utf8.offset("A\u{20AC}3", 5), nil) + equals(utf8.offset("A\u{20AC}3", 6), nil) + equals(utf8.offset("A\u{20AC}3", -1), 5) + equals(utf8.offset("A\u{20AC}3", 1, 2), 2) + equals(utf8.offset("A\u{20AC}3", 2, 2), 5) + equals(utf8.offset("A\u{20AC}3", 3, 2), 6) + equals(utf8.offset("A\u{20AC}3", 4, 2), nil) + equals(utf8.offset("A\u{20AC}3", -1, 2), 1) + equals(utf8.offset("A\u{20AC}3", -2, 2), nil) + equals(utf8.offset("A\u{20AC}3", 1, 5), 5) + equals(utf8.offset("A\u{20AC}3", 2, 5), 6) + equals(utf8.offset("A\u{20AC}3", 3, 5), nil) + equals(utf8.offset("A\u{20AC}3", -1, 5), 2) + equals(utf8.offset("A\u{20AC}3", -2, 5), 1) + equals(utf8.offset("A\u{20AC}3", -3, 5), nil) + equals(utf8.offset("A\u{20AC}3", 1, 6), 6) + equals(utf8.offset("A\u{20AC}3", 2, 6), nil) + equals(utf8.offset("A\u{20AC}3", 1, -1), 5) + equals(utf8.offset("A\u{20AC}3", -1, -1), 2) + equals(utf8.offset("A\u{20AC}3", -2, -1), 1) + equals(utf8.offset("A\u{20AC}3", -3, -1), nil) + equals(utf8.offset("A\u{20AC}3", 1, -4), 2) + equals(utf8.offset("A\u{20AC}3", 2, -4), 5) + equals(utf8.offset("A\u{20AC}3", -1, -4), 1) + equals(utf8.offset("A\u{20AC}3", -2, -4), nil) + + equals(utf8.offset("A\u{20AC}3", 0, 1), 1) + equals(utf8.offset("A\u{20AC}3", 0, 2), 2) + equals(utf8.offset("A\u{20AC}3", 0, 3), 2) + equals(utf8.offset("A\u{20AC}3", 0, 4), 2) + equals(utf8.offset("A\u{20AC}3", 0, 5), 5) + equals(utf8.offset("A\u{20AC}3", 0, 6), 6) + + error_matches(function () utf8.offset("A\u{20AC}3", 1, 7) end, + "^[^:]+:%d+: bad argument #3 to 'offset' %(position out of ", + "function offset (out of range)") + + error_matches(function () utf8.offset("\x80", 1) end, + "^[^:]+:%d+: initial position is a continuation byte", + "function offset (continuation byte)") end -- Local Variables: diff --git a/test/lua-Harness-tests/lexico54/lexico.t b/test/lua-Harness-tests/lexico54/lexico.t index 4523a51a..af14e71c 100644 --- a/test/lua-Harness-tests/lexico54/lexico.t +++ b/test/lua-Harness-tests/lexico54/lexico.t @@ -1,15 +1,15 @@ -- -- lua-Harness : -- --- Copyright (C) 2019, Perrad Francois +-- Copyright (C) 2019-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. -- -is("\u{10000}", "\xF0\x90\x80\x80") -is("\u{200000}", "\xF8\x88\x80\x80\x80") -is("\u{4000000}", "\xFC\x84\x80\x80\x80\x80") +equals("\u{10000}", "\xF0\x90\x80\x80") +equals("\u{200000}", "\xF8\x88\x80\x80\x80") +equals("\u{4000000}", "\xFC\x84\x80\x80\x80\x80") -- Local Variables: -- mode: lua diff --git a/test/lua-Harness-tests/lexico54/metatable.t b/test/lua-Harness-tests/lexico54/metatable.t index 4685b341..32878b3d 100644 --- a/test/lua-Harness-tests/lexico54/metatable.t +++ b/test/lua-Harness-tests/lexico54/metatable.t @@ -1,7 +1,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2019-2020, Perrad Francois +-- Copyright (C) 2019-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -11,15 +11,15 @@ do -- toclose local called = false do local foo = setmetatable({}, { __close = function () called = true end }) - type_ok(foo, 'table', "toclose") - is(called, false) + is_table(foo, "toclose") + is_false(called) end - is(called, true) + is_true(called) - error_like(function () do local foo = {} end end, - "^[^:]+:%d+: variable 'foo' got a non%-closable value") + error_matches(function () do local foo = {} end end, + "^[^:]+:%d+: variable 'foo' got a non%-closable value") - lives_ok(function () + not_errors(function () local var1 = nil local var2 = nil do diff --git a/test/lua-Harness-tests/lexico54/utf8.t b/test/lua-Harness-tests/lexico54/utf8.t index 1aa70cc6..a3dfddc2 100644 --- a/test/lua-Harness-tests/lexico54/utf8.t +++ b/test/lua-Harness-tests/lexico54/utf8.t @@ -1,7 +1,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2019, Perrad Francois +-- Copyright (C) 2019-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -14,36 +14,36 @@ do -- codes ap[#ap+1] = p ac[#ac+1] = c end - eq_array(ap, {1, 2, 7}, "function codes lax") - eq_array(ac, {0x41, 0x200000, 0x33}) + array_equals(ap, {1, 2, 7}, "function codes lax") + array_equals(ac, {0x41, 0x200000, 0x33}) - error_like(function () for _ in utf8.codes("A\u{200000}3", false) do end end, - "^[^:]+:%d+: invalid UTF%-8 code") + error_matches(function () for _ in utf8.codes("A\u{200000}3", false) do end end, + "^[^:]+:%d+: invalid UTF%-8 code") - error_like(function () for _ in utf8.codes("A\u{200000}3") do end end, - "^[^:]+:%d+: invalid UTF%-8 code") + error_matches(function () for _ in utf8.codes("A\u{200000}3") do end end, + "^[^:]+:%d+: invalid UTF%-8 code") end do -- codepoints - eq_array({utf8.codepoint("A\u{200000}3", 1, 7, true)}, {0x41, 0x200000, 0x33}, "function codepoint lax") + array_equals({utf8.codepoint("A\u{200000}3", 1, 7, true)}, {0x41, 0x200000, 0x33}, "function codepoint lax") - error_like(function () utf8.codepoint("A\u{200000}3", 1, 7, false) end, - "^[^:]+:%d+: invalid UTF%-8 code") + error_matches(function () utf8.codepoint("A\u{200000}3", 1, 7, false) end, + "^[^:]+:%d+: invalid UTF%-8 code") - error_like(function () utf8.codepoint("A\u{200000}3", 1, 7) end, - "^[^:]+:%d+: invalid UTF%-8 code") + error_matches(function () utf8.codepoint("A\u{200000}3", 1, 7) end, + "^[^:]+:%d+: invalid UTF%-8 code") end do -- len - is(utf8.len('A\u{200000}C', 1, -1, true), 3, "function len lax") + equals(utf8.len('A\u{200000}C', 1, -1, true), 3, "function len lax") local len, pos = utf8.len('A\u{200000}C') - is(len, nil) - is(pos, 2) + equals(len, nil) + equals(pos, 2) len, pos = utf8.len('A\u{200000}C', 1, -1, false) - is(len, nil) - is(pos, 2) + equals(len, nil) + equals(pos, 2) end -- Local Variables: diff --git a/test/lua-Harness-tests/lexicojit/basic.t b/test/lua-Harness-tests/lexicojit/basic.t index 8ad3a59b..2925e06f 100644 --- a/test/lua-Harness-tests/lexicojit/basic.t +++ b/test/lua-Harness-tests/lexicojit/basic.t @@ -1,22 +1,22 @@ -- -- lua-Harness : -- --- Copyright (C) 2018, Perrad Francois +-- Copyright (C) 2018-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. -- do -- tonumber - is(tonumber(42uLL), 42, "function tonumber (cdata)") - is(tonumber(42LL), 42) + equals(tonumber(42uLL), 42, "function tonumber (cdata)") + equals(tonumber(42LL), 42) end do -- tostring - is(tostring(42uLL), '42ULL', "function tostring (cdata)") - is(tostring(42LL), '42LL') - is(tostring(1i), '0+1i') - is(tostring(12.5i), '0+12.5i') + equals(tostring(42uLL), '42ULL', "function tostring (cdata)") + equals(tostring(42LL), '42LL') + equals(tostring(1i), '0+1i') + equals(tostring(12.5i), '0+12.5i') end -- Local Variables: diff --git a/test/lua-Harness-tests/lexicojit/ext.t b/test/lua-Harness-tests/lexicojit/ext.t index 8c44b99b..d044e2bb 100644 --- a/test/lua-Harness-tests/lexicojit/ext.t +++ b/test/lua-Harness-tests/lexicojit/ext.t @@ -1,7 +1,7 @@ -- -- lua-Harness : -- --- Copyright (C) 2019-2020, Perrad Francois +-- Copyright (C) 2019-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. @@ -11,37 +11,37 @@ local profile = require'profile' do -- thread.exdata local r, exdata = pcall(require, 'thread.exdata') - is(r, true, 'thread.exdata') - type_ok(exdata, 'function') - is(package.loaded['thread.exdata'], exdata) + is_true(r, 'thread.exdata') + is_function(exdata) + equals(package.loaded['thread.exdata'], exdata) local ffi = require'ffi' local u64 = ffi.new('uintptr_t', 0xefdeaddeadbeefLL) local ptr = ffi.cast('void *', u64) exdata(u64) -- set - is(exdata(), ptr) -- get + equals(exdata(), ptr) -- get - error_like(function () exdata(42) end, - "^[^:]+:%d+: bad argument #1 to 'exdata' %(cdata expected, got number%)") + error_matches(function () exdata(42) end, + "^[^:]+:%d+: bad argument #1 to 'exdata' %(cdata expected, got number%)") end -- thread.exdata2 if profile.openresty then local r, exdata2 = pcall(require, 'thread.exdata2') - is(r, true, 'thread.exdata2') - type_ok(exdata2, 'function') - is(package.loaded['thread.exdata2'], exdata2) + is_true(r, 'thread.exdata2') + is_function(exdata2) + equals(package.loaded['thread.exdata2'], exdata2) local ffi = require'ffi' local u64 = ffi.new('uintptr_t', 0xefdeaddeadbeefLL) local ptr = ffi.cast('void *', u64) exdata2(u64) -- set - is(exdata2(), ptr) -- get + equals(exdata2(), ptr) -- get - error_like(function () exdata2(42) end, + error_matches(function () exdata2(42) end, "^[^:]+:%d+: bad argument #1 to 'exdata2' %(cdata expected, got number%)") else - is(pcall(require, 'thread.exdata2'), false, 'no thread.exdata2') + is_false(pcall(require, 'thread.exdata2'), 'no thread.exdata2') end -- Local Variables: diff --git a/test/lua-Harness-tests/lexicojit/lexico.t b/test/lua-Harness-tests/lexicojit/lexico.t index 1a973b5b..72992907 100644 --- a/test/lua-Harness-tests/lexicojit/lexico.t +++ b/test/lua-Harness-tests/lexicojit/lexico.t @@ -1,28 +1,28 @@ -- -- lua-Harness : -- --- Copyright (C) 2018, Perrad Francois +-- Copyright (C) 2018-2021, Perrad Francois -- -- This code is licensed under the terms of the MIT/X11 license, -- like Lua itself. -- -type_ok(42LL, 'cdata', "42LL") -type_ok(42ULL, 'cdata', "42ULL") -type_ok(42uLL, 'cdata', "42uLL") -type_ok(42ull, 'cdata', "42ull") +is_cdata(42LL, "42LL") +is_cdata(42ULL, "42ULL") +is_cdata(42uLL, "42uLL") +is_cdata(42ull, "42ull") -type_ok(0x2aLL, 'cdata', "0x2aLL") -type_ok(0x2aULL, 'cdata', "0x2aULL") -type_ok(0x2auLL, 'cdata', "0x2auLL") -type_ok(0x2aull, 'cdata', "0x2aull") +is_cdata(0x2aLL, "0x2aLL") +is_cdata(0x2aULL, "0x2aULL") +is_cdata(0x2auLL, "0x2auLL") +is_cdata(0x2aull, "0x2aull") -type_ok(12.5i, 'cdata', '12.5i') -type_ok(12.5I, 'cdata', '12.5I') -type_ok(1i, 'cdata', '1i') -type_ok(1I, 'cdata', '1I') -type_ok(0i, 'cdata', '0i') -type_ok(0I, 'cdata', '0I') +is_cdata(12.5i, '12.5i') +is_cdata(12.5I, '12.5I') +is_cdata(1i, '1i') +is_cdata(1I, '1I') +is_cdata(0i, '0i') +is_cdata(0I, '0I') -- Local Variables: -- mode: lua diff --git a/test/lua-Harness-tests/tap.lua b/test/lua-Harness-tests/tap.lua index a8454ae0..f50cc319 100644 --- a/test/lua-Harness-tests/tap.lua +++ b/test/lua-Harness-tests/tap.lua @@ -9,8 +9,8 @@ ]] -if pcall(require, 'Test.More') then - diag 'Test.More loaded' +if pcall(require, 'Test.Assertion') then + diag 'Test.Assertion loaded' return end @@ -46,7 +46,7 @@ function skip_all (reason) os.exit(0) end -function ok (test, name) +function truthy (test, name) curr_test = curr_test + 1 local out = '' if not test then @@ -62,69 +62,93 @@ function ok (test, name) print(out) end -function nok (test, name) - ok(not test, name) +function falsy (test, name) + truthy(not test, name) end -function is (got, expected, name) +function equals (got, expected, name) local pass = got == expected - ok(pass, name) + truthy(pass, name) if not pass then diag(" got: " .. tostring(got)) diag(" expected: " .. tostring(expected)) end end -function isnt (got, not_expected, name) +function not_equals (got, not_expected, name) local pass = got ~= not_expected - ok(pass, name) + truthy(pass, name) if not pass then diag(" got: " .. tostring(got)) diag(" expected: anything else") end end -function like (got, pattern, name) +function matches (got, pattern, name) local pass = tostring(got):match(pattern) - ok(pass, name) + truthy(pass, name) if not pass then diag(" " .. tostring(got)) diag(" doesn't match '" .. tostring(pattern) .. "'") end end -function type_ok (val, t, name) - if type(val) == t then - ok(true, name) - else - ok(false, name) - diag(" " .. tostring(val) .. " isn't a '" .. t .."' it's '" .. type(val) .. "'") +local function is_type (t) + return function (val, name) + if type(val) == t then + truthy(true, name) + else + truthy(false, name) + diag(" " .. tostring(val) .. " isn't a '" .. t .."' it's a '" .. type(val) .. "'") + end + end +end +is_boolean = is_type('boolean') +is_cdata = is_type('cdata') +is_function = is_type('function') +is_number = is_type('number') +is_string = is_type('string') +is_table = is_type('table') +is_thread = is_type('thread') +is_userdata = is_type('userdata') + +local function is_value (expected) + return function (got, name) + local pass = got == expected + truthy(pass, name) + if not pass then + diag(" got: " .. tostring(got)) + diag(" expected: " .. tostring(expected)) + end end end +is_nil = is_value(nil) +is_true = is_value(true) +is_false = is_value(false) -function pass (name) - ok(true, name) +function passes (name) + truthy(true, name) end -function fail (name) - ok(false, name) +function fails (name) + truthy(false, name) end function require_ok (mod) local r, msg = pcall(require, mod) - ok(r, "require '" .. mod .. "'") + truthy(r, "require '" .. mod .. "'") if not r then diag(" " .. msg) end return r end -function eq_array (got, expected, name) +function array_equals (got, expected, name) for i = 1, #expected do local v = expected[i] local val = got[i] if val ~= v then - ok(false, name) + truthy(false, name) diag(" at index: " .. tostring(i)) diag(" got: " .. tostring(val)) diag(" expected: " .. tostring(v)) @@ -133,38 +157,38 @@ function eq_array (got, expected, name) end local extra = #got - #expected if extra ~= 0 then - ok(false, name) + truthy(false, name) diag(" " .. tostring(extra) .. " unexpected item(s)") else - ok(true, name) + truthy(true, name) end end -function error_is (code, expected, name) +function error_equals (code, expected, name) local r, msg = pcall(code) if r then - ok(false, name) + truthy(false, name) diag(" unexpected success") diag(" expected: " .. tostring(pattern)) else - is(msg, expected, name) + equals(msg, expected, name) end end -function error_like (code, pattern, name) +function error_matches (code, pattern, name) local r, msg = pcall(code) if r then - ok(false, name) + truthy(false, name) diag(" unexpected success") diag(" expected: " .. tostring(pattern)) else - like(msg, pattern, name) + matches(msg, pattern, name) end end -function lives_ok (code, name) +function not_errors (code, name) local r, msg = pcall(code) - ok(r, name) + truthy(r, name) if not r then diag(" " .. msg) end @@ -181,7 +205,7 @@ function skip (reason, count) name = name .. " " ..reason end for i = 1, count do - ok(true, name) + truthy(true, name) end end @@ -214,7 +238,7 @@ function make_specific_checks (filename) end -- --- Copyright (c) 2009-2018 Francois Perrad +-- Copyright (c) 2009-2021 Francois Perrad -- -- This library is licensed under the terms of the MIT/X11 license, -- like Lua itself. -- 2.32.0