summaryrefslogtreecommitdiffstats
path: root/gin/shell
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-25 21:26:15 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-25 21:26:15 +0000
commit2f70342531d0cb7335ea88ec5579d0a8a8bb114f (patch)
treebf1883a26ccf8493b5419fb239190619c249481b /gin/shell
parentae6f06153630c4c0940a4630443ae4faf44ef409 (diff)
downloadchromium_src-2f70342531d0cb7335ea88ec5579d0a8a8bb114f.zip
chromium_src-2f70342531d0cb7335ea88ec5579d0a8a8bb114f.tar.gz
chromium_src-2f70342531d0cb7335ea88ec5579d0a8a8bb114f.tar.bz2
[Gin] Add a basic unit testing framework
Previously, we were using JavaScript bindings to gtest to unit test JavaScript code in Gin and Mojo. The gtest bindings were very basic and not very idiomatic. This CL introduces a simple AMD module call "expect" to help us write more idiomatic unit tests. The API for "expect" is based on the popular Jasmine unit testing framework for node.js. I investigated just importing one of Node's many unit testing frameworks, but they all try to do too much (e.g., drive the entire test harness via Node's file system interface). The "expect" modules doesn't try to drive the testing process. We just let gtest handle that. Instead, "expect" just provides a simple language in which to write test assertions. We'll likely evolve our testing strategy over time, but hopefully this CL is an improvement over the primitive gtest bindings. R=jochen@chromium.org TBR=joth@chromium.org BUG=none Review URL: https://codereview.chromium.org/85223002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237145 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin/shell')
-rw-r--r--gin/shell/gin_main.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/gin/shell/gin_main.cc b/gin/shell/gin_main.cc
index 9d081a3..24fa6df 100644
--- a/gin/shell/gin_main.cc
+++ b/gin/shell/gin_main.cc
@@ -24,11 +24,11 @@ std::string Load(const base::FilePath& path) {
return source;
}
-void Run(base::WeakPtr<Runner> runner, const std::string& source) {
+void Run(base::WeakPtr<Runner> runner, const base::FilePath& path) {
if (!runner)
return;
Runner::Scope scope(runner.get());
- runner->Run(source);
+ runner->Run(Load(path), path.AsUTF8Unsafe());
}
std::vector<base::FilePath> GetModuleSearchPaths() {
@@ -46,7 +46,7 @@ class ShellRunnerDelegate : public ModuleRunnerDelegate {
virtual void UnhandledException(Runner* runner,
TryCatch& try_catch) OVERRIDE {
ModuleRunnerDelegate::UnhandledException(runner, try_catch);
- LOG(ERROR) << try_catch.GetPrettyMessage();
+ LOG(ERROR) << try_catch.GetStackTrace();
}
private:
@@ -68,11 +68,16 @@ int main(int argc, char** argv) {
gin::ShellRunnerDelegate delegate;
gin::Runner runner(&delegate, instance.isolate());
+ {
+ gin::Runner::Scope scope(&runner);
+ v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
+ }
+
CommandLine::StringVector args = CommandLine::ForCurrentProcess()->GetArgs();
for (CommandLine::StringVector::const_iterator it = args.begin();
it != args.end(); ++it) {
base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
- gin::Run, runner.GetWeakPtr(), gin::Load(base::FilePath(*it))));
+ gin::Run, runner.GetWeakPtr(), base::FilePath(*it)));
}
message_loop.RunUntilIdle();