Skip to content

Commit 06c46d5

Browse files
committed
auto merge of #6467 : alexcrichton/rust/better-rusti, r=bstrie
These few commits address a few existing issues: * #5469 - adding regression tests for `rusti`. This adds unit tests to the `rusti.rc` file (which needed some reorganization of the Makefile, see the first commit message). These are super-simple right now, and sadly can't test the output of the tests. I worked for a bit on making a compiletest version of the rusti tests, but I ended up hitting something which blocked me, although I've forgotten it by this point. * #5937 - regression test added, and it's fixed * #5803 - just doesn't appear to happen any more * #5784 - it's no longer broken, and it no longer spits out warnings about unused variables. I also did some investigation into #5774, and you may want to read the comment I left on the bug. The gist of the situation is that C++ exceptions across JIT code don't look like they're working, even though they [should be working](https://github.com/mozilla/rust/blob/3aa1122ec25d15a2a73a295f8298ad9c38b09a10/src/rustllvm/RustWrapper.cpp#L387). If anyone has any insight on this, that would be awesome!
2 parents 767e3ae + 2ab1da5 commit 06c46d5

File tree

5 files changed

+71
-19
lines changed

5 files changed

+71
-19
lines changed

Diff for: configure

+3
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ do
695695
# host lib dir
696696
make_dir $h/stage$i/$CFG_LIBDIR
697697

698+
# host test dir
699+
make_dir $h/stage$i/test
700+
698701
# target bin dir
699702
make_dir $h/stage$i/$CFG_LIBDIR/rustc/$t/bin
700703

Diff for: mk/tests.mk

+11-11
Original file line numberDiff line numberDiff line change
@@ -289,50 +289,50 @@ else
289289
STDTESTDEP_$(1)_$(2)_$(3) =
290290
endif
291291

292-
$(3)/test/coretest.stage$(1)-$(2)$$(X_$(2)): \
292+
$(3)/stage$(1)/test/coretest-$(2)$$(X_$(2)): \
293293
$$(CORELIB_CRATE) $$(CORELIB_INPUTS) \
294294
$$(STDTESTDEP_$(1)_$(2)_$(3))
295295
@$$(call E, compile_and_link: $$@)
296296
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
297297

298-
$(3)/test/stdtest.stage$(1)-$(2)$$(X_$(2)): \
298+
$(3)/stage$(1)/test/stdtest-$(2)$$(X_$(2)): \
299299
$$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
300300
$$(STDTESTDEP_$(1)_$(2)_$(3))
301301
@$$(call E, compile_and_link: $$@)
302302
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
303303

304-
$(3)/test/syntaxtest.stage$(1)-$(2)$$(X_$(2)): \
304+
$(3)/stage$(1)/test/syntaxtest-$(2)$$(X_$(2)): \
305305
$$(LIBSYNTAX_CRATE) $$(LIBSYNTAX_INPUTS) \
306306
$$(STDTESTDEP_$(1)_$(2)_$(3))
307307
@$$(call E, compile_and_link: $$@)
308308
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
309309

310-
$(3)/test/rustctest.stage$(1)-$(2)$$(X_$(2)): \
310+
$(3)/stage$(1)/test/rustctest-$(2)$$(X_$(2)): \
311311
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
312312
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM_$(2)) \
313313
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX_$(2))
314314
@$$(call E, compile_and_link: $$@)
315315
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
316316

317-
$(3)/test/rustpkgtest.stage$(1)-$(2)$$(X_$(2)): \
317+
$(3)/stage$(1)/test/rustpkgtest-$(2)$$(X_$(2)): \
318318
$$(RUSTPKG_LIB) $$(RUSTPKG_INPUTS) \
319319
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
320320
@$$(call E, compile_and_link: $$@)
321321
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
322322

323-
$(3)/test/rustitest.stage$(1)-$(2)$$(X_$(2)): \
323+
$(3)/stage$(1)/test/rustitest-$(2)$$(X_$(2)): \
324324
$$(RUSTI_LIB) $$(RUSTI_INPUTS) \
325325
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
326326
@$$(call E, compile_and_link: $$@)
327327
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
328328

329-
$(3)/test/rusttest.stage$(1)-$(2)$$(X_$(2)): \
329+
$(3)/stage$(1)/test/rusttest-$(2)$$(X_$(2)): \
330330
$$(RUST_LIB) $$(RUST_INPUTS) \
331331
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
332332
@$$(call E, compile_and_link: $$@)
333333
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test
334334

335-
$(3)/test/rustdoctest.stage$(1)-$(2)$$(X_$(2)): \
335+
$(3)/stage$(1)/test/rustdoctest-$(2)$$(X_$(2)): \
336336
$$(RUSTDOC_LIB) $$(RUSTDOC_INPUTS) \
337337
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
338338
@$$(call E, compile_and_link: $$@)
@@ -349,7 +349,7 @@ define DEF_TEST_CRATE_RULES
349349
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
350350

