From a7dba0899086434e380bbef86f817473221e6990 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 10 Feb 2022 05:59:35 +0100 Subject: [PATCH] improve things --- .github/workflows/rust.yml | 4 +- Cargo.lock | 105 ++++++++++++++++++++++++++++++++++++- amqp_transport/src/sasl.rs | 2 +- tests-js/package.json | 3 +- xtask/Cargo.toml | 3 +- xtask/src/codegen/mod.rs | 21 ++++++-- xtask/src/main.rs | 49 +++++++++++------ xtask/src/test_js.rs | 20 +++++++ yarn.lock | 4 ++ 9 files changed, 185 insertions(+), 26 deletions(-) create mode 100644 xtask/src/test_js.rs create mode 100644 yarn.lock diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d422a95..af557e5 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -20,7 +20,7 @@ jobs: uses: creyD/prettier_action@v4.2 with: dry: true - prettier_options: --check **/*.{html,css,js,md} --ignore-path .gitignore + prettier_options: --check amqp_dashboard/assets/* --ignore-path .gitignore - name: Build run: cargo build --verbose - name: Run clippy -D clippy::all @@ -29,3 +29,5 @@ jobs: run: cargo fmt --verbose --all -- --check - name: Run tests run: cargo test --verbose --all + - name: Run client integration tests + run: cargo xtask tests-js diff --git a/Cargo.lock b/Cargo.lock index 82808ea..f07d9c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,10 +213,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "bitflags", - "textwrap", + "textwrap 0.11.0", "unicode-width", ] +[[package]] +name = "clap" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d76c22c9b9b215eeb8d016ad3a90417bd13cb24cf8142756e6472445876cab7" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", + "strsim", + "termcolor", + "textwrap 0.14.2", +] + +[[package]] +name = "clap_derive" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd1122e63869df2cb309f449da1ad54a7c6dfeb7c7e6ccd8e0825d9eb93bb72" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "criterion" version = "0.3.5" @@ -225,7 +255,7 @@ checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" dependencies = [ "atty", "cast", - "clap", + "clap 2.34.0", "criterion-plot", "csv", "itertools", @@ -397,6 +427,12 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + [[package]] name = "heck" version = "0.4.0" @@ -475,6 +511,16 @@ dependencies = [ "want", ] +[[package]] +name = "indexmap" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "itertools" version = "0.10.3" @@ -662,6 +708,15 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] + [[package]] name = "parking_lot" version = "0.12.0" @@ -757,6 +812,30 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.36" @@ -1022,6 +1101,12 @@ dependencies = [ "syn", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" version = "1.0.86" @@ -1039,6 +1124,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -1048,6 +1142,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" + [[package]] name = "thiserror" version = "1.0.30" @@ -1468,6 +1568,7 @@ name = "xtask" version = "0.1.0" dependencies = [ "anyhow", + "clap 3.1.1", "heck", "itertools", "strong-xml", diff --git a/amqp_transport/src/sasl.rs b/amqp_transport/src/sasl.rs index 986dcb0..970d113 100644 --- a/amqp_transport/src/sasl.rs +++ b/amqp_transport/src/sasl.rs @@ -1,6 +1,6 @@ //! (Very) partial implementation of SASL Authentication (see [RFC 4422](https://datatracker.ietf.org/doc/html/rfc4422)) //! -//! Currently only supports PLAN (see [RFC 4616](https://datatracker.ietf.org/doc/html/rfc4616)) +//! Currently only supports PLAIN (see [RFC 4616](https://datatracker.ietf.org/doc/html/rfc4616)) use crate::error::{ConException, Result}; diff --git a/tests-js/package.json b/tests-js/package.json index ccee7e0..4b08626 100644 --- a/tests-js/package.json +++ b/tests-js/package.json @@ -5,7 +5,8 @@ "type": "module", "license": "MIT", "scripts": { - "fmt": "prettier -w ." + "fmt": "prettier -w .", + "test": "echo '✔️ Everything fine!'" }, "dependencies": { "@types/amqplib": "^0.8.2", diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index be38f42..ed4adde 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] anyhow = "1.0.54" +clap = { version = "3.1.1", features = ["derive"] } heck = "0.4.0" itertools = "0.10.3" -strong-xml = "0.6.3" \ No newline at end of file +strong-xml = "0.6.3" diff --git a/xtask/src/codegen/mod.rs b/xtask/src/codegen/mod.rs index f7a0d95..9600df1 100644 --- a/xtask/src/codegen/mod.rs +++ b/xtask/src/codegen/mod.rs @@ -4,13 +4,14 @@ mod parser; mod random; mod write; -use anyhow::Context; +use anyhow::{bail, Context}; use heck::ToUpperCamelCase; use std::fs; use std::fs::File; use std::io::Write; use std::iter::Peekable; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; +use std::process::Command; use std::str::FromStr; use strong_xml::XmlRead; @@ -105,6 +106,15 @@ struct Codegen { output: Box, } +fn fmt(path: &Path) -> anyhow::Result<()> { + println!("Formatting {path:?}..."); + let status = Command::new("rustfmt").arg(path).status()?; + if !status.success() { + bail!("error formatting {path:?}"); + } + Ok(()) +} + pub fn main() -> anyhow::Result<()> { let this_file = PathBuf::from_str(file!()).context("own file path")?; let xtask_root = this_file @@ -125,8 +135,8 @@ pub fn main() -> anyhow::Result<()> { let amqp = Amqp::from_str(&content).context("parse amqp spec file")?; let transport_output = - File::create(transport_generated_path).context("transport output file create")?; - let core_output = File::create(core_generated_path).context("core output file create")?; + File::create(&transport_generated_path).context("transport output file create")?; + let core_output = File::create(&core_generated_path).context("core output file create")?; Codegen { output: Box::new(transport_output), @@ -138,6 +148,9 @@ pub fn main() -> anyhow::Result<()> { } .core_codegen(&amqp); + fmt(&transport_generated_path)?; + fmt(&core_generated_path)?; + Ok(()) } impl Codegen { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index dfdacf5..0430f19 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,24 +1,41 @@ +use std::path::PathBuf; + mod codegen; +mod test_js; + +use clap::{Parser, Subcommand}; + +#[derive(Parser)] +#[clap(author)] +struct Args { + #[clap(subcommand)] + command: Commands, +} + +#[derive(Subcommand)] +enum Commands { + /// Generate method definitions/parser/writer + Generate, + /// Run Javascript integration tests + TestJs, +} fn main() -> anyhow::Result<()> { - let command = std::env::args().nth(1).unwrap_or_else(|| { - eprintln!("Error: No task provided"); - help(); - std::process::exit(1); - }); + let args: Args = Args::parse(); - match command.as_str() { - "generate" | "gen" => codegen::main(), - _ => { - eprintln!("Unknown command {command}."); - Ok(()) - } + match args.command { + Commands::Generate => codegen::main(), + Commands::TestJs => test_js::main(), } } -fn help() { - println!( - "Available tasks: - generate, gen - Generate amqp method code in `amqp_transport/src/methods/generated.rs and amqp_core/src/methods/generated.rs" - ); +pub fn project_root() -> PathBuf { + PathBuf::from(file!()) + .parent() + .expect("src directory path") + .parent() + .expect("xtask root path") + .parent() + .expect("project root path") + .to_path_buf() } diff --git a/xtask/src/test_js.rs b/xtask/src/test_js.rs new file mode 100644 index 0000000..aa41b52 --- /dev/null +++ b/xtask/src/test_js.rs @@ -0,0 +1,20 @@ +use crate::project_root; +use anyhow::{bail, Result}; +use std::process::Command; + +pub fn main() -> Result<()> { + let test_js_root = project_root().join("tests-js"); + let status = Command::new("yarn").current_dir(&test_js_root).status()?; + if !status.success() { + bail!("yarn install failed"); + } + let status = Command::new("yarn") + .arg("test") + .current_dir(&test_js_root) + .status()?; + if !status.success() { + bail!("yarn tests failed"); + } + + Ok(()) +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..fb57ccd --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + +