Skip to content

Commit d2482fd

Browse files
committed
use find not echo; this also brings fuzzer under the iron fist of tidy.py!
1 parent 27f1c2b commit d2482fd

File tree

7 files changed

+94
-76
lines changed

7 files changed

+94
-76
lines changed

mk/tests.mk

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
# Testing variables
33
######################################################################
44

5-
SOME_TEST_INPUTS = $(wildcard $(S)src/test/*/*.rs)
6-
7-
SOME_MOAR_TEST_INPUTS = $(wildcard $(S)src/test/*/*/*.rs \
8-
$(S)src/test/*/*.rc)
9-
105
RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
116
RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
127
RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
@@ -124,34 +119,13 @@ ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
124119

125120
tidy:
126121
@$(call E, check: formatting)
127-
$(Q)echo \
128-
$(wildcard $(S)src/etc/*.py) \
129-
$(COMPILER_CRATE) \
130-
$(COMPILER_INPUTS) \
131-
$(LIBRUSTSYNTAX_CRATE) \
132-
$(LIBRUSTSYNTAX_INPUTS) \
133-
$(CORELIB_CRATE) \
134-
$(CORELIB_INPUTS) \
122+
$(Q)find $(S)src -name '*.r[sc]' \
135123
| xargs -n 10 python $(S)src/etc/tidy.py
136-
$(Q)echo \
137-
$(STDLIB_CRATE) \
138-
$(STDLIB_INPUTS) \
139-
$(COMPILETEST_CRATE) \
140-
$(COMPILETEST_INPUTS) \
141-
$(CARGO_CRATE) \
142-
$(CARGO_INPUTS) \
143-
$(RUSTDOC_CRATE) \
144-
$(RUSTDOC_INPUTS) \
124+
$(Q)find $(S)src/etc -name '*.py' \
145125
| xargs -n 10 python $(S)src/etc/tidy.py
146-
$(Q)echo \
147-
$(SOME_TEST_INPUTS) \
148-
| xargs -n 10 python $(S)src/etc/tidy.py
149-
$(Q)echo \
150-
$(SOME_MOAR_TEST_INPUTS) \
126+
$(Q)echo $(ALL_CS) \
151127
| xargs -n 10 python $(S)src/etc/tidy.py
152-
$(Q)echo \
153-
$(ALL_CS) \
154-
$(ALL_HS) \
128+
$(Q)echo $(ALL_HS) \
155129
| xargs -n 10 python $(S)src/etc/tidy.py
156130

157131
endif

src/fuzzer/ast_match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std;
22
import vec;
33

4-
fn vec_equal<T>(v: [T], u: [T], element_equality_test: fn@(&&T, &&T) -> bool) ->
4+
fn vec_equal<T>(v: [T], u: [T],
5+
element_equality_test: fn@(&&T, &&T) -> bool) ->
56
bool {
67
let Lv = vec::len(v);
78
if Lv != vec::len(u) { ret false; }

src/fuzzer/cycles.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import std::rand;
33
import uint::range;
44

55
// random uint less than n
6-
fn under(r : rand::rng, n : uint) -> uint { assert n != 0u; r.next() as uint % n }
6+
fn under(r : rand::rng, n : uint) -> uint {
7+
assert n != 0u; r.next() as uint % n
8+
}
79

810
// random choice from a vec
9-
fn choice<T: copy>(r : rand::rng, v : [const T]) -> T { assert vec::len(v) != 0u; v[under(r, vec::len(v))] }
11+
fn choice<T: copy>(r : rand::rng, v : [const T]) -> T {
12+
assert vec::len(v) != 0u; v[under(r, vec::len(v))]
13+
}
1014

1115
// k in n chance of being true
1216
fn likelihood(r : rand::rng, k : uint, n : uint) -> bool { under(r, n) < k }
@@ -68,7 +72,8 @@ fn test_cycles(r : rand::rng, k: uint, n: uint)
6872
if (likelihood(r, k, n)) { v[i].c = @p(choice(r, v)); }
6973

7074
if (likelihood(r, k, n)) { v[i].f = bind nopP(choice(r, v)); }
71-
//if (false) { v[i].g = bind (fn~(_x: @pointy) { })(choice(r, v)); }
75+
//if (false) { v[i].g = bind (fn~(_x: @pointy) { })(
76+
// choice(r, v)); }
7277
// https://github.com/mozilla/rust/issues/1899
7378

7479
if (likelihood(r, k, n)) { v[i].m = [p(choice(r, v))]; }

src/fuzzer/fuzzer.rs

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ fn common_exprs() -> [ast::expr] {
4444
[dse(ast::expr_break),
4545
dse(ast::expr_cont),
4646
dse(ast::expr_fail(option::none)),
47-
dse(ast::expr_fail(option::some(@dse(ast::expr_lit(@dsl(ast::lit_str("boo"))))))),
47+
dse(ast::expr_fail(option::some(
48+
@dse(ast::expr_lit(@dsl(ast::lit_str("boo"))))))),
4849
dse(ast::expr_ret(option::none)),
4950
dse(ast::expr_lit(@dsl(ast::lit_nil))),
5051
dse(ast::expr_lit(@dsl(ast::lit_bool(false)))),
@@ -64,9 +65,9 @@ pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool {
6465
alt tm {
6566
tm_converge {
6667
alt e.node {
67-
// If the fuzzer moves a block-ending-in-semicolon into callee position,
68-
// the pretty-printer can't preserve this even by parenthesizing!!
69-
// See email to marijn.
68+
// If the fuzzer moves a block-ending-in-semicolon into callee
69+
// position, the pretty-printer can't preserve this even by
70+
// parenthesizing!! See email to marijn.
7071
ast::expr_if(_, _, _) { false }
7172
ast::expr_if_check(_, _, _) { false }
7273
ast::expr_block(_) { false }
@@ -166,18 +167,21 @@ fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool {
166167
fn safe_to_replace_ty(t: ast::ty_, _tm: test_mode) -> bool {
167168
alt t {
168169
ast::ty_infer { false } // always implicit, always top level
169-
ast::ty_bot { false } // in source, can only appear as the out type of a function
170+
ast::ty_bot { false } // in source, can only appear
171+
// as the out type of a function
170172
ast::ty_mac(_) { false }
171173
_ { true }
172174
}
173175
}
174176

175177
// Replace the |i|th expr (in fold order) of |crate| with |newexpr|.
176-
fn replace_expr_in_crate(crate: ast::crate, i: uint, newexpr: ast::expr, tm: test_mode) ->
178+
fn replace_expr_in_crate(crate: ast::crate, i: uint,
179+
newexpr: ast::expr, tm: test_mode) ->
177180
ast::crate {
178181
let j: @mut uint = @mut 0u;
179182
fn fold_expr_rep(j_: @mut uint, i_: uint, newexpr_: ast::expr_,
180-
original: ast::expr_, fld: fold::ast_fold, tm_: test_mode) ->
183+
original: ast::expr_, fld: fold::ast_fold,
184+
tm_: test_mode) ->
181185
ast::expr_ {
182186
*j_ += 1u;
183187
if i_ + 1u == *j_ && safe_to_replace_expr(original, tm_) {
@@ -187,20 +191,22 @@ fn replace_expr_in_crate(crate: ast::crate, i: uint, newexpr: ast::expr, tm: tes
187191
}
188192
}
189193
let afp =
190-
{fold_expr: fold::wrap(bind fold_expr_rep(j, i, newexpr.node, _, _, tm))
191-
with *fold::default_ast_fold()};
194+
{fold_expr: fold::wrap(bind fold_expr_rep(j, i,
195+
newexpr.node, _, _, tm))
196+
with *fold::default_ast_fold()};
192197
let af = fold::make_fold(afp);
193198
let crate2: @ast::crate = @af.fold_crate(crate);
194199
*crate2
195200
}
196201

197202

198203
// Replace the |i|th ty (in fold order) of |crate| with |newty|.
199-
fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::ty, tm: test_mode) ->
200-
ast::crate {
204+
fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::ty,
205+
tm: test_mode) -> ast::crate {
201206
let j: @mut uint = @mut 0u;
202207
fn fold_ty_rep(j_: @mut uint, i_: uint, newty_: ast::ty_,
203-
original: ast::ty_, fld: fold::ast_fold, tm_: test_mode) ->
208+
original: ast::ty_, fld: fold::ast_fold,
209+
tm_: test_mode) ->
204210
ast::ty_ {
205211
*j_ += 1u;
206212
if i_ + 1u == *j_ && safe_to_replace_ty(original, tm_) {
@@ -233,8 +239,11 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
233239
let stolen = steal(crate, cx.mode);
234240
let extra_exprs = vec::filter(common_exprs(),
235241
bind safe_to_use_expr(_, cx.mode));
236-
check_variants_T(crate, codemap, filename, "expr", extra_exprs + stolen.exprs, pprust::expr_to_str, replace_expr_in_crate, cx);
237-
check_variants_T(crate, codemap, filename, "ty", stolen.tys, pprust::ty_to_str, replace_ty_in_crate, cx);
242+
check_variants_T(crate, codemap, filename, "expr",
243+
extra_exprs + stolen.exprs, pprust::expr_to_str,
244+
replace_expr_in_crate, cx);
245+
check_variants_T(crate, codemap, filename, "ty", stolen.tys,
246+
pprust::ty_to_str, replace_ty_in_crate, cx);
238247
}
239248

240249
fn check_variants_T<T: copy>(
@@ -247,7 +256,8 @@ fn check_variants_T<T: copy>(
247256
replacer: fn@(ast::crate, uint, T, test_mode) -> ast::crate,
248257
cx: context
249258
) {
250-
#error("%s contains %u %s objects", filename, vec::len(things), thing_label);
259+
#error("%s contains %u %s objects", filename,
260+
vec::len(things), thing_label);
251261

252262
let L = vec::len(things);
253263

@@ -257,8 +267,8 @@ fn check_variants_T<T: copy>(
257267
under(uint::min(L, 30u)) {|j|
258268
log(error, "With... " + stringifier(@things[j]));
259269
let crate2 = @replacer(crate, i, things[j], cx.mode);
260-
// It would be best to test the *crate* for stability, but testing the
261-
// string for stability is easier and ok for now.
270+
// It would be best to test the *crate* for stability, but
271+
// testing the string for stability is easier and ok for now.
262272
let handler = diagnostic::mk_handler(none);
263273
let str3 =
264274
@as_str(bind pprust::print_crate(
@@ -273,8 +283,11 @@ fn check_variants_T<T: copy>(
273283
check_roundtrip_convergence(str3, 1u);
274284
}
275285
tm_run {
276-
let file_label = #fmt("rusttmp/%s_%s_%u_%u", last_part(filename), thing_label, i, j);
277-
let safe_to_run = !(content_is_dangerous_to_run(*str3) || has_raw_pointers(*crate2));
286+
let file_label = #fmt("rusttmp/%s_%s_%u_%u",
287+
last_part(filename),
288+
thing_label, i, j);
289+
let safe_to_run = !(content_is_dangerous_to_run(*str3)
290+
|| has_raw_pointers(*crate2));
278291
check_whole_compiler(*str3, file_label, safe_to_run);
279292
}
280293
}
@@ -292,9 +305,11 @@ enum happiness { passed, cleanly_rejected(str), known_bug(str), failed(str), }
292305

293306
// We'd find more bugs if we could take an AST here, but
294307
// - that would find many "false positives" or unimportant bugs
295-
// - that would be tricky, requiring use of tasks or serialization or randomness.
308+
// - that would be tricky, requiring use of tasks or serialization
309+
// or randomness.
296310
// This seems to find plenty of bugs as it is :)
297-
fn check_whole_compiler(code: str, suggested_filename_prefix: str, allow_running: bool) {
311+
fn check_whole_compiler(code: str, suggested_filename_prefix: str,
312+
allow_running: bool) {
298313
let filename = suggested_filename_prefix + ".rs";
299314
write_file(filename, code);
300315

@@ -331,7 +346,9 @@ fn removeDirIfExists(filename: str) {
331346
}
332347

333348
fn check_running(exe_filename: str) -> happiness {
334-
let p = run::program_output("/Users/jruderman/scripts/timed_run_rust_program.py", [exe_filename]);
349+
let p = run::program_output(
350+
"/Users/jruderman/scripts/timed_run_rust_program.py",
351+
[exe_filename]);
335352
let comb = p.out + "\n" + p.err;
336353
if str::len(comb) > 1u {
337354
log(error, "comb comb comb: " + comb);
@@ -352,17 +369,26 @@ fn check_running(exe_filename: str) -> happiness {
352369
0 { passed }
353370
100 { cleanly_rejected("running: explicit fail") }
354371
101 | 247 { cleanly_rejected("running: timed out") }
355-
245 | 246 | 138 | 252 { known_bug("https://github.com/mozilla/rust/issues/1466") }
356-
136 | 248 { known_bug("SIGFPE - https://github.com/mozilla/rust/issues/944") }
357-
rc { failed("Rust program ran but exited with status " + int::str(rc)) }
372+
245 | 246 | 138 | 252 {
373+
known_bug("https://github.com/mozilla/rust/issues/1466")
374+
}
375+
136 | 248 {
376+
known_bug(
377+
"SIGFPE - https://github.com/mozilla/rust/issues/944")
378+
}
379+
rc {
380+
failed("Rust program ran but exited with status " +
381+
int::str(rc))
382+
}
358383
}
359384
}
360385
}
361386

362387
fn check_compiling(filename: str) -> happiness {
363388
let p = run::program_output(
364-
"/Users/jruderman/code/rust/build/x86_64-apple-darwin/stage1/bin/rustc",
365-
[filename]);
389+
"/Users/jruderman/code/rust/build/x86_64-apple-darwin/\
390+
stage1/bin/rustc",
391+
[filename]);
366392

367393
//#error("Status: %d", p.status);
368394
if p.status == 0 {
@@ -454,10 +480,11 @@ fn content_might_not_converge(code: str) -> bool {
454480
let confusing_patterns =
455481
["xfail-test",
456482
"xfail-pretty",
457-
"self", // crazy rules enforced by parser rather than typechecker?
483+
"self", // crazy rules enforced by parser not typechecker?
458484
"spawn", // precedence issues?
459485
"bind", // precedence issues?
460-
" be ", // don't want to replace its child with a non-call: "Non-call expression in tail call"
486+
" be ", // don't want to replace its child with a non-call:
487+
// "Non-call expression in tail call"
461488
"\n\n\n\n\n" // https://github.com/mozilla/rust/issues/850
462489
];
463490

@@ -467,7 +494,8 @@ fn content_might_not_converge(code: str) -> bool {
467494

468495
fn file_might_not_converge(filename: str) -> bool {
469496
let confusing_files = [
470-
"expr-alt.rs", // pretty-printing "(a = b) = c" vs "a = b = c" and wrapping
497+
"expr-alt.rs", // pretty-printing "(a = b) = c"
498+
// vs "a = b = c" and wrapping
471499
"block-arg-in-ternary.rs", // wrapping
472500
"move-3-unique.rs", // 0 becomes (0), but both seem reasonable. wtf?
473501
"move-3.rs" // 0 becomes (0), but both seem reasonable. wtf?
@@ -513,7 +541,8 @@ fn check_convergence(files: [str]) {
513541
let s = @result::get(io::read_whole_file_str(file));
514542
if !content_might_not_converge(*s) {
515543
#error("pp converge: %s", file);
516-
// Change from 7u to 2u once https://github.com/mozilla/rust/issues/850 is fixed
544+
// Change from 7u to 2u once
545+
// https://github.com/mozilla/rust/issues/850 is fixed
517546
check_roundtrip_convergence(s, 7u);
518547
}
519548
}
@@ -523,7 +552,8 @@ fn check_convergence(files: [str]) {
523552
fn check_variants(files: [str], cx: context) {
524553
for files.each {|file|
525554
if cx.mode == tm_converge && file_might_not_converge(file) {
526-
#error("Skipping convergence test based on file_might_not_converge");
555+
#error("Skipping convergence test based on\
556+
file_might_not_converge");
527557
cont;
528558
}
529559

src/fuzzer/ivec_fuzz.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
33
Idea: provide functions for 'exhaustive' and 'random' modification of vecs.
44
5-
two functions, "return all edits" and "return a random edit" <-- leaning toward this model
6-
or
7-
two functions, "return the number of possible edits" and "return edit #n"
5+
two functions, "return all edits" and "return a random edit" <--
6+
leaning toward this model or two functions, "return the number of
7+
possible edits" and "return edit #n"
88
9-
It would be nice if this could be data-driven, so the two functions could share information:
9+
It would be nice if this could be data-driven, so the two functions
10+
could share information:
1011
type vec_modifier = rec(fn (<T> v, uint i) -> [T] fun, uint lo, uint di);
1112
const [vec_modifier] vec_modifiers = ~[rec(fun=vec_omit, 0u, 1u), ...];
12-
But that gives me "error: internal compiler error unimplemented consts that's not a plain literal".
13+
But that gives me "error: internal compiler error unimplemented consts
14+
that's not a plain literal".
1315
https://github.com/graydon/rust/issues/570
1416
1517
vec_edits is not an iter because iters might go away.
@@ -47,7 +49,8 @@ fn ix(skip_low: uint, skip_high: uint, length: uint, it: block(uint)) {
4749
while i + skip_high <= length { it(i); i += 1u; }
4850
}
4951

50-
// Returns a bunch of modified versions of v, some of which introduce new elements (borrowed from xs).
52+
// Returns a bunch of modified versions of v, some of which introduce
53+
// new elements (borrowed from xs).
5154
fn vec_edits<T: copy>(v: [T], xs: [T]) -> [[T]] {
5255
let edits: [[T]] = [];
5356
let Lv: uint = len(v);
@@ -78,7 +81,8 @@ fn vec_edits<T: copy>(v: [T], xs: [T]) -> [[T]] {
7881
edits
7982
}
8083

81-
// Would be nice if this were built in: https://github.com/graydon/rust/issues/424
84+
// Would be nice if this were built in:
85+
// https://github.com/graydon/rust/issues/424
8286
fn vec_to_str(v: [int]) -> str {
8387
let i = 0u;
8488
let s = "[";

src/fuzzer/rand_util.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import std::rand;
33
import vec;
44

55
// random uint less than n
6-
fn under(r : rand::rng, n : uint) -> uint { assert n != 0u; r.next() as uint % n }
6+
fn under(r : rand::rng, n : uint) -> uint {
7+
assert n != 0u; r.next() as uint % n
8+
}
79

810
// random choice from a vec
9-
fn choice<T: copy>(r : rand::rng, v : [T]) -> T { assert vec::len(v) != 0u; v[under(r, vec::len(v))] }
11+
fn choice<T: copy>(r : rand::rng, v : [T]) -> T {
12+
assert vec::len(v) != 0u; v[under(r, vec::len(v))]
13+
}
1014

1115
// 1 in n chance of being true
1216
fn unlikely(r : rand::rng, n : uint) -> bool { under(r, n) == 0u }

src/rustc/driver/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Options:
4848
--out-dir <dir> Write output to compiler-chosen filename in <dir>
4949
--parse-only Parse only; do not compile, assemble, or link
5050
--pretty [type] Pretty-print the input instead of compiling;
51-
valid types are: normal (un-annotated source),
51+
valid types are: normal (un-annotated source),
5252
expanded (crates expanded), typed (crates expanded,
5353
with type annotations), or identified (fully
5454
parenthesized, AST nodes and blocks with IDs)

0 commit comments

Comments
 (0)