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