MCPcopy Create free account
hub / github.com/KDE/kdevelop / testRegisterRepositoryForCurrentBranchChanges

Method testRegisterRepositoryForCurrentBranchChanges

plugins/git/tests/test_git.cpp:718–836  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

716}
717
718void GitInitTest::testRegisterRepositoryForCurrentBranchChanges()
719{
720 repoInit();
721 addFiles();
722 commitFiles();
723
724 // Remove the trailing slash so that the QCOMPARE(X, baseUrl) calls below succeed.
725 const auto baseUrl = QUrl::fromLocalFile(gitTest_BaseDir().chopped(1));
726
727 QSignalSpy branchChangedSpy(m_plugin, &GitPlugin::repositoryBranchChanged);
728
729 const auto events = runSynchronously(m_plugin->log(baseUrl, VcsRevision::createSpecialRevision(VcsRevision::Base),
730 VcsRevision::createSpecialRevision(VcsRevision::Start)))
731 .toList();
732 QCOMPARE(events.size(), 2); // commitFiles() creates two commits
733 std::vector<VcsRevision> revisions;
734 revisions.reserve(events.size());
735 std::transform(events.cbegin(), events.cend(), std::back_inserter(revisions), [](const QVariant& event) {
736 return event.value<VcsEvent>().revision();
737 });
738
739 const auto master = QStringLiteral("master");
740 const auto branch1 = QStringLiteral("branch1");
741 const auto branch2 = QStringLiteral("branch2");
742 // The master branch already exists, create two more branches.
743 for (const auto* const branch : {&branch1, &branch2}) {
744 const auto& revision = branch == &branch1 ? revisions.front() : revisions.back();
745 auto* const job = m_plugin->branch(baseUrl, revision, *branch);
746 VERIFYJOB(job);
747 }
748
749#define SWITCH_BRANCH(branchName) \
750 do { \
751 timeSwitchingBranch(m_plugin, baseUrl, branchName); \
752 RETURN_IF_TEST_FAILED(); \
753 } while (false)
754
755 // The signal GitPlugin::repositoryBranchChanged() is emitted
756 // after a delay of one second. Wait two seconds to be safe.
757 constexpr auto signalWaitInterval = 2000;
758
759 const auto verifyZeroSignalsEvenAfterWait = [&branchChangedSpy] {
760 QCOMPARE(branchChangedSpy.count(), 0);
761 QTest::qWait(signalWaitInterval);
762 QCOMPARE(branchChangedSpy.count(), 0);
763 };
764
765 const auto verifyAndRemoveSingleSignalAfterWait = [&branchChangedSpy, &baseUrl] {
766 QCOMPARE(branchChangedSpy.count(), 0); // the signal is emitted after a delay
767 QTest::qWait(signalWaitInterval);
768 QCOMPARE(branchChangedSpy.count(), 1);
769 QCOMPARE(branchChangedSpy.takeFirst().constFirst().toUrl(), baseUrl); // verify and remove the signal
770 QCOMPARE(branchChangedSpy.count(), 0);
771 };
772
773#define VERIFY_ZERO_SIGNALS_EVEN_AFTER_WAIT() \
774 do { \
775 verifyZeroSignalsEvenAfterWait(); \

Callers

nothing calls this directly

Calls 15

gitTest_BaseDirFunction · 0.85
transformFunction · 0.85
runCommandFunction · 0.85
branchMethod · 0.80
prettyValueMethod · 0.80
runSynchronouslyFunction · 0.50
toListMethod · 0.45
logMethod · 0.45
sizeMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected