Reputation: 21
Basically I want to test files/libraries/code in general that wont run on Linux by detecting windows specific includes, program calls, dynamically linked libraries at runtime, anything that isn't Linux compatible.
This is to make sure that the resulting program always works under Linux.
I also have to automate this
Thanks!
Edit: I'm talking about source code, not compiled binaries but if some code uses a pre-compiled library i would need to check that when in uses it, it works on Linux
Edit2: I dont know much about C/C++ test suites but compiling and evaluating every line, including all the conditional branches should be posible, this and checking that the linked binary libs are compatible from a list of known libs could work rigth?
Upvotes: 1
Views: 97
Reputation: 1315
I don't think that there's an exact way of doing that. Still, you can try the following:
#!/bin/bash
find . -type f -name "*.cpp" | xargs cat | grep "windows.h"
find . -type f -name "*.h" | xargs cat | grep "windows.h"
find . -type f -name "*.hpp" | xargs cat | grep "windows.h"
find . -type f -name "*.cc" | xargs cat | grep "windows.h"
find . -type f -name "*.cxx" | xargs cat | grep "windows.h"
find . -type f -name "*.cpp" | xargs cat | grep "winsock.h"
...
After that, you set your current directory to the root of the project, and run the script. If the output is empty, you're fine.
Problem here is building up a list of headers, but that can be googled pretty easily.
This solution won't get you to 100%, but, after a number of iterations, it will be very close to 99,9%.
To further automate this, you could check the output for being empty, and return 0 or 1 based on the result.
Checking all the macros for #ifdef _WIN32 and stuff like that... Well, you need to build your own sort of compiler for that, I don't know if this stuff exists.
Upvotes: 1