|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:engine_tool/src/gn.dart'; |
| 6 | +import 'package:engine_tool/src/label.dart'; |
| 7 | +import 'package:litetest/litetest.dart'; |
| 8 | + |
| 9 | +import 'utils.dart'; |
| 10 | + |
| 11 | +void main() { |
| 12 | + test('gn.desc handles a non-zero exit code', () async { |
| 13 | + final TestEnvironment testEnv = TestEnvironment.withTestEngine( |
| 14 | + cannedProcesses: <CannedProcess>[ |
| 15 | + CannedProcess( |
| 16 | + (List<String> command) => command.contains('desc'), |
| 17 | + exitCode: 1, |
| 18 | + stdout: 'stdout', |
| 19 | + stderr: 'stderr', |
| 20 | + ), |
| 21 | + ], |
| 22 | + ); |
| 23 | + try { |
| 24 | + final Gn gn = Gn.fromEnvironment(testEnv.environment); |
| 25 | + await gn.desc('out/Release', TargetPattern('//foo', 'bar')); |
| 26 | + fail('Expected an exception'); |
| 27 | + } catch (e) { |
| 28 | + final String message = '$e'; |
| 29 | + expect(message, contains('Failed to run')); |
| 30 | + expect(message, contains('exit code 1')); |
| 31 | + expect(message, contains('STDOUT:\nstdout')); |
| 32 | + expect(message, contains('STDERR:\nstderr')); |
| 33 | + } finally { |
| 34 | + testEnv.cleanup(); |
| 35 | + } |
| 36 | + }); |
| 37 | + |
| 38 | + test('gn.desc handles unparseable stdout', () async { |
| 39 | + final TestEnvironment testEnv = TestEnvironment.withTestEngine( |
| 40 | + cannedProcesses: <CannedProcess>[ |
| 41 | + CannedProcess( |
| 42 | + (List<String> command) => command.contains('desc'), |
| 43 | + stdout: 'not json', |
| 44 | + ), |
| 45 | + ], |
| 46 | + ); |
| 47 | + try { |
| 48 | + final Gn gn = Gn.fromEnvironment(testEnv.environment); |
| 49 | + await gn.desc('out/Release', TargetPattern('//foo', 'bar')); |
| 50 | + fail('Expected an exception'); |
| 51 | + } catch (e) { |
| 52 | + final String message = '$e'; |
| 53 | + expect(message, contains('Failed to parse JSON')); |
| 54 | + expect(message, contains('not json')); |
| 55 | + } finally { |
| 56 | + testEnv.cleanup(); |
| 57 | + } |
| 58 | + }); |
| 59 | + |
| 60 | + test('gn.desc parses build targets', () async { |
| 61 | + final TestEnvironment testEnv = TestEnvironment.withTestEngine( |
| 62 | + cannedProcesses: <CannedProcess>[ |
| 63 | + CannedProcess( |
| 64 | + (List<String> command) => command.contains('desc'), |
| 65 | + stdout: ''' |
| 66 | + { |
| 67 | + "//foo/bar:baz_test": { |
| 68 | + "outputs": ["//out/host_debug/foo/bar/baz_test"], |
| 69 | + "testonly": true, |
| 70 | + "type": "executable" |
| 71 | + }, |
| 72 | + "//foo/bar:baz_shared_library": { |
| 73 | + "testonly": false, |
| 74 | + "type": "shared_library" |
| 75 | + }, |
| 76 | + "//foo/bar:baz_static_library": { |
| 77 | + "testonly": false, |
| 78 | + "type": "static_library" |
| 79 | + } |
| 80 | + } |
| 81 | + ''', |
| 82 | + ), |
| 83 | + ], |
| 84 | + ); |
| 85 | + try { |
| 86 | + final Gn gn = Gn.fromEnvironment(testEnv.environment); |
| 87 | + final List<BuildTarget> targets = await gn.desc('out/Release', TargetPattern('//foo', 'bar')); |
| 88 | + expect(targets, hasLength(3)); |
| 89 | + |
| 90 | + // There should be exactly one binary test target and two library targets. |
| 91 | + final ExecutableBuildTarget testTarget = targets.whereType<ExecutableBuildTarget>().single; |
| 92 | + expect(testTarget, ExecutableBuildTarget( |
| 93 | + label: Label('//foo/bar', 'baz_test'), |
| 94 | + testOnly: true, |
| 95 | + executable: 'out/host_debug/foo/bar/baz_test', |
| 96 | + )); |
| 97 | + |
| 98 | + final List<LibraryBuildTarget> libraryTargets = targets.whereType<LibraryBuildTarget>().toList(); |
| 99 | + expect(libraryTargets, hasLength(2)); |
| 100 | + expect(libraryTargets.contains(LibraryBuildTarget( |
| 101 | + label: Label('//foo/bar', 'baz_shared_library'), |
| 102 | + testOnly: false, |
| 103 | + )), isTrue); |
| 104 | + expect(libraryTargets.contains(LibraryBuildTarget( |
| 105 | + label: Label('//foo/bar', 'baz_static_library'), |
| 106 | + testOnly: false, |
| 107 | + )), isTrue); |
| 108 | + } finally { |
| 109 | + testEnv.cleanup(); |
| 110 | + } |
| 111 | + }); |
| 112 | +} |
0 commit comments