mathjs/test/node-tests/cli/cli.test.js
Veeloxfire f6a8a23e8b
Prefix the cli test with 'node' so it works on windows (#1807)
* Prefix the cli test with 'node' so it works on windows

Shouldnt provide any issues for other systems I hope

* Revert "Prefix the cli test with 'node' so it works on windows"

This reverts commit 4cd270493aeba0a9fad1661258c7ccc286934f53.

* Revert "Revert "Prefix the cli test with 'node' so it works on windows""

This reverts commit 268b5949a817fd416dbada72f1334ccaac0e3dfa.

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2020-04-08 13:58:12 +02:00

44 lines
1.1 KiB
JavaScript

// Only use native node.js API's and references to ./lib here, this file is not transpiled!
const assert = require('assert')
const path = require('path')
const cp = require('child_process')
function run (args, done) {
cp.exec('node bin/cli.js ' + args, function (e, r) {
done(e, r.replace(/\n$/g, ''))
})
}
describe('command line interface', function () {
it('should sum numbers', function (done) {
run('"1+1"', function (e, result) {
assert.strictEqual(result, '2')
done()
})
})
it('should multiply matrices', function (done) {
run('"[1,2] * [3,4]"', function (e, result) {
assert.strictEqual(result, '11')
done()
})
})
it('should thow error', function (done) {
run('"y=x"', function (e, result) {
assert.strictEqual(/^Error/g.test(e.toString()), true)
done()
})
})
it('should interpret scripts', function (done) {
const path1 = path.join(__dirname, 'script1')
const path2 = path.join(__dirname, 'script2')
run('"' + path1 + '" "' + path2 + '"', function (e, result) {
assert.strictEqual(result, '2\n8\n')
done()
})
})
})