Skip to content

Commit

Permalink
Add SourceMod plugins to the test harness (compile-only).
Browse files Browse the repository at this point in the history
  • Loading branch information
dvander committed Nov 6, 2018
1 parent 1346c09 commit 338595b
Show file tree
Hide file tree
Showing 163 changed files with 43,048 additions and 19 deletions.
5 changes: 5 additions & 0 deletions tests/basic/loop-continue.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1
3
5
7
9
9 changes: 9 additions & 0 deletions tests/basic/loop-continue.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <shell>

public main() {
for (int i = 0; i < 10; i++) {
if (i % 2 == 0)
continue;
printnum(i);
}
}
2 changes: 1 addition & 1 deletion tests/compile-only/manifest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[folder]
type: compile-only
type: compiler-output
compiler: spcomp
43 changes: 30 additions & 13 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
import testutil
import datetime
from testutil import manifest_get

def main():
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -188,9 +189,8 @@ def find_tests_impl(self, local_folder, manifest):
folder = os.path.join(self.tests_path, local_folder)
manifest_path = os.path.join(folder, 'manifest.ini')
if os.path.exists(manifest_path):
manifest = manifest.copy()
manifest = testutil.parse_manifest(manifest_path, manifest)
if manifest.get('skip', None) == 'true':
manifest = testutil.parse_manifest(manifest_path, local_folder, manifest)
if manifest_get(manifest, 'folder', 'skip') == 'true':
return

for name in os.listdir(folder):
Expand All @@ -201,10 +201,14 @@ def find_tests_impl(self, local_folder, manifest):
elif path.endswith('.sp'):
if self.args.test is not None and not local_path.startswith(self.args.test):
continue
self.tests.append(Test(**{

test = Test(**{
'path': os.path.abspath(path),
'manifest': manifest,
}))
})
if manifest_get(manifest, test.name, 'skip') == 'true':
continue
self.tests.append(test)

###
# This is a helper class instantiated for each test file in the tree.
Expand Down Expand Up @@ -269,9 +273,11 @@ def unique_name(self):

@property
def type(self):
if 'type' in self.manifest_:
return self.manifest_['type']
return 'runtime'
return manifest_get(self.manifest_, self.name, 'type', 'runtime')

@property
def includes(self):
return manifest_get(self.manifest_, self.name, 'includes', [])

@property
def warnings_are_errors(self):
Expand All @@ -286,7 +292,7 @@ def expectedReturnCode(self):
def should_run(self, mode):
compiler = self.local_manifest_.get('compiler', None)
if compiler is None:
compiler = self.manifest_.get('compiler', None)
compiler = manifest_get(self.manifest_, self.name, 'compiler')
if compiler is None:
return True
return mode['spcomp']['name'] == compiler
Expand Down Expand Up @@ -369,7 +375,7 @@ def run_test(self, mode, test):

# First run the compiler.
rc, stdout, stderr = self.run_compiler(mode, test)
if test.type == 'compile-only':
if test.type == 'compiler-output' or test.type == 'compile-only':
if not self.compile_ok(mode, test, rc, stdout, stderr):
self.out_io(stderr, stdout)
return False
Expand All @@ -394,11 +400,19 @@ def run_compiler(self, mode, test):

# Build |argv| for the compiler.
spcomp_path = mode['spcomp']['path']
argv = [
spcomp_path,
argv = [spcomp_path]

# Add test-specific includes.
for include in test.includes:
include_path = self.fix_path(spcomp_path, os.path.join(self.include_path, include))
argv += ['-i', include_path]

# Add harness includes.
argv += [
'-i', self.fix_path(spcomp_path, self.core_include_path),
'-i', self.fix_path(spcomp_path, self.include_path),
]

argv += mode['spcomp']['args']
argv += mode['args']
if test.warnings_are_errors:
Expand Down Expand Up @@ -439,7 +453,10 @@ def run_shell(self, mode, shell, test):
return True

def compile_ok(self, mode, test, rc, stdout, stderr):
assert test.type == 'compile-only'
if test.type == 'compile-only':
return rc == 0

assert test.type == 'compiler-output'
test_prefix = test.name.split('-')[0]
if test_prefix == 'ok' or test_prefix == 'warn':
if rc != 0:
Expand Down
96 changes: 96 additions & 0 deletions tests/sourcemod/admin-flatfile/admin-flatfile.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod Admin File Reader Plugin
* Manages the standard flat files for admins. This is the file to compile.
*
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/

/* We like semicolons */
#pragma semicolon 1

#include <sourcemod>

public Plugin myinfo =
{
name = "Admin File Reader",
author = "AlliedModders LLC",
description = "Reads admin files",
version = SOURCEMOD_VERSION,
url = "http://www.sourcemod.net/"
};

/** Various parsing globals */
bool g_LoggedFileName = false; /* Whether or not the file name has been logged */
int g_ErrorCount = 0; /* Current error count */
int g_IgnoreLevel = 0; /* Nested ignored section count, so users can screw up files safely */
int g_CurrentLine = 0; /* Current line we're on */
char g_Filename[PLATFORM_MAX_PATH]; /* Used for error messages */

#include "admin-overrides.sp"
#include "admin-groups.sp"
#include "admin-users.sp"
#include "admin-simple.sp"

public void OnRebuildAdminCache(AdminCachePart part)
{
if (part == AdminCache_Overrides)
{
ReadOverrides();
} else if (part == AdminCache_Groups) {
ReadGroups();
} else if (part == AdminCache_Admins) {
ReadUsers();
ReadSimpleUsers();
}
}

void ParseError(const char[] format, any ...)
{
char buffer[512];

if (!g_LoggedFileName)
{
LogError("Error(s) detected parsing %s", g_Filename);
g_LoggedFileName = true;
}

VFormat(buffer, sizeof(buffer), format, 2);

LogError(" (line %d) %s", g_CurrentLine, buffer);

g_ErrorCount++;
}

void InitGlobalStates()
{
g_ErrorCount = 0;
g_IgnoreLevel = 0;
g_CurrentLine = 0;
g_LoggedFileName = false;
}
Loading

0 comments on commit 338595b

Please sign in to comment.