Visitar URL original
feat(test): support value comparisons by oiahoon · Pull Request #1266 · shelljs/shelljs · GitHub
Skip to content

feat(test): support value comparisons - #1266

Open
oiahoon wants to merge 1 commit into
shelljs:mainfrom
oiahoon:feat/test-value-comparisons
Open

oiahoon wants to merge 1 commit into
shelljs:mainfrom
oiahoon:feat/test-value-comparisons

Conversation

@oiahoon

@oiahoon oiahoon commented Aug 26, 2026

Copy link
Copy Markdown

Summary

  • add string equality, inequality, empty, and nonempty expressions to test
  • add the six standard integer comparison operators with strict integer validation
  • preserve filesystem tests and option-object compatibility, with generated README documentation

Fixes #1230

Verification

  • npx ava test/test.js (30 passed on Node 22, 24, and 26)
  • npx ava --match='!*setuid*' --match='!*setgid*' (634 passed, 6 skipped)
  • npm run lint
  • npm run check-node-support
  • npm run gendocs

The unfiltered suite has two macOS permission-bit failures for setuid/setgid; both reproduce on the unchanged base commit.

Comment thread src/test.js Outdated
if (operator === '-gt') return leftInteger > rightInteger;
if (operator === '-ge') return leftInteger >= rightInteger;
if (operator === '-lt') return leftInteger < rightInteger;
return leftInteger <= rightInteger;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the if (operator === '-le' ... part before this. Then for the default case, you should use:

var e = new Exception('Unknown operator: ' + operator);
e.name = 'ShellJSInternalError';
throw e;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the explicit -le branch and defensive ShellJSInternalError in 49af902, using the standard JavaScript Error constructor.

Comment thread test/test.js
});

test('integer comparison rejects unsafe integers', t => {
shell.test('9007199254740992', '-gt', '1');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a comment why this integer is considered unsafe.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented why 2 ** 53 exceeds Number.MAX_SAFE_INTEGER in 49af902.

Comment thread test/test.js Outdated
['4', '-le', '3'],
];

expressions.forEach(expression => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a for-loop, could we just write out each comparison directly inside this test? Like so:

t.false('2 -eq 3', shell.test('2', '-eq', '3'));
t.falsy(shell.error());

t.false('2 -ne 2', shell.test('2', '-ne', '2'));
t.falsy(shell.error());

// So on and so forth...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanded every true and false integer comparison into individual assertions in 49af902. The 30 focused tests pass.

@oiahoon
oiahoon force-pushed the feat/test-value-comparisons branch from 1648d74 to 49af902 Compare October 10, 2026 13:58
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.

Support test on environment variable's value

2 participants