fix: collect the output of `gm repo compare` in the tests
related to
- https://github.com/amtoine/nu-git-manager/actions/runs/10005343512/job/27655861805#step:6:329
running tk test compare --verbose would give the following error:
Error: × invalid error format.
╭─[NU_STDLIB_VIRTUAL_DIR/std/assert.nu:44:16]
43 │ msg: ($message | default "Assertion failed."),
44 │ ╭─▶ label: ($error_label | default {
45 │ │ text: "It is not true.",
46 │ │ span: (metadata $condition).span,
47 │ ├─▶ })
· ╰──── `$.label.start` should be smaller than `$.label.end`
48 │ }
╰────
help: 112592 > 104293
it appears the gm repo branch compare command outputs a "byte stream" instead of a string :thinking:
what i don't understand:
- where this error comes from
- why the
get-committest passes withoutcollect, becausegm repo get commitalso returns a byte stream instead of astring
Byte streams are the normal output of external commands. They can be used as strings as long as they parse as UTF-8, and they can also be used as binary. Having a byte stream isn't unusual, and you might also see string (stream) which can only be used as a string, but generally is produced by commands that definitely make good UTF-8 data (so internal commands that make potentially big strings).
Since the culprit is the value of $condition, can you tell me a little bit more about what the argument to assert might be? It would help to be able to narrow this down to the test that's producing it.
well, i can't reproduce this for now :thinking:
if i add a few debug prints to the test to extract the values of actual and expected
diff --git a/pkgs/nu-git-manager-sugar/tests/git.nu b/pkgs/nu-git-manager-sugar/tests/git.nu
index 9057dfe..df5414e 100644
--- a/pkgs/nu-git-manager-sugar/tests/git.nu
+++ b/pkgs/nu-git-manager-sugar/tests/git.nu
@@ -356,6 +356,12 @@ export def branch-compare [] {
"\\ No newline at end of file"
"",
]
+ print "ACTUAL---"
+ print (gm repo compare main)
+ print "---END"
+ print "EXPECTED"
+ print ($expected | str join "\n")
+ print "---END"
assert equal (gm repo compare main) ($expected | str join "\n")
assert equal (gm repo compare main --head HEAD) ($expected | str join "\n")
i get
let actual = 'diff --git a/foo.txt b/foo.txt
new file mode 100644
index 0000000..1910281
--- /dev/null
+++ b/foo.txt
@@ -0,0 +1 @@
+foo
\ No newline at end of file'
let expected = 'diff --git a/foo.txt b/foo.txt
new file mode 100644
index 0000000..1910281
--- /dev/null
+++ b/foo.txt
@@ -0,0 +1 @@
+foo
\ No newline at end of file
'
but
use std assert
assert equal $actual $expected
does not fail with the "span" issue
idea
maybe that's because actual is a Nushell string there and not an external byte stream.
but if i try a dummy example with an external command, it does not fail
^echo "foo" | describe # shows "byte stream"
but
assert equal (^echo "foo") "foo" # does not fail
also, if would expect metadata to always produce a valid span, which is not the case here :thinking:
I thought the CI error was because you are running ubuntu 20.04 in CI versus ubuntu latest.
@fdncred maybe you're referring to the failing CI from https://github.com/nushell/nupm/pull/94? :yum:
@amtoine Ya, sorry.
@fdncred aha, no worries, these two CI issues are haunting my dreams :rofl: