|
1 | 1 | import * as assert from 'assert';
|
2 | 2 | import { ChildProcess, spawn } from 'child_process';
|
| 3 | +import { debug } from 'console'; |
3 | 4 | import * as fs from 'fs';
|
4 | 5 | import getPort = require('get-port');
|
5 | 6 | import * as http from 'http';
|
@@ -568,6 +569,181 @@ suite('Go Debug Adapter', function () {
|
568 | 569 | });
|
569 | 570 | });
|
570 | 571 |
|
| 572 | + suite('set current working directory', () => { |
| 573 | + test('should debug program with cwd set', async () => { |
| 574 | + const WD = path.join(DATA_ROOT, 'cwdTest'); |
| 575 | + const PROGRAM = path.join(WD, 'cwdTest'); |
| 576 | + const FILE = path.join(PROGRAM, 'main.go'); |
| 577 | + const BREAKPOINT_LINE = 11; |
| 578 | + |
| 579 | + const config = { |
| 580 | + name: 'Launch', |
| 581 | + type: 'go', |
| 582 | + request: 'launch', |
| 583 | + mode: 'auto', |
| 584 | + program: PROGRAM, |
| 585 | + cwd: WD, |
| 586 | + }; |
| 587 | + const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config); |
| 588 | + |
| 589 | + await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE)); |
| 590 | + |
| 591 | + await assertVariableValue('strdat', '"Hello, World!"'); |
| 592 | + }); |
| 593 | + |
| 594 | + test('should debug program without cwd set', async () => { |
| 595 | + const WD = path.join(DATA_ROOT, 'cwdTest'); |
| 596 | + const PROGRAM = path.join(WD, 'cwdTest'); |
| 597 | + const FILE = path.join(PROGRAM, 'main.go'); |
| 598 | + const BREAKPOINT_LINE = 11; |
| 599 | + |
| 600 | + const config = { |
| 601 | + name: 'Launch', |
| 602 | + type: 'go', |
| 603 | + request: 'launch', |
| 604 | + mode: 'auto', |
| 605 | + program: PROGRAM, |
| 606 | + }; |
| 607 | + const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config); |
| 608 | + |
| 609 | + await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE)); |
| 610 | + |
| 611 | + await assertVariableValue('strdat', '"Goodbye, World."'); |
| 612 | + }); |
| 613 | + |
| 614 | + test('should debug file program with cwd set', async () => { |
| 615 | + const WD = path.join(DATA_ROOT, 'cwdTest'); |
| 616 | + const PROGRAM = path.join(WD, 'cwdTest', 'main.go'); |
| 617 | + const FILE = PROGRAM; |
| 618 | + const BREAKPOINT_LINE = 11; |
| 619 | + |
| 620 | + const config = { |
| 621 | + name: 'Launch', |
| 622 | + type: 'go', |
| 623 | + request: 'launch', |
| 624 | + mode: 'auto', |
| 625 | + program: PROGRAM, |
| 626 | + cwd: WD, |
| 627 | + }; |
| 628 | + const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config); |
| 629 | + |
| 630 | + await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE)); |
| 631 | + |
| 632 | + await assertVariableValue('strdat', '"Hello, World!"'); |
| 633 | + }); |
| 634 | + |
| 635 | + test('should debug file program without cwd set', async () => { |
| 636 | + const WD = path.join(DATA_ROOT, 'cwdTest'); |
| 637 | + const PROGRAM = path.join(WD, 'cwdTest', 'main.go'); |
| 638 | + const FILE = PROGRAM; |
| 639 | + const BREAKPOINT_LINE = 11; |
| 640 | + |
| 641 | + const config = { |
| 642 | + name: 'Launch', |
| 643 | + type: 'go', |
| 644 | + request: 'launch', |
| 645 | + mode: 'auto', |
| 646 | + program: PROGRAM, |
| 647 | + }; |
| 648 | + const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config); |
| 649 | + |
| 650 | + await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE)); |
| 651 | + |
| 652 | + await assertVariableValue('strdat', '"Goodbye, World."'); |
| 653 | + }); |
| 654 | + |
| 655 | + test('should run program with cwd set (noDebug)', () => { |
| 656 | + const WD = path.join(DATA_ROOT, 'cwdTest'); |
| 657 | + const PROGRAM = path.join(WD, 'cwdTest'); |
| 658 | + |
| 659 | + const config = { |
| 660 | + name: 'Launch', |
| 661 | + type: 'go', |
| 662 | + request: 'launch', |
| 663 | + mode: 'auto', |
| 664 | + program: PROGRAM, |
| 665 | + cwd: WD, |
| 666 | + noDebug: true |
| 667 | + }; |
| 668 | + const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config); |
| 669 | + |
| 670 | + return Promise.all([ |
| 671 | + dc.launch(debugConfig), |
| 672 | + dc.waitForEvent('output').then((event) => { |
| 673 | + assert.strictEqual(event.body.output, 'Hello, World!\n'); |
| 674 | + }) |
| 675 | + ]); |
| 676 | + }); |
| 677 | + |
| 678 | + test('should run program without cwd set (noDebug)', () => { |
| 679 | + const WD = path.join(DATA_ROOT, 'cwdTest'); |
| 680 | + const PROGRAM = path.join(WD, 'cwdTest'); |
| 681 | + |
| 682 | + const config = { |
| 683 | + name: 'Launch', |
| 684 | + type: 'go', |
| 685 | + request: 'launch', |
| 686 | + mode: 'auto', |
| 687 | + program: PROGRAM, |
| 688 | + noDebug: true |
| 689 | + }; |
| 690 | + const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config); |
| 691 | + |
| 692 | + return Promise.all([ |
| 693 | + dc.launch(debugConfig), |
| 694 | + dc.waitForEvent('output').then((event) => { |
| 695 | + assert.strictEqual(event.body.output, 'Goodbye, World.\n'); |
| 696 | + }) |
| 697 | + ]); |
| 698 | + }); |
| 699 | + |
| 700 | + test('should run file program with cwd set (noDebug)', () => { |
| 701 | + const WD = path.join(DATA_ROOT, 'cwdTest'); |
| 702 | + const PROGRAM = path.join(WD, 'cwdTest', 'main.go'); |
| 703 | + |
| 704 | + const config = { |
| 705 | + name: 'Launch', |
| 706 | + type: 'go', |
| 707 | + request: 'launch', |
| 708 | + mode: 'auto', |
| 709 | + program: PROGRAM, |
| 710 | + cwd: WD, |
| 711 | + noDebug: true |
| 712 | + }; |
| 713 | + const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config); |
| 714 | + |
| 715 | + return Promise.all([ |
| 716 | + dc.launch(debugConfig), |
| 717 | + dc.waitForEvent('output').then((event) => { |
| 718 | + assert.strictEqual(event.body.output, 'Hello, World!\n'); |
| 719 | + }) |
| 720 | + ]); |
| 721 | + }); |
| 722 | + |
| 723 | + test('should run file program without cwd set (noDebug)', () => { |
| 724 | + const WD = path.join(DATA_ROOT, 'cwdTest'); |
| 725 | + const PROGRAM = path.join(WD, 'cwdTest', 'main.go'); |
| 726 | + |
| 727 | + const config = { |
| 728 | + name: 'Launch', |
| 729 | + type: 'go', |
| 730 | + request: 'launch', |
| 731 | + mode: 'auto', |
| 732 | + program: PROGRAM, |
| 733 | + noDebug: true |
| 734 | + }; |
| 735 | + const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config); |
| 736 | + |
| 737 | + return Promise.all([ |
| 738 | + dc.launch(debugConfig), |
| 739 | + dc.waitForEvent('output').then((event) => { |
| 740 | + assert.strictEqual(event.body.output, 'Goodbye, World.\n'); |
| 741 | + }) |
| 742 | + ]); |
| 743 | + }); |
| 744 | + |
| 745 | + }); |
| 746 | + |
571 | 747 | suite('remote attach', () => {
|
572 | 748 | let childProcess: ChildProcess;
|
573 | 749 | let server: number;
|
|
0 commit comments