Skip to content

Commit

Permalink
Adding unit tests on the new clip --best option
Browse files Browse the repository at this point in the history
  • Loading branch information
lerignoux committed Jul 25, 2020
1 parent 07f6f09 commit 4099066
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cli/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int Clip::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<
return EXIT_FAILURE;
} else {
bestEntryPath = (results.isEmpty()) ? args.at(1) : results[0];
err << QObject::tr("Matching \"%1\" entry used.").arg(bestEntryPath) << endl;
out << QObject::tr("Matching \"%1\" entry used.").arg(bestEntryPath) << endl;
}
} else {
bestEntryPath = args.at(1);
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,20 @@ void TestCli::testClip()
setInput("a");
execCmd(clipCmd, {"clip", m_dbFile2->fileName(), "--attribute", "Username", "--totp", "/Sample Entry"});
QVERIFY(m_stderr->readAll().contains("ERROR: Please specify one of --attribute or --totp, not both.\n"));

// Best option
setInput("a");
execCmd(clipCmd, {"clip", m_dbFile->fileName(), "/Sample", "-b"});
QCOMPARE(m_stdout->readAll(), QByteArray());
QVERIFY(clipCmd.name.isEmpty());
QVERIFY(m_stderr->readAll().contains("Sample Entry"));
QVERIFY(m_stderr->readAll().contains("Sample Entry 1"));
QVERIFY(m_stderr->readAll().contains("Sample Entry 2"));

setInput("a");
execCmd(clipCmd, {"clip", m_dbFile->fileName(), "/Entry 1", "-b"});
QCOMPARE(m_stderr->readAll(), QByteArray());
QTRY_COMPARE(clipboard->text(), QString("Password"));
}

void TestCli::testCreate()
Expand Down

0 comments on commit 4099066

Please sign in to comment.