assert_fs-1.0.13/.cargo_vcs_info.json0000644000000001360000000000100131070ustar { "git": { "sha1": "57165c3e83e15785a70c94c1ac29282b3796cdca" }, "path_in_vcs": "" }assert_fs-1.0.13/Cargo.lock0000644000000373430000000000100110740ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "aho-corasick" version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] [[package]] name = "anstream" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e579a7752471abc2a8268df8b20005e3eadd975f585398f17efcfd8d4927371" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", "is-terminal", "utf8parse", ] [[package]] name = "anstyle" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" [[package]] name = "anstyle-parse" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" dependencies = [ "windows-sys 0.48.0", ] [[package]] name = "anstyle-wincon" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bcd8291a340dd8ac70e18878bc4501dd7b4ff970cfa21c207d36ece51ea88fd" dependencies = [ "anstyle", "windows-sys 0.48.0", ] [[package]] name = "assert_fs" version = "1.0.13" dependencies = [ "anstream", "anstyle", "doc-comment", "globwalk", "predicates", "predicates-core", "predicates-tree", "tempfile", ] [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bstr" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ "memchr", ] [[package]] name = "cc" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "colorchoice" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "crossbeam-utils" version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ "cfg-if", ] [[package]] name = "difflib" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" [[package]] name = "doc-comment" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] name = "either" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "errno" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" dependencies = [ "errno-dragonfly", "libc", "winapi", ] [[package]] name = "errno-dragonfly" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" dependencies = [ "cc", "libc", ] [[package]] name = "fastrand" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" dependencies = [ "instant", ] [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "globset" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" dependencies = [ "aho-corasick", "bstr", "fnv", "log", "regex", ] [[package]] name = "globwalk" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" dependencies = [ "bitflags", "ignore", "walkdir", ] [[package]] name = "hermit-abi" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" [[package]] name = "ignore" version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d" dependencies = [ "crossbeam-utils", "globset", "lazy_static", "log", "memchr", "regex", "same-file", "thread_local", "walkdir", "winapi-util", ] [[package]] name = "instant" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if", ] [[package]] name = "io-lifetimes" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfa919a82ea574332e2de6e74b4c36e74d41982b335080fa59d4ef31be20fdf3" dependencies = [ "libc", "windows-sys 0.45.0", ] [[package]] name = "is-terminal" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" dependencies = [ "hermit-abi", "io-lifetimes", "rustix", "windows-sys 0.45.0", ] [[package]] name = "itertools" version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" version = "0.2.135" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" [[package]] name = "linux-raw-sys" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "log" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "once_cell" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "predicates" version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09963355b9f467184c04017ced4a2ba2d75cbcb4e7462690d388233253d4b1a9" dependencies = [ "anstyle", "difflib", "itertools", "predicates-core", ] [[package]] name = "predicates-core" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" [[package]] name = "predicates-tree" version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2cfd78a1cd6926a74e7f263eb466b765c79409b176be05c3676fac27df378e96" dependencies = [ "predicates-core", "termtree", ] [[package]] name = "redox_syscall" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] [[package]] name = "regex" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "remove_dir_all" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ "winapi", ] [[package]] name = "rustix" version = "0.36.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" dependencies = [ "bitflags", "errno", "io-lifetimes", "libc", "linux-raw-sys", "windows-sys 0.45.0", ] [[package]] name = "same-file" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" dependencies = [ "winapi-util", ] [[package]] name = "tempfile" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ "cfg-if", "fastrand", "libc", "redox_syscall", "remove_dir_all", "winapi", ] [[package]] name = "termtree" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thread_local" version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" dependencies = [ "once_cell", ] [[package]] name = "utf8parse" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "walkdir" version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", "winapi", "winapi-util", ] [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ "winapi", ] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ "windows-targets 0.42.2", ] [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ "windows-targets 0.48.0", ] [[package]] name = "windows-targets" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ "windows_aarch64_gnullvm 0.42.2", "windows_aarch64_msvc 0.42.2", "windows_i686_gnu 0.42.2", "windows_i686_msvc 0.42.2", "windows_x86_64_gnu 0.42.2", "windows_x86_64_gnullvm 0.42.2", "windows_x86_64_msvc 0.42.2", ] [[package]] name = "windows-targets" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" dependencies = [ "windows_aarch64_gnullvm 0.48.0", "windows_aarch64_msvc 0.48.0", "windows_i686_gnu 0.48.0", "windows_i686_msvc 0.48.0", "windows_x86_64_gnu 0.48.0", "windows_x86_64_gnullvm 0.48.0", "windows_x86_64_msvc 0.48.0", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_aarch64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_i686_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "windows_x86_64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" assert_fs-1.0.13/Cargo.toml0000644000000047630000000000100111170ustar # 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.65.0" name = "assert_fs" version = "1.0.13" authors = ["Ed Page "] include = [ "build.rs", "src/**/*", "Cargo.toml", "LICENSE*", "README.md", "benches/**/*", "examples/**/*", ] description = "Filesystem fixtures and assertions for testing." homepage = "https://github.com/assert-rs/assert_fs" documentation = "http://docs.rs/assert_fs/" readme = "README.md" keywords = [ "filesystem", "test", "assert", "fixture", ] categories = ["development-tools::testing"] license = "MIT OR Apache-2.0" repository = "https://github.com/assert-rs/assert_fs.git" [package.metadata.docs.rs] all-features = true rustdoc-args = [ "--cfg", "docsrs", ] [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "Unreleased" replace = "{{version}}" min = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = '\.\.\.HEAD' replace = "...{{tag_name}}" exactly = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "ReleaseDate" replace = "{{date}}" min = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "" replace = """ ## [Unreleased] - ReleaseDate """ exactly = 1 [[package.metadata.release.pre-release-replacements]] file = "CHANGELOG.md" search = "" replace = """ [Unreleased]: https://github.com/assert-rs/assert_fs/compare/{{tag_name}}...HEAD""" exactly = 1 [dependencies.anstream] version = "0.3.0" optional = true [dependencies.anstyle] version = "1.0.0" [dependencies.doc-comment] version = "0.3" [dependencies.globwalk] version = "0.8" [dependencies.predicates] version = "3.0.1" features = ["diff"] default-features = false [dependencies.predicates-core] version = "1.0.6" [dependencies.predicates-tree] version = "1.0.1" [dependencies.tempfile] version = "3.0" [features] color = [ "dep:anstream", "predicates/color", ] color-auto = ["color"] assert_fs-1.0.13/Cargo.toml.orig000064400000000000000000000034351046102023000145730ustar 00000000000000[workspace] resolver = "2" [workspace.package] license = "MIT OR Apache-2.0" edition = "2021" rust-version = "1.65.0" # MSRV include = [ "build.rs", "src/**/*", "Cargo.toml", "LICENSE*", "README.md", "benches/**/*", "examples/**/*" ] [package] name = "assert_fs" version = "1.0.13" authors = ["Ed Page "] description = "Filesystem fixtures and assertions for testing." repository = "https://github.com/assert-rs/assert_fs.git" homepage = "https://github.com/assert-rs/assert_fs" documentation = "http://docs.rs/assert_fs/" readme = "README.md" categories = ["development-tools::testing"] keywords = ["filesystem", "test", "assert", "fixture"] license.workspace = true edition.workspace = true rust-version.workspace = true include.workspace = true [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] [package.metadata.release] pre-release-replacements = [ {file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1}, {file="CHANGELOG.md", search="\\.\\.\\.HEAD", replace="...{{tag_name}}", exactly=1}, {file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1}, {file="CHANGELOG.md", search="", replace="\n## [Unreleased] - ReleaseDate\n", exactly=1}, {file="CHANGELOG.md", search="", replace="\n[Unreleased]: https://github.com/assert-rs/assert_fs/compare/{{tag_name}}...HEAD", exactly=1}, ] [features] color = ["dep:anstream", "predicates/color"] color-auto = ["color"] [dependencies] tempfile = "3.0" globwalk = "0.8" predicates = { version = "3.0.1", default-features = false, features = ["diff"] } predicates-core = "1.0.6" predicates-tree = "1.0.1" doc-comment = "0.3" anstyle = "1.0.0" anstream = { version = "0.3.0", optional = true } assert_fs-1.0.13/LICENSE-APACHE000064400000000000000000000261361046102023000136330ustar 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 {yyyy} {name of copyright owner} 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. assert_fs-1.0.13/LICENSE-MIT000064400000000000000000000020461046102023000133350ustar 00000000000000Copyright (c) Individual contributors 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. assert_fs-1.0.13/README.md000064400000000000000000000027171046102023000131650ustar 00000000000000# assert_fs > **Assert Filesystems** - Filesystem fixtures and assertions for testing. [![Documentation](https://img.shields.io/badge/docs-master-blue.svg)][Documentation] ![License](https://img.shields.io/crates/l/assert_fs.svg) [![Crates Status](https://img.shields.io/crates/v/assert_fs.svg)](https://crates.io/crates/assert_fs) `assert_fs` aims to simplify - Setting up files for your tests to consume - Asserting on files produced by your tests ## Example Here is a trivial example: ```rust use assert_fs::prelude::*; use predicates::prelude::*; let temp = assert_fs::TempDir::new().unwrap(); let input_file = temp.child("foo.txt"); input_file.touch().unwrap(); // ... do something with input_file ... input_file.assert(""); temp.child("bar.txt").assert(predicate::path::missing()); temp.close().unwrap(); ``` See the [documentation](https://docs.rs/assert_fs) for more information. ## License Licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. [Crates.io]: https://crates.io/crates/assert_fs [Documentation]: https://docs.rs/assert_fs assert_fs-1.0.13/examples/failure.rs000064400000000000000000000004051046102023000155110ustar 00000000000000use assert_fs::prelude::*; fn main() { let temp = assert_fs::TempDir::new().unwrap(); let input_file = temp.child("foo.txt"); input_file.write_str("Hello\nWorld!").unwrap(); input_file.assert("Goodbye\nWorld!"); temp.close().unwrap(); } assert_fs-1.0.13/src/assert.rs000064400000000000000000000311731046102023000143420ustar 00000000000000//! Filesystem assertions. //! //! See [`PathAssert`]. //! //! # Examples //! //! ```rust //! use assert_fs::prelude::*; //! use predicates::prelude::*; //! //! let temp = assert_fs::TempDir::new().unwrap(); //! let input_file = temp.child("foo.txt"); //! input_file.touch().unwrap(); //! //! // ... do something with input_file ... //! //! input_file.assert(""); //! temp.child("bar.txt").assert(predicate::path::missing()); //! //! temp.close().unwrap(); //! ``` //! use std::fmt; use std::path; #[cfg(feature = "color")] use anstream::panic; use predicates::path::PredicateFileContentExt; use predicates::str::PredicateStrExt; use predicates_tree::CaseTreeExt; use crate::fixture; /// Assert the state of files within [`TempDir`]. /// /// This uses [`IntoPathPredicate`] to provide short-hands for common cases, accepting: /// - `Predicate` for validating a path. /// - `Predicate` for validating the content of the file. /// - `&Path` which must have the same file content. /// - `&[u8]` or `&str` representing the content of the file. /// /// See [`predicates`] for more predicates. /// /// # Examples /// /// ```rust /// use assert_fs::prelude::*; /// use predicates::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// let input_file = temp.child("foo.txt"); /// input_file.touch().unwrap(); /// /// // ... do something with input_file ... /// /// input_file.assert(""); /// temp.child("bar.txt").assert(predicate::path::missing()); /// /// temp.close().unwrap(); /// ``` /// /// [`TempDir`]: super::TempDir pub trait PathAssert { /// Assert the state of files within [`TempDir`]. /// /// This uses [`IntoPathPredicate`] to provide short-hands for common cases, accepting: /// - `Predicate` for validating a path. /// - `Predicate` for validating the content of the file. /// - `&Path` which must have the same file content. /// - `&[u8]` or `&str` representing the content of the file. /// /// See [`predicates`] for more predicates. /// /// # Panic /// /// Will panic if the condition is not satisfied /// /// # Examples /// /// ```rust /// use assert_fs::prelude::*; /// use predicates::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// let input_file = temp.child("foo.txt"); /// input_file.touch().unwrap(); /// /// // ... do something with input_file ... /// /// input_file.assert(""); /// // or /// input_file.assert(predicate::str::is_empty()); /// /// temp.child("bar.txt").assert(predicate::path::missing()); /// /// temp.close().unwrap(); /// ``` /// /// [`TempDir`]: super::TempDir #[track_caller] fn assert(&self, pred: I) -> &Self where I: IntoPathPredicate

, P: predicates_core::Predicate; } impl PathAssert for fixture::TempDir { #[track_caller] fn assert(&self, pred: I) -> &Self where I: IntoPathPredicate

, P: predicates_core::Predicate, { assert(self.path(), pred); self } } impl PathAssert for fixture::NamedTempFile { #[track_caller] fn assert(&self, pred: I) -> &Self where I: IntoPathPredicate

, P: predicates_core::Predicate, { assert(self.path(), pred); self } } impl PathAssert for fixture::ChildPath { #[track_caller] fn assert(&self, pred: I) -> &Self where I: IntoPathPredicate

, P: predicates_core::Predicate, { assert(self.path(), pred); self } } #[track_caller] fn assert(path: &path::Path, pred: I) where I: IntoPathPredicate

