Skip to content

Commit

Permalink
[playframework#347] All both 'test' and 'test-?.*' frameworkId when r…
Browse files Browse the repository at this point in the history
…unning in test mode
  • Loading branch information
mbknor authored and guillaumebort committed Mar 8, 2011
1 parent f5c8264 commit 22df0a8
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
5 changes: 4 additions & 1 deletion documentation/commands/cmd-test.txt
Expand Up @@ -11,8 +11,11 @@
~ Run the application hosted at the app_path directory. If app_path is omitted, the current directory is used.
~ The application is run in foreground in the current shell. You can then stop it using Ctrl+C.
~
~ The application is run in test mode: the framework ID is forced to 'test' and a web test runner is automatically
~ The application is run in test mode: the framework ID is forced to 'test' (unless you specify it to be
~ something matching 'test-?.*', e.g 'test-special') and a web test runner is automatically
~ started at the /@tests URL.
~ (Note that when using special test framework ID you have to make sure all test-settings in
~ application.conf is available with this special framework ID)
~
~ The script first tries to locate the java command using the $JAVA_HOME environment variable (from $JAVA_HOME/bin).
~ If the $JAVA_HOME variable is not defined, the default java command available from the PATH is used.
Expand Down
4 changes: 4 additions & 0 deletions documentation/manual/test.textile
Expand Up @@ -186,6 +186,10 @@ On the test runner page, each test is a link. You can ‘right click’ and ‘O

When you run tests this way, Play will start with a special **test** framework ID. So you can define special configurations in the **application.conf** file.

If you want several different test-configuration, you can use framework IDs matching the pattern 'test-?.*' (e.g: 'test-special').
If you use a framework ID other then the default 'test', you must make sure ALL test configuration in application.conf is available
with that framework ID. When launching test with special test framework ID you do it like this: 'play test --%test-your-special-id'

For example:

bc. %test.db=mem
Expand Down
7 changes: 5 additions & 2 deletions framework/pym/play/application.py
Expand Up @@ -4,6 +4,9 @@
import shutil
import socket

from play.utils import *


class ModuleNotFound(Exception):
def __init__(self, value):
self.value = value
Expand Down Expand Up @@ -73,7 +76,7 @@ def modules(self):
modules.append(mf)
else:
modules.append(open(mf, 'r').read().strip())
if self.play_env["id"] == 'test':
if isTestFrameworkId( self.play_env["id"] ):
modules.append(os.path.normpath(os.path.join(self.play_env["basedir"], 'modules/testrunner')))
return modules

Expand All @@ -96,7 +99,7 @@ def load_modules(self):
print 'Module not found %s' % e
sys.exit(-1)

if play_env["id"] == 'test':
if isTestFrameworkId( play_env["id"] ):
modules.append(os.path.normpath(os.path.join(play_env["basedir"], 'modules/testrunner')))

def override(self, f, t):
Expand Down
3 changes: 3 additions & 0 deletions framework/pym/play/utils.py
Expand Up @@ -213,3 +213,6 @@ def copy_directory(source, target, exclude = []):
if not os.path.exists(to_directory):
os.makedirs(to_directory)
shutil.copyfile(from_, to_)

def isTestFrameworkId( framework_id ):
return (framework_id == 'test' or (framework_id.startswith('test-') and framework_id.__len__() >= 6 ))
2 changes: 1 addition & 1 deletion framework/src/play/Logger.java
Expand Up @@ -75,7 +75,7 @@ public static void init() {
PropertyConfigurator.configure(log4jConf);
Logger.log4j = org.apache.log4j.Logger.getLogger("play");
// In test mode, append logs to test-result/application.log
if (Play.id.equals("test")) {
if (Play.runingInTestMode()) {
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
try {
if (!Play.getFile("test-result").exists()) {
Expand Down
14 changes: 13 additions & 1 deletion framework/src/play/Play.java
Expand Up @@ -648,7 +648,7 @@ public static void loadModules() {
}
}
// Auto add special modules
if (Play.id.equals("test")) {
if (Play.runingInTestMode()) {
addModule("_testrunner", new File(Play.frameworkPath, "modules/testrunner"));
}
if (Play.mode == Mode.DEV) {
Expand Down Expand Up @@ -698,4 +698,16 @@ public static VirtualFile getVirtualFile(String path) {
public static File getFile(String path) {
return new File(applicationPath, path);
}

/**
* Returns true if application is runing in test-mode.
* Test-mode is resolved from the framework id.
*
* Your app is running in test-mode if the framwork id (Play.id)
* is 'test' or 'test-?.*'
* @return true if testmode
*/
public static boolean runingInTestMode(){
return id.matches("test|test-?.*");
}
}
5 changes: 4 additions & 1 deletion play
Expand Up @@ -5,6 +5,7 @@
import sys
import os
import os.path
import re

sys.path.append(os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'framework', 'pym'))

Expand Down Expand Up @@ -101,7 +102,9 @@ try:
remaining_args.remove('--%%%s' % play_env["id"])

if play_command == 'test' or play_command == 'auto-test':
play_env["id"] = 'test'
# If framework-id is not a valid test-id, force it to 'test'
if not isTestFrameworkId( play_env["id"] ):
play_env["id"] = 'test'

if play_env["id"] is not '':
print "~ framework ID is %s" % play_env["id"]
Expand Down

0 comments on commit 22df0a8

Please sign in to comment.