Skip to content

Commit

Permalink
fix(learn): 解决编译问题
Browse files Browse the repository at this point in the history
Signed-off-by: YdrMaster <[email protected]>
  • Loading branch information
YdrMaster committed Jul 13, 2024
1 parent 192b569 commit a4c5dd1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions learn/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ static int process_run(const char *cmd, const char *proj, const char *log) {
return std::system(command.c_str());
}

static bool test_exercise(int n, std::ostream &os, const char *log) {
static bool test_exercise(int n, const char *log) {
std::ofstream file;
if (log) {
file.open(log, std::ios::out | std::ios::app);
}
std::ostream &os = log ? file : std::cout;

char str[] = "exerciseXX";
std::sprintf(str, "exercise%02d", n);

Expand All @@ -39,7 +45,7 @@ Log &Log::operator<<(unsigned int n) {
namespace fs = std::filesystem;
bool pass;
if (std::holds_alternative<Console>(this->dst)) {
pass = test_exercise(n, std::cout, nullptr);
pass = test_exercise(n, nullptr);
} else if (std::holds_alternative<Null>(this->dst)) {
#if defined(_WIN32)
constexpr auto null = "nul";
Expand All @@ -48,11 +54,11 @@ Log &Log::operator<<(unsigned int n) {
#else
#error "Unsupported platform"
#endif
pass = test_exercise(n, std::ofstream(null, std::ios::out | std::ios::app), null);
pass = test_exercise(n, null);
} else {
const auto path = fs::absolute(fs::path(XMAKE) / "log" / std::get<fs::path>(this->dst));
const auto path_string = path.string();
pass = test_exercise(n, std::ofstream(path, std::ios::out | std::ios::app), path_string.c_str());
pass = test_exercise(n, path_string.c_str());
}
{
std::lock_guard lock(this->mutex);
Expand Down

0 comments on commit a4c5dd1

Please sign in to comment.