import 'dart:io'; import 'package:path/path.dart' as p; import 'package:pipe/pipe.dart'; import 'package:pipe/src/cli.dart'; import 'package:test/test.dart'; /// A copy of the rule fixture, so a baseline can be written at its root. String _fixtureCopy() { final from = Directory('test/fixtures/stuck_loading'); final to = Directory.systemTemp.createTempSync('pipe-verify-default'); for (final entity in from.listSync(recursive: true)) { final target = p.join(to.path, p.relative(entity.path, from: from.path)); if (entity is Directory) { Directory(target).createSync(recursive: true); } else if (entity is File) { File(target) ..createSync(recursive: true) ..writeAsBytesSync(entity.readAsBytesSync()); } } return to.path; } void main() { // `pipe verify .` used to fail with "verify needs --baseline" even in a repo // whose baseline sits at the conventional path the README's CI recipe // writes (nuwayze's scripts/testing/pipe_state_flow_gate.sh). group('resolveVerifyBaseline', () { late Directory temp; setUp(() => temp = Directory.systemTemp.createTempSync('pipe-verify-bl')); tearDown(() => temp.deleteSync(recursive: true)); test('an explicit --baseline wins, with nothing announced', () { File(p.join(temp.path, defaultBaselineName)).writeAsStringSync('{}'); final log = StringBuffer(); expect( resolveVerifyBaseline('other.json', temp.path, log: log), 'other.json', ); expect(log.toString(), isEmpty); }); test('without --baseline the conventional file is used and announced', () { final conventional = p.join(temp.path, defaultBaselineName); File(conventional).writeAsStringSync('{}'); final log = StringBuffer(); expect(resolveVerifyBaseline(null, temp.path, log: log), conventional); expect(log.toString(), contains('using $conventional')); }); test('without either, the error names both remedies', () { expect( () => resolveVerifyBaseline(null, temp.path, log: StringBuffer()), throwsA( isA() .having((e) => e.message, 'message', contains('--baseline')) .having( (e) => e.remedy, 'remedy', allOf( contains('--baseline'), contains(p.join(temp.path, defaultBaselineName)), ), ), ), ); }); }); test('pipe verify reads /.pipe-baseline.json', () async { final root = _fixtureCopy(); try { final baseline = p.join(root, defaultBaselineName); expect( await PipeRunner().run([ 'check', root, '--write-baseline', baseline, '-c', '1', ]), 0, ); // Nothing changed since the baseline, so every accepted finding remains // and --expect-resolved fails: proof the default baseline was read, // since an empty one would have nothing to expect. expect( await PipeRunner().run([ 'verify', root, '--expect-resolved', '-c', '1', ]), 1, ); } finally { Directory(root).deleteSync(recursive: true); } }); }