, P: predicates_core::Predicate, { let pred = pred.into_path(); if let Some(case) = pred.find_case(false, path) { let palette = crate::Palette::color(); panic!( "Unexpected file, failed {:#}\n{:#}={:#}", case.tree(), palette.key("path"), palette.value(path.display()) ); } } /// Used by [`PathAssert`] to convert Self into the needed [`predicates_core::Predicate`]. /// /// # Examples /// /// ```rust /// use std::path; /// /// use assert_fs::prelude::*; /// use predicates::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// /// // ... do something with input_file ... /// /// temp.child("bar.txt").assert(predicate::path::missing()); // Uses IntoPathPredicate /// /// temp.close().unwrap(); /// ``` pub trait IntoPathPredicate

where P: predicates_core::Predicate, { /// The type of the predicate being returned. type Predicate; /// Convert to a predicate for testing a path. fn into_path(self) -> P; } impl

IntoPathPredicate

for P where P: predicates_core::Predicate, { type Predicate = P; fn into_path(self) -> Self::Predicate { self } } /// Keep `predicates` concrete Predicates out of our public API. /// [predicates_core::Predicate] used by [`IntoPathPredicate`] for bytes. /// /// # Example /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// let input_file = temp.child("foo.txt"); /// input_file.touch().unwrap(); /// /// // ... do something with input_file ... /// /// input_file.assert(b"" as &[u8]); // uses BytesContentPathPredicate /// /// temp.close().unwrap(); /// ``` #[derive(Debug)] pub struct BytesContentPathPredicate( predicates::path::FileContentPredicate>, ); impl BytesContentPathPredicate { pub(crate) fn new(value: &'static [u8]) -> Self { let pred = predicates::ord::eq(value).from_file_path(); BytesContentPathPredicate(pred) } } impl predicates_core::reflection::PredicateReflection for BytesContentPathPredicate { fn parameters<'a>( &'a self, ) -> Box> + 'a> { self.0.parameters() } /// Nested `Predicate`s of the current `Predicate`. fn children<'a>( &'a self, ) -> Box> + 'a> { self.0.children() } } impl predicates_core::Predicate for BytesContentPathPredicate { fn eval(&self, item: &path::Path) -> bool { self.0.eval(item) } fn find_case<'a>( &'a self, expected: bool, variable: &path::Path, ) -> Option> { self.0.find_case(expected, variable) } } impl fmt::Display for BytesContentPathPredicate { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } impl IntoPathPredicate for &'static [u8] { type Predicate = BytesContentPathPredicate; fn into_path(self) -> Self::Predicate { Self::Predicate::new(self) } } /// Keep `predicates` concrete Predicates out of our public API. /// [predicates_core::Predicate] used by `IntoPathPredicate` for `str`. /// /// # Example /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// let input_file = temp.child("foo.txt"); /// input_file.touch().unwrap(); /// /// // ... do something with input_file ... /// /// input_file.assert(""); // Uses StrContentPathPredicate /// /// temp.close().unwrap(); /// ``` #[derive(Debug, Clone)] pub struct StrContentPathPredicate( predicates::path::FileContentPredicate< predicates::str::Utf8Predicate, >, ); impl StrContentPathPredicate { pub(crate) fn new(value: String) -> Self { let pred = predicates::str::diff(value).from_utf8().from_file_path(); StrContentPathPredicate(pred) } } impl predicates_core::reflection::PredicateReflection for StrContentPathPredicate { fn parameters<'a>( &'a self, ) -> Box> + 'a> { self.0.parameters() } /// Nested `Predicate`s of the current `Predicate`. fn children<'a>( &'a self, ) -> Box> + 'a> { self.0.children() } } impl predicates_core::Predicate for StrContentPathPredicate { fn eval(&self, item: &path::Path) -> bool { self.0.eval(item) } fn find_case<'a>( &'a self, expected: bool, variable: &path::Path, ) -> Option> { self.0.find_case(expected, variable) } } impl fmt::Display for StrContentPathPredicate { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } impl IntoPathPredicate for String { type Predicate = StrContentPathPredicate; fn into_path(self) -> Self::Predicate { Self::Predicate::new(self) } } impl<'s> IntoPathPredicate for &'s str { type Predicate = StrContentPathPredicate; fn into_path(self) -> Self::Predicate { Self::Predicate::new(self.to_owned()) } } impl<'s> IntoPathPredicate for &'s String { type Predicate = StrContentPathPredicate; fn into_path(self) -> Self::Predicate { Self::Predicate::new(self.to_owned()) } } /// Keep `predicates` concrete Predicates out of our public API. /// [predicates_core::Predicate] used by `IntoPathPredicate` for `str` predicates. /// /// # Example /// /// ```rust /// use assert_fs::prelude::*; /// use predicates::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// let input_file = temp.child("foo.txt"); /// input_file.touch().unwrap(); /// /// // ... do something with input_file ... /// /// input_file.assert(predicate::str::is_empty()); // Uses StrPathPredicate /// /// temp.close().unwrap(); /// ``` #[derive(Debug, Clone)] pub struct StrPathPredicate>( predicates::path::FileContentPredicate>, ); impl

StrPathPredicate

where P: predicates_core::Predicate, { pub(crate) fn new(value: P) -> Self { let pred = value.from_utf8().from_file_path(); StrPathPredicate(pred) } } impl

predicates_core::reflection::PredicateReflection for StrPathPredicate

where P: predicates_core::Predicate, { fn parameters<'a>( &'a self, ) -> Box> + 'a> { self.0.parameters() } /// Nested `Predicate`s of the current `Predicate`. fn children<'a>( &'a self, ) -> Box> + 'a> { self.0.children() } } impl

predicates_core::Predicate for StrPathPredicate

where P: predicates_core::Predicate, { fn eval(&self, item: &path::Path) -> bool { self.0.eval(item) } fn find_case<'a>( &'a self, expected: bool, variable: &path::Path, ) -> Option> { self.0.find_case(expected, variable) } } impl

