From 9f60c38f5009e2edfd09ad0f2babf886e234a19b Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Thu, 15 Jun 2023 19:17:12 +0000 Subject: [PATCH] Add a test for root_line with aboslute test path Towards #2037 Add a test case running a file with an absolute path. --- pkgs/test/test/runner/json_reporter_test.dart | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/pkgs/test/test/runner/json_reporter_test.dart b/pkgs/test/test/runner/json_reporter_test.dart index b6b3317d7..5336b5433 100644 --- a/pkgs/test/test/runner/json_reporter_test.dart +++ b/pkgs/test/test/runner/json_reporter_test.dart @@ -512,7 +512,7 @@ void main() { args: ['-p', 'chrome']); }, tags: ['chrome'], skip: 'https://github.com/dart-lang/test/issues/872'); - test('the root suite if applicable', () { + test('the root suite from a relative path', () { return _expectReport( ''' customTest('success 1', () {}); @@ -543,6 +543,43 @@ void main() { 'common.dart': ''' import 'package:test/test.dart'; +void customTest(String name, dynamic Function() testFn) => test(name, testFn); +''', + }); + }); + + test('the root suite from an absolute path', () { + return _expectReport( + ''' + customTest('success 1', () {}); + test('success 2', () {}); + ''', + useRelativePath: false, + [ + [ + suiteJson(0), + testStartJson(1, 'loading test.dart', groupIDs: []), + testDoneJson(1, hidden: true), + ], + [ + groupJson(2, testCount: 2), + testStartJson(3, 'success 1', + line: 3, + column: 60, + url: p.toUri(p.join(d.sandbox, 'common.dart')).toString(), + rootColumn: 7, + rootLine: 7, + rootUrl: p.toUri(p.join(d.sandbox, 'test.dart')).toString()), + testDoneJson(3), + testStartJson(4, 'success 2', line: 8, column: 7), + testDoneJson(4), + ] + ], + doneJson(), + externalLibraries: { + 'common.dart': ''' +import 'package:test/test.dart'; + void customTest(String name, dynamic Function() testFn) => test(name, testFn); ''', }); @@ -586,6 +623,7 @@ void customTest(String name, dynamic Function() testFn) => test(name, testFn); Future _expectReport(String tests, List> expected, Map done, {List args = const [], + bool useRelativePath = true, Map externalLibraries = const {}}) async { var testContent = StringBuffer(''' import 'dart:async'; @@ -603,8 +641,9 @@ import 'package:test/test.dart'; ..writeln('}'); await d.file('test.dart', testContent.toString()).create(); + var testPath = useRelativePath ? 'test.dart' : p.join(d.sandbox, 'test.dart'); - var test = await runTest(['test.dart', '--chain-stack-traces', ...args], + var test = await runTest([testPath, '--chain-stack-traces', ...args], reporter: 'json'); await test.shouldExit();