From 1ed646eaf7d09455a086afa11bcd83a7d2a6b0f4 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 28 Jun 2014 13:57:36 -0700 Subject: Extract tests from libcore to a separate crate Libcore's test infrastructure is complicated by the fact that many lang items are defined in the crate. The current approach (realcore/realstd imports) is hacky and hard to work with (tests inside of core::cmp haven't been run for months!). Moving tests to a separate crate does mean that they can only test the public API of libcore, but I don't feel that that is too much of an issue. The only tests that I had to get rid of were some checking the various numeric formatters, but those are also exercised through normal format! calls in other tests. --- src/libcoretest/raw.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/libcoretest/raw.rs (limited to 'src/libcoretest/raw.rs') diff --git a/src/libcoretest/raw.rs b/src/libcoretest/raw.rs new file mode 100644 index 00000000000..f2c23c7c773 --- /dev/null +++ b/src/libcoretest/raw.rs @@ -0,0 +1,35 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use core::raw::*; +use core::mem; + +#[test] +fn synthesize_closure() { + unsafe { + let x = 10; + let f: |int| -> int = |y| x + y; + + assert_eq!(f(20), 30); + + let original_closure: Closure = mem::transmute(f); + + let actual_function_pointer = original_closure.code; + let environment = original_closure.env; + + let new_closure = Closure { + code: actual_function_pointer, + env: environment + }; + + let new_f: |int| -> int = mem::transmute(new_closure); + assert_eq!(new_f(20), 30); + } +} -- cgit 1.4.1-3-g733a5