Skip to content

Commit 305cac8

Browse files
committed
Fixes binaryen*.test_source_map tests.
1 parent 59fbdf8 commit 305cac8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tests/test_core.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6825,6 +6825,7 @@ def test_source_map(self):
68256825
dirname = self.get_dir()
68266826
src_filename = os.path.join(dirname, 'src.cpp')
68276827
out_filename = os.path.join(dirname, 'a.out.js')
6828+
wasm_filename = os.path.join(dirname, 'a.out.wasm')
68286829
no_maps_filename = os.path.join(dirname, 'no-maps.out.js')
68296830

68306831
with open(src_filename, 'w') as f: f.write(src)
@@ -6842,12 +6843,13 @@ def build_and_check():
68426843
import json
68436844
Building.emcc(src_filename, Settings.serialize() + self.emcc_args +
68446845
Building.COMPILER_TEST_OPTS, out_filename, stderr=PIPE)
6846+
map_referent = out_filename if not Settings.BINARYEN else wasm_filename
68456847
# after removing the @line and @sourceMappingURL comments, the build
68466848
# result should be identical to the non-source-mapped debug version.
68476849
# this is worth checking because the parser AST swaps strings for token
68486850
# objects when generating source maps, so we want to make sure the
68496851
# optimizer can deal with both types.
6850-
map_filename = out_filename + '.map'
6852+
map_filename = map_referent + '.map'
68516853

68526854
def encode_utf8(data):
68536855
if isinstance(data, dict):
@@ -6864,10 +6866,16 @@ def encode_utf8(data):
68646866
return data
68656867

68666868
data = encode_utf8(json.load(open(map_filename, 'r')))
6867-
self.assertPathsIdentical(out_filename, data['file'])
6869+
if hasattr(data, 'file'):
6870+
# the file attribute is optional, but if it is present it needs to refer
6871+
# the output file.
6872+
self.assertPathsIdentical(map_referent, data['file'])
68686873
assert len(data['sources']) == 1, data['sources']
68696874
self.assertPathsIdentical(src_filename, data['sources'][0])
6870-
self.assertTextDataIdentical(src, data['sourcesContent'][0])
6875+
if hasattr(data, 'sourcesContent'):
6876+
# the sourcesContent attribute is optional, but if it is present it
6877+
# needs to containt valid source text.
6878+
self.assertTextDataIdentical(src, data['sourcesContent'][0])
68716879
mappings = encode_utf8(json.loads(jsrun.run_js(
68726880
path_from_root('tools', 'source-maps', 'sourcemap2json.js'),
68736881
tools.shared.NODE_JS, [map_filename])))

0 commit comments

Comments
 (0)