-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[native_assets_cli] Add version skew regression test back in
- Loading branch information
Showing
16 changed files
with
214 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
pkgs/native_assets_builder/test/build_runner/version_skew_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
import 'package:test/test.dart'; | ||
|
||
import '../helpers.dart'; | ||
import 'helpers.dart'; | ||
|
||
const Timeout longTimeout = Timeout(Duration(minutes: 5)); | ||
|
||
void main() async { | ||
test('Test hook using an older version of native_assets_cli', | ||
timeout: longTimeout, () async { | ||
await inTempDir((tempUri) async { | ||
await copyTestProjects(targetUri: tempUri); | ||
final packageUri = tempUri.resolve('native_add_version_skew/'); | ||
|
||
// First, run `pub get`, we need pub to resolve our dependencies. | ||
await runPubGet( | ||
workingDirectory: packageUri, | ||
logger: logger, | ||
); | ||
|
||
{ | ||
final result = await build( | ||
packageUri, | ||
logger, | ||
dartExecutable, | ||
configValidator: validateCodeAssetBuildConfig, | ||
buildAssetTypes: [CodeAsset.type], | ||
buildValidator: validateCodeAssetBuildOutput, | ||
applicationAssetValidator: validateCodeAssetInApplication, | ||
); | ||
expect(result?.encodedAssets.length, 1); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
pkgs/native_assets_builder/test_data/native_add_version_skew/ffigen.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Run with `flutter pub run ffigen --config ffigen.yaml`. | ||
name: NativeAddBindings | ||
description: | | ||
Bindings for `src/native_add.h`. | ||
Regenerate bindings with `flutter pub run ffigen --config ffigen.yaml`. | ||
output: "lib/src/native_add_bindings_generated.dart" | ||
headers: | ||
entry-points: | ||
- "src/native_add.h" | ||
include-directives: | ||
- "src/native_add.h" | ||
preamble: | | ||
// Copyright (c) 2023, 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. | ||
comments: | ||
style: any | ||
length: full | ||
ffi-native: |
29 changes: 29 additions & 0 deletions
29
pkgs/native_assets_builder/test_data/native_add_version_skew/hook/build.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
import 'package:logging/logging.dart'; | ||
import 'package:native_assets_cli/native_assets_cli.dart'; | ||
import 'package:native_toolchain_c/native_toolchain_c.dart'; | ||
|
||
void main(List<String> arguments) async { | ||
await build(arguments, (config, output) async { | ||
final packageName = config.packageName; | ||
final cbuilder = CBuilder.library( | ||
name: packageName, | ||
assetName: 'src/${packageName}_bindings_generated.dart', | ||
sources: [ | ||
'src/$packageName.c', | ||
], | ||
); | ||
await cbuilder.run( | ||
config: config, | ||
output: output, | ||
logger: Logger('') | ||
..level = Level.ALL | ||
..onRecord.listen((record) { | ||
print('${record.level.name}: ${record.time}: ${record.message}'); | ||
}), | ||
); | ||
}); | ||
} |
5 changes: 5 additions & 0 deletions
5
pkgs/native_assets_builder/test_data/native_add_version_skew/lib/native_add.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
export 'src/native_add.dart'; |
7 changes: 7 additions & 0 deletions
7
pkgs/native_assets_builder/test_data/native_add_version_skew/lib/src/native_add.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
import 'native_add_bindings_generated.dart' as bindings; | ||
|
||
int add(int a, int b) => bindings.add(a, b); |
15 changes: 15 additions & 0 deletions
15
...sets_builder/test_data/native_add_version_skew/lib/src/native_add_bindings_generated.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
// AUTO GENERATED FILE, DO NOT EDIT. | ||
// | ||
// Generated by `package:ffigen`. | ||
// ignore_for_file: type=lint | ||
import 'dart:ffi' as ffi; | ||
|
||
@ffi.Native<ffi.Int32 Function(ffi.Int32, ffi.Int32)>(symbol: 'add') | ||
external int add( | ||
int a, | ||
int b, | ||
); |
9 changes: 9 additions & 0 deletions
9
pkgs/native_assets_builder/test_data/native_add_version_skew/manifest.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- ffigen.yaml | ||
- hook/build.dart | ||
- lib/native_add.dart | ||
- lib/src/native_add_bindings_generated.dart | ||
- lib/src/native_add.dart | ||
- pubspec.yaml | ||
- src/native_add.c | ||
- src/native_add.h | ||
- test/native_add_test.dart |
20 changes: 20 additions & 0 deletions
20
pkgs/native_assets_builder/test_data/native_add_version_skew/pubspec.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: native_add | ||
description: Sums two numbers with native code. | ||
version: 0.1.0 | ||
|
||
publish_to: none | ||
|
||
environment: | ||
sdk: '>=3.3.0 <4.0.0' | ||
|
||
dependencies: | ||
logging: ^1.1.1 | ||
native_assets_cli: ^0.9.0 | ||
native_toolchain_c: ^0.6.0 | ||
|
||
dev_dependencies: | ||
ffigen: ^8.0.2 | ||
lints: ^3.0.0 | ||
some_dev_dep: | ||
path: ../some_dev_dep/ | ||
test: ^1.23.1 |
9 changes: 9 additions & 0 deletions
9
pkgs/native_assets_builder/test_data/native_add_version_skew/src/native_add.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
#include "native_add.h" | ||
|
||
int32_t add(int32_t a, int32_t b) { | ||
return a + b; | ||
} |
13 changes: 13 additions & 0 deletions
13
pkgs/native_assets_builder/test_data/native_add_version_skew/src/native_add.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
#include <stdint.h> | ||
|
||
#if _WIN32 | ||
#define MYLIB_EXPORT __declspec(dllexport) | ||
#else | ||
#define MYLIB_EXPORT | ||
#endif | ||
|
||
MYLIB_EXPORT int32_t add(int32_t a, int32_t b); |
13 changes: 13 additions & 0 deletions
13
pkgs/native_assets_builder/test_data/native_add_version_skew/test/native_add_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
import 'package:native_add/native_add.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
test('native add test', () { | ||
final result = add(4, 6); | ||
expect(result, equals(10)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters