1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
use crate::test_descriptor::ast::Statement;
use crate::timeline::{SensorsTimeline, Timeline};
use serde::{Deserialize, Serialize};
use serde_json::to_writer_pretty;
use std::collections::BTreeMap;
use std::fs::File;
use std::path::PathBuf;

use crate::result::CompilerResult;
use crate::test_descriptor::concrete_test::ConcreteTest;

/// Contains the hashes of the TBF and CBF files
/// Used by mission control to identify which test is running
#[derive(Serialize, Deserialize)]
pub struct TestIdentifier {
    test: [String; 2],
    config: [String; 2],
}

impl TestIdentifier {
    pub fn new(test_hash: u32, test_name: &str, config_hash: u32, config_name: &str) -> Self {
        TestIdentifier {
            test: [test_hash.to_string(), test_name.into()],
            config: [config_hash.to_string(), config_name.into()],
        }
    }
    /// Output JSON sensor bounds based on the test_body and abort sensor timelines
    pub fn emit(&self, output_path: PathBuf) -> CompilerResult<()> {
        let mut res = CompilerResult::status_only("Emit JSON test identifier for mission control");

        // Emit the test identifier to file
        let file = check!(res, File::create(output_path));
        check!(
            res,
            to_writer_pretty(file, self),
            "Serialize test identifer and write to output file"
        );
        res
    }
}

/// Contains a hashmap containing a SensorBounds struct for the test body and each abort
/// The test body timestrip will use the key "test_body" and each abort will use its abort idx as the key
struct TestSensorBounds {
    sequences: BTreeMap<String, SequenceSensorBounds>,
}

/// Contains all of the sensor bounds for every sensor in a test body or abort sequence
#[derive(Serialize, Deserialize)]
#[serde(transparent)]
struct SequenceSensorBounds {
    sensors: BTreeMap<String, SensorBounds>,
}

/// Contains the bounds for a single sensor for an entire test body or abort sequence
#[derive(Serialize, Deserialize)]
struct SensorBounds {
    times: Vec<u32>,
    bound_values: Vec<BoundValue>,
}

/// Contains a single bound for a sensor or a null bound
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
enum BoundValue {
    Value { left: f64, right: f64 },
    NoValue { left: (), right: () },
}

impl TestSensorBounds {
    pub fn new() -> Self {
        TestSensorBounds {
            sequences: BTreeMap::new(),
        }
    }

    /// Function to add a sensor bounds sequence with the provided key
    /// Errors if a sequence already exists with the same key
    pub fn try_add_sensor_bounds_sequence(
        &mut self,
        key: &str,
    ) -> CompilerResult<&mut SequenceSensorBounds> {
        let mut res = CompilerResult::new(format!("Add sensor bound sequence with key {}", key));
        if self.sequences.contains_key(key) {
            res.error(format!(
                "A sensor bound sequence with key: {} already exists",
                key
            ));
            return res;
        }

        let new_sequence = SequenceSensorBounds::new();
        self.sequences.insert(key.into(), new_sequence);

        res.with_value(self.sequences.get_mut(key).unwrap())
    }
}

impl SequenceSensorBounds {
    pub fn new() -> Self {
        SequenceSensorBounds {
            sensors: BTreeMap::new(),
        }
    }

    /// Add sensor bounds for every sensor that is in this timeline
    pub fn add_bounds(&mut self, timeline: &SensorsTimeline) -> CompilerResult<()> {
        let mut res = CompilerResult::status_only("Add sensor bounds to JSON struct");

        for (sensor, timeline) in &timeline.sensor_timelines {
            let mut sensor_bounds = SensorBounds::new();

            // TODO currently we are only adding range constraints, but this can likely
            // be changed pretty easily to also include endpoint constraints if we have
            // a way to nicely visualize them in mission control
            sensor_bounds.times = timeline.endpoints.clone();
            for constraints_vec in &timeline.range_constraints {
                // The constraints_vec should contain 0 or 1 sensor constraints
                match constraints_vec.len() {
                    // If there are no constraints active, create a NoValue bound to tell mission control
                    // To stop displaying sensor bounds
                    0 => {
                        sensor_bounds.bound_values.push(BoundValue::NoValue {
                            left: (),
                            right: (),
                        });
                    }
                    // If there is a single constraint active, get the numeric bounds if they exist and
                    // only add NoValue bounds if it is a boolean
                    1 => {
                        match &constraints_vec[0].sensor_bound {
                            // Don't encode boolean sensor bounds as this doesn't make sense
                            crate::test_descriptor::ast::SensorBound::Boolean(_) => {
                                sensor_bounds.bound_values.push(BoundValue::NoValue {
                                    left: (),
                                    right: (),
                                })
                            }
                            crate::test_descriptor::ast::SensorBound::Numeric(bound) => {
                                sensor_bounds.bound_values.push(BoundValue::Value {
                                    left: bound.left,
                                    right: bound.right,
                                });
                            }
                        }
                    }
                    _ => {
                        res.error("Constraints vector contained more than one constraint!");
                    }
                }
            }

            self.sensors.insert(sensor.to_string(), sensor_bounds);
        }
        res
    }
}

