Skip to content

Commit

Permalink
Handle multi-lined messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pnehrer committed Apr 21, 2024
1 parent 9b12d20 commit 2674849
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gha"
version = "0.1.2"
version = "0.1.3"
authors = ["Peter Nehrer <pnehrer@eclipticalsoftware.com>"]
repository = "https://github.com/ecliptical/gha"
description = """
Expand Down
25 changes: 25 additions & 0 deletions examples/debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use gha::debug;

fn main() {
debug!("single line");

#[derive(Debug)]
#[allow(dead_code)]
struct LongStruct {
a: &'static str,
b: usize,
c: Option<Box<LongStruct>>,
}

let root = LongStruct {
a: "test",
b: 12,
c: Some(Box::new(LongStruct {
a: "another test",
b: 34,
c: None,
})),
};

debug!("{root:#?}");
}
56 changes: 47 additions & 9 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#[macro_export]
macro_rules! debug {
($($arg:tt)*) => {
println!("::debug::{}", format!($($arg)*));
for line in format!($($arg)*).lines() {
println!("::debug::{line}");
}
};
}

Expand Down Expand Up @@ -257,50 +259,50 @@ macro_rules! message {
($type:expr, title = $title:tt, file = $file:tt, line = $line:tt, end_line = $end_line:tt, col = $col:tt, end_col = $end_col:tt, $($arg:tt)*) => {
println!(
"::{} title={},file={},line={},endLine={},col={},endColumn={}::{}",
$type, $title, $file, $line, $end_line, $col, $end_col, format!($($arg)*)
$type, $title, $file, $line, $end_line, $col, $end_col, format!($($arg)*).replace('\n', " ")
);
};

($type:expr, title = $title:tt, file = $file:tt, line = $line:tt, col = $col:tt, end_col = $end_col:tt, $($arg:tt)*) => {
println!(
"::{} title={},file={},line={},col={},endColumn={}::{}",
$type, $title, $file, $line, $col, $end_col, format!($($arg)*)
$type, $title, $file, $line, $col, $end_col, format!($($arg)*).replace('\n', " ")
);
};

($type:expr, title = $title:tt, file = $file:tt, line = $line:tt, end_line = $end_line:tt, col = $col:tt, $($arg:tt)*) => {
println!(
"::{} title={},file={},line={},endLine={},col={}::{}",
$type, $title, $file, $line, $end_line, $col, format!($($arg)*)
$type, $title, $file, $line, $end_line, $col, format!($($arg)*).replace('\n', " ")
);
};
($type:expr, title = $title:tt, file = $file:tt, line = $line:tt, end_line = $end_line:tt, $($arg:tt)*) => {
println!(
"::{} title={},file={},line={},endLine={}::{}",
$type, $title, $file, $line, $end_line, format!($($arg)*)
$type, $title, $file, $line, $end_line, format!($($arg)*).replace('\n', " ")
);
};

($type:expr, title = $title:tt, file = $file:tt, line = $line:tt, col = $col:tt, $($arg:tt)*) => {
println!(
"::{} title={},file={},line={},col={}::{}",
$type, $title, $file, $line, $col, format!($($arg)*)
$type, $title, $file, $line, $col, format!($($arg)*).replace('\n', " ")
);
};

($type:expr, title = $title:tt, file = $file:tt, line = $line:tt, $($arg:tt)*) => {
println!(
"::{} title={},file={},line={}::{}",
$type, $title, $file, $line, format!($($arg)*)
$type, $title, $file, $line, format!($($arg)*).replace('\n', " ")
);
};

($type:expr, title = $title:tt, file = $file:tt, $($arg:tt)*) => {
println!("::{} title={},file={}::{}", $type, $title, $file, format!($($arg)*));
println!("::{} title={},file={}::{}", $type, $title, $file, format!($($arg)*).replace('\n', " "));
};

($type:expr, title = $title:tt, $($arg:tt)*) => {
println!("::{} title={}::{}", $type, $title, format!($($arg)*));
println!("::{} title={}::{}", $type, $title, format!($($arg)*).replace('\n', " "));
};
}

Expand Down Expand Up @@ -342,6 +344,18 @@ mod tests {
);
}

#[test]
fn notice_end_line_col() {
notice!(
title = "test title",
file = "test file",
line = 2,
end_line = 3,
col = 1,
"test msg"
);
}

#[test]
fn notice_col() {
notice!(
Expand Down Expand Up @@ -410,6 +424,18 @@ mod tests {
);
}

#[test]
fn warning_end_line_col() {
warning!(
title = "test title",
file = "test file",
line = 2,
end_line = 3,
col = 1,
"test msg"
);
}

#[test]
fn warning_col() {
warning!(
Expand Down Expand Up @@ -478,6 +504,18 @@ mod tests {
);
}

#[test]
fn error_end_line_col() {
error!(
title = "test title",
file = "test file",
line = 2,
end_line = 3,
col = 1,
"test msg"
);
}

#[test]
fn error_col() {
error!(
Expand Down

0 comments on commit 2674849

Please sign in to comment.