Migrate tests to using new require builtins syntax and typedefs

This commit is contained in:
Filip Tibell 2023-05-14 22:16:58 +02:00
parent 0db32ad4c4
commit 80e47baded
No known key found for this signature in database
47 changed files with 129 additions and 14 deletions

View file

@ -4,6 +4,9 @@
local LINE_SEPARATOR = "\n" local LINE_SEPARATOR = "\n"
local COMMA_SEPARATOR = "," local COMMA_SEPARATOR = ","
local fs = require("@lune/fs")
local process = require("@lune/process")
local path = process.args[1] or ".lune/data/test.csv" local path = process.args[1] or ".lune/data/test.csv"
assert(path ~= nil and #path > 0, "No input file path was given") assert(path ~= nil and #path > 0, "No input file path was given")

View file

@ -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 EXAMPLE #1

View file

@ -1,24 +1,28 @@
--> A basic http server that echoes the given request --> A basic http server that echoes the given request
--> body at /ping and otherwise responds 404 "Not Found" --> 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 local PORT = if process.env.PORT ~= nil and #process.env.PORT > 0
then assert(tonumber(process.env.PORT), "Failed to parse port from env") then assert(tonumber(process.env.PORT), "Failed to parse port from env")
else 8080 else 8080
-- Create our responder functions -- 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}` return `Pong!\n{request.path}\n{request.body}`
end end
local function teapot(_request: NetRequest): NetResponse local function teapot(_request: net.ServeRequest): net.ServeResponse
return { return {
status = 418, status = 418,
body = "🫖", body = "🫖",
} }
end end
local function notFound(_request: NetRequest): NetResponse local function notFound(_request: net.ServeRequest): net.ServeResponse
return { return {
status = 404, status = 404,
body = "Not Found", body = "Not Found",

View file

@ -1,5 +1,9 @@
--> A basic web socket client that communicates with an echo server --> 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 local PORT = if process.env.PORT ~= nil and #process.env.PORT > 0
then assert(tonumber(process.env.PORT), "Failed to parse port from env") then assert(tonumber(process.env.PORT), "Failed to parse port from env")
else 8080 else 8080

View file

@ -1,5 +1,9 @@
--> A basic web socket server that echoes given messages --> 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 local PORT = if process.env.PORT ~= nil and #process.env.PORT > 0
then assert(tonumber(process.env.PORT), "Failed to parse port from env") then assert(tonumber(process.env.PORT), "Failed to parse port from env")
else 8080 else 8080

View file

@ -3,6 +3,15 @@
"luau-lsp.sourcemap.enabled": false, "luau-lsp.sourcemap.enabled": false,
"luau-lsp.types.roblox": false, "luau-lsp.types.roblox": false,
"luau-lsp.require.mode": "relativeToFile", "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 - ignore type defs file in docs dir and dev scripts we use
"luau-lsp.ignoreGlobs": [ "luau-lsp.ignoreGlobs": [
"docs/*.d.luau", "docs/*.d.luau",

View file

@ -1,3 +1,4 @@
-- TODO: Autogenerate this somehow ...
export type Instance = {} export type Instance = {}
--[=[ --[=[

View file

@ -1,3 +1,5 @@
local fs = require("@lune/fs")
-- Write two inner dirs in the bir dir, a parent and a child -- Write two inner dirs in the bir dir, a parent and a child
fs.writeDir("bin/test_dir/test_inner") fs.writeDir("bin/test_dir/test_inner")

View file

@ -1,3 +1,6 @@
local fs = require("@lune/fs")
local net = require("@lune/net")
-- Generate test data & make sure our bin dir exists -- Generate test data & make sure our bin dir exists
local binary = "" local binary = ""

View file

@ -1,3 +1,6 @@
local fs = require("@lune/fs")
local net = require("@lune/net")
-- Generate test data & make sure our bin dir exists -- Generate test data & make sure our bin dir exists
local binary = "" local binary = ""

View file

@ -1,3 +1,5 @@
local task = require("@lune/task")
-- Coroutines should return true, ret values OR false, error -- Coroutines should return true, ret values OR false, error
local function pass() local function pass()

View file

@ -1,3 +1,6 @@
local net = require("@lune/net")
local task = require("@lune/task")
local PORT = 9090 -- NOTE: This must be different from local PORT = 9090 -- NOTE: This must be different from
-- net tests to let them run in parallel with this file -- net tests to let them run in parallel with this file

View file

@ -1,3 +1,5 @@
local task = require("@lune/task")
local function f() end local function f() end
local thread1 = coroutine.create(f) local thread1 = coroutine.create(f)

View file

@ -1,3 +1,5 @@
local task = require("@lune/task")
local function f() end local function f() end
local thread1 = coroutine.create(f) local thread1 = coroutine.create(f)

View file

@ -1,3 +1,5 @@
local net = require("@lune/net")
local QUERY: { [string]: string } = { local QUERY: { [string]: string } = {
Key = "Value", Key = "Value",
Hello = "World", Hello = "World",

View file

@ -1,3 +1,6 @@
local net = require("@lune/net")
local stdio = require("@lune/stdio")
local util = {} local util = {}
function util.pass(method, url, message) function util.pass(method, url, message)

View file

@ -1,3 +1,7 @@
local net = require("@lune/net")
local task = require("@lune/task")
local process = require("@lune/process")
local PORT = 8080 local PORT = 8080
local URL = `http://127.0.0.1:{PORT}` local URL = `http://127.0.0.1:{PORT}`
local RESPONSE = "Hello, lune!" local RESPONSE = "Hello, lune!"

