Skip to content

Commit

Permalink
Run integrationtests in main
Browse files Browse the repository at this point in the history
Integration tests should run in the main funtion, not in unittest blocks,
as unittest blocks might not be compiled in.
  • Loading branch information
leandro-lucarella-sociomantic authored and Gavin Norman committed Jun 8, 2017
1 parent 19b4500 commit e7473bc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 165 deletions.
153 changes: 1 addition & 152 deletions test/filesystemevent/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -48,135 +48,6 @@ import ocean.task.Task;

import ocean.task.Scheduler;

deprecated class FileModificationTestTask: Task
{
/***************************************************************************
File operations to be checked
***************************************************************************/

private bool modified = false;
private bool deleted = false;
private bool closed = false;

/***************************************************************************
Name of the created file.
***************************************************************************/

private cstring created_name;

/***************************************************************************
Path to the monitored file.
***************************************************************************/

private FilePath temp_path;

/***************************************************************************
Variable to control/test the order of the file operations
***************************************************************************/

private int operation_order = 0;

/***************************************************************************
Tested FileSystemEvent instance.
***************************************************************************/

private FileSystemEvent inotifier;

/***************************************************************************
Test entry point. Prepares environment and tests the FileSystemEvent.
***************************************************************************/

override public void run ( )
{
auto temp_file = new TempFile(TempFile.Permanent);
this.temp_path = FilePath(temp_file.toString());

this.inotifier = new FileSystemEvent(&this.fileSystemHandler);
inotifier.watch(cast(char[]) temp_file.toString(),
FileEventsEnum.IN_MODIFY | FileEventsEnum.IN_DELETE_SELF
| FileEventsEnum.IN_CLOSE_WRITE );

theScheduler.epoll.register(inotifier);

temp_file.write("something");
temp_file.close;
temp_path.remove();

this.suspend();

theScheduler.epoll.unregister(inotifier);

test(this.modified);
test(this.closed);
test(this.deleted);
}

/**********************************************************************
File System handler: called anytime a File System event occurs.
Params:
path = monitored path
event = Inotify event (see FileEventsEnum)
**********************************************************************/

private void fileSystemHandler ( char[] path, uint event )
{
if ( this.temp_path == path )
{
this.operation_order++;

switch ( event )
{
case FileEventsEnum.IN_MODIFY:

if ( this.operation_order == 1 )
{
this.modified = true;
}
break;

case FileEventsEnum.IN_CLOSE_WRITE:

if ( this.operation_order == 2 )
{
this.closed = true;
}
break;

case FileEventsEnum.IN_DELETE_SELF:

if ( this.operation_order == 3 )
{
this.deleted = true;
if (this.suspended())
this.resume();
}
break;

case FileEventsEnum.IN_IGNORED:
enforce(this.deleted);
break;

default:
test(false, "Unexpected file system event notification.");
}
}
}
}

class FileCreationTestTask: Task
{
Expand Down Expand Up @@ -395,21 +266,11 @@ class FileCreationTestTask: Task

/*******************************************************************************
Dummy main (required by compiler).
Main test
*******************************************************************************/

void main ( )
{
}

/***************************************************************************
UnitTest
***************************************************************************/

unittest
{
initScheduler(SchedulerConfiguration.init);
theScheduler.exception_handler = (Task t, Exception e) {
Expand All @@ -420,15 +281,3 @@ unittest
theScheduler.schedule(dir_test_task);
theScheduler.eventLoop();
}

deprecated unittest
{
initScheduler(SchedulerConfiguration.init);
theScheduler.exception_handler = (Task t, Exception e) {
throw e;
};

auto test_task = new FileModificationTestTask;
theScheduler.schedule(test_task);
theScheduler.eventLoop();
}
15 changes: 2 additions & 13 deletions test/signalfd/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -494,23 +494,12 @@ private class SignalFDTest

/*******************************************************************************
Dummy main (required by compiler).
Tests where the set of signals being handled by the SignalFD is set in the
ctor.
*******************************************************************************/

void main ( )
{
}


/*******************************************************************************
unittests where the set of signals being handled by the SignalFD is set in
the ctor.
*******************************************************************************/

unittest
{
// Test a single signal handled by a signalfd
new SignalFDTest(new SignalFD([SIGHUP]), [SIGHUP]);
Expand Down

0 comments on commit e7473bc

Please sign in to comment.