From 6ac923274a8519249821db6fee4280c0e8abef42 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 18 Mar 2026 18:29:56 +0100 Subject: [PATCH 1/2] Fix running testsuite from out-of-tre 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 --- CHANGES.md | 4 ++++ gap/Parser.gi | 18 ++++++++++++++---- tst/errorwithpos.tst | 8 ++++++-- tst/misc.tst | 30 +++++++++++++++++++++++++++++- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 806fd9ca..1994d57b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ This file describes changes in the AutoDoc package. +## 2026.03.18 + - Fix running the test suite via `TestPackage("AutoDoc")` when the + current working directory is not the package root + ## 2026.03.17 + **Breaking changes** diff --git a/gap/Parser.gi b/gap/Parser.gi index ac9577d3..de75039f 100644 --- a/gap/Parser.gi +++ b/gap/Parser.gi @@ -298,8 +298,9 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles, comment_start_pos, context_stack, current_command, current_line, current_line_fence, current_line_info, current_line_is_fence_delimiter, current_line_positition_for_filter, - current_line_unedited, filename, filestream, groupnumber, - line_number, markdown_fence, plain_text_mode, rest_of_file_skipped, + current_line_unedited, display_filename, filename, + filestream, groupnumber, line_number, + markdown_fence, plain_text_mode, rest_of_file_skipped, scope_group, single_line_title_item_list, title_item, title_item_list, xml_comment_mode; groupnumber := 0; @@ -325,11 +326,14 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles, end; ErrorWithPos := function(arg) local list; - list := Concatenation(arg, [ ",\n", "at ", filename, ":", line_number]); + list := Concatenation( + arg, + [ ",\n", "at ", display_filename, ":", line_number ] + ); CallFuncList(Error, list); end; CurrentSourcePosition := function() - return rec( filename := filename, line := line_number ); + return rec( filename := display_filename, line := line_number ); end; RecordStringSourcePosition := function( item ) local source_field; @@ -1220,6 +1224,12 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles, rest_of_file_skipped := false; ##Now read the files. for filename in filename_list do + if IsString( filename ) then + display_filename := filename; + else + display_filename := filename.display; + filename := filename.path; + fi; Reset(); ##Need to set autodoc_read_line to false again since we now look at a new file. autodoc_read_line := false; diff --git a/tst/errorwithpos.tst b/tst/errorwithpos.tst index 179b818a..8bc03778 100644 --- a/tst/errorwithpos.tst +++ b/tst/errorwithpos.tst @@ -1,14 +1,18 @@ # # test parser error reporting with ErrorWithPos gap> ParseFixture := function( arg ) -> local tree, default_chapter_data; +> local tree, default_chapter_data, file; > tree := DocumentationTree(); > if Length( arg ) > 1 then > default_chapter_data := arg[ 2 ]; > else > default_chapter_data := CreateDefaultChapterData( "Pkg" ); > fi; -> AutoDoc_Parser_ReadFiles( [ arg[ 1 ] ], tree, default_chapter_data ); +> file := rec( +> path := Filename( DirectoriesPackageLibrary( "AutoDoc", "" ), arg[ 1 ] ), +> display := arg[ 1 ] +> ); +> AutoDoc_Parser_ReadFiles( [ file ], tree, default_chapter_data ); > return tree; > end;; gap> RenderFixtureDescription := function( file, item_name ) diff --git a/tst/misc.tst b/tst/misc.tst index 4d1231f5..5aa1f1d8 100644 --- a/tst/misc.tst +++ b/tst/misc.tst @@ -174,8 +174,36 @@ true # # AutoDoc_Parser_ReadFiles: multiline InstallMethod parsing # +gap> parser_fixture := rec( +> path := Filename( +> DirectoriesPackageLibrary("AutoDoc", ""), +> "tst/autodoc-parser-installmethod.g" +> ), +> display := "tst/autodoc-parser-installmethod.g" +> );; gap> tree := DocumentationTree();; -gap> AutoDoc_Parser_ReadFiles( [ "tst/autodoc-parser-installmethod.g" ], tree, rec() ); +gap> AutoDoc_Parser_ReadFiles( [ parser_fixture ], tree, rec() ); +gap> section := SectionInTree( tree, "Parser", "InstallMethod" );; +gap> item := section!.content[ 1 ];; +gap> item!.item_type; +"Func" +gap> item!.name; +"MyOp" +gap> item!.tester_names; +"for IsInt,IsString" +gap> item!.arguments; +"x,y" +gap> olddir := Filename(DirectoryCurrent(), "");; +gap> ChangeDirectoryCurrent(Filename(DirectoryTemporary(), "")); +true +gap> tree := DocumentationTree();; +gap> AutoDoc_Parser_ReadFiles( +> [ parser_fixture ], +> tree, +> rec() +> ); +gap> ChangeDirectoryCurrent(olddir); +true gap> section := SectionInTree( tree, "Parser", "InstallMethod" );; gap> item := section!.content[ 1 ];; gap> item!.item_type; From c00212253ee8feac7eec22c521242f54fe4e07f1 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 18 Mar 2026 23:37:28 +0100 Subject: [PATCH 2/2] tests: canonicalize package fixture root Make test fixture paths absolute before changing directories. Handle relative DirectoriesPackageLibrary results under --packagedirs. This commit was prepared with Codex for code edits. Co-authored-by: Codex --- tst/errorwithpos.tst | 9 ++++++++- tst/misc.tst | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tst/errorwithpos.tst b/tst/errorwithpos.tst index 8bc03778..00a84c83 100644 --- a/tst/errorwithpos.tst +++ b/tst/errorwithpos.tst @@ -1,5 +1,12 @@ # # test parser error reporting with ErrorWithPos +gap> autodoc_pkgroot := Filename( DirectoriesPackageLibrary( "AutoDoc", "" ), "" );; +gap> if not StartsWith( autodoc_pkgroot, "/" ) then +> autodoc_pkgroot := Filename( +> Directory( AUTODOC_CurrentDirectory() ), +> autodoc_pkgroot +> ); +> fi; gap> ParseFixture := function( arg ) > local tree, default_chapter_data, file; > tree := DocumentationTree(); @@ -9,7 +16,7 @@ gap> ParseFixture := function( arg ) > default_chapter_data := CreateDefaultChapterData( "Pkg" ); > fi; > file := rec( -> path := Filename( DirectoriesPackageLibrary( "AutoDoc", "" ), arg[ 1 ] ), +> path := Filename( Directory( autodoc_pkgroot ), arg[ 1 ] ), > display := arg[ 1 ] > ); > AutoDoc_Parser_ReadFiles( [ file ], tree, default_chapter_data ); diff --git a/tst/misc.tst b/tst/misc.tst index 5aa1f1d8..172a9057 100644 --- a/tst/misc.tst +++ b/tst/misc.tst @@ -174,9 +174,16 @@ true # # AutoDoc_Parser_ReadFiles: multiline InstallMethod parsing # +gap> autodoc_pkgroot := Filename( DirectoriesPackageLibrary( "AutoDoc", "" ), "" );; +gap> if not StartsWith( autodoc_pkgroot, "/" ) then +> autodoc_pkgroot := Filename( +> Directory( AUTODOC_CurrentDirectory() ), +> autodoc_pkgroot +> ); +> fi; gap> parser_fixture := rec( > path := Filename( -> DirectoriesPackageLibrary("AutoDoc", ""), +> Directory( autodoc_pkgroot ), > "tst/autodoc-parser-installmethod.g" > ), > display := "tst/autodoc-parser-installmethod.g"