Files

minitest.src
  • MiniManager = {}
  • MiniManager.shell = get_shell
  • MiniManager.computer = MiniManager.shell.host_computer
  • MiniManager.running_test = null
  • MiniManager.work_path = home_dir+"/.tmp"
  • MiniManager.stats = ["assertions", "failures", "errors"]
  • MiniManager.assertions = 0
  • MiniManager.failures = 0
  • MiniManager.errors = 0
  • MiniManager.instalation_path = "/home/guest/minitest"
  • MiniManager.prepend = []
  • MiniManager.append = []
  • MiniManager.prepend.push("import_code("""+MiniManager.instalation_path+"/libs/listLib.src"")")
  • MiniManager.prepend.push("import_code("""+MiniManager.instalation_path+"/manager.src"")")
  • MiniManager.prepend.push("import_code("""+MiniManager.instalation_path+"/testApi.src"")")
  • MiniManager.append.push("import_code("""+MiniManager.instalation_path+"/runner.src"")")
  • MiniManager.test_files = function()
  • self.set_stats_files
  • for file_path in self.files_to_run
  • self.test_file(file_path)
  • end for
  • end function
  • MiniManager.test_file = function(file_path)
  • test_src_path = home_dir+"/.tmp/test.src"
  • test_src = self.computer.File(test_src_path)
  • if test_src != null then
  • test_src.delete
  • self.computer.touch(home_dir+"/.tmp", "test.src")
  • test_src = self.computer.File(test_src_path)
  • end if
  • bin_file_path = home_dir+"/.tmp/test"
  • bin_file = self.computer.File(bin_file_path)
  • if bin_file != null then
  • bin_file.delete
  • end if
  • code = self.computer.File(file_path).get_content
  • test_code = self.prepend.join(char(10)) + char(10) + code + char(10) + self.append.join(char(10))
  • test_src.set_content(test_code)
  • test_build = self.shell.build(test_src_path, home_dir+"/.tmp")
  • if test_build.len != 0 then
  • print(char(10)+"<color=red>compilation error on:</color>"+char(10)+"<color=red>"+file_path+"</color>")
  • print(test_build)
  • self.increment_stat("errors")
  • return
  • end if
  • self.shell.launch(bin_file_path)
  • end function
  • MiniManager.files_to_run = function()
  • return self.computer.File(home_dir+"/.tmp/files_to_run.txt").get_content.split(char(10))
  • end function
  • MiniManager.set_files_to_run = function(files)
  • self.computer.touch(home_dir+"/.tmp", "files_to_run.txt")
  • content = ""
  • for file in files
  • content = content + file.path + char(10)
  • end for
  • content = content[0:-1] // remove the last line break
  • self.computer.File(home_dir+"/.tmp/files_to_run.txt").set_content(content)
  • end function
  • MiniManager.set_stats_files = function()
  • for stat in self.stats
  • self.computer.touch(self.work_path, stat)
  • file = self.computer.File(self.work_path+"/"+stat)
  • stat_value = file.get_content
  • if stat_value != "0" then
  • file.set_content("0")
  • end if
  • end for
  • end function
  • MiniManager.increment_stat = function(stat)
  • file = self.computer.File(self.work_path+"/"+stat)
  • stat_value = file.get_content.to_int
  • file.set_content(stat_value + 1)
  • end function
  • MiniManager.get_stat = function(stat)
  • file = self.computer.File(self.work_path+"/"+stat)
  • stat_value = file.get_content.to_int
  • return stat_value
  • end function
  • MiniManager.set_running_test = function(test)
  • self.running_test = test
  • end function
