-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathextension.test.ts
More file actions
1270 lines (1150 loc) · 51.1 KB
/
extension.test.ts
File metadata and controls
1270 lines (1150 loc) · 51.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// Makefile Tools Extension tests without sources and makefiles.
// These tests take advantage of the possibility of parsing
// a previously created dry-run 'make' output log.
// Each tested operation produces logging in the 'Makefile Tools'
// output channel and also in a log file on disk (defined via settings),
// which is compared with a baseline.
// TODO: add a suite of tests operating on real stand-alone makefile repos,
// thus emulating more closely the Makefile Tools end to end usage scenarios.
// For this we need to refactor the make process spawning in the extension,
// so that these tests would produce a deterministic output.
// Thus, this suite is not able to test the entire functionality of the extension
// (anything that is related to a real invocation of the make tool is not yet supported),
// but the remaining scenarios represent an acceptable amount of testing coverage.
// For this suite, even if only parsing is involved, it cannot run any test on any platform
// because of differences in path processing, extension naming, CppTools defaults (sdk, standard),
// debugger settings, etc...
// TODO: figure out a way to test correctly any test on any platform
// (possibly define a property to be considered when querying for process.platform).
// Some of these tests need also some fake binaries being checked in
// (enough to pass an 'if exists' check), to cover the identification of launch binaries
// that are called with arguments in the makefile.
// See comment in parser.ts, parseLineAsTool and parseLaunchConfiguration.
import * as configuration from "../../configuration";
import { expect } from "chai";
import * as launch from "../../launch";
import * as make from "../../make";
import * as parser from "../../parser";
import * as util from "../../util";
import * as cpp from "vscode-cpptools";
import * as fs from "fs";
import * as path from "path";
import * as vscode from "vscode";
suite("Unit testing replacing characters in and outside of quotes", () => {
suiteSetup(async function (this: Mocha.Context) {
this.timeout(100000);
});
setup(async function (this: Mocha.Context) {
this.timeout(100000);
});
test("Test with only double quotes", () => {
const tests = [
"hey;blah;",
"hey;blah",
";hey;blah;",
'hey;bl"ah;"',
'";hey";"blah;";;"',
];
const expectedResults = [
"hey\nblah\n",
"hey\nblah",
"\nhey\nblah\n",
'hey\nbl"ah;"',
'";hey"\n"blah;"\n\n"',
];
for (let i = 0; i < tests.length; i++) {
expect(util.replaceStringNotInQuotes(tests[i], ";", "\n")).to.be.equal(
expectedResults[i]
);
}
});
test("Test with only single quotes", () => {
const tests = [
"hey;blah;",
"hey;blah",
";hey;blah;",
"hey;bl'ah;'",
"';hey';'blah;';;'",
];
const expectedResults = [
"hey\nblah\n",
"hey\nblah",
"\nhey\nblah\n",
"hey\nbl'ah;'",
"';hey'\n'blah;'\n\n'",
];
for (let i = 0; i < tests.length; i++) {
expect(util.replaceStringNotInQuotes(tests[i], ";", "\n")).to.be.equal(
expectedResults[i]
);
}
});
test("Test with both double and single quotes present", () => {
const tests = [
'hey;"bl;\'ah;";;',
"hey\";blah';'\";t'e;st''",
"h';\"e\";'blah;test;'",
];
const expectedResults = [
'hey\n"bl;\'ah;"\n\n',
"hey\";blah';'\"\nt'e;st''",
"h';\"e\";'blah\ntest\n'",
];
for (let i = 0; i < tests.length; i++) {
expect(util.replaceStringNotInQuotes(tests[i], ";", "\n")).to.be.equal(
expectedResults[i]
);
}
});
test("Test various quotes with strings longer than 1 character", () => {
const tests = [
"hey && blah",
'"hey && blah"',
'\'hey " && \'blah" && " && ',
];
const expectedResults = [
"hey\nblah",
'"hey && blah"',
'\'hey " && \'blah" && "\n',
];
for (let i = 0; i < tests.length; i++) {
expect(util.replaceStringNotInQuotes(tests[i], " && ", "\n")).to.be.equal(
expectedResults[i]
);
}
});
test("Test semicolon not replaced inside quotes after make directory banner", () => {
// GNU make outputs: Entering directory `path'
// The trailing ' must not open a phantom quote context that leaks
// into subsequent lines when processing the whole dry-run output.
// Processing per-line prevents this cross-line leakage.
const enteringDir = "make.exe: Entering directory `c:/project'";
const compilerCmd =
"gcc -D'MY_ASSERT(test)'='do { if(!(test)) {return -1;} } while(0)' -o main main.c";
const leavingDir = "make.exe: Leaving directory `c:/project'";
const input = [enteringDir, compilerCmd, leavingDir].join("\n");
// Per-line processing: each line is independent, so the directory
// banner's trailing ' does not affect the compiler command line.
const result = input
.split("\n")
.map((line) => util.replaceStringNotInQuotes(line, ";", "\n"))
.join("\n");
// The compiler command line should be preserved intact
// (semicolons inside the quoted value should NOT be replaced)
expect(result).to.contain(compilerCmd);
});
test("Test && not replaced inside quotes after make directory banner", () => {
const enteringDir = "make.exe: Entering directory `c:/project'";
const compilerCmd =
"gcc -D'CHECK(a,b)'='do { if(a && b) {return 0;} } while(0)' -o main main.c";
const leavingDir = "make.exe: Leaving directory `c:/project'";
const input = [enteringDir, compilerCmd, leavingDir].join("\n");
const result = input
.split("\n")
.map((line) => util.replaceStringNotInQuotes(line, " && ", "\n"))
.join("\n");
expect(result).to.contain(compilerCmd);
});
});
suite("Unit testing parseMultipleSwitchFromToolArguments", () => {
test("Quoted define with name=value using single quotes", () => {
const args =
"gcc -Wall -D'MY_ASSERT(test)'='do { if(!(test)) {return -1;} } while(0)' -o main main.c";
const result = parser.parseMultipleSwitchFromToolArguments(args, "D");
expect(result).to.have.lengthOf(1);
expect(result[0]).to.equal(
"MY_ASSERT(test)=do { if(!(test)) {return -1;} } while(0)"
);
});
test("Simple define without value", () => {
const args = "gcc -DSIMPLE main.c";
const result = parser.parseMultipleSwitchFromToolArguments(args, "D");
expect(result).to.have.lengthOf(1);
expect(result[0]).to.equal("SIMPLE");
});
test("Simple define with unquoted value", () => {
const args = "gcc -DNAME=VALUE main.c";
const result = parser.parseMultipleSwitchFromToolArguments(args, "D");
expect(result).to.have.lengthOf(1);
expect(result[0]).to.equal("NAME=VALUE");
});
test("Define with quoted value containing spaces", () => {
const args = 'gcc -D"MY DEFINE" main.c';
const result = parser.parseMultipleSwitchFromToolArguments(args, "D");
expect(result).to.have.lengthOf(1);
expect(result[0]).to.equal("MY DEFINE");
});
test("Define with single-quoted name only", () => {
const args = "gcc -D'MY_DEFINE' main.c";
const result = parser.parseMultipleSwitchFromToolArguments(args, "D");
expect(result).to.have.lengthOf(1);
expect(result[0]).to.equal("MY_DEFINE");
});
test("Multiple defines parsed correctly", () => {
const args = "gcc -DFOO -DBAR=baz -D'QUOTED' main.c";
const result = parser.parseMultipleSwitchFromToolArguments(args, "D");
expect(result).to.have.lengthOf(3);
expect(result[0]).to.equal("FOO");
expect(result[1]).to.equal("BAR=baz");
expect(result[2]).to.equal("QUOTED");
});
});
suite("Configuration settings", () => {
suiteSetup(async function (this: Mocha.Context) {
this.timeout(100000);
});
setup(async function (this: Mocha.Context) {
this.timeout(100000);
});
test("cleanConfigureOnConfigurationChange defaults to true", async () => {
// The setting should default to true when not explicitly set
const value = configuration.getCleanConfigureOnConfigurationChange();
// When the setting is not set, getExpandedSetting returns undefined,
// and the code treats undefined the same as true (cleanConfigureOnConfigurationChange !== false)
// So either true or undefined are valid default values
expect(value === true || value === undefined).to.be.true;
});
test("cleanConfigureOnConfigurationChange can be set to false", async () => {
// Save the original value
const originalValue = configuration.getCleanConfigureOnConfigurationChange();
// Set to false using the setter
configuration.setCleanConfigureOnConfigurationChange(false);
// Verify it was set
expect(configuration.getCleanConfigureOnConfigurationChange()).to.be.false;
// Restore original value - if it was undefined, we reset to true (the default)
// to ensure subsequent tests start with the expected default behavior
configuration.setCleanConfigureOnConfigurationChange(
originalValue !== undefined ? originalValue : true
);
});
});
suite("Launch configuration string comparison", () => {
test("areLaunchConfigurationStringsEqual - same strings", () => {
const str1 = "c:\\Users\\test\\project>out()";
const str2 = "c:\\Users\\test\\project>out()";
expect(util.areLaunchConfigurationStringsEqual(str1, str2)).to.be.true;
});
test("areLaunchConfigurationStringsEqual - different strings", () => {
const str1 = "c:\\Users\\test\\project>out()";
const str2 = "c:\\Users\\test\\project>out(arg1)";
expect(util.areLaunchConfigurationStringsEqual(str1, str2)).to.be.false;
});
test("areLaunchConfigurationStringsEqual - same strings with args", () => {
const str1 = "c:\\Users\\test\\project>out(arg1,arg2)";
const str2 = "c:\\Users\\test\\project>out(arg1,arg2)";
expect(util.areLaunchConfigurationStringsEqual(str1, str2)).to.be.true;
});
test("areLaunchConfigurationStringsEqual - handles null/undefined", () => {
expect(util.areLaunchConfigurationStringsEqual(null as any, null as any)).to
.be.true;
expect(
util.areLaunchConfigurationStringsEqual(undefined as any, undefined as any)
).to.be.true;
expect(
util.areLaunchConfigurationStringsEqual(
"c:\\Users\\test\\project>out()",
null as any
)
).to.be.false;
expect(
util.areLaunchConfigurationStringsEqual(
null as any,
"c:\\Users\\test\\project>out()"
)
).to.be.false;
});
// When the string doesn't match the expected cwd>binary(args) format,
// the function falls back to case-insensitive comparison on Windows.
if (process.platform === "win32") {
test("areLaunchConfigurationStringsEqual - fallback for non-standard format on Windows", () => {
const str1 = "some-random-string";
const str2 = "Some-Random-String";
expect(util.areLaunchConfigurationStringsEqual(str1, str2)).to.be.true;
});
test("areLaunchConfigurationStringsEqual - fallback mismatch for non-standard format on Windows", () => {
const str1 = "some-random-string";
const str2 = "different-string";
expect(util.areLaunchConfigurationStringsEqual(str1, str2)).to.be.false;
});
}
// On Windows, paths are case-insensitive but arguments are case-sensitive
if (process.platform === "win32") {
test("areLaunchConfigurationStringsEqual - different path case on Windows", () => {
const str1 = "c:\\Users\\test\\project>out()";
const str2 = "C:\\Users\\Test\\Project>OUT()";
expect(util.areLaunchConfigurationStringsEqual(str1, str2)).to.be.true;
});
test("areLaunchConfigurationStringsEqual - different path case same args on Windows", () => {
const str1 = "c:\\users\\test\\project>out(arg1,arg2)";
const str2 = "C:\\Users\\TEST\\Project>Out(arg1,arg2)";
// Paths are compared case-insensitively, args are case-sensitive
expect(util.areLaunchConfigurationStringsEqual(str1, str2)).to.be.true;
});
test("areLaunchConfigurationStringsEqual - different args case on Windows", () => {
const str1 = "c:\\users\\test\\project>out(arg1,arg2)";
const str2 = "C:\\Users\\TEST\\Project>Out(Arg1,Arg2)";
// Arguments are case-sensitive even on Windows
expect(util.areLaunchConfigurationStringsEqual(str1, str2)).to.be.false;
});
}
});
// TODO: refactor initialization and cleanup of each test
suite("Fake dryrun parsing", () => {
suiteSetup(async function (this: Mocha.Context) {
this.timeout(100000);
await vscode.commands.executeCommand("makefile.resetState", false);
});
setup(async function (this: Mocha.Context) {
this.timeout(100000);
await vscode.commands.executeCommand("makefile.resetState", false);
});
// Interesting scenarios with string paths, corner cases in defining includes/defines,
// complex configurations-targets-files associations.
// For now, this test needs to run in an environment with VS 2019.
// The output log varies depending on finding a particular VS toolset or not.
// We need to test the scenario of providing in the makefile a full path to the compiler,
// so there is no way around this. Using only compiler name and relying on path is not sufficient.
// Also, for the cases when a path (relative or full) is given to the compiler in the makefile
// and the compiler is not found there, the parser will skip over the compiler command
// (see comment in parser.ts - parseLineAsTool), so again, we need to find the toolset that is referenced in the makefile.
// TODO: mock various scenarios of VS environments without depending on what is installed.
// TODO: adapt the makefile on mac/linux/mingw and add new tests in this suite
// to parse the dry-run logs obtained on those platforms.
let systemPlatform: string;
if (process.platform === "win32") {
systemPlatform =
process.env.MSYSTEM === undefined ? "win32" : process.env.MSYSTEM;
} else {
systemPlatform = process.platform;
}
const ext = vscode.extensions.getExtension("ms-vscode.makefile-tools");
if (ext) {
ext.activate();
}
test(`Complex scenarios with quotes and escaped quotes - ${systemPlatform}`, async () => {
// Settings reset from the previous test run.
await vscode.commands.executeCommand("makefile.resetState", false);
await vscode.workspace
.getConfiguration("makefile")
.update("launchConfigurations", undefined);
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"Default"
);
// We define extension log here as opposed to in the fake repro .vscode/settings.json
// because the logging produced at the first project load has too few important data to verify and much variations
// that are not worth to be processed when comparing with a baseline.
// Example: when running a test after incomplete debugging or after loading the fake repro project independently of the testing framework,
// which leaves the workspace state not clean, resulting in a different extension output log
// than without debugging/loading the project before.
// If we define extension log here instead of .vscode/settings.json, we also have to clean it up
// because at project load time, there is no makefile log identified and no file is deleted on activation.
const extensionLogPath: string = path.join(
vscode.workspace.workspaceFolders?.[0]?.uri.path || "./",
".vscode/Makefile.out"
);
if (util.checkFileExistsSync(extensionLogPath)) {
util.deleteFileSync(extensionLogPath);
}
// Run a preconfigure script to include our tests fake compilers path so that we always find gcc/gpp/clang/...etc...
// from this extension repository instead of a real installation which may vary from system to system.
await vscode.commands.executeCommand(
"makefile.setPreconfigureScriptByPath",
path.join(
vscode.workspace.workspaceFolders?.[0]?.uri.path || "./",
systemPlatform === "win32"
? ".vscode/preconfigure.bat"
: ".vscode/preconfigure_nonwin.sh"
)
);
await vscode.commands.executeCommand("makefile.preConfigure");
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"complex_escaped_quotes"
);
await vscode.commands.executeCommand("makefile.cleanConfigure");
// Compare the output log with the baseline
// TODO: incorporate relevant diff snippets into the test log.
// Until then, print into base and diff files for easier viewing
// when the test fails.
let parsedPath: path.ParsedPath = path.parse(extensionLogPath);
let baselineLogPath: string = path.join(
parsedPath.dir,
systemPlatform === "win32"
? "../complex_escaped_quotes_baseline.out"
: "../complex_escaped_quotes_nonWin_baseline.out"
);
let extensionLogContent: string = util.readFile(extensionLogPath) || "";
extensionLogContent = extensionLogContent.replace(/\r\n/gm, "\n");
let baselineLogContent: string = util.readFile(baselineLogPath) || "";
let extensionRootPath: string = path.resolve(__dirname, "../../../..");
baselineLogContent = baselineLogContent.replace(
/{REPO:VSCODE-MAKEFILE-TOOLS}/gm,
extensionRootPath
);
baselineLogContent = baselineLogContent.replace(/\r\n/gm, "\n");
// fs.writeFileSync(path.join(parsedPath.dir, "base6.out"), baselineLogContent);
// fs.writeFileSync(path.join(parsedPath.dir, "diff6.out"), extensionLogContent);
expect(extensionLogContent).to.be.equal(baselineLogContent);
});
if (systemPlatform === "win32") {
test(`Complex scenarios with quotes and escaped quotes - winOnly`, async () => {
// Settings reset from the previous test run.
await vscode.commands.executeCommand("makefile.resetState", false);
await vscode.commands.executeCommand("makefile.testResetState");
await vscode.workspace
.getConfiguration("makefile")
.update("launchConfigurations", undefined);
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"Default"
);
// We define extension log here as opposed to in the fake repro .vscode/settings.json
// because the logging produced at the first project load has too few important data to verify and much variations
// that are not worth to be processed when comparing with a baseline.
// Example: when running a test after incomplete debugging or after loading the fake repro project independently of the testing framework,
// which leaves the workspace state not clean, resulting in a different extension output log
// than without debugging/loading the project before.
// If we define extension log here instead of .vscode/settings.json, we also have to clean it up
// because at project load time, there is no makefile log identified and no file is deleted on activation.
let extensionLogPath: string =
configuration.getExtensionLog() ||
path.join(vscode.workspace.workspaceFolders?.[0]?.uri.path || "./", ".vscode/Makefile.out");
if (util.checkFileExistsSync(extensionLogPath)) {
util.deleteFileSync(extensionLogPath);
}
// Run a preconfigure script to include our tests fake compilers path so that we always find gcc/gpp/clang/...etc...
// from this extension repository instead of a real installation which may vary from system to system.
await vscode.commands.executeCommand(
"makefile.setPreconfigureScriptByPath",
path.join(vscode.workspace.workspaceFolders?.[0]?.uri.path || "./", ".vscode/preconfigure.bat")
);
await vscode.commands.executeCommand("makefile.preConfigure");
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"complex_escaped_quotes_winOnly"
);
await vscode.commands.executeCommand("makefile.cleanConfigure");
// Compare the output log with the baseline
// TODO: incorporate relevant diff snippets into the test log.
// Until then, print into base and diff files for easier viewing
// when the test fails.
let parsedPath: path.ParsedPath = path.parse(extensionLogPath);
let baselineLogPath: string = path.join(
parsedPath.dir,
"../complex_escaped_quotes_winOnly_baseline.out"
);
let extensionLogContent: string = util.readFile(extensionLogPath) || "";
extensionLogContent = extensionLogContent.replace(/\r\n/gm, "\n");
let baselineLogContent: string = util.readFile(baselineLogPath) || "";
let extensionRootPath: string = path.resolve(__dirname, "../../../../");
baselineLogContent = baselineLogContent.replace(
/{REPO:VSCODE-MAKEFILE-TOOLS}/gm,
extensionRootPath
);
baselineLogContent = baselineLogContent.replace(/\r\n/gm, "\n");
// fs.writeFileSync(path.join(parsedPath.dir, "base.out"), baselineLogContent);
// fs.writeFileSync(path.join(parsedPath.dir, "diff.out"), extensionLogContent);
expect(extensionLogContent).to.be.equal(baselineLogContent);
});
}
if (systemPlatform === "win32") {
test("Interesting small makefile - windows", async () => {
// Settings reset from the previous test run.
await vscode.commands.executeCommand("makefile.resetState", false);
await vscode.commands.executeCommand("makefile.testResetState");
await vscode.workspace
.getConfiguration("makefile")
.update("launchConfigurations", undefined);
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"Default"
);
// Extension log is defined in the test .vscode/settings.json but delete it now
// because we are interested to compare against a baseline from this point further.
let extensionLogPath: string = path.join(
vscode.workspace.workspaceFolders?.[0]?.uri.path || "./",
".vscode/Makefile.out"
);
if (extensionLogPath && util.checkFileExistsSync(extensionLogPath)) {
util.deleteFileSync(extensionLogPath);
}
// Run a preconfigure script to include our tests "Program Files" path so that we always find a cl.exe
// from this extension repository instead of a real VS installation that happens to be in the path.
await vscode.commands.executeCommand(
"makefile.setPreconfigureScriptByPath",
path.join(vscode.workspace.workspaceFolders?.[0]?.uri.path || "./", ".vscode/preconfigure.bat")
);
await vscode.commands.executeCommand("makefile.preConfigure");
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"InterestingSmallMakefile_windows_configDebug"
);
await vscode.commands.executeCommand("makefile.cleanConfigure");
const launchConfigurations: string[] = [
"bin\\InterestingSmallMakefile\\ARC H3\\Debug\\main.exe(str3a,str3b,str3c)",
"bin\\InterestingSmallMakefile\\arch1\\Debug\\main.exe(str3a,str3b,str3c)",
"bin\\InterestingSmallMakefile\\arch2\\Debug\\main.exe()",
];
for (const config of launchConfigurations) {
await vscode.commands.executeCommand(
"makefile.setLaunchConfigurationByName",
vscode.workspace.workspaceFolders?.[0]?.uri.path + ">" + config
);
let status: string = await vscode.commands.executeCommand(
"makefile.validateLaunchConfiguration"
);
let launchConfiguration: configuration.LaunchConfiguration | undefined;
if (status === launch.LaunchStatuses.success) {
launchConfiguration = await vscode.commands.executeCommand(
"makefile.getCurrentLaunchConfiguration"
);
}
if (launchConfiguration) {
await vscode.commands.executeCommand(
"makefile.prepareDebugAndRunCurrentTarget",
launchConfiguration
);
}
}
// A bit more coverage, "RelSize" and "RelSpeed" are set up
// to exercise different combinations of pre-created build log and/or make tools.
// No configure is necessary to be run here, it is enough to look at what happens
// when changing a configuration.
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"InterestingSmallMakefile_windows_configRelSize"
);
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"InterestingSmallMakefile_windows_configRelSpeed"
);
// InterestingSmallMakefile_windows_configRelSpeed constructs a more interesting build command.
await vscode.commands.executeCommand(
"makefile.setTargetByName",
"Execute_Arch3"
);
await vscode.commands.executeCommand(
"makefile.prepareBuildTarget",
"Execute_Arch3"
);
await vscode.commands.executeCommand("makefile.resetState", false);
await vscode.workspace
.getConfiguration("makefile")
.update("launchConfigurations", undefined);
// Compare the output log with the baseline
// TODO: incorporate relevant diff snippets into the test log.
// Until then, print into base and diff files for easier viewing
// when the test fails.
let parsedPath: path.ParsedPath = path.parse(extensionLogPath);
let baselineLogPath: string = path.join(
parsedPath.dir,
"../InterestingSmallMakefile_windows_baseline.out"
);
let extensionLogContent: string = util.readFile(extensionLogPath) || "";
extensionLogContent = extensionLogContent.replace(/\r\n/gm, "\n");
let baselineLogContent: string = util.readFile(baselineLogPath) || "";
let extensionRootPath: string = path.resolve(__dirname, "../../../../");
baselineLogContent = baselineLogContent.replace(
/{REPO:VSCODE-MAKEFILE-TOOLS}/gm,
extensionRootPath
);
baselineLogContent = baselineLogContent.replace(/\r\n/gm, "\n");
// fs.writeFileSync(path.join(parsedPath.dir, "base.out"), baselineLogContent);
// fs.writeFileSync(path.join(parsedPath.dir, "diff.out"), extensionLogContent);
expect(extensionLogContent).to.be.equal(baselineLogContent);
});
}
// dry-run logs for https://github.com/rui314/8cc.git
if (systemPlatform === "linux" || systemPlatform === "mingw") {
test(`8cc - ${systemPlatform}`, async () => {
// Settings reset from the previous test run.
await vscode.commands.executeCommand("makefile.resetState", false);
await vscode.commands.executeCommand("makefile.testResetState");
await vscode.workspace
.getConfiguration("makefile")
.update("launchConfigurations", undefined);
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"Default"
);
// Extension log is defined in the test .vscode/settings.json but delete it now
// because we are interested to compare against a baseline from this point further.
let extensionLogPath: string = path.join(
vscode.workspace.workspaceFolders?.[0]?.uri.path || "./",
".vscode/Makefile.out"
);
if (extensionLogPath && util.checkFileExistsSync(extensionLogPath)) {
util.deleteFileSync(extensionLogPath);
}
// Run a preconfigure script to include our tests fake compilers path so that we always find gcc/gpp/clang/...etc...
// from this extension repository instead of a real installation which may vary from system to system.
await vscode.commands.executeCommand(
"makefile.setPreconfigureScriptByPath",
path.join(
vscode.workspace.workspaceFolders?.[0]?.uri.path || "./",
".vscode/preconfigure_nonwin.sh"
)
);
await vscode.commands.executeCommand("makefile.preConfigure");
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
process.platform === "linux" ? "8cc_linux" : "8cc_mingw"
);
await vscode.commands.executeCommand("makefile.cleanConfigure");
const launchConfigurations: string[] = ["8cc()"];
for (const config of launchConfigurations) {
await vscode.commands.executeCommand(
"makefile.setLaunchConfigurationByName",
vscode.workspace.workspaceFolders?.[0]?.uri.path + ">" + config
);
let status: string = await vscode.commands.executeCommand(
"makefile.validateLaunchConfiguration"
);
let launchConfiguration: configuration.LaunchConfiguration | undefined;
if (status === launch.LaunchStatuses.success) {
launchConfiguration = await vscode.commands.executeCommand(
"makefile.getCurrentLaunchConfiguration"
);
}
if (launchConfiguration) {
await vscode.commands.executeCommand(
"makefile.prepareDebugAndRunCurrentTarget",
launchConfiguration
);
}
}
await vscode.commands.executeCommand("makefile.setTargetByName", "all");
await vscode.commands.executeCommand(
"makefile.prepareBuildTarget",
"all"
);
// Compare the output log with the baseline
// TODO: incorporate relevant diff snippets into the test log.
// Until then, print into base and diff files for easier viewing
// when the test fails.
let parsedPath: path.ParsedPath = path.parse(extensionLogPath);
let baselineLogPath: string = path.join(
parsedPath.dir,
process.platform === "linux"
? "../8cc_linux_baseline.out"
: "../8cc_mingw_baseline.out"
);
let extensionLogContent: string = util.readFile(extensionLogPath) || "";
let baselineLogContent: string = util.readFile(baselineLogPath) || "";
let extensionRootPath: string = path.resolve(__dirname, "../../../../");
baselineLogContent = baselineLogContent.replace(
/{REPO:VSCODE-MAKEFILE-TOOLS}/gm,
extensionRootPath
);
// fs.writeFileSync(path.join(parsedPath.dir, "base5.out"), baselineLogContent);
// fs.writeFileSync(path.join(parsedPath.dir, "diff5.out"), extensionLogContent);
expect(extensionLogContent).to.be.equal(baselineLogContent);
});
}
// dry-run logs for https://github.com/FidoProject/Fido.git
if (systemPlatform === "linux" || systemPlatform === "mingw") {
test(`Fido - ${systemPlatform}`, async () => {
// Settings reset from the previous test run.
await vscode.commands.executeCommand("makefile.resetState", false);
await vscode.commands.executeCommand("makefile.testResetState");
await vscode.workspace
.getConfiguration("makefile")
.update("launchConfigurations", undefined);
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"Default"
);
// Extension log is defined in the test .vscode/settings.json but delete it now
// because we are interested to compare against a baseline from this point further.
let extensionLogPath: string = path.join(
vscode.workspace.workspaceFolders?.[0]?.uri.path || "./",
".vscode/Makefile.out"
);
if (extensionLogPath && util.checkFileExistsSync(extensionLogPath)) {
util.deleteFileSync(extensionLogPath);
}
// Run a preconfigure script to include our tests fake compilers path so that we always find gcc/gpp/clang/...etc...
// from this extension repository instead of a real installation which may vary from system to system.
await vscode.commands.executeCommand(
"makefile.setPreconfigureScriptByPath",
path.join(
vscode.workspace.workspaceFolders?.[0]?.uri.path || "./",
".vscode/preconfigure_nonwin.sh"
)
);
await vscode.commands.executeCommand("makefile.preConfigure");
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
process.platform === "linux" ? "Fido_linux" : "Fido_mingw"
);
await vscode.commands.executeCommand("makefile.cleanConfigure");
const launchConfigurations: string[] = ["bin/foo.o()"];
for (const config of launchConfigurations) {
await vscode.commands.executeCommand(
"makefile.setLaunchConfigurationByName",
vscode.workspace.workspaceFolders?.[0]?.uri.path + ">" + config
);
let status: string = await vscode.commands.executeCommand(
"makefile.validateLaunchConfiguration"
);
let launchConfiguration: configuration.LaunchConfiguration | undefined;
if (status === launch.LaunchStatuses.success) {
launchConfiguration = await vscode.commands.executeCommand(
"makefile.getCurrentLaunchConfiguration"
);
}
if (launchConfiguration) {
await vscode.commands.executeCommand(
"makefile.prepareDebugAndRunCurrentTarget",
launchConfiguration
);
}
}
await vscode.commands.executeCommand(
"makefile.setTargetByName",
"bin/foo.o"
);
await vscode.commands.executeCommand(
"makefile.prepareBuildTarget",
"bin/foo.o"
);
// Compare the output log with the baseline
// TODO: incorporate relevant diff snippets into the test log.
// Until then, print into base and diff files for easier viewing
// when the test fails.
let parsedPath: path.ParsedPath = path.parse(extensionLogPath);
let baselineLogPath: string = path.join(
parsedPath.dir,
process.platform === "linux"
? "../Fido_linux_baseline.out"
: "../Fido_mingw_baseline.out"
);
let extensionLogContent: string = util.readFile(extensionLogPath) || "";
let baselineLogContent: string = util.readFile(baselineLogPath) || "";
let extensionRootPath: string = path.resolve(__dirname, "../../../../");
baselineLogContent = baselineLogContent.replace(
/{REPO:VSCODE-MAKEFILE-TOOLS}/gm,
extensionRootPath
);
// fs.writeFileSync(path.join(parsedPath.dir, "base4.out"), baselineLogContent);
// fs.writeFileSync(path.join(parsedPath.dir, "diff4.out"), extensionLogContent);
expect(extensionLogContent).to.be.equal(baselineLogContent);
});
}
// dry-run logs for https://github.com/jakogut/tinyvm.git
if (systemPlatform === "linux" || systemPlatform === "mingw") {
test(`tinyvm - ${systemPlatform}`, async () => {
// Settings reset from the previous test run.
await vscode.commands.executeCommand("makefile.resetState", false);
await vscode.commands.executeCommand("makefile.testResetState");
await vscode.workspace
.getConfiguration("makefile")
.update("launchConfigurations", undefined);
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"Default"
);
// Extension log is defined in the test .vscode/settings.json but delete it now
// because we are interested to compare against a baseline from this point further.
let extensionLogPath: string = path.join(
vscode.workspace.workspaceFolders?.[0]?.uri.path || "./",
".vscode/Makefile.out"
);
if (extensionLogPath && util.checkFileExistsSync(extensionLogPath)) {
util.deleteFileSync(extensionLogPath);
}
// Run a preconfigure script to include our tests fake compilers path so that we always find gcc/gpp/clang/...etc...
// from this extension repository instead of a real installation which may vary from system to system.
await vscode.commands.executeCommand(
"makefile.setPreconfigureScriptByPath",
path.join(
vscode.workspace.workspaceFolders?.[0]?.uri.path || "./",
".vscode/preconfigure_nonwin.sh"
)
);
await vscode.commands.executeCommand("makefile.preConfigure");
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
process.platform === "linux"
? "tinyvm_linux_pedantic"
: "tinyvm_mingw_pedantic"
);
await vscode.commands.executeCommand("makefile.cleanConfigure");
const launchConfigurations: string[] = ["bin/tvmi()"];
for (const config of launchConfigurations) {
await vscode.commands.executeCommand(
"makefile.setLaunchConfigurationByName",
vscode.workspace.workspaceFolders?.[0]?.uri.path + ">" + config
);
let status: string = await vscode.commands.executeCommand(
"makefile.validateLaunchConfiguration"
);
let launchConfiguration: configuration.LaunchConfiguration | undefined;
if (status === launch.LaunchStatuses.success) {
launchConfiguration = await vscode.commands.executeCommand(
"makefile.getCurrentLaunchConfiguration"
);
}
if (launchConfiguration) {
await vscode.commands.executeCommand(
"makefile.prepareDebugAndRunCurrentTarget",
launchConfiguration
);
}
}
await vscode.commands.executeCommand("makefile.setTargetByName", "tvmi");
await vscode.commands.executeCommand(
"makefile.prepareBuildTarget",
"tvmi"
);
// Compare the output log with the baseline
// TODO: incorporate relevant diff snippets into the test log.
// Until then, print into base and diff files for easier viewing
// when the test fails.
let parsedPath: path.ParsedPath = path.parse(extensionLogPath);
let baselineLogPath: string = path.join(
parsedPath.dir,
process.platform === "linux"
? "../tinyvm_linux_baseline.out"
: "../tinyvm_mingw_baseline.out"
);
let extensionLogContent: string = util.readFile(extensionLogPath) || "";
let baselineLogContent: string = util.readFile(baselineLogPath) || "";
let extensionRootPath: string = path.resolve(__dirname, "../../../../");
baselineLogContent = baselineLogContent.replace(
/{REPO:VSCODE-MAKEFILE-TOOLS}/gm,
extensionRootPath
);
// fs.writeFileSync(path.join(parsedPath.dir, "base3.out"), baselineLogContent);
// fs.writeFileSync(path.join(parsedPath.dir, "diff3.out"), extensionLogContent);
expect(extensionLogContent).to.be.equal(baselineLogContent);
});
}
test(`Test real make - ${systemPlatform}`, async () => {
// Settings reset from the previous test run.
await vscode.commands.executeCommand("makefile.resetState", false);
await vscode.commands.executeCommand("makefile.testResetState");
await vscode.workspace
.getConfiguration("makefile")
.update("launchConfigurations", undefined);
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"Default"
);
// Extension log is defined in the test .vscode/settings.json but delete it now
// because we are interested to compare against a baseline from this point further.
let extensionLogPath: string = path.join(
vscode.workspace.workspaceFolders?.[0]?.uri.path || "./",
".vscode/Makefile.out"
);
if (extensionLogPath && util.checkFileExistsSync(extensionLogPath)) {
util.deleteFileSync(extensionLogPath);
}
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"test-make-f"
);
await vscode.commands.executeCommand("makefile.cleanConfigure");
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"test-make-C"
);
await vscode.commands.executeCommand("makefile.buildCleanAll");
// Compare the output log with the baseline
// TODO: incorporate relevant diff snippets into the test log.
// Until then, print into base and diff files for easier viewing
// when the test fails.
let parsedPath: path.ParsedPath = path.parse(extensionLogPath);
let baselineLogPath: string = path.join(
parsedPath.dir,
process.platform === "win32"
? "../test_real_make_windows_baseline.out"
: "../test_real_make_nonWin_baseline.out"
);
let extensionLogContent: string = util.readFile(extensionLogPath) || "";
extensionLogContent = extensionLogContent.replace(/\r\n/gm, "\n");
let baselineLogContent: string = util.readFile(baselineLogPath) || "";
let extensionRootPath: string = path.resolve(__dirname, "../../../../");
baselineLogContent = baselineLogContent.replace(
/{REPO:VSCODE-MAKEFILE-TOOLS}/gm,
extensionRootPath
);
baselineLogContent = baselineLogContent.replace(/\r\n/gm, "\n");
// fs.writeFileSync(path.join(parsedPath.dir, "base2.out"), baselineLogContent);
// fs.writeFileSync(path.join(parsedPath.dir, "diff2.out"), extensionLogContent);
expect(extensionLogContent).to.be.equal(baselineLogContent);
});
test(`Variables expansion - ${systemPlatform}`, async () => {
// Settings reset from the previous test run.
await vscode.commands.executeCommand("makefile.resetState", false);
await vscode.commands.executeCommand("makefile.testResetState");
await vscode.workspace
.getConfiguration("makefile")
.update("launchConfigurations", undefined);
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"Default"
);
await vscode.commands.executeCommand(
"makefile.setBuildConfigurationByName",
"varexp"
);
await vscode.commands.executeCommand("makefile.setTargetByName", "all");