Skip to content

Commit 54f2147

Browse files
committed
Get unit tests for rusti working
* They didn't work before, because the location of the tests caused the 'sysroot' option to crate lookup to be wrong for finding the correct stage's core/std libraries. This moves the compiled tests from the $host/test directory into a $host/$stage/test directory. This means that the sysroot will be correct and the core/std libraries can actually be found * The LLVM bindings apparently aren't threadsafe, so we can't run multiple tests in parallel.
1 parent 767e3ae commit 54f2147

File tree

3 files changed

+64
-14
lines changed

3 files changed

+64
-14
lines changed

configure

Lines changed: 3 additions & 0 deletions
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

mk/tests.mk

Lines changed: 11 additions & 11 deletions
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

src/librusti/rusti.rc

Lines changed: 50 additions & 3 deletions
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,
@@ -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,50 @@ 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 super_simple() {
441+
let mut r = repl();
442+
let result = run_line(&mut r, io::stdin(), io::stdout(), ~"", false);
443+
result.expect("empty input shouldn't fail in rusti");
444+
}
445+
446+
fn use_does_not_crash() {
447+
let mut r = repl();
448+
let result = run_line(&mut r, io::stdin(), io::stdout(),
449+
~"use core::util::with;", false);
450+
r = result.expect("use statements should't fail in rusti");
451+
let result = run_line(&mut r, io::stdin(), io::stdout(),
452+
~"", false);
453+
result.expect("something should be able to happen after a use statement");
454+
}
455+
456+
#[test]
457+
fn run_all() {
458+
// By default, unit tests are run in parallel. Rusti, on the other hand,
459+
// does not enjoy doing this. I suspect that it is because the LLVM
460+
// bindings are not thread-safe (when running parallel tests, some tests
461+
// were triggering assertions in LLVM (or segfaults). Hence, this
462+
// function exists to run everything serially (sadface).
463+
//
464+
// To get some interesting output, run with RUST_LOG=rusti::tests
465+
466+
debug!("super_simple"); super_simple();
467+
debug!("use_does_not_crash"); use_does_not_crash();
468+
469+
}
470+
}

0 commit comments

Comments
 (0)