Skip to content

Fixes for releasing to crates.io #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions rclrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ version = "0.2.0"
# This project is not military-sponsored, Jacob's employment contract just requires him to use this email address
authors = ["Esteve Fernandez <[email protected]>", "Nikolai Morin <[email protected]>", "Jacob Hassold <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
description = "A ROS 2 client library for developing robotics applications in Rust"

[lib]
path = "src/lib.rs"
Expand All @@ -16,17 +18,14 @@ libc = "0.2.43"
# Provides better concurrency primitives than std
parking_lot = "0.11.2"
# Needed for the Message trait, among others
rosidl_runtime_rs = "*"
rosidl_runtime_rs = "0.2.0"
# Needed for clients
futures = "0.3"

[dev-dependencies]
# Needed for e.g. writing yaml files in tests
tempfile = "3.3.0"

[dev-dependencies.std_msgs]
version = "*"

[build-dependencies]
# Needed for FFI
bindgen = "0.59.1"
2 changes: 0 additions & 2 deletions rclrs/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
<build_depend>rosidl_runtime_rs</build_depend>
<build_depend>rcl</build_depend>

<test_depend>std_msgs</test_depend>

<export>
<build_type>ament_cargo</build_type>
</export>
Expand Down
41 changes: 0 additions & 41 deletions rclrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,44 +147,3 @@ pub fn create_node(context: &Context, node_name: &str) -> Result<Node, RclrsErro
pub fn create_node_builder(context: &Context, node_name: &str) -> NodeBuilder {
Node::builder(context, node_name)
}

#[cfg(test)]
mod tests {
use super::*;
use std::sync::{Arc, Mutex};
use std::time::Duration;

#[test]
fn test_spin_once() -> Result<(), RclrsError> {
let context = Context::new(vec![]).unwrap();
let mut subscriber_node = create_node(&context, "minimal_subscriber")?;
let num_messages = Arc::new(Mutex::new(0));
let received_msg = Arc::new(Mutex::new(String::new()));
let n = num_messages.clone();
let m = received_msg.clone();
let publisher = subscriber_node
.create_publisher::<std_msgs::msg::String>("topic", QOS_PROFILE_DEFAULT)?;
let _subscription = subscriber_node.create_subscription::<std_msgs::msg::String, _>(
"topic",
QOS_PROFILE_DEFAULT,
move |msg: std_msgs::msg::String| {
let mut num_messages = n.lock().unwrap();
let mut received_msg = m.lock().unwrap();

*num_messages += 1;
*received_msg = msg.data;
},
)?;

let message = std_msgs::msg::String {
data: String::from("Hello World"),
};
publisher.publish(message)?;
spin_once(&subscriber_node, Some(Duration::from_millis(500)))?;

assert_eq!(*num_messages.lock().unwrap(), 1);
assert_eq!(&*received_msg.lock().unwrap().as_str(), "Hello World");

Ok(())
}
}
38 changes: 0 additions & 38 deletions rclrs/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,41 +338,3 @@ unsafe fn call_string_getter_with_handle(
let cstr = CStr::from_ptr(char_ptr);
cstr.to_string_lossy().into_owned()
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{create_node, Context, Node, QOS_PROFILE_DEFAULT};

#[test]
fn test_new() -> Result<(), RclrsError> {
let context =
Context::new(vec![]).expect("Context instantiation is expected to be a success");
let _ = Node::new(&context, "Bob")?;

Ok(())
}

#[test]
fn test_create_subscription() -> Result<(), RclrsError> {
let context =
Context::new(vec![]).expect("Context instantiation is expected to be a success");
let mut node = create_node(&context, "test_create_subscription")?;
let _subscription = node.create_subscription::<std_msgs::msg::String, _>(
"topic",
QOS_PROFILE_DEFAULT,
move |_: std_msgs::msg::String| {},
)?;
Ok(())
}

#[test]
fn test_create_publisher() -> Result<(), RclrsError> {
let context =
Context::new(vec![]).expect("Context instantiation is expected to be a success");
let node = create_node(&context, "test_create_publisher")?;
let _publisher =
node.create_publisher::<std_msgs::msg::String>("topic", QOS_PROFILE_DEFAULT)?;
Ok(())
}
}
34 changes: 0 additions & 34 deletions rclrs/src/node/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,37 +163,3 @@ impl<'a, T: Message> MessageCow<'a, T> for &'a T {
Cow::Borrowed(self)
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{create_node, Context, Publisher, QOS_PROFILE_DEFAULT};

fn create_fixture(name: &str) -> (Context, Node) {
let context =
Context::new(vec![]).expect("Context instantiation is expected to be a success");
let node =
create_node(&context, name).expect("Node instantiation is expected to be a success");

(context, node)
}

#[test]
fn test_new_publisher() -> Result<(), RclrsError> {
let (_, node) = create_fixture("test_new_publisher");
let _ = Publisher::<std_msgs::msg::String>::new(&node, "test", QOS_PROFILE_DEFAULT)?;

Ok(())
}

#[test]
fn test_publish_message() -> Result<(), RclrsError> {
let (_, node) = create_fixture("test_publish_message");
let publisher =
Publisher::<std_msgs::msg::String>::new(&node, "test", QOS_PROFILE_DEFAULT)?;
let message = std_msgs::msg::String {
data: "Hello world!".to_owned(),
};
publisher.publish(&message)
}
}
20 changes: 0 additions & 20 deletions rclrs/src/node/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,3 @@ where
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{create_node, Context, QOS_PROFILE_DEFAULT};

