Skip to content

Commit 791ef03

Browse files
committed
---
yaml --- r: 152701 b: refs/heads/try2 c: 311890c h: refs/heads/master i: 152699: f39d3d0 v: v3
1 parent 030260d commit 791ef03

File tree

12 files changed

+192
-112
lines changed

12 files changed

+192
-112
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: e698a397a8e4ffe545376571c01e413088d9049a
8+
refs/heads/try2: 311890ccfe08af8b0153510b6cfbc33f9a13d102
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/guide-testing.md

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
To create test functions, add a `#[test]` attribute like this:
66

7-
~~~
7+
~~~test_harness
88
fn return_two() -> int {
99
2
1010
}
@@ -37,7 +37,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
3737
Rust has built in support for simple unit testing. Functions can be
3838
marked as unit tests using the `test` attribute.
3939

40-
~~~
40+
~~~test_harness
4141
#[test]
4242
fn return_none_if_empty() {
4343
// ... test code ...
@@ -55,7 +55,7 @@ other (`assert_eq`, ...) means, then the test fails.
5555
When compiling a crate with the `--test` flag `--cfg test` is also
5656
implied, so that tests can be conditionally compiled.
5757

58-
~~~
58+
~~~test_harness
5959
#[cfg(test)]
6060
mod tests {
6161
#[test]
@@ -80,11 +80,11 @@ Tests that are intended to fail can be annotated with the
8080
task to fail then the test will be counted as successful; otherwise it
8181
will be counted as a failure. For example:
8282

83-
~~~
83+
~~~test_harness
8484
#[test]
8585
#[should_fail]
8686
fn test_out_of_bounds_failure() {
87-
let v: [int] = [];
87+
let v: &[int] = [];
8888
v[0];
8989
}
9090
~~~
@@ -204,26 +204,22 @@ amount.
204204

205205
For example:
206206

207-
~~~
208-
# #![allow(unused_imports)]
207+
~~~test_harness
209208
extern crate test;
210209
211-
use std::slice;
212210
use test::Bencher;
213211
214212
#[bench]
215213
fn bench_sum_1024_ints(b: &mut Bencher) {
216-
let v = slice::from_fn(1024, |n| n);
217-
b.iter(|| {v.iter().fold(0, |old, new| old + *new);} );
214+
let v = Vec::from_fn(1024, |n| n);
215+
b.iter(|| v.iter().fold(0, |old, new| old + *new));
218216
}
219217
220218
#[bench]
221219
fn initialise_a_vector(b: &mut Bencher) {
222-
b.iter(|| {slice::from_elem(1024, 0u64);} );
220+
b.iter(|| Vec::from_elem(1024, 0u64));
223221
b.bytes = 1024 * 8;
224222
}
225-
226-
# fn main() {}
227223
~~~
228224

229225
The benchmark runner will calibrate measurement of the benchmark
@@ -266,19 +262,16 @@ benchmarking what one expects. For example, the compiler might
266262
recognize that some calculation has no external effects and remove
267263
it entirely.
268264

269-
~~~
270-
# #![allow(unused_imports)]
265+
~~~test_harness
271266
extern crate test;
272267
use test::Bencher;
273268
274269
#[bench]
275270
fn bench_xor_1000_ints(b: &mut Bencher) {
276271
b.iter(|| {
277-
range(0, 1000).fold(0, |old, new| old ^ new);
278-
});
272+
range(0, 1000).fold(0, |old, new| old ^ new);
273+
});
279274
}
280-
281-
# fn main() {}
282275
~~~
283276

284277
gives the following results
@@ -297,8 +290,11 @@ cannot remove the computation entirely. This could be done for the
297290
example above by adjusting the `bh.iter` call to
298291

299292
~~~
300-
# struct X; impl X { fn iter<T>(&self, _: || -> T) {} } let bh = X;
301-
bh.iter(|| range(0, 1000).fold(0, |old, new| old ^ new))
293+
# struct X; impl X { fn iter<T>(&self, _: || -> T) {} } let b = X;
294+
b.iter(|| {
295+
// note lack of `;` (could also use an explicit `return`).
296+
range(0, 1000).fold(0, |old, new| old ^ new)
297+
});
302298
~~~
303299

