File indexing completed on 2025-03-09 05:11:39
0001 /* 0002 SPDX-FileCopyrightText: 2022 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "indextest.h" 0008 #include "gitmanager.h" 0009 #include "testcommon.h" 0010 #include <QTest> 0011 0012 QTEST_GUILESS_MAIN(IndexTest) 0013 0014 IndexTest::IndexTest(QObject *parent) 0015 : QObject{parent} 0016 { 0017 } 0018 0019 void IndexTest::initTestCase() 0020 { 0021 auto path = TestCommon::getTempPath(); 0022 qDebug() << path; 0023 mManager = new Git::Manager; 0024 auto init = mManager->init(path); 0025 QCOMPARE(mManager->path(), path); 0026 QVERIFY(init); 0027 QVERIFY(mManager->isValid()); 0028 0029 TestCommon::initSignature(mManager); 0030 } 0031 0032 void IndexTest::cleanupTestCase() 0033 { 0034 // TestCommon::cleanPath(mManager); 0035 } 0036 0037 void IndexTest::addFile() 0038 { 0039 TestCommon::touch(mManager->path() + "/README.md"); 0040 0041 auto changedFiles = mManager->changedFiles(); 0042 QVERIFY(changedFiles.contains("README.md")); 0043 0044 mManager->addFile("README.md"); 0045 0046 changedFiles = mManager->changedFiles(); 0047 QCOMPARE(changedFiles.value("README.md"), Git::ChangeStatus::Added); 0048 0049 mManager->commit("sample commit"); 0050 0051 changedFiles = mManager->changedFiles(); 0052 QVERIFY(!changedFiles.contains("README.md")); 0053 } 0054 0055 void IndexTest::revertFile() 0056 { 0057 TestCommon::touch(mManager->path() + "/README.md"); 0058 0059 auto changedFiles = mManager->changedFiles(); 0060 QVERIFY(changedFiles.contains("README.md")); 0061 0062 auto ok = mManager->revertFile("README.md"); 0063 QVERIFY(ok); 0064 0065 changedFiles = mManager->changedFiles(); 0066 QVERIFY(!changedFiles.contains("README.md")); 0067 } 0068 0069 void IndexTest::removeFile() 0070 { 0071 auto ok = mManager->removeFile("README.md", false); 0072 QVERIFY(ok); 0073 0074 TestCommon::touch(mManager->path() + "/README.md"); 0075 auto changedFiles = mManager->changedFiles(); 0076 QVERIFY(!changedFiles.contains("README.md")); 0077 } 0078 0079 #include "moc_indextest.cpp"