diff --git a/test.py b/test.py index d27fe79..e634c0f 100644 --- a/test.py +++ b/test.py @@ -258,16 +258,15 @@ def test_link_as_needed(self): def test_unused_data_and_function(self): if os_name == 'mac': - self.check_generate('unused_data_and_function', args='-DCMAKE_BUILD_TYPE=Release REMOVE_UNUSED_DATA_AND_FUNCTION=0') + self.check_generate('unused_data_and_function', args='-DCMAKE_BUILD_TYPE=Release -DREMOVE_UNUSED_DATA_AND_FUNCTION=0') self.check_build('unused_data_and_function') cmd = 'objdump -t build/unused_data_and_function/test' ret, out = check_output(cmd) self.assertEqual(0, ret, out) out = out.replace('\r\n', '\n') lines = out.strip().split('\n') - self.assertEqual(len(lines), 11, lines) - self.assertTrue(lines[5].endswith('g F __TEXT,__text _unused_function')) - self.assertTrue(lines[6].endswith('g O __DATA,__data _unused_global_variable')) + self.assertTrue(any(line.strip().endswith("g F __TEXT,__text _unused_function") for line in lines)) + self.assertTrue(any(line.strip().endswith("g O __DATA,__data _unused_global_variable") for line in lines)) shutil.rmtree('build/unused_data_and_function') self.check_generate('unused_data_and_function', args='-DCMAKE_BUILD_TYPE=Release -DREMOVE_UNUSED_DATA_AND_FUNCTION=1') @@ -277,9 +276,30 @@ def test_unused_data_and_function(self): self.assertEqual(0, ret, out) out = out.replace('\r\n', '\n') lines = out.strip().split('\n') - self.assertEqual(len(lines), 9, lines) - for line in lines: - self.assertTrue(not line.endswith('unused_function')) + self.assertTrue(all(not line.strip().endswith("g F __TEXT,__text _unused_function") for line in lines)) + self.assertTrue(all(not line.strip().endswith("g O __DATA,__data _unused_global_variable") for line in lines)) + shutil.rmtree('build/unused_data_and_function') + elif os_name == 'linux': + self.check_generate('unused_data_and_function', args='-DCMAKE_BUILD_TYPE=Release -DREMOVE_UNUSED_DATA_AND_FUNCTION=0') + self.check_build('unused_data_and_function') + cmd = 'objdump -t build/unused_data_and_function/test' + ret, out = check_output(cmd) + self.assertEqual(0, ret, out) + out = out.replace('\r\n', '\n') + lines = out.strip().split('\n') + self.assertTrue(any(line.strip().endswith(" unused_function") for line in lines)) + self.assertTrue(any(line.strip().endswith(" unused_global_variable") for line in lines)) + shutil.rmtree('build/unused_data_and_function') + + self.check_generate('unused_data_and_function', args='-DCMAKE_BUILD_TYPE=Release -DREMOVE_UNUSED_DATA_AND_FUNCTION=1') + self.check_build('unused_data_and_function') + cmd = 'objdump -t build/unused_data_and_function/test' + ret, out = check_output(cmd) + self.assertEqual(0, ret, out) + out = out.replace('\r\n', '\n') + lines = out.strip().split('\n') + self.assertTrue(all(not line.strip().endswith(" unused_function") for line in lines)) + self.assertTrue(all(not line.strip().endswith(" unused_global_variable") for line in lines)) shutil.rmtree('build/unused_data_and_function') if __name__ == "__main__":