mirror of
https://github.com/jaywcjlove/reference.git
synced 2025-06-21 14:31:30 +08:00
doc: add cargo test in cargo.md (#82) 823b3163d4
This commit is contained in:
@ -42,7 +42,7 @@
|
||||
<p>此快速参考备忘清单 <a href="https://conan.io/">Cargo</a> 提供了编译 <a href="./rust.html">Rust</a> 常用命令和示例</p>
|
||||
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
|
||||
<path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
|
||||
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" href="#安装升级-rust-和-cargo">安装/升级 Rust 和 Cargo</a><a aria-hidden="true" class="leve3 tocs-link" href="#命令说明">命令说明</a><a aria-hidden="true" class="leve3 tocs-link" href="#切换源">切换源</a><a aria-hidden="true" class="leve3 tocs-link" href="#创建新项目">创建新项目</a><a aria-hidden="true" class="leve3 tocs-link" href="#项目目录">项目目录</a><a aria-hidden="true" class="leve3 tocs-link" href="#编译测试">编译测试</a><a aria-hidden="true" class="leve3 tocs-link" href="#配置目标">配置目标</a><a aria-hidden="true" class="leve3 tocs-link" href="#来源配置">来源配置</a><a aria-hidden="true" class="leve3 tocs-link" href="#配置">配置</a><a aria-hidden="true" class="leve2 tocs-link" href="#包相关命令">包相关命令</a><a aria-hidden="true" class="leve3 tocs-link" href="#initnew">init/new</a><a aria-hidden="true" class="leve3 tocs-link" href="#安装包">安装包</a><a aria-hidden="true" class="leve3 tocs-link" href="#搜索包">搜索包</a><a aria-hidden="true" class="leve3 tocs-link" href="#卸载包">卸载包</a><a aria-hidden="true" class="leve2 tocs-link" href="#发布命令">发布命令</a><a aria-hidden="true" class="leve3 tocs-link" href="#登录">登录</a><a aria-hidden="true" class="leve3 tocs-link" href="#所有者">所有者</a><a aria-hidden="true" class="leve3 tocs-link" href="#打包--发布公共选项">打包 & 发布公共选项</a><a aria-hidden="true" class="leve3 tocs-link" href="#打包">打包</a><a aria-hidden="true" class="leve3 tocs-link" href="#发布">发布</a><a aria-hidden="true" class="leve3 tocs-link" href="#yank">yank</a><a aria-hidden="true" class="leve2 tocs-link" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
|
||||
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" href="#安装升级-rust-和-cargo">安装/升级 Rust 和 Cargo</a><a aria-hidden="true" class="leve3 tocs-link" href="#命令说明">命令说明</a><a aria-hidden="true" class="leve3 tocs-link" href="#切换源">切换源</a><a aria-hidden="true" class="leve3 tocs-link" href="#创建新项目">创建新项目</a><a aria-hidden="true" class="leve3 tocs-link" href="#项目目录">项目目录</a><a aria-hidden="true" class="leve3 tocs-link" href="#编译测试">编译测试</a><a aria-hidden="true" class="leve4 tocs-link" href="#测试">测试</a><a aria-hidden="true" class="leve3 tocs-link" href="#配置目标">配置目标</a><a aria-hidden="true" class="leve3 tocs-link" href="#来源配置">来源配置</a><a aria-hidden="true" class="leve3 tocs-link" href="#配置">配置</a><a aria-hidden="true" class="leve2 tocs-link" href="#包相关命令">包相关命令</a><a aria-hidden="true" class="leve3 tocs-link" href="#initnew">init/new</a><a aria-hidden="true" class="leve3 tocs-link" href="#安装包">安装包</a><a aria-hidden="true" class="leve3 tocs-link" href="#搜索包">搜索包</a><a aria-hidden="true" class="leve3 tocs-link" href="#卸载包">卸载包</a><a aria-hidden="true" class="leve2 tocs-link" href="#发布命令">发布命令</a><a aria-hidden="true" class="leve3 tocs-link" href="#登录">登录</a><a aria-hidden="true" class="leve3 tocs-link" href="#所有者">所有者</a><a aria-hidden="true" class="leve3 tocs-link" href="#打包--发布公共选项">打包 & 发布公共选项</a><a aria-hidden="true" class="leve3 tocs-link" href="#打包">打包</a><a aria-hidden="true" class="leve3 tocs-link" href="#发布">发布</a><a aria-hidden="true" class="leve3 tocs-link" href="#yank">yank</a><a aria-hidden="true" class="leve2 tocs-link" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
|
||||
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="安装升级-rust-和-cargo"><a aria-hidden="true" tabindex="-1" href="#安装升级-rust-和-cargo"><span class="icon icon-link"></span></a>安装/升级 Rust 和 Cargo</h3><div class="wrap-body">
|
||||
<pre class="wrap-text"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">curl</span> <span class="token parameter variable">-sSf</span> https://static.rust-lang.org/rustup.sh <span class="token operator">|</span> <span class="token function">sh</span>
|
||||
</span></code></pre>
|
||||
@ -180,14 +180,21 @@
|
||||
</span><span class="code-line">└── tests <span class="token comment"># 集成测试</span>
|
||||
</span><span class="code-line"> └── some-integration-tests.rs
|
||||
</span></code></pre>
|
||||
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="编译测试"><a aria-hidden="true" tabindex="-1" href="#编译测试"><span class="icon icon-link"></span></a>编译测试</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="编译测试"><a aria-hidden="true" tabindex="-1" href="#编译测试"><span class="icon icon-link"></span></a>编译测试</h3><div class="wrap-body">
|
||||
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token comment"># 编译输出二进制文件,放入 `target/debug` 目录</span>
|
||||
</span><span class="code-line">$ <span class="token function">cargo</span> build
|
||||
</span><span class="code-line"><span class="token comment"># 输出二进制文件,放入 `target/release` 目录</span>
|
||||
</span><span class="code-line">$ <span class="token function">cargo</span> build <span class="token parameter variable">--release</span>
|
||||
</span><span class="code-line">$ <span class="token function">cargo</span> run <span class="token comment"># 编译并运行</span>
|
||||
</span><span class="code-line">$ <span class="token function">cargo</span> <span class="token builtin class-name">test</span> <span class="token comment"># 运行您的测试</span>
|
||||
</span><span class="code-line">$ <span class="token function">cargo</span> <span class="token builtin class-name">test</span> foo <span class="token comment"># 传递过滤器,来运行特定测试</span>
|
||||
</span></code></pre>
|
||||
<h4 id="测试"><a aria-hidden="true" tabindex="-1" href="#测试"><span class="icon icon-link"></span></a>测试</h4>
|
||||
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">cargo</span> <span class="token builtin class-name">test</span> <span class="token comment"># 运行你的所有测试</span>
|
||||
</span><span class="code-line"><span class="token comment"># 指定函数过滤器</span>
|
||||
</span><span class="code-line">$ <span class="token function">cargo</span> <span class="token builtin class-name">test</span> test_foo <span class="token comment"># 开头是 test_foo 的函数都会运行,例如(test_foo_bar)</span>
|
||||
</span><span class="code-line"><span class="token comment"># 指定特定模块中的测试函数(通常可以简写 cargo test foo::bar::tests::test_foo)</span>
|
||||
</span><span class="code-line"><span class="token function">cargo</span> <span class="token builtin class-name">test</span> <span class="token parameter variable">--package</span> rustt <span class="token parameter variable">--lib</span> -- foo::bar::tests::test_foo <span class="token parameter variable">--exact</span> <span class="token parameter variable">--nocapture</span>
|
||||
</span><span class="code-line"><span class="token comment"># 指定特定测试的模块(通常可以简写 cargo test foo::bar::tests)</span>
|
||||
</span><span class="code-line"><span class="token function">cargo</span> <span class="token builtin class-name">test</span> <span class="token parameter variable">--package</span> rustt <span class="token parameter variable">--lib</span> -- foo::bar::tests <span class="token parameter variable">--nocapture</span>
|
||||
</span></code></pre>
|
||||
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="配置目标"><a aria-hidden="true" tabindex="-1" href="#配置目标"><span class="icon icon-link"></span></a>配置目标</h3><div class="wrap-body">
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
Reference in New Issue
Block a user