Git Product home page Git Product logo

Comments (4)

vangent avatar vangent commented on April 27, 2024

Does ${ROOTDIR} help?

https://github.com/google/go-cmdtest#variable-substitution

from go-cmdtest.

fe3dback avatar fe3dback commented on April 27, 2024

No,

i try this:

- [Archfile] path '$.components.not_exist.in': not found directories for 'not_exist' in '/home/neo/go/src/github.com/fe3dback/go-arch-lint/test/check/project/not_exist':
+ [Archfile] path '$.components.not_exist.in': not found directories for 'not_exist' in '${ROOTDIR}/test/check/project/not_exist':

After fix, test failed with error:

        cmdtest.go:294: test/check/invalid_spec.ct:1: got=-, want=+
            $ go-arch-lint check --project-path ${PWD}/test/check/project --arch-file invalid_spec.yml --output-color=false --> FAIL
              []string{
                ... // 7 identical elements
                "  25 | deps:",
                "  26 |   main:",
                strings.Join({
                        "[Archfile] path '$.components.not_exist.in': not found directori",
                        "es for 'not_exist' in '",
            -           "/home/neo/go/src/github.com/fe3dback/go-arch-lint",
            +           "${ROOTDIR}",
                        "/test/check/project/not_exist':",
                }, ""),
                "  14 |   main:",
                "  15 |     in: .",
                ... // 36 identical elements
              }

from go-cmdtest.

vangent avatar vangent commented on April 27, 2024

It looks like we do try to scrub the ${ROOTDIR}, here:
https://github.com/google/go-cmdtest/blob/master/cmdtest.go#L598

Is that path somewhere else? You might have to update the path to be relative to the test directory, or otherwise scrub it.

from go-cmdtest.

fe3dback avatar fe3dback commented on April 27, 2024

This ROOTDIR point to temporary dir like /tmp/cmdtest083165588, but i find solution for this:

Overriding ROOTDIR in testcase setup:

func TestCLI(t *testing.T) {
	ts, err := cmdtest.Read("test/**")
	if err != nil {
		t.Fatal(err)
	}

+	ts.Setup = func(_ string) error {
+		_, testFileName, _, ok := runtime.Caller(0)
+		if !ok {
+			return fmt.Errorf("failed get real working directory from caller")
+		}
+
+		projectRootDir := filepath.Dir(testFileName)
+		if err := os.Setenv("ROOTDIR", projectRootDir); err != nil {
+			return fmt.Errorf("failed change 'ROOTDIR' to caller working directory: %v", err)
+		}
+
+		return nil
+	}

	ts.Commands[binaryName] = cmdtest.InProcessProgram(binaryName, run)
	ts.Run(t, *update)
}
}

And now ${ROOTDIR} is working fine.

from go-cmdtest.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.