351351
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
352-
$(3)/test/$(4)test.stage$(1)-$(2)$$(X_$(2))
352+
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
353353
@$$(call E, run: $$<)
354354
$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(2),$(3)) $$(TESTARGS) \
355355
--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
@@ -360,7 +360,7 @@ define DEF_TEST_CRATE_RULES_arm-linux-androideabi
360360
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
361361

362362
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
363-
$(3)/test/$(4)test.stage$(1)-$(2)$$(X_$(2))
363+
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
364364
@$$(call E, run: $$< via adb)
365365
@$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
366366
@$(CFG_ADB) shell LD_LIBRARY_PATH=$(CFG_ADB_TEST_DIR) \
@@ -385,7 +385,7 @@ define DEF_TEST_CRATE_RULES_null
385385
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
386386

387387
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
388-
$(3)/test/$(4)test.stage$(1)-$(2)$$(X_$(2))
388+
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
389389
@$$(call E, run: skipped $$< )
390390
@touch $$@
391391
endef

Diff for: src/librusti/rusti.rc

+53-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use std::rl;
3535
* A structure shared across REPL instances for storing history
3636
* such as statements and view items. I wish the AST was sendable.
3737
*/
38-
struct Repl {
38+
pub struct Repl {
3939
prompt: ~str,
4040
binary: ~str,
4141
running: bool,
@@ -122,7 +122,7 @@ fn run(repl: Repl, input: ~str) -> Repl {
122122

123123
debug!("building driver input");
124124
let head = include_str!("wrapper.rs").to_owned();
125-
let foot = fmt!("%s\nfn main() {\n%s\n\nprint({\n%s\n})\n}",
125+
let foot = fmt!("fn main() {\n%s\n%s\n\nprint({\n%s\n})\n}",
126126
repl.view_items, repl.stmts, input);
127127
let wrapped = driver::str_input(head + foot);
128128

@@ -328,8 +328,8 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
328328

329329
/// Executes a line of input, which may either be rust code or a
330330
/// :command. Returns a new Repl if it has changed.
331-
fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str,
332-
use_rl: bool)
331+
pub fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str,
332+
use_rl: bool)
333333
-> Option<Repl> {
334334
if line.starts_with(":") {
335335
let full = line.substr(1, line.len() - 1);
@@ -421,3 +421,52 @@ pub fn main() {
421421
}
422422
}
423423
}
424+
425+
#[cfg(test)]
426+
mod tests {
427+
use super::*;
428+
429+
fn repl() -> Repl {
430+
Repl {
431+
prompt: ~"rusti> ",
432+
binary: ~"rusti",
433+
running: true,
434+
view_items: ~"",
435+
lib_search_paths: ~[],
436+
stmts: ~""
437+
}
438+
}
439+
440+
fn run_cmds(cmds: &[&str]) {
441+
let mut r = repl();
442+
for cmds.each |&cmd| {
443+
let result = run_line(&mut r, io::stdin(), io::stdout(),
444+
cmd.to_owned(), false);
445+
r = result.expect(fmt!("the command '%s' failed", cmd));
446+
}
447+
}
448+
449+
#[test]
450+
fn run_all() {
451+
// By default, unit tests are run in parallel. Rusti, on the other hand,
452+
// does not enjoy doing this. I suspect that it is because the LLVM
453+
// bindings are not thread-safe (when running parallel tests, some tests
454+
// were triggering assertions in LLVM (or segfaults). Hence, this
455+
// function exists to run everything serially (sadface).
456+
//
457+
// To get some interesting output, run with RUST_LOG=rusti::tests
458+
459+
debug!("hopefully this runs");
460+
run_cmds([""]);
461+
462+
debug!("regression test for #5937");
463+
run_cmds(["use core;", ""]);
464+
465+
debug!("regression test for #5784");
466+
run_cmds(["let a = 1;"]);
467+
468+
debug!("regression test for #5803");
469+
run_cmds(["spawn( || println(\"Please don't segfault\") );",
470+
"do spawn { println(\"Please?\"); }"]);
471+
}
472+
}

Diff for: src/librusti/wrapper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#[allow(unrecognized_lint)];
1919
#[allow(unused_imports)];
2020
#[allow(while_true)];
21-
#[allow(dead_assignment)];
2221
#[allow(unused_variable)];
22+
#[allow(dead_assignment)];
2323
#[allow(unused_unsafe)];
2424
#[allow(unused_mut)];
2525

Diff for: src/librustpkg/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ fn is_rwx(p: &Path) -> bool {
7979

8080
fn test_sysroot() -> Path {
8181
// Totally gross hack but it's just for test cases.
82-
// Infer the sysroot from the exe name and tack "stage2"
83-
// onto it. (Did I mention it was a gross hack?)
82+
// Infer the sysroot from the exe name and pray that it's right.
83+
// (Did I mention it was a gross hack?)
8484
let self_path = os::self_exe_path().expect("Couldn't get self_exe path");
85-
self_path.pop().push("stage2")
85+
self_path.pop()
8686
}
8787

8888
#[test]

0 commit comments

Comments
 (0)