rstest-0.26.1/.cargo_vcs_info.json0000644000000001440000000000100124450ustar { "git": { "sha1": "7a326c87e882d2da1f3f97c40e6b04757f085679" }, "path_in_vcs": "rstest" }rstest-0.26.1/Cargo.lock0000644000000676450000000000100104430ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "actix-macros" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" dependencies = [ "quote", "syn 2.0.93", ] [[package]] name = "actix-rt" version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24eda4e2a6e042aa4e55ac438a2ae052d3b5da0ecf83d7411e1a368946925208" dependencies = [ "actix-macros", "futures-core", "tokio", ] [[package]] name = "addr2line" version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ "gimli", ] [[package]] name = "adler2" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "aho-corasick" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "async-attributes" version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" dependencies = [ "quote", "syn 1.0.109", ] [[package]] name = "async-channel" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" dependencies = [ "concurrent-queue", "event-listener 2.5.3", "futures-core", ] [[package]] name = "async-channel" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b47800b0be77592da0afd425cc03468052844aff33b84e33cc696f64e77b6a" dependencies = [ "concurrent-queue", "event-listener-strategy", "futures-core", "pin-project-lite", ] [[package]] name = "async-executor" version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30ca9a001c1e8ba5149f91a74362376cc6bc5b919d92d988668657bd570bdcec" dependencies = [ "async-task", "concurrent-queue", "fastrand", "futures-lite", "slab", ] [[package]] name = "async-global-executor" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" dependencies = [ "async-channel 2.3.1", "async-executor", "async-io", "async-lock", "blocking", "futures-lite", "once_cell", ] [[package]] name = "async-io" version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a2b323ccce0a1d90b449fd71f2a06ca7faa7c54c2751f06c9bd851fc061059" dependencies = [ "async-lock", "cfg-if", "concurrent-queue", "futures-io", "futures-lite", "parking", "polling", "rustix", "slab", "tracing", "windows-sys 0.59.0", ] [[package]] name = "async-lock" version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18" dependencies = [ "event-listener 5.3.1", "event-listener-strategy", "pin-project-lite", ] [[package]] name = "async-std" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c634475f29802fde2b8f0b505b1bd00dfe4df7d4a000f0b36f7671197d5c3615" dependencies = [ "async-attributes", "async-channel 1.9.0", "async-global-executor", "async-io", "async-lock", "crossbeam-utils", "futures-channel", "futures-core", "futures-io", "futures-lite", "gloo-timers", "kv-log-macro", "log", "memchr", "once_cell", "pin-project-lite", "pin-utils", "slab", "wasm-bindgen-futures", ] [[package]] name = "async-task" version = "4.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" [[package]] name = "atomic-waker" version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", "windows-targets", ] [[package]] name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "blocking" version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "703f41c54fc768e63e091340b424302bb1c29ef4aa0c7f10fe849dfb114d29ea" dependencies = [ "async-channel 2.3.1", "async-task", "futures-io", "futures-lite", "piper", ] [[package]] name = "bumpalo" version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "concurrent-queue" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", "windows-sys 0.59.0", ] [[package]] name = "event-listener" version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "event-listener" version = "5.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" dependencies = [ "concurrent-queue", "parking", "pin-project-lite", ] [[package]] name = "event-listener-strategy" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c3e4e0dd3673c1139bf041f3008816d9cf2946bbfac2945c09e523b8d7b05b2" dependencies = [ "event-listener 5.3.1", "pin-project-lite", ] [[package]] name = "fastrand" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "futures-channel" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", ] [[package]] name = "futures-core" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-io" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cef40d21ae2c515b51041df9ed313ed21e572df340ea58a922a0aefe7e8891a1" dependencies = [ "fastrand", "futures-core", "futures-io", "parking", "pin-project-lite", ] [[package]] name = "futures-macro" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", "syn 2.0.93", ] [[package]] name = "futures-task" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-core", "futures-macro", "futures-task", "pin-project-lite", "pin-utils", "slab", ] [[package]] name = "gimli" version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "glob" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" [[package]] name = "gloo-timers" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" dependencies = [ "futures-channel", "futures-core", "js-sys", "wasm-bindgen", ] [[package]] name = "hashbrown" version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "hermit-abi" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" [[package]] name = "indexmap" version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown", ] [[package]] name = "js-sys" version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" dependencies = [ "once_cell", "wasm-bindgen", ] [[package]] name = "kv-log-macro" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" dependencies = [ "log", ] [[package]] name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "linux-raw-sys" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", ] [[package]] name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" dependencies = [ "value-bag", ] [[package]] name = "macro_rules_attribute" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65049d7923698040cd0b1ddcced9b0eb14dd22c5f86ae59c3740eab64a676520" dependencies = [ "macro_rules_attribute-proc_macro", "paste", ] [[package]] name = "macro_rules_attribute-proc_macro" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "670fdfda89751bc4a84ac13eaa63e205cf0fd22b4c9a5fbfa085b63c1f1d3a30" [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "miniz_oxide" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" dependencies = [ "adler2", ] [[package]] name = "mio" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" dependencies = [ "libc", "wasi", "windows-sys 0.52.0", ] [[package]] name = "object" version = "0.36.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" dependencies = [ "memchr", ] [[package]] name = "once_cell" version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "parking" version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" [[package]] name = "parking_lot" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", "windows-targets", ] [[package]] name = "paste" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pin-project-lite" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "pin-utils" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "piper" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96c8c490f422ef9a4efd2cb5b42b76c8613d7e7dfc1caf667b8a3350a5acc066" dependencies = [ "atomic-waker", "fastrand", "futures-io", ] [[package]] name = "polling" version = "3.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a604568c3202727d1507653cb121dbd627a58684eb09a820fd746bee38b4442f" dependencies = [ "cfg-if", "concurrent-queue", "hermit-abi", "pin-project-lite", "rustix", "tracing", "windows-sys 0.59.0", ] [[package]] name = "proc-macro-crate" version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" dependencies = [ "toml_edit", ] [[package]] name = "proc-macro2" version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" dependencies = [ "bitflags", ] [[package]] name = "regex" version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", "regex-automata", "regex-syntax", ] [[package]] name = "regex-automata" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "relative-path" version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2" [[package]] name = "rstest" version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fc39292f8613e913f7df8fa892b8944ceb47c247b78e1b1ae2f09e019be789d" dependencies = [ "rstest_macros 0.25.0", "rustc_version", ] [[package]] name = "rstest" version = "0.26.1" dependencies = [ "actix-rt", "async-std", "futures-timer", "futures-util", "lazy_static", "macro_rules_attribute", "rstest 0.25.0", "rstest_macros 0.26.1", "smol-macros", "temp_testdir", "tokio", "unindent", ] [[package]] name = "rstest_macros" version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f168d99749d307be9de54d23fd226628d99768225ef08f6ffb52e0182a27746" dependencies = [ "cfg-if", "glob", "proc-macro2", "quote", "regex", "relative-path", "rustc_version", "syn 2.0.93", "unicode-ident", ] [[package]] name = "rstest_macros" version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c845311f0ff7951c5506121a9ad75aec44d083c31583b2ea5a30bcb0b0abba0" dependencies = [ "cfg-if", "glob", "proc-macro-crate", "proc-macro2", "quote", "regex", "relative-path", "rustc_version", "syn 2.0.93", "unicode-ident", ] [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc_version" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] [[package]] name = "rustix" version = "0.38.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys 0.59.0", ] [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" [[package]] name = "signal-hook-registry" version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] [[package]] name = "slab" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smol-macros" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfcaedb62e0475a6898988138995ec7b1e5d116167a72bb12c7b59d0649fbbc2" dependencies = [ "async-executor", "async-io", "async-lock", "event-listener 5.3.1", "futures-lite", ] [[package]] name = "socket2" version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" dependencies = [ "libc", "windows-sys 0.52.0", ] [[package]] name = "syn" version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "syn" version = "2.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "temp_testdir" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "921f1e9c427802414907a48b21a6504ff6b3a15a1a3cf37e699590949ad9befc" [[package]] name = "tokio" version = "1.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" dependencies = [ "backtrace", "libc", "mio", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", "syn 2.0.93", ] [[package]] name = "toml_datetime" version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "toml_datetime", "winnow", ] [[package]] name = "tracing" version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" [[package]] name = "unicode-ident" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unindent" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" [[package]] name = "value-bag" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ef4c4aa54d5d05a279399bfa921ec387b7aba77caf7a682ae8d86785b8fdad2" [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" dependencies = [ "cfg-if", "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" dependencies = [ "bumpalo", "log", "proc-macro2", "quote", "syn 2.0.93", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" version = "0.4.49" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" dependencies = [ "cfg-if", "js-sys", "once_cell", "wasm-bindgen", "web-sys", ] [[package]] name = "wasm-bindgen-macro" version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" dependencies = [ "quote", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", "syn 2.0.93", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" [[package]] name = "web-sys" version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" dependencies = [ "js-sys", "wasm-bindgen", ] [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ "windows-targets", ] [[package]] name = "windows-sys" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6f5bb5257f2407a5425c6e749bfd9692192a73e70a6060516ac04f889087d68" dependencies = [ "memchr", ] rstest-0.26.1/Cargo.toml0000644000000041420000000000100104450ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.70.0" name = "rstest" version = "0.26.1" authors = ["Michele d'Amico "] build = false autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = """ Rust fixture based test framework. It use procedural macro to implement fixtures and table based tests. """ homepage = "https://github.com/la10736/rstest" readme = "README.md" keywords = [ "test", "fixture", ] categories = ["development-tools::testing"] license = "MIT OR Apache-2.0" repository = "https://github.com/la10736/rstest" [features] async-timeout = [ "dep:futures-timer", "dep:futures-util", "rstest_macros/async-timeout", ] crate-name = ["rstest_macros/crate-name"] default = [ "async-timeout", "crate-name", ] [lib] name = "rstest" path = "src/lib.rs" [[test]] name = "integration" path = "tests/integration.rs" [dependencies.futures-timer] version = "3.0.3" optional = true [dependencies.futures-util] version = "0.3.30" optional = true [dependencies.rstest_macros] version = "0.26.1" default-features = false [dev-dependencies.actix-rt] version = "2.9.0" [dev-dependencies.async-std] version = "1.13.0" features = ["attributes"] [dev-dependencies.lazy_static] version = "1.5.0" [dev-dependencies.macro_rules_attribute] version = "0.2.0" [dev-dependencies.mytest] version = "0.25.0" default-features = false package = "rstest" [dev-dependencies.smol-macros] version = "0.1.1" [dev-dependencies.temp_testdir] version = "0.2.3" [dev-dependencies.tokio] version = "1.38.1" features = [ "rt", "macros", ] [dev-dependencies.unindent] version = "0.2.3" rstest-0.26.1/Cargo.toml.orig000064400000000000000000000024431046102023000141300ustar 00000000000000[package] authors = ["Michele d'Amico "] categories = ["development-tools::testing"] description = """ Rust fixture based test framework. It use procedural macro to implement fixtures and table based tests. """ edition = "2021" homepage = "https://github.com/la10736/rstest" keywords = ["test", "fixture"] license = "MIT OR Apache-2.0" name = "rstest" readme = "README.md" repository = "https://github.com/la10736/rstest" rust-version = "1.70.0" version = "0.26.1" [features] async-timeout = [ "dep:futures-timer", "dep:futures-util", "rstest_macros/async-timeout", ] crate-name = ["rstest_macros/crate-name"] default = ["async-timeout", "crate-name"] [lib] [dependencies] futures-timer = { version = "3.0.3", optional = true } futures-util = { version = "0.3.30", optional = true } rstest_macros = { version = "0.26.1", path = "../rstest_macros", default-features = false } [dev-dependencies] actix-rt = "2.9.0" async-std = { version = "1.13.0", features = ["attributes"] } lazy_static = "1.5.0" macro_rules_attribute = "0.2.0" mytest = { package = "rstest", version = "0.25.0", default-features = false } rstest_test = { path = "../rstest_test" } smol-macros = "0.1.1" temp_testdir = "0.2.3" tokio = { version = "1.38.1", features = ["rt", "macros"] } unindent = "0.2.3" rstest-0.26.1/LICENSE-APACHE000064400000000000000000000261301046102023000131640ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2018-19 Michele d'Amico Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. rstest-0.26.1/LICENSE-MIT000064400000000000000000000020441046102023000126720ustar 00000000000000Copyright 2018-19 Michele d'Amico Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rstest-0.26.1/README.md000064400000000000000000000430711046102023000125220ustar 00000000000000[![Crate][crate-image]][crate-link] [![Docs][docs-image]][docs-link] [![Status][test-action-image]][test-action-link] [![Apache 2.0 Licensed][license-apache-image]][license-apache-link] [![MIT Licensed][license-mit-image]][license-mit-link] # Fixture-based test framework for Rust ## Introduction `rstest` uses procedural macros to help you on writing fixtures and table-based tests. To use it, add the following lines to your `Cargo.toml` file: ```toml [dev-dependencies] rstest = "0.26.1" ``` ### Features - `async-timeout`: `timeout` for `async` tests (Default enabled) - `crate-name`: Import `rstest` package with different name (Default enabled) ### Fixture The core idea is that you can inject your test dependencies by passing them as test arguments. In the following example, a `fixture` is defined and then used in two tests, simply providing it as an argument: ```rust use rstest::*; #[fixture] pub fn fixture() -> u32 { 42 } #[rstest] fn should_success(fixture: u32) { assert_eq!(fixture, 42); } #[rstest] fn should_fail(fixture: u32) { assert_ne!(fixture, 42); } ``` ### Parametrize You can also inject values in some other ways. For instance, you can create a set of tests by simply providing the injected values for each case: `rstest` will generate an independent test for each case. ```rust use rstest::rstest; #[rstest] #[case(0, 0)] #[case(1, 1)] #[case(2, 1)] #[case(3, 2)] #[case(4, 3)] fn fibonacci_test(#[case] input: u32, #[case] expected: u32) { assert_eq!(expected, fibonacci(input)) } ``` Running `cargo test` in this case executes five tests: ```bash running 5 tests test fibonacci_test::case_1 ... ok test fibonacci_test::case_2 ... ok test fibonacci_test::case_3 ... ok test fibonacci_test::case_4 ... ok test fibonacci_test::case_5 ... ok test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ``` If you need to just providing a bunch of values for which you need to run your test, you can use `#[values(list, of, values)]` argument attribute: ```rust use rstest::rstest; #[rstest] fn should_be_invalid( #[values(None, Some(""), Some(" "))] value: Option<&str> ) { assert!(!valid(value)) } ``` Or create a _matrix_ test by using _list of values_ for some variables that will generate the cartesian product of all the values. #### Use Parametrize definition in more tests If you need to use a test list for more than one test you can use [`rstest_reuse`][reuse-crate-link] crate. With this helper crate you can define a template and use it everywhere. ```rust use rstest::rstest; use rstest_reuse::{self, *}; #[template] #[rstest] #[case(2, 2)] #[case(4/2, 2)] fn two_simple_cases(#[case] a: u32, #[case] b: u32) {} #[apply(two_simple_cases)] fn it_works(#[case] a: u32, #[case] b: u32) { assert!(a == b); } ``` See [`rstest_reuse`][reuse-crate-link] for more details. #### Feature flagged cases In case you want certain test cases to only be present if a certain feature is enabled, use `#[cfg_attr(feature = …, case(…))]`: ```rust use rstest::rstest; #[rstest] #[case(2, 2)] #[cfg_attr(feature = "frac", case(4/2, 2))] fn it_works(#[case] a: u32, #[case] b: u32) { assert!(a == b); } ``` This also works with [`rstest_reuse`][reuse-crate-link]. ### Magic Conversion If you need a value where its type implement `FromStr()` trait you can use a literal string to build it: ```rust # use rstest::rstest; # use std::net::SocketAddr; #[rstest] #[case("1.2.3.4:8080", 8080)] #[case("127.0.0.1:9000", 9000)] fn check_port(#[case] addr: SocketAddr, #[case] expected: u16) { assert_eq!(expected, addr.port()); } ``` You can use this feature also in value list and in fixture default value. ### Async `rstest` supports async tests, but makes no assumptions about what async runtime you are using. Async tests require either an [explicit test attribute](#explicit-test-attribute) or an [implicit test attribute](#implicit-test-attribute). You are responsible for providing any appropriate peer dependencies to run your async tests. If your test input is an async value (fixture or test parameter) you can use `#[future]` attribute to remove `impl Future` boilerplate and just use `T`: ```rust use rstest::*; #[fixture] async fn base() -> u32 { 42 } #[rstest] #[tokio::test] #[case(21, async { 2 })] #[case(6, async { 7 })] async fn my_async_test( #[future] base: u32, #[case] expected: u32, #[future] #[case] div: u32 ) { assert_eq!(expected, base.await / div.await); } ``` As you noted you should `.await` all _future_ values and this sometimes can be really boring. In this case you can use `#[future(awt)]` to _awaiting_ an input or annotating your function with `#[awt]` attributes to globally `.await` all your _future_ inputs. Previous code can be simplified as follows: ```rust use rstest::*; # #[fixture] # async fn base() -> u32 { 42 } #[rstest] #[tokio::test] #[case(21, async { 2 })] #[case(6, async { 7 })] #[awt] async fn global( #[future] base: u32, #[case] expected: u32, #[future] #[case] div: u32 ) { assert_eq!(expected, base / div); } #[rstest] #[tokio::test] #[case(21, async { 2 })] #[case(6, async { 7 })] async fn single( #[future] base: u32, #[case] expected: u32, #[future(awt)] #[case] div: u32 ) { assert_eq!(expected, base.await / div); } ``` ### Files path as input arguments If you need to create a test for each file in a given location you can use `#[files("glob path syntax")]` attribute to generate a test for each file that satisfy the given glob path. ```rust #[rstest] fn for_each_file( #[files("src/**/*.rs")] #[exclude("test")] path: PathBuf ) { assert!(check_file(&path)) } ``` The default behavior is to ignore the files that start with `"."`, but you can modify this by use `#[include_dot_files]` attribute. The `files` attribute can be used more than once on the same variable, and you can also create some custom exclusion rules with the `#[exclude("regex")]` attributes that filter out all paths that verify the regular expression. You can pass in environment variables by using `${ENV_VAR_NAME}` in the glob path, e.g. `#[files("${SOME_ENV}/hello")]`. To set a default value for the environment variable, use `${ENV_VAR_NAME:-default_value}`. Files are resolved at compile time against your Cargo project root (the `CARGO_MANIFEST_DIR` environment variable). If you need to change this behavior, you can use the `#[base_dir = "..."]` attribute to specify a different base directory. That directory MUST exist, and will be used as the root for the files, as well as to resolve the relative path when creating the test name. Similar to the `files` attribute, you can use `${ENV_VAR_NAME}` in the `base_dir`. The `#[files(...)]` attribute ignores matched directory paths by default, returning only file paths. If you need the test cases to include directories found by the glob pattern, use the `#[dirs]` attribute in conjunction with `#[files(...)]`. ### Use `#[once]` Fixture If you need to a fixture that should be initialized just once for all tests you can use `#[once]` attribute. `rstest` call your fixture function just once and return a reference to your function result to all your tests: ```rust #[fixture] #[once] fn once_fixture() -> i32 { 42 } #[rstest] fn single(once_fixture: &i32) { // All tests that use once_fixture will share the same reference to once_fixture() // function result. assert_eq!(&42, once_fixture) } ``` ### Test `#[timeout()]` You can define an execution timeout for your tests with `#[timeout()]` attribute. Timeout works both for sync and async tests and is runtime agnostic. `#[timeout()]` take an expression that should return a `std::time::Duration`. Follow a simple async example: ```rust use rstest::*; use std::time::Duration; async fn delayed_sum(a: u32, b: u32, delay: Duration) -> u32 { async_std::task::sleep(delay).await; a + b } #[rstest] #[async_std::test] #[timeout(Duration::from_millis(80))] async fn single_pass() { assert_eq!(4, delayed_sum(2, 2, ms(10)).await); } ``` In this case test pass because the delay is just 10 milliseconds and timeout is 80 milliseconds. You can use `timeout` attribute like any other attribute in your tests, and you can override a group timeout with a case specific one. In the follow example we have 3 tests where first and third use 100 milliseconds but the second one use 10 milliseconds. Another valuable point in this example is to use an expression to compute the duration. ```rust fn ms(ms: u32) -> Duration { Duration::from_millis(ms.into()) } #[rstest] #[case::pass(ms(1), 4)] #[timeout(ms(10))] #[case::fail_timeout(ms(60), 4)] #[case::fail_value(ms(1), 5)] #[timeout(ms(100))] async fn group_one_timeout_override(#[case] delay: Duration, #[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay).await); } ``` If you want to use `timeout` for `async` test you need to use `async-timeout` feature (enabled by default). ### Default timeout You can set a default timeout for test using the `RSTEST_TIMEOUT` environment variable. The value is in seconds and is evaluated on test compile time. ### Explicit Test Attribute If your test contains an attribute `#[test_attr(...)]`, this is an explicit test attribute declaration. The contents of the parentheses will be inserted as an attribute of your test. This allows for arbitrary test attribute syntax. For instance, if you want to test an async function with [`smol_macros::test`](https://docs.rs/smol-macros/0.1.1/smol_macros/macro.test.html), you can write ```rust use rstest::*; use macro_rules_attribute::apply; use smol_macros::test; use std::future::Future; #[rstest] #[case(2, async { 4 })] #[case(21, async { 42 })] #[test_attr(apply(test))] async fn my_async_test(#[case] a: u32, #[case] #[future] result: u32) { assert_eq!(2 * a, result.await); } ``` When using an explicit test attribute, ensure it appears after any `#[case()]` attributes so that the attribute binds to the test function and not the case. ### Implicit Test Attribute If your test contains an attribute whose path ends in `test`, this is treated as an implicit test attribute, and replaces the default `#[test]` attribute. Simply including the attribute in your test's attribute list is all that is required. For instance, if you want to test an async function with the `actix_rt::test` attribute, you can just write: ```rust use rstest::*; use actix_rt; use std::future::Future; #[rstest] #[case(2, async { 4 })] #[case(21, async { 42 })] #[actix_rt::test] async fn my_async_test(#[case] a: u32, #[case] #[future] result: u32) { assert_eq!(2 * a, result.await); } ``` Implicit test attributes have a lower priority than [`explicit test attributes`](#explicit-test-attribute). If you have an unrelated attribute whose path ends in `test`, you should declare an explicit test attribute for deconfliction. When using an implicit test attribute, ensure it appears after any `#[case()]` attributes so that the attribute binds to the test function and not the case. ### Default Test Attribute Synchronous tests use `#[test]` as the default test attribute if nothing else is supplied explicitly or implicitly. Asynchronous tests will fail to compile if no test attribute is specified explicitly or implicitly. ## Test `Context` object You can have a [`Context`] object for your test just by annotate an argument by `#[context]` attribute. This object contains some useful information both to implement simple logics and debugging stuff. ```rust use rstest::{rstest, Context}; #[rstest] #[case::a_description(42)] fn my_test(#[context] ctx: Context, #[case] _c: u32) { assert_eq!("my_test", ctx.name); assert_eq!(Some("a_description"), ctx.description); assert_eq!(Some(0), ctx.case); std::thread::sleep(std::time::Duration::from_millis(100)); assert!(ctx.start.elapsed() >= std::time::Duration::from_millis(100)); } ``` ## Local lifetime and `#[by_ref]` attribute In some cases you may want to use a local lifetime for some arguments of your test. In these cases you can use the `#[by_ref]` attribute then use the reference instead the value. ```rust enum E<'a> { A(bool), B(&'a Cell>), } fn make_e_from_bool<'a>(_bump: &'a (), b: bool) -> E<'a> { E::A(b) } #[fixture] fn bump() -> () {} #[rstest] #[case(true, E::A(true))] fn it_works<'a>(#[by_ref] bump: &'a (), #[case] b: bool, #[case] expected: E<'a>) { let actual = make_e_from_bool(&bump, b); assert_eq!(actual, expected); } ``` You can use `#[by_ref]` attribute for all arguments of your test and not just for fixture but also for cases, values and files. ## Complete Example All these features can be used together with a mixture of fixture variables, fixed cases and a bunch of values. For instance, you might need two test cases which test for panics, one for a logged-in user and one for a guest user. ```rust use rstest::*; #[fixture] fn repository() -> InMemoryRepository { let mut r = InMemoryRepository::default(); // fill repository with some data r } #[fixture] fn alice() -> User { User::logged("Alice", "2001-10-04", "London", "UK") } #[rstest] #[case::authorized_user(alice())] // We can use `fixture` also as standard function #[case::guest(User::Guest)] // We can give a name to every case : `guest` in this case // and `authorized_user` #[should_panic(expected = "Invalid query error")] // We would test a panic fn should_be_invalid_query_error( repository: impl Repository, #[case] user: User, #[values(" ", "^%$some#@invalid!chars", ".n.o.d.o.t.s.")] query: &str, ) { repository.find_items(&user, query).unwrap(); } ``` This example will generate exactly 6 tests grouped by 2 different cases: ```text running 6 tests test should_be_invalid_query_error::case_1_authorized_user::query_1_____ - should panic ... ok test should_be_invalid_query_error::case_2_guest::query_2_____someinvalid_chars__ - should panic ... ok test should_be_invalid_query_error::case_1_authorized_user::query_2_____someinvalid_chars__ - should panic ... ok test should_be_invalid_query_error::case_2_guest::query_3____n_o_d_o_t_s___ - should panic ... ok test should_be_invalid_query_error::case_1_authorized_user::query_3____n_o_d_o_t_s___ - should panic ... ok test should_be_invalid_query_error::case_2_guest::query_1_____ - should panic ... ok test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s ``` Note that the names of the values _try_ to convert the input expression in a Rust valid identifier name to help you find which tests fail. ## More Is that all? Not quite yet! A fixture can be injected by another fixture, and they can be called using just some of its arguments. ```rust #[fixture] fn user(#[default("Alice")] name: &str, #[default(22)] age: u8) -> User { User::new(name, age) } #[rstest] fn is_alice(user: User) { assert_eq!(user.name(), "Alice") } #[rstest] fn is_22(user: User) { assert_eq!(user.age(), 22) } #[rstest] fn is_bob(#[with("Bob")] user: User) { assert_eq!(user.name(), "Bob") } #[rstest] fn is_42(#[with("", 42)] user: User) { assert_eq!(user.age(), 42) } ``` As you noted you can provide default values without the need of a fixture to define it. Finally, if you need tracing the input values you can just add the `trace` attribute to your test to enable the dump of all input variables. ```rust #[rstest] #[case(42, "FortyTwo", ("minus twelve", -12))] #[case(24, "TwentyFour", ("minus twentyfour", -24))] #[trace] //This attribute enable tracing fn should_fail(#[case] number: u32, #[case] name: &str, #[case] tuple: (&str, i32)) { assert!(false); // <- stdout come out just for failed tests } ``` ```text running 2 tests test should_fail::case_1 ... FAILED test should_fail::case_2 ... FAILED failures: ---- should_fail::case_1 stdout ---- ------------ TEST ARGUMENTS ------------ number = 42 name = "FortyTwo" tuple = ("minus twelve", -12) -------------- TEST START -------------- thread 'should_fail::case_1' panicked at 'assertion failed: false', src/main.rs:64:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. ---- should_fail::case_2 stdout ---- ------------ TEST ARGUMENTS ------------ number = 24 name = "TwentyFour" tuple = ("minus twentyfour", -24) -------------- TEST START -------------- thread 'should_fail::case_2' panicked at 'assertion failed: false', src/main.rs:64:5 failures: should_fail::case_1 should_fail::case_2 test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out ``` In case one or more variables don't implement the `Debug` trait, an error is raised, but it's also possible to exclude a variable using the `#[notrace]` argument attribute. You can learn more on [Docs][docs-link] and find more examples in [`tests/resources`](/rstest/tests/resources) directory. ## Changelog See [CHANGELOG.md](/CHANGELOG.md) ## License Licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](/LICENSE-APACHE) or [license-apache-link]) * MIT license [LICENSE-MIT](/LICENSE-MIT) or [license-MIT-link] at your option. [//]: # (links) [crate-image]: https://img.shields.io/crates/v/rstest.svg [crate-link]: https://crates.io/crates/rstest [docs-image]: https://docs.rs/rstest/badge.svg [docs-link]: https://docs.rs/rstest/ [test-action-image]: https://github.com/la10736/rstest/workflows/Test/badge.svg [test-action-link]: https://github.com/la10736/rstest/actions?query=workflow:Test [license-apache-image]: https://img.shields.io/badge/license-Apache2.0-blue.svg [license-mit-image]: https://img.shields.io/badge/license-MIT-blue.svg [license-apache-link]: http://www.apache.org/licenses/LICENSE-2.0 [license-MIT-link]: http://opensource.org/licenses/MIT [reuse-crate-link]: https://crates.io/crates/rstest_reuse rstest-0.26.1/src/context.rs000064400000000000000000000015131046102023000140570ustar 00000000000000/// A test context. #[non_exhaustive] pub struct Context { /// The complete module test path pub module: &'static str, /// The test function name pub name: &'static str, /// The test description if present pub description: Option<&'static str>, /// The cardinal case number if it's a test case pub case: Option, /// Start time pub start: std::time::Instant, } impl Context { /// Create a new test context. This function set also the start time to the current time. pub fn new( module: &'static str, name: &'static str, description: Option<&'static str>, case: Option, ) -> Self { Self { module, name, description, case, start: std::time::Instant::now(), } } } rstest-0.26.1/src/lib.rs000064400000000000000000001371711046102023000131530ustar 00000000000000#![allow(clippy::test_attr_in_doctest)] //! This crate will help you to write simpler tests by leveraging a software testing concept called //! [test fixtures](https://en.wikipedia.org/wiki/Test_fixture#Software). A fixture is something //! that you can use in your tests to encapsulate a test's dependencies. //! //! The general idea is to have smaller tests that only describe the thing you're testing while you //! hide the auxiliary utilities your tests make use of somewhere else. //! For instance, if you have an application that has many tests with users, shopping baskets, and //! products, you'd have to create a user, a shopping basket, and product every single time in //! every test which becomes unwieldy quickly. To cut down on that repetition, you can //! instead use fixtures to declare that you need those objects for your function and the fixtures //! will take care of creating those by themselves. Focus on the important stuff in your tests! //! //! In `rstest` a fixture is a function that can return any kind of valid Rust type. This //! effectively means that your fixtures are not limited by the kind of data they can return. //! A test can consume an arbitrary number of fixtures at the same time. //! //! ## What //! //! The `rstest` crate defines the following procedural macros: //! //! - [`[rstest]`](macro@rstest): Declare that a test or a group of tests that may take //! [fixtures](attr.rstest.html#injecting-fixtures), //! [input table](attr.rstest.html#test-parametrized-cases), //! [list of values](attr.rstest.html#values-lists) or read data from //! [files](attr.rstest.html#files-path-as-input-arguments). //! - [`[fixture]`](macro@fixture): To mark a function as a fixture. //! //! ## Why //! //! Very often in Rust we write tests like this //! //! ``` //! #[test] //! fn should_process_two_users() { //! let mut repository = create_repository(); //! repository.add("Bob", 21); //! repository.add("Alice", 22); //! //! let processor = string_processor(); //! processor.send_all(&repository, "Good Morning"); //! //! assert_eq!(2, processor.output.find("Good Morning").count()); //! assert!(processor.output.contains("Bob")); //! assert!(processor.output.contains("Alice")); //! } //! ``` //! //! By making use of [`[rstest]`](macro@rstest) we can isolate the dependencies `empty_repository` and //! `string_processor` by passing them as fixtures: //! //! ``` //! # use rstest::*; //! #[rstest] //! fn should_process_two_users(mut empty_repository: impl Repository, //! string_processor: FakeProcessor) { //! empty_repository.add("Bob", 21); //! empty_repository.add("Alice", 22); //! //! string_processor.send_all("Good Morning"); //! //! assert_eq!(2, string_processor.output.find("Good Morning").count()); //! assert!(string_processor.output.contains("Bob")); //! assert!(string_processor.output.contains("Alice")); //! } //! ``` //! //! ... or if you use `"Alice"` and `"Bob"` in other tests, you can isolate `alice_and_bob` fixture //! and use it directly: //! //! ``` //! # use rstest::*; //! # trait Repository { fn add(&mut self, name: &str, age: u8); } //! # struct Rep; //! # impl Repository for Rep { fn add(&mut self, name: &str, age: u8) {} } //! # #[fixture] //! # fn empty_repository() -> Rep { //! # Rep //! # } //! #[fixture] //! fn alice_and_bob(mut empty_repository: impl Repository) -> impl Repository { //! empty_repository.add("Bob", 21); //! empty_repository.add("Alice", 22); //! empty_repository //! } //! //! #[rstest] //! fn should_process_two_users(alice_and_bob: impl Repository, //! string_processor: FakeProcessor) { //! string_processor.send_all("Good Morning"); //! //! assert_eq!(2, string_processor.output.find("Good Morning").count()); //! assert!(string_processor.output.contains("Bob")); //! assert!(string_processor.output.contains("Alice")); //! } //! ``` //! ## Features //! //! - `async-timeout`: `timeout` for `async` tests (Default enabled) //! - `crate-name`: Import `rstest` package with different name (Default enabled) //! //! ## Injecting fixtures as function arguments //! //! `rstest` functions can receive fixtures by using them as input arguments. //! A function decorated with [`[rstest]`](attr.rstest.html#injecting-fixtures) //! will resolve each argument name by call the fixture function. //! Fixtures should be annotated with the [`[fixture]`](macro@fixture) attribute. //! //! Fixtures will be resolved like function calls by following the standard resolution rules. //! Therefore, an identically named fixture can be use in different context. //! //! ``` //! # use rstest::*; //! # trait Repository { } //! # #[derive(Default)] //! # struct DataSet {} //! # impl Repository for DataSet { } //! mod empty_cases { //! # use rstest::*; //! # trait Repository { } //! # #[derive(Default)] //! # struct DataSet {} //! # impl Repository for DataSet { } //! use super::*; //! //! #[fixture] //! fn repository() -> impl Repository { //! DataSet::default() //! } //! //! #[rstest] //! fn should_do_nothing(repository: impl Repository) { //! //.. test impl .. //! } //! } //! //! mod non_trivial_case { //! # use rstest::*; //! # trait Repository { } //! # #[derive(Default)] //! # struct DataSet {} //! # impl Repository for DataSet { } //! use super::*; //! //! #[fixture] //! fn repository() -> impl Repository { //! let mut ds = DataSet::default(); //! // Fill your dataset with interesting case //! ds //! } //! //! #[rstest] //! fn should_notify_all_entries(repository: impl Repository) { //! //.. test impl .. //! } //! } //! //! ``` //! //! Last but not least, fixtures can be injected like we saw in `alice_and_bob` example. //! //! ## Creating parametrized tests //! //! You can use also [`[rstest]`](attr.rstest.html#test-parametrized-cases) to create //! simple table-based tests. Let's see the classic Fibonacci example: //! //! ``` //! use rstest::rstest; //! //! #[rstest] //! #[case(0, 0)] //! #[case(1, 1)] //! #[case(2, 1)] //! #[case(3, 2)] //! #[case(4, 3)] //! #[case(5, 5)] //! #[case(6, 8)] //! fn fibonacci_test(#[case] input: u32,#[case] expected: u32) { //! assert_eq!(expected, fibonacci(input)) //! } //! //! fn fibonacci(input: u32) -> u32 { //! match input { //! 0 => 0, //! 1 => 1, //! n => fibonacci(n - 2) + fibonacci(n - 1) //! } //! } //! ``` //! This will generate a bunch of tests, one for every `#[case(a, b)]`. //! //! ## Creating a test for each combinations of given values //! //! In some cases you need to test your code for each combinations of some input values. In this //! cases [`[rstest]`](attr.rstest.html#values-lists) give you the ability to define a list //! of values (rust expressions) to use for an arguments. //! //! ``` //! # use rstest::rstest; //! # #[derive(PartialEq, Debug)] //! # enum State { Init, Start, Processing, Terminated } //! # #[derive(PartialEq, Debug)] //! # enum Event { Error, Fatal } //! # impl State { fn process(self, event: Event) -> Self { self } } //! //! #[rstest] //! fn should_terminate( //! #[values(State::Init, State::Start, State::Processing)] //! state: State, //! #[values(Event::Error, Event::Fatal)] //! event: Event //! ) { //! assert_eq!(State::Terminated, state.process(event)) //! } //! ``` //! //! This will generate a test for each combination of `state` and `event`. //! //! ## Magic Conversion //! //! If you need a value where its type implement `FromStr()` trait you //! can use a literal string to build it. //! //! ``` //! # use rstest::rstest; //! # use std::net::SocketAddr; //! #[rstest] //! #[case("1.2.3.4:8080", 8080)] //! #[case("127.0.0.1:9000", 9000)] //! fn check_port(#[case] addr: SocketAddr, #[case] expected: u16) { //! assert_eq!(expected, addr.port()); //! } //! ``` //! You can use this feature also in value list and in fixture default value. //! #[doc(hidden)] pub mod magic_conversion; #[doc(hidden)] pub mod timeout; #[doc(hidden)] pub mod __std { pub mod sync { pub use std::sync::{Once, OnceLock}; } } mod context; pub use crate::context::Context; /// Define a fixture that you can use in all `rstest`'s test arguments. You should just mark your /// function as `#[fixture]` and then use it as a test's argument. Fixture functions can also /// use other fixtures. /// /// Let's see a trivial example: /// /// ``` /// use rstest::*; /// /// #[fixture] /// fn twenty_one() -> i32 { 21 } /// /// #[fixture] /// fn two() -> i32 { 2 } /// /// #[fixture] /// fn injected(twenty_one: i32, two: i32) -> i32 { twenty_one * two } /// /// #[rstest] /// fn the_test(injected: i32) { /// assert_eq!(42, injected) /// } /// ``` /// /// If the fixture function is an [`async` function](#async) your fixture become an `async` /// fixture. /// /// # Default values /// /// If you need to define argument default value you can use `#[default(expression)]` /// argument's attribute: /// /// ``` /// use rstest::*; /// /// #[fixture] /// fn injected( /// #[default(21)] /// twenty_one: i32, /// #[default(1 + 1)] /// two: i32 /// ) -> i32 { twenty_one * two } /// /// #[rstest] /// fn the_test(injected: i32) { /// assert_eq!(42, injected) /// } /// ``` /// The `expression` could be any valid rust expression, even an `async` block if you need. /// Moreover, if the type implements `FromStr` trait you can use a literal string to build it. /// /// ``` /// # use rstest::*; /// # use std::net::SocketAddr; /// # struct DbConnection {} /// #[fixture] /// fn db_connection( /// #[default("127.0.0.1:9000")] /// addr: SocketAddr /// ) -> DbConnection { /// // create connection /// # DbConnection{} /// } /// ``` /// /// # Async /// /// If you need you can write `async` fixtures to use in your `async` tests. Simply use `async` /// keyword for your function and the fixture become an `async` fixture. /// /// ``` /// use rstest::*; /// /// #[fixture] /// async fn async_fixture() -> i32 { 42 } /// /// /// #[rstest] /// #[tokio::test] /// async fn the_test(#[future] async_fixture: i32) { /// assert_eq!(42, async_fixture.await) /// } /// ``` /// The `#[future]` argument attribute helps to remove the `impl Future` boilerplate. /// In this case the macro expands it in: /// /// ``` /// # use rstest::*; /// # use std::future::Future; /// # #[fixture] /// # async fn async_fixture() -> i32 { 42 } /// #[rstest] /// #[tokio::test] /// async fn the_test(async_fixture: impl std::future::Future) { /// assert_eq!(42, async_fixture.await) /// } /// ``` /// If you need, you can use `#[future]` attribute also with an implicit lifetime reference /// because the macro will replace the implicit lifetime with an explicit one. /// /// # Rename /// /// Sometimes you want to have long and descriptive name for your fixture but you prefer to use a much /// shorter name for argument that represent it in your fixture or test. You can rename the fixture /// using `#[from(short_name)]` attribute like following example: /// /// ## Destructuring /// /// It's possible to destructure the fixture type but, in this case, your're forced to use renaming syntax /// because it's not possible to guess the fixture name from this syntax: /// /// ``` /// use rstest::*; /// #[fixture] /// fn two_values() -> (u32, u32) { (42, 24) } /// /// #[rstest] /// fn the_test(#[from(two_values)] (first, _): (u32, u32)) { /// assert_eq!(42, first) /// } /// ``` /// /// ``` /// use rstest::*; /// /// #[fixture] /// fn long_and_boring_descriptive_name() -> i32 { 42 } /// /// #[rstest] /// fn the_test(#[from(long_and_boring_descriptive_name)] short: i32) { /// assert_eq!(42, short) /// } /// ``` /// /// This feature can also be useful when you don't want to declare the `use` of a fixture or simple /// use the fixture's path: /// /// ``` /// use rstest::*; /// /// # mod magic_numbers { /// # use rstest::*; /// # #[fixture] /// # pub fn fortytwo() -> i32 { 42 } /// # } /// #[rstest] /// fn the_test(#[from(magic_numbers::fortytwo)] x: i32) { /// assert_eq!(42, x) /// } /// ``` /// /// # `#[once]` Fixture /// /// Especially in integration tests there are cases where you need a fixture that is called just once /// for every tests. `rstest` provides `#[once]` attribute for these cases. /// /// If you mark your fixture with this attribute, then `rstest` will compute a static reference to your /// fixture result and return this reference to all your tests that need this fixture. /// /// In follow example all tests share the same reference to the `42` static value. /// /// ``` /// use rstest::*; /// /// #[fixture] /// #[once] /// fn once_fixture() -> i32 { 42 } /// /// // Take care!!! You need to use a reference to the fixture value /// /// #[rstest] /// #[case(1)] /// #[case(2)] /// fn cases_tests(once_fixture: &i32, #[case] v: i32) { /// // Take care!!! You need to use a reference to the fixture value /// assert_eq!(&42, once_fixture) /// } /// /// #[rstest] /// fn single(once_fixture: &i32) { /// assert_eq!(&42, once_fixture) /// } /// ``` /// /// There are some limitations when you use `#[once]` fixture. `rstest` forbid to use once fixture /// for: /// /// - `async` function /// - Generic function (both with generic types or use `impl` trait) /// /// Take care that the `#[once]` fixture value will **never be dropped**. /// /// # Partial Injection /// /// You can also partially inject fixture dependency using `#[with(v1, v2, ..)]` attribute: /// /// ``` /// use rstest::*; /// /// #[fixture] /// fn base() -> i32 { 1 } /// /// #[fixture] /// fn first(base: i32) -> i32 { 1 * base } /// /// #[fixture] /// fn second(base: i32) -> i32 { 2 * base } /// /// #[fixture] /// fn injected(first: i32, #[with(3)] second: i32) -> i32 { first * second } /// /// #[rstest] /// fn the_test(injected: i32) { /// assert_eq!(-6, injected) /// } /// ``` /// Note that injected value can be an arbitrary rust expression. `#[with(v1, ..., vn)]` /// attribute will inject `v1, ..., vn` expression as fixture arguments: all remaining arguments /// will be resolved as fixtures. /// /// Sometimes the return type cannot be inferred so you must define it: For the few times you may /// need to do it, you can use the `#[default(type)]`, `#[partial_n(type)]` function attribute /// to define it: /// /// ``` /// use rstest::*; /// # use std::fmt::Debug; /// /// #[fixture] /// pub fn i() -> u32 { /// 42 /// } /// /// #[fixture] /// pub fn j() -> i32 { /// -42 /// } /// /// #[fixture] /// #[default(impl Iterator)] /// #[partial_1(impl Iterator)] /// pub fn fx(i: I, j: J) -> impl Iterator { /// std::iter::once((i, j)) /// } /// /// #[rstest] /// fn resolve_by_default(mut fx: impl Iterator) { /// assert_eq!((42, -42), fx.next().unwrap()) /// } /// /// #[rstest] /// fn resolve_partial(#[with(42.0)] mut fx: impl Iterator) { /// assert_eq!((42.0, -42), fx.next().unwrap()) /// } /// ``` /// `partial_i` is the fixture used when you inject the first `i` arguments in test call. /// /// # Old _compact_ syntax /// /// There is also a compact form for all previous features. This will maintained for a long time /// but for `fixture` I strongly recommend to migrate your code because you'll pay a little /// verbosity but get back a more readable code. /// /// Follow the previous examples in old _compact_ syntax. /// /// ## Default /// ``` /// # use rstest::*; /// #[fixture(twenty_one=21, two=2)] /// fn injected(twenty_one: i32, two: i32) -> i32 { twenty_one * two } /// ``` /// /// ## Rename /// ``` /// # use rstest::*; /// #[fixture] /// fn long_and_boring_descriptive_name() -> i32 { 42 } /// /// #[rstest(long_and_boring_descriptive_name as short)] /// fn the_test(short: i32) { /// assert_eq!(42, short) /// } /// ``` /// /// ## Partial Injection /// ``` /// # use rstest::*; /// # #[fixture] /// # fn base() -> i32 { 1 } /// # /// # #[fixture] /// # fn first(base: i32) -> i32 { 1 * base } /// # /// # #[fixture] /// # fn second(base: i32) -> i32 { 2 * base } /// # /// #[fixture(second(-3))] /// fn injected(first: i32, second: i32) -> i32 { first * second } /// ``` /// ## Partial Type Injection /// ``` /// # use rstest::*; /// # use std::fmt::Debug; /// # /// # #[fixture] /// # pub fn i() -> u32 { /// # 42 /// # } /// # /// # #[fixture] /// # pub fn j() -> i32 { /// # -42 /// # } /// # /// #[fixture(::default>::partial_1>)] /// pub fn fx(i: I, j: J) -> impl Iterator { /// std::iter::once((i, j)) /// } /// ``` pub use rstest_macros::fixture; /// The attribute that you should use for your tests. Your /// annotated function's arguments can be /// [injected](attr.rstest.html#injecting-fixtures) with /// [`fixture`](macro@fixture)s, provided by /// [parametrized cases](attr.rstest.html#test-parametrized-cases) /// or by [value lists](attr.rstest.html#values-lists). /// /// `rstest` attribute can be applied to _any_ function and you can customize its /// parameters by using function and arguments attributes. /// /// Your test function can use generics, `impl` or `dyn` and like any kind of rust tests: /// /// - return results /// - marked by `#[should_panic]` attribute /// /// In the function signature, where you define your tests inputs, you can also destructuring /// the values like any other rust function. /// /// If the test function is an [`async` function](#async) `rstest` will run all cases as `async` /// tests. However, async tests must supply either an [explicit test attribute](#explicit-test-attributes) /// or an [implicit test attribute](#implicit-test-attributes). /// /// In your test function you can: /// /// - [inject fixtures](#injecting-fixtures) /// - Generate [parametrized test cases](#test-parametrized-cases) /// - Generate tests for each combination of [value lists](#values-lists) /// - Feed variables from [files](#files-path-as-input-arguments) /// /// Additional Attributes: /// /// - Function Attributes: /// - [`#[case]`](#test-parametrized-cases) define a parametrized test case /// - [`#[awt]`](#async) await all your future test function's inputs /// - [`#[timeout(...)]`](#test-timeout) define a test timeout /// - [`#[trace]`](#trace-input-arguments) tracing input arguments /// - [`#[test_attr(...)]`](#explicit-test-attr) define an explicit test attribute /// - Arguments Attributes: /// - [`#[case]`](#test-parametrized-cases) define an argument parametrized by test cases /// - [`#[values(...)]`](#values-lists) define an argument that can be a list of values /// - [`#[files(...)]`-`#[exclude(...)]`-`#[base_dir = ... ]`-`#[mode = ...]`](#files-path-as-input-arguments) /// define an argument that can be a list of path based on a glob pattern /// - [`#[from(...)]`-`#[with(...)]`](#injecting-fixtures) handling injected fixture /// - [`#[future]`](#async) implement future boilerplate argument /// - [`#[context]`](#test-context-object) Some metadata test information /// - [`#[by_ref]`](#local-lifetime-and-by_ref-attribute) define a local lifetime /// - [`#[ignore]`](#ignoring-arguments) ignore an argument used by a custom test function /// - [`#[notrace]`](#trace-input-arguments) disable trace /// /// ## Injecting Fixtures /// /// The simplest case is write a test that can be injected with /// [`[fixture]`](macro@fixture)s. You can just declare all used fixtures by passing /// them as a function's arguments. This can help your test to be neat /// and make your dependency clear. /// /// ``` /// use rstest::*; /// /// #[fixture] /// fn injected() -> i32 { 42 } /// /// #[rstest] /// fn the_test(injected: i32) { /// assert_eq!(42, injected) /// } /// ``` /// /// [`[rstest]`](macro@rstest) procedural macro will desugar it to something that isn't /// so far from /// /// ``` /// #[test] /// fn the_test() { /// let injected=injected(); /// assert_eq!(42, injected) /// } /// ``` /// /// If you want to use long and descriptive names for your fixture but prefer to use /// shorter names inside your tests you use rename feature described in /// [fixture rename](attr.fixture.html#rename): /// /// ``` /// use rstest::*; /// /// #[fixture] /// fn long_and_boring_descriptive_name() -> i32 { 42 } /// /// #[rstest] /// fn the_test(#[from(long_and_boring_descriptive_name)] short: i32) { /// assert_eq!(42, short) /// } /// ``` /// /// The use of `#[from(...)]` attribute is mandatory if you need to destructure the value: /// /// ``` /// use rstest::*; /// /// #[fixture] /// fn tuple() -> (u32, f32) { (42, 42.0) } /// /// #[rstest] /// fn the_test(#[from(tuple)] (u, _): (u32, f32)) { /// assert_eq!(42, u) /// } /// ``` /// /// Sometimes is useful to have some parameters in your fixtures but your test would /// override the fixture's default values in some cases. Like in /// [fixture partial injection](attr.fixture.html#partial-injection) you use `#[with]` /// attribute to indicate some fixture's arguments also in `rstest`. /// /// ``` /// # struct User(String, u8); /// # impl User { fn name(&self) -> &str {&self.0} } /// use rstest::*; /// /// #[fixture] /// fn user( /// #[default("Alice")] name: impl AsRef, /// #[default(22)] age: u8 /// ) -> User { User(name.as_ref().to_owned(), age) } /// /// #[rstest] /// fn check_user(#[with("Bob")] user: User) { /// assert_eq("Bob", user.name()) /// } /// ``` /// /// ## Test Parametrized Cases /// /// If you would execute your test for a set of input data cases /// you can define the arguments to use and the cases list. Let see /// the classical Fibonacci example. In this case we would give the /// `input` value and the `expected` result for a set of cases to test. /// /// ``` /// use rstest::rstest; /// /// #[rstest] /// #[case(0, 0)] /// #[case(1, 1)] /// #[case(2, 1)] /// #[case(3, 2)] /// #[case(4, 3)] /// fn fibonacci_test(#[case] input: u32,#[case] expected: u32) { /// assert_eq!(expected, fibonacci(input)) /// } /// /// fn fibonacci(input: u32) -> u32 { /// match input { /// 0 => 0, /// 1 => 1, /// n => fibonacci(n - 2) + fibonacci(n - 1) /// } /// } /// ``` /// /// `rstest` will produce 5 independent tests and not just one that /// check every case. Every test can fail independently and `cargo test` /// will give follow output: /// /// ```text /// running 5 tests /// test fibonacci_test::case_1 ... ok /// test fibonacci_test::case_2 ... ok /// test fibonacci_test::case_3 ... ok /// test fibonacci_test::case_4 ... ok /// test fibonacci_test::case_5 ... ok /// /// test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out /// ``` /// /// The cases input values can be arbitrary Rust expressions that return the /// argument type. /// /// ``` /// use rstest::rstest; /// /// fn sum(a: usize, b: usize) -> usize { a + b } /// /// #[rstest] /// #[case("foo", 3)] /// #[case(String::from("foo"), 2 + 1)] /// #[case(format!("foo"), sum(2, 1))] /// fn test_len(#[case] s: impl AsRef,#[case] len: usize) { /// assert_eq!(s.as_ref().len(), len); /// } /// ``` /// ### Feature flagged cases /// /// In case you want certain test cases to only be present if a certain feature is /// enabled, use `#[cfg_attr(feature = …, case(…))]`: /// /// ``` /// use rstest::rstest; /// /// #[rstest] /// #[case(2, 2)] /// #[cfg_attr(feature = "frac", case(4/2, 2))] /// fn it_works(#[case] a: u32, #[case] b: u32) { /// assert!(a == b); /// } /// ``` /// /// This also works with [`rstest_reuse`](https://crates.io/crates/rstest_reuse). /// /// ### Magic Conversion /// /// You can use the magic conversion feature every time you would define a variable /// where its type define `FromStr` trait: test will parse the string to build the value. /// /// ``` /// # use rstest::rstest; /// # use std::path::PathBuf; /// # fn count_words(path: PathBuf) -> usize {0} /// #[rstest] /// #[case("resources/empty", 0)] /// #[case("resources/divine_comedy", 101.698)] /// fn test_count_words(#[case] path: PathBuf, #[case] expected: usize) { /// assert_eq!(expected, count_words(path)) /// } /// ``` /// /// ### Optional case description /// /// Optionally you can give a _description_ to every case simple by follow `case` /// with `::my_case_description` where `my_case_description` should be a a valid /// Rust ident. /// /// ``` /// # use rstest::*; /// #[rstest] /// #[case::zero_base_case(0, 0)] /// #[case::one_base_case(1, 1)] /// #[case(2, 1)] /// #[case(3, 2)] /// fn fibonacci_test(#[case] input: u32,#[case] expected: u32) { /// assert_eq!(expected, fibonacci(input)) /// } /// /// # fn fibonacci(input: u32) -> u32 { /// # match input { /// # 0 => 0, /// # 1 => 1, /// # n => fibonacci(n - 2) + fibonacci(n - 1) /// # } /// # } /// ``` /// /// Output will be /// ```text /// running 4 tests /// test fibonacci_test::case_1_zero_base_case ... ok /// test fibonacci_test::case_2_one_base_case ... ok /// test fibonacci_test::case_3 ... ok /// test fibonacci_test::case_4 ... ok /// /// test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out /// ``` /// /// ### Use specific `case` attributes /// /// Every function's attributes that preceding a `#[case]` attribute will /// be used in this test case and all function's attributes that follow the /// last `#[case]` attribute will mark all test cases. /// /// This feature can be use to mark just some cases as `should_panic` /// and choose to have a fine grain on expected panic messages. /// /// In follow example we run 3 tests where the first pass without any /// panic, in the second we catch a panic but we don't care about the message /// and in the third one we also check the panic message. /// /// ``` /// use rstest::rstest; /// /// #[rstest] /// #[case::no_panic(0)] /// #[should_panic] /// #[case::panic(1)] /// #[should_panic(expected="expected")] /// #[case::panic_with_message(2)] /// fn attribute_per_case(#[case] val: i32) { /// match val { /// 0 => assert!(true), /// 1 => panic!("No catch"), /// 2 => panic!("expected"), /// _ => unreachable!(), /// } /// } /// ``` /// /// Output: /// /// ```text /// running 3 tests /// test attribute_per_case::case_1_no_panic ... ok /// test attribute_per_case::case_3_panic_with_message ... ok /// test attribute_per_case::case_2_panic ... ok /// /// test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out /// ``` /// /// To mark all your tests as `#[should_panic]` use: /// /// ``` /// # use rstest::rstest; /// #[rstest] /// #[case(1)] /// #[case(2)] /// #[case(3)] /// #[should_panic] /// fn fail(#[case] v: u32) { assert_eq!(0, v) } /// ``` /// /// ## Values Lists /// /// Another useful way to write a test and execute it for some values /// is to use the values list syntax. This syntax can be useful both /// for a plain list and for testing all combination of input arguments. /// /// ``` /// # use rstest::*; /// # fn is_valid(input: &str) -> bool { true } /// /// #[rstest] /// fn should_be_valid( /// #[values("John", "alice", "My_Name", "Zigy_2001")] /// input: &str /// ) { /// assert!(is_valid(input)) /// } /// ``` /// /// or /// /// ``` /// # use rstest::*; /// # fn valid_user(name: &str, age: u8) -> bool { true } /// /// #[rstest] /// fn should_accept_all_corner_cases( /// #[values("J", "A", "A________________________________________21")] /// name: &str, /// #[values(14, 100)] /// age: u8 /// ) { /// assert!(valid_user(name, age)) /// } /// ``` /// where `cargo test` output is /// /// ```text /// test should_accept_all_corner_cases::name_1___J__::age_2_100 ... ok /// test should_accept_all_corner_cases::name_2___A__::age_1_14 ... ok /// test should_accept_all_corner_cases::name_2___A__::age_2_100 ... ok /// test should_accept_all_corner_cases::name_3___A________________________________________21__::age_2_100 ... ok /// test should_accept_all_corner_cases::name_3___A________________________________________21__::age_1_14 ... ok /// test should_accept_all_corner_cases::name_1___J__::age_1_14 ... ok /// /// test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s /// ``` /// Note that the test names contains the given expression sanitized into /// a valid Rust identifier name. This should help to identify which case fails. /// /// /// Also value list implements the magic conversion feature: every time the value type /// implements `FromStr` trait you can use a literal string to define it. /// /// ``` /// # use rstest::rstest; /// # use std::net::SocketAddr; /// #[rstest] /// fn given_port(#[values("1.2.3.4:8000", "4.3.2.1:8000", "127.0.0.1:8000")] addr: SocketAddr) { /// assert_eq!(8000, addr.port()) /// } /// ``` /// /// ## Destructuring inputs /// /// Both parametrized case and values can be destructured: /// /// ``` /// # use rstest::*; /// struct S { /// first: u32, /// second: u32, /// } /// /// struct T(i32); /// /// #[rstest] /// #[case(S{first: 21, second: 42})] /// fn some_test(#[case] S{first, second} : S, #[values(T(-1), T(1))] T(t): T) { /// assert_eq!(1, t * t); /// assert_eq!(2 * first, second); /// } /// ``` /// /// ## Files path as input arguments /// /// If you need to create a test for each file in a given location you can use /// `#[files("glob path syntax")]` attribute to generate a test for each file that /// satisfy the given glob path. /// /// ``` /// # use rstest::rstest; /// # use std::path::{Path, PathBuf}; /// # fn check_file(path: &Path) -> bool { true }; /// #[rstest] /// fn for_each_file(#[files("src/**/*.rs")] #[exclude("test")] path: PathBuf) { /// assert!(check_file(&path)) /// } /// ``` /// /// The default behavior is to ignore the files that start with `"."`, but you can /// modify this by use `#[include_dot_files]` attribute. The `files` attribute can be /// used more than once on the same variable, and you can also create some custom /// exclusion rules with the `#[exclude("regex")]` attributes that filter out all /// paths that verify the regular expression. /// /// Sometime is useful to have test files in a workspace folder to share them between the /// crates in your workspace. You can do that by use the usual parent folders `..` in /// the glob path. In this case the test names will be the relative path from the crate root /// where the parent folder components are replaced by `_UP`: for instance if you have a /// `valid_call.yaml` in the folder `../test_cases` (from your crate root) a test name could be /// `path_1__UP_test_cases_valid_call_yaml`. /// /// If you want to change the base path for the test files. You can do that by using /// `#[base_dir = "..."]` attribute. The `base_dir` is resolved relative to the crate root /// (similar to the `files` attribute without `base_dir`). If you want to use an absolute /// path you can use `#[base_dir = "/path/to/your/files"]`. /// /// Both `files` and `base_dir` attributes can use environment variables using the syntax /// `$VAR` or `${VAR}`. If the environment variable is not set, the attribute will cause /// an error. This can be ignored using the `#[ignore_missing_env_vars]` attribute. A /// default value can be provided for the environment variable using the syntax /// `${VAR:-default}` (similar to bash). This can be really useful when you want to override /// the cargo root on some environments: use `#[base_dir = "BASE_TEST_DIR:-"]` do the trick. /// /// The `#[files(...)]` attribute ignores matched directory paths by default, /// returning only file paths. If you need the test cases to include directories /// found by the glob pattern, use the `#[dirs]` attribute in conjunction with `#[files(...)]`. /// /// Finally, often you would to recompile tests sources when file the folders or the /// environment variables changed. In this case you should provide a `build.rs` script file /// that tell to the compiler what to look in order to recompile the tests. For instance /// follow a simple example: /// /// ```ignore /// pub fn main() { /// println!("cargo::rerun-if-changed=tests/resources"); /// println!("cargo::rerun-if-env-changed=BASE_TEST_DIR"); /// } /// ``` /// /// ### `#[mode = ...]` /// /// Using the `#[mode = ...]` attribute on an argument tagged with /// `#[files(...)]` and friends will set the way the file is passed as an argument. /// It accepts the following arguments with the following behaviour: /// /// - `path`: the default behaviour, passes each file path as a [PathBuf][std::path::PathBuf]. /// - `str`: passes the contents of each file as a [&str][str] using [include_str]. /// - `bytes`: passes the contents of each files as a `&[u8]` using [include_bytes]. /// /// Trying to pass directories as arguments will cause a compile error when using `str` and /// `bytes`. /// /// ``` /// # use rstest::rstest; /// # use std::path::PathBuf; /// # use std::fs::read_to_string; /// #[rstest] /// fn for_each_path( /// #[files("src/**/*.rs")] #[exclude("test")] #[mode = path] path: PathBuf /// ) { /// let contents = read_to_string(path).unwrap(); /// assert!(contents.len() >= 0) /// } /// /// #[rstest] /// fn for_each_txt_file( /// #[files("src/**/*.rs")] #[exclude("test")] #[mode = str] contents: &str /// ) { /// assert!(contents.len() >= 0) /// } /// /// #[rstest] /// fn for_each_bin_file( /// #[files("src/**/*.rs")] #[exclude("test")] #[mode = bytes] contents: &[u8] /// ) { /// assert!(contents.len() >= 0) /// } /// ``` /// /// ## Use Parametrize definition in more tests /// /// If you need to use a test list for more than one test you can use /// [`rstest_reuse`](https://crates.io/crates/rstest_reuse) crate. /// With this helper crate you can define a template and use it everywhere. /// /// ```rust,ignore /// use rstest::rstest; /// use rstest_reuse::{self, *}; /// /// #[template] /// #[rstest] /// #[case(2, 2)] /// #[case(4/2, 2)] /// fn two_simple_cases(#[case] a: u32, #[case] b: u32) {} /// /// #[apply(two_simple_cases)] /// fn it_works(#[case] a: u32,#[case] b: u32) { /// assert_eq!(a, b); /// } /// ``` /// /// See [`rstest_reuse`](https://crates.io/crates/rstest_reuse) for more details. /// /// ## Async /// /// `rstest` supports async tests, but makes no assumptions about what /// async runtime you are using. Async tests require either an /// [explicit test attribute](#explicit-test-attributes) or an /// [implicit test attribute](#implicit-test-attributes). /// /// You are responsible for providing any appropriate peer dependencies to run your async tests. /// /// If your test input is an async value (fixture or test parameter) you can use `#[future]` /// attribute to remove `impl Future` boilerplate and just use `T`: /// /// ``` /// use rstest::*; /// #[fixture] /// async fn base() -> u32 { 42 } /// /// #[rstest] /// #[case(21, async { 2 })] /// #[case(6, async { 7 })] /// #[tokio::test] /// async fn my_async_test(#[future] base: u32, #[case] expected: u32, #[future] #[case] div: u32) { /// assert_eq!(expected, base.await / div.await); /// } /// ``` /// /// As you noted you should `.await` all _future_ values and this some times can be really boring. /// In this case you can use `#[future(awt)]` to _awaiting_ an input or annotating your function /// with `#[awt]` attributes to globally `.await` all your _future_ inputs. Previous code can be /// simplified like follow: /// /// ``` /// use rstest::*; /// # #[fixture] /// # async fn base() -> u32 { 42 } /// /// #[rstest] /// #[case(21, async { 2 })] /// #[case(6, async { 7 })] /// #[tokio::test] /// #[awt] /// async fn global(#[future] base: u32, #[case] expected: u32, #[future] #[case] div: u32) { /// assert_eq!(expected, base / div); /// } /// /// #[rstest] /// #[case(21, async { 2 })] /// #[case(6, async { 7 })] /// #[tokio::test] /// async fn single(#[future] base: u32, #[case] expected: u32, #[future(awt)] #[case] div: u32) { /// assert_eq!(expected, base.await / div); /// } /// ``` /// /// ### Test `#[timeout()]` /// /// You can define an execution timeout for your tests with `#[timeout()]` attribute. Timeout /// works both for sync and async tests and is runtime agnostic. `#[timeout()]` take an /// expression that should return a `std::time::Duration`. Follow a simple async example: /// /// ```rust /// use rstest::*; /// use std::time::Duration; /// /// async fn delayed_sum(a: u32, b: u32,delay: Duration) -> u32 { /// async_std::task::sleep(delay).await; /// a + b /// } /// /// #[rstest] /// #[timeout(Duration::from_millis(80))] /// #[async_std::test] /// async fn single_pass() { /// assert_eq!(4, delayed_sum(2, 2, ms(10)).await); /// } /// ``` /// In this case test pass because the delay is just 10 milliseconds and timeout is /// 80 milliseconds. /// /// You can use `timeout` attribute like any other attribute in your tests, and you can /// override a group timeout with a test specific one. In the follow example we have /// 3 tests where first and third use 100 milliseconds but the second one use 10 milliseconds. /// Another valuable point in this example is to use an expression to compute the /// duration. /// /// ```rust /// # use rstest::*; /// # use std::time::Duration; /// # /// # async fn delayed_sum(a: u32, b: u32,delay: Duration) -> u32 { /// # async_std::task::sleep(delay).await; /// # a + b /// # } /// fn ms(ms: u32) -> Duration { /// Duration::from_millis(ms.into()) /// } /// /// #[rstest] /// #[case::pass(ms(1), 4)] /// #[timeout(ms(10))] /// #[case::fail_timeout(ms(60), 4)] /// #[case::fail_value(ms(1), 5)] /// #[timeout(ms(100))] /// #[async_std::test] /// async fn group_one_timeout_override(#[case] delay: Duration, #[case] expected: u32) { /// assert_eq!(expected, delayed_sum(2, 2, delay).await); /// } /// ``` /// /// If you want to use `timeout` for `async` test you need to use `async-timeout` /// feature (enabled by default). /// /// ### Default timeout /// /// You can set a default timeout for test using the `RSTEST_TIMEOUT` environment variable. /// The value is in seconds and is evaluated on test compile time. /// /// ## Test Attributes /// /// ### Explicit Test Attributes /// /// If your test contains an attribute `#[test_attr(...)]`, this is an explicit test attribute declaration. /// The contents of the parentheses will be inserted as an attribute of your test. This allows for arbitrary /// test attribute syntax. /// /// For instance, if you want to test an async function with [`smol_macros::test`](https://docs.rs/smol-macros/0.1.1/smol_macros/macro.test.html), /// you can write /// /// ```rust /// use rstest::*; /// use macro_rules_attribute::apply; /// use smol_macros::test; /// use std::future::Future; /// /// #[rstest] /// #[case(2, async { 4 })] /// #[case(21, async { 42 })] /// #[test_attr(apply(test))] /// async fn my_async_test(#[case] a: u32, #[case] #[future] result: u32) { /// assert_eq!(2 * a, result.await); /// } /// ``` /// /// ### Implicit Test Attributes /// /// If your test contains an attribute whose path ends in `test`, this is treated /// as an implicit test attribute, and replaces the default `#[test]` attribute. /// Simply including the attribute in your test's attribute list is all that is required. /// /// For instance, if you want to test an async function with the `actix_rt::test` attribute, you can just write: /// /// ```rust /// use rstest::*; /// use actix_rt; /// use std::future::Future; /// /// #[rstest] /// #[case(2, async { 4 })] /// #[case(21, async { 42 })] /// #[actix_rt::test] /// async fn my_async_test(#[case] a: u32, #[case] #[future] result: u32) { /// assert_eq!(2 * a, result.await); /// } /// ``` /// /// Implicit test attributes have a lower priority than [`explicit test attributes`](#explicit-test-attribute). /// If you have an unrelated attribute whose path ends in `test`, you should declare an explicit test attribute /// for deconfliction. /// /// ### Default Test Attributes /// /// Synchronous tests use `#[test]` as the default test attribute if nothing else is supplied explicitly or implicitly. /// /// Asynchronous tests will fail to compile if no test attribute is specified explicitly or implicitly. /// /// ## Test `Context` object /// /// You can have a [`Context`] object for your test by annotating an argument by `#[context]` attribute. /// This object contains some useful information both to implement simple logics and debugging stuff. /// /// ``` /// use rstest::{rstest, Context}; /// /// #[rstest] /// #[case::a_description(42)] /// fn my_test(#[context] ctx: Context, #[case] _c: u32) { /// assert_eq!("my_test", ctx.name); /// assert_eq!(Some("a_description"), ctx.description); /// assert_eq!(Some(0), ctx.case); /// /// std::thread::sleep(std::time::Duration::from_millis(100)); /// assert!(ctx.start.elapsed() >= std::time::Duration::from_millis(100)); /// } /// /// ``` /// /// ## Local lifetime and `#[by_ref]` attribute /// /// In some cases you may want to use a local lifetime for some arguments of your test. /// In these cases you can use the `#[by_ref]` attribute then use the reference instead /// the value. /// /// ```rust /// # use std::cell::Cell; /// # use rstest::*; /// # #[derive(Debug, Clone, Copy, PartialEq, Eq)] /// enum E<'a> { /// A(bool), /// B(&'a Cell>), /// } /// /// fn make_e_from_bool<'a>(_bump: &'a (), b: bool) -> E<'a> { /// E::A(b) /// } /// /// #[fixture] /// fn bump() -> () {} /// /// #[rstest] /// #[case(true, E::A(true))] /// fn it_works<'a>(#[by_ref] bump: &'a (), #[case] b: bool, #[case] expected: E<'a>) { /// let actual = make_e_from_bool(&bump, b); /// assert_eq!(actual, expected); /// } /// ``` /// /// You can use `#[by_ref]` attribute for all arguments of your test and not just for fixture /// but also for cases, values and files. /// /// ## Putting all Together /// /// All these features can be used together with a mixture of fixture variables, /// fixed cases and bunch of values. For instance, you might need two /// test cases which test for panics, one for a logged in user and one for a guest user. /// /// ```rust /// # enum User { Guest, Logged, } /// # impl User { fn logged(_n: &str, _d: &str, _w: &str, _s: &str) -> Self { Self::Logged } } /// # struct Item {} /// # trait Repository { fn find_items(&self, user: &User, query: &str) -> Result, String> { Err("Invalid query error".to_owned()) } } /// # #[derive(Default)] struct InMemoryRepository {} /// # impl Repository for InMemoryRepository {} /// /// use rstest::*; /// /// #[fixture] /// fn repository() -> InMemoryRepository { /// let mut r = InMemoryRepository::default(); /// // fill repository with some data /// r /// } /// /// #[fixture] /// fn alice() -> User { /// User::logged("Alice", "2001-10-04", "London", "UK") /// } /// /// #[rstest] /// #[case::authorized_user(alice())] // We can use `fixture` also as standard function /// #[case::guest(User::Guest)] // We can give a name to every case : `guest` in this case /// #[should_panic(expected = "Invalid query error")] // We would test a panic /// fn should_be_invalid_query_error( /// repository: impl Repository, /// #[case] user: User, /// #[values(" ", "^%$some#@invalid!chars", ".n.o.d.o.t.s.")] query: &str, /// query: &str /// ) { /// repository.find_items(&user, query).unwrap(); /// } /// ``` /// /// ## Ignoring Arguments /// /// Sometimes, you may want to inject and use fixtures not managed by rstest /// (e.g. db connection pools for sqlx tests). /// /// In these cases, you can use the `#[ignore]` attribute to ignore the additional /// parameter and let another crate take care of it: /// /// ```rust, ignore /// use rstest::*; /// use sqlx::*; /// /// #[fixture] /// fn my_fixture() -> i32 { 42 } /// /// #[rstest] /// #[sqlx::test] /// async fn test_db(my_fixture: i32, #[ignore] pool: PgPool) { /// assert_eq!(42, injected); /// // do stuff with the connection pool /// } /// ``` /// /// /// ## Trace Input Arguments /// /// Sometimes can be very helpful to print all test's input arguments. To /// do it you can use the `#[trace]` function attribute that you can apply /// to all cases or just to some of them. /// /// ``` /// use rstest::*; /// /// #[fixture] /// fn injected() -> i32 { 42 } /// /// #[rstest] /// #[trace] /// fn the_test(injected: i32) { /// assert_eq!(42, injected) /// } /// ``` /// /// Will print an output like /// /// ```bash /// Testing started at 14.12 ... /// ------------ TEST ARGUMENTS ------------ /// injected = 42 /// -------------- TEST START -------------- /// /// /// Expected :42 /// Actual :43 /// ``` /// But /// ``` /// # use rstest::*; /// #[rstest] /// #[case(1)] /// #[trace] /// #[case(2)] /// fn the_test(#[case] v: i32) { /// assert_eq!(0, v) /// } /// ``` /// will trace just `case_2` input arguments. /// /// If you want to trace input arguments but skip some of them that don't /// implement the `Debug` trait, you can also use the /// `#[notrace]` argument attribute to skip them: /// /// ``` /// # use rstest::*; /// # struct Xyz; /// # struct NoSense; /// #[rstest] /// #[trace] /// fn the_test(injected: i32, #[notrace] xyz: Xyz, #[notrace] have_no_sense: NoSense) { /// assert_eq!(42, injected) /// } /// ``` /// # Old _compact_ syntax /// /// `rstest` support also a syntax where all options and configuration can be write as /// `rstest` attribute arguments. This syntax is a little less verbose but make /// composition harder: for instance try to add some cases to a `rstest_reuse` template /// is really hard. /// /// So we'll continue to maintain the old syntax for a long time but we strongly encourage /// to switch your test in the new form. /// /// Anyway, here we recall this syntax and rewrite the previous example in the _compact_ form. /// /// ```text /// rstest( /// arg_1, /// ..., /// arg_n[,] /// [::attribute_1[:: ... [::attribute_k]]] /// ) /// ``` /// Where: /// /// - `arg_i` could be one of the follow /// - `ident` that match to one of function arguments for parametrized cases /// - `case[::description](v1, ..., vl)` a test case /// - `fixture(v1, ..., vl) [as argument_name]` where fixture is the injected /// fixture and argument_name (default use fixture) is one of function arguments /// that and `v1, ..., vl` is a partial list of fixture's arguments /// - `ident => [v1, ..., vl]` where `ident` is one of function arguments and /// `v1, ..., vl` is a list of values for ident /// - `attribute_j` a test attribute like `trace` or `notrace` /// /// ## Fixture Arguments /// /// ``` /// # struct User(String, u8); /// # impl User { fn name(&self) -> &str {&self.0} } /// # use rstest::*; /// # /// # #[fixture] /// # fn user( /// # #[default("Alice")] name: impl AsRef, /// # #[default(22)] age: u8 /// # ) -> User { User(name.as_ref().to_owned(), age) } /// # /// #[rstest(user("Bob"))] /// fn check_user(user: User) { /// assert_eq("Bob", user.name()) /// } /// ``` /// /// ## Fixture Rename /// ``` /// # use rstest::*; /// #[fixture] /// fn long_and_boring_descriptive_name() -> i32 { 42 } /// /// #[rstest(long_and_boring_descriptive_name as short)] /// fn the_test(short: i32) { /// assert_eq!(42, short) /// } /// ``` /// /// ## Parametrized /// /// ``` /// # use rstest::*; /// #[rstest(input, expected, /// case::zero_base_case(0, 0), /// case::one_base_case(1, 1), /// case(2, 1), /// case(3, 2), /// #[should_panic] /// case(4, 42) /// )] /// fn fibonacci_test(input: u32, expected: u32) { /// assert_eq!(expected, fibonacci(input)) /// } /// /// # fn fibonacci(input: u32) -> u32 { /// # match input { /// # 0 => 0, /// # 1 => 1, /// # n => fibonacci(n - 2) + fibonacci(n - 1) /// # } /// # } /// ``` /// /// ## Values Lists /// /// ``` /// # use rstest::*; /// # fn is_valid(input: &str) -> bool { true } /// /// #[rstest( /// input => ["John", "alice", "My_Name", "Zigy_2001"] /// )] /// fn should_be_valid(input: &str) { /// assert!(is_valid(input)) /// } /// ``` /// /// ## `trace` and `notrace` /// /// ``` /// # use rstest::*; /// # struct Xyz; /// # struct NoSense; /// #[rstest(::trace::notrace(xzy, have_no_sense))] /// fn the_test(injected: i32, xyz: Xyz, have_no_sense: NoSense) { /// assert_eq!(42, injected) /// } /// ``` /// pub use rstest_macros::rstest; rstest-0.26.1/src/magic_conversion.rs000064400000000000000000000045301046102023000157220ustar 00000000000000pub struct Magic(pub std::marker::PhantomData); pub trait ViaParseDebug<'a, T> { fn magic_conversion(&self, input: &'a str) -> T; } impl<'a, T> ViaParseDebug<'a, T> for &&Magic where T: std::str::FromStr, T::Err: std::fmt::Debug, { fn magic_conversion(&self, input: &'a str) -> T { T::from_str(input).unwrap() } } pub trait ViaParse<'a, T> { fn magic_conversion(&self, input: &'a str) -> T; } impl<'a, T> ViaParse<'a, T> for &Magic where T: std::str::FromStr, { fn magic_conversion(&self, input: &'a str) -> T { match T::from_str(input) { Ok(v) => v, Err(_) => { panic!( "Cannot parse '{}' to get {}", input, std::any::type_name::() ); } } } } pub trait ViaIdent<'a, T> { fn magic_conversion(&self, input: &'a str) -> T; } impl<'a> ViaIdent<'a, &'a str> for &&Magic<&'a str> { fn magic_conversion(&self, input: &'a str) -> &'a str { input } } #[cfg(test)] mod test { use super::*; use std::str::FromStr; #[test] fn should_return_the_same_slice_string() { assert_eq!( "something", (&&&Magic::<&str>(std::marker::PhantomData)).magic_conversion("something") ); } #[test] fn should_parse_via_parse_debug() { assert_eq!( 42u32, (&&&Magic::(std::marker::PhantomData)).magic_conversion("42") ); } #[test] fn should_parse_via_parse_no_error_debug() { struct S(String); struct E; impl FromStr for S { type Err = E; fn from_str(s: &str) -> Result { Ok(S(s.to_owned())) } } assert_eq!( "some", (&&&Magic::(std::marker::PhantomData)) .magic_conversion("some") .0 ); } #[test] #[should_panic(expected = "MyTypeName")] fn should_show_error() { struct MyTypeName; struct E; impl FromStr for MyTypeName { type Err = E; fn from_str(_s: &str) -> Result { Err(E) } } (&&&Magic::(std::marker::PhantomData)).magic_conversion(""); } } rstest-0.26.1/src/timeout.rs000064400000000000000000000132341046102023000140640ustar 00000000000000use std::{sync::mpsc, thread, time::Duration}; #[cfg(feature = "async-timeout")] use futures_timer::Delay; #[cfg(feature = "async-timeout")] use futures_util::{select, Future, FutureExt}; pub fn execute_with_timeout_sync T + Send + 'static>( code: F, timeout: Duration, ) -> T { let (sender, receiver) = mpsc::channel(); let thread = if let Some(name) = thread::current().name() { thread::Builder::new().name(name.to_string()) } else { thread::Builder::new() }; let handle = thread.spawn(move || sender.send(code())).unwrap(); match receiver.recv_timeout(timeout) { Ok(result) => { // Unwraps are safe because we got a result from the thread, which is not a `SendError`, // and there was no panic within the thread which caused a disconnect. handle.join().unwrap().unwrap(); result } Err(mpsc::RecvTimeoutError::Timeout) => panic!("Timeout {timeout:?} expired"), Err(mpsc::RecvTimeoutError::Disconnected) => match handle.join() { Err(any) => std::panic::resume_unwind(any), Ok(_) => unreachable!(), }, } } #[cfg(feature = "async-timeout")] pub async fn execute_with_timeout_async, F: FnOnce() -> Fut>( code: F, timeout: Duration, ) -> T { select! { () = async { Delay::new(timeout).await; }.fuse() => panic!("Timeout {:?} expired", timeout), out = code().fuse() => out, } } #[cfg(test)] mod tests { use super::*; #[cfg(feature = "async-timeout")] mod async_version { use super::*; use std::time::Duration; async fn delayed_sum(a: u32, b: u32, delay: Duration) -> u32 { async_std::task::sleep(delay).await; a + b } async fn test(delay: Duration) { let result = delayed_sum(2, 2, delay).await; assert_eq!(result, 4); } mod use_async_std_runtime { use super::*; #[async_std::test] #[should_panic] async fn should_fail() { execute_with_timeout_async( || test(Duration::from_millis(40)), Duration::from_millis(10), ) .await } #[async_std::test] async fn should_pass() { execute_with_timeout_async( || test(Duration::from_millis(10)), Duration::from_millis(40), ) .await } #[async_std::test] #[should_panic = "inner message"] async fn should_fail_for_panic_with_right_panic_message() { execute_with_timeout_async( || async { panic!("inner message"); }, Duration::from_millis(30), ) .await } #[async_std::test] async fn should_compile_also_with_no_copy_move() { struct S {} async fn test(_s: S) { assert!(true); } let s = S {}; execute_with_timeout_async(move || test(s), Duration::from_millis(20)).await } } mod use_tokio_runtime { use super::*; #[tokio::test] #[should_panic] async fn should_fail() { execute_with_timeout_async( || test(Duration::from_millis(40)), Duration::from_millis(10), ) .await } #[tokio::test] #[should_panic = "inner message"] async fn should_fail_for_panic_with_right_panic_message() { execute_with_timeout_async( || async { panic!("inner message"); }, Duration::from_millis(30), ) .await } #[tokio::test] async fn should_pass() { execute_with_timeout_async( || test(Duration::from_millis(10)), Duration::from_millis(40), ) .await } } } mod thread_version { use super::*; pub fn delayed_sum(a: u32, b: u32, delay: Duration) -> u32 { std::thread::sleep(delay); a + b } fn test(delay: Duration) { let result = delayed_sum(2, 2, delay); assert_eq!(result, 4); } #[test] fn should_pass() { execute_with_timeout_sync( || test(Duration::from_millis(30)), Duration::from_millis(70), ) } #[test] #[should_panic = "inner message"] fn should_fail_for_panic_with_right_panic_message() { execute_with_timeout_sync( || { panic!("inner message"); }, Duration::from_millis(100), ) } #[test] #[should_panic] fn should_fail() { execute_with_timeout_sync( || test(Duration::from_millis(70)), Duration::from_millis(30), ) } #[test] fn should_compile_also_with_no_copy_move() { struct S {} fn test(_s: S) { assert!(true); } let s = S {}; execute_with_timeout_sync(move || test(s), Duration::from_millis(20)) } } } rstest-0.26.1/tests/fixture/mod.rs000064400000000000000000000326001046102023000152140ustar 00000000000000use std::path::Path; pub use unindent::Unindent; use super::resources; use mytest::*; use rstest_test::{assert_in, assert_not_in, Project, Stringable, TestResults}; const SRC_LIB_RS: &str = { const SEP: u8 = std::path::MAIN_SEPARATOR as u8; const SRC_LIB_RS: [u8; 11] = [ SEP, b's', b'r', b'c', SEP, b'l', b'i', b'b', b'.', b'r', b's', ]; unsafe { std::str::from_utf8_unchecked(&SRC_LIB_RS) } }; fn prj(res: &str) -> Project { let path = Path::new("fixture").join(res); crate::prj().set_code_file(resources(path)) } fn run_test(res: &str) -> (std::process::Output, String) { let prj = prj(res); ( prj.run_tests().unwrap(), prj.get_name().to_owned().to_string(), ) } mod should { use rstest_test::{assert_regex, CountMessageOccurrence}; use super::*; #[test] fn use_input_fixtures() { let (output, _) = run_test("simple_injection.rs"); TestResults::new().ok("success").fail("fail").assert(output); } #[test] fn create_a_struct_that_return_the_fixture() { let (output, _) = run_test("fixture_struct.rs"); TestResults::new() .ok("resolve_new") .ok("resolve_default") .ok("injected_new") .ok("injected_default") .assert(output); } #[test] fn be_accessible_from_other_module() { let (output, _) = run_test("from_other_module.rs"); TestResults::new().ok("struct_access").assert(output); } #[test] fn not_show_any_warning() { let (output, _) = run_test("no_warning.rs"); assert_not_in!(output.stderr.str(), "warning:"); } #[test] fn rename() { let (output, _) = run_test("rename.rs"); TestResults::new().ok("test").assert(output); } mod accept_and_return { use super::*; #[test] fn impl_traits() { let (output, _) = run_test("impl.rs"); TestResults::new() .ok("base_impl_return") .ok("nested_impl_return") .ok("nested_multiple_impl_return") .ok("base_impl_input") .ok("nested_impl_input") .ok("nested_multiple_impl_input") .assert(output); } #[test] fn dyn_traits() { let (output, _) = run_test("dyn.rs"); TestResults::new() .ok("test_dyn_box") .ok("test_dyn_ref") .ok("test_dyn_box_resolve") .ok("test_dyn_ref_resolve") .assert(output); } } #[rstest] #[case::base("async_fixture.rs")] #[case::use_global("await_complete_fixture.rs")] #[case::use_selective("await_partial_fixture.rs")] fn resolve_async_fixture(#[case] code: &str) { let prj = prj(code); prj.add_dependency("async-std", r#"{version="*", features=["attributes"]}"#); let output = prj.run_tests().unwrap(); TestResults::new() .ok("default_is_async") .ok("use_async_fixture") .ok("use_async_impl_output") .ok("use_async_nest_fixture_default") .ok("use_async_nest_fixture_injected") .ok("use_async_nest_fixture_with_default") .ok("use_two_args_mix_fixture") .ok("use_two_args_mix_fixture_inject_first") .ok("use_two_args_mix_fixture_inject_both") .assert(output); } #[test] fn resolve_fixture_generics_by_fixture_input() { let (output, _) = run_test("resolve.rs"); TestResults::new() .ok("test_u32") .ok("test_i32") .assert(output); } #[test] fn use_defined_return_type_if_any() { let (output, _) = run_test("defined_return_type.rs"); TestResults::new() .ok("resolve") .ok("resolve_partial") .ok("resolve_attrs") .ok("resolve_partial_attrs") .assert(output); } #[test] fn clean_up_default_from_unused_generics() { let (output, _) = run_test("clean_up_default_generics.rs"); TestResults::new() .ok("resolve") .ok("resolve_partial") .assert(output); } #[test] fn apply_partial_fixture() { let (output, _) = run_test("partial.rs"); TestResults::new() .ok("default") .ok("t_partial_1") .ok("t_partial_2") .ok("t_complete") .assert(output); } #[test] fn apply_partial_fixture_from_value_attribute() { let (output, _) = run_test("partial_in_attr.rs"); TestResults::new() .ok("default") .ok("t_partial_1") .ok("t_partial_2") .ok("t_complete") .assert(output); } #[rstest] #[case::compact_form("default.rs")] #[case::attrs_form("default_in_attrs.rs")] fn use_input_values_if_any(#[case] file: &str) { let (output, _) = run_test(file); TestResults::new() .ok("test_simple") .ok("test_simple_changed") .ok("test_double") .ok("test_double_changed") .ok("test_mixed") .assert(output); } #[test] fn convert_literal_string_for_default_values() { let (output, _) = run_test("default_conversion.rs"); assert_regex!( "Cannot parse 'error' to get [a-z:_0-9]*MyType", output.stdout.str() ); TestResults::new() .ok("test_base") .ok("test_byte_array") .ok("test_convert_custom") .fail("test_fail_conversion") .assert(output); } #[rstest] #[case("once.rs")] #[case::no_return("once_no_return.rs")] #[case::defined_type("once_defined_type.rs")] fn accept_once_attribute_and_call_fixture_just_once(#[case] fname: &str) { let project = prj(fname).with_nocapture(); let output = project.run_tests().unwrap(); // Just to see the errors if fixture doesn't compile assert_in!(output.stderr.str(), "Exec fixture() just once"); let occurrences = output.stderr.str().count("Exec fixture() just once"); assert_eq!(1, occurrences); } mod show_correct_errors { use super::*; use std::process::Output; use rstest::{fixture, rstest}; #[fixture] #[once] fn errors_rs() -> (Output, String) { run_test("errors.rs") } #[rstest] fn when_cannot_resolve_fixture(errors_rs: &(Output, String)) { let (output, name) = errors_rs.clone(); assert_in!(output.stderr.str(), "error[E0433]: "); assert_in!( output.stderr.str(), format!( r#" --> {name}{SRC_LIB_RS}:14:33 | 14 | fn error_cannot_resolve_fixture(no_fixture: u32) {{"# ) .unindent() ); } #[rstest] fn on_mismatched_types_inner(errors_rs: &(Output, String)) { let (output, name) = errors_rs.clone(); assert_in!( output.stderr.str(), format!( r#" error[E0308]: mismatched types --> {name}{SRC_LIB_RS}:10:18 | 10 | let a: u32 = ""; "# ) .unindent() ); } #[rstest] fn on_mismatched_types_argument(errors_rs: &(Output, String)) { let (output, name) = errors_rs.clone(); assert_in!( output.stderr.str(), format!( r#" error[E0308]: mismatched types --> {name}{SRC_LIB_RS}:17:29 "# ) .unindent() ); assert_in!( output.stderr.str(), r#" 17 | fn error_fixture_wrong_type(fixture: String) {} | ^^^^^^"# .unindent() ); } #[rstest] fn on_invalid_fixture(errors_rs: &(Output, String)) { let (output, name) = errors_rs.clone(); assert_in!( output.stderr.str(), format!( " error: Missed argument: 'not_a_fixture' should be a test function argument. --> {name}{SRC_LIB_RS}:19:11 | 19 | #[fixture(not_a_fixture(24))] | ^^^^^^^^^^^^^ " ) .unindent() ); } #[rstest] fn on_duplicate_fixture_argument(errors_rs: &(Output, String)) { let (output, name) = errors_rs.clone(); assert_in!( output.stderr.str(), format!( r#" error: Duplicate argument: 'f' is already defined. --> {name}{SRC_LIB_RS}:32:23 | 32 | #[fixture(f("first"), f("second"))] | ^ "# ) .unindent() ); } #[rstest] fn on_destruct_implicit_fixture(errors_rs: &(Output, String)) { let (output, name) = errors_rs.clone(); assert_in!( output.stderr.str(), format!( r#" error: To destruct a fixture you should provide a path to resolve it by '#[from(...)]' attribute. --> {name}{SRC_LIB_RS}:48:35 | 48 | fn error_destruct_without_resolve(T(a): T) {{}} | ^^^^^^^ "# ) .unindent() ); } #[rstest] fn on_destruct_explicit_fixture_without_from(errors_rs: &(Output, String)) { let (output, name) = errors_rs.clone(); assert_in!( output.stderr.str(), format!( r#" error: To destruct a fixture you should provide a path to resolve it by '#[from(...)]' attribute. --> {name}{SRC_LIB_RS}:51:57 | 51 | fn error_destruct_without_resolve_also_with(#[with(21)] T(a): T) {{}} | ^^^^^^^ "# ) .unindent() ); assert_eq!( 1, output.stderr.str().count("51 | fn error_destruct_without") ) } #[fixture] #[once] fn errors_once_rs() -> (Output, String) { run_test("errors_once.rs") } #[rstest] fn deny_docs() { let (output, _) = run_test("deny_docs.rs"); assert_not_in!(output.stdout.str(), "missing_docs"); TestResults::new().ok("success").fail("fail").assert(output); } #[rstest] fn once_async(errors_once_rs: &(Output, String)) { let (output, name) = errors_once_rs.clone(); assert_in!( output.stderr.str(), format!( r#" error: Cannot apply #[once] to async fixture. --> {name}{SRC_LIB_RS}:4:1 | 4 | #[once] "# ) .unindent() ); } #[rstest] fn once_generic_type(errors_once_rs: &(Output, String)) { let (output, name) = errors_once_rs.clone(); assert_in!( output.stderr.str(), format!( r#" error: Cannot apply #[once] on generic fixture. --> {name}{SRC_LIB_RS}:9:1 | 9 | #[once] "# ) .unindent() ); } #[rstest] fn once_generic_impl(errors_once_rs: &(Output, String)) { let (output, name) = errors_once_rs.clone(); assert_in!( output.stderr.str(), format!( r#" error: Cannot apply #[once] on generic fixture. --> {name}{SRC_LIB_RS}:15:1 | 15 | #[once] "# ) .unindent() ); } #[rstest] fn once_on_not_sync_type(errors_once_rs: &(Output, String)) { let (output, name) = errors_once_rs.clone(); assert_in!( output.stderr.str(), format!( r#" error[E0277]: `Cell` cannot be shared between threads safely --> {name}{SRC_LIB_RS}:20:1 | 20 | #[fixture] | ^^^^^^^^^^ `Cell` cannot be shared between threads safely "# ) .unindent(), ); } } } rstest-0.26.1/tests/integration.rs000064400000000000000000000014311046102023000152700ustar 00000000000000use rstest_test::{sanitize_name, testname, Project}; /// Rstest integration tests mod rstest; /// Fixture's integration tests mod fixture; use lazy_static::lazy_static; use std::path::{Path, PathBuf}; use temp_testdir::TempDir; lazy_static! { static ref ROOT_DIR: TempDir = TempDir::default().permanent(); static ref ROOT_PROJECT: Project = Project::new(ROOT_DIR.as_ref()); } pub fn base_prj() -> Project { let prj_name = sanitize_name(testname()); ROOT_PROJECT.subproject(&prj_name) } pub fn prj() -> Project { let prj_name = sanitize_name(testname()); let prj = ROOT_PROJECT.subproject(&prj_name); prj.add_local_dependency("rstest"); prj } pub fn resources>(name: O) -> PathBuf { Path::new("tests").join("resources").join(name) } rstest-0.26.1/tests/resources/fixture/async_fixture.rs000064400000000000000000000036751046102023000213440ustar 00000000000000use std::io::prelude::*; use rstest::*; #[fixture] async fn async_u32() -> u32 { 42 } #[fixture] async fn nest_fixture(#[future] async_u32: u32) -> u32 { async_u32.await } #[fixture(fortytwo = async { 42 })] async fn nest_fixture_with_default(#[future] fortytwo: u32) -> u32 { fortytwo.await } #[rstest] #[async_std::test] async fn default_is_async() { assert_eq!(42, async_u32::default().await); } #[rstest] #[async_std::test] async fn use_async_nest_fixture_default(#[future] nest_fixture: u32) { assert_eq!(42, nest_fixture.await); } #[rstest(nest_fixture(async { 24 }))] #[async_std::test] async fn use_async_nest_fixture_injected(#[future] nest_fixture: u32) { assert_eq!(24, nest_fixture.await); } #[rstest] #[async_std::test] async fn use_async_nest_fixture_with_default(#[future] nest_fixture_with_default: u32) { assert_eq!(42, nest_fixture_with_default.await); } #[rstest] #[async_std::test] async fn use_async_fixture(#[future] async_u32: u32) { assert_eq!(42, async_u32.await); } #[fixture] async fn async_impl_output() -> impl Read { std::io::Cursor::new(vec![1, 2, 3, 4, 5]) } #[rstest] #[async_std::test] async fn use_async_impl_output(#[future] async_impl_output: T) { let reader = async_impl_output.await; } #[fixture(four = async { 4 }, two = 2)] async fn two_args_mix_fixture(#[future] four: u32, two: u32) -> u32 { four.await * 10 + two } #[rstest] #[async_std::test] async fn use_two_args_mix_fixture(#[future] two_args_mix_fixture: u32) { assert_eq!(42, two_args_mix_fixture.await); } #[rstest(two_args_mix_fixture(async { 5 }))] #[async_std::test] async fn use_two_args_mix_fixture_inject_first(#[future] two_args_mix_fixture: u32) { assert_eq!(52, two_args_mix_fixture.await); } #[rstest(two_args_mix_fixture(async { 3 }, 1))] #[async_std::test] async fn use_two_args_mix_fixture_inject_both(#[future] two_args_mix_fixture: u32) { assert_eq!(31, two_args_mix_fixture.await); } rstest-0.26.1/tests/resources/fixture/await_complete_fixture.rs000064400000000000000000000037761046102023000232260ustar 00000000000000use std::io::prelude::*; use rstest::*; #[fixture] async fn async_u32() -> u32 { 42 } #[fixture] #[awt] async fn nest_fixture(#[future] async_u32: u32) -> u32 { async_u32 } #[fixture] #[awt] async fn nest_fixture_with_default( #[future] #[default(async { 42 })] fortytwo: u32, ) -> u32 { fortytwo } #[rstest] #[async_std::test] async fn default_is_async() { assert_eq!(42, async_u32::default().await); } #[rstest] #[async_std::test] #[awt] async fn use_async_nest_fixture_default(#[future] nest_fixture: u32) { assert_eq!(42, nest_fixture); } #[rstest] #[async_std::test] #[awt] async fn use_async_nest_fixture_injected( #[future] #[with(async { 24 })] nest_fixture: u32, ) { assert_eq!(24, nest_fixture); } #[rstest] #[async_std::test] #[awt] async fn use_async_nest_fixture_with_default(#[future] nest_fixture_with_default: u32) { assert_eq!(42, nest_fixture_with_default); } #[rstest] #[async_std::test] #[awt] async fn use_async_fixture(#[future] async_u32: u32) { assert_eq!(42, async_u32); } #[fixture] async fn async_impl_output() -> impl Read { std::io::Cursor::new(vec![1, 2, 3, 4, 5]) } #[rstest] #[async_std::test] #[awt] async fn use_async_impl_output(#[future] async_impl_output: T) { let reader = async_impl_output; } #[fixture] #[awt] async fn two_args_mix_fixture( #[future] #[default(async { 4 })] four: u32, #[default(2)] two: u32, ) -> u32 { four * 10 + two } #[rstest] #[async_std::test] #[awt] async fn use_two_args_mix_fixture(#[future] two_args_mix_fixture: u32) { assert_eq!(42, two_args_mix_fixture); } #[rstest] #[async_std::test] #[awt] async fn use_two_args_mix_fixture_inject_first( #[future] #[with(async { 5 })] two_args_mix_fixture: u32, ) { assert_eq!(52, two_args_mix_fixture); } #[rstest] #[async_std::test] #[awt] async fn use_two_args_mix_fixture_inject_both( #[future] #[with(async { 3 }, 1)] two_args_mix_fixture: u32, ) { assert_eq!(31, two_args_mix_fixture); } rstest-0.26.1/tests/resources/fixture/await_partial_fixture.rs000064400000000000000000000037501046102023000230420ustar 00000000000000use std::io::prelude::*; use rstest::*; #[fixture] async fn async_u32() -> u32 { 42 } #[fixture] async fn nest_fixture(#[future(awt)] async_u32: u32) -> u32 { async_u32 } #[fixture] async fn nest_fixture_with_default( #[future(awt)] #[default(async { 42 })] fortytwo: u32, ) -> u32 { fortytwo } #[rstest] #[async_std::test] async fn default_is_async() { assert_eq!(42, async_u32::default().await); } #[rstest] #[async_std::test] async fn use_async_nest_fixture_default(#[future(awt)] nest_fixture: u32) { assert_eq!(42, nest_fixture); } #[rstest] #[async_std::test] async fn use_async_nest_fixture_injected( #[future(awt)] #[with(async { 24 })] nest_fixture: u32, ) { assert_eq!(24, nest_fixture); } #[rstest] #[async_std::test] async fn use_async_nest_fixture_with_default(#[future(awt)] nest_fixture_with_default: u32) { assert_eq!(42, nest_fixture_with_default); } #[rstest] #[async_std::test] async fn use_async_fixture(#[future(awt)] async_u32: u32) { assert_eq!(42, async_u32); } #[fixture] async fn async_impl_output() -> impl Read { std::io::Cursor::new(vec![1, 2, 3, 4, 5]) } #[rstest] #[async_std::test] async fn use_async_impl_output(#[future(awt)] async_impl_output: T) { let reader = async_impl_output; } #[fixture] async fn two_args_mix_fixture( #[future(awt)] #[default(async { 4 })] four: u32, #[default(2)] two: u32, ) -> u32 { four * 10 + two } #[rstest] #[async_std::test] async fn use_two_args_mix_fixture(#[future(awt)] two_args_mix_fixture: u32) { assert_eq!(42, two_args_mix_fixture); } #[rstest] #[async_std::test] async fn use_two_args_mix_fixture_inject_first( #[future(awt)] #[with(async { 5 })] two_args_mix_fixture: u32, ) { assert_eq!(52, two_args_mix_fixture); } #[rstest] #[async_std::test] async fn use_two_args_mix_fixture_inject_both( #[future(awt)] #[with(async { 3 }, 1)] two_args_mix_fixture: u32, ) { assert_eq!(31, two_args_mix_fixture); } rstest-0.26.1/tests/resources/fixture/clean_up_default_generics.rs000064400000000000000000000006371046102023000236250ustar 00000000000000use rstest::*; #[fixture] fn s() -> &'static str { "42" } #[fixture] fn fx(s: S) -> usize { s.to_string().len() } #[fixture] fn sum() -> usize { 42 } #[fixture] fn fx_double(sum: usize, s: S) -> usize { s.to_string().len() + sum } #[test] fn resolve() { assert_eq!(2, fx::default()) } #[test] fn resolve_partial() { assert_eq!(12, fx_double::partial_1(10)) } rstest-0.26.1/tests/resources/fixture/default.rs000064400000000000000000000013641046102023000200760ustar 00000000000000use rstest::{fixture, rstest}; #[fixture(value = 42)] pub fn simple(value: u32) -> u32 { value } #[fixture(value = 21, mult = 2)] pub fn double(value: u32, mult: u32) -> u32 { value * mult } #[fixture] pub fn middle() -> u32 { 2 } #[fixture(value = 21, mult = 4)] pub fn mixed(value: u32, middle: u32, mult: u32) -> u32 { value * mult / middle } #[rstest] fn test_simple(simple: u32) { assert_eq!(simple, 42) } #[rstest(simple(21))] fn test_simple_changed(simple: u32) { assert_eq!(simple, 21) } #[rstest] fn test_double(double: u32) { assert_eq!(double, 42) } #[rstest(double(20, 3))] fn test_double_changed(double: u32) { assert_eq!(double, 60) } #[rstest] fn test_mixed(mixed: u32) { assert_eq!(mixed, 42) } rstest-0.26.1/tests/resources/fixture/default_conversion.rs000064400000000000000000000017411046102023000223420ustar 00000000000000use rstest::{fixture, rstest}; use std::net::{Ipv4Addr, SocketAddr}; struct MyType(String); struct E; impl core::str::FromStr for MyType { type Err = E; fn from_str(s: &str) -> Result { match s { "error" => Err(E), inner => Ok(MyType(inner.to_owned())), } } } #[fixture] fn base(#[default("1.2.3.4")] ip: Ipv4Addr, #[default(r#"8080"#)] port: u16) -> SocketAddr { SocketAddr::new(ip.into(), port) } #[fixture] fn fail(#[default("error")] t: MyType) -> MyType { t } #[fixture] fn valid(#[default("some")] t: MyType) -> MyType { t } #[rstest] fn test_base(base: SocketAddr) { assert_eq!(base, "1.2.3.4:8080".parse().unwrap()); } #[fixture] fn byte_array(#[default(b"1234")] some: &[u8]) -> usize { some.len() } #[rstest] fn test_byte_array(byte_array: usize) { assert_eq!(4, byte_array); } #[rstest] fn test_convert_custom(valid: MyType) {} #[rstest] fn test_fail_conversion(fail: MyType) {} rstest-0.26.1/tests/resources/fixture/default_in_attrs.rs000064400000000000000000000014211046102023000217730ustar 00000000000000use rstest::{fixture, rstest}; #[fixture] pub fn simple(#[default(42)] value: u32) -> u32 { value } #[fixture] pub fn double(#[default(20 + 1)] value: u32, #[default(1 + 1)] mult: u32) -> u32 { value * mult } #[fixture] pub fn middle() -> u32 { 2 } #[fixture] pub fn mixed(#[default(21)] value: u32, middle: u32, #[default(2 + 2)] mult: u32) -> u32 { value * mult / middle } #[rstest] fn test_simple(simple: u32) { assert_eq!(simple, 42) } #[rstest(simple(21))] fn test_simple_changed(simple: u32) { assert_eq!(simple, 21) } #[rstest] fn test_double(double: u32) { assert_eq!(double, 42) } #[rstest(double(20, 3))] fn test_double_changed(double: u32) { assert_eq!(double, 60) } #[rstest] fn test_mixed(mixed: u32) { assert_eq!(mixed, 42) } rstest-0.26.1/tests/resources/fixture/defined_return_type.rs000064400000000000000000000015371046102023000225120ustar 00000000000000use rstest::*; #[fixture] pub fn i() -> u32 { 42 } #[fixture] pub fn j() -> i32 { -42 } #[fixture(::default>::partial_1>)] pub fn fx(i: I, j: J) -> impl Iterator { std::iter::once((i, j)) } #[test] fn resolve() { assert_eq!((42, -42), fx::default().next().unwrap()) } #[test] fn resolve_partial() { assert_eq!((42.0, -42), fx::partial_1(42.0).next().unwrap()) } #[fixture] #[default(impl Iterator)] #[partial_1(impl Iterator)] pub fn fx_attrs(i: I, j: J) -> impl Iterator { std::iter::once((i, j)) } #[test] fn resolve_attrs() { assert_eq!((42, -42), fx_attrs::default().next().unwrap()) } #[test] fn resolve_partial_attrs() { assert_eq!((42.0, -42), fx_attrs::partial_1(42.0).next().unwrap()) }rstest-0.26.1/tests/resources/fixture/deny_docs.rs000064400000000000000000000006501046102023000204160ustar 00000000000000//! Crate with tests for missing docs. #![deny(missing_docs)] use rstest::{fixture, rstest}; /// Root fixture #[fixture] pub fn root() -> u32 { 21 } /// Injection fixture #[fixture] pub fn injection(root: u32) -> u32 { 2 * root } /// Success test #[rstest] pub fn success(injection: u32) { assert_eq!(42, injection); } /// Fail test #[rstest] pub fn fail(injection: u32) { assert_eq!(41, injection); } rstest-0.26.1/tests/resources/fixture/dyn.rs000064400000000000000000000014251046102023000172420ustar 00000000000000use rstest::*; #[fixture] fn dyn_box() -> Box> { Box::new(std::iter::once(42)) } #[fixture] fn dyn_ref() -> &'static dyn ToString { &42 } #[fixture] fn dyn_box_resolve(mut dyn_box: Box>) -> i32 { dyn_box.next().unwrap() } #[fixture] fn dyn_ref_resolve(dyn_ref: &dyn ToString) -> String { dyn_ref.to_string() } #[rstest] fn test_dyn_box(mut dyn_box: Box>) { assert_eq!(42, dyn_box.next().unwrap()) } #[rstest] fn test_dyn_ref(dyn_ref: &dyn ToString) { assert_eq!("42", dyn_ref.to_string()) } #[rstest] fn test_dyn_box_resolve(dyn_box_resolve: i32) { assert_eq!(42, dyn_box_resolve) } #[rstest] fn test_dyn_ref_resolve(dyn_ref_resolve: String) { assert_eq!("42", dyn_ref_resolve) } rstest-0.26.1/tests/resources/fixture/errors.rs000064400000000000000000000014571046102023000177710ustar 00000000000000use rstest::*; #[fixture] pub fn fixture() -> u32 { 42 } #[fixture] fn error_inner(fixture: u32) { let a: u32 = ""; } #[fixture] fn error_cannot_resolve_fixture(no_fixture: u32) {} #[fixture] fn error_fixture_wrong_type(fixture: String) {} #[fixture(not_a_fixture(24))] fn error_inject_an_invalid_fixture(fixture: String) {} #[fixture] fn name() -> &'static str { "name" } #[fixture] fn f(name: &str) -> String { name.to_owned() } #[fixture(f("first"), f("second"))] fn error_inject_a_fixture_more_than_once(f: String) {} struct T(u32); #[fixture] fn structed() -> T { T(42) } #[fixture] fn structed_injectd(fixture: u32) -> T { T(fixture) } #[fixture] fn error_destruct_without_resolve(T(a): T) {} #[fixture] fn error_destruct_without_resolve_also_with(#[with(21)] T(a): T) {} rstest-0.26.1/tests/resources/fixture/errors_once.rs000064400000000000000000000006001046102023000207620ustar 00000000000000use rstest::*; #[fixture] #[once] async fn error_async_once_fixture() { } #[fixture] #[once] fn error_generics_once_fixture() -> T { 42 } #[fixture] #[once] fn error_generics_once_fixture() -> impl Iterator { std::iter::once(42) } #[fixture] #[once] fn error_once_fixture_not_sync() -> std::cell::Cell { std::cell::Cell::new(42) } rstest-0.26.1/tests/resources/fixture/fixture_struct.rs000064400000000000000000000012641046102023000215430ustar 00000000000000use rstest::fixture; trait Mult { fn mult(&self, n: u32) -> u32; } struct M(u32); impl Mult for M { fn mult(&self, n: u32) -> u32 { n * self.0 } } #[fixture] fn my_fixture() -> u32 { 42 } #[fixture] fn multiplier() -> M { M(2) } #[fixture] fn my_fixture_injected(my_fixture: u32, multiplier: impl Mult) -> u32 { multiplier.mult(my_fixture) } #[test] fn resolve_new() { assert_eq!(42, my_fixture::get()); } #[test] fn resolve_default() { assert_eq!(42, my_fixture::default()); } #[test] fn injected_new() { assert_eq!(63, my_fixture_injected::get(21, M(3))); } #[test] fn injected_default() { assert_eq!(84, my_fixture_injected::default()); } rstest-0.26.1/tests/resources/fixture/from_other_module.rs000064400000000000000000000003101046102023000221510ustar 00000000000000 mod my_mod { use rstest::{fixture}; #[fixture] pub fn mod_fixture() -> u32 { 42 } } use my_mod::mod_fixture; #[test] fn struct_access() { assert_eq!(42, mod_fixture::default()); } rstest-0.26.1/tests/resources/fixture/impl.rs000064400000000000000000000034311046102023000174100ustar 00000000000000use rstest::*; #[fixture] fn fx_base_impl_return() -> impl Iterator { std::iter::once(42) } #[fixture] fn fx_base_impl_input(mut fx_base_impl_return: impl Iterator) -> u32 { fx_base_impl_return.next().unwrap() } #[rstest] fn base_impl_return(mut fx_base_impl_return: impl Iterator) { assert_eq!(42, fx_base_impl_return.next().unwrap()); } #[rstest] fn base_impl_input(mut fx_base_impl_input: u32) { assert_eq!(42, fx_base_impl_input); } #[fixture] fn fx_nested_impl_return() -> impl Iterator { std::iter::once(42) } #[fixture] fn fx_nested_impl_input(mut fx_nested_impl_return: impl Iterator) -> String { fx_nested_impl_return.next().unwrap().to_string() } #[rstest] fn nested_impl_return(mut fx_nested_impl_return: impl Iterator) { assert_eq!("42", fx_nested_impl_return.next().unwrap().to_string()); } #[rstest] fn nested_impl_input(mut fx_nested_impl_input: String) { assert_eq!("42", &fx_nested_impl_input); } #[fixture] fn fx_nested_multiple_impl_return() -> (impl Iterator, impl ToString) { (std::iter::once(42), 42i32) } #[fixture] fn fx_nested_multiple_impl_input(mut fx_nested_multiple_impl_return: (impl Iterator, impl ToString)) -> bool { fx_nested_multiple_impl_return.0.next().unwrap().to_string() == fx_nested_multiple_impl_return.1.to_string() } #[rstest] fn nested_multiple_impl_return(mut fx_nested_multiple_impl_return: (impl Iterator, impl ToString)) { assert_eq!(fx_nested_multiple_impl_return.0.next().unwrap().to_string(), fx_nested_multiple_impl_return.1.to_string()); } #[rstest] fn nested_multiple_impl_input(fx_nested_multiple_impl_input: bool) { assert!(fx_nested_multiple_impl_input); } rstest-0.26.1/tests/resources/fixture/no_warning.rs000064400000000000000000000003051046102023000206050ustar 00000000000000use rstest::*; #[fixture] fn val() -> i32 { 21 } #[fixture] fn fortytwo(mut val: i32) -> i32 { val *= 2; val } #[rstest] fn the_test(fortytwo: i32) { assert_eq!(fortytwo, 42); } rstest-0.26.1/tests/resources/fixture/once.rs000064400000000000000000000005371046102023000173770ustar 00000000000000use rstest::{fixture, rstest}; #[fixture] #[once] fn once_fixture() -> u32 { eprintln!("Exec fixture() just once"); 42 } #[rstest] fn base(once_fixture: &u32) { assert_eq!(&42, once_fixture); } #[rstest] #[case(2)] #[case(3)] #[case(7)] fn cases(once_fixture: &u32, #[case] divisor: u32) { assert_eq!(0, *once_fixture % divisor); } rstest-0.26.1/tests/resources/fixture/once_defined_type.rs000064400000000000000000000011641046102023000221130ustar 00000000000000use rstest::{fixture, rstest}; #[fixture] #[default(u32)] #[partial_1(u32)] #[once] fn once_fixture(#[default(())] a: (), #[default(())] b: ()) -> u32 { eprintln!("Exec fixture() just once"); 42 } #[rstest] fn base(once_fixture: &u32) { assert_eq!(&42, once_fixture); } #[rstest] fn base_partial(#[with(())] once_fixture: &u32) { assert_eq!(&42, once_fixture); } #[rstest] fn base_complete(#[with((), ())] once_fixture: &u32) { assert_eq!(&42, once_fixture); } #[rstest] #[case(2)] #[case(3)] #[case(7)] fn cases(once_fixture: &u32, #[case] divisor: u32) { assert_eq!(0, *once_fixture % divisor); } rstest-0.26.1/tests/resources/fixture/once_no_return.rs000064400000000000000000000003751046102023000214720ustar 00000000000000use rstest::*; #[fixture] #[once] fn once_fixture() { eprintln!("Exec fixture() just once"); } #[rstest] fn base(_once_fixture: ()) { assert!(true); } #[rstest] #[case()] #[case()] #[case()] fn cases(_once_fixture: ()) { assert!(true); } rstest-0.26.1/tests/resources/fixture/partial.rs000064400000000000000000000013071046102023000201030ustar 00000000000000use rstest::*; #[fixture] fn f1() -> u32 { 0 } #[fixture] fn f2() -> u32 { 0 } #[fixture] fn f3() -> u32 { 0 } #[fixture] fn fixture(f1: u32, f2: u32, f3: u32) -> u32 { f1 + 10 * f2 + 100 * f3 } #[fixture(fixture(7))] fn partial_1(fixture: u32) -> u32 { fixture } #[fixture(fixture(2, 4))] fn partial_2(fixture: u32) -> u32 { fixture } #[fixture(fixture(2, 4, 5))] fn complete(fixture: u32) -> u32 { fixture } #[rstest] fn default(fixture: u32) { assert_eq!(fixture, 0); } #[rstest] fn t_partial_1(partial_1: u32) { assert_eq!(partial_1, 7); } #[rstest] fn t_partial_2(partial_2: u32) { assert_eq!(partial_2, 42); } #[rstest] fn t_complete(complete: u32) { assert_eq!(complete, 542); } rstest-0.26.1/tests/resources/fixture/partial_in_attr.rs000064400000000000000000000013401046102023000216200ustar 00000000000000use rstest::*; #[fixture] fn f1() -> u32 { 0 } #[fixture] fn f2() -> u32 { 0 } #[fixture] fn f3() -> u32 { 0 } #[fixture] fn fixture(f1: u32, f2: u32, f3: u32) -> u32 { f1 + 10 * f2 + 100 * f3 } #[fixture] fn partial_1(#[with(7)] fixture: u32) -> u32 { fixture } #[fixture] fn partial_2(#[with(2, 4)] fixture: u32) -> u32 { fixture } #[fixture] fn complete(#[with(2, 4, 5)] fixture: u32) -> u32 { fixture } #[rstest] fn default(fixture: u32) { assert_eq!(fixture, 0); } #[rstest] fn t_partial_1(partial_1: u32) { assert_eq!(partial_1, 7); } #[rstest] fn t_partial_2(partial_2: u32) { assert_eq!(partial_2, 42); } #[rstest] fn t_complete(complete: u32) { assert_eq!(complete, 542); } rstest-0.26.1/tests/resources/fixture/rename.rs000064400000000000000000000021721046102023000177170ustar 00000000000000use rstest::*; #[fixture] fn very_long_and_boring_name(#[default(42)] inject: u32) -> u32 { inject } mod sub_module { use super::*; #[fixture] pub fn mod_fixture() -> u32 { 42 } } #[fixture(very_long_and_boring_name as foo)] fn compact(foo: u32) -> u32 { foo } #[fixture(very_long_and_boring_name(21) as foo)] fn compact_injected(foo: u32) -> u32 { foo } #[fixture(sub_module::mod_fixture as foo)] fn compact_from_mod(foo: u32) -> u32 { foo } #[fixture] fn attribute(#[from(very_long_and_boring_name)] foo: u32) -> u32 { foo } #[fixture] fn attribute_mod(#[from(sub_module::mod_fixture)] foo: u32) -> u32 { foo } #[fixture] fn attribute_injected( #[from(very_long_and_boring_name)] #[with(21)] foo: u32, ) -> u32 { foo } #[rstest] fn test( compact: u32, attribute: u32, attribute_mod: u32, compact_from_mod: u32, compact_injected: u32, attribute_injected: u32, ) { assert_eq!(compact, attribute); assert_eq!(attribute, attribute_mod); assert_eq!(attribute_mod, compact_from_mod); assert_eq!(compact_injected, attribute_injected); } rstest-0.26.1/tests/resources/fixture/resolve.rs000064400000000000000000000007251046102023000201310ustar 00000000000000use rstest::{rstest, fixture}; pub trait Tr { fn get() -> Self; } impl Tr for i32 { fn get() -> Self { 42 } } impl Tr for u32 { fn get() -> Self { 42 } } #[fixture] pub fn f() -> T { T::get() } #[fixture] pub fn fu32(f: u32) -> u32 { f } #[fixture] pub fn fi32(f: i32) -> i32 { f } #[rstest] fn test_u32(fu32: u32) { assert_eq!(fu32, 42) } #[rstest] fn test_i32(fi32: i32) { assert_eq!(fi32, 42) } rstest-0.26.1/tests/resources/fixture/simple_injection.rs000064400000000000000000000004121046102023000217760ustar 00000000000000use rstest::{rstest, fixture}; #[fixture] fn root() -> u32 { 21 } #[fixture] fn injection(root: u32) -> u32 { 2 * root } #[rstest] fn success(injection: u32) { assert_eq!(42, injection); } #[rstest] fn fail(injection: u32) { assert_eq!(41, injection); } rstest-0.26.1/tests/resources/rstest/by_ref.rs000064400000000000000000000012071046102023000175520ustar 00000000000000use rstest::*; use std::fs::File; use std::io::Read; use std::path::PathBuf; #[rstest] fn start_with_name( #[files("files/**/*.txt")] #[by_ref] path: &PathBuf, ) { let name = path.file_name().unwrap(); let mut f = File::open(&path).unwrap(); let mut contents = String::new(); f.read_to_string(&mut contents).unwrap(); assert!(contents.starts_with(name.to_str().unwrap())) } #[fixture] fn f() -> u32 { 42 } #[rstest] #[case(42)] fn test( #[by_ref] f: &u32, #[case] #[by_ref] c: &u32, #[values(42, 142)] #[by_ref] v: &u32, ) { assert_eq!(f, c); assert_eq!(*c, *v % 100); } rstest-0.26.1/tests/resources/rstest/cases/args_with_no_cases.rs000064400000000000000000000001641046102023000232440ustar 00000000000000use rstest::rstest; #[rstest(one, two, three)] fn should_show_error_for_no_case(one: u32, two: u32, three: u32) {} rstest-0.26.1/tests/resources/rstest/cases/async.rs000064400000000000000000000010621046102023000205160ustar 00000000000000use rstest::*; #[rstest] #[case::pass(42, async { 42 })] #[case::fail(42, async { 41 })] #[should_panic] #[case::pass_panic(42, async { 41 })] #[should_panic] #[case::fail_panic(42, async { 42 })] #[async_std::test] async fn my_async_test( #[case] expected: u32, #[case] #[future] value: u32, ) { assert_eq!(expected, value.await); } #[rstest] #[case::pass(42, async { 42 })] #[async_std::test] async fn my_async_test_revert( #[case] expected: u32, #[future] #[case] value: u32, ) { assert_eq!(expected, value.await); } rstest-0.26.1/tests/resources/rstest/cases/async_awt.rs000064400000000000000000000010601046102023000213670ustar 00000000000000use rstest::*; #[rstest] #[case::pass(42, async { 42 })] #[case::fail(42, async { 41 })] #[should_panic] #[case::pass_panic(42, async { 41 })] #[should_panic] #[case::fail_panic(42, async { 42 })] #[async_std::test] async fn my_async_test( #[case] expected: u32, #[case] #[future(awt)] value: u32, ) { assert_eq!(expected, value); } #[rstest] #[case::pass(42, async { 42 })] #[async_std::test] async fn my_async_test_revert( #[case] expected: u32, #[future(awt)] #[case] value: u32, ) { assert_eq!(expected, value); } rstest-0.26.1/tests/resources/rstest/cases/async_awt_global.rs000064400000000000000000000010641046102023000227130ustar 00000000000000use rstest::*; #[rstest] #[case::pass(42, async { 42 })] #[case::fail(42, async { 41 })] #[should_panic] #[case::pass_panic(42, async { 41 })] #[should_panic] #[case::fail_panic(42, async { 42 })] #[awt] #[async_std::test] async fn my_async_test( #[case] expected: u32, #[case] #[future] value: u32, ) { assert_eq!(expected, value); } #[rstest] #[case::pass(42, async { 42 })] #[awt] #[async_std::test] async fn my_async_test_revert( #[case] expected: u32, #[future] #[case] value: u32, ) { assert_eq!(expected, value); } rstest-0.26.1/tests/resources/rstest/cases/async_awt_mut.rs000064400000000000000000000005601046102023000222600ustar 00000000000000use rstest::*; #[rstest] #[case::pass(async { 3 })] #[awt] #[async_std::test] async fn my_mut_test_global_awt( #[future] #[case] mut a: i32, ) { a = 4; assert_eq!(a, 4); } #[rstest] #[case::pass(async { 3 })] #[async_std::test] async fn my_mut_test_local_awt( #[future(awt)] #[case] mut a: i32, ) { a = 4; assert_eq!(a, 4); } rstest-0.26.1/tests/resources/rstest/cases/case_attributes.rs000064400000000000000000000010531046102023000225620ustar 00000000000000use rstest::rstest; #[rstest( val, case::no_panic(0), #[should_panic] case::panic(2), #[should_panic(expected="expected")] case::panic_with_message(3), case::no_panic_but_fail(1), #[should_panic] case::panic_but_fail(0), #[should_panic(expected="other")] case::panic_with_wrong_message(3), )] fn attribute_per_case(val: i32) { match val { 0 => assert!(true), 1 => assert!(false), 2 => panic!("No catch"), 3 => panic!("expected"), _ => panic!("Not defined"), } } rstest-0.26.1/tests/resources/rstest/cases/case_with_wrong_args.rs000064400000000000000000000003461046102023000236030ustar 00000000000000use rstest::rstest; #[cfg(test)] #[rstest(a, b, case(42), case(1, 2), case(43))] fn error_less_arguments(a: u32, b: u32) {} #[cfg(test)] #[rstest(a, case(42, 43), case(12), case(24, 34))] fn error_too_much_arguments(a: u32) {} rstest-0.26.1/tests/resources/rstest/cases/description.rs000064400000000000000000000003151046102023000217240ustar 00000000000000use rstest::rstest; #[rstest( expected, case::user_test_description(true), case(true), case::user_test_description_fail(false) )] fn description(expected: bool) { assert!(expected); } rstest-0.26.1/tests/resources/rstest/cases/dump_just_one_case.rs000064400000000000000000000003221046102023000232450ustar 00000000000000use rstest::*; #[rstest] #[case::first_no_dump("Please don't trace me")] #[trace] #[case::dump_me("Trace it!")] #[case::last_no_dump("Please don't trace me")] fn cases(#[case] s: &str) { assert!(false); } rstest-0.26.1/tests/resources/rstest/cases/inject.rs000064400000000000000000000014611046102023000206600ustar 00000000000000use rstest::*; use actix_rt; use std::future::Future; #[rstest(expected, value, case::pass(42, 42), #[should_panic] case::panic(41, 42), case::fail(1, 42) )] #[test] fn sync(expected: u32, value: u32) { assert_eq!(expected, value); } #[rstest(expected, value, case::pass(42, async { 42 }), #[should_panic] case::panic(41, async { 42 }), case::fail(1, async { 42 }) )] #[actix_rt::test] async fn fn_async(expected: u32, value: impl Future) { assert_eq!(expected, value.await); } #[rstest(expected, value, case::pass(42, async { 42 }), #[should_panic] case::panic(41, async { 42 }), case::fail(1, async { 42 }) )] #[test_attr(actix_rt::test)] async fn fn_async_test_attr(expected: u32, value: impl Future) { assert_eq!(expected, value.await); } rstest-0.26.1/tests/resources/rstest/cases/missed_argument.rs000064400000000000000000000001411046102023000225640ustar 00000000000000use rstest::rstest; #[cfg(test)] #[rstest(f, case(42), case(24))] fn error_param_not_exist() {} rstest-0.26.1/tests/resources/rstest/cases/missed_some_arguments.rs000064400000000000000000000001611046102023000237740ustar 00000000000000use rstest::rstest; #[cfg(test)] #[rstest(a,b,c, case(1,2,3), case(3,2,1))] fn error_param_not_exist(b: u32) {} rstest-0.26.1/tests/resources/rstest/cases/partial.rs000064400000000000000000000022321046102023000210350ustar 00000000000000use rstest::*; #[fixture] fn f1() -> u32 { 0 } #[fixture] fn f2() -> u32 { 0 } #[fixture] fn f3() -> u32 { 0 } #[fixture] fn fixture(f1: u32, f2: u32, f3: u32) -> u32 { f1 + 10 * f2 + 100 * f3 } #[rstest(expected, case(0), case(1000))] fn default(fixture: u32, expected: u32) { assert_eq!(fixture, expected); } #[rstest(fixture(7), expected, case(7), case(1000))] fn partial_1(fixture: u32, expected: u32) { assert_eq!(fixture, expected); } #[rstest(expected, case(7), case(1000))] fn partial_attr_1(#[with(7)] fixture: u32, expected: u32) { assert_eq!(fixture, expected); } #[rstest(fixture(2, 4), expected, case(42), case(1000))] fn partial_2(fixture: u32, expected: u32) { assert_eq!(fixture, expected); } #[rstest(expected, case(42), case(1000))] fn partial_attr_2(#[with(2, 4)] fixture: u32, expected: u32) { assert_eq!(fixture, expected); } #[rstest(fixture(2, 4, 5), expected, case(542), case(1000))] fn complete(fixture: u32, expected: u32) { assert_eq!(fixture, expected); } #[rstest(expected, case(542), case(1000))] fn complete_attr(#[with(2, 4, 5)] fixture: u32, expected: u32) { assert_eq!(fixture, expected); } rstest-0.26.1/tests/resources/rstest/cases/simple.rs000064400000000000000000000002671046102023000207000ustar 00000000000000use rstest::rstest; #[rstest( expected, input, case(4, "ciao"), case(3, "Foo") )] fn strlen_test(expected: usize, input: &str) { assert_eq!(expected, input.len()); } rstest-0.26.1/tests/resources/rstest/cases/use_attr.rs000064400000000000000000000014441046102023000212330ustar 00000000000000use rstest::rstest; #[rstest] #[case::ciao(4, "ciao")] #[should_panic] #[case::panic(42, "Foo")] #[case::foo(3, "Foo")] fn all(#[case] expected: usize, #[case] input: &str) { assert_eq!(expected, input.len()); } #[rstest(expected, input)] #[case::ciao(4, "ciao")] #[case::foo(3, "Foo")] #[should_panic] #[case::panic(42, "Foo")] fn just_cases(expected: usize, input: &str) { assert_eq!(expected, input.len()); } #[rstest( case::ciao(4, "ciao"), case::foo(3, "Foo"), #[should_panic] case::panic(42, "Foo"), )] fn just_args(#[case] expected: usize, #[case] input: &str) { assert_eq!(expected, input.len()); } #[rstest] #[case(0, "ciao")] #[case(0, "Foo")] #[should_panic] fn all_panic(#[case] expected: usize, #[case] input: &str) { assert_eq!(expected, input.len()); } rstest-0.26.1/tests/resources/rstest/context.rs000064400000000000000000000014301046102023000177660ustar 00000000000000use rstest::*; #[rstest] #[case::description(42)] fn with_case(#[context] ctx: Context, #[case] _c: u32) { assert_eq!("with_case", ctx.name); assert_eq!(Some("description"), ctx.description); assert_eq!(Some(0), ctx.case); } #[rstest] fn without_case(#[context] ctx: Context) { assert_eq!("without_case", ctx.name); assert_eq!(None, ctx.description); assert_eq!(None, ctx.case); } mod first { mod inner { use rstest::*; #[rstest] fn test(#[context] ctx: Context) { assert!(ctx.module.ends_with("first::inner")); } } } #[rstest] fn measure_time(#[context] ctx: Context) { std::thread::sleep(std::time::Duration::from_millis(100)); assert!(ctx.start.elapsed() >= std::time::Duration::from_millis(100)); } rstest-0.26.1/tests/resources/rstest/convert_string_literal.rs000064400000000000000000000034131046102023000230670ustar 00000000000000use rstest::*; use std::net::SocketAddr; #[rstest] #[case(true, "1.2.3.4:42")] #[case(true, r#"4.3.2.1:24"#)] #[case(false, "[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443")] #[case(false, r#"[2aa1:db8:85a3:8af:1319:8a2e:375:4873]:344"#)] #[case(false, "this.is.not.a.socket.address")] #[case(false, r#"this.is.not.a.socket.address"#)] fn cases(#[case] expected: bool, #[case] addr: SocketAddr) { assert_eq!(expected, addr.is_ipv4()); } #[rstest] fn values( #[values( "1.2.3.4:42", r#"4.3.2.1:24"#, "this.is.not.a.socket.address", r#"this.is.not.a.socket.address"# )] addr: SocketAddr, ) { assert!(addr.is_ipv4()) } #[rstest] #[case(b"12345")] fn not_convert_byte_array(#[case] cases: &[u8], #[values(b"abc")] values: &[u8]) { assert_eq!(5, cases.len()); assert_eq!(3, values.len()); } trait MyTrait { fn my_trait(&self) -> u32 { 42 } } impl MyTrait for &str {} #[rstest] #[case("impl", "nothing")] fn not_convert_impl(#[case] that_impl: impl MyTrait, #[case] s: &str) { assert_eq!(42, that_impl.my_trait()); assert_eq!(42, s.my_trait()); } #[rstest] #[case("1.2.3.4", "1.2.3.4:42")] #[case("1.2.3.4".to_owned(), "1.2.3.4:42")] fn not_convert_generics>(#[case] ip: S, #[case] addr: SocketAddr) { assert_eq!(addr.ip().to_string(), ip.as_ref()); } struct MyType(String); struct E; impl core::str::FromStr for MyType { type Err = E; fn from_str(s: &str) -> Result { match s { "error" => Err(E), inner => Ok(MyType(inner.to_owned())), } } } #[rstest] #[case("hello", "hello")] #[case("doesn't mater", "error")] fn convert_without_debug(#[case] expected: &str, #[case] converted: MyType) { assert_eq!(expected, converted.0); } rstest-0.26.1/tests/resources/rstest/convert_string_literal_other_name.rs000064400000000000000000000034171046102023000252740ustar 00000000000000use other_name::*; use std::net::SocketAddr; #[rstest] #[case(true, "1.2.3.4:42")] #[case(true, r#"4.3.2.1:24"#)] #[case(false, "[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443")] #[case(false, r#"[2aa1:db8:85a3:8af:1319:8a2e:375:4873]:344"#)] #[case(false, "this.is.not.a.socket.address")] #[case(false, r#"this.is.not.a.socket.address"#)] fn cases(#[case] expected: bool, #[case] addr: SocketAddr) { assert_eq!(expected, addr.is_ipv4()); } #[rstest] fn values( #[values( "1.2.3.4:42", r#"4.3.2.1:24"#, "this.is.not.a.socket.address", r#"this.is.not.a.socket.address"# )] addr: SocketAddr, ) { assert!(addr.is_ipv4()) } #[rstest] #[case(b"12345")] fn not_convert_byte_array(#[case] cases: &[u8], #[values(b"abc")] values: &[u8]) { assert_eq!(5, cases.len()); assert_eq!(3, values.len()); } trait MyTrait { fn my_trait(&self) -> u32 { 42 } } impl MyTrait for &str {} #[rstest] #[case("impl", "nothing")] fn not_convert_impl(#[case] that_impl: impl MyTrait, #[case] s: &str) { assert_eq!(42, that_impl.my_trait()); assert_eq!(42, s.my_trait()); } #[rstest] #[case("1.2.3.4", "1.2.3.4:42")] #[case("1.2.3.4".to_owned(), "1.2.3.4:42")] fn not_convert_generics>(#[case] ip: S, #[case] addr: SocketAddr) { assert_eq!(addr.ip().to_string(), ip.as_ref()); } struct MyType(String); struct E; impl core::str::FromStr for MyType { type Err = E; fn from_str(s: &str) -> Result { match s { "error" => Err(E), inner => Ok(MyType(inner.to_owned())), } } } #[rstest] #[case("hello", "hello")] #[case("doesn't mater", "error")] fn convert_without_debug(#[case] expected: &str, #[case] converted: MyType) { assert_eq!(expected, converted.0); } rstest-0.26.1/tests/resources/rstest/destruct.rs000064400000000000000000000026251046102023000201460ustar 00000000000000use rstest::*; struct T { a: u32, b: u32, } impl T { fn new(a: u32, b: u32) -> Self { Self { a, b } } } struct S(u32, u32); #[fixture] fn fix() -> T { T::new(1, 42) } #[fixture] fn named() -> S { S(1, 42) } #[fixture] fn tuple() -> (u32, u32) { (1, 42) } #[fixture] fn swap(#[from(fix)] T { a, b }: T) -> T { T::new(b, a) } #[rstest] fn swapped(#[from(swap)] T { a, b }: T) { assert_eq!(a, 42); assert_eq!(b, 1); } #[rstest] #[case::two_times_twenty_one(T::new(2, 21))] #[case::six_times_seven(T{ a: 6, b: 7 })] fn cases_destruct( #[from(fix)] T { a, b }: T, #[case] T { a: c, b: d }: T, #[values(T::new(42, 1), T{ a: 3, b: 14})] T { a: e, b: f }: T, ) { assert_eq!(a * b, 42); assert_eq!(c * d, 42); assert_eq!(e * f, 42); } #[rstest] #[case::two_times_twenty_one(S(2, 21))] #[case::six_times_seven(S(6, 7))] fn cases_destruct_named_tuple( #[from(named)] S(a, b): S, #[case] S(c, d): S, #[values(S(42, 1), S(3, 14))] S(e, f): S, ) { assert_eq!(a * b, 42); assert_eq!(c * d, 42); assert_eq!(e * f, 42); } #[rstest] #[case::two_times_twenty_one((2, 21))] #[case::six_times_seven((6, 7))] fn cases_destruct_tuple( #[from(tuple)] (a, b): (u32, u32), #[case] (c, d): (u32, u32), #[values((42, 1), (3, 14))] (e, f): (u32, u32), ) { assert_eq!(a * b, 42); assert_eq!(c * d, 42); assert_eq!(e * f, 42); } rstest-0.26.1/tests/resources/rstest/dump_debug.rs000064400000000000000000000022431046102023000204200ustar 00000000000000use rstest::*; #[derive(Debug)] struct A {} #[fixture] fn fu32() -> u32 { 42 } #[fixture] fn fstring() -> String { "A String".to_string() } #[fixture] fn ftuple() -> (A, String, i32) { (A {}, "A String".to_string(), -12) } #[rstest] #[trace] fn single_fail(fu32: u32, fstring: String, ftuple: (A, String, i32)) { assert!(false); } #[rstest] fn no_trace_single_fail(fu32: u32, fstring: String, ftuple: (A, String, i32)) { assert!(false); } #[rstest] #[case(42, "str", ("ss", -12))] #[case(24, "trs", ("tt", -24))] #[trace] fn cases_fail(#[case] u: u32, #[case] s: &str, #[case] t: (&str, i32)) { assert!(false); } #[rstest] #[case(42, "str", ("ss", -12))] #[case(24, "trs", ("tt", -24))] fn no_trace_cases_fail(#[case] u: u32, #[case] s: &str, #[case] t: (&str, i32)) { assert!(false); } #[rstest] #[trace] fn matrix_fail( #[values(1, 3)] u: u32, #[values("rst", "srt")] s: &str, #[values(("SS", -12), ("TT", -24))] t: (&str, i32), ) { assert!(false); } #[rstest] fn no_trace_matrix_fail( #[values(1, 3)] u: u32, #[values("rst", "srt")] s: &str, #[values(("SS", -12), ("TT", -24))] t: (&str, i32), ) { assert!(false); } rstest-0.26.1/tests/resources/rstest/dump_debug_compact.rs000064400000000000000000000022011046102023000221200ustar 00000000000000use rstest::*; #[derive(Debug)] struct A {} #[fixture] fn fu32() -> u32 { 42 } #[fixture] fn fstring() -> String { "A String".to_string() } #[fixture] fn ftuple() -> (A, String, i32) { (A {}, "A String".to_string(), -12) } #[rstest(::trace)] fn single_fail(fu32: u32, fstring: String, ftuple: (A, String, i32)) { assert!(false); } #[rstest] fn no_trace_single_fail(fu32: u32, fstring: String, ftuple: (A, String, i32)) { assert!(false); } #[rstest(u, s, t, case(42, "str", ("ss", -12)), case(24, "trs", ("tt", -24)) ::trace )] fn cases_fail(u: u32, s: &str, t: (&str, i32)) { assert!(false); } #[rstest(u, s, t, case(42, "str", ("ss", -12)), case(24, "trs", ("tt", -24)) )] fn no_trace_cases_fail(u: u32, s: &str, t: (&str, i32)) { assert!(false); } #[rstest( u => [1, 2], s => ["rst", "srt"], t => [("SS", -12), ("TT", -24)] ::trace )] fn matrix_fail(u: u32, s: &str, t: (&str, i32)) { assert!(false); } #[rstest( u => [1, 2], s => ["rst", "srt"], t => [("SS", -12), ("TT", -24)] )] fn no_trace_matrix_fail(u: u32, s: &str, t: (&str, i32)) { assert!(false); } rstest-0.26.1/tests/resources/rstest/dump_exclude_some_inputs.rs000064400000000000000000000012241046102023000234060ustar 00000000000000use rstest::*; struct A; struct B; #[derive(Debug)] struct D; #[fixture] fn fu32() -> u32 { 42 } #[fixture] fn fb() -> B { B {} } #[fixture] fn fd() -> D { D {} } #[fixture] fn fa() -> A { A {} } #[rstest] #[trace] fn simple(fu32: u32, #[notrace] fa: A, #[notrace] fb: B, fd: D) { assert!(false); } #[rstest] #[trace] #[case(A{}, B{}, D{})] fn cases(fu32: u32, #[case] #[notrace] a: A, #[case] #[notrace] b: B, #[case] d: D) { assert!(false); } #[rstest] #[trace] fn matrix( fu32: u32, #[notrace] #[values(A{})] a: A, #[notrace] #[values(B{})] b: B, #[values(D{}) ] dd: D, ) { assert!(false); } rstest-0.26.1/tests/resources/rstest/dump_exclude_some_inputs_compact.rs000064400000000000000000000011141046102023000251120ustar 00000000000000use rstest::*; struct A; struct B; #[derive(Debug)] struct D; #[fixture] fn fu32() -> u32 { 42 } #[fixture] fn fb() -> B { B {} } #[fixture] fn fd() -> D { D {} } #[fixture] fn fa() -> A { A {} } #[rstest( ::trace::notrace(fa,fb)) ] fn simple(fu32: u32, fa: A, fb: B, fd: D) { assert!(false); } #[rstest(a,b,d, case(A{}, B{}, D{}) ::trace::notrace(a,b)) ] fn cases(fu32: u32, a: A, b: B, d: D) { assert!(false); } #[rstest( a => [A{}], b => [B{}], dd => [D{}], ::trace::notrace(a,b)) ] fn matrix(fu32: u32, a: A, b: B, dd: D) { assert!(false); } rstest-0.26.1/tests/resources/rstest/dump_not_debug.rs000064400000000000000000000004171046102023000213010ustar 00000000000000struct S; #[rustfmt::skip] mod _skip_format { use rstest::*; use super::*; #[fixture] fn fixture() -> S { S {} } #[rstest] #[trace] fn single(fixture: S) {} #[rstest(s)] #[trace] #[case(S{})] fn cases(s: S) {} #[rstest( s => [S{}])] #[trace] fn matrix(s: S) {} } rstest-0.26.1/tests/resources/rstest/dump_not_debug_compact.rs000064400000000000000000000004341046102023000230060ustar 00000000000000struct S; #[rustfmt::skip] mod _skip_format { use rstest::*; use super::*; #[fixture] fn fixture() -> S { S {} } #[rstest( ::trace)] fn single(fixture: S) {} #[rstest(s, case(S{}) ::trace)] fn cases(s: S) {} #[rstest( s => [S{}] ::trace)] fn matrix(s: S) {} } rstest-0.26.1/tests/resources/rstest/errors.rs000064400000000000000000000052651046102023000176300ustar 00000000000000use rstest::*; #[fixture] pub fn fixture() -> u32 { 42 } #[rstest(f, case(42))] fn error_inner(f: i32) { let a: u32 = ""; } #[rstest(f, case(42))] fn error_cannot_resolve_fixture(no_fixture: u32, f: u32) {} #[rstest(f, case(42))] fn error_fixture_wrong_type(fixture: String, f: u32) {} #[rstest(f, case(42))] fn error_case_wrong_type(f: &str) {} #[rstest(condition, case(vec![1,2,3].contains(2))) ] fn error_in_arbitrary_rust_code_cases(condition: bool) { assert!(condition) } #[rstest(f, case(42), not_a_fixture(24))] fn error_inject_an_invalid_fixture(f: u32) {} #[fixture] fn n() -> u32 { 24 } #[fixture] fn f(n: u32) -> u32 { 2 * n } #[rstest(f, f(42), case(12))] fn error_inject_a_fixture_that_is_already_a_case(f: u32) {} #[rstest(f(42), f, case(12))] fn error_define_case_that_is_already_an_injected_fixture(f: u32) {} #[rstest(v, f(42), f(42), case(12))] fn error_inject_a_fixture_more_than_once(v: u32, f: u32) {} #[rstest(f => [42])] fn error_matrix_wrong_type(f: &str) {} #[rstest(condition => [vec![1,2,3].contains(2)] )] fn error_arbitrary_rust_code_matrix(condition: bool) { assert!(condition) } #[rstest(empty => [])] fn error_empty_list(empty: &str) {} #[rstest(not_exist_1 => [42], not_exist_2 => [42])] fn error_no_match_args() {} #[rstest(f => [41, 42], f(42))] fn error_inject_a_fixture_that_is_already_a_value_list(f: u32) {} #[rstest(f(42), f => [41, 42])] fn error_define_a_value_list_that_is_already_an_injected_fixture(f: u32) {} #[rstest(a, case(42), a => [42])] fn error_define_a_value_list_that_is_already_a_case_arg(a: u32) {} #[rstest(a => [42], a, case(42))] fn error_define_a_case_arg_that_is_already_a_value_list(a: u32) {} #[rstest(a => [42, 24], a => [24, 42])] fn error_define_a_value_list_that_is_already_a_value_list(f: u32) {} #[rstest(a, a, case(42))] fn error_define_a_case_arg_that_is_already_a_case_arg(a: u32) {} struct S; #[rstest] #[case("donald duck")] fn error_convert_to_type_that_not_implement_from_str(#[case] s: S) {} #[rstest] #[case(async { "hello" } )] async fn error_future_on_impl_type( #[case] #[future] s: impl AsRef, ) { } #[rstest] #[case(async { 42 } )] async fn error_future_more_than_once( #[case] #[future] #[future] a: i32, ) { } #[rstest] #[timeout] fn error_timeout_without_arg() {} #[rstest] #[timeout(some -> strange -> invalid -> expression)] fn error_timeout_without_expression_arg() {} #[rstest] #[timeout(42)] fn error_timeout_without_duration() {} #[rstest] fn error_absolute_path_files(#[files("/tmp/tmp.Q81idVZYAV/*.txt")] path: std::path::PathBuf) {} struct T(u32, u32); #[rstest] #[case(T(3, 4))] fn wrong_destruct_fixture(T(a, b): T, #[with(42)] T(c, d): T) {} rstest-0.26.1/tests/resources/rstest/files.rs000064400000000000000000000076471046102023000174240ustar 00000000000000use rstest::*; use std::fs::File; use std::io::Read; use std::path::PathBuf; #[rstest] fn start_with_name( #[files("files/**/*.txt")] #[exclude("exclude")] #[files("../files_test_sub_folder/**/*.txt")] path: PathBuf, ) { let name = path.file_name().unwrap(); let mut f = File::open(&path).unwrap(); let mut contents = String::new(); f.read_to_string(&mut contents).unwrap(); assert!(contents.starts_with(name.to_str().unwrap())) } #[rstest] fn start_with_name_file_mode( #[files("files/**/*.txt")] #[exclude("exclude")] #[files("../files_test_sub_folder/**/*.txt")] #[mode = path] path: PathBuf, ) { let name = path.file_name().unwrap(); let mut f = File::open(&path).unwrap(); let mut contents = String::new(); f.read_to_string(&mut contents).unwrap(); assert!(contents.starts_with(name.to_str().unwrap())) } #[rstest] fn start_with_name_with_include( #[files("files/**/*.txt")] #[exclude("exclude")] #[include_dot_files] path: PathBuf, ) { let name = path.file_name().unwrap(); let mut f = File::open(&path).unwrap(); let mut contents = String::new(); f.read_to_string(&mut contents).unwrap(); assert!(contents.starts_with(name.to_str().unwrap())) } #[rstest] fn ignore_directories_wildcard( #[files("folders/**/*")] path: PathBuf, ) { assert!(!path.is_dir()) } #[rstest] fn ignore_directories( #[files("folders/**/*.txt")] path: PathBuf, ) { assert!(!path.is_dir()) } #[rstest] fn include_directories_wildcard( #[files("folders/**/*")] #[dirs] path: PathBuf, ) { // Should be generated when the glob matches folders as well. } #[rstest] fn include_directories( #[files("folders/**/*.txt")] #[dirs] path: PathBuf, ) { // Should be generated when the glob matches folders as well. } #[rstest] fn ignore_missing_env_vars( #[ignore_missing_env_vars] #[files("files/**/${__SHOULD_NOT_BE_DECLARED__}*.txt")] #[exclude("exclude")] path: PathBuf, ) { let name = path.file_name().unwrap(); let mut f = File::open(&path).unwrap(); let mut contents = String::new(); f.read_to_string(&mut contents).unwrap(); assert!(contents.starts_with(name.to_str().unwrap())) } #[rstest] fn env_vars( #[files("${FILES_ENV_VAR}/**/*.txt")] #[exclude("exclude")] path: PathBuf, ) { let name = path.file_name().unwrap(); let mut f = File::open(&path).unwrap(); let mut contents = String::new(); f.read_to_string(&mut contents).unwrap(); assert!(contents.starts_with(name.to_str().unwrap())) } #[rstest] fn env_vars_unknown( #[files("${__UNKNOWN__:-files}/**/*.txt")] #[exclude("exclude")] path: PathBuf, ) { let name = path.file_name().unwrap(); let mut f = File::open(&path).unwrap(); let mut contents = String::new(); f.read_to_string(&mut contents).unwrap(); assert!(contents.starts_with(name.to_str().unwrap())) } #[rstest] fn env_vars_base_dir( #[files("**/*.txt")] #[base_dir = "files"] #[exclude("exclude")] path: PathBuf, ) { let name = path.file_name().unwrap(); let mut f = File::open(&path).unwrap(); let mut contents = String::new(); f.read_to_string(&mut contents).unwrap(); assert!(contents.starts_with(name.to_str().unwrap())) } #[rstest] fn include_str( #[files("files/**/*.txt")] #[exclude("exclude")] #[files("../files_test_sub_folder/**/*.txt")] #[mode = str] contents: &str, ) { assert!(contents.len() != 0) } #[rstest] fn include_bytes( #[files("files/**/*.txt")] #[exclude("exclude")] #[files("../files_test_sub_folder/**/*.txt")] #[mode = bytes] contents: &[u8], ) { assert!(contents.len() != 0) } mod module { #[rstest::rstest] fn pathbuf_need_not_be_in_scope( #[files("files/**/*.txt")] #[exclude("exclude")] #[include_dot_files] path: std::path::PathBuf, ) { let _ = path; } } rstest-0.26.1/tests/resources/rstest/generic.rs000064400000000000000000000005541046102023000177240ustar 00000000000000use rstest::*; #[fixture] fn fixture() -> String { "str".to_owned() } #[rstest] fn simple>(fixture: S) { assert_eq!(3, fixture.as_ref().len()); } #[rstest( expected, input, case(4, String::from("ciao")), case(3, "Foo") )] fn strlen_test>(expected: usize, input: S) { assert_eq!(expected, input.as_ref().len()); } rstest-0.26.1/tests/resources/rstest/happy_path.rs000064400000000000000000000007431046102023000204450ustar 00000000000000use rstest::*; #[fixture] fn inject() -> u32 { 0 } #[fixture] fn ex() -> u32 { 42 } #[fixture] fn fix(inject: u32, ex: u32) -> bool { (inject * 2) == ex } #[rstest( fix(21), a, case(21, 2), expected => [4, 2*3-2], )] #[case::second(14, 3)] fn happy( fix: bool, a: u32, #[case] b: u32, expected: usize, #[values("ciao", "buzz")] input: &str, ) { assert!(fix); assert_eq!(a * b, 42); assert_eq!(expected, input.len()); } rstest-0.26.1/tests/resources/rstest/ignore_args.rs000064400000000000000000000002261046102023000206030ustar 00000000000000use rstest::*; #[rstest] #[case(42, 2)] #[case(43, 3)] fn test(#[case] _ignore1: u32, #[case] _ignore2: u32, #[values(1, 2, 3, 4)] _ignore3: u32) {} rstest-0.26.1/tests/resources/rstest/ignore_attributes_args_if_any.rs000064400000000000000000000004371046102023000244020ustar 00000000000000use rstest::*; use sqlx::SqlitePool; fn sum(a: i32, b: i32, c: i32) -> i32 { a + b + c } #[rstest] #[case(1, 2)] #[case(2, 3)] #[sqlx::test] fn test_sum(#[case] a: i32, #[case] b: i32, #[values(1,2)] c: i32, #[ignore] pool: SqlitePool) { assert_eq!(sum(a, b, c), a + b + c); }rstest-0.26.1/tests/resources/rstest/impl_param.rs000064400000000000000000000005521046102023000204270ustar 00000000000000use rstest::*; #[fixture] fn fixture() -> String { "str".to_owned() } #[rstest] fn simple(fixture: impl AsRef) { assert_eq!(3, fixture.as_ref().len()); } #[rstest( expected, input, case(4, String::from("ciao")), case(3, "Foo") )] fn strlen_test(expected: usize, input: impl AsRef) { assert_eq!(expected, input.as_ref().len()); } rstest-0.26.1/tests/resources/rstest/lifetimes.rs000064400000000000000000000004451046102023000202700ustar 00000000000000use rstest::*; enum E<'a> { A(bool), B(&'a std::cell::Cell>), } #[rstest] #[case(E::A(true))] fn case<'a>(#[case] e: E<'a>) {} #[rstest] fn values<'a>(#[values(E::A(true))] e: E<'a>) {} #[fixture] fn e<'a>() -> E<'a> { E::A(true) } #[rstest] fn fixture<'a>(e: E<'a>) {} rstest-0.26.1/tests/resources/rstest/local_lifetime.rs000064400000000000000000000010141046102023000212500ustar 00000000000000use std::cell::Cell; #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum E<'a> { A(bool), B(&'a Cell>), } fn make_e_from_bool<'a>(_bump: &'a (), b: bool) -> E<'a> { E::A(b) } #[cfg(test)] mod tests { use rstest::*; use super::*; #[fixture] fn bump() -> () {} #[rstest] #[case(true, E::A(true))] fn it_works<'a>(#[by_ref] bump: &'a (), #[case] b: bool, #[case] expected: E<'a>) { let actual = make_e_from_bool(&bump, b); assert_eq!(actual, expected); } } rstest-0.26.1/tests/resources/rstest/matrix/async.rs000064400000000000000000000003361046102023000207270ustar 00000000000000use rstest::*; #[rstest] #[async_std::test] async fn my_async_test( #[future] #[values(async { 1 }, async { 2 })] first: u32, #[values(42, 21)] second: u32, ) { assert_eq!(42, first.await * second); } rstest-0.26.1/tests/resources/rstest/matrix/async_awt.rs000064400000000000000000000003351046102023000216010ustar 00000000000000use rstest::*; #[rstest] #[async_std::test] async fn my_async_test( #[future(awt)] #[values(async { 1 }, async { 2 })] first: u32, #[values(42, 21)] second: u32, ) { assert_eq!(42, first * second); } rstest-0.26.1/tests/resources/rstest/matrix/async_awt_global.rs000064400000000000000000000003371046102023000231230ustar 00000000000000use rstest::*; #[rstest] #[async_std::test] #[awt] async fn my_async_test( #[future] #[values(async { 1 }, async { 2 })] first: u32, #[values(42, 21)] second: u32, ) { assert_eq!(42, first * second); } rstest-0.26.1/tests/resources/rstest/matrix/inject.rs000064400000000000000000000011411046102023000210610ustar 00000000000000use rstest::*; use actix_rt; use std::future::Future; #[rstest( first => [1, 2], second => [2, 1], )] #[test] fn sync(first: u32, second: u32) { assert_eq!(2, first * second); } #[rstest( first => [async { 1 }, async { 2 }], second => [2, 1], )] #[actix_rt::test] async fn fn_async(first: impl Future, second: u32) { assert_eq!(2, first.await * second); } #[rstest( first => [async { 1 }, async { 2 }], second => [2, 1], )] #[test_attr(actix_rt::test)] async fn fn_async_test_attr(first: impl Future, second: u32) { assert_eq!(2, first.await * second); } rstest-0.26.1/tests/resources/rstest/matrix/partial.rs000064400000000000000000000021341046102023000212440ustar 00000000000000use rstest::*; #[fixture] fn f1() -> u32 { 0 } #[fixture] fn f2() -> u32 { 0 } #[fixture] fn f3() -> u32 { 0 } #[fixture] fn fixture(f1: u32, f2: u32, f3: u32) -> u32 { f1 + f2 + 2 * f3 } #[rstest(a => [0, 1], b => [0, 2])] fn default(fixture: u32, a: u32, b: u32) { assert_eq!(fixture, a * b); } #[rstest(a => [0, 1], b => [0, 2], fixture(1))] fn partial_1(fixture: u32, a: u32, b: u32) { assert_eq!(fixture, a * b); } #[rstest(a => [0, 1], b => [0, 2])] fn partial_attr_1(#[with(1)] fixture: u32, a: u32, b: u32) { assert_eq!(fixture, a * b); } #[rstest(a => [0, 1], b => [0, 2], fixture(0, 2))] fn partial_2(fixture: u32, a: u32, b: u32) { assert_eq!(fixture, a * b); } #[rstest(a => [0, 1], b => [0, 2])] fn partial_attr_2(#[with(0, 2)] fixture: u32, a: u32, b: u32) { assert_eq!(fixture, a * b); } #[rstest(a => [0, 1], b => [0, 2], fixture(0, 0, 1))] fn complete(fixture: u32, a: u32, b: u32) { assert_eq!(fixture, a * b); } #[rstest(a => [0, 1], b => [0, 2])] fn complete_attr(#[with(0, 0, 1)] fixture: u32, a: u32, b: u32) { assert_eq!(fixture, a * b); } rstest-0.26.1/tests/resources/rstest/matrix/simple.rs000064400000000000000000000002651046102023000211040ustar 00000000000000use rstest::rstest; #[rstest( expected => [4, 2*3-2], input => ["ciao", "buzz"], )] fn strlen_test(expected: usize, input: &str) { assert_eq!(expected, input.len()); } rstest-0.26.1/tests/resources/rstest/matrix/use_attr.rs000064400000000000000000000007061046102023000214410ustar 00000000000000use rstest::rstest; #[rstest] fn both(#[values(4, 2*3-2)] expected: usize, #[values("ciao", "buzz")] input: &str) { assert_eq!(expected, input.len()); } #[rstest( input => ["ciao", "buzz"] )] fn first(#[values(4, 2*3-2)] expected: usize, input: &str) { assert_eq!(expected, input.len()); } #[rstest( expected => [4, 2*3-2] )] fn second(expected: usize, #[values("ciao", "buzz")] input: &str) { assert_eq!(expected, input.len()); } rstest-0.26.1/tests/resources/rstest/mut.rs000064400000000000000000000007271046102023000171170ustar 00000000000000use rstest::*; #[fixture] pub fn fixture() -> u32 { 42 } #[rstest] fn should_success(mut fixture: u32) { fixture += 1; assert_eq!(fixture, 43); } #[rstest] fn should_fail(mut fixture: u32) { fixture += 1; assert_ne!(fixture, 43); } #[rstest( expected, val, case(45, 1), case(46, 2), case(47, 2) )] fn add_test(mut fixture: u32, expected: u32, mut val: u32) { fixture += 1; val += fixture + 1; assert_eq!(expected, val); } rstest-0.26.1/tests/resources/rstest/no_std.rs000064400000000000000000000010421046102023000175670ustar 00000000000000#![no_std] use rstest::{fixture, rstest}; #[fixture] #[once] fn once_fixture() -> u64 { 42 } #[fixture] #[once] fn empty_once_fixture() {} #[fixture] async fn async_fixture() -> u64 { 42 } pub fn add(left: u64, right: u64) -> u64 { left + right } #[rstest] #[case("2", "2", "4")] fn it_works(#[case] left: u64, #[case] right: u64, #[case] expected: u64) { assert_eq!(add(left, right), expected); } #[rstest] #[async_std::test] async fn async_works(#[future] async_fixture: u64) { assert_eq!(42, async_fixture.await); } rstest-0.26.1/tests/resources/rstest/panic.rs000064400000000000000000000006311046102023000173760ustar 00000000000000use rstest::*; #[fixture] pub fn fixture() -> u32 { 42 } #[rstest] #[should_panic] fn should_success(fixture: u32) { assert_ne!(fixture, 42); } #[rstest] #[should_panic] fn should_fail(fixture: u32) { assert_eq!(fixture, 42); } #[rstest( expected, input, case(4, 5), case(3, 2), case(3, 3) )] #[should_panic] fn fail(expected: i32, input: i32) { assert_eq!(expected, input); } rstest-0.26.1/tests/resources/rstest/reject_no_item_function.rs000064400000000000000000000001351046102023000231760ustar 00000000000000use rstest::rstest; #[rstest] struct Foo; #[rstest] impl Foo {} #[rstest] mod mod_baz {} rstest-0.26.1/tests/resources/rstest/remove_underscore.rs000064400000000000000000000001711046102023000220310ustar 00000000000000use rstest::*; #[fixture] fn can_be_ignored() {} #[rstest] fn ignore_input(_can_be_ignored: ()) { assert!(true); } rstest-0.26.1/tests/resources/rstest/rename.rs000064400000000000000000000015051046102023000175540ustar 00000000000000use rstest::*; #[fixture] fn very_long_and_boring_name(#[default(42)] inject: u32) -> u32 { inject } mod sub_module { use super::*; #[fixture] pub fn mod_fixture() -> u32 { 42 } } #[rstest(very_long_and_boring_name as foo)] fn compact(foo: u32) { assert!(42 == foo); } #[rstest(sub_module::mod_fixture as foo)] fn compact_mod(foo: u32) { assert!(42 == foo); } #[rstest(very_long_and_boring_name(21) as foo)] fn compact_injected(foo: u32) { assert!(21 == foo); } #[rstest] fn attribute(#[from(very_long_and_boring_name)] foo: u32) { assert!(42 == foo); } #[rstest] fn attribute_mod(#[from(sub_module::mod_fixture)] foo: u32) { assert!(42 == foo); } #[rstest] fn attribute_injected( #[from(very_long_and_boring_name)] #[with(21)] foo: u32, ) { assert!(21 == foo); } rstest-0.26.1/tests/resources/rstest/return_result.rs000064400000000000000000000005471046102023000212270ustar 00000000000000use rstest::rstest; #[rstest] fn should_success() -> Result<(), &'static str> { Ok(()) } #[rstest] fn should_fail() -> Result<(), &'static str> { Err("Return Error") } #[rstest(ret, case::should_success(Ok(())), case::should_fail(Err("Return Error")) )] fn return_type(ret: Result<(), &'static str>) -> Result<(), &'static str> { ret } rstest-0.26.1/tests/resources/rstest/single/async.rs000064400000000000000000000011211046102023000206750ustar 00000000000000use rstest::*; #[fixture] async fn fixture() -> u32 { 42 } #[rstest] #[async_std::test] async fn should_pass(#[future] fixture: u32) { assert_eq!(fixture.await, 42); } #[rstest] #[async_std::test] async fn should_fail(#[future] fixture: u32) { assert_ne!(fixture.await, 42); } #[rstest] #[async_std::test] #[should_panic] async fn should_panic_pass(#[future] fixture: u32) { panic!(format!("My panic -> fixture = {}", fixture.await)); } #[rstest] #[async_std::test] #[should_panic] async fn should_panic_fail(#[future] fixture: u32) { assert_eq!(fixture.await, 42); } rstest-0.26.1/tests/resources/rstest/single/async_awt.rs000064400000000000000000000011151046102023000215530ustar 00000000000000use rstest::*; #[fixture] async fn fixture() -> u32 { 42 } #[rstest] #[async_std::test] async fn should_pass(#[future(awt)] fixture: u32) { assert_eq!(fixture, 42); } #[rstest] #[async_std::test] async fn should_fail(#[future(awt)] fixture: u32) { assert_ne!(fixture, 42); } #[rstest] #[async_std::test] #[should_panic] async fn should_panic_pass(#[future(awt)] fixture: u32) { panic!(format!("My panic -> fixture = {}", fixture)); } #[rstest] #[async_std::test] #[should_panic] async fn should_panic_fail(#[future(awt)] fixture: u32) { assert_eq!(fixture, 42); } rstest-0.26.1/tests/resources/rstest/single/async_awt_global.rs000064400000000000000000000011251046102023000230740ustar 00000000000000use rstest::*; #[fixture] async fn fixture() -> u32 { 42 } #[rstest] #[async_std::test] #[awt] async fn should_pass(#[future] fixture: u32) { assert_eq!(fixture, 42); } #[rstest] #[async_std::test] #[awt] async fn should_fail(#[future] fixture: u32) { assert_ne!(fixture, 42); } #[rstest] #[async_std::test] #[awt] #[should_panic] async fn should_panic_pass(#[future] fixture: u32) { panic!(format!("My panic -> fixture = {}", fixture)); } #[rstest] #[async_std::test] #[awt] #[should_panic] async fn should_panic_fail(#[future] fixture: u32) { assert_eq!(fixture, 42); } rstest-0.26.1/tests/resources/rstest/single/dump_debug.rs000064400000000000000000000005211046102023000216760ustar 00000000000000use rstest::*; #[derive(Debug)] struct A {} #[fixture] fn fu32() -> u32 { 42 } #[fixture] fn fstring() -> String { "A String".to_string() } #[fixture] fn ftuple() -> (A, String, i32) { (A{}, "A String".to_string(), -12) } #[rstest(::trace)] fn should_fail(fu32: u32, fstring: String, ftuple: (A, String, i32)) { assert!(false); } rstest-0.26.1/tests/resources/rstest/single/inject.rs000064400000000000000000000013441046102023000210430ustar 00000000000000use rstest::*; use actix_rt; #[fixture] fn a() -> u32 { 42 } #[rstest] #[test] fn sync_case(a: u32) {} #[rstest] #[test] #[should_panic] fn sync_case_panic(a: u32) { panic!("panic") } #[rstest] #[test] fn sync_case_fail(a: u32) { assert_eq!(2, a); } #[rstest] #[test] fn sync_case_panic_fail(a: u32) { panic!("panic") } #[rstest] #[actix_rt::test] async fn async_case(a: u32) {} #[rstest] #[test_attr(actix_rt::test)] async fn async_case_test_attr(a: u32) {} #[rstest] #[actix_rt::test] async fn async_case_fail(a: u32) { assert_eq!(2, a); } #[rstest] #[actix_rt::test] #[should_panic] async fn async_case_panic(a: u32) { panic!("panic") } #[rstest] #[actix_rt::test] async fn async_case_panic_fail(a: u32) { panic!("panic") }rstest-0.26.1/tests/resources/rstest/single/partial.rs000064400000000000000000000014471046102023000212270ustar 00000000000000use rstest::*; #[fixture] fn f1() -> u32 { 0 } #[fixture] fn f2() -> u32 { 0 } #[fixture] fn f3() -> u32 { 0 } #[fixture] fn fixture(f1: u32, f2: u32, f3: u32) -> u32 { f1 + 10 * f2 + 100 * f3 } #[rstest] fn default(fixture: u32) { assert_eq!(fixture, 0); } #[rstest(fixture(7))] fn partial_1(fixture: u32) { assert_eq!(fixture, 7); } #[rstest] fn partial_attr_1(#[with(7)] fixture: u32) { assert_eq!(fixture, 7); } #[rstest(fixture(2, 4))] fn partial_2(fixture: u32) { assert_eq!(fixture, 42); } #[rstest] fn partial_attr_2(#[with(2, 4)] fixture: u32) { assert_eq!(fixture, 42); } #[rstest(fixture(2, 4, 5))] fn complete(fixture: u32) { assert_eq!(fixture, 542); } #[rstest] fn complete_attr(#[with(2, 4, 5)] fixture: u32) { assert_eq!(fixture, 542); } rstest-0.26.1/tests/resources/rstest/single/resolve.rs000064400000000000000000000005661046102023000212530ustar 00000000000000use rstest::*; pub trait Tr { fn get() -> Self; } impl Tr for i32 { fn get() -> Self { 42 } } impl Tr for u32 { fn get() -> Self { 42 } } #[fixture] pub fn fgen() -> T { T::get() } #[rstest] fn generics_u32(fgen: u32) { assert_eq!(fgen, 42u32); } #[rstest] fn generics_i32(fgen: i32) { assert_eq!(fgen, 42i32); } rstest-0.26.1/tests/resources/rstest/single/simple.rs000064400000000000000000000003171046102023000210570ustar 00000000000000use rstest::*; #[fixture] pub fn fixture() -> u32 { 42 } #[rstest] fn should_success(fixture: u32) { assert_eq!(fixture, 42); } #[rstest] fn should_fail(fixture: u32) { assert_ne!(fixture, 42); } rstest-0.26.1/tests/resources/rstest/smol.rs000064400000000000000000000004351046102023000172600ustar 00000000000000use rstest::*; #[fixture] async fn a() -> u32 { 1 } #[rstest] #[test_attr(macro_rules_attribute::apply(smol_macros::test!))] #[awt] #[case(3)] #[case(2341)] async fn async_test(#[future] a: u32, #[case] b: u32, #[values(2, 4, 16)] c: u32) { assert_eq!((a * b * c) % 2, 0); } rstest-0.26.1/tests/resources/rstest/timeout.rs000064400000000000000000000127221046102023000177760ustar 00000000000000use rstest::*; use std::time::Duration; fn ms(ms: u32) -> Duration { Duration::from_millis(ms.into()) } mod thread { use super::*; fn delayed_sum(a: u32, b: u32, delay: Duration) -> u32 { std::thread::sleep(delay); a + b } #[rstest] #[timeout(ms(80))] fn single_pass() { assert_eq!(4, delayed_sum(2, 2, ms(10))); } #[rstest] #[timeout(ms(100))] fn single_fail_value() { assert_eq!(5, delayed_sum(2, 2, ms(1))); } #[rstest] #[timeout(ms(1000))] #[should_panic = "user message"] fn fail_with_user_message() { panic!("user message"); } #[rstest] #[timeout(ms(10))] fn single_fail_timeout() { assert_eq!(4, delayed_sum(2, 2, ms(80))); } #[rstest] #[timeout(ms(80))] #[case(ms(10))] fn one_pass(#[case] delay: Duration) { assert_eq!(4, delayed_sum(2, 2, delay)); } #[rstest] #[timeout(ms(10))] #[case(ms(80))] fn one_fail_timeout(#[case] delay: Duration) { assert_eq!(4, delayed_sum(2, 2, delay)); } #[rstest] #[timeout(ms(100))] #[case(ms(1))] fn one_fail_value(#[case] delay: Duration) { assert_eq!(5, delayed_sum(2, 2, delay)); } #[rstest] #[case::pass(ms(1), 4)] #[case::fail_timeout(ms(80), 4)] #[case::fail_value(ms(1), 5)] #[timeout(ms(40))] fn group_same_timeout(#[case] delay: Duration, #[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay)); } #[rstest] #[timeout(ms(100))] #[case::pass(ms(1), 4)] #[timeout(ms(30))] #[case::fail_timeout(ms(70), 4)] #[timeout(ms(100))] #[case::fail_value(ms(1), 5)] fn group_single_timeout(#[case] delay: Duration, #[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay)); } #[rstest] #[case::pass(ms(1), 4)] #[timeout(ms(10))] #[case::fail_timeout(ms(60), 4)] #[case::fail_value(ms(1), 5)] #[timeout(ms(100))] fn group_one_timeout_override(#[case] delay: Duration, #[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay)); } struct S {} #[rstest] #[case(S{})] fn compile_with_no_copy_arg(#[case] _s: S) { assert!(true); } #[fixture] fn no_copy() -> S { S {} } #[rstest] fn compile_with_no_copy_fixture(no_copy: S) { assert!(true); } #[rstest] fn default_timeout_failure() { assert_eq!(4, delayed_sum(2, 2, ms(1100))); } } mod async_std_cases { use super::*; async fn delayed_sum(a: u32, b: u32, delay: Duration) -> u32 { async_std::task::sleep(delay).await; a + b } #[rstest] #[async_std::test] #[timeout(ms(80))] async fn single_pass() { assert_eq!(4, delayed_sum(2, 2, ms(10)).await); } #[rstest] #[async_std::test] #[timeout(ms(10))] async fn single_fail_timeout() { assert_eq!(4, delayed_sum(2, 2, ms(80)).await); } #[rstest] #[async_std::test] #[timeout(ms(100))] async fn single_fail_value() { assert_eq!(5, delayed_sum(2, 2, ms(1)).await); } #[rstest] #[async_std::test] #[timeout(ms(1000))] #[should_panic = "user message"] async fn fail_with_user_message() { panic! {"user message"}; } #[rstest] #[timeout(ms(80))] #[case(ms(10))] #[async_std::test] async fn one_pass(#[case] delay: Duration) { assert_eq!(4, delayed_sum(2, 2, delay).await); } #[rstest] #[timeout(ms(10))] #[case(ms(80))] #[async_std::test] async fn one_fail_timeout(#[case] delay: Duration) { assert_eq!(4, delayed_sum(2, 2, delay).await); } #[rstest] #[timeout(ms(100))] #[case(ms(1))] #[async_std::test] async fn one_fail_value(#[case] delay: Duration) { assert_eq!(5, delayed_sum(2, 2, delay).await); } #[rstest] #[case::pass(ms(1), 4)] #[case::fail_timeout(ms(80), 4)] #[case::fail_value(ms(1), 5)] #[timeout(ms(40))] #[async_std::test] async fn group_same_timeout(#[case] delay: Duration, #[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay).await); } #[rstest] #[timeout(ms(100))] #[case::pass(ms(1), 4)] #[timeout(ms(30))] #[case::fail_timeout(ms(70), 4)] #[timeout(ms(100))] #[case::fail_value(ms(1), 5)] #[async_std::test] async fn group_single_timeout(#[case] delay: Duration, #[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay).await); } #[rstest] #[case::pass(ms(1), 4)] #[timeout(ms(10))] #[case::fail_timeout(ms(60), 4)] #[case::fail_value(ms(1), 5)] #[timeout(ms(100))] #[async_std::test] async fn group_one_timeout_override(#[case] delay: Duration, #[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay).await); } struct S {} #[rstest] #[case(S{})] #[async_std::test] async fn compile_with_no_copy_arg(#[case] _s: S) { assert!(true); } #[fixture] fn no_copy() -> S { S {} } #[rstest] fn compile_with_no_copy_fixture(_no_copy: S) { assert!(true); } #[fixture] async fn a_fix() -> S { S {} } #[rstest] fn compile_with_async_fixture(#[future] a_fix: S) { assert!(true); } #[rstest] #[async_std::test] async fn compile_with_async_awt_fixture(#[future(awt)] a_fix: S) { assert!(true); } } rstest-0.26.1/tests/resources/rstest/timeout_async.rs000064400000000000000000000005421046102023000211700ustar 00000000000000use rstest::*; use std::time::Duration; fn ms(ms: u32) -> Duration { Duration::from_millis(ms.into()) } async fn delayed_sum(a: u32, b: u32, delay: Duration) -> u32 { async_std::task::sleep(delay).await; a + b } #[rstest] #[async_std::test] #[timeout(ms(80))] async fn single_pass() { assert_eq!(4, delayed_sum(2, 2, ms(10)).await); } rstest-0.26.1/tests/resources/rstest/timeout_other_name.rs000064400000000000000000000047731046102023000222060ustar 00000000000000use other_name::*; use std::time::Duration; fn ms(ms: u32) -> Duration { Duration::from_millis(ms.into()) } mod thread { use super::*; fn delayed_sum(a: u32, b: u32, delay: Duration) -> u32 { std::thread::sleep(delay); a + b } #[rstest] #[timeout(ms(80))] fn single_pass() { assert_eq!(4, delayed_sum(2, 2, ms(10))); } #[rstest] #[timeout(ms(100))] fn single_fail_value() { assert_eq!(5, delayed_sum(2, 2, ms(1))); } #[rstest] #[timeout(ms(1000))] #[should_panic = "user message"] fn fail_with_user_message() { panic!("user message"); } #[rstest] #[timeout(ms(10))] fn single_fail_timeout() { assert_eq!(4, delayed_sum(2, 2, ms(80))); } #[rstest] #[timeout(ms(80))] #[case(ms(10))] fn one_pass(#[case] delay: Duration) { assert_eq!(4, delayed_sum(2, 2, delay)); } #[rstest] #[timeout(ms(10))] #[case(ms(80))] fn one_fail_timeout(#[case] delay: Duration) { assert_eq!(4, delayed_sum(2, 2, delay)); } #[rstest] #[timeout(ms(100))] #[case(ms(1))] fn one_fail_value(#[case] delay: Duration) { assert_eq!(5, delayed_sum(2, 2, delay)); } #[rstest] #[case::pass(ms(1), 4)] #[case::fail_timeout(ms(80), 4)] #[case::fail_value(ms(1), 5)] #[timeout(ms(40))] fn group_same_timeout(#[case] delay: Duration, #[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay)); } #[rstest] #[timeout(ms(100))] #[case::pass(ms(1), 4)] #[timeout(ms(30))] #[case::fail_timeout(ms(70), 4)] #[timeout(ms(100))] #[case::fail_value(ms(1), 5)] fn group_single_timeout(#[case] delay: Duration, #[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay)); } #[rstest] #[case::pass(ms(1), 4)] #[timeout(ms(10))] #[case::fail_timeout(ms(60), 4)] #[case::fail_value(ms(1), 5)] #[timeout(ms(100))] fn group_one_timeout_override(#[case] delay: Duration, #[case] expected: u32) { assert_eq!(expected, delayed_sum(2, 2, delay)); } struct S {} #[rstest] #[case(S{})] fn compile_with_no_copy_arg(#[case] _s: S) { assert!(true); } #[fixture] fn no_copy() -> S { S {} } #[rstest] fn compile_with_no_copy_fixture(no_copy: S) { assert!(true); } #[rstest] fn default_timeout_failure() { assert_eq!(4, delayed_sum(2, 2, ms(1100))); } } rstest-0.26.1/tests/resources/rstest/use_mutable_fixture_in_parametric_arguments.rs000064400000000000000000000007221046102023000273420ustar 00000000000000use rstest::*; #[fixture] fn f() -> String { "f".to_owned() } fn append(s: &mut String, a: &str) -> String { s.push_str("-"); s.push_str(a); s.clone() } #[rstest] #[case(append(&mut f, "a"), "f-a", "f-a-b")] fn use_mutate_fixture( mut f: String, #[case] a: String, #[values(append(&mut f, "b"))] b: String, #[case] expected_a: &str, #[case] expected_b: &str, ) { assert_eq!(expected_a, a); assert_eq!(expected_b, b); } rstest-0.26.1/tests/resources/rstest/values_tests_name.rs000064400000000000000000000005121046102023000220230ustar 00000000000000use rstest::*; enum Application { Python, Node, Go, } enum Method { GET, POST, PUT, HEAD, } #[rstest] fn name_values( #[values(Application::Python, Application::Node, Application::Go)] _val: Application, #[values(Method::GET, Method::POST, Method::PUT, Method::HEAD)] _method: Method, ) { } rstest-0.26.1/tests/rstest/mod.rs000064400000000000000000001601461046102023000150610ustar 00000000000000use mytest::*; use rstest_test::*; use std::{fs::File, io::Write, path::Path}; use unindent::Unindent; const SRC_LIB_RS: &str = { const SEP: u8 = std::path::MAIN_SEPARATOR as u8; const SRC_LIB_RS: [u8; 11] = [ SEP, b's', b'r', b'c', SEP, b'l', b'i', b'b', b'.', b'r', b's', ]; unsafe { std::str::from_utf8_unchecked(&SRC_LIB_RS) } }; pub fn resources(res: impl AsRef) -> std::path::PathBuf { let path = Path::new("rstest").join(res.as_ref()); super::resources(path) } fn prj(res: impl AsRef) -> Project { crate::prj().set_code_file(resources(res)) } fn run_test(res: impl AsRef) -> (std::process::Output, String) { let prj = prj(res); ( prj.run_tests().unwrap(), prj.get_name().to_owned().to_string(), ) } fn prepare_folders_tests(project_path: std::path::PathBuf) { let folders_path = project_path.join("folders"); let folder_with_txt_extension_path = folders_path.join("folder_but.txt"); let sub_folder_path = folders_path.join("sub"); std::fs::create_dir(&folders_path).unwrap(); std::fs::create_dir(&folder_with_txt_extension_path).unwrap(); std::fs::create_dir(&sub_folder_path).unwrap(); let text_file_path = sub_folder_path.join("file.txt"); File::create(text_file_path).unwrap(); } #[test] fn files() { std::env::set_var("FILES_ENV_VAR", "files"); let prj = prj("files.rs"); let files_path = prj.path().join("files"); let sub_folder = files_path.join("sub"); let up_sub_folder = prj.path().join("../files_test_sub_folder"); std::fs::create_dir(&files_path).unwrap(); std::fs::create_dir(&sub_folder).unwrap(); std::fs::create_dir(&up_sub_folder).unwrap(); prepare_folders_tests(prj.path()); for n in 0..4 { let name = format!("element_{}.txt", n); let path = files_path.join(&name); let mut out = File::create(path).unwrap(); out.write_all(name.as_bytes()).unwrap(); out.write_all(b"--\n").unwrap(); out.write_all(b"something else\n").unwrap(); } let dot = files_path.join(".ignore_me.txt"); File::create(dot) .unwrap() .write_all(b".ignore_me.txt--\n") .unwrap(); let exclude = files_path.join("exclude.txt"); File::create(exclude) .unwrap() .write_all(b"excluded\n") .unwrap(); let sub = sub_folder.join("sub_dir_file.txt"); File::create(sub) .unwrap() .write_all(b"sub_dir_file.txt--\nmore") .unwrap(); let down_from_parent_folder = up_sub_folder.join("from_parent_folder.txt"); File::create(down_from_parent_folder) .unwrap() .write_all(b"from_parent_folder.txt--\nmore") .unwrap(); let output = prj.run_tests().unwrap(); TestResults::new() .ok("env_vars::path_1_files_element_0_txt") .ok("env_vars::path_2_files_element_1_txt") .ok("env_vars::path_3_files_element_2_txt") .ok("env_vars::path_4_files_element_3_txt") .ok("env_vars::path_5_files_sub_sub_dir_file_txt") .ok("env_vars_base_dir::path_1_element_0_txt") .ok("env_vars_base_dir::path_2_element_1_txt") .ok("env_vars_base_dir::path_3_element_2_txt") .ok("env_vars_base_dir::path_4_element_3_txt") .ok("env_vars_base_dir::path_5_sub_sub_dir_file_txt") .ok("env_vars_unknown::path_1_files_element_0_txt") .ok("env_vars_unknown::path_2_files_element_1_txt") .ok("env_vars_unknown::path_3_files_element_2_txt") .ok("env_vars_unknown::path_4_files_element_3_txt") .ok("env_vars_unknown::path_5_files_sub_sub_dir_file_txt") .ok("ignore_missing_env_vars::path_1_files_element_0_txt") .ok("ignore_missing_env_vars::path_2_files_element_1_txt") .ok("ignore_missing_env_vars::path_3_files_element_2_txt") .ok("ignore_missing_env_vars::path_4_files_element_3_txt") .ok("ignore_missing_env_vars::path_5_files_sub_sub_dir_file_txt") .ok("include_bytes::contents_1__UP_files_test_sub_folder_from_parent_folder_txt") .ok("include_bytes::contents_2_files_element_0_txt") .ok("include_bytes::contents_3_files_element_1_txt") .ok("include_bytes::contents_4_files_element_2_txt") .ok("include_bytes::contents_5_files_element_3_txt") .ok("include_bytes::contents_6_files_sub_sub_dir_file_txt") .ok("include_str::contents_1__UP_files_test_sub_folder_from_parent_folder_txt") .ok("include_str::contents_2_files_element_0_txt") .ok("include_str::contents_3_files_element_1_txt") .ok("include_str::contents_4_files_element_2_txt") .ok("include_str::contents_5_files_element_3_txt") .ok("include_str::contents_6_files_sub_sub_dir_file_txt") .ok("module::pathbuf_need_not_be_in_scope::path_1_files__ignore_me_txt") .ok("module::pathbuf_need_not_be_in_scope::path_2_files_element_0_txt") .ok("module::pathbuf_need_not_be_in_scope::path_3_files_element_1_txt") .ok("module::pathbuf_need_not_be_in_scope::path_4_files_element_2_txt") .ok("module::pathbuf_need_not_be_in_scope::path_5_files_element_3_txt") .ok("module::pathbuf_need_not_be_in_scope::path_6_files_sub_sub_dir_file_txt") .ok("start_with_name::path_1__UP_files_test_sub_folder_from_parent_folder_txt") .ok("start_with_name::path_2_files_element_0_txt") .ok("start_with_name::path_3_files_element_1_txt") .ok("start_with_name::path_4_files_element_2_txt") .ok("start_with_name::path_5_files_element_3_txt") .ok("start_with_name::path_6_files_sub_sub_dir_file_txt") .ok("start_with_name_file_mode::path_1__UP_files_test_sub_folder_from_parent_folder_txt") .ok("start_with_name_file_mode::path_2_files_element_0_txt") .ok("start_with_name_file_mode::path_3_files_element_1_txt") .ok("start_with_name_file_mode::path_4_files_element_2_txt") .ok("start_with_name_file_mode::path_5_files_element_3_txt") .ok("start_with_name_file_mode::path_6_files_sub_sub_dir_file_txt") .ok("start_with_name_with_include::path_1_files__ignore_me_txt") .ok("start_with_name_with_include::path_2_files_element_0_txt") .ok("start_with_name_with_include::path_3_files_element_1_txt") .ok("start_with_name_with_include::path_4_files_element_2_txt") .ok("start_with_name_with_include::path_5_files_element_3_txt") .ok("start_with_name_with_include::path_6_files_sub_sub_dir_file_txt") .ok("ignore_directories::path_1_folders_sub_file_txt") .ok("ignore_directories_wildcard::path_1_folders_sub_file_txt") .ok("include_directories::path_1_folders_folder_but_txt") .ok("include_directories::path_2_folders_sub_file_txt") .ok("include_directories_wildcard::path_1_folders_folder_but_txt") .ok("include_directories_wildcard::path_2_folders_sub") .ok("include_directories_wildcard::path_3_folders_sub_file_txt") .assert(output); } #[test] fn mutable_input() { let (output, _) = run_test("mut.rs"); TestResults::new() .ok("should_success") .fail("should_fail") .ok("add_test::case_1") .ok("add_test::case_2") .fail("add_test::case_3") .assert(output); } #[test] fn test_with_return_type() { let (output, _) = run_test("return_result.rs"); TestResults::new() .ok("should_success") .fail("should_fail") .ok("return_type::case_1_should_success") .fail("return_type::case_2_should_fail") .assert(output); } #[test] fn should_panic() { let (output, _) = run_test("panic.rs"); TestResults::new() .ok("should_success") .fail("should_fail") .ok("fail::case_1") .ok("fail::case_2") .fail("fail::case_3") .assert(output); } #[test] fn should_not_show_a_warning_for_should_panic_attribute() { let (output, _) = run_test("panic.rs"); assert!(!output.stderr.str().contains("unused attribute")); } #[test] fn should_not_show_a_warning_for_values_test_names() { let (output, _) = run_test("values_tests_name.rs"); assert_not_in!(output.stderr.str(), "warning:"); } #[test] fn should_map_fixture_by_remove_first_underscore_if_any() { let (output, _) = run_test("remove_underscore.rs"); TestResults::new().ok("ignore_input").assert(output); } #[test] fn generic_input() { let (output, _) = run_test("generic.rs"); TestResults::new() .ok("simple") .ok("strlen_test::case_1") .ok("strlen_test::case_2") .assert(output); } #[test] fn impl_input() { let (output, _) = run_test("impl_param.rs"); TestResults::new() .ok("simple") .ok("strlen_test::case_1") .ok("strlen_test::case_2") .assert(output); } #[test] fn use_mutable_fixture_in_parametric_arguments() { let (output, _) = run_test("use_mutable_fixture_in_parametric_arguments.rs"); TestResults::new() .with_contains(true) .ok("use_mutate_fixture::case_1::b_1") .assert(output); } #[test] fn should_not_remove_lifetimes() { let (output, _) = run_test("lifetimes.rs"); TestResults::new() .with_contains(true) .ok("case") .ok("values") .ok("fixture") .assert(output); } #[test] fn should_reject_no_item_function() { let (output, name) = run_test("reject_no_item_function.rs"); assert_in!( output.stderr.str(), format!( " error: expected `fn` --> {name}{SRC_LIB_RS}:4:1 | 4 | struct Foo; | ^^^^^^ " ) .unindent() ); assert_in!( output.stderr.str(), format!( " error: expected `fn` --> {name}{SRC_LIB_RS}:7:1 | 7 | impl Foo {{}} | ^^^^ " ) .unindent() ); assert_in!( output.stderr.str(), format!( " error: expected `fn` --> {name}{SRC_LIB_RS}:10:1 | 10 | mod mod_baz {{}} | ^^^ " ) .unindent() ); } mod dump_input_values { use super::*; #[rstest] #[case::compact_syntax("dump_debug_compact.rs")] #[case::attr_syntax("dump_debug.rs")] fn if_implements_debug(#[case] source: &str) { let (output, _) = run_test(source); let out = output.stdout.str().to_string(); TestResults::new() .fail("single_fail") .fail("no_trace_single_fail") .fail("cases_fail::case_1") .fail("cases_fail::case_2") .fail("no_trace_cases_fail::case_1") .fail("no_trace_cases_fail::case_2") .fail_with("matrix_fail::u_1", false, 8) .fail_with("matrix_fail::u_2", false, 8) .assert(output); assert_in!(out, "fu32 = 42"); assert_in!(out, r#"fstring = "A String""#); assert_in!(out, r#"ftuple = (A, "A String", -12"#); assert_in!(out, "u = 42"); assert_in!(out, r#"s = "str""#); assert_in!(out, r#"t = ("ss", -12)"#); assert_in!(out, "u = 24"); assert_in!(out, r#"s = "trs""#); assert_in!(out, r#"t = ("tt", -24)"#); assert_in!(out, "u = 1"); assert_in!(out, r#"s = "rst""#); assert_in!(out, r#"t = ("SS", -12)"#); assert_in!(out, "u = 2"); assert_in!(out, r#"s = "srt""#); assert_in!(out, r#"t = ("TT", -24)"#); let expected = 11; for marker in ["TEST START", "TEST ARGUMENTS"] { let n_found = out.lines().filter(|l| l.contains(marker)).count(); assert_eq!( n_found, expected, "Should contain {expected} '{marker}' but found {n_found}. [Should not enclose output if no trace]" ); } } #[rstest] #[case::compact_syntax("dump_not_debug_compact.rs")] #[case::attr_syntax("dump_not_debug.rs")] fn should_not_compile_if_not_implement_debug(#[case] source: &str) { let (output, name) = run_test(source); assert_all_in!( output.stderr.str(), format!("--> {name}{SRC_LIB_RS}:10:11"), "fn single(fixture: S) {}", "^^^^^^^ `S` cannot be formatted using `{:?}`" ); assert_in!( output.stderr.str(), format!("--> {name}{SRC_LIB_RS}:15:10"), "fn cases(s: S) {}", "^ `S` cannot be formatted using `{:?}`" ); assert_in!( output.stderr.str(), format!("--> {name}{SRC_LIB_RS}:20:11"), "fn matrix(s: S) {}", "^ `S` cannot be formatted using `{:?}`" ); } #[rstest] #[case::compact_syntax("dump_exclude_some_inputs_compact.rs")] #[case::attr_syntax("dump_exclude_some_inputs.rs")] fn can_exclude_some_inputs(#[case] source: &str) { let (output, _) = run_test(source); let out = output.stdout.str().to_string(); TestResults::new() .fail("simple") .fail("cases::case_1") .fail_in("matrix::a_1") .assert(output); assert_in!(out, "fu32 = 42"); assert_in!(out, "d = D"); assert_in!(out, "fd = D"); assert_in!(out, "dd = D"); } #[test] fn should_be_enclosed_in_an_explicit_session() { let (output, _) = run_test(Path::new("single").join("dump_debug.rs")); let out = output.stdout.str().to_string(); TestResults::new().fail("should_fail").assert(output); let lines = out .lines() .skip_while(|l| !l.contains("TEST ARGUMENTS")) .take_while(|l| !l.contains("TEST START")) .collect::>(); let expected = 4; assert_eq!( expected, lines.len(), "Not contains {expected} lines but {}: '{}'", lines.len(), lines.join("\n") ); } } mod single { use super::*; fn res(name: impl AsRef) -> impl AsRef { Path::new("single").join(name.as_ref()) } #[test] fn one_success_and_one_fail() { let (output, _) = run_test(res("simple.rs")); TestResults::new() .ok("should_success") .fail("should_fail") .assert(output); } #[test] fn should_resolve_generics_fixture_outputs() { let (output, _) = run_test(res("resolve.rs")); TestResults::new() .ok("generics_u32") .ok("generics_i32") .assert(output); } #[test] fn should_apply_partial_fixture() { let (output, _) = run_test(res("partial.rs")); TestResults::new() .ok("default") .ok("partial_1") .ok("partial_attr_1") .ok("partial_2") .ok("partial_attr_2") .ok("complete") .ok("complete_attr") .assert(output); } #[rstest] #[case("async.rs")] #[case("async_awt.rs")] #[case("async_awt_global.rs")] fn should_run_async_function(#[case] name: &str) { let prj = prj(res(name)); prj.add_dependency("async-std", r#"{version="*", features=["attributes"]}"#); let output = prj.run_tests().unwrap(); TestResults::new() .ok("should_pass") .fail("should_fail") .ok("should_panic_pass") .fail("should_panic_fail") .assert(output); } #[test] fn should_use_injected_test_attr() { let prj = prj(res("inject.rs")); prj.add_dependency("actix-rt", r#""1.1.0""#); let output = prj.run_tests().unwrap(); TestResults::new() .ok("sync_case") .ok("sync_case_panic") .fail("sync_case_fail") .fail("sync_case_panic_fail") .ok("async_case") .ok("async_case_test_attr") .ok("async_case_panic") .fail("async_case_fail") .fail("async_case_panic_fail") .assert(output); } } mod cases { use super::*; fn res(name: impl AsRef) -> impl AsRef { Path::new("cases").join(name.as_ref()) } #[test] fn should_compile() { let output = prj(res("simple.rs")).compile().unwrap(); assert_eq!( Some(0), output.status.code(), "Compile error due: {}", output.stderr.str() ) } #[test] fn happy_path() { let (output, _) = run_test(res("simple.rs")); TestResults::new() .ok("strlen_test::case_1") .ok("strlen_test::case_2") .assert(output); } #[test] fn use_attr() { let (output, _) = run_test(res("use_attr.rs")); TestResults::new() .ok("all::case_1_ciao") .ok("all::case_2_panic") .ok("all::case_3_foo") .ok("just_cases::case_1_ciao") .ok("just_cases::case_2_foo") .ok("just_cases::case_3_panic") .ok("just_args::case_1_ciao") .ok("just_args::case_2_foo") .ok("just_args::case_3_panic") .ok("all_panic::case_1") .ok("all_panic::case_2") .assert(output); } #[test] fn case_description() { let (output, _) = run_test(res("description.rs")); TestResults::new() .ok("description::case_1_user_test_description") .ok("description::case_2") .fail("description::case_3_user_test_description_fail") .assert(output); } #[test] fn should_apply_partial_fixture() { let (output, _) = run_test(res("partial.rs")); TestResults::new() .ok("default::case_1") .ok("partial_1::case_1") .ok("partial_2::case_1") .ok("complete::case_1") .ok("partial_attr_1::case_1") .ok("partial_attr_2::case_1") .ok("complete_attr::case_1") .fail("default::case_2") .fail("partial_1::case_2") .fail("partial_2::case_2") .fail("complete::case_2") .fail("partial_attr_1::case_2") .fail("partial_attr_2::case_2") .fail("complete_attr::case_2") .assert(output); } #[test] fn should_use_case_attributes() { let (output, _) = run_test(res("case_attributes.rs")); TestResults::new() .ok("attribute_per_case::case_1_no_panic") .ok("attribute_per_case::case_2_panic") .ok("attribute_per_case::case_3_panic_with_message") .fail("attribute_per_case::case_4_no_panic_but_fail") .fail("attribute_per_case::case_5_panic_but_fail") .fail("attribute_per_case::case_6_panic_with_wrong_message") .assert(output); } #[rstest] #[case("async.rs")] #[case("async_awt.rs")] #[case("async_awt_global.rs")] fn should_run_async_function(#[case] name: &str) { let prj = prj(res(name)); prj.add_dependency("async-std", r#"{version="*", features=["attributes"]}"#); let output = prj.run_tests().unwrap(); TestResults::new() .ok("my_async_test::case_1_pass") .fail("my_async_test::case_2_fail") .ok("my_async_test::case_3_pass_panic") .fail("my_async_test::case_4_fail_panic") .ok("my_async_test_revert::case_1_pass") .assert(output); } #[rstest] fn should_run_async_mut() { let prj = prj(res("async_awt_mut.rs")); prj.add_dependency("async-std", r#"{version="*", features=["attributes"]}"#); let output = prj.run_tests().unwrap(); TestResults::new() .ok("my_mut_test_global_awt::case_1_pass") .ok("my_mut_test_local_awt::case_1_pass") .assert(output); } #[test] fn should_use_injected_test_attr() { let prj = prj(res("inject.rs")); prj.add_dependency("actix-rt", r#""1.1.0""#); let output = prj.run_tests().unwrap(); TestResults::new() .ok("sync::case_1_pass") .ok("sync::case_2_panic") .fail("sync::case_3_fail") .ok("fn_async::case_1_pass") .ok("fn_async::case_2_panic") .fail("fn_async::case_3_fail") .ok("fn_async_test_attr::case_1_pass") .ok("fn_async_test_attr::case_2_panic") .fail("fn_async_test_attr::case_3_fail") .assert(output); } #[test] fn trace_just_one_test() { let (output, _) = run_test(res("dump_just_one_case.rs")); let out = output.stdout.str().to_string(); TestResults::new() .fail("cases::case_1_first_no_dump") .fail("cases::case_2_dump_me") .fail("cases::case_3_last_no_dump") .assert(output); assert_in!(out, r#"s = "Trace it!""#); assert_not_in!(out, r#"s = "Please don't trace me""#); } mod not_compile_if_missed_arguments { use super::*; #[test] fn happy_path() { let (output, _) = run_test(res("missed_argument.rs")); let stderr = output.stderr.str(); assert_ne!(Some(0), output.status.code()); assert_in!(stderr, "Missed argument"); assert_in!( stderr, " | 4 | #[rstest(f, case(42), case(24))] | ^ " .unindent() ); } #[test] fn should_reports_all() { let (output, _) = run_test(res("missed_some_arguments.rs")); let stderr = output.stderr.str(); assert_in!( stderr, " | 4 | #[rstest(a,b,c, case(1,2,3), case(3,2,1))] | ^ " .unindent() ); assert_in!( stderr, " | 4 | #[rstest(a,b,c, case(1,2,3), case(3,2,1))] | ^ " .unindent() ); assert_eq!( 2, stderr.count("Missed argument"), "Should contain message exactly 2 occurrences in error message:\n{}", stderr ) } #[test] fn should_report_just_one_error_message_for_all_test_cases() { let (output, _) = run_test(res("missed_argument.rs")); let stderr = output.stderr.str(); assert_eq!( 1, stderr.count("Missed argument"), "More than one message occurrence in error message:\n{}", stderr ) } #[test] fn should_not_report_error_in_macro_syntax() { let (output, _) = run_test(res("missed_argument.rs")); let stderr = output.stderr.str(); assert!(!stderr.contains("macros that expand to items")); } } mod not_compile_if_a_case_has_a_wrong_signature { use std::process::Output; use lazy_static::lazy_static; use super::*; //noinspection RsTypeCheck fn execute() -> &'static (Output, String) { lazy_static! { static ref OUTPUT: (Output, String) = run_test(res("case_with_wrong_args.rs")); } assert_ne!(Some(0), OUTPUT.0.status.code(), "Should not compile"); &OUTPUT } #[test] fn with_too_much_arguments() { let (output, _) = execute(); let stderr = output.stderr.str(); assert_in!( stderr, " | 8 | #[rstest(a, case(42, 43), case(12), case(24, 34))] | ^^^^^^ " .unindent() ); assert_in!( stderr, " | 8 | #[rstest(a, case(42, 43), case(12), case(24, 34))] | ^^^^^^ " .unindent() ); } #[test] fn with_less_arguments() { let (output, _) = execute(); let stderr = output.stderr.str(); assert_in!( stderr, " | 4 | #[rstest(a, b, case(42), case(1, 2), case(43))] | ^^ " .unindent() ); assert_in!( stderr, " | 4 | #[rstest(a, b, case(42), case(1, 2), case(43))] | ^^ " .unindent() ); } #[test] fn and_reports_all_errors() { let (output, _) = execute(); let stderr = output.stderr.str(); // Exactly 4 cases are wrong assert_eq!( 4, stderr.count("Wrong case signature: should match the given parameters list."), "Should contain message exactly 4 occurrences in error message:\n{}", stderr ); } } mod not_compile_if_args_but_no_cases { use std::process::Output; use lazy_static::lazy_static; use super::*; //noinspection RsTypeCheck fn execute() -> &'static (Output, String) { lazy_static! { static ref OUTPUT: (Output, String) = run_test(res("args_with_no_cases.rs")); } assert_ne!(Some(0), OUTPUT.0.status.code(), "Should not compile"); &OUTPUT } #[test] fn report_error() { let (output, name) = execute(); let stderr = output.stderr.str(); assert_in!( stderr, format!( " error: No cases for this argument. --> {name}{SRC_LIB_RS}:3:10 | 3 | #[rstest(one, two, three)] | ^^^ " ) .unindent() ); } #[test] fn and_reports_all_errors() { let (output, _) = execute(); let stderr = output.stderr.str(); // Exactly 3 cases are wrong assert_eq!( 3, stderr.count("No cases for this argument."), "Should contain message exactly 3 occurrences in error message:\n{}", stderr ); } } } mod matrix { use super::*; fn res(name: impl AsRef) -> impl AsRef { Path::new("matrix").join(name.as_ref()) } #[test] fn should_compile() { let output = prj(res("simple.rs")).compile().unwrap(); assert_eq!( Some(0), output.status.code(), "Compile error due: {}", output.stderr.str() ) } #[test] fn happy_path() { let (output, _) = run_test(res("simple.rs")); TestResults::new() .with_contains(true) .ok("strlen_test::expected_1_4::input_1___ciao__") .ok("strlen_test::expected_1_4::input_2___buzz__") .ok("strlen_test::expected_2_2_3_2::input_1___ciao__") .ok("strlen_test::expected_2_2_3_2::input_2___buzz__") .assert(output); } #[test] fn should_apply_partial_fixture() { let (output, _) = run_test(res("partial.rs")); TestResults::new() .with_contains(true) .ok_times("default::a_1", 2) .ok("default::a_2") .ok("partial_2::a_2") .ok("partial_attr_2::a_2") .ok("complete::a_2") .ok("complete_attr::a_2") .fail("default::a_2") .fail_times("partial_1::a_1", 2) .fail_times("partial_1::a_2", 2) .fail_times("partial_2::a_1", 2) .fail("partial_2::a_2") .fail_times("complete::a_1", 2) .fail("complete::a_2") .fail_times("partial_attr_1::a_1", 2) .fail_times("partial_attr_1::a_2", 2) .fail_times("partial_attr_2::a_1", 2) .fail("partial_attr_2::a_2") .fail_times("complete_attr::a_1", 2) .fail("complete_attr::a_2") .assert(output); } #[rstest] #[case("async.rs")] #[case("async_awt.rs")] #[case("async_awt_global.rs")] fn should_run_async_function(#[case] name: &str) { let prj = prj(res(name)); prj.add_dependency("async-std", r#"{version="*", features=["attributes"]}"#); let output = prj.run_tests().unwrap(); TestResults::new() .with_contains(true) .ok("my_async_test::first_1") .fail("my_async_test::first_1") .fail("my_async_test::first_2") .ok("my_async_test::first_2") .assert(output); } #[test] fn should_use_injected_test_attr() { let prj = prj(res("inject.rs")); prj.add_dependency("actix-rt", r#""1.1.0""#); let output = prj.run_tests().unwrap(); TestResults::new() .with_contains(true) .ok("sync::first_1") .fail("sync::first_1") .fail("sync::first_2") .ok("sync::first_2") .ok("fn_async::first_1") .fail("fn_async::first_1") .fail("fn_async::first_2") .ok("fn_async::first_2") .ok("fn_async_test_attr::first_1") .fail("fn_async_test_attr::first_1") .fail("fn_async_test_attr::first_2") .ok("fn_async::first_2") .assert(output); } #[test] fn use_args_attributes() { let (output, _) = run_test(res("use_attr.rs")); TestResults::new() .ok("both::expected_1_4::input_1___ciao__") .ok("both::expected_1_4::input_2___buzz__") .ok("both::expected_2_2_3_2::input_1___ciao__") .ok("both::expected_2_2_3_2::input_2___buzz__") .ok("first::input_1___ciao__::expected_1_4") .ok("first::input_2___buzz__::expected_1_4") .ok("first::input_1___ciao__::expected_2_2_3_2") .ok("first::input_2___buzz__::expected_2_2_3_2") .ok("second::expected_1_4::input_1___ciao__") .ok("second::expected_1_4::input_2___buzz__") .ok("second::expected_2_2_3_2::input_1___ciao__") .ok("second::expected_2_2_3_2::input_2___buzz__") .assert(output); } } #[test] fn convert_string_literal() { let (output, _) = run_test("convert_string_literal.rs"); assert_regex!( "Cannot parse 'error' to get [a-z:_0-9]*MyType", output.stdout.str() ); TestResults::new() .ok("cases::case_1") .ok("cases::case_2") .ok("cases::case_3") .ok("cases::case_4") .fail("cases::case_5") .fail("cases::case_6") .ok_in("values::addr_1") .ok_in("values::addr_2") .fail_in("values::addr_3") .fail_in("values::addr_4") .ok_in("not_convert_byte_array::case_1::values_1") .ok("not_convert_impl::case_1") .ok("not_convert_generics::case_1") .ok("not_convert_generics::case_2") .ok("convert_without_debug::case_1") .fail("convert_without_debug::case_2") .assert(output); } #[test] fn happy_path() { let (output, _) = run_test("happy_path.rs"); TestResults::new() .ok("happy::case_1::expected_1_4::input_1___ciao__") .ok("happy::case_1::expected_1_4::input_2___buzz__") .ok("happy::case_1::expected_2_2_3_2::input_1___ciao__") .ok("happy::case_1::expected_2_2_3_2::input_2___buzz__") .ok("happy::case_2_second::expected_1_4::input_1___ciao__") .ok("happy::case_2_second::expected_1_4::input_2___buzz__") .ok("happy::case_2_second::expected_2_2_3_2::input_1___ciao__") .ok("happy::case_2_second::expected_2_2_3_2::input_2___buzz__") .assert(output); } #[test] fn destruct() { let (output, _) = run_test("destruct.rs"); TestResults::new() .ok("cases_destruct::case_1_two_times_twenty_one::__destruct_3_1_T__new_42_1_") .ok("cases_destruct::case_1_two_times_twenty_one::__destruct_3_2_T_a_3_b_14_") .ok("cases_destruct::case_2_six_times_seven::__destruct_3_1_T__new_42_1_") .ok("cases_destruct::case_2_six_times_seven::__destruct_3_2_T_a_3_b_14_") .ok("cases_destruct_named_tuple::case_1_two_times_twenty_one::__destruct_3_1_S_42_1_") .ok("cases_destruct_named_tuple::case_1_two_times_twenty_one::__destruct_3_2_S_3_14_") .ok("cases_destruct_named_tuple::case_2_six_times_seven::__destruct_3_1_S_42_1_") .ok("cases_destruct_named_tuple::case_2_six_times_seven::__destruct_3_2_S_3_14_") .ok("cases_destruct_tuple::case_1_two_times_twenty_one::__destruct_3_1__42_1_") .ok("cases_destruct_tuple::case_1_two_times_twenty_one::__destruct_3_2__3_14_") .ok("cases_destruct_tuple::case_2_six_times_seven::__destruct_3_1__42_1_") .ok("cases_destruct_tuple::case_2_six_times_seven::__destruct_3_2__3_14_") .ok("swapped") .assert(output); } #[test] fn rename() { let (output, _) = run_test("rename.rs"); TestResults::new() .ok("compact") .ok("compact_mod") .ok("compact_injected") .ok("attribute") .ok("attribute_mod") .ok("attribute_injected") .assert(output); } #[test] fn ignore_underscore_args() { let (output, _) = run_test("ignore_args.rs"); TestResults::new() .with_contains(true) .ok("test::case_1::_ignore3_1") .ok("test::case_1::_ignore3_2") .ok("test::case_1::_ignore3_3") .ok("test::case_1::_ignore3_4") .ok("test::case_2::_ignore3_1") .ok("test::case_2::_ignore3_2") .ok("test::case_2::_ignore3_3") .ok("test::case_2::_ignore3_4") .assert(output); } #[test] fn ignore_attributes_args_if_any() { let prj = prj("ignore_attributes_args_if_any.rs"); prj.add_dependency( "sqlx", r#"{version="*", features=["sqlite","macros","runtime-tokio"]}"#, ); let output = prj.run_tests().unwrap(); TestResults::new() .with_contains(true) .ok("test_sum::case_1::c_1_1") .ok("test_sum::case_1::c_2_2") .ok("test_sum::case_2::c_1_1") .ok("test_sum::case_2::c_2_2") .assert(output); } #[test] fn timeout() { let mut prj = prj("timeout.rs"); prj.add_dependency("async-std", r#"{version="*", features=["attributes"]}"#); prj.set_default_timeout(1); let output = prj.run_tests().unwrap(); TestResults::new() .ok("thread::single_pass") .fail("thread::single_fail_value") .ok("thread::fail_with_user_message") .fail("thread::single_fail_timeout") .ok("thread::one_pass::case_1") .fail("thread::one_fail_value::case_1") .fail("thread::one_fail_timeout::case_1") .ok("thread::group_same_timeout::case_1_pass") .fail("thread::group_same_timeout::case_2_fail_timeout") .fail("thread::group_same_timeout::case_3_fail_value") .ok("thread::group_single_timeout::case_1_pass") .fail("thread::group_single_timeout::case_2_fail_timeout") .fail("thread::group_single_timeout::case_3_fail_value") .ok("thread::group_one_timeout_override::case_1_pass") .fail("thread::group_one_timeout_override::case_2_fail_timeout") .fail("thread::group_one_timeout_override::case_3_fail_value") .ok("thread::compile_with_no_copy_arg::case_1") .ok("thread::compile_with_no_copy_fixture") .fail("thread::default_timeout_failure") .ok("async_std_cases::single_pass") .fail("async_std_cases::single_fail_value") .ok("async_std_cases::fail_with_user_message") .fail("async_std_cases::single_fail_timeout") .ok("async_std_cases::one_pass::case_1") .fail("async_std_cases::one_fail_value::case_1") .fail("async_std_cases::one_fail_timeout::case_1") .ok("async_std_cases::group_same_timeout::case_1_pass") .fail("async_std_cases::group_same_timeout::case_2_fail_timeout") .fail("async_std_cases::group_same_timeout::case_3_fail_value") .ok("async_std_cases::group_single_timeout::case_1_pass") .fail("async_std_cases::group_single_timeout::case_2_fail_timeout") .fail("async_std_cases::group_single_timeout::case_3_fail_value") .ok("async_std_cases::group_one_timeout_override::case_1_pass") .fail("async_std_cases::group_one_timeout_override::case_2_fail_timeout") .fail("async_std_cases::group_one_timeout_override::case_3_fail_value") .ok("async_std_cases::compile_with_no_copy_arg::case_1") .ok("async_std_cases::compile_with_no_copy_fixture") .ok("async_std_cases::compile_with_async_fixture") .ok("async_std_cases::compile_with_async_awt_fixture") .assert(output); } mod import_crate_with_other_name { use super::*; fn prj(res: &str, features: Option<&[&str]>) -> Project { let prj = crate::base_prj(); let default_features = features.is_none(); let features = features .map(|features| { features .iter() .map(|f| format!(r#""{}""#, f)) .collect::>() .join(",") }) .unwrap_or_else(|| "".to_string()); prj.add_dependency( "other_name", &format!( r#"{{path={}, package = "rstest", default-features = {}, features = [{}]}}"#, rstest_test::to_toml_string(prj.exec_dir_str()), default_features, features ), ); prj.set_code_file(resources(res)) } #[test] fn should_fails_to_compile_if_crate_name_feature_is_not_enabled() { let prj = prj("timeout_other_name.rs", Some(&[])); assert!(!prj.compile().unwrap().status.success()); } #[test] fn should_always_compile_project_that_use_default_name() { let prj = crate::base_prj(); prj.add_dependency( "rstest", &format!( r#"{{path={}, default-features = false}}"#, rstest_test::to_toml_string(prj.exec_dir_str()), ), ); let prj = prj.set_code_file(resources("convert_string_literal.rs")); assert!(prj.compile().unwrap().status.success()); } #[rstest] #[case::default_features(None)] #[case::with_crate_name_feature(Some(["crate-name"].as_slice()))] fn timeout_should_compile_and_run(#[case] features: Option<&[&str]>) { let prj = prj("timeout_other_name.rs", features); assert!(prj.compile().unwrap().status.success()); } #[rstest] #[case::default(None)] #[case::with_crate_name_feature(Some(["crate-name"].as_slice()))] fn convert_string_literal_should_compile_and_run(#[case] features: Option<&[&str]>) { let prj = prj("convert_string_literal_other_name.rs", features); assert!(prj.compile().unwrap().status.success()); } } #[test] fn local_lifetime() { let (output, _) = run_test("local_lifetime.rs"); TestResults::new() .ok("tests::it_works::case_1") .assert(output); } #[test] fn by_ref() { let prj = prj("by_ref.rs"); let files_path: std::path::PathBuf = prj.path().join("files"); std::fs::create_dir(&files_path).unwrap(); let name = "my_name.txt"; let mut out = File::create(files_path.join(name)).unwrap(); out.write_all(name.as_bytes()).unwrap(); let output = prj.run_tests().unwrap(); TestResults::new() .ok("test::case_1::v_1_42") .ok("test::case_1::v_2_142") .ok("start_with_name::path_1_files_my_name_txt") .assert(output); } #[test] fn no_std() { let prj = prj("no_std.rs"); prj.add_dependency("async-std", r#"{version="*", features=["attributes"]}"#); let output = prj.run_tests().unwrap(); TestResults::new() .ok("it_works::case_1") .ok("async_works") .assert(output); } #[test] fn context() { let (output, _) = run_test("context.rs"); TestResults::new() .ok("with_case::case_1_description") .ok("without_case") .ok("first::inner::test") .ok("measure_time") .assert(output); } #[test] fn should_works_with_smol_async_runtime() { let prj = prj("smol.rs"); prj.add_dependency("smol", r#""2.0.2""#); prj.add_dependency("smol-macros", r#""0.1.1""#); prj.add_dependency("macro_rules_attribute", r#""0.2.2""#); let output = prj.run_tests().unwrap(); TestResults::new() .with_contains(true) .ok("async_test::case_1::c_1_2") .ok("async_test::case_1::c_2_4") .ok("async_test::case_1::c_3_16") .ok("async_test::case_2::c_1_2") .ok("async_test::case_2::c_2_4") .ok("async_test::case_2::c_3_16") .assert(output); } mod async_timeout_feature { use super::*; fn build_prj(features: &[&str]) -> Project { let prj = crate::base_prj(); let features = match features.is_empty() { true => String::new(), false => format!(r#", features=["{}"]"#, features.join(r#"",""#)), }; prj.add_dependency( "rstest", &format!( r#"{{path={}, default-features = false {}}}"#, rstest_test::to_toml_string(prj.exec_dir_str()), features ), ); prj.add_dependency("async-std", r#"{version="*", features=["attributes"]}"#); prj } #[test] fn should_not_compile_if_feature_disable() { let prj = build_prj(&[]); let output = prj .set_code_file(resources("timeout_async.rs")) .run_tests() .unwrap(); assert_in!(output.stderr.str(), "error: Enable async-timeout feature"); } #[test] fn should_work_if_feature_enabled() { let prj = build_prj(&["async-timeout"]); let output = prj .set_code_file(resources("timeout_async.rs")) .run_tests() .unwrap(); TestResults::new().ok("single_pass").assert(output); } } mod should_show_correct_errors { use std::process::Output; use lazy_static::lazy_static; use super::*; //noinspection RsTypeCheck fn execute() -> &'static (Output, String) { lazy_static! { static ref OUTPUT: (Output, String) = run_test("errors.rs"); } &OUTPUT } #[test] fn if_no_fixture() { let (output, name) = execute(); assert_in!(output.stderr.str(), "error[E0433]: "); assert_in!( output.stderr.str(), format!( " --> {name}{SRC_LIB_RS}:13:33 | 13 | fn error_cannot_resolve_fixture(no_fixture: u32, f: u32) {{}}" ) .unindent() ); } #[test] fn if_inject_wrong_fixture() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Missed argument: 'not_a_fixture' should be a test function argument. --> {name}{SRC_LIB_RS}:28:23 | 28 | #[rstest(f, case(42), not_a_fixture(24))] | ^^^^^^^^^^^^^ " ) .unindent() ); } #[test] fn if_wrong_type() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( r#" error[E0308]: mismatched types --> {name}{SRC_LIB_RS}:9:18 | 9 | let a: u32 = ""; "# ) .unindent() ); } #[test] fn if_wrong_type_fixture() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error[E0308]: mismatched types --> {name}{SRC_LIB_RS}:16:29 | 16 | fn error_fixture_wrong_type(fixture: String, f: u32) {{}} " ) .unindent() ); } #[test] fn if_wrong_type_case_param() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error[E0308]: mismatched types --> {name}{SRC_LIB_RS}:19:26 | 19 | fn error_case_wrong_type(f: &str) {{}}" ) .unindent() ); } #[test] fn if_wrong_type_matrix_param() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error[E0308]: mismatched types --> {name}{SRC_LIB_RS}:51:28 | 51 | fn error_matrix_wrong_type(f: &str) {{}}" ) .unindent() ); } #[test] fn if_arbitrary_rust_code_has_some_errors() { let (output, name) = execute(); let src_lib_rs = regex::escape(SRC_LIB_RS); assert_regex!( format!( r#"error\[E0308\]: mismatched types \s+--> {name}{src_lib_rs}:22:31"# ) .unindent(), output.stderr.str() ); assert_regex!( r#"22\s+|\s+case\(vec!\[1,2,3\]\.contains\(2\)\)\)"#, output.stderr.str() ); assert_regex!( format!( r#"error\[E0308\]: mismatched types \s+--> {name}{src_lib_rs}:53:45"# ) .unindent(), output.stderr.str() ); assert_regex!( r#"53\s+|\s+#\[rstest\(condition => \[vec!\[1,2,3\]\.contains\(2\)\] \)\]"#, output.stderr.str() ); } #[test] fn if_inject_a_fixture_that_is_already_a_case() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Duplicate argument: 'f' is already defined. --> {name}{SRC_LIB_RS}:41:13 | 41 | #[rstest(f, f(42), case(12))] | ^" ) .unindent() ); } #[test] fn if_define_a_case_arg_that_is_already_an_injected_fixture() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Duplicate argument: 'f' is already defined. --> {name}{SRC_LIB_RS}:44:17 | 44 | #[rstest(f(42), f, case(12))] | ^" ) .unindent() ); } #[test] fn if_inject_a_fixture_more_than_once() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Duplicate argument: 'f' is already defined. --> {name}{SRC_LIB_RS}:47:20 | 47 | #[rstest(v, f(42), f(42), case(12))] | ^" ) .unindent() ); } #[test] fn if_list_argument_dont_match_function_signature() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Missed argument: 'not_exist_1' should be a test function argument. --> {name}{SRC_LIB_RS}:61:10 | 61 | #[rstest(not_exist_1 => [42], | ^^^^^^^^^^^" ) .unindent() ); assert_in!( output.stderr.str(), format!( " error: Missed argument: 'not_exist_2' should be a test function argument. --> {name}{SRC_LIB_RS}:62:10 | 62 | not_exist_2 => [42])] | ^^^^^^^^^^^" ) .unindent() ); } #[test] fn if_inject_a_fixture_that_is_already_a_value_list() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Duplicate argument: 'f' is already defined. --> {name}{SRC_LIB_RS}:65:25 | 65 | #[rstest(f => [41, 42], f(42))] | ^" ) .unindent() ); } #[test] fn if_define_value_list_more_that_once() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Duplicate argument: 'a' is already defined. --> {name}{SRC_LIB_RS}:77:25 | 77 | #[rstest(a => [42, 24], a => [24, 42])] | ^" ) .unindent() ); } #[test] fn if_define_value_list_that_is_already_an_injected_fixture() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Duplicate argument: 'f' is already defined. --> {name}{SRC_LIB_RS}:68:17 | 68 | #[rstest(f(42), f => [41, 42])] | ^" ) .unindent() ); } #[test] fn if_define_value_list_that_is_already_a_case_arg() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Duplicate argument: 'a' is already defined. --> {name}{SRC_LIB_RS}:71:23 | 71 | #[rstest(a, case(42), a => [42])] | ^" ) .unindent() ); } #[test] fn if_define_a_case_arg_that_is_already_a_value_list() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Duplicate argument: 'a' is already defined. --> {name}{SRC_LIB_RS}:74:21 | 74 | #[rstest(a => [42], a, case(42))] | ^" ) .unindent() ); } #[test] fn if_define_a_case_arg_more_that_once() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Duplicate argument: 'a' is already defined. --> {name}{SRC_LIB_RS}:80:13 | 80 | #[rstest(a, a, case(42))] | ^" ) .unindent() ); } #[test] fn if_a_value_contains_empty_list() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Values list should not be empty --> {name}{SRC_LIB_RS}:58:19 | 58 | #[rstest(empty => [])] | ^^" ) .unindent() ); } #[test] fn if_try_to_convert_literal_string_to_a_type_that_not_implement_from_str() { let (output, name) = execute(); assert_in!(output.stderr.str(), format!("--> {name}{SRC_LIB_RS}:84:1")); assert_in!( output.stderr.str(), "| -------- doesn't satisfy `S: FromStr`" ); } #[test] fn if_try_to_use_future_on_an_impl() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " --> {name}{SRC_LIB_RS}:93:8 | 93 | s: impl AsRef, | ^^^^^^^^^^^^^^^ " ) .unindent() ); } #[test] fn if_try_to_use_future_more_that_once() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " --> {name}{SRC_LIB_RS}:102:5 | 102 | #[future] | ^^^^^^^^^ " ) .unindent() ); } #[test] fn if_use_timeout_without_arg() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: expected attribute arguments in parentheses: #[timeout(...)] --> {name}{SRC_LIB_RS}:108:3 | 108 | #[timeout] | ^^^^^^^ " ) .unindent() ); } #[test] fn if_timeout_is_not_an_expression() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: expected an expression --> {name}{SRC_LIB_RS}:112:17 | 112 | #[timeout(some -> strange -> invalid -> expression)] | ^ " ) .unindent() ); } #[test] fn if_timeout_is_not_a_duration() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error[E0308]: mismatched types --> {name}{SRC_LIB_RS}:116:11" ) .unindent() ); assert_in!( output.stderr.str(), " 116 | #[timeout(42)] | ^^ expected `Duration`, found integer " .unindent() ); } #[test] fn if_files_contains_absolute_path() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( " error: Invalid glob path: path contains non-relative component --> {name}{SRC_LIB_RS}:120:30" ) .unindent() ); assert_in!( output.stderr.str(), r#" 120 | fn error_absolute_path_files(#[files("/tmp/tmp.Q81idVZYAV/*.txt")] path: std::path::PathBuf) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "# .unindent() ); } #[test] fn try_to_destruct_implicit_fixture() { let (output, name) = execute(); assert_in!( output.stderr.str(), format!( r#" error: To destruct a fixture you should provide a path to resolve it by '#[from(...)]' attribute. --> {name}{SRC_LIB_RS}:126:27 | 126 | fn wrong_destruct_fixture(T(a, b): T, #[with(42)] T(c, d): T) {{}} | ^^^^^^^^^^"#, ) .unindent() ); assert_in!( output.stderr.str(), format!( r#" error: To destruct a fixture you should provide a path to resolve it by '#[from(...)]' attribute. --> {name}{SRC_LIB_RS}:126:51 | 126 | fn wrong_destruct_fixture(T(a, b): T, #[with(42)] T(c, d): T) {{}} | ^^^^^^^^^^"#, ) .unindent() ); assert_not_in!(output.stderr.str(), "#[case] T(e, f): T"); assert_not_in!(output.stderr.str(), "#[values(T(1, 2))] T(g, h): T"); } }