Skip to content

Do better showing differences between x,y in test() failure#7836

Merged
MichaelChirico merged 6 commits into
masterfrom
test-err-show-diff
Jul 26, 2026
Merged

Do better showing differences between x,y in test() failure#7836
MichaelChirico merged 6 commits into
masterfrom
test-err-show-diff

Conversation

@MichaelChirico

@MichaelChirico MichaelChirico commented Jul 24, 2026

Copy link
Copy Markdown
Member

Closes #7834. NB: merge target is not master currently

Output from test(1, c(1:10, 11:20, 30:21, 31:1000), c(1:10, 20:11, 30:21, 1000:31))

Test 1 ran without errors but failed check that x equals y:
> x = c(1:10, 11:20, 30:21, 31:1000) 
First 6 different of 980 (1000 total, type 'integer'): 
x[11] x[12] x[13] x[14] x[15] x[16] 
   11    12    13    14    15    16 
> y = c(1:10, 20:11, 30:21, 1000:31) 
First 6 different of 980 (1000 total, type 'integer'): 
y[11] y[12] y[13] y[14] y[15] y[16] 
   20    19    18    17    16    15 
Mean relative difference: 0.9406426

It's a bit visually dense; we might prefer this alternative using a matrix representation:

Test 1 ran without errors but failed check that x equals y:
> x = c(1:10, 11:20, 30:21, 31:1000) 
First 6 different of 980 (1000 total, type 'integer'): 
                        
index: 11 12 13 14 15 16
value: 11 12 13 14 15 16
> y = c(1:10, 20:11, 30:21, 1000:31) 
First 6 different of 980 (1000 total, type 'integer'): 
                        
index: 11 12 13 14 15 16
value: 20 19 18 17 16 15
Mean relative difference: 0.9406426

See also other test cases:

test(1, NA_character_, 'abc')
# Test 1 ran without errors but failed check that x equals y:
# > x = NA_character_ 
# First 1 different of 1 (1 total, type 'character'): 
# x[1] 
#   NA 
# > y = "abc" 
# First 1 different of 1 (1 total, type 'character'): 
#  y[1] 
# "abc" 
# 'is.NA' value mismatch: 0 in current 1 in target

x = c(1, 2, 3, NA, 4, NA)
y = c(NA, 2, 4, NA, 4, 5)
test(1, x, y)
# Test 1 ran without errors but failed check that x equals y:
# > x = x 
# First 3 different of 3 (6 total, type 'double'): 
# x[1] x[3] x[6] 
#    1    3   NA 
# > y = y 
# First 3 different of 3 (6 total, type 'double'): 
# y[1] y[3] y[6] 
#   NA    4    5 
# 'is.NA' value mismatch: 2 in current 2 in target

A case that's still not completely satisfactory -- it gives the impression of showing x[11] == y[11] -- but I'm willing to ignore for now:

test(1, c(1:10, 1.0000001), c(1:10, 1))
# Test 1 ran without errors but failed check that x equals y:
# > x = c(1:10, 1.0000001) 
# First 1 different of 1 (11 total, type 'double'): 
# x[11] 
#     1 
# > y = c(1:10, 1) 
# First 1 different of 1 (11 total, type 'double'): 
# y[11] 
#     1 
# Mean relative difference: 9.999999e-08

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.02%. Comparing base (895067d) to head (746918d).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7836   +/-   ##
=======================================
  Coverage   99.02%   99.02%           
=======================================
  Files          88       88           
  Lines       17266    17266           
=======================================
  Hits        17097    17097           
  Misses        169      169           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MichaelChirico
MichaelChirico changed the base branch from master to other-attach-order July 24, 2026 06:06
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

No obvious timing issues in HEAD=test-err-show-diff
Comparison Plot

Generated via commit 746918d

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 2 minutes and 54 seconds
Installing different package versions 1 minutes and 12 seconds
Running and plotting the test cases 7 minutes and 42 seconds

Comment thread NEWS.md Outdated
@ben-schwen

Copy link
Copy Markdown
Member

Also not 100% satisfied with the index representation. Maybe something like

First 6 of 980 differing elements (1000 total):
 index  x  y
    11 11 20
    12 12 19
    13 13 18
    14 14 17
    15 15 16
    16 16 15
Types: x integer, y integer

Comment thread R/test.data.table.R Outdated
@MichaelChirico

Copy link
Copy Markdown
Member Author

Maybe something like

The problem with this one is it requires a bit more of a refactor since the current approach is "show x difference then show y difference" as opposed to "show a holistic comparison of x,y".

@ben-schwen

Copy link
Copy Markdown
Member

The problem with this one is it requires a bit more of a refactor since the current approach is "show x difference then show y difference" as opposed to "show a holistic comparison of x,y".

True. Maybe we put that as follow up. The index notation is already much better TY!

@MichaelChirico
MichaelChirico changed the base branch from other-attach-order to master July 26, 2026 16:55
@MichaelChirico
MichaelChirico merged commit 2f88b3e into master Jul 26, 2026
14 checks passed
@MichaelChirico
MichaelChirico deleted the test-err-show-diff branch July 26, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test() failure not helpful for reporting exact match subset

2 participants