impl SensorBounds {
    pub fn new() -> Self {
        SensorBounds {
            // Start with a single time that is the maximum u128 value. This will automatically remove
            // sensor bounds for each sensor once it is no longer used in the test
            times: Vec::new(),
            bound_values: Vec::new(),
        }
    }
}

/// Contains a hashmap with the timestrip for the test body and every abort
/// The test body timestrip will use the key "test_body" and each abort will use its abort idx as the key
struct TestTimestrips {
    timestrips: BTreeMap<String, Timestrip>,
}

#[derive(Serialize, Deserialize, Clone)]
/// Contains a vector of every section present in the TDF. The contained sections are serialized
/// into JSON and used by mission control to display an overview of the test.
#[serde(transparent)]
struct Timestrip {
    sections: Vec<TimestripSection>,
}

#[derive(Serialize, Deserialize, Clone)]
/// Represents an individual section of the TDF. Contains a unique identifier which is equivalent to
/// this section's location in the vector containing every section.
struct TimestripSection {
    id: u32,
    // corresponds with section depth
    group: u32,
    title: String,
    start_time: u128,
    end_time: u128,
}

impl TestTimestrips {
    pub fn new() -> Self {
        TestTimestrips {
            timestrips: BTreeMap::new(),
        }
    }

    /// Function to add a timestrip with the provided key
    /// Errors if a timestrip already exists with the same key
    pub fn try_add_timestrip(&mut self, key: &str) -> CompilerResult<&mut Timestrip> {
        let mut res = CompilerResult::new(format!("Add timestrip with key {}", key));
        if self.timestrips.contains_key(key) {
            res.error(format!("A timestrip with key: {} already exists", key));
            return res;
        }

        let test_body_timestrip = Timestrip::new();
        self.timestrips.insert(key.into(), test_body_timestrip);

        res.with_value(self.timestrips.get_mut(key).unwrap())
    }
}

impl Timestrip {
    pub fn new() -> Self {
        Timestrip {
            sections: Vec::new(),
        }
    }
    /// Create a new timestrip section
    /// maps the provided depth value into the TIMESTRIP_COLORS array
    pub fn new_section(&mut self, title: &str, start_time: u128, end_time: u128, depth: u32) {
        let new_section = TimestripSection {
            id: self.sections.len() as u32,
            group: depth,
            title: title.to_string(),
            start_time,
            end_time,
        };
        self.sections.push(new_section);
    }

    /// Recursively add all sections in the test to this timestrip
    fn create_sections(
        &mut self,
        statements: &[Statement],
        time_offset: u128,
        depth: u32,
    ) -> CompilerResult<()> {
        let mut res =
            CompilerResult::status_only(format!("Create timestrip sections with depth: {}", depth));

        // Loop through statements and find every section
        for statement in statements {
            match statement {
                Statement::Section(section_statement) => {
                    let start_time = time_offset + section_statement.time.start;
                    let end_time = start_time + section_statement.time.duration;
                    self.new_section(&section_statement.name, start_time, end_time, depth);

                    // Recursively add any section statements within this section
                    res.require(self.create_sections(
                        &section_statement.statements,
                        start_time,
                        depth + 1,
                    ));
                }
                // Do nothing for any other statement types
                _ => (),
            }
        }
        res
    }
}

