This is an automated email from the ASF dual-hosted git repository.

comphead pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 3978e5d11d Minor: add example to of assert_batches_eq (#12580)
3978e5d11d is described below

commit 3978e5d11dfd0532b4d19e27563bfbe7b8375389
Author: Andrew Lamb <[email protected]>
AuthorDate: Sun Sep 22 14:51:00 2024 -0400

    Minor: add example to of assert_batches_eq (#12580)
---
 datafusion/common/src/test_util.rs | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/datafusion/common/src/test_util.rs 
b/datafusion/common/src/test_util.rs
index 9c3dfe62e1..3625419255 100644
--- a/datafusion/common/src/test_util.rs
+++ b/datafusion/common/src/test_util.rs
@@ -29,6 +29,27 @@ use std::{error::Error, path::PathBuf};
 /// Expects to be called about like this:
 ///
 /// `assert_batch_eq!(expected_lines: &[&str], batches: &[RecordBatch])`
+///
+/// # Example
+/// ```
+/// # use std::sync::Arc;
+/// # use arrow::record_batch::RecordBatch;
+/// # use arrow_array::{ArrayRef, Int32Array};
+/// # use datafusion_common::assert_batches_eq;
+/// let col: ArrayRef = Arc::new(Int32Array::from(vec![1, 2]));
+///  let batch = RecordBatch::try_from_iter([("column", col)]).unwrap();
+/// // Expected output is a vec of strings
+/// let expected = vec![
+///     "+--------+",
+///     "| column |",
+///     "+--------+",
+///     "| 1      |",
+///     "| 2      |",
+///     "+--------+",
+/// ];
+/// // compare the formatted output of the record batch with the expected 
output
+/// assert_batches_eq!(expected, &[batch]);
+/// ```
 #[macro_export]
 macro_rules! assert_batches_eq {
     ($EXPECTED_LINES: expr, $CHUNKS: expr) => {
@@ -56,8 +77,7 @@ macro_rules! assert_batches_eq {
 /// vector of strings in a way that order does not matter.
 /// This is a macro so errors appear on the correct line
 ///
-/// Designed so that failure output can be directly copy/pasted
-/// into the test code as expected results.
+/// See [`assert_batches_eq`] for more details and example.
 ///
 /// Expects to be called about like this:
 ///


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to