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

/// A set of integration tests for `dart migrate`.
import 'package:test/test.dart';

import '../utils.dart';

void main() {
  group('migrate', defineMigrateTests, timeout: longTimeout);
}

bool _nnbdIsEnabled = true;

void defineMigrateTests() {
  final didYouForgetToRunPubGet = contains('Did you forget to run "pub get"?');

  TestProject p;

  tearDown(() => p?.dispose());

  test('--help', () {
    p = project();
    var result = p.runSync('migrate', ['--help']);

    expect(result.exitCode, 0);
    expect(result.stderr, isEmpty);
    expect(result.stdout,
        contains('Perform a null safety migration on a project or package.'));
    expect(result.stdout,
        contains('Usage: dart migrate [arguments] [project or directory]'));
  });

  test('directory implicit', () {
    p = project(mainSrc: 'int get foo => 1;\n');
    var result =
        p.runSync('migrate', ['--no-web-preview'], workingDir: p.dirPath);
    expect(result.exitCode, _nnbdIsEnabled ? 0 : 2);
    expect(result.stderr, _nnbdIsEnabled ? isEmpty : isNotEmpty);
    expect(result.stdout, contains('Generating migration suggestions'));
  });

  test('directory explicit', () {
    p = project(mainSrc: 'int get foo => 1;\n');
    var result = p.runSync('migrate', ['--no-web-preview', p.dirPath]);
    expect(result.exitCode, _nnbdIsEnabled ? 0 : 2);
    expect(result.stderr, _nnbdIsEnabled ? isEmpty : isNotEmpty);
    expect(result.stdout, contains('Generating migration suggestions'));
  });

  test('bad directory', () {
    p = project(mainSrc: 'int get foo => 1;\n');
    var result = p.runSync('migrate', ['foo_bar_dir']);
    expect(result.exitCode, 1);
    expect(result.stderr, contains('foo_bar_dir does not exist'));
    expect(result.stdout, isEmpty);
  });

  test('pub get needs running', () {
    p = project(mainSrc: 'import "package:foo/foo.dart";\n');
    var result = p.runSync('migrate', [p.dirPath]);
    expect(result.exitCode, 1);
    expect(result.stderr, isEmpty);
    expect(result.stdout, didYouForgetToRunPubGet);
  });

  test('non-pub-related error', () {
    p = project(mainSrc: 'var missing = "semicolon"\n');
    var result = p.runSync('migrate', [p.dirPath]);
    expect(result.exitCode, 1);
    expect(result.stderr, isEmpty);<commit_msg>Migration: remove _nnbdIsEnabled flag from migration unit test.<commit_after>// Copyright (c) 2020, 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.

/// A set of integration tests for `dart migrate`.
import 'package:test/test.dart';

import '../utils.dart';

void main() {
  group('migrate', defineMigrateTests, timeout: longTimeout);
}

void defineMigrateTests() {
  final didYouForgetToRunPubGet = contains('Did you forget to run "pub get"?');

  TestProject p;

  tearDown(() => p?.dispose());

  test('--help', () {
    p = project();
    var result = p.runSync('migrate', ['--help']);

    expect(result.exitCode, 0);
    expect(result.stderr, isEmpty);
    expect(result.stdout,
        contains('Perform a null safety migration on a project or package.'));
    expect(result.stdout,
        contains('Usage: dart migrate [arguments] [project or directory]'));
  });

  test('directory implicit', () {
    p = project(mainSrc: 'int get foo => 1;\n');
    var result =
        p.runSync('migrate', ['--no-web-preview'], workingDir: p.dirPath);
    expect(result.exitCode, 0);
    expect(result.stderr, isEmpty);
    expect(result.stdout, contains('Generating migration suggestions'));
  });

  test('directory explicit', () {
    p = project(mainSrc: 'int get foo => 1;\n');
    var result = p.runSync('migrate', ['--no-web-preview', p.dirPath]);
    expect(result.exitCode, 0);
    expect(result.stderr, isEmpty);
    expect(result.stdout, contains('Generating migration suggestions'));
  });

  test('bad directory', () {
    p = project(mainSrc: 'int get foo => 1;\n');
    var result = p.runSync('migrate', ['foo_bar_dir']);
    expect(result.exitCode, 1);
    expect(result.stderr, contains('foo_bar_dir does not exist'));
    expect(result.stdout, isEmpty);
  });

  test('pub get needs running', () {
    p = project(mainSrc: 'import "package:foo/foo.dart";\n');
    var result = p.runSync('migrate', [p.dirPath]);
    expect(result.exitCode, 1);
    expect(result.stderr, isEmpty);
    expect(result.stdout, didYouForgetToRunPubGet);
  });

  test('non-pub-related error', () {
    p = project(mainSrc: 'var missing = "semicolon"\n');
    var result = p.runSync('migrate', [p.dirPath]);
    expect(result.exitCode, 1);
    expect(result.stderr, isEmpty);
{'fraction_non_alphanumeric': 0.16398123597797268, 'fraction_numerical': 0.0057107893126657145, 'mean_word_length': 3.7984344422700587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1679916', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1538, 'n_words': 411}