From aec7f820ca3880fc0a6b204666068ecdd8f5bcb5 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Sun, 5 Feb 2023 19:13:58 -0500 Subject: [PATCH] Migrate to using cargo workspaces --- .github/workflows/ci.yaml | 6 +-- .github/workflows/publish.yaml | 1 + .github/workflows/release.yaml | 42 ++++++------------- CHANGELOG.md | 4 ++ Cargo.lock | 32 +++++++++----- Cargo.toml | 28 ++++--------- packages/cli/Cargo.toml | 29 +++++++++++++ {src/cli => packages/cli/src}/cli.rs | 2 +- {src/cli => packages/cli/src}/gen/doc.rs | 0 {src/cli => packages/cli/src}/gen/mod.rs | 0 {src/cli => packages/cli/src}/gen/tag.rs | 0 {src/cli => packages/cli/src}/gen/visitor.rs | 0 {src/cli => packages/cli/src}/main.rs | 1 + {src/cli => packages/cli/src}/utils/files.rs | 0 {src/cli => packages/cli/src}/utils/github.rs | 0 .../cli => packages/cli/src}/utils/listing.rs | 0 {src/cli => packages/cli/src}/utils/mod.rs | 0 packages/lib/Cargo.toml | 29 +++++++++++++ .../lib/src}/globals/console.rs | 0 {src/lib => packages/lib/src}/globals/fs.rs | 0 {src/lib => packages/lib/src}/globals/mod.rs | 0 {src/lib => packages/lib/src}/globals/net.rs | 0 .../lib/src}/globals/process.rs | 0 .../lib/src}/globals/require.rs | 0 {src/lib => packages/lib/src}/globals/task.rs | 0 {src/lib => packages/lib/src}/lib.rs | 33 +++++++++------ .../lib/src}/utils/formatting.rs | 4 +- {src/lib => packages/lib/src}/utils/mod.rs | 0 {src/lib => packages/lib/src}/utils/net.rs | 0 .../lib => packages/lib/src}/utils/process.rs | 0 {src/lib => packages/lib/src}/utils/table.rs | 0 {src/lib => packages/lib/src}/utils/task.rs | 0 src/tests/process/exit.luau | 14 ------- {src/tests => tests}/console/format.luau | 0 {src/tests => tests}/console/set_color.luau | 0 {src/tests => tests}/console/set_style.luau | 0 {src/tests => tests}/fs/dirs.luau | 0 {src/tests => tests}/fs/files.luau | 0 {src/tests => tests}/net/json/decode.luau | 0 {src/tests => tests}/net/json/encode.luau | 0 {src/tests => tests}/net/request/codes.luau | 0 {src/tests => tests}/net/request/methods.luau | 0 .../tests => tests}/net/request/redirect.luau | 0 {src/tests => tests}/net/request/util.luau | 0 {src/tests => tests}/net/serve.luau | 0 {src/tests => tests}/process/args.luau | 0 {src/tests => tests}/process/cwd.luau | 0 {src/tests => tests}/process/env.luau | 0 tests/process/exit.luau | 14 +++++++ {src/tests => tests}/process/spawn.luau | 0 .../require/modules/module.luau | 0 .../require/tests/children.luau | 0 .../require/tests/invalid.luau | 0 .../tests => tests}/require/tests/module.luau | 0 .../require/tests/modules/module.luau | 0 .../require/tests/modules/modules/module.luau | 0 .../require/tests/modules/nested.luau | 0 .../tests => tests}/require/tests/nested.luau | 0 .../require/tests/parents.luau | 0 .../require/tests/siblings.luau | 0 {src/tests => tests}/task/cancel.luau | 0 {src/tests => tests}/task/defer.luau | 0 {src/tests => tests}/task/delay.luau | 0 {src/tests => tests}/task/fcheck.luau | 0 {src/tests => tests}/task/spawn.luau | 0 {src/tests => tests}/task/wait.luau | 0 66 files changed, 148 insertions(+), 91 deletions(-) create mode 100644 packages/cli/Cargo.toml rename {src/cli => packages/cli/src}/cli.rs (99%) rename {src/cli => packages/cli/src}/gen/doc.rs (100%) rename {src/cli => packages/cli/src}/gen/mod.rs (100%) rename {src/cli => packages/cli/src}/gen/tag.rs (100%) rename {src/cli => packages/cli/src}/gen/visitor.rs (100%) rename {src/cli => packages/cli/src}/main.rs (92%) rename {src/cli => packages/cli/src}/utils/files.rs (100%) rename {src/cli => packages/cli/src}/utils/github.rs (100%) rename {src/cli => packages/cli/src}/utils/listing.rs (100%) rename {src/cli => packages/cli/src}/utils/mod.rs (100%) create mode 100644 packages/lib/Cargo.toml rename {src/lib => packages/lib/src}/globals/console.rs (100%) rename {src/lib => packages/lib/src}/globals/fs.rs (100%) rename {src/lib => packages/lib/src}/globals/mod.rs (100%) rename {src/lib => packages/lib/src}/globals/net.rs (100%) rename {src/lib => packages/lib/src}/globals/process.rs (100%) rename {src/lib => packages/lib/src}/globals/require.rs (100%) rename {src/lib => packages/lib/src}/globals/task.rs (100%) rename {src/lib => packages/lib/src}/lib.rs (87%) rename {src/lib => packages/lib/src}/utils/formatting.rs (99%) rename {src/lib => packages/lib/src}/utils/mod.rs (100%) rename {src/lib => packages/lib/src}/utils/net.rs (100%) rename {src/lib => packages/lib/src}/utils/process.rs (100%) rename {src/lib => packages/lib/src}/utils/table.rs (100%) rename {src/lib => packages/lib/src}/utils/task.rs (100%) delete mode 100644 src/tests/process/exit.luau rename {src/tests => tests}/console/format.luau (100%) rename {src/tests => tests}/console/set_color.luau (100%) rename {src/tests => tests}/console/set_style.luau (100%) rename {src/tests => tests}/fs/dirs.luau (100%) rename {src/tests => tests}/fs/files.luau (100%) rename {src/tests => tests}/net/json/decode.luau (100%) rename {src/tests => tests}/net/json/encode.luau (100%) rename {src/tests => tests}/net/request/codes.luau (100%) rename {src/tests => tests}/net/request/methods.luau (100%) rename {src/tests => tests}/net/request/redirect.luau (100%) rename {src/tests => tests}/net/request/util.luau (100%) rename {src/tests => tests}/net/serve.luau (100%) rename {src/tests => tests}/process/args.luau (100%) rename {src/tests => tests}/process/cwd.luau (100%) rename {src/tests => tests}/process/env.luau (100%) create mode 100644 tests/process/exit.luau rename {src/tests => tests}/process/spawn.luau (100%) rename {src/tests => tests}/require/modules/module.luau (100%) rename {src/tests => tests}/require/tests/children.luau (100%) rename {src/tests => tests}/require/tests/invalid.luau (100%) rename {src/tests => tests}/require/tests/module.luau (100%) rename {src/tests => tests}/require/tests/modules/module.luau (100%) rename {src/tests => tests}/require/tests/modules/modules/module.luau (100%) rename {src/tests => tests}/require/tests/modules/nested.luau (100%) rename {src/tests => tests}/require/tests/nested.luau (100%) rename {src/tests => tests}/require/tests/parents.luau (100%) rename {src/tests => tests}/require/tests/siblings.luau (100%) rename {src/tests => tests}/task/cancel.luau (100%) rename {src/tests => tests}/task/defer.luau (100%) rename {src/tests => tests}/task/delay.luau (100%) rename {src/tests => tests}/task/fcheck.luau (100%) rename {src/tests => tests}/task/spawn.luau (100%) rename {src/tests => tests}/task/wait.luau (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8260b6b..bd04c77 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,13 +23,13 @@ jobs: run: cargo fmt -- --check - name: Build - run: cargo build --locked --verbose + run: cargo build --locked - name: Clippy run: cargo clippy - name: Test - Lune - run: cargo test --lib + run: cargo test --package lune - name: Test - CLI - run: cargo test --bin lune + run: cargo test --package lune-cli diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 333a5e3..2bf6fc7 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -24,5 +24,6 @@ jobs: - name: Publish to crates.io uses: katyo/publish-crates@v1 with: + path: "packages/lib" registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} ignore-unpublished-changes: true diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7eee2bf..ec8ca58 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,23 +7,16 @@ permissions: contents: write jobs: - init: - name: Init + create-release: + name: Create release runs-on: ubuntu-latest outputs: - manifest_name: ${{ steps.get_name.outputs.value }} manifest_version: ${{ steps.get_version.outputs.value }} + upload_url: ${{ steps.create_release.outputs.upload_url }} steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Get name from manifest - uses: SebRollen/toml-action@0ad94c4a52c402aaa76e14e8a43551163b6cedf9 - id: get_name - with: - file: Cargo.toml - field: package.name - - name: Get version from manifest uses: SebRollen/toml-action@0ad94c4a52c402aaa76e14e8a43551163b6cedf9 id: get_version @@ -31,28 +24,18 @@ jobs: file: Cargo.toml field: package.version - create-release: - needs: ["init"] - name: Create release - runs-on: ubuntu-latest - outputs: - upload_url: ${{ steps.create_release.outputs.upload_url }} - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Create release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: v${{ needs.init.outputs.manifest_version }} - release_name: ${{ needs.init.outputs.manifest_version }} + tag_name: v${{ steps.get_version.outputs.value }} + release_name: ${{ steps.get_version.outputs.value }} draft: true upload-assets: - needs: ["init", "create-release"] + needs: ["create-release"] name: Upload assets runs-on: ubuntu-latest steps: @@ -96,15 +79,15 @@ jobs: include: - name: Windows x86_64 runner-os: windows-latest - artifact-name: ${{ needs.init.outputs.manifest_name }}-${{ needs.init.outputs.manifest_version }}-windows-x86_64 + artifact-name: lune-${{ needs.create-release.outputs.manifest_version }}-windows-x86_64 cargo-target: x86_64-pc-windows-msvc - name: Linux x86_64 runner-os: ubuntu-latest - artifact-name: ${{ needs.init.outputs.manifest_name }}-${{ needs.init.outputs.manifest_version }}-linux-x86_64 + artifact-name: lune-${{ needs.create-release.outputs.manifest_version }}-linux-x86_64 cargo-target: x86_64-unknown-linux-gnu - name: macOS x86_64 runner-os: macos-latest - artifact-name: ${{ needs.init.outputs.manifest_name }}-${{ needs.init.outputs.manifest_version }}-macos-x86_64 + artifact-name: lune-${{ needs.create-release.outputs.manifest_version }}-macos-x86_64 cargo-target: x86_64-apple-darwin name: Build - ${{ matrix.name }} @@ -122,21 +105,20 @@ jobs: profile: minimal - name: Build binary - run: cargo build --locked --release --all-features --target ${{ matrix.cargo-target }} + run: cargo build --package lune-cli --locked --release --all-features --target ${{ matrix.cargo-target }} env: CARGO_TARGET_DIR: output - OPENSSL_STATIC: 1 - name: Create binary archive shell: bash run: | mkdir -p staging if [ "${{ matrix.runner-os }}" = "windows-latest" ]; then - cp "output/${{ matrix.cargo-target }}/release/${{ needs.init.outputs.manifest_name }}.exe" staging/ + cp "output/${{ matrix.cargo-target }}/release/lune.exe" staging/ cd staging 7z a ../release.zip * else - cp "output/${{ matrix.cargo-target }}/release/${{ needs.init.outputs.manifest_name }}" staging/ + cp "output/${{ matrix.cargo-target }}/release/lune" staging/ cd staging zip ../release.zip * fi diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fddc6a..ea4c339 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `net.serve` gets `NetRequest` and `NetResponse` for the handler function argument and return value - `process.spawn` gets `ProcessSpawnOptions` for its third and optional parameter +### Changed + +- Reorganize repository structure to take advantage of cargo workspaces, improves compile times + ## `0.2.1` - February 3rd, 2023 ### Added diff --git a/Cargo.lock b/Cargo.lock index f29b221..cc1621a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" +checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" [[package]] name = "autocfg" @@ -518,11 +518,23 @@ name = "lune" version = "0.2.1" dependencies = [ "anyhow", - "clap", - "full_moon", "hyper", "mlua", "os_str_bytes", + "reqwest", + "serde", + "serde_json", + "tokio", +] + +[[package]] +name = "lune-cli" +version = "0.2.1" +dependencies = [ + "anyhow", + "clap", + "full_moon", + "lune", "regex", "reqwest", "serde", @@ -706,9 +718,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" dependencies = [ "unicode-ident", ] @@ -902,9 +914,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.91" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +checksum = "7434af0dc1cbd59268aa98b4c22c131c0584d2232f6fb166efb993e2832e896a" dependencies = [ "itoa", "ryu", @@ -949,9 +961,9 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "smol_str" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7475118a28b7e3a2e157ce0131ba8c5526ea96e90ee601d9f6bb2e286a35ab44" +checksum = "fad6c857cbab2627dcf01ec85a623ca4e7dcb5691cbaa3d7fb7653671f0d09c9" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index a298b5e..088f7ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,42 +1,32 @@ -[package] -name = "lune" +[workspace] + +members = ["packages/cli", "packages/lib"] +default-members = ["packages/cli"] + +[workspace.package] version = "0.2.1" edition = "2021" license = "MPL-2.0" repository = "https://github.com/filiptibell/lune" description = "A Luau script runner" +readme = "README.md" keywords = ["cli", "lua", "luau", "scripts"] categories = ["command-line-interface"] -[[bin]] -name = "lune" -path = "src/cli/main.rs" - -[lib] -name = "lune" -path = "src/lib/lib.rs" - [profile.release] strip = true # Automatically strip symbols from the binary. opt-level = "z" # Optimize for size. lto = true # Enable link-time optimization panic = "abort" # Remove extra panic info -[dependencies] +[workspace.dependencies] -anyhow = "1.0.68" -os_str_bytes = "6.4.1" -regex = "1.7.1" serde_json = "1.0.91" -clap = { version = "4.1.1", features = ["derive"] } -full_moon = { version = "0.17.0", features = ["roblox"] } -hyper = { version = "0.14.24", features = ["full"] } -mlua = { version = "0.8.7", features = ["luau", "async", "serialize"] } serde = { version = "1.0.152", features = ["derive"] } tokio = { version = "1.24.2", features = ["full"] } -[dependencies.reqwest] +[workspace.dependencies.reqwest] version = "0.11.14" default-features = false features = ["rustls-tls"] diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml new file mode 100644 index 0000000..4b3dfb0 --- /dev/null +++ b/packages/cli/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "lune-cli" +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +description.workspace = true +readme.workspace = true +keywords.workspace = true +categories.workspace = true + +[[bin]] +name = "lune" +path = "src/main.rs" + +[dependencies] + +lune = { path = "../lib" } + +serde_json.workspace = true +serde.workspace = true +tokio.workspace = true +reqwest.workspace = true + +anyhow = "1.0.68" +regex = "1.7.1" + +clap = { version = "4.1.1", features = ["derive"] } +full_moon = { version = "0.17.0", features = ["roblox"] } diff --git a/src/cli/cli.rs b/packages/cli/src/cli.rs similarity index 99% rename from src/cli/cli.rs rename to packages/cli/src/cli.rs index e2f2c57..6b8ad6b 100644 --- a/src/cli/cli.rs +++ b/packages/cli/src/cli.rs @@ -165,7 +165,7 @@ impl Cli { Ok(match result { Err(e) => { eprintln!("{e}"); - ExitCode::from(1) + ExitCode::FAILURE } Ok(code) => code, }) diff --git a/src/cli/gen/doc.rs b/packages/cli/src/gen/doc.rs similarity index 100% rename from src/cli/gen/doc.rs rename to packages/cli/src/gen/doc.rs diff --git a/src/cli/gen/mod.rs b/packages/cli/src/gen/mod.rs similarity index 100% rename from src/cli/gen/mod.rs rename to packages/cli/src/gen/mod.rs diff --git a/src/cli/gen/tag.rs b/packages/cli/src/gen/tag.rs similarity index 100% rename from src/cli/gen/tag.rs rename to packages/cli/src/gen/tag.rs diff --git a/src/cli/gen/visitor.rs b/packages/cli/src/gen/visitor.rs similarity index 100% rename from src/cli/gen/visitor.rs rename to packages/cli/src/gen/visitor.rs diff --git a/src/cli/main.rs b/packages/cli/src/main.rs similarity index 92% rename from src/cli/main.rs rename to packages/cli/src/main.rs index b1a4759..1abb499 100644 --- a/src/cli/main.rs +++ b/packages/cli/src/main.rs @@ -1,6 +1,7 @@ #![deny(clippy::all)] #![warn(clippy::cargo, clippy::pedantic)] #![allow( + clippy::cargo_common_metadata, clippy::match_bool, clippy::module_name_repetitions, clippy::multiple_crate_versions, diff --git a/src/cli/utils/files.rs b/packages/cli/src/utils/files.rs similarity index 100% rename from src/cli/utils/files.rs rename to packages/cli/src/utils/files.rs diff --git a/src/cli/utils/github.rs b/packages/cli/src/utils/github.rs similarity index 100% rename from src/cli/utils/github.rs rename to packages/cli/src/utils/github.rs diff --git a/src/cli/utils/listing.rs b/packages/cli/src/utils/listing.rs similarity index 100% rename from src/cli/utils/listing.rs rename to packages/cli/src/utils/listing.rs diff --git a/src/cli/utils/mod.rs b/packages/cli/src/utils/mod.rs similarity index 100% rename from src/cli/utils/mod.rs rename to packages/cli/src/utils/mod.rs diff --git a/packages/lib/Cargo.toml b/packages/lib/Cargo.toml new file mode 100644 index 0000000..719cf6b --- /dev/null +++ b/packages/lib/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "lune" +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +description.workspace = true +readme.workspace = true +keywords.workspace = true +categories.workspace = true + +[lib] +name = "lune" +path = "src/lib.rs" + +[dependencies] + +serde_json.workspace = true +serde.workspace = true +tokio.workspace = true +reqwest.workspace = true + +os_str_bytes = "6.4.1" + +hyper = { version = "0.14.24", features = ["full"] } +mlua = { version = "0.8.7", features = ["luau", "async", "serialize"] } + +[dev-dependencies] +anyhow = "1.0.69" diff --git a/src/lib/globals/console.rs b/packages/lib/src/globals/console.rs similarity index 100% rename from src/lib/globals/console.rs rename to packages/lib/src/globals/console.rs diff --git a/src/lib/globals/fs.rs b/packages/lib/src/globals/fs.rs similarity index 100% rename from src/lib/globals/fs.rs rename to packages/lib/src/globals/fs.rs diff --git a/src/lib/globals/mod.rs b/packages/lib/src/globals/mod.rs similarity index 100% rename from src/lib/globals/mod.rs rename to packages/lib/src/globals/mod.rs diff --git a/src/lib/globals/net.rs b/packages/lib/src/globals/net.rs similarity index 100% rename from src/lib/globals/net.rs rename to packages/lib/src/globals/net.rs diff --git a/src/lib/globals/process.rs b/packages/lib/src/globals/process.rs similarity index 100% rename from src/lib/globals/process.rs rename to packages/lib/src/globals/process.rs diff --git a/src/lib/globals/require.rs b/packages/lib/src/globals/require.rs similarity index 100% rename from src/lib/globals/require.rs rename to packages/lib/src/globals/require.rs diff --git a/src/lib/globals/task.rs b/packages/lib/src/globals/task.rs similarity index 100% rename from src/lib/globals/task.rs rename to packages/lib/src/globals/task.rs diff --git a/src/lib/lib.rs b/packages/lib/src/lib.rs similarity index 87% rename from src/lib/lib.rs rename to packages/lib/src/lib.rs index 55285b8..5c6f8f3 100644 --- a/src/lib/lib.rs +++ b/packages/lib/src/lib.rs @@ -1,6 +1,5 @@ use std::{collections::HashSet, process::ExitCode, sync::Arc}; -use anyhow::{bail, Result}; use mlua::prelude::*; use tokio::{sync::mpsc, task}; @@ -71,7 +70,7 @@ impl Lune { self } - pub async fn run(&self, name: &str, chunk: &str) -> Result { + pub async fn run(&self, name: &str, chunk: &str) -> Result { let task_set = task::LocalSet::new(); let (sender, mut receiver) = mpsc::channel::(64); let lua = Arc::new(mlua::Lua::new()); @@ -94,7 +93,10 @@ impl Lune { let script_name = name.to_string(); let script_chunk = chunk.to_string(); let script_sender = snd.clone(); - script_sender.send(LuneMessage::Spawned).await?; + script_sender + .send(LuneMessage::Spawned) + .await + .map_err(LuaError::external)?; task_set.spawn_local(async move { let result = script_lua .load(&script_chunk) @@ -123,10 +125,10 @@ impl Lune { LuneMessage::Spawned => {} message => { if task_count == 0 { - bail!( + return Err(format!( "Got message while task count was 0!\nMessage: {:#?}", message - ) + )); } } } @@ -153,7 +155,8 @@ impl Lune { } Ok((got_code, got_error, exit_code)) }) - .await?; + .await + .map_err(LuaError::external)?; // If we got an error, we will default to exiting // with code 1, unless a code was manually given if got_code { @@ -168,7 +171,7 @@ impl Lune { #[cfg(test)] mod tests { - use std::process::ExitCode; + use std::{env::set_current_dir, path::PathBuf, process::ExitCode}; use anyhow::Result; use tokio::fs::read_to_string; @@ -182,10 +185,15 @@ mod tests { $( #[tokio::test] async fn $name() -> Result { - let full_name = format!("src/tests/{}.luau", $value); - let script = read_to_string(&full_name) - .await - .unwrap(); + // NOTE: This path is relative to the lib + // package, not the cwd or workspace root, + // so we need to cd to the repo root first + let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let root_dir = crate_dir.join("../../").canonicalize()?; + set_current_dir(root_dir)?; + // The rest of the test logic can continue as normal + let full_name = format!("tests/{}.luau", $value); + let script = read_to_string(&full_name).await?; let lune = Lune::new() .with_args( ARGS @@ -196,7 +204,8 @@ mod tests { ) .with_all_globals(); let script_name = full_name.strip_suffix(".luau").unwrap(); - lune.run(&script_name, &script).await + let exit_code = lune.run(&script_name, &script).await?; + Ok(exit_code) } )* } diff --git a/src/lib/utils/formatting.rs b/packages/lib/src/utils/formatting.rs similarity index 99% rename from src/lib/utils/formatting.rs rename to packages/lib/src/utils/formatting.rs index 2cde6cf..bfd9adc 100644 --- a/src/lib/utils/formatting.rs +++ b/packages/lib/src/utils/formatting.rs @@ -110,7 +110,7 @@ pub fn pretty_format_value( buffer: &mut String, value: &LuaValue, depth: usize, -) -> anyhow::Result<()> { +) -> std::fmt::Result { // TODO: Handle tables with cyclic references match &value { LuaValue::Nil => write!(buffer, "nil")?, @@ -135,7 +135,7 @@ pub fn pretty_format_value( let depth_indent = INDENT.repeat(depth); write!(buffer, "{STYLE_DIM}{{{STYLE_RESET}")?; for pair in tab.clone().pairs::() { - let (key, value) = pair?; + let (key, value) = pair.unwrap(); match &key { LuaValue::String(s) if can_be_plain_lua_table_key(s) => write!( buffer, diff --git a/src/lib/utils/mod.rs b/packages/lib/src/utils/mod.rs similarity index 100% rename from src/lib/utils/mod.rs rename to packages/lib/src/utils/mod.rs diff --git a/src/lib/utils/net.rs b/packages/lib/src/utils/net.rs similarity index 100% rename from src/lib/utils/net.rs rename to packages/lib/src/utils/net.rs diff --git a/src/lib/utils/process.rs b/packages/lib/src/utils/process.rs similarity index 100% rename from src/lib/utils/process.rs rename to packages/lib/src/utils/process.rs diff --git a/src/lib/utils/table.rs b/packages/lib/src/utils/table.rs similarity index 100% rename from src/lib/utils/table.rs rename to packages/lib/src/utils/table.rs diff --git a/src/lib/utils/task.rs b/packages/lib/src/utils/task.rs similarity index 100% rename from src/lib/utils/task.rs rename to packages/lib/src/utils/task.rs diff --git a/src/tests/process/exit.luau b/src/tests/process/exit.luau deleted file mode 100644 index d83892f..0000000 --- a/src/tests/process/exit.luau +++ /dev/null @@ -1,14 +0,0 @@ -local function assert(condition, err) - if not condition then - console.error(err) - process.exit(0) - end -end - -local path = process.cwd .. "asdfghjkl" - -assert(fs.isDir(path), "Process should exit") -assert(fs.isDir(path), "Process should exit") -assert(fs.isDir(path), "Process should exit") - -error("Process should have exited...") diff --git a/src/tests/console/format.luau b/tests/console/format.luau similarity index 100% rename from src/tests/console/format.luau rename to tests/console/format.luau diff --git a/src/tests/console/set_color.luau b/tests/console/set_color.luau similarity index 100% rename from src/tests/console/set_color.luau rename to tests/console/set_color.luau diff --git a/src/tests/console/set_style.luau b/tests/console/set_style.luau similarity index 100% rename from src/tests/console/set_style.luau rename to tests/console/set_style.luau diff --git a/src/tests/fs/dirs.luau b/tests/fs/dirs.luau similarity index 100% rename from src/tests/fs/dirs.luau rename to tests/fs/dirs.luau diff --git a/src/tests/fs/files.luau b/tests/fs/files.luau similarity index 100% rename from src/tests/fs/files.luau rename to tests/fs/files.luau diff --git a/src/tests/net/json/decode.luau b/tests/net/json/decode.luau similarity index 100% rename from src/tests/net/json/decode.luau rename to tests/net/json/decode.luau diff --git a/src/tests/net/json/encode.luau b/tests/net/json/encode.luau similarity index 100% rename from src/tests/net/json/encode.luau rename to tests/net/json/encode.luau diff --git a/src/tests/net/request/codes.luau b/tests/net/request/codes.luau similarity index 100% rename from src/tests/net/request/codes.luau rename to tests/net/request/codes.luau diff --git a/src/tests/net/request/methods.luau b/tests/net/request/methods.luau similarity index 100% rename from src/tests/net/request/methods.luau rename to tests/net/request/methods.luau diff --git a/src/tests/net/request/redirect.luau b/tests/net/request/redirect.luau similarity index 100% rename from src/tests/net/request/redirect.luau rename to tests/net/request/redirect.luau diff --git a/src/tests/net/request/util.luau b/tests/net/request/util.luau similarity index 100% rename from src/tests/net/request/util.luau rename to tests/net/request/util.luau diff --git a/src/tests/net/serve.luau b/tests/net/serve.luau similarity index 100% rename from src/tests/net/serve.luau rename to tests/net/serve.luau diff --git a/src/tests/process/args.luau b/tests/process/args.luau similarity index 100% rename from src/tests/process/args.luau rename to tests/process/args.luau diff --git a/src/tests/process/cwd.luau b/tests/process/cwd.luau similarity index 100% rename from src/tests/process/cwd.luau rename to tests/process/cwd.luau diff --git a/src/tests/process/env.luau b/tests/process/env.luau similarity index 100% rename from src/tests/process/env.luau rename to tests/process/env.luau diff --git a/tests/process/exit.luau b/tests/process/exit.luau new file mode 100644 index 0000000..1d7f26d --- /dev/null +++ b/tests/process/exit.luau @@ -0,0 +1,14 @@ +local function assert(condition, err) + if not condition then + console.error(err) + process.exit(0) + end +end + +local path = process.cwd .. "asdfghjkl" + +assert(fs.isDir(path), "Process should exit with success") +assert(fs.isDir(path), "Process should exit with success") +assert(fs.isDir(path), "Process should exit with success") + +error("Process should have exited with success...") diff --git a/src/tests/process/spawn.luau b/tests/process/spawn.luau similarity index 100% rename from src/tests/process/spawn.luau rename to tests/process/spawn.luau diff --git a/src/tests/require/modules/module.luau b/tests/require/modules/module.luau similarity index 100% rename from src/tests/require/modules/module.luau rename to tests/require/modules/module.luau diff --git a/src/tests/require/tests/children.luau b/tests/require/tests/children.luau similarity index 100% rename from src/tests/require/tests/children.luau rename to tests/require/tests/children.luau diff --git a/src/tests/require/tests/invalid.luau b/tests/require/tests/invalid.luau similarity index 100% rename from src/tests/require/tests/invalid.luau rename to tests/require/tests/invalid.luau diff --git a/src/tests/require/tests/module.luau b/tests/require/tests/module.luau similarity index 100% rename from src/tests/require/tests/module.luau rename to tests/require/tests/module.luau diff --git a/src/tests/require/tests/modules/module.luau b/tests/require/tests/modules/module.luau similarity index 100% rename from src/tests/require/tests/modules/module.luau rename to tests/require/tests/modules/module.luau diff --git a/src/tests/require/tests/modules/modules/module.luau b/tests/require/tests/modules/modules/module.luau similarity index 100% rename from src/tests/require/tests/modules/modules/module.luau rename to tests/require/tests/modules/modules/module.luau diff --git a/src/tests/require/tests/modules/nested.luau b/tests/require/tests/modules/nested.luau similarity index 100% rename from src/tests/require/tests/modules/nested.luau rename to tests/require/tests/modules/nested.luau diff --git a/src/tests/require/tests/nested.luau b/tests/require/tests/nested.luau similarity index 100% rename from src/tests/require/tests/nested.luau rename to tests/require/tests/nested.luau diff --git a/src/tests/require/tests/parents.luau b/tests/require/tests/parents.luau similarity index 100% rename from src/tests/require/tests/parents.luau rename to tests/require/tests/parents.luau diff --git a/src/tests/require/tests/siblings.luau b/tests/require/tests/siblings.luau similarity index 100% rename from src/tests/require/tests/siblings.luau rename to tests/require/tests/siblings.luau diff --git a/src/tests/task/cancel.luau b/tests/task/cancel.luau similarity index 100% rename from src/tests/task/cancel.luau rename to tests/task/cancel.luau diff --git a/src/tests/task/defer.luau b/tests/task/defer.luau similarity index 100% rename from src/tests/task/defer.luau rename to tests/task/defer.luau diff --git a/src/tests/task/delay.luau b/tests/task/delay.luau similarity index 100% rename from src/tests/task/delay.luau rename to tests/task/delay.luau diff --git a/src/tests/task/fcheck.luau b/tests/task/fcheck.luau similarity index 100% rename from src/tests/task/fcheck.luau rename to tests/task/fcheck.luau diff --git a/src/tests/task/spawn.luau b/tests/task/spawn.luau similarity index 100% rename from src/tests/task/spawn.luau rename to tests/task/spawn.luau diff --git a/src/tests/task/wait.luau b/tests/task/wait.luau similarity index 100% rename from src/tests/task/wait.luau rename to tests/task/wait.luau