Original Summary

The approach in this crate is you don&#x27;t change any thing in your production code but directly mock functions such as std, reqwest and etc.<p>&#x2F;&#x2F; Production code use std::fs;<p>pub fn claim_slot() -&gt; Result&lt;(), String&gt; { fs::create_dir_all(&quot;&#x2F;var&#x2F;run&#x2F;dispatcher&quot;) .map_err(|error| format!(&quot;cannot claim a slot: {error}&quot;)) }<p>&#x2F;&#x2F; Test code<p>use shimforge::{Session, mock}; use std::io;<p>#[test] fn a_denied_slot_is_reported() { let mut session = Session::new(); let mkdir = mock!(session, fs::create_dir_all::&lt;&amp;str&gt;, fn(&amp;str) -&gt; io::Result&lt;()&gt;); mkdir .expect() .with(|path| *path == &quot;&#x2F;var&#x2F;run&#x2F;dispatcher&quot;) .once() .returning(|_| Err(io::ErrorKind::PermissionDenied.into()));<p><pre><code> let error = claim_slot().unwrap_err(); assert!(error.starts_with(&quot;cannot claim a slot&quot;)); }</code></pre>


  • 情报分类:综合情报
  • 分类依据:内容未命中明确的垂直分类规则,归入综合情报
  • 信息来源:Hacker News 新项目
  • 发布时间:2026/9/23 23:46:36