g00dmid

UNC Test

Mar 3rd, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.50 KB | None | 0 0
  1. # (not mine)
  2. # UNC Test:
  3. local passes, fails, undefined = 0, 0, 0
  4. local running = 0
  5.  
  6. local function getGlobal(path)
  7. local value = getfenv(0)
  8.  
  9. while value ~= nil and path ~= "" do
  10. local name, nextValue = string.match(path, "^([^.]+)%.?(.*)$")
  11. value = value[name]
  12. path = nextValue
  13. end
  14.  
  15. return value
  16. end
  17.  
  18. local function test(name, aliases, callback)
  19. running += 1
  20.  
  21. task.spawn(function()
  22. if not callback then
  23. print("⏺️ " .. name)
  24. elseif not getGlobal(name) then
  25. fails += 1
  26. warn("⛔ " .. name)
  27. else
  28. local success, message = pcall(callback)
  29.  
  30. if success then
  31. passes += 1
  32. print("✅ " .. name .. (message and " • " .. message or ""))
  33. else
  34. fails += 1
  35. warn("⛔ " .. name .. " failed: " .. message)
  36. end
  37. end
  38.  
  39. local undefinedAliases = {}
  40.  
  41. for _, alias in ipairs(aliases) do
  42. if getGlobal(alias) == nil then
  43. table.insert(undefinedAliases, alias)
  44. end
  45. end
  46.  
  47. if #undefinedAliases > 0 then
  48. undefined += 1
  49. warn("⚠️ " .. table.concat(undefinedAliases, ", "))
  50. end
  51.  
  52. running -= 1
  53. end)
  54. end
  55.  
  56. -- Header and summary
  57.  
  58. print("\n")
  59.  
  60. print("UNC Environment Check")
  61. print("✅ - Pass, ⛔ - Fail, ⏺️ - No test, ⚠️ - Missing aliases\n")
  62.  
  63. task.defer(function()
  64. repeat task.wait() until running == 0
  65.  
  66. local rate = math.round(passes / (passes + fails) * 100)
  67. local outOf = passes .. " out of " .. (passes + fails)
  68.  
  69. print("\n")
  70.  
  71. print("UNC Summary")
  72. print("✅ Tested with a " .. rate .. "% success rate (" .. outOf .. ")")
  73. print("⛔ " .. fails .. " tests failed")
  74. print("⚠️ " .. undefined .. " globals are missing aliases")
  75. end)
  76.  
  77. -- Cache
  78.  
  79. test("cache.invalidate", {}, function()
  80. local container = Instance.new("Folder")
  81. local part = Instance.new("Part", container)
  82. cache.invalidate(container:FindFirstChild("Part"))
  83. assert(part ~= container:FindFirstChild("Part"), "Reference `part` could not be invalidated")
  84. end)
  85.  
  86. test("cache.iscached", {}, function()
  87. local part = Instance.new("Part")
  88. assert(cache.iscached(part), "Part should be cached")
  89. cache.invalidate(part)
  90. assert(not cache.iscached(part), "Part should not be cached")
  91. end)
  92.  
  93. test("cache.replace", {}, function()
  94. local part = Instance.new("Part")
  95. local fire = Instance.new("Fire")
  96. cache.replace(part, fire)
  97. assert(part ~= fire, "Part was not replaced with Fire")
  98. end)
  99.  
  100. test("cloneref", {}, function()
  101. local part = Instance.new("Part")
  102. local clone = cloneref(part)
  103. assert(part ~= clone, "Clone should not be equal to original")
  104. clone.Name = "Test"
  105. assert(part.Name == "Test", "Clone should have updated the original")
  106. end)
  107.  
  108. test("compareinstances", {}, function()
  109. local part = Instance.new("Part")
  110. local clone = cloneref(part)
  111. assert(part ~= clone, "Clone should not be equal to original")
  112. assert(compareinstances(part, clone), "Clone should be equal to original when using compareinstances()")
  113. end)
  114.  
  115. -- Closures
  116.  
  117. local function shallowEqual(t1, t2)
  118. if t1 == t2 then
  119. return true
  120. end
  121.  
  122. local UNIQUE_TYPES = {
  123. ["function"] = true,
  124. ["table"] = true,
  125. ["userdata"] = true,
  126. ["thread"] = true,
  127. }
  128.  
  129. for k, v in pairs(t1) do
  130. if UNIQUE_TYPES[type(v)] then
  131. if type(t2[k]) ~= type(v) then
  132. return false
  133. end
  134. elseif t2[k] ~= v then
  135. return false
  136. end
  137. end
  138.  
  139. for k, v in pairs(t2) do
  140. if UNIQUE_TYPES[type(v)] then
  141. if type(t2[k]) ~= type(v) then
  142. return false
  143. end
  144. elseif t1[k] ~= v then
  145. return false
  146. end
  147. end
  148.  
  149. return true
  150. end
  151.  
  152. test("checkcaller", {}, function()
  153. assert(checkcaller(), "Main scope should return true")
  154. end)
  155.  
  156. test("clonefunction", {}, function()
  157. local function test()
  158. return "success"
  159. end
  160. local copy = clonefunction(test)
  161. assert(test() == copy(), "The clone should return the same value as the original")
  162. assert(test ~= copy, "The clone should not be equal to the original")
  163. end)
  164.  
  165. test("getcallingscript", {})
  166.  
  167. test("getscriptclosure", {"getscriptfunction"}, function()
  168. local module = game:GetService("CoreGui").RobloxGui.Modules.Common.Constants
  169. local constants = getrenv().require(module)
  170. local generated = getscriptclosure(module)()
  171. assert(constants ~= generated, "Generated module should not match the original")
  172. assert(shallowEqual(constants, generated), "Generated constant table should be shallow equal to the original")
  173. end)
  174.  
  175. test("hookfunction", {"replaceclosure"}, function()
  176. local function test()
  177. return true
  178. end
  179. local ref = hookfunction(test, function()
  180. return false
  181. end)
  182. assert(test() == false, "Function should return false")
  183. assert(ref() == true, "Original function should return true")
  184. assert(test ~= ref, "Original function should not be same as the reference")
  185. end)
  186.  
  187. test("iscclosure", {}, function()
  188. assert(iscclosure(print) == true, "Function 'print' should be a C closure")
  189. assert(iscclosure(function() end) == false, "Executor function should not be a C closure")
  190. end)
  191.  
  192. test("islclosure", {}, function()
  193. assert(islclosure(print) == false, "Function 'print' should not be a Lua closure")
  194. assert(islclosure(function() end) == true, "Executor function should be a Lua closure")
  195. end)
  196.  
  197. test("isexecutorclosure", {"checkclosure", "isourclosure"}, function()
  198. assert(isexecutorclosure(isexecutorclosure) == true, "Did not return true for an executor global")
  199. assert(isexecutorclosure(newcclosure(function() end)) == true, "Did not return true for an executor C closure")
  200. assert(isexecutorclosure(function() end) == true, "Did not return true for an executor Luau closure")
  201. assert(isexecutorclosure(print) == false, "Did not return false for a Roblox global")
  202. end)
  203.  
  204. test("loadstring", {}, function()
  205. local animate = game:GetService("Players").LocalPlayer.Character.Animate
  206. local bytecode = getscriptbytecode(animate)
  207. local func = loadstring(bytecode)
  208. assert(type(func) ~= "function", "Luau bytecode should not be loadable!")
  209. assert(assert(loadstring("return ... + 1"))(1) == 2, "Failed to do simple math")
  210. assert(type(select(2, loadstring("f"))) == "string", "Loadstring did not return anything for a compiler error")
  211. end)
  212.  
  213. test("newcclosure", {}, function()
  214. local function test()
  215. return true
  216. end
  217. local testC = newcclosure(test)
  218. assert(test() == testC(), "New C closure should return the same value as the original")
  219. assert(test ~= testC, "New C closure should not be same as the original")
  220. assert(iscclosure(testC), "New C closure should be a C closure")
  221. end)
  222.  
  223. -- Console
  224.  
  225. test("rconsoleclear", {"consoleclear"})
  226.  
  227. test("rconsolecreate", {"consolecreate"})
  228.  
  229. test("rconsoledestroy", {"consoledestroy"})
  230.  
  231. test("rconsoleinput", {"consoleinput"})
  232.  
  233. test("rconsoleprint", {"consoleprint"})
  234.  
  235. test("rconsolesettitle", {"rconsolename", "consolesettitle"})
  236.  
  237. -- Crypt
  238.  
  239. test("crypt.base64encode", {"crypt.base64.encode", "crypt.base64_encode", "base64.encode", "base64_encode"}, function()
  240. assert(crypt.base64encode("test") == "dGVzdA==", "Base64 encoding failed")
  241. end)
  242.  
  243. test("crypt.base64decode", {"crypt.base64.decode", "crypt.base64_decode", "base64.decode", "base64_decode"}, function()
  244. assert(crypt.base64decode("dGVzdA==") == "test", "Base64 decoding failed")
  245. end)
  246.  
  247. test("crypt.encrypt", {}, function()
  248. local key = crypt.generatekey()
  249. local encrypted, iv = crypt.encrypt("test", key, nil, "CBC")
  250. assert(iv, "crypt.encrypt should return an IV")
  251. local decrypted = crypt.decrypt(encrypted, key, iv, "CBC")
  252. assert(decrypted == "test", "Failed to decrypt raw string from encrypted data")
  253. end)
  254.  
  255. test("crypt.decrypt", {}, function()
  256. local key, iv = crypt.generatekey(), crypt.generatekey()
  257. local encrypted = crypt.encrypt("test", key, iv, "CBC")
  258. local decrypted = crypt.decrypt(encrypted, key, iv, "CBC")
  259. assert(decrypted == "test", "Failed to decrypt raw string from encrypted data")
  260. end)
  261.  
  262. test("crypt.generatebytes", {}, function()
  263. local size = math.random(10, 100)
  264. local bytes = crypt.generatebytes(size)
  265. assert(#crypt.base64decode(bytes) == size, "The decoded result should be " .. size .. " bytes long (got " .. #crypt.base64decode(bytes) .. " decoded, " .. #bytes .. " raw)")
  266. end)
  267.  
  268. test("crypt.generatekey", {}, function()
  269. local key = crypt.generatekey()
  270. assert(#crypt.base64decode(key) == 32, "Generated key should be 32 bytes long when decoded")
  271. end)
  272.  
  273. test("crypt.hash", {}, function()
  274. local algorithms = {'sha1', 'sha384', 'sha512', 'md5', 'sha256', 'sha3-224', 'sha3-256', 'sha3-512'}
  275. for _, algorithm in ipairs(algorithms) do
  276. local hash = crypt.hash("test", algorithm)
  277. assert(hash, "crypt.hash on algorithm '" .. algorithm .. "' should return a hash")
  278. end
  279. end)
  280.  
  281. --- Debug
  282.  
  283. test("debug.getconstant", {}, function()
  284. local function test()
  285. print("Hello, world!")
  286. end
  287. assert(debug.getconstant(test, 1) == "print", "First constant must be print")
  288. assert(debug.getconstant(test, 2) == nil, "Second constant must be nil")
  289. assert(debug.getconstant(test, 3) == "Hello, world!", "Third constant must be 'Hello, world!'")
  290. end)
  291.  
  292. test("debug.getconstants", {}, function()
  293. local function test()
  294. local num = 5000 .. 50000
  295. print("Hello, world!", num, warn)
  296. end
  297. local constants = debug.getconstants(test)
  298. assert(constants[1] == 50000, "First constant must be 50000")
  299. assert(constants[2] == "print", "Second constant must be print")
  300. assert(constants[3] == nil, "Third constant must be nil")
  301. assert(constants[4] == "Hello, world!", "Fourth constant must be 'Hello, world!'")
  302. assert(constants[5] == "warn", "Fifth constant must be warn")
  303. end)
  304.  
  305. test("debug.getinfo", {}, function()
  306. local types = {
  307. source = "string",
  308. short_src = "string",
  309. func = "function",
  310. what = "string",
  311. currentline = "number",
  312. name = "string",
  313. nups = "number",
  314. numparams = "number",
  315. is_vararg = "number",
  316. }
  317. local function test(...)
  318. print(...)
  319. end
  320. local info = debug.getinfo(test)
  321. for k, v in pairs(types) do
  322. assert(info[k] ~= nil, "Did not return a table with a '" .. k .. "' field")
  323. assert(type(info[k]) == v, "Did not return a table with " .. k .. " as a " .. v .. " (got " .. type(info[k]) .. ")")
  324. end
  325. end)
  326.  
  327. test("debug.getproto", {}, function()
  328. local function test()
  329. local function proto()
  330. return true
  331. end
  332. end
  333. local proto = debug.getproto(test, 1, true)[1]
  334. local realproto = debug.getproto(test, 1)
  335. assert(proto, "Failed to get the inner function")
  336. assert(proto() == true, "The inner function did not return anything")
  337. if not realproto() then
  338. return "Proto return values are disabled on this executor"
  339. end
  340. end)
  341.  
  342. test("debug.getprotos", {}, function()
  343. local function test()
  344. local function _1()
  345. return true
  346. end
  347. local function _2()
  348. return true
  349. end
  350. local function _3()
  351. return true
  352. end
  353. end
  354. for i in ipairs(debug.getprotos(test)) do
  355. local proto = debug.getproto(test, i, true)[1]
  356. local realproto = debug.getproto(test, i)
  357. assert(proto(), "Failed to get inner function " .. i)
  358. if not realproto() then
  359. return "Proto return values are disabled on this executor"
  360. end
  361. end
  362. end)
  363.  
  364. test("debug.getstack", {}, function()
  365. local _ = "a" .. "b"
  366. assert(debug.getstack(1, 1) == "ab", "The first item in the stack should be 'ab'")
  367. assert(debug.getstack(1)[1] == "ab", "The first item in the stack table should be 'ab'")
  368. end)
  369.  
  370. test("debug.getupvalue", {}, function()
  371. local upvalue = function() end
  372. local function test()
  373. print(upvalue)
  374. end
  375. assert(debug.getupvalue(test, 1) == upvalue, "Unexpected value returned from debug.getupvalue")
  376. end)
  377.  
  378. test("debug.getupvalues", {}, function()
  379. local upvalue = function() end
  380. local function test()
  381. print(upvalue)
  382. end
  383. local upvalues = debug.getupvalues(test)
  384. assert(upvalues[1] == upvalue, "Unexpected value returned from debug.getupvalues")
  385. end)
  386.  
  387. test("debug.setconstant", {}, function()
  388. local function test()
  389. return "fail"
  390. end
  391. debug.setconstant(test, 1, "success")
  392. assert(test() == "success", "debug.setconstant did not set the first constant")
  393. end)
  394.  
  395. test("debug.setstack", {}, function()
  396. local function test()
  397. return "fail", debug.setstack(1, 1, "success")
  398. end
  399. assert(test() == "success", "debug.setstack did not set the first stack item")
  400. end)
  401.  
  402. test("debug.setupvalue", {}, function()
  403. local function upvalue()
  404. return "fail"
  405. end
  406. local function test()
  407. return upvalue()
  408. end
  409. debug.setupvalue(test, 1, function()
  410. return "success"
  411. end)
  412. assert(test() == "success", "debug.setupvalue did not set the first upvalue")
  413. end)
  414.  
  415. -- Filesystem
  416.  
  417. if isfolder and makefolder and delfolder then
  418. if isfolder(".tests") then
  419. delfolder(".tests")
  420. end
  421. makefolder(".tests")
  422. end
  423.  
  424. test("readfile", {}, function()
  425. writefile(".tests/readfile.txt", "success")
  426. assert(readfile(".tests/readfile.txt") == "success", "Did not return the contents of the file")
  427. end)
  428.  
  429. test("listfiles", {}, function()
  430. makefolder(".tests/listfiles")
  431. writefile(".tests/listfiles/test_1.txt", "success")
  432. writefile(".tests/listfiles/test_2.txt", "success")
  433. local files = listfiles(".tests/listfiles")
  434. assert(#files == 2, "Did not return the correct number of files")
  435. assert(isfile(files[1]), "Did not return a file path")
  436. assert(readfile(files[1]) == "success", "Did not return the correct files")
  437. makefolder(".tests/listfiles_2")
  438. makefolder(".tests/listfiles_2/test_1")
  439. makefolder(".tests/listfiles_2/test_2")
  440. local folders = listfiles(".tests/listfiles_2")
  441. assert(#folders == 2, "Did not return the correct number of folders")
  442. assert(isfolder(folders[1]), "Did not return a folder path")
  443. end)
  444.  
  445. test("writefile", {}, function()
  446. writefile(".tests/writefile.txt", "success")
  447. assert(readfile(".tests/writefile.txt") == "success", "Did not write the file")
  448. local requiresFileExt = pcall(function()
  449. writefile(".tests/writefile", "success")
  450. assert(isfile(".tests/writefile.txt"))
  451. end)
  452. if not requiresFileExt then
  453. return "This executor requires a file extension in writefile"
  454. end
  455. end)
  456.  
  457. test("makefolder", {}, function()
  458. makefolder(".tests/makefolder")
  459. assert(isfolder(".tests/makefolder"), "Did not create the folder")
  460. end)
  461.  
  462. test("appendfile", {}, function()
  463. writefile(".tests/appendfile.txt", "su")
  464. appendfile(".tests/appendfile.txt", "cce")
  465. appendfile(".tests/appendfile.txt", "ss")
  466. assert(readfile(".tests/appendfile.txt") == "success", "Did not append the file")
  467. end)
  468.  
  469. test("isfile", {}, function()
  470. writefile(".tests/isfile.txt", "success")
  471. assert(isfile(".tests/isfile.txt") == true, "Did not return true for a file")
  472. assert(isfile(".tests") == false, "Did not return false for a folder")
  473. assert(isfile(".tests/doesnotexist.exe") == false, "Did not return false for a nonexistent path (got " .. tostring(isfile(".tests/doesnotexist.exe")) .. ")")
  474. end)
  475.  
  476. test("isfolder", {}, function()
  477. assert(isfolder(".tests") == true, "Did not return false for a folder")
  478. assert(isfolder(".tests/doesnotexist.exe") == false, "Did not return false for a nonexistent path (got " .. tostring(isfolder(".tests/doesnotexist.exe")) .. ")")
  479. end)
  480.  
  481. test("delfolder", {}, function()
  482. makefolder(".tests/delfolder")
  483. delfolder(".tests/delfolder")
  484. assert(isfolder(".tests/delfolder") == false, "Failed to delete folder (isfolder = " .. tostring(isfolder(".tests/delfolder")) .. ")")
  485. end)
  486.  
  487. test("delfile", {}, function()
  488. writefile(".tests/delfile.txt", "Hello, world!")
  489. delfile(".tests/delfile.txt")
  490. assert(isfile(".tests/delfile.txt") == false, "Failed to delete file (isfile = " .. tostring(isfile(".tests/delfile.txt")) .. ")")
  491. end)
  492.  
  493. test("loadfile", {}, function()
  494. writefile(".tests/loadfile.txt", "return ... + 1")
  495. assert(assert(loadfile(".tests/loadfile.txt"))(1) == 2, "Failed to load a file with arguments")
  496. writefile(".tests/loadfile.txt", "f")
  497. local callback, err = loadfile(".tests/loadfile.txt")
  498. assert(err and not callback, "Did not return an error message for a compiler error")
  499. end)
  500.  
  501. test("dofile", {})
  502.  
  503. -- Input
  504.  
  505. test("isrbxactive", {"isgameactive"}, function()
  506. assert(type(isrbxactive()) == "boolean", "Did not return a boolean value")
  507. end)
  508.  
  509. test("mouse1click", {})
  510.  
  511. test("mouse1press", {})
  512.  
  513. test("mouse1release", {})
  514.  
  515. test("mouse2click", {})
  516.  
  517. test("mouse2press", {})
  518.  
  519. test("mouse2release", {})
  520.  
  521. test("mousemoveabs", {})
  522.  
  523. test("mousemoverel", {})
  524.  
  525. test("mousescroll", {})
  526.  
  527. -- Instances
  528.  
  529. test("fireclickdetector", {}, function()
  530. local detector = Instance.new("ClickDetector")
  531. fireclickdetector(detector, 50, "MouseHoverEnter")
  532. end)
  533.  
  534. test("getcallbackvalue", {}, function()
  535. local bindable = Instance.new("BindableFunction")
  536. local function test()
  537. end
  538. bindable.OnInvoke = test
  539. assert(getcallbackvalue(bindable, "OnInvoke") == test, "Did not return the correct value")
  540. end)
  541.  
  542. test("getconnections", {}, function()
  543. local types = {
  544. Enabled = "boolean",
  545. ForeignState = "boolean",
  546. LuaConnection = "boolean",
  547. Function = "function",
  548. Thread = "thread",
  549. Fire = "function",
  550. Defer = "function",
  551. Disconnect = "function",
  552. Disable = "function",
  553. Enable = "function",
  554. }
  555. local bindable = Instance.new("BindableEvent")
  556. bindable.Event:Connect(function() end)
  557. local connection = getconnections(bindable.Event)[1]
  558. for k, v in pairs(types) do
  559. assert(connection[k] ~= nil, "Did not return a table with a '" .. k .. "' field")
  560. assert(type(connection[k]) == v, "Did not return a table with " .. k .. " as a " .. v .. " (got " .. type(connection[k]) .. ")")
  561. end
  562. end)
  563.  
  564. test("getcustomasset", {}, function()
  565. writefile(".tests/getcustomasset.txt", "success")
  566. local contentId = getcustomasset(".tests/getcustomasset.txt")
  567. assert(type(contentId) == "string", "Did not return a string")
  568. assert(#contentId > 0, "Returned an empty string")
  569. assert(string.match(contentId, "rbxasset://") == "rbxasset://", "Did not return an rbxasset url")
  570. end)
  571.  
  572. test("gethiddenproperty", {}, function()
  573. local fire = Instance.new("Fire")
  574. local property, isHidden = gethiddenproperty(fire, "size_xml")
  575. assert(property == 5, "Did not return the correct value")
  576. assert(isHidden == true, "Did not return whether the property was hidden")
  577. end)
  578.  
  579. test("sethiddenproperty", {}, function()
  580. local fire = Instance.new("Fire")
  581. local hidden = sethiddenproperty(fire, "size_xml", 10)
  582. assert(hidden, "Did not return true for the hidden property")
  583. assert(gethiddenproperty(fire, "size_xml") == 10, "Did not set the hidden property")
  584. end)
  585.  
  586. test("gethui", {}, function()
  587. assert(typeof(gethui()) == "Instance", "Did not return an Instance")
  588. end)
  589.  
  590. test("getinstances", {}, function()
  591. assert(getinstances()[1]:IsA("Instance"), "The first value is not an Instance")
  592. end)
  593.  
  594. test("getnilinstances", {}, function()
  595. assert(getnilinstances()[1]:IsA("Instance"), "The first value is not an Instance")
  596. assert(getnilinstances()[1].Parent == nil, "The first value is not parented to nil")
  597. end)
  598.  
  599. test("isscriptable", {}, function()
  600. local fire = Instance.new("Fire")
  601. assert(isscriptable(fire, "size_xml") == false, "Did not return false for a non-scriptable property (size_xml)")
  602. assert(isscriptable(fire, "Size") == true, "Did not return true for a scriptable property (Size)")
  603. end)
  604.  
  605. test("setscriptable", {}, function()
  606. local fire = Instance.new("Fire")
  607. local wasScriptable = setscriptable(fire, "size_xml", true)
  608. assert(wasScriptable == false, "Did not return false for a non-scriptable property (size_xml)")
  609. assert(isscriptable(fire, "size_xml") == true, "Did not set the scriptable property")
  610. fire = Instance.new("Fire")
  611. assert(isscriptable(fire, "size_xml") == false, "⚠️⚠️ setscriptable persists between unique instances ⚠️⚠️")
  612. end)
  613.  
  614. test("setrbxclipboard", {})
  615.  
  616. -- Metatable
  617.  
  618. test("getrawmetatable", {}, function()
  619. local metatable = { __metatable = "Locked!" }
  620. local object = setmetatable({}, metatable)
  621. assert(getrawmetatable(object) == metatable, "Did not return the metatable")
  622. end)
  623.  
  624. test("hookmetamethod", {}, function()
  625. local object = setmetatable({}, { __index = newcclosure(function() return false end), __metatable = "Locked!" })
  626. local ref = hookmetamethod(object, "__index", function() return true end)
  627. assert(object.test == true, "Failed to hook a metamethod and change the return value")
  628. assert(ref() == false, "Did not return the original function")
  629. end)
  630.  
  631. test("getnamecallmethod", {}, function()
  632. local method
  633. local ref
  634. ref = hookmetamethod(game, "__namecall", function(...)
  635. if not method then
  636. method = getnamecallmethod()
  637. end
  638. return ref(...)
  639. end)
  640. game:GetService("Lighting")
  641. assert(method == "GetService", "Did not get the correct method (GetService)")
  642. end)
  643.  
  644. test("isreadonly", {}, function()
  645. local object = {}
  646. table.freeze(object)
  647. assert(isreadonly(object), "Did not return true for a read-only table")
  648. end)
  649.  
  650. test("setrawmetatable", {}, function()
  651. local object = setmetatable({}, { __index = function() return false end, __metatable = "Locked!" })
  652. local objectReturned = setrawmetatable(object, { __index = function() return true end })
  653. assert(object, "Did not return the original object")
  654. assert(object.test == true, "Failed to change the metatable")
  655. if objectReturned then
  656. return objectReturned == object and "Returned the original object" or "Did not return the original object"
  657. end
  658. end)
  659.  
  660. test("setreadonly", {}, function()
  661. local object = { success = false }
  662. table.freeze(object)
  663. setreadonly(object, false)
  664. object.success = true
  665. assert(object.success, "Did not allow the table to be modified")
  666. end)
  667.  
  668. -- Miscellaneous
  669.  
  670. test("identifyexecutor", {"getexecutorname"}, function()
  671. local name, version = identifyexecutor()
  672. assert(type(name) == "string", "Did not return a string for the name")
  673. return type(version) == "string" and "Returns version as a string" or "Does not return version"
  674. end)
  675.  
  676. test("lz4compress", {}, function()
  677. local raw = "Hello, world!"
  678. local compressed = lz4compress(raw)
  679. assert(type(compressed) == "string", "Compression did not return a string")
  680. assert(lz4decompress(compressed, #raw) == raw, "Decompression did not return the original string")
  681. end)
  682.  
  683. test("lz4decompress", {}, function()
  684. local raw = "Hello, world!"
  685. local compressed = lz4compress(raw)
  686. assert(type(compressed) == "string", "Compression did not return a string")
  687. assert(lz4decompress(compressed, #raw) == raw, "Decompression did not return the original string")
  688. end)
  689.  
  690. test("messagebox", {})
  691.  
  692. test("queue_on_teleport", {"queueonteleport"})
  693.  
  694. test("request", {"http.request", "http_request"}, function()
  695. local response = request({
  696. Url = "https://httpbin.org/user-agent",
  697. Method = "GET",
  698. })
  699. assert(type(response) == "table", "Response must be a table")
  700. assert(response.StatusCode == 200, "Did not return a 200 status code")
  701. local data = game:GetService("HttpService"):JSONDecode(response.Body)
  702. assert(type(data) == "table" and type(data["user-agent"]) == "string", "Did not return a table with a user-agent key")
  703. return "User-Agent: " .. data["user-agent"]
  704. end)
  705.  
  706. test("setclipboard", {"toclipboard"})
  707.  
  708. test("setfpscap", {}, function()
  709. local renderStepped = game:GetService("RunService").RenderStepped
  710. local function step()
  711. renderStepped:Wait()
  712. local sum = 0
  713. for _ = 1, 5 do
  714. sum += 1 / renderStepped:Wait()
  715. end
  716. return math.round(sum / 5)
  717. end
  718. setfpscap(60)
  719. local step60 = step()
  720. setfpscap(0)
  721. local step0 = step()
  722. return step60 .. "fps @60 • " .. step0 .. "fps @0"
  723. end)
  724.  
  725. -- Scripts
  726.  
  727. test("getgc", {}, function()
  728. local gc = getgc()
  729. assert(type(gc) == "table", "Did not return a table")
  730. assert(#gc > 0, "Did not return a table with any values")
  731. end)
  732.  
  733. test("getgenv", {}, function()
  734. getgenv().__TEST_GLOBAL = true
  735. assert(__TEST_GLOBAL, "Failed to set a global variable")
  736. getgenv().__TEST_GLOBAL = nil
  737. end)
  738.  
  739. test("getloadedmodules", {}, function()
  740. local modules = getloadedmodules()
  741. assert(type(modules) == "table", "Did not return a table")
  742. assert(#modules > 0, "Did not return a table with any values")
  743. assert(typeof(modules[1]) == "Instance", "First value is not an Instance")
  744. assert(modules[1]:IsA("ModuleScript"), "First value is not a ModuleScript")
  745. end)
  746.  
  747. test("getrenv", {}, function()
  748. assert(_G ~= getrenv()._G, "The variable _G in the executor is identical to _G in the game")
  749. end)
  750.  
  751. test("getrunningscripts", {}, function()
  752. local scripts = getrunningscripts()
  753. assert(type(scripts) == "table", "Did not return a table")
  754. assert(#scripts > 0, "Did not return a table with any values")
  755. assert(typeof(scripts[1]) == "Instance", "First value is not an Instance")
  756. assert(scripts[1]:IsA("ModuleScript") or scripts[1]:IsA("LocalScript"), "First value is not a ModuleScript or LocalScript")
  757. end)
  758.  
  759. test("getscriptbytecode", {"dumpstring"}, function()
  760. local animate = game:GetService("Players").LocalPlayer.Character.Animate
  761. local bytecode = getscriptbytecode(animate)
  762. assert(type(bytecode) == "string", "Did not return a string for Character.Animate (a " .. animate.ClassName .. ")")
  763. end)
  764.  
  765. test("getscripthash", {}, function()
  766. local animate = game:GetService("Players").LocalPlayer.Character.Animate:Clone()
  767. local hash = getscripthash(animate)
  768. local source = animate.Source
  769. animate.Source = "print('Hello, world!')"
  770. task.defer(function()
  771. animate.Source = source
  772. end)
  773. local newHash = getscripthash(animate)
  774. assert(hash ~= newHash, "Did not return a different hash for a modified script")
  775. assert(newHash == getscripthash(animate), "Did not return the same hash for a script with the same source")
  776. end)
  777.  
  778. test("getscripts", {}, function()
  779. local scripts = getscripts()
  780. assert(type(scripts) == "table", "Did not return a table")
  781. assert(#scripts > 0, "Did not return a table with any values")
  782. assert(typeof(scripts[1]) == "Instance", "First value is not an Instance")
  783. assert(scripts[1]:IsA("ModuleScript") or scripts[1]:IsA("LocalScript"), "First value is not a ModuleScript or LocalScript")
  784. end)
  785.  
  786. test("getsenv", {}, function()
  787. local animate = game:GetService("Players").LocalPlayer.Character.Animate
  788. local env = getsenv(animate)
  789. assert(type(env) == "table", "Did not return a table for Character.Animate (a " .. animate.ClassName .. ")")
  790. assert(env.script == animate, "The script global is not identical to Character.Animate")
  791. end)
  792.  
  793. test("getthreadidentity", {"getidentity", "getthreadcontext"}, function()
  794. assert(type(getthreadidentity()) == "number", "Did not return a number")
  795. end)
  796.  
  797. test("setthreadidentity", {"setidentity", "setthreadcontext"}, function()
  798. setthreadidentity(3)
  799. assert(getthreadidentity() == 3, "Did not set the thread identity")
  800. end)
  801.  
  802. -- Drawing
  803.  
  804. test("Drawing", {})
  805.  
  806. test("Drawing.new", {}, function()
  807. local drawing = Drawing.new("Square")
  808. drawing.Visible = false
  809. local canDestroy = pcall(function()
  810. drawing:Destroy()
  811. end)
  812. assert(canDestroy, "Drawing:Destroy() should not throw an error")
  813. end)
  814.  
  815. test("Drawing.Fonts", {}, function()
  816. assert(Drawing.Fonts.UI == 0, "Did not return the correct id for UI")
  817. assert(Drawing.Fonts.System == 1, "Did not return the correct id for System")
  818. assert(Drawing.Fonts.Plex == 2, "Did not return the correct id for Plex")
  819. assert(Drawing.Fonts.Monospace == 3, "Did not return the correct id for Monospace")
  820. end)
  821.  
  822. test("isrenderobj", {}, function()
  823. local drawing = Drawing.new("Image")
  824. drawing.Visible = true
  825. assert(isrenderobj(drawing) == true, "Did not return true for an Image")
  826. assert(isrenderobj(newproxy()) == false, "Did not return false for a blank table")
  827. end)
  828.  
  829. test("getrenderproperty", {}, function()
  830. local drawing = Drawing.new("Image")
  831. drawing.Visible = true
  832. assert(type(getrenderproperty(drawing, "Visible")) == "boolean", "Did not return a boolean value for Image.Visible")
  833. local success, result = pcall(function()
  834. return getrenderproperty(drawing, "Color")
  835. end)
  836. if not success or not result then
  837. return "Image.Color is not supported"
  838. end
  839. end)
  840.  
  841. test("setrenderproperty", {}, function()
  842. local drawing = Drawing.new("Square")
  843. drawing.Visible = true
  844. setrenderproperty(drawing, "Visible", false)
  845. assert(drawing.Visible == false, "Did not set the value for Square.Visible")
  846. end)
  847.  
  848. test("cleardrawcache", {}, function()
  849. cleardrawcache()
  850. end)
  851.  
  852. -- WebSocket
  853.  
  854. test("WebSocket", {})
  855.  
  856. test("WebSocket.connect", {}, function()
  857. local types = {
  858. Send = "function",
  859. Close = "function",
  860. OnMessage = {"table", "userdata"},
  861. OnClose = {"table", "userdata"},
  862. }
  863. local ws = WebSocket.connect("ws://echo.websocket.events")
  864. assert(type(ws) == "table" or type(ws) == "userdata", "Did not return a table or userdata")
  865. for k, v in pairs(types) do
  866. if type(v) == "table" then
  867. assert(table.find(v, type(ws[k])), "Did not return a " .. table.concat(v, ", ") .. " for " .. k .. " (a " .. type(ws[k]) .. ")")
  868. else
  869. assert(type(ws[k]) == v, "Did not return a " .. v .. " for " .. k .. " (a " .. type(ws[k]) .. ")")
  870. end
  871. end
  872. ws:Close()
  873. end)
Add Comment
Please, Sign In to add comment