require 'gcc_to_clang_analyzer/prepare_compiler_commandline' describe PrepareCompilerCommandline do it 'should remove the program name and replace it with clang --analyze when a -c is given' do cl, out = PrepareCompilerCommandline.transform(['g++', '-c', 1, 2]) cl[0...2].should eq(['clang', '--analyze']) end it 'should remove the program name and replace it with true when no -c is given' do cl, out = PrepareCompilerCommandline.transform(['g++', 1, 2]) cl.first.should eq('true') end it 'should keep -D flags' do cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-Dflag', '-Dflag2=2']) cl.should eq(['clang', '--analyze', '-Dflag', '-Dflag2=2']) end it 'should keep -I flags' do cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-I/usr/include', '-I/usr/include2']) cl.should eq(['clang', '--analyze', '-I/usr/include', '-I/usr/include2']) end it 'should remove -c' do cl, out = PrepareCompilerCommandline.transform(['g++', '-c']) cl.should eq(['clang', '--analyze']) end it 'should remove -MF with a parameter' do cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-MF', 'anotherarg']) cl.should eq(['clang', '--analyze']) end it 'should remove -MMD' do cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-MMD']) cl.should eq(['clang', '--analyze']) end it 'should remove -Wwith values' do cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-Wall']) cl.should eq(['clang', '--analyze']) end it 'should output to the normal output appended with .plist' do cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-o', 'test.o']) cl.should eq(['clang', '--analyze', '-o', 'test.o.plist']) out.should eq('test.o.plist') end it 'should let unknown flags pass' do cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-unknown']) cl.should eq(['clang', '--analyze', '-unknown']) end end