Best JavaScript code snippet using stryker-parent
run-script.js
Source:run-script.js
1var fs = require('graceful-fs')2var path = require('path')3var mkdirp = require('mkdirp')4var test = require('tap').test5var rimraf = require('rimraf')6var common = require('../common-tap')7var pkg = path.resolve(__dirname, 'run-script')8var cache = path.resolve(pkg, 'cache')9var tmp = path.resolve(pkg, 'tmp')10var opts = { cwd: pkg }11var fullyPopulated = {12 'name': 'runscript',13 'version': '1.2.3',14 'scripts': {15 'start': 'node -e "console.log(process.argv[1] || \'start\')"',16 'prewith-pre': 'node -e "console.log(process.argv[1] || \'pre\')"',17 'with-pre': 'node -e "console.log(process.argv[1] || \'main\')"',18 'with-post': 'node -e "console.log(process.argv[1] || \'main\')"',19 'postwith-post': 'node -e "console.log(process.argv[1] || \'post\')"',20 'prewith-both': 'node -e "console.log(process.argv[1] || \'pre\')"',21 'with-both': 'node -e "console.log(process.argv[1] || \'main\')"',22 'postwith-both': 'node -e "console.log(process.argv[1] || \'post\')"',23 'stop': 'node -e "console.log(process.argv[1] || \'stop\')"',24 'env-vars': 'node -e "console.log(process.env.run_script_foo_var)"',25 'npm-env-vars': 'node -e "console.log(process.env.npm_run_script_foo_var)"',26 'package-env-vars': 'node -e "console.log(process.env.run_script_foo_var)"',27 'prefixed-package-env-vars': 'node -e "console.log(process.env.npm_package_run_script_foo_var)"'28 },29 'run_script_foo_var': 'run_script_test_foo_val'30}31var lifecycleOnly = {32 name: 'scripted',33 version: '1.2.3',34 scripts: {35 'prestart': 'echo prestart'36 }37}38var directOnly = {39 name: 'scripted',40 version: '1.2.3',41 scripts: {42 'whoa': 'echo whoa'43 }44}45var both = {46 name: 'scripted',47 version: '1.2.3',48 scripts: {49 'prestart': 'echo prestart',50 'whoa': 'echo whoa'51 }52}53var preversionOnly = {54 name: 'scripted',55 version: '1.2.3',56 scripts: {57 'preversion': 'echo preversion'58 }59}60var exitCode = {61 name: 'scripted',62 version: '1.2.3',63 scripts: {64 'start': 'node -e "process.exit(7)"'65 }66}67var shell = {68 name: 'scripted',69 version: '1.2.3',70 scripts: {71 'start': 'echo foo'72 }73}74function testOutput (t, command, er, code, stdout, stderr) {75 var lines76 if (er) throw er77 if (stderr) {78 throw new Error('npm ' + command + ' stderr: ' + stderr.toString())79 }80 lines = stdout.trim().split('\n')81 stdout = lines.filter(function (line) {82 return line.trim() !== '' && line[0] !== '>'83 }).join(';')84 t.equal(stdout, command)85 t.end()86}87function writeMetadata (object) {88 fs.writeFileSync(89 path.resolve(pkg, 'package.json'),90 JSON.stringify(object, null, 2) + '\n'91 )92}93function cleanup () {94 rimraf.sync(pkg)95}96test('setup', function (t) {97 cleanup()98 mkdirp.sync(cache)99 mkdirp.sync(tmp)100 writeMetadata(fullyPopulated)101 t.end()102})103test('npm run-script start', function (t) {104 common.npm(['run-script', 'start'], opts, testOutput.bind(null, t, 'start'))105})106test('npm run-script with args', function (t) {107 common.npm(['run-script', 'start', '--', 'stop'], opts, testOutput.bind(null, t, 'stop'))108})109test('npm run-script with args that contain spaces', function (t) {110 common.npm(['run-script', 'start', '--', 'hello world'], opts, testOutput.bind(null, t, 'hello world'))111})112test('npm run-script with args that contain single quotes', function (t) {113 common.npm(['run-script', 'start', '--', 'they"re awesome'], opts, testOutput.bind(null, t, 'they"re awesome'))114})115test('npm run-script with args that contain double quotes', function (t) {116 common.npm(['run-script', 'start', '--', 'what"s "up"?'], opts, testOutput.bind(null, t, 'what"s "up"?'))117})118test('npm run-script with args that contain ticks', function (t) {119 common.npm(['run-script', 'start', '--', 'what\'s \'up\'?'], opts, testOutput.bind(null, t, 'what\'s \'up\'?'))120})121test('npm run-script with pre script', function (t) {122 common.npm(['run-script', 'with-post'], opts, testOutput.bind(null, t, 'main;post'))123})124test('npm run-script with post script', function (t) {125 common.npm(['run-script', 'with-pre'], opts, testOutput.bind(null, t, 'pre;main'))126})127test('npm run-script with both pre and post script', function (t) {128 common.npm(['run-script', 'with-both'], opts, testOutput.bind(null, t, 'pre;main;post'))129})130test('npm run-script with both pre and post script and with args', function (t) {131 common.npm(['run-script', 'with-both', '--', 'an arg'], opts, testOutput.bind(null, t, 'pre;an arg;post'))132})133test('npm run-script explicitly call pre script with arg', function (t) {134 common.npm(['run-script', 'prewith-pre', '--', 'an arg'], opts, testOutput.bind(null, t, 'an arg'))135})136test('npm run-script test', function (t) {137 common.npm(['run-script', 'test'], opts, function (er, code, stdout, stderr) {138 t.ifError(er, 'npm run-script test ran without issue')139 t.notOk(stderr, 'should not generate errors')140 t.end()141 })142})143test('npm run-script env', function (t) {144 common.npm(['run-script', 'env'], opts, function (er, code, stdout, stderr) {145 t.ifError(er, 'using default env script')146 t.notOk(stderr, 'should not generate errors')147 t.ok(stdout.indexOf('npm_config_init_version') > 0, 'expected values in var list')148 t.end()149 })150})151test('npm run-script nonexistent-script', function (t) {152 common.npm(['run-script', 'nonexistent-script'], opts, function (er, code, stdout, stderr) {153 t.ifError(er, 'npm run-script nonexistent-script did not cause npm to explode')154 t.ok(stderr, 'should generate errors')155 t.end()156 })157})158test('npm run-script restart when there isn\'t restart', function (t) {159 common.npm(['run-script', 'restart'], opts, testOutput.bind(null, t, 'stop;start'))160})161test('npm run-script nonexistent-script with --if-present flag', function (t) {162 common.npm(['run-script', '--if-present', 'nonexistent-script'], opts, function (er, code, stdout, stderr) {163 t.ifError(er, 'npm run-script --if-present non-existent-script ran without issue')164 t.notOk(stderr, 'should not generate errors')165 t.end()166 })167})168test('npm run-script env vars accessible', function (t) {169 process.env.run_script_foo_var = 'run_script_test_foo_val'170 common.npm(['run-script', 'env-vars'], {171 cwd: pkg172 }, function (err, code, stdout, stderr) {173 t.ifError(err, 'ran run-script without crashing')174 t.equal(code, 0, 'exited normally')175 t.equal(stderr, '', 'no error output')176 t.match(stdout,177 new RegExp(process.env.run_script_foo_var),178 'script had env access')179 t.end()180 })181})182test('npm run-script package.json vars injected', function (t) {183 common.npm(['run-script', 'package-env-vars'], {184 cwd: pkg185 }, function (err, code, stdout, stderr) {186 t.ifError(err, 'ran run-script without crashing')187 t.equal(code, 0, 'exited normally')188 t.equal(stderr, '', 'no error output')189 t.match(stdout,190 new RegExp(fullyPopulated.run_script_foo_var),191 'script injected package.json value')192 t.end()193 })194})195test('npm run-script package.json vars injected with prefix', function (t) {196 common.npm(['run-script', 'prefixed-package-env-vars'], {197 cwd: pkg198 }, function (err, code, stdout, stderr) {199 t.ifError(err, 'ran run-script without crashing')200 t.equal(code, 0, 'exited normally')201 t.equal(stderr, '', 'no error output')202 t.match(stdout,203 new RegExp(fullyPopulated.run_script_foo_var),204 'script injected npm_package-prefixed package.json value')205 t.end()206 })207})208test('npm run-script env vars stripped npm-prefixed', function (t) {209 process.env.npm_run_script_foo_var = 'run_script_test_foo_val'210 common.npm(['run-script', 'npm-env-vars'], {211 cwd: pkg212 }, function (err, code, stdout, stderr) {213 t.ifError(err, 'ran run-script without crashing')214 t.equal(code, 0, 'exited normally')215 t.equal(stderr, '', 'no error output')216 t.notMatch(stdout,217 new RegExp(process.env.npm_run_script_foo_var),218 'script stripped npm-prefixed env var')219 t.end()220 })221})222test('npm run-script no-params (lifecycle only)', function (t) {223 var expected = [224 'Lifecycle scripts included in scripted:',225 ' prestart',226 ' echo prestart',227 ''228 ].join('\n')229 writeMetadata(lifecycleOnly)230 common.npm(['run-script'], opts, function (err, code, stdout, stderr) {231 t.ifError(err, 'ran run-script without parameters without crashing')232 t.notOk(code, 'npm exited without error code')233 t.notOk(stderr, 'npm printed nothing to stderr')234 t.equal(stdout, expected, 'got expected output')235 t.end()236 })237})238test('npm run-script no-params (preversion only)', function (t) {239 var expected = [240 'Lifecycle scripts included in scripted:',241 ' preversion',242 ' echo preversion',243 ''244 ].join('\n')245 writeMetadata(preversionOnly)246 common.npm(['run-script'], opts, function (err, code, stdout, stderr) {247 t.ifError(err, 'ran run-script without parameters without crashing')248 t.notOk(code, 'npm exited without error code')249 t.notOk(stderr, 'npm printed nothing to stderr')250 t.equal(stdout, expected, 'got expected output')251 t.end()252 })253})254test('npm run-script no-params (direct only)', function (t) {255 var expected = [256 'Scripts available in scripted via `npm run-script`:',257 ' whoa',258 ' echo whoa',259 ''260 ].join('\n')261 writeMetadata(directOnly)262 common.npm(['run-script'], opts, function (err, code, stdout, stderr) {263 t.ifError(err, 'ran run-script without parameters without crashing')264 t.notOk(code, 'npm exited without error code')265 t.notOk(stderr, 'npm printed nothing to stderr')266 t.equal(stdout, expected, 'got expected output')267 t.end()268 })269})270test('npm run-script script-shell config', function (t) {271 writeMetadata(shell)272 common.npm(['run-script', 'start', '--script-shell', 'echo'], opts, testOutput.bind(null, t, '-c echo foo'))273})274test('npm run-script no-params (direct only)', function (t) {275 var expected = [276 'Lifecycle scripts included in scripted:',277 ' prestart',278 ' echo prestart',279 '',280 'available via `npm run-script`:',281 ' whoa',282 ' echo whoa',283 ''284 ].join('\n')285 writeMetadata(both)286 common.npm(['run-script'], opts, function (err, code, stdout, stderr) {287 t.ifError(err, 'ran run-script without parameters without crashing')288 t.notOk(code, 'npm exited without error code')289 t.notOk(stderr, 'npm printed nothing to stderr')290 t.equal(stdout, expected, 'got expected output')291 t.end()292 })293})294test('npm run-script keep non-zero exit code', function (t) {295 writeMetadata(exitCode)296 common.npm(['run-script', 'start'], opts, function (err, code, stdout, stderr) {297 t.ifError(err, 'ran run-script without parameters without crashing')298 t.equal(code, 7, 'got expected exit code')299 t.ok(stderr, 'should generate errors')300 t.end()301 })302})303test('cleanup', function (t) {304 cleanup()305 t.end()...
options_storage.py
Source:options_storage.py
1import sys2SUPPORTED_PYTHON_VERSIONS = ['2.4', '2.5', '2.6', '2.7', '3.2', '3.3']3# allowed reads extensions for BayesHammer and for thw whole SPAdes pipeline4BH_ALLOWED_READS_EXTENSIONS = ['.fq', '.fastq']5ALLOWED_READS_EXTENSIONS = BH_ALLOWED_READS_EXTENSIONS + ['.fa', '.fasta']6# reads could be gzipped7BH_ALLOWED_READS_EXTENSIONS += [x + '.gz' for x in BH_ALLOWED_READS_EXTENSIONS]8ALLOWED_READS_EXTENSIONS += [x + '.gz' for x in ALLOWED_READS_EXTENSIONS]9# we support up to MAX_LIBS_NUMBER paired-end libs and MAX_LIBS_NUMBER mate-pair libs10MAX_LIBS_NUMBER = 511### DEFAULT VALUES:12# basic options13output_dir = ''14single_cell = False15# pipeline options16only_error_correction = False17only_assembler = False18disable_gzip_output = False19careful = False20rectangles = False21# advanced options22continue_mode = False23dataset_yaml_filename = ''24threads = 1625memory = 25026tmp_dir = ''27k_mers = None28k_mers_short = [21,33,55]29k_mers_150 = [21,33,55,77]30k_mers_250 = [21,33,55,77,99,127]31qvoffset = None # auto-detect by default32developer_mode = False33# hidden options34mismatch_corrector = False35reference = ''36iterations = 137bh_heap_check = ''38spades_heap_check = ''39### END OF DEFAULT VALUES40dict_of_prefixes = dict()41# list of spades.py options42long_options = "12= threads= memory= tmp-dir= iterations= phred-offset= sc "\43 "only-error-correction only-assembler "\44 "disable-gzip-output help test debug reference= "\45 "bh-heap-check= spades-heap-check= help-hidden "\46 "config-file= dataset= mismatch-correction careful rectangles continue".split()47short_options = "o:1:2:s:k:t:m:i:h"48# adding multiple paired-end and mate-pair libraries support49reads_options = []50for i in range(MAX_LIBS_NUMBER):51 for type in ["pe", "mp"]:52 reads_options += ("%s%d-1= %s%d-2= %s%d-12= %s%d-s= %s%d-rf %s%d-fr %s%d-ff" % tuple([type, i + 1] * 7)).split()53long_options += reads_options54# for checking whether option corresponds to reads or not55reads_options = list(map(lambda x:"--" + x.split('=')[0], reads_options))56reads_options += ["--12", "-1", "-2", "-s"]57def usage(spades_version, show_hidden=False):58 sys.stderr.write("SPAdes genome assembler v." + str(spades_version) + "\n")59 sys.stderr.write("Usage: " + str(sys.argv[0]) + " [options] -o <output_dir>" + "\n")60 sys.stderr.write("" + "\n")61 sys.stderr.write("Basic options:" + "\n")62 sys.stderr.write("-o\t<output_dir>\tdirectory to store all the resulting files (required)" + "\n")63 sys.stderr.write("--sc\t\t\tthis flag is required for MDA (single-cell)"\64 " data" + "\n")65 sys.stderr.write("--test\t\t\truns SPAdes on toy dataset" + "\n")66 sys.stderr.write("-h/--help\t\tprints this usage message" + "\n")67 sys.stderr.write("" + "\n")68 sys.stderr.write("Input data:" + "\n")69 sys.stderr.write("--12\t<filename>\tfile with interlaced forward and reverse"\70 " paired-end reads" + "\n")71 sys.stderr.write("-1\t<filename>\tfile with forward paired-end reads" + "\n")72 sys.stderr.write("-2\t<filename>\tfile with reverse paired-end reads" + "\n")73 sys.stderr.write("-s\t<filename>\tfile with unpaired reads" + "\n")74 sys.stderr.write("--pe<#>-12\t<filename>\tfile with interlaced"\75 " reads for paired-end library number <#> (<#> = 1,2,3,4,5)" + "\n")76 sys.stderr.write("--pe<#>-1\t<filename>\tfile with forward reads"\77 " for paired-end library number <#> (<#> = 1,2,3,4,5)" + "\n")78 sys.stderr.write("--pe<#>-2\t<filename>\tfile with reverse reads"\79 " for paired-end library number <#> (<#> = 1,2,3,4,5)" + "\n")80 sys.stderr.write("--pe<#>-s\t<filename>\tfile with unpaired reads"\81 " for paired-end library number <#> (<#> = 1,2,3,4,5)" + "\n")82 sys.stderr.write("--pe<#>-<or>\torientation of reads"\83 " for paired-end library number <#> (<#> = 1,2,3,4,5; <or> = fr, rf, ff)" + "\n")84 sys.stderr.write("--mp<#>-12\t<filename>\tfile with interlaced"\85 " reads for mate-pair library number <#> (<#> = 1,2,3,4,5)" + "\n")86 sys.stderr.write("--mp<#>-1\t<filename>\tfile with forward reads"\87 " for mate-pair library number <#> (<#> = 1,2,3,4,5)" + "\n")88 sys.stderr.write("--mp<#>-2\t<filename>\tfile with reverse reads"\89 " for mate-pair library number <#> (<#> = 1,2,3,4,5)" + "\n")90 sys.stderr.write("--mp<#>-s\t<filename>\tfile with unpaired reads"\91 " for mate-pair library number <#> (<#> = 1,2,3,4,5)" + "\n")92 sys.stderr.write("--mp<#>-<or>\torientation of reads"\93 " for mate-pair library number <#> (<#> = 1,2,3,4,5; <or> = fr, rf, ff)" + "\n")94 sys.stderr.write("" + "\n")95 sys.stderr.write("Pipeline options:" + "\n")96 sys.stderr.write("--only-error-correction\truns only read error correction"\97 " (without assembling)" + "\n")98 sys.stderr.write("--only-assembler\truns only assembling (without read error"\99 " correction)" + "\n")100 sys.stderr.write("--careful\t\ttries to reduce number"\101 " of mismatches and short indels" + "\n")102 sys.stderr.write("--continue\t\tcontinue run from the last available check-point" + "\n")103 sys.stderr.write("--disable-gzip-output\tforces error correction not to"\104 " compress the corrected reads" + "\n")105 sys.stderr.write("--rectangles\t\tuses rectangle graph algorithm for repeat resolution" + "\n")106 sys.stderr.write("" + "\n")107 sys.stderr.write("Advanced options:" + "\n")108 sys.stderr.write("--dataset\t<filename>\tfile with dataset description in YAML format" + "\n")109 sys.stderr.write("-t/--threads\t<int>\t\tnumber of threads" + "\n")110 sys.stderr.write("\t\t\t\t[default: %s]\n" % threads)111 sys.stderr.write("-m/--memory\t<int>\t\tRAM limit for SPAdes in Gb"\112 " (terminates if exceeded)" + "\n")113 sys.stderr.write("\t\t\t\t[default: %s]\n" % memory)114 sys.stderr.write("--tmp-dir\t<dirname>\tdirectory for read error correction"\115 " temporary files" + "\n")116 sys.stderr.write("\t\t\t\t[default: <output_dir>/corrected/tmp]" + "\n")117 sys.stderr.write("-k\t\t<int,int,...>\tcomma-separated list of k-mer sizes"\118 " (must be odd and" + "\n")119 sys.stderr.write("\t\t\t\tless than 128) [default: " + ",".join(map(str, k_mers_short)) + "]" + "\n")120 sys.stderr.write("--phred-offset\t<33 or 64>\tPHRED quality offset in the"\121 " input reads (33 or 64)" + "\n")122 sys.stderr.write("\t\t\t\t[default: auto-detect]" + "\n")123 sys.stderr.write("--debug\t\t\t\truns SPAdes in debug mode (keeps intermediate output)" + "\n")124 if show_hidden:125 sys.stderr.write("" + "\n")126 sys.stderr.write("HIDDEN options:" + "\n")127 sys.stderr.write("--mismatch-correction\t\truns post processing correction"\128 " of mismatches and short indels" + "\n")129 sys.stderr.write("--reference\t<filename>\tfile with reference for deep analysis"\130 " (only in debug mode)" + "\n")131 sys.stderr.write("-i/--iterations\t<int>\t\tnumber of iterations for read error"\132 " correction [default: %s]\n" % iterations)133 sys.stderr.write("--bh-heap-check\t\t<value>\tsets HEAPCHECK environment variable"\134 " for BayesHammer" + "\n")135 sys.stderr.write("--spades-heap-check\t<value>\tsets HEAPCHECK environment variable"\136 " for SPAdes" + "\n")137 sys.stderr.write("--help-hidden\tprints this usage message with all hidden options" + "\n")138 sys.stderr.flush()139def set_test_options():140 global output_dir141 global single_cell142 output_dir = 'spades_test'...
test_iostream.py
Source:test_iostream.py
...25 # Python 3.526 from contextlib import redirect_stderr27except ImportError:28 @contextmanager29 def redirect_stderr(target):30 original = sys.stderr31 sys.stderr = target32 yield33 sys.stderr = original34def test_captured(capsys):35 msg = "I've been redirected to Python, I hope!"36 m.captured_output(msg)37 stdout, stderr = capsys.readouterr()38 assert stdout == msg39 assert stderr == ""40 m.captured_output_default(msg)41 stdout, stderr = capsys.readouterr()42 assert stdout == msg43 assert stderr == ""44 m.captured_err(msg)45 stdout, stderr = capsys.readouterr()46 assert stdout == ""47 assert stderr == msg48def test_captured_large_string(capsys):49 # Make this bigger than the buffer used on the C++ side: 1024 chars50 msg = "I've been redirected to Python, I hope!"51 msg = msg * (1024 // len(msg) + 1)52 m.captured_output_default(msg)53 stdout, stderr = capsys.readouterr()54 assert stdout == msg55 assert stderr == ""56def test_captured_utf8_2byte_offset0(capsys):57 msg = "\u07FF"58 msg = "" + msg * (1024 // len(msg) + 1)59 m.captured_output_default(msg)60 stdout, stderr = capsys.readouterr()61 assert stdout == msg62 assert stderr == ""63def test_captured_utf8_2byte_offset1(capsys):64 msg = "\u07FF"65 msg = "1" + msg * (1024 // len(msg) + 1)66 m.captured_output_default(msg)67 stdout, stderr = capsys.readouterr()68 assert stdout == msg69 assert stderr == ""70def test_captured_utf8_3byte_offset0(capsys):71 msg = "\uFFFF"72 msg = "" + msg * (1024 // len(msg) + 1)73 m.captured_output_default(msg)74 stdout, stderr = capsys.readouterr()75 assert stdout == msg76 assert stderr == ""77def test_captured_utf8_3byte_offset1(capsys):78 msg = "\uFFFF"79 msg = "1" + msg * (1024 // len(msg) + 1)80 m.captured_output_default(msg)81 stdout, stderr = capsys.readouterr()82 assert stdout == msg83 assert stderr == ""84def test_captured_utf8_3byte_offset2(capsys):85 msg = "\uFFFF"86 msg = "12" + msg * (1024 // len(msg) + 1)87 m.captured_output_default(msg)88 stdout, stderr = capsys.readouterr()89 assert stdout == msg90 assert stderr == ""91def test_captured_utf8_4byte_offset0(capsys):92 msg = "\U0010FFFF"93 msg = "" + msg * (1024 // len(msg) + 1)94 m.captured_output_default(msg)95 stdout, stderr = capsys.readouterr()96 assert stdout == msg97 assert stderr == ""98def test_captured_utf8_4byte_offset1(capsys):99 msg = "\U0010FFFF"100 msg = "1" + msg * (1024 // len(msg) + 1)101 m.captured_output_default(msg)102 stdout, stderr = capsys.readouterr()103 assert stdout == msg104 assert stderr == ""105def test_captured_utf8_4byte_offset2(capsys):106 msg = "\U0010FFFF"107 msg = "12" + msg * (1024 // len(msg) + 1)108 m.captured_output_default(msg)109 stdout, stderr = capsys.readouterr()110 assert stdout == msg111 assert stderr == ""112def test_captured_utf8_4byte_offset3(capsys):113 msg = "\U0010FFFF"114 msg = "123" + msg * (1024 // len(msg) + 1)115 m.captured_output_default(msg)116 stdout, stderr = capsys.readouterr()117 assert stdout == msg118 assert stderr == ""119def test_guard_capture(capsys):120 msg = "I've been redirected to Python, I hope!"121 m.guard_output(msg)122 stdout, stderr = capsys.readouterr()123 assert stdout == msg124 assert stderr == ""125def test_series_captured(capture):126 with capture:127 m.captured_output("a")128 m.captured_output("b")129 assert capture == "ab"130def test_flush(capfd):131 msg = "(not flushed)"132 msg2 = "(flushed)"133 with m.ostream_redirect():134 m.noisy_function(msg, flush=False)135 stdout, stderr = capfd.readouterr()136 assert stdout == ""137 m.noisy_function(msg2, flush=True)138 stdout, stderr = capfd.readouterr()139 assert stdout == msg + msg2140 m.noisy_function(msg, flush=False)141 stdout, stderr = capfd.readouterr()142 assert stdout == msg143def test_not_captured(capfd):144 msg = "Something that should not show up in log"145 stream = StringIO()146 with redirect_stdout(stream):147 m.raw_output(msg)148 stdout, stderr = capfd.readouterr()149 assert stdout == msg150 assert stderr == ""151 assert stream.getvalue() == ""152 stream = StringIO()153 with redirect_stdout(stream):154 m.captured_output(msg)155 stdout, stderr = capfd.readouterr()156 assert stdout == ""157 assert stderr == ""158 assert stream.getvalue() == msg159def test_err(capfd):160 msg = "Something that should not show up in log"161 stream = StringIO()162 with redirect_stderr(stream):163 m.raw_err(msg)164 stdout, stderr = capfd.readouterr()165 assert stdout == ""166 assert stderr == msg167 assert stream.getvalue() == ""168 stream = StringIO()169 with redirect_stderr(stream):170 m.captured_err(msg)171 stdout, stderr = capfd.readouterr()172 assert stdout == ""173 assert stderr == ""174 assert stream.getvalue() == msg175def test_multi_captured(capfd):176 stream = StringIO()177 with redirect_stdout(stream):178 m.captured_output("a")179 m.raw_output("b")180 m.captured_output("c")181 m.raw_output("d")182 stdout, stderr = capfd.readouterr()183 assert stdout == "bd"184 assert stream.getvalue() == "ac"185def test_dual(capsys):186 m.captured_dual("a", "b")187 stdout, stderr = capsys.readouterr()188 assert stdout == "a"189 assert stderr == "b"190def test_redirect(capfd):191 msg = "Should not be in log!"192 stream = StringIO()193 with redirect_stdout(stream):194 m.raw_output(msg)195 stdout, stderr = capfd.readouterr()196 assert stdout == msg197 assert stream.getvalue() == ""198 stream = StringIO()199 with redirect_stdout(stream):200 with m.ostream_redirect():201 m.raw_output(msg)202 stdout, stderr = capfd.readouterr()203 assert stdout == ""204 assert stream.getvalue() == msg205 stream = StringIO()206 with redirect_stdout(stream):207 m.raw_output(msg)208 stdout, stderr = capfd.readouterr()209 assert stdout == msg210 assert stream.getvalue() == ""211def test_redirect_err(capfd):212 msg = "StdOut"213 msg2 = "StdErr"214 stream = StringIO()215 with redirect_stderr(stream):216 with m.ostream_redirect(stdout=False):217 m.raw_output(msg)218 m.raw_err(msg2)219 stdout, stderr = capfd.readouterr()220 assert stdout == msg221 assert stderr == ""222 assert stream.getvalue() == msg2223def test_redirect_both(capfd):224 msg = "StdOut"225 msg2 = "StdErr"226 stream = StringIO()227 stream2 = StringIO()228 with redirect_stdout(stream):229 with redirect_stderr(stream2):230 with m.ostream_redirect():231 m.raw_output(msg)232 m.raw_err(msg2)233 stdout, stderr = capfd.readouterr()234 assert stdout == ""235 assert stderr == ""236 assert stream.getvalue() == msg237 assert stream2.getvalue() == msg2238def test_threading():239 with m.ostream_redirect(stdout=True, stderr=False):240 # start some threads241 threads = []242 # start some threads243 for _j in range(20):...
git-npmignore.js
Source:git-npmignore.js
1var child_process = require('child_process')2var readdir = require('graceful-fs').readdirSync3var path = require('path')4var resolve = require('path').resolve5var rimraf = require('rimraf')6var test = require('tap').test7var which = require('which')8var common = require('../common-tap.js')9var escapeArg = require('../../lib/utils/escape-arg.js')10var Tacks = require('tacks')11var Dir = Tacks.Dir12var File = Tacks.File13var fixture = new Tacks(Dir({14 cache: Dir({}),15 deps: Dir({16 gitch: Dir({17 '.npmignore': File(18 't.js\n'19 ),20 '.gitignore': File(21 'node_modules/\n'22 ),23 'a.js': File(24 "console.log('hi');"25 ),26 't.js': File(27 "require('tap').test(function (t) { t.pass('I am a test!'); t.end(); });"28 ),29 'package.json': File({30 name: 'gitch',31 version: '1.0.0',32 private: true,33 main: 'a.js'34 })35 })36 }),37 'node_modules': Dir({38 })39}))40var testdir = resolve(__dirname, path.basename(__filename, '.js'))41var cachedir = resolve(testdir, 'cache')42var dep = resolve(testdir, 'deps', 'gitch')43var packname = 'gitch-1.0.0.tgz'44var packed = resolve(testdir, packname)45var modules = resolve(testdir, 'node_modules')46var installed = resolve(modules, 'gitch')47var expected = [48 'a.js',49 'package.json',50 '.npmignore'51].sort()52var NPM_OPTS = {53 cwd: testdir,54 env: common.newEnv().extend({55 npm_config_cache: cachedir56 })57}58function exec (todo, opts, cb) {59 console.log(' # EXEC:', todo)60 child_process.exec(todo, opts, cb)61}62test('setup', function (t) {63 setup(function (er) {64 t.ifError(er, 'setup ran OK')65 t.end()66 })67})68test('npm pack directly from directory', function (t) {69 packInstallTest(dep, t)70})71test('npm pack via git', function (t) {72 var urlPath = dep73 .replace(/\\/g, '/') // fixup slashes for Windows74 .replace(/^\/+/, '') // remove any leading slashes75 packInstallTest('git+file:///' + urlPath, t)76})77test('cleanup', function (t) {78 cleanup()79 t.end()80})81function packInstallTest (spec, t) {82 console.log(' # pack', spec)83 common.npm(84 [85 '--loglevel', 'error',86 'pack', spec87 ],88 NPM_OPTS,89 function (err, code, stdout, stderr) {90 if (err) throw err91 t.is(code, 0, 'npm pack exited cleanly')92 t.is(stderr, '', 'npm pack ran silently')93 t.is(stdout.trim(), packname, 'got expected package name')94 common.npm(95 [96 '--loglevel', 'error',97 'install', packed98 ],99 NPM_OPTS,100 function (err, code, stdout, stderr) {101 if (err) throw err102 t.is(code, 0, 'npm install exited cleanly')103 t.is(stderr, '', 'npm install ran silently')104 var actual = readdir(installed).sort()105 t.isDeeply(actual, expected, 'no unexpected files in packed directory')106 rimraf(packed, function () {107 t.end()108 })109 }110 )111 }112 )113}114function cleanup () {115 fixture.remove(testdir)116 rimraf.sync(testdir)117}118function setup (cb) {119 cleanup()120 fixture.create(testdir)121 common.npm(122 [123 '--loglevel', 'error',124 'cache', 'clean', '--force'125 ],126 NPM_OPTS,127 function (er, code, _, stderr) {128 if (er) return cb(er)129 if (stderr) return cb(new Error('npm cache clean error: ' + stderr))130 if (code) return cb(new Error('npm cache nonzero exit: ' + code))131 which('git', function found (er, gitPath) {132 if (er) return cb(er)133 var git = escapeArg(gitPath)134 exec(git + ' init', {cwd: dep}, init)135 function init (er, _, stderr) {136 if (er) return cb(er)137 if (stderr) return cb(new Error('git init error: ' + stderr))138 exec(git + " config user.name 'Phantom Faker'", {cwd: dep}, user)139 }140 function user (er, _, stderr) {141 if (er) return cb(er)142 if (stderr) return cb(new Error('git config error: ' + stderr))143 exec(git + ' config user.email nope@not.real', {cwd: dep}, email)144 }145 function email (er, _, stderr) {146 if (er) return cb(er)147 if (stderr) return cb(new Error('git config error: ' + stderr))148 exec(git + ' config core.autocrlf input', {cwd: dep}, autocrlf)149 }150 function autocrlf (er, _, stderr) {151 if (er) return cb(er)152 if (stderr) return cb(new Error('git config error: ' + stderr))153 exec(git + ' add .', {cwd: dep}, addAll)154 }155 function addAll (er, _, stderr) {156 if (er) return cb(er)157 if (stderr) return cb(new Error('git add . error: ' + stderr))158 exec(git + ' commit -m boot', {cwd: dep}, commit)159 }160 function commit (er, _, stderr) {161 if (er) return cb(er)162 if (stderr) return cb(new Error('git commit error: ' + stderr))163 cb()164 }165 })166 }167 )...
index.test.js
Source:index.test.js
1const testSetup = require('../__shared__/test-setup');2const fs = require('fs-extra');3const path = require('path');4test('formats babel syntax error', async () => {5 fs.copySync(6 path.join(__dirname, 'src', 'AppBabel.js'),7 path.join(testSetup.testDirectory, 'src', 'App.js')8 );9 const { stdout, stderr } = await testSetup.scripts.build();10 expect({ stdout, stderr }).toMatchSnapshot();11});12test('formats css syntax error', async () => {13 fs.copySync(14 path.join(__dirname, 'src', 'AppCss.js'),15 path.join(testSetup.testDirectory, 'src', 'App.js')16 );17 const { stdout, stderr } = await testSetup.scripts.build();18 expect({ stdout, stderr }).toMatchSnapshot();19});20test('formats unknown export', async () => {21 fs.copySync(22 path.join(__dirname, 'src', 'AppUnknownExport.js'),23 path.join(testSetup.testDirectory, 'src', 'App.js')24 );25 const { stdout, stderr } = await testSetup.scripts.build();26 expect({ stdout, stderr }).toMatchSnapshot();27});28test('formats aliased unknown export', async () => {29 fs.copySync(30 path.join(__dirname, 'src', 'AppAliasUnknownExport.js'),31 path.join(testSetup.testDirectory, 'src', 'App.js')32 );33 const { stdout, stderr } = await testSetup.scripts.build();34 expect({ stdout, stderr }).toMatchSnapshot();35});36test('formats no default export', async () => {37 fs.copySync(38 path.join(__dirname, 'src', 'AppNoDefault.js'),39 path.join(testSetup.testDirectory, 'src', 'App.js')40 );41 const { stdout, stderr } = await testSetup.scripts.build();42 expect({ stdout, stderr }).toMatchSnapshot();43});44test('formats missing package', async () => {45 fs.copySync(46 path.join(__dirname, 'src', 'AppMissingPackage.js'),47 path.join(testSetup.testDirectory, 'src', 'App.js')48 );49 let { stdout, stderr } = await testSetup.scripts.build();50 if (process.platform === 'win32') {51 stderr = stderr.replace('.\\src\\App.js', './src/App.js');52 }53 expect({ stdout, stderr }).toMatchSnapshot();54});55test('formats eslint warning', async () => {56 fs.copySync(57 path.join(__dirname, 'src', 'AppLintWarning.js'),58 path.join(testSetup.testDirectory, 'src', 'App.js')59 );60 let { stdout, stderr } = await testSetup.scripts.build();61 const sizeIndex = stdout.indexOf('File sizes after gzip');62 if (sizeIndex !== -1) {63 stdout = stdout.substring(0, sizeIndex);64 }65 expect({ stdout, stderr }).toMatchSnapshot();66});67test('formats eslint error', async () => {68 fs.copySync(69 path.join(__dirname, 'src', 'AppLintError.js'),70 path.join(testSetup.testDirectory, 'src', 'App.js')71 );72 const { stdout, stderr } = await testSetup.scripts.build();73 expect({ stdout, stderr }).toMatchSnapshot();74});75test('helps when users tries to use sass', async () => {76 fs.copySync(77 path.join(__dirname, 'src', 'AppSass.js'),78 path.join(testSetup.testDirectory, 'src', 'App.js')79 );80 const { stdout, stderr } = await testSetup.scripts.build();81 expect({ stdout, stderr }).toMatchSnapshot();82});83test('formats file not found error', async () => {84 fs.copySync(85 path.join(__dirname, 'src', 'AppUnknownFile.js'),86 path.join(testSetup.testDirectory, 'src', 'App.js')87 );88 let { stdout, stderr } = await testSetup.scripts.build();89 if (process.platform === 'win32') {90 stderr = stderr91 .replace('.\\src\\App.js', './src/App.js')92 .replace('.\\src', './src');93 }94 expect({ stdout, stderr }).toMatchSnapshot();95});96test('formats case sensitive path error', async () => {97 fs.copySync(98 path.join(__dirname, 'src', 'AppIncorrectCase.js'),99 path.join(testSetup.testDirectory, 'src', 'App.js')100 );101 const { stdout, stderr } = await testSetup.scripts.start({ smoke: true });102 if (process.platform === 'darwin') {103 expect(stderr).toMatch(104 `Cannot find file: 'export5.js' does not match the corresponding name on disk: './src/Export5.js'.`105 );106 } else {107 expect(stderr).not.toEqual(''); // TODO: figure out how we can test this on Linux/Windows108 // I believe getting this working requires we tap into enhanced-resolve109 // pipeline, which is debt we don't want to take on right now.110 }111});112test('formats out of scope error', async () => {113 fs.copySync(114 path.join(__dirname, 'src', 'AppOutOfScopeImport.js'),115 path.join(testSetup.testDirectory, 'src', 'App.js')116 );117 let { stdout, stderr } = await testSetup.scripts.build();118 if (process.platform === 'win32') {119 stderr = stderr.replace('.\\src\\App.js', './src/App.js');120 }121 expect({ stdout, stderr }).toMatchSnapshot();...
gyptest-errors.py
Source:gyptest-errors.py
1#!/usr/bin/env python2# Copyright (c) 2012 Google Inc. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5"""6Test that two targets with the same name generates an error.7"""8import os9import sys10import TestGyp11import TestCmd12# TODO(sbc): Remove the use of match_re below, done because scons13# error messages were not consistent with other generators.14# Also remove input.py:generator_wants_absolute_build_file_paths.15test = TestGyp.TestGyp()16stderr = ('gyp: Duplicate target definitions for '17 '.*duplicate_targets.gyp:foo#target\n')18test.run_gyp('duplicate_targets.gyp', status=1, stderr=stderr,19 match=TestCmd.match_re)20stderr = ('.*: Unable to find targets in build file .*missing_targets.gyp.*')21test.run_gyp('missing_targets.gyp', status=1, stderr=stderr,22 match=TestCmd.match_re_dotall)23stderr = ('gyp: rule bar exists in duplicate, target '24 '.*duplicate_rule.gyp:foo#target\n')25test.run_gyp('duplicate_rule.gyp', status=1, stderr=stderr,26 match=TestCmd.match_re)27stderr = ("gyp: Key 'targets' repeated at level 1 with key path '' while "28 "reading .*duplicate_node.gyp.*")29test.run_gyp('duplicate_node.gyp', '--check', status=1, stderr=stderr,30 match=TestCmd.match_re_dotall)31stderr = (".*target0.*target1.*target2.*target0.*")32test.run_gyp('dependency_cycle.gyp', status=1, stderr=stderr,33 match=TestCmd.match_re_dotall)34stderr = (".*file_cycle0.*file_cycle1.*file_cycle0.*")35test.run_gyp('file_cycle0.gyp', status=1, stderr=stderr,36 match=TestCmd.match_re_dotall)37stderr = 'gyp: Duplicate basenames in sources section, see list above\n'38test.run_gyp('duplicate_basenames.gyp', status=1, stderr=stderr)39# Check if '--no-duplicate-basename-check' works.40if ((test.format == 'make' and sys.platform == 'darwin') or41 (test.format == 'msvs' and42 int(os.environ.get('GYP_MSVS_VERSION', 2010)) < 2010)):43 stderr = 'gyp: Duplicate basenames in sources section, see list above\n'44 test.run_gyp('duplicate_basenames.gyp', '--no-duplicate-basename-check',45 status=1, stderr=stderr)46else:47 test.run_gyp('duplicate_basenames.gyp', '--no-duplicate-basename-check')48stderr = ("gyp: Dependency '.*missing_dep.gyp:missing.gyp#target' not found "49 "while trying to load target .*missing_dep.gyp:foo#target\n")50test.run_gyp('missing_dep.gyp', status=1, stderr=stderr,51 match=TestCmd.match_re)52# Make sure invalid <!() command invocations say what command it was and53# mention the gyp file name. Use a "random" command name to trigger an ENOENT.54stderr = (".*invalid-command-name-egtyevNif3.*netDurj9.*missing_command.gyp.*")55test.run_gyp('missing_command.gyp', status=1, stderr=stderr,56 match=TestCmd.match_re_dotall)57# Make sure <!() commands that error out result in a message that mentions58# the command and gyp file name59stderr = (".*python.*-c.*import sys.*sys.exit.*3.*error_command.gyp.*")60test.run_gyp('error_command.gyp', status=1, stderr=stderr,61 match=TestCmd.match_re_dotall)...
Using AI Code Generation
1var stryker = require('stryker-parent');2stryker.stderr('test');3var stryker = require('stryker-parent');4stryker.stdout('test');5var stryker = require('stryker-parent');6stryker.log('test');7var stryker = require('stryker-parent');8stryker.done('test');9var stryker = require('stryker-parent');10stryker.error('test');11var stryker = require('stryker-parent');12stryker.exit('test');13var stryker = require('stryker-parent');14stryker.write('test');15var stryker = require('stryker-parent');16stryker.write('test');17var stryker = require('stryker-parent');18stryker.write('test');19var stryker = require('stryker-parent');20stryker.write('test');21var stryker = require('stryker-parent');22stryker.write('test');23var stryker = require('stryker-parent');24stryker.write('test');25var stryker = require('stryker-parent');26stryker.write('test');27var stryker = require('stryker-parent');28stryker.write('test');29var stryker = require('stryker
Using AI Code Generation
1const strykerParent = require('stryker-parent');2const log = strykerParent.getLogger('test');3log.error('error');4log.warn('warn');5log.info('info');6log.debug('debug');7const stryker = require('stryker');8const log = stryker.getLogger('test');9log.error('error');10log.warn('warn');11log.info('info');12log.debug('debug');13const childProcess = require('child_process');14const log = childProcess.getLogger('test');15log.error('error');16log.warn('warn');17log.info('info');18log.debug('debug');19const strykerApi = require('stryker-api');20const log = strykerApi.getLogger('test');21log.error('error');22log.warn('warn');23log.info('info');24log.debug('debug');25const strykerMochaFramework = require('stryker-mocha-framework');26const log = strykerMochaFramework.getLogger('test');27log.error('error');28log.warn('warn');29log.info('info');30log.debug('debug');31const strykerHtmlReporter = require('stryker-html-reporter');32const log = strykerHtmlReporter.getLogger('test');33log.error('error');34log.warn('warn');35log.info('info');36log.debug('debug');37const strykerTypescript = require('stryker-typescript');38const log = strykerTypescript.getLogger('test');39log.error('error');40log.warn('warn');41log.info('info');42log.debug('debug');43const strykerMochaRunner = require('stryker-mocha-runner');44const log = strykerMochaRunner.getLogger('test');45log.error('error');46log.warn('warn');47log.info('info');48log.debug('debug');49const strykerJasmine = require('stryker-jasmine');50const log = strykerJasmine.getLogger('test');51log.error('error');52log.warn('warn');53log.info('info');
Using AI Code Generation
1var stryker = require('stryker-parent');2var log = stryker.getLogger('test');3log.error('test error');4var stryker = require('stryker');5var log = stryker.getLogger('test');6log.error('test error');7var stryker = require('stryker');8var log = stryker.getLogger('test');9log.error('test error');10var stryker = require('stryker');11var log = stryker.getLogger('test');12log.error('test error');13var stryker = require('stryker');14var log = stryker.getLogger('test');15log.error('test error');16var stryker = require('stryker');17var log = stryker.getLogger('test');18log.error('test error');19var stryker = require('stryker');20var log = stryker.getLogger('test');21log.error('test error');22var stryker = require('stryker');23var log = stryker.getLogger('test');24log.error('test error');25var stryker = require('stryker');26var log = stryker.getLogger('test');27log.error('test error');28var stryker = require('stryker');29var log = stryker.getLogger('test');30log.error('test error');31var stryker = require('stryker');32var log = stryker.getLogger('test');33log.error('test error');34var stryker = require('stryker');35var log = stryker.getLogger('test');36log.error('test error');
Using AI Code Generation
1var stryker = require('stryker-parent');2var log = stryker.getLogger('test');3log.error('error message');4var stryker = require('stryker');5var log = stryker.getLogger('test');6log.error('error message');7var stryker = require('stryker-parent');8var log = stryker.getLogger('test');9log.error('error message');10var stryker = require('stryker');11var log = stryker.getLogger('test');12log.error('error message');13var stryker = require('stryker-parent');14var log = stryker.getLogger('test');15log.error('error message');16var stryker = require('stryker');17var log = stryker.getLogger('test');18log.error('error message');19var stryker = require('stryker-parent');20var log = stryker.getLogger('test');21log.error('error message');22var stryker = require('stryker');23var log = stryker.getLogger('test');24log.error('error message');25var stryker = require('stryker-parent');26var log = stryker.getLogger('test');27log.error('error message');28var stryker = require('stryker');29var log = stryker.getLogger('test');30log.error('error message');31var stryker = require('stryker-parent');32var log = stryker.getLogger('test');33log.error('error message');34var stryker = require('stryker');35var log = stryker.getLogger('test');36log.error('error message');37var stryker = require('
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!