Fix possible crash if git config is broken
[TortoiseGit.git] / test / UnitTests / libgitTest.cpp
blobe0a7fff5a2713df0c47cc73d166d737267a31a64
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "Git.h"
22 #include "StringUtils.h"
24 TEST(libgit, BrokenConfig)
26 CAutoTempDir tempdir;
27 g_Git.m_CurrentDir = tempdir.GetTempDir();
28 g_Git.m_IsGitDllInited = false;
29 g_Git.m_CurrentDir = g_Git.m_CurrentDir;
30 g_Git.m_IsUseGitDLL = true;
31 g_Git.m_IsUseLibGit2 = false;
32 g_Git.m_IsUseLibGit2_mask = 0;
33 // libgit relies on CWD being set to working tree
34 SetCurrentDirectory(g_Git.m_CurrentDir);
36 CString output;
37 EXPECT_EQ(0, g_Git.Run(_T("git.exe init"), &output, CP_UTF8));
38 EXPECT_FALSE(output.IsEmpty());
39 CString testFile = tempdir.GetTempDir() + _T("\\.git\\config");
40 EXPECT_TRUE(CStringUtils::WriteStringToTextFile((LPCTSTR)testFile, L"[push]\ndefault=something-that-is-invalid\n"));
42 EXPECT_THROW(g_Git.CheckAndInitDll(), const char*);