<commit_before># Copyright (c) 2011, 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.
#

"""Runs a Dart unit test in different configurations.

Currently supported architectures include dartium, chromium, ia32, x64,
arm, simarm, and dartc.

Example:
  run.py --arch=dartium --mode=release --test=Test.dart

"""

import os
import platform
import re
import shutil
import subprocess
import sys
import tempfile

import utils

OS_GUESS = utils.GuessOS()

HTML_CONTENTS = """
<html>
<head>
  <title> Test %(title)s </title>
  <style>
     .unittest-table { font-family:monospace; border:1px; }
     .unittest-pass { background: #6b3;}
     .unittest-fail { background: #d55;}
     .unittest-error { background: #a11;}
  </style>
</head>
<body>
  <h1> Running %(title)s </h1>
  <script type="text/javascript" src="%(controller_script)s"></script>
  <script type="%(script_type)s" src="%(source_script)s"></script>
  <script type="text/javascript">
    // If nobody intercepts the error, finish the test.
    window.onerror = function() { window.layoutTestController.notifyDone() };

    // If 'startedDartTest' is not set, that means that the test did not have
    // a chance to load. This will happen when a load error occurs in the VM.
    // Give the machine time to start up.
    setTimeout(function() {
      // A window.postMessage might have been enqueued after this timeout.
      // Just sleep another time to give the browser the time to process the
      // posted message.
      setTimeout(function() {
        if (window.layoutTestController
            && !window.layoutTestController.startedDartTest) {
          window.layoutTestController.notifyDone();
        }
      }, 0);
    }, 0);
  </script>
</body>
</html>
"""

DART_TEST_AS_LIBRARY = """
#library('test');<commit_msg>Increase timeout. Hopefully this reduces the flakiness on the build-server. Start timeout only when document is loaded.<commit_after># Copyright (c) 2011, 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.
#

"""Runs a Dart unit test in different configurations.

Currently supported architectures include dartium, chromium, ia32, x64,
arm, simarm, and dartc.

Example:
  run.py --arch=dartium --mode=release --test=Test.dart

"""

import os
import platform
import re
import shutil
import subprocess
import sys
import tempfile

import utils

OS_GUESS = utils.GuessOS()

HTML_CONTENTS = """
<html>
<head>
  <title> Test %(title)s </title>
  <style>
     .unittest-table { font-family:monospace; border:1px; }
     .unittest-pass { background: #6b3;}
     .unittest-fail { background: #d55;}
     .unittest-error { background: #a11;}
  </style>
</head>
<body>
  <h1> Running %(title)s </h1>
  <script type="text/javascript" src="%(controller_script)s"></script>
  <script type="%(script_type)s" src="%(source_script)s"></script>
  <script type="text/javascript">
    // If nobody intercepts the error, finish the test.
    window.onerror = function() { window.layoutTestController.notifyDone() };

    window.addEventListener('DOMContentLoaded', function() {
      // If 'startedDartTest' is not set, that means that the test did not have
      // a chance to load. This will happen when a load error occurs in the VM.
      // Give the machine time to start up.
      setTimeout(function() {
        // A window.postMessage might have been enqueued after this timeout.
        // Just sleep another time to give the browser the time to process the
        // posted message.
        setTimeout(function() {
          if (window.layoutTestController
              && !window.layoutTestController.startedDartTest) {
            window.layoutTestController.notifyDone();
          }
        }, 0);
      }, 50);
    }, false);
  </script>
</body>
</html>
"""

DART_TEST_AS_LIBRARY = """
#library('test');
{'fraction_non_alphanumeric': 0.11993118702383879, 'fraction_numerical': 0.009584664536741214, 'mean_word_length': 3.325185972369819, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4985968', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1211, 'n_words': 414}