SVCS - English Documentation
Loading...
Searching...
No Matches
svcs::test::cli::UndoCommandTest Class Reference

Google Test fixture for running integration tests against the UndoCommand. More...

#include <IntUndoCommandTest.hxx>

Inheritance diagram for svcs::test::cli::UndoCommandTest:

Protected Member Functions

void SetUp () override
 Sets up the testing environment before each test.
void TearDown () override
 Tears down the testing environment after each test.
void createTestFile (const std::string &filename, const std::string &content) const
 Creates a test file with specified content in the temporary directory.
void createTestDirectory (const std::string &dirname) const
 Creates a test directory in the temporary location.
void stageFiles (const std::vector< std::string > &files)
 Stages a list of files using the RepositoryManager's staging logic.
bool createTestCommit (const std::string &message)
 Creates a new commit (save) with a specified message.

Static Protected Member Functions

static bool containsMessage (const std::vector< Event > &notifications, const std::string &message)
 Checks if a specific message (substring) exists in any event notification.
static int countMessages (const std::vector< Event > &notifications, const std::string &message)
 Counts the occurrences of a specific message (substring) across all event notifications.
static void simulateUserInput (const std::string &input)
 Simulates user input by pushing the string into the mock event bus's input queue.

Protected Attributes

std::shared_ptr< MockSubjectmockEventBus
 Shared pointer to the mock event bus (observer/input simulator).
std::shared_ptr< RepositoryManagerrepoManager
 Shared pointer to the repository core logic component.
std::unique_ptr< UndoCommandcommand
 Unique pointer to the command being tested.
std::filesystem::path testDir
 Path to the temporary test repository directory.

Detailed Description

Google Test fixture for running integration tests against the UndoCommand.

This fixture provides the necessary infrastructure for testing the undo command:

  • SetUp/TearDown: Manage a temporary SVCS repository directory.
  • Core Components: Instances of MockSubject (for event bus/output/input simulation) and RepositoryManager (for core logic).
  • Helper Methods: Simplify file manipulation, staging, committing, and verification of notifications.

Member Function Documentation

◆ containsMessage()

bool svcs::test::cli::utils::UndoCommandTest::containsMessage ( const std::vector< Event > & notifications,
const std::string & message )
staticprotected

Checks if a specific message (substring) exists in any event notification.

Parameters
notificationsThe list of captured events.
messageThe substring to search for.
Returns
true if the message is found in any notification, false otherwise.

◆ countMessages()

int svcs::test::cli::utils::UndoCommandTest::countMessages ( const std::vector< Event > & notifications,
const std::string & message )
staticprotected

Counts the occurrences of a specific message (substring) across all event notifications.

Parameters
notificationsThe list of captured events.
messageThe substring to count.
Returns
The number of events containing the substring.

◆ createTestCommit()

bool svcs::test::cli::utils::UndoCommandTest::createTestCommit ( const std::string & message)
protected

Creates a new commit (save) with a specified message.

Internally stages files (if needed) and calls the repository manager's commit logic.

Parameters
messageThe commit message.
Returns
true if the commit was successful, false otherwise.

◆ createTestDirectory()

void svcs::test::cli::utils::UndoCommandTest::createTestDirectory ( const std::string & dirname) const
protected

Creates a test directory in the temporary location.

Parameters
dirnameThe relative path/name of the directory.

◆ createTestFile()

void svcs::test::cli::utils::UndoCommandTest::createTestFile ( const std::string & filename,
const std::string & content ) const
protected

Creates a test file with specified content in the temporary directory.

Parameters
filenameThe relative path/name of the file.
contentThe content to write to the file.

◆ SetUp()

void svcs::test::cli::utils::UndoCommandTest::SetUp ( )
overrideprotected

Sets up the testing environment before each test.

Initializes components, creates the temporary directory, and initializes the repository.

◆ simulateUserInput()

void svcs::test::cli::utils::UndoCommandTest::simulateUserInput ( const std::string & input)
staticprotected

Simulates user input by pushing the string into the mock event bus's input queue.

This is crucial for testing the confirmation prompt in the UndoCommand.

Parameters
inputThe string to simulate as user input (e.g., "y\n" or "n\n").

◆ stageFiles()

void svcs::test::cli::utils::UndoCommandTest::stageFiles ( const std::vector< std::string > & files)
protected

Stages a list of files using the RepositoryManager's staging logic.

Parameters
filesA vector of file names to stage.

◆ TearDown()

void svcs::test::cli::utils::UndoCommandTest::TearDown ( )
overrideprotected

Tears down the testing environment after each test.

Cleans up the temporary directory and restores the working path.


The documentation for this class was generated from the following files: