<commit_before>// Copyright (c) 2017, 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.

@Tags(['presubmit-only'])
@OnPlatform({'windows': Skip('Cant run shell scripts on windows')})
import 'dart:io';

import 'package:io/ansi.dart';
import 'package:mono_repo/src/commands/presubmit.dart';
import 'package:mono_repo/src/commands/travis.dart';
import 'package:mono_repo/src/package_config.dart';
import 'package:mono_repo/src/root_config.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;

import 'shared.dart';

final pubBinary = Platform.isWindows ? 'pub.bat' : 'pub';

void main() {
  group('error reporting', () {
    test('no $travisShPath', () async {
      await d.dir('pkg_a', [
        d.file('mono_pkg.yaml', ''),
        d.file('pubspec.yaml', '{"name":"_test"}')
      ]).create();

      expect(
          () => presubmit(RootConfig(rootDirectory: d.sandbox)),
          throwsUserExceptionWith(
              'No $travisShPath file found, please run the `travis` '
              'command first.',
              isNull));
    });
  });

  group('golden path', () {
    String repoPath;
    String pkgAPath;
    String pkgBPath;

    setUpAll(() async {
      repoPath = Directory.systemTemp.createTempSync().path;
      pkgAPath = p.join(repoPath, 'pkg_a');
      Directory(pkgAPath).createSync();
      pkgBPath = p.join(repoPath, 'pkg_b');
      Directory(pkgBPath).createSync();

      File(p.join(pkgAPath, monoPkgFileName))
        ..createSync(recursive: true)
        ..writeAsStringSync(pkgAConfig);
      File(p.join(pkgAPath, 'pubspec.yaml'))
        ..createSync(recursive: true)
        ..writeAsStringSync(pkgAPubspec);
      File(p.join(pkgAPath, 'test', 'test.dart'))
        ..createSync(recursive: true)
        ..writeAsStringSync(basicTest);

      File(p.join(pkgBPath, monoPkgFileName))
        ..createSync(recursive: true)
        ..writeAsStringSync(pkgBConfig);
      File(p.join(pkgBPath, 'pubspec.yaml'))
        ..createSync(recursive: true)
        ..writeAsStringSync('name: pkg_b');

      await overrideAnsiOutput(false, () async {
        await expectLater(
            () => generateTravisConfig(RootConfig(rootDirectory: repoPath),
                pkgVersion: '1.2.3'),
            prints(stringContainsInOrder([
              'package:pkg_a',
              'package:pkg_b',
              'Make sure to mark `./tool/travis.sh` as executable.',
            ])));<commit_msg>Fix presubmit test with latest pkg:test fixes<commit_after>// Copyright (c) 2017, 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.

@Tags(['presubmit-only'])
@OnPlatform({'windows': Skip('Cant run shell scripts on windows')})
import 'dart:io';

import 'package:io/ansi.dart';
import 'package:mono_repo/src/commands/presubmit.dart';
import 'package:mono_repo/src/commands/travis.dart';
import 'package:mono_repo/src/package_config.dart';
import 'package:mono_repo/src/root_config.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;

import 'shared.dart';

final pubBinary = Platform.isWindows ? 'pub.bat' : 'pub';

void main() {
  group('error reporting', () {
    test('no $travisShPath', () async {
      await d.dir('pkg_a', [
        d.file('mono_pkg.yaml', ''),
        d.file('pubspec.yaml', '{"name":"_test"}')
      ]).create();

      expect(
          () => presubmit(RootConfig(rootDirectory: d.sandbox)),
          throwsUserExceptionWith(
              'No $travisShPath file found, please run the `travis` '
              'command first.',
              isNull));
    });
  });

  group('golden path', () {
    String repoPath;
    String pkgAPath;
    String pkgBPath;

    setUpAll(() async {
      repoPath = Directory.systemTemp.createTempSync().path;
      pkgAPath = p.join(repoPath, 'pkg_a');
      Directory(pkgAPath).createSync();
      pkgBPath = p.join(repoPath, 'pkg_b');
      Directory(pkgBPath).createSync();

      File(p.join(pkgAPath, monoPkgFileName))
        ..createSync(recursive: true)
        ..writeAsStringSync(pkgAConfig);
      File(p.join(pkgAPath, 'pubspec.yaml'))
        ..createSync(recursive: true)
        ..writeAsStringSync(pkgAPubspec);
      File(p.join(pkgAPath, 'test', 'some_test.dart'))
        ..createSync(recursive: true)
        ..writeAsStringSync(basicTest);

      File(p.join(pkgBPath, monoPkgFileName))
        ..createSync(recursive: true)
        ..writeAsStringSync(pkgBConfig);
      File(p.join(pkgBPath, 'pubspec.yaml'))
        ..createSync(recursive: true)
        ..writeAsStringSync('name: pkg_b');

      await overrideAnsiOutput(false, () async {
        await expectLater(
            () => generateTravisConfig(RootConfig(rootDirectory: repoPath),
                pkgVersion: '1.2.3'),
            prints(stringContainsInOrder([
              'package:pkg_a',
              'package:pkg_b',
              'Make sure to mark `./tool/travis.sh` as executable.',
            ])));
{'fraction_non_alphanumeric': 0.14601686972820993, 'fraction_numerical': 0.0026241799437675727, 'mean_word_length': 2.97319434102755, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, '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': '358062', 'n_tokens_mistral': 1743, 'n_tokens_neox': 1694, 'n_words': 342}