首页 文章

来自cmd的D程序中的单元测试错误

提问于
浏览
0

我有一个名为 test.d 的文本文件,其中包含以下代码段:

import std.array;

bool binarySearch(T)(T[] input, T value)
{
    while(!input.empty)
    {
        auto i = input.length /2;
        auto mod = input[i];
        if(mid > value) input = input[0 .. i];
        else if (mid < value) input = input[i+1 .. $];
        else return true;
    }
    return false;
}

unittest 
{
    assert(binarySearch([1, 3, 6, 7, 9, 15], 6) == true);
    assert(binarySearch([1, 3, 6, 7, 9, 15], 5) == false);
}

在致电 rdmd 时,如下所示:

C:\D\dmd2\windows\bin>rdmd.exe F:\Test\test.d

将打开一个窗口说:

An app on your PC needs the following feature:

NTVDM

并且,会抛出一个奇怪的错误:

std.process.ProcessException@std\process.d(568): Failed to spawn new process (%1 is a 16-bit application. You do not have permissions to execute 16-bit applications. Check your permissions with your system administrator.)
----------------
0x0043D878
0x0042E14C
0x004042AC
0x00404333
0x00437457
0x00437358
0x0042A064
0x74AADEA4 in BaseThreadInitThunk
0x7700055E in RtlInitializeCriticalSectionAndSpinCount
0x7700052D in RtlInitializeCriticalSectionAndSpinCount

所以,我刚刚安装了 NVDTM ,但是当我运行该代码片段时,弹出窗口只是断言 NVDTM 已停止工作...

怎么了?...

1 回答

  • 4

    您的文件没有主要功能,因此操作系统不知道它应该对可执行文件做什么 . Rdmd可以为您添加存根 . 此外,默认情况下它不会运行单元测试 .

    使用此命令运行它:

    rdmd -unittest --force --main test.d
    

    -unittest 启用单元测试

    --force 强制重新编译,因此它不使用旧的可执行文件

    --main 添加了一个存根主体

相关问题