approvals / ApprovalTests.cpp

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

Add Visual Studio (vsDiffMerge) as a WindowsDiffReporter #81

Closed DimRochette closed 4 years ago

DimRochette commented 4 years ago

Visual studio provide vsDiffMerge.exe which is a probably a nightmare to find in path, but could launch visual studio as a merge tool.

The command line documentation is explained in this post

vsDiffMerge.exe “source file” “target file” “base file” “result file” /t /m
Where:
    /t (open in a provisional tab, don’t use if you want to open in a normal tab)
    /m (merge operation)
claremacrae commented 4 years ago

Thank you for reporting this. This is another reporter type that will depend on #82 being fixed.

claremacrae commented 4 years ago

I think the best way to implement this will be to allow locations of Windows exes to be added to the PATH...

Currently, only Unix PATHs are supported, via the use of which in https://github.com/approvals/ApprovalTests.cpp/blob/f541e8c652c6792763dc307ee89ced94c03ccfa3/ApprovalTests/reporters/CommandReporter.h#L61-L67

The same could be done by adding a where clause for windows...

Then, so long as the user is running a process after vcvarsall.bat or similar has been run, vsDiffMerge.exe will be in the PATH, and we won't have to put in loads of search paths for loads of different Visual Studio versions.

claremacrae commented 4 years ago

A thing to note: we should only open a Visual Studio diff tool if the tests are being run from within Visual Studio itself, due to the slow start-up time of Visual Studio.

One idea would be to create the reporter, but not add it to the list of auto-detected reporters.

claremacrae commented 4 years ago

This is the corresponding code in ApprovalTests.Net:

https://github.com/approvals/ApprovalTests.Net/blob/master/src/ApprovalTests/Reporters/Windows/VisualStudioReporter.cs

It shows how that library detects whether the test is running from Visual Studio, and if so, how to find the location of the VS installation.

claremacrae commented 4 years ago

Sorry, we decided that this was too much work to implement robustly, but here is a workaround:

    // Use your appropriate path:
    auto path = "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer/vsDiffMerge.exe";
    auto reporter = CustomReporter::create(path);
    Approvals::verify("this will open in Visual Studio", *reporter);