Skip to content

Commit

Permalink
some diagnostics to troubleshoot the failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alensiljak committed Sep 6, 2023
1 parent baf502e commit 20e21b9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ impl Account {
/// called from find_or_create.
fn create_account(&self, first: &str) -> &Account {
let mut new_account = Account::new(first);
log::debug!("Setting account parent: {:?}", self);
new_account.set_parent(self);

let self_mut = self.get_account_mut(self as *const Account as *mut Account);
Expand All @@ -45,6 +44,7 @@ impl Account {
let Some(new_ref) = self.accounts.get(first)
else {panic!("should not happen")};

log::debug!("The new account {:?} reference: {:p}", new_ref.name, new_ref);
new_ref
}

Expand Down Expand Up @@ -180,8 +180,13 @@ impl Account {
}

pub(crate) fn set_parent(&mut self, parent: &Account) {
// Confirm the pointers are the same.
assert_eq!(parent as *const Account, addr_of!(*parent));

// self.parent = parent as *const Account;
self.parent = addr_of!(*parent);

log::debug!("Setting the {:?} parent to {:?}, {:p}", self.name, parent.name, self.parent);
}

/// Returns the balance of this account and all sub-accounts.
Expand Down Expand Up @@ -349,7 +354,7 @@ mod tests {
assert_eq!(addr_of!(journal.master), assets.parent);
}

#[test]
#[test_log::test]
fn test_parent_pointers() {
let input = r#"2023-05-05 Payee
Expenses:Groceries 20
Expand All @@ -364,10 +369,13 @@ mod tests {
let assets = journal.get_account(ptr);
assert_eq!(addr_of!(journal.master), assets.parent);

// confirm that addr_of! and `as *const` are the same.
assert_eq!(assets as *const Account, addr_of!(*assets));

// cash
let ptr = journal.master.find_account("Cash").unwrap();
let cash = journal.get_account(ptr);
assert_eq!(addr_of!(*assets), cash.parent);
assert_eq!(assets as *const Account, cash.parent);

// expenses

Expand Down

0 comments on commit 20e21b9

Please sign in to comment.