From 2f70342531d0cb7335ea88ec5579d0a8a8bb114f Mon Sep 17 00:00:00 2001 From: "abarth@chromium.org" Date: Mon, 25 Nov 2013 21:26:15 +0000 Subject: [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 --- gin/shell/gin_main.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'gin/shell') 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, const std::string& source) { +void Run(base::WeakPtr runner, const base::FilePath& path) { if (!runner) return; Runner::Scope scope(runner.get()); - runner->Run(source); + runner->Run(Load(path), path.AsUTF8Unsafe()); } std::vector 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(); -- cgit v1.1