// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

var args = process.argv.slice(2);
if (args.length != 1) {
  throw new Error("Usage: node test/run.js <test-module-name>");
}
var test = args[0];

var requirejs = require('requirejs');
var ddcdir = __dirname + '/../';
requirejs.config({
  baseUrl: ddcdir + 'gen/codegen_output',
  paths: {
    dart_sdk: ddcdir + 'lib/js/amd/dart_sdk',
    async_helper: ddcdir + 'gen/codegen_output/pkg/async_helper',
    expect: ddcdir + 'gen/codegen_output/pkg/expect',
    js: ddcdir + 'gen/codegen_output/pkg/js',
    matcher: ddcdir + 'gen/codegen_output/pkg/matcher',
    minitest: ddcdir + 'gen/codegen_output/pkg/minitest',
    path: ddcdir + 'gen/codegen_output/pkg/path',
    stack_trace: ddcdir + 'gen/codegen_output/pkg/stack_trace',
    unittest: ddcdir + 'gen/codegen_output/pkg/unittest',
  }
});

// TODO(vsm): Factor out test framework code in test/browser/language_tests.js
// and use here.  Async tests and unittests won't work without it.

var module = requirejs(test);
test = test.split('/').slice(-1)[0];
module[test].main();

@@ -210,16 +210,437 @@
  file.%0A%0A
+/// This is a utility to run and debug an individual DDC compiled test.%0A/// Tests can be run with either node or devtool (a Chrome-based utility with%0A/// DOM APIs and developer tools support).%0A///%0A/// Install devtool via:%0A/// %3E npm install -g devtool%0A///%0A/// Run via:%0A/// %3E devtool tool/run.js -- corelib/apply2_test%0A/// or%0A/// %3E node tool/run.js corelib/apply2_test%0A///%0A/// See TODO below on async / unittest support. %0A%0A
 var args
@@ -719,17 +719,20 @@
 ge: 
-node test
+devtool tool
 /run
@@ -1576,16 +1576,48 @@
 out it.%0A
+var sdk = requirejs('dart_sdk');
 %0Avar mod
@@ -1639,20 +1639,23 @@
 (test);%0A
-test
+var lib
  = test.
@@ -1683,25 +1683,179 @@
 0%5D;%0A
-module%5Btest%5D.main();
+try %7B%0A  module%5Blib%5D.main();%0A  console.log('Test ' + test + ' passed.');%0A%7D catch (e) %7B%0A  console.log('Test ' + test + ' failed:%5Cn' + e.toString());%0A  sdk.dart.stackPrint(e);%0A%7D
 %0A

Support for debugging DDC tests under devtool