Skip to content

Commit c76d93b

Browse files
committed
fixup! test only error code & simplify tests
1 parent e6b2341 commit c76d93b

5 files changed

+48
-98
lines changed

Diff for: test/pummel/test-buffer-large-size-buffer-alloc-unsafe-slow.js

+9-21
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,15 @@ const common = require('../common');
44
// Buffer with size > INT32_MAX
55
common.skipIf32Bits();
66

7-
// Test Buffer size larger than integer range
8-
const { test } = require('node:test');
9-
const assert = require('assert');
10-
const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
11-
12-
const stringTooLongError = {
13-
message: `Cannot create a string longer than 0x${kStringMaxLength.toString(16)}` +
14-
' characters',
15-
code: 'ERR_STRING_TOO_LONG',
16-
name: 'Error',
17-
};
18-
7+
const assert = require('node:assert');
198
const size = 2 ** 31;
209

21-
test('Buffer.allocUnsafeSlow with too long size', () => {
22-
try {
23-
assert.throws(() => Buffer.allocUnsafeSlow(size).toString('utf8'), stringTooLongError);
24-
} catch (e) {
25-
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
26-
throw e;
27-
}
28-
common.skip('insufficient space for Buffer.allocUnsafeSlow');
10+
// Test Buffer.allocUnsafe with size larger than integer range
11+
try {
12+
assert.throws(() => Buffer.allocUnsafeSlow(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
13+
} catch (e) {
14+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
15+
throw e;
2916
}
30-
});
17+
common.skip('insufficient space for Buffer.allocUnsafeSlow');
18+
}

Diff for: test/pummel/test-buffer-large-size-buffer-alloc-unsafe.js

+9-21
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,15 @@ const common = require('../common');
44
// Buffer with size > INT32_MAX
55
common.skipIf32Bits();
66

7-
// Test Buffer size larger than integer range
8-
const { test } = require('node:test');
9-
const assert = require('assert');
10-
const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
11-
12-
const stringTooLongError = {
13-
message: `Cannot create a string longer than 0x${kStringMaxLength.toString(16)}` +
14-
' characters',
15-
code: 'ERR_STRING_TOO_LONG',
16-
name: 'Error',
17-
};
18-
7+
const assert = require('node:assert');
198
const size = 2 ** 31;
209

21-
test('Buffer.allocUnsafe with too long size', () => {
22-
try {
23-
assert.throws(() => Buffer.allocUnsafe(size).toString('utf8'), stringTooLongError);
24-
} catch (e) {
25-
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
26-
throw e;
27-
}
28-
common.skip('insufficient space for Buffer.allocUnsafe');
10+
try {
11+
// Test Buffer.allocUnsafe with size larger than integer range
12+
assert.throws(() => Buffer.allocUnsafe(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
13+
} catch (e) {
14+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
15+
throw e;
2916
}
30-
});
17+
common.skip('insufficient space for Buffer.allocUnsafe');
18+
}

Diff for: test/pummel/test-buffer-large-size-buffer-alloc.js

+9-21
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,15 @@ const common = require('../common');
44
// Buffer with size > INT32_MAX
55
common.skipIf32Bits();
66

7-
// Test Buffer size larger than integer range
8-
const { test } = require('node:test');
9-
const assert = require('assert');
10-
const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
11-
12-
const stringTooLongError = {
13-
message: `Cannot create a string longer than 0x${kStringMaxLength.toString(16)}` +
14-
' characters',
15-
code: 'ERR_STRING_TOO_LONG',
16-
name: 'Error',
17-
};
18-
7+
const assert = require('node:assert');
198
const size = 2 ** 31;
209

21-
test('Buffer.alloc too long size', () => {
22-
try {
23-
assert.throws(() => Buffer.alloc(size).toString('utf8'), stringTooLongError);
24-
} catch (e) {
25-
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
26-
throw e;
27-
}
28-
common.skip('insufficient space for Buffer.alloc');
10+
// Test Buffer.alloc with size larger than integer range
11+
try {
12+
assert.throws(() => Buffer.alloc(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
13+
} catch (e) {
14+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
15+
throw e;
2916
}
30-
});
17+
common.skip('insufficient space for Buffer.alloc');
18+
}

Diff for: test/pummel/test-buffer-large-size-buffer-write.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@ const common = require('../common');
44
// Buffer with size > INT32_MAX
55
common.skipIf32Bits();
66

7-
// Test Buffer size larger than integer range
8-
const { test } = require('node:test');
9-
const assert = require('assert');
7+
const assert = require('node:assert');
108
const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
119

1210
const size = 2 ** 31;
1311

14-
test('Buffer.write with too long size', () => {
15-
try {
16-
const buf = Buffer.alloc(size);
17-
assert.strictEqual(buf.write('a', 2, kStringMaxLength), 1);
18-
assert.strictEqual(buf.write('a', 2, size), 1);
19-
} catch (e) {
20-
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
21-
throw e;
22-
}
23-
common.skip('insufficient space for Buffer.alloc');
12+
// Test Buffer.write with size larger than integer range
13+
try {
14+
const buf = Buffer.alloc(size);
15+
assert.strictEqual(buf.write('a', 2, kStringMaxLength), 1);
16+
assert.strictEqual(buf.write('a', 2, size), 1);
17+
} catch (e) {
18+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
19+
throw e;
2420
}
25-
});
21+
common.skip('insufficient space for Buffer.alloc');
22+
}

Diff for: test/pummel/test-buffer-large-size-slowbuffer.js

+10-21
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,19 @@ const common = require('../common');
44
// Buffer with size > INT32_MAX
55
common.skipIf32Bits();
66

7-
// Test Buffer size larger than integer range
8-
const { test } = require('node:test');
9-
const assert = require('assert');
7+
const assert = require('node:assert');
108
const {
119
SlowBuffer,
12-
} = require('buffer');
13-
const kStringMaxLength = require('buffer').constants.MAX_STRING_LENGTH;
14-
15-
const stringTooLongError = {
16-
message: `Cannot create a string longer than 0x${kStringMaxLength.toString(16)}` +
17-
' characters',
18-
code: 'ERR_STRING_TOO_LONG',
19-
name: 'Error',
20-
};
10+
} = require('node:buffer');
2111

2212
const size = 2 ** 31;
2313

24-
test('SlowBuffer.toString with too long size', () => {
25-
try {
26-
assert.throws(() => SlowBuffer(size).toString('utf8'), stringTooLongError);
27-
} catch (e) {
28-
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
29-
throw e;
30-
}
31-
common.skip('insufficient space for SlowBuffer');
14+
// Test SlowBuffer with size larger than integer range
15+
try {
16+
assert.throws(() => SlowBuffer(size).toString('utf8'), { code: 'ERR_STRING_TOO_LONG' });
17+
} catch (e) {
18+
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
19+
throw e;
3220
}
33-
});
21+
common.skip('insufficient space for SlowBuffer');
22+
}

0 commit comments

Comments
 (0)