|
| 1 | +/*jshint loopfunc:true, node:true */ |
| 2 | +// mainly for testing --config cli option |
| 3 | +"use strict"; |
| 4 | +function include(path, sandbox) { |
| 5 | + var |
| 6 | + vm = require("vm"), |
| 7 | + fs = require("fs"), |
| 8 | + file; |
| 9 | + |
| 10 | + file = fs.readFileSync(path); |
| 11 | + vm.runInNewContext(file, sandbox); |
| 12 | +} |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +(function(){ |
| 17 | + |
| 18 | + var Assert = YUITest.Assert, |
| 19 | + suite = new YUITest.TestSuite("General Tests for CLI"), |
| 20 | + apiStub = require("./tests/cli/assets/apiStub.js"), |
| 21 | + data = require("./tests/cli/assets/data.js"), |
| 22 | + suites = data.suites, |
| 23 | + suiteix, |
| 24 | + sandbox = { |
| 25 | + CSSLint: CSSLint |
| 26 | + }; |
| 27 | + |
| 28 | + include(__dirname + "/src/cli/common.js", sandbox); /* expose sandbox.cli */ |
| 29 | + |
| 30 | + for (suiteix in suites) { |
| 31 | + if (suites.hasOwnProperty(suiteix)) { |
| 32 | + (function (suiteix) { |
| 33 | + |
| 34 | + suite.add(new YUITest.TestCase({ |
| 35 | + |
| 36 | + name: "Test " + suiteix, |
| 37 | + |
| 38 | + "Outcome logs should match expected": function (){ |
| 39 | + var |
| 40 | + it = suites[suiteix], |
| 41 | + expecting = it.expecting, |
| 42 | + expectingLen = expecting.length, |
| 43 | + outcome, |
| 44 | + api, |
| 45 | + exp, |
| 46 | + out, |
| 47 | + i = 0; |
| 48 | + |
| 49 | + data.args = it.args.slice(); |
| 50 | + api = apiStub(data); |
| 51 | + sandbox.cli(api); |
| 52 | + outcome = api.readLogs(); |
| 53 | + |
| 54 | + for (i; i < expectingLen; i += 1) { |
| 55 | + exp = expecting[i]; |
| 56 | + out = outcome[i]; |
| 57 | + |
| 58 | + if ( typeof out === "string") { |
| 59 | + out = /^.*/.exec(out.trim())[0]; |
| 60 | + } |
| 61 | + if ( exp !== out ) { |
| 62 | + Assert.fail("Expecting: " + exp + " Got: " + out); |
| 63 | + } |
| 64 | + } |
| 65 | + Assert.pass(); |
| 66 | + |
| 67 | + } |
| 68 | + })); |
| 69 | + })(suiteix); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + YUITest.TestRunner.add(suite); |
| 74 | +})(); |
0 commit comments