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

#library('pub_tests');

#import('dart:io');

#import('test_pub.dart');
#import('../../../pkg/unittest/unittest.dart');

main() {
  test("updates locked Git packages", () {
    ensureGit();

    git('foo.git', [
      libDir('foo'),
      libPubspec('foo', '1.0.0')
    ]).scheduleCreate();

    git('bar.git', [
      libDir('bar'),
      libPubspec('bar', '1.0.0')
    ]).scheduleCreate();

    appDir([{"git": "../foo.git"}, {"git": "../bar.git"}]).scheduleCreate();

    schedulePub(args: ['install'],
        output: const RegExp(@"Dependencies installed!$"));

    dir(packagesPath, [
      dir('foo', [
        file('foo.dart', 'main() => "foo";')
      ]),
      dir('bar', [
        file('bar.dart', 'main() => "bar";')
      ])
    ]).scheduleValidate();

    git('foo.git', [
      libDir('foo', 'foo 2'),
      libPubspec('foo', '1.0.0')
    ]).scheduleCommit();

    git('bar.git', [
      libDir('bar', 'bar 2'),
      libPubspec('bar', '1.0.0')
    ]).scheduleCommit();

    schedulePub(args: ['update'],
        output: const RegExp(@"Dependencies updated!$"));

    dir(packagesPath, [
      dir('foo', [
        file('foo.dart', 'main() => "foo 2";')
      ]),
      dir('bar', [
        file('bar.dart', 'main() => "bar 2";')
      ])
    ]).scheduleValidate();

    run();
  });

  group("with an argument", () {
    test("updates one locked Git package but no others", () {
      ensureGit();

      git('foo.git', [
        libDir('foo'),
        libPubspec('foo', '1.0.0')
      ]).scheduleCreate();

      git('bar.git', [
        libDir('bar'),
        libPubspec('bar', '1.0.0')
      ]).scheduleCreate();

      appDir([{"git": "../foo.git"}, {"git": "../bar.git"}]).scheduleCreate();

      schedulePub(args: ['install'],
          output: const RegExp(@"Dependencies installed!$"));

      dir(packagesPath, [
        dir('foo', [
          file('foo.dart', 'main() => "foo";')
        ]),
        dir('bar', [
          file('bar.dart', 'main() => "bar";')
        ])
      ]).scheduleValidate();

      git('foo.git', [
        libDir('foo', 'foo 2'),
        libPubspec('foo', '1.0.0')
      ]).scheduleCommit();

      git('bar.git', [
        libDir('bar', 'bar 2'),
        libPubspec('bar', '1.0.0')
      ]).scheduleCommit();

      schedulePub(args: ['update', 'foo'],
          output: const RegExp(@"Dependencies updated!$"));

      dir(packagesPath, [
        dir('foo', [
          file('foo.dart', 'main() => "foo 2";')
        ]),
        dir('bar', [
          file('bar.dart', 'main() => "bar";')
        ])
      ]).scheduleValidate();

      run();
    });

    test("doesn't update one locked Git package's dependencies if it's not "
        "necessary", () {
      ensureGit();

      git('foo.git', [
        libDir('foo'),
        libPubspec("foo", "1.0.0", [{"git": "../foo-dep.git"}])
      ]).scheduleCreate();

      git('foo-dep.git', [
        libDir('foo-dep'),
        libPubspec('foo-dep', '1.0.0')
      ]).scheduleCreate();

      appDir([{"git": "../foo.git"}]).scheduleCreate();

      schedulePub(args: ['install'],
          output: const RegExp(@"Dependencies installed!$"));

      dir(packagesPath, [
        dir('foo', [
          file('foo.dart', 'main() => "foo";')
        ]),
        dir('foo-dep', [
          file('foo-dep.dart', 'main() => "foo-dep";')
        ])
      ]).scheduleValidate();

      git('foo.git', [
        libDir('foo', 'foo 2'),
        libPubspec("foo", "1.0.0", [{"git": "../foo-dep.git"}])
      ]).scheduleCreate();

      git('foo-dep.git', [
        libDir('foo-dep', 'foo-dep 2'),
        libPubspec('foo-dep', '1.0.0')
      ]).scheduleCommit();

      schedulePub(args: ['update', 'foo'],
          output: const RegExp(@"Dependencies updated!$"));

      dir(packagesPath, [
        dir('foo', [
          file('foo.dart', 'main() => "foo 2";')
        ]),
        dir('foo-dep', [
          file('foo-dep.dart', 'main() => "foo-dep";')
        ]),
      ]).scheduleValidate();

      run();
    });
  });
}
<commit_msg>Add tests for updating a git repo to a bad/different pubspec.<commit_after>// Copyright (c) 2012, 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.

