<commit_before>part of console_test_harness;

class SyncTests {
  static void run() {
    test('true result is cool', _testTrueIsCool);
    test('false result fails', _testFalseIsFail);
    test('null result is sad', _testNullIsSad);
    test('exception is sad', _testExceptionIsSad);
  }

  static void _testTrueIsCool() {
    _testSimpleSyncTask('good', (ctx) => true, (f) {
      expect(f.value, isTrue);
    });
  }

  static void _testFalseIsFail() {
    _testSimpleSyncTask('fail', (ctx) => false, (f) {
      expect(f.value, isFalse);
    });
  }

  static void _testNullIsSad() {
    _testSimpleSyncTask('null', (ctx) => null,(Future f) {
      expect(f.exception, isNotNull);
    });
  }

  static void _testExceptionIsSad() {
    _testSimpleSyncTask('exception', (ctx) {
        throw 'sorry';
      },
      (Future f) {
        expect(f.exception, isNotNull);
      }
    );
  }

  static Action0 _testSimpleSyncTask(String name, Func1<TaskContext, bool> task,
                            Action1<Future<bool>> completeHandler) {
    final tasks = new Tasks();
    tasks.addTask(name, task);
    tasks.freeze();

    final runner = new Runner(tasks, [name]);
    final future = runner.run();
    expect(future, isNotNull);
    expect(future.isComplete, isTrue);

    final onComplete = expectAsync1(completeHandler);

    future.onComplete(onComplete);<commit_msg>SyncTests: test no task name, bad task name, better test for exception<commit_after>part of console_test_harness;

class SyncTests {
  static void run() {
    test('true result is cool', _testTrueIsCool);
    test('false result fails', _testFalseIsFail);
    test('null result is sad', _testNullIsSad);
    test('exception is sad', _testExceptionIsSad);
    test('bad task name', _testBadParam);
    test('no task name', _testNoParam);
  }

  static void _testTrueIsCool() {
    _testSimpleSyncTask('good', (ctx) => true, (f) {
      expect(f.value, isTrue);
    });
  }

  static void _testFalseIsFail() {
    _testSimpleSyncTask('fail', (ctx) => false, (f) {
      expect(f.value, isFalse);
    });
  }

  static void _testNullIsSad() {
    _testSimpleSyncTask('null', (ctx) => null,(Future f) {
      expect(f.exception, isNotNull);
    });
  }

  static void _testExceptionIsSad() {
    _testSimpleSyncTask('exception', (ctx) {
        throw 'sorry';
      },
      (Future f) {
        expect(f.exception, 'sorry');
      }
    );
  }

  static void _testBadParam() {
    final tasks = new Tasks();
    tasks.addTask('good', (ctx) => true);
    tasks.freeze();

    final runner = new Runner(tasks, ['bad']);
    final future = runner.run();
    expect(future, isNotNull);
    expect(future.isComplete, isTrue);

    final onComplete = expectAsync1((f) {
      expect(f.value, isFalse);
      // TODO: test that proper error message is printed
    });

    future.onComplete(onComplete);
  }

  static void _testNoParam() {
    final tasks = new Tasks();
    tasks.addTask('good', (ctx) => true);
    tasks.freeze();

    final runner = new Runner(tasks, []);
    final future = runner.run();
    expect(future, isNotNull);
    expect(future.isComplete, isTrue);

    final onComplete = expectAsync1((f) {
      expect(f.value, isTrue);
      // TODO: test that task list is printed
    });

    future.onComplete(onComplete);
  }

  static Action0 _testSimpleSyncTask(String name, Func1<TaskContext, bool> task,
                            Action1<Future<bool>> completeHandler) {
    final tasks = new Tasks();
    tasks.addTask(name, task);
    tasks.freeze();

    final runner = new Runner(tasks, [name]);
    final future = runner.run();
    expect(future, isNotNull);
    expect(future.isComplete, isTrue);

    final onComplete = expectAsync1(completeHandler);

    future.onComplete(onComplete);
{'fraction_non_alphanumeric': 0.13712021136063407, 'fraction_numerical': 0.002642007926023778, 'mean_word_length': 3.137704918032787, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '3908619', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1176, 'n_words': 282}