View file

@ -1,3 +1,7 @@
local net = require("@lune/net")
local task = require("@lune/task")
local process = require("@lune/process")
local PORT = 8081 local PORT = 8081
local URL = `http://127.0.0.1:{PORT}` local URL = `http://127.0.0.1:{PORT}`
local WS_URL = `ws://127.0.0.1:{PORT}` local WS_URL = `ws://127.0.0.1:{PORT}`

View file

@ -1,2 +1,4 @@
local net = require("@lune/net")
local decoded = net.urlDecode("%F0%9F%9A%80%20This%20string%20will%20be%20decoded.") local decoded = net.urlDecode("%F0%9F%9A%80%20This%20string%20will%20be%20decoded.")
assert(decoded == "🚀 This string will be decoded.") assert(decoded == "🚀 This string will be decoded.")

View file

@ -1,2 +1,4 @@
local net = require("@lune/net")
local encoded = net.urlEncode("🚀 This string will be encoded.") local encoded = net.urlEncode("🚀 This string will be encoded.")
assert(encoded == "%F0%9F%9A%80%20This%20string%20will%20be%20encoded.") assert(encoded == "%F0%9F%9A%80%20This%20string%20will%20be%20encoded.")

View file

@ -1,3 +1,5 @@
local process = require("@lune/process")
assert(#process.args > 0, "No process arguments found") assert(#process.args > 0, "No process arguments found")
assert(process.args[1] == "Foo", "Invalid first argument to process") assert(process.args[1] == "Foo", "Invalid first argument to process")

View file

@ -1,3 +1,5 @@
local process = require("@lune/process")
assert(process.cwd ~= nil, "Process cwd is missing") assert(process.cwd ~= nil, "Process cwd is missing")
assert(type(process.cwd) == "string", "Process cwd is not a string") assert(type(process.cwd) == "string", "Process cwd is not a string")

View file

@ -1,3 +1,5 @@
local process = require("@lune/process")
local randomKey = string.format("LUNE_TEST_%d", math.random(1, 999_999)) local randomKey = string.format("LUNE_TEST_%d", math.random(1, 999_999))
assert(process.env[randomKey] == nil, "Unset variable returned a non-nil value") assert(process.env[randomKey] == nil, "Unset variable returned a non-nil value")

View file

@ -1,3 +1,7 @@
local fs = require("@lune/fs")
local task = require("@lune/task")
local process = require("@lune/process")
local function assert(condition, err) local function assert(condition, err)
if not condition then if not condition then
task.spawn(error, err) task.spawn(error, err)

View file

@ -1,3 +1,6 @@
local task = require("@lune/task")
local process = require("@lune/process")
-- Spawning a child process should work with options -- Spawning a child process should work with options
local result = process.spawn("ls", { local result = process.spawn("ls", {

View file

@ -1,3 +1,5 @@
local task = require("@lune/task")
local module1 local module1
local module2 local module2

View file

@ -1,3 +1,5 @@
local task = require("@lune/task")
local module1 = require("./modules/async") local module1 = require("./modules/async")
local module2 = require("./modules/async") local module2 = require("./modules/async")

View file

@ -1,8 +1,8 @@
local fs = require("@lune/fs") :: typeof(fs) local fs = require("@lune/fs")
local net = require("@lune/net") :: typeof(net) local net = require("@lune/net")
local process = require("@lune/process") :: typeof(process) local process = require("@lune/process")
local stdio = require("@lune/stdio") :: typeof(stdio) local stdio = require("@lune/stdio")
local task = require("@lune/task") :: typeof(task) local task = require("@lune/task")
assert(type(fs.move) == "function") assert(type(fs.move) == "function")
assert(type(net.request) == "function") assert(type(net.request) == "function")

View file

@ -1,3 +1,5 @@
local task = require("@lune/task")
task.wait(0.25) task.wait(0.25)
return { return {

View file

@ -1,4 +1,4 @@
local fs = require("@lune/fs") :: any local fs = require("@lune/fs")
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox") :: any
local modelDirs = {} local modelDirs = {}

View file

@ -1,4 +1,4 @@
local fs = require("@lune/fs") :: any local fs = require("@lune/fs")
local roblox = require("@lune/roblox") :: any local roblox = require("@lune/roblox") :: any
local placeDirs = {} local placeDirs = {}

View file

@ -1,3 +1,6 @@
local net = require("@lune/net")
local serde = require("@lune/serde")
type Response = { type Response = {
products: { products: {
{ {
@ -24,7 +27,7 @@ local response = net.request("https://dummyjson.com/products")
assert(response.ok, "Dummy JSON api returned an error") assert(response.ok, "Dummy JSON api returned an error")
assert(#response.body > 0, "Dummy JSON api returned empty body") 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.limit) == "number", "Products limit was not a number")
assert(type(data.products) == "table", "Products was not a table") assert(type(data.products) == "table", "Products was not a table")

View file

@ -1,4 +1,4 @@
local serde = require("@lune/serde") :: any local serde = require("@lune/serde")
local source = require("./source") local source = require("./source")
local decoded = serde.decode("json", source.pretty) local decoded = serde.decode("json", source.pretty)

View file

@ -1,4 +1,4 @@
local serde = require("@lune/serde") :: any local serde = require("@lune/serde")
local source = require("./source") local source = require("./source")
local toml = serde.decode("toml", source.encoded) local toml = serde.decode("toml", source.encoded)

View file

@ -1,4 +1,4 @@
local serde = require("@lune/serde") :: any local serde = require("@lune/serde")
local source = require("./source") local source = require("./source")
local str = serde.encode("toml", source.decoded) local str = serde.encode("toml", source.decoded)

View file

@ -1,3 +1,5 @@
local stdio = require("@lune/stdio")
local COLORS_VALID = local COLORS_VALID =
{ "reset", "black", "red", "green", "yellow", "blue", "purple", "cyan", "white" } { "reset", "black", "red", "green", "yellow", "blue", "purple", "cyan", "white" }
local COLORS_INVALID = { "", "gray", "grass", "red?", "super red", " ", "none" } local COLORS_INVALID = { "", "gray", "grass", "red?", "super red", " ", "none" }

View file

@ -1,3 +1,6 @@
local stdio = require("@lune/stdio")
local process = require("@lune/process")
stdio.ewrite("Hello, stderr!") stdio.ewrite("Hello, stderr!")
process.exit(0) process.exit(0)

View file

@ -1,3 +1,5 @@
local stdio = require("@lune/stdio")
assert( assert(
stdio.format("Hello", "world", "!") == "Hello world !", stdio.format("Hello", "world", "!") == "Hello world !",
"Format should add a single space between arguments" "Format should add a single space between arguments"

View file

@ -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 -- NOTE: This test is intentionally not included in the
-- automated tests suite since it requires user input -- automated tests suite since it requires user input

View file

@ -1,3 +1,5 @@
local stdio = require("@lune/stdio")
local STYLES_VALID = { "reset", "bold", "dim" } local STYLES_VALID = { "reset", "bold", "dim" }
local STYLES_INVALID = { "", "*bold*", "dimm", "megabright", "cheerful", "sad", " " } local STYLES_INVALID = { "", "*bold*", "dimm", "megabright", "cheerful", "sad", " " }

View file

@ -1 +1,3 @@
local stdio = require("@lune/stdio")
stdio.write("Hello, stdout!") stdio.write("Hello, stdout!")

View file

@ -1,3 +1,5 @@
local task = require("@lune/task")
-- Cancel should cancel any deferred or delayed threads -- Cancel should cancel any deferred or delayed threads
local flag: boolean = false local flag: boolean = false

View file

@ -1,3 +1,5 @@
local task = require("@lune/task")
-- Deferring a task should return the thread that can then be cancelled -- Deferring a task should return the thread that can then be cancelled
local thread = task.defer(function() end) local thread = task.defer(function() end)

View file

@ -1,3 +1,5 @@
local task = require("@lune/task")
-- Delaying a task should return the thread that can then be cancelled -- Delaying a task should return the thread that can then be cancelled
local thread = task.delay(0, function() end) local thread = task.delay(0, function() end)

View file

@ -1,3 +1,5 @@
local stdio = require("@lune/stdio")
return function(index: number, type: string, value: any) return function(index: number, type: string, value: any)
if typeof(value) ~= type then if typeof(value) ~= type then
error( error(

View file

@ -1,3 +1,5 @@
local task = require("@lune/task")
-- Spawning a task should return the thread that can then be cancelled -- Spawning a task should return the thread that can then be cancelled
local thread = task.spawn(function() end) local thread = task.spawn(function() end)

View file

@ -1,3 +1,6 @@
local task = require("@lune/task")
local stdio = require("@lune/stdio")
-- Wait should be accurate down to at least 10ms -- Wait should be accurate down to at least 10ms
local EPSILON = 10 / 1_000 local EPSILON = 10 / 1_000