@@ -577,44 +577,53 @@ var ErrInfiniteLoop = fmt.Errorf("infinite loop in template variables detected")
577577// interface being mocked. If this argument is nil, interface-specific template
578578// variables will be set to the empty string. The srcPkg is also needed to
579579// satisfy template variables regarding the source package.
580- func (c * Config ) ParseTemplates (ctx context.Context , ifaceFileName string , ifaceName string , srcPkg * packages.Package ) error {
580+ func (c * Config ) ParseTemplates (
581+ ctx context.Context ,
582+ // ifaceFilePath is the absolute path of the original interface.
583+ ifaceFilePath string ,
584+ ifaceName string ,
585+ srcPkg * packages.Package ,
586+ ) error {
581587 log := zerolog .Ctx (ctx )
582588
583589 mock := "mock"
584590 if ast .IsExported (ifaceName ) {
585591 mock = "Mock"
586592 }
587593
588- var (
589- interfaceDir string
590- interfaceDirRelative string
591- interfaceFile string
592- interfaceName string
593- )
594- interfaceFile = ifaceFileName
595- interfaceName = ifaceName
596-
597594 workingDir , err := os .Getwd ()
598595 if err != nil {
599596 return fmt .Errorf ("get working directory: %w" , err )
600597 }
601- interfaceDirPath := pathlib .NewPath (ifaceFileName ).Parent ()
602- interfaceDir = interfaceDirPath .String ()
598+ interfaceDirPath := pathlib .NewPath (ifaceFilePath ).Parent ()
603599 interfaceDirRelativePath , err := interfaceDirPath .RelativeToStr (workingDir )
600+
601+ var interfaceDirRelative string
602+
604603 if err != nil {
605- log .Debug ().Err (err ).Msg ("can't make path relative to working dir, setting to './'" )
604+ log .Debug ().
605+ Err (err ).
606+ Str ("working-dir" , workingDir ).
607+ Str ("interfaceDirPath" , interfaceDirPath .String ()).
608+ Str ("interface-dir-relative-path" , interfaceDirRelativePath .String ()).
609+ Msg ("can't make path relative to working dir, setting to './'" )
606610 interfaceDirRelative = "."
607611 } else {
612+ log .Debug ().
613+ Str ("working-dir" , workingDir ).
614+ Str ("interfaceDirPath" , interfaceDirPath .String ()).
615+ Str ("interface-dir-relative-path" , interfaceDirRelativePath .String ()).
616+ Msg ("found relative path" )
608617 interfaceDirRelative = interfaceDirRelativePath .String ()
609618 }
610619
611620 // data is the struct sent to the template parser
612621 data := TemplateData {
613622 ConfigDir : filepath .Dir (* c .ConfigFile ),
614- InterfaceDir : interfaceDir ,
623+ InterfaceDir : interfaceDirPath . String () ,
615624 InterfaceDirRelative : interfaceDirRelative ,
616- InterfaceFile : interfaceFile ,
617- InterfaceName : interfaceName ,
625+ InterfaceFile : ifaceFilePath ,
626+ InterfaceName : ifaceName ,
618627 Mock : mock ,
619628 StructName : * c .StructName ,
620629 SrcPackageName : srcPkg .Types .Name (),
0 commit comments