Skip to content

Commit

Permalink
src: Replace all dbg to tracing info and tracing-test macro
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin authored and patrickelectric committed Apr 24, 2024
1 parent 6a6b910 commit 717a002
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use tracing::info;

use crate::message::{ProtocolMessage, HEADER};

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -77,7 +79,11 @@ impl Decoder {
}
DecoderState::ReadingPayload => {
self.buffer.push(byte);
dbg!(self.buffer.len(), self.message.payload_length);
info!(
"DecoderState : ReadingPayload {:?} {:?}",
self.buffer.len(),
self.message.payload_length
);
if self.buffer.len() == self.message.payload_length as usize {
self.message.payload = self.buffer.clone();
self.state = DecoderState::ReadingChecksum;
Expand Down
7 changes: 5 additions & 2 deletions tests/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::convert::TryFrom;
use ping_rs::common::Messages as common_messages;
use ping_rs::decoder::*;
use ping_rs::{common, Messages};
use tracing::info;
use tracing_test::traced_test;

#[traced_test]
#[test]
fn test_simple_deserialization() {
let mut decoder = Decoder::new();
Expand All @@ -24,7 +27,7 @@ fn test_simple_deserialization() {
assert_eq!(general_request, parsed);

for byte in &buffer[0..buffer.len() - 2] {
dbg!(byte, &decoder.state);
info!("byte : {byte}, {:?}", &decoder.state);
assert!(matches!(
decoder.parse_byte(byte.clone()),
DecoderResult::InProgress
Expand All @@ -35,7 +38,7 @@ fn test_simple_deserialization() {
DecoderResult::InProgress
));
let DecoderResult::Success(_message) = decoder.parse_byte(buffer[buffer.len() - 1]) else {
dbg!(decoder.state);
info!("Decoder state: {:?}", decoder.state);
panic!("Failed to use decoder with valid message");
};

Expand Down
2 changes: 2 additions & 0 deletions tests/packer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use ping_rs::common::{self, Messages as common_messages};
use ping_rs::message::{MessageInfo, PingMessage, ProtocolMessage};
use tracing_test::traced_test;

#[traced_test]
#[test]
fn test_same_packer() {
let mut packer = ProtocolMessage::new();
Expand Down
2 changes: 2 additions & 0 deletions tests/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use ping_rs::common;
use ping_rs::message::SerializePayload;
use tracing_test::traced_test;

#[traced_test]
#[test]
fn test_simple_serialization() {
let general_request = common::GeneralRequestStruct { requested_id: 5 };
Expand Down

0 comments on commit 717a002

Please sign in to comment.