mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
110 lines
12 KiB
HTML
110 lines
12 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `test` mod in crate `ring`."><meta name="keywords" content="rust, rustlang, rust-lang, test"><title>ring::test - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-16x16.png">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../../ring/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Module test</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></div><p class="location"><a href="../index.html">ring</a></p><div id="sidebar-vars" data-name="test" data-ty="mod" data-relpath="../"></div><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button>
|
||
<a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Module <a href="../index.html">ring</a>::<wbr><a class="mod" href="">test</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../../src/ring/test.rs.html#15-640" title="goto source code">[src]</a></span></h1><div class="docblock"><p>Testing framework.</p>
|
||
<p>Unlike the rest of <em>ring</em>, this testing framework uses panics pretty
|
||
liberally. It was originally designed for internal use--it drives most of
|
||
<em>ring</em>'s internal tests, and so it is optimized for getting <em>ring</em>'s tests
|
||
written quickly at the expense of some usability. The documentation is
|
||
lacking. The best way to learn it is to look at some examples. The digest
|
||
tests are the most complicated because they use named sections. Other tests
|
||
avoid named sections and so are easier to understand.</p>
|
||
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1><h2 id="writing-tests" class="section-header"><a href="#writing-tests">Writing Tests</a></h2>
|
||
<p>Input files look like this:</p>
|
||
<pre><code class="language-text"># This is a comment.
|
||
|
||
HMAC = SHA1
|
||
Input = "My test data"
|
||
Key = ""
|
||
Output = 61afdecb95429ef494d61fdee15990cabf0826fc
|
||
|
||
HMAC = SHA256
|
||
Input = "Sample message for keylen<blocklen"
|
||
Key = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F
|
||
Output = A28CF43130EE696A98F14A37678B56BCFCBDD9E5CF69717FECF5480F0EBDF790
|
||
</code></pre>
|
||
<p>Test cases are separated with blank lines. Note how the bytes of the <code>Key</code>
|
||
attribute are specified as a quoted string in the first test case and as
|
||
hex in the second test case; you can use whichever form is more convenient
|
||
and you can mix and match within the same file. The empty sequence of bytes
|
||
can only be represented with the quoted string form (<code>""</code>).</p>
|
||
<p>Here's how you would consume the test data:</p>
|
||
|
||
<div class='information'><div class='tooltip ignore'>ⓘ</div></div><div class="example-wrap"><pre class="rust rust-example-rendered ignore">
|
||
<span class="kw">use</span> <span class="ident">ring</span>::<span class="ident">test</span>;
|
||
|
||
<span class="ident">test</span>::<span class="ident">run</span>(<span class="ident">test</span>::<span class="macro">test_file</span><span class="macro">!</span>(<span class="string">"hmac_tests.txt"</span>), <span class="op">|</span><span class="ident">section</span>, <span class="ident">test_case</span><span class="op">|</span> {
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">section</span>, <span class="string">""</span>); <span class="comment">// This test doesn't use named sections.</span>
|
||
|
||
<span class="kw">let</span> <span class="ident">digest_alg</span> <span class="op">=</span> <span class="ident">test_case</span>.<span class="ident">consume_digest_alg</span>(<span class="string">"HMAC"</span>);
|
||
<span class="kw">let</span> <span class="ident">input</span> <span class="op">=</span> <span class="ident">test_case</span>.<span class="ident">consume_bytes</span>(<span class="string">"Input"</span>);
|
||
<span class="kw">let</span> <span class="ident">key</span> <span class="op">=</span> <span class="ident">test_case</span>.<span class="ident">consume_bytes</span>(<span class="string">"Key"</span>);
|
||
<span class="kw">let</span> <span class="ident">output</span> <span class="op">=</span> <span class="ident">test_case</span>.<span class="ident">consume_bytes</span>(<span class="string">"Output"</span>);
|
||
|
||
<span class="comment">// Do the actual testing here</span>
|
||
});</pre></div>
|
||
<p>Note that <code>consume_digest_alg</code> automatically maps the string "SHA1" to a
|
||
reference to <code>digest::SHA1_FOR_LEGACY_USE_ONLY</code>, "SHA256" to
|
||
<code>digest::SHA256</code>, etc.</p>
|
||
<h2 id="output-when-a-test-fails" class="section-header"><a href="#output-when-a-test-fails">Output When a Test Fails</a></h2>
|
||
<p>When a test case fails, the framework automatically prints out the test
|
||
case. If the test case failed with a panic, then the backtrace of the panic
|
||
will be printed too. For example, let's say the failing test case looks
|
||
like this:</p>
|
||
<pre><code class="language-text">Curve = P-256
|
||
a = 2b11cb945c8cf152ffa4c9c2b1c965b019b35d0b7626919ef0ae6cb9d232f8af
|
||
b = 18905f76a53755c679fb732b7762251075ba95fc5fedb60179e730d418a9143c
|
||
r = 18905f76a53755c679fb732b7762251075ba95fc5fedb60179e730d418a9143c
|
||
</code></pre>
|
||
<p>If the test fails, this will be printed (if <code>$RUST_BACKTRACE</code> is <code>1</code>):</p>
|
||
<pre><code class="language-text">src/example_tests.txt: Test panicked.
|
||
Curve = P-256
|
||
a = 2b11cb945c8cf152ffa4c9c2b1c965b019b35d0b7626919ef0ae6cb9d232f8af
|
||
b = 18905f76a53755c679fb732b7762251075ba95fc5fedb60179e730d418a9143c
|
||
r = 18905f76a53755c679fb732b7762251075ba95fc5fedb60179e730d418a9143c
|
||
thread 'example_test' panicked at 'Test failed.', src\test.rs:206
|
||
stack backtrace:
|
||
0: 0x7ff654a05c7c - std::rt::lang_start::h61f4934e780b4dfc
|
||
1: 0x7ff654a04f32 - std::rt::lang_start::h61f4934e780b4dfc
|
||
2: 0x7ff6549f505d - std::panicking::rust_panic_with_hook::hfe203e3083c2b544
|
||
3: 0x7ff654a0825b - rust_begin_unwind
|
||
4: 0x7ff6549f63af - std::panicking::begin_panic_fmt::h484cd47786497f03
|
||
5: 0x7ff654a07e9b - rust_begin_unwind
|
||
6: 0x7ff654a0ae95 - core::panicking::panic_fmt::h257ceb0aa351d801
|
||
7: 0x7ff654a0b190 - core::panicking::panic::h4bb1497076d04ab9
|
||
8: 0x7ff65496dc41 - from_file<closure>
|
||
at C:\Users\Example\example\<core macros>:4
|
||
9: 0x7ff65496d49c - example_test
|
||
at C:\Users\Example\example\src\example.rs:652
|
||
10: 0x7ff6549d192a - test::stats::Summary::new::ha139494ed2e4e01f
|
||
11: 0x7ff6549d51a2 - test::stats::Summary::new::ha139494ed2e4e01f
|
||
12: 0x7ff654a0a911 - _rust_maybe_catch_panic
|
||
13: 0x7ff6549d56dd - test::stats::Summary::new::ha139494ed2e4e01f
|
||
14: 0x7ff654a03783 - std::sys::thread::Thread::new::h2b08da6cd2517f79
|
||
15: 0x7ff968518101 - BaseThreadInitThunk
|
||
</code></pre>
|
||
<p>Notice that the output shows the name of the data file
|
||
(<code>src/example_tests.txt</code>), the test inputs that led to the failure, and the
|
||
stack trace to the line in the test code that panicked: entry 9 in the
|
||
stack trace pointing to line 652 of the file <code>example.rs</code>.</p>
|
||
</div><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2>
|
||
<table><tr class="module-item"><td><a class="struct" href="struct.File.html" title="ring::test::File struct">File</a></td><td class="docblock-short"><p>A test input file.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.TestCase.html" title="ring::test::TestCase struct">TestCase</a></td><td class="docblock-short"><p>A test case. A test case consists of a set of named attributes. Every
|
||
attribute in the test case must be consumed exactly once; this helps catch
|
||
typos and omissions.</p>
|
||
</td></tr></table><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2>
|
||
<table><tr class="module-item"><td><a class="fn" href="fn.compile_time_assert_clone.html" title="ring::test::compile_time_assert_clone fn">compile_time_assert_clone</a></td><td class="docblock-short"><p><code>compile_time_assert_clone::<T>();</code> fails to compile if <code>T</code> doesn't
|
||
implement <code>Clone</code>.</p>
|
||
</td></tr><tr class="module-item"><td><a class="fn" href="fn.compile_time_assert_copy.html" title="ring::test::compile_time_assert_copy fn">compile_time_assert_copy</a></td><td class="docblock-short"><p><code>compile_time_assert_copy::<T>();</code> fails to compile if <code>T</code> doesn't
|
||
implement <code>Copy</code>.</p>
|
||
</td></tr><tr class="module-item"><td><a class="fn" href="fn.compile_time_assert_send.html" title="ring::test::compile_time_assert_send fn">compile_time_assert_send</a></td><td class="docblock-short"><p><code>compile_time_assert_send::<T>();</code> fails to compile if <code>T</code> doesn't
|
||
implement <code>Send</code>.</p>
|
||
</td></tr><tr class="module-item"><td><a class="fn" href="fn.compile_time_assert_sync.html" title="ring::test::compile_time_assert_sync fn">compile_time_assert_sync</a></td><td class="docblock-short"><p><code>compile_time_assert_sync::<T>();</code> fails to compile if <code>T</code> doesn't
|
||
implement <code>Sync</code>.</p>
|
||
</td></tr><tr class="module-item"><td><a class="fn" href="fn.from_hex.html" title="ring::test::from_hex fn">from_hex</a></td><td class="docblock-short"><p>Decode an string of hex digits into a sequence of bytes. The input must
|
||
have an even number of digits.</p>
|
||
</td></tr><tr class="module-item"><td><a class="fn" href="fn.run.html" title="ring::test::run fn">run</a></td><td class="docblock-short"><p>Parses test cases out of the given file, calling <code>f</code> on each vector until
|
||
<code>f</code> fails or until all the test vectors have been read. <code>f</code> can indicate
|
||
failure either by returning <code>Err()</code> or by panicking.</p>
|
||
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="ring"></div>
|
||
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html> |