fmt::Display for StrPathPredicate

where P: predicates_core::Predicate, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } impl

IntoPathPredicate> for P where P: predicates_core::Predicate, { type Predicate = StrPathPredicate

; fn into_path(self) -> Self::Predicate { Self::Predicate::new(self) } } #[cfg(test)] mod test { use super::*; use predicates::prelude::*; // Since IntoPathPredicate exists solely for conversion, test it under that scenario to ensure // it works as expected. fn convert_path(pred: I) -> P where I: IntoPathPredicate

, P: predicates_core::Predicate, { pred.into_path() } #[test] fn into_path_from_pred() { let pred = convert_path(predicate::eq(path::Path::new("hello.md"))); let case = pred.find_case(false, path::Path::new("hello.md")); println!("Failing case: {:?}", case); assert!(case.is_none()); } #[test] fn into_path_from_bytes() { let pred = convert_path(b"hello\n" as &[u8]); let case = pred.find_case(false, path::Path::new("tests/fixture/hello.txt")); println!("Failing case: {:?}", case); assert!(case.is_none()); } #[test] fn into_path_from_str() { let pred = convert_path("hello\n"); let case = pred.find_case(false, path::Path::new("tests/fixture/hello.txt")); println!("Failing case: {:?}", case); assert!(case.is_none()); } } assert_fs-1.0.13/src/color.rs000064400000000000000000000026371046102023000141620ustar 00000000000000#[derive(Copy, Clone, Debug, Default)] pub(crate) struct Palette { key: anstyle::Style, value: anstyle::Style, } impl Palette { pub(crate) fn color() -> Self { if cfg!(feature = "color") { Self { key: anstyle::AnsiColor::Blue.on_default() | anstyle::Effects::BOLD, value: anstyle::AnsiColor::Yellow.on_default() | anstyle::Effects::BOLD, } } else { Self::plain() } } pub(crate) fn plain() -> Self { Self::default() } pub(crate) fn key(self, display: D) -> Styled { Styled::new(display, self.key) } pub(crate) fn value(self, display: D) -> Styled { Styled::new(display, self.value) } } #[derive(Debug)] pub(crate) struct Styled { display: D, style: anstyle::Style, } impl Styled { pub(crate) fn new(display: D, style: anstyle::Style) -> Self { Self { display, style } } } impl std::fmt::Display for Styled { #[inline] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { if f.alternate() { write!(f, "{}", self.style.render())?; self.display.fmt(f)?; write!(f, "{}", self.style.render_reset())?; Ok(()) } else { self.display.fmt(f) } } } assert_fs-1.0.13/src/fixture/child.rs000064400000000000000000000043011046102023000156030ustar 00000000000000use std::path; /// Access paths within [`TempDir`][crate::TempDir] for testing. /// /// See [`ChildPath`] trait implementations. /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// let input_file = temp.child("foo.txt"); /// input_file.touch().unwrap(); /// temp.close().unwrap(); /// ``` /// pub trait PathChild { /// Access a path within the temp directory. /// /// # Examples /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// println!("{}", temp.path().display()); /// println!("{}", temp.child("foo/bar.txt").path().display()); /// temp.close().unwrap(); /// ``` fn child

