-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
load(":cdylib_name_analysis_test.bzl", "cdylib_name_analysis_test_suite") | ||
|
||
############################ UNIT TESTS ############################# | ||
cdylib_name_analysis_test_suite(name = "cdylib_name_analysis_test_suite") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Analysis tests for the name we assign to cdylib libraries.""" | ||
|
||
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") | ||
load("//rust:defs.bzl", "rust_shared_library") | ||
|
||
def _cdylib_name_test_impl(ctx): | ||
env = analysistest.begin(ctx) | ||
target = analysistest.target_under_test(env) | ||
|
||
# We're expecting the `.dylib`/`.so` to be the only file on Unix and Windows to | ||
# contain a pair of `.dll` and `.lib` files. | ||
files = target[DefaultInfo].files.to_list() | ||
if len(files) == 1: | ||
asserts.true(env, files[0].extension in ("so", "dylib")) | ||
if files[0].extension == "so": | ||
asserts.equals(env, files[0].basename, "libsomething.so") | ||
elif files[0].extension == "dylib": | ||
asserts.equals(env, files[0].basename, "libsomething.dylib") | ||
elif len(files) == 2: | ||
expected_filenames = ["something.dll", "something.dll.lib"] | ||
for file in files: | ||
asserts.true(env, file.basename in expected_filenames) | ||
expected_filenames.remove(file.basename) | ||
|
||
return analysistest.end(env) | ||
|
||
cdylib_name_test = analysistest.make(_cdylib_name_test_impl) | ||
|
||
def cdylib_name_analysis_test_suite(name): | ||
"""Analysis tests for the name we assign to cdylib libraries. | ||
Args: | ||
name: the test suite name | ||
""" | ||
rust_shared_library( | ||
name = "something", | ||
srcs = ["lib.rs"], | ||
) | ||
|
||
cdylib_name_test( | ||
name = "cdylib_name_test", | ||
target_under_test = ":something", | ||
) | ||
|
||
native.test_suite( | ||
name = name, | ||
tests = [":cdylib_name_test"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#[no_mangle] | ||
pub extern "C" fn say_hello() { | ||
println!("Hello"); | ||
} |