(self)
| 7907 | @requires_node |
| 7908 | @requires_dev_dependency('source-map') |
| 7909 | def test_source_map(self): |
| 7910 | if '-g' not in self.cflags: |
| 7911 | self.cflags.append('-g') |
| 7912 | |
| 7913 | src = ''' |
| 7914 | #include <stdio.h> |
| 7915 | #include <assert.h> |
| 7916 | |
| 7917 | __attribute__((noinline)) int foo() { |
| 7918 | printf("hi"); // line 6 |
| 7919 | return 1; // line 7 |
| 7920 | } |
| 7921 | |
| 7922 | int main() { |
| 7923 | printf("%d", foo()); // line 11 |
| 7924 | return 0; // line 12 |
| 7925 | } |
| 7926 | ''' |
| 7927 | create_file('src.cpp', src) |
| 7928 | |
| 7929 | out_filename = self.output_name('a.out') |
| 7930 | wasm_filename = 'a.out.wasm' |
| 7931 | no_maps_filename = 'no-maps.out.js' |
| 7932 | |
| 7933 | assert '-gsource-map' not in self.cflags |
| 7934 | self.emcc('src.cpp', ['-o', out_filename]) |
| 7935 | # the file name may find its way into the generated code, so make sure we |
| 7936 | # can do an apples-to-apples comparison by compiling with the same file name |
| 7937 | shutil.move(out_filename, no_maps_filename) |
| 7938 | no_maps_file = read_file(no_maps_filename) |
| 7939 | no_maps_file = re.sub(' *//[@#].*$', '', no_maps_file, flags=re.MULTILINE) |
| 7940 | self.cflags.append('-gsource-map') |
| 7941 | |
| 7942 | self.emcc(os.path.abspath('src.cpp'), ['-o', out_filename]) |
| 7943 | map_referent = out_filename if self.is_wasm2js() else wasm_filename |
| 7944 | # after removing the @line and @sourceMappingURL comments, the build |
| 7945 | # result should be identical to the non-source-mapped debug version. |
| 7946 | # this is worth checking because the parser AST swaps strings for token |
| 7947 | # objects when generating source maps, so we want to make sure the |
| 7948 | # optimizer can deal with both types. |
| 7949 | map_filename = map_referent + '.map' |
| 7950 | |
| 7951 | data = json.loads(utils.read_file(map_filename)) |
| 7952 | if hasattr(data, 'file'): |
| 7953 | # the file attribute is optional, but if it is present it needs to refer |
| 7954 | # the output file. |
| 7955 | self.assertPathsIdentical(map_referent, data['file']) |
| 7956 | self.assertGreater(len(data['sources']), 1) |
| 7957 | self.assertContained('src.cpp', data['sources']) |
| 7958 | src_index = data['sources'].index('src.cpp') |
| 7959 | if hasattr(data, 'sourcesContent'): |
| 7960 | # the sourcesContent attribute is optional, but if it is present it |
| 7961 | # needs to contain valid source text. |
| 7962 | self.assertTextDataIdentical(src, data['sourcesContent'][src_index]) |
| 7963 | mappings = json.loads(self.run_js( |
| 7964 | path_from_root('test/sourcemap2json.js'), |
| 7965 | args=[map_filename])) |
| 7966 | seen_lines = set() |
nothing calls this directly
no test coverage detected