Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dub test fails with "Error: unable to read module has" #2970

Open
LunaTheFoxgirl opened this issue Oct 7, 2024 · 1 comment
Open

dub test fails with "Error: unable to read module has" #2970

LunaTheFoxgirl opened this issue Oct 7, 2024 · 1 comment

Comments

@LunaTheFoxgirl
Copy link

System information

  • dub version: 1.38.1
  • OS Platform and distribution: Ubuntu 22.04.2 LTS
  • compiler version dmd-2.109.1

Bug Description

When attempting to run the unittests for numem, which uses silly. I get an error about has not existing.
There is no such module in any of my code.

How to reproduce?

Clone https://github.com/Inochi2D/numem, and run dub test

Expected Behavior

Unit tests run.

Logs

    Fetching silly 1.1.1 (getting selected version)
             Generating test runner configuration 'numem-test-unittest' for 'unittest' (library).
    Starting Performing "unittest" build using /opt/hostedtoolcache/dc/ldc2-1.39.0/x64/ldc2-1.39.0-linux-x86_64/bin/ldc2 for x86_64.
    Building numem ~main: building configuration [numem-test-unittest]
../../../.dub/cache/numem/~main/code/numem-test-unittest-unittest-d0ov_3u780tPX-97nrtTZQ/dub_test_root.d(28,15): Error: unable to read module `has`
../../../.dub/cache/numem/~main/code/numem-test-unittest-unittest-d0ov_3u780tPX-97nrtTZQ/dub_test_root.d(28,15):        Expected 'has.d' or 'has/package.d' in one of the following import paths:
import path[0] = source/
import path[1] = ../../../.dub/cache/numem/~main/code/numem-test-unittest-unittest-d0ov_3u780tPX-97nrtTZQ
import path[2] = ../../../.dub/packages/silly/1.1.1/silly
import path[3] = /opt/hostedtoolcache/dc/ldc2-1.39.0/x64/ldc2-1.39.0-linux-x86_64/bin/../import
Error /opt/hostedtoolcache/dc/ldc2-1.39.0/x64/ldc2-1.39.0-linux-x86_64/bin/ldc2 failed with exit code 1.
@Geod24
Copy link
Member

Geod24 commented Oct 7, 2024

Most likely a bug in

string determineModuleName(BuildSettings settings, NativePath file, NativePath base_path)
{
import std.algorithm : map;
import std.array : array;
import std.range : walkLength, chain;
assert(base_path.absolute);
if (!file.absolute) file = base_path ~ file;
size_t path_skip = 0;
foreach (ipath; chain(settings.importPaths, settings.cImportPaths).map!(p => NativePath(p))) {
if (!ipath.absolute) ipath = base_path ~ ipath;
assert(!ipath.empty);
if (file.startsWith(ipath) && ipath.bySegment.walkLength > path_skip)
path_skip = ipath.bySegment.walkLength;
}
auto mpath = file.bySegment.array[path_skip .. $];
auto ret = appender!string;
//search for module keyword in file
string moduleName = getModuleNameFromFile(file.to!string);
if(moduleName.length) {
assert(moduleName.length > 0, "Wasn't this module name already checked? what");
return moduleName;
}
//create module name from path
if (path_skip == 0)
{
import std.path;
ret ~= mpath[$-1].name.baseName(".d");
}
else
{
foreach (i; 0 .. mpath.length) {
import std.path;
auto p = mpath[i].name;
if (p == "package.d") break ;
if (ret.data.length > 0) ret ~= ".";
if (i+1 < mpath.length) ret ~= p;
else ret ~= p.baseName(".d");
}
}
assert(ret.data.length > 0, "A module name was expected to be computed, and none was.");
return ret.data;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants