improve things

This commit is contained in:
nora 2022-02-10 05:59:35 +01:00
parent f437754618
commit a7dba08990
9 changed files with 185 additions and 26 deletions

View file

@ -20,7 +20,7 @@ jobs:
uses: creyD/prettier_action@v4.2 uses: creyD/prettier_action@v4.2
with: with:
dry: true dry: true
prettier_options: --check **/*.{html,css,js,md} --ignore-path .gitignore prettier_options: --check amqp_dashboard/assets/* --ignore-path .gitignore
- name: Build - name: Build
run: cargo build --verbose run: cargo build --verbose
- name: Run clippy -D clippy::all - name: Run clippy -D clippy::all
@ -29,3 +29,5 @@ jobs:
run: cargo fmt --verbose --all -- --check run: cargo fmt --verbose --all -- --check
- name: Run tests - name: Run tests
run: cargo test --verbose --all run: cargo test --verbose --all
- name: Run client integration tests
run: cargo xtask tests-js

105
Cargo.lock generated
View file

@ -213,10 +213,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"textwrap", "textwrap 0.11.0",
"unicode-width", "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]] [[package]]
name = "criterion" name = "criterion"
version = "0.3.5" version = "0.3.5"
@ -225,7 +255,7 @@ checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10"
dependencies = [ dependencies = [
"atty", "atty",
"cast", "cast",
"clap", "clap 2.34.0",
"criterion-plot", "criterion-plot",
"csv", "csv",
"itertools", "itertools",
@ -397,6 +427,12 @@ version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.4.0" version = "0.4.0"
@ -475,6 +511,16 @@ dependencies = [
"want", "want",
] ]
[[package]]
name = "indexmap"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.10.3" version = "0.10.3"
@ -662,6 +708,15 @@ version = "11.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" 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]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.0" version = "0.12.0"
@ -757,6 +812,30 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" 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]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.36" version = "1.0.36"
@ -1022,6 +1101,12 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.86" version = "1.0.86"
@ -1039,6 +1124,15 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" 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]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.11.0" version = "0.11.0"
@ -1048,6 +1142,12 @@ dependencies = [
"unicode-width", "unicode-width",
] ]
[[package]]
name = "textwrap"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.30" version = "1.0.30"
@ -1468,6 +1568,7 @@ name = "xtask"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap 3.1.1",
"heck", "heck",
"itertools", "itertools",
"strong-xml", "strong-xml",

View file

@ -1,6 +1,6 @@
//! (Very) partial implementation of SASL Authentication (see [RFC 4422](https://datatracker.ietf.org/doc/html/rfc4422)) //! (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}; use crate::error::{ConException, Result};

View file

@ -5,7 +5,8 @@
"type": "module", "type": "module",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"fmt": "prettier -w ." "fmt": "prettier -w .",
"test": "echo '✔️ Everything fine!'"
}, },
"dependencies": { "dependencies": {
"@types/amqplib": "^0.8.2", "@types/amqplib": "^0.8.2",

View file

@ -7,6 +7,7 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0.54" anyhow = "1.0.54"
clap = { version = "3.1.1", features = ["derive"] }
heck = "0.4.0" heck = "0.4.0"
itertools = "0.10.3" itertools = "0.10.3"
strong-xml = "0.6.3" strong-xml = "0.6.3"

View file

@ -4,13 +4,14 @@ mod parser;
mod random; mod random;
mod write; mod write;
use anyhow::Context; use anyhow::{bail, Context};
use heck::ToUpperCamelCase; use heck::ToUpperCamelCase;
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
use std::io::Write; use std::io::Write;
use std::iter::Peekable; use std::iter::Peekable;
use std::path::PathBuf; use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::FromStr; use std::str::FromStr;
use strong_xml::XmlRead; use strong_xml::XmlRead;
@ -105,6 +106,15 @@ struct Codegen {
output: Box<dyn Write>, output: Box<dyn Write>,
} }
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<()> { pub fn main() -> anyhow::Result<()> {
let this_file = PathBuf::from_str(file!()).context("own file path")?; let this_file = PathBuf::from_str(file!()).context("own file path")?;
let xtask_root = this_file 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 amqp = Amqp::from_str(&content).context("parse amqp spec file")?;
let transport_output = let transport_output =
File::create(transport_generated_path).context("transport 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")?; let core_output = File::create(&core_generated_path).context("core output file create")?;
Codegen { Codegen {
output: Box::new(transport_output), output: Box::new(transport_output),
@ -138,6 +148,9 @@ pub fn main() -> anyhow::Result<()> {
} }
.core_codegen(&amqp); .core_codegen(&amqp);
fmt(&transport_generated_path)?;
fmt(&core_generated_path)?;
Ok(()) Ok(())
} }
impl Codegen { impl Codegen {

View file

@ -1,24 +1,41 @@
use std::path::PathBuf;
mod codegen; 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<()> { fn main() -> anyhow::Result<()> {
let command = std::env::args().nth(1).unwrap_or_else(|| { let args: Args = Args::parse();
eprintln!("Error: No task provided");
help();
std::process::exit(1);
});
match command.as_str() { match args.command {
"generate" | "gen" => codegen::main(), Commands::Generate => codegen::main(),
_ => { Commands::TestJs => test_js::main(),
eprintln!("Unknown command {command}.");
Ok(())
}
} }
} }
fn help() { pub fn project_root() -> PathBuf {
println!( PathBuf::from(file!())
"Available tasks: .parent()
generate, gen - Generate amqp method code in `amqp_transport/src/methods/generated.rs and amqp_core/src/methods/generated.rs" .expect("src directory path")
); .parent()
.expect("xtask root path")
.parent()
.expect("project root path")
.to_path_buf()
} }

20
xtask/src/test_js.rs Normal file
View file

@ -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(())
}

4
yarn.lock Normal file
View file

@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1