示例#1
0
        public void TestCreate()
        {
            //using (var create = MyCSVWriter._initCSV("DDT-create.csv", "name", "verb", "batchmode", "input_file", "target_file", "expected", "append", "verbose"))
            var folder   = Column(0);
            var verb     = Column(1); // "create", unused
            var isbatch  = Boolean.Parse(Column(2));
            var input    = Column(3);
            var target   = Column(4); // unused
            var expected = Column(5);
            var output   = Column(6);
            var append   = Boolean.Parse(Column(7));
            var verbose  = Boolean.Parse(Column(8));

            using (var cleaner = FileCleaner.New())
            {
                // this is the sloppiest code ever
                if (append)
                {
                    // copy to out-append.json for the test to avoid overwriting generated artifacts
                    var out_append      = "out-append.json";
                    var full_out_append = Path.Combine(folder, out_append);
                    File.Copy(Path.Combine(folder, output), full_out_append, true);
                    output = out_append;
                    cleaner.Add(full_out_append);
                }
                else
                {
                    cleaner.Add(Path.Combine(folder, output));
                }
                if (!String.IsNullOrWhiteSpace(target))
                {
                    cleaner.Add(target);
                }

                string cmdline;
                if (isbatch)
                {
                    cmdline = $"create -b -i \"{input}\" -o \"{output}\"";
                }
                else
                {
                    cmdline = $"create -i \"{input}\" -t \"target.txt\" -o \"{output}\"";
                }
                if (append)
                {
                    cmdline += " -a";
                }

                var proc = FVTestUtil.RunProcess(cmdline, folder);
                Assert.AreEqual(0, proc.ExitCode);
                var exp_text = LoadOutput(Path.Combine(folder, expected));
                var got_text = LoadOutput(Path.Combine(folder, output));
                DictCompare(exp_text, got_text);
            }
        }