testApi.src
  • printer = function(assert_out)
  • if assert_out == true then
  • MiniManager.increment_stat("assertions")
  • print("<color=green>.</color>")
  • else
  • MiniManager.increment_stat("failures")
  • test = MiniManager.running_test
  • print("<color=#f4292d>failure: "+test["class_name"]+" "+test["test_name"]+"</color>")
  • print("<color=#f4292d>"+assert_out+"</color>")
  • end if
  • end function
  • assert = function(condition)
  • if condition == true then
  • printer(true)
  • else
  • printer("expected "+condition+" to be true")
  • end if
  • end function
  • assert_equal = function(value1, value2)
  • if value1 == value2 then
  • printer(true)
  • else
  • printer("expected """+value1+""" to be equal to """+value2+"""")
  • end if
  • end function
manager.src
  • MiniManager = {}
  • MiniManager.shell = get_shell
  • MiniManager.computer = MiniManager.shell.host_computer
  • MiniManager.running_test = null
  • MiniManager.work_path = home_dir+"/.tmp"
  • MiniManager.stats = ["assertions", "failures", "errors"]
  • MiniManager.assertions = 0
  • MiniManager.failures = 0
  • MiniManager.errors = 0
  • MiniManager.instalation_path = "/home/guest/minitest"
  • MiniManager.prepend = []
  • MiniManager.append = []
  • MiniManager.prepend.push("import_code("""+MiniManager.instalation_path+"/libs/listLib.src"")")
  • MiniManager.prepend.push("import_code("""+MiniManager.instalation_path+"/manager.src"")")
  • MiniManager.prepend.push("import_code("""+MiniManager.instalation_path+"/testApi.src"")")
  • MiniManager.append.push("import_code("""+MiniManager.instalation_path+"/runner.src"")")
  • MiniManager.test_files = function()
  • self.set_stats_files
  • for file_path in self.files_to_run
  • self.test_file(file_path)
  • end for
  • end function
  • MiniManager.test_file = function(file_path)
  • test_src_path = home_dir+"/.tmp/test.src"
  • test_src = self.computer.File(test_src_path)
  • if test_src != null then
  • test_src.delete
  • self.computer.touch(home_dir+"/.tmp", "test.src")
  • test_src = self.computer.File(test_src_path)
  • end if
  • bin_file_path = home_dir+"/.tmp/test"
  • bin_file = self.computer.File(bin_file_path)
  • if bin_file != null then
  • bin_file.delete
  • end if
  • code = self.computer.File(file_path).get_content
  • test_code = self.prepend.join(char(10)) + char(10) + code + char(10) + self.append.join(char(10))
  • test_src.set_content(test_code)
  • test_build = self.shell.build(test_src_path, home_dir+"/.tmp")
  • if test_build.len != 0 then
  • print(char(10)+"<color=red>compilation error on:</color>"+char(10)+"<color=red>"+file_path+"</color>")
  • print(test_build)
  • self.increment_stat("errors")
  • return
  • end if
  • self.shell.launch(bin_file_path)
  • end function
  • MiniManager.files_to_run = function()
  • return self.computer.File(home_dir+"/.tmp/files_to_run.txt").get_content.split(char(10))
  • end function
  • MiniManager.set_files_to_run = function(files)
  • self.computer.touch(home_dir+"/.tmp", "files_to_run.txt")
  • content = ""
  • for file in files
  • content = content + file.path + char(10)
  • end for
  • content = content[0:-1] // remove the last line break
  • self.computer.File(home_dir+"/.tmp/files_to_run.txt").set_content(content)
  • end function
  • MiniManager.set_stats_files = function()
  • for stat in self.stats
  • self.computer.touch(self.work_path, stat)
  • file = self.computer.File(self.work_path+"/"+stat)
  • stat_value = file.get_content
  • if stat_value != "0" then
  • file.set_content("0")
  • end if
  • end for
  • end function
  • MiniManager.increment_stat = function(stat)
  • file = self.computer.File(self.work_path+"/"+stat)
  • stat_value = file.get_content.to_int
  • file.set_content(stat_value + 1)
  • end function
  • MiniManager.get_stat = function(stat)
  • file = self.computer.File(self.work_path+"/"+stat)
  • stat_value = file.get_content.to_int
  • return stat_value
  • end function
  • MiniManager.set_running_test = function(test)
  • self.running_test = test
  • end function
