mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	zjsunit: Handle exceptions in with_field, with_overrides.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Anders Kaseorg
					
				
			
			
				
	
			
			
			
						parent
						
							7e3735b9ba
						
					
				
				
					commit
					58b18fd499
				
			@@ -68,10 +68,12 @@ exports.restore = function () {
 | 
			
		||||
 | 
			
		||||
exports.with_field = function (obj, field, val, f) {
 | 
			
		||||
    const old_val = obj[field];
 | 
			
		||||
    obj[field] = val;
 | 
			
		||||
    const result = f();
 | 
			
		||||
    obj[field] = old_val;
 | 
			
		||||
    return result;
 | 
			
		||||
    try {
 | 
			
		||||
        obj[field] = val;
 | 
			
		||||
        return f();
 | 
			
		||||
    } finally {
 | 
			
		||||
        obj[field] = old_val;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.with_overrides = function (test_function) {
 | 
			
		||||
@@ -165,11 +167,13 @@ exports.with_overrides = function (test_function) {
 | 
			
		||||
        });
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    test_function(override);
 | 
			
		||||
 | 
			
		||||
    restore_callbacks.reverse();
 | 
			
		||||
    for (const restore_callback of restore_callbacks) {
 | 
			
		||||
        restore_callback();
 | 
			
		||||
    try {
 | 
			
		||||
        test_function(override);
 | 
			
		||||
    } finally {
 | 
			
		||||
        restore_callbacks.reverse();
 | 
			
		||||
        for (const restore_callback of restore_callbacks) {
 | 
			
		||||
            restore_callback();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (const module_unused_funcs of unused_funcs.values()) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user