Skip to content

Commit cc0c6fd

Browse files
committed
Add assertions and cross crate tests
1 parent a106613 commit cc0c6fd

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn f(x: int) -> int { -x }
12+
13+
pub static F: extern fn(int) -> int = f;
14+
pub static mut MutF: extern fn(int) -> int = f;

src/test/run-pass/static-function-pointer.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// aux-build:static-function-pointer-aux.rs
12+
extern mod aux(name = "static-function-pointer-aux");
13+
1114
fn f(x: int) -> int { x }
15+
fn g(x: int) -> int { 2 * x }
1216

1317
static F: extern fn(int) -> int = f;
1418
static mut G: extern fn(int) -> int = f;
1519

1620
fn main() {
17-
F(42);
18-
unsafe { G(7); }
21+
assert_eq!(F(42), 42);
22+
unsafe {
23+
assert_eq!(G(42), 42);
24+
G = g;
25+
assert_eq!(G(42), 84);
26+
}
27+
assert_eq!(aux::F(42), -42);
28+
unsafe {
29+
assert_eq!(aux::MutF(42), -42);
30+
aux::MutF = f;
31+
assert_eq!(aux::MutF(42), 42);
32+
}
1933
}

0 commit comments

Comments
 (0)