forked from stjordanis/rust-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·64 lines (51 loc) · 1.6 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env node
const fss = require('fs')
const spawnSync = require('child_process').spawnSync
const path = require('path')
const libImplDirName = 'impl'
const srcDirName = 'src'
let args = process.argv.slice(2)
function runSync(cmd, args) {
console.log(`Executing '${cmd} ${args.join(' ')}'`)
let proc = spawnSync(cmd, args, {stdio: 'inherit', shell: true})
if (proc.status != 0) {
process.exit(code)
}
}
function testLibrary() {
cwd = process.cwd()
containedDirs = fss.readdirSync(cwd, {withFileTypes: true})
.filter(f => f.isDirectory())
.map(d => d.name)
if (containedDirs.includes(srcDirName)) {
console.log(`In directory ${cwd}`)
runSync('wasm-pack',['test', '--node'])
} else if (containedDirs.includes(libImplDirName)) {
let new_dir = path.join(cwd,libImplDirName)
withCwd(new_dir, () => testLibrary())
} else {
let deeperDirs = containedDirs.map(d => path.join(cwd, d))
deeperDirs.forEach(d => withCwd(d, testLibrary))
}
}
async function withCwd(dir, fn) {
let cwd = process.cwd()
process.chdir(dir)
let out = await fn()
process.chdir(cwd)
return out
}
function testWasm() {
let workingDir = path.dirname(__filename)
let sourceDir = path.join(workingDir, 'src')
dirs = fss.readdirSync(sourceDir, {withFileTypes: true})
.filter(f => f.isDirectory())
.map(d => path.join(sourceDir, d.name))
dirs.forEach(d => withCwd(d, testLibrary))
}
async function main() {
if (args.includes('--test-wasm')) {
testWasm()
}
}
main()