Best Syzkaller code snippet using compiler.getArgsBase
check.go
Source:check.go
...284 comp.checkLenType(fld.Type, fld.Name.Name, fields, parents, checked, false)285 }286 return287 }288 _, args, _ := comp.getArgsBase(t, "", prog.DirIn, isArg)289 for i, arg := range args {290 argDesc := desc.Args[i]291 if argDesc.Type == typeArgLenTarget {292 comp.checkLenTarget(t, name, arg.Ident, fields, parents)293 } else if argDesc.Type == typeArgType {294 comp.checkLenType(arg, name, fields, parents, checked, false)295 }296 }297}298func (comp *compiler) checkLenTarget(t *ast.Type, name, target string, fields []*ast.Field, parents []*ast.Struct) {299 if target == name {300 comp.error(t.Pos, "%v target %v refer to itself", t.Ident, target)301 return302 }303 if target == "parent" {304 if len(parents) == 0 {305 comp.error(t.Pos, "%v target %v does not exist", t.Ident, target)306 }307 return308 }309 for _, fld := range fields {310 if target != fld.Name.Name {311 continue312 }313 if fld.Type == t {314 comp.error(t.Pos, "%v target %v refer to itself", t.Ident, target)315 }316 if t.Ident == "len" {317 inner := fld.Type318 desc, args, _ := comp.getArgsBase(inner, "", prog.DirIn, false)319 for desc == typePtr {320 if desc != typePtr {321 break322 }323 inner = args[1]324 desc, args, _ = comp.getArgsBase(inner, "", prog.DirIn, false)325 }326 if desc == typeArray && comp.isVarlen(args[0]) {327 comp.warning(t.Pos, "len target %v refer to an array with"+328 " variable-size elements (do you mean bytesize?)", target)329 }330 }331 return332 }333 for _, parent := range parents {334 parentName := parent.Name.Name335 if pos := strings.IndexByte(parentName, '['); pos != -1 {336 // For template parents name is "struct_name[ARG1, ARG2]", strip the part after '['.337 parentName = parentName[:pos]338 }339 if target == parentName {340 return341 }342 }343 comp.error(t.Pos, "%v target %v does not exist", t.Ident, target)344}345func (comp *compiler) checkUsed() {346 for _, decl := range comp.desc.Nodes {347 switch n := decl.(type) {348 case *ast.Call:349 if n.NR == ^uint64(0) {350 break351 }352 for _, arg := range n.Args {353 comp.checkUsedType(arg.Type, true)354 }355 if n.Ret != nil {356 comp.checkUsedType(n.Ret, true)357 }358 }359 }360}361func (comp *compiler) checkUsedType(t *ast.Type, isArg bool) {362 if comp.used[t.Ident] {363 return364 }365 desc := comp.getTypeDesc(t)366 if desc == typeResource {367 r := comp.resources[t.Ident]368 for r != nil && !comp.used[r.Name.Name] {369 comp.used[r.Name.Name] = true370 r = comp.resources[r.Base.Ident]371 }372 return373 }374 if desc == typeStruct {375 comp.used[t.Ident] = true376 s := comp.structs[t.Ident]377 for _, fld := range s.Fields {378 comp.checkUsedType(fld.Type, false)379 }380 return381 }382 _, args, _ := comp.getArgsBase(t, "", prog.DirIn, isArg)383 for i, arg := range args {384 if desc.Args[i].Type == typeArgType {385 comp.checkUsedType(arg, false)386 }387 }388}389type structDir struct {390 Struct string391 Dir prog.Dir392}393func (comp *compiler) checkConstructors() {394 ctors := make(map[string]bool) // resources for which we have ctors395 checked := make(map[structDir]bool)396 for _, decl := range comp.desc.Nodes {397 switch n := decl.(type) {398 case *ast.Call:399 for _, arg := range n.Args {400 comp.checkTypeCtors(arg.Type, prog.DirIn, true, ctors, checked)401 }402 if n.Ret != nil {403 comp.checkTypeCtors(n.Ret, prog.DirOut, true, ctors, checked)404 }405 }406 }407 for _, decl := range comp.desc.Nodes {408 switch n := decl.(type) {409 case *ast.Resource:410 name := n.Name.Name411 if !ctors[name] && comp.used[name] {412 comp.error(n.Pos, "resource %v can't be created"+413 " (never mentioned as a syscall return value or output argument/field)",414 name)415 }416 }417 }418}419func (comp *compiler) checkTypeCtors(t *ast.Type, dir prog.Dir, isArg bool,420 ctors map[string]bool, checked map[structDir]bool) {421 desc := comp.getTypeDesc(t)422 if desc == typeResource {423 // TODO(dvyukov): consider changing this to "dir == prog.DirOut".424 // We have few questionable cases where resources can be created425 // only by inout struct fields. These structs should be split426 // into two different structs: one is in and second is out.427 // But that will require attaching dir to individual fields.428 if dir != prog.DirIn {429 r := comp.resources[t.Ident]430 for r != nil && !ctors[r.Name.Name] {431 ctors[r.Name.Name] = true432 r = comp.resources[r.Base.Ident]433 }434 }435 return436 }437 if desc == typeStruct {438 s := comp.structs[t.Ident]439 name := s.Name.Name440 key := structDir{name, dir}441 if checked[key] {442 return443 }444 checked[key] = true445 for _, fld := range s.Fields {446 comp.checkTypeCtors(fld.Type, dir, false, ctors, checked)447 }448 return449 }450 if desc == typePtr {451 dir = genDir(t.Args[0])452 }453 _, args, _ := comp.getArgsBase(t, "", dir, isArg)454 for i, arg := range args {455 if desc.Args[i].Type == typeArgType {456 comp.checkTypeCtors(arg, dir, false, ctors, checked)457 }458 }459}460func (comp *compiler) checkRecursion() {461 checked := make(map[string]bool)462 for _, decl := range comp.desc.Nodes {463 switch n := decl.(type) {464 case *ast.Resource:465 comp.checkResourceRecursion(n)466 case *ast.Struct:467 var path []pathElem468 comp.checkStructRecursion(checked, n, path)469 }470 }471}472func (comp *compiler) checkResourceRecursion(n *ast.Resource) {473 var seen []string474 for n != nil {475 if arrayContains(seen, n.Name.Name) {476 chain := ""477 for _, r := range seen {478 chain += r + "->"479 }480 chain += n.Name.Name481 comp.error(n.Pos, "recursive resource %v", chain)482 return483 }484 seen = append(seen, n.Name.Name)485 n = comp.resources[n.Base.Ident]486 }487}488type pathElem struct {489 Pos ast.Pos490 Struct string491 Field string492}493func (comp *compiler) checkStructRecursion(checked map[string]bool, n *ast.Struct, path []pathElem) {494 name := n.Name.Name495 if checked[name] {496 return497 }498 for i, elem := range path {499 if elem.Struct != name {500 continue501 }502 path = path[i:]503 str := ""504 for _, elem := range path {505 str += fmt.Sprintf("%v.%v -> ", elem.Struct, elem.Field)506 }507 str += name508 comp.error(path[0].Pos, "recursive declaration: %v (mark some pointers as opt)", str)509 checked[name] = true510 return511 }512 for _, f := range n.Fields {513 path = append(path, pathElem{514 Pos: f.Pos,515 Struct: name,516 Field: f.Name.Name,517 })518 comp.recurseField(checked, f.Type, path)519 path = path[:len(path)-1]520 }521 checked[name] = true522}523func (comp *compiler) recurseField(checked map[string]bool, t *ast.Type, path []pathElem) {524 desc := comp.getTypeDesc(t)525 if desc == typeStruct {526 comp.checkStructRecursion(checked, comp.structs[t.Ident], path)527 return528 }529 _, args, base := comp.getArgsBase(t, "", prog.DirIn, false)530 if desc == typePtr && base.IsOptional {531 return // optional pointers prune recursion532 }533 for i, arg := range args {534 if desc.Args[i].Type == typeArgType {535 comp.recurseField(checked, arg, path)536 }537 }538}539func (comp *compiler) checkStruct(ctx checkCtx, n *ast.Struct) {540 var flags checkFlags541 if !n.IsUnion {542 flags |= checkIsStruct543 }544 for _, f := range n.Fields {545 comp.checkType(ctx, f.Type, flags)546 }547 for _, attr := range n.Attrs {548 if unexpected, _, ok := checkTypeKind(attr, kindIdent); !ok {549 comp.error(attr.Pos, "unexpected %v, expect attribute", unexpected)550 return551 }552 if attr.HasColon {553 comp.error(attr.Pos2, "unexpected ':'")554 return555 }556 }557 if n.IsUnion {558 comp.parseUnionAttrs(n)559 } else {560 comp.parseStructAttrs(n)561 }562}563type checkFlags int564const (565 checkIsArg checkFlags = 1 << iota // immediate syscall arg type566 checkIsRet // immediate syscall ret type567 checkIsStruct // immediate struct field type568 checkIsResourceBase // immediate resource base type569 checkIsTypedef // immediate type alias/template type570)571type checkCtx struct {572 instantiationStack []string573}574func (comp *compiler) checkType(ctx checkCtx, t *ast.Type, flags checkFlags) {575 if unexpected, _, ok := checkTypeKind(t, kindIdent); !ok {576 comp.error(t.Pos, "unexpected %v, expect type", unexpected)577 return578 }579 desc := comp.getTypeDesc(t)580 if desc == nil {581 comp.error(t.Pos, "unknown type %v", t.Ident)582 return583 }584 if desc == typeTypedef {585 err0 := comp.errors586 // Replace t with type alias/template target type inplace,587 // and check the replaced type recursively.588 comp.replaceTypedef(&ctx, t, flags)589 if err0 == comp.errors {590 comp.checkType(ctx, t, flags)591 }592 return593 }594 if t.HasColon {595 if !desc.AllowColon {596 comp.error(t.Pos2, "unexpected ':'")597 return598 }599 if flags&checkIsStruct == 0 {600 comp.error(t.Pos2, "unexpected ':', only struct fields can be bitfields")601 return602 }603 }604 if flags&checkIsTypedef != 0 && !desc.CanBeTypedef {605 comp.error(t.Pos, "%v can't be type alias target", t.Ident)606 return607 }608 if flags&checkIsResourceBase != 0 && !desc.ResourceBase {609 comp.error(t.Pos, "%v can't be resource base (int types can)", t.Ident)610 return611 }612 args, opt := removeOpt(t)613 if opt != nil {614 if len(opt.Args) != 0 {615 comp.error(opt.Pos, "opt can't have arguments")616 }617 if flags&checkIsResourceBase != 0 || desc.CantBeOpt {618 what := "resource base"619 if desc.CantBeOpt {620 what = t.Ident621 }622 comp.error(opt.Pos, "%v can't be marked as opt", what)623 return624 }625 }626 addArgs := 0627 needBase := flags&checkIsArg == 0 && desc.NeedBase628 if needBase {629 addArgs++ // last arg must be base type, e.g. const[0, int32]630 }631 if len(args) > len(desc.Args)+addArgs || len(args) < len(desc.Args)-desc.OptArgs+addArgs {632 comp.error(t.Pos, "wrong number of arguments for type %v, expect %v",633 t.Ident, expectedTypeArgs(desc, needBase))634 return635 }636 if needBase {637 base := args[len(args)-1]638 args = args[:len(args)-1]639 comp.checkTypeArg(t, base, typeArgBase)640 }641 err0 := comp.errors642 for i, arg := range args {643 if desc.Args[i].Type == typeArgType {644 comp.checkType(ctx, arg, 0)645 } else {646 comp.checkTypeArg(t, arg, desc.Args[i])647 }648 }649 canBeArg, canBeRet := false, false650 if desc.CanBeArgRet != nil {651 canBeArg, canBeRet = desc.CanBeArgRet(comp, t)652 }653 if flags&checkIsRet != 0 && !canBeRet {654 comp.error(t.Pos, "%v can't be syscall return", t.Ident)655 return656 }657 if flags&checkIsArg != 0 && !canBeArg {658 comp.error(t.Pos, "%v can't be syscall argument", t.Ident)659 return660 }661 if desc.Check != nil && err0 == comp.errors {662 _, args, base := comp.getArgsBase(t, "", prog.DirIn, flags&checkIsArg != 0)663 desc.Check(comp, t, args, base)664 }665}666func (comp *compiler) replaceTypedef(ctx *checkCtx, t *ast.Type, flags checkFlags) {667 typedefName := t.Ident668 if t.HasColon {669 comp.error(t.Pos, "type alias %v with ':'", t.Ident)670 return671 }672 typedef := comp.typedefs[typedefName]673 fullTypeName := ast.SerializeNode(t)674 for i, prev := range ctx.instantiationStack {675 if prev == fullTypeName {676 ctx.instantiationStack = append(ctx.instantiationStack, fullTypeName)677 path := ""678 for j := i; j < len(ctx.instantiationStack); j++ {679 if j != i {680 path += " -> "681 }682 path += ctx.instantiationStack[j]683 }684 comp.error(t.Pos, "type instantiation loop: %v", path)685 return686 }687 }688 ctx.instantiationStack = append(ctx.instantiationStack, fullTypeName)689 nargs := len(typedef.Args)690 args := t.Args691 if nargs != len(t.Args) {692 if nargs == 0 {693 comp.error(t.Pos, "type %v is not a template", typedefName)694 } else {695 comp.error(t.Pos, "template %v needs %v arguments instead of %v",696 typedefName, nargs, len(t.Args))697 }698 return699 }700 pos0 := t.Pos701 if typedef.Type != nil {702 *t = *typedef.Type.Clone().(*ast.Type)703 if !comp.instantiate(t, typedef.Args, args) {704 return705 }706 } else {707 if comp.structs[fullTypeName] == nil {708 inst := typedef.Struct.Clone().(*ast.Struct)709 inst.Name.Name = fullTypeName710 if !comp.instantiate(inst, typedef.Args, args) {711 return712 }713 comp.checkStruct(*ctx, inst)714 comp.desc.Nodes = append(comp.desc.Nodes, inst)715 comp.structs[fullTypeName] = inst716 }717 *t = ast.Type{718 Ident: fullTypeName,719 }720 }721 t.Pos = pos0722 // Remove base type if it's not needed in this context.723 desc := comp.getTypeDesc(t)724 if flags&checkIsArg != 0 && desc.NeedBase {725 baseTypePos := len(t.Args) - 1726 if t.Args[baseTypePos].Ident == "opt" {727 baseTypePos--728 }729 copy(t.Args[baseTypePos:], t.Args[baseTypePos+1:])730 t.Args = t.Args[:len(t.Args)-1]731 }732}733func (comp *compiler) instantiate(templ ast.Node, params []*ast.Ident, args []*ast.Type) bool {734 if len(params) == 0 {735 return true736 }737 argMap := make(map[string]*ast.Type)738 for i, param := range params {739 argMap[param.Name] = args[i]740 }741 err0 := comp.errors742 templ.Walk(ast.Recursive(func(n ast.Node) {743 templArg, ok := n.(*ast.Type)744 if !ok {745 return746 }747 if concreteArg := argMap[templArg.Ident]; concreteArg != nil {748 origArgs := templArg.Args749 if len(origArgs) != 0 && len(concreteArg.Args) != 0 {750 comp.error(templArg.Pos, "both template parameter %v and its usage"+751 " have sub-arguments", templArg.Ident)752 return753 }754 *templArg = *concreteArg.Clone().(*ast.Type)755 if len(origArgs) != 0 {756 templArg.Args = origArgs757 }758 }759 // TODO(dvyukov): somewhat hacky, but required for int8[0:CONST_ARG]760 // Need more checks here. E.g. that CONST_ARG does not have subargs.761 // And if CONST_ARG is a value, then use concreteArg.Value.762 // Also need to error if CONST_ARG is a string.763 if concreteArg := argMap[templArg.Ident2]; concreteArg != nil {764 templArg.Ident2 = concreteArg.Ident765 templArg.Pos2 = concreteArg.Pos766 }767 }))768 return err0 == comp.errors769}770func (comp *compiler) checkTypeArg(t, arg *ast.Type, argDesc namedArg) {771 desc := argDesc.Type772 if len(desc.Names) != 0 {773 if unexpected, _, ok := checkTypeKind(arg, kindIdent); !ok {774 comp.error(arg.Pos, "unexpected %v for %v argument of %v type, expect %+v",775 unexpected, argDesc.Name, t.Ident, desc.Names)776 return777 }778 if !arrayContains(desc.Names, arg.Ident) {779 comp.error(arg.Pos, "unexpected value %v for %v argument of %v type, expect %+v",780 arg.Ident, argDesc.Name, t.Ident, desc.Names)781 return782 }783 } else {784 if unexpected, expect, ok := checkTypeKind(arg, desc.Kind); !ok {785 comp.error(arg.Pos, "unexpected %v for %v argument of %v type, expect %v",786 unexpected, argDesc.Name, t.Ident, expect)787 return788 }789 }790 if !desc.AllowColon && arg.HasColon {791 comp.error(arg.Pos2, "unexpected ':'")792 return793 }794 if desc.Check != nil {795 desc.Check(comp, arg)796 }797}798func expectedTypeArgs(desc *typeDesc, needBase bool) string {799 expect := ""800 for i, arg := range desc.Args {801 if expect != "" {802 expect += ", "803 }804 opt := i >= len(desc.Args)-desc.OptArgs805 if opt {806 expect += "["807 }808 expect += arg.Name809 if opt {810 expect += "]"811 }812 }813 if needBase {814 if expect != "" {815 expect += ", "816 }817 expect += typeArgBase.Name818 }819 if !desc.CantBeOpt {820 if expect != "" {821 expect += ", "822 }823 expect += "[opt]"824 }825 if expect == "" {826 expect = "no arguments"827 }828 return expect829}830func checkTypeKind(t *ast.Type, kind int) (unexpected string, expect string, ok bool) {831 switch {832 case kind == kindAny:833 ok = true834 case t.HasString:835 ok = kind == kindString836 if !ok {837 unexpected = fmt.Sprintf("string %q", t.String)838 }839 case t.Ident != "":840 ok = kind == kindIdent || kind == kindInt841 if !ok {842 unexpected = fmt.Sprintf("identifier %v", t.Ident)843 }844 default:845 ok = kind == kindInt846 if !ok {847 unexpected = fmt.Sprintf("int %v", t.Value)848 }849 }850 if !ok {851 switch kind {852 case kindString:853 expect = "string"854 case kindIdent:855 expect = "identifier"856 case kindInt:857 expect = "int"858 }859 }860 return861}862func (comp *compiler) checkVarlens() {863 for _, decl := range comp.desc.Nodes {864 switch n := decl.(type) {865 case *ast.Struct:866 comp.checkVarlen(n)867 }868 }869}870func (comp *compiler) isVarlen(t *ast.Type) bool {871 desc, args, _ := comp.getArgsBase(t, "", prog.DirIn, false)872 return desc.Varlen != nil && desc.Varlen(comp, t, args)873}874func (comp *compiler) isZeroSize(t *ast.Type) bool {875 desc, args, _ := comp.getArgsBase(t, "", prog.DirIn, false)876 return desc.ZeroSize != nil && desc.ZeroSize(comp, t, args)877}878func (comp *compiler) checkVarlen(n *ast.Struct) {879 // Non-varlen unions can't have varlen fields.880 // Non-packed structs can't have varlen fields in the middle.881 if n.IsUnion {882 if varlen, _ := comp.parseUnionAttrs(n); varlen {883 return884 }885 } else {886 if packed, _, _ := comp.parseStructAttrs(n); packed {887 return888 }889 }...
getArgsBase
Using AI Code Generation
1import (2func main() {3 conf.CreateFromFilenames("main", "2.go")4 prog, err := conf.Load()5 if err != nil {6 panic(err)7 }8 ssaProg := ssautil.CreateProgram(prog, 0)9 ssaProg.Build()10 for _, mem := range ssaProg.Members {11 if fn, ok := mem.(*ssa.Function); ok {12 for _, b := range fn.Blocks {13 for _, instr := range b.Instrs {14 if call, ok := instr.(*ssa.Call); ok {15 if call.Call.IsInvoke() {16 }17 if call.Call.Signature().String() == "func(*go/ast.FieldList) []go/ast.Expr" {18 if args, ok := call.Call.Args[0].(*ssa.MakeInterface); ok {19 if fieldList, ok := args.X.(*ssa.Extract); ok {20 for _, field := range fieldList.Type().Underlying().(*types.Tuple).At(0).Type().Underlying().(*types.Struct).Fields() {21 fmt.Println(field.Name())22 }23 }24 }25 }26 }27 }28 }29 }30 }31}32End()
getArgsBase
Using AI Code Generation
1import (2var (3 fset = flag.String("fset", "", "fset")4func main() {5 flag.Parse()6 files, err := getArgsBase()7 if err != nil {8 log.Fatal(err)9 }10 pkgs, err := packagestest.LoadFake("github.com/foo/bar", files)11 if err != nil {12 log.Fatal(err)13 }14 for _, pkg := range pkgs {15 fmt.Println("Package:", pkg.Name)16 fmt.Println("Module:", pkg.Module)17 fmt.Println("ModulePath:", pkg.ModulePath)18 fmt.Println("ModuleConfig:", pkg.ModuleConfig)19 fmt.Println("ModuleData:", pkg.ModuleData)20 fmt.Println("ModuleDeps:", pkg.ModuleDeps)21 fmt.Println("ModuleFiles:", pkg.ModuleFiles)22 fmt.Println("ModuleGoFiles:", pkg.ModuleGoFiles)23 fmt.Println("ModuleImports:", pkg.ModuleImports)24 fmt.Println("ModuleTypes:", pkg.ModuleTypes)25 fmt.Println("ModuleTypesSizes:", pkg.ModuleTypesSizes)26 fmt.Println("ModuleTypesInfo:", pkg.ModuleTypesInfo)27 fmt.Println()28 }29}
getArgsBase
Using AI Code Generation
1import (2func main() {3 comp := compiler.New()4 args := comp.GetArgsBase()5 fmt.Println(args)6}7import (8func main() {9 comp := compiler.New()10 args := comp.GetArgsBase()11 fmt.Println(args)12}13import (14func main() {15 comp := compiler.New()16 args := comp.GetArgsBase()17 fmt.Println(args)18}19import (20func main() {21 comp := compiler.New()22 args := comp.GetArgsBase()23 fmt.Println(args)24}25import (26type Compiler struct {27}28func New() *Compiler {29 return &Compiler{}30}31func (c *Compiler) GetArgsBase() []string {32}33import (34func main() {35 comp := compiler.New()36 args := comp.GetArgsBase()37 fmt.Println(args)38}39import (40func TestGetArgsBase(t *testing.T) {41 comp := compiler.New()42 args := comp.GetArgsBase()43 fmt.Println(args)44}
getArgsBase
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 a := getArgsBase()5 fmt.Println(a)6}
getArgsBase
Using AI Code Generation
1import (2type Compiler struct {3}4func main() {5 compiler := Compiler{name: "gcc", args: []string{"-o", "test", "test.c"}}6 fmt.Println("Compiler:", compiler.name)7 fmt.Println("Args:", compiler.args)8 fmt.Println("ArgsBase:", compiler.getArgsBase())9}10func (c *Compiler) getArgsBase() []string {11 return c.args[:len(c.args)-1]12}13import (14type Compiler struct {15}16func main() {17 compiler := Compiler{name: "gcc", args: []string{"-o", "test", "test.c"}}18 fmt.Println("Compiler:", compiler.name)19 fmt.Println("Args:", compiler.args)20 fmt.Println("ArgsBase:", compiler.getArgsBase())21}22func (c *Compiler) getArgsBase() []string {23 return c.args[:len(c.args)-1]24}25import (26type Compiler struct {27}28func main() {29 compiler := Compiler{name: "gcc", args: []string{"-o", "test", "test.c"}}30 fmt.Println("Compiler:", compiler.name)31 fmt.Println("Args:", compiler.args)32 fmt.Println("ArgsBase:", compiler.getArgsBase())33}34func (c *Compiler) getArgsBase() []string {35 return c.args[:len(c.args)-1]36}
getArgsBase
Using AI Code Generation
1import "fmt" 2 import "os" 3 import "io/ioutil" 4 import "strings" 5 func main () { 6 c := NewCompiler () 7 file, err := ioutil . ReadFile ( os . Args [ 1 ]) 8 if err != nil { 9 fmt . Println ( err ) 10 } 11 lines := strings . Split ( string ( file ), "12 for _ , line := range lines { 13 args := c . getArgsBase ( line ) 14 fmt . Println ( args ) 15 } 16 }
getArgsBase
Using AI Code Generation
1import (2func main() {3 compiler := new(Compiler)4 args := compiler.getArgsBase()5 compiler.compile(args[0])6 compiler.run()7}8import (9type Compiler struct {10}11func (compiler *Compiler) getArgsBase() []string {12 if len(args) != 1 {13 fmt.Println("Error: Please provide one argument")14 os.Exit(1)15 }16}17func (compiler *Compiler) compile(fileName string) {18 file, err := os.Open(fileName)19 if err != nil {20 fmt.Println("Error: Could not open file")21 os.Exit(1)22 }23 scanner := bufio.NewScanner(file)24 outputFile, err := os.Create("output.go")25 if err != nil {26 fmt.Println("Error: Could not create file")27 os.Exit(1)28 }29 writer := bufio.NewWriter(outputFile)30 for scanner.Scan() {31 line := scanner.Text()
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!!