Skip to content

Commit

Permalink
Added Status test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrily committed May 26, 2018
1 parent 5adbe8d commit 5225d24
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests/InitTest/InitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <AppKit.h>

#include "../../GitCommand/Init.h"

#define PATH "/boot/home/InitTest"
#define GIT_PATH "/boot/home/InitTest/.git"

Expand Down
1 change: 0 additions & 1 deletion tests/InitTest/InitTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include "../../GitCommand/Init.h"

using namespace std;

Expand Down
Binary file modified tests/InitTest/InitTest.o
Binary file not shown.
Binary file removed tests/InitTest/inittest.o
Binary file not shown.
Binary file modified tests/InitTest/test
Binary file not shown.
85 changes: 85 additions & 0 deletions tests/StatusTest/StatusTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "StatusTest.h"

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

#include <SupportKit.h>

#include "../../GitCommand/Init.h"

#define PATH "/boot/home/StatusTest"

CPPUNIT_TEST_SUITE_REGISTRATION(StatusTest);

void
StatusTest::setUp(void)
{
// Create a git repo at PATH
Init::InitRepo(PATH);

char command[1024];

// Add initial files
sprintf(command, "touch %s/mod", PATH);
system(command);
sprintf(command, "touch %s/del", PATH);
system(command);

// Add files to repo
sprintf(command, "(cd %s && git add --all)", PATH);
system(command);

// Add initial commit
sprintf(command, "(cd %s && git commit -m \"Initial commit\")", PATH);
system(command);

// Add a file
sprintf(command, "touch %s/nf", PATH);
system(command);
sprintf(command, "(cd %s && git add nf)", PATH);
system(command);

// Delete a file
sprintf(command, "rm -rf %s/del", PATH);
system(command);

// Modify a file
sprintf(command, "echo \"Hello World\" > %s/mod", PATH);
system(command);

// Create new file
sprintf(command, "touch %s/unt", PATH);
system(command);

// Initialize status object
status = new Status(PATH);
}

void
StatusTest::tearDown(void)
{
char command[40];

// Remove created repo
sprintf(command, "rm -rf %s", PATH);
system(command);
}

void
StatusTest::test(void)
{
BString* statusText = status->GetStatusText();

// Check for new file
CPPUNIT_ASSERT (statusText->FindFirst("new file: nf") != B_ERROR);

// Check for deleted file
CPPUNIT_ASSERT (statusText->FindFirst("deleted: del") != B_ERROR);

// Check for modified file
CPPUNIT_ASSERT (statusText->FindFirst("modified: mod") != B_ERROR);

// Check for untracked file
CPPUNIT_ASSERT (statusText->FindFirst("untracked: unt") != B_ERROR);
}
28 changes: 28 additions & 0 deletions tests/StatusTest/StatusTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef _STATUS_TEST_H_
#define _STATUS_TEST_H_

#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>

#include "../../GitCommand/Status.h"

using namespace std;

class StatusTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(StatusTest);
CPPUNIT_TEST(test);
CPPUNIT_TEST_SUITE_END();

public:
void setUp(void);
void tearDown(void);

protected:
void test(void);

private:
Status* status;
};

#endif
Binary file added tests/StatusTest/StatusTest.o
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/StatusTest/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# file: makefile
# next line has to be changed to the installation-path of CppUnit
CPPUNIT_PATH=/opt/cppunit

test: StatusTest.o
g++ -o test ../../GitCommand/Init.cpp ../../GitCommand/Status.cpp StatusTest.o test.cpp -L${CPPUNIT_PATH}/lib -lcppunit -lbe -ltracker -lgit2 -g

clean:
rm -f *.o test
Binary file renamed tests/InitTest/itest → tests/StatusTest/test
Binary file not shown.
33 changes: 33 additions & 0 deletions tests/StatusTest/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <cppunit/BriefTestProgressListener.h>

int
main(int argc, char* argv[])
{
// informs test-listener about testresults
CPPUNIT_NS :: TestResult testresult;

// register listener for collecting the test-results
CPPUNIT_NS :: TestResultCollector collectedresults;
testresult.addListener (&collectedresults);

// register listener for per-test progress output
CPPUNIT_NS :: BriefTestProgressListener progress;
testresult.addListener (&progress);

// insert test-suite at test-runner by registry
CPPUNIT_NS :: TestRunner testrunner;
testrunner.addTest (CPPUNIT_NS :: TestFactoryRegistry :: getRegistry ().makeTest ());
testrunner.run (testresult);

// output results in compiler-format
CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, std::cerr);
compileroutputter.write ();

// return 0 if tests were successful
return collectedresults.wasSuccessful () ? 0 : 1;
}

0 comments on commit 5225d24

Please sign in to comment.