304300
Or, the other option is to call the generic `test::black_box`
@@ -309,10 +305,10 @@ forces it to consider any argument as used.
309305
extern crate test;
310306
311307
# fn main() {
312-
# struct X; impl X { fn iter<T>(&self, _: || -> T) {} } let bh = X;
313-
bh.iter(|| {
314-
test::black_box(range(0, 1000).fold(0, |old, new| old ^ new));
315-
});
308+
# struct X; impl X { fn iter<T>(&self, _: || -> T) {} } let b = X;
309+
b.iter(|| {
310+
test::black_box(range(0, 1000).fold(0, |old, new| old ^ new));
311+
});
316312
# }
317313
~~~
318314

branches/try2/src/doc/index.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,26 @@ li {list-style-type: none; }
6767

6868
* [The `rustdoc` manual](rustdoc.html)
6969

70-
# External resources
70+
# External documentation
7171

72-
* The Rust IRC channels on [irc.mozilla.org](http://irc.mozilla.org/)
72+
*Note: While these are great resources for learning Rust, they may
73+
track a particular version of Rust that is likely not exactly the same
74+
as that for which this documentation was generated.*
75+
76+
* [Rust for Rubyists] - An excellent introduction for Rust; not just for Rubyists (tracks the most recent release).
77+
* [Rust by Example] - Short examples of common tasks in Rust (tracks the master branch).
78+
* [The Rust wiki](http://github.com/rust-lang/rust/wiki)
79+
80+
[Rust for Rubyists]: http://www.rustforrubyists.com/
81+
[Rust by Example]: http://rustbyexample.com/
82+
83+
# Community
84+
85+
* [Reddit](http://reddit.com/r/rust)
86+
* [Stack Overflow](http://stackoverflow.com/questions/tagged/rust)
87+
* The Rust IRC channels on [irc.mozilla.org](http://irc.mozilla.org/):
7388
* [`#rust`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust) - general discussion
7489
* [`#rust-gamedev`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-gamedev) - game development
7590
* [`#rust-internals`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-internals) - compiler and libraries
7691
* [`#rust-osdev`](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust-osdev) - operating system development
77-
* The Rust community on [Reddit](http://reddit.com/r/rust)
78-
* The Rust [wiki](http://github.com/rust-lang/rust/wiki)
92+

branches/try2/src/doc/rustdoc.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ You can specify that the code block should be compiled but not run with the
171171
```
172172
~~~
173173

174+
Lastly, you can specify that a code block be compiled as if `--test`
175+
were passed to the compiler using the `test_harness` directive.
176+
177+
~~~md
178+
```test_harness
179+
#[test]
180+
fn foo() {
181+
fail!("oops! (will run & register as failure)")
182+
}
183+
```
184+
~~~
185+
174186
Rustdoc also supplies some extra sugar for helping with some tedious
175187
documentation examples. If a line is prefixed with `# `, then the line
176188
will not show up in the HTML documentation, but it will be used when

branches/try2/src/librustdoc/html/layout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ r##"<!DOCTYPE html>
6363
<div class="search-container">
6464
<input class="search-input" name="search"
6565
autocomplete="off"
66-
placeholder="Click or press 's' to search, '?' for more options..."
66+
placeholder="Click or press 'S' to search, '?' for more options..."
6767
type="search">
6868
</div>
6969
</form>
@@ -82,9 +82,9 @@ r##"<!DOCTYPE html>
8282
<dd>Show this help dialog</dd>
8383
<dt>S</dt>
8484
<dd>Focus the search field</dd>
85-
<dt>&uarr;</dt>
85+
<dt>&larrb;</dt>
8686
<dd>Move up in search results</dd>
87-
<dt>&darr;</dt>
87+
<dt>&rarrb;</dt>
8888
<dd>Move down in search results</dd>
8989
<dt>&#9166;</dt>
9090
<dd>Go to active search result</dd>

branches/try2/src/librustdoc/html/markdown.rs

Lines changed: 76 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
174174
slice::raw::buf_as_slice((*lang).data,
175175
(*lang).size as uint, |rlang| {
176176
let rlang = str::from_utf8(rlang).unwrap();
177-
let (_,_,_,notrust) = parse_lang_string(rlang);
178-
if notrust {
177+
if LangString::parse(rlang).notrust {
179178
(my_opaque.dfltblk)(ob, &buf, lang,
180179
opaque as *mut libc::c_void);
181180
true
@@ -196,7 +195,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
196195
stripped_filtered_line(l).unwrap_or(l)
197196
}).collect::<Vec<&str>>().connect("\n");
198197
let krate = krate.as_ref().map(|s| s.as_slice());
199-
let test = test::maketest(test.as_slice(), krate, false);
198+
let test = test::maketest(test.as_slice(), krate, false, false);
200199
s.push_str(format!("<span id='rust-example-raw-{}' \
201200
class='rusttest'>{}</span>",
202201
i, Escape(test.as_slice())).as_slice());
@@ -309,16 +308,16 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
309308
lang: *hoedown_buffer, opaque: *mut libc::c_void) {
310309
unsafe {
311310
if text.is_null() { return }
312-
let (should_fail, no_run, ignore, notrust) = if lang.is_null() {
313-
(false, false, false, false)
311+
let block_info = if lang.is_null() {
312+
LangString::all_false()
314313
} else {
315314
slice::raw::buf_as_slice((*lang).data,
316315
(*lang).size as uint, |lang| {
317316
let s = str::from_utf8(lang).unwrap();
318-
parse_lang_string(s)
317+
LangString::parse(s)
319318
})
320319
};
321-
if notrust { return }
320+
if block_info.notrust { return }
322321
slice::raw::buf_as_slice((*text).data, (*text).size as uint, |text| {
323322
let opaque = opaque as *mut hoedown_html_renderer_state;
324323
let tests = &mut *((*opaque).opaque as *mut ::test::Collector);
@@ -327,7 +326,9 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
327326
stripped_filtered_line(l).unwrap_or(l)
328327
});
329328
let text = lines.collect::<Vec<&str>>().connect("\n");
330-
tests.add_test(text.to_string(), should_fail, no_run, ignore);
329+
tests.add_test(text.to_string(),
330+
block_info.should_fail, block_info.no_run,
331+
block_info.ignore, block_info.test_harness);
331332
})
332333
}
333334
}
@@ -365,33 +366,52 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
365366
}
366367
}
367368

368-
fn parse_lang_string(string: &str) -> (bool,bool,bool,bool) {
369-
let mut seen_rust_tags = false;
370-
let mut seen_other_tags = false;
371-
let mut should_fail = false;
372-
let mut no_run = false;
373-
let mut ignore = false;
374-
let mut notrust = false;
375-
376-
let mut tokens = string.as_slice().split(|c: char|
377-
!(c == '_' || c == '-' || c.is_alphanumeric())
378-
);
379-
380-
for token in tokens {
381-
match token {
382-
"" => {},
383-
"should_fail" => { should_fail = true; seen_rust_tags = true; },
384-
"no_run" => { no_run = true; seen_rust_tags = true; },
385-
"ignore" => { ignore = true; seen_rust_tags = true; },
386-
"notrust" => { notrust = true; seen_rust_tags = true; },
387-
"rust" => { notrust = false; seen_rust_tags = true; },
388-
_ => { seen_other_tags = true }
369+
#[deriving(Eq, PartialEq, Clone, Show)]
370+
struct LangString {
371+
should_fail: bool,
372+
no_run: bool,
373+
ignore: bool,
374+
notrust: bool,
375+
test_harness: bool,
376+
}
377+
378+
impl LangString {
379+
fn all_false() -> LangString {
380+
LangString {
381+
should_fail: false,
382+
no_run: false,
383+
ignore: false,
384+
notrust: false,
385+
test_harness: false,
389386
}
390387
}
391388

392-
let notrust = notrust || (seen_other_tags && !seen_rust_tags);
389+
fn parse(string: &str) -> LangString {
390+
let mut seen_rust_tags = false;
391+
let mut seen_other_tags = false;
392+
let mut data = LangString::all_false();
393+
394+
let mut tokens = string.as_slice().split(|c: char|
395+
!(c == '_' || c == '-' || c.is_alphanumeric())
396+
);
397+
398+
for token in tokens {
399+
match token {
400+
"" => {},
401+
"should_fail" => { data.should_fail = true; seen_rust_tags = true; },
402+
"no_run" => { data.no_run = true; seen_rust_tags = true; },
403+
"ignore" => { data.ignore = true; seen_rust_tags = true; },
404+
"notrust" => { data.notrust = true; seen_rust_tags = true; },
405+
"rust" => { data.notrust = false; seen_rust_tags = true; },
406+
"test_harness" => { data.test_harness = true; seen_rust_tags = true; }
407+
_ => { seen_other_tags = true }
408+
}
409+
}
410+
411+
data.notrust |= seen_other_tags && !seen_rust_tags;
393412

394-
(should_fail, no_run, ignore, notrust)
413+
data
414+
}
395415
}
396416

397417
/// By default this markdown renderer generates anchors for each header in the
@@ -425,19 +445,32 @@ impl<'a> fmt::Show for MarkdownWithToc<'a> {
425445

426446
#[cfg(test)]
427447
mod tests {
428-
use super::parse_lang_string;
448+
use super::LangString;
429449

430450
#[test]
431-
fn test_parse_lang_string() {
432-
assert_eq!(parse_lang_string(""), (false,false,false,false))
433-
assert_eq!(parse_lang_string("rust"), (false,false,false,false))
434-
assert_eq!(parse_lang_string("sh"), (false,false,false,true))
435-
assert_eq!(parse_lang_string("notrust"), (false,false,false,true))
436-
assert_eq!(parse_lang_string("ignore"), (false,false,true,false))
437-
assert_eq!(parse_lang_string("should_fail"), (true,false,false,false))
438-
assert_eq!(parse_lang_string("no_run"), (false,true,false,false))
439-
assert_eq!(parse_lang_string("{.no_run .example}"), (false,true,false,false))
440-
assert_eq!(parse_lang_string("{.sh .should_fail}"), (true,false,false,false))
441-
assert_eq!(parse_lang_string("{.example .rust}"), (false,false,false,false))
451+
fn test_lang_string_parse() {
452+
fn t(s: &str,
453+
should_fail: bool, no_run: bool, ignore: bool, notrust: bool, test_harness: bool) {
454+
assert_eq!(LangString::parse(s), LangString {
455+
should_fail: should_fail,
456+
no_run: no_run,
457+
ignore: ignore,
458+
notrust: notrust,
459+
test_harness: test_harness,
460+
})
461+
}
462+
463+
t("", false,false,false,false,false);
464+
t("rust", false,false,false,false,false);
465+
t("sh", false,false,false,true,false);
466+
t("notrust", false,false,false,true,false);
467+
t("ignore", false,false,true,false,false);
468+
t("should_fail", true,false,false,false,false);
469+
t("no_run", false,true,false,false,false);
470+
t("test_harness", false,false,false,false,true);
471+
t("{.no_run .example}", false,true,false,false,false);
472+
t("{.sh .should_fail}", true,false,false,false,false);
473+
t("{.example .rust}", false,false,false,false,false);
474+
t("{.test_harness .rust}", false,false,false,false,true);
442475
}
443476
}

branches/try2/src/librustdoc/html/static/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ p a:hover { text-decoration: underline; }
347347
margin-top: -125px;
348348
margin-left: -275px;
349349
width: 550px;
350-
height: 250px;
350+
height: 300px;
351351
border: 1px solid #bfbfbf;
352352
}
353353

0 commit comments

Comments
 (0)