nu-git-manager icon indicating copy to clipboard operation
nu-git-manager copied to clipboard

fix: collect the output of `gm repo compare` in the tests

Open amtoine opened this issue 1 year ago • 7 comments

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-commit test passes without collect, because gm repo get commit also returns a byte stream instead of a string

amtoine avatar Jul 19 '24 09:07 amtoine

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.

devyn avatar Jul 19 '24 09:07 devyn

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

amtoine avatar Jul 19 '24 10:07 amtoine

also, if would expect metadata to always produce a valid span, which is not the case here :thinking:

amtoine avatar Jul 19 '24 10:07 amtoine

I thought the CI error was because you are running ubuntu 20.04 in CI versus ubuntu latest.

fdncred avatar Jul 19 '24 11:07 fdncred

@fdncred maybe you're referring to the failing CI from https://github.com/nushell/nupm/pull/94? :yum:

amtoine avatar Jul 19 '24 11:07 amtoine

@amtoine Ya, sorry.

fdncred avatar Jul 19 '24 13:07 fdncred

@fdncred aha, no worries, these two CI issues are haunting my dreams :rofl:

amtoine avatar Jul 19 '24 14:07 amtoine