From 0b67a2cd1d5616f9e0e24e07e18fd933fd137c61 Mon Sep 17 00:00:00 2001 From: Vuoksenmaa Aleksis I Date: Thu, 21 Sep 2017 17:37:55 +0300 Subject: [PATCH 01/50] Added a new test --- tmcRtestrunner/DESCRIPTION | 2 ++ tmcRtestrunner/R/RunTests.R | 1 + tmcRtestrunner/tests/testthat/testRunTests.R | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/tmcRtestrunner/DESCRIPTION b/tmcRtestrunner/DESCRIPTION index 03fb59d..c43f285 100644 --- a/tmcRtestrunner/DESCRIPTION +++ b/tmcRtestrunner/DESCRIPTION @@ -11,3 +11,5 @@ Encoding: UTF-8 LazyData: true Depends: testthat +Suggests: + testthat diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index aa0615a..d4b130b 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -8,6 +8,7 @@ runTests <- function(project_path, print = FALSE) { # print: If TRUE, prints results; if not, not. DEFAULT is FALSE. # + return(TRUE) } diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index f6fb738..465a417 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -1,3 +1,7 @@ test_that("Dummy test before real tests.", { expect_true(DummyFunction()) }) + +test_that("Empty test works", { + expect_true(runTests()) +}) From 55a137b8814feeb2fe63b17640046117b272af7a Mon Sep 17 00:00:00 2001 From: Vuoksenmaa Aleksis I Date: Thu, 21 Sep 2017 18:37:27 +0300 Subject: [PATCH 02/50] Added new dummy functions to check if coverage works as intended --- tmcRtestrunner/R/RunTests.R | 8 ++++++++ tmcRtestrunner/tests/testthat/testRunTests.R | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index d4b130b..4325733 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -19,3 +19,11 @@ DummyFunction <- function() { # A dumy function for testthat testing (before real tests) return(TRUE) } + +Dummy2 <- function() { + return(T) +} + +Dummy3 <- function() { + return(F) +} diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 465a417..a111770 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -5,3 +5,11 @@ test_that("Dummy test before real tests.", { test_that("Empty test works", { expect_true(runTests()) }) + +test_that("Dummy2 works", { + expect_true(Dummy2()) +}) + +test_that("Dummy3 works", { + expect_true(Dummy3()) +}) From 2eece8380197a036350193da5ad0041789c6ea0e Mon Sep 17 00:00:00 2001 From: Vuoksenmaa Aleksis I Date: Thu, 21 Sep 2017 18:40:43 +0300 Subject: [PATCH 03/50] Changed the third dummy method to pass. --- tmcRtestrunner/tests/testthat/testRunTests.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index a111770..26bbf3a 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -11,5 +11,5 @@ test_that("Dummy2 works", { }) test_that("Dummy3 works", { - expect_true(Dummy3()) + expect_false(Dummy3()) }) From 36e2d77a46fc1207283ee879395095d5a98db7d9 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Thu, 21 Sep 2017 18:46:20 +0300 Subject: [PATCH 04/50] Added new test file. --- tmcrstudioaddin/tests/testthat/testExample.R | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tmcrstudioaddin/tests/testthat/testExample.R diff --git a/tmcrstudioaddin/tests/testthat/testExample.R b/tmcrstudioaddin/tests/testthat/testExample.R new file mode 100644 index 0000000..9ad3c2a --- /dev/null +++ b/tmcrstudioaddin/tests/testthat/testExample.R @@ -0,0 +1,3 @@ +test_that("Example file with dummy function gets called", { + expect_true(returnsTrue()) +}) From 94ec7f081d4c7067dfa252cc7f9f39511229f364 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Thu, 21 Sep 2017 19:02:57 +0300 Subject: [PATCH 05/50] Changed project structure --- example_projects/example_project1/tmc/{ => R}/result.R | 0 example_projects/example_project1/tmc/tests/testthat/testResult.R | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename example_projects/example_project1/tmc/{ => R}/result.R (100%) create mode 100644 example_projects/example_project1/tmc/tests/testthat/testResult.R diff --git a/example_projects/example_project1/tmc/result.R b/example_projects/example_project1/tmc/R/result.R similarity index 100% rename from example_projects/example_project1/tmc/result.R rename to example_projects/example_project1/tmc/R/result.R diff --git a/example_projects/example_project1/tmc/tests/testthat/testResult.R b/example_projects/example_project1/tmc/tests/testthat/testResult.R new file mode 100644 index 0000000..e69de29 From bdc17e0bb550345865f087cc0476fb9be7ccd32a Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Thu, 21 Sep 2017 19:06:55 +0300 Subject: [PATCH 06/50] Changed .travis.yml to include new tests. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index dada049..f80f89f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ env: matrix: - REPO_TO_TEST=tmcrstudioaddin - REPO_TO_TEST=tmcRtestrunner + - REPO_TO_TEST=example_projects/example_project1/tmc after_success: - Rscript -e 'library(covr);coveralls()' From 85588803999a1b3dcc8ff21443779bd8786f2b68 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 11:50:00 +0300 Subject: [PATCH 07/50] Made the branch compatible with other branches --- .../example_project1/tmc/R/result.R | 125 ---------------- .../example_project1/tmc/result.R | 4 + .../tmc/tests/testthat/testResult.R | 0 tmcRtestrunner/R/RunTests.R | 134 +++++++++++++++++- 4 files changed, 134 insertions(+), 129 deletions(-) delete mode 100644 example_projects/example_project1/tmc/R/result.R create mode 100644 example_projects/example_project1/tmc/result.R delete mode 100644 example_projects/example_project1/tmc/tests/testthat/testResult.R diff --git a/example_projects/example_project1/tmc/R/result.R b/example_projects/example_project1/tmc/R/result.R deleted file mode 100644 index e436591..0000000 --- a/example_projects/example_project1/tmc/R/result.R +++ /dev/null @@ -1,125 +0,0 @@ -llibrary('testthat') -library('jsonlite') - -#declaring variables to global environment that for example helperTMC.R can use -points <- list() -points_for_all_tests <- list() - -#Checks if a single test passed -CheckIfResultCorrect <- function(test) { - ret <- TRUE - for (result in test$results) { - if (format(result) != "As expected") { - ret <- FALSE - break - } - } - return (ret) -} - -#Checks whether all the tests in a single file passed -CheckThatAllPassed <- function(test_output) { - ret <- TRUE - for (test in test_output) { - if (!CheckIfResultCorrect(test)) { - ret <- FALSE - break - } - } - return (ret) -} - -#Adds the points from a single test file to all the tests in the file -#returns points list, so that the modified points list is updated -AddPointsToAllTests <- function(test_output) { - for (test in test_output) { - if (!(points_for_all_tests %in% points[[test$test]])) { - points[[test$test]] <- c(points[[test$test]], points_for_all_tests) - } - } - return (points) -} - -PrintResult <- function(name, message, failed) { - if (failed) { - print(paste(name, ": FAIL", sep = "")) - print(paste(" ", message, sep = "")) - } else { - print(paste(name, ": PASS", sep = "")) - } -} - -#Returns message from failed results -#Currently supports only results that used calls -MessageFromFailedResult <- function(result) { - if (is.null(result$call)) { - return("") - } - #language that failed the test. for example call expect_equal(1,2) - language <- toString(result$call[[1]]) - return (paste(sep="", "Failed with call: ", language,"\n", result$message)) -} - -#Returns the points of a test or an empty vector if null -GetTestPoints <- function(testName) { - if (is.null(points[[testName]])) { - return(vector()) - } else { - return(points[[testName]]) - } -} - -CreateTestResult <- function(testStatus, testName, testMessage, - testPoints, backtrace) { - testResult <- list(status=unbox(testStatus), - name=unbox(format(testName)), - message=unbox(testMessage), - backtrace=unbox(backtrace), - points=testPoints) - return(testResult) -} - -testthatOutput <- list() - -#Lists all the files in the path beginning with "test" and ending in ".R" -testFiles <- list.files(path="tests/testthat", pattern = "test.*\\.R", full.names = T, recursive = FALSE) -for (testFile in testFiles) { - testFileOutput <- test_file(testFile, reporter = "silent") - #Modifies the points because they were added to all the tests. - points <- AddPointsToAllTests(testFileOutput) - #Adds the output from the tests in the file to the list - testthatOutput <- c(testthatOutput, testFileOutput) -} - -CreateResults <- function(testthatOutput) { - results = list() - for (test in testthatOutput) { - testName <- test$test - testPoints <- GetTestPoints(testName) - testFailed <- FALSE - testStatus <- "passed" - testMessage <- "" - for (result in test$results) { - if (format(result) != "As expected") { - testFailed <- TRUE - testStatus <- "failed" - testMessage <- paste(sep = "", testMessage, MessageFromFailedResult(result)) - } - } - PrintResult(testName, testMessage, testFailed) - testResult <- CreateTestResult(testStatus, testName, testMessage,testPoints, "") - #Add test result to results - results[[length(results)+1]] <- testResult - } - return (results) -} - - -results <- CreateResults(testthatOutput) - -#json utf-8 coded: -json <- enc2utf8(toJSON(results, pretty = FALSE)) -json <- prettify(json) - -#encode json to utf-8 and write file -write(json, ".results.json") diff --git a/example_projects/example_project1/tmc/result.R b/example_projects/example_project1/tmc/result.R new file mode 100644 index 0000000..73f5a91 --- /dev/null +++ b/example_projects/example_project1/tmc/result.R @@ -0,0 +1,4 @@ +library(tmcRtestrunner) + +# Note: working directory must be the projects root! +runTests(getwd()) diff --git a/example_projects/example_project1/tmc/tests/testthat/testResult.R b/example_projects/example_project1/tmc/tests/testthat/testResult.R deleted file mode 100644 index e69de29..0000000 diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index 4325733..d689719 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -1,4 +1,3 @@ - runTests <- function(project_path, print = FALSE) { # Runs the tests from project directory and writes results JSON to the root of the project # as .tmc_results.json. @@ -7,19 +6,146 @@ runTests <- function(project_path, print = FALSE) { # project_path: The path to the root of the project being tested. # print: If TRUE, prints results; if not, not. DEFAULT is FALSE. # + library('testthat') + library('jsonlite') + + tmcrtestrunnet_project_path <- getwd() + setwd(project_path) + + #declaring variables to global environment that for example helperTMC.R can use + points <- list() + points_for_all_tests <- list() + + testthatOutput <- list() + + #Lists all the files in the path beginning with "test" and ending in ".R" + testFiles <- list.files(path="tests/testthat", pattern = "test.*\\.R", full.names = T, recursive = FALSE) + for (testFile in testFiles) { + testFileOutput <- test_file(testFile, reporter = "silent") + #Modifies the points because they were added to all the tests. + points <- .AddPointsToAllTests(testFileOutput) + #Adds the output from the tests in the file to the list + testthatOutput <- c(testthatOutput, testFileOutput) + } + +.CreateResults <- function(testthatOutput) { + results = list() + for (test in testthatOutput) { + testName <- test$test + testPoints <- .GetTestPoints(testName) + testFailed <- FALSE + testStatus <- "passed" + testMessage <- "" + for (result in test$results) { + if (format(result) != "As expected") { + testFailed <- TRUE + testStatus <- "failed" + testMessage <- paste(sep = "", testMessage, .MessageFromFailedResult(result)) + } + } + .PrintResult(testName, testMessage, testFailed) + testResult <- .CreateTestResult(testStatus, testName, testMessage,testPoints, "") + #Add test result to results + results[[length(results)+1]] <- testResult + } + return (results) + } - return(TRUE) + results <- .CreateResults(testthatOutput) + + #json utf-8 coded: + json <- enc2utf8(toJSON(results, pretty = FALSE)) + json <- prettify(json) + + #encode json to utf-8 and write file + write(json, ".results.json") + + #restore project path: + setwd(tmcrtestrunnet_project_path) } -.hidden_function <- function() { +#Checks if a single test passed +.CheckIfResultCorrect <- function(test) { + ret <- TRUE + for (result in test$results) { + if (format(result) != "As expected") { + ret <- FALSE + break + } + } + return (ret) +} + +#Checks whether all the tests in a single file passed +.CheckThatAllPassed <- function(test_output) { + ret <- TRUE + for (test in test_output) { + if (!.CheckIfResultCorrect(test)) { + ret <- FALSE + break + } + } + return (ret) +} + +#Adds the points from a single test file to all the tests in the file +#returns points list, so that the modified points list is updated +.AddPointsToAllTests <- function(test_output) { + for (test in test_output) { + if (!(points_for_all_tests %in% points[[test$test]])) { + points[[test$test]] <- c(points[[test$test]], points_for_all_tests) + } + } + return (points) +} + +.PrintResult <- function(name, message, failed) { + if (failed) { + print(paste(name, ": FAIL", sep = "")) + print(paste(" ", message, sep = "")) + } else { + print(paste(name, ": PASS", sep = "")) + } +} + +#Returns message from failed results +#Currently supports only results that used calls +.MessageFromFailedResult <- function(result) { + if (is.null(result$call)) { + return("") + } + #language that failed the test. for example call expect_equal(1,2) + language <- toString(result$call[[1]]) + return (paste(sep="", "Failed with call: ", language,"\n", result$message)) +} + +#Returns the points of a test or an empty vector if null +.GetTestPoints <- function(testName) { + if (is.null(points[[testName]])) { + return(vector()) + } else { + return(points[[testName]]) + } +} + +.CreateTestResult <- function(testStatus, testName, testMessage, + testPoints, backtrace) { + testResult <- list(status=unbox(testStatus), + name=unbox(format(testName)), + message=unbox(testMessage), + backtrace=unbox(backtrace), + points=testPoints) + return(testResult) } DummyFunction <- function() { - # A dumy function for testthat testing (before real tests) return(TRUE) } +.hidden_function <- function() { +} + Dummy2 <- function() { return(T) } From cfcf32e7b7ba5b4a5c43e1b8bca634e33cf67617 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 11:54:36 +0300 Subject: [PATCH 08/50] Made branch fully compatible with owntestmethod --- .travis.yml | 1 - .../example_project1/tmc_run_test_example.sh | 1 + tmcRtestrunner/DESCRIPTION | 9 ++++----- tmcRtestrunner/NAMESPACE | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index f80f89f..dada049 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,6 @@ env: matrix: - REPO_TO_TEST=tmcrstudioaddin - REPO_TO_TEST=tmcRtestrunner - - REPO_TO_TEST=example_projects/example_project1/tmc after_success: - Rscript -e 'library(covr);coveralls()' diff --git a/example_projects/example_project1/tmc_run_test_example.sh b/example_projects/example_project1/tmc_run_test_example.sh index 4b7a7a3..65095c0 100755 --- a/example_projects/example_project1/tmc_run_test_example.sh +++ b/example_projects/example_project1/tmc_run_test_example.sh @@ -1,2 +1,3 @@ #!/bin/sh +#Currently this script needs to be run at project root! Rscript tmc/result.R diff --git a/tmcRtestrunner/DESCRIPTION b/tmcRtestrunner/DESCRIPTION index c43f285..fd9bf87 100644 --- a/tmcRtestrunner/DESCRIPTION +++ b/tmcRtestrunner/DESCRIPTION @@ -1,8 +1,8 @@ Package: tmcRtestrunner Type: Package -Title: What the Package Does (Title Case) +Title: Runs TMC R projects Version: 0.1.0 -Author: Who wrote it +Author: RTMC Maintainer: The package maintainer Description: More about what it does (maybe more than one line) Use four spaces when indenting paragraphs within the Description. @@ -10,6 +10,5 @@ License: What license is it under? Encoding: UTF-8 LazyData: true Depends: - testthat -Suggests: - testthat + testthat, + jsonlite diff --git a/tmcRtestrunner/NAMESPACE b/tmcRtestrunner/NAMESPACE index 8b7afee..8a5fcc4 100644 --- a/tmcRtestrunner/NAMESPACE +++ b/tmcRtestrunner/NAMESPACE @@ -1,3 +1,4 @@ exportPattern("^[[:alpha:]]+") import(testthat) +import(jsonlite) From 04960a8fb44bb093652d8669f79399b3f61e4aa3 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 12:30:57 +0300 Subject: [PATCH 09/50] Fixed comment on RunTests.R --- tmcRtestrunner/R/RunTests.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index d689719..5cbc207 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -3,7 +3,7 @@ runTests <- function(project_path, print = FALSE) { # as .tmc_results.json. # # Args: - # project_path: The path to the root of the project being tested. + # project_path: The absolute path to the root of the project being tested. # print: If TRUE, prints results; if not, not. DEFAULT is FALSE. # library('testthat') From 1c5c37b898e08757438347b85ad8d2f42461f3d0 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 12:37:33 +0300 Subject: [PATCH 10/50] Fixed namings of the functions. Test that checks if you can find hidden functions. --- tmcRtestrunner/R/RunTests.R | 5 +++-- tmcRtestrunner/tests/testthat/testRunTests.R | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index 5cbc207..47b411f 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -9,7 +9,7 @@ runTests <- function(project_path, print = FALSE) { library('testthat') library('jsonlite') - tmcrtestrunnet_project_path <- getwd() + tmcrtestrunner_project_path <- getwd() setwd(project_path) #declaring variables to global environment that for example helperTMC.R can use @@ -62,7 +62,7 @@ runTests <- function(project_path, print = FALSE) { write(json, ".results.json") #restore project path: - setwd(tmcrtestrunnet_project_path) + setwd(tmcrtestrunner_project_path) } #Checks if a single test passed @@ -144,6 +144,7 @@ DummyFunction <- function() { } .hidden_function <- function() { + return(T) } Dummy2 <- function() { diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 26bbf3a..1fc708f 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -2,10 +2,6 @@ test_that("Dummy test before real tests.", { expect_true(DummyFunction()) }) -test_that("Empty test works", { - expect_true(runTests()) -}) - test_that("Dummy2 works", { expect_true(Dummy2()) }) @@ -13,3 +9,7 @@ test_that("Dummy2 works", { test_that("Dummy3 works", { expect_false(Dummy3()) }) + +test_that("Hidden functions work", { + expect_true(.hidden_function()) +}) From ec424e186f0ade2f1162a5cb78054b0ab322fe4b Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 13:14:39 +0300 Subject: [PATCH 11/50] Started writing tests to correct functions. --- tmcRtestrunner/tests/testthat/testRunTests.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 1fc708f..a032cd3 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -1,3 +1,9 @@ +library('jsonlite') + +path <- file.path(getwd()) +path <- dirname(dirname(dirname(path))) +path_to_example1 <- paste(sep = "", path, "/example_projects/example_project1") +path_to_json <- paste(set="", path_to_example1, "/.results.json") test_that("Dummy test before real tests.", { expect_true(DummyFunction()) }) @@ -13,3 +19,7 @@ test_that("Dummy3 works", { test_that("Hidden functions work", { expect_true(.hidden_function()) }) + +test_that("Tests pass", { + expect_true(T) +}) From 3e8f011a852398d9baa785dd53a806ddf5c986f8 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 13:26:45 +0300 Subject: [PATCH 12/50] Refactored runTests-class so that it would be easier to test. --- tmcRtestrunner/R/RunTests.R | 49 +++++++++++--------- tmcRtestrunner/tests/testthat/testRunTests.R | 1 + 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index 47b411f..7b6c738 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -1,17 +1,26 @@ -runTests <- function(project_path, print = FALSE) { - # Runs the tests from project directory and writes results JSON to the root of the project - # as .tmc_results.json. - # - # Args: - # project_path: The absolute path to the root of the project being tested. - # print: If TRUE, prints results; if not, not. DEFAULT is FALSE. - # +# Runs the tests from project directory and writes results JSON to the root of the project +# as .tmc_results.json. +# +# Args: +# project_path: The absolute path to the root of the project being tested. +# print: If TRUE, prints results; if not, not. DEFAULT is FALSE. +# +runTests <- function(project_path, print=FALSE) { library('testthat') library('jsonlite') tmcrtestrunner_project_path <- getwd() setwd(project_path) + results <- GetTestResults(project_path, print) + .WriteJson(results) + + setwd(tmcrtestrunner_project_path) + +} + +GetTestResults <- function(project_path, print = FALSE) { + #declaring variables to global environment that for example helperTMC.R can use points <- list() points_for_all_tests <- list() @@ -28,6 +37,16 @@ runTests <- function(project_path, print = FALSE) { testthatOutput <- c(testthatOutput, testFileOutput) } +} + +.WriteJson <- function(results) { + #json utf-8 coded: + json <- enc2utf8(toJSON(results, pretty = FALSE)) + json <- prettify(json) + #encode json to utf-8 and write file + write(json, ".results.json") +} + .CreateResults <- function(testthatOutput) { results = list() for (test in testthatOutput) { @@ -51,20 +70,6 @@ runTests <- function(project_path, print = FALSE) { return (results) } - - results <- .CreateResults(testthatOutput) - - #json utf-8 coded: - json <- enc2utf8(toJSON(results, pretty = FALSE)) - json <- prettify(json) - - #encode json to utf-8 and write file - write(json, ".results.json") - - #restore project path: - setwd(tmcrtestrunner_project_path) -} - #Checks if a single test passed .CheckIfResultCorrect <- function(test) { ret <- TRUE diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index a032cd3..a634d67 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -22,4 +22,5 @@ test_that("Hidden functions work", { test_that("Tests pass", { expect_true(T) + runTests(path_to_example1) }) From 84c6ea0524a9a3e40a877d949897e2e2208582ce Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 13:30:08 +0300 Subject: [PATCH 13/50] Fixed travis build fail in runTests --- tmcRtestrunner/tests/testthat/testRunTests.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index a634d67..c751558 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -1,5 +1,3 @@ -library('jsonlite') - path <- file.path(getwd()) path <- dirname(dirname(dirname(path))) path_to_example1 <- paste(sep = "", path, "/example_projects/example_project1") From 61263b08f1550f415ec0df07eb21e3031565a756 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 13:36:58 +0300 Subject: [PATCH 14/50] Tried to fix travis issue. --- tmcRtestrunner/R/RunTests.R | 1 + tmcRtestrunner/tests/testthat/testRunTests.R | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index 7b6c738..08b7252 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -10,6 +10,7 @@ runTests <- function(project_path, print=FALSE) { library('jsonlite') tmcrtestrunner_project_path <- getwd() + setwd(project_path) results <- GetTestResults(project_path, print) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index c751558..7cc9e8e 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -20,5 +20,4 @@ test_that("Hidden functions work", { test_that("Tests pass", { expect_true(T) - runTests(path_to_example1) }) From 725357ad271949981ed1fdcec5187f1b6f034ebe Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 14:15:22 +0300 Subject: [PATCH 15/50] Refacored old runTests code and added tests --- tmcRtestrunner/R/RunTests.R | 6 ++++-- tmcRtestrunner/tests/testthat/testRunTests.R | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index 08b7252..eceeec6 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -11,8 +11,6 @@ runTests <- function(project_path, print=FALSE) { tmcrtestrunner_project_path <- getwd() - setwd(project_path) - results <- GetTestResults(project_path, print) .WriteJson(results) @@ -22,6 +20,7 @@ runTests <- function(project_path, print=FALSE) { GetTestResults <- function(project_path, print = FALSE) { + setwd(project_path) #declaring variables to global environment that for example helperTMC.R can use points <- list() points_for_all_tests <- list() @@ -30,6 +29,7 @@ GetTestResults <- function(project_path, print = FALSE) { #Lists all the files in the path beginning with "test" and ending in ".R" testFiles <- list.files(path="tests/testthat", pattern = "test.*\\.R", full.names = T, recursive = FALSE) + print(getwd()) for (testFile in testFiles) { testFileOutput <- test_file(testFile, reporter = "silent") #Modifies the points because they were added to all the tests. @@ -38,6 +38,8 @@ GetTestResults <- function(project_path, print = FALSE) { testthatOutput <- c(testthatOutput, testFileOutput) } + return(testthatOutput) + } .WriteJson <- function(results) { diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 7cc9e8e..3d97bb7 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -2,6 +2,7 @@ path <- file.path(getwd()) path <- dirname(dirname(dirname(path))) path_to_example1 <- paste(sep = "", path, "/example_projects/example_project1") path_to_json <- paste(set="", path_to_example1, "/.results.json") + test_that("Dummy test before real tests.", { expect_true(DummyFunction()) }) @@ -20,4 +21,9 @@ test_that("Hidden functions work", { test_that("Tests pass", { expect_true(T) + results <- GetTestResults(path_to_example1) + string <- format(results[[1]]$results[[1]]) + string2 <- "As expected" + + expect_equal(string, string2) }) From 82cf7a7ed517a1268b9d1800b75a67df435e7935 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 14:16:38 +0300 Subject: [PATCH 16/50] Changed test names. --- tmcRtestrunner/tests/testthat/testRunTests.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 3d97bb7..ee0f73b 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -19,8 +19,7 @@ test_that("Hidden functions work", { expect_true(.hidden_function()) }) -test_that("Tests pass", { - expect_true(T) +test_that("GetTestResults works as intended", { results <- GetTestResults(path_to_example1) string <- format(results[[1]]$results[[1]]) string2 <- "As expected" From 64c2b63d43dd12b9b378a06f1f292c16dd6bc604 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 14:21:39 +0300 Subject: [PATCH 17/50] Fixing travis issues. --- tmcRtestrunner/R/RunTests.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index eceeec6..71212cf 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -10,7 +10,6 @@ runTests <- function(project_path, print=FALSE) { library('jsonlite') tmcrtestrunner_project_path <- getwd() - results <- GetTestResults(project_path, print) .WriteJson(results) @@ -29,7 +28,7 @@ GetTestResults <- function(project_path, print = FALSE) { #Lists all the files in the path beginning with "test" and ending in ".R" testFiles <- list.files(path="tests/testthat", pattern = "test.*\\.R", full.names = T, recursive = FALSE) - print(getwd()) + for (testFile in testFiles) { testFileOutput <- test_file(testFile, reporter = "silent") #Modifies the points because they were added to all the tests. @@ -37,9 +36,7 @@ GetTestResults <- function(project_path, print = FALSE) { #Adds the output from the tests in the file to the list testthatOutput <- c(testthatOutput, testFileOutput) } - return(testthatOutput) - } .WriteJson <- function(results) { From 0e56f73e09477eaef071052adf3a7a4a80adff65 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 14:58:48 +0300 Subject: [PATCH 18/50] Figuring out what causes the tests to fail on travis. --- tmcRtestrunner/tests/testthat/testRunTests.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index ee0f73b..90a72fd 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -21,6 +21,7 @@ test_that("Hidden functions work", { test_that("GetTestResults works as intended", { results <- GetTestResults(path_to_example1) + print(results) string <- format(results[[1]]$results[[1]]) string2 <- "As expected" From 97810ed5b038a59545129a01aeeec582ff2e5183 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 15:06:09 +0300 Subject: [PATCH 19/50] Figuring out what causes the tests to fail on travis. --- tmcRtestrunner/R/RunTests.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index 71212cf..6bad667 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -10,6 +10,7 @@ runTests <- function(project_path, print=FALSE) { library('jsonlite') tmcrtestrunner_project_path <- getwd() + setwd(project_path) results <- GetTestResults(project_path, print) .WriteJson(results) @@ -18,7 +19,6 @@ runTests <- function(project_path, print=FALSE) { } GetTestResults <- function(project_path, print = FALSE) { - setwd(project_path) #declaring variables to global environment that for example helperTMC.R can use points <- list() From aa6546cf0cfd6ea9cffb2b47443b7873b8f45ac8 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 15:11:21 +0300 Subject: [PATCH 20/50] Figuring out what causes the tests to fail on travis. --- tmcRtestrunner/R/RunTests.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index 6bad667..220acbf 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -20,6 +20,7 @@ runTests <- function(project_path, print=FALSE) { GetTestResults <- function(project_path, print = FALSE) { setwd(project_path) + print(project_path) #declaring variables to global environment that for example helperTMC.R can use points <- list() points_for_all_tests <- list() From c240a350322c20461aca44ece7af7bb1fc404228 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 15:37:27 +0300 Subject: [PATCH 21/50] Trying to fix travis --- tmcRtestrunner/R/RunTests.R | 7 +++++-- tmcRtestrunner/tests/testthat/testRunTests.R | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index 220acbf..6550bca 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -15,16 +15,19 @@ runTests <- function(project_path, print=FALSE) { .WriteJson(results) setwd(tmcrtestrunner_project_path) - } GetTestResults <- function(project_path, print = FALSE) { + library('testthat') + library('jsonlite') setwd(project_path) - print(project_path) + + #declaring variables to global environment that for example helperTMC.R can use points <- list() points_for_all_tests <- list() + testthatOutput <- list() #Lists all the files in the path beginning with "test" and ending in ".R" diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 90a72fd..f8c8fed 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -21,9 +21,7 @@ test_that("Hidden functions work", { test_that("GetTestResults works as intended", { results <- GetTestResults(path_to_example1) - print(results) string <- format(results[[1]]$results[[1]]) string2 <- "As expected" - expect_equal(string, string2) }) From 002709863ceb8f9cca73cedb570c1a7f1f921c7c Mon Sep 17 00:00:00 2001 From: anttihaap Date: Fri, 22 Sep 2017 18:56:56 +0300 Subject: [PATCH 22/50] Testing travis. --- tmcRtestrunner/tests/testthat/testRunTests.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index f8c8fed..f3b53f7 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -1,5 +1,7 @@ path <- file.path(getwd()) +print(path) path <- dirname(dirname(dirname(path))) +print(path) path_to_example1 <- paste(sep = "", path, "/example_projects/example_project1") path_to_json <- paste(set="", path_to_example1, "/.results.json") From 186f8cf252a9ae4dc0602eca6385f85b1a27a03c Mon Sep 17 00:00:00 2001 From: anttihaap Date: Fri, 22 Sep 2017 19:02:18 +0300 Subject: [PATCH 23/50] Trying to fix travis again. --- tmcRtestrunner/tests/testthat/testRunTests.R | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index f3b53f7..4a436dc 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -1,8 +1,5 @@ -path <- file.path(getwd()) -print(path) -path <- dirname(dirname(dirname(path))) -print(path) -path_to_example1 <- paste(sep = "", path, "/example_projects/example_project1") +project_path <- project.root +path_to_example1 <- paste(sep = "", project_path, "/example_projects/example_project1") path_to_json <- paste(set="", path_to_example1, "/.results.json") test_that("Dummy test before real tests.", { From d14c08e81b9c93b8925befedc1914aee0634d47a Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Fri, 22 Sep 2017 19:28:10 +0300 Subject: [PATCH 24/50] Fixed travis (once more.) --- tmcRtestrunner/DESCRIPTION | 3 ++- tmcRtestrunner/R/RunTests.R | 4 ++-- tmcRtestrunner/tests/testthat/testRunTests.R | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tmcRtestrunner/DESCRIPTION b/tmcRtestrunner/DESCRIPTION index fd9bf87..6e74517 100644 --- a/tmcRtestrunner/DESCRIPTION +++ b/tmcRtestrunner/DESCRIPTION @@ -11,4 +11,5 @@ Encoding: UTF-8 LazyData: true Depends: testthat, - jsonlite + jsonlite, + rprojroot diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index 6550bca..e046570 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -9,8 +9,8 @@ runTests <- function(project_path, print=FALSE) { library('testthat') library('jsonlite') - tmcrtestrunner_project_path <- getwd() - setwd(project_path) + # tmcrtestrunner_project_path <- getwd() + #setwd(project_path) results <- GetTestResults(project_path, print) .WriteJson(results) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 4a436dc..575a128 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -1,4 +1,5 @@ -project_path <- project.root +project_path <- find_root(has_file("DESCRIPTION")) +project_path <- dirname(project_path) path_to_example1 <- paste(sep = "", project_path, "/example_projects/example_project1") path_to_json <- paste(set="", path_to_example1, "/.results.json") From 17524fd9051146fbb1b772bd8ad1a3c3ac77bcda Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 12:37:13 +0300 Subject: [PATCH 25/50] Refactored code. Fixed an issue with JSON --- tmcRtestrunner/R/RunTests.R | 11 ++++++++--- tmcRtestrunner/tests/testthat/testRunTests.R | 6 +++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index e046570..f9e4b85 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -5,14 +5,15 @@ # project_path: The absolute path to the root of the project being tested. # print: If TRUE, prints results; if not, not. DEFAULT is FALSE. # + runTests <- function(project_path, print=FALSE) { library('testthat') library('jsonlite') - # tmcrtestrunner_project_path <- getwd() + tmcrtestrunner_project_path <- getwd() #setwd(project_path) results <- GetTestResults(project_path, print) - .WriteJson(results) + .WriteJson(results) setwd(tmcrtestrunner_project_path) } @@ -40,10 +41,14 @@ GetTestResults <- function(project_path, print = FALSE) { #Adds the output from the tests in the file to the list testthatOutput <- c(testthatOutput, testFileOutput) } - return(testthatOutput) + + results <- .CreateResults(testthatOutput) + + return(results) } .WriteJson <- function(results) { + #json utf-8 coded: json <- enc2utf8(toJSON(results, pretty = FALSE)) json <- prettify(json) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 575a128..8a975e3 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -3,6 +3,7 @@ project_path <- dirname(project_path) path_to_example1 <- paste(sep = "", project_path, "/example_projects/example_project1") path_to_json <- paste(set="", path_to_example1, "/.results.json") + test_that("Dummy test before real tests.", { expect_true(DummyFunction()) }) @@ -23,5 +24,8 @@ test_that("GetTestResults works as intended", { results <- GetTestResults(path_to_example1) string <- format(results[[1]]$results[[1]]) string2 <- "As expected" - expect_equal(string, string2) +}) + +test_that("RunTests works", { + runTests(path_to_example1) }) From a81e631996db2ff39804d3a4dbb901c4c8ec58e8 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 13:54:01 +0300 Subject: [PATCH 26/50] Added test to test printing --- tmcRtestrunner/tests/testthat/testRunTests.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 8a975e3..eda1896 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -29,3 +29,9 @@ test_that("GetTestResults works as intended", { test_that("RunTests works", { runTests(path_to_example1) }) + +test_that("PrintResult produces the right output", { + string1 <- format(.PrintResult("Testi1", "!", FALSE)) + string2 <- format("Testi1: PASS") + expect_equal(string1, string2) +}) From d718d9120b73d8e93bf429575b654845c3b459d9 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 14:03:53 +0300 Subject: [PATCH 27/50] Changed .travis.yml-file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dada049..83e781e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,4 +17,4 @@ env: - REPO_TO_TEST=tmcRtestrunner after_success: - - Rscript -e 'library(covr);coveralls()' + - Rscript -e 'library(covr);codecov()' From 2b0aa806d359c1b88d97680d6c7361710c0e9061 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 14:07:46 +0300 Subject: [PATCH 28/50] Changed .travis.yml-file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 83e781e..90c9c1b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,8 +13,8 @@ before_install: env: matrix: - - REPO_TO_TEST=tmcrstudioaddin - REPO_TO_TEST=tmcRtestrunner + - REPO_TO_TEST=tmcrstudioaddin after_success: - Rscript -e 'library(covr);codecov()' From a3c60f319d65af798c69a744aceefaf5c852ed8a Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 14:12:16 +0300 Subject: [PATCH 29/50] Trying to wake up coveralls --- tmcRtestrunner/tests/testthat/testRunTests.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index eda1896..8558aca 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -35,3 +35,7 @@ test_that("PrintResult produces the right output", { string2 <- format("Testi1: PASS") expect_equal(string1, string2) }) + +test_that("Dummy test", { + expect_true(T) +}) From d823de7e2b4911d0e58c3fe45a5ceade649a53af Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 14:18:38 +0300 Subject: [PATCH 30/50] Changed .travis.yml files to include coveralls --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 90c9c1b..b1e776b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,4 +17,4 @@ env: - REPO_TO_TEST=tmcrstudioaddin after_success: - - Rscript -e 'library(covr);codecov()' + - Rscript -e 'library(covr);coveralls()' From f4ccb74b3e816c8e1cb984d75133d9dedacfc19c Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 14:29:05 +0300 Subject: [PATCH 31/50] Added support to parallel builds. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b1e776b..4875bfd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ env: matrix: - REPO_TO_TEST=tmcRtestrunner - REPO_TO_TEST=tmcrstudioaddin + - COVERALLS_PARALLEL=true after_success: - Rscript -e 'library(covr);coveralls()' From 4d0162080d22d1ed591ecbd9a3324a4978f52eaa Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 14:32:08 +0300 Subject: [PATCH 32/50] Added support to parallel builds. --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4875bfd..a840f90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,11 +11,13 @@ r_packages: before_install: - cd $REPO_TO_TEST +notifications: + webhooks: https://coveralls.io/webhook?repo_token=COVERALLS_REPO_TOKEN + env: matrix: - REPO_TO_TEST=tmcRtestrunner - REPO_TO_TEST=tmcrstudioaddin - - COVERALLS_PARALLEL=true after_success: - Rscript -e 'library(covr);coveralls()' From 3d7e505e989c883fe14717f9e8608fb4766c5e09 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 14:38:13 +0300 Subject: [PATCH 33/50] Configuring travis --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a840f90..761c99f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r language: R -sudo: false +sudo: enable cache: packages warnings_are_errors: false @@ -17,7 +17,6 @@ notifications: env: matrix: - REPO_TO_TEST=tmcRtestrunner - - REPO_TO_TEST=tmcrstudioaddin after_success: - Rscript -e 'library(covr);coveralls()' From 3450a3d2714f2e645e5c54cf3218927f53c23874 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 14:45:23 +0300 Subject: [PATCH 34/50] Fixing travis. --- .travis.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 761c99f..b1e776b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r language: R -sudo: enable +sudo: false cache: packages warnings_are_errors: false @@ -11,12 +11,10 @@ r_packages: before_install: - cd $REPO_TO_TEST -notifications: - webhooks: https://coveralls.io/webhook?repo_token=COVERALLS_REPO_TOKEN - env: matrix: - REPO_TO_TEST=tmcRtestrunner + - REPO_TO_TEST=tmcrstudioaddin after_success: - Rscript -e 'library(covr);coveralls()' From 0757db097dff7deaacc90c27d9e05b0bd9781ba7 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 15:04:47 +0300 Subject: [PATCH 35/50] Fixing travis. --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b1e776b..fee4caf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ r_packages: - covr before_install: - - cd $REPO_TO_TEST + - cd tmcRtestrunner env: matrix: @@ -18,3 +18,6 @@ env: after_success: - Rscript -e 'library(covr);coveralls()' + +jobs: + include: From bb09f1f334756f2010f94dd211286914ca0b25e4 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sat, 23 Sep 2017 15:18:30 +0300 Subject: [PATCH 36/50] Trying to fix travis. --- .travis.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index fee4caf..b1e776b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ r_packages: - covr before_install: - - cd tmcRtestrunner + - cd $REPO_TO_TEST env: matrix: @@ -18,6 +18,3 @@ env: after_success: - Rscript -e 'library(covr);coveralls()' - -jobs: - include: From b8e741997656713dc2c37357e12cd6af58297f11 Mon Sep 17 00:00:00 2001 From: anttihaap Date: Sat, 23 Sep 2017 20:59:04 +0300 Subject: [PATCH 37/50] Added resources for testrunner, some refactoring and test modifications. --- .gitignore | 1 + .../tests/testthat/testArithmetics.R | 2 +- tmcRtestrunner/DESCRIPTION | 3 +- tmcRtestrunner/R/RunTests.R | 37 +++--------------- .../simple_all_tests_pass/.results.json | 31 +++++++++++++++ .../resources/simple_all_tests_pass/R/main.R | 11 ++++++ .../simple_all_tests_pass.Rproj | 13 ++++++ .../tests/testthat/helperTMC.R | 13 ++++++ .../tests/testthat/testMain.R | 20 ++++++++++ tmcRtestrunner/tests/testthat/testRunTests.R | 31 +++------------ tmcRtestrunner_0.1.0.tar.gz | Bin 0 -> 3009 bytes 11 files changed, 101 insertions(+), 61 deletions(-) create mode 100644 tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/.results.json create mode 100644 tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/R/main.R create mode 100644 tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/simple_all_tests_pass.Rproj create mode 100644 tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/tests/testthat/helperTMC.R create mode 100644 tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/tests/testthat/testMain.R create mode 100644 tmcRtestrunner_0.1.0.tar.gz diff --git a/.gitignore b/.gitignore index 7b732e7..faea2bd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .RData .Ruserdata .DS_Store +tmcRtestrunner.Rcheck/ diff --git a/example_projects/example_project1/tests/testthat/testArithmetics.R b/example_projects/example_project1/tests/testthat/testArithmetics.R index de8d7c5..f889db7 100644 --- a/example_projects/example_project1/tests/testthat/testArithmetics.R +++ b/example_projects/example_project1/tests/testthat/testArithmetics.R @@ -4,7 +4,7 @@ source("../../R/arithmetics.R") pointsForAllTests(c("r1")) -test("Addition works", c("r1.1","r1.2"), { +test("Addition works", c("r1.1", "r1.2"), { expect_equal(add(1, 2), 3) expect_equal(add(1, 2), 3.0) expect_equal(add(1, 4), 5) diff --git a/tmcRtestrunner/DESCRIPTION b/tmcRtestrunner/DESCRIPTION index 6e74517..fd9bf87 100644 --- a/tmcRtestrunner/DESCRIPTION +++ b/tmcRtestrunner/DESCRIPTION @@ -11,5 +11,4 @@ Encoding: UTF-8 LazyData: true Depends: testthat, - jsonlite, - rprojroot + jsonlite diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index f9e4b85..eb7a04e 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -5,30 +5,18 @@ # project_path: The absolute path to the root of the project being tested. # print: If TRUE, prints results; if not, not. DEFAULT is FALSE. # - runTests <- function(project_path, print=FALSE) { - library('testthat') - library('jsonlite') - tmcrtestrunner_project_path <- getwd() #setwd(project_path) - results <- GetTestResults(project_path, print) - .WriteJson(results) + results <- .GetTestResults(project_path, print) + .WriteJson(results) setwd(tmcrtestrunner_project_path) } -GetTestResults <- function(project_path, print = FALSE) { - library('testthat') - library('jsonlite') +.GetTestResults <- function(project_path, print = FALSE) { setwd(project_path) - - #declaring variables to global environment that for example helperTMC.R can use - points <- list() - points_for_all_tests <- list() - - testthatOutput <- list() #Lists all the files in the path beginning with "test" and ending in ".R" @@ -42,13 +30,14 @@ GetTestResults <- function(project_path, print = FALSE) { testthatOutput <- c(testthatOutput, testFileOutput) } + .AddPointsForAllTestToPoints(testFileOutput) + results <- .CreateResults(testthatOutput) return(results) } .WriteJson <- function(results) { - #json utf-8 coded: json <- enc2utf8(toJSON(results, pretty = FALSE)) json <- prettify(json) @@ -152,19 +141,3 @@ GetTestResults <- function(project_path, print = FALSE) { points=testPoints) return(testResult) } - -DummyFunction <- function() { - return(TRUE) -} - -.hidden_function <- function() { - return(T) -} - -Dummy2 <- function() { - return(T) -} - -Dummy3 <- function() { - return(F) -} diff --git a/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/.results.json b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/.results.json new file mode 100644 index 0000000..4a50091 --- /dev/null +++ b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/.results.json @@ -0,0 +1,31 @@ +[ + { + "status": "passed", + "name": "RetTrue works.", + "message": "", + "backtrace": "", + "points": [ + "r1.1" + ] + }, + { + "status": "passed", + "name": "RetOne works.", + "message": "", + "backtrace": "", + "points": [ + "r1.2" + ] + }, + { + "status": "passed", + "name": "Add works.", + "message": "", + "backtrace": "", + "points": [ + "r1.3", + "r1.4" + ] + } +] + diff --git a/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/R/main.R b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/R/main.R new file mode 100644 index 0000000..f51705b --- /dev/null +++ b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/R/main.R @@ -0,0 +1,11 @@ +RetTrue <- function() { + return(TRUE) +} + +RetOne <- function() { + return(1) +} + +Add <- function(a, b) { + return(a + b) +} \ No newline at end of file diff --git a/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/simple_all_tests_pass.Rproj b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/simple_all_tests_pass.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/simple_all_tests_pass.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX diff --git a/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/tests/testthat/helperTMC.R b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/tests/testthat/helperTMC.R new file mode 100644 index 0000000..51a55d8 --- /dev/null +++ b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/tests/testthat/helperTMC.R @@ -0,0 +1,13 @@ + +#Sets the points for all tests to global environment, wherefrom they can +#be retrieved. +pointsForAllTests <- function(points) { + .GlobalEnv$points_for_all_tests <- points +} + +#The test that wraps around test_that()-method and stores the points +#to global environment. +test <- function(desc, points, code) { + .GlobalEnv$points[[desc]] <- points + test_that(desc, code) +} diff --git a/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/tests/testthat/testMain.R b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/tests/testthat/testMain.R new file mode 100644 index 0000000..af0b4ba --- /dev/null +++ b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/tests/testthat/testMain.R @@ -0,0 +1,20 @@ +library('testthat') + +source("../../R/main.R") + +pointsForAllTests(c("r1")) + +test("RetTrue works.", c("r1.1"), { + expect_true(RetTrue()) +}) + +test("RetOne works.", c("r1.2"), { + expect_equal(RetOne(), 1) +}) + +test("Add works.", c("r1.3", "r1.4"), { + expect_equal(Add(1, 1), 2) + expect_equal(Add(0, 1), 1) + expect_equal(Add(0, 0), 0) + expect_equal(Add(5, 5), 10) +}) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 8558aca..77ad7f6 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -1,33 +1,16 @@ -project_path <- find_root(has_file("DESCRIPTION")) -project_path <- dirname(project_path) -path_to_example1 <- paste(sep = "", project_path, "/example_projects/example_project1") -path_to_json <- paste(set="", path_to_example1, "/.results.json") +test_resources_dir <- paste(sep = "", getwd(), "/resources") - -test_that("Dummy test before real tests.", { - expect_true(DummyFunction()) -}) - -test_that("Dummy2 works", { - expect_true(Dummy2()) -}) - -test_that("Dummy3 works", { - expect_false(Dummy3()) -}) - -test_that("Hidden functions work", { - expect_true(.hidden_function()) -}) +#projects for testing: +simple_all_tests_pass_project_path <- paste(sep = "", test_resources_dir, "/simple_all_tests_pass") test_that("GetTestResults works as intended", { - results <- GetTestResults(path_to_example1) + results <- .GetTestResults(simple_all_tests_pass_project_path) string <- format(results[[1]]$results[[1]]) string2 <- "As expected" }) test_that("RunTests works", { - runTests(path_to_example1) + runTests(simple_all_tests_pass_project_path) }) test_that("PrintResult produces the right output", { @@ -35,7 +18,3 @@ test_that("PrintResult produces the right output", { string2 <- format("Testi1: PASS") expect_equal(string1, string2) }) - -test_that("Dummy test", { - expect_true(T) -}) diff --git a/tmcRtestrunner_0.1.0.tar.gz b/tmcRtestrunner_0.1.0.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..d5fd4bbd74c85eda12bfe0f818b8b620159bc94b GIT binary patch literal 3009 zcmV;y3qJH8iwFP!000001MM7ZbKAJlpZO~gDmS5e3Qg*n>dtLFj(yEdoOo=d`QW%7 zN`x#X6sZzm95>_t-d#LMP?BTk&ZopzViHRP7K>f%lX!^FC&!#Jp5;kGv+d{mCws>) zjz%wDzuLOD;z8+myZGr3dY<_yN`KJV@;iRt@3p;lzq94}-GT3I5pQb)C1*UyfRrHN zJo*CMZS4=V90ijP!37->UQq;VbhUs=)oP6*9>e2to-i^x+#|YltC|O8!WM0&hpRdw9V>F)rgQatNIineM6UzT) zJ*RAvMGG!)AEp^4!8px1xts-@M4W^vWyF~WS7X43&3qOlBuyxZ0ddnJP~I>~rhuO? z7#Y9;eL|unqzR9b3m_*8F0x=TgO-TTq6BbIVhrqBFQW-f7_j~phmGYEi5OCl1ETEj z)_yWcLqInqZ$<}CpII-1|6V;0cmPwH&?IE=1d|Ii@)mi|(j<;JwO&ygvb}V^ zh~hvpnxvMR^KeMoU?xw!zdmhuh(8$io(+8;#@PFb2wk-9MgCQ>Z@=0-+&?+m-P^xU z9lOo`eXp(T-)pz~J+%L>*RSn=6NP?Sq!~X7IHy_S*#AB~9R~4Y77WkMezcpG70t2T z(aPJ@6d5}a9OhdHQ22k-Coiu})O4?zCCj@POE|0YU9CUuzjpc*hT&C47U ziNTnqan3PY{jaeoHf59J@Jl{Xq zee-gJx!l3-%aeViD^t2pett@(c{0JA%rPlcICn&kCix6mCh(V)26S#hBbp1!FGB~@ z(FPM=O#rOcvk9>7FO=i>$FgeO$k@Yui*ooC=F(A}Ax;w_(SL!Qrgd#uOJm%|DcKzpqjLkE;`#JD5c8ZRT9&>)V5?50r+8l*C9F-K#15hV#q5_523BQjg4 z8>G!x4Zya0Y^!k&1OhdLE6_QJXGe5o+nN@;h3GM<0Tx7?`r(7bQ6*+gNjsG!-2YJLXI9rUPU!s7bgjUrri_ z@Y*nqs5HJsDs**BCqd5eWrkjnONwtjVMs$X13iU;PgkH&oltdl!|+HvjndsX7Fz67 z2~?v3pd2xkWD9#Q&0mQInb5X}GhHxTmGi`@*0sp$nAbR)C4C2JrU)FRvSx+OC9BxW zXuzp9it2z0nCF>c45;RXjZ`#TgD43$&>@kWPoF*`@Dc~_T%!8D>PC}E8ycTEJVjrp zd!uPk&aVn}X;ylP#%OvaQe-vh6yFi41c6zVBNi@I%(eg&kD_A>l-_ikwq&a^7Zui) z=0$O+=W$1yBvuxxt<`$9pA_~hFcPiTkMWPuc2w$~awv18K!J_vxr5P`*v87(I~ z;JH9!F9ODBXd8`(lrdZ{z*b!^h?i_>@*gjW6$|)!2SDcmSHMm32rO`y5qRSP?*#*y z;LBuU09k4@D4hy8dkMgx7FYo}GP*#kw_9d&i@56B0a%_KQOZ*j+AQ#1Th&kZ2z|1G z*7LlCz2w6bfb3(KQyBxClDQUHkF=CGsHLs(qAL+#O3P5Ql_V5|dOAG?w|Bv3h57yH zpPgyFl0;Y~o6?#|Y0kohH1=k6@`0gT1HvFK#L{CCsWo63*#2TF(e0%fCN3)mB1H}( z7&5+tLVcAoDeR`Ak73F`6f9m_CX-wkwr1~gM#1G~RcDW66-*1yTw!_y)(bB6NYt&c ze4ZMHy@qqs4^&_!+mF^xteni>%X1NmR2&nbs486@hgRl82Pvx|(K3w${alMM3|#>i zU~?H~LlXkizI+jaA;2uIiJf1b#yd@%BZoT&;Bz4VT$27nl>DFwIXx}>>e-nwnQK~Q ztXXRh7a7>N895guL@fBhD0#h?a z(gdD#q!enCqa{sXKAClsw_cN1l=BoZH-Riu)jvi|%`zm5Y(@G}lusiLl8YP(7Go=d zwYIxL+vulYz5r7|Ov>q;)Bof_?D(xVA}Vm8TTM?m%-n@J{OKw9+@`4wIz;VYfU;HS z6FE4-4^c!KY0G|>*ex|hkJa=xo0Um7>^MaqEzAQb4-!J>3&@r}iZ@B|5(ZOaRkMZ_ zdlMPN%6ys@fDne=sA-j>IIFs(+Sg#v`m+)lSBUy@lr++THN}jf<6!cEXTd~qSPjr3 zQDb7Hoje(*pNyfKHw=Qtp@3DKD(3K}E=r2V5Q>kRIut~!E+rE;bdXcMQ!-wvpHs4o zT2wE?elP2P^B}qZ72vzC|LXmp&Y%ZSf{xcfKse2r5ZvSuKFUh~x>9*_j-%XTv z7&<-+kzZTyf;b9T@x*c0|MNfbsYTwVSsXrs+8l$#XG;J%=)K>C<&ODh>qsuTK2hB+ zMYks|!l@*NeYR?!|DD>uTtxlm{=eJldbR)mX7bl-g4>&ye+TQ~>!4H1|C`JIp7wxm zjsO0#{r5Y5z5lzB5=Y}K$gYe7K1EGMGn$qq7P=<58tB;7M!P-*^yl>d8D(jnP3Z4S z3BJbvcRT$pukE${cJ2SaC;77oQ}=R-`5d<(w(nd1>il=R+xP1C{|6xd$`y+GliI!?QgJ{152dqXw^r)9E3{i@ zR-Mk(`QKgq|J{y@e@*_^_c8wWygL3r4Ef_#uG^LgzGnSj%D?Y*2X*}4MA4z#-0CjQ z3gJ#Io)r>1{VI^&2iDrZugX($5vSuICN%jNWoa^}32zZ`QD0vjxgwJwu^MBFF+PjvN4$@Q0Kl%80?U7kLPcQ1ldBc%97by=*US`39kswR+M4m-I$7-kfbWZs! z4aFS`#?!2F%f@P~<;oR192GM0WP?6p+Y(nqZXo&e6hY-dT{Q?X=#h9t|L^SR!@b(S zI7PVnLU617_w@Ro@AcbVVgGHvw*O5Oz1#Oh3-L+QvZT-*+jY0$pMJ^1p95I2YG>lu znUANih4nZqYlB1pxB$`;rlSro<8Na)3Kmc6UYiKa1v}Nhz0_YGewMHfH2Ee9b0JOj z@8BV4vD~!|4|H&RMA9PSH1$fOCma2n8oeg|U)R`ckskK+1c47M{)=O}zxzV?ZR`L3 zps(#8>>k(ueE_KKep??NQWDST5e+b7~8!T3? zMz6ahS0x3}D@A4=%9xG`v66)PN-qFx)Aq+8RfD(^(u5<>HG4*-VwM5RAjbTQ-V;;$M<66qT} zRW2FYNJQkL^Lzw<%KNScbE=;LRTp$te4!esrF(v#?yxR(sY_k{Z_57wy@iK}08#(| Dtbfj; literal 0 HcmV?d00001 From 840edc069fa19c4e442bc7dab25f6baaac1b4d4f Mon Sep 17 00:00:00 2001 From: anttihaap Date: Sat, 23 Sep 2017 21:28:16 +0300 Subject: [PATCH 38/50] Fixed typos... --- tmcRtestrunner/R/RunTests.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index eb7a04e..ce9ca11 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -23,6 +23,9 @@ runTests <- function(project_path, print=FALSE) { testFiles <- list.files(path="tests/testthat", pattern = "test.*\\.R", full.names = T, recursive = FALSE) for (testFile in testFiles) { + .GlobalEnv$points <- list() + .GlobalEnv$points_for_all_tests <- list() + testFileOutput <- test_file(testFile, reporter = "silent") #Modifies the points because they were added to all the tests. points <- .AddPointsToAllTests(testFileOutput) @@ -30,8 +33,6 @@ runTests <- function(project_path, print=FALSE) { testthatOutput <- c(testthatOutput, testFileOutput) } - .AddPointsForAllTestToPoints(testFileOutput) - results <- .CreateResults(testthatOutput) return(results) From 70982982b8262d17e41545c55c69f220263d462b Mon Sep 17 00:00:00 2001 From: anttihaap Date: Sun, 24 Sep 2017 02:00:04 +0300 Subject: [PATCH 39/50] A lot of refactoring. --- .../example_project1/tmc_run_test_example.sh | 3 +- tmcRtestrunner/DESCRIPTION | 4 + tmcRtestrunner/R/ResultsJsonParser.R | 68 +++++++++ tmcRtestrunner/R/RunTests.R | 142 ++++-------------- tmcRtestrunner/R/TestthatResultReader.R | 28 ++++ .../simple_all_tests_pass/.results.json | 9 +- tmcRtestrunner/tests/testthat/testRunTests.R | 28 ++-- .../tests/testthat/testTestthatResultReader.R | 1 + 8 files changed, 156 insertions(+), 127 deletions(-) create mode 100644 tmcRtestrunner/R/ResultsJsonParser.R create mode 100644 tmcRtestrunner/R/TestthatResultReader.R create mode 100644 tmcRtestrunner/tests/testthat/testTestthatResultReader.R diff --git a/example_projects/example_project1/tmc_run_test_example.sh b/example_projects/example_project1/tmc_run_test_example.sh index 65095c0..fc3febd 100755 --- a/example_projects/example_project1/tmc_run_test_example.sh +++ b/example_projects/example_project1/tmc_run_test_example.sh @@ -1,3 +1,4 @@ #!/bin/sh #Currently this script needs to be run at project root! -Rscript tmc/result.R + +Rscript -e "library(tmcRtestrunner);runTests(\"$PWD\", print=TRUE)" diff --git a/tmcRtestrunner/DESCRIPTION b/tmcRtestrunner/DESCRIPTION index fd9bf87..972841a 100644 --- a/tmcRtestrunner/DESCRIPTION +++ b/tmcRtestrunner/DESCRIPTION @@ -12,3 +12,7 @@ LazyData: true Depends: testthat, jsonlite +Collate: + 'ResultsJsonParser.R' + 'TestthatResultReader.R' + 'RunTests.R' diff --git a/tmcRtestrunner/R/ResultsJsonParser.R b/tmcRtestrunner/R/ResultsJsonParser.R new file mode 100644 index 0000000..1ae4544 --- /dev/null +++ b/tmcRtestrunner/R/ResultsJsonParser.R @@ -0,0 +1,68 @@ +.CreateJsonResults <- function(testthatOutput) { + results = list() + for (test in testthatOutput) { + testName <- test$test + testPoints <- test$points + testMessage <- "" + + if (.CheckIfTestPassed(test)) { + testStatus <- "pass" + } else { + testStatus <- "fail" + testMessage <- .CreateMessageForTestWithFailures(test) + } + + testResult <- .CreateJsonTestResult(testStatus, testName, testMessage,testPoints, "") + #Add test result to results + results[[length(results)+1]] <- testResult + } + return (results) +} + +.CreateJsonTestResult <- function(testStatus, testName, testMessage, + testPoints, backtrace) { + testResult <- list(status=unbox(testStatus), + name=unbox(format(testName)), + message=unbox(testMessage), + backtrace=unbox(backtrace), + points=testPoints) + return(testResult) +} + +#Returns message from failed results +#Currently supports only results that used calls +.MessageFromFailedResult <- function(result) { + if (is.null(result$call)) { + return("") + } + #language that failed the test. for example call expect_equal(1,2) + language <- toString(result$call[[1]]) + return (paste(sep="", "Failed with call: ", language,"\n", result$message)) +} + +.CreateMessageForTestWithFailures <- function(test) { + testMessage <- "" + for (result in test$results) { + if (format(result) != "As expected") { + testMessage <- paste(sep = "", testMessage, .MessageFromFailedResult(result)) + } + } + return(testMessage) +} + +.WriteJson <- function(results) { + #json utf-8 coded: + json <- enc2utf8(toJSON(results, pretty = FALSE)) + json <- prettify(json) + #encode json to utf-8 and write file + write(json, ".results.json") +} + +.PrintResultsFromJson <- function(jsonResult) { + for (test in jsonResult) { + cat(sep = "", test$name, ": ", test$status, "\n") + if (test$message != "") { + cat(sep = "", "\n", test$message, "\n") + } + } +} diff --git a/tmcRtestrunner/R/RunTests.R b/tmcRtestrunner/R/RunTests.R index ce9ca11..f96bdbf 100644 --- a/tmcRtestrunner/R/RunTests.R +++ b/tmcRtestrunner/R/RunTests.R @@ -5,17 +5,24 @@ # project_path: The absolute path to the root of the project being tested. # print: If TRUE, prints results; if not, not. DEFAULT is FALSE. # -runTests <- function(project_path, print=FALSE) { - tmcrtestrunner_project_path <- getwd() - #setwd(project_path) - results <- .GetTestResults(project_path, print) - .WriteJson(results) +runTests <- function(projectPath, print=FALSE) { + tmcrTestRunnerProjectPath <- getwd() - setwd(tmcrtestrunner_project_path) + #runs test for project, returns testthatOuput with added points. + testthatOutput <- .RunTestsProject(projectPath) + + jsonResults <- .CreateJsonResults(testthatOutput) + .WriteJson(jsonResults) + + if (print) { + .PrintResultsFromJson(jsonResults) + } + + setwd(tmcrTestRunnerProjectPath) } -.GetTestResults <- function(project_path, print = FALSE) { - setwd(project_path) +.RunTestsProject <- function(projectPath) { + setwd(projectPath) testthatOutput <- list() @@ -23,122 +30,35 @@ runTests <- function(project_path, print=FALSE) { testFiles <- list.files(path="tests/testthat", pattern = "test.*\\.R", full.names = T, recursive = FALSE) for (testFile in testFiles) { - .GlobalEnv$points <- list() - .GlobalEnv$points_for_all_tests <- list() - - testFileOutput <- test_file(testFile, reporter = "silent") - #Modifies the points because they were added to all the tests. - points <- .AddPointsToAllTests(testFileOutput) - #Adds the output from the tests in the file to the list + testFileOutput <- .RunTestsFile(testFile) testthatOutput <- c(testthatOutput, testFileOutput) } - - results <- .CreateResults(testthatOutput) - - return(results) -} - -.WriteJson <- function(results) { - #json utf-8 coded: - json <- enc2utf8(toJSON(results, pretty = FALSE)) - json <- prettify(json) - #encode json to utf-8 and write file - write(json, ".results.json") -} - -.CreateResults <- function(testthatOutput) { - results = list() - for (test in testthatOutput) { - testName <- test$test - testPoints <- .GetTestPoints(testName) - testFailed <- FALSE - testStatus <- "passed" - testMessage <- "" - for (result in test$results) { - if (format(result) != "As expected") { - testFailed <- TRUE - testStatus <- "failed" - testMessage <- paste(sep = "", testMessage, .MessageFromFailedResult(result)) - } - } - .PrintResult(testName, testMessage, testFailed) - testResult <- .CreateTestResult(testStatus, testName, testMessage,testPoints, "") - #Add test result to results - results[[length(results)+1]] <- testResult - } - return (results) - } - -#Checks if a single test passed -.CheckIfResultCorrect <- function(test) { - ret <- TRUE - for (result in test$results) { - if (format(result) != "As expected") { - ret <- FALSE - break - } - } - return (ret) + return(testthatOutput) } -#Checks whether all the tests in a single file passed -.CheckThatAllPassed <- function(test_output) { - ret <- TRUE - for (test in test_output) { - if (!.CheckIfResultCorrect(test)) { - ret <- FALSE - break - } - } - return (ret) -} +.RunTestsFile <- function(filePath) { + .GlobalEnv$points <- list() + .GlobalEnv$points_for_all_tests <- list() -#Adds the points from a single test file to all the tests in the file -#returns points list, so that the modified points list is updated -.AddPointsToAllTests <- function(test_output) { - for (test in test_output) { - if (!(points_for_all_tests %in% points[[test$test]])) { - points[[test$test]] <- c(points[[test$test]], points_for_all_tests) - } - } - return (points) -} + testFileOutput <- test_file(filePath, reporter = "silent") + testFileOutput <- .AddPointsToTestOutput(testFileOutput) -.PrintResult <- function(name, message, failed) { - if (failed) { - print(paste(name, ": FAIL", sep = "")) - print(paste(" ", message, sep = "")) - } else { - print(paste(name, ": PASS", sep = "")) - } + return(testFileOutput) } -#Returns message from failed results -#Currently supports only results that used calls -.MessageFromFailedResult <- function(result) { - if (is.null(result$call)) { - return("") +.AddPointsToTestOutput <- function(testOutput) { + for (i in 1 : length(testOutput)) { + testOutput[[i]]$points <- .GetTestPoints(testOutput[[i]]$test) } - #language that failed the test. for example call expect_equal(1,2) - language <- toString(result$call[[1]]) - return (paste(sep="", "Failed with call: ", language,"\n", result$message)) + return(testOutput) } -#Returns the points of a test or an empty vector if null .GetTestPoints <- function(testName) { if (is.null(points[[testName]])) { - return(vector()) + testPoints <- vector() } else { - return(points[[testName]]) + testPoints <- points[[testName]] } -} - -.CreateTestResult <- function(testStatus, testName, testMessage, - testPoints, backtrace) { - testResult <- list(status=unbox(testStatus), - name=unbox(format(testName)), - message=unbox(testMessage), - backtrace=unbox(backtrace), - points=testPoints) - return(testResult) + testPoints <- c(.GlobalEnv$points_for_all_tests, testPoints) + return(testPoints) } diff --git a/tmcRtestrunner/R/TestthatResultReader.R b/tmcRtestrunner/R/TestthatResultReader.R new file mode 100644 index 0000000..9e0a9fe --- /dev/null +++ b/tmcRtestrunner/R/TestthatResultReader.R @@ -0,0 +1,28 @@ +#Checks if all tests pass in testOutput +.CheckAllTestPassed <- function(testOutput) { + ret <- TRUE + for (test in testOutput) { + if (!.CheckIfTestPassed(test)) { + ret <- FALSE + break + } + } + return (ret) +} + +#Checks if a single test passed +.CheckIfTestPassed <- function(test) { + ret <- TRUE + for (result in test$results) { + if (!.CheckIfResultPassed(result)) { + ret <- FALSE + break + } + } + return (ret) +} + +#Check if a single result passed +.CheckIfResultPassed <- function(result) { + return(format(result) == "As expected") +} diff --git a/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/.results.json b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/.results.json index 4a50091..c4b61dd 100644 --- a/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/.results.json +++ b/tmcRtestrunner/tests/testthat/resources/simple_all_tests_pass/.results.json @@ -1,28 +1,31 @@ [ { - "status": "passed", + "status": "pass", "name": "RetTrue works.", "message": "", "backtrace": "", "points": [ + "r1", "r1.1" ] }, { - "status": "passed", + "status": "pass", "name": "RetOne works.", "message": "", "backtrace": "", "points": [ + "r1", "r1.2" ] }, { - "status": "passed", + "status": "pass", "name": "Add works.", "message": "", "backtrace": "", "points": [ + "r1", "r1.3", "r1.4" ] diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 77ad7f6..0835339 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -3,18 +3,22 @@ test_resources_dir <- paste(sep = "", getwd(), "/resources") #projects for testing: simple_all_tests_pass_project_path <- paste(sep = "", test_resources_dir, "/simple_all_tests_pass") -test_that("GetTestResults works as intended", { - results <- .GetTestResults(simple_all_tests_pass_project_path) - string <- format(results[[1]]$results[[1]]) - string2 <- "As expected" -}) +test_that("Test pass in simple_all_tests_pass", { + results <- .RunTestsProject(simple_all_tests_pass_project_path) -test_that("RunTests works", { - runTests(simple_all_tests_pass_project_path) + for (i in 1:3) { + string <- format(results[[i]]$results[[1]]) + string2 <- "As expected" + expect_equal(string, string2) + } }) -test_that("PrintResult produces the right output", { - string1 <- format(.PrintResult("Testi1", "!", FALSE)) - string2 <- format("Testi1: PASS") - expect_equal(string1, string2) -}) +# test_that("RunTests works", { +# runTests(simple_all_tests_pass_project_path) +# }) + +# test_that("PrintResult produces the right output", { +# string1 <- format(.PrintResult("Testi1", "!", FALSE)) +# string2 <- format("Testi1: PASS") +# expect_equal(string1, string2) +# }) diff --git a/tmcRtestrunner/tests/testthat/testTestthatResultReader.R b/tmcRtestrunner/tests/testthat/testTestthatResultReader.R new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tmcRtestrunner/tests/testthat/testTestthatResultReader.R @@ -0,0 +1 @@ + From 415ef74bc232a6409e2e05a76df4513ee211742c Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Sun, 24 Sep 2017 15:54:18 +0300 Subject: [PATCH 40/50] Added comments to the newly refactored source-files --- tmcRtestrunner/R/ResultsJsonParser.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tmcRtestrunner/R/ResultsJsonParser.R b/tmcRtestrunner/R/ResultsJsonParser.R index 1ae4544..b02452b 100644 --- a/tmcRtestrunner/R/ResultsJsonParser.R +++ b/tmcRtestrunner/R/ResultsJsonParser.R @@ -1,3 +1,4 @@ +#Creates JSON based on the test file. .CreateJsonResults <- function(testthatOutput) { results = list() for (test in testthatOutput) { @@ -19,6 +20,7 @@ return (results) } +#Creates JSON for each different test case. .CreateJsonTestResult <- function(testStatus, testName, testMessage, testPoints, backtrace) { testResult <- list(status=unbox(testStatus), @@ -50,6 +52,7 @@ return(testMessage) } +#Writes JSON based on the whole test result. .WriteJson <- function(results) { #json utf-8 coded: json <- enc2utf8(toJSON(results, pretty = FALSE)) @@ -58,6 +61,7 @@ write(json, ".results.json") } +#Prints results. .PrintResultsFromJson <- function(jsonResult) { for (test in jsonResult) { cat(sep = "", test$name, ": ", test$status, "\n") From aad55b675d6ad9ede855cc2bbfd85d61a1389ee8 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Mon, 25 Sep 2017 09:53:37 +0300 Subject: [PATCH 41/50] Added tests that test tmcRtestrunner --- tmcRtestrunner/tests/testthat/testRunTests.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 0835339..ef0bae3 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -13,6 +13,16 @@ test_that("Test pass in simple_all_tests_pass", { } }) +#Tests that all exercise entrys store the point for all tests. +test_that("Tests that pass in simple_all_tests_pass all have the point for all tests", { + results <- .RunTestsProject(simple_all_tests_pass_project_path) + point <- "r1" + for (i in 1:3) { + vec1 <- results[[i]]$points + expect_true(point %in% vec1) + } +}) + # test_that("RunTests works", { # runTests(simple_all_tests_pass_project_path) # }) From 4f39b6a526c98b67e7af42afd9474b0e54f84940 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Mon, 25 Sep 2017 10:16:11 +0300 Subject: [PATCH 42/50] Added tests to test that points are added correctly to the result dataframe --- tmcRtestrunner/tests/testthat/testRunTests.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index ef0bae3..6d361c5 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -23,6 +23,17 @@ test_that("Tests that pass in simple_all_tests_pass all have the point for all t } }) +#Tests if the hidden function .AddPointsToTestOutput works as intended. +#It should add points to the dataframe based on which the result-file is created. +test_that("Points are added accordingly after calling .AddPointsToTestOutput", { + testFileOutput <- test_file(paste(sep="", simple_all_tests_pass_project_path, "/tests/testthat/testMain.R"), reporter="silent") + expect_equal(testFileOutput[[1]]$points, NULL) + testFileOutput <- .AddPointsToTestOutput(testFileOutput) + expect_false(is.null(testFileOutput[[1]]$points)) +}) + + + # test_that("RunTests works", { # runTests(simple_all_tests_pass_project_path) # }) From 3b0e46d8bbfebe2883a69841e8f980251281d6ed Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Mon, 25 Sep 2017 10:25:55 +0300 Subject: [PATCH 43/50] Testing that file is created correctly when runTests is called. --- tmcRtestrunner/tests/testthat/testRunTests.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 6d361c5..89f9c68 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -32,6 +32,11 @@ test_that("Points are added accordingly after calling .AddPointsToTestOutput", { expect_false(is.null(testFileOutput[[1]]$points)) }) +test_that("RunTests works as intended", { + runTests(simple_all_tests_pass_project_path) + expect_true(file.exists(paste(sep="",simple_all_tests_pass_project_path, "/.results.json"))) +}) + # test_that("RunTests works", { From d8e08b2b8893a0ebcf9cacef76db0e1e7b55e077 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Mon, 25 Sep 2017 10:42:49 +0300 Subject: [PATCH 44/50] Added a second small resource project that includes files with failing tests. --- .../simple_some_tests_fail/.results.json | 34 +++++++++++++++++++ .../resources/simple_some_tests_fail/R/main.R | 15 ++++++++ .../simple_some_tests_fail.Rproj | 13 +++++++ .../tests/testthat/helperTMC.R | 13 +++++++ .../tests/testthat/testMain.R | 24 +++++++++++++ tmcRtestrunner/tests/testthat/testRunTests.R | 14 ++++++++ 6 files changed, 113 insertions(+) create mode 100644 tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/.results.json create mode 100644 tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/R/main.R create mode 100644 tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/simple_some_tests_fail.Rproj create mode 100644 tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/helperTMC.R create mode 100644 tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/testMain.R diff --git a/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/.results.json b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/.results.json new file mode 100644 index 0000000..c4b61dd --- /dev/null +++ b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/.results.json @@ -0,0 +1,34 @@ +[ + { + "status": "pass", + "name": "RetTrue works.", + "message": "", + "backtrace": "", + "points": [ + "r1", + "r1.1" + ] + }, + { + "status": "pass", + "name": "RetOne works.", + "message": "", + "backtrace": "", + "points": [ + "r1", + "r1.2" + ] + }, + { + "status": "pass", + "name": "Add works.", + "message": "", + "backtrace": "", + "points": [ + "r1", + "r1.3", + "r1.4" + ] + } +] + diff --git a/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/R/main.R b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/R/main.R new file mode 100644 index 0000000..ae0e172 --- /dev/null +++ b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/R/main.R @@ -0,0 +1,15 @@ +RetTrue <- function() { + return(TRUE) +} + +RetOne <- function() { + return(1) +} + +Add <- function(a, b) { + return(a + b) +} + +RetFalse <- function() { + return(FALSE) +} diff --git a/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/simple_some_tests_fail.Rproj b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/simple_some_tests_fail.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/simple_some_tests_fail.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX diff --git a/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/helperTMC.R b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/helperTMC.R new file mode 100644 index 0000000..51a55d8 --- /dev/null +++ b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/helperTMC.R @@ -0,0 +1,13 @@ + +#Sets the points for all tests to global environment, wherefrom they can +#be retrieved. +pointsForAllTests <- function(points) { + .GlobalEnv$points_for_all_tests <- points +} + +#The test that wraps around test_that()-method and stores the points +#to global environment. +test <- function(desc, points, code) { + .GlobalEnv$points[[desc]] <- points + test_that(desc, code) +} diff --git a/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/testMain.R b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/testMain.R new file mode 100644 index 0000000..ce6bdee --- /dev/null +++ b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/testMain.R @@ -0,0 +1,24 @@ +library('testthat') + +source("../../R/main.R") + +pointsForAllTests(c("r1")) + +test("RetTrue works.", c("r1.1"), { + expect_true(RetTrue()) +}) + +test("RetOne works.", c("r1.2"), { + expect_equal(RetOne(), 1) +}) + +test("Add works.", c("r1.3", "r1.4"), { + expect_equal(Add(1, 1), 2) + expect_equal(Add(0, 1), 1) + expect_equal(Add(0, 0), 0) + expect_equal(Add(5, 5), 10) +}) + +test("RetFalse returns true", c("r1.5"), { + expect_true(RetFalse()) +}) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 89f9c68..d63b361 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -2,6 +2,7 @@ test_resources_dir <- paste(sep = "", getwd(), "/resources") #projects for testing: simple_all_tests_pass_project_path <- paste(sep = "", test_resources_dir, "/simple_all_tests_pass") +simple_some_tests_fail_project_path <- paste(sep = "", test_resources_dir, "/simple_some_tests_fail") test_that("Test pass in simple_all_tests_pass", { results <- .RunTestsProject(simple_all_tests_pass_project_path) @@ -37,6 +38,19 @@ test_that("RunTests works as intended", { expect_true(file.exists(paste(sep="",simple_all_tests_pass_project_path, "/.results.json"))) }) +test_that("Not all tests pass in simple_some_tests_fail", { + results <- .RunTestsProject(simple_some_tests_fail_project_path) + all_tests_pass <- TRUE + pass_string <- "As expected" + for (i in 1:4) { + string <- format(results[[i]]$results[[1]]) + if(!isTRUE(all.equal(string, pass_string))) { + all_tests_pass <- FALSE + } + } + expect_false(all_tests_pass) +}) + # test_that("RunTests works", { From afc4e74a4f59d871876e26b634ec0385cb42c86f Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Mon, 25 Sep 2017 10:50:31 +0300 Subject: [PATCH 45/50] Added more tests. --- .../simple_some_tests_fail/.results.json | 19 +++++++++++++++++++ .../tests/testthat/testMain.R | 4 ++++ tmcRtestrunner/tests/testthat/testRunTests.R | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/.results.json b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/.results.json index c4b61dd..11495d5 100644 --- a/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/.results.json +++ b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/.results.json @@ -29,6 +29,25 @@ "r1.3", "r1.4" ] + }, + { + "status": "fail", + "name": "RetFalse returns true", + "message": "Failed with call: expect_true, RetFalse()\nRetFalse() isn't true.\n", + "backtrace": "", + "points": [ + "r1", + "r1.5" + ] + }, + { + "status": "pass", + "name": "RetTrue works but there are no points.", + "message": "", + "backtrace": "", + "points": [ + "r1" + ] } ] diff --git a/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/testMain.R b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/testMain.R index ce6bdee..f770c80 100644 --- a/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/testMain.R +++ b/tmcRtestrunner/tests/testthat/resources/simple_some_tests_fail/tests/testthat/testMain.R @@ -22,3 +22,7 @@ test("Add works.", c("r1.3", "r1.4"), { test("RetFalse returns true", c("r1.5"), { expect_true(RetFalse()) }) + +test("RetTrue works but there are no points.", NULL, { + expect_true(RetTrue()) +}) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index d63b361..5d97bf5 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -51,6 +51,11 @@ test_that("Not all tests pass in simple_some_tests_fail", { expect_false(all_tests_pass) }) +test_that("RunTests works even when some of the tests are failing", { + runTests(simple_some_tests_fail_project_path) + expect_true(file.exists(paste(sep="", simple_some_tests_fail_project_path, "/.results.json"))) +}) + # test_that("RunTests works", { From eb0a2504f6799c65e9515e949a670d861110b26f Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Mon, 25 Sep 2017 10:59:12 +0300 Subject: [PATCH 46/50] Added a printing test. --- tmcRtestrunner/tests/testthat/testRunTests.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tmcRtestrunner/tests/testthat/testRunTests.R b/tmcRtestrunner/tests/testthat/testRunTests.R index 5d97bf5..58e6f93 100644 --- a/tmcRtestrunner/tests/testthat/testRunTests.R +++ b/tmcRtestrunner/tests/testthat/testRunTests.R @@ -56,6 +56,13 @@ test_that("RunTests works even when some of the tests are failing", { expect_true(file.exists(paste(sep="", simple_some_tests_fail_project_path, "/.results.json"))) }) +test_that("RunTests works with printing", { + cat(format("\n\nTHIS TEST INCLUDES PRINTING\n\n")) + runTests(simple_some_tests_fail_project_path, TRUE) + cat("\n\nEND OF PRINTING TEST\n\n") + expect_true(file.exists(paste(sep="", simple_some_tests_fail_project_path, "/.results.json"))) +}) + # test_that("RunTests works", { From 70cfac835687c2b650cfc919864a88557ddb07d3 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Mon, 25 Sep 2017 14:31:46 +0300 Subject: [PATCH 47/50] Modified README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3d5e0fc..83de1f9 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ [![Build Status](https://travis-ci.org/RTMC/tmc-r.svg?branch=master)](https://travis-ci.org/RTMC/tmc-r) [![Coverage Status](https://coveralls.io/repos/github/RTMC/tmc-r/badge.svg)](https://coveralls.io/github/RTMC/tmc-r) -### Dokumentaatiota +### Documentation -* [Backlogit ja tuntikirjanpito](https://docs.google.com/spreadsheets/d/1uS8EfZtXFUFsn7fuUvls3LqDM_Vpn82c1zXXGLNh6ws/) +* [Product backlog, sprint backlogs and worked hours](https://docs.google.com/spreadsheets/d/1uS8EfZtXFUFsn7fuUvls3LqDM_Vpn82c1zXXGLNh6ws/) ### Definition of Done From 9f858ffe8bf20800bd5c9d563a01c3be7fde919d Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Mon, 25 Sep 2017 14:35:55 +0300 Subject: [PATCH 48/50] Modified example project description files --- example_projects/example_project1/DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example_projects/example_project1/DESCRIPTION b/example_projects/example_project1/DESCRIPTION index 329bf0b..2ed586d 100644 --- a/example_projects/example_project1/DESCRIPTION +++ b/example_projects/example_project1/DESCRIPTION @@ -3,7 +3,7 @@ Title: What the Package Does (one line, title case) Version: 0.0.0.9000 Authors@R: person("First", "Last", email = "first.last@example.com", role = c("aut", "cre")) Description: What the package does (one paragraph). -Depends: R (>= 3.2.3) +Depends: R (>= 3.3.2) License: What license is it under? Encoding: UTF-8 LazyData: true From 169776c92b10f399d82f6acfc9481949a12f8a65 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Mon, 25 Sep 2017 15:36:37 +0300 Subject: [PATCH 49/50] Modified example project description file --- example_projects/example_project1/DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example_projects/example_project1/DESCRIPTION b/example_projects/example_project1/DESCRIPTION index 2ed586d..329bf0b 100644 --- a/example_projects/example_project1/DESCRIPTION +++ b/example_projects/example_project1/DESCRIPTION @@ -3,7 +3,7 @@ Title: What the Package Does (one line, title case) Version: 0.0.0.9000 Authors@R: person("First", "Last", email = "first.last@example.com", role = c("aut", "cre")) Description: What the package does (one paragraph). -Depends: R (>= 3.3.2) +Depends: R (>= 3.2.3) License: What license is it under? Encoding: UTF-8 LazyData: true From 880c814b686b88f0540be5dbde5a664dd4b73de9 Mon Sep 17 00:00:00 2001 From: Aleksis Vuoksenmaa Date: Mon, 25 Sep 2017 15:39:56 +0300 Subject: [PATCH 50/50] Added files to collate --- tmcRtestrunner/DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/tmcRtestrunner/DESCRIPTION b/tmcRtestrunner/DESCRIPTION index 972841a..9f2b751 100644 --- a/tmcRtestrunner/DESCRIPTION +++ b/tmcRtestrunner/DESCRIPTION @@ -16,3 +16,4 @@ Collate: 'ResultsJsonParser.R' 'TestthatResultReader.R' 'RunTests.R' + 'getAvailablePoints.R'