Skip to content

Commit

Permalink
test dart directly
Browse files Browse the repository at this point in the history
asottile committed Jan 17, 2023
1 parent 2bd853e commit 043565d
Showing 5 changed files with 62 additions and 60 deletions.
4 changes: 0 additions & 4 deletions testing/resources/dart_repo/.pre-commit-hooks.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions testing/resources/dart_repo/bin/hello-world-dart.dart

This file was deleted.

10 changes: 0 additions & 10 deletions testing/resources/dart_repo/pubspec.yaml

This file was deleted.

62 changes: 62 additions & 0 deletions tests/languages/dart_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from __future__ import annotations

import re_assert

from pre_commit.languages import dart
from pre_commit.store import _make_local_repo
from testing.language_helpers import run_language


def test_dart(tmp_path):
pubspec_yaml = '''\
environment:
sdk: '>=2.10.0 <3.0.0'
name: hello_world_dart
executables:
hello-world-dart:
dependencies:
ansicolor: ^2.0.1
'''
hello_world_dart_dart = '''\
import 'package:ansicolor/ansicolor.dart';
void main() {
AnsiPen pen = new AnsiPen()..red();
print("hello hello " + pen("world"));
}
'''
tmp_path.joinpath('pubspec.yaml').write_text(pubspec_yaml)
bin_dir = tmp_path.joinpath('bin')
bin_dir.mkdir()
bin_dir.joinpath('hello-world-dart.dart').write_text(hello_world_dart_dart)

expected = (0, b'hello hello world\n')
assert run_language(tmp_path, dart, 'hello-world-dart') == expected


def test_dart_additional_deps(tmp_path):
_make_local_repo(str(tmp_path))

ret = run_language(
tmp_path,
dart,
'hello-world-dart',
deps=('hello_world_dart',),
)
assert ret == (0, b'hello hello world\n')


def test_dart_additional_deps_versioned(tmp_path):
_make_local_repo(str(tmp_path))

ret, out = run_language(
tmp_path,
dart,
'secure-random -l 4 -b 16',
deps=('encrypt:5.0.0',),
)
assert ret == 0
re_assert.Matches('^[a-f0-9]{8}\n$').assert_matches(out.decode())
40 changes: 0 additions & 40 deletions tests/repository_test.py
Original file line number Diff line number Diff line change
@@ -997,46 +997,6 @@ def test_dotnet_hook(tempdir_factory, store, repo):
)


def test_dart_hook(tempdir_factory, store):
_test_hook_repo(
tempdir_factory, store, 'dart_repo',
'hello-world-dart', [], b'hello hello world\n',
)


def test_local_dart_additional_dependencies(store):
config = {
'repo': 'local',
'hooks': [{
'id': 'local-dart',
'name': 'local-dart',
'entry': 'hello-world-dart',
'language': 'dart',
'additional_dependencies': ['hello_world_dart'],
}],
}
hook = _get_hook(config, store, 'local-dart')
ret, out = _hook_run(hook, (), color=False)
assert (ret, _norm_out(out)) == (0, b'hello hello world\n')


def test_local_dart_additional_dependencies_versioned(store):
config = {
'repo': 'local',
'hooks': [{
'id': 'local-dart',
'name': 'local-dart',
'entry': 'secure-random -l 4 -b 16',
'language': 'dart',
'additional_dependencies': ['encrypt:5.0.0'],
}],
}
hook = _get_hook(config, store, 'local-dart')
ret, out = _hook_run(hook, (), color=False)
assert ret == 0
re_assert.Matches('^[a-f0-9]{8}\r?\n$').assert_matches(out.decode())


def test_non_installable_hook_error_for_language_version(store, caplog):
config = {
'repo': 'local',

0 comments on commit 043565d

Please sign in to comment.