Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJason Perkins <starkos@industriousone.com>2013-01-11 17:53:59 +0400
committerJason Perkins <starkos@industriousone.com>2013-01-11 17:53:59 +0400
commitbc38d316887263a1a53783efb73968e69acadfcd (patch)
treec13ae97c6e007c9ddf49915d35326390024332a0 /tests
parente9599feea3b3b42d92797ac789c43dadcee81f29 (diff)
Bug 268: Target extension not set properly for Visual Studio 2010
Diffstat (limited to 'tests')
-rw-r--r--tests/actions/vstudio/test_vs2010_flags.lua57
-rw-r--r--tests/actions/vstudio/test_vs2010_project_kinds.lua45
-rw-r--r--tests/actions/vstudio/test_vs2010_vcxproj.lua60
-rw-r--r--tests/actions/vstudio/vc2010/test_output_props.lua179
-rw-r--r--tests/premake4.lua17
-rwxr-xr-xtests/test2
-rw-r--r--tests/testfx.lua126
7 files changed, 291 insertions, 195 deletions
diff --git a/tests/actions/vstudio/test_vs2010_flags.lua b/tests/actions/vstudio/test_vs2010_flags.lua
index c09776c..973ab71 100644
--- a/tests/actions/vstudio/test_vs2010_flags.lua
+++ b/tests/actions/vstudio/test_vs2010_flags.lua
@@ -9,12 +9,12 @@ function vs10_flags.setup()
sln = solution "MySolution"
configurations { "Debug" }
platforms {}
-
+
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
- uuid "AE61726D-187C-E440-BD07-2556188A6565"
- includedirs{"foo/bar"}
+ uuid "AE61726D-187C-E440-BD07-2556188A6565"
+ includedirs{"foo/bar"}
end
function vs10_flags.teardown()
@@ -35,14 +35,14 @@ end
function vs10_flags.sseSet()
flags {"EnableSSE"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet>')
end
function vs10_flags.sse2Set()
flags {"EnableSSE2"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>')
end
@@ -54,63 +54,63 @@ end
function vs10_flags.extraWarning_warningLevelIsFour()
flags {"ExtraWarnings"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<WarningLevel>Level4</WarningLevel>')
end
function vs10_flags.extraWarning_treatWarningsAsError_setToTrue()
flags {"FatalWarnings"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<TreatWarningAsError>true</TreatWarningAsError>')
end
function vs10_flags.floatFast_floatingPointModel_setToFast()
flags {"FloatFast"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<FloatingPointModel>Fast</FloatingPointModel>')
end
function vs10_flags.floatStrict_floatingPointModel_setToStrict()
flags {"FloatStrict"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<FloatingPointModel>Strict</FloatingPointModel>')
end
function vs10_flags.nativeWideChar_TreatWChar_tAsBuiltInType_setToTrue()
flags {"NativeWChar"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>')
end
function vs10_flags.nativeWideChar_TreatWChar_tAsBuiltInType_setToFalse()
flags {"NoNativeWChar"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>')
end
function vs10_flags.noExceptions_exceptionHandling_setToFalse()
flags {"NoExceptions"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<ExceptionHandling>false</ExceptionHandling>')
end
function vs10_flags.structuredExceptions_exceptionHandling_setToAsync()
flags {"SEH"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<ExceptionHandling>Async</ExceptionHandling>')
end
function vs10_flags.noFramePointer_omitFramePointers_setToTrue()
flags {"NoFramePointer"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<OmitFramePointers>true</OmitFramePointers>')
end
@@ -118,27 +118,27 @@ end
function vs10_flags.noRTTI_runtimeTypeInfo_setToFalse()
flags {"NoRTTI"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<RuntimeTypeInfo>false</RuntimeTypeInfo>')
end
function vs10_flags.optimizeSize_optimization_setToMinSpace()
flags {"OptimizeSize"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<Optimization>MinSpace</Optimization>')
end
function vs10_flags.optimizeSpeed_optimization_setToMaxSpeed()
flags {"OptimizeSpeed"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<Optimization>MaxSpeed</Optimization>')
end
function vs10_flags.optimizeSpeed_optimization_setToMaxSpeed()
flags {"Optimize"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<Optimization>Full</Optimization>')
end
@@ -177,7 +177,7 @@ end
function vs10_flags.unicode_characterSet_setToUnicode()
flags {"Unicode"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<CharacterSet>Unicode</CharacterSet>')
end
@@ -186,28 +186,28 @@ end
function vs10_flags.debugAndNoMinimalRebuildAndSymbols_minimalRebuild_setToFalse()
flags {debug_string,"NoMinimalRebuild"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<MinimalRebuild>false</MinimalRebuild>')
end
function vs10_flags.debugYetNotMinimalRebuild_minimalRebuild_setToTrue()
flags {debug_string}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<MinimalRebuild>true</MinimalRebuild>')
end
function vs10_flags.release_minimalRebuild_setToFalse()
flags {release_string}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<MinimalRebuild>false</MinimalRebuild>')
end
function vs10_flags.mfc_useOfMfc_setToStatic()
flags{"MFC"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<UseOfMfc>Dynamic</UseOfMfc>')
end
@@ -232,14 +232,14 @@ end
function vs10_flags.symbolsAndNoEditAndContinue_DebugInformationFormat_setToProgramDatabase()
flags{"Symbols","NoEditAndContinue"}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>')
end
function vs10_flags.symbolsAndRelease_DebugInformationFormat_setToProgramDatabase()
flags{"Symbols",release_string}
-
+
local buffer = get_buffer()
test.string_contains(buffer,'<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>')
end
@@ -255,13 +255,6 @@ function vs10_flags.noSymbols_DebugInformationFormat_blockIsEmpty()
test.string_contains(buffer,'<DebugInformationFormat></DebugInformationFormat>')
end
-function vs10_flags.noManifest_GenerateManifest_setToFalse()
- flags{"NoManifest"}
-
- local buffer = get_buffer()
- test.string_contains(buffer,'<GenerateManifest Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'Debug|Win32\'">false</GenerateManifest>')
-end
-
function vs10_flags.noSymbols_bufferDoesNotContainprogramDataBaseFile()
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<Link>.*<ProgramDataBaseFileName>.*</Link>')
diff --git a/tests/actions/vstudio/test_vs2010_project_kinds.lua b/tests/actions/vstudio/test_vs2010_project_kinds.lua
index 1de75a4..d32146a 100644
--- a/tests/actions/vstudio/test_vs2010_project_kinds.lua
+++ b/tests/actions/vstudio/test_vs2010_project_kinds.lua
@@ -65,51 +65,6 @@
test.string_contains(buffer,'<Link>.*<ImportLibrary>.*</ImportLibrary>.*</Link>')
end
- function vs10_project_kinds.sharedLib_bufferContainsImportLibrary()
- kind "SharedLib"
- local buffer = get_buffer()
- test.string_contains(buffer,'<Link>.*<ImportLibrary>MyProject.lib</ImportLibrary>.*</Link>')
- end
-
- function vs10_project_kinds.sharedLib_withNoImportLibraryFlag_linkSectionContainsImportLibrary()
- kind "SharedLib"
- flags{"NoImportLib"}
- local buffer = get_buffer()
- test.string_contains(buffer,'<Link>.*<ImportLibrary>.*</ImportLibrary>.*</Link>')
- end
-
- function vs10_project_kinds.sharedLib_withOutNoImportLibraryFlag_propertyGroupSectionContainsIgnoreImportLibrary()
- kind "SharedLib"
- local buffer = get_buffer()
- test.string_contains(buffer,'<PropertyGroup>.*<IgnoreImportLibrary.*</IgnoreImportLibrary>.*</PropertyGroup>')
- end
-
- function vs10_project_kinds.sharedLib_withNoImportLibraryFlag_propertyGroupSectionContainsIgnoreImportLibrary()
- kind "SharedLib"
- flags{"NoImportLib"}
- local buffer = get_buffer()
- test.string_contains(buffer,'<PropertyGroup>.*<IgnoreImportLibrary.*</IgnoreImportLibrary>.*</PropertyGroup>')
- end
-
- function vs10_project_kinds.sharedLib_withOutNoImportLibraryFlag_ignoreImportLibraryValueIsFalse()
- kind "SharedLib"
- local buffer = get_buffer()
- test.string_contains(buffer,'<PropertyGroup>.*<IgnoreImportLibrary.*false</IgnoreImportLibrary>.*</PropertyGroup>')
- end
-
- function vs10_project_kinds.sharedLib_withNoImportLibraryFlag_ignoreImportLibraryValueIsTrue()
- kind "SharedLib"
- flags{"NoImportLib"}
- local buffer = get_buffer()
- test.string_contains(buffer,'<PropertyGroup>.*<IgnoreImportLibrary.*true</IgnoreImportLibrary>.*</PropertyGroup>')
- end
-
- function vs10_project_kinds.staticLib_doesNotContainLinkIncremental()
- kind "StaticLib"
- local buffer = get_buffer()
- test.string_does_not_contain(buffer,'<LinkIncremental.*</LinkIncremental>')
- end
-
function vs10_project_kinds.sharedLib_withoutOptimisation_linkIncrementalValueIsTrue()
kind "SharedLib"
local buffer = get_buffer()
diff --git a/tests/actions/vstudio/test_vs2010_vcxproj.lua b/tests/actions/vstudio/test_vs2010_vcxproj.lua
index a7a3942..c5b3401 100644
--- a/tests/actions/vstudio/test_vs2010_vcxproj.lua
+++ b/tests/actions/vstudio/test_vs2010_vcxproj.lua
@@ -117,20 +117,6 @@
test.string_contains(buffer,'<PropertyGroup Label="UserMacros" />')
end
- function vs10_vcxproj.intermediateAndOutDirsPropertyGroupWithMagicNumber()
- local buffer = get_buffer()
- test.string_contains(buffer,'<PropertyGroup>.*<_ProjectFileVersion>10%.0%.30319%.1</_ProjectFileVersion>')
- end
-
- function vs10_vcxproj.outDirPresent()
- local buffer = get_buffer()
- test.string_contains(buffer,'<OutDir.*</OutDir>')
- end
- function vs10_vcxproj.initDirPresent()
- local buffer = get_buffer()
- test.string_contains(buffer,'<IntDir.*</IntDir>')
- end
-
function vs10_vcxproj.projectWithDebugAndReleaseConfig_twoOutDirsAndTwoIntDirs()
local buffer = get_buffer()
test.string_contains(buffer,'<OutDir.*</OutDir>.*<IntDir.*</IntDir>.*<OutDir.*</OutDir>.*<IntDir.*</IntDir>')
@@ -233,52 +219,6 @@
test.string_contains(buffer,'<PostBuildEvent>.*<Command>&quot;doSomeThing&quot;</Command>.*</PostBuildEvent>')
end
- function vs10_vcxproj.outDir_directorySuppliedIsNotSlashPostFixed_bufferContainsOutDirSlashPostFixed()
- targetdir("dir")
- local buffer = get_buffer()
- test.string_contains(buffer,'<OutDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\.*\'">dir\\</OutDir>')
- end
- --postfixed directory slashes are removed by default
- --yet these following two tests are to ensure if this behaviour is changed they will fail
- function vs10_vcxproj.outDir_directorySuppliedWhichIsForwardSlashPostFixed_bufferContainsOutDirSlashPostFixed()
- targetdir("dir/")
- local buffer = get_buffer()
- test.string_contains(buffer,'<OutDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\.*\'">dir\\</OutDir>')
- end
-
- function vs10_vcxproj.outDir_directorySuppliedWhichIsWindowsSlashPostFixed_bufferContainsOutDirSlashPostFixed()
- targetdir("dir\\")
- local buffer = get_buffer()
- test.string_contains(buffer,'<OutDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\.*\'">dir\\</OutDir>')
- end
-
- function vs10_vcxproj.objectDir_directorySuppliedIsNotSlashPostFixed_bufferContainsIntermediateDirSlashPostFixed()
- objdir ("dir")
-
- local buffer = get_buffer()
- test.string_contains(buffer,'<IntDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'.*\'">dir\\</IntDir>')
- end
-
- --postfixed directory slashes are removed by default
- --yet these following two tests are to ensure if this behaviour is changed they will fail
- function vs10_vcxproj.objectDir_directorySuppliedWhichIsSlashPostFixed_bufferContainsIntermediateDirSlashPostFixed()
- objdir ("dir/")
- local buffer = get_buffer()
- test.string_contains(buffer,'<IntDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'.*\'">dir\\</IntDir>')
- end
-
- function vs10_vcxproj.objectDir_directorySuppliedWhichIsWindowsSlashPostFixed_bufferContainsIntermediateDirSlashPostFixed()
- objdir ("dir\\")
- local buffer = get_buffer()
- test.string_contains(buffer,'<IntDir Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'.*\'">dir\\</IntDir>')
- end
- function vs10_vcxproj.targetName()
- configuration("Debug")
- targetname ("foo_d")
- local buffer = get_buffer()
- test.string_contains(buffer,'<TargetName Condition="\'%$%(Configuration%)|%$%(Platform%)\'==\'Debug|Win32\'">foo_d</TargetName>')
- end
-
function vs10_vcxproj.noExtraWarnings_bufferDoesNotContainSmallerTypeCheck()
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<SmallerTypeCheck>')
diff --git a/tests/actions/vstudio/vc2010/test_output_props.lua b/tests/actions/vstudio/vc2010/test_output_props.lua
new file mode 100644
index 0000000..30c6375
--- /dev/null
+++ b/tests/actions/vstudio/vc2010/test_output_props.lua
@@ -0,0 +1,179 @@
+--
+-- tests/actions/vstudio/vc2010/test_output_props.lua
+-- Validate generation of the output property groups.
+-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
+--
+
+ T.vstudio_vs2010_output_props = {}
+ local suite = T.vstudio_vs2010_output_props
+ local vc2010 = premake.vstudio.vc2010
+
+
+--
+-- Setup
+--
+
+ local sln
+
+ function suite.setup()
+ _ACTION = "vs2010"
+ sln = test.createsolution()
+ end
+
+ local function prepare()
+ premake.bake.buildconfigs()
+ sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
+ local prj = premake.solution.getproject(sln, 1)
+ vc2010.outputProperties(prj)
+ end
+
+
+--
+-- Check the structure with the default project values.
+--
+
+ function suite.structureIsCorrect_onDefaultValues()
+ prepare()
+ test.capture [[
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <OutDir>.\</OutDir>
+ <IntDir>obj\Debug\</IntDir>
+ <TargetName>MyProject</TargetName>
+ <TargetExt>.exe</TargetExt>
+ <LinkIncremental>true</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ ]]
+ end
+
+
+--
+-- Static libraries should omit the link incremental element entirely.
+--
+
+ function suite.omitLinkIncremental_onStaticLib()
+ kind "StaticLib"
+ prepare()
+ test.capture [[
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <OutDir>.\</OutDir>
+ <IntDir>obj\Debug\</IntDir>
+ <TargetName>MyProject</TargetName>
+ <TargetExt>.lib</TargetExt>
+ </PropertyGroup>
+ ]]
+ end
+
+--
+-- Optimized builds should not link incrementally.
+--
+
+ function suite.noIncrementalLink_onOptimizedBuild()
+ flags "Optimize"
+ prepare()
+ test.capture [[
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <OutDir>.\</OutDir>
+ <IntDir>obj\Debug\</IntDir>
+ <TargetName>MyProject</TargetName>
+ <TargetExt>.exe</TargetExt>
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ ]]
+ end
+
+--
+-- The target directory is applied, if specified.
+--
+
+ function suite.outDir_onTargetDir()
+ targetdir "../bin"
+ prepare()
+ test.capture [[
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <OutDir>..\bin\</OutDir>
+ ]]
+ end
+
+--
+-- The objeccts directory is applied, if specified.
+--
+
+ function suite.intDir_onTargetDir()
+ objdir "../tmp"
+ prepare()
+ test.capture [[
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <OutDir>.\</OutDir>
+ <IntDir>..\tmp\Debug\</IntDir>
+ ]]
+ end
+
+--
+-- The target name is applied, if specified.
+--
+
+ function suite.targetName_onTargetName()
+ targetname "MyTarget"
+ prepare()
+ test.capture [[
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <OutDir>.\</OutDir>
+ <IntDir>obj\Debug\</IntDir>
+ <TargetName>MyTarget</TargetName>
+ ]]
+ end
+
+--
+-- A target extension should be used if specified.
+--
+
+ function suite.targetExt_onTargetExtension()
+ targetextension ".delta"
+ prepare()
+ test.capture [[
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <OutDir>.\</OutDir>
+ <IntDir>obj\Debug\</IntDir>
+ <TargetName>MyProject</TargetName>
+ <TargetExt>.delta</TargetExt>
+ ]]
+ end
+
+--
+-- If the NoImportLib flag is set, add the IgnoreImportLibrary element.
+--
+
+ function suite.ignoreImportLib_onNoImportLib()
+ kind "SharedLib"
+ flags "NoImportLib"
+ prepare()
+ test.capture [[
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <OutDir>.\</OutDir>
+ <IntDir>obj\Debug\</IntDir>
+ <TargetName>MyProject</TargetName>
+ <TargetExt>.dll</TargetExt>
+ <IgnoreImportLibrary>true</IgnoreImportLibrary>
+ ]]
+ end
+
+
+--
+-- If the NoManifest flag is set, add the GenerateManifest element.
+--
+
+ function suite.generateManifest_onNoManifest()
+ flags "NoManifest"
+ prepare()
+ test.capture [[
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <OutDir>.\</OutDir>
+ <IntDir>obj\Debug\</IntDir>
+ <TargetName>MyProject</TargetName>
+ <TargetExt>.exe</TargetExt>
+ <LinkIncremental>true</LinkIncremental>
+ <GenerateManifest>false</GenerateManifest>
+ </PropertyGroup>
+ ]]
+ end
diff --git a/tests/premake4.lua b/tests/premake4.lua
index a2d0d5f..2f64d7f 100644
--- a/tests/premake4.lua
+++ b/tests/premake4.lua
@@ -110,6 +110,7 @@
dofile("actions/vstudio/vc2010/test_link_settings.lua")
dofile("actions/vstudio/vc2010/test_links.lua")
dofile("actions/vstudio/vc2010/test_mfc.lua")
+ dofile("actions/vstudio/vc2010/test_output_props.lua")
dofile("actions/vstudio/vc2010/test_pch.lua")
dofile("actions/vstudio/vc2010/test_project_refs.lua")
@@ -142,15 +143,27 @@
-- Register a test action
--
+ newoption {
+ trigger = "test",
+ description = "A suite or test to run"
+ }
+
newaction {
trigger = "test",
description = "Run the automated test suite",
execute = function ()
- passed, failed = test.runall()
+ if _OPTIONS["test"] then
+ local t = string.explode(_OPTIONS["test"] or "", ".", true)
+ passed, failed = test.runall(t[1], t[2])
+ else
+ passed, failed = test.runall()
+ end
+
msg = string.format("%d tests passed, %d failed", passed, failed)
if (failed > 0) then
- error(msg, 0)
+ -- should probably return an error code here somehow
+ print(msg)
else
print(msg)
end
diff --git a/tests/test b/tests/test
index e138ca1..4b3918d 100755
--- a/tests/test
+++ b/tests/test
@@ -1,2 +1,2 @@
#!/bin/sh
-cd `dirname $0` && ../bin/debug/premake4 /scripts=../src test
+cd `dirname $0` && ../bin/debug/premake4 /scripts=../src $1 $2 $3 test
diff --git a/tests/testfx.lua b/tests/testfx.lua
index a33a391..8342086 100644
--- a/tests/testfx.lua
+++ b/tests/testfx.lua
@@ -20,19 +20,19 @@
test.fail("\n==Fail==: Expected to find :\n%s\nyet it was not found in buffer:\n%s\n", expected,buffer)
end
end
-
+
function test.string_does_not_contain(buffer, expected)
if string.find(buffer,expected) then
test.fail("\n==Fail==: Did not expected to find :\n%s\nyet it was found in buffer:\n%s\n", expected,buffer)
end
end
-
+
function test.capture(expected)
local actual = io.endcapture()
-
+
local ait = actual:gfind("(.-)" .. io.eol)
local eit = expected:gfind("(.-)\n")
-
+
local linenum = 1
local atxt = ait()
local etxt = eit()
@@ -40,14 +40,14 @@
if (etxt ~= atxt) then
test.fail("(%d) expected:\n%s\n...but was:\n%s", linenum, etxt, atxt)
end
-
+
linenum = linenum + 1
atxt = ait()
etxt = eit()
end
end
-
+
function test.closedfile(expected)
if expected and not test.value_closedfile then
test.fail("expected file to be closed")
@@ -55,19 +55,19 @@
test.fail("expected file to remain open")
end
end
-
+
function test.contains(value, expected)
if not table.contains(value, expected) then
test.fail("expected value %s not found", expected)
end
end
-
-
+
+
function test.fail(format, ...)
-- convert nils into something more usefuls
for i = 1, arg.n do
- if (arg[i] == nil) then
+ if (arg[i] == nil) then
arg[i] = "(nil)"
elseif (type(arg[i]) == "table") then
arg[i] = "{" .. table.concat(arg[i], ", ") .. "}"
@@ -75,8 +75,8 @@
end
error(string.format(format, unpack(arg)), 3)
end
-
-
+
+
function test.filecontains(expected, fn)
local f = io.open(fn)
local actual = f:read("*a")
@@ -85,7 +85,7 @@
test.fail("expected %s but was %s", expected, actual)
end
end
-
+
function test.isemptycapture()
local actual = io.endcapture()
@@ -94,7 +94,7 @@
end
end
-
+
function test.isequal(expected, actual)
if (type(expected) == "table") then
for k,v in pairs(expected) do
@@ -109,36 +109,36 @@
end
return true
end
-
-
+
+
function test.isfalse(value)
if (value) then
test.fail("expected false but was true")
end
end
-
+
function test.isnil(value)
if (value ~= nil) then
test.fail("expected nil but was " .. tostring(value))
end
end
-
-
+
+
function test.isnotnil(value)
if (value == nil) then
test.fail("expected not nil")
end
end
-
-
+
+
function test.istrue(value)
if (not value) then
test.fail("expected true but was false")
end
end
-
+
function test.openedfile(fname)
if fname ~= test.value_openedfilename then
local msg = "expected to open file '" .. fname .. "'"
@@ -148,8 +148,8 @@
test.fail(msg)
end
end
-
-
+
+
function test.success(fn, ...)
local ok, err = pcall(fn, unpack(arg))
if not ok then
@@ -172,14 +172,14 @@
end
}
end
-
+
local function stub_io_output(f)
end
-
+
local function stub_print(s)
end
-
-
+
+
--
-- Define a collection for the test suites
--
@@ -213,13 +213,13 @@
return true
end
end
-
+
local function test_run(suite, fn)
io.capture()
return pcall(fn)
end
-
+
local function test_teardown(suite, fn)
if suite.teardown then
@@ -230,42 +230,58 @@
end
- function test.runall()
+ function test.runall(suitename, testname)
test.print = print
print = stub_print
io.open = stub_io_open
io.output = stub_io_output
-
+
local numpassed = 0
local numfailed = 0
local start_time = os.clock()
- for suitename, suitetests in pairs(T) do
- for testname, testfunc in pairs(suitetests) do
-
- if suitetests.setup ~= testfunc and suitetests.teardown ~= testfunc then
- local ok, err = test_setup(suitetests, testfunc)
-
- if ok then
- ok, err = test_run(suitetests, testfunc)
- end
-
- local tok, terr = test_teardown(suitetests, testfunc)
- ok = ok and tok
- err = err or tok
-
- if (not ok) then
- test.print(string.format("%s.%s: %s", suitename, testname, err))
- numfailed = numfailed + 1
- else
- numpassed = numpassed + 1
- end
+
+ function runtest(suitename, suitetests, testname, testfunc)
+ if suitetests.setup ~= testfunc and suitetests.teardown ~= testfunc then
+ local ok, err = test_setup(suitetests, testfunc)
+
+ if ok then
+ ok, err = test_run(suitetests, testfunc)
+ end
+
+ local tok, terr = test_teardown(suitetests, testfunc)
+ ok = ok and tok
+ err = err or terr
+
+ if (not ok) then
+ test.print(string.format("%s.%s: %s", suitename, testname, err))
+ numfailed = numfailed + 1
+ else
+ numpassed = numpassed + 1
+ end
+ end
+ end
+
+ function runsuite(suitename, suitetests, testname)
+ if testname then
+ runtest(suitename, suitetests, testname, suitetests[testname])
+ else
+ for testname, testfunc in pairs(suitetests) do
+ runtest(suitename, suitetests, testname, testfunc)
end
-
end
end
+
+ if suitename then
+ runsuite(suitename, T[suitename], testname)
+ else
+ for suitename, suitetests in pairs(T) do
+ runsuite(suitename, suitetests, testname)
+ end
+ end
+
io.write('running time : ', os.clock() - start_time,'\n')
print = test.print
- return numpassed, numfailed
+ return numpassed, numfailed
end
-
+