|
| 1 | +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:test/test.dart'; |
| 6 | + |
| 7 | +import 'invalidation_tester.dart'; |
| 8 | + |
| 9 | +/// Invalidation tests in which the inputs are individually read arbitrary assets. |
| 10 | +void main() { |
| 11 | + late InvalidationTester tester; |
| 12 | + |
| 13 | + setUp(() { |
| 14 | + tester = InvalidationTester(); |
| 15 | + }); |
| 16 | + |
| 17 | + group('a+(z) <-- a.1', () { |
| 18 | + setUp(() { |
| 19 | + tester.sources(['a', 'z']); |
| 20 | + tester.builder(from: '', to: '.1') |
| 21 | + ..readsOther('z') |
| 22 | + ..writes('.1'); |
| 23 | + }); |
| 24 | + |
| 25 | + test('a.1 is built', () async { |
| 26 | + expect(await tester.build(), Result(written: ['a.1', 'z.1'])); |
| 27 | + }); |
| 28 | + |
| 29 | + test('change z, a.1 is rebuilt', () async { |
| 30 | + await tester.build(); |
| 31 | + expect(await tester.build(change: 'z'), Result(written: ['a.1', 'z.1'])); |
| 32 | + }); |
| 33 | + |
| 34 | + test('delete z, a.1 is rebuilt', () async { |
| 35 | + await tester.build(); |
| 36 | + expect( |
| 37 | + await tester.build(delete: 'z'), |
| 38 | + // TODO(davidmorgan): a.1 should be rebuilt, but it's not. This is a |
| 39 | + // regression since the last version on pub: fix it! |
| 40 | + // Result(written: ['a.1'], deleted: ['z.1']) |
| 41 | + Result(deleted: ['z.1']), |
| 42 | + ); |
| 43 | + }); |
| 44 | + |
| 45 | + test('create z, a.1 is rebuilt', () async { |
| 46 | + tester.sources(['a']); |
| 47 | + expect(await tester.build(), Result(written: ['a.1'])); |
| 48 | + expect(await tester.build(create: 'z'), Result(written: ['a.1', 'z.1'])); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + group('a.1 <== a.2, b.3+(a.2) <== b.4', () { |
| 53 | + setUp(() { |
| 54 | + tester.sources(['a.1', 'b.3']); |
| 55 | + tester.builder(from: '.1', to: '.2') |
| 56 | + ..reads('.1') |
| 57 | + ..writes('.2'); |
| 58 | + tester.builder(from: '.3', to: '.4') |
| 59 | + ..reads('.3') |
| 60 | + ..readsOther('a.2') |
| 61 | + ..writes('.4'); |
| 62 | + }); |
| 63 | + |
| 64 | + test('a.4 is built', () async { |
| 65 | + expect(await tester.build(), Result(written: ['a.2', 'b.4'])); |
| 66 | + }); |
| 67 | + |
| 68 | + test('change a.1, a.2+b.4 are rebuilt', () async { |
| 69 | + await tester.build(); |
| 70 | + expect( |
| 71 | + await tester.build(change: 'a.1'), |
| 72 | + Result(written: ['a.2', 'b.4']), |
| 73 | + ); |
| 74 | + }); |
| 75 | + |
| 76 | + test('delete a.1, a.2+b.4 are rebuilt', () async { |
| 77 | + await tester.build(); |
| 78 | + expect( |
| 79 | + await tester.build(delete: 'a.1'), |
| 80 | + // TODO(davidmorgan): a.1 should be rebuilt, but it's not. This is a |
| 81 | + // regression since the last version on pub: fix it! |
| 82 | + // Result(written: ['a.2', 'b.4']), |
| 83 | + Result(deleted: ['a.2']), |
| 84 | + ); |
| 85 | + }); |
| 86 | + |
| 87 | + test('create a.1, a.2+b.4 are rebuilt', () async { |
| 88 | + tester.sources(['b.3']); |
| 89 | + await tester.build(); |
| 90 | + expect( |
| 91 | + await tester.build(create: 'a.1'), |
| 92 | + Result(written: ['a.2', 'b.4']), |
| 93 | + ); |
| 94 | + }); |
| 95 | + }); |
| 96 | +} |
0 commit comments