Skip to content

Commit 080f2d4

Browse files
fingolfincodex
andauthored
Fix running testsuite from out-of-tree (#364)
Fix running the test suite via `TestPackage("AutoDoc")` when the current working directory is not the package root. This is essential for passing the package distribution tests. Co-authored-by: Codex <codex@openai.com>
1 parent 3f73702 commit 080f2d4

4 files changed

Lines changed: 67 additions & 7 deletions

File tree

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
This file describes changes in the AutoDoc package.
22

3+
## 2026.03.18
4+
- Fix running the test suite via `TestPackage("AutoDoc")` when the
5+
current working directory is not the package root
6+
37
## 2026.03.17
48

59
+ **Breaking changes**

gap/Parser.gi

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles,
298298
comment_start_pos, context_stack, current_command,
299299
current_line, current_line_fence, current_line_info,
300300
current_line_is_fence_delimiter, current_line_positition_for_filter,
301-
current_line_unedited, filename, filestream, groupnumber,
302-
line_number, markdown_fence, plain_text_mode, rest_of_file_skipped,
301+
current_line_unedited, display_filename, filename,
302+
filestream, groupnumber, line_number,
303+
markdown_fence, plain_text_mode, rest_of_file_skipped,
303304
scope_group, single_line_title_item_list, title_item,
304305
title_item_list, xml_comment_mode;
305306
groupnumber := 0;
@@ -325,11 +326,14 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles,
325326
end;
326327
ErrorWithPos := function(arg)
327328
local list;
328-
list := Concatenation(arg, [ ",\n", "at ", filename, ":", line_number]);
329+
list := Concatenation(
330+
arg,
331+
[ ",\n", "at ", display_filename, ":", line_number ]
332+
);
329333
CallFuncList(Error, list);
330334
end;
331335
CurrentSourcePosition := function()
332-
return rec( filename := filename, line := line_number );
336+
return rec( filename := display_filename, line := line_number );
333337
end;
334338
RecordStringSourcePosition := function( item )
335339
local source_field;
@@ -1220,6 +1224,12 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles,
12201224
rest_of_file_skipped := false;
12211225
##Now read the files.
12221226
for filename in filename_list do
1227+
if IsString( filename ) then
1228+
display_filename := filename;
1229+
else
1230+
display_filename := filename.display;
1231+
filename := filename.path;
1232+
fi;
12231233
Reset();
12241234
##Need to set autodoc_read_line to false again since we now look at a new file.
12251235
autodoc_read_line := false;

tst/errorwithpos.tst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
#
22
# test parser error reporting with ErrorWithPos
3+
gap> autodoc_pkgroot := Filename( DirectoriesPackageLibrary( "AutoDoc", "" ), "" );;
4+
gap> if not StartsWith( autodoc_pkgroot, "/" ) then
5+
> autodoc_pkgroot := Filename(
6+
> Directory( AUTODOC_CurrentDirectory() ),
7+
> autodoc_pkgroot
8+
> );
9+
> fi;
310
gap> ParseFixture := function( arg )
4-
> local tree, default_chapter_data;
11+
> local tree, default_chapter_data, file;
512
> tree := DocumentationTree();
613
> if Length( arg ) > 1 then
714
> default_chapter_data := arg[ 2 ];
815
> else
916
> default_chapter_data := CreateDefaultChapterData( "Pkg" );
1017
> fi;
11-
> AutoDoc_Parser_ReadFiles( [ arg[ 1 ] ], tree, default_chapter_data );
18+
> file := rec(
19+
> path := Filename( Directory( autodoc_pkgroot ), arg[ 1 ] ),
20+
> display := arg[ 1 ]
21+
> );
22+
> AutoDoc_Parser_ReadFiles( [ file ], tree, default_chapter_data );
1223
> return tree;
1324
> end;;
1425
gap> RenderFixtureDescription := function( file, item_name )

tst/misc.tst

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,43 @@ true
174174
#
175175
# AutoDoc_Parser_ReadFiles: multiline InstallMethod parsing
176176
#
177+
gap> autodoc_pkgroot := Filename( DirectoriesPackageLibrary( "AutoDoc", "" ), "" );;
178+
gap> if not StartsWith( autodoc_pkgroot, "/" ) then
179+
> autodoc_pkgroot := Filename(
180+
> Directory( AUTODOC_CurrentDirectory() ),
181+
> autodoc_pkgroot
182+
> );
183+
> fi;
184+
gap> parser_fixture := rec(
185+
> path := Filename(
186+
> Directory( autodoc_pkgroot ),
187+
> "tst/autodoc-parser-installmethod.g"
188+
> ),
189+
> display := "tst/autodoc-parser-installmethod.g"
190+
> );;
177191
gap> tree := DocumentationTree();;
178-
gap> AutoDoc_Parser_ReadFiles( [ "tst/autodoc-parser-installmethod.g" ], tree, rec() );
192+
gap> AutoDoc_Parser_ReadFiles( [ parser_fixture ], tree, rec() );
193+
gap> section := SectionInTree( tree, "Parser", "InstallMethod" );;
194+
gap> item := section!.content[ 1 ];;
195+
gap> item!.item_type;
196+
"Func"
197+
gap> item!.name;
198+
"MyOp"
199+
gap> item!.tester_names;
200+
"for IsInt,IsString"
201+
gap> item!.arguments;
202+
"x,y"
203+
gap> olddir := Filename(DirectoryCurrent(), "");;
204+
gap> ChangeDirectoryCurrent(Filename(DirectoryTemporary(), ""));
205+
true
206+
gap> tree := DocumentationTree();;
207+
gap> AutoDoc_Parser_ReadFiles(
208+
> [ parser_fixture ],
209+
> tree,
210+
> rec()
211+
> );
212+
gap> ChangeDirectoryCurrent(olddir);
213+
true
179214
gap> section := SectionInTree( tree, "Parser", "InstallMethod" );;
180215
gap> item := section!.content[ 1 ];;
181216
gap> item!.item_type;

0 commit comments

Comments
 (0)