rustllvm \
dl stage0 stage1 stage2 stage3 \
stage0/lib stage1/lib stage2/lib stage3/lib \
- test/run-pass test/run-fail test/compile-fail \
- test/bench/99-bottles test/bench/shootout test/bench/task-perf
+ test/run-pass test/run-fail test/compile-fail test/bench
do
make_dir $i
done
$(Q)rm -f rt/$(CFG_RUNTIME)
$(Q)rm -f rt/main.o
$(Q)rm -f rt/main.ll
+ $(Q)rm -f test/run_pass_stage2.rc test/run_pass_stage2_driver.rs
$(Q)rm -Rf $(PKG_NAME)-*.tar.gz dist
$(Q)rm -f $(foreach ext,o a d bc s exe,$(wildcard stage*/*.$(ext)))
$(Q)rm -Rf $(foreach ext,out out.tmp \
CFG_WINDOWSY := 1
endif
-CFG_TESTLIB=$(CFG_BUILD_DIR)/$(strip \
- $(if $(findstring stage0,$(1)), \
- stage0/lib, \
- $(if $(findstring stage1,$(1)), \
- stage1/lib, \
- $(if $(findstring stage2,$(1)),\
- stage2/lib, \
- ))))
+CFG_TESTLIB=$(CFG_BUILD_DIR)/$(strip \
+ $(if $(findstring stage0,$(1)), \
+ stage0/lib, \
+ $(if $(findstring stage1,$(1)), \
+ stage1/lib, \
+ $(if $(findstring stage2,$(1)), \
+ stage2/lib, \
+ $(if $(findstring stage3,$(1)), \
+ stage3/lib, \
+ )))))
ifdef CFG_UNIXY
CFG_INFO := $(info cfg: unix-y environment)
CFG_PATH_MUNGE := true
CFG_EXE_SUFFIX :=
- CFG_RUN_TARG=$(CFG_LDENV)=$(CFG_BUILD_DIR)/$(1) $(2)
- CFG_RUN_TEST=\
- $(CFG_LDENV)=$(call CFG_TESTLIB,$(1)) \
- $(CFG_VALGRIND) $(1)
+ CFG_LDPATH :=
+ CFG_RUN=$(CFG_LDENV)=$(1) $(2)
+ CFG_RUN_TARG=$(call CFG_RUN,$(CFG_BUILD_DIR)/$(1),$(2))
+ CFG_RUN_TEST=$(call CFG_RUN,$(call CFG_TESTLIB,$(1)),\
+ $(CFG_VALGRIND) $(1))
ifdef CFG_ENABLE_MINGW_CROSS
CFG_WINDOWSY := 1
CFG_DEF_SUFFIX := .def
CFG_LDPATH :=$(CFG_LLVM_BINDIR)
CFG_LDPATH :=$(CFG_LDPATH):$$PATH
- CFG_RUN_TEST=PATH="$(CFG_LDPATH):$(call CFG_TESTLIB,$(1))" $(1)
- CFG_RUN_TARG=PATH="$(CFG_LDPATH)" $(2)
+ CFG_RUN=PATH="$(CFG_LDPATH):$(1)" $(2)
+ CFG_RUN_TARG=$(call CFG_RUN,,$(2))
+ CFG_RUN_TEST=$(call CFG_RUN,$(call CFG_TESTLIB,$(1)),$(1))
ifndef CFG_ENABLE_MINGW_CROSS
CFG_PATH_MUNGE := $(strip perl -i.bak -p \
$(S)src/test/*/*/*.rs \
$(S)src/test/*/*.rc)
-ifneq ($(findstring check,$(MAKECMDGOALS)),)
-XFAIL_INPUTS := $(shell grep -l xfail $(ALL_TEST_INPUTS))
-TEST_XFAILS_STAGE0 := $(shell grep -l xfail-stage0 $(XFAIL_INPUTS))
-TEST_XFAILS_STAGE1 := $(shell grep -l xfail-stage1 $(XFAIL_INPUTS))
-TEST_XFAILS_STAGE2 := $(shell grep -l xfail-stage2 $(XFAIL_INPUTS))
-
-ifdef MINGW_CROSS
-TEST_XFAILS_STAGE0 += $(S)src/test/run-pass/native-mod.rc
-TEST_XFAILS_STAGE1 += $(S)src/test/run-pass/native-mod.rc
-TEST_XFAILS_STAGE2 += $(S)src/test/run-pass/native-mod.rc
-endif
-ifdef CFG_WINDOWSY
-TEST_XFAILS_STAGE0 += $(S)src/test/run-pass/native-mod.rc
-TEST_XFAILS_STAGE1 += $(S)src/test/run-pass/native-mod.rc
-TEST_XFAILS_STAGE2 += $(S)src/test/run-pass/native-mod.rc
-endif
-endif
-
-
-BENCH_RS := $(wildcard $(S)src/test/bench/shootout/*.rs) \
- $(wildcard $(S)src/test/bench/99-bottles/*.rs)
+BENCH_RS := $(wildcard $(S)src/test/bench/*.rs) \
RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
-RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs) $(BENCH_RS)
+RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
-ifdef CHECK_XFAILS
-TEST_RPASS_CRATES_STAGE0 := $(filter $(TEST_XFAILS_STAGE0), $(RPASS_RC))
-TEST_RPASS_CRATES_STAGE1 := $(filter $(TEST_XFAILS_STAGE1), $(RPASS_RC))
-TEST_RPASS_CRATES_STAGE2 := $(filter $(TEST_XFAILS_STAGE2), $(RPASS_RC))
-TEST_RPASS_SOURCES_STAGE0 := $(filter $(TEST_XFAILS_STAGE0), $(RPASS_RS))
-TEST_RPASS_SOURCES_STAGE1 := $(filter $(TEST_XFAILS_STAGE1), $(RPASS_RS))
-TEST_RPASS_SOURCES_STAGE2 := $(filter $(TEST_XFAILS_STAGE2), $(RPASS_RS))
-else
-TEST_RPASS_CRATES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(RPASS_RC))
-TEST_RPASS_CRATES_STAGE1 := $(filter-out $(TEST_XFAILS_STAGE1), $(RPASS_RC))
-TEST_RPASS_CRATES_STAGE1 := $(filter-out $(TEST_XFAILS_STAGE2), $(RPASS_RC))
-TEST_RPASS_SOURCES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(RPASS_RS))
-TEST_RPASS_SOURCES_STAGE1 := $(filter-out $(TEST_XFAILS_STAGE1), $(RPASS_RS))
-TEST_RPASS_SOURCES_STAGE2 := $(filter-out $(TEST_XFAILS_STAGE2), $(RPASS_RS))
-endif
-
-TEST_RPASS_EXES_STAGE0 := \
- $(subst $(S)src/,,$(TEST_RPASS_CRATES_STAGE0:.rc=.stage0$(X))) \
- $(subst $(S)src/,,$(TEST_RPASS_SOURCES_STAGE0:.rs=.stage0$(X)))
-TEST_RPASS_EXES_STAGE1 := \
- $(subst $(S)src/,,$(TEST_RPASS_CRATES_STAGE1:.rc=.stage1$(X))) \
- $(subst $(S)src/,,$(TEST_RPASS_SOURCES_STAGE1:.rs=.stage1$(X)))
-TEST_RPASS_EXES_STAGE2 := \
- $(subst $(S)src/,,$(TEST_RPASS_CRATES_STAGE2:.rc=.stage2$(X))) \
- $(subst $(S)src/,,$(TEST_RPASS_SOURCES_STAGE2:.rs=.stage2$(X)))
-
-TEST_RPASS_OUTS_STAGE0 := \
- $(TEST_RPASS_EXES_STAGE0:.stage0$(X)=.stage0.out)
-TEST_RPASS_OUTS_STAGE1 := \
- $(TEST_RPASS_EXES_STAGE1:.stage1$(X)=.stage1.out)
-TEST_RPASS_OUTS_STAGE2 := \
- $(TEST_RPASS_EXES_STAGE2:.stage2$(X)=.stage2.out)
-
-TEST_RPASS_TMPS_STAGE0 := \
- $(TEST_RPASS_EXES_STAGE0:.stage0$(X)=.stage0$(X).tmp)
-TEST_RPASS_TMPS_STAGE1 := \
- $(TEST_RPASS_EXES_STAGE1:.stage1$(X)=.stage1$(X).tmp)
-TEST_RPASS_TMPS_STAGE2 := \
- $(TEST_RPASS_EXES_STAGE2:.stage2$(X)=.stage2$(X).tmp)
-
-
-TEST_RFAIL_CRATES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(RFAIL_RC))
-TEST_RFAIL_CRATES_STAGE1 := $(filter-out $(TEST_XFAILS_STAGE1), $(RFAIL_RC))
-TEST_RFAIL_CRATES_STAGE2 := $(filter-out $(TEST_XFAILS_STAGE2), $(RFAIL_RC))
-TEST_RFAIL_SOURCES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(RFAIL_RS))
-TEST_RFAIL_SOURCES_STAGE1 := $(filter-out $(TEST_XFAILS_STAGE1), $(RFAIL_RS))
-TEST_RFAIL_SOURCES_STAGE2 := $(filter-out $(TEST_XFAILS_STAGE2), $(RFAIL_RS))
-
-TEST_RFAIL_EXES_STAGE0 := \
- $(subst $(S)src/,,$(TEST_RFAIL_CRATES_STAGE0:.rc=.stage0$(X))) \
- $(subst $(S)src/,,$(TEST_RFAIL_SOURCES_STAGE0:.rs=.stage0$(X)))
-TEST_RFAIL_EXES_STAGE1 := \
- $(subst $(S)src/,,$(TEST_RFAIL_CRATES_STAGE1:.rc=.stage1$(X))) \
- $(subst $(S)src/,,$(TEST_RFAIL_SOURCES_STAGE1:.rs=.stage1$(X)))
-TEST_RFAIL_EXES_STAGE2 := \
- $(subst $(S)src/,,$(TEST_RFAIL_CRATES_STAGE2:.rc=.stage2$(X))) \
- $(subst $(S)src/,,$(TEST_RFAIL_SOURCES_STAGE2:.rs=.stage2$(X)))
-
-TEST_RFAIL_OUTS_STAGE0 := \
- $(TEST_RFAIL_EXES_STAGE0:.stage0$(X)=.stage0.out)
-TEST_RFAIL_OUTS_STAGE1 := \
- $(TEST_RFAIL_EXES_STAGE1:.stage1$(X)=.stage1.out)
-TEST_RFAIL_OUTS_STAGE2 := \
- $(TEST_RFAIL_EXES_STAGE2:.stage2$(X)=.stage2.out)
-
-
-TEST_CFAIL_CRATES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(CFAIL_RC))
-TEST_CFAIL_CRATES_STAGE1 := $(filter-out $(TEST_XFAILS_STAGE1), $(CFAIL_RC))
-TEST_CFAIL_CRATES_STAGE2 := $(filter-out $(TEST_XFAILS_STAGE2), $(CFAIL_RC))
-TEST_CFAIL_SOURCES_STAGE0 := $(filter-out $(TEST_XFAILS_STAGE0), $(CFAIL_RS))
-TEST_CFAIL_SOURCES_STAGE1 := $(filter-out $(TEST_XFAILS_STAGE1), $(CFAIL_RS))
-TEST_CFAIL_SOURCES_STAGE2 := $(filter-out $(TEST_XFAILS_STAGE2), $(CFAIL_RS))
-
-TEST_CFAIL_OUTS_STAGE0 := \
- $(subst $(S)src/,,$(TEST_CFAIL_CRATES_STAGE0:.rc=.stage0.out)) \
- $(subst $(S)src/,,$(TEST_CFAIL_SOURCES_STAGE0:.rs=.stage0.out))
-TEST_CFAIL_OUTS_STAGE1 := \
- $(subst $(S)src/,,$(TEST_CFAIL_CRATES_STAGE1:.rc=.stage1.out)) \
- $(subst $(S)src/,,$(TEST_CFAIL_SOURCES_STAGE1:.rs=.stage1.out))
-TEST_CFAIL_OUTS_STAGE2 := \
- $(subst $(S)src/,,$(TEST_CFAIL_CRATES_STAGE2:.rc=.stage2.out)) \
- $(subst $(S)src/,,$(TEST_CFAIL_SOURCES_STAGE2:.rs=.stage2.out))
-
-
-ALL_TEST_CRATES := $(TEST_CFAIL_CRATES_STAGE0) \
- $(TEST_RFAIL_CRATES_STAGE0) \
- $(TEST_RPASS_CRATES_STAGE0) \
- $(TEST_CFAIL_CRATES_STAGE1) \
- $(TEST_RFAIL_CRATES_STAGE1) \
- $(TEST_RPASS_CRATES_STAGE1) \
- $(TEST_CFAIL_CRATES_STAGE2) \
- $(TEST_RFAIL_CRATES_STAGE2) \
- $(TEST_RPASS_CRATES_STAGE2)
-
-ALL_TEST_SOURCES := $(TEST_CFAIL_SOURCES_STAGE0) \
- $(TEST_RFAIL_SOURCES_STAGE0) \
- $(TEST_RPASS_SOURCES_STAGE0) \
- $(TEST_CFAIL_SOURCES_STAGE1) \
- $(TEST_RFAIL_SOURCES_STAGE1) \
- $(TEST_RPASS_SOURCES_STAGE1) \
- $(TEST_CFAIL_SOURCES_STAGE2) \
- $(TEST_RFAIL_SOURCES_STAGE2) \
- $(TEST_RPASS_SOURCES_STAGE2)
+RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
+RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
+CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
FT := run_pass_stage2
FT_LIB := $(call CFG_LIB_NAME,$(FT))
FT_DRIVER := $(FT)_driver
GENERATED += test/$(FT).rc test/$(FT_DRIVER).rs
+# The arguments to all test runners
+ifdef TESTNAME
+ TESTARGS += $(TESTNAME)
+endif
+
+ifdef CHECK_XFAILS
+ TESTARGS += --ignored
+endif
+
+# Arguments to the cfail/rfail/rpass/bench tests
+ifdef CFG_VALGRIND
+ CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
+endif
-check-nocompile: $(TEST_CFAIL_OUTS_STAGE0) \
- $(TEST_CFAIL_OUTS_STAGE1) \
- $(TEST_CFAIL_OUTS_STAGE2)
+CTEST_TESTARGS := $(TESTARGS)
-check-stage0: tidy \
- $(TEST_RPASS_EXES_STAGE0) $(TEST_RFAIL_EXES_STAGE0) \
- $(TEST_RPASS_OUTS_STAGE0) $(TEST_RFAIL_OUTS_STAGE0) \
- $(TEST_CFAIL_OUTS_STAGE0) \
+ifdef VERBOSE
+ CTEST_TESTARGS += --verbose
+endif
+# The test runner that runs the cfail/rfail/rpass and bench tests
+COMPILETEST_CRATE := $(S)src/test/compiletest/compiletest.rc
+COMPILETEST_INPUTS := $(wildcard $(S)src/test/compiletest/*rs)
-check-stage1: tidy \
- $(TEST_RPASS_EXES_STAGE1) $(TEST_RFAIL_EXES_STAGE1) \
- $(TEST_RPASS_OUTS_STAGE1) $(TEST_RFAIL_OUTS_STAGE1) \
- $(TEST_CFAIL_OUTS_STAGE1) \
+# The standard library test crate
+STDTEST_CRATE := $(S)src/test/stdtest/stdtest.rc
+STDTEST_INPUTS := $(wildcard $(S)src/test/stdtest/*rs)
-check-stage2: tidy \
- $(TEST_RPASS_EXES_STAGE2) $(TEST_RFAIL_EXES_STAGE2) \
- $(TEST_RPASS_OUTS_STAGE2) $(TEST_RFAIL_OUTS_STAGE2) \
- $(TEST_CFAIL_OUTS_STAGE2) \
+######################################################################
+# Main test targets
+######################################################################
+
+check: tidy check-stage2 \
-check: tidy \
- $(TEST_RPASS_EXES_STAGE2) $(TEST_RFAIL_EXES_STAGE2) \
- $(TEST_RPASS_OUTS_STAGE2) $(TEST_RFAIL_OUTS_STAGE2) \
- $(TEST_CFAIL_OUTS_STAGE2)
+check-full: tidy check-stage1 check-stage2 check-stage3 \
check-fast: tidy \
- test/$(FT_DRIVER).out
+ check-stage2-rustc check-stage2-std \
+ test/$(FT_DRIVER).out \
-check-full: tidy \
- $(TEST_RPASS_EXES_STAGE0) $(TEST_RFAIL_EXES_STAGE0) \
- $(TEST_RPASS_OUTS_STAGE0) $(TEST_RFAIL_OUTS_STAGE0) \
- $(TEST_CFAIL_OUTS_STAGE0) \
- $(TEST_RPASS_EXES_STAGE1) $(TEST_RFAIL_EXES_STAGE1) \
- $(TEST_RPASS_OUTS_STAGE1) $(TEST_RFAIL_OUTS_STAGE1) \
- $(TEST_CFAIL_OUTS_STAGE1) \
- $(TEST_RPASS_EXES_STAGE2) $(TEST_RFAIL_EXES_STAGE2) \
- $(TEST_RPASS_OUTS_STAGE2) $(TEST_RFAIL_OUTS_STAGE2) \
- $(TEST_CFAIL_OUTS_STAGE2)
+tidy:
+ @$(call E, check: formatting)
+ $(Q)echo \
+ $(filter-out $(GENERATED) $(addprefix $(S)src/, $(GENERATED)) \
+ $(addprefix $(S)src/, $(RUSTLLVM_LIB_CS) $(RUSTLLVM_OBJS_CS) \
+ $(RUSTLLVM_HDR) $(PKG_3RDPARTY)) \
+ $(S)src/etc/%, $(PKG_FILES)) \
+ | xargs -n 10 python $(S)src/etc/tidy.py
-check-compile: tidy \
- $(TEST_RPASS_EXES_STAGE0) $(TEST_RFAIL_EXES_STAGE0) \
- $(TEST_RPASS_EXES_STAGE1) $(TEST_RFAIL_EXES_STAGE1) \
- $(TEST_RPASS_EXES_STAGE2) $(TEST_RFAIL_EXES_STAGE2)
+# Cancel the implicit .out rule in GNU make
+%.out: %
+%.out: %.out.tmp
+ $(Q)mv $< $@
######################################################################
-# Fast-test rules
+# Rules for the test runners
######################################################################
-test/$(FT).rc test/$(FT_DRIVER).rs: $(TEST_RPASS_SOURCES_STAGE2) \
- $(S)src/etc/combine-tests.py
- @$(call E, check: building combined stage2 test runner)
- $(Q)$(S)src/etc/combine-tests.py
+# StageN template: to stay consistent with stageN.mk, arge 2 is the
+# stage being tested, arg 1 is stage N-1
-stage2/lib/$(FT_LIB): test/$(FT).rc $(SREQ2)
- @$(call E, compile_and_link: $@)
- $(STAGE2) --lib -o $@ $<
+define TEST_STAGEN
-test/$(FT_DRIVER)$(X): test/$(FT_DRIVER).rs stage2/lib/$(FT_LIB) $(SREQ2)
- @$(call E, compile_and_link: $@)
- $(STAGE2) -o $@ $<
+check-stage$(2): tidy \
+ check-stage$(2)-rustc \
+ check-stage$(2)-std \
+ check-stage$(2)-rpass \
+ check-stage$(2)-rfail \
+ check-stage$(2)-cfail \
+ check-stage$(2)-bench \
-test/$(FT_DRIVER).out: test/$(FT_DRIVER)$(X) $(SREQ2)
- $(Q)$(call CFG_RUN_TEST, $<) | tee $@
+# Rules for the standard library test runner
-######################################################################
-# Testing rules
-######################################################################
+check-stage$(2)-std: test/stdtest.stage$(2).out \
-tidy:
- @$(call E, check: formatting)
- $(Q)echo \
- $(filter-out $(GENERATED) $(addprefix $(S)src/, $(GENERATED)) \
- $(addprefix $(S)src/, $(RUSTLLVM_LIB_CS) $(RUSTLLVM_OBJS_CS) \
- $(RUSTLLVM_HDR) $(PKG_3RDPARTY)) \
- $(S)src/etc/%, $(PKG_FILES)) \
- | xargs -n 10 python $(S)src/etc/tidy.py
+test/stdtest.stage$(2)$$(X): $$(STDTEST_CRATE) $$(STDTEST_INPUTS) \
+ $$(SREQ$(2))
+ @$$(call E, compile_and_link: $$@)
+ $$(STAGE1) -o $$@ $$< --test
-%.stage0$(X): %.rs $(SREQ0)
- @$(call E, compile_and_link: $@)
- $(STAGE0) -o $@ $<
+test/stdtest.stage$(2).out.tmp: test/stdtest.stage$(2)$$(X)
+ @$$(call E, run: $$<)
+ $$(Q)$$(call CFG_RUN_TEST,$$<) $$(TESTARGS)
+ $$(Q)touch $$@
-%.stage0$(X): %.rc $(SREQ0)
- @$(call E, compile_and_link: $@)
- $(STAGE0) -o $@ $<
-%.stage1$(X): %.rs $(SREQ1)
- @$(call E, compile_and_link: $@)
- $(STAGE1) -o $@ $<
+# Rules for the rustc test runner
-%.stage1$(X): %.rc $(SREQ1)
- @$(call E, compile_and_link: $@)
- $(STAGE1) -o $@ $<
+check-stage$(2)-rustc: test/rustctest.stage$(2).out \
-%.stage2$(X): %.rs $(SREQ2)
- @$(call E, compile_and_link: $@)
- $(STAGE2) -o $@ $<
+test/rustctest.stage$(2)$$(X): $$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
+ stage$(2)/$$(CFG_RUNTIME) \
+ $$(call CFG_STDLIB_DEFAULT,stage$(1),stage$(2)) \
+ stage$(2)/$$(CFG_RUSTLLVM) \
+ $$(SREQ$(1))
+ @$$(call E, compile_and_link: $$@)
+ $$(STAGE$(1)) -o $$@ $$< --test
-%.stage2$(X): %.rc $(SREQ2)
- @$(call E, compile_and_link: $@)
- $(STAGE2) -o $@ $<
+test/rustctest.stage$(2).out.tmp: test/rustctest.stage$(2)$$(X)
+ @$$(call E, run: $$<)
+ $$(Q)$$(call CFG_RUN,stage$(2),$$(CFG_VALGRIND) $$<) \
+ $$(TESTARGS)
+ $$(Q)touch $$@
-# Cancel the implicit .out rule in GNU make.
-%.out: %
-%.out: %.out.tmp
- $(Q)mv $< $@
+# Rules for the cfail/rfail/rpass/bench test runner
-test/run-pass/%.out.tmp: test/run-pass/%$(X) rt/$(CFG_RUNTIME)
- $(Q)rm -f $<.tmp
- @$(call E, run: $@)
- $(Q)$(call CFG_RUN_TEST, $<) > $@
-
-test/bench/shootout/%.out.tmp: test/bench/shootout/%$(X) \
- rt/$(CFG_RUNTIME)
- $(Q)rm -f $<.tmp
- @$(call E, run: $@)
- $(Q)$(call CFG_RUN_TEST, $<) > $@
-
-test/bench/99-bottles/%.out.tmp: test/bench/99-bottles/%$(X) \
- rt/$(CFG_RUNTIME)
- $(Q)rm -f $<.tmp
- @$(call E, run: $@)
- $(Q)$(call CFG_RUN_TEST, $<) > $@
-
-test/run-fail/%.out.tmp: test/run-fail/%$(X) \
- rt/$(CFG_RUNTIME)
- $(Q)rm -f $<.tmp
- @$(call E, run-fail: $@)
- $(Q)grep -q error-pattern $(S)src/test/run-fail/$(basename $*).rs
- $(Q)rm -f $@
- $(Q)$(call CFG_RUN_TEST, $<) >$@ 2>&1 ; X=$$? ; \
- if [ $$X -eq 0 ] ; then exit 1 ; else exit 0 ; fi
- $(Q)grep --text --quiet \
- "$$(grep error-pattern $(S)src/test/run-fail/$(basename $*).rs \
- | cut -d : -f 2- | tr -d '\n\r')" $@
-
-test/compile-fail/%.stage0.out.tmp: test/compile-fail/%.rs $(SREQ0)
- @$(call E, compile-fail [stage0]: $@)
- $(Q)grep -q error-pattern $<
- $(Q)rm -f $@
- $(STAGE0) -c -o $(@:.o=$(X)) $< >$@ 2>&1; test $$? -ne 0
- $(Q)grep --text --quiet \
- "$$(grep error-pattern $< | cut -d : -f 2- | tr -d '\n\r')" $@
-
-test/compile-fail/%.stage1.out.tmp: test/compile-fail/%.rs $(SREQ1)
- @$(call E, compile-fail [stage1]: $@)
- $(Q)grep -q error-pattern $<
- $(Q)rm -f $@
- $(STAGE1) -c -o $(@:.o=$(X)) $< >$@ 2>&1; test $$? -ne 0
- $(Q)grep --text --quiet \
- "$$(grep error-pattern $< | cut -d : -f 2- | tr -d '\n\r')" $@
-
-test/compile-fail/%.stage2.out.tmp: test/compile-fail/%.rs $(SREQ2)
- @$(call E, compile-fail [stage2]: $@)
- $(Q)grep -q error-pattern $<
- $(Q)rm -f $@
- $(STAGE2) -c -o $(@:.o=$(X)) $< >$@ 2>&1; test $$? -ne 0
- $(Q)grep --text --quiet \
- "$$(grep error-pattern $< | cut -d : -f 2- | tr -d '\n\r')" $@
-
-test/compile-fail/%.stage0.out.tmp: test/compile-fail/%.rc $(SREQ0)
- @$(call E, compile-fail [stage0]: $@)
- $(Q)grep -q error-pattern $<
- $(Q)rm -f $@
- $(STAGE0) -c -o $(@:.o=$(X)) $< >$@ 2>&1; test $$? -ne 0
- $(Q)grep --text --quiet \
- "$$(grep error-pattern $< | cut -d : -f 2- | tr -d '\n\r')" $@
-
-test/compile-fail/%.stage1.out.tmp: test/compile-fail/%.rc $(SREQ1)
- @$(call E, compile-fail [stage1]: $@)
- $(Q)grep -q error-pattern $<
- $(Q)rm -f $@
- $(STAGE1) -c -o $(@:.o=$(X)) $< >$@ 2>&1; test $$? -ne 0
- $(Q)grep --text --quiet \
- "$$(grep error-pattern $< | cut -d : -f 2- | tr -d '\n\r')" $@
-
-test/compile-fail/%.stage2.out.tmp: test/compile-fail/%.rc $(SREQ2)
- @$(call E, compile-fail [stage2]: $@)
- $(Q)grep -q error-pattern $<
- $(Q)rm -f $@
- $(STAGE2) -c -o $(@:.o=$(X)) $< >$@ 2>&1; test $$? -ne 0
- $(Q)grep --text --quiet \
- "$$(grep error-pattern $< | cut -d : -f 2- | tr -d '\n\r')" $@
-
-# Testing the stdtest crate
+check-stage$(2)-cfail: test/compile-fail.stage$(2).out \
-STDTEST_CRATE := $(S)src/test/stdtest/stdtest.rc
-STDTEST_INPUTS := $(wildcard $(S)src/test/stdtest/*rs)
+check-stage$(2)-rfail: test/run-fail.stage$(2).out \
-test/stdtest.stage1$(X): $(STDTEST_CRATE) $(STDTEST_INPUTS) $(SREQ1)
- @$(call E, compile_and_link: $@)
- $(STAGE1) -o $@ $< --test
+check-stage$(2)-rpass: test/run-pass.stage$(2).out \
-test/stdtest.stage2$(X): $(STDTEST_CRATE) $(STDTEST_INPUTS) $(SREQ2)
- @$(call E, compile_and_link: $@)
- $(STAGE2) -o $@ $< --test
+check-stage$(2)-bench: test/bench.stage$(2).out \
-test/stdtest.stage3$(X): $(STDTEST_CRATE) $(STDTEST_INPUTS) $(SREQ3)
- @$(call E, compile_and_link: $@)
- $(STAGE3) -o $@ $< --test
+CTEST_COMMON_ARGS$(2) := --compile-lib-path stage$(2) \
+ --run-lib-path stage$(2)/lib \
+ --rustc-path stage$(2)/rustc$$(X) \
+ --stage-id stage$(2) \
+ --rustcflags "$$(CFG_RUSTC_FLAGS)" \
+ $$(CTEST_TESTARGS) \
-check-stage1-std:test/stdtest.stage1$(X)
- @$(call E, run: $<)
- $(Q)$(call CFG_RUN_TARG,stage1, $<)
+CFAIL_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
+ --src-base $$(S)src/test/compile-fail/ \
+ --build-base test/compile-fail/ \
+ --mode compile-fail \
-check-stage2-std:test/stdtest.stage2$(X)
- @$(call E, run: $<)
- $(Q)$(call CFG_RUN_TARG,stage2, $<)
+# FIXME (236): run-fail should run under valgrind once unwinding works
+RFAIL_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
+ --src-base $$(S)src/test/run-fail/ \
+ --build-base test/run-fail/ \
+ --mode run-fail \
-check-stage3-std:test/stdtest.stage3$(X)
- @$(call E, run: $<)
- $(Q)$(call CFG_RUN_TARG,stage3, $<)
+RPASS_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
+ --src-base $(S)src/test/run-pass/ \
+ --build-base test/run-pass/ \
+ --mode run-pass \
+ $$(CTEST_RUNTOOL) \
-# Testing the rustctest crate
+BENCH_ARGS$(2) := $$(CTEST_COMMON_ARGS$(2)) \
+ --src-base $(S)src/test/bench/ \
+ --build-base test/bench/ \
+ --mode run-pass \
+ $$(CTEST_RUNTOOL) \
-test/rustctest.stage1$(X): $(COMPILER_CRATE) $(COMPILER_INPUTS) $(SREQ0) \
- stage0/intrinsics.bc
- @$(call E, compile_and_link: $@)
- $(STAGE0) -o $@ $< --test
+test/compiletest.stage$(2)$$(X): $$(COMPILETEST_CRATE) \
+ $$(COMPILETEST_INPUTS) \
+ $$(SREQ$(2))
+ @$$(call E, compile_and_link: $$@)
+ $$(STAGE$(2)) -o $$@ $$<
-test/rustctest.stage2$(X): $(COMPILER_CRATE) $(COMPILER_INPUTS) $(SREQ1) \
- stage1/intrinsics.bc
- @$(call E, compile_and_link: $@)
- $(STAGE1) -o $@ $< --test
+test/compile-fail.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
+ $$(CFAIL_TESTS)
+ @$$(call E, run: $$<)
+ $$(Q)$$(call CFG_RUN_TEST,$$<) $$(CFAIL_ARGS$(2))
+ $$(Q)touch $$@
-test/rustctest.stage3$(X): $(COMPILER_CRATE) $(COMPILER_INPUTS) $(SREQ2) \
- stage2/intrinsics.bc
- @$(call E, compile_and_link: $@)
- $(STAGE2) -o $@ $< --test
+test/run-fail.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
+ $$(RFAIL_TESTS)
+ @$$(call E, run: $$<)
+ $$(Q)$$(call CFG_RUN_TEST,$$<) $$(RFAIL_ARGS$(2))
+ $$(Q)touch $$@
+
+test/run-pass.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
+ $$(RPASS_TESTS)
+ @$$(call E, run: $$<)
+ $$(Q)$$(call CFG_RUN_TEST,$$<) $$(RPASS_ARGS$(2))
+ $$(Q)touch $$@
+
+test/bench.stage$(2).out.tmp: test/compiletest.stage$(2)$$(X) \
+ $$(BENCH_TESTS)
+ @$$(call E, run: $$<)
+ $$(Q)$$(call CFG_RUN_TEST,$$<) $$(BENCH_ARGS$(2))
+ $$(Q)touch $$@
-check-stage1-rustc: test/rustctest.stage1$(X)
- @$(call E, run: $<)
- $(Q)$(call CFG_RUN_TARG,stage1, $<)
+endef
-check-stage2-rustc: test/rustctest.stage2$(X)
- @$(call E, run: $<)
- $(Q)$(call CFG_RUN_TARG,stage2, $<)
+# Instantiate the template for stage 1, 2, 3
-check-stage3-rustc: test/rustctest.stage3$(X)
- @$(call E, run: $<)
- $(Q)$(call CFG_RUN_TARG,stage2, $<)
+$(eval $(call TEST_STAGEN,0,1))
+$(eval $(call TEST_STAGEN,1,2))
+$(eval $(call TEST_STAGEN,2,3))
+
+
+######################################################################
+# Fast-test rules
+######################################################################
+
+test/$(FT).rc test/$(FT_DRIVER).rs: $(TEST_RPASS_SOURCES_STAGE2) \
+ $(S)src/etc/combine-tests.py
+ @$(call E, check: building combined stage2 test runner)
+ $(Q)$(S)src/etc/combine-tests.py
+
+stage2/lib/$(FT_LIB): test/$(FT).rc $(SREQ2)
+ @$(call E, compile_and_link: $@)
+ $(STAGE2) --lib -o $@ $<
+
+test/$(FT_DRIVER)$(X): test/$(FT_DRIVER).rs stage2/lib/$(FT_LIB) $(SREQ2)
+ @$(call E, compile_and_link: $@)
+ $(STAGE2) -o $@ $<
+
+test/$(FT_DRIVER).out: test/$(FT_DRIVER)$(X) $(SREQ2)
+ $(Q)$(call CFG_RUN_TEST, $<) | tee $@
export tr_ok;
export tr_failed;
export tr_ignored;
+export run_tests_console;
export run_test;
export filter_tests;
export parse_opts;
either::left(?o) { o }
either::right(?m) { fail m }
};
- if (!run_tests(opts, tests)) {
+ if (!run_tests_console(opts, tests)) {
fail "Some tests failed";
}
}
}
// A simple console test runner
-fn run_tests(&test_opts opts, &test_desc[] tests) -> bool {
+fn run_tests_console(&test_opts opts, &test_desc[] tests) -> bool {
auto filtered_tests = filter_tests(opts, tests);
+++ /dev/null
-
-
-/* -*- mode::rust;indent-tabs-mode::nil -*-
- * Implementation of 99 Bottles of Beer
- * http://99-bottles-of-beer.net/
- */
-use std;
-import std::int;
-import std::str;
-
-fn b1() -> str { ret "# of beer on the wall, # of beer."; }
-
-fn b2() -> str {
- ret "Take one down and pass it around, # of beer on the wall.";
-}
-
-fn b7() -> str {
- ret "No more bottles of beer on the wall, no more bottles of beer.";
-}
-
-fn b8() -> str {
- ret "Go to the store and buy some more, # of beer on the wall.";
-}
-
-fn sub(str t, int n) -> str {
- let str b = "";
- let uint i = 0u;
- let str ns;
- alt (n) {
- case (0) { ns = "no more bottles"; }
- case (1) { ns = "1 bottle"; }
- case (_) { ns = int::to_str(n, 10u) + " bottles"; }
- }
- while (i < str::byte_len(t)) {
- if (t.(i) == '#' as u8) {
- b += ns;
- } else { str::push_byte(b, t.(i)); }
- i += 1u;
- }
- ret b;
-}
-
-
-/* Using an interator */
-iter ninetynine() -> int { let int n = 100; while (n > 1) { n -= 1; put n; } }
-
-fn main() {
- for each (int n in ninetynine()) {
- log sub(b1(), n);
- log sub(b2(), n - 1);
- log "";
- }
- log b7();
- log b8();
-}
\ No newline at end of file
+++ /dev/null
-
-
-/* -*- mode::rust;indent-tabs-mode::nil -*-
- * Implementation of 99 Bottles of Beer
- * http://99-bottles-of-beer.net/
- */
-use std;
-import std::int;
-import std::str;
-
-tag bottle { none; dual; single; multiple(int); }
-
-fn show(bottle b) {
- alt (b) {
- case (none) {
- log "No more bottles of beer on the wall, " +
- "no more bottles of beer,";
- log "Go to the store and buy some more, " +
- "99 bottles of beer on the wall.";
- }
- case (single) {
- log "1 bottle of beer on the wall, 1 bottle of beer,";
- log "Take one down and pass it around, " +
- "no more bottles of beer on the wall.";
- }
- case (dual) {
- log "2 bottles of beer on the wall, 2 bottles of beer,";
- log "Take one down and pass it around, " +
- "1 bottle of beer on the wall.";
- }
- case (multiple(?n)) {
- let str nb = int::to_str(n, 10u);
- let str mb = int::to_str(n - 1, 10u);
- log nb + " bottles of beer on the wall, " + nb +
- " bottles of beer,";
- log "Take one down and pass it around, " + mb +
- " bottles of beer on the wall.";
- }
- }
-}
-
-fn next(bottle b) -> bottle {
- alt (b) {
- case (none) { ret none; }
- case (single) { ret none; }
- case (dual) { ret single; }
- case (multiple(3)) { ret dual; }
- case (multiple(?n)) { ret multiple(n - 1); }
- }
-}
-
-
-// Won't need this when tags can be compared with ==
-fn more(bottle b) -> bool {
- alt (b) { case (none) { ret false; } case (_) { ret true; } }
-}
-
-fn main() {
- let bottle b = multiple(99);
- let bool running = true;
- while (running) { show(b); log ""; running = more(b); b = next(b); }
-}
\ No newline at end of file
+++ /dev/null
-
-
-/* -*- mode::rust;indent-tabs-mode::nil -*-
- * Implementation of 99 Bottles of Beer
- * http://99-bottles-of-beer.net/
- */
-use std;
-import std::int;
-import std::str;
-
-fn b1() -> str { ret "# of beer on the wall, # of beer."; }
-
-fn b2() -> str {
- ret "Take one down and pass it around, # of beer on the wall.";
-}
-
-fn b7() -> str {
- ret "No more bottles of beer on the wall, no more bottles of beer.";
-}
-
-fn b8() -> str {
- ret "Go to the store and buy some more, # of beer on the wall.";
-}
-
-fn sub(str t, int n) -> str {
- let str b = "";
- let uint i = 0u;
- let str ns;
- alt (n) {
- case (0) { ns = "no more bottles"; }
- case (1) { ns = "1 bottle"; }
- case (_) { ns = int::to_str(n, 10u) + " bottles"; }
- }
- while (i < str::byte_len(t)) {
- if (t.(i) == '#' as u8) {
- b += ns;
- } else { str::push_byte(b, t.(i)); }
- i += 1u;
- }
- ret b;
-}
-
-
-/* Straightforward counter */
-fn main() {
- let int n = 99;
- while (n > 0) { log sub(b1(), n); log sub(b2(), n - 1); log ""; n -= 1; }
- log b7();
- log sub(b8(), 99);
-}
\ No newline at end of file
+++ /dev/null
-/* -*- mode::rust;indent-tabs-mode::nil -*-
- * Implementation of 99 Bottles of Beer
- * http://99-bottles-of-beer.net/
- */
-use std;
-import std::int;
-import std::str;
-
-fn main() {
- fn multiple(int n) {
- let str nb = int::to_str(n, 10u);
- let str mb = int::to_str(n - 1, 10u);
- log nb + " bottles of beer on the wall, " + nb + " bottles of beer,";
- log "Take one down and pass it around, " + mb +
- " bottles of beer on the wall.";
- log "";
- if (n > 3) { be multiple(n - 1); } else { be dual(); }
- }
- fn dual() {
- log "2 bottles of beer on the wall, 2 bottles of beer,";
- log "Take one down and pass it around, 1 bottle of beer on the wall.";
- log "";
- be single();
- }
- fn single() {
- log "1 bottle of beer on the wall, 1 bottle of beer,";
- log "Take one down and pass it around, " +
- "no more bottles of beer on the wall.";
- log "";
- be none();
- }
- fn none() {
- log "No more bottles of beer on the wall, no more bottles of beer,";
- log "Go to the store and buy some more, " +
- "99 bottles of beer on the wall.";
- log "";
- }
- multiple(99);
-}
\ No newline at end of file
--- /dev/null
+
+
+/* -*- mode::rust;indent-tabs-mode::nil -*-
+ * Implementation of 99 Bottles of Beer
+ * http://99-bottles-of-beer.net/
+ */
+use std;
+import std::int;
+import std::str;
+
+fn b1() -> str { ret "# of beer on the wall, # of beer."; }
+
+fn b2() -> str {
+ ret "Take one down and pass it around, # of beer on the wall.";
+}
+
+fn b7() -> str {
+ ret "No more bottles of beer on the wall, no more bottles of beer.";
+}
+
+fn b8() -> str {
+ ret "Go to the store and buy some more, # of beer on the wall.";
+}
+
+fn sub(str t, int n) -> str {
+ let str b = "";
+ let uint i = 0u;
+ let str ns;
+ alt (n) {
+ case (0) { ns = "no more bottles"; }
+ case (1) { ns = "1 bottle"; }
+ case (_) { ns = int::to_str(n, 10u) + " bottles"; }
+ }
+ while (i < str::byte_len(t)) {
+ if (t.(i) == '#' as u8) {
+ b += ns;
+ } else { str::push_byte(b, t.(i)); }
+ i += 1u;
+ }
+ ret b;
+}
+
+
+/* Using an interator */
+iter ninetynine() -> int { let int n = 100; while (n > 1) { n -= 1; put n; } }
+
+fn main() {
+ for each (int n in ninetynine()) {
+ log sub(b1(), n);
+ log sub(b2(), n - 1);
+ log "";
+ }
+ log b7();
+ log b8();
+}
\ No newline at end of file
--- /dev/null
+
+
+/* -*- mode::rust;indent-tabs-mode::nil -*-
+ * Implementation of 99 Bottles of Beer
+ * http://99-bottles-of-beer.net/
+ */
+use std;
+import std::int;
+import std::str;
+
+tag bottle { none; dual; single; multiple(int); }
+
+fn show(bottle b) {
+ alt (b) {
+ case (none) {
+ log "No more bottles of beer on the wall, " +
+ "no more bottles of beer,";
+ log "Go to the store and buy some more, " +
+ "99 bottles of beer on the wall.";
+ }
+ case (single) {
+ log "1 bottle of beer on the wall, 1 bottle of beer,";
+ log "Take one down and pass it around, " +
+ "no more bottles of beer on the wall.";
+ }
+ case (dual) {
+ log "2 bottles of beer on the wall, 2 bottles of beer,";
+ log "Take one down and pass it around, " +
+ "1 bottle of beer on the wall.";
+ }
+ case (multiple(?n)) {
+ let str nb = int::to_str(n, 10u);
+ let str mb = int::to_str(n - 1, 10u);
+ log nb + " bottles of beer on the wall, " + nb +
+ " bottles of beer,";
+ log "Take one down and pass it around, " + mb +
+ " bottles of beer on the wall.";
+ }
+ }
+}
+
+fn next(bottle b) -> bottle {
+ alt (b) {
+ case (none) { ret none; }
+ case (single) { ret none; }
+ case (dual) { ret single; }
+ case (multiple(3)) { ret dual; }
+ case (multiple(?n)) { ret multiple(n - 1); }
+ }
+}
+
+
+// Won't need this when tags can be compared with ==
+fn more(bottle b) -> bool {
+ alt (b) { case (none) { ret false; } case (_) { ret true; } }
+}
+
+fn main() {
+ let bottle b = multiple(99);
+ let bool running = true;
+ while (running) { show(b); log ""; running = more(b); b = next(b); }
+}
\ No newline at end of file
--- /dev/null
+
+
+/* -*- mode::rust;indent-tabs-mode::nil -*-
+ * Implementation of 99 Bottles of Beer
+ * http://99-bottles-of-beer.net/
+ */
+use std;
+import std::int;
+import std::str;
+
+fn b1() -> str { ret "# of beer on the wall, # of beer."; }
+
+fn b2() -> str {
+ ret "Take one down and pass it around, # of beer on the wall.";
+}
+
+fn b7() -> str {
+ ret "No more bottles of beer on the wall, no more bottles of beer.";
+}
+
+fn b8() -> str {
+ ret "Go to the store and buy some more, # of beer on the wall.";
+}
+
+fn sub(str t, int n) -> str {
+ let str b = "";
+ let uint i = 0u;
+ let str ns;
+ alt (n) {
+ case (0) { ns = "no more bottles"; }
+ case (1) { ns = "1 bottle"; }
+ case (_) { ns = int::to_str(n, 10u) + " bottles"; }
+ }
+ while (i < str::byte_len(t)) {
+ if (t.(i) == '#' as u8) {
+ b += ns;
+ } else { str::push_byte(b, t.(i)); }
+ i += 1u;
+ }
+ ret b;
+}
+
+
+/* Straightforward counter */
+fn main() {
+ let int n = 99;
+ while (n > 0) { log sub(b1(), n); log sub(b2(), n - 1); log ""; n -= 1; }
+ log b7();
+ log sub(b8(), 99);
+}
\ No newline at end of file
--- /dev/null
+/* -*- mode::rust;indent-tabs-mode::nil -*-
+ * Implementation of 99 Bottles of Beer
+ * http://99-bottles-of-beer.net/
+ */
+use std;
+import std::int;
+import std::str;
+
+fn main() {
+ fn multiple(int n) {
+ let str nb = int::to_str(n, 10u);
+ let str mb = int::to_str(n - 1, 10u);
+ log nb + " bottles of beer on the wall, " + nb + " bottles of beer,";
+ log "Take one down and pass it around, " + mb +
+ " bottles of beer on the wall.";
+ log "";
+ if (n > 3) { be multiple(n - 1); } else { be dual(); }
+ }
+ fn dual() {
+ log "2 bottles of beer on the wall, 2 bottles of beer,";
+ log "Take one down and pass it around, 1 bottle of beer on the wall.";
+ log "";
+ be single();
+ }
+ fn single() {
+ log "1 bottle of beer on the wall, 1 bottle of beer,";
+ log "Take one down and pass it around, " +
+ "no more bottles of beer on the wall.";
+ log "";
+ be none();
+ }
+ fn none() {
+ log "No more bottles of beer on the wall, no more bottles of beer,";
+ log "Go to the store and buy some more, " +
+ "99 bottles of beer on the wall.";
+ log "";
+ }
+ multiple(99);
+}
\ No newline at end of file
--- /dev/null
+
+
+
+// -*- rust -*-
+fn ack(int m, int n) -> int {
+ if (m == 0) {
+ ret n + 1;
+ } else {
+ if (n == 0) {
+ ret ack(m - 1, 1);
+ } else { ret ack(m - 1, ack(m, n - 1)); }
+ }
+}
+
+fn main() {
+ assert (ack(0, 0) == 1);
+ assert (ack(3, 2) == 29);
+ assert (ack(3, 4) == 125);
+ // This takes a while; but a comparison may amuse: on win32 at least, the
+ // posted C version of the 'benchmark' running ack(4,1) overruns its stack
+ // segment and crashes. We just grow our stack (to 4mb) as we go.
+
+ // assert (ack(4,1) == 65533);
+
+}
\ No newline at end of file
--- /dev/null
+
+use std;
+import std::int;
+
+tag tree { nil; node(@tree, @tree, int); }
+
+fn item_check(@tree t) -> int {
+ alt (*t) {
+ case (nil) { ret 0; }
+ case (node(?left, ?right, ?item)) {
+ ret item + item_check(left) - item_check(right);
+ }
+ }
+}
+
+fn bottom_up_tree(int item, int depth) -> @tree {
+ if (depth > 0) {
+ ret @node(bottom_up_tree(2 * item - 1, depth - 1),
+ bottom_up_tree(2 * item, depth - 1), item);
+ } else { ret @nil; }
+}
+
+fn main() {
+ auto n = 8;
+ auto min_depth = 4;
+ auto max_depth;
+ if (min_depth + 2 > n) {
+ max_depth = min_depth + 2;
+ } else { max_depth = n; }
+ auto stretch_depth = max_depth + 1;
+ auto stretch_tree = bottom_up_tree(0, stretch_depth);
+ log #fmt("stretch tree of depth %d\t check: %d", stretch_depth,
+ item_check(stretch_tree));
+ auto long_lived_tree = bottom_up_tree(0, max_depth);
+ auto depth = min_depth;
+ while (depth <= max_depth) {
+ auto iterations = int::pow(2, max_depth - depth + min_depth as uint);
+ auto chk = 0;
+ auto i = 1;
+ while (i <= iterations) {
+ auto temp_tree = bottom_up_tree(i, depth);
+ chk += item_check(temp_tree);
+ temp_tree = bottom_up_tree(-i, depth);
+ chk += item_check(temp_tree);
+ i += 1;
+ }
+ log #fmt("%d\t trees of depth %d\t check: %d", iterations * 2, depth,
+ chk);
+ depth += 2;
+ }
+ log #fmt("long lived trees of depth %d\t check: %d", max_depth,
+ item_check(long_lived_tree));
+}
\ No newline at end of file
--- /dev/null
+
+
+// Based on Isaac Gouy's fannkuchredux.csharp
+use std;
+import std::int;
+import std::vec;
+
+fn fannkuch(int n) -> int {
+ fn perm1init(uint i) -> int { ret i as int; }
+ auto perm1init_ = perm1init; // Rustboot workaround
+
+ auto perm = vec::init_elt_mut(0, n as uint);
+ auto perm1 = vec::init_fn_mut(perm1init_, n as uint);
+ auto count = vec::init_elt_mut(0, n as uint);
+ auto f = 0;
+ auto i = 0;
+ auto k = 0;
+ auto r = 0;
+ auto flips = 0;
+ auto nperm = 0;
+ auto checksum = 0;
+ r = n;
+ while (r > 0) {
+ i = 0;
+ while (r != 1) { count.(r - 1) = r; r -= 1; }
+ while (i < n) { perm.(i) = perm1.(i); i += 1; }
+ // Count flips and update max and checksum
+
+ f = 0;
+ k = perm.(0);
+ while (k != 0) {
+ i = 0;
+ while (2 * i < k) {
+ auto t = perm.(i);
+ perm.(i) = perm.(k - i);
+ perm.(k - i) = t;
+ i += 1;
+ }
+ k = perm.(0);
+ f += 1;
+ }
+ if (f > flips) { flips = f; }
+ if (nperm & 0x1 == 0) { checksum += f; } else { checksum -= f; }
+ // Use incremental change to generate another permutation
+
+ auto go = true;
+ while (go) {
+ if (r == n) { log checksum; ret flips; }
+ auto p0 = perm1.(0);
+ i = 0;
+ while (i < r) { auto j = i + 1; perm1.(i) = perm1.(j); i = j; }
+ perm1.(r) = p0;
+ count.(r) -= 1;
+ if (count.(r) > 0) { go = false; } else { r += 1; }
+ }
+ nperm += 1;
+ }
+ ret flips;
+}
+
+fn main(vec[str] args) {
+ auto n = 7;
+ log #fmt("Pfannkuchen(%d) = %d", n, fannkuch(n));
+}
\ No newline at end of file
--- /dev/null
+
+
+/* -*- mode: rust; indent-tabs-mode: nil -*-
+ * Implementation of 'fasta' benchmark from
+ * Computer Language Benchmarks Game
+ * http://shootout.alioth.debian.org/
+ */
+use std;
+import std::vec;
+import std::str;
+import std::uint;
+import std::int;
+
+fn LINE_LENGTH() -> uint { ret 60u; }
+
+obj myrandom(mutable u32 last) {
+ fn next(u32 mx) -> u32 {
+ last = (last * 3877u32 + 29573u32) % 139968u32;
+ auto ans = mx * last / 139968u32;
+ ret ans;
+ }
+}
+
+type aminoacids = tup(char, u32);
+
+fn make_cumulative(vec[aminoacids] aa) -> vec[aminoacids] {
+ let u32 cp = 0u32;
+ let vec[aminoacids] ans = [];
+ for (aminoacids a in aa) { cp += a._1; ans += [tup(a._0, cp)]; }
+ ret ans;
+}
+
+fn select_random(u32 r, vec[aminoacids] genelist) -> char {
+ if (r < genelist.(0)._1) { ret genelist.(0)._0; }
+ fn bisect(vec[aminoacids] v, uint lo, uint hi, u32 target) -> char {
+ if (hi > lo + 1u) {
+ let uint mid = lo + (hi - lo) / 2u;
+ if (target < v.(mid)._1) {
+ be bisect(v, lo, mid, target);
+ } else { be bisect(v, mid, hi, target); }
+ } else { ret v.(hi)._0; }
+ }
+ ret bisect(genelist, 0u, vec::len[aminoacids](genelist) - 1u, r);
+}
+
+fn make_random_fasta(str id, str desc, vec[aminoacids] genelist, int n) {
+ log ">" + id + " " + desc;
+ auto rng = myrandom(std::rand::mk_rng().next());
+ let str op = "";
+ for each (uint i in uint::range(0u, n as uint)) {
+ str::push_byte(op, select_random(rng.next(100u32), genelist) as u8);
+ if (str::byte_len(op) >= LINE_LENGTH()) { log op; op = ""; }
+ }
+ if (str::byte_len(op) > 0u) { log op; }
+}
+
+fn make_repeat_fasta(str id, str desc, str s, int n) {
+ log ">" + id + " " + desc;
+ let str op = "";
+ let uint sl = str::byte_len(s);
+ for each (uint i in uint::range(0u, n as uint)) {
+ str::push_byte(op, s.(i % sl));
+ if (str::byte_len(op) >= LINE_LENGTH()) { log op; op = ""; }
+ }
+ if (str::byte_len(op) > 0u) { log op; }
+}
+
+fn main(vec[str] args) {
+ let vec[aminoacids] iub =
+ make_cumulative([tup('a', 27u32), tup('c', 12u32), tup('g', 12u32),
+ tup('t', 27u32), tup('B', 2u32), tup('D', 2u32),
+ tup('H', 2u32), tup('K', 2u32), tup('M', 2u32),
+ tup('N', 2u32), tup('R', 2u32), tup('S', 2u32),
+ tup('V', 2u32), tup('W', 2u32), tup('Y', 2u32)]);
+ let vec[aminoacids] homosapiens =
+ make_cumulative([tup('a', 30u32), tup('c', 20u32), tup('g', 20u32),
+ tup('t', 30u32)]);
+ let str alu =
+ "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
+ "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
+ "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
+ "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
+ "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
+ "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
+ "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
+ let int n = 512;
+ make_repeat_fasta("ONE", "Homo sapiens alu", alu, n * 2);
+ make_random_fasta("TWO", "IUB ambiguity codes", iub, n * 3);
+ make_random_fasta("THREE", "Homo sapiens frequency", homosapiens, n * 5);
+}
\ No newline at end of file
--- /dev/null
+
+
+
+// -*- rust -*-
+fn fib(int n) -> int {
+
+ // Several of the posted 'benchmark' versions of this compute the
+ // wrong Fibonacci numbers, of course.
+ if (n == 0) {
+ ret 0;
+ } else { if (n <= 2) { ret 1; } else { ret fib(n - 1) + fib(n - 2); } }
+}
+
+fn main() {
+ assert (fib(8) == 21);
+ assert (fib(15) == 610);
+ log fib(8);
+ log fib(15);
+}
\ No newline at end of file
--- /dev/null
+// based on:
+// http://shootout.alioth.debian.org/u32/benchmark.php?test=nbody&lang=java
+
+native "llvm" mod llvm {
+ fn sqrt(float n) -> float = "sqrt.f64";
+}
+
+fn main() {
+
+ let vec[int] inputs = [
+ 50000,
+ 500000
+ //
+ // Leave these commented out to
+ // finish in a reasonable time
+ // during 'make check' under valgrind
+ // 5000000
+ // 50000000
+ ];
+
+ let vec[Body::props] bodies = NBodySystem::MakeNBodySystem();
+
+ for (int n in inputs) {
+ log NBodySystem::energy(bodies);
+
+ let int i = 0;
+ while (i < n) {
+ NBodySystem::advance(bodies, 0.01);
+ i += 1;
+ }
+ log NBodySystem::energy(bodies);
+ }
+}
+
+// Body::props is a record of floats, so
+// vec[Body::props] is a vector of records of floats
+
+mod NBodySystem {
+
+ fn MakeNBodySystem() -> vec[Body::props] {
+ let vec[Body::props] bodies = [
+ // these each return a Body::props
+ Body::sun(),
+ Body::jupiter(),
+ Body::saturn(),
+ Body::uranus(),
+ Body::neptune()];
+
+ let float px = 0.0;
+ let float py = 0.0;
+ let float pz = 0.0;
+
+ let int i = 0;
+ while (i < 5) {
+ px += bodies.(i).vx * bodies.(i).mass;
+ py += bodies.(i).vy * bodies.(i).mass;
+ pz += bodies.(i).vz * bodies.(i).mass;
+
+ i += 1;
+ }
+
+ // side-effecting
+ Body::offsetMomentum(bodies.(0), px, py, pz);
+
+ ret bodies;
+ }
+
+ fn advance(vec[Body::props] bodies, float dt) -> () {
+
+ let int i = 0;
+ while (i < 5) {
+ let int j = i+1;
+ while (j < 5) {
+ advance_one(bodies.(i), bodies.(j), dt);
+ j += 1;
+ }
+
+ i += 1;
+ }
+
+ i = 0;
+ while (i < 5) {
+ move(bodies.(i), dt);
+ i += 1;
+ }
+ }
+
+ fn advance_one(&Body::props bi, &Body::props bj, float dt) {
+ let float dx = bi.x - bj.x;
+ let float dy = bi.y - bj.y;
+ let float dz = bi.z - bj.z;
+
+ let float dSquared = dx * dx + dy * dy + dz * dz;
+
+ let float distance = llvm::sqrt(dSquared);
+ let float mag = dt / (dSquared * distance);
+
+ bi.vx -= dx * bj.mass * mag;
+ bi.vy -= dy * bj.mass * mag;
+ bi.vz -= dz * bj.mass * mag;
+
+ bj.vx += dx * bi.mass * mag;
+ bj.vy += dy * bi.mass * mag;
+ bj.vz += dz * bi.mass * mag;
+ }
+
+ fn move(&Body::props b, float dt) {
+ b.x += dt * b.vx;
+ b.y += dt * b.vy;
+ b.z += dt * b.vz;
+ }
+
+ fn energy(vec[Body::props] bodies) -> float {
+ let float dx;
+ let float dy;
+ let float dz;
+ let float distance;
+ let float e = 0.0;
+
+ let int i = 0;
+ while (i < 5) {
+ e += 0.5 * bodies.(i).mass *
+ ( bodies.(i).vx * bodies.(i).vx
+ + bodies.(i).vy * bodies.(i).vy
+ + bodies.(i).vz * bodies.(i).vz );
+
+ let int j = i+1;
+ while (j < 5) {
+ dx = bodies.(i).x - bodies.(j).x;
+ dy = bodies.(i).y - bodies.(j).y;
+ dz = bodies.(i).z - bodies.(j).z;
+
+ distance = llvm::sqrt(dx*dx + dy*dy + dz*dz);
+ e -= (bodies.(i).mass * bodies.(j).mass) / distance;
+
+ j += 1;
+ }
+
+ i += 1;
+ }
+ ret e;
+
+ }
+}
+
+mod Body {
+
+ const float PI = 3.141592653589793;
+ const float SOLAR_MASS = 39.478417604357432; // was 4 * PI * PI originally
+ const float DAYS_PER_YEAR = 365.24;
+
+ type props = rec(mutable float x,
+ mutable float y,
+ mutable float z,
+ mutable float vx,
+ mutable float vy,
+ mutable float vz,
+ float mass);
+
+ fn jupiter() -> Body::props {
+ ret rec(
+ mutable x = 4.84143144246472090e+00,
+ mutable y = -1.16032004402742839e+00,
+ mutable z = -1.03622044471123109e-01,
+ mutable vx = 1.66007664274403694e-03 * DAYS_PER_YEAR,
+ mutable vy = 7.69901118419740425e-03 * DAYS_PER_YEAR,
+ mutable vz = -6.90460016972063023e-05 * DAYS_PER_YEAR,
+ mass = 9.54791938424326609e-04 * SOLAR_MASS
+ );
+ }
+
+ fn saturn() -> Body::props {
+ ret rec(
+ mutable x = 8.34336671824457987e+00,
+ mutable y = 4.12479856412430479e+00,
+ mutable z = -4.03523417114321381e-01,
+ mutable vx = -2.76742510726862411e-03 * DAYS_PER_YEAR,
+ mutable vy = 4.99852801234917238e-03 * DAYS_PER_YEAR,
+ mutable vz = 2.30417297573763929e-05 * DAYS_PER_YEAR,
+ mass = 2.85885980666130812e-04 * SOLAR_MASS
+ );
+ }
+
+ fn uranus() -> Body::props {
+ ret rec(
+ mutable x = 1.28943695621391310e+01,
+ mutable y = -1.51111514016986312e+01,
+ mutable z = -2.23307578892655734e-01,
+ mutable vx = 2.96460137564761618e-03 * DAYS_PER_YEAR,
+ mutable vy = 2.37847173959480950e-03 * DAYS_PER_YEAR,
+ mutable vz = -2.96589568540237556e-05 * DAYS_PER_YEAR,
+ mass = 4.36624404335156298e-05 * SOLAR_MASS
+ );
+ }
+
+ fn neptune() -> Body::props {
+ ret rec(
+ mutable x = 1.53796971148509165e+01,
+ mutable y = -2.59193146099879641e+01,
+ mutable z = 1.79258772950371181e-01,
+ mutable vx = 2.68067772490389322e-03 * DAYS_PER_YEAR,
+ mutable vy = 1.62824170038242295e-03 * DAYS_PER_YEAR,
+ mutable vz = -9.51592254519715870e-05 * DAYS_PER_YEAR,
+ mass = 5.15138902046611451e-05 * SOLAR_MASS
+ );
+ }
+
+ fn sun() -> Body::props {
+ ret rec(
+ mutable x = 0.0,
+ mutable y = 0.0,
+ mutable z = 0.0,
+ mutable vx = 0.0,
+ mutable vy = 0.0,
+ mutable vz = 0.0,
+ mass = SOLAR_MASS
+ );
+ }
+
+ fn offsetMomentum(&Body::props props,
+ float px,
+ float py,
+ float pz) -> () {
+ props.vx = -px / SOLAR_MASS;
+ props.vy = -py / SOLAR_MASS;
+ props.vz = -pz / SOLAR_MASS;
+ }
+
+}
--- /dev/null
+// -*- rust -*-
+
+/*
+ A parallel version of fibonacci numbers.
+
+ This version is meant mostly as a way of stressing and benchmarking
+ the task system. It supports a lot of command-line arguments to
+ control how it runs.
+
+*/
+
+use std;
+
+import std::vec;
+import std::uint;
+import std::time;
+import std::str;
+import std::int::range;
+import std::io;
+import std::getopts;
+import std::task;
+import std::u64;
+
+fn recv[T](&port[T] p) -> T {
+ let T x;
+ p |> x;
+ ret x;
+}
+
+fn fib(int n) -> int {
+ fn pfib(chan[int] c, int n) {
+ if (n == 0) {
+ c <| 0;
+ }
+ else if (n <= 2) {
+ c <| 1;
+ }
+ else {
+ auto p = port();
+
+ auto t1 = spawn pfib(chan(p), n - 1);
+ auto t2 = spawn pfib(chan(p), n - 2);
+
+ c <| recv(p) + recv(p);
+ }
+ }
+
+ auto p = port();
+ auto t = spawn pfib(chan(p), n);
+ ret recv(p);
+}
+
+type config = rec(bool stress);
+
+fn parse_opts(vec[str] argv) -> config {
+ auto opts = [getopts::optflag("stress")];
+
+ auto opt_args = vec::slice(argv, 1u, vec::len(argv));
+
+ alt(getopts::getopts(opt_args, opts)) {
+ case(getopts::success(?m)) {
+ ret rec(stress = getopts::opt_present(m, "stress"))
+ }
+ case(getopts::failure(_)) {
+ fail;
+ }
+ }
+}
+
+fn stress_task(int id) {
+ auto i = 0;
+ while(true) {
+ auto n = 15;
+ assert(fib(n) == fib(n));
+ i += 1;
+ log_err #fmt("%d: Completed %d iterations", id, i);
+ }
+}
+
+fn stress(int num_tasks) {
+ auto tasks = [];
+ for each(int i in range(0, num_tasks)) {
+ tasks += [spawn stress_task(i)];
+ }
+ for each(int i in range(0, num_tasks)) {
+ task::join(tasks.(i));
+ }
+}
+
+fn main(vec[str] argv) {
+ if(vec::len(argv) == 1u) {
+ assert (fib(8) == 21);
+ log fib(8);
+ }
+ else {
+ // Interactive mode! Wooo!!!!
+ auto opts = parse_opts(argv);
+
+ if(opts.stress) {
+ stress(2);
+ }
+ else {
+ auto max = uint::parse_buf(str::bytes(argv.(1)), 10u) as int;
+
+ auto num_trials = 10;
+
+ auto out = io::stdout();
+
+ for each(int n in range(1, max + 1)) {
+ for each(int i in range(0, num_trials)) {
+ auto start = time::precise_time_ns();
+ auto fibn = fib(n);
+ auto stop = time::precise_time_ns();
+
+ auto elapsed = stop - start;
+
+ out.write_line(#fmt("%d\t%d\t%s", n, fibn,
+ u64::str(elapsed)));
+ }
+ }
+ }
+ }
+}
+++ /dev/null
-
-
-
-// -*- rust -*-
-fn ack(int m, int n) -> int {
- if (m == 0) {
- ret n + 1;
- } else {
- if (n == 0) {
- ret ack(m - 1, 1);
- } else { ret ack(m - 1, ack(m, n - 1)); }
- }
-}
-
-fn main() {
- assert (ack(0, 0) == 1);
- assert (ack(3, 2) == 29);
- assert (ack(3, 4) == 125);
- // This takes a while; but a comparison may amuse: on win32 at least, the
- // posted C version of the 'benchmark' running ack(4,1) overruns its stack
- // segment and crashes. We just grow our stack (to 4mb) as we go.
-
- // assert (ack(4,1) == 65533);
-
-}
\ No newline at end of file
+++ /dev/null
-
-use std;
-import std::int;
-
-tag tree { nil; node(@tree, @tree, int); }
-
-fn item_check(@tree t) -> int {
- alt (*t) {
- case (nil) { ret 0; }
- case (node(?left, ?right, ?item)) {
- ret item + item_check(left) - item_check(right);
- }
- }
-}
-
-fn bottom_up_tree(int item, int depth) -> @tree {
- if (depth > 0) {
- ret @node(bottom_up_tree(2 * item - 1, depth - 1),
- bottom_up_tree(2 * item, depth - 1), item);
- } else { ret @nil; }
-}
-
-fn main() {
- auto n = 8;
- auto min_depth = 4;
- auto max_depth;
- if (min_depth + 2 > n) {
- max_depth = min_depth + 2;
- } else { max_depth = n; }
- auto stretch_depth = max_depth + 1;
- auto stretch_tree = bottom_up_tree(0, stretch_depth);
- log #fmt("stretch tree of depth %d\t check: %d", stretch_depth,
- item_check(stretch_tree));
- auto long_lived_tree = bottom_up_tree(0, max_depth);
- auto depth = min_depth;
- while (depth <= max_depth) {
- auto iterations = int::pow(2, max_depth - depth + min_depth as uint);
- auto chk = 0;
- auto i = 1;
- while (i <= iterations) {
- auto temp_tree = bottom_up_tree(i, depth);
- chk += item_check(temp_tree);
- temp_tree = bottom_up_tree(-i, depth);
- chk += item_check(temp_tree);
- i += 1;
- }
- log #fmt("%d\t trees of depth %d\t check: %d", iterations * 2, depth,
- chk);
- depth += 2;
- }
- log #fmt("long lived trees of depth %d\t check: %d", max_depth,
- item_check(long_lived_tree));
-}
\ No newline at end of file
+++ /dev/null
-
-
-// Based on Isaac Gouy's fannkuchredux.csharp
-use std;
-import std::int;
-import std::vec;
-
-fn fannkuch(int n) -> int {
- fn perm1init(uint i) -> int { ret i as int; }
- auto perm1init_ = perm1init; // Rustboot workaround
-
- auto perm = vec::init_elt_mut(0, n as uint);
- auto perm1 = vec::init_fn_mut(perm1init_, n as uint);
- auto count = vec::init_elt_mut(0, n as uint);
- auto f = 0;
- auto i = 0;
- auto k = 0;
- auto r = 0;
- auto flips = 0;
- auto nperm = 0;
- auto checksum = 0;
- r = n;
- while (r > 0) {
- i = 0;
- while (r != 1) { count.(r - 1) = r; r -= 1; }
- while (i < n) { perm.(i) = perm1.(i); i += 1; }
- // Count flips and update max and checksum
-
- f = 0;
- k = perm.(0);
- while (k != 0) {
- i = 0;
- while (2 * i < k) {
- auto t = perm.(i);
- perm.(i) = perm.(k - i);
- perm.(k - i) = t;
- i += 1;
- }
- k = perm.(0);
- f += 1;
- }
- if (f > flips) { flips = f; }
- if (nperm & 0x1 == 0) { checksum += f; } else { checksum -= f; }
- // Use incremental change to generate another permutation
-
- auto go = true;
- while (go) {
- if (r == n) { log checksum; ret flips; }
- auto p0 = perm1.(0);
- i = 0;
- while (i < r) { auto j = i + 1; perm1.(i) = perm1.(j); i = j; }
- perm1.(r) = p0;
- count.(r) -= 1;
- if (count.(r) > 0) { go = false; } else { r += 1; }
- }
- nperm += 1;
- }
- ret flips;
-}
-
-fn main(vec[str] args) {
- auto n = 7;
- log #fmt("Pfannkuchen(%d) = %d", n, fannkuch(n));
-}
\ No newline at end of file
+++ /dev/null
-
-
-/* -*- mode: rust; indent-tabs-mode: nil -*-
- * Implementation of 'fasta' benchmark from
- * Computer Language Benchmarks Game
- * http://shootout.alioth.debian.org/
- */
-use std;
-import std::vec;
-import std::str;
-import std::uint;
-import std::int;
-
-fn LINE_LENGTH() -> uint { ret 60u; }
-
-obj myrandom(mutable u32 last) {
- fn next(u32 mx) -> u32 {
- last = (last * 3877u32 + 29573u32) % 139968u32;
- auto ans = mx * last / 139968u32;
- ret ans;
- }
-}
-
-type aminoacids = tup(char, u32);
-
-fn make_cumulative(vec[aminoacids] aa) -> vec[aminoacids] {
- let u32 cp = 0u32;
- let vec[aminoacids] ans = [];
- for (aminoacids a in aa) { cp += a._1; ans += [tup(a._0, cp)]; }
- ret ans;
-}
-
-fn select_random(u32 r, vec[aminoacids] genelist) -> char {
- if (r < genelist.(0)._1) { ret genelist.(0)._0; }
- fn bisect(vec[aminoacids] v, uint lo, uint hi, u32 target) -> char {
- if (hi > lo + 1u) {
- let uint mid = lo + (hi - lo) / 2u;
- if (target < v.(mid)._1) {
- be bisect(v, lo, mid, target);
- } else { be bisect(v, mid, hi, target); }
- } else { ret v.(hi)._0; }
- }
- ret bisect(genelist, 0u, vec::len[aminoacids](genelist) - 1u, r);
-}
-
-fn make_random_fasta(str id, str desc, vec[aminoacids] genelist, int n) {
- log ">" + id + " " + desc;
- auto rng = myrandom(std::rand::mk_rng().next());
- let str op = "";
- for each (uint i in uint::range(0u, n as uint)) {
- str::push_byte(op, select_random(rng.next(100u32), genelist) as u8);
- if (str::byte_len(op) >= LINE_LENGTH()) { log op; op = ""; }
- }
- if (str::byte_len(op) > 0u) { log op; }
-}
-
-fn make_repeat_fasta(str id, str desc, str s, int n) {
- log ">" + id + " " + desc;
- let str op = "";
- let uint sl = str::byte_len(s);
- for each (uint i in uint::range(0u, n as uint)) {
- str::push_byte(op, s.(i % sl));
- if (str::byte_len(op) >= LINE_LENGTH()) { log op; op = ""; }
- }
- if (str::byte_len(op) > 0u) { log op; }
-}
-
-fn main(vec[str] args) {
- let vec[aminoacids] iub =
- make_cumulative([tup('a', 27u32), tup('c', 12u32), tup('g', 12u32),
- tup('t', 27u32), tup('B', 2u32), tup('D', 2u32),
- tup('H', 2u32), tup('K', 2u32), tup('M', 2u32),
- tup('N', 2u32), tup('R', 2u32), tup('S', 2u32),
- tup('V', 2u32), tup('W', 2u32), tup('Y', 2u32)]);
- let vec[aminoacids] homosapiens =
- make_cumulative([tup('a', 30u32), tup('c', 20u32), tup('g', 20u32),
- tup('t', 30u32)]);
- let str alu =
- "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
- "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
- "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
- "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
- "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
- "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
- "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
- let int n = 512;
- make_repeat_fasta("ONE", "Homo sapiens alu", alu, n * 2);
- make_random_fasta("TWO", "IUB ambiguity codes", iub, n * 3);
- make_random_fasta("THREE", "Homo sapiens frequency", homosapiens, n * 5);
-}
\ No newline at end of file
+++ /dev/null
-
-
-
-// -*- rust -*-
-fn fib(int n) -> int {
-
- // Several of the posted 'benchmark' versions of this compute the
- // wrong Fibonacci numbers, of course.
- if (n == 0) {
- ret 0;
- } else { if (n <= 2) { ret 1; } else { ret fib(n - 1) + fib(n - 2); } }
-}
-
-fn main() {
- assert (fib(8) == 21);
- assert (fib(15) == 610);
- log fib(8);
- log fib(15);
-}
\ No newline at end of file
+++ /dev/null
-// based on:
-// http://shootout.alioth.debian.org/u32/benchmark.php?test=nbody&lang=java
-
-native "llvm" mod llvm {
- fn sqrt(float n) -> float = "sqrt.f64";
-}
-
-fn main() {
-
- let vec[int] inputs = [
- 50000,
- 500000
- //
- // Leave these commented out to
- // finish in a reasonable time
- // during 'make check' under valgrind
- // 5000000
- // 50000000
- ];
-
- let vec[Body::props] bodies = NBodySystem::MakeNBodySystem();
-
- for (int n in inputs) {
- log NBodySystem::energy(bodies);
-
- let int i = 0;
- while (i < n) {
- NBodySystem::advance(bodies, 0.01);
- i += 1;
- }
- log NBodySystem::energy(bodies);
- }
-}
-
-// Body::props is a record of floats, so
-// vec[Body::props] is a vector of records of floats
-
-mod NBodySystem {
-
- fn MakeNBodySystem() -> vec[Body::props] {
- let vec[Body::props] bodies = [
- // these each return a Body::props
- Body::sun(),
- Body::jupiter(),
- Body::saturn(),
- Body::uranus(),
- Body::neptune()];
-
- let float px = 0.0;
- let float py = 0.0;
- let float pz = 0.0;
-
- let int i = 0;
- while (i < 5) {
- px += bodies.(i).vx * bodies.(i).mass;
- py += bodies.(i).vy * bodies.(i).mass;
- pz += bodies.(i).vz * bodies.(i).mass;
-
- i += 1;
- }
-
- // side-effecting
- Body::offsetMomentum(bodies.(0), px, py, pz);
-
- ret bodies;
- }
-
- fn advance(vec[Body::props] bodies, float dt) -> () {
-
- let int i = 0;
- while (i < 5) {
- let int j = i+1;
- while (j < 5) {
- advance_one(bodies.(i), bodies.(j), dt);
- j += 1;
- }
-
- i += 1;
- }
-
- i = 0;
- while (i < 5) {
- move(bodies.(i), dt);
- i += 1;
- }
- }
-
- fn advance_one(&Body::props bi, &Body::props bj, float dt) {
- let float dx = bi.x - bj.x;
- let float dy = bi.y - bj.y;
- let float dz = bi.z - bj.z;
-
- let float dSquared = dx * dx + dy * dy + dz * dz;
-
- let float distance = llvm::sqrt(dSquared);
- let float mag = dt / (dSquared * distance);
-
- bi.vx -= dx * bj.mass * mag;
- bi.vy -= dy * bj.mass * mag;
- bi.vz -= dz * bj.mass * mag;
-
- bj.vx += dx * bi.mass * mag;
- bj.vy += dy * bi.mass * mag;
- bj.vz += dz * bi.mass * mag;
- }
-
- fn move(&Body::props b, float dt) {
- b.x += dt * b.vx;
- b.y += dt * b.vy;
- b.z += dt * b.vz;
- }
-
- fn energy(vec[Body::props] bodies) -> float {
- let float dx;
- let float dy;
- let float dz;
- let float distance;
- let float e = 0.0;
-
- let int i = 0;
- while (i < 5) {
- e += 0.5 * bodies.(i).mass *
- ( bodies.(i).vx * bodies.(i).vx
- + bodies.(i).vy * bodies.(i).vy
- + bodies.(i).vz * bodies.(i).vz );
-
- let int j = i+1;
- while (j < 5) {
- dx = bodies.(i).x - bodies.(j).x;
- dy = bodies.(i).y - bodies.(j).y;
- dz = bodies.(i).z - bodies.(j).z;
-
- distance = llvm::sqrt(dx*dx + dy*dy + dz*dz);
- e -= (bodies.(i).mass * bodies.(j).mass) / distance;
-
- j += 1;
- }
-
- i += 1;
- }
- ret e;
-
- }
-}
-
-mod Body {
-
- const float PI = 3.141592653589793;
- const float SOLAR_MASS = 39.478417604357432; // was 4 * PI * PI originally
- const float DAYS_PER_YEAR = 365.24;
-
- type props = rec(mutable float x,
- mutable float y,
- mutable float z,
- mutable float vx,
- mutable float vy,
- mutable float vz,
- float mass);
-
- fn jupiter() -> Body::props {
- ret rec(
- mutable x = 4.84143144246472090e+00,
- mutable y = -1.16032004402742839e+00,
- mutable z = -1.03622044471123109e-01,
- mutable vx = 1.66007664274403694e-03 * DAYS_PER_YEAR,
- mutable vy = 7.69901118419740425e-03 * DAYS_PER_YEAR,
- mutable vz = -6.90460016972063023e-05 * DAYS_PER_YEAR,
- mass = 9.54791938424326609e-04 * SOLAR_MASS
- );
- }
-
- fn saturn() -> Body::props {
- ret rec(
- mutable x = 8.34336671824457987e+00,
- mutable y = 4.12479856412430479e+00,
- mutable z = -4.03523417114321381e-01,
- mutable vx = -2.76742510726862411e-03 * DAYS_PER_YEAR,
- mutable vy = 4.99852801234917238e-03 * DAYS_PER_YEAR,
- mutable vz = 2.30417297573763929e-05 * DAYS_PER_YEAR,
- mass = 2.85885980666130812e-04 * SOLAR_MASS
- );
- }
-
- fn uranus() -> Body::props {
- ret rec(
- mutable x = 1.28943695621391310e+01,
- mutable y = -1.51111514016986312e+01,
- mutable z = -2.23307578892655734e-01,
- mutable vx = 2.96460137564761618e-03 * DAYS_PER_YEAR,
- mutable vy = 2.37847173959480950e-03 * DAYS_PER_YEAR,
- mutable vz = -2.96589568540237556e-05 * DAYS_PER_YEAR,
- mass = 4.36624404335156298e-05 * SOLAR_MASS
- );
- }
-
- fn neptune() -> Body::props {
- ret rec(
- mutable x = 1.53796971148509165e+01,
- mutable y = -2.59193146099879641e+01,
- mutable z = 1.79258772950371181e-01,
- mutable vx = 2.68067772490389322e-03 * DAYS_PER_YEAR,
- mutable vy = 1.62824170038242295e-03 * DAYS_PER_YEAR,
- mutable vz = -9.51592254519715870e-05 * DAYS_PER_YEAR,
- mass = 5.15138902046611451e-05 * SOLAR_MASS
- );
- }
-
- fn sun() -> Body::props {
- ret rec(
- mutable x = 0.0,
- mutable y = 0.0,
- mutable z = 0.0,
- mutable vx = 0.0,
- mutable vy = 0.0,
- mutable vz = 0.0,
- mass = SOLAR_MASS
- );
- }
-
- fn offsetMomentum(&Body::props props,
- float px,
- float py,
- float pz) -> () {
- props.vx = -px / SOLAR_MASS;
- props.vy = -py / SOLAR_MASS;
- props.vz = -pz / SOLAR_MASS;
- }
-
-}
+++ /dev/null
-// -*- rust -*-
-
-/*
- A parallel version of fibonacci numbers.
-*/
-
-use std;
-
-import std::vec;
-import std::uint;
-import std::time;
-import std::str;
-
-fn recv[T](&port[T] p) -> T {
- let T x;
- p |> x;
- ret x;
-}
-
-fn fib(int n) -> int {
- fn pfib(chan[int] c, int n) {
- if (n == 0) {
- c <| 0;
- }
- else if (n <= 2) {
- c <| 1;
- }
- else {
- let port[int] p = port();
-
- auto t1 = spawn pfib(chan(p), n - 1);
- auto t2 = spawn pfib(chan(p), n - 2);
-
- c <| recv(p) + recv(p);
- }
- }
-
- let port[int] p = port();
- auto t = spawn pfib(chan(p), n);
- ret recv(p);
-}
-
-fn main(vec[str] argv) {
- if(vec::len(argv) == 1u) {
- assert (fib(8) == 21);
- //assert (fib(15) == 610);
- log fib(8);
- //log fib(15);
- }
- else {
- // Interactive mode! Wooo!!!!
-
- auto n = uint::parse_buf(str::bytes(argv.(1)), 10u) as int;
- auto start = time::precise_time_ns();
- auto fibn = fib(n);
- auto stop = time::precise_time_ns();
-
- assert(stop >= start);
-
- auto elapsed = stop - start;
- auto us_task = elapsed / (fibn as u64) / (1000 as u64);
-
- log_err #fmt("Determined that fib(%d) = %d in %d%d ns (%d us / task)",
- n, fibn,
- (elapsed / (1000000 as u64)) as int,
- (elapsed % (1000000 as u64)) as int,
- us_task as int);
- }
-}
--- /dev/null
+// xfail-stage1
+// xfail-stage2
+// xfail-stage3
+/**
+ A parallel word-frequency counting program.
+
+ This is meant primarily to demonstrate Rust's MapReduce framework.
+
+ It takes a list of files on the command line and outputs a list of
+ words along with how many times each word is used.
+
+*/
+
+use std;
+
+import std::io;
+import option = std::option::t;
+import std::option::some;
+import std::option::none;
+import std::str;
+import std::vec;
+import std::map;
+import std::ivec;
+
+import std::time;
+import std::u64;
+
+import std::task;
+import clone = std::task::clone_chan;
+
+fn map(str filename, map_reduce::putter emit) {
+ // log_err "mapping " + filename;
+ auto f = io::file_reader(filename);
+
+ while(true) {
+ alt(read_word(f)) {
+ case (some(?w)) {
+ emit(w, 1);
+ }
+ case (none) {
+ break;
+ }
+ }
+ }
+ // log_err "done mapping " + filename;
+}
+
+fn reduce(str word, map_reduce::getter get) {
+ // log_err "reducing " + word;
+ auto count = 0;
+
+ while(true) {
+ alt(get()) {
+ some(_) {
+ // log_err "received word " + word;
+ count += 1;
+ }
+ none { break }
+ }
+ }
+
+ // auto out = io::stdout();
+ // out.write_line(#fmt("%s: %d", word, count));
+
+ // log_err "reduce " + word + " done.";
+}
+
+mod map_reduce {
+ export putter;
+ export getter;
+ export mapper;
+ export reducer;
+ export map_reduce;
+
+ type putter = fn(str, int) -> ();
+
+ type mapper = fn(str, putter);
+
+ type getter = fn() -> option[int];
+
+ type reducer = fn(str, getter);
+
+ tag ctrl_proto {
+ find_reducer(u8[], chan[chan[reduce_proto]]);
+ mapper_done;
+ }
+
+ tag reduce_proto {
+ emit_val(int);
+ done;
+ ref;
+ release;
+ }
+
+ fn start_mappers(chan[ctrl_proto] ctrl,
+ vec[str] inputs) -> task[] {
+ auto tasks = ~[];
+ // log_err "starting mappers";
+ for(str i in inputs) {
+ // log_err "starting mapper for " + i;
+ tasks += ~[spawn map_task(ctrl, i)];
+ }
+ // log_err "done starting mappers";
+ ret tasks;
+ }
+
+ fn map_task(chan[ctrl_proto] ctrl,
+ str input) {
+ // log_err "map_task " + input;
+ auto intermediates = map::new_str_hash();
+
+ fn emit(&map::hashmap[str, chan[reduce_proto]] im,
+ chan[ctrl_proto] ctrl,
+ str key, int val) {
+ // log_err "emitting " + key;
+ auto c;
+ alt(im.find(key)) {
+ some(?_c) {
+ // log_err "reusing saved channel for " + key;
+ c = _c
+ }
+ none {
+ // log_err "fetching new channel for " + key;
+ auto p = port[chan[reduce_proto]]();
+ auto keyi = str::bytes_ivec(key);
+ ctrl <| find_reducer(keyi, chan(p));
+ p |> c;
+ im.insert(key, clone(c));
+ c <| ref;
+ }
+ }
+ c <| emit_val(val);
+ }
+
+ map(input, bind emit(intermediates, ctrl, _, _));
+
+ for each(@tup(str, chan[reduce_proto]) kv in intermediates.items()) {
+ // log_err "sending done to reducer for " + kv._0;
+ kv._1 <| release;
+ }
+
+ ctrl <| mapper_done;
+
+ // log_err "~map_task " + input;
+ }
+
+ fn reduce_task(str key, chan[chan[reduce_proto]] out) {
+ // log_err "reduce_task " + key;
+ auto p = port();
+
+ out <| chan(p);
+
+ auto ref_count = 0;
+ auto is_done = false;
+
+ fn get(&port[reduce_proto] p, &mutable int ref_count,
+ &mutable bool is_done) -> option[int] {
+ while (!is_done || ref_count > 0) {
+ auto m;
+ p |> m;
+
+ alt(m) {
+ emit_val(?v) {
+ // log_err #fmt("received %d", v);
+ ret some(v);
+ }
+ done {
+ // log_err "all done";
+ is_done = true;
+ }
+ ref {
+ ref_count += 1;
+ }
+ release {
+ ref_count -= 1;
+ }
+ }
+ }
+ ret none;
+ }
+
+ reduce(key, bind get(p, ref_count, is_done));
+ // log_err "~reduce_task " + key;
+ }
+
+ fn map_reduce (vec[str] inputs) {
+ auto ctrl = port[ctrl_proto]();
+
+ // This task becomes the master control task. It spawns others
+ // to do the rest.
+
+ let map::hashmap[str, chan[reduce_proto]] reducers;
+
+ reducers = map::new_str_hash();
+
+ auto tasks = start_mappers(chan(ctrl), inputs);
+
+ auto num_mappers = vec::len(inputs) as int;
+
+ while(num_mappers > 0) {
+ auto m;
+ ctrl |> m;
+
+ alt(m) {
+ mapper_done {
+ // log_err "received mapper terminated.";
+ num_mappers -= 1;
+ }
+ find_reducer(?ki, ?cc) {
+ auto c;
+ auto k = str::unsafe_from_bytes_ivec(ki);
+ // log_err "finding reducer for " + k;
+ alt(reducers.find(k)) {
+ some(?_c) {
+ // log_err "reusing existing reducer for " + k;
+ c = _c;
+ }
+ none {
+ // log_err "creating new reducer for " + k;
+ auto p = port();
+ tasks += ~[spawn reduce_task(k, chan(p))];
+ p |> c;
+ reducers.insert(k, c);
+ }
+ }
+ cc <| clone(c);
+ }
+ }
+ }
+
+ for each(@tup(str, chan[reduce_proto]) kv in reducers.items()) {
+ // log_err "sending done to reducer for " + kv._0;
+ kv._1 <| done;
+ }
+
+ // log_err #fmt("joining %u tasks", ivec::len(tasks));
+ for (task t in tasks) {
+ task::join(t);
+ }
+ // log_err "control task done.";
+ }
+}
+
+fn main(vec[str] argv) {
+ if(vec::len(argv) < 2u) {
+ auto out = io::stdout();
+
+ out.write_line(#fmt("Usage: %s <filename> ...", argv.(0)));
+ fail;
+ }
+
+ auto start = time::precise_time_ns();
+ map_reduce::map_reduce(vec::slice(argv, 1u, vec::len(argv)));
+ auto stop = time::precise_time_ns();
+
+ auto elapsed = stop - start;
+ elapsed /= 1000000u64;
+
+ log_err "MapReduce completed in " + u64::str(elapsed) + "ms";
+}
+
+fn read_word(io::reader r) -> option[str] {
+ auto w = "";
+
+ while(!r.eof()) {
+ auto c = r.read_char();
+
+ if(is_word_char(c)) {
+ w += str::from_char(c);
+ }
+ else {
+ if(w != "") {
+ ret some(w);
+ }
+ }
+ }
+ ret none;
+}
+
+fn is_digit(char c) -> bool {
+ alt(c) {
+ case ('0') { true }
+ case ('1') { true }
+ case ('2') { true }
+ case ('3') { true }
+ case ('4') { true }
+ case ('5') { true }
+ case ('6') { true }
+ case ('7') { true }
+ case ('8') { true }
+ case ('9') { true }
+ case (_) { false }
+ }
+}
+
+fn is_alpha_lower (char c) -> bool {
+ alt(c) {
+ case ('a') { true }
+ case ('b') { true }
+ case ('c') { true }
+ case ('d') { true }
+ case ('e') { true }
+ case ('f') { true }
+ case ('g') { true }
+ case ('h') { true }
+ case ('i') { true }
+ case ('j') { true }
+ case ('k') { true }
+ case ('l') { true }
+ case ('m') { true }
+ case ('n') { true }
+ case ('o') { true }
+ case ('p') { true }
+ case ('q') { true }
+ case ('r') { true }
+ case ('s') { true }
+ case ('t') { true }
+ case ('u') { true }
+ case ('v') { true }
+ case ('w') { true }
+ case ('x') { true }
+ case ('y') { true }
+ case ('z') { true }
+ case (_) { false }
+ }
+}
+
+fn is_alpha_upper (char c) -> bool {
+ alt(c) {
+ case ('A') { true }
+ case ('B') { true }
+ case ('C') { true }
+ case ('D') { true }
+ case ('E') { true }
+ case ('F') { true }
+ case ('G') { true }
+ case ('H') { true }
+ case ('I') { true }
+ case ('J') { true }
+ case ('K') { true }
+ case ('L') { true }
+ case ('M') { true }
+ case ('N') { true }
+ case ('O') { true }
+ case ('P') { true }
+ case ('Q') { true }
+ case ('R') { true }
+ case ('S') { true }
+ case ('T') { true }
+ case ('U') { true }
+ case ('V') { true }
+ case ('W') { true }
+ case ('X') { true }
+ case ('Y') { true }
+ case ('Z') { true }
+ case (_) { false }
+ }
+}
+
+fn is_alpha(char c) -> bool {
+ is_alpha_upper(c) || is_alpha_lower(c)
+}
+
+fn is_word_char(char c) -> bool {
+ is_alpha(c) || is_digit(c) || c == '_'
+}
\ No newline at end of file
+++ /dev/null
-// -*- rust -*-
-
-/*
- A parallel version of fibonacci numbers.
-
- This version is meant mostly as a way of stressing and benchmarking
- the task system. It supports a lot of command-line arguments to
- control how it runs.
-
-*/
-
-use std;
-
-import std::vec;
-import std::uint;
-import std::time;
-import std::str;
-import std::int::range;
-import std::io;
-import std::getopts;
-import std::task;
-import std::u64;
-
-fn recv[T](&port[T] p) -> T {
- let T x;
- p |> x;
- ret x;
-}
-
-fn fib(int n) -> int {
- fn pfib(chan[int] c, int n) {
- if (n == 0) {
- c <| 0;
- }
- else if (n <= 2) {
- c <| 1;
- }
- else {
- auto p = port();
-
- auto t1 = spawn pfib(chan(p), n - 1);
- auto t2 = spawn pfib(chan(p), n - 2);
-
- c <| recv(p) + recv(p);
- }
- }
-
- auto p = port();
- auto t = spawn pfib(chan(p), n);
- ret recv(p);
-}
-
-type config = rec(bool stress);
-
-fn parse_opts(vec[str] argv) -> config {
- auto opts = [getopts::optflag("stress")];
-
- auto opt_args = vec::slice(argv, 1u, vec::len(argv));
-
- alt(getopts::getopts(opt_args, opts)) {
- case(getopts::success(?m)) {
- ret rec(stress = getopts::opt_present(m, "stress"))
- }
- case(getopts::failure(_)) {
- fail;
- }
- }
-}
-
-fn stress_task(int id) {
- auto i = 0;
- while(true) {
- auto n = 15;
- assert(fib(n) == fib(n));
- i += 1;
- log_err #fmt("%d: Completed %d iterations", id, i);
- }
-}
-
-fn stress(int num_tasks) {
- auto tasks = [];
- for each(int i in range(0, num_tasks)) {
- tasks += [spawn stress_task(i)];
- }
- for each(int i in range(0, num_tasks)) {
- task::join(tasks.(i));
- }
-}
-
-fn main(vec[str] argv) {
- if(vec::len(argv) == 1u) {
- assert (fib(8) == 21);
- assert (fib(15) == 610);
- log fib(8);
- log fib(15);
- }
- else {
- // Interactive mode! Wooo!!!!
- auto opts = parse_opts(argv);
-
- if(opts.stress) {
- stress(2);
- }
- else {
- auto max = uint::parse_buf(str::bytes(argv.(1)), 10u) as int;
-
- auto num_trials = 10;
-
- auto out = io::stdout();
-
- for each(int n in range(1, max + 1)) {
- for each(int i in range(0, num_trials)) {
- auto start = time::precise_time_ns();
- auto fibn = fib(n);
- auto stop = time::precise_time_ns();
-
- auto elapsed = stop - start;
-
- out.write_line(#fmt("%d\t%d\t%s", n, fibn,
- u64::str(elapsed)));
- }
- }
- }
- }
-}
+++ /dev/null
-/**
- A parallel word-frequency counting program.
-
- This is meant primarily to demonstrate Rust's MapReduce framework.
-
- It takes a list of files on the command line and outputs a list of
- words along with how many times each word is used.
-
-*/
-
-use std;
-
-import std::io;
-import option = std::option::t;
-import std::option::some;
-import std::option::none;
-import std::str;
-import std::vec;
-import std::map;
-import std::ivec;
-
-import std::time;
-import std::u64;
-
-import std::task;
-import clone = std::task::clone_chan;
-
-fn map(str filename, map_reduce::putter emit) {
- // log_err "mapping " + filename;
- auto f = io::file_reader(filename);
-
- while(true) {
- alt(read_word(f)) {
- case (some(?w)) {
- emit(w, 1);
- }
- case (none) {
- break;
- }
- }
- }
- // log_err "done mapping " + filename;
-}
-
-fn reduce(str word, map_reduce::getter get) {
- // log_err "reducing " + word;
- auto count = 0;
-
- while(true) {
- alt(get()) {
- some(_) {
- // log_err "received word " + word;
- count += 1;
- }
- none { break }
- }
- }
-
- // auto out = io::stdout();
- // out.write_line(#fmt("%s: %d", word, count));
-
- // log_err "reduce " + word + " done.";
-}
-
-mod map_reduce {
- export putter;
- export getter;
- export mapper;
- export reducer;
- export map_reduce;
-
- type putter = fn(str, int) -> ();
-
- type mapper = fn(str, putter);
-
- type getter = fn() -> option[int];
-
- type reducer = fn(str, getter);
-
- tag ctrl_proto {
- find_reducer(u8[], chan[chan[reduce_proto]]);
- mapper_done;
- }
-
- tag reduce_proto {
- emit_val(int);
- done;
- ref;
- release;
- }
-
- fn start_mappers(chan[ctrl_proto] ctrl,
- vec[str] inputs) -> task[] {
- auto tasks = ~[];
- // log_err "starting mappers";
- for(str i in inputs) {
- // log_err "starting mapper for " + i;
- tasks += ~[spawn map_task(ctrl, i)];
- }
- // log_err "done starting mappers";
- ret tasks;
- }
-
- fn map_task(chan[ctrl_proto] ctrl,
- str input) {
- // log_err "map_task " + input;
- auto intermediates = map::new_str_hash();
-
- fn emit(&map::hashmap[str, chan[reduce_proto]] im,
- chan[ctrl_proto] ctrl,
- str key, int val) {
- // log_err "emitting " + key;
- auto c;
- alt(im.find(key)) {
- some(?_c) {
- // log_err "reusing saved channel for " + key;
- c = _c
- }
- none {
- // log_err "fetching new channel for " + key;
- auto p = port[chan[reduce_proto]]();
- auto keyi = str::bytes_ivec(key);
- ctrl <| find_reducer(keyi, chan(p));
- p |> c;
- im.insert(key, clone(c));
- c <| ref;
- }
- }
- c <| emit_val(val);
- }
-
- map(input, bind emit(intermediates, ctrl, _, _));
-
- for each(@tup(str, chan[reduce_proto]) kv in intermediates.items()) {
- // log_err "sending done to reducer for " + kv._0;
- kv._1 <| release;
- }
-
- ctrl <| mapper_done;
-
- // log_err "~map_task " + input;
- }
-
- fn reduce_task(str key, chan[chan[reduce_proto]] out) {
- // log_err "reduce_task " + key;
- auto p = port();
-
- out <| chan(p);
-
- auto ref_count = 0;
- auto is_done = false;
-
- fn get(&port[reduce_proto] p, &mutable int ref_count,
- &mutable bool is_done) -> option[int] {
- while (!is_done || ref_count > 0) {
- auto m;
- p |> m;
-
- alt(m) {
- emit_val(?v) {
- // log_err #fmt("received %d", v);
- ret some(v);
- }
- done {
- // log_err "all done";
- is_done = true;
- }
- ref {
- ref_count += 1;
- }
- release {
- ref_count -= 1;
- }
- }
- }
- ret none;
- }
-
- reduce(key, bind get(p, ref_count, is_done));
- // log_err "~reduce_task " + key;
- }
-
- fn map_reduce (vec[str] inputs) {
- auto ctrl = port[ctrl_proto]();
-
- // This task becomes the master control task. It spawns others
- // to do the rest.
-
- let map::hashmap[str, chan[reduce_proto]] reducers;
-
- reducers = map::new_str_hash();
-
- auto tasks = start_mappers(chan(ctrl), inputs);
-
- auto num_mappers = vec::len(inputs) as int;
-
- while(num_mappers > 0) {
- auto m;
- ctrl |> m;
-
- alt(m) {
- mapper_done {
- // log_err "received mapper terminated.";
- num_mappers -= 1;
- }
- find_reducer(?ki, ?cc) {
- auto c;
- auto k = str::unsafe_from_bytes_ivec(ki);
- // log_err "finding reducer for " + k;
- alt(reducers.find(k)) {
- some(?_c) {
- // log_err "reusing existing reducer for " + k;
- c = _c;
- }
- none {
- // log_err "creating new reducer for " + k;
- auto p = port();
- tasks += ~[spawn reduce_task(k, chan(p))];
- p |> c;
- reducers.insert(k, c);
- }
- }
- cc <| clone(c);
- }
- }
- }
-
- for each(@tup(str, chan[reduce_proto]) kv in reducers.items()) {
- // log_err "sending done to reducer for " + kv._0;
- kv._1 <| done;
- }
-
- // log_err #fmt("joining %u tasks", ivec::len(tasks));
- for (task t in tasks) {
- task::join(t);
- }
- // log_err "control task done.";
- }
-}
-
-fn main(vec[str] argv) {
- if(vec::len(argv) < 2u) {
- auto out = io::stdout();
-
- out.write_line(#fmt("Usage: %s <filename> ...", argv.(0)));
- fail;
- }
-
- auto start = time::precise_time_ns();
- map_reduce::map_reduce(vec::slice(argv, 1u, vec::len(argv)));
- auto stop = time::precise_time_ns();
-
- auto elapsed = stop - start;
- elapsed /= 1000000u64;
-
- log_err "MapReduce completed in " + u64::str(elapsed) + "ms";
-}
-
-fn read_word(io::reader r) -> option[str] {
- auto w = "";
-
- while(!r.eof()) {
- auto c = r.read_char();
-
- if(is_word_char(c)) {
- w += str::from_char(c);
- }
- else {
- if(w != "") {
- ret some(w);
- }
- }
- }
- ret none;
-}
-
-fn is_digit(char c) -> bool {
- alt(c) {
- case ('0') { true }
- case ('1') { true }
- case ('2') { true }
- case ('3') { true }
- case ('4') { true }
- case ('5') { true }
- case ('6') { true }
- case ('7') { true }
- case ('8') { true }
- case ('9') { true }
- case (_) { false }
- }
-}
-
-fn is_alpha_lower (char c) -> bool {
- alt(c) {
- case ('a') { true }
- case ('b') { true }
- case ('c') { true }
- case ('d') { true }
- case ('e') { true }
- case ('f') { true }
- case ('g') { true }
- case ('h') { true }
- case ('i') { true }
- case ('j') { true }
- case ('k') { true }
- case ('l') { true }
- case ('m') { true }
- case ('n') { true }
- case ('o') { true }
- case ('p') { true }
- case ('q') { true }
- case ('r') { true }
- case ('s') { true }
- case ('t') { true }
- case ('u') { true }
- case ('v') { true }
- case ('w') { true }
- case ('x') { true }
- case ('y') { true }
- case ('z') { true }
- case (_) { false }
- }
-}
-
-fn is_alpha_upper (char c) -> bool {
- alt(c) {
- case ('A') { true }
- case ('B') { true }
- case ('C') { true }
- case ('D') { true }
- case ('E') { true }
- case ('F') { true }
- case ('G') { true }
- case ('H') { true }
- case ('I') { true }
- case ('J') { true }
- case ('K') { true }
- case ('L') { true }
- case ('M') { true }
- case ('N') { true }
- case ('O') { true }
- case ('P') { true }
- case ('Q') { true }
- case ('R') { true }
- case ('S') { true }
- case ('T') { true }
- case ('U') { true }
- case ('V') { true }
- case ('W') { true }
- case ('X') { true }
- case ('Y') { true }
- case ('Z') { true }
- case (_) { false }
- }
-}
-
-fn is_alpha(char c) -> bool {
- is_alpha_upper(c) || is_alpha_lower(c)
-}
-
-fn is_word_char(char c) -> bool {
- is_alpha(c) || is_digit(c) || c == '_'
-}
\ No newline at end of file
// xfail-stage0
-// error-pattern:expecting \]
+// error-pattern:expecting ]
// asterisk is bogus
#[attr*]
// xfail-stage0
-// error-pattern:\^ cannot be applied to type `str`
+// error-pattern:^ cannot be applied to type `str`
fn main() {
auto x = "a" ^ "b";
// xfail-stage0
-// error-pattern:>> cannot be applied to type `port\[int\]`
+// error-pattern:>> cannot be applied to type `port[int]`
fn main() {
let port[int] p1 = port();
// xfail-stage0
-// error-pattern:\- cannot be applied to type `obj
+// error-pattern:- cannot be applied to type `obj
fn main() {
auto x = obj(){} - obj(){};
// xfail-stage0
-// error-pattern:expecting \[, found fmt
+// error-pattern:expecting [, found fmt
// Don't know how to deal with a syntax extension appearing after an
// item attribute. Probably could use a better error message.
--- /dev/null
+// Checking that the compiler reports multiple type errors at once
+// error-pattern:mismatched types: expected bool
+// error-pattern:mismatched types: expected int
+
+fn main() {
+ let bool a = 1;
+ let int b = true;
+}
\ No newline at end of file
// xfail-stage0
-// error-pattern:attempted field access on type vec\[int\]
+// error-pattern:attempted field access on type vec[int]
// issue #367
fn f() {
--- /dev/null
+use std;
+
+mod compiletest;
+
+// Local Variables:
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+import std::option;
+import std::getopts;
+import std::test;
+import std::fs;
+import std::str;
+import std::vec;
+import std::ivec;
+import std::io;
+import std::generic_os::setenv;
+import std::generic_os::getenv;
+import std::os;
+import std::run;
+
+tag mode {
+ mode_compile_fail;
+ mode_run_fail;
+ mode_run_pass;
+}
+
+type config = rec(// The library paths required for running the compiler
+ str compile_lib_path,
+ // The library paths required for running compiled programs
+ str run_lib_path,
+ // The rustc executable
+ str rustc_path,
+ // The directory containing the tests to run
+ str src_base,
+ // The directory where programs should be built
+ str build_base,
+ // The name of the stage being built (stage1, etc)
+ str stage_id,
+ // The test mode, compile-fail, run-fail, run-pass
+ mode mode,
+ // Run ignored tests
+ bool run_ignored,
+ // Only run tests that match this filter
+ option::t[str] filter,
+ // A command line to prefix program execution with,
+ // for running under valgrind
+ option::t[str] runtool,
+ // Flags to pass to the compiler
+ option::t[str] rustcflags,
+ // Explain what's going on
+ bool verbose);
+
+fn main(vec[str] args) {
+
+ auto ivec_args = {
+ auto ivec_args = ~[];
+ for (str arg in args) {
+ ivec_args += ~[arg];
+ }
+ ivec_args
+ };
+
+ auto config = parse_config(ivec_args);
+ log_config(config);
+ run_tests(config);
+}
+
+fn parse_config(&str[] args) -> config {
+ auto opts = ~[getopts::reqopt("compile-lib-path"),
+ getopts::reqopt("run-lib-path"),
+ getopts::reqopt("rustc-path"),
+ getopts::reqopt("src-base"),
+ getopts::reqopt("build-base"),
+ getopts::reqopt("stage-id"),
+ getopts::reqopt("mode"),
+ getopts::optflag("ignored"),
+ getopts::optopt("runtool"),
+ getopts::optopt("rustcflags"),
+ getopts::optflag("verbose")];
+
+ check ivec::is_not_empty(args);
+ auto args_ = ivec::tail(args);
+ auto match = alt (getopts::getopts_ivec(args_, opts)) {
+ getopts::success(?m) { m }
+ getopts::failure(?f) {
+ fail getopts::fail_str(f)
+ }
+ };
+
+ ret rec(compile_lib_path = getopts::opt_str(match, "compile-lib-path"),
+ run_lib_path = getopts::opt_str(match, "run-lib-path"),
+ rustc_path = getopts::opt_str(match, "rustc-path"),
+ src_base = getopts::opt_str(match, "src-base"),
+ build_base = getopts::opt_str(match, "build-base"),
+ stage_id = getopts::opt_str(match, "stage-id"),
+ mode = alt getopts::opt_str(match, "mode") {
+ "compile-fail" { mode_compile_fail }
+ "run-fail" { mode_run_fail }
+ "run-pass" { mode_run_pass }
+ _ { fail "invalid mode" }
+ },
+ run_ignored = getopts::opt_present(match, "ignored"),
+ filter = if vec::len(match.free) > 0u {
+ option::some(match.free.(0))
+ } else {
+ option::none
+ },
+ runtool = getopts::opt_maybe_str(match, "runtool"),
+ rustcflags = getopts::opt_maybe_str(match, "rustcflags"),
+ verbose = getopts::opt_present(match, "verbose"));
+}
+
+fn log_config(&config config) {
+ auto c = config;
+ logv(c, #fmt("configuration:"));
+ logv(c, #fmt("compile_lib_path: %s", config.compile_lib_path));
+ logv(c, #fmt("run_lib_path: %s", config.run_lib_path));
+ logv(c, #fmt("rustc_path: %s", config.rustc_path));
+ logv(c, #fmt("src_base: %s", config.src_base));;
+ logv(c, #fmt("build_base: %s", config.build_base));
+ logv(c, #fmt("stage_id: %s", config.stage_id));
+ logv(c, #fmt("mode: %s", mode_str(config.mode)));
+ logv(c, #fmt("run_ignored: %b", config.run_ignored));
+ logv(c, #fmt("filter: %s", alt (config.filter) {
+ option::some(?f) { f }
+ option::none { "(none)" }
+ }));
+ logv(c, #fmt("runtool: %s", alt (config.runtool) {
+ option::some(?s) { s }
+ option::none { "(none)" }
+ }));
+ logv(c, #fmt("rustcflags: %s", alt (config.rustcflags) {
+ option::some(?s) { s }
+ option::none { "(none)" }
+ }));
+ logv(c, #fmt("verbose: %b", config.verbose));
+ logv(c, #fmt("\n"));
+}
+
+fn mode_str(mode mode) -> str {
+ alt (mode) {
+ mode_compile_fail { "compile-fail" }
+ mode_run_fail { "run-fail" }
+ mode_run_pass { "run-pass" }
+ }
+}
+
+fn run_tests(&config config) {
+ auto opts = test_opts(config);
+ auto tests = make_tests(config);
+ test::run_tests_console(opts, tests);
+}
+
+fn test_opts(&config config) -> test::test_opts {
+ rec(filter = config.filter,
+ run_ignored = config.run_ignored)
+}
+
+fn make_tests(&config config) -> test::test_desc[] {
+ log #fmt("making tests from %s", config.src_base);
+ auto tests = ~[];
+ for (str file in fs::list_dir(config.src_base)) {
+ log #fmt("inspecting file %s", file);
+ if (is_test(file)) {
+ tests += ~[make_test(config, file)];
+ }
+ }
+ ret tests;
+}
+
+fn is_test(&str testfile) -> bool {
+ str::ends_with(testfile, ".rs") || str::ends_with(testfile, ".rc")
+}
+
+fn make_test(&config config, &str testfile) -> test::test_desc {
+ rec(name = testfile,
+ fn = make_test_fn(config, testfile),
+ ignore = is_test_ignored(config, testfile))
+}
+
+fn is_test_ignored(&config config, &str testfile) -> bool {
+ auto found = false;
+ for each (str ln in iter_header(testfile)) {
+ // FIXME: Can't return or break from iterator
+ found = found || parse_name_directive(ln, "xfail-" + config.stage_id);
+ }
+ ret found;
+}
+
+iter iter_header(&str testfile) -> str {
+ auto rdr = io::file_reader(testfile);
+ while !rdr.eof() {
+ auto ln = rdr.read_line();
+ // Assume that any directives will be found before the
+ // first module or function. This doesn't seem to be an optimization
+ // with a warm page cache. Maybe with a cold one.
+ if str::starts_with(ln, "fn") || str::starts_with(ln, "mod") {
+ break;
+ } else {
+ put ln;
+ }
+ }
+}
+
+fn make_test_fn(&config config, &str testfile) -> test::test_fn {
+ bind run_test(config, testfile)
+}
+
+fn run_test(config config, str testfile) {
+ log #fmt("running %s", testfile);
+ auto props = load_props(testfile);
+ alt (config.mode) {
+ mode_compile_fail {
+ run_cfail_test(config, props, testfile);
+ }
+ mode_run_fail {
+ run_rfail_test(config, props, testfile);
+ }
+ mode_run_pass {
+ run_rpass_test(config, props, testfile);
+ }
+ }
+}
+
+type test_props = rec(str[] error_patterns,
+ option::t[str] compile_flags);
+
+// Load any test directives embedded in the file
+fn load_props(&str testfile) -> test_props {
+ auto error_patterns = ~[];
+ auto compile_flags = option::none;
+ for each (str ln in iter_header(testfile)) {
+ alt parse_error_pattern(ln) {
+ option::some(?ep) { error_patterns += ~[ep]; }
+ option::none { }
+ }
+
+ if option::is_none(compile_flags) {
+ compile_flags = parse_compile_flags(ln);
+ }
+ }
+ ret rec(error_patterns = error_patterns,
+ compile_flags = compile_flags);
+}
+
+fn parse_error_pattern(&str line) -> option::t[str] {
+ parse_name_value_directive(line, "error-pattern")
+}
+
+fn parse_compile_flags(&str line) -> option::t[str] {
+ parse_name_value_directive(line, "compile-flags")
+}
+
+fn parse_name_directive(&str line, &str directive) -> bool {
+ str::find(line, directive) >= 0
+}
+
+fn parse_name_value_directive(&str line, &str directive) -> option::t[str] {
+ auto keycolon = directive + ":";
+ if str::find(line, keycolon) >= 0 {
+ auto colon = str::find(line, keycolon) as uint;
+ auto value = str::slice(line,
+ colon + str::byte_len(keycolon),
+ str::byte_len(line));
+ log #fmt("%s: %s", directive, value);
+ option::some(value)
+ } else {
+ option::none
+ }
+}
+
+fn run_cfail_test(&config config, &test_props props, &str testfile) {
+ auto procres = compile_test(config, props, testfile);
+
+ if (procres.status == 0) {
+ fatal_procres("compile-fail test compiled successfully!", procres);
+ }
+
+ check_error_patterns(props, testfile, procres);
+}
+
+fn run_rfail_test(&config config, &test_props props, &str testfile) {
+ auto procres = compile_test(config, props, testfile);
+
+ if (procres.status != 0) {
+ fatal_procres("compilation failed!", procres);
+ }
+
+ procres = exec_compiled_test(config, testfile);
+
+ if (procres.status == 0) {
+ fatal_procres("run-fail test didn't produce an error!",
+ procres);
+ }
+
+ check_error_patterns(props, testfile, procres);
+}
+
+fn run_rpass_test(&config config, &test_props props, &str testfile) {
+ auto procres = compile_test(config, props, testfile);
+
+ if (procres.status != 0) {
+ fatal_procres("compilation failed!", procres);
+ }
+
+ procres = exec_compiled_test(config, testfile);
+
+ if (procres.status != 0) {
+ fatal_procres("test run failed!", procres);
+ }
+}
+
+fn check_error_patterns(&test_props props, &str testfile,
+ &procres procres) {
+ if ivec::is_empty(props.error_patterns) {
+ fatal("no error pattern specified in " + testfile);
+ }
+
+ auto next_err_idx = 0u;
+ auto next_err_pat = props.error_patterns.(next_err_idx);
+ for (str line in str::split(procres.out, '\n' as u8)) {
+ if (str::find(line, next_err_pat) > 0) {
+ log #fmt("found error pattern %s", next_err_pat);
+ next_err_idx += 1u;
+ if next_err_idx == ivec::len(props.error_patterns) {
+ log "found all error patterns";
+ ret;
+ }
+ next_err_pat = props.error_patterns.(next_err_idx);
+ }
+ }
+
+ auto missing_patterns = ivec::slice(props.error_patterns,
+ next_err_idx,
+ ivec::len(props.error_patterns));
+ if (ivec::len(missing_patterns) == 1u) {
+ fatal_procres(#fmt("error pattern '%s' not found!",
+ missing_patterns.(0)),
+ procres);
+ } else {
+ for (str pattern in missing_patterns) {
+ error(#fmt("error pattern '%s' not found!", pattern));
+ }
+ fatal_procres("multiple error patterns not found", procres);
+ }
+}
+
+type procargs = rec(str prog, vec[str] args);
+
+type procres = rec(int status, str out, str cmdline);
+
+fn compile_test(&config config, &test_props props,
+ &str testfile) -> procres {
+ compose_and_run(config,
+ testfile,
+ bind make_compile_args(_, props, _),
+ config.compile_lib_path)
+}
+
+fn exec_compiled_test(&config config, &str testfile) -> procres {
+ compose_and_run(config,
+ testfile,
+ make_run_args,
+ config.run_lib_path)
+}
+
+fn compose_and_run(&config config, &str testfile,
+ fn(&config, &str) -> procargs make_args,
+ &str lib_path) -> procres {
+ auto procargs = make_args(config, testfile);
+ ret program_output(config, testfile, lib_path,
+ procargs.prog, procargs.args);
+}
+
+fn make_compile_args(&config config, &test_props props,
+ &str testfile) -> procargs {
+ auto prog = config.rustc_path;
+ auto args = [testfile,
+ "-o", make_exe_name(config, testfile)];
+ args += split_maybe_args(config.rustcflags);
+ args += split_maybe_args(props.compile_flags);
+ ret rec(prog = prog,
+ args = args);
+}
+
+fn make_run_args(&config config, &str testfile) -> procargs {
+ // If we've got another tool to run under (valgrind),
+ // then split apart its command
+ auto args = split_maybe_args(config.runtool)
+ + [make_exe_name(config, testfile)];
+ ret rec(prog = args.(0),
+ args = vec::slice(args, 1u, vec::len(args)));
+}
+
+fn split_maybe_args(&option::t[str] argstr) -> vec[str] {
+ alt (argstr) {
+ option::some(?s) { str::split(s, ' ' as u8) }
+ option::none { [] }
+ }
+}
+
+fn program_output(&config config, &str testfile,
+ &str lib_path, &str prog, &vec[str] args) -> procres {
+ auto cmdline = {
+ auto cmdline = make_cmdline(lib_path, prog, args);
+ logv(config, #fmt("running %s", cmdline));
+ cmdline
+ };
+ auto res = with_lib_path(lib_path,
+ bind run::program_output(prog, args));
+ dump_output(config, testfile, res.out);
+ ret rec(status = res.status,
+ out = res.out,
+ cmdline = cmdline);
+}
+
+fn make_cmdline(&str libpath, &str prog, &vec[str] args) -> str {
+ #fmt("%s %s %s",
+ lib_path_cmd_prefix(libpath),
+ prog,
+ str::connect(args, " "))
+}
+
+// Build the LD_LIBRARY_PATH variable as it would be seen on the command line
+// for diagnostic purposes
+fn lib_path_cmd_prefix(&str path) -> str {
+ #fmt("%s=\"%s\"", lib_path_env_var(), make_new_path(path))
+}
+
+fn with_lib_path[T](&str path, fn() -> T f) -> T {
+ auto maybe_oldpath = getenv(lib_path_env_var());
+ append_lib_path(path);
+ auto res = f();
+ if option::is_some(maybe_oldpath) {
+ export_lib_path(option::get(maybe_oldpath));
+ } else {
+ // FIXME: This should really be unset but we don't have that yet
+ export_lib_path("");
+ }
+ ret res;
+}
+
+fn append_lib_path(&str path) {
+ export_lib_path(make_new_path(path));
+}
+
+fn make_new_path(&str path) -> str {
+ // Windows just uses PATH as the library search path, so we have to
+ // maintain the current value while adding our own
+ alt getenv(lib_path_env_var()) {
+ option::some(?curr) { #fmt("%s:%s", path, curr) }
+ option::none { path }
+ }
+}
+
+fn export_lib_path(&str path) {
+ setenv(lib_path_env_var(), path);
+}
+
+#[cfg(target_os = "linux")]
+fn lib_path_env_var() -> str { "LD_LIBRARY_PATH" }
+
+#[cfg(target_os = "macos")]
+fn lib_path_env_var() -> str { "DYLD_LIBRARY_PATH" }
+
+#[cfg(target_os = "win32")]
+fn lib_path_env_var() -> str { "PATH" }
+
+fn make_exe_name(&config config, &str testfile) -> str {
+ output_base_name(config, testfile) + os::exec_suffix()
+}
+
+fn output_base_name(&config config, &str testfile) -> str {
+ auto base = config.build_base;
+ auto filename = {
+ auto parts = str::split(fs::basename(testfile), '.' as u8);
+ parts = vec::slice(parts, 0u, vec::len(parts) - 1u);
+ str::connect(parts, ".")
+ };
+ #fmt("%s%s.%s", base, filename, config.stage_id)
+}
+
+#[cfg(target_os = "win32")]
+#[cfg(target_os = "linux")]
+fn dump_output(&config config, &str testfile, &str out) {
+ auto outfile = make_out_name(config, testfile);
+ auto writer = io::file_writer(outfile, [io::create, io::truncate]);
+ writer.write_str(out);
+}
+
+// FIXME (726): Can't use file_writer on mac
+#[cfg(target_os = "macos")]
+fn dump_output(&config config, &str testfile, &str out) {
+}
+
+fn make_out_name(&config config, &str testfile) -> str {
+ output_base_name(config, testfile) + ".out"
+}
+
+fn error(&str err) {
+ io::stdout().write_line(#fmt("\nerror: %s", err));
+}
+
+fn fatal(&str err) -> ! {
+ error(err);
+ fail;
+}
+
+fn fatal_procres(&str err, procres procres) -> ! {
+ auto msg = #fmt("\n\
+ error: %s\n\
+ command: %s\n\
+ output:\n\
+ ------------------------------------------\n\
+ %s\n\
+ ------------------------------------------\n\
+ \n",
+ err, procres.cmdline, procres.out);
+ io::stdout().write_str(msg);
+ fail;
+}
+
+fn logv(&config config, &str s) {
+ log s;
+ if (config.verbose) {
+ io::stdout().write_line(s);
+ }
+}
+
+// Local Variables:
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
+++ /dev/null
-
-use std;
-import std::vec;
-import std::bitv;
-
-fn test_0_elements() {
- auto act;
- auto exp;
- act = bitv::create(0u, false);
- exp = vec::init_elt[uint](0u, 0u);
- // FIXME: why can't I write vec[uint]()?
-
- assert (bitv::eq_vec(act, exp));
-}
-
-fn test_1_element() {
- auto act;
- act = bitv::create(1u, false);
- assert (bitv::eq_vec(act, [0u]));
- act = bitv::create(1u, true);
- assert (bitv::eq_vec(act, [1u]));
-}
-
-fn test_10_elements() {
- auto act;
- // all 0
-
- act = bitv::create(10u, false);
- assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
- // all 1
-
- act = bitv::create(10u, true);
- assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u]));
- // mixed
-
- act = bitv::create(10u, false);
- bitv::set(act, 0u, true);
- bitv::set(act, 1u, true);
- bitv::set(act, 2u, true);
- bitv::set(act, 3u, true);
- bitv::set(act, 4u, true);
- assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u]));
- // mixed
-
- act = bitv::create(10u, false);
- bitv::set(act, 5u, true);
- bitv::set(act, 6u, true);
- bitv::set(act, 7u, true);
- bitv::set(act, 8u, true);
- bitv::set(act, 9u, true);
- assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u]));
- // mixed
-
- act = bitv::create(10u, false);
- bitv::set(act, 0u, true);
- bitv::set(act, 3u, true);
- bitv::set(act, 6u, true);
- bitv::set(act, 9u, true);
- assert (bitv::eq_vec(act, [1u, 0u, 0u, 1u, 0u, 0u, 1u, 0u, 0u, 1u]));
-}
-
-fn test_31_elements() {
- auto act;
- // all 0
-
- act = bitv::create(31u, false);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u]));
- // all 1
-
- act = bitv::create(31u, true);
- assert (bitv::eq_vec(act,
- [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
- 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
- 1u, 1u, 1u, 1u, 1u]));
- // mixed
-
- act = bitv::create(31u, false);
- bitv::set(act, 0u, true);
- bitv::set(act, 1u, true);
- bitv::set(act, 2u, true);
- bitv::set(act, 3u, true);
- bitv::set(act, 4u, true);
- bitv::set(act, 5u, true);
- bitv::set(act, 6u, true);
- bitv::set(act, 7u, true);
- assert (bitv::eq_vec(act,
- [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u]));
- // mixed
-
- act = bitv::create(31u, false);
- bitv::set(act, 16u, true);
- bitv::set(act, 17u, true);
- bitv::set(act, 18u, true);
- bitv::set(act, 19u, true);
- bitv::set(act, 20u, true);
- bitv::set(act, 21u, true);
- bitv::set(act, 22u, true);
- bitv::set(act, 23u, true);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u]));
- // mixed
-
- act = bitv::create(31u, false);
- bitv::set(act, 24u, true);
- bitv::set(act, 25u, true);
- bitv::set(act, 26u, true);
- bitv::set(act, 27u, true);
- bitv::set(act, 28u, true);
- bitv::set(act, 29u, true);
- bitv::set(act, 30u, true);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u,
- 1u, 1u, 1u, 1u, 1u]));
- // mixed
-
- act = bitv::create(31u, false);
- bitv::set(act, 3u, true);
- bitv::set(act, 17u, true);
- bitv::set(act, 30u, true);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 1u]));
-}
-
-fn test_32_elements() {
- auto act;
- // all 0
-
- act = bitv::create(32u, false);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u]));
- // all 1
-
- act = bitv::create(32u, true);
- assert (bitv::eq_vec(act,
- [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
- 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
- 1u, 1u, 1u, 1u, 1u, 1u]));
- // mixed
-
- act = bitv::create(32u, false);
- bitv::set(act, 0u, true);
- bitv::set(act, 1u, true);
- bitv::set(act, 2u, true);
- bitv::set(act, 3u, true);
- bitv::set(act, 4u, true);
- bitv::set(act, 5u, true);
- bitv::set(act, 6u, true);
- bitv::set(act, 7u, true);
- assert (bitv::eq_vec(act,
- [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u]));
- // mixed
-
- act = bitv::create(32u, false);
- bitv::set(act, 16u, true);
- bitv::set(act, 17u, true);
- bitv::set(act, 18u, true);
- bitv::set(act, 19u, true);
- bitv::set(act, 20u, true);
- bitv::set(act, 21u, true);
- bitv::set(act, 22u, true);
- bitv::set(act, 23u, true);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u]));
- // mixed
-
- act = bitv::create(32u, false);
- bitv::set(act, 24u, true);
- bitv::set(act, 25u, true);
- bitv::set(act, 26u, true);
- bitv::set(act, 27u, true);
- bitv::set(act, 28u, true);
- bitv::set(act, 29u, true);
- bitv::set(act, 30u, true);
- bitv::set(act, 31u, true);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u,
- 1u, 1u, 1u, 1u, 1u, 1u]));
- // mixed
-
- act = bitv::create(32u, false);
- bitv::set(act, 3u, true);
- bitv::set(act, 17u, true);
- bitv::set(act, 30u, true);
- bitv::set(act, 31u, true);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 1u, 1u]));
-}
-
-fn test_33_elements() {
- auto act;
- // all 0
-
- act = bitv::create(33u, false);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
- // all 1
-
- act = bitv::create(33u, true);
- assert (bitv::eq_vec(act,
- [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
- 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
- 1u, 1u, 1u, 1u, 1u, 1u, 1u]));
- // mixed
-
- act = bitv::create(33u, false);
- bitv::set(act, 0u, true);
- bitv::set(act, 1u, true);
- bitv::set(act, 2u, true);
- bitv::set(act, 3u, true);
- bitv::set(act, 4u, true);
- bitv::set(act, 5u, true);
- bitv::set(act, 6u, true);
- bitv::set(act, 7u, true);
- assert (bitv::eq_vec(act,
- [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
- // mixed
-
- act = bitv::create(33u, false);
- bitv::set(act, 16u, true);
- bitv::set(act, 17u, true);
- bitv::set(act, 18u, true);
- bitv::set(act, 19u, true);
- bitv::set(act, 20u, true);
- bitv::set(act, 21u, true);
- bitv::set(act, 22u, true);
- bitv::set(act, 23u, true);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
- // mixed
-
- act = bitv::create(33u, false);
- bitv::set(act, 24u, true);
- bitv::set(act, 25u, true);
- bitv::set(act, 26u, true);
- bitv::set(act, 27u, true);
- bitv::set(act, 28u, true);
- bitv::set(act, 29u, true);
- bitv::set(act, 30u, true);
- bitv::set(act, 31u, true);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u,
- 1u, 1u, 1u, 1u, 1u, 1u, 0u]));
- // mixed
-
- act = bitv::create(33u, false);
- bitv::set(act, 3u, true);
- bitv::set(act, 17u, true);
- bitv::set(act, 30u, true);
- bitv::set(act, 31u, true);
- bitv::set(act, 32u, true);
- assert (bitv::eq_vec(act,
- [0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
- 0u, 0u, 0u, 0u, 1u, 1u, 1u]));
-}
-
-fn main() {
- test_0_elements();
- test_1_element();
- test_10_elements();
- test_31_elements();
- test_32_elements();
- test_33_elements();
-}
\ No newline at end of file
+++ /dev/null
-
-use std;
-import std::box;
-
-fn main() {
- auto x = @3;
- auto y = @3;
- assert (box::ptr_eq[int](x, x));
- assert (box::ptr_eq[int](y, y));
- assert (!box::ptr_eq[int](x, y));
- assert (!box::ptr_eq[int](y, x));
-}
\ No newline at end of file
+++ /dev/null
-
-
-// -*- rust -*-
-use std;
-import std::deque;
-
-fn test_simple() {
- let deque::t[int] d = deque::create[int]();
- assert (d.size() == 0u);
- d.add_front(17);
- d.add_front(42);
- d.add_back(137);
- assert (d.size() == 3u);
- d.add_back(137);
- assert (d.size() == 4u);
- log d.peek_front();
- assert (d.peek_front() == 42);
- log d.peek_back();
- assert (d.peek_back() == 137);
- let int i = d.pop_front();
- log i;
- assert (i == 42);
- i = d.pop_back();
- log i;
- assert (i == 137);
- i = d.pop_back();
- log i;
- assert (i == 137);
- i = d.pop_back();
- log i;
- assert (i == 17);
- assert (d.size() == 0u);
- d.add_back(3);
- assert (d.size() == 1u);
- d.add_front(2);
- assert (d.size() == 2u);
- d.add_back(4);
- assert (d.size() == 3u);
- d.add_front(1);
- assert (d.size() == 4u);
- log d.get(0);
- log d.get(1);
- log d.get(2);
- log d.get(3);
- assert (d.get(0) == 1);
- assert (d.get(1) == 2);
- assert (d.get(2) == 3);
- assert (d.get(3) == 4);
-}
-
-fn test_boxes(@int a, @int b, @int c, @int d) {
- let deque::t[@int] deq = deque::create[@int]();
- assert (deq.size() == 0u);
- deq.add_front(a);
- deq.add_front(b);
- deq.add_back(c);
- assert (deq.size() == 3u);
- deq.add_back(d);
- assert (deq.size() == 4u);
- assert (deq.peek_front() == b);
- assert (deq.peek_back() == d);
- assert (deq.pop_front() == b);
- assert (deq.pop_back() == d);
- assert (deq.pop_back() == c);
- assert (deq.pop_back() == a);
- assert (deq.size() == 0u);
- deq.add_back(c);
- assert (deq.size() == 1u);
- deq.add_front(b);
- assert (deq.size() == 2u);
- deq.add_back(d);
- assert (deq.size() == 3u);
- deq.add_front(a);
- assert (deq.size() == 4u);
- assert (deq.get(0) == a);
- assert (deq.get(1) == b);
- assert (deq.get(2) == c);
- assert (deq.get(3) == d);
-}
-
-type eqfn[T] = fn(&T, &T) -> bool ;
-
-fn test_parameterized[T](eqfn[T] e, &T a, &T b, &T c, &T d) {
- let deque::t[T] deq = deque::create[T]();
- assert (deq.size() == 0u);
- deq.add_front(a);
- deq.add_front(b);
- deq.add_back(c);
- assert (deq.size() == 3u);
- deq.add_back(d);
- assert (deq.size() == 4u);
- assert (e(deq.peek_front(), b));
- assert (e(deq.peek_back(), d));
- assert (e(deq.pop_front(), b));
- assert (e(deq.pop_back(), d));
- assert (e(deq.pop_back(), c));
- assert (e(deq.pop_back(), a));
- assert (deq.size() == 0u);
- deq.add_back(c);
- assert (deq.size() == 1u);
- deq.add_front(b);
- assert (deq.size() == 2u);
- deq.add_back(d);
- assert (deq.size() == 3u);
- deq.add_front(a);
- assert (deq.size() == 4u);
- assert (e(deq.get(0), a));
- assert (e(deq.get(1), b));
- assert (e(deq.get(2), c));
- assert (e(deq.get(3), d));
-}
-
-tag taggy { one(int); two(int, int); three(int, int, int); }
-
-tag taggypar[T] { onepar(int); twopar(int, int); threepar(int, int, int); }
-
-type reccy = rec(int x, int y, taggy t);
-
-fn main() {
- fn inteq(&int a, &int b) -> bool { ret a == b; }
- fn intboxeq(&@int a, &@int b) -> bool { ret a == b; }
- fn taggyeq(&taggy a, &taggy b) -> bool {
- alt (a) {
- case (one(?a1)) {
- alt (b) {
- case (one(?b1)) { ret a1 == b1; }
- case (_) { ret false; }
- }
- }
- case (two(?a1, ?a2)) {
- alt (b) {
- case (two(?b1, ?b2)) { ret a1 == b1 && a2 == b2; }
- case (_) { ret false; }
- }
- }
- case (three(?a1, ?a2, ?a3)) {
- alt (b) {
- case (three(?b1, ?b2, ?b3)) {
- ret a1 == b1 && a2 == b2 && a3 == b3;
- }
- case (_) { ret false; }
- }
- }
- }
- }
- fn taggypareq[T](&taggypar[T] a, &taggypar[T] b) -> bool {
- alt (a) {
- case (onepar[T](?a1)) {
- alt (b) {
- case (onepar[T](?b1)) { ret a1 == b1; }
- case (_) { ret false; }
- }
- }
- case (twopar[T](?a1, ?a2)) {
- alt (b) {
- case (twopar[T](?b1, ?b2)) { ret a1 == b1 && a2 == b2; }
- case (_) { ret false; }
- }
- }
- case (threepar[T](?a1, ?a2, ?a3)) {
- alt (b) {
- case (threepar[T](?b1, ?b2, ?b3)) {
- ret a1 == b1 && a2 == b2 && a3 == b3;
- }
- case (_) { ret false; }
- }
- }
- }
- }
- fn reccyeq(&reccy a, &reccy b) -> bool {
- ret a.x == b.x && a.y == b.y && taggyeq(a.t, b.t);
- }
- log "*** starting";
- log "*** test simple";
- test_simple();
- log "*** end test simple";
- log "*** test boxes";
- test_boxes(@5, @72, @64, @175);
- log "*** end test boxes";
- log "test parameterized: int";
- let eqfn[int] eq1 = inteq;
- test_parameterized[int](eq1, 5, 72, 64, 175);
- log "*** test parameterized: @int";
- let eqfn[@int] eq2 = intboxeq;
- test_parameterized[@int](eq2, @5, @72, @64, @175);
- log "*** end test parameterized @int";
- log "test parameterized: taggy";
- let eqfn[taggy] eq3 = taggyeq;
- test_parameterized[taggy](eq3, one(1), two(1, 2), three(1, 2, 3),
- two(17, 42));
- /*
- * FIXME: Segfault. Also appears to be caused only after upcall_grow_task
-
- log "*** test parameterized: taggypar[int]";
- let eqfn[taggypar[int]] eq4 = taggypareq[int];
- test_parameterized[taggypar[int]](eq4,
- onepar[int](1),
- twopar[int](1, 2),
- threepar[int](1, 2, 3),
- twopar[int](17, 42));
- log "*** end test parameterized: taggypar[int]";
-
- */
-
- log "*** test parameterized: reccy";
- let reccy reccy1 = rec(x=1, y=2, t=one(1));
- let reccy reccy2 = rec(x=345, y=2, t=two(1, 2));
- let reccy reccy3 = rec(x=1, y=777, t=three(1, 2, 3));
- let reccy reccy4 = rec(x=19, y=252, t=two(17, 42));
- let eqfn[reccy] eq5 = reccyeq;
- test_parameterized[reccy](eq5, reccy1, reccy2, reccy3, reccy4);
- log "*** end test parameterized: reccy";
- log "*** done";
-}
\ No newline at end of file
+++ /dev/null
-// xfail-stage0
-
-use std;
-import std::either::*;
-import std::ivec::len;
-
-fn test_either_left() {
- auto val = left(10);
- fn f_left(&int x) -> bool { x == 10 }
- fn f_right(&uint x) -> bool { false }
- assert (either(f_left, f_right, val));
-}
-
-fn test_either_right() {
- auto val = right(10u);
- fn f_left(&int x) -> bool { false }
- fn f_right(&uint x) -> bool { x == 10u }
- assert (either(f_left, f_right, val));
-}
-
-fn test_lefts() {
- auto input = ~[left(10),
- right(11),
- left(12),
- right(13),
- left(14)];
- auto result = lefts(input);
- assert (result == ~[10, 12, 14]);
-}
-
-fn test_lefts_none() {
- let (t[int, int])[] input = ~[right(10),
- right(10)];
- auto result = lefts(input);
- assert (len(result) == 0u);
-}
-
-fn test_lefts_empty() {
- let (t[int, int])[] input = ~[];
- auto result = lefts(input);
- assert (len(result) == 0u);
-}
-
-fn test_rights() {
- auto input = ~[left(10),
- right(11),
- left(12),
- right(13),
- left(14)];
- auto result = rights(input);
- assert (result == ~[11, 13]);
-}
-
-fn test_rights_none() {
- let (t[int, int])[] input = ~[left(10),
- left(10)];
- auto result = rights(input);
- assert (len(result) == 0u);
-}
-
-fn test_rights_empty() {
- let (t[int, int])[] input = ~[];
- auto result = rights(input);
- assert (len(result) == 0u);
-}
-
-fn test_partition() {
- auto input = ~[left(10),
- right(11),
- left(12),
- right(13),
- left(14)];
- auto result = partition(input);
- assert (result._0.(0) == 10);
- assert (result._0.(1) == 12);
- assert (result._0.(2) == 14);
- assert (result._1.(0) == 11);
- assert (result._1.(1) == 13);
-}
-
-fn test_partition_no_lefts() {
- let (t[int, int])[] input = ~[right(10),
- right(11)];
- auto result = partition(input);
- assert (len(result._0) == 0u);
- assert (len(result._1) == 2u);
-}
-
-fn test_partition_no_rights() {
- let (t[int, int])[] input = ~[left(10),
- left(11)];
- auto result = partition(input);
- assert (len(result._0) == 2u);
- assert (len(result._1) == 0u);
-}
-
-fn test_partition_empty() {
- let (t[int, int])[] input = ~[];
- auto result = partition(input);
- assert (len(result._0) == 0u);
- assert (len(result._1) == 0u);
-}
-
-fn main() {
- test_either_left();
- test_either_right();
- test_lefts();
- test_lefts_none();
- test_lefts_empty();
- test_rights();
- test_rights_none();
- test_rights_empty();
- test_partition();
- test_partition_no_lefts();
- test_partition_no_rights();
- test_partition_empty();
-}
+++ /dev/null
-
-use std;
-import std::fs;
-
-fn test_connect() {
- auto slash = fs::path_sep();
- log_err fs::connect("a", "b");
- assert (fs::connect("a", "b") == "a" + slash + "b");
- assert (fs::connect("a" + slash, "b") == "a" + slash + "b");
-}
-
-// Issue #712
-fn test_list_dir_no_invalid_memory_access() {
- fs::list_dir(".");
-}
-
-fn main() {
- test_connect();
- test_list_dir_no_invalid_memory_access();
-}
\ No newline at end of file
+++ /dev/null
-
-use std;
-import std::vec;
-import std::option;
-import opt = std::getopts;
-
-tag fail_type {
- argument_missing;
- unrecognized_option;
- option_missing;
- option_duplicated;
- unexpected_argument;
-}
-
-fn check_fail_type(opt::fail_ f, fail_type ft) {
- alt (f) {
- case (opt::argument_missing(_)) { assert (ft == argument_missing); }
- case (opt::unrecognized_option(_)) {
- assert (ft == unrecognized_option);
- }
- case (opt::option_missing(_)) { assert (ft == option_missing); }
- case (opt::option_duplicated(_)) { assert (ft == option_duplicated); }
- case (opt::unexpected_argument(_)) {
- assert (ft == unexpected_argument);
- }
- case (_) { fail; }
- }
-}
-
-
-// Tests for reqopt
-fn test_reqopt_long() {
- auto args = ["--test=20"];
- auto opts = [opt::reqopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "test"));
- assert (opt::opt_str(m, "test") == "20");
- }
- case (_) { fail; }
- }
-}
-
-fn test_reqopt_long_missing() {
- auto args = ["blah"];
- auto opts = [opt::reqopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_missing); }
- case (_) { fail; }
- }
-}
-
-fn test_reqopt_long_no_arg() {
- auto args = ["--test"];
- auto opts = [opt::reqopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
- }
-}
-
-fn test_reqopt_long_multi() {
- auto args = ["--test=20", "--test=30"];
- auto opts = [opt::reqopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
- }
-}
-
-fn test_reqopt_short() {
- auto args = ["-t", "20"];
- auto opts = [opt::reqopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "t"));
- assert (opt::opt_str(m, "t") == "20");
- }
- case (_) { fail; }
- }
-}
-
-fn test_reqopt_short_missing() {
- auto args = ["blah"];
- auto opts = [opt::reqopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_missing); }
- case (_) { fail; }
- }
-}
-
-fn test_reqopt_short_no_arg() {
- auto args = ["-t"];
- auto opts = [opt::reqopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
- }
-}
-
-fn test_reqopt_short_multi() {
- auto args = ["-t", "20", "-t", "30"];
- auto opts = [opt::reqopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
- }
-}
-
-
-// Tests for optopt
-fn test_optopt_long() {
- auto args = ["--test=20"];
- auto opts = [opt::optopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "test"));
- assert (opt::opt_str(m, "test") == "20");
- }
- case (_) { fail; }
- }
-}
-
-fn test_optopt_long_missing() {
- auto args = ["blah"];
- auto opts = [opt::optopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); }
- case (_) { fail; }
- }
-}
-
-fn test_optopt_long_no_arg() {
- auto args = ["--test"];
- auto opts = [opt::optopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
- }
-}
-
-fn test_optopt_long_multi() {
- auto args = ["--test=20", "--test=30"];
- auto opts = [opt::optopt("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
- }
-}
-
-fn test_optopt_short() {
- auto args = ["-t", "20"];
- auto opts = [opt::optopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "t"));
- assert (opt::opt_str(m, "t") == "20");
- }
- case (_) { fail; }
- }
-}
-
-fn test_optopt_short_missing() {
- auto args = ["blah"];
- auto opts = [opt::optopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); }
- case (_) { fail; }
- }
-}
-
-fn test_optopt_short_no_arg() {
- auto args = ["-t"];
- auto opts = [opt::optopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
- }
-}
-
-fn test_optopt_short_multi() {
- auto args = ["-t", "20", "-t", "30"];
- auto opts = [opt::optopt("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
- }
-}
-
-
-// Tests for optflag
-fn test_optflag_long() {
- auto args = ["--test"];
- auto opts = [opt::optflag("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (opt::opt_present(m, "test")); }
- case (_) { fail; }
- }
-}
-
-fn test_optflag_long_missing() {
- auto args = ["blah"];
- auto opts = [opt::optflag("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); }
- case (_) { fail; }
- }
-}
-
-fn test_optflag_long_arg() {
- auto args = ["--test=20"];
- auto opts = [opt::optflag("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) {
- log_err opt::fail_str(f);
- check_fail_type(f, unexpected_argument);
- }
- case (_) { fail; }
- }
-}
-
-fn test_optflag_long_multi() {
- auto args = ["--test", "--test"];
- auto opts = [opt::optflag("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
- }
-}
-
-fn test_optflag_short() {
- auto args = ["-t"];
- auto opts = [opt::optflag("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (opt::opt_present(m, "t")); }
- case (_) { fail; }
- }
-}
-
-fn test_optflag_short_missing() {
- auto args = ["blah"];
- auto opts = [opt::optflag("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); }
- case (_) { fail; }
- }
-}
-
-fn test_optflag_short_arg() {
- auto args = ["-t", "20"];
- auto opts = [opt::optflag("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- // The next variable after the flag is just a free argument
-
- assert (m.free.(0) == "20");
- }
- case (_) { fail; }
- }
-}
-
-fn test_optflag_short_multi() {
- auto args = ["-t", "-t"];
- auto opts = [opt::optflag("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
- case (_) { fail; }
- }
-}
-
-
-// Tests for optmulti
-fn test_optmulti_long() {
- auto args = ["--test=20"];
- auto opts = [opt::optmulti("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "test"));
- assert (opt::opt_str(m, "test") == "20");
- }
- case (_) { fail; }
- }
-}
-
-fn test_optmulti_long_missing() {
- auto args = ["blah"];
- auto opts = [opt::optmulti("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); }
- case (_) { fail; }
- }
-}
-
-fn test_optmulti_long_no_arg() {
- auto args = ["--test"];
- auto opts = [opt::optmulti("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
- }
-}
-
-fn test_optmulti_long_multi() {
- auto args = ["--test=20", "--test=30"];
- auto opts = [opt::optmulti("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "test"));
- assert (opt::opt_str(m, "test") == "20");
- assert (opt::opt_strs(m, "test").(0) == "20");
- assert (opt::opt_strs(m, "test").(1) == "30");
- }
- case (_) { fail; }
- }
-}
-
-fn test_optmulti_short() {
- auto args = ["-t", "20"];
- auto opts = [opt::optmulti("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "t"));
- assert (opt::opt_str(m, "t") == "20");
- }
- case (_) { fail; }
- }
-}
-
-fn test_optmulti_short_missing() {
- auto args = ["blah"];
- auto opts = [opt::optmulti("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); }
- case (_) { fail; }
- }
-}
-
-fn test_optmulti_short_no_arg() {
- auto args = ["-t"];
- auto opts = [opt::optmulti("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
- case (_) { fail; }
- }
-}
-
-fn test_optmulti_short_multi() {
- auto args = ["-t", "20", "-t", "30"];
- auto opts = [opt::optmulti("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (opt::opt_present(m, "t"));
- assert (opt::opt_str(m, "t") == "20");
- assert (opt::opt_strs(m, "t").(0) == "20");
- assert (opt::opt_strs(m, "t").(1) == "30");
- }
- case (_) { fail; }
- }
-}
-
-fn test_unrecognized_option_long() {
- auto args = ["--untest"];
- auto opts = [opt::optmulti("t")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, unrecognized_option); }
- case (_) { fail; }
- }
-}
-
-fn test_unrecognized_option_short() {
- auto args = ["-t"];
- auto opts = [opt::optmulti("test")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::failure(?f)) { check_fail_type(f, unrecognized_option); }
- case (_) { fail; }
- }
-}
-
-fn test_combined() {
- auto args =
- ["prog", "free1", "-s", "20", "free2", "--flag", "--long=30", "-f",
- "-m", "40", "-m", "50"];
- auto opts =
- [opt::optopt("s"), opt::optflag("flag"), opt::reqopt("long"),
- opt::optflag("f"), opt::optmulti("m"), opt::optopt("notpresent")];
- auto rs = opt::getopts(args, opts);
- alt (rs) {
- case (opt::success(?m)) {
- assert (m.free.(0) == "prog");
- assert (m.free.(1) == "free1");
- assert (opt::opt_str(m, "s") == "20");
- assert (m.free.(2) == "free2");
- assert (opt::opt_present(m, "flag"));
- assert (opt::opt_str(m, "long") == "30");
- assert (opt::opt_present(m, "f"));
- assert (opt::opt_strs(m, "m").(0) == "40");
- assert (opt::opt_strs(m, "m").(1) == "50");
- assert (!opt::opt_present(m, "notpresent"));
- }
- case (_) { fail; }
- }
-}
-
-fn main() {
- test_reqopt_long();
- test_reqopt_long_missing();
- test_reqopt_long_no_arg();
- test_reqopt_long_multi();
- test_reqopt_short();
- test_reqopt_short_missing();
- test_reqopt_short_no_arg();
- test_reqopt_short_multi();
- test_optopt_long();
- test_optopt_long_missing();
- test_optopt_long_no_arg();
- test_optopt_long_multi();
- test_optopt_short();
- test_optopt_short_missing();
- test_optopt_short_no_arg();
- test_optopt_short_multi();
- test_optflag_long();
- test_optflag_long_missing();
- test_optflag_long_arg();
- test_optflag_long_multi();
- test_optflag_short();
- test_optflag_short_missing();
- test_optflag_short_arg();
- test_optflag_short_multi();
- test_optmulti_long();
- test_optmulti_long_missing();
- test_optmulti_long_no_arg();
- test_optmulti_long_multi();
- test_optmulti_short();
- test_optmulti_short_missing();
- test_optmulti_short_no_arg();
- test_optmulti_short_multi();
- test_unrecognized_option_long();
- test_unrecognized_option_short();
- test_combined();
-}
\ No newline at end of file
+++ /dev/null
-
-use std;
-import std::int;
-import std::str::eq;
-
-fn test_to_str() {
- assert (eq(int::to_str(0, 10u), "0"));
- assert (eq(int::to_str(1, 10u), "1"));
- assert (eq(int::to_str(-1, 10u), "-1"));
- assert (eq(int::to_str(255, 16u), "ff"));
- assert (eq(int::to_str(100, 10u), "100"));
-}
-
-fn test_pow() {
- assert (int::pow(0, 0u) == 1);
- assert (int::pow(0, 1u) == 0);
- assert (int::pow(0, 2u) == 0);
- assert (int::pow(-1, 0u) == 1);
- assert (int::pow(1, 0u) == 1);
- assert (int::pow(-3, 2u) == 9);
- assert (int::pow(-3, 3u) == -27);
- assert (int::pow(4, 9u) == 262144);
-}
-
-fn main() {
- test_to_str();
- test_pow();
-}
\ No newline at end of file
+++ /dev/null
-// xfail-stage0
-// -*- rust -*-
-use std;
-import std::io;
-import std::str;
-
-#[cfg(target_os = "linux")]
-#[cfg(target_os = "win32")]
-fn test_simple() {
- let str tmpfile = "test/run-pass/lib-io-test-simple.tmp";
- log tmpfile;
- let str frood = "A hoopy frood who really knows where his towel is.";
- log frood;
- {
- let io::writer out = io::file_writer(tmpfile, [io::create,
- io::truncate]);
- out.write_str(frood);
- }
- let io::reader inp = io::file_reader(tmpfile);
- let str frood2 = inp.read_c_str();
- log frood2;
- assert (str::eq(frood, frood2));
-}
-
-// FIXME (726)
-#[cfg(target_os = "macos")]
-fn test_simple() {}
-
-fn main() {
- test_simple();
-}
\ No newline at end of file
+++ /dev/null
-// xfail-stage0
-
-use std;
-import std::ivec;
-import std::option;
-import std::option::none;
-import std::option::some;
-
-fn square(uint n) -> uint { ret n * n; }
-
-fn square_alias(&uint n) -> uint { ret n * n; }
-
-pred is_three(&uint n) -> bool { ret n == 3u; }
-
-fn square_if_odd(&uint n) -> option::t[uint] {
- ret if (n % 2u == 1u) { some(n * n) } else { none };
-}
-
-fn add(&uint x, &uint y) -> uint { ret x + y; }
-
-fn test_reserve_and_on_heap() {
- let int[] v = ~[ 1, 2 ];
- assert (!ivec::on_heap(v));
- ivec::reserve(v, 8u);
- assert (ivec::on_heap(v));
-}
-
-fn test_unsafe_ptrs() {
- // Test on-stack copy-from-buf.
- auto a = ~[ 1, 2, 3 ];
- auto ptr = ivec::to_ptr(a);
- auto b = ~[];
- ivec::unsafe::copy_from_buf(b, ptr, 3u);
- assert (ivec::len(b) == 3u);
- assert (b.(0) == 1);
- assert (b.(1) == 2);
- assert (b.(2) == 3);
-
- // Test on-heap copy-from-buf.
- auto c = ~[ 1, 2, 3, 4, 5 ];
- ptr = ivec::to_ptr(c);
- auto d = ~[];
- ivec::unsafe::copy_from_buf(d, ptr, 5u);
- assert (ivec::len(d) == 5u);
- assert (d.(0) == 1);
- assert (d.(1) == 2);
- assert (d.(2) == 3);
- assert (d.(3) == 4);
- assert (d.(4) == 5);
-}
-
-fn test_init_fn() {
- // Test on-stack init_fn.
- auto v = ivec::init_fn(square, 3u);
- assert (ivec::len(v) == 3u);
- assert (v.(0) == 0u);
- assert (v.(1) == 1u);
- assert (v.(2) == 4u);
-
- // Test on-heap init_fn.
- v = ivec::init_fn(square, 5u);
- assert (ivec::len(v) == 5u);
- assert (v.(0) == 0u);
- assert (v.(1) == 1u);
- assert (v.(2) == 4u);
- assert (v.(3) == 9u);
- assert (v.(4) == 16u);
-}
-
-fn test_init_elt() {
- // Test on-stack init_elt.
- auto v = ivec::init_elt(10u, 2u);
- assert (ivec::len(v) == 2u);
- assert (v.(0) == 10u);
- assert (v.(1) == 10u);
-
- // Test on-heap init_elt.
- v = ivec::init_elt(20u, 6u);
- assert (v.(0) == 20u);
- assert (v.(1) == 20u);
- assert (v.(2) == 20u);
- assert (v.(3) == 20u);
- assert (v.(4) == 20u);
- assert (v.(5) == 20u);
-}
-
-fn test_is_empty() {
- assert ivec::is_empty[int](~[]);
- assert !ivec::is_empty(~[0]);
-}
-
-fn test_is_not_empty() {
- assert ivec::is_not_empty(~[0]);
- assert !ivec::is_not_empty[int](~[]);
-}
-
-fn test_head() {
- auto a = ~[11, 12];
- check ivec::is_not_empty(a);
- assert ivec::head(a) == 11;
-}
-
-fn test_tail() {
- auto a = ~[11];
- check ivec::is_not_empty(a);
- assert ivec::tail(a) == ~[];
-
- a = ~[11, 12];
- check ivec::is_not_empty(a);
- assert ivec::tail(a) == ~[12];
-}
-
-fn test_last() {
- auto n = ivec::last(~[]);
- assert (n == none);
- n = ivec::last(~[ 1, 2, 3 ]);
- assert (n == some(3));
- n = ivec::last(~[ 1, 2, 3, 4, 5 ]);
- assert (n == some(5));
-}
-
-fn test_slice() {
- // Test on-stack -> on-stack slice.
- auto v = ivec::slice(~[ 1, 2, 3 ], 1u, 3u);
- assert (ivec::len(v) == 2u);
- assert (v.(0) == 2);
- assert (v.(1) == 3);
-
- // Test on-heap -> on-stack slice.
- v = ivec::slice(~[ 1, 2, 3, 4, 5 ], 0u, 3u);
- assert (ivec::len(v) == 3u);
- assert (v.(0) == 1);
- assert (v.(1) == 2);
- assert (v.(2) == 3);
-
- // Test on-heap -> on-heap slice.
- v = ivec::slice(~[ 1, 2, 3, 4, 5, 6 ], 1u, 6u);
- assert (ivec::len(v) == 5u);
- assert (v.(0) == 2);
- assert (v.(1) == 3);
- assert (v.(2) == 4);
- assert (v.(3) == 5);
- assert (v.(4) == 6);
-}
-
-fn test_pop() {
- // Test on-stack pop.
- auto v = ~[ 1, 2, 3 ];
- auto e = ivec::pop(v);
- assert (ivec::len(v) == 2u);
- assert (v.(0) == 1);
- assert (v.(1) == 2);
- assert (e == 3);
-
- // Test on-heap pop.
- v = ~[ 1, 2, 3, 4, 5 ];
- e = ivec::pop(v);
- assert (ivec::len(v) == 4u);
- assert (v.(0) == 1);
- assert (v.(1) == 2);
- assert (v.(2) == 3);
- assert (v.(3) == 4);
- assert (e == 5);
-}
-
-fn test_grow() {
- // Test on-stack grow().
- auto v = ~[];
- ivec::grow(v, 2u, 1);
- assert (ivec::len(v) == 2u);
- assert (v.(0) == 1);
- assert (v.(1) == 1);
-
- // Test on-heap grow().
- ivec::grow(v, 3u, 2);
- assert (ivec::len(v) == 5u);
- assert (v.(0) == 1);
- assert (v.(1) == 1);
- assert (v.(2) == 2);
- assert (v.(3) == 2);
- assert (v.(4) == 2);
-}
-
-fn test_grow_fn() {
- auto v = ~[];
- ivec::grow_fn(v, 3u, square);
- assert (ivec::len(v) == 3u);
- assert (v.(0) == 0u);
- assert (v.(1) == 1u);
- assert (v.(2) == 4u);
-}
-
-fn test_grow_set() {
- auto v = ~[ mutable 1, 2, 3 ];
- ivec::grow_set(v, 4u, 4, 5);
- assert (ivec::len(v) == 5u);
- assert (v.(0) == 1);
- assert (v.(1) == 2);
- assert (v.(2) == 3);
- assert (v.(3) == 4);
- assert (v.(4) == 5);
-}
-
-fn test_map() {
- // Test on-stack map.
- auto v = ~[ 1u, 2u, 3u ];
- auto w = ivec::map(square_alias, v);
- assert (ivec::len(w) == 3u);
- assert (w.(0) == 1u);
- assert (w.(1) == 4u);
- assert (w.(2) == 9u);
-
- // Test on-heap map.
- v = ~[ 1u, 2u, 3u, 4u, 5u ];
- w = ivec::map(square_alias, v);
- assert (ivec::len(w) == 5u);
- assert (w.(0) == 1u);
- assert (w.(1) == 4u);
- assert (w.(2) == 9u);
- assert (w.(3) == 16u);
- assert (w.(4) == 25u);
-}
-
-fn test_filter_map() {
- // Test on-stack filter-map.
- auto v = ~[ 1u, 2u, 3u ];
- auto w = ivec::filter_map(square_if_odd, v);
- assert (ivec::len(w) == 2u);
- assert (w.(0) == 1u);
- assert (w.(1) == 9u);
-
- // Test on-heap filter-map.
- v = ~[ 1u, 2u, 3u, 4u, 5u ];
- w = ivec::filter_map(square_if_odd, v);
- assert (ivec::len(w) == 3u);
- assert (w.(0) == 1u);
- assert (w.(1) == 9u);
- assert (w.(2) == 25u);
-}
-
-fn test_foldl() {
- // Test on-stack fold.
- auto v = ~[ 1u, 2u, 3u ];
- auto sum = ivec::foldl(add, 0u, v);
- assert (sum == 6u);
-
- // Test on-heap fold.
- v = ~[ 1u, 2u, 3u, 4u, 5u ];
- sum = ivec::foldl(add, 0u, v);
- assert (sum == 15u);
-}
-
-fn test_any_and_all() {
- assert (ivec::any(is_three, ~[ 1u, 2u, 3u ]));
- assert (!ivec::any(is_three, ~[ 0u, 1u, 2u ]));
- assert (ivec::any(is_three, ~[ 1u, 2u, 3u, 4u, 5u ]));
- assert (!ivec::any(is_three, ~[ 1u, 2u, 4u, 5u, 6u ]));
-
- assert (ivec::all(is_three, ~[ 3u, 3u, 3u ]));
- assert (!ivec::all(is_three, ~[ 3u, 3u, 2u ]));
- assert (ivec::all(is_three, ~[ 3u, 3u, 3u, 3u, 3u ]));
- assert (!ivec::all(is_three, ~[ 3u, 3u, 0u, 1u, 2u ]));
-}
-
-#[test]
-fn test_zip_unzip() {
- auto v1 = ~[1, 2, 3];
- auto v2 = ~[4, 5, 6];
- auto z1 = ivec::zip(v1, v2);
-
- assert tup(1, 4) == z1.(0);
- assert tup(2, 5) == z1.(1);
- assert tup(3, 6) == z1.(2);
-
- auto u1 = ivec::unzip(z1);
-
- assert tup(1, 4) == tup(u1._0.(0), u1._1.(0));
- assert tup(2, 5) == tup(u1._0.(1), u1._1.(1));
- assert tup(3, 6) == tup(u1._0.(2), u1._1.(2));
-}
-
-fn main() {
- test_reserve_and_on_heap();
- test_unsafe_ptrs();
-
- // Predicates
- test_is_empty();
- test_is_not_empty();
-
- // Accessors
- test_init_fn();
- test_init_elt();
- test_head();
- test_tail();
- test_last();
- test_slice();
-
- // Mutators
- test_pop();
-
- // Appending
- test_grow();
- test_grow_fn();
- test_grow_set();
-
- // Functional utilities
- test_map();
- test_filter_map();
- test_foldl();
- test_any_and_all();
- test_zip_unzip();
-}
-
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
-
+++ /dev/null
-
-use std;
-import std::list;
-import std::list::car;
-import std::list::cdr;
-import std::list::from_vec;
-import std::option;
-
-fn test_from_vec() {
- auto l = from_vec([0, 1, 2]);
- assert (car(l) == 0);
- assert (car(cdr(l)) == 1);
- assert (car(cdr(cdr(l))) == 2);
-}
-
-fn test_foldl() {
- auto l = from_vec([0, 1, 2, 3, 4]);
- fn add(&int a, &uint b) -> uint { ret (a as uint) + b; }
- auto rs = list::foldl(l, 0u, add);
- assert (rs == 10u);
-}
-
-fn test_find_success() {
- auto l = from_vec([0, 1, 2]);
- fn match(&int i) -> option::t[int] {
- ret if (i == 2) { option::some(i) } else { option::none[int] };
- }
- auto rs = list::find(l, match);
- assert (rs == option::some(2));
-}
-
-fn test_find_fail() {
- auto l = from_vec([0, 1, 2]);
- fn match(&int i) -> option::t[int] { ret option::none[int]; }
- auto rs = list::find(l, match);
- assert (rs == option::none[int]);
-}
-
-fn test_has() {
- auto l = from_vec([5, 8, 6]);
- auto empty = list::nil[int];
- assert (list::has(l, 5));
- assert (!list::has(l, 7));
- assert (list::has(l, 8));
- assert (!list::has(empty, 5));
-}
-
-fn test_length() {
- auto l = from_vec([0, 1, 2]);
- assert (list::length(l) == 3u);
-}
-
-fn main() {
- test_from_vec();
- test_foldl();
- test_find_success();
- test_find_fail();
- test_length();
- test_has();
-}
\ No newline at end of file
+++ /dev/null
-
-
-// -*- rust -*-
-use std;
-import std::map;
-import std::str;
-import std::uint;
-import std::util;
-
-fn test_simple() {
- log "*** starting test_simple";
- fn eq_uint(&uint x, &uint y) -> bool { ret x == y; }
- fn hash_uint(&uint u) -> uint {
- // FIXME: can't use std::util::id since we'd be capturing a type
- // param, and presently we can't close items over type params.
-
- ret u;
- }
- let map::hashfn[uint] hasher_uint = hash_uint;
- let map::eqfn[uint] eqer_uint = eq_uint;
- let map::hashfn[str] hasher_str = str::hash;
- let map::eqfn[str] eqer_str = str::eq;
- log "uint -> uint";
- let map::hashmap[uint, uint] hm_uu =
- map::mk_hashmap[uint, uint](hasher_uint, eqer_uint);
- assert (hm_uu.insert(10u, 12u));
- assert (hm_uu.insert(11u, 13u));
- assert (hm_uu.insert(12u, 14u));
- assert (hm_uu.get(11u) == 13u);
- assert (hm_uu.get(12u) == 14u);
- assert (hm_uu.get(10u) == 12u);
- assert (!hm_uu.insert(12u, 14u));
- assert (hm_uu.get(12u) == 14u);
- assert (!hm_uu.insert(12u, 12u));
- assert (hm_uu.get(12u) == 12u);
- let str ten = "ten";
- let str eleven = "eleven";
- let str twelve = "twelve";
- log "str -> uint";
- let map::hashmap[str, uint] hm_su =
- map::mk_hashmap[str, uint](hasher_str, eqer_str);
- assert (hm_su.insert("ten", 12u));
- assert (hm_su.insert(eleven, 13u));
- assert (hm_su.insert("twelve", 14u));
- assert (hm_su.get(eleven) == 13u);
- assert (hm_su.get("eleven") == 13u);
- assert (hm_su.get("twelve") == 14u);
- assert (hm_su.get("ten") == 12u);
- assert (!hm_su.insert("twelve", 14u));
- assert (hm_su.get("twelve") == 14u);
- assert (!hm_su.insert("twelve", 12u));
- assert (hm_su.get("twelve") == 12u);
- log "uint -> str";
- let map::hashmap[uint, str] hm_us =
- map::mk_hashmap[uint, str](hasher_uint, eqer_uint);
- assert (hm_us.insert(10u, "twelve"));
- assert (hm_us.insert(11u, "thirteen"));
- assert (hm_us.insert(12u, "fourteen"));
- assert (str::eq(hm_us.get(11u), "thirteen"));
- assert (str::eq(hm_us.get(12u), "fourteen"));
- assert (str::eq(hm_us.get(10u), "twelve"));
- assert (!hm_us.insert(12u, "fourteen"));
- assert (str::eq(hm_us.get(12u), "fourteen"));
- assert (!hm_us.insert(12u, "twelve"));
- assert (str::eq(hm_us.get(12u), "twelve"));
- log "str -> str";
- let map::hashmap[str, str] hm_ss =
- map::mk_hashmap[str, str](hasher_str, eqer_str);
- assert (hm_ss.insert(ten, "twelve"));
- assert (hm_ss.insert(eleven, "thirteen"));
- assert (hm_ss.insert(twelve, "fourteen"));
- assert (str::eq(hm_ss.get("eleven"), "thirteen"));
- assert (str::eq(hm_ss.get("twelve"), "fourteen"));
- assert (str::eq(hm_ss.get("ten"), "twelve"));
- assert (!hm_ss.insert("twelve", "fourteen"));
- assert (str::eq(hm_ss.get("twelve"), "fourteen"));
- assert (!hm_ss.insert("twelve", "twelve"));
- assert (str::eq(hm_ss.get("twelve"), "twelve"));
- log "*** finished test_simple";
-}
-
-
-/**
- * Force map growth and rehashing.
- */
-fn test_growth() {
- log "*** starting test_growth";
- let uint num_to_insert = 64u;
- fn eq_uint(&uint x, &uint y) -> bool { ret x == y; }
- fn hash_uint(&uint u) -> uint {
- // FIXME: can't use std::util::id since we'd be capturing a type
- // param, and presently we can't close items over type params.
-
- ret u;
- }
- log "uint -> uint";
- let map::hashfn[uint] hasher_uint = hash_uint;
- let map::eqfn[uint] eqer_uint = eq_uint;
- let map::hashmap[uint, uint] hm_uu =
- map::mk_hashmap[uint, uint](hasher_uint, eqer_uint);
- let uint i = 0u;
- while (i < num_to_insert) {
- assert (hm_uu.insert(i, i * i));
- log "inserting " + uint::to_str(i, 10u) + " -> " +
- uint::to_str(i * i, 10u);
- i += 1u;
- }
- log "-----";
- i = 0u;
- while (i < num_to_insert) {
- log "get(" + uint::to_str(i, 10u) + ") = " +
- uint::to_str(hm_uu.get(i), 10u);
- assert (hm_uu.get(i) == i * i);
- i += 1u;
- }
- assert (hm_uu.insert(num_to_insert, 17u));
- assert (hm_uu.get(num_to_insert) == 17u);
- log "-----";
- hm_uu.rehash();
- i = 0u;
- while (i < num_to_insert) {
- log "get(" + uint::to_str(i, 10u) + ") = " +
- uint::to_str(hm_uu.get(i), 10u);
- assert (hm_uu.get(i) == i * i);
- i += 1u;
- }
- log "str -> str";
- let map::hashfn[str] hasher_str = str::hash;
- let map::eqfn[str] eqer_str = str::eq;
- let map::hashmap[str, str] hm_ss =
- map::mk_hashmap[str, str](hasher_str, eqer_str);
- i = 0u;
- while (i < num_to_insert) {
- assert (hm_ss.insert(uint::to_str(i, 2u), uint::to_str(i * i, 2u)));
- log "inserting \"" + uint::to_str(i, 2u) + "\" -> \"" +
- uint::to_str(i * i, 2u) + "\"";
- i += 1u;
- }
- log "-----";
- i = 0u;
- while (i < num_to_insert) {
- log "get(\"" + uint::to_str(i, 2u) + "\") = \"" +
- hm_ss.get(uint::to_str(i, 2u)) + "\"";
- assert (str::eq(hm_ss.get(uint::to_str(i, 2u)),
- uint::to_str(i * i, 2u)));
- i += 1u;
- }
- assert (hm_ss.insert(uint::to_str(num_to_insert, 2u),
- uint::to_str(17u, 2u)));
- assert (str::eq(hm_ss.get(uint::to_str(num_to_insert, 2u)),
- uint::to_str(17u, 2u)));
- log "-----";
- hm_ss.rehash();
- i = 0u;
- while (i < num_to_insert) {
- log "get(\"" + uint::to_str(i, 2u) + "\") = \"" +
- hm_ss.get(uint::to_str(i, 2u)) + "\"";
- assert (str::eq(hm_ss.get(uint::to_str(i, 2u)),
- uint::to_str(i * i, 2u)));
- i += 1u;
- }
- log "*** finished test_growth";
-}
-
-fn test_removal() {
- log "*** starting test_removal";
- let uint num_to_insert = 64u;
- fn eq(&uint x, &uint y) -> bool { ret x == y; }
- fn hash(&uint u) -> uint {
- // This hash function intentionally causes collisions between
- // consecutive integer pairs.
-
- ret u / 2u * 2u;
- }
- assert (hash(0u) == hash(1u));
- assert (hash(2u) == hash(3u));
- assert (hash(0u) != hash(2u));
- let map::hashfn[uint] hasher = hash;
- let map::eqfn[uint] eqer = eq;
- let map::hashmap[uint, uint] hm =
- map::mk_hashmap[uint, uint](hasher, eqer);
- let uint i = 0u;
- while (i < num_to_insert) {
- assert (hm.insert(i, i * i));
- log "inserting " + uint::to_str(i, 10u) + " -> " +
- uint::to_str(i * i, 10u);
- i += 1u;
- }
- assert (hm.size() == num_to_insert);
- log "-----";
- log "removing evens";
- i = 0u;
- while (i < num_to_insert) {
- /**
- * FIXME (issue #150): we want to check the removed value as in the
- * following:
-
- let util.option[uint] v = hm.remove(i);
- alt (v) {
- case (util.some[uint](u)) {
- assert (u == (i * i));
- }
- case (util.none[uint]()) { fail; }
- }
-
- * but we util.option is a tag type so util.some and util.none are
- * off limits until we parse the dwarf for tag types.
- */
-
- hm.remove(i);
- i += 2u;
- }
- assert (hm.size() == num_to_insert / 2u);
- log "-----";
- i = 1u;
- while (i < num_to_insert) {
- log "get(" + uint::to_str(i, 10u) + ") = " +
- uint::to_str(hm.get(i), 10u);
- assert (hm.get(i) == i * i);
- i += 2u;
- }
- log "-----";
- log "rehashing";
- hm.rehash();
- log "-----";
- i = 1u;
- while (i < num_to_insert) {
- log "get(" + uint::to_str(i, 10u) + ") = " +
- uint::to_str(hm.get(i), 10u);
- assert (hm.get(i) == i * i);
- i += 2u;
- }
- log "-----";
- i = 0u;
- while (i < num_to_insert) {
- assert (hm.insert(i, i * i));
- log "inserting " + uint::to_str(i, 10u) + " -> " +
- uint::to_str(i * i, 10u);
- i += 2u;
- }
- assert (hm.size() == num_to_insert);
- log "-----";
- i = 0u;
- while (i < num_to_insert) {
- log "get(" + uint::to_str(i, 10u) + ") = " +
- uint::to_str(hm.get(i), 10u);
- assert (hm.get(i) == i * i);
- i += 1u;
- }
- log "-----";
- log "rehashing";
- hm.rehash();
- log "-----";
- assert (hm.size() == num_to_insert);
- i = 0u;
- while (i < num_to_insert) {
- log "get(" + uint::to_str(i, 10u) + ") = " +
- uint::to_str(hm.get(i), 10u);
- assert (hm.get(i) == i * i);
- i += 1u;
- }
- log "*** finished test_removal";
-}
-
-fn test_contains_key() {
- auto key = "k";
- auto map = map::mk_hashmap[str, str](str::hash, str::eq);
- assert (!map.contains_key(key));
- map.insert(key, "val");
- assert (map.contains_key(key));
-}
-
-fn test_find() {
- auto key = "k";
- auto map = map::mk_hashmap[str, str](str::hash, str::eq);
- assert (std::option::is_none(map.find(key)));
- map.insert(key, "val");
- assert (std::option::get(map.find(key)) == "val");
-}
-
-fn main() {
- test_simple();
- test_growth();
- test_removal();
- test_contains_key();
- test_find();
-}
\ No newline at end of file
+++ /dev/null
-
-use std;
-
-fn main() { auto x = std::option::some[int](10); }
\ No newline at end of file
+++ /dev/null
-// xfail-stage0
-
-use std;
-
-import std::generic_os::setenv;
-import std::generic_os::getenv;
-import std::option;
-
-#[test]
-fn test_setenv() {
- setenv("NAME", "VALUE");
- assert getenv("NAME") == option::some("VALUE");
-}
-
-#[test]
-fn test_setenv_overwrite() {
- setenv("NAME", "1");
- setenv("NAME", "2");
- assert getenv("NAME") == option::some("2");
-}
-
-// Windows GetEnvironmentVariable requires some extra work to make sure
-// the buffer the variable is copied into is the right size
-#[test]
-fn test_getenv_big() {
- auto s = "";
- auto i = 0;
- while (i < 100) {
- s += "aaaaaaaaaa";
- i += 1;
- }
- setenv("NAME", s);
- assert getenv("NAME") == option::some(s);
-}
-
-fn main() {
- test_setenv();
- test_setenv_overwrite();
- test_getenv_big();
-}
-
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-// xfail-stage0
-
-// Testing a few of the path manipuation functions
-
-use std;
-
-import std::fs;
-import std::os;
-
-fn main() {
- assert(!fs::path_is_absolute("test-path"));
-
- log "Current working directory: " + os::getcwd();
-
- log fs::make_absolute("test-path");
- log fs::make_absolute("/usr/bin");
-}
\ No newline at end of file
+++ /dev/null
-// xfail-stage0
-
-use std;
-import std::ptr;
-import std::unsafe;
-
-type pair = rec(mutable int fst, mutable int snd);
-
-fn main() {
- auto p = rec(mutable fst=10, mutable snd=20);
- let *mutable pair pptr = ptr::addr_of(p);
- let *mutable int iptr = unsafe::reinterpret_cast(pptr);
- assert (*iptr == 10);
- *iptr = 30;
- assert (*iptr == 30);
- assert (p.fst == 30);
-
- *pptr = rec(mutable fst=50, mutable snd=60);
- assert (*iptr == 50);
- assert (p.fst == 50);
- assert (p.snd == 60);
-}
-
+++ /dev/null
-
-use std;
-
-fn check_sort(vec[mutable int] v1, vec[mutable int] v2) {
- auto len = std::vec::len[int](v1);
- fn ltequal(&int a, &int b) -> bool { ret a <= b; }
- auto f = ltequal;
- std::sort::quick_sort[int](f, v1);
- auto i = 0u;
- while (i < len) { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; }
-}
-
-fn main() {
- {
- auto v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8];
- auto v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9];
- check_sort(v1, v2);
- }
- {
- auto v1 = [mutable 1, 1, 1];
- auto v2 = [mutable 1, 1, 1];
- check_sort(v1, v2);
- }
- {
- let vec[mutable int] v1 = [mutable ];
- let vec[mutable int] v2 = [mutable ];
- check_sort(v1, v2);
- }
- { auto v1 = [mutable 9]; auto v2 = [mutable 9]; check_sort(v1, v2); }
- {
- auto v1 = [mutable 9, 3, 3, 3, 9];
- auto v2 = [mutable 3, 3, 3, 9, 9];
- check_sort(v1, v2);
- }
-}
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-
-use std;
-
-fn check_sort(vec[mutable int] v1, vec[mutable int] v2) {
- auto len = std::vec::len[int](v1);
- fn lt(&int a, &int b) -> bool { ret a < b; }
- fn equal(&int a, &int b) -> bool { ret a == b; }
- auto f1 = lt;
- auto f2 = equal;
- std::sort::quick_sort3[int](f1, f2, v1);
- auto i = 0u;
- while (i < len) { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; }
-}
-
-fn main() {
- {
- auto v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8];
- auto v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9];
- check_sort(v1, v2);
- }
- {
- auto v1 = [mutable 1, 1, 1];
- auto v2 = [mutable 1, 1, 1];
- check_sort(v1, v2);
- }
- {
- let vec[mutable int] v1 = [mutable ];
- let vec[mutable int] v2 = [mutable ];
- check_sort(v1, v2);
- }
- { auto v1 = [mutable 9]; auto v2 = [mutable 9]; check_sort(v1, v2); }
- {
- auto v1 = [mutable 9, 3, 3, 3, 9];
- auto v2 = [mutable 3, 3, 3, 9, 9];
- check_sort(v1, v2);
- }
-}
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-
-
-// -*- rust -*-
-use std;
-import std::rand;
-
-fn main() {
- let rand::rng r1 = rand::mk_rng();
- log r1.next();
- log r1.next();
- {
- auto r2 = rand::mk_rng();
- log r1.next();
- log r2.next();
- log r1.next();
- log r1.next();
- log r2.next();
- log r2.next();
- log r1.next();
- log r1.next();
- log r1.next();
- log r2.next();
- log r2.next();
- log r2.next();
- }
- log r1.next();
- log r1.next();
-}
\ No newline at end of file
+++ /dev/null
-// xfail-stage0
-
-use std;
-import std::run;
-
-// Regression test for memory leaks
-// FIXME (714) Why does this fail on win32?
-
-#[cfg(target_os = "linux")]
-#[cfg(target_os = "macos")]
-fn test_leaks() {
- run::run_program("echo", []);
- run::start_program("echo", []);
- run::program_output("echo", []);
-}
-
-#[cfg(target_os = "win32")]
-fn test_leaks() {}
-
-fn main() {
- test_leaks();
-}
\ No newline at end of file
+++ /dev/null
-
-
-// -*- rust -*-
-
-// xfail-stage0
-use std;
-import std::sha1;
-import std::vec;
-import std::str;
-
-fn main() {
- type test = rec(str input, vec[u8] output);
-
- fn a_million_letter_a() -> str {
- auto i = 0;
- auto rs = "";
- while (i < 100000) { rs += "aaaaaaaaaa"; i += 1; }
- ret rs;
- }
- // Test messages from FIPS 180-1
-
- let vec[test] fips_180_1_tests =
- [rec(input="abc",
- output=[0xA9u8, 0x99u8, 0x3Eu8, 0x36u8, 0x47u8, 0x06u8, 0x81u8,
- 0x6Au8, 0xBAu8, 0x3Eu8, 0x25u8, 0x71u8, 0x78u8, 0x50u8,
- 0xC2u8, 0x6Cu8, 0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8]),
- rec(input="abcdbcdecdefdefgefghfghighij" +
- "hijkijkljklmklmnlmnomnopnopq",
- output=[0x84u8, 0x98u8, 0x3Eu8, 0x44u8, 0x1Cu8, 0x3Bu8, 0xD2u8,
- 0x6Eu8, 0xBAu8, 0xAEu8, 0x4Au8, 0xA1u8, 0xF9u8, 0x51u8,
- 0x29u8, 0xE5u8, 0xE5u8, 0x46u8, 0x70u8, 0xF1u8]),
- rec(input=a_million_letter_a(),
- output=[0x34u8, 0xAAu8, 0x97u8, 0x3Cu8, 0xD4u8, 0xC4u8, 0xDAu8,
- 0xA4u8, 0xF6u8, 0x1Eu8, 0xEBu8, 0x2Bu8, 0xDBu8, 0xADu8,
- 0x27u8, 0x31u8, 0x65u8, 0x34u8, 0x01u8, 0x6Fu8])];
- // Examples from wikipedia
-
- let vec[test] wikipedia_tests =
- [rec(input="The quick brown fox jumps over the lazy dog",
- output=[0x2fu8, 0xd4u8, 0xe1u8, 0xc6u8, 0x7au8, 0x2du8, 0x28u8,
- 0xfcu8, 0xedu8, 0x84u8, 0x9eu8, 0xe1u8, 0xbbu8, 0x76u8,
- 0xe7u8, 0x39u8, 0x1bu8, 0x93u8, 0xebu8, 0x12u8]),
- rec(input="The quick brown fox jumps over the lazy cog",
- output=[0xdeu8, 0x9fu8, 0x2cu8, 0x7fu8, 0xd2u8, 0x5eu8, 0x1bu8,
- 0x3au8, 0xfau8, 0xd3u8, 0xe8u8, 0x5au8, 0x0bu8, 0xd1u8,
- 0x7du8, 0x9bu8, 0x10u8, 0x0du8, 0xb4u8, 0xb3u8])];
- auto tests = fips_180_1_tests + wikipedia_tests;
- fn check_vec_eq(vec[u8] v0, vec[u8] v1) {
- assert (vec::len[u8](v0) == vec::len[u8](v1));
- auto len = vec::len[u8](v0);
- auto i = 0u;
- while (i < len) {
- auto a = v0.(i);
- auto b = v1.(i);
- assert (a == b);
- i += 1u;
- }
- }
- // Test that it works when accepting the message all at once
-
- auto sh = sha1::mk_sha1();
- for (test t in tests) {
- sh.input_str(t.input);
- auto out = sh.result();
- check_vec_eq(t.output, out);
- sh.reset();
- }
-
- // Test that it works when accepting the message in pieces
- for (test t in tests) {
- auto len = str::byte_len(t.input);
- auto left = len;
- while (left > 0u) {
- auto take = (left + 1u) / 2u;
- sh.input_str(str::substr(t.input, len - left, take));
- left = left - take;
- }
- auto out = sh.result();
- check_vec_eq(t.output, out);
- sh.reset();
- }
-}
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-// xfail-stage0
-
-use std;
-
-fn check_sort(&int[] v1, &int[] v2) {
- auto len = std::ivec::len[int](v1);
- fn lteq(&int a, &int b) -> bool { ret a <= b; }
- auto f = lteq;
- auto v3 = std::sort::ivector::merge_sort[int](f, v1);
- auto i = 0u;
- while (i < len) { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; }
-}
-
-fn main() {
- {
- auto v1 = ~[3, 7, 4, 5, 2, 9, 5, 8];
- auto v2 = ~[2, 3, 4, 5, 5, 7, 8, 9];
- check_sort(v1, v2);
- }
- { auto v1 = ~[1, 1, 1]; auto v2 = ~[1, 1, 1]; check_sort(v1, v2); }
- { let int[] v1 = ~[]; let int[] v2 = ~[]; check_sort(v1, v2); }
- { auto v1 = ~[9]; auto v2 = ~[9]; check_sort(v1, v2); }
- {
- auto v1 = ~[9, 3, 3, 3, 9];
- auto v2 = ~[3, 3, 3, 9, 9];
- check_sort(v1, v2);
- }
-}
+++ /dev/null
-
-use std;
-
-fn check_sort(vec[int] v1, vec[int] v2) {
- auto len = std::vec::len[int](v1);
- fn lteq(&int a, &int b) -> bool { ret a <= b; }
- auto f = lteq;
- auto v3 = std::sort::merge_sort[int](f, v1);
- auto i = 0u;
- while (i < len) { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; }
-}
-
-fn main() {
- {
- auto v1 = [3, 7, 4, 5, 2, 9, 5, 8];
- auto v2 = [2, 3, 4, 5, 5, 7, 8, 9];
- check_sort(v1, v2);
- }
- { auto v1 = [1, 1, 1]; auto v2 = [1, 1, 1]; check_sort(v1, v2); }
- { let vec[int] v1 = []; let vec[int] v2 = []; check_sort(v1, v2); }
- { auto v1 = [9]; auto v2 = [9]; check_sort(v1, v2); }
- {
- auto v1 = [9, 3, 3, 3, 9];
- auto v2 = [3, 3, 3, 9, 9];
- check_sort(v1, v2);
- }
-}
\ No newline at end of file
+++ /dev/null
-
-
-// -*- rust -*-
-use std;
-import std::str;
-
-fn main() {
- auto s = "hello";
- auto sb = str::buf(s);
- auto s_cstr = str::str_from_cstr(sb);
- assert (str::eq(s_cstr, s));
- auto s_buf = str::str_from_buf(sb, 5u);
- assert (str::eq(s_buf, s));
-}
\ No newline at end of file
+++ /dev/null
-
-
-// xfail-stage0
-use std;
-import std::str;
-
-fn test_bytes_len() {
- assert (str::byte_len("") == 0u);
- assert (str::byte_len("hello world") == 11u);
- assert (str::byte_len("\x63") == 1u);
- assert (str::byte_len("\xa2") == 2u);
- assert (str::byte_len("\u03c0") == 2u);
- assert (str::byte_len("\u2620") == 3u);
- assert (str::byte_len("\U0001d11e") == 4u);
-}
-
-fn test_index_and_rindex() {
- assert (str::index("hello", 'e' as u8) == 1);
- assert (str::index("hello", 'o' as u8) == 4);
- assert (str::index("hello", 'z' as u8) == -1);
- assert (str::rindex("hello", 'l' as u8) == 3);
- assert (str::rindex("hello", 'h' as u8) == 0);
- assert (str::rindex("hello", 'z' as u8) == -1);
-}
-
-fn test_split() {
- fn t(&str s, char c, int i, &str k) {
- log "splitting: " + s;
- log i;
- auto v = str::split(s, c as u8);
- log "split to: ";
- for (str z in v) { log z; }
- log "comparing: " + v.(i) + " vs. " + k;
- assert (str::eq(v.(i), k));
- }
- t("abc.hello.there", '.', 0, "abc");
- t("abc.hello.there", '.', 1, "hello");
- t("abc.hello.there", '.', 2, "there");
- t(".hello.there", '.', 0, "");
- t(".hello.there", '.', 1, "hello");
- t("...hello.there.", '.', 3, "hello");
- t("...hello.there.", '.', 5, "");
-}
-
-fn test_find() {
- fn t(&str haystack, &str needle, int i) {
- let int j = str::find(haystack, needle);
- log "searched for " + needle;
- log j;
- assert (i == j);
- }
- t("this is a simple", "is a", 5);
- t("this is a simple", "is z", -1);
- t("this is a simple", "", 0);
- t("this is a simple", "simple", 10);
- t("this", "simple", -1);
-}
-
-fn test_substr() {
- fn t(&str a, &str b, int start) {
- assert (str::eq(str::substr(a, start as uint, str::byte_len(b)), b));
- }
- t("hello", "llo", 2);
- t("hello", "el", 1);
- t("substr should not be a challenge", "not", 14);
-}
-
-fn test_concat() {
- fn t(&vec[str] v, &str s) { assert (str::eq(str::concat(v), s)); }
- t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood");
- let vec[str] v = [];
- t(v, "");
- t(["hi"], "hi");
-}
-
-fn test_connect() {
- fn t(&vec[str] v, &str sep, &str s) {
- assert (str::eq(str::connect(v, sep), s));
- }
- t(["you", "know", "I'm", "no", "good"], " ", "you know I'm no good");
- let vec[str] v = [];
- t(v, " ", "");
- t(["hi"], " ", "hi");
-}
-
-fn test_to_upper() {
- // to_upper doesn't understand unicode yet,
- // but we need to at least preserve it
-
- auto unicode = "\u65e5\u672c";
- auto input = "abcDEF" + unicode + "xyz:.;";
- auto expected = "ABCDEF" + unicode + "XYZ:.;";
- auto actual = str::to_upper(input);
- assert (str::eq(expected, actual));
-}
-
-fn test_slice() {
- assert (str::eq("ab", str::slice("abc", 0u, 2u)));
- assert (str::eq("bc", str::slice("abc", 1u, 3u)));
- assert (str::eq("", str::slice("abc", 1u, 1u)));
- fn a_million_letter_a() -> str {
- auto i = 0;
- auto rs = "";
- while (i < 100000) { rs += "aaaaaaaaaa"; i += 1; }
- ret rs;
- }
- fn half_a_million_letter_a() -> str {
- auto i = 0;
- auto rs = "";
- while (i < 100000) { rs += "aaaaa"; i += 1; }
- ret rs;
- }
- assert (str::eq(half_a_million_letter_a(),
- str::slice(a_million_letter_a(), 0u, 500000u)));
-}
-
-fn test_ends_with() {
- assert (str::ends_with("", ""));
- assert (str::ends_with("abc", ""));
- assert (str::ends_with("abc", "c"));
- assert (!str::ends_with("a", "abc"));
- assert (!str::ends_with("", "abc"));
-}
-
-fn test_is_empty() {
- assert str::is_empty("");
- assert !str::is_empty("a");
-}
-
-fn test_is_not_empty() {
- assert str::is_not_empty("a");
- assert !str::is_not_empty("");
-}
-
-fn test_replace() {
- auto a = "a";
- check str::is_not_empty(a);
- assert str::replace("", a, "b") == "";
- assert str::replace("a", a, "b") == "b";
- assert str::replace("ab", a, "b") == "bb";
- auto test = "test";
- check str::is_not_empty(test);
- assert str::replace(" test test ", test, "toast")
- == " toast toast ";
- assert str::replace(" test test ", test, "") == " ";
-}
-
-fn main() {
- test_bytes_len();
- test_index_and_rindex();
- test_split();
- test_find();
- test_substr();
- test_concat();
- test_connect();
- test_to_upper();
- test_slice();
- test_ends_with();
- test_is_empty();
- test_is_not_empty();
- test_replace();
-}
-
-
-// Local Variables:
-// mode: rust;
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
-// End:
+++ /dev/null
-
-
-// xfail-stage0
-
-use std;
-import std::task;
-
-fn test_sleep() { task::sleep(1000000u); }
-
-fn test_unsupervise() {
- fn f() {
- task::unsupervise();
- fail;
- }
- spawn f();
-}
-
-fn test_join() {
- fn winner() {
- }
-
- auto wintask = spawn winner();
-
- assert task::join(wintask) == task::tr_success;
-
- fn failer() {
- task::unsupervise();
- fail;
- }
-
- auto failtask = spawn failer();
-
- assert task::join(failtask) == task::tr_failure;
-}
-
-fn main() {
- // FIXME: Why aren't we running this?
- //test_sleep();
- test_unsupervise();
- test_join();
-}
\ No newline at end of file
+++ /dev/null
-
-
-// -*- rust -*-
-use std;
-import std::uint;
-
-fn main() {
- assert (uint::next_power_of_two(0u) == 0u);
- assert (uint::next_power_of_two(1u) == 1u);
- assert (uint::next_power_of_two(2u) == 2u);
- assert (uint::next_power_of_two(3u) == 4u);
- assert (uint::next_power_of_two(4u) == 4u);
- assert (uint::next_power_of_two(5u) == 8u);
- assert (uint::next_power_of_two(6u) == 8u);
- assert (uint::next_power_of_two(7u) == 8u);
- assert (uint::next_power_of_two(8u) == 8u);
- assert (uint::next_power_of_two(9u) == 16u);
- assert (uint::next_power_of_two(10u) == 16u);
- assert (uint::next_power_of_two(11u) == 16u);
- assert (uint::next_power_of_two(12u) == 16u);
- assert (uint::next_power_of_two(13u) == 16u);
- assert (uint::next_power_of_two(14u) == 16u);
- assert (uint::next_power_of_two(15u) == 16u);
- assert (uint::next_power_of_two(16u) == 16u);
- assert (uint::next_power_of_two(17u) == 32u);
- assert (uint::next_power_of_two(18u) == 32u);
- assert (uint::next_power_of_two(19u) == 32u);
- assert (uint::next_power_of_two(20u) == 32u);
- assert (uint::next_power_of_two(21u) == 32u);
- assert (uint::next_power_of_two(22u) == 32u);
- assert (uint::next_power_of_two(23u) == 32u);
- assert (uint::next_power_of_two(24u) == 32u);
- assert (uint::next_power_of_two(25u) == 32u);
- assert (uint::next_power_of_two(26u) == 32u);
- assert (uint::next_power_of_two(27u) == 32u);
- assert (uint::next_power_of_two(28u) == 32u);
- assert (uint::next_power_of_two(29u) == 32u);
- assert (uint::next_power_of_two(30u) == 32u);
- assert (uint::next_power_of_two(31u) == 32u);
- assert (uint::next_power_of_two(32u) == 32u);
- assert (uint::next_power_of_two(33u) == 64u);
- assert (uint::next_power_of_two(34u) == 64u);
- assert (uint::next_power_of_two(35u) == 64u);
- assert (uint::next_power_of_two(36u) == 64u);
- assert (uint::next_power_of_two(37u) == 64u);
- assert (uint::next_power_of_two(38u) == 64u);
- assert (uint::next_power_of_two(39u) == 64u);
-}
\ No newline at end of file
+++ /dev/null
-
-
-// -*- rust -*-
-use std;
-import std::str;
-import std::vec;
-
-fn test_simple() {
- let str s1 = "All mimsy were the borogoves";
- /*
- * FIXME from_bytes(vec[u8] v) has constraint is_utf(v), which is
- * unimplemented and thereby just fails. This doesn't stop us from
- * using from_bytes for now since the constraint system isn't fully
- * working, but we should implement is_utf8 before that happens.
- */
-
- let vec[u8] v = str::bytes(s1);
- let str s2 = str::from_bytes(v);
- let uint i = 0u;
- let uint n1 = str::byte_len(s1);
- let uint n2 = vec::len[u8](v);
- assert (n1 == n2);
- while (i < n1) {
- let u8 a = s1.(i);
- let u8 b = s2.(i);
- log a;
- log b;
- assert (a == b);
- i += 1u;
- }
- log "refcnt is";
- log str::refcount(s1);
-}
-
-fn main() { test_simple(); }
\ No newline at end of file
+++ /dev/null
-
-use std;
-
-import std::vec::*;
-import std::option;
-
-fn test_init_elt() {
- let vec[uint] v = init_elt[uint](5u, 3u);
- assert (len[uint](v) == 3u);
- assert (v.(0) == 5u);
- assert (v.(1) == 5u);
- assert (v.(2) == 5u);
-}
-
-fn id(uint x) -> uint { ret x; }
-
-fn test_init_fn() {
- let fn(uint) -> uint op = id;
- let vec[uint] v = init_fn[uint](op, 5u);
- assert (len[uint](v) == 5u);
- assert (v.(0) == 0u);
- assert (v.(1) == 1u);
- assert (v.(2) == 2u);
- assert (v.(3) == 3u);
- assert (v.(4) == 4u);
-}
-
-fn test_slice() {
- let vec[int] v = [1, 2, 3, 4, 5];
- auto v2 = slice[int](v, 2u, 4u);
- assert (len[int](v2) == 2u);
- assert (v2.(0) == 3);
- assert (v2.(1) == 4);
-}
-
-fn test_map() {
- fn square(&int x) -> int { ret x * x; }
- let option::operator[int, int] op = square;
- let vec[int] v = [1, 2, 3, 4, 5];
- let vec[int] s = map[int, int](op, v);
- let int i = 0;
- while (i < 5) { assert (v.(i) * v.(i) == s.(i)); i += 1; }
-}
-
-fn test_map2() {
- fn times(&int x, &int y) -> int { ret x * y; }
- auto f = times;
- auto v0 = [1, 2, 3, 4, 5];
- auto v1 = [5, 4, 3, 2, 1];
- auto u = map2[int, int, int](f, v0, v1);
- auto i = 0;
- while (i < 5) { assert (v0.(i) * v1.(i) == u.(i)); i += 1; }
-}
-
-fn test_filter_map() {
- fn halve(&int i) -> option::t[int] {
- if (i % 2 == 0) {
- ret option::some[int](i / 2);
- } else { ret option::none[int]; }
- }
- fn halve_for_sure(&int i) -> int { ret i / 2; }
- let vec[int] all_even = [0, 2, 8, 6];
- let vec[int] all_odd1 = [1, 7, 3];
- let vec[int] all_odd2 = [];
- let vec[int] mix = [9, 2, 6, 7, 1, 0, 0, 3];
- let vec[int] mix_dest = [1, 3, 0, 0];
- assert (filter_map(halve, all_even) ==
- map(halve_for_sure, all_even));
- assert (filter_map(halve, all_odd1) == empty[int]());
- assert (filter_map(halve, all_odd2) == empty[int]());
- assert (filter_map(halve, mix) == mix_dest);
-}
-
-fn test_position() {
- let vec[int] v1 = [1, 2, 3, 3, 2, 5];
- assert (position(1, v1) == option::some[uint](0u));
- assert (position(2, v1) == option::some[uint](1u));
- assert (position(5, v1) == option::some[uint](5u));
- assert (position(4, v1) == option::none[uint]);
-}
-
-fn test_position_pred() {
- fn less_than_three(&int i) -> bool {
- ret i <3;
- }
- fn is_eighteen(&int i) -> bool {
- ret i == 18;
- }
- let vec[int] v1 = [5, 4, 3, 2, 1];
- assert (position_pred(less_than_three, v1) == option::some[uint](3u));
- assert (position_pred(is_eighteen, v1) == option::none[uint]);
-}
-
-fn main() {
- test_init_elt();
- test_init_fn();
- test_slice();
- test_map();
- test_map2();
- test_filter_map();
- test_position();
- test_position_pred();
-}
\ No newline at end of file
--- /dev/null
+// compile-flags:--test
+// xfail-fast
+
+use std;
+
+// Building as a test runner means that a synthetic main will be run,
+// not ours
+fn main() {
+ fail;
+}
\ No newline at end of file
--- /dev/null
+
+use std;
+import std::vec;
+import std::bitv;
+
+#[test]
+fn test_0_elements() {
+ auto act;
+ auto exp;
+ act = bitv::create(0u, false);
+ exp = vec::init_elt[uint](0u, 0u);
+ // FIXME: why can't I write vec[uint]()?
+
+ assert (bitv::eq_vec(act, exp));
+}
+
+#[test]
+fn test_1_element() {
+ auto act;
+ act = bitv::create(1u, false);
+ assert (bitv::eq_vec(act, [0u]));
+ act = bitv::create(1u, true);
+ assert (bitv::eq_vec(act, [1u]));
+}
+
+#[test]
+fn test_10_elements() {
+ auto act;
+ // all 0
+
+ act = bitv::create(10u, false);
+ assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
+ // all 1
+
+ act = bitv::create(10u, true);
+ assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u]));
+ // mixed
+
+ act = bitv::create(10u, false);
+ bitv::set(act, 0u, true);
+ bitv::set(act, 1u, true);
+ bitv::set(act, 2u, true);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 4u, true);
+ assert (bitv::eq_vec(act, [1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u]));
+ // mixed
+
+ act = bitv::create(10u, false);
+ bitv::set(act, 5u, true);
+ bitv::set(act, 6u, true);
+ bitv::set(act, 7u, true);
+ bitv::set(act, 8u, true);
+ bitv::set(act, 9u, true);
+ assert (bitv::eq_vec(act, [0u, 0u, 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u]));
+ // mixed
+
+ act = bitv::create(10u, false);
+ bitv::set(act, 0u, true);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 6u, true);
+ bitv::set(act, 9u, true);
+ assert (bitv::eq_vec(act, [1u, 0u, 0u, 1u, 0u, 0u, 1u, 0u, 0u, 1u]));
+}
+
+#[test]
+fn test_31_elements() {
+ auto act;
+ // all 0
+
+ act = bitv::create(31u, false);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u]));
+ // all 1
+
+ act = bitv::create(31u, true);
+ assert (bitv::eq_vec(act,
+ [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ 1u, 1u, 1u, 1u, 1u]));
+ // mixed
+
+ act = bitv::create(31u, false);
+ bitv::set(act, 0u, true);
+ bitv::set(act, 1u, true);
+ bitv::set(act, 2u, true);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 4u, true);
+ bitv::set(act, 5u, true);
+ bitv::set(act, 6u, true);
+ bitv::set(act, 7u, true);
+ assert (bitv::eq_vec(act,
+ [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u]));
+ // mixed
+
+ act = bitv::create(31u, false);
+ bitv::set(act, 16u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 18u, true);
+ bitv::set(act, 19u, true);
+ bitv::set(act, 20u, true);
+ bitv::set(act, 21u, true);
+ bitv::set(act, 22u, true);
+ bitv::set(act, 23u, true);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u]));
+ // mixed
+
+ act = bitv::create(31u, false);
+ bitv::set(act, 24u, true);
+ bitv::set(act, 25u, true);
+ bitv::set(act, 26u, true);
+ bitv::set(act, 27u, true);
+ bitv::set(act, 28u, true);
+ bitv::set(act, 29u, true);
+ bitv::set(act, 30u, true);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u,
+ 1u, 1u, 1u, 1u, 1u]));
+ // mixed
+
+ act = bitv::create(31u, false);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 30u, true);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 1u]));
+}
+
+#[test]
+fn test_32_elements() {
+ auto act;
+ // all 0
+
+ act = bitv::create(32u, false);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u]));
+ // all 1
+
+ act = bitv::create(32u, true);
+ assert (bitv::eq_vec(act,
+ [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ 1u, 1u, 1u, 1u, 1u, 1u]));
+ // mixed
+
+ act = bitv::create(32u, false);
+ bitv::set(act, 0u, true);
+ bitv::set(act, 1u, true);
+ bitv::set(act, 2u, true);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 4u, true);
+ bitv::set(act, 5u, true);
+ bitv::set(act, 6u, true);
+ bitv::set(act, 7u, true);
+ assert (bitv::eq_vec(act,
+ [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u]));
+ // mixed
+
+ act = bitv::create(32u, false);
+ bitv::set(act, 16u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 18u, true);
+ bitv::set(act, 19u, true);
+ bitv::set(act, 20u, true);
+ bitv::set(act, 21u, true);
+ bitv::set(act, 22u, true);
+ bitv::set(act, 23u, true);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u]));
+ // mixed
+
+ act = bitv::create(32u, false);
+ bitv::set(act, 24u, true);
+ bitv::set(act, 25u, true);
+ bitv::set(act, 26u, true);
+ bitv::set(act, 27u, true);
+ bitv::set(act, 28u, true);
+ bitv::set(act, 29u, true);
+ bitv::set(act, 30u, true);
+ bitv::set(act, 31u, true);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u,
+ 1u, 1u, 1u, 1u, 1u, 1u]));
+ // mixed
+
+ act = bitv::create(32u, false);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 30u, true);
+ bitv::set(act, 31u, true);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 1u, 1u]));
+}
+
+#[test]
+fn test_33_elements() {
+ auto act;
+ // all 0
+
+ act = bitv::create(33u, false);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
+ // all 1
+
+ act = bitv::create(33u, true);
+ assert (bitv::eq_vec(act,
+ [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u,
+ 1u, 1u, 1u, 1u, 1u, 1u, 1u]));
+ // mixed
+
+ act = bitv::create(33u, false);
+ bitv::set(act, 0u, true);
+ bitv::set(act, 1u, true);
+ bitv::set(act, 2u, true);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 4u, true);
+ bitv::set(act, 5u, true);
+ bitv::set(act, 6u, true);
+ bitv::set(act, 7u, true);
+ assert (bitv::eq_vec(act,
+ [1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
+ // mixed
+
+ act = bitv::create(33u, false);
+ bitv::set(act, 16u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 18u, true);
+ bitv::set(act, 19u, true);
+ bitv::set(act, 20u, true);
+ bitv::set(act, 21u, true);
+ bitv::set(act, 22u, true);
+ bitv::set(act, 23u, true);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 1u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u]));
+ // mixed
+
+ act = bitv::create(33u, false);
+ bitv::set(act, 24u, true);
+ bitv::set(act, 25u, true);
+ bitv::set(act, 26u, true);
+ bitv::set(act, 27u, true);
+ bitv::set(act, 28u, true);
+ bitv::set(act, 29u, true);
+ bitv::set(act, 30u, true);
+ bitv::set(act, 31u, true);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 1u, 1u,
+ 1u, 1u, 1u, 1u, 1u, 1u, 0u]));
+ // mixed
+
+ act = bitv::create(33u, false);
+ bitv::set(act, 3u, true);
+ bitv::set(act, 17u, true);
+ bitv::set(act, 30u, true);
+ bitv::set(act, 31u, true);
+ bitv::set(act, 32u, true);
+ assert (bitv::eq_vec(act,
+ [0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 1u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u,
+ 0u, 0u, 0u, 0u, 1u, 1u, 1u]));
+}
+
--- /dev/null
+
+use std;
+import std::box;
+
+#[test]
+fn test() {
+ auto x = @3;
+ auto y = @3;
+ assert (box::ptr_eq[int](x, x));
+ assert (box::ptr_eq[int](y, y));
+ assert (!box::ptr_eq[int](x, y));
+ assert (!box::ptr_eq[int](y, x));
+}
\ No newline at end of file
--- /dev/null
+
+
+// -*- rust -*-
+use std;
+import std::deque;
+
+#[test]
+fn test_simple() {
+ let deque::t[int] d = deque::create[int]();
+ assert (d.size() == 0u);
+ d.add_front(17);
+ d.add_front(42);
+ d.add_back(137);
+ assert (d.size() == 3u);
+ d.add_back(137);
+ assert (d.size() == 4u);
+ log d.peek_front();
+ assert (d.peek_front() == 42);
+ log d.peek_back();
+ assert (d.peek_back() == 137);
+ let int i = d.pop_front();
+ log i;
+ assert (i == 42);
+ i = d.pop_back();
+ log i;
+ assert (i == 137);
+ i = d.pop_back();
+ log i;
+ assert (i == 137);
+ i = d.pop_back();
+ log i;
+ assert (i == 17);
+ assert (d.size() == 0u);
+ d.add_back(3);
+ assert (d.size() == 1u);
+ d.add_front(2);
+ assert (d.size() == 2u);
+ d.add_back(4);
+ assert (d.size() == 3u);
+ d.add_front(1);
+ assert (d.size() == 4u);
+ log d.get(0);
+ log d.get(1);
+ log d.get(2);
+ log d.get(3);
+ assert (d.get(0) == 1);
+ assert (d.get(1) == 2);
+ assert (d.get(2) == 3);
+ assert (d.get(3) == 4);
+}
+
+fn test_boxes(@int a, @int b, @int c, @int d) {
+ let deque::t[@int] deq = deque::create[@int]();
+ assert (deq.size() == 0u);
+ deq.add_front(a);
+ deq.add_front(b);
+ deq.add_back(c);
+ assert (deq.size() == 3u);
+ deq.add_back(d);
+ assert (deq.size() == 4u);
+ assert (deq.peek_front() == b);
+ assert (deq.peek_back() == d);
+ assert (deq.pop_front() == b);
+ assert (deq.pop_back() == d);
+ assert (deq.pop_back() == c);
+ assert (deq.pop_back() == a);
+ assert (deq.size() == 0u);
+ deq.add_back(c);
+ assert (deq.size() == 1u);
+ deq.add_front(b);
+ assert (deq.size() == 2u);
+ deq.add_back(d);
+ assert (deq.size() == 3u);
+ deq.add_front(a);
+ assert (deq.size() == 4u);
+ assert (deq.get(0) == a);
+ assert (deq.get(1) == b);
+ assert (deq.get(2) == c);
+ assert (deq.get(3) == d);
+}
+
+type eqfn[T] = fn(&T, &T) -> bool ;
+
+fn test_parameterized[T](eqfn[T] e, &T a, &T b, &T c, &T d) {
+ let deque::t[T] deq = deque::create[T]();
+ assert (deq.size() == 0u);
+ deq.add_front(a);
+ deq.add_front(b);
+ deq.add_back(c);
+ assert (deq.size() == 3u);
+ deq.add_back(d);
+ assert (deq.size() == 4u);
+ assert (e(deq.peek_front(), b));
+ assert (e(deq.peek_back(), d));
+ assert (e(deq.pop_front(), b));
+ assert (e(deq.pop_back(), d));
+ assert (e(deq.pop_back(), c));
+ assert (e(deq.pop_back(), a));
+ assert (deq.size() == 0u);
+ deq.add_back(c);
+ assert (deq.size() == 1u);
+ deq.add_front(b);
+ assert (deq.size() == 2u);
+ deq.add_back(d);
+ assert (deq.size() == 3u);
+ deq.add_front(a);
+ assert (deq.size() == 4u);
+ assert (e(deq.get(0), a));
+ assert (e(deq.get(1), b));
+ assert (e(deq.get(2), c));
+ assert (e(deq.get(3), d));
+}
+
+tag taggy { one(int); two(int, int); three(int, int, int); }
+
+tag taggypar[T] { onepar(int); twopar(int, int); threepar(int, int, int); }
+
+type reccy = rec(int x, int y, taggy t);
+
+#[test]
+fn test() {
+ fn inteq(&int a, &int b) -> bool { ret a == b; }
+ fn intboxeq(&@int a, &@int b) -> bool { ret a == b; }
+ fn taggyeq(&taggy a, &taggy b) -> bool {
+ alt (a) {
+ case (one(?a1)) {
+ alt (b) {
+ case (one(?b1)) { ret a1 == b1; }
+ case (_) { ret false; }
+ }
+ }
+ case (two(?a1, ?a2)) {
+ alt (b) {
+ case (two(?b1, ?b2)) { ret a1 == b1 && a2 == b2; }
+ case (_) { ret false; }
+ }
+ }
+ case (three(?a1, ?a2, ?a3)) {
+ alt (b) {
+ case (three(?b1, ?b2, ?b3)) {
+ ret a1 == b1 && a2 == b2 && a3 == b3;
+ }
+ case (_) { ret false; }
+ }
+ }
+ }
+ }
+ fn taggypareq[T](&taggypar[T] a, &taggypar[T] b) -> bool {
+ alt (a) {
+ case (onepar[T](?a1)) {
+ alt (b) {
+ case (onepar[T](?b1)) { ret a1 == b1; }
+ case (_) { ret false; }
+ }
+ }
+ case (twopar[T](?a1, ?a2)) {
+ alt (b) {
+ case (twopar[T](?b1, ?b2)) { ret a1 == b1 && a2 == b2; }
+ case (_) { ret false; }
+ }
+ }
+ case (threepar[T](?a1, ?a2, ?a3)) {
+ alt (b) {
+ case (threepar[T](?b1, ?b2, ?b3)) {
+ ret a1 == b1 && a2 == b2 && a3 == b3;
+ }
+ case (_) { ret false; }
+ }
+ }
+ }
+ }
+ fn reccyeq(&reccy a, &reccy b) -> bool {
+ ret a.x == b.x && a.y == b.y && taggyeq(a.t, b.t);
+ }
+ log "*** test boxes";
+ test_boxes(@5, @72, @64, @175);
+ log "*** end test boxes";
+ log "test parameterized: int";
+ let eqfn[int] eq1 = inteq;
+ test_parameterized[int](eq1, 5, 72, 64, 175);
+ log "*** test parameterized: @int";
+ let eqfn[@int] eq2 = intboxeq;
+ test_parameterized[@int](eq2, @5, @72, @64, @175);
+ log "*** end test parameterized @int";
+ log "test parameterized: taggy";
+ let eqfn[taggy] eq3 = taggyeq;
+ test_parameterized[taggy](eq3, one(1), two(1, 2), three(1, 2, 3),
+ two(17, 42));
+ /*
+ * FIXME: Segfault. Also appears to be caused only after upcall_grow_task
+
+ log "*** test parameterized: taggypar[int]";
+ let eqfn[taggypar[int]] eq4 = taggypareq[int];
+ test_parameterized[taggypar[int]](eq4,
+ onepar[int](1),
+ twopar[int](1, 2),
+ threepar[int](1, 2, 3),
+ twopar[int](17, 42));
+ log "*** end test parameterized: taggypar[int]";
+
+ */
+
+ log "*** test parameterized: reccy";
+ let reccy reccy1 = rec(x=1, y=2, t=one(1));
+ let reccy reccy2 = rec(x=345, y=2, t=two(1, 2));
+ let reccy reccy3 = rec(x=1, y=777, t=three(1, 2, 3));
+ let reccy reccy4 = rec(x=19, y=252, t=two(17, 42));
+ let eqfn[reccy] eq5 = reccyeq;
+ test_parameterized[reccy](eq5, reccy1, reccy2, reccy3, reccy4);
+ log "*** end test parameterized: reccy";
+ log "*** done";
+}
\ No newline at end of file
--- /dev/null
+use std;
+import std::either::*;
+import std::ivec::len;
+
+#[test]
+fn test_either_left() {
+ auto val = left(10);
+ fn f_left(&int x) -> bool { x == 10 }
+ fn f_right(&uint x) -> bool { false }
+ assert (either(f_left, f_right, val));
+}
+
+#[test]
+fn test_either_right() {
+ auto val = right(10u);
+ fn f_left(&int x) -> bool { false }
+ fn f_right(&uint x) -> bool { x == 10u }
+ assert (either(f_left, f_right, val));
+}
+
+#[test]
+fn test_lefts() {
+ auto input = ~[left(10),
+ right(11),
+ left(12),
+ right(13),
+ left(14)];
+ auto result = lefts(input);
+ assert (result == ~[10, 12, 14]);
+}
+
+#[test]
+fn test_lefts_none() {
+ let (t[int, int])[] input = ~[right(10),
+ right(10)];
+ auto result = lefts(input);
+ assert (len(result) == 0u);
+}
+
+#[test]
+fn test_lefts_empty() {
+ let (t[int, int])[] input = ~[];
+ auto result = lefts(input);
+ assert (len(result) == 0u);
+}
+
+#[test]
+fn test_rights() {
+ auto input = ~[left(10),
+ right(11),
+ left(12),
+ right(13),
+ left(14)];
+ auto result = rights(input);
+ assert (result == ~[11, 13]);
+}
+
+#[test]
+fn test_rights_none() {
+ let (t[int, int])[] input = ~[left(10),
+ left(10)];
+ auto result = rights(input);
+ assert (len(result) == 0u);
+}
+
+#[test]
+fn test_rights_empty() {
+ let (t[int, int])[] input = ~[];
+ auto result = rights(input);
+ assert (len(result) == 0u);
+}
+
+#[test]
+fn test_partition() {
+ auto input = ~[left(10),
+ right(11),
+ left(12),
+ right(13),
+ left(14)];
+ auto result = partition(input);
+ assert (result._0.(0) == 10);
+ assert (result._0.(1) == 12);
+ assert (result._0.(2) == 14);
+ assert (result._1.(0) == 11);
+ assert (result._1.(1) == 13);
+}
+
+#[test]
+fn test_partition_no_lefts() {
+ let (t[int, int])[] input = ~[right(10),
+ right(11)];
+ auto result = partition(input);
+ assert (len(result._0) == 0u);
+ assert (len(result._1) == 2u);
+}
+
+#[test]
+fn test_partition_no_rights() {
+ let (t[int, int])[] input = ~[left(10),
+ left(11)];
+ auto result = partition(input);
+ assert (len(result._0) == 2u);
+ assert (len(result._1) == 0u);
+}
+
+#[test]
+fn test_partition_empty() {
+ let (t[int, int])[] input = ~[];
+ auto result = partition(input);
+ assert (len(result._0) == 0u);
+ assert (len(result._1) == 0u);
+}
--- /dev/null
+
+use std;
+import std::fs;
+
+#[test]
+fn test_connect() {
+ auto slash = fs::path_sep();
+ log_err fs::connect("a", "b");
+ assert (fs::connect("a", "b") == "a" + slash + "b");
+ assert (fs::connect("a" + slash, "b") == "a" + slash + "b");
+}
+
+// Issue #712
+#[test]
+fn test_list_dir_no_invalid_memory_access() {
+ fs::list_dir(".");
+}
+
--- /dev/null
+
+use std;
+import std::vec;
+import std::option;
+import opt = std::getopts;
+
+tag fail_type {
+ argument_missing;
+ unrecognized_option;
+ option_missing;
+ option_duplicated;
+ unexpected_argument;
+}
+
+fn check_fail_type(opt::fail_ f, fail_type ft) {
+ alt (f) {
+ case (opt::argument_missing(_)) { assert (ft == argument_missing); }
+ case (opt::unrecognized_option(_)) {
+ assert (ft == unrecognized_option);
+ }
+ case (opt::option_missing(_)) { assert (ft == option_missing); }
+ case (opt::option_duplicated(_)) { assert (ft == option_duplicated); }
+ case (opt::unexpected_argument(_)) {
+ assert (ft == unexpected_argument);
+ }
+ case (_) { fail; }
+ }
+}
+
+
+// Tests for reqopt
+#[test]
+fn test_reqopt_long() {
+ auto args = ["--test=20"];
+ auto opts = [opt::reqopt("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) {
+ assert (opt::opt_present(m, "test"));
+ assert (opt::opt_str(m, "test") == "20");
+ }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_reqopt_long_missing() {
+ auto args = ["blah"];
+ auto opts = [opt::reqopt("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, option_missing); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_reqopt_long_no_arg() {
+ auto args = ["--test"];
+ auto opts = [opt::reqopt("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_reqopt_long_multi() {
+ auto args = ["--test=20", "--test=30"];
+ auto opts = [opt::reqopt("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_reqopt_short() {
+ auto args = ["-t", "20"];
+ auto opts = [opt::reqopt("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) {
+ assert (opt::opt_present(m, "t"));
+ assert (opt::opt_str(m, "t") == "20");
+ }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_reqopt_short_missing() {
+ auto args = ["blah"];
+ auto opts = [opt::reqopt("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, option_missing); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_reqopt_short_no_arg() {
+ auto args = ["-t"];
+ auto opts = [opt::reqopt("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_reqopt_short_multi() {
+ auto args = ["-t", "20", "-t", "30"];
+ auto opts = [opt::reqopt("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
+ case (_) { fail; }
+ }
+}
+
+
+// Tests for optopt
+#[test]
+fn test_optopt_long() {
+ auto args = ["--test=20"];
+ auto opts = [opt::optopt("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) {
+ assert (opt::opt_present(m, "test"));
+ assert (opt::opt_str(m, "test") == "20");
+ }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optopt_long_missing() {
+ auto args = ["blah"];
+ auto opts = [opt::optopt("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optopt_long_no_arg() {
+ auto args = ["--test"];
+ auto opts = [opt::optopt("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optopt_long_multi() {
+ auto args = ["--test=20", "--test=30"];
+ auto opts = [opt::optopt("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optopt_short() {
+ auto args = ["-t", "20"];
+ auto opts = [opt::optopt("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) {
+ assert (opt::opt_present(m, "t"));
+ assert (opt::opt_str(m, "t") == "20");
+ }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optopt_short_missing() {
+ auto args = ["blah"];
+ auto opts = [opt::optopt("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optopt_short_no_arg() {
+ auto args = ["-t"];
+ auto opts = [opt::optopt("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optopt_short_multi() {
+ auto args = ["-t", "20", "-t", "30"];
+ auto opts = [opt::optopt("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
+ case (_) { fail; }
+ }
+}
+
+
+// Tests for optflag
+#[test]
+fn test_optflag_long() {
+ auto args = ["--test"];
+ auto opts = [opt::optflag("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) { assert (opt::opt_present(m, "test")); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optflag_long_missing() {
+ auto args = ["blah"];
+ auto opts = [opt::optflag("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optflag_long_arg() {
+ auto args = ["--test=20"];
+ auto opts = [opt::optflag("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) {
+ log_err opt::fail_str(f);
+ check_fail_type(f, unexpected_argument);
+ }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optflag_long_multi() {
+ auto args = ["--test", "--test"];
+ auto opts = [opt::optflag("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optflag_short() {
+ auto args = ["-t"];
+ auto opts = [opt::optflag("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) { assert (opt::opt_present(m, "t")); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optflag_short_missing() {
+ auto args = ["blah"];
+ auto opts = [opt::optflag("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optflag_short_arg() {
+ auto args = ["-t", "20"];
+ auto opts = [opt::optflag("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) {
+ // The next variable after the flag is just a free argument
+
+ assert (m.free.(0) == "20");
+ }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optflag_short_multi() {
+ auto args = ["-t", "-t"];
+ auto opts = [opt::optflag("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, option_duplicated); }
+ case (_) { fail; }
+ }
+}
+
+
+// Tests for optmulti
+#[test]
+fn test_optmulti_long() {
+ auto args = ["--test=20"];
+ auto opts = [opt::optmulti("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) {
+ assert (opt::opt_present(m, "test"));
+ assert (opt::opt_str(m, "test") == "20");
+ }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optmulti_long_missing() {
+ auto args = ["blah"];
+ auto opts = [opt::optmulti("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) { assert (!opt::opt_present(m, "test")); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optmulti_long_no_arg() {
+ auto args = ["--test"];
+ auto opts = [opt::optmulti("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optmulti_long_multi() {
+ auto args = ["--test=20", "--test=30"];
+ auto opts = [opt::optmulti("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) {
+ assert (opt::opt_present(m, "test"));
+ assert (opt::opt_str(m, "test") == "20");
+ assert (opt::opt_strs(m, "test").(0) == "20");
+ assert (opt::opt_strs(m, "test").(1) == "30");
+ }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optmulti_short() {
+ auto args = ["-t", "20"];
+ auto opts = [opt::optmulti("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) {
+ assert (opt::opt_present(m, "t"));
+ assert (opt::opt_str(m, "t") == "20");
+ }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optmulti_short_missing() {
+ auto args = ["blah"];
+ auto opts = [opt::optmulti("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) { assert (!opt::opt_present(m, "t")); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optmulti_short_no_arg() {
+ auto args = ["-t"];
+ auto opts = [opt::optmulti("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, argument_missing); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_optmulti_short_multi() {
+ auto args = ["-t", "20", "-t", "30"];
+ auto opts = [opt::optmulti("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) {
+ assert (opt::opt_present(m, "t"));
+ assert (opt::opt_str(m, "t") == "20");
+ assert (opt::opt_strs(m, "t").(0) == "20");
+ assert (opt::opt_strs(m, "t").(1) == "30");
+ }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_unrecognized_option_long() {
+ auto args = ["--untest"];
+ auto opts = [opt::optmulti("t")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, unrecognized_option); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_unrecognized_option_short() {
+ auto args = ["-t"];
+ auto opts = [opt::optmulti("test")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::failure(?f)) { check_fail_type(f, unrecognized_option); }
+ case (_) { fail; }
+ }
+}
+
+#[test]
+fn test_combined() {
+ auto args =
+ ["prog", "free1", "-s", "20", "free2", "--flag", "--long=30", "-f",
+ "-m", "40", "-m", "50"];
+ auto opts =
+ [opt::optopt("s"), opt::optflag("flag"), opt::reqopt("long"),
+ opt::optflag("f"), opt::optmulti("m"), opt::optopt("notpresent")];
+ auto rs = opt::getopts(args, opts);
+ alt (rs) {
+ case (opt::success(?m)) {
+ assert (m.free.(0) == "prog");
+ assert (m.free.(1) == "free1");
+ assert (opt::opt_str(m, "s") == "20");
+ assert (m.free.(2) == "free2");
+ assert (opt::opt_present(m, "flag"));
+ assert (opt::opt_str(m, "long") == "30");
+ assert (opt::opt_present(m, "f"));
+ assert (opt::opt_strs(m, "m").(0) == "40");
+ assert (opt::opt_strs(m, "m").(1) == "50");
+ assert (!opt::opt_present(m, "notpresent"));
+ }
+ case (_) { fail; }
+ }
+}
+
+
+use std;
import std::int;
import std::str::eq;
--- /dev/null
+// -*- rust -*-
+use std;
+import std::io;
+import std::str;
+
+#[cfg(target_os = "linux")]
+#[cfg(target_os = "win32")]
+#[test]
+fn test_simple() {
+ let str tmpfile = "test/run-pass/lib-io-test-simple.tmp";
+ log tmpfile;
+ let str frood = "A hoopy frood who really knows where his towel is.";
+ log frood;
+ {
+ let io::writer out = io::file_writer(tmpfile, [io::create,
+ io::truncate]);
+ out.write_str(frood);
+ }
+ let io::reader inp = io::file_reader(tmpfile);
+ let str frood2 = inp.read_c_str();
+ log frood2;
+ assert (str::eq(frood, frood2));
+}
+
+// FIXME (726)
+#[cfg(target_os = "macos")]
+#[test]
+#[ignore]
+fn test_simple() {}
+
--- /dev/null
+
+use std;
+import std::ivec;
+import std::option;
+import std::option::none;
+import std::option::some;
+
+fn square(uint n) -> uint { ret n * n; }
+
+fn square_alias(&uint n) -> uint { ret n * n; }
+
+pred is_three(&uint n) -> bool { ret n == 3u; }
+
+fn square_if_odd(&uint n) -> option::t[uint] {
+ ret if (n % 2u == 1u) { some(n * n) } else { none };
+}
+
+fn add(&uint x, &uint y) -> uint { ret x + y; }
+
+#[test]
+fn test_reserve_and_on_heap() {
+ let int[] v = ~[ 1, 2 ];
+ assert (!ivec::on_heap(v));
+ ivec::reserve(v, 8u);
+ assert (ivec::on_heap(v));
+}
+
+#[test]
+fn test_unsafe_ptrs() {
+ // Test on-stack copy-from-buf.
+ auto a = ~[ 1, 2, 3 ];
+ auto ptr = ivec::to_ptr(a);
+ auto b = ~[];
+ ivec::unsafe::copy_from_buf(b, ptr, 3u);
+ assert (ivec::len(b) == 3u);
+ assert (b.(0) == 1);
+ assert (b.(1) == 2);
+ assert (b.(2) == 3);
+
+ // Test on-heap copy-from-buf.
+ auto c = ~[ 1, 2, 3, 4, 5 ];
+ ptr = ivec::to_ptr(c);
+ auto d = ~[];
+ ivec::unsafe::copy_from_buf(d, ptr, 5u);
+ assert (ivec::len(d) == 5u);
+ assert (d.(0) == 1);
+ assert (d.(1) == 2);
+ assert (d.(2) == 3);
+ assert (d.(3) == 4);
+ assert (d.(4) == 5);
+}
+
+#[test]
+fn test_init_fn() {
+ // Test on-stack init_fn.
+ auto v = ivec::init_fn(square, 3u);
+ assert (ivec::len(v) == 3u);
+ assert (v.(0) == 0u);
+ assert (v.(1) == 1u);
+ assert (v.(2) == 4u);
+
+ // Test on-heap init_fn.
+ v = ivec::init_fn(square, 5u);
+ assert (ivec::len(v) == 5u);
+ assert (v.(0) == 0u);
+ assert (v.(1) == 1u);
+ assert (v.(2) == 4u);
+ assert (v.(3) == 9u);
+ assert (v.(4) == 16u);
+}
+
+#[test]
+fn test_init_elt() {
+ // Test on-stack init_elt.
+ auto v = ivec::init_elt(10u, 2u);
+ assert (ivec::len(v) == 2u);
+ assert (v.(0) == 10u);
+ assert (v.(1) == 10u);
+
+ // Test on-heap init_elt.
+ v = ivec::init_elt(20u, 6u);
+ assert (v.(0) == 20u);
+ assert (v.(1) == 20u);
+ assert (v.(2) == 20u);
+ assert (v.(3) == 20u);
+ assert (v.(4) == 20u);
+ assert (v.(5) == 20u);
+}
+
+#[test]
+fn test_is_empty() {
+ assert ivec::is_empty[int](~[]);
+ assert !ivec::is_empty(~[0]);
+}
+
+#[test]
+fn test_is_not_empty() {
+ assert ivec::is_not_empty(~[0]);
+ assert !ivec::is_not_empty[int](~[]);
+}
+
+#[test]
+fn test_head() {
+ auto a = ~[11, 12];
+ check ivec::is_not_empty(a);
+ assert ivec::head(a) == 11;
+}
+
+#[test]
+fn test_tail() {
+ auto a = ~[11];
+ check ivec::is_not_empty(a);
+ assert ivec::tail(a) == ~[];
+
+ a = ~[11, 12];
+ check ivec::is_not_empty(a);
+ assert ivec::tail(a) == ~[12];
+}
+
+#[test]
+fn test_last() {
+ auto n = ivec::last(~[]);
+ assert (n == none);
+ n = ivec::last(~[ 1, 2, 3 ]);
+ assert (n == some(3));
+ n = ivec::last(~[ 1, 2, 3, 4, 5 ]);
+ assert (n == some(5));
+}
+
+#[test]
+fn test_slice() {
+ // Test on-stack -> on-stack slice.
+ auto v = ivec::slice(~[ 1, 2, 3 ], 1u, 3u);
+ assert (ivec::len(v) == 2u);
+ assert (v.(0) == 2);
+ assert (v.(1) == 3);
+
+ // Test on-heap -> on-stack slice.
+ v = ivec::slice(~[ 1, 2, 3, 4, 5 ], 0u, 3u);
+ assert (ivec::len(v) == 3u);
+ assert (v.(0) == 1);
+ assert (v.(1) == 2);
+ assert (v.(2) == 3);
+
+ // Test on-heap -> on-heap slice.
+ v = ivec::slice(~[ 1, 2, 3, 4, 5, 6 ], 1u, 6u);
+ assert (ivec::len(v) == 5u);
+ assert (v.(0) == 2);
+ assert (v.(1) == 3);
+ assert (v.(2) == 4);
+ assert (v.(3) == 5);
+ assert (v.(4) == 6);
+}
+
+#[test]
+fn test_pop() {
+ // Test on-stack pop.
+ auto v = ~[ 1, 2, 3 ];
+ auto e = ivec::pop(v);
+ assert (ivec::len(v) == 2u);
+ assert (v.(0) == 1);
+ assert (v.(1) == 2);
+ assert (e == 3);
+
+ // Test on-heap pop.
+ v = ~[ 1, 2, 3, 4, 5 ];
+ e = ivec::pop(v);
+ assert (ivec::len(v) == 4u);
+ assert (v.(0) == 1);
+ assert (v.(1) == 2);
+ assert (v.(2) == 3);
+ assert (v.(3) == 4);
+ assert (e == 5);
+}
+
+#[test]
+fn test_grow() {
+ // Test on-stack grow().
+ auto v = ~[];
+ ivec::grow(v, 2u, 1);
+ assert (ivec::len(v) == 2u);
+ assert (v.(0) == 1);
+ assert (v.(1) == 1);
+
+ // Test on-heap grow().
+ ivec::grow(v, 3u, 2);
+ assert (ivec::len(v) == 5u);
+ assert (v.(0) == 1);
+ assert (v.(1) == 1);
+ assert (v.(2) == 2);
+ assert (v.(3) == 2);
+ assert (v.(4) == 2);
+}
+
+#[test]
+fn test_grow_fn() {
+ auto v = ~[];
+ ivec::grow_fn(v, 3u, square);
+ assert (ivec::len(v) == 3u);
+ assert (v.(0) == 0u);
+ assert (v.(1) == 1u);
+ assert (v.(2) == 4u);
+}
+
+#[test]
+fn test_grow_set() {
+ auto v = ~[ mutable 1, 2, 3 ];
+ ivec::grow_set(v, 4u, 4, 5);
+ assert (ivec::len(v) == 5u);
+ assert (v.(0) == 1);
+ assert (v.(1) == 2);
+ assert (v.(2) == 3);
+ assert (v.(3) == 4);
+ assert (v.(4) == 5);
+}
+
+#[test]
+fn test_map() {
+ // Test on-stack map.
+ auto v = ~[ 1u, 2u, 3u ];
+ auto w = ivec::map(square_alias, v);
+ assert (ivec::len(w) == 3u);
+ assert (w.(0) == 1u);
+ assert (w.(1) == 4u);
+ assert (w.(2) == 9u);
+
+ // Test on-heap map.
+ v = ~[ 1u, 2u, 3u, 4u, 5u ];
+ w = ivec::map(square_alias, v);
+ assert (ivec::len(w) == 5u);
+ assert (w.(0) == 1u);
+ assert (w.(1) == 4u);
+ assert (w.(2) == 9u);
+ assert (w.(3) == 16u);
+ assert (w.(4) == 25u);
+}
+
+#[test]
+fn test_filter_map() {
+ // Test on-stack filter-map.
+ auto v = ~[ 1u, 2u, 3u ];
+ auto w = ivec::filter_map(square_if_odd, v);
+ assert (ivec::len(w) == 2u);
+ assert (w.(0) == 1u);
+ assert (w.(1) == 9u);
+
+ // Test on-heap filter-map.
+ v = ~[ 1u, 2u, 3u, 4u, 5u ];
+ w = ivec::filter_map(square_if_odd, v);
+ assert (ivec::len(w) == 3u);
+ assert (w.(0) == 1u);
+ assert (w.(1) == 9u);
+ assert (w.(2) == 25u);
+}
+
+#[test]
+fn test_foldl() {
+ // Test on-stack fold.
+ auto v = ~[ 1u, 2u, 3u ];
+ auto sum = ivec::foldl(add, 0u, v);
+ assert (sum == 6u);
+
+ // Test on-heap fold.
+ v = ~[ 1u, 2u, 3u, 4u, 5u ];
+ sum = ivec::foldl(add, 0u, v);
+ assert (sum == 15u);
+}
+
+#[test]
+fn test_any_and_all() {
+ assert (ivec::any(is_three, ~[ 1u, 2u, 3u ]));
+ assert (!ivec::any(is_three, ~[ 0u, 1u, 2u ]));
+ assert (ivec::any(is_three, ~[ 1u, 2u, 3u, 4u, 5u ]));
+ assert (!ivec::any(is_three, ~[ 1u, 2u, 4u, 5u, 6u ]));
+
+ assert (ivec::all(is_three, ~[ 3u, 3u, 3u ]));
+ assert (!ivec::all(is_three, ~[ 3u, 3u, 2u ]));
+ assert (ivec::all(is_three, ~[ 3u, 3u, 3u, 3u, 3u ]));
+ assert (!ivec::all(is_three, ~[ 3u, 3u, 0u, 1u, 2u ]));
+}
+
+#[test]
+fn test_zip_unzip() {
+ auto v1 = ~[1, 2, 3];
+ auto v2 = ~[4, 5, 6];
+ auto z1 = ivec::zip(v1, v2);
+
+ assert tup(1, 4) == z1.(0);
+ assert tup(2, 5) == z1.(1);
+ assert tup(3, 6) == z1.(2);
+
+ auto u1 = ivec::unzip(z1);
+
+ assert tup(1, 4) == tup(u1._0.(0), u1._1.(0));
+ assert tup(2, 5) == tup(u1._0.(1), u1._1.(1));
+ assert tup(3, 6) == tup(u1._0.(2), u1._1.(2));
+}
+
+// Local Variables:
+// mode: rust;
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
+
--- /dev/null
+
+use std;
+import std::list;
+import std::list::car;
+import std::list::cdr;
+import std::list::from_vec;
+import std::option;
+
+#[test]
+fn test_from_vec() {
+ auto l = from_vec([0, 1, 2]);
+ assert (car(l) == 0);
+ assert (car(cdr(l)) == 1);
+ assert (car(cdr(cdr(l))) == 2);
+}
+
+#[test]
+fn test_foldl() {
+ auto l = from_vec([0, 1, 2, 3, 4]);
+ fn add(&int a, &uint b) -> uint { ret (a as uint) + b; }
+ auto rs = list::foldl(l, 0u, add);
+ assert (rs == 10u);
+}
+
+#[test]
+fn test_find_success() {
+ auto l = from_vec([0, 1, 2]);
+ fn match(&int i) -> option::t[int] {
+ ret if (i == 2) { option::some(i) } else { option::none[int] };
+ }
+ auto rs = list::find(l, match);
+ assert (rs == option::some(2));
+}
+
+#[test]
+fn test_find_fail() {
+ auto l = from_vec([0, 1, 2]);
+ fn match(&int i) -> option::t[int] { ret option::none[int]; }
+ auto rs = list::find(l, match);
+ assert (rs == option::none[int]);
+}
+
+#[test]
+fn test_has() {
+ auto l = from_vec([5, 8, 6]);
+ auto empty = list::nil[int];
+ assert (list::has(l, 5));
+ assert (!list::has(l, 7));
+ assert (list::has(l, 8));
+ assert (!list::has(empty, 5));
+}
+
+#[test]
+fn test_length() {
+ auto l = from_vec([0, 1, 2]);
+ assert (list::length(l) == 3u);
+}
+
--- /dev/null
+
+
+// -*- rust -*-
+use std;
+import std::map;
+import std::str;
+import std::uint;
+import std::util;
+
+#[test]
+fn test_simple() {
+ log "*** starting test_simple";
+ fn eq_uint(&uint x, &uint y) -> bool { ret x == y; }
+ fn hash_uint(&uint u) -> uint {
+ // FIXME: can't use std::util::id since we'd be capturing a type
+ // param, and presently we can't close items over type params.
+
+ ret u;
+ }
+ let map::hashfn[uint] hasher_uint = hash_uint;
+ let map::eqfn[uint] eqer_uint = eq_uint;
+ let map::hashfn[str] hasher_str = str::hash;
+ let map::eqfn[str] eqer_str = str::eq;
+ log "uint -> uint";
+ let map::hashmap[uint, uint] hm_uu =
+ map::mk_hashmap[uint, uint](hasher_uint, eqer_uint);
+ assert (hm_uu.insert(10u, 12u));
+ assert (hm_uu.insert(11u, 13u));
+ assert (hm_uu.insert(12u, 14u));
+ assert (hm_uu.get(11u) == 13u);
+ assert (hm_uu.get(12u) == 14u);
+ assert (hm_uu.get(10u) == 12u);
+ assert (!hm_uu.insert(12u, 14u));
+ assert (hm_uu.get(12u) == 14u);
+ assert (!hm_uu.insert(12u, 12u));
+ assert (hm_uu.get(12u) == 12u);
+ let str ten = "ten";
+ let str eleven = "eleven";
+ let str twelve = "twelve";
+ log "str -> uint";
+ let map::hashmap[str, uint] hm_su =
+ map::mk_hashmap[str, uint](hasher_str, eqer_str);
+ assert (hm_su.insert("ten", 12u));
+ assert (hm_su.insert(eleven, 13u));
+ assert (hm_su.insert("twelve", 14u));
+ assert (hm_su.get(eleven) == 13u);
+ assert (hm_su.get("eleven") == 13u);
+ assert (hm_su.get("twelve") == 14u);
+ assert (hm_su.get("ten") == 12u);
+ assert (!hm_su.insert("twelve", 14u));
+ assert (hm_su.get("twelve") == 14u);
+ assert (!hm_su.insert("twelve", 12u));
+ assert (hm_su.get("twelve") == 12u);
+ log "uint -> str";
+ let map::hashmap[uint, str] hm_us =
+ map::mk_hashmap[uint, str](hasher_uint, eqer_uint);
+ assert (hm_us.insert(10u, "twelve"));
+ assert (hm_us.insert(11u, "thirteen"));
+ assert (hm_us.insert(12u, "fourteen"));
+ assert (str::eq(hm_us.get(11u), "thirteen"));
+ assert (str::eq(hm_us.get(12u), "fourteen"));
+ assert (str::eq(hm_us.get(10u), "twelve"));
+ assert (!hm_us.insert(12u, "fourteen"));
+ assert (str::eq(hm_us.get(12u), "fourteen"));
+ assert (!hm_us.insert(12u, "twelve"));
+ assert (str::eq(hm_us.get(12u), "twelve"));
+ log "str -> str";
+ let map::hashmap[str, str] hm_ss =
+ map::mk_hashmap[str, str](hasher_str, eqer_str);
+ assert (hm_ss.insert(ten, "twelve"));
+ assert (hm_ss.insert(eleven, "thirteen"));
+ assert (hm_ss.insert(twelve, "fourteen"));
+ assert (str::eq(hm_ss.get("eleven"), "thirteen"));
+ assert (str::eq(hm_ss.get("twelve"), "fourteen"));
+ assert (str::eq(hm_ss.get("ten"), "twelve"));
+ assert (!hm_ss.insert("twelve", "fourteen"));
+ assert (str::eq(hm_ss.get("twelve"), "fourteen"));
+ assert (!hm_ss.insert("twelve", "twelve"));
+ assert (str::eq(hm_ss.get("twelve"), "twelve"));
+ log "*** finished test_simple";
+}
+
+
+/**
+ * Force map growth and rehashing.
+ */
+#[test]
+fn test_growth() {
+ log "*** starting test_growth";
+ let uint num_to_insert = 64u;
+ fn eq_uint(&uint x, &uint y) -> bool { ret x == y; }
+ fn hash_uint(&uint u) -> uint {
+ // FIXME: can't use std::util::id since we'd be capturing a type
+ // param, and presently we can't close items over type params.
+
+ ret u;
+ }
+ log "uint -> uint";
+ let map::hashfn[uint] hasher_uint = hash_uint;
+ let map::eqfn[uint] eqer_uint = eq_uint;
+ let map::hashmap[uint, uint] hm_uu =
+ map::mk_hashmap[uint, uint](hasher_uint, eqer_uint);
+ let uint i = 0u;
+ while (i < num_to_insert) {
+ assert (hm_uu.insert(i, i * i));
+ log "inserting " + uint::to_str(i, 10u) + " -> " +
+ uint::to_str(i * i, 10u);
+ i += 1u;
+ }
+ log "-----";
+ i = 0u;
+ while (i < num_to_insert) {
+ log "get(" + uint::to_str(i, 10u) + ") = " +
+ uint::to_str(hm_uu.get(i), 10u);
+ assert (hm_uu.get(i) == i * i);
+ i += 1u;
+ }
+ assert (hm_uu.insert(num_to_insert, 17u));
+ assert (hm_uu.get(num_to_insert) == 17u);
+ log "-----";
+ hm_uu.rehash();
+ i = 0u;
+ while (i < num_to_insert) {
+ log "get(" + uint::to_str(i, 10u) + ") = " +
+ uint::to_str(hm_uu.get(i), 10u);
+ assert (hm_uu.get(i) == i * i);
+ i += 1u;
+ }
+ log "str -> str";
+ let map::hashfn[str] hasher_str = str::hash;
+ let map::eqfn[str] eqer_str = str::eq;
+ let map::hashmap[str, str] hm_ss =
+ map::mk_hashmap[str, str](hasher_str, eqer_str);
+ i = 0u;
+ while (i < num_to_insert) {
+ assert (hm_ss.insert(uint::to_str(i, 2u), uint::to_str(i * i, 2u)));
+ log "inserting \"" + uint::to_str(i, 2u) + "\" -> \"" +
+ uint::to_str(i * i, 2u) + "\"";
+ i += 1u;
+ }
+ log "-----";
+ i = 0u;
+ while (i < num_to_insert) {
+ log "get(\"" + uint::to_str(i, 2u) + "\") = \"" +
+ hm_ss.get(uint::to_str(i, 2u)) + "\"";
+ assert (str::eq(hm_ss.get(uint::to_str(i, 2u)),
+ uint::to_str(i * i, 2u)));
+ i += 1u;
+ }
+ assert (hm_ss.insert(uint::to_str(num_to_insert, 2u),
+ uint::to_str(17u, 2u)));
+ assert (str::eq(hm_ss.get(uint::to_str(num_to_insert, 2u)),
+ uint::to_str(17u, 2u)));
+ log "-----";
+ hm_ss.rehash();
+ i = 0u;
+ while (i < num_to_insert) {
+ log "get(\"" + uint::to_str(i, 2u) + "\") = \"" +
+ hm_ss.get(uint::to_str(i, 2u)) + "\"";
+ assert (str::eq(hm_ss.get(uint::to_str(i, 2u)),
+ uint::to_str(i * i, 2u)));
+ i += 1u;
+ }
+ log "*** finished test_growth";
+}
+
+#[test]
+fn test_removal() {
+ log "*** starting test_removal";
+ let uint num_to_insert = 64u;
+ fn eq(&uint x, &uint y) -> bool { ret x == y; }
+ fn hash(&uint u) -> uint {
+ // This hash function intentionally causes collisions between
+ // consecutive integer pairs.
+
+ ret u / 2u * 2u;
+ }
+ assert (hash(0u) == hash(1u));
+ assert (hash(2u) == hash(3u));
+ assert (hash(0u) != hash(2u));
+ let map::hashfn[uint] hasher = hash;
+ let map::eqfn[uint] eqer = eq;
+ let map::hashmap[uint, uint] hm =
+ map::mk_hashmap[uint, uint](hasher, eqer);
+ let uint i = 0u;
+ while (i < num_to_insert) {
+ assert (hm.insert(i, i * i));
+ log "inserting " + uint::to_str(i, 10u) + " -> " +
+ uint::to_str(i * i, 10u);
+ i += 1u;
+ }
+ assert (hm.size() == num_to_insert);
+ log "-----";
+ log "removing evens";
+ i = 0u;
+ while (i < num_to_insert) {
+ /**
+ * FIXME (issue #150): we want to check the removed value as in the
+ * following:
+
+ let util.option[uint] v = hm.remove(i);
+ alt (v) {
+ case (util.some[uint](u)) {
+ assert (u == (i * i));
+ }
+ case (util.none[uint]()) { fail; }
+ }
+
+ * but we util.option is a tag type so util.some and util.none are
+ * off limits until we parse the dwarf for tag types.
+ */
+
+ hm.remove(i);
+ i += 2u;
+ }
+ assert (hm.size() == num_to_insert / 2u);
+ log "-----";
+ i = 1u;
+ while (i < num_to_insert) {
+ log "get(" + uint::to_str(i, 10u) + ") = " +
+ uint::to_str(hm.get(i), 10u);
+ assert (hm.get(i) == i * i);
+ i += 2u;
+ }
+ log "-----";
+ log "rehashing";
+ hm.rehash();
+ log "-----";
+ i = 1u;
+ while (i < num_to_insert) {
+ log "get(" + uint::to_str(i, 10u) + ") = " +
+ uint::to_str(hm.get(i), 10u);
+ assert (hm.get(i) == i * i);
+ i += 2u;
+ }
+ log "-----";
+ i = 0u;
+ while (i < num_to_insert) {
+ assert (hm.insert(i, i * i));
+ log "inserting " + uint::to_str(i, 10u) + " -> " +
+ uint::to_str(i * i, 10u);
+ i += 2u;
+ }
+ assert (hm.size() == num_to_insert);
+ log "-----";
+ i = 0u;
+ while (i < num_to_insert) {
+ log "get(" + uint::to_str(i, 10u) + ") = " +
+ uint::to_str(hm.get(i), 10u);
+ assert (hm.get(i) == i * i);
+ i += 1u;
+ }
+ log "-----";
+ log "rehashing";
+ hm.rehash();
+ log "-----";
+ assert (hm.size() == num_to_insert);
+ i = 0u;
+ while (i < num_to_insert) {
+ log "get(" + uint::to_str(i, 10u) + ") = " +
+ uint::to_str(hm.get(i), 10u);
+ assert (hm.get(i) == i * i);
+ i += 1u;
+ }
+ log "*** finished test_removal";
+}
+
+#[test]
+fn test_contains_key() {
+ auto key = "k";
+ auto map = map::mk_hashmap[str, str](str::hash, str::eq);
+ assert (!map.contains_key(key));
+ map.insert(key, "val");
+ assert (map.contains_key(key));
+}
+
+#[test]
+fn test_find() {
+ auto key = "k";
+ auto map = map::mk_hashmap[str, str](str::hash, str::eq);
+ assert (std::option::is_none(map.find(key)));
+ map.insert(key, "val");
+ assert (std::option::get(map.find(key)) == "val");
+}
--- /dev/null
+
+use std;
+
+#[test]
+fn test() { auto x = std::option::some[int](10); }
\ No newline at end of file
--- /dev/null
+import std::generic_os::setenv;
+import std::generic_os::getenv;
+import std::option;
+
+#[test]
+fn test_setenv() {
+ setenv("NAME", "VALUE");
+ assert getenv("NAME") == option::some("VALUE");
+}
+
+#[test]
+fn test_setenv_overwrite() {
+ setenv("NAME", "1");
+ setenv("NAME", "2");
+ assert getenv("NAME") == option::some("2");
+}
+
+// Windows GetEnvironmentVariable requires some extra work to make sure
+// the buffer the variable is copied into is the right size
+#[test]
+fn test_getenv_big() {
+ auto s = "";
+ auto i = 0;
+ while (i < 100) {
+ s += "aaaaaaaaaa";
+ i += 1;
+ }
+ setenv("NAME", s);
+ assert getenv("NAME") == option::some(s);
+}
+
+// Local Variables:
+// mode: rust;
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+
+// Testing a few of the path manipuation functions
+
+use std;
+
+import std::fs;
+import std::os;
+
+#[test]
+fn test() {
+ assert(!fs::path_is_absolute("test-path"));
+
+ log "Current working directory: " + os::getcwd();
+
+ log fs::make_absolute("test-path");
+ log fs::make_absolute("/usr/bin");
+}
\ No newline at end of file
--- /dev/null
+use std;
+import std::ptr;
+import std::unsafe;
+
+type pair = rec(mutable int fst, mutable int snd);
+
+#[test]
+fn test() {
+ auto p = rec(mutable fst=10, mutable snd=20);
+ let *mutable pair pptr = ptr::addr_of(p);
+ let *mutable int iptr = unsafe::reinterpret_cast(pptr);
+ assert (*iptr == 10);
+ *iptr = 30;
+ assert (*iptr == 30);
+ assert (p.fst == 30);
+
+ *pptr = rec(mutable fst=50, mutable snd=60);
+ assert (*iptr == 50);
+ assert (p.fst == 50);
+ assert (p.snd == 60);
+}
+
--- /dev/null
+
+use std;
+
+import std::sort;
+import std::ivec;
+import std::int;
+
+fn check_sort(vec[mutable int] v1, vec[mutable int] v2) {
+ auto len = std::vec::len[int](v1);
+ fn ltequal(&int a, &int b) -> bool { ret a <= b; }
+ auto f = ltequal;
+ std::sort::quick_sort[int](f, v1);
+ auto i = 0u;
+ while (i < len) { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; }
+}
+
+#[test]
+fn test() {
+ {
+ auto v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8];
+ auto v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9];
+ check_sort(v1, v2);
+ }
+ {
+ auto v1 = [mutable 1, 1, 1];
+ auto v2 = [mutable 1, 1, 1];
+ check_sort(v1, v2);
+ }
+ {
+ let vec[mutable int] v1 = [mutable ];
+ let vec[mutable int] v2 = [mutable ];
+ check_sort(v1, v2);
+ }
+ { auto v1 = [mutable 9]; auto v2 = [mutable 9]; check_sort(v1, v2); }
+ {
+ auto v1 = [mutable 9, 3, 3, 3, 9];
+ auto v2 = [mutable 3, 3, 3, 9, 9];
+ check_sort(v1, v2);
+ }
+}
+
+// Regression test for #705
+#[test]
+fn test_simple() {
+ auto names = ~[mutable 2, 1, 3];
+
+ auto expected = ~[1, 2, 3];
+
+ fn lteq(&int a, &int b) -> bool { int::le(a, b) }
+ sort::ivector::quick_sort(lteq, names);
+
+ auto pairs = ivec::zip(expected, ivec::from_mut(names));
+ for (tup(int, int) p in pairs) {
+ log #fmt("%d %d", p._0, p._1);
+ assert p._0 == p._1;
+ }
+}
+
+// Local Variables:
+// mode: rust;
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+
+use std;
+
+fn check_sort(vec[mutable int] v1, vec[mutable int] v2) {
+ auto len = std::vec::len[int](v1);
+ fn lt(&int a, &int b) -> bool { ret a < b; }
+ fn equal(&int a, &int b) -> bool { ret a == b; }
+ auto f1 = lt;
+ auto f2 = equal;
+ std::sort::quick_sort3[int](f1, f2, v1);
+ auto i = 0u;
+ while (i < len) { log v2.(i); assert (v2.(i) == v1.(i)); i += 1u; }
+}
+
+#[test]
+fn test() {
+ {
+ auto v1 = [mutable 3, 7, 4, 5, 2, 9, 5, 8];
+ auto v2 = [mutable 2, 3, 4, 5, 5, 7, 8, 9];
+ check_sort(v1, v2);
+ }
+ {
+ auto v1 = [mutable 1, 1, 1];
+ auto v2 = [mutable 1, 1, 1];
+ check_sort(v1, v2);
+ }
+ {
+ let vec[mutable int] v1 = [mutable ];
+ let vec[mutable int] v2 = [mutable ];
+ check_sort(v1, v2);
+ }
+ { auto v1 = [mutable 9]; auto v2 = [mutable 9]; check_sort(v1, v2); }
+ {
+ auto v1 = [mutable 9, 3, 3, 3, 9];
+ auto v2 = [mutable 3, 3, 3, 9, 9];
+ check_sort(v1, v2);
+ }
+}
+// Local Variables:
+// mode: rust;
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+
+
+// -*- rust -*-
+use std;
+import std::rand;
+
+#[test]
+fn test() {
+ let rand::rng r1 = rand::mk_rng();
+ log r1.next();
+ log r1.next();
+ {
+ auto r2 = rand::mk_rng();
+ log r1.next();
+ log r2.next();
+ log r1.next();
+ log r1.next();
+ log r2.next();
+ log r2.next();
+ log r1.next();
+ log r1.next();
+ log r1.next();
+ log r2.next();
+ log r2.next();
+ log r2.next();
+ }
+ log r1.next();
+ log r1.next();
+}
\ No newline at end of file
--- /dev/null
+use std;
+import std::run;
+
+// Regression test for memory leaks
+#[cfg(target_os = "linux")]
+#[cfg(target_os = "macos")]
+#[test]
+fn test_leaks() {
+ run::run_program("echo", []);
+ run::start_program("echo", []);
+ run::program_output("echo", []);
+}
+
+// FIXME
+#[cfg(target_os = "win32")]
+#[test]
+#[ignore]
+fn test_leaks() {}
+
+
+// -*- rust -*-
+
+use std;
import std::sha1;
import std::vec;
import std::str;
--- /dev/null
+
+use std;
+
+fn check_sort(vec[int] v1, vec[int] v2) {
+ auto len = std::vec::len[int](v1);
+ fn lteq(&int a, &int b) -> bool { ret a <= b; }
+ auto f = lteq;
+ auto v3 = std::sort::merge_sort[int](f, v1);
+ auto i = 0u;
+ while (i < len) { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; }
+}
+
+#[test]
+fn test() {
+ {
+ auto v1 = [3, 7, 4, 5, 2, 9, 5, 8];
+ auto v2 = [2, 3, 4, 5, 5, 7, 8, 9];
+ check_sort(v1, v2);
+ }
+ { auto v1 = [1, 1, 1]; auto v2 = [1, 1, 1]; check_sort(v1, v2); }
+ { let vec[int] v1 = []; let vec[int] v2 = []; check_sort(v1, v2); }
+ { auto v1 = [9]; auto v2 = [9]; check_sort(v1, v2); }
+ {
+ auto v1 = [9, 3, 3, 3, 9];
+ auto v2 = [3, 3, 3, 9, 9];
+ check_sort(v1, v2);
+ }
+}
\ No newline at end of file
--- /dev/null
+
+use std;
+
+fn check_sort(&int[] v1, &int[] v2) {
+ auto len = std::ivec::len[int](v1);
+ fn lteq(&int a, &int b) -> bool { ret a <= b; }
+ auto f = lteq;
+ auto v3 = std::sort::ivector::merge_sort[int](f, v1);
+ auto i = 0u;
+ while (i < len) { log v3.(i); assert (v3.(i) == v2.(i)); i += 1u; }
+}
+
+#[test]
+fn test() {
+ {
+ auto v1 = ~[3, 7, 4, 5, 2, 9, 5, 8];
+ auto v2 = ~[2, 3, 4, 5, 5, 7, 8, 9];
+ check_sort(v1, v2);
+ }
+ { auto v1 = ~[1, 1, 1]; auto v2 = ~[1, 1, 1]; check_sort(v1, v2); }
+ { let int[] v1 = ~[]; let int[] v2 = ~[]; check_sort(v1, v2); }
+ { auto v1 = ~[9]; auto v2 = ~[9]; check_sort(v1, v2); }
+ {
+ auto v1 = ~[9, 3, 3, 3, 9];
+ auto v2 = ~[3, 3, 3, 9, 9];
+ check_sort(v1, v2);
+ }
+}
use std;
-mod sha1;
+mod bitv;
+mod box;
+mod deque;
+mod either;
+mod fs;
+mod getopts;
mod int;
+mod io;
+mod ivec;
+mod list;
+mod map;
+mod option;
+mod os;
+mod path;
+mod ptr;
+mod qsort3;
+mod qsort;
+mod rand;
+mod run;
+mod sha1;
+mod sort_ivec;
+mod sort;
+mod str_buf;
+mod str;
+mod task;
mod test;
+mod uint;
+mod vec;
+mod vec_str_conversions;
+
// Local Variables:
// mode: rust
// fill-column: 78;
--- /dev/null
+use std;
+import std::str;
+
+#[test]
+fn test_bytes_len() {
+ assert (str::byte_len("") == 0u);
+ assert (str::byte_len("hello world") == 11u);
+ assert (str::byte_len("\x63") == 1u);
+ assert (str::byte_len("\xa2") == 2u);
+ assert (str::byte_len("\u03c0") == 2u);
+ assert (str::byte_len("\u2620") == 3u);
+ assert (str::byte_len("\U0001d11e") == 4u);
+}
+
+#[test]
+fn test_index_and_rindex() {
+ assert (str::index("hello", 'e' as u8) == 1);
+ assert (str::index("hello", 'o' as u8) == 4);
+ assert (str::index("hello", 'z' as u8) == -1);
+ assert (str::rindex("hello", 'l' as u8) == 3);
+ assert (str::rindex("hello", 'h' as u8) == 0);
+ assert (str::rindex("hello", 'z' as u8) == -1);
+}
+
+#[test]
+fn test_split() {
+ fn t(&str s, char c, int i, &str k) {
+ log "splitting: " + s;
+ log i;
+ auto v = str::split(s, c as u8);
+ log "split to: ";
+ for (str z in v) { log z; }
+ log "comparing: " + v.(i) + " vs. " + k;
+ assert (str::eq(v.(i), k));
+ }
+ t("abc.hello.there", '.', 0, "abc");
+ t("abc.hello.there", '.', 1, "hello");
+ t("abc.hello.there", '.', 2, "there");
+ t(".hello.there", '.', 0, "");
+ t(".hello.there", '.', 1, "hello");
+ t("...hello.there.", '.', 3, "hello");
+ t("...hello.there.", '.', 5, "");
+}
+
+#[test]
+fn test_find() {
+ fn t(&str haystack, &str needle, int i) {
+ let int j = str::find(haystack, needle);
+ log "searched for " + needle;
+ log j;
+ assert (i == j);
+ }
+ t("this is a simple", "is a", 5);
+ t("this is a simple", "is z", -1);
+ t("this is a simple", "", 0);
+ t("this is a simple", "simple", 10);
+ t("this", "simple", -1);
+}
+
+#[test]
+fn test_substr() {
+ fn t(&str a, &str b, int start) {
+ assert (str::eq(str::substr(a, start as uint, str::byte_len(b)), b));
+ }
+ t("hello", "llo", 2);
+ t("hello", "el", 1);
+ t("substr should not be a challenge", "not", 14);
+}
+
+#[test]
+fn test_concat() {
+ fn t(&vec[str] v, &str s) { assert (str::eq(str::concat(v), s)); }
+ t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood");
+ let vec[str] v = [];
+ t(v, "");
+ t(["hi"], "hi");
+}
+
+#[test]
+fn test_connect() {
+ fn t(&vec[str] v, &str sep, &str s) {
+ assert (str::eq(str::connect(v, sep), s));
+ }
+ t(["you", "know", "I'm", "no", "good"], " ", "you know I'm no good");
+ let vec[str] v = [];
+ t(v, " ", "");
+ t(["hi"], " ", "hi");
+}
+
+#[test]
+fn test_to_upper() {
+ // to_upper doesn't understand unicode yet,
+ // but we need to at least preserve it
+
+ auto unicode = "\u65e5\u672c";
+ auto input = "abcDEF" + unicode + "xyz:.;";
+ auto expected = "ABCDEF" + unicode + "XYZ:.;";
+ auto actual = str::to_upper(input);
+ assert (str::eq(expected, actual));
+}
+
+#[test]
+fn test_slice() {
+ assert (str::eq("ab", str::slice("abc", 0u, 2u)));
+ assert (str::eq("bc", str::slice("abc", 1u, 3u)));
+ assert (str::eq("", str::slice("abc", 1u, 1u)));
+ fn a_million_letter_a() -> str {
+ auto i = 0;
+ auto rs = "";
+ while (i < 100000) { rs += "aaaaaaaaaa"; i += 1; }
+ ret rs;
+ }
+ fn half_a_million_letter_a() -> str {
+ auto i = 0;
+ auto rs = "";
+ while (i < 100000) { rs += "aaaaa"; i += 1; }
+ ret rs;
+ }
+ assert (str::eq(half_a_million_letter_a(),
+ str::slice(a_million_letter_a(), 0u, 500000u)));
+}
+
+#[test]
+fn test_ends_with() {
+ assert (str::ends_with("", ""));
+ assert (str::ends_with("abc", ""));
+ assert (str::ends_with("abc", "c"));
+ assert (!str::ends_with("a", "abc"));
+ assert (!str::ends_with("", "abc"));
+}
+
+#[test]
+fn test_is_empty() {
+ assert str::is_empty("");
+ assert !str::is_empty("a");
+}
+
+#[test]
+fn test_is_not_empty() {
+ assert str::is_not_empty("a");
+ assert !str::is_not_empty("");
+}
+
+#[test]
+fn test_replace() {
+ auto a = "a";
+ check str::is_not_empty(a);
+ assert str::replace("", a, "b") == "";
+ assert str::replace("a", a, "b") == "b";
+ assert str::replace("ab", a, "b") == "bb";
+ auto test = "test";
+ check str::is_not_empty(test);
+ assert str::replace(" test test ", test, "toast")
+ == " toast toast ";
+ assert str::replace(" test test ", test, "") == " ";
+}
+
+
+// Local Variables:
+// mode: rust;
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
--- /dev/null
+
+
+// -*- rust -*-
+use std;
+import std::str;
+
+#[test]
+fn test() {
+ auto s = "hello";
+ auto sb = str::buf(s);
+ auto s_cstr = str::str_from_cstr(sb);
+ assert (str::eq(s_cstr, s));
+ auto s_buf = str::str_from_buf(sb, 5u);
+ assert (str::eq(s_buf, s));
+}
\ No newline at end of file
--- /dev/null
+use std;
+import std::task;
+
+#[test]
+#[ignore]
+fn test_sleep() { task::sleep(1000000u); }
+
+#[test]
+fn test_unsupervise() {
+ fn f() {
+ task::unsupervise();
+ fail;
+ }
+ spawn f();
+}
+
+#[test]
+fn test_join() {
+ fn winner() {
+ }
+
+ auto wintask = spawn winner();
+
+ assert task::join(wintask) == task::tr_success;
+
+ fn failer() {
+ task::unsupervise();
+ fail;
+ }
+
+ auto failtask = spawn failer();
+
+ assert task::join(failtask) == task::tr_failure;
+}
--- /dev/null
+
+
+// -*- rust -*-
+use std;
+import std::uint;
+
+#[test]
+fn test_next_power_of_two() {
+ assert (uint::next_power_of_two(0u) == 0u);
+ assert (uint::next_power_of_two(1u) == 1u);
+ assert (uint::next_power_of_two(2u) == 2u);
+ assert (uint::next_power_of_two(3u) == 4u);
+ assert (uint::next_power_of_two(4u) == 4u);
+ assert (uint::next_power_of_two(5u) == 8u);
+ assert (uint::next_power_of_two(6u) == 8u);
+ assert (uint::next_power_of_two(7u) == 8u);
+ assert (uint::next_power_of_two(8u) == 8u);
+ assert (uint::next_power_of_two(9u) == 16u);
+ assert (uint::next_power_of_two(10u) == 16u);
+ assert (uint::next_power_of_two(11u) == 16u);
+ assert (uint::next_power_of_two(12u) == 16u);
+ assert (uint::next_power_of_two(13u) == 16u);
+ assert (uint::next_power_of_two(14u) == 16u);
+ assert (uint::next_power_of_two(15u) == 16u);
+ assert (uint::next_power_of_two(16u) == 16u);
+ assert (uint::next_power_of_two(17u) == 32u);
+ assert (uint::next_power_of_two(18u) == 32u);
+ assert (uint::next_power_of_two(19u) == 32u);
+ assert (uint::next_power_of_two(20u) == 32u);
+ assert (uint::next_power_of_two(21u) == 32u);
+ assert (uint::next_power_of_two(22u) == 32u);
+ assert (uint::next_power_of_two(23u) == 32u);
+ assert (uint::next_power_of_two(24u) == 32u);
+ assert (uint::next_power_of_two(25u) == 32u);
+ assert (uint::next_power_of_two(26u) == 32u);
+ assert (uint::next_power_of_two(27u) == 32u);
+ assert (uint::next_power_of_two(28u) == 32u);
+ assert (uint::next_power_of_two(29u) == 32u);
+ assert (uint::next_power_of_two(30u) == 32u);
+ assert (uint::next_power_of_two(31u) == 32u);
+ assert (uint::next_power_of_two(32u) == 32u);
+ assert (uint::next_power_of_two(33u) == 64u);
+ assert (uint::next_power_of_two(34u) == 64u);
+ assert (uint::next_power_of_two(35u) == 64u);
+ assert (uint::next_power_of_two(36u) == 64u);
+ assert (uint::next_power_of_two(37u) == 64u);
+ assert (uint::next_power_of_two(38u) == 64u);
+ assert (uint::next_power_of_two(39u) == 64u);
+}
\ No newline at end of file
--- /dev/null
+
+use std;
+
+import std::vec::*;
+import std::option;
+
+#[test]
+fn test_init_elt() {
+ let vec[uint] v = init_elt[uint](5u, 3u);
+ assert (len[uint](v) == 3u);
+ assert (v.(0) == 5u);
+ assert (v.(1) == 5u);
+ assert (v.(2) == 5u);
+}
+
+fn id(uint x) -> uint { ret x; }
+
+#[test]
+fn test_init_fn() {
+ let fn(uint) -> uint op = id;
+ let vec[uint] v = init_fn[uint](op, 5u);
+ assert (len[uint](v) == 5u);
+ assert (v.(0) == 0u);
+ assert (v.(1) == 1u);
+ assert (v.(2) == 2u);
+ assert (v.(3) == 3u);
+ assert (v.(4) == 4u);
+}
+
+#[test]
+fn test_slice() {
+ let vec[int] v = [1, 2, 3, 4, 5];
+ auto v2 = slice[int](v, 2u, 4u);
+ assert (len[int](v2) == 2u);
+ assert (v2.(0) == 3);
+ assert (v2.(1) == 4);
+}
+
+#[test]
+fn test_map() {
+ fn square(&int x) -> int { ret x * x; }
+ let option::operator[int, int] op = square;
+ let vec[int] v = [1, 2, 3, 4, 5];
+ let vec[int] s = map[int, int](op, v);
+ let int i = 0;
+ while (i < 5) { assert (v.(i) * v.(i) == s.(i)); i += 1; }
+}
+
+#[test]
+fn test_map2() {
+ fn times(&int x, &int y) -> int { ret x * y; }
+ auto f = times;
+ auto v0 = [1, 2, 3, 4, 5];
+ auto v1 = [5, 4, 3, 2, 1];
+ auto u = map2[int, int, int](f, v0, v1);
+ auto i = 0;
+ while (i < 5) { assert (v0.(i) * v1.(i) == u.(i)); i += 1; }
+}
+
+#[test]
+fn test_filter_map() {
+ fn halve(&int i) -> option::t[int] {
+ if (i % 2 == 0) {
+ ret option::some[int](i / 2);
+ } else { ret option::none[int]; }
+ }
+ fn halve_for_sure(&int i) -> int { ret i / 2; }
+ let vec[int] all_even = [0, 2, 8, 6];
+ let vec[int] all_odd1 = [1, 7, 3];
+ let vec[int] all_odd2 = [];
+ let vec[int] mix = [9, 2, 6, 7, 1, 0, 0, 3];
+ let vec[int] mix_dest = [1, 3, 0, 0];
+ assert (filter_map(halve, all_even) ==
+ map(halve_for_sure, all_even));
+ assert (filter_map(halve, all_odd1) == empty[int]());
+ assert (filter_map(halve, all_odd2) == empty[int]());
+ assert (filter_map(halve, mix) == mix_dest);
+}
+
+#[test]
+fn test_position() {
+ let vec[int] v1 = [1, 2, 3, 3, 2, 5];
+ assert (position(1, v1) == option::some[uint](0u));
+ assert (position(2, v1) == option::some[uint](1u));
+ assert (position(5, v1) == option::some[uint](5u));
+ assert (position(4, v1) == option::none[uint]);
+}
+
+#[test]
+fn test_position_pred() {
+ fn less_than_three(&int i) -> bool {
+ ret i <3;
+ }
+ fn is_eighteen(&int i) -> bool {
+ ret i == 18;
+ }
+ let vec[int] v1 = [5, 4, 3, 2, 1];
+ assert (position_pred(less_than_three, v1) == option::some[uint](3u));
+ assert (position_pred(is_eighteen, v1) == option::none[uint]);
+}
--- /dev/null
+
+
+// -*- rust -*-
+use std;
+import std::str;
+import std::vec;
+
+#[test]
+fn test_simple() {
+ let str s1 = "All mimsy were the borogoves";
+ /*
+ * FIXME from_bytes(vec[u8] v) has constraint is_utf(v), which is
+ * unimplemented and thereby just fails. This doesn't stop us from
+ * using from_bytes for now since the constraint system isn't fully
+ * working, but we should implement is_utf8 before that happens.
+ */
+
+ let vec[u8] v = str::bytes(s1);
+ let str s2 = str::from_bytes(v);
+ let uint i = 0u;
+ let uint n1 = str::byte_len(s1);
+ let uint n2 = vec::len[u8](v);
+ assert (n1 == n2);
+ while (i < n1) {
+ let u8 a = s1.(i);
+ let u8 b = s2.(i);
+ log a;
+ log b;
+ assert (a == b);
+ i += 1u;
+ }
+ log "refcnt is";
+ log str::refcount(s1);
+}