From 52515963b485625e4d770212828c76e99bb9653b Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Wed, 17 Sep 2014 19:19:47 -0400 Subject: [PATCH 1/2] Make test framework module aware - Move test action into main project script - Look for and load test suites from manifest files - Make individual tests play nicer with third-party modifications --- premake5.lua | 44 ++++- scripts/test.lua | 53 ++++++ src/host/lua_auxlib.c | 2 + tests/_manifest.lua | 161 ++++++++++++++++++ tests/actions/make/cpp/test_wiidev.lua | 3 +- .../vstudio/vc200x/test_excluded_configs.lua | 24 --- .../vstudio/vc200x/test_external_compiler.lua | 83 --------- .../vstudio/vc200x/test_external_linker.lua | 126 -------------- .../vstudio/vc2010/test_excluded_configs.lua | 29 ---- tests/actions/vstudio/vc2010/test_link.lua | 17 -- tests/api/test_directory_kind.lua | 4 +- tests/base/test_include.lua | 14 +- tests/base/test_os.lua | 11 ++ tests/config/test_targetinfo.lua | 24 --- tests/folder/{premake4.lua => premake5.lua} | 0 tests/test_dofile.lua | 29 ++-- tests/testfx.lua | 51 +++++- tests/tools/test_gcc.lua | 66 +++---- 18 files changed, 369 insertions(+), 372 deletions(-) create mode 100644 scripts/test.lua create mode 100644 tests/_manifest.lua delete mode 100644 tests/actions/vstudio/vc200x/test_external_compiler.lua delete mode 100644 tests/actions/vstudio/vc200x/test_external_linker.lua rename tests/folder/{premake4.lua => premake5.lua} (100%) diff --git a/premake5.lua b/premake5.lua index 13fcb698..b269391c 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,19 +1,56 @@ +--- +-- Premake 5.x core configuration script -- --- Premake 5.x build configuration script --- Use this script to configure the project with Premake5. +-- You can generate from here if you only want to build Premake's core +-- component, but you probably want to be one level up in order to get +-- the extra modules too. -- +-- If you've been working from premake-dev, you will need to pull a new +-- working copy using premake-main to get the extras. +--- + +-- +-- Remember my location; I will need it to locate sub-scripts later. +-- + + local corePath = _SCRIPT_DIR + -- -- Disable deprecation warnings for myself, so that older development --- versions will still be able to regenerate the scripts. +-- versions of Premake can be used to bootstrap new builds. -- premake.api.deprecations "off" + + +-- +-- Register supporting actions and options. +-- + + newaction { + trigger = "test", + description = "Run the automated test suite", + execute = function () + include (path.join(corePath, "scripts/test.lua")) + end + } + + + newoption { + trigger = "test", + description = "When testing, run only the specified suite or test" + } + + + -- -- Define the project. Put the release configuration first so it will be the -- default when folks build using the makefile. That way they don't have to -- worry about the /scripts argument and all that. +-- +-- TODO: defaultConfiguration "Release" -- solution "Premake5" @@ -88,6 +125,7 @@ links { "m" } + -- -- A more thorough cleanup. -- diff --git a/scripts/test.lua b/scripts/test.lua new file mode 100644 index 00000000..25e11bf6 --- /dev/null +++ b/scripts/test.lua @@ -0,0 +1,53 @@ +--- +-- Premake automated test runner. +--- + + include "../tests/testfx.lua" + + + local focus = {} + if _OPTIONS["test"] then + focus = string.explode(_OPTIONS["test"] or "", ".", true) + end + + +-- +-- Find and load all of the test file manifests +-- + + local mask = path.join(_MAIN_SCRIPT_DIR, "**/tests/_manifest.lua") + local manifests = os.matchfiles(mask) + + -- Hmm, "**" should probably also match against "."? + local top = path.join(_MAIN_SCRIPT_DIR, "tests/_manifest.lua") + if os.isfile(top) then + table.insert(manifests, 1, top) + end + + for i = 1, #manifests do + local manifest = manifests[i] + _TESTS_DIR = path.getdirectory(manifest) + local files = dofile(manifest) + for f = 1, #files do + dofile(path.join(_TESTS_DIR, files[f])) + end + end + + +-- +-- Run them and show the results +-- + + local startTime = os.clock() + + passed, failed = test.runall(focus[1], focus[2]) + + io.write('running time : ', os.clock() - startTime,'\n') + + msg = string.format("%d tests passed, %d failed", passed, failed) + if (failed > 0) then + print(msg) + os.exit(5) + else + print(msg) + end diff --git a/src/host/lua_auxlib.c b/src/host/lua_auxlib.c index 6e9910dd..7a5b2109 100644 --- a/src/host/lua_auxlib.c +++ b/src/host/lua_auxlib.c @@ -49,6 +49,8 @@ static int chunk_wrapper(lua_State* L) ptr = strrchr(script, '/'); if (ptr) *ptr = '\0'; + lua_pushstring(L, script); + lua_setglobal(L, "_SCRIPT_DIR"); do_chdir(script); if (ptr) *ptr = '/'; diff --git a/tests/_manifest.lua b/tests/_manifest.lua new file mode 100644 index 00000000..e7054ca6 --- /dev/null +++ b/tests/_manifest.lua @@ -0,0 +1,161 @@ +return { + -- Base API tests + "test_dofile.lua", + "test_string.lua", + "base/test_configset.lua", + "base/test_context.lua", + "base/test_criteria.lua", + "base/test_detoken.lua", + "base/test_include.lua", + "base/test_option.lua", + "base/test_os.lua", + "base/test_override.lua", + "base/test_path.lua", + "base/test_premake_command.lua", + "base/test_table.lua", + "base/test_tree.lua", + "base/test_uuid.lua", + + -- Solution object tests + "solution/test_eachconfig.lua", + "solution/test_location.lua", + "solution/test_objdirs.lua", + + -- Project object tests + "project/test_config_maps.lua", + "project/test_eachconfig.lua", + "project/test_getconfig.lua", + "project/test_location.lua", + "project/test_vpaths.lua", + + -- Configuration object tests + "config/test_linkinfo.lua", + "config/test_links.lua", + "config/test_targetinfo.lua", + + -- Baking tests + "oven/test_filtering.lua", + "oven/test_objdirs.lua", + + -- API tests + "api/test_containers.lua", + "api/test_directory_kind.lua", + "api/test_list_kind.lua", + "api/test_path_kind.lua", + "api/test_register.lua", + "api/test_string_kind.lua", + "api/test_table_kind.lua", + + -- Control system tests + "test_premake.lua", + "base/test_validation.lua", + + -- -- Toolset tests + "tools/test_dotnet.lua", + "tools/test_gcc.lua", + "tools/test_msc.lua", + + -- Visual Studio 2005-2010 C# projects + "actions/vstudio/cs2005/test_assembly_refs.lua", + "actions/vstudio/cs2005/test_build_events.lua", + "actions/vstudio/cs2005/test_compiler_props.lua", + "actions/vstudio/cs2005/test_debug_props.lua", + "actions/vstudio/cs2005/test_files.lua", + "actions/vstudio/cs2005/test_icon.lua", + "actions/vstudio/cs2005/test_output_props.lua", + "actions/vstudio/cs2005/projectelement.lua", + "actions/vstudio/cs2005/test_platform_groups.lua", + "actions/vstudio/cs2005/test_project_refs.lua", + "actions/vstudio/cs2005/projectsettings.lua", + + -- Visual Studio 2005-2010 solutions + "actions/vstudio/sln2005/test_dependencies.lua", + "actions/vstudio/sln2005/test_header.lua", + "actions/vstudio/sln2005/test_nested_projects.lua", + "actions/vstudio/sln2005/test_projects.lua", + "actions/vstudio/sln2005/test_platforms.lua", + + -- Visual Studio 2002-2008 C/C++ projects + "actions/vstudio/vc200x/test_assembly_refs.lua", + "actions/vstudio/vc200x/test_build_steps.lua", + "actions/vstudio/vc200x/test_configuration.lua", + "actions/vstudio/vc200x/test_compiler_block.lua", + "actions/vstudio/vc200x/test_debug_settings.lua", + "actions/vstudio/vc200x/test_excluded_configs.lua", + "actions/vstudio/vc200x/test_files.lua", + "actions/vstudio/vc200x/test_linker_block.lua", + "actions/vstudio/vc200x/test_manifest_block.lua", + "actions/vstudio/vc200x/test_nmake_settings.lua", + "actions/vstudio/vc200x/test_platforms.lua", + "actions/vstudio/vc200x/test_project.lua", + "actions/vstudio/vc200x/test_project_refs.lua", + "actions/vstudio/vc200x/test_resource_compiler.lua", + + -- Visual Studio 2010 C/C++ projects + "actions/vstudio/vc2010/test_assembly_refs.lua", + "actions/vstudio/vc2010/test_build_events.lua", + "actions/vstudio/vc2010/test_compile_settings.lua", + "actions/vstudio/vc2010/test_config_props.lua", + "actions/vstudio/vc2010/test_debug_settings.lua", + "actions/vstudio/vc2010/test_excluded_configs.lua", + "actions/vstudio/vc2010/test_extension_settings.lua", + "actions/vstudio/vc2010/test_extension_targets.lua", + "actions/vstudio/vc2010/test_globals.lua", + "actions/vstudio/vc2010/test_header.lua", + "actions/vstudio/vc2010/test_files.lua", + "actions/vstudio/vc2010/test_filter_ids.lua", + "actions/vstudio/vc2010/test_filters.lua", + "actions/vstudio/vc2010/test_item_def_group.lua", + "actions/vstudio/vc2010/test_link.lua", + "actions/vstudio/vc2010/test_manifest.lua", + "actions/vstudio/vc2010/test_nmake_props.lua", + "actions/vstudio/vc2010/test_output_props.lua", + "actions/vstudio/vc2010/test_project_configs.lua", + "actions/vstudio/vc2010/test_project_refs.lua", + "actions/vstudio/vc2010/test_prop_sheet.lua", + "actions/vstudio/vc2010/test_resource_compile.lua", + + -- Visual Studio 2012 + "actions/vs2012/test_csproj_common_props.lua", + "actions/vs2012/test_csproj_project_element.lua", + "actions/vs2012/test_csproj_project_props.lua", + "actions/vs2012/test_csproj_targets.lua", + "actions/vs2012/test_sln_header.lua", + "actions/vs2012/test_vcxproj_clcompile.lua", + "actions/vs2012/test_vcxproj_config_props.lua", + + -- Visual Studio 2013 + "actions/vs2013/test_csproj_project_element.lua", + "actions/vs2013/test_globals.lua", + "actions/vs2013/test_sln_header.lua", + "actions/vs2013/test_vcxproj_config_props.lua", + + -- Makefile tests + "actions/make/test_make_escaping.lua", + "actions/make/test_make_tovar.lua", + + -- Makefile solutions + "actions/make/solution/test_config_maps.lua", + "actions/make/solution/test_default_config.lua", + "actions/make/solution/test_help_rule.lua", + "actions/make/solution/test_project_rule.lua", + + -- Makefile C/C++ projects + "actions/make/cpp/test_clang.lua", + "actions/make/cpp/test_file_rules.lua", + "actions/make/cpp/test_flags.lua", + "actions/make/cpp/test_make_pch.lua", + "actions/make/cpp/test_make_linking.lua", + "actions/make/cpp/test_objects.lua", + "actions/make/cpp/test_target_rules.lua", + "actions/make/cpp/test_tools.lua", + "actions/make/cpp/test_wiidev.lua", + + -- Makefile C# projects + "actions/make/cs/test_embed_files.lua", + "actions/make/cs/test_flags.lua", + "actions/make/cs/test_links.lua", + "actions/make/cs/test_response.lua", + "actions/make/cs/test_sources.lua", + +} diff --git a/tests/actions/make/cpp/test_wiidev.lua b/tests/actions/make/cpp/test_wiidev.lua index fb9372d1..27e3b036 100644 --- a/tests/actions/make/cpp/test_wiidev.lua +++ b/tests/actions/make/cpp/test_wiidev.lua @@ -18,6 +18,7 @@ function suite.setup() local sln, prj = test.createsolution() system "wii" + flags "Symbols" cfg = test.getconfig(prj, "Debug") end @@ -36,7 +37,7 @@ function suite.writesCorrectLinkerFlags() make.ldFlags(cfg, premake.tools.gcc) test.capture [[ - ALL_LDFLAGS += $(LDFLAGS) -L$(LIBOGC_LIB) -s $(MACHDEP) + ALL_LDFLAGS += $(LDFLAGS) -L$(LIBOGC_LIB) $(MACHDEP) ]] end diff --git a/tests/actions/vstudio/vc200x/test_excluded_configs.lua b/tests/actions/vstudio/vc200x/test_excluded_configs.lua index f403d206..8ff10404 100644 --- a/tests/actions/vstudio/vc200x/test_excluded_configs.lua +++ b/tests/actions/vstudio/vc200x/test_excluded_configs.lua @@ -55,18 +55,6 @@ ]] end - function suite.normalLink_onIncludedConfig_externalTool() - solution("MySolution") - system "PS3" - prepare("Zeus") - test.capture [[ - - ]] - end - - --- --- Make sure that include directories are project relative. --- - - function suite.includeDirsAreProjectRelative() - includedirs { "../include", "include" } - prepare() - test.capture [[ - - ]] - end - - --- --- Verify the structure of a PS3 static library. --- - - function suite.looksGood_onPS3StaticLib() - kind "StaticLib" - prepare() - test.capture [[ - - ]] - end - - --- --- Verify the handling of system libraries. --- - - function suite.additionalDependencies_onSystemLibs() - links { "fs_stub", "net_stub" } - prepare() - test.capture [[ - - Console - false - mainCRTStartup - - ]] - end -- @@ -91,20 +79,3 @@ ]] end - - function suite.explicitLink_onExcludedConfig_externalTool() - solution("MySolution") - system "PS3" - prepare("Ares") - test.capture [[ - - Console - false - libMyProject2.a;%(AdditionalDependencies) - mainCRTStartup - - - false - - ]] - end diff --git a/tests/actions/vstudio/vc2010/test_link.lua b/tests/actions/vstudio/vc2010/test_link.lua index cbb2a0e1..638e756f 100644 --- a/tests/actions/vstudio/vc2010/test_link.lua +++ b/tests/actions/vstudio/vc2010/test_link.lua @@ -311,23 +311,6 @@ end --- --- On the PS3, system libraries must be prefixed with the "-l" flag. --- - - function suite.additionalDependencies_onPS3SystemLinks() - system "PS3" - links { "fs_stub", "net_stub" } - prepare() - test.capture [[ - - Windows - false - -lfs_stub;-lnet_stub;%(AdditionalDependencies) - ]] - end - - -- -- Correctly handle module definition (.def) files. -- diff --git a/tests/api/test_directory_kind.lua b/tests/api/test_directory_kind.lua index 629d26ca..ff30b5c8 100644 --- a/tests/api/test_directory_kind.lua +++ b/tests/api/test_directory_kind.lua @@ -43,6 +43,6 @@ -- function suite.expandsWildcards() - testapi "./*" - test.istrue(table.contains(api.scope.project.testapi, os.getcwd() .. "/api")) + testapi (_TESTS_DIR .. "/*") + test.istrue(table.contains(api.scope.project.testapi, _TESTS_DIR .. "/api")) end diff --git a/tests/base/test_include.lua b/tests/base/test_include.lua index 9fc086ac..a0682f03 100644 --- a/tests/base/test_include.lua +++ b/tests/base/test_include.lua @@ -1,7 +1,7 @@ -- -- tests/base/test_include.lua -- Test the include() function, for including external scripts --- Copyright (c) 2011-2013 Jason Perkins and the Premake project +-- Copyright (c) 2011-2014 Jason Perkins and the Premake project -- @@ -23,26 +23,26 @@ -- function suite.include_findsPremakeFile_onFolderNameOnly() - include "folder" + include (_TESTS_DIR .. "/folder") test.isequal("ok", premake.captured()) end function suite.include_onExactFilename() - include "folder/premake4.lua" + include (_TESTS_DIR .. "/folder/premake5.lua") test.isequal("ok", premake.captured()) end function suite.include_runsOnlyOnce_onMultipleIncludes() - include "folder/premake4.lua" - include "folder/premake4.lua" + include (_TESTS_DIR .. "/folder/premake5.lua") + include (_TESTS_DIR .. "/folder/premake5.lua") test.isequal("ok", premake.captured()) end function suite.include_runsOnlyOnce_onMultipleIncludesWithDifferentPaths() - include "folder/premake4.lua" - include "../tests/folder/premake4.lua" + include (_TESTS_DIR .. "/folder/premake5.lua") + include (_TESTS_DIR .. "/../tests/folder/premake5.lua") test.isequal("ok", premake.captured()) end diff --git a/tests/base/test_os.lua b/tests/base/test_os.lua index 80d800f3..8129ec76 100644 --- a/tests/base/test_os.lua +++ b/tests/base/test_os.lua @@ -6,6 +6,17 @@ local suite = test.declare("base_os") + local cwd + + function suite.setup() + cwd = os.getcwd() + os.chdir(_TESTS_DIR) + end + + function suite.teardown() + os.chdir(cwd) + end + -- -- os.findlib() tests diff --git a/tests/config/test_targetinfo.lua b/tests/config/test_targetinfo.lua index 352ce99c..2db9d2c7 100755 --- a/tests/config/test_targetinfo.lua +++ b/tests/config/test_targetinfo.lua @@ -193,30 +193,6 @@ end --- --- Name should use ".elf" for PS3 executables. --- - - function suite.nameUsesElf_onPS3ConsoleApp() - kind "ConsoleApp" - system "PS3" - i = prepare() - test.isequal("MyProject.elf", i.name) - end - - --- --- Name should use "lib" and ".a" for PS3 static libraries. --- - - function suite.nameUsesLib_onPS3StaticLib() - kind "StaticLib" - system "PS3" - i = prepare() - test.isequal("libMyProject.a", i.name) - end - - -- -- Name should use ".exe" for Xbox360 executables. -- diff --git a/tests/folder/premake4.lua b/tests/folder/premake5.lua similarity index 100% rename from tests/folder/premake4.lua rename to tests/folder/premake5.lua diff --git a/tests/test_dofile.lua b/tests/test_dofile.lua index 4aaf4035..a955c4c4 100644 --- a/tests/test_dofile.lua +++ b/tests/test_dofile.lua @@ -1,36 +1,33 @@ -- -- tests/test_dofile.lua -- Automated test suite for the extended dofile() functions. --- Copyright (c) 2008 Jason Perkins and the Premake project +-- Copyright (c) 2008, 2014 Jason Perkins and the Premake project -- - T.dofile = { } + local suite = test.declare("do_file") + - local os_getenv - - function T.dofile.setup() + + function suite.setup() os_getenv = os.getenv end - - function T.dofile.teardown() + + function suite.teardown() os.getenv = os_getenv end - - --- --- dofile() tests --- - function T.dofile.SearchesPath() - os.getenv = function() return os.getcwd().."/folder" end + + + function suite.searchesPath() + os.getenv = function() return _TESTS_DIR .. "/folder" end result = dofile("ok.lua") test.isequal("ok", result) end - function T.dofile.SearchesScriptsOption() - _OPTIONS["scripts"] = os.getcwd().."/folder" + function suite.searchesScriptsOption() + _OPTIONS["scripts"] = _TESTS_DIR .. "/folder" result = dofile("ok.lua") test.isequal("ok", result) end diff --git a/tests/testfx.lua b/tests/testfx.lua index 6fd67435..ff9a8316 100644 --- a/tests/testfx.lua +++ b/tests/testfx.lua @@ -10,6 +10,7 @@ -- test = {} + test.suppressed = {} -- @@ -76,6 +77,17 @@ end + function test.excludes(expected, actual) + if type(expected) == "table" then + for i, v in ipairs(expected) do + test.excludes(v, actual) + end + elseif table.contains(actual, expected) then + test.fail("excluded value %s found", expected) + end + end + + function test.fail(format, ...) -- if format is a number then it is the stack depth @@ -365,15 +377,32 @@ end + function test.declare(id) if T[id] then error("Duplicate test suite " .. id) end - T[id] = {} + T[id] = { + _TESTS_DIR = _TESTS_DIR, + _SCRIPT_DIR = _SCRIPT_DIR, + } return T[id] end + + function test.suppress(id) + if type(id) == "table" then + for i = 1, #id do + test.suppress(id[i]) + end + else + test.suppressed[id] = true + end + end + + + function test.runall(suitename, testname) test.print = print @@ -387,10 +416,13 @@ local numpassed = 0 local numfailed = 0 - local start_time = os.clock() + function runtest(suitename, suitetests, testname, testfunc) - if suitetests.setup ~= testfunc and suitetests.teardown ~= testfunc then + if suitetests.setup ~= testfunc and + suitetests.teardown ~= testfunc and + not test.suppressed[suitename .. "." .. testname] + then local ok, err = test_setup(suitetests, testfunc) if ok then @@ -410,18 +442,25 @@ end end + function runsuite(suitename, suitetests, testname) - if suitetests then + if suitetests and not test.suppressed[suitename] then + _TESTS_DIR = suitetests._TESTS_DIR + _SCRIPT_DIR = suitetests._SCRIPT_DIR + if testname then runtest(suitename, suitetests, testname, suitetests[testname]) else for testname, testfunc in pairs(suitetests) do - runtest(suitename, suitetests, testname, testfunc) + if type(testfunc) == "function" then + runtest(suitename, suitetests, testname, testfunc) + end end end end end + if suitename then runsuite(suitename, T[suitename], testname) else @@ -430,8 +469,6 @@ end end - io.write('running time : ', os.clock() - start_time,'\n') - print = real_print io.open = real_open io.output = real_output diff --git a/tests/tools/test_gcc.lua b/tests/tools/test_gcc.lua index fb4e7f16..ec2e78af 100644 --- a/tests/tools/test_gcc.lua +++ b/tests/tools/test_gcc.lua @@ -53,7 +53,7 @@ function suite.cppflags_defaultWithMMD() prepare() - test.isequal({"-MMD", "-MP"}, gcc.getcppflags(cfg)) + test.contains({"-MMD", "-MP"}, gcc.getcppflags(cfg)) end @@ -64,7 +64,7 @@ function suite.cppflagsExcludeMP_onHaiku() system "Haiku" prepare() - test.isequal({ "-MMD" }, gcc.getcppflags(cfg)) + test.excludes({ "-MP" }, gcc.getcppflags(cfg)) end @@ -75,43 +75,43 @@ function suite.cflags_onExtraWarnings() warnings "extra" prepare() - test.isequal({ "-Wall -Wextra" }, gcc.getcflags(cfg)) + test.contains({ "-Wall -Wextra" }, gcc.getcflags(cfg)) end function suite.cflags_onFatalWarnings() flags { "FatalWarnings" } prepare() - test.isequal({ "-Werror" }, gcc.getcflags(cfg)) + test.contains({ "-Werror" }, gcc.getcflags(cfg)) end function suite.cflags_onFloastFast() floatingpoint "Fast" prepare() - test.isequal({ "-ffast-math" }, gcc.getcflags(cfg)) + test.contains({ "-ffast-math" }, gcc.getcflags(cfg)) end function suite.cflags_onFloastStrict() floatingpoint "Strict" prepare() - test.isequal({ "-ffloat-store" }, gcc.getcflags(cfg)) + test.contains({ "-ffloat-store" }, gcc.getcflags(cfg)) end function suite.cflags_onNoWarnings() warnings "Off" prepare() - test.isequal({ "-w" }, gcc.getcflags(cfg)) + test.contains({ "-w" }, gcc.getcflags(cfg)) end function suite.cflags_onSSE() vectorextensions "SSE" prepare() - test.isequal({ "-msse" }, gcc.getcflags(cfg)) + test.contains({ "-msse" }, gcc.getcflags(cfg)) end function suite.cflags_onSSE2() vectorextensions "SSE2" prepare() - test.isequal({ "-msse2" }, gcc.getcflags(cfg)) + test.contains({ "-msse2" }, gcc.getcflags(cfg)) end @@ -122,37 +122,37 @@ function suite.cflags_onNoOptimize() optimize "Off" prepare() - test.isequal({ "-O0" }, gcc.getcflags(cfg)) + test.contains({ "-O0" }, gcc.getcflags(cfg)) end function suite.cflags_onOptimize() optimize "On" prepare() - test.isequal({ "-O2" }, gcc.getcflags(cfg)) + test.contains({ "-O2" }, gcc.getcflags(cfg)) end function suite.cflags_onOptimizeSize() optimize "Size" prepare() - test.isequal({ "-Os" }, gcc.getcflags(cfg)) + test.contains({ "-Os" }, gcc.getcflags(cfg)) end function suite.cflags_onOptimizeSpeed() optimize "Speed" prepare() - test.isequal({ "-O3" }, gcc.getcflags(cfg)) + test.contains({ "-O3" }, gcc.getcflags(cfg)) end function suite.cflags_onOptimizeFull() optimize "Full" prepare() - test.isequal({ "-O3" }, gcc.getcflags(cfg)) + test.contains({ "-O3" }, gcc.getcflags(cfg)) end function suite.cflags_onOptimizeDebug() optimize "Debug" prepare() - test.isequal({ "-Og" }, gcc.getcflags(cfg)) + test.contains({ "-Og" }, gcc.getcflags(cfg)) end @@ -163,13 +163,13 @@ function suite.cflags_onNoExceptions() flags { "NoExceptions" } prepare() - test.isequal({ "-fno-exceptions" }, gcc.getcxxflags(cfg)) + test.contains({ "-fno-exceptions" }, gcc.getcxxflags(cfg)) end function suite.cflags_onNoBufferSecurityCheck() flags { "NoBufferSecurityCheck" } prepare() - test.isequal({ "-fno-stack-protector" }, gcc.getcxxflags(cfg)) + test.contains({ "-fno-stack-protector" }, gcc.getcxxflags(cfg)) end @@ -177,21 +177,21 @@ -- Check the basic translation of LDFLAGS for a Posix system. -- - function suite.ldflags_defaultOnLinux() + function suite.ldflags_onNoSymbols() prepare() - test.isequal({ "-s" }, gcc.getldflags(cfg)) + test.contains({ "-s" }, gcc.getldflags(cfg)) end function suite.ldflags_onSymbols() flags { "Symbols" } prepare() - test.isequal({}, gcc.getldflags(cfg)) + test.excludes("-s", gcc.getldflags(cfg)) end function suite.ldflags_onSharedLib() kind "SharedLib" prepare() - test.isequal({ "-s", "-shared" }, gcc.getldflags(cfg)) + test.contains({ "-shared" }, gcc.getldflags(cfg)) end @@ -199,17 +199,17 @@ -- Check Mac OS X variants on LDFLAGS. -- - function suite.ldflags_onMacOSXStrip() + function suite.ldflags_onMacOSXNoSymbols() system "MacOSX" prepare() - test.isequal({ "-Wl,-x" }, gcc.getldflags(cfg)) + test.contains({ "-Wl,-x" }, gcc.getldflags(cfg)) end function suite.ldflags_onMacOSXSharedLib() system "MacOSX" kind "SharedLib" prepare() - test.isequal({ "-Wl,-x", "-dynamiclib" }, gcc.getldflags(cfg)) + test.contains({ "-dynamiclib" }, gcc.getldflags(cfg)) end @@ -221,14 +221,14 @@ system "Windows" kind "SharedLib" prepare() - test.isequal({ "-s", "-shared", '-Wl,--out-implib="MyProject.lib"' }, gcc.getldflags(cfg)) + test.contains({ "-shared", '-Wl,--out-implib="MyProject.lib"' }, gcc.getldflags(cfg)) end function suite.ldflags_onWindowsApp() system "Windows" kind "WindowedApp" prepare() - test.isequal({ "-s", "-mwindows" }, gcc.getldflags(cfg)) + test.contains({ "-mwindows" }, gcc.getldflags(cfg)) end @@ -240,25 +240,25 @@ function suite.cflags_onX32() architecture "x32" prepare() - test.isequal({ "-m32" }, gcc.getcflags(cfg)) + test.contains({ "-m32" }, gcc.getcflags(cfg)) end function suite.ldflags_onX32() architecture "x32" prepare() - test.isequal({ "-s", "-m32" }, gcc.getldflags(cfg)) + test.contains({ "-m32" }, gcc.getldflags(cfg)) end function suite.cflags_onX64() architecture "x64" prepare() - test.isequal({ "-m64" }, gcc.getcflags(cfg)) + test.contains({ "-m64" }, gcc.getcflags(cfg)) end function suite.ldflags_onX64() architecture "x64" prepare() - test.isequal({ "-s", "-m64" }, gcc.getldflags(cfg)) + test.contains({ "-m64" }, gcc.getldflags(cfg)) end @@ -270,7 +270,7 @@ system "MacOSX" kind "SharedLib" prepare() - test.isequal({ "-fPIC" }, gcc.getcflags(cfg)) + test.contains({ "-fPIC" }, gcc.getcflags(cfg)) end @@ -281,13 +281,13 @@ function suite.links_onSystemLibs() links { "fs_stub", "net_stub" } prepare() - test.isequal({ "-lfs_stub", "-lnet_stub" }, gcc.getlinks(cfg)) + test.contains({ "-lfs_stub", "-lnet_stub" }, gcc.getlinks(cfg)) end function suite.links_onFramework() links { "Cocoa.framework" } prepare() - test.isequal({ "-framework Cocoa" }, gcc.getlinks(cfg)) + test.contains({ "-framework Cocoa" }, gcc.getlinks(cfg)) end From b347b204d89b707f6bc7b9a8013035a11c4bad0f Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Thu, 18 Sep 2014 16:19:08 -0400 Subject: [PATCH 2/2] Modify testing scripts to use new test action setup --- README.txt | 5 +- tests/base/test_os.lua | 10 +- tests/premake5.lua | 230 ----------------------------------------- tests/stress | 2 - tests/test | 2 +- tests/test.bat | 7 +- 6 files changed, 12 insertions(+), 244 deletions(-) delete mode 100644 tests/premake5.lua delete mode 100755 tests/stress diff --git a/README.txt b/README.txt index 756b7d0d..44d8c358 100644 --- a/README.txt +++ b/README.txt @@ -1,5 +1,6 @@ PREMAKE A build configuration tool +Core module Copyright (C) 2002-2014 by Jason Perkins Distributed under the terms of the BSD License, see LICENSE.txt @@ -7,9 +8,7 @@ A build configuration tool The Lua language and runtime library is (C) TeCGraf, PUC-Rio. See their website at http://www.lua.org/ - See the file BUILD.txt for instructions on building Premake. - For questions, comments, or more information, visit the project - website at http://industriousone.com/premake + website at https://bitbucket.org/premake/premake-main diff --git a/tests/base/test_os.lua b/tests/base/test_os.lua index 8129ec76..863f974e 100644 --- a/tests/base/test_os.lua +++ b/tests/base/test_os.lua @@ -42,7 +42,7 @@ -- function suite.isfile_ReturnsTrue_OnExistingFile() - test.istrue(os.isfile("premake5.lua")) + test.istrue(os.isfile("_manifest.lua")) end function suite.isfile_ReturnsFalse_OnNonexistantFile() @@ -116,17 +116,17 @@ -- function suite.pathsearch_ReturnsNil_OnNotFound() - test.istrue( os.pathsearch("nosuchfile", "aaa;bbb;ccc") == nil ) + test.istrue(os.pathsearch("nosuchfile", "aaa;bbb;ccc") == nil) end function suite.pathsearch_ReturnsPath_OnFound() - test.isequal(os.getcwd(), os.pathsearch("premake5.lua", os.getcwd())) + test.isequal(_TESTS_DIR, os.pathsearch("_manifest.lua", _TESTS_DIR)) end function suite.pathsearch_FindsFile_OnComplexPath() - test.isequal(os.getcwd(), os.pathsearch("premake5.lua", "aaa;"..os.getcwd()..";bbb")) + test.isequal(_TESTS_DIR, os.pathsearch("_manifest.lua", "aaa;" .. _TESTS_DIR .. ";bbb")) end function suite.pathsearch_NilPathsAllowed() - test.isequal(os.getcwd(), os.pathsearch("premake5.lua", nil, os.getcwd(), nil)) + test.isequal(_TESTS_DIR, os.pathsearch("_manifest.lua", nil, _TESTS_DIR, nil)) end diff --git a/tests/premake5.lua b/tests/premake5.lua deleted file mode 100644 index 4a17b9c3..00000000 --- a/tests/premake5.lua +++ /dev/null @@ -1,230 +0,0 @@ --- --- tests/premake5.lua --- Automated test suite for Premake 5.x --- Copyright (c) 2008-2013 Jason Perkins and the Premake project --- - - dofile("testfx.lua") - - newoption { - trigger = "test", - description = "A suite or test to run" - } - - newoption { - trigger = "profile", - description = "Profile execution times; saves to profile.txt" - } - - if _OPTIONS["profile"] then - dofile("pepperfish_profiler.lua") - end - - --- --- The test suites --- - - -- Base API tests - dofile("test_dofile.lua") - dofile("test_string.lua") - - dofile("base/test_configset.lua") - dofile("base/test_context.lua") - dofile("base/test_criteria.lua") - dofile("base/test_detoken.lua") - dofile("base/test_include.lua") - dofile("base/test_option.lua") - dofile("base/test_os.lua") - dofile("base/test_override.lua") - dofile("base/test_path.lua") - dofile("base/test_premake_command.lua") - dofile("base/test_table.lua") - dofile("base/test_tree.lua") - dofile("base/test_uuid.lua") - - -- Solution object tests - dofile("solution/test_eachconfig.lua") - dofile("solution/test_location.lua") - dofile("solution/test_objdirs.lua") - - -- Project object tests - dofile("project/test_config_maps.lua") - dofile("project/test_eachconfig.lua") - dofile("project/test_filename.lua") - dofile("project/test_getconfig.lua") - dofile("project/test_location.lua") - dofile("project/test_vpaths.lua") - - -- Configuration object tests - dofile("config/test_linkinfo.lua") - dofile("config/test_links.lua") - dofile("config/test_targetinfo.lua") - - -- Baking tests - dofile("oven/test_filtering.lua") - dofile("oven/test_objdirs.lua") - - -- API tests - dofile("api/test_containers.lua") - dofile("api/test_directory_kind.lua") - dofile("api/test_list_kind.lua") - dofile("api/test_path_kind.lua") - dofile("api/test_register.lua") - dofile("api/test_string_kind.lua") - dofile("api/test_table_kind.lua") - - -- Control system tests - dofile("test_premake.lua") - dofile("base/test_validation.lua") - - -- Toolset tests - dofile("tools/test_dotnet.lua") - dofile("tools/test_gcc.lua") - dofile("tools/test_msc.lua") - dofile("tools/test_snc.lua") - - -- Visual Studio 2005-2010 C# projects - dofile("actions/vstudio/cs2005/test_assembly_refs.lua") - dofile("actions/vstudio/cs2005/test_build_events.lua") - dofile("actions/vstudio/cs2005/test_compiler_props.lua") - dofile("actions/vstudio/cs2005/test_debug_props.lua") - dofile("actions/vstudio/cs2005/test_files.lua") - dofile("actions/vstudio/cs2005/test_icon.lua") - dofile("actions/vstudio/cs2005/test_output_props.lua") - dofile("actions/vstudio/cs2005/projectelement.lua") - dofile("actions/vstudio/cs2005/test_platform_groups.lua") - dofile("actions/vstudio/cs2005/test_project_refs.lua") - dofile("actions/vstudio/cs2005/projectsettings.lua") - - -- Visual Studio 2005-2010 solutions - dofile("actions/vstudio/sln2005/test_dependencies.lua") - dofile("actions/vstudio/sln2005/test_header.lua") - dofile("actions/vstudio/sln2005/test_nested_projects.lua") - dofile("actions/vstudio/sln2005/test_projects.lua") - dofile("actions/vstudio/sln2005/test_platforms.lua") - - -- Visual Studio 2002-2008 C/C++ projects - dofile("actions/vstudio/vc200x/test_assembly_refs.lua") - dofile("actions/vstudio/vc200x/test_build_steps.lua") - dofile("actions/vstudio/vc200x/test_configuration.lua") - dofile("actions/vstudio/vc200x/test_compiler_block.lua") - dofile("actions/vstudio/vc200x/test_debug_settings.lua") - dofile("actions/vstudio/vc200x/test_excluded_configs.lua") - dofile("actions/vstudio/vc200x/test_external_compiler.lua") - dofile("actions/vstudio/vc200x/test_external_linker.lua") - dofile("actions/vstudio/vc200x/test_files.lua") - dofile("actions/vstudio/vc200x/test_linker_block.lua") - dofile("actions/vstudio/vc200x/test_manifest_block.lua") - dofile("actions/vstudio/vc200x/test_nmake_settings.lua") - dofile("actions/vstudio/vc200x/test_platforms.lua") - dofile("actions/vstudio/vc200x/test_project.lua") - dofile("actions/vstudio/vc200x/test_project_refs.lua") - dofile("actions/vstudio/vc200x/test_resource_compiler.lua") - - -- Visual Studio 2010 C/C++ projects - dofile("actions/vstudio/vc2010/test_assembly_refs.lua") - dofile("actions/vstudio/vc2010/test_build_events.lua") - dofile("actions/vstudio/vc2010/test_compile_settings.lua") - dofile("actions/vstudio/vc2010/test_config_props.lua") - dofile("actions/vstudio/vc2010/test_debug_settings.lua") - dofile("actions/vstudio/vc2010/test_excluded_configs.lua") - dofile("actions/vstudio/vc2010/test_extension_settings.lua") - dofile("actions/vstudio/vc2010/test_extension_targets.lua") - dofile("actions/vstudio/vc2010/test_globals.lua") - dofile("actions/vstudio/vc2010/test_header.lua") - dofile("actions/vstudio/vc2010/test_files.lua") - dofile("actions/vstudio/vc2010/test_filter_ids.lua") - dofile("actions/vstudio/vc2010/test_filters.lua") - dofile("actions/vstudio/vc2010/test_item_def_group.lua") - dofile("actions/vstudio/vc2010/test_link.lua") - dofile("actions/vstudio/vc2010/test_manifest.lua") - dofile("actions/vstudio/vc2010/test_nmake_props.lua") - dofile("actions/vstudio/vc2010/test_output_props.lua") - dofile("actions/vstudio/vc2010/test_project_configs.lua") - dofile("actions/vstudio/vc2010/test_project_refs.lua") - dofile("actions/vstudio/vc2010/test_prop_sheet.lua") - dofile("actions/vstudio/vc2010/test_resource_compile.lua") - - -- Visual Studio 2012 - dofile("actions/vs2012/test_csproj_common_props.lua") - dofile("actions/vs2012/test_csproj_project_element.lua") - dofile("actions/vs2012/test_csproj_project_props.lua") - dofile("actions/vs2012/test_csproj_targets.lua") - dofile("actions/vs2012/test_sln_header.lua") - dofile("actions/vs2012/test_vcxproj_clcompile.lua") - dofile("actions/vs2012/test_vcxproj_config_props.lua") - - -- Visual Studio 2013 - dofile("actions/vs2013/test_csproj_project_element.lua") - dofile("actions/vs2013/test_globals.lua") - dofile("actions/vs2013/test_sln_header.lua") - dofile("actions/vs2013/test_vcxproj_config_props.lua") - - -- Makefile tests - dofile("actions/make/test_make_escaping.lua") - dofile("actions/make/test_make_tovar.lua") - - -- Makefile solutions - dofile("actions/make/solution/test_config_maps.lua") - dofile("actions/make/solution/test_default_config.lua") - dofile("actions/make/solution/test_help_rule.lua") - dofile("actions/make/solution/test_project_rule.lua") - - -- Makefile C/C++ projects - dofile("actions/make/cpp/test_clang.lua") - dofile("actions/make/cpp/test_file_rules.lua") - dofile("actions/make/cpp/test_flags.lua") - dofile("actions/make/cpp/test_make_pch.lua") - dofile("actions/make/cpp/test_make_linking.lua") - dofile("actions/make/cpp/test_objects.lua") - dofile("actions/make/cpp/test_ps3.lua") - dofile("actions/make/cpp/test_target_rules.lua") - dofile("actions/make/cpp/test_tools.lua") - dofile("actions/make/cpp/test_wiidev.lua") - - -- Makefile C# projects - dofile("actions/make/cs/test_embed_files.lua") - dofile("actions/make/cs/test_flags.lua") - dofile("actions/make/cs/test_links.lua") - dofile("actions/make/cs/test_response.lua") - dofile("actions/make/cs/test_sources.lua") - - - newaction { - trigger = "test", - description = "Run the automated test suite", - - execute = function () - local focus = {} - if _OPTIONS["test"] then - focus = string.explode(_OPTIONS["test"] or "", ".", true) - end - - local profile = _OPTIONS["profile"] - if profile == "" then profile = "time" end - - local profiler - if profile then - profiler = newProfiler() - profiler:start() - end - - passed, failed = test.runall(focus[1], focus[2]) - - if profile then - profiler:stop() - local outfile = io.open("profile.txt", "w+") - profiler:report(outfile) - outfile:close() - end - - msg = string.format("%d tests passed, %d failed", passed, failed) - if (failed > 0) then - print(msg) - os.exit(5) - else - print(msg) - end - end - } diff --git a/tests/stress b/tests/stress deleted file mode 100755 index 7c34e149..00000000 --- a/tests/stress +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -../bin/debug/premake5 /scripts=../src /file=test_stress.lua stress diff --git a/tests/test b/tests/test index 6ae7887b..e9f1d7f1 100755 --- a/tests/test +++ b/tests/test @@ -1,2 +1,2 @@ #!/bin/sh -cd `dirname $0` && ../bin/debug/premake5 /scripts=../src $1 $2 $3 test +cd `dirname $0` && ../bin/debug/premake5 /file=../premake5.lua /scripts=../src $1 $2 $3 test diff --git a/tests/test.bat b/tests/test.bat index 6a4ef87d..043871ef 100644 --- a/tests/test.bat +++ b/tests/test.bat @@ -1,3 +1,4 @@ - -CALL ..\\bin\\debug\\premake5 /scripts=..\\src test -::CALL ..\\bin\\release\\premake5 /scripts=..\\src test +@echo off +pushd "%~dp0" +..\bin\debug\premake5.exe /scripts=..\src /file=..\premake5.lua %* test +popd