Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pkgs/ffigen/dart_test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# This package uses dart:ffi.
test_on: vm

# https://github.com/dart-lang/native/issues/461
concurrency: 1
10 changes: 6 additions & 4 deletions pkgs/ffigen/lib/src/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import 'dart:io';
import 'package:logging/logging.dart';

/// Creates a default logger that logs to stdout and stderr.
Logger createDefaultLogger() {
Logger createDefaultLogger([Level level = Level.INFO]) {
final logger = Logger.detached('FFIgen');
logger.level = Level.INFO;
logger.level = level;
logger.onRecord.listen((record) {
final levelStr = '[${record.level.name}]'.padRight(9);
final log = '$levelStr: ${record.message}';
if (record.level >= Level.WARNING) {
stderr.writeln(record.message);
stderr.writeln(log);
} else {
stdout.writeln(record.message);
stdout.writeln(log);
}
if (record.error != null) {
stderr.writeln(record.error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
import 'package:ffigen/src/code_generator.dart';
import 'package:ffigen/src/config_provider/config.dart';
import 'package:ffigen/src/header_parser/parser.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';
import '../test_utils.dart';

void main() {
group('decl_decl_collision_test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
});
test('declaration conflict', () {
final context = testContext(
FfiGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:ffigen/src/code_generator.dart';
import 'package:ffigen/src/config_provider/config.dart';
import 'package:ffigen/src/header_parser/parser.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';

import '../test_utils.dart';
Expand All @@ -14,7 +13,6 @@ late Library actual;
void main() {
group('decl_symbol_address_collision_test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
final context = testContext(
FfiGenerator(
output: Output(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:ffigen/src/code_generator.dart';
import 'package:ffigen/src/header_parser.dart' as parser;
import 'package:ffigen/src/strings.dart' as strings;
import 'package:logging/logging.dart';
import 'package:test/test.dart';

import '../test_utils.dart';
Expand All @@ -14,7 +13,6 @@ late Library actual;
void main() {
group('decl_type_name_collision test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
actual = parser.parse(
testContext(
testConfig('''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@

import 'package:ffigen/src/config_provider.dart';
import 'package:ffigen/src/header_parser.dart' as parser;
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import '../test_utils.dart';

void main() {
group('reserved_keyword_collision_test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
});
test('reserved keyword collision', () {
final library = parser.parse(
testContext(
Expand Down
15 changes: 10 additions & 5 deletions pkgs/ffigen/test/config_tests/deprecate_assetid_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ import '../test_utils.dart';
void main() {
group('deprecate_assetId_test', () {
final logArr = <String>[];
final logger = logToArray(logArr, Level.WARNING);
final config = testConfig('''
late FfiGenerator config;
setUpAll(() {
final logger = createTestLogger(
capturedMessages: logArr,
level: Level.WARNING,
);
config = testConfig('''
${strings.name}: 'NativeLibrary'
${strings.description}: 'Deprecation warning if assetId is used instead of ${strings.ffiNativeAsset}'
${strings.output}: 'unused'
Expand All @@ -25,9 +30,9 @@ ${strings.headers}:
${strings.entryPoints}:
- '${absPath('test/header_parser_tests/comment_markup.h')}'
''', logger: logger);
parse(Context(logger, config));
parse(Context(logger, config));
});

final logStr = logArr.join('\n');
test('asset-id is correctly set', () {
expect(config.output.style is NativeExternalBindings, true);
expect(
Expand All @@ -37,7 +42,7 @@ ${strings.headers}:
});

test('Deprecation Warning is logged', () {
expect(logStr.contains('DEPRECATION WARNING'), true);
expect(logArr.join('\n').contains('DEPRECATION WARNING'), true);
});
});
}
5 changes: 2 additions & 3 deletions pkgs/ffigen/test/config_tests/json_schema_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:ffigen/src/strings.dart' as strings;
import 'package:file/local.dart';
import 'package:glob/glob.dart';
import 'package:json_schema/json_schema.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';
Expand All @@ -20,14 +19,14 @@ import '../test_utils.dart';
void main() {
group('json_schema_test', () {
final schema = YamlConfig.getsRootConfigSpec(
Logger.root,
createTestLogger(),
).generateJsonSchema(strings.ffigenJsonSchemaId);

test('Schema Changes', () {
final actualJsonSchema =
const JsonEncoder.withIndent(strings.ffigenJsonSchemaIndent).convert(
YamlConfig.getsRootConfigSpec(
Logger.root,
createTestLogger(),
).generateJsonSchema(strings.ffigenJsonSchemaId),
);
final expectedJsonSchema = File(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ void main() {
group('no_cursor_definition_warn_test', () {
setUpAll(() {
final logArr = <String>[];
final logger = logToArray(logArr, Level.WARNING);
final logger = createTestLogger(
capturedMessages: logArr,
level: Level.WARNING,
);
final config = testConfig('''
${strings.name}: 'NativeLibrary'
${strings.description}: 'Warn for no cursor definition.'
Expand Down
5 changes: 4 additions & 1 deletion pkgs/ffigen/test/config_tests/unknown_keys_warn_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ void main() {
group('unknown_keys_warn_test', () {
setUpAll(() {
final logArr = <String>[];
final logger = logToArray(logArr, Level.WARNING);
final logger = createTestLogger(
capturedMessages: logArr,
level: Level.WARNING,
);
testConfig('''
${strings.name}: 'NativeLibrary'
${strings.description}: 'Warn for unknown keys.'
Expand Down
4 changes: 0 additions & 4 deletions pkgs/ffigen/test/example_tests/cjson_example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:ffigen/src/header_parser.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import '../test_utils.dart';

void main() {
group('cjson_example_test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
});
test('c_json', () {
final config = testConfigFromPath(
path.join(packagePathForTests, 'example', 'c_json', 'config.yaml'),
Expand Down
5 changes: 0 additions & 5 deletions pkgs/ffigen/test/example_tests/ffinative_example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:ffigen/src/header_parser.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import '../test_utils.dart';

void main() {
group('ffinative_example_test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
});

test('ffinative', () {
final config = testConfigFromPath(
path.join(packagePathForTests, 'example', 'ffinative', 'config.yaml'),
Expand Down
25 changes: 13 additions & 12 deletions pkgs/ffigen/test/example_tests/libclang_example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@

import 'dart:io';

import 'package:ffigen/src/code_generator/library.dart';
import 'package:ffigen/src/config_provider/config.dart';
import 'package:ffigen/src/header_parser.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import '../test_utils.dart';

void main() {
group('example_test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
});
test('libclang-example', () {
final configYaml = File(
path.join(
Expand All @@ -27,12 +21,19 @@ void main() {
'config.yaml',
),
).absolute;
late FfiGenerator generator;
late Library library;
withChDir(configYaml.path, () {
generator = testConfigFromPath(configYaml.path);
library = parse(testContext(generator));
});
final generator = testConfigFromPath(configYaml.path);

// The clang parser is run using the current working directory, and the
// libclang-example config relies on relative paths for one of its '-I'
// compiler options. It can't use absolute paths because it's checked in
// yaml code. To support concurrent tests, we can't set Directory.current.
// As a workaround, add an extra '-I' option that uses the absolute path.
generator.headers.compilerOptions!.add(
'-I${path.join(packagePathForTests, 'third_party/libclang/include')}',
);

final context = testContext(generator);
final library = parse(context);

matchLibraryWithExpected(library, 'example_libclang.dart', [
generator.output.dartFile.toFilePath(),
Expand Down
5 changes: 0 additions & 5 deletions pkgs/ffigen/test/example_tests/objective_c_example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@
library;

import 'package:ffigen/src/header_parser.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';

import '../../example/objective_c/generate_code.dart' show config;
import '../test_utils.dart';

void main() {
group('objective_c_example_test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
});

test('objective_c', () {
final output = parse(testContext(config)).generate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:ffigen/src/header_parser.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import '../test_utils.dart';

void main() {
group('shared_bindings_example', () {
setUpAll(() {
logWarnings(Level.SEVERE);
});

test('a_shared_base bindings', () {
final config = testConfigFromPath(
path.join(
Expand Down
5 changes: 0 additions & 5 deletions pkgs/ffigen/test/example_tests/simple_example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:ffigen/src/header_parser.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import '../test_utils.dart';

void main() {
group('simple_example_test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
});

test('simple', () {
final config = testConfigFromPath(
path.join(packagePathForTests, 'example', 'simple', 'config.yaml'),
Expand Down
5 changes: 0 additions & 5 deletions pkgs/ffigen/test/example_tests/swift_example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@ import 'dart:async';
import 'dart:io';

import 'package:ffigen/src/header_parser.dart';
import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';

import '../test_utils.dart';

void main() {
group('swift_example_test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
});

test('swift', () async {
// Run the swiftc command from the example README, to generate the header.
final process = await Process.start('swiftc', [
Expand Down
2 changes: 0 additions & 2 deletions pkgs/ffigen/test/header_parser_tests/comment_markup_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:ffigen/src/code_generator.dart';
import 'package:ffigen/src/header_parser.dart' as parser;
import 'package:ffigen/src/strings.dart' as strings;
import 'package:logging/logging.dart';
import 'package:test/test.dart';

import '../test_utils.dart';
Expand All @@ -14,7 +13,6 @@ late Library actual;
void main() {
group('comment_markup_test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
actual = parser.parse(
testContext(
testConfig('''
Expand Down
1 change: 0 additions & 1 deletion pkgs/ffigen/test/header_parser_tests/dart_handle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ late Library actual;
void main() {
group('dart_handle_test', () {
setUpAll(() {
logWarnings();
actual = parser.parse(
testContext(
testConfig('''
Expand Down
2 changes: 0 additions & 2 deletions pkgs/ffigen/test/header_parser_tests/enum_int_mimic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:ffigen/src/code_generator.dart';
import 'package:ffigen/src/header_parser.dart' as parser;
import 'package:ffigen/src/strings.dart' as strings;
import 'package:logging/logging.dart';
import 'package:test/test.dart';

import '../test_utils.dart';
Expand All @@ -14,7 +13,6 @@ late Library actual;
void main() {
group('enum_int_mimic', () {
setUpAll(() {
logWarnings(Level.SEVERE);
actual = parser.parse(
testContext(
testConfig('''
Expand Down
2 changes: 0 additions & 2 deletions pkgs/ffigen/test/header_parser_tests/forward_decl_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:ffigen/src/code_generator.dart';
import 'package:ffigen/src/header_parser.dart' as parser;
import 'package:ffigen/src/strings.dart' as strings;
import 'package:logging/logging.dart';
import 'package:test/test.dart';

import '../test_utils.dart';
Expand All @@ -14,7 +13,6 @@ late Library actual;
void main() {
group('forward_decl_test', () {
setUpAll(() {
logWarnings(Level.SEVERE);
actual = parser.parse(
testContext(
testConfig('''
Expand Down
Loading