1#!/usr/bin/env Rscript 2# 3# Copyright 2014 Google Inc. All rights reserved. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# 18# Run unit tests for RAPPOR R code. 19 20library(RUnit) 21 22run_tests <- function() { 23 dirs <- "analysis/R" # Run from root 24 test_suite <- defineTestSuite("rappor", dirs, testFileRegexp = "_test.R$", 25 testFuncRegexp = "^Test") 26 stopifnot(isValidTestSuite(test_suite)) 27 28 test_result <- runTestSuite(test_suite) 29 30 printTextProtocol(test_result) # print to stdout 31 32 result <- test_result[[1]] # Result for our only suite 33 34 # Sanity check: fail if there were no tests found. 35 if (result$nTestFunc == 0) { 36 cat("No tests found.\n") 37 return(FALSE) 38 } 39 if (result$nFail != 0 || result$nErr != 0) { 40 cat("Some tests failed.\n") 41 return(FALSE) 42 } 43 return(TRUE) 44} 45 46if (!run_tests()) { 47 quit(status = 1) 48} 49