/
DeclManager.cpp
1727 lines (1319 loc) · 75.3 KB
/
DeclManager.cpp
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
#include "RadiantTest.h"
#include "igame.h"
#include "ideclmanager.h"
#include "testutil/TemporaryFile.h"
#include "testutil/ThreadUtils.h"
#include "decl/EditableDeclaration.h"
#include "algorithm/FileUtils.h"
#include "os/path.h"
#include "parser/DefBlockSyntaxParser.h"
#include "string/case_conv.h"
namespace test
{
class DeclManagerTest :
public RadiantTest
{
public:
const char* const TEST_DECL_FILE = "numbers.decl";
const char* const TEST_DECL_FOLDER = "testdecls/";
void preStartup() override
{
// Remove the physical override_test.decl file
fs::remove(_context.getTestProjectPath() + "testdecls/override_test.decl");
// Create a backup of the numbers file
fs::path testFile = _context.getTestProjectPath() + TEST_DECL_FOLDER + TEST_DECL_FILE;
fs::path bakFile = testFile;
bakFile.replace_extension(".bak");
fs::remove(bakFile);
fs::copy(testFile, bakFile);
}
void preShutdown() override
{
fs::path testFile = _context.getTestProjectPath() + TEST_DECL_FOLDER + TEST_DECL_FILE;
fs::remove(testFile);
fs::path bakFile = testFile;
bakFile.replace_extension(".bak");
fs::rename(bakFile, testFile);
}
};
class ITestDeclaration :
public decl::IDeclaration
{
public:
using Ptr = std::shared_ptr<ITestDeclaration>;
virtual ~ITestDeclaration() {}
// Interface methods for testing purposes
virtual std::string getKeyValue(const std::string& key) = 0;
virtual void setKeyValue(const std::string& key, const std::string& value) = 0;
virtual void foreachKeyValue(std::function<void(std::pair<std::string, std::string>)> functor) = 0;
};
class TestDeclaration :
public decl::EditableDeclaration<ITestDeclaration>
{
private:
std::map<std::string, std::string> _keyValues;
public:
TestDeclaration(decl::Type type, const std::string& name) :
EditableDeclaration<ITestDeclaration>(type, name)
{}
std::string getKeyValue(const std::string& key) override
{
ensureParsed();
return _keyValues.count(key) > 0 ? _keyValues.at(key) : "";
}
// API method to simulate a change of the declaration contents
void setKeyValue(const std::string& key, const std::string& value) override
{
_keyValues[key] = value;
onParsedContentsChanged();
}
void foreachKeyValue(std::function<void(std::pair<std::string, std::string>)> functor) override
{
for (auto& pair : _keyValues)
{
functor(pair);
}
}
int generateSyntaxInvocationCount = 0;
protected:
std::string generateSyntax() override
{
++generateSyntaxInvocationCount;
std::stringstream stream;
stream << "\n";
for (const auto& [key, value] : _keyValues)
{
stream << "\"" << key << "\" \"" << value << "\"\n";
}
stream << "\n";
return stream.str();
}
void parseFromTokens(parser::DefTokeniser& tokeniser) override
{
while (tokeniser.hasMoreTokens())
{
// Read key/value pairs until end of decl
auto key = tokeniser.nextToken();
auto value = tokeniser.nextToken();
_keyValues.emplace(key, value);
}
}
};
class TestDeclarationCreator :
public decl::IDeclarationCreator
{
public:
std::function<void()> creationCallback;
decl::Type getDeclType() const override
{
return decl::Type::TestDecl;
}
decl::IDeclaration::Ptr createDeclaration(const std::string& name) override
{
if (creationCallback)
{
creationCallback();
}
return std::make_shared<TestDeclaration>(getDeclType(), name);
}
};
class TestDeclaration2Creator :
public decl::IDeclarationCreator
{
public:
decl::Type getDeclType() const override
{
return decl::Type::TestDecl2;
}
decl::IDeclaration::Ptr createDeclaration(const std::string& name) override
{
return std::make_shared<TestDeclaration>(getDeclType(), name);
}
};
TEST_F(DeclManagerTest, DeclTypeRegistration)
{
auto creator = std::make_shared<TestDeclarationCreator>();
EXPECT_NO_THROW(GlobalDeclarationManager().registerDeclType("testdecl", creator));
// Registering the same type name twice should result in an exception
EXPECT_THROW(GlobalDeclarationManager().registerDeclType("testdecl", creator), std::logic_error);
// Passing a new creator instance doesn't help either
auto creator2 = std::make_shared<TestDeclarationCreator>();
EXPECT_THROW(GlobalDeclarationManager().registerDeclType("testdecl", creator2), std::logic_error);
}
TEST_F(DeclManagerTest, DeclTypeUnregistration)
{
auto creator = std::make_shared<TestDeclarationCreator>();
GlobalDeclarationManager().registerDeclType("testdecl", creator);
// Unregistering the creator should succeed
EXPECT_NO_THROW(GlobalDeclarationManager().unregisterDeclType("testdecl"));
// Trying to unregister it twice should result in an exception
EXPECT_THROW(GlobalDeclarationManager().unregisterDeclType("testdecl"), std::logic_error);
}
inline std::set<std::string> getAllDeclNames(decl::Type type)
{
// Iterate over all decls and collect the names
std::set<std::string> foundNames;
GlobalDeclarationManager().foreachDeclaration(type, [&](const decl::IDeclaration::Ptr& declaration)
{
foundNames.insert(declaration->getDeclName());
});
return foundNames;
}
inline void checkKnownTestDeclNames()
{
auto foundNames = getAllDeclNames(decl::Type::TestDecl);
// Check a few known ones
EXPECT_TRUE(foundNames.count("decl/exporttest/guisurf1") > 0);
EXPECT_TRUE(foundNames.count("decl/numbers/0") > 0);
EXPECT_TRUE(foundNames.count("decl/numbers/1") > 0);
EXPECT_TRUE(foundNames.count("decl/numbers/2") > 0);
// decltables should not be listed
EXPECT_FALSE(foundNames.count("decltable1") > 0);
EXPECT_FALSE(foundNames.count("decltable2") > 0);
EXPECT_FALSE(foundNames.count("decltable3") > 0);
}
inline void checkKnownTestDecl2Names()
{
auto foundNames = getAllDeclNames(decl::Type::TestDecl2);
// Assume testdecls are not listed
EXPECT_FALSE(foundNames.count("decl/exporttest/guisurf1") > 0);
EXPECT_FALSE(foundNames.count("decl/numbers/0") > 0);
EXPECT_FALSE(foundNames.count("decl/numbers/1") > 0);
EXPECT_FALSE(foundNames.count("decl/numbers/2") > 0);
// testdecl2 should be listed
EXPECT_TRUE(foundNames.count("decltable1") > 0);
EXPECT_TRUE(foundNames.count("decltable2") > 0);
EXPECT_TRUE(foundNames.count("decltable3") > 0);
}
TEST_F(DeclManagerTest, DeclFolderRegistration)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, "decl");
checkKnownTestDeclNames();
}
TEST_F(DeclManagerTest, DeclFolderRegistrationWithoutSlash)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
// Omit the trailing slash, should work just fine
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, "testdecls", ".decl");
checkKnownTestDeclNames();
}
TEST_F(DeclManagerTest, DeclFolderRegistrationWithoutExtensionDot)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
// Add no dot to the file extension, should work just fine
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, "decl");
checkKnownTestDeclNames();
}
// Test a second decl creator
TEST_F(DeclManagerTest, DeclTypeCreatorRegistration)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclType("testdecl2", std::make_shared<TestDeclaration2Creator>());
// Parse this folder, it contains decls of type testdecl and testdecl2 in the .decl files
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
checkKnownTestDeclNames();
checkKnownTestDecl2Names();
}
// Test that a creator coming late to the party is immediately fed with the buffered decl blocks
TEST_F(DeclManagerTest, LateCreatorRegistration)
{
auto creator = std::make_shared<TestDeclarationCreator>();
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
// Parse this folder, it contains decls of type testdecl and testdecl2 in the .decl files
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
// Let the testdecl creator finish its work
getAllDeclNames(decl::Type::TestDecl);
auto foundTestDecl2Names = getAllDeclNames(decl::Type::TestDecl2);
EXPECT_FALSE(foundTestDecl2Names.count("decltable1") > 0);
EXPECT_FALSE(foundTestDecl2Names.count("decltable2") > 0);
EXPECT_FALSE(foundTestDecl2Names.count("decltable3") > 0);
// Register the testdecl2 creator now, it should be used by the decl manager to parse the missing pieces
GlobalDeclarationManager().registerDeclType("testdecl2", std::make_shared<TestDeclaration2Creator>());
// Everything should be registered now
checkKnownTestDecl2Names();
}
TEST_F(DeclManagerTest, CreatorRegistrationDuringRunningThread)
{
auto creator = std::make_shared<TestDeclarationCreator>();
bool testDecl2Registered = false;
// When the first testdecl is created, we register the decl2 type
creator->creationCallback = [&]()
{
if (!testDecl2Registered)
{
// Register the testdecl2 creator now, it should be used by the decl manager
// (after the running thread is done) to parse the missing pieces
GlobalDeclarationManager().registerDeclType("testdecl2", std::make_shared<TestDeclaration2Creator>());
testDecl2Registered = true;
}
};
GlobalDeclarationManager().registerDeclType("testdecl", creator);
// We assume we know nothing about the decl2 typed table yet
auto foundTestDecl2Names = getAllDeclNames(decl::Type::TestDecl2);
EXPECT_FALSE(foundTestDecl2Names.count("decltable1") > 0);
// Parse this folder, it contains decls of type testdecl and testdecl2 in the .decl files
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
getAllDeclNames(decl::Type::TestDecl);
EXPECT_TRUE(testDecl2Registered) << "Callback to register testdecl2 has never been invoked";
// Everything should be registered now
checkKnownTestDecl2Names();
}
TEST_F(DeclManagerTest, DeclsReloadedSignalAfterInitialParse)
{
auto creator = std::make_shared<TestDeclarationCreator>();
GlobalDeclarationManager().registerDeclType("testdecl", creator);
bool testdeclSignalFired = false;
bool testdecl2SignalFired = false;
GlobalDeclarationManager().signal_DeclsReloaded(decl::Type::TestDecl).connect(
[&]() { testdeclSignalFired = true; }
);
GlobalDeclarationManager().signal_DeclsReloaded(decl::Type::TestDecl2).connect(
[&]() { testdecl2SignalFired = true; }
);
// Parse this folder, it contains decls of type testdecl and testdecl2 in the .decl files
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
// Force the threads to be finished
GlobalDeclarationManager().foreachDeclaration(decl::Type::TestDecl, [](const decl::IDeclaration::Ptr&) {});
EXPECT_TRUE(algorithm::waitUntil([&]() { return testdeclSignalFired; })) << "Time out waiting for the flag";
EXPECT_TRUE(testdeclSignalFired) << "testdecl signal should have fired by the time parsing has finished";
EXPECT_FALSE(testdecl2SignalFired) << "testdecl2-type Signal should not have been fired";
}
TEST_F(DeclManagerTest, DeclsReloadedSignals)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclType("testdecl2", std::make_shared<TestDeclaration2Creator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
// Force the threads to be finished
GlobalDeclarationManager().foreachDeclaration(decl::Type::TestDecl, [](const decl::IDeclaration::Ptr&) {});
GlobalDeclarationManager().foreachDeclaration(decl::Type::TestDecl2, [](const decl::IDeclaration::Ptr&) {});
bool testdeclsReloadingFired = false;
bool testdecl2sReloadingFired = false;
GlobalDeclarationManager().signal_DeclsReloading(decl::Type::TestDecl).connect(
[&]() { testdeclsReloadingFired = true; }
);
GlobalDeclarationManager().signal_DeclsReloading(decl::Type::TestDecl2).connect(
[&]() { testdecl2sReloadingFired = true; }
);
auto callingThreadId = std::this_thread::get_id();
std::thread::id signalThreadId;
std::size_t testdeclsReloadedFireCount = 0;
bool testdecl2sReloadedFired = false;
GlobalDeclarationManager().signal_DeclsReloaded(decl::Type::TestDecl).connect(
[&]()
{
++testdeclsReloadedFireCount;
signalThreadId = std::this_thread::get_id();
}
);
GlobalDeclarationManager().signal_DeclsReloaded(decl::Type::TestDecl2).connect(
[&]() { testdecl2sReloadedFired = true; }
);
GlobalDeclarationManager().reloadDeclarations();
EXPECT_TRUE(testdeclsReloadingFired) << "testdecl signal should have fired before reloadDecls";
EXPECT_TRUE(testdecl2sReloadingFired) << "testdecl2 signal should have fired before reloadDecls";
EXPECT_EQ(testdeclsReloadedFireCount, 1) << "testdecl signal should have fired once after reloadDecls";
EXPECT_TRUE(testdecl2sReloadedFired) << "testdecl2 signal should have fired after reloadDecls";
// The signal has to be fire on the same thread as the calling code
EXPECT_EQ(callingThreadId, signalThreadId) << "Reloaded Signal should have been fired on the calling thread.";
}
TEST_F(DeclManagerTest, FindDeclaration)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
EXPECT_TRUE(GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/exporttest/guisurf1"));
EXPECT_FALSE(GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/nonexistent"));
// Find declaration is case-insensitive
EXPECT_EQ(GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/exporttest/guisurf1"),
GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "Decl/eXporTTest/gUISURF1"));
}
TEST_F(DeclManagerTest, FindOrCreateDeclaration)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
EXPECT_TRUE(GlobalDeclarationManager().findOrCreateDeclaration(decl::Type::TestDecl, "decl/exporttest/guisurf1"));
EXPECT_FALSE(GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/nonexistent")) <<
"decl/nonexistent should not be present in this test setup";
auto defaultDecl = GlobalDeclarationManager().findOrCreateDeclaration(decl::Type::TestDecl, "decl/nonexistent");
EXPECT_TRUE(defaultDecl) << "Declaration manager didn't create a defaulted declaration";
EXPECT_EQ(defaultDecl->getDeclType(), decl::Type::TestDecl);
EXPECT_EQ(defaultDecl->getDeclName(), "decl/nonexistent");
EXPECT_EQ(defaultDecl->getBlockSyntax().contents, std::string());
EXPECT_EQ(defaultDecl->getBlockSyntax().fileInfo.visibility, vfs::Visibility::HIDDEN);
EXPECT_EQ(GlobalDeclarationManager().findOrCreateDeclaration(decl::Type::TestDecl, "decl/nonexistent"), defaultDecl)
<< "We expect the created declaration to be persistent";
EXPECT_EQ(GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/nonexistent"), defaultDecl)
<< "We expect the created declaration to be persistent";
}
TEST_F(DeclManagerTest, FindOrCreateUnknownDeclarationType)
{
// Unknown types should yield an exception
EXPECT_THROW(GlobalDeclarationManager().findOrCreateDeclaration(decl::Type::None, "decl/nonexistent"), std::invalid_argument);
EXPECT_THROW(GlobalDeclarationManager().findOrCreateDeclaration(decl::Type::Undetermined, "decl/nonexistent"), std::invalid_argument);
}
TEST_F(DeclManagerTest, DeclarationMetadata)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
auto decl = GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/exporttest/guisurf1");
EXPECT_TRUE(decl);
EXPECT_EQ(decl->getDeclType(), decl::Type::TestDecl);
EXPECT_EQ(decl->getDeclFilePath(), "testdecls/exporttest.decl");
EXPECT_EQ(decl->getModName(), RadiantTest::DEFAULT_GAME_TYPE);
}
inline void expectDeclIsPresent(decl::Type type, const std::string& declName)
{
EXPECT_TRUE(GlobalDeclarationManager().findDeclaration(type, declName))
<< declName << " should be present";
}
inline void expectDeclIsNotPresent(decl::Type type, const std::string& declName)
{
EXPECT_FALSE(GlobalDeclarationManager().findDeclaration(type, declName))
<< declName << " should not be present";
}
inline void expectDeclContains(decl::Type type, const std::string& declName, const std::string& expectedContents)
{
auto decl = GlobalDeclarationManager().findDeclaration(type, declName);
EXPECT_TRUE(decl) << declName << " should be present";
EXPECT_NE(decl->getBlockSyntax().contents.find(expectedContents), std::string::npos)
<< declName << " should contain the expected contents " << expectedContents;
}
// Decl must still be present, but not contain the given string
inline void expectDeclDoesNotContain(decl::Type type, const std::string& declName, const std::string& contents)
{
auto decl = GlobalDeclarationManager().findDeclaration(type, declName);
EXPECT_TRUE(decl) << declName << " should be present";
EXPECT_EQ(decl->getBlockSyntax().contents.find(contents), std::string::npos)
<< declName << " should NOT contain " << contents;
}
// EntityDef is treated the same as EnTiTyDeF and entitydef
TEST_F(DeclManagerTest, DeclTypenamesAreCaseInsensitive)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
expectDeclIsPresent(decl::Type::TestDecl, "decl/numbers/3");
expectDeclContains(decl::Type::TestDecl, "decl/numbers/3", "diffusemap textures/numbers/3");
}
TEST_F(DeclManagerTest, ReloadDeclarationDetectsChangedFile)
{
TemporaryFile tempFile(_context.getTestProjectPath() + "testdecls/temp_file.decl");
tempFile.setContents(R"(
decl/temporary/11
{
diffusemap textures/temporary/11
}
decl/temporary/12
{
diffusemap textures/temporary/12
}
)");
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/11");
expectDeclContains(decl::Type::TestDecl, "decl/temporary/12", "diffusemap textures/temporary/12");
expectDeclIsNotPresent(decl::Type::TestDecl, "decl/temporary/13");
// Change the file, change temp12, remove temp11 and add temp13 instead
tempFile.setContents(R"(
decl/temporary/12
{
diffusemap textures/changed_temporary/12
}
testdecl decl/temporary/13
{
diffusemap textures/temporary/13
}
)");
GlobalDeclarationManager().reloadDeclarations();
// Check the changes in temp12
expectDeclContains(decl::Type::TestDecl, "decl/temporary/12", "diffusemap textures/changed_temporary/12");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/13");
expectDeclDoesNotContain(decl::Type::TestDecl, "decl/temporary/11", "diffusemap textures/temporary/11");
}
TEST_F(DeclManagerTest, ReloadDeclarationDetectsNewFile)
{
TemporaryFile tempFile(_context.getTestProjectPath() + "testdecls/temp_file.decl");
tempFile.setContents(R"(
testdecl decl/temporary/11 { diffusemap textures/temporary/11 }
testdecl decl/temporary/12 { diffusemap textures/temporary/12 }
)");
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/12");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/11");
expectDeclIsNotPresent(decl::Type::TestDecl, "decl/temporary/13");
// Create a new file and reload decls
TemporaryFile tempFile2(_context.getTestProjectPath() + "testdecls/temp_file2.decl");
tempFile2.setContents(R"(
testdecl decl/temporary/13 { diffusemap textures/temporary/13 }
testdecl decl/temporary/14 { diffusemap textures/temporary/14 }
)");
GlobalDeclarationManager().reloadDeclarations();
// All the decls should be present now
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/11");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/12");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/13");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/14");
}
TEST_F(DeclManagerTest, ReloadDeclarationDetectsRemovedFile)
{
TemporaryFile tempFile(_context.getTestProjectPath() + "testdecls/temp_file.decl");
tempFile.setContents(R"(
testdecl decl/temporary/11 { diffusemap textures/temporary/11 }
testdecl decl/temporary/12 { diffusemap textures/temporary/12 }
)");
auto tempFile2 = std::make_shared<TemporaryFile>(_context.getTestProjectPath() + "testdecls/temp_file2.decl");
tempFile2->setContents(R"(
testdecl decl/temporary/13 { diffusemap textures/temporary/13 }
testdecl decl/temporary/14 { diffusemap textures/temporary/14 }
)");
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/11");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/12");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/13");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/14");
// Remove one file and reload decls
tempFile2.reset();
GlobalDeclarationManager().reloadDeclarations();
// All decls should still be present
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/11");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/12");
expectDeclDoesNotContain(decl::Type::TestDecl, "decl/temporary/13", "diffusemap textures/temporary/13");
expectDeclDoesNotContain(decl::Type::TestDecl, "decl/temporary/14", "diffusemap textures/temporary/14");
}
// Have one declaration moved from one existing file to another
TEST_F(DeclManagerTest, ReloadDeclarationDetectsMovedDecl)
{
TemporaryFile tempFile(_context.getTestProjectPath() + "testdecls/temp_file.decl");
TemporaryFile tempFile2(_context.getTestProjectPath() + "testdecls/temp_file2.decl");
tempFile.setContents(R"(
testdecl decl/temporary/11 { diffusemap textures/temporary/11 }
testdecl decl/temporary/12 { diffusemap textures/temporary/12 }
)");
tempFile2.setContents(R"(
testdecl decl/temporary/13 { diffusemap textures/temporary/13 }
)");
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/11");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/12");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/13");
// Move a decl from the first file to the second
tempFile.setContents(R"(
testdecl decl/temporary/11 { diffusemap textures/temporary/11 }
)");
tempFile2.setContents(R"(
testdecl decl/temporary/13 { diffusemap textures/temporary/13 }
testdecl decl/temporary/12 { diffusemap textures/changed_temporary/12 } // changed the decl
)");
GlobalDeclarationManager().reloadDeclarations();
// All decls should still be present, contents of 12 should have changed
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/11");
expectDeclContains(decl::Type::TestDecl, "decl/temporary/12", "diffusemap textures/changed_temporary/12");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/13");
}
TEST_F(DeclManagerTest, ReloadDeclarationsIncreasesParseStamp)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
auto decl = GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/exporttest/guisurf1");
EXPECT_TRUE(decl) << "Couldn't find the declaration decl/exporttest/guisurf1";
auto firstParseStamp = decl->getParseStamp();
GlobalDeclarationManager().reloadDeclarations();
decl = GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/exporttest/guisurf1");
EXPECT_TRUE(decl) << "Couldn't find the declaration decl/exporttest/guisurf1";
EXPECT_NE(decl->getParseStamp(), firstParseStamp) << "Parse stamp should have changed on reload";
}
// A declaration that is removed after reloadDecls should have its visibility set to hidden
TEST_F(DeclManagerTest, RemovedDeclarationIsHidden)
{
TemporaryFile tempFile(_context.getTestProjectPath() + "testdecls/temp_file.decl");
tempFile.setContents(R"(
testdecl decl/temporary/11 { diffusemap textures/temporary/11 }
testdecl decl/temporary/12 { diffusemap textures/temporary/12 }
)");
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
expectDeclIsPresent(decl::Type::TestDecl, "decl/temporary/11");
// Remove decl/temporary/11
tempFile.setContents(R"(
testdecl decl/temporary/13 { diffusemap textures/temporary/13 }
testdecl decl/temporary/12 { diffusemap textures/temporary/12 }
)");
GlobalDeclarationManager().reloadDeclarations();
// the decl decl/temporary/11 should be there, but hidden
auto decl = GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/temporary/11");
EXPECT_TRUE(decl) << "Declaration should still be registered after reloadDecls";
EXPECT_TRUE(decl->getBlockSyntax().contents.empty()) << "Declaration should be empty after reloadDecls";
EXPECT_EQ(decl->getBlockSyntax().fileInfo.visibility, vfs::Visibility::HIDDEN) << "Declaration should be hidden after reloadDecls";
}
TEST_F(DeclManagerTest, DeclarationPrecedence)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
expectDeclIsPresent(decl::Type::TestDecl, "decl/precedence_test/1");
// The first decl in the file precedence_test1.decl takes precedence over any decls
// declared in the same file or other files sorted after precedence_test1.decl
expectDeclContains(decl::Type::TestDecl, "decl/precedence_test/1", "diffusemap textures/numbers/1");
}
TEST_F(DeclManagerTest, RemoveDeclaration)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
expectDeclIsPresent(decl::Type::TestDecl, "decl/removal/1");
// Keep a local reference to the decl around to see what happens with its contents after removal
auto decl = GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/removal/1");
// Create a backup copy of the decl file we're going to manipulate
BackupCopy backup(_context.getTestProjectPath() + decl->getDeclFilePath());
GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/removal/1");
expectDeclIsNotPresent(decl::Type::TestDecl, "decl/removal/1");
// The held reference should be cleared
EXPECT_TRUE(decl->getBlockSyntax().name.empty());
EXPECT_TRUE(decl->getBlockSyntax().typeName.empty());
EXPECT_TRUE(decl->getBlockSyntax().contents.empty());
EXPECT_TRUE(decl->getBlockSyntax().fileInfo.name.empty());
EXPECT_TRUE(decl->getBlockSyntax().fileInfo.topDir.empty());
EXPECT_TRUE(decl->getBlockSyntax().fileInfo.fullPath().empty());
EXPECT_EQ(decl->getBlockSyntax().fileInfo.visibility, vfs::Visibility::HIDDEN);
}
// Removing a decl defined in a PK4 file will throw
TEST_F(DeclManagerTest, RemoveDeclarationInPk4File)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
auto decl = GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/export/0");
EXPECT_TRUE(decl) << "decl/export/0 must be present";
EXPECT_FALSE(decl->getBlockSyntax().fileInfo.getIsPhysicalFile()) << "decl/export/0 should be in a PK4 file";
// Attempting to remove the decl will throw
EXPECT_THROW(GlobalDeclarationManager().removeDeclaration(decl->getDeclType(), decl->getDeclName()),
std::logic_error) << "Removing a PK4 decl should throw";
}
// Removing a decl defined in a physical file will succeed
TEST_F(DeclManagerTest, RemoveDeclarationFromPhysicalFile)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
auto decl = GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/removal/1");
expectDeclIsPresent(decl::Type::TestDecl, "decl/removal/1");
auto originalSyntax = decl->getBlockSyntax();
EXPECT_TRUE(originalSyntax.fileInfo.getIsPhysicalFile()) << "decl/removal/1 must be in a physical file";
auto fileContents = algorithm::loadTextFromVfsFile(decl->getDeclFilePath());
EXPECT_NE(fileContents.find(originalSyntax.contents), std::string::npos) << "Decl source not found";
// Create a backup copy of the decl file we're going to manipulate
BackupCopy backup(_context.getTestProjectPath() + decl->getDeclFilePath());
// Remove the decl, it should remove the source from the file
GlobalDeclarationManager().removeDeclaration(decl->getDeclType(), decl->getDeclName());
auto contentsAfterRemoval = algorithm::loadTextFromVfsFile(decl->getDeclFilePath());
EXPECT_NE(contentsAfterRemoval, fileContents) << "File contents should have been changed";
EXPECT_EQ(contentsAfterRemoval.find(originalSyntax.contents), std::string::npos) << "Decl source should be gone";
}
// Removing a decl will keep leading comment lines that are separated with an empty line
TEST_F(DeclManagerTest, RemoveDeclarationPreservesSeparatedLeadingComments)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
// Create a backup copy of the decl file we're going to manipulate
auto fullPath = _context.getTestProjectPath() + "testdecls/removal_tests.decl";
BackupCopy backup(fullPath);
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "// Comments at the beginning of the file with an empty line in between"));
// Remove decl/removal/0. This should remove the decl, but the comment at the beginning of the file should remain intact
GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/removal/0");
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "// Comments at the beginning of the file with an empty line in between"));
EXPECT_FALSE(algorithm::fileContainsText(fullPath, R"(decl/removal/0
{
diffusemap textures/removal/0
})"));
// Similar situation with decls/removal/5
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "// Comment with a line before the start of the decl decl/removal/5"));
EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(testdecl decl/removal/5 { // a comment in the same line as the opening brace
diffusemap textures/removal/5
})"));
GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/removal/5");
EXPECT_FALSE(algorithm::fileContainsText(fullPath, R"(testdecl decl/removal/5 { // a comment in the same line as the opening brace
diffusemap textures/removal/5
})"));
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "// Comment with a line before the start of the decl decl/removal/5"));
}
// Removing a decl will keep trailing comment lines and remove leading C-style comments
TEST_F(DeclManagerTest, RemoveDeclarationRemovesLeadingCStyleComment)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
// Create a backup copy of the decl file we're going to manipulate
auto fullPath = _context.getTestProjectPath() + "testdecls/removal_tests.decl";
BackupCopy backup(fullPath);
// decl/removal/1 has leading C-style comment, and a trailing single line comment
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "/* Without \"testdecl\" typename, C-style comment */"));
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "// Some comments after decl/removal/1"));
GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/removal/1");
// Leading comment should be gone, trailing comment should stay
EXPECT_FALSE(algorithm::fileContainsText(fullPath, R"(decl/removal/1
{
diffusemap textures/removal/1
})"));
EXPECT_FALSE(algorithm::fileContainsText(fullPath, "/* Without \"testdecl\" typename, C-style comment */"));
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "// Some comments after decl/removal/1"));
}
// Removing a decl will keep trailing comment lines and remove leading single-line comments
TEST_F(DeclManagerTest, RemoveDeclarationRemovesLeadingSingleLineComment)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
// Create a backup copy of the decl file we're going to manipulate
auto fullPath = _context.getTestProjectPath() + "testdecls/removal_tests.decl";
BackupCopy backup(fullPath);
// decl/removal/3 has leading single-line comment
EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(// Comment before decl/removal/3)"));
EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(TestDecl decl/removal/3
{
diffusemap textures/removal/3
})"));
GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/removal/3");
EXPECT_FALSE(algorithm::fileContainsText(fullPath, R"(// Comment before decl/removal/3)"));
EXPECT_FALSE(algorithm::fileContainsText(fullPath, R"(TestDecl decl/removal/3
{
diffusemap textures/removal/3
})"));
// This one is a trailing comment, and separated with an empty line too
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "// Comment with a line before the start of the decl decl/removal/5"));
// decl/removal/6 has leading single-line comment, decl 7 is right afterwards
EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(// Everything in the same line (before decl/removal/6))"));
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "testdecl decl/removal/6 { diffusemap textures/removal/6 }"));
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "testdecl decl/removal/7 { diffusemap textures/removal/7 }"));
GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/removal/6");
// Leading comment should be gone, trailing decl should remain intact
EXPECT_FALSE(algorithm::fileContainsText(fullPath, R"(// Everything in the same line (before decl/removal/6))"));
EXPECT_FALSE(algorithm::fileContainsText(fullPath, "testdecl decl/removal/6 { diffusemap textures/removal/6 }"));
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "testdecl decl/removal/7 { diffusemap textures/removal/7 }"));
}
// Removing a decl will keep trailing comment lines and remove leading multi-line comments
TEST_F(DeclManagerTest, RemoveDeclarationRemovesLeadingMultilineComment)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
// Create a backup copy of the decl file we're going to manipulate
auto fullPath = _context.getTestProjectPath() + "testdecls/removal_tests.decl";
BackupCopy backup(fullPath);
// decl/removal/2 has leading multiline comment, and a trailing single line comment
EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(/**
A multiline comment before this decl
*/)"));
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "// Some comments after decl/removal/2"));
GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/removal/2");
// Leading comment should be gone, trailing comment should stay
EXPECT_FALSE(algorithm::fileContainsText(fullPath, R"(testdecl decl/removal/2
{
diffusemap textures/removal/2
})"));
EXPECT_FALSE(algorithm::fileContainsText(fullPath, R"(/**
A multiline comment before this decl
*/)"));
EXPECT_TRUE(algorithm::fileContainsText(fullPath, "// Some comments after decl/removal/2"));
}
// Multiple comments preceding the decl with minor whitespace in between
TEST_F(DeclManagerTest, RemoveDeclarationRemovesLeadingMixedComment)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
// Create a backup copy of the decl file we're going to manipulate
auto fullPath = _context.getTestProjectPath() + "testdecls/removal_tests.decl";
BackupCopy backup(fullPath);
// decl/removal/3a has leading multiline comment, and a trailing single line comment
EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(// Multiple comment lines before decl/removal/a3
/* mixed style comments too */
// multiple comment with some whitespace at the start of each line
// multiple comment with some whitespace at the start of each line)"));
GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/removal/3a");
// Leading comment should be gone, trailing comment should stay
EXPECT_FALSE(algorithm::fileContainsText(fullPath, R"(decl/removal/3a
{
diffusemap textures/removal/a3
})"));
EXPECT_FALSE(algorithm::fileContainsText(fullPath, R"(// Multiple comment lines before decl/removal/a3
/* mixed style comments too */
// multiple comment with some whitespace at the start of each line
// multiple comment with some whitespace at the start of each line)"));
// Safety check that nothing else got removed (including whitespace)
EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(
// Comment with a line before the start of the decl decl/removal/5)"));
EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(TestDecl decl/removal/3
{
diffusemap textures/removal/3
}
)"));
}
// There's an evil misleading commented out declaration decl/removal/9 in the file
// right before the actual, uncommented one
TEST_F(DeclManagerTest, RemoveDeclarationIgnoresCommentedContent)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
// Create a backup copy of the decl file we're going to manipulate
auto fullPath = _context.getTestProjectPath() + "testdecls/removal_tests.decl";
BackupCopy backup(fullPath);
// decl/removal/9 has a commented declaration above the actual one
EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(/*
testdecl decl/removal/9
{
diffusemap textures/old/5
}
*/)"));
expectDeclIsPresent(decl::Type::TestDecl, "decl/removal/9");
GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/removal/9");
EXPECT_TRUE(algorithm::fileContainsText(fullPath, R"(/*
testdecl decl/removal/9
{
diffusemap textures/old/5
}
*/)")) << "The decl manager removed the wrong declaration";
}
// Before overwriting the existing file it will be moved to .bak
TEST_F(DeclManagerTest, RemoveDeclarationCreatesBackupFile)
{
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");
// Create a backup copy of the decl file we're going to manipulate
auto fullPath = _context.getTestProjectPath() + "testdecls/removal_tests.decl";
auto expectedBackupPath = fullPath + ".bak";
// Remove the bak file for this test
fs::remove(expectedBackupPath);
// We want to remove the .bak file at the end of the test
TemporaryFile expectedBakFile(expectedBackupPath);
// A backup copy to restore the decl file to its previous state
BackupCopy backup(fullPath);
// Check that both decls are there