#[test]
fn test_instantiate_subscriber() -> Result<(), RclrsError> {
let context =
Context::new(vec![]).expect("Context instantiation is expected to be a success");
let mut node = create_node(&context, "test_new_subscriber")?;
let _subscriber = node.create_subscription::<std_msgs::msg::String, _>(
"test",
QOS_PROFILE_DEFAULT,
move |_: std_msgs::msg::String| {},
)?;

Ok(())
}
}
39 changes: 0 additions & 39 deletions rclrs/src/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,42 +289,3 @@ impl WaitSet {
Ok(ready_entities)
}
}

#[cfg(test)]
mod tests {
use crate::{Context, Node, RclrsError, WaitSet, QOS_PROFILE_DEFAULT};
use std::sync::Arc;

#[test]
fn test_adding_waitable_to_wait_sets() -> Result<(), RclrsError> {
let context = Context::new([])?;
let mut node = Node::new(&context, "test_adding_waitable_to_wait_sets")?;
let subscription = node.create_subscription(
"test",
QOS_PROFILE_DEFAULT,
move |_: std_msgs::msg::String| {},
)?;
let mut wait_set_1 = WaitSet::new(1, 0, 0, 0, 0, 0, &context)?;
let mut wait_set_2 = WaitSet::new(1, 0, 0, 0, 0, 0, &context)?;

// Try to add the subscription to wait set 1 twice
wait_set_1.add_subscription(Arc::clone(&subscription) as _)?;
assert!(wait_set_1
.add_subscription(Arc::clone(&subscription) as _)
.is_err());

// Try to add it to another wait set
assert!(wait_set_2
.add_subscription(Arc::clone(&subscription) as _)
.is_err());

// It works as soon as it is not anymore part of wait_set_1
wait_set_1.clear();
wait_set_2.add_subscription(Arc::clone(&subscription) as _)?;

// Dropping the wait set also frees up the subscription
drop(wait_set_2);
wait_set_1.add_subscription(Arc::clone(&subscription) as _)?;
Ok(())
}
}
4 changes: 3 additions & 1 deletion rosidl_runtime_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
name = "rosidl_runtime_rs"
version = "0.2.0"
# This project is not military-sponsored, Jacob's employment contract just requires him to use this email address
authors = ["Jacob Hassold <[email protected]>", "Nikolai Morin <[email protected]>"]
authors = ["Esteve Fernandez <[email protected]>", "Nikolai Morin <[email protected]>", "Jacob Hassold <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
description = "Message generation code shared by Rust projects in ROS 2"

[lib]
path = "src/lib.rs"
Expand Down