ravingmantis / unittest

Unit testing for R
4 stars 1 forks source link

Better comparison helper support #5

Closed lentinj closed 2 years ago

lentinj commented 2 years ago

I can make a helper to compare environments, e.g.:

cmp_environment <- function (a, b) {
    a <- as.list(a)
    b <- as.list(b)
    if (length(a) == 0) {
        # Can't order an empty list
        ut_cmp_identical(a, b)
    } else {
        ut_cmp_identical(a[order(names(a))], b[order(names(b))])
    }
}
ok(cmp_environment( as.environment(list(a=1, b=2)), as.environment(list(a=1, b=2))   )  )

...but then the diff output doesn't include the previous expressions as.environment(list(a=1, b=2)), just +++ a[order(names(a))], which doesn't help. Need to either:-