(t *testing.T)
| 1919 | } |
| 1920 | |
| 1921 | func TestInterpreter(t *testing.T) { |
| 1922 | for _, tst := range testData(t) { |
| 1923 | tc := tst |
| 1924 | prg, vars, err := program(t, &tc) |
| 1925 | if err != nil { |
| 1926 | t.Fatalf("%s: %v", tc.name, err) |
| 1927 | } |
| 1928 | t.Run(tc.name, func(t *testing.T) { |
| 1929 | t.Parallel() |
| 1930 | |
| 1931 | var want ref.Val = types.True |
| 1932 | if tc.out != nil { |
| 1933 | want = tc.out.(ref.Val) |
| 1934 | } |
| 1935 | got := prg.Eval(vars) |
| 1936 | _, expectUnk := want.(*types.Unknown) |
| 1937 | if expectUnk { |
| 1938 | if !reflect.DeepEqual(got, want) { |
| 1939 | t.Fatalf("Got %v, wanted %v", got, want) |
| 1940 | } |
| 1941 | } else if tc.err != "" { |
| 1942 | if !types.IsError(got) || !strings.Contains(got.(*types.Err).String(), tc.err) { |
| 1943 | t.Fatalf("Got %v (%T), wanted error: %s", got, got, tc.err) |
| 1944 | } |
| 1945 | } else if got.Equal(want) != types.True { |
| 1946 | t.Fatalf("Got %v, wanted %v", got, want) |
| 1947 | } |
| 1948 | |
| 1949 | state := NewEvalState() |
| 1950 | opts := map[string][]PlannerOption{ |
| 1951 | "optimize": {Optimize()}, |
| 1952 | "exhaustive": {ExhaustiveEval(), |
| 1953 | EvalStateObserver(EvalStateFactory(func() EvalState { return state }))}, |
| 1954 | "track": {EvalStateObserver(EvalStateFactory(func() EvalState { return state }))}, |
| 1955 | } |
| 1956 | for mode, opt := range opts { |
| 1957 | opts := opt |
| 1958 | if tc.extraOpts != nil { |
| 1959 | opts = append(opts, tc.extraOpts...) |
| 1960 | } |
| 1961 | prg, vars, err = program(t, &tc, opts...) |
| 1962 | if tc.progErr != "" { |
| 1963 | if !types.IsError(got) || !strings.Contains(got.(*types.Err).String(), tc.progErr) { |
| 1964 | t.Errorf("Got %v (%T), wanted error: %s", got, got, tc.progErr) |
| 1965 | } |
| 1966 | continue |
| 1967 | } |
| 1968 | if err != nil { |
| 1969 | t.Fatal(err) |
| 1970 | } |
| 1971 | t.Run(mode, func(t *testing.T) { |
| 1972 | got := prg.Eval(vars) |
| 1973 | _, expectUnk := want.(*types.Unknown) |
| 1974 | if expectUnk { |
| 1975 | if !reflect.DeepEqual(got, want) { |
| 1976 | t.Errorf("Got %v, wanted %v", got, want) |
| 1977 | } |
| 1978 | } else if tc.err != "" { |
nothing calls this directly
no test coverage detected