|
| 1 | +const t = require('tap') |
| 2 | + |
| 3 | +// run three scenarios |
| 4 | +// unix (no fmap) |
| 5 | +// win32 (without fmap support) |
| 6 | +// win32 (with fmap support) |
| 7 | + |
| 8 | +const fs = require('fs') |
| 9 | +const hasFmap = !!fs.constants.UV_FS_O_FILEMAP |
| 10 | +const platform = process.platform |
| 11 | + |
| 12 | +switch (process.argv[2]) { |
| 13 | + case 'win32-fmap': { |
| 14 | + if (!hasFmap) |
| 15 | + fs.constants.UV_FS_O_FILEMAP = 0x20000000 |
| 16 | + const { O_CREAT, O_TRUNC, O_WRONLY, UV_FS_O_FILEMAP } = fs.constants |
| 17 | + if (platform !== 'win32') |
| 18 | + process.env.__FAKE_PLATFORM__ = 'win32' |
| 19 | + const getFlag = require('../lib/get-write-flag.js') |
| 20 | + t.equal(getFlag(1), UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY) |
| 21 | + t.equal(getFlag(512 * 1024 + 1), 'w') |
| 22 | + break |
| 23 | + } |
| 24 | + |
| 25 | + case 'win32-nofmap': { |
| 26 | + if (hasFmap) |
| 27 | + fs.constants.UV_FS_O_FILEMAP = 0 |
| 28 | + if (platform !== 'win32') |
| 29 | + process.env.__FAKE_PLATFORM__ = 'win32' |
| 30 | + const getFlag = require('../lib/get-write-flag.js') |
| 31 | + t.equal(getFlag(1), 'w') |
| 32 | + t.equal(getFlag(512 * 1024 + 1), 'w') |
| 33 | + break |
| 34 | + } |
| 35 | + |
| 36 | + case 'unix': { |
| 37 | + if (platform === 'win32') |
| 38 | + process.env.__FAKE_PLATFORM__ = 'darwin' |
| 39 | + const getFlag = require('../lib/get-write-flag.js') |
| 40 | + t.equal(getFlag(1), 'w') |
| 41 | + t.equal(getFlag(512 * 1024 + 1), 'w') |
| 42 | + break |
| 43 | + } |
| 44 | + |
| 45 | + default: { |
| 46 | + const node = process.execPath |
| 47 | + t.spawn(node, [__filename, 'win32-fmap']) |
| 48 | + t.spawn(node, [__filename, 'win32-nofmap']) |
| 49 | + t.spawn(node, [__filename, 'unix']) |
| 50 | + } |
| 51 | +} |
0 commit comments