-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
26 lines (22 loc) · 924 Bytes
/
test.js
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
// Test whether it actually works
const fs = require('fs')
const {execSync} = require('child_process')
const {basename} = require('path')
const chalk = require('chalk')
console.log(chalk.bold('\n ** Beginning tests ** \n\n'))
const files = fs.readdirSync(__dirname)
.filter((filename) => { return filename.endsWith('.js') })
.filter(filename => filename !== basename(__filename))
let passed = 0;
files.forEach(file => {
const quineSourceCode = fs.readFileSync(file).toString().trim();
const quine = execSync(`node ${file}`, {cwd: __dirname}).toString().trim();
if (quine === quineSourceCode) {
console.log(chalk.green('PASS: ') + file)
passed++
} else {
console.log(chalk.red('FAIL: ') + file)
console.log(quine, quineSourceCode)
}
});
console.log(chalk.bold('\n\nResult: ') + `${passed} of ${files.length} passed, ${chalk.red(files.length - passed)} failed.`)