diff --git a/src/actions/vstudio/vs2010_vcxproj_filters.lua b/src/actions/vstudio/vs2010_vcxproj_filters.lua index 9ba64345..e828fcc9 100644 --- a/src/actions/vstudio/vs2010_vcxproj_filters.lua +++ b/src/actions/vstudio/vs2010_vcxproj_filters.lua @@ -48,7 +48,7 @@ end _x(2, '', path.translate(node.path)) - _p(3, '{%s}', os.uuid()) + _p(3, '{%s}', os.uuid(node.path)) _p(2, '') end }, false) diff --git a/src/base/os.lua b/src/base/os.lua index e9a1ff0e..5f964b0c 100644 --- a/src/base/os.lua +++ b/src/base/os.lua @@ -262,3 +262,21 @@ builtin_rmdir(p) end + +-- +-- Generate a UUID. +-- + + os._uuids = {} + + local builtin_uuid = os.uuid + function os.uuid(name) + local id = builtin_uuid(name) + if name then + if os._uuids[id] and os._uuids[id] ~= name then + print(string.format("** Warning: UUID clash between %s and %s", os._uuids[id], name)) + end + os._uuids[id] = name + end + return id + end diff --git a/tests/actions/vstudio/vc2010/test_filter_ids.lua b/tests/actions/vstudio/vc2010/test_filter_ids.lua index fe699b2f..2f5e9e1a 100644 --- a/tests/actions/vstudio/vc2010/test_filter_ids.lua +++ b/tests/actions/vstudio/vc2010/test_filter_ids.lua @@ -4,8 +4,7 @@ -- Copyright (c) 2011-2012 Jason Perkins and the Premake project -- - T.vs2010_filter_ids = { } - local suite = T.vs2010_filter_ids + local suite = test.declare("vs2010_filter_ids") local vc2010 = premake.vstudio.vc2010 @@ -14,19 +13,11 @@ -- local sln, prj - local os_uuid function suite.setup() - os_uuid = os.uuid - os.uuid = function() return "00112233-4455-6677-8888-99AABBCCDDEE" end - _ACTION = "vs2010" sln = test.createsolution() end - - function suite.teardown() - os.uuid = os_uuid - end local function prepare() prj = premake.solution.getproject_ng(sln, 1) @@ -55,7 +46,7 @@ test.capture [[ - {00112233-4455-6677-8888-99AABBCCDDEE} + {2DAB880B-99B4-887C-2230-9F7C8E38947C} ]] @@ -72,10 +63,10 @@ test.capture [[ - {00112233-4455-6677-8888-99AABBCCDDEE} + {2DAB880B-99B4-887C-2230-9F7C8E38947C} - {00112233-4455-6677-8888-99AABBCCDDEE} + {BB36ED8F-A704-E195-9098-51BC7C05BDFA} ]] @@ -93,7 +84,7 @@ test.capture [[ - {00112233-4455-6677-8888-99AABBCCDDEE} + {E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6} ]] @@ -106,10 +97,10 @@ test.capture [[ - {00112233-4455-6677-8888-99AABBCCDDEE} + {21EB8090-0D4E-1035-B6D3-48EBA215DCB7} - {00112233-4455-6677-8888-99AABBCCDDEE} + {E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6} ]] diff --git a/tests/base/test_os.lua b/tests/base/test_os.lua index 554c0f23..065e18a4 100644 --- a/tests/base/test_os.lua +++ b/tests/base/test_os.lua @@ -4,9 +4,7 @@ -- Copyright (c) 2008-2011 Jason Perkins and the Premake project -- - - T.os = { } - local suite = T.os + local suite = test.declare("base_os") -- @@ -105,22 +103,3 @@ function suite.pathsearch_NilPathsAllowed() test.isequal(os.getcwd(), os.pathsearch("premake4.lua", nil, os.getcwd(), nil)) end - - --- --- os.uuid() tests --- - - function suite.guid_ReturnsValidUUID() - local g = os.uuid() - test.istrue(#g == 36) - for i=1,36 do - local ch = g:sub(i,i) - test.istrue(ch:find("[ABCDEF0123456789-]")) - end - test.isequal("-", g:sub(9,9)) - test.isequal("-", g:sub(14,14)) - test.isequal("-", g:sub(19,19)) - test.isequal("-", g:sub(24,24)) - end - diff --git a/tests/base/test_uuid.lua b/tests/base/test_uuid.lua new file mode 100644 index 00000000..0e5230e2 --- /dev/null +++ b/tests/base/test_uuid.lua @@ -0,0 +1,64 @@ +-- +-- tests/base/test_uuid.lua +-- Automated test suite for UUID generation. +-- Copyright (c) 2008-2012 Jason Perkins and the Premake project +-- + + local suite = test.declare("os_uuid") + + +-- +-- Setup and teardown +-- + + local builtin_print, result + + function suite.setup() + builtin_print = print + print = function(value) + result = value + end + end + + function suite.teardown() + print = builtin_print + end + + +-- +-- Make sure the return value looks like a UUID. +-- + + function suite.returnsValidUUID() + local g = os.uuid() + test.istrue(#g == 36) + for i=1,36 do + local ch = g:sub(i,i) + test.istrue(ch:find("[ABCDEF0123456789-]")) + end + test.isequal("-", g:sub(9,9)) + test.isequal("-", g:sub(14,14)) + test.isequal("-", g:sub(19,19)) + test.isequal("-", g:sub(24,24)) + end + + +-- +-- Make sure the value returned is deterministic if a name is provided. +-- + + function suite.isDeterministic_onName() + test.isequal("885E8F4B-F43D-0EE7-FD55-99BD69B47448", os.uuid("MyValue")) + end + + +-- +-- A warning should be shown is an ID clash is ever discovered. +-- + + function suite.showsWarning_onCollision() + -- use a bit of secret knowledge to make the test possible + os._uuids["885E8F4B-F43D-0EE7-FD55-99BD69B47448"] = "Some other value" + os.uuid("MyValue") + test.istrue(result:startswith("** Warning:")) + end diff --git a/tests/premake4.lua b/tests/premake4.lua index 97c8b3dd..d0ab7f5d 100644 --- a/tests/premake4.lua +++ b/tests/premake4.lua @@ -53,6 +53,7 @@ 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") diff --git a/tests/testfx.lua b/tests/testfx.lua index a812b0eb..691b3cfa 100644 --- a/tests/testfx.lua +++ b/tests/testfx.lua @@ -263,6 +263,15 @@ end + function test.declare(id) + if T[id] then + error("Duplicate test suite " .. id) + end + T[id] = {} + return T[id] + end + + function test.runall(suitename, testname) test.print = print