From e9599feea3b3b42d92797ac789c43dadcee81f29 Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Fri, 14 Dec 2012 10:01:22 -0500 Subject: Port vpath tests from premake-dev --- tests/project/test_vpaths.lua | 111 +++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 60 deletions(-) (limited to 'tests') diff --git a/tests/project/test_vpaths.lua b/tests/project/test_vpaths.lua index 9a099ee..3055986 100644 --- a/tests/project/test_vpaths.lua +++ b/tests/project/test_vpaths.lua @@ -1,7 +1,7 @@ -- -- tests/project/test_vpaths.lua -- Automated test suite for the project support functions. --- Copyright (c) 2011 Jason Perkins and the Premake project +-- Copyright (c) 2011-2012 Jason Perkins and the Premake project -- T.project_vpaths = { } @@ -13,14 +13,17 @@ -- Setup and teardown -- - local sln, prj + local sln + function suite.setup() sln = test.createsolution() end - local function prepare() + local function run() premake.bake.buildconfigs() - prj = premake.solution.getproject(sln, 1) + local prj = premake.solution.getproject(sln, 1) + local cfg = premake.getconfig(prj, "Debug") + return project.getvpath(prj, cfg.files[1]) end @@ -29,39 +32,45 @@ -- function suite.ReturnsOriginalPath_OnNoVpaths() - prepare() - test.isequal("hello.c", project.getvpath(prj, "hello.c")) + files { "hello.c" } + test.isequal("hello.c", run()) end function suite.ReturnsOriginalPath_OnNoMatches() + files { "hello.c" } vpaths { ["Headers"] = "**.h" } - prepare() - test.isequal("hello.c", project.getvpath(prj, "hello.c")) + test.isequal("hello.c", run()) end - function suite.CanTrimLeadingPaths() + function suite.CanStripPaths() + files { "src/myproject/hello.c" } vpaths { [""] = "src" } - prepare() - test.isequal("myproject/hello.c", project.getvpath(prj, "src/myproject/hello.c")) + run() + test.isequal("hello.c", run()) + end + + function suite.CanTrimLeadingPaths() + files { "src/myproject/hello.c" } + vpaths { ["*"] = "src" } + test.isequal("myproject/hello.c", run()) end function suite.PatternMayIncludeTrailingSlash() + files { "src/myproject/hello.c" } vpaths { [""] = "src/myproject/" } - prepare() - test.isequal("hello.c", project.getvpath(prj, "src/myproject/hello.c")) + test.isequal("hello.c", run()) end function suite.SimpleReplacementPatterns() + files { "src/myproject/hello.c" } vpaths { ["sources"] = "src/myproject" } - prepare() - test.isequal("sources/hello.c", project.getvpath(prj, "src/myproject/hello.c")) + test.isequal("sources/hello.c", run()) end function suite.ExactFilenameMatch() files { "src/hello.c" } vpaths { ["sources"] = "src/hello.c" } - prepare() - test.isequal("sources/hello.c", project.getvpath(prj, "src/hello.c")) + test.isequal("sources/hello.c", run()) end @@ -70,69 +79,54 @@ -- function suite.MatchFilePattern_ToGroup_Flat() + files { "src/myproject/hello.h" } vpaths { ["Headers"] = "**.h" } - prepare() - test.isequal("Headers/hello.h", project.getvpath(prj, "src/myproject/hello.h")) + test.isequal("Headers/hello.h", run()) + end + + function suite.MatchFilePattern_ToNone_Flat() + files { "src/myproject/hello.h" } + vpaths { [""] = "**.h" } + test.isequal("hello.h", run()) end function suite.MatchFilePattern_ToNestedGroup_Flat() + files { "src/myproject/hello.h" } vpaths { ["Source/Headers"] = "**.h" } - prepare() - test.isequal("Source/Headers/hello.h", project.getvpath(prj, "src/myproject/hello.h")) + test.isequal("Source/Headers/hello.h", run()) end function suite.MatchFilePattern_ToGroup_WithTrailingSlash() + files { "src/myproject/hello.h" } vpaths { ["Headers/"] = "**.h" } - prepare() - test.isequal("Headers/hello.h", project.getvpath(prj, "src/myproject/hello.h")) + test.isequal("Headers/hello.h", run()) end function suite.MatchFilePattern_ToNestedGroup_Flat() + files { "src/myproject/hello.h" } vpaths { ["Group/Headers"] = "**.h" } - prepare() - test.isequal("Group/Headers/hello.h", project.getvpath(prj, "src/myproject/hello.h")) + test.isequal("Group/Headers/hello.h", run()) end function suite.MatchFilePattern_ToGroup_Nested() - vpaths { ["Headers/**"] = "**.h" } - prepare() - test.isequal("Headers/src/myproject/hello.h", project.getvpath(prj, "src/myproject/hello.h")) + files { "src/myproject/hello.h" } + vpaths { ["Headers/*"] = "**.h" } + test.isequal("Headers/src/myproject/hello.h", run()) end function suite.MatchFilePattern_ToGroup_Nested_OneStar() + files { "src/myproject/hello.h" } vpaths { ["Headers/*"] = "**.h" } - prepare() - test.isequal("Headers/src/myproject/hello.h", project.getvpath(prj, "src/myproject/hello.h")) + test.isequal("Headers/src/myproject/hello.h", run()) end function suite.MatchFilePatternWithPath_ToGroup_Nested() - vpaths { ["Headers/**"] = "src/**.h" } - prepare() - test.isequal("Headers/myproject/hello.h", project.getvpath(prj, "src/myproject/hello.h")) + files { "src/myproject/hello.h" } + vpaths { ["Headers/*"] = "src/**.h" } + test.isequal("Headers/myproject/hello.h", run()) end - --- --- Test directory dot patterns --- - - function suite.RemovesLeadingDotFolder() - prepare() - test.isequal("hello.c", project.getvpath(prj, "./hello.c")) - end - - function suite.RemovesLeadingDotDotFolder() - prepare() - test.isequal("hello.c", project.getvpath(prj, "../hello.c")) - end - - function suite.RemovesMultipleLeadingDotDotFolders() - prepare() - test.isequal("src/hello.c", project.getvpath(prj, "../../src/hello.c")) - end - - -- -- Test with project locations -- @@ -141,22 +135,19 @@ location "build" files "src/hello.h" vpaths { [""] = "src" } - prepare() - test.isequal("hello.h", project.getvpath(prj, prj.files[1])) + test.isequal("hello.h", run()) end function suite.MatchFilePattern_OnProjectLocationSet() location "build" files "src/hello.h" vpaths { ["Headers"] = "**.h" } - prepare() - test.isequal("Headers/hello.h", project.getvpath(prj, prj.files[1])) + test.isequal("Headers/hello.h", run()) end function suite.MatchFilePatternWithPath_OnProjectLocationSet() location "build" files "src/hello.h" vpaths { ["Headers"] = "src/**.h" } - prepare() - test.isequal("Headers/hello.h", project.getvpath(prj, prj.files[1])) + test.isequal("Headers/hello.h", run()) end -- cgit v1.2.3