Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions integrationtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,57 @@ def testHitsSimple(self):
newHits = stats.numCacheHits()
self.assertEqual(newHits, oldHits + 1)

def testAlternatingHeadersHit(self):
with cd(os.path.join(ASSETS_DIR, "hits-and-misses")), tempfile.TemporaryDirectory() as tempDir:
cache = clcache.Cache(tempDir)
customEnv = dict(os.environ, CLCACHE_DIR=tempDir)
baseCmd = CLCACHE_CMD + ["/nologo", "/EHsc", "/c"]

with cache.statistics as stats:
self.assertEqual(stats.numCacheHits(), 0)
self.assertEqual(stats.numCacheMisses(), 0)
self.assertEqual(stats.numCacheEntries(), 0)

# VERSION 1
with open('stable-source-with-alternating-header.h', 'w') as f:
f.write("#define VERSION 1\n")
subprocess.check_call(baseCmd + ["stable-source-with-alternating-header.cpp"], env=customEnv)

with cache.statistics as stats:
self.assertEqual(stats.numCacheHits(), 0)
self.assertEqual(stats.numCacheMisses(), 1)
self.assertEqual(stats.numCacheEntries(), 1)

# VERSION 2
with open('stable-source-with-alternating-header.h', 'w') as f:
f.write("#define VERSION 2\n")
subprocess.check_call(baseCmd + ["stable-source-with-alternating-header.cpp"], env=customEnv)

with cache.statistics as stats:
self.assertEqual(stats.numCacheHits(), 0)
self.assertEqual(stats.numCacheMisses(), 2)
self.assertEqual(stats.numCacheEntries(), 2)

# VERSION 1 again
with open('stable-source-with-alternating-header.h', 'w') as f:
f.write("#define VERSION 1\n")
subprocess.check_call(baseCmd + ["stable-source-with-alternating-header.cpp"], env=customEnv)

with cache.statistics as stats:
self.assertEqual(stats.numCacheHits(), 1)
self.assertEqual(stats.numCacheMisses(), 2)
self.assertEqual(stats.numCacheEntries(), 2)

# VERSION 2 again
with open('stable-source-with-alternating-header.h', 'w') as f:
f.write("#define VERSION 1\n")
subprocess.check_call(baseCmd + ["stable-source-with-alternating-header.cpp"], env=customEnv)

with cache.statistics as stats:
self.assertEqual(stats.numCacheHits(), 2)
self.assertEqual(stats.numCacheMisses(), 2)
self.assertEqual(stats.numCacheEntries(), 2)


class TestPrecompiledHeaders(unittest.TestCase):
def testSampleproject(self):
Expand Down
4 changes: 4 additions & 0 deletions tests/integrationtests/hits-and-misses/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.obj

# written by the tests
stable-source-with-alternating-header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>

#include "stable-source-with-alternating-header.h"

int main()
{
std::cout << "A C++ file we compile twice and expect a hit" << std::endl;
return 0;
}