{"id":18473900,"url":"https://github.com/ohsayan/all_asserts","last_synced_at":"2025-04-08T12:32:05.003Z","repository":{"id":50094338,"uuid":"176059745","full_name":"ohsayan/all_asserts","owner":"ohsayan","description":"A crate for multiple types of asserts that don't exist in the standard library","archived":false,"fork":false,"pushed_at":"2024-12-28T06:48:43.000Z","size":60,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T20:16:22.180Z","etag":null,"topics":["assertions","cargo","crate","rust","rust-lang","rust-tests","testing"],"latest_commit_sha":null,"homepage":"https://docs.rs/all_asserts","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ohsayan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["buymeacoffee.com/sayann"]}},"created_at":"2019-03-17T05:21:33.000Z","updated_at":"2025-01-27T23:13:45.000Z","dependencies_parsed_at":"2024-12-28T07:26:18.300Z","dependency_job_id":"dde5aef3-8757-4237-a0f7-4eebb2059bf3","html_url":"https://github.com/ohsayan/all_asserts","commit_stats":{"total_commits":46,"total_committers":3,"mean_commits":"15.333333333333334","dds":"0.28260869565217395","last_synced_commit":"87850ceca56a563f5ebd053f9bb0f992de9e52ed"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fall_asserts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fall_asserts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fall_asserts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fall_asserts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ohsayan","download_url":"https://codeload.github.com/ohsayan/all_asserts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247842723,"owners_count":21005338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assertions","cargo","crate","rust","rust-lang","rust-tests","testing"],"created_at":"2024-11-06T10:27:02.529Z","updated_at":"2025-04-08T12:32:04.996Z","avatar_url":"https://github.com/ohsayan.png","language":"Rust","funding_links":["buymeacoffee.com/sayann"],"categories":[],"sub_categories":[],"readme":"# all_asserts ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ohsayan/all_asserts/test.yml) [![all_asserts crate](https://img.shields.io/crates/v/all_asserts.svg?style=flat-square)](https://crates.io/crates/all_asserts) [![Crates.io](https://img.shields.io/crates/d/all_asserts.svg?color=%234527A0)](https://crates.io/crates/all_asserts) [![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](./LICENSE)\n\n## A crate for multiple types of asserts that don't exist in the standard library\n\n## Rationale\n\nThere are several kinds of problems that I had faced while writing tests, especially when writing comparator tests.\nThe output from the existing macros, were providing _vague_ outputs while debugging which made me write this crate.\nI had created an RFC, but neverthless it was rejected as there were not enough use cases. I am not too sure about others, but I find myself writing multiple tests that frequently make use of these assert macros.\n\n## Importing and using\n\nAdd this to your `Cargo.toml` :\n\n```toml\nall_asserts = \"*\"\n```\n\nAnd now you can use the asserts wherever you like! If you want to make it available all across\nyour crate, in your `lib.rs` or `main.rs`, add the following:\n\n```rust\n#[macro_use]\nextern crate all_asserts;\n```\n\n## Examples\n\nAn example using `assert_range!` :\n\n```rust\nuse all_asserts::assert_range;\nfn main() {\n  assert_range!(10..20, 20);\n}\n```\n\nThis outputs something like:\n\n```\nthread 'main' panicked at 'assertion failed:\n`20 is not in range of 10..20` - it should have been in this range, src/main.rs:292:5\n```\n\nAnother example:\n\n```rust\nuse all_asserts::{assert_range, assert_nrange};\nfn main() {\n  assert_range!(1.0..=2.0, 1.5);\n  // You can also add a debug message if the assertion fails\n  assert_nrange!(\n    1.0..=2.0, 1.5, \"Oops! 1.5 is in the interval [1.0,2.0]\"\n  );\n}\n```\n\nThis outputs:\n\n```\nthread 'main' panicked at 'assertion failed: `1.5 is in range of 1.0..2.0` - it should not have been in this range: Oops! 1.5 is in the interval [1.0,2.0]', src/main.rs:295:5\n```\n\nAn example using `assert_lt!` :\n\n```\nthread 'main' panicked at 'assertion failed: `(left \u003c right) but here (left \u003e= right)`\n  left: `100` ,\n right: `200` ', src/main.rs:79:5\n```\n\nIsn't that much better than what the current macros provide? Well, I'll leave you to decide!\n\n## Available macros\n\nThe name of the assert pretty much tells you everything:\n\n- `assert_gt!(a, b)` -\u003e Will panic if a is not greater than b\n- `assert_ge!(a, b)` -\u003e Will panic if a is not greater than or equal to b\n- `assert_lt!(a, b)` -\u003e Will panic if a is not less than b\n- `assert_le!(a, b)` -\u003e Will panic if a is not greater than or equal to b\n- `assert_range!((x..y), b)` -\u003e Will panic if b is not within the range [x, y)\n- `assert_nrange!((x..y), b)` -\u003e Will panic if b is within the range [x, y)\n- `assert_near!(a, b, e)` -\u003e Will panic if b is not within +/- e of a; i.e. b is within the range [a - e, a + e]\n- `assert_true!(a)` -\u003e Will panic if a is not true\n- `assert_false!(a)` -\u003e Will panic if a is not false\n\n`debug_*` variants of the macros are also available, which only work on builds with debug assertions enabled (usually builds produced by running `cargo build` or `cargo test` ).\n\n## Building\n\nSimply run:\n\n```shell\n$ git clone https://github.com/ohsayan/all_asserts.git\n$ cd all_asserts\n$ cargo build\n```\n\nAnd for testing:\n\n```shell\n$ cargo test\n```\n\n## Contributing\n\nYour welcome to!\n\n\u003e \"No man is an island!\"\n\nAnd I always stick to that belief! Please help me out in better formatting the output to make debugging easier. If you find an issue, go ahead a create one! (All doubts, questions and ideas are welcome)\n\n## License\n\nThis project is licensed under the [Apache-2.0 License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohsayan%2Fall_asserts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fohsayan%2Fall_asserts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohsayan%2Fall_asserts/lists"}