diff options
Diffstat (limited to 'test')
39 files changed, 608 insertions, 0 deletions
diff --git a/test/TARGETS b/test/TARGETS new file mode 100644 index 0000000..5115bdf --- /dev/null +++ b/test/TARGETS @@ -0,0 +1,98 @@ +{ "static": + { "type": ["@", "test-rules", "test_rules", "test_case"] + , "name": ["static"] + , "targets": + [ "+baz-lib" + , "+bar-lib" + , "-bar-missing-baz" + , "+foo-lib" + , "+main" + , "-main-wrong-dep" + , "-main-missing-dep" + ] + , "asserts": + [ "test -f baz-lib/baz/libbaz.rlib" + , "! test -f baz-lib/baz/libbaz.rmeta" + , "test -f bar-lib/bar/libbar.rlib" + , "test -f main/bin/main" + , "./main/bin/main | grep baz" + , "./main/bin/main | grep bar" + , "./main/bin/main | grep foo" + ] + , "data": [["TREE", null, "static"]] + } +, "static-native": + { "type": ["@", "test-rules", "test_rules", "test_case"] + , "name": ["static-native"] + , "targets": + [ "+baz-lib" + , "+bar-lib" + , "-bar-missing-baz" + , "+foo-lib" + , "+main" + , "-main-wrong-dep" + , "-main-missing-dep" + ] + , "asserts": + [ "test -f baz-lib/baz/libbaz.a" + , "! test -f baz-lib/baz/libbaz.rmeta" + , "! test -f baz-lib/baz/libbaz.rlib" + , "test -f bar-lib/bar/libbar.rlib" + , "test -f foo-lib/foo/libfoo.a" + , "test -f main/bin/main" + , "./main/bin/main | grep baz" + , "./main/bin/main | grep bar" + , "./main/bin/main | grep foo" + ] + , "data": [["TREE", null, "static-native"]] + } +, "dynamic": + { "type": ["@", "test-rules", "test_rules", "test_case"] + , "name": ["dynamic"] + , "targets": + [ "+baz-lib" + , "+bar-lib" + , "-bar-missing-baz" + , "+foo-lib" + , "+main" + , "-main-wrong-dep" + , "-main-missing-dep" + ] + , "asserts": + [ "test -f baz-lib/baz/libbaz.rlib" + , "! test -f baz-lib/baz/libbaz.rmeta" + , "test -f bar-lib/bar/libbar.rlib" + , "test -f main/bin/main" + , "./main/bin/main | grep baz" + , "./main/bin/main | grep bar" + , "./main/bin/main | grep foo" + ] + , "data": [["TREE", null, "dynamic"]] + } +, "build-script": + { "type": ["@", "test-rules", "test_rules", "test_case"] + , "name": ["build-script"] + , "targets": ["+build_script", "+main"] + , "asserts": + [ "test -f build_script/bar/build_script" + , "test -f build_script/bar/file_args" + , "test -f build_script/bar/out" + , "! ./main/bin/main | grep bar" + , "./main/bin/main | grep \"build script\"" + , "./main/bin/main | grep foo" + ] + , "data": [["TREE", null, "build-script"]] + } +, "ALL": + { "type": "install" + , "deps": + [ "static" + , "static-native" + , "dynamic" + , "build-script" + , ["./", "c-from-rust", "c-from-rust"] + ] + , "dirs": [[["./", "rust-from-c", "TESTS"], "rust-from-c"]] + , "tainted": ["test"] + } +} diff --git a/test/build-script/TARGETS b/test/build-script/TARGETS new file mode 100644 index 0000000..b896499 --- /dev/null +++ b/test/build-script/TARGETS @@ -0,0 +1,61 @@ +{ "baz-lib": + { "type": ["@", "rules", "rust", "library"] + , "name": ["baz"] + , "stage": ["baz"] + , "crate_root": ["baz.rs"] + , "edition": ["2021"] + , "version": ["1", "2", "3", "rc-1"] + } +, "build_script": + { "type": ["@", "rules", "cargo", "build_script"] + , "name": ["build_script"] + , "crate_root": ["build.rs"] + , "edition": ["2018"] + , "stage": ["bar"] + , "deps": ["baz-lib"] + } +, "bar-lib": + { "type": ["@", "rules", "rust", "library"] + , "name": ["bar"] + , "stage": ["bar"] + , "build_script": ["build_script"] + , "deps": ["baz-lib"] + , "crate_root": ["bar.rs"] + , "edition": ["2021"] + } +, "bar-missing-baz": + { "type": ["@", "rules", "rust", "library"] + , "name": ["bar"] + , "stage": ["bar"] + , "crate_root": ["bar.rs"] + , "edition": ["2021"] + } +, "foo-lib": + { "type": ["@", "rules", "rust", "library"] + , "name": ["foo"] + , "stage": ["foo"] + , "crate_root": ["foo.rs"] + , "edition": ["2021"] + , "deps": ["bar-lib"] + } +, "main": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + , "deps": ["foo-lib"] + } +, "main-wrong-dep": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + , "deps": ["bar-lib"] + } +, "main-missing-dep": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + } +} diff --git a/test/build-script/bar.rs b/test/build-script/bar.rs new file mode 100644 index 0000000..30de275 --- /dev/null +++ b/test/build-script/bar.rs @@ -0,0 +1,15 @@ + +#[cfg(not(bar))] +pub fn hello(){ + println!("hello bar"); +} + +#[cfg(bar)] +pub fn hello(){ + println!("hello build script"); +} + +pub fn add(a: i32, b: i32) -> i32 { + a + b +} + diff --git a/test/build-script/baz.rs b/test/build-script/baz.rs new file mode 100644 index 0000000..4222589 --- /dev/null +++ b/test/build-script/baz.rs @@ -0,0 +1,5 @@ + +pub fn hello(){ + +println!("hello baz"); + }
\ No newline at end of file diff --git a/test/build-script/build.rs b/test/build-script/build.rs new file mode 100644 index 0000000..35a358c --- /dev/null +++ b/test/build-script/build.rs @@ -0,0 +1,7 @@ + + +fn main() { + +println!("cargo:rustc-cfg=bar"); + +} diff --git a/test/build-script/foo.rs b/test/build-script/foo.rs new file mode 100644 index 0000000..c2dca08 --- /dev/null +++ b/test/build-script/foo.rs @@ -0,0 +1,6 @@ +extern crate bar; +pub fn hello(){ + +bar::hello(); + println!("hello foo"); + }
\ No newline at end of file diff --git a/test/build-script/main.rs b/test/build-script/main.rs new file mode 100644 index 0000000..6da0e2e --- /dev/null +++ b/test/build-script/main.rs @@ -0,0 +1,6 @@ +extern crate foo; + +fn main() { + +foo::hello(); +} diff --git a/test/c-from-rust/TARGETS b/test/c-from-rust/TARGETS new file mode 100644 index 0000000..7da2055 --- /dev/null +++ b/test/c-from-rust/TARGETS @@ -0,0 +1,13 @@ +{ "main": + { "type": ["rules/rust", "binary"] + , "name": ["main"] + , "crate_root": ["main.rs"] + , "deps": [["./", "clib", "foo"]] + } +, "c-from-rust": + { "type": ["@", "rules-cc", "shell/test", "script"] + , "name": ["c-from-rust"] + , "test": ["check_ints.sh"] + , "deps": ["main"] + } +} diff --git a/test/c-from-rust/check_ints.sh b/test/c-from-rust/check_ints.sh new file mode 100644 index 0000000..00780c3 --- /dev/null +++ b/test/c-from-rust/check_ints.sh @@ -0,0 +1,5 @@ +set -e + +for i in `seq 1 42`; do + ./main -$i | grep " -$i is $i" +done diff --git a/test/c-from-rust/clib/TARGETS b/test/c-from-rust/clib/TARGETS new file mode 100644 index 0000000..c72e90b --- /dev/null +++ b/test/c-from-rust/clib/TARGETS @@ -0,0 +1,19 @@ +{ "foo": + { "type": ["@", "rules-cc", "CC", "library"] + , "pure C": ["true"] + , "name": ["foo"] + , "srcs": ["foo.c"] + , "hdrs": ["foo.h"] + , "stage": ["foo"] + , "deps": ["bar"] + } +, "bar": + { "type": ["@", "rules-cc", "CC", "library"] + , "pure C": ["true"] + , "name": ["bar"] + , "srcs": ["bar.c"] + , "hdrs": ["bar.h"] + , "ldflags": ["-lm"] + , "stage": ["bar"] + } +} diff --git a/test/c-from-rust/clib/bar.c b/test/c-from-rust/clib/bar.c new file mode 100644 index 0000000..5ad792c --- /dev/null +++ b/test/c-from-rust/clib/bar.c @@ -0,0 +1,5 @@ +#include <math.h> + +int bar(int x){ + return sqrt(x); +} diff --git a/test/c-from-rust/clib/bar.h b/test/c-from-rust/clib/bar.h new file mode 100644 index 0000000..1c88e77 --- /dev/null +++ b/test/c-from-rust/clib/bar.h @@ -0,0 +1,3 @@ +#pragma once + +int bar(int); diff --git a/test/c-from-rust/clib/foo.c b/test/c-from-rust/clib/foo.c new file mode 100644 index 0000000..5306a9c --- /dev/null +++ b/test/c-from-rust/clib/foo.c @@ -0,0 +1,5 @@ +#include "bar/bar.h" + +int c_func(int x){ + return bar(x*x); +} diff --git a/test/c-from-rust/clib/foo.h b/test/c-from-rust/clib/foo.h new file mode 100644 index 0000000..6ce2745 --- /dev/null +++ b/test/c-from-rust/clib/foo.h @@ -0,0 +1,3 @@ +#pragma once +int c_func(int); + diff --git a/test/c-from-rust/main.rs b/test/c-from-rust/main.rs new file mode 100644 index 0000000..961150a --- /dev/null +++ b/test/c-from-rust/main.rs @@ -0,0 +1,20 @@ +use std::env; + +extern "C" { + fn c_func(input: i32) -> i32; +} + +fn c_call(i:i32) -> i32{ + unsafe { + return c_func(i); + } +} + +fn main() { + let args: Vec<String> = env::args().collect(); + match args[1].parse::<i32>() { + Ok(i) => println!("Absolute value of {} is {}",i, c_call(i)), + Err(..) => println!("Wrong argument {}",args[1]), + }; + +} diff --git a/test/dynamic/TARGETS b/test/dynamic/TARGETS new file mode 100644 index 0000000..556176e --- /dev/null +++ b/test/dynamic/TARGETS @@ -0,0 +1,53 @@ +{ "baz-lib": + { "type": ["@", "rules", "rust", "library"] + , "name": ["baz"] + , "stage": ["baz"] + , "crate_root": ["baz.rs"] + , "edition": ["2021"] + , "version": ["1", "2", "3", "rc-1"] + } +, "bar-lib": + { "type": ["@", "rules", "rust", "library"] + , "name": ["bar"] + , "stage": ["bar"] + , "crate_root": ["bar.rs"] + , "edition": ["2021"] + , "deps": ["baz-lib"] + } +, "bar-missing-baz": + { "type": ["@", "rules", "rust", "library"] + , "name": ["bar"] + , "stage": ["bar"] + , "crate_root": ["bar.rs"] + , "edition": ["2021"] + } +, "foo-lib": + { "type": ["@", "rules", "rust", "library"] + , "shared": ["true"] + , "name": ["foo"] + , "stage": ["foo"] + , "crate_root": ["foo.rs"] + , "edition": ["2021"] + , "deps": ["bar-lib"] + } +, "main": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + , "deps": ["foo-lib"] + } +, "main-wrong-dep": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + , "deps": ["bar-lib"] + } +, "main-missing-dep": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + } +} diff --git a/test/dynamic/bar.rs b/test/dynamic/bar.rs new file mode 100644 index 0000000..6a0afce --- /dev/null +++ b/test/dynamic/bar.rs @@ -0,0 +1,11 @@ + +extern crate baz; +pub fn hello(){ + baz::hello(); + println!("hello bar"); +} + +pub fn add(a: i32, b: i32) -> i32 { + a + b +} + diff --git a/test/dynamic/baz.rs b/test/dynamic/baz.rs new file mode 100644 index 0000000..4222589 --- /dev/null +++ b/test/dynamic/baz.rs @@ -0,0 +1,5 @@ + +pub fn hello(){ + +println!("hello baz"); + }
\ No newline at end of file diff --git a/test/dynamic/foo.rs b/test/dynamic/foo.rs new file mode 100644 index 0000000..c2dca08 --- /dev/null +++ b/test/dynamic/foo.rs @@ -0,0 +1,6 @@ +extern crate bar; +pub fn hello(){ + +bar::hello(); + println!("hello foo"); + }
\ No newline at end of file diff --git a/test/dynamic/main.rs b/test/dynamic/main.rs new file mode 100644 index 0000000..6da0e2e --- /dev/null +++ b/test/dynamic/main.rs @@ -0,0 +1,6 @@ +extern crate foo; + +fn main() { + +foo::hello(); +} diff --git a/test/rust-from-c/TARGETS b/test/rust-from-c/TARGETS new file mode 100644 index 0000000..1cb8019 --- /dev/null +++ b/test/rust-from-c/TARGETS @@ -0,0 +1,23 @@ +{ "main": + { "type": ["@", "rules-cc", "CC", "binary"] + , "pure C": ["true"] + , "name": ["main"] + , "srcs": ["main.c"] + , "private-deps": [["./", "foo", "foo"]] + } +, "test_foo": + { "type": ["rules/rust", "test"] + , "name": ["test_foo"] + , "crate_root": ["foo/foo_test.rs"] + , "stage": ["test_foo"] + , "deps": [["./", "foo", "foo"]] + } +, "check_ints": + { "type": ["@", "rules-cc", "shell/test", "script"] + , "name": ["check_ints"] + , "test": ["check_ints.sh"] + , "deps": ["main"] + } +, "TESTS": + {"type": "install", "deps": ["check_ints", "test_foo"], "tainted": ["test"]} +} diff --git a/test/rust-from-c/check_ints.sh b/test/rust-from-c/check_ints.sh new file mode 100644 index 0000000..00780c3 --- /dev/null +++ b/test/rust-from-c/check_ints.sh @@ -0,0 +1,5 @@ +set -e + +for i in `seq 1 42`; do + ./main -$i | grep " -$i is $i" +done diff --git a/test/rust-from-c/foo/TARGETS b/test/rust-from-c/foo/TARGETS new file mode 100644 index 0000000..17c66ba --- /dev/null +++ b/test/rust-from-c/foo/TARGETS @@ -0,0 +1,15 @@ +{ "foo": + { "type": ["rules/rust", "library"] + , "name": ["foo"] + , "crate_root": ["foo.rs"] + , "c_hdrs": ["foo.h"] + , "stage": ["foo"] + , "deps": ["bar"] + } +, "bar": + { "type": ["rules/rust", "library"] + , "name": ["bar"] + , "crate_root": ["bar.rs"] + , "stage": ["bar"] + } +} diff --git a/test/rust-from-c/foo/bar.rs b/test/rust-from-c/foo/bar.rs new file mode 100644 index 0000000..61e68f4 --- /dev/null +++ b/test/rust-from-c/foo/bar.rs @@ -0,0 +1,3 @@ +pub fn bar(x: i32) -> i32 { + return x.abs(); +}
\ No newline at end of file diff --git a/test/rust-from-c/foo/foo.h b/test/rust-from-c/foo/foo.h new file mode 100644 index 0000000..88deb2e --- /dev/null +++ b/test/rust-from-c/foo/foo.h @@ -0,0 +1,2 @@ +#pragma once +int foo(int); diff --git a/test/rust-from-c/foo/foo.rs b/test/rust-from-c/foo/foo.rs new file mode 100644 index 0000000..8735b67 --- /dev/null +++ b/test/rust-from-c/foo/foo.rs @@ -0,0 +1,6 @@ +extern crate bar; + +#[no_mangle] +pub extern "C" fn foo(x: i32) -> i32 { + return bar::bar(x); +} diff --git a/test/rust-from-c/foo/foo_test.rs b/test/rust-from-c/foo/foo_test.rs new file mode 100644 index 0000000..8b5de77 --- /dev/null +++ b/test/rust-from-c/foo/foo_test.rs @@ -0,0 +1,11 @@ +extern crate foo; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_foo(){ + assert_eq!(foo::foo(-7),7); + } +}
\ No newline at end of file diff --git a/test/rust-from-c/main.c b/test/rust-from-c/main.c new file mode 100644 index 0000000..0f69281 --- /dev/null +++ b/test/rust-from-c/main.c @@ -0,0 +1,14 @@ +#include <stdio.h> +#include <stdlib.h> + +int foo(int); + +int main(int argc, char **argv) { + if (argc < 2) { + fprintf(stderr, "Please provide one number as argument\n"); + exit(1); + } + int x = atoi(argv[1]); + printf("absolute value of %d is %d\n", x, foo(x)); + return 0; +} diff --git a/test/static-native/TARGETS b/test/static-native/TARGETS new file mode 100644 index 0000000..2b26236 --- /dev/null +++ b/test/static-native/TARGETS @@ -0,0 +1,54 @@ +{ "baz-lib": + { "type": ["@", "rules", "rust", "library"] + , "name": ["baz"] + , "native": ["true"] + , "stage": ["baz"] + , "crate_root": ["baz.rs"] + , "edition": ["2021"] + , "version": ["1", "2", "3", "rc-1"] + } +, "bar-lib": + { "type": ["@", "rules", "rust", "library"] + , "name": ["bar"] + , "stage": ["bar"] + , "crate_root": ["bar.rs"] + , "edition": ["2021"] + , "deps": ["baz-lib"] + } +, "bar-missing-baz": + { "type": ["@", "rules", "rust", "library"] + , "name": ["bar"] + , "stage": ["bar"] + , "crate_root": ["bar.rs"] + , "edition": ["2021"] + } +, "foo-lib": + { "type": ["@", "rules", "rust", "library"] + , "name": ["foo"] + , "native": ["true"] + , "stage": ["foo"] + , "crate_root": ["foo.rs"] + , "edition": ["2021"] + , "deps": ["bar-lib"] + } +, "main": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + , "deps": ["foo-lib"] + } +, "main-wrong-dep": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + , "deps": ["bar-lib"] + } +, "main-missing-dep": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + } +} diff --git a/test/static-native/bar.rs b/test/static-native/bar.rs new file mode 100644 index 0000000..6a0afce --- /dev/null +++ b/test/static-native/bar.rs @@ -0,0 +1,11 @@ + +extern crate baz; +pub fn hello(){ + baz::hello(); + println!("hello bar"); +} + +pub fn add(a: i32, b: i32) -> i32 { + a + b +} + diff --git a/test/static-native/baz.rs b/test/static-native/baz.rs new file mode 100644 index 0000000..4222589 --- /dev/null +++ b/test/static-native/baz.rs @@ -0,0 +1,5 @@ + +pub fn hello(){ + +println!("hello baz"); + }
\ No newline at end of file diff --git a/test/static-native/foo.rs b/test/static-native/foo.rs new file mode 100644 index 0000000..c2dca08 --- /dev/null +++ b/test/static-native/foo.rs @@ -0,0 +1,6 @@ +extern crate bar; +pub fn hello(){ + +bar::hello(); + println!("hello foo"); + }
\ No newline at end of file diff --git a/test/static-native/main.rs b/test/static-native/main.rs new file mode 100644 index 0000000..6da0e2e --- /dev/null +++ b/test/static-native/main.rs @@ -0,0 +1,6 @@ +extern crate foo; + +fn main() { + +foo::hello(); +} diff --git a/test/static/TARGETS b/test/static/TARGETS new file mode 100644 index 0000000..9337fc9 --- /dev/null +++ b/test/static/TARGETS @@ -0,0 +1,60 @@ +{ "baz-lib": + { "type": ["@", "rules", "rust", "library"] + , "name": ["baz"] + , "stage": ["baz"] + , "crate_root": ["baz.rs"] + , "deps": ["build_script"] + , "edition": ["2021"] + , "version": ["1", "2", "3", "rc-1"] + } +, "build_script": + { "type": ["@", "rules", "cargo", "build_script"] + , "name": ["build_script"] + , "crate_root": ["build.rs"] + , "edition": ["2018"] + , "stage": ["baz"] + } +, "bar-lib": + { "type": ["@", "rules", "rust", "library"] + , "name": ["bar"] + , "stage": ["bar"] + , "crate_root": ["bar.rs"] + , "edition": ["2021"] + , "deps": ["baz-lib"] + } +, "bar-missing-baz": + { "type": ["@", "rules", "rust", "library"] + , "name": ["bar"] + , "stage": ["bar"] + , "crate_root": ["bar.rs"] + , "edition": ["2021"] + } +, "foo-lib": + { "type": ["@", "rules", "rust", "library"] + , "name": ["foo"] + , "stage": ["foo"] + , "crate_root": ["foo.rs"] + , "edition": ["2021"] + , "deps": ["bar-lib"] + } +, "main": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + , "deps": ["foo-lib"] + } +, "main-wrong-dep": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + , "deps": ["bar-lib"] + } +, "main-missing-dep": + { "type": ["@", "rules", "rust", "binary"] + , "name": ["main"] + , "stage": ["bin"] + , "crate_root": ["main.rs"] + } +} diff --git a/test/static/bar.rs b/test/static/bar.rs new file mode 100644 index 0000000..6a0afce --- /dev/null +++ b/test/static/bar.rs @@ -0,0 +1,11 @@ + +extern crate baz; +pub fn hello(){ + baz::hello(); + println!("hello bar"); +} + +pub fn add(a: i32, b: i32) -> i32 { + a + b +} + diff --git a/test/static/baz.rs b/test/static/baz.rs new file mode 100644 index 0000000..4222589 --- /dev/null +++ b/test/static/baz.rs @@ -0,0 +1,5 @@ + +pub fn hello(){ + +println!("hello baz"); + }
\ No newline at end of file diff --git a/test/static/build.rs b/test/static/build.rs new file mode 100644 index 0000000..c2537fa --- /dev/null +++ b/test/static/build.rs @@ -0,0 +1,7 @@ + + +fn main() { + +println!("cargo:rustc-cfg=feature=\"config_transitionnnnnnnnnnnnnnnnnnnnnnnn\""); + +} diff --git a/test/static/foo.rs b/test/static/foo.rs new file mode 100644 index 0000000..c2dca08 --- /dev/null +++ b/test/static/foo.rs @@ -0,0 +1,6 @@ +extern crate bar; +pub fn hello(){ + +bar::hello(); + println!("hello foo"); + }
\ No newline at end of file diff --git a/test/static/main.rs b/test/static/main.rs new file mode 100644 index 0000000..6da0e2e --- /dev/null +++ b/test/static/main.rs @@ -0,0 +1,6 @@ +extern crate foo; + +fn main() { + +foo::hello(); +} |