Skip to content

Commit 91f4c8c

Browse files
committed
Migrate Driver Unit Tests to Fingerprints
1 parent 316005d commit 91f4c8c

6 files changed

+20
-20
lines changed

Diff for: lib/Driver/Driver.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,7 @@ populateOutOfDateMap(InputInfoMap &map, llvm::sys::TimePoint<> &LastBuildTime,
547547
// -swift-version argument is handled in the argsHashStr check that
548548
// follows.
549549
CompilationRecordSwiftVersion = value->getValue(scratch);
550-
versionValid = (CompilationRecordSwiftVersion
551-
== version::getSwiftFullVersion(
552-
version::Version::getCurrentLanguageVersion()));
553-
550+
versionValid = CompilationRecordSwiftVersion.equals(version::getSwiftFullVersion(version::Version::getCurrentLanguageVersion()));
554551
} else if (keyStr == compilation_record::getName(TopLevelKey::Options)) {
555552
auto *value = dyn_cast<yaml::ScalarNode>(i->getValue());
556553
if (!value)

Diff for: unittests/Driver/FineGrainedDependencyGraphTests.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,8 @@ TEST(ModuleDepGraph, BaselineForPrintsAndCrossType) {
788788

789789
{
790790
const auto jobs = simulateReload(
791-
graph, &job0, {{NodeKind::nominal, {"A1", "A2"}}}, "changed");
791+
graph, &job0, {{NodeKind::nominal, {"A1", "A2"}}},
792+
Fingerprint{"chchchangesturnandfacethestrange"});
792793
EXPECT_EQ(3u, jobs.size());
793794
EXPECT_TRUE(contains(jobs, &job0));
794795
EXPECT_TRUE(contains(jobs, &job1));

Diff for: unittests/Driver/MockingFineGrainedDependencyGraphs.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ using namespace mocking_fine_grained_dependency_graphs;
2626
void mocking_fine_grained_dependency_graphs::simulateLoad(
2727
ModuleDepGraph &g, const driver::Job *cmd,
2828
const DependencyDescriptions &dependencyDescriptions,
29-
StringRef interfaceHashIfNonEmpty,
29+
Optional<Fingerprint> interfaceHashIfNonEmpty,
3030
const bool hadCompilationError) {
3131
const auto changes = getChangesForSimulatedLoad(
3232
g, cmd, dependencyDescriptions, interfaceHashIfNonEmpty,
@@ -38,13 +38,14 @@ ModuleDepGraph::Changes
3838
mocking_fine_grained_dependency_graphs::getChangesForSimulatedLoad(
3939
ModuleDepGraph &g, const driver::Job *cmd,
4040
const DependencyDescriptions &dependencyDescriptions,
41-
StringRef interfaceHashIfNonEmpty,
41+
Optional<Fingerprint> interfaceHashIfNonEmpty,
4242
const bool hadCompilationError) {
43-
StringRef swiftDeps =
44-
cmd->getOutput().getAdditionalOutputForType(file_types::TY_SwiftDeps);
43+
auto swiftDeps =
44+
cmd->getOutput().getAdditionalOutputForType(file_types::TY_SwiftDeps).str();
4545
assert(!swiftDeps.empty());
46-
StringRef interfaceHash =
47-
interfaceHashIfNonEmpty.empty() ? swiftDeps : interfaceHashIfNonEmpty;
46+
swiftDeps.resize(Fingerprint::DIGEST_LENGTH, 'X');
47+
auto interfaceHash =
48+
interfaceHashIfNonEmpty.getValueOr(Fingerprint{swiftDeps});
4849

4950
SourceManager sm;
5051
DiagnosticEngine diags(sm);
@@ -63,7 +64,7 @@ std::vector<const driver::Job *>
6364
mocking_fine_grained_dependency_graphs::simulateReload(
6465
ModuleDepGraph &g, const driver::Job *cmd,
6566
const DependencyDescriptions &dependencyDescriptions,
66-
StringRef interfaceHashIfNonEmpty,
67+
Optional<Fingerprint> interfaceHashIfNonEmpty,
6768
const bool hadCompilationError) {
6869
const auto changedNodes = getChangesForSimulatedLoad(
6970
g, cmd, dependencyDescriptions, interfaceHashIfNonEmpty,

Diff for: unittests/Driver/MockingFineGrainedDependencyGraphs.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace mocking_fine_grained_dependency_graphs {
6666

6767
void simulateLoad(ModuleDepGraph &g, const driver::Job *cmd,
6868
const DependencyDescriptions &dependencyDescriptions,
69-
StringRef interfaceHashIfNonEmpty = StringRef(),
69+
Optional<Fingerprint> interfaceHashIfNonEmpty = None,
7070
const bool hadCompilationError = false);
7171

7272
/// Same as \ref simulateLoad, but returns the specifically changed nodes or
@@ -75,7 +75,7 @@ void simulateLoad(ModuleDepGraph &g, const driver::Job *cmd,
7575
ModuleDepGraph::Changes
7676
getChangesForSimulatedLoad(ModuleDepGraph &g, const driver::Job *cmd,
7777
const DependencyDescriptions &dependencyDescriptions,
78-
StringRef interfaceHashIfNonEmpty = StringRef(),
78+
Optional<Fingerprint> interfaceHashIfNonEmpty = None,
7979
const bool hadCompilationError = false);
8080

8181
/// Simulates the driver reloading a swiftdeps file after a job has run.
@@ -87,7 +87,7 @@ getChangesForSimulatedLoad(ModuleDepGraph &g, const driver::Job *cmd,
8787
std::vector<const driver::Job *>
8888
simulateReload(ModuleDepGraph &g, const driver::Job *cmd,
8989
const DependencyDescriptions &dependencyDescriptions,
90-
StringRef interfaceHashIfNonEmpty = StringRef(),
90+
Optional<Fingerprint> interfaceHashIfNonEmpty = None,
9191
const bool hadCompilationError = false);
9292

9393
std::vector<const driver::Job *>

Diff for: unittests/Driver/UnitTestSourceFileDepGraphFactory.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ void UnitTestSourceFileDepGraphFactory::addADefinedDecl(StringRef s,
5353
parseADefinedDecl(s, kind, DeclAspect::interface);
5454
if (!key)
5555
return;
56-
StringRef fingerprintString = s.split(fingerprintSeparator).second;
57-
const Optional<StringRef> fingerprint = fingerprintString.empty()
58-
? Optional<StringRef>()
59-
: StringRef(fingerprintString);
56+
auto fingerprintString = s.split(fingerprintSeparator).second.str();
57+
fingerprintString.resize(Fingerprint::DIGEST_LENGTH, 'X');
58+
const Optional<Fingerprint> fingerprint = fingerprintString.empty()
59+
? Optional<Fingerprint>()
60+
: Fingerprint{fingerprintString};
6061

6162
AbstractSourceFileDepGraphFactory::addADefinedDecl(key.getValue(),
6263
fingerprint);

Diff for: unittests/Driver/UnitTestSourceFileDepGraphFactory.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class UnitTestSourceFileDepGraphFactory
2828
public:
2929
UnitTestSourceFileDepGraphFactory(
3030
bool hadCompilationError, StringRef swiftDeps,
31-
StringRef fileFingerprint, bool emitDotFileAfterConstruction,
31+
Fingerprint fileFingerprint, bool emitDotFileAfterConstruction,
3232
const DependencyDescriptions &dependencyDescriptions,
3333
DiagnosticEngine &diags)
3434
: AbstractSourceFileDepGraphFactory(

0 commit comments

Comments
 (0)