Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

y_testing BeforeEach #205

Open
Misiur opened this issue Aug 19, 2017 · 6 comments
Open

y_testing BeforeEach #205

Misiur opened this issue Aug 19, 2017 · 6 comments

Comments

@Misiur
Copy link
Collaborator

Misiur commented Aug 19, 2017

Currently I have to write code like this:

TestInit:PlayerSetName()
{
	CreatePlayer(CONNECTED_USER_ID, "TestUser");
	call OnPlayerConnect(CONNECTED_USER_ID);
}

Test:PlayerSetName()
{
	new name[MAX_PLAYER_NAME + 1];
	SetPlayerName(CONNECTED_USER_ID, "ChangedName");
	GetPlayerName(CONNECTED_USER_ID, name, sizeof name);
	ASSERT_TRUE(!strcmp(name, "ChangedName"));
}

TestClose:PlayerSetName()
{
	call OnPlayerDisconnect(CONNECTED_USER_ID, 0);
	DeletePlayer(CONNECTED_USER_ID);
}

TestInit:PlayerPosition()
{
	CreatePlayer(CONNECTED_USER_ID, "TestUser");
	call OnPlayerConnect(CONNECTED_USER_ID);
}

Test:PlayerPosition()
{
	SetPlayerPos(CONNECTED_USER_ID, 300.0, 600.0, 11.0);
	new Float:pos[3];
	GetPlayerPos(CONNECTED_USER_ID, pos[0], pos[1], pos[2]);

	ASSERT_TRUE((pos[0] == 300.0 && pos[1] == 600.0 && pos[2] == 11.0));
}

TestClose:PlayerPosition()
{
	call OnPlayerDisconnect(CONNECTED_USER_ID, 0);
	DeletePlayer(CONNECTED_USER_ID);
}

And i'd like to write it like this:

TestBeforeEach:y_mock()
{
	CreatePlayer(CONNECTED_USER_ID, "TestUser");
	call OnPlayerConnect(CONNECTED_USER_ID);	
}

Test:y_mock:PlayerSetName()
{
	new name[MAX_PLAYER_NAME + 1];
	SetPlayerName(CONNECTED_USER_ID, "ChangedName");
	GetPlayerName(CONNECTED_USER_ID, name, sizeof name);
	ASSERT_TRUE(!strcmp(name, "ChangedName"));
}

Test:y_mock:PlayerPosition()
{
	SetPlayerPos(CONNECTED_USER_ID, 300.0, 600.0, 11.0);
	new Float:pos[3];
	GetPlayerPos(CONNECTED_USER_ID, pos[0], pos[1], pos[2]);

	ASSERT_TRUE((pos[0] == 300.0 && pos[1] == 600.0 && pos[2] == 11.0));
}

TestAfterEach:y_mock()
{
	call OnPlayerDisconnect(CONNECTED_USER_ID, 0);
	DeletePlayer(CONNECTED_USER_ID);
}

I've tried

#define Test:%1() @yQQ:@yQP:Test:%1()
#define @yQP:Test:%1:%2 @yQR:Test:%1_@yQS_%2
#define @yQQ:%0:Test:%1() forward bool:yQ@_%1(); public bool:yQ@_%1() for(new bool:__once = (_Testing_Start("\0\0"#%1), TEST_REPORT("*** Test %s start", YSI_gCurTestName) || true); __once; __once = _Testing_End())

But to no avail as the longest define seems to be picked first.

This issue is for tracking my findings

@Misiur
Copy link
Collaborator Author

Misiur commented Aug 24, 2017

Closed by #206

@Misiur Misiur closed this as completed Aug 24, 2017
@Y-Less
Copy link
Member

Y-Less commented Aug 24, 2017

Did you make any of the changes I said?

@Y-Less Y-Less reopened this Aug 24, 2017
@Y-Less
Copy link
Member

Y-Less commented Aug 24, 2017

apparently I had to press 'submit review'...

@Misiur
Copy link
Collaborator Author

Misiur commented Aug 24, 2017

Shit, sorry, I just assumed you don't want to review this and merged. I'll create a new branch to rework this as you want

@Y-Less
Copy link
Member

Y-Less commented Aug 24, 2017

Nope, I just didn't realise I had to click something after writing the comments - I just thought they were like normal comments.

@Y-Less
Copy link
Member

Y-Less commented Sep 8, 2017

Just pointing to #157 for reference here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants