File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,14 @@ namespace xcpp
2828
2929        void  apply (const  std::string& code, nl::json& kernel_res) override 
3030        {
31+ #if  defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
32+             //  WASM environment: Disable shell commands
33+             kernel_res[" status" " error" 
34+             kernel_res[" ename" " UnsupportedEnvironment" 
35+             kernel_res[" evalue" " Shell commands are not supported in the WASM environment." 
36+             kernel_res[" traceback" nl::json::array ();
37+ #else 
38+             //  Native environment: Execute shell commands
3139            std::regex re (spattern + R"( (.*))" 
3240            std::smatch to_execute;
3341            std::regex_search (code, to_execute, re);
@@ -65,6 +73,7 @@ namespace xcpp
6573                kernel_res[" evalue" " evalue" 
6674                kernel_res[" traceback" nl::json::array ();
6775            }
76+ #endif 
6877        }
6978
7079        [[nodiscard]] std::unique_ptr<xpreamble> clone () const  override 
Original file line number Diff line number Diff line change @@ -657,12 +657,20 @@ TEST_SUITE("xsystem_clone")
657657TEST_SUITE (" xsystem_apply" 
658658{
659659#if  defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
660-     TEST_CASE (" apply_xsystem" 
661-             * doctest::should_fail (true )
662-             * doctest::description (" TODO: Currently fails for the Emscripten build" 
660+     TEST_CASE (" apply_xsystem" 
661+     {
662+         xcpp::xsystem system;
663+         std::string code = " !echo Hello, World!" 
664+         nl::json kernel_res;
665+ 
666+         system.apply (code, kernel_res);
667+ 
668+         REQUIRE (kernel_res[" status" " error" 
669+         REQUIRE (kernel_res[" ename" " UnsupportedEnvironment" 
670+         REQUIRE (kernel_res[" evalue" " Shell commands are not supported in the WASM environment." 
671+     }
663672#else 
664673    TEST_CASE (" apply_xsystem" 
665- #endif 
666674    {
667675        xcpp::xsystem system;
668676        std::string code = " !echo Hello, World!" 
@@ -672,6 +680,7 @@ TEST_SUITE("xsystem_apply")
672680
673681        REQUIRE (kernel_res[" status" " ok" 
674682    }
683+ #endif 
675684}
676685
677686TEST_SUITE (" xmagics_contains" 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments