1-- 2-- tests/base/test_uuid.lua 3-- Automated test suite for UUID generation. 4-- Copyright (c) 2008-2012 Jason Perkins and the Premake project 5-- 6 7 local suite = test.declare("os_uuid") 8 9 10-- 11-- Setup and teardown 12-- 13 14 local builtin_print, result 15 16 function suite.setup() 17 builtin_print = print 18 print = function(value) 19 result = value 20 end 21 end 22 23 function suite.teardown() 24 print = builtin_print 25 end 26 27 28-- 29-- Make sure the return value looks like a UUID. 30-- 31 32 function suite.returnsValidUUID() 33 local g = os.uuid() 34 test.istrue(#g == 36) 35 for i=1,36 do 36 local ch = g:sub(i,i) 37 test.istrue(ch:find("[ABCDEF0123456789-]")) 38 end 39 test.isequal("-", g:sub(9,9)) 40 test.isequal("-", g:sub(14,14)) 41 test.isequal("-", g:sub(19,19)) 42 test.isequal("-", g:sub(24,24)) 43 end 44 45 46-- 47-- Make sure the value returned is deterministic if a name is provided. 48-- 49 50 function suite.isDeterministic_onName() 51 test.isequal("885E8F4B-F43D-0EE7-FD55-99BD69B47448", os.uuid("MyValue")) 52 end 53