{"id":16847238,"url":"https://github.com/koute/static_test","last_synced_at":"2025-04-11T06:33:21.979Z","repository":{"id":57668572,"uuid":"216367587","full_name":"koute/static_test","owner":"koute","description":"Attribute macro for writing tests which check that a given condition ALWAYS holds true or that a given code path is ALWAYS unreachable","archived":false,"fork":false,"pushed_at":"2019-10-20T13:43:12.000Z","size":9,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T04:27:09.895Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/koute.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-20T13:37:49.000Z","updated_at":"2022-05-25T22:08:28.000Z","dependencies_parsed_at":"2022-08-27T03:25:09.046Z","dependency_job_id":null,"html_url":"https://github.com/koute/static_test","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koute%2Fstatic_test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koute%2Fstatic_test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koute%2Fstatic_test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koute%2Fstatic_test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koute","download_url":"https://codeload.github.com/koute/static_test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247875871,"owners_count":21011015,"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":[],"created_at":"2024-10-13T13:07:11.867Z","updated_at":"2025-04-11T06:33:21.923Z","avatar_url":"https://github.com/koute.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://api.travis-ci.org/koute/static_test.svg)](https://travis-ci.org/koute/static_test)\n\n# `#[static_test]`\n\n[![Documentation](https://docs.rs/static_test/badge.svg)](https://docs.rs/static_test/*/static_test/)\n\n## Example\n\n```rust\nuse static_test::static_test;\n\n#[static_test]\nfn test_slice_get_will_always_succeed_if_length_is_known( buffer: \u0026[u8] ) -\u003e u8 {\n    assume!( buffer.len() == 1 );\n    match buffer.get( 0 ) {\n        Some( \u0026value ) =\u003e value,\n        None =\u003e static_unreachable!()\n    }\n}\n\n#[static_test]\nfn test_multiplication( value: u8 ) {\n    assume!( value == 2 );\n    static_assert!( value * 10 == 20 );\n}\n```\n\nYou can specify arbitrary types as parameters and as the return type of every\nfunction you mark as `#[static_test]`. The bodies of those functions will never\nactually be executed, however every `static_assert!` and `static_unreachable!`\nwill still be indirectly checked.\n\nIf the compiler can't prove that every `static_assert!` will *always* hold true\nand that every `static_unreachable!` will *always* be unreachable then an error\nwill be generated at link time.\n\nEvery function marked as `#[static_test]` will be turned into a `#[test]` function.\n\nThe `assume!`, `static_assert!` and `static_unreachable!` macros are defined\nby the procedural macro and are only available inside functions marked as `#[static_test]`.\n\n## Caveats\n\n* This requires at least Rust 1.40.\n* This requires the linker to run, so it will have no effect on `cargo check`.\n* This will only work when you compile your code with optimizations turned on,\n  as it depends on the optimizer to remove unreachable `static_assert!`s and `static_unreachable!`s.\n* *If* an assertion fails the error message [will not be great](https://asciinema.org/a/cvpHYZD6I3YR8TM3xfYfhyHwf).\n\n## Acknowledgments\n\nThis is inspired by the [no_panic](https://github.com/dtolnay/no-panic) crate.\n\n## License\n\nLicensed under either of\n\n  * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n  * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoute%2Fstatic_test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoute%2Fstatic_test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoute%2Fstatic_test/lists"}