github.com/getgauge/gauge@v1.6.9/reporter/jsonConsole_test.go (about) 1 /*---------------------------------------------------------------- 2 * Copyright (c) ThoughtWorks, Inc. 3 * Licensed under the Apache License, Version 2.0 4 * See LICENSE in the project root for license information. 5 *----------------------------------------------------------------*/ 6 7 package reporter 8 9 import ( 10 "github.com/getgauge/gauge-proto/go/gauge_messages" 11 "github.com/getgauge/gauge/execution/result" 12 "github.com/getgauge/gauge/gauge" 13 . "gopkg.in/check.v1" 14 ) 15 16 func setupJSONConsole() (*dummyWriter, *jsonConsole) { 17 dw := newDummyWriter() 18 console := newJSONConsole(dw, false, 0) 19 return dw, console 20 } 21 22 func (s *MySuite) TestSpecStart_JSONConsole(c *C) { 23 dw, jc := setupJSONConsole() 24 protoSpec := &gauge_messages.ProtoSpec{ 25 FileName: "file", 26 SpecHeading: "Specification", 27 } 28 scenarios := []*gauge.Scenario{ 29 { 30 Heading: &gauge.Heading{ 31 Value: "Scenario", 32 LineNo: 2, 33 HeadingType: 1, 34 }, 35 }, 36 } 37 spec := &gauge.Specification{ 38 FileName: "file", 39 Heading: &gauge.Heading{ 40 Value: "Specification", 41 LineNo: 1, 42 HeadingType: 0, 43 }, 44 Scenarios: scenarios, 45 } 46 47 expected := `{"type":"specStart","id":"file","name":"Specification","filename":"file","line":1} 48 ` 49 jc.SpecStart(spec, &result.SpecResult{Skipped: false, ProtoSpec: protoSpec}) 50 c.Assert(dw.output, Equals, expected) 51 } 52 53 func (s *MySuite) TestScenarioStart_JSONConsole(c *C) { 54 dw, jc := setupJSONConsole() 55 56 scenario := &gauge.Scenario{ 57 Heading: &gauge.Heading{ 58 Value: "Scenario", 59 LineNo: 2, 60 HeadingType: 1, 61 }, 62 Span: &gauge.Span{ 63 Start: 2, 64 End: 3, 65 }, 66 } 67 68 info := &gauge_messages.ExecutionInfo{ 69 CurrentSpec: &gauge_messages.SpecInfo{ 70 Name: "Specification", 71 FileName: "file", 72 IsFailed: false, 73 }, 74 CurrentScenario: &gauge_messages.ScenarioInfo{ 75 Name: "Scenario", 76 IsFailed: false, 77 }, 78 } 79 80 expected := `{"type":"scenarioStart","id":"file:2","parentId":"file","name":"Scenario","filename":"file","line":2,"result":{"time":0}} 81 ` 82 jc.ScenarioStart(scenario, info, &result.ScenarioResult{}) 83 c.Assert(dw.output, Equals, expected) 84 } 85 86 func (s *MySuite) TestScenarioEnd_JSONConsole(c *C) { 87 dw, jc := setupJSONConsole() 88 89 protoScenario := &gauge_messages.ProtoScenario{ 90 ScenarioHeading: "Scenario", 91 Failed: false, 92 } 93 94 scenario := &gauge.Scenario{ 95 Heading: &gauge.Heading{ 96 Value: "Scenario", 97 LineNo: 2, 98 HeadingType: 1, 99 }, 100 Span: &gauge.Span{ 101 Start: 2, 102 End: 3, 103 }, 104 } 105 106 info := &gauge_messages.ExecutionInfo{ 107 CurrentSpec: &gauge_messages.SpecInfo{ 108 Name: "Specification", 109 FileName: "file", 110 IsFailed: false, 111 }, 112 CurrentScenario: &gauge_messages.ScenarioInfo{ 113 Name: "Scenario", 114 IsFailed: false, 115 }, 116 } 117 118 expected := `{"type":"scenarioEnd","id":"file:2","parentId":"file","name":"Scenario","filename":"file","line":2,"result":{"status":"pass","time":0}} 119 ` 120 121 jc.ScenarioEnd(scenario, &result.ScenarioResult{ProtoScenario: protoScenario}, info) 122 c.Assert(dw.output, Equals, expected) 123 } 124 125 func (s *MySuite) TestScenarioEndWithPreHookFailure_JSONConsole(c *C) { 126 dw, jc := setupJSONConsole() 127 128 protoScenario := &gauge_messages.ProtoScenario{ 129 ScenarioHeading: "Scenario", 130 Failed: true, 131 PreHookFailure: &gauge_messages.ProtoHookFailure{ 132 StackTrace: "stacktrace", 133 ErrorMessage: "message", 134 }, 135 ExecutionStatus: gauge_messages.ExecutionStatus_FAILED, 136 } 137 138 scenario := &gauge.Scenario{ 139 Heading: &gauge.Heading{ 140 Value: "Scenario", 141 LineNo: 2, 142 HeadingType: 1, 143 }, 144 Span: &gauge.Span{ 145 Start: 2, 146 End: 3, 147 }, 148 } 149 150 info := &gauge_messages.ExecutionInfo{ 151 CurrentSpec: &gauge_messages.SpecInfo{ 152 Name: "Specification", 153 FileName: "file", 154 IsFailed: true, 155 }, 156 CurrentScenario: &gauge_messages.ScenarioInfo{ 157 Name: "Scenario", 158 IsFailed: true, 159 }, 160 } 161 162 expected := `{"type":"scenarioEnd","id":"file:2","parentId":"file","name":"Scenario","filename":"file","line":2,"result":{"status":"fail","time":0,"beforeHookFailure":{"text":"Before Scenario","filename":"","message":"message","lineNo":"","stackTrace":"stacktrace"}}} 163 ` 164 165 jc.ScenarioEnd(scenario, &result.ScenarioResult{ProtoScenario: protoScenario}, info) 166 c.Assert(dw.output, Equals, expected) 167 } 168 169 func (s *MySuite) TestScenarioEndWithPostHookFailure_JSONConsole(c *C) { 170 dw, jc := setupJSONConsole() 171 172 protoScenario := &gauge_messages.ProtoScenario{ 173 ScenarioHeading: "Scenario", 174 Failed: true, 175 PostHookFailure: &gauge_messages.ProtoHookFailure{ 176 StackTrace: "stacktrace", 177 ErrorMessage: "message", 178 }, 179 ExecutionStatus: gauge_messages.ExecutionStatus_PASSED, 180 } 181 182 scenario := &gauge.Scenario{ 183 Heading: &gauge.Heading{ 184 Value: "Scenario", 185 LineNo: 2, 186 HeadingType: 1, 187 }, 188 Span: &gauge.Span{ 189 Start: 2, 190 End: 3, 191 }, 192 } 193 194 info := &gauge_messages.ExecutionInfo{ 195 CurrentSpec: &gauge_messages.SpecInfo{ 196 Name: "Specification", 197 FileName: "file", 198 IsFailed: true, 199 }, 200 CurrentScenario: &gauge_messages.ScenarioInfo{ 201 Name: "Scenario", 202 IsFailed: true, 203 }, 204 } 205 206 expected := `{"type":"scenarioEnd","id":"file:2","parentId":"file","name":"Scenario","filename":"file","line":2,"result":{"status":"pass","time":0,"afterHookFailure":{"text":"After Scenario","filename":"","message":"message","lineNo":"","stackTrace":"stacktrace"}}} 207 ` 208 209 jc.ScenarioEnd(scenario, &result.ScenarioResult{ProtoScenario: protoScenario}, info) 210 c.Assert(dw.output, Equals, expected) 211 } 212 213 func (s *MySuite) TestScenarioEndWithPreAndPostHookFailure_JSONConsole(c *C) { 214 dw, jc := setupJSONConsole() 215 216 protoScenario := &gauge_messages.ProtoScenario{ 217 ScenarioHeading: "Scenario", 218 Failed: true, 219 PreHookFailure: &gauge_messages.ProtoHookFailure{ 220 StackTrace: "stacktrace", 221 ErrorMessage: "message", 222 }, 223 PostHookFailure: &gauge_messages.ProtoHookFailure{ 224 StackTrace: "stacktrace", 225 ErrorMessage: "message", 226 }, 227 ExecutionStatus: gauge_messages.ExecutionStatus_FAILED, 228 } 229 230 scenario := &gauge.Scenario{ 231 Heading: &gauge.Heading{ 232 Value: "Scenario", 233 LineNo: 2, 234 HeadingType: 1, 235 }, 236 Span: &gauge.Span{ 237 Start: 2, 238 End: 3, 239 }, 240 } 241 242 info := &gauge_messages.ExecutionInfo{ 243 CurrentSpec: &gauge_messages.SpecInfo{ 244 Name: "Specification", 245 FileName: "file", 246 IsFailed: true, 247 }, 248 CurrentScenario: &gauge_messages.ScenarioInfo{ 249 Name: "Scenario", 250 IsFailed: true, 251 }, 252 } 253 254 expected := `{"type":"scenarioEnd","id":"file:2","parentId":"file","name":"Scenario","filename":"file","line":2,"result":{"status":"fail","time":0,"beforeHookFailure":{"text":"Before Scenario","filename":"","message":"message","lineNo":"","stackTrace":"stacktrace"},"afterHookFailure":{"text":"After Scenario","filename":"","message":"message","lineNo":"","stackTrace":"stacktrace"}}} 255 ` 256 257 jc.ScenarioEnd(scenario, &result.ScenarioResult{ProtoScenario: protoScenario}, info) 258 c.Assert(dw.output, Equals, expected) 259 } 260 261 func (s *MySuite) TestScenarioEndWithBeforeStepHookFailure_JSONConsole(c *C) { 262 dw, jc := setupJSONConsole() 263 264 protoScenario := &gauge_messages.ProtoScenario{ 265 ScenarioHeading: "Scenario", 266 Failed: true, 267 ScenarioItems: []*gauge_messages.ProtoItem{ 268 { 269 ItemType: gauge_messages.ProtoItem_Step, 270 Step: &gauge_messages.ProtoStep{ 271 ActualText: "Step", 272 ParsedText: "Step", 273 StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ 274 PreHookFailure: &gauge_messages.ProtoHookFailure{ 275 ErrorMessage: "message", 276 StackTrace: "stacktrace", 277 }, 278 }, 279 }, 280 }, 281 }, 282 ExecutionStatus: gauge_messages.ExecutionStatus_FAILED, 283 } 284 285 scenario := &gauge.Scenario{ 286 Heading: &gauge.Heading{ 287 Value: "Scenario", 288 LineNo: 2, 289 HeadingType: 1, 290 }, 291 Span: &gauge.Span{ 292 Start: 2, 293 End: 3, 294 }, 295 } 296 297 info := &gauge_messages.ExecutionInfo{ 298 CurrentSpec: &gauge_messages.SpecInfo{ 299 Name: "Specification", 300 FileName: "file", 301 IsFailed: true, 302 }, 303 CurrentScenario: &gauge_messages.ScenarioInfo{ 304 Name: "Scenario", 305 IsFailed: true, 306 }, 307 } 308 309 expected := `{"type":"scenarioEnd","id":"file:2","parentId":"file","name":"Scenario","filename":"file","line":2,"result":{"status":"fail","time":0,"errors":[{"text":"BeforeStep hook for step: Step","filename":"","message":"message","lineNo":"","stackTrace":"stacktrace"}]}} 310 ` 311 312 jc.ScenarioEnd(scenario, &result.ScenarioResult{ProtoScenario: protoScenario}, info) 313 c.Assert(dw.output, Equals, expected) 314 } 315 316 func (s *MySuite) TestScenarioEndWithStepFailure_JSONConsole(c *C) { 317 dw, jc := setupJSONConsole() 318 319 protoStep := &gauge_messages.ProtoStep{ 320 ActualText: "Step", 321 ParsedText: "Step", 322 StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ 323 ExecutionResult: &gauge_messages.ProtoExecutionResult{ 324 Failed: true, 325 ErrorMessage: "message", 326 StackTrace: "stacktrace", 327 }, 328 }, 329 } 330 331 protoScenario := &gauge_messages.ProtoScenario{ 332 ScenarioHeading: "Scenario", 333 Failed: true, 334 ScenarioItems: []*gauge_messages.ProtoItem{ 335 { 336 ItemType: gauge_messages.ProtoItem_Step, 337 Step: protoStep, 338 }, 339 }, 340 ExecutionStatus: gauge_messages.ExecutionStatus_FAILED, 341 } 342 343 scenario := &gauge.Scenario{ 344 Heading: &gauge.Heading{ 345 Value: "Scenario", 346 LineNo: 2, 347 HeadingType: 1, 348 }, 349 Span: &gauge.Span{ 350 Start: 2, 351 End: 3, 352 }, 353 } 354 355 info := &gauge_messages.ExecutionInfo{ 356 CurrentSpec: &gauge_messages.SpecInfo{ 357 Name: "Specification", 358 FileName: "file", 359 IsFailed: false, 360 }, 361 CurrentScenario: &gauge_messages.ScenarioInfo{ 362 Name: "Scenario", 363 IsFailed: false, 364 }, 365 CurrentStep: &gauge_messages.StepInfo{ 366 Step: &gauge_messages.ExecuteStepRequest{ 367 ActualStepText: "Step", 368 ParsedStepText: "Step", 369 ScenarioFailing: false, 370 }, 371 IsFailed: false, 372 StackTrace: "stacktrace", 373 }, 374 } 375 376 step := gauge.Step{ 377 Value: "Step", 378 LineNo: 4, 379 LineText: "Step", 380 IsConcept: false, 381 Parent: nil, 382 } 383 384 res := result.NewStepResult(protoStep) 385 res.StepFailed = false 386 jc.StepEnd(step, res, info) 387 jc.ScenarioEnd(scenario, &result.ScenarioResult{ProtoScenario: protoScenario}, info) 388 389 expected := `{"type":"scenarioEnd","id":"file:2","parentId":"file","name":"Scenario","filename":"file","line":2,"result":{"status":"fail","time":0,"errors":[{"text":"Step","filename":"","message":"message","lineNo":"4","stackTrace":"stacktrace"}]}} 390 ` 391 392 c.Assert(dw.output, Equals, expected) 393 } 394 395 func (s *MySuite) TestScenarioEndWithConceptFailure_JSONConsole(c *C) { 396 dw, jc := setupJSONConsole() 397 398 protoStep := &gauge_messages.ProtoStep{ 399 ActualText: "Step", 400 ParsedText: "Step", 401 StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ 402 ExecutionResult: &gauge_messages.ProtoExecutionResult{ 403 Failed: true, 404 ErrorMessage: "message", 405 StackTrace: "stacktrace", 406 }, 407 }, 408 } 409 410 protoScenario := &gauge_messages.ProtoScenario{ 411 ScenarioHeading: "Scenario", 412 Failed: true, 413 ScenarioItems: []*gauge_messages.ProtoItem{ 414 { 415 ItemType: gauge_messages.ProtoItem_Step, 416 Step: protoStep, 417 }, 418 }, 419 ExecutionStatus: gauge_messages.ExecutionStatus_FAILED, 420 } 421 422 scenario := &gauge.Scenario{ 423 Heading: &gauge.Heading{ 424 Value: "Scenario", 425 LineNo: 2, 426 HeadingType: 1, 427 }, 428 Span: &gauge.Span{ 429 Start: 2, 430 End: 3, 431 }, 432 } 433 434 info := &gauge_messages.ExecutionInfo{ 435 CurrentSpec: &gauge_messages.SpecInfo{ 436 Name: "Specification", 437 FileName: "file", 438 IsFailed: false, 439 }, 440 CurrentScenario: &gauge_messages.ScenarioInfo{ 441 Name: "Scenario", 442 IsFailed: false, 443 }, 444 CurrentStep: &gauge_messages.StepInfo{ 445 Step: &gauge_messages.ExecuteStepRequest{ 446 ActualStepText: "Step", 447 ParsedStepText: "Step", 448 ScenarioFailing: false, 449 }, 450 IsFailed: false, 451 StackTrace: "stacktrace", 452 }, 453 } 454 455 step := gauge.Step{ 456 Value: "Step", 457 LineNo: 4, 458 LineText: "Step", 459 IsConcept: true, 460 Parent: nil, 461 } 462 463 step2 := gauge.Step{ 464 Value: "Step 2", 465 LineNo: 2, 466 LineText: "Step 2", 467 IsConcept: false, 468 Parent: &step, 469 } 470 471 step.ConceptSteps = []*gauge.Step{&step2} 472 473 res := result.NewStepResult(protoStep) 474 res.StepFailed = false 475 jc.StepEnd(step2, res, info) 476 jc.ScenarioEnd(scenario, &result.ScenarioResult{ProtoScenario: protoScenario}, info) 477 478 expected := `{"type":"scenarioEnd","id":"file:2","parentId":"file","name":"Scenario","filename":"file","line":2,"result":{"status":"fail","time":0,"errors":[{"text":"Step","filename":"","message":"message","lineNo":"2","stackTrace":"stacktrace"}]}} 479 ` 480 481 c.Assert(dw.output, Equals, expected) 482 } 483 484 func (s *MySuite) TestScenarioEndWithAfterStepHookFailure_JSONConsole(c *C) { 485 dw, jc := setupJSONConsole() 486 487 protoScenario := &gauge_messages.ProtoScenario{ 488 ScenarioHeading: "Scenario", 489 Failed: true, 490 ScenarioItems: []*gauge_messages.ProtoItem{ 491 { 492 ItemType: gauge_messages.ProtoItem_Step, 493 Step: &gauge_messages.ProtoStep{ 494 ActualText: "Step", 495 ParsedText: "Step", 496 StepExecutionResult: &gauge_messages.ProtoStepExecutionResult{ 497 PostHookFailure: &gauge_messages.ProtoHookFailure{ 498 ErrorMessage: "message", 499 StackTrace: "stacktrace", 500 }, 501 }, 502 }, 503 }, 504 }, 505 ExecutionStatus: gauge_messages.ExecutionStatus_FAILED, 506 } 507 508 scenario := &gauge.Scenario{ 509 Heading: &gauge.Heading{ 510 Value: "Scenario", 511 LineNo: 2, 512 HeadingType: 1, 513 }, 514 Span: &gauge.Span{ 515 Start: 2, 516 End: 3, 517 }, 518 } 519 520 info := &gauge_messages.ExecutionInfo{ 521 CurrentSpec: &gauge_messages.SpecInfo{ 522 Name: "Specification", 523 FileName: "file", 524 IsFailed: true, 525 }, 526 CurrentScenario: &gauge_messages.ScenarioInfo{ 527 Name: "Scenario", 528 IsFailed: true, 529 }, 530 } 531 532 expected := `{"type":"scenarioEnd","id":"file:2","parentId":"file","name":"Scenario","filename":"file","line":2,"result":{"status":"fail","time":0,"errors":[{"text":"AfterStep hook for step: Step","filename":"","message":"message","lineNo":"","stackTrace":"stacktrace"}]}} 533 ` 534 535 jc.ScenarioEnd(scenario, &result.ScenarioResult{ProtoScenario: protoScenario}, info) 536 c.Assert(dw.output, Equals, expected) 537 } 538 539 func (s *MySuite) TestSpecEnd_JSONConsole(c *C) { 540 dw, jc := setupJSONConsole() 541 protoSpec := &gauge_messages.ProtoSpec{ 542 FileName: "file", 543 SpecHeading: "Specification", 544 } 545 scenarios := []*gauge.Scenario{ 546 { 547 Heading: &gauge.Heading{ 548 Value: "Scenario", 549 LineNo: 2, 550 HeadingType: 1, 551 }, 552 }, 553 } 554 spec := &gauge.Specification{ 555 FileName: "file", 556 Heading: &gauge.Heading{ 557 Value: "Specification", 558 LineNo: 1, 559 HeadingType: 0, 560 }, 561 Scenarios: scenarios, 562 } 563 expected := `{"type":"specEnd","id":"file","name":"Specification","filename":"file","line":1,"result":{"status":"pass","time":0}} 564 ` 565 jc.SpecEnd(spec, &result.SpecResult{ProtoSpec: protoSpec}) 566 c.Assert(dw.output, Equals, expected) 567 } 568 569 func (s *MySuite) TestSpecEndWithPreHookFailure_JSONConsole(c *C) { 570 dw, jc := setupJSONConsole() 571 protoSpec := &gauge_messages.ProtoSpec{ 572 FileName: "file", 573 SpecHeading: "Specification", 574 PreHookFailures: []*gauge_messages.ProtoHookFailure{ 575 { 576 StackTrace: "stacktrace", 577 ErrorMessage: "message", 578 }, 579 }, 580 } 581 scenarios := []*gauge.Scenario{ 582 { 583 Heading: &gauge.Heading{ 584 Value: "Scenario", 585 LineNo: 2, 586 HeadingType: 1, 587 }, 588 }, 589 } 590 spec := &gauge.Specification{ 591 FileName: "file", 592 Heading: &gauge.Heading{ 593 Value: "Specification", 594 LineNo: 1, 595 HeadingType: 0, 596 }, 597 Scenarios: scenarios, 598 } 599 expected := `{"type":"specEnd","id":"file","name":"Specification","filename":"file","line":1,"result":{"status":"fail","time":0,"beforeHookFailure":{"text":"Before Specification","filename":"","message":"message","lineNo":"","stackTrace":"stacktrace"}}} 600 ` 601 res := &result.SpecResult{ 602 ProtoSpec: protoSpec, 603 IsFailed: true, 604 } 605 606 jc.SpecEnd(spec, res) 607 c.Assert(dw.output, Equals, expected) 608 } 609 610 func (s *MySuite) TestSpecEndWithPostHookFailure_JSONConsole(c *C) { 611 dw, jc := setupJSONConsole() 612 protoSpec := &gauge_messages.ProtoSpec{ 613 FileName: "file", 614 SpecHeading: "Specification", 615 PostHookFailures: []*gauge_messages.ProtoHookFailure{ 616 { 617 StackTrace: "stacktrace", 618 ErrorMessage: "message", 619 }, 620 }, 621 } 622 scenarios := []*gauge.Scenario{ 623 { 624 Heading: &gauge.Heading{ 625 Value: "Scenario", 626 LineNo: 2, 627 HeadingType: 1, 628 }, 629 }, 630 } 631 spec := &gauge.Specification{ 632 FileName: "file", 633 Heading: &gauge.Heading{ 634 Value: "Specification", 635 LineNo: 1, 636 HeadingType: 0, 637 }, 638 Scenarios: scenarios, 639 } 640 expected := `{"type":"specEnd","id":"file","name":"Specification","filename":"file","line":1,"result":{"status":"fail","time":0,"afterHookFailure":{"text":"After Specification","filename":"","message":"message","lineNo":"","stackTrace":"stacktrace"}}} 641 ` 642 res := &result.SpecResult{ 643 ProtoSpec: protoSpec, 644 IsFailed: true, 645 } 646 647 jc.SpecEnd(spec, res) 648 c.Assert(dw.output, Equals, expected) 649 } 650 651 func (s *MySuite) TestSpecEndWithPreAndPostHookFailure_JSONConsole(c *C) { 652 dw, jc := setupJSONConsole() 653 protoSpec := &gauge_messages.ProtoSpec{ 654 FileName: "file", 655 SpecHeading: "Specification", 656 PreHookFailures: []*gauge_messages.ProtoHookFailure{ 657 { 658 StackTrace: "stacktrace", 659 ErrorMessage: "message", 660 }, 661 }, 662 PostHookFailures: []*gauge_messages.ProtoHookFailure{ 663 { 664 StackTrace: "stacktrace", 665 ErrorMessage: "message", 666 }, 667 }, 668 } 669 scenarios := []*gauge.Scenario{ 670 { 671 Heading: &gauge.Heading{ 672 Value: "Scenario", 673 LineNo: 2, 674 HeadingType: 1, 675 }, 676 }, 677 } 678 spec := &gauge.Specification{ 679 FileName: "file", 680 Heading: &gauge.Heading{ 681 Value: "Specification", 682 LineNo: 1, 683 HeadingType: 0, 684 }, 685 Scenarios: scenarios, 686 } 687 expected := `{"type":"specEnd","id":"file","name":"Specification","filename":"file","line":1,"result":{"status":"fail","time":0,"beforeHookFailure":{"text":"Before Specification","filename":"","message":"message","lineNo":"","stackTrace":"stacktrace"},"afterHookFailure":{"text":"After Specification","filename":"","message":"message","lineNo":"","stackTrace":"stacktrace"}}} 688 ` 689 res := &result.SpecResult{ 690 ProtoSpec: protoSpec, 691 IsFailed: true, 692 } 693 694 jc.SpecEnd(spec, res) 695 c.Assert(dw.output, Equals, expected) 696 } 697 698 func (s *MySuite) TestSpecEndWithNoScenariosInSpec_JSONConsole(c *C) { 699 dw, jc := setupJSONConsole() 700 protoSpec := &gauge_messages.ProtoSpec{ 701 FileName: "file", 702 SpecHeading: "Specification", 703 } 704 705 scenarios := []*gauge.Scenario{} 706 707 spec := &gauge.Specification{ 708 FileName: "file", 709 Heading: &gauge.Heading{ 710 Value: "Specification", 711 LineNo: 1, 712 HeadingType: 0, 713 }, 714 Scenarios: scenarios, 715 } 716 expected := `{"type":"specEnd","id":"file","name":"Specification","filename":"file","line":1,"result":{"status":"skip","time":0}} 717 ` 718 res := &result.SpecResult{ 719 ProtoSpec: protoSpec, 720 Skipped: true, 721 } 722 723 jc.SpecEnd(spec, res) 724 c.Assert(dw.output, Equals, expected) 725 } 726 727 func (s *MySuite) TestSuiteEnd_JSONConsole(c *C) { 728 dw, jc := setupJSONConsole() 729 730 jc.SuiteEnd(&result.SuiteResult{}) 731 c.Assert(dw.output, Equals, "{\"type\":\"suiteEnd\",\"result\":{\"status\":\"pass\",\"time\":0}}\n") 732 } 733 734 func (s *MySuite) TestSuiteEndWithBeforeHookFailure_JSONConsole(c *C) { 735 dw, jc := setupJSONConsole() 736 737 res := &result.SuiteResult{ 738 PreSuite: &gauge_messages.ProtoHookFailure{ 739 StackTrace: "stack trace", 740 ErrorMessage: "message", 741 }, 742 IsFailed: true, 743 } 744 expected := `{"type":"suiteEnd","result":{"status":"fail","time":0,"beforeHookFailure":{"text":"Before Suite","filename":"","message":"message","lineNo":"","stackTrace":"stack trace"}}} 745 ` 746 jc.SuiteEnd(res) 747 c.Assert(dw.output, Equals, expected) 748 } 749 750 func (s *MySuite) TestSuiteEndWithAfterHookFailure_JSONConsole(c *C) { 751 dw, jc := setupJSONConsole() 752 753 res := &result.SuiteResult{ 754 PostSuite: &gauge_messages.ProtoHookFailure{ 755 StackTrace: "stack trace", 756 ErrorMessage: "message", 757 }, 758 PreSuite: &gauge_messages.ProtoHookFailure{ 759 StackTrace: "stack trace", 760 ErrorMessage: "message", 761 }, 762 IsFailed: true, 763 } 764 expected := `{"type":"suiteEnd","result":{"status":"fail","time":0,"beforeHookFailure":{"text":"Before Suite","filename":"","message":"message","lineNo":"","stackTrace":"stack trace"},"afterHookFailure":{"text":"After Suite","filename":"","message":"message","lineNo":"","stackTrace":"stack trace"}}} 765 ` 766 jc.SuiteEnd(res) 767 c.Assert(dw.output, Equals, expected) 768 } 769 770 func (s *MySuite) TestSuiteEndWithBeforeAndAfterHookFailure_JSONConsole(c *C) { 771 dw, jc := setupJSONConsole() 772 773 res := &result.SuiteResult{ 774 PostSuite: &gauge_messages.ProtoHookFailure{ 775 StackTrace: "stack trace", 776 ErrorMessage: "message", 777 }, 778 IsFailed: true, 779 } 780 expected := `{"type":"suiteEnd","result":{"status":"fail","time":0,"afterHookFailure":{"text":"After Suite","filename":"","message":"message","lineNo":"","stackTrace":"stack trace"}}} 781 ` 782 jc.SuiteEnd(res) 783 c.Assert(dw.output, Equals, expected) 784 }