false.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Phoenix Shell.
  5. *
  6. * Phoenix Shell is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import assert from 'assert';
  20. import { MakeTestContext } from './harness.js'
  21. import builtins from '../../src/puter-shell/coreutils/__exports__.js';
  22. import { Exit } from "../../src/puter-shell/coreutils/coreutil_lib/exit.js";
  23. async function testFalse(options) {
  24. let ctx = MakeTestContext(builtins.false, options);
  25. let hadError = false;
  26. try {
  27. await builtins.false.execute(ctx);
  28. } catch (e) {
  29. assert(e instanceof Exit);
  30. assert.notEqual(e.code, 0, 'returned exit code 0, meaning success');
  31. hadError = true;
  32. }
  33. if (!hadError) {
  34. assert.fail('didn\'t return an exit code');
  35. }
  36. assert.equal(ctx.externs.out.output, '', 'false should not write to stdout');
  37. assert.equal(ctx.externs.err.output, '', 'false should not write to stderr');
  38. }
  39. export const runFalseTests = () => {
  40. describe('false', function () {
  41. it('should return a non-zero exit code, with no output', async function () {
  42. await testFalse({});
  43. });
  44. it('should allow, but ignore, positional arguments', async function () {
  45. await testFalse({positionals: ['foo', 'bar', 'baz']});
  46. });
  47. });
  48. }