Skip to content

Commit

Permalink
Test: Move writePackageFile to UFCS, better document
Browse files Browse the repository at this point in the history
This is another step in separating FSEntry from TestDub.
  • Loading branch information
Geod24 authored and dlang-bot committed Feb 22, 2024
1 parent 203a3ca commit 29c829c
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions source/dub/test/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -653,17 +653,6 @@ public class FSEntry
}
}

/// Writes a package file for package `name` of version `vers` at `loc`.
public void writePackageFile (in string name, in string vers, in string recipe,
in PackageFormat fmt = PackageFormat.json,
in PlacementLocation location = PlacementLocation.user)
{
const path = FSEntry.getPackagePath(name, vers, location);
this.mkdir(path).writeFile(
NativePath(fmt == PackageFormat.json ? "dub.json" : "dub.sdl"),
recipe);
}

/// Returns: The final destination a specific package needs to be stored in
public static NativePath getPackagePath(in string name_, string vers,
PlacementLocation location = PlacementLocation.user)
Expand Down Expand Up @@ -791,3 +780,27 @@ public class FSEntry
}
}
}

/**
* Convenience function to write a package file
*
* Allows to write a package file (and only a package file) for a certain
* package name and version.
*
* Params:
* root = The root FSEntry
* name = The package name (typed as string for convenience)
* vers = The package version
* recipe = The text of the package recipe
* fmt = The format used for `recipe` (default to JSON)
* location = Where to place the package (default to user location)
*/
public void writePackageFile (FSEntry root, in string name, in string vers,
in string recipe, in PackageFormat fmt = PackageFormat.json,
in PlacementLocation location = PlacementLocation.user)
{
const path = FSEntry.getPackagePath(name, vers, location);
root.mkdir(path).writeFile(
NativePath(fmt == PackageFormat.json ? "dub.json" : "dub.sdl"),
recipe);
}

0 comments on commit 29c829c

Please sign in to comment.