approvals / ApprovalTests.cpp

Native ApprovalTests for C++ on Linux, Mac and Windows
https://approvaltestscpp.readthedocs.io/en/latest/
Apache License 2.0
312 stars 51 forks source link

Implement a helpful missing-symbol error for misconfigured main #145

Open claremacrae opened 4 years ago

claremacrae commented 4 years ago

We want to make a linker error something like this:

"___APPROVAL_MAIN_NOTCONFIGURED____::See_TroubleshootingMisconfiguredMain_Documentation::check()", referenced from:

But the initial underscore if global, and the double underscores are reserved.

claremacrae commented 4 years ago

We have an initial implementation sketched like this:


namespace v_v_v_v_v_v_v_v_v_APPROVAL_MAIN_NOT_CONFIGURED_v_v_v_v_v_v_v_v
{
  class Main_CPP_Not_Defined_Correctly
  {
} ;

  class See_TroubleshootingMisconfiguredMain_Documentation
  {
public:
    static Main_CPP_Not_Defined_Correctly check();
};
}

// then in Options, private:

    private:
      v_v_v_v_v_v_v_v_v_APPROVAL_MAIN_NOT_CONFIGURED_v_v_v_v_v_v_v_v::Main_CPP_Not_Defined_Correctly linkerCheck_ = v_v_v_v_v_v_v_v_v_APPROVAL_MAIN_NOT_CONFIGURED_v_v_v_v_v_v_v_v::See_TroubleshootingMisconfiguredMain_Documentation::check();

// and in a .cpp
namespace _v_v_v_v_v_v_v_v_v_APPROVAL_MAIN_NOT_CONFIGURED_v_v_v_v_v_v_v_v

{
    Main_CPP_Not_Defined_Correctly See_TroubleshootingMisconfiguredMain_Documentation::check()
{
return Main_CPP_Not_Defined_Correctly();
}

}
claremacrae commented 4 years ago

Reply from #include <C++> Discord:

X_X_X_X_X_X_X_APPROVAL_MAIN_NOT_CONFIGURED_X_X_X_X_X_X_X

i mean, tbh, the probability that _______________APPROVAL_MAIN_NOT_CONFIGURED_____________ is gonna get you in trouble in reality is extremely low^^

the main reason why reserved names exist is so that compilers and, most importantly, stdlib implementations have something that they can legally assume to not potentially be defined as macros by the user at the point where they include stdlib headers so they have something to work with…

claremacrae commented 4 years ago

I'd be really happy with X_X_X_X_X_X_X_APPROVAL_MAIN_NOT_CONFIGURED_X_X_X_X_X_X_X