(&self, path: P) -> ChildPath where P: AsRef; } impl PathChild for super::TempDir { fn child

(&self, path: P) -> ChildPath where P: AsRef, { ChildPath::new(self.path().join(path.as_ref())) } } impl PathChild for ChildPath { fn child

(&self, path: P) -> ChildPath where P: AsRef, { ChildPath::new(self.path().join(path.as_ref())) } } /// A path within a [`TempDir`][crate::TempDir] /// /// See Trait Implementations. /// /// # Examples /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// /// let input_file = temp.child("foo.txt"); /// input_file.touch().unwrap(); /// /// temp.child("bar.txt").touch().unwrap(); /// /// temp.close().unwrap(); /// ``` /// pub struct ChildPath { path: path::PathBuf, } impl ChildPath { /// Wrap a path for use with extension traits. /// /// See trait implementations or [`PathChild`] for more details. /// pub fn new

(path: P) -> Self where P: Into, { Self { path: path.into() } } /// Access the path. pub fn path(&self) -> &path::Path { &self.path } } impl AsRef for ChildPath { fn as_ref(&self) -> &path::Path { &self.path } } impl std::ops::Deref for ChildPath { type Target = path::Path; #[inline] fn deref(&self) -> &path::Path { &self.path } } assert_fs-1.0.13/src/fixture/dir.rs000064400000000000000000000140061046102023000153010ustar 00000000000000use std::path; use super::errors::*; /// A directory in the filesystem that is automatically deleted when /// it goes out of scope. /// /// The [`TempDir`] type creates a directory on the file system that /// is deleted once it goes out of scope. At construction, the /// `TempDir` creates a new directory with a randomly generated name. /// /// The constructor, [`TempDir::new()`], creates directories in /// the location returned by [`std::env::temp_dir()`]. /// /// After creating a `TempDir`, work with the file system by doing /// standard [`std::fs`] file system operations on its [`Path`], /// which can be retrieved with [`TempDir::path()`]. Once the `TempDir` /// value is dropped, the directory at the path will be deleted, along /// with any files and directories it contains. It is your responsibility /// to ensure that no further file system operations are attempted /// inside the temporary directory once it has been deleted. /// /// # Resource Leaking /// /// Various platform-specific conditions may cause `TempDir` to fail /// to delete the underlying directory. It's important to ensure that /// handles (like [`File`] and [`ReadDir`]) to files inside the /// directory are dropped before the `TempDir` goes out of scope. The /// `TempDir` destructor will silently ignore any errors in deleting /// the directory; to instead handle errors call [`TempDir::close()`]. /// /// Note that if the program exits before the `TempDir` destructor is /// run, such as via [`std::process::exit()`], by segfaulting, or by /// receiving a signal like `SIGINT`, then the temporary directory /// will not be deleted. /// /// # Examples /// /// Create a temporary directory with a generated name: /// /// ``` /// use assert_fs::fixture::TempDir; /// /// let tmp_dir = TempDir::new().unwrap(); /// /// // Ensure deletion happens. /// tmp_dir.close().unwrap(); /// ``` /// /// [`File`]: std::fs::File /// [`Path`]: std::path::Path /// [`ReadDir`]: std::fs::ReadDir #[derive(Debug)] pub struct TempDir { temp: Inner, } #[derive(Debug)] enum Inner { Temp(tempfile::TempDir), Persisted(path::PathBuf), } impl TempDir { /// Attempts to make a temporary directory inside of `env::temp_dir()`. /// /// The directory and everything inside it will be automatically deleted /// once the returned `TempDir` is destroyed. /// /// # Errors /// /// If the directory can not be created, `Err` is returned. /// /// # Examples /// /// ``` /// use assert_fs::fixture::TempDir; /// /// let tmp_dir = TempDir::new().unwrap(); /// /// // Ensure deletion happens. /// tmp_dir.close().unwrap(); /// ``` pub fn new() -> Result { let temp = tempfile::TempDir::new().chain(FixtureError::new(FixtureKind::CreateDir))?; let temp = Inner::Temp(temp); Ok(Self { temp }) } /// Conditionally persist the temporary directory for debug purposes. /// /// Note: this operation is not reversible, i.e. `into_persistent_if(false)` is a no-op. /// /// # Examples /// /// ```no_run /// use assert_fs::fixture::TempDir; /// /// let tmp_dir = TempDir::new() /// .unwrap() /// .into_persistent_if(std::env::var_os("TEST_PERSIST_FILES").is_some()); /// /// // Ensure deletion happens. /// tmp_dir.close().unwrap(); /// ``` pub fn into_persistent_if(self, yes: bool) -> Self { if !yes { return self; } self.into_persistent() } /// Persist the temporary directory for debug purposes. /// /// Note: this operation is not reversible, i.e. `into_persistent_if(false)` is a no-op. /// /// # Examples /// /// ```no_run /// use assert_fs::fixture::TempDir; /// /// let tmp_dir = TempDir::new() /// .unwrap() /// .into_persistent(); /// /// // Ensure deletion happens. /// tmp_dir.close().unwrap(); /// ``` pub fn into_persistent(self) -> Self { let path = match self.temp { Inner::Temp(temp) => temp.into_path(), Inner::Persisted(path) => path, }; let temp = Inner::Persisted(path); Self { temp } } /// Accesses the [`Path`] to the temporary directory. /// /// [`Path`]: std::path::Path /// /// # Examples /// /// ``` /// use assert_fs::fixture::TempDir; /// /// let tmp_dir = TempDir::new().unwrap(); /// /// println!("{}", tmp_dir.path().display()); /// /// tmp_dir.close().unwrap(); /// ``` pub fn path(&self) -> &path::Path { match self.temp { Inner::Temp(ref temp) => temp.path(), Inner::Persisted(ref path) => path.as_path(), } } /// Closes and removes the temporary directory, returning a `Result`. /// /// Although `TempDir` removes the directory on drop, in the destructor /// any errors are ignored. To detect errors cleaning up the temporary /// directory, call `close` instead. /// /// # Errors /// /// This function may return a variety of [`std::io::Error`]s that result from deleting /// the files and directories contained with the temporary directory, /// as well as from deleting the temporary directory itself. These errors /// may be platform specific. /// /// /// # Examples /// /// ``` /// use assert_fs::fixture::TempDir; /// /// let tmp_dir = TempDir::new().unwrap(); /// /// // Ensure deletion happens. /// tmp_dir.close().unwrap(); /// ``` pub fn close(self) -> Result<(), FixtureError> { match self.temp { Inner::Temp(temp) => temp .close() .chain(FixtureError::new(FixtureKind::Cleanup))?, Inner::Persisted(_) => (), } Ok(()) } } impl AsRef for TempDir { fn as_ref(&self) -> &path::Path { self.path() } } impl std::ops::Deref for TempDir { type Target = path::Path; #[inline] fn deref(&self) -> &path::Path { self.path() } } assert_fs-1.0.13/src/fixture/errors.rs000064400000000000000000000062071046102023000160430ustar 00000000000000//! Error types for fixtures. use std::error::Error; use std::fmt; pub(crate) trait ChainError { fn chain(self, cause: F) -> Self where F: Error + Send + Sync + 'static; } pub(crate) trait ResultChainExt { fn chain(self, chainable: C) -> Result where C: ChainError; fn chain_with(self, chainable: F) -> Result where F: FnOnce() -> C, C: ChainError; } impl ResultChainExt for Result where E: Error + Send + Sync + 'static, { fn chain(self, chainable: C) -> Result where C: ChainError, { self.map_err(|e| chainable.chain(e)) } fn chain_with(self, chainable: F) -> Result where F: FnOnce() -> C, C: ChainError, { self.map_err(|e| chainable().chain(e)) } } /// Fixture initialization cause. #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum FixtureKind { /// Failed when walking the source tree. Walk, /// Failed when copying a file. CopyFile, /// Failed when writing to a file. WriteFile, /// Failed when creating a directory. CreateDir, /// Failed to cleanup fixture. Cleanup, /// Failed to create symlink Symlink, } impl fmt::Display for FixtureKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { FixtureKind::Walk => write!(f, "Failed when walking the source tree,"), FixtureKind::CopyFile => write!(f, "Failed when copying a file."), FixtureKind::WriteFile => write!(f, "Failed when writing to a file."), FixtureKind::CreateDir => write!(f, "Failed when creating a directory."), FixtureKind::Cleanup => write!(f, "Failed to cleanup fixture."), FixtureKind::Symlink => write!(f, "Failed when symlinking to the target."), } } } /// Failure when initializing the fixture. #[derive(Debug)] pub struct FixtureError { kind: FixtureKind, cause: Option>, } impl FixtureError { /// Create a `FixtureError`. pub fn new(kind: FixtureKind) -> Self { Self { kind, cause: None } } /// Fixture initialization cause. pub fn kind(&self) -> FixtureKind { self.kind } } impl Error for FixtureError { fn description(&self) -> &str { "Failed to initialize fixture" } fn cause(&self) -> Option<&dyn Error> { self.cause.as_ref().map(|c| { let c: &dyn Error = c.as_ref(); c }) } } impl fmt::Display for FixtureError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.cause { Some(ref cause) => write!( f, "Failed to initialize fixture: {}\nCause: {}", self.kind, cause ), None => write!(f, "Failed to initialize fixture: {}", self.kind), } } } impl ChainError for FixtureError { fn chain(mut self, cause: F) -> Self where F: Error + Send + Sync + 'static, { self.cause = Some(Box::new(cause)); self } } assert_fs-1.0.13/src/fixture/file.rs000064400000000000000000000141611046102023000154440ustar 00000000000000use std::ffi; use std::path; use super::errors::*; /// A potential file in the filesystem that is automatically deleted when /// it goes out of scope. /// /// The [`NamedTempFile`] type creates a directory on the file system that /// is deleted once it goes out of scope. At construction, the /// `NamedTempFile` creates a new directory with a randomly generated name. /// /// The constructor, [`NamedTempFile::new(name)`], creates directories in /// the location returned by [`std::env::temp_dir()`]. /// /// After creating a `NamedTempFile`, work with the file system by doing /// standard [`std::fs`] file system operations on its [`Path`], /// which can be retrieved with [`NamedTempFile::path()`]. Once the `NamedTempFile` /// value is dropped, the parent directory will be deleted, along with the file. It is your /// responsibility to ensure that no further file system operations are attempted inside the /// temporary directory once it has been deleted. /// /// # Resource Leaking /// /// Various platform-specific conditions may cause `NamedTempFile` to fail /// to delete the underlying directory. It's important to ensure that /// handles (like [`File`] and [`ReadDir`]) to the file inside the /// directory is dropped before the `NamedTempFile` goes out of scope. The /// `NamedTempFile` destructor will silently ignore any errors in deleting /// the directory; to instead handle errors call [`NamedTempFile::close()`]. /// /// Note that if the program exits before the `NamedTempFile` destructor is /// run, such as via [`std::process::exit()`], by segfaulting, or by /// receiving a signal like `SIGINT`, then the temporary directory /// will not be deleted. /// /// # Examples /// /// Create a temporary file. /// /// ``` /// use assert_fs::fixture::NamedTempFile; /// /// let tmp_file = NamedTempFile::new("foo.rs").unwrap(); /// /// // Ensure deletion happens. /// tmp_file.close().unwrap(); /// ``` /// /// [`File`]: std::fs::File /// [`Path`]: std::path::Path /// [`ReadDir`]: std::fs::ReadDir #[derive(Debug)] pub struct NamedTempFile { temp: Inner, path: path::PathBuf, } #[derive(Debug)] enum Inner { Temp(tempfile::TempDir), Persisted, } impl NamedTempFile { /// Attempts to make a temporary file inside of `env::temp_dir()`. /// /// The file and parent directory will be automatically deleted once the returned /// `NamedTempFile` is destroyed. /// /// # Errors /// /// If the parent directory can not be created, `Err` is returned. /// /// # Examples /// /// ``` /// use assert_fs::fixture::NamedTempFile; /// /// let tmp_file = NamedTempFile::new("foo.rs").unwrap(); /// /// // Ensure deletion happens. /// tmp_file.close().unwrap(); /// ``` pub fn new(name: S) -> Result where S: AsRef, { let temp = tempfile::TempDir::new().chain(FixtureError::new(FixtureKind::CreateDir))?; let path = temp.path().join(name.as_ref()); let temp = Inner::Temp(temp); Ok(Self { temp, path }) } /// Conditionally persist the temporary file for debug purposes. /// /// Note: this operation is not reversible, i.e. `into_persistent_if(false)` is a no-op. /// /// # Examples /// /// ```no_run /// use assert_fs::fixture::NamedTempFile; /// /// let tmp_file = NamedTempFile::new("foo.rs") /// .unwrap() /// .into_persistent_if(std::env::var_os("TEST_PERSIST_FILES").is_some()); /// /// // Ensure deletion happens. /// tmp_file.close().unwrap(); /// ``` pub fn into_persistent_if(self, yes: bool) -> Self { if !yes { return self; } self.into_persistent() } /// Persist the temporary file for debug purposes. /// /// Note: this operation is not reversible, i.e. `into_persistent_if(false)` is a no-op. /// /// # Examples /// /// ```no_run /// use assert_fs::fixture::NamedTempFile; /// /// let tmp_file = NamedTempFile::new("foo.rs") /// .unwrap() /// .into_persistent(); /// /// // Ensure deletion happens. /// tmp_file.close().unwrap(); /// ``` pub fn into_persistent(mut self) -> Self { let mut temp = Inner::Persisted; ::std::mem::swap(&mut self.temp, &mut temp); if let Inner::Temp(temp) = temp { temp.into_path(); } self } /// Accesses the [`Path`] to the temporary file. /// /// [`Path`]: std::path::Path /// /// # Examples /// /// ``` /// use assert_fs::fixture::NamedTempFile; /// /// let tmp_file = NamedTempFile::new("foo.rs").unwrap(); /// /// println!("{}", tmp_file.path().display()); /// /// // Ensure deletion happens. /// tmp_file.close().unwrap(); /// ``` pub fn path(&self) -> &path::Path { &self.path } /// Closes and removes the temporary file and parent directory, returning a `Result`. /// /// Although `NamedTempFile` removes the directory on drop, in the destructor /// any errors are ignored. To detect errors cleaning up the temporary /// directory, call `close` instead. /// /// # Errors /// /// This function may return a variety of [`std::io::Error`]s that result from deleting the /// temporary file and parent directory, These errors may be platform specific. /// /// /// # Examples /// /// ``` /// use assert_fs::fixture::NamedTempFile; /// /// let tmp_file = NamedTempFile::new("foo.rs").unwrap(); /// /// // Ensure deletion happens. /// tmp_file.close().unwrap(); /// ``` pub fn close(self) -> Result<(), FixtureError> { match self.temp { Inner::Temp(temp) => temp .close() .chain(FixtureError::new(FixtureKind::Cleanup))?, Inner::Persisted => (), } Ok(()) } } impl AsRef for NamedTempFile { fn as_ref(&self) -> &path::Path { self.path() } } impl std::ops::Deref for NamedTempFile { type Target = path::Path; #[inline] fn deref(&self) -> &path::Path { self.path() } } assert_fs-1.0.13/src/fixture/mod.rs000064400000000000000000000003441046102023000153020ustar 00000000000000//! Initialize the filesystem to use as test fixtures. mod child; mod dir; mod errors; mod file; mod tools; pub use self::child::*; pub use self::dir::*; pub use self::errors::*; pub use self::file::*; pub use self::tools::*; assert_fs-1.0.13/src/fixture/tools.rs000064400000000000000000000241771046102023000156750ustar 00000000000000//! Initialize the filesystem to use as test fixtures. use std::fs; use std::io::Write; use std::path; use super::errors::*; use super::ChildPath; use super::NamedTempFile; use super::TempDir; /// Create empty directories at [`ChildPath`]. /// pub trait PathCreateDir { /// Create an empty directory at [`ChildPath`]. /// /// # Examples /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// temp.child("subdir").create_dir_all().unwrap(); /// temp.close().unwrap(); /// ``` /// fn create_dir_all(&self) -> Result<(), FixtureError>; } impl PathCreateDir for ChildPath { fn create_dir_all(&self) -> Result<(), FixtureError> { create_dir_all(self.path()) } } /// Create empty files at [`ChildPath`]. /// pub trait FileTouch { /// Create an empty file at [`ChildPath`]. /// /// # Examples /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// temp.child("foo.txt").touch().unwrap(); /// temp.close().unwrap(); /// ``` /// fn touch(&self) -> Result<(), FixtureError>; } impl FileTouch for ChildPath { fn touch(&self) -> Result<(), FixtureError> { touch(self.path()) } } impl FileTouch for NamedTempFile { fn touch(&self) -> Result<(), FixtureError> { touch(self.path()) } } /// Write a binary file at [`ChildPath`]. /// pub trait FileWriteBin { /// Write a binary file at [`ChildPath`]. /// /// # Examples /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// temp /// .child("foo.txt") /// .write_binary(b"To be or not to be...") /// .unwrap(); /// temp.close().unwrap(); /// ``` /// fn write_binary(&self, data: &[u8]) -> Result<(), FixtureError>; } impl FileWriteBin for ChildPath { fn write_binary(&self, data: &[u8]) -> Result<(), FixtureError> { write_binary(self.path(), data) } } impl FileWriteBin for NamedTempFile { fn write_binary(&self, data: &[u8]) -> Result<(), FixtureError> { write_binary(self.path(), data) } } /// Write a text file at [`ChildPath`]. /// pub trait FileWriteStr { /// Write a text file at [`ChildPath`]. /// /// # Examples /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// temp /// .child("foo.txt") /// .write_str("To be or not to be...") /// .unwrap(); /// temp.close().unwrap(); /// ``` /// fn write_str(&self, data: &str) -> Result<(), FixtureError>; } impl FileWriteStr for ChildPath { fn write_str(&self, data: &str) -> Result<(), FixtureError> { write_str(self.path(), data) } } impl FileWriteStr for NamedTempFile { fn write_str(&self, data: &str) -> Result<(), FixtureError> { write_str(self.path(), data) } } /// Write (copy) a file to [`ChildPath`]. /// pub trait FileWriteFile { /// Write (copy) a file to [`ChildPath`]. /// /// # Examples /// /// ```rust /// use std::path::Path; /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// temp /// .child("foo.txt") /// .write_file(Path::new("Cargo.toml")) /// .unwrap(); /// temp.close().unwrap(); /// ``` /// fn write_file(&self, data: &path::Path) -> Result<(), FixtureError>; } impl FileWriteFile for ChildPath { fn write_file(&self, data: &path::Path) -> Result<(), FixtureError> { write_file(self.path(), data) } } impl FileWriteFile for NamedTempFile { fn write_file(&self, data: &path::Path) -> Result<(), FixtureError> { write_file(self.path(), data) } } /// Copy files into [`TempDir`]. /// pub trait PathCopy { /// Copy files and directories into the current path from the `source` according to the glob /// `patterns`. /// /// # Examples /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// temp.copy_from(".", &["*.rs"]).unwrap(); /// temp.close().unwrap(); /// ``` fn copy_from(&self, source: P, patterns: &[S]) -> Result<(), FixtureError> where P: AsRef, S: AsRef; } impl PathCopy for TempDir { fn copy_from(&self, source: P, patterns: &[S]) -> Result<(), FixtureError> where P: AsRef, S: AsRef, { copy_files(self.path(), source.as_ref(), patterns) } } impl PathCopy for ChildPath { fn copy_from(&self, source: P, patterns: &[S]) -> Result<(), FixtureError> where P: AsRef, S: AsRef, { copy_files(self.path(), source.as_ref(), patterns) } } /// Create a symlink to the target /// pub trait SymlinkToFile { /// Create a symlink to the target /// /// # Examples /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// let real_file = temp.child("real_file"); /// real_file.touch().unwrap(); /// /// temp.child("link_file").symlink_to_file(real_file.path()).unwrap(); /// /// temp.close().unwrap(); /// ``` fn symlink_to_file

