mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 04:50:36 +00:00
Migrate tests to using new require builtins syntax and typedefs
This commit is contained in:
parent
0db32ad4c4
commit
80e47baded
47 changed files with 129 additions and 14 deletions
|
@ -4,6 +4,9 @@
|
|||
local LINE_SEPARATOR = "\n"
|
||||
local COMMA_SEPARATOR = ","
|
||||
|
||||
local fs = require("@lune/fs")
|
||||
local process = require("@lune/process")
|
||||
|
||||
local path = process.args[1] or ".lune/data/test.csv"
|
||||
|
||||
assert(path ~= nil and #path > 0, "No input file path was given")
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
local fs = require("@lune/fs")
|
||||
local net = require("@lune/net")
|
||||
local process = require("@lune/process")
|
||||
local stdio = require("@lune/stdio")
|
||||
local task = require("@lune/task")
|
||||
|
||||
--[[
|
||||
EXAMPLE #1
|
||||
|
||||
|
|
|
@ -1,24 +1,28 @@
|
|||
--> A basic http server that echoes the given request
|
||||
--> body at /ping and otherwise responds 404 "Not Found"
|
||||
|
||||
local net = require("@lune/net")
|
||||
local process = require("@lune/process")
|
||||
local task = require("@lune/task")
|
||||
|
||||
local PORT = if process.env.PORT ~= nil and #process.env.PORT > 0
|
||||
then assert(tonumber(process.env.PORT), "Failed to parse port from env")
|
||||
else 8080
|
||||
|
||||
-- Create our responder functions
|
||||
|
||||
local function pong(request: NetRequest): string
|
||||
local function pong(request: net.ServeRequest): string
|
||||
return `Pong!\n{request.path}\n{request.body}`
|
||||
end
|
||||
|
||||
local function teapot(_request: NetRequest): NetResponse
|
||||
local function teapot(_request: net.ServeRequest): net.ServeResponse
|
||||
return {
|
||||
status = 418,
|
||||
body = "🫖",
|
||||
}
|
||||
end
|
||||
|
||||
local function notFound(_request: NetRequest): NetResponse
|
||||
local function notFound(_request: net.ServeRequest): net.ServeResponse
|
||||
return {
|
||||
status = 404,
|
||||
body = "Not Found",
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
--> A basic web socket client that communicates with an echo server
|
||||
|
||||
local net = require("@lune/net")
|
||||
local process = require("@lune/process")
|
||||
local task = require("@lune/task")
|
||||
|
||||
local PORT = if process.env.PORT ~= nil and #process.env.PORT > 0
|
||||
then assert(tonumber(process.env.PORT), "Failed to parse port from env")
|
||||
else 8080
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
--> A basic web socket server that echoes given messages
|
||||
|
||||
local net = require("@lune/net")
|
||||
local process = require("@lune/process")
|
||||
local task = require("@lune/task")
|
||||
|
||||
local PORT = if process.env.PORT ~= nil and #process.env.PORT > 0
|
||||
then assert(tonumber(process.env.PORT), "Failed to parse port from env")
|
||||
else 8080
|
||||
|
|
9
.vscode/settings.json
vendored
9
.vscode/settings.json
vendored
|
@ -3,6 +3,15 @@
|
|||
"luau-lsp.sourcemap.enabled": false,
|
||||
"luau-lsp.types.roblox": false,
|
||||
"luau-lsp.require.mode": "relativeToFile",
|
||||
"luau-lsp.require.fileAliases": {
|
||||
"@lune/fs": "./docs/typedefs/FS.luau",
|
||||
"@lune/net": "./docs/typedefs/Net.luau",
|
||||
"@lune/process": "./docs/typedefs/Process.luau",
|
||||
"@lune/roblox": "./docs/typedefs/Roblox.luau",
|
||||
"@lune/serde": "./docs/typedefs/Serde.luau",
|
||||
"@lune/stdio": "./docs/typedefs/Stdio.luau",
|
||||
"@lune/task": "./docs/typedefs/Task.luau"
|
||||
},
|
||||
// Luau - ignore type defs file in docs dir and dev scripts we use
|
||||
"luau-lsp.ignoreGlobs": [
|
||||
"docs/*.d.luau",
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
-- TODO: Autogenerate this somehow ...
|
||||
export type Instance = {}
|
||||
|
||||
--[=[
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local fs = require("@lune/fs")
|
||||
|
||||
-- Write two inner dirs in the bir dir, a parent and a child
|
||||
|
||||
fs.writeDir("bin/test_dir/test_inner")
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
local fs = require("@lune/fs")
|
||||
local net = require("@lune/net")
|
||||
|
||||
-- Generate test data & make sure our bin dir exists
|
||||
|
||||
local binary = ""
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
local fs = require("@lune/fs")
|
||||
local net = require("@lune/net")
|
||||
|
||||
-- Generate test data & make sure our bin dir exists
|
||||
|
||||
local binary = ""
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local task = require("@lune/task")
|
||||
|
||||
-- Coroutines should return true, ret values OR false, error
|
||||
|
||||
local function pass()
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
local net = require("@lune/net")
|
||||
local task = require("@lune/task")
|
||||
|
||||
local PORT = 9090 -- NOTE: This must be different from
|
||||
-- net tests to let them run in parallel with this file
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local task = require("@lune/task")
|
||||
|
||||
local function f() end
|
||||
|
||||
local thread1 = coroutine.create(f)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local task = require("@lune/task")
|
||||
|
||||
local function f() end
|
||||
|
||||
local thread1 = coroutine.create(f)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local net = require("@lune/net")
|
||||
|
||||
local QUERY: { [string]: string } = {
|
||||
Key = "Value",
|
||||
Hello = "World",
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
local net = require("@lune/net")
|
||||
local stdio = require("@lune/stdio")
|
||||
|
||||
local util = {}
|
||||
|
||||
function util.pass(method, url, message)
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
local net = require("@lune/net")
|
||||
local task = require("@lune/task")
|
||||
local process = require("@lune/process")
|
||||
|
||||
local PORT = 8080
|
||||
local URL = `http://127.0.0.1:{PORT}`
|
||||
local RESPONSE = "Hello, lune!"
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
local net = require("@lune/net")
|
||||
local task = require("@lune/task")
|
||||
local process = require("@lune/process")
|
||||
|
||||
local PORT = 8081
|
||||
local URL = `http://127.0.0.1:{PORT}`
|
||||
local WS_URL = `ws://127.0.0.1:{PORT}`
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
local net = require("@lune/net")
|
||||
|
||||
local decoded = net.urlDecode("%F0%9F%9A%80%20This%20string%20will%20be%20decoded.")
|
||||
assert(decoded == "🚀 This string will be decoded.")
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
local net = require("@lune/net")
|
||||
|
||||
local encoded = net.urlEncode("🚀 This string will be encoded.")
|
||||
assert(encoded == "%F0%9F%9A%80%20This%20string%20will%20be%20encoded.")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local process = require("@lune/process")
|
||||
|
||||
assert(#process.args > 0, "No process arguments found")
|
||||
|
||||
assert(process.args[1] == "Foo", "Invalid first argument to process")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local process = require("@lune/process")
|
||||
|
||||
assert(process.cwd ~= nil, "Process cwd is missing")
|
||||
|
||||
assert(type(process.cwd) == "string", "Process cwd is not a string")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local process = require("@lune/process")
|
||||
|
||||
local randomKey = string.format("LUNE_TEST_%d", math.random(1, 999_999))
|
||||
|
||||
assert(process.env[randomKey] == nil, "Unset variable returned a non-nil value")
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
local fs = require("@lune/fs")
|
||||
local task = require("@lune/task")
|
||||
local process = require("@lune/process")
|
||||
|
||||
local function assert(condition, err)
|
||||
if not condition then
|
||||
task.spawn(error, err)
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
local task = require("@lune/task")
|
||||
local process = require("@lune/process")
|
||||
|
||||
-- Spawning a child process should work with options
|
||||
|
||||
local result = process.spawn("ls", {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local task = require("@lune/task")
|
||||
|
||||
local module1
|
||||
local module2
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local task = require("@lune/task")
|
||||
|
||||
local module1 = require("./modules/async")
|
||||
local module2 = require("./modules/async")
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
local fs = require("@lune/fs") :: typeof(fs)
|
||||
local net = require("@lune/net") :: typeof(net)
|
||||
local process = require("@lune/process") :: typeof(process)
|
||||
local stdio = require("@lune/stdio") :: typeof(stdio)
|
||||
local task = require("@lune/task") :: typeof(task)
|
||||
local fs = require("@lune/fs")
|
||||
local net = require("@lune/net")
|
||||
local process = require("@lune/process")
|
||||
local stdio = require("@lune/stdio")
|
||||
local task = require("@lune/task")
|
||||
|
||||
assert(type(fs.move) == "function")
|
||||
assert(type(net.request) == "function")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local task = require("@lune/task")
|
||||
|
||||
task.wait(0.25)
|
||||
|
||||
return {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local fs = require("@lune/fs") :: any
|
||||
local fs = require("@lune/fs")
|
||||
local roblox = require("@lune/roblox") :: any
|
||||
|
||||
local modelDirs = {}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local fs = require("@lune/fs") :: any
|
||||
local fs = require("@lune/fs")
|
||||
local roblox = require("@lune/roblox") :: any
|
||||
|
||||
local placeDirs = {}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
local net = require("@lune/net")
|
||||
local serde = require("@lune/serde")
|
||||
|
||||
type Response = {
|
||||
products: {
|
||||
{
|
||||
|
@ -24,7 +27,7 @@ local response = net.request("https://dummyjson.com/products")
|
|||
assert(response.ok, "Dummy JSON api returned an error")
|
||||
assert(#response.body > 0, "Dummy JSON api returned empty body")
|
||||
|
||||
local data: Response = net.jsonDecode(response.body)
|
||||
local data: Response = serde.decode("json", response.body)
|
||||
|
||||
assert(type(data.limit) == "number", "Products limit was not a number")
|
||||
assert(type(data.products) == "table", "Products was not a table")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local serde = require("@lune/serde") :: any
|
||||
local serde = require("@lune/serde")
|
||||
local source = require("./source")
|
||||
|
||||
local decoded = serde.decode("json", source.pretty)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local serde = require("@lune/serde") :: any
|
||||
local serde = require("@lune/serde")
|
||||
local source = require("./source")
|
||||
|
||||
local toml = serde.decode("toml", source.encoded)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local serde = require("@lune/serde") :: any
|
||||
local serde = require("@lune/serde")
|
||||
local source = require("./source")
|
||||
|
||||
local str = serde.encode("toml", source.decoded)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local stdio = require("@lune/stdio")
|
||||
|
||||
local COLORS_VALID =
|
||||
{ "reset", "black", "red", "green", "yellow", "blue", "purple", "cyan", "white" }
|
||||
local COLORS_INVALID = { "", "gray", "grass", "red?", "super red", " ", "none" }
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
local stdio = require("@lune/stdio")
|
||||
local process = require("@lune/process")
|
||||
|
||||
stdio.ewrite("Hello, stderr!")
|
||||
|
||||
process.exit(0)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local stdio = require("@lune/stdio")
|
||||
|
||||
assert(
|
||||
stdio.format("Hello", "world", "!") == "Hello world !",
|
||||
"Format should add a single space between arguments"
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
local task = require("@lune/task")
|
||||
local stdio = require("@lune/stdio")
|
||||
local process = require("@lune/process")
|
||||
|
||||
-- NOTE: This test is intentionally not included in the
|
||||
-- automated tests suite since it requires user input
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local stdio = require("@lune/stdio")
|
||||
|
||||
local STYLES_VALID = { "reset", "bold", "dim" }
|
||||
local STYLES_INVALID = { "", "*bold*", "dimm", "megabright", "cheerful", "sad", " " }
|
||||
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
local stdio = require("@lune/stdio")
|
||||
|
||||
stdio.write("Hello, stdout!")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local task = require("@lune/task")
|
||||
|
||||
-- Cancel should cancel any deferred or delayed threads
|
||||
|
||||
local flag: boolean = false
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local task = require("@lune/task")
|
||||
|
||||
-- Deferring a task should return the thread that can then be cancelled
|
||||
|
||||
local thread = task.defer(function() end)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local task = require("@lune/task")
|
||||
|
||||
-- Delaying a task should return the thread that can then be cancelled
|
||||
|
||||
local thread = task.delay(0, function() end)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local stdio = require("@lune/stdio")
|
||||
|
||||
return function(index: number, type: string, value: any)
|
||||
if typeof(value) ~= type then
|
||||
error(
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
local task = require("@lune/task")
|
||||
|
||||
-- Spawning a task should return the thread that can then be cancelled
|
||||
|
||||
local thread = task.spawn(function() end)
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
local task = require("@lune/task")
|
||||
local stdio = require("@lune/stdio")
|
||||
|
||||
-- Wait should be accurate down to at least 10ms
|
||||
|
||||
local EPSILON = 10 / 1_000
|
||||
|
|
Loading…
Reference in a new issue