diff -Nru lua-unit-3.2/.appveyor/install-lua.cmd lua-unit-3.3/.appveyor/install-lua.cmd --- lua-unit-3.2/.appveyor/install-lua.cmd 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/.appveyor/install-lua.cmd 2018-04-20 12:34:12.000000000 +0000 @@ -4,58 +4,92 @@ REM version numbers and file names for binaries from http://sf.net/p/luabinaries/ set VER_51=5.1.5 set VER_52=5.2.4 -set VER_53=5.3.2 +set VER_53=5.3.3 set ZIP_51=lua-%VER_51%_Win32_bin.zip set ZIP_52=lua-%VER_52%_Win32_bin.zip set ZIP_53=lua-%VER_53%_Win32_bin.zip :cinst +@echo off if NOT "%LUAENV%"=="cinst" goto lua51 echo Chocolatey install of Lua ... -@echo on -cinst lua +if NOT EXIST "C:\Program Files (x86)\Lua\5.1\lua.exe" ( + @echo on + cinst lua +) else ( + @echo on + echo Using cached version of Lua +) set LUA="C:\Program Files (x86)\Lua\5.1\lua.exe" @echo off goto :EOF :lua51 +@echo off if NOT "%LUAENV%"=="lua51" goto lua52 echo Setting up Lua 5.1 ... -@echo on -curl -fLsS -o %ZIP_51% http://sourceforge.net/projects/luabinaries/files/%VER_51%/Tools%%20Executables/%ZIP_51%/download -unzip %ZIP_51% -set LUA=lua5.1.exe +if NOT EXIST "lua51\lua5.1.exe" ( + @echo on + echo Fetching Lua v5.1 from internet + curl -fLsS -o %ZIP_51% http://sourceforge.net/projects/luabinaries/files/%VER_51%/Tools%%20Executables/%ZIP_51%/download + unzip -d lua51 %ZIP_51% +) else ( + echo Using cached version of Lua v5.1 +) +set LUA=lua51\lua5.1.exe @echo off goto :EOF :lua52 +@echo off if NOT "%LUAENV%"=="lua52" goto lua53 echo Setting up Lua 5.2 ... +if NOT EXIST "lua52\lua52.exe" ( + @echo on + echo Fetching Lua v5.2 from internet + curl -fLsS -o %ZIP_52% http://sourceforge.net/projects/luabinaries/files/%VER_52%/Tools%%20Executables/%ZIP_52%/download + unzip -d lua52 %ZIP_52% +) else ( + echo Using cached version of Lua v5.2 +) @echo on -curl -fLsS -o %ZIP_52% http://sourceforge.net/projects/luabinaries/files/%VER_52%/Tools%%20Executables/%ZIP_52%/download -unzip %ZIP_52% -set LUA=lua52.exe +set LUA=lua52\lua52.exe @echo off goto :EOF :lua53 +@echo off if NOT "%LUAENV%"=="lua53" goto luajit echo Setting up Lua 5.3 ... +if NOT EXIST "lua53\lua53.exe" ( + @echo on + echo Fetching Lua v5.3 from internet + curl -fLsS -o %ZIP_53% http://sourceforge.net/projects/luabinaries/files/%VER_53%/Tools%%20Executables/%ZIP_53%/download + unzip -d lua53 %ZIP_53% +) else ( + echo Using cached version of Lua v5.3 +) @echo on -curl -fLsS -o %ZIP_53% http://sourceforge.net/projects/luabinaries/files/%VER_53%/Tools%%20Executables/%ZIP_53%/download -unzip %ZIP_53% -set LUA=lua53.exe +set LUA=lua53\lua53.exe @echo off goto :EOF :luajit if NOT "%LUAENV%"=="luajit20" goto luajit21 echo Setting up LuaJIT 2.0 ... -call %~dp0install-luajit.cmd LuaJIT-2.0.4 -set LUA=luajit.exe +if NOT EXIST "luajit20\luajit.exe" ( + call %~dp0install-luajit.cmd LuaJIT-2.0.4 luajit20 +) else ( + echo Using cached version of LuaJIT 2.0 +) +set LUA=luajit20\luajit.exe goto :EOF :luajit21 echo Setting up LuaJIT 2.1 ... -call %~dp0install-luajit.cmd LuaJIT-2.1.0-beta2 -set LUA=luajit.exe +if NOT EXIST "luajit21\luajit.exe" ( + call %~dp0install-luajit.cmd LuaJIT-2.1.0-beta2 luajit21 +) else ( + echo Using cached version of LuaJIT 2.1 +) +set LUA=luajit21\luajit.exe diff -Nru lua-unit-3.2/.appveyor/install-luajit.cmd lua-unit-3.3/.appveyor/install-luajit.cmd --- lua-unit-3.2/.appveyor/install-luajit.cmd 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/.appveyor/install-luajit.cmd 2018-04-20 12:34:12.000000000 +0000 @@ -2,6 +2,8 @@ set PATH=C:\MinGW\bin;%PATH% +set targetdir=%2 + REM retrieve and unpack source curl -fLsS -o %1.zip http://luajit.org/download/%1.zip unzip -q %1 @@ -12,7 +14,8 @@ mingw32-make TARGET_SYS=Windows -C %1\src REM copy luajit.exe to project dir -copy %1\src\luajit.exe %APPVEYOR_BUILD_FOLDER% +mkdir %APPVEYOR_BUILD_FOLDER%\%targetdir% +copy %1\src\luajit.exe %APPVEYOR_BUILD_FOLDER%\%targetdir%\ REM clean up (remove source folders and archive) rm -rf %1/* diff -Nru lua-unit-3.2/appveyor.yml lua-unit-3.3/appveyor.yml --- lua-unit-3.2/appveyor.yml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/appveyor.yml 2018-04-20 12:34:12.000000000 +0000 @@ -1,29 +1,37 @@ -os: MinGW -shallow_clone: true - -# create a build matrix to use various Lua and LuaJIT versions -environment: - matrix: - - LUAENV: cinst - - LUAENV: lua51 - - LUAENV: lua52 - - LUAENV: lua53 - - LUAENV: luajit20 - - LUAENV: luajit21 - -# cinst occasionally has problems, allow it to fail -matrix: - allow_failures: - - LUAENV: cinst - -# install required binaries via batch file (also sets %LUA% path) -install: -- cmd: .appveyor\install-lua.cmd - -build: off - -test_script: -- cmd: >- - %LUA% -v run_unit_tests.lua - - %LUA% run_functional_tests.lua +os: MinGW +shallow_clone: true + +# create a build matrix to use various Lua and LuaJIT versions +environment: + matrix: + - LUAENV: lua51 + - LUAENV: lua52 + - LUAENV: lua53 + - LUAENV: luajit20 + - LUAENV: luajit21 + - LUAENV: cinst + +# cinst occasionally has problems, allow it to fail +matrix: + allow_failures: + - LUAENV: cinst + +# install required binaries via batch file (also sets %LUA% path) +install: +- cmd: .appveyor\install-lua.cmd + +cache: + - lua51 -> .appveyor\install-lua.cmd + - lua52 -> .appveyor\install-lua.cmd + - lua53 -> .appveyor\install-lua.cmd + - luajit20 -> .appveyor\install-lua.cmd + - luajit21 -> .appveyor\install-lua.cmd + - 'C:\Program Files (x86)\Lua -> .appveyor\install-lua.cmd' + +build: off + +test_script: +- cmd: >- + %LUA% -v run_unit_tests.lua --shuffle + + %LUA% run_functional_tests.lua diff -Nru lua-unit-3.2/debian/changelog lua-unit-3.3/debian/changelog --- lua-unit-3.2/debian/changelog 2016-11-21 14:10:33.000000000 +0000 +++ lua-unit-3.3/debian/changelog 2018-06-21 11:51:58.000000000 +0000 @@ -1,3 +1,18 @@ +lua-unit (3.3-1) unstable; urgency=medium + + * update d/gdb.conf + * New upstream version 3.3 + * debhelper compat 10 + * add support for lua5.3 + * update Vcs-* due migration to salsa + * update Standards-Version to 4.1.4 (no changes needed) + * fix build-depends-on-python-sphinx-only + * rules: clean doc/_build + * tests: use --shuffle + * add patches to fix build + + -- Victor Seva Thu, 21 Jun 2018 13:51:58 +0200 + lua-unit (3.2-1) unstable; urgency=medium * [4b747d1] filter upstream doc/html @@ -33,8 +48,8 @@ lua-unit (1.5+gita58da93-2) unstable; urgency=low - * Just build lua-unit and put in it the two available examples - * Fix typo in copyright + * Just build lua-unit and put in it the two available examples + * Fix typo in copyright -- Enrico Tassi Tue, 02 Jul 2013 11:26:16 +0200 diff -Nru lua-unit-3.2/debian/compat lua-unit-3.3/debian/compat --- lua-unit-3.2/debian/compat 2016-11-21 14:10:33.000000000 +0000 +++ lua-unit-3.3/debian/compat 2018-06-21 11:51:58.000000000 +0000 @@ -1 +1 @@ -9 +10 diff -Nru lua-unit-3.2/debian/control lua-unit-3.3/debian/control --- lua-unit-3.2/debian/control 2016-11-21 14:10:33.000000000 +0000 +++ lua-unit-3.3/debian/control 2018-06-21 11:51:58.000000000 +0000 @@ -5,13 +5,13 @@ Uploaders: Enrico Tassi , Build-Depends: - debhelper (>= 9~), + debhelper (>= 10~), dh-lua (>= 16~), - python-sphinx, -Standards-Version: 3.9.8 -Vcs-Git: https://anonscm.debian.org/git/pkg-lua/lua-unit.git -Vcs-Browser: https://anonscm.debian.org/cgit/pkg-lua/lua-unit.git + python3-sphinx, +Standards-Version: 4.1.4 Homepage: https://github.com/bluebird75/luaunit +Vcs-Git: https://salsa.debian.org/lua-team/lua-unit.git +Vcs-Browser: https://salsa.debian.org/lua-team/lua-unit Package: lua-unit Architecture: all diff -Nru lua-unit-3.2/debian/gbp.conf lua-unit-3.3/debian/gbp.conf --- lua-unit-3.2/debian/gbp.conf 2016-11-21 14:10:33.000000000 +0000 +++ lua-unit-3.3/debian/gbp.conf 2018-06-21 11:51:58.000000000 +0000 @@ -1,8 +1,10 @@ [import-orig] -filter = [ 'doc/html' ] +filter = [ '.git', 'doc/html' ] + [dch] -id-length = 7 +id-length = 0 meta = True + [DEFAULT] debian-branch = master upstream-branch = upstream diff -Nru lua-unit-3.2/debian/lua5.1.dh-lua.conf lua-unit-3.3/debian/lua5.1.dh-lua.conf --- lua-unit-3.2/debian/lua5.1.dh-lua.conf 2016-11-21 14:10:33.000000000 +0000 +++ lua-unit-3.3/debian/lua5.1.dh-lua.conf 2018-06-21 11:51:58.000000000 +0000 @@ -2,4 +2,4 @@ LUA_SOURCES=luaunit.lua LUA_MODNAME=luaunit -LUA_TEST_CUSTOM=@@LUA@@ run_unit_tests.lua +LUA_TEST_CUSTOM=@@LUA@@ run_unit_tests.lua --shuffle diff -Nru lua-unit-3.2/debian/lua5.2.dh-lua.conf lua-unit-3.3/debian/lua5.2.dh-lua.conf --- lua-unit-3.2/debian/lua5.2.dh-lua.conf 2016-11-21 14:10:33.000000000 +0000 +++ lua-unit-3.3/debian/lua5.2.dh-lua.conf 2018-06-21 11:51:58.000000000 +0000 @@ -2,4 +2,4 @@ LUA_SOURCES=luaunit.lua LUA_MODNAME=luaunit -LUA_TEST_CUSTOM=@@LUA@@ run_unit_tests.lua +LUA_TEST_CUSTOM=@@LUA@@ run_unit_tests.lua --shuffle diff -Nru lua-unit-3.2/debian/lua5.3.dh-lua.conf lua-unit-3.3/debian/lua5.3.dh-lua.conf --- lua-unit-3.2/debian/lua5.3.dh-lua.conf 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/debian/lua5.3.dh-lua.conf 2018-06-21 11:51:58.000000000 +0000 @@ -0,0 +1,5 @@ +PKG_NAME=unit + +LUA_SOURCES=luaunit.lua +LUA_MODNAME=luaunit +LUA_TEST_CUSTOM=@@LUA@@ run_unit_tests.lua --shuffle diff -Nru lua-unit-3.2/debian/patches/0001-fix_doc_build.patch lua-unit-3.3/debian/patches/0001-fix_doc_build.patch --- lua-unit-3.2/debian/patches/0001-fix_doc_build.patch 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/debian/patches/0001-fix_doc_build.patch 2018-06-21 11:51:58.000000000 +0000 @@ -0,0 +1,62 @@ +From: Victor Seva +Date: Thu, 21 Jun 2018 11:38:34 +0200 +Subject: [PATCH] doc: rearrange Value assertions tables + +'NotImplementedError: Column or row spanning cells are not implemented.' +was happening when building doc as text + +fixes #111 +--- + doc/index.rst | 39 +++++++++++++++++++++++++-------------- + 1 file changed, 25 insertions(+), 14 deletions(-) + +diff --git a/doc/index.rst b/doc/index.rst +index bda5435..bd0900e 100644 +--- a/doc/index.rst ++++ b/doc/index.rst +@@ -1256,20 +1256,31 @@ that a value is anything but the boolean *true* or *false*. + + The below table sums it up: + +-============ ============ =================== ================ ============= =================== =============== +-**True assertion family** **False assertion family** +------------------------------------------------------------------ --------------------------------------------------- +-Input Value assertTrue() assertEvalToTrue() assertNotFalse() assertFalse() assertEvalToFalse() assertNotTrue() +-============ ============ =================== ================ ============= =================== =============== +-*true* OK OK OK Fail Fail Fail +-*false* Fail Fail Fail OK OK OK +-*nil* Fail Fail OK Fail OK OK +-*0* Fail OK OK Fail Fail Fail +-*1* Fail OK OK Fail Fail Fail +-*"hello"* Fail OK OK Fail Fail Fail +-============ ============ =================== ================ ============= =================== =============== +- +- ++ **True assertion family** ++ ++============ ============ =================== ================ ++Input Value assertTrue() assertEvalToTrue() assertNotTrue() ++============ ============ =================== ================ ++*true* OK OK OK ++*false* Fail Fail Fail ++*nil* Fail Fail OK ++*0* Fail OK OK ++*1* Fail OK OK ++*"hello"* Fail OK OK ++============ ============ =================== ================ ++ ++ **False assertion family** ++ ++============ ================ ============= =================== ++Input Value assertNotFalse() assertFalse() assertEvalToFalse() ++============ ================ ============= =================== ++*true* Fail Fail Fail ++*false* OK OK OK ++*nil* Fail OK OK ++*0* Fail Fail Fail ++*1* Fail Fail Fail ++*"hello"* Fail Fail Fail ++============ ================ ============= =================== + + .. function:: assertEvalToTrue(value [, extra_msg]) + diff -Nru lua-unit-3.2/debian/patches/0002-test-fix-check-output-depending-on-environment.patch lua-unit-3.3/debian/patches/0002-test-fix-check-output-depending-on-environment.patch --- lua-unit-3.2/debian/patches/0002-test-fix-check-output-depending-on-environment.patch 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/debian/patches/0002-test-fix-check-output-depending-on-environment.patch 2018-06-21 11:51:58.000000000 +0000 @@ -0,0 +1,38 @@ +From d8fd89e5a42d71476f0e9a6a5c57905dd8754e52 Mon Sep 17 00:00:00 2001 +From: Victor Seva +Date: Thu, 21 Jun 2018 12:22:57 +0200 +Subject: [PATCH] test: fix check output depending on environment + +fixes #114 +--- + test/test_luaunit.lua | 14 +------------- + 1 file changed, 1 insertion(+), 13 deletions(-) + +diff --git a/test/test_luaunit.lua b/test/test_luaunit.lua +index 54f8d94..7271ec8 100644 +--- a/test/test_luaunit.lua ++++ b/test/test_luaunit.lua +@@ -493,19 +493,7 @@ bar"=1}]] ) + local t9 = {"t9", {}} + t9[{t9}] = 1 + +- if os.getenv('TRAVIS_OS_NAME') == 'osx' then +- -- on os X, because table references are longer, the table is expanded on multiple lines. +- --[[ Output example: +- ' { +- "t9", +- {}, +- {}=1 +- }' +- ]] +- lu.assertStrMatches(lu.prettystr(t9, true), '() {\n%s+"t9",\n%s+() {},\n%s+() {%1}=1\n}') +- else +- lu.assertStrMatches(lu.prettystr(t9, true), '() {"t9", () {}, () {%1}=1}') +- end ++ lu.assertStrMatches(lu.prettystr(t9, true), '() {\n?%s*"t9",\n?%s*() {},\n?%s*() {%1}=1\n?}') + end + + function TestLuaUnitUtilities:test_prettystrPairs() +-- +2.17.1 + diff -Nru lua-unit-3.2/debian/patches/series lua-unit-3.3/debian/patches/series --- lua-unit-3.2/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/debian/patches/series 2018-06-21 11:51:58.000000000 +0000 @@ -0,0 +1,2 @@ +0001-fix_doc_build.patch +0002-test-fix-check-output-depending-on-environment.patch diff -Nru lua-unit-3.2/debian/rules lua-unit-3.3/debian/rules --- lua-unit-3.2/debian/rules 2016-11-21 14:10:33.000000000 +0000 +++ lua-unit-3.3/debian/rules 2018-06-21 11:51:58.000000000 +0000 @@ -3,6 +3,10 @@ %: dh $@ --buildsystem=lua --with lua,sphinxdoc +override_dh_auto_clean: + dh_auto_clean + rm -rf doc/_build + override_dh_auto_build: dh_auto_build PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -N -btext doc/ \ diff -Nru lua-unit-3.2/doc/conf.py lua-unit-3.3/doc/conf.py --- lua-unit-3.2/doc/conf.py 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/doc/conf.py 2018-04-20 12:34:12.000000000 +0000 @@ -1,259 +1,259 @@ -# -*- coding: utf-8 -*- -# -# LuaUnit documentation build configuration file, created by -# sphinx-quickstart on Thu Aug 21 21:45:55 2014. -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys -import os - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) - -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. -extensions = [] - -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# The suffix of source filenames. -source_suffix = '.rst' - -# The encoding of source files. -#source_encoding = 'utf-8-sig' - -# The master toctree document. -master_doc = 'index' - -# General information about the project. -project = u'LuaUnit' -copyright = u'2014, Philippe Fremy' - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The short X.Y version. -version = '1.6' -# The full version, including alpha/beta/rc tags. -release = '1.6' - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -#language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -#today = '' -# Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ['_build'] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -#default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -#add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -#show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' - -# A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False - - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = 'default' - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -#html_theme_options = {} - -# Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# " v documentation". -#html_title = None - -# A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -#html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -#html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -#html_extra_path = [] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -#html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -#html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -#html_additional_pages = {} - -# If false, no module index is generated. -#html_domain_indices = True - -# If false, no index is generated. -#html_use_index = True - -# If true, the index is split into individual pages for each letter. -#html_split_index = False - -# If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -#html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None - -# Output file base name for HTML help builder. -htmlhelp_basename = 'LuaUnitdoc' - - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', - -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', - -# Additional stuff for the LaTeX preamble. -#'preamble': '', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - ('index', 'LuaUnit.tex', u'LuaUnit Documentation', - u'Philippe Fremy', 'manual'), -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -#latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -#latex_use_parts = False - -# If true, show page references after internal links. -#latex_show_pagerefs = False - -# If true, show URL addresses after external links. -#latex_show_urls = False - -# Documents to append as an appendix to all manuals. -#latex_appendices = [] - -# If false, no module index is generated. -#latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ('index', 'luaunit', u'LuaUnit Documentation', - [u'Philippe Fremy'], 1) -] - -# If true, show URL addresses after external links. -#man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - ('index', 'LuaUnit', u'LuaUnit Documentation', - u'Philippe Fremy', 'LuaUnit', 'One line description of project.', - 'Miscellaneous'), -] - -# Documents to append as an appendix to all manuals. -#texinfo_appendices = [] - -# If false, no module index is generated. -#texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False - +# -*- coding: utf-8 -*- +# +# LuaUnit documentation build configuration file, created by +# sphinx-quickstart on Thu Aug 21 21:45:55 2014. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'LuaUnit' +copyright = u'2016, Philippe Fremy' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '3.3' +# The full version, including alpha/beta/rc tags. +release = '3.3' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'LuaUnitdoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ('index', 'LuaUnit.tex', u'LuaUnit Documentation', + u'Philippe Fremy', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'luaunit', u'LuaUnit Documentation', + [u'Philippe Fremy'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'LuaUnit', u'LuaUnit Documentation', + u'Philippe Fremy', 'LuaUnit', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False + diff -Nru lua-unit-3.2/doc/index.rst lua-unit-3.3/doc/index.rst --- lua-unit-3.2/doc/index.rst 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/doc/index.rst 2018-04-20 12:35:02.000000000 +0000 @@ -1,1300 +1,2264 @@ -.. LuaUnit documentation master file, created by - sphinx-quickstart on Thu Aug 21 21:45:55 2014. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - - -,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, -Welcome to LuaUnit's documentation! -,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, - -.. toctree:: - :maxdepth: 3 - -.. highlight:: lua - - -Introduction -************ - -LuaUnit is a unit-testing framework for Lua. It allows you -to write test functions and test classes with test methods, combined with -setup/teardown functionality. A wide range of assertions are supported. - -LuaUnit supports several output format, like Junit or TAP, for easier integration -into Continuous Integration platforms (Jenkins, Maven, ...) . The integrated command-line -options provide a flexible interface to select tests by name or patterns, control output -format, set verbosity, ... - -Platform support -================ - -LuaUnit works with Lua 5.1, LuaJIT 2.0, LuaJIT 2.1 beta, Lua 5.2 and Lua 5.3 . It is tested on Windows Seven, Windows Server 2012 R2 (x64) and Ubuntu 14.04 (see -continuous build results on `Travis-CI`_ and `AppVeyor`_ ) and should work on all platforms supported by Lua. -It has no other dependency than Lua itself. - - -.. _Travis-CI: https://travis-ci.org/bluebird75/luaunit -.. _AppVeyor: https://ci.appveyor.com/project/bluebird75/luaunit/history - -LuaUnit is packed into a single-file. To make start using it, just add the file to your project. Other installation methods are described in the `README.md`_ file. - -.. _README.md: https://github.com/bluebird75/luaunit - -LuaUnit is maintained on github: -https://github.com/bluebird75/luaunit - -It is released under the BSD license. - - -Upgrade note -================ - -**Important note when upgrading to version 3.1 and above** : there is a break of backward compatibility in version 3.1, assertions functions are no longer exported directly to the global namespace. See :ref:`luaunit-global-asserts` on how to adjust or restore previous behavior. - - -LuaUnit development -=================== - -See :ref:`developing-luaunit` - -Version and Changelog -===================== -This documentation describes the functionality of LuaUnit v3.2 . - -New in version 3.2 - 12. Jul 2016 ---------------------------------- -* Add command-line option to stop on first error or failure -* Distinguish between failures (failed assertion) and errors -* Support for new versions: Lua 5.3 and LuaJIT (2.0, 2.1 beta) -* Validation of all lua versions on Travis CI and AppVeyor -* Add compatibility layer with forked luaunit v2.x -* Added documentation about development process -* Improved support for table containing keys of type table -* Small bug fixes, several internal improvements -* Available with a Luarock package - -New in version 3.1 - 10. Mar 2015 ---------------------------------- -* luaunit no longer pollutes global namespace, unless defining EXPORT_ASSERT_TO_GLOBALS to true -* fixes and validation of JUnit XML generation -* strip luaunit internal information from stacktrace -* general improvements of test results with duration and other details -* improve printing for tables, with an option to always print table id -* fix printing of recursive tables - -**Important note when upgrading to version 3.1** : assertions functions are -no longer exported directly to the global namespace. See :ref:`luaunit-global-asserts` - -New in version 3.0 - 9. Oct 2014 --------------------------------- - -Because LuaUnit was forked and released as some 2.x version, version number -is now jumping to 3.0 . - -* full documentation available in text, html and pdf at read-the-docs.org -* new output format: JUnit, compatible with Bamboo and other CI platforms -* much better table assertions -* new assertions for strings, with patterns and case insensitivity: assertStrContains, - assertNotStrContains, assertNotStrIContains, assertStrIContains, assertStrMatches -* new assertions for floats: assertAlmostEquals, assertNotAlmostEquals -* type assertions: assertIsString, assertIsNumber, ... -* error assertions: assertErrorMsgEquals, assertErrorMsgContains, assertErrorMsgMatches -* improved error messages for several assertions -* command-line options to select test, control output type and verbosity - - -New in version 1.5 - 8. Nov 2012 --------------------------------- -* compatibility with Lua 5.1 and 5.2 -* better object model internally -* a lot more of internal tests -* several internal bug fixes -* make it easy to customize the test output -* running test functions no longer requires a wrapper -* several level of verbosity - - -New in version 1.4 - 26. Jul 2012 ---------------------------------- -* switch from X11 to more popular BSD license -* add TAP output format for integration into Jenkins -* official repository now on github - - -New in version 1.3 - 30. Oct 2007 ---------------------------------- -* port to lua 5.1 -* iterate over the test classes, methods and functions in the alphabetical order -* change the default order of expected, actual in assertEquals (adjustable with USE_EXPECTED_ACTUAL_IN_ASSERT_EQUALS). - - -Version 1.2 - 13. Jun 2005 ---------------------------------- -* first public release - - -Version 1.1 ------------- -* move global variables to internal variables -* assertion order is configurable between expected/actual or actual/expected -* new assertion to check that a function call returns an error -* display the calling stack when an error is spotted -* two verbosity level, like in python unittest - - - -Getting started -*************** - -Setting up your test script -=========================== - -To get started, create your file *test_something.lua* . - -The script should import LuaUnit:: - - luaunit = require('luaunit') - -The last line executes your script with LuaUnit and exit with the -proper error code:: - - os.exit( luaunit.LuaUnit.run() ) - -Now, run your file with:: - - lua test_something.lua - -It prints something like:: - - Ran 0 tests in 0 seconds - OK - -Now, your testing framework is in place, you can start writing tests. - -Writing tests -============= - -LuaUnit scans all variables that start with *test* or *Test*. -If they are functions, or if they are tables that contain -functions that start with *test* or *Test*, they are run as part of the test suite. - -So just write a function whose name starts with test. Inside test functions, use the assertions functions provided by LuaUnit, such -as :func:`assertEquals`. - -Let's see that in practice. - -Suppose you want to test the following add function:: - - function add(v1,v2) - -- add positive numbers - -- return 0 if any of the numbers are 0 - -- error if any of the two numbers are negative - if v1 < 0 or v2 < 0 then - error('Can only add positive or null numbers, received '..v1..' and '..v2) - end - if v1 == 0 or v2 == 0 then - return 0 - end - return v1+v2 - end - -You write the following tests:: - - function testAddPositive() - luaunit.assertEquals(add(1,1),2) - end - - function testAddZero() - luaunit.assertEquals(add(1,0),0) - luaunit.assertEquals(add(0,5),0) - luaunit.assertEquals(add(0,0),0) - end - - -:func:`assertEquals` is the most common used assertion function. It simply -verifies that both argument are equals, in the order actual value, expected value. - -Rerun your test script (-v is to activate a more verbose output) :: - - lua test_something.lua -v - -It now prints:: - - Started on 03/10/15 16:45:41 - TestAdd.testAddPositive ... Ok - TestAdd.testAddZero ... Ok - ========================================================= - Ran 2 tests in 0.010 seconds - OK - -You always have: - -* the date at which the test suite was started -* the group to which the function belongs (usually, the name of the function table, and ** for all direct test functions) -* the name of the function being executed -* a report at the end, with number of executed test, number of non selected tests, number of failures, number of errors (if any) and duration. - -The difference between failures and errors are: - -* luaunit assertion functions generate failures -* any unexpected error during execution generates an error -* failures or errors during setup() or teardown() always generate errors - - -You also want to test that when the function receives negative numbers, it generates an error. Use -:func:`assertError` or even better, :func:`assertErrorMsgContains` to also validate the content -of the error message. There are other types or error checking functions, see :ref:`assert-error` . Here -we use :func:`assertErrorMsgContains` . First argument is the expected message, then the function to call -and the optional arguments:: - - function testAddError() - luaunit.assertErrorMsgContains('Can only add positive or null numbers, received 2 and -3', add, 2, -3) - end - -Now, suppose we also have the following function to test:: - - function adder(v) - -- return a function that adds v to its argument using add - function closure( x ) return x+v end - return closure - end - -We want to test the type of the value returned by adder and its behavior. LuaUnit -provides assertion for type testing (see :ref:`assert-type`). In this case, we use -:func:`assertIsFunction`:: - - function testAdder() - f = adder(3) - luaunit.assertIsFunction( f ) - luaunit.assertEquals( f(2), 5 ) - end - -Grouping tests, setup/teardown functionality -===================================================== - -When the number of tests starts to grow, you usually organise them -into separate groups. You can do that with LuaUnit by putting them -inside a table (whose name must start with *Test* or *test* ). - -For example, assume we have a second function to test:: - - function div(v1,v2) - -- divide positive numbers - -- return 0 if any of the numbers are 0 - -- error if any of the two numbers are negative - if v1 < 0 or v2 < 0 then - error('Can only divide positive or null numbers, received '..v1..' and '..v2) - end - if v1 == 0 or v2 == 0 then - return 0 - end - return v1/v2 - end - -We move the tests related to the function add into their own table:: - - TestAdd = {} - function TestAdd:testAddPositive() - luaunit.assertEquals(add(1,1),2) - end - - function TestAdd:testAddZero() - luaunit.assertEquals(add(1,0),0) - luaunit.assertEquals(add(0,5),0) - luaunit.assertEquals(add(0,0),0) - end - - function TestAdd:testAddError() - luaunit.assertErrorMsgContains('Can only add positive or null numbers, received 2 and -3', add, 2, -3) - end - - function TestAdd:testAdder() - f = adder(3) - luaunit.assertIsFunction( f ) - luaunit.assertEquals( f(2), 5 ) - end - -- end of table TestAdd - -Then we create a second set of tests for div:: - - TestDiv = {} - function TestDiv:testDivPositive() - luaunit.assertEquals(div(4,2),2) - end - - function TestDiv:testDivZero() - luaunit.assertEquals(div(4,0),0) - luaunit.assertEquals(div(0,5),0) - luaunit.assertEquals(div(0,0),0) - end - - function TestDiv:testDivError() - luaunit.assertErrorMsgContains('Can only divide positive or null numbers, received 2 and -3', div, 2, -3) - end - -- end of table TestDiv - -Execution of the test suite now looks like this:: - - Started on 03/10/15 16:47:33 - TestAdd.testAddError ... Ok - TestAdd.testAddPositive ... Ok - TestAdd.testAddZero ... Ok - TestAdd.testAdder ... Ok - TestDiv.testDivError ... Ok - TestDiv.testDivPositive ... Ok - TestDiv.testDivZero ... Ok - ========================================================= - Ran 7 tests in 0.010 seconds - OK - - -When tests are defined in tables, you can optionally define two special -functions, *setUp()* and *tearDown()*, which will be executed -respectively before and after every test. - -These function may be used to create specific resources for the -test being executed and cleanup the test environment. - -For a practical example, imagine that we have a *log()* function -that writes strings to a log file on disk. The file is created -upon first usage of the function, and the filename is defined -by calling the function *initLog()*. - -The tests for these functions would take advantage of the *setup/teardown* -functionality to prepare a log filename shared -by all tests, make sure that all tests start with a non existing -log file name, and erase the log filename after every test:: - - TestLogger = {} - function TestLogger:setUp() - -- define the fname to use for logging - self.fname = 'mytmplog.log' - -- make sure the file does not already exists - os.remove(self.fname) - end - - function TestLogger:testLoggerCreatesFile() - initLog(self.fname) - log('toto') - -- make sure that our log file was created - f = io.open(self.fname, 'r') - luaunit.assertNotNil( f ) - f:close() - end - - function TestLogger:tearDown() - -- cleanup our log file after all tests - os.remove(self.fname) - end - -.. Note:: - - *Errors generated during execution of setUp() or tearDown() - functions are considered test failures.* - - -.. Note:: - - *For compatibility with luaunit v2 and other lua unit-test frameworks, - setUp() and tearDown() may also be named setup(), SetUp(), Setup(), teardown(), TearDown(), Teardown().* - - -Using the command-line -====================== - -You can control the LuaUnit execution from the command-line: - -**Output format** - -Choose the test output format with ``-o`` or ``--output``. Available formats are: - -* text: the default output format -* nil: no output at all -* TAP: TAP format -* junit: output junit xml - -Example of non-verbose text format:: - - $ lua doc/test_something.lua - ....... - Ran 7 tests in 0.002 seconds - OK - - -Example of TAP format:: - - $ lua doc/test_something.lua -o TAP - 1..7 - # Started on 03/10/15 16:50:09 - # Starting class: TestAdd - ok 1 TestAdd.testAddError - ok 2 TestAdd.testAddPositive - ok 3 TestAdd.testAddZero - ok 4 TestAdd.testAdder - # Starting class: TestDiv - ok 5 TestDiv.testDivError - ok 6 TestDiv.testDivPositive - ok 7 TestDiv.testDivZero - # Ran 7 tests in 0.022 seconds, 7 successes, 0 failures - - - -**List of tests to run** - -You can list some test names on the command-line to run only those tests. -The name must be the exact match of either the test table, the test function or the test table -and the test method. The option may be repeated. - -Example:: - - -- Run all TestAdd table tests and one test of TestDiv table. - $ lua doc/test_something.lua TestAdd TestDiv.testDivError -v - Started on 03/10/15 16:52:20 - TestAdd.testAddError ... Ok - TestAdd.testAddPositive ... Ok - TestAdd.testAddZero ... Ok - TestAdd.testAdder ... Ok - TestDiv.testDivError ... Ok - ========================================================= - Ran 5 tests in 0.000 seconds - OK - -**Filtering tests** - -The most flexible approach for selecting tests to run is to use a pattern. With -``--pattern`` or ``-p``, you can provide a lua pattern and only the tests that contain -the pattern will actually be run. - -Example:: - - -- Run all tests of zero testing and error testing - -- by using the magic character . - lua my_test_suite.lua -v -p Err.r -p Z.ro - -For our test suite, it gives the following output:: - - Started on 03/10/15 16:48:29 - TestAdd.testAddError ... Ok - TestAdd.testAddZero ... Ok - TestDiv.testDivError ... Ok - TestDiv.testDivZero ... Ok - ========================================================= - Ran 4 tests in 0.010 seconds - OK (ignored=3) - -The number of tests ignored by the selection is printed, along -with the test result. The pattern can be any lua pattern. Be sure to exclude all magic -characters with % (like -+?*) and protect your pattern from the shell -interpretation by putting it in quotes. - -Conclusion -========== - -You now know enough of LuaUnit to start writing your test suite. Check -the reference documentation for a complete list of -assertions, command-line options and specific behavior. - - -.. _reference-documentation: - -Reference documentation -*********************** - -.. _luaunit-global-asserts: - -Enabling global or module-level functions -========================================= - -Versions of LuaUnit before version 3.1 would export all assertions functions to the global namespace. A typical -lua test file would look like this: - -.. code-block:: lua - - require('luaunit') - - TestToto = {} --class - - function TestToto:test1_withFailure() - local a = 1 - assertEquals( a , 1 ) - -- will fail - assertEquals( a , 2 ) - end - - [...] - -However, this is an obsolete practice in Lua. It is now recommended to keep all functions inside the module. Starting -from version 3.1 LuaUnit follows this practice and the code should be adapted to look like this: - -.. code-block:: lua - - -- the imported module must be stored - luaunit = require('luaunit') - - TestToto = {} --class - - function TestToto:test1_withFailure() - local a = 1 - luaunit.assertEquals( a , 1 ) - -- will fail - luaunit.assertEquals( a , 2 ) - end - - [...] - -If you prefer the old way, LuaUnit can continue to export assertions functions if you set the following -global variable **prior** to importing LuaUnit: - -.. code-block:: lua - - -- this works - EXPORT_ASSERT_TO_GLOBALS = true - require('luaunit') - - TestToto = {} --class - - function TestToto:test1_withFailure() - local a = 1 - assertEquals( a , 1 ) - -- will fail - assertEquals( a , 2 ) - end - - [...] - - -.. _luaunit-run: - -LuaUnit.run() function -====================== - -**Return value** - -Normally, you should run your test suite with the following line:: - - os.exit(luaunit.LuaUnit.run()) - -The *run()* function returns the number of failures of the test suite. This is -good for an exit code, 0 meaning success. - - -**Arguments** - -If no arguments are supplied, it parses the command-line arguments of the script -and interpret them. If arguments are supplied to the function, they are parsed -instead of the command-line. It uses the same syntax. - -Example:: - - -- execute tests matching the 'withXY' pattern - os.exit(luaunit.LuaUnit.run('--pattern', 'withXY')) - - -**Choice of tests** - -If test names were supplied, only those -tests are executed. When test names are supplied, they don't have -to start with *test*, they are run anyway. - -If no test names were supplied, a general test collection process starts -under the following rules: - -* all variable starting with *test* or *Test* are scanned. -* if the variable is a function it is collected for testing -* if the variable is a table: - - * all keys starting with *test* or *Test* are collected (provided that they are functions) - * keys with name *setUp* and *tearDown* are also collected - -If one or more pattern were supplied, the test are then filtered according the -pattern(s). Only the test that match the pattern(s) are actually executed. - - -**setup and teardown** - -The function *setUp()* is executed before each test if it exists in the table. -The function *tearDown()* is executed after every test if it exists in the table. - -.. Note:: - *tearDown()* is always executed if it exists, even if there was a failure in the test or in the *setUp()* function. - Failures in *setUp()* or *tearDown()* are considered as a general test failures. - - -LuaUnit.runSuite() function -============================== - -If you want to keep the flexibility of the command-line parsing, but want to force -some parameters, like the output format, you must use a slightly different syntax:: - - lu = luaunit.LuaUnit.new() - lu:setOutputType("tap") - os.exit( lu:runSuite() ) - -*runSuite()* behaves like *run()* except that it must be started -with a LuaUnit instance as first argument, and it will use the LuaUnit -instance settings. - - -.. _command-line: - -Command-line options -==================== - -Usage: lua [options] [testname1 [testname2] - -**Test names** - -When no test names are supplied, all tests are collected. - -The syntax for supplying test names can be either: name of the function, name of the table -or name of the table + '.' + name of the function. Only the supplied tests will be executed. - -**Selecting output format** - -Choose the output format with the syntax ``-o FORMAT`` or ``--output FORMAT``. - -Formats available: - -* ``text``: the default output format of LuaUnit -* ``nil``: no output at all -* ``tap``: output compatible with the `Test Anything Protocol`_ -* ``junit``: output compatible with the *JUnit xml* format (used by many CI platforms) - -.. _Test Anything Protocol: http://testanything.org/ - -.. Warning:: - - In the JUnit format, a destination filename must be supplied with ``--name`` or ``-n`` - -**Destination filename** - -When using the JUnit format, the test suites writes an XML file with the test results. The -file name is mandatory and must be supplied with: ``--name FILENAME`` or ``-n FILENAME`` - -**Selecting tests with patterns** - -You select a subset of tests by specifying one or more filter patterns, -with ``-p PATTERN`` or ``--pattern PATTERN``. - -The pattern is looked for on the full test name *TestTable.testMethod* . Only the tests that -actually match the pattern are selected. When specifying more than one pattern, -they are tried one by one until the name matches (OR combination). - -Make sure you esape magic chars like ``+?-*`` with ``%`` . - -**Stopping on first error or failure** - -If --failure or -f is passed as an option, LuaUnit will stop on the first failure or error and display the test results. - -If --error or -e is passed as an option, LuaUnit will stop on the first error (but continue on failures). - - -**Other Options:** - -* ``-h``, ``--help``: display the command-line help. -* ``--version``: display the version information -* ``-v``, ``--verbose``: Increase the output verbosity. The exact effect depends on the output format. May be specified multiple times. -* ``-q``, ``--quiet``: Set verbosity to minimum. The exact effect depends on the output format. - - -.. _assertions-label: - -Assertions functions -===================== -You will now find the list of all assertion functions. For all functions, When an assertion fails, the failure -message tries to be as informative as possible, by displaying the expectation and value that caused the failure. - -.. Note:: see :ref:`table-printing` and :ref:`comparing-table-keys-table` for more dealing with recursive tables and tables containing keys of type table. - - -.. _assert-equality: - -Equality assertions ----------------------- -All equality assertions functions take two arguments, in the order -*actual value* then *expected value*. Some people are more familiar -with the order *expected value* then *actual value*. It is possible to configure -LuaUnit to use the opposite order for all equality assertions, by setting up a module -variable: - -.. code-block:: lua - - luaunit.ORDER_ACTUAL_EXPECTED=false - -The order only matters for the message that is displayed in case of failures. It does -not influence the test itself. - - -.. function:: assertEquals(actual, expected) - - **Alias**: *assert_equals()* - - Assert that two values are equal. - - For tables, the comparison is a deep comparison : - - * number of elements must be the same - * tables must contain the same keys - * each key must contain the same values. The values - are also compared recursively with deep comparison. - - LuaUnit provides other table-related assertions, see :ref:`assert-table` - -.. function:: assertNotEquals(actual, expected) - - **Alias**: *assert_not_equals()* - - Assert that two values are different. The assertion - fails if the two values are identical. - - It also uses table deep comparison. - -.. function:: assertAlmostEquals( actual, expected, margin ) - - **Alias**: *assert_almost_equals()* - - Assert that two floating point numbers are almost equal. - - When comparing floating point numbers, strict equality does not work. - Computer arithmetic is so that an operation that mathematically - yields 1.00000000 might yield 0.999999999999 in lua . That's why you - need an *almost equals* comparison, where you specify the error margin. - -.. function:: assertNotAlmostEquals( actual, expected, margin ) - - **Alias**: *assert_not_almost_equals()* - - Assert that two floating point numbers are not almost equal. - -.. _assert-value: - -Value assertions ----------------------- -.. function:: assertTrue(value) - - **Alias**: *assert_true()* - - Assert that a given value compares to true. Lua coercion rules are applied - so that values like ``0``, ``""``, ``1.17`` all compare to *true*. - -.. function:: assertFalse(value) - - **Alias**: *assert_false()* - - Assert that a given value compares to false. Lua coercion rules are applied - so that only *nil* and *false* all compare to *false*. - -.. function:: assertNil(value) - - **Aliases**: *assert_nil()*, *assertIsNil()*, *assert_is_nil()* - - Assert that a given value is *nil* . - -.. function:: assertNotNil(value) - - **Aliases**: *assert_not_nil()*, *assertNotIsNil()*, *assert_not_is_nil()* - - Assert that a given value is not *nil* . Lua coercion rules are applied - so that values like ``0``, ``""``, ``false`` all validate the assertion. - -.. function:: assertIs(actual, expected) - - **Alias**: *assert_is()* - - Assert that two variables are identical. For string, numbers, boolean and for nil, - this gives the same result as :func:`assertEquals` . For the other types, identity - means that the two variables refer to the same object. - - **Example :** - -.. code-block:: lua - - s1='toto' - s2='to'..'to' - t1={1,2} - t2={1,2} - - luaunit.assertIs(s1,s1) -- ok - luaunit.assertIs(s1,s2) -- ok - luaunit.assertIs(t1,t1) -- ok - luaunit.assertIs(t1,t2) -- fail - -.. function:: assertNotIs(actual, expected) - - **Alias**: *assert_not_is()* - - Assert that two variables are not identical, in the sense that they do not - refer to the same value. See :func:`assertIs` for more details. - -.. _assert-string: - -String assertions --------------------------- - -Assertions related to string and patterns. - -.. function:: assertStrContains( str, sub [, useRe] ) - - **Alias**: *assert_str_contains()* - - Assert that a string contains the given substring or pattern. - - By default, substring is searched in the string. If *useRe* - is provided and is true, *sub* is treated as a pattern which - is searched inside the string *str* . - -.. function:: assertStrIContains( str, sub ) - - **Alias**: *assert_str_icontains()* - - Assert that a string contains the given substring, irrespective of the case. - - Not that unlike :func:`assertStrcontains`, you can not search for a pattern. - - -.. function:: assertNotStrContains( str, sub, useRe ) - - **Alias**: *assert_not_str_contains()* - - Assert that a string does not contain a given substring or pattern. - - By default, substring is searched in the string. If *useRe* - is provided and is true, *sub* is treated as a pattern which - is searched inside the string *str* . - -.. function:: assertNotStrIContains( str, sub ) - - **Alias**: *assert_not_str_icontains()* - - Assert that a string does not contain the given substring, irrespective of the case. - - Not that unlike :func:`assertNotStrcontains`, you can not search for a pattern. - -.. function:: assertStrMatches( str, pattern [, start [, final] ] ) - - **Alias**: *assert_str_matches()* - - Assert that a string matches the full pattern *pattern*. - - If *start* and *final* are not provided or are *nil*, the pattern must match the full string, from start to end. The - functions allows to specify the expected start and end position of the pattern in the string. - - -.. _assert-error: - -Error assertions --------------------------- -Error related assertions, to verify error generation and error messages. - -.. function:: assertError( func, ...) - - **Alias**: *assert_error()* - - Assert that calling functions *func* with the arguments yields an error. If the - function does not yield an error, the assertion fails. - - Note that the error message itself is not checked, which means that this function - does not distinguish between the legitimate error that you expect and another error - that might be triggered by mistake. - - The next functions provide a better approach to error testing, by checking - explicitly the error message content. - -.. Note:: - - When testing LuaUnit, switching from *assertError()* to *assertErrorMsgEquals()* - revealed quite a few bugs! - -.. function:: assertErrorMsgEquals( expectedMsg, func, ... ) - - **Alias**: *assert_error_msg_equals()* - - Assert that calling function *func* will generate exactly the given error message. If the - function does not yield an error, or if the error message is not identical, the assertion fails. - - Be careful when using this function that error messages usually contain the file name and - line number information of where the error was generated. This is usually inconvenient. To - ignore the filename and line number information, you can either use a pattern with :func:`assertErrorMsgMatches` - or simply check for the message containt with :func:`assertErrorMsgContains` . - -.. function:: assertErrorMsgContains( partialMsg, func, ... ) - - **Alias**: *assert_error_msg_contains()* - - Assert that calling function *func* will generate an error message containing *partialMsg* . If the - function does not yield an error, or if the expected message is not contained in the error message, the - assertion fails. - -.. function:: assertErrorMsgMatches( expectedPattern, func, ... ) - - **Alias**: *assert_error_msg_matches()* - - Assert that calling function *func* will generate an error message matching *expectedPattern* . If the - function does not yield an error, or if the error message does not match the provided patternm the - assertion fails. - - Note that matching is done from the start to the end of the error message. Be sure to escape magic all magic - characters with ``%`` (like ``-+.?*``) . - - -.. _assert-type: - -Type assertions --------------------------- - - The following functions all perform type checking on their argument. If the - received value is not of the right type, the failure message will contain - the expected type, the received type and the received value to help you - identify better the problem. - -.. function:: assertIsNumber(value) - - **Aliases**: *assertNumber()*, *assert_is_number()*, *assert_number()* - - Assert that the argument is a number (integer or float) - -.. function:: assertIsString(value) - - **Aliases**: *assertString()*, *assert_is_string()*, *assert_string()* - - Assert that the argument is a string. - -.. function:: assertIsTable(value) - - **Aliases**: *assertTable()*, *assert_is_table()*, *assert_table()* - - Assert that the argument is a table. - -.. function:: assertIsBoolean(value) - - **Aliases**: *assertBoolean()*, *assert_is_boolean()*, *assert_boolean()* - - Assert that the argument is a boolean. - -.. function:: assertIsNil(value) - - **Aliases**: *assertNil()*, *assert_is_nil()*, *assert_nil()* - - Assert that the argument is a nil. - -.. function:: assertIsFunction(value) - - **Aliases**: *assertFunction()*, *assert_is_function()*, *assert_function()* - - Assert that the argument is a function. - -.. function:: assertIsUserdata(value) - - **Aliases**: *assertUserdata()*, *assert_is_userdata()*, *assert_userdata()* - - Assert that the argument is a userdata. - -.. function:: assertIsCoroutine(value) - - **Aliases**: *assertCoroutine()*, *assert_is_coroutine()*, *assert_coroutine()*, *assertIsThread()*, *assertThread()*, *assert_is_thread()*, *assert_thread()* - - Assert that the argument is a coroutine (an object with type *thread* ). - -.. _assert-table: - -Table assertions --------------------------- - -.. function:: assertItemsEquals(actual, expected) - - **Alias**: *assert_items_equals()* - - Assert that two tables contain the same items, irrespective of their keys. - - This function is practical for example if you want to compare two lists but - where items are not in the same order: - -.. code-block:: lua - - luaunit.assertItemsEquals( {1,2,3}, {3,2,1} ) -- assertion succeeds - -.. - - The comparison is not recursive on the items: if any of the items are tables, - they are compared using table equality (like as in :func:`assertEquals` ), where - the key matters. - - -.. code-block:: lua - - luaunit.assertItemsEquals( {1,{2,3},4}, {4,{3,2,},1} ) -- assertion fails because {2,3} ~= {3,2} - - -.. _table-printing: - -More on table printing -=========================== - -When asserting tables equality, by default, the table content is printed in case of failures. LuaUnit tries to print -tables in a readable format. It is -possible to always display the table id along with the content, by setting a module parameter PRINT_TABLE_REF_IN_ERROR_MSG . This -helps identifying tables: - -.. code-block:: lua - - local lu = require('luaunit') - - local t1 = {1,2,3} - -- normally, t1 is dispalyed as: "{1,2,3}" - - -- if setting this: - lu.PRINT_TABLE_REF_IN_ERROR_MSG = true - - -- display of table t1 becomes: " {1,2,3}" - - -.. Note :: table loops - - When displaying table content, it is possible to encounter loops, if for example two table references eachother. In such - cases, LuaUnit display the full table content once, along with the table id, and displays only the table id for the looping - reference. - -**Example:** displaying a table with reference loop - -.. code-block:: lua - - local t1 = {} - local t2 = {} - t1.t2 = t2 - t1.a = {1,2,3} - t2.t1 = t1 - - -- when displaying table t1: - -- table t1 inside t2 is only displayed by its id because t1 is already being displayed - -- table t2 is displayed along with its id because it is part of a loop. - -- t1: " { a={1,2,3}, t2= {t1=} }" - - -.. _comparing-table-keys-table: - -Comparing tables with keys of type table -=========================================== - - -This is a very uncommon scenario but there are a few programs out there which use tables as keys for other tables. LuaUnit has been adjusted to deal intelligently with this scenario. - -A small code block is worth a thousand pictures : - -.. code-block:: lua - - local lu = require('luaunit') - - -- let's define two tables - t1 = { 1, 2 } - t2 = { 1, 2 } - lu.assertEquals( t1, t2 ) -- succeeds - - -- let's define three tables, with the two above tables as keys - t3 = { t1='a' } - t4 = { t2='a' } - t5 = { t2='a' } - -There are two ways to treat comparison of tables t3 and t4: - -**Method 1: table keys are compared by content** - -* t3 contain one key: t1 -* t4 contain one key: t2, which has exactly the same content as t1 -* the two keys compare equally with assertEquals, so assertEquals( t3, t4 ) succeeds - -**Method 2: table keys are compared by reference** - -* t3 contain one key: t1 -* t4 contain one key: t2, which is not the same table as t1, its reference is different -* the two keys are different because t1 is a different object than t2 so assertEquals( t3, t4 ) fails - -Whether method 1 or method 2 is more appropriate is up for debate. - -LuaUnit has been adjusted to support both scenarios, with the config variable: *TABLE_EQUALS_KEYBYCONTENT* - -* TABLE_EQUALS_KEYBYCONTENT = true (default): method 1 - table keys compared by content -* TABLE_EQUALS_KEYBYCONTENT = false: method 2 - table keys compared by reference - -In any case, assertEquals( t4, t5 ) always succeeds. - -To adjust the config, change it into the luaunit table before running any tests: - - -.. code-block:: lua - - local lu = require('luaunit') - - -- define all your tests - -- ... - - lu.TABLE_EQUALS_KEYBYCONTENT = false - -- run your tests: - os.exit( lu.LuaUnit.run() ) - -.. _developing-luaunit: - -Developing LuaUnit -****************** - -Development ecosystem -====================== - -LuaUnit is developed on `Github`_. - -.. _Github: https://github.com/bluebird75/luaunit - -Bugs or feature requests should be reported using `GitHub issues`_. - -.. _Github issues: https://github.com/bluebird75/luaunit/issues - -Usage and development may be discussed on `LuaUnit mailing-list`_ . If you are using LuaUnit for your -project, please drop us an note. - -.. _LuaUnit mailing-list: http://lists.freehackers.org/list/luaunit%40freehackers.org/ - -It is released under the BSD license. - -This documentation is available at `Read-the-docs`_. - -.. _Read-the-docs: http://luaunit.readthedocs.org/en/latest/ - - -Contributing -============= -You may contribute to LuaUnit by reporting bugs, fixing reported bugs or developing new features. - -Some issues on github are marked with label *enhancement*. Feel free to pick up such tasks and implement them. - -Changes should be proposed as *Pull Requests* on github. - -Unit-tests -------------------- -All proposed changes should pass all unit-tests and if needed, add more unit-tests to cover the bug or the new functionality. Usage is pretty simple: - -.. code-block:: shell - - $ lua run_unit_tests.lua - ................................................................................ - ............................... - Ran 111 tests in 0.120 seconds - OK - - -Functional tests -------------------- -Functional tests also exist to validate LuaUnit. Their management is slightly more complicated. - -The main goal of functional tests is to validate that LuaUnit output has not been altered. Since LuaUnit supports some standard compliant output (TAP, junitxml), this is very important (and it has been broken in the past) - -Functional tests perform the following actions: - -* Run the 2 suites: example_with_luaunit.lua, test_with_err_fail_pass.lua (with various options to have successe, failure and/or errors) -* Run every suite with all output format, all verbosity -* Validate the XML output with jenkins/hudson and junit schema -* Compare the results with the previous output ( archived in test/ref ), with some tricks to make the comparison possible : - - * adjustment of the file separator to use the same output on Windows and Unix - * date and test duration is zeroed so that it does not impact the comparison - * adjust the stack trace format which has changed between Lua 5.1, 5.2 and 5.3 - -* Run some legacy suites or tricky output to manage and verify output: test_with_xml.lua, , compat_luaunit_v2x.lua, legacy_example_with_luaunit.lua - - -For functional tests to run, *diff* must be available on the command line. *xmllint* is needed to perform the xml validation but -this step is skipped if *xmllint* can not be found. - -When functional tests work well, it looks like this: - -.. code-block:: shell - - $ lua run_functional_tests.lua - ............... - Ran 15 tests in 9.676 seconds - OK - - -When functional test fail, a diff of the comparison between the reference output and the current output is displayed (it can be quite -long). The list of faulty files is summed-up at the end. - -Modifying reference files for functional tests ------------------------------------------------ -The script run_functional_tests.lua supports a --update option, with an optional argument. - -* *--update* without argument **overwrites all reference output** with the current output. Use only if you know what you are doing, this is usually a very bad idea! - -* The following argument overwrite a specific subset of reference files, select the one that fits your change: - - * TestXml: XML output of test_with_xml - * ExampleXml: XML output of example_with_luaunit - * ExampleTap: TAP output of example_with_luaunit - * ExampleText: text output of example_with_luaunit - * ExampleNil: nil output of example_with_luaunit - * ErrFailPassText: text output of test_with_err_fail_pass - * ErrFailPassTap: TAP output of test_with_err_fail_pass - * ErrFailPassXml: XML output of test_with_err_fail_pass - * StopOnError: errFailPassTextStopOnError-1.txt, -2.txt, -3.txt, -4.txt - - -For example to record a change in the test_with_err_fail_pass output - -.. code-block:: shell - - $ lua run_functional_tests.lua --update ErrFailPassXml ErrFailPassTap ErrFailPassText - - >>>>>>> Generating test/ref/errFailPassXmlDefault.txt - >>>>>>> Generating test/ref/errFailPassXmlDefault-success.txt - >>>>>>> Generating test/ref/errFailPassXmlDefault-failures.txt - >>>>>>> Generating test/ref/errFailPassXmlQuiet.txt - >>>>>>> Generating test/ref/errFailPassXmlQuiet-success.txt - >>>>>>> Generating test/ref/errFailPassXmlQuiet-failures.txt - >>>>>>> Generating test/ref/errFailPassXmlVerbose.txt - >>>>>>> Generating test/ref/errFailPassXmlVerbose-success.txt - >>>>>>> Generating test/ref/errFailPassXmlVerbose-failures.txt - >>>>>>> Generating test/ref/errFailPassTapDefault.txt - >>>>>>> Generating test/ref/errFailPassTapDefault-success.txt - >>>>>>> Generating test/ref/errFailPassTapDefault-failures.txt - >>>>>>> Generating test/ref/errFailPassTapQuiet.txt - >>>>>>> Generating test/ref/errFailPassTapQuiet-success.txt - >>>>>>> Generating test/ref/errFailPassTapQuiet-failures.txt - >>>>>>> Generating test/ref/errFailPassTapVerbose.txt - >>>>>>> Generating test/ref/errFailPassTapVerbose-success.txt - >>>>>>> Generating test/ref/errFailPassTapVerbose-failures.txt - >>>>>>> Generating test/ref/errFailPassTextDefault.txt - >>>>>>> Generating test/ref/errFailPassTextDefault-success.txt - >>>>>>> Generating test/ref/errFailPassTextDefault-failures.txt - >>>>>>> Generating test/ref/errFailPassTextQuiet.txt - >>>>>>> Generating test/ref/errFailPassTextQuiet-success.txt - >>>>>>> Generating test/ref/errFailPassTextQuiet-failures.txt - >>>>>>> Generating test/ref/errFailPassTextVerbose.txt - >>>>>>> Generating test/ref/errFailPassTextVerbose-success.txt - >>>>>>> Generating test/ref/errFailPassTextVerbose-failures.txt - $ - -You can then commit the new files into git. - -.. Note :: how to commit updated reference outputs - - When committing those changes into git, please use if possible an - intelligent git committing tool to commit only the interesting changes. - With SourceTree for example, in case of XML changes, I can select only the - lines relevant to the change and avoid committing all the updates to test - duration and test datestamp. - - - -Typical failures for functional tests ---------------------------------------- - -Functional tests may start failing when: - -1. Increasing LuaUnit version -2. Improving or breaking LuaUnit output - - -Index and Search page -********************** - -* :ref:`genindex` -* :ref:`search` - +.. LuaUnit documentation master file, created by + + sphinx-quickstart on Thu Aug 21 21:45:55 2014. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + + +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +Welcome to LuaUnit's documentation! +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, + +Introduction +************ + +LuaUnit is a popular unit-testing framework for Lua, with an interface typical +of xUnit libraries (Python unittest, Junit, NUnit, ...). It supports +several output formats (Text, TAP, JUnit, ...) to be used directly or work with Continuous Integration platforms +(Jenkins, Hudson, ...). + +For simplicity, LuaUnit is contained into a single-file and has no external dependency. To start using it, +just add the file *luaunit.lua* to your project. A `LuaRocks package`_ is also available. + +.. _LuaRocks package: https://luarocks.org/modules/bluebird75/luaunit + +Tutorial and reference documentation is available on `Read-the-docs`_ . + +.. _Read-the-docs: http://luaunit.readthedocs.org/en/latest/ + +LuaUnit also provides some dedicated support to scientific computing. See the section `Scientific computing and LuaUnit`_ + +LuaUnit may also be used as an assertion library. In that case, you will call the assertion functions, which generate errors +when the assertion fails. The error includes a detailed analysis of the failed assertion, like when executing a test suite. + +LuaUnit provides another generic usage function: :func:`prettystr` which converts any value to a nicely +formatted string. It supports in particular tables, nested table and even recursive tables. + + +More details +************ + +LuaUnit provides a wide range of assertions and goes into great efforts to provide the most useful output. For example +since version 3.3 , comparing lists will provide a detailed difference analysis: + +.. code-block:: lua + + -- lua test code. Can you spot the difference ? + function TestListCompare:test1() + local A = { 121221, 122211, 121221, 122211, 121221, 122212, 121212, 122112, 122121, 121212, 122121 } + local B = { 121221, 122211, 121221, 122211, 121221, 122212, 121212, 122112, 121221, 121212, 122121 } + lu.assertEquals( A, B ) + end + + $ lua test_some_lists_comparison.lua + + TestListCompare.test1 ... FAIL + test/some_lists_comparisons.lua:22: expected: + + List difference analysis: + * lists A (actual) and B (expected) have the same size + * lists A and B start differing at index 9 + * lists A and B are equal again from index 10 + * Common parts: + = A[1], B[1]: 121221 + = A[2], B[2]: 122211 + = A[3], B[3]: 121221 + = A[4], B[4]: 122211 + = A[5], B[5]: 121221 + = A[6], B[6]: 122212 + = A[7], B[7]: 121212 + = A[8], B[8]: 122112 + * Differing parts: + - A[9]: 122121 + + B[9]: 121221 + * Common parts at the end of the lists + = A[10], B[10]: 121212 + = A[11], B[11]: 122121 + + +The command-line options provide a flexible interface to select tests by name or patterns, control output +format, set verbosity and more. See `Using the command-line`_ . + +LuaUnit is very well tested: code coverage is 99.5% . The test suite is run on every version of Lua (Lua 5.1 to 5.3, LuaJIT 2.0 and 2.1 beta) +and on many OS (Windows Seven, Windows Server 2012, MacOs X and Ubuntu). You can check the continuous build results on `Travis-CI`_ and `AppVeyor`_ . + +.. _Travis-CI: https://travis-ci.org/bluebird75/luaunit +.. _AppVeyor: https://ci.appveyor.com/project/bluebird75/luaunit/history + +LuaUnit is maintained on GitHub: https://github.com/bluebird75/luaunit . We gladly accept feature requests and even better Pull Requests. + +LuaUnit is released under the BSD license. + + +Installation +============ + +LuaUnit is packed into a single-file. To make start using it, just add the file to your project. + +Several installation methods are available. + +LuaRocks +-------- + +LuaUnit v3.3 is available as a `LuaRocks package`_ . + +.. _LuaRocks package: https://luarocks.org/modules/bluebird75/luaunit + +GitHub +------ + +The simplest way to install LuaUnit is to fetch the GitHub version: + +.. code-block:: bash + + git clone git@github.com:bluebird75/luaunit.git + +Then copy the file luaunit.lua into your project or the Lua libs directory. + +The version in development on GitHub is always stable and can be used safely. + +On Linux, you can also install it into your Lua directories + +.. code-block:: bash + + sudo python doit.py install + +If that fail, edit the function *install()* in the file *doit.py* to adjust +the Lua version and installation directory. It uses, by default, Linux paths that depend on the version. + + +Upgrade note +================ + +**Important note when upgrading to version 3.1 and above** : there is a break of backward compatibility in version 3.1, assertions functions are no longer exported directly to the global namespace. See :ref:`luaunit-global-asserts` on how to adjust or restore previous behavior. + + +LuaUnit development +=================== + +See `Developing luaunit`_ + +Version and Changelog +===================== +This documentation describes the functionality of LuaUnit v3.2 . + +New in version 3.3 - 6. Mar 2018 +-------------------------------- +* General + * when comparing lists with :func:`assertEquals`, failure message provides an advanced comparison of the lists + * :func:`assertErrorMsgEquals` can check for error raised as tables + * tests may be finished early with :func:`fail`, :func:`failIf`, :func:`success` or :func:`successIf` + * improve printing of recursive tables + * improvements and fixes to JUnit and TAP output + * stricter :func:`assertTrue` and :func:`assertFalse`: they only succeed with boolean values + * add :func:`assertEvalToTrue` and :func:`assertEvalToFalse` with previous :func:`assertTrue`/:func:`assertFalse` behavior of coercing to boolean before asserting + * all assertion functions accept an optional extra message, to be printed along the failure +* New command-line arguments: + * can now shuffle tests with ``--shuffle`` or ``-s`` + * possibility to repeat tests (for example to trigger a JIT), with ``--repeat NUM`` or ``-r NUM`` + * more flexible test selection with inclusion (``--pattern`` / ``-p``) or exclusion (``--exclude`` / ``-x``) or combination of both +* Scientific computing dedicated support (see documentation): + * provide the machine epsilon in EPS + * new functions: :func:`assertNan`, :func:`assertInf`, :func:`assertPlusInf`, :func:`assertMinusInf`, :func:`assertPlusZero`, :func:`assertMinusZero` and + their negative version + * in :func:`assertAlmostEquals`, margin no longer provides a default value of 1E-11, the machine epsilon is used instead +* Platform and continuous integration support: + * validate LuaUnit on MacOs platform (thank to Travis CI) + * validate LuaUnit with 32 bits numbers (floats) and 64 bits numbers (double) + * add test coverage measurements thank to coveralls.io . Status: 99.76% of the code is verified. + * use cache for AppVeyor and Travis builds + * support for ``luarocks doc`` command +* General doc improvements (detailed description of all output, more cross-linking between sections) + + +New in version 3.2 - 12. Jul 2016 +--------------------------------- +* Add command-line option to stop on first error or failure. See `Other options`_ +* Distinguish between failures (failed assertion) and errors +* Support for new versions: Lua 5.3 and LuaJIT (2.0, 2.1 beta) +* Validation of all lua versions on Travis CI and AppVeyor +* Add compatibility layer with forked luaunit v2.x +* Added documentation about development process. See `Developing luaUnit`_ +* Improved support for table containing keys of type table. See :ref:`comparing-table-keys-table` +* Small bug fixes, several internal improvements +* Availability of a Luarock package. See `https://luarocks.org/modules/bluebird75/luaunit` . + +New in version 3.1 - 10. Mar 2015 +--------------------------------- +* luaunit no longer pollutes global namespace, unless defining EXPORT_ASSERT_TO_GLOBALS to true. See :ref:`luaunit-global-asserts` +* fixes and validation of JUnit XML generation +* strip luaunit internal information from stacktrace +* general improvements of test results with duration and other details +* improve printing for tables, with an option to always print table id. See :ref:`table-printing` +* fix printing of recursive tables + +**Important note when upgrading to version 3.1** : assertions functions are +no longer exported directly to the global namespace. See :ref:`luaunit-global-asserts` + +New in version 3.0 - 9. Oct 2014 +-------------------------------- + +Because LuaUnit was forked and released as some 2.x version, version number +is now jumping to 3.0 . + +* full documentation available in text, html and pdf at http://luaunit.read-the-docs.org +* new output format: JUnit, compatible with Bamboo and other CI platforms. See `Output formats`_ +* much better table assertions +* new assertions for strings, with patterns and case insensitivity: assertStrContains, + assertNotStrContains, assertNotStrIContains, assertStrIContains, assertStrMatches +* new assertions for floats: assertAlmostEquals, assertNotAlmostEquals +* type assertions: assertIsString, assertIsNumber, ... +* error assertions: assertErrorMsgEquals, assertErrorMsgContains, assertErrorMsgMatches +* improved error messages for several assertions +* command-line options to select test, control output type and verbosity + + +New in version 1.5 - 8. Nov 2012 +-------------------------------- +* compatibility with Lua 5.1 and 5.2 +* better object model internally +* a lot more of internal tests +* several internal bug fixes +* make it easy to customize the test output +* running test functions no longer requires a wrapper +* several level of verbosity + + +New in version 1.4 - 26. Jul 2012 +--------------------------------- +* switch from X11 to more popular BSD license +* add TAP output format for integration into Jenkins. See `Output formats`_ +* official repository now on GitHub + + +New in version 1.3 - 30. Oct 2007 +--------------------------------- +* port to lua 5.1 +* iterate over the test classes, methods and functions in the alphabetical order +* change the default order of expected, actual in assertEquals. See `Equality assertions`_ + + +Version 1.2 - 13. Jun 2005 +--------------------------------- +* first public release + + +Version 1.1 +------------ +* move global variables to internal variables +* assertion order is configurable between expected/actual or actual/expected. See `Equality assertions`_ +* new assertion to check that a function call returns an error +* display the calling stack when an error is spotted +* two verbosity level, like in python unittest + + +Getting started with LuaUnit +**************************** + +This section will guide you through a step by step usage of *LuaUnit* . The full source code +of the example below is available in the : :ref:`source-code-example` or in the file *my_test_suite.lua* +in the doc directory. + +Setting up your test script +=========================== + +To get started, create your file *my_test_suite.lua* . + +The script should import LuaUnit:: + + lu = require('luaunit') + +The last line executes your script with LuaUnit and exit with the +proper error code:: + + os.exit( lu.LuaUnit.run() ) + +Now, run your file with:: + + lua my_test_suite.lua + +It prints something like:: + + Ran 0 tests in 0.000 seconds, 0 successes, 0 failures + OK + +Now, your testing framework is in place, you can start writing tests. + +Writing tests +============= + +LuaUnit scans all variables that start with *test* or *Test*. +If they are functions, or if they are tables that contain +functions that start with *test* or *Test*, they are run as part of the test suite. + +So just write a function whose name starts with test. Inside test functions, use the assertions functions provided by LuaUnit, such +as :func:`assertEquals`. + +Let's see that in practice. + +Suppose you want to test the following add function:: + + function add(v1,v2) + -- add positive numbers + -- return 0 if any of the numbers are 0 + -- error if any of the two numbers are negative + if v1 < 0 or v2 < 0 then + error('Can only add positive or null numbers, received '..v1..' and '..v2) + end + if v1 == 0 or v2 == 0 then + return 0 + end + return v1+v2 + end + +You write the following tests:: + + function testAddPositive() + lu.assertEquals(add(1,1),2) + end + + function testAddZero() + lu.assertEquals(add(1,0),0) + lu.assertEquals(add(0,5),0) + lu.assertEquals(add(0,0),0) + end + + +:func:`assertEquals` is the most commonly used assertion function. It +verifies that both argument are equals, in the order actual value, expected value. + +Rerun your test script (``-v`` is to activate a more verbose output):: + + $ lua my_test_suite.lua -v + +It now prints:: + + Started on 02/19/17 22:15:53 + TestAdd.testAddPositive ... Ok + TestAdd.testAddZero ... Ok + ========================================================= + Ran 2 tests in 0.003 seconds, 2 successes, 0 failures + OK + +You always have: + +* the date at which the test suite was started +* the group to which the function belongs (usually, the name of the function table, and ** for all direct test functions) +* the name of the function being executed +* a report at the end, with number of executed test, number of non selected tests if any, number of failures, number of errors (if any) and duration. + +The difference between failures and errors are: + +* luaunit assertion functions generate failures +* any unexpected error during execution generates an error +* failures or errors during setup() or teardown() always generate errors + + +If we continue with our example, we also want to test that when the function receives negative numbers, it generates an error. Use +:func:`assertError` or even better, :func:`assertErrorMsgContains` to also validate the content +of the error message. There are other types or error checking functions, see `Error assertions`_ . Here +we use :func:`assertErrorMsgContains` . First argument is the expected message, then the function to call +and the optional arguments:: + + function testAddError() + lu.assertErrorMsgContains('Can only add positive or null numbers, received 2 and -3', add, 2, -3) + end + +Now, suppose we also have the following function to test:: + + function adder(v) + -- return a function that adds v to its argument using add + function closure( x ) return x+v end + return closure + end + +We want to test the type of the value returned by adder and its behavior. LuaUnit +provides assertion for type testing (see `Type assertions`_ ). In this case, we use +:func:`assertIsFunction`:: + + function testAdder() + f = adder(3) + lu.assertIsFunction( f ) + lu.assertEquals( f(2), 5 ) + end + +Grouping tests, setup/teardown functionality +===================================================== + +When the number of tests starts to grow, you usually organise them +into separate groups. You can do that with LuaUnit by putting them +inside a table (whose name must start with *Test* or *test* ). + +For example, assume we have a second function to test:: + + function div(v1,v2) + -- divide positive numbers + -- return 0 if any of the numbers are 0 + -- error if any of the two numbers are negative + if v1 < 0 or v2 < 0 then + error('Can only divide positive or null numbers, received '..v1..' and '..v2) + end + if v1 == 0 or v2 == 0 then + return 0 + end + return v1/v2 + end + +We move the tests related to the function add into their own table:: + + TestAdd = {} + function TestAdd:testAddPositive() + lu.assertEquals(add(1,1),2) + end + + function TestAdd:testAddZero() + lu.assertEquals(add(1,0),0) + lu.assertEquals(add(0,5),0) + lu.assertEquals(add(0,0),0) + end + + function TestAdd:testAddError() + lu.assertErrorMsgContains('Can only add positive or null numbers, received 2 and -3', add, 2, -3) + end + + function TestAdd:testAdder() + f = adder(3) + lu.assertIsFunction( f ) + lu.assertEquals( f(2), 5 ) + end + -- end of table TestAdd + +Then we create a second set of tests for div:: + + TestDiv = {} + function TestDiv:testDivPositive() + lu.assertEquals(div(4,2),2) + end + + function TestDiv:testDivZero() + lu.assertEquals(div(4,0),0) + lu.assertEquals(div(0,5),0) + lu.assertEquals(div(0,0),0) + end + + function TestDiv:testDivError() + lu.assertErrorMsgContains('Can only divide positive or null numbers, received 2 and -3', div, 2, -3) + end + -- end of table TestDiv + +Execution of the test suite now looks like this:: + + Started on 02/19/17 22:15:53 + TestAdd.testAddError ... Ok + TestAdd.testAddPositive ... Ok + TestAdd.testAddZero ... Ok + TestAdd.testAdder ... Ok + TestDiv.testDivError ... Ok + TestDiv.testDivPositive ... Ok + TestDiv.testDivZero ... Ok + ========================================================= + Ran 7 tests in 0.006 seconds, 7 successes, 0 failures + OK + + +When tests are defined in tables, you can optionally define two special +functions, *setUp()* and *tearDown()*, which will be executed +respectively before and after every test. + +These function may be used to create specific resources for the +test being executed and cleanup the test environment. + +For a practical example, imagine that we have a *log()* function +that writes strings to a log file on disk. The file is created +upon first usage of the function, and the filename is defined +by calling the function *initLog()*. + +The tests for these functions would take advantage of the *setup/teardown* +functionality to prepare a log filename shared +by all tests, make sure that all tests start with a non existing +log file name, and delete the log filename after every test:: + + TestLogger = {} + function TestLogger:setUp() + -- define the fname to use for logging + self.fname = 'mytmplog.log' + -- make sure the file does not already exists + os.remove(self.fname) + end + + function TestLogger:testLoggerCreatesFile() + initLog(self.fname) + log('toto') + -- make sure that our log file was created + f = io.open(self.fname, 'r') + lu.assertNotNil( f ) + f:close() + end + + function TestLogger:tearDown() + -- cleanup our log file after all tests + os.remove(self.fname) + end + +.. Note:: + + *Errors generated during execution of setUp() or tearDown() + functions are considered test failures.* + + +.. Note:: + + *For compatibility with luaunit v2 and other lua unit-test frameworks, + setUp() and tearDown() may also be named setup(), SetUp(), Setup() and teardown(), TearDown(), Teardown().* + + +Using the command-line +====================== + +You can control the LuaUnit execution from the command-line: + +**Output format** + +Choose the test output format with ``-o`` or ``--output``. Available formats are: + +* text: the default output format +* nil: no output at all +* tap: TAP format +* junit: output junit xml + +Example of non-verbose text format:: + + $ lua doc/my_test_suite.lua + ....... + Ran 7 tests in 0.003 seconds, 7 successes, 0 failures + OK + + +Example of TAP format:: + + $ lua doc/my_test_suite.lua -o TAP + 1..7 + # Started on 02/19/17 22:15:53 + # Starting class: TestAdd + ok 1 TestAdd.testAddError + ok 2 TestAdd.testAddPositive + ok 3 TestAdd.testAddZero + ok 4 TestAdd.testAdder + # Starting class: TestDiv + ok 5 TestDiv.testDivError + ok 6 TestDiv.testDivPositive + ok 7 TestDiv.testDivZero + # Ran 7 tests in 0.007 seconds, 7 successes, 0 failures + +For a more detailed overview of all formats and their verbosity see the section `Output formats`_ . + + +**List of tests to run** + +You can list some test names on the command-line to run only those tests. +The name must be the exact match of either the test table, the test function or the test table +and the test method. The option may be repeated. + +Example:: + + -- Run all TestAdd table tests and one test of TestDiv table. + $ lua doc/my_test_suite.lua TestAdd TestDiv.testDivError -v + Started on 02/19/17 22:15:53 + TestAdd.testAddError ... Ok + TestAdd.testAddPositive ... Ok + TestAdd.testAddZero ... Ok + TestAdd.testAdder ... Ok + TestDiv.testDivError ... Ok + ========================================================= + Ran 5 tests in 0.003 seconds, 5 successes, 0 failures + OK + +**Including / excluding tests** + +The most flexible approach for selecting tests to use the include and exclude functionality. +With ``--pattern`` or ``-p``, you can provide a lua pattern and only the tests that contain +the pattern will actually be run. + +Example:: + + -- Run all tests of zero testing and error testing + -- by using the magic character . + $ lua my_test_suite.lua -v -p Err.r -p Z.ro + +For our test suite, it gives the following output:: + + Started on 02/19/17 22:15:53 + TestAdd.testAddError ... Ok + TestAdd.testAddZero ... Ok + TestDiv.testDivError ... Ok + TestDiv.testDivZero ... Ok + ========================================================= + Ran 4 tests in 0.003 seconds, 4 successes, 0 failures, 3 non-selected + OK + +The number of tests ignored by the selection is printed, along +with the test result. The pattern can be any lua pattern. Be sure to exclude all magic +characters with % (like -+?*) and protect your pattern from the shell +interpretation by putting it in quotes. + +You can also exclude tests that match some patterns: + +Example:: + + -- Run all tests except zero testing and except error testing + $ lua my_test_suite.lua -v -x Error -x Zero + +For our test suite, it gives the following output:: + + Started on 02/19/17 22:29:45 + TestAdd.testAddPositive ... Ok + TestAdd.testAdder ... Ok + TestDiv.testDivPositive ... Ok + ========================================================= + Ran 3 tests in 0.003 seconds, 3 successes, 0 failures, 4 non-selected + OK + +You can also combine test selection and test exclusion. See `Flexible test selection`_ + +Conclusion +========== + +You now know enough of LuaUnit to start writing your test suite. Check +the reference documentation for a complete list of +assertions, command-line options and specific behavior. + + +Reference documentation +*********************** + +.. _luaunit-global-asserts: + +Enabling global or module-level functions +========================================= + +Versions of LuaUnit before version 3.1 would export all assertions functions to the global namespace. A typical +lua test file would look like this: + +.. code-block:: lua + + require('luaunit') + + TestToto = {} --class + + function TestToto:test1_withFailure() + local a = 1 + assertEquals( a , 1 ) + -- will fail + assertEquals( a , 2 ) + end + + [...] + +However, this is an obsolete practice in Lua. It is now recommended to keep all functions inside the module. Starting +from version 3.1 LuaUnit follows this practice and the code should be adapted to look like this: + +.. code-block:: lua + + -- the imported module must be stored + lu = require('luaunit') + + TestToto = {} --class + + function TestToto:test1_withFailure() + local a = 1 + lu.assertEquals( a , 1 ) + -- will fail + lu.assertEquals( a , 2 ) + end + + [...] + +If you prefer the old way, LuaUnit can continue to export assertions functions if you set the following +global variable **prior** to importing LuaUnit: + +.. code-block:: lua + + -- this works + EXPORT_ASSERT_TO_GLOBALS = true + require('luaunit') + + TestToto = {} --class + + function TestToto:test1_withFailure() + local a = 1 + assertEquals( a , 1 ) + -- will fail + assertEquals( a , 2 ) + end + + [...] + + +LuaUnit.run() function +====================== + +**Return value** + +Run your test suite with the following line:: + + os.exit(lu.LauaUnit.run()) + +The *run()* function returns the number of failures of the test suite. This is +good for an exit code, 0 meaning success. + + +**Arguments** + +If no arguments are supplied, it parses the command-line arguments of the script +and interpret them. If arguments are supplied to the function, they are parsed +instead of the command-line. It uses the same syntax. + +Example:: + + -- execute tests matching the 'withXY' pattern + os.exit(lu.LuaUnit.run('--pattern', 'withXY')) + + +**Choice of tests** + +If test names were supplied, only those +tests are executed. When test names are supplied as arguments, they don't have +to start with *test*, they are run anyway. + +If no test names were supplied, a general test collection process starts +under the following rules: + +* all variable starting with *test* or *Test* are scanned. +* if the variable is a function it is collected for testing +* if the variable is a table: + + * all keys starting with *test* or *Test* are collected (provided that they are functions) + * keys with name *setUp* and *tearDown* are also collected + +If one or more pattern were supplied, the test are then filtered according the +pattern(s). Only the test that match the pattern(s) are actually executed. + + +**setup and teardown** + +The function *setUp()* is executed before each test if it exists in the table. +The function *tearDown()* is executed after every test if it exists in the table. + +.. Note:: + *tearDown()* is always executed if it exists, even if there was a failure in the test or in the *setUp()* function. + Failures in *setUp()* or *tearDown()* are considered as a general test failures. + + +LuaUnit.runSuite() function +============================== + +If you want to keep the flexibility of the command-line parsing, but want to force +some parameters, like the output format, you must use a slightly different syntax:: + + runner = lu.LuaUnit.new() + runner:setOutputType("tap") + os.exit( runner:runSuite() ) + +*runSuite()* behaves like *run()* except that it must be started +with a LuaUnit instance as first argument, and it will use the LuaUnit +instance settings. + + +Command-line options +==================== + +Usage: lua [options] [testname1 [testname2] ...] + +**Test names** + +When no test names are supplied, all tests are collected. + +The syntax for supplying test names can be either: name of the function, name of the table +or [name of the table].[name of the function]. Only the supplied tests will be executed. + +Selecting tests with --pattern and --exclude is usually more flexible. See `Flexible test selection`_ + +**Options** + +--output, -o FORMAT Set output format to FORMAT. Possible values: text, tap, junit, nil . See `Output formats`_ +--name, -n FILENAME For junit format only, mandatory name of xml file. Ignored for other formats. +--pattern, -p PATTERN Execute all test names matching the Lua PATTERN. May be repeated to include severals patterns. See `Flexible test selection`_ +--exclude, -x PATTERN Exclude all test names matching the Lua PATTERN. May be repeated to exclude severals patterns. See `Flexible test selection`_ +--repeat, -r NUM Repeat all tests NUM times, e.g. to trigger the JIT. See `Other options`_ +--shuffle, -s Shuffle tests before running them. See `Other options`_ +--error, -e Stop on first error. See `Other options`_ +--failure, -f Stop on first failure or error. See `Other options`_ +--verbose, -v Increase verbosity +--quiet, -q Set verbosity to minimum +--help, -h Print help +--version Version information of LuaUnit + +Output formats +------------------ + +Choose the output format with the syntax ``-o FORMAT`` or ``--output FORMAT``. + +Formats available: + +* ``text``: the default output format of LuaUnit +* ``tap``: output compatible with the `Test Anything Protocol`_ +* ``junit``: output compatible with the *JUnit XML* format (used by many CI + platforms). The XML is written to the file provided with the ``--name`` or ``-n`` option. +* ``nil``: no output at all + +.. _Test Anything Protocol: http://testanything.org/ + +To demonstrate the different output formats, we will take the example of the `Getting started with LuaUnit`_ +section and add the following two failing cases: + +.. code-block:: lua + + TestWithFailures = {} + -- two failing tests + + function TestWithFailures:testFail1() + local a="toto" + local b="titi" + lu.assertEquals( a, b ) --oops, two values are not equal + end + + function TestWithFailures:testFail2() + local a=1 + local b='toto' + local c = a + b --oops, can not add string and numbers + return c + end + + +**Text format** + +By default, LuaUnit uses the output format TEXT, with minimum verbosity:: + + $ lua my_test_suite.lua + .......FE + Failed tests: + ------------- + 1) TestWithFailures.testFail1 + doc\my_test_suite_with_failures.lua:79: expected: "titi" + actual: "toto" + stack traceback: + doc\my_test_suite_with_failures.lua:79: in function 'TestWithFailures.testFail1' + + 2) TestWithFailures.testFail2 + doc\my_test_suite_with_failures.lua:85: attempt to perform arithmetic on local 'b' (a string value) + stack traceback: + [C]: in function 'xpcall' + + Ran 9 tests in 0.001 seconds, 7 successes, 1 failure, 1 error + +This format is heavily inspired by python unit-test library. One character is printed +for every test executed, a dot for a successful test, a **F** for a test with failure and +a **E** for a test with an error. + +At the end of the test suite execution, the details of the failures or errors are given, with an +informative message and a full stack trace. + +The last line sums up the number of test executed, successful, failed, in error and not selected if any. +When all tests are successful, a line with just OK is added:: + + $ lua doc\my_test_suite.lua + ....... + Ran 7 tests in 0.002 seconds, 7 successes, 0 failures + OK + + +The text format is also available as a more verbose version, by adding the ``--verbose`` flag:: + + $ lua doc\my_test_suite_with_failures.lua --verbose + Started on 02/20/17 21:47:21 + TestAdd.testAddError ... Ok + TestAdd.testAddPositive ... Ok + TestAdd.testAddZero ... Ok + TestAdd.testAdder ... Ok + TestDiv.testDivError ... Ok + TestDiv.testDivPositive ... Ok + TestDiv.testDivZero ... Ok + TestWithFailures.testFail1 ... FAIL + doc\my_test_suite_with_failures.lua:79: expected: "titi" + actual: "toto" + TestWithFailures.testFail2 ... ERROR + doc\my_test_suite_with_failures.lua:85: attempt to perform arithmetic on local 'b' (a string value) + ========================================================= + Failed tests: + ------------- + 1) TestWithFailures.testFail1 + doc\my_test_suite_with_failures.lua:79: expected: "titi" + actual: "toto" + stack traceback: + doc\my_test_suite_with_failures.lua:79: in function 'TestWithFailures.testFail1' + + 2) TestWithFailures.testFail2 + doc\my_test_suite_with_failures.lua:85: attempt to perform arithmetic on local 'b' (a string value) + stack traceback: + [C]: in function 'xpcall' + + Ran 9 tests in 0.008 seconds, 7 successes, 1 failure, 1 error + +In this format, you get: + +* a first line with date-time at which the test was started +* one line per test executed +* the test line is ended by **Ok**, **FAIL**, or **ERROR** in case the test is not successful +* a summary of the failed tests with all details, like in the compact version. + +This format is usually interesting if some tests print debug output, to match the output to the test. + +**JUNIT format** + +The Junit XML format was introduced by the `Java testing framework JUnit`_ and has been then used by many continuous +integration platform as an interoperability format between test suites and the platform. + +.. _Java testing framework JUnit: http://junit.org/junit4/ + +To output in the JUnit XML format, you use the format junit with ``--output junit`` and specify the XML filename with ``--name `` . On +the standard output, LuaUnit will print information about the test progress in a simple format. + +Let's see with a simple example:: + + $ lua my_test_suite_with_failures.lua -o junit -n toto.xml + # XML output to toto.xml + # Started on 02/24/17 09:54:59 + # Starting class: TestAdd + # Starting test: TestAdd.testAddError + # Starting test: TestAdd.testAddPositive + # Starting test: TestAdd.testAddZero + # Starting test: TestAdd.testAdder + # Starting class: TestDiv + # Starting test: TestDiv.testDivError + # Starting test: TestDiv.testDivPositive + # Starting test: TestDiv.testDivZero + # Starting class: TestWithFailures + # Starting test: TestWithFailures.testFail1 + # Failure: doc/my_test_suite_with_failures.lua:79: expected: "titi" + # actual: "toto" + # Starting test: TestWithFailures.testFail2 + # Error: doc/my_test_suite_with_failures.lua:85: attempt to perform arithmetic on local 'b' (a string value) + # Ran 9 tests in 0.007 seconds, 7 successes, 1 failure, 1 error + +On the standard output, you will see the date-time, the name of the XML file, one line for each test started, a summary +of the failure or errors when they occurs and the usual one line summary of the test execution: number of tests run, successful, failed, +in error and number of non selected tests if any. + +The XML file generated by this execution is the following:: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +As you can see, the XML file is quite rich in terms of information. The verbosity level has no effect on junit output, all verbosity give the same output. + +Slight inconsistencies exist in the exact XML format in the different continuous integration suites. LuaUnit provides a compatible output which +is validated against `Jenkins/Hudson schema`_ +and `Ant/Maven schema`_ . If you ever find an problem in the XML formats, please report a bug to us, more testing is always welcome. + +.. _Ant/Maven schema: https://github.com/bluebird75/luaunit/blob/LUAUNIT_V3_2_1/junitxml/junit-apache-ant.xsd +.. _Jenkins/Hudson schema: https://github.com/bluebird75/luaunit/blob/LUAUNIT_V3_2_1/junitxml/junit-jenkins.xsd + +**TAP format** + +The `TAP format`_ for test results has been around since 1988. LuaUnit produces TAP reports compatible with version 12 of +the specification. + +.. _`TAP format`: https://testanything.org/ + +Example with minimal verbosiy:: + + $ lua my_test_suite_with_failures.lua -o tap --quiet + 1..9 + # Started on 02/24/17 22:09:31 + # Starting class: TestAdd + ok 1 TestAdd.testAddError + ok 2 TestAdd.testAddPositive + ok 3 TestAdd.testAddZero + ok 4 TestAdd.testAdder + # Starting class: TestDiv + ok 5 TestDiv.testDivError + ok 6 TestDiv.testDivPositive + ok 7 TestDiv.testDivZero + # Starting class: TestWithFailures + not ok 8 TestWithFailures.testFail1 + not ok 9 TestWithFailures.testFail2 + # Ran 9 tests in 0.003 seconds, 7 successes, 1 failure, 1 error + +With minimal verbosity, you have one line for each test run, with the status of the test, and one comment line +when starting the test suite, when starting a new class or when finishing the test. + + +Example with default verbosiy:: + + $ lua my_test_suite_with_failures.lua -o tap + 1..9 + # Started on 02/24/17 22:09:31 + # Starting class: TestAdd + ok 1 TestAdd.testAddError + ok 2 TestAdd.testAddPositive + ok 3 TestAdd.testAddZero + ok 4 TestAdd.testAdder + # Starting class: TestDiv + ok 5 TestDiv.testDivError + ok 6 TestDiv.testDivPositive + ok 7 TestDiv.testDivZero + # Starting class: TestWithFailures + not ok 8 TestWithFailures.testFail1 + doc/my_test_suite_with_failures.lua:79: expected: "titi" + actual: "toto" + not ok 9 TestWithFailures.testFail2 + doc/my_test_suite_with_failures.lua:85: attempt to perform arithmetic on local 'b' (a string value) + # Ran 9 tests in 0.005 seconds, 7 successes, 1 failure, 1 error + +In the default mode, the failure or error message is displayed in the failing test diagnostic part. + +Example with full verbosiy:: + + $ lua my_test_suite_with_failures.lua -o tap --verbose + 1..9 + # Started on 02/24/17 22:09:31 + # Starting class: TestAdd + ok 1 TestAdd.testAddError + ok 2 TestAdd.testAddPositive + ok 3 TestAdd.testAddZero + ok 4 TestAdd.testAdder + # Starting class: TestDiv + ok 5 TestDiv.testDivError + ok 6 TestDiv.testDivPositive + ok 7 TestDiv.testDivZero + # Starting class: TestWithFailures + not ok 8 TestWithFailures.testFail1 + doc/my_test_suite_with_failures.lua:79: expected: "titi" + actual: "toto" + stack traceback: + doc/my_test_suite_with_failures.lua:79: in function 'TestWithFailures.testFail1' + not ok 9 TestWithFailures.testFail2 + doc/my_test_suite_with_failures.lua:85: attempt to perform arithmetic on local 'b' (a string value) + stack traceback: + [C]: in function 'xpcall' + # Ran 9 tests in 0.007 seconds, 7 successes, 1 failure, 1 error + +With maximum verbosity, the stack trace is also displayed in the test diagnostic. + +**NIL format** + +With the nil format output, absolutely nothing is displayed while running the tests. Only the +exit code of the command can tell whether the test was successful or not:: + + $ lua my_test_suite_with_failures.lua -o nil --verbose + $ + +This mode is used by LuaUnit for its internal validation. + + + +Other options +-------------- + +**Stopping on first error or failure** + +If ``--failure`` or ``-f`` is passed as an option, LuaUnit will stop on the first failure or error and display the test results. + +If ``--error`` or ``-e`` is passed as an option, LuaUnit will stop on the first error (but continue on failures). + +**Randomize test order** + +If ``--shuffle`` or ``-s`` is passed as an option, LuaUnit will execute tests in random order. The randomisation works on all test functions +and methods. As a consequence test methods of a given class may be splitted into multiple location, generating several test class creation and destruction. + +**Repeat test** + +When using luajit, the just-in-time compiler will kick in only after a given function has been executed a sufficient number of times. To make sure +that the JIT is not introducing any bug, LuaUnit provides a way to repeat a test may times, with ``--repeat`` or ``-r`` followed by a number. + +Flexible test selection +------------------------- + +LuaUnit provides very flexible way to select which tests to execute. We will illustrate this with several examples. + +In the examples, we use a test suite composed of the following test funcions:: + + -- class: TestAdd + TestAdd.testAddError + TestAdd.testAddPositive + TestAdd.testAddZero + TestAdd.testAdder + + -- class: TestDiv + TestDiv.testDivError + TestDiv.testDivPositive + TestDiv.testDivZero + + +With ``--pattern`` or ``-p``, you can provide a lua pattern and only the tests that contain +the pattern will actually be run. + +Example:: + + -- Run all tests of zero testing and error testing + -- by using the magic character . + $ lua mytest_suite.lua -v -p Err.r -p Z.ro + Started on 02/19/17 22:29:45 + TestAdd.testAddError ... Ok + TestAdd.testAddZero ... Ok + TestDiv.testDivError ... Ok + TestDiv.testDivZero ... Ok + ========================================================= + Ran 4 tests in 0.004 seconds, 4 successes, 0 failures, 3 non-selected + OK + +The number of tests ignored by the selection is printed, along +with the test result. The tests *TestAdd.testAdder testAdd.testPositive and +testDiv.testDivPositive* have been correctly ignored. + +The pattern can be any lua pattern. Be sure to exclude all magic +characters with % (like ``-+?*``) and protect your pattern from the shell +interpretation by putting it in quotes. + +With ``--exclude`` or ``-x``, you can provide a lua pattern of tests which should +be excluded from execution. + +Example:: + + -- Run all tests except zero testing and except error testing + $ lua mytest_suite.lua -v -x Error -x Zero + Started on 02/19/17 22:29:45 + TestAdd.testAddPositive ... Ok + TestAdd.testAdder ... Ok + TestDiv.testDivPositive ... Ok + ========================================================= + Ran 3 tests in 0.003 seconds, 3 successes, 0 failures, 4 non-selected + OK + +You can also combine test selection and test exclusion. The rules are the following: + +* if the first argument encountered is a inclusion pattern, the list of tests start empty +* if the first argument encountered is an exclusion pattern, the list of tests start with all tests of the suite +* each subsequent inclusion pattern will add new tests to the list +* each subsequent exclusion pattern will remove test from the list +* the final list is the list of tests executed + +In pure logic term, inclusion is the equivalent of ``or match(pattern)`` and exclusion is ``and not match(pattern)`` . + +Let's look at some practical examples:: + + -- Add all tests which include the word Add + -- except the test Adder + -- and also include the Zero tests + $ lua my_test_suite.lua -v --pattern Add --exclude Adder --pattern Zero + Started on 02/19/17 22:29:45 + TestAdd.testAddError ... Ok + TestAdd.testAddPositive ... Ok + TestAdd.testAddZero ... Ok + TestDiv.testDivZero ... Ok + ========================================================= + Ran 4 tests in 0.003 seconds, 4 successes, 0 failures, 3 non-selected + OK + + +Assertions functions +===================== +We will now list all assertion functions. For every functions, the failure +message tries to be as informative as possible, by displaying the expectation and value that caused the failure. It +relies on the :func:`prettystr` for printing nicely formatted values. + +All function accept an optional extra message which if provided, is printed along with the failure message. + +.. Note:: see :ref:`table-printing` and :ref:`comparing-table-keys-table` for more dealing with recursive tables and tables containing keys of type table. + + +Equality assertions +---------------------- +All equality assertions functions take two arguments, in the order +*actual value* then *expected value*. Some people are more familiar +with the order *expected value* then *actual value*. It is possible to configure +LuaUnit to use the opposite order for all equality assertions, by setting up a module +variable: + +.. code-block:: lua + + lu.ORDER_ACTUAL_EXPECTED=false + +The order only matters for the message that is displayed in case of failures. It does +not influence the test itself. + + +.. function:: assertEquals(actual, expected [, extra_msg] ) + + **Alias**: *assert_equals()* + + Assert that two values are equal. + + For tables, the comparison is a deep comparison : + + * number of elements must be the same + * tables must contain the same keys + * each key must contain the same values. The values + are also compared recursively with deep comparison. + + If provided, *extra_msg* is a string which will be printed along with the failure message. + + LuaUnit provides other table-related assertions, see :ref:`assert-table` . + + +.. function:: assertNotEquals(actual, expected [, extra_msg]) + + **Alias**: *assert_not_equals()* + + Assert that two values are different. The assertion + fails if the two values are identical. Like the previous function, it uses table deep comparison. + + If provided, *extra_msg* is a string which will be printed along with the failure message. + +Value assertions +---------------------- + +LuaUnit contains several flavours of true/false assertions, to be used in different contexts. +Usually, when asserting for *true* or *false*, you want strict assertions (*nil* should not +assert to *false*); *assertTrue()* and *assertFalse()* are the functions for this purpose. In some cases though, +you want Lua coercion rules to apply (e.g. value *1* or string *"hello"* yields *true*) and the right functions to use +are *assertEvalToTrue()* and *assertEvalToFalse()*. Finally, you have the *assertNotTrue()* and *assertNotFalse()* to verify +that a value is anything but the boolean *true* or *false*. + +The below table sums it up: + +============ ============ =================== ================ ============= =================== =============== +**True assertion family** **False assertion family** +----------------------------------------------------------------- --------------------------------------------------- +Input Value assertTrue() assertEvalToTrue() assertNotFalse() assertFalse() assertEvalToFalse() assertNotTrue() +============ ============ =================== ================ ============= =================== =============== +*true* OK OK OK Fail Fail Fail +*false* Fail Fail Fail OK OK OK +*nil* Fail Fail OK Fail OK OK +*0* Fail OK OK Fail Fail Fail +*1* Fail OK OK Fail Fail Fail +*"hello"* Fail OK OK Fail Fail Fail +============ ============ =================== ================ ============= =================== =============== + + + +.. function:: assertEvalToTrue(value [, extra_msg]) + + **Alias**: *assert_eval_to_true()* + + Assert that a given value evals to ``true``. Lua coercion rules are applied + so that values like ``0``, ``""``, ``1.17`` **succeed** in this assertion. If provided, + extra_msg is a string which will be printed along with the failure message. + + See :func:`assertTrue` for a strict assertion to boolean ``true``. + +.. function:: assertEvalToFalse(value [, extra_msg]) + + **Alias**: *assert_eval_to_false()* + + Assert that a given value eval to ``false``. Lua coercion rules are applied + so that ``nil`` and ``false`` **succeed** in this assertion. If provided, extra_msg + is a string which will be printed along with the failure message. + + See :func:`assertFalse` for a strict assertion to boolean ``false``. + +.. function:: assertTrue(value [, extra_msg]) + + **Alias**: *assert_true()* + + Assert that a given value is strictly ``true``. Lua coercion rules do not apply + so that values like ``0``, ``""``, ``1.17`` **fail** in this assertion. If provided, + extra_msg is a string which will be printed along with the failure message. + + See :func:`assertEvalToTrue` for an assertion to ``true`` where Lua coercion rules apply. + +.. function:: assertFalse(value [, extra_msg]) + + **Alias**: *assert_false()* + + Assert that a given value is strictly ``false``. Lua coercion rules do not apply + so that ``nil`` **fails** in this assertion. If provided, *extra_msg* is a string + which will be printed along with the failure message. + + See :func:`assertEvalToFalse` for an assertion to ``false`` where Lua coertion fules apply. + +.. function:: assertNil(value [, extra_msg]) + + **Aliases**: *assert_nil()*, *assertIsNil()*, *assert_is_nil()* + + Assert that a given value is *nil* . If provided, *extra_msg* is + a string which will be printed along with the failure message. + +.. function:: assertNotNil(value [, extra_msg]) + + **Aliases**: *assert_not_nil()*, *assertNotIsNil()*, *assert_not_is_nil()* + + Assert that a given value is not *nil* . Lua coercion rules are applied + so that values like ``0``, ``""``, ``false`` all validate the assertion. + If provided, *extra_msg* is a string which will be printed along with the failure message. + +.. function:: assertIs(actual, expected [, extra_msg]) + + **Alias**: *assert_is()* + + Assert that two variables are identical. For string, numbers, boolean and for nil, + this gives the same result as :func:`assertEquals` . For the other types, identity + means that the two variables refer to the same object. + If provided, *extra_msg* is a string which will be printed along with the failure message. + + **Example :** + +.. code-block:: lua + + s1='toto' + s2='to'..'to' + t1={1,2} + t2={1,2} + v1=nil + v2=false + + lu.assertIs(s1,s1) -- ok + lu.assertIs(s1,s2) -- ok + lu.assertIs(t1,t1) -- ok + lu.assertIs(t1,t2) -- fail + lu.assertIs(v1,v2) -- fail + +.. function:: assertNotIs(actual, expected [, extra_msg]) + + **Alias**: *assert_not_is()* + + Assert that two variables are not identical, in the sense that they do not + refer to the same value. If provided, *extra_msg* is a string which will be printed along with the failure message. + + See :func:`assertIs` for more details. + + +String assertions +-------------------------- + +Assertions related to string and patterns. + +.. function:: assertStrContains( str, sub [, isPattern [, extra_msg ]] ) + + **Alias**: *assert_str_contains()* + + Assert that the string *str* contains the substring or pattern *sub*. + If provided, *extra_msg* is a string which will be printed along with the failure message. + + By default, substring is searched in the string. If *isPattern* + is provided and is true, *sub* is treated as a pattern which + is searched inside the string *str* . + + +.. function:: assertStrIContains( str, sub [, extra_msg] ) + + **Alias**: *assert_str_icontains()* + + Assert that the string *str* contains the given substring *sub*, irrespective of the case. + If provided, *extra_msg* is a string which will be printed along with the failure message. + + Note that unlike :func:`assertStrcontains`, you can not search for a pattern. + + + +.. function:: assertNotStrContains( str, sub, [isPattern [, extra_msg]] ) + + **Alias**: *assert_not_str_contains()* + + Assert that the string *str* does not contain the substring or pattern *sub*. + If provided, *extra_msg* is a string which will be printed along with the failure message. + + By default, the substring is searched in the string. If *isPattern* + is provided and is true, *sub* is treated as a pattern which + is searched inside the string *str* . + + +.. function:: assertNotStrIContains( str, sub [, extra_msg] ) + + **Alias**: *assert_not_str_icontains()* + + Assert that the string *str* does not contain the substring *sub*, irrespective of the case. + If provided, *extra_msg* is a string which will be printed along with the failure message. + + Note that unlike :func:`assertNotStrcontains`, you can not search for a pattern. + + +.. function:: assertStrMatches( str, pattern [, start [, final [, extra_msg ]]] ) + + **Alias**: *assert_str_matches()* + + Assert that the string *str* matches the full pattern *pattern*. + + If *start* and *final* are not provided or are *nil*, the pattern must match the full string, from start to end. The + function allows to specify the expected start and end position of the pattern in the string. If provided, + *extra_msg* is a string which will be printed along with the failure message. + + +Error assertions +-------------------------- +Error related assertions, to verify error generation and error messages. + +.. function:: assertError( func, ...) + + **Alias**: *assert_error()* + + Assert that calling functions *func* with the arguments yields an error. If the + function does not yield an error, the assertion fails. + + Note that the error message itself is not checked, which means that this function + does not distinguish between the legitimate error that you expect and another error + that might be triggered by mistake. + + The next functions provide a better approach to error testing, by checking + explicitly the error message content. + +.. Note:: + + When testing LuaUnit, switching from *assertError()* to *assertErrorMsgEquals()* + revealed quite a few bugs! + +.. function:: assertErrorMsgEquals( expectedMsg, func, ... ) + + **Alias**: *assert_error_msg_equals()* + + Assert that calling function *func* will generate exactly the given error message. If the + function does not yield an error, or if the error message is not identical, the assertion fails. + + Be careful when using this function that error messages usually contain the file name and + line number information of where the error was generated. This is usually inconvenient. To + ignore the filename and line number information, you can either use a pattern with :func:`assertErrorMsgMatches` + or simply check for the message content with :func:`assertErrorMsgContains` . + +.. function:: assertErrorMsgContains( partialMsg, func, ... ) + + **Alias**: *assert_error_msg_contains()* + + Assert that calling function *func* will generate an error message containing *partialMsg* . If the + function does not yield an error, or if the expected message is not contained in the error message, the + assertion fails. + +.. function:: assertErrorMsgMatches( expectedPattern, func, ... ) + + **Alias**: *assert_error_msg_matches()* + + Assert that calling function *func* will generate an error message matching *expectedPattern* . If the + function does not yield an error, or if the error message does not match the provided patternm the + assertion fails. + + Note that matching is done from the start to the end of the error message. Be sure to escape magic all magic + characters with ``%`` (like ``-+.?*``) . + + +Type assertions +-------------------------- + + The following functions all perform type checking on their argument. If the + received value is not of the right type, the failure message will contain + the expected type, the received type and the received value to help you + identify better the problem. + +.. function:: assertIsNumber(value [, extra_msg]) + + **Aliases**: *assertNumber()*, *assert_is_number()*, *assert_number()* + + Assert that the argument is a number (integer or float). + If provided, *extra_msg* is a string which will be printed along with the failure message. + +.. function:: assertIsString(value [, extra_msg]) + + **Aliases**: *assertString()*, *assert_is_string()*, *assert_string()* + + Assert that the argument is a string. + If provided, *extra_msg* is a string which will be printed along with the failure message. + +.. function:: assertIsTable(value [, extra_msg]) + + **Aliases**: *assertTable()*, *assert_is_table()*, *assert_table()* + + Assert that the argument is a table. + If provided, *extra_msg* is a string which will be printed along with the failure message. + +.. function:: assertIsBoolean(value [, extra_msg]) + + **Aliases**: *assertBoolean()*, *assert_is_boolean()*, *assert_boolean()* + + Assert that the argument is a boolean. + If provided, *extra_msg* is a string which will be printed along with the failure message. + +.. function:: assertIsNil(value [, extra_msg]) + + **Aliases**: *assertNil()*, *assert_is_nil()*, *assert_nil()* + + Assert that the argument is nil. + If provided, *extra_msg* is a string which will be printed along with the failure message. + +.. function:: assertIsFunction(value [, extra_msg]) + + **Aliases**: *assertFunction()*, *assert_is_function()*, *assert_function()* + + Assert that the argument is a function. + If provided, *extra_msg* is a string which will be printed along with the failure message. + +.. function:: assertIsUserdata(value [, extra_msg]) + + **Aliases**: *assertUserdata()*, *assert_is_userdata()*, *assert_userdata()* + + Assert that the argument is a userdata. + If provided, *extra_msg* is a string which will be printed along with the failure message. + +.. function:: assertIsCoroutine(value [, extra_msg]) + + **Aliases**: *assertCoroutine()*, *assert_is_coroutine()*, *assert_coroutine()* + + Assert that the argument is a coroutine (an object with type *thread* ). + If provided, *extra_msg* is a string which will be printed along with the failure message. + +.. function:: assertIsThread(value [, extra_msg]) + + **Aliases**: *assertIsThread()*, *assertThread()*, *assert_is_thread()*, *assert_thread()* + + Same function as :func:assertIsCoroutine . Since Lua coroutines have the type thread, it's not + clear which name is the clearer, so we provide syntax for both names. + If provided, *extra_msg* is a string which will be printed along with the failure message. + + +.. _assert-table: + +Table assertions +-------------------------- + +.. function:: assertItemsEquals(actual, expected [, extra_msg]) + + **Alias**: *assert_items_equals()* + + Assert that two tables contain the same items, irrespective of their keys. + If provided, *extra_msg* is a string which will be printed along with the failure message. + + This function is practical for example if you want to compare two lists but + where items are not in the same order: + +.. code-block:: lua + + lu.assertItemsEquals( {1,2,3}, {3,2,1} ) -- assertion succeeds + +.. + + The comparison is not recursive on the items: if any of the items are tables, + they are compared using table equality (like as in :func:`assertEquals` ), where + the key matters. + + +.. code-block:: lua + + lu.assertItemsEquals( {1,{2,3},4}, {4,{3,2,},1} ) -- assertion fails because {2,3} ~= {3,2} + + + +Ending test +--------------------- + +LuaUnit allows to force test ending, either positevely or negatively, with the following functions. + +.. function:: fail( message ) + + Stops the ongoing test and mark it as failed with the given message. + + +.. function:: failIf( cond, message ) + + If the condition *cond* evaluates to *true*, stops the ongoing test and mark it as failed with the given message. + Else, continue the test execution normally. + +.. function:: success() + + Stops the ongoing test and mark it as successful. + +.. function:: successIf( cond ) + + If the condition *cond* evaluates to *true*, stops the ongoing test and mark it as successful. + Else, continue the test execution normally. + + +Scientific computing and LuaUnit +-------------------------------- + +LuaUnit is used by the CERN for the MAD-NG program, the forefront of computational physics in the field of particle accelerator design and simulation (See MAD_). Thank to the feedback of a scientific computing developer, LuaUnit has been enhanced with some facilities for scientific applications (see all assertions functions below). + +.. _MAD: http://mad.web.cern.ch/mad/ + +The floating point library used by Lua is the one provided by the C compiler which built Lua. It is usually compliant with IEEE-754_ . As such, +it can yields results such as *plus infinity*, *minus infinity* or *Not a Number* (NaN). The precision of any calculation performed in Lua is +related to the smallest representable floating point value (typically called *EPS*): 2^-52 for 64 bits floats (type double in the C language) and 2^-23 for 32 bits float +(type float in C). + +.. _IEEE-754: https://en.wikipedia.org/wiki/IEEE_754 + +.. Note :: Lua may be compiled with numbers represented either as 32 bits floats or 64 bits double (as defined by the macro LUA_FLOAT_TYPE in luaconf.h ). LuaUnit has been validated in both these configurations and in particuluar, the epsilon value *EPS* is adjusted accordingly. + +For more information about performing calculations on computers, please read the reference paper `What Every Computer Scientist Should Know About Floating-Point Arithmetic`_ + +.. _What Every Computer Scientist Should Know About Floating-Point Arithmetic: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html + +If your calculation shall be portable to multiple OS or compilers, you may get different calculation errors depending on the OS/compiler. It is therefore important to verify them on every target. + + +.. _MinusZero: + +.. Note:: + If you need to deal with value *minus zero*, be very careful because Lua versions are inconsistent on how they treat the syntax *-0* : it creates either + a *plus zero* or a *minus zero* . Multiplying or dividing *0* by *-1* also yields inconsistent results. The reliable way to create the *-0* + value is : minusZero = -1 / (1/0) + + +.. _EPS: + +**EPS** *constant* + +The machine epsilon, to be used with :func:`assertAlmostEquals` . + +This is either: + +* 2^-52 or ~2.22E-16 (with lua number defined as double) +* 2^-23 or ~1.19E-07 (with lua number defined as float) + + +.. function:: assertNan( value [, extra_msg]) + + **Alias**: *assert_nan()* + + Assert that a given number is a *NaN* (Not a Number), according to the definition of IEEE-754_ . + If provided, *extra_msg* is a string which will be printed along with the failure message. + + +.. function:: assertNotNan( value [, extra_msg]) + + **Alias**: *assert_not_nan()* + + Assert that a given number is NOT a *NaN* (Not a Number), according to the definition of IEEE-754_ . + If provided, *extra_msg* is a string which will be printed along with the failure message. + + +.. function:: assertPlusInf( value [, extra_msg]) + + **Alias**: *assert_plus_inf()* + + Assert that a given number is *plus infinity*, according to the definition of IEEE-754_ . + If provided, *extra_msg* is a string which will be printed along with the failure message. + + +.. function:: assertMinusInf( value [, extra_msg]) + + **Alias**: *assert_minus_inf()* + + Assert that a given number is *minus infinity*, according to the definition of IEEE-754_ . + If provided, *extra_msg* is a string which will be printed along with the failure message. + + +.. function:: assertInf( value [, extra_msg]) + + **Alias**: *assert_inf()* + + Assert that a given number is *infinity* (either positive or negative), according to the definition of IEEE-754_ . + If provided, *extra_msg* is a string which will be printed along with the failure message. + + +.. function:: assertNotPlusInf( value [, extra_msg]) + + **Alias**: *assert_not_plus_inf()* + + Assert that a given number is NOT *plus infinity*, according to the definition of IEEE-754_ . + If provided, *extra_msg* is a string which will be printed along with the failure message. + + +.. function:: assertNotMinusInf( value [, extra_msg]) + + **Alias**: *assert_not_minus_inf()* + + Assert that a given number is NOT *minus infinity*, according to the definition of IEEE-754_ . + If provided, *extra_msg* is a string which will be printed along with the failure message. + + +.. function:: assertNotInf( value [, extra_msg]) + + **Alias**: *assert_not_inf()* + + Assert that a given number is neither *infinity* nor *minus infinity*, according to the definition of IEEE-754_ . + If provided, *extra_msg* is a string which will be printed along with the failure message. + + +.. function:: assertPlusZero( value [, extra_msg]) + + **Alias**: *assert_plus_zero()* + + Assert that a given number is *+0*, according to the definition of IEEE-754_ . The + verification is done by dividing by the provided number and verifying that it yields + *infinity* . If provided, *extra_msg* is a string which will be printed along with the failure message. + + Be careful when dealing with *+0* and *-0*, see note above. + + +.. function:: assertMinusZero( value [, extra_msg]) + + **Alias**: *assert_minus_zero()* + + Assert that a given number is *-0*, according to the definition of IEEE-754_ . The + verification is done by dividing by the provided number and verifying that it yields + *minus infinity* . If provided, *extra_msg* is a string which will be printed along with the failure message. + + Be careful when dealing with *+0* and *-0*, see :ref:`MinusZero` + + +.. function:: assertNotPlusZero( value [, extra_msg]) + + **Alias**: *assert_not_plus_zero()* + + Assert that a given number is NOT *+0*, according to the definition of IEEE-754_ . + If provided, *extra_msg* is a string which will be printed along with the failure message. + + Be careful when dealing with *+0* and *-0*, see :ref:`MinusZero` + + +.. function:: assertNotMinusZero( value [, extra_msg]) + + **Alias**: *assert_not_minus_zero()* + + Assert that a given number is NOT *-0*, according to the definition of IEEE-754_ . + If provided, *extra_msg* is a string which will be printed along with the failure message. + + Be careful when dealing with *+0* and *-0*, see :ref:`MinusZero` + + +.. function:: assertAlmostEquals( actual, expected [, margin=EPS [, extra_msg]] ) + + **Alias**: *assert_almost_equals()* + + Assert that two floating point numbers are equal by the defined margin. + If margin is not provided, the machine epsilon *EPS* is used. + If provided, *extra_msg* is a string which will be printed along with the failure message. + + Be careful that depending on the calculation, it might make more sense to measure + the absolute error or the relative error (see below): + + +.. function:: assertNotAlmostEquals( actual, expected [, margin=EPS [, extra_msg]] ) + + **Alias**: *assert_not_almost_equals()* + + Assert that two floating point numbers are not equal by the defined margin. + If margin is not provided, the machine epsilon *EPS* is used. + If provided, *extra_msg* is a string which will be printed along with the failure message. + + Be careful that depending on the calculation, it might make more sense to measure + the absolute error or the relative error (see below). + +**Example of absolute versus relative error** + +.. code-block:: lua + + -- convert pi/6 radian to 30 degree + pi_div_6_deg_calculated = math.deg(math.pi/6) + pi_div_6_deg_expected = 30 + + -- convert pi/3 radian to 60 degree + pi_div_3_deg_calculated = math.deg(math.pi/3) + pi_div_3_deg_expected = 60 + + -- check absolute error: it is not constant + print( (pi_div_6_deg_expected - pi_div_6_deg_calculated) / lu.EPS ) -- prints: 16 + print( (pi_div_3_deg_expected - pi_div_3_deg_calculated) / lu.EPS ) -- prints: 32 + + -- Better use relative error: + print( ( (pi_div_6_deg_expected - pi_div_6_deg_calculated) / pi_div_6_deg_expected) / lu.EPS ) -- prints: 0.53333 + print( ( (pi_div_3_deg_expected - pi_div_3_deg_calculated) / pi_div_3_deg_expected) / lu.EPS ) -- prints: 0.53333 + + -- relative error is constant. Assertion can take the form of: + assertAlmostEquals( (pi_div_6_deg_expected - pi_div_6_deg_calculated) / pi_div_6_deg_expected, lu.EPS ) + assertAlmostEquals( (pi_div_3_deg_expected - pi_div_3_deg_calculated) / pi_div_3_deg_expected, lu.EPS ) + + +Pretty printing +---------------- + +.. function:: prettystr( value ) + + Converts *value* to a nicely formatted string, whatever the type of the value. + It supports in particular tables, nested table and even recursive tables. + + You can use it in your code to replace calls to *tostring()* . + +**Example of prettystr()** + +.. code-block:: lua + + > lu = require('luaunit') + > t1 = {1,2,3} + > t1['toto'] = 'titi' + > t1.f = function () end + > t1.fa = (1 == 0) + > t1.tr = (1 == 1) + > print( lu.prettystr(t1) ) + {1, 2, 3, f=function: 00635d68, fa=false, toto="titi", tr=true} + + + +Developing LuaUnit +****************** + +Development ecosystem +====================== + +LuaUnit is developed on `GitHub`_. + +.. _GitHub: https://github.com/bluebird75/luaunit + +Bugs or feature requests should be reported using `GitHub issues`_. + +.. _GitHub issues: https://github.com/bluebird75/luaunit/issues + +LuaUnit is released under the BSD license. + +This documentation is available at `Read-the-docs`_. + +.. _Read-the-docs: http://luaunit.readthedocs.org/en/latest/ + + +Contributing +============= +You may contribute to LuaUnit by reporting bugs or wishes, or by contributing code directly with a pull request. + +Some issues on GitHub are marked with label *enhancement*. Feel also free to pick up such tasks and implement them. + +Changes should be proposed as *Pull Requests* on GitHub. + +Thank to our continous integration setup with Travis-Ci and AppVeyor, all unit-tests and functional tests are run on Linux, Windows and MacOs, with all versions of Lua. So +any *Pull Request* will show immediatly if anything is going unexpected. + + +Unit-tests +------------------- +All proposed changes should pass all unit-tests and if needed, add more unit-tests to cover the bug or the new functionality. Usage is pretty simple: + +.. code-block:: shell + + $ lua run_unit_tests.lua + ................................................................................ + ............................... + Ran 111 tests in 0.120 seconds + OK + + +Functional tests +------------------- +Functional tests also exist to validate LuaUnit. Their management is slightly more complicated. + +The main goal of functional tests is to validate that LuaUnit output has not been altered. Since LuaUnit supports some standard compliant output (TAP, junitxml), this is very important (and it has been broken in the past) + +Functional tests perform the following actions: + +* Run the 2 suites: example_with_luaunit.lua, test_with_err_fail_pass.lua (with various options to have successe, failure and/or errors) +* Run every suite with all output format, all verbosity +* Validate the XML output with jenkins/hudson and junit schema +* Compare the results with the previous output ( archived in test/ref ), with some tricks to make the comparison possible : + + * adjustment of the file separator to use the same output on Windows and Unix + * date and test duration is zeroed so that it does not impact the comparison + * adjust the stack trace format which has changed between Lua 5.1, 5.2 and 5.3 + +* Run some legacy suites or tricky output to manage and verify output: test_with_xml.lua, , compat_luaunit_v2x.lua, legacy_example_with_luaunit.lua + + +For functional tests to run, *diff* must be available on the command line. *xmllint* is needed to perform the xml validation but +this step is skipped if *xmllint* can not be found. + +When functional tests work well, it looks like this: + +.. code-block:: shell + + $ lua run_functional_tests.lua + ............... + Ran 15 tests in 9.676 seconds + OK + + +When functional test fail, a diff of the comparison between the reference output and the current output is displayed (it can be quite +long). The list of faulty files is summed-up at the end. + +Modifying reference files for functional tests +----------------------------------------------- +The script run_functional_tests.lua supports a --update option, with an optional argument. + +* *--update* without argument **overwrites all reference output** with the current output. Use only if you know what you are doing, this is usually a very bad idea! + +* The following argument overwrite a specific subset of reference files, select the one that fits your change: + + * TestXml: XML output of test_with_xml + * ExampleXml: XML output of example_with_luaunit + * ExampleTap: TAP output of example_with_luaunit + * ExampleText: text output of example_with_luaunit + * ExampleNil: nil output of example_with_luaunit + * ErrFailPassText: text output of test_with_err_fail_pass + * ErrFailPassTap: TAP output of test_with_err_fail_pass + * ErrFailPassXml: XML output of test_with_err_fail_pass + * StopOnError: errFailPassTextStopOnError-1.txt, -2.txt, -3.txt, -4.txt + + +For example to record a change in the test_with_err_fail_pass output + +.. code-block:: shell + + $ lua run_functional_tests.lua --update ErrFailPassXml ErrFailPassTap ErrFailPassText + + >>>>>>> Generating test/ref/errFailPassXmlDefault.txt + >>>>>>> Generating test/ref/errFailPassXmlDefault-success.txt + >>>>>>> Generating test/ref/errFailPassXmlDefault-failures.txt + >>>>>>> Generating test/ref/errFailPassXmlQuiet.txt + >>>>>>> Generating test/ref/errFailPassXmlQuiet-success.txt + >>>>>>> Generating test/ref/errFailPassXmlQuiet-failures.txt + >>>>>>> Generating test/ref/errFailPassXmlVerbose.txt + >>>>>>> Generating test/ref/errFailPassXmlVerbose-success.txt + >>>>>>> Generating test/ref/errFailPassXmlVerbose-failures.txt + >>>>>>> Generating test/ref/errFailPassTapDefault.txt + >>>>>>> Generating test/ref/errFailPassTapDefault-success.txt + >>>>>>> Generating test/ref/errFailPassTapDefault-failures.txt + >>>>>>> Generating test/ref/errFailPassTapQuiet.txt + >>>>>>> Generating test/ref/errFailPassTapQuiet-success.txt + >>>>>>> Generating test/ref/errFailPassTapQuiet-failures.txt + >>>>>>> Generating test/ref/errFailPassTapVerbose.txt + >>>>>>> Generating test/ref/errFailPassTapVerbose-success.txt + >>>>>>> Generating test/ref/errFailPassTapVerbose-failures.txt + >>>>>>> Generating test/ref/errFailPassTextDefault.txt + >>>>>>> Generating test/ref/errFailPassTextDefault-success.txt + >>>>>>> Generating test/ref/errFailPassTextDefault-failures.txt + >>>>>>> Generating test/ref/errFailPassTextQuiet.txt + >>>>>>> Generating test/ref/errFailPassTextQuiet-success.txt + >>>>>>> Generating test/ref/errFailPassTextQuiet-failures.txt + >>>>>>> Generating test/ref/errFailPassTextVerbose.txt + >>>>>>> Generating test/ref/errFailPassTextVerbose-success.txt + >>>>>>> Generating test/ref/errFailPassTextVerbose-failures.txt + $ + +You can then commit the new files into git. + +.. Note :: how to commit updated reference outputs + + When committing those changes into git, please use if possible an + intelligent git committing tool to commit only the interesting changes. + With SourceTree for example, in case of XML changes, I can select only the + lines relevant to the change and avoid committing all the updates to test + duration and test datestamp. + + + +Typical failures for functional tests +--------------------------------------- + +Functional tests may start failing when: + +1. Increasing LuaUnit version +2. Improving or breaking LuaUnit output + +This a good place to start looking if you see failures occuring. + +Annexes +******** + +.. _table-printing: + +Annex A: More on table printing +================================ + +When asserting tables equality, by default, the table content is printed in case of failures. LuaUnit tries to print +tables in a readable format. It is +possible to always display the table id along with the content, by setting a module parameter PRINT_TABLE_REF_IN_ERROR_MSG . This +helps identifying tables: + +.. code-block:: lua + + local lu = require('luaunit') + + local t1 = {1,2,3} + -- normally, t1 is dispalyed as: "{1,2,3}" + + -- if setting this: + lu.PRINT_TABLE_REF_IN_ERROR_MSG = true + + -- display of table t1 becomes: " {1,2,3}" + + +.. Note :: table loops + + When displaying table content, it is possible to encounter loops, if for example two table references eachother. In such + cases, LuaUnit display the full table content once, along with the table id, and displays only the table id for the looping + reference. + +**Example:** displaying a table with reference loop + +.. code-block:: lua + + local t1 = {} + local t2 = {} + t1.t2 = t2 + t1.a = {1,2,3} + t2.t1 = t1 + + -- when displaying table t1: + -- table t1 inside t2 is only displayed by its id because t1 is already being displayed + -- table t2 is displayed along with its id because it is part of a loop. + -- t1: " { a={1,2,3}, t2= {t1=} }" + + +.. _comparing-table-keys-table: + +Annex B: Comparing tables with keys of type table +================================================== + + If provided, *extra_msg* is a string which will be printed along with the failure message. + + +This is a very uncommon scenario but there are a few programs out there which use tables as keys for other tables. LuaUnit has been adjusted to deal intelligently with this scenario. + +A small code block is worth a thousand pictures : + +.. code-block:: lua + + local lu = require('luaunit') + + -- let's define two tables + t1 = { 1, 2 } + t2 = { 1, 2 } + lu.assertEquals( t1, t2 ) -- succeeds + + -- let's define three tables, with the two above tables as keys + t3 = { t1='a' } + t4 = { t2='a' } + t5 = { t2='a' } + +There are two ways to treat comparison of tables t3 and t4: + +**Method 1: table keys are compared by content** + +* t3 contain one key: t1 +* t4 contain one key: t2, which has exactly the same content as t1 +* the two keys compare equally with assertEquals, so assertEquals( t3, t4 ) succeeds + +**Method 2: table keys are compared by reference** + +* t3 contain one key: t1 +* t4 contain one key: t2, which is not the same table as t1, its reference is different +* the two keys are different because t1 is a different object than t2 so assertEquals( t3, t4 ) fails + +Whether method 1 or method 2 is more appropriate is up for debate. + +LuaUnit has been adjusted to support both scenarios, with the config variable: *TABLE_EQUALS_KEYBYCONTENT* + +* TABLE_EQUALS_KEYBYCONTENT = true (default): method 1 - table keys compared by content +* TABLE_EQUALS_KEYBYCONTENT = false: method 2 - table keys compared by reference + +In any case, assertEquals( t4, t5 ) always succeeds. + +To adjust the config, change it into the luaunit table before running any tests: + + +.. code-block:: lua + + local lu = require('luaunit') + + -- define all your tests + -- ... + + lu.TABLE_EQUALS_KEYBYCONTENT = false + -- run your tests: + os.exit( lu.LuaUnit.run() ) + +.. _source-code-example: + +Annex C: Source code of example +================================= + +Source code of the example used in the `Getting started with LuaUnit`_ + +.. code-block:: lua + + -- + -- The examples described in the documentation are below. + -- + + lu = require('luaunit') + + function add(v1,v2) + -- add positive numbers + -- return 0 if any of the numbers are 0 + -- error if any of the two numbers are negative + if v1 < 0 or v2 < 0 then + error('Can only add positive or null numbers, received '..v1..' and '..v2) + end + if v1 == 0 or v2 == 0 then + return 0 + end + return v1+v2 + end + + function adder(v) + -- return a function that adds v to its argument using add + function closure( x ) return x+v end + return closure + end + + function div(v1,v2) + -- divide positive numbers + -- return 0 if any of the numbers are 0 + -- error if any of the two numbers are negative + if v1 < 0 or v2 < 0 then + error('Can only divide positive or null numbers, received '..v1..' and '..v2) + end + if v1 == 0 or v2 == 0 then + return 0 + end + return v1/v2 + end + + + + TestAdd = {} + function TestAdd:testAddPositive() + lu.assertEquals(add(1,1),2) + end + + function TestAdd:testAddZero() + lu.assertEquals(add(1,0),0) + lu.assertEquals(add(0,5),0) + lu.assertEquals(add(0,0),0) + end + + function TestAdd:testAddError() + lu.assertErrorMsgContains('Can only add positive or null numbers, received 2 and -3', add, 2, -3) + end + + function TestAdd:testAdder() + f = adder(3) + lu.assertIsFunction( f ) + lu.assertEquals( f(2), 5 ) + end + -- end of table TestAdd + + TestDiv = {} + function TestDiv:testDivPositive() + lu.assertEquals(div(4,2),2) + end + + function TestDiv:testDivZero() + lu.assertEquals(div(4,0),0) + lu.assertEquals(div(0,5),0) + lu.assertEquals(div(0,0),0) + end + + function TestDiv:testDivError() + lu.assertErrorMsgContains('Can only divide positive or null numbers, received 2 and -3', div, 2, -3) + end + -- end of table TestDiv + + --[[ + -- + -- Uncomment this section to see how failures are displayed + -- + TestWithFailures = {} + -- two failing tests + + function TestWithFailures:testFail1() + lu.assertEquals( "toto", "titi") + end + + function TestWithFailures:testFail2() + local a=1 + local b='toto' + local c = a + b -- oops, can not add string and numbers + return c + end + -- end of table TestWithFailures + ]] + + + --[[ + TestLogger = {} + function TestLogger:setUp() + -- define the fname to use for logging + self.fname = 'mytmplog.log' + -- make sure the file does not already exists + os.remove(self.fname) + end + + function TestLogger:testLoggerCreatesFile() + initLog(self.fname) + log('toto') + f = io.open(self.fname, 'r') + lu.assertNotNil( f ) + f:close() + end + + function TestLogger:tearDown() + self.fname = 'mytmplog.log' + -- cleanup our log file after all tests + os.remove(self.fname) + end + -- end of table TestLogger + + ]] + + os.exit(lu.LuaUnit.run()) + + + + +Annex D: BSD License +==================== + + This software is distributed under the BSD License. + + Copyright (c) 2005-2018, Philippe Fremy + + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +Index and Search page +********************** + +* :ref:`genindex` +* :ref:`search` + diff -Nru lua-unit-3.2/doc/make.bat lua-unit-3.3/doc/make.bat --- lua-unit-3.2/doc/make.bat 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/doc/make.bat 2018-04-20 12:34:12.000000000 +0000 @@ -1,242 +1,241 @@ -@ECHO OFF - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set BUILDDIR=_build -set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . -set I18NSPHINXOPTS=%SPHINXOPTS% . -if NOT "%PAPER%" == "" ( - set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% - set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% -) - -if "%1" == "" goto help - -if "%1" == "help" ( - :help - echo.Please use `make ^` where ^ is one of - echo. html to make standalone HTML files - echo. dirhtml to make HTML files named index.html in directories - echo. singlehtml to make a single large HTML file - echo. pickle to make pickle files - echo. json to make JSON files - echo. htmlhelp to make HTML files and a HTML help project - echo. qthelp to make HTML files and a qthelp project - echo. devhelp to make HTML files and a Devhelp project - echo. epub to make an epub - echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter - echo. text to make text files - echo. man to make manual pages - echo. texinfo to make Texinfo files - echo. gettext to make PO message catalogs - echo. changes to make an overview over all changed/added/deprecated items - echo. xml to make Docutils-native XML files - echo. pseudoxml to make pseudoxml-XML files for display purposes - echo. linkcheck to check all external links for integrity - echo. doctest to run all doctests embedded in the documentation if enabled - goto end -) - -if "%1" == "clean" ( - for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i - del /q /s %BUILDDIR%\* - goto end -) - - -%SPHINXBUILD% 2> nul -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) - -if "%1" == "html" ( - %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/html. - goto end -) - -if "%1" == "dirhtml" ( - %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. - goto end -) - -if "%1" == "singlehtml" ( - %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. - goto end -) - -if "%1" == "pickle" ( - %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can process the pickle files. - goto end -) - -if "%1" == "json" ( - %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can process the JSON files. - goto end -) - -if "%1" == "htmlhelp" ( - %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can run HTML Help Workshop with the ^ -.hhp project file in %BUILDDIR%/htmlhelp. - goto end -) - -if "%1" == "qthelp" ( - %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; now you can run "qcollectiongenerator" with the ^ -.qhcp project file in %BUILDDIR%/qthelp, like this: - echo.^> qcollectiongenerator %BUILDDIR%\qthelp\LuaUnit.qhcp - echo.To view the help file: - echo.^> assistant -collectionFile %BUILDDIR%\qthelp\LuaUnit.ghc - goto end -) - -if "%1" == "devhelp" ( - %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. - goto end -) - -if "%1" == "epub" ( - %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The epub file is in %BUILDDIR%/epub. - goto end -) - -if "%1" == "latex" ( - %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex - if errorlevel 1 exit /b 1 - echo. - echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. - goto end -) - -if "%1" == "latexpdf" ( - %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex - cd %BUILDDIR%/latex - make all-pdf - cd %BUILDDIR%/.. - echo. - echo.Build finished; the PDF files are in %BUILDDIR%/latex. - goto end -) - -if "%1" == "latexpdfja" ( - %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex - cd %BUILDDIR%/latex - make all-pdf-ja - cd %BUILDDIR%/.. - echo. - echo.Build finished; the PDF files are in %BUILDDIR%/latex. - goto end -) - -if "%1" == "text" ( - %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The text files are in %BUILDDIR%/text. - goto end -) - -if "%1" == "man" ( - %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The manual pages are in %BUILDDIR%/man. - goto end -) - -if "%1" == "texinfo" ( - %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. - goto end -) - -if "%1" == "gettext" ( - %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The message catalogs are in %BUILDDIR%/locale. - goto end -) - -if "%1" == "changes" ( - %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes - if errorlevel 1 exit /b 1 - echo. - echo.The overview file is in %BUILDDIR%/changes. - goto end -) - -if "%1" == "linkcheck" ( - %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck - if errorlevel 1 exit /b 1 - echo. - echo.Link check complete; look for any errors in the above output ^ -or in %BUILDDIR%/linkcheck/output.txt. - goto end -) - -if "%1" == "doctest" ( - %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest - if errorlevel 1 exit /b 1 - echo. - echo.Testing of doctests in the sources finished, look at the ^ -results in %BUILDDIR%/doctest/output.txt. - goto end -) - -if "%1" == "xml" ( - %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The XML files are in %BUILDDIR%/xml. - goto end -) - -if "%1" == "pseudoxml" ( - %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml - if errorlevel 1 exit /b 1 - echo. - echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. - goto end -) - -:end +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + +%SPHINXBUILD% 1> nul 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\LuaUnit.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\LuaUnit.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %BUILDDIR%/.. + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end diff -Nru lua-unit-3.2/doc/Makefile lua-unit-3.3/doc/Makefile --- lua-unit-3.2/doc/Makefile 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/doc/Makefile 2018-04-20 12:34:12.000000000 +0000 @@ -1,177 +1,177 @@ -# Makefile for Sphinx documentation -# - -# You can set these variables from the command line. -SPHINXOPTS = -SPHINXBUILD = sphinx-build -PAPER = -BUILDDIR = _build - -# User-friendly check for sphinx-build -ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) -$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) -endif - -# Internal variables. -PAPEROPT_a4 = -D latex_paper_size=a4 -PAPEROPT_letter = -D latex_paper_size=letter -ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . -# the i18n builder cannot share the environment and doctrees with the others -I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . - -.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext - -help: - @echo "Please use \`make ' where is one of" - @echo " html to make standalone HTML files" - @echo " dirhtml to make HTML files named index.html in directories" - @echo " singlehtml to make a single large HTML file" - @echo " pickle to make pickle files" - @echo " json to make JSON files" - @echo " htmlhelp to make HTML files and a HTML help project" - @echo " qthelp to make HTML files and a qthelp project" - @echo " devhelp to make HTML files and a Devhelp project" - @echo " epub to make an epub" - @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" - @echo " latexpdf to make LaTeX files and run them through pdflatex" - @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" - @echo " text to make text files" - @echo " man to make manual pages" - @echo " texinfo to make Texinfo files" - @echo " info to make Texinfo files and run them through makeinfo" - @echo " gettext to make PO message catalogs" - @echo " changes to make an overview of all changed/added/deprecated items" - @echo " xml to make Docutils-native XML files" - @echo " pseudoxml to make pseudoxml-XML files for display purposes" - @echo " linkcheck to check all external links for integrity" - @echo " doctest to run all doctests embedded in the documentation (if enabled)" - -clean: - rm -rf $(BUILDDIR)/* - -html: - $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." - -dirhtml: - $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml - @echo - @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." - -singlehtml: - $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml - @echo - @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." - -pickle: - $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle - @echo - @echo "Build finished; now you can process the pickle files." - -json: - $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json - @echo - @echo "Build finished; now you can process the JSON files." - -htmlhelp: - $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp - @echo - @echo "Build finished; now you can run HTML Help Workshop with the" \ - ".hhp project file in $(BUILDDIR)/htmlhelp." - -qthelp: - $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp - @echo - @echo "Build finished; now you can run "qcollectiongenerator" with the" \ - ".qhcp project file in $(BUILDDIR)/qthelp, like this:" - @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/LuaUnit.qhcp" - @echo "To view the help file:" - @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/LuaUnit.qhc" - -devhelp: - $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp - @echo - @echo "Build finished." - @echo "To view the help file:" - @echo "# mkdir -p $$HOME/.local/share/devhelp/LuaUnit" - @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/LuaUnit" - @echo "# devhelp" - -epub: - $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub - @echo - @echo "Build finished. The epub file is in $(BUILDDIR)/epub." - -latex: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo - @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." - @echo "Run \`make' in that directory to run these through (pdf)latex" \ - "(use \`make latexpdf' here to do that automatically)." - -latexpdf: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo "Running LaTeX files through pdflatex..." - $(MAKE) -C $(BUILDDIR)/latex all-pdf - @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." - -latexpdfja: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex - @echo "Running LaTeX files through platex and dvipdfmx..." - $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja - @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." - -text: - $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text - @echo - @echo "Build finished. The text files are in $(BUILDDIR)/text." - -man: - $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man - @echo - @echo "Build finished. The manual pages are in $(BUILDDIR)/man." - -texinfo: - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo - @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." - @echo "Run \`make' in that directory to run these through makeinfo" \ - "(use \`make info' here to do that automatically)." - -info: - $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo - @echo "Running Texinfo files through makeinfo..." - make -C $(BUILDDIR)/texinfo info - @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." - -gettext: - $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale - @echo - @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." - -changes: - $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes - @echo - @echo "The overview file is in $(BUILDDIR)/changes." - -linkcheck: - $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck - @echo - @echo "Link check complete; look for any errors in the above output " \ - "or in $(BUILDDIR)/linkcheck/output.txt." - -doctest: - $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest - @echo "Testing of doctests in the sources finished, look at the " \ - "results in $(BUILDDIR)/doctest/output.txt." - -xml: - $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml - @echo - @echo "Build finished. The XML files are in $(BUILDDIR)/xml." - -pseudoxml: - $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml - @echo - @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/LuaUnit.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/LuaUnit.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/LuaUnit" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/LuaUnit" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff -Nru lua-unit-3.2/doc/my_test_suite.lua lua-unit-3.3/doc/my_test_suite.lua --- lua-unit-3.2/doc/my_test_suite.lua 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/doc/my_test_suite.lua 2018-04-20 12:34:12.000000000 +0000 @@ -0,0 +1,127 @@ + +-- +-- The examples described in the documentation are below. +-- + +lu = require('luaunit') + +function add(v1,v2) + -- add positive numbers + -- return 0 if any of the numbers are 0 + -- error if any of the two numbers are negative + if v1 < 0 or v2 < 0 then + error('Can only add positive or null numbers, received '..v1..' and '..v2) + end + if v1 == 0 or v2 == 0 then + return 0 + end + return v1+v2 +end + +function adder(v) + -- return a function that adds v to its argument using add + function closure( x ) return x+v end + return closure +end + +function div(v1,v2) + -- divide positive numbers + -- return 0 if any of the numbers are 0 + -- error if any of the two numbers are negative + if v1 < 0 or v2 < 0 then + error('Can only divide positive or null numbers, received '..v1..' and '..v2) + end + if v1 == 0 or v2 == 0 then + return 0 + end + return v1/v2 +end + + + +TestAdd = {} + function TestAdd:testAddPositive() + lu.assertEquals(add(1,1),2) + end + + function TestAdd:testAddZero() + lu.assertEquals(add(1,0),0) + lu.assertEquals(add(0,5),0) + lu.assertEquals(add(0,0),0) + end + + function TestAdd:testAddError() + lu.assertErrorMsgContains('Can only add positive or null numbers, received 2 and -3', add, 2, -3) + end + + function TestAdd:testAdder() + f = adder(3) + lu.assertIsFunction( f ) + lu.assertEquals( f(2), 5 ) + end +-- end of table TestAdd + +TestDiv = {} + function TestDiv:testDivPositive() + lu.assertEquals(div(4,2),2) + end + + function TestDiv:testDivZero() + lu.assertEquals(div(4,0),0) + lu.assertEquals(div(0,5),0) + lu.assertEquals(div(0,0),0) + end + + function TestDiv:testDivError() + lu.assertErrorMsgContains('Can only divide positive or null numbers, received 2 and -3', div, 2, -3) + end +-- end of table TestDiv + +--[[ +-- +-- Uncomment this section to see how failures are displayed +-- +TestWithFailures = {} + -- two failing tests + + function TestWithFailures:testFail1() + lu.assertEquals( "toto", "titi") + end + + function TestWithFailures:testFail2() + local a=1 + local b='toto' + local c = a + b -- oops, can not add string and numbers + return c + end +-- end of table TestWithFailures +]] + + +--[[ +TestLogger = {} + function TestLogger:setUp() + -- define the fname to use for logging + self.fname = 'mytmplog.log' + -- make sure the file does not already exists + os.remove(self.fname) + end + + function TestLogger:testLoggerCreatesFile() + initLog(self.fname) + log('toto') + f = io.open(self.fname, 'r') + lu.assertNotNil( f ) + f:close() + end + + function TestLogger:tearDown() + self.fname = 'mytmplog.log' + -- cleanup our log file after all tests + os.remove(self.fname) + end +-- end of table TestLogger + +]] + +os.exit(lu.LuaUnit.run()) diff -Nru lua-unit-3.2/doc/test_something.lua lua-unit-3.3/doc/test_something.lua --- lua-unit-3.2/doc/test_something.lua 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/doc/test_something.lua 1970-01-01 00:00:00.000000000 +0000 @@ -1,101 +0,0 @@ - -luaunit = require('luaunit') - -function add(v1,v2) - -- add positive numbers - -- return 0 if any of the numbers are 0 - -- error if any of the two numbers are negative - if v1 < 0 or v2 < 0 then - error('Can only add positive or null numbers, received '..v1..' and '..v2) - end - if v1 == 0 or v2 == 0 then - return 0 - end - return v1+v2 -end - -function adder(v) - -- return a function that adds v to its argument using add - function closure( x ) return x+v end - return closure -end - -function div(v1,v2) - -- divide positive numbers - -- return 0 if any of the numbers are 0 - -- error if any of the two numbers are negative - if v1 < 0 or v2 < 0 then - error('Can only divide positive or null numbers, received '..v1..' and '..v2) - end - if v1 == 0 or v2 == 0 then - return 0 - end - return v1/v2 -end - - - -TestAdd = {} - function TestAdd:testAddPositive() - luaunit.assertEquals(add(1,1),2) - end - - function TestAdd:testAddZero() - luaunit.assertEquals(add(1,0),0) - luaunit.assertEquals(add(0,5),0) - luaunit.assertEquals(add(0,0),0) - end - - function TestAdd:testAddError() - luaunit.assertErrorMsgContains('Can only add positive or null numbers, received 2 and -3', add, 2, -3) - end - - function TestAdd:testAdder() - f = adder(3) - luaunit.assertIsFunction( f ) - luaunit.assertEquals( f(2), 5 ) - end --- end of table TestAdd - -TestDiv = {} - function TestDiv:testDivPositive() - luaunit.assertEquals(div(4,2),2) - end - - function TestDiv:testDivZero() - luaunit.assertEquals(div(4,0),0) - luaunit.assertEquals(div(0,5),0) - luaunit.assertEquals(div(0,0),0) - end - - function TestDiv:testDivError() - luaunit.assertErrorMsgContains('Can only divide positive or null numbers, received 2 and -3', div, 2, -3) - end - ---[[ -TestLogger = {} - function TestLogger:setUp() - -- define the fname to use for logging - self.fname = 'mytmplog.log' - -- make sure the file does not already exists - os.remove(self.fname) - end - - function TestLogger:testLoggerCreatesFile() - initLog(self.fname) - log('toto') - f = io.open(self.fname, 'r') - luaunit.assertNotNil( f ) - f:close() - end - - function TestLogger:tearDown() - self.fname = 'mytmplog.log' - -- cleanup our log file after all tests - os.remove(self.fname) - end - --- end of table TestDiv -]] - -os.exit(luaunit.LuaUnit.run()) \ No newline at end of file diff -Nru lua-unit-3.2/doit.py lua-unit-3.3/doit.py --- lua-unit-3.2/doit.py 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/doit.py 2018-04-20 12:35:02.000000000 +0000 @@ -1,121 +1,226 @@ -import subprocess, sys, os, shutil, os.path, optparse - -VERSION='3.2' -RELEASE_NAME='luaunit-%s' % VERSION -RELEASE_DIR='release/' + RELEASE_NAME + '/' -TARGET_ZIP=RELEASE_NAME + '.zip' -TARGET_TGZ=RELEASE_NAME + '.tgz' -REPO_PATH='d:/work/luaunit/luaunit-git/luaunit2/' - -# LUA50='d:/program/dev/lua/lua50/lua50.exe' -LUA51='d:/program/dev/lua/lua51/lua51.exe' -LUA52='d:/program/dev/lua/lua52/lua52.exe' -LUA53='d:/program/dev/lua/lua53/lua53.exe' - -ALL_LUA = ( - (LUA53, 'lua 5.3'), - (LUA52, 'lua 5.2'), - (LUA51, 'lua 5.1'), -# (LUA50, 'lua 5.0'), -) - -os.environ["nodosfilewarning"] = "1" - -def report( s ): - print '[[[[[[[[[[[[[ %s ]]]]]]]]]]]]]' % s - -def run_tests(): - '''Run tests with all versions of lua''' - for lua, luaversion in ALL_LUA: - report( 'Running unit-tests tests with %s' % luaversion ) - retcode = subprocess.call( [lua, 'run_unit_tests.lua'] ) - if retcode != 0: - report( 'Invalid retcode when running tests: %d' % retcode ) - sys.exit( retcode ) - report( 'Running functional tests tests with %s' % luaversion ) - retcode = subprocess.call( [lua, 'run_functional_tests.lua'] ) - if retcode != 0: - report( 'Invalid retcode when running tests: %d' % retcode ) - sys.exit( retcode ) - report( 'All tests succeed!' ) - -def run_example(): - for lua, luaversion in ALL_LUA: - report( 'Running examples with %s' % luaversion ) - retcode = subprocess.call( [lua, 'example_with_luaunit.lua'] ) - if retcode != 12: - report( 'Invalid retcode when running examples: %d' % retcode ) - sys.exit( retcode ) - report( 'All examples ran!' ) - - -def packageit(): - shutil.rmtree('release', True) - try: - os.mkdir('release') - except OSError: - pass - subprocess.check_call(['d:/program/utils/Git/bin/git.exe', 'clone', '--no-hardlinks', REPO_PATH, RELEASE_DIR]) - os.chdir( RELEASE_DIR ) - - # Release dir cleanup - shutil.rmtree('.git') - os.unlink('.gitignore') - run_tests() - run_example() - makedoc() - shutil.rmtree('doc/_build') - - # Packaging - os.chdir('..') - report('Start packaging') - shutil.make_archive(RELEASE_NAME, 'zip', root_dir='.', base_dir=RELEASE_NAME ) - shutil.make_archive(RELEASE_NAME, 'gztar', root_dir='.', base_dir=RELEASE_NAME ) - report('Zip and tgz ready!') - -def help(): - print( 'Available actions:') - for opt in OptToFunc: - print '\t%s' % opt - -def makedoc(): - os.chdir('doc') - if os.path.exists('html'): - shutil.rmtree('html') - subprocess.check_call(['make.bat', 'html']) - shutil.copytree('_build/html', 'html') - os.chdir('..') - -def install(): - installpath = '/usr/local/share/lua/' - for lua, luaversion in ALL_LUA: - lua,ver = luaversion.split( ) - if os.path.exists(installpath+ver): - shutil.copy('luaunit.lua',installpath+ver) - - - -OptToFunc = { - 'runtests' : run_tests, - 'runexample' : run_example, - 'packageit' : packageit, - 'makedoc' : makedoc, - 'install' : install, - 'help' : help, -} - -if __name__ == '__main__': - doingNothing = True - for arg in sys.argv[1:]: - if OptToFunc.has_key(arg): - doingNothing = False - OptToFunc[arg]() - else: - print 'No such action :', arg - sys.exit(-1) - - if doingNothing: - help() - - - +# My universal runner for this project, the equivalent of a Makefile +import subprocess, sys, os, shutil, os.path, optparse, glob + +VERSION='3.3' +RELEASE_NAME='luaunit-%s' % VERSION +ROCK_RELEASE_NAME='rock-%s' % RELEASE_NAME +RELEASE_DIR='release/' + RELEASE_NAME + '/' +RELEASE_TAG='LUAUNIT_V3_3' +TARGET_ZIP=RELEASE_NAME + '.zip' +TARGET_TGZ=RELEASE_NAME + '.tgz' +REPO_PATH='d:/work/luaunit/luaunit-git/luaunit3/' + +# LUA50='d:/program/dev/lua/lua50/lua50.exe' +LUA51='d:/program/dev/lua/lua51/lua51.exe' +LUA52='d:/program/dev/lua/lua52/lua52.exe' +LUA53='d:/program/dev/lua/lua53/lua53.exe' +LUAJIT='d:/program/dev/lua/luajit/luajit.exe' + +ALL_LUA = ( + (LUA53, 'lua 5.3'), + (LUA52, 'lua 5.2'), + (LUA51, 'lua 5.1'), + (LUAJIT, 'lua JIT'), +# (LUA50, 'lua 5.0'), no longer supported... +) + +os.environ["nodosfilewarning"] = "1" + +def report( s ): + print( '[[[[[[[[[[[[[ %s ]]]]]]]]]]]]]' % s ) + +def run_unit_tests(): + '''Run unit-tests with all versions of lua''' + for lua, luaversion in ALL_LUA: + report( 'Running unit-tests tests with %s' % luaversion ) + retcode = subprocess.call( [lua, 'run_unit_tests.lua'] ) + if retcode != 0: + report( 'Invalid retcode when running tests: %d' % retcode ) + sys.exit( retcode ) + +def run_tests(): + '''Run tests with all versions of lua''' + run_unit_tests() + + for lua, luaversion in ALL_LUA: + report( 'Running functional tests tests with %s' % luaversion ) + retcode = subprocess.call( [lua, 'run_functional_tests.lua'] ) + if retcode != 0: + report( 'Invalid retcode when running tests: %d' % retcode ) + sys.exit( retcode ) + + run_luacheck() + report( 'All tests succeed!' ) + +def run_luacheck(): + report('Running luacheck') + retcode = subprocess.call( ['luacheck.bat', '*.lua', 'test' ] ) + if retcode != 0: + report( 'Invalid luacheck result' ) + sys.exit( retcode ) + +def run_example(): + for lua, luaversion in ALL_LUA: + report( 'Running examples with %s' % luaversion ) + retcode = subprocess.call( [lua, 'example_with_luaunit.lua'] ) + if retcode != 12: + report( 'Invalid retcode when running examples: %d' % retcode ) + sys.exit( retcode ) + report( 'All examples ran!' ) + +def pre_packageit_or_buildrock_step1(): + # shutil.rmtree('release', True) + try: + os.mkdir('release') + except OSError: + pass + subprocess.check_call(['d:/program/utils/Git/bin/git.exe', 'clone', '--no-hardlinks', '--branch', RELEASE_TAG, REPO_PATH, RELEASE_DIR]) + + os.chdir( RELEASE_DIR ) + + # Release dir cleanup. + shutil.rmtree('.git') + os.unlink('.gitignore') + shutil.rmtree('.travis') + os.unlink('.travis.yml') + shutil.rmtree('.appveyor') + os.unlink('appveyor.yml') + os.unlink('doit.py') + os.unlink('TODO.txt') + shutil.rmtree('junitxml/') + + for p in glob.glob('*.rockspec'): + os.unlink(p) + + makedoc() + # doc cleanup and simplification + os.rename( 'doc', 'olddoc' ) + shutil.copytree( 'olddoc/html', 'doc') + os.unlink('doc/.buildinfo') + shutil.copy( 'olddoc/my_test_suite.lua', 'doc') + shutil.rmtree('olddoc/') + + run_tests() + run_example() + os.unlink('.luacheckrc') # keep it to run the tests successfully + +def packageit(): + # Prepare a user release package, strip out all development stuff + pre_packageit_or_buildrock_step1() + + # Packaging into zip and tgz + os.chdir('..') + report('Start packaging') + shutil.make_archive(RELEASE_NAME, 'zip', root_dir='.', base_dir=RELEASE_NAME ) + shutil.make_archive(RELEASE_NAME, 'gztar', root_dir='.', base_dir=RELEASE_NAME ) + report('Zip and tgz ready!') + +def buildrock(): + pre_packageit_or_buildrock_step1() + + # Packaging into source rocks + report('Start preparing rock') + shutil.move('test/test_luaunit.lua', '.') + shutil.rmtree('test') + os.mkdir('test') + shutil.move('test_luaunit.lua', 'test') + shutil.move('run_unit_tests.lua', 'test') + + for p in glob.glob('*.lua'): + if p == 'luaunit.lua': + continue + os.unlink(p) + os.unlink('README.md') + os.unlink('LICENSE.txt') + + os.chdir('..') + shutil.move( RELEASE_NAME, ROCK_RELEASE_NAME ) + shutil.make_archive( ROCK_RELEASE_NAME, 'zip', root_dir='.', base_dir=ROCK_RELEASE_NAME ) + + +def help(): + print( 'Available actions:') + for opt in sorted(OptToFunc.keys()): + print( '\t%s' % opt ) + +def makedoc(): + os.chdir('doc') + if os.path.exists('html'): + shutil.rmtree('html') + subprocess.check_call(['make.bat', 'html']) + shutil.copytree('_build/html', 'html') + os.chdir('..') + +def rundoctests(): + lua = LUA52 + for expretcode, l in ( + (0, [ '-e', "lu = require('luaunit');os.exit(lu.LuaUnit.run())" ]), + (0, [ 'doc/my_test_suite.lua', '-v', 'TestAdd.testAddPositive', 'TestAdd.testAddZero']), + (0, [ 'doc/my_test_suite.lua', '-v' ]), + (0, [ 'doc/my_test_suite.lua', ]), + (0, [ 'doc/my_test_suite.lua', '-o','TAP']), + (0, [ 'doc/my_test_suite.lua', 'TestAdd', 'TestDiv.testDivError' , '-v']), + (0, [ 'doc/my_test_suite.lua', '-v', '-p', 'Err.r', '-p', 'Z.ro' ]), + (0, [ 'doc/my_test_suite.lua', '-v', '--pattern', 'Add', '--exclude', 'Adder', '--pattern', 'Zero' ]), + (0, [ 'doc/my_test_suite.lua', '-v', '-x', 'Error', '-x', 'Zero' ]), + (2, [ 'doc/my_test_suite_with_failures.lua', '-o', 'text' ]), + (2, [ 'doc/my_test_suite_with_failures.lua', '-o', 'text', '--verbose' ]), + (2, [ 'doc/my_test_suite_with_failures.lua', '-o', 'tap', '--quiet' ]), + (2, [ 'doc/my_test_suite_with_failures.lua', '-o', 'tap' ]), + (2, [ 'doc/my_test_suite_with_failures.lua', '-o', 'tap', '--verbose' ]), + (2, [ 'doc/my_test_suite_with_failures.lua', '-o', 'nil', '--verbose' ]), + ): + print( '%s %s' % ('\n$ lua', ' '.join(l).replace('doc/', '') ) ) + retcode = subprocess.call( [lua] + l ) + if retcode != expretcode: + report( 'Invalid luacheck result' ) + sys.exit( retcode ) + + for expretcode, l in ( + (2, [ 'doc/my_test_suite_with_failures.lua', '-o', 'junit', '-n', 'toto.xml' ]), + ): + print( '%s %s' % ('\n$ lua', ' '.join(l).replace('doc/', '') ) ) + retcode = subprocess.call( [lua] + l ) + if retcode != expretcode: + report( 'Invalid luacheck result' ) + sys.exit( retcode ) + + print( open('toto.xml').read() ) + +def install(): + installpath = '/usr/local/share/lua/' + for lua, luaversion in ALL_LUA: + lua,ver = luaversion.split( ) + if os.path.exists(installpath+ver): + shutil.copy('luaunit.lua',installpath+ver) + + + +OptToFunc = { + 'rununittests' : run_unit_tests, + 'runtests' : run_tests, + 'luacheck' : run_luacheck, + 'runexample' : run_example, + 'packageit' : packageit, + 'buildrock' : buildrock, + 'makedoc' : makedoc, + 'rundoctests' : rundoctests, + 'install' : install, + 'help' : help, +} + +if __name__ == '__main__': + doingNothing = True + for arg in sys.argv[1:]: + if arg in OptToFunc: + doingNothing = False + OptToFunc[arg]() + else: + print( 'No such action :', arg ) + sys.exit(-1) + + if doingNothing: + help() + + + diff -Nru lua-unit-3.2/example_with_luaunit.lua lua-unit-3.3/example_with_luaunit.lua --- lua-unit-3.2/example_with_luaunit.lua 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/example_with_luaunit.lua 2018-04-20 12:34:12.000000000 +0000 @@ -1,142 +1,145 @@ -#!/usr/bin/env lua - -EXPORT_ASSERT_TO_GLOBALS = true -require('luaunit') - -TestToto = {} --class - - function TestToto:setUp() - -- set up tests - self.a = 1 - self.s = 'hop' - self.t1 = {1,2,3} - self.t2 = {one=1,two=2,three=3} - self.t3 = {1,2,three=3} - end - - function TestToto:test1_withFailure() - -- print( "some stuff test 1" ) - assertEquals( self.a , 1 ) - -- will fail - assertEquals( self.a , 2 ) - assertEquals( self.a , 2 ) - end - - function TestToto:test2_withFailure() - -- print( "some stuff test 2" ) - assertEquals( self.a , 1 ) - assertEquals( self.s , 'hop' ) - -- will fail - assertEquals( self.s , 'bof' ) - assertEquals( self.s , 'bof' ) - end - - function TestToto:test3() - -- print( "some stuff test 3" ) - assertEquals( self.a , 1 ) - assertEquals( self.s , 'hop' ) - assertEquals( type(self.a), 'number' ) - end - - function TestToto:test4() - -- print( "some stuff test 4" ) - assertNotEquals( self.a , 1 ) - end - - function TestToto:test5() - -- print( "some stuff test 5" ) - assertTrue( self.a ) - assertFalse( self.a ) - end - - function TestToto:test6() - -- print( "some stuff test 6" ) - assertTrue( false ) - end - - function TestToto:test7() - -- assertEquals( {1,2}, self.t1 ) - -- assertEquals( {1,2}, self.t2 ) - assertEquals( {1,2}, self.t3 ) - end - - function TestToto:test8a() - -- failure occurs in a submethod - self:funcWithError() - end - - function TestToto:test8b() - -- failure occurs in a submethod - self:funcWithFuncWithError() - end - - function TestToto:funcWithFuncWithError() - self:funcWithError() - end - - function TestToto:funcWithError() - error('Bouhouhoum error!') - end - - --- class TestToto - -TestTiti = {} --class - function TestTiti:setUp() - -- set up tests - self.a = 1 - self.s = 'hop' - -- print( 'TestTiti:setUp' ) - end - - function TestTiti:tearDown() - -- some tearDown() code if necessary - -- print( 'TestTiti:tearDown' ) - end - - function TestTiti:test1_withFailure() - -- print( "some stuff test 1" ) - assertEquals( self.a , 1 ) - -- will fail - assertEquals( self.a , 2 ) - assertEquals( self.a , 2 ) - end - - function TestTiti:test2_withFailure() - -- print( "some stuff test 2" ) - assertEquals( self.a , 1 ) - assertEquals( self.s , 'hop' ) - -- will fail - assertEquals( self.s , 'bof' ) - assertEquals( self.s , 'bof' ) - end - - function TestTiti:test3() - -- print( "some stuff test 3" ) - assertEquals( self.a , 1 ) - assertEquals( self.s , 'hop' ) - end --- class TestTiti - --- simple test functions that were written previously can be integrated --- in luaunit too -function test1_withFailure() - assert( 1 == 1) - -- will fail - assert( 1 == 2) -end - -function test2_withFailure() - assert( 'a' == 'a') - -- will fail - assert( 'a' == 'b') -end - -function test3() - assert( 1 == 1) - assert( 'a' == 'a') -end - -local lu = LuaUnit.new() -lu:setOutputType("tap") -os.exit( lu:runSuite() ) +#!/usr/bin/env lua + + +local lu = require('luaunit') + +TestToto = {} --class + + function TestToto:setUp() + -- set up tests + self.a = 1 + self.s = 'hop' + self.t1 = {1,2,3} + self.t2 = {one=1,two=2,three=3} + self.t3 = {1,2,three=3} + end + + function TestToto:test1_withFailure() + -- print( "some stuff test 1" ) + lu.assertEquals( self.a , 1 ) + -- will fail + lu.assertEquals( self.a , 2 ) + lu.assertEquals( self.a , 2 ) + end + + function TestToto:test2_withFailure() + -- print( "some stuff test 2" ) + lu.assertEquals( self.a , 1 ) + lu.assertEquals( self.s , 'hop' ) + -- will fail + lu.assertEquals( self.s , 'bof' ) + lu.assertEquals( self.s , 'bof' ) + end + + function TestToto:test3() + -- print( "some stuff test 3" ) + lu.assertEquals( self.a , 1 ) + lu.assertEquals( self.s , 'hop' ) + lu.assertEquals( type(self.a), 'number' ) + end + + function TestToto:test4() + -- print( "some stuff test 4" ) + lu.assertNotEquals( self.a , 1 ) + end + + function TestToto:test5() + -- print( "some stuff test 5" ) + lu.assertEvalToTrue( self.a ) + lu.assertEvalToFalse( self.a ) -- will trigger the failure + end + + function TestToto:test6() + -- print( "some stuff test 6" ) + lu.assertTrue( true ) + lu.assertFalse( false ) + lu.assertEvalToFalse( nil ) + lu.assertFalse( nil ) -- trigger the failure assertFalse is strict + end + + function TestToto:test7() + -- assertEquals( {1,2}, self.t1 ) + -- assertEquals( {1,2}, self.t2 ) + lu.assertEquals( {1,2}, self.t3 ) + end + + function TestToto:test8a() + -- failure occurs in a submethod + self:funcWithError() + end + + function TestToto:test8b() + -- failure occurs in a submethod + self:funcWithFuncWithError() + end + + function TestToto:funcWithFuncWithError() + self:funcWithError() + end + + function TestToto:funcWithError() + error('Bouhouhoum error!') + end + + +-- class TestTiti + +TestTiti = {} --class + function TestTiti:setUp() + -- set up tests + self.a = 1 + self.s = 'hop' + -- print( 'TestTiti:setUp' ) + end + + function TestTiti:tearDown() + -- some tearDown() code if necessary + -- print( 'TestTiti:tearDown' ) + end + + function TestTiti:test1_withFailure() + -- print( "some stuff test 1" ) + lu.assertEquals( self.a , 1 ) + -- will fail + lu.assertEquals( self.a , 2 ) + lu.assertEquals( self.a , 2 ) + end + + function TestTiti:test2_withFailure() + -- print( "some stuff test 2" ) + lu.assertEquals( self.a , 1 ) + lu.assertEquals( self.s , 'hop' ) + -- will fail + lu.assertEquals( self.s , 'bof' ) + lu.assertEquals( self.s , 'bof' ) + end + + function TestTiti:test3() + -- print( "some stuff test 3" ) + lu.assertEquals( self.a , 1 ) + lu.assertEquals( self.s , 'hop' ) + end +-- class TestTiti + +-- simple test functions that were written previously can be integrated +-- in luaunit too +function test1_withFailure() + assert( 1 == 1) + -- will fail + assert( 1 == 2) +end + +function test2_withFailure() + assert( 'a' == 'a') + -- will fail + assert( 'a' == 'b') +end + +function test3() + assert( 1 == 1) + assert( 'a' == 'a') +end + +local runner = lu.LuaUnit.new() +runner:setOutputType("tap") +os.exit( runner:runSuite() ) diff -Nru lua-unit-3.2/.git/config lua-unit-3.3/.git/config --- lua-unit-3.2/.git/config 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/config 2018-04-20 12:34:12.000000000 +0000 @@ -0,0 +1,11 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true +[remote "origin"] + url = git@github.com:bluebird75/luaunit.git + fetch = +refs/heads/*:refs/remotes/origin/* +[branch "master"] + remote = origin + merge = refs/heads/master diff -Nru lua-unit-3.2/.git/description lua-unit-3.3/.git/description --- lua-unit-3.2/.git/description 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/description 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff -Nru lua-unit-3.2/.git/HEAD lua-unit-3.3/.git/HEAD --- lua-unit-3.2/.git/HEAD 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/HEAD 2018-04-20 12:35:02.000000000 +0000 @@ -0,0 +1 @@ +ref: refs/heads/3.3 diff -Nru lua-unit-3.2/.git/hooks/applypatch-msg.sample lua-unit-3.3/.git/hooks/applypatch-msg.sample --- lua-unit-3.2/.git/hooks/applypatch-msg.sample 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/hooks/applypatch-msg.sample 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,15 @@ +#!/bin/sh +# +# An example hook script to check the commit log message taken by +# applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. The hook is +# allowed to edit the commit message file. +# +# To enable this hook, rename this file to "applypatch-msg". + +. git-sh-setup +commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +: diff -Nru lua-unit-3.2/.git/hooks/commit-msg.sample lua-unit-3.3/.git/hooks/commit-msg.sample --- lua-unit-3.2/.git/hooks/commit-msg.sample 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/hooks/commit-msg.sample 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by "git commit" with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, rename this file to "commit-msg". + +# Uncomment the below to add a Signed-off-by line to the message. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +# hook is more suited to it. +# +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff -Nru lua-unit-3.2/.git/hooks/fsmonitor-watchman.sample lua-unit-3.3/.git/hooks/fsmonitor-watchman.sample --- lua-unit-3.2/.git/hooks/fsmonitor-watchman.sample 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/hooks/fsmonitor-watchman.sample 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,114 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use IPC::Open2; + +# An example hook script to integrate Watchman +# (https://facebook.github.io/watchman/) with git to speed up detecting +# new and modified files. +# +# The hook is passed a version (currently 1) and a time in nanoseconds +# formatted as a string and outputs to stdout all files that have been +# modified since the given time. Paths must be relative to the root of +# the working tree and separated by a single NUL. +# +# To enable this hook, rename this file to "query-watchman" and set +# 'git config core.fsmonitor .git/hooks/query-watchman' +# +my ($version, $time) = @ARGV; + +# Check the hook interface version + +if ($version == 1) { + # convert nanoseconds to seconds + $time = int $time / 1000000000; +} else { + die "Unsupported query-fsmonitor hook version '$version'.\n" . + "Falling back to scanning...\n"; +} + +my $git_work_tree; +if ($^O =~ 'msys' || $^O =~ 'cygwin') { + $git_work_tree = Win32::GetCwd(); + $git_work_tree =~ tr/\\/\//; +} else { + require Cwd; + $git_work_tree = Cwd::cwd(); +} + +my $retry = 1; + +launch_watchman(); + +sub launch_watchman { + + my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') + or die "open2() failed: $!\n" . + "Falling back to scanning...\n"; + + # In the query expression below we're asking for names of files that + # changed since $time but were not transient (ie created after + # $time but no longer exist). + # + # To accomplish this, we're using the "since" generator to use the + # recency index to select candidate nodes and "fields" to limit the + # output to file names only. Then we're using the "expression" term to + # further constrain the results. + # + # The category of transient files that we want to ignore will have a + # creation clock (cclock) newer than $time_t value and will also not + # currently exist. + + my $query = <<" END"; + ["query", "$git_work_tree", { + "since": $time, + "fields": ["name"], + "expression": ["not", ["allof", ["since", $time, "cclock"], ["not", "exists"]]] + }] + END + + print CHLD_IN $query; + close CHLD_IN; + my $response = do {local $/; }; + + die "Watchman: command returned no output.\n" . + "Falling back to scanning...\n" if $response eq ""; + die "Watchman: command returned invalid output: $response\n" . + "Falling back to scanning...\n" unless $response =~ /^\{/; + + my $json_pkg; + eval { + require JSON::XS; + $json_pkg = "JSON::XS"; + 1; + } or do { + require JSON::PP; + $json_pkg = "JSON::PP"; + }; + + my $o = $json_pkg->new->utf8->decode($response); + + if ($retry > 0 and $o->{error} and $o->{error} =~ m/unable to resolve root .* directory (.*) is not watched/) { + print STDERR "Adding '$git_work_tree' to watchman's watch list.\n"; + $retry--; + qx/watchman watch "$git_work_tree"/; + die "Failed to make watchman watch '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + + # Watchman will always return all files on the first query so + # return the fast "everything is dirty" flag to git and do the + # Watchman query just to get it over with now so we won't pay + # the cost in git to look up each individual file. + print "/\0"; + eval { launch_watchman() }; + exit 0; + } + + die "Watchman: $o->{error}.\n" . + "Falling back to scanning...\n" if $o->{error}; + + binmode STDOUT, ":utf8"; + local $, = "\0"; + print @{$o->{files}}; +} diff -Nru lua-unit-3.2/.git/hooks/post-update.sample lua-unit-3.3/.git/hooks/post-update.sample --- lua-unit-3.2/.git/hooks/post-update.sample 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/hooks/post-update.sample 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script to prepare a packed repository for use over +# dumb transports. +# +# To enable this hook, rename this file to "post-update". + +exec git update-server-info diff -Nru lua-unit-3.2/.git/hooks/pre-applypatch.sample lua-unit-3.3/.git/hooks/pre-applypatch.sample --- lua-unit-3.2/.git/hooks/pre-applypatch.sample 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/hooks/pre-applypatch.sample 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,14 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed +# by applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-applypatch". + +. git-sh-setup +precommit="$(git rev-parse --git-path hooks/pre-commit)" +test -x "$precommit" && exec "$precommit" ${1+"$@"} +: diff -Nru lua-unit-3.2/.git/hooks/pre-commit.sample lua-unit-3.3/.git/hooks/pre-commit.sample --- lua-unit-3.2/.git/hooks/pre-commit.sample 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/hooks/pre-commit.sample 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,49 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff -Nru lua-unit-3.2/.git/hooks/prepare-commit-msg.sample lua-unit-3.3/.git/hooks/prepare-commit-msg.sample --- lua-unit-3.2/.git/hooks/prepare-commit-msg.sample 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/hooks/prepare-commit-msg.sample 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,42 @@ +#!/bin/sh +# +# An example hook script to prepare the commit log message. +# Called by "git commit" with the name of the file that has the +# commit message, followed by the description of the commit +# message's source. The hook's purpose is to edit the commit +# message file. If the hook fails with a non-zero status, +# the commit is aborted. +# +# To enable this hook, rename this file to "prepare-commit-msg". + +# This hook includes three examples. The first one removes the +# "# Please enter the commit message..." help message. +# +# The second includes the output of "git diff --name-status -r" +# into the message, just before the "git status" output. It is +# commented because it doesn't cope with --amend or with squashed +# commits. +# +# The third example adds a Signed-off-by line to the message, that can +# still be edited. This is rarely a good idea. + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + +# case "$COMMIT_SOURCE,$SHA1" in +# ,|template,) +# /usr/bin/perl -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +# *) ;; +# esac + +# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi diff -Nru lua-unit-3.2/.git/hooks/pre-push.sample lua-unit-3.3/.git/hooks/pre-push.sample --- lua-unit-3.2/.git/hooks/pre-push.sample 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/hooks/pre-push.sample 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,53 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +remote="$1" +url="$2" + +z40=0000000000000000000000000000000000000000 + +while read local_ref local_sha remote_ref remote_sha +do + if [ "$local_sha" = $z40 ] + then + # Handle delete + : + else + if [ "$remote_sha" = $z40 ] + then + # New branch, examine all commits + range="$local_sha" + else + # Update to existing branch, examine new commits + range="$remote_sha..$local_sha" + fi + + # Check for WIP commit + commit=`git rev-list -n 1 --grep '^WIP' "$range"` + if [ -n "$commit" ] + then + echo >&2 "Found WIP commit in $local_ref, not pushing" + exit 1 + fi + fi +done + +exit 0 diff -Nru lua-unit-3.2/.git/hooks/pre-rebase.sample lua-unit-3.3/.git/hooks/pre-rebase.sample --- lua-unit-3.2/.git/hooks/pre-rebase.sample 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/hooks/pre-rebase.sample 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,169 @@ +#!/bin/sh +# +# Copyright (c) 2006, 2008 Junio C Hamano +# +# The "pre-rebase" hook is run just before "git rebase" starts doing +# its job, and can prevent the command from running by exiting with +# non-zero status. +# +# The hook is called with the following parameters: +# +# $1 -- the upstream the series was forked from. +# $2 -- the branch being rebased (or empty when rebasing the current branch). +# +# This sample shows how to prevent topic branches that are already +# merged to 'next' branch from getting rebased, because allowing it +# would result in rebasing already published history. + +publish=next +basebranch="$1" +if test "$#" = 2 +then + topic="refs/heads/$2" +else + topic=`git symbolic-ref HEAD` || + exit 0 ;# we do not interrupt rebasing detached HEAD +fi + +case "$topic" in +refs/heads/??/*) + ;; +*) + exit 0 ;# we do not interrupt others. + ;; +esac + +# Now we are dealing with a topic branch being rebased +# on top of master. Is it OK to rebase it? + +# Does the topic really exist? +git show-ref -q "$topic" || { + echo >&2 "No such branch $topic" + exit 1 +} + +# Is topic fully merged to master? +not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +if test -z "$not_in_master" +then + echo >&2 "$topic is fully merged to master; better remove it." + exit 1 ;# we could allow it, but there is no point. +fi + +# Is topic ever merged to next? If so you should not be rebasing it. +only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +only_next_2=`git rev-list ^master ${publish} | sort` +if test "$only_next_1" = "$only_next_2" +then + not_in_topic=`git rev-list "^$topic" master` + if test -z "$not_in_topic" + then + echo >&2 "$topic is already up to date with master" + exit 1 ;# we could allow it, but there is no point. + else + exit 0 + fi +else + not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` + /usr/bin/perl -e ' + my $topic = $ARGV[0]; + my $msg = "* $topic has commits already merged to public branch:\n"; + my (%not_in_next) = map { + /^([0-9a-f]+) /; + ($1 => 1); + } split(/\n/, $ARGV[1]); + for my $elem (map { + /^([0-9a-f]+) (.*)$/; + [$1 => $2]; + } split(/\n/, $ARGV[2])) { + if (!exists $not_in_next{$elem->[0]}) { + if ($msg) { + print STDERR $msg; + undef $msg; + } + print STDERR " $elem->[1]\n"; + } + } + ' "$topic" "$not_in_next" "$not_in_master" + exit 1 +fi + +<<\DOC_END + +This sample hook safeguards topic branches that have been +published from being rewound. + +The workflow assumed here is: + + * Once a topic branch forks from "master", "master" is never + merged into it again (either directly or indirectly). + + * Once a topic branch is fully cooked and merged into "master", + it is deleted. If you need to build on top of it to correct + earlier mistakes, a new topic branch is created by forking at + the tip of the "master". This is not strictly necessary, but + it makes it easier to keep your history simple. + + * Whenever you need to test or publish your changes to topic + branches, merge them into "next" branch. + +The script, being an example, hardcodes the publish branch name +to be "next", but it is trivial to make it configurable via +$GIT_DIR/config mechanism. + +With this workflow, you would want to know: + +(1) ... if a topic branch has ever been merged to "next". Young + topic branches can have stupid mistakes you would rather + clean up before publishing, and things that have not been + merged into other branches can be easily rebased without + affecting other people. But once it is published, you would + not want to rewind it. + +(2) ... if a topic branch has been fully merged to "master". + Then you can delete it. More importantly, you should not + build on top of it -- other people may already want to + change things related to the topic as patches against your + "master", so if you need further changes, it is better to + fork the topic (perhaps with the same name) afresh from the + tip of "master". + +Let's look at this example: + + o---o---o---o---o---o---o---o---o---o "next" + / / / / + / a---a---b A / / + / / / / + / / c---c---c---c B / + / / / \ / + / / / b---b C \ / + / / / / \ / + ---o---o---o---o---o---o---o---o---o---o---o "master" + + +A, B and C are topic branches. + + * A has one fix since it was merged up to "next". + + * B has finished. It has been fully merged up to "master" and "next", + and is ready to be deleted. + + * C has not merged to "next" at all. + +We would want to allow C to be rebased, refuse A, and encourage +B to be deleted. + +To compute (1): + + git rev-list ^master ^topic next + git rev-list ^master next + + if these match, topic has not merged in next at all. + +To compute (2): + + git rev-list master..topic + + if this is empty, it is fully merged to "master". + +DOC_END diff -Nru lua-unit-3.2/.git/hooks/pre-receive.sample lua-unit-3.3/.git/hooks/pre-receive.sample --- lua-unit-3.2/.git/hooks/pre-receive.sample 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/hooks/pre-receive.sample 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to make use of push options. +# The example simply echoes all push options that start with 'echoback=' +# and rejects all pushes when the "reject" push option is used. +# +# To enable this hook, rename this file to "pre-receive". + +if test -n "$GIT_PUSH_OPTION_COUNT" +then + i=0 + while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" + do + eval "value=\$GIT_PUSH_OPTION_$i" + case "$value" in + echoback=*) + echo "echo from the pre-receive-hook: ${value#*=}" >&2 + ;; + reject) + exit 1 + esac + i=$((i + 1)) + done +fi diff -Nru lua-unit-3.2/.git/hooks/update.sample lua-unit-3.3/.git/hooks/update.sample --- lua-unit-3.2/.git/hooks/update.sample 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/hooks/update.sample 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,128 @@ +#!/bin/sh +# +# An example hook script to block unannotated tags from entering. +# Called by "git receive-pack" with arguments: refname sha1-old sha1-new +# +# To enable this hook, rename this file to "update". +# +# Config +# ------ +# hooks.allowunannotated +# This boolean sets whether unannotated tags will be allowed into the +# repository. By default they won't be. +# hooks.allowdeletetag +# This boolean sets whether deleting tags will be allowed in the +# repository. By default they won't be. +# hooks.allowmodifytag +# This boolean sets whether a tag may be modified after creation. By default +# it won't be. +# hooks.allowdeletebranch +# This boolean sets whether deleting branches will be allowed in the +# repository. By default they won't be. +# hooks.denycreatebranch +# This boolean sets whether remotely creating branches will be denied +# in the repository. By default this is allowed. +# + +# --- Command line +refname="$1" +oldrev="$2" +newrev="$3" + +# --- Safety check +if [ -z "$GIT_DIR" ]; then + echo "Don't run this script from the command line." >&2 + echo " (if you want, you could supply GIT_DIR then run" >&2 + echo " $0 )" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "usage: $0 " >&2 + exit 1 +fi + +# --- Config +allowunannotated=$(git config --bool hooks.allowunannotated) +allowdeletebranch=$(git config --bool hooks.allowdeletebranch) +denycreatebranch=$(git config --bool hooks.denycreatebranch) +allowdeletetag=$(git config --bool hooks.allowdeletetag) +allowmodifytag=$(git config --bool hooks.allowmodifytag) + +# check for no description +projectdesc=$(sed -e '1q' "$GIT_DIR/description") +case "$projectdesc" in +"Unnamed repository"* | "") + echo "*** Project description file hasn't been set" >&2 + exit 1 + ;; +esac + +# --- Check types +# if $newrev is 0000...0000, it's a commit to delete a ref. +zero="0000000000000000000000000000000000000000" +if [ "$newrev" = "$zero" ]; then + newrev_type=delete +else + newrev_type=$(git cat-file -t $newrev) +fi + +case "$refname","$newrev_type" in + refs/tags/*,commit) + # un-annotated tag + short_refname=${refname##refs/tags/} + if [ "$allowunannotated" != "true" ]; then + echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 + exit 1 + fi + ;; + refs/tags/*,delete) + # delete tag + if [ "$allowdeletetag" != "true" ]; then + echo "*** Deleting a tag is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/tags/*,tag) + # annotated tag + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 + then + echo "*** Tag '$refname' already exists." >&2 + echo "*** Modifying a tag is not allowed in this repository." >&2 + exit 1 + fi + ;; + refs/heads/*,commit) + # branch + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then + echo "*** Creating a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/heads/*,delete) + # delete branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/remotes/*,commit) + # tracking branch + ;; + refs/remotes/*,delete) + # delete tracking branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + *) + # Anything else (is there anything else?) + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 + exit 1 + ;; +esac + +# --- Finished +exit 0 Binary files /tmp/tmpqlc4Q4/Ld1fyEJYap/lua-unit-3.2/.git/index and /tmp/tmpqlc4Q4/81x2Ab2VgL/lua-unit-3.3/.git/index differ diff -Nru lua-unit-3.2/.git/info/exclude lua-unit-3.3/.git/info/exclude --- lua-unit-3.2/.git/info/exclude 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/info/exclude 2018-04-20 12:34:10.000000000 +0000 @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff -Nru lua-unit-3.2/.git/logs/HEAD lua-unit-3.3/.git/logs/HEAD --- lua-unit-3.2/.git/logs/HEAD 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/logs/HEAD 2018-04-20 12:35:02.000000000 +0000 @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 c072c1bc0118090459c4296237bea66abfad4256 Victor Seva 1524227652 +0200 clone: from git@github.com:bluebird75/luaunit.git +c072c1bc0118090459c4296237bea66abfad4256 38deff2e2c58c0a37c9f2b0a74660d2de1183db3 Victor Seva 1524227702 +0200 checkout: moving from master to 3.3 diff -Nru lua-unit-3.2/.git/logs/refs/heads/3.3 lua-unit-3.3/.git/logs/refs/heads/3.3 --- lua-unit-3.2/.git/logs/refs/heads/3.3 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/logs/refs/heads/3.3 2018-04-20 12:35:02.000000000 +0000 @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 38deff2e2c58c0a37c9f2b0a74660d2de1183db3 Victor Seva 1524227702 +0200 branch: Created from LUAUNIT_V3_3 diff -Nru lua-unit-3.2/.git/logs/refs/heads/master lua-unit-3.3/.git/logs/refs/heads/master --- lua-unit-3.2/.git/logs/refs/heads/master 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/logs/refs/heads/master 2018-04-20 12:34:12.000000000 +0000 @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 c072c1bc0118090459c4296237bea66abfad4256 Victor Seva 1524227652 +0200 clone: from git@github.com:bluebird75/luaunit.git diff -Nru lua-unit-3.2/.git/logs/refs/remotes/origin/HEAD lua-unit-3.3/.git/logs/refs/remotes/origin/HEAD --- lua-unit-3.2/.git/logs/refs/remotes/origin/HEAD 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/logs/refs/remotes/origin/HEAD 2018-04-20 12:34:12.000000000 +0000 @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 c072c1bc0118090459c4296237bea66abfad4256 Victor Seva 1524227652 +0200 clone: from git@github.com:bluebird75/luaunit.git Binary files /tmp/tmpqlc4Q4/Ld1fyEJYap/lua-unit-3.2/.git/objects/pack/pack-99aa17fd0141f212dff6b623264ebfb39a3a95f0.idx and /tmp/tmpqlc4Q4/81x2Ab2VgL/lua-unit-3.3/.git/objects/pack/pack-99aa17fd0141f212dff6b623264ebfb39a3a95f0.idx differ Binary files /tmp/tmpqlc4Q4/Ld1fyEJYap/lua-unit-3.2/.git/objects/pack/pack-99aa17fd0141f212dff6b623264ebfb39a3a95f0.pack and /tmp/tmpqlc4Q4/81x2Ab2VgL/lua-unit-3.3/.git/objects/pack/pack-99aa17fd0141f212dff6b623264ebfb39a3a95f0.pack differ diff -Nru lua-unit-3.2/.git/packed-refs lua-unit-3.3/.git/packed-refs --- lua-unit-3.2/.git/packed-refs 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/packed-refs 2018-04-20 12:34:12.000000000 +0000 @@ -0,0 +1,23 @@ +# pack-refs with: peeled fully-peeled sorted +c072c1bc0118090459c4296237bea66abfad4256 refs/remotes/origin/master +7f2301c2f151f23a43fa6e790609e98ef65bcac0 refs/remotes/origin/nitehawk +b415b7019660f5f4e8d5b127e5019e0f6d0b16bf refs/tags/1.2 +dd0ece76c084a5b77020def08a632d2d2cb45f3f refs/tags/1.3 +8ec647c1e2e8a58b349539a36665fb0ead028c93 refs/tags/1.5 +403dd09a00a1f0f766c5cb187a8a7e92a42239d5 refs/tags/LUANIT_V1_4 +b415b7019660f5f4e8d5b127e5019e0f6d0b16bf refs/tags/LUAUNIT_V1_2 +dd0ece76c084a5b77020def08a632d2d2cb45f3f refs/tags/LUAUNIT_V1_3 +7dfd14736ffac7e73509c8cf9e02c5f658e9e3a6 refs/tags/LUAUNIT_V1_5 +7856427a9d909b961aaa06865055867b819463e6 refs/tags/LUAUNIT_V3_0 +^477548cf81bf3ceee4cae5d824743a7698f231ed +d2050566cb0b090f30fbe66d3e649765a97d802f refs/tags/LUAUNIT_V3_1 +^94de44396fc53ba5fcbf3b06fab6e7a74404e381 +31b1b579c96d6cc92a333a1e7de5457c55016e32 refs/tags/LUAUNIT_V3_2 +^07e5a8ada3a15d0bd040cceb9c49e51377c5b207 +6251dcb1aad86110d6dd49070abb75d9b0544bcf refs/tags/LUAUNIT_V3_2_1 +^88b2129cba5d55ad27ff76d51bbd327a1c1d8c45 +15d3536a6242073e4313039c8442d8a9d8845818 refs/tags/LUAUNIT_V3_3 +^38deff2e2c58c0a37c9f2b0a74660d2de1183db3 +2f576a7e8d97970952ddcb1f58146a838b1df43c refs/tags/LUAUNIT_V3_3-RC1 +dccd7b5f251fcf35d5e729b43880e543d86c4aa9 refs/tags/bof +e2995363849bfabb3b4e27d88ace52de0f0cc5a5 refs/tags/v3.0 diff -Nru lua-unit-3.2/.git/refs/heads/3.3 lua-unit-3.3/.git/refs/heads/3.3 --- lua-unit-3.2/.git/refs/heads/3.3 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/refs/heads/3.3 2018-04-20 12:35:02.000000000 +0000 @@ -0,0 +1 @@ +38deff2e2c58c0a37c9f2b0a74660d2de1183db3 diff -Nru lua-unit-3.2/.git/refs/heads/master lua-unit-3.3/.git/refs/heads/master --- lua-unit-3.2/.git/refs/heads/master 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/refs/heads/master 2018-04-20 12:34:12.000000000 +0000 @@ -0,0 +1 @@ +c072c1bc0118090459c4296237bea66abfad4256 diff -Nru lua-unit-3.2/.git/refs/remotes/origin/HEAD lua-unit-3.3/.git/refs/remotes/origin/HEAD --- lua-unit-3.2/.git/refs/remotes/origin/HEAD 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.git/refs/remotes/origin/HEAD 2018-04-20 12:34:12.000000000 +0000 @@ -0,0 +1 @@ +ref: refs/remotes/origin/master diff -Nru lua-unit-3.2/.gitignore lua-unit-3.3/.gitignore --- lua-unit-3.2/.gitignore 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/.gitignore 2018-04-20 12:34:12.000000000 +0000 @@ -0,0 +1,65 @@ + +# ignore temp files +*.sw? +*.bak +*.pyc + +#ignore thumbnails created by windows +Thumbs.db + +#Ignore files build by Visual Studio +*.obj +*.exe +*.pdb +*.user +*.aps +*.pch +*.vspscc +*_i.c +*_p.c +*.ncb +*.suo +*.tlb +*.tlh +*.cache +*.ilk +*.log +[Bb]in +[Dd]ebug*/ +*.lib +*.sbr +obj/ +[Rr]elease*/ +_ReSharper*/ + +# LuaCov output (stats and report) +luacov.*.out + +# LuaUnit ignores +[Tt]est[Rr]esult* +*.sublime-project +*.lsln +*.sublime-workspace +doc/_build/ +doc/html/ +junit_stdout.txt +output_junit.xml +junit_stdout?.txt +output_junit?.xml +test/example*.txt +test/example*.xml +test/testWithXml*.xml +test/testWithXml*.txt +test/unitTests*.xml +test/unitTests*.txt +test/legacyExample.txt +test/legacyExampleError.txt +test/compat_luaunit_v2x.txt +test/errFailPass*.txt +test/errFailPass*.xml +test/some_lists_comparisons.txt + +*.diff + +#Emacs +*~ diff -Nru lua-unit-3.2/junitxml/example-apache-ant.xml lua-unit-3.3/junitxml/example-apache-ant.xml --- lua-unit-3.2/junitxml/example-apache-ant.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/junitxml/example-apache-ant.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,31 +1,31 @@ - - - - - - - - - - Detailed failure content - - - - - - - Detailed error content - - - bla bla output bla bla - bla bla error bla bla - + + + + + + + + + + Detailed failure content + + + + + + + Detailed error content + + + bla bla output bla bla + bla bla error bla bla + \ No newline at end of file diff -Nru lua-unit-3.2/junitxml/example-bamboo-1.xml lua-unit-3.3/junitxml/example-bamboo-1.xml --- lua-unit-3.2/junitxml/example-bamboo-1.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/junitxml/example-bamboo-1.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,70 +1,70 @@ - - - - - - - - - - - junit.framework.AssertionFailedError: Should not have any errors. [Perforce client error:, Connect to server - failed; check $P4PORT., TCP connect to keg failed., keg: host unknown.] expected:<0> but was:<4> - at junit.framework.Assert.fail(Assert.java:47) - at junit.framework.Assert.failNotEquals(Assert.java:282) - at junit.framework.Assert.assertEquals(Assert.java:64) - at junit.framework.Assert.assertEquals(Assert.java:201) - at com.atlassian.bamboo.repository.perforce.PerforceSyncCommandTest.testUsingPerforceWhenNoFilesHaveChanged(PerforceSyncCommandTest.java:60) - at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) - at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) - at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) - at java.lang.reflect.Method.invoke(Method.java:585) - at junit.framework.TestCase.runTest(TestCase.java:154) - at junit.framework.TestCase.runBare(TestCase.java:127) - at junit.framework.TestResult$1.protect(TestResult.java:106) - at junit.framework.TestResult.runProtected(TestResult.java:124) - at junit.framework.TestResult.run(TestResult.java:109) - at junit.framework.TestCase.run(TestCase.java:118) - at junit.framework.TestSuite.runTest(TestSuite.java:208) - at junit.framework.TestSuite.run(TestSuite.java:203) - at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source) - at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) - at java.lang.reflect.Method.invoke(Method.java:585) - at org.apache.maven.surefire.battery.JUnitBattery.executeJUnit(JUnitBattery.java:242) - at org.apache.maven.surefire.battery.JUnitBattery.execute(JUnitBattery.java:216) - at org.apache.maven.surefire.Surefire.executeBattery(Surefire.java:215) - at org.apache.maven.surefire.Surefire.run(Surefire.java:163) - at org.apache.maven.surefire.Surefire.run(Surefire.java:87) - at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) - at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) - at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) - at java.lang.reflect.Method.invoke(Method.java:585) - at org.apache.maven.surefire.SurefireBooter.runTestsInProcess(SurefireBooter.java:313) - at org.apache.maven.surefire.SurefireBooter.run(SurefireBooter.java:221) - at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:371) - at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:412) - at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534) - at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:475) - at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454) - at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:306) - at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273) - at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140) - at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322) - at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115) - at org.apache.maven.cli.MavenCli.main(MavenCli.java:256) - at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) - at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) - at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) - at java.lang.reflect.Method.invoke(Method.java:585) - at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) - at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) - at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) - at org.codehaus.classworlds.Launcher.main(Launcher.java:375) - - - PerforceSyncCommand.command: /usr/local/bin/p4 - - + + + + + + + + + + + junit.framework.AssertionFailedError: Should not have any errors. [Perforce client error:, Connect to server + failed; check $P4PORT., TCP connect to keg failed., keg: host unknown.] expected:<0> but was:<4> + at junit.framework.Assert.fail(Assert.java:47) + at junit.framework.Assert.failNotEquals(Assert.java:282) + at junit.framework.Assert.assertEquals(Assert.java:64) + at junit.framework.Assert.assertEquals(Assert.java:201) + at com.atlassian.bamboo.repository.perforce.PerforceSyncCommandTest.testUsingPerforceWhenNoFilesHaveChanged(PerforceSyncCommandTest.java:60) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at junit.framework.TestCase.runTest(TestCase.java:154) + at junit.framework.TestCase.runBare(TestCase.java:127) + at junit.framework.TestResult$1.protect(TestResult.java:106) + at junit.framework.TestResult.runProtected(TestResult.java:124) + at junit.framework.TestResult.run(TestResult.java:109) + at junit.framework.TestCase.run(TestCase.java:118) + at junit.framework.TestSuite.runTest(TestSuite.java:208) + at junit.framework.TestSuite.run(TestSuite.java:203) + at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.apache.maven.surefire.battery.JUnitBattery.executeJUnit(JUnitBattery.java:242) + at org.apache.maven.surefire.battery.JUnitBattery.execute(JUnitBattery.java:216) + at org.apache.maven.surefire.Surefire.executeBattery(Surefire.java:215) + at org.apache.maven.surefire.Surefire.run(Surefire.java:163) + at org.apache.maven.surefire.Surefire.run(Surefire.java:87) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.apache.maven.surefire.SurefireBooter.runTestsInProcess(SurefireBooter.java:313) + at org.apache.maven.surefire.SurefireBooter.run(SurefireBooter.java:221) + at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:371) + at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:412) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:475) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:306) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140) + at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322) + at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115) + at org.apache.maven.cli.MavenCli.main(MavenCli.java:256) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) + at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) + at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) + at org.codehaus.classworlds.Launcher.main(Launcher.java:375) + + + PerforceSyncCommand.command: /usr/local/bin/p4 + + \ No newline at end of file diff -Nru lua-unit-3.2/junitxml/example-bamboo-2.xml lua-unit-3.3/junitxml/example-bamboo-2.xml --- lua-unit-3.2/junitxml/example-bamboo-2.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/junitxml/example-bamboo-2.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,56 +1,56 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -Nru lua-unit-3.2/junitxml/example-jenkins.xml lua-unit-3.3/junitxml/example-jenkins.xml --- lua-unit-3.2/junitxml/example-jenkins.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/junitxml/example-jenkins.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,29 +1,29 @@ - - - - - - - - bla bla - - Detailed failure content - - - - - - Detailed error content - - - bla bla output bla bla - bla bla error bla bla - - + + + + + + + + bla bla + + Detailed failure content + + + + + + Detailed error content + + + bla bla output bla bla + bla bla error bla bla + + \ No newline at end of file diff -Nru lua-unit-3.2/junitxml/junit-apache-ant.xsd lua-unit-3.3/junitxml/junit-apache-ant.xsd --- lua-unit-3.2/junitxml/junit-apache-ant.xsd 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/junitxml/junit-apache-ant.xsd 2018-04-20 12:34:12.000000000 +0000 @@ -1,206 +1,206 @@ - - - - - JUnit test result schema for the Apache Ant JUnit and JUnitReport tasks -Copyright © 2011, Windy Road Technology Pty. Limited -The Apache Ant JUnit XML Schema is distributed under the terms of the GNU Lesser General Public License (LGPL) http://www.gnu.org/licenses/lgpl.html -Permission to waive conditions of this license may be requested from Windy Road Support (http://windyroad.org/support). - - - - - - - - - - Contains an aggregation of testsuite results - - - - - - - - - - Derived from testsuite/@name in the non-aggregated documents - - - - - Starts at '0' for the first testsuite and is incremented by 1 for each following testsuite - - - - - - - - - - - - Contains the results of exexuting a testsuite - - - - - Properties (e.g., environment settings) set during test execution - - - - - - - - - - - - - - - - - - - - - - - - Indicates that the test errored. An errored test is one that had an unanticipated problem. e.g., an unchecked throwable; or a problem with the implementation of the test. Contains as a text node relevant data for the error, e.g., a stack trace - - - - - - - The error message. e.g., if a java exception is thrown, the return value of getMessage() - - - - - The type of error that occured. e.g., if a java execption is thrown the full class name of the exception. - - - - - - - - - Indicates that the test failed. A failure is a test which the code has explicitly failed by using the mechanisms for that purpose. e.g., via an assertEquals. Contains as a text node relevant data for the failure, e.g., a stack trace - - - - - - - The message specified in the assert - - - - - The type of the assert. - - - - - - - - - - Name of the test method - - - - - Full class name for the class the test method is in. - - - - - Time taken (in seconds) to execute the test - - - - - - - Data that was written to standard out while the test was executed - - - - - - - - - - Data that was written to standard error while the test was executed - - - - - - - - - - - Full class name of the test for non-aggregated testsuite documents. Class name without the package for aggregated testsuites documents - - - - - - - - - - when the test was executed. Timezone may not be specified. - - - - - Host on which the tests were executed. 'localhost' should be used if the hostname cannot be determined. - - - - - - - - - - The total number of tests in the suite - - - - - The total number of tests in the suite that failed. A failure is a test which the code has explicitly failed by using the mechanisms for that purpose. e.g., via an assertEquals - - - - - The total number of tests in the suite that errorrd. An errored test is one that had an unanticipated problem. e.g., an unchecked throwable; or a problem with the implementation of the test. - - - - - Time taken (in seconds) to execute the tests in the suite - - - - - - - - + + + + + JUnit test result schema for the Apache Ant JUnit and JUnitReport tasks +Copyright © 2011, Windy Road Technology Pty. Limited +The Apache Ant JUnit XML Schema is distributed under the terms of the GNU Lesser General Public License (LGPL) http://www.gnu.org/licenses/lgpl.html +Permission to waive conditions of this license may be requested from Windy Road Support (http://windyroad.org/support). + + + + + + + + + + Contains an aggregation of testsuite results + + + + + + + + + + Derived from testsuite/@name in the non-aggregated documents + + + + + Starts at '0' for the first testsuite and is incremented by 1 for each following testsuite + + + + + + + + + + + + Contains the results of exexuting a testsuite + + + + + Properties (e.g., environment settings) set during test execution + + + + + + + + + + + + + + + + + + + + + + + + Indicates that the test errored. An errored test is one that had an unanticipated problem. e.g., an unchecked throwable; or a problem with the implementation of the test. Contains as a text node relevant data for the error, e.g., a stack trace + + + + + + + The error message. e.g., if a java exception is thrown, the return value of getMessage() + + + + + The type of error that occured. e.g., if a java execption is thrown the full class name of the exception. + + + + + + + + + Indicates that the test failed. A failure is a test which the code has explicitly failed by using the mechanisms for that purpose. e.g., via an assertEquals. Contains as a text node relevant data for the failure, e.g., a stack trace + + + + + + + The message specified in the assert + + + + + The type of the assert. + + + + + + + + + + Name of the test method + + + + + Full class name for the class the test method is in. + + + + + Time taken (in seconds) to execute the test + + + + + + + Data that was written to standard out while the test was executed + + + + + + + + + + Data that was written to standard error while the test was executed + + + + + + + + + + + Full class name of the test for non-aggregated testsuite documents. Class name without the package for aggregated testsuites documents + + + + + + + + + + when the test was executed. Timezone may not be specified. + + + + + Host on which the tests were executed. 'localhost' should be used if the hostname cannot be determined. + + + + + + + + + + The total number of tests in the suite + + + + + The total number of tests in the suite that failed. A failure is a test which the code has explicitly failed by using the mechanisms for that purpose. e.g., via an assertEquals + + + + + The total number of tests in the suite that errorrd. An errored test is one that had an unanticipated problem. e.g., an unchecked throwable; or a problem with the implementation of the test. + + + + + Time taken (in seconds) to execute the tests in the suite + + + + + + + + \ No newline at end of file diff -Nru lua-unit-3.2/junitxml/junit-jenkins.xsd lua-unit-3.3/junitxml/junit-jenkins.xsd --- lua-unit-3.2/junitxml/junit-jenkins.xsd 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/junitxml/junit-jenkins.xsd 2018-04-20 12:34:12.000000000 +0000 @@ -1,91 +1,91 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -Nru lua-unit-3.2/junitxml/Makefile lua-unit-3.3/junitxml/Makefile --- lua-unit-3.2/junitxml/Makefile 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/junitxml/Makefile 2018-04-20 12:34:12.000000000 +0000 @@ -1,17 +1,17 @@ -# -# junitxml/Makefile -# - -XMLLINT ?= xmllint -TEST_APACHE = --noout --schema junit-apache-ant.xsd -TEST_JENKINS = --noout --schema junit-jenkins.xsd - -validate-examples: validate-apache validate-jenkins - -# This example file is the only one that satisfies the Apache schema -validate-apache: example-apache-ant.xml - $(XMLLINT) $(TEST_APACHE) $< - -# The Jenkins schema is more relaxed, and should apply to all .xml files -validate-jenkins: $(wildcard *.xml) - for file in $^; do $(XMLLINT) $(TEST_JENKINS) $$file || exit 1; done +# +# junitxml/Makefile +# + +XMLLINT ?= xmllint +TEST_APACHE = --noout --schema junit-apache-ant.xsd +TEST_JENKINS = --noout --schema junit-jenkins.xsd + +validate-examples: validate-apache validate-jenkins + +# This example file is the only one that satisfies the Apache schema +validate-apache: example-apache-ant.xml + $(XMLLINT) $(TEST_APACHE) $< + +# The Jenkins schema is more relaxed, and should apply to all .xml files +validate-jenkins: $(wildcard *.xml) + for file in $^; do $(XMLLINT) $(TEST_JENKINS) $$file || exit 1; done diff -Nru lua-unit-3.2/junitxml/notes-junit-compatibility.txt lua-unit-3.3/junitxml/notes-junit-compatibility.txt --- lua-unit-3.2/junitxml/notes-junit-compatibility.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/junitxml/notes-junit-compatibility.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,16 +1,34 @@ -Ant xml schema is much more restrictive than jenkins. - -Non allowed fields in ant, allowed in jenkins: - -testsuites: -- apache ant forbids all attributes. - -testsuite: -- apache ant forbids attributes: disabled, skipped -- apache ant allows elements system-out and system-err, that are in testcase for jenkins - -testcase: -- apache ant forbids attributes: assertions, status -- apache ant forbids elements: skipped, system-out, system-err - - +Our source information: +https://github.com/windyroad/JUnit-Schema +* http://stackoverflow.com/questions/4922867/junit-xml-format-specification-that-hudson-supports +(Jenkins) +* https://github.com/jenkinsci/xunit-plugin/tree/master/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd +* http://help.catchsoftware.com/display/ET/JUnit+Format +* http://llg.cubic.org/docs/junit/ +* https://confluence.atlassian.com/bamboo/junit-parsing-in-bamboo-289277357.html +* http://nose2.readthedocs.io/en/latest/plugins/junitxml.html +* https://pzolee.blogs.balabit.com/2012/11/jenkins-vs-junit-xml-format/ +* https://www.relishapp.com/cucumber/cucumber/docs/formatters/junit-output-formatter +* http://stackoverflow.com/questions/11241781/python-unittests-in-jenkins +* https://github.com/xmlrunner/unittest-xml-reporting/tree/master/ + + + +Notes: +====== +Ant xml schema is much more restrictive than jenkins. + +Non allowed fields in ant, allowed in jenkins: + +testsuites: +- apache ant forbids all attributes. + +testsuite: +- apache ant forbids attributes: disabled, skipped +- apache ant allows elements system-out and system-err, that are in testcase for jenkins + +testcase: +- apache ant forbids attributes: assertions, status +- apache ant forbids elements: skipped, system-out, system-err + + diff -Nru lua-unit-3.2/junitxml/XMLJUnitResultFormatter.java.txt lua-unit-3.3/junitxml/XMLJUnitResultFormatter.java.txt --- lua-unit-3.2/junitxml/XMLJUnitResultFormatter.java.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/junitxml/XMLJUnitResultFormatter.java.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,301 +1,301 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.tools.ant.taskdefs.optional.junit; - -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Properties; -import java.util.Date; -import java.net.InetAddress; -import java.net.UnknownHostException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import junit.framework.AssertionFailedError; -import junit.framework.Test; -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.util.DOMElementWriter; -import org.apache.tools.ant.util.DateUtils; -import org.apache.tools.ant.util.FileUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Text; - - -/** - * Prints XML output of the test to a specified Writer. - * - * @see FormatterElement - */ - -public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstants { - - private static final double ONE_SECOND = 1000.0; - - /** constant for unnnamed testsuites/cases */ - private static final String UNKNOWN = "unknown"; - - private static DocumentBuilder getDocumentBuilder() { - try { - return DocumentBuilderFactory.newInstance().newDocumentBuilder(); - } catch (Exception exc) { - throw new ExceptionInInitializerError(exc); - } - } - - /** - * The XML document. - */ - private Document doc; - /** - * The wrapper for the whole testsuite. - */ - private Element rootElement; - /** - * Element for the current test. - */ - private Hashtable testElements = new Hashtable(); - /** - * tests that failed. - */ - private Hashtable failedTests = new Hashtable(); - /** - * Timing helper. - */ - private Hashtable testStarts = new Hashtable(); - /** - * Where to write the log to. - */ - private OutputStream out; - - /** No arg constructor. */ - public XMLJUnitResultFormatter() { - } - - /** {@inheritDoc}. */ - public void setOutput(OutputStream out) { - this.out = out; - } - - /** {@inheritDoc}. */ - public void setSystemOutput(String out) { - formatOutput(SYSTEM_OUT, out); - } - - /** {@inheritDoc}. */ - public void setSystemError(String out) { - formatOutput(SYSTEM_ERR, out); - } - - /** - * The whole testsuite started. - * @param suite the testsuite. - */ - public void startTestSuite(JUnitTest suite) { - doc = getDocumentBuilder().newDocument(); - rootElement = doc.createElement(TESTSUITE); - String n = suite.getName(); - rootElement.setAttribute(ATTR_NAME, n == null ? UNKNOWN : n); - - //add the timestamp - final String timestamp = DateUtils.format(new Date(), - DateUtils.ISO8601_DATETIME_PATTERN); - rootElement.setAttribute(TIMESTAMP, timestamp); - //and the hostname. - rootElement.setAttribute(HOSTNAME, getHostname()); - - // Output properties - Element propsElement = doc.createElement(PROPERTIES); - rootElement.appendChild(propsElement); - Properties props = suite.getProperties(); - if (props != null) { - Enumeration e = props.propertyNames(); - while (e.hasMoreElements()) { - String name = (String) e.nextElement(); - Element propElement = doc.createElement(PROPERTY); - propElement.setAttribute(ATTR_NAME, name); - propElement.setAttribute(ATTR_VALUE, props.getProperty(name)); - propsElement.appendChild(propElement); - } - } - } - - /** - * get the local hostname - * @return the name of the local host, or "localhost" if we cannot work it out - */ - private String getHostname() { - try { - return InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - return "localhost"; - } - } - - /** - * The whole testsuite ended. - * @param suite the testsuite. - * @throws BuildException on error. - */ - public void endTestSuite(JUnitTest suite) throws BuildException { - rootElement.setAttribute(ATTR_TESTS, "" + suite.runCount()); - rootElement.setAttribute(ATTR_FAILURES, "" + suite.failureCount()); - rootElement.setAttribute(ATTR_ERRORS, "" + suite.errorCount()); - rootElement.setAttribute( - ATTR_TIME, "" + (suite.getRunTime() / ONE_SECOND)); - if (out != null) { - Writer wri = null; - try { - wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8")); - wri.write("\n"); - (new DOMElementWriter()).write(rootElement, wri, 0, " "); - } catch (IOException exc) { - throw new BuildException("Unable to write log file", exc); - } finally { - if (wri != null) { - try { - wri.flush(); - } catch (IOException ex) { - // ignore - } - } - if (out != System.out && out != System.err) { - FileUtils.close(wri); - } - } - } - } - - /** - * Interface TestListener. - * - *

A new Test is started. - * @param t the test. - */ - public void startTest(Test t) { - testStarts.put(t, new Long(System.currentTimeMillis())); - } - - /** - * Interface TestListener. - * - *

A Test is finished. - * @param test the test. - */ - public void endTest(Test test) { - // Fix for bug #5637 - if a junit.extensions.TestSetup is - // used and throws an exception during setUp then startTest - // would never have been called - if (!testStarts.containsKey(test)) { - startTest(test); - } - - Element currentTest = null; - if (!failedTests.containsKey(test)) { - currentTest = doc.createElement(TESTCASE); - String n = JUnitVersionHelper.getTestCaseName(test); - currentTest.setAttribute(ATTR_NAME, - n == null ? UNKNOWN : n); - // a TestSuite can contain Tests from multiple classes, - // even tests with the same name - disambiguate them. - currentTest.setAttribute(ATTR_CLASSNAME, - JUnitVersionHelper.getTestCaseClassName(test)); - rootElement.appendChild(currentTest); - testElements.put(test, currentTest); - } else { - currentTest = (Element) testElements.get(test); - } - - Long l = (Long) testStarts.get(test); - currentTest.setAttribute(ATTR_TIME, - "" + ((System.currentTimeMillis() - - l.longValue()) / ONE_SECOND)); - } - - /** - * Interface TestListener for JUnit <= 3.4. - * - *

A Test failed. - * @param test the test. - * @param t the exception. - */ - public void addFailure(Test test, Throwable t) { - formatError(FAILURE, test, t); - } - - /** - * Interface TestListener for JUnit > 3.4. - * - *

A Test failed. - * @param test the test. - * @param t the assertion. - */ - public void addFailure(Test test, AssertionFailedError t) { - addFailure(test, (Throwable) t); - } - - /** - * Interface TestListener. - * - *

An error occurred while running the test. - * @param test the test. - * @param t the error. - */ - public void addError(Test test, Throwable t) { - formatError(ERROR, test, t); - } - - private void formatError(String type, Test test, Throwable t) { - if (test != null) { - endTest(test); - failedTests.put(test, test); - } - - Element nested = doc.createElement(type); - Element currentTest = null; - if (test != null) { - currentTest = (Element) testElements.get(test); - } else { - currentTest = rootElement; - } - - currentTest.appendChild(nested); - - String message = t.getMessage(); - if (message != null && message.length() > 0) { - nested.setAttribute(ATTR_MESSAGE, t.getMessage()); - } - nested.setAttribute(ATTR_TYPE, t.getClass().getName()); - - String strace = JUnitTestRunner.getFilteredTrace(t); - Text trace = doc.createTextNode(strace); - nested.appendChild(trace); - } - - private void formatOutput(String type, String output) { - Element nested = doc.createElement(type); - rootElement.appendChild(nested); - nested.appendChild(doc.createCDATASection(output)); - } - -} // XMLJUnitResultFormatter +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.taskdefs.optional.junit; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Properties; +import java.util.Date; +import java.net.InetAddress; +import java.net.UnknownHostException; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.util.DOMElementWriter; +import org.apache.tools.ant.util.DateUtils; +import org.apache.tools.ant.util.FileUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Text; + + +/** + * Prints XML output of the test to a specified Writer. + * + * @see FormatterElement + */ + +public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstants { + + private static final double ONE_SECOND = 1000.0; + + /** constant for unnnamed testsuites/cases */ + private static final String UNKNOWN = "unknown"; + + private static DocumentBuilder getDocumentBuilder() { + try { + return DocumentBuilderFactory.newInstance().newDocumentBuilder(); + } catch (Exception exc) { + throw new ExceptionInInitializerError(exc); + } + } + + /** + * The XML document. + */ + private Document doc; + /** + * The wrapper for the whole testsuite. + */ + private Element rootElement; + /** + * Element for the current test. + */ + private Hashtable testElements = new Hashtable(); + /** + * tests that failed. + */ + private Hashtable failedTests = new Hashtable(); + /** + * Timing helper. + */ + private Hashtable testStarts = new Hashtable(); + /** + * Where to write the log to. + */ + private OutputStream out; + + /** No arg constructor. */ + public XMLJUnitResultFormatter() { + } + + /** {@inheritDoc}. */ + public void setOutput(OutputStream out) { + this.out = out; + } + + /** {@inheritDoc}. */ + public void setSystemOutput(String out) { + formatOutput(SYSTEM_OUT, out); + } + + /** {@inheritDoc}. */ + public void setSystemError(String out) { + formatOutput(SYSTEM_ERR, out); + } + + /** + * The whole testsuite started. + * @param suite the testsuite. + */ + public void startTestSuite(JUnitTest suite) { + doc = getDocumentBuilder().newDocument(); + rootElement = doc.createElement(TESTSUITE); + String n = suite.getName(); + rootElement.setAttribute(ATTR_NAME, n == null ? UNKNOWN : n); + + //add the timestamp + final String timestamp = DateUtils.format(new Date(), + DateUtils.ISO8601_DATETIME_PATTERN); + rootElement.setAttribute(TIMESTAMP, timestamp); + //and the hostname. + rootElement.setAttribute(HOSTNAME, getHostname()); + + // Output properties + Element propsElement = doc.createElement(PROPERTIES); + rootElement.appendChild(propsElement); + Properties props = suite.getProperties(); + if (props != null) { + Enumeration e = props.propertyNames(); + while (e.hasMoreElements()) { + String name = (String) e.nextElement(); + Element propElement = doc.createElement(PROPERTY); + propElement.setAttribute(ATTR_NAME, name); + propElement.setAttribute(ATTR_VALUE, props.getProperty(name)); + propsElement.appendChild(propElement); + } + } + } + + /** + * get the local hostname + * @return the name of the local host, or "localhost" if we cannot work it out + */ + private String getHostname() { + try { + return InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + return "localhost"; + } + } + + /** + * The whole testsuite ended. + * @param suite the testsuite. + * @throws BuildException on error. + */ + public void endTestSuite(JUnitTest suite) throws BuildException { + rootElement.setAttribute(ATTR_TESTS, "" + suite.runCount()); + rootElement.setAttribute(ATTR_FAILURES, "" + suite.failureCount()); + rootElement.setAttribute(ATTR_ERRORS, "" + suite.errorCount()); + rootElement.setAttribute( + ATTR_TIME, "" + (suite.getRunTime() / ONE_SECOND)); + if (out != null) { + Writer wri = null; + try { + wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8")); + wri.write("\n"); + (new DOMElementWriter()).write(rootElement, wri, 0, " "); + } catch (IOException exc) { + throw new BuildException("Unable to write log file", exc); + } finally { + if (wri != null) { + try { + wri.flush(); + } catch (IOException ex) { + // ignore + } + } + if (out != System.out && out != System.err) { + FileUtils.close(wri); + } + } + } + } + + /** + * Interface TestListener. + * + *

A new Test is started. + * @param t the test. + */ + public void startTest(Test t) { + testStarts.put(t, new Long(System.currentTimeMillis())); + } + + /** + * Interface TestListener. + * + *

A Test is finished. + * @param test the test. + */ + public void endTest(Test test) { + // Fix for bug #5637 - if a junit.extensions.TestSetup is + // used and throws an exception during setUp then startTest + // would never have been called + if (!testStarts.containsKey(test)) { + startTest(test); + } + + Element currentTest = null; + if (!failedTests.containsKey(test)) { + currentTest = doc.createElement(TESTCASE); + String n = JUnitVersionHelper.getTestCaseName(test); + currentTest.setAttribute(ATTR_NAME, + n == null ? UNKNOWN : n); + // a TestSuite can contain Tests from multiple classes, + // even tests with the same name - disambiguate them. + currentTest.setAttribute(ATTR_CLASSNAME, + JUnitVersionHelper.getTestCaseClassName(test)); + rootElement.appendChild(currentTest); + testElements.put(test, currentTest); + } else { + currentTest = (Element) testElements.get(test); + } + + Long l = (Long) testStarts.get(test); + currentTest.setAttribute(ATTR_TIME, + "" + ((System.currentTimeMillis() + - l.longValue()) / ONE_SECOND)); + } + + /** + * Interface TestListener for JUnit <= 3.4. + * + *

A Test failed. + * @param test the test. + * @param t the exception. + */ + public void addFailure(Test test, Throwable t) { + formatError(FAILURE, test, t); + } + + /** + * Interface TestListener for JUnit > 3.4. + * + *

A Test failed. + * @param test the test. + * @param t the assertion. + */ + public void addFailure(Test test, AssertionFailedError t) { + addFailure(test, (Throwable) t); + } + + /** + * Interface TestListener. + * + *

An error occurred while running the test. + * @param test the test. + * @param t the error. + */ + public void addError(Test test, Throwable t) { + formatError(ERROR, test, t); + } + + private void formatError(String type, Test test, Throwable t) { + if (test != null) { + endTest(test); + failedTests.put(test, test); + } + + Element nested = doc.createElement(type); + Element currentTest = null; + if (test != null) { + currentTest = (Element) testElements.get(test); + } else { + currentTest = rootElement; + } + + currentTest.appendChild(nested); + + String message = t.getMessage(); + if (message != null && message.length() > 0) { + nested.setAttribute(ATTR_MESSAGE, t.getMessage()); + } + nested.setAttribute(ATTR_TYPE, t.getClass().getName()); + + String strace = JUnitTestRunner.getFilteredTrace(t); + Text trace = doc.createTextNode(strace); + nested.appendChild(trace); + } + + private void formatOutput(String type, String output) { + Element nested = doc.createElement(type); + rootElement.appendChild(nested); + nested.appendChild(doc.createCDATASection(output)); + } + +} // XMLJUnitResultFormatter diff -Nru lua-unit-3.2/LICENSE.txt lua-unit-3.3/LICENSE.txt --- lua-unit-3.2/LICENSE.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/LICENSE.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,10 +1,12 @@ -This software is distributed under the BSD License. - -Copyright (c) 2005-2014, Philippe Fremy -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +This software is distributed under the BSD License. + +Copyright (c) 2005-2018, Philippe Fremy + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff -Nru lua-unit-3.2/.luacheckrc lua-unit-3.3/.luacheckrc --- lua-unit-3.2/.luacheckrc 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/.luacheckrc 2018-04-20 12:34:12.000000000 +0000 @@ -1,36 +1,26 @@ ---[[ -Luacheck configuration -(see http://luacheck.readthedocs.io/en/stable/config.html) -Thanks to Peter Melnichenko for providing an example file for LuaUnit. -]] - -only = {"1"} -- limit checks to the use of global variables -std = "max" - -files = { - ["luaunit.lua"] = { - ignore = {"LuaUnit", "EXPORT_ASSERT_TO_GLOBALS"} - }, - ["example_with_luaunit.lua"] = { - ignore = {"LuaUnit", "EXPORT_ASSERT_TO_GLOBALS", "[Tt]est[%w_]+", - "assertEquals", "assertNotEquals", "assertTrue", "assertFalse"} - }, - ["run_functional_tests.lua"] = { - ignore = {"test%w+"} - }, - ["test/compat_luaunit_v2x.lua"] = { - ignore = {"EXPORT_ASSERT_TO_GLOBALS", "[Tt]est[%w_]+", "assert[%w_]+"} - }, - ["test/legacy_example_with_luaunit.lua"] = { - ignore = {"LuaUnit", "EXPORT_ASSERT_TO_GLOBALS", "[Tt]est[%w_]+", - "assertEquals", "assertNotEquals", "assertTrue", "assertFalse"} - }, - ["test/test_luaunit.lua"] = { - ignore = {"TestMock", "TestLuaUnit%a+", "MyTest%w+"}}, - ["test/test_with_err_fail_pass.lua"] = { - ignore = {"[Tt]est[%w_]+"} - }, - ["test/test_with_xml.lua"] = { - ignore = {"Test%w+"} - } -} +--[[ +Luacheck configuration +(see http://luacheck.readthedocs.io/en/stable/config.html) +Thanks to Peter Melnichenko for providing an example file for LuaUnit. +]] + +only = {"1"} -- limit checks to the use of global variables +std = "max" +self = false +ignore = {"[Tt]est[%w_]+"} + +files = { + ["luaunit.lua"] = { + globals = {"EXPORT_ASSERT_TO_GLOBALS", "LuaUnit"}, + }, + ["test/compat_luaunit_v2x.lua"] = { + ignore = {"EXPORT_ASSERT_TO_GLOBALS", "assert[%w_]+", "v", "y"} + }, + ["test/legacy_example_with_luaunit.lua"] = { + ignore = {"LuaUnit", "EXPORT_ASSERT_TO_GLOBALS", + "assertEquals", "assertNotEquals", "assertTrue", "assertFalse"} + }, + ["test/test_luaunit.lua"] = { + ignore = {"TestMock", "TestLuaUnit%a+", "MyTest%w+", "v", "y" } + } +} diff -Nru lua-unit-3.2/luaunit-3.2.1-1.rockspec lua-unit-3.3/luaunit-3.2.1-1.rockspec --- lua-unit-3.2/luaunit-3.2.1-1.rockspec 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/luaunit-3.2.1-1.rockspec 1970-01-01 00:00:00.000000000 +0000 @@ -1,46 +0,0 @@ -package = "LuaUnit" -version = "3.2.1-1" -source = -{ - url = "git://github.com/bluebird75/luaunit", - - tag = "LUAUNIT_V3_2_1" -} - -description = -{ - summary = "A unit testing framework for Lua", - detailed = - [[ - Luaunit is a unit-testing framework for Lua. It allows you to write test functions and test classes with - test methods, combined with setup/teardown functionality. A wide range of assertions are supported. - - Luaunit supports several output format, like Junit or TAP, for easier integration into Continuous Integration - platforms (Jenkins, Maven, ...) . The integrated command-line options provide a flexible interface to select tests by name - or patterns, control output format, set verbosity, ... - - LuaUnit works with Lua 5.1, LuaJIT 2.0, LuaJIT 2.1 beta, Lua 5.2 and Lua 5.3 . It is tested on Windows Seven, Windows Server 2012 R2 (x64) and Ubuntu 14.04 (see continuous build results on Travis-CI and AppVeyor) and should work on all platforms supported by Lua. - It has no other dependency than Lua itself. - - **Important note when upgrading to version 3.1 and above** : break of backward compatibility, assertions functions are - no longer exported directly to the global namespace. See [documentation](http://luaunit.readthedocs.io/en/latest/#luaunit-global-asserts) on how to adjust or restore previous behavior. - - ]], - homepage = "http://github.com/bluebird75/luaunit", - license = "BSD" -} - -dependencies = -{ - "lua >= 5.1" -} - -build = -{ - type = "builtin", - modules = - { - luaunit = "luaunit.lua" - }, - -- copy_directories = { "doc/html" } -} diff -Nru lua-unit-3.2/luaunit-3.3-1.rockspec lua-unit-3.3/luaunit-3.3-1.rockspec --- lua-unit-3.2/luaunit-3.3-1.rockspec 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/luaunit-3.3-1.rockspec 2018-04-20 12:34:12.000000000 +0000 @@ -0,0 +1,48 @@ +package = "LuaUnit" +version = "3.3-1" +source = +{ + url = 'https://github.com/bluebird75/luaunit/releases/download/LUAUNIT_V3_3-RC1/rock-luaunit-3.3.zip' +} + +description = +{ + summary = "A unit testing framework for Lua", + detailed = + [[ + LuaUnit is a popular unit-testing framework for Lua, with an interface typical + of xUnit libraries (Python unittest, Junit, NUnit, ...). It supports + several output formats (Text, TAP, JUnit, ...) to be used directly or work with Continuous Integration platforms + (Jenkins, Hudson, ...). + + For simplicity, LuaUnit is contained into a single-file and has no external dependency. + + Tutorial and reference documentation is available on + [read-the-docs](http://luaunit.readthedocs.org/en/latest/) + + LuaUnit may also be used as an assertion library, to validate assertions inside a running program. In addition, it provides + a pretty stringifier which converts any type into a nicely formatted string (including complex nested or recursive tables). + + To install LuaUnit from LuaRocks, you need at least LuaRocks version 2.4.4 (due to old versions of wget being incompatible + with GitHub https downloading) + + ]], + homepage = "http://github.com/bluebird75/luaunit", + license = "BSD", + maintainer = 'Philippe Fremy ', +} + +dependencies = +{ + "lua >= 5.1", "lua < 5.4" +} + +build = +{ + type = "builtin", + modules = + { + luaunit = "luaunit.lua" + }, + copy_directories = { "doc", "test" } +} diff -Nru lua-unit-3.2/luaunit.lua lua-unit-3.3/luaunit.lua --- lua-unit-3.2/luaunit.lua 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/luaunit.lua 2018-04-20 12:34:12.000000000 +0000 @@ -1,2202 +1,3044 @@ ---[[ - luaunit.lua - -Description: A unit testing framework -Homepage: https://github.com/bluebird75/luaunit -Development by Philippe Fremy -Based on initial work of Ryu, Gwang (http://www.gpgstudy.com/gpgiki/LuaUnit) -License: BSD License, see LICENSE.txt -Version: 3.2 -]]-- - -require("math") -local M={} - --- private exported functions (for testing) -M.private = {} - -M.VERSION='3.2' -M._VERSION=M.VERSION -- For LuaUnit v2 compatibility - ---[[ Some people like assertEquals( actual, expected ) and some people prefer -assertEquals( expected, actual ). -]]-- -M.ORDER_ACTUAL_EXPECTED = true -M.PRINT_TABLE_REF_IN_ERROR_MSG = false -M.TABLE_EQUALS_KEYBYCONTENT = true -M.LINE_LENGTH=80 - --- set this to false to debug luaunit -local STRIP_LUAUNIT_FROM_STACKTRACE=true - -M.VERBOSITY_DEFAULT = 10 -M.VERBOSITY_LOW = 1 -M.VERBOSITY_QUIET = 0 -M.VERBOSITY_VERBOSE = 20 - --- set EXPORT_ASSERT_TO_GLOBALS to have all asserts visible as global values --- EXPORT_ASSERT_TO_GLOBALS = true - --- we need to keep a copy of the script args before it is overriden -local cmdline_argv = rawget(_G, "arg") - -M.FAILURE_PREFIX = 'LuaUnit test FAILURE: ' -- prefix string for failed tests - -M.USAGE=[[Usage: lua [options] [testname1 [testname2] ... ] -Options: - -h, --help: Print this help - --version: Print version information - -v, --verbose: Increase verbosity - -q, --quiet: Set verbosity to minimum - -e, --error: Stop on first error - -f, --failure: Stop on first failure or error - -o, --output OUTPUT: Set output type to OUTPUT - Possible values: text, tap, junit, nil - -n, --name NAME: For junit only, mandatory name of xml file - -p, --pattern PATTERN: Execute all test names matching the Lua PATTERN - May be repeated to include severals patterns - Make sure you escape magic chars like +? with % - testname1, testname2, ... : tests to run in the form of testFunction, - TestClass or TestClass.testMethod -]] - ----------------------------------------------------------------- --- --- general utility functions --- ----------------------------------------------------------------- - -local crossTypeOrdering = { - number = 1, - boolean = 2, - string = 3, - table = 4, - other = 5 -} -local crossTypeComparison = { - number = function(a, b) return a < b end, - string = function(a, b) return a < b end, - other = function(a, b) return tostring(a) < tostring(b) end, -} - -local function crossTypeSort(a, b) - local type_a, type_b = type(a), type(b) - if type_a == type_b then - local func = crossTypeComparison[type_a] or crossTypeComparison.other - return func(a, b) - end - type_a = crossTypeOrdering[type_a] or crossTypeOrdering.other - type_b = crossTypeOrdering[type_b] or crossTypeOrdering.other - return type_a < type_b -end - -local function __genSortedIndex( t ) - -- Returns a sequence consisting of t's keys, sorted. - local sortedIndex = {} - - for key,_ in pairs(t) do - table.insert(sortedIndex, key) - end - - table.sort(sortedIndex, crossTypeSort) - return sortedIndex -end -M.private.__genSortedIndex = __genSortedIndex - -local function sortedNext(state, control) - -- Equivalent of the next() function of table iteration, but returns the - -- keys in sorted order (see __genSortedIndex and crossTypeSort). - -- The state is a temporary variable during iteration and contains the - -- sorted key table (state.sortedIdx). It also stores the last index (into - -- the keys) used by the iteration, to find the next one quickly. - local key - - --print("sortedNext: control = "..tostring(control) ) - if control == nil then - -- start of iteration - state.lastIdx = 1 - key = state.sortedIdx[1] - return key, state.t[key] - end - - -- normally, we expect the control variable to match the last key used - if control ~= state.sortedIdx[state.lastIdx] then - -- strange, we have to find the next value by ourselves - -- the key table is sorted in crossTypeSort() order! -> use bisection - local count = #state.sortedIdx - local lower, upper = 1, count - repeat - state.lastIdx = math.modf((lower + upper) / 2) - key = state.sortedIdx[state.lastIdx] - if key == control then break; end -- key found (and thus prev index) - if crossTypeSort(key, control) then - -- key < control, continue search "right" (towards upper bound) - lower = state.lastIdx + 1 - else - -- key > control, continue search "left" (towards lower bound) - upper = state.lastIdx - 1 - end - until lower > upper - if lower > upper then -- only true if the key wasn't found, ... - state.lastIdx = count -- ... so ensure no match for the code below - end - end - - -- proceed by retrieving the next value (or nil) from the sorted keys - state.lastIdx = state.lastIdx + 1 - key = state.sortedIdx[state.lastIdx] - if key then - return key, state.t[key] - end - - -- getting here means returning `nil`, which will end the iteration -end - -local function sortedPairs(tbl) - -- Equivalent of the pairs() function on tables. Allows to iterate in - -- sorted order. As required by "generic for" loops, this will return the - -- iterator (function), an "invariant state", and the initial control value. - -- (see http://www.lua.org/pil/7.2.html) - return sortedNext, {t = tbl, sortedIdx = __genSortedIndex(tbl)}, nil -end -M.private.sortedPairs = sortedPairs - -local function strsplit(delimiter, text) --- Split text into a list consisting of the strings in text, separated --- by strings matching delimiter (which may _NOT_ be a pattern). --- Example: strsplit(", ", "Anna, Bob, Charlie, Dolores") - if delimiter == "" then -- this would result in endless loops - error("delimiter matches empty string!") - end - local list, pos, first, last = {}, 1 - while true do - first, last = text:find(delimiter, pos, true) - if first then -- found? - table.insert(list, text:sub(pos, first - 1)) - pos = last + 1 - else - table.insert(list, text:sub(pos)) - break - end - end - return list -end -M.private.strsplit = strsplit - -local function hasNewLine( s ) - -- return true if s has a newline - return (string.find(s, '\n', 1, true) ~= nil) -end -M.private.hasNewLine = hasNewLine - -local function prefixString( prefix, s ) - -- Prefix all the lines of s with prefix - return prefix .. string.gsub(s, '\n', '\n' .. prefix) -end -M.private.prefixString = prefixString - -local function strMatch(s, pattern, start, final ) - -- return true if s matches completely the pattern from index start to index end - -- return false in every other cases - -- if start is nil, matches from the beginning of the string - -- if final is nil, matches to the end of the string - start = start or 1 - final = final or string.len(s) - - local foundStart, foundEnd = string.find(s, pattern, start, false) - return foundStart == start and foundEnd == final -end -M.private.strMatch = strMatch - -local function xmlEscape( s ) - -- Return s escaped for XML attributes - -- escapes table: - -- " " - -- ' ' - -- < < - -- > > - -- & & - - return string.gsub( s, '.', { - ['&'] = "&", - ['"'] = """, - ["'"] = "'", - ['<'] = "<", - ['>'] = ">", - } ) -end -M.private.xmlEscape = xmlEscape - -local function xmlCDataEscape( s ) - -- Return s escaped for CData section, escapes: "]]>" - return string.gsub( s, ']]>', ']]>' ) -end -M.private.xmlCDataEscape = xmlCDataEscape - -local function stripLuaunitTrace( stackTrace ) - --[[ - -- Example of a traceback: - < - [C]: in function 'xpcall' - ./luaunit.lua:1449: in function 'protectedCall' - ./luaunit.lua:1508: in function 'execOneFunction' - ./luaunit.lua:1596: in function 'runSuiteByInstances' - ./luaunit.lua:1660: in function 'runSuiteByNames' - ./luaunit.lua:1736: in function 'runSuite' - example_with_luaunit.lua:140: in main chunk - [C]: in ?>> - - Other example: - < - [C]: in function 'xpcall' - ./luaunit.lua:1517: in function 'protectedCall' - ./luaunit.lua:1578: in function 'execOneFunction' - ./luaunit.lua:1677: in function 'runSuiteByInstances' - ./luaunit.lua:1730: in function 'runSuiteByNames' - ./luaunit.lua:1806: in function 'runSuite' - example_with_luaunit.lua:140: in main chunk - [C]: in ?>> - - < - [C]: in function 'xpcall' - luaunit2/luaunit.lua:1532: in function 'protectedCall' - luaunit2/luaunit.lua:1591: in function 'execOneFunction' - luaunit2/luaunit.lua:1679: in function 'runSuiteByInstances' - luaunit2/luaunit.lua:1743: in function 'runSuiteByNames' - luaunit2/luaunit.lua:1819: in function 'runSuite' - luaunit2/example_with_luaunit.lua:140: in main chunk - [C]: in ?>> - - - -- first line is "stack traceback": KEEP - -- next line may be luaunit line: REMOVE - -- next lines are call in the program under testOk: REMOVE - -- next lines are calls from luaunit to call the program under test: KEEP - - -- Strategy: - -- keep first line - -- remove lines that are part of luaunit - -- kepp lines until we hit a luaunit line - ]] - - local function isLuaunitInternalLine( s ) - -- return true if line of stack trace comes from inside luaunit - return s:find('[/\\]luaunit%.lua:%d+: ') ~= nil - end - - -- print( '<<'..stackTrace..'>>' ) - - local t = strsplit( '\n', stackTrace ) - -- print( prettystr(t) ) - - local idx = 2 - - -- remove lines that are still part of luaunit - while t[idx] and isLuaunitInternalLine( t[idx] ) do - -- print('Removing : '..t[idx] ) - table.remove(t, idx) - end - - -- keep lines until we hit luaunit again - while t[idx] and (not isLuaunitInternalLine(t[idx])) do - -- print('Keeping : '..t[idx] ) - idx = idx + 1 - end - - -- remove remaining luaunit lines - while t[idx] do - -- print('Removing : '..t[idx] ) - table.remove(t, idx) - end - - -- print( prettystr(t) ) - return table.concat( t, '\n') - -end -M.private.stripLuaunitTrace = stripLuaunitTrace - - -local function prettystr_sub(v, indentLevel, keeponeline, printTableRefs, recursionTable ) - local type_v = type(v) - if "string" == type_v then - if keeponeline then v = v:gsub("\n", "\\n") end - - -- use clever delimiters according to content: - -- enclose with single quotes if string contains ", but no ' - if v:find('"', 1, true) and not v:find("'", 1, true) then - return "'" .. v .. "'" - end - -- use double quotes otherwise, escape embedded " - return '"' .. v:gsub('"', '\\"') .. '"' - - elseif "table" == type_v then - --if v.__class__ then - -- return string.gsub( tostring(v), 'table', v.__class__ ) - --end - return M.private._table_tostring(v, indentLevel, printTableRefs, recursionTable) - end - - return tostring(v) -end - -local function prettystr( v, keeponeline ) - --[[ Better string conversion, to display nice variable content: - For strings, if keeponeline is set to true, string is displayed on one line, with visible \n - * string are enclosed with " by default, or with ' if string contains a " - * if table is a class, display class name - * tables are expanded - ]]-- - local recursionTable = {} - local s = prettystr_sub(v, 1, keeponeline, M.PRINT_TABLE_REF_IN_ERROR_MSG, recursionTable) - if recursionTable.recursionDetected and not M.PRINT_TABLE_REF_IN_ERROR_MSG then - -- some table contain recursive references, - -- so we must recompute the value by including all table references - -- else the result looks like crap - recursionTable = {} - s = prettystr_sub(v, 1, keeponeline, true, recursionTable) - end - return s -end -M.prettystr = prettystr - -local function prettystrPadded(value1, value2, suffix_a, suffix_b) - --[[ - This function helps with the recurring task of constructing the "expected - vs. actual" error messages. It takes two arbitrary values and formats - corresponding strings with prettystr(). - - To keep the (possibly complex) output more readable in case the resulting - strings contain line breaks, they get automatically prefixed with additional - newlines. Both suffixes are optional (default to empty strings), and get - appended to the "value1" string. "suffix_a" is used if line breaks were - encountered, "suffix_b" otherwise. - - Returns the two formatted strings (including padding/newlines). - ]] - local str1, str2 = prettystr(value1), prettystr(value2) - if hasNewLine(str1) or hasNewLine(str2) then - -- line break(s) detected, add padding - return "\n" .. str1 .. (suffix_a or ""), "\n" .. str2 - end - return str1 .. (suffix_b or ""), str2 -end -M.private.prettystrPadded = prettystrPadded - -local function _table_keytostring(k) - -- like prettystr but do not enclose with "" if the string is just alphanumerical - -- this is better for displaying table keys who are often simple strings - if "string" == type(k) and k:match("^[_%a][_%w]*$") then - return k - end - return prettystr(k) -end -M.private._table_keytostring = _table_keytostring - -local TABLE_TOSTRING_SEP = ", " -local TABLE_TOSTRING_SEP_LEN = string.len(TABLE_TOSTRING_SEP) - -local function _table_tostring( tbl, indentLevel, printTableRefs, recursionTable ) - printTableRefs = printTableRefs or M.PRINT_TABLE_REF_IN_ERROR_MSG - recursionTable = recursionTable or {} - recursionTable[tbl] = true - - local result, dispOnMultLines = {}, false - - local entry, count, seq_index = nil, 0, 1 - for k, v in sortedPairs( tbl ) do - if k == seq_index then - -- for the sequential part of tables, we'll skip the "=" output - entry = '' - seq_index = seq_index + 1 - else - entry = _table_keytostring( k ) .. "=" - end - if recursionTable[v] then -- recursion detected! - recursionTable.recursionDetected = true - entry = entry .. "<"..tostring(v)..">" - else - entry = entry .. - prettystr_sub( v, indentLevel+1, true, printTableRefs, recursionTable ) - end - count = count + 1 - result[count] = entry - end - - -- set dispOnMultLines if the maximum LINE_LENGTH would be exceeded - local totalLength = 0 - for k, v in ipairs( result ) do - totalLength = totalLength + string.len( v ) - if totalLength >= M.LINE_LENGTH then - dispOnMultLines = true - break - end - end - - if not dispOnMultLines then - -- adjust with length of separator(s): - -- two items need 1 sep, three items two seps, ... plus len of '{}' - if count > 0 then - totalLength = totalLength + TABLE_TOSTRING_SEP_LEN * (count - 1) - end - dispOnMultLines = totalLength + 2 >= M.LINE_LENGTH - end - - -- now reformat the result table (currently holding element strings) - if dispOnMultLines then - local indentString = string.rep(" ", indentLevel - 1) - result = {"{\n ", indentString, - table.concat(result, ",\n " .. indentString), "\n", - indentString, "}"} - else - result = {"{", table.concat(result, TABLE_TOSTRING_SEP), "}"} - end - if printTableRefs then - table.insert(result, 1, "<"..tostring(tbl).."> ") -- prepend table ref - end - return table.concat(result) -end -M.private._table_tostring = _table_tostring -- prettystr_sub() needs it - -local function _table_contains(t, element) - if type(t) == "table" then - local type_e = type(element) - for _, value in pairs(t) do - if type(value) == type_e then - if value == element then - return true - end - if type_e == 'table' then - -- if we wanted recursive items content comparison, we could use - -- _is_table_items_equals(v, expected) but one level of just comparing - -- items is sufficient - if M.private._is_table_equals( value, element ) then - return true - end - end - end - end - end - return false -end - -local function _is_table_items_equals(actual, expected ) - local type_a, type_e = type(actual), type(expected) - - if (type_a == 'table') and (type_e == 'table') then - for k, v in pairs(actual) do - if not _table_contains(expected, v) then - return false - end - end - for k, v in pairs(expected) do - if not _table_contains(actual, v) then - return false - end - end - return true - - elseif type_a ~= type_e then - return false - - elseif actual ~= expected then - return false - end - - return true -end - -local function _is_table_equals(actual, expected, recursions) - local type_a, type_e = type(actual), type(expected) - recursions = recursions or {} - - if type_a ~= type_e then - return false -- different types won't match - end - - if (type_a == 'table') --[[ and (type_e == 'table') ]] and not recursions[actual] then - -- Tables must have identical element count, or they can't match. - if (#actual ~= #expected) then - return false - end - - -- add "actual" to the recursions table, to detect and avoid loops - recursions[actual] = true - - local actualKeysMatched, actualTableKeys = {}, {} - - for k, v in pairs(actual) do - if M.TABLE_EQUALS_KEYBYCONTENT and type(k) == "table" then - -- If the keys are tables, things get a bit tricky here as we - -- can have _is_table_equals(k1, k2) and t[k1] ~= t[k2]. So we - -- collect actual's table keys, group them by length for - -- performance, and then for each table key in expected we look - -- it up in actualTableKeys. - local count = #k - if not actualTableKeys[count] then actualTableKeys[count] = {} end - table.insert(actualTableKeys[count], k) - else - if not _is_table_equals(v, expected[k], recursions) then - return false -- Mismatch on value, tables can't be equal - end - actualKeysMatched[k] = true -- Keep track of matched keys - end - end - - for k, v in pairs(expected) do - if M.TABLE_EQUALS_KEYBYCONTENT and type(k) == "table" then - local candidates, found = actualTableKeys[#k], nil - if not candidates then return false end - for i, candidate in pairs(candidates) do - if _is_table_equals(candidate, k) then - found = candidate - -- Remove the candidate we matched against from the list - -- of candidates, so each key in actual can only match - -- one key in expected. - candidates[i] = nil - break - end - end - if not(found and _is_table_equals(actual[found], v)) then - -- Either no matching key, or a different value - return false - end - else - if not actualKeysMatched[k] then - -- Found a key that we did not see in "actual" -> mismatch - return false - end - -- Otherwise we know that actual[k] was already matched - -- against v = expected[k]. Remove k from the table again. - actualKeysMatched[k] = nil - end - end - - -- If we have any keys left in the actualKeysMatched table, then those - -- were missing from "expected", meaning the tables are different. - if next(actualKeysMatched) then return false end - - if M.TABLE_EQUALS_KEYBYCONTENT then - for _, keys in pairs(actualTableKeys) do - -- if there are any keys left in any actualTableKeys[i] then - -- that is a key in actual with no matching key in expected, - -- and so the tables aren't equal. - if next(keys) then return false end - end - end - - return true - - elseif actual ~= expected then - return false - end - - return true -end -M.private._is_table_equals = _is_table_equals - -local function failure(msg, level) - -- raise an error indicating a test failure - -- for error() compatibility we adjust "level" here (by +1), to report the - -- calling context - error(M.FAILURE_PREFIX .. msg, (level or 1) + 1) -end - -local function fail_fmt(level, ...) - -- failure with printf-style formatted message and given error level - failure(string.format(...), (level or 1) + 1) -end -M.private.fail_fmt = fail_fmt - -local function error_fmt(level, ...) - -- printf-style error() - error(string.format(...), (level or 1) + 1) -end - ----------------------------------------------------------------- --- --- assertions --- ----------------------------------------------------------------- - -local function errorMsgEquality(actual, expected) - if not M.ORDER_ACTUAL_EXPECTED then - expected, actual = actual, expected - end - if type(expected) == 'string' or type(expected) == 'table' then - expected, actual = prettystrPadded(expected, actual) - return string.format("expected: %s\nactual: %s", expected, actual) - end - return string.format("expected: %s, actual: %s", - prettystr(expected), prettystr(actual)) -end - -function M.assertError(f, ...) - -- assert that calling f with the arguments will raise an error - -- example: assertError( f, 1, 2 ) => f(1,2) should generate an error - if pcall( f, ... ) then - failure( "Expected an error when calling function but no error generated", 2 ) - end -end - -function M.assertTrue(value) - if not value then - failure("expected: true, actual: " ..prettystr(value), 2) - end -end - -function M.assertFalse(value) - if value then - failure("expected: false, actual: " ..prettystr(value), 2) - end -end - -function M.assertIsNil(value) - if value ~= nil then - failure("expected: nil, actual: " ..prettystr(value), 2) - end -end - -function M.assertNotIsNil(value) - if value == nil then - failure("expected non nil value, received nil", 2) - end -end - -function M.assertEquals(actual, expected) - if type(actual) == 'table' and type(expected) == 'table' then - if not _is_table_equals(actual, expected) then - failure( errorMsgEquality(actual, expected), 2 ) - end - elseif type(actual) ~= type(expected) then - failure( errorMsgEquality(actual, expected), 2 ) - elseif actual ~= expected then - failure( errorMsgEquality(actual, expected), 2 ) - end -end - --- Help Lua in corner cases like almostEquals(1.1, 1.0, 0.1), which by default --- may not work. We need to give margin a small boost; EPSILON defines the --- default value to use for this: -local EPSILON = 1E-11 -function M.almostEquals( actual, expected, margin, margin_boost ) - if type(actual) ~= 'number' or type(expected) ~= 'number' or type(margin) ~= 'number' then - error_fmt(3, 'almostEquals: must supply only number arguments.\nArguments supplied: %s, %s, %s', - prettystr(actual), prettystr(expected), prettystr(margin)) - end - if margin < 0 then - error('almostEquals: margin must not be negative, current value is ' .. margin, 3) - end - local realmargin = margin + (margin_boost or EPSILON) - return math.abs(expected - actual) <= realmargin -end - -function M.assertAlmostEquals( actual, expected, margin ) - -- check that two floats are close by margin - if not M.almostEquals(actual, expected, margin) then - if not M.ORDER_ACTUAL_EXPECTED then - expected, actual = actual, expected - end - fail_fmt(2, 'Values are not almost equal\nExpected: %s with margin of %s, received: %s', - expected, margin, actual) - end -end - -function M.assertNotEquals(actual, expected) - if type(actual) ~= type(expected) then - return - end - - if type(actual) == 'table' and type(expected) == 'table' then - if not _is_table_equals(actual, expected) then - return - end - elseif actual ~= expected then - return - end - fail_fmt(2, 'Received the not expected value: %s', prettystr(actual)) -end - -function M.assertNotAlmostEquals( actual, expected, margin ) - -- check that two floats are not close by margin - if M.almostEquals(actual, expected, margin) then - if not M.ORDER_ACTUAL_EXPECTED then - expected, actual = actual, expected - end - fail_fmt(2, 'Values are almost equal\nExpected: %s with a difference above margin of %s, received: %s', - expected, margin, actual) - end -end - -function M.assertStrContains( str, sub, useRe ) - -- this relies on lua string.find function - -- a string always contains the empty string - if not string.find(str, sub, 1, not useRe) then - sub, str = prettystrPadded(sub, str, '\n') - fail_fmt(2, 'Error, %s %s was not found in string %s', - useRe and 'regexp' or 'substring', sub, str) - end -end - -function M.assertStrIContains( str, sub ) - -- this relies on lua string.find function - -- a string always contains the empty string - if not string.find(str:lower(), sub:lower(), 1, true) then - sub, str = prettystrPadded(sub, str, '\n') - fail_fmt(2, 'Error, substring %s was not found (case insensitively) in string %s', - sub, str) - end -end - -function M.assertNotStrContains( str, sub, useRe ) - -- this relies on lua string.find function - -- a string always contains the empty string - if string.find(str, sub, 1, not useRe) then - sub, str = prettystrPadded(sub, str, '\n') - fail_fmt(2, 'Error, %s %s was found in string %s', - useRe and 'regexp' or 'substring', sub, str) - end -end - -function M.assertNotStrIContains( str, sub ) - -- this relies on lua string.find function - -- a string always contains the empty string - if string.find(str:lower(), sub:lower(), 1, true) then - sub, str = prettystrPadded(sub, str, '\n') - fail_fmt(2, 'Error, substring %s was found (case insensitively) in string %s', - sub, str) - end -end - -function M.assertStrMatches( str, pattern, start, final ) - -- Verify a full match for the string - -- for a partial match, simply use assertStrContains with useRe set to true - if not strMatch( str, pattern, start, final ) then - pattern, str = prettystrPadded(pattern, str, '\n') - fail_fmt(2, 'Error, pattern %s was not matched by string %s', - pattern, str) - end -end - -function M.assertErrorMsgEquals( expectedMsg, func, ... ) - -- assert that calling f with the arguments will raise an error - -- example: assertError( f, 1, 2 ) => f(1,2) should generate an error - local no_error, error_msg = pcall( func, ... ) - if no_error then - failure( 'No error generated when calling function but expected error: "'..expectedMsg..'"', 2 ) - end - if error_msg ~= expectedMsg then - error_msg, expectedMsg = prettystrPadded(error_msg, expectedMsg) - fail_fmt(2, 'Exact error message expected: %s\nError message received: %s\n', - expectedMsg, error_msg) - end -end - -function M.assertErrorMsgContains( partialMsg, func, ... ) - -- assert that calling f with the arguments will raise an error - -- example: assertError( f, 1, 2 ) => f(1,2) should generate an error - local no_error, error_msg = pcall( func, ... ) - if no_error then - failure( 'No error generated when calling function but expected error containing: '..prettystr(partialMsg), 2 ) - end - if not string.find( error_msg, partialMsg, nil, true ) then - error_msg, partialMsg = prettystrPadded(error_msg, partialMsg) - fail_fmt(2, 'Error message does not contain: %s\nError message received: %s\n', - partialMsg, error_msg) - end -end - -function M.assertErrorMsgMatches( expectedMsg, func, ... ) - -- assert that calling f with the arguments will raise an error - -- example: assertError( f, 1, 2 ) => f(1,2) should generate an error - local no_error, error_msg = pcall( func, ... ) - if no_error then - failure( 'No error generated when calling function but expected error matching: "'..expectedMsg..'"', 2 ) - end - if not strMatch( error_msg, expectedMsg ) then - expectedMsg, error_msg = prettystrPadded(expectedMsg, error_msg) - fail_fmt(2, 'Error message does not match: %s\nError message received: %s\n', - expectedMsg, error_msg) - end -end - ---[[ -Add type assertion functions to the module table M. Each of these functions -takes a single parameter "value", and checks that its Lua type matches the -expected string (derived from the function name): - -M.assertIsXxx(value) -> ensure that type(value) conforms to "xxx" -]] -for _, funcName in ipairs( - {'assertIsNumber', 'assertIsString', 'assertIsTable', 'assertIsBoolean', - 'assertIsFunction', 'assertIsUserdata', 'assertIsThread'} -) do - local typeExpected = funcName:match("^assertIs([A-Z]%a*)$") - -- Lua type() always returns lowercase, also make sure the match() succeeded - typeExpected = typeExpected and typeExpected:lower() - or error("bad function name '"..funcName.."' for type assertion") - - M[funcName] = function(value) - if type(value) ~= typeExpected then - fail_fmt(2, 'Expected: a %s value, actual: type %s, value %s', - typeExpected, type(value), prettystrPadded(value)) - end - end -end - ---[[ -Add shortcuts for verifying type of a variable, without failure (luaunit v2 compatibility) -M.isXxx(value) -> returns true if type(value) conforms to "xxx" -]] -for _, typeExpected in ipairs( - {'Number', 'String', 'Table', 'Boolean', - 'Function', 'Userdata', 'Thread', 'Nil' } -) do - local typeExpectedLower = typeExpected:lower() - local isType = function(value) - return (type(value) == typeExpectedLower) - end - M['is'..typeExpected] = isType - M['is_'..typeExpectedLower] = isType -end - ---[[ -Add non-type assertion functions to the module table M. Each of these functions -takes a single parameter "value", and checks that its Lua type differs from the -expected string (derived from the function name): - -M.assertNotIsXxx(value) -> ensure that type(value) is not "xxx" -]] -for _, funcName in ipairs( - {'assertNotIsNumber', 'assertNotIsString', 'assertNotIsTable', 'assertNotIsBoolean', - 'assertNotIsFunction', 'assertNotIsUserdata', 'assertNotIsThread'} -) do - local typeUnexpected = funcName:match("^assertNotIs([A-Z]%a*)$") - -- Lua type() always returns lowercase, also make sure the match() succeeded - typeUnexpected = typeUnexpected and typeUnexpected:lower() - or error("bad function name '"..funcName.."' for type assertion") - - M[funcName] = function(value) - if type(value) == typeUnexpected then - fail_fmt(2, 'Not expected: a %s type, actual: value %s', - typeUnexpected, prettystrPadded(value)) - end - end -end - -function M.assertIs(actual, expected) - if actual ~= expected then - if not M.ORDER_ACTUAL_EXPECTED then - actual, expected = expected, actual - end - expected, actual = prettystrPadded(expected, actual, '\n', ', ') - fail_fmt(2, 'Expected object and actual object are not the same\nExpected: %sactual: %s', - expected, actual) - end -end - -function M.assertNotIs(actual, expected) - if actual == expected then - if not M.ORDER_ACTUAL_EXPECTED then - expected = actual - end - fail_fmt(2, 'Expected object and actual object are the same object: %s', - prettystrPadded(expected)) - end -end - -function M.assertItemsEquals(actual, expected) - -- checks that the items of table expected - -- are contained in table actual. Warning, this function - -- is at least O(n^2) - if not _is_table_items_equals(actual, expected ) then - expected, actual = prettystrPadded(expected, actual) - fail_fmt(2, 'Contents of the tables are not identical:\nExpected: %s\nActual: %s', - expected, actual) - end -end - ----------------------------------------------------------------- --- Compatibility layer ----------------------------------------------------------------- - --- for compatibility with LuaUnit v2.x -function M.wrapFunctions(...) - -- In LuaUnit version <= 2.1 , this function was necessary to include - -- a test function inside the global test suite. Nowadays, the functions - -- are simply run directly as part of the test discovery process. - -- so just do nothing ! - io.stderr:write[[Use of WrapFunctions() is no longer needed. -Just prefix your test function names with "test" or "Test" and they -will be picked up and run by LuaUnit. -]] -end - -local list_of_funcs = { - -- { official function name , alias } - - -- general assertions - { 'assertEquals' , 'assert_equals' }, - { 'assertItemsEquals' , 'assert_items_equals' }, - { 'assertNotEquals' , 'assert_not_equals' }, - { 'assertAlmostEquals' , 'assert_almost_equals' }, - { 'assertNotAlmostEquals' , 'assert_not_almost_equals' }, - { 'assertTrue' , 'assert_true' }, - { 'assertFalse' , 'assert_false' }, - { 'assertStrContains' , 'assert_str_contains' }, - { 'assertStrIContains' , 'assert_str_icontains' }, - { 'assertNotStrContains' , 'assert_not_str_contains' }, - { 'assertNotStrIContains' , 'assert_not_str_icontains' }, - { 'assertStrMatches' , 'assert_str_matches' }, - { 'assertError' , 'assert_error' }, - { 'assertErrorMsgEquals' , 'assert_error_msg_equals' }, - { 'assertErrorMsgContains' , 'assert_error_msg_contains' }, - { 'assertErrorMsgMatches' , 'assert_error_msg_matches' }, - { 'assertIs' , 'assert_is' }, - { 'assertNotIs' , 'assert_not_is' }, - { 'wrapFunctions' , 'WrapFunctions' }, - { 'wrapFunctions' , 'wrap_functions' }, - - -- type assertions: assertIsXXX -> assert_is_xxx - { 'assertIsNumber' , 'assert_is_number' }, - { 'assertIsString' , 'assert_is_string' }, - { 'assertIsTable' , 'assert_is_table' }, - { 'assertIsBoolean' , 'assert_is_boolean' }, - { 'assertIsNil' , 'assert_is_nil' }, - { 'assertIsFunction' , 'assert_is_function' }, - { 'assertIsThread' , 'assert_is_thread' }, - { 'assertIsUserdata' , 'assert_is_userdata' }, - - -- type assertions: assertIsXXX -> assertXxx - { 'assertIsNumber' , 'assertNumber' }, - { 'assertIsString' , 'assertString' }, - { 'assertIsTable' , 'assertTable' }, - { 'assertIsBoolean' , 'assertBoolean' }, - { 'assertIsNil' , 'assertNil' }, - { 'assertIsFunction' , 'assertFunction' }, - { 'assertIsThread' , 'assertThread' }, - { 'assertIsUserdata' , 'assertUserdata' }, - - -- type assertions: assertIsXXX -> assert_xxx (luaunit v2 compat) - { 'assertIsNumber' , 'assert_number' }, - { 'assertIsString' , 'assert_string' }, - { 'assertIsTable' , 'assert_table' }, - { 'assertIsBoolean' , 'assert_boolean' }, - { 'assertIsNil' , 'assert_nil' }, - { 'assertIsFunction' , 'assert_function' }, - { 'assertIsThread' , 'assert_thread' }, - { 'assertIsUserdata' , 'assert_userdata' }, - - -- type assertions: assertNotIsXXX -> assert_not_is_xxx - { 'assertNotIsNumber' , 'assert_not_is_number' }, - { 'assertNotIsString' , 'assert_not_is_string' }, - { 'assertNotIsTable' , 'assert_not_is_table' }, - { 'assertNotIsBoolean' , 'assert_not_is_boolean' }, - { 'assertNotIsNil' , 'assert_not_is_nil' }, - { 'assertNotIsFunction' , 'assert_not_is_function' }, - { 'assertNotIsThread' , 'assert_not_is_thread' }, - { 'assertNotIsUserdata' , 'assert_not_is_userdata' }, - - -- type assertions: assertNotIsXXX -> assertNotXxx (luaunit v2 compat) - { 'assertNotIsNumber' , 'assertNotNumber' }, - { 'assertNotIsString' , 'assertNotString' }, - { 'assertNotIsTable' , 'assertNotTable' }, - { 'assertNotIsBoolean' , 'assertNotBoolean' }, - { 'assertNotIsNil' , 'assertNotNil' }, - { 'assertNotIsFunction' , 'assertNotFunction' }, - { 'assertNotIsThread' , 'assertNotThread' }, - { 'assertNotIsUserdata' , 'assertNotUserdata' }, - - -- type assertions: assertNotIsXXX -> assert_not_xxx - { 'assertNotIsNumber' , 'assert_not_number' }, - { 'assertNotIsString' , 'assert_not_string' }, - { 'assertNotIsTable' , 'assert_not_table' }, - { 'assertNotIsBoolean' , 'assert_not_boolean' }, - { 'assertNotIsNil' , 'assert_not_nil' }, - { 'assertNotIsFunction' , 'assert_not_function' }, - { 'assertNotIsThread' , 'assert_not_thread' }, - { 'assertNotIsUserdata' , 'assert_not_userdata' }, - - -- all assertions with Coroutine duplicate Thread assertions - { 'assertIsThread' , 'assertIsCoroutine' }, - { 'assertIsThread' , 'assertCoroutine' }, - { 'assertIsThread' , 'assert_is_coroutine' }, - { 'assertIsThread' , 'assert_coroutine' }, - { 'assertNotIsThread' , 'assertNotIsCoroutine' }, - { 'assertNotIsThread' , 'assertNotCoroutine' }, - { 'assertNotIsThread' , 'assert_not_is_coroutine' }, - { 'assertNotIsThread' , 'assert_not_coroutine' }, -} - --- Create all aliases in M -for _,v in ipairs( list_of_funcs ) do - local funcname, alias = v[1], v[2] - M[alias] = M[funcname] - - if EXPORT_ASSERT_TO_GLOBALS then - _G[funcname] = M[funcname] - _G[alias] = M[funcname] - end -end - ----------------------------------------------------------------- --- --- Outputters --- ----------------------------------------------------------------- - --- A common "base" class for outputters --- For concepts involved (class inheritance) see http://www.lua.org/pil/16.2.html - -local genericOutput = { __class__ = 'genericOutput' } -- class -local genericOutput_MT = { __index = genericOutput } -- metatable -M.genericOutput = genericOutput -- publish, so that custom classes may derive from it - -function genericOutput.new(runner, default_verbosity) - -- runner is the "parent" object controlling the output, usually a LuaUnit instance - local t = { runner = runner } - if runner then - t.result = runner.result - t.verbosity = runner.verbosity or default_verbosity - t.fname = runner.fname - else - t.verbosity = default_verbosity - end - return setmetatable( t, genericOutput_MT) -end - --- abstract ("empty") methods -function genericOutput:startSuite() end -function genericOutput:startClass(className) end -function genericOutput:startTest(testName) end -function genericOutput:addStatus(node) end -function genericOutput:endTest(node) end -function genericOutput:endClass() end -function genericOutput:endSuite() end - - ----------------------------------------------------------------- --- class TapOutput ----------------------------------------------------------------- - -local TapOutput = genericOutput.new() -- derived class -local TapOutput_MT = { __index = TapOutput } -- metatable -TapOutput.__class__ = 'TapOutput' - - -- For a good reference for TAP format, check: http://testanything.org/tap-specification.html - - function TapOutput.new(runner) - local t = genericOutput.new(runner, M.VERBOSITY_LOW) - return setmetatable( t, TapOutput_MT) - end - function TapOutput:startSuite() - print("1.."..self.result.testCount) - print('# Started on '..self.result.startDate) - end - function TapOutput:startClass(className) - if className ~= '[TestFunctions]' then - print('# Starting class: '..className) - end - end - - function TapOutput:addStatus( node ) - io.stdout:write("not ok ", self.result.currentTestNumber, "\t", node.testName, "\n") - if self.verbosity > M.VERBOSITY_LOW then - print( prefixString( ' ', node.msg ) ) - end - if self.verbosity > M.VERBOSITY_DEFAULT then - print( prefixString( ' ', node.stackTrace ) ) - end - end - - function TapOutput:endTest( node ) - if node:isPassed() then - io.stdout:write("ok ", self.result.currentTestNumber, "\t", node.testName, "\n") - end - end - - function TapOutput:endSuite() - print( '# '..M.LuaUnit.statusLine( self.result ) ) - return self.result.notPassedCount - end - - --- class TapOutput end - ----------------------------------------------------------------- --- class JUnitOutput ----------------------------------------------------------------- - --- See directory junitxml for more information about the junit format -local JUnitOutput = genericOutput.new() -- derived class -local JUnitOutput_MT = { __index = JUnitOutput } -- metatable -JUnitOutput.__class__ = 'JUnitOutput' - - function JUnitOutput.new(runner) - local t = genericOutput.new(runner, M.VERBOSITY_LOW) - t.testList = {} - return setmetatable( t, JUnitOutput_MT ) - end - - function JUnitOutput:startSuite() - -- open xml file early to deal with errors - if self.fname == nil then - error('With Junit, an output filename must be supplied with --name!') - end - if string.sub(self.fname,-4) ~= '.xml' then - self.fname = self.fname..'.xml' - end - self.fd = io.open(self.fname, "w") - if self.fd == nil then - error("Could not open file for writing: "..self.fname) - end - - print('# XML output to '..self.fname) - print('# Started on '..self.result.startDate) - end - function JUnitOutput:startClass(className) - if className ~= '[TestFunctions]' then - print('# Starting class: '..className) - end - end - function JUnitOutput:startTest(testName) - print('# Starting test: '..testName) - end - - function JUnitOutput:addStatus( node ) - if node:isFailure() then - print('# Failure: ' .. node.msg) - -- print('# ' .. node.stackTrace) - elseif node:isError() then - print('# Error: ' .. node.msg) - -- print('# ' .. node.stackTrace) - end - end - - function JUnitOutput:endSuite() - print( '# '..M.LuaUnit.statusLine(self.result)) - - -- XML file writing - self.fd:write('\n') - self.fd:write('\n') - self.fd:write(string.format( - ' \n', - self.result.runCount, self.result.startIsodate, self.result.duration, self.result.errorCount, self.result.failureCount )) - self.fd:write(" \n") - self.fd:write(string.format(' \n', _VERSION ) ) - self.fd:write(string.format(' \n', M.VERSION) ) - -- XXX please include system name and version if possible - self.fd:write(" \n") - - for i,node in ipairs(self.result.tests) do - self.fd:write(string.format(' \n', - node.className, node.testName, node.duration ) ) - if node:isNotPassed() then - self.fd:write(node:statusXML()) - end - self.fd:write(' \n') - end - - -- Next two lines are needed to validate junit ANT xsd, but really not useful in general: - self.fd:write(' \n') - self.fd:write(' \n') - - self.fd:write(' \n') - self.fd:write('\n') - self.fd:close() - return self.result.notPassedCount - end - - --- class TapOutput end - ----------------------------------------------------------------- --- class TextOutput ----------------------------------------------------------------- - ---[[ - --- Python Non verbose: - -For each test: . or F or E - -If some failed tests: - ============== - ERROR / FAILURE: TestName (testfile.testclass) - --------- - Stack trace - - -then -------------- -then "Ran x tests in 0.000s" -then OK or FAILED (failures=1, error=1) - --- Python Verbose: -testname (filename.classname) ... ok -testname (filename.classname) ... FAIL -testname (filename.classname) ... ERROR - -then -------------- -then "Ran x tests in 0.000s" -then OK or FAILED (failures=1, error=1) - --- Ruby: -Started - . - Finished in 0.002695 seconds. - - 1 tests, 2 assertions, 0 failures, 0 errors - --- Ruby: ->> ruby tc_simple_number2.rb -Loaded suite tc_simple_number2 -Started -F.. -Finished in 0.038617 seconds. - - 1) Failure: -test_failure(TestSimpleNumber) [tc_simple_number2.rb:16]: -Adding doesn't work. -<3> expected but was -<4>. - -3 tests, 4 assertions, 1 failures, 0 errors - --- Java Junit -.......F. -Time: 0,003 -There was 1 failure: -1) testCapacity(junit.samples.VectorTest)junit.framework.AssertionFailedError - at junit.samples.VectorTest.testCapacity(VectorTest.java:87) - at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) - at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) - at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) - -FAILURES!!! -Tests run: 8, Failures: 1, Errors: 0 - - --- Maven - -# mvn test -------------------------------------------------------- - T E S T S -------------------------------------------------------- -Running math.AdditionTest -Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: -0.03 sec <<< FAILURE! - -Results : - -Failed tests: - testLireSymbole(math.AdditionTest) - -Tests run: 2, Failures: 1, Errors: 0, Skipped: 0 - - --- LuaUnit ----- non verbose -* display . or F or E when running tests ----- verbose -* display test name + ok/fail ----- -* blank line -* number) ERROR or FAILURE: TestName - Stack trace -* blank line -* number) ERROR or FAILURE: TestName - Stack trace - -then -------------- -then "Ran x tests in 0.000s (%d not selected, %d skipped)" -then OK or FAILED (failures=1, error=1) - - -]] - -local TextOutput = genericOutput.new() -- derived class -local TextOutput_MT = { __index = TextOutput } -- metatable -TextOutput.__class__ = 'TextOutput' - - function TextOutput.new(runner) - local t = genericOutput.new(runner, M.VERBOSITY_DEFAULT) - t.errorList = {} - return setmetatable( t, TextOutput_MT ) - end - - function TextOutput:startSuite() - if self.verbosity > M.VERBOSITY_DEFAULT then - print( 'Started on '.. self.result.startDate ) - end - end - - function TextOutput:startTest(testName) - if self.verbosity > M.VERBOSITY_DEFAULT then - io.stdout:write( " ", self.result.currentNode.testName, " ... " ) - end - end - - function TextOutput:endTest( node ) - if node:isPassed() then - if self.verbosity > M.VERBOSITY_DEFAULT then - io.stdout:write("Ok\n") - else - io.stdout:write(".") - end - else - if self.verbosity > M.VERBOSITY_DEFAULT then - print( node.status ) - print( node.msg ) - --[[ - -- find out when to do this: - if self.verbosity > M.VERBOSITY_DEFAULT then - print( node.stackTrace ) - end - ]] - else - -- write only the first character of status - io.stdout:write(string.sub(node.status, 1, 1)) - end - end - end - - function TextOutput:displayOneFailedTest( index, failure ) - print(index..") "..failure.testName ) - print( failure.msg ) - print( failure.stackTrace ) - print() - end - - function TextOutput:displayFailedTests() - if self.result.notPassedCount == 0 then return end - print("Failed tests:") - print("-------------") - for i,v in ipairs(self.result.notPassed) do - self:displayOneFailedTest( i, v ) - end - end - - function TextOutput:endSuite() - if self.verbosity > M.VERBOSITY_DEFAULT then - print("=========================================================") - else - print() - end - self:displayFailedTests() - print( M.LuaUnit.statusLine( self.result ) ) - local ignoredString = "" - if self.result.notPassedCount == 0 then - print('OK') - end - end - --- class TextOutput end - - ----------------------------------------------------------------- --- class NilOutput ----------------------------------------------------------------- - -local function nopCallable() - --print(42) - return nopCallable -end - -local NilOutput = { __class__ = 'NilOuptut' } -- class -local NilOutput_MT = { __index = nopCallable } -- metatable - -function NilOutput.new(runner) - return setmetatable( { __class__ = 'NilOutput' }, NilOutput_MT ) -end - ----------------------------------------------------------------- --- --- class LuaUnit --- ----------------------------------------------------------------- - -M.LuaUnit = { - outputType = TextOutput, - verbosity = M.VERBOSITY_DEFAULT, - __class__ = 'LuaUnit' -} -local LuaUnit_MT = { __index = M.LuaUnit } - -if EXPORT_ASSERT_TO_GLOBALS then - LuaUnit = M.LuaUnit -end - - function M.LuaUnit.new() - return setmetatable( {}, LuaUnit_MT ) - end - - -----------------[[ Utility methods ]]--------------------- - - function M.LuaUnit.asFunction(aObject) - -- return "aObject" if it is a function, and nil otherwise - if 'function' == type(aObject) then return aObject end - end - - function M.LuaUnit.isClassMethod(aName) - -- return true if aName contains a class + a method name in the form class:method - return string.find(aName, '.', nil, true) ~= nil - end - - function M.LuaUnit.splitClassMethod(someName) - -- return a pair className, methodName for a name in the form class:method - -- return nil if not a class + method name - -- name is class + method - local hasMethod, methodName, className - hasMethod = string.find(someName, '.', nil, true ) - if not hasMethod then return nil end - methodName = string.sub(someName, hasMethod+1) - className = string.sub(someName,1,hasMethod-1) - return className, methodName - end - - function M.LuaUnit.isMethodTestName( s ) - -- return true is the name matches the name of a test method - -- default rule is that is starts with 'Test' or with 'test' - return string.sub(s, 1, 4):lower() == 'test' - end - - function M.LuaUnit.isTestName( s ) - -- return true is the name matches the name of a test - -- default rule is that is starts with 'Test' or with 'test' - return string.sub(s, 1, 4):lower() == 'test' - end - - function M.LuaUnit.collectTests() - -- return a list of all test names in the global namespace - -- that match LuaUnit.isTestName - - local testNames = {} - for k, v in pairs(_G) do - if M.LuaUnit.isTestName( k ) then - table.insert( testNames , k ) - end - end - table.sort( testNames ) - return testNames - end - - function M.LuaUnit.parseCmdLine( cmdLine ) - -- parse the command line - -- Supported command line parameters: - -- --verbose, -v: increase verbosity - -- --quiet, -q: silence output - -- --error, -e: treat errors as fatal (quit program) - -- --output, -o, + name: select output type - -- --pattern, -p, + pattern: run test matching pattern, may be repeated - -- --name, -n, + fname: name of output file for junit, default to stdout - -- [testnames, ...]: run selected test names - -- - -- Returns a table with the following fields: - -- verbosity: nil, M.VERBOSITY_DEFAULT, M.VERBOSITY_QUIET, M.VERBOSITY_VERBOSE - -- output: nil, 'tap', 'junit', 'text', 'nil' - -- testNames: nil or a list of test names to run - -- pattern: nil or a list of patterns - - local result = {} - local state = nil - local SET_OUTPUT = 1 - local SET_PATTERN = 2 - local SET_FNAME = 3 - - if cmdLine == nil then - return result - end - - local function parseOption( option ) - if option == '--help' or option == '-h' then - result['help'] = true - return - elseif option == '--version' then - result['version'] = true - return - elseif option == '--verbose' or option == '-v' then - result['verbosity'] = M.VERBOSITY_VERBOSE - return - elseif option == '--quiet' or option == '-q' then - result['verbosity'] = M.VERBOSITY_QUIET - return - elseif option == '--error' or option == '-e' then - result['quitOnError'] = true - return - elseif option == '--failure' or option == '-f' then - result['quitOnFailure'] = true - return - elseif option == '--output' or option == '-o' then - state = SET_OUTPUT - return state - elseif option == '--name' or option == '-n' then - state = SET_FNAME - return state - elseif option == '--pattern' or option == '-p' then - state = SET_PATTERN - return state - end - error('Unknown option: '..option,3) - end - - local function setArg( cmdArg, state ) - if state == SET_OUTPUT then - result['output'] = cmdArg - return - elseif state == SET_FNAME then - result['fname'] = cmdArg - return - elseif state == SET_PATTERN then - if result['pattern'] then - table.insert( result['pattern'], cmdArg ) - else - result['pattern'] = { cmdArg } - end - return - end - error('Unknown parse state: '.. state) - end - - - for i, cmdArg in ipairs(cmdLine) do - if state ~= nil then - setArg( cmdArg, state, result ) - state = nil - else - if cmdArg:sub(1,1) == '-' then - state = parseOption( cmdArg ) - else - if result['testNames'] then - table.insert( result['testNames'], cmdArg ) - else - result['testNames'] = { cmdArg } - end - end - end - end - - if result['help'] then - M.LuaUnit.help() - end - - if result['version'] then - M.LuaUnit.version() - end - - if state ~= nil then - error('Missing argument after '..cmdLine[ #cmdLine ],2 ) - end - - return result - end - - function M.LuaUnit.help() - print(M.USAGE) - os.exit(0) - end - - function M.LuaUnit.version() - print('LuaUnit v'..M.VERSION..' by Philippe Fremy ') - os.exit(0) - end - - function M.LuaUnit.patternInclude( patternFilter, expr ) - -- check if any of patternFilter is contained in expr. If so, return true. - -- return false if None of the patterns are contained in expr - -- if patternFilter is nil, return true (no filtering) - if patternFilter == nil then - return true - end - - for i,pattern in ipairs(patternFilter) do - if string.find(expr, pattern) then - return true - end - end - - return false - end - ----------------------------------------------------------------- --- class NodeStatus ----------------------------------------------------------------- - - local NodeStatus = { __class__ = 'NodeStatus' } -- class - local NodeStatus_MT = { __index = NodeStatus } -- metatable - M.NodeStatus = NodeStatus - - -- values of status - NodeStatus.PASS = 'PASS' - NodeStatus.FAIL = 'FAIL' - NodeStatus.ERROR = 'ERROR' - - function NodeStatus.new( number, testName, className ) - local t = { number = number, testName = testName, className = className } - setmetatable( t, NodeStatus_MT ) - t:pass() - return t - end - - function NodeStatus:pass() - self.status = self.PASS - -- useless but we know it's the field we want to use - self.msg = nil - self.stackTrace = nil - end - - function NodeStatus:fail(msg, stackTrace) - self.status = self.FAIL - self.msg = msg - self.stackTrace = stackTrace - end - - function NodeStatus:error(msg, stackTrace) - self.status = self.ERROR - self.msg = msg - self.stackTrace = stackTrace - end - - function NodeStatus:isPassed() - return self.status == NodeStatus.PASS - end - - function NodeStatus:isNotPassed() - -- print('hasFailure: '..prettystr(self)) - return self.status ~= NodeStatus.PASS - end - - function NodeStatus:isFailure() - return self.status == NodeStatus.FAIL - end - - function NodeStatus:isError() - return self.status == NodeStatus.ERROR - end - - function NodeStatus:statusXML() - if self:isError() then - return table.concat( - {' \n', - ' \n'}) - elseif self:isFailure() then - return table.concat( - {' \n', - ' \n'}) - end - return ' \n' -- (not XSD-compliant! normally shouldn't get here) - end - - --------------[[ Output methods ]]------------------------- - - local function conditional_plural(number, singular) - -- returns a grammatically well-formed string "%d " - local suffix = '' - if number ~= 1 then -- use plural - suffix = (singular:sub(-2) == 'ss') and 'es' or 's' - end - return string.format('%d %s%s', number, singular, suffix) - end - - function M.LuaUnit.statusLine(result) - -- return status line string according to results - local s = { - string.format('Ran %d tests in %0.3f seconds', - result.runCount, result.duration), - conditional_plural(result.passedCount, 'success'), - } - if result.notPassedCount > 0 then - if result.failureCount > 0 then - table.insert(s, conditional_plural(result.failureCount, 'failure')) - end - if result.errorCount > 0 then - table.insert(s, conditional_plural(result.errorCount, 'error')) - end - else - table.insert(s, '0 failures') - end - if result.nonSelectedCount > 0 then - table.insert(s, string.format("%d non-selected", result.nonSelectedCount)) - end - return table.concat(s, ', ') - end - - function M.LuaUnit:startSuite(testCount, nonSelectedCount) - self.result = { - testCount = testCount, - nonSelectedCount = nonSelectedCount, - passedCount = 0, - runCount = 0, - currentTestNumber = 0, - currentClassName = "", - currentNode = nil, - suiteStarted = true, - startTime = os.clock(), - startDate = os.date(os.getenv('LUAUNIT_DATEFMT')), - startIsodate = os.date('%Y-%m-%dT%H:%M:%S'), - patternFilter = self.patternFilter, - tests = {}, - failures = {}, - errors = {}, - notPassed = {}, - } - - self.outputType = self.outputType or TextOutput - self.output = self.outputType.new(self) - self.output:startSuite() - end - - function M.LuaUnit:startClass( className ) - self.result.currentClassName = className - self.output:startClass( className ) - end - - function M.LuaUnit:startTest( testName ) - self.result.currentTestNumber = self.result.currentTestNumber + 1 - self.result.runCount = self.result.runCount + 1 - self.result.currentNode = NodeStatus.new( - self.result.currentTestNumber, - testName, - self.result.currentClassName - ) - self.result.currentNode.startTime = os.clock() - table.insert( self.result.tests, self.result.currentNode ) - self.output:startTest( testName ) - end - - function M.LuaUnit:addStatus( err ) - -- "err" is expected to be a table / result from protectedCall() - if err.status == NodeStatus.PASS then return end - - local node = self.result.currentNode - - --[[ As a first approach, we will report only one error or one failure for one test. - - However, we can have the case where the test is in failure, and the teardown is in error. - In such case, it's a good idea to report both a failure and an error in the test suite. This is - what Python unittest does for example. However, it mixes up counts so need to be handled carefully: for - example, there could be more (failures + errors) count that tests. What happens to the current node ? - - We will do this more intelligent version later. - ]] - - -- if the node is already in failure/error, just don't report the new error (see above) - if node.status ~= NodeStatus.PASS then return end - - if err.status == NodeStatus.FAIL then - node:fail( err.msg, err.trace ) - table.insert( self.result.failures, node ) - elseif err.status == NodeStatus.ERROR then - node:error( err.msg, err.trace ) - table.insert( self.result.errors, node ) - end - - if node:isFailure() or node:isError() then - -- add to the list of failed tests (gets printed separately) - table.insert( self.result.notPassed, node ) - end - self.output:addStatus( node ) - end - - function M.LuaUnit:endTest() - local node = self.result.currentNode - -- print( 'endTest() '..prettystr(node)) - -- print( 'endTest() '..prettystr(node:isNotPassed())) - node.duration = os.clock() - node.startTime - node.startTime = nil - self.output:endTest( node ) - - if node:isPassed() then - self.result.passedCount = self.result.passedCount + 1 - elseif node:isError() then - if self.quitOnError or self.quitOnFailure then - -- Runtime error - abort test execution as requested by - -- "--error" option. This is done by setting a special - -- flag that gets handled in runSuiteByInstances(). - print("\nERROR during LuaUnit test execution:\n" .. node.msg) - self.result.aborted = true - end - elseif node:isFailure() then - if self.quitOnFailure then - -- Failure - abort test execution as requested by - -- "--failure" option. This is done by setting a special - -- flag that gets handled in runSuiteByInstances(). - print("\nFailure during LuaUnit test execution:\n" .. node.msg) - self.result.aborted = true - end - end - self.result.currentNode = nil - end - - function M.LuaUnit:endClass() - self.output:endClass() - end - - function M.LuaUnit:endSuite() - if self.result.suiteStarted == false then - error('LuaUnit:endSuite() -- suite was already ended' ) - end - self.result.duration = os.clock()-self.result.startTime - self.result.suiteStarted = false - - -- Expose test counts for outputter's endSuite(). This could be managed - -- internally instead, but unit tests (and existing use cases) might - -- rely on these fields being present. - self.result.notPassedCount = #self.result.notPassed - self.result.failureCount = #self.result.failures - self.result.errorCount = #self.result.errors - - self.output:endSuite() - end - - function M.LuaUnit:setOutputType(outputType) - -- default to text - -- tap produces results according to TAP format - if outputType:upper() == "NIL" then - self.outputType = NilOutput - return - end - if outputType:upper() == "TAP" then - self.outputType = TapOutput - return - end - if outputType:upper() == "JUNIT" then - self.outputType = JUnitOutput - return - end - if outputType:upper() == "TEXT" then - self.outputType = TextOutput - return - end - error( 'No such format: '..outputType,2) - end - - --------------[[ Runner ]]----------------- - - function M.LuaUnit:protectedCall(classInstance, methodInstance, prettyFuncName) - -- if classInstance is nil, this is just a function call - -- else, it's method of a class being called. - - local function err_handler(e) - -- transform error into a table, adding the traceback information - return { - status = NodeStatus.ERROR, - msg = e, - trace = string.sub(debug.traceback("", 3), 2) - } - end - - local ok, err - if classInstance then - -- stupid Lua < 5.2 does not allow xpcall with arguments so let's use a workaround - ok, err = xpcall( function () methodInstance(classInstance) end, err_handler ) - else - ok, err = xpcall( function () methodInstance() end, err_handler ) - end - if ok then - return {status = NodeStatus.PASS} - end - - -- determine if the error was a failed test: - -- We do this by stripping the failure prefix from the error message, - -- while keeping track of the gsub() count. A non-zero value -> failure - local failed - err.msg, failed = err.msg:gsub(M.FAILURE_PREFIX, "", 1) - if failed > 0 then - err.status = NodeStatus.FAIL - end - - -- reformat / improve the stack trace - if prettyFuncName then -- we do have the real method name - err.trace = err.trace:gsub("in (%a+) 'methodInstance'", "in %1 '"..prettyFuncName.."'") - end - if STRIP_LUAUNIT_FROM_STACKTRACE then - err.trace = stripLuaunitTrace(err.trace) - end - - return err -- return the error "object" (table) - end - - - function M.LuaUnit:execOneFunction(className, methodName, classInstance, methodInstance) - -- When executing a test function, className and classInstance must be nil - -- When executing a class method, all parameters must be set - - if type(methodInstance) ~= 'function' then - error( tostring(methodName)..' must be a function, not '..type(methodInstance)) - end - - local prettyFuncName - if className == nil then - className = '[TestFunctions]' - prettyFuncName = methodName - else - prettyFuncName = className..'.'..methodName - end - - if self.lastClassName ~= className then - if self.lastClassName ~= nil then - self:endClass() - end - self:startClass( className ) - self.lastClassName = className - end - - self:startTest(prettyFuncName) - - -- run setUp first (if any) - if classInstance then - local func = self.asFunction( classInstance.setUp ) - or self.asFunction( classInstance.Setup ) - or self.asFunction( classInstance.setup ) - or self.asFunction( classInstance.SetUp ) - if func then - self:addStatus(self:protectedCall(classInstance, func, className..'.setUp')) - end - end - - -- run testMethod() - if self.result.currentNode:isPassed() then - self:addStatus(self:protectedCall(classInstance, methodInstance, prettyFuncName)) - end - - -- lastly, run tearDown (if any) - if classInstance then - local func = self.asFunction( classInstance.tearDown ) - or self.asFunction( classInstance.TearDown ) - or self.asFunction( classInstance.teardown ) - or self.asFunction( classInstance.Teardown ) - if func then - self:addStatus(self:protectedCall(classInstance, func, className..'.tearDown')) - end - end - - self:endTest() - end - - function M.LuaUnit.expandOneClass( result, className, classInstance ) - -- add all test methods of classInstance to result - for methodName, methodInstance in sortedPairs(classInstance) do - if M.LuaUnit.asFunction(methodInstance) and M.LuaUnit.isMethodTestName( methodName ) then - table.insert( result, { className..'.'..methodName, classInstance } ) - end - end - end - - function M.LuaUnit.expandClasses( listOfNameAndInst ) - -- expand all classes (provided as {className, classInstance}) to a list of {className.methodName, classInstance} - -- functions and methods remain untouched - local result = {} - - for i,v in ipairs( listOfNameAndInst ) do - local name, instance = v[1], v[2] - if M.LuaUnit.asFunction(instance) then - table.insert( result, { name, instance } ) - else - if type(instance) ~= 'table' then - error( 'Instance must be a table or a function, not a '..type(instance)..', value '..prettystr(instance)) - end - if M.LuaUnit.isClassMethod( name ) then - local className, methodName = M.LuaUnit.splitClassMethod( name ) - local methodInstance = instance[methodName] - if methodInstance == nil then - error( "Could not find method in class "..tostring(className).." for method "..tostring(methodName) ) - end - table.insert( result, { name, instance } ) - else - M.LuaUnit.expandOneClass( result, name, instance ) - end - end - end - - return result - end - - function M.LuaUnit.applyPatternFilter( patternFilter, listOfNameAndInst ) - local included, excluded = {}, {} - for i, v in ipairs( listOfNameAndInst ) do - -- local name, instance = v[1], v[2] - if M.LuaUnit.patternInclude( patternFilter, v[1] ) then - table.insert( included, v ) - else - table.insert( excluded, v ) - end - end - return included, excluded - end - - function M.LuaUnit:runSuiteByInstances( listOfNameAndInst ) - -- Run an explicit list of tests. All test instances and names must be supplied. - -- each test must be one of: - -- * { function name, function instance } - -- * { class name, class instance } - -- * { class.method name, class instance } - - local expandedList = self.expandClasses( listOfNameAndInst ) - local filteredList, filteredOutList - = self.applyPatternFilter( self.patternFilter, expandedList ) - - self:startSuite( #filteredList, #filteredOutList ) - - for i,v in ipairs( filteredList ) do - local name, instance = v[1], v[2] - if M.LuaUnit.asFunction(instance) then - self:execOneFunction( nil, name, nil, instance ) - else - if type(instance) ~= 'table' then - error( 'Instance must be a table or a function, not a '..type(instance)..', value '..prettystr(instance)) - else - assert( M.LuaUnit.isClassMethod( name ) ) - local className, methodName = M.LuaUnit.splitClassMethod( name ) - local methodInstance = instance[methodName] - if methodInstance == nil then - error( "Could not find method in class "..tostring(className).." for method "..tostring(methodName) ) - end - self:execOneFunction( className, methodName, instance, methodInstance ) - end - end - if self.result.aborted then break end -- "--error" or "--failure" option triggered - end - - if self.lastClassName ~= nil then - self:endClass() - end - - self:endSuite() - - if self.result.aborted then - print("LuaUnit ABORTED (as requested by --error or --failure option)") - os.exit(-2) - end - end - - function M.LuaUnit:runSuiteByNames( listOfName ) - -- Run an explicit list of test names - - local instanceName, instance - local listOfNameAndInst = {} - - for i,name in ipairs( listOfName ) do - if M.LuaUnit.isClassMethod( name ) then - local className, methodName = M.LuaUnit.splitClassMethod( name ) - instanceName = className - instance = _G[instanceName] - - if instance == nil then - error( "No such name in global space: "..instanceName ) - end - - if type(instance) ~= 'table' then - error( 'Instance of '..instanceName..' must be a table, not '..type(instance)) - end - - local methodInstance = instance[methodName] - if methodInstance == nil then - error( "Could not find method in class "..tostring(className).." for method "..tostring(methodName) ) - end - - else - -- for functions and classes - instanceName = name - instance = _G[instanceName] - end - - if instance == nil then - error( "No such name in global space: "..instanceName ) - end - - if (type(instance) ~= 'table' and type(instance) ~= 'function') then - error( 'Name must match a function or a table: '..instanceName ) - end - - table.insert( listOfNameAndInst, { name, instance } ) - end - - self:runSuiteByInstances( listOfNameAndInst ) - end - - function M.LuaUnit.run(...) - -- Run some specific test classes. - -- If no arguments are passed, run the class names specified on the - -- command line. If no class name is specified on the command line - -- run all classes whose name starts with 'Test' - -- - -- If arguments are passed, they must be strings of the class names - -- that you want to run or generic command line arguments (-o, -p, -v, ...) - - local runner = M.LuaUnit.new() - return runner:runSuite(...) - end - - function M.LuaUnit:runSuite( ... ) - - local args = {...} - if type(args[1]) == 'table' and args[1].__class__ == 'LuaUnit' then - -- run was called with the syntax M.LuaUnit:runSuite() - -- we support both M.LuaUnit.run() and M.LuaUnit:run() - -- strip out the first argument - table.remove(args,1) - end - - if #args == 0 then - args = cmdline_argv - end - - local no_error, val = pcall( M.LuaUnit.parseCmdLine, args ) - if not no_error then - print(val) -- error message - print() - print(M.USAGE) - os.exit(-1) - end - - local options = val - - -- We expect these option fields to be either `nil` or contain - -- valid values, so it's safe to always copy them directly. - self.verbosity = options.verbosity - self.quitOnError = options.quitOnError - self.quitOnFailure = options.quitOnFailure - self.fname = options.fname - self.patternFilter = options.pattern - - if options.output and options.output:lower() == 'junit' and options.fname == nil then - print('With junit output, a filename must be supplied with -n or --name') - os.exit(-1) - end - - if options.output then - no_error, val = pcall(self.setOutputType, self, options.output) - if not no_error then - print(val) -- error message - print() - print(M.USAGE) - os.exit(-1) - end - end - - self:runSuiteByNames( options.testNames or M.LuaUnit.collectTests() ) - - return self.result.notPassedCount - end --- class LuaUnit - --- For compatbility with LuaUnit v2 -M.run = M.LuaUnit.run -M.Run = M.LuaUnit.run - -function M:setVerbosity( verbosity ) - M.LuaUnit.verbosity = verbosity -end -M.set_verbosity = M.setVerbosity -M.SetVerbosity = M.setVerbosity - - -return M +--[[ + luaunit.lua + +Description: A unit testing framework +Homepage: https://github.com/bluebird75/luaunit +Development by Philippe Fremy +Based on initial work of Ryu, Gwang (http://www.gpgstudy.com/gpgiki/LuaUnit) +License: BSD License, see LICENSE.txt +]]-- + +require("math") +local M={} + +-- private exported functions (for testing) +M.private = {} + +M.VERSION='3.3' +M._VERSION=M.VERSION -- For LuaUnit v2 compatibility + +-- a version which distinguish between regular Lua and LuaJit +M._LUAVERSION = (jit and jit.version) or _VERSION + +--[[ Some people like assertEquals( actual, expected ) and some people prefer +assertEquals( expected, actual ). +]]-- +M.ORDER_ACTUAL_EXPECTED = true +M.PRINT_TABLE_REF_IN_ERROR_MSG = false +M.TABLE_EQUALS_KEYBYCONTENT = true +M.LINE_LENGTH = 80 +M.TABLE_DIFF_ANALYSIS_THRESHOLD = 10 -- display deep analysis for more than 10 items +M.LIST_DIFF_ANALYSIS_THRESHOLD = 10 -- display deep analysis for more than 10 items + +--[[ EPS is meant to help with Lua's floating point math in simple corner +cases like almostEquals(1.1-0.1, 1), which may not work as-is (e.g. on numbers +with rational binary representation) if the user doesn't provide some explicit +error margin. + +The default margin used by almostEquals() in such cases is EPS; and since +Lua may be compiled with different numeric precisions (single vs. double), we +try to select a useful default for it dynamically. Note: If the initial value +is not acceptable, it can be changed by the user to better suit specific needs. + +See also: https://en.wikipedia.org/wiki/Machine_epsilon +]] +M.EPS = 2^-52 -- = machine epsilon for "double", ~2.22E-16 +if math.abs(1.1 - 1 - 0.1) > M.EPS then + -- rounding error is above EPS, assume single precision + M.EPS = 2^-23 -- = machine epsilon for "float", ~1.19E-07 +end + +-- set this to false to debug luaunit +local STRIP_LUAUNIT_FROM_STACKTRACE = true + +M.VERBOSITY_DEFAULT = 10 +M.VERBOSITY_LOW = 1 +M.VERBOSITY_QUIET = 0 +M.VERBOSITY_VERBOSE = 20 +M.DEFAULT_DEEP_ANALYSIS = nil +M.FORCE_DEEP_ANALYSIS = true +M.DISABLE_DEEP_ANALYSIS = false + +-- set EXPORT_ASSERT_TO_GLOBALS to have all asserts visible as global values +-- EXPORT_ASSERT_TO_GLOBALS = true + +-- we need to keep a copy of the script args before it is overriden +local cmdline_argv = rawget(_G, "arg") + +M.FAILURE_PREFIX = 'LuaUnit test FAILURE: ' -- prefix string for failed tests +M.SUCCESS_PREFIX = 'LuaUnit test SUCCESS: ' -- prefix string for successful tests finished early + + + +M.USAGE=[[Usage: lua [options] [testname1 [testname2] ... ] +Options: + -h, --help: Print this help + --version: Print version information + -v, --verbose: Increase verbosity + -q, --quiet: Set verbosity to minimum + -e, --error: Stop on first error + -f, --failure: Stop on first failure or error + -s, --shuffle: Shuffle tests before running them + -o, --output OUTPUT: Set output type to OUTPUT + Possible values: text, tap, junit, nil + -n, --name NAME: For junit only, mandatory name of xml file + -r, --repeat NUM: Execute all tests NUM times, e.g. to trig the JIT + -p, --pattern PATTERN: Execute all test names matching the Lua PATTERN + May be repeated to include several patterns + Make sure you escape magic chars like +? with % + -x, --exclude PATTERN: Exclude all test names matching the Lua PATTERN + May be repeated to exclude several patterns + Make sure you escape magic chars like +? with % + testname1, testname2, ... : tests to run in the form of testFunction, + TestClass or TestClass.testMethod +]] + +local is_equal -- defined here to allow calling from mismatchFormattingPureList + +---------------------------------------------------------------- +-- +-- general utility functions +-- +---------------------------------------------------------------- + +local function pcall_or_abort(func, ...) + -- unpack is a global function for Lua 5.1, otherwise use table.unpack + local unpack = rawget(_G, "unpack") or table.unpack + local result = {pcall(func, ...)} + if not result[1] then + -- an error occurred + print(result[2]) -- error message + print() + print(M.USAGE) + os.exit(-1) + end + return unpack(result, 2) +end + +local crossTypeOrdering = { + number = 1, boolean = 2, string = 3, table = 4, other = 5 +} +local crossTypeComparison = { + number = function(a, b) return a < b end, + string = function(a, b) return a < b end, + other = function(a, b) return tostring(a) < tostring(b) end, +} + +local function crossTypeSort(a, b) + local type_a, type_b = type(a), type(b) + if type_a == type_b then + local func = crossTypeComparison[type_a] or crossTypeComparison.other + return func(a, b) + end + type_a = crossTypeOrdering[type_a] or crossTypeOrdering.other + type_b = crossTypeOrdering[type_b] or crossTypeOrdering.other + return type_a < type_b +end + +local function __genSortedIndex( t ) + -- Returns a sequence consisting of t's keys, sorted. + local sortedIndex = {} + + for key,_ in pairs(t) do + table.insert(sortedIndex, key) + end + + table.sort(sortedIndex, crossTypeSort) + return sortedIndex +end +M.private.__genSortedIndex = __genSortedIndex + +local function sortedNext(state, control) + -- Equivalent of the next() function of table iteration, but returns the + -- keys in sorted order (see __genSortedIndex and crossTypeSort). + -- The state is a temporary variable during iteration and contains the + -- sorted key table (state.sortedIdx). It also stores the last index (into + -- the keys) used by the iteration, to find the next one quickly. + local key + + --print("sortedNext: control = "..tostring(control) ) + if control == nil then + -- start of iteration + state.count = #state.sortedIdx + state.lastIdx = 1 + key = state.sortedIdx[1] + return key, state.t[key] + end + + -- normally, we expect the control variable to match the last key used + if control ~= state.sortedIdx[state.lastIdx] then + -- strange, we have to find the next value by ourselves + -- the key table is sorted in crossTypeSort() order! -> use bisection + local lower, upper = 1, state.count + repeat + state.lastIdx = math.modf((lower + upper) / 2) + key = state.sortedIdx[state.lastIdx] + if key == control then + break -- key found (and thus prev index) + end + if crossTypeSort(key, control) then + -- key < control, continue search "right" (towards upper bound) + lower = state.lastIdx + 1 + else + -- key > control, continue search "left" (towards lower bound) + upper = state.lastIdx - 1 + end + until lower > upper + if lower > upper then -- only true if the key wasn't found, ... + state.lastIdx = state.count -- ... so ensure no match in code below + end + end + + -- proceed by retrieving the next value (or nil) from the sorted keys + state.lastIdx = state.lastIdx + 1 + key = state.sortedIdx[state.lastIdx] + if key then + return key, state.t[key] + end + + -- getting here means returning `nil`, which will end the iteration +end + +local function sortedPairs(tbl) + -- Equivalent of the pairs() function on tables. Allows to iterate in + -- sorted order. As required by "generic for" loops, this will return the + -- iterator (function), an "invariant state", and the initial control value. + -- (see http://www.lua.org/pil/7.2.html) + return sortedNext, {t = tbl, sortedIdx = __genSortedIndex(tbl)}, nil +end +M.private.sortedPairs = sortedPairs + +-- seed the random with a strongly varying seed +math.randomseed(os.clock()*1E11) + +local function randomizeTable( t ) + -- randomize the item orders of the table t + for i = #t, 2, -1 do + local j = math.random(i) + if i ~= j then + t[i], t[j] = t[j], t[i] + end + end +end +M.private.randomizeTable = randomizeTable + +local function strsplit(delimiter, text) +-- Split text into a list consisting of the strings in text, separated +-- by strings matching delimiter (which may _NOT_ be a pattern). +-- Example: strsplit(", ", "Anna, Bob, Charlie, Dolores") + if delimiter == "" then -- this would result in endless loops + error("delimiter matches empty string!") + end + local list, pos, first, last = {}, 1 + while true do + first, last = text:find(delimiter, pos, true) + if first then -- found? + table.insert(list, text:sub(pos, first - 1)) + pos = last + 1 + else + table.insert(list, text:sub(pos)) + break + end + end + return list +end +M.private.strsplit = strsplit + +local function hasNewLine( s ) + -- return true if s has a newline + return (string.find(s, '\n', 1, true) ~= nil) +end +M.private.hasNewLine = hasNewLine + +local function prefixString( prefix, s ) + -- Prefix all the lines of s with prefix + return prefix .. string.gsub(s, '\n', '\n' .. prefix) +end +M.private.prefixString = prefixString + +local function strMatch(s, pattern, start, final ) + -- return true if s matches completely the pattern from index start to index end + -- return false in every other cases + -- if start is nil, matches from the beginning of the string + -- if final is nil, matches to the end of the string + start = start or 1 + final = final or string.len(s) + + local foundStart, foundEnd = string.find(s, pattern, start, false) + return foundStart == start and foundEnd == final +end +M.private.strMatch = strMatch + +local function patternFilter(patterns, expr) + -- Run `expr` through the inclusion and exclusion rules defined in patterns + -- and return true if expr shall be included, false for excluded. + -- Inclusion pattern are defined as normal patterns, exclusions + -- patterns start with `!` and are followed by a normal pattern + + -- result: nil = UNKNOWN (not matched yet), true = ACCEPT, false = REJECT + -- default: true if no explicit "include" is found, set to false otherwise + local default, result = true, nil + + if patterns ~= nil then + for _, pattern in ipairs(patterns) do + local exclude = pattern:sub(1,1) == '!' + if exclude then + pattern = pattern:sub(2) + else + -- at least one include pattern specified, a match is required + default = false + end + -- print('pattern: ',pattern) + -- print('exclude: ',exclude) + -- print('default: ',default) + + if string.find(expr, pattern) then + -- set result to false when excluding, true otherwise + result = not exclude + end + end + end + + if result ~= nil then + return result + end + return default +end +M.private.patternFilter = patternFilter + +local function xmlEscape( s ) + -- Return s escaped for XML attributes + -- escapes table: + -- " " + -- ' ' + -- < < + -- > > + -- & & + + return string.gsub( s, '.', { + ['&'] = "&", + ['"'] = """, + ["'"] = "'", + ['<'] = "<", + ['>'] = ">", + } ) +end +M.private.xmlEscape = xmlEscape + +local function xmlCDataEscape( s ) + -- Return s escaped for CData section, escapes: "]]>" + return string.gsub( s, ']]>', ']]>' ) +end +M.private.xmlCDataEscape = xmlCDataEscape + +local function stripLuaunitTrace( stackTrace ) + --[[ + -- Example of a traceback: + < + [C]: in function 'xpcall' + ./luaunit.lua:1449: in function 'protectedCall' + ./luaunit.lua:1508: in function 'execOneFunction' + ./luaunit.lua:1596: in function 'runSuiteByInstances' + ./luaunit.lua:1660: in function 'runSuiteByNames' + ./luaunit.lua:1736: in function 'runSuite' + example_with_luaunit.lua:140: in main chunk + [C]: in ?>> + + Other example: + < + [C]: in function 'xpcall' + ./luaunit.lua:1517: in function 'protectedCall' + ./luaunit.lua:1578: in function 'execOneFunction' + ./luaunit.lua:1677: in function 'runSuiteByInstances' + ./luaunit.lua:1730: in function 'runSuiteByNames' + ./luaunit.lua:1806: in function 'runSuite' + example_with_luaunit.lua:140: in main chunk + [C]: in ?>> + + < + [C]: in function 'xpcall' + luaunit2/luaunit.lua:1532: in function 'protectedCall' + luaunit2/luaunit.lua:1591: in function 'execOneFunction' + luaunit2/luaunit.lua:1679: in function 'runSuiteByInstances' + luaunit2/luaunit.lua:1743: in function 'runSuiteByNames' + luaunit2/luaunit.lua:1819: in function 'runSuite' + luaunit2/example_with_luaunit.lua:140: in main chunk + [C]: in ?>> + + + -- first line is "stack traceback": KEEP + -- next line may be luaunit line: REMOVE + -- next lines are call in the program under testOk: REMOVE + -- next lines are calls from luaunit to call the program under test: KEEP + + -- Strategy: + -- keep first line + -- remove lines that are part of luaunit + -- kepp lines until we hit a luaunit line + ]] + + local function isLuaunitInternalLine( s ) + -- return true if line of stack trace comes from inside luaunit + return s:find('[/\\]luaunit%.lua:%d+: ') ~= nil + end + + -- print( '<<'..stackTrace..'>>' ) + + local t = strsplit( '\n', stackTrace ) + -- print( prettystr(t) ) + + local idx = 2 + + -- remove lines that are still part of luaunit + while t[idx] and isLuaunitInternalLine( t[idx] ) do + -- print('Removing : '..t[idx] ) + table.remove(t, idx) + end + + -- keep lines until we hit luaunit again + while t[idx] and (not isLuaunitInternalLine(t[idx])) do + -- print('Keeping : '..t[idx] ) + idx = idx + 1 + end + + -- remove remaining luaunit lines + while t[idx] do + -- print('Removing : '..t[idx] ) + table.remove(t, idx) + end + + -- print( prettystr(t) ) + return table.concat( t, '\n') + +end +M.private.stripLuaunitTrace = stripLuaunitTrace + + +local function prettystr_sub(v, indentLevel, printTableRefs, recursionTable ) + local type_v = type(v) + if "string" == type_v then + -- use clever delimiters according to content: + -- enclose with single quotes if string contains ", but no ' + if v:find('"', 1, true) and not v:find("'", 1, true) then + return "'" .. v .. "'" + end + -- use double quotes otherwise, escape embedded " + return '"' .. v:gsub('"', '\\"') .. '"' + + elseif "table" == type_v then + --if v.__class__ then + -- return string.gsub( tostring(v), 'table', v.__class__ ) + --end + return M.private._table_tostring(v, indentLevel, printTableRefs, recursionTable) + + elseif "number" == type_v then + -- eliminate differences in formatting between various Lua versions + if v ~= v then + return "#NaN" -- "not a number" + end + if v == math.huge then + return "#Inf" -- "infinite" + end + if v == -math.huge then + return "-#Inf" + end + if _VERSION == "Lua 5.3" then + local i = math.tointeger(v) + if i then + return tostring(i) + end + end + end + + return tostring(v) +end + +local function prettystr( v ) + --[[ Pretty string conversion, to display the full content of a variable of any type. + + * string are enclosed with " by default, or with ' if string contains a " + * tables are expanded to show their full content, with indentation in case of nested tables + ]]-- + local recursionTable = {} + local s = prettystr_sub(v, 1, M.PRINT_TABLE_REF_IN_ERROR_MSG, recursionTable) + if recursionTable.recursionDetected and not M.PRINT_TABLE_REF_IN_ERROR_MSG then + -- some table contain recursive references, + -- so we must recompute the value by including all table references + -- else the result looks like crap + recursionTable = {} + s = prettystr_sub(v, 1, true, recursionTable) + end + return s +end +M.prettystr = prettystr + +function M.adjust_err_msg_with_iter( err_msg, iter_msg ) + --[[ Adjust the error message err_msg: trim the FAILURE_PREFIX or SUCCESS_PREFIX information if needed, + add the iteration message if any and return the result. + + err_msg: string, error message captured with pcall + iter_msg: a string describing the current iteration ("iteration N") or nil + if there is no iteration in this test. + + Returns: (new_err_msg, test_status) + new_err_msg: string, adjusted error message, or nil in case of success + test_status: M.NodeStatus.FAIL, SUCCESS or ERROR according to the information + contained in the error message. + ]] + if iter_msg then + iter_msg = iter_msg..', ' + else + iter_msg = '' + end + + local RE_FILE_LINE = '.*:%d+: ' + + if (err_msg:find( M.SUCCESS_PREFIX ) == 1) or err_msg:match( '('..RE_FILE_LINE..')' .. M.SUCCESS_PREFIX .. ".*" ) then + -- test finished early with success() + return nil, M.NodeStatus.PASS + end + + if (err_msg:find( M.FAILURE_PREFIX ) == 1) or (err_msg:match( '('..RE_FILE_LINE..')' .. M.FAILURE_PREFIX .. ".*" ) ~= nil) then + -- substitute prefix by iteration message + err_msg = err_msg:gsub(M.FAILURE_PREFIX, iter_msg, 1) + -- print("failure detected") + return err_msg, M.NodeStatus.FAIL + else + -- print("error detected") + -- regular error, not a failure + if iter_msg then + local match + -- "./test\\test_luaunit.lua:2241: some error msg + match = err_msg:match( '(.*:%d+: ).*' ) + if match then + err_msg = err_msg:gsub( match, match .. iter_msg ) + else + -- no file:line: infromation, just add the iteration info at the beginning of the line + err_msg = iter_msg .. err_msg + end + end + return err_msg, M.NodeStatus.ERROR + end +end + +local function tryMismatchFormatting( table_a, table_b, doDeepAnalysis ) + --[[ + Prepares a nice error message when comparing tables, performing a deeper + analysis. + + Arguments: + * table_a, table_b: tables to be compared + * doDeepAnalysis: + M.DEFAULT_DEEP_ANALYSIS: (the default if not specified) perform deep analysis only for big lists and big dictionnaries + M.FORCE_DEEP_ANALYSIS : always perform deep analysis + M.DISABLE_DEEP_ANALYSIS: never perform deep analysis + + Returns: {success, result} + * success: false if deep analysis could not be performed + in this case, just use standard assertion message + * result: if success is true, a multi-line string with deep analysis of the two lists + ]] + + -- check if table_a & table_b are suitable for deep analysis + if type(table_a) ~= 'table' or type(table_b) ~= 'table' then + return false + end + + if doDeepAnalysis == M.DISABLE_DEEP_ANALYSIS then + return false + end + + local len_a, len_b, isPureList = #table_a, #table_b, true + + for k1, v1 in pairs(table_a) do + if type(k1) ~= 'number' or k1 > len_a then + -- this table a mapping + isPureList = false + break + end + end + + if isPureList then + for k2, v2 in pairs(table_b) do + if type(k2) ~= 'number' or k2 > len_b then + -- this table a mapping + isPureList = false + break + end + end + end + + if isPureList and math.min(len_a, len_b) < M.LIST_DIFF_ANALYSIS_THRESHOLD then + if not (doDeepAnalysis == M.FORCE_DEEP_ANALYSIS) then + return false + end + end + + if isPureList then + return M.private.mismatchFormattingPureList( table_a, table_b ) + else + -- only work on mapping for the moment + -- return M.private.mismatchFormattingMapping( table_a, table_b, doDeepAnalysis ) + return false + end +end +M.private.tryMismatchFormatting = tryMismatchFormatting + +local function getTaTbDescr() + if not M.ORDER_ACTUAL_EXPECTED then + return 'expected', 'actual' + end + return 'actual', 'expected' +end + +local function extendWithStrFmt( res, ... ) + table.insert( res, string.format( ... ) ) +end + +local function mismatchFormattingMapping( table_a, table_b, doDeepAnalysis ) + --[[ + Prepares a nice error message when comparing tables which are not pure lists, performing a deeper + analysis. + + Returns: {success, result} + * success: false if deep analysis could not be performed + in this case, just use standard assertion message + * result: if success is true, a multi-line string with deep analysis of the two lists + ]] + + -- disable for the moment + --[[ + local result = {} + local descrTa, descrTb = getTaTbDescr() + + local keysCommon = {} + local keysOnlyTa = {} + local keysOnlyTb = {} + local keysDiffTaTb = {} + + local k, v + + for k,v in pairs( table_a ) do + if is_equal( v, table_b[k] ) then + table.insert( keysCommon, k ) + else + if table_b[k] == nil then + table.insert( keysOnlyTa, k ) + else + table.insert( keysDiffTaTb, k ) + end + end + end + + for k,v in pairs( table_b ) do + if not is_equal( v, table_a[k] ) and table_a[k] == nil then + table.insert( keysOnlyTb, k ) + end + end + + local len_a = #keysCommon + #keysDiffTaTb + #keysOnlyTa + local len_b = #keysCommon + #keysDiffTaTb + #keysOnlyTb + local limited_display = (len_a < 5 or len_b < 5) + + if math.min(len_a, len_b) < M.TABLE_DIFF_ANALYSIS_THRESHOLD then + return false + end + + if not limited_display then + if len_a == len_b then + extendWithStrFmt( result, 'Table A (%s) and B (%s) both have %d items', descrTa, descrTb, len_a ) + else + extendWithStrFmt( result, 'Table A (%s) has %d items and table B (%s) has %d items', descrTa, len_a, descrTb, len_b ) + end + + if #keysCommon == 0 and #keysDiffTaTb == 0 then + table.insert( result, 'Table A and B have no keys in common, they are totally different') + else + local s_other = 'other ' + if #keysCommon then + extendWithStrFmt( result, 'Table A and B have %d identical items', #keysCommon ) + else + table.insert( result, 'Table A and B have no identical items' ) + s_other = '' + end + + if #keysDiffTaTb ~= 0 then + result[#result] = string.format( '%s and %d items differing present in both tables', result[#result], #keysDiffTaTb) + else + result[#result] = string.format( '%s and no %sitems differing present in both tables', result[#result], s_other, #keysDiffTaTb) + end + end + + extendWithStrFmt( result, 'Table A has %d keys not present in table B and table B has %d keys not present in table A', #keysOnlyTa, #keysOnlyTb ) + end + + local function keytostring(k) + if "string" == type(k) and k:match("^[_%a][_%w]*$") then + return k + end + return prettystr(k) + end + + if #keysDiffTaTb ~= 0 then + table.insert( result, 'Items differing in A and B:') + for k,v in sortedPairs( keysDiffTaTb ) do + extendWithStrFmt( result, ' - A[%s]: %s', keytostring(v), prettystr(table_a[v]) ) + extendWithStrFmt( result, ' + B[%s]: %s', keytostring(v), prettystr(table_b[v]) ) + end + end + + if #keysOnlyTa ~= 0 then + table.insert( result, 'Items only in table A:' ) + for k,v in sortedPairs( keysOnlyTa ) do + extendWithStrFmt( result, ' - A[%s]: %s', keytostring(v), prettystr(table_a[v]) ) + end + end + + if #keysOnlyTb ~= 0 then + table.insert( result, 'Items only in table B:' ) + for k,v in sortedPairs( keysOnlyTb ) do + extendWithStrFmt( result, ' + B[%s]: %s', keytostring(v), prettystr(table_b[v]) ) + end + end + + if #keysCommon ~= 0 then + table.insert( result, 'Items common to A and B:') + for k,v in sortedPairs( keysCommon ) do + extendWithStrFmt( result, ' = A and B [%s]: %s', keytostring(v), prettystr(table_a[v]) ) + end + end + + return true, table.concat( result, '\n') + ]] +end +M.private.mismatchFormattingMapping = mismatchFormattingMapping + +local function mismatchFormattingPureList( table_a, table_b ) + --[[ + Prepares a nice error message when comparing tables which are lists, performing a deeper + analysis. + + Returns: {success, result} + * success: false if deep analysis could not be performed + in this case, just use standard assertion message + * result: if success is true, a multi-line string with deep analysis of the two lists + ]] + local result, descrTa, descrTb = {}, getTaTbDescr() + + local len_a, len_b, refa, refb = #table_a, #table_b, '', '' + if M.PRINT_TABLE_REF_IN_ERROR_MSG then + refa, refb = string.format( '<%s> ', tostring(table_a)), string.format('<%s> ', tostring(table_b) ) + end + local longest, shortest = math.max(len_a, len_b), math.min(len_a, len_b) + local deltalv = longest - shortest + + local commonUntil = shortest + for i = 1, shortest do + if not is_equal(table_a[i], table_b[i]) then + commonUntil = i - 1 + break + end + end + + local commonBackTo = shortest - 1 + for i = 0, shortest - 1 do + if not is_equal(table_a[len_a-i], table_b[len_b-i]) then + commonBackTo = i - 1 + break + end + end + + + table.insert( result, 'List difference analysis:' ) + if len_a == len_b then + -- TODO: handle expected/actual naming + extendWithStrFmt( result, '* lists %sA (%s) and %sB (%s) have the same size', refa, descrTa, refb, descrTb ) + else + extendWithStrFmt( result, '* list sizes differ: list %sA (%s) has %d items, list %sB (%s) has %d items', refa, descrTa, len_a, refb, descrTb, len_b ) + end + + extendWithStrFmt( result, '* lists A and B start differing at index %d', commonUntil+1 ) + if commonBackTo >= 0 then + if deltalv > 0 then + extendWithStrFmt( result, '* lists A and B are equal again from index %d for A, %d for B', len_a-commonBackTo, len_b-commonBackTo ) + else + extendWithStrFmt( result, '* lists A and B are equal again from index %d', len_a-commonBackTo ) + end + end + + local function insertABValue(ai, bi) + bi = bi or ai + if is_equal( table_a[ai], table_b[bi]) then + return extendWithStrFmt( result, ' = A[%d], B[%d]: %s', ai, bi, prettystr(table_a[ai]) ) + else + extendWithStrFmt( result, ' - A[%d]: %s', ai, prettystr(table_a[ai])) + extendWithStrFmt( result, ' + B[%d]: %s', bi, prettystr(table_b[bi])) + end + end + + -- common parts to list A & B, at the beginning + if commonUntil > 0 then + table.insert( result, '* Common parts:' ) + for i = 1, commonUntil do + insertABValue( i ) + end + end + + -- diffing parts to list A & B + if commonUntil < shortest - commonBackTo - 1 then + table.insert( result, '* Differing parts:' ) + for i = commonUntil + 1, shortest - commonBackTo - 1 do + insertABValue( i ) + end + end + + -- display indexes of one list, with no match on other list + if shortest - commonBackTo <= longest - commonBackTo - 1 then + table.insert( result, '* Present only in one list:' ) + for i = shortest - commonBackTo, longest - commonBackTo - 1 do + if len_a > len_b then + extendWithStrFmt( result, ' - A[%d]: %s', i, prettystr(table_a[i]) ) + -- table.insert( result, '+ (no matching B index)') + else + -- table.insert( result, '- no matching A index') + extendWithStrFmt( result, ' + B[%d]: %s', i, prettystr(table_b[i]) ) + end + end + end + + -- common parts to list A & B, at the end + if commonBackTo >= 0 then + table.insert( result, '* Common parts at the end of the lists' ) + for i = longest - commonBackTo, longest do + if len_a > len_b then + insertABValue( i, i-deltalv ) + else + insertABValue( i-deltalv, i ) + end + end + end + + return true, table.concat( result, '\n') +end +M.private.mismatchFormattingPureList = mismatchFormattingPureList + +local function prettystrPairs(value1, value2, suffix_a, suffix_b) + --[[ + This function helps with the recurring task of constructing the "expected + vs. actual" error messages. It takes two arbitrary values and formats + corresponding strings with prettystr(). + + To keep the (possibly complex) output more readable in case the resulting + strings contain line breaks, they get automatically prefixed with additional + newlines. Both suffixes are optional (default to empty strings), and get + appended to the "value1" string. "suffix_a" is used if line breaks were + encountered, "suffix_b" otherwise. + + Returns the two formatted strings (including padding/newlines). + ]] + local str1, str2 = prettystr(value1), prettystr(value2) + if hasNewLine(str1) or hasNewLine(str2) then + -- line break(s) detected, add padding + return "\n" .. str1 .. (suffix_a or ""), "\n" .. str2 + end + return str1 .. (suffix_b or ""), str2 +end +M.private.prettystrPairs = prettystrPairs + +local function _table_raw_tostring( t ) + -- return the default tostring() for tables, with the table ID, even if the table has a metatable + -- with the __tostring converter + local mt = getmetatable( t ) + if mt then setmetatable( t, nil ) end + local ref = tostring(t) + if mt then setmetatable( t, mt ) end + return ref +end +M.private._table_raw_tostring = _table_raw_tostring + +local TABLE_TOSTRING_SEP = ", " +local TABLE_TOSTRING_SEP_LEN = string.len(TABLE_TOSTRING_SEP) + +local function _table_tostring( tbl, indentLevel, printTableRefs, recursionTable ) + printTableRefs = printTableRefs or M.PRINT_TABLE_REF_IN_ERROR_MSG + recursionTable = recursionTable or {} + recursionTable[tbl] = true + + local result, dispOnMultLines = {}, false + + -- like prettystr but do not enclose with "" if the string is just alphanumerical + -- this is better for displaying table keys who are often simple strings + local function keytostring(k) + if "string" == type(k) and k:match("^[_%a][_%w]*$") then + return k + end + return prettystr_sub(k, indentLevel+1, printTableRefs, recursionTable) + end + + local mt = getmetatable( tbl ) + + if mt and mt.__tostring then + -- if table has a __tostring() function in its metatable, use it to display the table + -- else, compute a regular table + result = strsplit( '\n', tostring(tbl) ) + return M.private._table_tostring_format_multiline_string( result, indentLevel ) + + else + -- no metatable, compute the table representation + + local entry, count, seq_index = nil, 0, 1 + for k, v in sortedPairs( tbl ) do + + -- key part + if k == seq_index then + -- for the sequential part of tables, we'll skip the "=" output + entry = '' + seq_index = seq_index + 1 + elseif recursionTable[k] then + -- recursion in the key detected + recursionTable.recursionDetected = true + entry = "<".._table_raw_tostring(k)..">=" + else + entry = keytostring(k) .. "=" + end + + -- value part + if recursionTable[v] then + -- recursion in the value detected! + recursionTable.recursionDetected = true + entry = entry .. "<".._table_raw_tostring(v)..">" + else + entry = entry .. + prettystr_sub( v, indentLevel+1, printTableRefs, recursionTable ) + end + count = count + 1 + result[count] = entry + end + return M.private._table_tostring_format_result( tbl, result, indentLevel, printTableRefs ) + end + +end +M.private._table_tostring = _table_tostring -- prettystr_sub() needs it + +local function _table_tostring_format_multiline_string( tbl_str, indentLevel ) + local indentString = '\n'..string.rep(" ", indentLevel - 1) + return table.concat( tbl_str, indentString ) + +end +M.private._table_tostring_format_multiline_string = _table_tostring_format_multiline_string + + +local function _table_tostring_format_result( tbl, result, indentLevel, printTableRefs ) + -- final function called in _table_to_string() to format the resulting list of + -- string describing the table. + + local dispOnMultLines = false + + -- set dispOnMultLines to true if the maximum LINE_LENGTH would be exceeded with the values + local totalLength = 0 + for k, v in ipairs( result ) do + totalLength = totalLength + string.len( v ) + if totalLength >= M.LINE_LENGTH then + dispOnMultLines = true + break + end + end + + -- set dispOnMultLines to true if the max LINE_LENGTH would be exceeded + -- with the values and the separators. + if not dispOnMultLines then + -- adjust with length of separator(s): + -- two items need 1 sep, three items two seps, ... plus len of '{}' + if #result > 0 then + totalLength = totalLength + TABLE_TOSTRING_SEP_LEN * (#result - 1) + end + dispOnMultLines = (totalLength + 2 >= M.LINE_LENGTH) + end + + -- now reformat the result table (currently holding element strings) + if dispOnMultLines then + local indentString = string.rep(" ", indentLevel - 1) + result = { + "{\n ", + indentString, + table.concat(result, ",\n " .. indentString), + "\n", + indentString, + "}" + } + else + result = {"{", table.concat(result, TABLE_TOSTRING_SEP), "}"} + end + if printTableRefs then + table.insert(result, 1, "<".._table_raw_tostring(tbl).."> ") -- prepend table ref + end + return table.concat(result) +end +M.private._table_tostring_format_result = _table_tostring_format_result -- prettystr_sub() needs it + +local function _table_contains(t, element) + if type(t) == "table" then + local type_e = type(element) + for _, value in pairs(t) do + if type(value) == type_e then + if value == element then + return true + end + if type_e == 'table' then + -- if we wanted recursive items content comparison, we could use + -- _is_table_items_equals(v, expected) but one level of just comparing + -- items is sufficient + if M.private._is_table_equals( value, element ) then + return true + end + end + end + end + end + return false +end + +local function _is_table_items_equals(actual, expected ) + local type_a, type_e = type(actual), type(expected) + + if (type_a == 'table') and (type_e == 'table') then + for k, v in pairs(actual) do + if not _table_contains(expected, v) then + return false + end + end + for k, v in pairs(expected) do + if not _table_contains(actual, v) then + return false + end + end + return true + + elseif type_a ~= type_e then + return false + + elseif actual ~= expected then + return false + end + + return true +end + +--[[ +This is a specialized metatable to help with the bookkeeping of recursions +in _is_table_equals(). It provides an __index table that implements utility +functions for easier management of the table. The "cached" method queries +the state of a specific (actual,expected) pair; and the "store" method sets +this state to the given value. The state of pairs not "seen" / visited is +assumed to be `nil`. +]] +local _recursion_cache_MT = { + __index = { + -- Return the cached value for an (actual,expected) pair (or `nil`) + cached = function(t, actual, expected) + local subtable = t[actual] or {} + return subtable[expected] + end, + + -- Store cached value for a specific (actual,expected) pair. + -- Returns the value, so it's easy to use for a "tailcall" (return ...). + store = function(t, actual, expected, value, asymmetric) + local subtable = t[actual] + if not subtable then + subtable = {} + t[actual] = subtable + end + subtable[expected] = value + + -- Unless explicitly marked "asymmetric": Consider the recursion + -- on (expected,actual) to be equivalent to (actual,expected) by + -- default, and thus cache the value for both. + if not asymmetric then + t:store(expected, actual, value, true) + end + + return value + end + } +} + +local function _is_table_equals(actual, expected, recursions) + local type_a, type_e = type(actual), type(expected) + recursions = recursions or setmetatable({}, _recursion_cache_MT) + + if type_a ~= type_e then + return false -- different types won't match + end + + if (type_a == 'table') --[[ and (type_e == 'table') ]] then + if actual == expected then + -- Both reference the same table, so they are actually identical + return recursions:store(actual, expected, true) + end + + -- If we've tested this (actual,expected) pair before: return cached value + local previous = recursions:cached(actual, expected) + if previous ~= nil then + return previous + end + + -- Mark this (actual,expected) pair, so we won't recurse it again. For + -- now, assume a "false" result, which we might adjust later if needed. + recursions:store(actual, expected, false) + + -- Tables must have identical element count, or they can't match. + if (#actual ~= #expected) then + return false + end + + local actualKeysMatched, actualTableKeys = {}, {} + + for k, v in pairs(actual) do + if M.TABLE_EQUALS_KEYBYCONTENT and type(k) == "table" then + -- If the keys are tables, things get a bit tricky here as we + -- can have _is_table_equals(t[k1], t[k2]) despite k1 ~= k2. So + -- we first collect table keys from "actual", and then later try + -- to match each table key from "expected" to actualTableKeys. + table.insert(actualTableKeys, k) + else + if not _is_table_equals(v, expected[k], recursions) then + return false -- Mismatch on value, tables can't be equal + end + actualKeysMatched[k] = true -- Keep track of matched keys + end + end + + for k, v in pairs(expected) do + if M.TABLE_EQUALS_KEYBYCONTENT and type(k) == "table" then + local found = false + -- Note: DON'T use ipairs() here, table may be non-sequential! + for i, candidate in pairs(actualTableKeys) do + if _is_table_equals(candidate, k, recursions) then + if _is_table_equals(actual[candidate], v, recursions) then + found = true + -- Remove the candidate we matched against from the list + -- of table keys, so each key in actual can only match + -- one key in expected. + actualTableKeys[i] = nil + break + end + -- keys match but values don't, keep searching + end + end + if not found then + return false -- no matching (key,value) pair + end + else + if not actualKeysMatched[k] then + -- Found a key that we did not see in "actual" -> mismatch + return false + end + -- Otherwise actual[k] was already matched against v = expected[k]. + end + end + + if next(actualTableKeys) then + -- If there is any key left in actualTableKeys, then that is + -- a table-type key in actual with no matching counterpart + -- (in expected), and so the tables aren't equal. + return false + end + + -- The tables are actually considered equal, update cache and return result + return recursions:store(actual, expected, true) + + elseif actual ~= expected then + return false + end + + return true +end +M.private._is_table_equals = _is_table_equals +is_equal = _is_table_equals + +local function failure(main_msg, extra_msg_or_nil, level) + -- raise an error indicating a test failure + -- for error() compatibility we adjust "level" here (by +1), to report the + -- calling context + local msg + if type(extra_msg_or_nil) == 'string' and extra_msg_or_nil:len() > 0 then + msg = extra_msg_or_nil .. '\n' .. main_msg + else + msg = main_msg + end + error(M.FAILURE_PREFIX .. msg, (level or 1) + 1) +end + +local function fail_fmt(level, extra_msg_or_nil, ...) + -- failure with printf-style formatted message and given error level + failure(string.format(...), extra_msg_or_nil, (level or 1) + 1) +end +M.private.fail_fmt = fail_fmt + +local function error_fmt(level, ...) + -- printf-style error() + error(string.format(...), (level or 1) + 1) +end + +---------------------------------------------------------------- +-- +-- assertions +-- +---------------------------------------------------------------- + +local function errorMsgEquality(actual, expected, doDeepAnalysis) + + if not M.ORDER_ACTUAL_EXPECTED then + expected, actual = actual, expected + end + if type(expected) == 'string' or type(expected) == 'table' then + local strExpected, strActual = prettystrPairs(expected, actual) + local result = string.format("expected: %s\nactual: %s", strExpected, strActual) + + -- extend with mismatch analysis if possible: + local success, mismatchResult + success, mismatchResult = tryMismatchFormatting( actual, expected, doDeepAnalysis ) + if success then + result = table.concat( { result, mismatchResult }, '\n' ) + end + return result + end + return string.format("expected: %s, actual: %s", + prettystr(expected), prettystr(actual)) +end + +function M.assertError(f, ...) + -- assert that calling f with the arguments will raise an error + -- example: assertError( f, 1, 2 ) => f(1,2) should generate an error + if pcall( f, ... ) then + failure( "Expected an error when calling function but no error generated", nil, 2 ) + end +end + +function M.fail( msg ) + -- stops a test due to a failure + failure( msg, nil, 2 ) +end + +function M.failIf( cond, msg ) + -- Fails a test with "msg" if condition is true + if cond then + failure( msg, nil, 2 ) + end +end + +function M.success() + -- stops a test with a success + error(M.SUCCESS_PREFIX, 2) +end + +function M.successIf( cond ) + -- stops a test with a success if condition is met + if cond then + error(M.SUCCESS_PREFIX, 2) + end +end + + +------------------------------------------------------------------ +-- Equality assertions +------------------------------------------------------------------ + +function M.assertEquals(actual, expected, extra_msg_or_nil, doDeepAnalysis) + if type(actual) == 'table' and type(expected) == 'table' then + if not _is_table_equals(actual, expected) then + failure( errorMsgEquality(actual, expected, doDeepAnalysis), extra_msg_or_nil, 2 ) + end + elseif type(actual) ~= type(expected) then + failure( errorMsgEquality(actual, expected), extra_msg_or_nil, 2 ) + elseif actual ~= expected then + failure( errorMsgEquality(actual, expected), extra_msg_or_nil, 2 ) + end +end + +function M.almostEquals( actual, expected, margin ) + if type(actual) ~= 'number' or type(expected) ~= 'number' or type(margin) ~= 'number' then + error_fmt(3, 'almostEquals: must supply only number arguments.\nArguments supplied: %s, %s, %s', + prettystr(actual), prettystr(expected), prettystr(margin)) + end + if margin < 0 then + error('almostEquals: margin must not be negative, current value is ' .. margin, 3) + end + return math.abs(expected - actual) <= margin +end + +function M.assertAlmostEquals( actual, expected, margin, extra_msg_or_nil ) + -- check that two floats are close by margin + margin = margin or M.EPS + if not M.almostEquals(actual, expected, margin) then + if not M.ORDER_ACTUAL_EXPECTED then + expected, actual = actual, expected + end + local delta = math.abs(actual - expected) + fail_fmt(2, extra_msg_or_nil, 'Values are not almost equal\n' .. + 'Actual: %s, expected: %s, delta %s above margin of %s', + actual, expected, delta, margin) + end +end + +function M.assertNotEquals(actual, expected, extra_msg_or_nil) + if type(actual) ~= type(expected) then + return + end + + if type(actual) == 'table' and type(expected) == 'table' then + if not _is_table_equals(actual, expected) then + return + end + elseif actual ~= expected then + return + end + fail_fmt(2, extra_msg_or_nil, 'Received the not expected value: %s', prettystr(actual)) +end + +function M.assertNotAlmostEquals( actual, expected, margin, extra_msg_or_nil ) + -- check that two floats are not close by margin + margin = margin or M.EPS + if M.almostEquals(actual, expected, margin) then + if not M.ORDER_ACTUAL_EXPECTED then + expected, actual = actual, expected + end + local delta = math.abs(actual - expected) + fail_fmt(2, extra_msg_or_nil, 'Values are almost equal\nActual: %s, expected: %s' .. + ', delta %s below margin of %s', + actual, expected, delta, margin) + end +end + +function M.assertItemsEquals(actual, expected, extra_msg_or_nil) + -- checks that the items of table expected + -- are contained in table actual. Warning, this function + -- is at least O(n^2) + if not _is_table_items_equals(actual, expected ) then + expected, actual = prettystrPairs(expected, actual) + fail_fmt(2, extra_msg_or_nil, 'Content of the tables are not identical:\nExpected: %s\nActual: %s', + expected, actual) + end +end + +------------------------------------------------------------------ +-- String assertion +------------------------------------------------------------------ + +function M.assertStrContains( str, sub, isPattern, extra_msg_or_nil ) + -- this relies on lua string.find function + -- a string always contains the empty string + if not string.find(str, sub, 1, not isPattern) then + sub, str = prettystrPairs(sub, str, '\n') + fail_fmt(2, extra_msg_or_nil, 'Could not find %s %s in string %s', + isPattern and 'pattern' or 'substring', sub, str) + end +end + +function M.assertStrIContains( str, sub, extra_msg_or_nil ) + -- this relies on lua string.find function + -- a string always contains the empty string + if not string.find(str:lower(), sub:lower(), 1, true) then + sub, str = prettystrPairs(sub, str, '\n') + fail_fmt(2, extra_msg_or_nil, 'Could not find (case insensitively) substring %s in string %s', + sub, str) + end +end + +function M.assertNotStrContains( str, sub, isPattern, extra_msg_or_nil ) + -- this relies on lua string.find function + -- a string always contains the empty string + if string.find(str, sub, 1, not isPattern) then + sub, str = prettystrPairs(sub, str, '\n') + fail_fmt(2, extra_msg_or_nil, 'Found the not expected %s %s in string %s', + isPattern and 'pattern' or 'substring', sub, str) + end +end + +function M.assertNotStrIContains( str, sub, extra_msg_or_nil ) + -- this relies on lua string.find function + -- a string always contains the empty string + if string.find(str:lower(), sub:lower(), 1, true) then + sub, str = prettystrPairs(sub, str, '\n') + fail_fmt(2, extra_msg_or_nil, 'Found (case insensitively) the not expected substring %s in string %s', + sub, str) + end +end + +function M.assertStrMatches( str, pattern, start, final, extra_msg_or_nil ) + -- Verify a full match for the string + if not strMatch( str, pattern, start, final ) then + pattern, str = prettystrPairs(pattern, str, '\n') + fail_fmt(2, extra_msg_or_nil, 'Could not match pattern %s with string %s', + pattern, str) + end +end + +function M.assertErrorMsgEquals( expectedMsg, func, ... ) + -- assert that calling f with the arguments will raise an error + -- example: assertError( f, 1, 2 ) => f(1,2) should generate an error + local no_error, error_msg = pcall( func, ... ) + if no_error then + failure( 'No error generated when calling function but expected error: '..M.prettystr(expectedMsg), nil, 2 ) + end + if type(expectedMsg) == "string" and type(error_msg) ~= "string" then + -- table are converted to string automatically + error_msg = tostring(error_msg) + end + local differ = false + if error_msg ~= expectedMsg then + local tr = type(error_msg) + local te = type(expectedMsg) + if te == 'table' then + if tr ~= 'table' then + differ = true + else + local ok = pcall(M.assertItemsEquals, error_msg, expectedMsg) + if not ok then + differ = true + end + end + else + differ = true + end + end + + if differ then + error_msg, expectedMsg = prettystrPairs(error_msg, expectedMsg) + fail_fmt(2, nil, 'Error message expected: %s\nError message received: %s\n', + expectedMsg, error_msg) + end +end + +function M.assertErrorMsgContains( partialMsg, func, ... ) + -- assert that calling f with the arguments will raise an error + -- example: assertError( f, 1, 2 ) => f(1,2) should generate an error + local no_error, error_msg = pcall( func, ... ) + if no_error then + failure( 'No error generated when calling function but expected error containing: '..prettystr(partialMsg), nil, 2 ) + end + if type(error_msg) ~= "string" then + error_msg = tostring(error_msg) + end + if not string.find( error_msg, partialMsg, nil, true ) then + error_msg, partialMsg = prettystrPairs(error_msg, partialMsg) + fail_fmt(2, nil, 'Error message does not contain: %s\nError message received: %s\n', + partialMsg, error_msg) + end +end + +function M.assertErrorMsgMatches( expectedMsg, func, ... ) + -- assert that calling f with the arguments will raise an error + -- example: assertError( f, 1, 2 ) => f(1,2) should generate an error + local no_error, error_msg = pcall( func, ... ) + if no_error then + failure( 'No error generated when calling function but expected error matching: "'..expectedMsg..'"', nil, 2 ) + end + if type(error_msg) ~= "string" then + error_msg = tostring(error_msg) + end + if not strMatch( error_msg, expectedMsg ) then + expectedMsg, error_msg = prettystrPairs(expectedMsg, error_msg) + fail_fmt(2, nil, 'Error message does not match pattern: %s\nError message received: %s\n', + expectedMsg, error_msg) + end +end + +------------------------------------------------------------------ +-- Type assertions +------------------------------------------------------------------ + +function M.assertEvalToTrue(value, extra_msg_or_nil) + if not value then + failure("expected: a value evaluating to true, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertEvalToFalse(value, extra_msg_or_nil) + if value then + failure("expected: false or nil, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertIsTrue(value, extra_msg_or_nil) + if value ~= true then + failure("expected: true, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertNotIsTrue(value, extra_msg_or_nil) + if value == true then + failure("expected: not true, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertIsFalse(value, extra_msg_or_nil) + if value ~= false then + failure("expected: false, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertNotIsFalse(value, extra_msg_or_nil) + if value == false then + failure("expected: not false, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertIsNil(value, extra_msg_or_nil) + if value ~= nil then + failure("expected: nil, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertNotIsNil(value, extra_msg_or_nil) + if value == nil then + failure("expected: not nil, actual: nil", extra_msg_or_nil, 2) + end +end + +--[[ +Add type assertion functions to the module table M. Each of these functions +takes a single parameter "value", and checks that its Lua type matches the +expected string (derived from the function name): + +M.assertIsXxx(value) -> ensure that type(value) conforms to "xxx" +]] +for _, funcName in ipairs( + {'assertIsNumber', 'assertIsString', 'assertIsTable', 'assertIsBoolean', + 'assertIsFunction', 'assertIsUserdata', 'assertIsThread'} +) do + local typeExpected = funcName:match("^assertIs([A-Z]%a*)$") + -- Lua type() always returns lowercase, also make sure the match() succeeded + typeExpected = typeExpected and typeExpected:lower() + or error("bad function name '"..funcName.."' for type assertion") + + M[funcName] = function(value, extra_msg_or_nil) + if type(value) ~= typeExpected then + if type(value) == 'nil' then + fail_fmt(2, extra_msg_or_nil, 'expected: a %s value, actual: nil', + typeExpected, type(value), prettystrPairs(value)) + else + fail_fmt(2, extra_msg_or_nil, 'expected: a %s value, actual: type %s, value %s', + typeExpected, type(value), prettystrPairs(value)) + end + end + end +end + +--[[ +Add shortcuts for verifying type of a variable, without failure (luaunit v2 compatibility) +M.isXxx(value) -> returns true if type(value) conforms to "xxx" +]] +for _, typeExpected in ipairs( + {'Number', 'String', 'Table', 'Boolean', + 'Function', 'Userdata', 'Thread', 'Nil' } +) do + local typeExpectedLower = typeExpected:lower() + local isType = function(value) + return (type(value) == typeExpectedLower) + end + M['is'..typeExpected] = isType + M['is_'..typeExpectedLower] = isType +end + +--[[ +Add non-type assertion functions to the module table M. Each of these functions +takes a single parameter "value", and checks that its Lua type differs from the +expected string (derived from the function name): + +M.assertNotIsXxx(value) -> ensure that type(value) is not "xxx" +]] +for _, funcName in ipairs( + {'assertNotIsNumber', 'assertNotIsString', 'assertNotIsTable', 'assertNotIsBoolean', + 'assertNotIsFunction', 'assertNotIsUserdata', 'assertNotIsThread'} +) do + local typeUnexpected = funcName:match("^assertNotIs([A-Z]%a*)$") + -- Lua type() always returns lowercase, also make sure the match() succeeded + typeUnexpected = typeUnexpected and typeUnexpected:lower() + or error("bad function name '"..funcName.."' for type assertion") + + M[funcName] = function(value, extra_msg_or_nil) + if type(value) == typeUnexpected then + fail_fmt(2, extra_msg_or_nil, 'expected: not a %s type, actual: value %s', + typeUnexpected, prettystrPairs(value)) + end + end +end + +function M.assertIs(actual, expected, extra_msg_or_nil) + if actual ~= expected then + if not M.ORDER_ACTUAL_EXPECTED then + actual, expected = expected, actual + end + expected, actual = prettystrPairs(expected, actual, '\n', '') + fail_fmt(2, extra_msg_or_nil, 'expected and actual object should not be different\nExpected: %s\nReceived: %s', + expected, actual) + end +end + +function M.assertNotIs(actual, expected, extra_msg_or_nil) + if actual == expected then + if not M.ORDER_ACTUAL_EXPECTED then + expected = actual + end + fail_fmt(2, extra_msg_or_nil, 'expected and actual object should be different: %s', + prettystrPairs(expected)) + end +end + + +------------------------------------------------------------------ +-- Scientific assertions +------------------------------------------------------------------ + + +function M.assertIsNaN(value, extra_msg_or_nil) + if type(value) ~= "number" or value == value then + failure("expected: NaN, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertNotIsNaN(value, extra_msg_or_nil) + if type(value) == "number" and value ~= value then + failure("expected: not NaN, actual: NaN", extra_msg_or_nil, 2) + end +end + +function M.assertIsInf(value, extra_msg_or_nil) + if type(value) ~= "number" or math.abs(value) ~= math.huge then + failure("expected: #Inf, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertIsPlusInf(value, extra_msg_or_nil) + if type(value) ~= "number" or value ~= math.huge then + failure("expected: #Inf, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertIsMinusInf(value, extra_msg_or_nil) + if type(value) ~= "number" or value ~= -math.huge then + failure("expected: -#Inf, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertNotIsPlusInf(value, extra_msg_or_nil) + if type(value) == "number" and value == math.huge then + failure("expected: not #Inf, actual: #Inf", extra_msg_or_nil, 2) + end +end + +function M.assertNotIsMinusInf(value, extra_msg_or_nil) + if type(value) == "number" and value == -math.huge then + failure("expected: not -#Inf, actual: -#Inf", extra_msg_or_nil, 2) + end +end + +function M.assertNotIsInf(value, extra_msg_or_nil) + if type(value) == "number" and math.abs(value) == math.huge then + failure("expected: not infinity, actual: " .. prettystr(value), extra_msg_or_nil, 2) + end +end + +function M.assertIsPlusZero(value, extra_msg_or_nil) + if type(value) ~= 'number' or value ~= 0 then + failure("expected: +0.0, actual: " ..prettystr(value), extra_msg_or_nil, 2) + else if (1/value == -math.huge) then + -- more precise error diagnosis + failure("expected: +0.0, actual: -0.0", extra_msg_or_nil, 2) + else if (1/value ~= math.huge) then + -- strange, case should have already been covered + failure("expected: +0.0, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end + end + end +end + +function M.assertIsMinusZero(value, extra_msg_or_nil) + if type(value) ~= 'number' or value ~= 0 then + failure("expected: -0.0, actual: " ..prettystr(value), extra_msg_or_nil, 2) + else if (1/value == math.huge) then + -- more precise error diagnosis + failure("expected: -0.0, actual: +0.0", extra_msg_or_nil, 2) + else if (1/value ~= -math.huge) then + -- strange, case should have already been covered + failure("expected: -0.0, actual: " ..prettystr(value), extra_msg_or_nil, 2) + end + end + end +end + +function M.assertNotIsPlusZero(value, extra_msg_or_nil) + if type(value) == 'number' and (1/value == math.huge) then + failure("expected: not +0.0, actual: +0.0", extra_msg_or_nil, 2) + end +end + +function M.assertNotIsMinusZero(value, extra_msg_or_nil) + if type(value) == 'number' and (1/value == -math.huge) then + failure("expected: not -0.0, actual: -0.0", extra_msg_or_nil, 2) + end +end + +---------------------------------------------------------------- +-- Compatibility layer +---------------------------------------------------------------- + +-- for compatibility with LuaUnit v2.x +function M.wrapFunctions() + -- In LuaUnit version <= 2.1 , this function was necessary to include + -- a test function inside the global test suite. Nowadays, the functions + -- are simply run directly as part of the test discovery process. + -- so just do nothing ! + io.stderr:write[[Use of WrapFunctions() is no longer needed. +Just prefix your test function names with "test" or "Test" and they +will be picked up and run by LuaUnit. +]] +end + +local list_of_funcs = { + -- { official function name , alias } + + -- general assertions + { 'assertEquals' , 'assert_equals' }, + { 'assertItemsEquals' , 'assert_items_equals' }, + { 'assertNotEquals' , 'assert_not_equals' }, + { 'assertAlmostEquals' , 'assert_almost_equals' }, + { 'assertNotAlmostEquals' , 'assert_not_almost_equals' }, + { 'assertEvalToTrue' , 'assert_eval_to_true' }, + { 'assertEvalToFalse' , 'assert_eval_to_false' }, + { 'assertStrContains' , 'assert_str_contains' }, + { 'assertStrIContains' , 'assert_str_icontains' }, + { 'assertNotStrContains' , 'assert_not_str_contains' }, + { 'assertNotStrIContains' , 'assert_not_str_icontains' }, + { 'assertStrMatches' , 'assert_str_matches' }, + { 'assertError' , 'assert_error' }, + { 'assertErrorMsgEquals' , 'assert_error_msg_equals' }, + { 'assertErrorMsgContains' , 'assert_error_msg_contains' }, + { 'assertErrorMsgMatches' , 'assert_error_msg_matches' }, + { 'assertIs' , 'assert_is' }, + { 'assertNotIs' , 'assert_not_is' }, + { 'wrapFunctions' , 'WrapFunctions' }, + { 'wrapFunctions' , 'wrap_functions' }, + + -- type assertions: assertIsXXX -> assert_is_xxx + { 'assertIsNumber' , 'assert_is_number' }, + { 'assertIsString' , 'assert_is_string' }, + { 'assertIsTable' , 'assert_is_table' }, + { 'assertIsBoolean' , 'assert_is_boolean' }, + { 'assertIsNil' , 'assert_is_nil' }, + { 'assertIsTrue' , 'assert_is_true' }, + { 'assertIsFalse' , 'assert_is_false' }, + { 'assertIsNaN' , 'assert_is_nan' }, + { 'assertIsInf' , 'assert_is_inf' }, + { 'assertIsPlusInf' , 'assert_is_plus_inf' }, + { 'assertIsMinusInf' , 'assert_is_minus_inf' }, + { 'assertIsPlusZero' , 'assert_is_plus_zero' }, + { 'assertIsMinusZero' , 'assert_is_minus_zero' }, + { 'assertIsFunction' , 'assert_is_function' }, + { 'assertIsThread' , 'assert_is_thread' }, + { 'assertIsUserdata' , 'assert_is_userdata' }, + + -- type assertions: assertIsXXX -> assertXxx + { 'assertIsNumber' , 'assertNumber' }, + { 'assertIsString' , 'assertString' }, + { 'assertIsTable' , 'assertTable' }, + { 'assertIsBoolean' , 'assertBoolean' }, + { 'assertIsNil' , 'assertNil' }, + { 'assertIsTrue' , 'assertTrue' }, + { 'assertIsFalse' , 'assertFalse' }, + { 'assertIsNaN' , 'assertNaN' }, + { 'assertIsInf' , 'assertInf' }, + { 'assertIsPlusInf' , 'assertPlusInf' }, + { 'assertIsMinusInf' , 'assertMinusInf' }, + { 'assertIsPlusZero' , 'assertPlusZero' }, + { 'assertIsMinusZero' , 'assertMinusZero'}, + { 'assertIsFunction' , 'assertFunction' }, + { 'assertIsThread' , 'assertThread' }, + { 'assertIsUserdata' , 'assertUserdata' }, + + -- type assertions: assertIsXXX -> assert_xxx (luaunit v2 compat) + { 'assertIsNumber' , 'assert_number' }, + { 'assertIsString' , 'assert_string' }, + { 'assertIsTable' , 'assert_table' }, + { 'assertIsBoolean' , 'assert_boolean' }, + { 'assertIsNil' , 'assert_nil' }, + { 'assertIsTrue' , 'assert_true' }, + { 'assertIsFalse' , 'assert_false' }, + { 'assertIsNaN' , 'assert_nan' }, + { 'assertIsInf' , 'assert_inf' }, + { 'assertIsPlusInf' , 'assert_plus_inf' }, + { 'assertIsMinusInf' , 'assert_minus_inf' }, + { 'assertIsPlusZero' , 'assert_plus_zero' }, + { 'assertIsMinusZero' , 'assert_minus_zero' }, + { 'assertIsFunction' , 'assert_function' }, + { 'assertIsThread' , 'assert_thread' }, + { 'assertIsUserdata' , 'assert_userdata' }, + + -- type assertions: assertNotIsXXX -> assert_not_is_xxx + { 'assertNotIsNumber' , 'assert_not_is_number' }, + { 'assertNotIsString' , 'assert_not_is_string' }, + { 'assertNotIsTable' , 'assert_not_is_table' }, + { 'assertNotIsBoolean' , 'assert_not_is_boolean' }, + { 'assertNotIsNil' , 'assert_not_is_nil' }, + { 'assertNotIsTrue' , 'assert_not_is_true' }, + { 'assertNotIsFalse' , 'assert_not_is_false' }, + { 'assertNotIsNaN' , 'assert_not_is_nan' }, + { 'assertNotIsInf' , 'assert_not_is_inf' }, + { 'assertNotIsPlusInf' , 'assert_not_plus_inf' }, + { 'assertNotIsMinusInf' , 'assert_not_minus_inf' }, + { 'assertNotIsPlusZero' , 'assert_not_plus_zero' }, + { 'assertNotIsMinusZero' , 'assert_not_minus_zero' }, + { 'assertNotIsFunction' , 'assert_not_is_function' }, + { 'assertNotIsThread' , 'assert_not_is_thread' }, + { 'assertNotIsUserdata' , 'assert_not_is_userdata' }, + + -- type assertions: assertNotIsXXX -> assertNotXxx (luaunit v2 compat) + { 'assertNotIsNumber' , 'assertNotNumber' }, + { 'assertNotIsString' , 'assertNotString' }, + { 'assertNotIsTable' , 'assertNotTable' }, + { 'assertNotIsBoolean' , 'assertNotBoolean' }, + { 'assertNotIsNil' , 'assertNotNil' }, + { 'assertNotIsTrue' , 'assertNotTrue' }, + { 'assertNotIsFalse' , 'assertNotFalse' }, + { 'assertNotIsNaN' , 'assertNotNaN' }, + { 'assertNotIsInf' , 'assertNotInf' }, + { 'assertNotIsPlusInf' , 'assertNotPlusInf' }, + { 'assertNotIsMinusInf' , 'assertNotMinusInf' }, + { 'assertNotIsPlusZero' , 'assertNotPlusZero' }, + { 'assertNotIsMinusZero' , 'assertNotMinusZero' }, + { 'assertNotIsFunction' , 'assertNotFunction' }, + { 'assertNotIsThread' , 'assertNotThread' }, + { 'assertNotIsUserdata' , 'assertNotUserdata' }, + + -- type assertions: assertNotIsXXX -> assert_not_xxx + { 'assertNotIsNumber' , 'assert_not_number' }, + { 'assertNotIsString' , 'assert_not_string' }, + { 'assertNotIsTable' , 'assert_not_table' }, + { 'assertNotIsBoolean' , 'assert_not_boolean' }, + { 'assertNotIsNil' , 'assert_not_nil' }, + { 'assertNotIsTrue' , 'assert_not_true' }, + { 'assertNotIsFalse' , 'assert_not_false' }, + { 'assertNotIsNaN' , 'assert_not_nan' }, + { 'assertNotIsInf' , 'assert_not_inf' }, + { 'assertNotIsPlusInf' , 'assert_not_plus_inf' }, + { 'assertNotIsMinusInf' , 'assert_not_minus_inf' }, + { 'assertNotIsPlusZero' , 'assert_not_plus_zero' }, + { 'assertNotIsMinusZero' , 'assert_not_minus_zero' }, + { 'assertNotIsFunction' , 'assert_not_function' }, + { 'assertNotIsThread' , 'assert_not_thread' }, + { 'assertNotIsUserdata' , 'assert_not_userdata' }, + + -- all assertions with Coroutine duplicate Thread assertions + { 'assertIsThread' , 'assertIsCoroutine' }, + { 'assertIsThread' , 'assertCoroutine' }, + { 'assertIsThread' , 'assert_is_coroutine' }, + { 'assertIsThread' , 'assert_coroutine' }, + { 'assertNotIsThread' , 'assertNotIsCoroutine' }, + { 'assertNotIsThread' , 'assertNotCoroutine' }, + { 'assertNotIsThread' , 'assert_not_is_coroutine' }, + { 'assertNotIsThread' , 'assert_not_coroutine' }, +} + +-- Create all aliases in M +for _,v in ipairs( list_of_funcs ) do + local funcname, alias = v[1], v[2] + M[alias] = M[funcname] + + if EXPORT_ASSERT_TO_GLOBALS then + _G[funcname] = M[funcname] + _G[alias] = M[funcname] + end +end + +---------------------------------------------------------------- +-- +-- Outputters +-- +---------------------------------------------------------------- + +-- A common "base" class for outputters +-- For concepts involved (class inheritance) see http://www.lua.org/pil/16.2.html + +local genericOutput = { __class__ = 'genericOutput' } -- class +local genericOutput_MT = { __index = genericOutput } -- metatable +M.genericOutput = genericOutput -- publish, so that custom classes may derive from it + +function genericOutput.new(runner, default_verbosity) + -- runner is the "parent" object controlling the output, usually a LuaUnit instance + local t = { runner = runner } + if runner then + t.result = runner.result + t.verbosity = runner.verbosity or default_verbosity + t.fname = runner.fname + else + t.verbosity = default_verbosity + end + return setmetatable( t, genericOutput_MT) +end + +-- abstract ("empty") methods +function genericOutput:startSuite() end +function genericOutput:startClass(className) end +function genericOutput:startTest(testName) end +function genericOutput:addStatus(node) end +function genericOutput:endTest(node) end +function genericOutput:endClass() end +function genericOutput:endSuite() end + + +---------------------------------------------------------------- +-- class TapOutput +---------------------------------------------------------------- + +local TapOutput = genericOutput.new() -- derived class +local TapOutput_MT = { __index = TapOutput } -- metatable +TapOutput.__class__ = 'TapOutput' + + -- For a good reference for TAP format, check: http://testanything.org/tap-specification.html + + function TapOutput.new(runner) + local t = genericOutput.new(runner, M.VERBOSITY_LOW) + return setmetatable( t, TapOutput_MT) + end + function TapOutput:startSuite() + print("1.."..self.result.testCount) + print('# Started on '..self.result.startDate) + end + function TapOutput:startClass(className) + if className ~= '[TestFunctions]' then + print('# Starting class: '..className) + end + end + + function TapOutput:addStatus( node ) + io.stdout:write("not ok ", self.result.currentTestNumber, "\t", node.testName, "\n") + if self.verbosity > M.VERBOSITY_LOW then + print( prefixString( '# ', node.msg ) ) + end + if self.verbosity > M.VERBOSITY_DEFAULT then + print( prefixString( '# ', node.stackTrace ) ) + end + end + + function TapOutput:endTest( node ) + if node:isPassed() then + io.stdout:write("ok ", self.result.currentTestNumber, "\t", node.testName, "\n") + end + end + + function TapOutput:endSuite() + print( '# '..M.LuaUnit.statusLine( self.result ) ) + return self.result.notPassedCount + end + + +-- class TapOutput end + +---------------------------------------------------------------- +-- class JUnitOutput +---------------------------------------------------------------- + +-- See directory junitxml for more information about the junit format +local JUnitOutput = genericOutput.new() -- derived class +local JUnitOutput_MT = { __index = JUnitOutput } -- metatable +JUnitOutput.__class__ = 'JUnitOutput' + + function JUnitOutput.new(runner) + local t = genericOutput.new(runner, M.VERBOSITY_LOW) + t.testList = {} + return setmetatable( t, JUnitOutput_MT ) + end + + function JUnitOutput:startSuite() + -- open xml file early to deal with errors + if self.fname == nil then + error('With Junit, an output filename must be supplied with --name!') + end + if string.sub(self.fname,-4) ~= '.xml' then + self.fname = self.fname..'.xml' + end + self.fd = io.open(self.fname, "w") + if self.fd == nil then + error("Could not open file for writing: "..self.fname) + end + + print('# XML output to '..self.fname) + print('# Started on '..self.result.startDate) + end + function JUnitOutput:startClass(className) + if className ~= '[TestFunctions]' then + print('# Starting class: '..className) + end + end + function JUnitOutput:startTest(testName) + print('# Starting test: '..testName) + end + + function JUnitOutput:addStatus( node ) + if node:isFailure() then + print( '# Failure: ' .. prefixString( '# ', node.msg ):sub(4, nil) ) + -- print('# ' .. node.stackTrace) + elseif node:isError() then + print( '# Error: ' .. prefixString( '# ' , node.msg ):sub(4, nil) ) + -- print('# ' .. node.stackTrace) + end + end + + function JUnitOutput:endSuite() + print( '# '..M.LuaUnit.statusLine(self.result)) + + -- XML file writing + self.fd:write('\n') + self.fd:write('\n') + self.fd:write(string.format( + ' \n', + self.result.runCount, self.result.startIsodate, self.result.duration, self.result.errorCount, self.result.failureCount )) + self.fd:write(" \n") + self.fd:write(string.format(' \n', _VERSION ) ) + self.fd:write(string.format(' \n', M.VERSION) ) + -- XXX please include system name and version if possible + self.fd:write(" \n") + + for i,node in ipairs(self.result.tests) do + self.fd:write(string.format(' \n', + node.className, node.testName, node.duration ) ) + if node:isNotPassed() then + self.fd:write(node:statusXML()) + end + self.fd:write(' \n') + end + + -- Next two lines are needed to validate junit ANT xsd, but really not useful in general: + self.fd:write(' \n') + self.fd:write(' \n') + + self.fd:write(' \n') + self.fd:write('\n') + self.fd:close() + return self.result.notPassedCount + end + + +-- class TapOutput end + +---------------------------------------------------------------- +-- class TextOutput +---------------------------------------------------------------- + +--[[ + +-- Python Non verbose: + +For each test: . or F or E + +If some failed tests: + ============== + ERROR / FAILURE: TestName (testfile.testclass) + --------- + Stack trace + + +then -------------- +then "Ran x tests in 0.000s" +then OK or FAILED (failures=1, error=1) + +-- Python Verbose: +testname (filename.classname) ... ok +testname (filename.classname) ... FAIL +testname (filename.classname) ... ERROR + +then -------------- +then "Ran x tests in 0.000s" +then OK or FAILED (failures=1, error=1) + +-- Ruby: +Started + . + Finished in 0.002695 seconds. + + 1 tests, 2 assertions, 0 failures, 0 errors + +-- Ruby: +>> ruby tc_simple_number2.rb +Loaded suite tc_simple_number2 +Started +F.. +Finished in 0.038617 seconds. + + 1) Failure: +test_failure(TestSimpleNumber) [tc_simple_number2.rb:16]: +Adding doesn't work. +<3> expected but was +<4>. + +3 tests, 4 assertions, 1 failures, 0 errors + +-- Java Junit +.......F. +Time: 0,003 +There was 1 failure: +1) testCapacity(junit.samples.VectorTest)junit.framework.AssertionFailedError + at junit.samples.VectorTest.testCapacity(VectorTest.java:87) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + +FAILURES!!! +Tests run: 8, Failures: 1, Errors: 0 + + +-- Maven + +# mvn test +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running math.AdditionTest +Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: +0.03 sec <<< FAILURE! + +Results : + +Failed tests: + testLireSymbole(math.AdditionTest) + +Tests run: 2, Failures: 1, Errors: 0, Skipped: 0 + + +-- LuaUnit +---- non verbose +* display . or F or E when running tests +---- verbose +* display test name + ok/fail +---- +* blank line +* number) ERROR or FAILURE: TestName + Stack trace +* blank line +* number) ERROR or FAILURE: TestName + Stack trace + +then -------------- +then "Ran x tests in 0.000s (%d not selected, %d skipped)" +then OK or FAILED (failures=1, error=1) + + +]] + +local TextOutput = genericOutput.new() -- derived class +local TextOutput_MT = { __index = TextOutput } -- metatable +TextOutput.__class__ = 'TextOutput' + + function TextOutput.new(runner) + local t = genericOutput.new(runner, M.VERBOSITY_DEFAULT) + t.errorList = {} + return setmetatable( t, TextOutput_MT ) + end + + function TextOutput:startSuite() + if self.verbosity > M.VERBOSITY_DEFAULT then + print( 'Started on '.. self.result.startDate ) + end + end + + function TextOutput:startTest(testName) + if self.verbosity > M.VERBOSITY_DEFAULT then + io.stdout:write( " ", self.result.currentNode.testName, " ... " ) + end + end + + function TextOutput:endTest( node ) + if node:isPassed() then + if self.verbosity > M.VERBOSITY_DEFAULT then + io.stdout:write("Ok\n") + else + io.stdout:write(".") + end + else + if self.verbosity > M.VERBOSITY_DEFAULT then + print( node.status ) + print( node.msg ) + --[[ + -- find out when to do this: + if self.verbosity > M.VERBOSITY_DEFAULT then + print( node.stackTrace ) + end + ]] + else + -- write only the first character of status + io.stdout:write(string.sub(node.status, 1, 1)) + end + end + end + + function TextOutput:displayOneFailedTest( index, fail ) + print(index..") "..fail.testName ) + print( fail.msg ) + print( fail.stackTrace ) + print() + end + + function TextOutput:displayFailedTests() + if self.result.notPassedCount ~= 0 then + print("Failed tests:") + print("-------------") + for i, v in ipairs(self.result.notPassed) do + self:displayOneFailedTest(i, v) + end + end + end + + function TextOutput:endSuite() + if self.verbosity > M.VERBOSITY_DEFAULT then + print("=========================================================") + else + print() + end + self:displayFailedTests() + print( M.LuaUnit.statusLine( self.result ) ) + if self.result.notPassedCount == 0 then + print('OK') + end + end + +-- class TextOutput end + + +---------------------------------------------------------------- +-- class NilOutput +---------------------------------------------------------------- + +local function nopCallable() + --print(42) + return nopCallable +end + +local NilOutput = { __class__ = 'NilOuptut' } -- class +local NilOutput_MT = { __index = nopCallable } -- metatable + +function NilOutput.new(runner) + return setmetatable( { __class__ = 'NilOutput' }, NilOutput_MT ) +end + +---------------------------------------------------------------- +-- +-- class LuaUnit +-- +---------------------------------------------------------------- + +M.LuaUnit = { + outputType = TextOutput, + verbosity = M.VERBOSITY_DEFAULT, + __class__ = 'LuaUnit' +} +local LuaUnit_MT = { __index = M.LuaUnit } + +if EXPORT_ASSERT_TO_GLOBALS then + LuaUnit = M.LuaUnit +end + + function M.LuaUnit.new() + return setmetatable( {}, LuaUnit_MT ) + end + + -----------------[[ Utility methods ]]--------------------- + + function M.LuaUnit.asFunction(aObject) + -- return "aObject" if it is a function, and nil otherwise + if 'function' == type(aObject) then + return aObject + end + end + + function M.LuaUnit.splitClassMethod(someName) + --[[ + Return a pair of className, methodName strings for a name in the form + "class.method". If no class part (or separator) is found, will return + nil, someName instead (the latter being unchanged). + + This convention thus also replaces the older isClassMethod() test: + You just have to check for a non-nil className (return) value. + ]] + local separator = string.find(someName, '.', 1, true) + if separator then + return someName:sub(1, separator - 1), someName:sub(separator + 1) + end + return nil, someName + end + + function M.LuaUnit.isMethodTestName( s ) + -- return true is the name matches the name of a test method + -- default rule is that is starts with 'Test' or with 'test' + return string.sub(s, 1, 4):lower() == 'test' + end + + function M.LuaUnit.isTestName( s ) + -- return true is the name matches the name of a test + -- default rule is that is starts with 'Test' or with 'test' + return string.sub(s, 1, 4):lower() == 'test' + end + + function M.LuaUnit.collectTests() + -- return a list of all test names in the global namespace + -- that match LuaUnit.isTestName + + local testNames = {} + for k, _ in pairs(_G) do + if type(k) == "string" and M.LuaUnit.isTestName( k ) then + table.insert( testNames , k ) + end + end + table.sort( testNames ) + return testNames + end + + function M.LuaUnit.parseCmdLine( cmdLine ) + -- parse the command line + -- Supported command line parameters: + -- --verbose, -v: increase verbosity + -- --quiet, -q: silence output + -- --error, -e: treat errors as fatal (quit program) + -- --output, -o, + name: select output type + -- --pattern, -p, + pattern: run test matching pattern, may be repeated + -- --exclude, -x, + pattern: run test not matching pattern, may be repeated + -- --shuffle, -s, : shuffle tests before reunning them + -- --name, -n, + fname: name of output file for junit, default to stdout + -- --repeat, -r, + num: number of times to execute each test + -- [testnames, ...]: run selected test names + -- + -- Returns a table with the following fields: + -- verbosity: nil, M.VERBOSITY_DEFAULT, M.VERBOSITY_QUIET, M.VERBOSITY_VERBOSE + -- output: nil, 'tap', 'junit', 'text', 'nil' + -- testNames: nil or a list of test names to run + -- exeRepeat: num or 1 + -- pattern: nil or a list of patterns + -- exclude: nil or a list of patterns + + local result, state = {}, nil + local SET_OUTPUT = 1 + local SET_PATTERN = 2 + local SET_EXCLUDE = 3 + local SET_FNAME = 4 + local SET_REPEAT = 5 + + if cmdLine == nil then + return result + end + + local function parseOption( option ) + if option == '--help' or option == '-h' then + result['help'] = true + return + elseif option == '--version' then + result['version'] = true + return + elseif option == '--verbose' or option == '-v' then + result['verbosity'] = M.VERBOSITY_VERBOSE + return + elseif option == '--quiet' or option == '-q' then + result['verbosity'] = M.VERBOSITY_QUIET + return + elseif option == '--error' or option == '-e' then + result['quitOnError'] = true + return + elseif option == '--failure' or option == '-f' then + result['quitOnFailure'] = true + return + elseif option == '--shuffle' or option == '-s' then + result['shuffle'] = true + return + elseif option == '--output' or option == '-o' then + state = SET_OUTPUT + return state + elseif option == '--name' or option == '-n' then + state = SET_FNAME + return state + elseif option == '--repeat' or option == '-r' then + state = SET_REPEAT + return state + elseif option == '--pattern' or option == '-p' then + state = SET_PATTERN + return state + elseif option == '--exclude' or option == '-x' then + state = SET_EXCLUDE + return state + end + error('Unknown option: '..option,3) + end + + local function setArg( cmdArg, state ) + if state == SET_OUTPUT then + result['output'] = cmdArg + return + elseif state == SET_FNAME then + result['fname'] = cmdArg + return + elseif state == SET_REPEAT then + result['exeRepeat'] = tonumber(cmdArg) + or error('Malformed -r argument: '..cmdArg) + return + elseif state == SET_PATTERN then + if result['pattern'] then + table.insert( result['pattern'], cmdArg ) + else + result['pattern'] = { cmdArg } + end + return + elseif state == SET_EXCLUDE then + local notArg = '!'..cmdArg + if result['pattern'] then + table.insert( result['pattern'], notArg ) + else + result['pattern'] = { notArg } + end + return + end + error('Unknown parse state: '.. state) + end + + + for i, cmdArg in ipairs(cmdLine) do + if state ~= nil then + setArg( cmdArg, state, result ) + state = nil + else + if cmdArg:sub(1,1) == '-' then + state = parseOption( cmdArg ) + else + if result['testNames'] then + table.insert( result['testNames'], cmdArg ) + else + result['testNames'] = { cmdArg } + end + end + end + end + + if result['help'] then + M.LuaUnit.help() + end + + if result['version'] then + M.LuaUnit.version() + end + + if state ~= nil then + error('Missing argument after '..cmdLine[ #cmdLine ],2 ) + end + + return result + end + + function M.LuaUnit.help() + print(M.USAGE) + os.exit(0) + end + + function M.LuaUnit.version() + print('LuaUnit v'..M.VERSION..' by Philippe Fremy ') + os.exit(0) + end + +---------------------------------------------------------------- +-- class NodeStatus +---------------------------------------------------------------- + + local NodeStatus = { __class__ = 'NodeStatus' } -- class + local NodeStatus_MT = { __index = NodeStatus } -- metatable + M.NodeStatus = NodeStatus + + -- values of status + NodeStatus.PASS = 'PASS' + NodeStatus.FAIL = 'FAIL' + NodeStatus.ERROR = 'ERROR' + + function NodeStatus.new( number, testName, className ) + local t = { number = number, testName = testName, className = className } + setmetatable( t, NodeStatus_MT ) + t:pass() + return t + end + + function NodeStatus:pass() + self.status = self.PASS + -- useless but we know it's the field we want to use + self.msg = nil + self.stackTrace = nil + end + + function NodeStatus:fail(msg, stackTrace) + self.status = self.FAIL + self.msg = msg + self.stackTrace = stackTrace + end + + function NodeStatus:error(msg, stackTrace) + self.status = self.ERROR + self.msg = msg + self.stackTrace = stackTrace + end + + function NodeStatus:isPassed() + return self.status == NodeStatus.PASS + end + + function NodeStatus:isNotPassed() + -- print('hasFailure: '..prettystr(self)) + return self.status ~= NodeStatus.PASS + end + + function NodeStatus:isFailure() + return self.status == NodeStatus.FAIL + end + + function NodeStatus:isError() + return self.status == NodeStatus.ERROR + end + + function NodeStatus:statusXML() + if self:isError() then + return table.concat( + {' \n', + ' \n'}) + elseif self:isFailure() then + return table.concat( + {' \n', + ' \n'}) + end + return ' \n' -- (not XSD-compliant! normally shouldn't get here) + end + + --------------[[ Output methods ]]------------------------- + + local function conditional_plural(number, singular) + -- returns a grammatically well-formed string "%d " + local suffix = '' + if number ~= 1 then -- use plural + suffix = (singular:sub(-2) == 'ss') and 'es' or 's' + end + return string.format('%d %s%s', number, singular, suffix) + end + + function M.LuaUnit.statusLine(result) + -- return status line string according to results + local s = { + string.format('Ran %d tests in %0.3f seconds', + result.runCount, result.duration), + conditional_plural(result.passedCount, 'success'), + } + if result.notPassedCount > 0 then + if result.failureCount > 0 then + table.insert(s, conditional_plural(result.failureCount, 'failure')) + end + if result.errorCount > 0 then + table.insert(s, conditional_plural(result.errorCount, 'error')) + end + else + table.insert(s, '0 failures') + end + if result.nonSelectedCount > 0 then + table.insert(s, string.format("%d non-selected", result.nonSelectedCount)) + end + return table.concat(s, ', ') + end + + function M.LuaUnit:startSuite(testCount, nonSelectedCount) + self.result = { + testCount = testCount, + nonSelectedCount = nonSelectedCount, + passedCount = 0, + runCount = 0, + currentTestNumber = 0, + currentClassName = "", + currentNode = nil, + suiteStarted = true, + startTime = os.clock(), + startDate = os.date(os.getenv('LUAUNIT_DATEFMT')), + startIsodate = os.date('%Y-%m-%dT%H:%M:%S'), + patternIncludeFilter = self.patternIncludeFilter, + tests = {}, + failures = {}, + errors = {}, + notPassed = {}, + } + + self.outputType = self.outputType or TextOutput + self.output = self.outputType.new(self) + self.output:startSuite() + end + + function M.LuaUnit:startClass( className ) + self.result.currentClassName = className + self.output:startClass( className ) + end + + function M.LuaUnit:startTest( testName ) + self.result.currentTestNumber = self.result.currentTestNumber + 1 + self.result.runCount = self.result.runCount + 1 + self.result.currentNode = NodeStatus.new( + self.result.currentTestNumber, + testName, + self.result.currentClassName + ) + self.result.currentNode.startTime = os.clock() + table.insert( self.result.tests, self.result.currentNode ) + self.output:startTest( testName ) + end + + function M.LuaUnit:addStatus( err ) + -- "err" is expected to be a table / result from protectedCall() + if err.status == NodeStatus.PASS then + return + end + + local node = self.result.currentNode + + --[[ As a first approach, we will report only one error or one failure for one test. + + However, we can have the case where the test is in failure, and the teardown is in error. + In such case, it's a good idea to report both a failure and an error in the test suite. This is + what Python unittest does for example. However, it mixes up counts so need to be handled carefully: for + example, there could be more (failures + errors) count that tests. What happens to the current node ? + + We will do this more intelligent version later. + ]] + + -- if the node is already in failure/error, just don't report the new error (see above) + if node.status ~= NodeStatus.PASS then + return + end + + if err.status == NodeStatus.FAIL then + node:fail( err.msg, err.trace ) + table.insert( self.result.failures, node ) + elseif err.status == NodeStatus.ERROR then + node:error( err.msg, err.trace ) + table.insert( self.result.errors, node ) + end + + if node:isFailure() or node:isError() then + -- add to the list of failed tests (gets printed separately) + table.insert( self.result.notPassed, node ) + end + self.output:addStatus( node ) + end + + function M.LuaUnit:endTest() + local node = self.result.currentNode + -- print( 'endTest() '..prettystr(node)) + -- print( 'endTest() '..prettystr(node:isNotPassed())) + node.duration = os.clock() - node.startTime + node.startTime = nil + self.output:endTest( node ) + + if node:isPassed() then + self.result.passedCount = self.result.passedCount + 1 + elseif node:isError() then + if self.quitOnError or self.quitOnFailure then + -- Runtime error - abort test execution as requested by + -- "--error" option. This is done by setting a special + -- flag that gets handled in runSuiteByInstances(). + print("\nERROR during LuaUnit test execution:\n" .. node.msg) + self.result.aborted = true + end + elseif node:isFailure() then + if self.quitOnFailure then + -- Failure - abort test execution as requested by + -- "--failure" option. This is done by setting a special + -- flag that gets handled in runSuiteByInstances(). + print("\nFailure during LuaUnit test execution:\n" .. node.msg) + self.result.aborted = true + end + end + self.result.currentNode = nil + end + + function M.LuaUnit:endClass() + self.output:endClass() + end + + function M.LuaUnit:endSuite() + if self.result.suiteStarted == false then + error('LuaUnit:endSuite() -- suite was already ended' ) + end + self.result.duration = os.clock()-self.result.startTime + self.result.suiteStarted = false + + -- Expose test counts for outputter's endSuite(). This could be managed + -- internally instead, but unit tests (and existing use cases) might + -- rely on these fields being present. + self.result.notPassedCount = #self.result.notPassed + self.result.failureCount = #self.result.failures + self.result.errorCount = #self.result.errors + + self.output:endSuite() + end + + function M.LuaUnit:setOutputType(outputType) + -- default to text + -- tap produces results according to TAP format + if outputType:upper() == "NIL" then + self.outputType = NilOutput + return + end + if outputType:upper() == "TAP" then + self.outputType = TapOutput + return + end + if outputType:upper() == "JUNIT" then + self.outputType = JUnitOutput + return + end + if outputType:upper() == "TEXT" then + self.outputType = TextOutput + return + end + error( 'No such format: '..outputType,2) + end + + --------------[[ Runner ]]----------------- + + function M.LuaUnit:protectedCall(classInstance, methodInstance, prettyFuncName) + -- if classInstance is nil, this is just a function call + -- else, it's method of a class being called. + + local function err_handler(e) + -- transform error into a table, adding the traceback information + return { + status = NodeStatus.ERROR, + msg = e, + trace = string.sub(debug.traceback("", 3), 2) + } + end + + local ok, err + if classInstance then + -- stupid Lua < 5.2 does not allow xpcall with arguments so let's use a workaround + ok, err = xpcall( function () methodInstance(classInstance) end, err_handler ) + else + ok, err = xpcall( function () methodInstance() end, err_handler ) + end + if ok then + return {status = NodeStatus.PASS} + end + + local iter_msg + iter_msg = self.exeRepeat and 'iteration '..self.currentCount + + err.msg, err.status = M.adjust_err_msg_with_iter( err.msg, iter_msg ) + + if err.status == NodeStatus.PASS then + err.trace = nil + return err + end + + -- reformat / improve the stack trace + if prettyFuncName then -- we do have the real method name + err.trace = err.trace:gsub("in (%a+) 'methodInstance'", "in %1 '"..prettyFuncName.."'") + end + if STRIP_LUAUNIT_FROM_STACKTRACE then + err.trace = stripLuaunitTrace(err.trace) + end + + return err -- return the error "object" (table) + end + + + function M.LuaUnit:execOneFunction(className, methodName, classInstance, methodInstance) + -- When executing a test function, className and classInstance must be nil + -- When executing a class method, all parameters must be set + + if type(methodInstance) ~= 'function' then + error( tostring(methodName)..' must be a function, not '..type(methodInstance)) + end + + local prettyFuncName + if className == nil then + className = '[TestFunctions]' + prettyFuncName = methodName + else + prettyFuncName = className..'.'..methodName + end + + if self.lastClassName ~= className then + if self.lastClassName ~= nil then + self:endClass() + end + self:startClass( className ) + self.lastClassName = className + end + + self:startTest(prettyFuncName) + + local node = self.result.currentNode + for iter_n = 1, self.exeRepeat or 1 do + if node:isNotPassed() then + break + end + self.currentCount = iter_n + + -- run setUp first (if any) + if classInstance then + local func = self.asFunction( classInstance.setUp ) or + self.asFunction( classInstance.Setup ) or + self.asFunction( classInstance.setup ) or + self.asFunction( classInstance.SetUp ) + if func then + self:addStatus(self:protectedCall(classInstance, func, className..'.setUp')) + end + end + + -- run testMethod() + if node:isPassed() then + self:addStatus(self:protectedCall(classInstance, methodInstance, prettyFuncName)) + end + + -- lastly, run tearDown (if any) + if classInstance then + local func = self.asFunction( classInstance.tearDown ) or + self.asFunction( classInstance.TearDown ) or + self.asFunction( classInstance.teardown ) or + self.asFunction( classInstance.Teardown ) + if func then + self:addStatus(self:protectedCall(classInstance, func, className..'.tearDown')) + end + end + end + + self:endTest() + end + + function M.LuaUnit.expandOneClass( result, className, classInstance ) + --[[ + Input: a list of { name, instance }, a class name, a class instance + Ouptut: modify result to add all test method instance in the form: + { className.methodName, classInstance } + ]] + for methodName, methodInstance in sortedPairs(classInstance) do + if M.LuaUnit.asFunction(methodInstance) and M.LuaUnit.isMethodTestName( methodName ) then + table.insert( result, { className..'.'..methodName, classInstance } ) + end + end + end + + function M.LuaUnit.expandClasses( listOfNameAndInst ) + --[[ + -- expand all classes (provided as {className, classInstance}) to a list of {className.methodName, classInstance} + -- functions and methods remain untouched + + Input: a list of { name, instance } + + Output: + * { function name, function instance } : do nothing + * { class.method name, class instance }: do nothing + * { class name, class instance } : add all method names in the form of (className.methodName, classInstance) + ]] + local result = {} + + for i,v in ipairs( listOfNameAndInst ) do + local name, instance = v[1], v[2] + if M.LuaUnit.asFunction(instance) then + table.insert( result, { name, instance } ) + else + if type(instance) ~= 'table' then + error( 'Instance must be a table or a function, not a '..type(instance)..' with value '..prettystr(instance)) + end + local className, methodName = M.LuaUnit.splitClassMethod( name ) + if className then + local methodInstance = instance[methodName] + if methodInstance == nil then + error( "Could not find method in class "..tostring(className).." for method "..tostring(methodName) ) + end + table.insert( result, { name, instance } ) + else + M.LuaUnit.expandOneClass( result, name, instance ) + end + end + end + + return result + end + + function M.LuaUnit.applyPatternFilter( patternIncFilter, listOfNameAndInst ) + local included, excluded = {}, {} + for i, v in ipairs( listOfNameAndInst ) do + -- local name, instance = v[1], v[2] + if patternFilter( patternIncFilter, v[1] ) then + table.insert( included, v ) + else + table.insert( excluded, v ) + end + end + return included, excluded + end + + function M.LuaUnit:runSuiteByInstances( listOfNameAndInst ) + --[[ Run an explicit list of tests. Each item of the list must be one of: + * { function name, function instance } + * { class name, class instance } + * { class.method name, class instance } + ]] + + local expandedList = self.expandClasses( listOfNameAndInst ) + if self.shuffle then + randomizeTable( expandedList ) + end + local filteredList, filteredOutList = self.applyPatternFilter( + self.patternIncludeFilter, expandedList ) + + self:startSuite( #filteredList, #filteredOutList ) + + for i,v in ipairs( filteredList ) do + local name, instance = v[1], v[2] + if M.LuaUnit.asFunction(instance) then + self:execOneFunction( nil, name, nil, instance ) + else + -- expandClasses() should have already taken care of sanitizing the input + assert( type(instance) == 'table' ) + local className, methodName = M.LuaUnit.splitClassMethod( name ) + assert( className ~= nil ) + local methodInstance = instance[methodName] + assert(methodInstance ~= nil) + self:execOneFunction( className, methodName, instance, methodInstance ) + end + if self.result.aborted then + break -- "--error" or "--failure" option triggered + end + end + + if self.lastClassName ~= nil then + self:endClass() + end + + self:endSuite() + + if self.result.aborted then + print("LuaUnit ABORTED (as requested by --error or --failure option)") + os.exit(-2) + end + end + + function M.LuaUnit:runSuiteByNames( listOfName ) + --[[ Run LuaUnit with a list of generic names, coming either from command-line or from global + namespace analysis. Convert the list into a list of (name, valid instances (table or function)) + and calls runSuiteByInstances. + ]] + + local instanceName, instance + local listOfNameAndInst = {} + + for i,name in ipairs( listOfName ) do + local className, methodName = M.LuaUnit.splitClassMethod( name ) + if className then + instanceName = className + instance = _G[instanceName] + + if instance == nil then + error( "No such name in global space: "..instanceName ) + end + + if type(instance) ~= 'table' then + error( 'Instance of '..instanceName..' must be a table, not '..type(instance)) + end + + local methodInstance = instance[methodName] + if methodInstance == nil then + error( "Could not find method in class "..tostring(className).." for method "..tostring(methodName) ) + end + + else + -- for functions and classes + instanceName = name + instance = _G[instanceName] + end + + if instance == nil then + error( "No such name in global space: "..instanceName ) + end + + if (type(instance) ~= 'table' and type(instance) ~= 'function') then + error( 'Name must match a function or a table: '..instanceName ) + end + + table.insert( listOfNameAndInst, { name, instance } ) + end + + self:runSuiteByInstances( listOfNameAndInst ) + end + + function M.LuaUnit.run(...) + -- Run some specific test classes. + -- If no arguments are passed, run the class names specified on the + -- command line. If no class name is specified on the command line + -- run all classes whose name starts with 'Test' + -- + -- If arguments are passed, they must be strings of the class names + -- that you want to run or generic command line arguments (-o, -p, -v, ...) + + local runner = M.LuaUnit.new() + return runner:runSuite(...) + end + + function M.LuaUnit:runSuite( ... ) + + local args = {...} + if type(args[1]) == 'table' and args[1].__class__ == 'LuaUnit' then + -- run was called with the syntax M.LuaUnit:runSuite() + -- we support both M.LuaUnit.run() and M.LuaUnit:run() + -- strip out the first argument + table.remove(args,1) + end + + if #args == 0 then + args = cmdline_argv + end + + local options = pcall_or_abort( M.LuaUnit.parseCmdLine, args ) + + -- We expect these option fields to be either `nil` or contain + -- valid values, so it's safe to always copy them directly. + self.verbosity = options.verbosity + self.quitOnError = options.quitOnError + self.quitOnFailure = options.quitOnFailure + self.fname = options.fname + + self.exeRepeat = options.exeRepeat + self.patternIncludeFilter = options.pattern + self.shuffle = options.shuffle + + if options.output then + if options.output:lower() == 'junit' and options.fname == nil then + print('With junit output, a filename must be supplied with -n or --name') + os.exit(-1) + end + pcall_or_abort(self.setOutputType, self, options.output) + end + + self:runSuiteByNames( options.testNames or M.LuaUnit.collectTests() ) + + return self.result.notPassedCount + end +-- class LuaUnit + +-- For compatbility with LuaUnit v2 +M.run = M.LuaUnit.run +M.Run = M.LuaUnit.run + +function M:setVerbosity( verbosity ) + M.LuaUnit.verbosity = verbosity +end +M.set_verbosity = M.setVerbosity +M.SetVerbosity = M.setVerbosity + + +return M diff -Nru lua-unit-3.2/README.md lua-unit-3.3/README.md --- lua-unit-3.2/README.md 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/README.md 2018-04-20 12:34:12.000000000 +0000 @@ -1,165 +1,248 @@ -## LuaUnit -by Philippe Fremy - -[![Build status](https://ci.appveyor.com/api/projects/status/us6uh4e5q597jj54?svg=true&passingText=Windows%20Build%20passing&failingText=Windows%20Build%20failed)](https://ci.appveyor.com/project/bluebird75/luaunit) -[![Build Status](https://travis-ci.org/bluebird75/luaunit.svg?branch=master)](https://travis-ci.org/bluebird75/luaunit) -[![Documentation Status](https://readthedocs.org/projects/luaunit/badge/?version=latest)](https://readthedocs.org/projects/luaunit/?badge=latest) - -LuaUnit is a unit-testing framework for Lua. It allows you -to write test functions and test classes with test methods, combined with -setup/teardown functionality. A wide range of assertions are supported. - -LuaUnit supports several output formats, like JUnit or TAP, for easier integration -into Continuous Integration platforms (Jenkins, Maven, ...). The integrated command-line -options provide a flexible interface to select tests by name or patterns, control output -format, set verbosity, ... - -LuaUnit works with Lua 5.1, LuaJIT 2.0, LuaJIT 2.1 beta, Lua 5.2 and Lua 5.3 . It is tested on Windows Seven, Windows Server 2012 R2 (x64) and Ubuntu 14.04 (see -continuous build results on [Travis-CI](https://travis-ci.org/bluebird75/luaunit) and [AppVeyor](https://ci.appveyor.com/project/bluebird75/luaunit) ) and should work on all platforms supported by Lua. -It has no other dependency than Lua itself. - -LuaUnit is packed into a single-file. To make start using it, just add the file to your project. - -LuaUnit is maintained on github: -https://github.com/bluebird75/luaunit - -For more information on LuaUnit development, please check: [Developing LuaUnit](http://luaunit.readthedocs.org/en/latest/#developing-luaunit) - -It is released under the BSD license. - -Documentation is available on -[read-the-docs](http://luaunit.readthedocs.org/en/latest/) - -**Important note when upgrading to version 3.1 and above** : break of backward compatibility, assertions functions are -no longer exported directly to the global namespace. See [documentation](http://luaunit.readthedocs.io/en/latest/#luaunit-global-asserts) on how to adjust or restore previous behavior. - - -##Install - -The version in development on github is always stable and can be used safely. - -**github** - -The simplest way to install LuaUnit is to fetch the github version: - - git clone git@github.com:bluebird75/luaunit.git - -Then copy the file luaunit.lua into your project or the Lua libs directory. - -On Linux, you can also install it into your Lua directories - - sudo python doit.py install - -Edit `install()` for Lua version and installation directory if that -fails. It uses, by default, Linux paths that depend on the version. - -**bower** - -You can also install it with bower : - - bower install https://github.com/bluebird75/luaunit.git. - -**LuaRocks** - -LuaUnit v3.2 and above are available on LuaRocks. - -##Contributors -* [NiteHawk](https://github.com/n1tehawk) -* [AbigailBuccaneer](https://github.com/AbigailBuccaneer) -* [Juan Julián Merelo Guervós](https://github.com/JJ) -* [Naoyuki Totani](https://github.com/ntotani) -* [Jennal](https://github.com/Jennal) -* [George Zhao](https://github.com/zhaozg) -* kbuschelman -* [Victor Seva](https://github.com/linuxmaniac) -* [Urs Breu](https://github.com/ubreu) -* Jim Anderson - -### History - -#### Version 3.2 - 12. Jul 2016 -* distinguish between failures (failed assertion) and errors -* add command-line option to stop on first error or failure -* support for new versions: Lua 5.3 and LuaJIT (2.0, 2.1 beta) -* validation of all lua versions on Travis CI and AppVeyor -* added compatibility layer with forked luaunit v2.x -* added documentation about development process -* improved support for table containing keys of type table -* small bug fixes, several internal improvements - -#### Version 3.1 - 10 Mar. 2015 -* luaunit no longer pollutes global namespace, unless defining EXPORT_ASSERT_TO_GLOBALS to true -* fixes and validation of JUnit XML generation -* strip luaunit internal information from stacktrace -* general improvements of test results with duration and other details -* improve printing for tables, with an option to always print table id -* fix printing of recursive tables - -**Important note when upgrading to version 3.1** : assertions functions are -no longer exported directly to the global namespace. See documentation for upgrade -paths. - -#### Version 3.0 - 9. Oct 2014 - -Since some people have forked LuaUnit and release some 2.x version, I am -jumping the version number. - -- moved to Github -- full documentation available in text, html and pdf at read-the-docs.org -- new output format: JUnit -- much better table assertions -- new assertions for strings, with patterns and case insensitivity: assertStrContains, - assertNotStrContains, assertNotStrIContains, assertStrIContains, assertStrMatches -- new assertions for floats: assertAlmostEquals, assertNotAlmostEquals -- type assertions: assertIsString, assertIsNumber, ... -- error assertions: assertErrorMsgEquals, assertErrorMsgContains, assertErrorMsgMatches -- improved error messages for several assertions -- command-line options to select test, control output type and verbosity - -#### Version 2.0 -Unofficial fork from version 1.3 -- lua 5.2 module style, without global namespace pollution -- setUp() may be named Setup() or setup() -- tearDown() may be named Teardown() or teardown() -- wrapFunction() may be called WrapFunctions() or wrap_functions() -- run() may also be called Run() -- table deep comparision (also available in 1.4) -- control verbosity with setVerbosity() SetVerbosity() and set_verbosity() -- More assertions: - + is, is_, assert and assert_ (e.g. assert( LuaUnit.isString( getString() ) ) - + assertNot and assert_not_ - -#### Version 1.5 - 8. Nov 2012 -- compatibility with Lua 5.1 and 5.2 -- better object model internally -- a lot more of internal tests -- several internal bug fixes -- make it easy to customize the test output -- running test functions no longer requires a wrapper -- several level of verbosity - - -#### Version 1.4 - 26. Jul 2012 -- table deep comparison -- switch from X11 to more popular BSD license -- add TAP output format for integration into Jenkins -- official repository now on github - - -#### Version 1.3 - 30. Oct 2007 -- port to lua 5.1 -- iterate over the test classes, methods and functions in the alphabetical order -- change the default order of expected, actual in assertEquals (adjustable with USE_EXPECTED_ACTUAL_IN_ASSERT_EQUALS). - - -#### Version 1.2 - 13. Jun 2005 -- first public release - - -#### Version 1.1 -- move global variables to internal variables -- assertion order is configurable between expected/actual or actual/expected -- new assertion to check that a function call returns an error -- display the calling stack when an error is spotted -- two verbosity level, like in python unittest - +[![Build status](https://ci.appveyor.com/api/projects/status/us6uh4e5q597jj54?svg=true&passingText=Windows%20Build%20passing&failingText=Windows%20Build%20failed)](https://ci.appveyor.com/project/bluebird75/luaunit) +[![Build Status](https://travis-ci.org/bluebird75/luaunit.svg?branch=master)](https://travis-ci.org/bluebird75/luaunit) +[![Documentation Status](https://readthedocs.org/projects/luaunit/badge/?version=latest)](https://readthedocs.org/projects/luaunit/?badge=latest) +[![Coverage Status](https://coveralls.io/repos/github/bluebird75/luaunit/badge.svg?branch=master)](https://coveralls.io/github/bluebird75/luaunit?branch=master) +[![Downloads](https://img.shields.io/badge/downloads-235k-brightgreen.svg)](https://luarocks.org/modules/bluebird75/luaunit) +[![License](http://img.shields.io/badge/License-BSD-green.svg)](LICENSE.txt) + +## LuaUnit +by Philippe Fremy + +LuaUnit is a popular unit-testing framework for Lua, with an interface typical +of xUnit libraries (Python unittest, Junit, NUnit, ...). It supports +several output formats (Text, TAP, JUnit, ...) to be used directly or work with Continuous Integration platforms +(Jenkins, Hudson, ...). + +For simplicity, LuaUnit is contained into a single-file and has no external dependency. To start using it, +just add the file *luaunit.lua* to your project. A [LuaRocks package](https://luarocks.org/modules/bluebird75/luaunit) is also available. + +Tutorial and reference documentation is available on +[read-the-docs](http://luaunit.readthedocs.org/en/latest/) + +LuaUnit may also be used as an assertion library, to validate assertions inside a running program. In addition, it provides +a pretty stringifier which converts any type into a nicely formatted string (including complex nested or recursive tables). + +## More details + +LuaUnit provides a wide range of assertions and goes into great efforts to provide the most useful output. For example +since version 3.3 , comparing lists will provide a detailed difference analysis: + + -- lua test code. Can you spot the difference ? + function TestListCompare:test1() + local A = { 121221, 122211, 121221, 122211, 121221, 122212, 121212, 122112, 122121, 121212, 122121 } + local B = { 121221, 122211, 121221, 122211, 121221, 122212, 121212, 122112, 121221, 121212, 122121 } + lu.assertEquals( A, B ) + end + + $ lua test_some_lists_comparison.lua + + TestListCompare.test1 ... FAIL + test/some_lists_comparisons.lua:22: expected: + + List difference analysis: + * lists A (actual) and B (expected) have the same size + * lists A and B start differing at index 9 + * lists A and B are equal again from index 10 + * Common parts: + = A[1], B[1]: 121221 + = A[2], B[2]: 122211 + = A[3], B[3]: 121221 + = A[4], B[4]: 122211 + = A[5], B[5]: 121221 + = A[6], B[6]: 122212 + = A[7], B[7]: 121212 + = A[8], B[8]: 122112 + * Differing parts: + - A[9]: 122121 + + B[9]: 121221 + * Common parts at the end of the lists + = A[10], B[10]: 121212 + = A[11], B[11]: 122121 + + +The command-line options provide a flexible interface to select tests by name or patterns, control output +format, set verbosity and more. See [the documentation](http://luaunit.readthedocs.io/en/latest/#command-line-options) . + +LuaUnit also provides some dedicated support to scientific computing. See [the documentation](http://luaunit.readthedocs.io/en/latest/#scientific-computing-and-luaunit) . + +LuaUnit is very well tested: code coverage is 99.5% . The test suite is run on every version of Lua (Lua 5.1 to 5.3, LuaJIT 2.0 and 2.1 beta) +and on many OS (Windows Seven, Windows Server 2012, MacOs X and Ubuntu). You can check the continuous build results on [Travis-CI](https://travis-ci.org/bluebird75/luaunit) and [AppVeyor](https://ci.appveyor.com/project/bluebird75/luaunit). + +LuaUnit is maintained on GitHub: https://github.com/bluebird75/luaunit . We gladly accept feature requests and even better Pull Requests. +For more information on LuaUnit development, please check: [Developing LuaUnit](http://luaunit.readthedocs.org/en/latest/#developing-luaunit) . + +LuaUnit is released under the BSD license. + +## LuaUnit successes + +Version 3.2 of LuaUnit has been downloaded more than 235 000 times on [LuaRocks](https://luarocks.org/modules/bluebird75/luaunit) + +LuaUnit is used in some very nice technological products. I like to mention: + +* [SchedMD/Slurm](https://www.schedmd.com/): Slurm is an open-source cluster resource management and job scheduling +system that strives to be simple, scalable, portable, fault-tolerant, and interconnect agnostic. On the June 2017 Top 500 computer +list, Slurm was performing workload management on six of the ten most powerful computers in the world including the number 1 system, +Sunway TaihuLight with 10,649,600 computing cores. LuaUnit is used by Slurm to validate plugins written in Lua. Thanks Douglas Jacobsen +to contribute back to LuaUnit. See the [GitHub repository of Slurm](https://github.com/SchedMD/slurm) . + +* [MAD by the CERN](http://mad.web.cern.ch/mad/): CERN is the European Organization for Nuclear Research, where physicists and engineers are +probing the fundamental structure of the universe. MAD is one of the CERN project: MAD aims to be at the forefront of computational physics in +the field of particle accelerator design and simulation. Its scripting language is de facto the standard to describe particle accelerators, simulate +beam dynamics and optimize beam optics at CERN. Lua is the main language of MAD-ng, the new generatino of MAD. A fork of LuaUnit is used extensively +for all MAD calculation and framework validation. Thanks Laurent Deniau for contributing back to LuaUnit. See the [GitHub repository of MAD](https://github.com/MethodicalAcceleratorDesign/MAD) . + +## Contributors +* [NiteHawk](https://github.com/n1tehawk) +* [AbigailBuccaneer](https://github.com/AbigailBuccaneer) +* [Juan Julián Merelo Guervós](https://github.com/JJ) +* [Naoyuki Totani](https://github.com/ntotani) +* [Jennal](https://github.com/Jennal) +* [George Zhao](https://github.com/zhaozg) +* kbuschelman +* [Victor Seva](https://github.com/linuxmaniac) +* [Urs Breu](https://github.com/ubreu) +* Jim Anderson +* [Douglas Jacobsen](https://github.com/dmjacobsen) +* [Mayama Takeshi](https://github.com/MayamaTakeshi) + + +## Installation + +**LuaRocks** + +LuaUnit v3.3 is available on [LuaRocks](https://luarocks.org/modules/bluebird75/luaunit). To install it, you need at least +LuaRocks version 2.4.4 (due to old versions of wget being incompatible with GitHub https downloading) + +**GitHub** + +The simplest way to install LuaUnit is to fetch the GitHub version: + + git clone git@github.com:bluebird75/luaunit.git + +Then copy the file luaunit.lua into your project or the Lua libs directory. + +The version in development on GitHub is always stable and can be used safely. + +On Linux, you can also install it into your Lua directories + + sudo python doit.py install + +If that fail, edit the function `install()` in the file `doit.py` to adjust +the Lua version and installation directory. It uses, by default, Linux paths that depend on the version. + + +### History + +#### Version 3.3 - 6. March 2018 +* General + * when comparing lists with assertEquals(), failure message provides an advanced comparison of the lists + * assertErrorMsgEquals() can check for error raised as tables + * tests may be finished early with fail(), failIf(), success() or successIf() + * improve printing of recursive tables + * improvements and fixes to JUnit and TAP output + * stricter assertTrue() and assertFalse(): they only succeed with boolean values + * add assertEvalToTrue() and assertEvalToFalse() with previous assertTrue()/assertFalse() behavior of coercing to boolean before asserting + ** all assertion functions accept an optional extra message, to be printed along the failure +* New command-line arguments: + * can now shuffle tests with --shuffle or -s + * possibility to repeat tests (for example to trigger a JIT), with --repeat NUM or -r NUM + * more flexible test selection with inclusion (--pattern / -p) or exclusion (--exclude / -x) or combination of both +* Scientific computing dedicated support (see documentation): + * provide the machine epsilon in lu.EPS + * new functions: assertNan(), assertInf(), assertPlusInf(), assertMinusInf(), assertPlusZero(), assertMinusZero() + * in assertAlmostEquals( a, b, margin ), margin no longer provides a default value of 1E-11, the machine epsilon is used instead +* Platform and continuous integration support: + * validate LuaUnit on MacOs platform (thank to Travis CI) + * validate LuaUnit with 32 bits numbers (floats) and 64 bits numbers (double) + * add test coverage measurements thank to coveralls.io . Status: 99.76% of the code is verified. + * use cache for AppVeyor and Travis builds + * support for luarocks doc command +* General doc improvements (detailed description of all output, more cross-linking between sections) + +#### Version 3.2 - 12. Jul 2016 +* distinguish between failures (failed assertion) and errors +* add command-line option to stop on first error or failure +* support for new versions: Lua 5.3 and LuaJIT (2.0, 2.1 beta) +* validation of all lua versions on Travis CI and AppVeyor +* added compatibility layer with forked luaunit v2.x +* added documentation about development process +* improved support for table containing keys of type table +* small bug fixes, several internal improvements + +#### Version 3.1 - 10 Mar. 2015 +* luaunit no longer pollutes global namespace, unless defining EXPORT_ASSERT_TO_GLOBALS to true +* fixes and validation of JUnit XML generation +* strip luaunit internal information from stacktrace +* general improvements of test results with duration and other details +* improve printing for tables, with an option to always print table id +* fix printing of recursive tables + +**Important note when upgrading to version 3.1** : assertions functions are +no longer exported directly to the global namespace. See documentation for upgrade +paths. + +#### Version 3.0 - 9. Oct 2014 + +Since some people have forked LuaUnit and release some 2.x version, I am +jumping the version number. + +- moved to Github +- full documentation available in text, html and pdf at read-the-docs.org +- new output format: JUnit +- much better table assertions +- new assertions for strings, with patterns and case insensitivity: assertStrContains, + assertNotStrContains, assertNotStrIContains, assertStrIContains, assertStrMatches +- new assertions for floats: assertAlmostEquals, assertNotAlmostEquals +- type assertions: assertIsString, assertIsNumber, ... +- error assertions: assertErrorMsgEquals, assertErrorMsgContains, assertErrorMsgMatches +- improved error messages for several assertions +- command-line options to select test, control output type and verbosity + +#### Version 2.0 +Unofficial fork from version 1.3 +- lua 5.2 module style, without global namespace pollution +- setUp() may be named Setup() or setup() +- tearDown() may be named Teardown() or teardown() +- wrapFunction() may be called WrapFunctions() or wrap_functions() +- run() may also be called Run() +- table deep comparision (also available in 1.4) +- control verbosity with setVerbosity() SetVerbosity() and set_verbosity() +- More assertions: + - is, is_, assert and assert_ (e.g. assert( LuaUnit.isString( getString() ) ) + - assertNot and assert_not_ + +#### Version 1.5 - 8. Nov 2012 +- compatibility with Lua 5.1 and 5.2 +- better object model internally +- a lot more of internal tests +- several internal bug fixes +- make it easy to customize the test output +- running test functions no longer requires a wrapper +- several level of verbosity + + +#### Version 1.4 - 26. Jul 2012 +- table deep comparison +- switch from X11 to more popular BSD license +- add TAP output format for integration into Jenkins +- official repository now on GitHub + + +#### Version 1.3 - 30. Oct 2007 +- port to lua 5.1 +- iterate over the test classes, methods and functions in the alphabetical order +- change the default order of expected, actual in assertEquals (adjustable with USE_EXPECTED_ACTUAL_IN_ASSERT_EQUALS). + + +#### Version 1.2 - 13. Jun 2005 +- first public release + + +#### Version 1.1 +- move global variables to internal variables +- assertion order is configurable between expected/actual or actual/expected +- new assertion to check that a function call returns an error +- display the calling stack when an error is spotted +- two verbosity level, like in python unittest + +![stats](https://stats.sylphide-consulting.com/piwik/piwik.php?idsite=37&rec=1) diff -Nru lua-unit-3.2/run_functional_tests.lua lua-unit-3.3/run_functional_tests.lua --- lua-unit-3.2/run_functional_tests.lua 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/run_functional_tests.lua 2018-04-20 12:34:12.000000000 +0000 @@ -1,703 +1,738 @@ -#!/usr/bin/env lua - -require('os') -local lu = require('luaunit') - - -local function report( ... ) - print('>>>>>>>', string.format(...)) -end - -local function error_fmt( ... ) - error(string.format(...), 2) -- (level 2 = report chunk calling error_fmt) -end - -local IS_UNIX = ( package.config:sub(1,1) == '/' ) -local LUA='"'..arg[-1]..'"' - - --- Escape a string so it can safely be used as a Lua pattern without triggering --- special semantics. This means prepending any "magic" character ^$()%.[]*+-? --- with a percent sign. Note: We DON'T expect embedded NUL chars, and thus --- won't escape those (%z) for Lua 5.1. -local LUA_MAGIC_CHARS = "[%^%$%(%)%%%.%[%]%*%+%-%?]" -local function escape_lua_pattern(s) - return s:gsub(LUA_MAGIC_CHARS, "%%%1") -- substitute with '%' + matched char -end - -local function string_sub(s, orig, repl) - -- replace occurrence of string orig by string repl - -- just like string.gsub, but with no pattern matching - return s:gsub( escape_lua_pattern(orig), repl ) -end - -function testStringSub() - lu.assertEquals( string_sub('aa a % b cc', 'a % b', 'a + b'), 'aa a + b cc' ) - lu.assertEquals( string_sub('aa: ?cc', ': ?', 'xx?'), 'aaxx?cc' ) -end - -local function osExec( ... ) - -- execute a command with os.execute and return true if exit code is 0 - -- false in any other conditions - - local cmd = string.format(...) - if not(IS_UNIX) and cmd:sub(1, 1) == '"' then - -- In case we're running on Windows, and if the command starts with a - -- quote: It's reasonable (or even necessary in some cases) to enclose - -- the entire command string in another pair of quotes. (This is needed - -- to preserve other quotes, due to how os.execute makes use of cmd.exe) - -- see e.g. http://lua-users.org/lists/lua-l/2014-06/msg00551.html - cmd = '"' .. cmd .. '"' - end - - -- print('osExec('..cmd..')') - local exitSuccess, exitReason, exitCode = os.execute( cmd ) - -- print('\n', exitSuccess, exitReason, exitCode) - - if _VERSION == 'Lua 5.1' then - -- Lua 5.1 returns only the exit code - exitReason = 'exit' - if IS_UNIX then - -- in C: exitCode = (exitSuccess >> 8) & 0xFF - -- poor approximation that works: - exitCode = (exitSuccess / 256) - else - -- Windows, life is simple - exitCode = exitSuccess - end - end - - -- Use heuristics to determine negative exit codes, - -- assuming that those are in the range -8 to -1: - if exitCode >= 248 then exitCode = exitCode - 256 end - - -- Lua 5.2+ has a weird way of dealing with exit code -1, at least on Windows - if exitReason == 'No error' then - exitReason = 'exit' - exitCode = -1 - end - - if exitReason ~= 'exit' or exitCode ~= 0 then - -- print('return false '..tostring(exitCode)) - return false, exitCode - end - - -- print('return true') - return true, exitCode -end - -local function osExpectedCodeExec( refExitCode, ... ) - local cmd = string.format(...) - local ret, exitCode = osExec( cmd ) - if refExitCode and (exitCode ~= refExitCode) then - error_fmt('Expected exit code %d, but got %d for: %s', refExitCode, exitCode, cmd) - end - return ret -end - -local HAS_XMLLINT -do - local xmllint_output_fname = 'test/has_xmllint.txt' - HAS_XMLLINT = osExec('xmllint --version 2> '..xmllint_output_fname) - if not HAS_XMLLINT then - report('WARNING: xmllint absent, can not validate xml validity') - end - os.remove(xmllint_output_fname) -end - -local function adjustFile( fileOut, fileIn, pattern, mayBeAbsent, verbose ) - --[[ Adjust the content of fileOut by copying lines matching pattern from fileIn - - fileIn lines are read and the first line matching pattern is analysed. The first pattern - capture is memorized. - - fileOut lines are then read, and the first line matching pattern is modified, by applying - the first capture of fileIn. fileOut is then rewritten. - ]] - local source = nil - local idxStart, idxEnd, capture - for line in io.lines(fileIn) do - idxStart, idxEnd, capture = line:find( pattern ) - if idxStart ~= nil then - if capture == nil then - error_fmt('Must specify a capture for pattern %s in function adjustFile()', pattern) - end - source = capture - break - end - end - - if source == nil then - if mayBeAbsent then - return -- no capture, just return - end - error_fmt('No line in file %s matching pattern "%s"', fileIn, pattern) - end - - if verbose then - print('Captured in source: '.. source ) - end - - local dest, linesOut = nil, {} - for line in io.lines(fileOut) do - idxStart, idxEnd, capture = line:find( pattern ) - if idxStart ~= nil then - dest = capture - if verbose then - print('Modifying line: '..line ) - end - line = string_sub(line, dest, source) - -- line = line:sub(1,idxStart-1)..source..line:sub(idxEnd+1) - -- string.gsub( line, dest, source ) - if verbose then - print('Result: '..line ) - end - end - table.insert( linesOut, line ) - end - - if dest == nil then - if mayBeAbsent then - return -- capture but nothing to adjust, just return - end - error_fmt('No line in file %s matching pattern "%s"', fileOut, pattern) - end - - local f = io.open( fileOut, 'w') - f:write(table.concat(linesOut, '\n'), '\n') - f:close() -end - -local function check_tap_output( fileToRun, options, output, refOutput, refExitCode ) - -- remove output - osExpectedCodeExec(refExitCode, '%s %s --output TAP %s > %s', - LUA, fileToRun, options, output) - - adjustFile( output, refOutput, '# Started on (.*)') - adjustFile( output, refOutput, '# Ran %d+ tests in (%d+.%d*).*') - -- For Lua 5.3: stack trace uses "method" instead of "function" - adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true, false ) - - if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refOutput, output) then - error('TAP Output mismatch for file : '..output) - end - -- report('TAP Output ok: '..output) - return 0 -end - - -local function check_text_output( fileToRun, options, output, refOutput, refExitCode ) - -- remove output - osExpectedCodeExec(refExitCode, '%s %s --output text %s > %s', - LUA, fileToRun, options, output) - - if options:find( '--verbose' ) then - adjustFile( output, refOutput, 'Started on (.*)') - end - adjustFile( output, refOutput, 'Ran .* tests in (%d.%d*) seconds' ) - -- For Lua 5.3: stack trace uses "method" instead of "function" - adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true, false ) - - if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refOutput, output) then - error('Text Output mismatch for file : '..output) - end - -- report('Text Output ok: '..output) - return 0 -end - -local function check_nil_output( fileToRun, options, output, refOutput, refExitCode ) - -- remove output - osExpectedCodeExec(refExitCode, '%s %s --output nil %s > %s', - LUA, fileToRun, options, output) - - if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refOutput, output) then - error('NIL Output mismatch for file : '..output) - end - -- report('NIL Output ok: '..output) - return 0 -end - -local function check_xml_output( fileToRun, options, output, xmlOutput, xmlLintOutput, refOutput, refXmlOutput, refExitCode ) - local retcode = 0 - - -- remove output - osExpectedCodeExec(refExitCode, '%s %s %s --output junit --name %s > %s', - LUA, fileToRun, options, xmlOutput, output) - - adjustFile( output, refOutput, '# XML output to (.*)') - adjustFile( output, refOutput, '# Started on (.*)') - adjustFile( output, refOutput, '# Ran %d+ tests in (%d+.%d*).*') - adjustFile( xmlOutput, refXmlOutput, '.*') - -- For Lua 5.3: stack trace uses "method" instead of "function" - adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true, false ) - adjustFile( xmlOutput, refXmlOutput, '.*%.lua:%d+: in (%S*) .*', true, false ) - - - if HAS_XMLLINT then - -- General xmllint validation - if osExec('xmllint --noout %s > %s', xmlOutput, xmlLintOutput) then - -- report('XMLLint validation ok: file %s', xmlLintOutput) - else - error_fmt('XMLLint reported errors : file %s', xmlLintOutput) - retcode = retcode + 1 - end - - -- Validation against apache junit schema - if osExec('xmllint --noout --schema junitxml/junit-apache-ant.xsd %s 2> %s', xmlOutput, xmlLintOutput) then - -- report('XMLLint validation ok: file %s', xmlLintOutput) - else - error_fmt('XMLLint reported errors against apache schema: file %s', xmlLintOutput) - retcode = retcode + 1 - end - - -- Validation against jenkins/hudson schema - if osExec('xmllint --noout --schema junitxml/junit-jenkins.xsd %s 2> %s', xmlOutput, xmlLintOutput) then - -- report('XMLLint validation ok: file %s', xmlLintOutput) - else - error_fmt('XMLLint reported errors against jenkins schema: file %s', xmlLintOutput) - retcode = retcode + 1 - end - end - - -- ignore change in line numbers for luaunit - if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refXmlOutput, xmlOutput) then - error('XML content mismatch for file : '..xmlOutput) - retcode = retcode + 1 - end - - if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refOutput, output) then - error('XML Output mismatch for file : '..output) - retcode = retcode + 1 - end - - --[[ - if retcode == 0 then - report('XML Output ok: '..output) - end - --]] - - return retcode -end - --- check tap output - -function testTapDefault() - lu.assertEquals( 0, - check_tap_output('example_with_luaunit.lua', '', - 'test/exampleTapDefault.txt', - 'test/ref/exampleTapDefault.txt', 12) ) - lu.assertEquals( 0, - check_tap_output('test/test_with_err_fail_pass.lua', '', - 'test/errFailPassTapDefault.txt', - 'test/ref/errFailPassTapDefault.txt', 10 ) ) - lu.assertEquals( 0, - check_tap_output('test/test_with_err_fail_pass.lua', '-p Succ', - 'test/errFailPassTapDefault-success.txt', - 'test/ref/errFailPassTapDefault-success.txt', 0 ) ) - lu.assertEquals( 0, - check_tap_output('test/test_with_err_fail_pass.lua', '-p Succ -p Fail', - 'test/errFailPassTapDefault-failures.txt', - 'test/ref/errFailPassTapDefault-failures.txt', 5 ) ) -end - -function testTapVerbose() - lu.assertEquals( 0, - check_tap_output('example_with_luaunit.lua', '--verbose', - 'test/exampleTapVerbose.txt', - 'test/ref/exampleTapVerbose.txt', 12 ) ) - lu.assertEquals( 0, - check_tap_output('test/test_with_err_fail_pass.lua', '--verbose', - 'test/errFailPassTapVerbose.txt', - 'test/ref/errFailPassTapVerbose.txt', 10 ) ) - lu.assertEquals( 0, - check_tap_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ', - 'test/errFailPassTapVerbose-success.txt', - 'test/ref/errFailPassTapVerbose-success.txt', 0 ) ) - lu.assertEquals( 0, - check_tap_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ -p Fail', - 'test/errFailPassTapVerbose-failures.txt', - 'test/ref/errFailPassTapVerbose-failures.txt', 5 ) ) -end - -function testTapQuiet() - lu.assertEquals( 0, - check_tap_output('example_with_luaunit.lua', '--quiet', 'test/exampleTapQuiet.txt', 'test/ref/exampleTapQuiet.txt', 12 ) ) - lu.assertEquals( 0, - check_tap_output('test/test_with_err_fail_pass.lua', '--quiet', - 'test/errFailPassTapQuiet.txt', - 'test/ref/errFailPassTapQuiet.txt', 10 ) ) - lu.assertEquals( 0, - check_tap_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ', - 'test/errFailPassTapQuiet-success.txt', - 'test/ref/errFailPassTapQuiet-success.txt', 0 ) ) - lu.assertEquals( 0, - check_tap_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ -p Fail', - 'test/errFailPassTapQuiet-failures.txt', - 'test/ref/errFailPassTapQuiet-failures.txt', 5 ) ) -end - --- check text output - -function testTextDefault() - lu.assertEquals( 0, - check_text_output('example_with_luaunit.lua', '', - 'test/exampleTextDefault.txt', - 'test/ref/exampleTextDefault.txt', 12 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '', - 'test/errFailPassTextDefault.txt', - 'test/ref/errFailPassTextDefault.txt', 10 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '-p Succ', - 'test/errFailPassTextDefault-success.txt', - 'test/ref/errFailPassTextDefault-success.txt', 0 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '-p Succ -p Fail', - 'test/errFailPassTextDefault-failures.txt', - 'test/ref/errFailPassTextDefault-failures.txt', 5 ) ) -end - -function testTextVerbose() - lu.assertEquals( 0, - check_text_output('example_with_luaunit.lua', '--verbose', 'test/exampleTextVerbose.txt', 'test/ref/exampleTextVerbose.txt', 12 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '--verbose', - 'test/errFailPassTextVerbose.txt', - 'test/ref/errFailPassTextVerbose.txt', 10 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ', - 'test/errFailPassTextVerbose-success.txt', - 'test/ref/errFailPassTextVerbose-success.txt', 0 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ -p Fail', - 'test/errFailPassTextVerbose-failures.txt', - 'test/ref/errFailPassTextVerbose-failures.txt', 5 ) ) -end - -function testTextQuiet() - lu.assertEquals( 0, - check_text_output('example_with_luaunit.lua', '--quiet', - 'test/exampleTextQuiet.txt', - 'test/ref/exampleTextQuiet.txt', 12 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '--quiet', - 'test/errFailPassTextQuiet.txt', - 'test/ref/errFailPassTextQuiet.txt', 10 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ', - 'test/errFailPassTextQuiet-success.txt', - 'test/ref/errFailPassTextQuiet-success.txt', 0 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ -p Fail', - 'test/errFailPassTextQuiet-failures.txt', - 'test/ref/errFailPassTextQuiet-failures.txt', 5 ) ) -end - --- check nil output - -function testNilDefault() - lu.assertEquals( 0, - check_nil_output('example_with_luaunit.lua', '', 'test/exampleNilDefault.txt', 'test/ref/exampleNilDefault.txt', 12 ) ) - lu.assertEquals( 0, - check_nil_output('test/test_with_err_fail_pass.lua', '', - 'test/errFailPassNilDefault.txt', - 'test/ref/errFailPassNilDefault.txt', 10 ) ) - lu.assertEquals( 0, - check_nil_output('test/test_with_err_fail_pass.lua', ' -p Succ', - 'test/errFailPassNilDefault-success.txt', - 'test/ref/errFailPassNilDefault-success.txt', 0 ) ) - lu.assertEquals( 0, - check_nil_output('test/test_with_err_fail_pass.lua', ' -p Succ -p Fail', - 'test/errFailPassNilDefault-failures.txt', - 'test/ref/errFailPassNilDefault-failures.txt', 5 ) ) -end - --- check xml output - -function testXmlDefault() - lu.assertEquals( 0, - check_xml_output('example_with_luaunit.lua', '', - 'test/exampleXmlDefault.txt', 'test/exampleXmlDefault.xml', 'test/exampleXmllintDefault.xml', - 'test/ref/exampleXmlDefault.txt', 'test/ref/exampleXmlDefault.xml', 12 ) ) - lu.assertEquals( 0, - check_xml_output('test/test_with_err_fail_pass.lua', '', - 'test/errFailPassXmlDefault.txt', 'test/errFailPassXmlDefault.xml', 'test/errFailPassXmllintDefault.xml', - 'test/ref/errFailPassXmlDefault.txt', 'test/ref/errFailPassXmlDefault.xml', 10 ) ) - lu.assertEquals( 0, - check_xml_output('test/test_with_err_fail_pass.lua', '-p Succ', - 'test/errFailPassXmlDefault-success.txt', 'test/errFailPassXmlDefault-success.xml', 'test/errFailPassXmllintDefault.xml', - 'test/ref/errFailPassXmlDefault-success.txt', 'test/ref/errFailPassXmlDefault-success.xml', 0 ) ) - lu.assertEquals( 0, - check_xml_output('test/test_with_err_fail_pass.lua', '-p Succ -p Fail', - 'test/errFailPassXmlDefault-failures.txt', 'test/errFailPassXmlDefault-failures.xml', 'test/errFailPassXmllintDefault.xml', - 'test/ref/errFailPassXmlDefault-failures.txt', 'test/ref/errFailPassXmlDefault-failures.xml', 5 ) ) -end - -function testXmlVerbose() - lu.assertEquals( 0, - check_xml_output('example_with_luaunit.lua', '--verbose', - 'test/exampleXmlVerbose.txt', 'test/exampleXmlVerbose.xml', 'test/exampleXmllintVerbose.xml', - 'test/ref/exampleXmlVerbose.txt', 'test/ref/exampleXmlVerbose.xml', 12 ) ) - lu.assertEquals( 0, - check_xml_output('test/test_with_err_fail_pass.lua', '--verbose ', - 'test/errFailPassXmlVerbose.txt', 'test/errFailPassXmlVerbose.xml', 'test/errFailPassXmllintVerbose.xml', - 'test/ref/errFailPassXmlVerbose.txt', 'test/ref/errFailPassXmlVerbose.xml', 10 ) ) - lu.assertEquals( 0, - check_xml_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ', - 'test/errFailPassXmlVerbose-success.txt', 'test/errFailPassXmlVerbose-success.xml', 'test/errFailPassXmllintVerbose.xml', - 'test/ref/errFailPassXmlVerbose-success.txt', 'test/ref/errFailPassXmlVerbose-success.xml', 0 ) ) - lu.assertEquals( 0, - check_xml_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ -p Fail', - 'test/errFailPassXmlVerbose-failures.txt', 'test/errFailPassXmlVerbose-failures.xml', 'test/errFailPassXmllintVerbose.xml', - 'test/ref/errFailPassXmlVerbose-failures.txt', 'test/ref/errFailPassXmlVerbose-failures.xml', 5 ) ) -end - -function testXmlQuiet() - lu.assertEquals( 0, - check_xml_output('example_with_luaunit.lua', '--quiet', 'test/exampleXmlQuiet.txt', 'test/exampleXmlQuiet.xml', - 'test/exampleXmllintQuiet.xml', 'test/ref/exampleXmlQuiet.txt', 'test/ref/exampleXmlQuiet.xml', 12 ) ) - lu.assertEquals( 0, - check_xml_output('test/test_with_err_fail_pass.lua', '--quiet ', - 'test/errFailPassXmlQuiet.txt', 'test/errFailPassXmlQuiet.xml', 'test/errFailPassXmllintQuiet.xml', - 'test/ref/errFailPassXmlQuiet.txt', 'test/ref/errFailPassXmlQuiet.xml', 10 ) ) - lu.assertEquals( 0, - check_xml_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ', - 'test/errFailPassXmlQuiet-success.txt', 'test/errFailPassXmlQuiet-success.xml', 'test/errFailPassXmllintQuiet.xml', - 'test/ref/errFailPassXmlQuiet-success.txt', 'test/ref/errFailPassXmlQuiet-success.xml', 0 ) ) - lu.assertEquals( 0, - check_xml_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ -p Fail', - 'test/errFailPassXmlQuiet-failures.txt', 'test/errFailPassXmlQuiet-failures.xml', 'test/errFailPassXmllintQuiet.xml', - 'test/ref/errFailPassXmlQuiet-failures.txt', 'test/ref/errFailPassXmlQuiet-failures.xml', 5 ) ) -end - -function testTestWithXmlDefault() - lu.assertEquals( 0, - check_xml_output('test/test_with_xml.lua', '', 'test/testWithXmlDefault.txt', 'test/testWithXmlDefault.xml', - 'test/testWithXmlLintDefault.txt', 'test/ref/testWithXmlDefault.txt', 'test/ref/testWithXmlDefault.xml', 2 ) ) -end - -function testTestWithXmlVerbose() - lu.assertEquals( 0, - check_xml_output('test/test_with_xml.lua', '--verbose', 'test/testWithXmlVerbose.txt', 'test/testWithXmlVerbose.xml', - 'test/testWithXmlLintVerbose.txt', 'test/ref/testWithXmlVerbose.txt', 'test/ref/testWithXmlVerbose.xml', 2 ) ) -end - -function testTestWithXmlQuiet() - lu.assertEquals( 0, - check_xml_output('test/test_with_xml.lua', '--quiet', 'test/testWithXmlQuiet.txt', 'test/testWithXmlQuiet.xml', - 'test/testWithXmlLintQuiet.txt', 'test/ref/testWithXmlQuiet.txt', 'test/ref/testWithXmlQuiet.xml', 2 ) ) -end - -function testLegacyLuaunitUsage() - -- run test/legacy_example_usage and check exit status (expecting 12 failures) - osExpectedCodeExec(12, '%s %s --output text > %s', LUA, - "test/legacy_example_with_luaunit.lua", "test/legacyExample.txt") -end - -function testLuaunitV2Usage() - osExpectedCodeExec(0, '%s %s --output text 1> %s 2>&1', LUA, - "test/compat_luaunit_v2x.lua", "test/compat_luaunit_v2x.txt") -end - -function testBasicLuaunitOptions() - osExpectedCodeExec(0, '%s example_with_luaunit.lua --help > test/null.txt', LUA) - osExpectedCodeExec(0, '%s example_with_luaunit.lua --version > test/null.txt', LUA) - -- test invalid syntax - osExpectedCodeExec(-1, '%s example_with_luaunit.lua --foobar > test/null.txt', LUA) -- invalid option - osExpectedCodeExec(-1, '%s example_with_luaunit.lua --output foobar > test/null.txt', LUA) -- invalid format - osExpectedCodeExec(-1, '%s example_with_luaunit.lua --output junit > test/null.txt', LUA) -- missing output name - os.remove('test/null.txt') -end - -function testStopOnError() - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ --error --failure', - 'test/errFailPassTextStopOnError-1.txt', - 'test/ref/errFailPassTextStopOnError-1.txt', 0 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p TestSome --error', - 'test/errFailPassTextStopOnError-2.txt', - 'test/ref/errFailPassTextStopOnError-2.txt', -2 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p TestAnoth --failure', - 'test/errFailPassTextStopOnError-3.txt', - 'test/ref/errFailPassTextStopOnError-3.txt', -2 ) ) - lu.assertEquals( 0, - check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p TestSome --failure', - 'test/errFailPassTextStopOnError-4.txt', - 'test/ref/errFailPassTextStopOnError-4.txt', -2 ) ) -end - -local filesToGenerateExampleXml = { - { 'example_with_luaunit.lua', '', '--output junit --name test/ref/exampleXmlDefault.xml', 'test/ref/exampleXmlDefault.txt' }, - { 'example_with_luaunit.lua', '--quiet', '--output junit --name test/ref/exampleXmlQuiet.xml', 'test/ref/exampleXmlQuiet.txt' }, - { 'example_with_luaunit.lua', '--verbose', '--output junit --name test/ref/exampleXmlVerbose.xml', 'test/ref/exampleXmlVerbose.txt' }, -} - -local filesToGenerateExampleTap = { - { 'example_with_luaunit.lua', '', '--output tap', 'test/ref/exampleTapDefault.txt' }, - { 'example_with_luaunit.lua', '--quiet', '--output tap', 'test/ref/exampleTapQuiet.txt' }, - { 'example_with_luaunit.lua', '--verbose', '--output tap', 'test/ref/exampleTapVerbose.txt' }, -} - -local filesToGenerateExampleText = { - { 'example_with_luaunit.lua', '', '--output text', 'test/ref/exampleTextDefault.txt' }, - { 'example_with_luaunit.lua', '--quiet', '--output text', 'test/ref/exampleTextQuiet.txt' }, - { 'example_with_luaunit.lua', '--verbose', '--output text', 'test/ref/exampleTextVerbose.txt' }, -} - -local filesToGenerateExampleNil = { - { 'example_with_luaunit.lua', '', '--output nil', 'test/ref/exampleNilDefault.txt' }, -} - -local filesToGenerateErrFailPassXml = { - { 'test/test_with_err_fail_pass.lua', '', - '--output junit --name test/ref/errFailPassXmlDefault.xml', - 'test/ref/errFailPassXmlDefault.txt' }, - { 'test/test_with_err_fail_pass.lua', '', - '-p Succ --output junit --name test/ref/errFailPassXmlDefault-success.xml', - 'test/ref/errFailPassXmlDefault-success.txt' }, - { 'test/test_with_err_fail_pass.lua', '', - '-p Succ -p Fail --output junit --name test/ref/errFailPassXmlDefault-failures.xml', - 'test/ref/errFailPassXmlDefault-failures.txt' }, - { 'test/test_with_err_fail_pass.lua', '', '--quiet --output junit --name test/ref/errFailPassXmlQuiet.xml', - 'test/ref/errFailPassXmlQuiet.txt' }, - { 'test/test_with_err_fail_pass.lua', '', - '-p Succ --quiet --output junit --name test/ref/errFailPassXmlQuiet-success.xml', - 'test/ref/errFailPassXmlQuiet-success.txt' }, - { 'test/test_with_err_fail_pass.lua', '', - '-p Succ -p Fail --quiet --output junit --name test/ref/errFailPassXmlQuiet-failures.xml', - 'test/ref/errFailPassXmlQuiet-failures.txt' }, - { 'test/test_with_err_fail_pass.lua', '', '--verbose --output junit --name test/ref/errFailPassXmlVerbose.xml', 'test/ref/errFailPassXmlVerbose.txt' }, - { 'test/test_with_err_fail_pass.lua', '', - '-p Succ --verbose --output junit --name test/ref/errFailPassXmlVerbose-success.xml', - 'test/ref/errFailPassXmlVerbose-success.txt' }, - { 'test/test_with_err_fail_pass.lua', '', - '-p Succ -p Fail --verbose --output junit --name test/ref/errFailPassXmlVerbose-failures.xml', - 'test/ref/errFailPassXmlVerbose-failures.txt' }, -} - -local filesToGenerateErrFailPassTap = { - { 'test/test_with_err_fail_pass.lua', '', '--output tap', 'test/ref/errFailPassTapDefault.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ', '--output tap', 'test/ref/errFailPassTapDefault-success.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail', '--output tap', 'test/ref/errFailPassTapDefault-failures.txt' }, - - { 'test/test_with_err_fail_pass.lua', '--quiet', '--output tap', 'test/ref/errFailPassTapQuiet.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ --quiet', - '--output tap', 'test/ref/errFailPassTapQuiet-success.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail --quiet', - '--output tap', 'test/ref/errFailPassTapQuiet-failures.txt' }, - - { 'test/test_with_err_fail_pass.lua', '--verbose', '--output tap', 'test/ref/errFailPassTapVerbose.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ --verbose', - '--output tap', 'test/ref/errFailPassTapVerbose-success.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail --verbose', - '--output tap', 'test/ref/errFailPassTapVerbose-failures.txt' }, -} - -local filesToGenerateErrFailPassText = { - { 'test/test_with_err_fail_pass.lua', '', '--output text', 'test/ref/errFailPassTextDefault.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ', '--output text', 'test/ref/errFailPassTextDefault-success.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail', '--output text', 'test/ref/errFailPassTextDefault-failures.txt' }, - { 'test/test_with_err_fail_pass.lua', '--quiet', '--output text', 'test/ref/errFailPassTextQuiet.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ --quiet', - '--output text', 'test/ref/errFailPassTextQuiet-success.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail --quiet', - '--output text', 'test/ref/errFailPassTextQuiet-failures.txt' }, - { 'test/test_with_err_fail_pass.lua', '--verbose', '--output text', 'test/ref/errFailPassTextVerbose.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ --verbose', - '--output text', 'test/ref/errFailPassTextVerbose-success.txt' }, - { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail --verbose', - '--output text', 'test/ref/errFailPassTextVerbose-failures.txt' }, -} - -local filesToGenerateTestXml = { - { 'test/test_with_xml.lua', '', '--output junit --name test/ref/testWithXmlDefault.xml', 'test/ref/testWithXmlDefault.txt' }, - { 'test/test_with_xml.lua', '--verbose', '--output junit --name test/ref/testWithXmlVerbose.xml', 'test/ref/testWithXmlVerbose.txt' }, - { 'test/test_with_xml.lua', '--quiet', '--output junit --name test/ref/testWithXmlQuiet.xml', 'test/ref/testWithXmlQuiet.txt' }, -} - -local filesToGenerateStopOnError = { - { 'test/test_with_err_fail_pass.lua', '', '--output text --quiet -p Succ --error --failure', - 'test/ref/errFailPassTextStopOnError-1.txt'}, - { 'test/test_with_err_fail_pass.lua', '', '--output text --quiet -p TestSome --error', - 'test/ref/errFailPassTextStopOnError-2.txt'}, - { 'test/test_with_err_fail_pass.lua', '', '--output text --quiet -p TestAnoth --failure', - 'test/ref/errFailPassTextStopOnError-3.txt'}, - { 'test/test_with_err_fail_pass.lua', '', '--output text --quiet -p TestSome --failure', - 'test/ref/errFailPassTextStopOnError-4.txt'}, -} - -local filesSetIndex = { - ErrFailPassText=filesToGenerateErrFailPassText, - ErrFailPassTap=filesToGenerateErrFailPassTap, - ErrFailPassXml=filesToGenerateErrFailPassXml, - ExampleNil=filesToGenerateExampleNil, - ExampleText=filesToGenerateExampleText, - ExampleTap=filesToGenerateExampleTap, - ExampleXml=filesToGenerateExampleXml, - TestXml=filesToGenerateTestXml, - StopOnError=filesToGenerateStopOnError, -} - -local function updateRefFiles( filesToGenerate ) - local ret - - for i,v in ipairs(filesToGenerate) do - report('Generating '..v[4]) - ret = osExec( '%s %s %s %s > %s', LUA, v[1], v[2], v[3], v[4] ) - --[[ - -- exitcode != 0 is not an error for us ... - if ret == false then - error('Error while generating '..prettystr(v) ) - os.exit(1) - end - ]] - -- neutralize all testcase time values in ref xml output - local refXmlName = string.match(v[3], "--name (test/ref/.*%.xml)$") - if refXmlName then - adjustFile( refXmlName, refXmlName, '.*>>>>>>', string.format(...)) +end + +local function error_fmt( ... ) + error(string.format(...), 2) -- (level 2 = report chunk calling error_fmt) +end + +local IS_UNIX = ( package.config:sub(1,1) == '/' ) +local LUA='"'..arg[-1]..'"' + + +-- Escape a string so it can safely be used as a Lua pattern without triggering +-- special semantics. This means prepending any "magic" character ^$()%.[]*+-? +-- with a percent sign. Note: We DON'T expect embedded NUL chars, and thus +-- won't escape those (%z) for Lua 5.1. +local LUA_MAGIC_CHARS = "[%^%$%(%)%%%.%[%]%*%+%-%?]" +local function escape_lua_pattern(s) + return s:gsub(LUA_MAGIC_CHARS, "%%%1") -- substitute with '%' + matched char +end + +local function string_gsub(s, orig, repl) + -- replace occurrence of string orig by string repl + -- just like string.gsub, but with no pattern matching + -- print( 'gsub_input '..s..' '..orig..' '..repl) + return s:gsub( escape_lua_pattern(orig), repl ) +end + +function testStringSub() + lu.assertEquals( string_gsub('aa a % b cc', 'a % b', 'a + b'), 'aa a + b cc' ) + lu.assertEquals( string_gsub('aa: ?cc', ': ?', 'xx?'), 'aaxx?cc' ) + lu.assertEquals( string_gsub('aa b: cc b: ee', 'b:', 'xx'), 'aa xx cc xx ee' ) +end + +local function osExec( ... ) + -- execute a command with os.execute and return true if exit code is 0 + -- false in any other conditions + + local cmd = string.format(...) + if not(IS_UNIX) and cmd:sub(1, 1) == '"' then + -- In case we're running on Windows, and if the command starts with a + -- quote: It's reasonable (or even necessary in some cases) to enclose + -- the entire command string in another pair of quotes. (This is needed + -- to preserve other quotes, due to how os.execute makes use of cmd.exe) + -- see e.g. http://lua-users.org/lists/lua-l/2014-06/msg00551.html + cmd = '"' .. cmd .. '"' + end + + -- print('osExec('..cmd..')') + local exitSuccess, exitReason, exitCode = os.execute( cmd ) + -- print('\n', exitSuccess, exitReason, exitCode) + + if _VERSION == 'Lua 5.1' then + -- Lua 5.1 returns only the exit code + exitReason = 'exit' + if IS_UNIX then + -- in C: exitCode = (exitSuccess >> 8) & 0xFF + -- poor approximation that works: + exitCode = (exitSuccess / 256) + else + -- Windows, life is simple + exitCode = exitSuccess + end + end + + -- Use heuristics to determine negative exit codes, + -- assuming that those are in the range -8 to -1: + if exitCode >= 248 then exitCode = exitCode - 256 end + + -- Lua 5.2+ has a weird way of dealing with exit code -1, at least on Windows + if exitReason == 'No error' then + exitReason = 'exit' + exitCode = -1 + end + + if exitReason ~= 'exit' or exitCode ~= 0 then + -- print('return false '..tostring(exitCode)) + return false, exitCode + end + + -- print('return true') + return true, exitCode +end + +local function osExpectedCodeExec( refExitCode, ... ) + local cmd = string.format(...) + local ret, exitCode = osExec( cmd ) + if refExitCode and (exitCode ~= refExitCode) then + error_fmt('Expected exit code %d, but got %d for: %s', refExitCode, exitCode, cmd) + end + return ret +end + +local HAS_XMLLINT +do + local xmllint_output_fname = 'test/has_xmllint.txt' + HAS_XMLLINT = osExec('xmllint --version 2> '..xmllint_output_fname) + if not HAS_XMLLINT then + report('WARNING: xmllint absent, can not validate xml validity') + end + os.remove(xmllint_output_fname) +end + +local function adjustFile( fileOut, fileIn, pattern, mayBeAbsent, verbose ) + --[[ Adjust the content of fileOut by copying lines matching pattern from fileIn + + fileIn lines are read and the first line matching pattern is analysed. The first pattern + capture is memorized. + + fileOut lines are then read, and the first line matching pattern2 is modified, by applying + the first capture of fileIn. fileOut is then rewritten. + + In most cases, pattern2 may be nil in which case, pattern is used when matching in fileout. + ]] + local source, idxStart, idxEnd, capture = nil + for line in io.lines(fileIn) do + idxStart, idxEnd, capture = line:find( pattern ) + if idxStart ~= nil then + if capture == nil then + error_fmt('Must specify a capture for pattern %s in function adjustFile()', pattern) + end + source = capture + break + end + end + + if source == nil then + if mayBeAbsent then + return -- no capture, just return + end + error_fmt('No line in file %s matching pattern "%s"', fileIn, pattern) + end + + if verbose then + print('Captured in source: '.. source ) + end + + local dest, linesOut = nil, {} + for line in io.lines(fileOut) do + idxStart, idxEnd, capture = line:find( pattern ) + while idxStart ~= nil do + if capture == nil then + print('missing pattern for outfile!') + end + dest = capture + if verbose then + print('Modifying line: '..line ) + end + line = string_gsub(line, dest, source) + -- line = line:sub(1,idxStart-1)..source..line:sub(idxEnd+1) + -- string.gsub( line, dest, source ) + if verbose then + print('Result : '..line ) + end + idxStart, idxEnd, capture = line:find( pattern, idxEnd ) + end + table.insert( linesOut, line ) + end + + if dest == nil then + if mayBeAbsent then + return -- capture but nothing to adjust, just return + end + error_fmt('No line in file %s matching pattern "%s"', fileOut, pattern) + end + + local f = io.open( fileOut, 'w') + f:write(table.concat(linesOut, '\n'), '\n') + f:close() +end + +local function check_tap_output( fileToRun, options, output, refOutput, refExitCode ) + -- remove output + osExpectedCodeExec(refExitCode, '%s %s --output TAP %s > %s', + LUA, fileToRun, options, output) + + adjustFile( output, refOutput, '# Started on (.*)') + adjustFile( output, refOutput, '# Ran %d+ tests in (%d+.%d*).*') + if _VERSION == 'Lua 5.3' then + -- For Lua 5.3: stack trace uses "method" instead of "function" + adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true ) + end + + if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refOutput, output) then + error('TAP Output mismatch for file : '..output) + end + -- report('TAP Output ok: '..output) + return 0 +end + + +local function check_text_output( fileToRun, options, output, refOutput, refExitCode ) + -- remove output + osExpectedCodeExec(refExitCode, '%s %s --output text %s > %s', + LUA, fileToRun, options, output) + + if options:find( '--verbose' ) then + adjustFile( output, refOutput, 'Started on (.*)') + end + adjustFile( output, refOutput, 'Ran .* tests in (%d.%d*) seconds' ) + adjustFile( output, refOutput, 'Ran .* tests in (%d.%d*) seconds' ) + adjustFile( output, refOutput, 'thread: (0?x?[%x]+)', true ) + adjustFile( output, refOutput, 'function: (0?x?[%x]+)', true ) + adjustFile( output, refOutput, '', true ) + if _VERSION == 'Lua 5.3' then + -- For Lua 5.3: stack trace uses "method" instead of "function" + adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true ) + end + + if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refOutput, output) then + error('Text Output mismatch for file : '..output) + end + -- report('Text Output ok: '..output) + return 0 +end + +local function check_nil_output( fileToRun, options, output, refOutput, refExitCode ) + -- remove output + osExpectedCodeExec(refExitCode, '%s %s --output nil %s > %s', + LUA, fileToRun, options, output) + + if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refOutput, output) then + error('NIL Output mismatch for file : '..output) + end + -- report('NIL Output ok: '..output) + return 0 +end + +local function check_xml_output( fileToRun, options, output, xmlOutput, xmlLintOutput, refOutput, refXmlOutput, refExitCode ) + local retcode = 0 + + -- remove output + osExpectedCodeExec(refExitCode, '%s %s %s --output junit --name %s > %s', + LUA, fileToRun, options, xmlOutput, output) + + adjustFile( output, refOutput, '# XML output to (.*)') + adjustFile( output, refOutput, '# Started on (.*)') + adjustFile( output, refOutput, '# Ran %d+ tests in (%d+.%d*).*') + adjustFile( xmlOutput, refXmlOutput, '.*') + + if _VERSION == 'Lua 5.3' then + -- For Lua 5.3: stack trace uses "method" instead of "function" + adjustFile( output, refOutput, '.*%.lua:%d+: in (%S*) .*', true ) + adjustFile( xmlOutput, refXmlOutput, '.*%.lua:%d+: in (%S*) .*', true ) + end + + if HAS_XMLLINT then + -- General xmllint validation + if osExec('xmllint --noout %s > %s', xmlOutput, xmlLintOutput) then + -- report('XMLLint validation ok: file %s', xmlLintOutput) + else + error_fmt('XMLLint reported errors : file %s', xmlLintOutput) + retcode = retcode + 1 + end + + -- Validation against apache junit schema + if osExec('xmllint --noout --schema junitxml/junit-apache-ant.xsd %s 2> %s', xmlOutput, xmlLintOutput) then + -- report('XMLLint validation ok: file %s', xmlLintOutput) + else + error_fmt('XMLLint reported errors against apache schema: file %s', xmlLintOutput) + retcode = retcode + 1 + end + + -- Validation against jenkins/hudson schema + if osExec('xmllint --noout --schema junitxml/junit-jenkins.xsd %s 2> %s', xmlOutput, xmlLintOutput) then + -- report('XMLLint validation ok: file %s', xmlLintOutput) + else + error_fmt('XMLLint reported errors against jenkins schema: file %s', xmlLintOutput) + retcode = retcode + 1 + end + end + + -- ignore change in line numbers for luaunit + if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refXmlOutput, xmlOutput) then + error('XML content mismatch for file : '..xmlOutput) + retcode = retcode + 1 + end + + if not osExec([[diff -NPw -u -I " *\.[/\\]luaunit.lua:[0123456789]\+:.*" %s %s]], refOutput, output) then + error('XML Output mismatch for file : '..output) + retcode = retcode + 1 + end + + --[[ + if retcode == 0 then + report('XML Output ok: '..output) + end + --]] + + return retcode +end + +-- check tap output + +function testTapDefault() + lu.assertEquals( 0, + check_tap_output('example_with_luaunit.lua', '', + 'test/exampleTapDefault.txt', + 'test/ref/exampleTapDefault.txt', 12) ) + lu.assertEquals( 0, + check_tap_output('test/test_with_err_fail_pass.lua', '', + 'test/errFailPassTapDefault.txt', + 'test/ref/errFailPassTapDefault.txt', 10 ) ) + lu.assertEquals( 0, + check_tap_output('test/test_with_err_fail_pass.lua', '-p Succ', + 'test/errFailPassTapDefault-success.txt', + 'test/ref/errFailPassTapDefault-success.txt', 0 ) ) + lu.assertEquals( 0, + check_tap_output('test/test_with_err_fail_pass.lua', '-p Succ -p Fail', + 'test/errFailPassTapDefault-failures.txt', + 'test/ref/errFailPassTapDefault-failures.txt', 5 ) ) +end + +function testTapVerbose() + lu.assertEquals( 0, + check_tap_output('example_with_luaunit.lua', '--verbose', + 'test/exampleTapVerbose.txt', + 'test/ref/exampleTapVerbose.txt', 12 ) ) + lu.assertEquals( 0, + check_tap_output('test/test_with_err_fail_pass.lua', '--verbose', + 'test/errFailPassTapVerbose.txt', + 'test/ref/errFailPassTapVerbose.txt', 10 ) ) + lu.assertEquals( 0, + check_tap_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ', + 'test/errFailPassTapVerbose-success.txt', + 'test/ref/errFailPassTapVerbose-success.txt', 0 ) ) + lu.assertEquals( 0, + check_tap_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ -p Fail', + 'test/errFailPassTapVerbose-failures.txt', + 'test/ref/errFailPassTapVerbose-failures.txt', 5 ) ) +end + +function testTapQuiet() + lu.assertEquals( 0, + check_tap_output('example_with_luaunit.lua', '--quiet', 'test/exampleTapQuiet.txt', 'test/ref/exampleTapQuiet.txt', 12 ) ) + lu.assertEquals( 0, + check_tap_output('test/test_with_err_fail_pass.lua', '--quiet', + 'test/errFailPassTapQuiet.txt', + 'test/ref/errFailPassTapQuiet.txt', 10 ) ) + lu.assertEquals( 0, + check_tap_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ', + 'test/errFailPassTapQuiet-success.txt', + 'test/ref/errFailPassTapQuiet-success.txt', 0 ) ) + lu.assertEquals( 0, + check_tap_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ -p Fail', + 'test/errFailPassTapQuiet-failures.txt', + 'test/ref/errFailPassTapQuiet-failures.txt', 5 ) ) +end + +-- check text output + +function testTextDefault() + lu.assertEquals( 0, + check_text_output('example_with_luaunit.lua', '', + 'test/exampleTextDefault.txt', + 'test/ref/exampleTextDefault.txt', 12 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '', + 'test/errFailPassTextDefault.txt', + 'test/ref/errFailPassTextDefault.txt', 10 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '-p Succ', + 'test/errFailPassTextDefault-success.txt', + 'test/ref/errFailPassTextDefault-success.txt', 0 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '-p Succ -p Fail', + 'test/errFailPassTextDefault-failures.txt', + 'test/ref/errFailPassTextDefault-failures.txt', 5 ) ) +end + +function testTextVerbose() + lu.assertEquals( 0, + check_text_output('example_with_luaunit.lua', '--verbose', 'test/exampleTextVerbose.txt', 'test/ref/exampleTextVerbose.txt', 12 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '--verbose', + 'test/errFailPassTextVerbose.txt', + 'test/ref/errFailPassTextVerbose.txt', 10 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ', + 'test/errFailPassTextVerbose-success.txt', + 'test/ref/errFailPassTextVerbose-success.txt', 0 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ -p Fail', + 'test/errFailPassTextVerbose-failures.txt', + 'test/ref/errFailPassTextVerbose-failures.txt', 5 ) ) +end + +function testTextQuiet() + lu.assertEquals( 0, + check_text_output('example_with_luaunit.lua', '--quiet', + 'test/exampleTextQuiet.txt', + 'test/ref/exampleTextQuiet.txt', 12 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '--quiet', + 'test/errFailPassTextQuiet.txt', + 'test/ref/errFailPassTextQuiet.txt', 10 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ', + 'test/errFailPassTextQuiet-success.txt', + 'test/ref/errFailPassTextQuiet-success.txt', 0 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ -p Fail', + 'test/errFailPassTextQuiet-failures.txt', + 'test/ref/errFailPassTextQuiet-failures.txt', 5 ) ) +end + +-- check nil output + +function testNilDefault() + lu.assertEquals( 0, + check_nil_output('example_with_luaunit.lua', '', 'test/exampleNilDefault.txt', 'test/ref/exampleNilDefault.txt', 12 ) ) + lu.assertEquals( 0, + check_nil_output('test/test_with_err_fail_pass.lua', '', + 'test/errFailPassNilDefault.txt', + 'test/ref/errFailPassNilDefault.txt', 10 ) ) + lu.assertEquals( 0, + check_nil_output('test/test_with_err_fail_pass.lua', ' -p Succ', + 'test/errFailPassNilDefault-success.txt', + 'test/ref/errFailPassNilDefault-success.txt', 0 ) ) + lu.assertEquals( 0, + check_nil_output('test/test_with_err_fail_pass.lua', ' -p Succ -p Fail', + 'test/errFailPassNilDefault-failures.txt', + 'test/ref/errFailPassNilDefault-failures.txt', 5 ) ) +end + +-- check xml output + +function testXmlDefault() + lu.assertEquals( 0, + check_xml_output('example_with_luaunit.lua', '', + 'test/exampleXmlDefault.txt', 'test/exampleXmlDefault.xml', 'test/exampleXmllintDefault.xml', + 'test/ref/exampleXmlDefault.txt', 'test/ref/exampleXmlDefault.xml', 12 ) ) + lu.assertEquals( 0, + check_xml_output('test/test_with_err_fail_pass.lua', '', + 'test/errFailPassXmlDefault.txt', 'test/errFailPassXmlDefault.xml', 'test/errFailPassXmllintDefault.xml', + 'test/ref/errFailPassXmlDefault.txt', 'test/ref/errFailPassXmlDefault.xml', 10 ) ) + lu.assertEquals( 0, + check_xml_output('test/test_with_err_fail_pass.lua', '-p Succ', + 'test/errFailPassXmlDefault-success.txt', 'test/errFailPassXmlDefault-success.xml', 'test/errFailPassXmllintDefault.xml', + 'test/ref/errFailPassXmlDefault-success.txt', 'test/ref/errFailPassXmlDefault-success.xml', 0 ) ) + lu.assertEquals( 0, + check_xml_output('test/test_with_err_fail_pass.lua', '-p Succ -p Fail', + 'test/errFailPassXmlDefault-failures.txt', 'test/errFailPassXmlDefault-failures.xml', 'test/errFailPassXmllintDefault.xml', + 'test/ref/errFailPassXmlDefault-failures.txt', 'test/ref/errFailPassXmlDefault-failures.xml', 5 ) ) +end + +function testXmlVerbose() + lu.assertEquals( 0, + check_xml_output('example_with_luaunit.lua', '--verbose', + 'test/exampleXmlVerbose.txt', 'test/exampleXmlVerbose.xml', 'test/exampleXmllintVerbose.xml', + 'test/ref/exampleXmlVerbose.txt', 'test/ref/exampleXmlVerbose.xml', 12 ) ) + lu.assertEquals( 0, + check_xml_output('test/test_with_err_fail_pass.lua', '--verbose ', + 'test/errFailPassXmlVerbose.txt', 'test/errFailPassXmlVerbose.xml', 'test/errFailPassXmllintVerbose.xml', + 'test/ref/errFailPassXmlVerbose.txt', 'test/ref/errFailPassXmlVerbose.xml', 10 ) ) + lu.assertEquals( 0, + check_xml_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ', + 'test/errFailPassXmlVerbose-success.txt', 'test/errFailPassXmlVerbose-success.xml', 'test/errFailPassXmllintVerbose.xml', + 'test/ref/errFailPassXmlVerbose-success.txt', 'test/ref/errFailPassXmlVerbose-success.xml', 0 ) ) + lu.assertEquals( 0, + check_xml_output('test/test_with_err_fail_pass.lua', '--verbose -p Succ -p Fail', + 'test/errFailPassXmlVerbose-failures.txt', 'test/errFailPassXmlVerbose-failures.xml', 'test/errFailPassXmllintVerbose.xml', + 'test/ref/errFailPassXmlVerbose-failures.txt', 'test/ref/errFailPassXmlVerbose-failures.xml', 5 ) ) +end + +function testXmlQuiet() + lu.assertEquals( 0, + check_xml_output('example_with_luaunit.lua', '--quiet', 'test/exampleXmlQuiet.txt', 'test/exampleXmlQuiet.xml', + 'test/exampleXmllintQuiet.xml', 'test/ref/exampleXmlQuiet.txt', 'test/ref/exampleXmlQuiet.xml', 12 ) ) + lu.assertEquals( 0, + check_xml_output('test/test_with_err_fail_pass.lua', '--quiet ', + 'test/errFailPassXmlQuiet.txt', 'test/errFailPassXmlQuiet.xml', 'test/errFailPassXmllintQuiet.xml', + 'test/ref/errFailPassXmlQuiet.txt', 'test/ref/errFailPassXmlQuiet.xml', 10 ) ) + lu.assertEquals( 0, + check_xml_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ', + 'test/errFailPassXmlQuiet-success.txt', 'test/errFailPassXmlQuiet-success.xml', 'test/errFailPassXmllintQuiet.xml', + 'test/ref/errFailPassXmlQuiet-success.txt', 'test/ref/errFailPassXmlQuiet-success.xml', 0 ) ) + lu.assertEquals( 0, + check_xml_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ -p Fail', + 'test/errFailPassXmlQuiet-failures.txt', 'test/errFailPassXmlQuiet-failures.xml', 'test/errFailPassXmllintQuiet.xml', + 'test/ref/errFailPassXmlQuiet-failures.txt', 'test/ref/errFailPassXmlQuiet-failures.xml', 5 ) ) +end + +function testTestWithXmlDefault() + lu.assertEquals( 0, + check_xml_output('test/test_with_xml.lua', '', 'test/testWithXmlDefault.txt', 'test/testWithXmlDefault.xml', + 'test/testWithXmlLintDefault.txt', 'test/ref/testWithXmlDefault.txt', 'test/ref/testWithXmlDefault.xml', 2 ) ) +end + +function testTestWithXmlVerbose() + lu.assertEquals( 0, + check_xml_output('test/test_with_xml.lua', '--verbose', 'test/testWithXmlVerbose.txt', 'test/testWithXmlVerbose.xml', + 'test/testWithXmlLintVerbose.txt', 'test/ref/testWithXmlVerbose.txt', 'test/ref/testWithXmlVerbose.xml', 2 ) ) +end + +function testTestWithXmlQuiet() + lu.assertEquals( 0, + check_xml_output('test/test_with_xml.lua', '--quiet', 'test/testWithXmlQuiet.txt', 'test/testWithXmlQuiet.xml', + 'test/testWithXmlLintQuiet.txt', 'test/ref/testWithXmlQuiet.txt', 'test/ref/testWithXmlQuiet.xml', 2 ) ) +end + +function testListComparison() + -- run test/some_lists_comparisons and check exit status + lu.assertEquals( 0, + check_text_output('test/some_lists_comparisons.lua', '--verbose', + 'test/some_lists_comparisons.txt', + 'test/ref/some_lists_comparisons.txt', 11 ) ) +end + +function testLegacyLuaunitUsage() + -- run test/legacy_example_usage and check exit status (expecting 12 failures) + osExpectedCodeExec(12, '%s %s --output text > %s', LUA, + "test/legacy_example_with_luaunit.lua", "test/legacyExample.txt") +end + +function testLuaunitV2Usage() + osExpectedCodeExec(0, '%s %s --output text 1> %s 2>&1', LUA, + "test/compat_luaunit_v2x.lua", "test/compat_luaunit_v2x.txt") +end + +function testBasicLuaunitOptions() + osExpectedCodeExec(0, '%s example_with_luaunit.lua --help > test/null.txt', LUA) + osExpectedCodeExec(0, '%s example_with_luaunit.lua --version > test/null.txt', LUA) + -- test invalid syntax + osExpectedCodeExec(-1, '%s example_with_luaunit.lua --foobar > test/null.txt', LUA) -- invalid option + osExpectedCodeExec(-1, '%s example_with_luaunit.lua --output foobar > test/null.txt', LUA) -- invalid format + osExpectedCodeExec(-1, '%s example_with_luaunit.lua --output junit > test/null.txt', LUA) -- missing output name + os.remove('test/null.txt') +end + +function testStopOnError() + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p Succ --error --failure', + 'test/errFailPassTextStopOnError-1.txt', + 'test/ref/errFailPassTextStopOnError-1.txt', 0 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p TestSome --error', + 'test/errFailPassTextStopOnError-2.txt', + 'test/ref/errFailPassTextStopOnError-2.txt', -2 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p TestAnoth --failure', + 'test/errFailPassTextStopOnError-3.txt', + 'test/ref/errFailPassTextStopOnError-3.txt', -2 ) ) + lu.assertEquals( 0, + check_text_output('test/test_with_err_fail_pass.lua', '--quiet -p TestSome --failure', + 'test/errFailPassTextStopOnError-4.txt', + 'test/ref/errFailPassTextStopOnError-4.txt', -2 ) ) +end + +local filesToGenerateExampleXml = { + { 'example_with_luaunit.lua', '', '--output junit --name test/ref/exampleXmlDefault.xml', 'test/ref/exampleXmlDefault.txt' }, + { 'example_with_luaunit.lua', '--quiet', '--output junit --name test/ref/exampleXmlQuiet.xml', 'test/ref/exampleXmlQuiet.txt' }, + { 'example_with_luaunit.lua', '--verbose', '--output junit --name test/ref/exampleXmlVerbose.xml', 'test/ref/exampleXmlVerbose.txt' }, +} + +local filesToGenerateExampleTap = { + { 'example_with_luaunit.lua', '', '--output tap', 'test/ref/exampleTapDefault.txt' }, + { 'example_with_luaunit.lua', '--quiet', '--output tap', 'test/ref/exampleTapQuiet.txt' }, + { 'example_with_luaunit.lua', '--verbose', '--output tap', 'test/ref/exampleTapVerbose.txt' }, +} + +local filesToGenerateExampleText = { + { 'example_with_luaunit.lua', '', '--output text', 'test/ref/exampleTextDefault.txt' }, + { 'example_with_luaunit.lua', '--quiet', '--output text', 'test/ref/exampleTextQuiet.txt' }, + { 'example_with_luaunit.lua', '--verbose', '--output text', 'test/ref/exampleTextVerbose.txt' }, +} + +local filesToGenerateExampleNil = { + { 'example_with_luaunit.lua', '', '--output nil', 'test/ref/exampleNilDefault.txt' }, +} + +local filesToGenerateErrFailPassXml = { + { 'test/test_with_err_fail_pass.lua', '', + '--output junit --name test/ref/errFailPassXmlDefault.xml', + 'test/ref/errFailPassXmlDefault.txt' }, + { 'test/test_with_err_fail_pass.lua', '', + '-p Succ --output junit --name test/ref/errFailPassXmlDefault-success.xml', + 'test/ref/errFailPassXmlDefault-success.txt' }, + { 'test/test_with_err_fail_pass.lua', '', + '-p Succ -p Fail --output junit --name test/ref/errFailPassXmlDefault-failures.xml', + 'test/ref/errFailPassXmlDefault-failures.txt' }, + { 'test/test_with_err_fail_pass.lua', '', '--quiet --output junit --name test/ref/errFailPassXmlQuiet.xml', + 'test/ref/errFailPassXmlQuiet.txt' }, + { 'test/test_with_err_fail_pass.lua', '', + '-p Succ --quiet --output junit --name test/ref/errFailPassXmlQuiet-success.xml', + 'test/ref/errFailPassXmlQuiet-success.txt' }, + { 'test/test_with_err_fail_pass.lua', '', + '-p Succ -p Fail --quiet --output junit --name test/ref/errFailPassXmlQuiet-failures.xml', + 'test/ref/errFailPassXmlQuiet-failures.txt' }, + { 'test/test_with_err_fail_pass.lua', '', '--verbose --output junit --name test/ref/errFailPassXmlVerbose.xml', 'test/ref/errFailPassXmlVerbose.txt' }, + { 'test/test_with_err_fail_pass.lua', '', + '-p Succ --verbose --output junit --name test/ref/errFailPassXmlVerbose-success.xml', + 'test/ref/errFailPassXmlVerbose-success.txt' }, + { 'test/test_with_err_fail_pass.lua', '', + '-p Succ -p Fail --verbose --output junit --name test/ref/errFailPassXmlVerbose-failures.xml', + 'test/ref/errFailPassXmlVerbose-failures.txt' }, +} + +local filesToGenerateErrFailPassTap = { + { 'test/test_with_err_fail_pass.lua', '', '--output tap', 'test/ref/errFailPassTapDefault.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ', '--output tap', 'test/ref/errFailPassTapDefault-success.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail', '--output tap', 'test/ref/errFailPassTapDefault-failures.txt' }, + + { 'test/test_with_err_fail_pass.lua', '--quiet', '--output tap', 'test/ref/errFailPassTapQuiet.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ --quiet', + '--output tap', 'test/ref/errFailPassTapQuiet-success.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail --quiet', + '--output tap', 'test/ref/errFailPassTapQuiet-failures.txt' }, + + { 'test/test_with_err_fail_pass.lua', '--verbose', '--output tap', 'test/ref/errFailPassTapVerbose.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ --verbose', + '--output tap', 'test/ref/errFailPassTapVerbose-success.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail --verbose', + '--output tap', 'test/ref/errFailPassTapVerbose-failures.txt' }, +} + +local filesToGenerateErrFailPassText = { + { 'test/test_with_err_fail_pass.lua', '', '--output text', 'test/ref/errFailPassTextDefault.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ', '--output text', 'test/ref/errFailPassTextDefault-success.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail', '--output text', 'test/ref/errFailPassTextDefault-failures.txt' }, + { 'test/test_with_err_fail_pass.lua', '--quiet', '--output text', 'test/ref/errFailPassTextQuiet.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ --quiet', + '--output text', 'test/ref/errFailPassTextQuiet-success.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail --quiet', + '--output text', 'test/ref/errFailPassTextQuiet-failures.txt' }, + { 'test/test_with_err_fail_pass.lua', '--verbose', '--output text', 'test/ref/errFailPassTextVerbose.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ --verbose', + '--output text', 'test/ref/errFailPassTextVerbose-success.txt' }, + { 'test/test_with_err_fail_pass.lua', '-p Succ -p Fail --verbose', + '--output text', 'test/ref/errFailPassTextVerbose-failures.txt' }, +} + +local filesToGenerateTestXml = { + { 'test/test_with_xml.lua', '', '--output junit --name test/ref/testWithXmlDefault.xml', 'test/ref/testWithXmlDefault.txt' }, + { 'test/test_with_xml.lua', '--verbose', '--output junit --name test/ref/testWithXmlVerbose.xml', 'test/ref/testWithXmlVerbose.txt' }, + { 'test/test_with_xml.lua', '--quiet', '--output junit --name test/ref/testWithXmlQuiet.xml', 'test/ref/testWithXmlQuiet.txt' }, +} + +local filesToGenerateStopOnError = { + { 'test/test_with_err_fail_pass.lua', '', '--output text --quiet -p Succ --error --failure', + 'test/ref/errFailPassTextStopOnError-1.txt'}, + { 'test/test_with_err_fail_pass.lua', '', '--output text --quiet -p TestSome --error', + 'test/ref/errFailPassTextStopOnError-2.txt'}, + { 'test/test_with_err_fail_pass.lua', '', '--output text --quiet -p TestAnoth --failure', + 'test/ref/errFailPassTextStopOnError-3.txt'}, + { 'test/test_with_err_fail_pass.lua', '', '--output text --quiet -p TestSome --failure', + 'test/ref/errFailPassTextStopOnError-4.txt'}, +} + +local filesToGenerateListsComp = { + { 'test/some_lists_comparisons.lua', '', '--output text --verbose', + 'test/ref/some_lists_comparisons.txt'}, +} + +local filesSetIndex = { + ErrFailPassText=filesToGenerateErrFailPassText, + ErrFailPassTap=filesToGenerateErrFailPassTap, + ErrFailPassXml=filesToGenerateErrFailPassXml, + ExampleNil=filesToGenerateExampleNil, + ExampleText=filesToGenerateExampleText, + ExampleTap=filesToGenerateExampleTap, + ExampleXml=filesToGenerateExampleXml, + TestXml=filesToGenerateTestXml, + StopOnError=filesToGenerateStopOnError, + ListsComp=filesToGenerateListsComp, +} + +local function updateRefFiles( filesToGenerate ) + local ret + + for _,v in ipairs(filesToGenerate) do + report('Generating '..v[4]) + ret = osExec( '%s %s %s %s > %s', LUA, v[1], v[2], v[3], v[4] ) + --[[ + -- exitcode != 0 is not an error for us ... + if ret == false then + error('Error while generating '..prettystr(v) ) + os.exit(1) + end + ]] + -- neutralize all testcase time values in ref xml output + local refXmlName = string.match(v[3], "--name (test/ref/.*%.xml)$") + if refXmlName then + adjustFile( refXmlName, refXmlName, '.* and LuaUnit.is_ helper functions. (e.g. assert( LuaUnit.isString( getString() ) ) -x Added assert and assert_ -x Added assertNot and assert_not_ -x Added _VERSION variable to hold the LuaUnit version -x Added LuaUnit:setVerbosity(lvl) method to the LuaUnit. Alias: LuaUnit:SetVerbosity() and LuaUnit:set_verbosity(). -x Added table deep compare -x check that wrapFunctions works -x Made "testable" classes able to start with 'test' or 'Test' for their name. -x Made "testable" methods able to start with 'test' or 'Test' for their name. -x Made testClass:setUp() methods able to be named with 'setUp' or 'Setup' or 'setup'. -x Made testClass:tearDown() methods able to be named with 'tearDown' or 'TearDown' or 'teardown'. -]] - - -TestLuaUnitV2Compat = {} - -function TestLuaUnitV2Compat:testRunAliases() - -- some old function - assertFunction( lu.run ) - assertEquals( lu.Run, lu.run ) -end - -function TestLuaUnitV2Compat:testWrapFunctionsAliases() - assertFunction( lu.wrapFunctions ) - assertEquals( lu.wrapFunctions, lu.WrapFunctions ) - assertEquals( lu.wrapFunctions, lu.wrap_functions ) -end - -local function typeAsserter( goodType, badType, goodAsserter, badAsserter ) - goodAsserter( goodType ) - if badAsserter ~= nil then - badAsserter( badType ) - end -end - -function TestLuaUnitV2Compat:testAssertType() - local f = function (v) return v+1 end - local t = coroutine.create( function(v) local y=v+1 end ) - local typesToVerify = { - -- list of: { goodType, badType, goodAsserter, badAsserter } - { true, "toto", assertBoolean, assertNotBoolean }, - { true, "toto", assert_boolean, assert_not_boolean }, - { 1 , "toto", assertNumber, assertNotNumber }, - { 1 , "toto", assert_number, assert_not_number }, - { "q" , 1 , assertString, assertNotString }, - { "q" , 1 , assert_string, assert_not_string }, - { nil , 1 , assertNil, assertNotNil }, - { nil , 1 , assert_nil, assert_not_nil }, - { {1,2}, "toto", assertTable, assertNotTable }, - { {1,2}, "toto", assert_table, assert_not_table }, - { f , "toto", assertFunction, assertNotFunction }, - { f , "toto", assert_function,assert_not_function }, - { t , "toto", assertThread, assertNotThread }, - { t , "toto", assert_thread, assert_not_thread }, - - } - - for _,v in ipairs( typesToVerify ) do - local goodType, badType, goodAsserter, badAsserter = v[1], v[2], v[3], v[4] - typeAsserter( goodType, badType, goodAsserter, badAsserter ) - end - - assertNotUserdata( "toto" ) - - - local typesToVerify2 = { - { true, "toto", lu.isBoolean }, - { true, "toto", lu.is_boolean }, - { 1, "toto", lu.isNumber }, - { 1, "toto", lu.is_number }, - { "t", 1, lu.isString }, - { "t", 1, lu.is_string }, - { nil, "toto", lu.isNil }, - { nil, "toto", lu.is_nil }, - { {1,2},"toto", lu.isTable }, - { {1,2},"toto", lu.is_table }, - { f, "toto", lu.isFunction }, - { f, "toto", lu.is_function }, - { t, "toto", lu.isThread }, - { t, "toto", lu.is_thread }, - } - - for _,v in ipairs( typesToVerify2 ) do - local goodType, badType, goodTypeVerifier = v[1], v[2], v[3] - if (v[3] == nil) then - print('Missing function at index '.._) - assertNotNil( v[3] ) - end - assertTrue ( goodTypeVerifier( goodType ) ) - assertFalse( goodTypeVerifier( badType ) ) - end - -end - -function TestLuaUnitV2Compat:testHasVersionKey() - assertNotNil( lu.VERSION ) - assertString( lu.VERSION ) - assertNotNil( lu._VERSION ) - assertTrue( lu.is_string( lu._VERSION ) ) -end - -function TestLuaUnitV2Compat:testTableEquality() - local t1 = {1,2} - local t2 = t1 - local t3 = {1,2} - local t4 = {1,2,3} - - assertEquals( t1, t1 ) - assertEquals( t1, t2 ) - -- new in LuaUnit v2.0 , deep table compare - assertEquals( t1, t3 ) - assertError( assertEquals, t1, t4 ) -end - --- Setup -local called = {} - -function test_w1() called.w1 = true end -function test_w2() called.w2 = true end -function test_w3() called.w3 = true end - -TestSomeFuncs = lu.wrapFunctions( 'test_w1', 'test_w2', 'test_w3' ) - -TestWithCap = {} -function TestWithCap:setup() called.setup = true end -function TestWithCap:Test1() called.t1 = true end -function TestWithCap:test2() called.t2 = true end -function TestWithCap:teardown() called.teardown = true end - -testWithoutCap = {} -function testWithoutCap:Setup() called.Setup = true end -function testWithoutCap:Test3() called.t3 = true end -function testWithoutCap:test4() called.t4 = true end -function testWithoutCap:tearDown() called.tearDown = true end - -TestWithUnderscore = {} -function TestWithUnderscore:setUp() called.setUp = true end -function TestWithUnderscore:Test1() called.t1 = true end -function TestWithUnderscore:test2() called.t2 = true end -function TestWithUnderscore:TearDown() called.TearDown = true end - --- Run -lu:setVerbosity( 1 ) -lu:set_verbosity( 1 ) -lu:SetVerbosity( 1 ) - -local results = lu.run() - --- Verif -assert( called.w1 == true ) -assert( called.w2 == true ) -assert( called.w3 == true ) -assert( called.t1 == true ) -assert( called.t2 == true ) -assert( called.t3 == true ) -assert( called.t4 == true ) -assert( called.setup == true ) -assert( called.setUp == true ) -assert( called.Setup == true ) -assert( called.teardown == true ) -assert( called.tearDown == true ) -assert( called.TearDown == true ) - -os.exit( results ) +EXPORT_ASSERT_TO_GLOBALS = true +local lu = require('luaunit') + +--[[ +Use Luaunit in the v2.1 fashion and check that it still works. +Exercise every luaunit v2.1 function and have it executed successfully. + +Coverage: +x Made LuaUnit:run() method able to be called with 'run' or 'Run'. +x Made LuaUnit.wrapFunctions() function able to be called with 'wrapFunctions' or 'WrapFunctions' or 'wrap_functions'. +x Moved wrapFunctions to the LuaUnit module table (e.g. local LuaUnit = require( "luaunit" ); LuaUnit.wrapFunctions( ... ) ) +x Added LuaUnit.is and LuaUnit.is_ helper functions. (e.g. assert( LuaUnit.isString( getString() ) ) +x Added assert and assert_ +x Added assertNot and assert_not_ +x Added _VERSION variable to hold the LuaUnit version +x Added LuaUnit:setVerbosity(lvl) method to the LuaUnit. Alias: LuaUnit:SetVerbosity() and LuaUnit:set_verbosity(). +x Added table deep compare +x check that wrapFunctions works +x Made "testable" classes able to start with 'test' or 'Test' for their name. +x Made "testable" methods able to start with 'test' or 'Test' for their name. +x Made testClass:setUp() methods able to be named with 'setUp' or 'Setup' or 'setup'. +x Made testClass:tearDown() methods able to be named with 'tearDown' or 'TearDown' or 'teardown'. +]] + + +TestLuaUnitV2Compat = {} + +function TestLuaUnitV2Compat:testRunAliases() + -- some old function + assertFunction( lu.run ) + assertEquals( lu.Run, lu.run ) +end + +function TestLuaUnitV2Compat:testWrapFunctionsAliases() + assertFunction( lu.wrapFunctions ) + assertEquals( lu.wrapFunctions, lu.WrapFunctions ) + assertEquals( lu.wrapFunctions, lu.wrap_functions ) +end + +local function typeAsserter( goodType, badType, goodAsserter, badAsserter ) + goodAsserter( goodType ) + if badAsserter ~= nil then + badAsserter( badType ) + end +end + +function TestLuaUnitV2Compat:testAssertType() + local f = function (v) return v+1 end + local t = coroutine.create( function(v) local y=v+1 end ) + local typesToVerify = { + -- list of: { goodType, badType, goodAsserter, badAsserter } + { true, "toto", assertBoolean, assertNotBoolean }, + { true, "toto", assert_boolean, assert_not_boolean }, + { 1 , "toto", assertNumber, assertNotNumber }, + { 1 , "toto", assert_number, assert_not_number }, + { "q" , 1 , assertString, assertNotString }, + { "q" , 1 , assert_string, assert_not_string }, + { nil , 1 , assertNil, assertNotNil }, + { nil , 1 , assert_nil, assert_not_nil }, + { {1,2}, "toto", assertTable, assertNotTable }, + { {1,2}, "toto", assert_table, assert_not_table }, + { f , "toto", assertFunction, assertNotFunction }, + { f , "toto", assert_function,assert_not_function }, + { t , "toto", assertThread, assertNotThread }, + { t , "toto", assert_thread, assert_not_thread }, + + } + + for _,v in ipairs( typesToVerify ) do + local goodType, badType, goodAsserter, badAsserter = v[1], v[2], v[3], v[4] + typeAsserter( goodType, badType, goodAsserter, badAsserter ) + end + + assertNotUserdata( "toto" ) + + + local typesToVerify2 = { + { true, "toto", lu.isBoolean }, + { true, "toto", lu.is_boolean }, + { 1, "toto", lu.isNumber }, + { 1, "toto", lu.is_number }, + { "t", 1, lu.isString }, + { "t", 1, lu.is_string }, + { nil, "toto", lu.isNil }, + { nil, "toto", lu.is_nil }, + { {1,2},"toto", lu.isTable }, + { {1,2},"toto", lu.is_table }, + { f, "toto", lu.isFunction }, + { f, "toto", lu.is_function }, + { t, "toto", lu.isThread }, + { t, "toto", lu.is_thread }, + } + + for _,v in ipairs( typesToVerify2 ) do + local goodType, badType, goodTypeVerifier = v[1], v[2], v[3] + if (v[3] == nil) then + print('Missing function at index '.._) + assertNotNil( v[3] ) + end + assertTrue ( goodTypeVerifier( goodType ) ) + assertFalse( goodTypeVerifier( badType ) ) + end + +end + +function TestLuaUnitV2Compat:testHasVersionKey() + assertNotNil( lu.VERSION ) + assertString( lu.VERSION ) + assertNotNil( lu._VERSION ) + assertTrue( lu.is_string( lu._VERSION ) ) +end + +function TestLuaUnitV2Compat:testTableEquality() + local t1 = {1,2} + local t2 = t1 + local t3 = {1,2} + local t4 = {1,2,3} + + assertEquals( t1, t1 ) + assertEquals( t1, t2 ) + -- new in LuaUnit v2.0 , deep table compare + assertEquals( t1, t3 ) + assertError( assertEquals, t1, t4 ) +end + +-- Setup +local called = {} + +function test_w1() called.w1 = true end +function test_w2() called.w2 = true end +function test_w3() called.w3 = true end + +TestSomeFuncs = lu.wrapFunctions( 'test_w1', 'test_w2', 'test_w3' ) + +TestWithCap = {} +function TestWithCap:setup() called.setup = true end +function TestWithCap:Test1() called.t1 = true end +function TestWithCap:test2() called.t2 = true end +function TestWithCap:teardown() called.teardown = true end + +testWithoutCap = {} +function testWithoutCap:Setup() called.Setup = true end +function testWithoutCap:Test3() called.t3 = true end +function testWithoutCap:test4() called.t4 = true end +function testWithoutCap:tearDown() called.tearDown = true end + +TestWithUnderscore = {} +function TestWithUnderscore:setUp() called.setUp = true end +function TestWithUnderscore:Test1() called.t1 = true end +function TestWithUnderscore:test2() called.t2 = true end +function TestWithUnderscore:TearDown() called.TearDown = true end + +-- Run +lu:setVerbosity( 1 ) +lu:set_verbosity( 1 ) +lu:SetVerbosity( 1 ) + +local results = lu.run() + +-- Verif +assert( called.w1 == true ) +assert( called.w2 == true ) +assert( called.w3 == true ) +assert( called.t1 == true ) +assert( called.t2 == true ) +assert( called.t3 == true ) +assert( called.t4 == true ) +assert( called.setup == true ) +assert( called.setUp == true ) +assert( called.Setup == true ) +assert( called.teardown == true ) +assert( called.tearDown == true ) +assert( called.TearDown == true ) + +os.exit( results ) diff -Nru lua-unit-3.2/test/compat_luaunit_v2x.txt lua-unit-3.3/test/compat_luaunit_v2x.txt --- lua-unit-3.2/test/compat_luaunit_v2x.txt 2016-10-11 09:40:07.000000000 +0000 +++ lua-unit-3.3/test/compat_luaunit_v2x.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,6 +0,0 @@ -.............. -Ran 14 tests in 0.000 seconds, 14 successes, 0 failures -OK -Use of WrapFunctions() is no longer needed. -Just prefix your test function names with "test" or "Test" and they -will be picked up and run by LuaUnit. diff -Nru lua-unit-3.2/test/errFailPassTapDefault-failures.txt lua-unit-3.3/test/errFailPassTapDefault-failures.txt --- lua-unit-3.2/test/errFailPassTapDefault-failures.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTapDefault-failures.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -1..10 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test3_Fail1 - test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -not ok 4 TestAnotherThing.test3_Fail2 - test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -ok 5 TestSomething.test1_Success1 -ok 6 TestSomething.test1_Success2 -not ok 7 TestSomething.test2_Fail1 - test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -not ok 8 TestSomething.test2_Fail2 - test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -not ok 9 testFuncFail1 - test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -ok 10 testFuncSuccess1 -# Ran 10 tests in 0.000 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/errFailPassTapDefault-success.txt lua-unit-3.3/test/errFailPassTapDefault-success.txt --- lua-unit-3.2/test/errFailPassTapDefault-success.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTapDefault-success.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -1..5 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -# Starting class: TestSomething -ok 3 TestSomething.test1_Success1 -ok 4 TestSomething.test1_Success2 -ok 5 testFuncSuccess1 -# Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/errFailPassTapDefault.txt lua-unit-3.3/test/errFailPassTapDefault.txt --- lua-unit-3.2/test/errFailPassTapDefault.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTapDefault.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -1..15 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test2_Err1 - test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -not ok 4 TestAnotherThing.test2_Err2 - test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -not ok 5 TestAnotherThing.test3_Fail1 - test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -not ok 6 TestAnotherThing.test3_Fail2 - test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -ok 7 TestSomething.test1_Success1 -ok 8 TestSomething.test1_Success2 -not ok 9 TestSomething.test2_Fail1 - test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -not ok 10 TestSomething.test2_Fail2 - test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -not ok 11 TestSomething.test3_Err1 - test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -not ok 12 TestSomething.test3_Err2 - test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -not ok 13 testFuncErr1 - test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -not ok 14 testFuncFail1 - test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -ok 15 testFuncSuccess1 -# Ran 15 tests in 0.003 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/errFailPassTapQuiet-failures.txt lua-unit-3.3/test/errFailPassTapQuiet-failures.txt --- lua-unit-3.2/test/errFailPassTapQuiet-failures.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTapQuiet-failures.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,15 +0,0 @@ -1..10 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test3_Fail1 -not ok 4 TestAnotherThing.test3_Fail2 -# Starting class: TestSomething -ok 5 TestSomething.test1_Success1 -ok 6 TestSomething.test1_Success2 -not ok 7 TestSomething.test2_Fail1 -not ok 8 TestSomething.test2_Fail2 -not ok 9 testFuncFail1 -ok 10 testFuncSuccess1 -# Ran 10 tests in 0.002 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/errFailPassTapQuiet-success.txt lua-unit-3.3/test/errFailPassTapQuiet-success.txt --- lua-unit-3.2/test/errFailPassTapQuiet-success.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTapQuiet-success.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -1..5 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -# Starting class: TestSomething -ok 3 TestSomething.test1_Success1 -ok 4 TestSomething.test1_Success2 -ok 5 testFuncSuccess1 -# Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/errFailPassTapQuiet.txt lua-unit-3.3/test/errFailPassTapQuiet.txt --- lua-unit-3.2/test/errFailPassTapQuiet.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTapQuiet.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -1..15 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test2_Err1 -not ok 4 TestAnotherThing.test2_Err2 -not ok 5 TestAnotherThing.test3_Fail1 -not ok 6 TestAnotherThing.test3_Fail2 -# Starting class: TestSomething -ok 7 TestSomething.test1_Success1 -ok 8 TestSomething.test1_Success2 -not ok 9 TestSomething.test2_Fail1 -not ok 10 TestSomething.test2_Fail2 -not ok 11 TestSomething.test3_Err1 -not ok 12 TestSomething.test3_Err2 -not ok 13 testFuncErr1 -not ok 14 testFuncFail1 -ok 15 testFuncSuccess1 -# Ran 15 tests in 0.002 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/errFailPassTapVerbose-failures.txt lua-unit-3.3/test/errFailPassTapVerbose-failures.txt --- lua-unit-3.2/test/errFailPassTapVerbose-failures.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTapVerbose-failures.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -1..10 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test3_Fail1 - test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 - stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' -not ok 4 TestAnotherThing.test3_Fail2 - test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' -# Starting class: TestSomething -ok 5 TestSomething.test1_Success1 -ok 6 TestSomething.test1_Success2 -not ok 7 TestSomething.test2_Fail1 - test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 - stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' -not ok 8 TestSomething.test2_Fail2 - test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' -not ok 9 testFuncFail1 - test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' -ok 10 testFuncSuccess1 -# Ran 10 tests in 0.000 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/errFailPassTapVerbose-success.txt lua-unit-3.3/test/errFailPassTapVerbose-success.txt --- lua-unit-3.2/test/errFailPassTapVerbose-success.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTapVerbose-success.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -1..5 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -# Starting class: TestSomething -ok 3 TestSomething.test1_Success1 -ok 4 TestSomething.test1_Success2 -ok 5 testFuncSuccess1 -# Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/errFailPassTapVerbose.txt lua-unit-3.3/test/errFailPassTapVerbose.txt --- lua-unit-3.2/test/errFailPassTapVerbose.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTapVerbose.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,50 +0,0 @@ -1..15 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test2_Err1 - test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value - stack traceback: - [C]: in function 'xpcall' -not ok 4 TestAnotherThing.test2_Err2 - test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value - stack traceback: - [C]: in function 'xpcall' -not ok 5 TestAnotherThing.test3_Fail1 - test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 - stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' -not ok 6 TestAnotherThing.test3_Fail2 - test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' -# Starting class: TestSomething -ok 7 TestSomething.test1_Success1 -ok 8 TestSomething.test1_Success2 -not ok 9 TestSomething.test2_Fail1 - test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 - stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' -not ok 10 TestSomething.test2_Fail2 - test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' -not ok 11 TestSomething.test3_Err1 - test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value - stack traceback: - [C]: in function 'xpcall' -not ok 12 TestSomething.test3_Err2 - test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value - stack traceback: - [C]: in function 'xpcall' -not ok 13 testFuncErr1 - test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value - stack traceback: - [C]: in function 'xpcall' -not ok 14 testFuncFail1 - test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' -ok 15 testFuncSuccess1 -# Ran 15 tests in 0.000 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/errFailPassTextDefault-failures.txt lua-unit-3.3/test/errFailPassTextDefault-failures.txt --- lua-unit-3.2/test/errFailPassTextDefault-failures.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextDefault-failures.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,29 +0,0 @@ -..FF..FFF. -Failed tests: -------------- -1) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -2) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -3) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -4) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -5) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 10 tests in 0.001 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/errFailPassTextDefault-success.txt lua-unit-3.3/test/errFailPassTextDefault-success.txt --- lua-unit-3.2/test/errFailPassTextDefault-success.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextDefault-success.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -..... -Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected -OK diff -Nru lua-unit-3.2/test/errFailPassTextDefault.txt lua-unit-3.3/test/errFailPassTextDefault.txt --- lua-unit-3.2/test/errFailPassTextDefault.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextDefault.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -..EEFF..FFEEEF. -Failed tests: -------------- -1) TestAnotherThing.test2_Err1 -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -2) TestAnotherThing.test2_Err2 -test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -3) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -4) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -5) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -6) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -7) TestSomething.test3_Err1 -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -8) TestSomething.test3_Err2 -test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -9) testFuncErr1 -test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -10) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 15 tests in 0.002 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/errFailPassTextQuiet-failures.txt lua-unit-3.3/test/errFailPassTextQuiet-failures.txt --- lua-unit-3.2/test/errFailPassTextQuiet-failures.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextQuiet-failures.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,29 +0,0 @@ -..FF..FFF. -Failed tests: -------------- -1) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -2) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -3) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -4) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -5) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 10 tests in 0.001 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/errFailPassTextQuiet-success.txt lua-unit-3.3/test/errFailPassTextQuiet-success.txt --- lua-unit-3.2/test/errFailPassTextQuiet-success.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextQuiet-success.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -..... -Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected -OK diff -Nru lua-unit-3.2/test/errFailPassTextQuiet.txt lua-unit-3.3/test/errFailPassTextQuiet.txt --- lua-unit-3.2/test/errFailPassTextQuiet.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextQuiet.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -..EEFF..FFEEEF. -Failed tests: -------------- -1) TestAnotherThing.test2_Err1 -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -2) TestAnotherThing.test2_Err2 -test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -3) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -4) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -5) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -6) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -7) TestSomething.test3_Err1 -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -8) TestSomething.test3_Err2 -test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -9) testFuncErr1 -test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -10) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 15 tests in 0.002 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/errFailPassTextStopOnError-1.txt lua-unit-3.3/test/errFailPassTextStopOnError-1.txt --- lua-unit-3.2/test/errFailPassTextStopOnError-1.txt 2016-10-11 09:40:07.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextStopOnError-1.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -..... -Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected -OK diff -Nru lua-unit-3.2/test/errFailPassTextStopOnError-2.txt lua-unit-3.3/test/errFailPassTextStopOnError-2.txt --- lua-unit-3.2/test/errFailPassTextStopOnError-2.txt 2016-10-11 09:40:07.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextStopOnError-2.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -..FFE -ERROR during LuaUnit test execution: -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value - -Failed tests: -------------- -1) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -2) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -3) TestSomething.test3_Err1 -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -Ran 5 tests in 0.000 seconds, 2 successes, 2 failures, 1 error, 9 non-selected -LuaUnit ABORTED (as requested by --error or --failure option) diff -Nru lua-unit-3.2/test/errFailPassTextStopOnError-3.txt lua-unit-3.3/test/errFailPassTextStopOnError-3.txt --- lua-unit-3.2/test/errFailPassTextStopOnError-3.txt 2016-10-11 09:40:07.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextStopOnError-3.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,13 +0,0 @@ -..E -ERROR during LuaUnit test execution: -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value - -Failed tests: -------------- -1) TestAnotherThing.test2_Err1 -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -Ran 3 tests in 0.000 seconds, 2 successes, 1 error, 9 non-selected -LuaUnit ABORTED (as requested by --error or --failure option) diff -Nru lua-unit-3.2/test/errFailPassTextStopOnError-4.txt lua-unit-3.3/test/errFailPassTextStopOnError-4.txt --- lua-unit-3.2/test/errFailPassTextStopOnError-4.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextStopOnError-4.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,13 +0,0 @@ -..F -Failure during LuaUnit test execution: -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 - -Failed tests: -------------- -1) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -Ran 3 tests in 0.000 seconds, 2 successes, 1 failure, 9 non-selected -LuaUnit ABORTED (as requested by --error or --failure option) diff -Nru lua-unit-3.2/test/errFailPassTextVerbose-failures.txt lua-unit-3.3/test/errFailPassTextVerbose-failures.txt --- lua-unit-3.2/test/errFailPassTextVerbose-failures.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextVerbose-failures.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,45 +0,0 @@ -Started on 03/22/16 21:29:18 - TestAnotherThing.test1_Success1 ... Ok - TestAnotherThing.test1_Success2 ... Ok - TestAnotherThing.test3_Fail1 ... FAIL -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 - TestAnotherThing.test3_Fail2 ... FAIL -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 - TestSomething.test1_Success1 ... Ok - TestSomething.test1_Success2 ... Ok - TestSomething.test2_Fail1 ... FAIL -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 - TestSomething.test2_Fail2 ... FAIL -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 - testFuncFail1 ... FAIL -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 - testFuncSuccess1 ... Ok -========================================================= -Failed tests: -------------- -1) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -2) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -3) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -4) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -5) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 10 tests in 0.001 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/errFailPassTextVerbose-success.txt lua-unit-3.3/test/errFailPassTextVerbose-success.txt --- lua-unit-3.2/test/errFailPassTextVerbose-success.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextVerbose-success.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,9 +0,0 @@ -Started on 03/22/16 21:29:18 - TestAnotherThing.test1_Success1 ... Ok - TestAnotherThing.test1_Success2 ... Ok - TestSomething.test1_Success1 ... Ok - TestSomething.test1_Success2 ... Ok - testFuncSuccess1 ... Ok -========================================================= -Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected -OK diff -Nru lua-unit-3.2/test/errFailPassTextVerbose.txt lua-unit-3.3/test/errFailPassTextVerbose.txt --- lua-unit-3.2/test/errFailPassTextVerbose.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassTextVerbose.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,80 +0,0 @@ -Started on 03/22/16 21:29:18 - TestAnotherThing.test1_Success1 ... Ok - TestAnotherThing.test1_Success2 ... Ok - TestAnotherThing.test2_Err1 ... ERROR -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value - TestAnotherThing.test2_Err2 ... ERROR -test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value - TestAnotherThing.test3_Fail1 ... FAIL -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 - TestAnotherThing.test3_Fail2 ... FAIL -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 - TestSomething.test1_Success1 ... Ok - TestSomething.test1_Success2 ... Ok - TestSomething.test2_Fail1 ... FAIL -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 - TestSomething.test2_Fail2 ... FAIL -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 - TestSomething.test3_Err1 ... ERROR -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value - TestSomething.test3_Err2 ... ERROR -test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value - testFuncErr1 ... ERROR -test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value - testFuncFail1 ... FAIL -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 - testFuncSuccess1 ... Ok -========================================================= -Failed tests: -------------- -1) TestAnotherThing.test2_Err1 -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -2) TestAnotherThing.test2_Err2 -test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -3) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -4) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -5) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -6) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -7) TestSomething.test3_Err1 -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -8) TestSomething.test3_Err2 -test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -9) testFuncErr1 -test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -10) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 15 tests in 0.001 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/errFailPassXmlDefault-failures.txt lua-unit-3.3/test/errFailPassXmlDefault-failures.txt --- lua-unit-3.2/test/errFailPassXmlDefault-failures.txt 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlDefault-failures.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -# XML output to test/ref/errFailPassXmlDefault-failures.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 10 tests in 0.003 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/errFailPassXmlDefault-failures.xml lua-unit-3.3/test/errFailPassXmlDefault-failures.xml --- lua-unit-3.2/test/errFailPassXmlDefault-failures.xml 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlDefault-failures.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/errFailPassXmlDefault-success.txt lua-unit-3.3/test/errFailPassXmlDefault-success.txt --- lua-unit-3.2/test/errFailPassXmlDefault-success.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlDefault-success.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -# XML output to test/ref/errFailPassXmlDefault-success.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: testFuncSuccess1 -# Ran 5 tests in 0.001 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/errFailPassXmlDefault-success.xml lua-unit-3.3/test/errFailPassXmlDefault-success.xml --- lua-unit-3.2/test/errFailPassXmlDefault-success.xml 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlDefault-success.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/errFailPassXmlDefault.txt lua-unit-3.3/test/errFailPassXmlDefault.txt --- lua-unit-3.2/test/errFailPassXmlDefault.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlDefault.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -# XML output to test/ref/errFailPassXmlDefault.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test2_Err1 -# Error: test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test2_Err2 -# Error: test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: TestSomething.test3_Err1 -# Error: test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -# Starting test: TestSomething.test3_Err2 -# Error: test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -# Starting test: testFuncErr1 -# Error: test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 15 tests in 0.004 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/errFailPassXmlDefault.xml lua-unit-3.3/test/errFailPassXmlDefault.xml --- lua-unit-3.2/test/errFailPassXmlDefault.xml 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlDefault.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,71 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/errFailPassXmlQuiet-failures.txt lua-unit-3.3/test/errFailPassXmlQuiet-failures.txt --- lua-unit-3.2/test/errFailPassXmlQuiet-failures.txt 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlQuiet-failures.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -# XML output to test/ref/errFailPassXmlQuiet-failures.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 10 tests in 0.002 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/errFailPassXmlQuiet-failures.xml lua-unit-3.3/test/errFailPassXmlQuiet-failures.xml --- lua-unit-3.2/test/errFailPassXmlQuiet-failures.xml 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlQuiet-failures.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/errFailPassXmlQuiet-success.txt lua-unit-3.3/test/errFailPassXmlQuiet-success.txt --- lua-unit-3.2/test/errFailPassXmlQuiet-success.txt 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlQuiet-success.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -# XML output to test/ref/errFailPassXmlQuiet-success.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: testFuncSuccess1 -# Ran 5 tests in 0.001 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/errFailPassXmlQuiet-success.xml lua-unit-3.3/test/errFailPassXmlQuiet-success.xml --- lua-unit-3.2/test/errFailPassXmlQuiet-success.xml 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlQuiet-success.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/errFailPassXmlQuiet.txt lua-unit-3.3/test/errFailPassXmlQuiet.txt --- lua-unit-3.2/test/errFailPassXmlQuiet.txt 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlQuiet.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -# XML output to test/ref/errFailPassXmlQuiet.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test2_Err1 -# Error: test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test2_Err2 -# Error: test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: TestSomething.test3_Err1 -# Error: test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -# Starting test: TestSomething.test3_Err2 -# Error: test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -# Starting test: testFuncErr1 -# Error: test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 15 tests in 0.003 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/errFailPassXmlQuiet.xml lua-unit-3.3/test/errFailPassXmlQuiet.xml --- lua-unit-3.2/test/errFailPassXmlQuiet.xml 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlQuiet.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,71 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/errFailPassXmlVerbose-failures.txt lua-unit-3.3/test/errFailPassXmlVerbose-failures.txt --- lua-unit-3.2/test/errFailPassXmlVerbose-failures.txt 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlVerbose-failures.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -# XML output to test/ref/errFailPassXmlVerbose-failures.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 10 tests in 0.002 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/errFailPassXmlVerbose-failures.xml lua-unit-3.3/test/errFailPassXmlVerbose-failures.xml --- lua-unit-3.2/test/errFailPassXmlVerbose-failures.xml 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlVerbose-failures.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/errFailPassXmlVerbose-success.txt lua-unit-3.3/test/errFailPassXmlVerbose-success.txt --- lua-unit-3.2/test/errFailPassXmlVerbose-success.txt 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlVerbose-success.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -# XML output to test/ref/errFailPassXmlVerbose-success.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: testFuncSuccess1 -# Ran 5 tests in 0.001 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/errFailPassXmlVerbose-success.xml lua-unit-3.3/test/errFailPassXmlVerbose-success.xml --- lua-unit-3.2/test/errFailPassXmlVerbose-success.xml 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlVerbose-success.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/errFailPassXmlVerbose.txt lua-unit-3.3/test/errFailPassXmlVerbose.txt --- lua-unit-3.2/test/errFailPassXmlVerbose.txt 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlVerbose.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -# XML output to test/ref/errFailPassXmlVerbose.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test2_Err1 -# Error: test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test2_Err2 -# Error: test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: TestSomething.test3_Err1 -# Error: test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -# Starting test: TestSomething.test3_Err2 -# Error: test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -# Starting test: testFuncErr1 -# Error: test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 15 tests in 0.004 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/errFailPassXmlVerbose.xml lua-unit-3.3/test/errFailPassXmlVerbose.xml --- lua-unit-3.2/test/errFailPassXmlVerbose.xml 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/errFailPassXmlVerbose.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,71 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/exampleTapDefault.txt lua-unit-3.3/test/exampleTapDefault.txt --- lua-unit-3.2/test/exampleTapDefault.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/exampleTapDefault.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,35 +0,0 @@ -1..15 -# Started on 01/30/16 22:19:36 -# Starting class: TestTiti -not ok 1 TestTiti.test1_withFailure - example_with_luaunit.lua:101: expected: 2, actual: 1 -not ok 2 TestTiti.test2_withFailure - example_with_luaunit.lua:110: expected: "bof" - actual: "hop" -ok 3 TestTiti.test3 -# Starting class: TestToto -not ok 4 TestToto.test1_withFailure - example_with_luaunit.lua:21: expected: 2, actual: 1 -not ok 5 TestToto.test2_withFailure - example_with_luaunit.lua:30: expected: "bof" - actual: "hop" -ok 6 TestToto.test3 -not ok 7 TestToto.test4 - example_with_luaunit.lua:43: Received the not expected value: 1 -not ok 8 TestToto.test5 - example_with_luaunit.lua:49: expected: false, actual: 1 -not ok 9 TestToto.test6 - example_with_luaunit.lua:54: expected: true, actual: false -not ok 10 TestToto.test7 - example_with_luaunit.lua:60: expected: {1, 2, three=3} - actual: {1, 2} -not ok 11 TestToto.test8a - example_with_luaunit.lua:78: Bouhouhoum error! -not ok 12 TestToto.test8b - example_with_luaunit.lua:78: Bouhouhoum error! -not ok 13 test1_withFailure - example_with_luaunit.lua:126: assertion failed! -not ok 14 test2_withFailure - example_with_luaunit.lua:132: assertion failed! -ok 15 test3 -# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/exampleTapQuiet.txt lua-unit-3.3/test/exampleTapQuiet.txt --- lua-unit-3.2/test/exampleTapQuiet.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/exampleTapQuiet.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -1..15 -# Started on 01/30/16 22:19:36 -# Starting class: TestTiti -not ok 1 TestTiti.test1_withFailure -not ok 2 TestTiti.test2_withFailure -ok 3 TestTiti.test3 -# Starting class: TestToto -not ok 4 TestToto.test1_withFailure -not ok 5 TestToto.test2_withFailure -ok 6 TestToto.test3 -not ok 7 TestToto.test4 -not ok 8 TestToto.test5 -not ok 9 TestToto.test6 -not ok 10 TestToto.test7 -not ok 11 TestToto.test8a -not ok 12 TestToto.test8b -not ok 13 test1_withFailure -not ok 14 test2_withFailure -ok 15 test3 -# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/exampleTapVerbose.txt lua-unit-3.3/test/exampleTapVerbose.txt --- lua-unit-3.2/test/exampleTapVerbose.txt 2016-10-11 09:40:08.000000000 +0000 +++ lua-unit-3.3/test/exampleTapVerbose.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,62 +0,0 @@ -1..15 -# Started on 01/30/16 22:19:36 -# Starting class: TestTiti -not ok 1 TestTiti.test1_withFailure - example_with_luaunit.lua:101: expected: 2, actual: 1 - stack traceback: - example_with_luaunit.lua:101: in function 'TestTiti.test1_withFailure' -not ok 2 TestTiti.test2_withFailure - example_with_luaunit.lua:110: expected: "bof" - actual: "hop" - stack traceback: - example_with_luaunit.lua:110: in function 'TestTiti.test2_withFailure' -ok 3 TestTiti.test3 -# Starting class: TestToto -not ok 4 TestToto.test1_withFailure - example_with_luaunit.lua:21: expected: 2, actual: 1 - stack traceback: - example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' -not ok 5 TestToto.test2_withFailure - example_with_luaunit.lua:30: expected: "bof" - actual: "hop" - stack traceback: - example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' -ok 6 TestToto.test3 -not ok 7 TestToto.test4 - example_with_luaunit.lua:43: Received the not expected value: 1 - stack traceback: - example_with_luaunit.lua:43: in function 'TestToto.test4' -not ok 8 TestToto.test5 - example_with_luaunit.lua:49: expected: false, actual: 1 - stack traceback: - example_with_luaunit.lua:49: in function 'TestToto.test5' -not ok 9 TestToto.test6 - example_with_luaunit.lua:54: expected: true, actual: false - stack traceback: - example_with_luaunit.lua:54: in function 'TestToto.test6' -not ok 10 TestToto.test7 - example_with_luaunit.lua:60: expected: {1, 2, three=3} - actual: {1, 2} - stack traceback: - example_with_luaunit.lua:60: in function 'TestToto.test7' -not ok 11 TestToto.test8a - example_with_luaunit.lua:78: Bouhouhoum error! - stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:65: in function 'TestToto.test8a' -not ok 12 TestToto.test8b - example_with_luaunit.lua:78: Bouhouhoum error! - stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:74: in function 'funcWithFuncWithError' - example_with_luaunit.lua:70: in function 'TestToto.test8b' -not ok 13 test1_withFailure - example_with_luaunit.lua:126: assertion failed! - stack traceback: - example_with_luaunit.lua:126: in function 'test1_withFailure' -not ok 14 test2_withFailure - example_with_luaunit.lua:132: assertion failed! - stack traceback: - example_with_luaunit.lua:132: in function 'test2_withFailure' -ok 15 test3 -# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/exampleTextDefault.txt lua-unit-3.3/test/exampleTextDefault.txt --- lua-unit-3.2/test/exampleTextDefault.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/exampleTextDefault.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,70 +0,0 @@ -FF.FF.FFFFEEEE. -Failed tests: -------------- -1) TestTiti.test1_withFailure -example_with_luaunit.lua:101: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:101: in function 'TestTiti.test1_withFailure' - -2) TestTiti.test2_withFailure -example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:110: in function 'TestTiti.test2_withFailure' - -3) TestToto.test1_withFailure -example_with_luaunit.lua:21: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' - -4) TestToto.test2_withFailure -example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' - -5) TestToto.test4 -example_with_luaunit.lua:43: Received the not expected value: 1 -stack traceback: - example_with_luaunit.lua:43: in function 'TestToto.test4' - -6) TestToto.test5 -example_with_luaunit.lua:49: expected: false, actual: 1 -stack traceback: - example_with_luaunit.lua:49: in function 'TestToto.test5' - -7) TestToto.test6 -example_with_luaunit.lua:54: expected: true, actual: false -stack traceback: - example_with_luaunit.lua:54: in function 'TestToto.test6' - -8) TestToto.test7 -example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -stack traceback: - example_with_luaunit.lua:60: in function 'TestToto.test7' - -9) TestToto.test8a -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:65: in function 'TestToto.test8a' - -10) TestToto.test8b -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:74: in function 'funcWithFuncWithError' - example_with_luaunit.lua:70: in function 'TestToto.test8b' - -11) test1_withFailure -example_with_luaunit.lua:126: assertion failed! -stack traceback: - example_with_luaunit.lua:126: in function 'test1_withFailure' - -12) test2_withFailure -example_with_luaunit.lua:132: assertion failed! -stack traceback: - example_with_luaunit.lua:132: in function 'test2_withFailure' - -Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/exampleTextQuiet.txt lua-unit-3.3/test/exampleTextQuiet.txt --- lua-unit-3.2/test/exampleTextQuiet.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/exampleTextQuiet.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,70 +0,0 @@ -FF.FF.FFFFEEEE. -Failed tests: -------------- -1) TestTiti.test1_withFailure -example_with_luaunit.lua:101: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:101: in function 'TestTiti.test1_withFailure' - -2) TestTiti.test2_withFailure -example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:110: in function 'TestTiti.test2_withFailure' - -3) TestToto.test1_withFailure -example_with_luaunit.lua:21: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' - -4) TestToto.test2_withFailure -example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' - -5) TestToto.test4 -example_with_luaunit.lua:43: Received the not expected value: 1 -stack traceback: - example_with_luaunit.lua:43: in function 'TestToto.test4' - -6) TestToto.test5 -example_with_luaunit.lua:49: expected: false, actual: 1 -stack traceback: - example_with_luaunit.lua:49: in function 'TestToto.test5' - -7) TestToto.test6 -example_with_luaunit.lua:54: expected: true, actual: false -stack traceback: - example_with_luaunit.lua:54: in function 'TestToto.test6' - -8) TestToto.test7 -example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -stack traceback: - example_with_luaunit.lua:60: in function 'TestToto.test7' - -9) TestToto.test8a -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:65: in function 'TestToto.test8a' - -10) TestToto.test8b -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:74: in function 'funcWithFuncWithError' - example_with_luaunit.lua:70: in function 'TestToto.test8b' - -11) test1_withFailure -example_with_luaunit.lua:126: assertion failed! -stack traceback: - example_with_luaunit.lua:126: in function 'test1_withFailure' - -12) test2_withFailure -example_with_luaunit.lua:132: assertion failed! -stack traceback: - example_with_luaunit.lua:132: in function 'test2_withFailure' - -Ran 15 tests in 0.012 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/exampleTextVerbose.txt lua-unit-3.3/test/exampleTextVerbose.txt --- lua-unit-3.2/test/exampleTextVerbose.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/exampleTextVerbose.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,101 +0,0 @@ -Started on 01/27/16 21:35:20 - TestTiti.test1_withFailure ... FAIL -example_with_luaunit.lua:101: expected: 2, actual: 1 - TestTiti.test2_withFailure ... FAIL -example_with_luaunit.lua:110: expected: "bof" -actual: "hop" - TestTiti.test3 ... Ok - TestToto.test1_withFailure ... FAIL -example_with_luaunit.lua:21: expected: 2, actual: 1 - TestToto.test2_withFailure ... FAIL -example_with_luaunit.lua:30: expected: "bof" -actual: "hop" - TestToto.test3 ... Ok - TestToto.test4 ... FAIL -example_with_luaunit.lua:43: Received the not expected value: 1 - TestToto.test5 ... FAIL -example_with_luaunit.lua:49: expected: false, actual: 1 - TestToto.test6 ... FAIL -example_with_luaunit.lua:54: expected: true, actual: false - TestToto.test7 ... FAIL -example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} - TestToto.test8a ... ERROR -example_with_luaunit.lua:78: Bouhouhoum error! - TestToto.test8b ... ERROR -example_with_luaunit.lua:78: Bouhouhoum error! - test1_withFailure ... ERROR -example_with_luaunit.lua:126: assertion failed! - test2_withFailure ... ERROR -example_with_luaunit.lua:132: assertion failed! - test3 ... Ok -========================================================= -Failed tests: -------------- -1) TestTiti.test1_withFailure -example_with_luaunit.lua:101: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:101: in function 'TestTiti.test1_withFailure' - -2) TestTiti.test2_withFailure -example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:110: in function 'TestTiti.test2_withFailure' - -3) TestToto.test1_withFailure -example_with_luaunit.lua:21: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' - -4) TestToto.test2_withFailure -example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' - -5) TestToto.test4 -example_with_luaunit.lua:43: Received the not expected value: 1 -stack traceback: - example_with_luaunit.lua:43: in function 'TestToto.test4' - -6) TestToto.test5 -example_with_luaunit.lua:49: expected: false, actual: 1 -stack traceback: - example_with_luaunit.lua:49: in function 'TestToto.test5' - -7) TestToto.test6 -example_with_luaunit.lua:54: expected: true, actual: false -stack traceback: - example_with_luaunit.lua:54: in function 'TestToto.test6' - -8) TestToto.test7 -example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -stack traceback: - example_with_luaunit.lua:60: in function 'TestToto.test7' - -9) TestToto.test8a -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:65: in function 'TestToto.test8a' - -10) TestToto.test8b -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:74: in function 'funcWithFuncWithError' - example_with_luaunit.lua:70: in function 'TestToto.test8b' - -11) test1_withFailure -example_with_luaunit.lua:126: assertion failed! -stack traceback: - example_with_luaunit.lua:126: in function 'test1_withFailure' - -12) test2_withFailure -example_with_luaunit.lua:132: assertion failed! -stack traceback: - example_with_luaunit.lua:132: in function 'test2_withFailure' - -Ran 15 tests in 0.004 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/exampleXmlDefault.txt lua-unit-3.3/test/exampleXmlDefault.txt --- lua-unit-3.2/test/exampleXmlDefault.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/exampleXmlDefault.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,35 +0,0 @@ -# XML output to test/ref/exampleXmlDefault.xml -# Started on 01/30/16 22:19:37 -# Starting class: TestTiti -# Starting test: TestTiti.test1_withFailure -# Failure: example_with_luaunit.lua:101: expected: 2, actual: 1 -# Starting test: TestTiti.test2_withFailure -# Failure: example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -# Starting test: TestTiti.test3 -# Starting class: TestToto -# Starting test: TestToto.test1_withFailure -# Failure: example_with_luaunit.lua:21: expected: 2, actual: 1 -# Starting test: TestToto.test2_withFailure -# Failure: example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -# Starting test: TestToto.test3 -# Starting test: TestToto.test4 -# Failure: example_with_luaunit.lua:43: Received the not expected value: 1 -# Starting test: TestToto.test5 -# Failure: example_with_luaunit.lua:49: expected: false, actual: 1 -# Starting test: TestToto.test6 -# Failure: example_with_luaunit.lua:54: expected: true, actual: false -# Starting test: TestToto.test7 -# Failure: example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -# Starting test: TestToto.test8a -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: TestToto.test8b -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: test1_withFailure -# Error: example_with_luaunit.lua:126: assertion failed! -# Starting test: test2_withFailure -# Error: example_with_luaunit.lua:132: assertion failed! -# Starting test: test3 -# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/exampleXmlDefault.xml lua-unit-3.3/test/exampleXmlDefault.xml --- lua-unit-3.2/test/exampleXmlDefault.xml 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/exampleXmlDefault.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/exampleXmlQuiet.txt lua-unit-3.3/test/exampleXmlQuiet.txt --- lua-unit-3.2/test/exampleXmlQuiet.txt 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/exampleXmlQuiet.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,35 +0,0 @@ -# XML output to test/ref/exampleXmlQuiet.xml -# Started on 01/30/16 22:19:37 -# Starting class: TestTiti -# Starting test: TestTiti.test1_withFailure -# Failure: example_with_luaunit.lua:101: expected: 2, actual: 1 -# Starting test: TestTiti.test2_withFailure -# Failure: example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -# Starting test: TestTiti.test3 -# Starting class: TestToto -# Starting test: TestToto.test1_withFailure -# Failure: example_with_luaunit.lua:21: expected: 2, actual: 1 -# Starting test: TestToto.test2_withFailure -# Failure: example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -# Starting test: TestToto.test3 -# Starting test: TestToto.test4 -# Failure: example_with_luaunit.lua:43: Received the not expected value: 1 -# Starting test: TestToto.test5 -# Failure: example_with_luaunit.lua:49: expected: false, actual: 1 -# Starting test: TestToto.test6 -# Failure: example_with_luaunit.lua:54: expected: true, actual: false -# Starting test: TestToto.test7 -# Failure: example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -# Starting test: TestToto.test8a -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: TestToto.test8b -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: test1_withFailure -# Error: example_with_luaunit.lua:126: assertion failed! -# Starting test: test2_withFailure -# Error: example_with_luaunit.lua:132: assertion failed! -# Starting test: test3 -# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/exampleXmlQuiet.xml lua-unit-3.3/test/exampleXmlQuiet.xml --- lua-unit-3.2/test/exampleXmlQuiet.xml 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/exampleXmlQuiet.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/exampleXmlVerbose.txt lua-unit-3.3/test/exampleXmlVerbose.txt --- lua-unit-3.2/test/exampleXmlVerbose.txt 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/exampleXmlVerbose.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,35 +0,0 @@ -# XML output to test/ref/exampleXmlVerbose.xml -# Started on 01/30/16 22:19:37 -# Starting class: TestTiti -# Starting test: TestTiti.test1_withFailure -# Failure: example_with_luaunit.lua:101: expected: 2, actual: 1 -# Starting test: TestTiti.test2_withFailure -# Failure: example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -# Starting test: TestTiti.test3 -# Starting class: TestToto -# Starting test: TestToto.test1_withFailure -# Failure: example_with_luaunit.lua:21: expected: 2, actual: 1 -# Starting test: TestToto.test2_withFailure -# Failure: example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -# Starting test: TestToto.test3 -# Starting test: TestToto.test4 -# Failure: example_with_luaunit.lua:43: Received the not expected value: 1 -# Starting test: TestToto.test5 -# Failure: example_with_luaunit.lua:49: expected: false, actual: 1 -# Starting test: TestToto.test6 -# Failure: example_with_luaunit.lua:54: expected: true, actual: false -# Starting test: TestToto.test7 -# Failure: example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -# Starting test: TestToto.test8a -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: TestToto.test8b -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: test1_withFailure -# Error: example_with_luaunit.lua:126: assertion failed! -# Starting test: test2_withFailure -# Error: example_with_luaunit.lua:132: assertion failed! -# Starting test: test3 -# Ran 15 tests in 0.015 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/exampleXmlVerbose.xml lua-unit-3.3/test/exampleXmlVerbose.xml --- lua-unit-3.2/test/exampleXmlVerbose.xml 2016-10-11 09:40:13.000000000 +0000 +++ lua-unit-3.3/test/exampleXmlVerbose.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/legacyExample.txt lua-unit-3.3/test/legacyExample.txt --- lua-unit-3.2/test/legacyExample.txt 2016-10-11 09:40:07.000000000 +0000 +++ lua-unit-3.3/test/legacyExample.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,85 +0,0 @@ -TestTiti:setUp -some stuff test 1 -TestTiti:tearDown -FTestTiti:setUp -some stuff test 2 -TestTiti:tearDown -FTestTiti:setUp -some stuff test 3 -TestTiti:tearDown -.some stuff test 1 -Fsome stuff test 2 -Fsome stuff test 3 -.some stuff test 4 -Fsome stuff test 5 -Fsome stuff test 6 -FFEEEE. -Failed tests: -------------- -1) TestTiti.test1_withFailure -test/legacy_example_with_luaunit.lua:99: expected: 2, actual: 1 -stack traceback: - test/legacy_example_with_luaunit.lua:99: in function 'TestTiti.test1_withFailure' - -2) TestTiti.test2_withFailure -test/legacy_example_with_luaunit.lua:108: expected: "bof" -actual: "hop" -stack traceback: - test/legacy_example_with_luaunit.lua:108: in function 'TestTiti.test2_withFailure' - -3) TestToto.test1_withFailure -test/legacy_example_with_luaunit.lua:19: expected: 2, actual: 1 -stack traceback: - test/legacy_example_with_luaunit.lua:19: in function 'TestToto.test1_withFailure' - -4) TestToto.test2_withFailure -test/legacy_example_with_luaunit.lua:28: expected: "bof" -actual: "hop" -stack traceback: - test/legacy_example_with_luaunit.lua:28: in function 'TestToto.test2_withFailure' - -5) TestToto.test4 -test/legacy_example_with_luaunit.lua:41: Received the not expected value: 1 -stack traceback: - test/legacy_example_with_luaunit.lua:41: in function 'TestToto.test4' - -6) TestToto.test5 -test/legacy_example_with_luaunit.lua:47: expected: false, actual: 1 -stack traceback: - test/legacy_example_with_luaunit.lua:47: in function 'TestToto.test5' - -7) TestToto.test6 -test/legacy_example_with_luaunit.lua:52: expected: true, actual: false -stack traceback: - test/legacy_example_with_luaunit.lua:52: in function 'TestToto.test6' - -8) TestToto.test7 -test/legacy_example_with_luaunit.lua:58: expected: {1, 2, three=3} -actual: {1, 2} -stack traceback: - test/legacy_example_with_luaunit.lua:58: in function 'TestToto.test7' - -9) TestToto.test8a -test/legacy_example_with_luaunit.lua:76: Bouhouhoum error! -stack traceback: - test/legacy_example_with_luaunit.lua:76: in function 'funcWithError' - test/legacy_example_with_luaunit.lua:63: in function 'TestToto.test8a' - -10) TestToto.test8b -test/legacy_example_with_luaunit.lua:76: Bouhouhoum error! -stack traceback: - test/legacy_example_with_luaunit.lua:76: in function 'funcWithError' - test/legacy_example_with_luaunit.lua:72: in function 'funcWithFuncWithError' - test/legacy_example_with_luaunit.lua:68: in function 'TestToto.test8b' - -11) test1_withFailure -test/legacy_example_with_luaunit.lua:124: assertion failed! -stack traceback: - test/legacy_example_with_luaunit.lua:124: in function 'test1_withFailure' - -12) test2_withFailure -test/legacy_example_with_luaunit.lua:130: assertion failed! -stack traceback: - test/legacy_example_with_luaunit.lua:130: in function 'test2_withFailure' - -Ran 15 tests in 0.001 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/legacy_example_with_luaunit.lua lua-unit-3.3/test/legacy_example_with_luaunit.lua --- lua-unit-3.2/test/legacy_example_with_luaunit.lua 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/legacy_example_with_luaunit.lua 2018-04-20 12:34:12.000000000 +0000 @@ -1,140 +1,140 @@ -EXPORT_ASSERT_TO_GLOBALS = true -require('luaunit') - -TestToto = {} --class - - function TestToto:setUp() - -- set up tests - self.a = 1 - self.s = 'hop' - self.t1 = {1,2,3} - self.t2 = {one=1,two=2,three=3} - self.t3 = {1,2,three=3} - end - - function TestToto:test1_withFailure() - print( "some stuff test 1" ) - assertEquals( self.a , 1 ) - -- will fail - assertEquals( self.a , 2 ) - assertEquals( self.a , 2 ) - end - - function TestToto:test2_withFailure() - print( "some stuff test 2" ) - assertEquals( self.a , 1 ) - assertEquals( self.s , 'hop' ) - -- will fail - assertEquals( self.s , 'bof' ) - assertEquals( self.s , 'bof' ) - end - - function TestToto:test3() - print( "some stuff test 3" ) - assertEquals( self.a , 1 ) - assertEquals( self.s , 'hop' ) - assertEquals( type(self.a), 'number' ) - end - - function TestToto:test4() - print( "some stuff test 4" ) - assertNotEquals( self.a , 1 ) - end - - function TestToto:test5() - print( "some stuff test 5" ) - assertTrue( self.a ) - assertFalse( self.a ) - end - - function TestToto:test6() - print( "some stuff test 6" ) - assertTrue( false ) - end - - function TestToto:test7() - -- assertEquals( {1,2}, self.t1 ) - -- assertEquals( {1,2}, self.t2 ) - assertEquals( {1,2}, self.t3 ) - end - - function TestToto:test8a() - -- failure occurs in a submethod - self:funcWithError() - end - - function TestToto:test8b() - -- failure occurs in a submethod - self:funcWithFuncWithError() - end - - function TestToto:funcWithFuncWithError() - self:funcWithError() - end - - function TestToto:funcWithError() - error('Bouhouhoum error!') - end - - --- class TestToto - -TestTiti = {} --class - function TestTiti:setUp() - -- set up tests - self.a = 1 - self.s = 'hop' - print( 'TestTiti:setUp' ) - end - - function TestTiti:tearDown() - -- some tearDown() code if necessary - print( 'TestTiti:tearDown' ) - end - - function TestTiti:test1_withFailure() - print( "some stuff test 1" ) - assertEquals( self.a , 1 ) - -- will fail - assertEquals( self.a , 2 ) - assertEquals( self.a , 2 ) - end - - function TestTiti:test2_withFailure() - print( "some stuff test 2" ) - assertEquals( self.a , 1 ) - assertEquals( self.s , 'hop' ) - -- will fail - assertEquals( self.s , 'bof' ) - assertEquals( self.s , 'bof' ) - end - - function TestTiti:test3() - print( "some stuff test 3" ) - assertEquals( self.a , 1 ) - assertEquals( self.s , 'hop' ) - end --- class TestTiti - --- simple test functions that were written previously can be integrated --- in luaunit too -function test1_withFailure() - assert( 1 == 1) - -- will fail - assert( 1 == 2) -end - -function test2_withFailure() - assert( 'a' == 'a') - -- will fail - assert( 'a' == 'b') -end - -function test3() - assert( 1 == 1) - assert( 'a' == 'a') -end - -local lu = LuaUnit.new() -lu:setOutputType("tap") -os.exit( lu:runSuite() ) +EXPORT_ASSERT_TO_GLOBALS = true +require('luaunit') + +TestToto = {} --class + + function TestToto:setUp() + -- set up tests + self.a = 1 + self.s = 'hop' + self.t1 = {1,2,3} + self.t2 = {one=1,two=2,three=3} + self.t3 = {1,2,three=3} + end + + function TestToto:test1_withFailure() + print( "some stuff test 1" ) + assertEquals( self.a , 1 ) + -- will fail + assertEquals( self.a , 2 ) + assertEquals( self.a , 2 ) + end + + function TestToto:test2_withFailure() + print( "some stuff test 2" ) + assertEquals( self.a , 1 ) + assertEquals( self.s , 'hop' ) + -- will fail + assertEquals( self.s , 'bof' ) + assertEquals( self.s , 'bof' ) + end + + function TestToto:test3() + print( "some stuff test 3" ) + assertEquals( self.a , 1 ) + assertEquals( self.s , 'hop' ) + assertEquals( type(self.a), 'number' ) + end + + function TestToto:test4() + print( "some stuff test 4" ) + assertNotEquals( self.a , 1 ) + end + + function TestToto:test5() + print( "some stuff test 5" ) + assertTrue( self.a ) + assertFalse( self.a ) + end + + function TestToto:test6() + print( "some stuff test 6" ) + assertTrue( false ) + end + + function TestToto:test7() + -- assertEquals( {1,2}, self.t1 ) + -- assertEquals( {1,2}, self.t2 ) + assertEquals( {1,2}, self.t3 ) + end + + function TestToto:test8a() + -- failure occurs in a submethod + self:funcWithError() + end + + function TestToto:test8b() + -- failure occurs in a submethod + self:funcWithFuncWithError() + end + + function TestToto:funcWithFuncWithError() + self:funcWithError() + end + + function TestToto:funcWithError() + error('Bouhouhoum error!') + end + + +-- class TestToto + +TestTiti = {} --class + function TestTiti:setUp() + -- set up tests + self.a = 1 + self.s = 'hop' + print( 'TestTiti:setUp' ) + end + + function TestTiti:tearDown() + -- some tearDown() code if necessary + print( 'TestTiti:tearDown' ) + end + + function TestTiti:test1_withFailure() + print( "some stuff test 1" ) + assertEquals( self.a , 1 ) + -- will fail + assertEquals( self.a , 2 ) + assertEquals( self.a , 2 ) + end + + function TestTiti:test2_withFailure() + print( "some stuff test 2" ) + assertEquals( self.a , 1 ) + assertEquals( self.s , 'hop' ) + -- will fail + assertEquals( self.s , 'bof' ) + assertEquals( self.s , 'bof' ) + end + + function TestTiti:test3() + print( "some stuff test 3" ) + assertEquals( self.a , 1 ) + assertEquals( self.s , 'hop' ) + end +-- class TestTiti + +-- simple test functions that were written previously can be integrated +-- in luaunit too +function test1_withFailure() + assert( 1 == 1) + -- will fail + assert( 1 == 2) +end + +function test2_withFailure() + assert( 'a' == 'a') + -- will fail + assert( 'a' == 'b') +end + +function test3() + assert( 1 == 1) + assert( 'a' == 'a') +end + +local lu = LuaUnit.new() +lu:setOutputType("tap") +os.exit( lu:runSuite() ) diff -Nru lua-unit-3.2/test/ref/errFailPassTapDefault-failures.txt lua-unit-3.3/test/ref/errFailPassTapDefault-failures.txt --- lua-unit-3.2/test/ref/errFailPassTapDefault-failures.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTapDefault-failures.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,20 +1,20 @@ -1..10 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test3_Fail1 - test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -not ok 4 TestAnotherThing.test3_Fail2 - test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -ok 5 TestSomething.test1_Success1 -ok 6 TestSomething.test1_Success2 -not ok 7 TestSomething.test2_Fail1 - test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -not ok 8 TestSomething.test2_Fail2 - test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -not ok 9 testFuncFail1 - test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -ok 10 testFuncSuccess1 -# Ran 10 tests in 0.000 seconds, 5 successes, 5 failures, 5 non-selected +1..10 +# Started on 03/22/16 21:58:32 +# Starting class: TestAnotherThing +ok 1 TestAnotherThing.test1_Success1 +ok 2 TestAnotherThing.test1_Success2 +not ok 3 TestAnotherThing.test3_Fail1 +# test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +not ok 4 TestAnotherThing.test3_Fail2 +# test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +# Starting class: TestSomething +ok 5 TestSomething.test1_Success1 +ok 6 TestSomething.test1_Success2 +not ok 7 TestSomething.test2_Fail1 +# test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +not ok 8 TestSomething.test2_Fail2 +# test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +not ok 9 testFuncFail1 +# test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +ok 10 testFuncSuccess1 +# Ran 10 tests in 0.000 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassTapDefault-success.txt lua-unit-3.3/test/ref/errFailPassTapDefault-success.txt --- lua-unit-3.2/test/ref/errFailPassTapDefault-success.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTapDefault-success.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,10 +1,10 @@ -1..5 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -# Starting class: TestSomething -ok 3 TestSomething.test1_Success1 -ok 4 TestSomething.test1_Success2 -ok 5 testFuncSuccess1 -# Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected +1..5 +# Started on 03/22/16 21:58:32 +# Starting class: TestAnotherThing +ok 1 TestAnotherThing.test1_Success1 +ok 2 TestAnotherThing.test1_Success2 +# Starting class: TestSomething +ok 3 TestSomething.test1_Success1 +ok 4 TestSomething.test1_Success2 +ok 5 testFuncSuccess1 +# Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassTapDefault.txt lua-unit-3.3/test/ref/errFailPassTapDefault.txt --- lua-unit-3.2/test/ref/errFailPassTapDefault.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTapDefault.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,30 +1,30 @@ -1..15 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test2_Err1 - test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -not ok 4 TestAnotherThing.test2_Err2 - test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -not ok 5 TestAnotherThing.test3_Fail1 - test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -not ok 6 TestAnotherThing.test3_Fail2 - test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -ok 7 TestSomething.test1_Success1 -ok 8 TestSomething.test1_Success2 -not ok 9 TestSomething.test2_Fail1 - test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -not ok 10 TestSomething.test2_Fail2 - test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -not ok 11 TestSomething.test3_Err1 - test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -not ok 12 TestSomething.test3_Err2 - test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -not ok 13 testFuncErr1 - test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -not ok 14 testFuncFail1 - test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -ok 15 testFuncSuccess1 -# Ran 15 tests in 0.003 seconds, 5 successes, 5 failures, 5 errors +1..15 +# Started on 03/22/16 21:58:32 +# Starting class: TestAnotherThing +ok 1 TestAnotherThing.test1_Success1 +ok 2 TestAnotherThing.test1_Success2 +not ok 3 TestAnotherThing.test2_Err1 +# test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value +not ok 4 TestAnotherThing.test2_Err2 +# test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value +not ok 5 TestAnotherThing.test3_Fail1 +# test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +not ok 6 TestAnotherThing.test3_Fail2 +# test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +# Starting class: TestSomething +ok 7 TestSomething.test1_Success1 +ok 8 TestSomething.test1_Success2 +not ok 9 TestSomething.test2_Fail1 +# test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +not ok 10 TestSomething.test2_Fail2 +# test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +not ok 11 TestSomething.test3_Err1 +# test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value +not ok 12 TestSomething.test3_Err2 +# test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value +not ok 13 testFuncErr1 +# test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value +not ok 14 testFuncFail1 +# test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +ok 15 testFuncSuccess1 +# Ran 15 tests in 0.003 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/ref/errFailPassTapQuiet-failures.txt lua-unit-3.3/test/ref/errFailPassTapQuiet-failures.txt --- lua-unit-3.2/test/ref/errFailPassTapQuiet-failures.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTapQuiet-failures.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,15 +1,15 @@ -1..10 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test3_Fail1 -not ok 4 TestAnotherThing.test3_Fail2 -# Starting class: TestSomething -ok 5 TestSomething.test1_Success1 -ok 6 TestSomething.test1_Success2 -not ok 7 TestSomething.test2_Fail1 -not ok 8 TestSomething.test2_Fail2 -not ok 9 testFuncFail1 -ok 10 testFuncSuccess1 -# Ran 10 tests in 0.002 seconds, 5 successes, 5 failures, 5 non-selected +1..10 +# Started on 03/22/16 21:58:32 +# Starting class: TestAnotherThing +ok 1 TestAnotherThing.test1_Success1 +ok 2 TestAnotherThing.test1_Success2 +not ok 3 TestAnotherThing.test3_Fail1 +not ok 4 TestAnotherThing.test3_Fail2 +# Starting class: TestSomething +ok 5 TestSomething.test1_Success1 +ok 6 TestSomething.test1_Success2 +not ok 7 TestSomething.test2_Fail1 +not ok 8 TestSomething.test2_Fail2 +not ok 9 testFuncFail1 +ok 10 testFuncSuccess1 +# Ran 10 tests in 0.002 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassTapQuiet-success.txt lua-unit-3.3/test/ref/errFailPassTapQuiet-success.txt --- lua-unit-3.2/test/ref/errFailPassTapQuiet-success.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTapQuiet-success.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,10 +1,10 @@ -1..5 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -# Starting class: TestSomething -ok 3 TestSomething.test1_Success1 -ok 4 TestSomething.test1_Success2 -ok 5 testFuncSuccess1 -# Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected +1..5 +# Started on 03/22/16 21:58:32 +# Starting class: TestAnotherThing +ok 1 TestAnotherThing.test1_Success1 +ok 2 TestAnotherThing.test1_Success2 +# Starting class: TestSomething +ok 3 TestSomething.test1_Success1 +ok 4 TestSomething.test1_Success2 +ok 5 testFuncSuccess1 +# Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassTapQuiet.txt lua-unit-3.3/test/ref/errFailPassTapQuiet.txt --- lua-unit-3.2/test/ref/errFailPassTapQuiet.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTapQuiet.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,20 +1,20 @@ -1..15 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test2_Err1 -not ok 4 TestAnotherThing.test2_Err2 -not ok 5 TestAnotherThing.test3_Fail1 -not ok 6 TestAnotherThing.test3_Fail2 -# Starting class: TestSomething -ok 7 TestSomething.test1_Success1 -ok 8 TestSomething.test1_Success2 -not ok 9 TestSomething.test2_Fail1 -not ok 10 TestSomething.test2_Fail2 -not ok 11 TestSomething.test3_Err1 -not ok 12 TestSomething.test3_Err2 -not ok 13 testFuncErr1 -not ok 14 testFuncFail1 -ok 15 testFuncSuccess1 -# Ran 15 tests in 0.002 seconds, 5 successes, 5 failures, 5 errors +1..15 +# Started on 03/22/16 21:58:32 +# Starting class: TestAnotherThing +ok 1 TestAnotherThing.test1_Success1 +ok 2 TestAnotherThing.test1_Success2 +not ok 3 TestAnotherThing.test2_Err1 +not ok 4 TestAnotherThing.test2_Err2 +not ok 5 TestAnotherThing.test3_Fail1 +not ok 6 TestAnotherThing.test3_Fail2 +# Starting class: TestSomething +ok 7 TestSomething.test1_Success1 +ok 8 TestSomething.test1_Success2 +not ok 9 TestSomething.test2_Fail1 +not ok 10 TestSomething.test2_Fail2 +not ok 11 TestSomething.test3_Err1 +not ok 12 TestSomething.test3_Err2 +not ok 13 testFuncErr1 +not ok 14 testFuncFail1 +ok 15 testFuncSuccess1 +# Ran 15 tests in 0.002 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/ref/errFailPassTapVerbose-failures.txt lua-unit-3.3/test/ref/errFailPassTapVerbose-failures.txt --- lua-unit-3.2/test/ref/errFailPassTapVerbose-failures.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTapVerbose-failures.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,30 +1,30 @@ -1..10 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test3_Fail1 - test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 - stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' -not ok 4 TestAnotherThing.test3_Fail2 - test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' -# Starting class: TestSomething -ok 5 TestSomething.test1_Success1 -ok 6 TestSomething.test1_Success2 -not ok 7 TestSomething.test2_Fail1 - test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 - stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' -not ok 8 TestSomething.test2_Fail2 - test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' -not ok 9 testFuncFail1 - test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' -ok 10 testFuncSuccess1 -# Ran 10 tests in 0.000 seconds, 5 successes, 5 failures, 5 non-selected +1..10 +# Started on 03/22/16 21:58:32 +# Starting class: TestAnotherThing +ok 1 TestAnotherThing.test1_Success1 +ok 2 TestAnotherThing.test1_Success2 +not ok 3 TestAnotherThing.test3_Fail1 +# test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +# stack traceback: +# test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' +not ok 4 TestAnotherThing.test3_Fail2 +# test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +# stack traceback: +# test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' +# Starting class: TestSomething +ok 5 TestSomething.test1_Success1 +ok 6 TestSomething.test1_Success2 +not ok 7 TestSomething.test2_Fail1 +# test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +# stack traceback: +# test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' +not ok 8 TestSomething.test2_Fail2 +# test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +# stack traceback: +# test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' +not ok 9 testFuncFail1 +# test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +# stack traceback: +# test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' +ok 10 testFuncSuccess1 +# Ran 10 tests in 0.000 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassTapVerbose-success.txt lua-unit-3.3/test/ref/errFailPassTapVerbose-success.txt --- lua-unit-3.2/test/ref/errFailPassTapVerbose-success.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTapVerbose-success.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,10 +1,10 @@ -1..5 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -# Starting class: TestSomething -ok 3 TestSomething.test1_Success1 -ok 4 TestSomething.test1_Success2 -ok 5 testFuncSuccess1 -# Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected +1..5 +# Started on 03/22/16 21:58:32 +# Starting class: TestAnotherThing +ok 1 TestAnotherThing.test1_Success1 +ok 2 TestAnotherThing.test1_Success2 +# Starting class: TestSomething +ok 3 TestSomething.test1_Success1 +ok 4 TestSomething.test1_Success2 +ok 5 testFuncSuccess1 +# Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassTapVerbose.txt lua-unit-3.3/test/ref/errFailPassTapVerbose.txt --- lua-unit-3.2/test/ref/errFailPassTapVerbose.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTapVerbose.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,50 +1,50 @@ -1..15 -# Started on 03/22/16 21:58:32 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test2_Err1 - test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value - stack traceback: - [C]: in function 'xpcall' -not ok 4 TestAnotherThing.test2_Err2 - test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value - stack traceback: - [C]: in function 'xpcall' -not ok 5 TestAnotherThing.test3_Fail1 - test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 - stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' -not ok 6 TestAnotherThing.test3_Fail2 - test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' -# Starting class: TestSomething -ok 7 TestSomething.test1_Success1 -ok 8 TestSomething.test1_Success2 -not ok 9 TestSomething.test2_Fail1 - test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 - stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' -not ok 10 TestSomething.test2_Fail2 - test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' -not ok 11 TestSomething.test3_Err1 - test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value - stack traceback: - [C]: in function 'xpcall' -not ok 12 TestSomething.test3_Err2 - test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value - stack traceback: - [C]: in function 'xpcall' -not ok 13 testFuncErr1 - test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value - stack traceback: - [C]: in function 'xpcall' -not ok 14 testFuncFail1 - test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 - stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' -ok 15 testFuncSuccess1 -# Ran 15 tests in 0.000 seconds, 5 successes, 5 failures, 5 errors +1..15 +# Started on 03/22/16 21:58:32 +# Starting class: TestAnotherThing +ok 1 TestAnotherThing.test1_Success1 +ok 2 TestAnotherThing.test1_Success2 +not ok 3 TestAnotherThing.test2_Err1 +# test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value +# stack traceback: +# [C]: in function 'xpcall' +not ok 4 TestAnotherThing.test2_Err2 +# test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value +# stack traceback: +# [C]: in function 'xpcall' +not ok 5 TestAnotherThing.test3_Fail1 +# test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +# stack traceback: +# test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' +not ok 6 TestAnotherThing.test3_Fail2 +# test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +# stack traceback: +# test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' +# Starting class: TestSomething +ok 7 TestSomething.test1_Success1 +ok 8 TestSomething.test1_Success2 +not ok 9 TestSomething.test2_Fail1 +# test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +# stack traceback: +# test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' +not ok 10 TestSomething.test2_Fail2 +# test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +# stack traceback: +# test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' +not ok 11 TestSomething.test3_Err1 +# test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value +# stack traceback: +# [C]: in function 'xpcall' +not ok 12 TestSomething.test3_Err2 +# test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value +# stack traceback: +# [C]: in function 'xpcall' +not ok 13 testFuncErr1 +# test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value +# stack traceback: +# [C]: in function 'xpcall' +not ok 14 testFuncFail1 +# test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +# stack traceback: +# test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' +ok 15 testFuncSuccess1 +# Ran 15 tests in 0.000 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/ref/errFailPassTextDefault-failures.txt lua-unit-3.3/test/ref/errFailPassTextDefault-failures.txt --- lua-unit-3.2/test/ref/errFailPassTextDefault-failures.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextDefault-failures.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,29 +1,29 @@ -..FF..FFF. -Failed tests: -------------- -1) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -2) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -3) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -4) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -5) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 10 tests in 0.001 seconds, 5 successes, 5 failures, 5 non-selected +..FF..FFF. +Failed tests: +------------- +1) TestAnotherThing.test3_Fail1 +test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' + +2) TestAnotherThing.test3_Fail2 +test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' + +3) TestSomething.test2_Fail1 +test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' + +4) TestSomething.test2_Fail2 +test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' + +5) testFuncFail1 +test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' + +Ran 10 tests in 0.001 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassTextDefault-success.txt lua-unit-3.3/test/ref/errFailPassTextDefault-success.txt --- lua-unit-3.2/test/ref/errFailPassTextDefault-success.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextDefault-success.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,3 +1,3 @@ -..... -Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected -OK +..... +Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected +OK diff -Nru lua-unit-3.2/test/ref/errFailPassTextDefault.txt lua-unit-3.3/test/ref/errFailPassTextDefault.txt --- lua-unit-3.2/test/ref/errFailPassTextDefault.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextDefault.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,54 +1,54 @@ -..EEFF..FFEEEF. -Failed tests: -------------- -1) TestAnotherThing.test2_Err1 -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -2) TestAnotherThing.test2_Err2 -test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -3) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -4) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -5) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -6) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -7) TestSomething.test3_Err1 -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -8) TestSomething.test3_Err2 -test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -9) testFuncErr1 -test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -10) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 15 tests in 0.002 seconds, 5 successes, 5 failures, 5 errors +..EEFF..FFEEEF. +Failed tests: +------------- +1) TestAnotherThing.test2_Err1 +test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +2) TestAnotherThing.test2_Err2 +test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +3) TestAnotherThing.test3_Fail1 +test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' + +4) TestAnotherThing.test3_Fail2 +test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' + +5) TestSomething.test2_Fail1 +test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' + +6) TestSomething.test2_Fail2 +test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' + +7) TestSomething.test3_Err1 +test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +8) TestSomething.test3_Err2 +test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +9) testFuncErr1 +test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +10) testFuncFail1 +test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' + +Ran 15 tests in 0.002 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/ref/errFailPassTextQuiet-failures.txt lua-unit-3.3/test/ref/errFailPassTextQuiet-failures.txt --- lua-unit-3.2/test/ref/errFailPassTextQuiet-failures.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextQuiet-failures.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,29 +1,29 @@ -..FF..FFF. -Failed tests: -------------- -1) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -2) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -3) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -4) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -5) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 10 tests in 0.001 seconds, 5 successes, 5 failures, 5 non-selected +..FF..FFF. +Failed tests: +------------- +1) TestAnotherThing.test3_Fail1 +test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' + +2) TestAnotherThing.test3_Fail2 +test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' + +3) TestSomething.test2_Fail1 +test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' + +4) TestSomething.test2_Fail2 +test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' + +5) testFuncFail1 +test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' + +Ran 10 tests in 0.001 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassTextQuiet-success.txt lua-unit-3.3/test/ref/errFailPassTextQuiet-success.txt --- lua-unit-3.2/test/ref/errFailPassTextQuiet-success.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextQuiet-success.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,3 +1,3 @@ -..... -Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected -OK +..... +Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected +OK diff -Nru lua-unit-3.2/test/ref/errFailPassTextQuiet.txt lua-unit-3.3/test/ref/errFailPassTextQuiet.txt --- lua-unit-3.2/test/ref/errFailPassTextQuiet.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextQuiet.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,54 +1,54 @@ -..EEFF..FFEEEF. -Failed tests: -------------- -1) TestAnotherThing.test2_Err1 -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -2) TestAnotherThing.test2_Err2 -test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -3) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -4) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -5) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -6) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -7) TestSomething.test3_Err1 -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -8) TestSomething.test3_Err2 -test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -9) testFuncErr1 -test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -10) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 15 tests in 0.002 seconds, 5 successes, 5 failures, 5 errors +..EEFF..FFEEEF. +Failed tests: +------------- +1) TestAnotherThing.test2_Err1 +test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +2) TestAnotherThing.test2_Err2 +test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +3) TestAnotherThing.test3_Fail1 +test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' + +4) TestAnotherThing.test3_Fail2 +test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' + +5) TestSomething.test2_Fail1 +test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' + +6) TestSomething.test2_Fail2 +test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' + +7) TestSomething.test3_Err1 +test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +8) TestSomething.test3_Err2 +test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +9) testFuncErr1 +test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +10) testFuncFail1 +test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' + +Ran 15 tests in 0.002 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/ref/errFailPassTextStopOnError-1.txt lua-unit-3.3/test/ref/errFailPassTextStopOnError-1.txt --- lua-unit-3.2/test/ref/errFailPassTextStopOnError-1.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextStopOnError-1.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,3 +1,3 @@ -..... -Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected -OK +..... +Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected +OK diff -Nru lua-unit-3.2/test/ref/errFailPassTextStopOnError-2.txt lua-unit-3.3/test/ref/errFailPassTextStopOnError-2.txt --- lua-unit-3.2/test/ref/errFailPassTextStopOnError-2.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextStopOnError-2.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,23 +1,23 @@ -..FFE -ERROR during LuaUnit test execution: -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value - -Failed tests: -------------- -1) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -2) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -3) TestSomething.test3_Err1 -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -Ran 5 tests in 0.000 seconds, 2 successes, 2 failures, 1 error, 9 non-selected -LuaUnit ABORTED (as requested by --error or --failure option) +..FFE +ERROR during LuaUnit test execution: +test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value + +Failed tests: +------------- +1) TestSomething.test2_Fail1 +test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' + +2) TestSomething.test2_Fail2 +test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' + +3) TestSomething.test3_Err1 +test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +Ran 5 tests in 0.000 seconds, 2 successes, 2 failures, 1 error, 9 non-selected +LuaUnit ABORTED (as requested by --error or --failure option) diff -Nru lua-unit-3.2/test/ref/errFailPassTextStopOnError-3.txt lua-unit-3.3/test/ref/errFailPassTextStopOnError-3.txt --- lua-unit-3.2/test/ref/errFailPassTextStopOnError-3.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextStopOnError-3.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,13 +1,13 @@ -..E -ERROR during LuaUnit test execution: -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value - -Failed tests: -------------- -1) TestAnotherThing.test2_Err1 -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -Ran 3 tests in 0.000 seconds, 2 successes, 1 error, 9 non-selected -LuaUnit ABORTED (as requested by --error or --failure option) +..E +ERROR during LuaUnit test execution: +test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value + +Failed tests: +------------- +1) TestAnotherThing.test2_Err1 +test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +Ran 3 tests in 0.000 seconds, 2 successes, 1 error, 9 non-selected +LuaUnit ABORTED (as requested by --error or --failure option) diff -Nru lua-unit-3.2/test/ref/errFailPassTextStopOnError-4.txt lua-unit-3.3/test/ref/errFailPassTextStopOnError-4.txt --- lua-unit-3.2/test/ref/errFailPassTextStopOnError-4.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextStopOnError-4.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,13 +1,13 @@ -..F -Failure during LuaUnit test execution: -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 - -Failed tests: -------------- -1) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -Ran 3 tests in 0.000 seconds, 2 successes, 1 failure, 9 non-selected -LuaUnit ABORTED (as requested by --error or --failure option) +..F +Failure during LuaUnit test execution: +test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 + +Failed tests: +------------- +1) TestSomething.test2_Fail1 +test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' + +Ran 3 tests in 0.000 seconds, 2 successes, 1 failure, 9 non-selected +LuaUnit ABORTED (as requested by --error or --failure option) diff -Nru lua-unit-3.2/test/ref/errFailPassTextVerbose-failures.txt lua-unit-3.3/test/ref/errFailPassTextVerbose-failures.txt --- lua-unit-3.2/test/ref/errFailPassTextVerbose-failures.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextVerbose-failures.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,45 +1,45 @@ -Started on 03/22/16 21:29:18 - TestAnotherThing.test1_Success1 ... Ok - TestAnotherThing.test1_Success2 ... Ok - TestAnotherThing.test3_Fail1 ... FAIL -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 - TestAnotherThing.test3_Fail2 ... FAIL -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 - TestSomething.test1_Success1 ... Ok - TestSomething.test1_Success2 ... Ok - TestSomething.test2_Fail1 ... FAIL -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 - TestSomething.test2_Fail2 ... FAIL -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 - testFuncFail1 ... FAIL -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 - testFuncSuccess1 ... Ok -========================================================= -Failed tests: -------------- -1) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -2) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -3) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -4) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -5) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 10 tests in 0.001 seconds, 5 successes, 5 failures, 5 non-selected +Started on 03/22/16 21:29:18 + TestAnotherThing.test1_Success1 ... Ok + TestAnotherThing.test1_Success2 ... Ok + TestAnotherThing.test3_Fail1 ... FAIL +test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 + TestAnotherThing.test3_Fail2 ... FAIL +test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 + TestSomething.test1_Success1 ... Ok + TestSomething.test1_Success2 ... Ok + TestSomething.test2_Fail1 ... FAIL +test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 + TestSomething.test2_Fail2 ... FAIL +test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 + testFuncFail1 ... FAIL +test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 + testFuncSuccess1 ... Ok +========================================================= +Failed tests: +------------- +1) TestAnotherThing.test3_Fail1 +test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' + +2) TestAnotherThing.test3_Fail2 +test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' + +3) TestSomething.test2_Fail1 +test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' + +4) TestSomething.test2_Fail2 +test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' + +5) testFuncFail1 +test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' + +Ran 10 tests in 0.001 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassTextVerbose-success.txt lua-unit-3.3/test/ref/errFailPassTextVerbose-success.txt --- lua-unit-3.2/test/ref/errFailPassTextVerbose-success.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextVerbose-success.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,9 +1,9 @@ -Started on 03/22/16 21:29:18 - TestAnotherThing.test1_Success1 ... Ok - TestAnotherThing.test1_Success2 ... Ok - TestSomething.test1_Success1 ... Ok - TestSomething.test1_Success2 ... Ok - testFuncSuccess1 ... Ok -========================================================= -Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected -OK +Started on 03/22/16 21:29:18 + TestAnotherThing.test1_Success1 ... Ok + TestAnotherThing.test1_Success2 ... Ok + TestSomething.test1_Success1 ... Ok + TestSomething.test1_Success2 ... Ok + testFuncSuccess1 ... Ok +========================================================= +Ran 5 tests in 0.000 seconds, 5 successes, 0 failures, 10 non-selected +OK diff -Nru lua-unit-3.2/test/ref/errFailPassTextVerbose.txt lua-unit-3.3/test/ref/errFailPassTextVerbose.txt --- lua-unit-3.2/test/ref/errFailPassTextVerbose.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassTextVerbose.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,80 +1,80 @@ -Started on 03/22/16 21:29:18 - TestAnotherThing.test1_Success1 ... Ok - TestAnotherThing.test1_Success2 ... Ok - TestAnotherThing.test2_Err1 ... ERROR -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value - TestAnotherThing.test2_Err2 ... ERROR -test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value - TestAnotherThing.test3_Fail1 ... FAIL -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 - TestAnotherThing.test3_Fail2 ... FAIL -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 - TestSomething.test1_Success1 ... Ok - TestSomething.test1_Success2 ... Ok - TestSomething.test2_Fail1 ... FAIL -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 - TestSomething.test2_Fail2 ... FAIL -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 - TestSomething.test3_Err1 ... ERROR -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value - TestSomething.test3_Err2 ... ERROR -test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value - testFuncErr1 ... ERROR -test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value - testFuncFail1 ... FAIL -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 - testFuncSuccess1 ... Ok -========================================================= -Failed tests: -------------- -1) TestAnotherThing.test2_Err1 -test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -2) TestAnotherThing.test2_Err2 -test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -3) TestAnotherThing.test3_Fail1 -test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' - -4) TestAnotherThing.test3_Fail2 -test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' - -5) TestSomething.test2_Fail1 -test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -stack traceback: - test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' - -6) TestSomething.test2_Fail2 -test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' - -7) TestSomething.test3_Err1 -test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -8) TestSomething.test3_Err2 -test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -9) testFuncErr1 -test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -stack traceback: - [C]: in function 'xpcall' - -10) testFuncFail1 -test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -stack traceback: - test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' - -Ran 15 tests in 0.001 seconds, 5 successes, 5 failures, 5 errors +Started on 03/22/16 21:29:18 + TestAnotherThing.test1_Success1 ... Ok + TestAnotherThing.test1_Success2 ... Ok + TestAnotherThing.test2_Err1 ... ERROR +test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value + TestAnotherThing.test2_Err2 ... ERROR +test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value + TestAnotherThing.test3_Fail1 ... FAIL +test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 + TestAnotherThing.test3_Fail2 ... FAIL +test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 + TestSomething.test1_Success1 ... Ok + TestSomething.test1_Success2 ... Ok + TestSomething.test2_Fail1 ... FAIL +test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 + TestSomething.test2_Fail2 ... FAIL +test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 + TestSomething.test3_Err1 ... ERROR +test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value + TestSomething.test3_Err2 ... ERROR +test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value + testFuncErr1 ... ERROR +test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value + testFuncFail1 ... FAIL +test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 + testFuncSuccess1 ... Ok +========================================================= +Failed tests: +------------- +1) TestAnotherThing.test2_Err1 +test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +2) TestAnotherThing.test2_Err2 +test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +3) TestAnotherThing.test3_Fail1 +test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:49: in function 'TestAnotherThing.test3_Fail1' + +4) TestAnotherThing.test3_Fail2 +test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:53: in function 'TestAnotherThing.test3_Fail2' + +5) TestSomething.test2_Fail1 +test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +stack traceback: + test/test_with_err_fail_pass.lua:15: in function 'TestSomething.test2_Fail1' + +6) TestSomething.test2_Fail2 +test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:19: in function 'TestSomething.test2_Fail2' + +7) TestSomething.test3_Err1 +test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +8) TestSomething.test3_Err2 +test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +9) testFuncErr1 +test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value +stack traceback: + [C]: in function 'xpcall' + +10) testFuncFail1 +test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +stack traceback: + test/test_with_err_fail_pass.lua:62: in function 'testFuncFail1' + +Ran 15 tests in 0.001 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/ref/errFailPassXmlDefault-failures.txt lua-unit-3.3/test/ref/errFailPassXmlDefault-failures.txt --- lua-unit-3.2/test/ref/errFailPassXmlDefault-failures.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlDefault-failures.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,20 +1,20 @@ -# XML output to test/ref/errFailPassXmlDefault-failures.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 10 tests in 0.003 seconds, 5 successes, 5 failures, 5 non-selected +# XML output to test/ref/errFailPassXmlDefault-failures.xml +# Started on 03/22/16 21:29:18 +# Starting class: TestAnotherThing +# Starting test: TestAnotherThing.test1_Success1 +# Starting test: TestAnotherThing.test1_Success2 +# Starting test: TestAnotherThing.test3_Fail1 +# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +# Starting test: TestAnotherThing.test3_Fail2 +# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +# Starting class: TestSomething +# Starting test: TestSomething.test1_Success1 +# Starting test: TestSomething.test1_Success2 +# Starting test: TestSomething.test2_Fail1 +# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +# Starting test: TestSomething.test2_Fail2 +# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +# Starting test: testFuncFail1 +# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +# Starting test: testFuncSuccess1 +# Ran 10 tests in 0.003 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassXmlDefault-failures.xml lua-unit-3.3/test/ref/errFailPassXmlDefault-failures.xml --- lua-unit-3.2/test/ref/errFailPassXmlDefault-failures.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlDefault-failures.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,46 +1,46 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/errFailPassXmlDefault-success.txt lua-unit-3.3/test/ref/errFailPassXmlDefault-success.txt --- lua-unit-3.2/test/ref/errFailPassXmlDefault-success.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlDefault-success.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,10 +1,10 @@ -# XML output to test/ref/errFailPassXmlDefault-success.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: testFuncSuccess1 -# Ran 5 tests in 0.001 seconds, 5 successes, 0 failures, 10 non-selected +# XML output to test/ref/errFailPassXmlDefault-success.xml +# Started on 03/22/16 21:29:18 +# Starting class: TestAnotherThing +# Starting test: TestAnotherThing.test1_Success1 +# Starting test: TestAnotherThing.test1_Success2 +# Starting class: TestSomething +# Starting test: TestSomething.test1_Success1 +# Starting test: TestSomething.test1_Success2 +# Starting test: testFuncSuccess1 +# Ran 5 tests in 0.001 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassXmlDefault-success.xml lua-unit-3.3/test/ref/errFailPassXmlDefault-success.xml --- lua-unit-3.2/test/ref/errFailPassXmlDefault-success.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlDefault-success.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,21 +1,21 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/errFailPassXmlDefault.txt lua-unit-3.3/test/ref/errFailPassXmlDefault.txt --- lua-unit-3.2/test/ref/errFailPassXmlDefault.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlDefault.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,30 +1,30 @@ -# XML output to test/ref/errFailPassXmlDefault.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test2_Err1 -# Error: test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test2_Err2 -# Error: test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: TestSomething.test3_Err1 -# Error: test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -# Starting test: TestSomething.test3_Err2 -# Error: test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -# Starting test: testFuncErr1 -# Error: test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 15 tests in 0.004 seconds, 5 successes, 5 failures, 5 errors +# XML output to test/ref/errFailPassXmlDefault.xml +# Started on 03/22/16 21:29:18 +# Starting class: TestAnotherThing +# Starting test: TestAnotherThing.test1_Success1 +# Starting test: TestAnotherThing.test1_Success2 +# Starting test: TestAnotherThing.test2_Err1 +# Error: test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value +# Starting test: TestAnotherThing.test2_Err2 +# Error: test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value +# Starting test: TestAnotherThing.test3_Fail1 +# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +# Starting test: TestAnotherThing.test3_Fail2 +# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +# Starting class: TestSomething +# Starting test: TestSomething.test1_Success1 +# Starting test: TestSomething.test1_Success2 +# Starting test: TestSomething.test2_Fail1 +# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +# Starting test: TestSomething.test2_Fail2 +# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +# Starting test: TestSomething.test3_Err1 +# Error: test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value +# Starting test: TestSomething.test3_Err2 +# Error: test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value +# Starting test: testFuncErr1 +# Error: test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value +# Starting test: testFuncFail1 +# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +# Starting test: testFuncSuccess1 +# Ran 15 tests in 0.004 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/ref/errFailPassXmlDefault.xml lua-unit-3.3/test/ref/errFailPassXmlDefault.xml --- lua-unit-3.2/test/ref/errFailPassXmlDefault.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlDefault.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,71 +1,71 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/errFailPassXmlQuiet-failures.txt lua-unit-3.3/test/ref/errFailPassXmlQuiet-failures.txt --- lua-unit-3.2/test/ref/errFailPassXmlQuiet-failures.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlQuiet-failures.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,20 +1,20 @@ -# XML output to test/ref/errFailPassXmlQuiet-failures.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 10 tests in 0.002 seconds, 5 successes, 5 failures, 5 non-selected +# XML output to test/ref/errFailPassXmlQuiet-failures.xml +# Started on 03/22/16 21:29:18 +# Starting class: TestAnotherThing +# Starting test: TestAnotherThing.test1_Success1 +# Starting test: TestAnotherThing.test1_Success2 +# Starting test: TestAnotherThing.test3_Fail1 +# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +# Starting test: TestAnotherThing.test3_Fail2 +# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +# Starting class: TestSomething +# Starting test: TestSomething.test1_Success1 +# Starting test: TestSomething.test1_Success2 +# Starting test: TestSomething.test2_Fail1 +# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +# Starting test: TestSomething.test2_Fail2 +# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +# Starting test: testFuncFail1 +# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +# Starting test: testFuncSuccess1 +# Ran 10 tests in 0.002 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassXmlQuiet-failures.xml lua-unit-3.3/test/ref/errFailPassXmlQuiet-failures.xml --- lua-unit-3.2/test/ref/errFailPassXmlQuiet-failures.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlQuiet-failures.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,46 +1,46 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/errFailPassXmlQuiet-success.txt lua-unit-3.3/test/ref/errFailPassXmlQuiet-success.txt --- lua-unit-3.2/test/ref/errFailPassXmlQuiet-success.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlQuiet-success.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,10 +1,10 @@ -# XML output to test/ref/errFailPassXmlQuiet-success.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: testFuncSuccess1 -# Ran 5 tests in 0.001 seconds, 5 successes, 0 failures, 10 non-selected +# XML output to test/ref/errFailPassXmlQuiet-success.xml +# Started on 03/22/16 21:29:18 +# Starting class: TestAnotherThing +# Starting test: TestAnotherThing.test1_Success1 +# Starting test: TestAnotherThing.test1_Success2 +# Starting class: TestSomething +# Starting test: TestSomething.test1_Success1 +# Starting test: TestSomething.test1_Success2 +# Starting test: testFuncSuccess1 +# Ran 5 tests in 0.001 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassXmlQuiet-success.xml lua-unit-3.3/test/ref/errFailPassXmlQuiet-success.xml --- lua-unit-3.2/test/ref/errFailPassXmlQuiet-success.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlQuiet-success.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,21 +1,21 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/errFailPassXmlQuiet.txt lua-unit-3.3/test/ref/errFailPassXmlQuiet.txt --- lua-unit-3.2/test/ref/errFailPassXmlQuiet.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlQuiet.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,30 +1,30 @@ -# XML output to test/ref/errFailPassXmlQuiet.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test2_Err1 -# Error: test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test2_Err2 -# Error: test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: TestSomething.test3_Err1 -# Error: test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -# Starting test: TestSomething.test3_Err2 -# Error: test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -# Starting test: testFuncErr1 -# Error: test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 15 tests in 0.003 seconds, 5 successes, 5 failures, 5 errors +# XML output to test/ref/errFailPassXmlQuiet.xml +# Started on 03/22/16 21:29:18 +# Starting class: TestAnotherThing +# Starting test: TestAnotherThing.test1_Success1 +# Starting test: TestAnotherThing.test1_Success2 +# Starting test: TestAnotherThing.test2_Err1 +# Error: test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value +# Starting test: TestAnotherThing.test2_Err2 +# Error: test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value +# Starting test: TestAnotherThing.test3_Fail1 +# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +# Starting test: TestAnotherThing.test3_Fail2 +# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +# Starting class: TestSomething +# Starting test: TestSomething.test1_Success1 +# Starting test: TestSomething.test1_Success2 +# Starting test: TestSomething.test2_Fail1 +# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +# Starting test: TestSomething.test2_Fail2 +# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +# Starting test: TestSomething.test3_Err1 +# Error: test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value +# Starting test: TestSomething.test3_Err2 +# Error: test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value +# Starting test: testFuncErr1 +# Error: test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value +# Starting test: testFuncFail1 +# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +# Starting test: testFuncSuccess1 +# Ran 15 tests in 0.003 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/ref/errFailPassXmlQuiet.xml lua-unit-3.3/test/ref/errFailPassXmlQuiet.xml --- lua-unit-3.2/test/ref/errFailPassXmlQuiet.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlQuiet.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,71 +1,71 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/errFailPassXmlVerbose-failures.txt lua-unit-3.3/test/ref/errFailPassXmlVerbose-failures.txt --- lua-unit-3.2/test/ref/errFailPassXmlVerbose-failures.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlVerbose-failures.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,20 +1,20 @@ -# XML output to test/ref/errFailPassXmlVerbose-failures.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 10 tests in 0.002 seconds, 5 successes, 5 failures, 5 non-selected +# XML output to test/ref/errFailPassXmlVerbose-failures.xml +# Started on 03/22/16 21:29:18 +# Starting class: TestAnotherThing +# Starting test: TestAnotherThing.test1_Success1 +# Starting test: TestAnotherThing.test1_Success2 +# Starting test: TestAnotherThing.test3_Fail1 +# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +# Starting test: TestAnotherThing.test3_Fail2 +# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +# Starting class: TestSomething +# Starting test: TestSomething.test1_Success1 +# Starting test: TestSomething.test1_Success2 +# Starting test: TestSomething.test2_Fail1 +# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +# Starting test: TestSomething.test2_Fail2 +# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +# Starting test: testFuncFail1 +# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +# Starting test: testFuncSuccess1 +# Ran 10 tests in 0.002 seconds, 5 successes, 5 failures, 5 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassXmlVerbose-failures.xml lua-unit-3.3/test/ref/errFailPassXmlVerbose-failures.xml --- lua-unit-3.2/test/ref/errFailPassXmlVerbose-failures.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlVerbose-failures.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,46 +1,46 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/errFailPassXmlVerbose-success.txt lua-unit-3.3/test/ref/errFailPassXmlVerbose-success.txt --- lua-unit-3.2/test/ref/errFailPassXmlVerbose-success.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlVerbose-success.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,10 +1,10 @@ -# XML output to test/ref/errFailPassXmlVerbose-success.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: testFuncSuccess1 -# Ran 5 tests in 0.001 seconds, 5 successes, 0 failures, 10 non-selected +# XML output to test/ref/errFailPassXmlVerbose-success.xml +# Started on 03/22/16 21:29:18 +# Starting class: TestAnotherThing +# Starting test: TestAnotherThing.test1_Success1 +# Starting test: TestAnotherThing.test1_Success2 +# Starting class: TestSomething +# Starting test: TestSomething.test1_Success1 +# Starting test: TestSomething.test1_Success2 +# Starting test: testFuncSuccess1 +# Ran 5 tests in 0.001 seconds, 5 successes, 0 failures, 10 non-selected diff -Nru lua-unit-3.2/test/ref/errFailPassXmlVerbose-success.xml lua-unit-3.3/test/ref/errFailPassXmlVerbose-success.xml --- lua-unit-3.2/test/ref/errFailPassXmlVerbose-success.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlVerbose-success.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,21 +1,21 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/errFailPassXmlVerbose.txt lua-unit-3.3/test/ref/errFailPassXmlVerbose.txt --- lua-unit-3.2/test/ref/errFailPassXmlVerbose.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlVerbose.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,30 +1,30 @@ -# XML output to test/ref/errFailPassXmlVerbose.xml -# Started on 03/22/16 21:29:18 -# Starting class: TestAnotherThing -# Starting test: TestAnotherThing.test1_Success1 -# Starting test: TestAnotherThing.test1_Success2 -# Starting test: TestAnotherThing.test2_Err1 -# Error: test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test2_Err2 -# Error: test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value -# Starting test: TestAnotherThing.test3_Fail1 -# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 -# Starting test: TestAnotherThing.test3_Fail2 -# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 -# Starting class: TestSomething -# Starting test: TestSomething.test1_Success1 -# Starting test: TestSomething.test1_Success2 -# Starting test: TestSomething.test2_Fail1 -# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 -# Starting test: TestSomething.test2_Fail2 -# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 -# Starting test: TestSomething.test3_Err1 -# Error: test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value -# Starting test: TestSomething.test3_Err2 -# Error: test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value -# Starting test: testFuncErr1 -# Error: test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value -# Starting test: testFuncFail1 -# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 -# Starting test: testFuncSuccess1 -# Ran 15 tests in 0.004 seconds, 5 successes, 5 failures, 5 errors +# XML output to test/ref/errFailPassXmlVerbose.xml +# Started on 03/22/16 21:29:18 +# Starting class: TestAnotherThing +# Starting test: TestAnotherThing.test1_Success1 +# Starting test: TestAnotherThing.test1_Success2 +# Starting test: TestAnotherThing.test2_Err1 +# Error: test/test_with_err_fail_pass.lua:41: attempt to perform arithmetic on a table value +# Starting test: TestAnotherThing.test2_Err2 +# Error: test/test_with_err_fail_pass.lua:45: attempt to perform arithmetic on a table value +# Starting test: TestAnotherThing.test3_Fail1 +# Failure: test/test_with_err_fail_pass.lua:49: expected: 0, actual: 2 +# Starting test: TestAnotherThing.test3_Fail2 +# Failure: test/test_with_err_fail_pass.lua:53: expected: 0, actual: 3 +# Starting class: TestSomething +# Starting test: TestSomething.test1_Success1 +# Starting test: TestSomething.test1_Success2 +# Starting test: TestSomething.test2_Fail1 +# Failure: test/test_with_err_fail_pass.lua:15: expected: 0, actual: 2 +# Starting test: TestSomething.test2_Fail2 +# Failure: test/test_with_err_fail_pass.lua:19: expected: 0, actual: 3 +# Starting test: TestSomething.test3_Err1 +# Error: test/test_with_err_fail_pass.lua:23: attempt to perform arithmetic on a table value +# Starting test: TestSomething.test3_Err2 +# Error: test/test_with_err_fail_pass.lua:27: attempt to perform arithmetic on a table value +# Starting test: testFuncErr1 +# Error: test/test_with_err_fail_pass.lua:66: attempt to perform arithmetic on a table value +# Starting test: testFuncFail1 +# Failure: test/test_with_err_fail_pass.lua:62: expected: 0, actual: 3 +# Starting test: testFuncSuccess1 +# Ran 15 tests in 0.004 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/ref/errFailPassXmlVerbose.xml lua-unit-3.3/test/ref/errFailPassXmlVerbose.xml --- lua-unit-3.2/test/ref/errFailPassXmlVerbose.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errFailPassXmlVerbose.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,71 +1,71 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/errPassFailTapQuiet.txt lua-unit-3.3/test/ref/errPassFailTapQuiet.txt --- lua-unit-3.2/test/ref/errPassFailTapQuiet.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/errPassFailTapQuiet.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,20 +1,20 @@ -1..15 -# Started on 03/22/16 21:54:40 -# Starting class: TestAnotherThing -ok 1 TestAnotherThing.test1_Success1 -ok 2 TestAnotherThing.test1_Success2 -not ok 3 TestAnotherThing.test2_Err1 -not ok 4 TestAnotherThing.test2_Err2 -not ok 5 TestAnotherThing.test3_Fail1 -not ok 6 TestAnotherThing.test3_Fail2 -# Starting class: TestSomething -ok 7 TestSomething.test1_Success1 -ok 8 TestSomething.test1_Success2 -not ok 9 TestSomething.test2_Fail1 -not ok 10 TestSomething.test2_Fail2 -not ok 11 TestSomething.test3_Err1 -not ok 12 TestSomething.test3_Err2 -not ok 13 testFuncErr1 -not ok 14 testFuncFail1 -ok 15 testFuncSuccess1 -# Ran 15 tests in 0.000 seconds, 5 successes, 5 failures, 5 errors +1..15 +# Started on 03/22/16 21:54:40 +# Starting class: TestAnotherThing +ok 1 TestAnotherThing.test1_Success1 +ok 2 TestAnotherThing.test1_Success2 +not ok 3 TestAnotherThing.test2_Err1 +not ok 4 TestAnotherThing.test2_Err2 +not ok 5 TestAnotherThing.test3_Fail1 +not ok 6 TestAnotherThing.test3_Fail2 +# Starting class: TestSomething +ok 7 TestSomething.test1_Success1 +ok 8 TestSomething.test1_Success2 +not ok 9 TestSomething.test2_Fail1 +not ok 10 TestSomething.test2_Fail2 +not ok 11 TestSomething.test3_Err1 +not ok 12 TestSomething.test3_Err2 +not ok 13 testFuncErr1 +not ok 14 testFuncFail1 +ok 15 testFuncSuccess1 +# Ran 15 tests in 0.000 seconds, 5 successes, 5 failures, 5 errors diff -Nru lua-unit-3.2/test/ref/exampleTapDefault.txt lua-unit-3.3/test/ref/exampleTapDefault.txt --- lua-unit-3.2/test/ref/exampleTapDefault.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleTapDefault.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,35 +1,35 @@ -1..15 -# Started on 01/30/16 22:19:36 -# Starting class: TestTiti -not ok 1 TestTiti.test1_withFailure - example_with_luaunit.lua:101: expected: 2, actual: 1 -not ok 2 TestTiti.test2_withFailure - example_with_luaunit.lua:110: expected: "bof" - actual: "hop" -ok 3 TestTiti.test3 -# Starting class: TestToto -not ok 4 TestToto.test1_withFailure - example_with_luaunit.lua:21: expected: 2, actual: 1 -not ok 5 TestToto.test2_withFailure - example_with_luaunit.lua:30: expected: "bof" - actual: "hop" -ok 6 TestToto.test3 -not ok 7 TestToto.test4 - example_with_luaunit.lua:43: Received the not expected value: 1 -not ok 8 TestToto.test5 - example_with_luaunit.lua:49: expected: false, actual: 1 -not ok 9 TestToto.test6 - example_with_luaunit.lua:54: expected: true, actual: false -not ok 10 TestToto.test7 - example_with_luaunit.lua:60: expected: {1, 2, three=3} - actual: {1, 2} -not ok 11 TestToto.test8a - example_with_luaunit.lua:78: Bouhouhoum error! -not ok 12 TestToto.test8b - example_with_luaunit.lua:78: Bouhouhoum error! -not ok 13 test1_withFailure - example_with_luaunit.lua:126: assertion failed! -not ok 14 test2_withFailure - example_with_luaunit.lua:132: assertion failed! -ok 15 test3 -# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors +1..15 +# Started on 02/27/17 18:21:41 +# Starting class: TestTiti +not ok 1 TestTiti.test1_withFailure +# example_with_luaunit.lua:104: expected: 2, actual: 1 +not ok 2 TestTiti.test2_withFailure +# example_with_luaunit.lua:113: expected: "bof" +# actual: "hop" +ok 3 TestTiti.test3 +# Starting class: TestToto +not ok 4 TestToto.test1_withFailure +# example_with_luaunit.lua:21: expected: 2, actual: 1 +not ok 5 TestToto.test2_withFailure +# example_with_luaunit.lua:30: expected: "bof" +# actual: "hop" +ok 6 TestToto.test3 +not ok 7 TestToto.test4 +# example_with_luaunit.lua:43: Received the not expected value: 1 +not ok 8 TestToto.test5 +# example_with_luaunit.lua:49: expected: false or nil, actual: 1 +not ok 9 TestToto.test6 +# example_with_luaunit.lua:57: expected: false, actual: nil +not ok 10 TestToto.test7 +# example_with_luaunit.lua:63: expected: {1, 2, three=3} +# actual: {1, 2} +not ok 11 TestToto.test8a +# example_with_luaunit.lua:81: Bouhouhoum error! +not ok 12 TestToto.test8b +# example_with_luaunit.lua:81: Bouhouhoum error! +not ok 13 test1_withFailure +# example_with_luaunit.lua:129: assertion failed! +not ok 14 test2_withFailure +# example_with_luaunit.lua:135: assertion failed! +ok 15 test3 +# Ran 15 tests in 0.001 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/ref/exampleTapQuiet.txt lua-unit-3.3/test/ref/exampleTapQuiet.txt --- lua-unit-3.2/test/ref/exampleTapQuiet.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleTapQuiet.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,20 +1,20 @@ -1..15 -# Started on 01/30/16 22:19:36 -# Starting class: TestTiti -not ok 1 TestTiti.test1_withFailure -not ok 2 TestTiti.test2_withFailure -ok 3 TestTiti.test3 -# Starting class: TestToto -not ok 4 TestToto.test1_withFailure -not ok 5 TestToto.test2_withFailure -ok 6 TestToto.test3 -not ok 7 TestToto.test4 -not ok 8 TestToto.test5 -not ok 9 TestToto.test6 -not ok 10 TestToto.test7 -not ok 11 TestToto.test8a -not ok 12 TestToto.test8b -not ok 13 test1_withFailure -not ok 14 test2_withFailure -ok 15 test3 -# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors +1..15 +# Started on 02/27/17 18:21:41 +# Starting class: TestTiti +not ok 1 TestTiti.test1_withFailure +not ok 2 TestTiti.test2_withFailure +ok 3 TestTiti.test3 +# Starting class: TestToto +not ok 4 TestToto.test1_withFailure +not ok 5 TestToto.test2_withFailure +ok 6 TestToto.test3 +not ok 7 TestToto.test4 +not ok 8 TestToto.test5 +not ok 9 TestToto.test6 +not ok 10 TestToto.test7 +not ok 11 TestToto.test8a +not ok 12 TestToto.test8b +not ok 13 test1_withFailure +not ok 14 test2_withFailure +ok 15 test3 +# Ran 15 tests in 0.001 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/ref/exampleTapVerbose.txt lua-unit-3.3/test/ref/exampleTapVerbose.txt --- lua-unit-3.2/test/ref/exampleTapVerbose.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleTapVerbose.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,62 +1,62 @@ -1..15 -# Started on 01/30/16 22:19:36 -# Starting class: TestTiti -not ok 1 TestTiti.test1_withFailure - example_with_luaunit.lua:101: expected: 2, actual: 1 - stack traceback: - example_with_luaunit.lua:101: in function 'TestTiti.test1_withFailure' -not ok 2 TestTiti.test2_withFailure - example_with_luaunit.lua:110: expected: "bof" - actual: "hop" - stack traceback: - example_with_luaunit.lua:110: in function 'TestTiti.test2_withFailure' -ok 3 TestTiti.test3 -# Starting class: TestToto -not ok 4 TestToto.test1_withFailure - example_with_luaunit.lua:21: expected: 2, actual: 1 - stack traceback: - example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' -not ok 5 TestToto.test2_withFailure - example_with_luaunit.lua:30: expected: "bof" - actual: "hop" - stack traceback: - example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' -ok 6 TestToto.test3 -not ok 7 TestToto.test4 - example_with_luaunit.lua:43: Received the not expected value: 1 - stack traceback: - example_with_luaunit.lua:43: in function 'TestToto.test4' -not ok 8 TestToto.test5 - example_with_luaunit.lua:49: expected: false, actual: 1 - stack traceback: - example_with_luaunit.lua:49: in function 'TestToto.test5' -not ok 9 TestToto.test6 - example_with_luaunit.lua:54: expected: true, actual: false - stack traceback: - example_with_luaunit.lua:54: in function 'TestToto.test6' -not ok 10 TestToto.test7 - example_with_luaunit.lua:60: expected: {1, 2, three=3} - actual: {1, 2} - stack traceback: - example_with_luaunit.lua:60: in function 'TestToto.test7' -not ok 11 TestToto.test8a - example_with_luaunit.lua:78: Bouhouhoum error! - stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:65: in function 'TestToto.test8a' -not ok 12 TestToto.test8b - example_with_luaunit.lua:78: Bouhouhoum error! - stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:74: in function 'funcWithFuncWithError' - example_with_luaunit.lua:70: in function 'TestToto.test8b' -not ok 13 test1_withFailure - example_with_luaunit.lua:126: assertion failed! - stack traceback: - example_with_luaunit.lua:126: in function 'test1_withFailure' -not ok 14 test2_withFailure - example_with_luaunit.lua:132: assertion failed! - stack traceback: - example_with_luaunit.lua:132: in function 'test2_withFailure' -ok 15 test3 -# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors +1..15 +# Started on 02/27/17 18:21:41 +# Starting class: TestTiti +not ok 1 TestTiti.test1_withFailure +# example_with_luaunit.lua:104: expected: 2, actual: 1 +# stack traceback: +# example_with_luaunit.lua:104: in function 'TestTiti.test1_withFailure' +not ok 2 TestTiti.test2_withFailure +# example_with_luaunit.lua:113: expected: "bof" +# actual: "hop" +# stack traceback: +# example_with_luaunit.lua:113: in function 'TestTiti.test2_withFailure' +ok 3 TestTiti.test3 +# Starting class: TestToto +not ok 4 TestToto.test1_withFailure +# example_with_luaunit.lua:21: expected: 2, actual: 1 +# stack traceback: +# example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' +not ok 5 TestToto.test2_withFailure +# example_with_luaunit.lua:30: expected: "bof" +# actual: "hop" +# stack traceback: +# example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' +ok 6 TestToto.test3 +not ok 7 TestToto.test4 +# example_with_luaunit.lua:43: Received the not expected value: 1 +# stack traceback: +# example_with_luaunit.lua:43: in function 'TestToto.test4' +not ok 8 TestToto.test5 +# example_with_luaunit.lua:49: expected: false or nil, actual: 1 +# stack traceback: +# example_with_luaunit.lua:49: in function 'TestToto.test5' +not ok 9 TestToto.test6 +# example_with_luaunit.lua:57: expected: false, actual: nil +# stack traceback: +# example_with_luaunit.lua:57: in function 'TestToto.test6' +not ok 10 TestToto.test7 +# example_with_luaunit.lua:63: expected: {1, 2, three=3} +# actual: {1, 2} +# stack traceback: +# example_with_luaunit.lua:63: in function 'TestToto.test7' +not ok 11 TestToto.test8a +# example_with_luaunit.lua:81: Bouhouhoum error! +# stack traceback: +# example_with_luaunit.lua:81: in function 'funcWithError' +# example_with_luaunit.lua:68: in function 'TestToto.test8a' +not ok 12 TestToto.test8b +# example_with_luaunit.lua:81: Bouhouhoum error! +# stack traceback: +# example_with_luaunit.lua:81: in function 'funcWithError' +# example_with_luaunit.lua:77: in function 'funcWithFuncWithError' +# example_with_luaunit.lua:73: in function 'TestToto.test8b' +not ok 13 test1_withFailure +# example_with_luaunit.lua:129: assertion failed! +# stack traceback: +# example_with_luaunit.lua:129: in function 'test1_withFailure' +not ok 14 test2_withFailure +# example_with_luaunit.lua:135: assertion failed! +# stack traceback: +# example_with_luaunit.lua:135: in function 'test2_withFailure' +ok 15 test3 +# Ran 15 tests in 0.002 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/ref/exampleTextDefault.txt lua-unit-3.3/test/ref/exampleTextDefault.txt --- lua-unit-3.2/test/ref/exampleTextDefault.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleTextDefault.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,70 +1,70 @@ -FF.FF.FFFFEEEE. -Failed tests: -------------- -1) TestTiti.test1_withFailure -example_with_luaunit.lua:101: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:101: in function 'TestTiti.test1_withFailure' - -2) TestTiti.test2_withFailure -example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:110: in function 'TestTiti.test2_withFailure' - -3) TestToto.test1_withFailure -example_with_luaunit.lua:21: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' - -4) TestToto.test2_withFailure -example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' - -5) TestToto.test4 -example_with_luaunit.lua:43: Received the not expected value: 1 -stack traceback: - example_with_luaunit.lua:43: in function 'TestToto.test4' - -6) TestToto.test5 -example_with_luaunit.lua:49: expected: false, actual: 1 -stack traceback: - example_with_luaunit.lua:49: in function 'TestToto.test5' - -7) TestToto.test6 -example_with_luaunit.lua:54: expected: true, actual: false -stack traceback: - example_with_luaunit.lua:54: in function 'TestToto.test6' - -8) TestToto.test7 -example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -stack traceback: - example_with_luaunit.lua:60: in function 'TestToto.test7' - -9) TestToto.test8a -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:65: in function 'TestToto.test8a' - -10) TestToto.test8b -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:74: in function 'funcWithFuncWithError' - example_with_luaunit.lua:70: in function 'TestToto.test8b' - -11) test1_withFailure -example_with_luaunit.lua:126: assertion failed! -stack traceback: - example_with_luaunit.lua:126: in function 'test1_withFailure' - -12) test2_withFailure -example_with_luaunit.lua:132: assertion failed! -stack traceback: - example_with_luaunit.lua:132: in function 'test2_withFailure' - -Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors +FF.FF.FFFFEEEE. +Failed tests: +------------- +1) TestTiti.test1_withFailure +example_with_luaunit.lua:104: expected: 2, actual: 1 +stack traceback: + example_with_luaunit.lua:104: in function 'TestTiti.test1_withFailure' + +2) TestTiti.test2_withFailure +example_with_luaunit.lua:113: expected: "bof" +actual: "hop" +stack traceback: + example_with_luaunit.lua:113: in function 'TestTiti.test2_withFailure' + +3) TestToto.test1_withFailure +example_with_luaunit.lua:21: expected: 2, actual: 1 +stack traceback: + example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' + +4) TestToto.test2_withFailure +example_with_luaunit.lua:30: expected: "bof" +actual: "hop" +stack traceback: + example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' + +5) TestToto.test4 +example_with_luaunit.lua:43: Received the not expected value: 1 +stack traceback: + example_with_luaunit.lua:43: in function 'TestToto.test4' + +6) TestToto.test5 +example_with_luaunit.lua:49: expected: false or nil, actual: 1 +stack traceback: + example_with_luaunit.lua:49: in function 'TestToto.test5' + +7) TestToto.test6 +example_with_luaunit.lua:57: expected: false, actual: nil +stack traceback: + example_with_luaunit.lua:57: in function 'TestToto.test6' + +8) TestToto.test7 +example_with_luaunit.lua:63: expected: {1, 2, three=3} +actual: {1, 2} +stack traceback: + example_with_luaunit.lua:63: in function 'TestToto.test7' + +9) TestToto.test8a +example_with_luaunit.lua:81: Bouhouhoum error! +stack traceback: + example_with_luaunit.lua:81: in function 'funcWithError' + example_with_luaunit.lua:68: in function 'TestToto.test8a' + +10) TestToto.test8b +example_with_luaunit.lua:81: Bouhouhoum error! +stack traceback: + example_with_luaunit.lua:81: in function 'funcWithError' + example_with_luaunit.lua:77: in function 'funcWithFuncWithError' + example_with_luaunit.lua:73: in function 'TestToto.test8b' + +11) test1_withFailure +example_with_luaunit.lua:129: assertion failed! +stack traceback: + example_with_luaunit.lua:129: in function 'test1_withFailure' + +12) test2_withFailure +example_with_luaunit.lua:135: assertion failed! +stack traceback: + example_with_luaunit.lua:135: in function 'test2_withFailure' + +Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/ref/exampleTextQuiet.txt lua-unit-3.3/test/ref/exampleTextQuiet.txt --- lua-unit-3.2/test/ref/exampleTextQuiet.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleTextQuiet.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,70 +1,70 @@ -FF.FF.FFFFEEEE. -Failed tests: -------------- -1) TestTiti.test1_withFailure -example_with_luaunit.lua:101: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:101: in function 'TestTiti.test1_withFailure' - -2) TestTiti.test2_withFailure -example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:110: in function 'TestTiti.test2_withFailure' - -3) TestToto.test1_withFailure -example_with_luaunit.lua:21: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' - -4) TestToto.test2_withFailure -example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' - -5) TestToto.test4 -example_with_luaunit.lua:43: Received the not expected value: 1 -stack traceback: - example_with_luaunit.lua:43: in function 'TestToto.test4' - -6) TestToto.test5 -example_with_luaunit.lua:49: expected: false, actual: 1 -stack traceback: - example_with_luaunit.lua:49: in function 'TestToto.test5' - -7) TestToto.test6 -example_with_luaunit.lua:54: expected: true, actual: false -stack traceback: - example_with_luaunit.lua:54: in function 'TestToto.test6' - -8) TestToto.test7 -example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -stack traceback: - example_with_luaunit.lua:60: in function 'TestToto.test7' - -9) TestToto.test8a -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:65: in function 'TestToto.test8a' - -10) TestToto.test8b -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:74: in function 'funcWithFuncWithError' - example_with_luaunit.lua:70: in function 'TestToto.test8b' - -11) test1_withFailure -example_with_luaunit.lua:126: assertion failed! -stack traceback: - example_with_luaunit.lua:126: in function 'test1_withFailure' - -12) test2_withFailure -example_with_luaunit.lua:132: assertion failed! -stack traceback: - example_with_luaunit.lua:132: in function 'test2_withFailure' - -Ran 15 tests in 0.012 seconds, 3 successes, 8 failures, 4 errors +FF.FF.FFFFEEEE. +Failed tests: +------------- +1) TestTiti.test1_withFailure +example_with_luaunit.lua:104: expected: 2, actual: 1 +stack traceback: + example_with_luaunit.lua:104: in function 'TestTiti.test1_withFailure' + +2) TestTiti.test2_withFailure +example_with_luaunit.lua:113: expected: "bof" +actual: "hop" +stack traceback: + example_with_luaunit.lua:113: in function 'TestTiti.test2_withFailure' + +3) TestToto.test1_withFailure +example_with_luaunit.lua:21: expected: 2, actual: 1 +stack traceback: + example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' + +4) TestToto.test2_withFailure +example_with_luaunit.lua:30: expected: "bof" +actual: "hop" +stack traceback: + example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' + +5) TestToto.test4 +example_with_luaunit.lua:43: Received the not expected value: 1 +stack traceback: + example_with_luaunit.lua:43: in function 'TestToto.test4' + +6) TestToto.test5 +example_with_luaunit.lua:49: expected: false or nil, actual: 1 +stack traceback: + example_with_luaunit.lua:49: in function 'TestToto.test5' + +7) TestToto.test6 +example_with_luaunit.lua:57: expected: false, actual: nil +stack traceback: + example_with_luaunit.lua:57: in function 'TestToto.test6' + +8) TestToto.test7 +example_with_luaunit.lua:63: expected: {1, 2, three=3} +actual: {1, 2} +stack traceback: + example_with_luaunit.lua:63: in function 'TestToto.test7' + +9) TestToto.test8a +example_with_luaunit.lua:81: Bouhouhoum error! +stack traceback: + example_with_luaunit.lua:81: in function 'funcWithError' + example_with_luaunit.lua:68: in function 'TestToto.test8a' + +10) TestToto.test8b +example_with_luaunit.lua:81: Bouhouhoum error! +stack traceback: + example_with_luaunit.lua:81: in function 'funcWithError' + example_with_luaunit.lua:77: in function 'funcWithFuncWithError' + example_with_luaunit.lua:73: in function 'TestToto.test8b' + +11) test1_withFailure +example_with_luaunit.lua:129: assertion failed! +stack traceback: + example_with_luaunit.lua:129: in function 'test1_withFailure' + +12) test2_withFailure +example_with_luaunit.lua:135: assertion failed! +stack traceback: + example_with_luaunit.lua:135: in function 'test2_withFailure' + +Ran 15 tests in 0.012 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/ref/exampleTextVerbose.txt lua-unit-3.3/test/ref/exampleTextVerbose.txt --- lua-unit-3.2/test/ref/exampleTextVerbose.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleTextVerbose.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,101 +1,101 @@ -Started on 01/27/16 21:35:20 - TestTiti.test1_withFailure ... FAIL -example_with_luaunit.lua:101: expected: 2, actual: 1 - TestTiti.test2_withFailure ... FAIL -example_with_luaunit.lua:110: expected: "bof" -actual: "hop" - TestTiti.test3 ... Ok - TestToto.test1_withFailure ... FAIL -example_with_luaunit.lua:21: expected: 2, actual: 1 - TestToto.test2_withFailure ... FAIL -example_with_luaunit.lua:30: expected: "bof" -actual: "hop" - TestToto.test3 ... Ok - TestToto.test4 ... FAIL -example_with_luaunit.lua:43: Received the not expected value: 1 - TestToto.test5 ... FAIL -example_with_luaunit.lua:49: expected: false, actual: 1 - TestToto.test6 ... FAIL -example_with_luaunit.lua:54: expected: true, actual: false - TestToto.test7 ... FAIL -example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} - TestToto.test8a ... ERROR -example_with_luaunit.lua:78: Bouhouhoum error! - TestToto.test8b ... ERROR -example_with_luaunit.lua:78: Bouhouhoum error! - test1_withFailure ... ERROR -example_with_luaunit.lua:126: assertion failed! - test2_withFailure ... ERROR -example_with_luaunit.lua:132: assertion failed! - test3 ... Ok -========================================================= -Failed tests: -------------- -1) TestTiti.test1_withFailure -example_with_luaunit.lua:101: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:101: in function 'TestTiti.test1_withFailure' - -2) TestTiti.test2_withFailure -example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:110: in function 'TestTiti.test2_withFailure' - -3) TestToto.test1_withFailure -example_with_luaunit.lua:21: expected: 2, actual: 1 -stack traceback: - example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' - -4) TestToto.test2_withFailure -example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -stack traceback: - example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' - -5) TestToto.test4 -example_with_luaunit.lua:43: Received the not expected value: 1 -stack traceback: - example_with_luaunit.lua:43: in function 'TestToto.test4' - -6) TestToto.test5 -example_with_luaunit.lua:49: expected: false, actual: 1 -stack traceback: - example_with_luaunit.lua:49: in function 'TestToto.test5' - -7) TestToto.test6 -example_with_luaunit.lua:54: expected: true, actual: false -stack traceback: - example_with_luaunit.lua:54: in function 'TestToto.test6' - -8) TestToto.test7 -example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -stack traceback: - example_with_luaunit.lua:60: in function 'TestToto.test7' - -9) TestToto.test8a -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:65: in function 'TestToto.test8a' - -10) TestToto.test8b -example_with_luaunit.lua:78: Bouhouhoum error! -stack traceback: - example_with_luaunit.lua:78: in function 'funcWithError' - example_with_luaunit.lua:74: in function 'funcWithFuncWithError' - example_with_luaunit.lua:70: in function 'TestToto.test8b' - -11) test1_withFailure -example_with_luaunit.lua:126: assertion failed! -stack traceback: - example_with_luaunit.lua:126: in function 'test1_withFailure' - -12) test2_withFailure -example_with_luaunit.lua:132: assertion failed! -stack traceback: - example_with_luaunit.lua:132: in function 'test2_withFailure' - -Ran 15 tests in 0.004 seconds, 3 successes, 8 failures, 4 errors +Started on 01/27/16 21:35:20 + TestTiti.test1_withFailure ... FAIL +example_with_luaunit.lua:104: expected: 2, actual: 1 + TestTiti.test2_withFailure ... FAIL +example_with_luaunit.lua:113: expected: "bof" +actual: "hop" + TestTiti.test3 ... Ok + TestToto.test1_withFailure ... FAIL +example_with_luaunit.lua:21: expected: 2, actual: 1 + TestToto.test2_withFailure ... FAIL +example_with_luaunit.lua:30: expected: "bof" +actual: "hop" + TestToto.test3 ... Ok + TestToto.test4 ... FAIL +example_with_luaunit.lua:43: Received the not expected value: 1 + TestToto.test5 ... FAIL +example_with_luaunit.lua:49: expected: false or nil, actual: 1 + TestToto.test6 ... FAIL +example_with_luaunit.lua:57: expected: false, actual: nil + TestToto.test7 ... FAIL +example_with_luaunit.lua:63: expected: {1, 2, three=3} +actual: {1, 2} + TestToto.test8a ... ERROR +example_with_luaunit.lua:81: Bouhouhoum error! + TestToto.test8b ... ERROR +example_with_luaunit.lua:81: Bouhouhoum error! + test1_withFailure ... ERROR +example_with_luaunit.lua:129: assertion failed! + test2_withFailure ... ERROR +example_with_luaunit.lua:135: assertion failed! + test3 ... Ok +========================================================= +Failed tests: +------------- +1) TestTiti.test1_withFailure +example_with_luaunit.lua:104: expected: 2, actual: 1 +stack traceback: + example_with_luaunit.lua:104: in function 'TestTiti.test1_withFailure' + +2) TestTiti.test2_withFailure +example_with_luaunit.lua:113: expected: "bof" +actual: "hop" +stack traceback: + example_with_luaunit.lua:113: in function 'TestTiti.test2_withFailure' + +3) TestToto.test1_withFailure +example_with_luaunit.lua:21: expected: 2, actual: 1 +stack traceback: + example_with_luaunit.lua:21: in function 'TestToto.test1_withFailure' + +4) TestToto.test2_withFailure +example_with_luaunit.lua:30: expected: "bof" +actual: "hop" +stack traceback: + example_with_luaunit.lua:30: in function 'TestToto.test2_withFailure' + +5) TestToto.test4 +example_with_luaunit.lua:43: Received the not expected value: 1 +stack traceback: + example_with_luaunit.lua:43: in function 'TestToto.test4' + +6) TestToto.test5 +example_with_luaunit.lua:49: expected: false or nil, actual: 1 +stack traceback: + example_with_luaunit.lua:49: in function 'TestToto.test5' + +7) TestToto.test6 +example_with_luaunit.lua:57: expected: false, actual: nil +stack traceback: + example_with_luaunit.lua:57: in function 'TestToto.test6' + +8) TestToto.test7 +example_with_luaunit.lua:63: expected: {1, 2, three=3} +actual: {1, 2} +stack traceback: + example_with_luaunit.lua:63: in function 'TestToto.test7' + +9) TestToto.test8a +example_with_luaunit.lua:81: Bouhouhoum error! +stack traceback: + example_with_luaunit.lua:81: in function 'funcWithError' + example_with_luaunit.lua:68: in function 'TestToto.test8a' + +10) TestToto.test8b +example_with_luaunit.lua:81: Bouhouhoum error! +stack traceback: + example_with_luaunit.lua:81: in function 'funcWithError' + example_with_luaunit.lua:77: in function 'funcWithFuncWithError' + example_with_luaunit.lua:73: in function 'TestToto.test8b' + +11) test1_withFailure +example_with_luaunit.lua:129: assertion failed! +stack traceback: + example_with_luaunit.lua:129: in function 'test1_withFailure' + +12) test2_withFailure +example_with_luaunit.lua:135: assertion failed! +stack traceback: + example_with_luaunit.lua:135: in function 'test2_withFailure' + +Ran 15 tests in 0.004 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/ref/exampleXmlDefault.txt lua-unit-3.3/test/ref/exampleXmlDefault.txt --- lua-unit-3.2/test/ref/exampleXmlDefault.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleXmlDefault.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,35 +1,35 @@ -# XML output to test/ref/exampleXmlDefault.xml -# Started on 01/30/16 22:19:37 -# Starting class: TestTiti -# Starting test: TestTiti.test1_withFailure -# Failure: example_with_luaunit.lua:101: expected: 2, actual: 1 -# Starting test: TestTiti.test2_withFailure -# Failure: example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -# Starting test: TestTiti.test3 -# Starting class: TestToto -# Starting test: TestToto.test1_withFailure -# Failure: example_with_luaunit.lua:21: expected: 2, actual: 1 -# Starting test: TestToto.test2_withFailure -# Failure: example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -# Starting test: TestToto.test3 -# Starting test: TestToto.test4 -# Failure: example_with_luaunit.lua:43: Received the not expected value: 1 -# Starting test: TestToto.test5 -# Failure: example_with_luaunit.lua:49: expected: false, actual: 1 -# Starting test: TestToto.test6 -# Failure: example_with_luaunit.lua:54: expected: true, actual: false -# Starting test: TestToto.test7 -# Failure: example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -# Starting test: TestToto.test8a -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: TestToto.test8b -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: test1_withFailure -# Error: example_with_luaunit.lua:126: assertion failed! -# Starting test: test2_withFailure -# Error: example_with_luaunit.lua:132: assertion failed! -# Starting test: test3 -# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors +# XML output to test/ref/exampleXmlDefault.xml +# Started on 01/30/16 22:19:37 +# Starting class: TestTiti +# Starting test: TestTiti.test1_withFailure +# Failure: example_with_luaunit.lua:104: expected: 2, actual: 1 +# Starting test: TestTiti.test2_withFailure +# Failure: example_with_luaunit.lua:113: expected: "bof" +# actual: "hop" +# Starting test: TestTiti.test3 +# Starting class: TestToto +# Starting test: TestToto.test1_withFailure +# Failure: example_with_luaunit.lua:21: expected: 2, actual: 1 +# Starting test: TestToto.test2_withFailure +# Failure: example_with_luaunit.lua:30: expected: "bof" +# actual: "hop" +# Starting test: TestToto.test3 +# Starting test: TestToto.test4 +# Failure: example_with_luaunit.lua:43: Received the not expected value: 1 +# Starting test: TestToto.test5 +# Failure: example_with_luaunit.lua:49: expected: false or nil, actual: 1 +# Starting test: TestToto.test6 +# Failure: example_with_luaunit.lua:57: expected: false, actual: nil +# Starting test: TestToto.test7 +# Failure: example_with_luaunit.lua:63: expected: {1, 2, three=3} +# actual: {1, 2} +# Starting test: TestToto.test8a +# Error: example_with_luaunit.lua:81: Bouhouhoum error! +# Starting test: TestToto.test8b +# Error: example_with_luaunit.lua:81: Bouhouhoum error! +# Starting test: test1_withFailure +# Error: example_with_luaunit.lua:129: assertion failed! +# Starting test: test2_withFailure +# Error: example_with_luaunit.lua:135: assertion failed! +# Starting test: test3 +# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/ref/exampleXmlDefault.xml lua-unit-3.3/test/ref/exampleXmlDefault.xml --- lua-unit-3.2/test/ref/exampleXmlDefault.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleXmlDefault.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,83 +1,83 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/exampleXmlQuiet.txt lua-unit-3.3/test/ref/exampleXmlQuiet.txt --- lua-unit-3.2/test/ref/exampleXmlQuiet.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleXmlQuiet.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,35 +1,35 @@ -# XML output to test/ref/exampleXmlQuiet.xml -# Started on 01/30/16 22:19:37 -# Starting class: TestTiti -# Starting test: TestTiti.test1_withFailure -# Failure: example_with_luaunit.lua:101: expected: 2, actual: 1 -# Starting test: TestTiti.test2_withFailure -# Failure: example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -# Starting test: TestTiti.test3 -# Starting class: TestToto -# Starting test: TestToto.test1_withFailure -# Failure: example_with_luaunit.lua:21: expected: 2, actual: 1 -# Starting test: TestToto.test2_withFailure -# Failure: example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -# Starting test: TestToto.test3 -# Starting test: TestToto.test4 -# Failure: example_with_luaunit.lua:43: Received the not expected value: 1 -# Starting test: TestToto.test5 -# Failure: example_with_luaunit.lua:49: expected: false, actual: 1 -# Starting test: TestToto.test6 -# Failure: example_with_luaunit.lua:54: expected: true, actual: false -# Starting test: TestToto.test7 -# Failure: example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -# Starting test: TestToto.test8a -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: TestToto.test8b -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: test1_withFailure -# Error: example_with_luaunit.lua:126: assertion failed! -# Starting test: test2_withFailure -# Error: example_with_luaunit.lua:132: assertion failed! -# Starting test: test3 -# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors +# XML output to test/ref/exampleXmlQuiet.xml +# Started on 01/30/16 22:19:37 +# Starting class: TestTiti +# Starting test: TestTiti.test1_withFailure +# Failure: example_with_luaunit.lua:104: expected: 2, actual: 1 +# Starting test: TestTiti.test2_withFailure +# Failure: example_with_luaunit.lua:113: expected: "bof" +# actual: "hop" +# Starting test: TestTiti.test3 +# Starting class: TestToto +# Starting test: TestToto.test1_withFailure +# Failure: example_with_luaunit.lua:21: expected: 2, actual: 1 +# Starting test: TestToto.test2_withFailure +# Failure: example_with_luaunit.lua:30: expected: "bof" +# actual: "hop" +# Starting test: TestToto.test3 +# Starting test: TestToto.test4 +# Failure: example_with_luaunit.lua:43: Received the not expected value: 1 +# Starting test: TestToto.test5 +# Failure: example_with_luaunit.lua:49: expected: false or nil, actual: 1 +# Starting test: TestToto.test6 +# Failure: example_with_luaunit.lua:57: expected: false, actual: nil +# Starting test: TestToto.test7 +# Failure: example_with_luaunit.lua:63: expected: {1, 2, three=3} +# actual: {1, 2} +# Starting test: TestToto.test8a +# Error: example_with_luaunit.lua:81: Bouhouhoum error! +# Starting test: TestToto.test8b +# Error: example_with_luaunit.lua:81: Bouhouhoum error! +# Starting test: test1_withFailure +# Error: example_with_luaunit.lua:129: assertion failed! +# Starting test: test2_withFailure +# Error: example_with_luaunit.lua:135: assertion failed! +# Starting test: test3 +# Ran 15 tests in 0.000 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/ref/exampleXmlQuiet.xml lua-unit-3.3/test/ref/exampleXmlQuiet.xml --- lua-unit-3.2/test/ref/exampleXmlQuiet.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleXmlQuiet.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,83 +1,83 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/exampleXmlVerbose.txt lua-unit-3.3/test/ref/exampleXmlVerbose.txt --- lua-unit-3.2/test/ref/exampleXmlVerbose.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleXmlVerbose.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,35 +1,35 @@ -# XML output to test/ref/exampleXmlVerbose.xml -# Started on 01/30/16 22:19:37 -# Starting class: TestTiti -# Starting test: TestTiti.test1_withFailure -# Failure: example_with_luaunit.lua:101: expected: 2, actual: 1 -# Starting test: TestTiti.test2_withFailure -# Failure: example_with_luaunit.lua:110: expected: "bof" -actual: "hop" -# Starting test: TestTiti.test3 -# Starting class: TestToto -# Starting test: TestToto.test1_withFailure -# Failure: example_with_luaunit.lua:21: expected: 2, actual: 1 -# Starting test: TestToto.test2_withFailure -# Failure: example_with_luaunit.lua:30: expected: "bof" -actual: "hop" -# Starting test: TestToto.test3 -# Starting test: TestToto.test4 -# Failure: example_with_luaunit.lua:43: Received the not expected value: 1 -# Starting test: TestToto.test5 -# Failure: example_with_luaunit.lua:49: expected: false, actual: 1 -# Starting test: TestToto.test6 -# Failure: example_with_luaunit.lua:54: expected: true, actual: false -# Starting test: TestToto.test7 -# Failure: example_with_luaunit.lua:60: expected: {1, 2, three=3} -actual: {1, 2} -# Starting test: TestToto.test8a -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: TestToto.test8b -# Error: example_with_luaunit.lua:78: Bouhouhoum error! -# Starting test: test1_withFailure -# Error: example_with_luaunit.lua:126: assertion failed! -# Starting test: test2_withFailure -# Error: example_with_luaunit.lua:132: assertion failed! -# Starting test: test3 -# Ran 15 tests in 0.015 seconds, 3 successes, 8 failures, 4 errors +# XML output to test/ref/exampleXmlVerbose.xml +# Started on 01/30/16 22:19:37 +# Starting class: TestTiti +# Starting test: TestTiti.test1_withFailure +# Failure: example_with_luaunit.lua:104: expected: 2, actual: 1 +# Starting test: TestTiti.test2_withFailure +# Failure: example_with_luaunit.lua:113: expected: "bof" +# actual: "hop" +# Starting test: TestTiti.test3 +# Starting class: TestToto +# Starting test: TestToto.test1_withFailure +# Failure: example_with_luaunit.lua:21: expected: 2, actual: 1 +# Starting test: TestToto.test2_withFailure +# Failure: example_with_luaunit.lua:30: expected: "bof" +# actual: "hop" +# Starting test: TestToto.test3 +# Starting test: TestToto.test4 +# Failure: example_with_luaunit.lua:43: Received the not expected value: 1 +# Starting test: TestToto.test5 +# Failure: example_with_luaunit.lua:49: expected: false or nil, actual: 1 +# Starting test: TestToto.test6 +# Failure: example_with_luaunit.lua:57: expected: false, actual: nil +# Starting test: TestToto.test7 +# Failure: example_with_luaunit.lua:63: expected: {1, 2, three=3} +# actual: {1, 2} +# Starting test: TestToto.test8a +# Error: example_with_luaunit.lua:81: Bouhouhoum error! +# Starting test: TestToto.test8b +# Error: example_with_luaunit.lua:81: Bouhouhoum error! +# Starting test: test1_withFailure +# Error: example_with_luaunit.lua:129: assertion failed! +# Starting test: test2_withFailure +# Error: example_with_luaunit.lua:135: assertion failed! +# Starting test: test3 +# Ran 15 tests in 0.015 seconds, 3 successes, 8 failures, 4 errors diff -Nru lua-unit-3.2/test/ref/exampleXmlVerbose.xml lua-unit-3.3/test/ref/exampleXmlVerbose.xml --- lua-unit-3.2/test/ref/exampleXmlVerbose.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/exampleXmlVerbose.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,83 +1,83 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/some_lists_comparisons.txt lua-unit-3.3/test/ref/some_lists_comparisons.txt --- lua-unit-3.2/test/ref/some_lists_comparisons.txt 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/test/ref/some_lists_comparisons.txt 2018-04-20 12:34:12.000000000 +0000 @@ -0,0 +1,844 @@ +Started on 11/08/16 21:28:53 + TestListCompare.test1 ... FAIL +test/some_lists_comparisons.lua:22: expected: +{ + 121221, + 122211, + 121221, + 122211, + 121221, + 122212, + 121212, + 122112, + 121221, + 121212, + 122121 +} +actual: +{ + 121221, + 122211, + 121221, + 122211, + 121221, + 122212, + 121212, + 122112, + 122121, + 121212, + 122121 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 9 +* lists A and B are equal again from index 10 +* Common parts: + = A[1], B[1]: 121221 + = A[2], B[2]: 122211 + = A[3], B[3]: 121221 + = A[4], B[4]: 122211 + = A[5], B[5]: 121221 + = A[6], B[6]: 122212 + = A[7], B[7]: 121212 + = A[8], B[8]: 122112 +* Differing parts: + - A[9]: 122121 + + B[9]: 121221 +* Common parts at the end of the lists + = A[10], B[10]: 121212 + = A[11], B[11]: 122121 + TestListCompare.test1b ... FAIL +test/some_lists_comparisons.lua:28: expected: +{ + 121221, + 122211, + 121221, + 122112, + 121212, + 121122, + 121212, + 122122, + 121212, + 122112, + 121212 +} +actual: +{ + 121221, + 122211, + 121221, + 122112, + 121212, + 121122, + 121212, + 122122, + 121212, + 122112, + 122112 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 11 +* Common parts: + = A[1], B[1]: 121221 + = A[2], B[2]: 122211 + = A[3], B[3]: 121221 + = A[4], B[4]: 122112 + = A[5], B[5]: 121212 + = A[6], B[6]: 121122 + = A[7], B[7]: 121212 + = A[8], B[8]: 122122 + = A[9], B[9]: 121212 + = A[10], B[10]: 122112 +* Differing parts: + - A[11]: 122112 + + B[11]: 121212 + TestListCompare.test1c ... FAIL +test/some_lists_comparisons.lua:34: expected: +{ + 121212, + 122121, + 111212, + 122121, + 122121, + 121212, + 121121, + 121212, + 121221, + 122212, + 112121 +} +actual: +{ + 122112, + 122121, + 111212, + 122121, + 122121, + 121212, + 121121, + 121212, + 121221, + 122212, + 112121 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 1 +* lists A and B are equal again from index 2 +* Differing parts: + - A[1]: 122112 + + B[1]: 121212 +* Common parts at the end of the lists + = A[2], B[2]: 122121 + = A[3], B[3]: 111212 + = A[4], B[4]: 122121 + = A[5], B[5]: 122121 + = A[6], B[6]: 121212 + = A[7], B[7]: 121121 + = A[8], B[8]: 121212 + = A[9], B[9]: 121221 + = A[10], B[10]: 122212 + = A[11], B[11]: 112121 + TestListCompare.test2 ... FAIL +test/some_lists_comparisons.lua:43: expected: {1, 2, 3, 4, 5, 6, 8, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 7 +* lists A and B are equal again from index 9 +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Differing parts: + - A[7]: 7 + + B[7]: 8 + - A[8]: 8 + + B[8]: 7 +* Common parts at the end of the lists + = A[9], B[9]: 9 + = A[10], B[10]: 10 + = A[11], B[11]: 11 + = A[12], B[12]: 12 + = A[13], B[13]: 13 + = A[14], B[14]: 14 + = A[15], B[15]: 15 + = A[16], B[16]: 16 + = A[17], B[17]: 17 + = A[18], B[18]: 18 + = A[19], B[19]: 19 + = A[20], B[20]: 20 + TestListCompare.test3 ... FAIL +test/some_lists_comparisons.lua:57: expected: {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* list sizes differ: list A (actual) has 20 items, list B (expected) has 19 items +* lists A and B start differing at index 7 +* lists A and B are equal again from index 8 for A, 7 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Present only in one list: + - A[7]: 7 +* Common parts at the end of the lists + = A[8], B[7]: 8 + = A[9], B[8]: 9 + = A[10], B[9]: 10 + = A[11], B[10]: 11 + = A[12], B[11]: 12 + = A[13], B[12]: 13 + = A[14], B[13]: 14 + = A[15], B[14]: 15 + = A[16], B[15]: 16 + = A[17], B[16]: 17 + = A[18], B[17]: 18 + = A[19], B[18]: 19 + = A[20], B[19]: 20 + TestListCompare.test4 ... FAIL +test/some_lists_comparisons.lua:74: expected: {1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* list sizes differ: list A (actual) has 20 items, list B (expected) has 17 items +* lists A and B start differing at index 7 +* lists A and B are equal again from index 10 for A, 7 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Present only in one list: + - A[7]: 7 + - A[8]: 8 + - A[9]: 9 +* Common parts at the end of the lists + = A[10], B[7]: 10 + = A[11], B[8]: 11 + = A[12], B[9]: 12 + = A[13], B[10]: 13 + = A[14], B[11]: 14 + = A[15], B[12]: 15 + = A[16], B[13]: 16 + = A[17], B[14]: 17 + = A[18], B[15]: 18 + = A[19], B[16]: 19 + = A[20], B[17]: 20 + TestListCompare.test5a ... FAIL +test/some_lists_comparisons.lua:98: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* list sizes differ: list A (expected) has 17 items, list B (actual) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equal again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 + TestListCompare.test5b ... FAIL +test/some_lists_comparisons.lua:103: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* list sizes differ: list A (actual) has 17 items, list B (expected) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equal again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 + TestListCompare.test5c ... FAIL +test/some_lists_comparisons.lua:109: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* list sizes differ: list A (actual) has 17 items, list B (expected) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equal again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 + TestListCompare.test6 ... FAIL +test/some_lists_comparisons.lua:117: expected: +{ + "aaa", + "bbb", + "ccc", + function: 00E70160, + 1.1, + 2.1, + 8=true, + 9=false, + 10=thread: 00E35480, + 11=thread: 00E35480, + 12=thread: 00E35480 +} +actual: +{ + "aaa", + "bbb", + "ccc", + function: 00E70160, + 1.1, + 2.1, + 8=false, + 9=false, + 10=thread: 00E35480, + 11=thread: 00E35480, + 12=thread: 00E35480 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 8 +* lists A and B are equal again from index 9 +* Common parts: + = A[1], B[1]: "aaa" + = A[2], B[2]: "bbb" + = A[3], B[3]: "ccc" + = A[4], B[4]: function: 00E70160 + = A[5], B[5]: 1.1 + = A[6], B[6]: 2.1 + = A[7], B[7]: nil +* Differing parts: + - A[8]: false + + B[8]: true +* Common parts at the end of the lists + = A[9], B[9]: false + = A[10], B[10]: thread: 00E35480 + = A[11], B[11]: thread: 00E35480 + = A[12], B[12]: thread: 00E35480 + TestListCompare.test7 ... FAIL +test/some_lists_comparisons.lua:123: expected: {{1, 2, 3}, {1, 2}, {{1}, {2}}, {"aa", "cc"}, 1, 2, 1.33, #Inf, {a=1}, {}} +actual: {{1, 2, 3}, {1, 2}, {{2}, {2}}, {"aa", "bb"}, 1, 2, 1.33, #Inf, {a=1}, {}} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 3 +* lists A and B are equal again from index 5 +* Common parts: + = A[1], B[1]: {1, 2, 3} + = A[2], B[2]: {1, 2} +* Differing parts: + - A[3]: {{2}, {2}} + + B[3]: {{1}, {2}} + - A[4]: {"aa", "bb"} + + B[4]: {"aa", "cc"} +* Common parts at the end of the lists + = A[5], B[5]: 1 + = A[6], B[6]: 2 + = A[7], B[7]: 1.33 + = A[8], B[8]: #Inf + = A[9], B[9]: {a=1} + = A[10], B[10]: {} +========================================================= +Failed tests: +------------- +1) TestListCompare.test1 +test/some_lists_comparisons.lua:22: expected: +{ + 121221, + 122211, + 121221, + 122211, + 121221, + 122212, + 121212, + 122112, + 121221, + 121212, + 122121 +} +actual: +{ + 121221, + 122211, + 121221, + 122211, + 121221, + 122212, + 121212, + 122112, + 122121, + 121212, + 122121 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 9 +* lists A and B are equal again from index 10 +* Common parts: + = A[1], B[1]: 121221 + = A[2], B[2]: 122211 + = A[3], B[3]: 121221 + = A[4], B[4]: 122211 + = A[5], B[5]: 121221 + = A[6], B[6]: 122212 + = A[7], B[7]: 121212 + = A[8], B[8]: 122112 +* Differing parts: + - A[9]: 122121 + + B[9]: 121221 +* Common parts at the end of the lists + = A[10], B[10]: 121212 + = A[11], B[11]: 122121 +stack traceback: + test/some_lists_comparisons.lua:22: in function 'TestListCompare.test1' + +2) TestListCompare.test1b +test/some_lists_comparisons.lua:28: expected: +{ + 121221, + 122211, + 121221, + 122112, + 121212, + 121122, + 121212, + 122122, + 121212, + 122112, + 121212 +} +actual: +{ + 121221, + 122211, + 121221, + 122112, + 121212, + 121122, + 121212, + 122122, + 121212, + 122112, + 122112 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 11 +* Common parts: + = A[1], B[1]: 121221 + = A[2], B[2]: 122211 + = A[3], B[3]: 121221 + = A[4], B[4]: 122112 + = A[5], B[5]: 121212 + = A[6], B[6]: 121122 + = A[7], B[7]: 121212 + = A[8], B[8]: 122122 + = A[9], B[9]: 121212 + = A[10], B[10]: 122112 +* Differing parts: + - A[11]: 122112 + + B[11]: 121212 +stack traceback: + test/some_lists_comparisons.lua:28: in function 'TestListCompare.test1b' + +3) TestListCompare.test1c +test/some_lists_comparisons.lua:34: expected: +{ + 121212, + 122121, + 111212, + 122121, + 122121, + 121212, + 121121, + 121212, + 121221, + 122212, + 112121 +} +actual: +{ + 122112, + 122121, + 111212, + 122121, + 122121, + 121212, + 121121, + 121212, + 121221, + 122212, + 112121 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 1 +* lists A and B are equal again from index 2 +* Differing parts: + - A[1]: 122112 + + B[1]: 121212 +* Common parts at the end of the lists + = A[2], B[2]: 122121 + = A[3], B[3]: 111212 + = A[4], B[4]: 122121 + = A[5], B[5]: 122121 + = A[6], B[6]: 121212 + = A[7], B[7]: 121121 + = A[8], B[8]: 121212 + = A[9], B[9]: 121221 + = A[10], B[10]: 122212 + = A[11], B[11]: 112121 +stack traceback: + test/some_lists_comparisons.lua:34: in function 'TestListCompare.test1c' + +4) TestListCompare.test2 +test/some_lists_comparisons.lua:43: expected: {1, 2, 3, 4, 5, 6, 8, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 7 +* lists A and B are equal again from index 9 +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Differing parts: + - A[7]: 7 + + B[7]: 8 + - A[8]: 8 + + B[8]: 7 +* Common parts at the end of the lists + = A[9], B[9]: 9 + = A[10], B[10]: 10 + = A[11], B[11]: 11 + = A[12], B[12]: 12 + = A[13], B[13]: 13 + = A[14], B[14]: 14 + = A[15], B[15]: 15 + = A[16], B[16]: 16 + = A[17], B[17]: 17 + = A[18], B[18]: 18 + = A[19], B[19]: 19 + = A[20], B[20]: 20 +stack traceback: + test/some_lists_comparisons.lua:43: in function 'TestListCompare.test2' + +5) TestListCompare.test3 +test/some_lists_comparisons.lua:57: expected: {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* list sizes differ: list A (actual) has 20 items, list B (expected) has 19 items +* lists A and B start differing at index 7 +* lists A and B are equal again from index 8 for A, 7 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Present only in one list: + - A[7]: 7 +* Common parts at the end of the lists + = A[8], B[7]: 8 + = A[9], B[8]: 9 + = A[10], B[9]: 10 + = A[11], B[10]: 11 + = A[12], B[11]: 12 + = A[13], B[12]: 13 + = A[14], B[13]: 14 + = A[15], B[14]: 15 + = A[16], B[15]: 16 + = A[17], B[16]: 17 + = A[18], B[17]: 18 + = A[19], B[18]: 19 + = A[20], B[19]: 20 +stack traceback: + test/some_lists_comparisons.lua:57: in function 'TestListCompare.test3' + +6) TestListCompare.test4 +test/some_lists_comparisons.lua:74: expected: {1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* list sizes differ: list A (actual) has 20 items, list B (expected) has 17 items +* lists A and B start differing at index 7 +* lists A and B are equal again from index 10 for A, 7 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 + = A[5], B[5]: 5 + = A[6], B[6]: 6 +* Present only in one list: + - A[7]: 7 + - A[8]: 8 + - A[9]: 9 +* Common parts at the end of the lists + = A[10], B[7]: 10 + = A[11], B[8]: 11 + = A[12], B[9]: 12 + = A[13], B[10]: 13 + = A[14], B[11]: 14 + = A[15], B[12]: 15 + = A[16], B[13]: 16 + = A[17], B[14]: 17 + = A[18], B[15]: 18 + = A[19], B[16]: 19 + = A[20], B[17]: 20 +stack traceback: + test/some_lists_comparisons.lua:74: in function 'TestListCompare.test4' + +7) TestListCompare.test5a +test/some_lists_comparisons.lua:98: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* list sizes differ: list A (expected) has 17 items, list B (actual) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equal again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 +stack traceback: + test/some_lists_comparisons.lua:98: in function 'TestListCompare.test5a' + +8) TestListCompare.test5b +test/some_lists_comparisons.lua:103: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* list sizes differ: list A (actual) has 17 items, list B (expected) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equal again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 +stack traceback: + test/some_lists_comparisons.lua:103: in function 'TestListCompare.test5b' + +9) TestListCompare.test5c +test/some_lists_comparisons.lua:109: expected: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +actual: {1, 2, 3, 4, 6, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20} +List difference analysis: +* list sizes differ: list A (actual) has 17 items, list B (expected) has 20 items +* lists A and B start differing at index 5 +* lists A and B are equal again from index 7 for A, 10 for B +* Common parts: + = A[1], B[1]: 1 + = A[2], B[2]: 2 + = A[3], B[3]: 3 + = A[4], B[4]: 4 +* Differing parts: + - A[5]: 6 + + B[5]: 5 + - A[6]: 5 + + B[6]: 6 +* Present only in one list: + + B[7]: 7 + + B[8]: 8 + + B[9]: 9 +* Common parts at the end of the lists + = A[7], B[10]: 10 + = A[8], B[11]: 11 + = A[9], B[12]: 12 + = A[10], B[13]: 13 + = A[11], B[14]: 14 + = A[12], B[15]: 15 + = A[13], B[16]: 16 + = A[14], B[17]: 17 + = A[15], B[18]: 18 + = A[16], B[19]: 19 + = A[17], B[20]: 20 +stack traceback: + test/some_lists_comparisons.lua:109: in function 'TestListCompare.test5c' + +10) TestListCompare.test6 +test/some_lists_comparisons.lua:117: expected: +{ + "aaa", + "bbb", + "ccc", + function: 00E70160, + 1.1, + 2.1, + 8=true, + 9=false, + 10=thread: 00E35480, + 11=thread: 00E35480, + 12=thread: 00E35480 +} +actual: +{ + "aaa", + "bbb", + "ccc", + function: 00E70160, + 1.1, + 2.1, + 8=false, + 9=false, + 10=thread: 00E35480, + 11=thread: 00E35480, + 12=thread: 00E35480 +} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 8 +* lists A and B are equal again from index 9 +* Common parts: + = A[1], B[1]: "aaa" + = A[2], B[2]: "bbb" + = A[3], B[3]: "ccc" + = A[4], B[4]: function: 00E70160 + = A[5], B[5]: 1.1 + = A[6], B[6]: 2.1 + = A[7], B[7]: nil +* Differing parts: + - A[8]: false + + B[8]: true +* Common parts at the end of the lists + = A[9], B[9]: false + = A[10], B[10]: thread: 00E35480 + = A[11], B[11]: thread: 00E35480 + = A[12], B[12]: thread: 00E35480 +stack traceback: + test/some_lists_comparisons.lua:117: in function 'TestListCompare.test6' + +11) TestListCompare.test7 +test/some_lists_comparisons.lua:123: expected: {{1, 2, 3}, {1, 2}, {{1}, {2}}, {"aa", "cc"}, 1, 2, 1.33, #Inf, {a=1}, {}} +actual: {{1, 2, 3}, {1, 2}, {{2}, {2}}, {"aa", "bb"}, 1, 2, 1.33, #Inf, {a=1}, {}} +List difference analysis: +* lists A (actual) and B (expected) have the same size +* lists A and B start differing at index 3 +* lists A and B are equal again from index 5 +* Common parts: + = A[1], B[1]: {1, 2, 3} + = A[2], B[2]: {1, 2} +* Differing parts: + - A[3]: {{2}, {2}} + + B[3]: {{1}, {2}} + - A[4]: {"aa", "bb"} + + B[4]: {"aa", "cc"} +* Common parts at the end of the lists + = A[5], B[5]: 1 + = A[6], B[6]: 2 + = A[7], B[7]: 1.33 + = A[8], B[8]: #Inf + = A[9], B[9]: {a=1} + = A[10], B[10]: {} +stack traceback: + test/some_lists_comparisons.lua:123: in function 'TestListCompare.test7' + +Ran 11 tests in 0.005 seconds, 0 successes, 11 failures diff -Nru lua-unit-3.2/test/ref/testWithXmlDefault.txt lua-unit-3.3/test/ref/testWithXmlDefault.txt --- lua-unit-3.2/test/ref/testWithXmlDefault.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/testWithXmlDefault.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,11 +1,11 @@ -# XML output to test/ref/testWithXmlDefault.xml -# Started on 01/01/16 22:13:02 -# Starting class: TestFailuresWithXml -# Starting test: TestFailuresWithXml.test_failure_with_cdata_xml -# Failure: test/test_with_xml.lua:13: expected: "got it" -actual: "cdata does not like ]]>" -# Starting test: TestFailuresWithXml.test_failure_with_simple_xml -# Failure: test/test_with_xml.lua:9: expected: "got it" -actual: 'ti"ti' -# Starting test: TestThatLastsALongTime -# Ran 3 tests in 1.101 seconds, 1 success, 2 failures +# XML output to test/ref/testWithXmlDefault.xml +# Started on 01/01/16 22:13:02 +# Starting class: TestFailuresWithXml +# Starting test: TestFailuresWithXml.test_failure_with_cdata_xml +# Failure: test/test_with_xml.lua:13: expected: "got it" +# actual: "cdata does not like ]]>" +# Starting test: TestFailuresWithXml.test_failure_with_simple_xml +# Failure: test/test_with_xml.lua:9: expected: "got it" +# actual: 'ti"ti' +# Starting test: TestThatLastsALongTime +# Ran 3 tests in 1.101 seconds, 1 success, 2 failures diff -Nru lua-unit-3.2/test/ref/testWithXmlDefault.xml lua-unit-3.3/test/ref/testWithXmlDefault.xml --- lua-unit-3.2/test/ref/testWithXmlDefault.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/testWithXmlDefault.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/testWithXmlQuiet.txt lua-unit-3.3/test/ref/testWithXmlQuiet.txt --- lua-unit-3.2/test/ref/testWithXmlQuiet.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/testWithXmlQuiet.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,11 +1,11 @@ -# XML output to test/ref/testWithXmlQuiet.xml -# Started on 01/01/16 22:13:04 -# Starting class: TestFailuresWithXml -# Starting test: TestFailuresWithXml.test_failure_with_cdata_xml -# Failure: test/test_with_xml.lua:13: expected: "got it" -actual: "cdata does not like ]]>" -# Starting test: TestFailuresWithXml.test_failure_with_simple_xml -# Failure: test/test_with_xml.lua:9: expected: "got it" -actual: 'ti"ti' -# Starting test: TestThatLastsALongTime -# Ran 3 tests in 1.102 seconds, 1 success, 2 failures +# XML output to test/ref/testWithXmlQuiet.xml +# Started on 01/01/16 22:13:04 +# Starting class: TestFailuresWithXml +# Starting test: TestFailuresWithXml.test_failure_with_cdata_xml +# Failure: test/test_with_xml.lua:13: expected: "got it" +# actual: "cdata does not like ]]>" +# Starting test: TestFailuresWithXml.test_failure_with_simple_xml +# Failure: test/test_with_xml.lua:9: expected: "got it" +# actual: 'ti"ti' +# Starting test: TestThatLastsALongTime +# Ran 3 tests in 1.102 seconds, 1 success, 2 failures diff -Nru lua-unit-3.2/test/ref/testWithXmlQuiet.xml lua-unit-3.3/test/ref/testWithXmlQuiet.xml --- lua-unit-3.2/test/ref/testWithXmlQuiet.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/testWithXmlQuiet.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/ref/testWithXmlVerbose.txt lua-unit-3.3/test/ref/testWithXmlVerbose.txt --- lua-unit-3.2/test/ref/testWithXmlVerbose.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/testWithXmlVerbose.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,11 +1,11 @@ -# XML output to test/ref/testWithXmlVerbose.xml -# Started on 01/01/16 22:13:03 -# Starting class: TestFailuresWithXml -# Starting test: TestFailuresWithXml.test_failure_with_cdata_xml -# Failure: test/test_with_xml.lua:13: expected: "got it" -actual: "cdata does not like ]]>" -# Starting test: TestFailuresWithXml.test_failure_with_simple_xml -# Failure: test/test_with_xml.lua:9: expected: "got it" -actual: 'ti"ti' -# Starting test: TestThatLastsALongTime -# Ran 3 tests in 1.102 seconds, 1 success, 2 failures +# XML output to test/ref/testWithXmlVerbose.xml +# Started on 01/01/16 22:13:03 +# Starting class: TestFailuresWithXml +# Starting test: TestFailuresWithXml.test_failure_with_cdata_xml +# Failure: test/test_with_xml.lua:13: expected: "got it" +# actual: "cdata does not like ]]>" +# Starting test: TestFailuresWithXml.test_failure_with_simple_xml +# Failure: test/test_with_xml.lua:9: expected: "got it" +# actual: 'ti"ti' +# Starting test: TestThatLastsALongTime +# Ran 3 tests in 1.102 seconds, 1 success, 2 failures diff -Nru lua-unit-3.2/test/ref/testWithXmlVerbose.xml lua-unit-3.3/test/ref/testWithXmlVerbose.xml --- lua-unit-3.2/test/ref/testWithXmlVerbose.xml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/ref/testWithXmlVerbose.xml 2018-04-20 12:34:12.000000000 +0000 @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/test/some_lists_comparisons.lua lua-unit-3.3/test/some_lists_comparisons.lua --- lua-unit-3.2/test/some_lists_comparisons.lua 1970-01-01 00:00:00.000000000 +0000 +++ lua-unit-3.3/test/some_lists_comparisons.lua 2018-04-20 12:34:12.000000000 +0000 @@ -0,0 +1,147 @@ + +local lu = require('luaunit') + +local function range(start, stop) + -- return list of { start ... stop } + local i + local ret = {} + i=start + while i <= stop do + table.insert(ret, i) + i = i + 1 + end + return ret +end + + +TestListCompare = {} + + function TestListCompare:test1() + local A = { 121221, 122211, 121221, 122211, 121221, 122212, 121212, 122112, 122121, 121212, 122121 } + local B = { 121221, 122211, 121221, 122211, 121221, 122212, 121212, 122112, 121221, 121212, 122121 } + lu.assertEquals( A, B ) + end + + function TestListCompare:test1b() + local A = { 121221, 122211, 121221, 122112, 121212, 121122, 121212, 122122, 121212, 122112, 122112 } + local B = { 121221, 122211, 121221, 122112, 121212, 121122, 121212, 122122, 121212, 122112, 121212 } + lu.assertEquals( A, B ) + end + + function TestListCompare:test1c() + local A = { 122112, 122121, 111212, 122121, 122121, 121212, 121121, 121212, 121221, 122212, 112121 } + local B = { 121212, 122121, 111212, 122121, 122121, 121212, 121121, 121212, 121221, 122212, 112121 } + lu.assertEquals( A, B ) + end + + + -- long list of numbers, same size, swapped values + function TestListCompare:test2() + local x=7 + local A, B = range(1,20), range(1,20) + B[x], B[x+1] = B[x+1], B[x] + lu.assertEquals( A, B ) + end + + -- long list of numbers, one hole + function TestListCompare:test3() + local x=7 + local A, B = range(1,20), {} + local i=1 + while i <= #A do + if i ~= x then + table.insert( B, A[i] ) + end + i = i + 1 + end + lu.assertEquals( A, B ) + end + + + -- long list of numbers, one bigger hole + function TestListCompare:test4() + local x=7 + local x2=8 + local x3=9 + local A, B = range(1,20), {} + local i=1 + while i <= #A do + if i ~= x and i ~= x2 and i ~= x3 then + table.insert( B, A[i] ) + end + i = i + 1 + end + lu.assertEquals( A, B ) + end + + -- long list, difference + big hole + function TestListCompare:sub_test5() + local x=7 + local x2=8 + local x3=9 + local A, B = range(1,20), {} + local i=1 + while i <= #A do + if i ~= x and i ~= x2 and i ~= x3 then + table.insert( B, A[i] ) + end + i = i + 1 + end + x = 5 + B[x], B[x+1] = B[x+1], B[x] + return A, B + end + + function TestListCompare:test5a() + local A, B = self:sub_test5() + lu.ORDER_ACTUAL_EXPECTED = false + lu.assertEquals( A, B ) + end + + function TestListCompare:test5b() + local A, B = self:sub_test5() + lu.assertEquals( B, A ) + end + + function TestListCompare:test5c() + local A, B = self :sub_test5() + lu.PRINT_TABLE_REF_IN_ERROR_MSG = true + lu.assertEquals( B, A ) + end + + function TestListCompare:test6() + local f1 = function () return nil end + local t1 = coroutine.create( function(v) local y=v+1 end ) + local A = { 'aaa', 'bbb', 'ccc', f1, 1.1, 2.1, nil, true, false, t1, t1, t1 } + local B = { 'aaa', 'bbb', 'ccc', f1, 1.1, 2.1, nil, false, false, t1, t1, t1 } + lu.assertEquals( B, A ) + end + + function TestListCompare:test7() + local A = { {1,2,3}, {1,2}, { {1}, {2} }, { 'aa', 'cc'}, 1, 2, 1.33, 1/0, { a=1 }, {} } + local B = { {1,2,3}, {1,2}, { {2}, {2} }, { 'aa', 'bb'}, 1, 2, 1.33, 1/0, { a=1 }, {} } + lu.assertEquals( B, A ) + end + + function TestListCompare:tearDown() + -- cancel effect of test5a + lu.ORDER_ACTUAL_EXPECTED = true + -- cancel effect of test5c + lu.PRINT_TABLE_REF_IN_ERROR_MSG = false + end +-- end TestListCompare + +--[[ +TestDictCompare = {} + function XTestDictCompare:test1() + lu.assertEquals( {one=1,two=2, three=3}, {one=1,two=1, three=3} ) + end + + function XTestDictCompare:test2() + lu.assertEquals( {one=1,two=2, three=3, four=4, five=5}, {one=1,two=1, three=3, four=4, five=5} ) + end +-- end TestDictCompare +]] + + +os.exit( lu.run() ) \ No newline at end of file diff -Nru lua-unit-3.2/test/test_luaunit.lua lua-unit-3.3/test/test_luaunit.lua --- lua-unit-3.2/test/test_luaunit.lua 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/test_luaunit.lua 2018-04-20 12:34:12.000000000 +0000 @@ -1,2486 +1,3816 @@ ---[[ -Author: Philippe Fremy -License: BSD License, see LICENSE.txt - -]]-- - --- Return a function that appends its arguments to the `callInfo` table -local function callRecorder( callInfo ) - return function( ... ) - for i, v in pairs({...}) do - table.insert( callInfo, v ) - end - end -end - --- This is a bit tricky since the test uses the features that it tests. - -local lu = require('luaunit') - -local Mock = { __class__ = 'Mock' } - -function Mock.new(runner) - local t = lu.genericOutput.new(runner) - t.calls = {} - local t_MT = { - __index = function( t, key ) - local callInfo = { key } - table.insert( t.calls, callInfo ) - return callRecorder( callInfo ) - end - } - return setmetatable( t, t_MT ) -end - - -TestMock = {} - function TestMock:testMock() - local m = Mock.new() - m.titi( 42 ) - m.toto( 33, "abc", { 21} ) - lu.assertEquals( m.calls[1][1], 'titi' ) - lu.assertEquals( m.calls[1][2], 42 ) - lu.assertEquals( #m.calls[1], 2 ) - - lu.assertEquals( m.calls[2][1], 'toto' ) - lu.assertEquals( m.calls[2][2], 33 ) - lu.assertEquals( m.calls[2][3], 'abc' ) - lu.assertEquals( m.calls[2][4][1], 21 ) - lu.assertEquals( #m.calls[2], 4 ) - - lu.assertEquals( #m.calls, 2 ) - end - ------------------------------------------------------------------- --- --- Utility Tests --- ------------------------------------------------------------------- - -TestLuaUnitUtilities = { __class__ = 'TestLuaUnitUtilities' } - - function TestLuaUnitUtilities:test_genSortedIndex() - lu.assertEquals( lu.private.__genSortedIndex( { 2, 5, 7} ), {1,2,3} ) - lu.assertEquals( lu.private.__genSortedIndex( { a='1', h='2', c='3' } ), {'a', 'c', 'h'} ) - lu.assertEquals( lu.private.__genSortedIndex( { 1, 'z', a='1', h='2', c='3' } ), { 1, 2, 'a', 'c', 'h' } ) - lu.assertEquals( lu.private.__genSortedIndex( { b=4, a=3, true, foo="bar", nil, bar=false, 42, c=5 } ), - { 1, 3, 'a', 'b', 'bar', 'c', 'foo' } ) - end - - function TestLuaUnitUtilities:test_sortedNextWorks() - local t1 = {} - t1['aaa'] = 'abc' - t1['ccc'] = 'def' - t1['bbb'] = 'cba' - - -- mimic semantics of "generic for" loop - local sortedNext, state = lu.private.sortedPairs(t1) - - local k, v = sortedNext( state, nil ) - lu.assertEquals( k, 'aaa' ) - lu.assertEquals( v, 'abc' ) - k, v = sortedNext( state, k ) - lu.assertEquals( k, 'bbb' ) - lu.assertEquals( v, 'cba' ) - k, v = sortedNext( state, k ) - lu.assertEquals( k, 'ccc' ) - lu.assertEquals( v, 'def' ) - k, v = sortedNext( state, k ) - lu.assertEquals( k, nil ) - lu.assertEquals( v, nil ) - - -- check if starting the iteration a second time works - k, v = sortedNext( state, nil ) - lu.assertEquals( k, 'aaa' ) - lu.assertEquals( v, 'abc' ) - - -- run a generic for loop (internally using a separate state) - local tested = {} - for k, v in lu.private.sortedPairs(t1) do table.insert(tested, v) end - lu.assertEquals( tested, {'abc', 'cba', 'def'} ) - - -- test bisection algorithm by searching for non-existing key values - k, v = sortedNext( state, '' ) -- '' would come before any of the keys - lu.assertNil( k ) - lu.assertNil( v ) - k, v = sortedNext( state, 'xyz' ) -- 'xyz' would be after any other key - lu.assertNil( k ) - lu.assertNil( v ) - - -- finally let's see if we successfully find an "out of sequence" key - k, v = sortedNext( state, 'bbb' ) - lu.assertEquals( k, 'ccc' ) - lu.assertEquals( v, 'def' ) - end - - function TestLuaUnitUtilities:test_sortedNextWorksOnTwoTables() - local t1 = { aaa = 'abc', ccc = 'def' } - local t2 = { ['3'] = '33', ['1'] = '11' } - - local sortedNext, state1, state2 - sortedNext, state1 = lu.private.sortedPairs(t1) - sortedNext, state2 = lu.private.sortedPairs(t2) - - local k, v = sortedNext( state1, nil ) - lu.assertEquals( k, 'aaa' ) - lu.assertEquals( v, 'abc' ) - - k, v = sortedNext( state2, nil ) - lu.assertEquals( k, '1' ) - lu.assertEquals( v, '11' ) - - k, v = sortedNext( state1, 'aaa' ) - lu.assertEquals( k, 'ccc' ) - lu.assertEquals( v, 'def' ) - - k, v = sortedNext( state2, '1' ) - lu.assertEquals( k, '3' ) - lu.assertEquals( v, '33' ) - end - - function TestLuaUnitUtilities:test_strSplitOneCharDelim() - local t = lu.private.strsplit( '\n', '1\n22\n333\n' ) - lu.assertEquals( t[1], '1') - lu.assertEquals( t[2], '22') - lu.assertEquals( t[3], '333') - lu.assertEquals( t[4], '') - lu.assertEquals( #t, 4 ) - -- test invalid (empty) delimiter - lu.assertErrorMsgContains('delimiter matches empty string!', - lu.private.strsplit, '', '1\n22\n333\n') - end - - function TestLuaUnitUtilities:test_strSplit3CharDelim() - local t = lu.private.strsplit( '2\n3', '1\n22\n332\n3' ) - lu.assertEquals( t[1], '1\n2') - lu.assertEquals( t[2], '3') - lu.assertEquals( t[3], '') - lu.assertEquals( #t, 3 ) - end - - function TestLuaUnitUtilities:test_protectedCall() - local function boom() error("Something went wrong.") end - local err = lu.LuaUnit:protectedCall(nil, boom, "kaboom") - - -- check that err received the expected fields - lu.assertEquals(err.status, "ERROR") - lu.assertStrContains(err.msg, "Something went wrong.") - lu.assertStrMatches(err.trace, "^stack traceback:.*in %a+ 'kaboom'.*") - end - - function TestLuaUnitUtilities:test_prefixString() - lu.assertEquals( lu.private.prefixString( '12 ', 'ab\ncd\nde'), '12 ab\n12 cd\n12 de' ) - end - - function TestLuaUnitUtilities:test_is_table_equals() - -- Make sure that _is_table_equals() doesn't fall for these traps - -- (See https://github.com/bluebird75/luaunit/issues/48) - local A, B, C = {}, {}, {} - - A.self = A - B.self = B - lu.assertNotEquals(A, B) - lu.assertEquals(A, A) - - A, B = {}, {} - A.circular = C - B.circular = A - C.circular = B - lu.assertNotEquals(A, B) - lu.assertEquals(C, C) - end - - function TestLuaUnitUtilities:test_table_keytostring() - lu.assertEquals( lu.private._table_keytostring( 'a' ), 'a' ) - lu.assertEquals( lu.private._table_keytostring( 'a0' ), 'a0' ) - lu.assertEquals( lu.private._table_keytostring( 'a0!' ), '"a0!"' ) - end - - function TestLuaUnitUtilities:test_prettystr() - lu.assertEquals( lu.prettystr( 1 ), "1" ) - lu.assertEquals( lu.prettystr( 1.1 ), "1.1" ) - lu.assertEquals( lu.prettystr( 'abc' ), '"abc"' ) - lu.assertEquals( lu.prettystr( 'ab\ncd' ), '"ab\ncd"' ) - lu.assertEquals( lu.prettystr( 'ab\ncd', true ), '"ab\\ncd"' ) - lu.assertEquals( lu.prettystr( 'ab"cd' ), "'ab\"cd'" ) - lu.assertEquals( lu.prettystr( "ab'cd" ), '"ab\'cd"' ) - lu.assertEquals( lu.prettystr( {1,2,3} ), "{1, 2, 3}" ) - lu.assertEquals( lu.prettystr( {a=1,bb=2,ab=3} ), '{a=1, ab=3, bb=2}' ) - lu.assertEquals( lu.prettystr( { [{}] = 1 }), '{{}=1}' ) - lu.assertEquals( lu.prettystr( { 1, [{}] = 1, 2 }), '{1, 2, {}=1}' ) - lu.assertEquals( lu.prettystr( { 1, [{one=1}] = 1, 2, "test", false }), '{1, 2, "test", false, {one=1}=1}' ) - end - - function TestLuaUnitUtilities:test_prettystr_adv_tables() - local t1 = {1,2,3,4,5,6} - lu.assertEquals(lu.prettystr(t1), "{1, 2, 3, 4, 5, 6}" ) - - local t2 = {'aaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbb', 'ccccccccccccccccc', 'ddddddddddddd', 'eeeeeeeeeeeeeeeeee', 'ffffffffffffffff', 'ggggggggggg', 'hhhhhhhhhhhhhh'} - lu.assertEquals(lu.prettystr(t2), table.concat( { - '{', - ' "aaaaaaaaaaaaaaaaa",', - ' "bbbbbbbbbbbbbbbbbbbb",', - ' "ccccccccccccccccc",', - ' "ddddddddddddd",', - ' "eeeeeeeeeeeeeeeeee",', - ' "ffffffffffffffff",', - ' "ggggggggggg",', - ' "hhhhhhhhhhhhhh"', - '}', - } , '\n' ) ) - - local t2bis = { 1,2,3,'12345678901234567890123456789012345678901234567890123456789012345678901234567890', 4,5,6 } - lu.assertEquals(lu.prettystr(t2bis), [[{ - 1, - 2, - 3, - "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - 4, - 5, - 6 -}]] ) - - local t3 = { l1a = { l2a = { l3a='012345678901234567890123456789012345678901234567890123456789' }, - l2b='bbb' }, l1b = 4} - lu.assertEquals(lu.prettystr(t3), [[{ - l1a={ - l2a={l3a="012345678901234567890123456789012345678901234567890123456789"}, - l2b="bbb" - }, - l1b=4 -}]] ) - - local t4 = { a=1, b=2, c=3 } - lu.assertEquals(lu.prettystr(t4), '{a=1, b=2, c=3}' ) - - local t5 = { t1, t2, t3 } - lu.assertEquals( lu.prettystr(t5), [[{ - {1, 2, 3, 4, 5, 6}, - { - "aaaaaaaaaaaaaaaaa", - "bbbbbbbbbbbbbbbbbbbb", - "ccccccccccccccccc", - "ddddddddddddd", - "eeeeeeeeeeeeeeeeee", - "ffffffffffffffff", - "ggggggggggg", - "hhhhhhhhhhhhhh" - }, - { - l1a={ - l2a={l3a="012345678901234567890123456789012345678901234567890123456789"}, - l2b="bbb" - }, - l1b=4 - } -}]] ) - - local t6 = { t1=t1, t2=t2, t3=t3, t4=t4 } - lu.assertEquals(lu.prettystr(t6),[[{ - t1={1, 2, 3, 4, 5, 6}, - t2={ - "aaaaaaaaaaaaaaaaa", - "bbbbbbbbbbbbbbbbbbbb", - "ccccccccccccccccc", - "ddddddddddddd", - "eeeeeeeeeeeeeeeeee", - "ffffffffffffffff", - "ggggggggggg", - "hhhhhhhhhhhhhh" - }, - t3={ - l1a={ - l2a={l3a="012345678901234567890123456789012345678901234567890123456789"}, - l2b="bbb" - }, - l1b=4 - }, - t4={a=1, b=2, c=3} -}]]) - end - - function TestLuaUnitUtilities:test_prettystrTableRecursion() - local t = {} - t.__index = t - lu.assertStrMatches(lu.prettystr(t), " {__index=}") - - local t1 = {} - local t2 = {} - t1.t2 = t2 - t2.t1 = t1 - local t3 = { t1 = t1, t2 = t2 } - lu.assertStrMatches(lu.prettystr(t1), " {t2= {t1=}}") - lu.assertStrMatches(lu.prettystr(t3), [[ { - t1= {t2= {t1=}}, - t2= -}]]) - - local t4 = {1,2} - local t5 = {3,4,t4} - t4[3] = t5 - lu.assertStrMatches(lu.prettystr(t5), " {3, 4, {1, 2, }}") - end - - function TestLuaUnitUtilities:test_prettystrPadded() - local foo, bar, str1, str2 - - -- test all combinations of: foo = nil, "foo", "fo\no" (embedded - -- newline); and bar = nil, "bar", "bar\n" (trailing newline) - - str1, str2 = lu.private.prettystrPadded(foo, bar) - lu.assertEquals(str1, "nil") - lu.assertEquals(str2, "nil") - str1, str2 = lu.private.prettystrPadded(foo, bar, "_A", "_B") - lu.assertEquals(str1, "nil_B") - lu.assertEquals(str2, "nil") - - bar = "bar" - str1, str2 = lu.private.prettystrPadded(foo, bar) - lu.assertEquals(str1, "nil") - lu.assertEquals(str2, '"bar"') - str1, str2 = lu.private.prettystrPadded(foo, bar, "_A", "_B") - lu.assertEquals(str1, "nil_B") - lu.assertEquals(str2, '"bar"') - - bar = "bar\n" - str1, str2 = lu.private.prettystrPadded(foo, bar) - lu.assertEquals(str1, "\nnil") - lu.assertEquals(str2, '\n"bar\n"') - str1, str2 = lu.private.prettystrPadded(foo, bar, "_A", "_B") - lu.assertEquals(str1, "\nnil_A") - lu.assertEquals(str2, '\n"bar\n"') - - foo = "foo" - bar = nil - str1, str2 = lu.private.prettystrPadded(foo, bar) - lu.assertEquals(str1, '"foo"') - lu.assertEquals(str2, "nil") - str1, str2 = lu.private.prettystrPadded(foo, bar, "_A", "_B") - lu.assertEquals(str1, '"foo"_B') - lu.assertEquals(str2, "nil") - - bar = "bar" - str1, str2 = lu.private.prettystrPadded(foo, bar) - lu.assertEquals(str1, '"foo"') - lu.assertEquals(str2, '"bar"') - str1, str2 = lu.private.prettystrPadded(foo, bar, "_A", "_B") - lu.assertEquals(str1, '"foo"_B') - lu.assertEquals(str2, '"bar"') - - bar = "bar\n" - str1, str2 = lu.private.prettystrPadded(foo, bar) - lu.assertEquals(str1, '\n"foo"') - lu.assertEquals(str2, '\n"bar\n"') - str1, str2 = lu.private.prettystrPadded(foo, bar, "_A", "_B") - lu.assertEquals(str1, '\n"foo"_A') - lu.assertEquals(str2, '\n"bar\n"') - - foo = "fo\no" - bar = nil - str1, str2 = lu.private.prettystrPadded(foo, bar) - lu.assertEquals(str1, '\n"fo\no"') - lu.assertEquals(str2, "\nnil") - str1, str2 = lu.private.prettystrPadded(foo, bar, "_A", "_B") - lu.assertEquals(str1, '\n"fo\no"_A') - lu.assertEquals(str2, "\nnil") - - bar = "bar" - str1, str2 = lu.private.prettystrPadded(foo, bar) - lu.assertEquals(str1, '\n"fo\no"') - lu.assertEquals(str2, '\n"bar"') - str1, str2 = lu.private.prettystrPadded(foo, bar, "_A", "_B") - lu.assertEquals(str1, '\n"fo\no"_A') - lu.assertEquals(str2, '\n"bar"') - - bar = "bar\n" - str1, str2 = lu.private.prettystrPadded(foo, bar) - lu.assertEquals(str1, '\n"fo\no"') - lu.assertEquals(str2, '\n"bar\n"') - str1, str2 = lu.private.prettystrPadded(foo, bar, "_A", "_B") - lu.assertEquals(str1, '\n"fo\no"_A') - lu.assertEquals(str2, '\n"bar\n"') - end - - function TestLuaUnitUtilities:test_FailFmt() - -- raise failure from within nested functions - local function bar(level) - lu.private.fail_fmt(level, "hex=%X", 123) - end - local function foo(level) - bar(level) - end - - local _, err = pcall(foo) -- default level 1 = error position in bar() - local line1, prefix = err:match("test[\\/]test_luaunit%.lua:(%d+): (.*)hex=7B$") - lu.assertEquals(prefix, lu.FAILURE_PREFIX) - lu.assertNotNil(line1) - _, err = pcall(foo, 2) -- level 2 = error position within foo() - local line2, prefix = err:match("test[\\/]test_luaunit%.lua:(%d+): (.*)hex=7B$") - lu.assertEquals(prefix, lu.FAILURE_PREFIX) - lu.assertNotNil(line2) - -- make sure that "line2" position is exactly 3 lines after "line1" - lu.assertEquals(tonumber(line2), tonumber(line1) + 3) - end - - function TestLuaUnitUtilities:test_IsFunction() - -- previous LuaUnit.isFunction was superseded by LuaUnit.asFunction - -- (which can also serve as a boolean expression) - lu.assertNotNil( lu.LuaUnit.asFunction( function (a,b) end ) ) - lu.assertNil( lu.LuaUnit.asFunction( nil ) ) - lu.assertNil( lu.LuaUnit.asFunction( "not a function" ) ) - end - - function TestLuaUnitUtilities:test_IsClassMethod() - lu.assertEquals( lu.LuaUnit.isClassMethod( 'toto' ), false ) - lu.assertEquals( lu.LuaUnit.isClassMethod( 'toto.titi' ), true ) - end - - function TestLuaUnitUtilities:test_splitClassMethod() - lu.assertEquals( lu.LuaUnit.splitClassMethod( 'toto' ), nil ) - local v1, v2 = lu.LuaUnit.splitClassMethod( 'toto.titi' ) - lu.assertEquals( {v1, v2}, {'toto', 'titi'} ) - end - - function TestLuaUnitUtilities:test_isTestName() - lu.assertEquals( lu.LuaUnit.isTestName( 'testToto' ), true ) - lu.assertEquals( lu.LuaUnit.isTestName( 'TestToto' ), true ) - lu.assertEquals( lu.LuaUnit.isTestName( 'TESTToto' ), true ) - lu.assertEquals( lu.LuaUnit.isTestName( 'xTESTToto' ), false ) - lu.assertEquals( lu.LuaUnit.isTestName( '' ), false ) - end - - function TestLuaUnitUtilities:test_parseCmdLine() - --test names - lu.assertEquals( lu.LuaUnit.parseCmdLine(), {} ) - lu.assertEquals( lu.LuaUnit.parseCmdLine( { 'someTest' } ), { testNames={'someTest'} } ) - lu.assertEquals( lu.LuaUnit.parseCmdLine( { 'someTest', 'someOtherTest' } ), { testNames={'someTest', 'someOtherTest'} } ) - - -- verbosity - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--verbose' } ), { verbosity=lu.VERBOSITY_VERBOSE } ) - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-v' } ), { verbosity=lu.VERBOSITY_VERBOSE } ) - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--quiet' } ), { verbosity=lu.VERBOSITY_QUIET } ) - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-q' } ), { verbosity=lu.VERBOSITY_QUIET } ) - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-v', '-q' } ), { verbosity=lu.VERBOSITY_QUIET } ) - - --output - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--output', 'toto' } ), { output='toto'} ) - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-o', 'toto' } ), { output='toto'} ) - lu.assertErrorMsgContains( 'Missing argument after -o', lu.LuaUnit.parseCmdLine, { '-o', } ) - - --name - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--name', 'toto' } ), { fname='toto'} ) - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-n', 'toto' } ), { fname='toto'} ) - lu.assertErrorMsgContains( 'Missing argument after -n', lu.LuaUnit.parseCmdLine, { '-n', } ) - - --patterns - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--pattern', 'toto' } ), { pattern={'toto'} } ) - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-p', 'toto' } ), { pattern={'toto'} } ) - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-p', 'titi', '-p', 'toto' } ), { pattern={'titi', 'toto'} } ) - lu.assertErrorMsgContains( 'Missing argument after -p', lu.LuaUnit.parseCmdLine, { '-p', } ) - - --megamix - lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-p', 'toto', 'titi', '-v', 'tata', '-o', 'tintin', '-p', 'tutu', 'prout', '-n', 'toto.xml' } ), - { pattern={'toto', 'tutu'}, verbosity=lu.VERBOSITY_VERBOSE, output='tintin', testNames={'titi', 'tata', 'prout'}, fname='toto.xml' } ) - - lu.assertErrorMsgContains( 'option: -x', lu.LuaUnit.parseCmdLine, { '-x', } ) - end - - function TestLuaUnitUtilities:test_includePattern() - lu.assertEquals( lu.LuaUnit.patternInclude( nil, 'toto'), true ) - lu.assertEquals( lu.LuaUnit.patternInclude( {}, 'toto'), false ) - lu.assertEquals( lu.LuaUnit.patternInclude( {'toto'}, 'toto'), true ) - lu.assertEquals( lu.LuaUnit.patternInclude( {'toto'}, 'yyytotoxxx'), true ) - lu.assertEquals( lu.LuaUnit.patternInclude( {'titi', 'toto'}, 'yyytotoxxx'), true ) - lu.assertEquals( lu.LuaUnit.patternInclude( {'titi', 'to..'}, 'yyytoxxx'), true ) - end - - function TestLuaUnitUtilities:test_applyPatternFilter() - local myTestToto1Value = { 'MyTestToto1.test1', MyTestToto1 } - - local included, excluded = lu.LuaUnit.applyPatternFilter( nil, { myTestToto1Value } ) - lu.assertEquals( excluded, {} ) - lu.assertEquals( included, { myTestToto1Value } ) - - included, excluded = lu.LuaUnit.applyPatternFilter( {'T.to'}, { myTestToto1Value } ) - lu.assertEquals( excluded, {} ) - lu.assertEquals( included, { myTestToto1Value } ) - - included, excluded = lu.LuaUnit.applyPatternFilter( {'T.ti'}, { myTestToto1Value } ) - lu.assertEquals( excluded, { myTestToto1Value } ) - lu.assertEquals( included, {} ) - end - - function TestLuaUnitUtilities:test_strMatch() - lu.assertEquals( lu.private.strMatch('toto', 't.t.'), true ) - lu.assertEquals( lu.private.strMatch('toto', 't.t.', 1, 4), true ) - lu.assertEquals( lu.private.strMatch('toto', 't.t.', 2, 5), false ) - lu.assertEquals( lu.private.strMatch('toto', '.t.t.'), false ) - lu.assertEquals( lu.private.strMatch('ototo', 't.t.'), false ) - lu.assertEquals( lu.private.strMatch('totot', 't.t.'), false ) - lu.assertEquals( lu.private.strMatch('ototot', 't.t.'), false ) - lu.assertEquals( lu.private.strMatch('ototot', 't.t.',2,3), false ) - lu.assertEquals( lu.private.strMatch('ototot', 't.t.',2,5), true ) - lu.assertEquals( lu.private.strMatch('ototot', 't.t.',2,6), false ) - end - - function TestLuaUnitUtilities:test_expandOneClass() - local result = {} - lu.LuaUnit.expandOneClass( result, 'titi', {} ) - lu.assertEquals( result, {} ) - - result = {} - lu.LuaUnit.expandOneClass( result, 'MyTestToto1', MyTestToto1 ) - lu.assertEquals( result, { - {'MyTestToto1.test1', MyTestToto1 }, - {'MyTestToto1.test2', MyTestToto1 }, - {'MyTestToto1.test3', MyTestToto1 }, - {'MyTestToto1.testa', MyTestToto1 }, - {'MyTestToto1.testb', MyTestToto1 }, - } ) - end - - function TestLuaUnitUtilities:test_expandClasses() - local result = {} - result = lu.LuaUnit.expandClasses( {} ) - lu.assertEquals( result, {} ) - - result = lu.LuaUnit.expandClasses( { { 'MyTestFunction', MyTestFunction } } ) - lu.assertEquals( result, { { 'MyTestFunction', MyTestFunction } } ) - - result = lu.LuaUnit.expandClasses( { { 'MyTestToto1.test1', MyTestToto1 } } ) - lu.assertEquals( result, { { 'MyTestToto1.test1', MyTestToto1 } } ) - - result = lu.LuaUnit.expandClasses( { { 'MyTestToto1', MyTestToto1 } } ) - lu.assertEquals( result, { - {'MyTestToto1.test1', MyTestToto1 }, - {'MyTestToto1.test2', MyTestToto1 }, - {'MyTestToto1.test3', MyTestToto1 }, - {'MyTestToto1.testa', MyTestToto1 }, - {'MyTestToto1.testb', MyTestToto1 }, - } ) - end - - function TestLuaUnitUtilities:test_xmlEscape() - lu.assertEquals( lu.private.xmlEscape( 'abc' ), 'abc' ) - lu.assertEquals( lu.private.xmlEscape( 'a"bc' ), 'a"bc' ) - lu.assertEquals( lu.private.xmlEscape( "a'bc" ), 'a'bc' ) - lu.assertEquals( lu.private.xmlEscape( "a" ), 'a<b&c>' ) - end - - function TestLuaUnitUtilities:test_xmlCDataEscape() - lu.assertEquals( lu.private.xmlCDataEscape( 'abc' ), 'abc' ) - lu.assertEquals( lu.private.xmlCDataEscape( 'a"bc' ), 'a"bc' ) - lu.assertEquals( lu.private.xmlCDataEscape( "a'bc" ), "a'bc" ) - lu.assertEquals( lu.private.xmlCDataEscape( "a" ), 'a' ) - lu.assertEquals( lu.private.xmlCDataEscape( "a--" ), 'a - [C]: in function 'xpcall' - ./luaunit.lua:1449: in function 'protectedCall' - ./luaunit.lua:1508: in function 'execOneFunction' - ./luaunit.lua:1596: in function 'runSuiteByInstances' - ./luaunit.lua:1660: in function 'runSuiteByNames' - ./luaunit.lua:1736: in function 'runSuite' - example_with_luaunit.lua:140: in main chunk - [C]: in ?]] - - - local realStackTrace2=[[stack traceback: - ./luaunit.lua:545: in function 'lu.assertEquals' - example_with_luaunit.lua:58: in function 'TestToto.test7' - ./luaunit.lua:1517: in function <./luaunit.lua:1517> - [C]: in function 'xpcall' - ./luaunit.lua:1517: in function 'protectedCall' - ./luaunit.lua:1578: in function 'execOneFunction' - ./luaunit.lua:1677: in function 'runSuiteByInstances' - ./luaunit.lua:1730: in function 'runSuiteByNames' - ./luaunit.lua:1806: in function 'runSuite' - example_with_luaunit.lua:140: in main chunk - [C]: in ?]] - - local realStackTrace3 = [[stack traceback: - luaunit2/example_with_luaunit.lua:124: in function 'test1_withFailure' - luaunit2/luaunit.lua:1532: in function - [C]: in function 'xpcall' - luaunit2/luaunit.lua:1532: in function 'protectedCall' - luaunit2/luaunit.lua:1591: in function 'execOneFunction' - luaunit2/luaunit.lua:1679: in function 'runSuiteByInstances' - luaunit2/luaunit.lua:1743: in function 'runSuiteByNames' - luaunit2/luaunit.lua:1819: in function 'runSuite' - luaunit2/example_with_luaunit.lua:140: in main chunk - [C]: in ?]] - - - local strippedStackTrace=lu.private.stripLuaunitTrace( realStackTrace ) - -- print( strippedStackTrace ) - - local expectedStackTrace=[[stack traceback: - example_with_luaunit.lua:130: in function 'test2_withFailure']] - lu.assertEquals( strippedStackTrace, expectedStackTrace ) - - strippedStackTrace=lu.private.stripLuaunitTrace( realStackTrace2 ) - expectedStackTrace=[[stack traceback: - example_with_luaunit.lua:58: in function 'TestToto.test7']] - lu.assertEquals( strippedStackTrace, expectedStackTrace ) - - strippedStackTrace=lu.private.stripLuaunitTrace( realStackTrace3 ) - expectedStackTrace=[[stack traceback: - luaunit2/example_with_luaunit.lua:124: in function 'test1_withFailure']] - lu.assertEquals( strippedStackTrace, expectedStackTrace ) - - - end - ------------------------------------------------------------------- --- --- Assertion Tests --- ------------------------------------------------------------------- - -local function assertFailure( ... ) - -- ensure that execution generates a failure type error - lu.assertErrorMsgMatches(lu.FAILURE_PREFIX .. ".*", ...) -end - -local function assertBadFindArgTable( ... ) - lu.assertErrorMsgMatches( ".* bad argument .* to 'find' %(string expected, got table%)", ...) -end -local function assertBadFindArgNil( ... ) - lu.assertErrorMsgMatches( ".* bad argument .* to 'find' %(string expected, got nil%)", ...) -end -local function assertBadIndexNumber( ... ) - lu.assertErrorMsgMatches( ".* attempt to index .*a number value.*", ... ) -end -local function assertBadIndexNil( ... ) - lu.assertErrorMsgMatches( ".* attempt to index .*a nil value.*", ... ) -end -local function assertBadMethodNil( ... ) - lu.assertErrorMsgMatches( ".* attempt to call .*a nil value.*", ... ) -end - -TestLuaUnitAssertions = { __class__ = 'TestLuaUnitAssertions' } - - function TestLuaUnitAssertions:test_assertEquals() - local f = function() return true end - local g = function() return true end - - lu.assertEquals( 1, 1 ) - lu.assertEquals( "abc", "abc" ) - lu.assertEquals( nil, nil ) - lu.assertEquals( true, true ) - lu.assertEquals( f, f) - lu.assertEquals( {1,2,3}, {1,2,3}) - lu.assertEquals( {one=1,two=2,three=3}, {one=1,two=2,three=3}) - lu.assertEquals( {one=1,two=2,three=3}, {two=2,three=3,one=1}) - lu.assertEquals( {one=1,two={1,2},three=3}, {two={1,2},three=3,one=1}) - lu.assertEquals( {one=1,two={1,{2,nil}},three=3}, {two={1,{2,nil}},three=3,one=1}) - lu.assertEquals( {nil}, {nil} ) - local config_saved = lu.TABLE_EQUALS_KEYBYCONTENT - lu.TABLE_EQUALS_KEYBYCONTENT = false - assertFailure( lu.assertEquals, {[{}] = 1}, { [{}] = 1}) - assertFailure( lu.assertEquals, {[{one=1, two=2}] = 1}, { [{two=2, one=1}] = 1}) - lu.TABLE_EQUALS_KEYBYCONTENT = true - lu.assertEquals( {[{}] = 1}, { [{}] = 1}) - lu.assertEquals( {[{one=1, two=2}] = 1}, { [{two=2, one=1}] = 1}) - - assertFailure( lu.assertEquals, 1, 2) - assertFailure( lu.assertEquals, 1, "abc" ) - assertFailure( lu.assertEquals, 0, nil ) - assertFailure( lu.assertEquals, false, nil ) - assertFailure( lu.assertEquals, true, 1 ) - assertFailure( lu.assertEquals, f, 1 ) - assertFailure( lu.assertEquals, f, g ) - assertFailure( lu.assertEquals, {1,2,3}, {2,1,3} ) - assertFailure( lu.assertEquals, {1,2,3}, nil ) - assertFailure( lu.assertEquals, {1,2,3}, 1 ) - assertFailure( lu.assertEquals, {1,2,3}, true ) - assertFailure( lu.assertEquals, {1,2,3}, {one=1,two=2,three=3} ) - assertFailure( lu.assertEquals, {1,2,3}, {one=1,two=2,three=3,four=4} ) - assertFailure( lu.assertEquals, {one=1,two=2,three=3}, {2,1,3} ) - assertFailure( lu.assertEquals, {one=1,two=2,three=3}, nil ) - assertFailure( lu.assertEquals, {one=1,two=2,three=3}, 1 ) - assertFailure( lu.assertEquals, {one=1,two=2,three=3}, true ) - assertFailure( lu.assertEquals, {one=1,two=2,three=3}, {1,2,3} ) - assertFailure( lu.assertEquals, {one=1,two={1,2},three=3}, {two={2,1},three=3,one=1}) - lu.TABLE_EQUALS_KEYBYCONTENT = true -- without it, these tests won't pass anyway - assertFailure( lu.assertEquals, {[{}] = 1}, {[{}] = 2}) - assertFailure( lu.assertEquals, {[{}] = 1}, {[{one=1}] = 2}) - assertFailure( lu.assertEquals, {[{}] = 1}, {[{}] = 1, 2}) - assertFailure( lu.assertEquals, {[{}] = 1}, {[{}] = 1, [{}] = 1}) - lu.TABLE_EQUALS_KEYBYCONTENT = config_saved - end - - function TestLuaUnitAssertions:test_assertAlmostEquals() - lu.assertAlmostEquals( 1, 1, 0.1 ) - lu.assertAlmostEquals( 1, 1, 0 ) -- zero margin - - lu.assertAlmostEquals( 1, 1.1, 0.2 ) - lu.assertAlmostEquals( -1, -1.1, 0.2 ) - lu.assertAlmostEquals( 0.1, -0.1, 0.3 ) - - lu.assertAlmostEquals( 1, 1.1, 0.1 ) - lu.assertAlmostEquals( -1, -1.1, 0.1 ) - lu.assertAlmostEquals( 0.1, -0.1, 0.2 ) - - assertFailure( lu.assertAlmostEquals, 1, 1.11, 0.1 ) - assertFailure( lu.assertAlmostEquals, -1, -1.11, 0.1 ) - lu.assertErrorMsgContains( "must supply only number arguments", lu.assertAlmostEquals, -1, 1, nil ) - lu.assertErrorMsgContains( "must supply only number arguments", lu.assertAlmostEquals, -1, nil, 0 ) - lu.assertErrorMsgContains( "must supply only number arguments", lu.assertAlmostEquals, nil, 1, 0 ) - lu.assertErrorMsgContains( "margin must not be negative", lu.assertAlmostEquals, 1, 1.1, -0.1 ) - end - - function TestLuaUnitAssertions:test_assertNotEquals() - local f = function() return true end - local g = function() return true end - - lu.assertNotEquals( 1, 2 ) - lu.assertNotEquals( "abc", 2 ) - lu.assertNotEquals( "abc", "def" ) - lu.assertNotEquals( 1, 2) - lu.assertNotEquals( 1, "abc" ) - lu.assertNotEquals( 0, nil ) - lu.assertNotEquals( false, nil ) - lu.assertNotEquals( true, 1 ) - lu.assertNotEquals( f, 1 ) - lu.assertNotEquals( f, g ) - lu.assertNotEquals( {one=1,two=2,three=3}, true ) - lu.assertNotEquals( {one=1,two={1,2},three=3}, {two={2,1},three=3,one=1} ) - - assertFailure( lu.assertNotEquals, 1, 1) - assertFailure( lu.assertNotEquals, "abc", "abc" ) - assertFailure( lu.assertNotEquals, nil, nil ) - assertFailure( lu.assertNotEquals, true, true ) - assertFailure( lu.assertNotEquals, f, f) - assertFailure( lu.assertNotEquals, {one=1,two={1,{2,nil}},three=3}, {two={1,{2,nil}},three=3,one=1}) - end - - function TestLuaUnitAssertions:test_assertNotAlmostEquals() - lu.assertNotAlmostEquals( 1, 1.2, 0.1 ) - lu.assertNotAlmostEquals( 1, 1.01, 0 ) -- zero margin - - lu.assertNotAlmostEquals( 1, 1.3, 0.2 ) - lu.assertNotAlmostEquals( -1, -1.3, 0.2 ) - lu.assertNotAlmostEquals( 0.1, -0.1, 0.1 ) - - lu.assertNotAlmostEquals( 1, 1.1, 0.09 ) - lu.assertNotAlmostEquals( -1, -1.1, 0.09 ) - lu.assertNotAlmostEquals( 0.1, -0.1, 0.11 ) - - assertFailure( lu.assertNotAlmostEquals, 1, 1.11, 0.2 ) - assertFailure( lu.assertNotAlmostEquals, -1, -1.11, 0.2 ) - lu.assertErrorMsgContains( "must supply only number arguments", lu.assertNotAlmostEquals, -1, 1, nil ) - lu.assertErrorMsgContains( "must supply only number arguments", lu.assertNotAlmostEquals, -1, nil, 0 ) - lu.assertErrorMsgContains( "must supply only number arguments", lu.assertNotAlmostEquals, nil, 1, 0 ) - lu.assertErrorMsgContains( "margin must not be negative", lu.assertNotAlmostEquals, 1, 1.1, -0.1 ) - end - - function TestLuaUnitAssertions:test_assertNotEqualsDifferentTypes2() - lu.assertNotEquals( 2, "abc" ) - end - - function TestLuaUnitAssertions:test_assertTrue() - lu.assertTrue(true) - assertFailure( lu.assertTrue, false) - lu.assertTrue(0) - lu.assertTrue(1) - lu.assertTrue("") - lu.assertTrue("abc") - assertFailure( lu.assertTrue, nil ) - lu.assertTrue( function() return true end ) - lu.assertTrue( {} ) - lu.assertTrue( { 1 } ) - end - - function TestLuaUnitAssertions:test_assertFalse() - lu.assertFalse(false) - assertFailure( lu.assertFalse, true) - lu.assertFalse( nil ) - assertFailure( lu.assertFalse, 0 ) - assertFailure( lu.assertFalse, 1 ) - assertFailure( lu.assertFalse, "" ) - assertFailure( lu.assertFalse, "abc" ) - assertFailure( lu.assertFalse, function() return true end ) - assertFailure( lu.assertFalse, {} ) - assertFailure( lu.assertFalse, { 1 } ) - end - - function TestLuaUnitAssertions:test_assertNil() - lu.assertNil(nil) - assertFailure( lu.assertTrue, false) - assertFailure( lu.assertNil, 0) - assertFailure( lu.assertNil, "") - assertFailure( lu.assertNil, "abc") - assertFailure( lu.assertNil, function() return true end ) - assertFailure( lu.assertNil, {} ) - assertFailure( lu.assertNil, { 1 } ) - end - - function TestLuaUnitAssertions:test_assertNotNil() - assertFailure( lu.assertNotNil, nil) - lu.assertNotNil( false ) - lu.assertNotNil( 0 ) - lu.assertNotNil( "" ) - lu.assertNotNil( "abc" ) - lu.assertNotNil( function() return true end ) - lu.assertNotNil( {} ) - lu.assertNotNil( { 1 } ) - end - - function TestLuaUnitAssertions:test_assertStrContains() - lu.assertStrContains( 'abcdef', 'abc' ) - lu.assertStrContains( 'abcdef', 'bcd' ) - lu.assertStrContains( 'abcdef', 'abcdef' ) - lu.assertStrContains( 'abc0', 0 ) - assertFailure( lu.assertStrContains, 'ABCDEF', 'abc' ) - assertFailure( lu.assertStrContains, '', 'abc' ) - lu.assertStrContains( 'abcdef', '' ) - assertFailure( lu.assertStrContains, 'abcdef', 'abcx' ) - assertFailure( lu.assertStrContains, 'abcdef', 'abcdefg' ) - assertFailure( lu.assertStrContains, 'abcdef', 0 ) - assertBadFindArgTable( lu.assertStrContains, 'abcdef', {} ) - assertBadFindArgNil( lu.assertStrContains, 'abcdef', nil ) - - lu.assertStrContains( 'abcdef', 'abc', false ) - lu.assertStrContains( 'abcdef', 'abc', true ) - lu.assertStrContains( 'abcdef', 'a.c', true ) - - assertFailure( lu.assertStrContains, 'abcdef', '.abc', true ) - end - - function TestLuaUnitAssertions:test_assertStrIContains() - lu.assertStrIContains( 'ABcdEF', 'aBc' ) - lu.assertStrIContains( 'abCDef', 'bcd' ) - lu.assertStrIContains( 'abcdef', 'abcDef' ) - assertFailure( lu.assertStrIContains, '', 'aBc' ) - lu.assertStrIContains( 'abcDef', '' ) - assertFailure( lu.assertStrIContains, 'abcdef', 'abcx' ) - assertFailure( lu.assertStrIContains, 'abcdef', 'abcdefg' ) - end - - function TestLuaUnitAssertions:test_assertNotStrContains() - assertFailure( lu.assertNotStrContains, 'abcdef', 'abc' ) - assertFailure( lu.assertNotStrContains, 'abcdef', 'bcd' ) - assertFailure( lu.assertNotStrContains, 'abcdef', 'abcdef' ) - lu.assertNotStrContains( '', 'abc' ) - assertFailure( lu.assertNotStrContains, 'abcdef', '' ) - assertFailure( lu.assertNotStrContains, 'abc0', 0 ) - lu.assertNotStrContains( 'abcdef', 'abcx' ) - lu.assertNotStrContains( 'abcdef', 'abcdefg' ) - assertBadFindArgTable( lu.assertNotStrContains, 'abcdef', {} ) - assertBadFindArgNil( lu.assertNotStrContains, 'abcdef', nil ) - - assertFailure( lu.assertNotStrContains, 'abcdef', 'abc', false ) - assertFailure( lu.assertNotStrContains, 'abcdef', 'a.c', true ) - lu.assertNotStrContains( 'abcdef', 'a.cx', true ) - end - - function TestLuaUnitAssertions:test_assertNotStrIContains() - assertFailure( lu.assertNotStrIContains, 'aBcdef', 'abc' ) - assertFailure( lu.assertNotStrIContains, 'abcdef', 'aBc' ) - assertFailure( lu.assertNotStrIContains, 'abcdef', 'bcd' ) - assertFailure( lu.assertNotStrIContains, 'abcdef', 'abcdef' ) - lu.assertNotStrIContains( '', 'abc' ) - assertFailure( lu.assertNotStrIContains, 'abcdef', '' ) - assertBadIndexNumber( lu.assertNotStrIContains, 'abc0', 0 ) - lu.assertNotStrIContains( 'abcdef', 'abcx' ) - lu.assertNotStrIContains( 'abcdef', 'abcdefg' ) - assertBadMethodNil( lu.assertNotStrIContains, 'abcdef', {} ) - assertBadIndexNil( lu.assertNotStrIContains, 'abcdef', nil ) - end - - function TestLuaUnitAssertions:test_assertStrMatches() - lu.assertStrMatches( 'abcdef', 'abcdef' ) - lu.assertStrMatches( 'abcdef', '..cde.' ) - assertFailure( lu.assertStrMatches, 'abcdef', '..def') - assertFailure( lu.assertStrMatches, 'abCDEf', '..cde.') - lu.assertStrMatches( 'abcdef', 'bcdef', 2 ) - lu.assertStrMatches( 'abcdef', 'bcde', 2, 5 ) - lu.assertStrMatches( 'abcdef', 'b..e', 2, 5 ) - lu.assertStrMatches( 'abcdef', 'ab..e', nil, 5 ) - assertFailure( lu.assertStrMatches, 'abcdef', '' ) - assertFailure( lu.assertStrMatches, '', 'abcdef' ) - - assertFailure( lu.assertStrMatches, 'abcdef', 0 ) - assertBadFindArgTable( lu.assertStrMatches, 'abcdef', {} ) - assertBadFindArgNil( lu.assertStrMatches, 'abcdef', nil ) - end - - function TestLuaUnitAssertions:test_assertItemsEquals() - lu.assertItemsEquals(nil, nil) - lu.assertItemsEquals({},{}) - lu.assertItemsEquals({1,2,3}, {3,1,2}) - lu.assertItemsEquals({nil},{nil}) - lu.assertItemsEquals({one=1,two=2,three=3}, {two=2,one=1,three=3}) - lu.assertItemsEquals({one=1,two=2,three=3}, {a=1,b=2,c=3}) - lu.assertItemsEquals({1,2,three=3}, {3,1,two=2}) - - assertFailure(lu.assertItemsEquals, {1}, {}) - assertFailure(lu.assertItemsEquals, nil, {1,2,3}) - assertFailure(lu.assertItemsEquals, {1,2,3}, nil) - assertFailure(lu.assertItemsEquals, {1,2,3,4}, {3,1,2}) - assertFailure(lu.assertItemsEquals, {1,2,3}, {3,1,2,4}) - assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3,four=4}, {a=1,b=2,c=3}) - assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {a=1,b=2,c=3,d=4}) - assertFailure(lu.assertItemsEquals, {1,2,three=3}, {3,4,a=1,b=2}) - assertFailure(lu.assertItemsEquals, {1,2,three=3,four=4}, {3,a=1,b=2}) - - lu.assertItemsEquals({one=1,two={1,2},three=3}, {one={1,2},two=1,three=3}) - lu.assertItemsEquals({one=1, - two={1,{3,2,one=1}}, - three=3}, - {two={1,{3,2,one=1}}, - one=1, - three=3}) - -- itemsEquals is not recursive: - assertFailure( lu.assertItemsEquals,{1,{2,1},3}, {3,1,{1,2}}) - assertFailure( lu.assertItemsEquals,{one=1,two={1,2},three=3}, {one={2,1},two=1,three=3}) - assertFailure( lu.assertItemsEquals,{one=1,two={1,{3,2,one=1}},three=3}, {two={{3,one=1,2},1},one=1,three=3}) - assertFailure( lu.assertItemsEquals,{one=1,two={1,{3,2,one=1}},three=3}, {two={{3,2,one=1},1},one=1,three=3}) - - assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {two=2,one=1,three=2}) - assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {two=2,one=1,four=4}) - assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {two=2,one=1,'three'}) - assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {two=2,one=1,nil}) - assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {two=2,one=1}) - end - - function TestLuaUnitAssertions:test_assertIsNumber() - lu.assertIsNumber(1) - lu.assertIsNumber(1.4) - assertFailure(lu.assertIsNumber, "hi there!") - assertFailure(lu.assertIsNumber, nil) - assertFailure(lu.assertIsNumber, {}) - assertFailure(lu.assertIsNumber, {1,2,3}) - assertFailure(lu.assertIsNumber, {1}) - assertFailure(lu.assertIsNumber, coroutine.create( function(v) local y=v+1 end ) ) - assertFailure(lu.assertIsNumber, true) - end - - function TestLuaUnitAssertions:test_assertIsString() - assertFailure(lu.assertIsString, 1) - assertFailure(lu.assertIsString, 1.4) - lu.assertIsString("hi there!") - assertFailure(lu.assertIsString, nil) - assertFailure(lu.assertIsString, {}) - assertFailure(lu.assertIsString, {1,2,3}) - assertFailure(lu.assertIsString, {1}) - assertFailure(lu.assertIsString, coroutine.create( function(v) local y=v+1 end ) ) - assertFailure(lu.assertIsString, true) - end - - function TestLuaUnitAssertions:test_assertIsTable() - assertFailure(lu.assertIsTable, 1) - assertFailure(lu.assertIsTable, 1.4) - assertFailure(lu.assertIsTable, "hi there!") - assertFailure(lu.assertIsTable, nil) - lu.assertIsTable({}) - lu.assertIsTable({1,2,3}) - lu.assertIsTable({1}) - assertFailure(lu.assertIsTable, true) - assertFailure(lu.assertIsTable, coroutine.create( function(v) local y=v+1 end ) ) - end - - function TestLuaUnitAssertions:test_assertIsBoolean() - assertFailure(lu.assertIsBoolean, 1) - assertFailure(lu.assertIsBoolean, 1.4) - assertFailure(lu.assertIsBoolean, "hi there!") - assertFailure(lu.assertIsBoolean, nil) - assertFailure(lu.assertIsBoolean, {}) - assertFailure(lu.assertIsBoolean, {1,2,3}) - assertFailure(lu.assertIsBoolean, {1}) - assertFailure(lu.assertIsBoolean, coroutine.create( function(v) local y=v+1 end ) ) - lu.assertIsBoolean(true) - lu.assertIsBoolean(false) - end - - function TestLuaUnitAssertions:test_assertIsNil() - assertFailure(lu.assertIsNil, 1) - assertFailure(lu.assertIsNil, 1.4) - assertFailure(lu.assertIsNil, "hi there!") - lu.assertIsNil(nil) - assertFailure(lu.assertIsNil, {}) - assertFailure(lu.assertIsNil, {1,2,3}) - assertFailure(lu.assertIsNil, {1}) - assertFailure(lu.assertIsNil, false) - assertFailure(lu.assertIsNil, coroutine.create( function(v) local y=v+1 end ) ) - end - - function TestLuaUnitAssertions:test_assertIsFunction() - local f = function() return true end - - assertFailure(lu.assertIsFunction, 1) - assertFailure(lu.assertIsFunction, 1.4) - assertFailure(lu.assertIsFunction, "hi there!") - assertFailure(lu.assertIsFunction, nil) - assertFailure(lu.assertIsFunction, {}) - assertFailure(lu.assertIsFunction, {1,2,3}) - assertFailure(lu.assertIsFunction, {1}) - assertFailure(lu.assertIsFunction, false) - assertFailure(lu.assertIsFunction, coroutine.create( function(v) local y=v+1 end ) ) - lu.assertIsFunction(f) - end - - function TestLuaUnitAssertions:test_assertIsThread() - assertFailure(lu.assertIsThread, 1) - assertFailure(lu.assertIsThread, 1.4) - assertFailure(lu.assertIsThread, "hi there!") - assertFailure(lu.assertIsThread, nil) - assertFailure(lu.assertIsThread, {}) - assertFailure(lu.assertIsThread, {1,2,3}) - assertFailure(lu.assertIsThread, {1}) - assertFailure(lu.assertIsThread, false) - assertFailure(lu.assertIsThread, function(v) local y=v+1 end ) - lu.assertIsThread(coroutine.create( function(v) local y=v+1 end ) ) - end - - function TestLuaUnitAssertions:test_assertIsUserdata() - assertFailure(lu.assertIsUserdata, 1) - assertFailure(lu.assertIsUserdata, 1.4) - assertFailure(lu.assertIsUserdata, "hi there!") - assertFailure(lu.assertIsUserdata, nil) - assertFailure(lu.assertIsUserdata, {}) - assertFailure(lu.assertIsUserdata, {1,2,3}) - assertFailure(lu.assertIsUserdata, {1}) - assertFailure(lu.assertIsUserdata, false) - assertFailure(lu.assertIsUserdata, function(v) local y=v+1 end ) - assertFailure(lu.assertIsUserdata, coroutine.create( function(v) local y=v+1 end ) ) - end - - function TestLuaUnitAssertions:test_assertNotIsNumber() - assertFailure(lu.assertNotIsNumber, 1 ) - assertFailure(lu.assertNotIsNumber, 1.4 ) - lu.assertNotIsNumber( "hi there!") - lu.assertNotIsNumber( nil) - lu.assertNotIsNumber( {}) - lu.assertNotIsNumber( {1,2,3}) - lu.assertNotIsNumber( {1}) - lu.assertNotIsNumber( coroutine.create( function(v) local y=v+1 end ) ) - lu.assertNotIsNumber( true) - end - - function TestLuaUnitAssertions:test_assertNotIsString() - lu.assertNotIsString( 1) - lu.assertNotIsString( 1.4) - assertFailure( lu.assertNotIsString, "hi there!") - lu.assertNotIsString( nil) - lu.assertNotIsString( {}) - lu.assertNotIsString( {1,2,3}) - lu.assertNotIsString( {1}) - lu.assertNotIsString( coroutine.create( function(v) local y=v+1 end ) ) - lu.assertNotIsString( true) - end - - function TestLuaUnitAssertions:test_assertNotIsTable() - lu.assertNotIsTable( 1) - lu.assertNotIsTable( 1.4) - lu.assertNotIsTable( "hi there!") - lu.assertNotIsTable( nil) - assertFailure( lu.assertNotIsTable, {}) - assertFailure( lu.assertNotIsTable, {1,2,3}) - assertFailure( lu.assertNotIsTable, {1}) - lu.assertNotIsTable( true) - lu.assertNotIsTable( coroutine.create( function(v) local y=v+1 end ) ) - end - - function TestLuaUnitAssertions:test_assertNotIsBoolean() - lu.assertNotIsBoolean( 1) - lu.assertNotIsBoolean( 1.4) - lu.assertNotIsBoolean( "hi there!") - lu.assertNotIsBoolean( nil) - lu.assertNotIsBoolean( {}) - lu.assertNotIsBoolean( {1,2,3}) - lu.assertNotIsBoolean( {1}) - lu.assertNotIsBoolean( coroutine.create( function(v) local y=v+1 end ) ) - assertFailure( lu.assertNotIsBoolean, true) - assertFailure( lu.assertNotIsBoolean, false) - end - - function TestLuaUnitAssertions:test_assertNotIsNil() - lu.assertNotIsNil( 1) - lu.assertNotIsNil( 1.4) - lu.assertNotIsNil( "hi there!") - assertFailure( lu.assertNotIsNil, nil) - lu.assertNotIsNil( {}) - lu.assertNotIsNil( {1,2,3}) - lu.assertNotIsNil( {1}) - lu.assertNotIsNil( false) - lu.assertNotIsNil( coroutine.create( function(v) local y=v+1 end ) ) - end - - function TestLuaUnitAssertions:test_assertNotIsFunction() - local f = function() return true end - - lu.assertNotIsFunction( 1) - lu.assertNotIsFunction( 1.4) - lu.assertNotIsFunction( "hi there!") - lu.assertNotIsFunction( nil) - lu.assertNotIsFunction( {}) - lu.assertNotIsFunction( {1,2,3}) - lu.assertNotIsFunction( {1}) - lu.assertNotIsFunction( false) - lu.assertNotIsFunction( coroutine.create( function(v) local y=v+1 end ) ) - assertFailure( lu.assertNotIsFunction, f) - end - - function TestLuaUnitAssertions:test_assertNotIsThread() - lu.assertNotIsThread( 1) - lu.assertNotIsThread( 1.4) - lu.assertNotIsThread( "hi there!") - lu.assertNotIsThread( nil) - lu.assertNotIsThread( {}) - lu.assertNotIsThread( {1,2,3}) - lu.assertNotIsThread( {1}) - lu.assertNotIsThread( false) - lu.assertNotIsThread( function(v) local y=v+1 end ) - assertFailure( lu.assertNotIsThread, coroutine.create( function(v) local y=v+1 end ) ) - end - - function TestLuaUnitAssertions:test_assertNotIsUserdata() - lu.assertNotIsUserdata( 1) - lu.assertNotIsUserdata( 1.4) - lu.assertNotIsUserdata( "hi there!") - lu.assertNotIsUserdata( nil) - lu.assertNotIsUserdata( {}) - lu.assertNotIsUserdata( {1,2,3}) - lu.assertNotIsUserdata( {1}) - lu.assertNotIsUserdata( false) - lu.assertNotIsUserdata( function(v) local y=v+1 end ) - lu.assertNotIsUserdata( coroutine.create( function(v) local y=v+1 end ) ) - end - - function TestLuaUnitAssertions:test_assertIs() - local f = function() return true end - local g = function() return true end - local t1= {} - local t2={1,2} - local t3={1,2} - local t4= {a=1,{1,2},day="today"} - local s1='toto' - local s2='toto' - local s3='to'..'to' - - lu.assertIs(1,1) - lu.assertIs(f,f) - lu.assertIs('toto', 'toto') - lu.assertIs(s1, s2) - lu.assertIs(s1, s3) - lu.assertIs(t1,t1) - lu.assertIs(t4,t4) - - assertFailure(lu.assertIs, 1, 2) - assertFailure(lu.assertIs, 1.4, 1) - assertFailure(lu.assertIs, "hi there!", "hola") - assertFailure(lu.assertIs, nil, 1) - assertFailure(lu.assertIs, {}, {}) - assertFailure(lu.assertIs, {1,2,3}, f) - assertFailure(lu.assertIs, f, g) - assertFailure(lu.assertIs, t2,t3 ) - end - - function TestLuaUnitAssertions:test_assertNotIs() - local f = function() return true end - local g = function() return true end - local t1= {} - local t2={1,2} - local t3={1,2} - local t4= {a=1,{1,2},day="today"} - local s1='toto' - local s2='toto' - - assertFailure( lu.assertNotIs, 1,1 ) - assertFailure( lu.assertNotIs, f,f ) - assertFailure( lu.assertNotIs, t1,t1 ) - assertFailure( lu.assertNotIs, t4,t4) - assertFailure( lu.assertNotIs, s1,s2 ) - assertFailure( lu.assertNotIs, 'toto', 'toto' ) - - lu.assertNotIs(1, 2) - lu.assertNotIs(1.4, 1) - lu.assertNotIs("hi there!", "hola") - lu.assertNotIs(nil, 1) - lu.assertNotIs({}, {}) - lu.assertNotIs({1,2,3}, f) - lu.assertNotIs(f, g) - lu.assertNotIs(t2,t3) - end - - function TestLuaUnitAssertions:test_assertTableNum() - lu.assertEquals( 3, 3 ) - lu.assertNotEquals( 3, 4 ) - lu.assertEquals( {3}, {3} ) - lu.assertNotEquals( {3}, 3 ) - lu.assertNotEquals( {3}, {4} ) - lu.assertEquals( {x=1}, {x=1} ) - lu.assertNotEquals( {x=1}, {x=2} ) - lu.assertNotEquals( {x=1}, {y=1} ) - end - function TestLuaUnitAssertions:test_assertTableStr() - lu.assertEquals( '3', '3' ) - lu.assertNotEquals( '3', '4' ) - lu.assertEquals( {'3'}, {'3'} ) - lu.assertNotEquals( {'3'}, '3' ) - lu.assertNotEquals( {'3'}, {'4'} ) - lu.assertEquals( {x='1'}, {x='1'} ) - lu.assertNotEquals( {x='1'}, {x='2'} ) - lu.assertNotEquals( {x='1'}, {y='1'} ) - end - function TestLuaUnitAssertions:test_assertTableLev2() - lu.assertEquals( {x={'a'}}, {x={'a'}} ) - lu.assertNotEquals( {x={'a'}}, {x={'b'}} ) - lu.assertNotEquals( {x={'a'}}, {z={'a'}} ) - lu.assertEquals( {{x=1}}, {{x=1}} ) - lu.assertNotEquals( {{x=1}}, {{y=1}} ) - lu.assertEquals( {{x='a'}}, {{x='a'}} ) - lu.assertNotEquals( {{x='a'}}, {{x='b'}} ) - end - function TestLuaUnitAssertions:test_assertTableList() - lu.assertEquals( {3,4,5}, {3,4,5} ) - lu.assertNotEquals( {3,4,5}, {3,4,6} ) - lu.assertNotEquals( {3,4,5}, {3,5,4} ) - lu.assertEquals( {3,4,x=5}, {3,4,x=5} ) - lu.assertNotEquals( {3,4,x=5}, {3,4,x=6} ) - lu.assertNotEquals( {3,4,x=5}, {3,x=4,5} ) - lu.assertNotEquals( {3,4,5}, {2,3,4,5} ) - lu.assertNotEquals( {3,4,5}, {3,2,4,5} ) - lu.assertNotEquals( {3,4,5}, {3,4,5,6} ) - end - - function TestLuaUnitAssertions:test_assertTableNil() - lu.assertEquals( {3,4,5}, {3,4,5} ) - lu.assertNotEquals( {3,4,5}, {nil,3,4,5} ) - lu.assertNotEquals( {3,4,5}, {nil,4,5} ) - lu.assertEquals( {3,4,5}, {3,4,5,nil} ) -- lua quirk - lu.assertNotEquals( {3,4,5}, {3,4,nil} ) - lu.assertNotEquals( {3,4,5}, {3,nil,5} ) - lu.assertNotEquals( {3,4,5}, {3,4,nil,5} ) - end - - function TestLuaUnitAssertions:test_assertTableNilFront() - lu.assertEquals( {nil,4,5}, {nil,4,5} ) - lu.assertNotEquals( {nil,4,5}, {nil,44,55} ) - lu.assertEquals( {nil,'4','5'}, {nil,'4','5'} ) - lu.assertNotEquals( {nil,'4','5'}, {nil,'44','55'} ) - lu.assertEquals( {nil,{4,5}}, {nil,{4,5}} ) - lu.assertNotEquals( {nil,{4,5}}, {nil,{44,55}} ) - lu.assertNotEquals( {nil,{4}}, {nil,{44}} ) - lu.assertEquals( {nil,{x=4,5}}, {nil,{x=4,5}} ) - lu.assertEquals( {nil,{x=4,5}}, {nil,{5,x=4}} ) -- lua quirk - lu.assertEquals( {nil,{x=4,y=5}}, {nil,{y=5,x=4}} ) -- lua quirk - lu.assertNotEquals( {nil,{x=4,5}}, {nil,{y=4,5}} ) - end - - function TestLuaUnitAssertions:test_assertTableAdditions() - lu.assertEquals( {1,2,3}, {1,2,3} ) - lu.assertNotEquals( {1,2,3}, {1,2,3,4} ) - lu.assertNotEquals( {1,2,3,4}, {1,2,3} ) - lu.assertEquals( {1,x=2,3}, {1,x=2,3} ) - lu.assertNotEquals( {1,x=2,3}, {1,x=2,3,y=4} ) - lu.assertNotEquals( {1,x=2,3,y=4}, {1,x=2,3} ) - end - - -local function assertFailureEquals(msg, ...) - lu.assertErrorMsgEquals(lu.FAILURE_PREFIX .. msg, ...) -end - -local function assertFailureMatches(msg, ...) - lu.assertErrorMsgMatches(lu.FAILURE_PREFIX .. msg, ...) -end - -local function assertFailureContains(msg, ...) - lu.assertErrorMsgContains(lu.FAILURE_PREFIX .. msg, ...) -end - -TestLuaUnitAssertionsError = {} - - function TestLuaUnitAssertionsError:setUp() - self.f = function ( v ) - local y = v + 1 - end - self.f_with_error = function (v) - local y = v + 2 - error('This is an error', 2) - end - end - - function TestLuaUnitAssertionsError:test_assertError() - local x = 1 - - -- f_with_error generates an error - local has_error = not pcall( self.f_with_error, x ) - lu.assertEquals( has_error, true ) - - -- f does not generate an error - has_error = not pcall( self.f, x ) - lu.assertEquals( has_error, false ) - - -- lu.assertError is happy with f_with_error - lu.assertError( self.f_with_error, x ) - - -- lu.assertError is unhappy with f - assertFailureEquals( "Expected an error when calling function but no error generated", - lu.assertError, self.f, x ) - - -- multiple arguments - local function f_with_multi_arguments(a,b,c) - if a == b and b == c then return end - error("three arguments not equal") - end - - lu.assertError( f_with_multi_arguments, 1, 1, 3 ) - lu.assertError( f_with_multi_arguments, 1, 3, 1 ) - lu.assertError( f_with_multi_arguments, 3, 1, 1 ) - - assertFailureEquals( "Expected an error when calling function but no error generated", - lu.assertError, f_with_multi_arguments, 1, 1, 1 ) - end - - function TestLuaUnitAssertionsError:test_assertErrorMsgContains() - local x = 1 - assertFailure( lu.assertErrorMsgContains, 'toto', self.f, x ) - lu.assertErrorMsgContains( 'is an err', self.f_with_error, x ) - lu.assertErrorMsgContains( 'This is an error', self.f_with_error, x ) - assertFailure( lu.assertErrorMsgContains, ' This is an error', self.f_with_error, x ) - assertFailure( lu.assertErrorMsgContains, 'This .. an error', self.f_with_error, x ) - end - - function TestLuaUnitAssertionsError:test_assertErrorMsgEquals() - local x = 1 - assertFailure( lu.assertErrorMsgEquals, 'toto', self.f, x ) - assertFailure( lu.assertErrorMsgEquals, 'is an err', self.f_with_error, x ) - lu.assertErrorMsgEquals( 'This is an error', self.f_with_error, x ) - assertFailure( lu.assertErrorMsgEquals, ' This is an error', self.f_with_error, x ) - assertFailure( lu.assertErrorMsgEquals, 'This .. an error', self.f_with_error, x ) - end - - function TestLuaUnitAssertionsError:test_assertErrorMsgMatches() - local x = 1 - assertFailure( lu.assertErrorMsgMatches, 'toto', self.f, x ) - assertFailure( lu.assertErrorMsgMatches, 'is an err', self.f_with_error, x ) - lu.assertErrorMsgMatches( 'This is an error', self.f_with_error, x ) - lu.assertErrorMsgMatches( 'This is .. error', self.f_with_error, x ) - assertFailure( lu.assertErrorMsgMatches, ' This is an error', self.f_with_error, x ) - end - ------------------------------------------------------------------- --- --- Failure message tests --- ------------------------------------------------------------------- - -TestLuaUnitErrorMsg = { __class__ = 'TestLuaUnitErrorMsg' } - - function TestLuaUnitErrorMsg:setUp() - self.old_ORDER_ACTUAL_EXPECTED = lu.ORDER_ACTUAL_EXPECTED - self.old_PRINT_TABLE_REF_IN_ERROR_MSG = lu.PRINT_TABLE_REF_IN_ERROR_MSG - end - - function TestLuaUnitErrorMsg:tearDown() - lu.ORDER_ACTUAL_EXPECTED = self.old_ORDER_ACTUAL_EXPECTED - lu.PRINT_TABLE_REF_IN_ERROR_MSG = self.old_PRINT_TABLE_REF_IN_ERROR_MSG - end - - function TestLuaUnitErrorMsg:test_assertEqualsMsg() - assertFailureEquals( 'expected: 2, actual: 1', lu.assertEquals, 1, 2 ) - assertFailureEquals( 'expected: "exp"\nactual: "act"', lu.assertEquals, 'act', 'exp' ) - assertFailureEquals( 'expected: \n"exp\npxe"\nactual: \n"act\ntca"', lu.assertEquals, 'act\ntca', 'exp\npxe' ) - assertFailureEquals( 'expected: true, actual: false', lu.assertEquals, false, true ) - if _VERSION == 'Lua 5.3' then - assertFailureEquals( 'expected: 1.2, actual: 1.0', lu.assertEquals, 1.0, 1.2) - else - assertFailureEquals( 'expected: 1.2, actual: 1', lu.assertEquals, 1.0, 1.2) - end - assertFailureMatches( 'expected: {1, 2, 3}\nactual: {3, 2, 1}', lu.assertEquals, {3,2,1}, {1,2,3} ) - assertFailureMatches( 'expected: {one=1, two=2}\nactual: {3, 2, 1}', lu.assertEquals, {3,2,1}, {one=1,two=2} ) - assertFailureEquals( 'expected: 2, actual: nil', lu.assertEquals, nil, 2 ) - end - - function TestLuaUnitErrorMsg:test_assertEqualsOrderReversedMsg() - lu.ORDER_ACTUAL_EXPECTED = false - assertFailureEquals( 'expected: 1, actual: 2', lu.assertEquals, 1, 2 ) - assertFailureEquals( 'expected: "act"\nactual: "exp"', lu.assertEquals, 'act', 'exp' ) - end - - function TestLuaUnitErrorMsg:test_assertAlmostEqualsMsg() - assertFailureEquals('Values are not almost equal\nExpected: 1 with margin of 0.1, received: 2', lu.assertAlmostEquals, 2, 1, 0.1 ) - end - - function TestLuaUnitErrorMsg:test_assertAlmostEqualsOrderReversedMsg() - lu.ORDER_ACTUAL_EXPECTED = false - assertFailureEquals('Values are not almost equal\nExpected: 2 with margin of 0.1, received: 1', lu.assertAlmostEquals, 2, 1, 0.1 ) - end - - function TestLuaUnitErrorMsg:test_assertNotAlmostEqualsMsg() - assertFailureEquals('Values are almost equal\nExpected: 1 with a difference above margin of 0.2, received: 1.1', lu.assertNotAlmostEquals, 1.1, 1, 0.2 ) - end - - function TestLuaUnitErrorMsg:test_assertNotAlmostEqualsMsg() - lu.ORDER_ACTUAL_EXPECTED = false - assertFailureEquals('Values are almost equal\nExpected: 1.1 with a difference above margin of 0.2, received: 1', lu.assertNotAlmostEquals, 1.1, 1, 0.2 ) - end - - function TestLuaUnitErrorMsg:test_assertNotEqualsMsg() - assertFailureEquals( 'Received the not expected value: 1', lu.assertNotEquals, 1, 1 ) - assertFailureMatches( 'Received the not expected value: {1, 2}', lu.assertNotEquals, {1,2}, {1,2} ) - assertFailureEquals( 'Received the not expected value: nil', lu.assertNotEquals, nil, nil ) - end - - function TestLuaUnitErrorMsg:test_assertNotEqualsOrderReversedMsg() - lu.ORDER_ACTUAL_EXPECTED = false - assertFailureEquals( 'Received the not expected value: 1', lu.assertNotEquals, 1, 1 ) - end - - function TestLuaUnitErrorMsg:test_assertTrueFalse() - assertFailureEquals( 'expected: true, actual: false', lu.assertTrue, false ) - assertFailureEquals( 'expected: true, actual: nil', lu.assertTrue, nil ) - assertFailureEquals( 'expected: false, actual: true', lu.assertFalse, true ) - assertFailureEquals( 'expected: false, actual: 0', lu.assertFalse, 0) - assertFailureMatches( 'expected: false, actual: {}', lu.assertFalse, {}) - assertFailureEquals( 'expected: false, actual: "abc"', lu.assertFalse, 'abc') - assertFailureContains( 'expected: false, actual: function', lu.assertFalse, function () end ) - end - - function TestLuaUnitErrorMsg:test_assertNil() - assertFailureEquals( 'expected: nil, actual: false', lu.assertNil, false ) - assertFailureEquals( 'expected non nil value, received nil', lu.assertNotNil, nil ) - end - - function TestLuaUnitErrorMsg:test_assertStrContains() - assertFailureEquals( 'Error, substring "xxx" was not found in string "abcdef"', lu.assertStrContains, 'abcdef', 'xxx' ) - assertFailureEquals( 'Error, substring "aBc" was not found in string "abcdef"', lu.assertStrContains, 'abcdef', 'aBc' ) - assertFailureEquals( 'Error, substring "xxx" was not found in string ""', lu.assertStrContains, '', 'xxx' ) - - assertFailureEquals( 'Error, substring "xxx" was not found in string "abcdef"', lu.assertStrContains, 'abcdef', 'xxx', false ) - assertFailureEquals( 'Error, substring "aBc" was not found in string "abcdef"', lu.assertStrContains, 'abcdef', 'aBc', false ) - assertFailureEquals( 'Error, substring "xxx" was not found in string ""', lu.assertStrContains, '', 'xxx', false ) - - assertFailureEquals( 'Error, regexp "xxx" was not found in string "abcdef"', lu.assertStrContains, 'abcdef', 'xxx', true ) - assertFailureEquals( 'Error, regexp "aBc" was not found in string "abcdef"', lu.assertStrContains, 'abcdef', 'aBc', true ) - assertFailureEquals( 'Error, regexp "xxx" was not found in string ""', lu.assertStrContains, '', 'xxx', true ) - - end - - function TestLuaUnitErrorMsg:test_assertStrIContains() - assertFailureEquals( 'Error, substring "xxx" was not found in string "abcdef"', lu.assertStrContains, 'abcdef', 'xxx' ) - assertFailureEquals( 'Error, substring "xxx" was not found in string ""', lu.assertStrContains, '', 'xxx' ) - end - - function TestLuaUnitErrorMsg:test_assertNotStrContains() - assertFailureEquals( 'Error, substring "abc" was found in string "abcdef"', lu.assertNotStrContains, 'abcdef', 'abc' ) - assertFailureEquals( 'Error, substring "abc" was found in string "abcdef"', lu.assertNotStrContains, 'abcdef', 'abc', false ) - assertFailureEquals( 'Error, regexp "..." was found in string "abcdef"', lu.assertNotStrContains, 'abcdef', '...', true) - end - - function TestLuaUnitErrorMsg:test_assertNotStrIContains() - assertFailureEquals( 'Error, substring "aBc" was found (case insensitively) in string "abcdef"', lu.assertNotStrIContains, 'abcdef', 'aBc' ) - assertFailureEquals( 'Error, substring "abc" was found (case insensitively) in string "abcdef"', lu.assertNotStrIContains, 'abcdef', 'abc' ) - end - - function TestLuaUnitErrorMsg:test_assertStrMatches() - assertFailureEquals('Error, pattern "xxx" was not matched by string "abcdef"', lu.assertStrMatches, 'abcdef', 'xxx' ) - end - - function TestLuaUnitErrorMsg:test_assertIsNumber() - assertFailureEquals( 'Expected: a number value, actual: type string, value "abc"', lu.assertIsNumber, 'abc' ) - assertFailureEquals( 'Expected: a number value, actual: type nil, value nil', lu.assertIsNumber, nil ) - end - - function TestLuaUnitErrorMsg:test_assertIsString() - assertFailureEquals( 'Expected: a string value, actual: type number, value 1.2', lu.assertIsString, 1.2 ) - assertFailureEquals( 'Expected: a string value, actual: type nil, value nil', lu.assertIsString, nil ) - end - - function TestLuaUnitErrorMsg:test_assertIsTable() - assertFailureEquals( 'Expected: a table value, actual: type number, value 1.2', lu.assertIsTable, 1.2 ) - assertFailureEquals( 'Expected: a table value, actual: type nil, value nil', lu.assertIsTable, nil ) - end - - function TestLuaUnitErrorMsg:test_assertIsBoolean() - assertFailureEquals( 'Expected: a boolean value, actual: type number, value 1.2', lu.assertIsBoolean, 1.2 ) - assertFailureEquals( 'Expected: a boolean value, actual: type nil, value nil', lu.assertIsBoolean, nil ) - end - - function TestLuaUnitErrorMsg:test_assertIsFunction() - assertFailureEquals( 'Expected: a function value, actual: type number, value 1.2', lu.assertIsFunction, 1.2 ) - assertFailureEquals( 'Expected: a function value, actual: type nil, value nil', lu.assertIsFunction, nil ) - end - - function TestLuaUnitErrorMsg:test_assertIsThread() - assertFailureEquals( 'Expected: a thread value, actual: type number, value 1.2', lu.assertIsThread, 1.2 ) - assertFailureEquals( 'Expected: a thread value, actual: type nil, value nil', lu.assertIsThread, nil ) - end - - function TestLuaUnitErrorMsg:test_assertIsUserdata() - assertFailureEquals( 'Expected: a userdata value, actual: type number, value 1.2', lu.assertIsUserdata, 1.2 ) - assertFailureEquals( 'Expected: a userdata value, actual: type nil, value nil', lu.assertIsUserdata, nil ) - end - - function TestLuaUnitErrorMsg:test_assertNotIsNumber() - assertFailureEquals( 'Not expected: a number type, actual: value 123', lu.assertNotIsNumber, 123 ) - end - - function TestLuaUnitErrorMsg:test_assertNotIsString() - assertFailureEquals( 'Not expected: a string type, actual: value "abc"', lu.assertNotIsString, "abc" ) - end - - function TestLuaUnitErrorMsg:test_assertNotIsTable() - assertFailureEquals( 'Not expected: a table type, actual: value {1, 2, 3}', lu.assertNotIsTable, {1,2,3} ) - end - - function TestLuaUnitErrorMsg:test_assertNotIsBoolean() - assertFailureEquals( 'Not expected: a boolean type, actual: value false', lu.assertNotIsBoolean, false ) - end - - function TestLuaUnitErrorMsg:test_assertNotIsFunction() - assertFailureContains( 'Not expected: a function type, actual: value function:', lu.assertNotIsFunction, function() return true end ) - end - - function TestLuaUnitErrorMsg:test_assertNotIsThread() - assertFailureContains( 'Not expected: a thread type, actual: value thread:', lu.assertNotIsThread, coroutine.create( function(v) local y=v+1 end ) ) - end - - --[[ How do you create UserData ? - function TestLuaUnitErrorMsg:test_assertIsNotUserdata() - assertFailureEquals( 'Not expected: a userdata type, actual: value XXX ???', lu.assertIsNotUserdata, XXX ??? ) - end - ]] - - function TestLuaUnitErrorMsg:test_assertIs() - assertFailureEquals( 'Expected object and actual object are not the same\nExpected: 1, actual: 2', lu.assertIs, 2, 1 ) - lu.ORDER_ACTUAL_EXPECTED = false - assertFailureEquals( 'Expected object and actual object are not the same\nExpected: 2, actual: 1', lu.assertIs, 2, 1 ) - end - - function TestLuaUnitErrorMsg:test_assertNotIs() - local v = {1,2} - assertFailureMatches( 'Expected object and actual object are the same object: {1, 2}', lu.assertNotIs, v, v ) - lu.ORDER_ACTUAL_EXPECTED = false -- order shouldn't matter here, but let's cover it - assertFailureMatches( 'Expected object and actual object are the same object: {1, 2}', lu.assertNotIs, v, v ) - end - - function TestLuaUnitErrorMsg:test_assertItemsEquals() - assertFailureMatches('Contents of the tables are not identical:\nExpected: {one=2, two=3}\nActual: {1, 2}' , lu.assertItemsEquals, {1,2}, {one=2, two=3} ) - assertFailureContains('Contents of the tables are not identical' , lu.assertItemsEquals, {}, {1} ) -- actual table empty, = doesn't contain expected value - assertFailureContains('Contents of the tables are not identical' , lu.assertItemsEquals, nil, 'foobar' ) -- type mismatch - assertFailureContains('Contents of the tables are not identical' , lu.assertItemsEquals, 'foo', 'bar' ) -- value mismatch - end - - function TestLuaUnitErrorMsg:test_assertError() - assertFailureEquals('Expected an error when calling function but no error generated' , lu.assertError, function( v ) local y = v+1 end, 3 ) - end - - function TestLuaUnitErrorMsg:test_assertErrorMsg() - assertFailureEquals('No error generated when calling function but expected error: "bla bla bla"' , lu.assertErrorMsgEquals, 'bla bla bla', function( v ) local y = v+1 end, 3 ) - assertFailureEquals('No error generated when calling function but expected error containing: "bla bla bla"' , lu.assertErrorMsgContains, 'bla bla bla', function( v ) local y = v+1 end, 3 ) - assertFailureEquals('No error generated when calling function but expected error matching: "bla bla bla"' , lu.assertErrorMsgMatches, 'bla bla bla', function( v ) local y = v+1 end, 3 ) - - assertFailureEquals('Exact error message expected: "bla bla bla"\nError message received: "toto xxx"\n' , lu.assertErrorMsgEquals, 'bla bla bla', function( v ) error('toto xxx',2) end, 3 ) - assertFailureEquals('Error message does not contain: "bla bla bla"\nError message received: "toto xxx"\n' , lu.assertErrorMsgContains, 'bla bla bla', function( v ) error('toto xxx',2) end, 3 ) - assertFailureEquals('Error message does not match: "bla bla bla"\nError message received: "toto xxx"\n' , lu.assertErrorMsgMatches, 'bla bla bla', function( v ) error('toto xxx',2) end, 3 ) - - end - - function TestLuaUnitErrorMsg:test_printTableWithRef() - lu.PRINT_TABLE_REF_IN_ERROR_MSG = true - assertFailureMatches( 'Received the not expected value: {1, 2}', lu.assertNotEquals, {1,2}, {1,2} ) - -- trigger multiline prettystr - assertFailureMatches( 'Received the not expected value: {1, 2, 3, 4}', lu.assertNotEquals, {1,2,3,4}, {1,2,3,4} ) - assertFailureMatches( 'expected: false, actual: {}', lu.assertFalse, {}) - local v = {1,2} - assertFailureMatches( 'Expected object and actual object are the same object: {1, 2}', lu.assertNotIs, v, v ) - assertFailureMatches('Contents of the tables are not identical:\nExpected: {one=2, two=3}\nActual: {1, 2}' , lu.assertItemsEquals, {1,2}, {one=2, two=3} ) - assertFailureMatches( 'expected: {1, 2, 3}\nactual: {3, 2, 1}', lu.assertEquals, {3,2,1}, {1,2,3} ) - -- trigger multiline prettystr - assertFailureMatches( 'expected: {1, 2, 3, 4}\nactual: {3, 2, 1, 4}', lu.assertEquals, {3,2,1,4}, {1,2,3,4} ) - assertFailureMatches( 'expected: {one=1, two=2}\nactual: {3, 2, 1}', lu.assertEquals, {3,2,1}, {one=1,two=2} ) - end - ------------------------------------------------------------------- --- --- Execution Tests --- ------------------------------------------------------------------- - -local executedTests - -MyTestToto1 = {} --class - function MyTestToto1:test1() table.insert( executedTests, "MyTestToto1:test1" ) end - function MyTestToto1:testb() table.insert( executedTests, "MyTestToto1:testb" ) end - function MyTestToto1:test3() table.insert( executedTests, "MyTestToto1:test3" ) end - function MyTestToto1:testa() table.insert( executedTests, "MyTestToto1:testa" ) end - function MyTestToto1:test2() table.insert( executedTests, "MyTestToto1:test2" ) end - -MyTestToto2 = {} --class - function MyTestToto2:test1() table.insert( executedTests, "MyTestToto2:test1" ) end - -MyTestWithErrorsAndFailures = {} --class - function MyTestWithErrorsAndFailures:testWithFailure1() lu.assertEquals(1, 2) end - function MyTestWithErrorsAndFailures:testWithFailure2() lu.assertError( function() end ) end - function MyTestWithErrorsAndFailures:testWithError1() error('some error') end - function MyTestWithErrorsAndFailures:testOk() end - -MyTestOk = {} --class - function MyTestOk:testOk1() end - function MyTestOk:testOk2() end - -function MyTestFunction() - table.insert( executedTests, "MyTestFunction" ) -end - -TestLuaUnitExecution = { __class__ = 'TestLuaUnitExecution' } - - function TestLuaUnitExecution:tearDown() - executedTests = {} - lu.LuaUnit.isTestName = lu.LuaUnit.isTestNameOld - end - - function TestLuaUnitExecution:setUp() - executedTests = {} - lu.LuaUnit.isTestNameOld = lu.LuaUnit.isTestName - lu.LuaUnit.isTestName = function( s ) return (string.sub(s,1,6) == 'MyTest') end - end - - function TestLuaUnitExecution:test_collectTests() - local allTests = lu.LuaUnit.collectTests() - lu.assertEquals( allTests, {"MyTestFunction", "MyTestOk", "MyTestToto1", "MyTestToto2","MyTestWithErrorsAndFailures"}) - end - - function TestLuaUnitExecution:test_MethodsAreExecutedInRightOrder() - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuite( 'MyTestToto1' ) - lu.assertEquals( #executedTests, 5 ) - lu.assertEquals( executedTests[1], "MyTestToto1:test1" ) - lu.assertEquals( executedTests[2], "MyTestToto1:test2" ) - lu.assertEquals( executedTests[3], "MyTestToto1:test3" ) - lu.assertEquals( executedTests[4], "MyTestToto1:testa" ) - lu.assertEquals( executedTests[5], "MyTestToto1:testb" ) - end - - function TestLuaUnitExecution:test_runSuiteByNames() - -- note: this also test that names are executed in explicit order - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByNames( { 'MyTestToto2', 'MyTestToto1', 'MyTestFunction' } ) - lu.assertEquals( #executedTests, 7 ) - lu.assertEquals( executedTests[1], "MyTestToto2:test1" ) - lu.assertEquals( executedTests[2], "MyTestToto1:test1" ) - lu.assertEquals( executedTests[7], "MyTestFunction" ) - end - - function TestLuaUnitExecution:testRunSomeTestByGlobalInstance( ) - lu.assertEquals( #executedTests, 0 ) - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'Toto', MyTestToto1 } } ) - lu.assertEquals( #executedTests, 5 ) - - lu.assertEquals( #runner.result.tests, 5 ) - lu.assertEquals( runner.result.tests[1].testName, "Toto.test1" ) - lu.assertEquals( runner.result.tests[5].testName, "Toto.testb" ) - end - - function TestLuaUnitExecution:testRunSomeTestByLocalInstance( ) - local MyLocalTestToto1 = {} --class - function MyLocalTestToto1:test1() table.insert( executedTests, "MyLocalTestToto1:test1" ) end - local MyLocalTestToto2 = {} --class - function MyLocalTestToto2:test1() table.insert( executedTests, "MyLocalTestToto2:test1" ) end - function MyLocalTestToto2:test2() table.insert( executedTests, "MyLocalTestToto2:test2" ) end - local function MyLocalTestFunction() table.insert( executedTests, "MyLocalTestFunction" ) end - - lu.assertEquals( #executedTests, 0 ) - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { - { 'MyLocalTestToto1', MyLocalTestToto1 }, - { 'MyLocalTestToto2.test2', MyLocalTestToto2 }, - { 'MyLocalTestFunction', MyLocalTestFunction }, - } ) - lu.assertEquals( #executedTests, 3 ) - lu.assertEquals( executedTests[1], 'MyLocalTestToto1:test1') - lu.assertEquals( executedTests[2], 'MyLocalTestToto2:test2') - lu.assertEquals( executedTests[3], 'MyLocalTestFunction') - end - - function TestLuaUnitExecution:testRunReturnsNumberOfFailures() - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - local ret = runner:runSuite( 'MyTestWithErrorsAndFailures' ) - lu.assertEquals(ret, 3) - - ret = runner:runSuite( 'MyTestToto1' ) - lu.assertEquals(ret, 0) - end - - function TestLuaUnitExecution:testTestCountAndFailCount() - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuite( 'MyTestWithErrorsAndFailures' ) - lu.assertEquals( runner.result.testCount, 4) - lu.assertEquals( runner.result.notPassedCount, 3) - lu.assertEquals( runner.result.failureCount, 2) - lu.assertEquals( runner.result.errorCount, 1) - - runner:runSuite( 'MyTestToto1' ) - lu.assertEquals( runner.result.testCount, 5) - lu.assertEquals( runner.result.notPassedCount, 0) - lu.assertEquals( runner.result.failureCount, 0) - lu.assertEquals( runner.result.errorCount, 0) - end - - function TestLuaUnitExecution:testRunSetupAndTeardown() - local myExecutedTests = {} - local MyTestWithSetupTeardown = {} - function MyTestWithSetupTeardown:setUp() table.insert( myExecutedTests, '1setUp' ) end - function MyTestWithSetupTeardown:test1() table.insert( myExecutedTests, '1test1' ) end - function MyTestWithSetupTeardown:test2() table.insert( myExecutedTests, '1test2' ) end - function MyTestWithSetupTeardown:tearDown() table.insert( myExecutedTests, '1tearDown' ) end - - local MyTestWithSetupTeardown2 = {} - function MyTestWithSetupTeardown2:setUp() table.insert( myExecutedTests, '2setUp' ) end - function MyTestWithSetupTeardown2:test1() table.insert( myExecutedTests, '2test1' ) end - function MyTestWithSetupTeardown2:tearDown() table.insert( myExecutedTests, '2tearDown' ) end - - local MyTestWithSetupTeardown3 = {} - function MyTestWithSetupTeardown3:Setup() table.insert( myExecutedTests, '3Setup' ) end - function MyTestWithSetupTeardown3:test1() table.insert( myExecutedTests, '3test1' ) end - function MyTestWithSetupTeardown3:Teardown() table.insert( myExecutedTests, '3Teardown' ) end - - local MyTestWithSetupTeardown4 = {} - function MyTestWithSetupTeardown4:setup() table.insert( myExecutedTests, '4setup' ) end - function MyTestWithSetupTeardown4:test1() table.insert( myExecutedTests, '4test1' ) end - function MyTestWithSetupTeardown4:teardown() table.insert( myExecutedTests, '4teardown' ) end - - local MyTestWithSetupTeardown5 = {} - function MyTestWithSetupTeardown5:SetUp() table.insert( myExecutedTests, '5SetUp' ) end - function MyTestWithSetupTeardown5:test1() table.insert( myExecutedTests, '5test1' ) end - function MyTestWithSetupTeardown5:TearDown() table.insert( myExecutedTests, '5TearDown' ) end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupTeardown.test1', MyTestWithSetupTeardown } } ) - lu.assertEquals( runner.result.notPassedCount, 0 ) - lu.assertEquals( myExecutedTests[1], '1setUp' ) - lu.assertEquals( myExecutedTests[2], '1test1') - lu.assertEquals( myExecutedTests[3], '1tearDown') - lu.assertEquals( #myExecutedTests, 3) - - myExecutedTests = {} - runner:runSuiteByInstances( { - { 'MyTestWithSetupTeardown', MyTestWithSetupTeardown }, - { 'MyTestWithSetupTeardown2', MyTestWithSetupTeardown2 }, - { 'MyTestWithSetupTeardown3', MyTestWithSetupTeardown3 }, - { 'MyTestWithSetupTeardown4', MyTestWithSetupTeardown4 }, - { 'MyTestWithSetupTeardown5', MyTestWithSetupTeardown5 } - } ) - lu.assertEquals( runner.result.notPassedCount, 0 ) - lu.assertEquals( myExecutedTests[1], '1setUp' ) - lu.assertEquals( myExecutedTests[2], '1test1') - lu.assertEquals( myExecutedTests[3], '1tearDown') - lu.assertEquals( myExecutedTests[4], '1setUp' ) - lu.assertEquals( myExecutedTests[5], '1test2') - lu.assertEquals( myExecutedTests[6], '1tearDown') - lu.assertEquals( myExecutedTests[7], '2setUp' ) - lu.assertEquals( myExecutedTests[8], '2test1') - lu.assertEquals( myExecutedTests[9], '2tearDown') - lu.assertEquals( myExecutedTests[10], '3Setup') - lu.assertEquals( myExecutedTests[11], '3test1') - lu.assertEquals( myExecutedTests[12], '3Teardown') - lu.assertEquals( myExecutedTests[13], '4setup') - lu.assertEquals( myExecutedTests[14], '4test1') - lu.assertEquals( myExecutedTests[15], '4teardown') - lu.assertEquals( myExecutedTests[16], '5SetUp') - lu.assertEquals( myExecutedTests[17], '5test1') - lu.assertEquals( myExecutedTests[18], '5TearDown') - lu.assertEquals( #myExecutedTests, 18) - end - - function TestLuaUnitExecution:testWithSetupTeardownFailure1() - local myExecutedTests = {} - - local MyTestWithSetupFailure = {} - function MyTestWithSetupFailure:setUp() table.insert( myExecutedTests, 'setUp' ) lu.assertEquals( 'b', 'c') end - function MyTestWithSetupFailure:test1() table.insert( myExecutedTests, 'test1' ) end - function MyTestWithSetupFailure:tearDown() table.insert( myExecutedTests, 'tearDown' ) end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupFailure', MyTestWithSetupFailure } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - lu.assertEquals( runner.result.failureCount, 1 ) - lu.assertEquals( runner.result.errorCount, 0 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'tearDown') - lu.assertEquals( #myExecutedTests, 2) - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.FAIL ) - end - - function TestLuaUnitExecution:testWithSetupTeardownFailure2() - local myExecutedTests = {} - - local MyTestWithSetupFailure = {} - function MyTestWithSetupFailure:setUp() table.insert( myExecutedTests, 'setUp' ) end - function MyTestWithSetupFailure:test1() table.insert( myExecutedTests, 'test1' ) end - function MyTestWithSetupFailure:tearDown() table.insert( myExecutedTests, 'tearDown' ) lu.assertEquals( 'b', 'c') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupFailure', MyTestWithSetupFailure } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - lu.assertEquals( runner.result.failureCount, 1 ) - lu.assertEquals( runner.result.errorCount, 0 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'test1' ) - lu.assertEquals( myExecutedTests[3], 'tearDown') - lu.assertEquals( #myExecutedTests, 3) - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.FAIL ) - end - - function TestLuaUnitExecution:testWithSetupTeardownFailure3() - local myExecutedTests = {} - - local MyTestWithSetupFailure = {} - function MyTestWithSetupFailure:setUp() table.insert( myExecutedTests, 'setUp' ) lu.assertEquals( 'b', 'c') end - function MyTestWithSetupFailure:test1() table.insert( myExecutedTests, 'test1' ) end - function MyTestWithSetupFailure:tearDown() table.insert( myExecutedTests, 'tearDown' ) lu.assertEquals( 'b', 'c') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupFailure', MyTestWithSetupFailure } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - -- Note: in the future, we may want to report two failures for this - lu.assertEquals( runner.result.failureCount, 1 ) - lu.assertEquals( runner.result.errorCount, 0 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'tearDown') - lu.assertEquals( #myExecutedTests, 2) - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.FAIL ) - end - - function TestLuaUnitExecution:testWithSetupTeardownFailure4() - local myExecutedTests = {} - - local MyTestWithSetupFailure = {} - function MyTestWithSetupFailure:setUp() table.insert( myExecutedTests, 'setUp' ) lu.assertEquals( 'b', 'c') end - function MyTestWithSetupFailure:test1() table.insert( myExecutedTests, 'test1' ) lu.assertEquals( 'b', 'c') end - function MyTestWithSetupFailure:tearDown() table.insert( myExecutedTests, 'tearDown' ) lu.assertEquals( 'b', 'c') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupFailure', MyTestWithSetupFailure } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - -- Note: in the future, we may want to report two failures for this - lu.assertEquals( runner.result.failureCount, 1 ) - lu.assertEquals( runner.result.errorCount, 0 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'tearDown') - lu.assertEquals( #myExecutedTests, 2) - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.FAIL ) - end - - function TestLuaUnitExecution:testWithSetupTeardownFailure5() - local myExecutedTests = {} - - local MyTestWithSetupFailure = {} - function MyTestWithSetupFailure:setUp() table.insert( myExecutedTests, 'setUp' ) end - function MyTestWithSetupFailure:test1() table.insert( myExecutedTests, 'test1' ) lu.assertEquals( 'b', 'c') end - function MyTestWithSetupFailure:tearDown() table.insert( myExecutedTests, 'tearDown' ) lu.assertEquals( 'b', 'c') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupFailure', MyTestWithSetupFailure } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - -- Note: in the future, we may want to report two failures for this - lu.assertEquals( runner.result.failureCount, 1 ) - lu.assertEquals( runner.result.errorCount, 0 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'test1' ) - lu.assertEquals( myExecutedTests[3], 'tearDown') - lu.assertEquals( #myExecutedTests, 3) - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.FAIL ) - end - - function TestLuaUnitExecution:testWithSetupTeardownErrors1() - local myExecutedTests = {} - - local MyTestWithSetupError = {} - function MyTestWithSetupError:setUp() table.insert( myExecutedTests, 'setUp' ) error('setup error') end - function MyTestWithSetupError:test1() table.insert( myExecutedTests, 'test1' ) end - function MyTestWithSetupError:tearDown() table.insert( myExecutedTests, 'tearDown' ) end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupError', MyTestWithSetupError } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - lu.assertEquals( runner.result.failureCount, 0 ) - lu.assertEquals( runner.result.errorCount, 1 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'tearDown') - lu.assertEquals( #myExecutedTests, 2) - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.ERROR ) - end - - function TestLuaUnitExecution:testWithSetupTeardownErrors2() - local myExecutedTests = {} - - local MyTestWithSetupError = {} - function MyTestWithSetupError:setUp() table.insert( myExecutedTests, 'setUp' ) end - function MyTestWithSetupError:test1() table.insert( myExecutedTests, 'test1' ) end - function MyTestWithSetupError:tearDown() table.insert( myExecutedTests, 'tearDown' ) error('teardown error') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupError', MyTestWithSetupError } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - lu.assertEquals( runner.result.failureCount, 0 ) - lu.assertEquals( runner.result.errorCount, 1 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'test1' ) - lu.assertEquals( myExecutedTests[3], 'tearDown') - lu.assertEquals( #myExecutedTests, 3) - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.ERROR ) - end - - function TestLuaUnitExecution:testWithSetupTeardownErrors3() - local myExecutedTests = {} - - local MyTestWithSetupError = {} - function MyTestWithSetupError:setUp() table.insert( myExecutedTests, 'setUp' ) error('setup error') end - function MyTestWithSetupError:test1() table.insert( myExecutedTests, 'test1' ) end - function MyTestWithSetupError:tearDown() table.insert( myExecutedTests, 'tearDown' ) error('teardown error') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupError', MyTestWithSetupError } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - -- Note: in the future, we may want to report two errors for this - lu.assertEquals( runner.result.failureCount, 0 ) - lu.assertEquals( runner.result.errorCount, 1 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'tearDown') - lu.assertEquals( #myExecutedTests, 2) - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.ERROR ) - end - - function TestLuaUnitExecution:testWithSetupTeardownErrors4() - local myExecutedTests = {} - - local MyTestWithSetupError = {} - function MyTestWithSetupError:setUp() table.insert( myExecutedTests, 'setUp' ) error('setup error') end - function MyTestWithSetupError:test1() table.insert( myExecutedTests, 'test1' ) error('test error') end - function MyTestWithSetupError:tearDown() table.insert( myExecutedTests, 'tearDown' ) error('teardown error') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupError', MyTestWithSetupError } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - -- Note: in the future, we may want to report two errors for this - lu.assertEquals( runner.result.failureCount, 0 ) - lu.assertEquals( runner.result.errorCount, 1 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'tearDown') - lu.assertEquals( #myExecutedTests, 2) - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.ERROR ) - end - - function TestLuaUnitExecution:testWithSetupTeardownErrors5() - local myExecutedTests = {} - - local MyTestWithSetupError = {} - function MyTestWithSetupError:setUp() table.insert( myExecutedTests, 'setUp' ) end - function MyTestWithSetupError:test1() table.insert( myExecutedTests, 'test1' ) error('test error') end - function MyTestWithSetupError:tearDown() table.insert( myExecutedTests, 'tearDown' ) error('teardown error') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupError', MyTestWithSetupError } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - -- Note: in the future, we may want to report two errors for this - lu.assertEquals( runner.result.failureCount, 0 ) - lu.assertEquals( runner.result.errorCount, 1 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'test1' ) - lu.assertEquals( myExecutedTests[3], 'tearDown') - lu.assertEquals( #myExecutedTests, 3) - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.ERROR ) - end - - function TestLuaUnitExecution:testWithSetupTeardownErrorsAndFailures1() - local myExecutedTests = {} - - local MyTestWithSetupError = {} - function MyTestWithSetupError:setUp() table.insert( myExecutedTests, 'setUp' ) lu.assertEquals( 'a', 'b') end - function MyTestWithSetupError:test1() table.insert( myExecutedTests, 'test1' ) end - function MyTestWithSetupError:tearDown() table.insert( myExecutedTests, 'tearDown' ) error('teardown error') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupError', MyTestWithSetupError } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - -- Note: in the future, we may want to report failure + error for this - lu.assertEquals( runner.result.failureCount, 1 ) - lu.assertEquals( runner.result.errorCount, 0 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'tearDown') - lu.assertEquals( #myExecutedTests, 2) - -- The first error/failure set the whole test status - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.FAIL ) - end - - function TestLuaUnitExecution:testWithSetupTeardownErrorsAndFailures2() - local myExecutedTests = {} - - local MyTestWithSetupError = {} - function MyTestWithSetupError:setUp() table.insert( myExecutedTests, 'setUp' ) error('setup error') end - function MyTestWithSetupError:test1() table.insert( myExecutedTests, 'test1' ) end - function MyTestWithSetupError:tearDown() table.insert( myExecutedTests, 'tearDown' ) lu.assertEquals( 'a', 'b') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupError', MyTestWithSetupError } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - -- Note: in the future, we may want to report failure + error for this - lu.assertEquals( runner.result.failureCount, 0 ) - lu.assertEquals( runner.result.errorCount, 1 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'tearDown') - lu.assertEquals( #myExecutedTests, 2) - -- The first error/failure set the whole test status - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.ERROR ) - end - - function TestLuaUnitExecution:testWithSetupTeardownErrorsAndFailures3() - local myExecutedTests = {} - - local MyTestWithSetupError = {} - function MyTestWithSetupError:setUp() table.insert( myExecutedTests, 'setUp' ) end - function MyTestWithSetupError:test1() table.insert( myExecutedTests, 'test1' ) error('test error') end - function MyTestWithSetupError:tearDown() table.insert( myExecutedTests, 'tearDown' ) lu.assertEquals( 'a', 'b') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupError', MyTestWithSetupError } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - -- Note: in the future, we may want to report failure + error for this - lu.assertEquals( runner.result.failureCount, 0 ) - lu.assertEquals( runner.result.errorCount, 1 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'test1' ) - lu.assertEquals( myExecutedTests[3], 'tearDown') - lu.assertEquals( #myExecutedTests, 3) - -- The first error/failure set the whole test status - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.ERROR ) - end - - function TestLuaUnitExecution:testWithSetupTeardownErrorsAndFailures4() - local myExecutedTests = {} - - local MyTestWithSetupError = {} - function MyTestWithSetupError:setUp() table.insert( myExecutedTests, 'setUp' ) end - function MyTestWithSetupError:test1() table.insert( myExecutedTests, 'test1' ) lu.assertEquals( 'a', 'b') end - function MyTestWithSetupError:tearDown() table.insert( myExecutedTests, 'tearDown' ) error('teardown error') end - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuiteByInstances( { { 'MyTestWithSetupError', MyTestWithSetupError } } ) - lu.assertEquals( runner.result.notPassedCount, 1 ) - -- Note: in the future, we may want to report failure + error for this - lu.assertEquals( runner.result.failureCount, 1 ) - lu.assertEquals( runner.result.errorCount, 0 ) - lu.assertEquals( runner.result.testCount, 1 ) - lu.assertEquals( myExecutedTests[1], 'setUp' ) - lu.assertEquals( myExecutedTests[2], 'test1' ) - lu.assertEquals( myExecutedTests[3], 'tearDown') - lu.assertEquals( #myExecutedTests, 3) - -- The first error/failure set the whole test status - lu.assertEquals( runner.result.notPassed[1].status, lu.NodeStatus.FAIL ) - end - - - - function TestLuaUnitExecution:testOutputInterface() - local runner = lu.LuaUnit.new() - runner.outputType = Mock - runner:runSuite( 'MyTestWithErrorsAndFailures', 'MyTestOk' ) - local m = runner.output - - lu.assertEquals( m.calls[1][1], 'startSuite' ) - lu.assertEquals(#m.calls[1], 2 ) - - lu.assertEquals( m.calls[2][1], 'startClass' ) - lu.assertEquals( m.calls[2][3], 'MyTestWithErrorsAndFailures' ) - lu.assertEquals(#m.calls[2], 3 ) - - lu.assertEquals( m.calls[3][1], 'startTest' ) - lu.assertEquals( m.calls[3][3], 'MyTestWithErrorsAndFailures.testOk' ) - lu.assertEquals(#m.calls[3], 3 ) - - lu.assertEquals( m.calls[4][1], 'endTest' ) - lu.assertEquals(#m.calls[4], 3 ) - lu.assertIsTable( m.calls[4][3] ) - lu.assertEquals( m.calls[4][3].status, lu.NodeStatus.PASS ) - - lu.assertEquals( m.calls[5][1], 'startTest' ) - lu.assertEquals( m.calls[5][3], 'MyTestWithErrorsAndFailures.testWithError1' ) - lu.assertEquals(#m.calls[5], 3 ) - - lu.assertEquals( m.calls[6][1], 'addStatus' ) - lu.assertEquals(#m.calls[6], 3 ) - - lu.assertEquals( m.calls[7][1], 'endTest' ) - lu.assertEquals(#m.calls[7], 3 ) - lu.assertIsTable( m.calls[7][3] ) - lu.assertEquals( m.calls[7][3].status, lu.NodeStatus.ERROR ) - - - lu.assertEquals( m.calls[8][1], 'startTest' ) - lu.assertEquals( m.calls[8][3], 'MyTestWithErrorsAndFailures.testWithFailure1' ) - lu.assertEquals(#m.calls[8], 3 ) - - lu.assertEquals( m.calls[9][1], 'addStatus' ) - lu.assertEquals(#m.calls[9], 3 ) - - lu.assertEquals( m.calls[10][1], 'endTest' ) - lu.assertEquals(#m.calls[10], 3 ) - lu.assertIsTable( m.calls[10][3] ) - lu.assertEquals( m.calls[10][3].status, lu.NodeStatus.FAIL ) - - lu.assertEquals( m.calls[11][1], 'startTest' ) - lu.assertEquals( m.calls[11][3], 'MyTestWithErrorsAndFailures.testWithFailure2' ) - lu.assertEquals(#m.calls[11], 3 ) - - lu.assertEquals( m.calls[12][1], 'addStatus' ) - lu.assertEquals(#m.calls[12], 3 ) - - lu.assertEquals( m.calls[13][1], 'endTest' ) - lu.assertEquals(#m.calls[13], 3 ) - lu.assertIsTable(m.calls[13][3] ) - lu.assertEquals( m.calls[13][3].status, lu.NodeStatus.FAIL ) - - lu.assertEquals( m.calls[14][1], 'endClass' ) - lu.assertEquals(#m.calls[14], 2 ) - - lu.assertEquals( m.calls[15][1], 'startClass' ) - lu.assertEquals( m.calls[15][3], 'MyTestOk' ) - lu.assertEquals(#m.calls[15], 3 ) - - lu.assertEquals( m.calls[16][1], 'startTest' ) - lu.assertEquals( m.calls[16][3], 'MyTestOk.testOk1' ) - lu.assertEquals(#m.calls[16], 3 ) - - lu.assertEquals( m.calls[17][1], 'endTest' ) - lu.assertEquals(#m.calls[17], 3 ) - lu.assertIsTable( m.calls[17][3] ) - lu.assertEquals( m.calls[17][3].status, lu.NodeStatus.PASS ) - - lu.assertEquals( m.calls[18][1], 'startTest' ) - lu.assertEquals( m.calls[18][3], 'MyTestOk.testOk2' ) - lu.assertEquals(#m.calls[18], 3 ) - - lu.assertEquals( m.calls[19][1], 'endTest' ) - lu.assertEquals(#m.calls[19], 3 ) - lu.assertIsTable( m.calls[19][3] ) - lu.assertEquals( m.calls[19][3].status, lu.NodeStatus.PASS ) - - lu.assertEquals( m.calls[20][1], 'endClass' ) - lu.assertEquals(#m.calls[20], 2 ) - - lu.assertEquals( m.calls[21][1], 'endSuite' ) - lu.assertEquals(#m.calls[21], 2 ) - - lu.assertEquals( m.calls[22], nil ) - - end - - function TestLuaUnitExecution:testInvocation() - - local runner = lu.LuaUnit.new() - - -- test alternative "object" syntax for run(), passing self - runner:run('--output', 'nil', 'MyTestOk') - -- select class instance by name - runner.run('--output', 'nil', 'MyTestOk.testOk2') - - -- check error handling - lu.assertErrorMsgContains('No such name in global space', - runner.runSuite, runner, 'foobar') - lu.assertErrorMsgContains('Name must match a function or a table', - runner.runSuite, runner, '_VERSION') - lu.assertErrorMsgContains('No such name in global space', - runner.runSuite, runner, 'foo.bar') - lu.assertErrorMsgContains('must be a function, not', - runner.runSuite, runner, '_G._VERSION') - lu.assertErrorMsgContains('Could not find method in class', - runner.runSuite, runner, 'MyTestOk.foobar') - lu.assertErrorMsgContains('Instance must be a table or a function', - runner.expandClasses, {{'foobar', 'INVALID'}}) - lu.assertErrorMsgContains('Could not find method in class', - runner.expandClasses, {{'MyTestOk.foobar', {}}}) - end - - function TestLuaUnitExecution:test_filterWithPattern() - - local runner = lu.LuaUnit.new() - runner:setOutputType( "NIL" ) - runner:runSuite('-p', 'Function', '-p', 'Toto.' ) - lu.assertEquals( executedTests[1], "MyTestFunction" ) - lu.assertEquals( executedTests[2], "MyTestToto1:test1" ) - lu.assertEquals( executedTests[3], "MyTestToto1:test2" ) - lu.assertEquals( executedTests[4], "MyTestToto1:test3" ) - lu.assertEquals( executedTests[5], "MyTestToto1:testa" ) - lu.assertEquals( executedTests[6], "MyTestToto1:testb" ) - lu.assertEquals( executedTests[7], "MyTestToto2:test1" ) - lu.assertEquals( #executedTests, 7) - end - - - ------------------------------------------------------------------- --- --- Results Tests --- ------------------------------------------------------------------- - -TestLuaUnitResults = { __class__ = 'TestLuaUnitResults' } - - function TestLuaUnitResults:tearDown() - executedTests = {} - lu.LuaUnit.isTestName = lu.LuaUnit.isTestNameOld - end - - function TestLuaUnitResults:setUp() - executedTests = {} - lu.LuaUnit.isTestNameOld = lu.LuaUnit.isTestName - lu.LuaUnit.isTestName = function( s ) return (string.sub(s,1,6) == 'MyTest') end - end - - function TestLuaUnitResults:test_statusLine() - -- full success - local r = {runCount=5, duration=0.17, passedCount=5, notPassedCount=0, failureCount=0, errorCount=0, nonSelectedCount=0} - lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 5 successes, 0 failures') - - -- 1 failure, nothing more displayed - r = {runCount=5, duration=0.17, passedCount=4, notPassedCount=1, failureCount=1, errorCount=0, nonSelectedCount=0} - lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 4 successes, 1 failure') - - -- 1 error, no failure displayed - r = {runCount=5, duration=0.17, passedCount=4, notPassedCount=1, failureCount=0, errorCount=1, nonSelectedCount=0} - lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 4 successes, 1 error') - - -- 1 error, 1 failure - r = {runCount=5, duration=0.17, passedCount=3, notPassedCount=2, failureCount=1, errorCount=1, nonSelectedCount=0} - lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 3 successes, 1 failure, 1 error') - - -- 1 error, 1 failure, 1 non selected - r = {runCount=5, duration=0.17, passedCount=3, notPassedCount=2, failureCount=1, errorCount=1, nonSelectedCount=1} - lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 3 successes, 1 failure, 1 error, 1 non-selected') - - -- full success, 1 non selected - r = {runCount=5, duration=0.17, passedCount=5, notPassedCount=0, failureCount=0, errorCount=0, nonSelectedCount=1} - lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 5 successes, 0 failures, 1 non-selected') - end - - function TestLuaUnitResults:test_nodeStatus() - local es = lu.NodeStatus.new() - lu.assertEquals( es.status, lu.NodeStatus.PASS ) - lu.assertTrue( es:isPassed() ) - lu.assertNil( es.msg ) - lu.assertNil( es.stackTrace ) - lu.assertStrContains( es:statusXML(), " +License: BSD License, see LICENSE.txt +]]-- + +-- Return a function that appends its arguments to the `callInfo` table +local function callRecorder( callInfo ) + return function( ... ) + for _, v in pairs({...}) do + table.insert( callInfo, v ) + end + end +end + +-- This is a bit tricky since the test uses the features that it tests. + +local function range(start, stop) + -- return list of { start ... stop } + local i + local ret = {} + i=start + while i <= stop do + table.insert(ret, i) + i = i + 1 + end + return ret +end + + +local lu = require('luaunit') + +local Mock = { __class__ = 'Mock' } + +function Mock.new(runner) + local t = lu.genericOutput.new(runner) + t.calls = {} + local t_MT = { + __index = function( tab, key ) + local callInfo = { key } + table.insert( tab.calls, callInfo ) + return callRecorder( callInfo ) + end + } + return setmetatable( t, t_MT ) +end + + +TestMock = {} + function TestMock:testMock() + local m = Mock.new() + m.titi( 42 ) + m.toto( 33, "abc", { 21} ) + lu.assertEquals( m.calls[1][1], 'titi' ) + lu.assertEquals( m.calls[1][2], 42 ) + lu.assertEquals( #m.calls[1], 2 ) + + lu.assertEquals( m.calls[2][1], 'toto' ) + lu.assertEquals( m.calls[2][2], 33 ) + lu.assertEquals( m.calls[2][3], 'abc' ) + lu.assertEquals( m.calls[2][4][1], 21 ) + lu.assertEquals( #m.calls[2], 4 ) + + lu.assertEquals( #m.calls, 2 ) + end + +------------------------------------------------------------------ +-- +-- Utility Tests +-- +------------------------------------------------------------------ + +TestLuaUnitUtilities = { __class__ = 'TestLuaUnitUtilities' } + + function TestLuaUnitUtilities:test_genSortedIndex() + lu.assertEquals( lu.private.__genSortedIndex( { 2, 5, 7} ), {1,2,3} ) + lu.assertEquals( lu.private.__genSortedIndex( { a='1', h='2', c='3' } ), {'a', 'c', 'h'} ) + lu.assertEquals( lu.private.__genSortedIndex( { 1, 'z', a='1', h='2', c='3' } ), { 1, 2, 'a', 'c', 'h' } ) + lu.assertEquals( lu.private.__genSortedIndex( { b=4, a=3, true, foo="bar", nil, bar=false, 42, c=5 } ), + { 1, 3, 'a', 'b', 'bar', 'c', 'foo' } ) + end + + function TestLuaUnitUtilities:test_sortedNextWorks() + local t1 = {} + local _ + t1['aaa'] = 'abc' + t1['ccc'] = 'def' + t1['bbb'] = 'cba' + + -- mimic semantics of "generic for" loop + local sortedNext, state = lu.private.sortedPairs(t1) + + local k, v = sortedNext( state, nil ) + lu.assertEquals( k, 'aaa' ) + lu.assertEquals( v, 'abc' ) + k, v = sortedNext( state, k ) + lu.assertEquals( k, 'bbb' ) + lu.assertEquals( v, 'cba' ) + k, v = sortedNext( state, k ) + lu.assertEquals( k, 'ccc' ) + lu.assertEquals( v, 'def' ) + k, v = sortedNext( state, k ) + lu.assertEquals( k, nil ) + lu.assertEquals( v, nil ) + + -- check if starting the iteration a second time works + k, v = sortedNext( state, nil ) + lu.assertEquals( k, 'aaa' ) + lu.assertEquals( v, 'abc' ) + + -- run a generic for loop (internally using a separate state) + local tested = {} + for _, v in lu.private.sortedPairs(t1) do table.insert(tested, v) end + lu.assertEquals( tested, {'abc', 'cba', 'def'} ) + + -- test bisection algorithm by searching for non-existing key values + k, v = sortedNext( state, '' ) -- '' would come before any of the keys + lu.assertNil( k ) + lu.assertNil( v ) + k, v = sortedNext( state, 'xyz' ) -- 'xyz' would be after any other key + lu.assertNil( k ) + lu.assertNil( v ) + + -- finally let's see if we successfully find an "out of sequence" key + k, v = sortedNext( state, 'bbb' ) + lu.assertEquals( k, 'ccc' ) + lu.assertEquals( v, 'def' ) + end + + function TestLuaUnitUtilities:test_sortedNextWorksOnTwoTables() + local t1 = { aaa = 'abc', ccc = 'def' } + local t2 = { ['3'] = '33', ['1'] = '11' } + + local sortedNext, state1, state2, _ + _, state1 = lu.private.sortedPairs(t1) + sortedNext, state2 = lu.private.sortedPairs(t2) + + local k, v = sortedNext( state1, nil ) + lu.assertEquals( k, 'aaa' ) + lu.assertEquals( v, 'abc' ) + + k, v = sortedNext( state2, nil ) + lu.assertEquals( k, '1' ) + lu.assertEquals( v, '11' ) + + k, v = sortedNext( state1, 'aaa' ) + lu.assertEquals( k, 'ccc' ) + lu.assertEquals( v, 'def' ) + + k, v = sortedNext( state2, '1' ) + lu.assertEquals( k, '3' ) + lu.assertEquals( v, '33' ) + end + + function TestLuaUnitUtilities:test_randomizeTable() + local t, tref, n = {}, {}, 20 + for i = 1, n do + t[i], tref[i] = i, i + end + lu.assertEquals( #t, n ) + + lu.private.randomizeTable( t ) + lu.assertEquals( #t, n ) + lu.assertNotEquals( t, tref) + table.sort(t) + lu.assertEquals( t, tref ) + end + + function TestLuaUnitUtilities:test_strSplitOneCharDelim() + local t = lu.private.strsplit( '\n', '122333' ) + lu.assertEquals( t[1], '122333') + lu.assertEquals( #t, 1 ) + + local t = lu.private.strsplit( '\n', '1\n22\n333\n' ) + lu.assertEquals( t[1], '1') + lu.assertEquals( t[2], '22') + lu.assertEquals( t[3], '333') + lu.assertEquals( t[4], '') + lu.assertEquals( #t, 4 ) + -- test invalid (empty) delimiter + lu.assertErrorMsgContains('delimiter matches empty string!', + lu.private.strsplit, '', '1\n22\n333\n') + end + + function TestLuaUnitUtilities:test_strSplit3CharDelim() + local t = lu.private.strsplit( '2\n3', '1\n22\n332\n3' ) + lu.assertEquals( t[1], '1\n2') + lu.assertEquals( t[2], '3') + lu.assertEquals( t[3], '') + lu.assertEquals( #t, 3 ) + end + + function TestLuaUnitUtilities:test_protectedCall() + local function boom() error("Something went wrong.") end + local err = lu.LuaUnit:protectedCall(nil, boom, "kaboom") + + -- check that err received the expected fields + lu.assertEquals(err.status, "ERROR") + lu.assertStrContains(err.msg, "Something went wrong.") + lu.assertStrMatches(err.trace, "^stack traceback:.*in %a+ 'kaboom'.*") + end + + function TestLuaUnitUtilities:test_prefixString() + lu.assertEquals( lu.private.prefixString( '12 ', 'ab\ncd\nde'), '12 ab\n12 cd\n12 de' ) + end + + function TestLuaUnitUtilities:test_is_table_equals() + -- Make sure that _is_table_equals() doesn't fall for these traps + -- (See https://github.com/bluebird75/luaunit/issues/48) + local A, B, C = {}, {}, {} + + A.self = A + B.self = B + lu.assertNotEquals(A, B) + lu.assertEquals(A, A) + + A, B = {}, {} + A.circular = C + B.circular = A + C.circular = B + lu.assertNotEquals(A, B) + lu.assertEquals(C, C) + + A = {} + A[{}] = A + lu.assertEquals( A, A ) + + A = {} + A[A] = 1 + lu.assertEquals( A, A ) + end + + function TestLuaUnitUtilities:test_suitableForMismatchFormatting() + lu.assertFalse( lu.private.tryMismatchFormatting( {1,2}, {2,1} ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( nil, { 1,2,3} ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( {1,2,3}, {} ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( "123", "123" ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( "123", "123" ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( {'a','b','c'}, {'c', 'b', 'a'} )) + lu.assertFalse( lu.private.tryMismatchFormatting( {1,2,3, toto='titi'}, {1,2,3, toto='tata', tutu="bloup" } ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( {1,2,3, [5]=1000}, {1,2,3} ) ) + + local i=0 + local l1, l2={}, {} + while i <= lu.LIST_DIFF_ANALYSIS_THRESHOLD+1 do + i = i + 1 + table.insert( l1, i ) + table.insert( l2, i+1 ) + end + + lu.assertTrue( lu.private.tryMismatchFormatting( l1, l2 ) ) + end + + + function TestLuaUnitUtilities:test_diffAnalysisThreshold() + local threshold = lu.LIST_DIFF_ANALYSIS_THRESHOLD + lu.assertFalse( lu.private.tryMismatchFormatting( range(1,threshold-1), range(1,threshold-2), lu.DEFAULT_DEEP_ANALYSIS ) ) + lu.assertTrue( lu.private.tryMismatchFormatting( range(1,threshold), range(1,threshold), lu.DEFAULT_DEEP_ANALYSIS ) ) + + lu.assertFalse( lu.private.tryMismatchFormatting( range(1,threshold-1), range(1,threshold-2), lu.DISABLE_DEEP_ANALYSIS ) ) + lu.assertFalse( lu.private.tryMismatchFormatting( range(1,threshold), range(1,threshold), lu.DISABLE_DEEP_ANALYSIS ) ) + + lu.assertTrue( lu.private.tryMismatchFormatting( range(1,threshold-1), range(1,threshold-2), lu.FORCE_DEEP_ANALYSIS ) ) + lu.assertTrue( lu.private.tryMismatchFormatting( range(1,threshold), range(1,threshold), lu.FORCE_DEEP_ANALYSIS ) ) + end + + function TestLuaUnitUtilities:test_table_raw_tostring() + local t1 = {'1','2'} + lu.assertStrMatches( tostring(t1), 'table: 0?x?[%x]+' ) + lu.assertStrMatches( lu.private._table_raw_tostring(t1), 'table: 0?x?[%x]+' ) + + local ts = function(t) return t[1]..t[2] end + local mt = { __tostring = ts } + setmetatable( t1, mt ) + lu.assertStrMatches( tostring(t1), '12' ) + lu.assertStrMatches( lu.private._table_raw_tostring(t1), 'table: 0?x?[%x]+' ) + end + + function TestLuaUnitUtilities:test_prettystr_numbers() + lu.assertEquals( lu.prettystr( 1 ), "1" ) + lu.assertEquals( lu.prettystr( 1.0 ), "1" ) + lu.assertEquals( lu.prettystr( 1.1 ), "1.1" ) + lu.assertEquals( lu.prettystr( 1/0 ), "#Inf" ) + lu.assertEquals( lu.prettystr( -1/0 ), "-#Inf" ) + lu.assertEquals( lu.prettystr( 0/0 ), "#NaN" ) + end + + function TestLuaUnitUtilities:test_prettystr_strings() + lu.assertEquals( lu.prettystr( 'abc' ), '"abc"' ) + lu.assertEquals( lu.prettystr( 'ab\ncd' ), '"ab\ncd"' ) + lu.assertEquals( lu.prettystr( 'ab"cd' ), "'ab\"cd'" ) + lu.assertEquals( lu.prettystr( "ab'cd" ), '"ab\'cd"' ) + end + + function TestLuaUnitUtilities:test_prettystr_tables1() + lu.assertEquals( lu.prettystr( {1,2,3} ), "{1, 2, 3}" ) + lu.assertEquals( lu.prettystr( {a=1,bb=2,ab=3} ), '{a=1, ab=3, bb=2}' ) + lu.assertEquals( lu.prettystr( { [{}] = 1 }), '{{}=1}' ) + lu.assertEquals( lu.prettystr( { 1, [{}] = 1, 2 }), '{1, 2, {}=1}' ) + lu.assertEquals( lu.prettystr( { 1, [{one=1}] = 1, 2, "test", false }), '{1, 2, "test", false, {one=1}=1}' ) + end + + function TestLuaUnitUtilities:test_prettystr_tables2() + -- test the (private) key string formatting within _table_tostring() + lu.assertEquals( lu.prettystr( {a = 1} ), '{a=1}' ) + lu.assertEquals( lu.prettystr( {a0 = 2} ), '{a0=2}' ) + lu.assertEquals( lu.prettystr( {['a0!'] = 3} ), '{"a0!"=3}' ) + lu.assertEquals( lu.prettystr( {["foo\nbar"] = 1}), [[{"foo +bar"=1}]] ) + lu.assertEquals( lu.prettystr( {["foo'bar"] = 2}), [[{"foo'bar"=2}]] ) + lu.assertEquals( lu.prettystr( {['foo"bar'] = 3}), [[{'foo"bar'=3}]] ) + end + + function TestLuaUnitUtilities:test_prettystr_tables3() + -- test with a table containing a metatable for __tostring + local t1 = {'1','2'} + lu.assertStrMatches( tostring(t1), 'table: 0?x?[%x]+' ) + lu.assertEquals( lu.prettystr(t1), '{"1", "2"}' ) + + -- add metatable + local function ts(t) return string.format( 'Point<%s,%s>', t[1], t[2] ) end + setmetatable( t1, { __tostring = ts } ) + + lu.assertEquals( tostring(t1), 'Point<1,2>' ) + lu.assertEquals( lu.prettystr(t1), 'Point<1,2>' ) + + local function ts2(t) + return string.format( 'Point:\n x=%s\n y=%s', t[1], t[2] ) + end + + local t2 = {'1','2'} + setmetatable( t2, { __tostring = ts2 } ) + + lu.assertEquals( tostring(t2), [[Point: + x=1 + y=2]] ) + lu.assertEquals( lu.prettystr(t2), [[Point: + x=1 + y=2]] ) + + -- nested table + local t3 = {'3', t1} + lu.assertEquals( lu.prettystr(t3), [[{"3", Point<1,2>}]] ) + + local t4 = {'3', t2} + lu.assertEquals( lu.prettystr(t4), [[{"3", Point: + x=1 + y=2}]] ) + + local t5 = {1,2,{3,4},string.rep('W', lu.LINE_LENGTH), t2, 33} + lu.assertEquals( lu.prettystr(t5), [[{ + 1, + 2, + {3, 4}, + "]]..string.rep('W', lu.LINE_LENGTH)..[[", + Point: + x=1 + y=2, + 33 +}]] ) + end + + function TestLuaUnitUtilities:test_prettystr_adv_tables() + local t1 = {1,2,3,4,5,6} + lu.assertEquals(lu.prettystr(t1), "{1, 2, 3, 4, 5, 6}" ) + + local t2 = {'aaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbb', 'ccccccccccccccccc', 'ddddddddddddd', 'eeeeeeeeeeeeeeeeee', 'ffffffffffffffff', 'ggggggggggg', 'hhhhhhhhhhhhhh'} + lu.assertEquals(lu.prettystr(t2), table.concat( { + '{', + ' "aaaaaaaaaaaaaaaaa",', + ' "bbbbbbbbbbbbbbbbbbbb",', + ' "ccccccccccccccccc",', + ' "ddddddddddddd",', + ' "eeeeeeeeeeeeeeeeee",', + ' "ffffffffffffffff",', + ' "ggggggggggg",', + ' "hhhhhhhhhhhhhh"', + '}', + } , '\n' ) ) + + lu.assertTrue( lu.private.hasNewLine( lu.prettystr(t2)) ) + + local t2bis = { 1,2,3,'12345678901234567890123456789012345678901234567890123456789012345678901234567890', 4,5,6 } + lu.assertEquals(lu.prettystr(t2bis), [[{ + 1, + 2, + 3, + "12345678901234567890123456789012345678901234567890123456789012345678901234567890", + 4, + 5, + 6 +}]] ) + + local t3 = { l1a = { l2a = { l3a='012345678901234567890123456789012345678901234567890123456789' }, + l2b='bbb' }, l1b = 4} + lu.assertEquals(lu.prettystr(t3), [[{ + l1a={ + l2a={l3a="012345678901234567890123456789012345678901234567890123456789"}, + l2b="bbb" + }, + l1b=4 +}]] ) + + local t4 = { a=1, b=2, c=3 } + lu.assertEquals(lu.prettystr(t4), '{a=1, b=2, c=3}' ) + + local t5 = { t1, t2, t3 } + lu.assertEquals( lu.prettystr(t5), [[{ + {1, 2, 3, 4, 5, 6}, + { + "aaaaaaaaaaaaaaaaa", + "bbbbbbbbbbbbbbbbbbbb", + "ccccccccccccccccc", + "ddddddddddddd", + "eeeeeeeeeeeeeeeeee", + "ffffffffffffffff", + "ggggggggggg", + "hhhhhhhhhhhhhh" + }, + { + l1a={ + l2a={l3a="012345678901234567890123456789012345678901234567890123456789"}, + l2b="bbb" + }, + l1b=4 + } +}]] ) + + local t6 = { t1=t1, t2=t2, t3=t3, t4=t4 } + lu.assertEquals(lu.prettystr(t6),[[{ + t1={1, 2, 3, 4, 5, 6}, + t2={ + "aaaaaaaaaaaaaaaaa", + "bbbbbbbbbbbbbbbbbbbb", + "ccccccccccccccccc", + "ddddddddddddd", + "eeeeeeeeeeeeeeeeee", + "ffffffffffffffff", + "ggggggggggg", + "hhhhhhhhhhhhhh" + }, + t3={ + l1a={ + l2a={l3a="012345678901234567890123456789012345678901234567890123456789"}, + l2b="bbb" + }, + l1b=4 + }, + t4={a=1, b=2, c=3} +}]]) + end + + function TestLuaUnitUtilities:test_prettystrTableRecursion() + local t = {} + t.__index = t + lu.assertStrMatches(lu.prettystr(t), "() {__index=%1}") + + local t1 = {} + local t2 = {} + t1.t2 = t2 + t2.t1 = t1 + local t3 = { t1 = t1, t2 = t2 } + lu.assertStrMatches(lu.prettystr(t1), "() {t2=() {t1=%1}}") + lu.assertStrMatches(lu.prettystr(t3), [[() { + t1=() {t2=() {t1=%2}}, + t2=%3 +}]]) + + local t4 = {1,2} + local t5 = {3,4,t4} + t4[3] = t5 + lu.assertStrMatches(lu.prettystr(t5), "() {3, 4, () {1, 2, %1}}") + + local t6 = {} + t6[t6] = 1 + lu.assertStrMatches(lu.prettystr(t6), "() {%1=1}" ) + + local t7, t8 = {"t7"}, {"t8"} + t7[t8] = 1 + t8[t7] = 2 + lu.assertStrMatches(lu.prettystr(t7), '() {"t7", () {"t8", %1=2}=1}') + + local t9 = {"t9", {}} + t9[{t9}] = 1 + + if os.getenv('TRAVIS_OS_NAME') == 'osx' then + -- on os X, because table references are longer, the table is expanded on multiple lines. + --[[ Output example: + ' { + "t9", + {}, + {}=1 + }' + ]] + lu.assertStrMatches(lu.prettystr(t9, true), '() {\n%s+"t9",\n%s+() {},\n%s+() {%1}=1\n}') + else + lu.assertStrMatches(lu.prettystr(t9, true), '() {"t9", () {}, () {%1}=1}') + end + end + + function TestLuaUnitUtilities:test_prettystrPairs() + local foo, bar, str1, str2 = nil, nil + + -- test all combinations of: foo = nil, "foo", "fo\no" (embedded + -- newline); and bar = nil, "bar", "bar\n" (trailing newline) + + str1, str2 = lu.private.prettystrPairs(foo, bar) + lu.assertEquals(str1, "nil") + lu.assertEquals(str2, "nil") + str1, str2 = lu.private.prettystrPairs(foo, bar, "_A", "_B") + lu.assertEquals(str1, "nil_B") + lu.assertEquals(str2, "nil") + + bar = "bar" + str1, str2 = lu.private.prettystrPairs(foo, bar) + lu.assertEquals(str1, "nil") + lu.assertEquals(str2, '"bar"') + str1, str2 = lu.private.prettystrPairs(foo, bar, "_A", "_B") + lu.assertEquals(str1, "nil_B") + lu.assertEquals(str2, '"bar"') + + bar = "bar\n" + str1, str2 = lu.private.prettystrPairs(foo, bar) + lu.assertEquals(str1, "\nnil") + lu.assertEquals(str2, '\n"bar\n"') + str1, str2 = lu.private.prettystrPairs(foo, bar, "_A", "_B") + lu.assertEquals(str1, "\nnil_A") + lu.assertEquals(str2, '\n"bar\n"') + + foo = "foo" + bar = nil + str1, str2 = lu.private.prettystrPairs(foo, bar) + lu.assertEquals(str1, '"foo"') + lu.assertEquals(str2, "nil") + str1, str2 = lu.private.prettystrPairs(foo, bar, "_A", "_B") + lu.assertEquals(str1, '"foo"_B') + lu.assertEquals(str2, "nil") + + bar = "bar" + str1, str2 = lu.private.prettystrPairs(foo, bar) + lu.assertEquals(str1, '"foo"') + lu.assertEquals(str2, '"bar"') + str1, str2 = lu.private.prettystrPairs(foo, bar, "_A", "_B") + lu.assertEquals(str1, '"foo"_B') + lu.assertEquals(str2, '"bar"') + + bar = "bar\n" + str1, str2 = lu.private.prettystrPairs(foo, bar) + lu.assertEquals(str1, '\n"foo"') + lu.assertEquals(str2, '\n"bar\n"') + str1, str2 = lu.private.prettystrPairs(foo, bar, "_A", "_B") + lu.assertEquals(str1, '\n"foo"_A') + lu.assertEquals(str2, '\n"bar\n"') + + foo = "fo\no" + bar = nil + str1, str2 = lu.private.prettystrPairs(foo, bar) + lu.assertEquals(str1, '\n"fo\no"') + lu.assertEquals(str2, "\nnil") + str1, str2 = lu.private.prettystrPairs(foo, bar, "_A", "_B") + lu.assertEquals(str1, '\n"fo\no"_A') + lu.assertEquals(str2, "\nnil") + + bar = "bar" + str1, str2 = lu.private.prettystrPairs(foo, bar) + lu.assertEquals(str1, '\n"fo\no"') + lu.assertEquals(str2, '\n"bar"') + str1, str2 = lu.private.prettystrPairs(foo, bar, "_A", "_B") + lu.assertEquals(str1, '\n"fo\no"_A') + lu.assertEquals(str2, '\n"bar"') + + bar = "bar\n" + str1, str2 = lu.private.prettystrPairs(foo, bar) + lu.assertEquals(str1, '\n"fo\no"') + lu.assertEquals(str2, '\n"bar\n"') + str1, str2 = lu.private.prettystrPairs(foo, bar, "_A", "_B") + lu.assertEquals(str1, '\n"fo\no"_A') + lu.assertEquals(str2, '\n"bar\n"') + end + + function TestLuaUnitUtilities:test_FailFmt() + -- raise failure from within nested functions + local function babar(level) + lu.private.fail_fmt(level, 'toto', "hex=%X", 123) + end + local function bar(level) + lu.private.fail_fmt(level, nil, "hex=%X", 123) + end + local function foo(level) + bar(level) + end + + local _, err = pcall(foo) -- default level 1 = error position in bar() + local line1, prefix = err:match("test[\\/]test_luaunit%.lua:(%d+): (.*)hex=7B$") + lu.assertEquals(prefix, lu.FAILURE_PREFIX) + lu.assertNotNil(line1) + + _, err = pcall(foo, 2) -- level 2 = error position within foo() + local line2 + line2 , prefix = err:match("test[\\/]test_luaunit%.lua:(%d+): (.*)hex=7B$") + lu.assertEquals(prefix, lu.FAILURE_PREFIX) + lu.assertNotNil(line2) + -- make sure that "line2" position is exactly 3 lines after "line1" + lu.assertEquals(tonumber(line2), tonumber(line1) + 3) + + _, err = pcall(babar, 1) + local _, prefix = err:match("test[\\/]test_luaunit%.lua:(%d+): (.*)hex=7B$") + lu.assertEquals(prefix, lu.FAILURE_PREFIX .. 'toto\n') + + end + + function TestLuaUnitUtilities:test_IsFunction() + -- previous LuaUnit.isFunction was superseded by LuaUnit.asFunction + -- (which can also serve as a boolean expression) + lu.assertNotNil( lu.LuaUnit.asFunction( function (v,y) end ) ) + lu.assertNil( lu.LuaUnit.asFunction( nil ) ) + lu.assertNil( lu.LuaUnit.asFunction( "not a function" ) ) + end + + function TestLuaUnitUtilities:test_splitClassMethod() + lu.assertEquals( lu.LuaUnit.splitClassMethod( 'toto' ), nil ) + lu.assertEquals( {lu.LuaUnit.splitClassMethod( 'toto.titi' )}, + {'toto', 'titi'} ) + end + + function TestLuaUnitUtilities:test_isTestName() + lu.assertEquals( lu.LuaUnit.isTestName( 'testToto' ), true ) + lu.assertEquals( lu.LuaUnit.isTestName( 'TestToto' ), true ) + lu.assertEquals( lu.LuaUnit.isTestName( 'TESTToto' ), true ) + lu.assertEquals( lu.LuaUnit.isTestName( 'xTESTToto' ), false ) + lu.assertEquals( lu.LuaUnit.isTestName( '' ), false ) + end + + function TestLuaUnitUtilities:test_parseCmdLine() + --test names + lu.assertEquals( lu.LuaUnit.parseCmdLine(), {} ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { 'someTest' } ), { testNames={'someTest'} } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { 'someTest', 'someOtherTest' } ), { testNames={'someTest', 'someOtherTest'} } ) + + -- verbosity + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--verbose' } ), { verbosity=lu.VERBOSITY_VERBOSE } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-v' } ), { verbosity=lu.VERBOSITY_VERBOSE } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--quiet' } ), { verbosity=lu.VERBOSITY_QUIET } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-q' } ), { verbosity=lu.VERBOSITY_QUIET } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-v', '-q' } ), { verbosity=lu.VERBOSITY_QUIET } ) + + --output + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--output', 'toto' } ), { output='toto'} ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-o', 'toto' } ), { output='toto'} ) + lu.assertErrorMsgContains( 'Missing argument after -o', lu.LuaUnit.parseCmdLine, { '-o', } ) + + --name + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--name', 'toto' } ), { fname='toto'} ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-n', 'toto' } ), { fname='toto'} ) + lu.assertErrorMsgContains( 'Missing argument after -n', lu.LuaUnit.parseCmdLine, { '-n', } ) + + --patterns + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--pattern', 'toto' } ), { pattern={'toto'} } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-p', 'toto' } ), { pattern={'toto'} } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-p', 'titi', '-p', 'toto' } ), { pattern={'titi', 'toto'} } ) + lu.assertErrorMsgContains( 'Missing argument after -p', lu.LuaUnit.parseCmdLine, { '-p', } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--exclude', 'toto' } ), { pattern={'!toto'} } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-x', 'toto' } ), { pattern={'!toto'} } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-x', 'titi', '-x', 'toto' } ), { pattern={'!titi', '!toto'} } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-x', 'titi', '-p', 'foo', '-x', 'toto' } ), { pattern={'!titi', 'foo', '!toto'} } ) + lu.assertErrorMsgContains( 'Missing argument after -x', lu.LuaUnit.parseCmdLine, { '-x', } ) + + -- repeat + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--repeat', '123' } ), { exeRepeat=123 } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-r', '123' } ), { exeRepeat=123 } ) + lu.assertErrorMsgContains( 'Malformed -r argument', lu.LuaUnit.parseCmdLine, { '-r', 'bad' } ) + lu.assertErrorMsgContains( 'Missing argument after -r', lu.LuaUnit.parseCmdLine, { '-r', } ) + + -- shuffle + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '--shuffle' } ), { shuffle=true } ) + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-s' } ), { shuffle=true } ) + + --megamix + lu.assertEquals( lu.LuaUnit.parseCmdLine( { '-p', 'toto', 'titi', '-v', 'tata', '-o', 'tintin', '-p', 'tutu', 'prout', '-n', 'toto.xml' } ), + { pattern={'toto', 'tutu'}, verbosity=lu.VERBOSITY_VERBOSE, output='tintin', testNames={'titi', 'tata', 'prout'}, fname='toto.xml' } ) + + lu.assertErrorMsgContains( 'option: -$', lu.LuaUnit.parseCmdLine, { '-$', } ) + end + + function TestLuaUnitUtilities:test_patternFilter() + lu.assertEquals( lu.private.patternFilter( nil, 'toto'), true ) + lu.assertEquals( lu.private.patternFilter( {}, 'toto'), true ) + + -- positive pattern + lu.assertEquals( lu.private.patternFilter( {'toto'}, 'toto'), true ) + lu.assertEquals( lu.private.patternFilter( {'toto'}, 'yyytotoxxx'), true ) + lu.assertEquals( lu.private.patternFilter( {'titi', 'toto'}, 'yyytotoxxx'), true ) + lu.assertEquals( lu.private.patternFilter( {'titi', 'toto'}, 'tutu'), false ) + lu.assertEquals( lu.private.patternFilter( {'titi', 'to..'}, 'yyytoxxx'), true ) + + -- negative pattern + lu.assertEquals( lu.private.patternFilter( {'!toto'}, 'toto'), false ) + lu.assertEquals( lu.private.patternFilter( {'!t.t.'}, 'titi'), false ) + lu.assertEquals( lu.private.patternFilter( {'!toto'}, 'titi'), true ) + lu.assertEquals( lu.private.patternFilter( {'!toto'}, 'yyytotoxxx'), false ) + lu.assertEquals( lu.private.patternFilter( {'!titi', '!toto'}, 'yyytotoxxx'), false ) + lu.assertEquals( lu.private.patternFilter( {'!titi', '!toto'}, 'tutu'), true ) + lu.assertEquals( lu.private.patternFilter( {'!titi', '!to..'}, 'yyytoxxx'), false ) + + -- combine patterns + lu.assertEquals( lu.private.patternFilter( { 'foo' }, 'foo'), true ) + lu.assertEquals( lu.private.patternFilter( { 'foo', '!foo' }, 'foo'), false ) + lu.assertEquals( lu.private.patternFilter( { 'foo', '!foo', 'foo' }, 'foo'), true ) + lu.assertEquals( lu.private.patternFilter( { 'foo', '!foo', 'foo', '!foo' }, 'foo'), false ) + + lu.assertEquals( lu.private.patternFilter( { '!foo' }, 'foo'), false ) + lu.assertEquals( lu.private.patternFilter( { '!foo', 'foo' }, 'foo'), true ) + lu.assertEquals( lu.private.patternFilter( { '!foo', 'foo', '!foo' }, 'foo'), false ) + lu.assertEquals( lu.private.patternFilter( { '!foo', 'foo', '!foo', 'foo' }, 'foo'), true ) + + lu.assertEquals( lu.private.patternFilter( { 'f..', '!foo', '__foo__' }, 'toto'), false ) + lu.assertEquals( lu.private.patternFilter( { 'f..', '!foo', '__foo__' }, 'fii'), true ) + lu.assertEquals( lu.private.patternFilter( { 'f..', '!foo', '__foo__' }, 'foo'), false ) + lu.assertEquals( lu.private.patternFilter( { 'f..', '!foo', '__foo__' }, '__foo__'), true ) + + lu.assertEquals( lu.private.patternFilter( { '!f..', 'foo', '!__foo__' }, 'toto'), false ) + lu.assertEquals( lu.private.patternFilter( { '!f..', 'foo', '!__foo__' }, 'fii'), false ) + lu.assertEquals( lu.private.patternFilter( { '!f..', 'foo', '!__foo__' }, 'foo'), true ) + lu.assertEquals( lu.private.patternFilter( { '!f..', 'foo', '!__foo__' }, '__foo__'), false ) + end + + function TestLuaUnitUtilities:test_applyPatternFilter() + local dummy = function() end + local testset = { + { 'toto.foo', dummy}, { 'toto.bar', dummy}, + { 'titi.foo', dummy}, { 'titi.bar', dummy}, + { 'tata.foo', dummy}, { 'tata.bar', dummy}, + { 'foo.bar', dummy}, { 'foobar.test', dummy}, + } + + -- default action: include everything + local included, excluded = lu.LuaUnit.applyPatternFilter( nil, testset ) + lu.assertEquals( #included, 8 ) + lu.assertEquals( excluded, {} ) + + -- single exclude pattern (= select anything not matching "bar") + included, excluded = lu.LuaUnit.applyPatternFilter( {'!bar'}, testset ) + lu.assertEquals( included, {testset[1], testset[3], testset[5]} ) + lu.assertEquals( #excluded, 5 ) + + -- single include pattern + included, excluded = lu.LuaUnit.applyPatternFilter( {'t.t.'}, testset ) + lu.assertEquals( #included, 6 ) + lu.assertEquals( excluded, {testset[7], testset[8]} ) + + -- single include and exclude patterns + included, excluded = lu.LuaUnit.applyPatternFilter( {'foo', '!test'}, testset ) + lu.assertEquals( included, {testset[1], testset[3], testset[5], testset[7]} ) + lu.assertEquals( #excluded, 4 ) + + -- multiple (specific) includes + included, excluded = lu.LuaUnit.applyPatternFilter( {'toto', 'titi'}, testset ) + lu.assertEquals( included, {testset[1], testset[2], testset[3], testset[4]} ) + lu.assertEquals( #excluded, 4 ) + + -- multiple excludes + included, excluded = lu.LuaUnit.applyPatternFilter( {'!tata', '!%.bar'}, testset ) + lu.assertEquals( included, {testset[1], testset[3], testset[8]} ) + lu.assertEquals( #excluded, 5 ) + + -- combined test + included, excluded = lu.LuaUnit.applyPatternFilter( {'t[oai]', 'bar$', 'test', '!%.b', '!titi'}, testset ) + lu.assertEquals( included, {testset[1], testset[5], testset[8]} ) + lu.assertEquals( #excluded, 5 ) + + --[[ Combining positive and negative filters ]]-- + included, excluded = lu.LuaUnit.applyPatternFilter( {'foo', 'bar', '!t.t.', '%.bar'}, testset ) + lu.assertEquals( included, {testset[2], testset[4], testset[6], testset[7], testset[8]} ) + lu.assertEquals( #excluded, 3 ) + end + + function TestLuaUnitUtilities:test_strMatch() + lu.assertEquals( lu.private.strMatch('toto', 't.t.'), true ) + lu.assertEquals( lu.private.strMatch('toto', 't.t.', 1, 4), true ) + lu.assertEquals( lu.private.strMatch('toto', 't.t.', 2, 5), false ) + lu.assertEquals( lu.private.strMatch('toto', '.t.t.'), false ) + lu.assertEquals( lu.private.strMatch('ototo', 't.t.'), false ) + lu.assertEquals( lu.private.strMatch('totot', 't.t.'), false ) + lu.assertEquals( lu.private.strMatch('ototot', 't.t.'), false ) + lu.assertEquals( lu.private.strMatch('ototot', 't.t.',2,3), false ) + lu.assertEquals( lu.private.strMatch('ototot', 't.t.',2,5), true ) + lu.assertEquals( lu.private.strMatch('ototot', 't.t.',2,6), false ) + end + + function TestLuaUnitUtilities:test_expandOneClass() + local result = {} + lu.LuaUnit.expandOneClass( result, 'titi', {} ) + lu.assertEquals( result, {} ) + + result = {} + lu.LuaUnit.expandOneClass( result, 'MyTestToto1', MyTestToto1 ) + lu.assertEquals( result, { + {'MyTestToto1.test1', MyTestToto1 }, + {'MyTestToto1.test2', MyTestToto1 }, + {'MyTestToto1.test3', MyTestToto1 }, + {'MyTestToto1.testa', MyTestToto1 }, + {'MyTestToto1.testb', MyTestToto1 }, + } ) + end + + function TestLuaUnitUtilities:test_expandClasses() + local result + result = lu.LuaUnit.expandClasses( {} ) + lu.assertEquals( result, {} ) + + result = lu.LuaUnit.expandClasses( { { 'MyTestFunction', MyTestFunction } } ) + lu.assertEquals( result, { { 'MyTestFunction', MyTestFunction } } ) + + result = lu.LuaUnit.expandClasses( { { 'MyTestToto1.test1', MyTestToto1 } } ) + lu.assertEquals( result, { { 'MyTestToto1.test1', MyTestToto1 } } ) + + result = lu.LuaUnit.expandClasses( { { 'MyTestToto1', MyTestToto1 } } ) + lu.assertEquals( result, { + {'MyTestToto1.test1', MyTestToto1 }, + {'MyTestToto1.test2', MyTestToto1 }, + {'MyTestToto1.test3', MyTestToto1 }, + {'MyTestToto1.testa', MyTestToto1 }, + {'MyTestToto1.testb', MyTestToto1 }, + } ) + end + + function TestLuaUnitUtilities:test_xmlEscape() + lu.assertEquals( lu.private.xmlEscape( 'abc' ), 'abc' ) + lu.assertEquals( lu.private.xmlEscape( 'a"bc' ), 'a"bc' ) + lu.assertEquals( lu.private.xmlEscape( "a'bc" ), 'a'bc' ) + lu.assertEquals( lu.private.xmlEscape( "a" ), 'a<b&c>' ) + end + + function TestLuaUnitUtilities:test_xmlCDataEscape() + lu.assertEquals( lu.private.xmlCDataEscape( 'abc' ), 'abc' ) + lu.assertEquals( lu.private.xmlCDataEscape( 'a"bc' ), 'a"bc' ) + lu.assertEquals( lu.private.xmlCDataEscape( "a'bc" ), "a'bc" ) + lu.assertEquals( lu.private.xmlCDataEscape( "a" ), 'a' ) + lu.assertEquals( lu.private.xmlCDataEscape( "a--" ), 'a + [C]: in function 'xpcall' + ./luaunit.lua:1449: in function 'protectedCall' + ./luaunit.lua:1508: in function 'execOneFunction' + ./luaunit.lua:1596: in function 'runSuiteByInstances' + ./luaunit.lua:1660: in function 'runSuiteByNames' + ./luaunit.lua:1736: in function 'runSuite' + example_with_luaunit.lua:140: in main chunk + [C]: in ?]] + + + local realStackTrace2=[[stack traceback: + ./luaunit.lua:545: in function 'lu.assertEquals' + example_with_luaunit.lua:58: in function 'TestToto.test7' + ./luaunit.lua:1517: in function <./luaunit.lua:1517> + [C]: in function 'xpcall' + ./luaunit.lua:1517: in function 'protectedCall' + ./luaunit.lua:1578: in function 'execOneFunction' + ./luaunit.lua:1677: in function 'runSuiteByInstances' + ./luaunit.lua:1730: in function 'runSuiteByNames' + ./luaunit.lua:1806: in function 'runSuite' + example_with_luaunit.lua:140: in main chunk + [C]: in ?]] + + local realStackTrace3 = [[stack traceback: + luaunit2/example_with_luaunit.lua:124: in function 'test1_withFailure' + luaunit2/luaunit.lua:1532: in function + [C]: in function 'xpcall' + luaunit2/luaunit.lua:1532: in function 'protectedCall' + luaunit2/luaunit.lua:1591: in function 'execOneFunction' + luaunit2/luaunit.lua:1679: in function 'runSuiteByInstances' + luaunit2/luaunit.lua:1743: in function 'runSuiteByNames' + luaunit2/luaunit.lua:1819: in function 'runSuite' + luaunit2/example_with_luaunit.lua:140: in main chunk + [C]: in ?]] + + + local strippedStackTrace=lu.private.stripLuaunitTrace( realStackTrace ) + -- print( strippedStackTrace ) + + local expectedStackTrace=[[stack traceback: + example_with_luaunit.lua:130: in function 'test2_withFailure']] + lu.assertEquals( strippedStackTrace, expectedStackTrace ) + + strippedStackTrace=lu.private.stripLuaunitTrace( realStackTrace2 ) + expectedStackTrace=[[stack traceback: + example_with_luaunit.lua:58: in function 'TestToto.test7']] + lu.assertEquals( strippedStackTrace, expectedStackTrace ) + + strippedStackTrace=lu.private.stripLuaunitTrace( realStackTrace3 ) + expectedStackTrace=[[stack traceback: + luaunit2/example_with_luaunit.lua:124: in function 'test1_withFailure']] + lu.assertEquals( strippedStackTrace, expectedStackTrace ) + + + end + + function TestLuaUnitUtilities:test_eps_value() + -- calculate epsilon + local local_eps = 1.0 + while (1.0 + 0.5 * local_eps) ~= 1.0 do + local_eps = 0.5 * local_eps + end + -- print( local_eps, lu.EPS) + lu.assertEquals( local_eps, lu.EPS ) + end + + +------------------------------------------------------------------ +-- +-- Outputter Tests +-- +------------------------------------------------------------------ + +TestLuaUnitOutputters = { __class__ = 'TestOutputters' } + + -- JUnitOutput:startSuite() can raise errors on its own, cover those + function TestLuaUnitOutputters:testJUnitOutputErrors() + local runner = lu.LuaUnit.new() + runner:setOutputType('junit') + local outputter = runner.outputType.new(runner) + + -- missing file name + lu.assertErrorMsgContains('With Junit, an output filename must be supplied', + outputter.startSuite, outputter) + + -- test adding .xml extension, catch output error + outputter.fname = '/tmp/nonexistent.dir/foobar' + lu.assertErrorMsgContains('Could not open file for writing: /tmp/nonexistent.dir/foobar.xml', + outputter.startSuite, outputter) + end + +------------------------------------------------------------------ +-- +-- Assertion Tests +-- +------------------------------------------------------------------ + +local function assertFailure( ... ) + -- ensure that execution generates a failure type error + lu.assertErrorMsgMatches(lu.FAILURE_PREFIX .. ".*", ...) +end + +local function assertBadFindArgTable( ... ) + lu.assertErrorMsgMatches( ".* bad argument .* to 'find' %(string expected, got table%)", ...) +end +local function assertBadFindArgNil( ... ) + lu.assertErrorMsgMatches( ".* bad argument .* to 'find' %(string expected, got nil%)", ...) +end +local function assertBadIndexNumber( ... ) + lu.assertErrorMsgMatches( ".* attempt to index .*a number value.*", ... ) +end +local function assertBadIndexNil( ... ) + lu.assertErrorMsgMatches( ".* attempt to index .*a nil value.*", ... ) +end +local function assertBadMethodNil( ... ) + lu.assertErrorMsgMatches( ".* attempt to call .*a nil value.*", ... ) +end + + +TestLuaUnitAssertions = { __class__ = 'TestLuaUnitAssertions' } + + function TestLuaUnitAssertions:test_assertEquals() + local f = function() return true end + local g = function() return true end + + lu.assertEquals( 1, 1 ) + lu.assertEquals( "abc", "abc" ) + lu.assertEquals( nil, nil ) + lu.assertEquals( true, true ) + lu.assertEquals( f, f) + lu.assertEquals( {1,2,3}, {1,2,3}) + lu.assertEquals( {one=1,two=2,three=3}, {one=1,two=2,three=3}) + lu.assertEquals( {one=1,two=2,three=3}, {two=2,three=3,one=1}) + lu.assertEquals( {one=1,two={1,2},three=3}, {two={1,2},three=3,one=1}) + lu.assertEquals( {one=1,two={1,{2,nil}},three=3}, {two={1,{2,nil}},three=3,one=1}) + lu.assertEquals( {nil}, {nil} ) + local config_saved = lu.TABLE_EQUALS_KEYBYCONTENT + lu.TABLE_EQUALS_KEYBYCONTENT = false + assertFailure( lu.assertEquals, {[{}] = 1}, { [{}] = 1}) + assertFailure( lu.assertEquals, {[{one=1, two=2}] = 1}, { [{two=2, one=1}] = 1}) + assertFailure( lu.assertEquals, {[{1}]=2, [{1}]=3}, {[{1}]=3, [{1}]=2} ) + lu.TABLE_EQUALS_KEYBYCONTENT = true + lu.assertEquals( {[{}] = 1}, { [{}] = 1}) + lu.assertEquals( {[{one=1, two=2}] = 1}, { [{two=2, one=1}] = 1}) + lu.assertEquals( {[{1}]=2, [{1}]=3}, {[{1}]=3, [{1}]=2} ) + -- try the other order as well, in case pairs() returns items reversed in the test above + lu.assertEquals( {[{1}]=2, [{1}]=3}, {[{1}]=2, [{1}]=3} ) + + assertFailure( lu.assertEquals, 1, 2) + assertFailure( lu.assertEquals, 1, "abc" ) + assertFailure( lu.assertEquals, 0, nil ) + assertFailure( lu.assertEquals, false, nil ) + assertFailure( lu.assertEquals, true, 1 ) + assertFailure( lu.assertEquals, f, 1 ) + assertFailure( lu.assertEquals, f, g ) + assertFailure( lu.assertEquals, {1,2,3}, {2,1,3} ) + assertFailure( lu.assertEquals, {1,2,3}, nil ) + assertFailure( lu.assertEquals, {1,2,3}, 1 ) + assertFailure( lu.assertEquals, {1,2,3}, true ) + assertFailure( lu.assertEquals, {1,2,3}, {one=1,two=2,three=3} ) + assertFailure( lu.assertEquals, {1,2,3}, {one=1,two=2,three=3,four=4} ) + assertFailure( lu.assertEquals, {one=1,two=2,three=3}, {2,1,3} ) + assertFailure( lu.assertEquals, {one=1,two=2,three=3}, nil ) + assertFailure( lu.assertEquals, {one=1,two=2,three=3}, 1 ) + assertFailure( lu.assertEquals, {one=1,two=2,three=3}, true ) + assertFailure( lu.assertEquals, {one=1,two=2,three=3}, {1,2,3} ) + assertFailure( lu.assertEquals, {one=1,two={1,2},three=3}, {two={2,1},three=3,one=1}) + lu.TABLE_EQUALS_KEYBYCONTENT = true -- without it, these tests won't pass anyway + assertFailure( lu.assertEquals, {[{}] = 1}, {[{}] = 2}) + assertFailure( lu.assertEquals, {[{}] = 1}, {[{one=1}] = 2}) + assertFailure( lu.assertEquals, {[{}] = 1}, {[{}] = 1, 2}) + assertFailure( lu.assertEquals, {[{}] = 1}, {[{}] = 1, [{}] = 1}) + assertFailure( lu.assertEquals, {[{"one"}]=1}, {[{"one", 1}]=2} ) + assertFailure( lu.assertEquals, {[{"one"}]=1,[{"one"}]=1}, {[{"one"}]=1} ) + lu.TABLE_EQUALS_KEYBYCONTENT = config_saved + end + + function TestLuaUnitAssertions:test_assertAlmostEquals() + lu.assertAlmostEquals( 1, 1, 0.1 ) + lu.assertAlmostEquals( 1, 1 ) -- default margin (= M.EPS) + lu.assertAlmostEquals( 1, 1, 0 ) -- zero margin + assertFailure( lu.assertAlmostEquals, 0, lu.EPS, 0 ) -- zero margin + + lu.assertAlmostEquals( 1, 1.1, 0.2 ) + lu.assertAlmostEquals( -1, -1.1, 0.2 ) + lu.assertAlmostEquals( 0.1, -0.1, 0.3 ) + lu.assertAlmostEquals( 0.1, -0.1, 0.2 ) + + -- Due to rounding errors, these user-supplied margins are too small. + -- The tests should respect them, and so are required to fail. + assertFailure( lu.assertAlmostEquals, 1, 1.1, 0.1 ) + assertFailure( lu.assertAlmostEquals, -1, -1.1, 0.1 ) + -- Check that an explicit zero margin gets respected too + assertFailure( lu.assertAlmostEquals, 1.1 - 1, 0.1, 0 ) + assertFailure( lu.assertAlmostEquals, -1 - (-1.1), 0.1, 0 ) + -- Tests pass when adding M.EPS, either explicitly or implicitly + lu.assertAlmostEquals( 1, 1.1, 0.1 + lu.EPS) + lu.assertAlmostEquals( 1.1 - 1, 0.1 ) + lu.assertAlmostEquals( -1, -1.1, 0.1 + lu.EPS ) + lu.assertAlmostEquals( -1 - (-1.1), 0.1 ) + + assertFailure( lu.assertAlmostEquals, 1, 1.11, 0.1 ) + assertFailure( lu.assertAlmostEquals, -1, -1.11, 0.1 ) + lu.assertErrorMsgContains( "must supply only number arguments", lu.assertAlmostEquals, -1, 1, "foobar" ) + lu.assertErrorMsgContains( "must supply only number arguments", lu.assertAlmostEquals, -1, nil, 0 ) + lu.assertErrorMsgContains( "must supply only number arguments", lu.assertAlmostEquals, nil, 1, 0 ) + lu.assertErrorMsgContains( "margin must not be negative", lu.assertAlmostEquals, 1, 1.1, -0.1 ) + end + + function TestLuaUnitAssertions:test_assertNotEquals() + local f = function() return true end + local g = function() return true end + + lu.assertNotEquals( 1, 2 ) + lu.assertNotEquals( "abc", 2 ) + lu.assertNotEquals( "abc", "def" ) + lu.assertNotEquals( 1, 2) + lu.assertNotEquals( 1, "abc" ) + lu.assertNotEquals( 0, nil ) + lu.assertNotEquals( false, nil ) + lu.assertNotEquals( true, 1 ) + lu.assertNotEquals( f, 1 ) + lu.assertNotEquals( f, g ) + lu.assertNotEquals( {one=1,two=2,three=3}, true ) + lu.assertNotEquals( {one=1,two={1,2},three=3}, {two={2,1},three=3,one=1} ) + + assertFailure( lu.assertNotEquals, 1, 1) + assertFailure( lu.assertNotEquals, "abc", "abc" ) + assertFailure( lu.assertNotEquals, nil, nil ) + assertFailure( lu.assertNotEquals, true, true ) + assertFailure( lu.assertNotEquals, f, f) + assertFailure( lu.assertNotEquals, {one=1,two={1,{2,nil}},three=3}, {two={1,{2,nil}},three=3,one=1}) + end + + function TestLuaUnitAssertions:test_assertNotAlmostEquals() + lu.assertNotAlmostEquals( 1, 1.2, 0.1 ) + lu.assertNotAlmostEquals( 1, 1.01 ) -- default margin (= M.EPS) + lu.assertNotAlmostEquals( 1, 1.01, 0 ) -- zero margin + lu.assertNotAlmostEquals( 0, lu.EPS, 0 ) -- zero margin + + lu.assertNotAlmostEquals( 1, 1.3, 0.2 ) + lu.assertNotAlmostEquals( -1, -1.3, 0.2 ) + lu.assertNotAlmostEquals( 0.1, -0.1, 0.1 ) + + lu.assertNotAlmostEquals( 1, 1.1, 0.09 ) + lu.assertNotAlmostEquals( -1, -1.1, 0.09 ) + lu.assertNotAlmostEquals( 0.1, -0.1, 0.11 ) + + -- Due to rounding errors, these user-supplied margins are too small. + -- The tests should respect them, and so are expected to pass. + lu.assertNotAlmostEquals( 1, 1.1, 0.1 ) + lu.assertNotAlmostEquals( -1, -1.1, 0.1 ) + -- Check that an explicit zero margin gets respected too + lu.assertNotAlmostEquals( 1.1 - 1, 0.1, 0 ) + lu.assertNotAlmostEquals( -1 - (-1.1), 0.1, 0 ) + -- Tests fail when adding M.EPS, either explicitly or implicitly + assertFailure( lu.assertNotAlmostEquals, 1, 1.1, 0.1 + lu.EPS) + assertFailure( lu.assertNotAlmostEquals, 1.1 - 1, 0.1 ) + assertFailure( lu.assertNotAlmostEquals, -1, -1.1, 0.1 + lu.EPS ) + assertFailure( lu.assertNotAlmostEquals, -1 - (-1.1), 0.1 ) + + assertFailure( lu.assertNotAlmostEquals, 1, 1.11, 0.2 ) + assertFailure( lu.assertNotAlmostEquals, -1, -1.11, 0.2 ) + lu.assertErrorMsgContains( "must supply only number arguments", lu.assertNotAlmostEquals, -1, 1, "foobar" ) + lu.assertErrorMsgContains( "must supply only number arguments", lu.assertNotAlmostEquals, -1, nil, 0 ) + lu.assertErrorMsgContains( "must supply only number arguments", lu.assertNotAlmostEquals, nil, 1, 0 ) + lu.assertErrorMsgContains( "margin must not be negative", lu.assertNotAlmostEquals, 1, 1.1, -0.1 ) + end + + function TestLuaUnitAssertions:test_assertNotEqualsDifferentTypes2() + lu.assertNotEquals( 2, "abc" ) + end + + function TestLuaUnitAssertions:test_assertIsTrue() + lu.assertIsTrue(true) + -- assertIsTrue is strict + assertFailure( lu.assertIsTrue, false) + assertFailure( lu.assertIsTrue, nil ) + assertFailure( lu.assertIsTrue, 0) + assertFailure( lu.assertIsTrue, 1) + assertFailure( lu.assertIsTrue, "") + assertFailure( lu.assertIsTrue, "abc") + assertFailure( lu.assertIsTrue, function() return true end ) + assertFailure( lu.assertIsTrue, {} ) + assertFailure( lu.assertIsTrue, { 1 } ) + end + + function TestLuaUnitAssertions:test_assertNotIsTrue() + assertFailure( lu.assertNotIsTrue, true) + lu.assertNotIsTrue( false) + lu.assertNotIsTrue( nil ) + lu.assertNotIsTrue( 0) + lu.assertNotIsTrue( 1) + lu.assertNotIsTrue( "") + lu.assertNotIsTrue( "abc") + lu.assertNotIsTrue( function() return true end ) + lu.assertNotIsTrue( {} ) + lu.assertNotIsTrue( { 1 } ) + end + + function TestLuaUnitAssertions:test_assertIsFalse() + lu.assertIsFalse(false) + assertFailure( lu.assertIsFalse, nil) -- assertIsFalse is strict ! + assertFailure( lu.assertIsFalse, true) + assertFailure( lu.assertIsFalse, 0 ) + assertFailure( lu.assertIsFalse, 1 ) + assertFailure( lu.assertIsFalse, "" ) + assertFailure( lu.assertIsFalse, "abc" ) + assertFailure( lu.assertIsFalse, function() return true end ) + assertFailure( lu.assertIsFalse, {} ) + assertFailure( lu.assertIsFalse, { 1 } ) + end + + function TestLuaUnitAssertions:test_assertNotIsFalse() + assertFailure(lu.assertNotIsFalse, false) + lu.assertNotIsFalse( true) + lu.assertNotIsFalse( 0 ) + lu.assertNotIsFalse( 1 ) + lu.assertNotIsFalse( "" ) + lu.assertNotIsFalse( "abc" ) + lu.assertNotIsFalse( function() return true end ) + lu.assertNotIsFalse( {} ) + lu.assertNotIsFalse( { 1 } ) + end + + function TestLuaUnitAssertions:test_assertEvalToTrue() + lu.assertEvalToTrue(true) + assertFailure( lu.assertEvalToTrue, false) + assertFailure( lu.assertEvalToTrue, nil ) + lu.assertEvalToTrue(0) + lu.assertEvalToTrue(1) + lu.assertEvalToTrue("") + lu.assertEvalToTrue("abc") + lu.assertEvalToTrue( function() return true end ) + lu.assertEvalToTrue( {} ) + lu.assertEvalToTrue( { 1 } ) + end + + function TestLuaUnitAssertions:test_assertEvalToFalse() + lu.assertEvalToFalse(false) + lu.assertEvalToFalse(nil) + assertFailure( lu.assertEvalToFalse, true) + assertFailure( lu.assertEvalToFalse, 0 ) + assertFailure( lu.assertEvalToFalse, 1 ) + assertFailure( lu.assertEvalToFalse, "" ) + assertFailure( lu.assertEvalToFalse, "abc" ) + assertFailure( lu.assertEvalToFalse, function() return true end ) + assertFailure( lu.assertEvalToFalse, {} ) + assertFailure( lu.assertEvalToFalse, { 1 } ) + end + + function TestLuaUnitAssertions:test_assertNil() + lu.assertNil(nil) + assertFailure( lu.assertTrue, false) + assertFailure( lu.assertNil, 0) + assertFailure( lu.assertNil, "") + assertFailure( lu.assertNil, "abc") + assertFailure( lu.assertNil, function() return true end ) + assertFailure( lu.assertNil, {} ) + assertFailure( lu.assertNil, { 1 } ) + end + + function TestLuaUnitAssertions:test_assertNotNil() + assertFailure( lu.assertNotNil, nil) + lu.assertNotNil( false ) + lu.assertNotNil( 0 ) + lu.assertNotNil( "" ) + lu.assertNotNil( "abc" ) + lu.assertNotNil( function() return true end ) + lu.assertNotNil( {} ) + lu.assertNotNil( { 1 } ) + end + + function TestLuaUnitAssertions:test_assertStrContains() + lu.assertStrContains( 'abcdef', 'abc' ) + lu.assertStrContains( 'abcdef', 'bcd' ) + lu.assertStrContains( 'abcdef', 'abcdef' ) + lu.assertStrContains( 'abc0', 0 ) + assertFailure( lu.assertStrContains, 'ABCDEF', 'abc' ) + assertFailure( lu.assertStrContains, '', 'abc' ) + lu.assertStrContains( 'abcdef', '' ) + assertFailure( lu.assertStrContains, 'abcdef', 'abcx' ) + assertFailure( lu.assertStrContains, 'abcdef', 'abcdefg' ) + assertFailure( lu.assertStrContains, 'abcdef', 0 ) + assertBadFindArgTable( lu.assertStrContains, 'abcdef', {} ) + assertBadFindArgNil( lu.assertStrContains, 'abcdef', nil ) + + lu.assertStrContains( 'abcdef', 'abc', false ) + lu.assertStrContains( 'abcdef', 'abc', true ) + lu.assertStrContains( 'abcdef', 'a.c', true ) + + assertFailure( lu.assertStrContains, 'abcdef', '.abc', true ) + end + + function TestLuaUnitAssertions:test_assertStrIContains() + lu.assertStrIContains( 'ABcdEF', 'aBc' ) + lu.assertStrIContains( 'abCDef', 'bcd' ) + lu.assertStrIContains( 'abcdef', 'abcDef' ) + assertFailure( lu.assertStrIContains, '', 'aBc' ) + lu.assertStrIContains( 'abcDef', '' ) + assertFailure( lu.assertStrIContains, 'abcdef', 'abcx' ) + assertFailure( lu.assertStrIContains, 'abcdef', 'abcdefg' ) + end + + function TestLuaUnitAssertions:test_assertNotStrContains() + assertFailure( lu.assertNotStrContains, 'abcdef', 'abc' ) + assertFailure( lu.assertNotStrContains, 'abcdef', 'bcd' ) + assertFailure( lu.assertNotStrContains, 'abcdef', 'abcdef' ) + lu.assertNotStrContains( '', 'abc' ) + assertFailure( lu.assertNotStrContains, 'abcdef', '' ) + assertFailure( lu.assertNotStrContains, 'abc0', 0 ) + lu.assertNotStrContains( 'abcdef', 'abcx' ) + lu.assertNotStrContains( 'abcdef', 'abcdefg' ) + assertBadFindArgTable( lu.assertNotStrContains, 'abcdef', {} ) + assertBadFindArgNil( lu.assertNotStrContains, 'abcdef', nil ) + + assertFailure( lu.assertNotStrContains, 'abcdef', 'abc', false ) + assertFailure( lu.assertNotStrContains, 'abcdef', 'a.c', true ) + lu.assertNotStrContains( 'abcdef', 'a.cx', true ) + end + + function TestLuaUnitAssertions:test_assertNotStrIContains() + assertFailure( lu.assertNotStrIContains, 'aBcdef', 'abc' ) + assertFailure( lu.assertNotStrIContains, 'abcdef', 'aBc' ) + assertFailure( lu.assertNotStrIContains, 'abcdef', 'bcd' ) + assertFailure( lu.assertNotStrIContains, 'abcdef', 'abcdef' ) + lu.assertNotStrIContains( '', 'abc' ) + assertFailure( lu.assertNotStrIContains, 'abcdef', '' ) + assertBadIndexNumber( lu.assertNotStrIContains, 'abc0', 0 ) + lu.assertNotStrIContains( 'abcdef', 'abcx' ) + lu.assertNotStrIContains( 'abcdef', 'abcdefg' ) + assertBadMethodNil( lu.assertNotStrIContains, 'abcdef', {} ) + assertBadIndexNil( lu.assertNotStrIContains, 'abcdef', nil ) + end + + function TestLuaUnitAssertions:test_assertStrMatches() + lu.assertStrMatches( 'abcdef', 'abcdef' ) + lu.assertStrMatches( 'abcdef', '..cde.' ) + assertFailure( lu.assertStrMatches, 'abcdef', '..def') + assertFailure( lu.assertStrMatches, 'abCDEf', '..cde.') + lu.assertStrMatches( 'abcdef', 'bcdef', 2 ) + lu.assertStrMatches( 'abcdef', 'bcde', 2, 5 ) + lu.assertStrMatches( 'abcdef', 'b..e', 2, 5 ) + lu.assertStrMatches( 'abcdef', 'ab..e', nil, 5 ) + assertFailure( lu.assertStrMatches, 'abcdef', '' ) + assertFailure( lu.assertStrMatches, '', 'abcdef' ) + + assertFailure( lu.assertStrMatches, 'abcdef', 0 ) + assertBadFindArgTable( lu.assertStrMatches, 'abcdef', {} ) + assertBadFindArgNil( lu.assertStrMatches, 'abcdef', nil ) + end + + function TestLuaUnitAssertions:test_assertItemsEquals() + lu.assertItemsEquals(nil, nil) + lu.assertItemsEquals({},{}) + lu.assertItemsEquals({1,2,3}, {3,1,2}) + lu.assertItemsEquals({nil},{nil}) + lu.assertItemsEquals({one=1,two=2,three=3}, {two=2,one=1,three=3}) + lu.assertItemsEquals({one=1,two=2,three=3}, {a=1,b=2,c=3}) + lu.assertItemsEquals({1,2,three=3}, {3,1,two=2}) + + assertFailure(lu.assertItemsEquals, {1}, {}) + assertFailure(lu.assertItemsEquals, nil, {1,2,3}) + assertFailure(lu.assertItemsEquals, {1,2,3}, nil) + assertFailure(lu.assertItemsEquals, {1,2,3,4}, {3,1,2}) + assertFailure(lu.assertItemsEquals, {1,2,3}, {3,1,2,4}) + assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3,four=4}, {a=1,b=2,c=3}) + assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {a=1,b=2,c=3,d=4}) + assertFailure(lu.assertItemsEquals, {1,2,three=3}, {3,4,a=1,b=2}) + assertFailure(lu.assertItemsEquals, {1,2,three=3,four=4}, {3,a=1,b=2}) + + lu.assertItemsEquals({one=1,two={1,2},three=3}, {one={1,2},two=1,three=3}) + lu.assertItemsEquals({one=1, + two={1,{3,2,one=1}}, + three=3}, + {two={1,{3,2,one=1}}, + one=1, + three=3}) + -- itemsEquals is not recursive: + assertFailure( lu.assertItemsEquals,{1,{2,1},3}, {3,1,{1,2}}) + assertFailure( lu.assertItemsEquals,{one=1,two={1,2},three=3}, {one={2,1},two=1,three=3}) + assertFailure( lu.assertItemsEquals,{one=1,two={1,{3,2,one=1}},three=3}, {two={{3,one=1,2},1},one=1,three=3}) + assertFailure( lu.assertItemsEquals,{one=1,two={1,{3,2,one=1}},three=3}, {two={{3,2,one=1},1},one=1,three=3}) + + assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {two=2,one=1,three=2}) + assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {two=2,one=1,four=4}) + assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {two=2,one=1,'three'}) + assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {two=2,one=1,nil}) + assertFailure(lu.assertItemsEquals, {one=1,two=2,three=3}, {two=2,one=1}) + end + + function TestLuaUnitAssertions:test_assertIsNumber() + lu.assertIsNumber(1) + lu.assertIsNumber(1.4) + assertFailure(lu.assertIsNumber, "hi there!") + assertFailure(lu.assertIsNumber, nil) + assertFailure(lu.assertIsNumber, {}) + assertFailure(lu.assertIsNumber, {1,2,3}) + assertFailure(lu.assertIsNumber, {1}) + assertFailure(lu.assertIsNumber, coroutine.create( function(v) local y=v+1 end ) ) + assertFailure(lu.assertIsNumber, true) + end + + function TestLuaUnitAssertions:test_assertIsNaN() + assertFailure(lu.assertIsNaN, "hi there!") + assertFailure(lu.assertIsNaN, nil) + assertFailure(lu.assertIsNaN, {}) + assertFailure(lu.assertIsNaN, {1,2,3}) + assertFailure(lu.assertIsNaN, {1}) + assertFailure(lu.assertIsNaN, coroutine.create( function(v) local y=v+1 end ) ) + lu.assertIsNaN(0 / 0) + lu.assertIsNaN(-0 / 0) + lu.assertIsNaN(0 / -0) + lu.assertIsNaN(-0 / -0) + local inf = math.huge + lu.assertIsNaN(inf / inf) + lu.assertIsNaN(-inf / inf) + lu.assertIsNaN(inf / -inf) + lu.assertIsNaN(-inf / -inf) + lu.assertIsNaN(inf - inf) + lu.assertIsNaN((-inf) + inf) + lu.assertIsNaN(inf + (-inf)) + lu.assertIsNaN((-inf) - (-inf)) + lu.assertIsNaN(0 * inf) + lu.assertIsNaN(-0 * inf) + lu.assertIsNaN(0 * -inf) + lu.assertIsNaN(-0 * -inf) + lu.assertIsNaN(math.sqrt(-1)) + if lu._LUAVERSION == "Lua 5.1" or lu._LUAVERSION == "Lua 5.2" then + -- Lua 5.3 will complain/error "bad argument #2 to 'fmod' (zero)" + lu.assertIsNaN(math.fmod(1, 0)) + lu.assertIsNaN(math.fmod(1, -0)) + end + lu.assertIsNaN(math.fmod(inf, 1)) + lu.assertIsNaN(math.fmod(-inf, 1)) + assertFailure(lu.assertIsNaN, 0 / 1) -- 0.0 + assertFailure(lu.assertIsNaN, 1 / 0) -- inf + assertFailure(lu.assertIsNaN, -1 / 0)-- -inf + end + + function TestLuaUnitAssertions:test_assertNotIsNaN() + -- not NaN + lu.assertNotIsNaN( "hi there!") + lu.assertNotIsNaN( nil) + lu.assertNotIsNaN( {}) + lu.assertNotIsNaN( {1,2,3}) + lu.assertNotIsNaN( {1}) + lu.assertNotIsNaN( coroutine.create( function(v) local y=v+1 end ) ) + + -- is NaN + lu.assertFailure( lu.assertNotIsNaN, 0 / 0) + lu.assertFailure( lu.assertNotIsNaN, -0 / 0) + lu.assertFailure( lu.assertNotIsNaN, 0 / -0) + lu.assertFailure( lu.assertNotIsNaN, -0 / -0) + local inf = math.huge + lu.assertFailure( lu.assertNotIsNaN, inf / inf) + lu.assertFailure( lu.assertNotIsNaN, -inf / inf) + lu.assertFailure( lu.assertNotIsNaN, inf / -inf) + lu.assertFailure( lu.assertNotIsNaN, -inf / -inf) + lu.assertFailure( lu.assertNotIsNaN, inf - inf) + lu.assertFailure( lu.assertNotIsNaN, (-inf) + inf) + lu.assertFailure( lu.assertNotIsNaN, inf + (-inf)) + lu.assertFailure( lu.assertNotIsNaN, (-inf) - (-inf)) + lu.assertFailure( lu.assertNotIsNaN, 0 * inf) + lu.assertFailure( lu.assertNotIsNaN, -0 * inf) + lu.assertFailure( lu.assertNotIsNaN, 0 * -inf) + lu.assertFailure( lu.assertNotIsNaN, -0 * -inf) + lu.assertFailure( lu.assertNotIsNaN, math.sqrt(-1)) + if lu._LUAVERSION == "Lua 5.1" or lu._LUAVERSION == "Lua 5.2" then + -- Lua 5.3 will complain/error "bad argument #2 to 'fmod' (zero)" + lu.assertFailure( lu.assertNotIsNaN, math.fmod(1, 0)) + lu.assertFailure( lu.assertNotIsNaN, math.fmod(1, -0)) + end + lu.assertFailure( lu.assertNotIsNaN, math.fmod(inf, 1)) + lu.assertFailure( lu.assertNotIsNaN, math.fmod(-inf, 1)) + + -- not NaN + assertFailure(lu.assertNotIsNaN, 0 / 1) -- 0.0 + assertFailure(lu.assertNotIsNaN, 1 / 0) -- inf + assertFailure(lu.assertNotIdNaN, -1 / 0) -- -inf + end + + function TestLuaUnitAssertions:test_assertIsInf() + assertFailure(lu.assertIsInf, "hi there!") + assertFailure(lu.assertIsInf, nil) + assertFailure(lu.assertIsInf, {}) + assertFailure(lu.assertIsInf, {1,2,3}) + assertFailure(lu.assertIsInf, {1}) + assertFailure(lu.assertIsInf, coroutine.create( function(v) local y=v+1 end ) ) + + assertFailure(lu.assertIsInf, 0 ) + assertFailure(lu.assertIsInf, 1 ) + assertFailure(lu.assertIsInf, 0 / 0) -- NaN + assertFailure(lu.assertIsInf, -0 / 0) -- NaN + assertFailure(lu.assertIsInf, 0 / 1) -- 0.0 + + lu.assertIsInf(1 / 0) -- inf + lu.assertIsInf(math.log(0)) -- -inf + lu.assertIsInf(math.huge) -- inf + lu.assertIsInf(-math.huge) -- -inf + end + + function TestLuaUnitAssertions:test_assertIsPlusInf() + assertFailure(lu.assertIsPlusInf, "hi there!") + assertFailure(lu.assertIsPlusInf, nil) + assertFailure(lu.assertIsPlusInf, {}) + assertFailure(lu.assertIsPlusInf, {1,2,3}) + assertFailure(lu.assertIsPlusInf, {1}) + assertFailure(lu.assertIsPlusInf, coroutine.create( function(v) local y=v+1 end ) ) + + assertFailure(lu.assertIsPlusInf, 0 ) + assertFailure(lu.assertIsPlusInf, 1 ) + assertFailure(lu.assertIsPlusInf, 0 / 0) -- NaN + assertFailure(lu.assertIsPlusInf, -0 / 0) -- NaN + assertFailure(lu.assertIsPlusInf, 0 / 1) -- 0.0 + assertFailure(lu.assertIsPlusInf, math.log(0)) -- -inf + assertFailure(lu.assertIsPlusInf, -math.huge) -- -inf + + lu.assertIsPlusInf(1 / 0) -- inf + lu.assertIsPlusInf(math.huge) -- inf + + -- behavior with -0 is lua version dependant: + -- lua51, lua53: -0 does NOT represent the value minus zero BUT plus zero + -- lua52, luajit: -0 represents the value minus zero + -- this is verified with the value 1/-0 + -- lua 5.1, 5.3: 1/-0 = inf + -- lua 5.2, luajit: 1/-0 = -inf + if lu._LUAVERSION == "Lua 5.1" or lu._LUAVERSION == "Lua 5.3" then + lu.assertIsPlusInf( 1/-0 ) + else + assertFailure( lu.assertIsPlusInf, 1/-0 ) + end + end + + + function TestLuaUnitAssertions:test_assertIsMinusInf() + assertFailure(lu.assertIsMinusInf, "hi there!") + assertFailure(lu.assertIsMinusInf, nil) + assertFailure(lu.assertIsMinusInf, {}) + assertFailure(lu.assertIsMinusInf, {1,2,3}) + assertFailure(lu.assertIsMinusInf, {1}) + assertFailure(lu.assertIsMinusInf, coroutine.create( function(v) local y=v+1 end ) ) + + assertFailure(lu.assertIsMinusInf, 0 ) + assertFailure(lu.assertIsMinusInf, 1 ) + assertFailure(lu.assertIsMinusInf, 0 / 0) -- NaN + assertFailure(lu.assertIsMinusInf, -0 / 0) -- NaN + assertFailure(lu.assertIsMinusInf, 0 / 1) -- 0.0 + assertFailure(lu.assertIsMinusInf, -math.log(0)) -- inf + assertFailure(lu.assertIsMinusInf, math.huge) -- inf + + lu.assertIsMinusInf( math.log(0)) -- -inf + lu.assertIsMinusInf(-1 / 0) -- -inf + lu.assertIsMinusInf(-math.huge) -- -inf + + -- behavior with -0 is lua version dependant: + -- lua51, lua53: -0 does NOT represent the value minus zero BUT plus zero + -- lua52, luajit: -0 represents the value minus zero + -- this is verified with the value 1/-0 + -- lua 5.1, 5.3: 1/-0 = inf + -- lua 5.2, luajit: 1/-0 = -inf + if lu._LUAVERSION == "Lua 5.1" or lu._LUAVERSION == "Lua 5.3" then + assertFailure( lu.assertIsMinusInf, 1/-0 ) + else + lu.assertIsMinusInf( 1/-0 ) + end + + end + + function TestLuaUnitAssertions:test_assertNotIsInf() + -- not inf + lu.assertNotIsInf( "hi there!") + lu.assertNotIsInf( nil) + lu.assertNotIsInf( {}) + lu.assertNotIsInf( {1,2,3}) + lu.assertNotIsInf( {1}) + lu.assertNotIsInf( coroutine.create( function(v) local y=v+1 end ) ) + + -- not inf + lu.assertNotIsInf( 0 ) + lu.assertNotIsInf( 1 ) + lu.assertNotIsInf( 0 / 0) -- NaN + lu.assertNotIsInf( -0 / 0) -- NaN + lu.assertNotIsInf( 0 / 1) -- 0.0 + + -- inf + assertFailure( lu.assertNotIsInf, 1 / 0) -- inf + assertFailure( lu.assertNotIsInf, math.log(0)) -- -inf + assertFailure( lu.assertNotIsInf, math.huge) -- inf + assertFailure( lu.assertNotIsInf, math.huge) -- -inf + end + + function TestLuaUnitAssertions:test_assertNotIsPlusInf() + -- not inf + lu.assertNotIsPlusInf( "hi there!") + lu.assertNotIsPlusInf( nil) + lu.assertNotIsPlusInf( {}) + lu.assertNotIsPlusInf( {1,2,3}) + lu.assertNotIsPlusInf( {1}) + lu.assertNotIsPlusInf( coroutine.create( function(v) local y=v+1 end ) ) + + lu.assertNotIsPlusInf( 0 ) + lu.assertNotIsPlusInf( 1 ) + lu.assertNotIsPlusInf( 0 / 0) -- NaN + lu.assertNotIsPlusInf( -0 / 0) -- NaN + lu.assertNotIsPlusInf( 0 / 1) -- 0.0 + lu.assertNotIsPlusInf( math.log(0)) -- -inf + lu.assertNotIsPlusInf( -math.huge) -- -inf + + -- inf + assertFailure( lu.assertNotIsPlusInf, 1 / 0) -- inf + assertFailure( lu.assertNotIsPlusInf, math.huge) -- inf + end + + + function TestLuaUnitAssertions:test_assertNotIsMinusInf() + -- not inf + lu.assertNotIsMinusInf( "hi there!") + lu.assertNotIsMinusInf( nil) + lu.assertNotIsMinusInf( {}) + lu.assertNotIsMinusInf( {1,2,3}) + lu.assertNotIsMinusInf( {1}) + lu.assertNotIsMinusInf( coroutine.create( function(v) local y=v+1 end ) ) + + lu.assertNotIsMinusInf( 0 ) + lu.assertNotIsMinusInf( 1 ) + lu.assertNotIsMinusInf( 0 / 0) -- NaN + lu.assertNotIsMinusInf( -0 / 0) -- NaN + lu.assertNotIsMinusInf( 0 / 1) -- 0.0 + lu.assertNotIsMinusInf( -math.log(0)) -- inf + lu.assertNotIsMinusInf( math.huge) -- inf + + -- inf + assertFailure( lu.assertNotIsMinusInf, math.log(0)) -- -inf + assertFailure( lu.assertNotIsMinusInf, -1 / 0) -- -inf + assertFailure( lu.assertNotIsMinusInf, -math.huge) -- -inf + end + + -- enable it only for debugging + --[[ + function Xtest_printHandlingOfZeroAndInf() + local inf = 1/0 + print( ' inf = ' .. inf ) + print( '-inf = ' .. -inf ) + print( ' 1/inf = ' .. 1/inf ) + print( '-1/inf = ' .. -1/inf ) + print( ' 1/-inf = ' .. 1/-inf ) + print( '-1/-inf = ' .. -1/-inf ) + print() + print( ' 1/-0 = ' .. 1/-0 ) + print() + print( ' -0 = ' .. -0 ) + print( ' 0/-1 = ' .. 0/-1 ) + print( ' 0*-1 = ' .. 0*-1 ) + print( '-0/-1 = ' .. -0/-1 ) + print( '-0*-1 = ' .. -0*-1 ) + print( '(-0)/-1 = ' .. (-0)/-1 ) + print( ' 1/(0/-1) = ' .. 1/(0/-1) ) + print( ' 1/(-0/-1) = ' .. 1/(-0/-1) ) + print( '-1/(0/-1) = ' .. -1/(0/-1) ) + print( '-1/(-0/-1) = ' .. -1/(-0/-1) ) + + print() + local minusZero = -1 / (1/0) + print( 'minusZero = -1 / (1/0)' ) + print( 'minusZero = '..minusZero) + print( ' 1/minusZero = ' .. 1/minusZero ) + print() + print( 'minusZero/-1 = ' .. minusZero/-1 ) + print( 'minusZero*-1 = ' .. minusZero*-1 ) + print( ' 1/(minusZero/-1) = ' .. 1/(minusZero/-1) ) + print( '-1/(minusZero/-1) = ' .. -1/(minusZero/-1) ) + + end + ]] + + --[[ #### Important note when dealing with -0 and infinity #### + + 1. Dealing with infinity is consistent, the only difference is whether the resulting 0 is integer or float + + Lua 5.3: dividing by infinity yields float 0 + With inf = 1/0: + -inf = -inf + 1/inf = 0.0 + -1/inf = -0.0 + 1/-inf = -0.0 + -1/-inf = 0.0 + + Lua 5.2 and 5.1 and luajit: dividing by infinity yields integer 0 + -inf =-1.#INF + 1/inf = 0 + -1/inf = -0 + 1/-inf = -0 + -1/-inf = 0 + + 2. Dealing with minus 0 is totally inconsistent mathematically and accross lua versions if you use the syntax -0. + It works correctly if you create the value by minusZero = -1 / (1/0) + + Enable the function above to see the extent of the damage of -0 : + + Lua 5.1: + * -0 is consistently considered as 0 + * 0 multipllied or diveded by -1 is still 0 + * -0 multipllied or diveded by -1 is still 0 + + Lua 5.2 and LuaJIT: + * -0 is consistently -0 + * 0 multipllied or diveded by -1 is correctly -0 + * -0 multipllied or diveded by -1 is correctly 0 + + Lua 5.3: + * -0 is consistently considered as 0 + * 0 multipllied by -1 is correctly -0 but divided by -1 yields 0 + * -0 multipllied by -1 is 0 but diveded by -1 is -0 + ]] + + function TestLuaUnitAssertions:test_assertIsPlusZero() + assertFailure(lu.assertIsPlusZero, "hi there!") + assertFailure(lu.assertIsPlusZero, nil) + assertFailure(lu.assertIsPlusZero, {}) + assertFailure(lu.assertIsPlusZero, {1,2,3}) + assertFailure(lu.assertIsPlusZero, {1}) + assertFailure(lu.assertIsPlusZero, coroutine.create( function(v) local y=v+1 end ) ) + + local inf = 1/0 + assertFailure(lu.assertIsPlusZero, 1 ) + assertFailure(lu.assertIsPlusZero, 0 / 0) -- NaN + assertFailure(lu.assertIsPlusZero, -0 / 0) -- NaN + assertFailure(lu.assertIsPlusZero, math.log(0)) -- inf + assertFailure(lu.assertIsPlusZero, math.huge) -- inf + assertFailure(lu.assertIsPlusZero, -math.huge) -- -inf + assertFailure(lu.assertIsPlusZero, -1/inf) -- -0.0 + + lu.assertIsPlusZero( 0 / 1) + lu.assertIsPlusZero( 0 ) + lu.assertIsPlusZero( 1/inf ) + + -- behavior with -0 is lua version dependant, see note above + if lu._LUAVERSION == "Lua 5.1" or lu._LUAVERSION == "Lua 5.3" then + lu.assertIsPlusZero( -0 ) + else + assertFailure( lu.assertIsPlusZero, -0 ) + end + end + + function TestLuaUnitAssertions:test_assertNotIsPlusZero() + -- not plus zero + lu.assertNotIsPlusZero( "hi there!") + lu.assertNotIsPlusZero( nil) + lu.assertNotIsPlusZero( {}) + lu.assertNotIsPlusZero( {1,2,3}) + lu.assertNotIsPlusZero( {1}) + lu.assertNotIsPlusZero( coroutine.create( function(v) local y=v+1 end ) ) + + local inf = 1/0 + lu.assertNotIsPlusZero( 1 ) + lu.assertNotIsPlusZero( 0 / 0) -- NaN + lu.assertNotIsPlusZero( -0 / 0) -- NaN + lu.assertNotIsPlusZero( math.log(0)) -- inf + lu.assertNotIsPlusZero( math.huge) -- inf + lu.assertNotIsPlusZero( -math.huge) -- -inf + lu.assertNotIsPlusZero( -1/inf ) -- -0.0 + + -- plus zero + assertFailure( lu.assertNotIsPlusZero, 0 / 1) + assertFailure( lu.assertNotIsPlusZero, 0 ) + assertFailure( lu.assertNotIsPlusZero, 1/inf ) + + -- behavior with -0 is lua version dependant, see note above + if lu._LUAVERSION == "Lua 5.1" or lu._LUAVERSION == "Lua 5.3" then + assertFailure( lu.assertNotIsPlusZero, -0 ) + else + lu.assertNotIsPlusZero( -0 ) + end + end + + + function TestLuaUnitAssertions:test_assertIsMinusZero() + assertFailure(lu.assertIsMinusZero, "hi there!") + assertFailure(lu.assertIsMinusZero, nil) + assertFailure(lu.assertIsMinusZero, {}) + assertFailure(lu.assertIsMinusZero, {1,2,3}) + assertFailure(lu.assertIsMinusZero, {1}) + assertFailure(lu.assertIsMinusZero, coroutine.create( function(v) local y=v+1 end ) ) + + local inf = 1/0 + assertFailure(lu.assertIsMinusZero, 1 ) + assertFailure(lu.assertIsMinusZero, 0 / 0) -- NaN + assertFailure(lu.assertIsMinusZero, -0 / 0) -- NaN + assertFailure(lu.assertIsMinusZero, math.log(0)) -- inf + assertFailure(lu.assertIsMinusZero, math.huge) -- inf + assertFailure(lu.assertIsMinusZero, -math.huge) -- -inf + assertFailure(lu.assertIsMinusZero, 1/inf) -- -0.0 + assertFailure(lu.assertIsMinusZero, 0 ) + + + lu.assertIsMinusZero( -1/inf ) + lu.assertIsMinusZero( 1/-inf ) + + -- behavior with -0 is lua version dependant, see note above + if lu._LUAVERSION == "Lua 5.1" or lu._LUAVERSION == "Lua 5.3" then + assertFailure( lu.assertIsMinusZero, -0 ) + else + lu.assertIsMinusZero( -0 ) + end + end + + function TestLuaUnitAssertions:test_assertNotIsMinusZero() + lu.assertNotIsMinusZero( "hi there!") + lu.assertNotIsMinusZero( nil) + lu.assertNotIsMinusZero( {}) + lu.assertNotIsMinusZero( {1,2,3}) + lu.assertNotIsMinusZero( {1}) + lu.assertNotIsMinusZero( coroutine.create( function(v) local y=v+1 end ) ) + + local inf = 1/0 + lu.assertNotIsMinusZero( 1 ) + lu.assertNotIsMinusZero( 0 / 0) -- NaN + lu.assertNotIsMinusZero( -0 / 0) -- NaN + lu.assertNotIsMinusZero( math.log(0)) -- inf + lu.assertNotIsMinusZero( math.huge) -- inf + lu.assertNotIsMinusZero( -math.huge) -- -inf + lu.assertNotIsMinusZero( 0 ) + lu.assertNotIsMinusZero( 1/inf) -- -0.0 + + assertFailure( lu.assertNotIsMinusZero, -1/inf ) + assertFailure( lu.assertNotIsMinusZero, 1/-inf ) + + -- behavior with -0 is lua version dependant, see note above + if lu._LUAVERSION == "Lua 5.1" or lu._LUAVERSION == "Lua 5.3" then + lu.assertNotIsMinusZero( -0 ) + else + assertFailure( lu.assertNotIsMinusZero, -0 ) + end + end + + function TestLuaUnitAssertions:test_assertIsString() + assertFailure(lu.assertIsString, 1) + assertFailure(lu.assertIsString, 1.4) + lu.assertIsString("hi there!") + assertFailure(lu.assertIsString, nil) + assertFailure(lu.assertIsString, {}) + assertFailure(lu.assertIsString, {1,2,3}) + assertFailure(lu.assertIsString, {1}) + assertFailure(lu.assertIsString, coroutine.create( function(v) local y=v+1 end ) ) + assertFailure(lu.assertIsString, true) + end + + function TestLuaUnitAssertions:test_assertIsTable() + assertFailure(lu.assertIsTable, 1) + assertFailure(lu.assertIsTable, 1.4) + assertFailure(lu.assertIsTable, "hi there!") + assertFailure(lu.assertIsTable, nil) + lu.assertIsTable({}) + lu.assertIsTable({1,2,3}) + lu.assertIsTable({1}) + assertFailure(lu.assertIsTable, true) + assertFailure(lu.assertIsTable, coroutine.create( function(v) local y=v+1 end ) ) + end + + function TestLuaUnitAssertions:test_assertIsBoolean() + assertFailure(lu.assertIsBoolean, 1) + assertFailure(lu.assertIsBoolean, 1.4) + assertFailure(lu.assertIsBoolean, "hi there!") + assertFailure(lu.assertIsBoolean, nil) + assertFailure(lu.assertIsBoolean, {}) + assertFailure(lu.assertIsBoolean, {1,2,3}) + assertFailure(lu.assertIsBoolean, {1}) + assertFailure(lu.assertIsBoolean, coroutine.create( function(v) local y=v+1 end ) ) + lu.assertIsBoolean(true) + lu.assertIsBoolean(false) + end + + function TestLuaUnitAssertions:test_assertIsNil() + assertFailure(lu.assertIsNil, 1) + assertFailure(lu.assertIsNil, 1.4) + assertFailure(lu.assertIsNil, "hi there!") + lu.assertIsNil(nil) + assertFailure(lu.assertIsNil, {}) + assertFailure(lu.assertIsNil, {1,2,3}) + assertFailure(lu.assertIsNil, {1}) + assertFailure(lu.assertIsNil, false) + assertFailure(lu.assertIsNil, coroutine.create( function(v) local y=v+1 end ) ) + end + + function TestLuaUnitAssertions:test_assertIsFunction() + local f = function() return true end + + assertFailure(lu.assertIsFunction, 1) + assertFailure(lu.assertIsFunction, 1.4) + assertFailure(lu.assertIsFunction, "hi there!") + assertFailure(lu.assertIsFunction, nil) + assertFailure(lu.assertIsFunction, {}) + assertFailure(lu.assertIsFunction, {1,2,3}) + assertFailure(lu.assertIsFunction, {1}) + assertFailure(lu.assertIsFunction, false) + assertFailure(lu.assertIsFunction, coroutine.create( function(v) local y=v+1 end ) ) + lu.assertIsFunction(f) + end + + function TestLuaUnitAssertions:test_assertIsThread() + assertFailure(lu.assertIsThread, 1) + assertFailure(lu.assertIsThread, 1.4) + assertFailure(lu.assertIsThread, "hi there!") + assertFailure(lu.assertIsThread, nil) + assertFailure(lu.assertIsThread, {}) + assertFailure(lu.assertIsThread, {1,2,3}) + assertFailure(lu.assertIsThread, {1}) + assertFailure(lu.assertIsThread, false) + assertFailure(lu.assertIsThread, function(v) local y=v+1 end ) + lu.assertIsThread(coroutine.create( function(v) local y=v+1 end ) ) + end + + function TestLuaUnitAssertions:test_assertIsUserdata() + assertFailure(lu.assertIsUserdata, 1) + assertFailure(lu.assertIsUserdata, 1.4) + assertFailure(lu.assertIsUserdata, "hi there!") + assertFailure(lu.assertIsUserdata, nil) + assertFailure(lu.assertIsUserdata, {}) + assertFailure(lu.assertIsUserdata, {1,2,3}) + assertFailure(lu.assertIsUserdata, {1}) + assertFailure(lu.assertIsUserdata, false) + assertFailure(lu.assertIsUserdata, function(v) local y=v+1 end ) + assertFailure(lu.assertIsUserdata, coroutine.create( function(v) local y=v+1 end ) ) + end + + function TestLuaUnitAssertions:test_assertNotIsNumber() + assertFailure(lu.assertNotIsNumber, 1 ) + assertFailure(lu.assertNotIsNumber, 1.4 ) + lu.assertNotIsNumber( "hi there!") + lu.assertNotIsNumber( nil) + lu.assertNotIsNumber( {}) + lu.assertNotIsNumber( {1,2,3}) + lu.assertNotIsNumber( {1}) + lu.assertNotIsNumber( coroutine.create( function(v) local y=v+1 end ) ) + lu.assertNotIsNumber( true) + end + + function TestLuaUnitAssertions:test_assertNotIsNaN() + lu.assertNotIsNaN( "hi there!" ) + lu.assertNotIsNaN( nil ) + lu.assertNotIsNaN( {} ) + lu.assertNotIsNaN( {1,2,3} ) + lu.assertNotIsNaN( {1} ) + lu.assertNotIsNaN( coroutine.create( function(v) local y=v+1 end ) ) + assertFailure(lu.assertNotIsNaN, 0 / 0) + assertFailure(lu.assertNotIsNaN, -0 / 0) + assertFailure(lu.assertNotIsNaN, 0 / -0) + assertFailure(lu.assertNotIsNaN, -0 / -0) + local inf = math.huge + assertFailure(lu.assertNotIsNaN, inf / inf) + assertFailure(lu.assertNotIsNaN, -inf / inf) + assertFailure(lu.assertNotIsNaN, inf / -inf) + assertFailure(lu.assertNotIsNaN, -inf / -inf) + assertFailure(lu.assertNotIsNaN, inf - inf) + assertFailure(lu.assertNotIsNaN, (-inf) + inf) + assertFailure(lu.assertNotIsNaN, inf + (-inf)) + assertFailure(lu.assertNotIsNaN, (-inf) - (-inf)) + assertFailure(lu.assertNotIsNaN, 0 * inf) + assertFailure(lu.assertNotIsNaN, -0 * inf) + assertFailure(lu.assertNotIsNaN, 0 * -inf) + assertFailure(lu.assertNotIsNaN, -0 * -inf) + assertFailure(lu.assertNotIsNaN, math.sqrt(-1)) + if lu._LUAVERSION == "Lua 5.1" or lu._LUAVERSION == "Lua 5.2" then + -- Lua 5.3 will complain/error "bad argument #2 to 'fmod' (zero)" + assertFailure(lu.assertNotIsNaN, math.fmod(1, 0)) + assertFailure(lu.assertNotIsNaN, math.fmod(1, -0)) + end + assertFailure(lu.assertNotIsNaN, math.fmod(inf, 1)) + assertFailure(lu.assertNotIsNaN, math.fmod(-inf, 1)) + lu.assertNotIsNaN( 0 / 1 ) -- 0.0 + lu.assertNotIsNaN( 1 / 0 ) -- inf + end + + function TestLuaUnitAssertions:test_assertNotIsInf() + lu.assertNotIsInf( "hi there!" ) + lu.assertNotIsInf( nil) + lu.assertNotIsInf( {}) + lu.assertNotIsInf( {1,2,3}) + lu.assertNotIsInf( {1}) + lu.assertNotIsInf( coroutine.create( function(v) local y=v+1 end ) ) + lu.assertNotIsInf( 0 / 0 ) -- NaN + lu.assertNotIsInf( 0 / 1 ) -- 0.0 + assertFailure(lu.assertNotIsInf, 1 / 0 ) + assertFailure(lu.assertNotIsInf, math.log(0) ) + assertFailure(lu.assertNotIsInf, math.huge ) + assertFailure(lu.assertNotIsInf, -math.huge ) + end + + function TestLuaUnitAssertions:test_assertNotIsString() + lu.assertNotIsString( 1) + lu.assertNotIsString( 1.4) + assertFailure( lu.assertNotIsString, "hi there!") + lu.assertNotIsString( nil) + lu.assertNotIsString( {}) + lu.assertNotIsString( {1,2,3}) + lu.assertNotIsString( {1}) + lu.assertNotIsString( coroutine.create( function(v) local y=v+1 end ) ) + lu.assertNotIsString( true) + end + + function TestLuaUnitAssertions:test_assertNotIsTable() + lu.assertNotIsTable( 1) + lu.assertNotIsTable( 1.4) + lu.assertNotIsTable( "hi there!") + lu.assertNotIsTable( nil) + assertFailure( lu.assertNotIsTable, {}) + assertFailure( lu.assertNotIsTable, {1,2,3}) + assertFailure( lu.assertNotIsTable, {1}) + lu.assertNotIsTable( true) + lu.assertNotIsTable( coroutine.create( function(v) local y=v+1 end ) ) + end + + function TestLuaUnitAssertions:test_assertNotIsBoolean() + lu.assertNotIsBoolean( 1) + lu.assertNotIsBoolean( 1.4) + lu.assertNotIsBoolean( "hi there!") + lu.assertNotIsBoolean( nil) + lu.assertNotIsBoolean( {}) + lu.assertNotIsBoolean( {1,2,3}) + lu.assertNotIsBoolean( {1}) + lu.assertNotIsBoolean( coroutine.create( function(v) local y=v+1 end ) ) + assertFailure( lu.assertNotIsBoolean, true) + assertFailure( lu.assertNotIsBoolean, false) + end + + function TestLuaUnitAssertions:test_assertNotIsNil() + lu.assertNotIsNil( 1) + lu.assertNotIsNil( 1.4) + lu.assertNotIsNil( "hi there!") + assertFailure( lu.assertNotIsNil, nil) + lu.assertNotIsNil( {}) + lu.assertNotIsNil( {1,2,3}) + lu.assertNotIsNil( {1}) + lu.assertNotIsNil( false) + lu.assertNotIsNil( coroutine.create( function(v) local y=v+1 end ) ) + end + + function TestLuaUnitAssertions:test_assertNotIsFunction() + local f = function() return true end + + lu.assertNotIsFunction( 1) + lu.assertNotIsFunction( 1.4) + lu.assertNotIsFunction( "hi there!") + lu.assertNotIsFunction( nil) + lu.assertNotIsFunction( {}) + lu.assertNotIsFunction( {1,2,3}) + lu.assertNotIsFunction( {1}) + lu.assertNotIsFunction( false) + lu.assertNotIsFunction( coroutine.create( function(v) local y=v+1 end ) ) + assertFailure( lu.assertNotIsFunction, f) + end + + function TestLuaUnitAssertions:test_assertNotIsThread() + lu.assertNotIsThread( 1) + lu.assertNotIsThread( 1.4) + lu.assertNotIsThread( "hi there!") + lu.assertNotIsThread( nil) + lu.assertNotIsThread( {}) + lu.assertNotIsThread( {1,2,3}) + lu.assertNotIsThread( {1}) + lu.assertNotIsThread( false) + lu.assertNotIsThread( function(v) local y=v+1 end ) + assertFailure( lu.assertNotIsThread, coroutine.create( function(v) local y=v+1 end ) ) + end + + function TestLuaUnitAssertions:test_assertNotIsUserdata() + lu.assertNotIsUserdata( 1) + lu.assertNotIsUserdata( 1.4) + lu.assertNotIsUserdata( "hi there!") + lu.assertNotIsUserdata( nil) + lu.assertNotIsUserdata( {}) + lu.assertNotIsUserdata( {1,2,3}) + lu.assertNotIsUserdata( {1}) + lu.assertNotIsUserdata( false) + lu.assertNotIsUserdata( function(v) local y=v+1 end ) + lu.assertNotIsUserdata( coroutine.create( function(v) local y=v+1 end ) ) + end + + function TestLuaUnitAssertions:test_assertIs() + local f = function() return true end + local g = function() return true end + local t1= {} + local t2={1,2} + local t3={1,2} + local t4= {a=1,{1,2},day="today"} + local s1='toto' + local s2='toto' + local s3='to'..'to' + local b1=true + local b2=false + + lu.assertIs(1,1) + lu.assertIs(f,f) + lu.assertIs('toto', 'toto') + lu.assertIs(s1, s2) + lu.assertIs(s1, s3) + lu.assertIs(t1,t1) + lu.assertIs(t4,t4) + lu.assertIs(b1, true) + lu.assertIs(b2, false) + + assertFailure(lu.assertIs, 1, 2) + assertFailure(lu.assertIs, 1.4, 1) + assertFailure(lu.assertIs, "hi there!", "hola") + assertFailure(lu.assertIs, nil, 1) + assertFailure(lu.assertIs, {}, {}) + assertFailure(lu.assertIs, {1,2,3}, f) + assertFailure(lu.assertIs, f, g) + assertFailure(lu.assertIs, t2,t3 ) + assertFailure(lu.assertIs, b2, nil) + end + + function TestLuaUnitAssertions:test_assertNotIs() + local f = function() return true end + local g = function() return true end + local t1= {} + local t2={1,2} + local t3={1,2} + local t4= {a=1,{1,2},day="today"} + local s1='toto' + local s2='toto' + local b1=true + local b2=false + + assertFailure( lu.assertNotIs, 1,1 ) + assertFailure( lu.assertNotIs, f,f ) + assertFailure( lu.assertNotIs, t1,t1 ) + assertFailure( lu.assertNotIs, t4,t4) + assertFailure( lu.assertNotIs, s1,s2 ) + assertFailure( lu.assertNotIs, 'toto', 'toto' ) + assertFailure( lu.assertNotIs, b1, true ) + assertFailure( lu.assertNotIs, b2, false ) + + lu.assertNotIs(1, 2) + lu.assertNotIs(1.4, 1) + lu.assertNotIs("hi there!", "hola") + lu.assertNotIs(nil, 1) + lu.assertNotIs({}, {}) + lu.assertNotIs({1,2,3}, f) + lu.assertNotIs(f, g) + lu.assertNotIs(t2,t3) + lu.assertNotIs(b1, false) + lu.assertNotIs(b2, true) + lu.assertNotIs(b2, nil) + end + + function TestLuaUnitAssertions:test_assertTableNum() + lu.assertEquals( 3, 3 ) + lu.assertNotEquals( 3, 4 ) + lu.assertEquals( {3}, {3} ) + lu.assertNotEquals( {3}, 3 ) + lu.assertNotEquals( {3}, {4} ) + lu.assertEquals( {x=1}, {x=1} ) + lu.assertNotEquals( {x=1}, {x=2} ) + lu.assertNotEquals( {x=1}, {y=1} ) + end + function TestLuaUnitAssertions:test_assertTableStr() + lu.assertEquals( '3', '3' ) + lu.assertNotEquals( '3', '4' ) + lu.assertEquals( {'3'}, {'3'} ) + lu.assertNotEquals( {'3'}, '3' ) + lu.assertNotEquals( {'3'}, {'4'} ) + lu.assertEquals( {x='1'}, {x='1'} ) + lu.assertNotEquals( {x='1'}, {x='2'} ) + lu.assertNotEquals( {x='1'}, {y='1'} ) + end + function TestLuaUnitAssertions:test_assertTableLev2() + lu.assertEquals( {x={'a'}}, {x={'a'}} ) + lu.assertNotEquals( {x={'a'}}, {x={'b'}} ) + lu.assertNotEquals( {x={'a'}}, {z={'a'}} ) + lu.assertEquals( {{x=1}}, {{x=1}} ) + lu.assertNotEquals( {{x=1}}, {{y=1}} ) + lu.assertEquals( {{x='a'}}, {{x='a'}} ) + lu.assertNotEquals( {{x='a'}}, {{x='b'}} ) + end + function TestLuaUnitAssertions:test_assertTableList() + lu.assertEquals( {3,4,5}, {3,4,5} ) + lu.assertNotEquals( {3,4,5}, {3,4,6} ) + lu.assertNotEquals( {3,4,5}, {3,5,4} ) + lu.assertEquals( {3,4,x=5}, {3,4,x=5} ) + lu.assertNotEquals( {3,4,x=5}, {3,4,x=6} ) + lu.assertNotEquals( {3,4,x=5}, {3,x=4,5} ) + lu.assertNotEquals( {3,4,5}, {2,3,4,5} ) + lu.assertNotEquals( {3,4,5}, {3,2,4,5} ) + lu.assertNotEquals( {3,4,5}, {3,4,5,6} ) + end + + function TestLuaUnitAssertions:test_assertTableNil() + lu.assertEquals( {3,4,5}, {3,4,5} ) + lu.assertNotEquals( {3,4,5}, {nil,3,4,5} ) + lu.assertNotEquals( {3,4,5}, {nil,4,5} ) + lu.assertEquals( {3,4,5}, {3,4,5,nil} ) -- lua quirk + lu.assertNotEquals( {3,4,5}, {3,4,nil} ) + lu.assertNotEquals( {3,4,5}, {3,nil,5} ) + lu.assertNotEquals( {3,4,5}, {3,4,nil,5} ) + end + + function TestLuaUnitAssertions:test_assertTableNilFront() + lu.assertEquals( {nil,4,5}, {nil,4,5} ) + lu.assertNotEquals( {nil,4,5}, {nil,44,55} ) + lu.assertEquals( {nil,'4','5'}, {nil,'4','5'} ) + lu.assertNotEquals( {nil,'4','5'}, {nil,'44','55'} ) + lu.assertEquals( {nil,{4,5}}, {nil,{4,5}} ) + lu.assertNotEquals( {nil,{4,5}}, {nil,{44,55}} ) + lu.assertNotEquals( {nil,{4}}, {nil,{44}} ) + lu.assertEquals( {nil,{x=4,5}}, {nil,{x=4,5}} ) + lu.assertEquals( {nil,{x=4,5}}, {nil,{5,x=4}} ) -- lua quirk + lu.assertEquals( {nil,{x=4,y=5}}, {nil,{y=5,x=4}} ) -- lua quirk + lu.assertNotEquals( {nil,{x=4,5}}, {nil,{y=4,5}} ) + end + + function TestLuaUnitAssertions:test_assertTableAdditions() + lu.assertEquals( {1,2,3}, {1,2,3} ) + lu.assertNotEquals( {1,2,3}, {1,2,3,4} ) + lu.assertNotEquals( {1,2,3,4}, {1,2,3} ) + lu.assertEquals( {1,x=2,3}, {1,x=2,3} ) + lu.assertNotEquals( {1,x=2,3}, {1,x=2,3,y=4} ) + lu.assertNotEquals( {1,x=2,3,y=4}, {1,x=2,3} ) + end + + +local function assertFailureEquals(msg, ...) + lu.assertErrorMsgEquals(lu.FAILURE_PREFIX .. msg, ...) +end + +local function assertFailureMatches(msg, ...) + lu.assertErrorMsgMatches(lu.FAILURE_PREFIX .. msg, ...) +end + +local function assertFailureContains(msg, ...) + lu.assertErrorMsgContains(lu.FAILURE_PREFIX .. msg, ...) +end + +TestLuaUnitAssertionsError = {} + + function TestLuaUnitAssertionsError:setUp() + self.f = function ( v ) + local y = v + 1 + end + self.f_with_error = function (v) + local y = v + 2 + error('This is an error', 2) + end + + self.f_with_table_error = function (v) + local y = v + 2 + local ts = { __tostring = function() return 'This table has error!' end } + error( setmetatable( { this_table="has error" }, ts ) ) + end + + + end + + function TestLuaUnitAssertionsError:test_assertError() + local x = 1 + + -- f_with_error generates an error + local has_error = not pcall( self.f_with_error, x ) + lu.assertEquals( has_error, true ) + + -- f does not generate an error + has_error = not pcall( self.f, x ) + lu.assertEquals( has_error, false ) + + -- lu.assertError is happy with f_with_error + lu.assertError( self.f_with_error, x ) + + -- lu.assertError is unhappy with f + assertFailureEquals( "Expected an error when calling function but no error generated", + lu.assertError, self.f, x ) + + -- multiple arguments + local function f_with_multi_arguments(a,b,c) + if a == b and b == c then return end + error("three arguments not equal") + end + + lu.assertError( f_with_multi_arguments, 1, 1, 3 ) + lu.assertError( f_with_multi_arguments, 1, 3, 1 ) + lu.assertError( f_with_multi_arguments, 3, 1, 1 ) + + assertFailureEquals( "Expected an error when calling function but no error generated", + lu.assertError, f_with_multi_arguments, 1, 1, 1 ) + + -- error generated as table + lu.assertError( self.f_with_table_error, 1 ) + + end + + function TestLuaUnitAssertionsError:test_assertErrorMsgContains() + local x = 1 + assertFailure( lu.assertErrorMsgContains, 'toto', self.f, x ) + lu.assertErrorMsgContains( 'is an err', self.f_with_error, x ) + lu.assertErrorMsgContains( 'This is an error', self.f_with_error, x ) + assertFailure( lu.assertErrorMsgContains, ' This is an error', self.f_with_error, x ) + assertFailure( lu.assertErrorMsgContains, 'This .. an error', self.f_with_error, x ) + lu.assertErrorMsgContains("50", function() error(500) end) + + -- error message is a table which converts to a string + lu.assertErrorMsgContains( 'This table has error', self.f_with_table_error, 1 ) + end + + function TestLuaUnitAssertionsError:test_assertErrorMsgEquals() + local x = 1 + assertFailure( lu.assertErrorMsgEquals, 'toto', self.f, x ) + assertFailure( lu.assertErrorMsgEquals, 'is an err', self.f_with_error, x ) + + -- expected string, receive string + lu.assertErrorMsgEquals( 'This is an error', self.f_with_error, x ) + + -- expected table, receive table + lu.assertErrorMsgEquals({1,2,3,4}, function() error({1,2,3,4}) end) + + -- expected complex table, receive complex table + lu.assertErrorMsgEquals({ + details = {1,2,3,4}, + id = 10, + }, function() error({ + details = {1,2,3,4}, + id = 10, + }) end) + + -- expected string, receive number converted to string + lu.assertErrorMsgEquals("500", function() error(500, 2) end) + + -- one space added at the beginning + assertFailure( lu.assertErrorMsgEquals, ' This is an error', self.f_with_error, x ) + + -- pattern does not work + assertFailure( lu.assertErrorMsgEquals, 'This .. an error', self.f_with_error, x ) + + -- expected string, receive table which converts to string + lu.assertErrorMsgEquals( "This table has error!", self.f_with_table_error, x) + + -- expected table, no error generated + assertFailure( lu.assertErrorMsgEquals, { 1 }, function( v ) return "{ 1 }" end, 33 ) + + -- expected table, error generated as string, no match + assertFailure( lu.assertErrorMsgEquals, { 1 }, function( v ) error( "{ 1 }" ) end, 33 ) + end + + function TestLuaUnitAssertionsError:test_assertErrorMsgMatches() + local x = 1 + assertFailure( lu.assertErrorMsgMatches, 'toto', self.f, x ) + assertFailure( lu.assertErrorMsgMatches, 'is an err', self.f_with_error, x ) + lu.assertErrorMsgMatches( 'This is an error', self.f_with_error, x ) + lu.assertErrorMsgMatches( 'This is .. error', self.f_with_error, x ) + lu.assertErrorMsgMatches(".*500$", function() error(500, 2) end) + lu.assertErrorMsgMatches("This .* has error!", self.f_with_table_error, 33 ) + + -- one space added to cause failure + assertFailure( lu.assertErrorMsgMatches, ' This is an error', self.f_with_error, x ) + assertFailure( lu.assertErrorMsgMatches, "This", self.f_with_table_error, 33 ) + + + + end + +------------------------------------------------------------------ +-- +-- Failure message tests +-- +------------------------------------------------------------------ + +TestLuaUnitErrorMsg = { __class__ = 'TestLuaUnitErrorMsg' } + + function TestLuaUnitErrorMsg:setUp() + self.old_ORDER_ACTUAL_EXPECTED = lu.ORDER_ACTUAL_EXPECTED + self.old_PRINT_TABLE_REF_IN_ERROR_MSG = lu.PRINT_TABLE_REF_IN_ERROR_MSG + end + + function TestLuaUnitErrorMsg:tearDown() + lu.ORDER_ACTUAL_EXPECTED = self.old_ORDER_ACTUAL_EXPECTED + lu.PRINT_TABLE_REF_IN_ERROR_MSG = self.old_PRINT_TABLE_REF_IN_ERROR_MSG + end + + function TestLuaUnitErrorMsg:test_adjust_err_msg_with_iter() + local err_msg, status + + --------------- FAIL --------------------- + -- file-line info, strip failure prefix, no iteration info + err_msg, status = lu.adjust_err_msg_with_iter( + '.\\test\\test_luaunit.lua:2247: LuaUnit test FAILURE: Expected an error when calling function but no error generated', + nil ) + lu.assertEquals( { err_msg, status }, + { '.\\test\\test_luaunit.lua:2247: Expected an error when calling function but no error generated', + lu.NodeStatus.FAIL } ) + + -- file-line info, strip failure prefix, with iteration info + err_msg, status = lu.adjust_err_msg_with_iter( + '.\\test\\test_luaunit.lua:2247: LuaUnit test FAILURE: Expected an error when calling function but no error generated', + 'iteration 33' ) + lu.assertEquals( { err_msg, status }, + { '.\\test\\test_luaunit.lua:2247: iteration 33, Expected an error when calling function but no error generated', + lu.NodeStatus.FAIL } ) + + -- no file-line info, strip failure prefix, no iteration info + err_msg, status = lu.adjust_err_msg_with_iter( + 'LuaUnit test FAILURE: Expected an error when calling function but no error generated', + nil ) + lu.assertEquals( { err_msg, status }, + { 'Expected an error when calling function but no error generated', + lu.NodeStatus.FAIL } ) + + -- no file-line info, strip failure prefix, with iteration info + err_msg, status = lu.adjust_err_msg_with_iter( + 'LuaUnit test FAILURE: Expected an error when calling function but no error generated', + 'iteration 33' ) + lu.assertEquals( { err_msg, status }, + { 'iteration 33, Expected an error when calling function but no error generated', + lu.NodeStatus.FAIL } ) + + --------------- ERROR --------------------- + -- file-line info, pure error, no iteration info, do nothing + err_msg, status = lu.adjust_err_msg_with_iter( + '.\\test\\test_luaunit.lua:2723: teardown error', + nil ) + lu.assertEquals( { err_msg, status }, + { '.\\test\\test_luaunit.lua:2723: teardown error', + lu.NodeStatus.ERROR } ) + + -- file-line info, pure error, add iteration info + err_msg, status = lu.adjust_err_msg_with_iter( + '.\\test\\test_luaunit.lua:2723: teardown error', + 'iteration 33' ) + lu.assertEquals( { err_msg, status }, + { '.\\test\\test_luaunit.lua:2723: iteration 33, teardown error', + lu.NodeStatus.ERROR } ) + + -- no file-line info, pure error, no iteration info, do nothing + err_msg, status = lu.adjust_err_msg_with_iter( + 'teardown error', + nil ) + lu.assertEquals( { err_msg, status }, + { 'teardown error', + lu.NodeStatus.ERROR } ) + + -- no file-line info, pure error, add iteration info + err_msg, status = lu.adjust_err_msg_with_iter( + 'teardown error', + 'iteration 33' ) + lu.assertEquals( { err_msg, status }, + { 'iteration 33, teardown error', + lu.NodeStatus.ERROR } ) + + --------------- PASS --------------------- + -- file-line info, success, return empty error message + err_msg, status = lu.adjust_err_msg_with_iter( + '.\\test\\test_luaunit.lua:2247: LuaUnit test SUCCESS: the test did actually work !', + nil ) + lu.assertEquals( { err_msg, status }, + { nil, lu.NodeStatus.PASS } ) + + -- file-line info, success, return empty error message, even with iteration + err_msg, status = lu.adjust_err_msg_with_iter( + '.\\test\\test_luaunit.lua:2247: LuaUnit test SUCCESS: the test did actually work !', + 'iteration 33' ) + lu.assertEquals( { err_msg, status }, + { nil, lu.NodeStatus.PASS } ) + + -- no file-line info, success, return empty error message + err_msg, status = lu.adjust_err_msg_with_iter( + 'LuaUnit test SUCCESS: the test did actually work !', + nil ) + lu.assertEquals( { err_msg, status }, + { nil, lu.NodeStatus.PASS } ) + + -- no file-line info, success, return empty error message, even with iteration + err_msg, status = lu.adjust_err_msg_with_iter( + 'LuaUnit test SUCCESS: the test did actually work !', + 'iteration 33' ) + lu.assertEquals( { err_msg, status }, + { nil, lu.NodeStatus.PASS } ) + + end + + + function TestLuaUnitErrorMsg:test_assertEqualsMsg() + assertFailureEquals( 'expected: 2, actual: 1', lu.assertEquals, 1, 2 ) + assertFailureEquals( 'expected: "exp"\nactual: "act"', lu.assertEquals, 'act', 'exp' ) + assertFailureEquals( 'expected: \n"exp\npxe"\nactual: \n"act\ntca"', lu.assertEquals, 'act\ntca', 'exp\npxe' ) + assertFailureEquals( 'expected: true, actual: false', lu.assertEquals, false, true ) + assertFailureEquals( 'expected: 1.2, actual: 1', lu.assertEquals, 1.0, 1.2) + assertFailureMatches( 'expected: {1, 2}\nactual: {2, 1}', lu.assertEquals, {2,1}, {1,2} ) + assertFailureMatches( 'expected: {one=1, two=2}\nactual: {3, 2, 1}', lu.assertEquals, {3,2,1}, {one=1,two=2} ) + assertFailureEquals( 'expected: 2, actual: nil', lu.assertEquals, nil, 2 ) + assertFailureEquals( 'toto\nexpected: 2, actual: nil', lu.assertEquals, nil, 2, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertEqualsOrderReversedMsg() + lu.ORDER_ACTUAL_EXPECTED = false + assertFailureEquals( 'expected: 1, actual: 2', lu.assertEquals, 1, 2 ) + assertFailureEquals( 'expected: "act"\nactual: "exp"', lu.assertEquals, 'act', 'exp' ) + end + + function TestLuaUnitErrorMsg:test_assertAlmostEqualsMsg() + assertFailureEquals('Values are not almost equal\nActual: 2, expected: 1, delta 1 above margin of 0.1', lu.assertAlmostEquals, 2, 1, 0.1 ) + assertFailureEquals('toto\nValues are not almost equal\nActual: 2, expected: 1, delta 1 above margin of 0.1', lu.assertAlmostEquals, 2, 1, 0.1, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertAlmostEqualsOrderReversedMsg() + lu.ORDER_ACTUAL_EXPECTED = false + assertFailureEquals('Values are not almost equal\nActual: 1, expected: 2, delta 1 above margin of 0.1', lu.assertAlmostEquals, 2, 1, 0.1 ) + end + + function TestLuaUnitErrorMsg:test_assertNotAlmostEqualsMsg() + -- single precision math Lua won't output an "exact" delta (0.1) here, so we do a partial match + assertFailureContains('Values are almost equal\nActual: 1.1, expected: 1, delta 0.1 below margin of 0.2', lu.assertNotAlmostEquals, 1.1, 1, 0.2 ) + assertFailureContains('toto\nValues are almost equal\nActual: 1.1, expected: 1, delta 0.1 below margin of 0.2', lu.assertNotAlmostEquals, 1.1, 1, 0.2, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotAlmostEqualsOrderReversedMsg() + -- single precision math Lua won't output an "exact" delta (0.1) here, so we do a partial match + lu.ORDER_ACTUAL_EXPECTED = false + assertFailureContains('Values are almost equal\nActual: 1, expected: 1.1, delta 0.1 below margin of 0.2', lu.assertNotAlmostEquals, 1.1, 1, 0.2 ) + end + + function TestLuaUnitErrorMsg:test_assertNotEqualsMsg() + assertFailureEquals( 'Received the not expected value: 1', lu.assertNotEquals, 1, 1 ) + assertFailureMatches( 'Received the not expected value: {1, 2}', lu.assertNotEquals, {1,2}, {1,2} ) + assertFailureEquals( 'Received the not expected value: nil', lu.assertNotEquals, nil, nil ) + assertFailureEquals( 'toto\nReceived the not expected value: 1', lu.assertNotEquals, 1, 1, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotEqualsOrderReversedMsg() + lu.ORDER_ACTUAL_EXPECTED = false + assertFailureEquals( 'Received the not expected value: 1', lu.assertNotEquals, 1, 1 ) + end + + function TestLuaUnitErrorMsg:test_assertTrueFalse() + assertFailureEquals( 'expected: true, actual: false', lu.assertTrue, false ) + assertFailureEquals( 'expected: true, actual: nil', lu.assertTrue, nil ) + assertFailureEquals( 'expected: false, actual: true', lu.assertFalse, true ) + assertFailureEquals( 'expected: false, actual: nil', lu.assertFalse, nil ) + assertFailureEquals( 'expected: false, actual: 0', lu.assertFalse, 0) + assertFailureMatches( 'expected: false, actual: {}', lu.assertFalse, {}) + assertFailureEquals( 'expected: false, actual: "abc"', lu.assertFalse, 'abc') + assertFailureContains( 'expected: false, actual: function', lu.assertFalse, function () end ) + + assertFailureEquals( 'toto\nexpected: true, actual: false', lu.assertTrue, false, 'toto' ) + assertFailureEquals( 'toto\nexpected: false, actual: 0', lu.assertFalse, 0, 'toto') + end + + function TestLuaUnitErrorMsg:test_assertEvalToTrueFalse() + assertFailureEquals( 'expected: a value evaluating to true, actual: false', lu.assertEvalToTrue, false ) + assertFailureEquals( 'expected: a value evaluating to true, actual: nil', lu.assertEvalToTrue, nil ) + assertFailureEquals( 'expected: false or nil, actual: true', lu.assertEvalToFalse, true ) + assertFailureEquals( 'expected: false or nil, actual: 0', lu.assertEvalToFalse, 0) + assertFailureMatches( 'expected: false or nil, actual: {}', lu.assertEvalToFalse, {}) + assertFailureEquals( 'expected: false or nil, actual: "abc"', lu.assertEvalToFalse, 'abc') + assertFailureContains( 'expected: false or nil, actual: function', lu.assertEvalToFalse, function () end ) + assertFailureEquals( 'toto\nexpected: a value evaluating to true, actual: false', lu.assertEvalToTrue, false, 'toto' ) + assertFailureEquals( 'toto\nexpected: false or nil, actual: 0', lu.assertEvalToFalse, 0, 'toto') + end + + function TestLuaUnitErrorMsg:test_assertNil() + assertFailureEquals( 'expected: nil, actual: false', lu.assertNil, false ) + assertFailureEquals( 'toto\nexpected: nil, actual: false', lu.assertNil, false, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotNil() + assertFailureEquals( 'expected: not nil, actual: nil', lu.assertNotNil, nil ) + assertFailureEquals( 'toto\nexpected: not nil, actual: nil', lu.assertNotNil, nil, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertStrContains() + assertFailureEquals( 'Could not find substring "xxx" in string "abcdef"', lu.assertStrContains, 'abcdef', 'xxx' ) + assertFailureEquals( 'Could not find substring "aBc" in string "abcdef"', lu.assertStrContains, 'abcdef', 'aBc' ) + assertFailureEquals( 'Could not find substring "xxx" in string ""', lu.assertStrContains, '', 'xxx' ) + + assertFailureEquals( 'Could not find substring "xxx" in string "abcdef"', lu.assertStrContains, 'abcdef', 'xxx', false ) + assertFailureEquals( 'Could not find substring "aBc" in string "abcdef"', lu.assertStrContains, 'abcdef', 'aBc', false ) + assertFailureEquals( 'Could not find substring "xxx" in string ""', lu.assertStrContains, '', 'xxx', false ) + + assertFailureEquals( 'Could not find pattern "xxx" in string "abcdef"', lu.assertStrContains, 'abcdef', 'xxx', true ) + assertFailureEquals( 'Could not find pattern "aBc" in string "abcdef"', lu.assertStrContains, 'abcdef', 'aBc', true ) + assertFailureEquals( 'Could not find pattern "xxx" in string ""', lu.assertStrContains, '', 'xxx', true ) + + assertFailureEquals( 'toto\nCould not find pattern "xxx" in string ""', lu.assertStrContains, '', 'xxx', true, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertStrIContains() + assertFailureEquals( 'Could not find (case insensitively) substring "xxx" in string "abcdef"', lu.assertStrIContains, 'abcdef', 'xxx' ) + assertFailureEquals( 'Could not find (case insensitively) substring "xxx" in string ""', lu.assertStrIContains, '', 'xxx' ) + + assertFailureEquals( 'toto\nCould not find (case insensitively) substring "xxx" in string "abcdef"', lu.assertStrIContains, 'abcdef', 'xxx', 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotStrContains() + assertFailureEquals( 'Found the not expected substring "abc" in string "abcdef"', lu.assertNotStrContains, 'abcdef', 'abc' ) + assertFailureEquals( 'Found the not expected substring "abc" in string "abcdef"', lu.assertNotStrContains, 'abcdef', 'abc', false ) + assertFailureEquals( 'Found the not expected pattern "..." in string "abcdef"', lu.assertNotStrContains, 'abcdef', '...', true) + + assertFailureEquals( 'toto\nFound the not expected substring "abc" in string "abcdef"', lu.assertNotStrContains, 'abcdef', 'abc', false, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotStrIContains() + assertFailureEquals( 'Found (case insensitively) the not expected substring "aBc" in string "abcdef"', lu.assertNotStrIContains, 'abcdef', 'aBc' ) + assertFailureEquals( 'Found (case insensitively) the not expected substring "abc" in string "abcdef"', lu.assertNotStrIContains, 'abcdef', 'abc' ) + assertFailureEquals( 'toto\nFound (case insensitively) the not expected substring "abc" in string "abcdef"', lu.assertNotStrIContains, 'abcdef', 'abc', 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertStrMatches() + assertFailureEquals('Could not match pattern "xxx" with string "abcdef"', lu.assertStrMatches, 'abcdef', 'xxx' ) + assertFailureEquals('toto\nCould not match pattern "xxx" with string "abcdef"', lu.assertStrMatches, 'abcdef', 'xxx', nil, nil, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsNumber() + assertFailureEquals( 'expected: a number value, actual: type string, value "abc"', lu.assertIsNumber, 'abc' ) + assertFailureEquals( 'expected: a number value, actual: nil', lu.assertIsNumber, nil ) + assertFailureEquals( 'toto\nexpected: a number value, actual: type string, value "abc"', lu.assertIsNumber, 'abc', 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsString() + assertFailureEquals( 'expected: a string value, actual: type number, value 1.2', lu.assertIsString, 1.2 ) + assertFailureEquals( 'expected: a string value, actual: nil', lu.assertIsString, nil ) + assertFailureEquals( 'toto\nexpected: a string value, actual: nil', lu.assertIsString, nil, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsTable() + assertFailureEquals( 'expected: a table value, actual: type number, value 1.2', lu.assertIsTable, 1.2 ) + assertFailureEquals( 'expected: a table value, actual: nil', lu.assertIsTable, nil ) + assertFailureEquals( 'toto\nexpected: a table value, actual: nil', lu.assertIsTable, nil, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsBoolean() + assertFailureEquals( 'expected: a boolean value, actual: type number, value 1.2', lu.assertIsBoolean, 1.2 ) + assertFailureEquals( 'expected: a boolean value, actual: nil', lu.assertIsBoolean, nil ) + assertFailureEquals( 'toto\nexpected: a boolean value, actual: nil', lu.assertIsBoolean, nil, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsFunction() + assertFailureEquals( 'expected: a function value, actual: type number, value 1.2', lu.assertIsFunction, 1.2 ) + assertFailureEquals( 'expected: a function value, actual: nil', lu.assertIsFunction, nil ) + assertFailureEquals( 'toto\nexpected: a function value, actual: nil', lu.assertIsFunction, nil, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsThread() + assertFailureEquals( 'expected: a thread value, actual: type number, value 1.2', lu.assertIsThread, 1.2 ) + assertFailureEquals( 'expected: a thread value, actual: nil', lu.assertIsThread, nil ) + assertFailureEquals( 'toto\nexpected: a thread value, actual: nil', lu.assertIsThread, nil, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsUserdata() + assertFailureEquals( 'expected: a userdata value, actual: type number, value 1.2', lu.assertIsUserdata, 1.2 ) + assertFailureEquals( 'expected: a userdata value, actual: nil', lu.assertIsUserdata, nil ) + assertFailureEquals( 'toto\nexpected: a userdata value, actual: nil', lu.assertIsUserdata, nil, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsNan() + assertFailureEquals( 'expected: NaN, actual: 33', lu.assertIsNaN, 33 ) + assertFailureEquals( 'toto\nexpected: NaN, actual: 33', lu.assertIsNaN, 33, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsNan() + assertFailureEquals( 'expected: not NaN, actual: NaN', lu.assertNotIsNaN, 0 / 0 ) + assertFailureEquals( 'toto\nexpected: not NaN, actual: NaN', lu.assertNotIsNaN, 0 / 0, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsInf() + assertFailureEquals( 'expected: #Inf, actual: 33', lu.assertIsInf, 33 ) + assertFailureEquals( 'toto\nexpected: #Inf, actual: 33', lu.assertIsInf, 33, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsPlusInf() + assertFailureEquals( 'expected: #Inf, actual: 33', lu.assertIsPlusInf, 33 ) + assertFailureEquals( 'toto\nexpected: #Inf, actual: 33', lu.assertIsPlusInf, 33, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsMinusInf() + assertFailureEquals( 'expected: -#Inf, actual: 33', lu.assertIsMinusInf, 33 ) + assertFailureEquals( 'toto\nexpected: -#Inf, actual: 33', lu.assertIsMinusInf, 33, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsInf() + assertFailureEquals( 'expected: not infinity, actual: #Inf', lu.assertNotIsInf, 1 / 0 ) + assertFailureEquals( 'toto\nexpected: not infinity, actual: -#Inf', lu.assertNotIsInf, -1 / 0, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsPlusInf() + assertFailureEquals( 'expected: not #Inf, actual: #Inf', lu.assertNotIsPlusInf, 1 / 0 ) + assertFailureEquals( 'toto\nexpected: not #Inf, actual: #Inf', lu.assertNotIsPlusInf, 1 / 0, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsMinusInf() + assertFailureEquals( 'expected: not -#Inf, actual: -#Inf', lu.assertNotIsMinusInf, -1 / 0 ) + assertFailureEquals( 'toto\nexpected: not -#Inf, actual: -#Inf', lu.assertNotIsMinusInf, -1 / 0, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsPlusZero() + assertFailureEquals( 'expected: +0.0, actual: 33', lu.assertIsPlusZero, 33 ) + assertFailureEquals( 'toto\nexpected: +0.0, actual: 33', lu.assertIsPlusZero, 33, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertIsMinusZero() + assertFailureEquals( 'expected: -0.0, actual: 33', lu.assertIsMinusZero, 33 ) + assertFailureEquals( 'toto\nexpected: -0.0, actual: 33', lu.assertIsMinusZero, 33, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsPlusZero() + assertFailureEquals( 'expected: not +0.0, actual: +0.0', lu.assertNotIsPlusZero, 0 ) + assertFailureEquals( 'toto\nexpected: not +0.0, actual: +0.0', lu.assertNotIsPlusZero, 0, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsMinusZero() + local minusZero = -1 / (1/0) + assertFailureEquals( 'expected: not -0.0, actual: -0.0', lu.assertNotIsMinusZero, minusZero ) + assertFailureEquals( 'toto\nexpected: not -0.0, actual: -0.0', lu.assertNotIsMinusZero, minusZero, 'toto' ) + end + + + function TestLuaUnitErrorMsg:test_assertNotIsTrue() + assertFailureEquals('expected: not true, actual: true', lu.assertNotIsTrue, true ) + assertFailureEquals('toto\nexpected: not true, actual: true', lu.assertNotIsTrue, true, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsFalse() + assertFailureEquals('expected: not false, actual: false', lu.assertNotIsFalse, false ) + assertFailureEquals('toto\nexpected: not false, actual: false', lu.assertNotIsFalse, false, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsNil() + assertFailureEquals( + 'expected: not nil, actual: nil', + lu.assertNotIsNil, nil ) + assertFailureEquals( + 'toto\nexpected: not nil, actual: nil', + lu.assertNotIsNil, nil, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsNumber() + assertFailureEquals( 'expected: not a number type, actual: value 123', lu.assertNotIsNumber, 123 ) + assertFailureEquals( 'toto\nexpected: not a number type, actual: value 123', lu.assertNotIsNumber, 123, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsString() + assertFailureEquals( 'expected: not a string type, actual: value "abc"', lu.assertNotIsString, "abc" ) + assertFailureEquals( 'toto\nexpected: not a string type, actual: value "abc"', lu.assertNotIsString, "abc", 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsTable() + assertFailureEquals( 'expected: not a table type, actual: value {1, 2, 3}', lu.assertNotIsTable, {1,2,3} ) + assertFailureEquals( 'toto\nexpected: not a table type, actual: value {1, 2, 3}', lu.assertNotIsTable, {1,2,3}, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsBoolean() + assertFailureEquals( 'expected: not a boolean type, actual: value false', lu.assertNotIsBoolean, false ) + assertFailureEquals( 'toto\nexpected: not a boolean type, actual: value false', lu.assertNotIsBoolean, false, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsFunction() + assertFailureContains( 'expected: not a function type, actual: value function:', lu.assertNotIsFunction, function() return true end ) + assertFailureContains( 'toto\nexpected: not a function type, actual: value function:', lu.assertNotIsFunction, function() return true end, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIsThread() + assertFailureContains( 'expected: not a thread type, actual: value thread:', lu.assertNotIsThread, coroutine.create( function(v) local y=v+1 end ) ) + assertFailureContains( 'toto\nexpected: not a thread type, actual: value thread:', lu.assertNotIsThread, coroutine.create( function(v) local y=v+1 end ), 'toto' ) + end + + --[[ How do you create UserData ? + function TestLuaUnitErrorMsg:test_assertIsNotUserdata() + assertFailureEquals( 'Not expected: a userdata type, actual: value XXX ???', lu.assertIsNotUserdata, XXX ??? ) + end + ]] + + function TestLuaUnitErrorMsg:test_assertIs() + assertFailureEquals( 'expected and actual object should not be different\nExpected: 1\nReceived: 2', lu.assertIs, 2, 1 ) + assertFailureEquals( 'expected and actual object should not be different\n'.. + 'Expected: {1, 2, 3, 4, 5, 6, 7, 8}\n'.. + 'Received: {1, 2, 3, 4, 5, 6, 7, 8}', + lu.assertIs, {1,2,3,4,5,6,7,8}, {1,2,3,4,5,6,7,8} ) + lu.ORDER_ACTUAL_EXPECTED = false + assertFailureEquals( 'expected and actual object should not be different\nExpected: 2\nReceived: 1', lu.assertIs, 2, 1 ) + assertFailureEquals( 'toto\nexpected and actual object should not be different\nExpected: 2\nReceived: 1', lu.assertIs, 2, 1, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertNotIs() + local v = {1,2} + assertFailureMatches( 'expected and actual object should be different: {1, 2}', lu.assertNotIs, v, v ) + lu.ORDER_ACTUAL_EXPECTED = false -- order shouldn't matter here, but let's cover it + assertFailureMatches( 'expected and actual object should be different: {1, 2}', lu.assertNotIs, v, v ) + assertFailureMatches( 'toto\nexpected and actual object should be different: {1, 2}', lu.assertNotIs, v, v, 'toto' ) + end + + function TestLuaUnitErrorMsg:test_assertItemsEquals() + assertFailureMatches('Content of the tables are not identical:\nExpected: {one=2, two=3}\nActual: {1, 2}' , lu.assertItemsEquals, {1,2}, {one=2, two=3} ) + assertFailureContains('Content of the tables are not identical' , lu.assertItemsEquals, {}, {1} ) -- actual table empty, = doesn't contain expected value + assertFailureContains('Content of the tables are not identical' , lu.assertItemsEquals, nil, 'foobar' ) -- type mismatch + assertFailureContains('Content of the tables are not identical' , lu.assertItemsEquals, 'foo', 'bar' ) -- value mismatch + assertFailureContains('toto\nContent of the tables are not identical' , lu.assertItemsEquals, 'foo', 'bar', 'toto' ) -- value mismatch + end + + function TestLuaUnitErrorMsg:test_assertError() + assertFailureEquals('Expected an error when calling function but no error generated' , lu.assertError, function( v ) local y = v+1 end, 3 ) + end + + function TestLuaUnitErrorMsg:test_assertErrorMsgEquals() + assertFailureEquals('No error generated when calling function but expected error: "bla bla bla"' , + lu.assertErrorMsgEquals, 'bla bla bla', function( v ) local y = v+1 end, 3 ) + assertFailureEquals('Error message expected: "bla bla bla"\n' .. + 'Error message received: "toto xxx"\n' , + lu.assertErrorMsgEquals, 'bla bla bla', function( v ) error('toto xxx',2) end, 3 ) + assertFailureEquals('Error message expected: {1, 2, 3, 4}\nError message received: {1, 2, 3}\n' , + lu.assertErrorMsgEquals, {1,2,3,4}, function( v ) error(v) end, {1,2,3}) + assertFailureEquals('Error message expected: {details="bla bla bla"}\nError message received: {details="ble ble ble"}\n' , + lu.assertErrorMsgEquals, {details="bla bla bla"}, function( v ) error(v) end, {details="ble ble ble"}) + end + + function TestLuaUnitErrorMsg:test_assertErrorMsgContains() + assertFailureEquals('No error generated when calling function but expected error containing: "bla bla bla"' , + lu.assertErrorMsgContains, 'bla bla bla', function( v ) local y = v+1 end, 3 ) + assertFailureEquals('Error message does not contain: "bla bla bla"\nError message received: "toto xxx"\n' , + lu.assertErrorMsgContains, 'bla bla bla', function( v ) error('toto xxx',2) end, 3 ) + end + + function TestLuaUnitErrorMsg:test_assertErrorMsgMatches() + assertFailureEquals('No error generated when calling function but expected error matching: "bla bla bla"' , + lu.assertErrorMsgMatches, 'bla bla bla', function( v ) local y = v+1 end, 3 ) + + assertFailureEquals('Error message does not match pattern: "bla bla bla"\n' .. + 'Error message received: "toto xxx"\n' , + lu.assertErrorMsgMatches, 'bla bla bla', function( v ) error('toto xxx',2) end, 3 ) + end + + function TestLuaUnitErrorMsg:test_printTableWithRef() + lu.PRINT_TABLE_REF_IN_ERROR_MSG = true + assertFailureMatches( 'Received the not expected value: {1, 2}', lu.assertNotEquals, {1,2}, {1,2} ) + -- trigger multiline prettystr + assertFailureMatches( 'Received the not expected value: {1, 2, 3, 4}', lu.assertNotEquals, {1,2,3,4}, {1,2,3,4} ) + assertFailureMatches( 'expected: false, actual: {}', lu.assertFalse, {}) + local v = {1,2} + assertFailureMatches( 'expected and actual object should be different: {1, 2}', lu.assertNotIs, v, v ) + assertFailureMatches('Content of the tables are not identical:\nExpected: {one=2, two=3}\nActual: {1, 2}' , lu.assertItemsEquals, {1,2}, {one=2, two=3} ) + assertFailureMatches( 'expected: {1, 2}\nactual: {2, 1}', lu.assertEquals, {2,1}, {1,2} ) + -- trigger multiline prettystr + assertFailureMatches( 'expected: {one=1, two=2}\nactual: {3, 2, 1}', lu.assertEquals, {3,2,1}, {one=1,two=2} ) + -- trigger mismatch formatting + lu.assertErrorMsgContains( [[lists 5 then + error( 'Exceeding 5') + end + end + + _G.MyTestWithIteration = MyTestWithIteration + nbIter = 0 + runner:runSuite( '--repeat', '10', + 'MyTestWithIteration') + _G.MyTestWithIteration = nil -- clean up + -- check if the current iteration got reflected in the failure message + lu.assertEquals( runner.result.passedCount, 0 ) + lu.assertEquals( runner.result.failureCount, 0 ) + lu.assertEquals( runner.result.errorCount, 1 ) + lu.assertEquals( runner.exeRepeat, 10 ) + lu.assertEquals( runner.currentCount, 6 ) + -- print( lu.prettystr( runner.result ) ) + lu.assertStrContains(runner.result.errors[1].msg, "iteration 6") + lu.assertStrContains(runner.result.errors[1].msg, "Exceeding 5" ) + end + + + function TestLuaUnitExecution:testOutputInterface() + local runner = lu.LuaUnit.new() + runner.outputType = Mock + runner:runSuite( 'MyTestWithErrorsAndFailures', 'MyTestOk' ) + local m = runner.output + + lu.assertEquals( m.calls[1][1], 'startSuite' ) + lu.assertEquals(#m.calls[1], 2 ) + + lu.assertEquals( m.calls[2][1], 'startClass' ) + lu.assertEquals( m.calls[2][3], 'MyTestWithErrorsAndFailures' ) + lu.assertEquals(#m.calls[2], 3 ) + + lu.assertEquals( m.calls[3][1], 'startTest' ) + lu.assertEquals( m.calls[3][3], 'MyTestWithErrorsAndFailures.testOk' ) + lu.assertEquals(#m.calls[3], 3 ) + + lu.assertEquals( m.calls[4][1], 'endTest' ) + lu.assertEquals(#m.calls[4], 3 ) + lu.assertIsTable( m.calls[4][3] ) + lu.assertEquals( m.calls[4][3].status, lu.NodeStatus.PASS ) + + lu.assertEquals( m.calls[5][1], 'startTest' ) + lu.assertEquals( m.calls[5][3], 'MyTestWithErrorsAndFailures.testWithError1' ) + lu.assertEquals(#m.calls[5], 3 ) + + lu.assertEquals( m.calls[6][1], 'addStatus' ) + lu.assertEquals(#m.calls[6], 3 ) + + lu.assertEquals( m.calls[7][1], 'endTest' ) + lu.assertEquals(#m.calls[7], 3 ) + lu.assertIsTable( m.calls[7][3] ) + lu.assertEquals( m.calls[7][3].status, lu.NodeStatus.ERROR ) + + + lu.assertEquals( m.calls[8][1], 'startTest' ) + lu.assertEquals( m.calls[8][3], 'MyTestWithErrorsAndFailures.testWithFailure1' ) + lu.assertEquals(#m.calls[8], 3 ) + + lu.assertEquals( m.calls[9][1], 'addStatus' ) + lu.assertEquals(#m.calls[9], 3 ) + + lu.assertEquals( m.calls[10][1], 'endTest' ) + lu.assertEquals(#m.calls[10], 3 ) + lu.assertIsTable( m.calls[10][3] ) + lu.assertEquals( m.calls[10][3].status, lu.NodeStatus.FAIL ) + + lu.assertEquals( m.calls[11][1], 'startTest' ) + lu.assertEquals( m.calls[11][3], 'MyTestWithErrorsAndFailures.testWithFailure2' ) + lu.assertEquals(#m.calls[11], 3 ) + + lu.assertEquals( m.calls[12][1], 'addStatus' ) + lu.assertEquals(#m.calls[12], 3 ) + + lu.assertEquals( m.calls[13][1], 'endTest' ) + lu.assertEquals(#m.calls[13], 3 ) + lu.assertIsTable(m.calls[13][3] ) + lu.assertEquals( m.calls[13][3].status, lu.NodeStatus.FAIL ) + + lu.assertEquals( m.calls[14][1], 'endClass' ) + lu.assertEquals(#m.calls[14], 2 ) + + lu.assertEquals( m.calls[15][1], 'startClass' ) + lu.assertEquals( m.calls[15][3], 'MyTestOk' ) + lu.assertEquals(#m.calls[15], 3 ) + + lu.assertEquals( m.calls[16][1], 'startTest' ) + lu.assertEquals( m.calls[16][3], 'MyTestOk.testOk1' ) + lu.assertEquals(#m.calls[16], 3 ) + + lu.assertEquals( m.calls[17][1], 'endTest' ) + lu.assertEquals(#m.calls[17], 3 ) + lu.assertIsTable( m.calls[17][3] ) + lu.assertEquals( m.calls[17][3].status, lu.NodeStatus.PASS ) + + lu.assertEquals( m.calls[18][1], 'startTest' ) + lu.assertEquals( m.calls[18][3], 'MyTestOk.testOk2' ) + lu.assertEquals(#m.calls[18], 3 ) + + lu.assertEquals( m.calls[19][1], 'endTest' ) + lu.assertEquals(#m.calls[19], 3 ) + lu.assertIsTable( m.calls[19][3] ) + lu.assertEquals( m.calls[19][3].status, lu.NodeStatus.PASS ) + + lu.assertEquals( m.calls[20][1], 'endClass' ) + lu.assertEquals(#m.calls[20], 2 ) + + lu.assertEquals( m.calls[21][1], 'endSuite' ) + lu.assertEquals(#m.calls[21], 2 ) + + lu.assertEquals( m.calls[22], nil ) + + end + + function TestLuaUnitExecution:testInvocation() + + local runner = lu.LuaUnit.new() + + -- test alternative "object" syntax for run(), passing self + runner:run('--output', 'nil', 'MyTestOk') + -- select class instance by name + runner.run('--output', 'nil', 'MyTestOk.testOk2') + + -- check error handling + lu.assertErrorMsgContains('No such name in global space', + runner.runSuite, runner, 'foobar') + lu.assertErrorMsgContains('Name must match a function or a table', + runner.runSuite, runner, '_VERSION') + lu.assertErrorMsgContains('No such name in global space', + runner.runSuite, runner, 'foo.bar') + lu.assertErrorMsgContains('must be a function, not', + runner.runSuite, runner, '_G._VERSION') + lu.assertErrorMsgContains('Could not find method in class', + runner.runSuite, runner, 'MyTestOk.foobar') + lu.assertErrorMsgContains('Instance must be a table or a function', + runner.expandClasses, {{'foobar', 'INVALID'}}) + lu.assertErrorMsgContains('Could not find method in class', + runner.expandClasses, {{'MyTestOk.foobar', {}}}) + end + + function TestLuaUnitExecution:test_filterWithPattern() + + local runner = lu.LuaUnit.new() + runner:setOutputType( "NIL" ) + runner:runSuite('-p', 'Function', '-p', 'Toto.' ) + lu.assertEquals( executedTests[1], "MyTestFunction" ) + lu.assertEquals( executedTests[2], "MyTestToto1:test1" ) + lu.assertEquals( executedTests[3], "MyTestToto1:test2" ) + lu.assertEquals( executedTests[4], "MyTestToto1:test3" ) + lu.assertEquals( executedTests[5], "MyTestToto1:testa" ) + lu.assertEquals( executedTests[6], "MyTestToto1:testb" ) + lu.assertEquals( executedTests[7], "MyTestToto2:test1" ) + lu.assertEquals( #executedTests, 7) + + runner:runSuite('-p', 'Toto.', '-x', 'Toto2' ) + lu.assertEquals( runner.result.testCount, 5) -- MyTestToto2 excluded + end + + function TestLuaUnitExecution:test_endSuiteTwice() + local runner = lu.LuaUnit.new() + runner:setOutputType( "NIL" ) + runner:runSuite( 'MyTestWithErrorsAndFailures', 'MyTestOk' ) + lu.assertErrorMsgContains('suite was already ended', + runner.endSuite, runner) + end + + + +------------------------------------------------------------------ +-- +-- Results Tests +-- +------------------------------------------------------------------ + +TestLuaUnitResults = { __class__ = 'TestLuaUnitResults' } + + function TestLuaUnitResults:tearDown() + executedTests = {} + lu.LuaUnit.isTestName = lu.LuaUnit.isTestNameOld + end + + function TestLuaUnitResults:setUp() + executedTests = {} + lu.LuaUnit.isTestNameOld = lu.LuaUnit.isTestName + lu.LuaUnit.isTestName = function( s ) return (string.sub(s,1,6) == 'MyTest') end + end + + function TestLuaUnitResults:test_statusLine() + -- full success + local r = {runCount=5, duration=0.17, passedCount=5, notPassedCount=0, failureCount=0, errorCount=0, nonSelectedCount=0} + lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 5 successes, 0 failures') + + -- 1 failure, nothing more displayed + r = {runCount=5, duration=0.17, passedCount=4, notPassedCount=1, failureCount=1, errorCount=0, nonSelectedCount=0} + lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 4 successes, 1 failure') + + -- 1 error, no failure displayed + r = {runCount=5, duration=0.17, passedCount=4, notPassedCount=1, failureCount=0, errorCount=1, nonSelectedCount=0} + lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 4 successes, 1 error') + + -- 1 error, 1 failure + r = {runCount=5, duration=0.17, passedCount=3, notPassedCount=2, failureCount=1, errorCount=1, nonSelectedCount=0} + lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 3 successes, 1 failure, 1 error') + + -- 1 error, 1 failure, 1 non selected + r = {runCount=5, duration=0.17, passedCount=3, notPassedCount=2, failureCount=1, errorCount=1, nonSelectedCount=1} + lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 3 successes, 1 failure, 1 error, 1 non-selected') + + -- full success, 1 non selected + r = {runCount=5, duration=0.17, passedCount=5, notPassedCount=0, failureCount=0, errorCount=0, nonSelectedCount=1} + lu.assertEquals( lu.LuaUnit.statusLine(r), 'Ran 5 tests in 0.170 seconds, 5 successes, 0 failures, 1 non-selected') + end + + function TestLuaUnitResults:test_nodeStatus() + local es = lu.NodeStatus.new() + lu.assertEquals( es.status, lu.NodeStatus.PASS ) + lu.assertTrue( es:isPassed() ) + lu.assertNil( es.msg ) + lu.assertNil( es.stackTrace ) + lu.assertStrContains( es:statusXML(), "" -# Starting test: TestFailuresWithXml.test_failure_with_simple_xml -# Failure: test/test_with_xml.lua:9: expected: "got it" -actual: 'ti"ti' -# Starting test: TestThatLastsALongTime -# Ran 3 tests in 1.101 seconds, 1 success, 2 failures diff -Nru lua-unit-3.2/test/testWithXmlDefault.xml lua-unit-3.3/test/testWithXmlDefault.xml --- lua-unit-3.2/test/testWithXmlDefault.xml 2016-10-11 09:40:09.000000000 +0000 +++ lua-unit-3.3/test/testWithXmlDefault.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/test_with_xml.lua lua-unit-3.3/test/test_with_xml.lua --- lua-unit-3.2/test/test_with_xml.lua 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/test/test_with_xml.lua 2018-04-20 12:34:12.000000000 +0000 @@ -1,23 +1,23 @@ - -local lu = require('luaunit') - -TestFailuresWithXml = {} --class - - TestFailuresWithXml.__class__ = 'TestFailuresWithXml' - - function TestFailuresWithXml:test_failure_with_simple_xml() - lu.assertEquals( 'ti"ti', 'got it' ) - end - - function TestFailuresWithXml:test_failure_with_cdata_xml() - lu.assertEquals( 'cdata does not like ]]>', 'got it' ) - end - -function TestThatLastsALongTime() - local start = os.clock() - while os.clock() - start < 1.1 do - end -end - -lu.LuaUnit.verbosity = 2 -os.exit( lu.LuaUnit.run() ) + +local lu = require('luaunit') + +TestFailuresWithXml = {} --class + + TestFailuresWithXml.__class__ = 'TestFailuresWithXml' + + function TestFailuresWithXml:test_failure_with_simple_xml() + lu.assertEquals( 'ti"ti', 'got it' ) + end + + function TestFailuresWithXml:test_failure_with_cdata_xml() + lu.assertEquals( 'cdata does not like ]]>', 'got it' ) + end + +function TestThatLastsALongTime() + local start = os.clock() + while os.clock() - start < 1.1 do + end +end + +lu.LuaUnit.verbosity = 2 +os.exit( lu.LuaUnit.run() ) diff -Nru lua-unit-3.2/test/testWithXmlQuiet.txt lua-unit-3.3/test/testWithXmlQuiet.txt --- lua-unit-3.2/test/testWithXmlQuiet.txt 2016-10-11 09:40:10.000000000 +0000 +++ lua-unit-3.3/test/testWithXmlQuiet.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,11 +0,0 @@ -# XML output to test/ref/testWithXmlQuiet.xml -# Started on 01/01/16 22:13:04 -# Starting class: TestFailuresWithXml -# Starting test: TestFailuresWithXml.test_failure_with_cdata_xml -# Failure: test/test_with_xml.lua:13: expected: "got it" -actual: "cdata does not like ]]>" -# Starting test: TestFailuresWithXml.test_failure_with_simple_xml -# Failure: test/test_with_xml.lua:9: expected: "got it" -actual: 'ti"ti' -# Starting test: TestThatLastsALongTime -# Ran 3 tests in 1.102 seconds, 1 success, 2 failures diff -Nru lua-unit-3.2/test/testWithXmlQuiet.xml lua-unit-3.3/test/testWithXmlQuiet.xml --- lua-unit-3.2/test/testWithXmlQuiet.xml 2016-10-11 09:40:10.000000000 +0000 +++ lua-unit-3.3/test/testWithXmlQuiet.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/test/testWithXmlVerbose.txt lua-unit-3.3/test/testWithXmlVerbose.txt --- lua-unit-3.2/test/testWithXmlVerbose.txt 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/testWithXmlVerbose.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,11 +0,0 @@ -# XML output to test/ref/testWithXmlVerbose.xml -# Started on 01/01/16 22:13:03 -# Starting class: TestFailuresWithXml -# Starting test: TestFailuresWithXml.test_failure_with_cdata_xml -# Failure: test/test_with_xml.lua:13: expected: "got it" -actual: "cdata does not like ]]>" -# Starting test: TestFailuresWithXml.test_failure_with_simple_xml -# Failure: test/test_with_xml.lua:9: expected: "got it" -actual: 'ti"ti' -# Starting test: TestThatLastsALongTime -# Ran 3 tests in 1.102 seconds, 1 success, 2 failures diff -Nru lua-unit-3.2/test/testWithXmlVerbose.xml lua-unit-3.3/test/testWithXmlVerbose.xml --- lua-unit-3.2/test/testWithXmlVerbose.xml 2016-10-11 09:40:12.000000000 +0000 +++ lua-unit-3.3/test/testWithXmlVerbose.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff -Nru lua-unit-3.2/TODO.txt lua-unit-3.3/TODO.txt --- lua-unit-3.2/TODO.txt 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/TODO.txt 2018-04-20 12:34:12.000000000 +0000 @@ -1,102 +1,173 @@ - -TODO Future: -============ -- add the ability to count the number of assertions that should have been executed in the test -- mention that general error are correctly handled by luaunit as failures -- detect if a functions creates new global variables. -- validate output with ignored tests (0 failures or some failures) -- report test duration everywhere -- allow to skip tests -- randomized testing -- parametrize tests -- coloured output -- global setup / teardown -- class setup / teardown -- add date and duration to tap output -- better error messages for table assertions: - + expected length of X, got Y - + keys differing in table 1 and 2 -- XML: report system information -- better error messages for string differences - -Nice to have: -============ -- stack unwrapping like in py.test - -TODO for 3.2 release: -==================== -- document new config: table with key of type table -- document --error - -Done since 3.1: -=============== -x provide a luarock package. See: https://rocks.moonscript.org/modules/rjpcomputing/luaunit -x make a difference between errors and failures -x lua 5.3 -x travis lua 5.3 -x compatibility with LuaUnit v2.0 of rjbcomputing -x provide a legacy wrapFunction() - -Done since 3.0: -=============== -x check documentation link glitch to TAP -x doc: report how to handle global space pollution/restriction -x doc: adapt all examples to new way of requireing luaunit -x less global space pollution -x doc: move description of table printing to an annex -x validate well-formed XML with a DTD -x validate test output (TAP, ...) with functional tests -x test failures, verify that output is correct -x improve testresult: contain the list of tests, with status of each test -x strip luaunit stack more intelligently: exclude content of luaunit -x mention mailing-list in README.md -x mention version in documentation -x mention mailing-list -x mention the new global variable config for displaying table content -x fix display of tables with recursive references -x improve display of nested tables in error messages -x improve display of multiline strings in error messages - -x Junit XML Ouptut: - x test and fix xml escaping - x validate xml with apache and jenkins schemas - + xml format: - - add proper xml formatting header - - report number of failures within element - - report duration - - add properties describe the environment - -Done: -============ -x add other types of output -x assert with matching of the error message -x finish user documentation -x switch version 3.0 -x add assertMatch for strings -x document --name -x improve junit xml output (one file, choice of filename) -x display number of non selected tests -x assertIs with all types -x mention one file distribution -x improve TAP output: pre-calculate test numbers, display test summary as comment -x test error messages of assertStrMatches and all error functions -x assertNil + assertNotNil -x readthedocs integration -x add travis-ci badges to README -x filter by pattern -x support --version -x support --help -x replace methodInstance with real test name in reports -x better error messages for wrong command line option, or wrong output type -x control verbosity and output type with command line -x display time to run all tests -x move all assertions together -x better error display of assertIsXXX functions -x add assertContains for strings -x add assertIsNumber, assertIsXXX -x table assertions -x sequence asserts -x compatibilty tests with several version of lua -x add assertNotEquals - - +TODO Future: +============ +- pretty function formatting: https://github.com/luarocks/luarocks/blob/master/src/luarocks/core/util.lua +- platform detection: +- document prettystr +- add the ability to count the number of assertions that should have been executed in the test +- validate output with ignored tests (0 failures or some failures) +- parametrize tests +- coloured output +- better error messages for string differences (diffing) +- print local variables upon assertion error: + + debug.get_local( ) will get the local variables in the current context + + debug.get_upvalue( ) will get the upvalues in the current context +- see inspect for better table printing: https://github.com/kikito/inspect.lua + + print list part separate from the dict part in a table + + print metatables in tables +- see StackTracePlus for printing more stack information: https://github.com/ignacio/StackTracePlus +- how does busted deal with nested tables ? functions ? +- look at serpent to see how to improve nested table printing +- function should be printed as +- print table of test test_filterWithPattern and see how to improve readability +- shuffle should shuffle separately classes and then class methods +- add assertTableContains and assertTableNotContains to check the presence / absence of value in an array +- look at serpent to see how to improve nested table printing +- doc about usage of prettystr & assertion library +- assertListContainsElements +- assertListContainsElements +- checkXXX for every assertXXX + +Version 3.4: +============ +- global setup / teardown +- class setup / teardown +- report test duration everywhere +- allow to skip tests +- add date and duration to tap output +- XML: report system information +- align the "OK" vertically for text output +- better detection of screen size +- catch the os.exit call with a handler or something, to avoid aborting the tests +- move all file:line description to stack trace +- better deal with one line formatting + + +Done since 3.2: +=============== +- make sure that example source code is included in documentation when packaging +- add annex to documentation with full source code of example +- add annex with BSD license +- verify that assertError functions all work with tables, review implementation in detail +- useRe -> usePattern +- add success() to terminate test successfully +- doc: explain that prettystr() is used in assertions +- check rock installation of luaunit +- add custom message support +- build luarocks +- update contributors +- update download badge +- doc about prettystr +- add fail() to force test failure +- use caching on travis-ci +- assertAlmostEqual no longer includes a default margin, margin must always be explicitly specified. +- verify that lu.EPS by calculation +- fix include/exclude bug (see https://github.com/bluebird75/luaunit/pull/82 ) +- doc about scientific computing dedicated functions +- assertions for nan and inf and +/- zero +- fixes for junit and tap output +- doc improvements +- better error messages for list assertions: + + expected length of X, got Y + + index differing in table 1 and 2 +- more doc about assertTrue/False/... with a table +- randomized testing +- can run a tests numerous times (useful for triggering the JIT effect) +- can include and exclude tests from the test list + +Done since 3.1: +=============== +x provide a luarock package. See: https://rocks.moonscript.org/modules/rjpcomputing/luaunit +x make a difference between errors and failures +x lua 5.3 +x travis lua 5.3 +x compatibility with LuaUnit v2.0 of rjbcomputing +x provide a legacy wrapFunction() + +Done since 3.0: +=============== +x check documentation link glitch to TAP +x doc: report how to handle global space pollution/restriction +x doc: adapt all examples to new way of requireing luaunit +x less global space pollution +x doc: move description of table printing to an annex +x validate well-formed XML with a DTD +x validate test output (TAP, ...) with functional tests +x test failures, verify that output is correct +x improve testresult: contain the list of tests, with status of each test +x strip luaunit stack more intelligently: exclude content of luaunit +x mention mailing-list in README.md +x mention version in documentation +x mention mailing-list +x mention the new global variable config for displaying table content +x fix display of tables with recursive references +x improve display of nested tables in error messages +x improve display of multiline strings in error messages + +x Junit XML Ouptut: + x test and fix xml escaping + x validate xml with apache and jenkins schemas + + xml format: + - add proper xml formatting header + - report number of failures within element + - report duration + - add properties describe the environment + +Done: +============ +x add other types of output +x assert with matching of the error message +x finish user documentation +x switch version 3.0 +x add assertMatch for strings +x document --name +x improve junit xml output (one file, choice of filename) +x display number of non selected tests +x assertIs with all types +x mention one file distribution +x improve TAP output: pre-calculate test numbers, display test summary as comment +x test error messages of assertStrMatches and all error functions +x assertNil + assertNotNil +x readthedocs integration +x add travis-ci badges to README +x filter by pattern +x support --version +x support --help +x replace methodInstance with real test name in reports +x better error messages for wrong command line option, or wrong output type +x control verbosity and output type with command line +x display time to run all tests +x move all assertions together +x better error display of assertIsXXX functions +x add assertContains for strings +x add assertIsNumber, assertIsXXX +x table assertions +x sequence asserts +x compatibilty tests with several version of lua +x add assertNotEquals + +Release TODO: +============= +- all tests green in Travis and AppVeyor +- doc is green in read-the-docs +- documentation is updated with release content +- doit.py runtests success +- tag set on the code +- upload release to GitHub +- prepare luarocks and upload to luarocks +- verify smooth installation of luarocks +- annonce release on lua mailing-list + + + + + + + + + + + + + + + diff -Nru lua-unit-3.2/.travis/platform.sh lua-unit-3.3/.travis/platform.sh --- lua-unit-3.2/.travis/platform.sh 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/.travis/platform.sh 2018-04-20 12:34:12.000000000 +0000 @@ -1,15 +1,15 @@ -if [ -z "${PLATFORM:-}" ]; then - PLATFORM=$TRAVIS_OS_NAME; -fi - -if [ "$PLATFORM" == "osx" ]; then - PLATFORM="macosx"; -fi - -if [ -z "$PLATFORM" ]; then - if [ "$(uname)" == "Linux" ]; then - PLATFORM="linux"; - else - PLATFORM="macosx"; - fi; -fi +if [ -z "${PLATFORM:-}" ]; then + PLATFORM=$TRAVIS_OS_NAME; +fi + +if [ "$PLATFORM" == "osx" ]; then + PLATFORM="macosx"; +fi + +if [ -z "$PLATFORM" ]; then + if [ "$(uname)" == "Linux" ]; then + PLATFORM="linux"; + else + PLATFORM="macosx"; + fi; +fi diff -Nru lua-unit-3.2/.travis/setenv_lua.sh lua-unit-3.3/.travis/setenv_lua.sh --- lua-unit-3.2/.travis/setenv_lua.sh 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/.travis/setenv_lua.sh 2018-04-20 12:34:12.000000000 +0000 @@ -1,3 +1,3 @@ -export PATH=${PATH}:$HOME/.lua:$HOME/.local/bin:${TRAVIS_BUILD_DIR}/install/luarocks/bin -bash .travis/setup_lua.sh -eval `$HOME/.lua/luarocks path` +export PATH=${PATH}:$HOME/.lua:$HOME/.local/bin:${TRAVIS_BUILD_DIR}/install/luarocks/bin +bash .travis/setup_lua.sh +eval `$HOME/.lua/luarocks path` diff -Nru lua-unit-3.2/.travis/setup_lua.sh lua-unit-3.3/.travis/setup_lua.sh --- lua-unit-3.2/.travis/setup_lua.sh 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/.travis/setup_lua.sh 2018-04-20 12:34:12.000000000 +0000 @@ -1,122 +1,187 @@ -#! /bin/bash - -# A script for setting up environment for travis-ci testing. -# Sets up Lua and Luarocks. -# LUA must be "lua5.1", "lua5.2" or "luajit". -# luajit2.0 - master v2.0 -# luajit2.1 - master v2.1 - -set -eufo pipefail - -LUAJIT_VERSION="2.0.4" -LUAJIT_BASE="LuaJIT-$LUAJIT_VERSION" - -source .travis/platform.sh - -LUA_HOME_DIR=$TRAVIS_BUILD_DIR/install/lua - -LR_HOME_DIR=$TRAVIS_BUILD_DIR/install/luarocks - -mkdir $HOME/.lua - -LUAJIT="no" - -if [ "$PLATFORM" == "macosx" ]; then - if [ "$LUA" == "luajit" ]; then - LUAJIT="yes"; - fi - if [ "$LUA" == "luajit2.0" ]; then - LUAJIT="yes"; - fi - if [ "$LUA" == "luajit2.1" ]; then - LUAJIT="yes"; - fi; -elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then - LUAJIT="yes"; -fi - -mkdir -p "$LUA_HOME_DIR" - -if [ "$LUAJIT" == "yes" ]; then - - if [ "$LUA" == "luajit" ]; then - curl --location https://github.com/LuaJIT/LuaJIT/archive/v$LUAJIT_VERSION.tar.gz | tar xz; - else - git clone https://github.com/LuaJIT/LuaJIT.git $LUAJIT_BASE; - fi - - cd $LUAJIT_BASE - - if [ "$LUA" == "luajit2.1" ]; then - git checkout v2.1; - # force the INSTALL_TNAME to be luajit - perl -i -pe 's/INSTALL_TNAME=.+/INSTALL_TNAME= luajit/' Makefile - fi - - make && make install PREFIX="$LUA_HOME_DIR" - - ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/luajit - ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/lua; - -else - - if [ "$LUA" == "lua5.1" ]; then - curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz - cd lua-5.1.5; - elif [ "$LUA" == "lua5.2" ]; then - curl http://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xz - cd lua-5.2.4; - elif [ "$LUA" == "lua5.3" ]; then - curl http://www.lua.org/ftp/lua-5.3.2.tar.gz | tar xz - cd lua-5.3.2; - fi - - # Build Lua without backwards compatibility for testing - perl -i -pe 's/-DLUA_COMPAT_(ALL|5_2)//' src/Makefile - make $PLATFORM - make INSTALL_TOP="$LUA_HOME_DIR" install; - - ln -s $LUA_HOME_DIR/bin/lua $HOME/.lua/lua - ln -s $LUA_HOME_DIR/bin/luac $HOME/.lua/luac; - -fi - -cd $TRAVIS_BUILD_DIR - -lua -v - -LUAROCKS_BASE=luarocks-$LUAROCKS - -curl --location http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz - -cd $LUAROCKS_BASE - -if [ "$LUA" == "luajit" ]; then - ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR"; -elif [ "$LUA" == "luajit2.0" ]; then - ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR"; -elif [ "$LUA" == "luajit2.1" ]; then - ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.1" --prefix="$LR_HOME_DIR"; -else - ./configure --with-lua="$LUA_HOME_DIR" --prefix="$LR_HOME_DIR" -fi - -make build && make install - -ln -s $LR_HOME_DIR/bin/luarocks $HOME/.lua/luarocks - -cd $TRAVIS_BUILD_DIR - -luarocks --version - -rm -rf $LUAROCKS_BASE - -if [ "$LUAJIT" == "yes" ]; then - rm -rf $LUAJIT_BASE; -elif [ "$LUA" == "lua5.1" ]; then - rm -rf lua-5.1.5; -elif [ "$LUA" == "lua5.2" ]; then - rm -rf lua-5.2.4; -elif [ "$LUA" == "lua5.3" ]; then - rm -rf lua-5.3.2; -fi +#! /bin/bash + +# A script for setting up environment for travis-ci testing. +# Sets up Lua and Luarocks. +# LUA must be "lua5.1", "lua5.2" or "luajit". +# luajit2.0 - master v2.0 +# luajit2.1 - master v2.1 + +set -eufo pipefail + +LUAJIT_VERSION="2.0.4" +LUAJIT_BASE="LuaJIT-$LUAJIT_VERSION" + +source .travis/platform.sh + +LUA_HOME_DIR=$TRAVIS_BUILD_DIR/install/$LUA +LR_HOME_DIR=$TRAVIS_BUILD_DIR/install/luarocks + +mkdir $HOME/.lua + +LUAJIT="no" + +if [ "$PLATFORM" == "macosx" ]; then + if [ "$LUA" == "luajit" ]; then + LUAJIT="yes"; + fi + if [ "$LUA" == "luajit2.0" ]; then + LUAJIT="yes"; + fi + if [ "$LUA" == "luajit2.1" ]; then + LUAJIT="yes"; + fi; +elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then + LUAJIT="yes"; +fi + +if [ -e $LUA_HOME_DIR ] +then + echo ">> Using cached version of $LUA_HOME_DIR and luarocks" + echo "Content:" + find $LUA_HOME_DIR -print + find $LR_HOME_DIR -print + + # remove links to other version of lua and luarocks + rm -f $HOME/.lua/lua + rm -f $HOME/.lua/luajit + rm -f $HOME/.lua/luac + rm -f $HOME/.lua/luarocks + + # recreating the links + if [ "$LUAJIT" == "yes" ]; then + ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/luajit + ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/lua + else + ln -s $LUA_HOME_DIR/bin/lua $HOME/.lua/lua + ln -s $LUA_HOME_DIR/bin/luac $HOME/.lua/luac + fi + ln -s $LR_HOME_DIR/bin/luarocks $HOME/.lua/luarocks + + # installation is ok ? + lua -v + luarocks --version + luarocks list + +else # -e $LUA_HOME_DIR + + echo ">> Compiling lua into $LUA_HOME_DIR" + + mkdir -p "$LUA_HOME_DIR" + + if [ "$LUAJIT" == "yes" ]; then + + echo ">> Downloading LuaJIT" + if [ "$LUA" == "luajit" ]; then + curl --location https://github.com/LuaJIT/LuaJIT/archive/v$LUAJIT_VERSION.tar.gz | tar xz; + else + git clone https://github.com/LuaJIT/LuaJIT.git $LUAJIT_BASE; + fi + + cd $LUAJIT_BASE + + if [ "$LUA" == "luajit2.1" ]; then + git checkout v2.1; + # force the INSTALL_TNAME to be luajit + perl -i -pe 's/INSTALL_TNAME=.+/INSTALL_TNAME= luajit/' Makefile + fi + + echo ">> Compiling LuaJIT" + make && make install PREFIX="$LUA_HOME_DIR" + + else # $LUAJIT == "yes" + + echo "Downloading $LUA" + if [ "$LUA" == "lua5.1" ]; then + curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz + cd lua-5.1.5; + elif [ "$LUA" == "lua5.2" ]; then + curl http://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xz + cd lua-5.2.4; + elif [ "$LUA" == "lua5.3" ]; then + curl http://www.lua.org/ftp/lua-5.3.3.tar.gz | tar xz + cd lua-5.3.3; + fi + + # adjust numerical precision if requested with LUANUMBER=float + if [ "$LUANUMBER" == "float" ]; then + if [ "$LUA" == "lua5.3" ]; then + # for Lua 5.3 we can simply adjust the default float type + perl -i -pe "s/#define LUA_FLOAT_TYPE\tLUA_FLOAT_DOUBLE/#define LUA_FLOAT_TYPE\tLUA_FLOAT_FLOAT/" src/luaconf.h + else + # modify the basic LUA_NUMBER type + perl -i -pe 's/#define LUA_NUMBER_DOUBLE/#define LUA_NUMBER_FLOAT/' src/luaconf.h + perl -i -pe "s/LUA_NUMBER\tdouble/LUA_NUMBER\tfloat/" src/luaconf.h + #perl -i -pe "s/LUAI_UACNUMBER\tdouble/LUAI_UACNUMBER\tfloat/" src/luaconf.h + # adjust LUA_NUMBER_SCAN (input format) + perl -i -pe 's/"%lf"/"%f"/' src/luaconf.h + # adjust LUA_NUMBER_FMT (output format) + perl -i -pe 's/"%\.14g"/"%\.7g"/' src/luaconf.h + # adjust lua_str2number conversion + perl -i -pe 's/strtod\(/strtof\(/' src/luaconf.h + # this one is specific to the l_mathop(x) macro of Lua 5.2 + perl -i -pe 's/\t\t\(x\)/\t\t\(x##f\)/' src/luaconf.h + fi + fi + + # Build Lua without backwards compatibility for testing + perl -i -pe 's/-DLUA_COMPAT_(ALL|5_2)//' src/Makefile + + echo ">> Compiling $LUA" + make $PLATFORM + make INSTALL_TOP="$LUA_HOME_DIR" install; + + fi # $LUAJIT == "yes" + + # cleanup LUA build dir + if [ "$LUAJIT" == "yes" ]; then + rm -rf $LUAJIT_BASE; + elif [ "$LUA" == "lua5.1" ]; then + rm -rf lua-5.1.5; + elif [ "$LUA" == "lua5.2" ]; then + rm -rf lua-5.2.4; + elif [ "$LUA" == "lua5.3" ]; then + rm -rf lua-5.3.2; + fi + + if [ "$LUAJIT" == "yes" ]; then + ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/luajit + ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/lua + else + ln -s $LUA_HOME_DIR/bin/lua $HOME/.lua/lua + ln -s $LUA_HOME_DIR/bin/luac $HOME/.lua/luac + fi + + # lua is OK ? + lua -v + + echo ">> Downloading luarocks" + LUAROCKS_BASE=luarocks-$LUAROCKS + curl --location http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz + + cd $LUAROCKS_BASE + + echo ">> Compiling luarocks" + if [ "$LUA" == "luajit" ]; then + ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR"; + elif [ "$LUA" == "luajit2.0" ]; then + ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR"; + elif [ "$LUA" == "luajit2.1" ]; then + ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.1" --prefix="$LR_HOME_DIR"; + else + ./configure --with-lua="$LUA_HOME_DIR" --prefix="$LR_HOME_DIR" + fi + + make build && make install + + # cleanup luarocks + rm -rf $LUAROCKS_BASE + + ln -s $LR_HOME_DIR/bin/luarocks $HOME/.lua/luarocks + luarocks --version + luarocks install luacheck + luarocks install luacov-coveralls + +fi # -e $LUA_HOME_DIR + +cd $TRAVIS_BUILD_DIR + diff -Nru lua-unit-3.2/.travis.yml lua-unit-3.3/.travis.yml --- lua-unit-3.2/.travis.yml 2016-10-11 09:39:54.000000000 +0000 +++ lua-unit-3.3/.travis.yml 2018-04-20 12:34:12.000000000 +0000 @@ -1,34 +1,49 @@ -language: c - -sudo: false - -env: - global: - - LUAROCKS=2.2.2 - matrix: - - LUA=lua5.1 - - LUA=lua5.2 - - LUA=lua5.3 - - LUA=luajit # latest stable version (2.0.x) - - LUA=luajit2.0 # current head of 2.0 branch - - LUA=luajit2.1 # current head of 2.1 branch - -# 'bleeding edge' LuaJIT may fail without breaking the build -matrix: - allow_failures: - - env: LUA=luajit2.0 - - env: LUA=luajit2.1 - -before_install: - - source .travis/setenv_lua.sh - - luarocks install luacheck - -script: - - lua -v run_unit_tests.lua - - lua run_functional_tests.lua - - luacheck *.lua test/ - -notifications: - email: - on_success: change - on_failure: always +language: c +sudo: false + +os: linux + +env: + global: + - LUAROCKS=2.2.2 + matrix: + - LUA=lua5.1 LUANUMBER=double + - LUA=lua5.1 LUANUMBER=float + - LUA=lua5.2 LUANUMBER=double + - LUA=lua5.2 LUANUMBER=float + - LUA=lua5.3 LUANUMBER=double + - LUA=lua5.3 LUANUMBER=float + - LUA=luajit # latest stable version (2.0.x) + - LUA=luajit2.0 # current head of 2.0 branch + - LUA=luajit2.1 # current head of 2.1 branch + +matrix: + # test Mac OS X, but limit it to a single build + include: + - os: osx + env: LUA=lua5.1 LUANUMBER=double + # 'bleeding edge' LuaJIT may fail without breaking the build + allow_failures: + - env: LUA=luajit2.0 + - env: LUA=luajit2.1 + +before_install: + - source .travis/setenv_lua.sh + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y libxml2-utils; fi + +cache: + directories: + - $TRAVIS_BUILD_DIR/install + +script: + - lua -v -lluacov run_unit_tests.lua --shuffle + - lua run_functional_tests.lua --coverage + - luacheck *.lua test/ + +after_success: + - luacov-coveralls -v --include %./luaunit.lua + +notifications: + email: + on_success: change + on_failure: always