Skip to content

Test fails on windows when run in a git bash window #12

@hlovdal

Description

@hlovdal

The test newln = win32 ? '\r\n' : '\n' is too naive. It is perfectly possible to have single newline eol on stdout even on windows when running in a Git bash window (or via cygwin).

$ findstr commit < test/fixtures/commit | xxd
00000000: 636f 6d6d 6974 2032 3662 3131 3931 3562  commit 26b11915b
00000010: 3163 3136 3434 3034 3638 6134 6235 6634  1c16440468a4b5f4
00000020: 6230 3764 3234 3039 6239 3863 3638 630a  b07d2409b98c68c.
$

Notice the single 0a (aka '\n') at the end.

This makes running the test fail:

$ npm run test

> spawn-command@1.0.0 test
> node test/spawn-command-test.js

node:assert:95
  throw new AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: 'commit 26b11915b1c16440468a4b5f4b07d2409b98c68c\n' == 'commit 26b11915b1c16440468a4b5f4b07d2409b98c68c\r\n'
    at ChildProcess.<anonymous> (C:\github\spawn-command\test\spawn-command-test.js:24:10)
    at ChildProcess.<anonymous> (C:\github\spawn-command\node_modules\assert-called\lib\assert-called.js:7:8)
    at ChildProcess.emit (node:events:507:28)
    at maybeClose (node:internal/child_process:1101:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: 'commit 26b11915b1c16440468a4b5f4b07d2409b98c68c\n',
  expected: 'commit 26b11915b1c16440468a4b5f4b07d2409b98c68c\r\n',
  operator: '=='
}

Node.js v24.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions