当我尝试使用gcovr生成html报告时出错,' NoneType'对象没有属性' startswith'

时间:2015-06-27 13:43:16

标签: code-coverage gcov gcovr

我收到错误

'NoneType' object has no attribute 'startswith'

尝试使用gcovr(用于估算测试覆盖率的工具)生成html报告时

知道我应该怎么解决它?有关信息,我在Ubuntu 14.04上。请参阅下面的详细错误消息:

parallels:try_gcovr$ gcovr -r .  --html
Traceback (most recent call last):
  File "/usr/local/bin/gcovr", line 1970, in <module>
    print_html_report(covdata, options.html_details)
  File "/usr/local/bin/gcovr", line 1373, in print_html_report
    ttmp = os.path.abspath(options.output).split('.')
  File "/usr/lib/python2.7/posixpath.py", line 367, in abspath
    if not isabs(path):
  File "/usr/lib/python2.7/posixpath.py", line 61, in isabs
    return s.startswith('/')
AttributeError: 'NoneType' object has no attribute 'startswith'

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,并使用以下命令解决了这个问题。

  

gcovr --html --html-details -o output-file-name.html -v -r。

这是我的设置和命令:

$ ls; ls testDir

main.cpp   Makefile   test.cpp   testDir

test.cpp  test.h


$ make test

g++  -fprofile-arcs -ftest-coverage -fPIC -O0 -c main.cpp -o main.o

g++  -o  test testDir/test.o main.o -lgcov -coverage


$ ./test

hello world

$ ls;ls testDir

main.cpp   main.gcda  main.o test
main.gcno  Makefile test.cpp  testDir 

test.cpp  test.gcda  test.gcno  test.h  test.o

$ gcovr -r . --html

Traceback (most recent call last):
  File "/usr/bin/gcovr", line 1970, in <module>
    print_html_report(covdata, options.html_details)
  File "/usr/bin/gcovr", line 1373, in print_html_report
    ttmp = os.path.abspath(options.output).split('.')
  File "/usr/lib64/python2.7/posixpath.py", line 343, in abspath
    if not isabs(path):
  File "/usr/lib64/python2.7/posixpath.py", line 53, in isabs
    return s.startswith('/')
AttributeError: 'NoneType' object has no attribute 'startswith'


$ gcovr --html --html-details -o output.html -v -r .

//a bunch of gcov output while generating files...

$ ls; ls testDir

main.cpp   Makefile   output.html output.testDir_test.cpp.html  test.cpp   testDir 
output.main.cpp.html  test 

test.cpp  test.gcda  test.gcno  test.h  test.o

$ cat Makefile


OBJS=testDir/test.o main.o

EXEC_TARGET=test
CXXFLAGS+=-fprofile-arcs -ftest-coverage -fPIC -O0
bla:
    @echo $(GXX)

LINKLIBSCTT+=-lgcov -coverage

#Executable target rule
$(EXEC_TARGET): $(OBJS)
    $(CXX) $(LINK_FLAGS) -o  $(EXEC_TARGET) $(OBJS) $(LINKLIBSCTT)


#implicit rule to compile object files
%.o: %.cpp
    $(CXX) $(INCLUDES) $(CXXFLAGS) -c $^ -o $@


clean:
    rm -f *.o *.rpo *.d $(EXEC_TARGET)