<commit_before>#!/usr/bin/env node

'use strict';


/**
 * Methods that help with performing the tests
 */

const fs = require('fs');
const os = require('os');
const path = require('path');
require('./../../main/js/globals');
const { StringUtils, FilesManager, ArrayUtils } = require('turbocommons-ts');
const { execSync } = require('child_process');
const console = require('./../../main/js/console');


let executionDir = path.resolve('./'); 


/**
 * A files manager object ready to be used by the tests
 */
exports.fm = new FilesManager(fs, os, path, process);


/**
 * The path to the turbobuilder executable to test
 */
exports.pathToExecutable = 'node "' + path.resolve(__dirname + '/../../main/js/turbobuilder.js') + '"';


/**
 * Switch the work directory back to the execution dir
 */
exports.switchToExecutionDir = function () {
  
    process.chdir(executionDir);
};


/**
 * Move the work directory to the specified folder inside the main temp folder.
 * If folder does not exist, it will be created
 */
exports.createAndSwitchToTempFolder = function (dirName) {
  
    let tmp = this.fm.createTempDirectory(dirName);
        
    process.chdir(tmp);
    
    return tmp;
};


/**
 * Execute the project via cmd with the specified cmd arguments
 */
exports.exec = function (options) {
    
    try{
        
        return execSync(this.pathToExecutable + ' ' + options, {stdio : 'pipe'}).toString();
        
    }catch(e){
        
        if(!StringUtils.isEmpty(e.stderr.toString())){
            
            return e.stderr.toString();
        }
        
        return e.stdout.toString();
    }  
};


/**
 * Read the setup file from the current work dir and return it as a json object
 */
exports.readSetupFile = function () {
  
    return JSON.parse(this.fm.readFile('.' + this.fm.dirSep() + global.fileNames.setup));
};


/**
 * Save the provided object to the setup file on the current work dir as a json string
 */
exports.saveToSetupFile = function (object) {
  
    return this.fm.saveFile('.' + this.fm.dirSep() + global.fileNames.setup, JSON.stringify(object));
};<commit_msg>Added method to test-utils to execute arbitrary cmd commands<commit_after>#!/usr/bin/env node

'use strict';


/**
 * Methods that help with performing the tests
 */

const fs = require('fs');
const os = require('os');
const path = require('path');
require('./../../main/js/globals');
const { StringUtils, FilesManager, ArrayUtils } = require('turbocommons-ts');
const { execSync } = require('child_process');
const console = require('./../../main/js/console');


let executionDir = path.resolve('./'); 


/**
 * A files manager object ready to be used by the tests
 */
exports.fm = new FilesManager(fs, os, path, process);


/**
 * The path to the turbobuilder executable to test
 */
exports.pathToExecutable = 'node "' + path.resolve(__dirname + '/../../main/js/turbobuilder.js') + '"';


/**
 * Switch the work directory back to the execution dir
 */
exports.switchToExecutionDir = function () {
  
    process.chdir(executionDir);
};


/**
 * Move the work directory to the specified folder inside the main temp folder.
 * If folder does not exist, it will be created
 */
exports.createAndSwitchToTempFolder = function (dirName) {
  
    let tmp = this.fm.createTempDirectory(dirName);
        
    process.chdir(tmp);
    
    return tmp;
};


/**
 * Execute the project via cmd with the specified cmd arguments
 */
exports.exec = function (options) {
    
    return this.execCmdCommand(this.pathToExecutable + ' ' + options);
};


/**
 * Execute an arbitrary cmd command on the current active dir
 */
exports.execCmdCommand = function (cmdLine) {
    
    try{
        
        return execSync(cmdLine, {stdio : 'pipe'}).toString();
        
    }catch(e){
        
        if(!StringUtils.isEmpty(e.stderr.toString())){
            
            return e.stderr.toString();
        }
        
        return e.stdout.toString();
    }  
}


/**
 * Read the setup file from the current work dir and return it as a json object
 */
exports.readSetupFile = function () {
  
    return JSON.parse(this.fm.readFile('.' + this.fm.dirSep() + global.fileNames.setup));
};


/**
 * Save the provided object to the setup file on the current work dir as a json string
 */
exports.saveToSetupFile = function (object) {
  
    return this.fm.saveFile('.' + this.fm.dirSep() + global.fileNames.setup, JSON.stringify(object));
};
{'fraction_non_alphanumeric': 0.14298622091709962, 'fraction_numerical': 0.0, 'mean_word_length': 2.9185840707964603, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3422704', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1277, 'n_words': 381}