MCPcopy
hub / github.com/tinygo-org/tinygo / runTestWithConfig

Function runTestWithConfig

main_test.go:435–504  ·  view source on GitHub ↗
(name string, t *testing.T, options compileopts.Options, cmdArgs, environmentVars []string)

Source from the content-addressed store, hash-verified

433}
434
435func runTestWithConfig(name string, t *testing.T, options compileopts.Options, cmdArgs, environmentVars []string) {
436 t.Helper()
437 // Get the expected output for this test.
438 // Note: not using filepath.Join as it strips the path separator at the end
439 // of the path.
440 path := TESTDATA + "/" + name
441 // Get the expected output for this test.
442 expectedOutputPath := path[:len(path)-3] + ".txt"
443 pkgName := "./" + path
444 if path[len(path)-1] == '/' {
445 expectedOutputPath = path + "out.txt"
446 options.Directory = path
447 pkgName = "."
448 }
449
450 config, err := builder.NewConfig(&options)
451 if err != nil {
452 t.Fatal(err)
453 }
454
455 // Build the test binary.
456 stdout := &bytes.Buffer{}
457 _, err = buildAndRun(pkgName, config, stdout, cmdArgs, environmentVars, 2*time.Minute, func(cmd *exec.Cmd, result builder.BuildResult) error {
458 return cmd.Run()
459 })
460 if err != nil {
461 w := &bytes.Buffer{}
462 diagnostics.CreateDiagnostics(err).WriteTo(w, "")
463 for _, line := range strings.Split(strings.TrimRight(w.String(), "\n"), "\n") {
464 t.Log(line)
465 }
466 if stdout.Len() != 0 {
467 t.Logf("output:\n%s", stdout.String())
468 }
469 t.Fail()
470 return
471 }
472
473 actual := stdout.Bytes()
474 if config.EmulatorName() == "simavr" {
475 // Strip simavr log formatting.
476 actual = bytes.Replace(actual, []byte{0x1b, '[', '3', '2', 'm'}, nil, -1)
477 actual = bytes.Replace(actual, []byte{0x1b, '[', '0', 'm'}, nil, -1)
478 actual = bytes.Replace(actual, []byte{'.', '.', '\n'}, []byte{'\n'}, -1)
479 actual = bytes.Replace(actual, []byte{'\n', '.', '\n'}, []byte{'\n', '\n'}, -1)
480 }
481 if name == "testing.go" {
482 // Strip actual time.
483 re := regexp.MustCompile(`\([0-9]\.[0-9][0-9]s\)`)
484 actual = re.ReplaceAllLiteral(actual, []byte{'(', '0', '.', '0', '0', 's', ')'})
485 }
486
487 // Check whether the command ran successfully.
488 if err != nil {
489 t.Error("failed to run:", err)
490 }
491 checkOutput(t, expectedOutputPath, actual)
492

Callers 2

TestBuildFunction · 0.85
runTestFunction · 0.85

Calls 15

EmulatorNameMethod · 0.95
NewConfigFunction · 0.92
CreateDiagnosticsFunction · 0.92
buildAndRunFunction · 0.85
checkOutputFunction · 0.85
HelperMethod · 0.65
FatalMethod · 0.65
StringMethod · 0.65
LogMethod · 0.65
LenMethod · 0.65
LogfMethod · 0.65
FailMethod · 0.65

Tested by

no test coverage detected