<commit_before>﻿module runner

open canopy

let mutable tests = []
let mutable before = fun () -> ()
let failfast = ref false
let suggestions = ref true

let test f = 
    let fAsList = [f]
    tests <- List.append tests fAsList

let rec private makeSuggestions (actions : Action list) =
    match actions with
    | [] -> ()
    | action1 :: action2 :: _ when action1.action <> "on" && action2.action <> "on" && (action1.url <> action2.url) ->  //suggestion for doing an action one page that transitioned you to another page and performing an action without checking to see if that page loaded with 'on'
        (
            System.Console.WriteLine("Suggestion: as a best practice you should check that you are on a page before
accessing an element on it
you were on {0}
then on {1}", action1.url, action2.url);
            makeSuggestions actions.Tail
        )
    | _ -> makeSuggestions actions.Tail

let run _ =
    let failed = ref false
    tests |> List.map (fun f -> (
                                if failed = ref false then
                                    try
                                        (before ())
                                        (f ())
                                        System.Console.WriteLine("Passed");
                                    with
                                        | ex -> (
                                                    if failfast = ref true then
                                                        failed := true
                                                        System.Console.WriteLine("failfast was set to true and an error occured; stopping testing");
                                                    System.Console.WriteLine("Error: {0}", ex.Message);
                                                )
                                        )
                                if suggestions = ref true then
                                    makeSuggestions actions

                                actions <- []
                                ) |> ignore
    
    ()<commit_msg>added pass/fail count and timer for how long tests run<commit_after>﻿module runner

open canopy

let mutable tests = []
let mutable before = fun () -> ()
let failfast = ref false
let suggestions = ref true
let mutable passedCount = 0
let mutable failedCount = 0
let stopWatch = new System.Diagnostics.Stopwatch()
stopWatch.Start()

let test f = 
    let fAsList = [f]
    tests <- List.append tests fAsList

let rec private makeSuggestions (actions : Action list) =
    match actions with
    | [] -> ()
    | action1 :: action2 :: _ when action1.action <> "on" && action2.action <> "on" && (action1.url <> action2.url) ->  //suggestion for doing an action one page that transitioned you to another page and performing an action without checking to see if that page loaded with 'on'
        (
            System.Console.WriteLine("Suggestion: as a best practice you should check that you are on a page before
accessing an element on it
you were on {0}
then on {1}", action1.url, action2.url);
            makeSuggestions actions.Tail
        )
    | _ -> makeSuggestions actions.Tail

let run _ =
    let failed = ref false
    tests |> List.map (fun f -> (
                                if failed = ref false then
                                    try
                                        (before ())
                                        (f ())
                                        System.Console.WriteLine("Passed");
                                        passedCount <- passedCount + 1
                                    with
                                        | ex -> (
                                                    if failfast = ref true then
                                                        failed := true
                                                        System.Console.WriteLine("failfast was set to true and an error occured; stopping testing");
                                                    System.Console.WriteLine("Error: {0}", ex.Message);
                                                    failedCount <- failedCount + 1
                                                )
                                        )
                                if suggestions = ref true then
                                    makeSuggestions actions

                                actions <- []
                                ) |> ignore
    
    stopWatch.Stop()
    System.Console.WriteLine()
    System.Console.WriteLine("{0} seconds to execute", stopWatch.Elapsed.Seconds)
    System.Console.WriteLine("{0} passed", passedCount)
    System.Console.WriteLine("{0} failed", failedCount)    

    ()
{'fraction_non_alphanumeric': 0.07552358789930189, 'fraction_numerical': 0.006134969325153374, 'mean_word_length': 1.1078912171199287, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 47, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5238810', 'n_tokens_mistral': 1005, 'n_tokens_neox': 956, 'n_words': 359}