14
14
#include " xeus-cpp/xoptions.hpp"
15
15
16
16
#include " ../src/xparser.hpp"
17
+ #include " ../src/xsystem.hpp"
18
+ #include " ../src/xmagics/os.hpp"
19
+
20
+ #include < fstream>
17
21
18
22
TEST_SUITE (" execute_request" )
19
23
{
@@ -398,7 +402,7 @@ TEST_SUITE("xbuffer")
398
402
}
399
403
}
400
404
401
- TEST_SUITE (" xotions " )
405
+ TEST_SUITE (" xoptions " )
402
406
{
403
407
TEST_CASE (" good_status" ) {
404
408
xcpp::argparser parser (" test" );
@@ -426,3 +430,105 @@ TEST_SUITE("xotions")
426
430
REQUIRE (exceptionThrown);
427
431
}
428
432
}
433
+
434
+ TEST_SUITE (" os" )
435
+ {
436
+ TEST_CASE (" write_new_file" ) {
437
+ xcpp::writefile wf;
438
+ std::string line = " filename testfile.txt" ;
439
+ std::string cell = " Hello, World!" ;
440
+
441
+ wf (line, cell);
442
+
443
+ std::ifstream infile (" testfile.txt" );
444
+ REQUIRE (infile.good () == true );
445
+ infile.close ();
446
+
447
+ std::remove (" testfile.txt" );
448
+ }
449
+
450
+ TEST_CASE (" overwrite_file" ) {
451
+ xcpp::writefile wf;
452
+ std::string line = " filename testfile.txt" ;
453
+ std::string cell = " Hello, World!" ;
454
+
455
+ wf (line, cell);
456
+
457
+ std::string overwrite_cell = " Overwrite test" ;
458
+
459
+ wf (line, overwrite_cell);
460
+
461
+ std::ifstream infile (" testfile.txt" );
462
+ std::string content;
463
+ std::getline (infile, content);
464
+
465
+ REQUIRE (content == overwrite_cell);
466
+ infile.close ();
467
+
468
+ std::remove (" testfile.txt" );
469
+ }
470
+
471
+ TEST_CASE (" append_file" ) {
472
+ xcpp::writefile wf;
473
+ std::string line = " filename testfile.txt" ;
474
+ std::string cell = " Hello, World!" ;
475
+
476
+ wf (line, cell);
477
+
478
+ std::string append_line = " filename testfile.txt --append" ;
479
+ std::string append_cell = " Hello, again!" ;
480
+
481
+ wf (append_line, append_cell);
482
+
483
+ std::ifstream infile (" testfile.txt" );
484
+ std::vector<std::string> lines;
485
+ std::string content;
486
+ while (std::getline (infile, content)) {
487
+ lines.push_back (content);
488
+ }
489
+
490
+ REQUIRE (lines[0 ] == cell);
491
+ REQUIRE (lines[1 ] == append_cell);
492
+ infile.close ();
493
+
494
+ std::remove (" testfile.txt" );
495
+ }
496
+
497
+ }
498
+
499
+ TEST_SUITE (" xsystem_clone" )
500
+ {
501
+ TEST_CASE (" clone_xsystem_not_null" )
502
+ {
503
+ xcpp::xsystem system;
504
+
505
+ xcpp::xpreamble* clone = system.clone ();
506
+
507
+ REQUIRE (clone != nullptr );
508
+ }
509
+
510
+ TEST_CASE (" clone_xsystem_same_type" )
511
+ {
512
+ xcpp::xsystem system;
513
+
514
+ xcpp::xpreamble* clone = system.clone ();
515
+
516
+ REQUIRE (dynamic_cast <xcpp::xsystem*>(clone) != nullptr );
517
+
518
+ delete clone;
519
+ }
520
+ }
521
+
522
+ TEST_SUITE (" xsystem_apply" )
523
+ {
524
+ TEST_CASE (" apply_xsystem" )
525
+ {
526
+ xcpp::xsystem system;
527
+ std::string code = " !echo Hello, World!" ;
528
+ nl::json kernel_res;
529
+
530
+ system.apply (code, kernel_res);
531
+
532
+ REQUIRE (kernel_res[" status" ] == " ok" );
533
+ }
534
+ }
0 commit comments