NoTextForSpeech

unc fixed for incognito

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