/// Output JSON sensor bounds based on the test_body and abort sensor timelines
pub fn emit_json_sensor_bounds(
    test_body_timeline: &Timeline,
    abort_timelines: &Vec<Timeline>,
    output_path: PathBuf,
) -> CompilerResult<()> {
    let mut res = CompilerResult::status_only("Emit JSON sensor bounds for mission control");

    // Construct the sensor bounds for the test body
    let mut test_sensor_bounds = TestSensorBounds::new();
    let test_body_bounds = check!(
        res,
        test_sensor_bounds.try_add_sensor_bounds_sequence("test_body")
    );
    check!(
        res,
        test_body_bounds.add_bounds(&test_body_timeline.timeline_sensor)
    );

    // Construct the sensor bounds for each abort sequence
    for (idx, abort_timeline) in abort_timelines.into_iter().enumerate() {
        let abort_bounds = check!(
            res,
            // Add 1 to the abort idx because 0 is hard abort
            test_sensor_bounds.try_add_sensor_bounds_sequence(&(idx + 1).to_string())
        );
        check!(
            res,
            abort_bounds.add_bounds(&abort_timeline.timeline_sensor)
        );
    }

    // Emit the sensor bounds to file
    let file = check!(res, File::create(output_path));
    check!(
        res,
        to_writer_pretty(file, &test_sensor_bounds.sequences),
        "Serialize sensor bounds and write to output file"
    );
    res
}

/// Output a JSON timestrip based on the section statements in the Test
pub fn emit_timestrip(concrete: &ConcreteTest, output_path: PathBuf) -> CompilerResult<()> {
    let mut res = CompilerResult::status_only("Emit timestrip for mission control");

    let mut test_timestrips = TestTimestrips::new();
    let test_body_timestrip = check!(res, test_timestrips.try_add_timestrip("test_body"));

    let statements = &concrete.test.test_body.statements;
    test_body_timestrip.create_sections(statements, 0u128, 0);

    for abort in &concrete.test.aborts {
        // Get the numeric id of this abort
        let abort_id = check!(res, concrete.get_abort_id(&abort.name));
        // Add this abort to the test_timestrips using the abort id as the key
        let abort_timestrip = check!(
            res,
            test_timestrips.try_add_timestrip(&abort_id.to_string())
        );

        // Add the timestrip sections from this abort's statements
        abort_timestrip.create_sections(&abort.statements, 0u128, 0);
    }

    let file = check!(res, File::create(output_path));
    check!(
        res,
        to_writer_pretty(file, &test_timestrips.timestrips),
        "Serialize timestrip and write to output file"
    );
    return res;
}

/// Emit the JSON mapping between abort names and abort indices. Used by mission control to
/// understand firmware telemetry messages.
pub fn emit_abort_json(concrete: &ConcreteTest, output: PathBuf) -> CompilerResult<()> {
    //Get all the aborts from the concrete tests
    let mut res = CompilerResult::status_only("Emit abort idx and name mapping");
    let aborts = &concrete.test.aborts;

    // Create map that gets the inserts the id as the key and name as the value
    let mut abort_mapping: BTreeMap<u32, &str> = BTreeMap::new();
    for x in aborts {
        abort_mapping.insert(check!(res, concrete.get_abort_id(&x.name)), &x.name);
    }

    // Emitting abort mapping JSON
    let file = check!(res, File::create(output));
    check!(
        res,
        to_writer_pretty(file, &abort_mapping),
        "Serialize abort mappings and write to output file"
    );
    res
}
#[cfg(test)]
mod tests {
    use super::*;
    use crate::test_builder::TestBuilder;
    use std::{fs, io::Read};
    use tempfile::NamedTempFile;

    /// Test that a TDF with no sections outputs an empty
    #[test]
    pub fn test_emit_empty_timeline() {
        let timeline_expected = r#"{
  "1": [],
  "test_body": []
}"#;
        let mut testbuilder = TestBuilder::new();
        testbuilder.with_relay("relay1").with_relay("relay2");
        testbuilder.with_sensor("sensor1").with_sensor("sensor2");

        let mut test_body = testbuilder.with_body();

        test_body.at(10).set("relay1");
        test_body.at(40).set("relay2");

        test_body
            .at(5)
            .require("sensor1", 10_f64, 40_f64, "HARD_ABORT");
        test_body
            .at(40)
            .require("sensor1", 10_f64, 40_f64, "HARD_ABORT");

        test_body.at(60).unset("relay1");
        test_body.at(60).unset("relay2");

        let mut abort = testbuilder.with_abort("pressure_lost");
        abort.at(20).unset("relay1");
        abort.at(20).unset("relay2");

        let concrete_test_opt =
            ConcreteTest::try_new(testbuilder.env, testbuilder.test).to_option();
        assert!(concrete_test_opt.is_some());

        let timeline_output_path = NamedTempFile::new().unwrap().into_temp_path().to_path_buf();
        emit_timestrip(&concrete_test_opt.unwrap(), timeline_output_path.clone());

