zezer3 / cmaked2

Automatically exported from code.google.com/p/cmaked2
0 stars 0 forks source link

Unittest feature broken for testing modules with in-project modules imports #14

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Suppose you have the following module layout:
.../main.d
.../CMakeLists.txt
.../mypackage/module1.d
.../mypackage/module2.d
where ... means path to project directory.

Module sources:

===========================================
// module1.d
module mypackage.module1;

void foo() {
   // Important work here
}

===========================================
// module2.d
module mypackage.module2;

import mypackage.module1 : foo;

bool bar() {
    foo();
    return true;
}

unittest {
    assert(bar());
}

===========================================
// main.d
import mypackage.module2 : bar;
import std.stdio;

void main() {
    writefln("%s", bar());
}

===========================================
# CMakeLists.txt
cmake_minimum_required (VERSION 2.8.1)
project (testut D)

enable_testing()

set (MAINFILE main.d)
set (MODULES mypackage/module1.d mypackage/module2.d)
set (SOURCES ${MAINFILE} ${MODULES})

include (UseDUnittest)

include_directories (.)
add_executable (testut ${SOURCES})

foreach (f IN LISTS MODULES)
    add_unittests (${f})
endforeach()

===========================================

Doing
  $ mkdir build
  $ cd build
  $ cmake ..
  $ make
produces correctrly working binary.

But the following
  $ make test
gives

Running tests...
Test project /tmp/testut/build
    Start 1: mypackage/module1.d
1/2 Test #1: mypackage/module1.d ..............   Passed    0.07 sec
    Start 2: mypackage/module2.d
2/2 Test #2: mypackage/module2.d ..............***Failed    0.06 sec

50% tests passed, 1 tests failed out of 2

Total Test time (real) =   0.17 sec

The following tests FAILED:
      2 - mypackage/module2.d (Failed)
Errors while running CTest
make: *** [test] Ошибка 8

The exact error (from Testing/Temporary/LastTest.log) is this:

2/2 Testing: mypackage/module2.d
2/2 Test: mypackage/module2.d
Command: "/usr/bin/dmd" "-I/tmp/testut/." 
"/tmp/testut/build/CMakeFiles/unittest.d" "-unittest" "-run" 
"/tmp/testut/mypackage/module2.d"
Directory: /tmp/testut/build
"mypackage/module2.d" start time: May 11 23:26 MSD
Output:
----------------------------------------------------------
unittest.o: In function `_D9mypackage7module23barFZb':
/tmp/testut/mypackage/module2.d:(.text._D9mypackage7module23barFZb+0x5): 
undefined reference to `_D9mypackage7module13fooFZv'
collect2: выполнение ld завершилось с кодом 
возврата 1
--- errorlevel 1
<end of output>
Test time =   0.06 sec
----------------------------------------------------------
Test Failed.
"mypackage/module2.d" end time: May 11 23:26 MSD
"mypackage/module2.d" time elapsed: 00:00:00
----------------------------------------------------------

This happens because dmd does not compile object files for modules which are 
imported from another module.

There was a discussion on the digitalmars mailing list on this behavior of dmd, 
and it was suggested that rdmd tool is right thing for this problem. But it 
seems that rdmd doesn't handle multiple .d files on the command line (it 
launches the first one, passing others as arguments to it; this results to link 
errors), so the only option for rdmd is to use direct imports of modules in the 
main file (unittest.d), which I think is unacceptable for automated testing 
purposes.

Original issue reported on code.google.com by dpx.infinity@gmail.com on 11 May 2011 at 7:58

GoogleCodeExporter commented 9 years ago
This is the test project described above.

Original comment by dpx.infinity@gmail.com on 11 May 2011 at 8:00

Attachments: