browser_gcli_exec.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /*
  2. * Copyright 2012, Mozilla Foundation and contributors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. "use strict";
  17. // THIS FILE IS GENERATED FROM SOURCE IN THE GCLI PROJECT
  18. // PLEASE TALK TO SOMEONE IN DEVELOPER TOOLS BEFORE EDITING IT
  19. const exports = {};
  20. function test() {
  21. helpers.runTestModule(exports, "browser_gcli_exec.js");
  22. }
  23. // var assert = require('../testharness/assert');
  24. // var helpers = require('./helpers');
  25. exports.testParamGroup = function (options) {
  26. var tsg = options.requisition.system.commands.get("tsg");
  27. assert.is(tsg.params[0].groupName, null, "tsg param 0 group null");
  28. assert.is(tsg.params[1].groupName, "First", "tsg param 1 group First");
  29. assert.is(tsg.params[2].groupName, "First", "tsg param 2 group First");
  30. assert.is(tsg.params[3].groupName, "Second", "tsg param 3 group Second");
  31. assert.is(tsg.params[4].groupName, "Second", "tsg param 4 group Second");
  32. };
  33. exports.testWithHelpers = function (options) {
  34. return helpers.audit(options, [
  35. {
  36. setup: "tss",
  37. check: {
  38. input: "tss",
  39. hints: "",
  40. markup: "VVV",
  41. cursor: 3,
  42. current: "__command",
  43. status: "VALID",
  44. unassigned: [ ],
  45. args: {
  46. command: { name: "tss" },
  47. }
  48. },
  49. exec: {
  50. output: /^Exec: tss/,
  51. }
  52. },
  53. {
  54. setup: "tsv option1 10",
  55. check: {
  56. input: "tsv option1 10",
  57. hints: "",
  58. markup: "VVVVVVVVVVVVVV",
  59. cursor: 14,
  60. current: "optionValue",
  61. status: "VALID",
  62. predictions: [ ],
  63. unassigned: [ ],
  64. args: {
  65. command: { name: "tsv" },
  66. optionType: {
  67. value: "string",
  68. arg: " option1",
  69. status: "VALID",
  70. message: ""
  71. },
  72. optionValue: {
  73. arg: " 10",
  74. status: "VALID",
  75. message: ""
  76. }
  77. }
  78. },
  79. exec: {
  80. output: "Exec: tsv optionType=option1 optionValue=10"
  81. }
  82. },
  83. {
  84. setup: "tsv option2 10",
  85. check: {
  86. input: "tsv option2 10",
  87. hints: "",
  88. markup: "VVVVVVVVVVVVVV",
  89. cursor: 14,
  90. current: "optionValue",
  91. status: "VALID",
  92. predictions: [ ],
  93. unassigned: [ ],
  94. args: {
  95. command: { name: "tsv" },
  96. optionType: {
  97. value: "number",
  98. arg: " option2",
  99. status: "VALID",
  100. message: ""
  101. },
  102. optionValue: {
  103. arg: " 10",
  104. status: "VALID",
  105. message: ""
  106. }
  107. }
  108. },
  109. exec: {
  110. output: "Exec: tsv optionType=option2 optionValue=10"
  111. }
  112. },
  113. // Delegated remote types can't transfer value types so we only test for
  114. // the value of optionValue when we're local
  115. {
  116. skipIf: options.isRemote,
  117. setup: "tsv option1 10",
  118. check: {
  119. args: { optionValue: { value: "10" } }
  120. },
  121. exec: {
  122. output: "Exec: tsv optionType=option1 optionValue=10"
  123. }
  124. },
  125. {
  126. skipIf: options.isRemote,
  127. setup: "tsv option2 10",
  128. check: {
  129. args: { optionValue: { value: 10 } }
  130. },
  131. exec: {
  132. output: "Exec: tsv optionType=option2 optionValue=10"
  133. }
  134. }
  135. ]);
  136. };
  137. exports.testExecText = function (options) {
  138. return helpers.audit(options, [
  139. {
  140. setup: "tsr fred",
  141. check: {
  142. input: "tsr fred",
  143. hints: "",
  144. markup: "VVVVVVVV",
  145. cursor: 8,
  146. current: "text",
  147. status: "VALID",
  148. predictions: [ ],
  149. unassigned: [ ],
  150. args: {
  151. command: { name: "tsr" },
  152. text: {
  153. value: "fred",
  154. arg: " fred",
  155. status: "VALID",
  156. message: ""
  157. }
  158. }
  159. },
  160. exec: {
  161. output: "Exec: tsr text=fred"
  162. }
  163. },
  164. {
  165. setup: "tsr fred bloggs",
  166. check: {
  167. input: "tsr fred bloggs",
  168. hints: "",
  169. markup: "VVVVVVVVVVVVVVV",
  170. cursor: 15,
  171. current: "text",
  172. status: "VALID",
  173. predictions: [ ],
  174. unassigned: [ ],
  175. args: {
  176. command: { name: "tsr" },
  177. text: {
  178. value: "fred bloggs",
  179. arg: " fred bloggs",
  180. status: "VALID",
  181. message: ""
  182. }
  183. }
  184. },
  185. exec: {
  186. output: "Exec: tsr text=fred\\ bloggs"
  187. }
  188. },
  189. {
  190. setup: 'tsr "fred bloggs"',
  191. check: {
  192. input: 'tsr "fred bloggs"',
  193. hints: "",
  194. markup: "VVVVVVVVVVVVVVVVV",
  195. cursor: 17,
  196. current: "text",
  197. status: "VALID",
  198. predictions: [ ],
  199. unassigned: [ ],
  200. args: {
  201. command: { name: "tsr" },
  202. text: {
  203. value: "fred bloggs",
  204. arg: ' "fred bloggs"',
  205. status: "VALID",
  206. message: ""
  207. }
  208. }
  209. },
  210. exec: {
  211. output: "Exec: tsr text=fred\\ bloggs"
  212. }
  213. },
  214. {
  215. setup: 'tsr "fred bloggs',
  216. check: {
  217. input: 'tsr "fred bloggs',
  218. hints: "",
  219. markup: "VVVVVVVVVVVVVVVV",
  220. cursor: 16,
  221. current: "text",
  222. status: "VALID",
  223. predictions: [ ],
  224. unassigned: [ ],
  225. args: {
  226. command: { name: "tsr" },
  227. text: {
  228. value: "fred bloggs",
  229. arg: ' "fred bloggs',
  230. status: "VALID",
  231. message: ""
  232. }
  233. }
  234. },
  235. exec: {
  236. output: "Exec: tsr text=fred\\ bloggs"
  237. }
  238. }
  239. ]);
  240. };
  241. exports.testExecBoolean = function (options) {
  242. return helpers.audit(options, [
  243. {
  244. setup: "tsb",
  245. check: {
  246. input: "tsb",
  247. hints: " [toggle]",
  248. markup: "VVV",
  249. cursor: 3,
  250. current: "__command",
  251. status: "VALID",
  252. predictions: [ ],
  253. unassigned: [ ],
  254. args: {
  255. command: { name: "tsb" },
  256. toggle: {
  257. value: false,
  258. arg: "",
  259. status: "VALID",
  260. message: ""
  261. }
  262. }
  263. },
  264. exec: {
  265. output: "Exec: tsb toggle=false"
  266. }
  267. },
  268. {
  269. setup: "tsb --toggle",
  270. check: {
  271. input: "tsb --toggle",
  272. hints: "",
  273. markup: "VVVVVVVVVVVV",
  274. cursor: 12,
  275. current: "toggle",
  276. status: "VALID",
  277. predictions: [ ],
  278. unassigned: [ ],
  279. outputState: "false:default",
  280. args: {
  281. command: { name: "tsb" },
  282. toggle: {
  283. value: true,
  284. arg: " --toggle",
  285. status: "VALID",
  286. message: ""
  287. }
  288. }
  289. },
  290. exec: {
  291. output: "Exec: tsb toggle=true"
  292. }
  293. }
  294. ]);
  295. };
  296. exports.testExecNumber = function (options) {
  297. return helpers.audit(options, [
  298. {
  299. setup: "tsu 10",
  300. check: {
  301. input: "tsu 10",
  302. hints: "",
  303. markup: "VVVVVV",
  304. cursor: 6,
  305. current: "num",
  306. status: "VALID",
  307. predictions: [ ],
  308. unassigned: [ ],
  309. args: {
  310. command: { name: "tsu" },
  311. num: { value: 10, arg: " 10", status: "VALID", message: "" }
  312. }
  313. },
  314. exec: {
  315. output: "Exec: tsu num=10"
  316. }
  317. },
  318. {
  319. setup: "tsu --num 10",
  320. check: {
  321. input: "tsu --num 10",
  322. hints: "",
  323. markup: "VVVVVVVVVVVV",
  324. cursor: 12,
  325. current: "num",
  326. status: "VALID",
  327. predictions: [ ],
  328. unassigned: [ ],
  329. args: {
  330. command: { name: "tsu" },
  331. num: { value: 10, arg: " --num 10", status: "VALID", message: "" }
  332. }
  333. },
  334. exec: {
  335. output: "Exec: tsu num=10"
  336. }
  337. }
  338. ]);
  339. };
  340. exports.testExecScript = function (options) {
  341. return helpers.audit(options, [
  342. {
  343. // Bug 704829 - Enable GCLI Javascript parameters
  344. // The answer to this should be 2
  345. setup: "tsj { 1 + 1 }",
  346. check: {
  347. input: "tsj { 1 + 1 }",
  348. hints: "",
  349. markup: "VVVVVVVVVVVVV",
  350. cursor: 13,
  351. current: "javascript",
  352. status: "VALID",
  353. predictions: [ ],
  354. unassigned: [ ],
  355. args: {
  356. command: { name: "tsj" },
  357. javascript: {
  358. arg: " { 1 + 1 }",
  359. status: "VALID",
  360. message: ""
  361. }
  362. }
  363. },
  364. exec: {
  365. output: "Exec: tsj javascript=1 + 1"
  366. }
  367. }
  368. ]);
  369. };
  370. exports.testExecNode = function (options) {
  371. return helpers.audit(options, [
  372. {
  373. skipIf: options.isRemote,
  374. setup: "tse :root",
  375. check: {
  376. input: "tse :root",
  377. hints: " [options]",
  378. markup: "VVVVVVVVV",
  379. cursor: 9,
  380. current: "node",
  381. status: "VALID",
  382. predictions: [ ],
  383. unassigned: [ ],
  384. args: {
  385. command: { name: "tse" },
  386. node: {
  387. arg: " :root",
  388. status: "VALID",
  389. message: ""
  390. },
  391. nodes: {
  392. arg: "",
  393. status: "VALID",
  394. message: ""
  395. },
  396. nodes2: {
  397. arg: "",
  398. status: "VALID",
  399. message: ""
  400. }
  401. }
  402. },
  403. exec: {
  404. output: /^Exec: tse/
  405. },
  406. post: function (output) {
  407. assert.is(output.data.args.node, ":root", "node should be :root");
  408. assert.is(output.data.args.nodes, "Error", "nodes should be Error");
  409. assert.is(output.data.args.nodes2, "Error", "nodes2 should be Error");
  410. }
  411. }
  412. ]);
  413. };
  414. exports.testExecSubCommand = function (options) {
  415. return helpers.audit(options, [
  416. {
  417. setup: "tsn dif fred",
  418. check: {
  419. input: "tsn dif fred",
  420. hints: "",
  421. markup: "VVVVVVVVVVVV",
  422. cursor: 12,
  423. current: "text",
  424. status: "VALID",
  425. predictions: [ ],
  426. unassigned: [ ],
  427. args: {
  428. command: { name: "tsn dif" },
  429. text: { value: "fred", arg: " fred", status: "VALID", message: "" }
  430. }
  431. },
  432. exec: {
  433. output: "Exec: tsnDif text=fred"
  434. }
  435. },
  436. {
  437. setup: "tsn exten fred",
  438. check: {
  439. input: "tsn exten fred",
  440. hints: "",
  441. markup: "VVVVVVVVVVVVVV",
  442. cursor: 14,
  443. current: "text",
  444. status: "VALID",
  445. predictions: [ ],
  446. unassigned: [ ],
  447. args: {
  448. command: { name: "tsn exten" },
  449. text: { value: "fred", arg: " fred", status: "VALID", message: "" },
  450. }
  451. },
  452. exec: {
  453. output: "Exec: tsnExten text=fred"
  454. }
  455. },
  456. {
  457. setup: "tsn extend fred",
  458. check: {
  459. input: "tsn extend fred",
  460. hints: "",
  461. markup: "VVVVVVVVVVVVVVV",
  462. cursor: 15,
  463. current: "text",
  464. status: "VALID",
  465. predictions: [ ],
  466. unassigned: [ ],
  467. args: {
  468. command: { name: "tsn extend" },
  469. text: { value: "fred", arg: " fred", status: "VALID", message: "" },
  470. }
  471. },
  472. exec: {
  473. output: "Exec: tsnExtend text=fred"
  474. }
  475. }
  476. ]);
  477. };
  478. exports.testExecArray = function (options) {
  479. return helpers.audit(options, [
  480. {
  481. setup: "tselarr 1",
  482. check: {
  483. input: "tselarr 1",
  484. hints: "",
  485. markup: "VVVVVVVVV",
  486. cursor: 9,
  487. current: "num",
  488. status: "VALID",
  489. predictions: ["1"],
  490. unassigned: [ ],
  491. outputState: "false:default",
  492. args: {
  493. command: { name: "tselarr" },
  494. num: { value: "1", arg: " 1", status: "VALID", message: "" },
  495. arr: { /* value:,*/ arg: "{}", status: "VALID", message: "" },
  496. }
  497. },
  498. exec: {
  499. output: "Exec: tselarr num=1 arr="
  500. }
  501. },
  502. {
  503. setup: "tselarr 1 a",
  504. check: {
  505. input: "tselarr 1 a",
  506. hints: "",
  507. markup: "VVVVVVVVVVV",
  508. cursor: 11,
  509. current: "arr",
  510. status: "VALID",
  511. predictions: [ ],
  512. unassigned: [ ],
  513. args: {
  514. command: { name: "tselarr" },
  515. num: { value: "1", arg: " 1", status: "VALID", message: "" },
  516. arr: { /* value:a,*/ arg: "{ a}", status: "VALID", message: "" },
  517. }
  518. },
  519. exec: {
  520. output: "Exec: tselarr num=1 arr=a"
  521. }
  522. },
  523. {
  524. setup: "tselarr 1 a b",
  525. check: {
  526. input: "tselarr 1 a b",
  527. hints: "",
  528. markup: "VVVVVVVVVVVVV",
  529. cursor: 13,
  530. current: "arr",
  531. status: "VALID",
  532. predictions: [ ],
  533. unassigned: [ ],
  534. args: {
  535. command: { name: "tselarr" },
  536. num: { value: "1", arg: " 1", status: "VALID", message: "" },
  537. arr: { /* value:a,b,*/ arg: "{ a, b}", status: "VALID", message: "" },
  538. }
  539. },
  540. exec: {
  541. output: "Exec: tselarr num=1 arr=a b"
  542. }
  543. }
  544. ]);
  545. };
  546. exports.testExecMultiple = function (options) {
  547. return helpers.audit(options, [
  548. {
  549. setup: "tsm a 10 10",
  550. check: {
  551. input: "tsm a 10 10",
  552. hints: "",
  553. markup: "VVVVVVVVVVV",
  554. cursor: 11,
  555. current: "num",
  556. status: "VALID",
  557. predictions: [ ],
  558. unassigned: [ ],
  559. args: {
  560. command: { name: "tsm" },
  561. abc: { value: "a", arg: " a", status: "VALID", message: "" },
  562. txt: { value: "10", arg: " 10", status: "VALID", message: "" },
  563. num: { value: 10, arg: " 10", status: "VALID", message: "" },
  564. }
  565. },
  566. exec: {
  567. output: "Exec: tsm abc=a txt=10 num=10"
  568. }
  569. }
  570. ]);
  571. };
  572. exports.testExecDefaults = function (options) {
  573. return helpers.audit(options, [
  574. {
  575. // Bug 707009 - GCLI doesn't always fill in default parameters properly
  576. setup: "tsg aaa",
  577. check: {
  578. input: "tsg aaa",
  579. hints: " [options]",
  580. markup: "VVVVVVV",
  581. cursor: 7,
  582. current: "solo",
  583. status: "VALID",
  584. predictions: ["aaa"],
  585. unassigned: [ ],
  586. args: {
  587. command: { name: "tsg" },
  588. solo: { value: "aaa", arg: " aaa", status: "VALID", message: "" },
  589. txt1: { value: undefined, arg: "", status: "VALID", message: "" },
  590. bool: { value: false, arg: "", status: "VALID", message: "" },
  591. txt2: { value: undefined, arg: "", status: "VALID", message: "" },
  592. num: { value: undefined, arg: "", status: "VALID", message: "" },
  593. }
  594. },
  595. exec: {
  596. output: "Exec: tsg solo=aaa txt1= bool=false txt2=d num=42"
  597. }
  598. }
  599. ]);
  600. };
  601. exports.testNested = function (options) {
  602. var commands = options.requisition.system.commands;
  603. commands.add({
  604. name: "nestorama",
  605. exec: function (args, context) {
  606. return context.updateExec("tsb").then(function (tsbOutput) {
  607. return context.updateExec("tsu 6").then(function (tsuOutput) {
  608. return JSON.stringify({
  609. tsb: tsbOutput.data,
  610. tsu: tsuOutput.data
  611. });
  612. });
  613. });
  614. }
  615. });
  616. return helpers.audit(options, [
  617. {
  618. setup: "nestorama",
  619. exec: {
  620. output:
  621. "{" +
  622. '"tsb":{' +
  623. '"name":"tsb",' +
  624. '"args":{"toggle":"false"}' +
  625. "}," +
  626. '"tsu":{' +
  627. '"name":"tsu",' +
  628. '"args":{"num":"6"}' +
  629. "}" +
  630. "}"
  631. },
  632. post: function () {
  633. commands.remove("nestorama");
  634. }
  635. }
  636. ]);
  637. };