        let mut timeline_output = String::new();
        fs::File::open(timeline_output_path)
            .expect("Failed to open tmp file")
            .read_to_string(&mut timeline_output)
            .expect("Failed to read from tmp file");

        assert_eq!(timeline_expected, timeline_output)
    }

    /// Test that a TDF with a few sections outputs a correct timeline
    #[test]
    pub fn test_emit_timeline() {
        let timeline_expected = r#"{
  "1": [
    {
      "id": 0,
      "group": 0,
      "title": "abort_section",
      "start_time": 50,
      "end_time": 100
    }
  ],
  "test_body": [
    {
      "id": 0,
      "group": 0,
      "title": "example_section",
      "start_time": 2,
      "end_time": 52
    },
    {
      "id": 1,
      "group": 0,
      "title": "new_section",
      "start_time": 52,
      "end_time": 102
    },
    {
      "id": 2,
      "group": 1,
      "title": "inner_section",
      "start_time": 58,
      "end_time": 68
    }
  ]
}"#;
        let mut testbuilder = TestBuilder::new();
        testbuilder.with_relay("relay1").with_relay("relay2");
        testbuilder.with_sensor("sensor1").with_sensor("sensor2");

        let mut test_body = testbuilder.with_body();

        let mut example_section = test_body.section_from(2, 50, "example_section");
        example_section.at(10).set("relay1");
        example_section.at(40).set("relay2");

        let mut new_section = test_body.section_from(52, 50, "new_section");
        new_section.at(5).unset("relay1");

        // create and add contents to a nested section within new_section
        let mut inner_section = new_section.section_from(6, 10, "inner_section");
        inner_section
            .at(5)
            .require("sensor1", 10_f64, 40_f64, "HARD_ABORT");

        // add contents after inner_section to new_section
        new_section.at(20).unset("relay2");
        new_section
            .at(40)
            .require("sensor1", 10_f64, 40_f64, "HARD_ABORT");

        let mut abort = testbuilder.with_abort("test_abort");
        abort.at(20).unset("relay1");
        let mut abort_section = abort.section_from(50, 50, "abort_section");
        abort_section.at(40).unset("relay2");

        let concrete_test_opt =
            ConcreteTest::try_new(testbuilder.env, testbuilder.test).to_option();
        assert!(concrete_test_opt.is_some());

        let timeline_output_path = NamedTempFile::new().unwrap().into_temp_path().to_path_buf();
        emit_timestrip(&concrete_test_opt.unwrap(), timeline_output_path.clone());

        let mut timeline_output = String::new();
        fs::File::open(timeline_output_path)
            .expect("Failed to open tmp file")
            .read_to_string(&mut timeline_output)
            .expect("Failed to read from tmp file");

        assert_eq!(timeline_expected, timeline_output)
    }

    /// Test to do the abort mapping and check that it printed completely
    #[test]
    pub fn test_abort_mapping() {
        // Create the parameters
        let expected: &str = r#"{
  "1": "test1",
  "2": "test2",
  "3": "test3",
  "4": "test4"
}"#;
        let mut testbuilder = TestBuilder::new();
        testbuilder.with_abort("test1");
        testbuilder.with_abort("test2");
        testbuilder.with_abort("test3");
        testbuilder.with_abort("test4");
        let concrete_test_opt =
            ConcreteTest::try_new(testbuilder.env, testbuilder.test).to_option();

        assert!(concrete_test_opt.is_some());

        let output_path = NamedTempFile::new().unwrap().into_temp_path().to_path_buf();
        //Emits the abort json
        emit_abort_json(&concrete_test_opt.unwrap(), output_path.clone());

        //Gets the contents of the files and puts in a string
        let mut abort_output = String::new();
        fs::File::open(output_path)
            .expect("Failed to open tmp file")
            .read_to_string(&mut abort_output)
            .expect("Failed to read from tmp file");

        // Asserts that the raw string created by hand, which is correct, is equal to the file created from the function.
        assert_eq!(abort_output, expected);
    }

    //Creates a concrete test with no aborts and checks if the emited json
    //is correct and has no aborts in it
    #[test]
    pub fn empty_abort_mapping() {
        let expected: &str = r#"{}"#;
        let testbuilder = TestBuilder::new();
        let concrete_test_opt =
            ConcreteTest::try_new(testbuilder.env, testbuilder.test).to_option();

        assert!(concrete_test_opt.is_some());

        let output_path = NamedTempFile::new().unwrap().into_temp_path().to_path_buf();
        //Emits the abort json
        emit_abort_json(&concrete_test_opt.unwrap(), output_path.clone());

        //Gets the contents of the files and puts in a string
        let mut abort_output = String::new();
        fs::File::open(output_path)
            .expect("Failed to open tmp file")
            .read_to_string(&mut abort_output)
            .expect("Failed to read from tmp file");

        // Asserts that the raw string created by hand, which is correct, is equal to the file created from the function.
        assert_eq!(abort_output, expected);
    }

    //Creates a concrete test with max amount of aborts possible and makes
    //sure it still prints out correctly
    #[test]
    pub fn full_abort_mapping() {
        // Create the parameters
        let expected: &str = r#"{
  "1": "test1",
  "2": "test2",
  "3": "test3",
  "4": "test4",
  "5": "test5",
  "6": "test6",
  "7": "test7",
  "8": "test8",
  "9": "test9",
  "10": "test10",
  "11": "test11",
  "12": "test12",
  "13": "test13",
  "14": "test14",
  "15": "test15"
}"#;
        let mut testbuilder = TestBuilder::new();
        testbuilder.with_abort("test1");
        testbuilder.with_abort("test2");
        testbuilder.with_abort("test3");
        testbuilder.with_abort("test4");
        testbuilder.with_abort("test5");
        testbuilder.with_abort("test6");
        testbuilder.with_abort("test7");
        testbuilder.with_abort("test8");
        testbuilder.with_abort("test9");
        testbuilder.with_abort("test10");
        testbuilder.with_abort("test11");
        testbuilder.with_abort("test12");
        testbuilder.with_abort("test13");
        testbuilder.with_abort("test14");
        testbuilder.with_abort("test15");
        let concrete_test_opt =
            ConcreteTest::try_new(testbuilder.env, testbuilder.test).to_option();

        assert!(concrete_test_opt.is_some());

        let output_path = NamedTempFile::new().unwrap().into_temp_path().to_path_buf();
        //Emits the abort json
        emit_abort_json(&concrete_test_opt.unwrap(), output_path.clone());

        //Gets the contents of the files and puts in a string
        let mut abort_output = String::new();
        fs::File::open(output_path)
            .expect("Failed to open tmp file")
            .read_to_string(&mut abort_output)
            .expect("Failed to read from tmp file");

        // Asserts that the raw string created by hand, which is correct, is equal to the file created from the function.
        assert_eq!(abort_output, expected);
    }

    //Creates an abort mapping when the concrete test contains section and other things
    //like in an actual test
    #[test]
    pub fn realistic_abort_mapping() {
        let expected: &str = r#"{
  "1": "section1_fail",
  "2": "section2_fail",
  "3": "inner_section_fail"
}"#;
        let mut testbuilder = TestBuilder::new();
        testbuilder.with_relay("relay1").with_relay("relay2");
        testbuilder.with_sensor("sensor1").with_sensor("sensor2");

        let mut test_body = testbuilder.with_body();

        let mut example_section = test_body.section_from(2, 50, "example_section");
        example_section.at(10).set("relay1");
        example_section.at(40).set("relay2");

        let mut new_section = test_body.section_from(52, 50, "new_section");
        new_section.at(5).unset("relay1");

        // create and add contents to a nested section within new_section
        let mut inner_section = new_section.section_from(6, 10, "inner_section");
        inner_section
            .at(5)
            .require("sensor1", 10_f64, 40_f64, "HARD_ABORT");

        // add contents after inner_section to new_section
        new_section.at(20).unset("relay2");
        new_section
            .at(40)
            .require("sensor1", 10_f64, 40_f64, "HARD_ABORT");

        testbuilder.with_abort("section1_fail");
        testbuilder.with_abort("section2_fail");
        testbuilder.with_abort("inner_section_fail");

        let concrete_test_opt =
            ConcreteTest::try_new(testbuilder.env, testbuilder.test).to_option();

        assert!(concrete_test_opt.is_some());

        let output_path = NamedTempFile::new().unwrap().into_temp_path().to_path_buf();
        //Emits the abort json
        emit_abort_json(&concrete_test_opt.unwrap(), output_path.clone());

        //Gets the contents of the files and puts in a string
        let mut abort_output = String::new();
        fs::File::open(output_path)
            .expect("Failed to open tmp file")
            .read_to_string(&mut abort_output)
            .expect("Failed to read from tmp file");

        // Asserts that the raw string created by hand, which is correct, is equal to the file created from the function.
        assert_eq!(abort_output, expected);
    }
}