-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b082586
Showing
14 changed files
with
456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: github-actions | ||
directory: / | ||
schedule: | ||
interval: daily | ||
target-branch: "main" | ||
|
||
- package-ecosystem: cargo | ||
directory: / | ||
schedule: | ||
interval: daily | ||
target-branch: "main" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
name: Testing | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
format: | ||
name: Formatting | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- id: checkout | ||
name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- id: setup | ||
name: Setup Toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: nightly | ||
components: rustfmt | ||
|
||
- id: cache | ||
name: Enable Workflow Cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- id: format | ||
name: Run Formatting-Checks | ||
run: cargo fmt --check | ||
|
||
check: | ||
name: Static Analysis | ||
runs-on: ubuntu-latest | ||
needs: format | ||
|
||
strategy: | ||
matrix: | ||
toolchain: [stable, nightly] | ||
|
||
steps: | ||
- id: checkout | ||
name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- id: setup | ||
name: Setup Toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: ${{ matrix.toolchain }} | ||
components: clippy | ||
|
||
- id: cache | ||
name: Enable Workflow Cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- id: check | ||
name: Run Build Checks | ||
run: cargo check --tests --benches --examples --workspace --all-targets --all-features | ||
|
||
- id: lint | ||
name: Run Lint Checks | ||
run: cargo clippy --tests --benches --examples --workspace --all-targets --all-features -- -D clippy::correctness -D clippy::suspicious -D clippy::complexity -D clippy::perf -D clippy::style -D clippy::pedantic | ||
|
||
- id: doc | ||
name: Run Documentation Checks | ||
run: cargo test --doc | ||
|
||
unit: | ||
name: Units | ||
runs-on: ubuntu-latest | ||
needs: check | ||
|
||
strategy: | ||
matrix: | ||
toolchain: [stable, nightly] | ||
|
||
steps: | ||
- id: checkout | ||
name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- id: setup | ||
name: Setup Toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: ${{ matrix.toolchain }} | ||
components: llvm-tools-preview | ||
|
||
- id: cache | ||
name: Enable Job Cache | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- id: tools | ||
name: Install Tools | ||
uses: taiki-e/install-action@v2 | ||
with: | ||
tool: cargo-llvm-cov, cargo-nextest | ||
|
||
- id: test | ||
name: Run Unit Tests | ||
run: cargo test --tests --benches --examples --workspace --all-targets --all-features |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.coverage/ | ||
/.idea/ | ||
/.vscode/launch.json | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"recommendations": [ | ||
"streetsidesoftware.code-spell-checker", | ||
"rust-lang.rust-analyzer", | ||
"tamasfe.even-better-toml" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"[rust]": { | ||
"editor.formatOnSave": true | ||
}, | ||
"rust-analyzer.checkOnSave": true, | ||
"rust-analyzer.check.command": "clippy", | ||
"rust-analyzer.check.allTargets": true, | ||
"rust-analyzer.check.extraArgs": [ | ||
"--", | ||
"-D", | ||
"clippy::correctness", | ||
"-D", | ||
"clippy::suspicious", | ||
"-W", | ||
"clippy::complexity", | ||
"-W", | ||
"clippy::perf", | ||
"-W", | ||
"clippy::style", | ||
"-W", | ||
"clippy::pedantic", | ||
], | ||
"evenBetterToml.formatter.allowedBlankLines": 1, | ||
"evenBetterToml.formatter.columnWidth": 130, | ||
"evenBetterToml.formatter.trailingNewline": true, | ||
"evenBetterToml.formatter.reorderKeys": true, | ||
"evenBetterToml.formatter.reorderArrays": true, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "pretty-test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "GPL-3.0" | ||
authors = ["vague", "Jose Celano <[email protected]>"] | ||
description = "A console command to format cargo test output" | ||
repository = "https://github.com/josecelano/pretty-test" | ||
|
||
[dependencies] | ||
termtree = "0.4.1" | ||
|
||
[dev-dependencies] | ||
pretty_assertions = "1.4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Pretty-test ✨ | ||
|
||
A Rust command that prettifies the ugly `cargo test` into a beautiful output. | ||
|
||
Input: | ||
|
||
```s | ||
test e2e::web::api::v1::contexts::category::contract::it_should_not_allow_adding_duplicated_categories ... ok | ||
test e2e::web::api::v1::contexts::tag::contract::it_should_not_allow_adding_duplicated_tags ... ok | ||
test e2e::web::api::v1::contexts::category::contract::it_should_not_allow_non_admins_to_delete_categories ... ok | ||
test e2e::web::api::v1::contexts::tag::contract::it_should_not_allow_adding_a_tag_with_an_empty_name ... ok | ||
test e2e::web::api::v1::contexts::tag::contract::it_should_not_allow_guests_to_delete_tags ... ok | ||
test e2e::web::api::v1::contexts::category::contract::it_should_allow_admins_to_delete_categories ... ok | ||
test e2e::web::api::v1::contexts::user::contract::banned_user_list::it_should_allow_an_admin_to_ban_a_user ... ok | ||
test e2e::web::api::v1::contexts::tag::contract::it_should_allow_admins_to_delete_tags ... fail | ||
test e2e::web::api::v1::contexts::user::contract::banned_user_list::it_should_not_allow_a_non_admin_to_ban_a_user ... ok | ||
test e2e::web::api::v1::contexts::tag::contract::it_should_not_allow_non_admins_to_delete_tags ... ok | ||
``` | ||
|
||
Output: | ||
|
||
```s | ||
test | ||
└── e2e | ||
└── web | ||
└── api | ||
└── v1 | ||
└── contexts | ||
├── category | ||
│ └── contract | ||
│ ├─ ✅ it_should_allow_admins_to_delete_categories | ||
│ ├─ ✅ it_should_not_allow_adding_duplicated_categories | ||
│ └─ ✅ it_should_not_allow_non_admins_to_delete_categories | ||
├── tag | ||
│ └── contract | ||
│ ├─ ❌ it_should_allow_admins_to_delete_tags | ||
│ ├─ ✅ it_should_not_allow_adding_a_tag_with_an_empty_name | ||
│ ├─ ✅ it_should_not_allow_adding_duplicated_tags | ||
│ ├─ ✅ it_should_not_allow_guests_to_delete_tags | ||
│ └─ ✅ it_should_not_allow_non_admins_to_delete_tags | ||
└── user | ||
└── contract | ||
└── banned_user_list | ||
├─ ✅ it_should_allow_an_admin_to_ban_a_user | ||
└─ ✅ it_should_not_allow_a_non_admin_to_ban_a_user | ||
``` | ||
|
||
## Run | ||
|
||
```s | ||
cat tests/fixtures/sample_cargo_test_output.txt | cargo run | ||
``` | ||
|
||
You can also create a Rust script with <https://rust-script.org/>: | ||
|
||
- `cargo install rust-script`. | ||
- Execute the code. | ||
- Save the code in a file named pretty-test. | ||
- `chmod +x ./pretty-test` | ||
- Add it in your environment, like `mv pretty-test ~/.cargo/bin` | ||
- Run `pretty-test` in your project. | ||
|
||
## Test | ||
|
||
```s | ||
cargo test | ||
``` | ||
|
||
## Credits | ||
|
||
- <https://users.rust-lang.org/t/cargo-test-output-with-indentation/100149> | ||
- <https://www.rustexplorer.com/b/i058g3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"words": [ | ||
"splitn", | ||
"termtree" | ||
], | ||
"enableFiletypes": [ | ||
"dockerfile", | ||
"shellscript", | ||
"toml" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use std::collections::{btree_map::Entry, BTreeMap}; | ||
use termtree::{GlyphPalette, Tree}; | ||
|
||
/// Make the cargo test output pretty. | ||
#[must_use] | ||
pub fn make_pretty(output: &str) -> Option<Tree<&str>> { | ||
let mut path = BTreeMap::new(); | ||
for line in output.trim().lines() { | ||
let mut iter = line.trim().splitn(3, ' '); | ||
let mut split = iter.nth(1)?.split("::"); | ||
let next = split.next(); | ||
let status = iter.next()?; | ||
make_mods(split, status, &mut path, next); | ||
} | ||
let mut tree = Tree::new("test"); | ||
for (root, child) in path { | ||
make_tree(root, &child, &mut tree); | ||
} | ||
Some(tree) | ||
} | ||
|
||
#[derive(Debug)] | ||
enum Node<'s> { | ||
Path(BTreeMap<&'s str, Node<'s>>), | ||
Status(&'s str), | ||
} | ||
|
||
/// Add paths to Node. | ||
fn make_mods<'s>( | ||
mut split: impl Iterator<Item = &'s str>, | ||
status: &'s str, | ||
path: &mut BTreeMap<&'s str, Node<'s>>, | ||
key: Option<&'s str>, | ||
) { | ||
let Some(key) = key else { return }; | ||
let next = split.next(); | ||
match path.entry(key) { | ||
Entry::Vacant(empty) => { | ||
if next.is_some() { | ||
let mut btree = BTreeMap::new(); | ||
make_mods(split, status, &mut btree, next); | ||
empty.insert(Node::Path(btree)); | ||
} else { | ||
empty.insert(Node::Status(status)); | ||
} | ||
} | ||
Entry::Occupied(mut node) => { | ||
if let Node::Path(btree) = node.get_mut() { | ||
make_mods(split, status, btree, next); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Add Node to Tree. | ||
fn make_tree<'s>(root: &'s str, node: &Node<'s>, parent: &mut Tree<&'s str>) { | ||
match node { | ||
Node::Path(btree) => { | ||
let mut t = Tree::new(root); | ||
for (path, child) in btree { | ||
make_tree(path, child, &mut t); | ||
} | ||
parent.push(t); | ||
} | ||
Node::Status(s) => { | ||
parent.push(Tree::new(root).with_glyphs(set_status(s))); | ||
} | ||
} | ||
} | ||
|
||
/// Display with a status icon | ||
fn set_status(status: &str) -> GlyphPalette { | ||
let mut glyph = GlyphPalette::new(); | ||
glyph.item_indent = if status.ends_with("ok") { | ||
"─ ✅ " | ||
} else { | ||
"─ ❌ " | ||
}; | ||
glyph | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod app; |
Oops, something went wrong.