runner.src
  • is_class_test = function(tuple)
  • return tuple[0].indexOf("Test") != null and typeof(tuple[1]) == "list"
  • end function
  • test_classes = select(to_list(globals), @is_class_test)
  • tests_table = []
  • convert_to_table = function(list)
  • struct = {}
  • class_name = list[0]
  • functions = to_map(list[1])
  • setup = functions["setup"]
  • functions.remove("setup")
  • tests = functions
  • for i in tests.indexes
  • tests_table.push({"class_name": class_name, "setup": @setup, "test_name": i, "test_function": tests[i]})
  • end for
  • end function
  • test_classes = each(test_classes, @convert_to_table)
  • for test in tests_table
  • MiniManager.set_running_test(test)
  • if test["setup"] != null then
  • test["setup"]()
  • end if
  • test["test_function"]()
  • end for
examples/duck.src
  • Duck = {}
  • Duck.mood = null
  • Duck.fly = false
  • Duck.quack = function()
  • if self.mood == "happy" then
  • return "quack"
  • return "name is null"
  • else
  • if self.mood == null then return "mood is null"
  • return "not happy"
  • end if
  • end function
examples/test/duckTest.src
  • import_code("/home/guest/minitest/examples/duck.src")
  • DuckTest = {}
  • DuckTest.setup = function()
  • self.duck = new Duck
  • end function
  • DuckTest.fly_should_return_false = function()
  • assert_equal(self.duck.fly, false)
  • end function
  • DuckTest.quack_should_quack_when_happy = function()
  • self.duck.mood = "happy"
  • assert(self.duck.quack.indexOf("quack") != null)
  • end function
  • DuckTest.quack_should_not_quack_if_mood_is_sad = function()
  • self.duck.mood = "sad"
  • assert(self.duck.quack.indexOf("quack") != null)
  • end function
  • DuckTest.quack_should_not_quack_if_mood_is_null = function()
  • self.duck.mood = null
  • assert(self.duck.quack.indexOf("quack") == null)
  • end function
examples/test/birdTest.src
  • // no import
  • BirdTest = {}
  • BirdTest.setup = function()
  • self.bird = new Bird
  • end function
  • BirdTest.fly_should_return_true = function()
  • assert_equal(self.bird.fly, true)
  • end function
libs/listLib.src
  • to_list = function(map)
  • list = []
  • for i in map.indexes
  • if typeof(map[i]) == "map" then
  • list.push([i, to_list(map[i])])
  • else
  • list.push([i, map[i]])
  • end if
  • end for
  • return list
  • end function
  • to_map = function(list)
  • l = list[0:]
  • map = {}
  • for i in indexes(l)
  • if typeof(l[i][1]) == "list" and l[i][1].len == 2 and typeof(l[i][1][0]) == "string" then
  • map[l[i][0]] = to_map(l[i][1])
  • else
  • map[l[i][0]] = l[i][1]
  • end if
  • end for
  • return map
  • end function
  • each = function(obj, func)
  • if typeof(obj) == "map" then
  • list = to_list(obj)
  • else
  • list = obj
  • end if
  • result = list[0:] //list copy.
  • for i in indexes(list)
  • if typeof(obj) == "map" then
  • func(result[i][0], result[i][1])
  • else
  • func(result[i])
  • end if
  • end for
  • end function
  • map = function(list, func)
  • result = list[0:] //list copy.
  • for i in indexes(list)
  • result[i] = func(result[i])
  • end for
  • return result
  • end function
  • reject = function(list, func)
  • result = list[0:] //list copy.
  • i = 0
  • while i < result.len
  • if func(result[i]) == true then
  • result.remove(i)
  • continue
  • end if
  • i = i + 1
  • end while
  • return result
  • end function
  • select = function(list, func)
  • result = list[0:] //list copy.
  • i = 0
  • while i < result.len
  • if func(result[i]) == false then
  • result.remove(i)
  • continue
  • end if
  • i = i + 1
  • end while
  • return result
  • end function