title: generate mock class with python google mock
body: <p>I am trying to generate a mock class automatically using the gmock_gen.py script with python 3.7.2.</p>
  
  <p>here is <code>my IController.h</code> file</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Gui;   
  
  class IController
  {
  public:
      virtual void display(Gui *gui) = 0;
      virtual void count(int val) = 0;
  
  };
  </code></pre>
  
  <p>I made a python script called <code>controller.py</code></p>
  
  <pre><code>import os
  
  filename = "IController.h"
  file = open(filename,"r")
  
  flag = False
  header = []
  classheader = ""
  classbody = None
  classitems = []
  
  
  for line in file:
      if(filename[:-2] in line):
          flag = True
  
      if flag == False:
          header.append(line)
  
  
      if filename[:-2] in line:
          flag = True
          classname = filename[1:-2]
          line = line.replace("class ", "public ")
  
          classbody = "class " + classname + " : " + line
          #print("class " + header + " : " + line)
  
      if "virtual" in line:
          line = line.replace("virtual","")
          line = line.replace(" = 0","")
          classitems.append(line)
  
  classbody += "\n"
  classbody += "{\n"
  classbody += "  public:\n"
  
  for x in classitems:
       classbody += x 
       classbody + "\n"
  
  classbody += "};"
  
  for x in header:
      classheader += x
  
  classheader += "#include " + "\""  + filename + "\"" + "\n\n"
  classheader += classbody
  
  f = open(filename[1:], "w")
  f.write(classheader)
  
  cppfilename = filename[1:-2] + ".cpp"
  f = open(cppfilename,"w")
  
  mockfilename = "Mock" + filename[1:]
  
      print(filename)
  print(mockfilename[:-2])
  
  #os.system("python gmock_gen.py " + filename + " " + mockfilename[:-2])
  os.system("python gmock_gen.py " + filename + " " + mockfilename[:-2])
  </code></pre>
  
  <p>I am getting this error when i run the <code>controller.py</code> on the command line.</p>
  
  <pre><code>    C:\Users\rafael\Desktop\CPP&gt;controller.py
  IController.h
  MockController
  Got exception in IController.h @ Token('class', 50, 55) []
  Traceback (most recent call last):
    File "C:\Users\rafael\Desktop\CPP\cpp\ast.py", line 706, in Generate
      token = self._GetNextToken()
    File "C:\Users\rafael\Desktop\CPP\cpp\ast.py", line 908, in _GetNextToken
      return next(self.tokens)
  StopIteration
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File "gmock_gen.py", line 31, in &lt;module&gt;
      gmock_class.main()
    File "C:\Users\rafael\Desktop\CPP\cpp\gmock_class.py", line 222, in main
      lines = _GenerateMocks(filename, source, entire_ast, desired_class_names)
    File "C:\Users\rafael\Desktop\CPP\cpp\gmock_class.py", line 129, in _GenerateMocks
      for node in ast_list:
    File "C:\Users\rafael\Desktop\CPP\cpp\ast.py", line 720, in Generate
      result = self._GenerateOne(token)
    File "C:\Users\rafael\Desktop\CPP\cpp\ast.py", line 743, in _GenerateOne
      return method()
    File "C:\Users\rafael\Desktop\CPP\cpp\ast.py", line 1455, in handle_class
      return self._GetClass(Class, VISIBILITY_PRIVATE, None)
    File "C:\Users\rafael\Desktop\CPP\cpp\ast.py", line 1537, in _GetClass
      body = list(ast.Generate())
  RuntimeError: generator raised StopIteration
  </code></pre>
  
  <p>What am i doing wrong?</p>