(&self, target: P) -> Result<(), FixtureError> where P: AsRef; } impl SymlinkToFile for ChildPath { fn symlink_to_file

(&self, target: P) -> Result<(), FixtureError> where P: AsRef, { symlink_to_file(self.path(), target.as_ref()) } } impl SymlinkToFile for NamedTempFile { fn symlink_to_file

(&self, target: P) -> Result<(), FixtureError> where P: AsRef, { symlink_to_file(self.path(), target.as_ref()) } } /// Create a symlink to the target /// pub trait SymlinkToDir { /// Create a symlink to the target /// /// # Examples /// /// ```rust /// use assert_fs::prelude::*; /// /// let temp = assert_fs::TempDir::new().unwrap(); /// let real_dir = temp.child("real_dir"); /// real_dir.create_dir_all().unwrap(); /// /// temp.child("link_dir").symlink_to_dir(real_dir.path()).unwrap(); /// /// temp.close().unwrap(); /// ``` fn symlink_to_dir

(&self, target: P) -> Result<(), FixtureError> where P: AsRef; } impl SymlinkToDir for ChildPath { fn symlink_to_dir

(&self, target: P) -> Result<(), FixtureError> where P: AsRef, { symlink_to_dir(self.path(), target.as_ref()) } } impl SymlinkToDir for TempDir { fn symlink_to_dir

(&self, target: P) -> Result<(), FixtureError> where P: AsRef, { symlink_to_dir(self.path(), target.as_ref()) } } fn ensure_parent_dir(path: &path::Path) -> Result<(), FixtureError> { if let Some(parent) = path.parent() { fs::create_dir_all(parent).chain(FixtureError::new(FixtureKind::CreateDir))?; } Ok(()) } fn create_dir_all(path: &path::Path) -> Result<(), FixtureError> { fs::create_dir_all(path).chain(FixtureError::new(FixtureKind::CreateDir))?; Ok(()) } fn touch(path: &path::Path) -> Result<(), FixtureError> { ensure_parent_dir(path)?; fs::File::create(path).chain(FixtureError::new(FixtureKind::WriteFile))?; Ok(()) } fn write_binary(path: &path::Path, data: &[u8]) -> Result<(), FixtureError> { ensure_parent_dir(path)?; let mut file = fs::File::create(path).chain(FixtureError::new(FixtureKind::WriteFile))?; file.write_all(data) .chain(FixtureError::new(FixtureKind::WriteFile))?; Ok(()) } fn write_str(path: &path::Path, data: &str) -> Result<(), FixtureError> { ensure_parent_dir(path)?; write_binary(path, data.as_bytes()).chain(FixtureError::new(FixtureKind::WriteFile)) } fn write_file(path: &path::Path, data: &path::Path) -> Result<(), FixtureError> { ensure_parent_dir(path)?; fs::copy(data, path).chain(FixtureError::new(FixtureKind::CopyFile))?; Ok(()) } fn copy_files( target: &path::Path, source: &path::Path, patterns: &[S], ) -> Result<(), FixtureError> where S: AsRef, { // `walkdir`, on Windows, seems to convert "." into "" which then fails. let source = source .canonicalize() .chain(FixtureError::new(FixtureKind::Walk))?; for entry in globwalk::GlobWalkerBuilder::from_patterns(&source, patterns) .follow_links(true) .build() .chain(FixtureError::new(FixtureKind::Walk))? { let entry = entry.chain(FixtureError::new(FixtureKind::Walk))?; let rel = entry .path() .strip_prefix(&source) .expect("entries to be under `source`"); let target_path = target.join(rel); if entry.file_type().is_dir() { fs::create_dir_all(target_path).chain(FixtureError::new(FixtureKind::CreateDir))?; } else if entry.file_type().is_file() { fs::create_dir_all(target_path.parent().expect("at least `target` exists")) .chain(FixtureError::new(FixtureKind::CreateDir))?; fs::copy(entry.path(), target_path).chain(FixtureError::new(FixtureKind::CopyFile))?; } } Ok(()) } #[cfg(windows)] fn symlink_to_file(link: &path::Path, target: &path::Path) -> Result<(), FixtureError> { std::os::windows::fs::symlink_file(target, link) .chain(FixtureError::new(FixtureKind::Symlink))?; Ok(()) } #[cfg(windows)] fn symlink_to_dir(link: &path::Path, target: &path::Path) -> Result<(), FixtureError> { std::os::windows::fs::symlink_dir(target, link) .chain(FixtureError::new(FixtureKind::Symlink))?; Ok(()) } #[cfg(not(windows))] fn symlink_to_file(link: &path::Path, target: &path::Path) -> Result<(), FixtureError> { std::os::unix::fs::symlink(target, link).chain(FixtureError::new(FixtureKind::Symlink))?; Ok(()) } #[cfg(not(windows))] fn symlink_to_dir(link: &path::Path, target: &path::Path) -> Result<(), FixtureError> { std::os::unix::fs::symlink(target, link).chain(FixtureError::new(FixtureKind::Symlink))?; Ok(()) } assert_fs-1.0.13/src/lib.rs000064400000000000000000000051601046102023000136040ustar 00000000000000//! Filesystem fixtures and assertions for testing. //! //! `assert_fs` aims to simplify //! - Setting up files for your tests to consume //! - Asserting on files produced by your tests //! //! ## Overview //! //! Setting up a fixture //! - [`TempDir`] or [`NamedTempFile`] for a sandbox to test in. //! - [`touch`][`FileTouch`] a [`ChildPath`] or [`NamedTempFile`] //! - [`write_binary`][`FileWriteBin`] a [`ChildPath`] or [`NamedTempFile`] //! - [`write_str`][`FileWriteStr`] a [`ChildPath`] or [`NamedTempFile`] //! - [`write_file`][`FileWriteFile`] a [`ChildPath`] or [`NamedTempFile`] //! - [`copy_from`][`PathCopy`] a pristine folder to a [`ChildPath`] or [`TempDir`] //! - [`symlink_to_file`][`SymlinkToFile`] a [`ChildPath`] or [`NamedTempFile`] //! - [`symlink_to_dir`][`SymlinkToDir`] a [`ChildPath`] or [`TempDir`] //! //! Validating //! - [`assert`][`PathAssert`] a [`ChildPath`], [`TempDir`], or [`NamedTempFile`] //! //! ## Example //! //! Here is a trivial example: //! //! ```rust //! use assert_fs::prelude::*; //! use predicates::prelude::*; //! //! let temp = assert_fs::TempDir::new().unwrap(); //! let input_file = temp.child("foo.txt"); //! input_file.touch().unwrap(); //! //! // ... do something with input_file ... //! //! input_file.assert(""); //! temp.child("bar.txt").assert(predicate::path::missing()); //! //! temp.close().unwrap(); //! ``` //! //! [`ChildPath`]: fixture::ChildPath //! [`FileTouch`]: fixture::FileTouch //! [`FileWriteBin`]: fixture::FileWriteBin //! [`FileWriteStr`]: fixture::FileWriteStr //! [`FileWriteFile`]: fixture::FileWriteFile //! [`SymlinkToDir`]: fixture::SymlinkToDir //! [`SymlinkToFile`]: fixture::SymlinkToFile //! [`PathCopy`]: fixture::PathCopy //! [`PathAssert`]: assert::PathAssert //! [dir-diff]: https://crates.io/crates/dir-diff #![warn(missing_docs)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] pub mod assert; pub mod fixture; // Pulling this in for convenience-sake #[doc(inline)] pub use crate::fixture::TempDir; // Pulling this in for convenience-sake #[doc(inline)] pub use crate::fixture::NamedTempFile; /// Extension traits that are useful to have available. pub mod prelude { pub use crate::assert::PathAssert; pub use crate::fixture::FileTouch; pub use crate::fixture::FileWriteBin; pub use crate::fixture::FileWriteFile; pub use crate::fixture::FileWriteStr; pub use crate::fixture::PathChild; pub use crate::fixture::PathCopy; pub use crate::fixture::PathCreateDir; pub use crate::fixture::SymlinkToDir; pub use crate::fixture::SymlinkToFile; } mod color; use color::Palette; #[macro_use] extern crate doc_comment; doctest!("../README.md");