#library('pub_tests');

#import('dart:io');

#import('test_pub.dart');
#import('../../../pkg/unittest/unittest.dart');

main() {
  test("updates locked Git packages", () {
    ensureGit();

    git('foo.git', [
      libDir('foo'),
      libPubspec('foo', '1.0.0')
    ]).scheduleCreate();

    git('bar.git', [
      libDir('bar'),
      libPubspec('bar', '1.0.0')
    ]).scheduleCreate();

    appDir([{"git": "../foo.git"}, {"git": "../bar.git"}]).scheduleCreate();

    schedulePub(args: ['install'],
        output: const RegExp(@"Dependencies installed!$"));

    dir(packagesPath, [
      dir('foo', [
        file('foo.dart', 'main() => "foo";')
      ]),
      dir('bar', [
        file('bar.dart', 'main() => "bar";')
      ])
    ]).scheduleValidate();

    git('foo.git', [
      libDir('foo', 'foo 2'),
      libPubspec('foo', '1.0.0')
    ]).scheduleCommit();

    git('bar.git', [
      libDir('bar', 'bar 2'),
      libPubspec('bar', '1.0.0')
    ]).scheduleCommit();

    schedulePub(args: ['update'],
        output: const RegExp(@"Dependencies updated!$"));

    dir(packagesPath, [
      dir('foo', [
        file('foo.dart', 'main() => "foo 2";')
      ]),
      dir('bar', [
        file('bar.dart', 'main() => "bar 2";')
      ])
    ]).scheduleValidate();

    run();
  });

  test("updates Git packages to an incompatible pubspec", () {
    ensureGit();

    git('foo.git', [
      libDir('foo'),
      libPubspec('foo', '1.0.0')
    ]).scheduleCreate();

    appDir([{"git": "../foo.git"}]).scheduleCreate();

    schedulePub(args: ['install'],
        output: const RegExp(@"Dependencies installed!$"));

    dir(packagesPath, [
      dir('foo', [
        file('foo.dart', 'main() => "foo";')
      ])
    ]).scheduleValidate();

    git('foo.git', [
      libDir('zoo'),
      libPubspec('zoo', '1.0.0')
    ]).scheduleCommit();

    schedulePub(args: ['update'],
        error: const RegExp(@'The name you specified for your dependency, '
            @'"foo", doesn' @"'" @'t match the name "zoo" in its pubspec.'),
        exitCode: 1);

    dir(packagesPath, [
      dir('foo', [
        file('foo.dart', 'main() => "foo";')
      ])
    ]).scheduleValidate();

    run();
  });

  solo_test("updates Git packages to a nonexistent pubspec", () {
    ensureGit();

    var repo = git('foo.git', [
      libDir('foo'),
      libPubspec('foo', '1.0.0')
    ]);
    repo.scheduleCreate();

    appDir([{"git": "../foo.git"}]).scheduleCreate();

    schedulePub(args: ['install'],
        output: const RegExp(@"Dependencies installed!$"));

    dir(packagesPath, [
      dir('foo', [
        file('foo.dart', 'main() => "foo";')
      ])
    ]).scheduleValidate();

    repo.scheduleGit(['rm', 'pubspec.yaml']);
    repo.scheduleGit(['commit', '-m', 'delete']);

    schedulePub(args: ['update'],
        error: const RegExp(@'Package "foo" doesn' @"'" @'t have a '
            @'pubspec.yaml file.'),
        exitCode: 1);

    dir(packagesPath, [
      dir('foo', [
        file('foo.dart', 'main() => "foo";')
      ])
    ]).scheduleValidate();

    run();
  });

  group("with an argument", () {
    test("updates one locked Git package but no others", () {
      ensureGit();

      git('foo.git', [
        libDir('foo'),
        libPubspec('foo', '1.0.0')
      ]).scheduleCreate();

      git('bar.git', [
        libDir('bar'),
        libPubspec('bar', '1.0.0')
      ]).scheduleCreate();

      appDir([{"git": "../foo.git"}, {"git": "../bar.git"}]).scheduleCreate();

      schedulePub(args: ['install'],
          output: const RegExp(@"Dependencies installed!$"));

      dir(packagesPath, [
        dir('foo', [
          file('foo.dart', 'main() => "foo";')
        ]),
        dir('bar', [
          file('bar.dart', 'main() => "bar";')
        ])
      ]).scheduleValidate();

      git('foo.git', [
        libDir('foo', 'foo 2'),
        libPubspec('foo', '1.0.0')
      ]).scheduleCommit();

      git('bar.git', [
        libDir('bar', 'bar 2'),
        libPubspec('bar', '1.0.0')
      ]).scheduleCommit();

      schedulePub(args: ['update', 'foo'],
          output: const RegExp(@"Dependencies updated!$"));

      dir(packagesPath, [
        dir('foo', [
          file('foo.dart', 'main() => "foo 2";')
        ]),
        dir('bar', [
          file('bar.dart', 'main() => "bar";')
        ])
      ]).scheduleValidate();

      run();
    });

    test("doesn't update one locked Git package's dependencies if it's not "
        "necessary", () {
      ensureGit();

      git('foo.git', [
        libDir('foo'),
        libPubspec("foo", "1.0.0", [{"git": "../foo-dep.git"}])
      ]).scheduleCreate();

      git('foo-dep.git', [
        libDir('foo-dep'),
        libPubspec('foo-dep', '1.0.0')
      ]).scheduleCreate();

      appDir([{"git": "../foo.git"}]).scheduleCreate();

      schedulePub(args: ['install'],
          output: const RegExp(@"Dependencies installed!$"));

      dir(packagesPath, [
        dir('foo', [
          file('foo.dart', 'main() => "foo";')
        ]),
        dir('foo-dep', [
          file('foo-dep.dart', 'main() => "foo-dep";')
        ])
      ]).scheduleValidate();

      git('foo.git', [
        libDir('foo', 'foo 2'),
        libPubspec("foo", "1.0.0", [{"git": "../foo-dep.git"}])
      ]).scheduleCreate();

      git('foo-dep.git', [
        libDir('foo-dep', 'foo-dep 2'),
        libPubspec('foo-dep', '1.0.0')
      ]).scheduleCommit();

      schedulePub(args: ['update', 'foo'],
          output: const RegExp(@"Dependencies updated!$"));

      dir(packagesPath, [
        dir('foo', [
          file('foo.dart', 'main() => "foo 2";')
        ]),
        dir('foo-dep', [
          file('foo-dep.dart', 'main() => "foo-dep";')
        ]),
      ]).scheduleValidate();

      run();
    });
  });
}

{'fraction_non_alphanumeric': 0.2335005789270552, 'fraction_numerical': 0.01071015052103435, 'mean_word_length': 2.259433962264151, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 31, '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': '3004105', 'n_tokens_mistral': 3526, 'n_tokens_neox': 3324, 'n_words': 651}