<commit_before>// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"testing"

	"v.io/x/lib/cmdline"
)

const (
	testDir    = "../../lib/vdl/testdata/base"
	outPkgPath = "v.io/x/ref/lib/vdl/testdata/base"
)

//go:generate v23 test generate

// Compares generated VDL files against the copy in the repo.
func TestVDLGenerator(t *testing.T) {
	// Use vdl to generate Go code from input, into a temporary directory.
	outDir, err := ioutil.TempDir("", "vdltest")
	if err != nil {
		t.Fatalf("TempDir() failed: %v", err)
	}
	defer os.RemoveAll(outDir)
	// TODO(toddw): test the generated java and javascript files too.
	outOpt := fmt.Sprintf("--go-out-dir=%s", outDir)
	env := cmdline.NewEnv()
	if err := cmdline.ParseAndRun(cmdVDL, env, []string{"generate", "--lang=go", outOpt, testDir}); err != nil {
		t.Fatalf("Execute() failed: %v", err)
	}
	// Check that each *.vdl.go file in the testDir matches the generated output.<commit_msg>ref: Rename cmdline.NewEnv to cmdline.EnvFromOS<commit_after>// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"testing"

	"v.io/x/lib/cmdline"
)

const (
	testDir    = "../../lib/vdl/testdata/base"
	outPkgPath = "v.io/x/ref/lib/vdl/testdata/base"
)

//go:generate v23 test generate

// Compares generated VDL files against the copy in the repo.
func TestVDLGenerator(t *testing.T) {
	// Use vdl to generate Go code from input, into a temporary directory.
	outDir, err := ioutil.TempDir("", "vdltest")
	if err != nil {
		t.Fatalf("TempDir() failed: %v", err)
	}
	defer os.RemoveAll(outDir)
	// TODO(toddw): test the generated java and javascript files too.
	outOpt := fmt.Sprintf("--go-out-dir=%s", outDir)
	env := cmdline.EnvFromOS()
	if err := cmdline.ParseAndRun(cmdVDL, env, []string{"generate", "--lang=go", outOpt, testDir}); err != nil {
		t.Fatalf("Execute() failed: %v", err)
	}
	// Check that each *.vdl.go file in the testDir matches the generated output.
{'fraction_non_alphanumeric': 0.14993481095176012, 'fraction_numerical': 0.005215123859191656, 'mean_word_length': 3.6505050505050507, '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': '2597967', 'n_tokens_mistral': 844, 'n_tokens_neox': 825, 'n_words': 255}