mirror of
https://github.com/jmcnamara/libxlsxwriter.git
synced 2026-05-15 14:15:54 -06:00
[GH-ISSUE #413] Unit tests won't run when using Microsoft C compiler #327
Labels
No labels
awaiting user feedback
bug
cmake
cmake
docs
feature request
in progress
long term
medium term
medium term
pull-request
question
question
ready to close
short term
under investigation
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/libxlsxwriter#327
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @HolgiHo on GitHub (Sep 18, 2023).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/413
When using the Microsoft C compiler (Visual Studio / VS Build Tools), the unit test registration in
ctest.hdoes not work (and has apparently never worked before). The unit test executablexlsxwriter_unit.exesimply executes zero test cases.Reason: The test case registration macro
CTEST(...)works by adding instances ofstruct ctestto a special linker segments (on *nix platforms). When using MSC, the structs are added to the normal data segment and thus cannot be found by the test case driver inctest_main.Solution: Use linker segments also in MSC. This requires a special syntax, as linker segments specifications are not portable between platforms.
PR will follow shortly.
@jmcnamara commented on GitHub (Sep 18, 2023):
Thanks for the report.
There is an upstream PR to fix this in
ctestbut it doesn't seem to have been merged: https://github.com/bvdberg/ctest/pull/35I'd prefer not to include local fixes for this issue so I think I will pass on this.
The PR also includes some other fixes: "fix build error in VS: use const char* in struct lxw_header_footer_options". Any idea why this doesn't show up in the "CMake on Windows" CI test?
@HolgiHo commented on GitHub (Sep 19, 2023):
VS build error
The error occurs when compiling the following code in a C++ file, even when xlsxwriter.h uses the extern "C" { ... } declaration.
gives
error C2440: '=': cannot convert from 'const char [15]' to 'char *'This works in C, so cmake builds don't complain. However, it should be possible to use the struct members also from a C++ implementation file without writing strange things like
using
const char*forimage_strings[]in_worksheet_set_header_footer_imageis not really required as this is always C code, but it's cleaner.ctest
I saw ctest.h was already modified (see its git log) to "work" on Windows. So I wondered that it compiles, but no tests are found.
IMHO, in the short term, working unit tests under Windows are important for libxlsxwriter development. The ctest repository seems to be a bit abandoned, so I doubt if the PR you mentioned will ever be merged into ctest, also because there are lots of guesses and no clear statements how the MS compiler works. (The source of truth is here I think: https://devblogs.microsoft.com/oldnewthing/20181107-00/?p=100155 and the two follow-up articles.)
I mean, if ctest once supports MSVC, you can simply copy the latest version from there and you're done.
@jmcnamara commented on GitHub (Sep 23, 2023):
Thanks for flagging this. I'll look into that separately. I have a simple test to ensure CPP compatible
const char*in the APIs but it doesn't flag them in structs or assignments so I'm going to work on that for a bit to see if I can have better automated tests.After that I'll look at the unit test part of the PR. I just need to figure out if I should upgrade to the latest
ctest.hbefore adding this fix.@jmcnamara commented on GitHub (Sep 25, 2023):
I've added a fix to change all the public "char*" members to "const char*". You can try it when you get a chance.
I'll look into the
ctest.hissue next. It is likely that I will upgrade to the latest version. The previous version I used with from 2014 with local fixes over time.@jmcnamara commented on GitHub (Sep 25, 2023):
I updated
ctest.hto the latest version on thectestbranch. It works well for Unix-like systems but fails completely on Windows.I think that rather than fix it I'd prefer to disable the unit test compilation on Windows. As you pointed out the tests didn't work previously so it probably isn't a big loss. The functional tests are more comprehensive anyway.
@jmcnamara commented on GitHub (Sep 26, 2023):
In the end I went with the option of turning off the unit tests for MSVC until
ctest.hsupports it. I am going to close this and the PR. Thanks for the input.