From 46b79494223d33aac8b8fa1544c6e72af9c086b5 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Wed, 27 Mar 2024 18:13:03 +0530 Subject: [PATCH] chore(tests): include test runner powered by lune --- .lune/tests.lua | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + src/index.ts | 2 -- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 .lune/tests.lua diff --git a/.lune/tests.lua b/.lune/tests.lua new file mode 100644 index 0000000..f24d637 --- /dev/null +++ b/.lune/tests.lua @@ -0,0 +1,57 @@ +local process = require("@lune/process") +local fs = require("@lune/fs") +local stdio = require("@lune/stdio") + +local OK = stdio.color("green") + .. stdio.style("bold") + .. " OK" + .. stdio.style("reset") + .. stdio.color("reset") + .. "\n" + .. "" +local FAILED = stdio.color("red") + .. stdio.style("bold") + .. " FAILED" + .. stdio.style("reset") + .. stdio.color("reset") + .. "\n" + +-- Adapted from https://github.com/4x8Matrix/Package-Index/blob/Master/.lune/type-check.luau#L10 +local function execute(exe, ...): (boolean, string, string) + local res = process.spawn(exe, { ... }, { + stdio = "default", + }) + + return res.ok, res.stdout, res.stderr +end + +function main() + local results = { + passed = 0, + failed = 0, + } + + for _, test in fs.readDir("tests/") do + stdio.write(`Running wg::{test:gsub(".luau", "")}...`) + + local ok, _out, err = execute("lune", "run", "tests/" .. test) + + if ok then + stdio.write(OK) + results.passed += 1 + else + stdio.write(FAILED) + print(err:split("\n")[1]) + + results.failed += 1 + end + end + + print(`\nResults: passed: {results.passed}; failed: {results.failed}`) + + if results.failed > 0 then + process.exit(1) + end +end + +return main() diff --git a/package.json b/package.json index 6249c6c..6cee6ed 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "check_fmt": "prettier -c src/", "check": "pnpm lint && pnpm check_fmt", "fmt": "prettier -w src/", + "test": "lune run tests", "postinstall": "patch -f node_modules/@rbxts/types/include/roblox.d.ts < lune_require_patch.diff", "prepublishOnly": "pnpm run build" }, diff --git a/src/index.ts b/src/index.ts index d84a789..f13e880 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,8 +19,6 @@ export const wireguard: Wireguard = { const privateKey = generatePrivateKey(); const publicKey = generatePublicKey(privateKey); - print(privateKey); - return { publicKey: atob(publicKey), privateKey: atob(privateKey),