true.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. async function testTrue(options) {
  23. let ctx = MakeTestContext(builtins.true, options);
  24. try {
  25. const result = await builtins.true.execute(ctx);
  26. assert.equal(result, undefined);
  27. } catch (e) {
  28. assert.fail(e);
  29. }
  30. assert.equal(ctx.externs.out.output, '', 'true should not write to stdout');
  31. assert.equal(ctx.externs.err.output, '', 'true should not write to stderr');
  32. }
  33. export const runTrueTests = () => {
  34. describe('true', function () {
  35. it('should execute successfully with no output', async function () {
  36. await testTrue({});
  37. });
  38. it('should allow, but ignore, positional arguments', async function () {
  39. await testTrue({positionals: ['foo', 'bar', 'baz']});
  40. });
  41. });
  42. }